Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.MaybeEmbed {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Definition.Untyped using (Con ; Term)
open import Tools.Nat
open import Tools.Product
private
variable
n : Nat
Γ : Con Term n
-- Any level can be embedded into the highest level (validity variant).
maybeEmbᵛ : ∀ {l A}
([Γ] : ⊩ᵛ Γ)
→ Γ ⊩ᵛ⟨ l ⟩ A / [Γ]
→ Γ ⊩ᵛ⟨ ¹ ⟩ A / [Γ]
maybeEmbᵛ {l = ⁰} [Γ] [A] ⊢Δ [σ] =
let [σA] = proj₁ ([A] ⊢Δ [σ])
[σA]′ = maybeEmb (proj₁ ([A] ⊢Δ [σ]))
in [σA]′
, (λ [σ′] [σ≡σ′] → irrelevanceEq [σA] [σA]′ (proj₂ ([A] ⊢Δ [σ]) [σ′] [σ≡σ′]))
maybeEmbᵛ {l = ¹} [Γ] [A] = [A]
-- The lowest level can be embedded in any level (validity variant).
maybeEmbₛ′ : ∀ {l A}
([Γ] : ⊩ᵛ Γ)
→ Γ ⊩ᵛ⟨ ⁰ ⟩ A / [Γ]
→ Γ ⊩ᵛ⟨ l ⟩ A / [Γ]
maybeEmbₛ′ {l = ⁰} [Γ] [A] = [A]
maybeEmbₛ′ {l = ¹} [Γ] [A] ⊢Δ [σ] =
let [σA] = proj₁ ([A] ⊢Δ [σ])
[σA]′ = maybeEmb′ (proj₁ ([A] ⊢Δ [σ]))
in [σA]′
, (λ [σ′] [σ≡σ′] → irrelevanceEq [σA] [σA]′ (proj₂ ([A] ⊢Δ [σ]) [σ′] [σ≡σ′]))
|
{
"alphanum_fraction": 0.5624543462,
"avg_line_length": 30.4222222222,
"ext": "agda",
"hexsha": "feb9c373ba3a4549dd1c1160839725e2f83ed4d2",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-11-27T15:58:33.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-10-18T14:18:20.000Z",
"max_forks_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "fhlkfy/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Substitution/MaybeEmbed.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391",
"max_issues_repo_issues_event_max_datetime": "2021-02-22T10:37:24.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-22T12:49:23.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "fhlkfy/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Substitution/MaybeEmbed.agda",
"max_line_length": 84,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "fhlkfy/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Substitution/MaybeEmbed.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:01:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-20T03:05:21.000Z",
"num_tokens": 581,
"size": 1369
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Base
open import lib.Equivalence
open import lib.NType
open import lib.PathFunctor
open import lib.PathGroupoid
open import lib.PathOver
open import lib.Univalence
module lib.cubical.Square where
{-
*--1--*
| |
0 3
| |
*--2--*
-}
data Square {i} {A : Type i} {a₀₀ : A} : {a₀₁ a₁₀ a₁₁ : A}
→ a₀₀ == a₀₁ → a₀₀ == a₁₀ → a₀₁ == a₁₁ → a₁₀ == a₁₁ → Type i
where
ids : Square idp idp idp idp
hid-square : ∀ {i} {A : Type i} {a₀₀ a₀₁ : A} {p : a₀₀ == a₀₁}
→ Square p idp idp p
hid-square {p = idp} = ids
vid-square : ∀ {i} {A : Type i} {a₀₀ a₁₀ : A} {p : a₀₀ == a₁₀}
→ Square idp p p idp
vid-square {p = idp} = ids
square-to-disc : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ p₀₋ ∙ p₋₁ == p₋₀ ∙ p₁₋
square-to-disc ids = idp
disc-to-square : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ p₀₋ ∙ p₋₁ == p₋₀ ∙ p₁₋
→ Square p₀₋ p₋₀ p₋₁ p₁₋
disc-to-square {p₀₋ = idp} {p₋₀ = idp} {p₋₁ = idp} {p₁₋ = .idp} idp = ids
square-to-disc-β : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(α : p₀₋ ∙ p₋₁ == p₋₀ ∙ p₁₋)
→ square-to-disc (disc-to-square {p₀₋ = p₀₋} {p₋₀ = p₋₀} α) == α
square-to-disc-β {p₀₋ = idp} {p₋₀ = idp} {p₋₁ = idp} {p₁₋ = .idp} idp = idp
disc-to-square-β : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ disc-to-square (square-to-disc sq) == sq
disc-to-square-β ids = idp
square-disc-equiv : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ (Square p₀₋ p₋₀ p₋₁ p₁₋) ≃ (p₀₋ ∙ p₋₁ == p₋₀ ∙ p₁₋)
square-disc-equiv =
equiv square-to-disc disc-to-square square-to-disc-β disc-to-square-β
Square-level : ∀ {n : ℕ₋₂} {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ has-level (S (S n)) A
→ has-level n (Square p₀₋ p₋₀ p₋₁ p₁₋)
Square-level {n} A-level =
transport (has-level n) (! (ua square-disc-equiv)) $
has-level-apply (has-level-apply A-level _ _) _ _
ap-square : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square (ap f p₀₋) (ap f p₋₀) (ap f p₋₁) (ap f p₁₋)
ap-square f ids = ids
ap-square-hid : ∀ {i j} {A : Type i} {B : Type j} {f : A → B}
{a₀ a₁ : A} {p : a₀ == a₁}
→ ap-square f (hid-square {p = p}) == hid-square
ap-square-hid {p = idp} = idp
ap-square-vid : ∀ {i j} {A : Type i} {B : Type j} {f : A → B}
{a₀ a₁ : A} {p : a₀ == a₁}
→ ap-square f (vid-square {p = p}) == vid-square
ap-square-vid {p = idp} = idp
module _ {i} {A : Type i} where
horiz-degen-square : {a a' : A} {p q : a == a'}
→ p == q → Square p idp idp q
horiz-degen-square {p = idp} α = disc-to-square α
horiz-degen-path : {a a' : A} {p q : a == a'}
→ Square p idp idp q → p == q
horiz-degen-path {p = idp} sq = square-to-disc sq
horiz-degen-path-β : {a a' : A} {p q : a == a'} (α : p == q)
→ horiz-degen-path (horiz-degen-square α) == α
horiz-degen-path-β {p = idp} α = square-to-disc-β α
horiz-degen-square-β : {a a' : A} {p q : a == a'} (sq : Square p idp idp q)
→ horiz-degen-square (horiz-degen-path sq) == sq
horiz-degen-square-β {p = idp} sq = disc-to-square-β sq
vert-degen-square : {a a' : A} {p q : a == a'}
→ p == q → Square idp p q idp
vert-degen-square {p = idp} α = disc-to-square (! α)
vert-degen-path : {a a' : A} {p q : a == a'}
→ Square idp p q idp → p == q
vert-degen-path {p = idp} sq = ! (square-to-disc sq)
vert-degen-path-β : {a a' : A} {p q : a == a'} (α : p == q)
→ vert-degen-path (vert-degen-square α) == α
vert-degen-path-β {p = idp} α = ap ! (square-to-disc-β (! α)) ∙ !-! α
vert-degen-square-β : {a a' : A} {p q : a == a'} (sq : Square idp p q idp)
→ vert-degen-square (vert-degen-path sq) == sq
vert-degen-square-β {p = idp} sq =
ap disc-to-square (!-! (square-to-disc sq)) ∙ disc-to-square-β sq
horiz-degen-square-idp : {a a' : A} {p : a == a'}
→ horiz-degen-square (idp {a = p}) == hid-square
horiz-degen-square-idp {p = idp} = idp
vert-degen-square-idp : {a a' : A} {p : a == a'}
→ vert-degen-square (idp {a = p}) == vid-square
vert-degen-square-idp {p = idp} = idp
ap-horiz-degen-square : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{a a' : A} {p q : a == a'} (r : p == q)
→ ap-square f (horiz-degen-square r) == horiz-degen-square (ap (ap f) r)
ap-horiz-degen-square f {p = idp} r@idp = idp
ap-vert-degen-square : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{a a' : A} {p q : a == a'} (r : p == q)
→ ap-square f (vert-degen-square r) == vert-degen-square (ap (ap f) r)
ap-vert-degen-square f {p = idp} r@idp = idp
{- Flipping squares -}
module _ {i} {A : Type i} where
square-symmetry : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square p₋₀ p₀₋ p₁₋ p₋₁
square-symmetry ids = ids
square-sym-inv : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ square-symmetry (square-symmetry sq) == sq
square-sym-inv ids = idp
!□h : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square p₁₋ (! p₋₀) (! p₋₁) p₀₋
!□h ids = ids
!□v : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square (! p₀₋) p₋₁ p₋₀ (! p₁₋)
!□v ids = ids
!□v-horiz-degen-square : {a a' : A} {p q : a == a'}
(r : p == q)
→ !□v (horiz-degen-square r) == horiz-degen-square (ap ! r)
!□v-horiz-degen-square {p = idp} r@idp = idp
!□v-vert-degen-square : {a a' : A} {p q : a == a'}
(r : p == q)
→ !□v (vert-degen-square r) == vert-degen-square (! r)
!□v-vert-degen-square {p = idp} r@idp = idp
ap-square-symmetry : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ ap-square f (square-symmetry sq) == square-symmetry (ap-square f sq)
ap-square-symmetry f ids = idp
horiz-degen-square-symmetry : ∀ {i} {A : Type i}
{a a' : A} {p q : a == a'} (r : p == q)
→ square-symmetry (horiz-degen-square r) == vert-degen-square r
horiz-degen-square-symmetry {p = idp} α@idp = idp
{- Alternate induction principles -}
square-left-J : ∀ {i j} {A : Type i} {a₀₀ a₀₁ : A} {p₀₋ : a₀₀ == a₀₁}
(P : {a₁₀ a₁₁ : A} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ Type j)
(r : P hid-square)
{a₁₀ a₁₁ : A} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ P sq
square-left-J P r ids = r
square-top-J : ∀ {i j} {A : Type i} {a₀₀ a₁₀ : A} {p₋₀ : a₀₀ == a₁₀}
(P : {a₀₁ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ Type j)
(r : P vid-square)
{a₀₁ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ P sq
square-top-J P r ids = r
square-bot-J : ∀ {i j} {A : Type i} {a₀₁ a₁₁ : A} {p₋₁ : a₀₁ == a₁₁}
(P : {a₀₀ a₁₀ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ Type j)
(r : P vid-square)
{a₀₀ a₁₀ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ P sq
square-bot-J P r ids = r
square-right-J : ∀ {i j} {A : Type i} {a₁₀ a₁₁ : A} {p₁₋ : a₁₀ == a₁₁}
(P : {a₀₀ a₀₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ Type j)
(r : P hid-square)
{a₀₀ a₀₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ P sq
square-right-J P r ids = r
module _ where
private
lemma : ∀ {i j} {A : Type i} {a₀ : A}
(P : {a₁ : A} {p q : a₀ == a₁} → p == q → Type j)
(r : P (idp {a = idp}))
{a₁ : A} {p q : a₀ == a₁} (α : p == q)
→ P α
lemma P r {p = idp} idp = r
horiz-degen-J : ∀ {i j} {A : Type i} {a₀ : A}
(P : {a₁ : A} {p q : a₀ == a₁} → Square p idp idp q → Type j)
(r : P ids)
{a₁ : A} {p q : a₀ == a₁} (sq : Square p idp idp q)
→ P sq
horiz-degen-J P r sq = transport P
(horiz-degen-square-β sq)
(lemma (P ∘ horiz-degen-square) r (horiz-degen-path sq))
vert-degen-J : ∀ {i j} {A : Type i} {a₀ : A}
(P : {a₁ : A} {p q : a₀ == a₁} → Square idp p q idp → Type j)
(r : P ids)
{a₁ : A} {p q : a₀ == a₁} (sq : Square idp p q idp)
→ P sq
vert-degen-J P r sq = transport P
(vert-degen-square-β sq)
(lemma (P ∘ vert-degen-square) r (vert-degen-path sq))
{- Square filling -}
module _ {i} {A : Type i} where
fill-square-left : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
(p₋₀ : a₀₀ == a₁₀) (p₋₁ : a₀₁ == a₁₁) (p₁₋ : a₁₀ == a₁₁)
→ Σ (a₀₀ == a₀₁) (λ p₀₋ → Square p₀₋ p₋₀ p₋₁ p₁₋)
fill-square-left idp idp p = (p , hid-square)
fill-square-top : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
(p₀₋ : a₀₀ == a₀₁) (p₋₁ : a₀₁ == a₁₁) (p₁₋ : a₁₀ == a₁₁)
→ Σ (a₀₀ == a₁₀) (λ p₋₀ → Square p₀₋ p₋₀ p₋₁ p₁₋)
fill-square-top idp p idp = (p , vid-square)
fill-square-bot : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
(p₀₋ : a₀₀ == a₀₁) (p₋₀ : a₀₀ == a₁₀) (p₁₋ : a₁₀ == a₁₁)
→ Σ (a₀₁ == a₁₁) (λ p₋₁ → Square p₀₋ p₋₀ p₋₁ p₁₋)
fill-square-bot idp p idp = (p , vid-square)
fill-square-right : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
(p₀₋ : a₀₀ == a₀₁) (p₋₀ : a₀₀ == a₁₀) (p₋₁ : a₀₁ == a₁₁)
→ Σ (a₁₀ == a₁₁) (λ p₁₋ → Square p₀₋ p₋₀ p₋₁ p₁₋)
fill-square-right p idp idp = (p , hid-square)
module _ {i j} {A : Type i} {B : Type j} {f : A → B} {b : B} where
↓-cst=app-from-square : {x y : A} {p : x == y}
{u : b == f x} {v : b == f y}
→ Square u idp (ap f p) v
→ u == v [ (λ z → b == f z) ↓ p ]
↓-cst=app-from-square {p = idp} sq = horiz-degen-path sq
↓-cst=app-to-square : {x y : A} {p : x == y}
{u : b == f x} {v : b == f y}
→ u == v [ (λ z → b == f z) ↓ p ]
→ Square u idp (ap f p) v
↓-cst=app-to-square {p = idp} α = horiz-degen-square α
↓-app=cst-from-square : {x y : A} {p : x == y}
{u : f x == b} {v : f y == b}
→ Square u (ap f p) idp v
→ u == v [ (λ z → f z == b) ↓ p ]
↓-app=cst-from-square {p = idp} sq = horiz-degen-path sq
↓-app=cst-to-square : {x y : A} {p : x == y}
{u : f x == b} {v : f y == b}
→ u == v [ (λ z → f z == b) ↓ p ]
→ Square u (ap f p) idp v
↓-app=cst-to-square {p = idp} α = horiz-degen-square α
module _ {i} {A : Type i} {f : A → A} where
↓-idf=app-from-square : {x y : A} {p : x == y}
{u : x == f x} {v : y == f y}
→ Square u p (ap f p) v
→ u == v [ (λ z → z == f z) ↓ p ]
↓-idf=app-from-square {p = idp} sq = horiz-degen-path sq
↓-idf=app-to-square : {x y : A} {p : x == y}
{u : x == f x} {v : y == f y}
→ u == v [ (λ z → z == f z) ↓ p ]
→ Square u p (ap f p) v
↓-idf=app-to-square {p = idp} α = horiz-degen-square α
↓-app=idf-from-square : {x y : A} {p : x == y}
{u : f x == x} {v : f y == y}
→ Square u (ap f p) p v
→ u == v [ (λ z → f z == z) ↓ p ]
↓-app=idf-from-square {p = idp} sq = horiz-degen-path sq
↓-app=idf-to-square : {x y : A} {p : x == y}
{u : f x == x} {v : f y == y}
→ u == v [ (λ z → f z == z) ↓ p ]
→ Square u (ap f p) p v
↓-app=idf-to-square {p = idp} α = horiz-degen-square α
module _ {i j} {A : Type i} {B : Type j} (g : B → A) (f : A → B) where
↓-∘=idf-from-square : {x y : A} {p : x == y}
{u : g (f x) == x} {v : g (f y) == y}
→ Square u (ap g (ap f p)) p v
→ (u == v [ (λ z → g (f z) == z) ↓ p ])
↓-∘=idf-from-square {p = idp} sq = horiz-degen-path sq
↓-∘=idf-to-square : {x y : A} {p : x == y}
{u : g (f x) == x} {v : g (f y) == y}
→ (u == v [ (λ z → g (f z) == z) ↓ p ])
→ Square u (ap g (ap f p)) p v
↓-∘=idf-to-square {p = idp} α = horiz-degen-square α
_⊡v_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ a₀₂ a₁₂ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{q₀₋ : a₀₁ == a₀₂} {q₋₂ : a₀₂ == a₁₂} {q₁₋ : a₁₁ == a₁₂}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square q₀₋ p₋₁ q₋₂ q₁₋
→ Square (p₀₋ ∙ q₀₋) p₋₀ q₋₂ (p₁₋ ∙ q₁₋)
ids ⊡v sq = sq
_⊡v'_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ a₀₂ a₁₂ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{q₀₋ : a₀₁ == a₀₂} {q₋₂ : a₀₂ == a₁₂} {q₁₋ : a₁₁ == a₁₂}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square q₀₋ p₋₁ q₋₂ q₁₋
→ Square (p₀₋ ∙' q₀₋) p₋₀ q₋₂ (p₁₋ ∙' q₁₋)
sq ⊡v' ids = sq
_∙v⊡_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ p₋₀' : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ p₋₀ == p₋₀'
→ Square p₀₋ p₋₀' p₋₁ p₁₋
→ Square p₀₋ p₋₀ p₋₁ p₁₋
idp ∙v⊡ sq = sq
_⊡v∙_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₋₀ : a₀₀ == a₁₀} {p₀₋ : a₀₀ == a₀₁}
{p₋₁ p₋₁' : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ p₋₁ == p₋₁'
→ Square p₀₋ p₋₀ p₋₁' p₁₋
sq ⊡v∙ idp = sq
_⊡h_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ a₂₀ a₂₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{q₋₀ : a₁₀ == a₂₀} {q₋₁ : a₁₁ == a₂₁} {q₂₋ : a₂₀ == a₂₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square p₁₋ q₋₀ q₋₁ q₂₋
→ Square p₀₋ (p₋₀ ∙ q₋₀) (p₋₁ ∙ q₋₁) q₂₋
ids ⊡h sq = sq
_⊡h'_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ a₂₀ a₂₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{q₋₀ : a₁₀ == a₂₀} {q₋₁ : a₁₁ == a₂₁} {q₂₋ : a₂₀ == a₂₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square p₁₋ q₋₀ q₋₁ q₂₋
→ Square p₀₋ (p₋₀ ∙' q₋₀) (p₋₁ ∙' q₋₁) q₂₋
sq ⊡h' ids = sq
_∙h⊡_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ p₀₋' : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ p₀₋ == p₀₋'
→ Square p₀₋' p₋₀ p₋₁ p₁₋
→ Square p₀₋ p₋₀ p₋₁ p₁₋
idp ∙h⊡ sq = sq
_⊡h∙_ : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ p₁₋' : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ p₁₋ == p₁₋'
→ Square p₀₋ p₋₀ p₋₁ p₁₋'
sq ⊡h∙ idp = sq
infixr 80 _⊡v_ _⊡v'_ _⊡h_ _⊡h'_
infixr 80 _∙v⊡_ _∙h⊡_
infixl 85 _⊡v∙_ _⊡h∙_
∙h⊡-hid-square-⊡h∙ : ∀ {i} {A : Type i} {a₀₀ a₀₁ : A} {p p' : a₀₀ == a₀₁}
(q : p' == p)
→ ! q ∙h⊡ hid-square ⊡h∙ q == hid-square
∙h⊡-hid-square-⊡h∙ q@idp = idp
∙v⊡-assoc : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₋₀ p₋₀' p₋₀'' : a₀₀ == a₁₀} {p₀₋ : a₀₀ == a₀₁}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(q : p₋₀ == p₋₀')
(r : p₋₀' == p₋₀'')
(sq : Square p₀₋ p₋₀'' p₋₁ p₁₋)
→ (q ∙ r) ∙v⊡ sq == q ∙v⊡ (r ∙v⊡ sq)
∙v⊡-assoc q@idp r sq = idp
⊡v∙-assoc : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₋₀ : a₀₀ == a₁₀} {p₀₋ : a₀₀ == a₀₁}
{p₋₁ p₋₁' p₋₁'' : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
(q : p₋₁ == p₋₁')
(r : p₋₁' == p₋₁'')
→ (sq ⊡v∙ q) ⊡v∙ r == sq ⊡v∙ (q ∙ r)
⊡v∙-assoc sq q@idp r = idp
⊡h∙-assoc : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₋₀ : a₀₀ == a₁₀} {p₀₋ : a₀₀ == a₀₁}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ p₁₋' p₁₋'' : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
(q : p₁₋ == p₁₋')
(r : p₁₋' == p₁₋'')
→ (sq ⊡h∙ q) ⊡h∙ r == sq ⊡h∙ (q ∙ r)
⊡h∙-assoc sq q@idp r = idp
∙v⊡-⊡h∙-comm : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₋₀ p₋₀' : a₀₀ == a₁₀} {p₀₋ : a₀₀ == a₀₁}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ p₁₋' : a₁₀ == a₁₁}
(q : p₋₀ == p₋₀')
(sq : Square p₀₋ p₋₀' p₋₁ p₁₋)
(r : p₁₋ == p₁₋')
→ (q ∙v⊡ sq) ⊡h∙ r == q ∙v⊡ (sq ⊡h∙ r)
∙v⊡-⊡h∙-comm q@idp sq r = idp
⊡v∙-⊡h∙-comm : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₋₀ : a₀₀ == a₁₀} {p₀₋ : a₀₀ == a₀₁}
{p₋₁ p₋₁' : a₀₁ == a₁₁} {p₁₋ p₁₋' : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
(q : p₋₁ == p₋₁')
(r : p₁₋ == p₁₋')
→ (sq ⊡v∙ q) ⊡h∙ r == (sq ⊡h∙ r) ⊡v∙ q
⊡v∙-⊡h∙-comm sq q@idp r = idp
∙v⊡-⊡v∙-comm : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₋₀ p₋₀' : a₀₀ == a₁₀} {p₀₋ : a₀₀ == a₀₁}
{p₋₁ p₋₁' : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(q : p₋₀ == p₋₀')
(sq : Square p₀₋ p₋₀' p₋₁ p₁₋)
(r : p₋₁ == p₋₁')
→ (q ∙v⊡ sq) ⊡v∙ r == q ∙v⊡ (sq ⊡v∙ r)
∙v⊡-⊡v∙-comm q@idp sq r = idp
∙h⊡-⊡h∙-comm : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₋₀ : a₀₀ == a₁₀} {p₀₋ p₀₋' : a₀₀ == a₀₁}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ p₁₋' : a₁₀ == a₁₁}
(q : p₀₋ == p₀₋')
(sq : Square p₀₋' p₋₀ p₋₁ p₁₋)
(r : p₁₋ == p₁₋')
→ (q ∙h⊡ sq) ⊡h∙ r == q ∙h⊡ (sq ⊡h∙ r)
∙h⊡-⊡h∙-comm q@idp sq r = idp
⊡h-⊡v∙-comm : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ a₂₀ a₂₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ p₋₁' : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{q₋₀ : a₁₀ == a₂₀} {q₋₁ q₋₁' : a₁₁ == a₂₁} {q₂₋ : a₂₀ == a₂₁}
(p-sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
(q-sq : Square p₁₋ q₋₀ q₋₁ q₂₋)
(r : p₋₁ == p₋₁')
(s : q₋₁ == q₋₁')
→ (p-sq ⊡h q-sq) ⊡v∙ (ap2 _∙_ r s) == (p-sq ⊡v∙ r) ⊡h (q-sq ⊡v∙ s)
⊡h-⊡v∙-comm p-sq q-sq r@idp s@idp = idp
module _ {i j} {A : Type i} {B : Type j} (f : A → B) where
ap-square-∙v⊡ : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₋₀ p₋₀' : a₀₀ == a₁₀} {p₀₋ : a₀₀ == a₀₁}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(q : p₋₀ == p₋₀')
(sq : Square p₀₋ p₋₀' p₋₁ p₁₋)
→ ap (ap f) q ∙v⊡ ap-square f sq == ap-square f (q ∙v⊡ sq)
ap-square-∙v⊡ q@idp sq = idp
ap-square-⊡v∙ : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₋₀ : a₀₀ == a₁₀} {p₀₋ : a₀₀ == a₀₁}
{p₋₁ p₋₁' : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
(q : p₋₁ == p₋₁')
→ ap-square f sq ⊡v∙ ap (ap f) q == ap-square f (sq ⊡v∙ q)
ap-square-⊡v∙ sq q@idp = idp
module _ {i j} {A : Type i} {B : Type j} {f g : A → B} where
↓-='-to-square : {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
→ u == v [ (λ z → f z == g z) ↓ p ]
→ Square u (ap f p) (ap g p) v
↓-='-to-square {p = idp} α = horiz-degen-square α
↓-='-from-square : {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
→ Square u (ap f p) (ap g p) v
→ u == v [ (λ z → f z == g z) ↓ p ]
↓-='-from-square {p = idp} sq = horiz-degen-path sq
↓-='-square-comp : {x y z : A} {p : x == y} {q : y == z}
{u : f x == g x} {v : f y == g y} {w : f z == g z}
→ Square u (ap f p) (ap g p) v
→ Square v (ap f q) (ap g q) w
→ Square u (ap f (p ∙ q)) (ap g (p ∙ q)) w
↓-='-square-comp {p = idp} {q = idp} sq₁ sq₂ =
horiz-degen-square (horiz-degen-path sq₁ ∙ horiz-degen-path sq₂)
↓-='-from-square-comp : {x y z : A} {p : x == y} {q : y == z}
{u : f x == g x} {v : f y == g y} {w : f z == g z}
(sq₁ : Square u (ap f p) (ap g p) v)
(sq₂ : Square v (ap f q) (ap g q) w)
→ ↓-='-from-square (↓-='-square-comp sq₁ sq₂) ==
↓-='-from-square sq₁ ∙ᵈ ↓-='-from-square sq₂
↓-='-from-square-comp {p = idp} {q = idp} sq₁ sq₂ =
horiz-degen-path-β _
private
custom-square-over :
{x y z : A} {p : x == y} {q : y == z} {r : x == z}
(comp : r == p ∙ q)
{u : f x == g x} {v : f y == g y} {w : f z == g z}
(p-sq : Square u (ap f p) (ap g p) v)
(q-sq : Square v (ap f q) (ap g q) w)
(r-sq : Square u (ap f r) (ap g r) w)
→ r-sq ⊡v∙ ap (ap g) comp ==
ap (ap f) comp ∙v⊡ ↓-='-square-comp p-sq q-sq
→ r-sq == ↓-='-square-comp p-sq q-sq
[ (λ s → Square u (ap f s) (ap g s) w) ↓ comp ]
custom-square-over {p = idp} {q = idp} {r = .idp} idp p-sq q-sq r-sq e = e
↓-='-from-square-comp-path :
{x y z : A} {p : x == y} {q : y == z} {r : x == z}
(comp : r == p ∙ q)
{u : f x == g x} {v : f y == g y} {w : f z == g z}
(p-sq : Square u (ap f p) (ap g p) v)
(q-sq : Square v (ap f q) (ap g q) w)
(r-sq : Square u (ap f r) (ap g r) w)
→ r-sq ⊡v∙ ap (ap g) comp ==
ap (ap f) comp ∙v⊡ ↓-='-square-comp p-sq q-sq
→ ↓-='-from-square r-sq == ↓-='-from-square p-sq ∙ᵈ ↓-='-from-square q-sq
[ (λ p → u == w [ (λ x → f x == g x) ↓ p ]) ↓ comp ]
↓-='-from-square-comp-path comp p-sq q-sq r-sq e =
ap↓ ↓-='-from-square (custom-square-over comp p-sq q-sq r-sq e) ▹
↓-='-from-square-comp p-sq q-sq
↓-='-from-square-! : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B}
{x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
(sq : Square u (ap f p) (ap g p) v)
→ ap↓ ! (↓-='-from-square sq) == ↓-='-from-square (!□v sq)
↓-='-from-square-! {p = idp} sq =
ap ! (horiz-degen-path sq)
=⟨ ! (horiz-degen-path-β (ap ! (horiz-degen-path sq))) ⟩
horiz-degen-path (horiz-degen-square (ap ! (horiz-degen-path sq)))
=⟨ ap horiz-degen-path (! (!□v-horiz-degen-square (horiz-degen-path sq))) ⟩
horiz-degen-path (!□v (horiz-degen-square (horiz-degen-path sq)))
=⟨ ap (horiz-degen-path ∘ !□v) (horiz-degen-square-β sq) ⟩
horiz-degen-path (!□v sq) =∎
↓-='-from-square-post-∘ : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}
{f g : A → B} {h : B → C}
{x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
→ (sq : Square u (ap f p) (ap g p) v)
→ ap↓ (ap h) (↓-='-from-square sq)
==
↓-='-from-square (ap-∘ h f p ∙v⊡ ap-square h sq ⊡v∙ ∘-ap h g p)
↓-='-from-square-post-∘ {h = h} {p = idp} sq =
ap (ap h) (horiz-degen-path sq)
=⟨ ! (horiz-degen-path-β (ap (ap h) (horiz-degen-path sq))) ⟩
horiz-degen-path (horiz-degen-square (ap (ap h) (horiz-degen-path sq)))
=⟨ ap horiz-degen-path (! (ap-horiz-degen-square h (horiz-degen-path sq))) ⟩
horiz-degen-path (ap-square h (horiz-degen-square (horiz-degen-path sq)))
=⟨ ap (horiz-degen-path ∘ ap-square h) (horiz-degen-square-β sq) ⟩
horiz-degen-path (ap-square h sq) =∎
module _ {i j} {A : Type i} {B : Type j} where
natural-square : {f₁ f₂ : A → B} (h : ∀ a → f₁ a == f₂ a)
{a₁ a₂ : A} (q : a₁ == a₂)
→ Square (h a₁) (ap f₁ q) (ap f₂ q) (h a₂)
natural-square h idp = hid-square
natural-square-path : {f₁ f₂ : A → B} (h h' : ∀ a → f₁ a == f₂ a)
(H : ∀ a → h' a == h a)
{a₁ a₂ : A} (q : a₁ == a₂)
→ ! (H a₁) ∙h⊡ natural-square h' q ⊡h∙ H a₂ == natural-square h q
natural-square-path h h' H {a₁} idp = ∙h⊡-hid-square-⊡h∙ (H a₁)
natural-square-idp : {f₁ : A → B} {a₁ a₂ : A} (q : a₁ == a₂)
→ natural-square {f₁ = f₁} (λ _ → idp) q == vid-square
natural-square-idp idp = idp
natural-square-cst : ∀ (b₁ b₂ : B) (h : A → b₁ == b₂)
{a₁ a₂ : A} (q : a₁ == a₂)
→ ! (ap-cst b₁ q) ∙v⊡ natural-square {f₁ = λ a → b₁} {f₂ = λ a → b₂} h q ⊡v∙ ap-cst b₂ q
==
horiz-degen-square (ap h q)
natural-square-cst b₁ b₂ h q@idp = ! horiz-degen-square-idp
{- Used for getting square equivalents of glue-β terms -}
natural-square-β : {f₁ f₂ : A → B} (h : (a : A) → f₁ a == f₂ a)
{x y : A} (q : x == y)
{sq : Square (h x) (ap f₁ q) (ap f₂ q) (h y)}
→ apd h q == ↓-='-from-square sq
→ natural-square h q == sq
natural-square-β _ idp α =
! horiz-degen-square-idp ∙ ap horiz-degen-square α ∙ horiz-degen-square-β _
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} where
natural-square-ap : (g : B → C)
{f₁ f₂ : A → B} (h : ∀ a → f₁ a == f₂ a)
{a₁ a₂ : A} (q : a₁ == a₂)
→ natural-square (ap g ∘ h) q
==
ap-∘ g f₁ q ∙v⊡
ap-square g (natural-square h q) ⊡v∙
∘-ap g f₂ q
natural-square-ap g h q@idp = ! ap-square-hid
natural-square-symmetry : (f : A → B → C)
{a₁ a₂ : A} (p : a₁ == a₂)
{b₁ b₂ : B} (q : b₁ == b₂)
→ square-symmetry (natural-square (λ b → ap (λ a → f a b) p) q)
==
natural-square (λ a → ap (f a) q) p
natural-square-symmetry f p@idp q@idp = idp
module _ {i} {A : Type i} where
horiz-degen-path-⊡h : {a a' : A} {p q r : a == a'}
(sq₁ : Square p idp idp q)
(sq₂ : Square q idp idp r)
→ horiz-degen-path (sq₁ ⊡h sq₂) ==
horiz-degen-path sq₁ ∙ horiz-degen-path sq₂
horiz-degen-path-⊡h {p = idp} {q = .idp} ids sq₂ = idp
vert-degen-square-⊡v∙ : {a a' : A} {p q r : a == a'}
→ (s : p == q) (t : q == r)
→ vert-degen-square s ⊡v∙ t == vert-degen-square (s ∙ t)
vert-degen-square-⊡v∙ idp idp = idp
vert-degen-square-∙v⊡ : {a a' : A} {p q r : a == a'}
→ (s : p == q) (t : q == r)
→ s ∙v⊡ vert-degen-square t == vert-degen-square (s ∙ t)
vert-degen-square-∙v⊡ idp idp = idp
vert-degen-square-⊡h : {a a' a'' : A}
{p p' : a == a'} {q q' : a' == a''}
(s : p == p') (t : q == q')
→ vert-degen-square s ⊡h vert-degen-square t ==
vert-degen-square (ap2 _∙_ s t)
vert-degen-square-⊡h {p = idp} idp idp = idp
module _ {i j} {A : Type i} {B : Type j} {f g : A → B} where
↓-='-square-comp' : {x y z : A} {p : x == y} {q : y == z}
{u : f x == g x} {v : f y == g y} {w : f z == g z}
→ Square u (ap f p) (ap g p) v
→ Square v (ap f q) (ap g q) w
→ Square u (ap f (p ∙ q)) (ap g (p ∙ q)) w
↓-='-square-comp' {p = p} {q = q} sq₁ sq₂ =
ap-∙ f p q ∙v⊡ ((sq₁ ⊡h sq₂) ⊡v∙ ∙-ap g p q)
↓-='-square-comp'=↓-='-square-comp : {x y z : A} {p : x == y} {q : y == z}
{u : f x == g x} {v : f y == g y} {w : f z == g z}
→ (sq₁ : Square u (ap f p) (ap g p) v)
→ (sq₂ : Square v (ap f q) (ap g q) w)
→ ↓-='-square-comp' sq₁ sq₂ == ↓-='-square-comp sq₁ sq₂
↓-='-square-comp'=↓-='-square-comp {p = idp} {q = idp} sq₁ sq₂ =
↓-='-square-comp' sq₁ sq₂
=⟨ idp ⟩
sq₁ ⊡h sq₂
=⟨ ! (horiz-degen-square-β (sq₁ ⊡h sq₂)) ⟩
horiz-degen-square (horiz-degen-path (sq₁ ⊡h sq₂))
=⟨ ap horiz-degen-square (horiz-degen-path-⊡h sq₁ sq₂) ⟩
horiz-degen-square (horiz-degen-path sq₁ ∙ horiz-degen-path sq₂) =∎
module _ {i} {A : Type i} where
{- TODO rest of these -}
⊡h-unit-l : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ hid-square ⊡h sq == sq
⊡h-unit-l ids = idp
⊡h-unit-r : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ sq ⊡h hid-square == ∙-unit-r _ ∙v⊡ (sq ⊡v∙ ! (∙-unit-r _))
⊡h-unit-r ids = idp
⊡h'-unit-l : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ hid-square ⊡h' sq == ∙'-unit-l _ ∙v⊡ (sq ⊡v∙ ! (∙'-unit-l _))
⊡h'-unit-l ids = idp
⊡h-unit-l-unique : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq' : Square p₀₋ idp idp p₀₋) (sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ sq' ⊡h sq == sq
→ sq' == hid-square
⊡h-unit-l-unique sq' ids p = ! (⊡h-unit-r sq') ∙ p
module _ {i} {A : Type i} where
!□h-inv-l : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ (!□h sq) ⊡h sq == !-inv-l p₋₀ ∙v⊡ (hid-square ⊡v∙ ! (!-inv-l p₋₁))
!□h-inv-l ids = idp
!□h-inv-r : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ sq ⊡h (!□h sq) == !-inv-r p₋₀ ∙v⊡ (hid-square ⊡v∙ ! (!-inv-r p₋₁))
!□h-inv-r ids = idp
!□v-inv-l : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ (!□v sq) ⊡v sq == !-inv-l p₀₋ ∙h⊡ (vid-square ⊡h∙ ! (!-inv-l p₁₋))
!□v-inv-l ids = idp
!□v-inv-r : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
(sq : Square p₀₋ p₋₀ p₋₁ p₁₋)
→ sq ⊡v (!□v sq) == !-inv-r p₀₋ ∙h⊡ (vid-square ⊡h∙ ! (!-inv-r p₁₋))
!□v-inv-r ids = idp
module _ {i} {A : Type i} where
square-left-unique : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ p₀₋' : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square p₀₋' p₋₀ p₋₁ p₁₋
→ p₀₋ == p₀₋'
square-left-unique {p₋₀ = idp} {p₋₁ = idp} sq₁ sq₂ =
horiz-degen-path (sq₁ ⊡h (!□h sq₂))
square-top-unique : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ p₋₀' : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square p₀₋ p₋₀' p₋₁ p₁₋
→ p₋₀ == p₋₀'
square-top-unique {p₀₋ = idp} {p₁₋ = idp} sq₁ sq₂ =
vert-degen-path (sq₁ ⊡v (!□v sq₂))
square-bot-unique : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ p₋₁' : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square p₀₋ p₋₀ p₋₁' p₁₋
→ p₋₁ == p₋₁'
square-bot-unique {p₀₋ = idp} {p₁₋ = idp} sq₁ sq₂ =
vert-degen-path ((!□v sq₁) ⊡v sq₂)
square-right-unique : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ p₁₋' : a₁₀ == a₁₁}
→ Square p₀₋ p₋₀ p₋₁ p₁₋ → Square p₀₋ p₋₀ p₋₁ p₁₋'
→ p₁₋ == p₁₋'
square-right-unique {p₋₀ = idp} {p₋₁ = idp} sq₁ sq₂ =
horiz-degen-path ((!□h sq₁) ⊡h sq₂)
module _ {i} {A : Type i} where
{- XXX naminig -}
connection : {a₀ a₁ : A} {q : a₀ == a₁}
→ Square idp idp q q
connection {q = idp} = ids
{- XXX naminig -}
connection2 : {a₀ a₁ a₂ : A} {p : a₀ == a₁} {q : a₁ == a₂}
→ Square p p q q
connection2 {p = idp} {q = idp} = ids
lb-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square p idp (! p) idp
lb-square idp = ids
bl-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square (! p) idp p idp
bl-square idp = ids
br-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square idp idp p p
br-square idp = ids
rb-square = br-square
rt-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square idp (! p) idp p
rt-square idp = ids
tr-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square idp p idp (! p)
tr-square idp = ids
lt-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ Square p p idp idp
lt-square idp = ids
tl-square = lt-square
tr-square-∙v⊡-⊡h∙ : {a₀ a₁ : A} {p p' : a₀ == a₁} (r : p == p')
→ ! r ∙v⊡ tr-square p ⊡h∙ ap ! r == tr-square p'
tr-square-∙v⊡-⊡h∙ r@idp = idp
tr-square-! : {a₀ a₁ : A} (p : a₀ == a₁)
→ tr-square (! p) ⊡h∙ !-! p == rt-square p
tr-square-! p@idp = idp
module _ {i} {j} {A : Type i} {B : Type j} (f : A → B) where
ap-tr-square : {a₀ a₁ : A} (p : a₀ == a₁)
→ ap-square f (tr-square p) ⊡h∙ ap-! f p == tr-square (ap f p)
ap-tr-square p@idp = idp
|
{
"alphanum_fraction": 0.4754822754,
"avg_line_length": 35.7606132075,
"ext": "agda",
"hexsha": "8511adb584cbb020c674a9786e0bc66cfff27a28",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/cubical/Square.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/cubical/Square.agda",
"max_line_length": 92,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/cubical/Square.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 16249,
"size": 30325
}
|
------------------------------------------------------------------------
-- Some defined parsers, collected in a library
------------------------------------------------------------------------
-- Recursive parsers cannot be defined simply as functions, but have
-- to be defined in terms of a grammar.
-- Non-recursive parsers can either be defined directly or by using a
-- grammar. The grammar version may be harder to use in some cases,
-- but has the potential advantage of increased sharing/less memory
-- usage.
module RecursiveDescent.Inductive.Lib (tok : Set) where
open import RecursiveDescent.Index
open import RecursiveDescent.Inductive
open import RecursiveDescent.Inductive.SimpleLib
open import Utilities
open import Data.Bool
open import Data.List
open import Data.Nat
open import Data.Product.Record using (_,_)
open import Data.Product renaming (_,_ to pair)
-- The index of atLeast can only be partly inferred.
atLeast-index : Corners -> ℕ -> Index
atLeast-index c zero = _
atLeast-index c (suc n) = _
private
-- Note that the parsers are parameterised on other parsers.
data NT (nt : ParserType₁) : ParserType₁ where
many : forall {c r} ->
Parser tok nt (false , c) r ->
NT nt _ (List r)
many₁ : forall {c r} ->
Parser tok nt (false , c) r ->
NT nt _ (List r)
atLeast' : forall {c r} (n : ℕ) ->
Parser tok nt (false , c) r ->
NT nt (atLeast-index c n) (List r)
chain≥' : forall {c₁ i₂ r} (n : ℕ) ->
Assoc ->
Parser tok nt (false , c₁) r ->
Parser tok nt i₂ (r -> r -> r) ->
NT nt _ r
Nonterminal : ParserType₁ -> ParserType₁
Nonterminal = NT
module Combinators
{nt} (lib : forall {i r} -> Nonterminal nt i r -> nt i r)
where
infix 55 _⋆ _+
_⋆ : forall {c r} ->
Parser tok nt (false , c) r ->
Parser tok nt _ (List r)
p ⋆ = ! lib (many p)
_+ : forall {c r} ->
Parser tok nt (false , c) r ->
Parser tok nt _ (List r)
p + = ! lib (many₁ p)
-- At least n occurrences of p.
atLeast : forall {c r} (n : ℕ) ->
Parser tok nt (false , c) r ->
Parser tok nt _ (List r)
atLeast n p = ! lib (atLeast' n p)
-- Chains at least n occurrences of op, in an a-associative
-- manner. The ops are surrounded by ps.
chain≥ : forall {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 = ! lib (chain≥' n a p op)
library : forall {i r} -> Nonterminal nt i r -> Parser tok nt i r
library (many p) = return [] ∣ p +
library (many₁ p) = _∷_ <$> p ⊛ p ⋆
library (atLeast' zero p) = p ⋆
library (atLeast' (suc n) p) = _∷_ <$> p ⊛ atLeast n p
library (chain≥' n a p op) = chain≥-combine a <$>
p ⊛ atLeast n (op ⊗! p)
|
{
"alphanum_fraction": 0.543,
"avg_line_length": 31.5789473684,
"ext": "agda",
"hexsha": "3770447b5a9246a211db49fbcd237a10c2a2ef92",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "misc/RecursiveDescent/Inductive/Lib.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "misc/RecursiveDescent/Inductive/Lib.agda",
"max_line_length": 72,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "misc/RecursiveDescent/Inductive/Lib.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 835,
"size": 3000
}
|
-- 2010-11-16
-- compactification of Data.Set.Decoration.gmapAll
--
-- This test case fails if we remove instantiateFull
-- (and with it eta-contraction) from definition bodies in Def.hs
-- see Issue 361
-- {-# OPTIONS -v tc.lhs.unify:25 #-}
module EtaContractionDefBody where
------------------------------------------------------------------------
-- Binary relations
-- Homogeneous binary relations
Rel : Set → Set1
Rel A = A → A → Set
-- Generalised implication. If P ≡ Q it can be read as "f preserves
-- P".
_=[_]⇒_ : {A B : Set} →
Rel A → (A → B) → Rel B → Set
P =[ f ]⇒ Q = ∀ {x y} → P x y → Q (f x) (f y)
record Σ₂ {A B : Set}
(T : A → B → Set) : Set where
constructor pack₂
field
{x} : A
{y} : B
proof : T x y
-- Data.Star
infixr 5 _◅_
-- Reflexive transitive closure.
data Star {I : Set} (T : Rel I) : Rel I where
ε : ∀ {i} → Star T i i
_◅_ : ∀ {i j k} (x : T i j) (xs : Star T j k) → Star T i k
-- The type of _◅_ is Trans T (Star T) (Star T); I expanded
-- the definition in order to be able to name the arguments (x
-- and xs).
-- A generalised variant of map which allows the index type to change.
gmap : ∀ {I} {T : Rel I} {J} {U : Rel J} →
(f : I → J) → T =[ f ]⇒ U → Star T =[ f ]⇒ Star U
gmap f g ε = ε
gmap f g (x ◅ xs) = g x ◅ gmap f g xs
-- Data.Star.Decoration
EdgePred : ∀ {I} → Rel I → Set₁
EdgePred T = ∀ {i j} → T i j → Set
-- Decorating an edge with more information.
data DecoratedWith {I : Set} {T : Rel I} (P : EdgePred T)
: Rel (Σ₂ (Star T)) where
↦ : ∀ {i j k} {x : T i j} {xs : Star T j k}
(p : P x) → DecoratedWith P (pack₂ (x ◅ xs)) (pack₂ xs)
-- Star-lists decorated with extra information. All P xs means that
-- all edges in xs satisfy P.
All : ∀ {I} {T : Rel I} → EdgePred T → EdgePred (Star T)
All P {j = j} xs =
Star (DecoratedWith P) (pack₂ xs) (pack₂ {y = j} ε)
-- We can map over decorated vectors.
gmapAll : ∀ {I} {T : Rel I} {P : EdgePred T}
{J} {U : Rel J} {Q : EdgePred U}
{i j} {xs : Star T i j}
(f : I → J) (g : T =[ f ]⇒ U) →
(∀ {i j} {x : T i j} → P x → Q (g x)) →
All P xs → All {T = U} Q (gmap f g xs)
gmapAll f g h ε = ε
gmapAll f g h (↦ x ◅ xs) = ↦ (h x) ◅ gmapAll f g h xs
{- THIS WOULD BE THE ERROR MESSAGE:
/Users/abel/cover/alfa/Agda2/test/succeed/EtaContractionDefBody.agda:76,15-16
xs != ε of type Star (λ .i' .j → T .i' .j) j j
when checking that the pattern ε has type
Star (DecoratedWith (λ {.i} {.j} → P)) (pack₂ xs) (pack₂ ε)
-}
|
{
"alphanum_fraction": 0.5321277414,
"avg_line_length": 28.5604395604,
"ext": "agda",
"hexsha": "c74634b9e4c714b01e42708e4cc5fe100a6ddb70",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/agda-kanso",
"max_forks_repo_path": "test/succeed/EtaContractionDefBody.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/agda-kanso",
"max_issues_repo_path": "test/succeed/EtaContractionDefBody.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/EtaContractionDefBody.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 947,
"size": 2599
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- A bunch of properties about natural number operations
------------------------------------------------------------------------
-- See README.Data.Nat for some examples showing how this module can be
-- used.
{-# OPTIONS --without-K --safe #-}
module Data.Nat.Properties where
open import Axiom.UniquenessOfIdentityProofs
open import Algebra.Bundles
open import Algebra.Morphism
open import Algebra.Consequences.Propositional
open import Data.Bool.Base using (Bool; false; true; T)
open import Data.Bool.Properties using (T?)
open import Data.Empty
open import Data.Nat.Base
open import Data.Product
open import Data.Sum.Base as Sum
open import Data.Unit using (tt)
open import Function.Base
open import Function.Injection using (_↣_)
open import Level using (0ℓ)
open import Relation.Binary
open import Relation.Binary.Consequences using (flip-Connex)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary hiding (Irrelevant)
open import Relation.Nullary.Decidable using (True; via-injection; map′)
open import Relation.Nullary.Negation using (contradiction)
open import Algebra.Definitions {A = ℕ} _≡_
hiding (LeftCancellative; RightCancellative; Cancellative)
open import Algebra.Definitions
using (LeftCancellative; RightCancellative; Cancellative)
open import Algebra.Structures {A = ℕ} _≡_
------------------------------------------------------------------------
-- Properties of _≡_
------------------------------------------------------------------------
suc-injective : ∀ {m n} → suc m ≡ suc n → m ≡ n
suc-injective refl = refl
≡ᵇ⇒≡ : ∀ m n → T (m ≡ᵇ n) → m ≡ n
≡ᵇ⇒≡ zero zero _ = refl
≡ᵇ⇒≡ (suc m) (suc n) eq = cong suc (≡ᵇ⇒≡ m n eq)
≡⇒≡ᵇ : ∀ m n → m ≡ n → T (m ≡ᵇ n)
≡⇒≡ᵇ zero zero eq = _
≡⇒≡ᵇ (suc m) (suc n) eq = ≡⇒≡ᵇ m n (suc-injective eq)
-- NB: we use the builtin function `_≡ᵇ_` here so that the function
-- quickly decides whether to return `yes` or `no`. It still takes
-- a linear amount of time to generate the proof if it is inspected.
-- We expect the main benefit to be visible in compiled code as the
-- backend erases proofs.
infix 4 _≟_
_≟_ : Decidable {A = ℕ} _≡_
m ≟ n = map′ (≡ᵇ⇒≡ m n) (≡⇒≡ᵇ m n) (T? (m ≡ᵇ n))
≡-irrelevant : Irrelevant {A = ℕ} _≡_
≡-irrelevant = Decidable⇒UIP.≡-irrelevant _≟_
≟-diag : ∀ {m n} (eq : m ≡ n) → (m ≟ n) ≡ yes eq
≟-diag = ≡-≟-identity _≟_
≡-isDecEquivalence : IsDecEquivalence (_≡_ {A = ℕ})
≡-isDecEquivalence = record
{ isEquivalence = isEquivalence
; _≟_ = _≟_
}
≡-decSetoid : DecSetoid 0ℓ 0ℓ
≡-decSetoid = record
{ Carrier = ℕ
; _≈_ = _≡_
; isDecEquivalence = ≡-isDecEquivalence
}
0≢1+n : ∀ {n} → 0 ≢ suc n
0≢1+n ()
1+n≢0 : ∀ {n} → suc n ≢ 0
1+n≢0 ()
1+n≢n : ∀ {n} → suc n ≢ n
1+n≢n {suc n} = 1+n≢n ∘ suc-injective
------------------------------------------------------------------------
-- Properties of _<ᵇ_
------------------------------------------------------------------------
<ᵇ⇒< : ∀ m n → T (m <ᵇ n) → m < n
<ᵇ⇒< zero (suc n) m<n = s≤s z≤n
<ᵇ⇒< (suc m) (suc n) m<n = s≤s (<ᵇ⇒< m n m<n)
<⇒<ᵇ : ∀ {m n} → m < n → T (m <ᵇ n)
<⇒<ᵇ (s≤s z≤n) = tt
<⇒<ᵇ (s≤s (s≤s m<n)) = <⇒<ᵇ (s≤s m<n)
------------------------------------------------------------------------
-- Properties of _≤_
------------------------------------------------------------------------
≤-pred : ∀ {m n} → suc m ≤ suc n → m ≤ n
≤-pred (s≤s m≤n) = m≤n
------------------------------------------------------------------------
-- Relational properties of _≤_
≤-reflexive : _≡_ ⇒ _≤_
≤-reflexive {zero} refl = z≤n
≤-reflexive {suc m} refl = s≤s (≤-reflexive refl)
≤-refl : Reflexive _≤_
≤-refl = ≤-reflexive refl
≤-antisym : Antisymmetric _≡_ _≤_
≤-antisym z≤n z≤n = refl
≤-antisym (s≤s m≤n) (s≤s n≤m) = cong suc (≤-antisym m≤n n≤m)
≤-trans : Transitive _≤_
≤-trans z≤n _ = z≤n
≤-trans (s≤s m≤n) (s≤s n≤o) = s≤s (≤-trans m≤n n≤o)
≤-total : Total _≤_
≤-total zero _ = inj₁ z≤n
≤-total _ zero = inj₂ z≤n
≤-total (suc m) (suc n) with ≤-total m n
... | inj₁ m≤n = inj₁ (s≤s m≤n)
... | inj₂ n≤m = inj₂ (s≤s n≤m)
≤-irrelevant : Irrelevant _≤_
≤-irrelevant z≤n z≤n = refl
≤-irrelevant (s≤s m≤n₁) (s≤s m≤n₂) = cong s≤s (≤-irrelevant m≤n₁ m≤n₂)
-- NB: we use the builtin function `_<ᵇ_` here so that the function
-- quickly decides whether to return `yes` or `no`. It still takes
-- a linear amount of time to generate the proof if it is inspected.
-- We expect the main benefit to be visible in compiled code as the
-- backend erases proofs.
infix 4 _≤?_ _≥?_
_≤?_ : Decidable _≤_
zero ≤? _ = yes z≤n
suc m ≤? n = map′ (<ᵇ⇒< m n) <⇒<ᵇ (T? (m <ᵇ n))
_≥?_ : Decidable _≥_
_≥?_ = flip _≤?_
------------------------------------------------------------------------
-- Structures
≤-isPreorder : IsPreorder _≡_ _≤_
≤-isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = ≤-reflexive
; trans = ≤-trans
}
≤-isPartialOrder : IsPartialOrder _≡_ _≤_
≤-isPartialOrder = record
{ isPreorder = ≤-isPreorder
; antisym = ≤-antisym
}
≤-isTotalOrder : IsTotalOrder _≡_ _≤_
≤-isTotalOrder = record
{ isPartialOrder = ≤-isPartialOrder
; total = ≤-total
}
≤-isDecTotalOrder : IsDecTotalOrder _≡_ _≤_
≤-isDecTotalOrder = record
{ isTotalOrder = ≤-isTotalOrder
; _≟_ = _≟_
; _≤?_ = _≤?_
}
------------------------------------------------------------------------
-- Bundles
≤-preorder : Preorder 0ℓ 0ℓ 0ℓ
≤-preorder = record
{ isPreorder = ≤-isPreorder
}
≤-poset : Poset 0ℓ 0ℓ 0ℓ
≤-poset = record
{ isPartialOrder = ≤-isPartialOrder
}
≤-totalOrder : TotalOrder 0ℓ 0ℓ 0ℓ
≤-totalOrder = record
{ isTotalOrder = ≤-isTotalOrder
}
≤-decTotalOrder : DecTotalOrder 0ℓ 0ℓ 0ℓ
≤-decTotalOrder = record
{ isDecTotalOrder = ≤-isDecTotalOrder
}
------------------------------------------------------------------------
-- Other properties of _≤_
s≤s-injective : ∀ {m n} {p q : m ≤ n} → s≤s p ≡ s≤s q → p ≡ q
s≤s-injective refl = refl
≤-step : ∀ {m n} → m ≤ n → m ≤ 1 + n
≤-step z≤n = z≤n
≤-step (s≤s m≤n) = s≤s (≤-step m≤n)
n≤1+n : ∀ n → n ≤ 1 + n
n≤1+n _ = ≤-step ≤-refl
1+n≰n : ∀ {n} → 1 + n ≰ n
1+n≰n (s≤s le) = 1+n≰n le
n≤0⇒n≡0 : ∀ {n} → n ≤ 0 → n ≡ 0
n≤0⇒n≡0 z≤n = refl
------------------------------------------------------------------------
-- Properties of _<_
------------------------------------------------------------------------
-- Relationships between the various relations
<⇒≤ : _<_ ⇒ _≤_
<⇒≤ (s≤s m≤n) = ≤-trans m≤n (≤-step ≤-refl)
<⇒≢ : _<_ ⇒ _≢_
<⇒≢ m<n refl = 1+n≰n m<n
≤⇒≯ : _≤_ ⇒ _≯_
≤⇒≯ (s≤s m≤n) (s≤s n≤m) = ≤⇒≯ m≤n n≤m
<⇒≱ : _<_ ⇒ _≱_
<⇒≱ (s≤s m+1≤n) (s≤s n≤m) = <⇒≱ m+1≤n n≤m
<⇒≯ : _<_ ⇒ _≯_
<⇒≯ (s≤s m<n) (s≤s n<m) = <⇒≯ m<n n<m
≰⇒≮ : _≰_ ⇒ _≮_
≰⇒≮ m≰n 1+m≤n = m≰n (<⇒≤ 1+m≤n)
≰⇒> : _≰_ ⇒ _>_
≰⇒> {zero} z≰n = contradiction z≤n z≰n
≰⇒> {suc m} {zero} _ = s≤s z≤n
≰⇒> {suc m} {suc n} m≰n = s≤s (≰⇒> (m≰n ∘ s≤s))
≰⇒≥ : _≰_ ⇒ _≥_
≰⇒≥ = <⇒≤ ∘ ≰⇒>
≮⇒≥ : _≮_ ⇒ _≥_
≮⇒≥ {_} {zero} _ = z≤n
≮⇒≥ {zero} {suc j} 1≮j+1 = contradiction (s≤s z≤n) 1≮j+1
≮⇒≥ {suc i} {suc j} i+1≮j+1 = s≤s (≮⇒≥ (i+1≮j+1 ∘ s≤s))
≤∧≢⇒< : ∀ {m n} → m ≤ n → m ≢ n → m < n
≤∧≢⇒< {_} {zero} z≤n m≢n = contradiction refl m≢n
≤∧≢⇒< {_} {suc n} z≤n m≢n = s≤s z≤n
≤∧≢⇒< {_} {suc n} (s≤s m≤n) 1+m≢1+n =
s≤s (≤∧≢⇒< m≤n (1+m≢1+n ∘ cong suc))
≤-<-connex : Connex _≤_ _<_
≤-<-connex m n with m ≤? n
... | yes m≤n = inj₁ m≤n
... | no ¬m≤n = inj₂ (≰⇒> ¬m≤n)
≥->-connex : Connex _≥_ _>_
≥->-connex = flip ≤-<-connex
<-≤-connex : Connex _<_ _≤_
<-≤-connex = flip-Connex ≤-<-connex
>-≥-connex : Connex _>_ _≥_
>-≥-connex = flip-Connex ≥->-connex
------------------------------------------------------------------------
-- Relational properties of _<_
<-irrefl : Irreflexive _≡_ _<_
<-irrefl refl (s≤s n<n) = <-irrefl refl n<n
<-asym : Asymmetric _<_
<-asym (s≤s n<m) (s≤s m<n) = <-asym n<m m<n
<-trans : Transitive _<_
<-trans (s≤s i≤j) (s≤s j<k) = s≤s (≤-trans i≤j (≤-trans (n≤1+n _) j<k))
<-transʳ : Trans _≤_ _<_ _<_
<-transʳ m≤n (s≤s n≤o) = s≤s (≤-trans m≤n n≤o)
<-transˡ : Trans _<_ _≤_ _<_
<-transˡ (s≤s m≤n) (s≤s n≤o) = s≤s (≤-trans m≤n n≤o)
-- NB: we use the builtin function `_<ᵇ_` here so that the function
-- quickly decides which constructor to return. It still takes a
-- linear amount of time to generate the proof if it is inspected.
-- We expect the main benefit to be visible in compiled code as the
-- backend erases proofs.
<-cmp : Trichotomous _≡_ _<_
<-cmp m n with m ≟ n | T? (m <ᵇ n)
... | yes m≡n | _ = tri≈ (<-irrefl m≡n) m≡n (<-irrefl (sym m≡n))
... | no m≢n | yes m<n = tri< (<ᵇ⇒< m n m<n) m≢n (<⇒≯ (<ᵇ⇒< m n m<n))
... | no m≢n | no m≮n = tri> (m≮n ∘ <⇒<ᵇ) m≢n (≤∧≢⇒< (≮⇒≥ (m≮n ∘ <⇒<ᵇ)) (m≢n ∘ sym))
infix 4 _<?_ _>?_
_<?_ : Decidable _<_
m <? n = suc m ≤? n
_>?_ : Decidable _>_
_>?_ = flip _<?_
<-irrelevant : Irrelevant _<_
<-irrelevant = ≤-irrelevant
<-resp₂-≡ : _<_ Respects₂ _≡_
<-resp₂-≡ = subst (_ <_) , subst (_< _)
------------------------------------------------------------------------
-- Bundles
<-isStrictPartialOrder : IsStrictPartialOrder _≡_ _<_
<-isStrictPartialOrder = record
{ isEquivalence = isEquivalence
; irrefl = <-irrefl
; trans = <-trans
; <-resp-≈ = <-resp₂-≡
}
<-isStrictTotalOrder : IsStrictTotalOrder _≡_ _<_
<-isStrictTotalOrder = record
{ isEquivalence = isEquivalence
; trans = <-trans
; compare = <-cmp
}
<-strictPartialOrder : StrictPartialOrder 0ℓ 0ℓ 0ℓ
<-strictPartialOrder = record
{ isStrictPartialOrder = <-isStrictPartialOrder
}
<-strictTotalOrder : StrictTotalOrder 0ℓ 0ℓ 0ℓ
<-strictTotalOrder = record
{ isStrictTotalOrder = <-isStrictTotalOrder
}
------------------------------------------------------------------------
-- Other properties of _<_
n≮n : ∀ n → n ≮ n
n≮n n = <-irrefl (refl {x = n})
0<1+n : ∀ {n} → 0 < suc n
0<1+n = s≤s z≤n
n<1+n : ∀ n → n < suc n
n<1+n n = ≤-refl
n≢0⇒n>0 : ∀ {n} → n ≢ 0 → n > 0
n≢0⇒n>0 {zero} 0≢0 = contradiction refl 0≢0
n≢0⇒n>0 {suc n} _ = 0<1+n
m<n⇒n≢0 : ∀ {m n} → m < n → n ≢ 0
m<n⇒n≢0 (s≤s m≤n) ()
m<n⇒m≤1+n : ∀ {m n} → m < n → m ≤ suc n
m<n⇒m≤1+n (s≤s z≤n) = z≤n
m<n⇒m≤1+n (s≤s (s≤s m<n)) = s≤s (m<n⇒m≤1+n (s≤s m<n))
∀[m≤n⇒m≢o]⇒n<o : ∀ n o → (∀ {m} → m ≤ n → m ≢ o) → n < o
∀[m≤n⇒m≢o]⇒n<o _ zero m≤n⇒n≢0 = contradiction refl (m≤n⇒n≢0 z≤n)
∀[m≤n⇒m≢o]⇒n<o zero (suc o) _ = 0<1+n
∀[m≤n⇒m≢o]⇒n<o (suc n) (suc o) m≤n⇒n≢o = s≤s (∀[m≤n⇒m≢o]⇒n<o n o rec)
where
rec : ∀ {m} → m ≤ n → m ≢ o
rec m≤n refl = m≤n⇒n≢o (s≤s m≤n) refl
∀[m<n⇒m≢o]⇒n≤o : ∀ n o → (∀ {m} → m < n → m ≢ o) → n ≤ o
∀[m<n⇒m≢o]⇒n≤o zero n _ = z≤n
∀[m<n⇒m≢o]⇒n≤o (suc n) zero m<n⇒m≢0 = contradiction refl (m<n⇒m≢0 0<1+n)
∀[m<n⇒m≢o]⇒n≤o (suc n) (suc o) m<n⇒m≢o = s≤s (∀[m<n⇒m≢o]⇒n≤o n o rec)
where
rec : ∀ {m} → m < n → m ≢ o
rec x<m refl = m<n⇒m≢o (s≤s x<m) refl
------------------------------------------------------------------------
-- A module for reasoning about the _≤_ and _<_ relations
------------------------------------------------------------------------
module ≤-Reasoning where
open import Relation.Binary.Reasoning.Base.Triple
≤-isPreorder
<-trans
(resp₂ _<_)
<⇒≤
<-transˡ
<-transʳ
public
hiding (step-≈; step-≈˘)
open ≤-Reasoning
------------------------------------------------------------------------
-- Properties of pred
------------------------------------------------------------------------
pred-mono : pred Preserves _≤_ ⟶ _≤_
pred-mono z≤n = z≤n
pred-mono (s≤s le) = le
≤pred⇒≤ : ∀ {m n} → m ≤ pred n → m ≤ n
≤pred⇒≤ {m} {zero} le = le
≤pred⇒≤ {m} {suc n} le = ≤-step le
≤⇒pred≤ : ∀ {m n} → m ≤ n → pred m ≤ n
≤⇒pred≤ {zero} le = le
≤⇒pred≤ {suc m} le = ≤-trans (n≤1+n m) le
<⇒≤pred : ∀ {m n} → m < n → m ≤ pred n
<⇒≤pred (s≤s le) = le
suc[pred[n]]≡n : ∀ {n} → n ≢ 0 → suc (pred n) ≡ n
suc[pred[n]]≡n {zero} n≢0 = contradiction refl n≢0
suc[pred[n]]≡n {suc n} n≢0 = refl
------------------------------------------------------------------------
-- Properties of _+_
------------------------------------------------------------------------
+-suc : ∀ m n → m + suc n ≡ suc (m + n)
+-suc zero n = refl
+-suc (suc m) n = cong suc (+-suc m n)
------------------------------------------------------------------------
-- Algebraic properties of _+_
+-assoc : Associative _+_
+-assoc zero _ _ = refl
+-assoc (suc m) n o = cong suc (+-assoc m n o)
+-identityˡ : LeftIdentity 0 _+_
+-identityˡ _ = refl
+-identityʳ : RightIdentity 0 _+_
+-identityʳ zero = refl
+-identityʳ (suc n) = cong suc (+-identityʳ n)
+-identity : Identity 0 _+_
+-identity = +-identityˡ , +-identityʳ
+-comm : Commutative _+_
+-comm zero n = sym (+-identityʳ n)
+-comm (suc m) n = begin-equality
suc m + n ≡⟨⟩
suc (m + n) ≡⟨ cong suc (+-comm m n) ⟩
suc (n + m) ≡⟨ sym (+-suc n m) ⟩
n + suc m ∎
+-cancelˡ-≡ : LeftCancellative _≡_ _+_
+-cancelˡ-≡ zero eq = eq
+-cancelˡ-≡ (suc m) eq = +-cancelˡ-≡ m (cong pred eq)
+-cancelʳ-≡ : RightCancellative _≡_ _+_
+-cancelʳ-≡ = comm+cancelˡ⇒cancelʳ +-comm +-cancelˡ-≡
+-cancel-≡ : Cancellative _≡_ _+_
+-cancel-≡ = +-cancelˡ-≡ , +-cancelʳ-≡
------------------------------------------------------------------------
-- Structures
+-isMagma : IsMagma _+_
+-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _+_
}
+-isSemigroup : IsSemigroup _+_
+-isSemigroup = record
{ isMagma = +-isMagma
; assoc = +-assoc
}
+-isCommutativeSemigroup : IsCommutativeSemigroup _+_
+-isCommutativeSemigroup = record
{ isSemigroup = +-isSemigroup
; comm = +-comm
}
+-0-isMonoid : IsMonoid _+_ 0
+-0-isMonoid = record
{ isSemigroup = +-isSemigroup
; identity = +-identity
}
+-0-isCommutativeMonoid : IsCommutativeMonoid _+_ 0
+-0-isCommutativeMonoid = record
{ isMonoid = +-0-isMonoid
; comm = +-comm
}
------------------------------------------------------------------------
-- Raw bundles
+-rawMagma : RawMagma 0ℓ 0ℓ
+-rawMagma = record
{ _≈_ = _≡_
; _∙_ = _+_
}
+-0-rawMonoid : RawMonoid 0ℓ 0ℓ
+-0-rawMonoid = record
{ _≈_ = _≡_
; _∙_ = _+_
; ε = 0
}
------------------------------------------------------------------------
-- Bundles
+-magma : Magma 0ℓ 0ℓ
+-magma = record
{ isMagma = +-isMagma
}
+-semigroup : Semigroup 0ℓ 0ℓ
+-semigroup = record
{ isSemigroup = +-isSemigroup
}
+-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ
+-commutativeSemigroup = record
{ isCommutativeSemigroup = +-isCommutativeSemigroup
}
+-0-monoid : Monoid 0ℓ 0ℓ
+-0-monoid = record
{ isMonoid = +-0-isMonoid
}
+-0-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
+-0-commutativeMonoid = record
{ isCommutativeMonoid = +-0-isCommutativeMonoid
}
------------------------------------------------------------------------
-- Other properties of _+_ and _≡_
m≢1+m+n : ∀ m {n} → m ≢ suc (m + n)
m≢1+m+n (suc m) eq = m≢1+m+n m (cong pred eq)
m≢1+n+m : ∀ m {n} → m ≢ suc (n + m)
m≢1+n+m m m≡1+n+m = m≢1+m+n m (trans m≡1+n+m (cong suc (+-comm _ m)))
m+1+n≢m : ∀ m {n} → m + suc n ≢ m
m+1+n≢m (suc m) = (m+1+n≢m m) ∘ suc-injective
m+1+n≢0 : ∀ m {n} → m + suc n ≢ 0
m+1+n≢0 m {n} rewrite +-suc m n = λ()
m+n≡0⇒m≡0 : ∀ m {n} → m + n ≡ 0 → m ≡ 0
m+n≡0⇒m≡0 zero eq = refl
m+n≡0⇒n≡0 : ∀ m {n} → m + n ≡ 0 → n ≡ 0
m+n≡0⇒n≡0 m {n} m+n≡0 = m+n≡0⇒m≡0 n (trans (+-comm n m) (m+n≡0))
------------------------------------------------------------------------
-- Properties of _+_ and _≤_/_<_
+-cancelˡ-≤ : LeftCancellative _≤_ _+_
+-cancelˡ-≤ zero le = le
+-cancelˡ-≤ (suc m) (s≤s le) = +-cancelˡ-≤ m le
+-cancelʳ-≤ : RightCancellative _≤_ _+_
+-cancelʳ-≤ {m} n o le =
+-cancelˡ-≤ m (subst₂ _≤_ (+-comm n m) (+-comm o m) le)
+-cancel-≤ : Cancellative _≤_ _+_
+-cancel-≤ = +-cancelˡ-≤ , +-cancelʳ-≤
+-cancelˡ-< : LeftCancellative _<_ _+_
+-cancelˡ-< m {n} {o} = +-cancelˡ-≤ m ∘ subst (_≤ m + o) (sym (+-suc m n))
+-cancelʳ-< : RightCancellative _<_ _+_
+-cancelʳ-< n o n+m<o+m = +-cancelʳ-≤ (suc n) o n+m<o+m
+-cancel-< : Cancellative _<_ _+_
+-cancel-< = +-cancelˡ-< , +-cancelʳ-<
≤-stepsˡ : ∀ {m n} o → m ≤ n → m ≤ o + n
≤-stepsˡ zero m≤n = m≤n
≤-stepsˡ (suc o) m≤n = ≤-step (≤-stepsˡ o m≤n)
≤-stepsʳ : ∀ {m n} o → m ≤ n → m ≤ n + o
≤-stepsʳ {m} o m≤n = subst (m ≤_) (+-comm o _) (≤-stepsˡ o m≤n)
m≤m+n : ∀ m n → m ≤ m + n
m≤m+n zero n = z≤n
m≤m+n (suc m) n = s≤s (m≤m+n m n)
m≤n+m : ∀ m n → m ≤ n + m
m≤n+m m n = subst (m ≤_) (+-comm m n) (m≤m+n m n)
m≤n⇒m<n∨m≡n : ∀ {m n} → m ≤ n → m < n ⊎ m ≡ n
m≤n⇒m<n∨m≡n {0} {0} _ = inj₂ refl
m≤n⇒m<n∨m≡n {0} {suc n} _ = inj₁ 0<1+n
m≤n⇒m<n∨m≡n {suc m} {suc n} (s≤s m≤n) with m≤n⇒m<n∨m≡n m≤n
... | inj₂ m≡n = inj₂ (cong suc m≡n)
... | inj₁ m<n = inj₁ (s≤s m<n)
m+n≤o⇒m≤o : ∀ m {n o} → m + n ≤ o → m ≤ o
m+n≤o⇒m≤o zero m+n≤o = z≤n
m+n≤o⇒m≤o (suc m) (s≤s m+n≤o) = s≤s (m+n≤o⇒m≤o m m+n≤o)
m+n≤o⇒n≤o : ∀ m {n o} → m + n ≤ o → n ≤ o
m+n≤o⇒n≤o zero n≤o = n≤o
m+n≤o⇒n≤o (suc m) m+n<o = m+n≤o⇒n≤o m (<⇒≤ m+n<o)
+-mono-≤ : _+_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
+-mono-≤ {_} {m} z≤n o≤p = ≤-trans o≤p (m≤n+m _ m)
+-mono-≤ {_} {_} (s≤s m≤n) o≤p = s≤s (+-mono-≤ m≤n o≤p)
+-monoˡ-≤ : ∀ n → (_+ n) Preserves _≤_ ⟶ _≤_
+-monoˡ-≤ n m≤o = +-mono-≤ m≤o (≤-refl {n})
+-monoʳ-≤ : ∀ n → (n +_) Preserves _≤_ ⟶ _≤_
+-monoʳ-≤ n m≤o = +-mono-≤ (≤-refl {n}) m≤o
+-mono-<-≤ : _+_ Preserves₂ _<_ ⟶ _≤_ ⟶ _<_
+-mono-<-≤ {_} {suc n} (s≤s z≤n) o≤p = s≤s (≤-stepsˡ n o≤p)
+-mono-<-≤ {_} {_} (s≤s (s≤s m<n)) o≤p = s≤s (+-mono-<-≤ (s≤s m<n) o≤p)
+-mono-≤-< : _+_ Preserves₂ _≤_ ⟶ _<_ ⟶ _<_
+-mono-≤-< {_} {n} z≤n o<p = ≤-trans o<p (m≤n+m _ n)
+-mono-≤-< {_} {_} (s≤s m≤n) o<p = s≤s (+-mono-≤-< m≤n o<p)
+-mono-< : _+_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
+-mono-< m≤n = +-mono-≤-< (<⇒≤ m≤n)
+-monoˡ-< : ∀ n → (_+ n) Preserves _<_ ⟶ _<_
+-monoˡ-< n = +-monoˡ-≤ n
+-monoʳ-< : ∀ n → (n +_) Preserves _<_ ⟶ _<_
+-monoʳ-< zero m≤o = m≤o
+-monoʳ-< (suc n) m≤o = s≤s (+-monoʳ-< n m≤o)
m+1+n≰m : ∀ m {n} → m + suc n ≰ m
m+1+n≰m (suc m) le = m+1+n≰m m (≤-pred le)
m<m+n : ∀ m {n} → n > 0 → m < m + n
m<m+n zero n>0 = n>0
m<m+n (suc m) n>0 = s≤s (m<m+n m n>0)
m<n+m : ∀ m {n} → n > 0 → m < n + m
m<n+m m {n} n>0 rewrite +-comm n m = m<m+n m n>0
m+n≮n : ∀ m n → m + n ≮ n
m+n≮n zero n = n≮n n
m+n≮n (suc m) (suc n) (s≤s m+n<n) = m+n≮n m (suc n) (≤-step m+n<n)
m+n≮m : ∀ m n → m + n ≮ m
m+n≮m m n = subst (_≮ m) (+-comm n m) (m+n≮n n m)
------------------------------------------------------------------------
-- Properties of _*_
------------------------------------------------------------------------
*-suc : ∀ m n → m * suc n ≡ m + m * n
*-suc zero n = refl
*-suc (suc m) n = begin-equality
suc m * suc n ≡⟨⟩
suc n + m * suc n ≡⟨ cong (suc n +_) (*-suc m n) ⟩
suc n + (m + m * n) ≡⟨⟩
suc (n + (m + m * n)) ≡⟨ cong suc (sym (+-assoc n m (m * n))) ⟩
suc (n + m + m * n) ≡⟨ cong (λ x → suc (x + m * n)) (+-comm n m) ⟩
suc (m + n + m * n) ≡⟨ cong suc (+-assoc m n (m * n)) ⟩
suc (m + (n + m * n)) ≡⟨⟩
suc m + suc m * n ∎
------------------------------------------------------------------------
-- Algebraic properties of _*_
*-identityˡ : LeftIdentity 1 _*_
*-identityˡ n = +-identityʳ n
*-identityʳ : RightIdentity 1 _*_
*-identityʳ zero = refl
*-identityʳ (suc n) = cong suc (*-identityʳ n)
*-identity : Identity 1 _*_
*-identity = *-identityˡ , *-identityʳ
*-zeroˡ : LeftZero 0 _*_
*-zeroˡ _ = refl
*-zeroʳ : RightZero 0 _*_
*-zeroʳ zero = refl
*-zeroʳ (suc n) = *-zeroʳ n
*-zero : Zero 0 _*_
*-zero = *-zeroˡ , *-zeroʳ
*-comm : Commutative _*_
*-comm zero n = sym (*-zeroʳ n)
*-comm (suc m) n = begin-equality
suc m * n ≡⟨⟩
n + m * n ≡⟨ cong (n +_) (*-comm m n) ⟩
n + n * m ≡⟨ sym (*-suc n m) ⟩
n * suc m ∎
*-distribʳ-+ : _*_ DistributesOverʳ _+_
*-distribʳ-+ m zero o = refl
*-distribʳ-+ m (suc n) o = begin-equality
(suc n + o) * m ≡⟨⟩
m + (n + o) * m ≡⟨ cong (m +_) (*-distribʳ-+ m n o) ⟩
m + (n * m + o * m) ≡⟨ sym (+-assoc m (n * m) (o * m)) ⟩
m + n * m + o * m ≡⟨⟩
suc n * m + o * m ∎
*-distribˡ-+ : _*_ DistributesOverˡ _+_
*-distribˡ-+ = comm+distrʳ⇒distrˡ *-comm *-distribʳ-+
*-distrib-+ : _*_ DistributesOver _+_
*-distrib-+ = *-distribˡ-+ , *-distribʳ-+
*-assoc : Associative _*_
*-assoc zero n o = refl
*-assoc (suc m) n o = begin-equality
(suc m * n) * o ≡⟨⟩
(n + m * n) * o ≡⟨ *-distribʳ-+ o n (m * n) ⟩
n * o + (m * n) * o ≡⟨ cong (n * o +_) (*-assoc m n o) ⟩
n * o + m * (n * o) ≡⟨⟩
suc m * (n * o) ∎
------------------------------------------------------------------------
-- Structures
*-isMagma : IsMagma _*_
*-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _*_
}
*-isSemigroup : IsSemigroup _*_
*-isSemigroup = record
{ isMagma = *-isMagma
; assoc = *-assoc
}
*-isCommutativeSemigroup : IsCommutativeSemigroup _*_
*-isCommutativeSemigroup = record
{ isSemigroup = *-isSemigroup
; comm = *-comm
}
*-1-isMonoid : IsMonoid _*_ 1
*-1-isMonoid = record
{ isSemigroup = *-isSemigroup
; identity = *-identity
}
*-1-isCommutativeMonoid : IsCommutativeMonoid _*_ 1
*-1-isCommutativeMonoid = record
{ isMonoid = *-1-isMonoid
; comm = *-comm
}
*-+-isSemiring : IsSemiring _+_ _*_ 0 1
*-+-isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-0-isCommutativeMonoid
; *-isMonoid = *-1-isMonoid
; distrib = *-distrib-+
}
; zero = *-zero
}
*-+-isCommutativeSemiring : IsCommutativeSemiring _+_ _*_ 0 1
*-+-isCommutativeSemiring = record
{ isSemiring = *-+-isSemiring
; *-comm = *-comm
}
------------------------------------------------------------------------
-- Bundles
*-rawMagma : RawMagma 0ℓ 0ℓ
*-rawMagma = record
{ _≈_ = _≡_
; _∙_ = _*_
}
*-1-rawMonoid : RawMonoid 0ℓ 0ℓ
*-1-rawMonoid = record
{ _≈_ = _≡_
; _∙_ = _*_
; ε = 1
}
*-magma : Magma 0ℓ 0ℓ
*-magma = record
{ isMagma = *-isMagma
}
*-semigroup : Semigroup 0ℓ 0ℓ
*-semigroup = record
{ isSemigroup = *-isSemigroup
}
*-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ
*-commutativeSemigroup = record
{ isCommutativeSemigroup = *-isCommutativeSemigroup
}
*-1-monoid : Monoid 0ℓ 0ℓ
*-1-monoid = record
{ isMonoid = *-1-isMonoid
}
*-1-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
*-1-commutativeMonoid = record
{ isCommutativeMonoid = *-1-isCommutativeMonoid
}
*-+-semiring : Semiring 0ℓ 0ℓ
*-+-semiring = record
{ isSemiring = *-+-isSemiring
}
*-+-commutativeSemiring : CommutativeSemiring 0ℓ 0ℓ
*-+-commutativeSemiring = record
{ isCommutativeSemiring = *-+-isCommutativeSemiring
}
------------------------------------------------------------------------
-- Other properties of _*_ and _≡_
*-cancelʳ-≡ : ∀ m n {o} → m * suc o ≡ n * suc o → m ≡ n
*-cancelʳ-≡ zero zero eq = refl
*-cancelʳ-≡ (suc m) (suc n) {o} eq =
cong suc (*-cancelʳ-≡ m n (+-cancelˡ-≡ (suc o) eq))
*-cancelˡ-≡ : ∀ {m n} o → suc o * m ≡ suc o * n → m ≡ n
*-cancelˡ-≡ {m} {n} o eq = *-cancelʳ-≡ m n
(subst₂ _≡_ (*-comm (suc o) m) (*-comm (suc o) n) eq)
m*n≡0⇒m≡0∨n≡0 : ∀ m {n} → m * n ≡ 0 → m ≡ 0 ⊎ n ≡ 0
m*n≡0⇒m≡0∨n≡0 zero {n} eq = inj₁ refl
m*n≡0⇒m≡0∨n≡0 (suc m) {zero} eq = inj₂ refl
m*n≡1⇒m≡1 : ∀ m n → m * n ≡ 1 → m ≡ 1
m*n≡1⇒m≡1 (suc zero) n _ = refl
m*n≡1⇒m≡1 (suc (suc m)) (suc zero) ()
m*n≡1⇒m≡1 (suc (suc m)) zero eq =
contradiction (trans (sym $ *-zeroʳ m) eq) λ()
m*n≡1⇒n≡1 : ∀ m n → m * n ≡ 1 → n ≡ 1
m*n≡1⇒n≡1 m n eq = m*n≡1⇒m≡1 n m (trans (*-comm n m) eq)
------------------------------------------------------------------------
-- Other properties of _*_ and _≤_/_<_
*-cancelʳ-≤ : ∀ m n o → m * suc o ≤ n * suc o → m ≤ n
*-cancelʳ-≤ zero _ _ _ = z≤n
*-cancelʳ-≤ (suc m) (suc n) o le =
s≤s (*-cancelʳ-≤ m n o (+-cancelˡ-≤ (suc o) le))
*-cancelˡ-≤ : ∀ {m n} o → suc o * m ≤ suc o * n → m ≤ n
*-cancelˡ-≤ {m} {n} o rewrite *-comm (suc o) m | *-comm (suc o) n = *-cancelʳ-≤ m n o
*-mono-≤ : _*_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
*-mono-≤ z≤n _ = z≤n
*-mono-≤ (s≤s m≤n) u≤v = +-mono-≤ u≤v (*-mono-≤ m≤n u≤v)
*-monoˡ-≤ : ∀ n → (_* n) Preserves _≤_ ⟶ _≤_
*-monoˡ-≤ n m≤o = *-mono-≤ m≤o (≤-refl {n})
*-monoʳ-≤ : ∀ n → (n *_) Preserves _≤_ ⟶ _≤_
*-monoʳ-≤ n m≤o = *-mono-≤ (≤-refl {n}) m≤o
*-mono-< : _*_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
*-mono-< (s≤s z≤n) (s≤s u≤v) = s≤s z≤n
*-mono-< (s≤s (s≤s m≤n)) (s≤s u≤v) =
+-mono-< (s≤s u≤v) (*-mono-< (s≤s m≤n) (s≤s u≤v))
*-monoˡ-< : ∀ n → (_* suc n) Preserves _<_ ⟶ _<_
*-monoˡ-< n (s≤s z≤n) = s≤s z≤n
*-monoˡ-< n (s≤s (s≤s m≤o)) =
+-mono-≤-< (≤-refl {suc n}) (*-monoˡ-< n (s≤s m≤o))
*-monoʳ-< : ∀ n → (suc n *_) Preserves _<_ ⟶ _<_
*-monoʳ-< zero (s≤s m≤o) = +-mono-≤ (s≤s m≤o) z≤n
*-monoʳ-< (suc n) (s≤s m≤o) =
+-mono-≤ (s≤s m≤o) (<⇒≤ (*-monoʳ-< n (s≤s m≤o)))
m≤m*n : ∀ m {n} → 0 < n → m ≤ m * n
m≤m*n m {n} 0<n = begin
m ≡⟨ sym (*-identityʳ m) ⟩
m * 1 ≤⟨ *-monoʳ-≤ m 0<n ⟩
m * n ∎
m<m*n : ∀ {m n} → 0 < m → 1 < n → m < m * n
m<m*n {m@(suc m-1)} {n@(suc (suc n-2))} (s≤s _) (s≤s (s≤s _)) = begin-strict
m <⟨ s≤s (s≤s (m≤n+m m-1 n-2)) ⟩
n + m-1 ≤⟨ +-monoʳ-≤ n (m≤m*n m-1 0<1+n) ⟩
n + m-1 * n ≡⟨⟩
m * n ∎
*-cancelʳ-< : RightCancellative _<_ _*_
*-cancelʳ-< {zero} zero (suc o) _ = 0<1+n
*-cancelʳ-< {suc m} zero (suc o) _ = 0<1+n
*-cancelʳ-< {m} (suc n) (suc o) nm<om =
s≤s (*-cancelʳ-< n o (+-cancelˡ-< m nm<om))
-- Redo in terms of `comm+cancelʳ⇒cancelˡ` when generalised
*-cancelˡ-< : LeftCancellative _<_ _*_
*-cancelˡ-< x {y} {z} rewrite *-comm x y | *-comm x z = *-cancelʳ-< y z
*-cancel-< : Cancellative _<_ _*_
*-cancel-< = *-cancelˡ-< , *-cancelʳ-<
------------------------------------------------------------------------
-- Properties of _^_
------------------------------------------------------------------------
^-identityʳ : RightIdentity 1 _^_
^-identityʳ zero = refl
^-identityʳ (suc n) = cong suc (^-identityʳ n)
^-zeroˡ : LeftZero 1 _^_
^-zeroˡ zero = refl
^-zeroˡ (suc n) = begin-equality
1 ^ suc n ≡⟨⟩
1 * (1 ^ n) ≡⟨ *-identityˡ (1 ^ n) ⟩
1 ^ n ≡⟨ ^-zeroˡ n ⟩
1 ∎
^-distribˡ-+-* : ∀ m n o → m ^ (n + o) ≡ m ^ n * m ^ o
^-distribˡ-+-* m zero o = sym (+-identityʳ (m ^ o))
^-distribˡ-+-* m (suc n) o = begin-equality
m * (m ^ (n + o)) ≡⟨ cong (m *_) (^-distribˡ-+-* m n o) ⟩
m * ((m ^ n) * (m ^ o)) ≡⟨ sym (*-assoc m _ _) ⟩
(m * (m ^ n)) * (m ^ o) ∎
^-semigroup-morphism : ∀ {n} → (n ^_) Is +-semigroup -Semigroup⟶ *-semigroup
^-semigroup-morphism = record
{ ⟦⟧-cong = cong (_ ^_)
; ∙-homo = ^-distribˡ-+-* _
}
^-monoid-morphism : ∀ {n} → (n ^_) Is +-0-monoid -Monoid⟶ *-1-monoid
^-monoid-morphism = record
{ sm-homo = ^-semigroup-morphism
; ε-homo = refl
}
^-*-assoc : ∀ m n o → (m ^ n) ^ o ≡ m ^ (n * o)
^-*-assoc m n zero = cong (m ^_) (sym $ *-zeroʳ n)
^-*-assoc m n (suc o) = begin-equality
(m ^ n) * ((m ^ n) ^ o) ≡⟨ cong ((m ^ n) *_) (^-*-assoc m n o) ⟩
(m ^ n) * (m ^ (n * o)) ≡⟨ sym (^-distribˡ-+-* m n (n * o)) ⟩
m ^ (n + n * o) ≡⟨ cong (m ^_) (sym (*-suc n o)) ⟩
m ^ (n * (suc o)) ∎
m^n≡0⇒m≡0 : ∀ m n → m ^ n ≡ 0 → m ≡ 0
m^n≡0⇒m≡0 m (suc n) eq = [ id , m^n≡0⇒m≡0 m n ]′ (m*n≡0⇒m≡0∨n≡0 m eq)
m^n≡1⇒n≡0∨m≡1 : ∀ m n → m ^ n ≡ 1 → n ≡ 0 ⊎ m ≡ 1
m^n≡1⇒n≡0∨m≡1 m zero _ = inj₁ refl
m^n≡1⇒n≡0∨m≡1 m (suc n) eq = inj₂ (m*n≡1⇒m≡1 m (m ^ n) eq)
------------------------------------------------------------------------
-- Properties of _⊔_
------------------------------------------------------------------------
------------------------------------------------------------------------
-- Algebraic properties
⊔-assoc : Associative _⊔_
⊔-assoc zero _ _ = refl
⊔-assoc (suc m) zero o = refl
⊔-assoc (suc m) (suc n) zero = refl
⊔-assoc (suc m) (suc n) (suc o) = cong suc $ ⊔-assoc m n o
⊔-identityˡ : LeftIdentity 0 _⊔_
⊔-identityˡ _ = refl
⊔-identityʳ : RightIdentity 0 _⊔_
⊔-identityʳ zero = refl
⊔-identityʳ (suc n) = refl
⊔-identity : Identity 0 _⊔_
⊔-identity = ⊔-identityˡ , ⊔-identityʳ
⊔-comm : Commutative _⊔_
⊔-comm zero n = sym $ ⊔-identityʳ n
⊔-comm (suc m) zero = refl
⊔-comm (suc m) (suc n) = cong suc (⊔-comm m n)
⊔-sel : Selective _⊔_
⊔-sel zero _ = inj₂ refl
⊔-sel (suc m) zero = inj₁ refl
⊔-sel (suc m) (suc n) with ⊔-sel m n
... | inj₁ m⊔n≡m = inj₁ (cong suc m⊔n≡m)
... | inj₂ m⊔n≡n = inj₂ (cong suc m⊔n≡n)
⊔-idem : Idempotent _⊔_
⊔-idem = sel⇒idem ⊔-sel
⊔-least : ∀ {m n o} → m ≤ o → n ≤ o → m ⊔ n ≤ o
⊔-least {m} {n} m≤o n≤o with ⊔-sel m n
... | inj₁ m⊔n≡m rewrite m⊔n≡m = m≤o
... | inj₂ m⊔n≡n rewrite m⊔n≡n = n≤o
------------------------------------------------------------------------
-- Structures
⊔-isMagma : IsMagma _⊔_
⊔-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _⊔_
}
⊔-isSemigroup : IsSemigroup _⊔_
⊔-isSemigroup = record
{ isMagma = ⊔-isMagma
; assoc = ⊔-assoc
}
⊔-isBand : IsBand _⊔_
⊔-isBand = record
{ isSemigroup = ⊔-isSemigroup
; idem = ⊔-idem
}
⊔-isSemilattice : IsSemilattice _⊔_
⊔-isSemilattice = record
{ isBand = ⊔-isBand
; comm = ⊔-comm
}
⊔-0-isMonoid : IsMonoid _⊔_ 0
⊔-0-isMonoid = record
{ isSemigroup = ⊔-isSemigroup
; identity = ⊔-identity
}
⊔-0-isCommutativeMonoid : IsCommutativeMonoid _⊔_ 0
⊔-0-isCommutativeMonoid = record
{ isMonoid = ⊔-0-isMonoid
; comm = ⊔-comm
}
------------------------------------------------------------------------
-- Bundles
⊔-magma : Magma 0ℓ 0ℓ
⊔-magma = record
{ isMagma = ⊔-isMagma
}
⊔-semigroup : Semigroup 0ℓ 0ℓ
⊔-semigroup = record
{ isSemigroup = ⊔-isSemigroup
}
⊔-band : Band 0ℓ 0ℓ
⊔-band = record
{ isBand = ⊔-isBand
}
⊔-semilattice : Semilattice 0ℓ 0ℓ
⊔-semilattice = record
{ isSemilattice = ⊔-isSemilattice
}
⊔-0-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
⊔-0-commutativeMonoid = record
{ isCommutativeMonoid = ⊔-0-isCommutativeMonoid
}
------------------------------------------------------------------------
-- Other properties of _⊔_ and _≡_
⊔-triangulate : ∀ m n o → m ⊔ n ⊔ o ≡ (m ⊔ n) ⊔ (n ⊔ o)
⊔-triangulate m n o = begin-equality
m ⊔ n ⊔ o ≡⟨ cong (λ v → m ⊔ v ⊔ o) (sym (⊔-idem n)) ⟩
m ⊔ (n ⊔ n) ⊔ o ≡⟨ ⊔-assoc m _ _ ⟩
m ⊔ ((n ⊔ n) ⊔ o) ≡⟨ cong (m ⊔_) (⊔-assoc n _ _) ⟩
m ⊔ (n ⊔ (n ⊔ o)) ≡⟨ sym (⊔-assoc m _ _) ⟩
(m ⊔ n) ⊔ (n ⊔ o) ∎
------------------------------------------------------------------------
-- Other properties of _⊔_ and _≤_/_<_
m≤m⊔n : ∀ m n → m ≤ m ⊔ n
m≤m⊔n zero _ = z≤n
m≤m⊔n (suc m) zero = ≤-refl
m≤m⊔n (suc m) (suc n) = s≤s $ m≤m⊔n m n
n≤m⊔n : ∀ m n → n ≤ m ⊔ n
n≤m⊔n m n = subst (n ≤_) (⊔-comm n m) (m≤m⊔n n m)
m≤n⇒n⊔m≡n : ∀ {m n} → m ≤ n → n ⊔ m ≡ n
m≤n⇒n⊔m≡n z≤n = ⊔-identityʳ _
m≤n⇒n⊔m≡n (s≤s m≤n) = cong suc (m≤n⇒n⊔m≡n m≤n)
m≤n⇒m⊔n≡n : ∀ {m n} → m ≤ n → m ⊔ n ≡ n
m≤n⇒m⊔n≡n {m} m≤n = trans (⊔-comm m _) (m≤n⇒n⊔m≡n m≤n)
n⊔m≡m⇒n≤m : ∀ {m n} → n ⊔ m ≡ m → n ≤ m
n⊔m≡m⇒n≤m n⊔m≡m = subst (_ ≤_) n⊔m≡m (m≤m⊔n _ _)
n⊔m≡n⇒m≤n : ∀ {m n} → n ⊔ m ≡ n → m ≤ n
n⊔m≡n⇒m≤n n⊔m≡n = subst (_ ≤_) n⊔m≡n (n≤m⊔n _ _)
m≤n⇒m≤n⊔o : ∀ {m n} o → m ≤ n → m ≤ n ⊔ o
m≤n⇒m≤n⊔o o m≤n = ≤-trans m≤n (m≤m⊔n _ o)
m≤n⇒m≤o⊔n : ∀ {m n} o → m ≤ n → m ≤ o ⊔ n
m≤n⇒m≤o⊔n n m≤n = ≤-trans m≤n (n≤m⊔n n _)
m⊔n≤o⇒m≤o : ∀ m n {o} → m ⊔ n ≤ o → m ≤ o
m⊔n≤o⇒m≤o m n m⊔n≤o = ≤-trans (m≤m⊔n m n) m⊔n≤o
m⊔n≤o⇒n≤o : ∀ m n {o} → m ⊔ n ≤ o → n ≤ o
m⊔n≤o⇒n≤o m n m⊔n≤o = ≤-trans (n≤m⊔n m n) m⊔n≤o
m<n⇒m<n⊔o : ∀ {m n} o → m < n → m < n ⊔ o
m<n⇒m<n⊔o = m≤n⇒m≤n⊔o
m<n⇒m<o⊔n : ∀ {m n} o → m < n → m < o ⊔ n
m<n⇒m<o⊔n = m≤n⇒m≤o⊔n
m⊔n<o⇒m<o : ∀ m n {o} → m ⊔ n < o → m < o
m⊔n<o⇒m<o m n m⊔n<o = <-transʳ (m≤m⊔n m n) m⊔n<o
m⊔n<o⇒n<o : ∀ m n {o} → m ⊔ n < o → n < o
m⊔n<o⇒n<o m n m⊔n<o = <-transʳ (n≤m⊔n m n) m⊔n<o
⊔-mono-≤ : _⊔_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
⊔-mono-≤ {m} {n} {u} {v} m≤n u≤v with ⊔-sel m u
... | inj₁ m⊔u≡m rewrite m⊔u≡m = ≤-trans m≤n (m≤m⊔n n v)
... | inj₂ m⊔u≡u rewrite m⊔u≡u = ≤-trans u≤v (n≤m⊔n n v)
⊔-monoˡ-≤ : ∀ n → (_⊔ n) Preserves _≤_ ⟶ _≤_
⊔-monoˡ-≤ n m≤o = ⊔-mono-≤ m≤o (≤-refl {n})
⊔-monoʳ-≤ : ∀ n → (n ⊔_) Preserves _≤_ ⟶ _≤_
⊔-monoʳ-≤ n m≤o = ⊔-mono-≤ (≤-refl {n}) m≤o
⊔-mono-< : _⊔_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
⊔-mono-< = ⊔-mono-≤
⊔-pres-≤m : ∀ {m n o} → n ≤ m → o ≤ m → n ⊔ o ≤ m
⊔-pres-≤m {m} n≤m o≤m = subst (_ ≤_) (⊔-idem m) (⊔-mono-≤ n≤m o≤m)
⊔-pres-<m : ∀ {m n o} → n < m → o < m → n ⊔ o < m
⊔-pres-<m {m} n<m o<m = subst (_ <_) (⊔-idem m) (⊔-mono-< n<m o<m)
------------------------------------------------------------------------
-- Other properties of _⊔_ and _+_
+-distribˡ-⊔ : _+_ DistributesOverˡ _⊔_
+-distribˡ-⊔ zero n o = refl
+-distribˡ-⊔ (suc m) n o = cong suc (+-distribˡ-⊔ m n o)
+-distribʳ-⊔ : _+_ DistributesOverʳ _⊔_
+-distribʳ-⊔ = comm+distrˡ⇒distrʳ +-comm +-distribˡ-⊔
+-distrib-⊔ : _+_ DistributesOver _⊔_
+-distrib-⊔ = +-distribˡ-⊔ , +-distribʳ-⊔
m⊔n≤m+n : ∀ m n → m ⊔ n ≤ m + n
m⊔n≤m+n m n with ⊔-sel m n
... | inj₁ m⊔n≡m rewrite m⊔n≡m = m≤m+n m n
... | inj₂ m⊔n≡n rewrite m⊔n≡n = m≤n+m n m
------------------------------------------------------------------------
-- Properties of _⊓_
------------------------------------------------------------------------
------------------------------------------------------------------------
-- Algebraic properties
⊓-assoc : Associative _⊓_
⊓-assoc zero _ _ = refl
⊓-assoc (suc m) zero o = refl
⊓-assoc (suc m) (suc n) zero = refl
⊓-assoc (suc m) (suc n) (suc o) = cong suc $ ⊓-assoc m n o
⊓-zeroˡ : LeftZero 0 _⊓_
⊓-zeroˡ _ = refl
⊓-zeroʳ : RightZero 0 _⊓_
⊓-zeroʳ zero = refl
⊓-zeroʳ (suc n) = refl
⊓-zero : Zero 0 _⊓_
⊓-zero = ⊓-zeroˡ , ⊓-zeroʳ
⊓-comm : Commutative _⊓_
⊓-comm zero n = sym $ ⊓-zeroʳ n
⊓-comm (suc m) zero = refl
⊓-comm (suc m) (suc n) = cong suc (⊓-comm m n)
⊓-sel : Selective _⊓_
⊓-sel zero _ = inj₁ refl
⊓-sel (suc m) zero = inj₂ refl
⊓-sel (suc m) (suc n) with ⊓-sel m n
... | inj₁ m⊓n≡m = inj₁ (cong suc m⊓n≡m)
... | inj₂ m⊓n≡n = inj₂ (cong suc m⊓n≡n)
⊓-idem : Idempotent _⊓_
⊓-idem = sel⇒idem ⊓-sel
⊓-greatest : ∀ {m n o} → m ≥ o → n ≥ o → m ⊓ n ≥ o
⊓-greatest {m} {n} m≥o n≥o with ⊓-sel m n
... | inj₁ m⊓n≡m rewrite m⊓n≡m = m≥o
... | inj₂ m⊓n≡n rewrite m⊓n≡n = n≥o
⊓-distribʳ-⊔ : _⊓_ DistributesOverʳ _⊔_
⊓-distribʳ-⊔ (suc m) (suc n) (suc o) = cong suc $ ⊓-distribʳ-⊔ m n o
⊓-distribʳ-⊔ (suc m) (suc n) zero = cong suc $ refl
⊓-distribʳ-⊔ (suc m) zero o = refl
⊓-distribʳ-⊔ zero n o = begin-equality
(n ⊔ o) ⊓ 0 ≡⟨ ⊓-comm (n ⊔ o) 0 ⟩
0 ⊓ (n ⊔ o) ≡⟨⟩
0 ⊓ n ⊔ 0 ⊓ o ≡⟨ ⊓-comm 0 n ⟨ cong₂ _⊔_ ⟩ ⊓-comm 0 o ⟩
n ⊓ 0 ⊔ o ⊓ 0 ∎
⊓-distribˡ-⊔ : _⊓_ DistributesOverˡ _⊔_
⊓-distribˡ-⊔ = comm+distrʳ⇒distrˡ ⊓-comm ⊓-distribʳ-⊔
⊓-distrib-⊔ : _⊓_ DistributesOver _⊔_
⊓-distrib-⊔ = ⊓-distribˡ-⊔ , ⊓-distribʳ-⊔
⊔-abs-⊓ : _⊔_ Absorbs _⊓_
⊔-abs-⊓ zero n = refl
⊔-abs-⊓ (suc m) zero = refl
⊔-abs-⊓ (suc m) (suc n) = cong suc $ ⊔-abs-⊓ m n
⊓-abs-⊔ : _⊓_ Absorbs _⊔_
⊓-abs-⊔ zero n = refl
⊓-abs-⊔ (suc m) (suc n) = cong suc $ ⊓-abs-⊔ m n
⊓-abs-⊔ (suc m) zero = cong suc $ begin-equality
m ⊓ m ≡⟨ cong (m ⊓_) $ sym $ ⊔-identityʳ m ⟩
m ⊓ (m ⊔ 0) ≡⟨ ⊓-abs-⊔ m zero ⟩
m ∎
⊓-⊔-absorptive : Absorptive _⊓_ _⊔_
⊓-⊔-absorptive = ⊓-abs-⊔ , ⊔-abs-⊓
------------------------------------------------------------------------
-- Structures
⊓-isMagma : IsMagma _⊓_
⊓-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _⊓_
}
⊓-isSemigroup : IsSemigroup _⊓_
⊓-isSemigroup = record
{ isMagma = ⊓-isMagma
; assoc = ⊓-assoc
}
⊓-isBand : IsBand _⊓_
⊓-isBand = record
{ isSemigroup = ⊓-isSemigroup
; idem = ⊓-idem
}
⊓-isSemilattice : IsSemilattice _⊓_
⊓-isSemilattice = record
{ isBand = ⊓-isBand
; comm = ⊓-comm
}
⊔-⊓-isSemiringWithoutOne : IsSemiringWithoutOne _⊔_ _⊓_ 0
⊔-⊓-isSemiringWithoutOne = record
{ +-isCommutativeMonoid = ⊔-0-isCommutativeMonoid
; *-isSemigroup = ⊓-isSemigroup
; distrib = ⊓-distrib-⊔
; zero = ⊓-zero
}
⊔-⊓-isCommutativeSemiringWithoutOne
: IsCommutativeSemiringWithoutOne _⊔_ _⊓_ 0
⊔-⊓-isCommutativeSemiringWithoutOne = record
{ isSemiringWithoutOne = ⊔-⊓-isSemiringWithoutOne
; *-comm = ⊓-comm
}
⊓-⊔-isLattice : IsLattice _⊓_ _⊔_
⊓-⊔-isLattice = record
{ isEquivalence = isEquivalence
; ∨-comm = ⊓-comm
; ∨-assoc = ⊓-assoc
; ∨-cong = cong₂ _⊓_
; ∧-comm = ⊔-comm
; ∧-assoc = ⊔-assoc
; ∧-cong = cong₂ _⊔_
; absorptive = ⊓-⊔-absorptive
}
⊓-⊔-isDistributiveLattice : IsDistributiveLattice _⊓_ _⊔_
⊓-⊔-isDistributiveLattice = record
{ isLattice = ⊓-⊔-isLattice
; ∨-distribʳ-∧ = ⊓-distribʳ-⊔
}
------------------------------------------------------------------------
-- Bundles
⊓-magma : Magma 0ℓ 0ℓ
⊓-magma = record
{ isMagma = ⊓-isMagma
}
⊓-semigroup : Semigroup 0ℓ 0ℓ
⊓-semigroup = record
{ isSemigroup = ⊔-isSemigroup
}
⊓-band : Band 0ℓ 0ℓ
⊓-band = record
{ isBand = ⊓-isBand
}
⊓-semilattice : Semilattice 0ℓ 0ℓ
⊓-semilattice = record
{ isSemilattice = ⊓-isSemilattice
}
⊔-⊓-commutativeSemiringWithoutOne : CommutativeSemiringWithoutOne 0ℓ 0ℓ
⊔-⊓-commutativeSemiringWithoutOne = record
{ isCommutativeSemiringWithoutOne =
⊔-⊓-isCommutativeSemiringWithoutOne
}
⊓-⊔-lattice : Lattice 0ℓ 0ℓ
⊓-⊔-lattice = record
{ isLattice = ⊓-⊔-isLattice
}
⊓-⊔-distributiveLattice : DistributiveLattice 0ℓ 0ℓ
⊓-⊔-distributiveLattice = record
{ isDistributiveLattice = ⊓-⊔-isDistributiveLattice
}
------------------------------------------------------------------------
-- Other properties of _⊓_ and _≡_
⊓-triangulate : ∀ m n o → m ⊓ n ⊓ o ≡ (m ⊓ n) ⊓ (n ⊓ o)
⊓-triangulate m n o = begin-equality
m ⊓ n ⊓ o ≡⟨ sym (cong (λ v → m ⊓ v ⊓ o) (⊓-idem n)) ⟩
m ⊓ (n ⊓ n) ⊓ o ≡⟨ ⊓-assoc m _ _ ⟩
m ⊓ ((n ⊓ n) ⊓ o) ≡⟨ cong (m ⊓_) (⊓-assoc n _ _) ⟩
m ⊓ (n ⊓ (n ⊓ o)) ≡⟨ sym (⊓-assoc m _ _) ⟩
(m ⊓ n) ⊓ (n ⊓ o) ∎
------------------------------------------------------------------------
-- Other properties of _⊓_ and _≤_/_<_
m⊓n≤m : ∀ m n → m ⊓ n ≤ m
m⊓n≤m zero _ = z≤n
m⊓n≤m (suc m) zero = z≤n
m⊓n≤m (suc m) (suc n) = s≤s $ m⊓n≤m m n
m⊓n≤n : ∀ m n → m ⊓ n ≤ n
m⊓n≤n m n = subst (_≤ n) (⊓-comm n m) (m⊓n≤m n m)
m≤n⇒m⊓n≡m : ∀ {m n} → m ≤ n → m ⊓ n ≡ m
m≤n⇒m⊓n≡m z≤n = refl
m≤n⇒m⊓n≡m (s≤s m≤n) = cong suc (m≤n⇒m⊓n≡m m≤n)
m≤n⇒n⊓m≡m : ∀ {m n} → m ≤ n → n ⊓ m ≡ m
m≤n⇒n⊓m≡m {m} m≤n = trans (⊓-comm _ m) (m≤n⇒m⊓n≡m m≤n)
m⊓n≡m⇒m≤n : ∀ {m n} → m ⊓ n ≡ m → m ≤ n
m⊓n≡m⇒m≤n m⊓n≡m = subst (_≤ _) m⊓n≡m (m⊓n≤n _ _)
m⊓n≡n⇒n≤m : ∀ {m n} → m ⊓ n ≡ n → n ≤ m
m⊓n≡n⇒n≤m m⊓n≡n = subst (_≤ _) m⊓n≡n (m⊓n≤m _ _)
m≤n⇒m⊓o≤n : ∀ {m n} o → m ≤ n → m ⊓ o ≤ n
m≤n⇒m⊓o≤n o m≤n = ≤-trans (m⊓n≤m _ o) m≤n
m≤n⇒o⊓m≤n : ∀ {m n} o → m ≤ n → o ⊓ m ≤ n
m≤n⇒o⊓m≤n n m≤n = ≤-trans (m⊓n≤n n _) m≤n
m≤n⊓o⇒m≤n : ∀ {m} n o → m ≤ n ⊓ o → m ≤ n
m≤n⊓o⇒m≤n n o m≤n⊓o = ≤-trans m≤n⊓o (m⊓n≤m n o)
m≤n⊓o⇒m≤o : ∀ {m} n o → m ≤ n ⊓ o → m ≤ o
m≤n⊓o⇒m≤o n o m≤n⊓o = ≤-trans m≤n⊓o (m⊓n≤n n o)
m<n⇒m⊓o<n : ∀ {m n} o → m < n → m ⊓ o < n
m<n⇒m⊓o<n o m<n = <-transʳ (m⊓n≤m _ o) m<n
m<n⇒o⊓m<n : ∀ {m n} o → m < n → o ⊓ m < n
m<n⇒o⊓m<n o m<n = <-transʳ (m⊓n≤n o _) m<n
m<n⊓o⇒m<n : ∀ {m} n o → m < n ⊓ o → m < n
m<n⊓o⇒m<n = m≤n⊓o⇒m≤n
m<n⊓o⇒m<o : ∀ {m} n o → m < n ⊓ o → m < o
m<n⊓o⇒m<o = m≤n⊓o⇒m≤o
⊓-mono-≤ : _⊓_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
⊓-mono-≤ {m} {n} {u} {v} m≤n u≤v with ⊓-sel n v
... | inj₁ n⊓v≡n rewrite n⊓v≡n = ≤-trans (m⊓n≤m m u) m≤n
... | inj₂ n⊓v≡v rewrite n⊓v≡v = ≤-trans (m⊓n≤n m u) u≤v
⊓-monoˡ-≤ : ∀ n → (_⊓ n) Preserves _≤_ ⟶ _≤_
⊓-monoˡ-≤ n m≤o = ⊓-mono-≤ m≤o (≤-refl {n})
⊓-monoʳ-≤ : ∀ n → (n ⊓_) Preserves _≤_ ⟶ _≤_
⊓-monoʳ-≤ n m≤o = ⊓-mono-≤ (≤-refl {n}) m≤o
⊓-mono-< : _⊓_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
⊓-mono-< = ⊓-mono-≤
m⊓n≤m⊔n : ∀ m n → m ⊓ n ≤ m ⊔ n
m⊓n≤m⊔n zero n = z≤n
m⊓n≤m⊔n (suc m) zero = z≤n
m⊓n≤m⊔n (suc m) (suc n) = s≤s (m⊓n≤m⊔n m n)
⊓-pres-m≤ : ∀ {m n o} → m ≤ n → m ≤ o → m ≤ n ⊓ o
⊓-pres-m≤ {m} m≤n m≤o = subst (_≤ _) (⊓-idem m) (⊓-mono-≤ m≤n m≤o)
⊓-pres-m< : ∀ {m n o} → m < n → m < o → m < n ⊓ o
⊓-pres-m< {m} m<n m<o = subst (_< _) (⊓-idem m) (⊓-mono-< m<n m<o)
------------------------------------------------------------------------
-- Other properties of _⊓_ and _+_
+-distribˡ-⊓ : _+_ DistributesOverˡ _⊓_
+-distribˡ-⊓ zero n o = refl
+-distribˡ-⊓ (suc m) n o = cong suc (+-distribˡ-⊓ m n o)
+-distribʳ-⊓ : _+_ DistributesOverʳ _⊓_
+-distribʳ-⊓ = comm+distrˡ⇒distrʳ +-comm +-distribˡ-⊓
+-distrib-⊓ : _+_ DistributesOver _⊓_
+-distrib-⊓ = +-distribˡ-⊓ , +-distribʳ-⊓
m⊓n≤m+n : ∀ m n → m ⊓ n ≤ m + n
m⊓n≤m+n m n with ⊓-sel m n
... | inj₁ m⊓n≡m rewrite m⊓n≡m = m≤m+n m n
... | inj₂ m⊓n≡n rewrite m⊓n≡n = m≤n+m n m
------------------------------------------------------------------------
-- Properties of _∸_
------------------------------------------------------------------------
0∸n≡0 : LeftZero zero _∸_
0∸n≡0 zero = refl
0∸n≡0 (suc _) = refl
n∸n≡0 : ∀ n → n ∸ n ≡ 0
n∸n≡0 zero = refl
n∸n≡0 (suc n) = n∸n≡0 n
------------------------------------------------------------------------
-- Properties of _∸_ and _≤_/_<_
m∸n≤m : ∀ m n → m ∸ n ≤ m
m∸n≤m n zero = ≤-refl
m∸n≤m zero (suc n) = ≤-refl
m∸n≤m (suc m) (suc n) = ≤-trans (m∸n≤m m n) (n≤1+n m)
m≮m∸n : ∀ m n → m ≮ m ∸ n
m≮m∸n m zero = n≮n m
m≮m∸n (suc m) (suc n) = m≮m∸n m n ∘ ≤-trans (n≤1+n (suc m))
1+m≢m∸n : ∀ {m} n → suc m ≢ m ∸ n
1+m≢m∸n {m} n eq = m≮m∸n m n (≤-reflexive eq)
∸-mono : _∸_ Preserves₂ _≤_ ⟶ _≥_ ⟶ _≤_
∸-mono z≤n (s≤s n₁≥n₂) = z≤n
∸-mono (s≤s m₁≤m₂) (s≤s n₁≥n₂) = ∸-mono m₁≤m₂ n₁≥n₂
∸-mono m₁≤m₂ (z≤n {n = n₁}) = ≤-trans (m∸n≤m _ n₁) m₁≤m₂
∸-monoˡ-≤ : ∀ {m n} o → m ≤ n → m ∸ o ≤ n ∸ o
∸-monoˡ-≤ o m≤n = ∸-mono {u = o} m≤n ≤-refl
∸-monoʳ-≤ : ∀ {m n} o → m ≤ n → o ∸ m ≥ o ∸ n
∸-monoʳ-≤ _ m≤n = ∸-mono ≤-refl m≤n
∸-monoʳ-< : ∀ {m n o} → o < n → n ≤ m → m ∸ n < m ∸ o
∸-monoʳ-< {n = suc n} {zero} (s≤s o<n) (s≤s n<m) = s≤s (m∸n≤m _ n)
∸-monoʳ-< {n = suc n} {suc o} (s≤s o<n) (s≤s n<m) = ∸-monoʳ-< o<n n<m
∸-cancelʳ-≤ : ∀ {m n o} → m ≤ o → o ∸ n ≤ o ∸ m → m ≤ n
∸-cancelʳ-≤ {_} {_} z≤n _ = z≤n
∸-cancelʳ-≤ {suc m} {zero} (s≤s _) o<o∸m = contradiction o<o∸m (m≮m∸n _ m)
∸-cancelʳ-≤ {suc m} {suc n} (s≤s m≤o) o∸n<o∸m = s≤s (∸-cancelʳ-≤ m≤o o∸n<o∸m)
∸-cancelʳ-< : ∀ {m n o} → o ∸ m < o ∸ n → n < m
∸-cancelʳ-< {zero} {n} {o} o<o∸n = contradiction o<o∸n (m≮m∸n o n)
∸-cancelʳ-< {suc m} {zero} {_} o∸n<o∸m = 0<1+n
∸-cancelʳ-< {suc m} {suc n} {suc o} o∸n<o∸m = s≤s (∸-cancelʳ-< o∸n<o∸m)
∸-cancelˡ-≡ : ∀ {m n o} → n ≤ m → o ≤ m → m ∸ n ≡ m ∸ o → n ≡ o
∸-cancelˡ-≡ {_} z≤n z≤n _ = refl
∸-cancelˡ-≡ {o = suc o} z≤n (s≤s _) eq = contradiction eq (1+m≢m∸n o)
∸-cancelˡ-≡ {n = suc n} (s≤s _) z≤n eq = contradiction (sym eq) (1+m≢m∸n n)
∸-cancelˡ-≡ {_} (s≤s n≤m) (s≤s o≤m) eq = cong suc (∸-cancelˡ-≡ n≤m o≤m eq)
∸-cancelʳ-≡ : ∀ {m n o} → o ≤ m → o ≤ n → m ∸ o ≡ n ∸ o → m ≡ n
∸-cancelʳ-≡ z≤n z≤n eq = eq
∸-cancelʳ-≡ (s≤s o≤m) (s≤s o≤n) eq = cong suc (∸-cancelʳ-≡ o≤m o≤n eq)
m∸n≡0⇒m≤n : ∀ {m n} → m ∸ n ≡ 0 → m ≤ n
m∸n≡0⇒m≤n {zero} {_} _ = z≤n
m∸n≡0⇒m≤n {suc m} {suc n} eq = s≤s (m∸n≡0⇒m≤n eq)
m≤n⇒m∸n≡0 : ∀ {m n} → m ≤ n → m ∸ n ≡ 0
m≤n⇒m∸n≡0 {n = n} z≤n = 0∸n≡0 n
m≤n⇒m∸n≡0 {_} (s≤s m≤n) = m≤n⇒m∸n≡0 m≤n
m<n⇒0<n∸m : ∀ {m n} → m < n → 0 < n ∸ m
m<n⇒0<n∸m {zero} {suc n} _ = 0<1+n
m<n⇒0<n∸m {suc m} {suc n} (s≤s m<n) = m<n⇒0<n∸m m<n
m∸n≢0⇒n<m : ∀ {m n} → m ∸ n ≢ 0 → n < m
m∸n≢0⇒n<m {m} {n} m∸n≢0 with n <? m
... | yes n<m = n<m
... | no n≮m = contradiction (m≤n⇒m∸n≡0 (≮⇒≥ n≮m)) m∸n≢0
m>n⇒m∸n≢0 : ∀ {m n} → m > n → m ∸ n ≢ 0
m>n⇒m∸n≢0 {n = suc n} (s≤s m>n) = m>n⇒m∸n≢0 m>n
---------------------------------------------------------------
-- Properties of _∸_ and _+_
+-∸-comm : ∀ {m} n {o} → o ≤ m → (m + n) ∸ o ≡ (m ∸ o) + n
+-∸-comm {zero} _ {zero} _ = refl
+-∸-comm {suc m} _ {zero} _ = refl
+-∸-comm {suc m} n {suc o} (s≤s o≤m) = +-∸-comm n o≤m
∸-+-assoc : ∀ m n o → (m ∸ n) ∸ o ≡ m ∸ (n + o)
∸-+-assoc zero zero o = refl
∸-+-assoc zero (suc n) o = 0∸n≡0 o
∸-+-assoc (suc m) zero o = refl
∸-+-assoc (suc m) (suc n) o = ∸-+-assoc m n o
+-∸-assoc : ∀ m {n o} → o ≤ n → (m + n) ∸ o ≡ m + (n ∸ o)
+-∸-assoc m (z≤n {n = n}) = begin-equality m + n ∎
+-∸-assoc m (s≤s {m = o} {n = n} o≤n) = begin-equality
(m + suc n) ∸ suc o ≡⟨ cong (_∸ suc o) (+-suc m n) ⟩
suc (m + n) ∸ suc o ≡⟨⟩
(m + n) ∸ o ≡⟨ +-∸-assoc m o≤n ⟩
m + (n ∸ o) ∎
m≤n+m∸n : ∀ m n → m ≤ n + (m ∸ n)
m≤n+m∸n zero n = z≤n
m≤n+m∸n (suc m) zero = ≤-refl
m≤n+m∸n (suc m) (suc n) = s≤s (m≤n+m∸n m n)
m+n∸n≡m : ∀ m n → m + n ∸ n ≡ m
m+n∸n≡m m n = begin-equality
(m + n) ∸ n ≡⟨ +-∸-assoc m (≤-refl {x = n}) ⟩
m + (n ∸ n) ≡⟨ cong (m +_) (n∸n≡0 n) ⟩
m + 0 ≡⟨ +-identityʳ m ⟩
m ∎
m+n∸m≡n : ∀ m n → m + n ∸ m ≡ n
m+n∸m≡n m n = trans (cong (_∸ m) (+-comm m n)) (m+n∸n≡m n m)
m+[n∸m]≡n : ∀ {m n} → m ≤ n → m + (n ∸ m) ≡ n
m+[n∸m]≡n {m} {n} m≤n = begin-equality
m + (n ∸ m) ≡⟨ sym $ +-∸-assoc m m≤n ⟩
(m + n) ∸ m ≡⟨ cong (_∸ m) (+-comm m n) ⟩
(n + m) ∸ m ≡⟨ m+n∸n≡m n m ⟩
n ∎
m∸n+n≡m : ∀ {m n} → n ≤ m → (m ∸ n) + n ≡ m
m∸n+n≡m {m} {n} n≤m = begin-equality
(m ∸ n) + n ≡⟨ sym (+-∸-comm n n≤m) ⟩
(m + n) ∸ n ≡⟨ m+n∸n≡m m n ⟩
m ∎
m∸[m∸n]≡n : ∀ {m n} → n ≤ m → m ∸ (m ∸ n) ≡ n
m∸[m∸n]≡n {m} {_} z≤n = n∸n≡0 m
m∸[m∸n]≡n {suc m} {suc n} (s≤s n≤m) = begin-equality
suc m ∸ (m ∸ n) ≡⟨ +-∸-assoc 1 (m∸n≤m m n) ⟩
suc (m ∸ (m ∸ n)) ≡⟨ cong suc (m∸[m∸n]≡n n≤m) ⟩
suc n ∎
[m+n]∸[m+o]≡n∸o : ∀ m n o → (m + n) ∸ (m + o) ≡ n ∸ o
[m+n]∸[m+o]≡n∸o zero n o = refl
[m+n]∸[m+o]≡n∸o (suc m) n o = [m+n]∸[m+o]≡n∸o m n o
------------------------------------------------------------------------
-- Properties of _∸_ and _*_
*-distribʳ-∸ : _*_ DistributesOverʳ _∸_
*-distribʳ-∸ m zero zero = refl
*-distribʳ-∸ zero zero (suc o) = sym (0∸n≡0 (o * zero))
*-distribʳ-∸ (suc m) zero (suc o) = refl
*-distribʳ-∸ m (suc n) zero = refl
*-distribʳ-∸ m (suc n) (suc o) = begin-equality
(n ∸ o) * m ≡⟨ *-distribʳ-∸ m n o ⟩
n * m ∸ o * m ≡⟨ sym $ [m+n]∸[m+o]≡n∸o m _ _ ⟩
m + n * m ∸ (m + o * m) ∎
*-distribˡ-∸ : _*_ DistributesOverˡ _∸_
*-distribˡ-∸ = comm+distrʳ⇒distrˡ *-comm *-distribʳ-∸
*-distrib-∸ : _*_ DistributesOver _∸_
*-distrib-∸ = *-distribˡ-∸ , *-distribʳ-∸
even≢odd : ∀ m n → 2 * m ≢ suc (2 * n)
even≢odd (suc m) zero eq = contradiction (suc-injective eq) (m+1+n≢0 m)
even≢odd (suc m) (suc n) eq = even≢odd m n (suc-injective (begin-equality
suc (2 * m) ≡⟨ sym (+-suc m _) ⟩
m + suc (m + 0) ≡⟨ suc-injective eq ⟩
suc n + suc (n + 0) ≡⟨ cong suc (+-suc n _) ⟩
suc (suc (2 * n)) ∎))
------------------------------------------------------------------------
-- Properties of _∸_ and _⊓_ and _⊔_
m⊓n+n∸m≡n : ∀ m n → (m ⊓ n) + (n ∸ m) ≡ n
m⊓n+n∸m≡n zero n = refl
m⊓n+n∸m≡n (suc m) zero = refl
m⊓n+n∸m≡n (suc m) (suc n) = cong suc $ m⊓n+n∸m≡n m n
[m∸n]⊓[n∸m]≡0 : ∀ m n → (m ∸ n) ⊓ (n ∸ m) ≡ 0
[m∸n]⊓[n∸m]≡0 zero zero = refl
[m∸n]⊓[n∸m]≡0 zero (suc n) = refl
[m∸n]⊓[n∸m]≡0 (suc m) zero = refl
[m∸n]⊓[n∸m]≡0 (suc m) (suc n) = [m∸n]⊓[n∸m]≡0 m n
∸-distribˡ-⊓-⊔ : ∀ m n o → m ∸ (n ⊓ o) ≡ (m ∸ n) ⊔ (m ∸ o)
∸-distribˡ-⊓-⊔ m zero zero = sym (⊔-idem m)
∸-distribˡ-⊓-⊔ zero zero (suc o) = refl
∸-distribˡ-⊓-⊔ zero (suc n) zero = refl
∸-distribˡ-⊓-⊔ zero (suc n) (suc o) = refl
∸-distribˡ-⊓-⊔ (suc m) (suc n) zero = sym (m≤n⇒m⊔n≡n (≤-step (m∸n≤m m n)))
∸-distribˡ-⊓-⊔ (suc m) zero (suc o) = sym (m≤n⇒n⊔m≡n (≤-step (m∸n≤m m o)))
∸-distribˡ-⊓-⊔ (suc m) (suc n) (suc o) = ∸-distribˡ-⊓-⊔ m n o
∸-distribʳ-⊓ : _∸_ DistributesOverʳ _⊓_
∸-distribʳ-⊓ zero n o = refl
∸-distribʳ-⊓ (suc m) zero o = refl
∸-distribʳ-⊓ (suc m) (suc n) zero = sym (⊓-zeroʳ (n ∸ m))
∸-distribʳ-⊓ (suc m) (suc n) (suc o) = ∸-distribʳ-⊓ m n o
∸-distribˡ-⊔-⊓ : ∀ m n o → m ∸ (n ⊔ o) ≡ (m ∸ n) ⊓ (m ∸ o)
∸-distribˡ-⊔-⊓ m zero zero = sym (⊓-idem m)
∸-distribˡ-⊔-⊓ zero zero o = 0∸n≡0 o
∸-distribˡ-⊔-⊓ zero (suc n) o = 0∸n≡0 (suc n ⊔ o)
∸-distribˡ-⊔-⊓ (suc m) (suc n) zero = sym (m≤n⇒m⊓n≡m (≤-step (m∸n≤m m n)))
∸-distribˡ-⊔-⊓ (suc m) zero (suc o) = sym (m≤n⇒n⊓m≡m (≤-step (m∸n≤m m o)))
∸-distribˡ-⊔-⊓ (suc m) (suc n) (suc o) = ∸-distribˡ-⊔-⊓ m n o
∸-distribʳ-⊔ : _∸_ DistributesOverʳ _⊔_
∸-distribʳ-⊔ zero n o = refl
∸-distribʳ-⊔ (suc m) zero o = refl
∸-distribʳ-⊔ (suc m) (suc n) zero = sym (⊔-identityʳ (n ∸ m))
∸-distribʳ-⊔ (suc m) (suc n) (suc o) = ∸-distribʳ-⊔ m n o
------------------------------------------------------------------------
-- Properties of ∣_-_∣
------------------------------------------------------------------------
m≡n⇒∣m-n∣≡0 : ∀ {m n} → m ≡ n → ∣ m - n ∣ ≡ 0
m≡n⇒∣m-n∣≡0 {zero} refl = refl
m≡n⇒∣m-n∣≡0 {suc m} refl = m≡n⇒∣m-n∣≡0 {m} refl
∣m-n∣≡0⇒m≡n : ∀ {m n} → ∣ m - n ∣ ≡ 0 → m ≡ n
∣m-n∣≡0⇒m≡n {zero} {zero} eq = refl
∣m-n∣≡0⇒m≡n {suc m} {suc n} eq = cong suc (∣m-n∣≡0⇒m≡n eq)
m≤n⇒∣n-m∣≡n∸m : ∀ {m n} → m ≤ n → ∣ n - m ∣ ≡ n ∸ m
m≤n⇒∣n-m∣≡n∸m {_} {zero} z≤n = refl
m≤n⇒∣n-m∣≡n∸m {_} {suc m} z≤n = refl
m≤n⇒∣n-m∣≡n∸m {_} {_} (s≤s m≤n) = m≤n⇒∣n-m∣≡n∸m m≤n
∣m-n∣≡m∸n⇒n≤m : ∀ {m n} → ∣ m - n ∣ ≡ m ∸ n → n ≤ m
∣m-n∣≡m∸n⇒n≤m {zero} {zero} eq = z≤n
∣m-n∣≡m∸n⇒n≤m {suc m} {zero} eq = z≤n
∣m-n∣≡m∸n⇒n≤m {suc m} {suc n} eq = s≤s (∣m-n∣≡m∸n⇒n≤m eq)
∣n-n∣≡0 : ∀ n → ∣ n - n ∣ ≡ 0
∣n-n∣≡0 n = m≡n⇒∣m-n∣≡0 {n} refl
∣m-m+n∣≡n : ∀ m n → ∣ m - m + n ∣ ≡ n
∣m-m+n∣≡n zero n = refl
∣m-m+n∣≡n (suc m) n = ∣m-m+n∣≡n m n
∣m+n-m+o∣≡∣n-o| : ∀ m n o → ∣ m + n - m + o ∣ ≡ ∣ n - o ∣
∣m+n-m+o∣≡∣n-o| zero n o = refl
∣m+n-m+o∣≡∣n-o| (suc m) n o = ∣m+n-m+o∣≡∣n-o| m n o
m∸n≤∣m-n∣ : ∀ m n → m ∸ n ≤ ∣ m - n ∣
m∸n≤∣m-n∣ m n with ≤-total m n
... | inj₁ m≤n = subst (_≤ ∣ m - n ∣) (sym (m≤n⇒m∸n≡0 m≤n)) z≤n
... | inj₂ n≤m = subst (m ∸ n ≤_) (sym (m≤n⇒∣n-m∣≡n∸m n≤m)) ≤-refl
∣m-n∣≤m⊔n : ∀ m n → ∣ m - n ∣ ≤ m ⊔ n
∣m-n∣≤m⊔n zero m = ≤-refl
∣m-n∣≤m⊔n (suc m) zero = ≤-refl
∣m-n∣≤m⊔n (suc m) (suc n) = ≤-step (∣m-n∣≤m⊔n m n)
∣-∣-identityˡ : LeftIdentity 0 ∣_-_∣
∣-∣-identityˡ x = refl
∣-∣-identityʳ : RightIdentity 0 ∣_-_∣
∣-∣-identityʳ zero = refl
∣-∣-identityʳ (suc x) = refl
∣-∣-identity : Identity 0 ∣_-_∣
∣-∣-identity = ∣-∣-identityˡ , ∣-∣-identityʳ
∣-∣-comm : Commutative ∣_-_∣
∣-∣-comm zero zero = refl
∣-∣-comm zero (suc n) = refl
∣-∣-comm (suc m) zero = refl
∣-∣-comm (suc m) (suc n) = ∣-∣-comm m n
∣m-n∣≡[m∸n]∨[n∸m] : ∀ m n → (∣ m - n ∣ ≡ m ∸ n) ⊎ (∣ m - n ∣ ≡ n ∸ m)
∣m-n∣≡[m∸n]∨[n∸m] m n with ≤-total m n
... | inj₂ n≤m = inj₁ $ m≤n⇒∣n-m∣≡n∸m n≤m
... | inj₁ m≤n = inj₂ $ begin-equality
∣ m - n ∣ ≡⟨ ∣-∣-comm m n ⟩
∣ n - m ∣ ≡⟨ m≤n⇒∣n-m∣≡n∸m m≤n ⟩
n ∸ m ∎
private
*-distribˡ-∣-∣-aux : ∀ a m n → m ≤ n → a * ∣ n - m ∣ ≡ ∣ a * n - a * m ∣
*-distribˡ-∣-∣-aux a m n m≤n = begin-equality
a * ∣ n - m ∣ ≡⟨ cong (a *_) (m≤n⇒∣n-m∣≡n∸m m≤n) ⟩
a * (n ∸ m) ≡⟨ *-distribˡ-∸ a n m ⟩
a * n ∸ a * m ≡⟨ sym $′ m≤n⇒∣n-m∣≡n∸m (*-monoʳ-≤ a m≤n) ⟩
∣ a * n - a * m ∣ ∎
*-distribˡ-∣-∣ : _*_ DistributesOverˡ ∣_-_∣
*-distribˡ-∣-∣ a m n with ≤-total m n
... | inj₁ m≤n = begin-equality
a * ∣ m - n ∣ ≡⟨ cong (a *_) (∣-∣-comm m n) ⟩
a * ∣ n - m ∣ ≡⟨ *-distribˡ-∣-∣-aux a m n m≤n ⟩
∣ a * n - a * m ∣ ≡⟨ ∣-∣-comm (a * n) (a * m) ⟩
∣ a * m - a * n ∣ ∎
... | inj₂ n≤m = *-distribˡ-∣-∣-aux a n m n≤m
*-distribʳ-∣-∣ : _*_ DistributesOverʳ ∣_-_∣
*-distribʳ-∣-∣ = comm+distrˡ⇒distrʳ *-comm *-distribˡ-∣-∣
*-distrib-∣-∣ : _*_ DistributesOver ∣_-_∣
*-distrib-∣-∣ = *-distribˡ-∣-∣ , *-distribʳ-∣-∣
m≤n+∣n-m∣ : ∀ m n → m ≤ n + ∣ n - m ∣
m≤n+∣n-m∣ zero n = z≤n
m≤n+∣n-m∣ (suc m) zero = ≤-refl
m≤n+∣n-m∣ (suc m) (suc n) = s≤s (m≤n+∣n-m∣ m n)
m≤n+∣m-n∣ : ∀ m n → m ≤ n + ∣ m - n ∣
m≤n+∣m-n∣ m n = subst (m ≤_) (cong (n +_) (∣-∣-comm n m)) (m≤n+∣n-m∣ m n)
m≤∣m-n∣+n : ∀ m n → m ≤ ∣ m - n ∣ + n
m≤∣m-n∣+n m n = subst (m ≤_) (+-comm n _) (m≤n+∣m-n∣ m n)
------------------------------------------------------------------------
-- Properties of ⌊_/2⌋ and ⌈_/2⌉
------------------------------------------------------------------------
⌊n/2⌋-mono : ⌊_/2⌋ Preserves _≤_ ⟶ _≤_
⌊n/2⌋-mono z≤n = z≤n
⌊n/2⌋-mono (s≤s z≤n) = z≤n
⌊n/2⌋-mono (s≤s (s≤s m≤n)) = s≤s (⌊n/2⌋-mono m≤n)
⌈n/2⌉-mono : ⌈_/2⌉ Preserves _≤_ ⟶ _≤_
⌈n/2⌉-mono m≤n = ⌊n/2⌋-mono (s≤s m≤n)
⌊n/2⌋≤⌈n/2⌉ : ∀ n → ⌊ n /2⌋ ≤ ⌈ n /2⌉
⌊n/2⌋≤⌈n/2⌉ zero = z≤n
⌊n/2⌋≤⌈n/2⌉ (suc zero) = z≤n
⌊n/2⌋≤⌈n/2⌉ (suc (suc n)) = s≤s (⌊n/2⌋≤⌈n/2⌉ n)
⌊n/2⌋+⌈n/2⌉≡n : ∀ n → ⌊ n /2⌋ + ⌈ n /2⌉ ≡ n
⌊n/2⌋+⌈n/2⌉≡n zero = refl
⌊n/2⌋+⌈n/2⌉≡n (suc n) = begin-equality
⌊ suc n /2⌋ + suc ⌊ n /2⌋ ≡⟨ +-comm ⌊ suc n /2⌋ (suc ⌊ n /2⌋) ⟩
suc ⌊ n /2⌋ + ⌊ suc n /2⌋ ≡⟨⟩
suc (⌊ n /2⌋ + ⌊ suc n /2⌋) ≡⟨ cong suc (⌊n/2⌋+⌈n/2⌉≡n n) ⟩
suc n ∎
⌊n/2⌋≤n : ∀ n → ⌊ n /2⌋ ≤ n
⌊n/2⌋≤n zero = z≤n
⌊n/2⌋≤n (suc zero) = z≤n
⌊n/2⌋≤n (suc (suc n)) = s≤s (≤-step (⌊n/2⌋≤n n))
⌊n/2⌋<n : ∀ n → ⌊ suc n /2⌋ < suc n
⌊n/2⌋<n zero = s≤s z≤n
⌊n/2⌋<n (suc n) = s≤s (s≤s (⌊n/2⌋≤n n))
⌈n/2⌉≤n : ∀ n → ⌈ n /2⌉ ≤ n
⌈n/2⌉≤n zero = z≤n
⌈n/2⌉≤n (suc n) = s≤s (⌊n/2⌋≤n n)
⌈n/2⌉<n : ∀ n → ⌈ suc (suc n) /2⌉ < suc (suc n)
⌈n/2⌉<n n = s≤s (⌊n/2⌋<n n)
------------------------------------------------------------------------
-- Properties of _≤′_ and _<′_
------------------------------------------------------------------------
≤′-trans : Transitive _≤′_
≤′-trans m≤n ≤′-refl = m≤n
≤′-trans m≤n (≤′-step n≤o) = ≤′-step (≤′-trans m≤n n≤o)
z≤′n : ∀ {n} → zero ≤′ n
z≤′n {zero} = ≤′-refl
z≤′n {suc n} = ≤′-step z≤′n
s≤′s : ∀ {m n} → m ≤′ n → suc m ≤′ suc n
s≤′s ≤′-refl = ≤′-refl
s≤′s (≤′-step m≤′n) = ≤′-step (s≤′s m≤′n)
≤′⇒≤ : _≤′_ ⇒ _≤_
≤′⇒≤ ≤′-refl = ≤-refl
≤′⇒≤ (≤′-step m≤′n) = ≤-step (≤′⇒≤ m≤′n)
≤⇒≤′ : _≤_ ⇒ _≤′_
≤⇒≤′ z≤n = z≤′n
≤⇒≤′ (s≤s m≤n) = s≤′s (≤⇒≤′ m≤n)
≤′-step-injective : ∀ {m n} {p q : m ≤′ n} → ≤′-step p ≡ ≤′-step q → p ≡ q
≤′-step-injective refl = refl
infix 4 _≤′?_ _<′?_ _≥′?_ _>′?_
_≤′?_ : Decidable _≤′_
m ≤′? n = map′ ≤⇒≤′ ≤′⇒≤ (m ≤? n)
_<′?_ : Decidable _<′_
m <′? n = suc m ≤′? n
_≥′?_ : Decidable _≥′_
_≥′?_ = flip _≤′?_
_>′?_ : Decidable _>′_
_>′?_ = flip _<′?_
m≤′m+n : ∀ m n → m ≤′ m + n
m≤′m+n m n = ≤⇒≤′ (m≤m+n m n)
n≤′m+n : ∀ m n → n ≤′ m + n
n≤′m+n zero n = ≤′-refl
n≤′m+n (suc m) n = ≤′-step (n≤′m+n m n)
⌈n/2⌉≤′n : ∀ n → ⌈ n /2⌉ ≤′ n
⌈n/2⌉≤′n zero = ≤′-refl
⌈n/2⌉≤′n (suc zero) = ≤′-refl
⌈n/2⌉≤′n (suc (suc n)) = s≤′s (≤′-step (⌈n/2⌉≤′n n))
⌊n/2⌋≤′n : ∀ n → ⌊ n /2⌋ ≤′ n
⌊n/2⌋≤′n zero = ≤′-refl
⌊n/2⌋≤′n (suc n) = ≤′-step (⌈n/2⌉≤′n n)
------------------------------------------------------------------------
-- Properties of _≤″_ and _<″_
------------------------------------------------------------------------
m<ᵇn⇒1+m+[n-1+m]≡n : ∀ m n → T (m <ᵇ n) → suc m + (n ∸ suc m) ≡ n
m<ᵇn⇒1+m+[n-1+m]≡n m n lt = m+[n∸m]≡n (<ᵇ⇒< m n lt)
m<ᵇ1+m+n : ∀ m {n} → T (m <ᵇ suc (m + n))
m<ᵇ1+m+n m = <⇒<ᵇ (m≤m+n (suc m) _)
<ᵇ⇒<″ : ∀ {m n} → T (m <ᵇ n) → m <″ n
<ᵇ⇒<″ {m} {n} leq = less-than-or-equal (m+[n∸m]≡n (<ᵇ⇒< m n leq))
<″⇒<ᵇ : ∀ {m n} → m <″ n → T (m <ᵇ n)
<″⇒<ᵇ {m} (less-than-or-equal refl) = <⇒<ᵇ (m≤m+n (suc m) _)
-- equivalence to _≤_
≤″⇒≤ : _≤″_ ⇒ _≤_
≤″⇒≤ {zero} (less-than-or-equal refl) = z≤n
≤″⇒≤ {suc m} (less-than-or-equal refl) =
s≤s (≤″⇒≤ (less-than-or-equal refl))
≤⇒≤″ : _≤_ ⇒ _≤″_
≤⇒≤″ = less-than-or-equal ∘ m+[n∸m]≡n
-- NB: we use the builtin function `_<ᵇ_ : (m n : ℕ) → Bool` here so
-- that the function quickly decides whether to return `yes` or `no`.
-- It still takes a linear amount of time to generate the proof if it
-- is inspected. We expect the main benefit to be visible for compiled
-- code: the backend erases proofs.
infix 4 _<″?_ _≤″?_ _≥″?_ _>″?_
_<″?_ : Decidable _<″_
m <″? n = map′ <ᵇ⇒<″ <″⇒<ᵇ (T? (m <ᵇ n))
_≤″?_ : Decidable _≤″_
zero ≤″? n = yes (less-than-or-equal refl)
suc m ≤″? n = m <″? n
_≥″?_ : Decidable _≥″_
_≥″?_ = flip _≤″?_
_>″?_ : Decidable _>″_
_>″?_ = flip _<″?_
≤″-irrelevant : Irrelevant _≤″_
≤″-irrelevant {m} (less-than-or-equal eq₁)
(less-than-or-equal eq₂)
with +-cancelˡ-≡ m (trans eq₁ (sym eq₂))
... | refl = cong less-than-or-equal (≡-irrelevant eq₁ eq₂)
<″-irrelevant : Irrelevant _<″_
<″-irrelevant = ≤″-irrelevant
>″-irrelevant : Irrelevant _>″_
>″-irrelevant = ≤″-irrelevant
≥″-irrelevant : Irrelevant _≥″_
≥″-irrelevant = ≤″-irrelevant
------------------------------------------------------------------------
-- Properties of _≤‴_
------------------------------------------------------------------------
≤‴⇒≤″ : ∀{m n} → m ≤‴ n → m ≤″ n
≤‴⇒≤″ {m = m} ≤‴-refl = less-than-or-equal {k = 0} (+-identityʳ m)
≤‴⇒≤″ {m = m} (≤‴-step x) = less-than-or-equal (trans (+-suc m _) (_≤″_.proof ind)) where
ind = ≤‴⇒≤″ x
m≤‴m+k : ∀{m n k} → m + k ≡ n → m ≤‴ n
m≤‴m+k {m} {k = zero} refl = subst (λ z → m ≤‴ z) (sym (+-identityʳ m)) (≤‴-refl {m})
m≤‴m+k {m} {k = suc k} proof
= ≤‴-step (m≤‴m+k {k = k} (trans (sym (+-suc m _)) proof))
≤″⇒≤‴ : ∀{m n} → m ≤″ n → m ≤‴ n
≤″⇒≤‴ (less-than-or-equal {k} proof) = m≤‴m+k proof
------------------------------------------------------------------------
-- Other properties
------------------------------------------------------------------------
-- If there is an injection from a type to ℕ, then the type has
-- decidable equality.
eq? : ∀ {a} {A : Set a} → A ↣ ℕ → Decidable {A = A} _≡_
eq? inj = via-injection inj _≟_
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.14
_*-mono_ = *-mono-≤
{-# WARNING_ON_USAGE _*-mono_
"Warning: _*-mono_ was deprecated in v0.14.
Please use *-mono-≤ instead."
#-}
_+-mono_ = +-mono-≤
{-# WARNING_ON_USAGE _+-mono_
"Warning: _+-mono_ was deprecated in v0.14.
Please use +-mono-≤ instead."
#-}
+-right-identity = +-identityʳ
{-# WARNING_ON_USAGE +-right-identity
"Warning: +-right-identity was deprecated in v0.14.
Please use +-identityʳ instead."
#-}
*-right-zero = *-zeroʳ
{-# WARNING_ON_USAGE *-right-zero
"Warning: *-right-zero was deprecated in v0.14.
Please use *-zeroʳ instead."
#-}
distribʳ-*-+ = *-distribʳ-+
{-# WARNING_ON_USAGE distribʳ-*-+
"Warning: distribʳ-*-+ was deprecated in v0.14.
Please use *-distribʳ-+ instead."
#-}
*-distrib-∸ʳ = *-distribʳ-∸
{-# WARNING_ON_USAGE *-distrib-∸ʳ
"Warning: *-distrib-∸ʳ was deprecated in v0.14.
Please use *-distribʳ-∸ instead."
#-}
cancel-+-left = +-cancelˡ-≡
{-# WARNING_ON_USAGE cancel-+-left
"Warning: cancel-+-left was deprecated in v0.14.
Please use +-cancelˡ-≡ instead."
#-}
cancel-+-left-≤ = +-cancelˡ-≤
{-# WARNING_ON_USAGE cancel-+-left-≤
"Warning: cancel-+-left-≤ was deprecated in v0.14.
Please use +-cancelˡ-≤ instead."
#-}
cancel-*-right = *-cancelʳ-≡
{-# WARNING_ON_USAGE cancel-*-right
"Warning: cancel-*-right was deprecated in v0.14.
Please use *-cancelʳ-≡ instead."
#-}
cancel-*-right-≤ = *-cancelʳ-≤
{-# WARNING_ON_USAGE cancel-*-right-≤
"Warning: cancel-*-right-≤ was deprecated in v0.14.
Please use *-cancelʳ-≤ instead."
#-}
strictTotalOrder = <-strictTotalOrder
{-# WARNING_ON_USAGE strictTotalOrder
"Warning: strictTotalOrder was deprecated in v0.14.
Please use <-strictTotalOrder instead."
#-}
isCommutativeSemiring = *-+-isCommutativeSemiring
{-# WARNING_ON_USAGE isCommutativeSemiring
"Warning: isCommutativeSemiring was deprecated in v0.14.
Please use *-+-isCommutativeSemiring instead."
#-}
commutativeSemiring = *-+-commutativeSemiring
{-# WARNING_ON_USAGE commutativeSemiring
"Warning: commutativeSemiring was deprecated in v0.14.
Please use *-+-commutativeSemiring instead."
#-}
isDistributiveLattice = ⊓-⊔-isDistributiveLattice
{-# WARNING_ON_USAGE isDistributiveLattice
"Warning: isDistributiveLattice was deprecated in v0.14.
Please use ⊓-⊔-isDistributiveLattice instead."
#-}
distributiveLattice = ⊓-⊔-distributiveLattice
{-# WARNING_ON_USAGE distributiveLattice
"Warning: distributiveLattice was deprecated in v0.14.
Please use ⊓-⊔-distributiveLattice instead."
#-}
⊔-⊓-0-isSemiringWithoutOne = ⊔-⊓-isSemiringWithoutOne
{-# WARNING_ON_USAGE ⊔-⊓-0-isSemiringWithoutOne
"Warning: ⊔-⊓-0-isSemiringWithoutOne was deprecated in v0.14.
Please use ⊔-⊓-isSemiringWithoutOne instead."
#-}
⊔-⊓-0-isCommutativeSemiringWithoutOne = ⊔-⊓-isCommutativeSemiringWithoutOne
{-# WARNING_ON_USAGE ⊔-⊓-0-isCommutativeSemiringWithoutOne
"Warning: ⊔-⊓-0-isCommutativeSemiringWithoutOne was deprecated in v0.14.
Please use ⊔-⊓-isCommutativeSemiringWithoutOne instead."
#-}
⊔-⊓-0-commutativeSemiringWithoutOne = ⊔-⊓-commutativeSemiringWithoutOne
{-# WARNING_ON_USAGE ⊔-⊓-0-commutativeSemiringWithoutOne
"Warning: ⊔-⊓-0-commutativeSemiringWithoutOne was deprecated in v0.14.
Please use ⊔-⊓-commutativeSemiringWithoutOne instead."
#-}
-- Version 0.15
¬i+1+j≤i = m+1+n≰m
{-# WARNING_ON_USAGE ¬i+1+j≤i
"Warning: ¬i+1+j≤i was deprecated in v0.15.
Please use m+1+n≰m instead."
#-}
≤-steps = ≤-stepsˡ
{-# WARNING_ON_USAGE ≤-steps
"Warning: ≤-steps was deprecated in v0.15.
Please use ≤-stepsˡ instead."
#-}
-- Version 0.17
i∸k∸j+j∸k≡i+j∸k : ∀ i j k → i ∸ (k ∸ j) + (j ∸ k) ≡ i + j ∸ k
i∸k∸j+j∸k≡i+j∸k zero j k = cong (_+ (j ∸ k)) (0∸n≡0 (k ∸ j))
i∸k∸j+j∸k≡i+j∸k (suc i) j zero = cong (λ x → suc i ∸ x + j) (0∸n≡0 j)
i∸k∸j+j∸k≡i+j∸k (suc i) zero (suc k) = begin-equality
i ∸ k + 0 ≡⟨ +-identityʳ _ ⟩
i ∸ k ≡⟨ cong (_∸ k) (sym (+-identityʳ _)) ⟩
i + 0 ∸ k ∎
i∸k∸j+j∸k≡i+j∸k (suc i) (suc j) (suc k) = begin-equality
suc i ∸ (k ∸ j) + (j ∸ k) ≡⟨ i∸k∸j+j∸k≡i+j∸k (suc i) j k ⟩
suc i + j ∸ k ≡⟨ cong (_∸ k) (sym (+-suc i j)) ⟩
i + suc j ∸ k ∎
{-# WARNING_ON_USAGE i∸k∸j+j∸k≡i+j∸k
"Warning: i∸k∸j+j∸k≡i+j∸k was deprecated in v0.17."
#-}
im≡jm+n⇒[i∸j]m≡n : ∀ i j m n → i * m ≡ j * m + n → (i ∸ j) * m ≡ n
im≡jm+n⇒[i∸j]m≡n i j m n eq = begin-equality
(i ∸ j) * m ≡⟨ *-distribʳ-∸ m i j ⟩
(i * m) ∸ (j * m) ≡⟨ cong (_∸ j * m) eq ⟩
(j * m + n) ∸ (j * m) ≡⟨ cong (_∸ j * m) (+-comm (j * m) n) ⟩
(n + j * m) ∸ (j * m) ≡⟨ m+n∸n≡m n (j * m) ⟩
n ∎
{-# WARNING_ON_USAGE im≡jm+n⇒[i∸j]m≡n
"Warning: im≡jm+n⇒[i∸j]m≡n was deprecated in v0.17."
#-}
≤+≢⇒< = ≤∧≢⇒<
{-# WARNING_ON_USAGE ≤+≢⇒<
"Warning: ≤+≢⇒< was deprecated in v0.17.
Please use ≤∧≢⇒< instead."
#-}
-- Version 1.0
≤-irrelevance = ≤-irrelevant
{-# WARNING_ON_USAGE ≤-irrelevance
"Warning: ≤-irrelevance was deprecated in v1.0.
Please use ≤-irrelevant instead."
#-}
<-irrelevance = <-irrelevant
{-# WARNING_ON_USAGE <-irrelevance
"Warning: <-irrelevance was deprecated in v1.0.
Please use <-irrelevant instead."
#-}
-- Version 1.1
i+1+j≢i = m+1+n≢m
{-# WARNING_ON_USAGE i+1+j≢i
"Warning: i+1+j≢i was deprecated in v1.1.
Please use m+1+n≢m instead."
#-}
i+j≡0⇒i≡0 = m+n≡0⇒m≡0
{-# WARNING_ON_USAGE i+j≡0⇒i≡0
"Warning: i+j≡0⇒i≡0 was deprecated in v1.1.
Please use m+n≡0⇒m≡0 instead."
#-}
i+j≡0⇒j≡0 = m+n≡0⇒n≡0
{-# WARNING_ON_USAGE i+j≡0⇒j≡0
"Warning: i+j≡0⇒j≡0 was deprecated in v1.1.
Please use m+n≡0⇒n≡0 instead."
#-}
i+1+j≰i = m+1+n≰m
{-# WARNING_ON_USAGE i+1+j≰i
"Warning: i+1+j≰i was deprecated in v1.1.
Please use m+1+n≰m instead."
#-}
i*j≡0⇒i≡0∨j≡0 = m*n≡0⇒m≡0∨n≡0
{-# WARNING_ON_USAGE i*j≡0⇒i≡0∨j≡0
"Warning: i*j≡0⇒i≡0∨j≡0 was deprecated in v1.1.
Please use m*n≡0⇒m≡0∨n≡0 instead."
#-}
i*j≡1⇒i≡1 = m*n≡1⇒m≡1
{-# WARNING_ON_USAGE i*j≡1⇒i≡1
"Warning: i*j≡1⇒i≡1 was deprecated in v1.1.
Please use m*n≡1⇒m≡1 instead."
#-}
i*j≡1⇒j≡1 = m*n≡1⇒n≡1
{-# WARNING_ON_USAGE i*j≡1⇒j≡1
"Warning: i*j≡1⇒j≡1 was deprecated in v1.1.
Please use m*n≡1⇒n≡1 instead."
#-}
i^j≡0⇒i≡0 = m^n≡0⇒m≡0
{-# WARNING_ON_USAGE i^j≡0⇒i≡0
"Warning: i^j≡0⇒i≡0 was deprecated in v1.1.
Please use m^n≡0⇒m≡0 instead."
#-}
i^j≡1⇒j≡0∨i≡1 = m^n≡1⇒n≡0∨m≡1
{-# WARNING_ON_USAGE i^j≡1⇒j≡0∨i≡1
"Warning: i^j≡1⇒j≡0∨i≡1 was deprecated in v1.1.
Please use m^n≡1⇒n≡0∨m≡1 instead."
#-}
[i+j]∸[i+k]≡j∸k = [m+n]∸[m+o]≡n∸o
{-# WARNING_ON_USAGE [i+j]∸[i+k]≡j∸k
"Warning: [i+j]∸[i+k]≡j∸k was deprecated in v1.1.
Please use [m+n]∸[m+o]≡n∸o instead."
#-}
m≢0⇒suc[pred[m]]≡m = suc[pred[n]]≡n
{-# WARNING_ON_USAGE m≢0⇒suc[pred[m]]≡m
"Warning: m≢0⇒suc[pred[m]]≡m was deprecated in v1.1.
Please use suc[pred[n]]≡n instead."
#-}
n≡m⇒∣n-m∣≡0 = m≡n⇒∣m-n∣≡0
{-# WARNING_ON_USAGE n≡m⇒∣n-m∣≡0
"Warning: n≡m⇒∣n-m∣≡0 was deprecated in v1.1.
Please use m≡n⇒∣m-n∣≡0 instead."
#-}
∣n-m∣≡0⇒n≡m = ∣m-n∣≡0⇒m≡n
{-# WARNING_ON_USAGE ∣n-m∣≡0⇒n≡m
"Warning: ∣n-m∣≡0⇒n≡m was deprecated in v1.1.
Please use ∣m-n∣≡0⇒m≡n instead."
#-}
∣n-m∣≡n∸m⇒m≤n = ∣m-n∣≡m∸n⇒n≤m
{-# WARNING_ON_USAGE ∣n-m∣≡n∸m⇒m≤n
"Warning: ∣n-m∣≡n∸m⇒m≤n was deprecated in v1.1.
Please use ∣m-n∣≡m∸n⇒n≤m instead."
#-}
∣n-n+m∣≡m = ∣m-m+n∣≡n
{-# WARNING_ON_USAGE ∣n-n+m∣≡m
"Warning: ∣n-n+m∣≡m was deprecated in v1.1.
Please use ∣m-m+n∣≡n instead."
#-}
∣n+m-n+o∣≡∣m-o| = ∣m+n-m+o∣≡∣n-o|
{-# WARNING_ON_USAGE ∣n+m-n+o∣≡∣m-o|
"Warning: ∣n+m-n+o∣≡∣m-o| was deprecated in v1.1.
Please use ∣m+n-m+o∣≡∣n-o| instead."
#-}
n∸m≤∣n-m∣ = m∸n≤∣m-n∣
{-# WARNING_ON_USAGE n∸m≤∣n-m∣
"Warning: n∸m≤∣n-m∣ was deprecated in v1.1.
Please use m∸n≤∣m-n∣ instead."
#-}
∣n-m∣≤n⊔m = ∣m-n∣≤m⊔n
{-# WARNING_ON_USAGE ∣n-m∣≤n⊔m
"Warning: ∣n-m∣≤n⊔m was deprecated in v1.1.
Please use ∣m-n∣≤m⊔n instead."
#-}
n≤m+n : ∀ m n → n ≤ m + n
n≤m+n m n = subst (n ≤_) (+-comm n m) (m≤m+n n m)
{-# WARNING_ON_USAGE n≤m+n
"Warning: n≤m+n was deprecated in v1.1.
Please use m≤n+m instead (note, you will need to switch the argument order)."
#-}
n≤m+n∸m : ∀ m n → n ≤ m + (n ∸ m)
n≤m+n∸m m zero = z≤n
n≤m+n∸m zero (suc n) = ≤-refl
n≤m+n∸m (suc m) (suc n) = s≤s (n≤m+n∸m m n)
{-# WARNING_ON_USAGE n≤m+n∸m
"Warning: n≤m+n∸m was deprecated in v1.1.
Please use m≤n+m∸n instead (note, you will need to switch the argument order)."
#-}
∣n-m∣≡[n∸m]∨[m∸n] : ∀ m n → (∣ n - m ∣ ≡ n ∸ m) ⊎ (∣ n - m ∣ ≡ m ∸ n)
∣n-m∣≡[n∸m]∨[m∸n] m n with ≤-total m n
... | inj₁ m≤n = inj₁ $ m≤n⇒∣n-m∣≡n∸m m≤n
... | inj₂ n≤m = inj₂ $ begin-equality
∣ n - m ∣ ≡⟨ ∣-∣-comm n m ⟩
∣ m - n ∣ ≡⟨ m≤n⇒∣n-m∣≡n∸m n≤m ⟩
m ∸ n ∎
{-# WARNING_ON_USAGE ∣n-m∣≡[n∸m]∨[m∸n]
"Warning: ∣n-m∣≡[n∸m]∨[m∸n] was deprecated in v1.1.
Please use ∣m-n∣≡[m∸n]∨[n∸m] instead (note, you will need to switch the argument order)."
#-}
-- Version 1.2
+-*-suc = *-suc
{-# WARNING_ON_USAGE +-*-suc
"Warning: +-*-suc was deprecated in v1.2.
Please use *-suc instead."
#-}
n∸m≤n : ∀ m n → n ∸ m ≤ n
n∸m≤n m n = m∸n≤m n m
{-# WARNING_ON_USAGE n∸m≤n
"Warning: n∸m≤n was deprecated in v1.2.
Please use m∸n≤m instead (note, you will need to switch the argument order)."
#-}
-- Version 1.3
∀[m≤n⇒m≢o]⇒o<n : ∀ n o → (∀ {m} → m ≤ n → m ≢ o) → n < o
∀[m≤n⇒m≢o]⇒o<n = ∀[m≤n⇒m≢o]⇒n<o
{-# WARNING_ON_USAGE n∸m≤∣n-m∣
"Warning: ∀[m≤n⇒m≢o]⇒o<n was deprecated in v1.3.
Please use ∀[m≤n⇒m≢o]⇒n<o instead."
#-}
∀[m<n⇒m≢o]⇒o≤n : ∀ n o → (∀ {m} → m < n → m ≢ o) → n ≤ o
∀[m<n⇒m≢o]⇒o≤n = ∀[m<n⇒m≢o]⇒n≤o
{-# WARNING_ON_USAGE n∸m≤∣n-m∣
"Warning: ∀[m<n⇒m≢o]⇒o≤n was deprecated in v1.3.
Please use ∀[m<n⇒m≢o]⇒n≤o instead."
#-}
|
{
"alphanum_fraction": 0.4739812469,
"avg_line_length": 29.7134683099,
"ext": "agda",
"hexsha": "0e7fa4834c66420bdf98dc6475abc495765d65de",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Nat/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Nat/Properties.agda",
"max_line_length": 89,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Nat/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 36095,
"size": 67509
}
|
open import Nat
open import Prelude
open import core
open import checks
open import judgemental-erase
module structural where
-- this module contains proofs that the judgements that mention contexts
-- defined throughout the work enjoy the standard structural properties
-- of contexts:
--
-- exchange
--
-- Γ, (x : t1), (y : t2) ⊢ A
-- -------------------------
-- Γ, (y : t2), (x : t1) ⊢ A
--
-- contraction
--
-- Γ, (x : t), (x : t) ⊢ A
-- -----------------------
-- Γ , (x : t) ⊢ A
--
-- weakening
--
-- Γ ⊢ A x # Γ
-- ----------------------
-- Γ , (x : t) ⊢ A
--
-- proofs of the first two are generally easier: viewed as finite
-- functions, the contexts on the top and bottom of both exchange answer
-- every question the same, so an appeal to function extensionality is
-- enough to treat them the same. weakening does not have this property,
-- and there requires some induction to demonstrate.
-- because of our choice to use barendrecht's convention, we need a quite
-- strong form of freshness of a variable for weakening. specifically, we
-- need to know not just that the variable we're using to extend the
-- context doesn't appear in the context, as in a standard presentation,
-- it can't appear anywhere in the term at all; it must be totally
-- fresh. it's possible to drop this requirement with alpha-renaming to
-- recover the standard description of these things, so we allow it here
-- for convenience.
fresh : Nat → ė → Set
fresh x (e ·: t) = fresh x e
fresh x (X y) = natEQp x y
fresh x (·λ y e) = natEQp x y × fresh x e
fresh x (N n) = ⊤
fresh x (e1 ·+ e2) = fresh x e1 × fresh x e2
fresh x ⦇-⦈ = ⊤
fresh x ⦇⌜ e ⌟⦈ = fresh x e
fresh x (e1 ∘ e2) = fresh x e1 × fresh x e2
---- lemmas
-- freshness interacts with erasure as you'd expect. the proofs below mix
-- and match between judgmental and functional erasure as usual, so this
-- is needed enough times to pull it out.
fresh-er-lem : ∀{ e e◆ x} → erase-e e e◆ → fresh x (e ◆e) → fresh x e◆
fresh-er-lem er f = tr (λ q → fresh _ q) ( ! (erasee-det er (rel◆ _))) f
--- a contracted context gives all the same responses as the
--- non-contracted context
lem-contract : (Γ : ·ctx) (x : Nat) (t : τ̇) (y : Nat) →
((Γ ,, (x , t)) ,, (x , t)) y == (Γ ,, (x , t)) y
lem-contract Γ x t y with natEQ x y
lem-contract Γ x t .x | Inl refl = refl
... | Inr qq with natEQ x y
... | Inl pp = abort (qq pp)
... | Inr pp = refl
--- an exchanged context gives all the same responses as the
--- non-exchanged context
lem-swap : (Γ : ·ctx) (x y : Nat) (t1 t2 : τ̇) {x≠y : x == y → ⊥} (z : Nat) →
((Γ ,, (x , t1)) ,, (y , t2)) z == ((Γ ,, (y , t2)) ,, (x , t1)) z
lem-swap Γ x y t1 t2 z with natEQ x z | natEQ y z
lem-swap Γ x y t1 t2 {x≠y} z | Inl p | Inl q = abort (x≠y (p · ! q))
lem-swap Γ x y t1 t2 .x | Inl refl | Inr x₂ with natEQ x x
lem-swap Γ x y t1 t2 .x | Inl refl | Inr x₂ | Inl refl = refl
lem-swap Γ x y t1 t2 .x | Inl refl | Inr x₂ | Inr x₁ = abort (x₁ refl)
lem-swap Γ x y t1 t2 .y | Inr x₁ | Inl refl with natEQ y y
lem-swap Γ x₁ y t1 t2 .y | Inr x₂ | Inl refl | Inl refl = refl
lem-swap Γ x₁ y t1 t2 .y | Inr x₂ | Inl refl | Inr x = abort (x refl)
lem-swap Γ x y t1 t2 z | Inr x₁ | Inr x₂ with natEQ x z | natEQ y z
lem-swap Γ x .x t1 t2 .x | Inr x₂ | Inr x₃ | Inl refl | Inl refl = abort (x₃ refl)
lem-swap Γ x y t1 t2 .x | Inr x₂ | Inr x₃ | Inl refl | Inr x₁ = abort (x₂ refl)
lem-swap Γ x y t1 t2 z | Inr x₃ | Inr x₄ | Inr x₁ | Inl x₂ = abort (x₄ x₂)
lem-swap Γ x y t1 t2 z | Inr x₃ | Inr x₄ | Inr x₁ | Inr x₂ = refl
-- extending a context with a new variable doesn't change anything under
lem-extend : ∀{n x Γ t w} →
(n == x → ⊥) → Γ n == w → (Γ ,, (x , t)) n == w
lem-extend {n} {x} neq w with natEQ x n
lem-extend neq w₁ | Inl refl = abort (neq refl)
lem-extend neq w₁ | Inr x₁ = w₁
---- structural properties for the well-typedness jugements
mutual
wt-exchange-synth : {Γ : ·ctx} {x y : Nat} {t1 t2 t : τ̇} {e : ė} →
{x≠y : x == y → ⊥} →
((Γ ,, (x , t1)) ,, (y , t2)) ⊢ e => t →
((Γ ,, (y , t2)) ,, (x , t1)) ⊢ e => t
wt-exchange-synth {Γ} {x} {y} {t1} {t2} {t} {e} {x≠y} d =
tr (λ q → q ⊢ e => t) (funext (lem-swap Γ x y t1 t2 {x≠y = x≠y})) d
wt-exchange-ana : {Γ : ·ctx} {x y : Nat} {t1 t2 t : τ̇} {e : ė} →
(x≠y : x == y → ⊥) →
((Γ ,, (x , t1)) ,, (y , t2)) ⊢ e <= t →
((Γ ,, (y , t2)) ,, (x , t1)) ⊢ e <= t
wt-exchange-ana {Γ} {x} {y} {t1} {t2} {t} {e} x≠y d =
tr (λ q → q ⊢ e <= t) (funext (lem-swap Γ x y t1 t2 {x≠y = x≠y})) d
mutual
wt-contract-synth : {Γ : ·ctx} {x : Nat} {t t' : τ̇} {e : ė} →
((Γ ,, (x , t')) ,, (x , t')) ⊢ e => t →
(Γ ,, (x , t')) ⊢ e => t
wt-contract-synth {Γ} {x} {t} {t'} {e} wt =
tr (λ q → q ⊢ e => t) (funext (lem-contract Γ x t')) wt
wt-contract-ana : (Γ : ·ctx) (x : Nat) (t t' : τ̇) (e : ė) →
((Γ ,, (x , t')) ,, (x , t')) ⊢ e <= t →
(Γ ,, (x , t')) ⊢ e <= t
wt-contract-ana Γ x t t' e wt =
tr (λ q → q ⊢ e <= t) (funext (lem-contract Γ x t')) wt
mutual
wt-weak-synth : {Γ : ·ctx} {x : Nat} {t t' : τ̇} {e : ė} →
x # Γ →
Γ ⊢ e => t →
fresh x e →
(Γ ,, (x , t')) ⊢ e => t
wt-weak-synth apt (SAsc x₁) f = SAsc (wt-weak-ana apt x₁ f)
wt-weak-synth {x = x} apt (SVar {n = n} x₁) f with natEQ n x
wt-weak-synth apt (SVar x₂) f | Inl refl = abort (somenotnone (! x₂ · apt))
wt-weak-synth apt (SVar x₂) f | Inr x₁ = SVar (lem-extend x₁ x₂)
wt-weak-synth apt (SAp wt x₁ x₂) (f1 , f2) = SAp (wt-weak-synth apt wt f1) x₁ (wt-weak-ana apt x₂ f2)
wt-weak-synth apt SNum f = SNum
wt-weak-synth apt (SPlus x₁ x₂) (f1 , f2) = SPlus (wt-weak-ana apt x₁ f1) (wt-weak-ana apt x₂ f2)
wt-weak-synth apt SEHole f = SEHole
wt-weak-synth apt (SNEHole wt) f = SNEHole (wt-weak-synth apt wt f)
wt-weak-ana : {Γ : ·ctx} {x : Nat} {t t' : τ̇} {e : ė} →
x # Γ →
Γ ⊢ e <= t →
fresh x e →
(Γ ,, (x , t')) ⊢ e <= t
wt-weak-ana apt (ASubsume x₁ x₂) f = ASubsume (wt-weak-synth apt x₁ f) x₂
wt-weak-ana {x = x} apt (ALam {x = x₁} x₂ x₃ wt) f with natEQ x x₁
wt-weak-ana apt (ALam x₃ x₄ wt) (f1 , _) | Inl refl = abort f1
wt-weak-ana apt (ALam x₃ m wt) (f1 , f2) | Inr x₂ = ALam (lem-extend (flip x₂) x₃) m (wt-exchange-ana (flip x₂) (wt-weak-ana (lem-extend x₂ apt) wt f2))
---- structural properties for the action jugements
mutual
act-exchange-synth : ∀{ Γ x y t1 t2 t t' e e' α } →
(x == y → ⊥) →
((Γ ,, (x , t1)) ,, (y , t2)) ⊢ e => t ~ α ~> e' => t' →
((Γ ,, (y , t2)) ,, (x , t1)) ⊢ e => t ~ α ~> e' => t'
act-exchange-synth {Γ} {x} {y} {t1} {t2} {t} {t'} {e} {e'} {α} x≠y d = tr (λ q → q ⊢ e => t ~ α ~> e' => t') (funext (lem-swap Γ x y t1 t2 {x≠y})) d
act-exchange-ana : ∀{ Γ x y t1 t2 t e e' α } →
(x == y → ⊥) →
((Γ ,, (x , t1)) ,, (y , t2)) ⊢ e ~ α ~> e' ⇐ t →
((Γ ,, (y , t2)) ,, (x , t1)) ⊢ e ~ α ~> e' ⇐ t
act-exchange-ana {Γ} {x} {y} {t1} {t2} {t} {e} {e'} {α} x≠y d = tr (λ q → q ⊢ e ~ α ~> e' ⇐ t) (funext (lem-swap Γ x y t1 t2 {x≠y})) d
mutual
act-contract-synth : ∀{ Γ x t t' t'' e e' α } →
((Γ ,, (x , t'')) ,, (x , t'')) ⊢ e => t ~ α ~> e' => t' →
(Γ ,, (x , t'')) ⊢ e => t ~ α ~> e' => t'
act-contract-synth {Γ} {x} {t} {t'} {t''} {e} {e'} {α} d = tr (λ q → q ⊢ e => t ~ α ~> e' => t') (funext (lem-contract Γ x t'')) d
act-contract-ana : ∀{ Γ x t t' e e' α } →
((Γ ,, (x , t')) ,, (x , t')) ⊢ e ~ α ~> e' ⇐ t →
(Γ ,, (x , t')) ⊢ e ~ α ~> e' ⇐ t
act-contract-ana {Γ} {x} {t} {t'} {e} {e'} {α} d = tr (λ q → q ⊢ e ~ α ~> e' ⇐ t) (funext (lem-contract Γ x t')) d
mutual
act-weak-synth : ∀{ Γ x t t' t'' e e' α } →
x # Γ →
fresh x (e ◆e) →
fresh x (e' ◆e) →
(d : Γ ⊢ e => t ~ α ~> e' => t') →
(Γ ,, (x , t'')) ⊢ e => t ~ α ~> e' => t'
act-weak-synth apt f f' (SAMove x₁) = SAMove x₁
act-weak-synth apt f f' SADel = SADel
act-weak-synth apt f f' SAConAsc = SAConAsc
act-weak-synth {x = x} apt f f' (SAConVar {x = y} p) with natEQ x y
act-weak-synth apt f f' (SAConVar p) | Inl refl = abort (somenotnone (! p · apt))
act-weak-synth apt f f' (SAConVar p) | Inr x₂ = SAConVar (lem-extend (flip x₂) p)
act-weak-synth {x = x} apt f f' (SAConLam {x = y} x₂) with natEQ x y
act-weak-synth apt f f' (SAConLam x₃) | Inl refl = abort (π1 f')
act-weak-synth apt f f' (SAConLam x₃) | Inr x₂ = SAConLam (lem-extend (flip x₂) x₃)
act-weak-synth apt f f' (SAConApArr x₁) = SAConApArr x₁
act-weak-synth apt f f' (SAConApOtw x₁) = SAConApOtw x₁
act-weak-synth apt f f' SAConNumlit = SAConNumlit
act-weak-synth apt f f' (SAConPlus1 x₁) = SAConPlus1 x₁
act-weak-synth apt f f' (SAConPlus2 x₁) = SAConPlus2 x₁
act-weak-synth apt f f' SAConNEHole = SAConNEHole
act-weak-synth apt f f' (SAFinish x₁) = SAFinish (wt-weak-synth apt x₁ f')
act-weak-synth apt f f' (SAZipAsc1 x₁) = SAZipAsc1 (act-weak-ana apt f f' x₁)
act-weak-synth apt f f' (SAZipAsc2 x₁ x₂ x₃ x₄) = SAZipAsc2 x₁ x₂ x₃ (wt-weak-ana apt x₄ f')
act-weak-synth apt f f' (SAZipApArr x₁ x₂ x₃ d x₄) = SAZipApArr x₁ x₂ (wt-weak-synth apt x₃ (fresh-er-lem x₂ (π1 f)))
(act-weak-synth apt (π1 f) (π1 f') d)
(wt-weak-ana apt x₄ (π2 f'))
act-weak-synth apt f f' (SAZipApAna x₁ x₂ x₃) = SAZipApAna x₁ (wt-weak-synth apt x₂ (π1 f'))
(act-weak-ana apt (π2 f) (π2 f') x₃)
act-weak-synth apt f f' (SAZipPlus1 x₁) = SAZipPlus1 (act-weak-ana apt (π1 f) (π1 f') x₁)
act-weak-synth apt f f' (SAZipPlus2 x₁) = SAZipPlus2 (act-weak-ana apt (π2 f) (π2 f') x₁)
act-weak-synth apt f f' (SAZipHole x₁ x₂ d) = SAZipHole x₁ (wt-weak-synth apt x₂ (fresh-er-lem x₁ f))
(act-weak-synth apt f f' d)
act-weak-ana : ∀{ Γ x t t' e e' α } →
x # Γ →
fresh x (e ◆e) →
fresh x (e' ◆e) →
(d : Γ ⊢ e ~ α ~> e' ⇐ t) →
(Γ ,, (x , t')) ⊢ e ~ α ~> e' ⇐ t
act-weak-ana apt f f' (AASubsume x₁ x₂ x₃ x₄) = AASubsume x₁ (wt-weak-synth apt x₂ (fresh-er-lem x₁ f)) (act-weak-synth apt f f' x₃) x₄
act-weak-ana apt f f' (AAMove x₁) = AAMove x₁
act-weak-ana apt f f' AADel = AADel
act-weak-ana apt f f' AAConAsc = AAConAsc
act-weak-ana {x = x} apt f f' (AAConVar {x = y} x₂ p) with natEQ x y
act-weak-ana apt f f' (AAConVar x₃ p) | Inl refl = abort (somenotnone (! p · apt))
act-weak-ana apt f f' (AAConVar x₃ p) | Inr x₂ = AAConVar x₃ (lem-extend (flip x₂) p)
act-weak-ana {x = x} apt f f' (AAConLam1 {x = y} x₂ x₃) with natEQ x y
act-weak-ana apt f f' (AAConLam1 x₃ x₄) | Inl refl = abort (π1 f')
act-weak-ana apt f f' (AAConLam1 x₃ x₄) | Inr x₂ = AAConLam1 (lem-extend (flip x₂) x₃) x₄
act-weak-ana {x = x} apt f f' (AAConLam2 {x = y} x₂ x₃) with natEQ x y
act-weak-ana apt f f' (AAConLam2 x₃ x₄) | Inl refl = abort (π1 f')
act-weak-ana apt f f' (AAConLam2 x₃ x₄) | Inr x₂ = AAConLam2 (lem-extend (flip x₂) x₃) x₄
act-weak-ana apt f f' (AAConNumlit x₁) = AAConNumlit x₁
act-weak-ana apt f f' (AAFinish x₁) = AAFinish (wt-weak-ana apt x₁ f')
act-weak-ana {x = x} apt f f' (AAZipLam {x = y} x₂ x₃ d) with natEQ x y
act-weak-ana apt f f' (AAZipLam x₃ x₄ d) | Inl refl = abort (π1 f')
act-weak-ana apt f f' (AAZipLam x₃ x₄ d) | Inr x₂ = AAZipLam (lem-extend (flip x₂) x₃) x₄ (act-exchange-ana (flip x₂) (act-weak-ana (lem-extend x₂ apt) (π2 f) (π2 f') d))
|
{
"alphanum_fraction": 0.4959967974,
"avg_line_length": 52.9237288136,
"ext": "agda",
"hexsha": "fc25fa81202202758136fd7ef3becc395d816cd1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-07-03T03:45:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-07-03T03:45:07.000Z",
"max_forks_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/agda-popl17",
"max_forks_repo_path": "structural.agda",
"max_issues_count": 37,
"max_issues_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_issues_repo_issues_event_max_datetime": "2016-11-09T18:13:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-07-07T16:23:11.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/agda-popl17",
"max_issues_repo_path": "structural.agda",
"max_line_length": 174,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/agda-popl17",
"max_stars_repo_path": "structural.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-11T12:30:50.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-01T22:44:11.000Z",
"num_tokens": 5087,
"size": 12490
}
|
module Sets.IterativeSet.Oper.Proofs 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 Logic.Propositional
open import Logic.Predicate
open import Relator.Equals using () renaming (_≡_ to Id ; [≡]-intro to intro)
open import Sets.IterativeSet.Oper
open import Sets.IterativeSet.Relator
open import Sets.IterativeSet.Relator.Proofs
open import Sets.IterativeSet
open import Structure.Function.Domain
open import Structure.Function
open import Structure.Relator.Properties
open import Structure.Relator
open import Syntax.Function
open import Syntax.Transitivity
open import Type.Dependent
open import Type.Properties.Decidable
open import Type.Properties.Decidable.Proofs
module _ where
private variable {ℓ ℓ₁ ℓ₂} : Lvl.Level
open Iset
-- If there is an element in the empty set, then there exists an instance of the empty type by definition, and that is false by definition.
∅-membership : ∀{x : Iset{ℓ₁}} → (x ∉ ∅ {ℓ₂})
∅-membership ()
-- There is a bijection between (A ‖ B) and ∃{Lvl.Up Bool}(\{(Lvl.up 𝐹) → A ; (Lvl.up 𝑇) → B}).
pair-membership : ∀{a b x : Iset{ℓ}} → (x ∈ pair a b) ↔ (x ≡ a)∨(x ≡ b)
Tuple.left (pair-membership {a = a} {x}) ([∨]-introₗ p) = [∃]-intro (Lvl.up 𝐹) ⦃ p ⦄
Tuple.left (pair-membership {a = a} {x}) ([∨]-introᵣ p) = [∃]-intro (Lvl.up 𝑇) ⦃ p ⦄
Tuple.right (pair-membership {a = a} {x}) ([∃]-intro (Lvl.up 𝐹) ⦃ eq ⦄) = [∨]-introₗ eq
Tuple.right (pair-membership {a = a} {x}) ([∃]-intro (Lvl.up 𝑇) ⦃ eq ⦄) = [∨]-introᵣ eq
-- There is a bijection between (A) and ∃{Unit}(\{<> → A}).
singleton-membership : ∀{a x : Iset{ℓ}} → (x ∈ singleton(a)) ↔ (x ≡ a)
Tuple.left (singleton-membership {a = a} {x}) xin = [∃]-intro <> ⦃ xin ⦄
Tuple.right (singleton-membership {a = a} {x}) ([∃]-intro i ⦃ eq ⦄ ) = eq
[∪]-membership : ∀{A B x : Iset{ℓ}} → (x ∈ (A ∪ B)) ↔ (x ∈ A)∨(x ∈ B)
Tuple.left ([∪]-membership {A = A} {B} {x}) ([∨]-introₗ ([∃]-intro ia)) = [∃]-intro (Either.Left ia)
Tuple.left ([∪]-membership {A = A} {B} {x}) ([∨]-introᵣ ([∃]-intro ib)) = [∃]-intro (Either.Right ib)
Tuple.right ([∪]-membership {A = A} {B} {x}) ([∃]-intro ([∨]-introₗ ia)) = [∨]-introₗ ([∃]-intro ia)
Tuple.right ([∪]-membership {A = A} {B} {x}) ([∃]-intro ([∨]-introᵣ ib)) = [∨]-introᵣ ([∃]-intro ib)
[⋃]-membership : ∀{A x : Iset{ℓ}} → (x ∈ (⋃ A)) ↔ ∃(a ↦ (a ∈ A) ∧ (x ∈ a))
Σ.left (∃.witness (Tuple.left ([⋃]-membership {A = A} {x}) ([∃]-intro a ⦃ [∧]-intro ([∃]-intro iA) _ ⦄))) = iA
Σ.right (∃.witness (Tuple.left ([⋃]-membership {A = A} {x}) ([∃]-intro a ⦃ [∧]-intro ([∃]-intro iA ⦃ aA ⦄) ([∃]-intro ia) ⦄))) = _⊆_.map (Tuple.right aA) ia
∃.proof (Tuple.left ([⋃]-membership {A = A} {x}) ([∃]-intro a ⦃ [∧]-intro ([∃]-intro iA ⦃ aA ⦄) ([∃]-intro ia ⦃ xa ⦄) ⦄)) = [≡]-transitivity-raw xa ([⊆]-with-elem (sub₂(_≡_)(_⊆_) aA) {ia})
∃.witness (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄)) = elem(A)(iA)
Tuple.left (∃.proof (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄))) = [∈]-of-elem {A = A}
∃.witness (Tuple.right (∃.proof (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄)))) = ia
∃.proof (Tuple.right (∃.proof (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄)))) = proof
module _ {A : Iset{ℓ}} where
open import Relator.Equals.Proofs.Equivalence using ([≡]-equiv)
instance _ = [≡]-equiv {T = Index(A)}
module _ {P : Index(A) → Stmt{ℓ}} where
indexFilter-elem-membershipₗ : ∀{i : Index(A)} → (elem(A)(i) ∈ indexFilter A P) ← P(i)
Σ.left (∃.witness ((indexFilter-elem-membershipₗ {i = i}) pi)) = i
Σ.right(∃.witness ((indexFilter-elem-membershipₗ {i = i}) pi)) = pi
Tuple.left (∃.proof (indexFilter-elem-membershipₗ pi)) = intro id [≡]-reflexivity-raw
Tuple.right (∃.proof (indexFilter-elem-membershipₗ pi)) = intro id [≡]-reflexivity-raw
module _
⦃ _ : Injective(elem A) ⦄ -- TODO: Is this satisfiable?
{P : Index(A) → Stmt{ℓ}}
⦃ unaryRelator-P : UnaryRelator(P) ⦄
where
indexFilter-elem-membership : ∀{i : Index(A)} → (elem(A)(i) ∈ indexFilter A P) ↔ P(i)
Tuple.left indexFilter-elem-membership = indexFilter-elem-membershipₗ
Tuple.right (indexFilter-elem-membership {i = i}) ([∃]-intro (intro iA PiA) ⦃ pp ⦄) = substitute₁(P) (injective(elem A) (symmetry(_≡_) pp)) PiA
filter-elem-membership : ∀{A : Iset{ℓ}}{P} ⦃ _ : UnaryRelator(P) ⦄ {i : Index(A)} → (elem(A)(i) ∈ filter A P) ↔ P(elem(A)(i))
Tuple.left (filter-elem-membership {A = A}{P = P}) = indexFilter-elem-membershipₗ {A = A}{P = P ∘ elem(A)}
Tuple.right (filter-elem-membership {P = P}) ([∃]-intro (intro iA PiA) ⦃ pp ⦄) = substitute₁(P) (symmetry(_≡_) pp) PiA
filter-membership : ∀{A : Iset{ℓ}}{P} ⦃ _ : UnaryRelator(P) ⦄ {x : Iset{ℓ}} → (x ∈ filter A P) ↔ ((x ∈ A) ∧ P(x))
∃.witness (Tuple.left(filter-membership {P = P}) ([∧]-intro ([∃]-intro i ⦃ p ⦄) pb)) = intro i (substitute₁(P) p pb)
∃.proof (Tuple.left(filter-membership) ([∧]-intro ([∃]-intro i ⦃ p ⦄) pb)) = p
∃.witness (Tuple.left (Tuple.right(filter-membership) ([∃]-intro (intro iA PiA) ⦃ pp ⦄))) = iA
∃.proof (Tuple.left (Tuple.right(filter-membership) ([∃]-intro (intro iA PiA) ⦃ pp ⦄))) = pp
Tuple.right (Tuple.right(filter-membership {P = P}) ([∃]-intro (intro iA PiA) ⦃ pp ⦄)) = substitute₁(P) (symmetry(_≡_) pp) PiA
mapSet-membership : ∀{A : Iset{ℓ}}{f} ⦃ _ : Function(f) ⦄ {y : Iset{ℓ}} → (y ∈ mapSet f(A)) ↔ ∃(x ↦ (x ∈ A) ∧ (y ≡ f(x)))
∃.witness (Tuple.left (mapSet-membership) ([∃]-intro x ⦃ [∧]-intro xA fxy ⦄)) = [∃]-witness xA
∃.proof (Tuple.left (mapSet-membership {A = A} {f = f} {y = y}) ([∃]-intro x ⦃ [∧]-intro xA fxy ⦄)) =
y 🝖[ _≡_ ]-[ fxy ]
f(x) 🝖[ _≡_ ]-[ congruence₁(f) ([∃]-proof xA) ]
f(elem(A) ([∃]-witness xA)) 🝖[ _≡_ ]-[]
elem (mapSet f(A)) ([∃]-witness xA) 🝖[ _≡_ ]-end
∃.witness (Tuple.right (mapSet-membership {A = A}) ([∃]-intro iA)) = elem(A) iA
Tuple.left (∃.proof (Tuple.right (mapSet-membership {A = A}) ([∃]-intro iA ⦃ p ⦄))) = [∈]-of-elem {A = A} {ia = iA}
Tuple.right (∃.proof (Tuple.right mapSet-membership ([∃]-intro iA ⦃ p ⦄))) = p
open import Logic.Classical
module _ ⦃ classical : ∀{ℓ}{P} → Classical{ℓ}(P) ⦄ where
instance _ = classical-to-decidable
instance _ = classical-to-decider
indexFilterBool-subset : ∀{A : Iset{ℓ}}{P} → (indexFilterBool A P ⊆ A)
_⊇_.map indexFilterBool-subset (intro iA _) = iA
_⊇_.proof (indexFilterBool-subset {ℓ = ℓ}{A = A}{P = P}) {intro iA (Lvl.up PiA)} =
elem (indexFilterBool A P) (intro iA (Lvl.up PiA)) 🝖[ _≡_ ]-[]
elem (indexFilter A (Lvl.Up ∘ IsTrue ∘ P)) (intro iA (Lvl.up PiA)) 🝖[ _≡_ ]-[]
elem A (Σ.left {B = Lvl.Up{ℓ} ∘ IsTrue ∘ P} (intro iA (Lvl.up PiA))) 🝖[ _≡_ ]-[]
elem A iA 🝖[ _≡_ ]-end
℘-membershipₗ : ∀{A : Iset{ℓ}}{B : Iset{ℓ}} → (B ∈ ℘(A)) ← (B ⊆ A)
∃.witness (℘-membershipₗ {A = A}{B = B} BA) iA = decide(0)(∃(iB ↦ Id(_⊆_.map BA iB) iA))
_⊇_.map (Tuple.left (∃.proof (℘-membershipₗ {A = A} {B = B} _))) (intro iA (Lvl.up mapiBiA)) = [∃]-witness([↔]-to-[←] decider-true mapiBiA)
_⊇_.proof (Tuple.left (∃.proof (℘-membershipₗ {ℓ = ℓ} {A = A} {B = B} BA))) {intro iA (Lvl.up mapiBiA)} =
elem (elem (℘ A) f) (intro iA (Lvl.up mapiBiA)) 🝖[ _≡_ ]-[]
elem (indexFilterBool A f) (intro iA (Lvl.up mapiBiA)) 🝖[ _≡_ ]-[]
elem (indexFilter A (Lvl.Up ∘ IsTrue ∘ f)) (intro iA (Lvl.up mapiBiA)) 🝖[ _≡_ ]-[]
elem A (Σ.left {B = Lvl.Up{ℓ} ∘ IsTrue ∘ f} (intro iA (Lvl.up mapiBiA))) 🝖[ _≡_ ]-[]
elem A iA 🝖[ _≡_ ]-[ [≡]-to-equivalence(congruence₁(elem A) ([∃]-proof emapiBiA)) ]-sym
elem A (_⊆_.map BA ([∃]-witness emapiBiA)) 🝖[ _≡_ ]-[ _⊆_.proof BA {[∃]-witness emapiBiA} ]-sym
elem B ([∃]-witness emapiBiA) 🝖[ _≡_ ]-end
where
f = \iA → decide(0)(∃(iB ↦ Id(_⊆_.map BA iB) iA))
emapiBiA = [↔]-to-[←] decider-true mapiBiA
open import Relator.Equals.Proofs.Equiv using ([≡]-to-equivalence)
_⊇_.map (Tuple.right (∃.proof (℘-membershipₗ {A = A} {B = B} BA))) iB = intro (_⊆_.map BA iB) (Lvl.up ([↔]-to-[→] decider-true ([∃]-intro iB ⦃ intro ⦄)))
_⊇_.proof (Tuple.right (∃.proof (℘-membershipₗ {A = A} {B = B} BA))) = _⊆_.proof BA
℘-membershipᵣ : ∀{A : Iset{ℓ}}{B : Iset{ℓ}} → (B ∈ ℘(A)) → (B ⊆ A)
℘-membershipᵣ ([∃]-intro witness ⦃ b≡indexFilterBool ⦄) = substitute₂ₗ(_⊆_) (symmetry(_≡_) b≡indexFilterBool) indexFilterBool-subset
℘-membership : ∀{A : Iset{ℓ}}{x : Iset{ℓ}} → (x ∈ ℘(A)) ↔ (x ⊆ A)
℘-membership = [↔]-intro ℘-membershipₗ ℘-membershipᵣ
|
{
"alphanum_fraction": 0.5540065862,
"avg_line_length": 64.1549295775,
"ext": "agda",
"hexsha": "c573dbad1d832f5089982df95bc455a8cea47bf9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Sets/IterativeSet/Oper/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Sets/IterativeSet/Oper/Proofs.agda",
"max_line_length": 190,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Sets/IterativeSet/Oper/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 3767,
"size": 9110
}
|
module Tensor where
open import Basics
open import Ix
open import All
open import Perm
open import Cutting
open import Recutter
open _|>_
open RECUTTER
open SUBCOLLECTLEMMA
_><_ : forall {I J} -> (I |> I) -> (J |> J) -> (I * J) |> (I * J)
Cuts (C >< D) (i , j) = Cuts C i + Cuts D j
inners (C >< D) {i , j} (inl c) = list (_, j) (inners C c)
inners (C >< D) {i , j} (inr d) = list (i ,_) (inners D d)
module TENSORRECUT {I J}(C : I |> I)(D : J |> J)(rec : Recutter C)(red : Recutter D) where
cartLeftLemma : (is : List I)(j : J)(d : Cuts D j) -> subCollect (C >< D) (list (_, j) is)
(allRe (_, j) is
(allPu (\ _ -> inr (inr d)) is)) == cart is (inners D d)
cartLeftLemma [] j d = refl []
cartLeftLemma (i ,- is) j d = refl (list (i ,_) (inners D d) +L_) =$= cartLeftLemma is j d
cartRightLemma : (i : I)(c : Cuts C i)(js : List J) ->
subCollect (C >< D) (list (i ,_) js)
(allRe (i ,_) js (allPu (\ _ -> inr (inl c)) js)) ==
list swap (cart js (inners C c))
cartRightLemma i c [] = refl []
cartRightLemma i c (j ,- js)
rewrite sym (catNatural swap (list (j ,_) (inners C c)) (cart js (inners C c)))
| listlist swap (j ,_) (_, j) (\ i -> refl (i , j)) (inners C c)
= refl (list (_, j) (inners C c) +L_) =$= cartRightLemma i c js
TensorRecut : Recutter (C >< D)
-- both cuts in left dimension
TensorRecut (i , j) (inl c) (inl c') with rec i c c'
... | x , y , m
= allRe (_, j) (inners C c) (all (\ _ -> id +map inl) _ x)
, allRe (_, j) (inners C c') (all (\ _ -> id +map inl) _ y)
, lemma where
lemma : subCollect (C >< D) (list (_, j) (inners C c))
(allRe (_, j) (inners C c) (all (\ _ -> id +map inl) (inners C c) x))
~
subCollect (C >< D) (list (_, j) (inners C c'))
(allRe (_, j) (inners C c') (all (\ _ -> id +map inl) (inners C c') y))
lemma rewrite subCollectLemma C (C >< D) (_, j) (\ _ -> inl) (\ i c -> refl _)
(inners C c) x
| subCollectLemma C (C >< D) (_, j) (\ _ -> inl) (\ i c -> refl _)
(inners C c') y
= permap (_, j) m
-- left to right
fst (TensorRecut (i , j) (inl c) (inr d)) =
allRe (_, j) (inners C c) (allPu (\ i -> inr (inr d)) (inners C c))
fst (snd (TensorRecut (i , j) (inl c) (inr d))) =
allRe (i ,_) (inners D d) (allPu (\ i -> inr (inl c)) (inners D d))
snd (snd (TensorRecut (i , j) (inl c) (inr d)))
rewrite cartLeftLemma (inners C c) j d
| cartRightLemma i c (inners D d)
= cartLemma (inners C c) (inners D d)
-- right to left
fst (TensorRecut (i , j) (inr d) (inl c)) =
allRe (i ,_) (inners D d) (allPu (\ i -> inr (inl c)) (inners D d))
fst (snd (TensorRecut (i , j) (inr d) (inl c))) =
allRe (_, j) (inners C c) (allPu (\ i -> inr (inr d)) (inners C c))
snd (snd (TensorRecut (i , j) (inr d) (inl c)))
rewrite cartLeftLemma (inners C c) j d
| cartRightLemma i c (inners D d)
= symP (cartLemma (inners C c) (inners D d))
-- both cuts in right dimension
TensorRecut (i , j) (inr d) (inr d') with red j d d'
... | x , y , m
= allRe (i ,_) (inners D d) (all (\ _ -> id +map inr) _ x)
, allRe (i ,_) (inners D d') (all (\ _ -> id +map inr) _ y)
, lemma where
lemma : subCollect (C >< D) (list (i ,_) (inners D d))
(allRe (i ,_) (inners D d) (all (\ _ -> id +map inr) (inners D d) x))
~
subCollect (C >< D) (list (i ,_) (inners D d'))
(allRe (i ,_) (inners D d') (all (\ _ -> id +map inr) (inners D d') y))
lemma rewrite subCollectLemma D (C >< D) (i ,_) (\ _ -> inr) (\ i d -> refl _)
(inners D d) x
| subCollectLemma D (C >< D) (i ,_) (\ _ -> inr) (\ i d -> refl _)
(inners D d') y
= permap (i ,_) m
module RECTANGLE where
RectCut = NatCut >< NatCut
open NATRECUT
open TENSORRECUT NatCut NatCut NatRecut NatRecut
RectRecut = TensorRecut
|
{
"alphanum_fraction": 0.4890861118,
"avg_line_length": 40.8725490196,
"ext": "agda",
"hexsha": "9c7fcca4841ac645fe5bf309aef199feb38f9d9e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pigworker/InteriorDesign",
"max_forks_repo_path": "Tensor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pigworker/InteriorDesign",
"max_issues_repo_path": "Tensor.agda",
"max_line_length": 92,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pigworker/InteriorDesign",
"max_stars_repo_path": "Tensor.agda",
"max_stars_repo_stars_event_max_datetime": "2018-07-31T02:00:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-18T15:25:39.000Z",
"num_tokens": 1505,
"size": 4169
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- An inductive definition for the permutation relation
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.Permutation.Inductive
{a} {A : Set a} where
open import Data.List using (List; []; _∷_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
import Relation.Binary.Reasoning.Setoid as EqReasoning
------------------------------------------------------------------------
-- An inductive definition of permutation
infix 3 _↭_
data _↭_ : Rel (List A) a where
refl : ∀ {xs} → xs ↭ xs
prep : ∀ {xs ys} x → xs ↭ ys → x ∷ xs ↭ x ∷ ys
swap : ∀ {xs ys} x y → xs ↭ ys → x ∷ y ∷ xs ↭ y ∷ x ∷ ys
trans : ∀ {xs ys zs} → xs ↭ ys → ys ↭ zs → xs ↭ zs
------------------------------------------------------------------------
-- _↭_ is an equivalence
↭-reflexive : _≡_ ⇒ _↭_
↭-reflexive refl = refl
↭-refl : Reflexive _↭_
↭-refl = refl
↭-sym : ∀ {xs ys} → xs ↭ ys → ys ↭ xs
↭-sym refl = refl
↭-sym (prep x xs↭ys) = prep x (↭-sym xs↭ys)
↭-sym (swap x y xs↭ys) = swap y x (↭-sym xs↭ys)
↭-sym (trans xs↭ys ys↭zs) = trans (↭-sym ys↭zs) (↭-sym xs↭ys)
↭-trans : Transitive _↭_
↭-trans = trans
↭-isEquivalence : IsEquivalence _↭_
↭-isEquivalence = record
{ refl = refl
; sym = ↭-sym
; trans = trans
}
↭-setoid : Setoid _ _
↭-setoid = record
{ isEquivalence = ↭-isEquivalence
}
------------------------------------------------------------------------
-- A reasoning API to chain permutation proofs and allow "zooming in"
-- to localised reasoning.
module PermutationReasoning where
open EqReasoning ↭-setoid
using (_IsRelatedTo_; relTo)
open EqReasoning ↭-setoid public
using (begin_ ; _∎ ; _≡⟨⟩_; _≡⟨_⟩_)
renaming (_≈⟨_⟩_ to _↭⟨_⟩_; _≈˘⟨_⟩_ to _↭˘⟨_⟩_)
infixr 2 _∷_<⟨_⟩_ _∷_∷_<<⟨_⟩_
-- Skip reasoning on the first element
_∷_<⟨_⟩_ : ∀ x xs {ys zs : List A} → xs ↭ ys →
(x ∷ ys) IsRelatedTo zs → (x ∷ xs) IsRelatedTo zs
x ∷ xs <⟨ xs↭ys ⟩ rel = relTo (trans (prep x xs↭ys) (begin rel))
-- Skip reasoning about the first two elements
_∷_∷_<<⟨_⟩_ : ∀ x y xs {ys zs : List A} → xs ↭ ys →
(y ∷ x ∷ ys) IsRelatedTo zs → (x ∷ y ∷ xs) IsRelatedTo zs
x ∷ y ∷ xs <<⟨ xs↭ys ⟩ rel = relTo (trans (swap x y xs↭ys) (begin rel))
|
{
"alphanum_fraction": 0.5062575696,
"avg_line_length": 30.2073170732,
"ext": "agda",
"hexsha": "023bb4e7884f41416bac27da821cf72e814edaf5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Permutation/Inductive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Permutation/Inductive.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Permutation/Inductive.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 870,
"size": 2477
}
|
-- Andreas, 2016-10-06 issue #2239
-- We need to subtract number of locals when computing
-- de Bruijn index of split variable!
-- {-# OPTIONS -v interaction.case:50 #-}
data Bool : Set where
true false : Bool
test : (x y z : Bool) → Bool
test x y = λ z → {!y !} -- splitting on y should succeed
fails : (x y z : Bool) → Bool
fails x y = λ z → {!z !} -- splitting on z should fail
|
{
"alphanum_fraction": 0.6307692308,
"avg_line_length": 24.375,
"ext": "agda",
"hexsha": "b7abc7feee74f4082ec773c361b0cb6bbbd50e87",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue2239.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue2239.agda",
"max_line_length": 57,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue2239.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 121,
"size": 390
}
|
------------------------------------------------------------------------
-- Code related to the paper "Partiality, Revisited: The Partiality
-- Monad as a Quotient Inductive-Inductive Type"
--
-- Thorsten Altenkirch, Nils Anders Danielsson and Nicolai Kraus
------------------------------------------------------------------------
-- Note that this is a version of the code that does not quite match
-- the description in the paper. Some key changes (there might be
-- others):
--
-- * The partiality monad is not postulated, but defined as a QIIT
-- (Agda's cubical features are used). The types and eliminators are
-- marked as "abstract", so the eliminators do not compute.
--
-- * Rewrite rules are no longer used. Instead the propositional
-- truncation and set quotient operators are defined as
-- (non-abstract) QITs.
--
-- * The set quotient operator that is used can be applied to
-- arbitrary binary relations, not only propositional ones.
{-# OPTIONS --cubical --sized-types #-}
module README where
-- Note that our definition of the partiality monad and some of the
-- results are heavily inspired by the section on Cauchy reals in the
-- HoTT book (first edition).
-- The partiality algebra code uses ideas and concepts from "Inductive
-- types in homotopy type theory" by Awodey, Gambino and Sojakova,
-- "Inductive Types in Homotopy Type Theory" by Sojakova, "Quotient
-- inductive-inductive types" by Altenkirch, Capriotti, Dijkstra and
-- Nordvall Forsberg, and Gabe Dijkstra's PhD thesis.
------------------------------------------------------------------------
-- Pointers to results from the paper
-- In order to more easily find code corresponding to results from the
-- paper, see the following module. Note that some of the code
-- referenced below is not discussed at all in the paper.
import README.Pointers-to-results-from-the-paper
------------------------------------------------------------------------
-- Partiality algebras
-- Partiality algebras.
import Partiality-algebra
-- Some partiality algebra properties.
import Partiality-algebra.Properties
-- Partiality algebra categories.
import Partiality-algebra.Category
-- Eliminators and initiality.
import Partiality-algebra.Eliminators
-- Monotone functions.
import Partiality-algebra.Monotone
-- ω-continuous functions.
import Partiality-algebra.Omega-continuous
-- Strict ω-continuous functions.
import Partiality-algebra.Strict-omega-continuous
-- Fixpoint combinators.
import Partiality-algebra.Fixpoints
-- Pi with partiality algebra families as codomains.
import Partiality-algebra.Pi
------------------------------------------------------------------------
-- The partiality monad
-- A quotient inductive-inductive definition of the partiality monad.
import Partiality-monad.Inductive
-- Specialised eliminators.
import Partiality-monad.Inductive.Eliminators
-- A function that runs computations.
import Partiality-monad.Inductive.Approximate
-- An alternative characterisation of the information ordering, along
-- with related results.
import Partiality-monad.Inductive.Alternative-order
-- Monotone functions.
import Partiality-monad.Inductive.Monotone
-- ω-continuous functions.
import Partiality-monad.Inductive.Omega-continuous
-- The partiality monad's monad instance.
import Partiality-monad.Inductive.Monad
-- The partiality monad's monad instance, defined via an adjunction.
import Partiality-monad.Inductive.Monad.Adjunction
-- Strict ω-continuous functions.
import Partiality-monad.Inductive.Strict-omega-continuous
-- Fixpoint combinators.
import Partiality-monad.Inductive.Fixpoints
------------------------------------------------------------------------
-- Some examples
-- A function that, given a stream, tries to find an element
-- satisfying a predicate.
import Search
-- Examples involving simple λ-calculi.
import README.Lambda
------------------------------------------------------------------------
-- An alternative definition of the delay monad
-- The delay monad, defined using increasing sequences of potential
-- values.
import Delay-monad.Alternative
-- Various properties.
import Delay-monad.Alternative.Properties
-- Theorems relating the coinductive definition of the delay
-- monad to the alternative one and to another type.
import Delay-monad.Alternative.Equivalence
-- Termination predicates.
import Delay-monad.Alternative.Termination
-- Information orderings.
import Delay-monad.Alternative.Partial-order
-- Weak bisimilarity.
import Delay-monad.Alternative.Weak-bisimilarity
-- Two eliminators for Delay-monad.Alternative.Delay (A / R).
import Delay-monad.Alternative.Eliminators
------------------------------------------------------------------------
-- The delay monad quotiented by weak bisimilarity
-- The delay monad quotiented by weak bisimilarity.
import Partiality-monad.Coinductive
-- A partial order.
import Partiality-monad.Coinductive.Partial-order
-- An alternative definition of the partiality monad: a variant of the
-- delay monad quotiented by a notion of weak bisimilarity.
import Partiality-monad.Coinductive.Alternative
------------------------------------------------------------------------
-- A proof of equivalence
-- The partiality monads in Partiality-monad.Inductive and
-- Partiality-monad.Coinductive are pointwise equivalent, for sets,
-- assuming extensionality and countable choice.
import Partiality-monad.Equivalence
------------------------------------------------------------------------
-- ω-cpos
-- Pointed and non-pointed ω-cpos.
import Omega-cpo
-- The code in the following three modules is based on a suggestion
-- from Paolo Capriotti.
-- A quotient inductive-inductive definition of the lifting
-- construction on ω-cpos.
import Lifting
-- An alternative but equivalent definition of the partiality monad
-- (but only for sets), based on the lifting construction in Lifting.
import Lifting.Partiality-monad
|
{
"alphanum_fraction": 0.6870190699,
"avg_line_length": 27.4220183486,
"ext": "agda",
"hexsha": "4fd78d0a3994ddeb8e2b2c79f9c9db5995fac11c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "README.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "README.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "README.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 1279,
"size": 5978
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lists
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List where
------------------------------------------------------------------------
-- Types and basic operations
open import Data.List.Base public
|
{
"alphanum_fraction": 0.3005181347,
"avg_line_length": 25.7333333333,
"ext": "agda",
"hexsha": "8ca5daee07d314f1395a0a5b005302179c150eb9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 43,
"size": 386
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Object.Product.Indexed.Properties {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Categories.Category.Discrete
open import Categories.Category.Complete
open import Categories.Category.Construction.Cones
open import Categories.Category.Lift
open import Categories.Object.Product.Indexed C
open import Categories.Diagram.Limit
open import Categories.Functor
import Relation.Binary.PropositionalEquality as ≡
private
variable
o′ ℓ′ e′ : Level
open Category C
module _ {i} (Com : Complete (i ⊔ o′) (i ⊔ ℓ′) (i ⊔ e′) C) where
module _ {I : Set i} (P : I → Obj) where
private
Z = liftC o′ ℓ′ e′ (Discrete I)
F = lift-func C P ∘F unliftF o′ ℓ′ e′ (Discrete I)
module L = Limit (Com F)
K : ∀ {Y} → (∀ i → Y ⇒ P i) → Cone F
K f = record
{ apex = record
{ ψ = λ i → f (lower i)
; commute = λ { (lift ≡.refl) → identityˡ }
}
}
Complete⇒IndexedProductOf : IndexedProductOf P
Complete⇒IndexedProductOf = record
{ X = L.apex
; π = λ i → L.proj (lift i)
; ⟨_⟩ = λ f → L.rep (K f)
; commute = λ f _ → Cone⇒.commute (L.rep-cone (K f))
; unique = λ f g eq → L.terminal.!-unique {A = K g} record
{ arr = f
; commute = eq _
}
}
|
{
"alphanum_fraction": 0.5864768683,
"avg_line_length": 27.5490196078,
"ext": "agda",
"hexsha": "96ed0ce81508722ddfc28976bc011f8f23459620",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Object/Product/Indexed/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Object/Product/Indexed/Properties.agda",
"max_line_length": 86,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Object/Product/Indexed/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 433,
"size": 1405
}
|
{-# OPTIONS --without-K #-}
module hott.truncation.equality where
open import sum
open import equality
open import function.extensionality
open import function.isomorphism
open import function.overloading
open import sets.nat
open import hott.equivalence
open import hott.level.core
open import hott.level.closure
open import hott.truncation.core
module _ {i}{X : Set i}(n-1 : ℕ) where
private
n : ℕ
n = suc n-1
Trunc-dep-iso₂ : ∀ {j} (Z : Trunc n X → Trunc n X → Set j)
→ ((c c' : Trunc n X) → h n (Z c c'))
→ ((c c' : Trunc n X) → Z c c')
≅ ((x y : X) → Z [ x ] [ y ])
Trunc-dep-iso₂ Z hZ = begin
((c c' : Trunc n X) → Z c c')
≅⟨ (Π-ap-iso refl≅ λ c → Trunc-dep-iso n (Z c) (hZ c)) ⟩
((c : Trunc n X)(y : X) → Z c [ y ])
≅⟨ Trunc-dep-iso n (λ c → (y : X) → Z c [ y ]) (λ c → Π-level λ y → hZ c [ y ]) ⟩
((x y : X) → Z [ x ] [ y ])
∎
where open ≅-Reasoning
P₀ : X → X → Type i (n-1)
P₀ x y = Trunc (n-1) (x ≡ y) , Trunc-level n-1
abstract
r₀ : (x : X) → proj₁ (P₀ x x)
r₀ x = [ refl ]
abstract
P-iso' : (Trunc n X → Trunc n X → Type i (n-1))
≅ (X → X → Type i (n-1))
P-iso' = Trunc-dep-iso₂ (λ _ _ → Type i (n-1))
(λ _ _ → type-level)
P-iso-we : weak-equiv (λ (Z : Trunc n X → Trunc n X → Type i (n-1)) x y → Z [ x ] [ y ])
P-iso-we = proj₂ (≅⇒≈ P-iso')
P-iso : (Trunc n X → Trunc n X → Type i (n-1))
≅ (X → X → Type i (n-1))
P-iso = ≈⇒≅ ((λ Z x y → Z [ x ] [ y ]) , P-iso-we)
module impl (P : Trunc n X → Trunc n X → Type i (n-1))
(P-β : (x y : X) → P [ x ] [ y ] ≡ P₀ x y) where
r' : (P : Trunc n X → Trunc n X → Type i (n-1))
→ (∀ x y → P [ x ] [ y ] ≡ P₀ x y)
→ (c : Trunc n X) → proj₁ (P c c)
r' P q = Trunc-dep-elim n (λ c → proj₁ (P c c))
(λ c → h↑ (proj₂ (P c c)))
λ x → subst proj₁ (sym (q x x)) (r₀ x)
r : (c : Trunc n X) → proj₁ (P c c)
r = r' P P-β
abstract
P-elim-iso : (Z : Trunc n X → Trunc n X → Type i (n-1))
→ ((c c' : Trunc n X) → proj₁ (P c c') → proj₁ (Z c c'))
≅ ((c : Trunc n X) → proj₁ (Z c c))
P-elim-iso Z = begin
((c c' : Trunc n X) → proj₁ (P c c') → proj₁ (Z c c'))
≅⟨ Trunc-dep-iso₂ (λ c c' → proj₁ (P c c') → proj₁ (Z c c'))
(λ c c' → Π-level λ p → h↑ (proj₂ (Z c c'))) ⟩
((x y : X) → proj₁ (P [ x ] [ y ]) → proj₁ (Z [ x ] [ y ]))
≅⟨ ( Π-ap-iso refl≅ λ x
→ Π-ap-iso refl≅ λ y
→ Π-ap-iso (≡⇒≅ (ap proj₁ (P-β x y))) λ _
→ refl≅ ) ⟩
((x y : X) → Trunc (n-1) (x ≡ y) → proj₁ (Z [ x ] [ y ]))
≅⟨ ( Π-ap-iso refl≅ λ x
→ Π-ap-iso refl≅ λ y
→ Trunc-elim-iso (n-1) (x ≡ y) _ (proj₂ (Z [ x ] [ y ])) ) ⟩
((x y : X) → x ≡ y → proj₁ (Z [ x ] [ y ]))
≅⟨ ( Π-ap-iso refl≅ λ x → sym≅ J-iso ) ⟩
((x : X) → proj₁ (Z [ x ] [ x ]))
≅⟨ sym≅ (Trunc-dep-iso n (λ c → proj₁ (Z c c)) (λ c → h↑ (proj₂ (Z c c)))) ⟩
((c : Trunc n X) → proj₁ (Z c c))
∎
where open ≅-Reasoning
Eq : Trunc n X → Trunc n X → Type i (n-1)
Eq c c' = (c ≡ c') , Trunc-level n c c'
abstract
f₀ : (c c' : Trunc n X) → proj₁ (P c c') → c ≡ c'
f₀ = _≅_.from (P-elim-iso Eq) (λ _ → refl)
abstract
f : (c c' : Trunc n X) → proj₁ (P c c') → c ≡ c'
f c c' p = f₀ c c' p · sym (f₀ c' c' (r c'))
f-β : (c : Trunc n X) → f c c (r c) ≡ refl
f-β c = left-inverse (f₀ c c (r c))
g : (c c' : Trunc n X) → c ≡ c' → proj₁ (P c c')
g c .c refl = r c
-- α : (c c' : Trunc n X)(p : proj₁ (P c c')) → g c c' (f c c' p) ≡ p
-- α = _≅_.from (P-elim-dep-iso Z) λ c → ap (g c c) (f-β c)
-- where
-- Z : (c c' : Trunc n X) → proj₁ (P c c') → Type i (n-1)
-- Z c c' p = (g c c' (f c c' p) ≡ p) , h↑ (proj₂ (P c c')) _ _
β : (c c' : Trunc n X)(q : c ≡ c') → f c c' (g c c' q) ≡ q
β c .c refl = f-β c
trunc-equality : {x y : X} → _≡_ {A = Trunc n X} [ x ] [ y ] → Trunc (n-1) (x ≡ y)
trunc-equality {x}{y} p = subst (λ Z → Z) (ap proj₁ (P-β x y)) (g [ x ] [ y ] p)
P : Trunc n X → Trunc n X → Type i (n-1)
P = _≅_.from P-iso P₀
P-β' : (λ x y → P [ x ] [ y ]) ≡ P₀
P-β' = _≅_.iso₂ P-iso P₀
P-β : (x y : X) → P [ x ] [ y ] ≡ P₀ x y
P-β x y = funext-inv (funext-inv P-β' x) y
open impl P P-β using (trunc-equality) public
|
{
"alphanum_fraction": 0.3949856145,
"avg_line_length": 37.4307692308,
"ext": "agda",
"hexsha": "59f5de4d3f5330b3d95e4a4f7d9ae69862da9934",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/hott/truncation/equality.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/hott/truncation/equality.agda",
"max_line_length": 96,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/hott/truncation/equality.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 1989,
"size": 4866
}
|
-- Andreas, 2014-09-07
open import Common.Equality
data ⊥ : Set where
record ⊤ : Set where
-- Agda allows us to prove that A ≠ (A → B)
test : {A B : Set} → A ≡ (A → B) → ⊥
test ()
-- Agda allows us to prove that A ≠ (B → A)
test' : {A B : Set} → A ≡ (B → A) → ⊥
test' ()
-- But ⊤ is isomorphic to ⊤ → ⊤, which under univalence
-- isomorphism-as-equality contradicts both test and test'.
test'' : (⊤ ≡ (⊤ → ⊤)) → ⊥
test'' = test'
there : ⊤ → (⊤ → ⊤)
there _ _ = _
back : (⊤ → ⊤) → ⊤
back _ = _
|
{
"alphanum_fraction": 0.536,
"avg_line_length": 19.2307692308,
"ext": "agda",
"hexsha": "3ab13d8f620378f48b031a839d719824267acfd1",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue1271b.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue1271b.agda",
"max_line_length": 59,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue1271b.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 204,
"size": 500
}
|
{- The following code gives the basic idea of division by repeated
subtraction. We have to ask Agda not to check termination of this
function, because it is not structurally terminating. The versions
in nat-division.agda and nat-division-wf.agda correct this problem,
and can be judged by Agda to be terminating. -}
module nat-division-basic where
open import bool
open import eq
open import nat
open import product
open import sum
{-# NON_TERMINATING #-}
div : (x d : ℕ) → d =ℕ 0 ≡ ff → ℕ × ℕ
div 0 _ _ = 0 , 0
div x d p with (x < d)
div x d p | tt = 0 , x
div x d p | ff with div (x ∸ d) d p
div x d p | ff | q , r = suc q , r
test-div : ℕ × ℕ
test-div = div 17 3 refl
|
{
"alphanum_fraction": 0.6743849493,
"avg_line_length": 27.64,
"ext": "agda",
"hexsha": "79c8e4a959dcde61fe31c771bb3538a92966c3d8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "nat-division-basic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "nat-division-basic.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "nat-division-basic.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 217,
"size": 691
}
|
module Miscellaneous.TFlipFlop where
open import Data.Boolean
import Data.Boolean.Operators
open Data.Boolean.Operators.Logic
open import Data.Boolean.Numeral
open import Numeral.Natural
open import Syntax.Number
tFlipFlop : Bool → (ℕ → Bool) → (ℕ → Bool)
tFlipFlop init T(𝟎) = init
tFlipFlop init T(𝐒(n)) = T(n) ⊕ tFlipFlop init T(n)
open import Data
open import Relator.Equals
module _ where
postulate Q₀ : ℕ → Bool
postulate Q₁ : ℕ → Bool
postulate f : Bool → Bool
postulate g : Bool → Bool
postulate q₀0 : Q₀(0) ≡ 1
postulate q₁0 : Q₁(0) ≡ 1
postulate q₀1 : Q₀(1) ≡ 0
postulate q₁1 : Q₁(1) ≡ 1
postulate q₀2 : Q₀(2) ≡ 1
postulate q₁2 : Q₁(2) ≡ 0
postulate q₀3 : Q₀(3) ≡ 0
postulate q₁3 : Q₁(3) ≡ 0
postulate q₀4 : Q₀(4) ≡ Q₀(0)
postulate q₁4 : Q₁(4) ≡ Q₁(0)
{-# REWRITE q₀0 q₁0 q₀1 q₁1 q₀2 q₁2 q₀3 q₁3 q₀4 q₁4 #-}
private variable n : ℕ
postulate q₀step : Q₀(𝐒 n) ≡ f(Q₁(n)) ⊕ Q₀(n)
postulate q₁step : Q₁(𝐒 n) ≡ g(Q₀(n)) ⊕ Q₁(n)
open import Numeral.Natural.Oper
open import Relator.Equals.Proofs
open import Structure.Function
open import Structure.Operator
open import Syntax.Transitivity
q₀cyclic : Q₀(n + 4) ≡ Q₀(n)
q₁cyclic : Q₁(n + 4) ≡ Q₁(n)
q₀cyclic {𝟎} = [≡]-intro
q₀cyclic {𝐒 n} =
Q₀ (𝐒 n + 4) 🝖[ _≡_ ]-[]
Q₀ (𝐒(n + 4)) 🝖[ _≡_ ]-[ q₀step{n + 4} ]
f(Q₁(n + 4)) ⊕ Q₀(n + 4) 🝖[ _≡_ ]-[ congruence₂(_⊕_) (congruence₁(f) (q₁cyclic{n})) (q₀cyclic{n}) ]
f(Q₁(n)) ⊕ Q₀(n) 🝖[ _≡_ ]-[ q₀step{n} ]-sym
Q₀ (𝐒 n) 🝖-end
q₁cyclic {𝟎} = [≡]-intro
q₁cyclic {𝐒 n} =
Q₁ (𝐒 n + 4) 🝖[ _≡_ ]-[]
Q₁ (𝐒(n + 4)) 🝖[ _≡_ ]-[ q₁step{n + 4} ]
g(Q₀(n + 4)) ⊕ Q₁(n + 4) 🝖[ _≡_ ]-[ congruence₂(_⊕_) (congruence₁(g) (q₀cyclic{n})) (q₁cyclic{n}) ]
g(Q₀(n)) ⊕ Q₁(n) 🝖[ _≡_ ]-[ q₁step{n} ]-sym
Q₁ (𝐒 n) 🝖-end
f0 : f(0) ≡ 1
f0 with f(0) | q₀step{2}
... | 𝑇 | q = [≡]-intro
f1 : f(1) ≡ 1
f1 with f(1) | q₀step{0}
... | 𝑇 | q = [≡]-intro
f1' : f(1) ≡ 1
f1' with f(1) | q₀step{1}
... | 𝑇 | q = [≡]-intro
f1'' : f(1) ≡ 1
f1'' with f(1) | q₀step{0}
... | 𝑇 | q = [≡]-intro
g1 : g(1) ≡ 0
g1 with g(1) | q₁step{0}
... | 𝐹 | q = [≡]-intro
g0 : g(0) ≡ 1
g0 with g(0) | q₁step{1}
... | 𝑇 | q = [≡]-intro
g1' : g(1) ≡ 0
g1' with g(1) | q₁step{2}
... | 𝐹 | q = [≡]-intro
g1'' : g(0) ≡ 1
g1'' with g(0) | q₁step{3}
... | 𝑇 | q = [≡]-intro
|
{
"alphanum_fraction": 0.5099443119,
"avg_line_length": 24.1730769231,
"ext": "agda",
"hexsha": "6750e3c414aad35c7127bbd6488f9b07cd9e5185",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Miscellaneous/TFlipFlop.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Miscellaneous/TFlipFlop.agda",
"max_line_length": 106,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Miscellaneous/TFlipFlop.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1249,
"size": 2514
}
|
open import Nat
open import Prelude
open import dynamics-core
open import contexts
open import progress
open import htype-decidable
open import lemmas-complete
module complete-progress where
-- as in progress, we define a datatype for the possible outcomes of
-- progress for readability.
data okc : (d : ihexp) (Δ : hctx) → Set where
V : ∀{d Δ} → d val → okc d Δ
S : ∀{d Δ} → Σ[ d' ∈ ihexp ] (d ↦ d') → okc d Δ
complete-progress : {Δ : hctx} {d : ihexp} {τ : htyp} →
Δ , ∅ ⊢ d :: τ →
d dcomplete →
okc d Δ
complete-progress wt comp with progress wt
complete-progress wt comp | I x = abort (lem-ind-comp comp x)
complete-progress wt comp | S x = S x
complete-progress wt comp | BV (BVVal x) = V x
complete-progress wt (DCCast comp x₂ ()) | BV (BVHoleCast x x₁)
complete-progress (TACast wt x) (DCCast comp x₃ x₄) | BV (BVArrCast x₁ x₂) = abort (x₁ (complete-consistency x x₃ x₄))
complete-progress (TACast wt x) (DCCast comp x₃ x₄) | BV (BVSumCast x₁ x₂) = abort (x₁ (complete-consistency x x₃ x₄))
complete-progress (TAInl wt) (DCInl x₁ comp) | BV (BVInl x)
with complete-progress wt comp
... | V v = V (VInl v)
... | S (_ , Step x₂ x₃ x₄) = S (_ , Step (FHInl x₂) x₃ (FHInl x₄))
complete-progress (TAInr wt) (DCInr x₁ comp) | BV (BVInr x)
with complete-progress wt comp
... | V v = V (VInr v)
... | S (_ , Step x₂ x₃ x₄) = S (_ , Step (FHInr x₂) x₃ (FHInr x₄))
complete-progress (TAPair wt wt₁) (DCPair comp comp₁) | BV (BVPair x x₁)
with complete-progress wt comp | complete-progress wt₁ comp₁
... | V v | V v₁ = V (VPair v v₁)
... | V v | S (_ , Step x₁ x₂ x₃) = S (_ , Step (FHPair2 x₁) x₂ (FHPair2 x₃))
... | S (_ , Step x₁ x₂ x₃) | V v = S (_ , Step (FHPair1 x₁) x₂ (FHPair1 x₃))
... | S (_ , Step x₁ x₂ x₃) | S (_ , Step x₄ x₅ x₆) = S (_ , Step (FHPair1 x₁) x₂ (FHPair1 x₃))
complete-progress (TACast wt x₁) (DCCast comp x₂ x₃) | BV (BVProdCast x x₄) = abort (x (complete-consistency x₁ x₂ x₃))
|
{
"alphanum_fraction": 0.6107579462,
"avg_line_length": 45.4444444444,
"ext": "agda",
"hexsha": "1a1dbcc4e58556300590e52c45a513493f7bb45d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "complete-progress.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "complete-progress.agda",
"max_line_length": 121,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "complete-progress.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 772,
"size": 2045
}
|
module Whitespace where
-- The following definition contains several different whitespace
-- characters, and they are all treated as whitespace.
foo : Set -> Set -> Set
foo x _ = x
-- Tab characters are not treated as white space, but are still
-- allowed in character and string literals and non-pragma comments
-- ( ).
{-# BUILTIN STRING String #-}
{-# BUILTIN CHAR Char #-}
string : String
string = " "
char : Char
char = ' '
|
{
"alphanum_fraction": 0.6853932584,
"avg_line_length": 21.1904761905,
"ext": "agda",
"hexsha": "719df7b18b9c2fd724ae588b63262bac6593d7ce",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/Whitespace.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/Whitespace.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/Whitespace.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-07T10:49:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-07T10:49:57.000Z",
"num_tokens": 127,
"size": 445
}
|
{-# OPTIONS --without-K --safe #-}
module Loop where
open import Loop.Definitions public
open import Loop.Bundles public
open import Loop.Structures public
|
{
"alphanum_fraction": 0.7721518987,
"avg_line_length": 19.75,
"ext": "agda",
"hexsha": "d4192b0e0ce79da58b794dca574351383021178d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_forks_repo_path": "src/Loop.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_issues_repo_issues_event_max_datetime": "2021-10-09T08:24:56.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-04T05:30:30.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_issues_repo_path": "src/Loop.agda",
"max_line_length": 35,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_stars_repo_path": "src/Loop.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-17T09:14:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-15T06:16:13.000Z",
"num_tokens": 34,
"size": 158
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Natural numbers, basic types and operations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.Base where
open import Level using (0ℓ)
open import Function using (_∘_; flip)
open import Relation.Binary
open import Relation.Binary.Core
open import Relation.Binary.PropositionalEquality.Core
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary using (¬_)
------------------------------------------------------------------------
-- The types
open import Agda.Builtin.Nat public
using (zero; suc) renaming (Nat to ℕ)
------------------------------------------------------------------------
-- Standard ordering relations
open import Agda.Builtin.Nat public
using () renaming (_==_ to _≡ᵇ_; _<_ to _<ᵇ_)
infix 4 _≤_ _<_ _≥_ _>_ _≰_ _≮_ _≱_ _≯_
data _≤_ : Rel ℕ 0ℓ where
z≤n : ∀ {n} → zero ≤ n
s≤s : ∀ {m n} (m≤n : m ≤ n) → suc m ≤ suc n
_<_ : Rel ℕ 0ℓ
m < n = suc m ≤ n
_≥_ : Rel ℕ 0ℓ
m ≥ n = n ≤ m
_>_ : Rel ℕ 0ℓ
m > n = n < m
_≰_ : Rel ℕ 0ℓ
a ≰ b = ¬ a ≤ b
_≮_ : Rel ℕ 0ℓ
a ≮ b = ¬ a < b
_≱_ : Rel ℕ 0ℓ
a ≱ b = ¬ a ≥ b
_≯_ : Rel ℕ 0ℓ
a ≯ b = ¬ a > b
------------------------------------------------------------------------
-- Arithmetic
open import Agda.Builtin.Nat public
using (_+_; _*_) renaming (_-_ to _∸_)
pred : ℕ → ℕ
pred zero = zero
pred (suc n) = n
infixl 7 _⊓_
infixl 6 _+⋎_ _⊔_
-- Argument-swapping addition. Used by Data.Vec._⋎_.
_+⋎_ : ℕ → ℕ → ℕ
zero +⋎ n = n
suc m +⋎ n = suc (n +⋎ m)
-- Max.
_⊔_ : ℕ → ℕ → ℕ
zero ⊔ n = n
suc m ⊔ zero = suc m
suc m ⊔ suc n = suc (m ⊔ n)
-- Min.
_⊓_ : ℕ → ℕ → ℕ
zero ⊓ n = zero
suc m ⊓ zero = zero
suc m ⊓ suc n = suc (m ⊓ n)
-- Division by 2, rounded downwards.
⌊_/2⌋ : ℕ → ℕ
⌊ 0 /2⌋ = 0
⌊ 1 /2⌋ = 0
⌊ suc (suc n) /2⌋ = suc ⌊ n /2⌋
-- Division by 2, rounded upwards.
⌈_/2⌉ : ℕ → ℕ
⌈ n /2⌉ = ⌊ suc n /2⌋
-- Naïve exponentiation
_^_ : ℕ → ℕ → ℕ
x ^ zero = 1
x ^ suc n = x * x ^ n
-- Distance
∣_-_∣ : ℕ → ℕ → ℕ
∣ zero - y ∣ = y
∣ x - zero ∣ = x
∣ suc x - suc y ∣ = ∣ x - y ∣
------------------------------------------------------------------------
-- The following, alternative definition of _≤_ is more suitable for
-- well-founded induction (see Induction.Nat).
infix 4 _≤′_ _<′_ _≥′_ _>′_
data _≤′_ (m : ℕ) : ℕ → Set where
≤′-refl : m ≤′ m
≤′-step : ∀ {n} (m≤′n : m ≤′ n) → m ≤′ suc n
_<′_ : Rel ℕ 0ℓ
m <′ n = suc m ≤′ n
_≥′_ : Rel ℕ 0ℓ
m ≥′ n = n ≤′ m
_>′_ : Rel ℕ 0ℓ
m >′ n = n <′ m
------------------------------------------------------------------------
-- Another alternative definition of _≤_.
record _≤″_ (m n : ℕ) : Set where
constructor less-than-or-equal
field
{k} : ℕ
proof : m + k ≡ n
infix 4 _≤″_ _<″_ _≥″_ _>″_
_<″_ : Rel ℕ 0ℓ
m <″ n = suc m ≤″ n
_≥″_ : Rel ℕ 0ℓ
m ≥″ n = n ≤″ m
_>″_ : Rel ℕ 0ℓ
m >″ n = n <″ m
------------------------------------------------------------------------
-- Useful for induction when you have an upper bound.
data _≤‴_ : ℕ → ℕ → Set where
≤‴-refl : ∀{m} → m ≤‴ m
≤‴-step : ∀{m n} → suc m ≤‴ n → m ≤‴ n
infix 4 _≤‴_ _<‴_ _≥‴_ _>‴_
_<‴_ : Rel ℕ 0ℓ
m <‴ n = suc m ≤‴ n
_≥‴_ : Rel ℕ 0ℓ
m ≥‴ n = n ≤‴ m
_>‴_ : Rel ℕ 0ℓ
m >‴ n = n <‴ m
------------------------------------------------------------------------
-- A comparison view. Taken from "View from the left"
-- (McBride/McKinna); details may differ.
data Ordering : Rel ℕ 0ℓ where
less : ∀ m k → Ordering m (suc (m + k))
equal : ∀ m → Ordering m m
greater : ∀ m k → Ordering (suc (m + k)) m
compare : ∀ m n → Ordering m n
compare zero zero = equal zero
compare (suc m) zero = greater zero m
compare zero (suc n) = less zero n
compare (suc m) (suc n) with compare m n
... | less m k = less (suc m) k
... | equal m = equal (suc m)
... | greater n k = greater (suc n) k
|
{
"alphanum_fraction": 0.4501863354,
"avg_line_length": 21.1842105263,
"ext": "agda",
"hexsha": "c67805fab300dda04bd92a104ebf20e1216db834",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/Base.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1539,
"size": 4025
}
|
-- MIT License
-- Copyright (c) 2021 Luca Ciccone and Luca Padovani
-- Permission is hereby granted, free of charge, to any person
-- obtaining a copy of this software and associated documentation
-- files (the "Software"), to deal in the Software without
-- restriction, including without limitation the rights to use,
-- copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following
-- conditions:
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-- OTHER DEALINGS IN THE SOFTWARE.
|
{
"alphanum_fraction": 0.7637314734,
"avg_line_length": 45.88,
"ext": "agda",
"hexsha": "e2f38aae9eeb310f1039fb69fcc0f9e88a582625",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "boystrange/FairSubtypingAgda",
"max_forks_repo_path": "LICENSE.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "boystrange/FairSubtypingAgda",
"max_issues_repo_path": "LICENSE.agda",
"max_line_length": 68,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "boystrange/FairSubtypingAgda",
"max_stars_repo_path": "LICENSE.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z",
"num_tokens": 243,
"size": 1147
}
|
module Network where
open import Data.Fin hiding (lift; _<_)
open import Function
open import Data.Nat
open import Data.Nat.Show
open import Data.String hiding (show)
open import Data.Vec hiding (_++_)
open import Foreign.Haskell
open import IO
import IO.Primitive as IOPrim
import Network.Primitive as NetPrim
withSocketsDo : ∀ {a} {A : Set a} → IO A → IO A
withSocketsDo io = lift (NetPrim.withSocketsDo (run io))
byteSize : ℕ
byteSize = 256
wordSize : ℕ
wordSize = byteSize * byteSize
data IPAddress : Set where
IPv4 : Vec (Fin byteSize) 4 → IPAddress
IPv6 : Vec (Fin wordSize) 8 → IPAddress
{-
private
showIPVec : {m n : ℕ} → Vec (Fin m) n → String
showIPVec ip = foldl₁ (λ x y → x ++ "." ++ y) (map (show ∘ toℕ) ip)
-}
showIP : IPAddress → String
showIP (IPv4 ip) = foldl₁ (λ x y → x ++ "." ++ y) (map (show ∘ toℕ) ip)
showIP (IPv6 ip) = foldl₁ (λ x y → x ++ ":" ++ y) (map ((showInBase 16) ∘ toℕ) ip)
data PortNumber : Set where
portNum : Fin wordSize → PortNumber
showPort : PortNumber → String
showPort (portNum n) = show (toℕ n)
connectTo : IPAddress → PortNumber → IO IOPrim.Handle
connectTo ip (portNum n) = lift (NetPrim.connectTo (showIP ip) (toInteger (toℕ n)))
|
{
"alphanum_fraction": 0.6825795645,
"avg_line_length": 26.5333333333,
"ext": "agda",
"hexsha": "2227733294ba3389a8d0bbf41bc13f475a11f835",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "06defd709b073f951723d7e717fcf96ee30567eb",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "ilya-fiveisky/agda-network",
"max_forks_repo_path": "src/Network.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "06defd709b073f951723d7e717fcf96ee30567eb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "ilya-fiveisky/agda-network",
"max_issues_repo_path": "src/Network.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "06defd709b073f951723d7e717fcf96ee30567eb",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "ilya-fiveisky/agda-network",
"max_stars_repo_path": "src/Network.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 399,
"size": 1194
}
|
-- Andreas, 2019-11-10, issue #4185, reported and test case by nad.
--
-- Problem: no-eta-equality was ignored during Miller pattern unification
-- when turning meta-variable applied to constructed record expression
-- into meta-variable applied to record field(s).
-- {-# OPTIONS -v tc.meta.assign:30 #-}
open import Agda.Builtin.Equality
record Box (A : Set) : Set where
no-eta-equality
constructor box
field
unbox : A
open Box
postulate
A : Set
AllBox All : (P : Box A → Set) → Set
AllBox P = (x : Box A) → P x
All P = (a : A) → P (box a)
postulate
to : (P : Box A → Set) → AllBox P → All P
from : (P : Box A → Set) → All P → AllBox P
test : (P : Box A → Set)
→ (f : AllBox P) → from _ (to P f) ≡ f -- Underscore should be solved.
-- Problem WAS:
--
-- Due to invalid η-expansion, the equation
--
-- _P (box a) = P (box a)
--
-- was solved as
--
-- _P x = P (box (unbox x))
--
-- resulting in a subsequent type error as Box has no η.
|
{
"alphanum_fraction": 0.6146044625,
"avg_line_length": 21.9111111111,
"ext": "agda",
"hexsha": "db2ec03e5aff90399aaff8f175a83cdfd1e73b2b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue4185.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue4185.agda",
"max_line_length": 79,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue4185.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 320,
"size": 986
}
|
{-# OPTIONS --without-K --safe #-}
module Definition.Typed.Consequences.SucCong where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Weakening
open import Definition.Typed.Properties
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.Substitution
open import Tools.Product
-- Congurence of the type of the successor case in natrec.
sucCong : ∀ {F G Γ} → Γ ∙ ℕ ⊢ F ≡ G
→ Γ ⊢ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)
≡ Π ℕ ▹ (G ▹▹ G [ suc (var 0) ]↑)
sucCong F≡G with wfEq F≡G
sucCong F≡G | ⊢Γ ∙ ⊢ℕ =
let ⊢F , _ = syntacticEq F≡G
in Π-cong ⊢ℕ (refl ⊢ℕ)
(Π-cong ⊢F F≡G
(wkEq (step id) (⊢Γ ∙ ⊢ℕ ∙ ⊢F)
(subst↑TypeEq F≡G
(refl (sucⱼ (var (⊢Γ ∙ ⊢ℕ) here))))))
|
{
"alphanum_fraction": 0.5760743322,
"avg_line_length": 31.8888888889,
"ext": "agda",
"hexsha": "73cb4dac32d4be06d7184e3dfe31f546170b4b81",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/Typed/Consequences/SucCong.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/Typed/Consequences/SucCong.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/Typed/Consequences/SucCong.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 304,
"size": 861
}
|
module Structure.Topology.Properties where
|
{
"alphanum_fraction": 0.8837209302,
"avg_line_length": 21.5,
"ext": "agda",
"hexsha": "c6964098b1c7a9f943db93834365188690953637",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Topology/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Topology/Properties.agda",
"max_line_length": 42,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Topology/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 7,
"size": 43
}
|
{-# OPTIONS --without-K #-}
module sum-properties where
open import Type
import Level as L
open L using (Lift)
open import Data.Zero using (𝟘)
open import Data.Bool.NP
open Data.Bool.NP.Indexed
open import Data.Nat.NP
open import Data.Nat.Properties
open import Data.Product renaming (map to pmap)
open import Data.Sum
open import Relation.Binary.Product.Pointwise
open import Data.Maybe
open import Data.One using (𝟙)
open import Function.NP
import Function.Inverse as Inv
open Inv using (_↔_)
open import Function.Related
open import Function.Related.TypeIsomorphisms.NP
open import Function.Equality using (_⟨$⟩_)
--open import sum
open import Search.Type
open import Search.Sum
open import Search.Derived using (sum-swap)
open import Search.Searchable renaming (Searchable to SumProp)
open import Search.Searchable.Fin
open import Search.Searchable.Product
open import Search.Searchable.Sum
open import Relation.Binary.Sum
import Relation.Binary.PropositionalEquality.NP as ≡
open ≡ using (_≡_ ; _≗_ ; _≗₂_)
module _M2 {A : ★} (μA : SumProp A) (f g : A → Bool) where
sum-ext₂ : ∀ {A B}{f g : A → B → ℕ}(μA : SumProp A)(μB : SumProp B) → f ≗₂ g → sum μA (sum μB ∘ f) ≡ sum μA (sum μB ∘ g)
sum-ext₂ μA μB f≗g = sum-ext μA (sum-ext μB ∘ f≗g)
CountStableUnderInjection : ∀ {A} → SumProp A → Set
CountStableUnderInjection μ = ∀ p → Injective p → CountStableUnder (count μ) p
#-StableUnderInjection : ∀ {A}{μ : SumProp A} → SumStableUnderInjection (sum μ) → CountStableUnderInjection μ
#-StableUnderInjection sui p p-inj f = sui p p-inj (toℕ ∘ f)
𝟙SUI : SumStableUnderInjection (sum μ𝟙)
𝟙SUI f p x = ≡.refl
{-
stableMaybe : ∀ {A} (μA : SumProp A) → StableUnderInjection μA
→ StableUnderInjection (μMaybe μA)
stableMaybe {A} μA suiA f p p-inj with p nothing | ≡.inspect p nothing
... | nothing | ≡.[ eq ] = {!!}
where h : ∀ x → p (just x) ≡ just {!!}
h = {!!}
p' : A → A
p' x = {!p (just x)!}
p'-inj : Injective p'
p'-inj = {!!}
... | just pn | ≡.[ eq ] = ≡.trans (≡.cong (λ x → f nothing + x) (suiA (f ∘ just) p' p'-inj)) {!!}
where p' : A → A
p' x = maybe id pn (p (just x))
p'-inj : Injective p'
p'-inj = {!!}
SumsOk : ∀ {A B} → SumProp A → SumProp B → A ↔ B → ★
SumsOk μA μB iso = ∀ f → sum μA f ≡ sum μB (f ∘ from)
where from = _⟨$⟩_ (Inv.Inverse.from iso)
module StableIso {A B}(μA : SumProp A)(μB : SumProp B)(iso : A ↔ B)
(sums-ok : SumsOk μA μB iso)
(suiB : StableUnderInjection μB) where
to : A → B
to x = Inv.Inverse.to iso ⟨$⟩ x
from : B → A
from x = Inv.Inverse.from iso ⟨$⟩ x
from-inj : Injective from
from-inj = Inv.Inverse.injective (Inv.sym iso)
to-inj : Injective to
to-inj = Inv.Inverse.injective iso
left-inv : from ∘ to ≗ id
left-inv = Inv.Inverse.left-inverse-of iso
stable : StableUnderInjection μA
stable f p p-inj
= sum μA f
≡⟨ sums-ok f ⟩
sum μB (f ∘ from)
≡⟨ suiB (f ∘ from) (to ∘ p ∘ from) (from-inj ∘ p-inj ∘ to-inj) ⟩
sum μB (f ∘ from ∘ to ∘ p ∘ from)
≡⟨ sum-ext μB (λ x → ≡.cong f (left-inv (p (from x)))) ⟩
sum μB (f ∘ p ∘ from)
≡⟨ ≡.sym (sums-ok (f ∘ p)) ⟩
sum μA (f ∘ p)
∎
where open ≡.≡-Reasoning
record Iso1+ {A : Set}(μA : SumProp A) : ★₁ where
constructor mk
field
B : ★
μB : SumProp B
iso : A ↔ Maybe B
toMaybe : A → Maybe B
toMaybe x = Inv.Inverse.to iso ⟨$⟩ x
fromMaybe : Maybe B → A
fromMaybe x = Inv.Inverse.from iso ⟨$⟩ x
field
sums-ok : ∀ f → sum μA f ≡ sum (μMaybe μB) (f ∘ fromMaybe)
from-inj : Injective fromMaybe
from-inj = Inv.Inverse.injective (Inv.sym iso)
to-inj : Injective toMaybe
to-inj = Inv.Inverse.injective iso
left-inv : fromMaybe ∘ toMaybe ≗ id
left-inv = Inv.Inverse.left-inverse-of iso
stable : StableUnderInjection (μMaybe μB) → StableUnderInjection μA
stable suiMB = StableIso.stable μA (μMaybe μB) iso sums-ok suiMB
-- iso1+𝟙 : Iso1+ μ𝟙
-- iso1+𝟙 = {!mk !}
iso1+Maybe : ∀ {A} (μA : SumProp A) → Iso1+ μA → Iso1+ (μMaybe μA)
iso1+Maybe {A} μA A≅1+ = mk A μA Inv.id (λ f → ≡.refl)
iso1+FinSuc : ∀ n → Iso1+ (μFinSuc (suc n))
iso1+FinSuc n = mk (Fin (suc n)) (μFinSuc n) Fin∘suc↔Maybe∘Fin (λ f → ≡.refl)
-}
infix 4 _≈_
record _≈_ {A B} (μA : SumProp A)(μB : SumProp B) : Set where
constructor mk
field
iso : A ↔ B
from : B → A
from x = Inv.Inverse.from iso ⟨$⟩ x
to : A → B
to x = Inv.Inverse.to iso ⟨$⟩ x
from-inj : Injective from
from-inj = Inv.Inverse.injective (Inv.sym iso)
to-inj : Injective to
to-inj = Inv.Inverse.injective iso
field
sums-ok : ∀ f → sum μA f ≡ sum μB (f ∘ from)
sums-ok' : ∀ f → sum μB f ≡ sum μA (f ∘ to)
sums-ok' f = sum μB f
≡⟨ sum-ext μB (≡.cong f ∘ ≡.sym ∘ Inv.Inverse.right-inverse-of iso) ⟩
sum μB (f ∘ to ∘ from)
≡⟨ ≡.sym (sums-ok (f ∘ to)) ⟩
sum μA (f ∘ to)
∎
where open ≡.≡-Reasoning
StableUnder≈ : SumStableUnderInjection (sum μA) → SumStableUnderInjection (sum μB)
StableUnder≈ μA-SUI p p-inj f
= sum μB f
≡⟨ sums-ok' f ⟩
sum μA (f ∘ to)
≡⟨ μA-SUI (from ∘ p ∘ to) (to-inj ∘ p-inj ∘ from-inj) (f ∘ to) ⟩
sum μA (f ∘ to ∘ from ∘ p ∘ to)
≡⟨ ≡.sym (sums-ok' (f ∘ to ∘ from ∘ p)) ⟩
sum μB (f ∘ to ∘ from ∘ p)
≡⟨ sum-ext μB (≡.cong f ∘ Inv.Inverse.right-inverse-of iso ∘ p) ⟩
sum μB (f ∘ p)
∎
where open ≡.≡-Reasoning
≈-refl : ∀ {A} (μA : SumProp A) → μA ≈ μA
≈-refl μA = mk Inv.id (λ f → ≡.refl)
≈-id : ∀ {A} {μA : SumProp A} → μA ≈ μA
≈-id = ≈-refl _
≈-sym : ∀ {A B}{μA : SumProp A}{μB : SumProp B} → μA ≈ μB → μB ≈ μA
≈-sym A≈B = mk (Inv.sym iso) sums-ok'
where open _≈_ A≈B
≈-trans : ∀ {A B C}{μA : SumProp A}{μB : SumProp B}{μC : SumProp C} → μA ≈ μB → μB ≈ μC → μA ≈ μC
≈-trans A≈B B≈C = mk (iso B≈C Inv.∘ iso A≈B) (λ f → ≡.trans (sums-ok A≈B f) (sums-ok B≈C (f ∘ from A≈B)))
where open _≈_
infix 2 _≈∎
infixr 2 _≈⟨_⟩_
_≈∎ : ∀ {A} (μA : SumProp A) → μA ≈ μA
_≈∎ = ≈-refl
_≈⟨_⟩_ : ∀ {A B C} (μA : SumProp A){μB : SumProp B}{μC : SumProp C} → μA ≈ μB → μB ≈ μC → μA ≈ μC
_ ≈⟨ A≈B ⟩ B≈C = ≈-trans A≈B B≈C
{-
Fin1≈𝟙 : μFin 1 ≈ μ𝟙
Fin1≈𝟙 = mk iso sums-ok where
open import Relation.Binary.Sum
iso : _
iso = (A⊎𝟘↔A Inv.∘ Inv.id ⊎-cong Fin0↔𝟘) Inv.∘ Fin∘suc↔𝟙⊎Fin
sums-ok : (_ : _) → _
sums-ok f = ≡.refl
-}
𝟙+Fin : ∀ {n pf} → μ𝟙 ⊎-μ μFinSuc n ≈ μFinSuc (suc n)
𝟙+Fin {zero} {()}
𝟙+Fin {suc n} = mk iso sums-ok where
iso : _
iso = Inv.sym Fin∘suc↔𝟙⊎Fin
sums-ok : (_ : _) → _
sums-ok f = ≡.refl
𝟙×A≈A : ∀ {A}{μA : SumProp A} → μ𝟙 ×-μ μA ≈ μA
𝟙×A≈A = mk iso sums-ok where
iso : _
iso = 𝟙×A↔A
sums-ok : (_ : _) → _
sums-ok f = ≡.refl
μFinSucPres : ∀ {m n} → m ≡ n → μFinSuc m ≈ μFinSuc n
μFinSucPres eq rewrite eq = ≈-refl _
μFinPres : ∀ {m n pfm pfn} → m ≡ n → μFinSuc m {pfm} ≈ μFinSuc n {pfn}
μFinPres eq rewrite eq = ≈-refl _
{-
Maybe-Finable : ∀ {A} (μA : SumProp A) → Finable μA → Finable (μMaybe μA)
Maybe-Finable {A} μA finA = mk card iso sums-ok where
module FinA = Finable finA
card = suc FinA.FinCard
|A| : ℕ
|A| = suc (Finable.FinCard finA)
iso : _
iso = (𝟙 ⊎ A) ↔⟨ Inv.id ⊎-cong FinA.iso ⟩
(𝟙 ⊎ Fin |A|) ↔⟨ sym Fin∘suc↔𝟙⊎Fin ⟩
Fin (suc |A|) ∎
where open EquationalReasoning
sums-ok : (_ : _) → _
sums-ok f = ≡.cong (λ x → f (inj₁ _) + x) (FinA.sums-ok _)
-}
_+μ-cong_ : ∀ {A B C D}{μA : SumProp A}{μB : SumProp B}{μC : SumProp C}{μD : SumProp D}
→ μA ≈ μC → μB ≈ μD → μA ⊎-μ μB ≈ μC ⊎-μ μD
A≈C +μ-cong B≈D = mk iso sums-ok where
open import Relation.Binary.Sum
iso : _
iso = (_≈_.iso A≈C) ⊎-cong (_≈_.iso B≈D)
sums-ok : (_ : _) → _
sums-ok f = ≡.cong₂ _+_ (_≈_.sums-ok A≈C (f ∘ inj₁)) (_≈_.sums-ok B≈D (f ∘ inj₂))
+μ-assoc : ∀ {A B C}(μA : SumProp A)(μB : SumProp B)(μC : SumProp C)
→ (μA ⊎-μ μB) ⊎-μ μC ≈ μA ⊎-μ (μB ⊎-μ μC)
+μ-assoc μA μB μC = mk iso sums-ok where
iso : _
iso = ⊎-CMon.assoc _ _ _
sums-ok : (_ : _) → _
sums-ok f = ℕ°.+-assoc (sum μA (f ∘ inj₁ ∘ inj₁)) (sum μB (f ∘ inj₁ ∘ inj₂)) (sum μC (f ∘ inj₂))
+μ-comm : ∀ {A B}(μA : SumProp A)(μB : SumProp B)
→ μA ⊎-μ μB ≈ μB ⊎-μ μA
+μ-comm μA μB = mk iso sums-ok where
iso : _
iso = ⊎-CMon.comm _ _
sums-ok : (_ : _) → _
sums-ok f = ℕ°.+-comm (sum μA (f ∘ inj₁)) (sum μB (f ∘ inj₂))
_×μ-cong_ : ∀ {A B C D}{μA : SumProp A}{μB : SumProp B}{μC : SumProp C}{μD : SumProp D}
→ μA ≈ μC → μB ≈ μD → μA ×-μ μB ≈ μC ×-μ μD
_×μ-cong_ {μA = μA}{μD = μD} A≈C B≈D = mk iso sums-ok where
open import Relation.Binary.Product.Pointwise
iso : _
iso = _≈_.iso A≈C ×-cong _≈_.iso B≈D
sums-ok : (_ : _) → _
sums-ok f = ≡.trans (sum-ext μA (_≈_.sums-ok B≈D ∘ curry f))
(_≈_.sums-ok A≈C (λ a → sum μD (curry f a ∘ (_≈_.from B≈D))))
×μ-assoc : ∀ {A B C}(μA : SumProp A)(μB : SumProp B)(μC : SumProp C)
→ (μA ×-μ μB) ×-μ μC ≈ μA ×-μ (μB ×-μ μC)
×μ-assoc μA μB μC = mk iso sums-ok where
iso : _
iso = ×-CMon.assoc _ _ _
sums-ok : (_ : _) → _
sums-ok f = ≡.refl
×μ-comm : ∀ {A B}(μA : SumProp A)(μB : SumProp B)
→ μA ×-μ μB ≈ μB ×-μ μA
×μ-comm μA μB = mk iso sums-ok where
iso : _
iso = ×-CMon.comm _ _
sums-ok : (_ : _) → _
sums-ok f = sum-swap μA μB (curry f)
×+-distrib : ∀ {A B C}(μA : SumProp A)(μB : SumProp B)(μC : SumProp C)
→ (μA ⊎-μ μB) ×-μ μC ≈ (μA ×-μ μC) ⊎-μ (μB ×-μ μC)
×+-distrib μA μB μC = mk iso sums-ok where
iso : _
iso = ×⊎°.distribʳ _ _ _
sums-ok : (_ : _) → _
sums-ok f = ≡.refl
{-
_Suc-+_ : ∀ {m} → Suc m → ∀ n → Suc (m + n)
_Suc-+_ {zero} () _
_Suc-+_ {suc m} _ _ = _
+-≈ : ∀ m n {pfm pfn} → (μFin m {pfm}) +μ (μFin n {pfn}) ≈ μFin (m + n) {pfm Suc-+ n}
+-≈ zero _ {()}
+-≈ _ zero {_} {()}
+-≈ (suc m) (suc n) = μFin (suc m) +μ μFin (suc n)
≈⟨ {!!} ⟩
μFin (suc m + suc n)
≈∎
-}
{-
+-≈ (suc zero) (suc n) = μFin 1 +μ μFin (suc n)
≈⟨ Fin1≈𝟙 +μ-cong ≈-refl (μFin (suc n)) ⟩
μ𝟙 +μ μFinSuc n
≈⟨ 𝟙+Fin ⟩
μFinSuc (suc n)
≈∎
+-≈ (suc (suc m)) (suc n) = μFinSuc (suc m) +μ μFinSuc n
≈⟨ ≈-sym 𝟙+Fin +μ-cong ≈-refl (μFinSuc n) ⟩
(μ𝟙 +μ μFinSuc m) +μ μFinSuc n
≈⟨ +μ-assoc μ𝟙 (μFinSuc m) (μFinSuc n) ⟩
μ𝟙 +μ (μFinSuc m +μ μFinSuc n)
≈⟨ ≈-refl μ𝟙 +μ-cong +-≈ (suc m) (suc n) ⟩
μ𝟙 +μ μFinSuc (m + suc n)
≈⟨ 𝟙+Fin ⟩
μFinSuc (suc m + suc n)
≈∎
-}
{-
+-≈ : ∀ m n → (μFinSuc m) +μ (μFinSuc n) ≈ μFinSuc (m + suc n)
+-≈ zero n = μFinSuc zero +μ μFinSuc n
≈⟨ Fin1≈𝟙 +μ-cong ≈-refl (μFinSuc n) ⟩
μ𝟙 +μ μFinSuc n
≈⟨ 𝟙+Fin ⟩
μFinSuc (suc n)
≈∎
+-≈ (suc m) n = μFinSuc (suc m) +μ μFinSuc n
≈⟨ ≈-sym 𝟙+Fin +μ-cong ≈-refl (μFinSuc n) ⟩
(μ𝟙 +μ μFinSuc m) +μ μFinSuc n
≈⟨ +μ-assoc μ𝟙 (μFinSuc m) (μFinSuc n) ⟩
μ𝟙 +μ (μFinSuc m +μ μFinSuc n)
≈⟨ ≈-refl μ𝟙 +μ-cong +-≈ m n ⟩
μ𝟙 +μ μFinSuc (m + suc n)
≈⟨ 𝟙+Fin ⟩
μFinSuc (suc m + suc n)
≈∎
×-≈ : ∀ m n → μFinSuc m ×μ μFinSuc n ≈ μFinSuc (n + m * suc n)
×-≈ zero n = μFinSuc 0 ×μ μFinSuc n
≈⟨ Fin1≈𝟙 ×μ-cong (≈-refl (μFinSuc n)) ⟩
μ𝟙 ×μ μFinSuc n
≈⟨ 𝟙×A≈A ⟩
μFinSuc n
≈⟨ μFinSucPres (ℕ°.+-comm 0 n) ⟩
μFinSuc (n + 0)
≈∎
×-≈ (suc m) n = μFinSuc (suc m) ×μ μFinSuc n
≈⟨ ≈-sym 𝟙+Fin ×μ-cong ≈-refl (μFinSuc n) ⟩
(μ𝟙 +μ μFinSuc m) ×μ μFinSuc n
≈⟨ ×+-distrib μ𝟙 (μFinSuc m) (μFinSuc n) ⟩
(μ𝟙 ×μ μFinSuc n) +μ (μFinSuc m ×μ μFinSuc n)
≈⟨ 𝟙×A≈A {μA = μFinSuc n} +μ-cong ×-≈ m n ⟩
μFinSuc n +μ μFinSuc (n + m * suc n)
≈⟨ +-≈ n (n + m * suc n) ⟩
μFinSuc (n + suc m * suc n)
≈∎
-- μA→B ≈ μFinSuc (m ^ n)
-- μB ≈ μFinSuc m
-- μMaybe→ μA→B μB ≈ μFinSuc (m * m ^ n)
open import Data.Fin using (Fin ; zero ; suc)
Finable : ∀ {A} → SumProp A → Set
Finable μA = Σ ℕ λ FinCard → μA ≈ μFinSuc FinCard
𝟙-Finable : Finable μ𝟙
𝟙-Finable = 0 , ≈-sym Fin1≈𝟙
Fin-Finable : ∀ {n} → Finable (μFinSuc n)
Fin-Finable {n} = n , ≈-refl (μFinSuc n)
+-Finable : ∀ {A B}(μA : SumProp A)(μB : SumProp B) → Finable μA → Finable μB → Finable (μA +μ μB)
+-Finable μA μB (|A| , A≈) (|B| , B≈) = (|A| + suc |B|) ,
( μA +μ μB
≈⟨ A≈ +μ-cong B≈ ⟩
μFinSuc |A| +μ μFinSuc |B|
≈⟨ +-≈ |A| |B| ⟩
μFinSuc (|A| + suc |B|) ≈∎)
×-Finable : ∀ {A B}(μA : SumProp A)(μB : SumProp B) → Finable μA → Finable μB → Finable (μA ×μ μB)
×-Finable μA μB (|A| , A≈) (|B| , B≈) = (|B| + |A| * suc |B|) ,
( μA ×μ μB
≈⟨ A≈ ×μ-cong B≈ ⟩
μFinSuc |A| ×μ μFinSuc |B|
≈⟨ ×-≈ |A| |B| ⟩
μFinSuc (|B| + |A| * suc |B|)
≈∎)
module _M3 where
open import bijection-fin
open import Data.Fin using (Fin; zero; suc)
open import Data.Vec.NP renaming (sum to vsum)
sumFin : ∀ n → Sum (Fin n)
sumFin n f = vsum (tabulate f)
sumFin-spec : ∀ n → sumFin (suc n) ≗ sum (μFinSuc n)
sumFin-spec zero f = ℕ°.+-comm (f zero) 0
sumFin-spec (suc n) f = ≡.cong (_+_ (f zero)) (sumFin-spec n (f ∘ suc))
sumFinSUI : ∀ n f p → Injective p → sumFin n f ≡ sumFin n (f ∘ p)
sumFinSUI n f p p-inj = count-perm f p (λ _ _ → p-inj)
μFinSUI : ∀ {n} → StableUnderInjection (μFinSuc n)
μFinSUI {n} p p-inj f rewrite ≡.sym (sumFin-spec n f)
| ≡.sym (sumFin-spec n (f ∘ p))
= sumFinSUI (suc n) f p p-inj
open _M3 public
StableIfFinable : ∀ {A} (μA : SumProp A) → Finable μA → StableUnderInjection μA
StableIfFinable μA (_ , A≈Fin)
= _≈_.StableUnder≈ (≈-sym A≈Fin) μFinSUI
Decomposable : ★ → ★₁
Decomposable A = (A ↔ 𝟙) ⊎ (∃ λ (B : ★) → A ↔ Maybe B)
open EquationalReasoning
dec-iso : ∀ {A B} → (A ↔ B) → Decomposable A → Decomposable B
dec-iso A↔B (inj₁ A↔𝟙) = inj₁ (A↔𝟙 Inv.∘ sym A↔B)
dec-iso A↔B (inj₂ (C , A↔MaybeC)) = inj₂ (C , A↔MaybeC Inv.∘ sym A↔B)
Maybe×⊎ : ∀ {A B : ★} → (Maybe A × B) ↔ (B ⊎ (A × B))
Maybe×⊎ {A} {B} = (Maybe A × B) ↔⟨ Maybe↔𝟙⊎ ×-cong Inv.id ⟩
((𝟙 ⊎ A) × B) ↔⟨ ×⊎°.distribʳ B 𝟙 A ⟩
(𝟙 × B ⊎ A × B) ↔⟨ 𝟙×A↔A ⊎-cong Inv.id ⟩
(B ⊎ (A × B)) ∎
dec× : ∀ {A B} → Decomposable A → Decomposable B → Decomposable (A × B)
dec× {A} {B} (inj₁ A↔𝟙) dB = dec-iso (B ↔⟨ sym 𝟙×A↔A ⟩
(𝟙 × B) ↔⟨ sym A↔𝟙 ×-cong Inv.id ⟩
(A × B) ∎) dB
dec× {A} {B} dA (inj₁ B↔𝟙) = dec-iso (A ↔⟨ sym A×𝟙↔A ⟩
(A × 𝟙) ↔⟨ Inv.id ×-cong sym B↔𝟙 ⟩
(A × B) ∎) dA
dec× {A} {B} (inj₂ (C , A↔1+C)) (inj₂ (D , B↔1+D))
= inj₂ (_ , Maybe-⊎ Inv.∘ Maybe×⊎ Inv.∘ A↔1+C ×-cong B↔1+D)
dec+ : ∀ {A B} → Decomposable A → Decomposable B → Decomposable (A ⊎ B)
dec+ {A} {B} (inj₁ A↔𝟙) dB = inj₂ (B , sym Maybe↔𝟙⊎ Inv.∘ A↔𝟙 ⊎-cong Inv.id)
dec+ {A} {B} (inj₂ (C , A↔1+C)) dB = inj₂ ((C ⊎ B) , sym Maybe↔𝟙⊎
Inv.∘ ⊎-CMon.assoc 𝟙 C B
Inv.∘ (Maybe↔𝟙⊎ Inv.∘ A↔1+C) ⊎-cong Inv.id)
{-
dB = dec-iso {!!} dB
where dec : Decomposable (A × B)
{-
-- B + C×B
-- 1×B + C×B
-- (1+C) × B
-- A × B
-}
Stable× : ∀ {A} (μA : SumProp A) {B} (μB : SumProp B)
(suiA : StableUnderInjection μA)
(suiB : StableUnderInjection μB)
→ StableUnderInjection (μA ×μ μB)
Stable× μA μB suiA suiB = {!!}
-- -}
-- -}
-- -}
-- -}
|
{
"alphanum_fraction": 0.5092009075,
"avg_line_length": 31.2978303748,
"ext": "agda",
"hexsha": "1063e053cfb047cd0ccb797d94ec6486b4afeb4f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/Old/Sum/sum-properties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/Old/Sum/sum-properties.agda",
"max_line_length": 120,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/Old/Sum/sum-properties.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 7132,
"size": 15868
}
|
module Numeral.Finite.Proofs where
import Lvl
open import Data
open import Data.Boolean.Stmt
open import Functional
open import Logic.Classical
open import Logic.Propositional
open import Logic.Propositional.Theorems
open import Logic.Predicate
open import Numeral.Finite
import Numeral.Finite.Oper.Comparisons as 𝕟
open import Numeral.Natural hiding (𝐏)
open import Numeral.Natural.Function
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Relation.Order
open import Numeral.Natural.Relation.Order.Decidable
open import Numeral.Natural.Relation.Order.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Function.Domain
open import Syntax.Number
open import Type.Properties.Decidable
open import Type.Properties.Decidable.Proofs
private variable N : ℕ
bounded : ∀{N : ℕ}{n : 𝕟(𝐒(N))} → (𝕟-to-ℕ(n) < 𝐒(N))
bounded{_} {𝟎} = [≤]-with-[𝐒] ⦃ [≤]-minimum ⦄
bounded{𝐒(N)}{𝐒(n)} = [≤]-with-[𝐒] ⦃ bounded{N}{n} ⦄
ℕ-to-𝕟-eq : ∀{M N n} ⦃ nM : IsTrue(n <? M) ⦄ ⦃ nN : IsTrue(n <? N) ⦄ → IsTrue(ℕ-to-𝕟 n {n = M} ⦃ nM ⦄ 𝕟.≡? ℕ-to-𝕟 n {n = N} ⦃ nN ⦄)
ℕ-to-𝕟-eq {𝐒 M} {𝐒 N} {𝟎} = [⊤]-intro
ℕ-to-𝕟-eq {𝐒 M} {𝐒 N} {𝐒 n} = ℕ-to-𝕟-eq {M} {N} {n}
𝕟-to-ℕ-preserve-eq : ∀{M N}{m : 𝕟(M)}{n : 𝕟(N)} → IsTrue(m 𝕟.≡? n) → (𝕟-to-ℕ m ≡ 𝕟-to-ℕ n)
𝕟-to-ℕ-preserve-eq {𝐒 M} {𝐒 N} {𝟎} {𝟎} [⊤]-intro = [≡]-intro
𝕟-to-ℕ-preserve-eq {𝐒 M} {𝐒 N} {𝐒 m} {𝐒 n} = [≡]-with(𝐒) ∘ 𝕟-to-ℕ-preserve-eq {M} {N} {m} {n}
𝕟-to-ℕ-preserve-gt : ∀{M N}{m : 𝕟(M)}{n : 𝕟(N)} → IsTrue(m 𝕟.>? n) → (𝕟-to-ℕ m > 𝕟-to-ℕ n)
𝕟-to-ℕ-preserve-gt {𝐒 M} {𝐒 N} {𝐒 m} {𝟎} [⊤]-intro = [≤]-with-[𝐒] ⦃ [≤]-minimum ⦄
𝕟-to-ℕ-preserve-gt {𝐒 M} {𝐒 N} {𝐒 m} {𝐒 n} x = [≤]-with-[𝐒] ⦃ 𝕟-to-ℕ-preserve-gt {M} {N} {m} {n} x ⦄
𝕟-to-ℕ-preserve-lt : ∀{M N}{m : 𝕟(M)}{n : 𝕟(N)} → IsTrue(m 𝕟.<? n) → (𝕟-to-ℕ m < 𝕟-to-ℕ n)
𝕟-to-ℕ-preserve-lt {𝐒 M} {𝐒 N} {𝟎} {𝐒 n} [⊤]-intro = [≤]-with-[𝐒] ⦃ [≤]-minimum ⦄
𝕟-to-ℕ-preserve-lt {𝐒 M} {𝐒 N} {𝐒 m} {𝐒 n} x = [≤]-with-[𝐒] ⦃ 𝕟-to-ℕ-preserve-lt {M} {N} {m} {n} x ⦄
𝕟-to-ℕ-preserve-ge : ∀{M N}{m : 𝕟(M)}{n : 𝕟(N)} → IsTrue(m 𝕟.≥? n) → (𝕟-to-ℕ m ≥ 𝕟-to-ℕ n)
𝕟-to-ℕ-preserve-ge {𝐒 M} {𝐒 N} {𝟎} {𝟎} [⊤]-intro = [≤]-minimum
𝕟-to-ℕ-preserve-ge {𝐒 M} {𝐒 N} {𝐒 n} {𝟎} [⊤]-intro = [≤]-minimum
𝕟-to-ℕ-preserve-ge {𝐒 M} {𝐒 N} {𝐒 m} {𝐒 n} x = [≤]-with-[𝐒] ⦃ 𝕟-to-ℕ-preserve-ge {M} {N} {m} {n} x ⦄
𝕟-to-ℕ-preserve-le : ∀{M N}{m : 𝕟(M)}{n : 𝕟(N)} → IsTrue(m 𝕟.≤? n) → (𝕟-to-ℕ m ≤ 𝕟-to-ℕ n)
𝕟-to-ℕ-preserve-le {𝐒 M} {𝐒 N} {𝟎} {𝟎} [⊤]-intro = [≤]-minimum
𝕟-to-ℕ-preserve-le {𝐒 M} {𝐒 N} {𝟎} {𝐒 n} [⊤]-intro = [≤]-minimum
𝕟-to-ℕ-preserve-le {𝐒 M} {𝐒 N} {𝐒 m} {𝐒 n} x = [≤]-with-[𝐒] ⦃ 𝕟-to-ℕ-preserve-le {M} {N} {m} {n} x ⦄
𝕟-to-ℕ-preserve-ne : ∀{M N}{m : 𝕟(M)}{n : 𝕟(N)} → IsTrue(m 𝕟.≢? n) → (𝕟-to-ℕ m ≢ 𝕟-to-ℕ n)
𝕟-to-ℕ-preserve-ne {𝐒 M} {𝐒 N} {𝟎} {𝐒 n} _ ()
𝕟-to-ℕ-preserve-ne {𝐒 M} {𝐒 N} {𝐒 m} {𝟎} _ ()
𝕟-to-ℕ-preserve-ne {𝐒 M} {𝐒 N} {𝐒 m} {𝐒 n} x p = 𝕟-to-ℕ-preserve-ne {M} {N} {m} {n} x (injective(𝐒) p)
congruence-ℕ-to-𝕟 : ∀ ⦃ pos : IsTrue(positive? N) ⦄ {x} ⦃ px : IsTrue(x <? N) ⦄ {y} ⦃ py : IsTrue(y <? N) ⦄ → (x ≡ y) → (ℕ-to-𝕟 x {N} ⦃ px ⦄ ≡ ℕ-to-𝕟 y ⦃ py ⦄)
congruence-ℕ-to-𝕟 [≡]-intro = [≡]-intro
𝕟-ℕ-inverse : ∀{N n} ⦃ nN : IsTrue(n <? N) ⦄ → (𝕟-to-ℕ {n = N}(ℕ-to-𝕟 n) ≡ n)
𝕟-ℕ-inverse {𝐒 N}{𝟎} = [≡]-intro
𝕟-ℕ-inverse {𝐒 N}{𝐒 n} = [≡]-with(𝐒) (𝕟-ℕ-inverse {N}{n})
ℕ-𝕟-inverse : ∀{N}{n : 𝕟(𝐒(N))} → (ℕ-to-𝕟(𝕟-to-ℕ n) ⦃ [↔]-to-[→] decider-true (bounded{n = n}) ⦄ ≡ n)
ℕ-𝕟-inverse {𝟎} {𝟎} = [≡]-intro
ℕ-𝕟-inverse {𝐒 N} {𝟎} = [≡]-intro
ℕ-𝕟-inverse {𝐒 N} {𝐒 n} = [≡]-with(𝐒) (ℕ-𝕟-inverse{N}{n})
instance
[<]-of-𝕟-to-ℕ : ∀{N : ℕ}{n : 𝕟(N)} → (𝕟-to-ℕ (n) < N)
[<]-of-𝕟-to-ℕ {𝟎} {()}
[<]-of-𝕟-to-ℕ {𝐒 N} {𝟎} = [≤]-with-[𝐒]
[<]-of-𝕟-to-ℕ {𝐒 N} {𝐒 n} = [≤]-with-[𝐒] ⦃ [<]-of-𝕟-to-ℕ {N} {n} ⦄
instance
[𝐒]-injective : ∀{N : ℕ} → Injective(𝕟.𝐒{N})
Injective.proof [𝐒]-injective [≡]-intro = [≡]-intro
[≡][≡?]-equivalence : ∀{n}{i j : 𝕟(n)} → (i ≡ j) ↔ IsTrue(i 𝕟.≡? j)
[≡][≡?]-equivalence {𝐒 n} {𝟎} {𝟎} = [↔]-intro (const [≡]-intro) (const [⊤]-intro)
[≡][≡?]-equivalence {𝐒 n} {𝟎} {𝐒 j} = [↔]-intro (\()) (\())
[≡][≡?]-equivalence {𝐒 n} {𝐒 i} {𝟎} = [↔]-intro (\()) (\())
[≡][≡?]-equivalence {𝐒 n} {𝐒 i} {𝐒 j} = [∧]-map ([≡]-with(𝐒) ∘_) (_∘ injective(𝐒)) ([≡][≡?]-equivalence {n} {i} {j})
instance
[≡][𝕟]-decider : ∀{n} → Decider(2)(_≡_ {T = 𝕟(n)})(𝕟._≡?_)
[≡][𝕟]-decider {𝐒 n} {𝟎} {𝟎} = true [≡]-intro
[≡][𝕟]-decider {𝐒 n} {𝟎} {𝐒 y} = false \()
[≡][𝕟]-decider {𝐒 n} {𝐒 x} {𝟎} = false \()
[≡][𝕟]-decider {𝐒 n} {𝐒 x} {𝐒 y} = step{f = id} (true ∘ [≡]-with(𝐒)) (false ∘ contrapositiveᵣ(injective(𝐒))) ([≡][𝕟]-decider {n} {x} {y})
maximum-0 : (maximum{N} ≡ 𝟎) → (N ≡ 𝟎)
maximum-0 {𝟎} _ = [≡]-intro
|
{
"alphanum_fraction": 0.5193347193,
"avg_line_length": 47.1568627451,
"ext": "agda",
"hexsha": "23f5c4bf83c3b43e462cb2ad794135f9d28c0a87",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Finite/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Finite/Proofs.agda",
"max_line_length": 159,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Finite/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 2929,
"size": 4810
}
|
open import Prelude
open import core
module grounding where
grounding : ∀{ τ1 τ2} →
τ1 ▸gnd τ2 →
((τ2 ground) × (τ1 ~ τ2) × (τ1 ≠ τ2))
grounding (MGArr x) = GHole , TCArr TCHole1 TCHole1 , x
|
{
"alphanum_fraction": 0.5,
"avg_line_length": 28.2222222222,
"ext": "agda",
"hexsha": "67b06979db80cc8a144c6616a6e7d1451284ec5e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_forks_repo_path": "grounding.agda",
"max_issues_count": 54,
"max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_issues_repo_path": "grounding.agda",
"max_line_length": 66,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_stars_repo_path": "grounding.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z",
"num_tokens": 82,
"size": 254
}
|
{-
Module in which the Grothendieck Group ("Groupification") of a commutative monoid is defined.
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommMonoid.GrothendieckGroup where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Structure
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.CommMonoid
open import Cubical.Algebra.CommMonoid.CommMonoidProd
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.AbGroup
open import Cubical.HITs.SetQuotients.Base
open import Cubical.HITs.SetQuotients.Properties
open import Cubical.Relation.Binary.Base
private
variable
ℓ ℓ' : Level
module _ (M : CommMonoid ℓ) where
open BinaryRelation
M² : CommMonoid _
M² = CommMonoidProd M M
open CommMonoidStr ⦃...⦄
private
instance
_ = snd M
_ = snd M²
R : ⟨ M² ⟩ → ⟨ M² ⟩ → Type _
R (a₁ , b₁) (a₂ , b₂) = Σ[ k ∈ ⟨ M ⟩ ] k · (a₁ · b₂) ≡ k · (b₁ · a₂)
M²/R : Type _
M²/R = ⟨ M² ⟩ / R
0/R : M²/R
0/R = [ ε , ε ]
private
_+/_ : M²/R → M²/R → M²/R
x +/ y = setQuotBinOp isReflR isReflR _·_ isCongR x y
where
isReflR : isRefl R
isReflR (a , b) = ε , cong (ε ·_) (·Comm a b)
isCongR : ∀ u u' v v' → R u u' → R v v' → R (u · v) (u' · v')
isCongR (a₁ , b₁) (a₂ , b₂) (a₃ , b₃) (a₄ , b₄) (k , p) (s , q) = k · s , proof
where
proof =
(k · s) · ((a₁ · a₃) · (b₂ · b₄)) ≡⟨ lemma ⟩
(k · (a₁ · b₂)) · (s · (a₃ · b₄)) ≡⟨ cong₂ _·_ p q ⟩
(k · (b₁ · a₂)) · (s · (b₃ · a₄)) ≡⟨ sym lemma ⟩
(k · s) · ((b₁ · b₃) · (a₂ · a₄)) ∎
where
rExp : ∀ {x y z} → x ≡ y → x · z ≡ y · z
rExp r = cong₂ _·_ r refl
lExp : ∀ {x y z} → x ≡ y → z · x ≡ z · y
lExp r = cong₂ _·_ refl r
-- remove proof when MonoidSolver is done
lemma : ∀ {k s a b c d} → (k · s) · ((a · b) · (c · d)) ≡ (k · (a · c)) · (s · (b · d))
lemma = sym (·Assoc _ _ _) ∙ lExp (
(·Assoc _ _ _) ∙ (·Assoc _ _ _) ∙ rExp (
·Comm _ _ ∙ (·Assoc _ _ _) ∙ (·Assoc _ _ _) ∙ rExp (
·Comm _ _ ∙ (·Assoc _ _ _)
) ∙ sym (·Assoc _ _ _)
) ∙ sym (·Assoc _ _ _) ∙ lExp (sym (·Assoc _ _ _))
) ∙ (·Assoc _ _ _)
-/_ : M²/R → M²/R
-/_ = setQuotUnaryOp swap h
where
swap : ⟨ M² ⟩ → ⟨ M² ⟩
swap = λ (a , b) → b , a
h : ∀ u v → R u v → R (swap u) (swap v)
h _ _ (k , p) = k , sym p
assoc/R : (x y z : M²/R) → x +/ ( y +/ z) ≡ (x +/ y) +/ z
assoc/R = elimProp3 (λ x y z → squash/ _ _) (λ u v w → cong [_] (·Assoc _ _ _))
rid/R : (x : M²/R) → x +/ 0/R ≡ x
rid/R = elimProp (λ x → squash/ _ _) (λ u → cong [_] (·IdR u))
rinv/R : (x : M²/R) → x +/ (-/ x) ≡ 0/R
rinv/R = elimProp (λ x → squash/ _ _)
(λ (a , b) → eq/ _ _ (ε , cong (λ x → ε · (x · ε)) (·Comm _ _)))
comm/R : (x y : M²/R) → x +/ y ≡ y +/ x
comm/R = elimProp2 (λ x y → squash/ _ _) (λ u v → cong [_] (·Comm _ _))
asAbGroup : AbGroup ℓ
asAbGroup = makeAbGroup 0/R _+/_ -/_ squash/ assoc/R rid/R rinv/R comm/R
Groupification : CommMonoid ℓ → AbGroup ℓ
Groupification M = asAbGroup M
module UniversalProperty (M : CommMonoid ℓ) where
open IsMonoidHom
open CommMonoidStr ⦃...⦄
private
instance
_ = snd M
{-
The "groupification" of a monoid comes with a universal morphism and a universal property:
M ----- ∀φ -----> A
\ Λ
\ /
universalHom ∃! inducedHom
\ /
V /
Groupification M
-}
universalHom : CommMonoidHom M (AbGroup→CommMonoid (Groupification M))
fst universalHom = λ m → [ m , ε ]
pres· (snd universalHom) =
λ _ _ → eq/ _ _ (ε , cong (ε ·_) (·Comm _ _ ∙ cong₂ _·_ (·IdR ε) refl))
presε (snd universalHom) = refl
private
i = fst universalHom
module _ {A : AbGroup ℓ} (φ : CommMonoidHom M (AbGroup→CommMonoid A)) where
open IsGroupHom
open GroupTheory (AbGroup→Group A)
open AbGroupStr ⦃...⦄ using (-_; _-_; _+_; +InvR; +InvL)
private
instance
AAsGroup = snd A
MAsGroup = snd (Groupification M)
AAsMonoid = snd (AbGroup→CommMonoid A)
private
module φ = IsMonoidHom (snd φ)
f = fst φ
inducedHom : AbGroupHom (Groupification M) A
fst inducedHom = elim (λ x → isSetAbGroup A) g proof
where
g = λ (a , b) → f a - f b
proof : (u v : ⟨ M² M ⟩) (r : R M u v) → g u ≡ g v
proof _ _ (k , p) = lemma (lemma₂ p)
where
lemma₂ : ∀ {k a b c d} → k · (a · d) ≡ k · (b · c) → f a + f d ≡ f b + f c
lemma₂ {k} {a} {b} {c} {d} p =
f a + f d ≡⟨ sym (φ.pres· _ _) ⟩
f (a · d) ≡⟨ ·CancelL _ (sym (φ.pres· _ _) ∙ (cong f p) ∙ φ.pres· _ _) ⟩
f (b · c) ≡⟨ φ.pres· _ _ ⟩
f b + f c ∎
lemma : ∀ {a b c d} → f a + f d ≡ f b + f c → f a - f b ≡ f c - f d
lemma {a} {b} {c} {d} p =
f a - f b
≡⟨ cong (λ x → x - f b) (sym (·IdR _)) ⟩
f a + ε - f b
≡⟨ cong (λ x → f a + x - f b) (sym (+InvR _)) ⟩
f a + (f d - f d) - f b
≡⟨ cong (λ x → x - f b) (·Assoc _ _ _) ⟩
f a + f d - f d - f b
≡⟨ cong (λ x → x - f d - f b) p ⟩
f b + f c - f d - f b
≡⟨ ·Comm _ _ ∙ ·Assoc _ _ _ ⟩
(- f b + (f b + f c)) - f d
≡⟨ cong (λ x → x - f d) (·Assoc _ _ _) ⟩
((- f b + f b) + f c) - f d
≡⟨ cong (λ x → (x + f c) - f d) (+InvL _) ∙ sym (·Assoc _ _ _) ∙ ·IdL _ ⟩
f c - f d
∎
pres· (snd inducedHom) = elimProp2 (λ _ _ → isSetAbGroup A _ _) proof
where
rExp : ∀ {x y z} → x ≡ y → x + z ≡ y + z
rExp r = cong₂ _+_ r refl
lExp : ∀ {x y z} → x ≡ y → z + x ≡ z + y
lExp r = cong₂ _+_ refl r
proof : ((a , b) (c , d) : ⟨ M² M ⟩) → (f (a · c)) - (f (b · d)) ≡ (f a - f b) + (f c - f d)
proof (a , b) (c , d) =
f (a · c) - f (b · d) ≡⟨ cong₂ _-_ (φ.pres· _ _) (φ.pres· _ _) ⟩
(f a + f c) - (f b + f d) ≡⟨ lExp (invDistr _ _ ∙ ·Comm _ _) ∙ ·Assoc _ _ _ ⟩
((f a + f c) - f b) - f d ≡⟨ lemma ⟩
(f a - f b) + (f c - f d) ∎
where
lemma = rExp (sym (·Assoc _ _ _) ∙ lExp (·Comm _ _) ∙ ·Assoc _ _ _) ∙ sym (·Assoc _ _ _)
pres1 (snd inducedHom) = +InvR _
presinv (snd inducedHom) = elimProp (λ _ → isSetAbGroup A _ _)
(λ _ → sym (invDistr _ _ ∙ cong₂ _-_ (invInv _) refl))
solution : (m : ⟨ M ⟩) → (fst inducedHom) (i m) ≡ f m
solution m = cong ((f m)+_) ((cong (-_) φ.presε) ∙ inv1g) ∙ ·IdR _
unique : (ψ : AbGroupHom (Groupification M) A)
→ (ψIsSolution : (m : ⟨ M ⟩) → ψ .fst (i m) ≡ f m)
→ (u : ⟨ M² M ⟩) → ψ .fst [ u ] ≡ inducedHom .fst [ u ]
unique ψ ψIsSolution (a , b) =
ψ .fst [ a , b ] ≡⟨ lemma ⟩
ψ .fst ([ a , ε ] - [ b , ε ]) ≡⟨ (snd ψ).pres· _ _ ∙ cong₂ _+_ refl ((snd ψ).presinv _) ⟩
ψ .fst [ a , ε ] - ψ .fst [ b , ε ] ≡⟨ cong₂ _-_ (ψIsSolution a) (ψIsSolution b) ⟩
f a - f b ∎
where
lemma = cong (ψ .fst) (eq/ _ _ (ε , cong (ε ·_) (·Assoc _ _ _ ∙ ·Comm _ _)))
|
{
"alphanum_fraction": 0.4447013487,
"avg_line_length": 34.7544642857,
"ext": "agda",
"hexsha": "f1addba0e2d21c2c0e16aec19e398bb020749273",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommMonoid/GrothendieckGroup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommMonoid/GrothendieckGroup.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommMonoid/GrothendieckGroup.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3003,
"size": 7785
}
|
{-# OPTIONS --with-K #-}
open import Level using (Level)
open import Axiom.UniquenessOfIdentityProofs.WithK using (uip)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Data.Nat using (ℕ)
open import Data.Vec using (Vec)
open import FLA.Axiom.Extensionality.Propositional
open import FLA.Algebra.Structures
open import FLA.Algebra.LinearAlgebra
open import FLA.Algebra.LinearAlgebra.Properties
open import FLA.Algebra.LinearMap
module FLA.Algebra.LinearMap.Properties where
private
variable
ℓ : Level
A : Set ℓ
m n p q : ℕ
⦃ F ⦄ : Field A
-------------------------------------------------------------------------------
-- LinearMap without the proofs: LinearMap↓ --
-------------------------------------------------------------------------------
private
data _⊸↓_ {A : Set ℓ} ⦃ F : Field A ⦄ (m n : ℕ) : Set ℓ where
LM↓ : (Vec A m → Vec A n) → m ⊸↓ n
_·ˡᵐ↓_ : ⦃ F : Field A ⦄ → m ⊸↓ n → Vec A m → Vec A n
_·ˡᵐ↓_ (LM↓ f) = f
-- Choose 20 since function application is assumed higher than almost anything
infixr 20 _·ˡᵐ↓_
L→L↓ : ⦃ F : Field A ⦄ → m ⊸ n → m ⊸↓ n
L→L↓ record { f = f } = LM↓ f
L↓→L : ⦃ F : Field A ⦄
→ (L↓ : m ⊸↓ n)
→ (f[u+v]≡f[u]+f[v] : (u v : Vec A m)
→ L↓ ·ˡᵐ↓ (u +ⱽ v) ≡ L↓ ·ˡᵐ↓ u +ⱽ L↓ ·ˡᵐ↓ v)
→ (f[c*v]≡c*f[v] : (c : A) → (v : Vec A m)
→ L↓ ·ˡᵐ↓ (c ∘ⱽ v) ≡ c ∘ⱽ (L↓ ·ˡᵐ↓ v))
→ m ⊸ n
L↓→L (LM↓ f) f[u+v]≡f[u]+f[v] f[c*v]≡c*f[v] =
record
{ f = f
; f[u+v]≡f[u]+f[v] = f[u+v]≡f[u]+f[v]
; f[c*v]≡c*f[v] = f[c*v]≡c*f[v]
}
f[u+v]≡f[u]+f[v]-UIP : {ℓ : Level} {A : Set ℓ} {m n : ℕ} → ⦃ F : Field A ⦄
→ (f : Vec A m → Vec A n)
→ (p q : (u v : Vec A m)
→ f (u +ⱽ v) ≡ f u +ⱽ f v)
→ p ≡ q
f[u+v]≡f[u]+f[v]-UIP f p q =
extensionality (λ u → extensionality (λ v → t f p q u v))
where
t : {ℓ : Level} {A : Set ℓ} {m n : ℕ} → ⦃ F : Field A ⦄
→ (f : Vec A m → Vec A n)
→ (p q : (u v : Vec A m)
→ f (u +ⱽ v) ≡ f u +ⱽ f v)
→ (u v : Vec A m) → p u v ≡ q u v
t f p q u v = uip (p u v) (q u v)
f[c*v]≡c*f[v]-UIP : {ℓ : Level} {A : Set ℓ} {m n : ℕ} → ⦃ F : Field A ⦄
→ (f : Vec A m → Vec A n)
→ (p q : (c : A) (v : Vec A m) → f (c ∘ⱽ v) ≡ c ∘ⱽ (f v))
→ p ≡ q
f[c*v]≡c*f[v]-UIP f p q =
extensionality (λ c → extensionality (λ v → t f p q c v))
where
t : {ℓ : Level} {A : Set ℓ} {m n : ℕ} → ⦃ F : Field A ⦄
→ (f : Vec A m → Vec A n)
→ (p q : (c : A) (v : Vec A m) → f (c ∘ⱽ v) ≡ c ∘ⱽ (f v))
→ (c : A) (v : Vec A m) → p c v ≡ q c v
t f p q c v = uip (p c v) (q c v)
L↓≡→L≡ : ⦃ F : Field A ⦄ → (C D : m ⊸ n)
→ (L→L↓ C ≡ L→L↓ D) → C ≡ D
L↓≡→L≡ record { f = f
; f[u+v]≡f[u]+f[v] = f[u+v]≡f[u]+f[v]ᶜ
; f[c*v]≡c*f[v] = f[c*v]≡c*f[v]ᶜ
}
record { f = .f
; f[u+v]≡f[u]+f[v] = f[u+v]≡f[u]+f[v]ᵈ
; f[c*v]≡c*f[v] = f[c*v]≡c*f[v]ᵈ
}
refl
rewrite
f[u+v]≡f[u]+f[v]-UIP f f[u+v]≡f[u]+f[v]ᶜ f[u+v]≡f[u]+f[v]ᵈ
| f[c*v]≡c*f[v]-UIP f f[c*v]≡c*f[v]ᶜ f[c*v]≡c*f[v]ᵈ
= refl
-------------------------------------------------------------------------------
-- LinearMap Proofs via LinearMap↓ Proofs --
-------------------------------------------------------------------------------
module _ {ℓ : Level} {A : Set ℓ} ⦃ F : Field A ⦄ where
open Field F
open _⊸_
+ˡᵐ-comm : (L R : m ⊸ n)
→ L +ˡᵐ R ≡ R +ˡᵐ L
+ˡᵐ-comm L R = L↓≡→L≡ (L +ˡᵐ R) (R +ˡᵐ L) (+ˡᵐ-comm↓ L R)
where
+ⱽ-comm-ext : (f g : Vec A m → Vec A n)
→ (λ v → f v +ⱽ g v) ≡ (λ v → g v +ⱽ f v)
+ⱽ-comm-ext f g = extensionality (λ v → +ⱽ-comm (f v) (g v))
+ˡᵐ-comm↓ : (L R : m ⊸ n)
→ L→L↓ (L +ˡᵐ R) ≡ L→L↓ (R +ˡᵐ L)
+ˡᵐ-comm↓ L R = cong LM↓ (+ⱽ-comm-ext (L ·ˡᵐ_) (R ·ˡᵐ_))
*ˡᵐ-distr-+ˡᵐₗ : (X : n ⊸ m) → (Y Z : p ⊸ n)
→ (X *ˡᵐ (Y +ˡᵐ Z)) ≡ (X *ˡᵐ Y +ˡᵐ X *ˡᵐ Z)
*ˡᵐ-distr-+ˡᵐₗ X Y Z = L↓≡→L≡ (X *ˡᵐ (Y +ˡᵐ Z)) ((X *ˡᵐ Y +ˡᵐ X *ˡᵐ Z))
(*ˡᵐ-distr-+ˡᵐₗ↓ X Y Z)
where
*-distr-+ⱽ : (X : n ⊸ m) → (Y Z : p ⊸ n)
→ (λ v → X ·ˡᵐ (Y ·ˡᵐ v +ⱽ Z ·ˡᵐ v)) ≡
(λ v → X ·ˡᵐ (Y ·ˡᵐ v) +ⱽ X ·ˡᵐ (Z ·ˡᵐ v))
*-distr-+ⱽ X Y Z = extensionality
(λ v → f[u+v]≡f[u]+f[v] X (Y ·ˡᵐ v) (Z ·ˡᵐ v))
*ˡᵐ-distr-+ˡᵐₗ↓ : (X : n ⊸ m) → (Y Z : p ⊸ n)
→ L→L↓ (X *ˡᵐ (Y +ˡᵐ Z)) ≡ L→L↓ (X *ˡᵐ Y +ˡᵐ X *ˡᵐ Z)
*ˡᵐ-distr-+ˡᵐₗ↓ X Y Z = cong LM↓ (*-distr-+ⱽ X Y Z)
*ˡᵐ-distr-+ˡᵐᵣ : (X Y : n ⊸ m) → (Z : p ⊸ n)
→ (X +ˡᵐ Y) *ˡᵐ Z ≡ X *ˡᵐ Z +ˡᵐ Y *ˡᵐ Z
*ˡᵐ-distr-+ˡᵐᵣ X Y Z = L↓≡→L≡ ((X +ˡᵐ Y) *ˡᵐ Z) (X *ˡᵐ Z +ˡᵐ Y *ˡᵐ Z)
(*ˡᵐ-distr-+ˡᵐᵣ↓ X Y Z)
where
*ˡᵐ-distr-+ˡᵐᵣ↓ : (X Y : n ⊸ m) → (Z : p ⊸ n)
→ L→L↓ ((X +ˡᵐ Y) *ˡᵐ Z) ≡ L→L↓ (X *ˡᵐ Z +ˡᵐ Y *ˡᵐ Z)
*ˡᵐ-distr-+ˡᵐᵣ↓ X Y Z = cong LM↓ refl
|
{
"alphanum_fraction": 0.3819270129,
"avg_line_length": 35.231292517,
"ext": "agda",
"hexsha": "b6471633fb72324f22df055d77b255a1ac21d827",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-09-07T19:55:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-12T20:34:17.000Z",
"max_forks_repo_head_hexsha": "375475a2daa57b5995ceb78b4bffcbfcbb5d8898",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "turion/functional-linear-algebra",
"max_forks_repo_path": "src/FLA/Algebra/LinearMap/Properties.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "375475a2daa57b5995ceb78b4bffcbfcbb5d8898",
"max_issues_repo_issues_event_max_datetime": "2022-01-07T05:27:53.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-01T01:42:12.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "turion/functional-linear-algebra",
"max_issues_repo_path": "src/FLA/Algebra/LinearMap/Properties.agda",
"max_line_length": 80,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "375475a2daa57b5995ceb78b4bffcbfcbb5d8898",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "turion/functional-linear-algebra",
"max_stars_repo_path": "src/FLA/Algebra/LinearMap/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-07T05:28:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-22T20:49:34.000Z",
"num_tokens": 2577,
"size": 5179
}
|
open import Proc
module Mission (param : Param) where
import Interp
import Hear
open import Basics
private
open module P = Process param
open module I = Interp param
open module H = Hear param
renaming ( sound to hear-sound
; uniq to hear-uniq
; complete to hear-complete
)
open Tran
data IsRefuse {a : U}{p : Proc a} : Result p -> Set where
isRefuse : {s : Silent p} -> IsRefuse (refuse s)
completeS : {a : U}{p : Proc a}(g : Guard p) ->
Silent p -> (oracle : Oracle) -> IsRefuse (step g oracle)
completeS og silent-o oracle = isRefuse
completeS (>g f) silent-> oracle = isRefuse
completeS (_ !g _) () oracle
completeS (_ ! _ +g _) () oracle
completeS (g1 ||g g2) (silent-|| s1 s2) oracle
with step g1 (nextOracle oracle)
| completeS g1 s1 (nextOracle oracle)
| step g2 (nextOracle oracle)
| completeS g2 s2 (nextOracle oracle)
| prophecy oracle
... | refuse _ | _ | refuse _ | _ | _ = isRefuse
... | speak _ | () | speak _ | _ | _
... | refuse _ | _ | speak _ | () | _
... | speak _ | () | speak _ | _ | left
... | speak _ | _ | speak _ | () | right
... | speak _ | _ | refuse _ | () | _
completeS (φ /|g g) (silent-/| s) oracle with step g oracle
| completeS g s oracle
... | speak _ | ()
... | refuse _ | _ = isRefuse
completeS (defg x g) (silent-def s) oracle with step g oracle
| completeS g s oracle
... | speak _ | ()
... | refuse _ | _ = isRefuse
theOracle : {a : U}{p : Proc a}{w : LT a}{q : Proc a} ->
p -! w !-> q -> Oracle
theOracle tx-! = anyOracle
theOracle tx-+ = anyOracle
theOracle (tx-!| s r) = ocons left (theOracle s)
theOracle (tx-|! r s) = ocons right (theOracle s)
theOracle (tx-/| s) = theOracle s
theOracle (tx-def s) = theOracle s
data IsSpeak {a : U}{p : Proc a}(w : LT a)(q : Proc a) : Result p -> Set where
isSpeak : {r : p -! w !-> q} -> IsSpeak w q (speak r)
completeT : {a : U}{p : Proc a}(g : Guard p){w : LT a}{q : Proc a} ->
(r : p -! w !-> q) -> IsSpeak w q (step g (\x -> theOracle r x))
completeT og ()
completeT (>g _) ()
completeT (w !g p) tx-! = isSpeak
completeT (w ! p +g f) tx-+ = isSpeak
completeT (g1 ||g g2) (tx-!| s r) with step g1 (\x -> theOracle s x)
| step g2 (\x -> theOracle s x)
| completeT g1 s
| hear-complete g2 r
... | .(speak _) | refuse _ | isSpeak | refl = isSpeak
... | .(speak _) | speak _ | isSpeak | refl = isSpeak
completeT (g1 ||g g2) (tx-|! r s) with step g1 (\x -> theOracle s x)
| step g2 (\x -> theOracle s x)
| hear-complete g1 r
| completeT g2 s
... | refuse _ | .(speak _) | refl | isSpeak = isSpeak
... | speak _ | .(speak _) | refl | isSpeak = isSpeak
completeT (φ /|g g) (tx-/| s) with step g (\x -> theOracle s x)
| completeT g s
... | ._ | isSpeak = isSpeak
completeT (defg x g) (tx-def s) with step g (\x -> theOracle s x)
| completeT g s
... | ._ | isSpeak = isSpeak
|
{
"alphanum_fraction": 0.4877693652,
"avg_line_length": 38.1555555556,
"ext": "agda",
"hexsha": "e2442095a62f192ed12a883cddd414ed7c22040f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/cbs/Mission.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/cbs/Mission.agda",
"max_line_length": 78,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/cbs/Mission.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 1045,
"size": 3434
}
|
{-# OPTIONS --warning=error #-}
module UselessPrivatePrivate where
private
private
postulate
A : Set
|
{
"alphanum_fraction": 0.6782608696,
"avg_line_length": 12.7777777778,
"ext": "agda",
"hexsha": "babfd9f880dcca8093ee987651551ad6d9a96b94",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/UselessPrivatePrivate.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/UselessPrivatePrivate.agda",
"max_line_length": 34,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/UselessPrivatePrivate.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 28,
"size": 115
}
|
module optics where
open import Function
open import Data.Nat
open import Data.Vec
open import Agda.Builtin.Sigma
open import Data.Product
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; trans; sym; cong; cong-app; subst)
record TraversalF (S T A B : Set) : Set where
field
extract : Σ[ f ∈ (S -> ℕ) ] ((s : S) -> Vec A (f s) × (Vec B (f s) -> T))
record Traversal (S T A B : Set) : Set where
field
--extract : S -> ∃[ n ] (Vec A n × (Vec B n -> T))
extract : S -> Σ[ n ∈ ℕ ] Vec A n × (Vec B n -> T)
get : (s : S) -> Vec A (fst (extract s))
get = fst ∘ snd ∘ extract
put : (s : S) -> Vec B (fst (extract s)) -> T
put = snd ∘ snd ∘ extract
record TraversalLaws (S A : Set) (t : Traversal S S A A): Set where
open Traversal t public
field
get-put-law : (s : S) -> (put s) (get s) ≡ s
-- put-get-law : (s : S) -> (v : Vec A (fst (Traversal.extract t s))) ->
-- (Traversal.get t (Traversal.put t s v)) ≡ {!!}
record Traversal2 (S A B T : Set) : Set where
field
extract : (s : S) -> Σ[ f ∈ (S -> ℕ) ] Vec A (f s) × (Vec B (f s) -> T)
|
{
"alphanum_fraction": 0.5397096499,
"avg_line_length": 30.0256410256,
"ext": "agda",
"hexsha": "3a9deacdf901ec893a879b4c836e59d37d386b80",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "hablapps/safeoptics",
"max_forks_repo_path": "src/main/agda/optics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "hablapps/safeoptics",
"max_issues_repo_path": "src/main/agda/optics.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "hablapps/safeoptics",
"max_stars_repo_path": "src/main/agda/optics.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 413,
"size": 1171
}
|
module Prologue where
open import Relation.Binary.Core
open IsEquivalence ⦃ … ⦄
|
{
"alphanum_fraction": 0.7710843373,
"avg_line_length": 11.8571428571,
"ext": "agda",
"hexsha": "200900d2055a70a81ac744d3bb2a882c7c2626cc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/Prologue.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/Prologue.agda",
"max_line_length": 32,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/Prologue.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 24,
"size": 83
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Setoids.Setoids
open import Sets.EquivalenceRelations
open import Rings.Definition
module Rings.Ideals.Principal.Lemmas {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} (R : Ring S _+_ _*_) where
open Setoid S
open Ring R
open Equivalence eq
open import Rings.Ideals.Principal.Definition R
open import Rings.Ideals.Definition R
open import Rings.Ideals.Lemmas R
open import Rings.Divisible.Definition R
generatorZeroImpliesAllZero : {c : _} {pred : A → Set c} → {i : Ideal pred} → (princ : PrincipalIdeal i) → PrincipalIdeal.generator princ ∼ 0R → {x : A} → pred x → x ∼ 0R
generatorZeroImpliesAllZero record { generator = gen ; genIsInIdeal = genIsInIdeal ; genGenerates = genGenerates } gen=0 {x} predX = generatorZeroImpliesMembersZero {x} (divisibleWellDefined gen=0 reflexive (genGenerates predX))
|
{
"alphanum_fraction": 0.733408324,
"avg_line_length": 44.45,
"ext": "agda",
"hexsha": "1fa04184e92b73d87afbba50c01ac6d7041240d7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Rings/Ideals/Principal/Lemmas.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/Ideals/Principal/Lemmas.agda",
"max_line_length": 228,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Rings/Ideals/Principal/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 275,
"size": 889
}
|
-- WARNING: This file was generated automatically by Vehicle
-- and should not be modified manually!
-- Metadata
-- - Agda version: 2.6.2
-- - AISEC version: 0.1.0.1
-- - Time generated: ???
{-# OPTIONS --allow-exec #-}
open import Vehicle
open import Data.Integer as ℤ using (ℤ)
open import Data.Rational as ℚ using (ℚ)
module simple-arithmetic-temp-output where
precedence : ℚ → (ℚ → (ℚ → ℚ))
precedence x y z = (x ℚ.+ (ℤ.+ 2 ℚ./ 1) ℚ.* y) ℚ.- z ℚ.÷ y
|
{
"alphanum_fraction": 0.652173913,
"avg_line_length": 27.0588235294,
"ext": "agda",
"hexsha": "ce9aa3d50547f0eebd86ad38864405028917feb1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vehicle-lang/vehicle",
"max_forks_repo_path": "test/Test/Compile/Golden/simple-arithmetic/simple-arithmetic-output.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T20:49:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-07T14:09:13.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vehicle-lang/vehicle",
"max_issues_repo_path": "test/Test/Compile/Golden/simple-arithmetic/simple-arithmetic-output.agda",
"max_line_length": 60,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vehicle-lang/vehicle",
"max_stars_repo_path": "test/Test/Compile/Golden/simple-arithmetic/simple-arithmetic-output.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-17T18:51:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-10T12:56:42.000Z",
"num_tokens": 159,
"size": 460
}
|
-- Andreas, 2012-09-11
{-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.meta:50 #-}
module Const where
import Common.Level
const : {A B : Set} → A → B → A
const a b = a
-- If this is analyzed as {A B : Set} → A → .B → A
-- then, due to constraint solving insensitive to subtyping,
-- the following will trigger an 'UnequalRelevance' error.
postulate
F : Set → Set
_<$>_ : {A B : Set} → (A → B) → F A → F B
_<*>_ : {A B : Set} → F (A → B) → F A → F B
test : {A B : Set} → F A → F B → F A
test {A} {B} x y = (const <$> x) <*> y
|
{
"alphanum_fraction": 0.5489833641,
"avg_line_length": 24.5909090909,
"ext": "agda",
"hexsha": "a629942f5857655b380d0333273c099b127274d3",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Const.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Const.agda",
"max_line_length": 60,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Const.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 200,
"size": 541
}
|
module PolyDepPrelude where
data Pi {X : Set} (Y : X -> Set) : Set where
pi : ((x : X) -> Y x) -> Pi Y
apply : {a : Set} -> {f : a -> Set} -> Pi f -> (x : a) -> f x
apply (pi f) x = f x
data Forall {X : Set} (Y : X -> Set) : Set where
forAll : ((x : X) -> Y x) -> Forall Y
data _=>_ (X Y : Set) : Set where
lam : (X -> Y) -> X => Y
_$$_ : {X Y : Set} -> (X => Y) -> X -> Y
lam f $$ x = f x
infixr 0 _$$_
id : {a : Set} -> a -> a
id x = x
infixr 0 _$_
_$_ : {a b : Set} -> (a -> b) -> a -> b
f $ x = f x
data Bool : Set where
true : Bool
false : Bool
_&&_ : Bool -> Bool -> Bool
true && b = b
false && _ = false
data Pair (a b : Set) : Set where
pair : a -> b -> Pair a b
fst : {a b : Set} -> Pair a b -> a
fst (pair x y) = x
snd : {a b : Set} -> Pair a b -> b
snd (pair x y) = y
cmp : {X Y Z : Set} -> (Y -> Z) -> (X -> Y) -> X -> Z
cmp f g = \x -> f (g x)
data Either (a b : Set) : Set where
left : a -> Either a b
right : b -> Either a b
data Maybe (a : Set) : Set where
Nothing : Maybe a
Just : a -> Maybe a
data Unit : Set where
unit : Unit
Taut = Unit
data Absurd : Set where
postulate
absurdElim : {whatever : Set} -> Absurd -> whatever
T : Bool -> Set
T true = Unit
T false = Absurd
andT : {x y : Bool} -> T x -> T y -> T (x && y)
andT {true} {true} _ _ = unit
andT {false} {_} () _
andT {true} {false} _ ()
T' : {a : Set} -> (a -> a -> Bool) -> (a -> a -> Set)
T' f x y = T (f x y)
data Not (a : Set) : Set where
not : (a -> Absurd) -> Not a
-- Not : Set -> Set
-- Not a = a -> Absurd
contrapositive : {a b : Set} -> (a -> b) -> Not b -> Not a
contrapositive p (not nb) = not (\a -> nb (p a))
private
notDistribOut' : {a b : Set} -> Not a -> Not b -> Either a b -> Absurd
notDistribOut' (not na) _ (left a) = na a
notDistribOut' _ (not nb) (right b) = nb b
notDistribOut : {a b : Set} -> Not a -> Not b -> Not (Either a b)
notDistribOut na nb = not (notDistribOut' na nb)
notDistribIn : {a b : Set} -> Not (Either a b) -> Pair (Not a) (Not b)
notDistribIn (not nab) = pair (not (\a -> nab (left a)))
(not (\b -> nab (right b)))
data _<->_ (a b : Set) : Set where
iff : (a -> b) -> (b -> a) -> a <-> b
iffLeft : {a b : Set} -> (a <-> b) -> (a -> b)
iffLeft (iff l _) = l
iffRight : {a b : Set} -> (a <-> b) -> (b -> a)
iffRight (iff _ r) = r
data Nat : Set where
zero : Nat
suc : Nat -> Nat
one : Nat
one = suc zero
elimNat : (C : Nat -> Set)
-> (C zero) -> ((m : Nat) -> C m -> C (suc m)) -> (n : Nat) -> C n
elimNat C c_z c_s zero = c_z
elimNat C c_z c_s (suc m') = c_s m' (elimNat C c_z c_s m')
data List (A : Set) : Set where
nil : List A
_::_ : A -> List A -> List A
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL nil #-}
{-# BUILTIN CONS _::_ #-}
elimList : {A : Set} ->
(C : List A -> Set) ->
(C nil) ->
((a : A) -> (as : List A) -> C as -> C (a :: as)) ->
(as : List A) ->
C as
elimList _ c_nil _ nil = c_nil
elimList C c_nil c_con (a :: as) = c_con a as (elimList C c_nil c_con as)
data Reflexive {X : Set} (_R_ : X -> X -> Set) : Set where
reflexive : ((x : X) -> x R x) -> Reflexive _R_
data Symmetrical {X : Set} (_R_ : X -> X -> Set) : Set where
symmetrical : ( {x1 x2 : X} -> x1 R x2 -> x2 R x1) -> Symmetrical _R_
data Substitutive {X : Set} (_R_ : X -> X -> Set) : Set1 where
substitutive : ( (P : X -> Set) -> {x1 x2 : X} -> x1 R x2 -> P x1 -> P x2)
-> Substitutive _R_
True : Bool -> Set
True (true) = Unit
True (false) = Absurd
data Datoid : Set1 where
datoid : (Elem : Set) ->
(eq : Elem -> Elem -> Bool) ->
(ref : (x : Elem) -> True (eq x x)) ->
(subst : Substitutive (\x1 -> \x2 -> True (eq x1 x2))) ->
Datoid
pElem : Datoid -> Set
pElem (datoid Elem _ _ _) = Elem
|
{
"alphanum_fraction": 0.4895429899,
"avg_line_length": 24.0559006211,
"ext": "agda",
"hexsha": "d5ec0316993486025c9611b27331b36b9389e3a8",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "examples/AIM5/PolyDep/PolyDepPrelude.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "examples/AIM5/PolyDep/PolyDepPrelude.agda",
"max_line_length": 76,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "examples/AIM5/PolyDep/PolyDepPrelude.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 1477,
"size": 3873
}
|
open import Oscar.Prelude
open import Oscar.Class.HasEquivalence
open import Oscar.Class.Smap
open import Oscar.Class.Symmetry
open import Oscar.Class.Symmetrical
open import Oscar.Data.Surjcollation
import Oscar.Class.HasEquivalence.Ṗroperty
import Oscar.Class.Surjection.⋆
import Oscar.Data.Proposequality
module Oscar.Class.Symmetrical.Unifies where
module _
{𝔵} {𝔛 : Ø 𝔵}
{𝔞} {𝔄 : 𝔛 → 𝔛 → Ø 𝔞}
{𝔠} {ℭ : 𝔛 → Ø 𝔠}
⦃ _ : Smap!.class 𝔄 (Extension ℭ) ⦄
{ℓ} {_≈'_ : ∀ {y} → ℭ y → ℭ y → Ø ℓ}
⦃ _ : ∀ {y} → Symmetry.class (_≈'_ {y}) ⦄
where
instance
𝓢ymmetricalUnifies₀ : ∀ {m} → Symmetrical surjcollation⟦ _ / _≈'_ ⟧ (λ x y → x ≈[ LeftṖroperty ℓ 𝔄 m ] y)
𝓢ymmetricalUnifies₀ .𝓢ymmetrical.symmetrical x y .π₀ = symmetry , symmetry
|
{
"alphanum_fraction": 0.6794195251,
"avg_line_length": 28.0740740741,
"ext": "agda",
"hexsha": "7d7ad9641d147c478e3b1b866bc9d3816ea8e582",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Symmetrical/Unifies.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Symmetrical/Unifies.agda",
"max_line_length": 110,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Symmetrical/Unifies.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 306,
"size": 758
}
|
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Fin.Arithmetic where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat
open import Cubical.Data.Nat.Mod
open import Cubical.Data.Nat.Order
open import Cubical.Data.Fin
open import Cubical.Data.Sigma
infixl 6 _+ₘ_ _-ₘ_ _·ₘ_
infix 7 -ₘ_
-- Addition, subtraction and multiplication
_+ₘ_ : {n : ℕ} → Fin (suc n) → Fin (suc n) → Fin (suc n)
fst (_+ₘ_ {n = n} x y) = ((fst x) + (fst y)) mod (suc n)
snd (_+ₘ_ {n = n} x y) = mod< _ ((fst x) + (fst y))
-ₘ_ : {n : ℕ} → (x : Fin (suc n)) → Fin (suc n)
fst (-ₘ_ {n = n} x) =
(+induction n _ (λ x _ → ((suc n) ∸ x) mod (suc n)) λ _ x → x) (fst x)
snd (-ₘ_ {n = n} x) = lem (fst x)
where
≡<-trans : {x y z : ℕ} → x < y → x ≡ z → z < y
≡<-trans (k , p) q = k , cong (λ x → k + suc x) (sym q) ∙ p
lem : {n : ℕ} (x : ℕ)
→ (+induction n _ _ _) x < suc n
lem {n = n} =
+induction n _
(λ x p → ≡<-trans (mod< n (suc n ∸ x))
(sym (+inductionBase n _ _ _ x p)))
λ x p → ≡<-trans p
(sym (+inductionStep n _ _ _ x))
_-ₘ_ : {n : ℕ} → (x y : Fin (suc n)) → Fin (suc n)
_-ₘ_ x y = x +ₘ (-ₘ y)
_·ₘ_ : {n : ℕ} → (x y : Fin (suc n)) → Fin (suc n)
fst (_·ₘ_ {n = n} x y) = (fst x · fst y) mod (suc n)
snd (_·ₘ_ {n = n} x y) = mod< n (fst x · fst y)
-- Group laws
+ₘ-assoc : {n : ℕ} (x y z : Fin (suc n))
→ (x +ₘ y) +ₘ z ≡ (x +ₘ (y +ₘ z))
+ₘ-assoc {n = n} x y z =
Σ≡Prop (λ _ → isProp≤)
((mod-rCancel (suc n) ((fst x + fst y) mod (suc n)) (fst z))
∙∙ sym (mod+mod≡mod (suc n) (fst x + fst y) (fst z))
∙∙ cong (_mod suc n) (sym (+-assoc (fst x) (fst y) (fst z)))
∙∙ mod+mod≡mod (suc n) (fst x) (fst y + fst z)
∙∙ sym (mod-lCancel (suc n) (fst x) ((fst y + fst z) mod suc n)))
+ₘ-comm : {n : ℕ} (x y : Fin (suc n)) → (x +ₘ y) ≡ (y +ₘ x)
+ₘ-comm {n = n} x y =
Σ≡Prop (λ _ → isProp≤)
(cong (_mod suc n) (+-comm (fst x) (fst y)))
+ₘ-lUnit : {n : ℕ} (x : Fin (suc n)) → 0 +ₘ x ≡ x
+ₘ-lUnit {n = n} (x , p) =
Σ≡Prop (λ _ → isProp≤)
(+inductionBase n _ _ _ x p)
+ₘ-rUnit : {n : ℕ} (x : Fin (suc n)) → x +ₘ 0 ≡ x
+ₘ-rUnit x = +ₘ-comm x 0 ∙ (+ₘ-lUnit x)
+ₘ-rCancel : {n : ℕ} (x : Fin (suc n)) → x -ₘ x ≡ 0
+ₘ-rCancel {n = n} x =
Σ≡Prop (λ _ → isProp≤)
(cong (λ z → (fst x + z) mod (suc n))
(+inductionBase n _ _ _ (fst x) (snd x))
∙∙ sym (mod-rCancel (suc n) (fst x) ((suc n) ∸ (fst x)))
∙∙ cong (_mod (suc n)) (+-comm (fst x) ((suc n) ∸ (fst x)))
∙∙ cong (_mod (suc n)) (≤-∸-+-cancel (<-weaken (snd x)))
∙∙ zero-charac (suc n))
+ₘ-lCancel : {n : ℕ} (x : Fin (suc n)) → (-ₘ x) +ₘ x ≡ 0
+ₘ-lCancel {n = n} x = +ₘ-comm (-ₘ x) x ∙ +ₘ-rCancel x
-- TODO : Ring laws
private
test₁ : Path (Fin 11) (5 +ₘ 10) 4
test₁ = refl
test₂ : Path (Fin 11) (-ₘ 7 +ₘ 5 +ₘ 10) 8
test₂ = refl
|
{
"alphanum_fraction": 0.4904255319,
"avg_line_length": 32.0454545455,
"ext": "agda",
"hexsha": "3a35a9e138dd6ea15f405c253a36ce7fc795f1f1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Data/Fin/Arithmetic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Data/Fin/Arithmetic.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Data/Fin/Arithmetic.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 1348,
"size": 2820
}
|
-- Operator example
module Operators where
data True : Set where
tt : True
data False : Set where
data Bool : Set where
false : Bool
true : Bool
-- An operator is declared with '_' where the arguments go
if_then_else_ : Bool -> {A : Set} -> A -> A -> A
if true then x else y = x
if false then x else y = y
-- The actual name of the operator is obtained by removing all the spaces from
-- the declared version.
infix 1 if_then_else_
-- This name can be used in normal applications, for instance, if a hidden argument
-- needs to be supplied.
_&&_ : Bool -> Bool -> Bool
x && y = if_then_else_ x {Bool} y false
-- Operators can be prefix...
¬_ : Bool -> Bool
¬ true = false
¬ false = true
-- ...or postfix...
_valid : Bool -> Set
true valid = True
false valid = False
-- ...or roundfix
⟦_⟧ : Bool -> Set
⟦ x ⟧ = x valid
|
{
"alphanum_fraction": 0.6583333333,
"avg_line_length": 19.5348837209,
"ext": "agda",
"hexsha": "74c0d523ba336c2b48e0211b132b6e51536aa9e2",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Operators.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Operators.agda",
"max_line_length": 83,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Operators.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 242,
"size": 840
}
|
-- Andreas, 2014-01-10
-- Code by Jesper Cockx and Conor McBride and folks from the Coq-club
{-# OPTIONS --cubical-compatible #-}
-- An empty type.
data Zero : Set where
-- A unit type as W-type.
mutual
data WOne : Set where wrap : FOne -> WOne
FOne = Zero -> WOne
-- Type equality.
data _<->_ (X : Set) : Set -> Set₁ where
Refl : X <-> X
-- This postulate is compatible with univalence:
postulate
iso : WOne <-> FOne
-- But accepting that is incompatible with univalence:
auoo : WOne -> Zero
auoo (wrap f) = noo FOne iso f
where
noo : (X : Set) -> (WOne <-> X) -> X -> Zero
noo .WOne Refl w = auoo w
-- Matching against Refl silently applies the conversion
-- FOne -> WOne to f. But this conversion corresponds
-- to an application of wrap. Thus, f, which is really
-- (wrap f), should not be considered a subterm of (wrap f)
-- by the termination checker.
-- At least, if we want to be compatible with univalence.
absurd : Zero
absurd = auoo (wrap \ ())
-- noo should fail termination check.
|
{
"alphanum_fraction": 0.6624513619,
"avg_line_length": 22.8444444444,
"ext": "agda",
"hexsha": "50049579f770565137f99497137bb58cb0adf8f2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Fail/Issue1023-MaskNonData.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Fail/Issue1023-MaskNonData.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Fail/Issue1023-MaskNonData.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 306,
"size": 1028
}
|
module Data.QuadTree.Implementation.QuadrantLenses where
open import Haskell.Prelude renaming (zero to Z; suc to S)
open import Data.Lens.Lens
open import Data.Logic
open import Data.QuadTree.Implementation.PropDepthRelation
open import Data.QuadTree.Implementation.Definition
open import Data.QuadTree.Implementation.ValidTypes
{-# FOREIGN AGDA2HS
{-# LANGUAGE Safe #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE Rank2Types #-}
import Data.Nat
import Data.Lens.Lens
import Data.Logic
import Data.QuadTree.Implementation.Definition
import Data.QuadTree.Implementation.ValidTypes
#-}
---- Lenses
-- Lenses into a leaf of a depth zero quadrant
lensLeaf : {t : Set} {{eqT : Eq t}}
-> Lens (VQuadrant t {0}) t
lensLeaf f (CVQuadrant (Leaf v)) = fmap (λ x -> CVQuadrant (Leaf x) {IsTrue.itsTrue}) (f v)
{-# COMPILE AGDA2HS lensLeaf #-}
-- A proof of the depth relation of a node and its children
propDepthRelationLte : {t : Set} -> (a b c d : Quadrant t) -> (dep : Nat)
-> ((depth a <= dep && depth b <= dep) && (depth c <= dep && depth d <= dep)) ≡ (depth (Node a b c d) <= (S dep))
propDepthRelationLte a b c d dep =
begin
((depth a <= dep && depth b <= dep) && (depth c <= dep && depth d <= dep))
=⟨ propMaxLte4 (depth a) (depth b) (depth c) (depth d) dep ⟩
(max (max (depth a) (depth b)) (max (depth c) (depth d)) <= dep)
=⟨⟩
(depth (Node a b c d) <= S dep)
end
-- A proof of the compressed relation of a node and its children
propCompressedRelation : {t : Set} {{eqT : Eq t}} -> {a b c d : Quadrant t}
-> IsTrue (isCompressed (Node a b c d))
-> IsTrue (isCompressed a && isCompressed b && isCompressed c && isCompressed d)
propCompressedRelation {_} {Leaf a} {Leaf b} {Leaf c} {Leaf d} p = IsTrue.itsTrue
propCompressedRelation {_} {Node _ _ _ _} {b} {c} {d} p = p
propCompressedRelation {_} {Leaf _} {Node _ _ _ _} {c} {d} p = p
propCompressedRelation {_} {Leaf _} {Leaf _} {Node _ _ _ _} {d} p = p
propCompressedRelation {_} {Leaf _} {Leaf _} {Leaf _} {Node _ _ _ _} p = p
-- Combine 4 valid quadrants to a new valid quadrant
combine : {t : Set} {{eqT : Eq t}}
-> {dep : Nat}
-> (a b c d : VQuadrant t {dep})
-> VQuadrant t {S dep}
combine {t} {dep} (CVQuadrant a@(Leaf va) {pa}) (CVQuadrant b@(Leaf vb) {pb}) (CVQuadrant c@(Leaf vc) {pc}) (CVQuadrant d@(Leaf vd) {pd})
= ifc (va == vb && vb == vc && vc == vd)
then CVQuadrant a {IsTrue.itsTrue}
else (λ {{pn}} -> CVQuadrant (Node a b c d) {andCombine (zeroLteAny dep) (falseToNotTrue $ pn)})
-- The next 4 cases are all identical, but I could not figure out another way to convince agda
combine {t} {dep} (CVQuadrant a@(Node v1 v2 v3 v4) {pa}) (CVQuadrant b {pb}) (CVQuadrant c {pc}) (CVQuadrant d {pd})
= CVQuadrant (Node a b c d) {andCombine
(useEq (propDepthRelationLte a b c d dep) ((propIsTrueCombine4 (andFst {depth a <= dep} pa) (andFst {depth b <= dep} pb) (andFst {depth c <= dep} pc) (andFst {depth d <= dep} pd))))
(propIsTrueCombine4Alt (andSnd {depth a <= dep} pa) (andSnd {depth b <= dep} pb) (andSnd {depth c <= dep} pc) (andSnd {depth d <= dep} pd))
}
combine {t} {dep} (CVQuadrant a@(Leaf va) {pa}) (CVQuadrant b@(Node v1 v2 v3 v4) {pb}) (CVQuadrant c {pc}) (CVQuadrant d {pd})
= CVQuadrant (Node a b c d) {andCombine
(useEq (propDepthRelationLte a b c d dep) ((propIsTrueCombine4 (andFst {depth a <= dep} pa) (andFst {depth b <= dep} pb) (andFst {depth c <= dep} pc) (andFst {depth d <= dep} pd))))
(propIsTrueCombine4Alt (andSnd {depth a <= dep} pa) (andSnd {depth b <= dep} pb) (andSnd {depth c <= dep} pc) (andSnd {depth d <= dep} pd))
}
combine {t} {dep} (CVQuadrant a@(Leaf va) {pa}) (CVQuadrant b@(Leaf vb) {pb}) (CVQuadrant c@(Node v1 v2 v3 v4) {pc}) (CVQuadrant d {pd})
= CVQuadrant (Node a b c d) {andCombine
(useEq (propDepthRelationLte a b c d dep) ((propIsTrueCombine4 (andFst {depth a <= dep} pa) (andFst {depth b <= dep} pb) (andFst {depth c <= dep} pc) (andFst {depth d <= dep} pd))))
(propIsTrueCombine4Alt (andSnd {depth a <= dep} pa) (andSnd {depth b <= dep} pb) (andSnd {depth c <= dep} pc) (andSnd {depth d <= dep} pd))
}
combine {t} {dep} (CVQuadrant a@(Leaf va) {pa}) (CVQuadrant b@(Leaf vb) {pb}) (CVQuadrant c@(Leaf vc) {pc}) (CVQuadrant d@(Node v1 v2 v3 v4) {pd})
= CVQuadrant (Node a b c d) {andCombine
(useEq (propDepthRelationLte a b c d dep) ((propIsTrueCombine4 (andFst {depth a <= dep} pa) (andFst {depth b <= dep} pb) (andFst {depth c <= dep} pc) (andFst {depth d <= dep} pd))))
(propIsTrueCombine4Alt (andSnd {depth a <= dep} pa) (andSnd {depth b <= dep} pb) (andSnd {depth c <= dep} pc) (andSnd {depth d <= dep} pd))
}
{-# COMPILE AGDA2HS combine #-}
-- Goes from a valid quadrant to its a subquadrant
aSub : {t : Set} {{eqT : Eq t}} -> {dep : Nat} -> (a b c d : Quadrant t)
-> IsTrue (isValid (S dep) (Node a b c d)) -> IsTrue (isValid (dep) a)
aSub {_} {dep} a b c d p = andCombine
-- Convert depth proof using propDepthRelationLte
(andFst $ andFst {(depth a <= dep && depth b <= dep)} $ useEq (sym (propDepthRelationLte a b c d dep)) (andFst p))
-- Convert compressed proof using propCompressedRelation
(and1 {isCompressed a} {isCompressed b} {isCompressed c} {isCompressed d} (propCompressedRelation {_} {a} (andSnd p)))
-- Goes from a valid quadrant to its b subquadrant
bSub : {t : Set} {{eqT : Eq t}} -> {dep : Nat} -> (a b c d : Quadrant t)
-> IsTrue (isValid (S dep) (Node a b c d)) -> IsTrue (isValid (dep) b)
bSub {_} {dep} a b c d p = andCombine
-- Convert depth proof using propDepthRelationLte
(andSnd $ andFst {(depth a <= dep && depth b <= dep)} $ useEq (sym (propDepthRelationLte a b c d dep)) (andFst p))
-- Convert compressed proof using propCompressedRelation
(and2 {isCompressed a} {isCompressed b} {isCompressed c} {isCompressed d} (propCompressedRelation {_} {a} (andSnd p)))
-- Goes from a valid quadrant to its c subquadrant
cSub : {t : Set} {{eqT : Eq t}} -> {dep : Nat} -> (a b c d : Quadrant t)
-> IsTrue (isValid (S dep) (Node a b c d)) -> IsTrue (isValid (dep) c)
cSub {_} {dep} a b c d p = andCombine
-- Convert depth proof using propDepthRelationLte
(andFst $ andSnd {(depth a <= dep && depth b <= dep)} $ useEq (sym (propDepthRelationLte a b c d dep)) (andFst p))
-- Convert compressed proof using propCompressedRelation
(and3 {isCompressed a} {isCompressed b} {isCompressed c} {isCompressed d} (propCompressedRelation {_} {a} (andSnd p)))
-- Goes from a valid quadrant to its d subquadrant
dSub : {t : Set} {{eqT : Eq t}} -> {dep : Nat} -> (a b c d : Quadrant t)
-> IsTrue (isValid (S dep) (Node a b c d)) -> IsTrue (isValid (dep) d)
dSub {_} {dep} a b c d p = andCombine
-- Convert depth proof using propDepthRelationLte
(andSnd $ andSnd {(depth a <= dep && depth b <= dep)} $ useEq (sym (propDepthRelationLte a b c d dep)) (andFst p))
-- Convert compressed proof using propCompressedRelation
(and4 {isCompressed a} {isCompressed b} {isCompressed c} {isCompressed d} (propCompressedRelation {_} {a} (andSnd p)))
-- Lens into the a subquadrant
lensA :
{t : Set} {{eqT : Eq t}}
-> {dep : Nat}
-> Lens (VQuadrant t {S dep}) (VQuadrant t {dep})
lensA {_} {dep} f (CVQuadrant (Leaf v) {p}) =
let sub = CVQuadrant (Leaf v) {andCombine (zeroLteAny dep) IsTrue.itsTrue}
in fmap (λ x -> combine x sub sub sub ) (f sub)
lensA {_} {dep} f (CVQuadrant (Node a b c d) {p}) =
let
sA = CVQuadrant a {aSub a b c d p}
sB = CVQuadrant b {bSub a b c d p}
sC = CVQuadrant c {cSub a b c d p}
sD = CVQuadrant d {dSub a b c d p}
in fmap (λ x -> combine x sB sC sD ) (f sA)
{-# COMPILE AGDA2HS lensA #-}
-- Lens into the b subquadrant
lensB :
{t : Set} {{eqT : Eq t}}
-> {dep : Nat}
-> Lens (VQuadrant t {S dep}) (VQuadrant t {dep})
lensB {_} {dep} f (CVQuadrant (Leaf v) {p}) =
let sub = CVQuadrant (Leaf v) {andCombine (zeroLteAny dep) IsTrue.itsTrue}
in fmap (λ x -> combine sub x sub sub ) (f sub)
lensB {_} {dep} f (CVQuadrant (Node a b c d) {p}) =
let
sA = CVQuadrant a {aSub a b c d p}
sB = CVQuadrant b {bSub a b c d p}
sC = CVQuadrant c {cSub a b c d p}
sD = CVQuadrant d {dSub a b c d p}
in fmap (λ x -> combine sA x sC sD ) (f sB)
{-# COMPILE AGDA2HS lensB #-}
-- Lens into the c subquadrant
lensC :
{t : Set} {{eqT : Eq t}}
-> {dep : Nat}
-> Lens (VQuadrant t {S dep}) (VQuadrant t {dep})
lensC {_} {dep} f (CVQuadrant (Leaf v) {p}) =
let sub = CVQuadrant (Leaf v) {andCombine (zeroLteAny dep) IsTrue.itsTrue}
in fmap (λ x -> combine sub sub x sub ) (f sub)
lensC {_} {dep} f (CVQuadrant (Node a b c d) {p}) =
let
sA = CVQuadrant a {aSub a b c d p}
sB = CVQuadrant b {bSub a b c d p}
sC = CVQuadrant c {cSub a b c d p}
sD = CVQuadrant d {dSub a b c d p}
in fmap (λ x -> combine sA sB x sD ) (f sC)
{-# COMPILE AGDA2HS lensC #-}
-- Lens into the d subquadrant
lensD :
{t : Set} {{eqT : Eq t}}
-> {dep : Nat}
-> Lens (VQuadrant t {S dep}) (VQuadrant t {dep})
lensD {_} {dep} f (CVQuadrant (Leaf v) {p}) =
let sub = CVQuadrant (Leaf v) {andCombine (zeroLteAny dep) IsTrue.itsTrue}
in fmap (λ x -> combine sub sub sub x ) (f sub)
lensD {_} {dep} f (CVQuadrant (Node a b c d) {p}) =
let
sA = CVQuadrant a {aSub a b c d p}
sB = CVQuadrant b {bSub a b c d p}
sC = CVQuadrant c {cSub a b c d p}
sD = CVQuadrant d {dSub a b c d p}
in fmap (λ x -> combine sA sB sC x ) (f sD)
{-# COMPILE AGDA2HS lensD #-}
|
{
"alphanum_fraction": 0.6310597221,
"avg_line_length": 50.6827956989,
"ext": "agda",
"hexsha": "75ad91ab0461622710eadfa781e4c159178ba50c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "JonathanBrouwer/research-project",
"max_forks_repo_path": "src/Data/QuadTree/Implementation/QuadrantLenses.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "JonathanBrouwer/research-project",
"max_issues_repo_path": "src/Data/QuadTree/Implementation/QuadrantLenses.agda",
"max_line_length": 186,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "JonathanBrouwer/research-project",
"max_stars_repo_path": "src/Data/QuadTree/Implementation/QuadrantLenses.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z",
"num_tokens": 3524,
"size": 9427
}
|
------------------------------------------------------------------------------
-- Proving properties without using pattern matching on refl
------------------------------------------------------------------------------
{-# OPTIONS --no-pattern-matching #-}
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
module FOT.DistributiveLaws.NoPatternMatchingOnRefl where
open import DistributiveLaws.Base
------------------------------------------------------------------------------
-- From DistributiveLaws.PropertiesI
-- Congruence properties
·-leftCong : ∀ {a b c} → a ≡ b → a · c ≡ b · c
·-leftCong {a} {c = c} h = subst (λ t → a · c ≡ t · c) h refl
·-rightCong : ∀ {a b c} → b ≡ c → a · b ≡ a · c
·-rightCong {a} {b} h = subst (λ t → a · b ≡ a · t) h refl
|
{
"alphanum_fraction": 0.432304038,
"avg_line_length": 35.0833333333,
"ext": "agda",
"hexsha": "3f2d4932dcebd8f4053627bb8f173b6b708cb560",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/DistributiveLaws/NoPatternMatchingOnRefl.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/DistributiveLaws/NoPatternMatchingOnRefl.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/DistributiveLaws/NoPatternMatchingOnRefl.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 201,
"size": 842
}
|
open import Agda.Builtin.Bool
data D : Set where
c : Bool → D
f : @0 D → Bool
f (c true) = true
f (c false) = false
|
{
"alphanum_fraction": 0.6033057851,
"avg_line_length": 13.4444444444,
"ext": "agda",
"hexsha": "b358554cf2fda1cfadf5c36f93e89360e9680d5b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Fail/Issue5079.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Fail/Issue5079.agda",
"max_line_length": 29,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Fail/Issue5079.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 46,
"size": 121
}
|
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
postulate
D : Set
_≡_ : D → D → Set
a b : D
postulate p : a ≡ b
{-# ATP axiom p #-}
postulate foo : a ≡ b
{-# ATP prove foo #-}
|
{
"alphanum_fraction": 0.4790996785,
"avg_line_length": 19.4375,
"ext": "agda",
"hexsha": "3922e9174791507a64f86c766a954b7adaa1fce3",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Fail/Errors/Issue84.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Fail/Errors/Issue84.agda",
"max_line_length": 42,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Fail/Errors/Issue84.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 87,
"size": 311
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.CoYoneda where
-- CoYoneda Lemma. See Yoneda for more documentation
open import Level
open import Function.Base using (_$_)
open import Function.Bundles using (Inverse)
open import Function.Equality using (Π; _⟨$⟩_; cong)
open import Relation.Binary.Bundles using (module Setoid)
import Relation.Binary.Reasoning.Setoid as SetoidR
open import Data.Product using (_,_; Σ)
open import Categories.Category using (Category; _[_,_])
open import Categories.Category.Product using (πʳ; πˡ; _※_)
open import Categories.Category.Construction.Presheaves using (CoPresheaves)
open import Categories.Category.Construction.Functors using (eval)
open import Categories.Category.Construction.Functors
open import Categories.Category.Instance.Setoids using (Setoids)
open import Categories.Functor using (Functor; _∘F_) renaming (id to idF)
open import Categories.Functor.Hom using (module Hom; Hom[_][_,-]; Hom[_][-,-])
open import Categories.Functor.Bifunctor using (Bifunctor)
-- open import Categories.Functor.Presheaf using (Presheaf)
open import Categories.Functor.Construction.LiftSetoids using (LiftSetoids)
open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper) renaming (id to idN)
open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism)
import Categories.Morphism as Mor
import Categories.Morphism.Reasoning as MR
import Categories.NaturalTransformation.Hom as NT-Hom
private
variable
o ℓ e : Level
module Yoneda (C : Category o ℓ e) where
open Category C hiding (op) -- uses lots
open HomReasoning using (_○_; ⟺)
open MR C using (id-comm)
open NaturalTransformation using (η; commute)
open NT-Hom C using (Hom[C,A]⇒Hom[C,B])
private
module CE = Category.Equiv C using (refl)
module C = Category C using (op)
-- The CoYoneda embedding functor
embed : Functor C.op (CoPresheaves C)
embed = record
{ F₀ = Hom[ C ][_,-]
; F₁ = Hom[C,A]⇒Hom[C,B] -- B⇒A induces a NatTrans on the Homs.
; identity = identityʳ ○_
; homomorphism = λ h₁≈h₂ → ∘-resp-≈ˡ h₁≈h₂ ○ sym-assoc
; F-resp-≈ = λ f≈g h≈i → ∘-resp-≈ h≈i f≈g
}
-- Using the adjunction between product and product, we get a kind of contravariant Bifunctor
yoneda-inverse : (a : Obj) (F : Functor C (Setoids ℓ e)) →
Inverse (Category.hom-setoid (CoPresheaves C) {Functor.F₀ embed a} {F}) (Functor.F₀ F a)
yoneda-inverse a F = record
{ f = λ nat → η nat a ⟨$⟩ id
; f⁻¹ = λ x → ntHelper record
{ η = λ X → record
{ _⟨$⟩_ = λ X⇒a → F.₁ X⇒a ⟨$⟩ x
; cong = λ i≈j → F.F-resp-≈ i≈j SE.refl
}
; commute = λ {X} {Y} X⇒Y {f} {g} f≈g →
let module SR = SetoidR (F.₀ Y) in
SR.begin
F.₁ (X⇒Y ∘ f ∘ id) ⟨$⟩ x SR.≈⟨ F.F-resp-≈ (∘-resp-≈ʳ (identityʳ ○ f≈g)) SE.refl ⟩
F.₁ (X⇒Y ∘ g) ⟨$⟩ x SR.≈⟨ F.homomorphism SE.refl ⟩
F.₁ X⇒Y ⟨$⟩ (F.₁ g ⟨$⟩ x)
SR.∎
}
; cong₁ = λ i≈j → i≈j CE.refl
; cong₂ = λ i≈j y≈z → F.F-resp-≈ y≈z i≈j
; inverse = (λ Fa → F.identity SE.refl) , λ nat {x} {z} {y} z≈y →
let module SR = SetoidR (F.₀ x) in
SR.begin
F.₁ z ⟨$⟩ (η nat a ⟨$⟩ id) SR.≈˘⟨ commute nat z (CE.refl {a}) ⟩
η nat x ⟨$⟩ z ∘ id ∘ id SR.≈⟨ cong (η nat x) (∘-resp-≈ʳ identity² ○ identityʳ ○ z≈y ) ⟩
η nat x ⟨$⟩ y
SR.∎
}
where
module F = Functor F using (₀; ₁; F-resp-≈; homomorphism; identity)
module SE = Setoid (F.₀ a) using (refl)
private
Nat[Hom[C][c,-],F] : Bifunctor (CoPresheaves C) C (Setoids (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e))
Nat[Hom[C][c,-],F] = Hom[ CoPresheaves C ][-,-] ∘F (Functor.op embed ∘F πʳ ※ πˡ)
FC : Bifunctor (CoPresheaves C) C (Setoids _ _)
FC = LiftSetoids (o ⊔ ℓ ⊔ e) (o ⊔ ℓ) ∘F eval {C = C} {D = Setoids ℓ e}
module yoneda-inverse {a} {F} = Inverse (yoneda-inverse a F)
-- the two bifunctors above are naturally isomorphic.
-- it is easy to show yoneda-inverse first then to yoneda.
yoneda : NaturalIsomorphism Nat[Hom[C][c,-],F] FC
yoneda = record
{ F⇒G = ntHelper record
{ η = λ where
(F , A) → record
{ _⟨$⟩_ = λ α → lift (yoneda-inverse.f α)
; cong = λ i≈j → lift (i≈j CE.refl)
}
; commute = λ where
{_} {G , B} (α , f) {β} {γ} β≈γ → lift $ cong (η α B) (helper f β γ β≈γ)
}
; F⇐G = ntHelper record
{ η = λ (F , A) → record
{ _⟨$⟩_ = λ x → yoneda-inverse.f⁻¹ (lower x)
; cong = λ i≈j y≈z → Functor.F-resp-≈ F y≈z (lower i≈j)
}
; commute = λ { {F , A} {G , B} (α , f) {X} {Y} eq {Z} {h} {i} eq′ → helper′ α f (lower eq) eq′}
}
; iso = λ (F , A) → record
{ isoˡ = λ {α β} i≈j {X} y≈z →
Setoid.trans (Functor.F₀ F X) ( yoneda-inverse.inverseʳ α {x = X} y≈z) (i≈j CE.refl)
; isoʳ = λ eq → lift (Setoid.trans (Functor.F₀ F A) ( yoneda-inverse.inverseˡ {F = F} _) (lower eq))
}
}
where helper : {F : Functor C (Setoids ℓ e)}
{A B : Obj} (f : A ⇒ B)
(β γ : NaturalTransformation Hom[ C ][ A ,-] F) →
Setoid._≈_ (Functor.F₀ Nat[Hom[C][c,-],F] (F , A)) β γ →
Setoid._≈_ (Functor.F₀ F B) (η β B ⟨$⟩ id ∘ f) (Functor.F₁ F f ⟨$⟩ (η γ A ⟨$⟩ id))
helper {F} {A} {B} f β γ β≈γ = S.begin
η β B ⟨$⟩ id ∘ f S.≈⟨ cong (η β B) (MR.id-comm-sym C ○ ∘-resp-≈ʳ (⟺ identity²)) ⟩
η β B ⟨$⟩ f ∘ id ∘ id S.≈⟨ commute β f CE.refl ⟩
F.₁ f ⟨$⟩ (η β A ⟨$⟩ id) S.≈⟨ cong (F.₁ f) (β≈γ CE.refl) ⟩
F.₁ f ⟨$⟩ (η γ A ⟨$⟩ id) S.∎
where
module F = Functor F using (₀;₁)
module S = SetoidR (F.₀ B)
helper′ : ∀ {F G : Functor C (Setoids ℓ e)}
{A B Z : Obj}
{h i : B ⇒ Z}
{X Y : Setoid.Carrier (Functor.F₀ F A)}
(α : NaturalTransformation F G)
(f : A ⇒ B) →
Setoid._≈_ (Functor.F₀ F A) X Y →
h ≈ i →
Setoid._≈_ (Functor.F₀ G Z) (Functor.F₁ G h ⟨$⟩ (η α B ⟨$⟩ (Functor.F₁ F f ⟨$⟩ X)))
(η α Z ⟨$⟩ (Functor.F₁ F (i ∘ f) ⟨$⟩ Y))
helper′ {F} {G} {A} {B} {Z} {h} {i} {X} {Y} α f eq eq′ = S.begin
G.₁ h ⟨$⟩ (η α B ⟨$⟩ (F.₁ f ⟨$⟩ X)) S.≈˘⟨ commute α h ((S′.sym (cong (F.₁ f) eq))) ⟩
η α Z ⟨$⟩ (F.₁ h ⟨$⟩ (F.₁ f ⟨$⟩ Y)) S.≈⟨ cong (η α Z) ((F.F-resp-≈ eq′ S′.refl)) ⟩
η α Z ⟨$⟩ (F.₁ i ⟨$⟩ (F.₁ f ⟨$⟩ Y)) S.≈˘⟨ cong (η α Z) ((F.homomorphism (Setoid.refl (F.₀ A)))) ⟩
η α Z ⟨$⟩ (F.₁ (i ∘ f) ⟨$⟩ Y) S.∎
where
module F = Functor F using (₀; ₁; homomorphism; F-resp-≈)
module G = Functor G using (₀; ₁)
module S = SetoidR (G.₀ Z)
module S′ = Setoid (F.₀ B) using (refl; sym)
module yoneda = NaturalIsomorphism yoneda
|
{
"alphanum_fraction": 0.53076165,
"avg_line_length": 44.6729559748,
"ext": "agda",
"hexsha": "6aa993ddc1ef03ef55b9effb693ae9f9a8fb4e41",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/CoYoneda.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/CoYoneda.agda",
"max_line_length": 110,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/CoYoneda.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 2693,
"size": 7103
}
|
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Equivalence
open import HoTT.Identity.Pi
module HoTT.Sigma.Universal where
Σ-univ : ∀ {i j k} {X : 𝒰 i} {A : X → 𝒰 j} (P : (x : X) → A x → 𝒰 k) →
((x : X) → Σ (A x) λ a → P x a) ≃
(Σ ((x : X) → A x) λ g → (x : X) → P x (g x))
Σ-univ _ = let open Iso in iso→eqv λ where
.f h → pr₁ ∘ h , pr₂ ∘ h
.g h x → pr₁ h x , pr₂ h x
.η h → funext (Σ-uniq ∘ h)
.ε h → Σ-uniq h
|
{
"alphanum_fraction": 0.5032679739,
"avg_line_length": 28.6875,
"ext": "agda",
"hexsha": "7653c2d906ab104359b85a05347d50ac531bee41",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Sigma/Universal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Sigma/Universal.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Sigma/Universal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 213,
"size": 459
}
|
module Function.Iteration.Proofs where
import Lvl
open import Functional
open import Function.Names as Names using (_⊜_)
open import Function.Iteration
open import Function.Proofs
open import Logic.Propositional
open import Logic.Predicate
open import Numeral.Natural
open import Numeral.Natural.Oper using (_+_ ; _⋅_ ; _𝄩_)
open import Numeral.Natural.Oper.Proofs
import Structure.Function.Names as Names
import Structure.Function
open import Structure.Operator.Properties
open import Structure.Operator.Proofs.Util
import Structure.Operator.Names as Names
import Structure.Operator
open import Structure.Relator.Properties
open import Structure.Function.Domain
open import Syntax.Transitivity
open import Type
private variable ℓ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₑ₄ : Lvl.Level
private variable T A B C X Y Z : Type{ℓ}
module _ where
open import Structure.Setoid
open Structure.Function
open Structure.Operator
module _ ⦃ equiv-X : Equiv{ℓₑ}(X) ⦄ where
-- Propositions that state something about arbitrary composed functions also apply to arbitrary function iterations of the first function.
[^]-from-[∘]-proof : ∀{ℓ₂}{P : (X → X) → Type{ℓ₂}} → (∀{f g : X → X} → P(f ∘ g)) → (∀{f : X → X}{n} → P(f ^ n))
[^]-from-[∘]-proof {P = P} p {f} {𝟎} = p{id}{id}
[^]-from-[∘]-proof {P = P} p {f} {𝐒 n} = p{f}{f ^ n}
[^]-function-raw : ∀{f : X → X} → Names.Congruence₁(f) → ∀{n} → Names.Congruence₁(f ^ n)
[^]-function-raw func-f {𝟎} xy = xy
[^]-function-raw func-f {𝐒(n)} xy = func-f([^]-function-raw func-f {n} xy)
-- Iterated function is a function when the function is.
[^]-function : ∀{f : X → X} → ⦃ func : Function(f) ⦄ → ∀{n} → Function(f ^ n)
Function.congruence ([^]-function ⦃ intro func-f ⦄ {n}) = [^]-function-raw func-f {n}
[^]-injective-raw : ∀{f : X → X} → Names.Injective(f) → ∀{n} → Names.Injective(f ^ n)
[^]-injective-raw inj-f {𝟎} fnxfny = fnxfny
[^]-injective-raw inj-f {𝐒(n)} fnxfny = [^]-injective-raw inj-f {n} (inj-f fnxfny)
-- Iterated function is injective when the function is.
[^]-injective : ∀{f : X → X} → ⦃ inj : Injective(f) ⦄ → ∀{n} → Injective(f ^ n)
Injective.proof ([^]-injective ⦃ intro inj-f ⦄ {n}) = [^]-injective-raw inj-f {n}
[^]-surjective-raw : ∀{f : X → X} → ⦃ func : Function(f) ⦄ → Names.Surjective(f) → ∀{n} → Names.Surjective(f ^ n)
[^]-surjective-raw surj-f {𝟎} {y} = [∃]-intro y ⦃ reflexivity(_≡_) ⦄
[^]-surjective-raw {f} surj-f {𝐒(n)} {y} = [∃]-map-proof (p ↦ (congruence₁(f) p) 🝖 [∃]-proof(surj-f {y})) ([^]-surjective-raw surj-f {n} {[∃]-witness(surj-f {y})})
-- Iterated function is surjective when the function is.
[^]-surjective : ∀{f : X → X} → ⦃ func : Function(f) ⦄ → ⦃ surj : Surjective(f) ⦄ → ∀{n} → Surjective(f ^ n)
Surjective.proof ([^]-surjective ⦃ _ ⦄ ⦃ intro surj-f ⦄ {n}) = [^]-surjective-raw surj-f {n}
-- Argument applied to the iterated function is one extra iteration.
-- Note: This implies: (f ^ n)(f x) ≡ f((f ^ n)(x))
[^]-inner-value : ∀{f : X → X} → ⦃ func : Function(f) ⦄ → ∀{x}{n} → ((f ^ n)(f x) ≡ (f ^ (𝐒(n)))(x))
[^]-inner-value {f} {x} {𝟎} = reflexivity(_≡_)
[^]-inner-value {f} {x} {𝐒 n} = congruence₁(f) ([^]-inner-value {f} {x} {n})
-- A fixpoint of the function is also a fixpoint of the iterated function.
[^]-of-fixpoint : ∀{f : X → X} → ⦃ func : Function(f) ⦄ → ∀{x : X} → ⦃ fix : Fixpoint f(x) ⦄ → ∀{n} → ((f ^ n)(x) ≡ x)
[^]-of-fixpoint {f} {x} {𝟎} = reflexivity(_≡_)
[^]-of-fixpoint {f} {x} {𝐒(n)} =
(f ^ 𝐒(n))(x) 🝖-[ reflexivity(_≡_) ]
(f ∘ (f ^ n))(x) 🝖-[ reflexivity(_≡_) ]
f((f ^ n)(x)) 🝖-[ congruence₁(f) ([^]-of-fixpoint {f} {x} {n}) ]
f(x) 🝖-[ fixpoint f(x) ]
x 🝖-end
module _ ⦃ equiv-XX : Equiv{ℓₑ}(X → X) ⦄ where
[^]-by-1 : ∀{f : X → X} → (f ^ 1 ≡ f)
[^]-by-1 {f} = reflexivity(_≡_)
[^]-of-id : ∀{n} → (id ^ n ≡ id)
[^]-of-id {𝟎} = reflexivity(_≡_)
[^]-of-id {𝐒 n} = [^]-of-id {n}
[^]-inner : ∀{f : X → X} → ⦃ _ : Function(f ∘_) ⦄ → ∀{n} → ((f ^ n) ∘ f ≡ f ^ (𝐒(n)))
[^]-inner {f} {𝟎} = reflexivity(_≡_)
[^]-inner {f} {𝐒 n} = congruence₁(f ∘_) ([^]-inner {f} {n})
[^]-add : ⦃ [∘]-op : BinaryOperator(_∘_) ⦄ → ∀{f : X → X} → ∀{a b} → ((f ^ a) ∘ (f ^ b) ≡ f ^ (a + b))
[^]-add {f} {𝟎} {𝟎} = reflexivity(_≡_)
[^]-add {f} {𝟎} {𝐒 b} = reflexivity(_≡_)
[^]-add {f} {𝐒 a} {𝟎} = reflexivity(_≡_)
[^]-add ⦃ [∘]-op ⦄ {f} {𝐒 a} {𝐒 b} =
(f ^ 𝐒(a)) ∘ (f ^ 𝐒(b)) 🝖-[ reflexivity(_≡_) ]
(f ^ 𝐒(a)) ∘ (f ∘ (f ^ b)) 🝖-[ reflexivity(_≡_) ]
((f ^ 𝐒(a)) ∘ f) ∘ (f ^ b) 🝖-[ congruence₂ₗ(_∘_)(f ^ b) ([^]-inner {f} ⦃ [≡]-congruence2-right(_∘_)(f) ⦄ {𝐒(a)}) ]
f ∘ ((f ^ 𝐒(a)) ∘ (f ^ b)) 🝖-[ reflexivity(_≡_) ]
(f ∘ (f ^ 𝐒(a))) ∘ (f ^ b) 🝖-[ congruence₂ᵣ(_∘_)(f) ([^]-add{f} {𝐒 a} {b}) ]
f ∘ (f ^ (𝐒(a) + b)) 🝖-[ reflexivity(_≡_) ]
f ^ (𝐒(a) + 𝐒(b)) 🝖-end
[^]-multiply : ⦃ [∘]-op : BinaryOperator(_∘_) ⦄ → ∀{f : X → X} → ∀{a b} → ((f ^ a) ^ b ≡ f ^ (a ⋅ b))
[^]-multiply ⦃ [∘]-op ⦄ {f} {𝟎} {𝟎} = reflexivity(_≡_)
[^]-multiply ⦃ [∘]-op ⦄ {f} {𝟎} {𝐒 b} = [^]-of-id {𝐒 b}
[^]-multiply ⦃ [∘]-op ⦄ {f} {𝐒 a} {𝟎} = reflexivity(_≡_)
[^]-multiply ⦃ [∘]-op ⦄ {f} {𝐒 a} {𝐒 b} =
(f ^ 𝐒(a)) ^ 𝐒(b) 🝖-[ reflexivity(_≡_) ]
(f ^ 𝐒(a)) ∘ ((f ^ 𝐒(a)) ^ b) 🝖-[ congruence₂ᵣ(_∘_)(f ^ 𝐒(a)) ([^]-multiply{f} {𝐒 a} {b}) ]
(f ^ 𝐒(a)) ∘ (f ^ (𝐒(a) ⋅ b)) 🝖-[ [^]-add {f} {𝐒(a)} {𝐒(a) ⋅ b} ]
f ^ (𝐒(a) + (𝐒(a) ⋅ b)) 🝖-[ reflexivity(_≡_) ]
f ^ (𝐒(a) ⋅ 𝐒(b)) 🝖-end
[^]-distanceₗ : ⦃ [∘]-op : BinaryOperator(_∘_) ⦄ → ∀{f : X → X}{a b} → (f ^ a ≡ f ^ b) ← (f ^ (a 𝄩 b) ≡ id)
[^]-distanceₗ {f} {𝟎} {𝟎} = id
[^]-distanceₗ {f} {𝟎} {𝐒 b} = symmetry(_≡_)
[^]-distanceₗ {f} {𝐒 a} {𝟎} = id
[^]-distanceₗ {f} {𝐒 a} {𝐒 b} = congruence₂ᵣ(_∘_)(f) ∘ ([^]-distanceₗ {f} {a} {b})
[^]-distanceᵣ : ⦃ [∘]-op : BinaryOperator(_∘_) ⦄ → ⦃ [∘]-cancₗ : Cancellationₗ(_∘_) ⦄ → ∀{f : X → X}{a b} → (f ^ a ≡ f ^ b) → (f ^ (a 𝄩 b) ≡ id)
[^]-distanceᵣ {f} {𝟎} {𝟎} = id
[^]-distanceᵣ {f} {𝟎} {𝐒 b} = symmetry(_≡_)
[^]-distanceᵣ {f} {𝐒 a} {𝟎} = id
[^]-distanceᵣ {f} {𝐒 a} {𝐒 b} p = [^]-distanceᵣ {f} {a} {b} (cancellationₗ(_∘_) {f} p)
module _ ⦃ op : BinaryOperator(_∘_) ⦄ ⦃ assoc : Associativity(_∘_) ⦄ where
[^]-commuting : ∀{f g : X → X} → Names.Commuting(_∘_)(f)(g) → ∀{a b} → Names.Commuting(_∘_)(f ^ a)(g ^ b)
[^]-commuting {f} {g} com {𝟎} {𝟎} = reflexivity(_≡_)
[^]-commuting {f} {g} com {𝟎} {𝐒 b} = reflexivity(_≡_)
[^]-commuting {f} {g} com {𝐒 a} {𝟎} = reflexivity(_≡_)
[^]-commuting {f} {g} com {𝐒 a} {𝐒 b} =
(f ^ 𝐒(a)) ∘ (g ^ 𝐒(b)) 🝖-[ reflexivity(_≡_) ]
(f ∘ (f ^ a)) ∘ (g ∘ (g ^ b)) 🝖-[ One.associate-commute4 {a = f} {f ^ a} {g} {g ^ b} ([^]-commuting {f} {g} com {a} {1}) ]
(f ∘ g) ∘ ((f ^ a) ∘ (g ^ b)) 🝖-[ congruence₂(_∘_) com ([^]-commuting {f} {g} com {a} {b}) ]
(g ∘ f) ∘ ((g ^ b) ∘ (f ^ a)) 🝖-[ One.associate-commute4 {a = g} {f} {g ^ b} {f ^ a} ([^]-commuting {f} {g} com {1} {b}) ]
(g ∘ (g ^ b)) ∘ (f ∘ (f ^ a)) 🝖-[ reflexivity(_≡_) ]
(g ^ 𝐒(b)) ∘ (f ^ 𝐒(a)) 🝖-end
[^]-of-[∘] : ∀{f : X → X}{g : X → X} → Names.Commuting(_∘_)(f)(g) → ∀{n} → ((f ∘ g) ^ n ≡ (f ^ n) ∘ (g ^ n))
[^]-of-[∘] {f}{g} com {𝟎} = reflexivity(_≡_)
[^]-of-[∘] {f}{g} com {𝐒 n} =
(f ∘ g) ^ 𝐒(n) 🝖-[ reflexivity(_≡_) ]
(f ∘ g) ∘ ((f ∘ g) ^ n) 🝖-[ congruence₂ᵣ(_∘_)(f ∘ g) ([^]-of-[∘] {f}{g} com {n}) ]
(f ∘ g) ∘ ((f ^ n) ∘ (g ^ n)) 🝖-[ One.associate-commute4 {a = f} {g} {f ^ n}{g ^ n} (symmetry(_≡_) ([^]-commuting {f} {g} com {n} {1})) ]
(f ∘ (f ^ n)) ∘ (g ∘ (g ^ n)) 🝖-[ reflexivity(_≡_) ]
(f ^ 𝐒(n)) ∘ (g ^ 𝐒(n)) 🝖-end
module _ {ℓ₁}{ℓ₂} {X : Type{ℓ₁}} ⦃ equiv-x : Equiv{ℓₑ₁}(X) ⦄ {Y : Type{ℓ₂}} ⦃ equiv-y : Equiv{ℓₑ₂}(Y) ⦄ where
private variable n : ℕ
private variable x : X
private variable init : Y
repeatᵣₗ-flip-equality : ∀{_▫_ : Y → X → Y} → ⦃ op : BinaryOperator(_▫_) ⦄ → (repeatᵣ n (swap(_▫_)) x init ≡ repeatₗ n (_▫_) init x)
repeatᵣₗ-flip-equality {n = 𝟎} = reflexivity(_≡_)
repeatᵣₗ-flip-equality {n = 𝐒(n)}{x = x}{_▫_ = _▫_} = congruence₂ₗ(_▫_)(x) (repeatᵣₗ-flip-equality {n = n}{_▫_ = _▫_})
repeatₗᵣ-flip-equality : ∀{_▫_ : X → Y → Y} → ⦃ op : BinaryOperator(_▫_) ⦄ → (repeatₗ n (swap _▫_) init x ≡ repeatᵣ n (_▫_) x init)
repeatₗᵣ-flip-equality {n = n}{init = init}{x = x}{_▫_ = _▫_} = symmetry(_≡_) (repeatᵣₗ-flip-equality {n = n}{x = x}{init = init}{_▫_ = swap(_▫_)} ⦃ op = swap-binaryOperator ⦄)
module _ ⦃ equiv-X : Equiv{ℓₑ}(X) ⦄ where
private variable f : X → X
private variable _▫_ : X → X → X
private variable x elem init : X
private variable n : ℕ
[^]-from-repeatᵣ-alt : ⦃ func : Function(f) ⦄ → ((f ^ n) ⊜ repeatᵣ(n) (f ∘_) id)
[^]-from-repeatᵣ-alt {n = 𝟎} = reflexivity(_≡_)
[^]-from-repeatᵣ-alt {f}{n = 𝐒 n} = congruence₁(f) ([^]-from-repeatᵣ-alt {n = n})
[^]-from-repeatᵣ : ⦃ func : Function(f) ⦄ → ((f ^ n) ⊜ repeatᵣ(n) (_∘_) f id)
[^]-from-repeatᵣ {n = 𝟎} = reflexivity(_≡_)
[^]-from-repeatᵣ {f}{n = 𝐒 n} = congruence₁(f) ([^]-from-repeatᵣ {f}{n = n})
-- TODO: Should also be provable using associativity? Prove (CommutingOn(_▫_)(x)(x) → AssociativityOn(_▫_)(x)). Is this helping?
repeat-swap-side : ⦃ op : BinaryOperator(_▫_) ⦄ ⦃ comm : Commutativity(_▫_) ⦄ → (repeatₗ n (_▫_) x x ≡ repeatᵣ n (_▫_) x x)
repeat-swap-side {n = 𝟎} = reflexivity(_≡_)
repeat-swap-side {_▫_ = _▫_}{n = 𝐒 n}{x} = congruence₂ₗ(_▫_)(x) (repeat-swap-side {n = n}) 🝖 commutativity(_▫_)
repeat-swap-side-by-associativity : ⦃ op : BinaryOperator(_▫_) ⦄ ⦃ _ : Associativity(_▫_) ⦄ → (repeatₗ n (_▫_) x x ≡ repeatᵣ n (_▫_) x x)
repeat-swap-side-by-associativity {n = 𝟎} = reflexivity(_≡_)
repeat-swap-side-by-associativity {n = 𝐒 𝟎} {x} = reflexivity(_≡_)
repeat-swap-side-by-associativity {_▫_ = _▫_} {n = 𝐒(𝐒 n)}{x} =
repeatₗ (𝐒(𝐒(n))) (_▫_) x x 🝖[ _≡_ ]-[]
repeatₗ (𝐒(n)) (_▫_) x x ▫ x 🝖[ _≡_ ]-[ congruence₂ₗ(_▫_)(x) (repeat-swap-side-by-associativity {n = 𝐒 n}) ]
repeatᵣ (𝐒(n)) (_▫_) x x ▫ x 🝖[ _≡_ ]-[]
(x ▫ repeatᵣ n (_▫_) x x) ▫ x 🝖[ _≡_ ]-[ associativity(_▫_) ]
x ▫ (repeatᵣ n (_▫_) x x ▫ x) 🝖[ _≡_ ]-[ congruence₂ᵣ(_▫_)(x) (congruence₂ₗ(_▫_)(x) (repeat-swap-side-by-associativity {n = n})) ]-sym
x ▫ (repeatₗ n (_▫_) x x ▫ x) 🝖[ _≡_ ]-[]
x ▫ repeatₗ (𝐒(n)) (_▫_) x x 🝖[ _≡_ ]-[ congruence₂ᵣ(_▫_)(x) (repeat-swap-side-by-associativity {n = 𝐒(n)}) ]
x ▫ repeatᵣ (𝐒(n)) (_▫_) x x 🝖[ _≡_ ]-[]
repeatᵣ (𝐒(𝐒(n))) (_▫_) x x 🝖[ _≡_ ]-end
repeat-with-id-swap-side : ⦃ op : BinaryOperator(_▫_) ⦄ ⦃ comm : Commutativity(_▫_) ⦄ ⦃ ident : Identity(_▫_)(init) ⦄ → (repeatₗ n (_▫_) init x ≡ repeatᵣ n (_▫_) x init)
repeat-with-id-swap-side {n = 𝟎} = reflexivity(_≡_)
repeat-with-id-swap-side {_▫_ = _▫_}{n = 𝐒 n}{x = x} = congruence₂ₗ(_▫_)(x) (repeat-with-id-swap-side {n = n}) 🝖 commutativity(_▫_)
repeat-raise-equality : ⦃ op : BinaryOperator(_▫_) ⦄ → (repeatᵣ n (_▫_) elem (x) ≡ ((elem ▫_) ^ n)(x))
repeat-raise-equality {n = 𝟎} = reflexivity(_≡_)
repeat-raise-equality{_▫_ = _▫_}{n = 𝐒(n)}{elem}{x} = congruence₂ᵣ(_▫_)(elem) (repeat-raise-equality{_▫_ = _▫_}{n = n}{elem}{x})
module _ {X : Type{ℓ}} where
open import Relator.Equals
open import Relator.Equals.Proofs
raise-repeat-equality : ∀{n : ℕ}{f : X → X} → (f ^ n ≡ repeatᵣ n (_∘_) f id)
raise-repeat-equality{𝟎} = reflexivity(_≡_)
raise-repeat-equality{𝐒(n)}{f} = [≡]-with(f ∘_) (raise-repeat-equality{n}{f})
module _ where
open import Structure.Setoid
open Structure.Function
open Structure.Operator
module _ ⦃ equiv-X : Equiv{ℓₑ}(X) ⦄ where
repeatₗ-by-0 : ∀{_▫_ : X → X → X}{x id} → ⦃ _ : Identityᵣ(_▫_)(id) ⦄ → (repeatᵣ 0 (_▫_) x id ≡ id)
repeatₗ-by-0 {_▫_} {x}{id} ⦃ identᵣ ⦄ = reflexivity(_≡_)
repeatₗ-by-1 : ∀{_▫_ : X → X → X}{x id} → ⦃ _ : Identityᵣ(_▫_)(id) ⦄ → (repeatᵣ 1 (_▫_) x id ≡ x)
repeatₗ-by-1 {_▫_} {x}{id} ⦃ identᵣ ⦄ = identityᵣ(_▫_)(id)
repeatₗ-by-sum : ∀{_▫_ : X → X → X}{x id} → ⦃ _ : BinaryOperator(_▫_) ⦄ → ⦃ _ : Identityᵣ(_▫_)(id) ⦄ → ⦃ _ : Associativity(_▫_) ⦄ → ∀{a b} → ((repeatₗ a (_▫_) id x) ▫ (repeatₗ b (_▫_) id x) ≡ repeatₗ (a + b) (_▫_) id x)
repeatₗ-by-sum {_▫_} {x} {id} ⦃ identᵣ ⦄ {a} {𝟎} =
(repeatₗ a (_▫_) id x) ▫ (repeatₗ 𝟎 (_▫_) id x) 🝖-[ reflexivity(_≡_) ]
(repeatₗ a (_▫_) id x) ▫ id 🝖-[ identityᵣ(_▫_)(id) ]
repeatₗ a (_▫_) id x 🝖-[ reflexivity(_≡_) ]
repeatₗ (a + 𝟎) (_▫_) id x 🝖-end
repeatₗ-by-sum {_▫_} {x} {id} ⦃ identᵣ ⦄ {a} {𝐒 b} =
(repeatₗ a (_▫_) id x) ▫ (repeatₗ (𝐒(b)) (_▫_) id x) 🝖-[ reflexivity(_≡_) ]
(repeatₗ a (_▫_) id x) ▫ ((repeatₗ b (_▫_) id x) ▫ x) 🝖-[ symmetry(_≡_) (associativity(_▫_)) ]
((repeatₗ a (_▫_) id x) ▫ (repeatₗ b (_▫_) id x)) ▫ x 🝖-[ congruence₂ₗ(_▫_)(_) (repeatₗ-by-sum{a = a}{b = b}) ]
(repeatₗ (a + b) (_▫_) id x) ▫ x 🝖-[ reflexivity(_≡_) ]
repeatₗ (a + 𝐒(b)) (_▫_) id x 🝖-end
repeatₗ-by-product : ∀{_▫_ : X → X → X}{x id} → ⦃ _ : BinaryOperator(_▫_) ⦄ → ⦃ _ : Identityᵣ(_▫_)(id) ⦄ → ⦃ _ : Associativity(_▫_) ⦄ → ∀{a b} → (repeatₗ b (_▫_) id ((repeatₗ a (_▫_) id x)) ≡ repeatₗ (a ⋅ b) (_▫_) id x)
repeatₗ-by-product {_▫_} {x} {id} ⦃ identᵣ ⦄ {a} {𝟎} =
repeatₗ 𝟎 (_▫_) id ((repeatₗ a (_▫_) id x)) 🝖-[ reflexivity(_≡_) ]
repeatₗ (a ⋅ 𝟎) (_▫_) id x 🝖-end
repeatₗ-by-product {_▫_} {x} {id} ⦃ identᵣ ⦄ {a} {𝐒 b} =
repeatₗ (𝐒(b)) (_▫_) id ((repeatₗ a (_▫_) id x)) 🝖-[ reflexivity(_≡_) ]
(repeatₗ b (_▫_) id ((repeatₗ a (_▫_) id x))) ▫ (repeatₗ a (_▫_) id x) 🝖-[ congruence₂ₗ(_▫_)(_) (repeatₗ-by-product{a = a}{b = b}) ]
(repeatₗ (a ⋅ b) (_▫_) id x) ▫ (repeatₗ a (_▫_) id x) 🝖-[ repeatₗ-by-sum {a = a ⋅ b}{a} ]
repeatₗ ((a ⋅ b) + a) (_▫_) id x 🝖-[ [≡]-to-equivalence (congruence₁(expr ↦ repeatₗ expr (_▫_) id x) {a ⋅ b + a}{a + a ⋅ b} (commutativity(_+_) {a ⋅ b})) ]
repeatₗ (a ⋅ 𝐒(b)) (_▫_) id x 🝖-end
where
open import Relator.Equals.Proofs.Equiv using ([≡]-to-equivalence)
repeatₗ-by-distanceₗ : ∀{_▫_ : X → X → X}{x id} → ⦃ _ : BinaryOperator(_▫_) ⦄ → ⦃ _ : Identityᵣ(_▫_)(id) ⦄ → ⦃ _ : Associativity(_▫_) ⦄ → ∀{a b} → (repeatₗ a (_▫_) id x ≡ repeatₗ b (_▫_) id x) ← (repeatₗ (a 𝄩 b) (_▫_) id x ≡ id)
repeatₗ-by-distanceₗ {_▫_} {x} {id} {𝟎} {𝟎} p = p
repeatₗ-by-distanceₗ {_▫_} {x} {id} {𝟎} {𝐒 b} p = symmetry(_≡_) p
repeatₗ-by-distanceₗ {_▫_} {x} {id} {𝐒 a} {𝟎} p = p
repeatₗ-by-distanceₗ {_▫_} {x} {id} {𝐒 a} {𝐒 b} p = congruence₂ₗ(_▫_)(_) (repeatₗ-by-distanceₗ {_▫_} {x} {id} {a} {b} p)
repeatₗ-by-distanceᵣ : ∀{_▫_ : X → X → X}{x id} → ⦃ _ : BinaryOperator(_▫_) ⦄ → ⦃ _ : Identityᵣ(_▫_)(id) ⦄ → ⦃ _ : Associativity(_▫_) ⦄ → ⦃ cancᵣ : Cancellationᵣ(_▫_) ⦄ → ∀{a b} → (repeatₗ a (_▫_) id x ≡ repeatₗ b (_▫_) id x) → (repeatₗ (a 𝄩 b) (_▫_) id x ≡ id)
repeatₗ-by-distanceᵣ {_▫_} {x} {id} {𝟎} {𝟎} p = p
repeatₗ-by-distanceᵣ {_▫_} {x} {id} {𝟎} {𝐒 b} p = symmetry(_≡_) p
repeatₗ-by-distanceᵣ {_▫_} {x} {id} {𝐒 a} {𝟎} p = p
repeatₗ-by-distanceᵣ {_▫_} {x} {id} {𝐒 a} {𝐒 b} p = repeatₗ-by-distanceᵣ {_▫_} {x} {id} {a} {b} (cancellationᵣ(_▫_) {x} p)
|
{
"alphanum_fraction": 0.4910742446,
"avg_line_length": 61.2084942085,
"ext": "agda",
"hexsha": "6222abf5579673f94fe073185babf3f418396fc7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Function/Iteration/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Function/Iteration/Proofs.agda",
"max_line_length": 265,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Function/Iteration/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 7576,
"size": 15853
}
|
module Vec where
open import Star
open import Nat
data Step (A : Set) : Nat -> Nat -> Set where
step : (x : A){n : Nat} -> Step A (suc n) n
Vec : (A : Set) -> Nat -> Set
Vec A n = Star (Step A) n zero
[] : {A : Set} -> Vec A zero
[] = ε
_::_ : {A : Set}{n : Nat} -> A -> Vec A n -> Vec A (suc n)
x :: xs = step x • xs
_+++_ : {A : Set}{n m : Nat} -> Vec A n -> Vec A m -> Vec A (n + m)
_+++_ {A}{m = m} xs ys = map +m step+m xs ++ ys
where
+m = \z -> z + m
step+m : Step A =[ +m ]=> Step A
step+m (step x) = step x
vec : {A : Set}{n : Nat} -> A -> Vec A n
vec {n = ε} x = []
vec {n = _ • n} x = x :: vec x
_⊗_ : {A B : Set}{n : Nat} -> Vec (A -> B) n -> Vec A n -> Vec B n
ε ⊗ ε = []
(step f • fs) ⊗ (step x • xs) = f x :: (fs ⊗ xs)
ε ⊗ (() • _)
{- Some proof about _-_ needed...
vreverse : {A : Set}{n : Nat} -> Vec A n -> Vec A n
vreverse {A}{n} xs = {! !} -- map i f (reverse xs)
where
i : Nat -> Nat
i m = n - m
f : Step A op =[ i ]=> Step A
f (step x) = {! !} -- step x
-}
|
{
"alphanum_fraction": 0.4289746002,
"avg_line_length": 23.6222222222,
"ext": "agda",
"hexsha": "2585f460b73926fc88d2a8519873e79b08b54ddc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/AIM6/Path/Vec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/AIM6/Path/Vec.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/AIM6/Path/Vec.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 427,
"size": 1063
}
|
module sv20.exam2 where
-------------------------- FIRST TASK PREPARATION CODE --------------------------
open import Data.Unit using (⊤; tt)
open import Data.Product using (_×_ ; ∃) renaming (_,_ to ⟨_,_⟩)
open import Relation.Nullary using (¬_)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function using (_∘_)
import Relation.Binary.PropositionalEquality as Eq
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _≡˘⟨_⟩_; _∎)
open Eq using (_≡_; refl; cong; sym; trans)
Subset : (A : Set) -> Set _
Subset A = A → Set
_∈_ : ∀ {A} → A → Subset A → Set
a ∈ P = P a
Relation : ∀ A B → Set₁
Relation A B = Subset (A × B)
Range : ∀ {A B} → Relation A B → Subset B
Range R b = ∃ (R ∘ ⟨_, b ⟩) -- equivalent to ∃ \a → R ⟨ a , b ⟩
Dom : ∀ {A B} → Relation A B → Subset A
Dom R a = ∃ (R ∘ ⟨ a ,_⟩) -- equivalent to ∃ \b → R ⟨ a , b ⟩
_⊆_ : ∀ {A} → Subset A → Subset A → Set
A ⊆ B = ∀ x → x ∈ A → x ∈ B
_∩_ : ∀ {A} → Subset A → Subset A → Subset A
A ∩ B = λ x → x ∈ A × x ∈ B
_∪_ : ∀ {A} → Subset A → Subset A → Subset A
A ∪ B = λ x → x ∈ A ⊎ x ∈ B
_/_ : ∀ {A} → Subset A → Subset A → Subset A
A / B = λ x → x ∈ A × ¬ (x ∈ B)
postulate
⊆→≡ : ∀ {a} {A B : Subset a} → A ⊆ B → B ⊆ A → A ≡ B
-------------------------- Solution to TASK 1 --------------------------
diff-theorem-3 : ∀ {a} {A B : Subset a}
→ (A / (A ∩ B)) ≡ (A / B)
-- The proof is divided in two parts, forwards (right contained in left) and
-- backwards (left contained in right)
diff-theorem-3 = ⊆→≡ diff-theorem-3→ diff-theorem-3←
where
diff-theorem-3→ : ∀ {a} {A B : Subset a}
→ (A / (A ∩ B)) ⊆ (A / B)
diff-theorem-3→ x x∈A/A∩B = -- Given an x such that `x ∈ (A / (A ∩ B))`
let
⟨ x∈A , ¬x∈A∩B ⟩ = x∈A/A∩B -- (1) By def. of diff, we have that `x ∈ A` and `¬ x ∈ A ∩ B`
¬x∈B = -- (2) Proof by contradiction that ¬ x ∈ B
λ{ x∈B → -- (a) Suppose `x ∈ B`
let x∈A∩B = ⟨ x∈A , x∈B ⟩ -- (b) then by def. of ∩ and (1) (a), we have that `x ∈ A ∩ B`
in ¬x∈A∩B x∈A∩B } -- Contradiction `x ∈ A ∩ B` (b) and `¬ x ∈ A ∩ B` (1).
x∈A/B = ⟨ x∈A , ¬x∈B ⟩ -- From (1), (2) and by def. of /, we have that `x ∈ A / B`
in x∈A/B -- QED
--Proof without comments
--diff-theorem-3→ x ⟨ x∈A , ¬x∈A∩B ⟩ = ⟨ x∈A , (λ{x∈B → ¬x∈A∩B ⟨ x∈A , x∈B ⟩}) ⟩
diff-theorem-3← : ∀ {a} {A B : Subset a}
→ (A / B) ⊆ (A / (A ∩ B))
diff-theorem-3← x x∈A/B = -- Given an x such that `x ∈ A / B`
let
⟨ x∈A , ¬x∈B ⟩ = x∈A/B -- (1) By def. of diff, we have that `x ∈ A` and `¬ x ∈ B`
¬x∈A∩B = -- (2) Proof by contradiction that `¬ x ∈ A ∩ B`
λ{ x∈A∩B → -- (a) Suppose `x ∈ A ∩ B`
let ⟨ x∈A , x∈B ⟩ = x∈A∩B -- (b) then by def. of ∩, we have that `x ∈ A` and `x ∈ B`
in ¬x∈B x∈B } -- Contraduction `x ∈ B` (b) and `¬ x ∈ B` (1)
x∈A/A∩B = ⟨ x∈A , ¬x∈A∩B ⟩ -- From (1), (2) and by the def. of /, `x ∈ (A / (A ∩ B))`
in x∈A/A∩B -- QED
--Proof without comments
--diff-theorem-3← x ⟨ x∈A , ¬x∈B ⟩ = ⟨ x∈A , (λ{⟨ x∈A , x∈B ⟩ → ¬x∈B x∈B}) ⟩
-- This might be another way to prove it, it still seems to require some postulate to work
--diff-theorem-3` : ∀ {a} {A B : Subset a}
-- (y : a)
-- → y ∈ (A / (A ∩ B)) ≡ y ∈ (A / B)
---- The proof is divided in two parts, forwards (right contained in left) and
---- backwards (left contained in right)
--diff-theorem-3` {_} {A} {B} y =
-- begin
-- y ∈ (A / (A ∩ B))
-- ≡⟨⟩
-- (A / (A ∩ B)) y
-- ≡⟨⟩
-- (A y × ¬ (A y × B y))
-- ≡⟨ cong (A y ×_) ? ⟩
-- (A y × ¬ (B y))
-- ≡⟨⟩
-- (A / B) y
-- ≡⟨⟩
-- y ∈ (A / B)
-- ∎
-------------------------- END FIRST TASK --------------------------
-------------------------- SECOND TASK PREPARATION CODE --------------------------
open import Data.List using (List; []; _∷_; _++_; length; reverse; map; foldr; downFrom; foldl)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_)
open import Data.Nat.Properties using (*-identityʳ; +-identityʳ; *-assoc)
pattern [_] z = z ∷ []
product : List ℕ → ℕ
product [] = 1
product (n ∷ ns) = n * product ns
-------------------------- Solution to TASK 2 --------------------------
of-singleton : ∀ (n : ℕ) → product [ n ] ≡ n
of-singleton n =
begin
product [ n ] ≡⟨⟩
product (n ∷ []) ≡⟨⟩
n * product [] ≡⟨⟩
n * 1 ≡⟨ *-identityʳ n ⟩
n
∎
of-join : ∀ (ms ns : List ℕ)
→ product (ms ++ ns) ≡ (product ms) * (product ns)
of-join [] ns =
begin
product ([] ++ ns) ≡⟨⟩
product ns ≡˘⟨ +-identityʳ (product ns) ⟩ -- product ns ≡ 1 * product ns
1 * product ns ≡⟨⟩
product [] * product ns
∎
of-join (m ∷ ms) ns =
begin
product ((m ∷ ms) ++ ns) ≡⟨⟩
product (m ∷ (ms ++ ns)) ≡⟨⟩
m * product (ms ++ ns) ≡⟨ cong (m *_) (of-join ms ns) ⟩ -- product (ms ++ ns) ≡ product ms * product ns
m * (product ms * product ns) ≡˘⟨ *-assoc m (product ms) (product ns) ⟩ -- * associativity
(m * product ms) * product ns ≡⟨⟩
product (m ∷ ms) * product ns
∎
-------------------------- END SECOND TASK --------------------------
|
{
"alphanum_fraction": 0.4278890318,
"avg_line_length": 37.2808219178,
"ext": "agda",
"hexsha": "c03099953659714a1eef1c5c66f5a682751f97af",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "helq/old_code",
"max_forks_repo_path": "proglangs-learning/Agda/sv20/exam2.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z",
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "helq/old_code",
"max_issues_repo_path": "proglangs-learning/Agda/sv20/exam2.agda",
"max_line_length": 116,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "helq/old_code",
"max_stars_repo_path": "proglangs-learning/Agda/sv20/exam2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2109,
"size": 5443
}
|
------------------------------------------------------------------------
-- A parser for PBM images; illustrates "essential" use of bind
------------------------------------------------------------------------
-- Note that I am using the simple "Plain PBM" format, and I try to
-- adhere to the following statement from the pbm man page:
--
-- "Programs that read this format should be as lenient as possible,
-- accepting anything that looks remotely like a bitmap."
-- I got the idea to write this particular parser from "The Power of
-- Pi" by Oury and Swierstra.
module TotalParserCombinators.Examples.PBM where
open import Data.Bool
open import Data.Char as Char using (Char; _==_)
open import Data.List as List using (List)
open import Data.Maybe hiding (_>>=_)
open import Data.Nat hiding (_^_)
import Data.Nat.Show as ℕ
open import Data.String as String
using (String) renaming (_++_ to _<+>_)
open import Data.Unit
open import Data.Vec as Vec using (Vec; _++_; [_])
open import Function
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import TotalParserCombinators.BreadthFirst
open import TotalParserCombinators.Lib
open import TotalParserCombinators.Parser
open Token Char Char._≟_
------------------------------------------------------------------------
-- PBM images
module PBM where
-- Colours.
data Colour : Set where
white : Colour
black : Colour
-- Matrices.
Matrix : Set → ℕ → ℕ → Set
Matrix A rows cols = Vec (Vec A cols) rows
-- PBM images.
record PBM : Set where
constructor toPBM
field
{rows cols} : ℕ
matrix : Matrix Colour rows cols
open PBM public
-- Showing PBM images.
showColour : Colour → Char
showColour white = '0'
showColour black = '1'
show : PBM → String
show i = "P1\n" <+>
ℕ.show (cols i) <+> " " <+> ℕ.show (rows i) <+> "\n" <+>
showMatrix (matrix i)
where
showMatrix = String.fromList ∘
Vec.toList ∘
Vec.concat ∘
Vec.map ((λ xs → xs ++ [ '\n' ]) ∘ Vec.map showColour)
open PBM
------------------------------------------------------------------------
-- Parsing PBM images
comment : Parser Char ⊤ _
comment =
tok '#' >>= λ _ →
sat′ (not ∘ _==_ '\n') ⋆ >>= λ _ →
tok '\n' >>= λ _ →
return tt
colour : Parser Char Colour _
colour = const white <$> tok '0'
∣ const black <$> tok '1'
pbm : Parser Char PBM _
pbm =
w∣c ⋆ >>= λ _ →
tok 'P' >>= λ _ → tok '1' >>= λ _ →
w∣c ⋆ >>= λ _ →
number >>= λ cols →
w∣c + >>= λ _ →
number >>= λ rows →
w∣c >>= λ _ →
(w∣c ⋆ >>= λ _ → colour) ^ cols ^ rows >>= λ m →
token ⋆ >>= λ _ →
return (toPBM m)
where
w∣c = whitespace ∣ comment
-- The example is commented out, because it takes ages to run this
-- parser.
-- module Example where
-- open Vec.Vec
-- image = toPBM ((white ∷ black ∷ []) ∷
-- (black ∷ white ∷ []) ∷
-- (black ∷ black ∷ []) ∷ [])
-- ex : parse pbm (String.toList $ show image) ≡ List.[_] image
-- ex = P.refl
|
{
"alphanum_fraction": 0.5032816229,
"avg_line_length": 27.7024793388,
"ext": "agda",
"hexsha": "47c9303c339afe0f49cccde2df35fa8f47c18ac0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "TotalParserCombinators/Examples/PBM.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "TotalParserCombinators/Examples/PBM.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "TotalParserCombinators/Examples/PBM.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 863,
"size": 3352
}
|
module L where
open import Data.Nat using (ℕ; suc) -- ; _*_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong; sym; trans)
open import Data.Product
open import Data.Empty
-- Recursion principle
recℕ : (C : Set) → C → (ℕ → C → C) → ℕ → C
recℕ C c f 0 = c
recℕ C c f (suc n) = f n (recℕ C c f n)
double : ℕ → ℕ
double = recℕ ℕ 0 (λ n r → suc (suc r))
add : ℕ → ℕ → ℕ
add = recℕ (ℕ → ℕ) (λ n → n) (λ m r → λ n → suc (r n))
-- fact : ℕ → ℕ
-- fact = recℕ ℕ 1 (λ n r → suc n * r)
-- Induction principle
indℕ : (C : ℕ → Set) → C 0 → ((n : ℕ) → C n → C (suc n)) → (n : ℕ) → C n
indℕ C c f 0 = c
indℕ C c f (suc n) = f n (indℕ C c f n)
add-assoc : (i j k : ℕ) → add i (add j k) ≡ add (add i j) k
add-assoc = indℕ
(λ i → (j k : ℕ) → add i (add j k) ≡ add (add i j) k)
(λ j k → refl)
(λ i i+[j+k]≡[i+j]+k j k → cong suc (i+[j+k]≡[i+j]+k j k))
add-right-unit : (i : ℕ) → add i 0 ≡ i
add-right-unit = indℕ (λ i → add i 0 ≡ i) refl (λ i i+0≡i → cong suc i+0≡i)
add-suc : (i j : ℕ) → suc (add i j) ≡ add i (suc j)
add-suc = indℕ (λ i → (j : ℕ) → suc (add i j) ≡ add i (suc j))
(λ j → refl)
(λ i s[i+j]≡i+s[j] j → cong suc (s[i+j]≡i+s[j] j))
add-comm : (i j : ℕ) → add i j ≡ add j i
add-comm = indℕ
(λ i → (j : ℕ) → add i j ≡ add j i)
(λ j → sym (add-right-unit j))
(λ i i+j≡j+i j → trans (cong suc (i+j≡j+i j)) (add-suc j i))
-- Some type definitions
_≤_ : (i j : ℕ) → Set
i ≤ j = Σ[ k ∈ ℕ ] (add i k ≡ j)
i≤i+j : (i j : ℕ) → i ≤ add i j
i≤i+j = indℕ
(λ i → (j : ℕ) → i ≤ add i j)
(λ j → (j , refl))
(λ i i≤i+j j → (j , refl))
¬ : Set → Set
¬ A = A → ⊥
_<_ : (i j : ℕ) → Set
i < j = (i ≤ j) × ¬ (i ≡ j)
0≠si : (i : ℕ) → ¬ (0 ≡ suc i)
0≠si i = λ ()
0< : (i : ℕ) → (0 < suc i)
0< = indℕ (λ i → 0 < suc i)
{!!}
{!!}
|
{
"alphanum_fraction": 0.440333507,
"avg_line_length": 25.9324324324,
"ext": "agda",
"hexsha": "765fbf2afa4edf6d542731ec0082d2f1b1c68024",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b05c58ffdaed99932ca2acc632deca8d14742b04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andmkent/misc-HoTT",
"max_forks_repo_path": "L.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b05c58ffdaed99932ca2acc632deca8d14742b04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andmkent/misc-HoTT",
"max_issues_repo_path": "L.agda",
"max_line_length": 85,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "b05c58ffdaed99932ca2acc632deca8d14742b04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andmkent/misc-HoTT",
"max_stars_repo_path": "L.agda",
"max_stars_repo_stars_event_max_datetime": "2016-01-26T18:17:16.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-01-26T18:17:16.000Z",
"num_tokens": 860,
"size": 1919
}
|
open import MLib.Algebra.PropertyCode
open import MLib.Algebra.PropertyCode.Structures
module MLib.Matrix.Tensor {c ℓ} (struct : Struct bimonoidCode c ℓ) where
open import MLib.Prelude
open import MLib.Matrix.Core
open import MLib.Matrix.Equality struct
open import MLib.Matrix.Mul struct
open import MLib.Algebra.Operations struct
open Table using (head; tail; rearrange; fromList; toList; _≗_; replicate)
open Nat using () renaming (_+_ to _+ℕ_; _*_ to _*ℕ_)
open FunctionProperties
open import MLib.Fin.Parts.Simple
-- Tensor product
_⊠_ : ∀ {m n p q} → Matrix S m n → Matrix S p q → Matrix S (m *ℕ p) (n *ℕ q)
(A ⊠ B) i j =
let i₁ , i₂ = toParts i
j₁ , j₂ = toParts j
in A i₁ j₁ *′ B i₂ j₂
private
≡⇒≡×≡×≡ :
∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
{i i′ : A} {j j′ : B} {k k′ : C} →
(i , j , k) ≡ (i′ , j′ , k′) →
i ≡ i′ × j ≡ j′ × k ≡ k′
≡⇒≡×≡×≡ = Σ.map id Σ.≡⇒≡×≡ ∘ Σ.≡⇒≡×≡
open _≃_
module _ ⦃ props : Has (associative on * ∷ []) ⦄ {m n p q r s} where
⊠-associative :
(A : Matrix S m n) (B : Matrix S p q) (C : Matrix S r s) →
(A ⊠ B) ⊠ C ≃ A ⊠ (B ⊠ C)
⊠-associative A B C .m≡p = Nat.*-assoc m p r
⊠-associative A B C .n≡q = Nat.*-assoc n q s
⊠-associative A B C .equal {i} {i′} {j} {j′} i≅i′ j≅j′ =
let i₁ , i₂ , i₃ = toParts³ m p r i
j₁ , j₂ , j₃ = toParts³ n q s j
i′₁ , i′₂ , i′₃ = toParts³′ m p r i′
j′₁ , j′₂ , j′₃ = toParts³′ n q s j′
i₁-eq , i₂-eq , i₃-eq = ≡⇒≡×≡×≡ (toParts-assoc m p r i≅i′)
j₁-eq , j₂-eq , j₃-eq = ≡⇒≡×≡×≡ (toParts-assoc n q s j≅j′)
open EqReasoning S.setoid
in begin
((A ⊠ B) ⊠ C) i j ≡⟨⟩
A i₁ j₁ *′ B i₂ j₂ *′ C i₃ j₃ ≈⟨ from props (associative on *) _ _ _ ⟩
A i₁ j₁ *′ (B i₂ j₂ *′ C i₃ j₃) ≡⟨ ≡.cong₂ _*′_ (≡.cong₂ A i₁-eq j₁-eq) (≡.cong₂ _*′_ (≡.cong₂ B i₂-eq j₂-eq) (≡.cong₂ C i₃-eq j₃-eq)) ⟩
A i′₁ j′₁ *′ (B i′₂ j′₂ *′ C i′₃ j′₃) ≡⟨⟩
(A ⊠ (B ⊠ C)) i′ j′ ∎
⊠-cong : ∀ {m n m′ n′} {p q p′ q′} {A : Matrix S m n} {A′ : Matrix S m′ n′} {B : Matrix S p q} {B′ : Matrix S p′ q′} → A ≃ A′ → B ≃ B′ → (A ⊠ B) ≃ (A′ ⊠ B′)
⊠-cong A≃A′ B≃B′ with A≃A′ .m≡p | B≃B′ .m≡p | A≃A′ .n≡q | B≃B′ .n≡q
⊠-cong {A = A} {A′} {B} {B′} A≃A′ B≃B′ | ≡.refl | ≡.refl | ≡.refl | ≡.refl = lem
where
lem : (A ⊠ B) ≃ (A′ ⊠ B′)
lem .m≡p = ≡.refl
lem .n≡q = ≡.refl
lem .equal ≅.refl ≅.refl = cong * (A≃A′ .equal ≅.refl ≅.refl) (B≃B′ .equal ≅.refl ≅.refl)
⊠-identityˡ :
⦃ props : Has (1# is leftIdentity for * ∷ []) ⦄ →
∀ {m n} (A : Matrix S m n) → 1● {1} ⊠ A ≃ A
⊠-identityˡ A .m≡p = Nat.*-identityˡ _
⊠-identityˡ A .n≡q = Nat.*-identityˡ _
⊠-identityˡ ⦃ props ⦄ A .equal {i} {i′} {j} {j′} i≅i′ j≅j′ =
let i₁ , i₂ = toParts {1} i
j₁ , j₂ = toParts {1} j
-- x : i₁ ≡ zero
-- x′ : i₂ ≡ i′
-- y : j₁ ≡ zero
-- y′ : j₂ ≡ j′
x , x′ = Σ.≡⇒≡×≡ (toParts-1ˡ i i′ i≅i′)
y , y′ = Σ.≡⇒≡×≡ (toParts-1ˡ j j′ j≅j′)
open EqReasoning S.setoid
in begin
(1● {1} ⊠ A) i j ≡⟨⟩
1● {1} i₁ j₁ *′ A i₂ j₂ ≡⟨ ≡.cong₂ _*′_ (≡.cong₂ (1● {1}) x y) (≡.cong₂ A x′ y′) ⟩
1● {1} zero zero *′ A i′ j′ ≡⟨⟩
1′ *′ A i′ j′ ≈⟨ from props (1# is leftIdentity for *) _ ⟩
A i′ j′ ∎
⊠-identityʳ :
⦃ props : Has (1# is rightIdentity for * ∷ []) ⦄ →
∀ {m n} (A : Matrix S m n) → A ⊠ 1● {1} ≃ A
⊠-identityʳ A .m≡p = Nat.*-identityʳ _
⊠-identityʳ A .n≡q = Nat.*-identityʳ _
⊠-identityʳ A .equal {i} {i′} {j} {j′} i≅i′ j≅j′ with Σ.≡⇒≡×≡ (toParts-1ʳ i i′ i≅i′) | Σ.≡⇒≡×≡ (toParts-1ʳ j j′ j≅j′)
⊠-identityʳ ⦃ props ⦄ A .equal {i} {i′} {j} {j′} i≅i′ j≅j′ | x , x′ | y , y′
rewrite x | x′ | y | y′ = from props (1# is rightIdentity for *) _
|
{
"alphanum_fraction": 0.4794007491,
"avg_line_length": 36.6470588235,
"ext": "agda",
"hexsha": "cf6b878078a92eb4ff4a32b7ebca5f3be5d4fa12",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-matrices",
"max_forks_repo_path": "src/MLib/Matrix/Tensor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bch29/agda-matrices",
"max_issues_repo_path": "src/MLib/Matrix/Tensor.agda",
"max_line_length": 156,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-matrices",
"max_stars_repo_path": "src/MLib/Matrix/Tensor.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2004,
"size": 3738
}
|
open import Prelude
open import Nat
open import core
open import contexts
open import lemmas-disjointness
module lemmas-freshness where
-- if x is fresh in an eexp, it's fresh in its expansion
mutual
fresh-elab-synth1 : ∀{x e τ d Γ Δ} →
x # Γ →
freshe x e →
Γ ⊢ e ⇒ τ ~> d ⊣ Δ →
fresh x d
fresh-elab-synth1 _ FRHConst ESConst = FConst
fresh-elab-synth1 apt (FRHAsc frsh) (ESAsc x₁) = FCast (fresh-elab-ana1 apt frsh x₁)
fresh-elab-synth1 _ (FRHVar x₂) (ESVar x₃) = FVar x₂
fresh-elab-synth1 {Γ = Γ} apt (FRHLam2 x₂ frsh) (ESLam x₃ exp) = FLam x₂ (fresh-elab-synth1 (apart-extend1 Γ x₂ apt) frsh exp)
fresh-elab-synth1 apt FRHEHole ESEHole = FHole (EFId apt)
fresh-elab-synth1 apt (FRHNEHole frsh) (ESNEHole x₁ exp) = FNEHole (EFId apt) (fresh-elab-synth1 apt frsh exp)
fresh-elab-synth1 apt (FRHAp frsh frsh₁) (ESAp x₁ x₂ x₃ x₄ x₅ x₆) =
FAp (FCast (fresh-elab-ana1 apt frsh x₅))
(FCast (fresh-elab-ana1 apt frsh₁ x₆))
fresh-elab-synth1 apt (FRHLam1 x₁ frsh) ()
fresh-elab-synth1 apt (FRHFst frsh) (ESFst s m esana) = FFst (FCast (fresh-elab-ana1 apt frsh esana))
fresh-elab-synth1 apt (FRHSnd frsh) (ESSnd s m esana) = FSnd (FCast (fresh-elab-ana1 apt frsh esana))
fresh-elab-synth1 apt (FRHPair frsh frsh₁) (ESPair x₁ x₂ exp exp₁) = FPair (fresh-elab-synth1 apt frsh exp)
(fresh-elab-synth1 apt frsh₁ exp₁)
fresh-elab-ana1 : ∀{ x e τ d τ' Γ Δ} →
x # Γ →
freshe x e →
Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →
fresh x d
fresh-elab-ana1 {Γ = Γ} apt (FRHLam1 x₁ frsh) (EALam x₂ x₃ exp) = FLam x₁ (fresh-elab-ana1 (apart-extend1 Γ x₁ apt) frsh exp )
fresh-elab-ana1 apt frsh (EASubsume x₁ x₂ x₃ x₄) = fresh-elab-synth1 apt frsh x₃
fresh-elab-ana1 apt FRHEHole EAEHole = FHole (EFId apt)
fresh-elab-ana1 apt (FRHNEHole frsh) (EANEHole x₁ x₂) = FNEHole (EFId apt) (fresh-elab-synth1 apt frsh x₂)
-- if x is fresh in the expansion of an eexp, it's fresh in that eexp
mutual
fresh-elab-synth2 : ∀{x e τ d Γ Δ} →
fresh x d →
Γ ⊢ e ⇒ τ ~> d ⊣ Δ →
freshe x e
fresh-elab-synth2 FConst ESConst = FRHConst
fresh-elab-synth2 (FVar x₂) (ESVar x₃) = FRHVar x₂
fresh-elab-synth2 (FLam x₂ frsh) (ESLam x₃ exp) = FRHLam2 x₂ (fresh-elab-synth2 frsh exp)
fresh-elab-synth2 (FHole x₁) ESEHole = FRHEHole
fresh-elab-synth2 (FNEHole x₁ frsh) (ESNEHole x₂ exp) = FRHNEHole (fresh-elab-synth2 frsh exp)
fresh-elab-synth2 (FAp (FCast frsh) (FCast frsh₁)) (ESAp x₁ x₂ x₃ x₄ x₅ x₆) =
FRHAp (fresh-elab-ana2 frsh x₅)
(fresh-elab-ana2 frsh₁ x₆)
fresh-elab-synth2 (FCast frsh) (ESAsc x₁) = FRHAsc (fresh-elab-ana2 frsh x₁)
fresh-elab-synth2 (FFailedCast frsh) ()
fresh-elab-synth2 (FFst (FCast frsh)) (ESFst s m esana) = FRHFst (fresh-elab-ana2 frsh esana)
fresh-elab-synth2 (FSnd (FCast frsh)) (ESSnd s m esana) = FRHSnd (fresh-elab-ana2 frsh esana)
fresh-elab-synth2 (FPair frsh frsh₁) (ESPair x₁ x₂ exp exp₁) = FRHPair (fresh-elab-synth2 frsh exp) (fresh-elab-synth2 frsh₁ exp₁)
fresh-elab-ana2 : ∀{ x e τ d τ' Γ Δ} →
fresh x d →
Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →
freshe x e
fresh-elab-ana2 (FLam x₁ frsh) (EALam x₂ x₃ exp) = FRHLam1 x₁ (fresh-elab-ana2 frsh exp)
fresh-elab-ana2 frsh (EASubsume x₁ x₂ x₃ x₄) = fresh-elab-synth2 frsh x₃
fresh-elab-ana2 (FHole x₁) EAEHole = FRHEHole
fresh-elab-ana2 (FNEHole x₁ frsh) (EANEHole x₂ x₃) = FRHNEHole (fresh-elab-synth2 frsh x₃)
|
{
"alphanum_fraction": 0.5875256674,
"avg_line_length": 57.2941176471,
"ext": "agda",
"hexsha": "cbef682b7bca326b7ed0bf44fe1b7869519fe899",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-livelits-agda",
"max_forks_repo_path": "lemmas-freshness.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_issues_repo_issues_event_max_datetime": "2020-10-20T20:44:13.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-30T20:27:56.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazel-palette-agda",
"max_issues_repo_path": "lemmas-freshness.agda",
"max_line_length": 134,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazel-palette-agda",
"max_stars_repo_path": "lemmas-freshness.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T15:38:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-04T06:45:06.000Z",
"num_tokens": 1479,
"size": 3896
}
|
module Issue499 where
data A : Set where
a : A
data B : Set where
b : .A → B
data C : B → Set where
c : C (b a)
f : ∀ {i} → C i → A
f x = {!!} -- Hitting C-c C-c x
|
{
"alphanum_fraction": 0.4971428571,
"avg_line_length": 11.6666666667,
"ext": "agda",
"hexsha": "9befa42a66bd171420013ba7970be707c81e99b1",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue499.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue499.agda",
"max_line_length": 31,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue499.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 73,
"size": 175
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module cw.cohomology.GridMap {i j k}
{A : Type i} {B : Type j} {C : Type k}
(f : A → B) (g : B → C) where
B/A = Cofiber f
C/A = Cofiber (g ∘ f)
C/B = Cofiber g
B/A-to-C/A-span-map : SpanMap (cofiber-span f) (cofiber-span (g ∘ f))
B/A-to-C/A-span-map = span-map (idf _) g (idf _)
(comm-sqr λ _ → idp) (comm-sqr λ _ → idp)
module B/AToC/A = PushoutFmap B/A-to-C/A-span-map
B/A-to-C/A : B/A → C/A
B/A-to-C/A = B/AToC/A.f
C/A-to-C/B-span-map : SpanMap (cofiber-span (g ∘ f)) (cofiber-span g)
C/A-to-C/B-span-map = span-map (idf _) (idf _) f
(comm-sqr λ _ → idp) (comm-sqr λ _ → idp)
module C/AToC/B = PushoutFmap C/A-to-C/B-span-map
C/A-to-C/B : C/A → C/B
C/A-to-C/B = C/AToC/B.f
|
{
"alphanum_fraction": 0.5670103093,
"avg_line_length": 29.8461538462,
"ext": "agda",
"hexsha": "9e38e65a3200d0d87f759b057cffd8ec87d9f260",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/GridMap.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/GridMap.agda",
"max_line_length": 71,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/GridMap.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 326,
"size": 776
}
|
------------------------------------------------------------------------------
-- The gcd is divisible by any common divisor
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.GCD.Total.DivisibleATP where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Divisibility.By0
open import FOTC.Data.Nat.Divisibility.By0.PropertiesATP
open import FOTC.Data.Nat.Induction.NonAcc.LexicographicATP
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.EliminationPropertiesATP
open import FOTC.Data.Nat.Inequalities.PropertiesATP
open import FOTC.Data.Nat.PropertiesATP
open import FOTC.Program.GCD.Total.Definitions
open import FOTC.Program.GCD.Total.GCD
------------------------------------------------------------------------------
-- The gcd 0 0 is Divisible.
postulate gcd-00-Divisible : Divisible zero zero (gcd zero zero)
{-# ATP prove gcd-00-Divisible #-}
-- The gcd 0 (succ n) is Divisible.
postulate
gcd-0S-Divisible : ∀ {n} → N n → Divisible zero (succ₁ n) (gcd zero (succ₁ n))
{-# ATP prove gcd-0S-Divisible #-}
postulate
gcd-S0-Divisible : ∀ {n} → N n → Divisible (succ₁ n) zero (gcd (succ₁ n) zero)
{-# ATP prove gcd-S0-Divisible #-}
------------------------------------------------------------------------------
-- The gcd (succ₁ m) (succ₁ n) when succ₁ m > succ₁ n is Divisible.
-- For the proof using the ATP we added the helper hypothesis
-- c | succ₁ m → c | succ₁ c → c | succ₁ m ∸ succ₁ n.
postulate
gcd-S>S-Divisible-ah :
∀ {m n} → N m → N n →
(Divisible (succ₁ m ∸ succ₁ n) (succ₁ n) (gcd (succ₁ m ∸ succ₁ n) (succ₁ n))) →
succ₁ m > succ₁ n →
∀ c → N c → CD (succ₁ m) (succ₁ n) c →
(c ∣ succ₁ m ∸ succ₁ n) →
c ∣ gcd (succ₁ m) (succ₁ n)
{-# ATP prove gcd-S>S-Divisible-ah #-}
gcd-S>S-Divisible :
∀ {m n} → N m → N n →
(Divisible (succ₁ m ∸ succ₁ n) (succ₁ n) (gcd (succ₁ m ∸ succ₁ n) (succ₁ n))) →
succ₁ m > succ₁ n →
Divisible (succ₁ m) (succ₁ n) (gcd (succ₁ m) (succ₁ n))
gcd-S>S-Divisible {m} {n} Nm Nn acc Sm>Sn c Nc (c∣Sm , c∣Sn) =
gcd-S>S-Divisible-ah Nm Nn acc Sm>Sn c Nc (c∣Sm , c∣Sn)
(x∣y→x∣z→x∣y∸z Nc (nsucc Nm) (nsucc Nn) c∣Sm c∣Sn)
------------------------------------------------------------------------------
-- The gcd (succ₁ m) (succ₁ n) when succ₁ m ≯ succ₁ n is Divisible.
-- For the proof using the ATP we added the helper hypothesis
-- c | succ₁ n → c | succ₁ m → c | succ₁ n ∸ succ₁ m.
postulate
gcd-S≯S-Divisible-ah :
∀ {m n} → N m → N n →
(Divisible (succ₁ m) (succ₁ n ∸ succ₁ m) (gcd (succ₁ m) (succ₁ n ∸ succ₁ m))) →
succ₁ m ≯ succ₁ n →
∀ c → N c → CD (succ₁ m) (succ₁ n) c →
(c ∣ succ₁ n ∸ succ₁ m) →
c ∣ gcd (succ₁ m) (succ₁ n)
{-# ATP prove gcd-S≯S-Divisible-ah #-}
gcd-S≯S-Divisible :
∀ {m n} → N m → N n →
(Divisible (succ₁ m) (succ₁ n ∸ succ₁ m) (gcd (succ₁ m) (succ₁ n ∸ succ₁ m))) →
succ₁ m ≯ succ₁ n →
Divisible (succ₁ m) (succ₁ n) (gcd (succ₁ m) (succ₁ n))
gcd-S≯S-Divisible {m} {n} Nm Nn acc Sm≯Sn c Nc (c∣Sm , c∣Sn) =
gcd-S≯S-Divisible-ah Nm Nn acc Sm≯Sn c Nc (c∣Sm , c∣Sn)
(x∣y→x∣z→x∣y∸z Nc (nsucc Nn) (nsucc Nm) c∣Sn c∣Sm)
------------------------------------------------------------------------------
-- The gcd m n when m > n is Divisible.
gcd-x>y-Divisible :
∀ {m n} → N m → N n →
(∀ {o p} → N o → N p → Lexi o p m n → Divisible o p (gcd o p)) →
m > n →
Divisible m n (gcd m n)
gcd-x>y-Divisible nzero Nn _ 0>n _ _ = ⊥-elim (0>x→⊥ Nn 0>n)
gcd-x>y-Divisible (nsucc Nm) nzero _ _ c Nc = gcd-S0-Divisible Nm c Nc
gcd-x>y-Divisible (nsucc {m} Nm) (nsucc {n} Nn) ah Sm>Sn c Nc =
gcd-S>S-Divisible Nm Nn ih Sm>Sn c Nc
where
-- Inductive hypothesis.
ih : Divisible (succ₁ m ∸ succ₁ n) (succ₁ n) (gcd (succ₁ m ∸ succ₁ n) (succ₁ n))
ih = ah {succ₁ m ∸ succ₁ n}
{succ₁ n}
(∸-N (nsucc Nm) (nsucc Nn))
(nsucc Nn)
([Sx∸Sy,Sy]<[Sx,Sy] Nm Nn)
------------------------------------------------------------------------------
-- The gcd m n when m ≯ n is Divisible.
gcd-x≯y-Divisible :
∀ {m n} → N m → N n →
(∀ {o p} → N o → N p → Lexi o p m n → Divisible o p (gcd o p)) →
m ≯ n →
Divisible m n (gcd m n)
gcd-x≯y-Divisible nzero nzero _ _ c Nc = gcd-00-Divisible c Nc
gcd-x≯y-Divisible nzero (nsucc Nn) _ _ c Nc = gcd-0S-Divisible Nn c Nc
gcd-x≯y-Divisible (nsucc _) nzero _ Sm≯0 _ _ = ⊥-elim (S≯0→⊥ Sm≯0)
gcd-x≯y-Divisible (nsucc {m} Nm) (nsucc {n} Nn) ah Sm≯Sn c Nc =
gcd-S≯S-Divisible Nm Nn ih Sm≯Sn c Nc
where
-- Inductive hypothesis.
ih : Divisible (succ₁ m) (succ₁ n ∸ succ₁ m) (gcd (succ₁ m) (succ₁ n ∸ succ₁ m))
ih = ah {succ₁ m}
{succ₁ n ∸ succ₁ m}
(nsucc Nm)
(∸-N (nsucc Nn) (nsucc Nm))
([Sx,Sy∸Sx]<[Sx,Sy] Nm Nn)
------------------------------------------------------------------------------
-- The gcd is Divisible.
gcdDivisible : ∀ {m n} → N m → N n → Divisible m n (gcd m n)
gcdDivisible = Lexi-wfind A h
where
A : D → D → Set
A i j = Divisible i j (gcd i j)
h : ∀ {i j} → N i → N j → (∀ {k l} → N k → N l → Lexi k l i j → A k l) →
A i j
h Ni Nj ah = case (gcd-x>y-Divisible Ni Nj ah)
(gcd-x≯y-Divisible Ni Nj ah)
(x>y∨x≯y Ni Nj)
|
{
"alphanum_fraction": 0.5201317716,
"avg_line_length": 39.5942028986,
"ext": "agda",
"hexsha": "acdd614ee59d442672bae389d46d87e20348ed45",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/GCD/Total/DivisibleATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/GCD/Total/DivisibleATP.agda",
"max_line_length": 83,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/GCD/Total/DivisibleATP.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 2019,
"size": 5464
}
|
module Vecs where
open import Nats
infixr 5 _∷_ _++_ _∷ʳ_
infix 4 _∈_ _⊛_
data Vec {a} (A : Set a) : ℕ → Set a where
[] : Vec A zero
_∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n)
data _∈_ {a} {A : Set a} : A → {n : ℕ} → Vec A n → Set a where
here : ∀ {n} {x} {xs : Vec A n} → x ∈ x ∷ xs
there : ∀ {n} {x y} {xs : Vec A n} (x∈xs : x ∈ xs) → x ∈ y ∷ xs
head : ∀ {a n} {A : Set a} → Vec A (suc n) → A
head (x ∷ xs) = x
tail : ∀ {a n} {A : Set a} → Vec A (suc n) → Vec A n
tail (x ∷ xs) = xs
[_] : ∀ {a} {A : Set a} → A → Vec A 1
[ x ] = x ∷ []
_++_ : ∀ {a m n} {A : Set a} → Vec A m → Vec A n → Vec A (m + n)
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
_⊛_ : ∀ {a b n} {A : Set a} {B : Set b} →
Vec (A → B) n → Vec A n → Vec B n
[] ⊛ _ = []
(f ∷ fs) ⊛ (x ∷ xs) = f x ∷ (fs ⊛ xs)
replicate : ∀ {a n} {A : Set a} → A → Vec A n
replicate {n = zero} x = []
replicate {n = suc n} x = x ∷ replicate x
_∷ʳ_ : ∀ {a n} {A : Set a} → Vec A n → A → Vec A (suc n)
[] ∷ʳ y = [ y ]
(x ∷ xs) ∷ʳ y = x ∷ (xs ∷ʳ y)
reverse : ∀ {n m} {A : Set n} → Vec A m → Vec A m
reverse [] = []
reverse (x ∷ xs) = reverse xs ∷ʳ x
|
{
"alphanum_fraction": 0.4201898188,
"avg_line_length": 25.7555555556,
"ext": "agda",
"hexsha": "09cde49efaeb67d9053e9349565ad14b17245432",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ice1k/Theorems",
"max_forks_repo_path": "src/Vecs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ice1k/Theorems",
"max_issues_repo_path": "src/Vecs.agda",
"max_line_length": 65,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ice1k/Theorems",
"max_stars_repo_path": "src/Vecs.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z",
"num_tokens": 575,
"size": 1159
}
|
{-# OPTIONS --erased-cubical --safe --no-sized-types --no-guardedness
--no-subtyping #-}
module Agda.Builtin.Cubical.Path where
open import Agda.Primitive.Cubical using (PathP) public
infix 4 _≡_
-- We have a variable name in `(λ i → A)` as a hint for case
-- splitting.
_≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
_≡_ {A = A} = PathP (λ i → A)
{-# BUILTIN PATH _≡_ #-}
|
{
"alphanum_fraction": 0.5682926829,
"avg_line_length": 24.1176470588,
"ext": "agda",
"hexsha": "722fce87ab6cad01b32afad6ae0079ae5e73dae7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-18T13:34:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-18T13:34:07.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/Path.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/Path.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/Path.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 145,
"size": 410
}
|
{-# OPTIONS --no-universe-polymorphism #-}
open import Data.List
open import Data.Product
open import Data.Unit hiding (_≤_)
open import Data.Nat
open import Data.Empty
open import Relation.Nullary
open import Relation.Binary.Core hiding (Total)
import Level as L using (zero)
open import Lists
open import BagEquality
open import Equivalence
open import DivideEtImpera
module Mergesort where
merge : {A : Set} → {_<_ : Rel A L.zero} → Total _<_ → List A → List A → List A
merge _ [] ys = ys
merge _ (x ∷ xs) [] = (x ∷ xs)
merge total (x ∷ xs) (y ∷ ys) with (total x y)
merge total (x ∷ xs) (y ∷ ys) | (inj₁ x≤y) = x ∷ merge total xs (y ∷ ys)
merge total (x ∷ xs) (y ∷ ys) | (inj₂ y≤x) = y ∷ merge total (x ∷ xs) ys
merge-cong : {A : Set} → {_<_ : Rel A L.zero} → (total : Total _<_) → (xs ys : List A) → merge total xs ys ≈ (xs ++ ys)
merge-cong _ [] ys = λ z → z ∈ ys □↔
merge-cong _ (x ∷ xs) [] = λ z → z ∈ (x ∷ xs) ↔⟨ ++-comm [] (x ∷ xs) z ⟩
z ∈ ((x ∷ xs) ++ []) □↔
merge-cong total (x ∷ xs) (y ∷ ys) with (total x y)
merge-cong total (x ∷ xs) (y ∷ ys) | (inj₁ x≤y) = λ z →
(z ≡ x) ⊕ z ∈ merge total xs (y ∷ ys) ↔⟨ ⊕-cong ((z ≡ x) □↔) (merge-cong total xs (y ∷ ys) z) ⟩
(z ≡ x) ⊕ z ∈ (xs ++ (y ∷ ys)) □↔
merge-cong total (x ∷ xs) (y ∷ ys) | (inj₂ y≤x) = λ z →
(z ≡ y) ⊕ z ∈ merge total (x ∷ xs) ys ↔⟨ ⊕-cong ((z ≡ y) □↔) (merge-cong total (x ∷ xs) ys z) ⟩
(z ≡ y) ⊕ z ∈ ((x ∷ xs) ++ ys) ↔⟨ ⊕-cong ((z ≡ y) □↔) (++-comm (x ∷ xs) ys z) ⟩
(z ≡ y) ⊕ z ∈ (ys ++ (x ∷ xs)) ↔⟨ ++-comm (y ∷ ys) (x ∷ xs) z ⟩
z ∈ ((x ∷ xs) ++ (y ∷ ys)) □↔
SmallerThanHead : {A : Set} → Rel A L.zero → A → List A → Set
SmallerThanHead _ x [] = ⊤
SmallerThanHead _<_ x (y ∷ ys) = _<_ x y
ord : {A : Set} → {_<_ : Rel A L.zero} → {x : A} → {xs : List A} → SmallerThanHead _<_ x xs → Ordered _<_ xs → Ordered _<_ (x ∷ xs)
ord {xs = []} _ _ = SingleIsOrd
ord {xs = (y ∷ ys)} x≤y ordXs = HeadTailOrd x≤y ordXs
merge-order : {A : Set} → {_<_ : Rel A L.zero} → (total : Total _<_) → (xs ys : List A)
→ Ordered _<_ xs → Ordered _<_ ys → Ordered _<_ (merge total xs ys)
merge-order _ [] ys _ ysOrd = ysOrd
merge-order _ (x ∷ xs) [] xsOrd _ = xsOrd
merge-order total (x ∷ xs) (y ∷ ys) _ _ with (total x y)
merge-order total (x ∷ xs) (y ∷ ys) _ _ | (inj₁ x≤y) with xs
merge-order total (x ∷ xs) (y ∷ ys) _ ysOrd | (inj₁ x≤y) | [] = HeadTailOrd x≤y ysOrd
merge-order {_<_ = _<_} total (x ∷ xs) (y ∷ ys) (HeadTailOrd x≤x₂ xsOrd) ysOrd | (inj₁ x≤y) | (x₂ ∷ xs₂)
= ord x≤z (merge-order total (x₂ ∷ xs₂) (y ∷ ys) xsOrd ysOrd) where
x≤z : SmallerThanHead _<_ x (merge total (x₂ ∷ xs₂) (y ∷ ys))
x≤z with (total x₂ y)
x≤z | (inj₁ _) = x≤x₂
x≤z | (inj₂ _) = x≤y
merge-order total (x ∷ xs) (y ∷ ys) _ _ | (inj₂ y≤x) with ys
merge-order total (x ∷ xs) (y ∷ ys) xsOrd _ | (inj₂ y≤x) | [] = HeadTailOrd y≤x xsOrd
merge-order {_<_ = _<_} total (x ∷ xs) (y ∷ ys) xsOrd (HeadTailOrd y≤y₂ ysOrd) | (inj₂ y≤x) | (y₂ ∷ ys₂)
= ord y≤z (merge-order total (x ∷ xs) (y₂ ∷ ys₂) xsOrd ysOrd) where
y≤z : SmallerThanHead _<_ y (merge total (x ∷ xs) (y₂ ∷ ys₂))
y≤z with (total x y₂)
y≤z | (inj₁ _) = y≤x
y≤z | (inj₂ _) = y≤y₂
minus : ℕ → ℕ → ℕ
minus n zero = n
minus zero (suc m) = zero
minus (suc n) (suc m) = minus n m
minus-suc : {n m : ℕ} → m ≤ n → minus (suc n) m ≡ suc (minus n m)
minus-suc z≤n = refl
minus-suc (s≤s pf) = minus-suc pf
bisect : {A : Set} → List A → (List A × List A)
bisect xs = splitAt ⌊ length xs /2⌋ xs
splitAtLen1 : {A : Set} → (n : ℕ) → (xs : List A) → n ≤ (length xs) → length (proj₁ (splitAt n xs)) ≡ n
splitAtLen1 zero xs _ = refl
splitAtLen1 (suc n) [] ()
splitAtLen1 (suc n) (x ∷ xs) (s≤s pf) = suc (length (proj₁ (splitAt n xs))) =⟨ splitAtLen1 n xs pf under suc ⟩
suc n □=
splitAtLen2 : {A : Set} → (n : ℕ) → (xs : List A) → length (proj₂ (splitAt n xs)) ≡ minus (length xs) n
splitAtLen2 zero xs = refl
splitAtLen2 (suc n) [] = refl
splitAtLen2 (suc n) (x ∷ xs) = length (proj₂ (splitAt n xs)) =⟨ splitAtLen2 n xs ⟩
minus (length xs) n □=
s≤′s : {n m : ℕ} → n ≤′ m → suc n ≤′ suc m
s≤′s ≤′-refl = ≤′-refl
s≤′s (≤′-step pf) = ≤′-step (s≤′s pf)
lte-cong : {n m : ℕ} → (n ≤ m) ⇔ (n ≤′ m)
lte-cong = record { to = to' ;
from = from' } where
to' : {n m : ℕ} → n ≤ m → n ≤′ m
to' {m = zero} z≤n = ≤′-refl
to' {m = suc m} z≤n = ≤′-step (to' z≤n)
to' (s≤s pf) = s≤′s (to' pf)
from' : {n m : ℕ} → n ≤′ m → n ≤ m
from' {zero} ≤′-refl = z≤n
from' {suc n} ≤′-refl = s≤s (from' ≤′-refl)
from' (≤′-step pf) = ≤-step (from' pf) where
≤-step : {n m : ℕ} → n ≤ m → n ≤ (suc m)
≤-step z≤n = z≤n
≤-step (s≤s pf) = s≤s (≤-step pf)
eq-rel-cong : {A : Set} → {rel : Rel A L.zero} → {x y z : A} → x ≡ y → rel y z → rel x z
eq-rel-cong refl pf = pf
halfLte1 : (n : ℕ) → ⌊ n /2⌋ ≤′ n
halfLte1 zero = ≤′-refl
halfLte1 (suc zero) = ≤′-step ≤′-refl
halfLte1 (suc (suc n)) = ≤′-step (s≤′s (halfLte1 n))
halfLt1 : (n : ℕ) → ⌊ (suc (suc n)) /2⌋ <′ (suc (suc n))
halfLt1 n = s≤′s (s≤′s (halfLte1 n))
halfLte2 : (n : ℕ) → (minus n ⌊ n /2⌋) ≤′ n
halfLte2 zero = ≤′-refl
halfLte2 (suc zero) = ≤′-refl
halfLte2 (suc (suc n)) = ≤′-step (eq-rel-cong {rel = _≤′_} {x = minus (suc n) ⌊ n /2⌋} {y = suc (minus n ⌊ n /2⌋)}
(minus-suc (_⇔_.from lte-cong (halfLte1 n))) (s≤′s (halfLte2 n)))
halfLt2 : (n : ℕ) → (minus (suc (suc n)) ⌊ (suc (suc n)) /2⌋) <′ (suc (suc n))
halfLt2 n = s≤′s (eq-rel-cong {rel = _≤′_} {x = minus (suc n) ⌊ n /2⌋} {y = suc (minus n ⌊ n /2⌋)}
(minus-suc (_⇔_.from lte-cong (halfLte1 n))) (s≤′s (halfLte2 n)))
bisectPf1 : {A : Set} → (x y : A) → (zs : List A) → proj₁ (bisect (x ∷ y ∷ zs)) <l (x ∷ y ∷ zs)
bisectPf1 x y zs = eq-rel-cong {rel = _<′_}
(splitAtLen1 ⌊ (suc (suc (length zs))) /2⌋ (x ∷ y ∷ zs) (_⇔_.from lte-cong (halfLte1 (suc (suc (length zs))))))
(halfLt1 (length zs))
bisectPf2 : {A : Set} → (x y : A) → (zs : List A) → proj₂ (bisect (x ∷ y ∷ zs)) <l (x ∷ y ∷ zs)
bisectPf2 x y zs = eq-rel-cong {rel = _<′_}
(splitAtLen2 ⌊ (suc (suc (length zs))) /2⌋ (x ∷ y ∷ zs))
(halfLt2 (length zs))
splitAt-cong : {A : Set} → (n : ℕ) → (xs : List A) → proj₁ (splitAt n xs) ++ proj₂ (splitAt n xs) ≈ xs
splitAt-cong zero xs z = z ∈ xs □↔
splitAt-cong (suc n) [] z = ⊥ □↔
splitAt-cong (suc n) (x ∷ xs) z = (z ≡ x) ⊕ z ∈ (proj₁ (splitAt n xs) ++ proj₂ (splitAt n xs))
↔⟨ ⊕-cong ((z ≡ x) □↔) (splitAt-cong n xs z) ⟩
(z ≡ x) ⊕ z ∈ xs □↔
ms-inputCond : {A : Set} → List A → Set
ms-inputCond _ = ⊤
ms-decompCond : {A : Set} → List A → (⊤ × List A × List A) → Set
ms-decompCond xs (_ , ys , zs ) = ys ++ zs ≈ xs
ms-compCond : {A : Set} → Rel A L.zero → (⊤ × List A × List A) → List A → Set
ms-compCond rel (_ , xs , ys ) zs = zs ≈ xs ++ ys × (Ordered rel xs → Ordered rel ys → Ordered rel zs)
ms-outputCond : {A : Set} → Rel A L.zero → List A → List A → Set
ms-outputCond rel xs zs = (zs ≈ xs) × Ordered rel zs
ms-G : ⊤ → ⊤ → Σ ⊤ (λ x → ⊤)
ms-G _ _ = (⊤.tt , ⊤.tt)
ms-decomp : {A : Set} → (xs : List A) → ⊤ → ¬ ListPrimitive2 xs → Σ (⊤ × List A × List A)
(λ z → ⊤ × ⊤ × ⊤ × (proj₁ (proj₂ z) <l xs) × (proj₂ (proj₂ z) <l xs) × ms-decompCond xs z)
ms-decomp [] _ notPrim = ⊥-elim (notPrim NilIsPrim2)
ms-decomp (x ∷ []) _ notPrim = ⊥-elim (notPrim SingleIsPrim2)
ms-decomp (x ∷ y ∷ zs) _ _ = (⊤.tt , bisect (x ∷ y ∷ zs)) , (⊤.tt , ⊤.tt , ⊤.tt ,
bisectPf1 x y zs ,
bisectPf2 x y zs ,
splitAt-cong ⌊ (suc (suc (length zs))) /2⌋ (x ∷ y ∷ zs))
ms-comp : {A : Set} → {rel : Rel A L.zero} → Total rel → (z : (⊤ × List A × List A)) → Σ (List A) (ms-compCond rel z)
ms-comp total ( _ , xs , ys) = (merge total xs ys) , (merge-cong total xs ys , merge-order total xs ys)
ms-dirSolve : {A : Set} → (rel : Rel A L.zero) → (xs : List A) → ⊤ → ListPrimitive2 xs → Σ (List A) (ms-outputCond rel xs)
ms-dirSolve _ [] _ _ = [] , ((λ z → ⊥ □↔) , NilIsOrd)
ms-dirSolve _ (x ∷ []) _ _ = (x ∷ []) , ((λ z → z ∈ (x ∷ []) □↔) , SingleIsOrd)
ms-dirSolve _ (x ∷ y ∷ zs) _ prim = ⊥-elim (consConsIsNotPrim2 prim)
ms-lemma : {A : Set} → (rel : Rel A L.zero) → ∀{xs ys₁ ys₂ zs₁ zs₂ ws} → ms-decompCond xs (⊤.tt , ys₁ , ys₂)
→ ⊤ → ms-outputCond rel ys₁ zs₁ → ms-outputCond rel ys₂ zs₂
→ ms-compCond rel (⊤.tt , zs₁ , zs₂) ws → ms-outputCond rel xs ws
ms-lemma rel {xs} {ys₁} {ys₂} {zs₁} {zs₂} {ws} ys₁++ys₂≈xs _ ( ys₁≈zs₁ , zs₁Ord ) ( ys₂≈zs₂ , zs₂Ord ) ( ws≈zs₁++zs₂ , compOrd)
= (λ z → z ∈ ws ↔⟨ ws≈zs₁++zs₂ z ⟩
z ∈ (zs₁ ++ zs₂) ↔⟨ Any-++ (z ≡_) zs₁ zs₂ ⟩
z ∈ zs₁ ⊕ z ∈ zs₂ ↔⟨ ⊕-cong (ys₁≈zs₁ z) (ys₂≈zs₂ z) ⟩
z ∈ ys₁ ⊕ z ∈ ys₂ ↔⟨ ↔sym (Any-++ (z ≡_) ys₁ ys₂) ⟩
z ∈ (ys₁ ++ ys₂) ↔⟨ ys₁++ys₂≈xs z ⟩
z ∈ xs □↔) ,
compOrd zs₁Ord zs₂Ord
mergesort : {A : Set} → {rel : Rel A L.zero} → Total rel → (xs : List A) → Σ (List A) (λ zs → (zs ≈ xs) × Ordered rel zs)
mergesort {rel = rel} total xs = makeD&C2 <l-wellFounded
prim2Dec
ms-decomp
(ms-comp total)
ms-G
(ms-dirSolve rel)
(ms-lemma rel)
xs ⊤.tt
|
{
"alphanum_fraction": 0.4431497839,
"avg_line_length": 48.8165137615,
"ext": "agda",
"hexsha": "887ca1b8ea8aa3942f921d0cfd328a41c89278c2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "99bd3a5e772563153d78f61c1bbca48d7809ff48",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "NAMEhzj/Divide-and-Conquer-in-Agda",
"max_forks_repo_path": "Mergesort.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "99bd3a5e772563153d78f61c1bbca48d7809ff48",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "NAMEhzj/Divide-and-Conquer-in-Agda",
"max_issues_repo_path": "Mergesort.agda",
"max_line_length": 132,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "99bd3a5e772563153d78f61c1bbca48d7809ff48",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "NAMEhzj/Divide-and-Conquer-in-Agda",
"max_stars_repo_path": "Mergesort.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4224,
"size": 10642
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Adjoint.Instance.StrictCore where
-- The adjunction between the forgetful functor from (strict) Cats to
-- (strict) Groupoids and the (strict) Core functor.
open import Data.Product
open import Level using (_⊔_)
import Function
open import Relation.Binary using (IsEquivalence)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Categories.Adjoint
open import Categories.Category using (Category)
open import Categories.Category.Groupoid using (Groupoid)
import Categories.Category.Construction.Core as C
open import Categories.Category.Instance.StrictCats
open import Categories.Category.Instance.StrictGroupoids
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Equivalence
open import Categories.Functor.Instance.StrictCore
import Categories.Morphism as Morphism
import Categories.Morphism.Reasoning as MR
open import Categories.Morphism.IsoEquiv using (⌞_⌟; _≃_)
-- The forgetful functor from StrictGroupoids to StrictCats
Forgetful : ∀ {o ℓ e} → Functor (Groupoids o ℓ e) (Cats o ℓ e)
Forgetful {o} {ℓ} {e} = record
{ F₀ = Groupoid.category
; F₁ = Function.id
; identity = λ {G} → Groupoids.Equiv.refl {G} {G} {idF}
; homomorphism = λ {G H K F H} → Groupoids.Equiv.refl {G} {K} {H ∘F F}
; F-resp-≈ = Function.id
}
where
module Groupoids = Category (Groupoids o ℓ e)
-- Core is right-adjoint to the forgetful functor from Groupoids to
-- Cats
CoreAdj : ∀ {o ℓ e} → Forgetful {o} {ℓ ⊔ e} {e} ⊣ Core
CoreAdj = record
{ unit = record { η = unit ; commute = λ {G H} F → unit-commute {G} {H} F ; sym-commute = λ {G H} F → unit-sym-commute {G} {H} F }
; counit = record { η = counit ; commute = counit-commute ; sym-commute = counit-sym-commute }
; zig = λ {G} → zig {G}
; zag = zag
}
where
open Groupoid using (category)
module Core = Functor Core
unit : ∀ G → Functor (category G) (C.Core (category G))
unit G = record
{ F₀ = Function.id
; F₁ = λ f → record { from = f ; to = f ⁻¹ ; iso = iso }
; identity = ⌞ Equiv.refl ⌟
; homomorphism = ⌞ Equiv.refl ⌟
; F-resp-≈ = ⌞_⌟
}
where open Groupoid G
unit-commute : ∀ {G H} (F : Functor (category G) (category H)) →
unit H ∘F F ≡F Core.F₁ F ∘F unit G
unit-commute {_} {H} F = record
{ eq₀ = λ _ → refl
; eq₁ = λ _ → ⌞ MR.id-comm-sym (category H) ⌟
}
unit-sym-commute : ∀ {G H} (F : Functor (category G) (category H)) →
Core.F₁ F ∘F unit G ≡F unit H ∘F F
unit-sym-commute {_} {H} F = record
{ eq₀ = λ _ → refl
; eq₁ = λ _ → ⌞ MR.id-comm-sym (category H) ⌟
}
counit : ∀ C → Functor (C.Core C) C
counit C = record
{ F₀ = Function.id
; F₁ = _≅_.from
; identity = Equiv.refl
; homomorphism = Equiv.refl
; F-resp-≈ = _≃_.from-≈
}
where
open Category C
open Morphism C
counit-commute : ∀ {C D} (F : Functor C D) →
counit D ∘F Core.F₁ F ≡F F ∘F counit C
counit-commute {C} {D} F = record
{ eq₀ = λ _ → refl
; eq₁ = λ _ → MR.id-comm-sym D
}
counit-sym-commute : ∀ {C D} (F : Functor C D) →
F ∘F counit C ≡F counit D ∘F Core.F₁ F
counit-sym-commute {C} {D} F = record
{ eq₀ = λ _ → refl
; eq₁ = λ _ → MR.id-comm-sym D
}
zig : ∀ {G} → counit (category G) ∘F unit G ≡F idF
zig {G} = record
{ eq₀ = λ _ → refl
; eq₁ = λ _ → MR.id-comm-sym (category G)
}
zag : ∀ {B} → Core.F₁ (counit B) ∘F unit (Core.F₀ B) ≡F idF
zag {B} = record { eq₀ = λ _ → refl ; eq₁ = λ _ → ⌞ MR.id-comm-sym B ⌟ }
|
{
"alphanum_fraction": 0.5889182058,
"avg_line_length": 33.8392857143,
"ext": "agda",
"hexsha": "34477e0eed619aa31f2fbd9f02112374db88778f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Adjoint/Instance/StrictCore.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Adjoint/Instance/StrictCore.agda",
"max_line_length": 136,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Adjoint/Instance/StrictCore.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 1274,
"size": 3790
}
|
open import Data.Product using ( ∃ ; _×_ ; _,_ )
open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl )
open import Relation.Nullary using ( ¬_ )
open import Relation.Unary using ( _∈_ ; ∅ )
open import Web.Semantic.DL.Signature using ( Signature ; CN ; RN )
open import Web.Semantic.Util using ( Setoid ; Subset ; _∘_ ; False )
module Web.Semantic.DL.TBox.Interp where
{- TBox interpretation of a Signature Σ
consists essentially of:
1. A Domain Δ of intepretation
2. An equivalence relation on Δ
3. An interpretation of Σ, i.e. a function from CN and RN to Δ
4. Proofs that the interpretations respect the Equivalence Relation
One would use records in Agda 2.6.x
-}
data Interp (Σ : Signature) : Set₁ where
interp :
(Δ : Set) → -- The Domain of Interpretation (e.g. representing real objects in the world)
(_≈_ : Δ → Δ → Set) → -- an equivalence relation between those objects (one may have hesperus ≈ phosphorus)
(ref : ∀ {x} → (x ≈ x)) → -- proof of reflexivity of equivalence relation
(sym : ∀ {x y} → (x ≈ y) → (y ≈ x)) → -- proof of symmetry of ≈
(trans : ∀ {x y z} → (x ≈ y) → (y ≈ z) → (x ≈ z)) → -- proof of transitivity
(con : CN Σ → Subset Δ) → -- concept names of signature map
(rol : RN Σ → Subset (Δ × Δ)) → -- role name of signature map
(con-≈ : ∀ {x y} c → (x ∈ con c) → (x ≈ y) → (y ∈ con c)) →
(rol-≈ : ∀ {w x y z} r → (w ≈ x) → ((x , y) ∈ rol r) → (y ≈ z) → ((w , z) ∈ rol r)) →
Interp Σ
{-
the functions below return some elements of Interp,
which would with Agda 2.6.* be given by the record structure
-}
-- The Domain of Interpretation (e.g. representing real objects in the world)
Δ : ∀ {Σ} → Interp Σ → Set
Δ (interp Δ _≈_ ref sym trans con rol con-≈ rol-≈) = Δ
-- this semantic entailment relation is unusual as it relates an interpretation to
-- elements in the domain whereas usually we have
-- M ⊨ P where M is a model and P a sentence of the language (as done in Institution Theory)
-- so we might have I ⊨ { a owl:sameAs b }
-- which would be true if a refers to the same object as b in Δ via I
-- this may indicate a confusion of syntax with semantics here.
_⊨_≈_ : ∀ {Σ} → (I : Interp Σ) → (Δ I) → (Δ I) → Set
_⊨_≈_ (interp Δ _≈_ ref sym trans con rol con-≈ rol-≈) = _≈_
≈-refl : ∀ {Σ} → (I : Interp Σ) → ∀ {x} → (I ⊨ x ≈ x)
≈-refl (interp Δ _≈_ ref sym trans con rol con-≈ rol-≈) = ref
≈-sym : ∀ {Σ} → (I : Interp Σ) → ∀ {x y} → (I ⊨ x ≈ y) → (I ⊨ y ≈ x)
≈-sym (interp Δ _≈_ ref sym trans con rol con-≈ rol-≈) = sym
≈-trans : ∀ {Σ} → (I : Interp Σ) → ∀ {x y z} → (I ⊨ x ≈ y) → (I ⊨ y ≈ z) → (I ⊨ x ≈ z)
≈-trans (interp Δ _≈_ ref sym trans con rol con-≈ rol-≈) = trans
-- concept names of signature map
con : ∀ {Σ} → (I : Interp Σ) → CN Σ → Subset (Δ I)
con (interp Δ _≈_ ref sym trans con rol con-≈ rol-≈) = con
-- role name of signature map
rol : ∀ {Σ} → (I : Interp Σ) → RN Σ → Subset (Δ I × Δ I)
rol (interp Δ _≈_ ref sym trans con rol con-≈ rol-≈) = rol
con-≈ : ∀ {Σ} → (I : Interp Σ) → ∀ {x y} c → (x ∈ con I c) → (I ⊨ x ≈ y) → (y ∈ con I c)
con-≈ (interp Δ _≈_ ref sym trans con rol con-≈ rol-≈) = con-≈
rol-≈ : ∀ {Σ} → (I : Interp Σ) → ∀ {w x y z} r → (I ⊨ w ≈ x) → ((x , y) ∈ rol I r) → (I ⊨ y ≈ z) → ((w , z) ∈ rol I r)
rol-≈ (interp Δ _≈_ ref sym trans con rol con-≈ rol-≈) = rol-≈
{-
Additional functions
-}
-- Interpretation implies two elements are not equal
_⊨_≉_ : ∀ {Σ} → (I : Interp Σ) → (Δ I) → (Δ I) → Set
I ⊨ x ≉ y = ¬(I ⊨ x ≈ y)
-- the Empty Interpretation
emp : ∀ {Σ} → Interp Σ
emp = interp False (λ ()) (λ {}) (λ {}) (λ {}) (λ c → ∅) (λ r → ∅) (λ {}) (λ {})
-- relf implies ≈
≈-refl′ : ∀ {Σ} (I : Interp Σ) → ∀ {x y} → (x ≡ y) → (I ⊨ x ≈ y)
≈-refl′ I refl = ≈-refl I
|
{
"alphanum_fraction": 0.5707459517,
"avg_line_length": 43.2988505747,
"ext": "agda",
"hexsha": "f9be0638d4d10f2ec6bae0d656306041f9901090",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/TBox/Interp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/TBox/Interp.agda",
"max_line_length": 118,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/TBox/Interp.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-22T09:43:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-22T09:43:23.000Z",
"num_tokens": 1488,
"size": 3767
}
|
{-
This is the readme of the Agda mechanization accompanying our
POPL 2018 paper:
"Intrinsically-Typed Interpreters for Imperative Languages"
The repository is hosted here:
- https://github.com/metaborg/mj.agda
A rendered and linked version of this readme can be found here:
- https://metaborg.github.io/mj.agda/
This development has been tested against Agda 2.6.1.1 (see CHANGELOG for previous versions).
If you have this installed, you should simply be able to run
`make` in the project root. This will checkout the two dependencies in
`./lib/` first and then build this `./Readme.agda` which serves as the main
entrypoint to the development.
Alternatively you can run `make docs` to build the html version of
the development which is useful if you want to navigate the code
(starting e.g. in `docs/index.html`) without having an editor setup
for it. The html docs are syntax-highlighted and you can click
references to navigate to their definitions.
There are some minor differences between the Agda code used in the
paper and this mechanization. One general (but minor) discrepancy
is that the definitions in the paper are typed in a manner that is
not universe polymorphic. However, the development makes extensive
use of universe polymorphism, by explicitly quantifying over
universe levels (e.g., `i` in `{i} → Set i`).
Other discrepancies are summarized below in this readme.
-}
module Readme where
{-
* Section 2 *
We develop a monadic, well-typed interpreter for STLC and interpret
a few example programs.
Unlike the interpreter summarized in the paper, the STLC semantics
in the development makes use of integers and integer operations.
-}
open import STLC.Semantics
open import STLC.Examples
{-
* Section 3.1 - 3.3 *
We demonstrate how naively extending the approach to cover
imperative state is possible, but requires explicit weakening of
bound values in the interpreter.
-}
open import STLCRef.SemanticsLB
{-
* Section 3.4 : dependent passing style *
We can improve the semantics with a form of monadic strength to get
rid of explicit weakening.
-}
open import STLCRef.Semantics
open import STLCRef.Examples
{-
* Section 4 until 4.3 *
We implement the scopes and frames approach in the following small
Agda library.
-}
open import ScopesFrames.ScopesFrames
{-
* Section 4.4 *
We demonstrate the basic usage of this library on an interpreter for
STLC using scopes and frames.
-}
open import STLCSF.Semantics
{-
* Section 5 *
We show how our techniques scale by defining an intrinsically-typed
interpreter for Middleweight Java (MJ), a language with:
- Imperative objects
- Sub-typing
- Mutable, block-scoped environments
- Early returns
The only discrepancy between the code in this development and the
code shown in the paper is the following:
- Pattern matching lambdas are not useful for pattern matching
against. Instead of using `All` types with pattern matching
lambdas (Section 5.3 and 5.4), we use tagging predicates in
`MJSF.Syntax`.
Then there are some notable differences between the original
presentation of MJ and our development:
- Original MJ distinguishes promotable expressions (method
invocation and object creation) and all other expressions. We
admit arbitrary expressions to be promoted. This does not change
the semantics in any significant way. The expressions that we
allow to be promoted are side-effect free.
- returns are implemented by modeling non-void methods as having an
expression as its last statement (technically, this is enforced by
the type rules of Original MJ; in our development it is
syntactically enforced).
- MJ only has equality comparison expressions that can be used as
conditional expressions. We allow arbitrary expressions, and use
if-zero (`ifz`) for conditionals. This does not correspond to MJ
or Java, but it would be straightforward to add Booleans and use a
more conventional `if` statement instead.
- If-zero statements have ordinary statements as their
sub-statements. These can either be block statements or any other
statement which does not allocate a new frame. In Original MJ, if
statements must be blocks.
- We include integers and integer operations, which are not in
Original MJ.
- Our MJ syntax admits fields typed by `void`, which Original MJ
does not.
- Our MJ syntax incorporates a dedicated `this` expression for
referencing the "self" of an object.
-}
open import MJSF.Syntax
open import MJSF.Values
open import MJSF.Monad
open import MJSF.Semantics
{-
We demonstrate that our interpreter is executable:
-}
open import MJSF.Examples.Integer
open import MJSF.Examples.DynamicDispatch
{-
* Appendix A *
The following code artifacts *are not* described in the paper, but
are used as a comparison point to evaluate the impact on the
interpreter of using the scopes and frames model of binding.
This is an intrinsically-typed interpreter for MJ without the use of
scope-and-frames. Instead it describes a language-*dependent*
classtable construction to deal with object dot-access binding and
typing contexts and environments to deal with lexical binding
respectively.
-}
open import MJ.Syntax.Typed
-- lexical contexts
open import MJ.LexicalScope
-- class table
open import MJ.Classtable.Core
open import MJ.Classtable.Membership
open import MJ.Classtable.Code
-- semantics
open import MJ.Semantics.Values
open import MJ.Semantics.Environments
open import MJ.Semantics.Objects
open import MJ.Semantics.Objects.Flat
open import MJ.Semantics.Monadic
-- examples
open import MJ.Examples.Integer
open import MJ.Examples.Exceptions
open import MJ.Examples.While
open import MJ.Examples.DynDispatch
{-
* Appendix B *
Additionally we demonstrate briefly how Agda's typeclass mechanism
is not sufficiently strong to infer store extension facts for
weakening. (Notably Idris rejects an equivalent program as well
because the two instances are overlapping)
-}
open import Experiments.Infer
{-
* Appendix C *
Our interpreters make use of the operator `_^_` operator, defined
as:
(1) `_^_ : ∀ {Σ Γ}{p q : List Type → Set} ⦃ w : Weakenable q ⦄ →
M Γ p Σ → q Σ → M Γ (p ⊗ q) Σ`
This operator is strikingly similar to the strength operator that is
characteristic of strong monads:
(2) `_^_ : ∀ {p q} → M p → q → M (p ⊗ q)`
Here, `p` and `q` are objects in a category ℂ, and M is a monad for
ℂ.
In the following development we show how to define a monad that is
morally equivalent to ours. The monad in the development below is
defined over the category of monotone predicates. In this category,
the store-passing monad is a strong monad, with the usual notion of
monadic strength, i.e., (2) above.
We also show how, in this category, we can write an interpreter
without explicit weakening, by writing the interpreter in a
point-free style.
-}
open import Experiments.Category
open import Experiments.StrongMonad
open import Experiments.STLCRefPointfree
{-
We briefly outline how these experiments relate to our paper.
The interpreters in our paper are defined in terms of ordinary Agda
functions and indexed types. Agda functions and indexed types are
not guaranteed to be weakenable, and Agda does not have built-in
support for automatically weakening types across monadic binds. In
our paper, we address the weakening problem by making explicit use
in our interpreters of the `_^_` operator, which is morally
equivalent to the monadic strength operator for monotone predicates
over store types, defined in the categorical development above. Our
`_^_` operator explicitly requires `q` to be weakenable, which is a
fairly minimal requirement for convincing Agda's type checker that
carrying types over monadic binds is safe.
The categorical model enjoys a cleaner treatment of weakening, but
it is more cumbersome to write interpreters in Agda using this
model, because of the additional level of encoding imposed by
constructing and working with objects and morphisms in a category,
as encoded in Agda. However, we imagine that the categorical
development is a good target model for a future specification
language for dynamic semantics.
-}
|
{
"alphanum_fraction": 0.7575288656,
"avg_line_length": 33.2055335968,
"ext": "agda",
"hexsha": "5ce48ac0a9695f24a309679f1c3fd8354db5d246",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "Readme.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "Readme.agda",
"max_line_length": 94,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "Readme.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 2022,
"size": 8401
}
|
{-# OPTIONS --without-K #-}
{- Here, we derive our main theorem: there is a type in the n-th universe
that is not an n-type, implying the n-th universe is not n-truncated.
The n-th universe restricted to n-types is hence a 'strict' n-type.
For this, we first derive local-global looping in a modular way.
A technical point worth noting is that Agda does not implement
cumulative universes. Since that means the crucial steps in our
transformations (where we pass between universes uning univalence)
can not be expressed using equality without resorting to explicit lifting,
we decide to explicitely uses equivalences (and pointed equivalences,
respectively) instead where possible.
As a drawback, we have to use lemmata showing preservation of
(pointed) equivalences of various (pointed) type constructions,
a parametricity property derived for free
from univalence-induced equalities. -}
module Universe.Hierarchy where
open import lib.Basics
open import lib.Equivalences2
open import lib.NType2
open import lib.types.Bool
open import lib.types.Nat hiding (_+_)
open import lib.types.Paths
open import lib.types.Sigma
open import lib.types.TLevel
open import Universe.Utility.General
open import Universe.Utility.Pointed
open import Universe.Utility.TruncUniverse
-- *** Lemma 5.2 ***
{- Our Local-global looping principle.
We would like to state this principle in the form of
Ωⁿ⁺¹ (Type i , A) == ∀• a → Ωⁿ (A , a)
for n ≥ 1. Unfortunately, the two sides have different universe
levels since (Type i , A) lives in Type• (suc i) instead of Type• i.
Morally, this is outbalanced by the extra Ω on the left-hand side,
which might help explain on an intuitive level why
the n-th universe ends up being not an n-type.
The reason why the univalence principle (A ≡ B) ≃ (A ≃ B)
cannot be written as (A ≡ B) ≡ (A ≃ B) is precisely the same. -}
module _ {i} {A : Type i} where
-- The degenerate pre-base case carries around a propositional component.
Ω-Type : Ω (Type i , A) ≃• Σ• (Π• (A , λ a → (A , a))
, (is-equiv , idf-is-equiv _))
Ω-Type =
Ω (Type i , A)
≃•⟨ ide• _ ⟩
(A == A , idp)
≃•⟨ ua-equiv• ⁻¹• ⟩
(A ≃ A , ide _)
≃•⟨ ide• _ ⟩
((Σ (A → A) is-equiv) , (idf _ , idf-is-equiv _))
≃•⟨ ide• _ ⟩
Σ• (Π• (A , λ a → (A , a)) , (is-equiv , idf-is-equiv _))
≃•∎
-- The base case.
Ω²-Type : (Ω ^ 2) (Type i , A) ≃• Π• (A , λ a → Ω (A , a))
Ω²-Type =
(Ω ^ 2) (Type i , A)
≃•⟨ equiv-Ω Ω-Type ⟩
Ω (Σ• (Π• (A , λ a → (A , a)) , (is-equiv , idf-is-equiv _)))
≃•⟨ forget-Ω^-Σ•₂ {i} _ 1 (is-equiv-is-prop ∘ _) ⟩
Ω (Π• (A , λ a → (A , a)))
≃•⟨ Ω-Π•-comm _ ⟩
Π• (A , λ a → Ω (A , a))
≃•∎
-- The general case follows by permuting Ω and Π• repeatedly.
Ω^-Type : (n : ℕ) → (Ω ^ (n + 2)) (Type i , A)
≃• Π• (A , λ a → (Ω ^ (n + 1)) (A , a))
Ω^-Type n = Ω^-Π•-comm _ _ n ∘e• equiv-Ω^ n Ω²-Type
{- The pointed family P from the article.
It takes an n-type A and returns the space of (n+1)-loops
with basepoint A in U_n^n (the n-th universe restricted to n-types).
This crucial restriction to n-types implies it is just a set. -}
module _ (n : ℕ) (A : ⟨ n ⟩ -Type 「 n 」) where
-- *** Definition of P and Corollary 5.6 ***
P : ⟨0⟩ -Type• 「 n + 1 」
P = Ω^-≤' (n + 1) q where
q : ⟨ n + 1 ⟩ -Type• 「 n + 1 」
q = –> Σ-comm-snd ((⟨ n ⟩ -Type-≤ 「 n 」 , A))
-- Forgetting about the truncation level, we may present P as follows:
Q : Type• 「 n + 1 」
Q = (Ω ^ (n + 1)) (Type 「 n 」 , fst A)
P-is-Q : fst P ≃• Q
P-is-Q = equiv-Ω^ n (forget-Ω^-Σ•₂ _ 1 (λ _ → has-level-is-prop))
-- *** Definition of Loop and Lemma 5.7 ***
{- The type Loop of (images of) n-loops in U_(n-1)^(n-1) is
just the dependent sum over P except for the special case n ≡ 0,
where we take U_(-1)^(-1) (and hence Loop) to be the booleans.
The boilerplate with raise-≤T is just to verify Loop n is n-truncated.
The bulk of the rest of this module consists of showing
the n-th universe is not n-truncated at basepoint Loop n,
i.e. that Q n (Loop n) is not contractible.
Warning: The indexing of Loop starts at -1 in the article,
but we use natural numbers here (starting at 0),
thus everything is shifted by one. -}
Loop : (n : ℕ) → ⟨ n ⟩ -Type 「 n 」
Loop 0 = (Bool , Bool-is-set)
Loop (S n) = Σ-≤ (⟨ n ⟩ -Type-≤ 「 n 」) (λ A →
raise-≤T {n = ⟨ n + 1 ⟩} (≤T-+2+-l ⟨0⟩ (-2≤T _))
(fst (<– Σ-comm-snd (P n A))))
-- *** Section 2: the base case ***
-- The base case is as usual (there is a non-trivial automorphism on booleans).
base-case : ¬ (is-contr• (Q 0 (Loop 0)))
base-case c = Bool-false≠true false-is-true where
-- Negation.
~ : Bool → Bool
~ = λ {true → false; false → true}
-- Negation is an equivalence.
e : Bool ≃ Bool
e = equiv ~ ~ inv inv where
inv = λ {true → idp; false → idp}
-- Negation being equal to the identity yields a contradiction.
false-is-true =
false =⟨ ! (coe-β e true) ⟩
coe (ua e) true =⟨ ap (λ p → coe p true) (! (c (ua e))) ⟩
coe idp true =⟨ idp ⟩
true ∎
-- Let us now turn towards the successor case.
module _ (m : ℕ) where
-- We expand the type we are later going to assume contractible.
Q-L-is-… =
Q (m + 1) (Loop (m + 1))
≃•⟨ ide• _ ⟩
(Ω ^ (m + 2)) (_ , ⟦ Loop (m + 1) ⟧)
≃•⟨ (Ω^-Type m) ⟩
Π• (_ , λ {(A , q) → Ω ^ (m + 1) $ (⟦ Loop (m + 1) ⟧ , (A , q))})
≃•⟨ ide• _ ⟩
Π• (_ , λ {(A , q) → Ω ^ (m + 1) $ Σ• ((_ , A) , (base ∘ fst ∘ P m , q))})
≃•∎
-- What we really want is to arrive at contractibility of E (m ≥ 1)...
E = Π• (⟦ Loop (m + 1) ⟧ , λ {(A , q) → Ω ^ (m + 1) $ (⟨ m ⟩ -Type 「 m 」 , A)})
-- ...or at least show that the following element f of E is trivial (m ≡ 0).
f : base E
f (_ , q) = q
{- We want to use our assumption of contractibility of Q (n + 1) (Loop (n + 1))
to show that f is trivial, i.e. constant with value the basepoint. -}
f-is-trivial : (m : ℕ) → is-contr• (Q (m + 1) (Loop (m + 1))) → f m == pt (E m)
-- m ≡ 0
f-is-trivial 0 c = ap (λ f' → fst ∘ f')
(! (–> (equiv-is-contr• …-is-E') c f')) where
{- This is almost E, except for the additional component
specifying that the first component p should commute with q. -}
E' = Π• (_ , λ {(A , q) → (Σ (A == A) (λ p → q == q [ (λ x → x == x) ↓ p ])
, (idp , idp))})
-- This "almost" E comes from Q 1 (Loop 1), hence can be shown contractible.
…-is-E' : Q 1 (Loop 1) ≃• E'
…-is-E' = equiv-Π• (ide _ , Ω-Σ•-comm ∘ _) ∘e• Q-L-is-… 0
{- Fortunately, f can be 'extended' to an element f' of E',
and triviality of f' implies triviality of f. -}
f' = λ {(_ , q) → (q , ↓-idf=idf-in (∙=∙' q q))}
{- m ≥ 1: We can show Q (k + 2) (Loop (k + 2)) ≃ E (k + 1),
thus E is contractible, hence f trivial. -}
f-is-trivial (S k) c = ! (–> (equiv-is-contr• (…-is-E ∘e• Q-L-is-… (k + 1)))
c
(f (k + 1))) where
…-is-E : _ ≃• E (k + 1)
…-is-E = equiv-Π• (ide _ , equiv-Ω^ k ∘ (λ {(A , q) → forget-Ω^-Σ•₂
{「 k + 2 」} (base ∘ fst ∘ P (k + 1) , q) 2
(snd ∘ P (k + 1))}))
-- *** Lemma 5.8, part one ***
-- Our main lemma: like in the article, but in negative form.
main : (n : ℕ) → ¬ (is-contr• (Q n (Loop n)))
main 0 = base-case
main (S m) c = main m step where
{- We know Q (m + 1) (Loop (m + 1)) is contractible,
use that to show that the above f is trivial,
deduce f (Loop m , p) ≡ p is trivial for all p in P m (Loop m),
which implies P m (Loop m) is contractible.
But this is just another form of Q m (Loop m),
so the conclusion follows by induction hypothesis. -}
step : is-contr• (Q m (Loop m))
step = –> (equiv-is-contr• (P-is-Q m (Loop m)))
(λ q → app= (! (f-is-trivial m c)) (Loop m , q))
-- *** Lemma 5.8, part two ***
-- Alternate form of the main lemma
main' : (n : ℕ) → ¬ (is-contr• ((Ω ^ (n + 1)) (⟨ n ⟩ -Type 「 n 」 , Loop n )))
main' n = main n ∘ –> (equiv-is-contr• (P-is-Q n (Loop n)))
-- Small helper thingy
helpy : ∀ {i} {n : ℕ} {X : Type• i}
→ has-level• (n -1) X → is-contr• ((Ω ^ n) X)
helpy {n = n} {X} = <– contr•-equiv-prop
∘ trunc-many n
∘ transport (λ k → has-level• (k -2) X)
(+-comm 1 n)
-- Main theorems now fall out as corollaries.
module _ (n : ℕ) where
{- Recall that L n is n-truncated.
We also know it is not (n-1)-truncated, it is thus a 'strict' n-type. -}
Loop-is-not-trunc : ¬ (has-level (n -1) ⟦ Loop n ⟧)
Loop-is-not-trunc = main n ∘ helpy ∘ (λ t → universe-=-level t t)
-- *** Theorem 5.9 ***
-- The n-th universe is not n-truncated.
Type-is-not-trunc : ¬ (has-level ⟨ n ⟩ (Type 「 n 」))
Type-is-not-trunc = main n ∘ helpy
-- *** Theorem 5.11 ***
{- MAIN RESULT:
The n-th universe restricted to n-types is a 'strict' (n+1)-type. -}
Type-≤-is-not-trunc : ¬ (has-level ⟨ n ⟩ (⟨ n ⟩ -Type 「 n 」))
Type-≤-is-not-trunc = main' n ∘ helpy
|
{
"alphanum_fraction": 0.5476550681,
"avg_line_length": 39.547008547,
"ext": "agda",
"hexsha": "49f10c3a4ed9c5197306804dd6b0561ca2f76a8b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sattlerc/HoTT-Agda",
"max_forks_repo_path": "Universe/Hierarchy.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "sattlerc/HoTT-Agda",
"max_issues_repo_path": "Universe/Hierarchy.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "sattlerc/HoTT-Agda",
"max_stars_repo_path": "Universe/Hierarchy.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3399,
"size": 9254
}
|
-- Andreas, 2015-07-20, record patterns
open import Common.Product
open import Common.Prelude
open import Common.Equality
swap : {A B : Set} (p : A × B) → B × A
swap record{ proj₁ = a; proj₂ = b } = record{ proj₁ = b; proj₂ = a }
fst : {A : Set}{B : A → Set} (p : Σ A B) → A
fst record{ proj₁ = a } = a
snd : {A : Set}{B : A → Set} (p : Σ A B) → B (fst p)
snd record{ proj₂ = b } = b
module _ (A : Set) (B : A → Set) (C : (a : A) → B a → Set) where
Tr = Σ A (λ a → Σ (B a) (C a))
fst3 : Tr → A
fst3 record{ proj₁ = a } = a
snd3 : (t : Tr) → B (fst3 t)
snd3 record{ proj₂ = record { proj₁ = b }} = b
thd3 : (t : Tr) → C (fst3 t) (snd3 t)
thd3 record{ proj₂ = record { proj₂ = c }} = c
thd32 : (t u : Tr) → C (fst3 t) (snd3 t)
thd32 record{ proj₂ = record { proj₂ = c }}
record{ proj₂ = record { proj₂ = _ }} = c
postulate A : Set
record R : Set where
field f : A
T : Bool → Set
T true = R
T false = A
-- Postponed record pattern
test : ∀{b} → T b → b ≡ true → A
test record{f = a} refl = a
|
{
"alphanum_fraction": 0.5368217054,
"avg_line_length": 22.9333333333,
"ext": "agda",
"hexsha": "f3375e776cd9c565893acb993b9446547d61b7c2",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/RecordPattern.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/RecordPattern.agda",
"max_line_length": 68,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/RecordPattern.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 421,
"size": 1032
}
|
{-# OPTIONS --safe #-} -- --without-K #-}
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl; sym; subst; cong; trans)
open import Relation.Nullary.Decidable using (toWitness; fromWitness)
open import Relation.Nullary using (yes; no)
open import Function.Reasoning
open import Function using (_∘_)
import Data.Empty as Empty
import Data.Product as Product
import Data.Product.Properties as Productₚ
import Data.Unit as Unit
import Data.Nat.Base as Nat
import Data.Vec.Base as Vec
import Data.Vec.Properties as Vecₚ
import Data.Fin.Base as Fin
import Data.Fin.Properties as Finₚ
import Data.Vec.Relation.Unary.All as All
open Empty using (⊥-elim)
open Unit using (tt)
open Nat using (ℕ; zero; suc)
open Vec using (Vec; []; _∷_)
open All using (All; []; _∷_)
open Fin using (Fin ; zero ; suc)
open Product using (Σ-syntax; ∃-syntax; _×_; _,_; proj₁; proj₂)
import PiCalculus.Syntax
open PiCalculus.Syntax.Scoped
open import PiCalculus.Semantics
open import PiCalculus.Semantics.Properties
open import PiCalculus.LinearTypeSystem.Algebras
module PiCalculus.LinearTypeSystem.Substitution (Ω : Algebras) where
open Algebras Ω
open import PiCalculus.LinearTypeSystem Ω
open import PiCalculus.LinearTypeSystem.ContextLemmas Ω
open import PiCalculus.LinearTypeSystem.Framing Ω
private
variable
n : ℕ
i j : Fin n
t t' : Type
γ : PreCtx n
idx idx' : Idx
idxs : Idxs n
x y z m m' l δ : Usage idx ²
Γ Γₗ Γᵣ Ξₗ Ξᵣ Δ Δ' Ξ' Θ Ψ Ξ Ψ' Θ' Δₗ Δᵣ Β : Ctx idxs
P : Scoped n
midpoint : {Γᵢ Γ Δ Ψ ΔP Ξᵢ ΔQ Ψᵢ : Ctx idxs} {m n : Usage idx ²}
→ Γᵢ ∋[ i ] m ▹ Γ
→ Γ ≔ Δ ⊗ Ψ
→ All.lookup i Δ ≡ ℓ∅
→ Γᵢ ≔ ΔP ⊗ Ξᵢ
→ Ξᵢ ≔ ΔQ ⊗ Ψᵢ
→ Ψᵢ ∋[ i ] n ▹ Ψ
→ Σ[ δ ∈ Usage idx ² ]
Σ[ Θ ∈ Ctx idxs ]
Σ[ Δ₁ ∈ Ctx idxs ]
Σ[ Δ₂ ∈ Ctx idxs ] (
Ξᵢ ∋[ i ] δ ▹ Θ
× Γ ≔ Δ₁ ⊗ Θ
× Θ ≔ Δ₂ ⊗ Ψ)
midpoint {i = zero} (zero γᵢ≔m∙γ) (Γ≔Δ∙Ψ , γ≔δ∙ψ) refl (Γᵢ≔ΔP∙Ξᵢ , γᵢ≔δp∙ξᵢ) (Ξᵢ≔ΔQ∙Ψᵢ , ξᵢ≔δq∙ψᵢ) (zero ψᵢ≔n∙ψ)
rewrite ∙²-unique γ≔δ∙ψ ∙²-idˡ =
let _ , ξᵢ≔δ∙θ , _ = ∙²-assoc⁻¹ ξᵢ≔δq∙ψᵢ ψᵢ≔n∙ψ in
_ , _ , (_ -, _) , _ , zero ξᵢ≔δ∙θ , (Γᵢ≔ΔP∙Ξᵢ , ∙²-idˡ) , (Ξᵢ≔ΔQ∙Ψᵢ , ∙²-idˡ)
midpoint {i = suc i} (suc Γᵢ≔m∙Γ) (Γ≔Δ∙Ψ , _) Δ[i]≡ℓ∅ (Γᵢ≔ΔP∙Ξᵢ , γᵢ≔δp∙ξᵢ) (Ξᵢ≔ΔQ∙Ψᵢ , ξᵢ≔δq∙ψᵢ) (suc ψᵢ≔n∙ψ) =
let _ , _ , _ , _ , Ξᵢ≔δ∙Θ , Γ≔Δ₁∙Θ , Θ≔Δ₂∙Ψ = midpoint Γᵢ≔m∙Γ Γ≔Δ∙Ψ Δ[i]≡ℓ∅ Γᵢ≔ΔP∙Ξᵢ Ξᵢ≔ΔQ∙Ψᵢ ψᵢ≔n∙ψ in
_ , _ , (_ -, _) , _ , suc Ξᵢ≔δ∙Θ , (Γ≔Δ₁∙Θ , γᵢ≔δp∙ξᵢ) , (Θ≔Δ₂∙Ψ , ξᵢ≔δq∙ψᵢ)
cutpoint : {Γ Δ Θ Γⱼ : Ctx idxs} {m n l : Usage idx ²}
→ Γ ≔ Δ ⊗ Θ
→ Γⱼ ∋[ j ] m ▹ Γ
→ m ≔ n ∙² l
→ Σ[ Θⱼ ∈ Ctx idxs ] (Θⱼ ∋[ j ] l ▹ Θ)
cutpoint (_ , γ≔) (zero x) m≔ =
let
_ , _ , a = ∙²-assoc x m≔
_ , _ , c = ∙²-assoc (∙²-comm a) γ≔
in _ , zero (∙²-comm c)
cutpoint (Γ≔ , _) (suc ∋j) m≔ with cutpoint Γ≔ ∋j m≔
cutpoint (Γ≔ , _) (suc ∋j) m≔ | _ , r = _ , suc r
∋-subst : {Γ Γᵢ Γⱼ Δ Ψ Ψᵢ Ψⱼ Ξᵢ CONT : Ctx idxs} {i j x : Fin n} {mx : Usage idx' ²} {m n : Usage idx ²}
→ Vec.lookup γ i ≡ Vec.lookup γ j
→ Γᵢ ∋[ i ] m ▹ Γ
→ Γⱼ ∋[ j ] m ▹ Γ
→ Ψᵢ ∋[ i ] n ▹ Ψ
→ Ψⱼ ∋[ j ] n ▹ Ψ
→ Γ ≔ Δ ⊗ Ψ
→ All.lookup i Δ ≡ ℓ∅
→ γ ; Γᵢ ∋[ x ] t ; mx ▹ Ξᵢ
→ Ξᵢ ≔ CONT ⊗ Ψᵢ
→ Σ[ Ξⱼ ∈ Ctx idxs ]
Σ[ Θ ∈ Ctx idxs ]
Σ[ Δ' ∈ Ctx idxs ]
Σ[ m' ∈ Usage idx ² ]
(γ ; Γⱼ ∋[ x [ i ↦ j ]' ] t ; mx ▹ Ξⱼ
× Ξᵢ ∋[ i ] m' ▹ Θ
× Ξⱼ ∋[ j ] m' ▹ Θ
× Θ ≔ Δ' ⊗ Ψ
× All.lookup i Δ' ≡ ℓ∅)
∋-subst {i = i} {x = x} eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ (∋t , ∋x) Ξᵢ≔CONT∙Ψᵢ with i Finₚ.≟ x
∋-subst {i = i} {x = x} eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ (∋t , ∋x) Ξᵢ≔CONT∙Ψᵢ | yes refl with ∋-≡Idx ∋i | ∋-≡Idx ∋x
∋-subst {i = i} {x = x} eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ (∋t , ∋x) Ξᵢ≔CONT∙Ψᵢ | yes refl | refl | refl =
let
_ , Ξᵢ≔CONTn∙Ψ , _ = ⊗-assoc⁻¹ Ξᵢ≔CONT∙Ψᵢ (proj₁ (proj₂ (∋-⊗ ∈i)))
δ , m≔ℓ∙δ = boil ∋i ∋x Ξᵢ≔CONTn∙Ψ Γ≔Δ∙Ψ Δ∋iℓ∅
_ , Γᵢ≔ℓ∙⁇ᵢ , ⁇ᵢ≔δ∙Γ = split m≔ℓ∙δ ∋i
_ , Γⱼ≔ℓ∙⁇ⱼ , ⁇ⱼ≔δ∙Γ = split m≔ℓ∙δ ∋j
⁇ᵢ≡Ξᵢ = ∋-uniqueʳ Γᵢ≔ℓ∙⁇ᵢ ∋x
Ξᵢ≔δ∙Γ = subst (λ ● → ● ∋[ _ ] δ ▹ _) ⁇ᵢ≡Ξᵢ ⁇ᵢ≔δ∙Γ
in _ , _ , _ , _ , (≡Type-∋ (trans (sym eq) (∋-≡Type ∋t)) , Γⱼ≔ℓ∙⁇ⱼ) , Ξᵢ≔δ∙Γ , ⁇ⱼ≔δ∙Γ , Γ≔Δ∙Ψ , Δ∋iℓ∅
∋-subst {i = i} {x = x} eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ (∋t , ∋x) Ξᵢ≔CONT∙Ψᵢ | no i≢x =
let
_ , Ξᵢ≔m∙Θ , Γ≔ℓ∙Θ = diamond i≢x ∋x ∋i
_ , Γⱼ≔m'∙Γ , m'≔m∙ε = ∋-⊗ ∋j
_ , Γ≔ℓ'∙Θ , ℓ'≔ℓ∙ε = ∋-⊗ Γ≔ℓ∙Θ
_ , Γⱼ≔ℓ'∙Ξⱼ , Ξⱼ≔m'∙Θ = reverse Γⱼ≔m'∙Γ Γ≔ℓ'∙Θ
_ , Γᵢ≔ℓCONT∙Ψᵢ , _ = ⊗-assoc⁻¹ (proj₁ (proj₂ (∋-⊗ ∋x))) Ξᵢ≔CONT∙Ψᵢ
_ , Ξᵢ≔CONTn∙Ψ , _ = ⊗-assoc⁻¹ Ξᵢ≔CONT∙Ψᵢ (proj₁ (proj₂ (∋-⊗ ∈i)))
_ , Θ≔Δ'∙Ψ = outer-diamond i≢x ∋i ∋x Γ≔ℓ∙Θ Ξᵢ≔m∙Θ Γ≔Δ∙Ψ Ξᵢ≔CONTn∙Ψ
_ , Δ'∋iℓ∅ = split-ℓ∅ Γ≔Δ∙Ψ (proj₁ (proj₂ (∋-⊗ Γ≔ℓ∙Θ))) Θ≔Δ'∙Ψ Δ∋iℓ∅
in _ , _ , _ , _ , (∋t , ⊗-∋ Γⱼ≔ℓ'∙Ξⱼ ℓ'≔ℓ∙ε) , Ξᵢ≔m∙Θ , ⊗-∋ Ξⱼ≔m'∙Θ m'≔m∙ε , Θ≔Δ'∙Ψ , Δ'∋iℓ∅
⊢-subst-ih : ∀ {γ : PreCtx n} {idxs : Idxs n} {Γ Γᵢ Γⱼ Δ Ψ Ψᵢ Ψⱼ : Ctx idxs} {i j : Fin n} {m n : Usage idx ²}
→ Vec.lookup γ i ≡ Vec.lookup γ j
→ Γᵢ ∋[ i ] m ▹ Γ
→ Γⱼ ∋[ j ] m ▹ Γ
→ Ψᵢ ∋[ i ] n ▹ Ψ
→ Ψⱼ ∋[ j ] n ▹ Ψ
→ Γ ≔ Δ ⊗ Ψ
→ All.lookup i Δ ≡ ℓ∅
→ γ ; Γᵢ ⊢ P ▹ Ψᵢ
→ γ ; Γⱼ ⊢ P [ i ↦ j ] ▹ Ψⱼ
⊢-subst-ih {i = i} eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ 𝟘 with ⊗-get i Γ≔Δ∙Ψ | ∋-≡Idx ∈i | ∋-≡Idx ∋i
⊢-subst-ih {i = i} eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ 𝟘 | Γi≔Δi∙Ψi | refl | refl with ∋-lookup-≡ ∈i | ∋-lookup-≡ ∋i
⊢-subst-ih {i = i} eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ 𝟘 | Γi≔Δi∙Ψi | refl | refl | qeq | qe
rewrite Δ∋iℓ∅ | ∙²-unique Γi≔Δi∙Ψi ∙²-idˡ | ∙²-uniqueˡ qe qeq | ∋-uniqueʳ ∋i ∈i | ∋-uniqueˡ ∋j ∈j = 𝟘
⊢-subst-ih eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ (ν t m μ ⊢P) =
ν t m μ (⊢-subst-ih eq (suc ∋i) (suc ∋j) (suc ∈i) (suc ∈j) (Γ≔Δ∙Ψ , ∙²-idʳ) Δ∋iℓ∅ ⊢P)
⊢-subst-ih eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ (∋x ⦅⦆ ⊢P) with ⊢-⊗ ⊢P
⊢-subst-ih eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ (∋x ⦅⦆ ⊢P) | (_ -, _) , (Ξᵢ≔δ⊢P∙Ψᵢ , _) =
let _ , _ , _ , _ , ∋x' , ∋i' , ∋j' , Θ≔Δ'∙Ψ , Δ'∋iℓ∅ = ∋-subst eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ ∋x Ξᵢ≔δ⊢P∙Ψᵢ in
∋x' ⦅⦆ ⊢-subst-ih eq (suc ∋i') (suc ∋j') (suc ∈i) (suc ∈j) (Θ≔Δ'∙Ψ , ∙²-idʳ) Δ'∋iℓ∅ ⊢P
⊢-subst-ih eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ ((∋tx , ∋x) ⟨ ∋ty , ∋y ⟩ ⊢P) =
let
_ , δ⊢P = ⊢-⊗ ⊢P
_ , δy , _ = ∋-⊗ ∋y
_ , δy⊢P , _ = ⊗-assoc⁻¹ δy δ⊢P
_ , _ , _ , _ , ∋x' , ∋i' , ∋j' , Θ≔Δ'∙Ψ , Δ'∋iℓ∅ = ∋-subst eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ (∋tx , ∋x) δy⊢P
_ , _ , _ , _ , ∋y' , ∋i'' , ∋j'' , Θ≔Δ''∙Ψ , Δ''∋iℓ∅ = ∋-subst eq ∋i' ∋j' ∈i ∈j Θ≔Δ'∙Ψ Δ'∋iℓ∅ (∋ty , ∋y) δ⊢P
in ∋x' ⟨ ∋y' ⟩ ⊢-subst-ih eq ∋i'' ∋j'' ∈i ∈j Θ≔Δ''∙Ψ Δ''∋iℓ∅ ⊢P
⊢-subst-ih eq ∋i ∋j ∈i ∈j Γ≔Δ∙Ψ Δ∋iℓ∅ (_∥_ {Δ = Ξᵢ} ⊢P ⊢Q) =
let
_ , Γᵢ≔δ⊢P∙Ξᵢ = ⊢-⊗ ⊢P
_ , Ξᵢ≔δ⊢Q∙Ψᵢ = ⊢-⊗ ⊢Q
_ , _ , _ , _ , Ξᵢ≔δ∙Θ , Γ≔Δ₁∙Θ , Θ≔Δ₂∙Ψ = midpoint ∋i Γ≔Δ∙Ψ Δ∋iℓ∅ Γᵢ≔δ⊢P∙Ξᵢ Ξᵢ≔δ⊢Q∙Ψᵢ ∈i
_ , Ξᵢ≔δ'∙Θ , δ'≔δ∙ε = ∋-⊗ Ξᵢ≔δ∙Θ
_ , Γᵢ≔δ'∙⁇ᵢ , ⁇ᵢ≔δ⊢P∙Θ = reverse Γᵢ≔δ⊢P∙Ξᵢ Ξᵢ≔δ'∙Θ
Δ₁∋iℓ∅ , Δ₂∋iℓ∅ = split-ℓ∅ Γ≔Δ∙Ψ Γ≔Δ₁∙Θ Θ≔Δ₂∙Ψ Δ∋iℓ∅
_ , m≔δ∙δ⊢P = boil ∋i (⊗-∋ Γᵢ≔δ'∙⁇ᵢ δ'≔δ∙ε) ⁇ᵢ≔δ⊢P∙Θ Γ≔Δ₁∙Θ Δ₁∋iℓ∅
_ , Ξⱼ≔δ∙Θ = cutpoint Γ≔Δ₁∙Θ ∋j (∙²-comm m≔δ∙δ⊢P)
in ⊢-subst-ih eq ∋i ∋j Ξᵢ≔δ∙Θ Ξⱼ≔δ∙Θ Γ≔Δ₁∙Θ Δ₁∋iℓ∅ ⊢P ∥ ⊢-subst-ih eq Ξᵢ≔δ∙Θ Ξⱼ≔δ∙Θ ∈i ∈j Θ≔Δ₂∙Ψ Δ₂∋iℓ∅ ⊢Q
switch : ∀ {γ : PreCtx n} {idxs : Idxs n} {Γ Ξ Ψ : Ctx idxs} {t idx} {m : Usage idx ²}
→ γ -, t ; Γ -, m ⊢ P ▹ Ψ -, ℓ∅
→ Ψ ∋[ j ] m ▹ Ξ
→ ∃[ Θ ] (Γ ∋[ j ] m ▹ Θ
× γ -, t ; Θ -, m ⊢ P ▹ Ξ -, ℓ∅)
switch ⊢P ∋j with ⊢-⊗ ⊢P | ∋-⊗ ∋j
switch ⊢P ∋j | (Δ⊢P -, _) , (Γ≔ , _) | _ , Ψ≔ , _ =
let W , Γ≔Δj∙W , W≔Δ⊢P∙Ξ = ⊗-assoc (⊗-comm Γ≔) Ψ≔ in
_ , ∋-frame Ψ≔ Γ≔Δj∙W ∋j , ⊢-frame (Γ≔ , ∙²-idʳ) (⊗-comm W≔Δ⊢P∙Ξ , ∙²-idʳ) ⊢P
⊢-subst : ∀ {γ : PreCtx n} {idxs : Idxs n} {Γ Ξ Ψ : Ctx idxs} {t idx} {m : Usage idx ²}
→ γ ; Ψ ∋[ j ] t ; m ▹ Ξ
→ γ -, t ; Γ -, m ⊢ P ▹ Ψ -, ℓ∅
→ γ -, t ; Γ -, m ⊢ P [ zero ↦ suc j ] ▹ Ξ -, m
⊢-subst {Γ = Γ} {Ξ} (t , y) ⊢P with switch ⊢P y
⊢-subst {Γ = Γ} {Ξ} (t , y) ⊢P | Θ , y' , ⊢P' with ⊢-⊗ ⊢P'
⊢-subst {Γ = Γ} {Ξ} (t , y) ⊢P | Θ , y' , ⊢P' | (_ -, _) , (⊢P'≔ , _) =
⊢-frame (proj₂ Γ≔ , ∙²-idˡ) (proj₂ Γ≔ , ∙²-idˡ) ⊢P''
where
⊢P'' = ⊢-subst-ih (sym (∋-≡Type t)) (zero ∙²-idʳ) (suc y') (zero ∙²-idʳ) (suc (∋-ℓ∅ (∋-≡Idx y))) (⊢P'≔ , ∙²-idʳ) refl ⊢P'
Γ≔ : ∃[ Δ ] (Γ ≔ Δ ⊗ Ξ)
Γ≔ with ⊢-⊗ ⊢P''
Γ≔ | (_ -, _) , (x , _) = _ , x
|
{
"alphanum_fraction": 0.4613813814,
"avg_line_length": 42.2588832487,
"ext": "agda",
"hexsha": "c1bebbb64243901a6d3b5207594e5fd82ecd8c74",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T16:24:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-25T13:57:13.000Z",
"max_forks_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/typing-linear-pi",
"max_forks_repo_path": "src/PiCalculus/LinearTypeSystem/Substitution.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_issues_repo_issues_event_max_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guilhermehas/typing-linear-pi",
"max_issues_repo_path": "src/PiCalculus/LinearTypeSystem/Substitution.agda",
"max_line_length": 123,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/typing-linear-pi",
"max_stars_repo_path": "src/PiCalculus/LinearTypeSystem/Substitution.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-14T15:18:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-02T23:32:11.000Z",
"num_tokens": 5901,
"size": 8325
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Homotopy.Connected where
open import Cubical.Core.Everything
open import Cubical.Foundations.Everything
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Path
open import Cubical.Foundations.Univalence
open import Cubical.Functions.Fibration
open import Cubical.Data.Nat
open import Cubical.Data.Prod hiding (map)
open import Cubical.Data.Sigma hiding (_×_)
open import Cubical.HITs.Nullification
open import Cubical.HITs.Susp
open import Cubical.HITs.SmashProduct
open import Cubical.HITs.Truncation as Trunc renaming (rec to trRec)
open import Cubical.Homotopy.Loopspace
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn.Base
open import Cubical.HITs.S1
open import Cubical.Data.Bool
open import Cubical.Data.Unit
-- Note that relative to most sources, this notation is off by +2
isConnected : ∀ {ℓ} (n : HLevel) (A : Type ℓ) → Type ℓ
isConnected n A = isContr (hLevelTrunc n A)
isConnectedFun : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ')
isConnectedFun n f = ∀ b → isConnected n (fiber f b)
isTruncatedFun : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ')
isTruncatedFun n f = ∀ b → isOfHLevel n (fiber f b)
isConnectedSubtr : ∀ {ℓ} {A : Type ℓ} (n m : HLevel)
→ isConnected (m + n) A
→ isConnected n A
isConnectedSubtr {A = A} n m iscon =
isOfHLevelRetractFromIso 0 (truncOfTruncIso n m) (helper n iscon)
where
helper : (n : ℕ) → isConnected (m + n) A → isContr (hLevelTrunc n (hLevelTrunc (m + n) A))
helper zero iscon = isContrUnit*
helper (suc n) iscon = ∣ iscon .fst ∣ , (Trunc.elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ a → cong ∣_∣ (iscon .snd a))
isConnectedFunSubtr : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (n m : HLevel) (f : A → B)
→ isConnectedFun (m + n) f
→ isConnectedFun n f
isConnectedFunSubtr n m f iscon b = isConnectedSubtr n m (iscon b)
private
typeToFiberIso : ∀ {ℓ} (A : Type ℓ) → Iso A (fiber (λ (x : A) → tt) tt)
Iso.fun (typeToFiberIso A) x = x , refl
Iso.inv (typeToFiberIso A) = fst
Iso.rightInv (typeToFiberIso A) b i = fst b , (isOfHLevelSuc 1 (isPropUnit) tt tt (snd b) refl) i
Iso.leftInv (typeToFiberIso A) a = refl
typeToFiber : ∀ {ℓ} (A : Type ℓ) → A ≡ fiber (λ (x : A) → tt) tt
typeToFiber A = isoToPath (typeToFiberIso A)
module elim {ℓ ℓ' : Level} {A : Type ℓ} {B : Type ℓ'} (f : A → B) where
private
inv : ∀ {ℓ'''} (n : HLevel) (P : B → TypeOfHLevel ℓ''' (suc n))
→ ((a : A) → P (f a) .fst)
→ (b : B)
→ hLevelTrunc (suc n) (fiber f b) → P b .fst
inv n P t b =
Trunc.rec
(P b .snd)
(λ {(a , p) → subst (fst ∘ P) p (t a)})
isIsoPrecompose : ∀ {ℓ'''} (n : ℕ) (P : B → TypeOfHLevel ℓ''' n)
→ isConnectedFun n f
→ Iso ((b : B) → P b .fst) ((a : A) → P (f a) .fst)
isIsoPrecompose zero P fConn = isContr→Iso (isOfHLevelΠ _ (λ b → P b .snd)) (isOfHLevelΠ _ λ a → P (f a) .snd)
Iso.fun (isIsoPrecompose (suc n) P fConn) = _∘ f
Iso.inv (isIsoPrecompose (suc n) P fConn) t b = inv n P t b (fConn b .fst)
Iso.rightInv (isIsoPrecompose (suc n) P fConn) t =
funExt λ a → cong (inv n P t (f a)) (fConn (f a) .snd ∣ a , refl ∣)
∙ substRefl {B = fst ∘ P} (t a)
Iso.leftInv (isIsoPrecompose (suc n) P fConn) s =
funExt λ b →
Trunc.elim
{B = λ d → inv n P (s ∘ f) b d ≡ s b}
(λ _ → isOfHLevelPath (suc n) (P b .snd) _ _)
(λ {(a , p) i → transp (λ j → P (p (j ∨ i)) .fst) i (s (p i))})
(fConn b .fst)
isEquivPrecompose : ∀ {ℓ'''} (n : ℕ) (P : B → TypeOfHLevel ℓ''' n)
→ isConnectedFun n f
→ isEquiv (λ(s : (b : B) → P b .fst) → s ∘ f)
isEquivPrecompose zero P fConn = isoToIsEquiv theIso
where
theIso : Iso ((b : B) → P b .fst) ((a : A) → P (f a) .fst)
Iso.fun theIso = λ(s : (b : B) → P b .fst) → s ∘ f
Iso.inv theIso = λ _ b → P b .snd .fst
Iso.rightInv theIso g = funExt λ x → P (f x) .snd .snd (g x)
Iso.leftInv theIso g = funExt λ x → P x .snd .snd (g x)
isEquivPrecompose (suc n) P fConn = isoToIsEquiv (isIsoPrecompose (suc n) P fConn)
isConnectedPrecompose : (n : ℕ) → ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') n)
→ hasSection (λ(s : (b : B) → P b .fst) → s ∘ f))
→ isConnectedFun n f
isConnectedPrecompose zero P→sect b = isContrUnit*
isConnectedPrecompose (suc n) P→sect b = c n P→sect b , λ y → sym (fun n P→sect b y)
where
P : (n : HLevel) → ((P : B → TypeOfHLevel ℓ (suc n))
→ hasSection (λ(s : (b : B) → P b .fst) → s ∘ f))
→ B → Type _
P n s b = hLevelTrunc (suc n) (fiber f b)
c : (n : HLevel) → ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') (suc n))
→ hasSection (λ(s : (b : B) → P b .fst) → s ∘ f)) → (b : B)
→ hLevelTrunc (suc n) (fiber f b)
c n s = (s λ b → (hLevelTrunc (suc n) (fiber f b) , isOfHLevelTrunc _)) .fst
λ a → ∣ a , refl ∣
fun : (n : HLevel) (P→sect : ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') (suc n))
→ hasSection λ(s : (b : B) → P b .fst) → s ∘ f))
→ (b : B) (w : (hLevelTrunc (suc n) (fiber f b)))
→ w ≡ c n P→sect b
fun n P→sect b = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _)
λ a → J (λ b p → ∣ (fst a) , p ∣ ≡ c n P→sect b)
(c* (fst a))
(snd a)
where
c* : ((a : A) → ∣ (a , refl {x = f a}) ∣ ≡ c n P→sect (f a))
c* a = sym (cong (λ x → x a) (P→sect (λ b → hLevelTrunc (suc n) (fiber f b) , isOfHLevelTrunc _) .snd λ a → ∣ a , refl ∣))
isOfHLevelPrecomposeConnected : ∀ {ℓ ℓ' ℓ''} (k : HLevel) (n : HLevel)
{A : Type ℓ} {B : Type ℓ'} (P : B → TypeOfHLevel ℓ'' (k + n)) (f : A → B)
→ isConnectedFun n f
→ isOfHLevelFun k (λ(s : (b : B) → P b .fst) → s ∘ f)
isOfHLevelPrecomposeConnected zero n P f fConn =
elim.isEquivPrecompose f n P fConn .equiv-proof
isOfHLevelPrecomposeConnected (suc k) n P f fConn t =
isOfHLevelPath'⁻ k
λ {(s₀ , p₀) (s₁ , p₁) →
isOfHLevelRetractFromIso k (invIso ΣPathIsoPathΣ)
(subst (isOfHLevel k)
(sym (fiberPath (s₀ , p₀) (s₁ , p₁)))
(isOfHLevelRetract k
(λ {(q , α) → (funExt⁻ q) , (cong funExt⁻ α)})
(λ {(h , β) → (funExt h) , (cong funExt β)})
(λ _ → refl)
(isOfHLevelPrecomposeConnected k n
(λ b → (s₀ b ≡ s₁ b) , isOfHLevelPath' (k + n) (P b .snd) _ _)
f fConn
(funExt⁻ (p₀ ∙∙ refl ∙∙ sym p₁)))))}
indMapEquiv→conType : ∀ {ℓ} {A : Type ℓ} (n : HLevel)
→ ((B : TypeOfHLevel ℓ n)
→ isEquiv (λ (b : (fst B)) → λ (a : A) → b))
→ isConnected n A
indMapEquiv→conType {A = A} zero BEq = isContrUnit*
indMapEquiv→conType {A = A} (suc n) BEq =
isOfHLevelRetractFromIso 0 (mapCompIso {n = (suc n)} (typeToFiberIso A))
(elim.isConnectedPrecompose (λ _ → tt) (suc n)
(λ P → ((λ a _ → a) ∘ invIsEq (BEq (P tt)))
, λ a → equiv-proof (BEq (P tt)) a .fst .snd)
tt)
isConnectedPath : ∀ {ℓ} (n : HLevel) {A : Type ℓ}
→ isConnected (suc n) A
→ (a₀ a₁ : A) → isConnected n (a₀ ≡ a₁)
isConnectedPath zero connA a₀ a₁ = isContrUnit*
isConnectedPath (suc n) connA a₀ a₁ =
isOfHLevelRetractFromIso 0
(invIso (PathIdTruncIso (suc n)))
(isContr→isContrPath connA _ _)
isConnectedPathP : ∀ {ℓ} (n : HLevel) {A : I → Type ℓ}
→ isConnected (suc n) (A i1)
→ (a₀ : A i0) (a₁ : A i1) → isConnected n (PathP A a₀ a₁)
isConnectedPathP n con a₀ a₁ =
subst (isConnected n) (sym (PathP≡Path _ _ _))
(isConnectedPath n con _ _)
isConnectedRetract : ∀ {ℓ ℓ'} (n : HLevel)
{A : Type ℓ} {B : Type ℓ'}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isConnected n B → isConnected n A
isConnectedRetract zero _ _ _ _ = isContrUnit*
isConnectedRetract (suc n) f g h =
isContrRetract
(Trunc.map f)
(Trunc.map g)
(Trunc.elim
(λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(λ a → cong ∣_∣ (h a)))
isConnectedRetractFromIso : ∀ {ℓ ℓ'} (n : HLevel)
{A : Type ℓ} {B : Type ℓ'}
→ Iso A B
→ isConnected n B → isConnected n A
isConnectedRetractFromIso n e =
isConnectedRetract n
(Iso.fun e)
(Iso.inv e)
(Iso.leftInv e)
isConnectedPoint : ∀ {ℓ} (n : HLevel) {A : Type ℓ}
→ isConnected (suc n) A
→ (a : A) → isConnectedFun n (λ(_ : Unit) → a)
isConnectedPoint n connA a₀ a =
isConnectedRetract n
snd (_ ,_) (λ _ → refl)
(isConnectedPath n connA a₀ a)
isConnectedPoint2 : ∀ {ℓ} (n : HLevel) {A : Type ℓ} (a : A)
→ isConnectedFun n (λ(_ : Unit) → a)
→ isConnected (suc n) A
isConnectedPoint2 n {A = A} a connMap = indMapEquiv→conType _ λ B → isoToIsEquiv (theIso B)
where
module _ {ℓ' : Level} (B : TypeOfHLevel ℓ' (suc n))
where
helper : (f : A → fst B) → (a2 : A) → f a2 ≡ f a
helper f = equiv-proof (elim.isEquivPrecompose (λ _ → a) n (λ a2 → (f a2 ≡ f a) ,
isOfHLevelPath' n (snd B) (f a2) (f a)) connMap) (λ _ → refl) .fst .fst
theIso : Iso (fst B) (A → fst B)
Iso.fun theIso b a = b
Iso.inv theIso f = f a
Iso.rightInv theIso f = funExt λ y → sym (helper f y)
Iso.leftInv theIso _ = refl
connectedTruncIso : ∀ {ℓ} {A B : Type ℓ} (n : HLevel) (f : A → B)
→ isConnectedFun n f
→ Iso (hLevelTrunc n A) (hLevelTrunc n B)
connectedTruncIso {A = A} {B = B} zero f con = isContr→Iso isContrUnit* isContrUnit*
connectedTruncIso {A = A} {B = B} (suc n) f con = g
where
back : B → hLevelTrunc (suc n) A
back y = map fst ((con y) .fst)
backSection : (b : B) → Path (hLevelTrunc (suc n) B)
(Trunc.rec (isOfHLevelTrunc (suc n))
(λ a → ∣ f a ∣)
(Trunc.rec {n = n}
{B = hLevelTrunc (suc n) A} (isOfHLevelTrunc (suc n))
back ∣ b ∣))
∣ b ∣
backSection b = helper (λ p → map f p ≡ ∣ b ∣)
(λ x → (isOfHLevelSuc (suc n) (isOfHLevelTrunc (suc n)))
(map f (map fst x)) ∣ b ∣)
(λ a p → cong ∣_∣ p)
(fst (con b))
where
helper : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : A → Type ℓ'} (P : hLevelTrunc (suc n) A → Type ℓ'')
→ ((x : hLevelTrunc (suc n) (Σ A B)) → isOfHLevel (suc n) (P (map fst x)))
→ ((a : A) (b : B a) → P ∣ a ∣)
→ (p : hLevelTrunc (suc n) (Σ A B))
→ P (map fst p)
helper P hlev pf = Trunc.elim hlev λ pair → pf (fst pair) (snd pair)
g : Iso (hLevelTrunc (suc n) A) (hLevelTrunc (suc n) B)
Iso.fun g = map f
Iso.inv g = Trunc.rec (isOfHLevelTrunc _) back
Iso.leftInv g = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _)
λ a → cong (map fst) (con (f a) .snd ∣ a , refl ∣)
Iso.rightInv g = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _)
backSection
connectedTruncIso2 : ∀ {ℓ} {A B : Type ℓ} (n m : HLevel) (f : A → B)
→ Σ[ x ∈ ℕ ] x + n ≡ m
→ isConnectedFun m f
→ Iso (hLevelTrunc n A) (hLevelTrunc n B)
connectedTruncIso2 {A = A} {B = B} n m f (x , pf) con =
connectedTruncIso n f (isConnectedFunSubtr n x f (transport (λ i → isConnectedFun (pf (~ i)) f) con))
connectedTruncEquiv : ∀ {ℓ} {A B : Type ℓ} (n : HLevel) (f : A → B)
→ isConnectedFun n f
→ hLevelTrunc n A ≃ hLevelTrunc n B
connectedTruncEquiv {A = A} {B = B} n f con = isoToEquiv (connectedTruncIso n f con)
-- TODO : Reorganise the following proofs.
inrConnected : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} (n : HLevel)
→ (f : C → A) (g : C → B)
→ isConnectedFun n f
→ isConnectedFun n {A = B} {B = Pushout f g} inr
inrConnected {A = A} {B = B} {C = C} n f g iscon =
elim.isConnectedPrecompose inr n λ P → (k P) , λ b → refl
where
module _ {ℓ : Level} (P : (Pushout f g) → TypeOfHLevel ℓ n)
(h : (b : B) → typ (P (inr b)))
where
Q : A → TypeOfHLevel _ n
Q a = (P (inl a))
fun : (c : C) → typ (Q (f c))
fun c = transport (λ i → typ (P (push c (~ i)))) (h (g c))
k : (d : Pushout f g) → typ (P d)
k (inl x) = equiv-proof (elim.isEquivPrecompose f n Q iscon) fun .fst .fst x
k (inr x) = h x
k (push a i) =
hcomp (λ k → λ { (i = i0) → equiv-proof (elim.isEquivPrecompose f n Q iscon) fun .fst .snd i0 a
; (i = i1) → transportTransport⁻ (λ j → typ (P (push a j))) (h (g a)) k })
(transp (λ j → typ (P (push a (i ∧ j))))
(~ i)
(equiv-proof (elim.isEquivPrecompose f n Q iscon)
fun .fst .snd i a))
|
{
"alphanum_fraction": 0.5298248208,
"avg_line_length": 43.501607717,
"ext": "agda",
"hexsha": "2693bc83e07fbed6695c7f56764baeb0c058b972",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ayberkt/cubical",
"max_forks_repo_path": "Cubical/Homotopy/Connected.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ayberkt/cubical",
"max_issues_repo_path": "Cubical/Homotopy/Connected.agda",
"max_line_length": 145,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ayberkt/cubical",
"max_stars_repo_path": "Cubical/Homotopy/Connected.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5037,
"size": 13529
}
|
module Data.Num.Core where
open import Data.Num.Digit public
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Properties.Simple
open import Data.Nat.Properties.Extra
open import Data.Fin as Fin
using (Fin; fromℕ≤; inject≤; toℕ; zero; suc; #_)
open import Data.Fin.Properties as FinProps using (bounded; toℕ-fromℕ≤)
open import Function
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Nullary.Decidable
open import Relation.Binary
open import Function.Equality using (_⟶_)
open ≡-Reasoning
open ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≈⟨_⟩_)
open DecTotalOrder decTotalOrder using (reflexive) renaming (refl to ≤-refl)
------------------------------------------------------------------------
-- Numbers
------------------------------------------------------------------------
infixr 5 _∷_
data Numeral : ℕ → ℕ → ℕ → Set where
_∙ : ∀ {b d o} → Digit d → Numeral b d o
_∷_ : ∀ {b d o} → Digit d → Numeral b d o → Numeral b d o
MMXVI : Numeral 10 10 0
MMXVI = # 6 ∷ # 1 ∷ # 0 ∷ (# 2) ∙
------------------------------------------------------------------------
-- Converting from Numeral to ℕ
------------------------------------------------------------------------
⟦_⟧ : ∀ {b d o} → (xs : Numeral b d o) → ℕ
⟦_⟧ {_} {_} {o} (x ∙) = Digit-toℕ x o
⟦_⟧ {b} {_} {o} (x ∷ xs) = Digit-toℕ x o + ⟦ xs ⟧ * b
Num-lower-bound : ∀ {b d o}
→ (xs : Numeral b (suc d) o)
→ ⟦ xs ⟧ ≥ o
Num-lower-bound {_} {_} {o} (x ∙) = Digit-lower-bound o x
Num-lower-bound {b} {d} {o} (x ∷ xs) =
start
o
≤⟨ m≤m+n o (⟦ xs ⟧ * b) ⟩
o + ⟦ xs ⟧ * b
≤⟨ +n-mono (⟦ xs ⟧ * b) (Digit-lower-bound o x) ⟩
Digit-toℕ x o + ⟦ xs ⟧ * b
□
-- the least significant digit
lsd : ∀ {b d o} → (xs : Numeral b d o) → Digit d
lsd (x ∙ ) = x
lsd (x ∷ xs) = x
lsd-toℕ : ∀ {b d o} → (xs : Numeral b d o) → Digit-toℕ (lsd xs) o ≤ ⟦ xs ⟧
lsd-toℕ (x ∙) = ≤-refl
lsd-toℕ {b} {d} {o} (x ∷ xs) = m≤m+n (Digit-toℕ x o) (⟦ xs ⟧ * b)
------------------------------------------------------------------------
-- View of Num
------------------------------------------------------------------------
data NumView : ℕ → ℕ → ℕ → Set where
NullBase : ∀ d o → NumView 0 (suc d) o
NoDigits : ∀ b o → NumView b 0 o
AllZeros : ∀ b → NumView (suc b) 1 0
Proper : ∀ b d o → (proper : suc d + o ≥ 2) → NumView (suc b) (suc d) o
numView : ∀ b d o → NumView b d o
numView b zero o = NoDigits b o
numView zero (suc d) o = NullBase d o
numView (suc b) (suc zero) zero = AllZeros b
numView (suc b) (suc zero) (suc o) = Proper b zero (suc o) (s≤s (s≤s z≤n))
numView (suc b) (suc (suc d)) o = Proper b (suc d) o (s≤s (s≤s z≤n))
------------------------------------------------------------------------
-- Properties of Num
------------------------------------------------------------------------
NoDigits-explode : ∀ {b o a} {Whatever : Set a}
→ (xs : Numeral b 0 o)
→ Whatever
NoDigits-explode (() ∙ )
NoDigits-explode (() ∷ xs)
toℕ-NullBase : ∀ {d o}
→ (x : Digit d)
→ (xs : Numeral 0 d o)
→ ⟦ x ∷ xs ⟧ ≡ Digit-toℕ x o
toℕ-NullBase {d} {o} x xs =
begin
Digit-toℕ x o + ⟦ xs ⟧ * 0
≡⟨ cong (λ w → Digit-toℕ x o + w) (*-right-zero ⟦ xs ⟧) ⟩
Digit-toℕ x o + 0
≡⟨ +-right-identity (Digit-toℕ x o) ⟩
Digit-toℕ x o
∎
toℕ-AllZeros : ∀ {b} → (xs : Numeral b 1 0) → ⟦ xs ⟧ ≡ 0
toℕ-AllZeros (zero ∙ ) = refl
toℕ-AllZeros (suc () ∙ )
toℕ-AllZeros {b} (zero ∷ xs) = cong (λ w → w * b) (toℕ-AllZeros xs)
toℕ-AllZeros (suc () ∷ xs)
n∷-mono-strict : ∀ {b d o}
→ (x : Fin d) (xs : Numeral (suc b) d o)
→ (y : Fin d) (ys : Numeral (suc b) d o)
→ Digit-toℕ x o ≡ Digit-toℕ y o
→ ⟦ xs ⟧ < ⟦ ys ⟧
→ ⟦ x ∷ xs ⟧ < ⟦ y ∷ ys ⟧
n∷-mono-strict {b} {d} {o} x xs y ys ⟦x⟧≡⟦y⟧ ⟦xs⟧<⟦ys⟧ =
start
suc (Digit-toℕ x o) + ⟦ xs ⟧ * suc b
≈⟨ sym (+-suc (Digit-toℕ x o) (⟦ xs ⟧ * suc b)) ⟩
Digit-toℕ x o + suc (⟦ xs ⟧ * suc b)
≤⟨ n+-mono (Digit-toℕ x o) (s≤s (n≤m+n b (⟦ xs ⟧ * suc b))) ⟩
Digit-toℕ x o + (suc ⟦ xs ⟧) * suc b
≤⟨ (reflexive ⟦x⟧≡⟦y⟧) +-mono (*n-mono (suc b) ⟦xs⟧<⟦ys⟧) ⟩
Digit-toℕ y o + ⟦ ys ⟧ * suc b
□
∷ns-mono-strict : ∀ {b d o}
→ (x : Fin d) (xs : Numeral b d o)
→ (y : Fin d) (ys : Numeral b d o)
→ ⟦ xs ⟧ ≡ ⟦ ys ⟧
→ Digit-toℕ x o < Digit-toℕ y o
→ ⟦ x ∷ xs ⟧ < ⟦ y ∷ ys ⟧
∷ns-mono-strict {b} {d} {o} x xs y ys ⟦xs⟧≡⟦ys⟧ ⟦x⟧<⟦y⟧ =
start
suc ⟦ x ∷ xs ⟧
≤⟨ ⟦x⟧<⟦y⟧ +-mono *n-mono b (reflexive ⟦xs⟧≡⟦ys⟧) ⟩
⟦ y ∷ ys ⟧
□
tail-mono-strict : ∀ {b d o}
→ (x : Fin d) (xs : Numeral b d o)
→ (y : Fin d) (ys : Numeral b d o)
→ Greatest x
→ ⟦ x ∷ xs ⟧ < ⟦ y ∷ ys ⟧
→ ⟦ xs ⟧ < ⟦ ys ⟧
tail-mono-strict {b} {_} {o} x xs y ys greatest p
= *n-mono-strict-inverse b ⟦∷xs⟧<⟦∷ys⟧
where
⟦x⟧≥⟦y⟧ : Digit-toℕ x o ≥ Digit-toℕ y o
⟦x⟧≥⟦y⟧ = greatest-of-all o x y greatest
⟦∷xs⟧<⟦∷ys⟧ : ⟦ xs ⟧ * b < ⟦ ys ⟧ * b
⟦∷xs⟧<⟦∷ys⟧ = +-mono-contra ⟦x⟧≥⟦y⟧ p
tail-mono-strict-Null : ∀ {b d o}
→ (x : Fin d)
→ (y : Fin d) (ys : Numeral b d o)
→ Greatest x
→ ⟦ _∙ {b} {d} {o} x ⟧ < ⟦ y ∷ ys ⟧
→ 0 < ⟦ ys ⟧
tail-mono-strict-Null {b} {_} {o} x y ys greatest p
= *n-mono-strict-inverse b ⟦∷∙⟧<⟦∷ys⟧
where
⟦x⟧≥⟦y⟧ : Digit-toℕ x o ≥ Digit-toℕ y o
⟦x⟧≥⟦y⟧ = greatest-of-all o x y greatest
⟦∷∙⟧<⟦∷ys⟧ : 0 < ⟦ ys ⟧ * b
⟦∷∙⟧<⟦∷ys⟧ = +-mono-contra ⟦x⟧≥⟦y⟧ $
start
suc (Digit-toℕ x o) + 0
≈⟨ +-right-identity (suc (Digit-toℕ x o)) ⟩
suc (Digit-toℕ x o)
≤⟨ p ⟩
⟦ y ∷ ys ⟧
□
|
{
"alphanum_fraction": 0.4387583893,
"avg_line_length": 32.9281767956,
"ext": "agda",
"hexsha": "b2fd9846c4ee6c269ecb6ab0cb83340f43fc73ed",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Data/Num/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "Data/Num/Core.agda",
"max_line_length": 80,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Data/Num/Core.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 2506,
"size": 5960
}
|
{-# OPTIONS --warning=error --safe --without-K #-}
open import Functions.Definition
open import Rings.Homomorphisms.Definition
open import Groups.Homomorphisms.Definition
open import Setoids.Setoids
open import Rings.Definition
open import Sets.EquivalenceRelations
open import Groups.QuotientGroup.Definition
module Rings.Quotients.Definition {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {_+A_ _*A_ : A → A → A} {_+B_ _*B_ : B → B → B} (R : Ring S _+A_ _*A_) (R2 : Ring T _+B_ _*B_) {underf : A → B} (f : RingHom R R2 underf) where
open import Groups.QuotientGroup.Lemmas (Ring.additiveGroup R) (Ring.additiveGroup R2) (RingHom.groupHom f)
quotientByRingHom : Ring (quotientGroupSetoid (Ring.additiveGroup R) (RingHom.groupHom f)) _+A_ _*A_
Ring.additiveGroup quotientByRingHom = quotientGroupByHom (Ring.additiveGroup R) (RingHom.groupHom f)
Ring.*WellDefined quotientByRingHom fr=ft fs=fu = quotientGroupLemma (Ring.additiveGroup R) (RingHom.groupHom f) (transitive (RingHom.ringHom f) (transitive (Ring.*WellDefined R2 (quotientGroupLemma' (Ring.additiveGroup R) (RingHom.groupHom f) fr=ft) (quotientGroupLemma' (Ring.additiveGroup R) (RingHom.groupHom f) fs=fu)) (symmetric (RingHom.ringHom f))))
where
open Setoid T
open Equivalence eq
Ring.1R quotientByRingHom = Ring.1R R
Ring.groupIsAbelian quotientByRingHom = quotientGroupLemma (Ring.additiveGroup R) (RingHom.groupHom f) (GroupHom.wellDefined (RingHom.groupHom f) (Ring.groupIsAbelian R))
Ring.*Associative quotientByRingHom = quotientGroupLemma (Ring.additiveGroup R) (RingHom.groupHom f) (GroupHom.wellDefined (RingHom.groupHom f) (Ring.*Associative R))
Ring.*Commutative quotientByRingHom = quotientGroupLemma (Ring.additiveGroup R) (RingHom.groupHom f) (GroupHom.wellDefined (RingHom.groupHom f) (Ring.*Commutative R))
Ring.*DistributesOver+ quotientByRingHom = quotientGroupLemma (Ring.additiveGroup R) (RingHom.groupHom f) (GroupHom.wellDefined (RingHom.groupHom f) (Ring.*DistributesOver+ R))
Ring.identIsIdent quotientByRingHom = quotientGroupLemma (Ring.additiveGroup R) (RingHom.groupHom f) (GroupHom.wellDefined (RingHom.groupHom f) (Ring.identIsIdent R))
projectionMapIsHom : RingHom R quotientByRingHom id
RingHom.preserves1 projectionMapIsHom = quotientGroupLemma (Ring.additiveGroup R) (RingHom.groupHom f) (Equivalence.reflexive (Setoid.eq T))
RingHom.ringHom projectionMapIsHom = quotientGroupLemma (Ring.additiveGroup R) (RingHom.groupHom f) (Equivalence.reflexive (Setoid.eq T))
RingHom.groupHom projectionMapIsHom = projectionMapIsGroupHom
|
{
"alphanum_fraction": 0.7822204969,
"avg_line_length": 80.5,
"ext": "agda",
"hexsha": "bd468ecc65b6405b06a468f6ac0e5bd294a56a58",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Rings/Quotients/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/Quotients/Definition.agda",
"max_line_length": 357,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Rings/Quotients/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 785,
"size": 2576
}
|
{-# OPTIONS --safe #-}
module Cubical.Data.Int.MoreInts.DiffInt.Properties where
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.Data.Int.MoreInts.DiffInt.Base
open import Cubical.Data.Nat as ℕ renaming (_+_ to _+ℕ_ ; _·_ to _*ℕ_)
open import Cubical.Data.Sigma
open import Cubical.Data.Bool
open import Cubical.Relation.Binary.Base
open import Cubical.Relation.Nullary
open import Cubical.HITs.SetQuotients as SetQuotients
open import Cubical.HITs.PropositionalTruncation as PropositionalTruncation
open import Cubical.Foundations.Isomorphism
open BinaryRelation
relIsEquiv : isEquivRel rel
relIsEquiv = equivRel {A = ℕ × ℕ} relIsRefl relIsSym relIsTrans
where
relIsRefl : isRefl rel
relIsRefl (a0 , a1) = refl
relIsSym : isSym rel
relIsSym (a0 , a1) (b0 , b1) p = sym p
relIsTrans : isTrans rel
relIsTrans (a0 , a1) (b0 , b1) (c0 , c1) p0 p1 =
inj-m+ {m = (b0 +ℕ b1)} ((b0 +ℕ b1) +ℕ (a0 +ℕ c1) ≡⟨ ℕ.+-assoc (b0 +ℕ b1) a0 c1 ⟩
((b0 +ℕ b1) +ℕ a0) +ℕ c1 ≡[ i ]⟨ ℕ.+-comm b0 b1 i +ℕ a0 +ℕ c1 ⟩
((b1 +ℕ b0) +ℕ a0) +ℕ c1 ≡[ i ]⟨ ℕ.+-comm (b1 +ℕ b0) a0 i +ℕ c1 ⟩
(a0 +ℕ (b1 +ℕ b0)) +ℕ c1 ≡[ i ]⟨ ℕ.+-assoc a0 b1 b0 i +ℕ c1 ⟩
(a0 +ℕ b1) +ℕ b0 +ℕ c1 ≡⟨ sym (ℕ.+-assoc (a0 +ℕ b1) b0 c1) ⟩
(a0 +ℕ b1) +ℕ (b0 +ℕ c1) ≡⟨ cong (λ p → p . fst +ℕ p .snd) (transport ΣPath≡PathΣ (p0 , p1))⟩
(b0 +ℕ a1) +ℕ (c0 +ℕ b1) ≡⟨ sym (ℕ.+-assoc b0 a1 (c0 +ℕ b1))⟩
b0 +ℕ (a1 +ℕ (c0 +ℕ b1)) ≡[ i ]⟨ b0 +ℕ (a1 +ℕ ℕ.+-comm c0 b1 i) ⟩
b0 +ℕ (a1 +ℕ (b1 +ℕ c0)) ≡[ i ]⟨ b0 +ℕ ℕ.+-comm a1 (b1 +ℕ c0) i ⟩
b0 +ℕ ((b1 +ℕ c0) +ℕ a1) ≡[ i ]⟨ b0 +ℕ ℕ.+-assoc b1 c0 a1 (~ i) ⟩
b0 +ℕ (b1 +ℕ (c0 +ℕ a1)) ≡⟨ ℕ.+-assoc b0 b1 (c0 +ℕ a1)⟩
(b0 +ℕ b1) +ℕ (c0 +ℕ a1) ∎ )
relIsProp : BinaryRelation.isPropValued rel
relIsProp a b x y = isSetℕ _ _ _ _
discreteℤ : Discrete ℤ
discreteℤ = discreteSetQuotients (discreteΣ discreteℕ λ _ → discreteℕ) relIsProp relIsEquiv (λ _ _ → discreteℕ _ _)
private
_ : Dec→Bool (discreteℤ [ (3 , 5) ] [ (4 , 6) ]) ≡ true
_ = refl
_ : Dec→Bool (discreteℤ [ (3 , 5) ] [ (4 , 7) ]) ≡ false
_ = refl
_+ℕ'_ : (ℕ × ℕ) → (ℕ × ℕ) → (ℕ × ℕ)
(n₁ , n₂) +ℕ' (m₁ , m₂) = (n₁ +ℕ m₁ , n₂ +ℕ m₂)
[_-ℕ'_] : ℕ → ℕ → ℤ
[ x -ℕ' y ] = [ x , y ]
ℤ-cancelˡ : ∀ {a b} (c : ℕ) → [ (c ℕ.+ a) -ℕ' (c +ℕ b) ] ≡ [ a -ℕ' b ]
ℤ-cancelˡ {a} {b} c = eq/ _ _ (tmp a b c)
where tmp : ∀ a b c → rel (c +ℕ a , c +ℕ b) (a , b)
tmp a b c =
c +ℕ a +ℕ b
≡⟨ cong (λ x → x +ℕ b) (ℕ.+-comm c a) ⟩
a +ℕ c +ℕ b
≡⟨ sym(ℕ.+-assoc a c b) ⟩
a +ℕ (c +ℕ b) ∎
ℤ-cancelʳ : ∀ {a b} (c : ℕ) → [ a +ℕ c -ℕ' b +ℕ c ] ≡ [ a -ℕ' b ]
ℤ-cancelʳ {a} {b} c = eq/ _ _ (tmp a b c)
where tmp : ∀ a b c → rel (a +ℕ c , b +ℕ c) (a , b)
tmp a b c =
a +ℕ c +ℕ b
≡⟨ sym(ℕ.+-assoc a c b) ⟩
a +ℕ (c +ℕ b)
≡⟨ cong (λ x → a +ℕ x) (ℕ.+-comm c b) ⟩
a +ℕ (b +ℕ c) ∎
-- right congruence
+-right-congruence : ∀ x y z → rel y z → rel (x +ℕ' y) (x +ℕ' z)
+-right-congruence x y z p =
(fst x +ℕ fst y) +ℕ (snd x +ℕ snd z)
≡⟨ cong (λ x' → (fst x +ℕ fst y) +ℕ x') (ℕ.+-comm (snd x) (snd z)) ⟩
(fst x +ℕ fst y) +ℕ (snd z +ℕ snd x)
≡⟨ ℕ.+-assoc (fst x +ℕ fst y) (snd z) (snd x) ⟩
fst x +ℕ fst y +ℕ snd z +ℕ snd x
≡⟨ cong (λ x' → x' +ℕ snd x) (sym (ℕ.+-assoc (fst x) (fst y) (snd z))) ⟩
fst x +ℕ (fst y +ℕ snd z) +ℕ snd x
≡⟨ cong (λ x' → fst x +ℕ x' +ℕ snd x) p ⟩
fst x +ℕ (fst z +ℕ snd y) +ℕ snd x
≡⟨ cong (λ x' → x' +ℕ snd x) (ℕ.+-assoc (fst x) (fst z) (snd y)) ⟩
fst x +ℕ fst z +ℕ snd y +ℕ snd x
≡⟨ sym (ℕ.+-assoc (fst x +ℕ fst z) (snd y) (snd x)) ⟩
fst x +ℕ fst z +ℕ (snd y +ℕ snd x)
≡⟨ cong (λ x' → fst x +ℕ fst z +ℕ x') (ℕ.+-comm (snd y) (snd x)) ⟩
fst x +ℕ fst z +ℕ (snd x +ℕ snd y) ∎
+-left-congruence : ∀ x y z → rel x y → rel (x +ℕ' z) (y +ℕ' z)
+-left-congruence x y z p =
(fst x +ℕ fst z) +ℕ (snd y +ℕ snd z)
≡⟨ cong (λ x' → x' +ℕ (snd y +ℕ snd z)) (ℕ.+-comm (fst x) (fst z)) ⟩
(fst z +ℕ fst x) +ℕ (snd y +ℕ snd z)
≡⟨ ℕ.+-assoc (fst z +ℕ fst x) (snd y) (snd z) ⟩
fst z +ℕ fst x +ℕ snd y +ℕ snd z
≡⟨ cong (λ x' → x' +ℕ snd z) (sym (ℕ.+-assoc (fst z) (fst x) (snd y))) ⟩
fst z +ℕ (fst x +ℕ snd y) +ℕ snd z
≡⟨ cong (λ x' → fst z +ℕ x' +ℕ snd z) p ⟩
fst z +ℕ (fst y +ℕ snd x) +ℕ snd z
≡⟨ cong (λ x' → x' +ℕ snd z) (ℕ.+-assoc (fst z) (fst y) (snd x)) ⟩
fst z +ℕ fst y +ℕ snd x +ℕ snd z
≡⟨ sym (ℕ.+-assoc (fst z +ℕ fst y) (snd x) (snd z)) ⟩
fst z +ℕ fst y +ℕ (snd x +ℕ snd z)
≡⟨ cong (λ x' → x' +ℕ (snd x +ℕ snd z)) (ℕ.+-comm (fst z) (fst y)) ⟩
fst y +ℕ fst z +ℕ (snd x +ℕ snd z) ∎
ℤ-isSet : isSet ℤ
ℤ-isSet m n p q = squash/ m n p q
_+_ : ℤ → ℤ → ℤ
_+_ = SetQuotients.rec2 ℤ-isSet (λ x y → [ x +ℕ' y ]) feql feqr
where
feql : (a b c : ℕ × ℕ) (r : rel a b) → [ a +ℕ' c ] ≡ [ b +ℕ' c ]
feql a b c r = eq/ (a +ℕ' c) (b +ℕ' c) (+-left-congruence a b c r)
feqr : (a b c : ℕ × ℕ) (r : rel b c) → [ a +ℕ' b ] ≡ [ a +ℕ' c ]
feqr a b c r = eq/ (a +ℕ' b) (a +ℕ' c) (+-right-congruence a b c r)
private
zero-identityˡ-lem : (a : ℕ)(b : ℤ) → (Σ (ℕ × ℕ) ( λ (c , d) → [ (c , d) ] ≡ b )) → [ a , a ] + b ≡ b
zero-identityˡ-lem a b ( (c , d) , p ) =
[ a , a ] + b ≡⟨ cong (λ x → [ a , a ] + x) (sym p) ⟩
[ a , a ] + [ c , d ] ≡⟨ ℤ-cancelˡ a ⟩
[ c , d ] ≡⟨ p ⟩
b ∎
zero-identityʳ-lem : (a : ℕ)(b : ℤ) → (Σ (ℕ × ℕ) ( λ (c , d) → [ (c , d) ] ≡ b )) → b + [ a , a ] ≡ b
zero-identityʳ-lem a b ( (c , d) , p ) =
b + [ a , a ] ≡⟨ cong (λ x → x + [ a , a ]) (sym(p)) ⟩
[ c , d ] + [ a , a ] ≡⟨ ℤ-cancelʳ a ⟩
[ c , d ] ≡⟨ p ⟩
b ∎
zero-identityˡ : (a : ℕ) (b : ℤ) → [ a , a ] + b ≡ b
zero-identityˡ a b = PropositionalTruncation.rec (lem2 a b) (zero-identityˡ-lem a b) ([]surjective b)
where
lem2 : (a : ℕ) (b : ℤ) → isProp ([ a , a ] + b ≡ b)
lem2 a b = ℤ-isSet ([ a , a ] + b) b
zero-identityʳ : (a : ℕ)(b : ℤ) → b + [ a , a ] ≡ b
zero-identityʳ a b = PropositionalTruncation.rec (lem2 a b) (zero-identityʳ-lem a b) ([]surjective b)
where
lem2 : (a : ℕ) (b : ℤ) → isProp (b + [ a , a ] ≡ b)
lem2 a b = ℤ-isSet (b + [ a , a ]) b
-ℤ_ : ℤ → ℤ
-ℤ [ a ] = [ snd a , fst a ]
-ℤ eq/ a b r i = eq/ (snd a , fst a) (snd b , fst b) (tmp a b r) i
where
tmp : ∀ a b → fst a +ℕ snd b ≡ fst b +ℕ snd a → snd a +ℕ fst b ≡ snd b +ℕ fst a
tmp a b r =
snd a +ℕ fst b ≡⟨ ℕ.+-comm (snd a) (fst b) ⟩
fst b +ℕ snd a ≡⟨ sym r ⟩
fst a +ℕ snd b ≡⟨ ℕ.+-comm (fst a) (snd b) ⟩
snd b +ℕ fst a ∎
-ℤ squash/ a a₁ p q i i₁ = squash/ (-ℤ a) (-ℤ a₁) (cong (λ x → -ℤ x) p) (cong (λ x → -ℤ x) q) i i₁
private
-ℤ-invʳ-lem : (b : ℤ) → (Σ (ℕ × ℕ) ( λ (c , d) → [ (c , d) ] ≡ b )) → b + (-ℤ b) ≡ [ 0 , 0 ]
-ℤ-invʳ-lem b ( (c , d) , p ) =
b + (-ℤ b)
≡⟨ cong (λ x → x + (-ℤ b)) (sym p) ⟩
[ c , d ] + (-ℤ b)
≡⟨ cong (λ x → [ c , d ] + (-ℤ x)) (sym p) ⟩
[ c +ℕ d , d +ℕ c ]
≡⟨ cong (λ x → [ c +ℕ d , x ]) (ℕ.+-comm d c) ⟩
[ c +ℕ d , c +ℕ d ]
≡⟨ ℤ-cancelˡ c ⟩
[ d -ℕ' d ]
≡⟨ sym(ℤ-cancelʳ 0) ⟩
[ d +ℕ 0 -ℕ' d +ℕ 0 ]
≡⟨ ℤ-cancelˡ d ⟩
[ 0 , 0 ] ∎
-ℤ-invˡ-lem : (b : ℤ) → (Σ (ℕ × ℕ) ( λ (c , d) → [ (c , d) ] ≡ b )) → (-ℤ b) + b ≡ [ 0 , 0 ]
-ℤ-invˡ-lem b ( (c , d) , p ) =
(-ℤ b) + b
≡⟨ cong (λ x → (-ℤ b) + x) (sym p) ⟩
(-ℤ b) + [ c , d ]
≡⟨ cong (λ x → (-ℤ x) + [ c , d ]) (sym p) ⟩
[ d +ℕ c , c +ℕ d ]
≡⟨ cong (λ x → [ x , c +ℕ d ]) (ℕ.+-comm d c) ⟩
[ c +ℕ d , c +ℕ d ]
≡⟨ ℤ-cancelˡ c ⟩
[ d -ℕ' d ]
≡⟨ sym(ℤ-cancelʳ 0) ⟩
[ d +ℕ 0 -ℕ' d +ℕ 0 ]
≡⟨ ℤ-cancelˡ d ⟩
[ 0 , 0 ] ∎
_-_ : ℤ → ℤ → ℤ
a - b = a + (-ℤ b)
-ℤ-invʳ : (b : ℤ) → b + (-ℤ b) ≡ [ 0 , 0 ]
-ℤ-invʳ b = PropositionalTruncation.rec (lem2 b) (-ℤ-invʳ-lem b) ([]surjective b)
where
lem2 : (b : ℤ) → isProp (b + (-ℤ b) ≡ [ 0 , 0 ])
lem2 b = ℤ-isSet (b + (-ℤ b)) [ 0 , 0 ]
-ℤ-invˡ : (b : ℤ) → (-ℤ b) + b ≡ [ 0 , 0 ]
-ℤ-invˡ b = PropositionalTruncation.rec (lem2 b) (-ℤ-invˡ-lem b) ([]surjective b)
where
lem2 : (b : ℤ) → isProp ((-ℤ b) + b ≡ [ 0 , 0 ])
lem2 b = ℤ-isSet ((-ℤ b) + b) [ 0 , 0 ]
+ℤ-assoc : ∀ x y z → x + (y + z) ≡ (x + y) + z
+ℤ-assoc = elimProp3 (λ _ _ _ → ℤ-isSet _ _)
(λ { (a , b) (c , d) (e , f) i → [ ℕ.+-assoc a c e i -ℕ' ℕ.+-assoc b d f i ] })
+ℤ-comm : ∀ x y → x + y ≡ y + x
+ℤ-comm = elimProp2 (λ _ _ → ℤ-isSet _ _)
λ ( a , b ) ( c , d ) i → [ ℕ.+-comm a c i -ℕ' ℕ.+-comm b d i ]
|
{
"alphanum_fraction": 0.4296426996,
"avg_line_length": 39.7719298246,
"ext": "agda",
"hexsha": "a5f4f67810092fb9a729053ec0d198de949e12ad",
"lang": "Agda",
"max_forks_count": 134,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z",
"max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Data/Int/MoreInts/DiffInt/Properties.agda",
"max_issues_count": 584,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Data/Int/MoreInts/DiffInt/Properties.agda",
"max_line_length": 115,
"max_stars_count": 301,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Data/Int/MoreInts/DiffInt/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z",
"num_tokens": 4534,
"size": 9068
}
|
------------------------------------------------------------------------------
-- Main properties of the McCarthy 91 function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- The main properties proved of the McCarthy 91 function (called
-- f₉₁) are
-- 1. The function always terminates.
-- 2. For all n, n < f₉₁ n + 11.
-- 3. For all n > 100, then f₉₁ n = n - 10.
-- 4. For all n <= 100, then f₉₁ n = 91.
-- N.B This module does not contain combined proofs, but it imports
-- modules which contain combined proofs.
module FOTC.Program.McCarthy91.PropertiesATP where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.EliminationPropertiesATP
using ( x>y→x≤y→⊥ )
open import FOTC.Data.Nat.Inequalities.PropertiesATP
using ( x>y∨x≯y
; x≯y→x≤y
; x≯Sy→x≯y∨x≡Sy
; x+k<y+k→x<y
; <-trans
)
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+11 )
open import FOTC.Data.Nat.UnaryNumbers.TotalityATP
using ( 10-N
; 11-N
; 89-N
; 90-N
; 91-N
; 92-N
; 93-N
; 94-N
; 95-N
; 96-N
; 97-N
; 98-N
; 99-N
; 100-N
)
open import FOTC.Program.McCarthy91.ArithmeticATP
open import FOTC.Program.McCarthy91.AuxiliaryPropertiesATP
open import FOTC.Program.McCarthy91.McCarthy91
open import FOTC.Program.McCarthy91.WF-Relation
open import FOTC.Program.McCarthy91.WF-Relation.LT2WF-RelationATP
open import FOTC.Program.McCarthy91.WF-Relation.Induction.Acc.WF-ATP
------------------------------------------------------------------------------
-- For all n > 100, then f₉₁ n = n - 10.
postulate f₉₁-x>100 : ∀ n → n > 100' → f₉₁ n ≡ n ∸ 10'
{-# ATP prove f₉₁-x>100 #-}
-- For all n <= 100, then f₉₁ n = 91.
f₉₁-x≯100 : ∀ {n} → N n → n ≯ 100' → f₉₁ n ≡ 91'
f₉₁-x≯100 = ◁-wfind A h
where
A : D → Set
A d = d ≯ 100' → f₉₁ d ≡ 91'
h : ∀ {m} → N m → (∀ {k} → N k → k ◁ m → A k) → A m
h {m} Nm f with x>y∨x≯y Nm 100-N
... | inj₁ m>100 = λ m≯100 →
⊥-elim (x>y→x≤y→⊥ Nm 100-N m>100 (x≯y→x≤y Nm 100-N m≯100))
... | inj₂ m≯100 with x≯Sy→x≯y∨x≡Sy Nm 99-N m≯100
... | inj₂ m≡100 = λ _ → f₉₁-x≡y f₉₁-100 m≡100
... | inj₁ m≯99 with x≯Sy→x≯y∨x≡Sy Nm 98-N m≯99
... | inj₂ m≡99 = λ _ → f₉₁-x≡y f₉₁-99 m≡99
... | inj₁ m≯98 with x≯Sy→x≯y∨x≡Sy Nm 97-N m≯98
... | inj₂ m≡98 = λ _ → f₉₁-x≡y f₉₁-98 m≡98
... | inj₁ m≯97 with x≯Sy→x≯y∨x≡Sy Nm 96-N m≯97
... | inj₂ m≡97 = λ _ → f₉₁-x≡y f₉₁-97 m≡97
... | inj₁ m≯96 with x≯Sy→x≯y∨x≡Sy Nm 95-N m≯96
... | inj₂ m≡96 = λ _ → f₉₁-x≡y f₉₁-96 m≡96
... | inj₁ m≯95 with x≯Sy→x≯y∨x≡Sy Nm 94-N m≯95
... | inj₂ m≡95 = λ _ → f₉₁-x≡y f₉₁-95 m≡95
... | inj₁ m≯94 with x≯Sy→x≯y∨x≡Sy Nm 93-N m≯94
... | inj₂ m≡94 = λ _ → f₉₁-x≡y f₉₁-94 m≡94
... | inj₁ m≯93 with x≯Sy→x≯y∨x≡Sy Nm 92-N m≯93
... | inj₂ m≡93 = λ _ → f₉₁-x≡y f₉₁-93 m≡93
... | inj₁ m≯92 with x≯Sy→x≯y∨x≡Sy Nm 91-N m≯92
... | inj₂ m≡92 = λ _ → f₉₁-x≡y f₉₁-92 m≡92
... | inj₁ m≯91 with x≯Sy→x≯y∨x≡Sy Nm 90-N m≯91
... | inj₂ m≡91 = λ _ → f₉₁-x≡y f₉₁-91 m≡91
... | inj₁ m≯90 with x≯Sy→x≯y∨x≡Sy Nm 89-N m≯90
... | inj₂ m≡90 = λ _ → f₉₁-x≡y f₉₁-90 m≡90
... | inj₁ m≯89 = λ _ → f₉₁-m≯89
where
m≤89 : m ≤ 89'
m≤89 = x≯y→x≤y Nm 89-N m≯89
f₉₁-m+11 : m + 11' ≯ 100' → f₉₁ (m + 11') ≡ 91'
f₉₁-m+11 = f (x+11-N Nm) (<→◁ (x+11-N Nm) Nm m≯100 (x<x+11 Nm))
f₉₁-m≯89 : f₉₁ m ≡ 91'
f₉₁-m≯89 = f₉₁-x≯100-helper m 91' m≯100
(f₉₁-m+11 (x≤89→x+11≯100 Nm m≤89))
f₉₁-91
-- The function always terminates.
f₉₁-N : ∀ {n} → N n → N (f₉₁ n)
f₉₁-N {n} Nn = case prf₁ prf₂ (x>y∨x≯y Nn 100-N)
where
prf₁ : n > 100' → N (f₉₁ n)
prf₁ n>100 = subst N (sym (f₉₁-x>100 n n>100)) (∸-N Nn 10-N)
prf₂ : n ≯ 100' → N (f₉₁ n)
prf₂ n≯100 = subst N (sym (f₉₁-x≯100 Nn n≯100)) 91-N
-- The function always terminates (using Agda with constructor).
f₉₁-N' : ∀ {n} → N n → N (f₉₁ n)
f₉₁-N' {n} Nn with x>y∨x≯y Nn 100-N
... | inj₁ n>100 = subst N (sym (f₉₁-x>100 n n>100)) (∸-N Nn 10-N)
... | inj₂ n≯100 = subst N (sym (f₉₁-x≯100 Nn n≯100)) 91-N
-- For all n, n < f₉₁ n + 11.
f₉₁-ineq : ∀ {n} → N n → n < f₉₁ n + 11'
f₉₁-ineq = ◁-wfind A h
where
A : D → Set
A d = d < f₉₁ d + 11'
h : ∀ {m} → N m → (∀ {k} → N k → k ◁ m → A k) → A m
h {m} Nm f with x>y∨x≯y Nm 100-N
... | inj₁ m>100 = x>100→x<f₉₁-x+11 Nm m>100
... | inj₂ m≯100 =
let f₉₁-m+11-N : N (f₉₁ (m + 11'))
f₉₁-m+11-N = f₉₁-N (+-N Nm 11-N)
h₁ : A (m + 11')
h₁ = f (x+11-N Nm) (<→◁ (x+11-N Nm) Nm m≯100 (x<x+11 Nm))
m<f₉₁m+11 : m < f₉₁ (m + 11')
m<f₉₁m+11 = x+k<y+k→x<y Nm f₉₁-m+11-N 11-N h₁
h₂ : A (f₉₁ (m + 11'))
h₂ = f f₉₁-m+11-N (<→◁ f₉₁-m+11-N Nm m≯100 m<f₉₁m+11)
in (<-trans Nm f₉₁-m+11-N (x+11-N (f₉₁-N Nm))
m<f₉₁m+11
(f₉₁x+11<f₉₁x+11 m m≯100 h₂))
|
{
"alphanum_fraction": 0.5089639555,
"avg_line_length": 33.5379746835,
"ext": "agda",
"hexsha": "6e962752712bb489d49b1176605f940e9b7f6e68",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/McCarthy91/PropertiesATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/McCarthy91/PropertiesATP.agda",
"max_line_length": 79,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/McCarthy91/PropertiesATP.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 2577,
"size": 5299
}
|
{-# OPTIONS --allow-unsolved-metas #-}
open import CS410-Prelude
------------------------------------------------------------------------------
-- Vectors
------------------------------------------------------------------------------
data Vec (X : Set) : Nat -> Set where
[] : Vec X zero
_,-_ : {n : Nat} -> X -> Vec X n -> Vec X (suc n)
infixr 4 _,-_
------------------------------------------------------------------------------
-- Heads and Tails
------------------------------------------------------------------------------
vHead : {X : Set}{n : Nat} -> Vec X (suc n) -> X
vHead (x ,- xs) = x
vTail : {X : Set}{n : Nat} -> Vec X (suc n) -> Vec X n
vTail (x ,- xs) = xs
vHeadTailFact : {X : Set}{n : Nat}(xs : Vec X (suc n)) -> (vHead xs ,- vTail xs) == xs
vHeadTailFact (x ,- xs) = refl (x ,- xs)
------------------------------------------------------------------------------
-- Concatenation and its Inverse
------------------------------------------------------------------------------
_+V_ : {X : Set}{m n : Nat} -> Vec X m -> Vec X n -> Vec X (m +N n)
[] +V ys = ys
(x ,- xs) +V ys = x ,- xs +V ys
infixr 4 _+V_
vChop : {X : Set}(m : Nat){n : Nat} -> Vec X (m +N n) -> Vec X m * Vec X n
vChop zero xs = [] , xs
vChop (suc m) (x ,- xs) with vChop m xs
vChop (suc m) (x ,- xs) | xf , xb = (x ,- xf) , xb
vChopAppendFact : {X : Set}{m n : Nat}(xs : Vec X m)(ys : Vec X n) -> vChop m (xs +V ys) == (xs , ys)
vChopAppendFact [] ys = refl ([] , ys)
vChopAppendFact (x ,- xs) ys rewrite vChopAppendFact xs ys = refl ((x ,- xs) , ys)
------------------------------------------------------------------------------
-- Map, take I
------------------------------------------------------------------------------
-- Implement the higher-order function that takes an operation on
-- elements and does it to each element of a vector. Use recursion
-- on the vector.
-- Note that the type tells you the size remains the same.
-- Show that if the elementwise function "does nothing", neither does
-- its vMap. "map of identity is identity"
-- Show that two vMaps in a row can be collapsed to just one, or
-- "composition of maps is map of compositions"
vMap : {X Y : Set} -> (X -> Y) -> {n : Nat} -> Vec X n -> Vec Y n
vMap f [] = []
vMap f (x ,- xs) = f x ,- vMap f xs
vMapIdFact : {X : Set}{f : X -> X}(feq : (x : X) -> f x == x) ->
{n : Nat}(xs : Vec X n) ->
vMap f xs == xs
vMapIdFact feq [] = refl []
vMapIdFact feq (x ,- xs) rewrite vMapIdFact feq xs | feq x
= refl (x ,- xs)
vMapCpFact : {X Y Z : Set}{f : Y -> Z}{g : X -> Y}{h : X -> Z}(heq : (x : X) -> f (g x) == h x) ->
{n : Nat}(xs : Vec X n) ->
vMap f (vMap g xs) == vMap h xs
vMapCpFact heq [] = refl []
vMapCpFact {f = f}{g = g}{h = h} heq (x ,- xs) rewrite vMapCpFact {f = f}{g = g}{h = h} heq xs | heq x
= refl (h x ,- vMap h xs)
------------------------------------------------------------------------------
-- vMap and +V
------------------------------------------------------------------------------
-- Show that if you've got two vectors of Xs and a function from X to Y,
-- and you want to concatenate and map, it doesn't matter which you do
-- first.
vMap+VFact : {X Y : Set}(f : X -> Y) ->
{m n : Nat}(xs : Vec X m)(xs' : Vec X n) ->
vMap f (xs +V xs') == (vMap f xs +V vMap f xs')
vMap+VFact f [] xs' = refl (vMap f xs')
vMap+VFact f (x ,- xs) xs' rewrite vMap+VFact f xs xs' = refl (f x ,- vMap f xs +V vMap f xs')
------------------------------------------------------------------------------
-- Applicative Structure (giving mapping and zipping cheaply)
------------------------------------------------------------------------------
-- HINT: you will need to override the default invisibility of n to do this.
vPure : {X : Set} -> X -> {n : Nat} -> Vec X n
vPure x {zero} = []
vPure x {suc n} = x ,- vPure x
_$V_ : {X Y : Set}{n : Nat} -> Vec (X -> Y) n -> Vec X n -> Vec Y n
[] $V [] = []
f ,- fs $V x ,- xs = f x ,- (fs $V xs)
infixl 3 _$V_
-- Pattern matching and recursion are forbidden for the next two tasks.
-- implement vMap again, but as a one-liner
vec : {X Y : Set} -> (X -> Y) -> {n : Nat} -> Vec X n -> Vec Y n
vec f xs = vPure f $V xs
-- implement the operation which pairs up corresponding elements
vZip : {X Y : Set}{n : Nat} -> Vec X n -> Vec Y n -> Vec (X * Y) n
vZip xs ys = vPure _,_ $V xs $V ys
------------------------------------------------------------------------------
-- Applicative Laws
------------------------------------------------------------------------------
-- According to "Applicative programming with effects" by
-- Conor McBride and Ross Paterson
-- some laws should hold for applicative functors.
-- Check that this is the case.
vIdentity : {X : Set}{f : X -> X}(feq : (x : X) -> f x == x) ->
{n : Nat}(xs : Vec X n) -> (vPure f $V xs) == xs
vIdentity feq [] = refl []
vIdentity feq (x ,- xs) rewrite vIdentity feq xs | feq x = refl (x ,- xs)
vHomomorphism : {X Y : Set}(f : X -> Y)(x : X) -> {n : Nat} ->
(vPure f $V vPure x) == vPure (f x) {n}
vHomomorphism f x {zero} = refl []
vHomomorphism f x {suc n} rewrite vHomomorphism f x {n} = refl (f x ,- vPure (f x))
vInterchange : {X Y : Set}{n : Nat}(fs : Vec (X -> Y) n)(x : X) ->
(fs $V vPure x) == (vPure (_$ x) $V fs)
vInterchange [] x = refl []
vInterchange (f ,- fs) x rewrite vInterchange fs x = refl (f x ,- (vPure (\ f → f x) $V fs))
vComposition : {X Y Z : Set}{n : Nat}(fs : Vec (Y -> Z) n)(gs : Vec (X -> Y) n)(xs : Vec X n) ->
(vPure _<<_ $V fs $V gs $V xs) == (fs $V (gs $V xs))
vComposition [] [] [] = refl []
vComposition (f ,- fs) (g ,- gs) (x ,- xs) rewrite vComposition fs gs xs = refl (f (g x) ,- (fs $V (gs $V xs)))
------------------------------------------------------------------------------
-- Order-Preserving Embeddings (also known in the business as "thinnings")
------------------------------------------------------------------------------
-- What have these to do with Pascal's Triangle?
data _<=_ : Nat -> Nat -> Set where
oz : zero <= zero
os : {n m : Nat} -> n <= m -> suc n <= suc m
o' : {n m : Nat} -> n <= m -> n <= suc m
-- Find all the values in each of the following <= types.
-- This is a good opportunity to learn to use C-c C-a with the -l option
-- (a.k.a. "google the type" without "I feel lucky")
-- The -s n option also helps.
all0<=4 : Vec (0 <= 4) 1
all0<=4 = o' (o' (o' (o' oz))) ,- []
all1<=4 : Vec (1 <= 4) 4
all1<=4 = o' (o' (o' (os oz))) ,-
o' (o' (os (o' oz))) ,-
o' (os (o' (o' oz))) ,-
os (o' (o' (o' oz))) ,-
[]
all2<=4 : Vec (2 <= 4) 6
all2<=4 = os (os (o' (o' oz))) ,-
os (o' (os (o' oz))) ,-
os (o' (o' (os oz))) ,-
o' (os (os (o' oz))) ,-
o' (os (o' (os oz))) ,-
o' (o' (os (os oz))) ,-
[]
all3<=4 : Vec (3 <= 4) 4
all3<=4 = os (os (os (o' oz))) ,-
os (os (o' (os oz))) ,-
os (o' (os (os oz))) ,-
o' (os (os (os oz))) ,-
[]
all4<=4 : Vec (4 <= 4) 1
all4<=4 = os (os (os (os oz))) ,- []
-- Prove the following. A massive case analysis "rant" is fine.
no5<=4 : 5 <= 4 -> Zero
no5<=4 (os (os (os (os ()))))
no5<=4 (os (os (os (o' ()))))
no5<=4 (os (os (o' (os ()))))
no5<=4 (os (os (o' (o' ()))))
no5<=4 (os (o' (os (os ()))))
no5<=4 (os (o' (os (o' ()))))
no5<=4 (os (o' (o' (os ()))))
no5<=4 (os (o' (o' (o' ()))))
no5<=4 (o' (os (os (os ()))))
no5<=4 (o' (os (os (o' ()))))
no5<=4 (o' (os (o' (os ()))))
no5<=4 (o' (os (o' (o' ()))))
no5<=4 (o' (o' (os (os ()))))
no5<=4 (o' (o' (os (o' ()))))
no5<=4 (o' (o' (o' (os ()))))
no5<=4 (o' (o' (o' (o' ()))))
------------------------------------------------------------------------------
-- Order-Preserving Embeddings Select From Vectors
------------------------------------------------------------------------------
-- Use n <= m to encode the choice of n elements from an m-Vector.
-- The os constructor tells you to take the next element of the vector;
-- the o' constructor tells you to omit the next element of the vector.
_<?=_ : {X : Set}{n m : Nat} -> n <= m -> Vec X m -> Vec X n
oz <?= [] = []
os th <?= (x ,- xs) = x ,- th <?= xs
o' th <?= (x ,- xs) = th <?= xs
-- it shouldn't matter whether you map then select or select then map
vMap<?=Fact : {X Y : Set}(f : X -> Y)
{n m : Nat}(th : n <= m)(xs : Vec X m) ->
vMap f (th <?= xs) == (th <?= vMap f xs)
vMap<?=Fact f oz [] = refl []
vMap<?=Fact f (os th) (x ,- xs) rewrite vMap<?=Fact f th xs = refl (f x ,- (th <?= vMap f xs))
vMap<?=Fact f (o' th) (x ,- xs) rewrite vMap<?=Fact f th xs = refl (th <?= vMap f xs)
------------------------------------------------------------------------------
-- Our Favourite Thinnings
------------------------------------------------------------------------------
-- Construct the identity thinning and the empty thinning.
oi : {n : Nat} -> n <= n
oi {zero} = oz
oi {suc n} = os oi
oe : {n : Nat} -> 0 <= n
oe {zero} = oz
oe {suc n} = o' oe
-- Show that all empty thinnings are equal to yours.
oeUnique : {n : Nat}(th : 0 <= n) -> th == oe
oeUnique oz = refl oz
oeUnique (o' i) with oeUnique i
oeUnique (o' .oe) | refl .oe = refl (o' oe)
-- Show that there are no thinnings of form big <= small (TRICKY)
-- Then show that all the identity thinnings are equal to yours.
-- Note that you can try the second even if you haven't finished the first.
-- HINT: you WILL need to expose the invisible numbers.
-- HINT: check CS410-Prelude for a reminder of >=
oTooBig : {n m : Nat} -> n >= m -> suc n <= m -> Zero
oTooBig {_} {zero} n>=m ()
oTooBig {zero} {suc m} n>=m (th) = n>=m
oTooBig {suc n} {suc m} n>=m (os th) with oTooBig {n} {m} n>=m th
oTooBig {suc n} {suc m} n>=m (os th) | ()
oTooBig {suc n} {suc m} n>=m (o' th) with oTooBig {suc n} {m} (trans->= (suc n) n m (suc->= n) n>=m) th
oTooBig {suc n} {suc m} n>=m (o' th) | ()
oiUnique : {n : Nat}(th : n <= n) -> th == oi
oiUnique oz = refl oz
oiUnique (os th) with oiUnique th
oiUnique (os .oi) | refl .oi = refl (os oi)
oiUnique {n}(o' th) with oTooBig (refl->= n) th
oiUnique {.(suc _)} (o' th) | ()
-- Show that the identity thinning selects the whole vector
id-<?= : {X : Set}{n : Nat}(xs : Vec X n) -> (oi <?= xs) == xs
id-<?= [] = refl []
id-<?= (x ,- xs) rewrite id-<?= xs = refl (x ,- xs)
------------------------------------------------------------------------------
-- Composition of Thinnings
------------------------------------------------------------------------------
-- Define the composition of thinnings and show that selecting by a
-- composite thinning is like selecting then selecting again.
-- A small bonus applies to minimizing the length of the proof.
-- To collect the bonus, you will need to think carefully about
-- how to make the composition as *lazy* as possible.
_o>>_ : {p n m : Nat} -> p <= n -> n <= m -> p <= m
oz o>> th' = th'
os th o>> os th' with th o>> th'
os th o>> os th' | p = os p
os th o>> o' th' with (os th) o>> th'
os th o>> o' th' | p = o' p
o' th o>> os th' with th o>> th'
o' th o>> os th' | p = o' p
o' th o>> o' th' with (o' th) o>> th'
o' th o>> o' th' | p = o' p
cp-<?= : {p n m : Nat}(th : p <= n)(th' : n <= m) ->
{X : Set}(xs : Vec X m) ->
((th o>> th') <?= xs) == (th <?= (th' <?= xs))
cp-<?= oz oz [] = refl []
cp-<?= oz (o' th') xs with o' th' <?= xs
cp-<?= oz (o' th') xs | [] = refl []
cp-<?= (os th) (os th') (x ,- xs) rewrite cp-<?= th th' xs = refl (x ,- (th <?= (th' <?= xs)))
cp-<?= (os th) (o' th') (x ,- xs) rewrite cp-<?= (os th) th' xs = refl (os th <?= (th' <?= xs))
cp-<?= (o' th) (os th') (x ,- xs) rewrite cp-<?= th th' xs = refl (th <?= (th' <?= xs))
cp-<?= (o' th) (o' th') (x ,- xs) rewrite cp-<?= (o' th) th' xs = refl (o' th <?= (th' <?= xs))
-- TODO: shorter solution for bonus
------------------------------------------------------------------------------
-- Thinning Dominoes
------------------------------------------------------------------------------
idThen-o>> : {n m : Nat}(th : n <= m) -> (oi o>> th) == th
idThen-o>> oz = refl oz
idThen-o>> (os th) rewrite idThen-o>> th = refl (os th)
idThen-o>> {zero}(o' th) rewrite idThen-o>> th = refl (o' th)
idThen-o>> {suc n}(o' th) rewrite idThen-o>> th = refl (o' th)
idAfter-o>> : {n m : Nat}(th : n <= m) -> (th o>> oi) == th
idAfter-o>> oz = refl oz
idAfter-o>> (os th) rewrite idAfter-o>> th = refl (os th)
idAfter-o>> (o' th) rewrite idAfter-o>> th = refl (o' th)
assoc-o>> : {q p n m : Nat}(th0 : q <= p)(th1 : p <= n)(th2 : n <= m) ->
((th0 o>> th1) o>> th2) == (th0 o>> (th1 o>> th2))
assoc-o>> oz th1 th2 = refl (th1 o>> th2)
assoc-o>> (os th0) (os th1) (os th2) rewrite assoc-o>> th0 th1 th2 = refl (os (th0 o>> (th1 o>> th2)))
assoc-o>> (os th0) (os th1) (o' th2) rewrite assoc-o>> (os th0) (os th1) th2 = refl (o' (os th0 o>> (os th1 o>> th2)))
assoc-o>> (os th0) (o' th1) (os th2) rewrite assoc-o>> (os th0) th1 th2 = refl (o' (os th0 o>> (th1 o>> th2)))
assoc-o>> (os th0) (o' th1) (o' th2) rewrite assoc-o>> (os th0) (o' th1) th2 = refl (o' (os th0 o>> (o' th1 o>> th2)))
assoc-o>> (o' th0) (os th1) (os th2) rewrite assoc-o>> th0 th1 th2 = refl (o' (th0 o>> (th1 o>> th2)))
assoc-o>> (o' th0) (os th1) (o' th2) rewrite assoc-o>> (o' th0) (os th1) th2 = refl (o' (o' th0 o>> (os th1 o>> th2)))
assoc-o>> (o' th0) (o' th1) (os th2) rewrite assoc-o>> (o' th0) th1 th2 = refl (o' (o' th0 o>> (th1 o>> th2)))
assoc-o>> (o' th0) (o' th1) (o' th2) rewrite assoc-o>> (o' th0) (o' th1) th2 = refl (o' (o' th0 o>> (o' th1 o>> th2)))
------------------------------------------------------------------------------
-- Vectors as Arrays
------------------------------------------------------------------------------
-- We can use 1 <= n as the type of bounded indices into a vector and do
-- a kind of "array projection". First we select a 1-element vector from
-- the n-element vector, then we take its head to get the element out.
vProject : {n : Nat}{X : Set} -> Vec X n -> 1 <= n -> X
vProject xs i = vHead (i <?= xs)
-- Your (TRICKY) mission is to reverse the process, tabulating a function
-- from indices as a vector. Then show that these operations are inverses.
-- HINT: composition of functions
vTabulate : {n : Nat}{X : Set} -> (1 <= n -> X) -> Vec X n
vTabulate {zero} f = []
vTabulate {suc n} f with f (os oe) | vTabulate (f << o')
vTabulate {suc n} f | x | xs = x ,- xs
-- This should be easy if vTabulate is correct.
vTabulateProjections : {n : Nat}{X : Set}(xs : Vec X n) -> vTabulate (vProject xs) == xs
vTabulateProjections [] = refl []
vTabulateProjections (x ,- xs) rewrite vTabulateProjections xs = refl (x ,- xs)
-- HINT: oeUnique
vProjectFromTable : {n : Nat}{X : Set}(f : 1 <= n -> X)(i : 1 <= n) -> vProject (vTabulate f) i == f i
vProjectFromTable f (os i) rewrite oeUnique i = refl (f (os oe))
vProjectFromTable f (o' i) rewrite vProjectFromTable (f << o') i = refl (f (o' i))
|
{
"alphanum_fraction": 0.4577478726,
"avg_line_length": 39.0695876289,
"ext": "agda",
"hexsha": "55d393c921a749ec29b9ad9a3687815912406008",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5db8e95bbcbe8dc0eec810f3e73130ecd78d207c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "m-schmidt/CS410-17-Exercises",
"max_forks_repo_path": "Ex1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5db8e95bbcbe8dc0eec810f3e73130ecd78d207c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "m-schmidt/CS410-17-Exercises",
"max_issues_repo_path": "Ex1.agda",
"max_line_length": 118,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5db8e95bbcbe8dc0eec810f3e73130ecd78d207c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "m-schmidt/CS410-17-Exercises",
"max_stars_repo_path": "Ex1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5003,
"size": 15159
}
|
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
module DTGP
{Domain Word : Set}
(pre post : Word → Domain → Domain)
(_≟_ : (x y : Domain) → Dec (x ≡ y))
where
open import Function
open import Relation.Binary
open import Data.Bool hiding (_≟_)
open import Data.Nat hiding (_≥_; _≟_)
open import Data.Fin hiding (_+_; raise)
open import Data.Maybe
open import Data.Product hiding (map; swap)
open import Data.List hiding (length) renaming (_++_ to _l++_)
open import Data.Vec hiding (_++_; _>>=_; concat; map; init)
open import DTGP.Rand
infixr 5 _∷_ _++_ _++'_
data Term (inp : Domain) : Domain → Set where
[] : Term inp inp
_∷_ : ∀ {d} (w : Word) →
Term inp (pre w d) → Term inp (post w d)
_++_ : ∀ {inp mid out} →
Term mid out →
Term inp mid →
Term inp out
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
data Split {inp out} mid : Term inp out → Set where
_++'_ :
(xs : Term mid out)
(ys : Term inp mid) →
Split mid (xs ++ ys)
swap₁ : ∀ {inp mid out} {xs ys : Term inp out} →
Split mid xs → Split mid ys → Term inp out
swap₁ (xs ++' ys) (as ++' bs) = xs ++ bs
swap₂ : ∀ {inp mid out} {xs ys : Term inp out} →
Split mid xs → Split mid ys → Term inp out
swap₂ (xs ++' ys) (as ++' bs) = as ++ ys
swaps : ∀ {inp mid out} {xs ys : Term inp out} →
Split mid xs → Split mid ys →
Term inp out × Term inp out
swaps xs ys = swap₁ xs ys , swap₂ xs ys
split : ∀ {inp out} (n : ℕ) (xs : Term inp out) → ∃ λ mid → Split mid xs
split zero xs = _ , [] ++' xs
split (suc n) [] = _ , [] ++' []
split (suc n) (x ∷ xs) with split n xs
split (suc n) (x ∷ ._) | _ , xs ++' ys = _ , (x ∷ xs) ++' ys
splits : ∀ {inp out} (n : ℕ) mid → (xs : Term inp out) → ∃ (Vec (Split mid xs))
splits zero mid xs with split zero xs
... | mid' , ys with mid ≟ mid'
... | yes p rewrite p = _ , ys ∷ []
... | no p = _ , []
splits (suc n) mid xs with split (suc n) xs
... | mid' , ys with mid ≟ mid' | splits n mid xs
... | yes p | _ , yss rewrite p = _ , ys ∷ yss
... | no p | _ , yss = _ , yss
length : ∀ {inp out} → Term inp out → ℕ
length [] = 0
length (x ∷ xs) = suc (length xs)
split♀ : ∀ {inp out} → (xs : Term inp out) → Rand (∃ λ mid → Split mid xs)
split♀ xs =
rand >>= λ r →
let i = r mod (suc (length xs))
in return (split (toℕ i) xs)
split♂ : ∀ {inp out} (xs : Term inp out) mid →
Maybe (Rand (Split mid xs))
split♂ xs B
with splits (length xs) B xs
... | zero , [] = nothing
... | suc n , xss = just (
rand >>= λ r →
return (lookup (r mod suc n) xss)
)
crossover : ∀ {inp out} (♀ ♂ : Term inp out) →
Rand (Term inp out × Term inp out)
crossover ♀ ♂ =
split♀ ♀ >>= λ b,xs →
maybe′
(_=<<_ (return ∘ (swaps (proj₂ b,xs))))
(return (♀ , ♂))
(split♂ ♂ (proj₁ b,xs))
Population : ∀ inp out n → Set
Population inp out n = Vec (Term inp out) (2 + n)
module Initialization
(match : ∀ w out → Dec (∃ λ d → out ≡ pre w d))
where
toMaybe : ∀ {w inp out} →
Term inp out →
Dec (∃ λ d → out ≡ pre w d) →
Maybe (∃ λ d → Term inp d)
toMaybe {w = w} ws (no _) = nothing
toMaybe {w = w} ws (yes (_ , p))
rewrite p = just (_ , w ∷ ws)
enum-inp : ∀ (n : ℕ) inp → List Word → List (∃ λ out → Term inp out)
enum-inp zero inp ws = gfilter (λ w → toMaybe [] (match w inp)) ws
enum-inp (suc n) A ws
with enum-inp n A ws
... | ih = concat (map (λ out,t → gfilter (λ w →
toMaybe (proj₂ out,t) (match w (proj₁ out,t))
) ws) ih) l++ ih
filter-out : ∀ {inp} out → List (∃ (Term inp)) → List (Term inp out)
filter-out out [] = []
filter-out out ((out' , x) ∷ xs)
with out' ≟ out
... | no p = filter-out out xs
... | yes p rewrite p = x ∷ filter-out out xs
init : ∀ (n : ℕ) inp out → List Word → List (Term inp out)
init n inp out ws = filter-out out (enum-inp n inp ws)
module Evolution {inp out} (score : Term inp out → ℕ) where
_≥_ : ℕ → ℕ → Bool
zero ≥ zero = true
zero ≥ (suc n) = false
(suc m) ≥ zero = true
(suc m) ≥ (suc n) = m ≥ n
select : ∀ {n} →
Population inp out n → Rand (Term inp out)
select {n = n} xss =
rand >>= λ ii →
rand >>= λ jj →
let ♀ = lookup (ii mod (2 + n)) xss
♂ = lookup (jj mod (2 + n)) xss
in return $
if score ♀ ≥ score ♂
then ♀ else ♂
breed2 : ∀ {n} →
Population inp out n →
Rand (Term inp out × Term inp out)
breed2 xss =
select xss >>= λ ♀ →
select xss >>= λ ♂ →
crossover ♀ ♂
breedN : ∀ {m} → (n : ℕ) →
Population inp out m →
Rand (Vec (Term inp out) n)
breedN zero xss = return []
breedN (suc n) xss =
breed2 xss >>= λ offspring →
breedN n xss >>= λ ih →
return (proj₁ offspring ∷ ih)
evolve1 : ∀ {n} →
Population inp out n → Rand (Population inp out n)
evolve1 xss = breedN _ xss
evolveN : ∀ {n} → (gens : ℕ) →
Population inp out n → Rand (Population inp out n)
evolveN zero xss = return xss
evolveN (suc gens) xss =
evolveN gens xss >>= evolve1
evolve : ∀ {n} → (seed gens : ℕ) →
Population inp out n → Population inp out n
evolve seed gens xss =
runRand (evolveN gens xss) seed
|
{
"alphanum_fraction": 0.5578658297,
"avg_line_length": 28.010989011,
"ext": "agda",
"hexsha": "502bd202274fd2aaf9c1721b8ff9498d6a485694",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:53:14.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-04-17T02:02:58.000Z",
"max_forks_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/dtgp",
"max_forks_repo_path": "src/DTGP.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/dtgp",
"max_issues_repo_path": "src/DTGP.agda",
"max_line_length": 79,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/dtgp",
"max_stars_repo_path": "src/DTGP.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T21:39:58.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-20T16:46:00.000Z",
"num_tokens": 1848,
"size": 5098
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Hash
open import LibraBFT.Lemmas
open import LibraBFT.Base.KVMap
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Impl.Consensus.Types
open import LibraBFT.Impl.Util.Crypto
open import LibraBFT.Impl.Handle sha256 sha256-cr
open import LibraBFT.Concrete.System.Parameters
open EpochConfig
open import LibraBFT.Yasm.Yasm (ℓ+1 0ℓ) EpochConfig epochId authorsN ConcSysParms NodeId-PK-OK
-- This module defines an abstract system state given a reachable
-- concrete system state.
-- An implementation must prove that, if one of its handlers sends a
-- message that contains a vote and is signed by a public key pk, then
-- either the vote's author is the peer executing the handler, the
-- epochId is in range, the peer is a member of the epoch, and its key
-- in that epoch is pk; or, a message with the same signature has been
-- sent before. This is represented by StepPeerState-AllValidParts.
module LibraBFT.Concrete.System (sps-corr : StepPeerState-AllValidParts) where
-- Bring in 'unwind', 'ext-unforgeability' and friends
open Structural sps-corr
-- TODO-1: refactor this somewhere else? Maybe something like
-- LibraBFT.Impl.Consensus.Types.Properties?
sameHonestSig⇒sameVoteData : ∀ {v1 v2 : Vote} {pk}
→ Meta-Honest-PK pk
→ WithVerSig pk v1
→ WithVerSig pk v2
→ v1 ^∙ vSignature ≡ v2 ^∙ vSignature
→ NonInjective-≡ sha256 ⊎ v2 ^∙ vVoteData ≡ v1 ^∙ vVoteData
sameHonestSig⇒sameVoteData {v1} {v2} hpk wvs1 wvs2 refl
with verify-bs-inj (verified wvs1) (verified wvs2)
-- The signable fields of the votes must be the same (we do not model signature collisions)
...| bs≡
-- Therefore the LedgerInfo is the same for the new vote as for the previous vote
= sym <⊎$> (hashVote-inj1 {v1} {v2} (sameBS⇒sameHash bs≡))
honestVoteProps : ∀ {e st} → ReachableSystemState {e} st → ∀ {pk nm v sender}
→ Meta-Honest-PK pk
→ v ⊂Msg nm
→ (sender , nm) ∈ msgPool st
→ WithVerSig pk v
→ NonInjective-≡ sha256 ⊎ v ^∙ vEpoch < e
honestVoteProps r hpk v⊂m m∈pool ver
with honestPartValid r hpk v⊂m m∈pool ver
...| msg , valid
= ⊎-map id (λ { refl → vp-epoch valid })
(sameHonestSig⇒sameVoteData hpk ver (msgSigned msg)
(sym (msgSameSig msg)))
-- We are now ready to define an 'IntermediateSystemState' view for a concrete
-- reachable state. We will do so by fixing an epoch that exists in
-- the system, which will enable us to define the abstract
-- properties. The culminaton of this 'PerEpoch' module is seen in
-- the 'IntSystemState' "function" at the bottom, which probably the
-- best place to start uynderstanding this. Longer term, we will
-- also need higher-level, cross-epoch properties.
module PerState {e}(st : SystemState e)(r : ReachableSystemState st) where
-- TODO-3: Remove this postulate when we are satisfied with the
-- "hash-collision-tracking" solution. For example, when proving voo
-- (in LibraBFT.LibraBFT.Concrete.Properties.VotesOnce), we
-- currently use this postulate to eliminate the possibility of two
-- votes that have the same signature but different VoteData
-- whenever we use sameHonestSig⇒sameVoteData. To eliminate the
-- postulate, we need to refine the properties we prove to enable
-- the possibility of a hash collision, in which case the required
-- property might not hold. However, it is not sufficient to simply
-- prove that a hash collision *exists* (which is obvious,
-- regardless of the LibraBFT implementation). Rather, we
-- ultimately need to produce a specific hash collision and relate
-- it to the data in the system, so that we can prove that the
-- desired properties hold *unless* an actual hash collision is
-- found by the implementation given the data in the system. In
-- the meantime, we simply require that the collision identifies a
-- reachable state; later "collision tracking" will require proof
-- that the colliding values actually exist in that state.
postulate -- temporary
meta-sha256-cr : ¬ (NonInjective-≡ sha256)
module PerEpoch (eid : Fin e) where
𝓔 : EpochConfig
𝓔 = EC-lookup (availEpochs st) eid
open import LibraBFT.Abstract.Abstract UID _≟UID_ NodeId 𝓔 (ConcreteVoteEvidence 𝓔) as Abs hiding (qcVotes; Vote)
open import LibraBFT.Concrete.Intermediate 𝓔 (ConcreteVoteEvidence 𝓔)
open import LibraBFT.Concrete.Records 𝓔
-- * Auxiliary definitions;
-- Here we capture the idea that there exists a vote message that
-- witnesses the existence of a given Abs.Vote
record ∃VoteMsgFor (v : Abs.Vote) : Set where
constructor mk∃VoteMsgFor
field
-- A message that was actually sent
nm : NetworkMsg
cv : Vote
cv∈nm : cv ⊂Msg nm
-- And contained a valid vote that, once abstracted, yeilds v.
vmsgMember : EpochConfig.Member 𝓔
vmsgSigned : WithVerSig (getPubKey 𝓔 vmsgMember) cv
vmsg≈v : α-ValidVote 𝓔 cv vmsgMember ≡ v
vmsgEpoch : cv ^∙ vEpoch ≡ epochId 𝓔
open ∃VoteMsgFor public
record ∃VoteMsgSentFor (sm : SentMessages)(v : Abs.Vote) : Set where
constructor mk∃VoteMsgSentFor
field
vmFor : ∃VoteMsgFor v
vmSender : NodeId
nmSentByAuth : (vmSender , (nm vmFor)) ∈ sm
open ∃VoteMsgSentFor public
∃VoteMsgSentFor-stable : ∀ {e e'} {pre : SystemState e} {post : SystemState e'} {v}
→ Step pre post
→ ∃VoteMsgSentFor (msgPool pre) v
→ ∃VoteMsgSentFor (msgPool post) v
∃VoteMsgSentFor-stable theStep (mk∃VoteMsgSentFor sndr vmFor sba) =
mk∃VoteMsgSentFor sndr vmFor (msgs-stable theStep sba)
record ∃VoteMsgInFor (outs : List NetworkMsg)(v : Abs.Vote) : Set where
constructor mk∃VoteMsgInFor
field
vmFor : ∃VoteMsgFor v
nmInOuts : nm vmFor ∈ outs
open ∃VoteMsgInFor public
∈QC⇒sent : ∀{e} {st : SystemState e} {q α}
→ Abs.Q q α-Sent (msgPool st)
→ Meta-Honest-Member α
→ (vα : α Abs.∈QC q)
→ ∃VoteMsgSentFor (msgPool st) (Abs.∈QC-Vote q vα)
∈QC⇒sent {e} {st} {α = α} vsent@(ws {sender} {nm} e≡ nm∈st (qc∈NM {cqc} {q} .{nm} valid cqc∈nm q≡)) ha va
with All-reduce⁻ {vdq = Any-lookup va} (α-Vote cqc valid) All-self
(subst (Any-lookup va ∈_) (cong Abs.qVotes q≡) (Any-lookup-correctP va))
...| as , as∈cqc , α≡
with α-Vote-evidence cqc valid as∈cqc | inspect
(α-Vote-evidence cqc valid) as∈cqc
...| ev | [ refl ]
with vote∈qc {vs = as} as∈cqc refl cqc∈nm
...| v∈nm =
mk∃VoteMsgSentFor
(mk∃VoteMsgFor nm (₋cveVote ev) v∈nm
(₋ivvMember (₋cveIsValidVote ev))
(₋ivvSigned (₋cveIsValidVote ev)) (sym α≡)
(₋ivvEpoch (₋cveIsValidVote ev)))
sender
nm∈st
-- Finally, we can define the abstract system state corresponding to the concrete state st
IntSystemState : IntermediateSystemState ℓ0
IntSystemState = record
{ InSys = λ { r → r α-Sent (msgPool st) }
; HasBeenSent = λ { v → ∃VoteMsgSentFor (msgPool st) v }
; ∈QC⇒HasBeenSent = ∈QC⇒sent {st = st}
}
|
{
"alphanum_fraction": 0.6423494201,
"avg_line_length": 47.7321428571,
"ext": "agda",
"hexsha": "00c77d01d654044cacf5103329741147cb1b5965",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "haroldcarr/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Concrete/System.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "haroldcarr/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Concrete/System.agda",
"max_line_length": 120,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "haroldcarr/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Concrete/System.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2350,
"size": 8019
}
|
-- {-# OPTIONS -v 20 #-}
-- {-# OPTIONS -v tc.polarity:30 #-}
-- {-# OPTIONS -v tc.decl:30 #-}
-- {-# OPTIONS -v tc.term:30 #-}
-- {-# OPTIONS -v tc.conv.coerce:20 #-}
-- {-# OPTIONS -v tc.signature:30 #-}
-- {-# OPTIONS -v import.iface:100 #-}
module Issue1168 where
open import Agda.Primitive
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
id : ∀{a} {A : Set a} → A → A
id {A = A} a = a
id2 : ∀{A : id Set} → id A → A
id2 x = x
plus0 : ∀ x → x + 0 ≡ x
plus0 zero = refl
plus0 (suc x) rewrite plus0 x = refl
Identity : ∀{a} {A : Set a} (f : A → A) → Set a
Identity f = ∀ x → f x ≡ x
plus-0 : Identity (_+ 0)
plus-0 = plus0
my-Fun : ∀{a b} (A : Set a) (F : A → Set b) → Set (a ⊔ b)
my-Fun A F = (x : A) → F x
syntax my-Fun A (λ x → B) = [ x ∷ A ]=> B
my-id : [ A ∷ Set ]=> [ x ∷ A ]=> A
my-id A x = x
|
{
"alphanum_fraction": 0.5247883918,
"avg_line_length": 21.7631578947,
"ext": "agda",
"hexsha": "a0d1a92542f481b9b47bf5895efe094dbb23a051",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Blaisorblade/Agda",
"max_forks_repo_path": "test/api/Issue1168.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "Blaisorblade/Agda",
"max_issues_repo_path": "test/api/Issue1168.agda",
"max_line_length": 57,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "Blaisorblade/Agda",
"max_stars_repo_path": "test/api/Issue1168.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 339,
"size": 827
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Groups.Definition
open import Setoids.Setoids
open import Setoids.Orders.Partial.Definition
open import Functions.Definition
open import Rings.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Rings.Orders.Partial.Definition {n m : _} {A : Set n} {S : Setoid {n} {m} A} {_+_ : A → A → A} {_*_ : A → A → A} (R : Ring S _+_ _*_) where
open Ring R
open Group additiveGroup
open Setoid S
open import Groups.Orders.Partial.Definition
record PartiallyOrderedRing {p : _} {_<_ : Rel {_} {p} A} (pOrder : SetoidPartialOrder S _<_) : Set (lsuc n ⊔ m ⊔ p) where
field
orderRespectsAddition : {a b : A} → (a < b) → (c : A) → (a + c) < (b + c)
orderRespectsMultiplication : {a b : A} → (0R < a) → (0R < b) → (0R < (a * b))
open SetoidPartialOrder pOrder
toGroup : {p : _} {_<_ : Rel {_} {p} A} {pOrder : SetoidPartialOrder S _<_} → PartiallyOrderedRing pOrder → PartiallyOrderedGroup additiveGroup pOrder
PartiallyOrderedGroup.orderRespectsAddition (toGroup p) = PartiallyOrderedRing.orderRespectsAddition p
|
{
"alphanum_fraction": 0.6902173913,
"avg_line_length": 42.4615384615,
"ext": "agda",
"hexsha": "8f44e3781577f686133978bc652c4ff193b0d3b2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Rings/Orders/Partial/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/Orders/Partial/Definition.agda",
"max_line_length": 150,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Rings/Orders/Partial/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 363,
"size": 1104
}
|
data D : Set₁ where
⟨_⟩_ : Set → Set → D
Test : D → Set
Test ((⟨_⟩ X) _) = X
|
{
"alphanum_fraction": 0.4875,
"avg_line_length": 13.3333333333,
"ext": "agda",
"hexsha": "4cabf555f4425d624231ab5d1775993376ca55ee",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Sections-8.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Sections-8.agda",
"max_line_length": 22,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Sections-8.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 37,
"size": 80
}
|
open import Relation.Binary.Core
module BBHeap.Drop {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import BBHeap _≤_
open import BBHeap.Compound _≤_
open import BBHeap.Equality _≤_
open import BBHeap.Equality.Properties _≤_
open import BBHeap.Subtyping.Properties _≤_ trans≤
open import BBHeap.Perfect _≤_
open import BBHeap.Properties _≤_
open import BBHeap.Push _≤_ tot≤ trans≤
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import Bound.Lower.Order.Properties _≤_ trans≤
open import Data.Empty
open import Data.Product renaming (_×_ to _∧_)
open import Data.Sum renaming (_⊎_ to _∨_)
open import Order.Total _≤_ tot≤
root : {b : Bound}{h : BBHeap b}(cₕ : Compound h) → A
root (cl {x = x} _ _) = x
root (cr {x = x} _ _) = x
mutual
drop : {b : Bound}{h : BBHeap b}(cₕ : Compound h) → BBHeap (val (root cₕ))
drop (cl b≤x l⋘r) = drop⋘ b≤x l⋘r
drop (cr b≤x l⋙r) = drop⋙ b≤x l⋙r
drop⋘ : {b : Bound}{x : A}{l r : BBHeap (val x)}(b≤x : LeB b (val x)) → l ⋘ r → BBHeap (val x)
drop⋘ b≤x lf⋘ = leaf
drop⋘ b≤x (ll⋘ {x = y₁} {x' = y₂} x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂)
with tot≤ y₁ y₂ | lemma-drop⋘ (cl x≤y₁ l₁⋘r₁) (cl x≤y₂ l₂⋘r₂) (ll⋘ x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂)
... | inj₁ y₁≤y₂ | inj₁ (_ , l⋙dr) =
let pl'≈l' = lemma-push⋘ (lexy y₁≤y₂) (lexy refl≤) l₁⋘r₁ ;
l'≈l = ≈left (lexy refl≤) x≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;
pl'≈l = trans≈ pl'≈l' l'≈l ;
pl'⋙dr = lemma≈⋙ pl'≈l l⋙dr ;
pl'⋙dr' = subtyping⋙r (lexy y₁≤y₂) pl'⋙dr
in right x≤y₁ pl'⋙dr'
... | inj₁ y₁≤y₂ | inj₂ dl⋘r =
let r≈r' = ≈left x≤y₂ (lexy y₁≤y₂) l₂⋘r₂ l₂⋘r₂ refl≈ refl≈ ;
dl⋘r' = lemma⋘≈ dl⋘r r≈r'
in left x≤y₁ dl⋘r'
... | inj₂ y₂≤y₁ | inj₁ (_ , l⋙dr) =
let l'≈l = ≈left (lexy y₂≤y₁) x≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;
l'⋙dr = lemma≈⋙ l'≈l l⋙dr
in right x≤y₂ l'⋙dr
... | inj₂ y₂≤y₁ | inj₂ dl⋘r =
let pr'≈r' = lemma-push⋘ (lexy y₂≤y₁) (lexy refl≤) l₂⋘r₂ ;
r'≈pr' = sym≈ pr'≈r' ;
r≈r' = ≈left x≤y₂ (lexy refl≤) l₂⋘r₂ l₂⋘r₂ refl≈ refl≈ ;
r≈pr' = trans≈ r≈r' r'≈pr' ;
dl⋘pr' = lemma⋘≈ dl⋘r r≈pr' ;
dl'⋘pr' = subtyping⋘l (lexy y₂≤y₁) dl⋘pr'
in left x≤y₂ dl'⋘pr'
drop⋘ b≤x (lr⋘ {x = y₁} {x' = y₂} x≤y₁ x≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂)
with tot≤ y₁ y₂ | lemma-drop⋘ (cr x≤y₁ l₁⋙r₁) (cl x≤y₂ l₂⋘r₂) (lr⋘ x≤y₁ x≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂)
... | _ | inj₁ (() , _)
... | inj₁ y₁≤y₂ | inj₂ dl⋘r =
let r≈r' = ≈left x≤y₂ (lexy y₁≤y₂) l₂⋘r₂ l₂⋘r₂ refl≈ refl≈ ;
dl⋘r' = lemma⋘≈ dl⋘r r≈r'
in left x≤y₁ dl⋘r'
... | inj₂ y₂≤y₁ | inj₂ dl⋘r =
let pr'≈r' = lemma-push⋘ (lexy y₂≤y₁) (lexy refl≤) l₂⋘r₂ ;
r'≈pr' = sym≈ pr'≈r' ;
r≈r' = ≈left x≤y₂ (lexy refl≤) l₂⋘r₂ l₂⋘r₂ refl≈ refl≈ ;
r≈pr' = trans≈ r≈r' r'≈pr' ;
dl⋘pr' = lemma⋘≈ dl⋘r r≈pr' ;
dl'⋘pr' = subtyping⋘l (lexy y₂≤y₁) dl⋘pr'
in left x≤y₂ dl'⋘pr'
drop⋙ : {b : Bound}{x : A}{l r : BBHeap (val x)}(b≤x : LeB b (val x)) → l ⋙ r → BBHeap (val x)
drop⋙ b≤x (⋙lf x≤y) = left x≤y lf⋘
drop⋙ b≤x (⋙rl {x = y₁} {x' = y₂} x≤y₁ x≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂)
with tot≤ y₁ y₂ | lemma-drop⋙ (cl x≤y₁ l₁⋘r₁) (cl x≤y₂ l₂⋘r₂) (⋙rl x≤y₁ x≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂)
... | inj₁ y₁≤y₂ | inj₁ (_ , dl⋘r) =
let r≈r' = ≈left x≤y₂ (lexy y₁≤y₂) l₂⋘r₂ l₂⋘r₂ refl≈ refl≈ ;
dl⋘r' = lemma⋘≈ dl⋘r r≈r'
in left x≤y₁ dl⋘r'
... | inj₁ y₁≤y₂ | inj₂ l⋙dr =
let l'≈l = ≈left (lexy refl≤) x≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;
pl'≈l' = lemma-push⋘ (lexy y₁≤y₂) (lexy refl≤) l₁⋘r₁ ;
pl'≈l = trans≈ pl'≈l' l'≈l ;
pl'⋙dr = lemma≈⋙ pl'≈l l⋙dr ;
pl'⋙dr' = subtyping⋙r (lexy y₁≤y₂) pl'⋙dr
in right x≤y₁ pl'⋙dr'
... | inj₂ y₂≤y₁ | inj₁ (_ , dl⋘r) =
let pr'≈r' = lemma-push⋘ (lexy y₂≤y₁) (lexy refl≤) l₂⋘r₂ ;
r'≈r = ≈left (lexy refl≤) x≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈ ;
pr'≈r = trans≈ pr'≈r' r'≈r ;
r≈pr' = sym≈ pr'≈r ;
dl⋘pr' = lemma⋘≈ dl⋘r r≈pr' ;
dl'⋘pr' = subtyping⋘l (lexy y₂≤y₁) dl⋘pr'
in left x≤y₂ dl'⋘pr'
... | inj₂ y₂≤y₁ | inj₂ l⋙dr =
let l'≈l = ≈left (lexy y₂≤y₁) x≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;
l'⋙dr = lemma≈⋙ l'≈l l⋙dr
in right x≤y₂ l'⋙dr
drop⋙ b≤x (⋙rr {x = y₁} {x' = y₂} x≤y₁ x≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂)
with tot≤ y₁ y₂ | lemma-drop⋙ (cl x≤y₁ l₁⋘r₁) (cr x≤y₂ l₂⋙r₂) (⋙rr x≤y₁ x≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂)
... | _ | inj₁ (() , _)
... | inj₁ y₁≤y₂ | inj₂ l⋙dr =
let l'≈l = ≈left (lexy refl≤) x≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;
pl'≈l' = lemma-push⋘ (lexy y₁≤y₂) (lexy refl≤) l₁⋘r₁ ;
pl'≈l = trans≈ pl'≈l' l'≈l ;
pl'⋙dr = lemma≈⋙ pl'≈l l⋙dr ;
pl'⋙dr' = subtyping⋙r (lexy y₁≤y₂) pl'⋙dr
in right x≤y₁ pl'⋙dr'
... | inj₂ y₂≤y₁ | inj₂ l⋙dr =
let l'≈l = ≈left (lexy y₂≤y₁) x≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;
l'⋙dr = lemma≈⋙ l'≈l l⋙dr
in right x≤y₂ l'⋙dr
lemma-drop⋘ : {b : Bound}{l r : BBHeap b}(cₗ : Compound l)(cᵣ : Compound r) → l ⋘ r → l ≃ r ∧ l ⋙ drop cᵣ ∨ drop cₗ ⋘ r
lemma-drop⋘ (cl y≤y₁ lf⋘) (cl y≤y₂ lf⋘) (ll⋘ .y≤y₁ .y≤y₂ .lf⋘ .lf⋘ ≃lf ≃lf) = inj₁ (≃nd y≤y₁ y≤y₂ lf⋘ lf⋘ ≃lf ≃lf ≃lf , ⋙lf y≤y₁)
lemma-drop⋘ (cl y≤y₁ (ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄)) (cl y≤y₂ lf⋘) (ll⋘ .y≤y₁ .y≤y₂ .(ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄) .lf⋘ _ ())
lemma-drop⋘ (cl y≤y₁ (ll⋘ {x = y₃} {x' = y₄} y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄)) (cl y≤y₂ (ll⋘ {x = y₅} {x' = y₆} y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆)) (ll⋘ {x = y₁} .y≤y₁ .y≤y₂ .(ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄) .(ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆) l₂≃r₂ r₁≃l₂)
with tot≤ y₃ y₄ | tot≤ y₅ y₆ | lemma-drop⋘ (cl y₁≤y₃ l₃⋘r₃) (cl y₁≤y₄ l₄⋘r₄) (ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄) | lemma-drop⋘ (cl y₂≤y₅ l₅⋘r₅) (cl y₂≤y₆ l₆⋘r₆) (ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆)
... | _ | inj₁ y₅≤y₆ | inj₁ (l₁≃r₁ , _) | inj₁ (_ , l₂⋙dr₂) =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
l₂⋘r₂ = ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆ ;
l₁≃l₂ = trans≃ l₁≃r₁ r₁≃l₂ ;
pl₂'≈l₂' = lemma-push⋘ (lexy y₅≤y₆) (lexy refl≤) l₅⋘r₅ ;
l₂'≈l₂ = ≈left (lexy refl≤) y₂≤y₅ l₅⋘r₅ l₅⋘r₅ refl≈ refl≈ ;
pl₂'≈l₂ = trans≈ pl₂'≈l₂' l₂'≈l₂ ;
pl₂'⋙dr₂ = lemma≈⋙ pl₂'≈l₂ l₂⋙dr₂ ;
pl₂'⋙dr₂' = subtyping⋙r (lexy y₅≤y₆) pl₂'⋙dr₂ ;
l₂≈pl₂' = sym≈ pl₂'≈l₂ ;
l₁≃pl₂' = lemma≃≈ l₁≃l₂ l₂≈pl₂'
in inj₁ (≃nd y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂ , ⋙rr y≤y₁ y₂≤y₅ l₁⋘r₁ l₁≃r₁ pl₂'⋙dr₂' l₁≃pl₂')
... | _ | inj₂ y₆≤y₅ | inj₁ (l₁≃r₁ , _) | inj₁ (_ , l₂⋙dr₂) =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
l₂⋘r₂ = ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆ ;
l₁≃l₂ = trans≃ l₁≃r₁ r₁≃l₂ ;
l₂'≈l₂ = ≈left (lexy y₆≤y₅) y₂≤y₅ l₅⋘r₅ l₅⋘r₅ refl≈ refl≈ ;
l₂'⋙dr₂ = lemma≈⋙ l₂'≈l₂ l₂⋙dr₂ ;
l₂≈l₂' = sym≈ l₂'≈l₂ ;
l₁≃l₂' = lemma≃≈ l₁≃l₂ l₂≈l₂'
in inj₁ (≃nd y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂ , ⋙rr y≤y₁ y₂≤y₆ l₁⋘r₁ l₁≃r₁ l₂'⋙dr₂ l₁≃l₂')
... | inj₁ y₃≤y₄ | _ | inj₂ dl₁⋘r₁ | _ =
let r₁≈r₁' = ≈left y₁≤y₄ (lexy y₃≤y₄) l₄⋘r₄ l₄⋘r₄ refl≈ refl≈ ;
dl₁⋘r₁' = lemma⋘≈ dl₁⋘r₁ r₁≈r₁' ;
l₂⋘r₂ = ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆ ;
r₁'≈r₁ = sym≈ r₁≈r₁' ;
r₁'≃l₂ = lemma≈≃ r₁'≈r₁ r₁≃l₂
in inj₂ (ll⋘ y₁≤y₃ y≤y₂ dl₁⋘r₁' l₂⋘r₂ l₂≃r₂ r₁'≃l₂)
... | inj₂ y₄≤y₃ | _ | inj₂ dl₁⋘r₁ | _ =
let r₁≈r₁' = ≈left y₁≤y₄ (lexy refl≤) l₄⋘r₄ l₄⋘r₄ refl≈ refl≈ ;
pr₁'≈r₁' = lemma-push⋘ (lexy y₄≤y₃) (lexy refl≤) l₄⋘r₄ ;
dl₁⋘r₁' = lemma⋘≈ dl₁⋘r₁ r₁≈r₁' ;
r₁'≈pr₁' = sym≈ pr₁'≈r₁' ;
r₁≈pr₁' = trans≈ r₁≈r₁' r₁'≈pr₁' ;
dl₁⋘pr₁' = lemma⋘≈ dl₁⋘r₁ r₁≈pr₁' ;
l₂⋘r₂ = ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆ ;
dl₁'⋘pr₁' = subtyping⋘l (lexy y₄≤y₃) dl₁⋘pr₁' ;
r₁'≈r₁ = sym≈ r₁≈r₁' ;
r₁'≃l₂ = lemma≈≃ r₁'≈r₁ r₁≃l₂ ;
pr₁'≃l₂ = lemma≈≃ pr₁'≈r₁' r₁'≃l₂
in inj₂ (ll⋘ y₁≤y₄ y≤y₂ dl₁'⋘pr₁' l₂⋘r₂ l₂≃r₂ pr₁'≃l₂)
... | _ | _ | inj₁ (l₁≃r₁ , l₁⋙dr₁) | inj₂ dl₂⋘r₂
with lemma-drop-⊥ y₂≤y₅ l₅⋘r₅ (lemma-⋘-≃ dl₂⋘r₂ (sym≃ l₂≃r₂))
... | ()
lemma-drop⋘ (cl y≤y₁ (ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄)) (cl y≤y₂ (lr⋘ y₂≤y₅ y₂≤y₆ l₅⋙r₅ l₆⋘r₆ l₆≃r₆ l₅⋗l₆)) (ll⋘ .y≤y₁ .y≤y₂ .(ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄) .(lr⋘ y₂≤y₅ y₂≤y₆ l₅⋙r₅ l₆⋘r₆ l₆≃r₆ l₅⋗l₆) _ ())
lemma-drop⋘ (cl y≤y₁ (lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄)) (cl y≤y₂ lf⋘) (ll⋘ .y≤y₁ .y≤y₂ .(lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄) .lf⋘ _ ())
lemma-drop⋘ (cl y≤y₁ (lr⋘ {x = y₃} {x' = y₄} y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄)) (cl y≤y₂ (ll⋘ {x = y₅} {x' = y₆} y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆)) (ll⋘ .y≤y₁ .y≤y₂ .(lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄) .(ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆) l₂≃r₂ r₁≃l₂)
with tot≤ y₃ y₄ | tot≤ y₅ y₆ | lemma-drop⋘ (cr y₁≤y₃ l₃⋙r₃) (cl y₁≤y₄ l₄⋘r₄) (lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄) | lemma-drop⋘ (cl y₂≤y₅ l₅⋘r₅) (cl y₂≤y₆ l₆⋘r₆) (ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆)
... | _ | inj₁ y₅≤y₆ | inj₁ (l₁≃r₁ , _) | inj₁ (_ , l₂⋙dr₂) =
let l₁⋘r₁ = lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄ ;
l₂⋘r₂ = ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆ ;
l₁≃l₂ = trans≃ l₁≃r₁ r₁≃l₂ ;
pl₂'≈l₂' = lemma-push⋘ (lexy y₅≤y₆) (lexy refl≤) l₅⋘r₅ ;
l₂'≈l₂ = ≈left (lexy refl≤) y₂≤y₅ l₅⋘r₅ l₅⋘r₅ refl≈ refl≈ ;
pl₂'≈l₂ = trans≈ pl₂'≈l₂' l₂'≈l₂ ;
pl₂'⋙dr₂ = lemma≈⋙ pl₂'≈l₂ l₂⋙dr₂ ;
pl₂'⋙dr₂' = subtyping⋙r (lexy y₅≤y₆) pl₂'⋙dr₂ ;
l₂≈pl₂' = sym≈ pl₂'≈l₂ ;
l₁≃pl₂' = lemma≃≈ l₁≃l₂ l₂≈pl₂'
in inj₁ (≃nd y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂ , ⋙rr y≤y₁ y₂≤y₅ l₁⋘r₁ l₁≃r₁ pl₂'⋙dr₂' l₁≃pl₂')
... | _ | inj₂ y₆≤y₅ | inj₁ (l₁≃r₁ , _) | inj₁ (_ , l₂⋙dr₂) =
let l₁⋘r₁ = lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄ ;
l₂⋘r₂ = ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆ ;
l₁≃l₂ = trans≃ l₁≃r₁ r₁≃l₂ ;
l₂'≈l₂ = ≈left (lexy y₆≤y₅) y₂≤y₅ l₅⋘r₅ l₅⋘r₅ refl≈ refl≈ ;
l₂'⋙dr₂ = lemma≈⋙ l₂'≈l₂ l₂⋙dr₂ ;
l₂≈l₂' = sym≈ l₂'≈l₂ ;
l₁≃l₂' = lemma≃≈ l₁≃l₂ l₂≈l₂'
in inj₁ (≃nd y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂ , ⋙rr y≤y₁ y₂≤y₆ l₁⋘r₁ l₁≃r₁ l₂'⋙dr₂ l₁≃l₂')
... | inj₁ y₃≤y₄ | _ | inj₂ dl₁⋘r₁ | _ =
let r₁≈r₁' = ≈left y₁≤y₄ (lexy y₃≤y₄) l₄⋘r₄ l₄⋘r₄ refl≈ refl≈ ;
dl₁⋘r₁' = lemma⋘≈ dl₁⋘r₁ r₁≈r₁' ;
l₂⋘r₂ = ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆ ;
r₁'≈r₁ = sym≈ r₁≈r₁' ;
r₁'≃l₂ = lemma≈≃ r₁'≈r₁ r₁≃l₂
in inj₂ (ll⋘ y₁≤y₃ y≤y₂ dl₁⋘r₁' l₂⋘r₂ l₂≃r₂ r₁'≃l₂)
... | inj₂ y₄≤y₃ | _ | inj₂ dl₁⋘r₁ | _ =
let r₁≈r₁' = ≈left y₁≤y₄ (lexy refl≤) l₄⋘r₄ l₄⋘r₄ refl≈ refl≈ ;
pr₁'≈r₁' = lemma-push⋘ (lexy y₄≤y₃) (lexy refl≤) l₄⋘r₄ ;
dl₁⋘r₁' = lemma⋘≈ dl₁⋘r₁ r₁≈r₁' ;
r₁'≈pr₁' = sym≈ pr₁'≈r₁' ;
r₁≈pr₁' = trans≈ r₁≈r₁' r₁'≈pr₁' ;
dl₁⋘pr₁' = lemma⋘≈ dl₁⋘r₁ r₁≈pr₁' ;
l₂⋘r₂ = ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆ ;
dl₁'⋘pr₁' = subtyping⋘l (lexy y₄≤y₃) dl₁⋘pr₁' ;
r₁'≈r₁ = sym≈ r₁≈r₁' ;
r₁'≃l₂ = lemma≈≃ r₁'≈r₁ r₁≃l₂ ;
pr₁'≃l₂ = lemma≈≃ pr₁'≈r₁' r₁'≃l₂
in inj₂ (ll⋘ y₁≤y₄ y≤y₂ dl₁'⋘pr₁' l₂⋘r₂ l₂≃r₂ pr₁'≃l₂)
... | _ | _ | inj₁ (l₁≃r₁ , l₁⋙dr₁) | inj₂ dl₂⋘r₂
with lemma-drop-⊥ y₂≤y₅ l₅⋘r₅ (lemma-⋘-≃ dl₂⋘r₂ (sym≃ l₂≃r₂))
... | ()
lemma-drop⋘ (cl y≤y₁ (lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄)) (cl y≤y₂ (lr⋘ y₂≤y₅ y₂≤y₆ l₅⋙r₅ l₆⋘r₆ l₆≃r₆ l₅⋗l₆)) (ll⋘ .y≤y₁ .y≤y₂ .(lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄) .(lr⋘ y₂≤y₅ y₂≤y₆ l₅⋙r₅ l₆⋘r₆ l₆≃r₆ l₅⋗l₆) () _)
lemma-drop⋘ (cr y≤y₁ (⋙lf y₁≤y₃)) (cl y≤y₂ lf⋘) (lr⋘ .y≤y₁ .y≤y₂ .(⋙lf y₁≤y₃) .lf⋘ ≃lf (⋗lf .y₁≤y₃)) = inj₂ (ll⋘ y₁≤y₃ y≤y₂ lf⋘ lf⋘ ≃lf ≃lf)
lemma-drop⋘ (cr y≤y₁ (⋙lf y₁≤y₃)) (cl y≤y₂ (ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆)) (lr⋘ .y≤y₁ .y≤y₂ .(⋙lf y₁≤y₃) .(ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆) _ (⋗nd .y₁≤y₃ .y₂≤y₅ .lf⋘ .l₅⋘r₅ _ _ ()))
lemma-drop⋘ (cr y≤y₁ (⋙lf y₁≤y₃)) (cl y≤y₂ (lr⋘ y₂≤y₅ y₂≤y₆ l₅⋙r₅ l₆⋘r₆ l₆≃r₆ l₅⋗l₆)) (lr⋘ .y≤y₁ .y≤y₂ .(⋙lf y₁≤y₃) .(lr⋘ y₂≤y₅ y₂≤y₆ l₅⋙r₅ l₆⋘r₆ l₆≃r₆ l₅⋗l₆) () _)
lemma-drop⋘ (cr y≤y₁ (⋙rl {x = y₃} {x' = y₄} y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₃≃r₃ l₄⋘r₄ l₃⋗r₄)) (cl y≤y₂ l₂⋘r₂) (lr⋘ .y≤y₁ .y≤y₂ .(⋙rl y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₃≃r₃ l₄⋘r₄ l₃⋗r₄) .l₂⋘r₂ l₂≃r₂ l₁⋗l₂)
with tot≤ y₃ y₄ | lemma-drop⋙ (cl y₁≤y₃ l₃⋘r₃) (cl y₁≤y₄ l₄⋘r₄) (⋙rl y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₃≃r₃ l₄⋘r₄ l₃⋗r₄)
... | inj₁ y₃≤y₄ | inj₁ (l₁⋗r₁ , dl₁⋘r₁) =
let r₁≈r₁' = ≈left y₁≤y₄ (lexy y₃≤y₄) l₄⋘r₄ l₄⋘r₄ refl≈ refl≈ ;
dl₁⋘r₁' = lemma⋘≈ dl₁⋘r₁ r₁≈r₁' ;
r₁'≈r₁ = sym≈ r₁≈r₁' ;
r₁≃l₂ = lemma⋗⋗' l₁⋗r₁ l₁⋗l₂ ;
r₁'≃l₂ = lemma≈≃ r₁'≈r₁ r₁≃l₂
in inj₂ (ll⋘ y₁≤y₃ y≤y₂ dl₁⋘r₁' l₂⋘r₂ l₂≃r₂ r₁'≃l₂)
... | inj₁ y₃≤y₄ | inj₂ l₁⋙dr₁ =
let l₁'≈l₁ = ≈left (lexy refl≤) y₁≤y₃ l₃⋘r₃ l₃⋘r₃ refl≈ refl≈ ;
pl₁'≈l₁' = lemma-push⋘ (lexy y₃≤y₄) (lexy refl≤) l₃⋘r₃ ;
pl₁'≈l₁ = trans≈ pl₁'≈l₁' l₁'≈l₁ ;
pl₁'⋙dr = lemma≈⋙ pl₁'≈l₁ l₁⋙dr₁ ;
pl₁'⋙dr₁' = subtyping⋙r (lexy y₃≤y₄) pl₁'⋙dr ;
pl₁'⋗l₂ = lemma≈⋗ pl₁'≈l₁ l₁⋗l₂
in inj₂ (lr⋘ y₁≤y₃ y≤y₂ pl₁'⋙dr₁' l₂⋘r₂ l₂≃r₂ pl₁'⋗l₂)
... | inj₂ y₄≤y₃ | inj₁ (l₁⋗r₁ , dl₁⋘r₁) =
let r₁'≈r₁ = ≈left (lexy refl≤) y₁≤y₄ l₄⋘r₄ l₄⋘r₄ refl≈ refl≈ ;
pr₁'≈r₁' = lemma-push⋘ (lexy y₄≤y₃) (lexy refl≤) l₄⋘r₄ ;
r₁'≈pr₁' = sym≈ pr₁'≈r₁' ;
pr₁'≈r₁ = trans≈ pr₁'≈r₁' r₁'≈r₁ ;
r₁≈pr₁' = sym≈ pr₁'≈r₁ ;
dl₁⋘pr₁' = lemma⋘≈ dl₁⋘r₁ r₁≈pr₁' ;
dl₁'⋘pr₁' = subtyping⋘l (lexy y₄≤y₃) dl₁⋘pr₁' ;
r₁≃l₂ = lemma⋗⋗' l₁⋗r₁ l₁⋗l₂ ;
pr₁'≃l₂ = lemma≈≃ pr₁'≈r₁ r₁≃l₂
in inj₂ (ll⋘ y₁≤y₄ y≤y₂ dl₁'⋘pr₁' l₂⋘r₂ l₂≃r₂ pr₁'≃l₂)
... | inj₂ y₄≤y₃ | inj₂ l₁⋙dr₁ =
let l₁'≈l₁ = ≈left (lexy y₄≤y₃) y₁≤y₃ l₃⋘r₃ l₃⋘r₃ refl≈ refl≈ ;
l₁'⋙dr₁ = lemma≈⋙ l₁'≈l₁ l₁⋙dr₁ ;
l₁'⋗l₂ = lemma≈⋗ l₁'≈l₁ l₁⋗l₂
in inj₂ (lr⋘ y₁≤y₄ y≤y₂ l₁'⋙dr₁ l₂⋘r₂ l₂≃r₂ l₁'⋗l₂)
lemma-drop⋘ (cr y≤y₁ (⋙rr {x = y₃} {x' = y₄} y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₃≃r₃ l₄⋙r₄ l₃≃l₄)) (cl y≤y₂ l₂⋘r₂) (lr⋘ .y≤y₁ .y≤y₂ .(⋙rr y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₃≃r₃ l₄⋙r₄ l₃≃l₄) .l₂⋘r₂ l₂≃r₂ l₁⋗l₂)
with tot≤ y₃ y₄ | lemma-drop⋙ (cl y₁≤y₃ l₃⋘r₃) (cr y₁≤y₄ l₄⋙r₄) (⋙rr y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₃≃r₃ l₄⋙r₄ l₃≃l₄)
... | _ | inj₁ (() , _)
... | inj₁ y₃≤y₄ | inj₂ l₁⋙dr₁ =
let l₁'≈l₁ = ≈left (lexy refl≤) y₁≤y₃ l₃⋘r₃ l₃⋘r₃ refl≈ refl≈ ;
pl₁'≈l₁' = lemma-push⋘ (lexy y₃≤y₄) (lexy refl≤) l₃⋘r₃ ;
pl₁'≈l₁ = trans≈ pl₁'≈l₁' l₁'≈l₁ ;
pl₁'⋙dr = lemma≈⋙ pl₁'≈l₁ l₁⋙dr₁ ;
pl₁'⋙dr₁' = subtyping⋙r (lexy y₃≤y₄) pl₁'⋙dr ;
pl₁'⋗l₂ = lemma≈⋗ pl₁'≈l₁ l₁⋗l₂
in inj₂ (lr⋘ y₁≤y₃ y≤y₂ pl₁'⋙dr₁' l₂⋘r₂ l₂≃r₂ pl₁'⋗l₂)
... | inj₂ y₄≤y₃ | inj₂ l₁⋙dr₁ =
let l₁'≈l₁ = ≈left (lexy y₄≤y₃) y₁≤y₃ l₃⋘r₃ l₃⋘r₃ refl≈ refl≈ ;
l₁'⋙dr₁ = lemma≈⋙ l₁'≈l₁ l₁⋙dr₁ ;
l₁'⋗l₂ = lemma≈⋗ l₁'≈l₁ l₁⋗l₂
in inj₂ (lr⋘ y₁≤y₄ y≤y₂ l₁'⋙dr₁ l₂⋘r₂ l₂≃r₂ l₁'⋗l₂)
lemma-drop⋙ : {b : Bound}{l r : BBHeap b}(cₗ : Compound l)(cᵣ : Compound r) → l ⋙ r → l ⋗ r ∧ drop cₗ ⋘ r ∨ l ⋙ drop cᵣ
lemma-drop⋙ (cl y≤y₁ lf⋘) (cl y≤y₂ l₂⋘r₂) (⋙rl .y≤y₁ .y≤y₂ .lf⋘ _ .l₂⋘r₂ ())
lemma-drop⋙ (cl y≤y₁ (ll⋘ {x = y₃} {x' = y₄} y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄)) (cl y≤y₂ lf⋘) (⋙rl .y≤y₁ .y≤y₂ .(ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄) l₁≃r₁ .lf⋘ l₁⋗r₂)
with tot≤ y₃ y₄ | lemma-drop⋘ (cl y₁≤y₃ l₃⋘r₃) (cl y₁≤y₄ l₄⋘r₄) (ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄)
... | inj₁ y₃≤y₄ | inj₁ (_ , l₁⋙dr₁) =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
l₁⋗l₂ = lemma⋗≃ l₁⋗r₂ ≃lf ;
l₁'≈l₁ = ≈left (lexy refl≤) y₁≤y₃ l₃⋘r₃ l₃⋘r₃ refl≈ refl≈ ;
pl₁'≈l₁' = lemma-push⋘ (lexy y₃≤y₄) (lexy refl≤) l₃⋘r₃ ;
pl₁'≈l₁ = trans≈ pl₁'≈l₁' l₁'≈l₁ ;
pl₁'⋙dr₁ = lemma≈⋙ pl₁'≈l₁ l₁⋙dr₁ ;
pl₁'⋙dr₁' = subtyping⋙r (lexy y₃≤y₄) pl₁'⋙dr₁ ;
pl₁'⋗l₂ = lemma≈⋗ pl₁'≈l₁ l₁⋗l₂
in inj₁ (⋗nd y≤y₁ y≤y₂ l₁⋘r₁ lf⋘ l₁≃r₁ ≃lf l₁⋗l₂ , lr⋘ y₁≤y₃ y≤y₂ pl₁'⋙dr₁' lf⋘ ≃lf pl₁'⋗l₂)
... | inj₂ y₄≤y₃ | inj₁ (_ , l₁⋙dr₁) =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
l₁⋗l₂ = lemma⋗≃ l₁⋗r₂ ≃lf ;
l₁'≈l₁ = ≈left (lexy y₄≤y₃) y₁≤y₃ l₃⋘r₃ l₃⋘r₃ refl≈ refl≈ ;
l₁'⋙dr₁ = lemma≈⋙ l₁'≈l₁ l₁⋙dr₁ ;
l₁'⋗l₂ = lemma≈⋗ l₁'≈l₁ l₁⋗l₂
in inj₁ (⋗nd y≤y₁ y≤y₂ l₁⋘r₁ lf⋘ l₁≃r₁ ≃lf l₁⋗l₂ , lr⋘ y₁≤y₄ y≤y₂ l₁'⋙dr₁ lf⋘ ≃lf l₁'⋗l₂)
... | _ | inj₂ dl₁⋘r₁
with lemma-drop-⊥ y₁≤y₃ l₃⋘r₃ (lemma-⋘-≃ dl₁⋘r₁ (sym≃ l₁≃r₁))
... | ()
lemma-drop⋙ (cl y≤y₁ (ll⋘ {x = y₃} {x' = y₄} y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄)) (cl y≤y₂ (ll⋘ {x = y₅} {x' = y₆} y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆)) (⋙rl .y≤y₁ .y≤y₂ .(ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄) l₁≃r₁ .(ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆) l₁⋗r₂)
with tot≤ y₃ y₄ | tot≤ y₅ y₆ | lemma-drop⋘ (cl y₂≤y₅ l₅⋘r₅) (cl y₂≤y₆ l₆⋘r₆) (ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆) | lemma-drop⋘ (cl y₁≤y₃ l₃⋘r₃) (cl y₁≤y₄ l₄⋘r₄) (ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄)
... | inj₁ y₃≤y₄ | _ | inj₁ (l₂≃r₂ , _) | inj₁ (_ , l₁⋙dr₁) =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
l₂⋘r₂ = ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆ ;
r₂≃l₂ = sym≃ l₂≃r₂ ;
l₁⋗l₂ = lemma⋗≃ l₁⋗r₂ r₂≃l₂ ;
l₁'≈l₁ = ≈left (lexy refl≤) y₁≤y₃ l₃⋘r₃ l₃⋘r₃ refl≈ refl≈ ;
pl₁'≈l₁' = lemma-push⋘ (lexy y₃≤y₄) (lexy refl≤) l₃⋘r₃ ;
pl₁'≈l₁ = trans≈ pl₁'≈l₁' l₁'≈l₁ ;
pl₁'⋙dr₁ = lemma≈⋙ pl₁'≈l₁ l₁⋙dr₁ ;
pl₁'⋙dr₁' = subtyping⋙r (lexy y₃≤y₄) pl₁'⋙dr₁ ;
pl₁'⋗l₂ = lemma≈⋗ pl₁'≈l₁ l₁⋗l₂
in inj₁ (⋗nd y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁⋗l₂ , lr⋘ y₁≤y₃ y≤y₂ pl₁'⋙dr₁' l₂⋘r₂ l₂≃r₂ pl₁'⋗l₂)
... | inj₂ y₄≤y₃ | _ | inj₁ (l₂≃r₂ , _) | inj₁ (_ , l₁⋙dr₁) =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
l₂⋘r₂ = ll⋘ y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₆⋘r₆ l₆≃r₆ r₅≃l₆ ;
r₂≃l₂ = sym≃ l₂≃r₂ ;
l₁⋗l₂ = lemma⋗≃ l₁⋗r₂ r₂≃l₂ ;
l₁'≈l₁ = ≈left (lexy y₄≤y₃) y₁≤y₃ l₃⋘r₃ l₃⋘r₃ refl≈ refl≈ ;
l₁'⋙dr₁ = lemma≈⋙ l₁'≈l₁ l₁⋙dr₁ ;
l₁'⋗l₂ = lemma≈⋗ l₁'≈l₁ l₁⋗l₂
in inj₁ (⋗nd y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁⋗l₂ , lr⋘ y₁≤y₄ y≤y₂ l₁'⋙dr₁ l₂⋘r₂ l₂≃r₂ l₁'⋗l₂)
... | _ | inj₁ y₅≤y₆ | inj₂ dl₂⋘r₂ | _ =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
r₂≈r₂' = ≈left y₂≤y₆ (lexy y₅≤y₆) l₆⋘r₆ l₆⋘r₆ refl≈ refl≈ ;
dl₂⋘r₂' = lemma⋘≈ dl₂⋘r₂ r₂≈r₂' ;
l₁⋗r₂' = lemma⋗≈ l₁⋗r₂ r₂≈r₂'
in inj₂ (⋙rl y≤y₁ y₂≤y₅ l₁⋘r₁ l₁≃r₁ dl₂⋘r₂' l₁⋗r₂')
... | _ | inj₂ y₆≤y₅ | inj₂ dl₂⋘r₂ | _ =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
r₂≈r₂' = ≈left y₂≤y₆ (lexy refl≤) l₆⋘r₆ l₆⋘r₆ refl≈ refl≈ ;
pr₂'≈r₂' = lemma-push⋘ (lexy y₆≤y₅) (lexy refl≤) l₆⋘r₆ ;
r₂'≈pr₂' = sym≈ pr₂'≈r₂' ;
r₂≈pr₂' = trans≈ r₂≈r₂' r₂'≈pr₂';
dl₂⋘pr₂' = lemma⋘≈ dl₂⋘r₂ r₂≈pr₂' ;
dl₂'⋘pr₂' = subtyping⋘l (lexy y₆≤y₅) dl₂⋘pr₂' ;
l₁⋗pr₂' = lemma⋗≈ l₁⋗r₂ r₂≈pr₂'
in inj₂ (⋙rl y≤y₁ y₂≤y₆ l₁⋘r₁ l₁≃r₁ dl₂'⋘pr₂' l₁⋗pr₂')
... | _ | _ | _ | inj₂ dl₁⋘r₁
with lemma-drop-⊥ y₁≤y₃ l₃⋘r₃ (lemma-⋘-≃ dl₁⋘r₁ (sym≃ l₁≃r₁))
... | ()
lemma-drop⋙ (cl y≤y₁ (ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄)) (cl y≤y₂ (lr⋘ {x = y₅} {x' = y₆} y₂≤y₅ y₂≤y₆ l₅⋙r₅ l₆⋘r₆ l₆≃r₆ l₅⋗l₆)) (⋙rl .y≤y₁ .y≤y₂ .(ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄) l₁≃r₁ .(lr⋘ y₂≤y₅ y₂≤y₆ l₅⋙r₅ l₆⋘r₆ l₆≃r₆ l₅⋗l₆) l₁⋗r₂)
with tot≤ y₅ y₆ | lemma-drop⋘ (cr y₂≤y₅ l₅⋙r₅) (cl y₂≤y₆ l₆⋘r₆) (lr⋘ y₂≤y₅ y₂≤y₆ l₅⋙r₅ l₆⋘r₆ l₆≃r₆ l₅⋗l₆)
... | _ | inj₁ (() , _)
... | inj₁ y₅≤y₆ | inj₂ dl₂⋘r₂ =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
r₂≈r₂' = ≈left y₂≤y₆ (lexy y₅≤y₆) l₆⋘r₆ l₆⋘r₆ refl≈ refl≈ ;
dl₂⋘r₂' = lemma⋘≈ dl₂⋘r₂ r₂≈r₂' ;
l₁⋗r₂' = lemma⋗≈ l₁⋗r₂ r₂≈r₂'
in inj₂ (⋙rl y≤y₁ y₂≤y₅ l₁⋘r₁ l₁≃r₁ dl₂⋘r₂' l₁⋗r₂')
... | inj₂ y₆≤y₅ | inj₂ dl₂⋘r₂ =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
r₂≈r₂' = ≈left y₂≤y₆ (lexy refl≤) l₆⋘r₆ l₆⋘r₆ refl≈ refl≈ ;
pr₂'≈r₂' = lemma-push⋘ (lexy y₆≤y₅) (lexy refl≤) l₆⋘r₆ ;
r₂'≈pr₂' = sym≈ pr₂'≈r₂' ;
r₂≈pr₂' = trans≈ r₂≈r₂' r₂'≈pr₂';
dl₂⋘pr₂' = lemma⋘≈ dl₂⋘r₂ r₂≈pr₂' ;
dl₂'⋘pr₂' = subtyping⋘l (lexy y₆≤y₅) dl₂⋘pr₂' ;
l₁⋗pr₂' = lemma⋗≈ l₁⋗r₂ r₂≈pr₂'
in inj₂ (⋙rl y≤y₁ y₂≤y₆ l₁⋘r₁ l₁≃r₁ dl₂'⋘pr₂' l₁⋗pr₂')
lemma-drop⋙ (cl y≤y₁ (lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄)) (cl y≤y₂ l₂⋘r₂) (⋙rl .y≤y₁ .y≤y₂ .(lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄) () .l₂⋘r₂ _)
lemma-drop⋙ _ _ (⋙rr _ _ lf⋘ _ (⋙lf _) ())
lemma-drop⋙ _ _ (⋙rr _ _ lf⋘ _ (⋙rl _ _ _ _ _ _) ())
lemma-drop⋙ _ _ (⋙rr _ _ lf⋘ _ (⋙rr _ _ _ _ _ _) ())
lemma-drop⋙ (cl y≤y₁ (ll⋘ y₁≤y₃ y₁≤y₄ lf⋘ l₄⋘r₄ l₄≃r₄ r₃≃l₄)) (cr y≤y₂ (⋙lf y₂≤y₅)) (⋙rr .y≤y₁ .y≤y₂ .(ll⋘ y₁≤y₃ y₁≤y₄ lf⋘ l₄⋘r₄ l₄≃r₄ r₃≃l₄) l₁≃r₁ .(⋙lf y₂≤y₅) (≃nd .y₁≤y₃ .y₂≤y₅ .lf⋘ .lf⋘ ≃lf ≃lf ≃lf)) =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ lf⋘ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
l₁⋗r₂ = ⋗lf y₁≤y₃
in inj₂ (⋙rl y≤y₁ y₂≤y₅ l₁⋘r₁ l₁≃r₁ lf⋘ l₁⋗r₂)
lemma-drop⋙ _ _ (⋙rr _ _ (ll⋘ y₁≤y₃ _ (ll⋘ _ _ _ _ _ _) _ _ _) _ (⋙lf y₂≤y₅) (≃nd .y₁≤y₃ .y₂≤y₅ .(ll⋘ _ _ _ _ _ _) .lf⋘ _ ≃lf ()))
lemma-drop⋙ _ _ (⋙rr _ _ (ll⋘ y₁≤y₃ _ (lr⋘ _ _ _ _ _ _) _ _ _) _ (⋙lf y₂≤y₅) (≃nd .y₁≤y₃ .y₂≤y₅ .(lr⋘ _ _ _ _ _ _) .lf⋘ _ ≃lf ()))
lemma-drop⋙ (cl y≤y₁ (ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄)) (cr y≤y₂ (⋙rl {x = y₅} {x' = y₆} y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₅≃r₅ l₆⋘r₆ l₅⋗r₆)) (⋙rr .y≤y₁ .y≤y₂ .(ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄) l₁≃r₁ .(⋙rl y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₅≃r₅ l₆⋘r₆ l₅⋗r₆) l₁≃l₂)
with tot≤ y₅ y₆ | lemma-drop⋙ (cl y₂≤y₅ l₅⋘r₅) (cl y₂≤y₆ l₆⋘r₆) (⋙rl y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₅≃r₅ l₆⋘r₆ l₅⋗r₆)
... | inj₁ y₅≤y₆ | inj₁ (l₂⋗r₂ , dl₂⋘r₂) =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
r₂≈r₂' = ≈left y₂≤y₆ (lexy y₅≤y₆) l₆⋘r₆ l₆⋘r₆ refl≈ refl≈ ;
dl₂⋘r₂' = lemma⋘≈ dl₂⋘r₂ r₂≈r₂' ;
l₁⋗r₂ = lemma≃⋗ l₁≃l₂ l₂⋗r₂ ;
l₁⋗r₂' = lemma⋗≈ l₁⋗r₂ r₂≈r₂'
in inj₂ (⋙rl y≤y₁ y₂≤y₅ l₁⋘r₁ l₁≃r₁ dl₂⋘r₂' l₁⋗r₂')
... | inj₁ y₅≤y₆ | inj₂ l₂⋙dr₂ =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
l₂'≈l₂ = ≈left (lexy refl≤) y₂≤y₅ l₅⋘r₅ l₅⋘r₅ refl≈ refl≈ ;
pl₂'≈l₂' = lemma-push⋘ (lexy y₅≤y₆) (lexy refl≤) l₅⋘r₅ ;
pl₂'≈l₂ = trans≈ pl₂'≈l₂' l₂'≈l₂ ;
pl₂'⋙dr₂ = lemma≈⋙ pl₂'≈l₂ l₂⋙dr₂ ;
l₂≈pl₂' = sym≈ pl₂'≈l₂ ;
pl₂'⋙dr₂' = subtyping⋙r (lexy y₅≤y₆) pl₂'⋙dr₂ ;
l₁≃pl₂' = lemma≃≈ l₁≃l₂ l₂≈pl₂'
in inj₂ (⋙rr y≤y₁ y₂≤y₅ l₁⋘r₁ l₁≃r₁ pl₂'⋙dr₂' l₁≃pl₂')
... | inj₂ y₆≤y₅ | inj₁ (l₂⋗r₂ , dl₂⋘r₂) =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
r₂'≈r₂ = ≈left (lexy refl≤) y₂≤y₆ l₆⋘r₆ l₆⋘r₆ refl≈ refl≈ ;
pr₂'≈r₂' = lemma-push⋘ (lexy y₆≤y₅) (lexy refl≤) l₆⋘r₆ ;
pr₂'≈r₂ = trans≈ pr₂'≈r₂' r₂'≈r₂ ;
r₂≈pr₂' = sym≈ pr₂'≈r₂ ;
dl₂⋘pr₂' = lemma⋘≈ dl₂⋘r₂ r₂≈pr₂' ;
dl₂'⋘pr₂' = subtyping⋘l (lexy y₆≤y₅) dl₂⋘pr₂' ;
l₁⋗r₂ = lemma≃⋗ l₁≃l₂ l₂⋗r₂ ;
l₁⋗pr₂' = lemma⋗≈ l₁⋗r₂ r₂≈pr₂'
in inj₂ (⋙rl y≤y₁ y₂≤y₆ l₁⋘r₁ l₁≃r₁ dl₂'⋘pr₂' l₁⋗pr₂')
... | inj₂ y₆≤y₅ | inj₂ l₂⋙dr₂ =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
l₂'≈l₂ = ≈left (lexy y₆≤y₅) y₂≤y₅ l₅⋘r₅ l₅⋘r₅ refl≈ refl≈ ;
l₂'⋙dr₂ = lemma≈⋙ l₂'≈l₂ l₂⋙dr₂ ;
l₂≈l₂' = sym≈ l₂'≈l₂ ;
l₁≃l₂' = lemma≃≈ l₁≃l₂ l₂≈l₂'
in inj₂ (⋙rr y≤y₁ y₂≤y₆ l₁⋘r₁ l₁≃r₁ l₂'⋙dr₂ l₁≃l₂')
lemma-drop⋙ (cl y≤y₁ (ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄)) (cr y≤y₂ (⋙rr {x = y₅} {x' = y₆} y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₅≃r₅ l₆⋙r₆ l₅≃l₆)) (⋙rr .y≤y₁ .y≤y₂ .(ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄) l₁≃r₁ .(⋙rr y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₅≃r₅ l₆⋙r₆ l₅≃l₆) l₁≃l₂)
with tot≤ y₅ y₆ | lemma-drop⋙ (cl y₂≤y₅ l₅⋘r₅) (cr y₂≤y₆ l₆⋙r₆) (⋙rr y₂≤y₅ y₂≤y₆ l₅⋘r₅ l₅≃r₅ l₆⋙r₆ l₅≃l₆)
... | _ | inj₁ (() , _)
... | inj₁ y₅≤y₆ | inj₂ l₂⋙dr₂ =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
l₂'≈l₂ = ≈left (lexy refl≤) y₂≤y₅ l₅⋘r₅ l₅⋘r₅ refl≈ refl≈ ;
pl₂'≈l₂' = lemma-push⋘ (lexy y₅≤y₆) (lexy refl≤) l₅⋘r₅ ;
pl₂'≈l₂ = trans≈ pl₂'≈l₂' l₂'≈l₂ ;
pl₂'⋙dr₂ = lemma≈⋙ pl₂'≈l₂ l₂⋙dr₂ ;
l₂≈pl₂' = sym≈ pl₂'≈l₂ ;
pl₂'⋙dr₂' = subtyping⋙r (lexy y₅≤y₆) pl₂'⋙dr₂ ;
l₁≃pl₂' = lemma≃≈ l₁≃l₂ l₂≈pl₂'
in inj₂ (⋙rr y≤y₁ y₂≤y₅ l₁⋘r₁ l₁≃r₁ pl₂'⋙dr₂' l₁≃pl₂')
... | inj₂ y₆≤y₅ | inj₂ l₂⋙dr₂ =
let l₁⋘r₁ = ll⋘ y₁≤y₃ y₁≤y₄ l₃⋘r₃ l₄⋘r₄ l₄≃r₄ r₃≃l₄ ;
l₂'≈l₂ = ≈left (lexy y₆≤y₅) y₂≤y₅ l₅⋘r₅ l₅⋘r₅ refl≈ refl≈ ;
l₂'⋙dr₂ = lemma≈⋙ l₂'≈l₂ l₂⋙dr₂ ;
l₂≈l₂' = sym≈ l₂'≈l₂ ;
l₁≃l₂' = lemma≃≈ l₁≃l₂ l₂≈l₂'
in inj₂ (⋙rr y≤y₁ y₂≤y₆ l₁⋘r₁ l₁≃r₁ l₂'⋙dr₂ l₁≃l₂')
lemma-drop⋙ (cl y≤y₁ (lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄)) (cr y≤y₂ l₂⋙r₂) (⋙rr .y≤y₁ .y≤y₂ .(lr⋘ y₁≤y₃ y₁≤y₄ l₃⋙r₃ l₄⋘r₄ l₄≃r₄ l₃⋗l₄) () .l₂⋙r₂ _)
lemma-drop-⊥ : {b : Bound}{x : A}{l r : BBHeap (val x)}(b≤x : LeB b (val x))(l⋘r : l ⋘ r) → drop (cl b≤x l⋘r) ⋘ (left b≤x l⋘r) → ⊥
lemma-drop-⊥ _ lf⋘ ()
lemma-drop-⊥ b≤x (ll⋘ {x = y₁} {x' = y₂} x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂) dxlr⋘xlr
with tot≤ y₁ y₂ | lemma-drop⋘ (cl x≤y₁ l₁⋘r₁) (cl x≤y₂ l₂⋘r₂) (ll⋘ x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂) | dxlr⋘xlr | lemma-perfect dxlr⋘xlr
... | inj₁ y₁≤y₂ | inj₁ (l≃r , l⋙dr) | _dxlr⋘xlr | _ =
let l⋘r = ll⋘ x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;
pl'≈l' = lemma-push⋘ (lexy y₁≤y₂) (lexy refl≤) l₁⋘r₁ ;
l'≈l = ≈left (lexy refl≤) x≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;
pl'≈l = trans≈ pl'≈l' l'≈l ;
pl'⋙dr = lemma≈⋙ pl'≈l l⋙dr ;
pl'⋙dr' = subtyping⋙r (lexy y₁≤y₂) pl'⋙dr ;
r≃l = sym≃ l≃r ;
l≃l = trans≃ l≃r r≃l ;
pl'≃l = lemma≈≃ pl'≈l l≃l
in lemma-⋘-⊥ x≤y₁ b≤x pl'⋙dr' l⋘r pl'≃l _dxlr⋘xlr
... | inj₂ y₂≤y₁ | inj₁ (l≃r , l⋙dr) | _dxlr⋘xlr | _ =
let l⋘r = ll⋘ x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;
l'≈l = ≈left (lexy y₂≤y₁) x≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;
l'⋙dr = lemma≈⋙ l'≈l l⋙dr ;
r≃l = sym≃ l≃r ;
l≃l = trans≃ l≃r r≃l ;
l'≃l = lemma≈≃ l'≈l l≃l
in lemma-⋘-⊥ x≤y₂ b≤x l'⋙dr l⋘r l'≃l _dxlr⋘xlr
... | _ | inj₂ dl⋘r | _ | pnd .b≤x .(ll⋘ x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂) l≃r =
let r≃l = sym≃ l≃r ;
dl⋘l = lemma-⋘-≃ dl⋘r r≃l
in lemma-drop-⊥ x≤y₁ l₁⋘r₁ dl⋘l
lemma-drop-⊥ b≤x (lr⋘ x≤y₁ x≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗r₂) dxlr⋘xlr
with lemma-perfect dxlr⋘xlr
... | pnd .b≤x .(lr⋘ x≤y₁ x≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗r₂) ()
|
{
"alphanum_fraction": 0.4194886186,
"avg_line_length": 70.7947019868,
"ext": "agda",
"hexsha": "ab7a74e08d9efd5ad68ac4164325f4f30be851dc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/BBHeap/Drop.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/BBHeap/Drop.agda",
"max_line_length": 281,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/BBHeap/Drop.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 20783,
"size": 32070
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of unique lists (setoid equality)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.Unique.Propositional.Properties where
open import Data.Fin.Base using (Fin)
open import Data.List.Base
open import Data.List.Relation.Binary.Disjoint.Propositional
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
open import Data.List.Relation.Unary.AllPairs as AllPairs using (AllPairs)
open import Data.List.Relation.Unary.Unique.Propositional
import Data.List.Relation.Unary.Unique.Setoid.Properties as Setoid
open import Data.Nat.Base
open import Data.Nat.Properties using (<⇒≢)
open import Function using (id; _∘_)
open import Relation.Binary using (Rel; Setoid)
open import Relation.Binary.PropositionalEquality
using (_≡_; _≢_; sym; setoid)
open import Relation.Unary using (Pred; Decidable)
open import Relation.Nullary using (¬_)
------------------------------------------------------------------------
-- Introduction (⁺) and elimination (⁻) rules for list operations
------------------------------------------------------------------------
-- map
module _ {a b} {A : Set a} {B : Set b} where
map⁺ : ∀ {f} → (∀ {x y} → f x ≡ f y → x ≡ y) →
∀ {xs} → Unique xs → Unique (map f xs)
map⁺ = Setoid.map⁺ (setoid A) (setoid B)
------------------------------------------------------------------------
-- ++
module _ {a} {A : Set a} where
++⁺ : ∀ {xs ys} → Unique xs → Unique ys → Disjoint xs ys → Unique (xs ++ ys)
++⁺ = Setoid.++⁺ (setoid A)
------------------------------------------------------------------------
-- concat
module _ {a} {A : Set a} where
concat⁺ : ∀ {xss} → All Unique xss → AllPairs Disjoint xss → Unique (concat xss)
concat⁺ = Setoid.concat⁺ (setoid A)
------------------------------------------------------------------------
-- take & drop
module _ {a} {A : Set a} where
drop⁺ : ∀ {xs} n → Unique xs → Unique (drop n xs)
drop⁺ = Setoid.drop⁺ (setoid A)
take⁺ : ∀ {xs} n → Unique xs → Unique (take n xs)
take⁺ = Setoid.take⁺ (setoid A)
------------------------------------------------------------------------
-- applyUpTo & upTo
module _ {a} {A : Set a} where
applyUpTo⁺₁ : ∀ f n → (∀ {i j} → i < j → j < n → f i ≢ f j) →
Unique (applyUpTo f n)
applyUpTo⁺₁ = Setoid.applyUpTo⁺₁ (setoid A)
applyUpTo⁺₂ : ∀ f n → (∀ i j → f i ≢ f j) →
Unique (applyUpTo f n)
applyUpTo⁺₂ = Setoid.applyUpTo⁺₂ (setoid A)
------------------------------------------------------------------------
-- upTo
upTo⁺ : ∀ n → Unique (upTo n)
upTo⁺ n = applyUpTo⁺₁ id n (λ i<j _ → <⇒≢ i<j)
------------------------------------------------------------------------
-- applyDownFrom
module _ {a} {A : Set a} where
applyDownFrom⁺₁ : ∀ f n → (∀ {i j} → j < i → i < n → f i ≢ f j) →
Unique (applyDownFrom f n)
applyDownFrom⁺₁ = Setoid.applyDownFrom⁺₁ (setoid A)
applyDownFrom⁺₂ : ∀ f n → (∀ i j → f i ≢ f j) →
Unique (applyDownFrom f n)
applyDownFrom⁺₂ = Setoid.applyDownFrom⁺₂ (setoid A)
------------------------------------------------------------------------
-- downFrom
downFrom⁺ : ∀ n → Unique (downFrom n)
downFrom⁺ n = applyDownFrom⁺₁ id n (λ j<i _ → <⇒≢ j<i ∘ sym)
------------------------------------------------------------------------
-- tabulate
module _ {a} {A : Set a} where
tabulate⁺ : ∀ {n} {f : Fin n → A} → (∀ {i j} → f i ≡ f j → i ≡ j) →
Unique (tabulate f)
tabulate⁺ = Setoid.tabulate⁺ (setoid A)
------------------------------------------------------------------------
-- allFin
allFin⁺ : ∀ n → Unique (allFin n)
allFin⁺ n = tabulate⁺ id
------------------------------------------------------------------------
-- filter
module _ {a p} {A : Set a} {P : Pred _ p} (P? : Decidable P) where
filter⁺ : ∀ {xs} → Unique xs → Unique (filter P? xs)
filter⁺ = Setoid.filter⁺ (setoid A) P?
|
{
"alphanum_fraction": 0.4589158695,
"avg_line_length": 32.616,
"ext": "agda",
"hexsha": "a637d603c4ae341c27c893224a870f5cf718a652",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Relation/Unary/Unique/Propositional/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Unary/Unique/Propositional/Properties.agda",
"max_line_length": 82,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Unary/Unique/Propositional/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 1127,
"size": 4077
}
|
------------------------------------------------------------------------
-- Properties of functions, such as associativity and commutativity
------------------------------------------------------------------------
-- These properties can (for instance) be used to define algebraic
-- structures.
open import Relation.Binary
-- The properties are specified using the following relation as
-- "equality".
module Algebra.FunctionProperties {A} (_≈_ : Rel A) where
open import Data.Product
------------------------------------------------------------------------
-- Unary and binary operations
open import Algebra.FunctionProperties.Core public
------------------------------------------------------------------------
-- Properties of operations
Associative : Op₂ A → Set
Associative _∙_ = ∀ x y z → ((x ∙ y) ∙ z) ≈ (x ∙ (y ∙ z))
Commutative : Op₂ A → Set
Commutative _∙_ = ∀ x y → (x ∙ y) ≈ (y ∙ x)
LeftIdentity : A → Op₂ A → Set
LeftIdentity e _∙_ = ∀ x → (e ∙ x) ≈ x
RightIdentity : A → Op₂ A → Set
RightIdentity e _∙_ = ∀ x → (x ∙ e) ≈ x
Identity : A → Op₂ A → Set
Identity e ∙ = LeftIdentity e ∙ × RightIdentity e ∙
LeftZero : A → Op₂ A → Set
LeftZero z _∙_ = ∀ x → (z ∙ x) ≈ z
RightZero : A → Op₂ A → Set
RightZero z _∙_ = ∀ x → (x ∙ z) ≈ z
Zero : A → Op₂ A → Set
Zero z ∙ = LeftZero z ∙ × RightZero z ∙
LeftInverse : A → Op₁ A → Op₂ A → Set
LeftInverse e _⁻¹ _∙_ = ∀ x → (x ⁻¹ ∙ x) ≈ e
RightInverse : A → Op₁ A → Op₂ A → Set
RightInverse e _⁻¹ _∙_ = ∀ x → (x ∙ (x ⁻¹)) ≈ e
Inverse : A → Op₁ A → Op₂ A → Set
Inverse e ⁻¹ ∙ = LeftInverse e ⁻¹ ∙ × RightInverse e ⁻¹ ∙
_DistributesOverˡ_ : Op₂ A → Op₂ A → Set
_*_ DistributesOverˡ _+_ =
∀ x y z → (x * (y + z)) ≈ ((x * y) + (x * z))
_DistributesOverʳ_ : Op₂ A → Op₂ A → Set
_*_ DistributesOverʳ _+_ =
∀ x y z → ((y + z) * x) ≈ ((y * x) + (z * x))
_DistributesOver_ : Op₂ A → Op₂ A → Set
* DistributesOver + = (* DistributesOverˡ +) × (* DistributesOverʳ +)
_IdempotentOn_ : Op₂ A → A → Set
_∙_ IdempotentOn x = (x ∙ x) ≈ x
Idempotent : Op₂ A → Set
Idempotent ∙ = ∀ x → ∙ IdempotentOn x
IdempotentFun : Op₁ A → Set
IdempotentFun f = ∀ x → f (f x) ≈ f x
_Absorbs_ : Op₂ A → Op₂ A → Set
_∙_ Absorbs _∘_ = ∀ x y → (x ∙ (x ∘ y)) ≈ x
Absorptive : Op₂ A → Op₂ A → Set
Absorptive ∙ ∘ = (∙ Absorbs ∘) × (∘ Absorbs ∙)
Involutive : Op₁ A → Set
Involutive f = ∀ x → f (f x) ≈ x
|
{
"alphanum_fraction": 0.5283340435,
"avg_line_length": 27.2906976744,
"ext": "agda",
"hexsha": "9162175f0ca37d1ae97644be45225d967f348efc",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Algebra/FunctionProperties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Algebra/FunctionProperties.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Algebra/FunctionProperties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 842,
"size": 2347
}
|
------------------------------------------------------------------------
-- A type soundness result
------------------------------------------------------------------------
open import Prelude
open import Prelude.Size
import Lambda.Syntax
module Lambda.Type-soundness
{Name : Type}
(open Lambda.Syntax Name)
(open Closure Tm)
(def : Name → Tm 1)
(Σ : Name → Ty ∞ × Ty ∞)
where
open import Equality.Propositional
open import Function-universe equality-with-J
open import Maybe equality-with-J
open import Monad equality-with-J
open import Vec.Data equality-with-J
open import Delay-monad.Always
open import Delay-monad.Bisimilarity
open import Lambda.Delay-crash
open import Lambda.Interpreter def
-- WF-Value, WF-Env and WF-MV specify when a
-- value/environment/potential value is well-formed with respect to a
-- given context (and type).
mutual
data WF-Value : Ty ∞ → Value → Type where
lam : ∀ {n Γ σ τ} {t : Tm (1 + n)} {ρ} →
Σ , force σ ∷ Γ ⊢ t ∈ force τ →
WF-Env Γ ρ →
WF-Value (σ ⇾′ τ) (lam t ρ)
con : ∀ b → WF-Value bool (con b)
WF-Env : ∀ {n} → Ctxt n → Env n → Type
WF-Env Γ ρ = ∀ x → WF-Value (index Γ x) (index ρ x)
WF-MV : Ty ∞ → Maybe Value → Type
WF-MV σ v = maybe (WF-Value σ) Prelude.⊥ v
-- Some "constructors" for WF-Env.
[]-wf : WF-Env [] []
[]-wf ()
infixr 5 _∷-wf_
_∷-wf_ : ∀ {n} {Γ : Ctxt n} {ρ σ v} →
WF-Value σ v → WF-Env Γ ρ → WF-Env (σ ∷ Γ) (v ∷ ρ)
(v-wf ∷-wf ρ-wf) fzero = v-wf
(v-wf ∷-wf ρ-wf) (fsuc x) = ρ-wf x
-- If we can prove □ ∞ (WF-MV σ) (run x), then x does not "go wrong".
does-not-go-wrong : ∀ {σ} {x : Delay-crash Value ∞} →
□ ∞ (WF-MV σ) x → ¬ x ≈ crash
does-not-go-wrong (now {x = nothing} ())
does-not-go-wrong (now {x = just x} x-wf) ()
does-not-go-wrong (later x-wf) (laterˡ x↯) =
does-not-go-wrong (force x-wf) x↯
-- A "constructor" for □ i ∘ WF-MV.
_>>=-wf_ :
∀ {i σ τ} {x : Delay-crash Value ∞} {f : Value → Delay-crash Value ∞} →
□ i (WF-MV σ) x →
(∀ {v} → WF-Value σ v → □ i (WF-MV τ) (f v)) →
□ i (WF-MV τ) (x >>= f)
x-wf >>=-wf f-wf =
□->>= x-wf λ { {nothing} ()
; {just v} v-wf → f-wf v-wf
}
-- Well-typed programs do not "go wrong".
module _ (def∈ : (f : Name) →
Σ , proj₁ (Σ f) ∷ [] ⊢ def f ∈ proj₂ (Σ f)) where
mutual
⟦⟧-wf : ∀ {i n Γ} (t : Tm n) {σ} → Σ , Γ ⊢ t ∈ σ →
∀ {ρ} → WF-Env Γ ρ →
□ i (WF-MV σ) (⟦ t ⟧ ρ)
⟦⟧-wf (var x) var ρ-wf = now (ρ-wf x)
⟦⟧-wf (lam t) (lam t∈) ρ-wf = now (lam t∈ ρ-wf)
⟦⟧-wf (t₁ · t₂) (t₁∈ · t₂∈) ρ-wf =
⟦⟧-wf t₁ t₁∈ ρ-wf >>=-wf λ f-wf →
⟦⟧-wf t₂ t₂∈ ρ-wf >>=-wf λ v-wf →
∙-wf f-wf v-wf
⟦⟧-wf (call f t) (call t∈) ρ-wf =
⟦⟧-wf t t∈ ρ-wf >>=-wf λ v-wf →
∙-wf {σ = λ { .force → proj₁ (Σ f) }}
{τ = λ { .force → proj₂ (Σ f) }}
(lam (def∈ f) []-wf) v-wf
⟦⟧-wf (con b) con ρ-wf = now (con b)
⟦⟧-wf (if t₁ t₂ t₃) (if t₁∈ t₂∈ t₃∈) ρ-wf =
⟦⟧-wf t₁ t₁∈ ρ-wf >>=-wf λ v₁-wf →
⟦if⟧-wf v₁-wf t₂∈ t₃∈ ρ-wf
∙-wf : ∀ {i σ τ f v} →
WF-Value (σ ⇾′ τ) f → WF-Value (force σ) v →
□ i (WF-MV (force τ)) (f ∙ v)
∙-wf (lam t₁∈ ρ₁-wf) v₂-wf =
later λ { .force → ⟦⟧-wf _ t₁∈ (v₂-wf ∷-wf ρ₁-wf) }
⟦if⟧-wf : ∀ {i n Γ σ v} {t₂ t₃ : Tm n} →
WF-Value bool v →
Σ , Γ ⊢ t₂ ∈ σ →
Σ , Γ ⊢ t₃ ∈ σ →
∀ {ρ} → WF-Env Γ ρ →
□ i (WF-MV σ) (⟦if⟧ v t₂ t₃ ρ)
⟦if⟧-wf (con true) t₂∈ t₃∈ ρ-wf = ⟦⟧-wf _ t₂∈ ρ-wf
⟦if⟧-wf (con false) t₂∈ t₃∈ ρ-wf = ⟦⟧-wf _ t₃∈ ρ-wf
type-soundness : ∀ {t : Tm 0} {σ} →
Σ , [] ⊢ t ∈ σ → ¬ ⟦ t ⟧ [] ≈ crash
type-soundness {t = t} {σ} =
Σ , [] ⊢ t ∈ σ ↝⟨ (λ t∈ → ⟦⟧-wf _ t∈ []-wf) ⟩
□ ∞ (WF-MV σ) (⟦ t ⟧ []) ↝⟨ does-not-go-wrong ⟩□
¬ ⟦ t ⟧ [] ≈ crash □
|
{
"alphanum_fraction": 0.4529784537,
"avg_line_length": 30.3461538462,
"ext": "agda",
"hexsha": "816ee428b49f16abde71cfd71e29779785c7a85b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/definitional-interpreters",
"max_forks_repo_path": "src/Lambda/Type-soundness.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/definitional-interpreters",
"max_issues_repo_path": "src/Lambda/Type-soundness.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/definitional-interpreters",
"max_stars_repo_path": "src/Lambda/Type-soundness.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1739,
"size": 3945
}
|
open import Common.Prelude
test : Nat → Nat
test = __+ 2
|
{
"alphanum_fraction": 0.6896551724,
"avg_line_length": 11.6,
"ext": "agda",
"hexsha": "db054f639641cfa2b4bef4196c38dbbfd0c9775c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Sections-6.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Sections-6.agda",
"max_line_length": 26,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Sections-6.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 19,
"size": 58
}
|
{-
This file contains:
- Eliminator for propositional truncation
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.PropositionalTruncation.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation.Base
private
variable
ℓ : Level
A B C : Type ℓ
∥∥-isPropDep : (P : A → Type ℓ) → isOfHLevelDep 1 (λ x → ∥ P x ∥)
∥∥-isPropDep P = isOfHLevel→isOfHLevelDep 1 (λ _ → squash)
rec : {P : Type ℓ} → isProp P → (A → P) → ∥ A ∥ → P
rec Pprop f ∣ x ∣ = f x
rec Pprop f (squash x y i) = Pprop (rec Pprop f x) (rec Pprop f y) i
rec2 : {P : Type ℓ} → isProp P → (A → B → P) → ∥ A ∥ → ∥ B ∥ → P
rec2 Pprop f ∣ x ∣ ∣ y ∣ = f x y
rec2 Pprop f ∣ x ∣ (squash y z i) = Pprop (rec2 Pprop f ∣ x ∣ y) (rec2 Pprop f ∣ x ∣ z) i
rec2 Pprop f (squash x y i) z = Pprop (rec2 Pprop f x z) (rec2 Pprop f y z) i
-- Old version
-- rec2 : ∀ {P : Type ℓ} → isProp P → (A → A → P) → ∥ A ∥ → ∥ A ∥ → P
-- rec2 Pprop f = rec (isProp→ Pprop) (λ a → rec Pprop (f a))
elim : {P : ∥ A ∥ → Type ℓ} → ((a : ∥ A ∥) → isProp (P a))
→ ((x : A) → P ∣ x ∣) → (a : ∥ A ∥) → P a
elim Pprop f ∣ x ∣ = f x
elim Pprop f (squash x y i) =
isOfHLevel→isOfHLevelDep 1 Pprop
(elim Pprop f x) (elim Pprop f y) (squash x y) i
elim2 : {P : ∥ A ∥ → ∥ A ∥ → Type ℓ}
(Bset : ((x y : ∥ A ∥) → isProp (P x y)))
(f : (a b : A) → P ∣ a ∣ ∣ b ∣)
(x y : ∥ A ∥) → P x y
elim2 Pprop f = elim (λ _ → isPropΠ (λ _ → Pprop _ _))
(λ a → elim (λ _ → Pprop _ _) (f a))
elim3 : {P : ∥ A ∥ → ∥ A ∥ → ∥ A ∥ → Type ℓ}
(Bset : ((x y z : ∥ A ∥) → isProp (P x y z)))
(g : (a b c : A) → P (∣ a ∣) ∣ b ∣ ∣ c ∣)
(x y z : ∥ A ∥) → P x y z
elim3 Pprop g = elim2 (λ _ _ → isPropΠ (λ _ → Pprop _ _ _))
(λ a b → elim (λ _ → Pprop _ _ _) (g a b))
propTruncIsProp : isProp ∥ A ∥
propTruncIsProp x y = squash x y
propTruncIdempotent≃ : isProp A → ∥ A ∥ ≃ A
propTruncIdempotent≃ {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 (λ _ → isProp→isSet propTruncIsProp _ _) (λ _ → refl)
propTruncIdempotent : isProp A → ∥ A ∥ ≡ A
propTruncIdempotent hA = ua (propTruncIdempotent≃ hA)
-- We could also define the eliminator using the recursor
elim' : {P : ∥ A ∥ → Type ℓ} → ((a : ∥ A ∥) → isProp (P a)) →
((x : A) → P ∣ x ∣) → (a : ∥ A ∥) → P a
elim' {P = P} Pprop f a =
rec (Pprop a) (λ x → transp (λ i → P (squash ∣ x ∣ a i)) i0 (f x)) a
map : (A → B) → (∥ A ∥ → ∥ B ∥)
map f = rec squash (∣_∣ ∘ f)
map2 : (A → B → C) → (∥ A ∥ → ∥ B ∥ → ∥ C ∥)
map2 f = rec (isPropΠ λ _ → squash) (map ∘ f)
-- The propositional truncation can be eliminated into non-propositional
-- types as long as the function used in the eliminator is 'coherently
-- constant.' The details of this can be found in the following paper:
--
-- https://arxiv.org/pdf/1411.2682.pdf
module SetElim (Bset : isSet B) where
Bset' : isSet' B
Bset' = isSet→isSet' Bset
rec→Set : (f : A → B) (kf : 2-Constant f) → ∥ A ∥ → B
helper : (f : A → B) (kf : 2-Constant f) → (t u : ∥ A ∥)
→ rec→Set f kf t ≡ rec→Set f kf u
rec→Set f kf ∣ x ∣ = f x
rec→Set f kf (squash t u i) = helper f kf t u i
helper f kf ∣ x ∣ ∣ y ∣ = kf x y
helper f kf (squash t u i) v
= Bset' (helper f kf t v) (helper f kf u v) (helper f kf t u) refl i
helper f kf t (squash u v i)
= Bset' (helper f kf t u) (helper f kf t v) refl (helper f kf u v) i
kcomp : (f : ∥ A ∥ → B) → 2-Constant (f ∘ ∣_∣)
kcomp f x y = cong f (squash ∣ x ∣ ∣ y ∣)
Fset : isSet (A → B)
Fset = isSetΠ (const Bset)
Kset : (f : A → B) → isSet (2-Constant f)
Kset f = isSetΠ (λ _ → isSetΠ (λ _ → isProp→isSet (Bset _ _)))
setRecLemma
: (f : ∥ A ∥ → B)
→ rec→Set (f ∘ ∣_∣) (kcomp f) ≡ f
setRecLemma f i t
= elim {P = λ t → rec→Set (f ∘ ∣_∣) (kcomp f) t ≡ f t}
(λ t → Bset _ _) (λ x → refl) t i
mkKmap : (∥ A ∥ → B) → Σ (A → B) 2-Constant
mkKmap f = f ∘ ∣_∣ , kcomp f
fib : (g : Σ (A → B) 2-Constant) → fiber mkKmap g
fib (g , kg) = rec→Set g kg , refl
eqv : (g : Σ (A → B) 2-Constant) → ∀ fi → fib g ≡ fi
eqv g (f , p) =
Σ≡Prop (λ f → isOfHLevelΣ 2 Fset Kset _ _)
(cong (uncurry rec→Set) (sym p) ∙ setRecLemma f)
trunc→Set≃ : (∥ A ∥ → B) ≃ (Σ (A → B) 2-Constant)
trunc→Set≃ .fst = mkKmap
trunc→Set≃ .snd .equiv-proof g = fib g , eqv g
-- The strategy of this equivalence proof follows the paper more closely.
-- It is used further down for the groupoid version, because the above
-- strategy does not generalize so easily.
e : B → Σ (A → B) 2-Constant
e b = const b , λ _ _ → refl
eval : A → (γ : Σ (A → B) 2-Constant) → B
eval a₀ (g , _) = g a₀
e-eval : ∀ (a₀ : A) γ → e (eval a₀ γ) ≡ γ
e-eval a₀ (g , kg) i .fst a₁ = kg a₀ a₁ i
e-eval a₀ (g , kg) i .snd a₁ a₂ = Bset' refl (kg a₁ a₂) (kg a₀ a₁) (kg a₀ a₂) i
e-isEquiv : A → isEquiv (e {A = A})
e-isEquiv a₀ = isoToIsEquiv (iso e (eval a₀) (e-eval a₀) λ _ → refl)
preEquiv₁ : ∥ A ∥ → B ≃ Σ (A → B) 2-Constant
preEquiv₁ t = e , rec (isPropIsEquiv e) e-isEquiv t
preEquiv₂ : (∥ A ∥ → Σ (A → B) 2-Constant) ≃ Σ (A → B) 2-Constant
preEquiv₂ = isoToEquiv (iso to const (λ _ → refl) retr)
where
to : (∥ A ∥ → Σ (A → B) 2-Constant) → Σ (A → B) 2-Constant
to f .fst x = f ∣ x ∣ .fst x
to f .snd x y i = f (squash ∣ x ∣ ∣ y ∣ i) .snd x y i
retr : retract to const
retr f i t .fst x = f (squash ∣ x ∣ t i) .fst x
retr f i t .snd x y
= Bset'
(λ j → f (squash ∣ x ∣ ∣ y ∣ j) .snd x y j)
(f t .snd x y)
(λ j → f (squash ∣ x ∣ t j) .fst x)
(λ j → f (squash ∣ y ∣ t j) .fst y)
i
trunc→Set≃₂ : (∥ A ∥ → B) ≃ Σ (A → B) 2-Constant
trunc→Set≃₂ = compEquiv (equivΠCod preEquiv₁) preEquiv₂
open SetElim public using (rec→Set; trunc→Set≃)
elim→Set
: {P : ∥ A ∥ → Type ℓ}
→ (∀ t → isSet (P t))
→ (f : (x : A) → P ∣ x ∣)
→ (kf : ∀ x y → PathP (λ i → P (squash ∣ x ∣ ∣ y ∣ i)) (f x) (f y))
→ (t : ∥ A ∥) → P t
elim→Set {A = A} {P = P} Pset f kf t
= rec→Set (Pset t) g gk t
where
g : A → P t
g x = transp (λ i → P (squash ∣ x ∣ t i)) i0 (f x)
gk : 2-Constant g
gk x y i = transp (λ j → P (squash (squash ∣ x ∣ ∣ y ∣ i) t j)) i0 (kf x y i)
RecHProp : (P : A → hProp ℓ) (kP : ∀ x y → P x ≡ P y) → ∥ A ∥ → hProp ℓ
RecHProp P kP = rec→Set isSetHProp P kP
module GpdElim (Bgpd : isGroupoid B) where
Bgpd' : isGroupoid' B
Bgpd' = isGroupoid→isGroupoid' Bgpd
module _ (f : A → B) (3kf : 3-Constant f) where
open 3-Constant 3kf
rec→Gpd : ∥ A ∥ → B
pathHelper : (t u : ∥ A ∥) → rec→Gpd t ≡ rec→Gpd u
triHelper₁
: (t u v : ∥ A ∥)
→ Square (pathHelper t u) (pathHelper t v) refl (pathHelper u v)
triHelper₂
: (t u v : ∥ A ∥)
→ Square (pathHelper t v) (pathHelper u v) (pathHelper t u) refl
rec→Gpd ∣ x ∣ = f x
rec→Gpd (squash t u i) = pathHelper t u i
pathHelper ∣ x ∣ ∣ y ∣ = link x y
pathHelper (squash t u j) v = triHelper₂ t u v j
pathHelper ∣ x ∣ (squash u v j) = triHelper₁ ∣ x ∣ u v j
triHelper₁ ∣ x ∣ ∣ y ∣ ∣ z ∣ = coh₁ x y z
triHelper₁ (squash s t i) u v
= Bgpd'
(triHelper₁ s u v)
(triHelper₁ t u v)
(triHelper₂ s t u)
(triHelper₂ s t v)
(λ i → refl)
(λ i → pathHelper u v)
i
triHelper₁ ∣ x ∣ (squash t u i) v
= Bgpd'
(triHelper₁ ∣ x ∣ t v)
(triHelper₁ ∣ x ∣ u v)
(triHelper₁ ∣ x ∣ t u)
(λ i → pathHelper ∣ x ∣ v)
(λ i → refl)
(triHelper₂ t u v)
i
triHelper₁ ∣ x ∣ ∣ y ∣ (squash u v i)
= Bgpd'
(triHelper₁ ∣ x ∣ ∣ y ∣ u)
(triHelper₁ ∣ x ∣ ∣ y ∣ v)
(λ i → link x y)
(triHelper₁ ∣ x ∣ u v)
(λ i → refl)
(triHelper₁ ∣ y ∣ u v)
i
triHelper₂ ∣ x ∣ ∣ y ∣ ∣ z ∣ = coh₂ x y z
triHelper₂ (squash s t i) u v
= Bgpd'
(triHelper₂ s u v)
(triHelper₂ t u v)
(triHelper₂ s t v)
(λ i → pathHelper u v)
(triHelper₂ s t u)
(λ i → refl)
i
triHelper₂ ∣ x ∣ (squash t u i) v
= Bgpd'
(triHelper₂ ∣ x ∣ t v)
(triHelper₂ ∣ x ∣ u v)
(λ i → pathHelper ∣ x ∣ v)
(triHelper₂ t u v)
(triHelper₁ ∣ x ∣ t u)
(λ i → refl)
i
triHelper₂ ∣ x ∣ ∣ y ∣ (squash u v i)
= Bgpd'
(triHelper₂ ∣ x ∣ ∣ y ∣ u)
(triHelper₂ ∣ x ∣ ∣ y ∣ v)
(triHelper₁ ∣ x ∣ u v)
(triHelper₁ ∣ y ∣ u v)
(λ i → link x y)
(λ i → refl)
i
preEquiv₁ : (∥ A ∥ → Σ (A → B) 3-Constant) ≃ Σ (A → B) 3-Constant
preEquiv₁ = isoToEquiv (iso fn const (λ _ → refl) retr)
where
open 3-Constant
fn : (∥ A ∥ → Σ (A → B) 3-Constant) → Σ (A → B) 3-Constant
fn f .fst x = f ∣ x ∣ .fst x
fn f .snd .link x y i = f (squash ∣ x ∣ ∣ y ∣ i) .snd .link x y i
fn f .snd .coh₁ x y z i j
= f (squash ∣ x ∣ (squash ∣ y ∣ ∣ z ∣ i) j) .snd .coh₁ x y z i j
retr : retract fn const
retr f i t .fst x = f (squash ∣ x ∣ t i) .fst x
retr f i t .snd .link x y j
= f (squash (squash ∣ x ∣ ∣ y ∣ j) t i) .snd .link x y j
retr f i t .snd .coh₁ x y z
= Bgpd'
(λ k j → f (cb k j i0) .snd .coh₁ x y z k j )
(λ k j → f (cb k j i1) .snd .coh₁ x y z k j)
(λ k j → f (cb i0 j k) .snd .link x y j)
(λ k j → f (cb i1 j k) .snd .link x z j)
(λ _ → refl)
(λ k j → f (cb j i1 k) .snd .link y z j)
i
where
cb : I → I → I → ∥ _ ∥
cb i j k = squash (squash ∣ x ∣ (squash ∣ y ∣ ∣ z ∣ i) j) t k
e : B → Σ (A → B) 3-Constant
e b .fst _ = b
e b .snd = record
{ link = λ _ _ _ → b
; coh₁ = λ _ _ _ _ _ → b
}
eval : A → Σ (A → B) 3-Constant → B
eval a₀ (g , _) = g a₀
module _ where
open 3-Constant
e-eval : ∀(a₀ : A) γ → e (eval a₀ γ) ≡ γ
e-eval a₀ (g , 3kg) i .fst x = 3kg .link a₀ x i
e-eval a₀ (g , 3kg) i .snd .link x y = λ j → 3kg .coh₁ a₀ x y j i
e-eval a₀ (g , 3kg) i .snd .coh₁ x y z
= Bgpd'
(λ _ _ → g a₀)
(3kg .coh₁ x y z)
(λ k j → 3kg .coh₁ a₀ x y j k)
(λ k j → 3kg .coh₁ a₀ x z j k)
(λ _ → refl)
(λ k j → 3kg .coh₁ a₀ y z j k)
i
e-isEquiv : A → isEquiv (e {A = A})
e-isEquiv a₀ = isoToIsEquiv (iso e (eval a₀) (e-eval a₀) λ _ → refl)
preEquiv₂ : ∥ A ∥ → B ≃ Σ (A → B) 3-Constant
preEquiv₂ t = e , rec (isPropIsEquiv e) e-isEquiv t
trunc→Gpd≃ : (∥ A ∥ → B) ≃ Σ (A → B) 3-Constant
trunc→Gpd≃ = compEquiv (equivΠCod preEquiv₂) preEquiv₁
open GpdElim using (rec→Gpd; trunc→Gpd≃) public
squashᵗ
: ∀(x y z : A)
→ Square (squash ∣ x ∣ ∣ y ∣) (squash ∣ x ∣ ∣ z ∣) refl (squash ∣ y ∣ ∣ z ∣)
squashᵗ x y z i = squash ∣ x ∣ (squash ∣ y ∣ ∣ z ∣ i)
elim→Gpd
: (P : ∥ A ∥ → Type ℓ)
→ (∀ t → isGroupoid (P t))
→ (f : (x : A) → P ∣ x ∣)
→ (kf : ∀ x y → PathP (λ i → P (squash ∣ x ∣ ∣ y ∣ i)) (f x) (f y))
→ (3kf : ∀ x y z
→ SquareP (λ i j → P (squashᵗ x y z i j)) (kf x y) (kf x z) refl (kf y z))
→ (t : ∥ A ∥) → P t
elim→Gpd {A = A} P Pgpd f kf 3kf t = rec→Gpd (Pgpd t) g 3kg t
where
g : A → P t
g x = transp (λ i → P (squash ∣ x ∣ t i)) i0 (f x)
open 3-Constant
3kg : 3-Constant g
3kg .link x y i
= transp (λ j → P (squash (squash ∣ x ∣ ∣ y ∣ i) t j)) i0 (kf x y i)
3kg .coh₁ x y z i j
= transp (λ k → P (squash (squashᵗ x y z i j) t k)) i0 (3kf x y z i j)
RecHSet : (P : A → TypeOfHLevel ℓ 2) → 3-Constant P → ∥ A ∥ → TypeOfHLevel ℓ 2
RecHSet P 3kP = rec→Gpd (isOfHLevelTypeOfHLevel 2) P 3kP
|
{
"alphanum_fraction": 0.5009099934,
"avg_line_length": 31.9788359788,
"ext": "agda",
"hexsha": "03aa341f6e05b1444481106d69c2dd334c6abd8a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/HITs/PropositionalTruncation/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/HITs/PropositionalTruncation/Properties.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/HITs/PropositionalTruncation/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5414,
"size": 12088
}
|
module OpBind where
postulate _∘_ : Set -> Set -> Set
Homomorphic₀ : Set → Set
Homomorphic₀ ∘ = ∘
|
{
"alphanum_fraction": 0.6504854369,
"avg_line_length": 10.3,
"ext": "agda",
"hexsha": "44788b7a768765d13717cc5bc86925d105597730",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/OpBind.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/OpBind.agda",
"max_line_length": 33,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/OpBind.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 35,
"size": 103
}
|
module _ where
open import Data.Nat using (ℕ ; _+_ ; _≤′_ ; suc)
open import Induction.Nat using (<′-rec)
open import Esterel.Lang.CanFunction
open import Function using (_∋_ ; _∘_ ; id ; _$_)
open import Data.Nat.Properties.Simple using ( +-comm ; +-assoc)
open import utility
open import noetherian using (noetherian ; ∥_∥s)
open import Esterel.Lang
open import Esterel.Lang.Properties
open import Esterel.Environment as Env
open import Esterel.Context
open import Data.Product
open import Data.Sum
open import Data.Bool
open import Data.List using ([] ; [_] ; _∷_ ; List ; _++_)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; sym ; subst ; cong ; trans ; module ≡-Reasoning ; cong₂ ; subst₂ ; inspect)
open import Data.Empty
open import sn-calculus
open import context-properties -- get view, E-views
open import Esterel.Lang.Binding
open import Data.Maybe using ( just )
-- open import coherence
open import Data.List.Any
open import Data.List.Any.Properties
open import Esterel.Lang.CanFunction.Base
open import eval
open import blocked
open import Data.List.All
open ≡-Reasoning using (_≡⟨_⟩_ ; _≡⟨⟩_ ; _∎)
open import Relation.Nullary.Decidable
using (⌊_⌋)
open import Data.FiniteMap
import Data.OrderedListMap as OMap
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import sn-calculus-compatconf using (1-step)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
open import binding-preserve
{- definition of two relations commuting
(wrt to Correct Binding) -}
CB-COMMUTE : (Term -> Term -> Set) ->
(Term -> Term -> Set) ->
Set
CB-COMMUTE R1 R2 =
∀ {p q r BV FV} ->
CorrectBinding p BV FV ->
R1 p q ->
R2 p r ->
∃ λ {z → (R2 q z × R1 r z)}
{- a relation that commutes with itself is confluent -}
CB-CONFLUENT : (Term -> Term -> Set) -> Set
CB-CONFLUENT R = CB-COMMUTE R R
sn⟶*-confluent : CB-CONFLUENT _sn⟶*_
sn⟶*-confluent {p} {q} {r} {BV} {FV} CB =
newman ∥ p ∥s p q r BV FV refl CB where
{-
Proof of Newman's lemma from:
_Confluent Reductions: Abstract Properties and Applications to Term
Rewriting Systems_ by Gérard Huet. Oct 1980; JACM volume 27 issue 4
https://dl.acm.org/citation.cfm?id=322230
-}
newmantype : ℕ -> Set
newmantype c = ∀ p q r BV FV ->
∥ p ∥s ≡ c ->
CorrectBinding p BV FV ->
p sn⟶* q ->
p sn⟶* r ->
Σ[ z ∈ Term ] (q sn⟶* z × r sn⟶* z)
step : ∀ (c : ℕ) ->
((c′ : ℕ) → suc c′ ≤′ c → newmantype c′)
-> (newmantype c)
step c rec x .x z BV FV nsx≡c CB rrefl s*xz = z , (s*xz , rrefl)
step c rec x y .x BV FV nsx≡c CB s*xy rrefl = y , (rrefl , s*xy)
step c rec x y z BV FV refl CB
(rstep {.x} {y1} {.y} sxy1 s*y1y)
(rstep {.x} {z1} {.z} sxz1 s*z1z)
with 1-step {x} {y1} {z1} {BV} {FV} CB sxy1 sxz1
... | (u , s*y1u , s*z1u) with sn⟶-maintains-binding CB sxy1
... | (BVy1 , FVy1) , (CBy1 , _) with sn⟶-maintains-binding CB sxz1
... | (BVz1 , FVz1) , (CBz1 , _) with rec ∥ y1 ∥s (noetherian{x}{y1} sxy1)
y1 y u BVy1 FVy1 refl CBy1 s*y1y s*y1u
... | (v , s*yv , s*uv) with rec ∥ z1 ∥s (noetherian{x}{z1} sxz1)
z1 v z BVz1 FVz1 refl CBz1 (sn⟶*+ s*z1u s*uv) s*z1z
... | (t , s*vt , s*zt) = t , (sn⟶*+ s*yv s*vt) , s*zt
newman : ∀ c -> newmantype c
newman = <′-rec _ step
lift-sn⟶* : ∀ {p q} → (P : Term → Set) → (∀ {p q} → P p → p sn⟶ q → P q) → P p → p sn⟶* q → P q
lift-sn⟶* P P-respects-sn⟶ Pp rrefl = Pp
lift-sn⟶* P P-respects-sn⟶ Pp (rstep psn⟶r rsn⟶*q) =
lift-sn⟶* P P-respects-sn⟶ (P-respects-sn⟶ Pp psn⟶r) rsn⟶*q
sn≡ₑ-preserve-cb : ∀{p q BV FV} → CorrectBinding p BV FV → p sn≡ₑ q → Σ (VarList × VarList) λ {(BVq , FVq) → CorrectBinding q BVq FVq}
sn≡ₑ-preserve-cb cb (rstp x) with sn⟶-maintains-binding cb x
... | (bv,fv , cbq , _)= _ , cbq
sn≡ₑ-preserve-cb cb (rsym psn≡ₑq x) = _ , x
sn≡ₑ-preserve-cb cb rref = _ , cb
sn≡ₑ-preserve-cb cb (rtrn psn≡ₑq psn≡ₑq₁) = sn≡ₑ-preserve-cb (proj₂ (sn≡ₑ-preserve-cb cb psn≡ₑq)) psn≡ₑq₁
sn≡ₑ-consistent : ∀{p q BV FV} → CorrectBinding p BV FV → p sn≡ₑ q → Σ[ r ∈ Term ] p sn⟶* r × q sn⟶* r
sn≡ₑ-consistent cb (rstp x) = _ , rstep x rrefl , rrefl
sn≡ₑ-consistent cb (rsym qsn≡ₑp cbq) with sn≡ₑ-consistent cbq qsn≡ₑp
... | (r , qsn⟶r , psn⟶r ) = (r , psn⟶r , qsn⟶r)
sn≡ₑ-consistent cb rref = _ , rrefl , rrefl
sn≡ₑ-consistent cb (rtrn psn≡ₑs ssn≡ₑq) with (sn≡ₑ-preserve-cb cb psn≡ₑs)
... | (_ , cbs) with sn≡ₑ-consistent cb psn≡ₑs | sn≡ₑ-consistent cbs ssn≡ₑq
... | (rl , psn⟶*rl , ssn⟶*rl) | (rr , ssn⟶*rr , qsn⟶*rr) with sn⟶*-confluent cbs ssn⟶*rl ssn⟶*rr
... | (r , rlsn⟶*r , rrsn⟶*r) = r , (sn⟶*+ psn⟶*rl rlsn⟶*r , sn⟶*+ qsn⟶*rr rrsn⟶*r )
irreducibility-of-complete-sn⟶₁ : ∀{p q} → complete p → p sn⟶₁ q → ⊥
irreducibility-of-complete-sn⟶₁ (codone p/done) psn⟶₁q = done-¬sn⟶₁ p/done psn⟶₁q
irreducibility-of-complete-sn⟶₁ (coenv {θ} (θcomplete x x₁) p/done) ρθpsn⟶₁ρθ'q
with ρ-stays-ρ-sn⟶₁ ρθpsn⟶₁ρθ'q
... | θ' , q , A' , refl with get-view ρθpsn⟶₁ρθ'q
irreducibility-of-complete-sn⟶₁ (coenv {θ} (θcomplete x x₁) p/done) ρθpsn⟶₁ρθ'q
| θ' , q , A' , refl | inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , e-view) =
⊥-elim
(done-E-view-term-disjoint
(done-⟦⟧e p/done p≐E⟦pin⟧)
(->E-view-inner-term e-view))
irreducibility-of-complete-sn⟶₁ (coenv {θ} (θcomplete x x₁) p/done) ρθpsn⟶₁ρθ'q
| θ' , q , A' , refl | inj₂ (refl , refl , vabsence S S∈ x₂ x₃)
with x S S∈
... | inj₁ S≡ = lookup-S-eq θ S S∈ S∈ S≡ x₂ (λ ())
... | inj₂ S≡ = lookup-S-eq θ S S∈ S∈ S≡ x₂ (λ ())
irreducibility-of-complete-sn⟶₁ (coenv {θ} (θcomplete x x₁) p/done) ρθpsn⟶₁ρθ'q
| θ' , q , A' , refl | inj₂ (refl , refl , vreadyness s s∈ x₂ x₃)
with x₁ s s∈
... | s≡ with x₂
... | inj₁ s2≡ = lookup-s-eq θ s s∈ s∈ s≡ s2≡ (λ ())
... | inj₂ s2≡ = lookup-s-eq θ s s∈ s∈ s≡ s2≡ (λ ())
inescapability-of-paused-sn⟶ : ∀ {p q} ->
paused p ->
p sn⟶ q ->
paused q
inescapability-of-paused-sn⟶ ppause (rcontext .[] dchole ())
inescapability-of-paused-sn⟶ (pseq ()) (rcontext .[] dchole rseq-done)
inescapability-of-paused-sn⟶ (pseq ()) (rcontext .[] dchole rseq-exit)
inescapability-of-paused-sn⟶ (pseq pausedp) (rcontext _ (dcseq₁ dc) psn⟶₁p')
= pseq (inescapability-of-paused-sn⟶ pausedp (rcontext _ dc psn⟶₁p'))
inescapability-of-paused-sn⟶ (pseq pausedp) (rcontext _ (dcseq₂ dc) psn⟶₁p')
= pseq pausedp
inescapability-of-paused-sn⟶ (ploopˢ ()) (rcontext .[] dchole rloopˢ-exit)
inescapability-of-paused-sn⟶ (ploopˢ pausedp) (rcontext _ (dcloopˢ₁ dc) psn⟶₁p')
= ploopˢ (inescapability-of-paused-sn⟶ pausedp (rcontext _ dc psn⟶₁p'))
inescapability-of-paused-sn⟶ (ploopˢ pausedp) (rcontext _ (dcloopˢ₂ dc) psn⟶₁p')
= ploopˢ pausedp
inescapability-of-paused-sn⟶ (ppar pausedp _) (rcontext .[] dchole (rpar-done-right p' q'))
= ⊥-elim (halted-paused-disjoint p' pausedp)
inescapability-of-paused-sn⟶ (ppar _ pausedq) (rcontext .[] dchole (rpar-done-left p' q'))
= ⊥-elim (halted-paused-disjoint q' pausedq)
inescapability-of-paused-sn⟶ (ppar pausedp pausedq) (rcontext _ (dcpar₁ dc) psn⟶₁p')
= ppar (inescapability-of-paused-sn⟶ pausedp (rcontext _ dc psn⟶₁p')) pausedq
inescapability-of-paused-sn⟶ (ppar pausedp pausedq) (rcontext _ (dcpar₂ dc) psn⟶₁p')
= ppar pausedp (inescapability-of-paused-sn⟶ pausedq (rcontext _ dc psn⟶₁p'))
inescapability-of-paused-sn⟶ (psuspend pausedp) (rcontext .[] dchole (rsuspend-done haltedp))
= ⊥-elim (halted-paused-disjoint haltedp pausedp)
inescapability-of-paused-sn⟶ (psuspend pausedp) (rcontext _ (dcsuspend dc) psn⟶₁p')
= psuspend (inescapability-of-paused-sn⟶ pausedp (rcontext _ dc psn⟶₁p'))
inescapability-of-paused-sn⟶ (ptrap ()) (rcontext .[] dchole (rtrap-done hnothin))
inescapability-of-paused-sn⟶ (ptrap ()) (rcontext .[] dchole (rtrap-done (hexit n)))
inescapability-of-paused-sn⟶ (ptrap pausedp) (rcontext _ (dctrap dc) psn⟶₁p')
= ptrap (inescapability-of-paused-sn⟶ pausedp (rcontext _ dc psn⟶₁p'))
inescapability-of-paused-sn⟶* : ∀ {p q} ->
paused p ->
p sn⟶* q ->
paused q
inescapability-of-paused-sn⟶* pausedp rrefl = pausedp
inescapability-of-paused-sn⟶* pausedp (rstep psn⟶r r⟶q)
= inescapability-of-paused-sn⟶* (inescapability-of-paused-sn⟶ pausedp psn⟶r) r⟶q
inescapability-of-complete-sn⟶ : ∀{p q} → complete p → p sn⟶ q → complete q
inescapability-of-complete-sn⟶ c@(codone p-done) psn⟶q = codone (done-sn⟶ p-done psn⟶q)
inescapability-of-complete-sn⟶ c@(coenv x x₁) (rcontext .[] dchole psn⟶₁p') = ⊥-elim (irreducibility-of-complete-sn⟶₁ c psn⟶₁p')
inescapability-of-complete-sn⟶ (coenv x (dhalted hnothin)) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p')
= ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dhalted hnothin)) psn⟶₁p')
inescapability-of-complete-sn⟶ (coenv x (dhalted (hexit n))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p')
= ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dhalted (hexit n))) psn⟶₁p')
inescapability-of-complete-sn⟶ (coenv x (dpaused p/paused)) (rcontext .(cenv _ _ ∷ _) (dcenv dc) psn⟶₁p')
with (inescapability-of-complete-sn⟶ (codone (dpaused p/paused)) (rcontext _ dc psn⟶₁p'))
inescapability-of-complete-sn⟶ (coenv x (dpaused ppause)) (rcontext .(cenv _ _ ∷ _) (dcenv dchole) psn⟶₁p') | rec
= ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused ppause)) psn⟶₁p')
inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ploopˢ p/paused))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') | rec
= ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused (ploopˢ p/paused))) psn⟶₁p')
inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ploopˢ p/paused))) (rcontext .(cenv _ _ ∷ ceval (eloopˢ _) ∷ _) (dcenv (dcloopˢ₁ dc)) psn⟶₁p') | codone x
= coenv x₁ x
inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ploopˢ p/paused))) (rcontext .(cenv _ _ ∷ cloopˢ₂ _ ∷ _) (dcenv (dcloopˢ₂ dc)) psn⟶₁p') | codone x
= coenv x₁ x
inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (pseq p/paused))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') | rec
= ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused (pseq p/paused))) psn⟶₁p')
inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (pseq p/paused))) (rcontext .(cenv _ _ ∷ ceval (eseq _) ∷ _) (dcenv (dcseq₁ dc)) psn⟶₁p') | codone x
= coenv x₁ x
inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (pseq p/paused))) (rcontext .(cenv _ _ ∷ cseq₂ _ ∷ _) (dcenv (dcseq₂ dc)) psn⟶₁p') | codone x
= coenv x₁ x
inescapability-of-complete-sn⟶ (coenv x (dpaused (ppar p/paused p/paused₁))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') | rec
= ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused (ppar p/paused p/paused₁))) psn⟶₁p')
inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ppar p/paused p/paused₁))) (rcontext .(cenv _ _ ∷ ceval (epar₁ _) ∷ _) (dcenv (dcpar₁ dc)) psn⟶₁p') | codone x
= coenv x₁ x
inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ppar p/paused p/paused₁))) (rcontext .(cenv _ _ ∷ ceval (epar₂ _) ∷ _) (dcenv (dcpar₂ dc)) psn⟶₁p') | codone x = coenv x₁ x
inescapability-of-complete-sn⟶ (coenv x (dpaused (psuspend p/paused))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') | rec
= ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused (psuspend p/paused))) psn⟶₁p')
inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (psuspend p/paused))) (rcontext .(cenv _ _ ∷ ceval (esuspend _) ∷ _) (dcenv (dcsuspend dc)) psn⟶₁p') | codone x = coenv x₁ x
inescapability-of-complete-sn⟶ (coenv x (dpaused (ptrap p/paused))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') | rec
= ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused (ptrap p/paused))) psn⟶₁p')
inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ptrap p/paused))) (rcontext .(cenv _ _ ∷ ceval etrap ∷ _) (dcenv (dctrap dc)) psn⟶₁p') | codone x = coenv x₁ x
inescapability-of-complete-sn : ∀{p q} → complete p → p sn⟶* q → complete q
inescapability-of-complete-sn = lift-sn⟶* complete inescapability-of-complete-sn⟶
equality-of-complete-sn⟶* : ∀{θ θ' p q A A'} →
complete (ρ⟨ θ , A ⟩· p) →
(ρ⟨ θ , A ⟩· p) sn⟶* (ρ⟨ θ' , A' ⟩· q) →
θ ≡ θ' × A ≡ A'
equality-of-complete-sn⟶* ρθp/complete rrefl = refl , refl
equality-of-complete-sn⟶* ρθp/complete (rstep (rcontext _ dchole ρθpsn⟶₁ρθ''r) ρθ''rsn⟶*ρθ'q)
with irreducibility-of-complete-sn⟶₁ ρθp/complete ρθpsn⟶₁ρθ''r
... | ()
equality-of-complete-sn⟶* ρθp/complete (rstep (rcontext _ (dcenv ρθp≐C⟦p'⟧) p'sn⟶₁r) ρθrsn⟶*ρθ'q) =
equality-of-complete-sn⟶*
(inescapability-of-complete-sn⟶ ρθp/complete (rcontext _ (dcenv ρθp≐C⟦p'⟧) p'sn⟶₁r))
ρθrsn⟶*ρθ'q
get-view/blocked : ∀{θ θ' p q A A'} →
blocked θ A p →
(ρθpsn⟶₁ρθ'q : ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θ' , A' ⟩· q) →
∃ (λ a → ∃ (->pot-view ρθpsn⟶₁ρθ'q a))
get-view/blocked p/blocked ρθpsn⟶₁ρθ'q with get-view ρθpsn⟶₁ρθ'q
... | inj₂ refl-pot-view = refl-pot-view
... | inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , e-view)
with blocked-⟦⟧e p/blocked p≐E⟦pin⟧ | ->E-view-inner-term e-view
... | inj₂ pin/done | e-view-term =
⊥-elim
(done-E-view-term-disjoint
pin/done
(->E-view-inner-term e-view))
... | (inj₁ (bpar-both pin'/blocked qin'/blocked)) | ()
... | (inj₁ (bpar-left pin'/blocked qin'/done)) | ()
... | (inj₁ (bpar-right pin'/done qin'/blocked)) | ()
... | (inj₁ (bloopˢ pin/blocked)) | ()
... | (inj₁ (bseq pin/blocked)) | ()
... | (inj₁ (bsusp pin/blocked)) | ()
... | (inj₁ (btrap pin/blocked)) | ()
get-view/blocked {θ} p/blocked (ris-present S∈' θS≡present .p≐E⟦pin⟧)
| inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vis-present)
| (inj₁ (bsig-exists S S∈ θS≡unknown)) | evt-present
with trans (sym θS≡present) (trans (Env.sig-stats-∈-irr {S} {θ} S∈' S∈) θS≡unknown)
... | ()
get-view/blocked {θ} p/blocked (ris-absent S∈' θS≡absent .p≐E⟦pin⟧)
| inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vis-absent)
| (inj₁ (bsig-exists S S∈ θS≡unknown)) | evt-present
with trans (sym θS≡absent) (trans (Env.sig-stats-∈-irr {S} {θ} S∈' S∈) θS≡unknown)
... | ()
get-view/blocked p/blocked (rraise-shared {s = s} e' .p≐E⟦pin⟧)
| inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vraise-shared)
| (inj₁ (bshared e/blocked)) | evt-raise-shared =
⊥-elim (all-ready-blocked-disjoint (e' , e/blocked))
get-view/blocked p/blocked (rset-shared-value-old {s = s} e' s∈ θs≡old .p≐E⟦pin⟧)
| inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vset-shared-value-old)
| (inj₁ (bsset e/blocked)) | evt-set-shared =
⊥-elim (all-ready-blocked-disjoint (e' , e/blocked))
get-view/blocked p/blocked (rset-shared-value-new {s = s} e' s∈ θs≡new .p≐E⟦pin⟧)
| inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vset-shared-value-new)
| (inj₁ (bsset e/blocked)) | evt-set-shared =
⊥-elim (all-ready-blocked-disjoint (e' , e/blocked))
get-view/blocked p/blocked (rraise-var {x = x} e' .p≐E⟦pin⟧)
| inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vraise-var)
| (inj₁ (bvar e/blocked)) | evt-raise-var =
⊥-elim (all-ready-blocked-disjoint (e' , e/blocked))
get-view/blocked p/blocked (rset-var {x = x} x∈ e' .p≐E⟦pin⟧)
| inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vset-var)
| (inj₁ (bxset e/blocked)) | evt-set-var =
⊥-elim (all-ready-blocked-disjoint (e' , e/blocked))
get-view/blocked {A = .WAIT} p/blocked ρθpsn⟶₁ρθ'q | inj₁ (E , s ⇐ e , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , ())
| inj₁ bwset | evt-set-shared
get-view/blocked {A = .WAIT} p/blocked ρθpsn⟶₁ρθ'q | inj₁ (E , emit S , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , ())
| inj₁ bwemit | evt-emit
irreducibility-of-blocked-sn⟶₁ : ∀ {θ p q A} → blocked θ A p → p sn⟶₁ q → ⊥
irreducibility-of-blocked-sn⟶₁ (bsig-exists S S∈ θS≡unknown) ()
irreducibility-of-blocked-sn⟶₁ (bshared e/blocked) ()
irreducibility-of-blocked-sn⟶₁ (bsset e/blocked) ()
irreducibility-of-blocked-sn⟶₁ (bvar e/blocked) ()
irreducibility-of-blocked-sn⟶₁ (bxset e/blocked) ()
irreducibility-of-blocked-sn⟶₁ {p = s ⇐ e} {A = WAIT} bwset ()
irreducibility-of-blocked-sn⟶₁ {p = emit S} {A = WAIT} bwemit ()
irreducibility-of-blocked-sn⟶₁ (bpar-both p/blocked q/blocked)
(rpar-done-right p/halted q/done) =
halted-blocked-disjoint p/halted p/blocked
irreducibility-of-blocked-sn⟶₁ (bpar-left p/blocked q/done)
(rpar-done-right p/halted q/done') =
halted-blocked-disjoint p/halted p/blocked
irreducibility-of-blocked-sn⟶₁ (bpar-right p/done q/blocked)
(rpar-done-right p/halted q/done) =
done-blocked-disjoint q/done q/blocked
irreducibility-of-blocked-sn⟶₁ (bpar-both p/blocked q/blocked)
(rpar-done-left p/done q/halted) =
halted-blocked-disjoint q/halted q/blocked
irreducibility-of-blocked-sn⟶₁ (bpar-left p/blocked q/done)
(rpar-done-left p/done q/halted) =
done-blocked-disjoint p/done p/blocked
irreducibility-of-blocked-sn⟶₁ (bpar-right p/done q/blocked)
(rpar-done-left p/done' q/halted) =
halted-blocked-disjoint q/halted q/blocked
irreducibility-of-blocked-sn⟶₁ (bseq ())
rseq-done
irreducibility-of-blocked-sn⟶₁ (bseq ())
rseq-exit
irreducibility-of-blocked-sn⟶₁ (bloopˢ ())
rloopˢ-exit
irreducibility-of-blocked-sn⟶₁ (bsusp p/blocked)
(rsuspend-done p/halted) =
halted-blocked-disjoint p/halted p/blocked
irreducibility-of-blocked-sn⟶₁ (btrap p/blocked)
(rtrap-done p/halted) =
halted-blocked-disjoint p/halted p/blocked
irreducibility-of-halted-sn⟶ : ∀ {p q} ->
halted p ->
p sn⟶ q ->
⊥
irreducibility-of-halted-sn⟶ hnothin (rcontext [] dchole ())
irreducibility-of-halted-sn⟶ (hexit n) (rcontext [] dchole ())
-- not sure if it's worthwhile for now to also prove this for ρ θ · p sn⟶₁ ρ θ' · p
inescapability-of-blocked-inside-sn⟶ : ∀{θ p q A} →
blocked θ A p →
p sn⟶ q →
blocked θ A q
inescapability-of-blocked-inside-sn⟶ p/blocked (rcontext _ dchole psn⟶₁p') =
⊥-elim (irreducibility-of-blocked-sn⟶₁ p/blocked psn⟶₁p')
inescapability-of-blocked-inside-sn⟶ (bpar-both p/blocked q/blocked)
(rcontext _ (dcpar₁ p≐C⟦pin⟧) pinsn⟶₁pin') =
bpar-both
(inescapability-of-blocked-inside-sn⟶ p/blocked
(rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin'))
q/blocked
inescapability-of-blocked-inside-sn⟶ (bpar-both p/blocked q/blocked)
(rcontext _ (dcpar₂ p≐C⟦pin⟧) pinsn⟶₁pin') =
bpar-both p/blocked
(inescapability-of-blocked-inside-sn⟶ q/blocked
(rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin'))
inescapability-of-blocked-inside-sn⟶ (bpar-left p/blocked q/done)
(rcontext _ (dcpar₁ p≐C⟦pin⟧) pinsn⟶₁pin') =
bpar-left
(inescapability-of-blocked-inside-sn⟶ p/blocked
(rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin'))
q/done
inescapability-of-blocked-inside-sn⟶ (bpar-left p/blocked q/done)
(rcontext _ (dcpar₂ p≐C⟦pin⟧) pinsn⟶₁pin') =
bpar-left p/blocked
(done-sn⟶ q/done (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin'))
inescapability-of-blocked-inside-sn⟶ (bpar-right p/done q/blocked)
(rcontext _ (dcpar₁ p≐C⟦pin⟧) pinsn⟶₁pin') =
bpar-right (done-sn⟶ p/done (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin'))
q/blocked
inescapability-of-blocked-inside-sn⟶ (bpar-right p/done q/blocked)
(rcontext _ (dcpar₂ p≐C⟦pin⟧) pinsn⟶₁pin') =
bpar-right p/done
(inescapability-of-blocked-inside-sn⟶ q/blocked
(rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin'))
inescapability-of-blocked-inside-sn⟶ (bseq p/blocked)
(rcontext _ (dcseq₁ p≐C⟦pin⟧) pinsn⟶₁pin') =
bseq
(inescapability-of-blocked-inside-sn⟶ p/blocked
(rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin'))
inescapability-of-blocked-inside-sn⟶ (bseq p/blocked)
(rcontext _ (dcseq₂ p≐C⟦pin⟧) pinsn⟶₁pin') =
bseq p/blocked
inescapability-of-blocked-inside-sn⟶ (bloopˢ p/blocked)
(rcontext _ (dcloopˢ₁ p≐C⟦pin⟧) pinsn⟶₁pin') =
bloopˢ
(inescapability-of-blocked-inside-sn⟶ p/blocked
(rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin'))
inescapability-of-blocked-inside-sn⟶ (bloopˢ p/blocked)
(rcontext _ (dcloopˢ₂ p≐C⟦pin⟧) pinsn⟶₁pin') =
bloopˢ p/blocked
inescapability-of-blocked-inside-sn⟶ (bsusp p/blocked)
(rcontext _ (dcsuspend p≐C⟦pin⟧) pinsn⟶₁pin') =
bsusp
(inescapability-of-blocked-inside-sn⟶ p/blocked
(rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin'))
inescapability-of-blocked-inside-sn⟶ (btrap p/blocked)
(rcontext _ (dctrap p≐C⟦pin⟧) pinsn⟶₁pin') =
btrap
(inescapability-of-blocked-inside-sn⟶ p/blocked
(rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin'))
inescapability-of-blocked-inside-sn⟶ (bshared e/blocked)
(rcontext _ (dcshared p≐C⟦pin⟧) pinsn⟶₁pin') =
bshared e/blocked
inescapability-of-blocked-inside-sn⟶ (bvar e/blocked)
(rcontext _ (dcvar p≐C⟦pin⟧) pinsn⟶₁pin') =
bvar e/blocked
inescapability-of-blocked-inside-sn⟶ {θ} {A = A}(bsig-exists S S∈ θS≡unknown)
(rcontext _ S?p:q≐C⟦pin⟧ pinsn⟶₁pin') with S?p:q≐C⟦pin⟧
-- we still have the dchole case here since Agda can't determine that it cannot happen
... | dchole = ⊥-elim (irreducibility-of-blocked-sn⟶₁ {A = A} (bsig-exists {θ} S S∈ θS≡unknown) pinsn⟶₁pin')
... | dcpresent₁ p≐C⟦pin⟧ = bsig-exists S S∈ θS≡unknown
... | dcpresent₂ p≐C⟦pin⟧ = bsig-exists S S∈ θS≡unknown
|
{
"alphanum_fraction": 0.6536270772,
"avg_line_length": 48.9470046083,
"ext": "agda",
"hexsha": "df7ca02b72d1fb42d3a3ead26768e0a70fe782f1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/sn-calculus-props.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/sn-calculus-props.agda",
"max_line_length": 174,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/sn-calculus-props.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 8988,
"size": 21243
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import groups.ProductRepr
open import cohomology.Theory
open import homotopy.WedgeCofiber
{- For the cohomology group of a suspension ΣX, the group inverse has the
- explicit form Cⁿ(flip-susp) : Cⁿ(ΣX) → Cⁿ(ΣX).
-}
module cohomology.InverseInSusp {i} (CT : CohomologyTheory i)
(n : ℤ) {X : Ptd i} where
open CohomologyTheory CT
open import cohomology.Wedge CT n
private
module Subtract = SuspRec {C = de⊙ (⊙Susp X ⊙∨ ⊙Susp X)}
(winl south)
(winr south)
(λ x → ap winl (! (merid x)) ∙ wglue ∙ ap winr (merid x))
subtract = Subtract.f
⊙subtract : ⊙Susp X ⊙→ ⊙Susp X ⊙∨ ⊙Susp X
⊙subtract = (subtract , ! (ap winl (merid (pt X))))
projl-subtract : ∀ σ → projl (subtract σ) == Susp-flip σ
projl-subtract = Susp-elim idp idp $
↓-='-from-square ∘ vert-degen-square ∘ λ x →
ap-∘ projl subtract (merid x)
∙ ap (ap projl) (Subtract.merid-β x)
∙ ap-∙ projl (ap winl (! (merid x))) (wglue ∙ ap winr (merid x))
∙ ((∘-ap projl winl (! (merid x))
∙ ap-idf _)
∙2 (ap-∙ projl wglue (ap winr (merid x))
∙ (Projl.glue-β
∙2 (∘-ap projl winr (merid x) ∙ ap-cst _ _))))
∙ ∙-unit-r _
∙ ! (SuspFlip.merid-β x)
projr-subtract : ∀ σ → projr (subtract σ) == σ
projr-subtract = Susp-elim idp idp $
↓-∘=idf-in' projr subtract ∘ λ x →
ap (ap projr) (Subtract.merid-β x)
∙ ap-∙ projr (ap winl (! (merid x))) (wglue ∙ ap winr (merid x))
∙ ((∘-ap projr winl (! (merid x)) ∙ ap-cst _ _)
∙2 (ap-∙ projr wglue (ap winr (merid x))
∙ (Projr.glue-β
∙2 (∘-ap projr winr (merid x) ∙ ap-idf _))))
fold-subtract : ∀ σ → fold (subtract σ) == south
fold-subtract = Susp-elim idp idp $
↓-app=cst-in ∘ ! ∘ λ x →
∙-unit-r _
∙ ap-∘ fold subtract (merid x)
∙ ap (ap fold) (Subtract.merid-β x)
∙ ap-∙ fold (ap winl (! (merid x))) (wglue ∙ ap winr (merid x))
∙ ((∘-ap fold winl (! (merid x)) ∙ ap-idf _)
∙2 (ap-∙ fold wglue (ap winr (merid x))
∙ (Fold.glue-β
∙2 (∘-ap fold winr (merid x) ∙ ap-idf _))))
∙ !-inv-l (merid x)
abstract
cancel : ∀ x
→ GroupHom.f (×ᴳ-fanin (C-is-abelian n _) (C-fmap n (⊙Susp-flip X)) (idhom _)) (x , x)
== Cident n (⊙Susp X)
cancel x =
ap2 (Group.comp (C n (⊙Susp X)))
(! (CEl-fmap-base-indep n projl-subtract x))
(! (CEl-fmap-idf n x) ∙ ! (CEl-fmap-base-indep n projr-subtract x))
∙ (C-Wedge-in-comm-sqr' (⊙Susp X) (⊙Susp X) ⊙subtract □$ᴳ (x , x))
∙ ap (CEl-fmap n ⊙subtract)
( ap (GroupIso.g (C-Wedge (⊙Susp X) (⊙Susp X)) ∘ diag) (! (CEl-fmap-idf n x))
∙ (C-Wedge-rec-comm-sqr' (⊙Susp X) (⊙Susp X) (⊙idf _) (⊙idf _) □$ᴳ x))
∙ ∘-CEl-fmap n ⊙subtract ⊙fold x
∙ CEl-fmap-base-indep n (λ σ → fold-subtract σ ∙ ! (merid (pt X))) x
∙ CEl-fmap-cst n x
abstract
C-Susp-flip-is-inv : ∀ x → CEl-fmap n (⊙Susp-flip X) x == Group.inv (C n (⊙Susp X)) x
C-Susp-flip-is-inv x = ! (Group.inv-unique-l (C n (⊙Susp X)) _ x (cancel x))
|
{
"alphanum_fraction": 0.5419190309,
"avg_line_length": 36.9058823529,
"ext": "agda",
"hexsha": "03167be9218af16266d35623bb626ad36ff5c0c1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/cohomology/InverseInSusp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/cohomology/InverseInSusp.agda",
"max_line_length": 92,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/cohomology/InverseInSusp.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1298,
"size": 3137
}
|
------------------------------------------------------------------------
-- A type for values that should be erased at run-time
------------------------------------------------------------------------
-- This module reexports definitions that do not depend on an
-- implementation of []-cong.
{-# OPTIONS --without-K --safe #-}
open import Equality
module Erased.Without-box-cong
{c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) where
-- Re-exported definitions.
open import Erased.Level-1 eq public
hiding (module Erased-cong;
module []-cong;
module []-cong₁;
module []-cong₂; module []-cong₂-⊔;
module Extensionality)
open import Erased.Stability eq public
hiding (module []-cong;
module []-cong₁; module []-cong₁-lsuc;
module []-cong₂; module []-cong₂-⊔₁; module []-cong₂-⊔₂;
module Extensionality)
|
{
"alphanum_fraction": 0.5284090909,
"avg_line_length": 31.4285714286,
"ext": "agda",
"hexsha": "b3d12ebf6cd62fb41e83fc5b6438ab01c67b60fd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Erased/Without-box-cong.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Erased/Without-box-cong.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Erased/Without-box-cong.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 222,
"size": 880
}
|
module Dave.Functions where
_∘_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C)
(g ∘ f) a = g (f a)
_∘´_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C)
(g ∘´ f) = λ x → g (f x)
|
{
"alphanum_fraction": 0.3333333333,
"avg_line_length": 27.8571428571,
"ext": "agda",
"hexsha": "3602f36bd9956ea82855be8b2193d01319f4f555",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DavidStahl97/formal-proofs",
"max_forks_repo_path": "Dave/Functions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DavidStahl97/formal-proofs",
"max_issues_repo_path": "Dave/Functions.agda",
"max_line_length": 56,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DavidStahl97/formal-proofs",
"max_stars_repo_path": "Dave/Functions.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 102,
"size": 195
}
|
{-# OPTIONS --no-positivity-check
#-}
{-
Data, Deliberately
Conor McBride
Workshop in Dependently Typed Programming
Nottingham, 2008
(Agda rendering by Ulf Norell)
-}
module Talk where
open import SomeBasicStuff
-- Codes for (first order) inductive families.
data Code (I : Set) : Set1 where
arg : (A : Set) -> (A -> Code I) -> Code I
rec : I -> Code I -> Code I
out : I -> Code I
-- The semantics of a code is a functor.
⟦_⟧ : {I : Set} -> Code I -> (I -> Set) -> I -> Set
⟦ out i ⟧ X j = i == j
⟦ arg A B ⟧ X j = Σ A \a -> ⟦ B a ⟧ X j
⟦ rec i C ⟧ X j = X i × ⟦ C ⟧ X j
map : {I : Set}{X Y : I -> Set}(C : Code I) ->
({i : I} -> X i -> Y i) ->
{i : I} -> ⟦ C ⟧ X i -> ⟦ C ⟧ Y i
map (out i) f x = x
map (arg A B) f (a , b) = a , map (B a) f b
map (rec i C) f (a , b) = f a , map C f b
-- Tying the recursive knot. The positivity checker won't spot that
-- ⟦ C ⟧ X i is strictly positive i X, so we've switched it off.
data μ {I : Set}(C : Code I) : I -> Set where
<_> : forall {i} -> ⟦ C ⟧ (μ C) i -> μ C i
-- Who needs a primitive case-construct anyway?
case_of_ : {A : Set1}{ts : Enumeration} -> Enum ts -> Table A ts -> A
case t of tbl = lookup tbl t
-- The code for lists
`List` : Set -> Code True
`List` X = arg _ \t ->
case t of
"nil" ↦ out _
∣ "cons" ↦ arg X (\_ -> rec _ (out _))
∣ []
-- The actual list type
List : Set -> Set
List A = μ (`List` A) _
-- We can define the code for vectors directly. However, the point is
-- that we won't have to.
`VecD` : Set -> Code Nat
`VecD` X = arg _ \t ->
case t of
"nil" ↦ out zero
∣ "cons" ↦ ( arg Nat \n ->
arg X \_ ->
rec n (out (suc n))
)
∣ []
-- An ornamentation of a datatype adds some new indexing.
data Orn {I : Set}(J : I -> Set) : Code I -> Set1 where
arg : forall {A B} -> ((a : A) -> Orn J (B a)) -> Orn J (arg A B)
rec : forall {i C} -> J i -> Orn J C -> Orn J (rec i C)
out : forall {i} -> J i -> Orn J (out i)
new : forall {C} -> (A : Set) -> (A -> Orn J C) -> Orn J C
-- An ornamented datatype is indexed by pairs of the old and the new index.
orn : {I : Set}{J : I -> Set}{C : Code I} -> Orn J C -> Code (Σ I J)
orn (out j) = out (_ , j)
orn (arg B) = arg _ \a -> orn (B a)
orn (new A B) = arg A \a -> orn (B a)
orn (rec j C) = rec (_ , j) (orn C)
-- We can forget the ornamentation and recover an element of the original type.
forget' : {I : Set}{J : I -> Set}{C : Code I}{i : I}{j : J i}
{X : Σ I J -> Set}{Y : I -> Set} ->
({i : I}{j : J i} -> X (i , j) -> Y i) ->
(ΔC : Orn J C) -> ⟦ orn ΔC ⟧ X (i , j) -> ⟦ C ⟧ Y i
forget' φ (out j) refl = refl
forget' φ (arg B) (a , b) = a , forget' φ (B a) b
forget' φ (new A B) (a , b) = forget' φ (B a) b
forget' φ (rec j C) (a , b) = φ a , forget' φ C b
-- The termination checker runs into the same problem as the positivity
-- checker--it can't tell that forget' φ C x is only applying φ to
-- things smaller than x.
forget : {I : Set}{J : I -> Set}{C : Code I}{i : I}{j : J i}
(ΔC : Orn J C) -> μ (orn ΔC) (i , j) -> μ C i
forget ΔC < x > = < forget' (forget ΔC) ΔC x >
-- A C-algebra over X takes us from ⟦ C ⟧ X i to X i.
Alg : {I : Set} -> Code I -> (I -> Set) -> Set
Alg C X = forall i -> ⟦ C ⟧ X i -> X i
-- We can fold by an algebra.
fold : {I : Set}{X : I -> Set}{C : Code I} ->
Alg C X -> {i : I} -> μ C i -> X i
fold {C = C} φ < x > = φ _ (map C (fold φ) x)
-- A type can be ornamented an arbitrary algebra over its functor.
decorate : {I : Set}{X : I -> Set}(C : Code I)
(φ : Alg C X) -> Orn X C
decorate (out i) φ = out (φ i refl)
decorate (arg A B) φ = arg \a -> decorate (B a) (\i b -> φ i (a , b))
decorate {X = X} (rec i C) φ = new (X i) \x -> rec x (decorate C \i b -> φ i (x , b))
-- Main theorem: If you have an element in a type decorated by φ, you
-- can recover forgotten decorations by folding with φ. Specialised to
-- lists and vectors we get
-- ∀ xs : Vec A n. length (forget xs) == n.
-- Two-level definition as usual.
thm' : {I : Set}{X J : I -> Set}{Y : Σ I J -> Set}
(C : Code I){i : I}{j : J i}(φ : Alg C J)
(F : {i : I} -> X i -> J i)
(ψ : {i : I}{j : J i} -> Y (i , j) -> X i) ->
({i : I}{j : J i}(z : Y (i , j)) -> F (ψ z) == j) ->
let ΔC = decorate C φ in
(x : ⟦ orn ΔC ⟧ Y (i , j)) ->
φ i (map C F (forget' ψ ΔC x)) == j
thm' (out i) φ F ψ ih refl = refl
thm' (arg A B) φ F ψ ih (a , b) = thm' (B a) (\i b -> φ i (a , b)) F ψ ih b
thm' (rec i C) {i = i0}{j = j0} φ F ψ ih (j , x , c)
with F (ψ x) | ih x | thm' C (\i b -> φ i (j , b)) F ψ ih c
... | .j | refl | rest = rest
thm : {I : Set}{J : I -> Set}(C : Code I){i : I}{j : J i}(φ : Alg C J) ->
(x : μ (orn (decorate C φ)) (i , j)) ->
fold φ (forget (decorate C φ) x) == j
thm C φ < x > = thm' C φ (fold φ) (forget (decorate C φ)) (thm C φ) x
-- Vectors as decorated lists.
lengthAlg : {A : Set} -> Alg (`List` A) (\_ -> Nat)
lengthAlg _ (enum ."nil" zero , _) = zero
lengthAlg _ (enum ."cons" (suc zero) , x , n , _) = suc n
lengthAlg _ (enum _ (suc (suc ())) , _)
length : {A : Set} -> List A -> Nat
length = fold lengthAlg
-- Now vectors are really lists decorated by their length.
`Vec` : (A : Set) -> Orn (\_ -> Nat) (`List` A)
`Vec` A = decorate (`List` A) lengthAlg
Vec : Set -> Nat -> Set
Vec A n = μ (orn (`Vec` A)) (_ , n)
nil : {A : Set} -> Vec A zero
nil = < enum "nil" zero , refl >
cons : {A : Set}{n : Nat} -> A -> Vec A n -> Vec A (suc n)
cons {n = n} x xs = < enum "cons" (suc zero) , x , n , xs , refl >
-- The proof that the index of the vector is really the length follows directly
-- from our main theorem.
corollary : {A : Set}{n : Nat}(xs : Vec A n) ->
length (forget (`Vec` _) xs) == n
corollary = thm (`List` _) lengthAlg
|
{
"alphanum_fraction": 0.5005011694,
"avg_line_length": 35.2117647059,
"ext": "agda",
"hexsha": "dfa47df508347623f043c85e164179fa4cc5b51b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/DTP08/conor/Talk.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/DTP08/conor/Talk.agda",
"max_line_length": 85,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/DTP08/conor/Talk.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 2220,
"size": 5986
}
|
------------------------------------------------------------------------
-- An implementation of the Thue-Morse sequence
------------------------------------------------------------------------
-- The paper "Productivity of stream definitions" by Endrullis et al.
-- (TCS 2010) uses a certain definition of the Thue-Morse sequence as
-- a running example.
-- Note that the code below makes use of the fact that Agda's
-- termination checker allows "swapping of arguments", which was not
-- mentioned when the termination checker was described in the paper
-- "Beating the Productivity Checker Using Embedded Languages".
-- However, it is easy to rewrite the code into a form which does not
-- make use of swapping, at the cost of some code duplication.
module ThueMorse where
open import Codata.Musical.Notation
open import Codata.Musical.Stream as S using (Stream; _≈_)
open S.Stream; open S._≈_
open import Data.Bool using (Bool; not); open Data.Bool.Bool
open import Function
open import Relation.Binary
import Relation.Binary.PropositionalEquality as P
import Relation.Binary.Reasoning.Setoid as EqReasoning
private
module SS {A : Set} = Setoid (S.setoid A)
open module SR {A : Set} = EqReasoning (S.setoid A)
using (begin_; _∎)
------------------------------------------------------------------------
-- Chunks
-- A value of type Chunks describes how a stream is generated. Note
-- that an infinite sequence of empty chunks is not allowed.
data Chunks : Set where
-- Start the next chunk.
next : (m : Chunks) → Chunks
-- Cons an element to the current chunk.
cons : (m : ∞ Chunks) → Chunks
-- Equality of chunks.
infix 4 _≈C_
data _≈C_ : Chunks → Chunks → Set where
next : ∀ {m m′} (m≈m′ : m ≈C m′ ) → next m ≈C next m′
cons : ∀ {m m′} (m≈m′ : ∞ (♭ m ≈C ♭ m′)) → cons m ≈C cons m′
------------------------------------------------------------------------
-- Chunk transformers
tailC : Chunks → Chunks
tailC (next m) = next (tailC m)
tailC (cons m) = ♭ m
mutual
evensC : Chunks → Chunks
evensC (next m) = next (evensC m)
evensC (cons m) = cons (♯ oddsC (♭ m))
oddsC : Chunks → Chunks
oddsC (next m) = next (oddsC m)
oddsC (cons m) = evensC (♭ m)
infixr 5 _⋎C_
-- Note that care is taken to create as few and large chunks as
-- possible (see also _⋎W_).
_⋎C_ : Chunks → Chunks → Chunks
next m ⋎C next m′ = next (m ⋎C m′) -- Two chunks in, one out.
next m ⋎C cons m′ = next (m ⋎C cons m′)
cons m ⋎C m′ = cons (♯ (m′ ⋎C ♭ m))
------------------------------------------------------------------------
-- Stream programs
-- StreamP m A encodes programs which generate streams with chunk
-- sizes given by m.
infixr 5 _∷_ _⋎_
data StreamP : Chunks → Set → Set₁ where
[_] : ∀ {m A} (xs : ∞ (StreamP m A)) → StreamP (next m) A
_∷_ : ∀ {m A} (x : A) (xs : StreamP (♭ m) A) → StreamP (cons m) A
tail : ∀ {m A} (xs : StreamP m A) → StreamP (tailC m) A
evens : ∀ {m A} (xs : StreamP m A) → StreamP (evensC m) A
odds : ∀ {m A} (xs : StreamP m A) → StreamP (oddsC m) A
_⋎_ : ∀ {m m′ A} (xs : StreamP m A) (ys : StreamP m′ A) →
StreamP (m ⋎C m′) A
map : ∀ {m A B} (f : A → B) (xs : StreamP m A) → StreamP m B
cast : ∀ {m m′ A} (ok : m ≈C m′) (xs : StreamP m A) → StreamP m′ A
data StreamW : Chunks → Set → Set₁ where
[_] : ∀ {m A} (xs : StreamP m A) → StreamW (next m) A
_∷_ : ∀ {m A} (x : A) (xs : StreamW (♭ m) A) → StreamW (cons m) A
program : ∀ {m A} → StreamW m A → StreamP m A
program [ xs ] = [ ♯ xs ]
program (x ∷ xs) = x ∷ program xs
tailW : ∀ {m A} → StreamW m A → StreamW (tailC m) A
tailW [ xs ] = [ tail xs ]
tailW (x ∷ xs) = xs
mutual
evensW : ∀ {m A} → StreamW m A → StreamW (evensC m) A
evensW [ xs ] = [ evens xs ]
evensW (x ∷ xs) = x ∷ oddsW xs
oddsW : ∀ {m A} → StreamW m A → StreamW (oddsC m) A
oddsW [ xs ] = [ odds xs ]
oddsW (x ∷ xs) = evensW xs
infixr 5 _⋎W_
-- Note: Uses swapping of arguments.
_⋎W_ : ∀ {m m′ A} → StreamW m A → StreamW m′ A → StreamW (m ⋎C m′) A
[ xs ] ⋎W [ ys ] = [ xs ⋎ ys ]
[ xs ] ⋎W (y ∷ ys) = [ xs ⋎ program (y ∷ ys) ]
(x ∷ xs) ⋎W ys = x ∷ ys ⋎W xs
mapW : ∀ {m A B} → (A → B) → StreamW m A → StreamW m B
mapW f [ xs ] = [ map f xs ]
mapW f (x ∷ xs) = f x ∷ mapW f xs
castW : ∀ {m m′ A} → m ≈C m′ → StreamW m A → StreamW m′ A
castW (next m≈m′) [ xs ] = [ cast m≈m′ xs ]
castW (cons m≈m′) (x ∷ xs) = x ∷ castW (♭ m≈m′) xs
whnf : ∀ {m A} → StreamP m A → StreamW m A
whnf [ xs ] = [ ♭ xs ]
whnf (x ∷ xs) = x ∷ whnf xs
whnf (tail xs) = tailW (whnf xs)
whnf (evens xs) = evensW (whnf xs)
whnf (odds xs) = oddsW (whnf xs)
whnf (xs ⋎ ys) = whnf xs ⋎W whnf ys
whnf (map f xs) = mapW f (whnf xs)
whnf (cast m≈m′ xs) = castW m≈m′ (whnf xs)
mutual
⟦_⟧W : ∀ {m A} → StreamW m A → Stream A
⟦ [ xs ] ⟧W = ⟦ xs ⟧P
⟦ x ∷ xs ⟧W = x ∷ ♯ ⟦ xs ⟧W
⟦_⟧P : ∀ {m A} → StreamP m A → Stream A
⟦ xs ⟧P = ⟦ whnf xs ⟧W
------------------------------------------------------------------------
-- The Thue-Morse sequence
[ccn]ω : Chunks
[ccn]ω = cons (♯ cons (♯ next [ccn]ω))
[cn]²[ccn]ω : Chunks
[cn]²[ccn]ω = cons (♯ next (cons (♯ next [ccn]ω)))
[cn]³[ccn]ω : Chunks
[cn]³[ccn]ω = cons (♯ next [cn]²[ccn]ω)
-- Explanation of the proof of lemma₁:
--
-- odds [ccn]ω ≈ [cn]ω
--
-- [cn]ω ⋎ [ccn]ω ≈
-- c ([ccn]ω ⋎ n[cn]ω) ≈
-- c c (n[cn]ω ⋎ cn[ccn]ω) ≈
-- c c n ([cn]ω ⋎ cn[ccn]ω) ≈
-- c c n c (cn[ccn]ω ⋎ n[cn]ω) ≈
-- c c n c c (n[cn]ω ⋎ n[ccn]ω) ≈
-- c c n c c n ([cn]ω ⋎ [ccn]ω)
lemma₁ : oddsC [ccn]ω ⋎C [ccn]ω ≈C [ccn]ω
lemma₁ = cons (♯ cons (♯ next (cons (♯ cons (♯ next lemma₁)))))
-- Explanation of the proof of lemma:
--
-- evens [cn]³[ccn]ω ≈ cnn[cn]ω
-- tail [cn]³[ccn]ω ≈ n[cn]²[ccn]ω
--
-- cnn[cn]ω ⋎ n[cn]²[ccn]ω ≈
-- c (n[cn]²[ccn]ω ⋎ nn[cn]ω) ≈
-- c n ([cn]²[ccn]ω ⋎ n[cn]ω) ≈
-- c n c (n[cn]ω ⋎ ncn[ccn]ω) ≈
-- c n c n ([cn]ω ⋎ cn[ccn]ω) ≈
-- c n c n c (cn[ccn]ω ⋎ n[cn]ω) ≈
-- c n c n c c (n[cn]ω ⋎ n[ccn]ω) ≈
-- c n c n c c n ([cn]ω ⋎ [ccn]ω)
lemma : evensC [cn]³[ccn]ω ⋎C tailC [cn]³[ccn]ω ≈C [cn]²[ccn]ω
lemma = cons (♯ next (cons (♯ next (cons (♯ cons (♯ next lemma₁))))))
thueMorse : StreamP [cn]³[ccn]ω Bool
thueMorse =
false ∷ [ ♯ cast lemma (map not (evens thueMorse) ⋎ tail thueMorse) ]
------------------------------------------------------------------------
-- Equality programs
infix 4 _≈[_]P_ _≈[_]W_
infixr 2 _≈⟨_⟩P_ _≈⟨_⟩_
data _≈[_]P_ : {A : Set} → Stream A → Chunks → Stream A → Set₁ where
[_] : ∀ {m A} {xs ys : Stream A}
(xs≈ys : ∞ (xs ≈[ m ]P ys)) → xs ≈[ next m ]P ys
_∷_ : ∀ {m A} (x : A) {xs ys}
(xs≈ys : ♭ xs ≈[ ♭ m ]P ♭ ys) → x ∷ xs ≈[ cons m ]P x ∷ ys
tail : ∀ {m A} {xs ys : Stream A} (xs≈ys : xs ≈[ m ]P ys) →
S.tail xs ≈[ tailC m ]P S.tail ys
evens : ∀ {m A} {xs ys : Stream A} (xs≈ys : xs ≈[ m ]P ys) →
S.evens xs ≈[ evensC m ]P S.evens ys
odds : ∀ {m A} {xs ys : Stream A} (xs≈ys : xs ≈[ m ]P ys) →
S.odds xs ≈[ oddsC m ]P S.odds ys
_⋎_ : ∀ {m m′ A} {xs xs′ ys ys′ : Stream A}
(xs≈ys : xs ≈[ m ]P ys) (xs′≈ys′ : xs′ ≈[ m′ ]P ys′) →
(xs ⟨ S._⋎_ ⟩ xs′) ≈[ m ⋎C m′ ]P (ys ⟨ S._⋎_ ⟩ ys′)
map : ∀ {m A B} (f : A → B) {xs ys : Stream A}
(xs≈ys : xs ≈[ m ]P ys) → S.map f xs ≈[ m ]P S.map f ys
cast : ∀ {m m′ A} (ok : m ≈C m′) {xs ys : Stream A}
(xs≈ys : xs ≈[ m ]P ys) → xs ≈[ m′ ]P ys
_≈⟨_⟩P_ : ∀ {m A} xs {ys zs : Stream A}
(xs≈ys : xs ≈[ m ]P ys) (ys≈zs : ys ≈ zs) → xs ≈[ m ]P zs
_≈⟨_⟩_ : ∀ {m A} xs {ys zs : Stream A}
(xs≈ys : xs ≈ ys) (ys≈zs : ys ≈[ m ]P zs) → xs ≈[ m ]P zs
data _≈[_]W_ : {A : Set} → Stream A → Chunks → Stream A → Set₁ where
[_] : ∀ {m A} {xs ys : Stream A}
(xs≈ys : xs ≈[ m ]P ys) → xs ≈[ next m ]W ys
_∷_ : ∀ {m A} (x : A) {xs ys}
(xs≈ys : ♭ xs ≈[ ♭ m ]W ♭ ys) → x ∷ xs ≈[ cons m ]W x ∷ ys
program≈ : ∀ {m A} {xs ys : Stream A} → xs ≈[ m ]W ys → xs ≈[ m ]P ys
program≈ [ xs≈ys ] = [ ♯ xs≈ys ]
program≈ (x ∷ xs≈ys) = x ∷ program≈ xs≈ys
tail-congW : ∀ {m A} {xs ys : Stream A} → xs ≈[ m ]W ys →
S.tail xs ≈[ tailC m ]W S.tail ys
tail-congW [ xs≈ys ] = [ tail xs≈ys ]
tail-congW (x ∷ xs≈ys) = xs≈ys
mutual
evens-congW : ∀ {m A} {xs ys : Stream A} →
xs ≈[ m ]W ys → S.evens xs ≈[ evensC m ]W S.evens ys
evens-congW [ xs≈ys ] = [ evens xs≈ys ]
evens-congW (x ∷ xs≈ys) = x ∷ odds-congW xs≈ys
odds-congW : ∀ {m A} {xs ys : Stream A} →
xs ≈[ m ]W ys → S.odds xs ≈[ oddsC m ]W S.odds ys
odds-congW [ xs≈ys ] = [ odds xs≈ys ]
odds-congW (x ∷ xs≈ys) = evens-congW xs≈ys
infixr 5 _⋎-congW_
-- Note: Uses swapping of arguments.
_⋎-congW_ : ∀ {m m′ A} {xs xs′ ys ys′ : Stream A} →
xs ≈[ m ]W ys → xs′ ≈[ m′ ]W ys′ →
(xs ⟨ S._⋎_ ⟩ xs′) ≈[ m ⋎C m′ ]W (ys ⟨ S._⋎_ ⟩ ys′)
[ xs≈ys ] ⋎-congW [ xs′≈ys′ ] = [ xs≈ys ⋎ xs′≈ys′ ]
[ xs≈ys ] ⋎-congW (y ∷ xs′≈ys′) = [ xs≈ys ⋎ program≈ (y ∷ xs′≈ys′) ]
(x ∷ xs≈ys) ⋎-congW xs′≈ys′ = x ∷ xs′≈ys′ ⋎-congW xs≈ys
map-congW : ∀ {m A B} (f : A → B) {xs ys : Stream A} →
xs ≈[ m ]W ys → S.map f xs ≈[ m ]W S.map f ys
map-congW f [ xs≈ys ] = [ map f xs≈ys ]
map-congW f (x ∷ xs≈ys) = f x ∷ map-congW f xs≈ys
cast-congW : ∀ {m m′ A} (ok : m ≈C m′) {xs ys : Stream A} →
xs ≈[ m ]W ys → xs ≈[ m′ ]W ys
cast-congW (next m≈m′) [ xs≈ys ] = [ cast m≈m′ xs≈ys ]
cast-congW (cons m≈m′) (x ∷ xs≈ys) = x ∷ cast-congW (♭ m≈m′) xs≈ys
transPW : ∀ {m A} {xs ys zs : Stream A} →
xs ≈[ m ]W ys → ys ≈ zs → xs ≈[ m ]W zs
transPW [ xs≈ys ] ys≈zs = [ _ ≈⟨ xs≈ys ⟩P ys≈zs ]
transPW (x ∷ xs≈ys) (P.refl ∷ ys≈zs) = x ∷ transPW xs≈ys (♭ ys≈zs)
transW : ∀ {m A} {xs ys zs : Stream A} →
xs ≈ ys → ys ≈[ m ]W zs → xs ≈[ m ]W zs
transW (x ∷ xs≈ys) [ ys≈zs ] = [ _ ≈⟨ x ∷ xs≈ys ⟩ ys≈zs ]
transW (P.refl ∷ xs≈ys) (x ∷ ys≈zs) = x ∷ transW (♭ xs≈ys) ys≈zs
whnf≈ : ∀ {m A} {xs ys : Stream A} → xs ≈[ m ]P ys → xs ≈[ m ]W ys
whnf≈ [ xs ] = [ ♭ xs ]
whnf≈ (x ∷ xs) = x ∷ whnf≈ xs
whnf≈ (tail xs) = tail-congW (whnf≈ xs)
whnf≈ (evens xs) = evens-congW (whnf≈ xs)
whnf≈ (odds xs) = odds-congW (whnf≈ xs)
whnf≈ (xs ⋎ ys) = whnf≈ xs ⋎-congW whnf≈ ys
whnf≈ (map f xs) = map-congW f (whnf≈ xs)
whnf≈ (cast m≈m′ xs) = cast-congW m≈m′ (whnf≈ xs)
whnf≈ (xs ≈⟨ xs≈ys ⟩P ys≈zs) = transPW (whnf≈ xs≈ys) ys≈zs
whnf≈ (xs ≈⟨ xs≈ys ⟩ ys≈zs) = transW xs≈ys (whnf≈ ys≈zs)
mutual
soundW : ∀ {m A} {xs ys : Stream A} → xs ≈[ m ]W ys → xs ≈ ys
soundW [ xs≈ys ] = soundP xs≈ys
soundW (x ∷ xs≈ys) = P.refl ∷ ♯ soundW xs≈ys
soundP : ∀ {m A} {xs ys : Stream A} → xs ≈[ m ]P ys → xs ≈ ys
soundP xs≈ys = soundW (whnf≈ xs≈ys)
------------------------------------------------------------------------
-- The definition is correct
-- The proof consists mostly of boiler-plate code.
program-hom : ∀ {m A} (xs : StreamW m A) → ⟦ program xs ⟧P ≈ ⟦ xs ⟧W
program-hom [ xs ] = SS.refl
program-hom (x ∷ xs) = P.refl ∷ ♯ program-hom xs
mutual
tailW-hom : ∀ {A : Set} {m} (xs : StreamW m A) →
⟦ tailW xs ⟧W ≈ S.tail ⟦ xs ⟧W
tailW-hom [ xs ] = tail-hom xs
tailW-hom (x ∷ xs) = SS.refl
tail-hom : ∀ {A : Set} {m} (xs : StreamP m A) →
⟦ tail xs ⟧P ≈ S.tail ⟦ xs ⟧P
tail-hom xs = tailW-hom (whnf xs)
mutual
infixr 5 _⋎W-hom_ _⋎-hom_
-- Note: Uses swapping of arguments.
_⋎W-hom_ : ∀ {A : Set} {m m′} (xs : StreamW m A) (ys : StreamW m′ A) →
⟦ xs ⋎W ys ⟧W ≈[ m ⋎C m′ ]P (⟦ xs ⟧W ⟨ S._⋎_ ⟩ ⟦ ys ⟧W)
(x ∷ xs) ⋎W-hom ys = x ∷ ys ⋎W-hom xs
[ xs ] ⋎W-hom [ ys ] = [ ♯ (xs ⋎-hom ys) ]
[ xs ] ⋎W-hom (y ∷ ys′) =
[ ♯ (⟦ xs ⋎ program ys ⟧P ≈⟨ xs ⋎-hom program ys ⟩P (begin
(⟦ xs ⟧P ⟨ S._⋎_ ⟩ ⟦ program ys ⟧P) SR.≈⟨ SS.refl ⟨ S._⋎-cong_ ⟩ program-hom ys ⟩
(⟦ xs ⟧P ⟨ S._⋎_ ⟩ ⟦ ys ⟧W) ∎)) ]
where ys = y ∷ ys′
_⋎-hom_ : ∀ {A : Set} {m m′} (xs : StreamP m A) (ys : StreamP m′ A) →
⟦ xs ⋎ ys ⟧P ≈[ m ⋎C m′ ]P (⟦ xs ⟧P ⟨ S._⋎_ ⟩ ⟦ ys ⟧P)
xs ⋎-hom ys = whnf xs ⋎W-hom whnf ys
mutual
evensW-hom : ∀ {A : Set} {m} (xs : StreamW m A) →
⟦ evensW xs ⟧W ≈ S.evens ⟦ xs ⟧W
evensW-hom [ xs ] = evens-hom xs
evensW-hom (x ∷ xs) = P.refl ∷ ♯ oddsW-hom xs
evens-hom : ∀ {A : Set} {m} (xs : StreamP m A) →
⟦ evens xs ⟧P ≈ S.evens ⟦ xs ⟧P
evens-hom xs = evensW-hom (whnf xs)
oddsW-hom : ∀ {A : Set} {m} (xs : StreamW m A) →
⟦ oddsW xs ⟧W ≈ S.odds ⟦ xs ⟧W
oddsW-hom [ xs ] = odds-hom xs
oddsW-hom (x ∷ xs) = evensW-hom xs
odds-hom : ∀ {A : Set} {m} (xs : StreamP m A) →
⟦ odds xs ⟧P ≈ S.odds ⟦ xs ⟧P
odds-hom xs = oddsW-hom (whnf xs)
mutual
mapW-hom : ∀ {A B : Set} {m} (f : A → B) (xs : StreamW m A) →
⟦ mapW f xs ⟧W ≈ S.map f ⟦ xs ⟧W
mapW-hom f [ xs ] = map-hom f xs
mapW-hom f (x ∷ xs) = P.refl ∷ ♯ mapW-hom f xs
map-hom : ∀ {A B : Set} {m} (f : A → B) (xs : StreamP m A) →
⟦ map f xs ⟧P ≈ S.map f ⟦ xs ⟧P
map-hom f xs = mapW-hom f (whnf xs)
mutual
castW-hom : ∀ {m m′ A} (m≈m′ : m ≈C m′) (xs : StreamW m A) →
⟦ castW m≈m′ xs ⟧W ≈ ⟦ xs ⟧W
castW-hom (next m≈m′) [ xs ] = cast-hom m≈m′ xs
castW-hom (cons m≈m′) (x ∷ xs) = P.refl ∷ ♯ castW-hom (♭ m≈m′) xs
cast-hom : ∀ {m m′ A} (m≈m′ : m ≈C m′) (xs : StreamP m A) →
⟦ cast m≈m′ xs ⟧P ≈ ⟦ xs ⟧P
cast-hom m≈m′ xs = castW-hom m≈m′ (whnf xs)
-- The intended definition of the Thue-Morse sequence is bs = rhs bs.
rhs : Stream Bool → Stream Bool
rhs bs = false ∷ ♯ (S.map not (S.evens bs) ⟨ S._⋎_ ⟩ S.tail bs)
-- The definition above satisfies the intended defining equation.
correct : ⟦ thueMorse ⟧P ≈[ [cn]³[ccn]ω ]P rhs ⟦ thueMorse ⟧P
correct = false ∷ [ ♯ cast lemma (
⟦ cast lemma (map not (evens thueMorse) ⋎ tail thueMorse) ⟧P ≈⟨ cast-hom lemma (map not (evens thueMorse) ⋎ tail thueMorse) ⟩
⟦ map not (evens thueMorse) ⋎ tail thueMorse ⟧P ≈⟨ map not (evens thueMorse) ⋎-hom tail thueMorse ⟩P (begin
(⟦ map not (evens thueMorse) ⟧P ⟨ S._⋎_ ⟩ ⟦ tail thueMorse ⟧P) SR.≈⟨ SS.trans (map-hom not (evens thueMorse))
(S.map-cong not (evens-hom thueMorse))
⟨ S._⋎-cong_ ⟩
tail-hom thueMorse ⟩
(S.map not (S.evens ⟦ thueMorse ⟧P) ⟨ S._⋎_ ⟩ S.tail ⟦ thueMorse ⟧P) ∎ )) ]
-- The defining equation has at most one solution.
unique : ∀ bs bs′ → bs ≈ rhs bs → bs′ ≈ rhs bs′ → bs ≈[ [cn]³[ccn]ω ]P bs′
unique bs bs′ bs≈ bs′≈ =
bs ≈⟨ bs≈ ⟩
rhs bs ≈⟨ false ∷ [ ♯ cast lemma
(map not (evens (unique bs bs′ bs≈ bs′≈))
⋎
tail (unique bs bs′ bs≈ bs′≈)) ] ⟩P (begin
rhs bs′ SR.≈⟨ SS.sym bs′≈ ⟩
bs′ ∎)
|
{
"alphanum_fraction": 0.4819085487,
"avg_line_length": 35.7582938389,
"ext": "agda",
"hexsha": "eaac89cd4b1fde9fdfaa62e3b0993b9fa8ed0920",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "ThueMorse.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "ThueMorse.agda",
"max_line_length": 136,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "ThueMorse.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 6764,
"size": 15090
}
|
-- {-# OPTIONS -v tc.proj.like:30 #-}
open import Common.Bool
open import Common.Equality
abstract
Id : Set → Set
Id A = A
f : ∀ A → Id A → Id A
f A x = x
postulate
foo : ∀{X : Set} (x y : X) → x ≡ y → Set
abstract
bla : Set
bla = foo (f Bool true) false refl
-- WAS:
-- true != false of type Bool
-- when checking that the expression refl has type f _ true ≡ false
-- EXPECTED:
-- true != false of type Bool
-- when checking that the expression refl has type f Bool true ≡ false
|
{
"alphanum_fraction": 0.6277665996,
"avg_line_length": 18.4074074074,
"ext": "agda",
"hexsha": "a92e5921d24627f4fccf5086ffdd0a5002c13757",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pthariensflame/agda",
"max_forks_repo_path": "test/Fail/AbstractTypeProjectionLike.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pthariensflame/agda",
"max_issues_repo_path": "test/Fail/AbstractTypeProjectionLike.agda",
"max_line_length": 70,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pthariensflame/agda",
"max_stars_repo_path": "test/Fail/AbstractTypeProjectionLike.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 155,
"size": 497
}
|
-- Andreas, 2019-07-04, issue #3886
-- Override forcing with explicit quantity attributes.
open import Common.Prelude
pattern [_] x = x ∷ []
module _ {a} {A : Set a} where
variable
x y z : A
@0 xs ys zs : List A
data FSet : List A → Set a where
∅ : FSet []
_∪_ : FSet xs → FSet ys → FSet (xs ++ ys)
sg : (@ω x : A) → FSet [ x ]
-- x is forced here, but this is not wanted.
-- With an explicit quantity attribute we tell the forcing machinery not to erase x.
-- Since xs is erased, we cannot get x from sg x : FSet xs (with xs = [ x ])
-- unless x is retained in sg x.
elements : {@0 xs : List A} → FSet xs → List A
elements ∅ = []
elements (s ∪ t) = elements s ++ elements t
elements (sg x) = [ x ]
-- ERROR WAS:
-- Variable x is declared erased, so it cannot be used here
-- when checking that the expression x has type A
mySet = (sg 1 ∪ sg 2) ∪ (sg 3 ∪ sg 4)
sum : List Nat → Nat
sum [] = 0
sum (n ∷ ns) = n + sum ns
test = elements mySet
main = printNat (sum (elements mySet))
-- Should print 10.
|
{
"alphanum_fraction": 0.5994371482,
"avg_line_length": 24.7906976744,
"ext": "agda",
"hexsha": "d4eb1788d81137619ee46a749923b47ec11d9276",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Compiler/simple/Issue3886.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Compiler/simple/Issue3886.agda",
"max_line_length": 88,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Compiler/simple/Issue3886.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 348,
"size": 1066
}
|
{-# OPTIONS --cubical --safe #-}
module Data.List.Syntax where
open import Data.List
open import Prelude
record ListSyntax {a b} (A : Type a) (B : Type b) : Type (a ℓ⊔ b) where
field [_] : B → List A
open ListSyntax ⦃ ... ⦄ public
instance
cons : ⦃ _ : ListSyntax A B ⦄ → ListSyntax A (A × B)
[_] ⦃ cons ⦄ (x , xs) = x ∷ [ xs ]
instance
sing : ListSyntax A A
[_] ⦃ sing ⦄ = _∷ []
|
{
"alphanum_fraction": 0.5804020101,
"avg_line_length": 18.9523809524,
"ext": "agda",
"hexsha": "b9e5311bf1161a603d83cc89114d4bd1732a7987",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Data/List/Syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Data/List/Syntax.agda",
"max_line_length": 71,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Data/List/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z",
"num_tokens": 152,
"size": 398
}
|
open import Level using () renaming (zero to ℓ₀)
open import Relation.Binary using (DecSetoid)
module Bidir (A : DecSetoid ℓ₀ ℓ₀) where
open import Data.Nat using (ℕ)
open import Data.Fin using (Fin)
import Level
import Category.Monad
import Category.Functor
open import Data.Maybe using (Maybe ; nothing ; just ; maybe′ ; drop-just) renaming (setoid to MaybeSetoid ; Eq to MaybeEq)
open Category.Monad.RawMonad {Level.zero} Data.Maybe.monad using (_>>=_)
open Category.Functor.RawFunctor {Level.zero} Data.Maybe.functor using (_<$>_)
open import Data.List using (List)
open import Data.List.All using (All)
open import Data.Vec using (Vec ; [] ; _∷_ ; toList ; map ; allFin) renaming (lookup to lookupVec)
open import Data.Vec.Equality using () renaming (module Equality to VecEq)
open import Data.Vec.Properties using (lookup∘tabulate ; map-cong ; map-∘ ; map-lookup-allFin)
open import Data.Product using (∃ ; _×_ ; _,_ ; proj₁ ; proj₂)
open import Function using (id ; _∘_ ; flip)
open import Relation.Binary.Core using (refl ; _≡_)
open import Relation.Binary.Indexed using (_at_) renaming (Setoid to ISetoid)
open import Relation.Binary.PropositionalEquality using (cong ; sym ; inspect ; [_] ; trans ; cong₂ ; decSetoid ; module ≡-Reasoning) renaming (setoid to EqSetoid)
open import Relation.Binary using (Setoid ; module Setoid ; module DecSetoid)
import Relation.Binary.EqReasoning as EqR
open import Structures using (Functor ; IsFunctor ; Shaped ; module Shaped)
open import Instances using (MaybeFunctor ; ShapedISetoid)
import GetTypes
open GetTypes.PartialShapeShape using (Get ; module Get)
open import Generic using (mapMV ; mapMV-cong ; mapMV-purity ; sequenceV ; VecISetoid ; just-injective)
open import FinMap
import CheckInsert
open CheckInsert A
import BFF
open BFF.PartialShapeBFF A using (assoc ; enumerate ; denumerate ; bff)
open Setoid using () renaming (_≈_ to _∋_≈_)
open module A = DecSetoid A using (Carrier) renaming (_≟_ to deq)
lemma-1 : {m n : ℕ} → (f : Fin n → Carrier) → (is : Vec (Fin n) m) → assoc is (map f is) ≡ just (restrict f is)
lemma-1 f [] = refl
lemma-1 f (i ∷ is′) = begin
(assoc is′ (map f is′) >>= checkInsert i (f i))
≡⟨ cong (λ m → m >>= checkInsert i (f i)) (lemma-1 f is′) ⟩
checkInsert i (f i) (restrict f is′)
≡⟨ lemma-checkInsert-restrict f i is′ ⟩
just (restrict f (i ∷ is′)) ∎
where open ≡-Reasoning
lemma-lookupM-checkInserted : {n : ℕ} → (i : Fin n) → (x : Carrier) → (h : FinMapMaybe n Carrier) → {h' : FinMapMaybe n Carrier} → checkInsert i x h ≡ just h' → MaybeSetoid A.setoid ∋ lookupM i h' ≈ just x
lemma-lookupM-checkInserted i x h p with checkInsert i x h | insertionresult i x h
lemma-lookupM-checkInserted i x h refl | ._ | same x' x≈x' pl = begin
lookupM i h
≡⟨ pl ⟩
just x'
≈⟨ MaybeEq.just (Setoid.sym A.setoid x≈x') ⟩
just x ∎
where open EqR (MaybeSetoid A.setoid)
lemma-lookupM-checkInserted i x h refl | ._ | new _ = Setoid.reflexive (MaybeSetoid A.setoid) (lemma-lookupM-insert i x h)
lemma-lookupM-checkInserted i x h () | ._ | wrong _ _ _
_in-domain-of_ : {m n : ℕ} {A : Set} → (is : Vec (Fin m) n) → (FinMapMaybe m A) → Set
_in-domain-of_ is h = All (λ i → ∃ λ x → lookupM i h ≡ just x) (toList is)
lemma-assoc-domain : {m n : ℕ} → (is : Vec (Fin n) m) → (xs : Vec Carrier m) → {h : FinMapMaybe n Carrier} → assoc is xs ≡ just h → is in-domain-of h
lemma-assoc-domain [] [] ph = Data.List.All.[]
lemma-assoc-domain (i' ∷ is') (x' ∷ xs') ph with assoc is' xs' | inspect (assoc is') xs'
lemma-assoc-domain (i' ∷ is') (x' ∷ xs') () | nothing | [ ph' ]
lemma-assoc-domain (i' ∷ is') (x' ∷ xs') ph | just h' | [ ph' ] with checkInsert i' x' h' | inspect (checkInsert i' x') h' | insertionresult i' x' h'
lemma-assoc-domain (i' ∷ is') (x' ∷ xs') refl | just h | [ ph' ] | ._ | _ | same x _ pl = All._∷_ (x , pl) (lemma-assoc-domain is' xs' ph')
lemma-assoc-domain (i' ∷ is') (x' ∷ xs') refl | just h' | [ ph' ] | ._ | [ cI≡ ] | new _ = All._∷_
(x' , lemma-lookupM-insert i' x' h')
(Data.List.All.map
(λ {i} p → proj₁ p , lemma-lookupM-checkInsert i i' h' (proj₂ p) x' cI≡)
(lemma-assoc-domain is' xs' ph'))
lemma-assoc-domain (i' ∷ is') (x' ∷ xs') () | just h' | [ ph' ] | ._ | _ | wrong _ _ _
lemma-map-lookupM-assoc : {m : ℕ} → (i : Fin m) → (x : Carrier) → (h : FinMapMaybe m Carrier) → {h' : FinMapMaybe m Carrier} → checkInsert i x h ≡ just h' → {n : ℕ} → (js : Vec (Fin m) n) → js in-domain-of h → map (flip lookupM h') js ≡ map (flip lookupM h) js
lemma-map-lookupM-assoc i x h ph [] pj = refl
lemma-map-lookupM-assoc i x h ph (j ∷ js) (Data.List.All._∷_ (x' , pl) pj) = cong₂ _∷_
(trans (lemma-lookupM-checkInsert j i h pl x ph) (sym pl))
(lemma-map-lookupM-assoc i x h ph js pj)
lemma-2 : {m n : ℕ} → (is : Vec (Fin n) m) → (v : Vec Carrier m) → (h : FinMapMaybe n Carrier) → assoc is v ≡ just h → VecISetoid (MaybeSetoid A.setoid) at _ ∋ map (flip lookupM h) is ≈ map just v
lemma-2 [] [] h p = ISetoid.refl (VecISetoid (MaybeSetoid A.setoid))
lemma-2 (i ∷ is) (x ∷ xs) h p with assoc is xs | inspect (assoc is) xs
lemma-2 (i ∷ is) (x ∷ xs) h () | nothing | _
lemma-2 (i ∷ is) (x ∷ xs) h p | just h' | [ ir ] = begin
lookupM i h ∷ map (flip lookupM h) is
≈⟨ VecEq._∷-cong_ (lemma-lookupM-checkInserted i x h' p) (ISetoid.refl (VecISetoid (MaybeSetoid A.setoid))) ⟩
just x ∷ map (flip lookupM h) is
≡⟨ cong (_∷_ (just x)) (lemma-map-lookupM-assoc i x h' p is (lemma-assoc-domain is xs ir)) ⟩
just x ∷ map (flip lookupM h') is
≈⟨ VecEq._∷-cong_ (Setoid.refl (MaybeSetoid A.setoid)) (lemma-2 is xs h' ir) ⟩
just x ∷ map just xs ∎
where open EqR (VecISetoid (MaybeSetoid A.setoid) at _)
lemma-fmap-denumerate-enumerate : {S : Set} {C : Set → S → Set} → (ShapeT : Shaped S C) → {α : Set} {s : S} → (c : C α s) → Shaped.fmap ShapeT (denumerate ShapeT c) (enumerate ShapeT s) ≡ c
lemma-fmap-denumerate-enumerate {S} {C} ShapeT {s = s} c = begin
fmap (denumerate ShapeT c) (fill s (allFin (arity s)))
≡⟨ fill-fmap (denumerate ShapeT c) s (allFin (arity s)) ⟩
fill s (map (flip lookupVec (content c)) (allFin (arity s)))
≡⟨ cong (fill s) (map-lookup-allFin (content c)) ⟩
fill s (content c)
≡⟨ content-fill c ⟩
c ∎
where open ≡-Reasoning
open Shaped ShapeT
theorem-1 : (G : Get) → {i : Get.I G} → (s : Get.SourceContainer G Carrier (Get.gl₁ G i)) → bff G i s (Get.get G s) ≡ just (Get.fmapS G just s)
theorem-1 G {i} s = begin
bff G i s (get s)
≡⟨ cong (bff G i s ∘ get) (sym (lemma-fmap-denumerate-enumerate SourceShapeT s)) ⟩
bff G i s (get (fmapS f t))
≡⟨ cong (bff G i s) (free-theorem f t) ⟩
bff G i s (fmapV f (get t))
≡⟨ refl ⟩
h′↦r <$> (h↦h′ <$> (assoc (Shaped.content ViewShapeT (get t)) (Shaped.content ViewShapeT (fmapV f (get t)))))
≡⟨ cong (_<$>_ h′↦r ∘ _<$>_ h↦h′ ∘ assoc (Shaped.content ViewShapeT (get t))) (Shaped.fmap-content ViewShapeT f (get t)) ⟩
h′↦r <$> (h↦h′ <$> (assoc (Shaped.content ViewShapeT (get t)) (map f (Shaped.content ViewShapeT (get t)))))
≡⟨ cong (_<$>_ h′↦r ∘ _<$>_ h↦h′) (lemma-1 f (Shaped.content ViewShapeT (get t))) ⟩
(Maybe.just ∘ h′↦r ∘ h↦h′) (restrict f (Shaped.content ViewShapeT (get t)))
≡⟨ cong just (begin
h′↦r (union (restrict f (Shaped.content ViewShapeT (get t))) (reshape g′ (Shaped.arity SourceShapeT (gl₁ i))))
≡⟨ cong (h′↦r ∘ union (restrict f (Shaped.content ViewShapeT (get t)))) (lemma-reshape-id g′) ⟩
h′↦r (union (restrict f (Shaped.content ViewShapeT (get t))) g′)
≡⟨ cong h′↦r (lemma-disjoint-union f (Shaped.content ViewShapeT (get t))) ⟩
h′↦r (fromFunc f)
≡⟨ refl ⟩
fmapS (flip lookupM (fromFunc f)) t
≡⟨ IsFunctor.cong (Shaped.isFunctor SourceShapeT (gl₁ i)) (lemma-lookupM-fromFunc f) t ⟩
fmapS (Maybe.just ∘ f) t
≡⟨ IsFunctor.composition (Shaped.isFunctor SourceShapeT (gl₁ i)) just f t ⟩
fmapS just (fmapS f t)
≡⟨ cong (fmapS just) (lemma-fmap-denumerate-enumerate SourceShapeT s) ⟩
fmapS just s ∎) ⟩ _ ∎
where open ≡-Reasoning
open Get G
t = enumerate SourceShapeT (gl₁ i)
f = denumerate SourceShapeT s
g′ = delete-many (Shaped.content ViewShapeT (get t)) (fromFunc f)
h↦h′ = flip union (reshape g′ (Shaped.arity SourceShapeT (gl₁ i)))
h′↦r = (λ f′ → fmapS f′ t) ∘ flip lookupM
lemma-<$>-just : {A B : Set} {f : A → B} {b : B} (ma : Maybe A) → f <$> ma ≡ just b → ∃ λ a → ma ≡ just a
lemma-<$>-just (just x) f<$>ma≡just-b = x , refl
lemma-<$>-just nothing ()
lemma-union-not-used : {n : ℕ} → {A : Set} → (h h′ : FinMapMaybe n A) → (i : Fin n) → ∃ (λ x → lookupM i h ≡ just x) → lookupM i (union h h′) ≡ lookupM i h
lemma-union-not-used h h′ i (x , px) = begin
lookupM i (union h h′)
≡⟨ lookup∘tabulate (λ j → maybe′ just (lookupM j h′) (lookupM j h)) i ⟩
maybe′ just (lookupM i h′) (lookupM i h)
≡⟨ cong (maybe′ just (lookupM i h′)) px ⟩
maybe′ just (lookupM i h′) (just x)
≡⟨ sym px ⟩
lookupM i h ∎
where open ≡-Reasoning
lemma->>=-just : {A B : Set} (ma : Maybe A) {f : A → Maybe B} {b : B} → (ma >>= f) ≡ just b → ∃ λ a → ma ≡ just a
lemma->>=-just (just a) p = a , refl
lemma->>=-just nothing ()
lemma-just-sequenceV : {A : Set} {n : ℕ} → (v : Vec A n) → sequenceV (map just v) ≡ just v
lemma-just-sequenceV [] = refl
lemma-just-sequenceV (x ∷ xs) = cong (_<$>_ (_∷_ x)) (lemma-just-sequenceV xs)
lemma-just-sequence : {S : Set} {C : Set → S → Set} → (ShapeT : Shaped S C) → {A : Set} {s : S} → (c : C A s) → Shaped.sequence ShapeT (Shaped.fmap ShapeT just c) ≡ just c
lemma-just-sequence ShapeT {s = s} c = begin
fill s <$> sequenceV (content (fmap just c))
≡⟨ cong (_<$>_ (fill s) ∘ sequenceV) (fmap-content just c) ⟩
fill s <$> sequenceV (map just (content c))
≡⟨ cong (_<$>_ (fill s)) (lemma-just-sequenceV (content c)) ⟩
fill s <$> just (content c)
≡⟨ cong just (content-fill c) ⟩
just c ∎
where open ≡-Reasoning
open Shaped ShapeT
lemma-sequenceV-successful : {A : Set} {n : ℕ} → (v : Vec (Maybe A) n) → {r : Vec A n} → sequenceV v ≡ just r → v ≡ map just r
lemma-sequenceV-successful [] {r = []} p = refl
lemma-sequenceV-successful (just x ∷ xs) p with sequenceV xs | inspect sequenceV xs
lemma-sequenceV-successful (just x ∷ xs) () | nothing | _
lemma-sequenceV-successful (just x ∷ xs) {r = .x ∷ .ys} refl | just ys | [ p′ ] = cong (_∷_ (just x)) (lemma-sequenceV-successful xs p′)
lemma-sequenceV-successful (nothing ∷ xs) ()
lemma-sequence-successful : {S : Set} {C : Set → S → Set} → (ShapeT : Shaped S C) → {A : Set} {s : S} → (c : C (Maybe A) s) → {r : C A s} → Shaped.sequence ShapeT c ≡ just r → c ≡ Shaped.fmap ShapeT just r
lemma-sequence-successful ShapeT {s = s} c {r} p = just-injective (sym (begin
fill s <$> (map just <$> (content <$> just r))
≡⟨ cong (_<$>_ (fill s) ∘ _<$>_ (map just)) (begin
content <$> just r
≡⟨ cong (_<$>_ content) (sym p) ⟩
content <$> (fill s <$> sequenceV (content c))
≡⟨ sym (Functor.composition MaybeFunctor content (fill s) (sequenceV (content c))) ⟩
content ∘ fill s <$> sequenceV (content c)
≡⟨ Functor.cong MaybeFunctor (fill-content s) (sequenceV (content c)) ⟩
id <$> sequenceV (content c)
≡⟨ Functor.identity MaybeFunctor (sequenceV (content c)) ⟩
sequenceV (content c)
≡⟨ cong sequenceV (lemma-sequenceV-successful (content c) (proj₂ wp)) ⟩
sequenceV (map just (proj₁ wp))
≡⟨ lemma-just-sequenceV (proj₁ wp) ⟩
just (proj₁ (lemma-<$>-just (sequenceV (content c)) p)) ∎) ⟩
fill s <$> (map just <$> just (proj₁ (lemma-<$>-just (sequenceV (content c)) p)))
≡⟨ cong (_<$>_ (fill s) ∘ just) (sym (lemma-sequenceV-successful (content c) (proj₂ wp))) ⟩
fill s <$> just (content c)
≡⟨ cong just (content-fill c) ⟩
just c ∎))
where open ≡-Reasoning
open Shaped ShapeT
wp = lemma-<$>-just (sequenceV (content c)) p
module _ (G : Get) where
open ≡-Reasoning
open Get G
open Shaped SourceShapeT using () renaming (sequence to sequenceSource)
open Shaped ViewShapeT using () renaming (sequence to sequenceView)
lemma-get-sequence : {A : Set} → {i : I} {v : SourceContainer (Maybe A) (gl₁ i)} {r : SourceContainer A (gl₁ i)} → sequenceSource v ≡ just r → get <$> sequenceSource v ≡ sequenceView (get v)
lemma-get-sequence {v = v} {r = r} p = begin
get <$> sequenceSource v
≡⟨ cong (_<$>_ get ∘ sequenceSource) (lemma-sequence-successful SourceShapeT v p) ⟩
get <$> sequenceSource (fmapS just r)
≡⟨ cong (_<$>_ get) (lemma-just-sequence SourceShapeT r) ⟩
get <$> just r
≡⟨ sym (lemma-just-sequence ViewShapeT (get r)) ⟩
sequenceView (fmapV just (get r))
≡⟨ cong sequenceView (sym (free-theorem just r)) ⟩
sequenceView (get (fmapS just r))
≡⟨ cong (sequenceView ∘ get) (sym (lemma-sequence-successful SourceShapeT v p)) ⟩
sequenceView (get v) ∎
sequenceV-cong : {S : Setoid ℓ₀ ℓ₀} {n : ℕ} {m₁ m₂ : Setoid.Carrier (VecISetoid (MaybeSetoid S) at n)} → VecISetoid (MaybeSetoid S) at _ ∋ m₁ ≈ m₂ → MaybeSetoid (VecISetoid S at n) ∋ sequenceV m₁ ≈ sequenceV m₂
sequenceV-cong {S} VecEq.[]-cong = Setoid.refl (MaybeSetoid (VecISetoid S at _))
sequenceV-cong {S} {m₁ = just x ∷ xs} {m₂ = just y ∷ ys} (VecEq._∷-cong_ (just x≈y) xs≈ys) with sequenceV xs | sequenceV ys | sequenceV-cong xs≈ys
sequenceV-cong {S} {m₁ = just x ∷ xs} {m₂ = just y ∷ ys} (VecEq._∷-cong_ (just x≈y) xs≈ys) | just sxs | just sys | just p = MaybeEq.just (VecEq._∷-cong_ x≈y p)
sequenceV-cong {S} {m₁ = just x ∷ xs} {m₂ = just y ∷ ys} (VecEq._∷-cong_ (just x≈y) xs≈ys) | nothing | just sys | ()
sequenceV-cong {S} {m₁ = just x ∷ xs} {m₂ = just y ∷ ys} (VecEq._∷-cong_ (just x≈y) xs≈ys) | just sxs | nothing | ()
sequenceV-cong {S} {m₁ = just x ∷ xs} {m₂ = just y ∷ ys} (VecEq._∷-cong_ (just x≈y) xs≈ys) | nothing | nothing | nothing = Setoid.refl (MaybeSetoid (VecISetoid S at _))
sequenceV-cong {S} (VecEq._∷-cong_ nothing xs≈ys) = Setoid.refl (MaybeSetoid (VecISetoid S at _))
sequence-cong : {S : Set} {C : Set → S → Set} → (ShapeT : Shaped S C) → (α : Setoid ℓ₀ ℓ₀) → {s : S} {x y : C (Maybe (Setoid.Carrier α)) s} → ShapedISetoid (EqSetoid S) ShapeT (MaybeSetoid α) at _ ∋ x ≈ y → MaybeSetoid (ShapedISetoid (EqSetoid S) ShapeT α at _) ∋ Shaped.sequence ShapeT x ≈ Shaped.sequence ShapeT y
sequence-cong ShapeT α {x = x} {y = y} (shape≈ , content≈) with sequenceV (Shaped.content ShapeT x) | sequenceV (Shaped.content ShapeT y) | sequenceV-cong content≈
sequence-cong ShapeT α {s} (shape≈ , content≈) | .(just x) | .(just y) | just {x} {y} x≈y = just (refl , (begin
content (fill s x)
≡⟨ fill-content s x ⟩
x
≈⟨ x≈y ⟩
y
≡⟨ sym (fill-content s y) ⟩
content (fill s y) ∎))
where open EqR (VecISetoid α at _)
open Shaped ShapeT
sequence-cong ShapeT α (shape≈ , content≈) | .nothing | .nothing | nothing = nothing
module _ (G : Get) where
open Get G
open Shaped SourceShapeT using () renaming (arity to arityS)
open Shaped ViewShapeT using () renaming (content to contentV)
theorem-2 : {i : I} → (j : I) → (s : SourceContainer Carrier (gl₁ i)) → (v : ViewContainer Carrier (gl₂ j)) → (u : SourceContainer (Maybe Carrier) (gl₁ j)) → bff G j s v ≡ just u → ShapedISetoid (EqSetoid _) ViewShapeT (MaybeSetoid A.setoid) at _ ∋ get u ≈ Get.fmapV G just v
theorem-2 {i} j s v u p with lemma-<$>-just ((flip union (reshape (delete-many (contentV (get (enumerate SourceShapeT (gl₁ i)))) (fromFunc (denumerate SourceShapeT s))) (arityS (gl₁ j)))) <$> assoc (contentV (get (enumerate SourceShapeT (gl₁ j)))) (contentV v)) p
theorem-2 {i} j s v u p | h′ , ph′ with lemma-<$>-just (assoc (contentV (get (enumerate SourceShapeT (gl₁ j)))) (contentV v)) ph′
theorem-2 {i} j s v u p | h′ , ph′ | h , ph = refl , (begin
contentV (get u)
≡⟨ cong contentV (just-injective (trans (cong (_<$>_ get) (sym p))
(cong (_<$>_ get ∘ _<$>_ h′↦r ∘ _<$>_ h↦h′) ph))) ⟩
contentV (get (h′↦r (h↦h′ h)))
≡⟨ refl ⟩
contentV (get (fmapS (flip lookupM (h↦h′ h)) t))
≡⟨ cong contentV (free-theorem (flip lookupM (h↦h′ h)) t) ⟩
contentV (fmapV (flip lookupM (h↦h′ h)) (get t))
≡⟨ Shaped.fmap-content ViewShapeT (flip lookupM (h↦h′ h)) (get t) ⟩
map (flip lookupM (h↦h′ h)) (contentV (get t))
≡⟨ lemma-exchange-maps (lemma-union-not-used h (reshape g′ (arityS (gl₁ j)))) (lemma-assoc-domain (contentV (get t)) (contentV v) ph) ⟩
map (flip lookupM h) (contentV (get t))
≈⟨ lemma-2 (contentV (get t)) (contentV v) h ph ⟩
map just (contentV v)
≡⟨ sym (Shaped.fmap-content ViewShapeT just v) ⟩
contentV (fmapV just v) ∎)
where open EqR (VecISetoid (MaybeSetoid A.setoid) at _)
s′ = enumerate SourceShapeT (gl₁ i)
g = fromFunc (denumerate SourceShapeT s)
g′ = delete-many (contentV (get s′)) g
t = enumerate SourceShapeT (gl₁ j)
h↦h′ = flip union (reshape g′ (arityS (gl₁ j)))
h′↦r = (λ f → fmapS f t) ∘ flip lookupM
module _ (G : Get) where
open Get G
theorem-2′ : {i : I} → (j : I) → (s : SourceContainer Carrier (gl₁ i)) → (v : ViewContainer Carrier (gl₂ j)) → (u : SourceContainer Carrier (gl₁ j)) → bff G j s v ≡ just (Get.fmapS G just u) → ShapedISetoid (EqSetoid _) ViewShapeT A.setoid at _ ∋ get u ≈ v
theorem-2′ j s v u p = drop-just (begin
get <$> just u
≡⟨ cong (_<$>_ get) (sym (lemma-just-sequence SourceShapeT u)) ⟩
get <$> Shaped.sequence SourceShapeT (fmapS just u)
≡⟨ lemma-get-sequence G (lemma-just-sequence SourceShapeT u) ⟩
Shaped.sequence ViewShapeT (get (fmapS just u))
≈⟨ sequence-cong ViewShapeT A.setoid (theorem-2 G j s v (fmapS just u) p) ⟩
Shaped.sequence ViewShapeT (fmapV just v)
≡⟨ lemma-just-sequence ViewShapeT v ⟩
just v ∎)
where open EqR (MaybeSetoid (ShapedISetoid (EqSetoid _) ViewShapeT A.setoid at _))
|
{
"alphanum_fraction": 0.6138269698,
"avg_line_length": 59.2287581699,
"ext": "agda",
"hexsha": "790f9b952560321d565bd3a6515b14ecdc8a40dd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jvoigtlaender/bidiragda",
"max_forks_repo_path": "Bidir.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jvoigtlaender/bidiragda",
"max_issues_repo_path": "Bidir.agda",
"max_line_length": 315,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jvoigtlaender/bidiragda",
"max_stars_repo_path": "Bidir.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6675,
"size": 18124
}
|
------------------------------------------------------------------------
-- A bunch of properties
------------------------------------------------------------------------
module Data.Bool.Properties where
open import Data.Bool as Bool
open import Data.Fin
open import Data.Function
open import Algebra
open import Algebra.Structures
import Algebra.RingSolver.Simple as Solver
import Algebra.RingSolver.AlmostCommutativeRing as ACR
open import Relation.Nullary using (_⇔_)
open import Relation.Binary.PropositionalEquality
import Algebra.FunctionProperties as P; open P _≡_
open import Data.Product
open import Data.Sum
open import Data.Empty
import Relation.Binary.EqReasoning as EqR; open EqR Bool.setoid
------------------------------------------------------------------------
-- Duality
-- Can we take advantage of duality in some (nice) way?
------------------------------------------------------------------------
-- (Bool, ∨, ∧, false, true) forms a commutative semiring
private
∨-assoc : Associative _∨_
∨-assoc true y z = refl
∨-assoc false y z = refl
∧-assoc : Associative _∧_
∧-assoc true y z = refl
∧-assoc false y z = refl
∨-comm : Commutative _∨_
∨-comm true true = refl
∨-comm true false = refl
∨-comm false true = refl
∨-comm false false = refl
∧-comm : Commutative _∧_
∧-comm true true = refl
∧-comm true false = refl
∧-comm false true = refl
∧-comm false false = refl
∨-identity : Identity false _∨_
∨-identity = (λ _ → refl) , (λ x → ∨-comm x false)
∧-identity : Identity true _∧_
∧-identity = (λ _ → refl) , (λ x → ∧-comm x true)
zero-∧ : Zero false _∧_
zero-∧ = (λ _ → refl) , (λ x → ∧-comm x false)
distrib-∧-∨ : _∧_ DistributesOver _∨_
distrib-∧-∨ = distˡ , distʳ
where
distˡ : _∧_ DistributesOverˡ _∨_
distˡ true y z = refl
distˡ false y z = refl
distʳ : _∧_ DistributesOverʳ _∨_
distʳ x y z =
begin
(y ∨ z) ∧ x
≈⟨ ∧-comm (y ∨ z) x ⟩
x ∧ (y ∨ z)
≈⟨ distˡ x y z ⟩
x ∧ y ∨ x ∧ z
≈⟨ cong₂ _∨_ (∧-comm x y) (∧-comm x z) ⟩
y ∧ x ∨ z ∧ x
∎
isCommutativeSemiring-∨-∧
: IsCommutativeSemiring _≡_ _∨_ _∧_ false true
isCommutativeSemiring-∨-∧ = record
{ isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = record
{ isMonoid = record
{ isSemigroup = record
{ isEquivalence = isEquivalence
; assoc = ∨-assoc
; ∙-pres-≈ = cong₂ _∨_
}
; identity = ∨-identity
}
; comm = ∨-comm
}
; *-isMonoid = record
{ isSemigroup = record
{ isEquivalence = isEquivalence
; assoc = ∧-assoc
; ∙-pres-≈ = cong₂ _∧_
}
; identity = ∧-identity
}
; distrib = distrib-∧-∨
}
; zero = zero-∧
}
; *-comm = ∧-comm
}
commutativeSemiring-∨-∧ : CommutativeSemiring
commutativeSemiring-∨-∧ = record
{ _+_ = _∨_
; _*_ = _∧_
; 0# = false
; 1# = true
; isCommutativeSemiring = isCommutativeSemiring-∨-∧
}
module RingSolver =
Solver (ACR.fromCommutativeSemiring commutativeSemiring-∨-∧)
------------------------------------------------------------------------
-- (Bool, ∧, ∨, true, false) forms a commutative semiring
private
zero-∨ : Zero true _∨_
zero-∨ = (λ _ → refl) , (λ x → ∨-comm x true)
distrib-∨-∧ : _∨_ DistributesOver _∧_
distrib-∨-∧ = distˡ , distʳ
where
distˡ : _∨_ DistributesOverˡ _∧_
distˡ true y z = refl
distˡ false y z = refl
distʳ : _∨_ DistributesOverʳ _∧_
distʳ x y z =
begin
(y ∧ z) ∨ x
≈⟨ ∨-comm (y ∧ z) x ⟩
x ∨ (y ∧ z)
≈⟨ distˡ x y z ⟩
(x ∨ y) ∧ (x ∨ z)
≈⟨ cong₂ _∧_ (∨-comm x y) (∨-comm x z) ⟩
(y ∨ x) ∧ (z ∨ x)
∎
isCommutativeSemiring-∧-∨
: IsCommutativeSemiring _≡_ _∧_ _∨_ true false
isCommutativeSemiring-∧-∨ = record
{ isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = record
{ isMonoid = record
{ isSemigroup = record
{ isEquivalence = isEquivalence
; assoc = ∧-assoc
; ∙-pres-≈ = cong₂ _∧_
}
; identity = ∧-identity
}
; comm = ∧-comm
}
; *-isMonoid = record
{ isSemigroup = record
{ isEquivalence = isEquivalence
; assoc = ∨-assoc
; ∙-pres-≈ = cong₂ _∨_
}
; identity = ∨-identity
}
; distrib = distrib-∨-∧
}
; zero = zero-∨
}
; *-comm = ∨-comm
}
commutativeSemiring-∧-∨ : CommutativeSemiring
commutativeSemiring-∧-∨ = record
{ _+_ = _∧_
; _*_ = _∨_
; 0# = true
; 1# = false
; isCommutativeSemiring = isCommutativeSemiring-∧-∨
}
------------------------------------------------------------------------
-- (Bool, ∨, ∧, not, true, false) is a boolean algebra
private
absorptive : Absorptive _∨_ _∧_
absorptive = abs-∨-∧ , abs-∧-∨
where
abs-∨-∧ : _∨_ Absorbs _∧_
abs-∨-∧ true y = refl
abs-∨-∧ false y = refl
abs-∧-∨ : _∧_ Absorbs _∨_
abs-∧-∨ true y = refl
abs-∧-∨ false y = refl
not-∧-inverse : Inverse false not _∧_
not-∧-inverse =
¬x∧x≡⊥ , (λ x → ∧-comm x (not x) ⟨ trans ⟩ ¬x∧x≡⊥ x)
where
¬x∧x≡⊥ : LeftInverse false not _∧_
¬x∧x≡⊥ false = refl
¬x∧x≡⊥ true = refl
not-∨-inverse : Inverse true not _∨_
not-∨-inverse =
¬x∨x≡⊤ , (λ x → ∨-comm x (not x) ⟨ trans ⟩ ¬x∨x≡⊤ x)
where
¬x∨x≡⊤ : LeftInverse true not _∨_
¬x∨x≡⊤ false = refl
¬x∨x≡⊤ true = refl
isBooleanAlgebra : IsBooleanAlgebra _≡_ _∨_ _∧_ not true false
isBooleanAlgebra = record
{ isDistributiveLattice = record
{ isLattice = record
{ isEquivalence = isEquivalence
; ∨-comm = ∨-comm
; ∨-assoc = ∨-assoc
; ∨-pres-≈ = cong₂ _∨_
; ∧-comm = ∧-comm
; ∧-assoc = ∧-assoc
; ∧-pres-≈ = cong₂ _∧_
; absorptive = absorptive
}
; ∨-∧-distribʳ = proj₂ distrib-∨-∧
}
; ∨-complementʳ = proj₂ not-∨-inverse
; ∧-complementʳ = proj₂ not-∧-inverse
; ¬-pres-≈ = cong not
}
booleanAlgebra : BooleanAlgebra
booleanAlgebra = record
{ _∨_ = _∨_
; _∧_ = _∧_
; ¬_ = not
; ⊤ = true
; ⊥ = false
; isBooleanAlgebra = isBooleanAlgebra
}
------------------------------------------------------------------------
-- (Bool, xor, ∧, id, false, true) forms a commutative ring
private
xor-is-ok : ∀ x y → x xor y ≡ (x ∨ y) ∧ not (x ∧ y)
xor-is-ok true y = refl
xor-is-ok false y = sym $ proj₂ ∧-identity _
commutativeRing-xor-∧ : CommutativeRing
commutativeRing-xor-∧ = commutativeRing
where
import Algebra.Props.BooleanAlgebra as BA
open BA booleanAlgebra
open XorRing _xor_ xor-is-ok
module XorRingSolver =
Solver (ACR.fromCommutativeRing commutativeRing-xor-∧)
------------------------------------------------------------------------
-- Miscellaneous other properties
not-involutive : Involutive not
not-involutive true = refl
not-involutive false = refl
not-¬ : ∀ {x y} → x ≡ y → x ≢ not y
not-¬ {true} refl ()
not-¬ {false} refl ()
¬-not : ∀ {x y} → x ≢ y → x ≡ not y
¬-not {true} {true} x≢y = ⊥-elim (x≢y refl)
¬-not {true} {false} _ = refl
¬-not {false} {true} _ = refl
¬-not {false} {false} x≢y = ⊥-elim (x≢y refl)
⇔→≡ : {b₁ b₂ b : Bool} → b₁ ≡ b ⇔ b₂ ≡ b → b₁ ≡ b₂
⇔→≡ {true } {true } hyp = refl
⇔→≡ {true } {false} {true } hyp = sym (proj₁ hyp refl)
⇔→≡ {true } {false} {false} hyp = proj₂ hyp refl
⇔→≡ {false} {true } {true } hyp = proj₂ hyp refl
⇔→≡ {false} {true } {false} hyp = sym (proj₁ hyp refl)
⇔→≡ {false} {false} hyp = refl
T-≡ : ∀ {b} → T b ⇔ b ≡ true
T-≡ {false} = ((λ ()) , λ ())
T-≡ {true} = (const refl , const _)
T-∧ : ∀ {b₁ b₂} → T (b₁ ∧ b₂) ⇔ (T b₁ × T b₂)
T-∧ {true} {true} = (const (_ , _) , const _)
T-∧ {true} {false} = ((λ ()) , proj₂)
T-∧ {false} {_} = ((λ ()) , proj₁)
T-∨ : ∀ {b₁ b₂} → T (b₁ ∨ b₂) ⇔ (T b₁ ⊎ T b₂)
T-∨ {true} {b₂} = (inj₁ , const _)
T-∨ {false} {true} = (inj₂ , const _)
T-∨ {false} {false} = (inj₁ , [ id , id ])
proof-irrelevance : ∀ {b} (p q : T b) → p ≡ q
proof-irrelevance {true} _ _ = refl
proof-irrelevance {false} () ()
|
{
"alphanum_fraction": 0.4853727945,
"avg_line_length": 27.9777070064,
"ext": "agda",
"hexsha": "ff302cc54a9b232de33e9af9ee84dde7a32ad525",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/Bool/Properties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/Bool/Properties.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/Bool/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 3184,
"size": 8785
}
|
------------------------------------------------------------------------
-- Syntax of Fω with interval kinds
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module FOmegaInt.Syntax where
open import Algebra using (Monoid)
import Data.Context as Context
open import Data.Context.Properties
open import Data.Fin using (Fin; suc; zero)
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Nat using (ℕ; suc; zero)
open import Data.Product using (proj₂)
open import Data.Vec as Vec using ([]; _∷_)
open import Data.List as List using (List; []; _∷_; foldl; map; _++_; _∷ʳ_)
open import Data.List.Properties using (++-monoid)
import Data.Maybe as Maybe
open import Function using (_∘_)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive using (ε; _◅_)
open import Relation.Binary.PropositionalEquality as P hiding ([_])
open P.≡-Reasoning
----------------------------------------------------------------------
-- Raw terms: untyped syntax of terms, types and kinds.
-- NOTE 1. Following the style of Pure Type System (PTS), we define
-- raw (i.e. untyped/unkinded) terms and types as a single syntactic
-- category rather than distinguishing them syntactically.
-- Concretely, we use the singe datatype Term to represent raw terms
-- and types. This simplifies the definition of substitution in types
-- and terms as we don't need to distinguish between type and term
-- variables. The difference between terms and types becomes manifest
-- only later in (sub-)typing and (sub-)kinding judgments. However,
-- unlike PTS, we *do* treat kinds as a separate syntactic
-- category/datatype because there are no kind variables. This
-- simplifies some definitions and proofs that rely on the syntactic
-- structure of kinds (e.g. kind simplification and related
-- properties).
--
-- NOTE 2. We use well-scoped de Bruijn indexing to represent term
-- and type variables in raw terms/types. The datatype `Term' is
-- indexed by the number of free variables its inhabitants may
-- contain, i.e. given a raw term
--
-- a : Term n
--
-- the set of "names" that may appear in `a' is
--
-- { 0, 1, ..., n-1 }.
--
-- Binders extend this set by increasing n by one for each fresh name
-- they introduce. This ensures that raw terms are intrinsically
-- well-scoped. This representation was adapted from previous Agda
-- formalizations of typed lambda calculi by Danielsson and others [1,
-- 2] and comes with some support in the Agda standard library. See
-- Data.Fin.Substitution.Example for a simple example.
--
-- [1] N. A. Danielsson and T. Altenkirch, "Subtyping, Declaratively
-- An Exercise in Mixed Induction and Coinduction", Proc. MPC
-- 2010.
--
-- [2] N. A. Danielsson, "Operational Semantics Using the Partiality
-- Monad", Proc. ICFP 2012.
module Syntax where
infixl 9 _·_ _⊡_ _⊡∙_
infixr 7 _⇒_ _⇒∙_
infix 6 _⋯_
-- Raw, T-dependent kinds with up to n free variables.
data Kind (T : ℕ → Set) (n : ℕ) : Set where
_⋯_ : (a b : T n) → Kind T n -- interval
Π : (j : Kind T n) (k : Kind T (suc n)) → Kind T n -- dependent arrow
-- Raw terms and types with up to n free variables.
--
-- NOTE. The type instantiation operator _⊡_ should be considered
-- specialized variant of the application operator _·_. The reason
-- for including a dedicated _⊡_ constructor is to distinguish term
-- applications from type applications/instantiations in CBV
-- reductions (see FOmegaInt.Reduction.Cbv). Without the special
-- treatment of type instantiation, CBV reduction would permit
-- reduction of type arguments before contraction. Not only is this
-- counter to the usual CBV semantics for Fω (see e.g. TAPL p. 450),
-- but it would require a proof of subject reduction (aka
-- preservation) for kinding in order to prove preservation of
-- typing even under CBV reduction. By adopting the usual CBV
-- semantics, this dependency can be avoided. See
-- FOmegaInt.Typing.Preservation for a proof of subject reduction
-- for typing using the usual CBV semantics.
data Term (n : ℕ) : Set where
var : (x : Fin n) → Term n -- variable
⊥ : Term n -- bottom (minimum)
⊤ : Term n -- top (maximum)
Π : (k : Kind Term n) (a : Term (suc n)) → Term n -- universal quant.
_⇒_ : (a b : Term n) → Term n -- arrow
Λ : (k : Kind Term n) (a : Term (suc n)) → Term n -- type abstraction
ƛ : (a : Term n) (b : Term (suc n)) → Term n -- term abstraction
_⊡_ : (a b : Term n) → Term n -- type instantiation
_·_ : (a b : Term n) → Term n -- term application
-- A shorthand for the kind of proper types.
* : ∀ {n} → Kind Term n
* = ⊥ ⋯ ⊤
infixl 9 _∙_
-- Raw terms and types in spine form.
--
-- Spine form is an alternative representation of raw terms where
-- the arguments of consecutive applications are grouped together
-- into sequences of arguments called "spines". This representation
-- is better suited for the definition of "hereditary substitution"
-- (see Syntax.HereditarySubstitution) and canonical kinding (see
-- Kinding.Canonical). The two representations are isomorphic, as
-- witnessed by ⌜⌝∘⌞⌟-id and ⌞⌟∘⌜⌝-id below.
--
-- NOTE. Below, we consider type instantiations (a ⊡ b) as heads
-- rather than eliminations, despite the fact that, semantically,
-- they are elimination forms. However, for the purpose of
-- hereditary substitution we will ignore their semantics and treat
-- _⊡_ as an uninterpreted binary operation. This is justified by
-- the fact that *well-kinded* hereditary substitution is only
-- defined on (well-kinded) types, in which _⊡_ cannot appear.
--
-- One may wonder: why include constructors for term-level forms
-- such as ƛ or _⊡_ in this presentation of the syntax if it is only
-- used to define type-level hereditary substitution? The answer is
-- that we often rely on the two presentations of the syntax being
-- isomorphic to switch between them without loss of generality. If
-- we only included type formers, we could not prove this
-- isomorphism. Including the term formers thus adds a bit of
-- overhead but simplifies things over all.
mutual
-- Eliminations are applications of (possibly empty) sequences of
-- arguments to heads.
data Elim (n : ℕ) : Set where
_∙_ : (a : Head n) (as : Spine n) → Elim n -- application
-- Heads are those terms that are not eliminations.
data Head (n : ℕ) : Set where
var : (x : Fin n) → Head n -- variable
⊥ : Head n -- bottom (minimum)
⊤ : Head n -- top (maximum)
Π : (k : Kind Elim n) (a : Elim (suc n)) → Head n -- universal
_⇒_ : (a b : Elim n) → Head n -- arrow
Λ : (k : Kind Elim n) (a : Elim (suc n)) → Head n -- type abstraction
ƛ : (a : Elim n) (b : Elim (suc n)) → Head n -- term abstraction
_⊡_ : (a b : Elim n) → Head n -- type inst.
-- Spines are (possibly empty) sequences of eliminations.
Spine : ℕ → Set
Spine n = List (Elim n)
-- Projections.
headOf : ∀ {n} → Elim n → Head n
headOf (a ∙ as) = a
spineOf : ∀ {n} → Elim n → Spine n
spineOf (a ∙ as) = as
infixl 9 _⌜·⌝_ _⌞∙⌟_ _∙∙_
-- Post-application of spines and eliminations to eliminations.
_∙∙_ : ∀ {n} → Elim n → Spine n → Elim n
a ∙ as ∙∙ bs = a ∙ (as ++ bs)
_⌜·⌝_ : ∀ {n} → Elim n → Elim n → Elim n
a ⌜·⌝ b = a ∙∙ (b ∷ [])
-- Application of term sequences to terms.
_⌞∙⌟_ : ∀ {n} → Term n → List (Term n) → Term n
a ⌞∙⌟ as = foldl _·_ a as
-- Shorthands for "unapplied" term/type constructors.
var∙ : ∀ {n} → Fin n → Elim n
var∙ x = var x ∙ []
⊥∙ : ∀ {n} → Elim n
⊥∙ = ⊥ ∙ []
⊤∙ : ∀ {n} → Elim n
⊤∙ = ⊤ ∙ []
∀∙ : ∀ {n} → Kind Elim n → Elim (suc n) → Elim n
∀∙ k a = Π k a ∙ []
_⇒∙_ : ∀ {n} → Elim n → Elim n → Elim n
a ⇒∙ b = (a ⇒ b) ∙ []
Λ∙ : ∀ {n} → Kind Elim n → Elim (suc n) → Elim n
Λ∙ k a = Λ k a ∙ []
ƛ∙ : ∀ {n} → Elim n → Elim (suc n) → Elim n
ƛ∙ a b = ƛ a b ∙ []
_⊡∙_ : ∀ {n} → Elim n → Elim n → Elim n
a ⊡∙ b = (a ⊡ b) ∙ []
⌜*⌝ : ∀ {n} → Kind Elim n
⌜*⌝ = ⊥∙ ⋯ ⊤∙
-- Conversions between the two representations.
mutual
-- Turn raw eliminations into raw terms.
⌞_⌟ : ∀ {n} → Elim n → Term n
⌞ a ∙ as ⌟ = ⌞ a ⌟Hd ⌞∙⌟ ⌞ as ⌟Sp
⌞_⌟Kd : ∀ {n} → Kind Elim n → Kind Term n
⌞ a ⋯ b ⌟Kd = ⌞ a ⌟ ⋯ ⌞ b ⌟
⌞ Π j k ⌟Kd = Π ⌞ j ⌟Kd ⌞ k ⌟Kd
⌞_⌟Sp : ∀ {n} → Spine n → List (Term n)
⌞ [] ⌟Sp = []
⌞ a ∷ as ⌟Sp = ⌞ a ⌟ ∷ ⌞ as ⌟Sp
⌞_⌟Hd : ∀ {n} → Head n → Term n
⌞ var x ⌟Hd = var x
⌞ ⊥ ⌟Hd = ⊥
⌞ ⊤ ⌟Hd = ⊤
⌞ Π k a ⌟Hd = Π ⌞ k ⌟Kd ⌞ a ⌟
⌞ a ⇒ b ⌟Hd = ⌞ a ⌟ ⇒ ⌞ b ⌟
⌞ Λ k a ⌟Hd = Λ ⌞ k ⌟Kd ⌞ a ⌟
⌞ ƛ a b ⌟Hd = ƛ ⌞ a ⌟ ⌞ b ⌟
⌞ a ⊡ b ⌟Hd = ⌞ a ⌟ ⊡ ⌞ b ⌟
mutual
-- Turn raw terms into raw eliminations.
⌜_⌝ : ∀ {n} → Term n → Elim n
⌜ var x ⌝ = var x ∙ []
⌜ ⊥ ⌝ = ⊥∙
⌜ ⊤ ⌝ = ⊤∙
⌜ Π k a ⌝ = ∀∙ ⌜ k ⌝Kd ⌜ a ⌝
⌜ a ⇒ b ⌝ = ⌜ a ⌝ ⇒∙ ⌜ b ⌝
⌜ Λ k a ⌝ = Λ∙ ⌜ k ⌝Kd ⌜ a ⌝
⌜ ƛ a b ⌝ = ƛ∙ ⌜ a ⌝ ⌜ b ⌝
⌜ a ⊡ b ⌝ = ⌜ a ⌝ ⊡∙ ⌜ b ⌝
⌜ a · b ⌝ = ⌜ a ⌝ ⌜·⌝ ⌜ b ⌝
⌜_⌝Kd : ∀ {n} → Kind Term n → Kind Elim n
⌜ a ⋯ b ⌝Kd = ⌜ a ⌝ ⋯ ⌜ b ⌝
⌜ Π j k ⌝Kd = Π ⌜ j ⌝Kd ⌜ k ⌝Kd
-- Shapes (aka simple kinds).
data SKind : Set where
★ : SKind
_⇒_ : SKind → SKind → SKind
-- Kind simplification (aka erasure from kinds to shapes).
⌊_⌋ : ∀ {T n} → Kind T n → SKind
⌊ a ⋯ b ⌋ = ★
⌊ Π j k ⌋ = ⌊ j ⌋ ⇒ ⌊ k ⌋
-- A wrapper for raw kind or type ascriptions.
data KdOrTp (T : ℕ → Set) (n : ℕ) : Set where
kd : Kind T n → KdOrTp T n
tp : T n → KdOrTp T n
TermAsc = KdOrTp Term
ElimAsc = KdOrTp Elim
⌞_⌟Asc : ∀ {n} → ElimAsc n → TermAsc n
⌞ kd k ⌟Asc = kd ⌞ k ⌟Kd
⌞ tp a ⌟Asc = tp ⌞ a ⌟
⌜_⌝Asc : ∀ {n} → TermAsc n → ElimAsc n
⌜ kd k ⌝Asc = kd ⌜ k ⌝Kd
⌜ tp a ⌝Asc = tp ⌜ a ⌝
open Syntax
----------------------------------------------------------------------
-- Some properties of raw terms and kinds
-- The kd constructor is injective.
kd-inj : ∀ {T n} {j k : Kind T n} → kd j ≡ kd k → j ≡ k
kd-inj refl = refl
-- Extensionality of eliminations.
∙-ext : ∀ {n} (a : Elim n) → headOf a ∙ spineOf a ≡ a
∙-ext (a ∙ as) = refl
-- The empty spine is a right unit of _∙∙_
∙∙-[] : ∀ {n} (a : Elim n) → a ∙∙ [] ≡ a
∙∙-[] (a ∙ as) = cong (a ∙_) (proj₂ identity as)
where open Monoid (++-monoid (Elim _)) hiding (_∙_)
-- Spine application commutes with spine concatenation.
∙∙-++ : ∀ {n} (a : Elim n) bs cs → a ∙∙ bs ∙∙ cs ≡ a ∙∙ (bs ++ cs)
∙∙-++ (a ∙ as) bs cs = cong (a ∙_) (assoc as bs cs)
where open Monoid (++-monoid (Elim _)) hiding (_∙_)
-- Spine application can be expressed as a left fold.
∙∙IsFold : ∀ {n} (a : Elim n) bs → a ∙∙ bs ≡ foldl _⌜·⌝_ a bs
∙∙IsFold (a ∙ as) [] = ∙∙-[] (a ∙ as)
∙∙IsFold (a ∙ as) (b ∷ bs) = begin
a ∙ (as ++ b ∷ bs)
≡⟨ sym (∙∙-++ (a ∙ as) (b ∷ []) bs) ⟩
a ∙ ((as ∷ʳ b) ++ bs)
≡⟨ ∙∙IsFold (a ∙ (as ∷ʳ b)) bs ⟩
foldl _⌜·⌝_ (a ∙ (as ∷ʳ b)) bs
∎
-- Conversion to raw terms commutes with (post-)application.
⌞⌟-· : ∀ {n} (a : Elim n) b → ⌞ a ⌜·⌝ b ⌟ ≡ ⌞ a ⌟ · ⌞ b ⌟
⌞⌟-· (a ∙ as) b = helper as b
where
helper : ∀ {n} {a : Term n} bs c →
a ⌞∙⌟ ⌞ bs ∷ʳ c ⌟Sp ≡ a ⌞∙⌟ ⌞ bs ⌟Sp · ⌞ c ⌟
helper [] c = refl
helper (b ∷ bs) c = helper bs c
⌞⌟-∙∙ : ∀ {n} (a : Elim n) bs → ⌞ a ∙∙ bs ⌟ ≡ ⌞ a ⌟ ⌞∙⌟ ⌞ bs ⌟Sp
⌞⌟-∙∙ a [] = cong ⌞_⌟ (∙∙-[] a)
⌞⌟-∙∙ a (b ∷ bs) = begin
⌞ a ∙∙ (b ∷ bs) ⌟ ≡⟨ sym (cong ⌞_⌟ (∙∙-++ a (b ∷ []) bs)) ⟩
⌞ a ∙∙ (b ∷ []) ∙∙ bs ⌟ ≡⟨ ⌞⌟-∙∙ (a ∙∙ (b ∷ [])) bs ⟩
⌞ a ∙∙ (b ∷ []) ⌟ ⌞∙⌟ ⌞ bs ⌟Sp ≡⟨ cong (_⌞∙⌟ ⌞ bs ⌟Sp) (⌞⌟-· a b) ⟩
⌞ a ⌟ · ⌞ b ⌟ ⌞∙⌟ ⌞ bs ⌟Sp ∎
-- Conversion to eliminations commutes with spine application.
⌜⌝-∙ : ∀ {n} (a : Term n) bs → ⌜ a ⌞∙⌟ bs ⌝ ≡ ⌜ a ⌝ ∙∙ map ⌜_⌝ bs
⌜⌝-∙ a bs = begin
⌜ a ⌞∙⌟ bs ⌝ ≡⟨ helper a bs ⟩
foldl _⌜·⌝_ ⌜ a ⌝ (map ⌜_⌝ bs) ≡⟨ sym (∙∙IsFold ⌜ a ⌝ (map ⌜_⌝ bs)) ⟩
⌜ a ⌝ ∙∙ map ⌜_⌝ bs ∎
where
helper : ∀ {n} (a : Term n) bs →
⌜ a ⌞∙⌟ bs ⌝ ≡ foldl _⌜·⌝_ ⌜ a ⌝ (map ⌜_⌝ bs)
helper a [] = refl
helper a (b ∷ bs) = helper (a · b) bs
-- The two representations of raw terms are isomorphic.
mutual
⌞⌟∘⌜⌝-id : ∀ {n} (a : Term n) → ⌞ ⌜ a ⌝ ⌟ ≡ a
⌞⌟∘⌜⌝-id (var x) = refl
⌞⌟∘⌜⌝-id ⊥ = refl
⌞⌟∘⌜⌝-id ⊤ = refl
⌞⌟∘⌜⌝-id (Π k a) = cong₂ Π (⌞⌟Kd∘⌜⌝Kd-id k) (⌞⌟∘⌜⌝-id a)
⌞⌟∘⌜⌝-id (a ⇒ b) = cong₂ _⇒_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)
⌞⌟∘⌜⌝-id (Λ k a) = cong₂ Λ (⌞⌟Kd∘⌜⌝Kd-id k) (⌞⌟∘⌜⌝-id a)
⌞⌟∘⌜⌝-id (ƛ a b) = cong₂ ƛ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)
⌞⌟∘⌜⌝-id (a ⊡ b) = cong₂ _⊡_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)
⌞⌟∘⌜⌝-id (a · b) = begin
⌞ ⌜ a ⌝ ⌜·⌝ ⌜ b ⌝ ⌟ ≡⟨ ⌞⌟-· ⌜ a ⌝ ⌜ b ⌝ ⟩
⌞ ⌜ a ⌝ ⌟ · ⌞ ⌜ b ⌝ ⌟ ≡⟨ cong₂ _·_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b) ⟩
a · b ∎
⌞⌟Kd∘⌜⌝Kd-id : ∀ {n} (k : Kind Term n) → ⌞ ⌜ k ⌝Kd ⌟Kd ≡ k
⌞⌟Kd∘⌜⌝Kd-id (a ⋯ b) = cong₂ _⋯_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)
⌞⌟Kd∘⌜⌝Kd-id (Π j k) = cong₂ Π (⌞⌟Kd∘⌜⌝Kd-id j) (⌞⌟Kd∘⌜⌝Kd-id k)
mutual
⌜⌝∘⌞⌟-id : ∀ {n} (a : Elim n) → ⌜ ⌞ a ⌟ ⌝ ≡ a
⌜⌝∘⌞⌟-id (a ∙ bs) = begin
⌜ ⌞ a ⌟Hd ⌞∙⌟ ⌞ bs ⌟Sp ⌝
≡⟨ ⌜⌝-∙ ⌞ a ⌟Hd ⌞ bs ⌟Sp ⟩
⌜ ⌞ a ⌟Hd ⌝ ∙∙ map ⌜_⌝ ⌞ bs ⌟Sp
≡⟨ cong₂ _∙∙_ (⌜⌝∘⌞⌟Hd-∙-[] a) (map-⌜⌝∘⌞⌟Sp-id bs) ⟩
a ∙ [] ∙∙ bs
∎
map-⌜⌝∘⌞⌟Sp-id : ∀ {n} (as : Spine n) → map ⌜_⌝ ⌞ as ⌟Sp ≡ as
map-⌜⌝∘⌞⌟Sp-id [] = refl
map-⌜⌝∘⌞⌟Sp-id (a ∷ as) = cong₂ _∷_ (⌜⌝∘⌞⌟-id a) (map-⌜⌝∘⌞⌟Sp-id as)
⌜⌝∘⌞⌟Hd-∙-[] : ∀ {n} (a : Head n) → ⌜ ⌞ a ⌟Hd ⌝ ≡ a ∙ []
⌜⌝∘⌞⌟Hd-∙-[] (var x) = refl
⌜⌝∘⌞⌟Hd-∙-[] ⊥ = refl
⌜⌝∘⌞⌟Hd-∙-[] ⊤ = refl
⌜⌝∘⌞⌟Hd-∙-[] (Π k a) = cong₂ ∀∙ (⌜⌝Kd∘⌞⌟Kd-id k) (⌜⌝∘⌞⌟-id a)
⌜⌝∘⌞⌟Hd-∙-[] (a ⇒ b) = cong₂ _⇒∙_ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)
⌜⌝∘⌞⌟Hd-∙-[] (Λ k a) = cong₂ Λ∙ (⌜⌝Kd∘⌞⌟Kd-id k) (⌜⌝∘⌞⌟-id a)
⌜⌝∘⌞⌟Hd-∙-[] (ƛ a b) = cong₂ ƛ∙ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)
⌜⌝∘⌞⌟Hd-∙-[] (a ⊡ b) = cong₂ _⊡∙_ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)
⌜⌝Kd∘⌞⌟Kd-id : ∀ {n} (k : Kind Elim n) → ⌜ ⌞ k ⌟Kd ⌝Kd ≡ k
⌜⌝Kd∘⌞⌟Kd-id (a ⋯ b) = cong₂ _⋯_ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)
⌜⌝Kd∘⌞⌟Kd-id (Π j k) = cong₂ Π (⌜⌝Kd∘⌞⌟Kd-id j) (⌜⌝Kd∘⌞⌟Kd-id k)
-- Simplified kinds are stable under conversions of term
-- representation.
⌊⌋-⌜⌝Kd : ∀ {n} (k : Kind Term n) → ⌊ ⌜ k ⌝Kd ⌋ ≡ ⌊ k ⌋
⌊⌋-⌜⌝Kd (a ⋯ b) = refl
⌊⌋-⌜⌝Kd (Π j k) = cong₂ _⇒_ (⌊⌋-⌜⌝Kd j) (⌊⌋-⌜⌝Kd k)
⌊⌋-⌞⌟Kd : ∀ {n} (k : Kind Elim n) → ⌊ ⌞ k ⌟Kd ⌋ ≡ ⌊ k ⌋
⌊⌋-⌞⌟Kd (a ⋯ b) = refl
⌊⌋-⌞⌟Kd (Π j k) = cong₂ _⇒_ (⌊⌋-⌞⌟Kd j) (⌊⌋-⌞⌟Kd k)
----------------------------------------------------------------------
-- Substitutions in raw terms
--
-- We use an intrinsically well-scoped variant of simultaneous
-- substitutions inspired by McBride's technique for defining
-- type-preserving substitutions [3]. These come with some support in
-- the Agda standard library. In particular, the standard library
-- provides generic proofs for a plethora of standard untyped
-- substitution lemmas (e.g. substitutions commute, identity
-- substitutions vanish, etc.) which are easy but tedious to prove
-- (see the Data.Fin.Substitution.Lemmas module). By using this
-- substitution framework, we get those lemmas for "free" (we still
-- need to provide some basic lemmas to bootstrap everything).
--
-- To use the standard framework, we must follow the following four
-- steps.
--
-- 1. We define an application function `t / σ' of generic untyped
-- substitutions `σ' to well-scoped untyped terms `t'. Generic
-- substitutions are defined over an abstract type `T', which will
-- later represent variables (to encode renamings) or terms (to
-- encode actual substitutions). Hence the definition of
-- application must be parametrized over some abstract operations
-- on such substitutions (lifting, weakening, etc.) to be defined
-- later. Concrete instances of these operations are collected in
-- the record `Lift' (see e.g. `SubstApp' module below).
--
-- Along with application, we define a few lemmas to be used in
-- step 4. (They express the fact that application of
-- (multi-)substitutions is compositional w.r.t. the various
-- syntactic forms.)
--
-- 2. Application is instantiated with `T = Fin' to obtain
-- well-scoped renamings, i.e. substitutions of variables in
-- terms. The standard library provides a predefined instance of
-- `Lift Fin Term' to this end.
--
-- 3. Using well-scoped renamings, an instance of `Lift Term Term' is
-- defined, and application is instantiated to concrete
-- substitutions of terms in terms.
--
-- 4. Using the generic lemmas defined in step 1, many helpful
-- derived substitution lemmas are instantiated.
-- (E.g. "substitutions commute", "identity substitutions vanish",
-- etc.)
--
-- Most of the work is done in step 1, while steps 2-3 consists mostly
-- in calls to the substitution API of the Agda standard library.
--
-- [3] C. McBride, "Type-Preserving Renaming and Substitution"
-- http://strictlypositive.org/ren-sub.pdf
-- Application of generic substitutions lifted to type and kind
-- ascriptions.
module KdOrTpSubstApp {T T′ : ℕ → Set} (simple : Simple T)
(kdApp : Application (Kind T′) T)
(tpApp : Application T′ T) where
open Simple simple
open Application kdApp renaming (_/_ to _Kd/_; _/✶_ to _Kd/✶_)
open Application tpApp renaming (_/_ to _Tp/_; _/✶_ to _Tp/✶_)
infixl 8 _/_
-- Apply a substitution to a kind or type ascription.
_/_ : ∀ {m n} → KdOrTp T′ m → Sub T m n → KdOrTp T′ n
(kd k) / σ = kd (k Kd/ σ)
(tp a) / σ = tp (a Tp/ σ)
open Application (record { _/_ = _/_ }) public hiding (_/_)
-- Some helper lemmas about applying sequences of substitutions (to
-- be used for instantiating TermSubstLemmas).
-- Substitutions in kind ascriptions are compositional.
kd-/✶-↑✶ : ∀ k {m n j} (σs : Subs T m n) →
(kd j) /✶ σs ↑✶ k ≡ kd (j Kd/✶ σs ↑✶ k)
kd-/✶-↑✶ k ε = refl
kd-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (kd-/✶-↑✶ k σs) refl
-- Substitutions in type ascriptions are compositional.
tp-/✶-↑✶ : ∀ k {m n a} (σs : Subs T m n) →
(tp a) /✶ σs ↑✶ k ≡ tp (a Tp/✶ σs ↑✶ k)
tp-/✶-↑✶ k ε = refl
tp-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (tp-/✶-↑✶ k σs) refl
-- Application of generic substitutions to terms
module SubstApp {T : ℕ → Set} (l : Lift T Term) where
open Lift l hiding (var)
infixl 8 _/_ _Kind/_ _Elim/_ _Head/_ _//_ _Kind′/_
mutual
-- Apply a substitution to a raw term/type.
_/_ : ∀ {m n} → Term m → Sub T m n → Term n
var x / σ = lift (Vec.lookup σ x)
⊥ / σ = ⊥
⊤ / σ = ⊤
Π k a / σ = Π (k Kind/ σ) (a / σ ↑)
(a ⇒ b) / σ = (a / σ) ⇒ (b / σ)
Λ k a / σ = Λ (k Kind/ σ) (a / σ ↑)
ƛ a b / σ = ƛ (a / σ) (b / σ ↑)
a · b / σ = (a / σ) · (b / σ)
a ⊡ b / σ = (a / σ) ⊡ (b / σ)
-- Apply a substitution to a kind.
_Kind/_ : ∀ {m n} → Kind Term m → Sub T m n → Kind Term n
(a ⋯ b) Kind/ σ = (a / σ) ⋯ (b / σ)
Π j k Kind/ σ = Π (j Kind/ σ) (k Kind/ σ ↑)
mutual
-- Apply a substitution to an elimination.
_Elim/_ : ∀ {m n} → Elim m → Sub T m n → Elim n
a ∙ as Elim/ σ = (a Head/ σ) ∙∙ (as // σ)
-- Apply a substitution to a head.
_Head/_ : ∀ {m n} → Head m → Sub T m n → Elim n
var x Head/ σ = ⌜ lift (Vec.lookup σ x) ⌝
⊥ Head/ σ = ⊥∙
⊤ Head/ σ = ⊤∙
Π k a Head/ σ = ∀∙ (k Kind′/ σ) (a Elim/ σ ↑)
(a ⇒ b) Head/ σ = (a Elim/ σ) ⇒∙ (b Elim/ σ)
Λ k a Head/ σ = Λ∙ (k Kind′/ σ) (a Elim/ σ ↑)
ƛ a b Head/ σ = ƛ∙ (a Elim/ σ) (b Elim/ σ ↑)
a ⊡ b Head/ σ = (a Elim/ σ) ⊡∙ (b Elim/ σ)
-- Apply a substitution to a spine.
_//_ : ∀ {m n} → Spine m → Sub T m n → Spine n
[] // σ = []
(a ∷ as) // σ = a Elim/ σ ∷ as // σ
-- Apply a substitution to a (elimination-based) kind.
_Kind′/_ : ∀ {m n} → Kind Elim m → Sub T m n → Kind Elim n
(a ⋯ b) Kind′/ σ = (a Elim/ σ) ⋯ (b Elim/ σ)
Π j k Kind′/ σ = Π (j Kind′/ σ) (k Kind′/ σ ↑)
private
appTerm = record { _/_ = _/_ }
appKind = record { _/_ = _Kind/_ }
appElim = record { _/_ = _Elim/_ }
appKind′ = record { _/_ = _Kind′/_ }
-- Some helper lemmas about applying sequences of substitutions (to
-- be used for instantiating TermSubstLemmas).
open Application appTerm hiding (_/_)
open Application appKind using () renaming (_/✶_ to _Kind/✶_)
-- The bottom and top types are invariant under substitution.
⊥-/✶-↑✶ : ∀ k {m n} (σs : Subs T m n) → ⊥ /✶ σs ↑✶ k ≡ ⊥
⊥-/✶-↑✶ k ε = refl
⊥-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⊥-/✶-↑✶ k σs) refl
⊤-/✶-↑✶ : ∀ k {m n} (σs : Subs T m n) → ⊤ /✶ σs ↑✶ k ≡ ⊤
⊤-/✶-↑✶ k ε = refl
⊤-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⊤-/✶-↑✶ k σs) refl
-- Substitutions in the remaining term and type formers are
-- compositional.
Π-/✶-↑✶ : ∀ k {m n j a} (σs : Subs T m n) →
(Π j a) /✶ σs ↑✶ k ≡ Π (j Kind/✶ σs ↑✶ k) (a /✶ σs ↑✶ suc k)
Π-/✶-↑✶ k ε = refl
Π-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (Π-/✶-↑✶ k σs) refl
⇒-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →
(a ⇒ b) /✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) ⇒ (b /✶ σs ↑✶ k)
⇒-/✶-↑✶ k ε = refl
⇒-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⇒-/✶-↑✶ k σs) refl
Λ-/✶-↑✶ : ∀ k {m n j a} (σs : Subs T m n) →
(Λ j a) /✶ σs ↑✶ k ≡ Λ (j Kind/✶ σs ↑✶ k) (a /✶ σs ↑✶ suc k)
Λ-/✶-↑✶ k ε = refl
Λ-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (Λ-/✶-↑✶ k σs) refl
ƛ-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →
(ƛ a b) /✶ σs ↑✶ k ≡ ƛ (a /✶ σs ↑✶ k) (b /✶ σs ↑✶ suc k)
ƛ-/✶-↑✶ k ε = refl
ƛ-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (ƛ-/✶-↑✶ k σs) refl
·-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →
(a · b) /✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) · (b /✶ σs ↑✶ k)
·-/✶-↑✶ k ε = refl
·-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (·-/✶-↑✶ k σs) refl
⊡-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →
(a ⊡ b) /✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) ⊡ (b /✶ σs ↑✶ k)
⊡-/✶-↑✶ k ε = refl
⊡-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⊡-/✶-↑✶ k σs) refl
-- Substitutions in the kind formers are compositional.
Π-Kind/✶-↑✶ : ∀ k {m n j l} (σs : Subs T m n) →
(Π j l) Kind/✶ σs ↑✶ k ≡
Π (j Kind/✶ σs ↑✶ k) (l Kind/✶ σs ↑✶ (suc k))
Π-Kind/✶-↑✶ k ε = refl
Π-Kind/✶-↑✶ k (σ ◅ σs) = cong₂ _Kind/_ (Π-Kind/✶-↑✶ k σs) refl
⋯-Kind/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →
(a ⋯ b) Kind/✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) ⋯ (b /✶ σs ↑✶ k)
⋯-Kind/✶-↑✶ k ε = refl
⋯-Kind/✶-↑✶ k (σ ◅ σs) = cong₂ _Kind/_ (⋯-Kind/✶-↑✶ k σs) refl
-- Application of substitutions commutes with concatenation of spines.
++-// : ∀ {m n} (as bs : Spine m) {σ : Sub T m n} →
(as ++ bs) // σ ≡ as // σ ++ bs // σ
++-// [] bs = refl
++-// (a ∷ as) bs = cong (a Elim/ _ ∷_) (++-// as bs)
-- Application of substitutions commutes application of spines and
-- eliminations.
∙∙-/ : ∀ {m n} a (as : Spine m) {σ : Sub T m n} →
a ∙∙ as Elim/ σ ≡ (a Elim/ σ) ∙∙ (as // σ)
∙∙-/ (a ∙ as) bs = begin
(a Head/ _) ∙∙ ((as ++ bs) // _)
≡⟨ cong (_ ∙∙_) (++-// as bs) ⟩
(a Head/ _) ∙∙ (as // _ ++ bs // _)
≡⟨ sym (∙∙-++ _ (as // _) (bs // _)) ⟩
(a Head/ _) ∙∙ (as // _) ∙∙ (bs // _)
∎
⌜·⌝-/ : ∀ {m n} (a b : Elim m) {σ : Sub T m n} →
a ⌜·⌝ b Elim/ σ ≡ (a Elim/ σ) ⌜·⌝ (b Elim/ σ)
⌜·⌝-/ (a ∙ as) b {σ} = begin
(a Head/ σ) ∙∙ ((as ∷ʳ b) // σ)
≡⟨ cong ((a Head/ σ) ∙∙_) (++-// as (b ∷ [])) ⟩
(a Head/ σ) ∙∙ (as // σ ++ (b ∷ []) // σ)
≡⟨ sym (∙∙-++ (a Head/ σ) (as // σ) ((b ∷ []) // σ)) ⟩
(a Head/ σ) ∙∙ (as // σ) ∙∙ ((b ∷ []) // σ)
≡⟨ ∙∙IsFold ((a Head/ σ) ∙∙ (as // σ)) ((b ∷ []) // σ) ⟩
(a Head/ σ) ∙∙ (as // σ) ⌜·⌝ (b Elim/ σ)
∎
-- Application of substitutions commutes with the conversions.
mutual
⌜⌝-/ : ∀ {m n} a {σ : Sub T m n} → ⌜ a / σ ⌝ ≡ ⌜ a ⌝ Elim/ σ
⌜⌝-/ (var x) = sym (∙∙-[] _)
⌜⌝-/ ⊥ = refl
⌜⌝-/ ⊤ = refl
⌜⌝-/ (Π k a) = cong₂ ∀∙ (⌜⌝Kd-/ k) (⌜⌝-/ a)
⌜⌝-/ (a ⇒ b) = cong₂ _⇒∙_ (⌜⌝-/ a) (⌜⌝-/ b)
⌜⌝-/ (Λ k a) = cong₂ Λ∙ (⌜⌝Kd-/ k) (⌜⌝-/ a)
⌜⌝-/ (ƛ a b) = cong₂ ƛ∙ (⌜⌝-/ a) (⌜⌝-/ b)
⌜⌝-/ (a · b) {σ} = begin
⌜ a / σ ⌝ ⌜·⌝ ⌜ b / σ ⌝ ≡⟨ cong₂ _⌜·⌝_ (⌜⌝-/ a) (⌜⌝-/ b) ⟩
(⌜ a ⌝ Elim/ σ) ⌜·⌝ (⌜ b ⌝ Elim/ σ) ≡⟨ sym (⌜·⌝-/ ⌜ a ⌝ ⌜ b ⌝) ⟩
⌜ a ⌝ ⌜·⌝ ⌜ b ⌝ Elim/ σ ∎
⌜⌝-/ (a ⊡ b) = cong₂ _⊡∙_ (⌜⌝-/ a) (⌜⌝-/ b)
⌜⌝Kd-/ : ∀ {m n} k {σ : Sub T m n} → ⌜ k Kind/ σ ⌝Kd ≡ ⌜ k ⌝Kd Kind′/ σ
⌜⌝Kd-/ (a ⋯ b) = cong₂ _⋯_ (⌜⌝-/ a) (⌜⌝-/ b)
⌜⌝Kd-/ (Π j k) = cong₂ Π (⌜⌝Kd-/ j) (⌜⌝Kd-/ k)
⌞⌟-/ : ∀ {m n} a {σ : Sub T m n} → ⌞ a Elim/ σ ⌟ ≡ ⌞ a ⌟ / σ
⌞⌟-/ a {σ} = begin
⌞ a Elim/ σ ⌟ ≡⟨ cong (⌞_⌟ ∘ (_Elim/ σ)) (sym (⌜⌝∘⌞⌟-id a)) ⟩
⌞ ⌜ ⌞ a ⌟ ⌝ Elim/ σ ⌟ ≡⟨ cong ⌞_⌟ (sym (⌜⌝-/ ⌞ a ⌟)) ⟩
⌞ ⌜ ⌞ a ⌟ / σ ⌝ ⌟ ≡⟨ ⌞⌟∘⌜⌝-id (⌞ a ⌟ / σ) ⟩
⌞ a ⌟ / σ ∎
⌞⌟Kd-/ : ∀ {m n} k {σ : Sub T m n} → ⌞ k Kind′/ σ ⌟Kd ≡ ⌞ k ⌟Kd Kind/ σ
⌞⌟Kd-/ (a ⋯ b) = cong₂ _⋯_ (⌞⌟-/ a) (⌞⌟-/ b)
⌞⌟Kd-/ (Π j k) = cong₂ Π (⌞⌟Kd-/ j) (⌞⌟Kd-/ k)
open Application appElim using () renaming (_/✶_ to _Elim/✶_)
open Application appKind′ using () renaming (_/✶_ to _Kind′/✶_)
-- Application of multiple substitutions commutes with conversion to
-- eliminations.
⌜⌝-/✶-↑✶ : ∀ k {m n a} (σs : Subs T m n) →
⌜ a /✶ σs ↑✶ k ⌝ ≡ ⌜ a ⌝ Elim/✶ σs ↑✶ k
⌜⌝-/✶-↑✶ k ε = refl
⌜⌝-/✶-↑✶ k (σ ◅ σs) = begin
⌜ _ /✶ (σ ◅ σs) ↑✶ k ⌝ ≡⟨ ⌜⌝-/ (_ /✶ σs ↑✶ k) ⟩
⌜ _ /✶ σs ↑✶ k ⌝ Elim/ σ ↑⋆ k ≡⟨ cong (_Elim/ _) (⌜⌝-/✶-↑✶ k σs) ⟩
_ Elim/✶ (σ ◅ σs) ↑✶ k ∎
⌜⌝Kd-/✶-↑✶ : ∀ k {m n j} (σs : Subs T m n) →
⌜ j Kind/✶ σs ↑✶ k ⌝Kd ≡ ⌜ j ⌝Kd Kind′/✶ σs ↑✶ k
⌜⌝Kd-/✶-↑✶ k ε = refl
⌜⌝Kd-/✶-↑✶ k (σ ◅ σs) = begin
⌜ _ Kind/✶ (σ ◅ σs) ↑✶ k ⌝Kd
≡⟨ ⌜⌝Kd-/ (_ Kind/✶ σs ↑✶ k) ⟩
⌜ _ Kind/✶ σs ↑✶ k ⌝Kd Kind′/ σ ↑⋆ k
≡⟨ cong (_Kind′/ _) (⌜⌝Kd-/✶-↑✶ k σs) ⟩
_ Kind′/✶ (σ ◅ σs) ↑✶ k
∎
-- Simplified kinds are stable under application of substitutions.
⌊⌋-Kind/ : ∀ {m n} (k : Kind Term m) {σ : Sub T m n} → ⌊ k Kind/ σ ⌋ ≡ ⌊ k ⌋
⌊⌋-Kind/ (a ⋯ b) = refl
⌊⌋-Kind/ (Π j k) = cong₂ _⇒_ (⌊⌋-Kind/ j) (⌊⌋-Kind/ k)
⌊⌋-Kind′/ : ∀ {m n} (k : Kind Elim m) {σ : Sub T m n} →
⌊ k Kind′/ σ ⌋ ≡ ⌊ k ⌋
⌊⌋-Kind′/ (a ⋯ b) = refl
⌊⌋-Kind′/ (Π j k) = cong₂ _⇒_ (⌊⌋-Kind′/ j) (⌊⌋-Kind′/ k)
-- Application of substitutions to type and kind ascriptions.
open KdOrTpSubstApp simple appKind appTerm public using ()
renaming (_/_ to _TermAsc/_)
open KdOrTpSubstApp simple appKind′ appElim public using ()
renaming (_/_ to _ElimAsc/_)
-- Substitutions in terms and associated lemmas.
module Substitution where
-- Term substitutions.
termSubst : TermSubst Term
termSubst = record { var = var; app = SubstApp._/_ }
-- Variable substitutions (renamings) in heads.
--
-- NOTE. The special treatment of heads here reflects the fact that
-- the structure of heads is preserved by renamings but not by
-- general term substitutions.
module HeadRenamings where
open Simple VarSubst.simple hiding (var)
open SubstApp (TermSubst.varLift termSubst)
infixl 8 _Head/Var_
_Head/Var_ : ∀ {m n} → Head m → Sub Fin m n → Head n
var x Head/Var σ = var (Vec.lookup σ x)
⊥ Head/Var σ = ⊥
⊤ Head/Var σ = ⊤
Π k a Head/Var σ = Π (k Kind′/ σ) (a Elim/ σ ↑)
(a ⇒ b) Head/Var σ = (a Elim/ σ) ⇒ (b Elim/ σ)
Λ k a Head/Var σ = Λ (k Kind′/ σ) (a Elim/ σ ↑)
ƛ a b Head/Var σ = ƛ (a Elim/ σ) (b Elim/ σ ↑)
(a ⊡ b) Head/Var σ = (a Elim/ σ) ⊡ (b Elim/ σ)
-- A lemma relating the above definition of application to the
-- previous ones.
Head/Var-∙ : ∀ {m n} {σ : Sub Fin m n} a → (a Head/Var σ) ∙ [] ≡ a Head/ σ
Head/Var-∙ (var x) = refl
Head/Var-∙ ⊥ = refl
Head/Var-∙ ⊤ = refl
Head/Var-∙ (Π k a) = refl
Head/Var-∙ (a ⇒ b) = refl
Head/Var-∙ (Λ k a) = refl
Head/Var-∙ (ƛ a b) = refl
Head/Var-∙ (a ⊡ b) = refl
headOf-Head/Var : ∀ {m n} {σ : Sub Fin m n} a →
a Head/Var σ ≡ headOf (a Head/ σ)
headOf-Head/Var a = cong headOf (Head/Var-∙ a)
Elim/Var-Head/Var : ∀ {m n} {σ : Sub Fin m n} a →
a ∙ [] Elim/ σ ≡ (a Head/Var σ) ∙ []
Elim/Var-Head/Var {σ = σ} a = begin
a ∙ [] Elim/ σ ≡⟨ ∙∙-[] (a Head/ σ) ⟩
a Head/ σ ≡⟨ sym (Head/Var-∙ a) ⟩
(a Head/Var σ) ∙ [] ∎
open HeadRenamings public
-- Lemmas relating application of sequences of generic substitutions
-- lifted to any number of additional variables.
--
-- Using these generic lemmas, we can instantiate the record
-- Data.Fin.Substitution.Lemmas.TermLemmas below, which gives access
-- to a number of useful (derived) lemmas about path substitutions.
module Lemmas {T₁ T₂ : ℕ → Set}
{lift₁ : Lift T₁ Term} {lift₂ : Lift T₂ Term} where
open SubstApp
open Lift lift₁ using () renaming (_↑✶_ to _↑✶₁_)
open Lift lift₂ using () renaming (_↑✶_ to _↑✶₂_)
open Application (record { _/_ = SubstApp._/_ lift₁ }) using ()
renaming (_/✶_ to _/✶₁_)
open Application (record { _/_ = SubstApp._/_ lift₂ }) using ()
renaming (_/✶_ to _/✶₂_)
open Application (record { _/_ = SubstApp._Kind/_ lift₁ }) using ()
renaming (_/✶_ to _Kind/✶₁_)
open Application (record { _/_ = SubstApp._Kind/_ lift₂ }) using ()
renaming (_/✶_ to _Kind/✶₂_)
-- Sequences of (lifted) T₁ and T₂-substitutions are equivalent
-- when applied to raw terms/types/kinds if they are equivalent
-- when applied to variables.
mutual
/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →
∀ k a → a /✶₁ σs₁ ↑✶₁ k ≡ a /✶₂ σs₂ ↑✶₂ k
/✶-↑✶ σs₁ σs₂ hyp k (var x) = hyp k x
/✶-↑✶ σs₁ σs₂ hyp k ⊥ = begin
⊥ /✶₁ σs₁ ↑✶₁ k ≡⟨ ⊥-/✶-↑✶ _ k σs₁ ⟩
⊥ ≡⟨ sym (⊥-/✶-↑✶ _ k σs₂) ⟩
⊥ /✶₂ σs₂ ↑✶₂ k ∎
/✶-↑✶ σs₁ σs₂ hyp k ⊤ = begin
⊤ /✶₁ σs₁ ↑✶₁ k ≡⟨ ⊤-/✶-↑✶ _ k σs₁ ⟩
⊤ ≡⟨ sym (⊤-/✶-↑✶ _ k σs₂) ⟩
⊤ /✶₂ σs₂ ↑✶₂ k ∎
/✶-↑✶ σs₁ σs₂ hyp k (Π j a) = begin
(Π j a) /✶₁ σs₁ ↑✶₁ k
≡⟨ Π-/✶-↑✶ _ k σs₁ ⟩
Π (j Kind/✶₁ σs₁ ↑✶₁ k) (a /✶₁ σs₁ ↑✶₁ suc k)
≡⟨ cong₂ Π (Kind/✶-↑✶ σs₁ σs₂ hyp k j) (/✶-↑✶ σs₁ σs₂ hyp (suc k) a) ⟩
Π (j Kind/✶₂ σs₂ ↑✶₂ k) (a /✶₂ σs₂ ↑✶₂ suc k)
≡⟨ sym (Π-/✶-↑✶ _ k σs₂) ⟩
(Π j a) /✶₂ σs₂ ↑✶₂ k
∎
/✶-↑✶ σs₁ σs₂ hyp k (a ⇒ b) = begin
(a ⇒ b) /✶₁ σs₁ ↑✶₁ k
≡⟨ ⇒-/✶-↑✶ _ k σs₁ ⟩
(a /✶₁ σs₁ ↑✶₁ k) ⇒ (b /✶₁ σs₁ ↑✶₁ k)
≡⟨ cong₂ _⇒_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩
(a /✶₂ σs₂ ↑✶₂ k) ⇒ (b /✶₂ σs₂ ↑✶₂ k)
≡⟨ sym (⇒-/✶-↑✶ _ k σs₂) ⟩
(a ⇒ b) /✶₂ σs₂ ↑✶₂ k
∎
/✶-↑✶ σs₁ σs₂ hyp k (Λ j a) = begin
(Λ j a) /✶₁ σs₁ ↑✶₁ k
≡⟨ Λ-/✶-↑✶ _ k σs₁ ⟩
Λ (j Kind/✶₁ σs₁ ↑✶₁ k) (a /✶₁ σs₁ ↑✶₁ suc k)
≡⟨ cong₂ Λ (Kind/✶-↑✶ σs₁ σs₂ hyp k j) (/✶-↑✶ σs₁ σs₂ hyp (suc k) a) ⟩
Λ (j Kind/✶₂ σs₂ ↑✶₂ k) (a /✶₂ σs₂ ↑✶₂ suc k)
≡⟨ sym (Λ-/✶-↑✶ _ k σs₂) ⟩
(Λ j a) /✶₂ σs₂ ↑✶₂ k
∎
/✶-↑✶ σs₁ σs₂ hyp k (ƛ a b) = begin
(ƛ a b) /✶₁ σs₁ ↑✶₁ k
≡⟨ ƛ-/✶-↑✶ _ k σs₁ ⟩
ƛ (a /✶₁ σs₁ ↑✶₁ k) (b /✶₁ σs₁ ↑✶₁ suc k)
≡⟨ cong₂ ƛ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp (suc k) b) ⟩
ƛ (a /✶₂ σs₂ ↑✶₂ k) (b /✶₂ σs₂ ↑✶₂ suc k)
≡⟨ sym (ƛ-/✶-↑✶ _ k σs₂) ⟩
(ƛ a b) /✶₂ σs₂ ↑✶₂ k
∎
/✶-↑✶ σs₁ σs₂ hyp k (a · b) = begin
(a · b) /✶₁ σs₁ ↑✶₁ k
≡⟨ ·-/✶-↑✶ _ k σs₁ ⟩
(a /✶₁ σs₁ ↑✶₁ k) · (b /✶₁ σs₁ ↑✶₁ k)
≡⟨ cong₂ _·_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩
(a /✶₂ σs₂ ↑✶₂ k) · (b /✶₂ σs₂ ↑✶₂ k)
≡⟨ sym (·-/✶-↑✶ _ k σs₂) ⟩
(a · b) /✶₂ σs₂ ↑✶₂ k
∎
/✶-↑✶ σs₁ σs₂ hyp k (a ⊡ b) = begin
(a ⊡ b) /✶₁ σs₁ ↑✶₁ k
≡⟨ ⊡-/✶-↑✶ _ k σs₁ ⟩
(a /✶₁ σs₁ ↑✶₁ k) ⊡ (b /✶₁ σs₁ ↑✶₁ k)
≡⟨ cong₂ _⊡_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩
(a /✶₂ σs₂ ↑✶₂ k) ⊡ (b /✶₂ σs₂ ↑✶₂ k)
≡⟨ sym (⊡-/✶-↑✶ _ k σs₂) ⟩
(a ⊡ b) /✶₂ σs₂ ↑✶₂ k
∎
Kind/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →
∀ k j → j Kind/✶₁ σs₁ ↑✶₁ k ≡ j Kind/✶₂ σs₂ ↑✶₂ k
Kind/✶-↑✶ σs₁ σs₂ hyp k (a ⋯ b) = begin
(a ⋯ b) Kind/✶₁ σs₁ ↑✶₁ k
≡⟨ ⋯-Kind/✶-↑✶ _ k σs₁ ⟩
(a /✶₁ σs₁ ↑✶₁ k) ⋯ (b /✶₁ σs₁ ↑✶₁ k)
≡⟨ cong₂ _⋯_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩
(a /✶₂ σs₂ ↑✶₂ k) ⋯ (b /✶₂ σs₂ ↑✶₂ k)
≡⟨ sym (⋯-Kind/✶-↑✶ _ k σs₂) ⟩
(a ⋯ b) Kind/✶₂ σs₂ ↑✶₂ k
∎
Kind/✶-↑✶ σs₁ σs₂ hyp k (Π j l) = begin
(Π j l) Kind/✶₁ σs₁ ↑✶₁ k
≡⟨ Π-Kind/✶-↑✶ _ k σs₁ ⟩
Π (j Kind/✶₁ σs₁ ↑✶₁ k) (l Kind/✶₁ σs₁ ↑✶₁ suc k)
≡⟨ cong₂ Π (Kind/✶-↑✶ σs₁ σs₂ hyp k j)
(Kind/✶-↑✶ σs₁ σs₂ hyp (suc k) l) ⟩
Π (j Kind/✶₂ σs₂ ↑✶₂ k) (l Kind/✶₂ σs₂ ↑✶₂ suc k)
≡⟨ sym (Π-Kind/✶-↑✶ _ k σs₂) ⟩
(Π j l) Kind/✶₂ σs₂ ↑✶₂ k
∎
open Application (record { _/_ = SubstApp._Elim/_ lift₁ }) using ()
renaming (_/✶_ to _Elim/✶₁_)
open Application (record { _/_ = SubstApp._Elim/_ lift₂ }) using ()
renaming (_/✶_ to _Elim/✶₂_)
Elim/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →
∀ k a → a Elim/✶₁ σs₁ ↑✶₁ k ≡ a Elim/✶₂ σs₂ ↑✶₂ k
Elim/✶-↑✶ σs₁ σs₂ hyp k a = begin
a Elim/✶₁ σs₁ ↑✶₁ k
≡⟨ sym (cong (_Elim/✶₁ σs₁ ↑✶₁ k) (⌜⌝∘⌞⌟-id a)) ⟩
⌜ ⌞ a ⌟ ⌝ Elim/✶₁ σs₁ ↑✶₁ k
≡⟨ sym (⌜⌝-/✶-↑✶ _ k σs₁) ⟩
⌜ ⌞ a ⌟ /✶₁ σs₁ ↑✶₁ k ⌝
≡⟨ cong ⌜_⌝ (/✶-↑✶ σs₁ σs₂ hyp k ⌞ a ⌟) ⟩
⌜ ⌞ a ⌟ /✶₂ σs₂ ↑✶₂ k ⌝
≡⟨ ⌜⌝-/✶-↑✶ _ k σs₂ ⟩
⌜ ⌞ a ⌟ ⌝ Elim/✶₂ σs₂ ↑✶₂ k
≡⟨ cong (_Elim/✶₂ σs₂ ↑✶₂ k) (⌜⌝∘⌞⌟-id a) ⟩
a Elim/✶₂ σs₂ ↑✶₂ k
∎
open Application (record { _/_ = SubstApp._Kind′/_ lift₁ }) using ()
renaming (_/✶_ to _Kind′/✶₁_)
open Application (record { _/_ = SubstApp._Kind′/_ lift₂ }) using ()
renaming (_/✶_ to _Kind′/✶₂_)
Kind′/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →
∀ k j → j Kind′/✶₁ σs₁ ↑✶₁ k ≡ j Kind′/✶₂ σs₂ ↑✶₂ k
Kind′/✶-↑✶ σs₁ σs₂ hyp k j = begin
j Kind′/✶₁ σs₁ ↑✶₁ k
≡⟨ sym (cong (_Kind′/✶₁ σs₁ ↑✶₁ k) (⌜⌝Kd∘⌞⌟Kd-id j)) ⟩
⌜ ⌞ j ⌟Kd ⌝Kd Kind′/✶₁ σs₁ ↑✶₁ k
≡⟨ sym (⌜⌝Kd-/✶-↑✶ _ k σs₁) ⟩
⌜ ⌞ j ⌟Kd Kind/✶₁ σs₁ ↑✶₁ k ⌝Kd
≡⟨ cong ⌜_⌝Kd (Kind/✶-↑✶ σs₁ σs₂ hyp k ⌞ j ⌟Kd) ⟩
⌜ ⌞ j ⌟Kd Kind/✶₂ σs₂ ↑✶₂ k ⌝Kd
≡⟨ ⌜⌝Kd-/✶-↑✶ _ k σs₂ ⟩
⌜ ⌞ j ⌟Kd ⌝Kd Kind′/✶₂ σs₂ ↑✶₂ k
≡⟨ cong (_Kind′/✶₂ σs₂ ↑✶₂ k) (⌜⌝Kd∘⌞⌟Kd-id j) ⟩
j Kind′/✶₂ σs₂ ↑✶₂ k
∎
-- Lemmas relating application of sequences of generic substitutions
-- in generic kind or type ascriptions, provided substitutions on
-- the underlying kinds or types are similarly related.
record KdOrTpLemmas {T₁ T₂ T′ : ℕ → Set}
(lift₁ : Lift T₁ Term)
(lift₂ : Lift T₂ Term)
: Set where
field
kdApp₁ : Application (Kind T′) T₁
kdApp₂ : Application (Kind T′) T₂
tpApp₁ : Application T′ T₁
tpApp₂ : Application T′ T₂
open Lift lift₁ using () renaming (_↑✶_ to _↑✶₁_)
open Lift lift₂ using () renaming (_↑✶_ to _↑✶₂_)
private
module A₁ = Application (record { _/_ = SubstApp._/_ lift₁ })
module A₂ = Application (record { _/_ = SubstApp._/_ lift₂ })
module T₁ = Application tpApp₁
module T₂ = Application tpApp₂
module K₁ = Application kdApp₁
module K₂ = Application kdApp₂
module KT₁ = KdOrTpSubstApp (Lift.simple lift₁) kdApp₁ tpApp₁
module KT₂ = KdOrTpSubstApp (Lift.simple lift₂) kdApp₂ tpApp₂
-- Sequences of (lifted) T₁ and T₂-substitutions are equivalent
-- when applied to kinds and raw types (represented as T′s) if
-- they are equivalent when applied to variables (represented as
-- raw terms).
field
Kd/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x A₁./✶ σs₁ ↑✶₁ k ≡ var x A₂./✶ σs₂ ↑✶₂ k) →
∀ k a → a K₁./✶ σs₁ ↑✶₁ k ≡ a K₂./✶ σs₂ ↑✶₂ k
Tp/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x A₁./✶ σs₁ ↑✶₁ k ≡ var x A₂./✶ σs₂ ↑✶₂ k) →
∀ k a → a T₁./✶ σs₁ ↑✶₁ k ≡ a T₂./✶ σs₂ ↑✶₂ k
/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → var x A₁./✶ σs₁ ↑✶₁ k ≡ var x A₂./✶ σs₂ ↑✶₂ k) →
∀ k a → a KT₁./✶ σs₁ ↑✶₁ k ≡ a KT₂./✶ σs₂ ↑✶₂ k
/✶-↑✶ σs₁ σs₂ hyp k (kd j) = begin
kd j KT₁./✶ σs₁ ↑✶₁ k ≡⟨ KT₁.kd-/✶-↑✶ k σs₁ ⟩
kd (j K₁./✶ σs₁ ↑✶₁ k) ≡⟨ cong kd (Kd/✶-↑✶ σs₁ σs₂ hyp k j) ⟩
kd (j K₂./✶ σs₂ ↑✶₂ k) ≡⟨ sym (KT₂.kd-/✶-↑✶ k σs₂) ⟩
kd j KT₂./✶ σs₂ ↑✶₂ k ∎
/✶-↑✶ σs₁ σs₂ hyp k (tp a) = begin
tp a KT₁./✶ σs₁ ↑✶₁ k ≡⟨ KT₁.tp-/✶-↑✶ k σs₁ ⟩
tp (a T₁./✶ σs₁ ↑✶₁ k) ≡⟨ cong tp (Tp/✶-↑✶ σs₁ σs₂ hyp k a) ⟩
tp (a T₂./✶ σs₂ ↑✶₂ k) ≡⟨ sym (KT₂.tp-/✶-↑✶ k σs₂) ⟩
tp a KT₂./✶ σs₂ ↑✶₂ k ∎
termAscLemmas : ∀ {T₁ T₂} lift₁ lift₂ → KdOrTpLemmas {T₁} {T₂} lift₁ lift₂
termAscLemmas lift₁ lift₂ = record
{ kdApp₁ = record { _/_ = SubstApp._Kind/_ lift₁ }
; kdApp₂ = record { _/_ = SubstApp._Kind/_ lift₂ }
; tpApp₁ = record { _/_ = SubstApp._/_ lift₁ }
; tpApp₂ = record { _/_ = SubstApp._/_ lift₂ }
; Kd/✶-↑✶ = Lemmas.Kind/✶-↑✶
; Tp/✶-↑✶ = Lemmas./✶-↑✶
}
elimAscLemmas : ∀ {T₁ T₂} lift₁ lift₂ → KdOrTpLemmas {T₁} {T₂} lift₁ lift₂
elimAscLemmas lift₁ lift₂ = record
{ kdApp₁ = record { _/_ = SubstApp._Kind′/_ lift₁ }
; kdApp₂ = record { _/_ = SubstApp._Kind′/_ lift₂ }
; tpApp₁ = record { _/_ = SubstApp._Elim/_ lift₁ }
; tpApp₂ = record { _/_ = SubstApp._Elim/_ lift₂ }
; Kd/✶-↑✶ = Lemmas.Kind′/✶-↑✶
; Tp/✶-↑✶ = Lemmas.Elim/✶-↑✶
}
-- By instantiating TermLemmas, we get access to a number of useful
-- (derived) lemmas about path substitutions.
termLemmas : TermLemmas Term
termLemmas = record
{ termSubst = termSubst
; app-var = refl
; /✶-↑✶ = Lemmas./✶-↑✶
}
open TermLemmas termLemmas public hiding (var; termSubst; weaken-sub)
open SubstApp (TermSubst.termLift termSubst) public using
( _Head/_; _//_
; ++-//; ∙∙-/; ⌜·⌝-/; ⌜⌝-/; ⌜⌝Kd-/; ⌞⌟-/; ⌞⌟Kd-/; ⌊⌋-Kind/; ⌊⌋-Kind′/
)
open SubstApp (TermSubst.varLift termSubst) public using () renaming
( _Head/_ to _Head/Var′_
; _//_ to _//Var_
; ++-// to ++-//Var
; ∙∙-/ to ∙∙-/Var
; ⌜·⌝-/ to ⌜·⌝-/Var
; ⌜⌝-/ to ⌜⌝-/Var
; ⌜⌝Kd-/ to ⌜⌝Kd-/Var
; ⌞⌟-/ to ⌞⌟-/Var
; ⌞⌟Kd-/ to ⌞⌟Kd-/Var
; ⌊⌋-Kind/ to ⌊⌋-Kind/Var
; ⌊⌋-Kind′/ to ⌊⌋-Kind′/Var
)
-- By instantiating TermLikeLemmas, we get access to a number of
-- useful (derived) lemmas about variable substitutions (renamings)
-- and substitutions in kinds, eliminations and ascriptions.
private
termLikeLemmas : TermLikeLemmas Term Term
termLikeLemmas = record
{ app = SubstApp._/_
; termLemmas = termLemmas
; /✶-↑✶₁ = Lemmas./✶-↑✶
; /✶-↑✶₂ = Lemmas./✶-↑✶
}
open TermLikeLemmas termLikeLemmas public using
( varLiftAppLemmas; varLiftSubLemmas; _/Var_
; weaken-sub; weaken-/; weaken⋆; /-wk⋆
)
termLikeLemmasKind : TermLikeLemmas (Kind Term) Term
termLikeLemmasKind = record
{ app = SubstApp._Kind/_
; termLemmas = termLemmas
; /✶-↑✶₁ = Lemmas.Kind/✶-↑✶
; /✶-↑✶₂ = Lemmas.Kind/✶-↑✶
}
open TermLikeLemmas termLikeLemmasKind public using () renaming
( _/_ to _Kind/_
; _/Var_ to _Kind/Var_
; weaken to weakenKind
; weaken⋆ to weakenKind⋆
)
termLikeLemmasElim : TermLikeLemmas Elim Term
termLikeLemmasElim = record
{ app = SubstApp._Elim/_
; termLemmas = termLemmas
; /✶-↑✶₁ = Lemmas.Elim/✶-↑✶
; /✶-↑✶₂ = Lemmas.Elim/✶-↑✶
}
open TermLikeLemmas termLikeLemmasElim public using () renaming
( _/_ to _Elim/_
; _/Var_ to _Elim/Var_
; weaken to weakenElim
; weaken⋆ to weakenElim⋆
)
termLikeLemmasKind′ : TermLikeLemmas (Kind Elim) Term
termLikeLemmasKind′ = record
{ app = SubstApp._Kind′/_
; termLemmas = termLemmas
; /✶-↑✶₁ = Lemmas.Kind′/✶-↑✶
; /✶-↑✶₂ = Lemmas.Kind′/✶-↑✶
}
open TermLikeLemmas termLikeLemmasKind′ public using () renaming
( _/_ to _Kind′/_
; _/Var_ to _Kind′/Var_
; weaken to weakenKind′
; weaken⋆ to weakenKind′⋆
)
termLikeLemmasTermAsc : TermLikeLemmas TermAsc Term
termLikeLemmasTermAsc = record
{ app = SubstApp._TermAsc/_
; termLemmas = termLemmas
; /✶-↑✶₁ = KdOrTpLemmas./✶-↑✶ (termAscLemmas _ _)
; /✶-↑✶₂ = KdOrTpLemmas./✶-↑✶ (termAscLemmas _ _)
}
open TermLikeLemmas termLikeLemmasTermAsc public using () renaming
( termLikeSubst to termAscTermSubst
; _/_ to _TermAsc/_
; _/Var_ to _TermAsc/Var_
; weaken to weakenTermAsc
)
termLikeLemmasElimAsc : TermLikeLemmas ElimAsc Term
termLikeLemmasElimAsc = record
{ app = SubstApp._ElimAsc/_
; termLemmas = termLemmas
; /✶-↑✶₁ = KdOrTpLemmas./✶-↑✶ (elimAscLemmas _ _)
; /✶-↑✶₂ = KdOrTpLemmas./✶-↑✶ (elimAscLemmas _ _)
}
open TermLikeLemmas termLikeLemmasElimAsc public using () renaming
( termLikeSubst to elimAscTermSubst
; _/_ to _ElimAsc/_
; _/Var_ to _ElimAsc/Var_
; weaken to weakenElimAsc
; weaken⋆ to weakenElimAsc⋆
)
-- Weakening of heads and spines.
weakenHead : ∀ {n} → Head n → Head (suc n)
weakenHead a = a Head/Var VarSubst.wk
weakenSpine : ∀ {n} → Spine n → Spine (suc n)
weakenSpine a = a //Var VarSubst.wk
-- Conversion of ascriptions commutes with weakening.
⌜⌝Asc-weaken : ∀ {n} (a : TermAsc n) →
⌜ weakenTermAsc a ⌝Asc ≡ weakenElimAsc ⌜ a ⌝Asc
⌜⌝Asc-weaken (kd k) = cong kd (⌜⌝Kd-/Var k)
⌜⌝Asc-weaken (tp a) = cong tp (⌜⌝-/Var a)
⌞⌟Asc-weaken : ∀ {n} (a : ElimAsc n) →
⌞ weakenElimAsc a ⌟Asc ≡ weakenTermAsc ⌞ a ⌟Asc
⌞⌟Asc-weaken (kd k) = cong kd (⌞⌟Kd-/Var k)
⌞⌟Asc-weaken (tp a) = cong tp (⌞⌟-/Var a)
-- Simplified kinds are stable under weakening.
⌊⌋-weaken : ∀ {n} (k : Kind Term n) → ⌊ weakenKind k ⌋ ≡ ⌊ k ⌋
⌊⌋-weaken k = ⌊⌋-Kind/Var k
⌊⌋-weaken′ : ∀ {n} (k : Kind Elim n) → ⌊ weakenKind′ k ⌋ ≡ ⌊ k ⌋
⌊⌋-weaken′ k = ⌊⌋-Kind′/Var k
⌊⌋-weaken⋆′ : ∀ {m} n (k : Kind Elim m) → ⌊ weakenKind′⋆ n k ⌋ ≡ ⌊ k ⌋
⌊⌋-weaken⋆′ zero k = refl
⌊⌋-weaken⋆′ (suc n) k = begin
⌊ weakenKind′ (weakenKind′⋆ n k) ⌋ ≡⟨ ⌊⌋-weaken′ (weakenKind′⋆ n k) ⟩
⌊ weakenKind′⋆ n k ⌋ ≡⟨ ⌊⌋-weaken⋆′ n k ⟩
⌊ k ⌋ ∎
infix 10 _[_] _Elim[_] _Kind[_] _Kind′[_] _TermAsc[_] _ElimAsc[_]
-- Shorthands for single-variable term substitutions.
_[_] : ∀ {n} → Term (suc n) → Term n → Term n
a [ b ] = a / sub b
_Elim[_] : ∀ {n} → Elim (suc n) → Term n → Elim n
a Elim[ b ] = a Elim/ sub b
_Kind[_] : ∀ {n} → Kind Term (suc n) → Term n → Kind Term n
k Kind[ b ] = k Kind/ (sub b)
_Kind′[_] : ∀ {n} → Kind Elim (suc n) → Term n → Kind Elim n
k Kind′[ b ] = k Kind′/ (sub b)
_TermAsc[_] : ∀ {n} → TermAsc (suc n) → Term n → TermAsc n
a TermAsc[ b ] = a TermAsc/ sub b
_ElimAsc[_] : ∀ {n} → ElimAsc (suc n) → Term n → ElimAsc n
a ElimAsc[ b ] = a ElimAsc/ sub b
private module V = VarSubst
-- Kinds are stable under substitutions of a variable for a fresh
-- variable (up to α-equivalence).
Kind-wk↑-sub-zero-vanishes : ∀ {n} (k : Kind Term (suc n)) →
(k Kind/Var V.wk V.↑) Kind[ var zero ] ≡ k
Kind-wk↑-sub-zero-vanishes k = begin
(k Kind/Var V.wk V.↑) Kind[ var zero ]
≡⟨ sym (KL./-sub (k Kind/Var _) zero) ⟩
k Kind/Var V.wk V.↑ Kind/Var V.sub zero
≡⟨ sym (LiftAppLemmas./-⊙ KL.varLiftAppLemmas k) ⟩
k Kind/Var V.wk V.↑ V.⊙ V.sub zero
≡⟨⟩
k Kind/Var (zero ∷ (Vec.map suc V.wk V.⊙ V.sub zero))
≡⟨ cong (λ σ → k Kind/Var (zero ∷ σ)) VarLemmas.map-weaken-⊙-sub ⟩
k Kind/Var (zero ∷ V.wk)
≡⟨⟩
k Kind/Var V.id
≡⟨ LiftAppLemmas.id-vanishes KL.varLiftAppLemmas k ⟩
k
∎
where
open ≡-Reasoning
module KL = TermLikeLemmas termLikeLemmasKind
----------------------------------------------------------------------
-- Typing contexts containing kind and type ascriptions.
-- Generic typing contexts over T-ascriptions and useful operations.
record KdOrTpCtx (T : ℕ → Set) : Set₁ where
open Context public hiding (Ctx; CtxExt)
-- Contexts and context extensions.
Ctx = Context.Ctx (KdOrTp T)
CtxExt = Context.CtxExt (KdOrTp T)
-- Operations such as context lookup and substitutions in context
-- extensions require some extra substitution machinery for
-- T-ascriptions, all of which is provided by the following instance
-- of TermLikeLemmas.
field termLikeLemmas : TermLikeLemmas (KdOrTp T) Term
open TermLikeLemmas termLikeLemmas
using (termApplication; weaken; termLemmas)
open TermLemmas termLemmas using (simple)
weakenOps : Extension (KdOrTp T)
weakenOps = record { weaken = weaken }
open WeakenOps weakenOps public hiding (weaken; weaken⋆)
open WeakenOpsLemmas weakenOps public
open ConversionLemmas weakenOps weakenOps public
open SubstOps termApplication simple public using (_E/_)
open Substitution
-- Concrete typing contexts over raw term and raw elimination
-- ascriptions.
termCtx : KdOrTpCtx Term
termCtx = record { termLikeLemmas = termLikeLemmasTermAsc }
module TermCtx = KdOrTpCtx termCtx
elimCtx : KdOrTpCtx Elim
elimCtx = record { termLikeLemmas = termLikeLemmasElimAsc }
module ElimCtx = KdOrTpCtx elimCtx
-- Concrete typing contexts over shape ascriptions and useful
-- operations.
module SimpleCtx where
open Context public hiding (Ctx; CtxExt)
open Maybe public using (Maybe) renaming (just to kd; nothing to tp)
-- Shape ascriptions.
--
-- NOTE. We only use shape ascriptions (or "simple" kind
-- ascriptions) in the simplified kinding system, which is defined
-- exclusively on types (see the FOmegaInt.Kinding.Simple module).
-- Because simple kinding judgments can never refer to term
-- variables, we may as well forget the type of such variables. We
-- just need to remember that there are such variables in the
-- context so as to maintain the de Bruijn indexes of (type)
-- variables, e.g. when we convert full kinding judgments to
-- simplified ones. Accordingly, we implement shape ascriptions
-- using `Maybe' from the standard library, but with the
-- constructors `just' and `nothing' renamed to `kd' and `tp' to
-- better reflect their meaning. (This renaming happens during the
-- import of the `Maybe' module above.)
SAsc : ℕ → Set
SAsc _ = Maybe SKind
-- Simplification/erasure of ascriptions.
⌊_⌋Asc : ∀ {T n} → KdOrTp T n → SAsc n
⌊ kd k ⌋Asc = kd ⌊ k ⌋
⌊ tp a ⌋Asc = tp
-- Injectivity of the (simple) `kd' constructor.
kd-inj′ : {j k : SKind} → _≡_ {A = Maybe SKind} (kd j) (kd k) → j ≡ k
kd-inj′ refl = refl
-- Contexts and context extensions over shape ascriptions.
Ctx = Context.Ctx SAsc
CtxExt = Context.CtxExt SAsc
weakenOps : Extension SAsc
weakenOps = record { weaken = Function.id }
open WeakenOps weakenOps public hiding (weaken; weaken⋆)
open WeakenOpsLemmas weakenOps public
open ConversionLemmas weakenOps weakenOps public
-- Change the indexing of a context extension.
re-idx : ∀ {k m n} → CtxExt k n → CtxExt m n
re-idx Γ = mapExt (λ _ k → k) Γ
open Extension weakenOps public using () renaming (weaken⋆ to weakenSAsc⋆)
weakenSAsc⋆-id : ∀ m {n a} → weakenSAsc⋆ m {n} a ≡ a
weakenSAsc⋆-id zero = refl
weakenSAsc⋆-id (suc m) = weakenSAsc⋆-id m
⌊⌋-TermAsc/ : ∀ {m n} a {σ : Sub Term m n} → ⌊ a TermAsc/ σ ⌋Asc ≡ ⌊ a ⌋Asc
⌊⌋-TermAsc/ (kd k) = cong kd (⌊⌋-Kind/ k)
⌊⌋-TermAsc/ (tp t) = refl
⌊⌋-ElimAsc/ : ∀ {m n} a {σ : Sub Term m n} → ⌊ a ElimAsc/ σ ⌋Asc ≡ ⌊ a ⌋Asc
⌊⌋-ElimAsc/ (kd k) = cong kd (⌊⌋-Kind′/ k)
⌊⌋-ElimAsc/ (tp t) = refl
⌊⌋-ElimAsc/Var : ∀ {m n} a {σ : Sub Fin m n} →
⌊ a ElimAsc/Var σ ⌋Asc ≡ ⌊ a ⌋Asc
⌊⌋-ElimAsc/Var (kd k) = cong kd (⌊⌋-Kind′/Var k)
⌊⌋-ElimAsc/Var (tp t) = refl
-- Conversions between the different context representations.
module ContextConversions where
open Context
open SimpleCtx using (kd; ⌊_⌋Asc; ⌊⌋-ElimAsc/Var)
⌞_⌟Ctx : ∀ {n} → ElimCtx.Ctx n → TermCtx.Ctx n
⌞ Γ ⌟Ctx = ElimCtx.map ⌞_⌟Asc Γ
⌜_⌝Ctx : ∀ {n} → TermCtx.Ctx n → ElimCtx.Ctx n
⌜ Γ ⌝Ctx = TermCtx.map ⌜_⌝Asc Γ
⌊_⌋Ctx : ∀ {T n} → Ctx (KdOrTp T) n → SimpleCtx.Ctx n
⌊ Γ ⌋Ctx = SimpleCtx.map ⌊_⌋Asc Γ
⌊_⌋CtxExt : ∀ {T m n} → CtxExt (KdOrTp T) m n → SimpleCtx.CtxExt m n
⌊ Γ ⌋CtxExt = SimpleCtx.mapExt (λ _ → ⌊_⌋Asc) Γ
module ⌞⌟Ctx-Lemmas = ConversionLemmas ElimCtx.weakenOps TermCtx.weakenOps
module ⌜⌝Ctx-Lemmas = ConversionLemmas TermCtx.weakenOps ElimCtx.weakenOps
module ⌊⌋Ctx-Lemmas = ConversionLemmas ElimCtx.weakenOps SimpleCtx.weakenOps
-- Context conversions commute with context lookup.
⌞⌟Asc-lookup : ∀ {n} (Γ : ElimCtx.Ctx n) x →
TermCtx.lookup ⌞ Γ ⌟Ctx x ≡ ⌞ ElimCtx.lookup Γ x ⌟Asc
⌞⌟Asc-lookup Γ x =
⌞⌟Ctx-Lemmas.lookup-map ⌞_⌟Asc Γ x (λ a → sym (⌞⌟Asc-weaken a))
⌜⌝Asc-lookup : ∀ {n} (Γ : TermCtx.Ctx n) x →
ElimCtx.lookup ⌜ Γ ⌝Ctx x ≡ ⌜ TermCtx.lookup Γ x ⌝Asc
⌜⌝Asc-lookup Γ x =
⌜⌝Ctx-Lemmas.lookup-map ⌜_⌝Asc Γ x (λ a → sym (⌜⌝Asc-weaken a))
⌊⌋Asc-lookup : ∀ {n} (Γ : ElimCtx.Ctx n) x →
SimpleCtx.lookup ⌊ Γ ⌋Ctx x ≡ ⌊ ElimCtx.lookup Γ x ⌋Asc
⌊⌋Asc-lookup Γ x =
⌊⌋Ctx-Lemmas.lookup-map ⌊_⌋Asc Γ x (λ a → sym (⌊⌋-ElimAsc/Var a))
⌊⌋-lookup : ∀ {n} (Γ : ElimCtx.Ctx n) x {k} → ElimCtx.lookup Γ x ≡ kd k →
SimpleCtx.lookup ⌊ Γ ⌋Ctx x ≡ kd ⌊ k ⌋
⌊⌋-lookup Γ x {k} Γ[x]≡kd-k = begin
SimpleCtx.lookup ⌊ Γ ⌋Ctx x
≡⟨ ⌊⌋Asc-lookup Γ x ⟩
⌊ ElimCtx.lookup Γ x ⌋Asc
≡⟨ cong ⌊_⌋Asc Γ[x]≡kd-k ⟩
kd ⌊ k ⌋
∎
where open ≡-Reasoning
|
{
"alphanum_fraction": 0.5107730567,
"avg_line_length": 36.2727272727,
"ext": "agda",
"hexsha": "05ba78191488d0c19bd9143474b036c002b768d1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/FOmegaInt/Syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/FOmegaInt/Syntax.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/FOmegaInt/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 24250,
"size": 51471
}
|
open import Poly
open import Function
open import Data.Nat
open import Data.Empty
open import Data.Unit
open import Data.Product as Prod
open import Data.Sum
open import Relation.Binary.PropositionalEquality
data ℕ∞ : Set where
fin : ℕ → ℕ∞
ω : ℕ∞
data _<'_ : ℕ∞ → ℕ∞ → Set where
ltSuc : (n : ℕ) → fin n <' fin (suc n)
ltω : (n : ℕ) → fin n <' ω
z : ⊤ → ℕ∞
z _ = fin 0
suc' : ℕ∞ → ℕ∞
suc' (fin x) = fin (suc x)
suc' ω = ω
F : (ℕ∞ → Set) → (ℕ∞ → Set)
F X n = (n ≡ z tt → ⊥)
× ((k : ℕ∞) → n ≡ suc' k → X k)
× ((n ≡ ω) → (∃ λ k → k <' ω × X k))
A = ℕ∞ × (⊥ ⊎ ⊤ ⊎ (∃ λ k → k <' ω))
B = ⊥ ⊎ ℕ∞ ⊎ (∃ λ k → k <' ω)
f : B → A
f (inj₁ x) = (z tt , inj₁ x)
f (inj₂ (inj₁ x)) = (suc' x , inj₂ (inj₁ tt))
f (inj₂ (inj₂ y)) = (ω , inj₂ (inj₂ y))
s : B → ℕ∞
s (inj₁ x) = ⊥-elim x
s (inj₂ (inj₁ x)) = x
s (inj₂ (inj₂ y)) = proj₁ y
t : A → ℕ∞
t = proj₁
P : DPoly
P = dpoly A t B f s
-- Claim : F ≅ ⟦ P ⟧
F→P : ∀{X} n → F X n → T P X n
F→P {X} (fin zero) v = ins a (abs'' a u)
where
a = (z tt , inj₁ (proj₁ v refl))
u : (b : B) → f b ≡ a → X (s b)
u b p with b
u b refl | inj₁ _ = ⊥-elim (proj₁ v refl)
u b () | inj₂ (inj₁ x)
u b () | inj₂ (inj₂ y)
F→P {X} (fin (suc k)) (_ , v , _) = ins a (abs'' a u)
where
a = (fin (suc k) , inj₂ (inj₁ tt))
u : (b : B) → f b ≡ a → X (s b)
u b p with b
u b () | inj₁ x
u b refl | inj₂ (inj₁ (fin .k)) = v (fin k) refl
u b () | inj₂ (inj₁ ω)
u b () | inj₂ (inj₂ y)
F→P {X} ω (_ , _ , v) = ins a (abs'' a u)
where
i : ∃ λ k → k <' ω
i = Prod.map id proj₁ (v refl)
a = (ω , inj₂ (inj₂ i))
u : (b : B) → f b ≡ a → X (s b)
u b p with b
u b () | inj₁ x
u b () | inj₂ (inj₁ x)
u b refl | inj₂ (inj₂ _) = proj₂ (proj₂ (v refl))
P→F : ∀{X} n → T P X n → F X n
P→F (fin zero) (ins (.(fin 0) , v) x) = ? -- ({!!} , {!!})
P→F (fin (suc n)) v = {!!}
P→F ω v = {!!}
|
{
"alphanum_fraction": 0.4444444444,
"avg_line_length": 21.5393258427,
"ext": "agda",
"hexsha": "c11638249ab44ebf8c4f523ec7227ffe8959f950",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "TypeTheory/Container/AF.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hbasold/Sandbox",
"max_issues_repo_path": "TypeTheory/Container/AF.agda",
"max_line_length": 58,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "TypeTheory/Container/AF.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 943,
"size": 1917
}
|
module Numeric.Nat.Divide where
open import Prelude
open import Control.WellFounded
open import Numeric.Nat.Properties
open import Numeric.Nat.DivMod
open import Tactic.Nat
--- Divides predicate ---
data _Divides_ (a b : Nat) : Set where
factor : ∀ q (eq : q * a ≡ b) → a Divides b
pattern factor! q = factor q refl
get-factor : ∀ {a b} → a Divides b → Nat
get-factor (factor q _) = q
dividesToDivMod : ∀ {a b} {{_ : NonZero b}} → b Divides a → DivMod a b
dividesToDivMod {b = zero } {{}}
dividesToDivMod {b = suc b} (factor q eq) = qr q 0 auto (by eq)
mod-divides : ∀ {a b} {{_ : NonZero a}} → a Divides b → b mod a ≡ 0
mod-divides {zero} {{}}
mod-divides {suc a} {b} (factor q eq) =
rem-unique (b divmod suc a) (dividesToDivMod (factor q eq))
div-divides : ∀ {a b} {{_ : NonZero a}} → a Divides b → (b div a) * a ≡ b
div-divides {a} {b} a|b with divmod-sound a b
... | eq rewrite mod-divides a|b = by eq
private
safediv : Nat → Nat → Nat
safediv a 0 = 0
safediv a (suc b) = a div suc b
divides-safediv : ∀ {a b} → a Divides b → safediv b a * a ≡ b
divides-safediv {zero } (factor! _) = auto
divides-safediv {suc a} a|b = div-divides a|b
fast-divides : ∀ {a b} → a Divides b → a Divides b
fast-divides {a} {b} a|b = factor (safediv b a) (eraseEquality (divides-safediv a|b))
private
no-divides-suc-mod : ∀ {a b} q {r} → LessNat (suc r) a → q * a + suc r ≡ b → ¬ (a Divides b)
no-divides-suc-mod {zero} _ (diff _ ())
no-divides-suc-mod {suc a} q {r} lt eq (factor q′ eq′) =
refute (rem-unique
(dividesToDivMod (factor q′ eq′))
(qr q (suc r) lt eq))
no-divides-zero : ∀ {a} → ¬ (0 Divides suc a)
no-divides-zero {a} (factor q eq) = refute eq
_divides?_ : ∀ a b → Dec (a Divides b)
a divides? zero = yes (factor! 0)
zero divides? suc b = no no-divides-zero
suc a divides? suc b with suc b divmod suc a
suc a divides? suc b | qr q zero _ eq = yes (factor q (by eq))
suc a divides? suc b | qr q (suc r) lt eq₁ = no (no-divides-suc-mod q lt eq₁)
--- Instances ---
instance
SmashDivides : ∀ {a b} {{_ : NonZero a}} → Smashed (a Divides b)
SmashDivides {0} {{}}
smashed {{SmashDivides {a@(suc _)}}} {factor q eq} {factor q₁ refl} =
case mul-inj₁ q q₁ (suc _) eq of λ where refl → factor q $≡ smashed
|
{
"alphanum_fraction": 0.6151157711,
"avg_line_length": 32.7,
"ext": "agda",
"hexsha": "648531b7b483957c6a7874465d4ede21a7f0cbf7",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Numeric/Nat/Divide.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Numeric/Nat/Divide.agda",
"max_line_length": 94,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Numeric/Nat/Divide.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 856,
"size": 2289
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.