Search is not available for this dataset
text
string | meta
dict |
---|---|
module Issue1760c where
-- Skipping an old-style mutual block: Before the `mutual` keyword.
{-# NO_POSITIVITY_CHECK #-}
mutual
data D : Set where
lam : (D → D) → D
record U : Set where
field ap : U → U
|
{
"alphanum_fraction": 0.6481481481,
"avg_line_length": 19.6363636364,
"ext": "agda",
"hexsha": "a7564dca25c25e08a6e71081f7cf69a9abe2d5c5",
"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/Issue1760c.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/Issue1760c.agda",
"max_line_length": 67,
"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/Issue1760c.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": 66,
"size": 216
}
|
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Properties.Symmetry {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties.Conversion
open import Tools.Embedding
open import Tools.Product
import Tools.PropositionalEquality as PE
mutual
-- Helper function for symmetry of type equality using shape views.
symEqT : ∀ {Γ A B l l′} {[A] : Γ ⊩⟨ l ⟩ A} {[B] : Γ ⊩⟨ l′ ⟩ B}
→ ShapeView Γ l l′ A B [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ B ≡ A / [B]
symEqT (ℕᵥ D D′) A≡B = ιx (ℕ₌ (red D))
symEqT (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ιx (ne₌ M D′ neM K≡M))
rewrite whrDet* (red D′ , ne neM) (red D₁ , ne neK₁) =
ιx (ne₌ _ D neK
(~-sym K≡M))
symEqT {Γ = Γ} (Πᵥ (Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
F₁≡F′ , G₁≡G′ = Π-PE-injectivity ΠF₁G₁≡ΠF′G′
[F₁≡F] : ∀ {Δ} {ρ} [ρ] ⊢Δ → _
[F₁≡F] {Δ} {ρ} [ρ] ⊢Δ =
let ρF′≡ρF₁ ρ = PE.cong (wk ρ) (PE.sym F₁≡F′)
[ρF′] {ρ} [ρ] ⊢Δ = PE.subst (λ x → Δ ⊩⟨ _ ⟩ wk ρ x) F₁≡F′ ([F]₁ [ρ] ⊢Δ)
in irrelevanceEq′ {Δ} (ρF′≡ρF₁ ρ)
([ρF′] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ)
(symEq ([F] [ρ] ⊢Δ) ([ρF′] [ρ] ⊢Δ)
([F≡F′] [ρ] ⊢Δ))
in Π₌ _ _ (red D) (≅-sym (PE.subst (λ x → Γ ⊢ Π F ▹ G ≅ x) (PE.sym ΠF₁G₁≡ΠF′G′) A≡B))
[F₁≡F]
(λ {ρ} [ρ] ⊢Δ [a] →
let ρG′a≡ρG₁′a = PE.cong (λ x → wk (lift ρ) x [ _ ]) (PE.sym G₁≡G′)
[ρG′a] = PE.subst (λ x → _ ⊩⟨ _ ⟩ wk (lift ρ) x [ _ ]) G₁≡G′
([G]₁ [ρ] ⊢Δ [a])
[a]₁ = convTerm₁ ([F]₁ [ρ] ⊢Δ) ([F] [ρ] ⊢Δ) ([F₁≡F] [ρ] ⊢Δ) [a]
in irrelevanceEq′ ρG′a≡ρG₁′a
[ρG′a]
([G]₁ [ρ] ⊢Δ [a])
(symEq ([G] [ρ] ⊢Δ [a]₁) [ρG′a]
([G≡G′] [ρ] ⊢Δ [a]₁)))
symEqT (Uᵥ _ _ _ _ _ _) A≡B = U₌ PE.refl
symEqT (emb⁰¹ PE.refl x) (ιx A≡B) = symEqT x A≡B
symEqT (emb¹⁰ PE.refl x) A≡B = ιx (symEqT x A≡B)
-- Symmetry of type equality.
symEq : ∀ {Γ A B l l′} ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ B ≡ A / [B]
symEq [A] [B] A≡B = symEqT (goodCases [A] [B] A≡B) A≡B
symNeutralTerm : ∀ {t u A Γ}
→ Γ ⊩neNf t ≡ u ∷ A
→ Γ ⊩neNf u ≡ t ∷ A
symNeutralTerm (neNfₜ₌ neK neM k≡m) = neNfₜ₌ neM neK (~-sym k≡m)
symNatural-prop : ∀ {Γ k k′}
→ [Natural]-prop Γ k k′
→ [Natural]-prop Γ k′ k
symNatural-prop (sucᵣ (ℕₜ₌ k k′ d d′ t≡u prop)) =
sucᵣ (ℕₜ₌ k′ k d′ d (≅ₜ-sym t≡u) (symNatural-prop prop))
symNatural-prop zeroᵣ = zeroᵣ
symNatural-prop (ne prop) = ne (symNeutralTerm prop)
-- Symmetry of term equality.
symEqTerm : ∀ {l Γ A t u} ([A] : Γ ⊩⟨ l ⟩ A)
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]
→ Γ ⊩⟨ l ⟩ u ≡ t ∷ A / [A]
symEqTerm (Uᵣ′ .⁰ 0<1 ⊢Γ) (Uₜ₌ A B d d′ typeA typeB A≡B [A] [B] [A≡B]) =
Uₜ₌ B A d′ d typeB typeA (≅ₜ-sym A≡B) [B] [A] (symEq [A] [B] [A≡B])
symEqTerm (ℕᵣ D) (ιx (ℕₜ₌ k k′ d d′ t≡u prop)) =
ιx (ℕₜ₌ k′ k d′ d (≅ₜ-sym t≡u) (symNatural-prop prop))
symEqTerm (ne′ K D neK K≡K) (ιx (neₜ₌ k m d d′ nf)) =
ιx (neₜ₌ m k d′ d (symNeutralTerm nf))
symEqTerm (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πₜ₌ f g d d′ funcF funcG f≡g [f] [g] [f≡g]) =
Πₜ₌ g f d′ d funcG funcF (≅ₜ-sym f≡g) [g] [f]
(λ ρ ⊢Δ [a] → symEqTerm ([G] ρ ⊢Δ [a]) ([f≡g] ρ ⊢Δ [a]))
symEqTerm (emb′ 0<1 x) (ιx t≡u) = ιx (symEqTerm x t≡u)
|
{
"alphanum_fraction": 0.4655172414,
"avg_line_length": 42.7368421053,
"ext": "agda",
"hexsha": "d4d0d6fcd80fb76f0519d2d89b7a4c5b124c794a",
"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/LogicalRelation/Properties/Symmetry.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/LogicalRelation/Properties/Symmetry.agda",
"max_line_length": 90,
"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/LogicalRelation/Properties/Symmetry.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2001,
"size": 4060
}
|
{-# OPTIONS --universe-polymorphism #-}
module Prelude.Stream where
-- open import Coinduction
-- Infinite streams.
open import Prelude.IO
open import Prelude.Nat
open import Prelude.Unit
data Level : Set where
zero : Level
suc : (i : Level) → Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO zero #-}
{-# BUILTIN LEVELSUC suc #-}
infixl 6 _⊔_
_⊔_ : Level → Level → Level
zero ⊔ j = j
suc i ⊔ zero = suc i
suc i ⊔ suc j = suc (i ⊔ j)
{-# BUILTIN LEVELMAX _⊔_ #-}
infix 1000 ♯_
postulate
∞ : ∀ {a} (A : Set a) → Set a
♯_ : ∀ {a} {A : Set a} → A → ∞ A
♭ : ∀ {a} {A : Set a} → ∞ A → A
{-# BUILTIN INFINITY ∞ #-}
{-# BUILTIN SHARP ♯_ #-}
{-# BUILTIN FLAT ♭ #-}
data Stream (A : Set) : Set where
_∷_ : (x : A) (xs : ∞ (Stream A)) → Stream A
-- A stream processor SP A B consumes elements of A and produces
-- elements of B. It can only consume a finite number of A’s before
-- producing a B.
data SP (A B : Set) : Set where
get : (f : A → SP A B) → SP A B
put : (b : B) (sp : ∞ (SP A B)) → SP A B
-- The function eat is defined by an outer corecursion into Stream B
-- and an inner recursion on SP A B.
eat : ∀ {A B} → SP A B → Stream A → Stream B
eat (get f) (a ∷ as) = eat (f a) (♭ as)
eat (put b sp) as = b ∷ ♯ eat (♭ sp) as
-- Composition of stream processors.
_∘_ : ∀ {A B C} → SP B C → SP A B → SP A C
get f₁ ∘ put x sp₂ = f₁ x ∘ ♭ sp₂
put x sp₁ ∘ sp₂ = put x (♯ (♭ sp₁ ∘ sp₂))
sp₁ ∘ get f₂ = get (λ x → sp₁ ∘ f₂ x)
ones : Stream Nat
ones = 1 ∷ (♯ ones)
twos : Stream Nat
twos = 2 ∷ (♯ twos)
printStream : Nat -> Stream Nat -> IO Unit
printStream Z _ = return unit
printStream (S steps) (n ∷ ns) =
printNat n ,,
printStream steps (♭ ns)
main : IO Unit
main = printStream 100 twos
|
{
"alphanum_fraction": 0.5691102406,
"avg_line_length": 23.2077922078,
"ext": "agda",
"hexsha": "88783ce763678eabff4eed897df6020c5aa3b4e2",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/epic/Prelude/Stream.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"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": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/epic/Prelude/Stream.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/epic/Prelude/Stream.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 668,
"size": 1787
}
|
-- Andreas, 2011-05-10
module MetaAppUnderLambda where
data _≡_ {A : Set} (a : A) : A -> Set where
refl : a ≡ a
data D (A : Set) : Set where
cons : A -> (A -> A) -> D A
f : {A : Set} -> D A -> A
f (cons a h) = a
test : (A : Set) ->
let X : A
X = _
Y : A -> A
Y = λ v -> _ v
in f (cons X Y) ≡ X
test A = refl
-- should return "Unsolved Metas"
-- executes the defauls A.App case in the type checker (which is not covered by appView)
|
{
"alphanum_fraction": 0.5102880658,
"avg_line_length": 23.1428571429,
"ext": "agda",
"hexsha": "838794f226f68c9cf783835d587fe27a9acc0450",
"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/fail/MetaAppUnderLambda.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/fail/MetaAppUnderLambda.agda",
"max_line_length": 88,
"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/fail/MetaAppUnderLambda.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": 178,
"size": 486
}
|
-- Andreas, 2015-08-26
{-# OPTIONS --rewriting #-} -- Should give error
open import Agda.Builtin.Equality
open import Common.List
{-# BUILTIN REWRITE _≡_ #-}
lengthMap : {A B : Set} (f : A → B) (xs : List A) →
length (map f xs) ≡ length xs
lengthMap f [] = refl
lengthMap f (x ∷ xs) rewrite lengthMap f xs = refl
{-# REWRITE lengthMap #-}
|
{
"alphanum_fraction": 0.6225352113,
"avg_line_length": 23.6666666667,
"ext": "agda",
"hexsha": "d0fb3bffb75d012a4d51dc62624085af07dec009",
"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/RewritingNotSafe.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/RewritingNotSafe.agda",
"max_line_length": 51,
"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/RewritingNotSafe.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": 113,
"size": 355
}
|
open import Oscar.Prelude
module Oscar.Class.Apply where
module _
(𝔉 : ∀ {𝔣} → Ø 𝔣 → Ø 𝔣)
𝔬₁ 𝔬₂
where
𝓪pply = ∀ {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} → 𝔉 (𝔒₁ → 𝔒₂) → 𝔉 𝔒₁ → 𝔉 𝔒₂
record 𝓐pply : Ø ↑̂ (𝔬₁ ∙̂ 𝔬₂) where
infixl 4 apply
field apply : 𝓪pply
syntax apply f x = f <*> x
open 𝓐pply ⦃ … ⦄ public
_<*>_ = apply
|
{
"alphanum_fraction": 0.5535168196,
"avg_line_length": 18.1666666667,
"ext": "agda",
"hexsha": "309d954a8377dcbe390fd55fed3585e48651c692",
"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/Apply.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/Apply.agda",
"max_line_length": 63,
"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/Apply.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 191,
"size": 327
}
|
open import Coinduction using ( ∞ ; ♯_ ; ♭ )
open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ; sym ; cong )
open import System.IO.Transducers.Lazy using ( _⇒_ ; inp ; out ; done ; _⟫_ ; ⟦_⟧ ; _≃_ ; equiv )
open import System.IO.Transducers.Session using ( Session ; I ; Σ ; _∼_ ; ∼-refl ; ∼-trans )
open import System.IO.Transducers.Trace using ( Trace ; [] ; _∷_ )
open import System.IO.Transducers.Properties.Lemmas using ( ⟦⟧-resp-∼ ; ≃-refl ; ≃-sym ; IsEquiv ; isEquiv ; ≃-equiv ; ∷-refl-≡₁ ; ∷-refl-≡₂ )
module System.IO.Transducers.Properties.Category where
open Relation.Binary.PropositionalEquality.≡-Reasoning
infixr 6 _⟦⟫⟧_
-- Coinductive equivalence of programs, note that in the
-- case where done has type I ⇒ I, this is syntactic
-- identity.
data _⇒_⊨_≣_ : ∀ S T (P Q : S ⇒ T) → Set₁ where
inp : ∀ {A V F T P Q} → ∞ (∀ a → ♭ F a ⇒ T ⊨ ♭ P a ≣ ♭ Q a) →
(Σ {A} V F ⇒ T ⊨ inp P ≣ inp Q)
out : ∀ {B W G S} b {P Q} → (S ⇒ ♭ G b ⊨ P ≣ Q) →
(S ⇒ Σ {B} W G ⊨ out b P ≣ out b Q)
done : ∀ {S} →
(S ⇒ S ⊨ done ≣ done)
inp-done : ∀ {A V F P} → ∞ (∀ a → ♭ F a ⇒ Σ V F ⊨ ♭ P a ≣ out a done) →
(Σ {A} V F ⇒ Σ V F ⊨ inp P ≣ done)
done-inp : ∀ {A V F P} → ∞ (∀ a → ♭ F a ⇒ Σ V F ⊨ out a done ≣ ♭ P a) →
(Σ {A} V F ⇒ Σ V F ⊨ done ≣ inp P)
_≣_ : ∀ {S T} (P Q : S ⇒ T) → Set₁
P ≣ Q = _ ⇒ _ ⊨ P ≣ Q
-- Coinductive equivalence implies semantic equivalence
⟦⟧-resp-≣ : ∀ {S T} {P Q : S ⇒ T} → (P ≣ Q) → (⟦ P ⟧ ≃ ⟦ Q ⟧)
⟦⟧-resp-≣ (inp P≣Q) [] = refl
⟦⟧-resp-≣ (inp P≣Q) (a ∷ as) = ⟦⟧-resp-≣ (♭ P≣Q a) as
⟦⟧-resp-≣ (out b P≣Q) as = cong (_∷_ b) (⟦⟧-resp-≣ P≣Q as)
⟦⟧-resp-≣ done as = refl
⟦⟧-resp-≣ (inp-done P≣outadone) [] = refl
⟦⟧-resp-≣ (inp-done P≣outadone) (a ∷ as) = ⟦⟧-resp-≣ (♭ P≣outadone a) as
⟦⟧-resp-≣ (done-inp outadone≣P) [] = refl
⟦⟧-resp-≣ (done-inp outadone≣P) (a ∷ as) = ⟦⟧-resp-≣ (♭ outadone≣P a) as
-- Semantic equivalence implies coinductive equivalence
⟦⟧-refl-≣ : ∀ {S T} (P Q : S ⇒ T) → (⟦ P ⟧ ≃ ⟦ Q ⟧) → (P ≣ Q)
⟦⟧-refl-≣ (inp P) (inp Q) P≃Q = inp (♯ λ a → ⟦⟧-refl-≣ (♭ P a) (♭ Q a) (λ as → P≃Q (a ∷ as)))
⟦⟧-refl-≣ (inp P) done P≃Q = inp-done (♯ λ a → ⟦⟧-refl-≣ (♭ P a) (out a done) (λ as → P≃Q (a ∷ as)))
⟦⟧-refl-≣ (out b P) (out c Q) P≃Q with ∷-refl-≡₁ refl refl (P≃Q [])
⟦⟧-refl-≣ (out b P) (out .b Q) P≃Q | refl = out b (⟦⟧-refl-≣ P Q (λ as → ∷-refl-≡₂ refl refl (P≃Q as)))
⟦⟧-refl-≣ done (inp Q) P≃Q = done-inp (♯ λ a → ⟦⟧-refl-≣ (out a done) (♭ Q a) (λ as → P≃Q (a ∷ as)))
⟦⟧-refl-≣ done done P≃Q = done
⟦⟧-refl-≣ (inp P) (out b Q) P≃Q with P≃Q []
⟦⟧-refl-≣ (inp P) (out b Q) P≃Q | ()
⟦⟧-refl-≣ (out b P) (inp Q) P≃Q with P≃Q []
⟦⟧-refl-≣ (out b P) (inp Q) P≃Q | ()
⟦⟧-refl-≣ (out b P) done P≃Q with P≃Q []
⟦⟧-refl-≣ (out b P) done P≃Q | ()
⟦⟧-refl-≣ done (out b Q) P≃Q with P≃Q []
⟦⟧-refl-≣ done (out b Q) P≃Q | ()
-- Trace semantics of identity
⟦done⟧ : ∀ {S} → (Trace S) → (Trace S)
⟦done⟧ as = as
done-semantics : ∀ {S} → ⟦ done {S} ⟧ ≃ ⟦done⟧
done-semantics as = refl
-- Trace semantics of composition
_⟦⟫⟧_ : ∀ {S T U} →
(f : Trace S → Trace T) → (g : Trace T → Trace U) →
(Trace S) → (Trace U)
(f ⟦⟫⟧ g) as = g (f as)
⟫-semantics : ∀ {S T U} (P : S ⇒ T) (Q : T ⇒ U) →
(⟦ P ⟫ Q ⟧ ≃ ⟦ P ⟧ ⟦⟫⟧ ⟦ Q ⟧)
⟫-semantics (inp P) (inp Q) [] = refl
⟫-semantics (inp P) (inp Q) (a ∷ as) = ⟫-semantics (♭ P a) (inp Q) as
⟫-semantics (inp P) (out c Q) as = cong (_∷_ c) (⟫-semantics (inp P) Q as)
⟫-semantics (inp P) done as = refl
⟫-semantics (out b P) (inp Q) as = ⟫-semantics P (♭ Q b) as
⟫-semantics (out b P) (out c Q) as = cong (_∷_ c) (⟫-semantics (out b P) Q as)
⟫-semantics (out b P) done as = refl
⟫-semantics done Q as = refl
⟫-≃-⟦⟫⟧ : ∀ {S T U}
{P : S ⇒ T} {f : Trace S → Trace T} {Q : T ⇒ U} {g : Trace T → Trace U} →
(⟦ P ⟧ ≃ f) → (⟦ Q ⟧ ≃ g) → (⟦ P ⟫ Q ⟧ ≃ f ⟦⟫⟧ g)
⟫-≃-⟦⟫⟧ {S} {T} {U} {P} {f} {Q} {g} P≃f Q≃g as =
begin
⟦ P ⟫ Q ⟧ as
≡⟨ ⟫-semantics P Q as ⟩
⟦ Q ⟧ (⟦ P ⟧ as)
≡⟨ cong ⟦ Q ⟧ (P≃f as) ⟩
⟦ Q ⟧ (f as)
≡⟨ Q≃g (f as) ⟩
g (f as)
∎
-- Composition respects ≃
⟫-resp-≃ : ∀ {S T U} {P₁ P₂ : S ⇒ T} {Q₁ Q₂ : T ⇒ U} →
(⟦ P₁ ⟧ ≃ ⟦ P₂ ⟧) → (⟦ Q₁ ⟧ ≃ ⟦ Q₂ ⟧) →
(⟦ P₁ ⟫ Q₁ ⟧ ≃ ⟦ P₂ ⟫ Q₂ ⟧)
⟫-resp-≃ {S} {T} {U} {P₁} {P₂} {Q₁} {Q₂} P₁≃P₂ Q₁≃Q₂ as =
begin
⟦ P₁ ⟫ Q₁ ⟧ as
≡⟨ ⟫-≃-⟦⟫⟧ P₁≃P₂ Q₁≃Q₂ as ⟩
(⟦ P₂ ⟧ ⟦⟫⟧ ⟦ Q₂ ⟧) as
≡⟨ sym (⟫-semantics P₂ Q₂ as) ⟩
⟦ P₂ ⟫ Q₂ ⟧ as
∎
-- Left identity of composition
⟫-identity₁ : ∀ {S T} (P : S ⇒ T) → ⟦ done ⟫ P ⟧ ≃ ⟦ P ⟧
⟫-identity₁ P = ⟫-semantics done P
-- Right identity of composition
⟫-identity₂ : ∀ {S T} (P : S ⇒ T) → ⟦ P ⟫ done ⟧ ≃ ⟦ P ⟧
⟫-identity₂ P = ⟫-semantics P done
-- Associativity of composition
⟫-assoc : ∀ {S T U V} (P : S ⇒ T) (Q : T ⇒ U) (R : U ⇒ V) →
⟦ (P ⟫ Q) ⟫ R ⟧ ≃ ⟦ P ⟫ (Q ⟫ R) ⟧
⟫-assoc P Q R as =
begin
⟦ (P ⟫ Q) ⟫ R ⟧ as
≡⟨ ⟫-≃-⟦⟫⟧ (⟫-semantics P Q) ≃-refl as ⟩
(⟦ P ⟧ ⟦⟫⟧ ⟦ Q ⟧ ⟦⟫⟧ ⟦ R ⟧) as
≡⟨ sym (⟫-≃-⟦⟫⟧ ≃-refl (⟫-semantics Q R) as) ⟩
⟦ P ⟫ (Q ⟫ R) ⟧ as
∎
-- Identity is an equivalence
equiv-resp-done : ∀ {S} → ⟦ done ⟧ ≃ ⟦ equiv (∼-refl {S}) ⟧
equiv-resp-done {I} as = refl
equiv-resp-done {Σ V F} [] = refl
equiv-resp-done {Σ V F} (a ∷ as) = cong (_∷_ a) (equiv-resp-done as)
done-isEquiv : ∀ {S} → IsEquiv (done {S})
done-isEquiv = isEquiv {P = done} ∼-refl equiv-resp-done
-- Composition respects being an equivalence
equiv-resp-⟦⟫⟧ : ∀ {S T U} (S∼T : S ∼ T) (T∼U : T ∼ U) →
⟦ equiv S∼T ⟧ ⟦⟫⟧ ⟦ equiv T∼U ⟧ ≃ ⟦ equiv (∼-trans S∼T T∼U) ⟧
equiv-resp-⟦⟫⟧ I I as = refl
equiv-resp-⟦⟫⟧ (Σ W F) (Σ .W G) [] = refl
equiv-resp-⟦⟫⟧ (Σ W F) (Σ .W G) (a ∷ as) = cong (_∷_ a) (equiv-resp-⟦⟫⟧ (♭ F a) (♭ G a) as)
equiv-resp-⟫ : ∀ {S T U} (S∼T : S ∼ T) (T∼U : T ∼ U) →
⟦ equiv S∼T ⟫ equiv T∼U ⟧ ≃ ⟦ equiv (∼-trans S∼T T∼U) ⟧
equiv-resp-⟫ S∼T T∼U as =
begin
⟦ equiv S∼T ⟫ equiv T∼U ⟧ as
≡⟨ ⟫-semantics (equiv S∼T) (equiv T∼U) as ⟩
(⟦ equiv S∼T ⟧ ⟦⟫⟧ ⟦ equiv T∼U ⟧) as
≡⟨ equiv-resp-⟦⟫⟧ S∼T T∼U as ⟩
⟦ equiv (∼-trans S∼T T∼U) ⟧ as
∎
⟫-isEquiv : ∀ {S T U} {P : S ⇒ T} {Q : T ⇒ U} →
(IsEquiv P) → (IsEquiv Q) → (IsEquiv (P ⟫ Q))
⟫-isEquiv {S} {T} {U} {P} {Q} (isEquiv S∼T P≃S∼T) (isEquiv (T∼U) (Q≃T∼U)) =
isEquiv (∼-trans S∼T T∼U) λ as →
begin
⟦ P ⟫ Q ⟧ as
≡⟨ ⟫-resp-≃ P≃S∼T Q≃T∼U as ⟩
⟦ equiv S∼T ⟫ equiv T∼U ⟧ as
≡⟨ equiv-resp-⟫ S∼T T∼U as ⟩
⟦ equiv (∼-trans S∼T T∼U) ⟧ as
∎
-- Equivalences form isos
equiv-is-iso : ∀ {S T} {P : S ⇒ T} {Q : T ⇒ S} →
(IsEquiv P) → (IsEquiv Q) → ⟦ P ⟫ Q ⟧ ≃ ⟦ done ⟧
equiv-is-iso PisEq QisEq =
≃-equiv (⟫-isEquiv PisEq QisEq) done-isEquiv
|
{
"alphanum_fraction": 0.4644696189,
"avg_line_length": 36.5430107527,
"ext": "agda",
"hexsha": "b80ab09b7b06329b8296c4c6b428f6b16f1f0a17",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z",
"max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ilya-fiveisky/agda-system-io",
"max_forks_repo_path": "src/System/IO/Transducers/Properties/Category.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"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": "ilya-fiveisky/agda-system-io",
"max_issues_repo_path": "src/System/IO/Transducers/Properties/Category.agda",
"max_line_length": 142,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ilya-fiveisky/agda-system-io",
"max_stars_repo_path": "src/System/IO/Transducers/Properties/Category.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z",
"num_tokens": 3665,
"size": 6797
}
|
{-# OPTIONS --without-K --safe #-}
-- Categorical equivalences preserve various structures
module Categories.Category.Equivalence.Preserves where
open import Level
open import Categories.Adjoint.Equivalence using (⊣Equivalence)
open import Categories.Category.Core
open import Categories.Category.Equivalence using (WeakInverse; StrongEquivalence)
open import Categories.Category.Equivalence.Properties using (C≅D)
open import Categories.Diagram.Duality
open import Categories.Functor.Core
open import Categories.Morphism
import Categories.Morphism.Reasoning as MR
open import Categories.NaturalTransformation.NaturalIsomorphism.Properties
open import Categories.Object.Initial
open import Categories.Object.Terminal
open import Categories.Object.Duality
private
variable
o ℓ e o′ ℓ′ e′ : Level
C : Category o ℓ e
D : Category o′ ℓ′ e′
module _ (S : StrongEquivalence C D) where
open StrongEquivalence S
open IsInitial
private
module C = Category C
module D = Category D
module F = Functor F
module G = Functor G
X : ⊣Equivalence C D
X = C≅D S
-- see below the proof for the abbreviations that make the proof readable
pres-IsInitial : {c : C.Obj} (i : IsInitial C c) → IsInitial D (F.₀ c)
pres-IsInitial {c} i = record
{ ! = λ {A} → F∘G≈id.⇒.η A D.∘ F.₁ (! i)
; !-unique = λ {A} f → begin {- f : F.₀ c D.⇒ A -}
FG⇒ A D.∘ F.₁ (! i) ≈⟨ (refl⟩∘⟨ F.F-resp-≈ (!-unique i _)) ⟩
FG⇒ A D.∘ F.₁ ((G.₁ f C.∘ GF⇒) C.∘ G.₁ FG⇐′ C.∘ GF⇐) ≈⟨ (refl⟩∘⟨ F.homomorphism) ⟩
FG⇒ A D.∘ F.₁ (G.₁ f C.∘ GF⇒) D.∘ F.₁ (G.₁ FG⇐′ C.∘ GF⇐) ≈⟨ (refl⟩∘⟨ refl⟩∘⟨ (F.homomorphism ○ (D.Equiv.sym (F≃id-comm₂ F∘G≈id) ⟩∘⟨refl))) ⟩
FG⇒ A D.∘ F.₁ (G.₁ f C.∘ GF⇒) D.∘ FG⇐ D.∘ F.F₁ GF⇐ ≈⟨ (refl⟩∘⟨ F.homomorphism ⟩∘⟨refl) ⟩
FG⇒ A D.∘ (F.₁ (G.₁ f) D.∘ F.₁ GF⇒) D.∘ (FG⇐ D.∘ F.F₁ GF⇐) ≈⟨ (D.sym-assoc ○ (D.sym-assoc ⟩∘⟨refl) ○ D.assoc) ⟩
(FG⇒ A D.∘ F.₁ (G.₁ f)) D.∘ F.F₁ GF⇒ D.∘ FG⇐ D.∘ F.F₁ GF⇐ ≈⟨ (F∘G≈id.⇒.commute f ⟩∘⟨ D.sym-assoc) ⟩
(f D.∘ FG⇒ (F.₀ c)) D.∘ (F.F₁ GF⇒ D.∘ FG⇐) D.∘ F.F₁ GF⇐ ≈⟨ (D.assoc ○ (refl⟩∘⟨ D.sym-assoc)) ⟩
f D.∘ (FG⇒ (F.₀ c) D.∘ F.F₁ GF⇒ D.∘ FG⇐) D.∘ F.F₁ GF⇐ ≈⟨ elimʳ (⊣Equivalence.zig X) ⟩
f ∎
}
where
open D.HomReasoning
open MR D
FG⇒ : (A : D.Obj) → F.₀ (G.₀ A) D.⇒ A
FG⇒ A = F∘G≈id.⇒.η A
FG⇐ = F∘G≈id.⇐.η (F.F₀ (G.F₀ (F.F₀ c)))
FG⇐′ = F∘G≈id.⇐.η (F.₀ c)
GF⇐ : c C.⇒ G.₀ (F.₀ c)
GF⇐ = G∘F≈id.⇐.η c
GF⇒ = G∘F≈id.⇒.η (G.F₀ (F.F₀ c))
pres-Initial : Initial C → Initial D
pres-Initial i = record { ⊥ = F.₀ ⊥ ; ⊥-is-initial = pres-IsInitial ⊥-is-initial }
where open Initial i
-- We can do the other proof by duality
pres-terminal : {C : Category o ℓ e} {D : Category o′ ℓ′ e′} (S : StrongEquivalence C D) {c : Category.Obj C} → (t : IsTerminal C c) → IsTerminal D (Functor.F₀ (StrongEquivalence.F S) c)
pres-terminal {C = C} {D} S {c} t = IsInitial⇒coIsTerminal (Category.op D) (pres-IsInitial Sop (coIsTerminal⇒IsInitial (Category.op C) t))
where
Sop : StrongEquivalence (Category.op C) (Category.op D)
Sop = StrongEquivalence.op S
pres-Terminal : {C : Category o ℓ e} {D : Category o′ ℓ′ e′} (S : StrongEquivalence C D) (t : Terminal C) → Terminal D
pres-Terminal S t = record { ⊤ = Functor.F₀ F ⊤; ⊤-is-terminal = pres-terminal S ⊤-is-terminal}
where
open Terminal t
open StrongEquivalence S
|
{
"alphanum_fraction": 0.5951417004,
"avg_line_length": 42.6913580247,
"ext": "agda",
"hexsha": "92e9728e07ca712014d07dd152bc61818198a4c4",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Equivalence/Preserves.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Equivalence/Preserves.agda",
"max_line_length": 186,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Equivalence/Preserves.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 1512,
"size": 3458
}
|
-- An ATP local hint cannot be equal to the conjecture in which it is
-- used.
-- This error is detected by Syntax.Translation.ConcreteToAbstract.
module ATPBadLocalHint1 where
postulate
D : Set
p : D
{-# ATP prove p p #-}
|
{
"alphanum_fraction": 0.7142857143,
"avg_line_length": 17.7692307692,
"ext": "agda",
"hexsha": "38bb9631bebae8118bc06b55eb24854453dea8b4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "asr/eagda",
"max_forks_repo_path": "test/fail/ATPBadLocalHint1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "asr/eagda",
"max_issues_repo_path": "test/fail/ATPBadLocalHint1.agda",
"max_line_length": 69,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "asr/eagda",
"max_stars_repo_path": "test/fail/ATPBadLocalHint1.agda",
"max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z",
"num_tokens": 61,
"size": 231
}
|
------------------------------------------------------------------------
-- Reduced canonical kinding for the undecidability proof
------------------------------------------------------------------------
{-# OPTIONS --safe --exact-split --without-K #-}
module FOmegaInt.Kinding.Canonical.Reduced where
open import Data.Context.WellFormed
open import Data.Fin using (Fin; zero; suc)
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Fin.Substitution.Typed
open import Data.List using ([]; _∷_; _++_)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product using (∃; _,_; _×_)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Vec as Vec using ([]; _∷_)
open import Data.Vec.Properties as VecProps using (map-∘; map-cong)
open import Function using (_∘_)
open import Level using () renaming (zero to lzero)
open import Relation.Binary.PropositionalEquality
open import FOmegaInt.Syntax
open import FOmegaInt.Syntax.HereditarySubstitution using (Kind/⟨★⟩-/)
import FOmegaInt.Kinding.Canonical as CanonicalKinding
module C where
open CanonicalKinding public
open Kinding public
------------------------------------------------------------------------
-- Reduced canonical kinding derivations.
module Kinding where
open ElimCtx
open Syntax
open Substitution using (_Kind′[_])
infix 4 _⊢_wf _ctx _⊢_kd
infix 4 _⊢Nf_⇉_ _⊢Ne_⇉_ _⊢Var_⇉_ _⊢_⇉∙_⇉_ _⊢Nf_⇇_
infix 4 _⊢_<∷_ _⊢_∼_
infix 4 _⊢_⇉∙_∼_⇉_
mutual
-- Formation of kinds, bindings, and contexts.
--
-- NOTE. The rule kd-Π only supports first-order operators.
data _⊢_kd {n} (Γ : Ctx n) : Kind Elim n → Set where
kd-⋯ : ∀ {a b} → Γ ⊢Nf a ⇉ a ⋯ a → Γ ⊢Nf b ⇉ b ⋯ b → Γ ⊢ a ⋯ b kd
kd-Π : ∀ {a b k} → Γ ⊢Nf a ⇉ a ⋯ a → Γ ⊢Nf b ⇉ b ⋯ b →
kd (a ⋯ b) ∷ Γ ⊢ k kd → Γ ⊢ Π (a ⋯ b) k kd
data _⊢_wf {n} (Γ : Ctx n) : ElimAsc n → Set where
wf-kd : ∀ {a} → Γ ⊢ a kd → Γ ⊢ kd a wf
wf-tp : ∀ {a} → Γ ⊢Nf a ⇉ a ⋯ a → Γ ⊢ tp a wf
_ctx : ∀ {n} → Ctx n → Set
Γ ctx = ContextFormation._wf _⊢_wf Γ
-- Kind synthesis for variables, neutrals and βη-normal types.
data _⊢Var_⇉_ {n} (Γ : Ctx n) : Fin n → Kind Elim n → Set where
⇉-var : ∀ {k} x → Γ ctx → lookup Γ x ≡ kd k → Γ ⊢Var x ⇉ k
data _⊢Ne_⇉_ {n} (Γ : Ctx n) : Elim n → Kind Elim n → Set where
⇉-∙ : ∀ {x j k} {as : Spine n} → Γ ⊢Var x ⇉ j →
Γ ⊢ j ⇉∙ as ⇉ k → Γ ⊢Ne var x ∙ as ⇉ k
data _⊢Nf_⇉_ {n} (Γ : Ctx n) : Elim n → Kind Elim n → Set where
⇉-⊥-f : Γ ctx → Γ ⊢Nf ⊥∙ ⇉ ⊥∙ ⋯ ⊥∙
⇉-⊤-f : Γ ctx → Γ ⊢Nf ⊤∙ ⇉ ⊤∙ ⋯ ⊤∙
⇉-s-i : ∀ {a b c} → Γ ⊢Ne a ⇉ b ⋯ c → Γ ⊢Nf a ⇉ a ⋯ a
-- Kind checking for η-long β-normal types.
data _⊢Nf_⇇_ {n} (Γ : Ctx n) : Elim n → Kind Elim n → Set where
⇇-⇑ : ∀ {a j k} → Γ ⊢Nf a ⇉ j → Γ ⊢ j <∷ k → Γ ⊢Nf a ⇇ k
-- Kind synthesis for spines.
--
-- Note the use of ordinary (instead of hereditary) substitution.
data _⊢_⇉∙_⇉_ {n} (Γ : Ctx n)
: Kind Elim n → Spine n → Kind Elim n → Set where
⇉-[] : ∀ {k} → Γ ⊢ k ⇉∙ [] ⇉ k
⇉-∷ : ∀ {a as b c j k} → Γ ⊢Nf a ⇇ b ⋯ c →
Γ ⊢ j Kind′[ ⌞ a ⌟ ] ⇉∙ as ⇉ k → Γ ⊢ Π (b ⋯ c) j ⇉∙ a ∷ as ⇉ k
-- Reduced canonical subkinding derivations.
--
-- NOTE. The rule <∷-Π only supports first-order operators.
data _⊢_<∷_ {n} (Γ : Ctx n) : Kind Elim n → Kind Elim n → Set where
<∷-⋯ : ∀ {a₁ a₂ b₁ b₂} →
Γ ⊢ a₂ ∼ a₁ → Γ ⊢ b₁ ∼ b₂ → Γ ⊢ a₁ ⋯ b₁ <∷ a₂ ⋯ b₂
<∷-Π : ∀ {a₁ a₂ b₁ b₂ k₁ k₂} → Γ ⊢ a₁ ∼ a₂ → Γ ⊢ b₂ ∼ b₁ →
kd (a₂ ⋯ b₂) ∷ Γ ⊢ k₁ <∷ k₂ →
Γ ⊢ Π (a₁ ⋯ b₁) k₁ <∷ Π (a₂ ⋯ b₂) k₂
-- Canonical relatedness of proper types and spines.
data _⊢_∼_ {n} (Γ : Ctx n) : Elim n → Elim n → Set where
∼-trans : ∀ {a b c} → Γ ⊢ a ∼ b → Γ ⊢ b ∼ c → Γ ⊢ a ∼ c
∼-⊥ : ∀ {a} → Γ ⊢Nf a ⇉ a ⋯ a → Γ ⊢ ⊥∙ ∼ a
∼-⊤ : ∀ {a} → Γ ⊢Nf a ⇉ a ⋯ a → Γ ⊢ a ∼ ⊤∙
∼-∙ : ∀ {x as₁ as₂ k b c} →
Γ ⊢Var x ⇉ k → Γ ⊢ k ⇉∙ as₁ ∼ as₂ ⇉ b ⋯ c →
Γ ⊢ var x ∙ as₁ ∼ var x ∙ as₂
∼-⟨| : ∀ {a b c} → Γ ⊢Ne a ⇉ b ⋯ c → Γ ⊢ b ∼ a
∼-|⟩ : ∀ {a b c} → Γ ⊢Ne a ⇉ b ⋯ c → Γ ⊢ a ∼ c
data _⊢_⇉∙_∼_⇉_ {n} (Γ : Ctx n)
: Kind Elim n → Spine n → Spine n → Kind Elim n → Set where
∼-[] : ∀ {k} → Γ ⊢ k ⇉∙ [] ∼ [] ⇉ k
∼-∷ : ∀ {a as b bs c d j k} → Γ ⊢ c ∼ a → Γ ⊢ a ∼ d →
Γ ⊢ a ∼ b → Γ ⊢ j Kind′[ ⌞ a ⌟ ] ⇉∙ as ∼ bs ⇉ k →
Γ ⊢ Π (c ⋯ d) j ⇉∙ a ∷ as ∼ b ∷ bs ⇉ k
-- Well-formed context extensions.
open ContextFormation _⊢_wf public hiding (_wf; _⊢_wfExt)
-- A wrapper for the kind checking judgment that also supports
-- arbitrary variable bindings.
infix 4 _⊢NfOrVar_∈_
data _⊢NfOrVar_∈_ {n} (Γ : Ctx n) : Term n → ElimAsc n → Set where
∈-nf : ∀ {a b c d e} → Γ ⊢Nf a ⇇ c ⋯ d → ⌞ a ⌟ ≡ b → kd (c ⋯ d) ≡ e →
Γ ⊢NfOrVar b ∈ e
∈-var : ∀ x {a b} → Γ ctx → var x ≡ a → lookup Γ x ≡ b →
Γ ⊢NfOrVar a ∈ b
------------------------------------------------------------------------
-- Simple properties of canonical kindings
open Syntax
open ElimCtx hiding (_++_)
open Kinding
-- An inversion lemma for interval subkinding.
<∷-⋯-inv : ∀ {n} {Γ : Ctx n} {k a₂ b₂} → Γ ⊢ k <∷ a₂ ⋯ b₂ →
∃ λ a₁ → ∃ λ b₁ → Γ ⊢ a₂ ∼ a₁ × Γ ⊢ b₁ ∼ b₂ × k ≡ a₁ ⋯ b₁
<∷-⋯-inv (<∷-⋯ a₂∼a₁ b₁∼b₂) = _ , _ , a₂∼a₁ , b₁∼b₂ , refl
-- An inversion lemma for _⊢_wf.
wf-kd-inv : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ kd k wf → Γ ⊢ k kd
wf-kd-inv (wf-kd k-kd) = k-kd
-- The synthesized kind of a normal proper type is exactly the singleton
-- containing that type.
Nf⇉-≡ : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇉ k → k ≡ a ⋯ a
Nf⇉-≡ (⇉-⊥-f Γ-ctx) = refl
Nf⇉-≡ (⇉-⊤-f Γ-ctx) = refl
Nf⇉-≡ (⇉-s-i a∈b⋯c) = refl
-- Derived singleton introduction rules where the premises are
-- well-kinded normal forms rather than neutrals.
Nf⇉-s-i : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇉ k → Γ ⊢Nf a ⇉ a ⋯ a
Nf⇉-s-i a⇉b⋯c with Nf⇉-≡ a⇉b⋯c
Nf⇉-s-i a⇉a⋯a | refl = a⇉a⋯a
Nf⇇-s-i : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇇ b ⋯ c → Γ ⊢Nf a ⇉ a ⋯ a
Nf⇇-s-i (⇇-⇑ a⇉b₁⋯c₁ (<∷-⋯ b₂∼b₁ c₁∼c₂)) = Nf⇉-s-i a⇉b₁⋯c₁
-- The synthesized kinds of neutrals kind-check.
Nf⇇-ne : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Ne a ⇉ b ⋯ c → Γ ⊢Nf a ⇇ b ⋯ c
Nf⇇-ne (⇉-∙ x∈k k⇉as⇉b⋯c) =
⇇-⇑ (⇉-s-i (⇉-∙ x∈k k⇉as⇉b⋯c))
(<∷-⋯ (∼-⟨| (⇉-∙ x∈k k⇉as⇉b⋯c)) (∼-|⟩ (⇉-∙ x∈k k⇉as⇉b⋯c)))
-- The contexts of (most of) the above judgments are well-formed.
--
-- NOTE. The exceptions are again the spine judgments. See the
-- comment on context validity in FOmegaInt.Kinding.Canonical for why
-- this doesn't matter.
Var⇉-ctx : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Var a ⇉ k → Γ ctx
Var⇉-ctx (⇉-var x Γ-ctx _) = Γ-ctx
Ne⇉-ctx : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Ne a ⇉ k → Γ ctx
Ne⇉-ctx (⇉-∙ x∈j j⇉as⇉k) = Var⇉-ctx x∈j
Nf⇉-ctx : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇉ k → Γ ctx
Nf⇉-ctx (⇉-⊥-f Γ-ctx) = Γ-ctx
Nf⇉-ctx (⇉-⊤-f Γ-ctx) = Γ-ctx
Nf⇉-ctx (⇉-s-i a∈b⋯c) = Ne⇉-ctx a∈b⋯c
Nf⇇-ctx : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Nf a ⇇ k → Γ ctx
Nf⇇-ctx (⇇-⇑ a⇉j j<∷k) = Nf⇉-ctx a⇉j
kd-ctx : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ctx
kd-ctx (kd-⋯ a⇉a⋯a b⇉b⋯b) = Nf⇉-ctx a⇉a⋯a
kd-ctx (kd-Π a⇉a⋯a b⇉b⋯b k-kd) = Nf⇉-ctx a⇉a⋯a
∼-ctx : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a ∼ b → Γ ctx
∼-ctx (∼-trans a∼b b∼c) = ∼-ctx a∼b
∼-ctx (∼-⊥ a⇉a⋯a) = Nf⇉-ctx a⇉a⋯a
∼-ctx (∼-⊤ a⇉a⋯a) = Nf⇉-ctx a⇉a⋯a
∼-ctx (∼-∙ x∈j as∼bs) = Var⇉-ctx x∈j
∼-ctx (∼-⟨| a∈b⋯c) = Ne⇉-ctx a∈b⋯c
∼-ctx (∼-|⟩ a∈b⋯c) = Ne⇉-ctx a∈b⋯c
<∷-ctx : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j <∷ k → Γ ctx
<∷-ctx (<∷-⋯ a₂∼a₁ b₁∼b₂) = ∼-ctx a₂∼a₁
<∷-ctx (<∷-Π a₁∼a₂ b₂∼b₁ k₁<∷k₂) = ∼-ctx a₁∼a₂
wf-ctx : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢ a wf → Γ ctx
wf-ctx (wf-kd k-kd) = kd-ctx k-kd
wf-ctx (wf-tp a⇉a⋯a) = Nf⇉-ctx a⇉a⋯a
NfOrVar∈-ctx : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢NfOrVar a ∈ b → Γ ctx
NfOrVar∈-ctx (∈-nf a⇇c⋯d _ _) = Nf⇇-ctx a⇇c⋯d
NfOrVar∈-ctx (∈-var x Γ-ctx _ _) = Γ-ctx
-- Reflexivity of the various relations.
mutual
<∷-refl : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k <∷ k
<∷-refl (kd-⋯ a⇉a⋯a b⇉b⋯b) = <∷-⋯ (∼-refl a⇉a⋯a) (∼-refl b⇉b⋯b)
<∷-refl (kd-Π a⇉a⋯a b⇉b⋯b k-kd) =
<∷-Π (∼-refl a⇉a⋯a) (∼-refl b⇉b⋯b) (<∷-refl k-kd)
∼-refl : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇉ b ⋯ c → Γ ⊢ a ∼ a
∼-refl (⇉-⊥-f Γ-ctx) = ∼-⊥ (⇉-⊥-f Γ-ctx)
∼-refl (⇉-⊤-f Γ-ctx) = ∼-⊤ (⇉-⊤-f Γ-ctx)
∼-refl (⇉-s-i (⇉-∙ x∈j j⇉as⇉k)) = ∼-∙ x∈j (∼Sp-refl j⇉as⇉k)
∼Sp-refl : ∀ {n} {Γ : Ctx n} {as j k} →
Γ ⊢ j ⇉∙ as ⇉ k → Γ ⊢ j ⇉∙ as ∼ as ⇉ k
∼Sp-refl ⇉-[] = ∼-[]
∼Sp-refl (⇉-∷ (⇇-⇑ a⇉b₁⋯c₁ (<∷-⋯ b₂∼b₁ c₁∼c₂)) k[a]⇉as⇉l)
with Nf⇉-≡ a⇉b₁⋯c₁
∼Sp-refl (⇉-∷ (⇇-⇑ a⇉a⋯a (<∷-⋯ b∼a a∼c)) k[a]⇉as⇉l) | refl =
∼-∷ b∼a a∼c (∼-refl a⇉a⋯a) (∼Sp-refl k[a]⇉as⇉l)
-- Admissible projection rules for canonically kinded proper types.
∼-⟨|-Nf⇉ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇉ b ⋯ c → Γ ⊢ b ∼ a
∼-⟨|-Nf⇉ a⇉b⋯c with Nf⇉-≡ a⇉b⋯c
∼-⟨|-Nf⇉ a⇉a⋯a | refl = ∼-refl a⇉a⋯a
∼-⟨|-Nf⇇ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇇ b ⋯ c → Γ ⊢ b ∼ a
∼-⟨|-Nf⇇ (⇇-⇑ a⇉b₁⋯c₁ (<∷-⋯ b₂∼b₁ c₁∼c₂)) =
∼-trans b₂∼b₁ (∼-⟨|-Nf⇉ a⇉b₁⋯c₁)
∼-|⟩-Nf⇉ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇉ b ⋯ c → Γ ⊢ a ∼ c
∼-|⟩-Nf⇉ a⇉b⋯c with Nf⇉-≡ a⇉b⋯c
∼-|⟩-Nf⇉ a⇉a⋯a | refl = ∼-refl a⇉a⋯a
∼-|⟩-Nf⇇ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Nf a ⇇ b ⋯ c → Γ ⊢ a ∼ c
∼-|⟩-Nf⇇ (⇇-⇑ a⇉b₁⋯c₁ (<∷-⋯ b₂∼b₁ c₁∼c₂)) =
∼-trans (∼-|⟩-Nf⇉ a⇉b₁⋯c₁) c₁∼c₂
-- Spines with interval-kinded heads are empty, and therefore have
-- interval-kinded tails.
Sp⇉-⋯ : ∀ {n} {Γ : Ctx n} {as b c k} →
Γ ⊢ b ⋯ c ⇉∙ as ⇉ k → as ≡ [] × k ≡ b ⋯ c
Sp⇉-⋯ ⇉-[] = refl , refl
Sp∼-⋯ : ∀ {n} {Γ : Ctx n} {as bs c d k} →
Γ ⊢ c ⋯ d ⇉∙ as ∼ bs ⇉ k → as ≡ [] × bs ≡ [] × k ≡ c ⋯ d
Sp∼-⋯ ∼-[] = refl , refl , refl
----------------------------------------------------------------------
-- Well-kinded/typed substitutions (i.e. substitution lemmas)
-- A shorthand for kindings and typings of Ts by kind or type
-- ascriptions.
ElimAscTyping : (ℕ → Set) → Set₁
ElimAscTyping T = Typing ElimAsc T ElimAsc Level.zero
-- Liftings from well-typed Ts to well-typed/kinded normal forms or
-- variables.
LiftTo-NfOrVar∈ : ∀ {T} → ElimAscTyping T → Set₁
LiftTo-NfOrVar∈ _⊢T_∈_ =
LiftTyped Substitution.elimAscTermSubst _⊢_wf _⊢T_∈_ _⊢NfOrVar_∈_
-- A helper lemma about untyped T-substitutions in raw kinds.
record TypedSubstAppHelpers {T} (rawLift : Lift T Term) : Set where
open Substitution using (_Kind′[_])
module A = SubstApp rawLift
module L = Lift rawLift
-- Substitutions in kinds and types commute.
field Kind/-sub-↑ : ∀ {m n} k a (σ : Sub T m n) →
k Kind′[ ⌞ a ⌟ ] A.Kind′/ σ ≡
(k A.Kind′/ σ L.↑) Kind′[ ⌞ a A.Elim/ σ ⌟ ]
-- Application of generic well-typed T-substitutions to all the judgments.
module TypedSubstApp {T : ℕ → Set} (_⊢T_∈_ : ElimAscTyping T)
(liftTyped : LiftTo-NfOrVar∈ _⊢T_∈_)
(helpers : TypedSubstAppHelpers
(LiftTyped.rawLift liftTyped))
where
open LiftTyped liftTyped renaming (lookup to /∈-lookup) hiding (∈-var)
open TypedSubstAppHelpers helpers
-- Well-typed/kinded substitutions preserve all the judgments.
mutual
wf-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a σ} →
Γ ⊢ a wf → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A.ElimAsc/ σ wf
wf-/ (wf-kd k-kd) σ∈Γ = wf-kd (kd-/ k-kd σ∈Γ)
wf-/ (wf-tp a⇉a⋯a) σ∈Γ = wf-tp (Nf⇉-/ a⇉a⋯a σ∈Γ)
kd-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {k σ} →
Γ ⊢ k kd → Δ ⊢/ σ ∈ Γ → Δ ⊢ k A.Kind′/ σ kd
kd-/ (kd-⋯ a⇉a⋯a b⇉b⋯b) σ∈Γ =
kd-⋯ (Nf⇉-/ a⇉a⋯a σ∈Γ) (Nf⇉-/ b⇉b⋯b σ∈Γ)
kd-/ (kd-Π a⇉a⋯a b⇉b⋯b k-kd) σ∈Γ =
let a/σ⇉a/σ⋯a/σ = Nf⇉-/ a⇉a⋯a σ∈Γ
b/σ⇉b/σ⋯b/σ = Nf⇉-/ b⇉b⋯b σ∈Γ
in kd-Π a/σ⇉a/σ⋯a/σ b/σ⇉b/σ⋯b/σ
(kd-/ k-kd (∈-↑ (wf-kd (kd-⋯ a/σ⇉a/σ⋯a/σ b/σ⇉b/σ⋯b/σ)) σ∈Γ))
Ne⇉-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a k σ} →
Γ ⊢Ne a ⇉ k → Δ ⊢/ σ ∈ Γ →
Δ ⊢Nf a A.Elim/ σ ⇇ k A.Kind′/ σ ⊎
Δ ⊢Ne a A.Elim/ σ ⇉ k A.Kind′/ σ
Ne⇉-/ (⇉-∙ (⇉-var x Γ-ctx Γ[x]≡j) j⇉as⇉k) σ∈Γ with ∈-lift (/∈-lookup σ∈Γ x)
... | ∈-nf {a} a⇇c⋯d ⌞a⌟≡σ[x] c⋯d≡Γ[x]/σ =
let c⋯d≡j/σ = kd-inj (trans c⋯d≡Γ[x]/σ (cong (A._ElimAsc/ _) Γ[x]≡j))
c⋯d⇉as/σ⇉k/σ = subst (_ ⊢_⇉∙ _ ⇉ _) (sym c⋯d≡j/σ) (Sp⇉-/ j⇉as⇉k σ∈Γ)
as≡[] , k/σ≡c⋯d = Sp⇉-⋯ c⋯d⇉as/σ⇉k/σ
a≡⌜σ[x]⌝ = trans (sym (⌜⌝∘⌞⌟-id a)) (cong ⌜_⌝ ⌞a⌟≡σ[x])
⌜σ[x]⌝∙∙as≡a = trans (cong₂ _∙∙_ (sym a≡⌜σ[x]⌝) as≡[]) (∙∙-[] _)
in inj₁ (subst₂ (_ ⊢Nf_⇇_) (sym ⌜σ[x]⌝∙∙as≡a) (sym k/σ≡c⋯d) a⇇c⋯d)
... | ∈-var y Δ-ctx y≡σ[x] Δ[y]≡Γ[x]/σ =
let Δ[y]≡j/σ = trans Δ[y]≡Γ[x]/σ (cong (A._ElimAsc/ _) Γ[x]≡j)
in inj₂ (subst (_ ⊢Ne_⇉ _) (cong (_∙∙ _) (cong ⌜_⌝ y≡σ[x]))
(⇉-∙ (⇉-var y Δ-ctx Δ[y]≡j/σ) (Sp⇉-/ j⇉as⇉k σ∈Γ)))
Nf⇉-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a k σ} →
Γ ⊢Nf a ⇉ k → Δ ⊢/ σ ∈ Γ → Δ ⊢Nf a A.Elim/ σ ⇉ k A.Kind′/ σ
Nf⇉-/ (⇉-⊥-f Γ-ctx) σ∈Γ = ⇉-⊥-f (/∈-wf σ∈Γ)
Nf⇉-/ (⇉-⊤-f Γ-ctx) σ∈Γ = ⇉-⊤-f (/∈-wf σ∈Γ)
Nf⇉-/ (⇉-s-i a∈b⋯c) σ∈Γ with Ne⇉-/ a∈b⋯c σ∈Γ
... | inj₁ a/σ⇇b/σ⋯c/σ = Nf⇇-s-i a/σ⇇b/σ⋯c/σ
... | inj₂ a/σ⇉b/σ⋯c/σ = ⇉-s-i a/σ⇉b/σ⋯c/σ
Nf⇇-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a k σ} →
Γ ⊢Nf a ⇇ k → Δ ⊢/ σ ∈ Γ → Δ ⊢Nf a A.Elim/ σ ⇇ k A.Kind′/ σ
Nf⇇-/ (⇇-⇑ a⇉j j<∷k) σ∈Γ = ⇇-⇑ (Nf⇉-/ a⇉j σ∈Γ) (<∷-/ j<∷k σ∈Γ)
Sp⇉-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {as j k σ} →
Γ ⊢ j ⇉∙ as ⇉ k → Δ ⊢/ σ ∈ Γ →
Δ ⊢ j A.Kind′/ σ ⇉∙ as A.// σ ⇉ k A.Kind′/ σ
Sp⇉-/ ⇉-[] σ∈Γ = ⇉-[]
Sp⇉-/ (⇉-∷ {a} {j = j} a⇇b⋯c j[a]⇉as⇉k) σ∈Γ =
⇉-∷ (Nf⇇-/ a⇇b⋯c σ∈Γ)
(subst (_ ⊢_⇉∙ _ ⇉ _) (Kind/-sub-↑ j a _)
(Sp⇉-/ j[a]⇉as⇉k σ∈Γ))
<∷-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k σ} →
Γ ⊢ j <∷ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ j A.Kind′/ σ <∷ k A.Kind′/ σ
<∷-/ (<∷-⋯ a₂∼a₁ b₁∼b₂) σ∈Γ =
<∷-⋯ (∼-/ a₂∼a₁ σ∈Γ) (∼-/ b₁∼b₂ σ∈Γ)
<∷-/ (<∷-Π a₁∼a₂ b₂∼b₁ k₁<∷k₂) σ∈Γ =
<∷-Π (∼-/ a₁∼a₂ σ∈Γ) (∼-/ b₂∼b₁ σ∈Γ)
(<∷-/ k₁<∷k₂ (∈-↑ (<∷-/-wf k₁<∷k₂ σ∈Γ) σ∈Γ))
∼-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} →
Γ ⊢ a ∼ b → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A.Elim/ σ ∼ b A.Elim/ σ
∼-/ (∼-trans a∼b b∼c) σ∈Γ =
∼-trans (∼-/ a∼b σ∈Γ) (∼-/ b∼c σ∈Γ)
∼-/ (∼-⊥ a⇉a⋯a) σ∈Γ = ∼-⊥ (Nf⇉-/ a⇉a⋯a σ∈Γ)
∼-/ (∼-⊤ a⇉a⋯a) σ∈Γ = ∼-⊤ (Nf⇉-/ a⇉a⋯a σ∈Γ)
∼-/ (∼-∙ (⇉-var x Γ-ctx Γ[x]≡j) j⇉as∼bs⇉k) σ∈Γ
with ∈-lift (/∈-lookup σ∈Γ x)
... | ∈-nf {a} (⇇-⇑ a⇉c₁⋯d₁ (<∷-⋯ _ _)) ⌞a⌟≡σ[x] c⋯d≡Γ[x]/σ =
let c⋯d≡j/σ = kd-inj (trans c⋯d≡Γ[x]/σ (cong (A._ElimAsc/ _) Γ[x]≡j))
c⋯d⇉as/σ∼bs/σ⇉k/σ = subst (_ ⊢_⇉∙ _ ∼ _ ⇉ _) (sym c⋯d≡j/σ)
(Sp∼-/ j⇉as∼bs⇉k σ∈Γ)
as≡[] , bs≡[] , _ = Sp∼-⋯ c⋯d⇉as/σ∼bs/σ⇉k/σ
a≡⌜σ[x]⌝ = trans (sym (⌜⌝∘⌞⌟-id a)) (cong ⌜_⌝ ⌞a⌟≡σ[x])
⌜σ[x]⌝∙∙as≡a = trans (cong₂ _∙∙_ (sym a≡⌜σ[x]⌝) as≡[]) (∙∙-[] _)
⌜σ[x]⌝∙∙bs≡a = trans (cong₂ _∙∙_ (sym a≡⌜σ[x]⌝) bs≡[]) (∙∙-[] _)
in subst₂ (_ ⊢_∼_) (sym ⌜σ[x]⌝∙∙as≡a) (sym ⌜σ[x]⌝∙∙bs≡a)
(∼-refl a⇉c₁⋯d₁)
... | ∈-var y Δ-ctx y≡σ[x] Δ[y]≡Γ[x]/σ =
let Δ[y]≡j/σ = trans Δ[y]≡Γ[x]/σ (cong (A._ElimAsc/ _) Γ[x]≡j)
in subst₂ (_ ⊢_∼_) (cong (_∙∙ _) (cong ⌜_⌝ y≡σ[x]))
(cong (_∙∙ _) (cong ⌜_⌝ y≡σ[x]))
(∼-∙ (⇉-var y Δ-ctx Δ[y]≡j/σ) (Sp∼-/ j⇉as∼bs⇉k σ∈Γ))
∼-/ (∼-⟨| a∈b⋯c) σ∈Γ with Ne⇉-/ a∈b⋯c σ∈Γ
... | inj₁ a⇇b⋯c = ∼-⟨|-Nf⇇ a⇇b⋯c
... | inj₂ a⇉b⋯c = ∼-⟨| a⇉b⋯c
∼-/ (∼-|⟩ a∈b⋯c) σ∈Γ with Ne⇉-/ a∈b⋯c σ∈Γ
... | inj₁ a⇇b⋯c = ∼-|⟩-Nf⇇ a⇇b⋯c
... | inj₂ a⇉b⋯c = ∼-|⟩ a⇉b⋯c
Sp∼-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {as bs j k σ} →
Γ ⊢ j ⇉∙ as ∼ bs ⇉ k → Δ ⊢/ σ ∈ Γ →
Δ ⊢ j A.Kind′/ σ ⇉∙ as A.// σ ∼ bs A.// σ ⇉ k A.Kind′/ σ
Sp∼-/ ∼-[] σ∈Γ = ∼-[]
Sp∼-/ (∼-∷ {a} {j = j} c∼a a∼d a∼b as∼bs) σ∈Γ =
∼-∷ (∼-/ c∼a σ∈Γ) (∼-/ a∼d σ∈Γ) (∼-/ a∼b σ∈Γ)
(subst (_ ⊢_⇉∙ _ ∼ _ ⇉ _) (Kind/-sub-↑ j a _)
(Sp∼-/ as∼bs σ∈Γ))
-- Helpers (to satisfy the termination checker).
--
-- These are simply (manual) expansions of the form
--
-- XX-/-wf x σ∈Γ = wf-/ (wf-∷₁ (XX-ctx x)) σ∈Γ
--
-- to ensure the above definitions remain structurally recursive
-- in the various derivations.
Nf⇉-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a j k σ} →
kd j ∷ Γ ⊢Nf a ⇉ k → Δ ⊢/ σ ∈ Γ →
Δ ⊢ kd (j A.Kind′/ σ) wf
Nf⇉-/-wf (⇉-⊥-f (j-wf ∷ _)) σ∈Γ = wf-/ j-wf σ∈Γ
Nf⇉-/-wf (⇉-⊤-f (j-wf ∷ _)) σ∈Γ = wf-/ j-wf σ∈Γ
Nf⇉-/-wf (⇉-s-i a∈b⋯c) σ∈Γ = Ne⇉-/-wf a∈b⋯c σ∈Γ
Ne⇉-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a j k σ} →
kd j ∷ Γ ⊢Ne a ⇉ k → Δ ⊢/ σ ∈ Γ →
Δ ⊢ kd (j A.Kind′/ σ) wf
Ne⇉-/-wf (⇉-∙ x∈k _) σ∈Γ = Var⇉-/-wf x∈k σ∈Γ
Var⇉-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a j k σ} →
kd j ∷ Γ ⊢Var a ⇉ k → Δ ⊢/ σ ∈ Γ →
Δ ⊢ kd (j A.Kind′/ σ) wf
Var⇉-/-wf (⇉-var x (j-wf ∷ _) _) σ∈Γ = wf-/ j-wf σ∈Γ
<∷-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k l σ} →
kd j ∷ Γ ⊢ k <∷ l → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind′/ σ) wf
<∷-/-wf (<∷-⋯ a₂∼a₁ _) σ∈Γ = ∼-/-wf a₂∼a₁ σ∈Γ
<∷-/-wf (<∷-Π a₁∼a₂ _ _) σ∈Γ = ∼-/-wf a₁∼a₂ σ∈Γ
∼-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b j σ} →
kd j ∷ Γ ⊢ a ∼ b → Δ ⊢/ σ ∈ Γ →
Δ ⊢ kd (j A.Kind′/ σ) wf
∼-/-wf (∼-trans a∼b _) σ∈Γ = ∼-/-wf a∼b σ∈Γ
∼-/-wf (∼-⊥ a⇉a⋯a) σ∈Γ = Nf⇉-/-wf a⇉a⋯a σ∈Γ
∼-/-wf (∼-⊤ a⇉a⋯a) σ∈Γ = Nf⇉-/-wf a⇉a⋯a σ∈Γ
∼-/-wf (∼-∙ x∈j _) σ∈Γ = Var⇉-/-wf x∈j σ∈Γ
∼-/-wf (∼-⟨| a∈b⋯c) σ∈Γ = Ne⇉-/-wf a∈b⋯c σ∈Γ
∼-/-wf (∼-|⟩ a∈b⋯c) σ∈Γ = Ne⇉-/-wf a∈b⋯c σ∈Γ
-- Renamings preserve wrapped variable typing
NfOrVar∈-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} →
Γ ⊢NfOrVar a ∈ b → Δ ⊢/ σ ∈ Γ →
Δ ⊢NfOrVar a A./ σ ∈ b A.ElimAsc/ σ
NfOrVar∈-/ (∈-nf {a} a⇇c⋯d refl refl) σ∈Γ =
∈-nf (Nf⇇-/ a⇇c⋯d σ∈Γ) (A.⌞⌟-/ a) refl
NfOrVar∈-/ (∈-var x _ refl refl) σ∈Γ = ∈-lift (/∈-lookup σ∈Γ x)
-- Well-kinded renamings and type substitutions.
module KindedSubstitution where
open Substitution using (simple; termSubst)
open SimpleExt simple using (extension)
open TermSubst termSubst using (varLift; termLift)
open ≡-Reasoning
private
module S = Substitution
module KL = TermLikeLemmas S.termLikeLemmasKind′
-- Helper lemmas about untyped renamings and substitutions in terms
-- and kinds.
varHelpers : TypedSubstAppHelpers varLift
varHelpers = record
{ Kind/-sub-↑ = λ k a ρ → begin
(k Kind′[ ⌞ a ⌟ ]) Kind′/Var ρ
≡⟨ KL./-sub-↑ k ⌞ a ⌟ ρ ⟩
(k Kind′/Var ρ VarSubst.↑) Kind′[ ⌞ a ⌟ /Var ρ ]
≡⟨ cong ((k Kind′/Var ρ VarSubst.↑) Kind′[_]) (sym (⌞⌟-/Var a)) ⟩
(k Kind′/Var ρ VarSubst.↑) Kind′[ ⌞ a Elim/Var ρ ⌟ ]
∎
}
where open S
termHelpers : TypedSubstAppHelpers termLift
termHelpers = record
{ Kind/-sub-↑ = λ k a σ → begin
(k Kind′[ ⌞ a ⌟ ]) Kind′/ σ
≡⟨ KL.sub-commutes k ⟩
(k Kind′/ σ ↑) Kind′[ ⌞ a ⌟ / σ ]
≡⟨ cong ((k Kind′/ σ ↑) Kind′[_]) (sym (⌞⌟-/ a)) ⟩
(k Kind′/ σ ↑) Kind′[ ⌞ a Elim/ σ ⌟ ]
∎
}
where open S
-- Kinded type substitutions.
typedTermSubst : TypedTermSubst ElimAsc Term Level.zero TypedSubstAppHelpers
typedTermSubst = record
{ _⊢_wf = _⊢_wf
; _⊢_∈_ = _⊢NfOrVar_∈_
; termLikeLemmas = S.termLikeLemmasElimAsc
; varHelpers = varHelpers
; termHelpers = termHelpers
; wf-wf = wf-ctx
; ∈-wf = NfOrVar∈-ctx
; ∈-var = λ x Γ-ctx → ∈-var x Γ-ctx refl refl
; typedApp = TypedSubstApp.NfOrVar∈-/
}
open TypedTermSubst typedTermSubst public
hiding (_⊢_wf; _⊢_∈_; varHelpers; termHelpers; ∈-var; ∈-/Var; ∈-/)
renaming (lookup to /∈-lookup)
open TypedSubstApp _⊢Var_∈_ varLiftTyped varHelpers public using ()
renaming (wf-/ to wf-/Var; ∼-/ to ∼-/Var)
open Substitution using (weakenElim; weakenElimAsc)
-- Weakening preserves the various judgments.
wf-weaken : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a wf → Γ ⊢ b wf →
(a ∷ Γ) ⊢ weakenElimAsc b wf
wf-weaken a-wf b-wf = wf-/Var b-wf (Var∈-wk a-wf)
∼-weaken : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a wf → Γ ⊢ b ∼ c →
(a ∷ Γ) ⊢ weakenElim b ∼ weakenElim c
∼-weaken a-wf b∼c∈k = ∼-/Var b∼c∈k (Var∈-wk a-wf)
open TypedSubstApp _⊢NfOrVar_∈_ termLiftTyped termHelpers public
open Substitution using (_Kind′/_; id; sub; _Kind′[_])
-- Substitution of a single variable or normal form preserves the
-- kinding judgments.
kd-[] : ∀ {n} {Γ : Ctx n} {a b c k} →
kd (b ⋯ c) ∷ Γ ⊢ k kd → Γ ⊢Nf a ⇇ b ⋯ c → Γ ⊢ k Kind′[ ⌞ a ⌟ ] kd
kd-[] k-kd a⇇b⋯c = kd-/ k-kd (∈-sub (∈-nf a⇇b⋯c refl refl))
<∷-[] : ∀ {n} {Γ : Ctx n} {j k a b c} →
kd (b ⋯ c) ∷ Γ ⊢ j <∷ k → Γ ⊢Nf a ⇇ b ⋯ c →
Γ ⊢ j Kind′[ ⌞ a ⌟ ] <∷ k Kind′[ ⌞ a ⌟ ]
<∷-[] j<∷k a⇇b⋯c = <∷-/ j<∷k (∈-sub (∈-nf a⇇b⋯c refl refl))
-- A typed substitution that narrows the kind of the first type
-- variable.
∈-<∷-sub : ∀ {n} {Γ : Ctx n} {a₁ a₂ b₁ b₂} →
Γ ⊢ (a₁ ⋯ b₁) kd → Γ ⊢ a₂ ∼ a₁ → Γ ⊢ b₁ ∼ b₂ →
kd (a₁ ⋯ b₁) ∷ Γ ⊢/ id ∈ kd (a₂ ⋯ b₂) ∷ Γ
∈-<∷-sub a₁⋯b₁-kd a₁∼a₂ b₂∼b₁ =
∈-tsub (∈-nf (⇇-⇑ (⇉-s-i x∈a₁⋯a₂) (<∷-⋯ x∼a₂ b₂∼x)) refl refl)
where
a₁⋯b₁-wf = wf-kd a₁⋯b₁-kd
Γ-ctx = kd-ctx a₁⋯b₁-kd
x∈a₁⋯a₂ = ⇉-∙ (⇉-var zero (a₁⋯b₁-wf ∷ Γ-ctx) refl) ⇉-[]
x∼a₂ = ∼-trans (∼-weaken a₁⋯b₁-wf a₁∼a₂) (∼-⟨| x∈a₁⋯a₂)
b₂∼x = ∼-trans (∼-|⟩ x∈a₁⋯a₂) (∼-weaken a₁⋯b₁-wf b₂∼b₁)
-- Narrowing the kind of the first type variable preserves
-- subkinding
⇓-<∷ : ∀ {n} {Γ : Ctx n} {a₁ a₂ b₁ b₂ k₁ k₂} →
Γ ⊢ (a₁ ⋯ b₁) kd → Γ ⊢ a₂ ∼ a₁ → Γ ⊢ b₁ ∼ b₂ →
kd (a₂ ⋯ b₂) ∷ Γ ⊢ k₁ <∷ k₂ → kd (a₁ ⋯ b₁) ∷ Γ ⊢ k₁ <∷ k₂
⇓-<∷ a₁⋯b₁-kd a₂∼a₁ b₁∼b₂ k₁<∷k₂ =
subst₂ (_ ⊢_<∷_) (KL.id-vanishes _) (KL.id-vanishes _)
(<∷-/ k₁<∷k₂ (∈-<∷-sub a₁⋯b₁-kd a₂∼a₁ b₁∼b₂))
-- Operations on well-formed contexts that require weakening of
-- well-formedness judgments.
module WfCtxOps where
wfWeakenOps : WellFormedWeakenOps weakenOps
wfWeakenOps = record { wf-weaken = KindedSubstitution.wf-weaken }
open WellFormedWeakenOps wfWeakenOps public renaming (lookup to lookup-wf)
-- Lookup the kind of a type variable in a well-formed context.
lookup-kd : ∀ {m} {Γ : Ctx m} {k} x →
Γ ctx → ElimCtx.lookup Γ x ≡ kd k → Γ ⊢ k kd
lookup-kd x Γ-ctx Γ[x]≡kd-k =
wf-kd-inv (subst (_ ⊢_wf) Γ[x]≡kd-k (lookup-wf Γ-ctx x))
open KindedSubstitution
open WfCtxOps
-- A corollary of context narrowing: transitivity of subkinding is
-- admissible.
<∷-trans : ∀ {n} {Γ : Ctx n} {j k l} → Γ ⊢ j <∷ k → Γ ⊢ k <∷ l → Γ ⊢ j <∷ l
<∷-trans (<∷-⋯ a₂∼a₁ b₁∼b₂) (<∷-⋯ a₃∼a₂ b₂∼b₃) =
<∷-⋯ (∼-trans a₃∼a₂ a₂∼a₁) (∼-trans b₁∼b₂ b₂∼b₃)
<∷-trans (<∷-Π a₁∼a₂ b₂∼b₁ k₁<∷k₂) (<∷-Π a₂∼a₃ b₃∼b₂ k₂<∷k₃) =
let a₃⋯b₃-kd = wf-kd-inv (wf-∷₁ (<∷-ctx k₂<∷k₃))
in <∷-Π (∼-trans a₁∼a₂ a₂∼a₃) (∼-trans b₃∼b₂ b₂∼b₁)
(<∷-trans (⇓-<∷ a₃⋯b₃-kd a₂∼a₃ b₃∼b₂ k₁<∷k₂) k₂<∷k₃)
-- Another corollary: subsumption is admissible in kind checking.
Nf⇇-⇑ : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢Nf a ⇇ j → Γ ⊢ j <∷ k → Γ ⊢Nf a ⇇ k
Nf⇇-⇑ (⇇-⇑ a⇇j₁ j₁<∷j₂) j₂<∷j₃ = ⇇-⇑ a⇇j₁ (<∷-trans j₁<∷j₂ j₂<∷j₃)
-- We can push kind formation proofs through spine kindings.
kd-Sp⇉ : ∀ {n} {Γ : Ctx n} {j as k} →
Γ ⊢ j kd → Γ ⊢ j ⇉∙ as ⇉ k → Γ ⊢ k kd
kd-Sp⇉ j-kd ⇉-[] = j-kd
kd-Sp⇉ (kd-Π b⇉b⋯b c⇉c⋯c j-kd) (⇉-∷ a⇇b⋯c j[a]⇉as⇉k) =
kd-Sp⇉ (kd-[] j-kd a⇇b⋯c) j[a]⇉as⇉k
-- Kind-validity of neutrals
Var⇉-valid : ∀ {n} {Γ : Ctx n} {x k} → Γ ⊢Var x ⇉ k → Γ ⊢ k kd
Var⇉-valid (⇉-var x Γ-ctx Γ[x]≡k) = lookup-kd x Γ-ctx Γ[x]≡k
Ne⇉-valid : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Ne a ⇉ k → Γ ⊢ k kd
Ne⇉-valid (⇉-∙ x⇉j j⇉as⇉k) = kd-Sp⇉ (Var⇉-valid x⇉j) j⇉as⇉k
-- Left-hand validity of related types and spines
mutual
∼-valid₁ : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a ∼ b → Γ ⊢Nf a ⇉ a ⋯ a
∼-valid₁ (∼-trans a∼b _) = ∼-valid₁ a∼b
∼-valid₁ (∼-⊥ b⇉b⋯b) = ⇉-⊥-f (Nf⇉-ctx b⇉b⋯b)
∼-valid₁ (∼-⊤ a⇉a⋯a) = a⇉a⋯a
∼-valid₁ (∼-∙ x⇉j j⇉as⇉k) = ⇉-s-i (⇉-∙ x⇉j (∼Sp-valid₁ j⇉as⇉k))
∼-valid₁ (∼-⟨| a⇉b⋯c) with Ne⇉-valid a⇉b⋯c
... | kd-⋯ b⇉b⋯b _ = b⇉b⋯b
∼-valid₁ (∼-|⟩ a⇉b⋯c) = ⇉-s-i a⇉b⋯c
∼Sp-valid₁ : ∀ {n} {Γ : Ctx n} {j as bs k} →
Γ ⊢ j ⇉∙ as ∼ bs ⇉ k → Γ ⊢ j ⇉∙ as ⇉ k
∼Sp-valid₁ ∼-[] = ⇉-[]
∼Sp-valid₁ (∼-∷ c∼a a∼d a∼b j[x]⇉as⇉k) =
⇉-∷ (⇇-⇑ (∼-valid₁ a∼b) (<∷-⋯ c∼a a∼d)) (∼Sp-valid₁ j[x]⇉as⇉k)
-- We can push subkinding proofs through spine kindings/relations.
<∷-Sp⇉ : ∀ {n} {Γ : Ctx n} {j₁ j₂ as k₂} →
Γ ⊢ j₁ <∷ j₂ → Γ ⊢ j₂ ⇉∙ as ⇉ k₂ → ∃ λ k₁ →
Γ ⊢ j₁ ⇉∙ as ⇉ k₁ × Γ ⊢ k₁ <∷ k₂
<∷-Sp⇉ j₁<∷j₂ ⇉-[] = _ , ⇉-[] , j₁<∷j₂
<∷-Sp⇉ (<∷-Π b₁∼b₂ c₂∼c₁ j₁<∷j₂) (⇉-∷ a⇇b₂⋯c₂ j₂[a]⇉as⇉k₂) =
let k₁ , j₁[a]⇉as⇉k₁ , k₁<∷k₂ = <∷-Sp⇉ (<∷-[] j₁<∷j₂ a⇇b₂⋯c₂) j₂[a]⇉as⇉k₂
in k₁ , ⇉-∷ (Nf⇇-⇑ a⇇b₂⋯c₂ (<∷-⋯ b₁∼b₂ c₂∼c₁)) j₁[a]⇉as⇉k₁ , k₁<∷k₂
<∷-Sp∼ : ∀ {n} {Γ : Ctx n} {j₁ j₂ as bs k₂} →
Γ ⊢ j₁ <∷ j₂ → Γ ⊢ j₂ ⇉∙ as ∼ bs ⇉ k₂ → ∃ λ k₁ →
Γ ⊢ j₁ ⇉∙ as ∼ bs ⇉ k₁ × Γ ⊢ k₁ <∷ k₂
<∷-Sp∼ j₁<∷j₂ ∼-[] = _ , ∼-[] , j₁<∷j₂
<∷-Sp∼ (<∷-Π c₁∼c₂ d₂∼d₁ j₁<∷j₂)
(∼-∷ c₂∼a a∼d₂ a∼b j₂[a]⇉as∼bs⇉k₂) =
let a⇇c₂⋯d₂ = ⇇-⇑ (∼-valid₁ a∼b) (<∷-⋯ c₂∼a a∼d₂)
k₁ , j₁[a]⇉as∼bs⇉k₁ , k₁<∷k₂ = <∷-Sp∼ (<∷-[] j₁<∷j₂ a⇇c₂⋯d₂)
j₂[a]⇉as∼bs⇉k₂
in k₁ , ∼-∷ (∼-trans c₁∼c₂ c₂∼a) (∼-trans a∼d₂ d₂∼d₁) a∼b j₁[a]⇉as∼bs⇉k₁ ,
k₁<∷k₂
------------------------------------------------------------------------
-- Squashing of terms
mutual
squashElim : ∀ {n} → Elim n → Elim n
squashElim (a ∙ as) = squashHead a ∙ squashSpine as
squashHead : ∀ {n} → Head n → Head n
squashHead (var x) = var x
squashHead ⊥ = ⊥
squashHead ⊤ = ⊤
{-# CATCHALL #-}
squashHead a = ⊤ -- all other types are squashed into ⊤
squashSpine : ∀ {n} → Spine n → Spine n
squashSpine [] = []
squashSpine (a ∷ as) = squashElim a ∷ squashSpine as
squashKind : ∀ {n} → Kind Elim n → Kind Elim n
squashKind (a ⋯ b) = squashElim a ⋯ squashElim b
squashKind (Π j k) = Π (squashKind j) (squashKind k)
squashAsc : ∀ {n} → ElimAsc n → ElimAsc n
squashAsc (kd k) = kd (squashKind k)
squashAsc (tp a) = tp (squashElim a)
squashCtx : ∀ {n} → Ctx n → Ctx n
squashCtx [] = []
squashCtx (a ∷ Γ) = (squashAsc a) ∷ (squashCtx Γ)
squashTerm : ∀ {n} → Term n → Term n
squashTerm a = ⌞ squashElim ⌜ a ⌝ ⌟
squash-++ : ∀ {n} (as : Spine n) {bs} →
squashSpine as ++ squashSpine bs ≡ squashSpine (as ++ bs)
squash-++ [] = refl
squash-++ (a ∷ as) = cong (_ ∷_) (squash-++ as)
squash-∙∙ : ∀ {n} (a : Elim n) {bs} →
squashElim a ∙∙ squashSpine bs ≡ squashElim (a ∙∙ bs)
squash-∙∙ (a ∙ as) = cong (_ ∙_) (squash-++ as)
-- Squashing commutes with generic substitutions.
module SquashSubstAppLemmas {T : ℕ → Set} (l : Lift T Term)
(squashSub : ∀ {m n} → Sub T m n → Sub T m n)
(squash-↑ : ∀ {m n} (σ : Sub T m n) →
Lift._↑ l (squashSub σ) ≡ squashSub (Lift._↑ l σ))
(squash-lift-lookup : ∀ {m n} (σ : Sub T m n) x →
⌜ Lift.lift l (Vec.lookup (squashSub σ) x) ⌝ ≡
squashElim ⌜ Lift.lift l (Vec.lookup σ x) ⌝)
where
open SubstApp l
-- Squashing commutes with application of generic substitutions.
mutual
squashElim-/ : ∀ {m n} {σ : Sub T m n} a →
squashElim a Elim/ squashSub σ ≡ squashElim (a Elim/ σ)
squashElim-/ (a ∙ as) =
trans (cong₂ _∙∙_ (squashHead-/ a) (squashSpine-/ as)) (squash-∙∙ _)
squashHead-/ : ∀ {m n} {σ : Sub T m n} a →
squashHead a Head/ squashSub σ ≡ squashElim (a Head/ σ)
squashHead-/ (var x) = squash-lift-lookup _ x
squashHead-/ ⊥ = refl
squashHead-/ ⊤ = refl
squashHead-/ (Π k a) = refl
squashHead-/ (a ⇒ b) = refl
squashHead-/ (Λ k a) = refl
squashHead-/ (ƛ a b) = refl
squashHead-/ (a ⊡ b) = refl
squashSpine-/ : ∀ {m n} {σ : Sub T m n} as →
squashSpine as // squashSub σ ≡ squashSpine (as // σ)
squashSpine-/ [] = refl
squashSpine-/ (a ∷ as) =
cong₂ _∷_ (squashElim-/ a) (squashSpine-/ as)
squashKind-/ : ∀ {m n} {σ : Sub T m n} k →
squashKind k Kind′/ squashSub σ ≡ squashKind (k Kind′/ σ)
squashKind-/ (a ⋯ b) = cong₂ _⋯_ (squashElim-/ a) (squashElim-/ b)
squashKind-/ (Π j k) =
cong₂ Π (squashKind-/ j)
(trans (cong (_ Kind′/_) (squash-↑ _)) (squashKind-/ k))
squashAsc-/ : ∀ {m n} {σ : Sub T m n} a →
squashAsc a ElimAsc/ squashSub σ ≡ squashAsc (a ElimAsc/ σ)
squashAsc-/ (kd k) = cong kd (squashKind-/ k)
squashAsc-/ (tp a) = cong tp (squashElim-/ a)
squashTerm-/ : ∀ {m n} {σ : Sub T m n} a →
squashTerm a / squashSub σ ≡ squashTerm (a / σ)
squashTerm-/ {σ = σ} a = begin
⌞ squashElim ⌜ a ⌝ ⌟ / squashSub σ ≡˘⟨ ⌞⌟-/ (squashElim ⌜ a ⌝) ⟩
⌞ squashElim ⌜ a ⌝ Elim/ squashSub σ ⌟ ≡⟨ cong ⌞_⌟ (squashElim-/ ⌜ a ⌝) ⟩
⌞ squashElim (⌜ a ⌝ Elim/ σ) ⌟ ≡˘⟨ cong (⌞_⌟ ∘ squashElim) (⌜⌝-/ a) ⟩
⌞ squashElim ⌜ a / σ ⌝ ⌟ ∎
where open ≡-Reasoning
-- Squashing commutes with renamings and term substitutions.
module SquashSubstLemmas where
open Substitution
using (termSubst; _↑; id; sub; weaken; _Kind′/_; _Kind′[_])
open TermSubst termSubst using (varLift; termLift)
open ≡-Reasoning
open SquashSubstAppLemmas varLift (λ x → x) (λ _ → refl) (λ _ _ → refl)
public using () renaming
( squashAsc-/ to squashAsc-/Var
; squashTerm-/ to squashTerm-/Var
)
-- Squashing applied point-wise to term substitutions.
squashSub : ∀ {m n} → Sub Term m n → Sub Term m n
squashSub = Vec.map squashTerm
-- Helper lemmas about squashed substitutions.
squash-↑ : ∀ {m n} (σ : Sub Term m n) → (squashSub σ) ↑ ≡ squashSub (σ ↑)
squash-↑ σ = cong (_ ∷_) (begin
Vec.map weaken (Vec.map squashTerm σ) ≡˘⟨ map-∘ weaken squashTerm σ ⟩
Vec.map (weaken ∘ squashTerm) σ ≡⟨ map-cong squashTerm-/Var σ ⟩
Vec.map (squashTerm ∘ weaken) σ ≡⟨ map-∘ squashTerm weaken σ ⟩
Vec.map squashTerm (Vec.map weaken σ) ∎)
squash-lookup : ∀ {m n} (σ : Sub Term m n) x →
⌜ Vec.lookup (squashSub σ) x ⌝ ≡ squashElim ⌜ Vec.lookup σ x ⌝
squash-lookup σ x = begin
⌜ Vec.lookup (squashSub σ) x ⌝
≡⟨ cong ⌜_⌝ (VecProps.lookup-map x squashTerm σ) ⟩
⌜ squashTerm (Vec.lookup σ x) ⌝
≡⟨ ⌜⌝∘⌞⌟-id (squashElim ⌜ Vec.lookup σ x ⌝) ⟩
squashElim ⌜ Vec.lookup σ x ⌝
∎
open SquashSubstAppLemmas termLift squashSub squash-↑ squash-lookup public
squash-id : ∀ {n} → squashSub (id {n}) ≡ id
squash-id {zero} = refl
squash-id {suc n} = cong (var zero ∷_) (begin
Vec.map squashTerm (Vec.map weaken id) ≡˘⟨ map-∘ squashTerm weaken id ⟩
Vec.map (squashTerm ∘ weaken) id ≡˘⟨ map-cong squashTerm-/Var id ⟩
Vec.map (weaken ∘ squashTerm) id ≡⟨ map-∘ weaken squashTerm id ⟩
Vec.map weaken (Vec.map squashTerm id) ≡⟨ cong (Vec.map weaken) squash-id ⟩
Vec.map weaken id ∎)
squash-sub : ∀ {n} (a : Term n) → squashSub (sub a) ≡ sub (squashTerm a)
squash-sub a = cong (squashTerm a ∷_) squash-id
-- Squashing commutes with single-variable substitutions in kinds.
squashKind-[] : ∀ {n} k (a : Elim n) →
squashKind (k Kind′[ ⌞ a ⌟ ]) ≡
squashKind k Kind′[ ⌞ squashElim a ⌟ ]
squashKind-[] k a = begin
squashKind (k Kind′[ ⌞ a ⌟ ])
≡˘⟨ squashKind-/ k ⟩
squashKind k Kind′/ squashSub (sub ⌞ a ⌟)
≡⟨ cong (squashKind k Kind′/_) (squash-sub ⌞ a ⌟) ⟩
squashKind k Kind′[ squashTerm ⌞ a ⌟ ]
≡⟨ cong ((squashKind k Kind′[_]) ∘ ⌞_⌟ ∘ squashElim) (⌜⌝∘⌞⌟-id a) ⟩
squashKind k Kind′[ ⌞ squashElim a ⌟ ]
∎
open Substitution using (weakenElimAsc)
open SquashSubstLemmas
-- Context lookup and conversion to vector representation commute with
-- squashing
toVec-squashCtx : ∀ {n} (Γ : Ctx n) →
toVec (squashCtx Γ) ≡ Vec.map squashAsc (toVec Γ)
toVec-squashCtx [] = refl
toVec-squashCtx (a ∷ Γ) = cong₂ _∷_ (squashAsc-/Var a) (begin
Vec.map weakenElimAsc (toVec (squashCtx Γ))
≡⟨ cong (Vec.map weakenElimAsc) (toVec-squashCtx Γ) ⟩
Vec.map weakenElimAsc (Vec.map squashAsc (toVec Γ))
≡˘⟨ map-∘ weakenElimAsc squashAsc (toVec Γ) ⟩
Vec.map (weakenElimAsc ∘ squashAsc) (toVec Γ)
≡⟨ map-cong squashAsc-/Var (toVec Γ) ⟩
Vec.map (squashAsc ∘ weakenElimAsc) (toVec Γ)
≡⟨ map-∘ squashAsc weakenElimAsc (toVec Γ) ⟩
Vec.map squashAsc (Vec.map weakenElimAsc (toVec Γ))
∎)
where open ≡-Reasoning
lookup-squashCtx : ∀ {n} (Γ : Ctx n) x →
lookup (squashCtx Γ) x ≡ squashAsc (lookup Γ x)
lookup-squashCtx {n} Γ x = begin
Vec.lookup (toVec (squashCtx Γ)) x
≡⟨ cong (λ Δ → Vec.lookup Δ x) (toVec-squashCtx Γ) ⟩
Vec.lookup (Vec.map squashAsc (toVec Γ)) x
≡⟨ VecProps.lookup-map x squashAsc (toVec Γ) ⟩
squashAsc (Vec.lookup (toVec Γ) x)
∎
where open ≡-Reasoning
------------------------------------------------------------------------
-- Predicates characterizing first-order kinds, bindings and contexts.
data FOKind {n} : Kind Elim n → Set where
fo-⋯ : ∀ {a b} → FOKind (a ⋯ b)
fo-Π : ∀ {a b k} → FOKind k → FOKind (Π (a ⋯ b) k)
data FOAsc {n} : ElimAsc n → Set where
fo-kd : ∀ {k} → FOKind k → FOAsc (kd k)
open ContextFormation (λ {n} Γ → FOAsc {n}) public using () renaming
( _wf to FOCtx; [] to fo-[]; _∷_ to fo-∷
; WellFormedWeakenOps to FOWeakenOps)
<∷-FOKind₂ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j <∷ k → FOKind k
<∷-FOKind₂ (<∷-⋯ _ _) = fo-⋯
<∷-FOKind₂ (<∷-Π _ _ j<∷k) = fo-Π (<∷-FOKind₂ j<∷k)
module FOSubstAppLemmas {T : ℕ → Set} (l : Lift T Term) where
open SubstApp l
FOKind-/ : ∀ {m n k} {σ : Sub T m n} → FOKind k → FOKind (k Kind′/ σ)
FOKind-/ fo-⋯ = fo-⋯
FOKind-/ (fo-Π k-fo) = fo-Π (FOKind-/ k-fo)
FOAsc-/ : ∀ {m n a} {σ : Sub T m n} → FOAsc a → FOAsc (a ElimAsc/ σ)
FOAsc-/ (fo-kd k-fo) = fo-kd (FOKind-/ k-fo)
module FOSubstLemmas where
open Substitution using (termSubst)
open TermSubst termSubst using (varLift; termLift)
open FOSubstAppLemmas varLift public using ()
renaming (FOKind-/ to FOKind-/Var; FOAsc-/ to FOAsc-/Var)
open FOSubstAppLemmas termLift public
FOAsc-weaken : ∀ {n} {a : ElimAsc n} → FOAsc a → FOAsc (weakenElimAsc a)
FOAsc-weaken a-fo = FOAsc-/Var a-fo
open FOSubstLemmas
foWeakenOps : FOWeakenOps weakenOps
foWeakenOps = record { wf-weaken = λ _ → FOAsc-weaken }
open FOWeakenOps foWeakenOps public using () renaming (lookup to lookup-FOAsc)
lookup-FOKind : ∀ {m} {Γ : Ctx m} {k} x →
FOCtx Γ → ElimCtx.lookup Γ x ≡ kd k → FOKind k
lookup-FOKind x Γ-fo Γ[x]≡kd-a with subst FOAsc Γ[x]≡kd-a (lookup-FOAsc Γ-fo x)
... | fo-kd k-fo = k-fo
------------------------------------------------------------------------
-- Reduction of canonical judgments to their reduced forms
open Substitution hiding (subst)
mutual
reduce-ctx : ∀ {n} {Γ : Ctx n} → FOCtx (squashCtx Γ) →
Γ C.ctx → squashCtx Γ ctx
reduce-ctx fo-[] C.[] = []
reduce-ctx (fo-∷ a-fo Γ-fo) (a-wf C.∷ Γ-ctx) =
reduce-wf Γ-fo a-fo a-wf ∷ reduce-ctx Γ-fo Γ-ctx
reduce-wf : ∀ {n} {Γ : Ctx n} {a} →
FOCtx (squashCtx Γ) → FOAsc (squashAsc a) →
Γ C.⊢ a wf → squashCtx Γ ⊢ squashAsc a wf
reduce-wf Γ-fo (fo-kd k-fo) (C.wf-kd k-kd) =
wf-kd (reduce-kd Γ-fo k-fo k-kd)
reduce-wf Γ-fo _ (C.wf-tp a⇉a⋯a) = wf-tp (reduce-Nf⇉ Γ-fo a⇉a⋯a)
reduce-kd : ∀ {n} {Γ : Ctx n} {k} →
FOCtx (squashCtx Γ) → FOKind (squashKind k) →
Γ C.⊢ k kd → squashCtx Γ ⊢ squashKind k kd
reduce-kd Γ-fo _ (C.kd-⋯ a⇉a⋯a b⇉b⋯b) =
kd-⋯ (reduce-Nf⇉ Γ-fo a⇉a⋯a) (reduce-Nf⇉ Γ-fo b⇉b⋯b)
reduce-kd Γ-fo (fo-Π k-fo) (C.kd-Π (C.kd-⋯ a⇉a⋯a b⇉b⋯b) k-kd) =
kd-Π (reduce-Nf⇉ Γ-fo a⇉a⋯a) (reduce-Nf⇉ Γ-fo b⇉b⋯b)
(reduce-kd (fo-∷ (fo-kd fo-⋯) Γ-fo) k-fo k-kd)
reduce-kd Γ-fo () (C.kd-Π (C.kd-Π _ _) k-kd)
reduce-Var∈ : ∀ {n} {Γ : Ctx n} {x k} → FOCtx (squashCtx Γ) →
Γ C.⊢Var x ∈ k → ∃ λ j →
squashCtx Γ ⊢Var x ⇉ j × squashCtx Γ ⊢ j <∷ squashKind k
reduce-Var∈ {_} {Γ} Γ-fo (C.⇉-var x Γ-ctx Γ[x]≡kd-j₁) =
let Γ-ctx′ = reduce-ctx Γ-fo Γ-ctx
Γ[x]≡kd-j₁′ = trans (lookup-squashCtx Γ x) (cong squashAsc Γ[x]≡kd-j₁)
in _ , ⇉-var x Γ-ctx′ Γ[x]≡kd-j₁′ ,
<∷-refl (lookup-kd x Γ-ctx′ Γ[x]≡kd-j₁′)
reduce-Var∈ Γ-fo (C.⇇-⇑ x∈k₁ k₁<∷k₂ _) =
let j , x∈j , j<∷k₁ = reduce-Var∈ Γ-fo x∈k₁
in j , x∈j , <∷-trans j<∷k₁ (reduce-<∷ Γ-fo (<∷-FOKind₂ j<∷k₁) k₁<∷k₂)
reduce-Ne∈ : ∀ {n} {Γ : Ctx n} {a b c} → FOCtx (squashCtx Γ) →
Γ C.⊢Ne a ∈ (b ⋯ c) →
squashCtx Γ ⊢Nf squashElim a ⇇ squashKind (b ⋯ c)
reduce-Ne∈ {_} {Γ} Γ-fo (C.∈-∙ {as = as} x∈j₂ j₂⇉as⇉b₂⋯c₂) =
let j₁ , x⇉j₁ , j₁<∷j₂ = reduce-Var∈ Γ-fo x∈j₂
j₂-fo = <∷-FOKind₂ j₁<∷j₂
j₂⇉as⇉b₂⋯c₂′ = reduce-Sp⇉ Γ-fo j₂-fo j₂⇉as⇉b₂⋯c₂
k₁ , j₁⇉as⇉k₁ , k₁<∷b₂⋯c₂ = <∷-Sp⇉ j₁<∷j₂ j₂⇉as⇉b₂⋯c₂′
_ , _ , b₂∼b₁ , c₁∼c₂ , k₁≡b₁⋯c₁ = <∷-⋯-inv k₁<∷b₂⋯c₂
j₁⇉as⇉b₁⋯c₁ = subst (squashCtx Γ ⊢ j₁ ⇉∙ squashSpine as ⇉_)
k₁≡b₁⋯c₁ j₁⇉as⇉k₁
in Nf⇇-⇑ (Nf⇇-ne (⇉-∙ x⇉j₁ j₁⇉as⇉b₁⋯c₁)) (<∷-⋯ b₂∼b₁ c₁∼c₂)
reduce-Nf⇉ : ∀ {n} {Γ : Ctx n} {a b c} → FOCtx (squashCtx Γ) →
Γ C.⊢Nf a ⇉ b ⋯ c →
squashCtx Γ ⊢Nf squashElim a ⇉ squashElim b ⋯ squashElim c
reduce-Nf⇉ Γ-fo (C.⇉-⊥-f Γ-ctx) = ⇉-⊥-f (reduce-ctx Γ-fo Γ-ctx)
reduce-Nf⇉ Γ-fo (C.⇉-⊤-f Γ-ctx) = ⇉-⊤-f (reduce-ctx Γ-fo Γ-ctx)
reduce-Nf⇉ Γ-fo (C.⇉-∀-f k-kd _) =
⇉-⊤-f (reduce-kd-ctx Γ-fo k-kd)
reduce-Nf⇉ Γ-fo (C.⇉-→-f a⇉a⋯a _) =
⇉-⊤-f (Nf⇉-ctx (reduce-Nf⇉ Γ-fo a⇉a⋯a))
reduce-Nf⇉ Γ-fo (C.⇉-s-i (C.∈-∙ x∈j j⇉as⇉b⋯c))
with reduce-Ne∈ Γ-fo (C.∈-∙ x∈j j⇉as⇉b⋯c)
... | ⇇-⇑ (⇉-s-i x∙as∈b′⋯c′) (<∷-⋯ _ _) = ⇉-s-i x∙as∈b′⋯c′
reduce-Nf⇇ : ∀ {n} {Γ : Ctx n} {a b c} → FOCtx (squashCtx Γ) →
Γ C.⊢Nf a ⇇ b ⋯ c →
squashCtx Γ ⊢Nf squashElim a ⇇ squashElim b ⋯ squashElim c
reduce-Nf⇇ Γ-fo (C.⇇-⇑ a⇉b₁⋯c₁ (C.<∷-⋯ b₂<:b₁ c₁<:c₂)) =
⇇-⇑ (reduce-Nf⇉ Γ-fo a⇉b₁⋯c₁)
(<∷-⋯ (reduce-<: Γ-fo b₂<:b₁) (reduce-<: Γ-fo c₁<:c₂))
reduce-Sp⇉ : ∀ {n} {Γ : Ctx n} {j as k} →
FOCtx (squashCtx Γ) → FOKind (squashKind j) →
Γ C.⊢ j ⇉∙ as ⇉ k →
squashCtx Γ ⊢ squashKind j ⇉∙ squashSpine as ⇉ squashKind k
reduce-Sp⇉ Γ-fo _ C.⇉-[] = ⇉-[]
reduce-Sp⇉ Γ-fo (fo-Π k-fo)
(C.⇉-∷ {a} {as} {b ⋯ c} {k} a⇇b⋯c _ k[a∈★]⇉as⇉l) =
let k[a∈★]≡k[a] = trans (cong squashKind (Kind/⟨★⟩-/ k))
(squashKind-[] k a)
k[a∈★]-fo = subst FOKind (sym k[a∈★]≡k[a])
(FOKind-/ {σ = sub ⌞ squashElim a ⌟} k-fo)
in ⇉-∷ (reduce-Nf⇇ Γ-fo a⇇b⋯c)
(subst (_ ⊢_⇉∙ _ ⇉ _) k[a∈★]≡k[a]
(reduce-Sp⇉ Γ-fo k[a∈★]-fo k[a∈★]⇉as⇉l))
reduce-<∷ : ∀ {n} {Γ : Ctx n} {j k} →
FOCtx (squashCtx Γ) → FOKind (squashKind j) →
Γ C.⊢ j <∷ k → squashCtx Γ ⊢ squashKind j <∷ squashKind k
reduce-<∷ Γ-fo a₁⋯a₂-fo (C.<∷-⋯ a₂<:a₁ b₁<:b₂) =
<∷-⋯ (reduce-<: Γ-fo a₂<:a₁) (reduce-<: Γ-fo b₁<:b₂)
reduce-<∷ Γ-fo (fo-Π k₁-fo) (C.<∷-Π (C.<∷-⋯ a₁<:a₂ b₂<:b₁) k₁<∷k₂ bb) =
<∷-Π (reduce-<: Γ-fo a₁<:a₂) (reduce-<: Γ-fo b₂<:b₁)
(reduce-<∷ (fo-∷ (fo-kd fo-⋯) Γ-fo) k₁-fo k₁<∷k₂)
reduce-<: : ∀ {n} {Γ : Ctx n} {a b} → FOCtx (squashCtx Γ) →
Γ C.⊢ a <: b → squashCtx Γ ⊢ squashElim a ∼ squashElim b
reduce-<: Γ-fo (C.<:-trans a<:b b<:c) =
∼-trans (reduce-<: Γ-fo a<:b) (reduce-<: Γ-fo b<:c)
reduce-<: Γ-fo (C.<:-⊥ b⇉b⋯b) = ∼-⊥ (reduce-Nf⇉ Γ-fo b⇉b⋯b)
reduce-<: Γ-fo (C.<:-⊤ a⇉a⋯a) = ∼-⊤ (reduce-Nf⇉ Γ-fo a⇉a⋯a)
reduce-<: Γ-fo (C.<:-∀ _ _ ∀ka⇉⋯) =
∼-⊤ (⇉-⊤-f (Nf⇉-ctx (reduce-Nf⇉ Γ-fo ∀ka⇉⋯)))
reduce-<: Γ-fo (C.<:-→ a₂<:a₁ _) =
∼-⊤ (⇉-⊤-f (∼-ctx (reduce-<: Γ-fo a₂<:a₁)))
reduce-<: {_} {Γ} Γ-fo (C.<:-∙ {as₁ = as} {bs} x∈j₂ j₂⇉as∼bs⇉c₂⋯d₂) =
let j₁ , x⇉j₁ , j₁<∷j₂ = reduce-Var∈ Γ-fo x∈j₂
j₂-fo = <∷-FOKind₂ j₁<∷j₂
j₂⇉as∼bs⇉c₂⋯d₂′ = reduce-Sp≃ Γ-fo j₂-fo j₂⇉as∼bs⇉c₂⋯d₂
k₁ , j₁⇉as∼bs⇉k₁ , k₁<∷c₂⋯d₂ = <∷-Sp∼ j₁<∷j₂ j₂⇉as∼bs⇉c₂⋯d₂′
_ , _ , _ , _ , k₁≡c₁⋯d₁ = <∷-⋯-inv k₁<∷c₂⋯d₂
j₁⇉as∼bs⇉c₁⋯d₁ = subst (squashCtx Γ ⊢ j₁ ⇉∙ squashSpine as ∼
squashSpine bs ⇉_)
k₁≡c₁⋯d₁ j₁⇉as∼bs⇉k₁
in ∼-∙ x⇉j₁ j₁⇉as∼bs⇉c₁⋯d₁
reduce-<: Γ-fo (C.<:-⟨| b∈a⋯c) with reduce-Ne∈ Γ-fo b∈a⋯c
... | b⇇a⋯c = ∼-⟨|-Nf⇇ b⇇a⋯c
reduce-<: Γ-fo (C.<:-|⟩ a∈c⋯b) with reduce-Ne∈ Γ-fo a∈c⋯b
... | a⇇c⋯b = ∼-|⟩-Nf⇇ a⇇c⋯b
reduce-Sp≃ : ∀ {n} {Γ : Ctx n} {j as bs k} →
FOCtx (squashCtx Γ) → FOKind (squashKind j) →
Γ C.⊢ j ⇉∙ as ≃ bs ⇉ k →
squashCtx Γ ⊢ squashKind j ⇉∙ squashSpine as ∼
squashSpine bs ⇉ squashKind k
reduce-Sp≃ Γ-fo _ C.≃-[] = ∼-[]
reduce-Sp≃ Γ-fo (fo-Π k-fo)
(C.≃-∷ {j = c ⋯ d}
(C.<:-antisym _
(C.<:-⇇ (C.⇇-⇑ a⇉c₁⋯d₁ (C.<∷-⋯ _ _)) _ a<:b) _)
k[a∈★]⇉as≃bs⇉l)
with C.Nf⇉-≡ a⇉c₁⋯d₁
reduce-Sp≃ Γ-fo (fo-Π k-fo)
(C.≃-∷ {a} {as} {b} {bs} {c ⋯ d} {k}
(C.<:-antisym _
(C.<:-⇇ (C.⇇-⇑ a⇉a⋯a (C.<∷-⋯ c<:a a<:d)) _ a<:b) _)
k[a∈★]⇉as≃bs⇉l)
| refl , refl =
let k[a∈★]≡k[a] = trans (cong squashKind (Kind/⟨★⟩-/ k))
(squashKind-[] k a)
k[a∈★]-fo = subst FOKind (sym k[a∈★]≡k[a])
(FOKind-/ {σ = sub ⌞ squashElim a ⌟} k-fo)
in ∼-∷ (reduce-<: Γ-fo c<:a) (reduce-<: Γ-fo a<:d)
(reduce-<: Γ-fo a<:b)
(subst (_ ⊢_⇉∙ _ ∼ _ ⇉ _) k[a∈★]≡k[a]
(reduce-Sp≃ Γ-fo k[a∈★]-fo k[a∈★]⇉as≃bs⇉l))
-- A helper to satisfy the termination checker.
reduce-kd-ctx : ∀ {n} {Γ : Ctx n} {k} →
FOCtx (squashCtx Γ) → Γ C.⊢ k kd → squashCtx Γ ctx
reduce-kd-ctx Γ-fo (C.kd-⋯ a⇉a⋯a _) = Nf⇉-ctx (reduce-Nf⇉ Γ-fo a⇉a⋯a)
reduce-kd-ctx Γ-fo (C.kd-Π j-kd _) = reduce-kd-ctx Γ-fo j-kd
|
{
"alphanum_fraction": 0.4775337403,
"avg_line_length": 39.4400369004,
"ext": "agda",
"hexsha": "53baf579ccfdca5ae6f877368281c4437bf43c1f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/FOmegaInt/Kinding/Canonical/Reduced.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/FOmegaInt/Kinding/Canonical/Reduced.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/FOmegaInt/Kinding/Canonical/Reduced.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 22974,
"size": 42753
}
|
------------------------------------------------------------------------
-- An ad-hoc but straightforward solution to the problem of showing
-- that elegant definitions of the Hamming numbers (see EWD 792) and
-- the Fibonacci sequence are productive
------------------------------------------------------------------------
module StreamProg where
open import Codata.Musical.Notation
open import Codata.Musical.Stream as S using (Stream; _∷_; _≈_)
open import Data.Nat
open import Relation.Binary
import Relation.Binary.PropositionalEquality as P
private
module SS {A : Set} = Setoid (S.setoid A)
------------------------------------------------------------------------
-- Merging of streams
data Ord : Set where
lt : Ord
eq : Ord
gt : Ord
merge : {A : Set} → (A → A → Ord) → Stream A → Stream A → Stream A
merge cmp (x ∷ xs) (y ∷ ys) with cmp x y
... | lt = x ∷ ♯ merge cmp (♭ xs) (y ∷ ys)
... | eq = x ∷ ♯ merge cmp (♭ xs) (♭ ys)
... | gt = y ∷ ♯ merge cmp (x ∷ xs) (♭ ys)
------------------------------------------------------------------------
-- Stream programs
infixr 5 _∷_
data StreamP (A : Set) : Set1 where
_∷_ : (x : A) (xs : ∞ (StreamP A)) → StreamP A
zipWith : ∀ {B C} (f : B → C → A)
(xs : StreamP B) (ys : StreamP C) → StreamP A
map : ∀ {B} (f : B → A) (xs : StreamP B) → StreamP A
mergeP : (cmp : A → A → Ord)
(xs : StreamP A) (ys : StreamP A) → StreamP A
data StreamW A : Set1 where
_∷_ : (x : A) (xs : StreamP A) → StreamW A
zipWithW : {A B C : Set} →
(A → B → C) → StreamW A → StreamW B → StreamW C
zipWithW f (x ∷ xs) (y ∷ ys) = f x y ∷ zipWith f xs ys
mapW : {A B : Set} → (A → B) → StreamW A → StreamW B
mapW f (x ∷ xs) = f x ∷ map f xs
mergeW : {A : Set} →
(A → A → Ord) → StreamW A → StreamW A → StreamW A
mergeW cmp (x ∷ xs) (y ∷ ys) with cmp x y
... | lt = x ∷ mergeP cmp xs (y ∷ ♯ ys)
... | eq = x ∷ mergeP cmp xs ys
... | gt = y ∷ mergeP cmp (x ∷ ♯ xs) ys
whnf : ∀ {A} → StreamP A → StreamW A
whnf (x ∷ xs) = x ∷ ♭ xs
whnf (zipWith f xs ys) = zipWithW f (whnf xs) (whnf ys)
whnf (map f xs) = mapW f (whnf xs)
whnf (mergeP cmp xs ys) = mergeW cmp (whnf xs) (whnf ys)
mutual
⟦_⟧W : ∀ {A} → StreamW A → Stream A
⟦ x ∷ xs ⟧W = x ∷ ♯ ⟦ xs ⟧P
⟦_⟧P : ∀ {A} → StreamP A → Stream A
⟦ xs ⟧P = ⟦ whnf xs ⟧W
------------------------------------------------------------------------
-- Examples
fib : StreamP ℕ
fib = 0 ∷ ♯ zipWith _+_ fib (1 ∷ ♯ fib)
-- Alternative definition showing that definitions do not need to
-- start with a cons constructor.
fib′ : StreamP ℕ
fib′ = zipWith _+_ (0 ∷ ♯ fib′) (0 ∷ ♯ (1 ∷ ♯ fib′))
cmp : ℕ → ℕ → Ord
cmp m n = toOrd (compare m n)
where
toOrd : ∀ {m n} → Ordering m n → Ord
toOrd (less _ _) = lt
toOrd (equal _) = eq
toOrd (greater _ _) = gt
hamming : StreamP ℕ
hamming = 1 ∷ ♯ mergeP cmp (map (_*_ 2) hamming) (map (_*_ 3) hamming)
------------------------------------------------------------------------
-- The definition of fib is correct
-- ⟦_⟧P is homomorphic with respect to zipWith/S.zipWith.
zipWith-hom : ∀ {A B C} (_∙_ : A → B → C) xs ys →
⟦ zipWith _∙_ xs ys ⟧P ≈ S.zipWith _∙_ ⟦ xs ⟧P ⟦ ys ⟧P
zipWith-hom _∙_ xs ys with whnf xs | whnf ys
zipWith-hom _∙_ xs ys | x ∷ xs′ | y ∷ ys′ =
P.refl ∷ ♯ zipWith-hom _∙_ xs′ ys′
-- Unfortunately Agda's definitional equality for coinductive
-- constructors is currently a little strange, so the result type
-- cannot be written out completely here:
fib-correct′ :
⟦ fib ⟧P ≈ 0 ∷ ♯ S.zipWith _+_ ⟦ fib ⟧P (1 ∷ _ {- ♯ ⟦ fib ⟧P -})
fib-correct′ = P.refl ∷ ♯ zipWith-hom _+_ fib (1 ∷ ♯ fib)
-- Fortunately there is a workaround.
fib-correct : ⟦ fib ⟧P ≈ 0 ∷ ♯ S.zipWith _+_ ⟦ fib ⟧P (1 ∷ ♯ ⟦ fib ⟧P)
fib-correct =
P.refl ∷ ♯ SS.trans (zipWith-hom _+_ fib (1 ∷ ♯ fib))
(S.zipWith-cong _+_ (SS.refl {x = 0 ∷ _})
(P.refl ∷ ♯ SS.refl))
-- For a proof showing that the given equation for fib has a unique
-- solution, see MapIterate.
------------------------------------------------------------------------
-- The definition of hamming is correct
-- ⟦_⟧P is homomorphic with respect to map/S.map.
map-hom : ∀ {A B} (f : A → B) xs →
⟦ map f xs ⟧P ≈ S.map f ⟦ xs ⟧P
map-hom f xs with whnf xs
... | x ∷ xs′ = P.refl ∷ ♯ map-hom f xs′
-- ⟦_⟧P is homomorphic with respect to mergeP/merge.
merge-hom : ∀ {A} (cmp : A → A → Ord) xs ys →
⟦ mergeP cmp xs ys ⟧P ≈ merge cmp ⟦ xs ⟧P ⟦ ys ⟧P
merge-hom cmp xs ys with whnf xs | whnf ys
... | x ∷ xs′ | y ∷ ys′ with cmp x y
... | lt = P.refl ∷ ♯ merge-hom cmp xs′ (y ∷ ♯ ys′)
... | eq = P.refl ∷ ♯ merge-hom cmp xs′ ys′
... | gt = P.refl ∷ ♯ merge-hom cmp (x ∷ ♯ xs′) ys′
-- merge is a congruence.
merge-cong : ∀ {A} (cmp : A → A → Ord) {xs xs′ ys ys′} →
xs ≈ xs′ → ys ≈ ys′ →
merge cmp xs ys ≈ merge cmp xs′ ys′
merge-cong cmp (_∷_ {x = x} P.refl xs≈)
(_∷_ {x = y} P.refl ys≈) with cmp x y
... | lt = P.refl ∷ ♯ merge-cong cmp (♭ xs≈) (P.refl ∷ ys≈)
... | eq = P.refl ∷ ♯ merge-cong cmp (♭ xs≈) (♭ ys≈)
... | gt = P.refl ∷ ♯ merge-cong cmp (P.refl ∷ xs≈) (♭ ys≈)
-- hamming is correct.
hamming-correct : ⟦ hamming ⟧P ≈
1 ∷ ♯ merge cmp (S.map (_*_ 2) ⟦ hamming ⟧P)
(S.map (_*_ 3) ⟦ hamming ⟧P)
hamming-correct =
P.refl ∷ ♯ SS.trans (merge-hom cmp (map (_*_ 2) hamming)
(map (_*_ 3) hamming))
(merge-cong cmp (map-hom (_*_ 2) hamming)
(map-hom (_*_ 3) hamming))
|
{
"alphanum_fraction": 0.4902689314,
"avg_line_length": 33.2470588235,
"ext": "agda",
"hexsha": "499361beb58656190173932e9e497e8459afa113",
"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": "StreamProg.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": "StreamProg.agda",
"max_line_length": 72,
"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": "StreamProg.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": 2038,
"size": 5652
}
|
module AKS.Modular.Quotient where
open import AKS.Modular.Quotient.Base public
open import AKS.Modular.Quotient.Properties public
|
{
"alphanum_fraction": 0.8473282443,
"avg_line_length": 26.2,
"ext": "agda",
"hexsha": "a11a3706d070ea4ba09aff7d99aa90ea6543dc58",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/thesis",
"max_forks_repo_path": "proofs/AKS/Modular/Quotient.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mckeankylej/thesis",
"max_issues_repo_path": "proofs/AKS/Modular/Quotient.agda",
"max_line_length": 50,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/thesis",
"max_stars_repo_path": "proofs/AKS/Modular/Quotient.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z",
"num_tokens": 34,
"size": 131
}
|
module Formalization.ClassicalPropositionalLogic.Semantics.Proofs where
import Lvl
open import Data
open import Data.Boolean
open import Data.Either as Either using (_‖_ ; Left ; Right)
open import Formalization.ClassicalPropositionalLogic.Syntax
open import Formalization.ClassicalPropositionalLogic.Semantics
open import Functional
open import Logic.Classical as Logic using (Classical)
import Logic.Propositional as Logic
import Logic.Predicate as Logic
open import Relator.Equals
open import Relator.Equals.Proofs
open import Sets.PredicateSet using (PredSet ; _∈_ ; _∉_ ; _∪_ ; _∪•_ ; _∖_ ; _⊆_ ; _⊇_ ; ∅ ; [≡]-to-[⊆] ; [≡]-to-[⊇]) renaming (•_ to singleton ; _≡_ to _≡ₛ_)
open import Type
private variable ℓₚ ℓ : Lvl.Level
private variable P : Type{ℓₚ}
private variable 𝔐 : Model(P)
private variable Γ Γ₁ Γ₂ : Formulas(P){ℓ}
private variable φ ψ : Formula(P)
[⊧₊]-antimonotone : (Γ₁ ⊆ Γ₂) → ((_⊧₊ Γ₁) ⊇ (_⊧₊ Γ₂))
[⊧₊]-antimonotone Γ₁Γ₂ 𝔐Γ₂ Γ₁γ = 𝔐Γ₂ (Γ₁Γ₂ Γ₁γ)
[⊧₊]-strengthen : (𝔐 ⊧₊ Γ₁) → (𝔐 ⊧₊ Γ₂) → (𝔐 ⊧₊ (Γ₁ ∪ Γ₂))
[⊧₊]-strengthen 𝔐Γ₁ 𝔐Γ₂ Γ₁Γ₂γ = Logic.[∨]-elim 𝔐Γ₁ 𝔐Γ₂ Γ₁Γ₂γ
[⊧₊]-of-[∪]ₗ : (𝔐 ⊧₊ (Γ₁ ∪ Γ₂)) → (𝔐 ⊧₊ Γ₁)
[⊧₊]-of-[∪]ₗ 𝔐Γ₁Γ₂ 𝔐Γ₁ = 𝔐Γ₁Γ₂ (Left 𝔐Γ₁)
[⊧₊]-of-[∪]ᵣ : (𝔐 ⊧₊ (Γ₁ ∪ Γ₂)) → (𝔐 ⊧₊ Γ₂)
[⊧₊]-of-[∪]ᵣ 𝔐Γ₁Γ₂ 𝔐Γ₂ = 𝔐Γ₁Γ₂ (Right 𝔐Γ₂)
[⊧]-to-[⊧₊] : (𝔐 ⊧ φ) Logic.↔ (𝔐 ⊧₊ singleton(φ))
[⊧]-to-[⊧₊] = Logic.[↔]-intro (_$ [≡]-intro) (\𝔐φ φγ → [≡]-substitutionᵣ φγ 𝔐φ)
[⊧]-contradiction : (𝔐 ⊧ φ) → (𝔐 ⊧ (¬ φ)) → (𝔐 ⊧ ⊥)
[⊧]-contradiction = apply
[⊨]-monotone : (Γ₁ ⊆ Γ₂) → ((Γ₁ ⊨_) ⊆ (Γ₂ ⊨_))
[⊨]-monotone Γ₁Γ₂ Γ₁φ 𝔐Γ₂ = Γ₁φ (Γ₁γ ↦ 𝔐Γ₂ (Γ₁Γ₂ Γ₁γ))
[⊨]-functionₗ : (Γ₁ ≡ₛ Γ₂) → ((Γ₁ ⊨_) ≡ₛ (Γ₂ ⊨_))
[⊨]-functionₗ {Γ₁ = Γ₁}{Γ₂ = Γ₂} Γ₁Γ₂ {φ} = Logic.[↔]-intro ([⊨]-monotone{Γ₁ = Γ₂}{Γ₂ = Γ₁}(\{x} → [≡]-to-[⊇] (Γ₁Γ₂{x}) {x}){φ}) ([⊨]-monotone{Γ₁ = Γ₁}{Γ₂ = Γ₂}(\{x} → [≡]-to-[⊆] (Γ₁Γ₂{x}) {x}){φ})
[⊨]-weaken : (Γ₁ ⊨ φ) → ((Γ₁ ∪ Γ₂) ⊨ φ)
[⊨]-weaken Γ₁φ 𝔐Γ₁Γ₂ = Γ₁φ (Γ₁γ ↦ 𝔐Γ₁Γ₂ (Left Γ₁γ))
[⊨]-validity : (∀{Γ : Formulas(P){ℓ}} → (Γ ⊨ φ)) Logic.↔ Valid(φ)
[⊨]-validity = Logic.[↔]-intro (λ r → const r) (λ l → l{∅} empty)
[⊨]-contradiction : (Γ ⊨ φ) → (Γ ⊨ (¬ φ)) → (Γ ⊨ ⊥)
[⊨]-contradiction Γφ Γ¬φ 𝔐Γ = Γ¬φ 𝔐Γ (Γφ 𝔐Γ)
[⊨]-unsatisfiability : (Γ ⊨ ⊥) Logic.↔ Unsatisfiable(Γ)
[⊨]-unsatisfiability {Γ = Γ} = Logic.[↔]-intro l r where
l : (Γ ⊨ ⊥) ← Unsatisfiable(Γ)
l unsatΓ {𝔐} 𝔐Γ = unsatΓ (Logic.[∃]-intro 𝔐 ⦃ 𝔐Γ ⦄)
r : (Γ ⊨ ⊥) → Unsatisfiable(Γ)
r Γ⊥ (Logic.[∃]-intro 𝔐 ⦃ 𝔐Γ ⦄) = Γ⊥ 𝔐Γ
[⊨][¬]-intro : ((Γ ∪ singleton(φ)) ⊨ ⊥) Logic.↔ (Γ ⊨ (¬ φ))
[⊨][¬]-intro {Γ = Γ}{φ = φ} = Logic.[↔]-intro l r where
l : ((Γ ∪ singleton(φ)) ⊨ ⊥) ← (Γ ⊨ (¬ φ))
l Γ¬φ 𝔐Γφ = Γ¬φ (𝔐Γφ ∘ Left) (𝔐Γφ (Right [≡]-intro))
r : ((Γ ∪ singleton(φ)) ⊨ ⊥) → (Γ ⊨ (¬ φ))
r Γφ⊥ 𝔐Γ 𝔐φ = Γφ⊥ ([⊧₊]-strengthen {Γ₁ = Γ}{Γ₂ = singleton(φ)} 𝔐Γ (Logic.[↔]-to-[→] [⊧]-to-[⊧₊] 𝔐φ))
[∅]-satisfiable : Satisfiable{P = P}{ℓ = ℓ}(∅)
[∅]-satisfiable = Logic.[∃]-intro (const(𝑇)) ⦃ \{_}() ⦄
module _ ⦃ classical : ∀{ℓ} → Logic.∀ₗ(Classical{ℓ}) ⦄ where
[⊧]-of-[¬¬] : (𝔐 ⊧ ¬(¬ φ)) → (𝔐 ⊧ φ)
[⊧]-of-[¬¬] {𝔐 = 𝔐}{φ = φ} = Logic.[¬¬]-elim
[⊨]-entailment-unsatisfiability : (Γ ⊨ φ) Logic.↔ Unsatisfiable(Γ ∪ singleton(¬ φ))
[⊨]-entailment-unsatisfiability {Γ = Γ}{φ = φ} = Logic.[↔]-intro l r where
l : (Γ ⊨ φ) ← Unsatisfiable(Γ ∪ singleton(¬ φ))
l r {𝔐} 𝔐Γ = [⊧]-of-[¬¬] {𝔐 = 𝔐}{φ = φ} (𝔐¬φ ↦ r (Logic.[∃]-intro 𝔐 ⦃ Logic.[∨]-elim 𝔐Γ (\{[≡]-intro → 𝔐¬φ}) ⦄))
r : (Γ ⊨ φ) → Unsatisfiable(Γ ∪ singleton(¬ φ))
r l (Logic.[∃]-intro 𝔐 ⦃ sat ⦄) = [⊧]-contradiction {φ = φ} 𝔐φ 𝔐¬φ where
𝔐φ = l([⊧₊]-of-[∪]ₗ {Γ₁ = Γ} sat)
𝔐¬φ = Logic.[↔]-to-[←] [⊧]-to-[⊧₊] ([⊧₊]-of-[∪]ᵣ {Γ₁ = Γ} sat)
[⊨][⟶]-intro : ((Γ ∪ singleton(φ)) ⊨ ψ) Logic.↔ (Γ ⊨ (φ ⟶ ψ))
[⊨][⟶]-intro {Γ = Γ}{φ = φ}{ψ = ψ} = Logic.[↔]-intro l r where
l : (Γ ⊨ (φ ⟶ ψ)) → ((Γ ∪ singleton(φ)) ⊨ ψ)
l φψ {𝔐 = 𝔐} 𝔐Γφ = Logic.[∨]-elim (¬φ ↦ Logic.[⊥]-elim(¬φ 𝔐φ)) id (φψ 𝔐Γ) where
𝔐Γ : 𝔐 ⊧₊ Γ
𝔐Γ {γ} Γγ = 𝔐Γφ {γ} (Logic.[∨]-introₗ Γγ)
𝔐φ : 𝔐 ⊧ φ
𝔐φ = 𝔐Γφ {φ} (Logic.[∨]-introᵣ [≡]-intro)
r : ((Γ ∪ singleton(φ)) ⊨ ψ) → (Γ ⊨ (φ ⟶ ψ))
r Γφψ {𝔐 = 𝔐} 𝔐Γ with Logic.excluded-middle(𝔐 ⊧ φ)
... | Logic.[∨]-introₗ 𝔐φ = Logic.[∨]-introᵣ (Γφψ(Logic.[∨]-elim 𝔐Γ \{[≡]-intro → 𝔐φ}))
... | Logic.[∨]-introᵣ ¬𝔐φ = Logic.[∨]-introₗ ¬𝔐φ
|
{
"alphanum_fraction": 0.5198135198,
"avg_line_length": 41.25,
"ext": "agda",
"hexsha": "5d385b8644992b2d2f1700e7fe1ff461b97769b5",
"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": "Formalization/ClassicalPropositionalLogic/Semantics/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": "Formalization/ClassicalPropositionalLogic/Semantics/Proofs.agda",
"max_line_length": 197,
"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": "Formalization/ClassicalPropositionalLogic/Semantics/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": 2586,
"size": 4290
}
|
module InstanceArgumentsHidden where
record ⊤ : Set where
-- check that the instance argument resolution takes into account
-- instances which take hidden arguments to be of the correct type.
postulate A1 A2 B : Set
f1 : {{a : A1}} → B
f2 : {{a : A2}} → B
inst1 : {_ : ⊤} → A1
checkProperty : ⊤ → Set
checkProperty _ = ⊤
postulate inst2 : {a : ⊤} → {_ : checkProperty a} → A2
test1 = f1
test2 = f2
|
{
"alphanum_fraction": 0.6189376443,
"avg_line_length": 22.7894736842,
"ext": "agda",
"hexsha": "c253e71055f2808f1937c70b91cefe8b1c3bbfc7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/InstanceArgumentsHidden.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/InstanceArgumentsHidden.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": "test/succeed/InstanceArgumentsHidden.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": 135,
"size": 433
}
|
module MagicWith where
data _×_ (A : Set)(B : A -> Set) : Set where
_,_ : (x : A) -> B x -> A × B
fst : {A : Set}{B : A -> Set} -> A × B -> A
fst (x , y) = x
snd : {A : Set}{B : A -> Set}(p : A × B) -> B (fst p)
snd (x , y) = y
data Nat : Set where
zero : Nat
suc : Nat -> Nat
record True : Set where
data False : Set where
IsZero : Nat -> Set
IsZero zero = True
IsZero (suc _) = False
Uncurry : {A : Set}{B : A -> Set} -> ((x : A) -> B x -> Set) -> A × B -> Set
Uncurry F p = F (fst p) (snd p)
F : (n : Nat) -> IsZero n -> Set
F zero _ = True
F (suc _) ()
-- Trying to match only on fst p will give a (bad) error,
-- just as it should.
f : (p : Nat × IsZero) -> Uncurry F p
f p with fst p | snd p
f p | zero | q = _
f p | suc _ | ()
|
{
"alphanum_fraction": 0.5059445178,
"avg_line_length": 21.0277777778,
"ext": "agda",
"hexsha": "eeaebc5f3f918666b58333861f30d6f7001fa0ec",
"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/MagicWith.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/MagicWith.agda",
"max_line_length": 76,
"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/MagicWith.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": 297,
"size": 757
}
|
------------------------------------------------------------------------
-- An alternative definition of listed finite subsets
------------------------------------------------------------------------
-- The code in this module is based on Frumin, Geuvers, Gondelman and
-- van der Weide's "Finite Sets in Homotopy Type Theory". However, the
-- type of subsets is defined mutually with a membership predicate,
-- and two higher constructors have been replaced by a constructor
-- that states that extensionally equal subsets are equal.
--
-- The type in this module is perhaps harder to work with than the one
-- in Finite-subset.Listed: the "natural" eliminator only works for
-- motives that are propositional. However, the two types are shown to
-- be equivalent.
{-# OPTIONS --cubical --safe #-}
import Equality.Path as P
module Finite-subset.Listed.Alternative
{c⁺} (eq : ∀ {a p} → P.Equality-with-paths a p c⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
import Equality.Path.Univalence as EPU
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (_∷_; swap)
open import Bijection equality-with-J using (_↔_)
import Bijection P.equality-with-J as PB
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq using (_≃_)
import Equivalence P.equality-with-J as PEq
import Finite-subset.Listed eq as Listed
open import Function-universe equality-with-J as F hiding (id; _∘_)
import H-level P.equality-with-J as PH
open import H-level.Closure equality-with-J
import H-level.Closure P.equality-with-J as PHC
open import H-level.Truncation.Propositional eq as Trunc
using (∥_∥; _∥⊎∥_)
open import Injection equality-with-J using (Injective)
import Univalence-axiom P.equality-with-J as PU
private
variable
a b p : Level
A B : Type a
P : A → Type p
x x∼y y y₁ y₂ z z₁ z₂ : A
------------------------------------------------------------------------
-- Listed finite subsets
mutual
-- Listed finite subsets of a given type, defined mutually with a
-- membership predicate.
infixr 5 _∷_
data Finite-subset-of (A : Type a) : Type a where
[] : Finite-subset-of A
_∷_ : A → Finite-subset-of A → Finite-subset-of A
extensionalityᴾ : x ∼ y → x P.≡ y
is-setᴾ : P.Is-set (Finite-subset-of A)
private
Membership :
{A : Type a} → A → Finite-subset-of A → PH.Proposition a
-- Membership.
infix 4 _∈_
_∈_ : {A : Type a} → A → Finite-subset-of A → Type a
x ∈ y = proj₁ (Membership x y)
-- Membership is propositional.
∈-propositionalᴾ : ∀ y → P.Is-proposition (x ∈ y)
∈-propositionalᴾ y = proj₂ (Membership _ y)
-- Extensional equality.
infix 4 _∼_
_∼_ :
{A : Type a} → Finite-subset-of A → Finite-subset-of A → Type a
x ∼ y = ∀ z → z ∈ x ⇔ z ∈ y
Membership x [] =
⊥ , PHC.⊥-propositional
Membership x (y ∷ z) =
(x ≡ y ∥⊎∥ x ∈ z) , Trunc.truncation-is-propositionᴾ
Membership x (extensionalityᴾ {x = y} {y = z} y∼z i) =
lemma i
where
lemma : Membership x y P.≡ Membership x z
lemma = P.Σ-≡,≡→≡
(x ∈ y P.≡⟨ PEq._≃_.from
(PU.Propositional-extensionality-is-univalence-for-propositions P.ext)
(λ _ _ → EPU.univ)
(∈-propositionalᴾ y)
(∈-propositionalᴾ z)
(y∼z x) ⟩∎
x ∈ z ∎)
(PHC.H-level-propositional P.ext 1 _ _)
Membership x (is-setᴾ {x = y} {y = z} p q i j) =
P.heterogeneous-UIP₀₀
{x = λ _ → Membership x y}
{y = λ _ → Membership x z}
{p = λ i → Membership x (p i)}
{q = λ i → Membership x (q i)}
(PU.∃-H-level-H-level-1+ P.ext EPU.univ 1)
i j
-- Variants of some of the constructors.
extensionality : x ∼ y → x ≡ y
extensionality = _↔_.from ≡↔≡ ∘ extensionalityᴾ
is-set : Is-set (Finite-subset-of A)
is-set =
_↔_.from (H-level↔H-level 2) Finite-subset-of.is-setᴾ
-- Membership is propositional.
∈-propositional : ∀ y → Is-proposition (x ∈ y)
∈-propositional = _↔_.from (H-level↔H-level 1) ∘ ∈-propositionalᴾ
-- Unit tests documenting some of the computational behaviour of _∈_.
_ : (x ∈ []) ≡ ⊥
_ = refl _
_ : (x ∈ y ∷ z) ≡ (x ≡ y ∥⊎∥ x ∈ z)
_ = refl _
------------------------------------------------------------------------
-- Eliminators
private
-- The following dependent eliminator is not exported, because the
-- motive is necessarily pointwise propositional (see
-- motive-propositional below).
record Elimᴾ′ {A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
[]ʳ : P []
∷ʳ : ∀ x → P y → P (x ∷ y)
is-setʳ : ∀ x → P.Is-set (P x)
extensionalityʳ :
(p : P x) (q : P y) →
P.[ (λ i → P (extensionalityᴾ {x = x} {y = y} x∼y i)) ] p ≡ q
open Elimᴾ′
elimᴾ′ : Elimᴾ′ P → (x : Finite-subset-of A) → P x
elimᴾ′ {A = A} {P = P} e = helper
where
module E = Elimᴾ′ e
helper : (x : Finite-subset-of A) → P x
helper [] = E.[]ʳ
helper (x ∷ y) = E.∷ʳ x (helper y)
helper (extensionalityᴾ {x = x} {y = y} _ i) =
E.extensionalityʳ (helper x) (helper y) i
helper (is-setᴾ x y i j) =
P.heterogeneous-UIP
E.is-setʳ (is-setᴾ x y)
(λ i → helper (x i)) (λ i → helper (y i)) i j
-- The motive is necessarily pointwise propositional.
motive-propositional :
Elimᴾ′ P → ∀ x → P.Is-proposition (P x)
motive-propositional {P = P} e x p q =
p P.≡⟨ P.sym $ P.subst-refl P _ ⟩
P.subst P P.refl p P.≡⟨ P.cong (λ eq → P.subst P eq p) $ is-setᴾ _ _ ⟩
P.subst P (extensionalityᴾ λ _ → F.id) p P.≡⟨ PB._↔_.to (P.heterogeneous↔homogeneous _)
(e .extensionalityʳ {x∼y = λ _ → F.id} p q) ⟩∎
q ∎
-- A dependent eliminator, expressed using paths.
record Elimᴾ {A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
[]ʳ : P []
∷ʳ : ∀ x → P y → P (x ∷ y)
is-propositionʳ : ∀ x → P.Is-proposition (P x)
open Elimᴾ public
elimᴾ : Elimᴾ P → (x : Finite-subset-of A) → P x
elimᴾ {A = A} {P = P} e = elimᴾ′ e′
where
module E = Elimᴾ e
e′ : Elimᴾ′ _
e′ .[]ʳ = e .[]ʳ
e′ .∷ʳ = e .∷ʳ
e′ .is-setʳ = PH.mono₁ 1 ∘ e .is-propositionʳ
e′ .extensionalityʳ _ _ =
PB._↔_.from (P.heterogeneous↔homogeneous _)
(e .is-propositionʳ _ _ _)
-- A non-dependent eliminator, expressed using paths.
record Recᴾ (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
[]ʳ : B
∷ʳ : A → Finite-subset-of A → B → B
is-propositionʳ : P.Is-proposition B
open Recᴾ public
recᴾ : Recᴾ A B → Finite-subset-of A → B
recᴾ {A = A} {B = B} r = elimᴾ e
where
module R = Recᴾ r
e : Elimᴾ _
e .[]ʳ = R.[]ʳ
e .∷ʳ {y = y} x = R.∷ʳ x y
e .is-propositionʳ _ = R.is-propositionʳ
-- A dependent eliminator, expressed using equality.
record Elim
{A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
field
[]ʳ : P []
∷ʳ : ∀ x → P y → P (x ∷ y)
is-propositionʳ : ∀ x → Is-proposition (P x)
open Elim public
elim : Elim P → (x : Finite-subset-of A) → P x
elim e = elimᴾ e′
where
module E = Elim e
e′ : Elimᴾ _
e′ .[]ʳ = E.[]ʳ
e′ .∷ʳ = E.∷ʳ
e′ .is-propositionʳ = _↔_.to (H-level↔H-level 1) ∘ E.is-propositionʳ
-- A non-dependent eliminator, expressed using equality.
record Rec (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
[]ʳ : B
∷ʳ : A → Finite-subset-of A → B → B
is-propositionʳ : Is-proposition B
open Rec public
rec : Rec A B → Finite-subset-of A → B
rec r = elim e
where
module R = Rec r
e : Elim _
e .[]ʳ = R.[]ʳ
e .∷ʳ {y = y} x = R.∷ʳ x y
e .is-propositionʳ _ = R.is-propositionʳ
------------------------------------------------------------------------
-- Some lemmas
-- If A is inhabited, then Finite-subset-of A is not a proposition.
¬-proposition : A → ¬ Is-proposition (Finite-subset-of A)
¬-proposition {A = A} x =
Is-proposition (Finite-subset-of A) ↝⟨ (λ hyp → hyp _ _) ⟩
x ∷ [] ≡ [] ↝⟨ (λ hyp → subst (x ∈_) hyp (Trunc.∣inj₁∣ (refl _))) ⟩
x ∈ [] ↔⟨ ⊥↔⊥ ⟩□
⊥ □
abstract
-- Duplicated elements can be dropped.
drop : x ∷ x ∷ y ≡ x ∷ y
drop {x = x} {y = y} = extensionality λ z →
z ≡ x ∥⊎∥ (z ≡ x ∥⊎∥ z ∈ y) ↔⟨ Trunc.drop-left-∥⊎∥ Trunc.∥⊎∥-propositional Trunc.∣inj₁∣ ⟩□
z ≡ x ∥⊎∥ z ∈ y □
-- The "first" two elements can be swapped.
swap : x ∷ y ∷ z ≡ y ∷ x ∷ z
swap {x = x} {y = y} {z = z} = extensionality λ u →
u ≡ x ∥⊎∥ (u ≡ y ∥⊎∥ u ∈ z) ↔⟨ Trunc.∥⊎∥-assoc ⟩
(u ≡ x ∥⊎∥ u ≡ y) ∥⊎∥ u ∈ z ↔⟨ Trunc.∥⊎∥-comm Trunc.∥⊎∥-cong F.id ⟩
(u ≡ y ∥⊎∥ u ≡ x) ∥⊎∥ u ∈ z ↔⟨ inverse Trunc.∥⊎∥-assoc ⟩□
u ≡ y ∥⊎∥ (u ≡ x ∥⊎∥ u ∈ z) □
-- If x is a member of y, then x ∷ y is equal to y.
∈→∷≡ : x ∈ y → x ∷ y ≡ y
∈→∷≡ {x = x} = elim e _
where
e : Elim (λ y → x ∈ y → x ∷ y ≡ y)
e .∷ʳ {y = y} z hyp =
Trunc.rec is-set
[ (λ x≡z →
x ∷ z ∷ y ≡⟨ cong (λ x → x ∷ _) x≡z ⟩
z ∷ z ∷ y ≡⟨ drop ⟩∎
z ∷ y ∎)
, (λ x∈y →
x ∷ z ∷ y ≡⟨ swap ⟩
z ∷ x ∷ y ≡⟨ cong (_ ∷_) (hyp x∈y) ⟩∎
z ∷ y ∎)
]
e .is-propositionʳ _ =
Π-closure ext 1 λ _ →
is-set
------------------------------------------------------------------------
-- Some operations
-- Singleton subsets.
singleton : A → Finite-subset-of A
singleton x = x ∷ []
-- A lemma characterising singleton.
∈singleton≃ :
(x ∈ singleton y) ≃ ∥ x ≡ y ∥
∈singleton≃ {x = x} {y = y} =
x ∈ singleton y ↔⟨⟩
x ≡ y ∥⊎∥ ⊥ ↔⟨ Trunc.∥∥-cong $ drop-⊥-right ⊥↔⊥ ⟩□
∥ x ≡ y ∥ □
-- If truncated equality is decidable, then membership is also
-- decidable.
member? :
((x y : A) → Dec ∥ x ≡ y ∥) →
(x : A) (y : Finite-subset-of A) → Dec (x ∈ y)
member? equal? x = elim e
where
e : Elim _
e .[]ʳ = no λ ()
e .∷ʳ {y = z} y = case equal? x y of
[ (λ ∥x≡y∥ _ → yes (Trunc.∥∥-map inj₁ ∥x≡y∥))
, (λ ¬∥x≡y∥ →
[ (λ x∈z → yes (Trunc.∣inj₂∣ x∈z))
, (λ x∉z → no (
x ∈ y ∷ z ↔⟨⟩
x ≡ y ∥⊎∥ x ∈ z ↝⟨ Trunc.∥∥-map [ ¬∥x≡y∥ ∘ Trunc.∣_∣ , x∉z ] ⟩
∥ ⊥ ∥ ↔⟨ Trunc.not-inhabited⇒∥∥↔⊥ id ⟩□
⊥ □))
])
]
e .is-propositionʳ y =
Dec-closure-propositional ext (∈-propositional y)
------------------------------------------------------------------------
-- The union operation
private
-- A specification of what it means for a subset to be the union of
-- two subsets.
Is-union-of :
{A : Type a} (_ _ _ : Finite-subset-of A) → Type a
Is-union-of x y z = ∀ u → (u ∈ z) ≃ (u ∈ x ∥⊎∥ u ∈ y)
-- Is-union-of x y is functional.
Is-union-of-functional :
(x y : Finite-subset-of A) →
Is-union-of x y z₁ → Is-union-of x y z₂ →
z₁ ≡ z₂
Is-union-of-functional {z₁ = z₁} {z₂ = z₂} x y p₁ p₂ =
extensionality λ u →
u ∈ z₁ ↔⟨ p₁ u ⟩
u ∈ x ∥⊎∥ u ∈ y ↔⟨ inverse $ p₂ u ⟩□
u ∈ z₂ □
-- Is-union-of is propositional.
Is-union-of-propositional :
(x y z : Finite-subset-of A) →
Is-proposition (Is-union-of x y z)
Is-union-of-propositional x y z =
Π-closure ext 1 λ _ →
Eq.left-closure ext 0 (∈-propositional z)
-- The union operation, along with a correctness proof.
union : (x y : Finite-subset-of A) → ∃ (Is-union-of x y)
union = elim e
where
e : Elim _
e .[]ʳ y =
y
, λ u →
u ∈ y ↔⟨ inverse $ Trunc.∥⊎∥-left-identity (∈-propositional y) ⟩□
⊥ ∥⊎∥ u ∈ y □
e .∷ʳ {y = y} x hyp z =
x ∷ proj₁ (hyp z)
, λ u →
u ∈ x ∷ proj₁ (hyp z) ↔⟨⟩
u ≡ x ∥⊎∥ u ∈ proj₁ (hyp z) ↝⟨ F.id Trunc.∥⊎∥-cong proj₂ (hyp z) u ⟩
u ≡ x ∥⊎∥ (u ∈ y ∥⊎∥ u ∈ z) ↔⟨ Trunc.∥⊎∥-assoc ⟩
(u ≡ x ∥⊎∥ u ∈ y) ∥⊎∥ u ∈ z ↔⟨⟩
u ∈ x ∷ y ∥⊎∥ u ∈ z □
e .is-propositionʳ x f g = ⟨ext⟩ λ y →
Σ-≡,≡→≡
(Is-union-of-functional x y (proj₂ (f y)) (proj₂ (g y)))
(Is-union-of-propositional x y (proj₁ (g y)) _ _)
-- The union of two finite subsets.
infixr 5 _∪_
_∪_ :
Finite-subset-of A → Finite-subset-of A →
Finite-subset-of A
x ∪ y = proj₁ (union x y)
-- Unit tests documenting some of the computational behaviour of _∪_.
_ : [] ∪ x ≡ x
_ = refl _
_ : (x ∷ y) ∪ z ≡ x ∷ (y ∪ z)
_ = refl _
-- Membership of a union of two subsets can be expressed in terms of
-- membership of the subsets.
∈∪≃∈∥⊎∥∈ : ∀ y → (x ∈ y ∪ z) ≃ (x ∈ y ∥⊎∥ x ∈ z)
∈∪≃∈∥⊎∥∈ {z = z} y = proj₂ (union y z) _
-- If x is a member of y, then x is a member of y ∪ z.
∈→∈∪ˡ : ∀ y → x ∈ y → x ∈ y ∪ z
∈→∈∪ˡ y = _≃_.from (∈∪≃∈∥⊎∥∈ y) ∘ Trunc.∣inj₁∣
-- If x is a member of z, then x is a member of y ∪ z.
∈→∈∪ʳ : ∀ y → x ∈ z → x ∈ y ∪ z
∈→∈∪ʳ y = _≃_.from (∈∪≃∈∥⊎∥∈ y) ∘ Trunc.∣inj₂∣
-- [] is a right identity of _∪_.
∪[] :
(x : Finite-subset-of A) →
x ∪ [] ≡ x
∪[] = elim e
where
e : Elim _
e .is-propositionʳ _ = is-set
e .[]ʳ = refl _
e .∷ʳ {y = y} x hyp =
x ∷ y ∪ [] ≡⟨ cong (x ∷_) hyp ⟩∎
x ∷ y ∎
-- A lemma relating _∪_ and _∷_.
∪∷ :
(x : Finite-subset-of A) →
x ∪ (y ∷ z) ≡ y ∷ x ∪ z
∪∷ {y = y} {z = z} = elim e
where
e : Elim _
e .is-propositionʳ _ = is-set
e .[]ʳ = refl _
e .∷ʳ {y = u} x hyp =
(x ∷ u) ∪ (y ∷ z) ≡⟨⟩
x ∷ u ∪ (y ∷ z) ≡⟨ cong (x ∷_) hyp ⟩
x ∷ y ∷ u ∪ z ≡⟨ swap ⟩
y ∷ x ∷ u ∪ z ≡⟨⟩
y ∷ (x ∷ u) ∪ z ∎
-- The union operator is associative.
∪-assoc :
(x : Finite-subset-of A) →
x ∪ (y ∪ z) ≡ (x ∪ y) ∪ z
∪-assoc {y = y} {z = z} = elim e
where
e : Elim _
e .is-propositionʳ _ = is-set
e .[]ʳ = refl _
e .∷ʳ {y = u} x hyp =
x ∷ u ∪ (y ∪ z) ≡⟨ cong (x ∷_) hyp ⟩∎
x ∷ (u ∪ y) ∪ z ∎
-- The union operator is commutative.
∪-comm :
(x : Finite-subset-of A) →
x ∪ y ≡ y ∪ x
∪-comm {y = y} = elim e
where
e : Elim _
e .is-propositionʳ _ = is-set
e .[]ʳ =
[] ∪ y ≡⟨⟩
y ≡⟨ sym (∪[] y) ⟩∎
y ∪ [] ∎
e .∷ʳ {y = z} x hyp =
x ∷ z ∪ y ≡⟨ cong (x ∷_) hyp ⟩
x ∷ y ∪ z ≡⟨ sym (∪∷ y) ⟩∎
y ∪ (x ∷ z) ∎
-- The union operator is idempotent.
∪-idem : (x : Finite-subset-of A) → x ∪ x ≡ x
∪-idem = elim e
where
e : Elim _
e .[]ʳ =
[] ∪ [] ≡⟨⟩
[] ∎
e .∷ʳ {y = y} x hyp =
(x ∷ y) ∪ (x ∷ y) ≡⟨⟩
x ∷ y ∪ x ∷ y ≡⟨ cong (_ ∷_) (∪∷ y) ⟩
x ∷ x ∷ y ∪ y ≡⟨ drop ⟩
x ∷ y ∪ y ≡⟨ cong (_ ∷_) hyp ⟩∎
x ∷ y ∎
e .is-propositionʳ = λ _ → is-set
-- The union operator distributes from the left and right over itself.
∪-distrib-left : ∀ x → x ∪ (y ∪ z) ≡ (x ∪ y) ∪ (x ∪ z)
∪-distrib-left {y = y} {z = z} x =
x ∪ (y ∪ z) ≡⟨ cong (_∪ _) $ sym (∪-idem x) ⟩
(x ∪ x) ∪ (y ∪ z) ≡⟨ sym $ ∪-assoc x ⟩
x ∪ (x ∪ (y ∪ z)) ≡⟨ cong (x ∪_) $ ∪-assoc x ⟩
x ∪ ((x ∪ y) ∪ z) ≡⟨ cong ((x ∪_) ∘ (_∪ _)) $ ∪-comm x ⟩
x ∪ ((y ∪ x) ∪ z) ≡⟨ cong (x ∪_) $ sym $ ∪-assoc y ⟩
x ∪ (y ∪ (x ∪ z)) ≡⟨ ∪-assoc x ⟩∎
(x ∪ y) ∪ (x ∪ z) ∎
∪-distrib-right : ∀ x → (x ∪ y) ∪ z ≡ (x ∪ z) ∪ (y ∪ z)
∪-distrib-right {y = y} {z = z} x =
(x ∪ y) ∪ z ≡⟨ ∪-comm (x ∪ _) ⟩
z ∪ (x ∪ y) ≡⟨ ∪-distrib-left z ⟩
(z ∪ x) ∪ (z ∪ y) ≡⟨ cong₂ _∪_ (∪-comm z) (∪-comm z) ⟩∎
(x ∪ z) ∪ (y ∪ z) ∎
------------------------------------------------------------------------
-- Subsets of subsets
-- Subsets.
infix 4 _⊆_
_⊆_ : {A : Type a} → Finite-subset-of A → Finite-subset-of A → Type a
x ⊆ y = ∀ z → z ∈ x → z ∈ y
-- _⊆_ is pointwise propositional.
⊆-propositional :
(x y : Finite-subset-of A) → Is-proposition (x ⊆ y)
⊆-propositional x y =
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
∈-propositional y
-- The function x ∷_ is monotone with respect to _⊆_.
∷-cong-⊆ : ∀ y z → y ⊆ z → x ∷ y ⊆ x ∷ z
∷-cong-⊆ {x = x} y z y⊆z = λ u →
u ∈ x ∷ y ↔⟨⟩
u ≡ x ∥⊎∥ u ∈ y ↝⟨ id Trunc.∥⊎∥-cong y⊆z _ ⟩
u ≡ x ∥⊎∥ u ∈ z ↔⟨⟩
u ∈ x ∷ z □
-- The union operator is monotone with respect to _⊆_.
∪-mono-⊆ : ∀ x₁ x₂ → x₁ ⊆ x₂ → y₁ ⊆ y₂ → x₁ ∪ y₁ ⊆ x₂ ∪ y₂
∪-mono-⊆ {y₁ = y₁} {y₂ = y₂} x₁ x₂ x₁⊆x₂ y₁⊆y₂ = λ u →
u ∈ x₁ ∪ y₁ ↔⟨ ∈∪≃∈∥⊎∥∈ x₁ ⟩
u ∈ x₁ ∥⊎∥ u ∈ y₁ ↝⟨ x₁⊆x₂ u Trunc.∥⊎∥-cong y₁⊆y₂ u ⟩
u ∈ x₂ ∥⊎∥ u ∈ y₂ ↔⟨ inverse $ ∈∪≃∈∥⊎∥∈ x₂ ⟩□
u ∈ x₂ ∪ y₂ □
-- The subset property can be expressed using _∪_ and _≡_.
⊆≃∪≡ : ∀ x → (x ⊆ y) ≃ (x ∪ y ≡ y)
⊆≃∪≡ {y = y} x = Eq.⇔→≃
(⊆-propositional x y)
is-set
(elim e x)
(λ p z →
z ∈ x ↝⟨ ∈→∈∪ˡ x ⟩
z ∈ x ∪ y ↝⟨ ≡⇒↝ _ (cong (z ∈_) p) ⟩□
z ∈ y □)
where
e : Elim (λ x → x ⊆ y → x ∪ y ≡ y)
e .[]ʳ _ =
[] ∪ y ≡⟨⟩
y ∎
e .∷ʳ {y = z} x hyp x∷z⊆y =
x ∷ z ∪ y ≡⟨ cong (x ∷_) (hyp (λ _ → x∷z⊆y _ ∘ Trunc.∣inj₂∣)) ⟩
x ∷ y ≡⟨ ∈→∷≡ (x∷z⊆y x (Trunc.∣inj₁∣ (refl _))) ⟩∎
y ∎
e .is-propositionʳ _ =
Π-closure ext 1 λ _ →
is-set
-- _⊆_ is a partial order.
⊆-refl : x ⊆ x
⊆-refl _ = id
⊆-trans : x ⊆ y → y ⊆ z → x ⊆ z
⊆-trans x⊆y y⊆z _ = y⊆z _ ∘ x⊆y _
⊆-antisymmetric : x ⊆ y → y ⊆ x → x ≡ y
⊆-antisymmetric x⊆y y⊆x =
extensionality λ z →
record { to = x⊆y z; from = y⊆x z }
------------------------------------------------------------------------
-- Another lemma
-- Equality can be expressed using _⊆_.
≡≃⊆×⊇ : (x ≡ y) ≃ (x ⊆ y × y ⊆ x)
≡≃⊆×⊇ {x = x} {y = y} =
x ≡ y ↝⟨ Eq.⇔→≃
is-set
(×-closure 1 is-set is-set)
(λ x≡y →
(x ∪ y ≡⟨ cong (_∪ _) x≡y ⟩
y ∪ y ≡⟨ ∪-idem y ⟩∎
y ∎)
, (y ∪ x ≡⟨ cong (_∪ _) $ sym x≡y ⟩
x ∪ x ≡⟨ ∪-idem x ⟩∎
x ∎))
(λ (p , q) →
x ≡⟨ sym q ⟩
y ∪ x ≡⟨ ∪-comm y ⟩
x ∪ y ≡⟨ p ⟩∎
y ∎) ⟩
x ∪ y ≡ y × y ∪ x ≡ x ↝⟨ inverse $ ⊆≃∪≡ x ×-cong ⊆≃∪≡ y ⟩□
x ⊆ y × y ⊆ x □
-- Extensional equality is equivalent to equality.
∼≃≡ : (x ∼ y) ≃ (x ≡ y)
∼≃≡ {x = x} {y = y} =
x ∼ y ↔⟨⟩
(∀ z → z ∈ x ⇔ z ∈ y) ↔⟨ (∀-cong ext λ _ → ⇔↔→×→) ⟩
(∀ z → (z ∈ x → z ∈ y) × (z ∈ y → z ∈ x)) ↔⟨ ΠΣ-comm ⟩
x ⊆ y × y ⊆ x ↝⟨ inverse ≡≃⊆×⊇ ⟩□
x ≡ y □
------------------------------------------------------------------------
-- Definitions related to the listed finite subsets defined in Listed
-- Some lemmas used below.
private
module Listed≃Listed where
-- Converts one kind of finite subset to another.
from : Listed.Finite-subset-of A → Finite-subset-of A
from = Listed.rec r
where
r : Listed.Rec _ _
r .Listed.Rec.[]ʳ = []
r .Listed.Rec.∷ʳ x _ y = x ∷ y
r .Listed.Rec.dropʳ _ _ _ = drop
r .Listed.Rec.swapʳ _ _ _ _ = swap
r .Listed.Rec.is-setʳ = is-set
-- A lemma relating from, _∈_ and Listed._∈_.
∈from≃ : ∀ x → (z ∈ from x) ≃ (z Listed.∈ x)
∈from≃ {z = z} = Listed.elim-prop e
where
e : Listed.Elim-prop _
e .Listed.Elim-prop.[]ʳ =
z ∈ from Listed.[] ↔⟨⟩
⊥ ↔⟨ ⊥↔⊥ ⟩
⊥₀ ↝⟨ inverse $ Listed.∈[]≃ ⟩
z Listed.∈ Listed.[] □
e .Listed.Elim-prop.∷ʳ {y = y} x hyp =
z ∈ from (x Listed.∷ y) ↔⟨⟩
z ≡ x ∥⊎∥ z ∈ from y ↝⟨ F.id Trunc.∥⊎∥-cong hyp ⟩
z ≡ x ∥⊎∥ z Listed.∈ y ↝⟨ inverse Listed.∈∷≃ ⟩□
z Listed.∈ x Listed.∷ y □
e .Listed.Elim-prop.is-propositionʳ _ =
Eq.right-closure ext 0 Listed.∈-propositional
-- A lemma relating from, _⊆_ and Listed._⊆_.
from⊆from→ :
(x y : Listed.Finite-subset-of A) →
from x ⊆ from y → x Listed.⊆ y
from⊆from→ = Listed.elim-prop e
where
e : Listed.Elim-prop _
e .Listed.Elim-prop.[]ʳ = Listed.elim-prop e′
where
e′ : Listed.Elim-prop _
e′ .Listed.Elim-prop.[]ʳ _ = Listed.⊆-refl
e′ .Listed.Elim-prop.∷ʳ {y = y} x _ _ z =
z Listed.∈ Listed.[] ↔⟨ Listed.∈[]≃ ⟩
⊥₀ ↝⟨ ⊥-elim ⟩□
z Listed.∈ x Listed.∷ y □
e′ .Listed.Elim-prop.is-propositionʳ _ =
Π-closure ext 1 λ _ →
Listed.⊆-propositional
e .Listed.Elim-prop.∷ʳ {y = y₁} x hyp₁ y₂ =
from (x Listed.∷ y₁) ⊆ from y₂ ↔⟨⟩
(∀ z → z ≡ x ∥⊎∥ z ∈ from y₁ → z ∈ from y₂) ↝⟨ (λ hyp₂ z → Trunc.rec Listed.∈-propositional
[ (
z ≡ x ↝⟨ Trunc.∣inj₁∣ ⟩
z ≡ x ∥⊎∥ z ∈ from y₁ ↝⟨ hyp₂ z ⟩
z ∈ from y₂ ↔⟨ ∈from≃ _ ⟩□
z Listed.∈ y₂ □)
, ($⟨ (λ z → hyp₂ z ∘ Trunc.∣inj₂∣) ⟩
from y₁ ⊆ from y₂ ↝⟨ hyp₁ y₂ ⟩
y₁ Listed.⊆ y₂ ↝⟨ _$ z ⟩□
(z Listed.∈ y₁ → z Listed.∈ y₂) □)
]) ⟩
(∀ z → z ≡ x ∥⊎∥ z Listed.∈ y₁ → z Listed.∈ y₂) ↔⟨ (∀-cong ext λ _ → →-cong ext (inverse Listed.∈∷≃) F.id) ⟩□
x Listed.∷ y₁ Listed.⊆ y₂ □
e .Listed.Elim-prop.is-propositionʳ _ =
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Listed.⊆-propositional
-- The function from is injective.
from-injective : Injective (from {A = A})
from-injective {x = x} {y = y} =
from x ≡ from y ↔⟨ ≡≃⊆×⊇ ⟩
from x ⊆ from y × from y ⊆ from x ↝⟨ Σ-map (from⊆from→ _ _) (from⊆from→ _ _) ⟩
x Listed.⊆ y × y Listed.⊆ x ↝⟨ uncurry Listed.⊆-antisymmetric ⟩□
x ≡ y □
-- Converts one kind of finite subset to another, and returns a
-- partial correctness result.
to :
(x : Finite-subset-of A) →
∃ λ (y : Listed.Finite-subset-of A) → from y ≡ x
to = elim e
where
e : Elim _
e .Elim.[]ʳ = Listed.[] , refl _
e .Elim.∷ʳ x (y , eq) = x Listed.∷ y , cong (x ∷_) eq
e .Elim.is-propositionʳ x (y₁ , eq₁) (y₂ , eq₂) =
Σ-≡,≡→≡
(from-injective
(from y₁ ≡⟨ eq₁ ⟩
x ≡⟨ sym eq₂ ⟩∎
from y₂ ∎))
(is-set _ _)
-- Another correctness result.
to-from :
(x : Listed.Finite-subset-of A) →
proj₁ (to (from x)) ≡ x
to-from = Listed.elim-prop e
where
e : Listed.Elim-prop _
e .Listed.Elim-prop.[]ʳ = refl _
e .Listed.Elim-prop.∷ʳ x = cong (x Listed.∷_)
e .Listed.Elim-prop.is-propositionʳ _ = Listed.is-set
-- The type of listed finite subsets defined above is pointwise
-- equivalent to the type of listed finite subsets defined in Listed.
Listed≃Listed : Finite-subset-of A ≃ Listed.Finite-subset-of A
Listed≃Listed = Eq.↔→≃ (proj₁ ∘ to) from to-from (proj₂ ∘ to)
where
open Listed≃Listed
-- The equivalence preserves membership.
∈≃∈ : ∀ y → (x ∈ y) ≃ (x Listed.∈ _≃_.to Listed≃Listed y)
∈≃∈ {x = x} y =
x ∈ y ↝⟨ ≡⇒↝ _ $ cong (_ ∈_) $ sym $ _≃_.left-inverse-of Listed≃Listed y ⟩
x ∈ _≃_.from Listed≃Listed (_≃_.to Listed≃Listed y) ↝⟨ ∈from≃ _ ⟩□
x Listed.∈ _≃_.to Listed≃Listed y □
where
open Listed≃Listed
-- Another dependent eliminator (expressed using equality).
--
-- Note that the motive is not required to be propositional.
record Elim′ {A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
[]ʳ : P []
∷ʳ : ∀ x → P y → P (x ∷ y)
dropʳ : ∀ x (p : P y) →
subst P (drop {x = x} {y = y}) (∷ʳ x (∷ʳ x p)) ≡ ∷ʳ x p
swapʳ : ∀ x y (p : P z) →
subst P (swap {x = x} {y = y} {z = z}) (∷ʳ x (∷ʳ y p)) ≡
∷ʳ y (∷ʳ x p)
is-setʳ : ∀ x → Is-set (P x)
open Elim′ public
elim′ : Elim′ P → (x : Finite-subset-of A) → P x
elim′ {P = P} e x =
subst P (_≃_.left-inverse-of Listed≃Listed x)
(Listed.elim e′ (_≃_.to Listed≃Listed x))
where
module E = Elim′ e
e′ : Listed.Elim (P ∘ _≃_.from Listed≃Listed)
e′ .Listed.[]ʳ = E.[]ʳ
e′ .Listed.∷ʳ = E.∷ʳ
e′ .Listed.dropʳ x p =
subst (P ∘ _≃_.from Listed≃Listed)
Listed.drop
(e .∷ʳ x (e .∷ʳ x p)) ≡⟨ subst-∘ _ _ _ ⟩
subst P
(cong (_≃_.from Listed≃Listed) Listed.drop)
(e .∷ʳ x (e .∷ʳ x p)) ≡⟨ cong (flip (subst P) _) $ is-set _ _ ⟩
subst P drop (e .∷ʳ x (e .∷ʳ x p)) ≡⟨ e .dropʳ x p ⟩∎
e .∷ʳ x p ∎
e′ .Listed.swapʳ x y p =
subst (P ∘ _≃_.from Listed≃Listed)
Listed.swap
(e .∷ʳ x (e .∷ʳ y p)) ≡⟨ subst-∘ _ _ _ ⟩
subst P
(cong (_≃_.from Listed≃Listed) Listed.swap)
(e .∷ʳ x (e .∷ʳ y p)) ≡⟨ cong (flip (subst P) _) $ is-set _ _ ⟩
subst P swap (e .∷ʳ x (e .∷ʳ y p)) ≡⟨ e .swapʳ x y p ⟩∎
e .∷ʳ y (e .∷ʳ x p) ∎
e′ .Listed.is-setʳ _ = E.is-setʳ _
|
{
"alphanum_fraction": 0.4465430273,
"avg_line_length": 29.726042841,
"ext": "agda",
"hexsha": "d20f94f0c5db3763a4a4114d08cbb85399c4c982",
"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/Finite-subset/Listed/Alternative.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/Finite-subset/Listed/Alternative.agda",
"max_line_length": 123,
"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/Finite-subset/Listed/Alternative.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": 10798,
"size": 26367
}
|
------------------------------------------------------------------------------
-- Properties for the nest function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.Nest.PropertiesATP where
open import FOTC.Base
open import FOTC.Data.Nat.Type
open import FOTC.Program.Nest.Nest
------------------------------------------------------------------------------
nest-x≡0 : ∀ {n} → N n → nest n ≡ zero
nest-x≡0 nzero = prf
where postulate prf : nest zero ≡ zero
{-# ATP prove prf #-}
nest-x≡0 (nsucc {n} Nn) = prf (nest-x≡0 Nn)
where postulate prf : nest n ≡ zero → nest (succ₁ n) ≡ zero
{-# ATP prove prf #-}
postulate nest-N : ∀ {n} → N n → N (nest n)
{-# ATP prove nest-N nest-x≡0 #-}
|
{
"alphanum_fraction": 0.4402583423,
"avg_line_length": 33.1785714286,
"ext": "agda",
"hexsha": "bdf8aa6bfbe5f53d357ade35051987be14ebd929",
"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/Nest/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/Nest/PropertiesATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/Nest/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": 223,
"size": 929
}
|
module README where
import Semantics
import Theory
import Soundness
import Categories.Category.Construction.Models
import Categories.Category.Construction.Classifying
import Categories.Functor.Construction.Inclusion
import Internal
import Examples
|
{
"alphanum_fraction": 0.873015873,
"avg_line_length": 18,
"ext": "agda",
"hexsha": "2b2de66b28a908de263e69c1d3ff7e168fc3ce90",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "elpinal/exsub-ccc",
"max_forks_repo_path": "README.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "elpinal/exsub-ccc",
"max_issues_repo_path": "README.agda",
"max_line_length": 51,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "elpinal/exsub-ccc",
"max_stars_repo_path": "README.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T13:30:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-05T06:16:32.000Z",
"num_tokens": 46,
"size": 252
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
open import LibraBFT.Concrete.Records
open import LibraBFT.Concrete.System
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.Impl.Consensus.Network as Network
open import LibraBFT.Impl.Consensus.Network.Properties as NetworkProps
open import LibraBFT.Impl.Consensus.RoundManager as RoundManager
open import LibraBFT.Impl.Consensus.RoundManager.Properties
open import LibraBFT.Impl.IO.OBM.InputOutputHandlers
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.Impl.Properties.Util
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Interface.Output
open import LibraBFT.ImplShared.NetworkMsg
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.Prelude
open import Yasm.System ℓ-RoundManager ℓ-VSFP ConcSysParms
open Invariants
open RoundManagerTransProps
module LibraBFT.Impl.IO.OBM.Properties.InputOutputHandlers where
module epvvSpec where
contract
: ∀ pre Post
→ let ep = pre ^∙ pssSafetyData-rm ∙ sdEpoch
vv = pre ^∙ rmEpochState ∙ esVerifier in
(Post (ep , vv) pre [])
→ LBFT-weakestPre epvv Post pre
contract pre Post pf ._ refl ._ refl ._ refl ._ refl = pf
module handleProposalSpec (now : Instant) (pm : ProposalMsg) where
open handleProposal now pm
module _ (pool : SentMessages) (pre : RoundManager) where
open Invariants.Reqs (pm ^∙ pmProposal) (pre ^∙ lBlockTree)
record Contract (_ : Unit) (post : RoundManager) (outs : List Output) : Set where
constructor mkContract
field
-- General properties / invariants
rmInv : Preserves RoundManagerInv pre post
invalidProposal : ¬ (BlockId-correct (pm ^∙ pmProposal)) → pre ≡ post × OutputProps.NoVotes outs
noEpochChange : NoEpochChange pre post
-- Voting
voteAttemptCorrect : BlockId-correct (pm ^∙ pmProposal)
→ NoHC1 → Voting.VoteAttemptCorrectWithEpochReq pre post outs (pm ^∙ pmProposal)
-- voteBuildsOnRC : TODO-2: We will need to know that, if we're sending a Vote, then there
-- is a Block b such that the Vote's proposed id is bId B and there
-- is a RecordChain (B b) and all the Records in that RecordChain
-- are InSys. This is needed to prove ImplObligation-RC. However,
-- before doing so, it may be worth considering strengthening the
-- Concrete PreferredRound proof, so that only IsValidVote is
-- required of the implementation, and that is used to construct
-- the required RecordChain, independently of the implementation.
-- QCs
outQcs∈RM : QCProps.OutputQc∈RoundManager outs post
qcPost : QCProps.∈Post⇒∈PreOr (_QC∈NM (P pm)) pre post
contract : LBFT-weakestPre (handleProposal now pm) Contract pre
contract =
epvvSpec.contract pre Post-epvv contract-step₁
where
Post-epvv : LBFT-Post (Epoch × ValidatorVerifier)
Post-epvv = RWS-weakestPre-bindPost unit (λ where (myEpoch , vv) → step₁ myEpoch vv) Contract
myEpoch = pre ^∙ pssSafetyData-rm ∙ sdEpoch
vv = pre ^∙ rmEpochState ∙ esVerifier
contractBail : ∀ outs → OutputProps.NoMsgs outs → Contract unit pre outs
contractBail outs noMsgs =
mkContract reflPreservesRoundManagerInv (const $ refl , OutputProps.NoMsgs⇒NoVotes outs noMsgs) (reflNoEpochChange{pre})
vac outQcs∈RM qcPost
where
vac : BlockId-correct (pm ^∙ pmProposal) → NoHC1 → Voting.VoteAttemptCorrectWithEpochReq pre pre outs (pm ^∙ pmProposal)
vac _ _ = Voting.mkVoteAttemptCorrectWithEpochReq
(Voting.voteAttemptBailed outs (OutputProps.NoMsgs⇒NoVotes outs noMsgs)) tt
outQcs∈RM : QCProps.OutputQc∈RoundManager outs pre
outQcs∈RM = QCProps.NoMsgs⇒OutputQc∈RoundManager outs pre noMsgs
qcPost : QCProps.∈Post⇒∈PreOr _ pre pre
qcPost qc = Left
contract-step₁ : Post-epvv (myEpoch , vv) pre []
proj₁ (contract-step₁ (myEpoch@._ , vv@._) refl) (inj₁ e) pp≡Left =
contractBail _ refl
proj₁ (contract-step₁ (myEpoch@._ , vv@._) refl) (inj₂ i) pp≡Left =
contractBail _ refl
proj₂ (contract-step₁ (myEpoch@._ , vv@._) refl) unit pp≡Right =
processProposalMsgMSpec.contract now pm proposalId≡ pre Contract pf
where
sdEpoch≡ : pre ^∙ pssSafetyData-rm ∙ sdEpoch ≡ pm ^∙ pmProposal ∙ bEpoch
sdEpoch≡
with processProposalSpec.contract pm myEpoch vv
...| con rewrite pp≡Right = sym (proj₁ con)
proposalId≡ : BlockId-correct (pm ^∙ pmProposal)
proposalId≡
with processProposalSpec.contract pm myEpoch vv
...| con rewrite pp≡Right = proj₂ con
module PPM = processProposalMsgMSpec now pm proposalId≡
pf : RWS-Post-⇒ (PPM.Contract pre) Contract
pf unit st outs con =
mkContract PPMSpec.rmInv (λ x → ⊥-elim (x proposalId≡)) PPMSpec.noEpochChange
vac PPMSpec.outQcs∈RM PPMSpec.qcPost
where
module PPMSpec = processProposalMsgMSpec.Contract con
vac : BlockId-correct (pm ^∙ pmProposal) → NoHC1
→ Voting.VoteAttemptCorrectWithEpochReq pre st outs (pm ^∙ pmProposal)
vac _ nohc = Voting.mkVoteAttemptCorrectWithEpochReq (PPMSpec.voteAttemptCorrect nohc)
(Voting.voteAttemptEpochReq! (PPMSpec.voteAttemptCorrect nohc) sdEpoch≡)
contract! : LBFT-Post-True Contract (handleProposal now pm) pre
contract! = LBFT-contract (handleProposal now pm) Contract pre contract
module handleVoteSpec (now : Instant) (vm : VoteMsg) where
open handleVote now vm
module _ (pool : SentMessages) (pre : RoundManager) where
record Contract (_ : Unit) (post : RoundManager) (outs : List Output) : Set where
constructor mkContract
field
-- General properties / invariants
rmInv : Preserves RoundManagerInv pre post
noEpochChange : NoEpochChange pre post
noSDChange : NoSafetyDataChange pre post
-- Output
noVotes : OutputProps.NoVotes outs
-- Signatures
outQcs∈RM : QCProps.OutputQc∈RoundManager outs post
qcPost : QCProps.∈Post⇒∈PreOr (_QC∈NM (V vm)) pre post
-- TODO-2: `handleVote` can create a new QC once it receives enough
-- votes. We need to be tracking /votes/ here, not QCs
postulate -- TODO-2: prove (waiting on: refinement of `Contract`)
contract : LBFT-weakestPre (handleVote now vm) Contract pre
contract! : LBFT-Post-True Contract (handleVote now vm) pre
contract! = LBFT-contract (handleVote now vm) Contract pre contract
|
{
"alphanum_fraction": 0.6711363008,
"avg_line_length": 45.7848101266,
"ext": "agda",
"hexsha": "c78b306ed1883b37dfd5ffa6ceed128819aa1243",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/IO/OBM/Properties/InputOutputHandlers.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/IO/OBM/Properties/InputOutputHandlers.agda",
"max_line_length": 128,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/IO/OBM/Properties/InputOutputHandlers.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1965,
"size": 7234
}
|
{-
Copyright 2019 Lisandra Silva
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}
open import Prelude
open import Data.Nat.Divisibility
open import StateMachineModel
{-
This State Machine begins in a state equal to 0 or 1 and if :
- The current state s is Even then jump to state (s + 2)
- The current state is Odd jump to state (s + 1)
We want to prove that a state s always leads-to a state Even
-}
module Examples.SMCounterEven where
-- DEFINITIONS and proofs about Even and Odd
Even : ℕ → Set
Even n = 2 ∣ n
Odd : ℕ → Set
Odd = ¬_ ∘ Even
even? : (n : ℕ) → Dec (Even n)
even? n = 2 ∣? n
evenK⇒even2+K : ∀ {k} → Even k → Even (2 + k)
evenK⇒even2+K (divides q₁ refl) = divides (1 + q₁) refl
-- The following are mutually recursive properties.
oddK⇒even1+K : ∀ {k} → Odd k → Even (suc k)
oddK⇒evenK-1 : ∀ {k} → Odd k → Even (pred k)
oddK⇒even1+K {zero} x = ⊥-elim (x (divides 0 refl))
oddK⇒even1+K {suc k} x = evenK⇒even2+K (oddK⇒evenK-1 x)
oddK⇒evenK-1 {zero} x = ⊥-elim (x (divides 0 refl))
oddK⇒evenK-1 {suc k} x with even? k
...| no imp = ⊥-elim (x (oddK⇒even1+K imp))
...| yes prf = prf
odd1 : Odd 1
odd1 (divides zero ())
odd1 (divides (suc q₁) ())
-----------------------------------------------------------------------------
-- SPECIFICATION
-----------------------------------------------------------------------------
data MyEvent : Set where
inc : MyEvent
inc2 : MyEvent
-- TODO : Try with an event iddle that doesn't do anything and is in another
-- EventSet in the weakFairness relation (just to try)
-- If we are in a state that is odd then the enabled event is inc
-- otherwise the enabled event is inc2
data MyEnabled : MyEvent → ℕ → Set where
odd : ∀ {n} → Odd n → MyEnabled inc n
even : ∀ {n} → Even n → MyEnabled inc2 n
MyStateMachine : StateMachine ℕ MyEvent
MyStateMachine = record
{ initial = (0 ≡_) ∪ (1 ≡_)
; enabled = MyEnabled
; action = λ { {pre} {inc} cond → 1 + pre
; {pre} {inc2} cond → 2 + pre }
}
MyEventSet : EventSet {Event = MyEvent}
MyEventSet inc = ⊤
MyEventSet inc2 = ⊤
data MyWeakFairness : EventSet → Set where
wf : MyWeakFairness MyEventSet
MySystem : System ℕ MyEvent
MySystem = record
{ stateMachine = MyStateMachine
; weakFairness = MyWeakFairness
}
-----------------------------------------------------------------------------
-- PROOFS
-----------------------------------------------------------------------------
open LeadsTo ℕ MyEvent MySystem
-- In every state there is always an enabled transition
alwaysEnabled : ∀ (s : ℕ) → enabledSet MyStateMachine MyEventSet s
alwaysEnabled s with even? s
... | yes p = inc2 , tt , even p
... | no ¬p = inc , tt , odd ¬p
-- Any state n leads to an Even state
progressEven : ∀ {n : ℕ} → (n ≡_) l-t Even
progressEven = viaEvSet
MyEventSet wf
(λ { inc ⊤ → hoare λ { refl (odd x) → oddK⇒even1+K x }
; inc2 ⊤ → hoare λ { refl (even x) → evenK⇒even2+K x } })
(λ { inc ⊥ → ⊥-elim (⊥ tt)
; inc2 ⊥ → ⊥-elim (⊥ tt) })
λ {s} rs n≡s → alwaysEnabled s
-- QUESTION : Although we don't have weakfairness (WF) on event inc it was
-- possible to prove this.
-- ANSWER : This is because of the 2nd constraint in the viaEvSet constructor:
-- - ∀ event e ∉ WF (in this case only inc) → [P] e [P ∪ Q], in this case
-- we achieve Q (Even), because the event inc is enabled only in Odd states.
-- REFACTOR: Maybe m is the one that should be explicit
myWFR : ∀ {m} → ℕ → Z → Set
myWFR {m} d s = m ≡ d + s
-- For every m and even state s, or s is greater than m or there is a distance
-- x between s and m
[Q∪Fx] : ∀ {m} → (s : Z) → Even s
→ (m ≤ s × Even s) ⊎ ∃[ x ] myWFR {m} x s
[Q∪Fx] {m} s sEven with m ≤? s
... | yes m≤s = inj₁ (m≤s , sEven)
... | no s<m = inj₂ ( m ∸ s , sym (m∸n+n≡m (<⇒≤ (≰⇒> s<m))) )
-- First constraint for WFR rule
[P]l-t[Q∪Fx] : ∀ {n m}
→ (n ≡_) l-t ( ((m ≤_) ∩ Even) ∪ [∃ x ∶ myWFR {m} x ] )
[P]l-t[Q∪Fx] {n} {m} = viaEvSet
MyEventSet wf
(λ { inc ⊤
→ hoare λ { refl (odd x)
→ [Q∪Fx] (1 + n) (oddK⇒even1+K x) }
; inc2 ⊤
→ hoare λ { refl (even x)
→ [Q∪Fx] (2 + n) (evenK⇒even2+K x) }})
(λ { inc ⊥ → ⊥-elim (⊥ tt)
; inc2 ⊥ → ⊥-elim (⊥ tt) })
λ {s} rs n≡s → alwaysEnabled s
-- If we are at distance 0 from m, which means state s ≡ m, then it leads-to a
-- state s₁ > m ∩ Even s₁, because or we increment 1 if s is odd or we
-- increment 2 if s is even.
d≡0⇒Q : ∀ {m}
→ myWFR {m} 0
l-t
( (m ≤_) ∩ Even )
d≡0⇒Q {m} = viaEvSet
MyEventSet wf
(λ { inc ⊤
→ hoare λ { refl (odd x)
→ m≤n+m m 1 , oddK⇒even1+K x }
; inc2 ⊤
→ hoare λ { refl (even x)
→ m≤n+m m 2 , evenK⇒even2+K x }})
(λ { inc ⊥ → ⊥-elim (⊥ tt)
; inc2 ⊥ → ⊥-elim (⊥ tt) })
λ {s} rs F0 → alwaysEnabled s
-- If we are at distance 1 from m, which means m ≡ s + 1.
-- If s is odd then s is incremented by 1 (because of the enabling
-- condition) then we go to an even state s₁ ≡ s + 1 ≡ m.
-- If if s is even then s is incremented by 2, which leads to a state
-- s₁ ≡ s + 2 > s + 1 ≡ m. As so, m ≤ s₁ ∩ Even s₁ will always hold.
d≡1⇒Q∪d≡0 : ∀ {m}
→ myWFR {m} 1
l-t
( ((m ≤_) ∩ Even) ∪ [∃ x ⇒ _< 1 ∶ myWFR {m} x ] )
d≡1⇒Q∪d≡0 {m} = viaEvSet
MyEventSet wf
(λ { inc ⊤
→ hoare λ { {ps} refl (odd x)
→ inj₁ (≤-refl , oddK⇒even1+K x) }
; inc2 ⊤
→ hoare λ { {ps} refl (even x)
→ inj₁ (m≤n+m (suc ps) 1 , evenK⇒even2+K x) }})
(λ { inc ⊥ → ⊥-elim (⊥ tt)
; inc2 ⊥ → ⊥-elim (⊥ tt) })
λ {s} rs F1 → alwaysEnabled s
-- Auxiliary properties
assoc∘comm : ∀ {w s : ℕ} n → n + w + s ≡ w + (n + s)
assoc∘comm {w} {s} n = trans (cong (_+ s) (+-comm n w)) (+-assoc w n s)
assoc∘assoc : ∀ {w s : ℕ} n p → (n + p) + w + s ≡ n + w + (p + s)
assoc∘assoc {w} {s} n p
rewrite +-assoc n p w
| +-comm p w
| +-assoc n (w + p) s
| +-assoc w p s
| +-assoc n w (p + s) = refl
-- If we are at a distance greater o equal to 2 then with we decrease the
-- distance in 1 or 2, because we can jump 1 or 2 states (inc or onc2)
-- This property together with d≡0⇒Q and d≡1⇒Q∪d≡0 allows to prove the
-- second constraint for the WFR rule (see below)
[d≡2+w]⇒[d≡1+w]∪[d≡w] : ∀ {m w}
→ myWFR {m} (2 + w)
l-t
( myWFR {m} (1 + w) ∪ myWFR {m} w )
[d≡2+w]⇒[d≡1+w]∪[d≡w] {m} {w} =
viaEvSet
MyEventSet wf
(λ { inc ⊤
→ hoare λ { {ps} refl (odd x) → inj₁ (assoc∘assoc 1 1) }
; inc2 ⊤
→ hoare λ { {ps} refl enEv → inj₂ (assoc∘comm 2) }})
(λ { inc ⊥ → ⊥-elim (⊥ tt)
; inc2 ⊥ → ⊥-elim (⊥ tt) })
λ {s} rs F2+d → alwaysEnabled s
-- Second constraint for WFR rule
[Fw]l-t[Q∪Fx] : ∀ {m w}
→ myWFR {m} w
l-t
( ((m ≤_) ∩ Even) ∪ [∃ x ⇒ _< w ∶ myWFR {m} x ] )
[Fw]l-t[Q∪Fx] {m} {zero} = viaTrans d≡0⇒Q (viaInv (λ rs x → inj₁ x))
[Fw]l-t[Q∪Fx] {m} {suc zero} = d≡1⇒Q∪d≡0
[Fw]l-t[Q∪Fx] {m} {suc (suc w)} =
viaTrans
[d≡2+w]⇒[d≡1+w]∪[d≡w]
(viaInv (λ { rs (inj₁ mfr[1+w]) → inj₂ ( 1 + w , s≤s ≤-refl , mfr[1+w] )
; rs (inj₂ mfr[w]) → inj₂ ( w , s≤s (m≤n+m w 1) , mfr[w]) }))
------------------------------------------------------------------------------
-- MAIN PROPERTY
------------------------------------------------------------------------------
-- From any n, we can reach any state m such that m is Even
progressAlwaysEven : ∀ {n m : ℕ} → (n ≡_) l-t ((m ≤_) ∩ Even)
progressAlwaysEven {n} {m} = viaWFR
(myWFR {m})
[P]l-t[Q∪Fx]
λ w → [Fw]l-t[Q∪Fx]
|
{
"alphanum_fraction": 0.4575114618,
"avg_line_length": 34.9962686567,
"ext": "agda",
"hexsha": "8a62537dffb4e9edb9422364ad45dff4c3099a6c",
"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": "391e148f391dc2d246249193788a0d203285b38e",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "lisandrasilva/agda-liveness",
"max_forks_repo_path": "src/Examples/SMCounterEven.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "391e148f391dc2d246249193788a0d203285b38e",
"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": "lisandrasilva/agda-liveness",
"max_issues_repo_path": "src/Examples/SMCounterEven.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "391e148f391dc2d246249193788a0d203285b38e",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "lisandrasilva/agda-liveness",
"max_stars_repo_path": "src/Examples/SMCounterEven.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3215,
"size": 9379
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Instance.0-Truncation where
-- 0-trucation of groupoids as a functor from Groupoids to Setoids.
--
-- This is the right-adjoint of the inclusion functor from Setoids to
-- Groupoids (see Categories.Functor.Adjoint.Instance.ZeroTruncation)
import Function
open import Function.Equality using (_⟶_)
open import Relation.Binary using (Setoid)
open import Categories.Category using (Category; _[_≈_])
open import Categories.Functor hiding (id)
open import Categories.Category.Groupoid using (Groupoid)
open import Categories.Category.Instance.Groupoids using (Groupoids)
open import Categories.Category.Instance.Setoids using (Setoids)
open import Categories.NaturalTransformation.NaturalIsomorphism
using (NaturalIsomorphism; _≃_)
Trunc : ∀ {o ℓ e} → Functor (Groupoids o ℓ e) (Setoids o ℓ)
Trunc {o} {ℓ} {e} = record
{ F₀ = TruncSetoid
; F₁ = λ {G H} F → TruncMap {G} {H} F
; identity = Function.id
; homomorphism = λ {_ _ _ F G} f → F₁ G (F₁ F f)
; F-resp-≈ = λ {G H} → TruncRespNI {G} {H}
}
where
open Groupoid using (category)
open Functor
TruncSetoid : Groupoid o ℓ e → Setoid o ℓ
TruncSetoid G = record
{ Carrier = Obj
; _≈_ = _⇒_
; isEquivalence = record
{ refl = id
; sym = _⁻¹
; trans = λ f g → g ∘ f
}
}
where open Groupoid G
TruncMap : ∀ {G H} → Functor (category G) (category H) →
TruncSetoid G ⟶ TruncSetoid H
TruncMap F = record { _⟨$⟩_ = F₀ F ; cong = F₁ F }
TruncRespNI : ∀ {G H : Groupoid o ℓ e}
{E F : Functor (category G) (category H)} →
E ≃ F → Setoids o ℓ [ TruncMap {G} {H} E ≈ TruncMap {G} {H} F ]
TruncRespNI {_} {H} {_} {F} μ {a} f = F₁ F f ∘ ⇒.η a
where
open Groupoid H
open NaturalIsomorphism μ
|
{
"alphanum_fraction": 0.6059517701,
"avg_line_length": 34.1929824561,
"ext": "agda",
"hexsha": "d7f7554a221a5bab13e12470f09c02c7bed435b9",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Functor/Instance/0-Truncation.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Functor/Instance/0-Truncation.agda",
"max_line_length": 82,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Functor/Instance/0-Truncation.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 610,
"size": 1949
}
|
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl)
open import Relation.Nullary.Decidable using (False; toWitnessFalse)
open import Data.Fin using (Fin; _≟_)
open import Data.Nat using (ℕ; suc)
open import Data.Product using (_×_; _,_)
open import Common
data Global (n : ℕ) : Set where
endG : Global n
msgSingle : (p q : Fin n) -> p ≢ q -> Label -> Global n -> Global n
private
variable
n : ℕ
p p′ q q′ r s : Fin n
l l′ : Label
g gSub gSub′ : Global n
msgSingle′ : (p q : Fin n) -> {False (p ≟ q)} -> Label -> Global n -> Global n
msgSingle′ p q {p≢q} l gSub = msgSingle p q (toWitnessFalse p≢q) l gSub
size-g : ∀ { n : ℕ } -> (g : Global n) -> ℕ
size-g endG = 0
size-g (msgSingle _ _ _ _ gSub) = suc (size-g gSub)
size-g-reduces :
∀ { p≢q }
-> g ≡ msgSingle {n} p q p≢q l gSub
-> size-g g ≡ suc (size-g gSub)
size-g-reduces {g = endG} ()
size-g-reduces {g = msgSingle _ _ _ _ gSub} refl = refl
msgSingle-subst-left :
∀ { p≢q }
-> g ≡ msgSingle {n} p q p≢q l gSub
-> (p≡p′ : p ≡ p′)
-> g ≡ msgSingle {n} p′ q (≢-subst-left p≢q p≡p′) l gSub
msgSingle-subst-left refl refl = refl
msgSingle-subst-right :
∀ { p≢q }
-> g ≡ msgSingle {n} p q p≢q l gSub
-> (q≡q′ : q ≡ q′)
-> g ≡ msgSingle {n} p q′ (≢-subst-right p≢q q≡q′) l gSub
msgSingle-subst-right refl refl = refl
msgSingle-injective :
∀ { p≢q p′≢q′ }
-> msgSingle {n} p q p≢q l gSub ≡ msgSingle p′ q′ p′≢q′ l′ gSub′
-> p ≡ p′ × q ≡ q′ × l ≡ l′ × gSub ≡ gSub′
msgSingle-injective refl = refl , refl , refl , refl
data _-_→g_ {n : ℕ} : Global n -> Action n -> Global n -> Set where
→g-prefix :
∀ { p≢q p≢q′ }
-> (msgSingle p q p≢q l gSub) - (action p q p≢q′ l) →g gSub
→g-cont :
∀ { p≢q r≢s }
-> gSub - (action p q p≢q l) →g gSub′
-> p ≢ r
-> q ≢ r
-> p ≢ s
-> q ≢ s
-> (msgSingle r s r≢s l′ gSub) - (action p q p≢q l) →g (msgSingle r s r≢s l′ gSub′)
|
{
"alphanum_fraction": 0.5631825273,
"avg_line_length": 29.1363636364,
"ext": "agda",
"hexsha": "90e5b93b79d30e94cf42808b65b801e073370704",
"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": "3d12eed9d340207d242d70f43c6b34e01d3620de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "fangyi-zhou/mpst-in-agda",
"max_forks_repo_path": "Global.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "3d12eed9d340207d242d70f43c6b34e01d3620de",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T11:30:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-08-31T10:15:38.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "fangyi-zhou/mpst-in-agda",
"max_issues_repo_path": "Global.agda",
"max_line_length": 87,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "3d12eed9d340207d242d70f43c6b34e01d3620de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "fangyi-zhou/mpst-in-agda",
"max_stars_repo_path": "Global.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-14T17:36:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-14T17:36:53.000Z",
"num_tokens": 815,
"size": 1923
}
|
-- Andreas, 2012-04-21
-- {-# OPTIONS -v tc.proj.like:100 -v tc.with:100 #-}
module ReifyProjectionLike where
data Maybe (A : Set) : Set where
just : A → Maybe A
fromJust : (A : Set) → Maybe A → A
fromJust A (just a) = a
data Sing (A : Set) : A -> Set where
sing : (a : A) -> Sing A a
succeed : (A : Set) -> Maybe A -> Set
succeed A m with sing (fromJust A m)
... | _ = A
fail : (A : Set) -> Maybe A -> Set
fail A m with sing (fromJust A m)
... | (just x) = x
-- error message is wrong:
--
-- just is not a constructor of the datatype Sing
-- when checking that the pattern just x has type Sing A (fromJust m)
--
-- the "A" got dropped from "fromJust"
--
-- correct message is
--
-- just is not a constructor of the datatype Sing
-- when checking that the pattern just x has type Sing A (fromJust A m)
|
{
"alphanum_fraction": 0.6233292831,
"avg_line_length": 24.9393939394,
"ext": "agda",
"hexsha": "69bbe98326e56ceea1ce7fb385fc2b969686fc63",
"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/ReifyProjectionLike.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/ReifyProjectionLike.agda",
"max_line_length": 73,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/ReifyProjectionLike.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": 259,
"size": 823
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category using (Category; module Commutation)
open import Categories.Category.Monoidal
open import Categories.Category.Monoidal.Braided using (Braided)
module Categories.Category.Monoidal.Braided.Properties
{o ℓ e} {C : Category o ℓ e} {M : Monoidal C} (BM : Braided M) where
open import Data.Product using (_,_)
open import Categories.Category.Monoidal.Properties M
open import Categories.Category.Monoidal.Reasoning M
open import Categories.Category.Monoidal.Utilities M
open import Categories.Functor using (Functor)
open import Categories.Morphism C using (module ≅)
open import Categories.Morphism.IsoEquiv C using (_≃_; ⌞_⌟)
open import Categories.Morphism.Reasoning C hiding (push-eq)
open import Categories.NaturalTransformation.NaturalIsomorphism using (niHelper)
open import Categories.NaturalTransformation.NaturalIsomorphism.Properties
using (push-eq)
open Category C
open Braided BM
open Commutation C
private
variable
X Y Z : Obj
-- A shorthand for the braiding
B : ∀ {X Y} → X ⊗₀ Y ⇒ Y ⊗₀ X
B {X} {Y} = braiding.⇒.η (X , Y)
-- It's easier to prove the following lemma, which is the desired
-- coherence theorem moduolo application of the |-⊗ unit| functor.
-- Because |-⊗ unit| is equivalent to the identity functor, the
-- lemma and the theorem are equivalent.
-- The following diagram illustrates the hexagon that we are
-- operating on. The main outer hexagon is hexagon₁, the braiding
-- coherence, instantiated with X, 1 and 1 (Here we denote the unit
-- by 1 for brevity).
-- In the middle are X1 and 1X along with morphisms towards them.
-- The lower hexagon (given by the double lines) commutes and is
-- an intermediary in the final proof. It is there to effectively
-- get rid of the top half of the main hexagon.
-- The rest of the proof is isolating the bottom left triangle
-- which represents our desired identity. It is doing that by
-- proving that the pentagon to the right of it commutes.
-- The pentagon commuting is, in turn, proved by gluing the
-- rightmost "square" onto the middle triangle.
--
--
-- ┌─────> X(11) ─────────> (11)X ──────┐
-- ┌┘ α │ B │ α └┐
-- ┌┘ │id⊗λ │λ⊗id └┐
-- ┌┘ V V V
-- (X1)1 ═══════> X1 ════════════> 1X <══════ 1(1X)
-- ╚╗ ρ⊗id Λ <───┐ B λ Λ
-- ╚╗ │λ⊗id └────────┐ ╔╝
-- ╚╗ │ λ └┐ ╔╝
-- ╚═════> (1X)1 ═════════> 1(X1) ═════╝
-- B⊗id α id⊗B
braiding-coherence⊗unit : [ (X ⊗₀ unit) ⊗₀ unit ⇒ X ⊗₀ unit ]⟨
B ⊗₁ id ⇒⟨ (unit ⊗₀ X) ⊗₀ unit ⟩
unitorˡ.from ⊗₁ id
≈ unitorʳ.from ⊗₁ id
⟩
braiding-coherence⊗unit = cancel-fromˡ braiding.FX≅GX (
begin
B ∘ unitorˡ.from ⊗₁ id ∘ B ⊗₁ id ≈⟨ pullˡ (⟺ (glue◽◃ unitorˡ-commute-from coherence₁)) ⟩
(unitorˡ.from ∘ id ⊗₁ B ∘ associator.from) ∘ B ⊗₁ id ≈⟨ assoc²' ⟩
unitorˡ.from ∘ id ⊗₁ B ∘ associator.from ∘ B ⊗₁ id ≈⟨ refl⟩∘⟨ hexagon₁ ⟩
unitorˡ.from ∘ associator.from ∘ B ∘ associator.from ≈⟨ pullˡ coherence₁ ⟩
unitorˡ.from ⊗₁ id ∘ B ∘ associator.from ≈˘⟨ pushˡ (braiding.⇒.commute _) ⟩
(B ∘ id ⊗₁ unitorˡ.from) ∘ associator.from ≈⟨ pullʳ triangle ⟩
B ∘ unitorʳ.from ⊗₁ id
∎)
-- The desired theorem follows from |braiding-coherence⊗unit| by
-- translating it along the right unitor (which is a natural iso).
braiding-coherence : [ X ⊗₀ unit ⇒ X ]⟨
B ⇒⟨ unit ⊗₀ X ⟩
unitorˡ.from
≈ unitorʳ.from
⟩
braiding-coherence = push-eq unitorʳ-naturalIsomorphism (begin
(unitorˡ.from ∘ B) ⊗₁ id ≈⟨ homomorphism ⟩
(unitorˡ.from ⊗₁ id) ∘ (B ⊗₁ id) ≈⟨ braiding-coherence⊗unit ⟩
unitorʳ.from ⊗₁ id ∎)
where open Functor (-⊗ unit)
-- Shorthands for working with isomorphisms.
open ≅ using () renaming (refl to idᵢ; sym to _⁻¹)
infixr 9 _∘ᵢ_
private
_∘ᵢ_ = λ {A B C} f g → ≅.trans {A} {B} {C} g f
Bᵢ = braiding.FX≅GX
B⁻¹ = λ {X} {Y} → braiding.⇐.η (X , Y)
-- Variants of the hexagon identities defined on isos.
hexagon₁-iso : idᵢ ⊗ᵢ Bᵢ ∘ᵢ associator ∘ᵢ Bᵢ {X , Y} ⊗ᵢ idᵢ {Z} ≃
associator ∘ᵢ Bᵢ {X , Y ⊗₀ Z} ∘ᵢ associator
hexagon₁-iso = ⌞ hexagon₁ ⌟
hexagon₂-iso : (Bᵢ ⊗ᵢ idᵢ ∘ᵢ associator ⁻¹) ∘ᵢ idᵢ {X} ⊗ᵢ Bᵢ {Y , Z} ≃
(associator ⁻¹ ∘ᵢ Bᵢ {X ⊗₀ Y , Z}) ∘ᵢ associator ⁻¹
hexagon₂-iso = ⌞ hexagon₂ ⌟
-- A variants of the above coherence law defined on isos.
braiding-coherence-iso : unitorˡ ∘ᵢ Bᵢ ≃ unitorʳ {X}
braiding-coherence-iso = ⌞ braiding-coherence ⌟
-- The inverse of the braiding is also a braiding on M.
inv-Braided : Braided M
inv-Braided = record
{ braiding = niHelper (record
{ η = λ _ → B⁻¹
; η⁻¹ = λ _ → B
; commute = λ{ (f , g) → braiding.⇐.commute (g , f) }
; iso = λ{ (X , Y) → record
{ isoˡ = braiding.iso.isoʳ (Y , X)
; isoʳ = braiding.iso.isoˡ (Y , X) } }
})
; hexagon₁ = _≃_.to-≈ hexagon₂-iso
; hexagon₂ = _≃_.to-≈ hexagon₁-iso
}
-- A variant of the above coherence law for the inverse of the braiding.
inv-braiding-coherence : [ unit ⊗₀ X ⇒ X ]⟨
B⁻¹ ⇒⟨ X ⊗₀ unit ⟩
unitorʳ.from
≈ unitorˡ.from
⟩
inv-braiding-coherence = ⟺ (switch-fromtoʳ Bᵢ braiding-coherence)
|
{
"alphanum_fraction": 0.5672108371,
"avg_line_length": 39.4383561644,
"ext": "agda",
"hexsha": "a61306f456609bc54e42a7c357f83b20e1e488d0",
"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": "f8a33de12956c729c7fb00a302f166a643eb6052",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "TOTBWF/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Monoidal/Braided/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f8a33de12956c729c7fb00a302f166a643eb6052",
"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": "TOTBWF/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Monoidal/Braided/Properties.agda",
"max_line_length": 124,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f8a33de12956c729c7fb00a302f166a643eb6052",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "TOTBWF/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Monoidal/Braided/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2073,
"size": 5758
}
|
module Implicits.Resolution.Ambiguous.Undecidable where
open import Prelude hiding (Dec)
open import Relation.Nullary
open import Relation.Nullary.Decidable as DecM
open import Function.Equivalence using (_⇔_; equivalence)
open import Relation.Binary.HeterogeneousEquality as H using ()
open import Implicits.Syntax
open import Implicits.Resolution.Ambiguous.Resolution
open import Implicits.Resolution.Ambiguous.Semantics
open import Implicits.Resolution.Ambiguous.SystemFEquiv
open import Implicits.Resolution.Embedding
open import Implicits.Resolution.Embedding.Lemmas
open import SystemF.Everything as F using ()
{-
Assuming undecidability of the type inhabitation problem for System F
(as proven by e.g. Barendregt) we can prove the undecidability of Ambiguous resolution
-}
private
-- type of inhabitation problem decider
?:-Dec : Set
?:-Dec = ∀ {n ν} (Γ : F.Ctx ν n) (a : F.Type ν) → Dec (∃ λ t → Γ F.⊢ t ∈ a)
module Undecidable (?:-undec : ¬ ?:-Dec) where
-- type of decider for ambiguous resolution
⊢ᵣ-Dec : Set
⊢ᵣ-Dec = ∀ {ν} (Δ : ICtx ν) (a : Type ν) → Dec (Δ ⊢ᵣ a)
-- proof that such a decider would imply a decider for type inhabitation problem
reduction : ⊢ᵣ-Dec → ?:-Dec
reduction f Γ x = DecM.map (equivalent' Γ x) (f ⟦ Γ ⟧ctx← ⟦ x ⟧tp←)
-- completing the proof
undecidable : ¬ ⊢ᵣ-Dec
undecidable f = ?:-undec (reduction f)
|
{
"alphanum_fraction": 0.7300435414,
"avg_line_length": 32.8095238095,
"ext": "agda",
"hexsha": "edcb23bd6b95c59e6af0d72c8880bbf5b1356d97",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Ambiguous/Undecidable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Ambiguous/Undecidable.agda",
"max_line_length": 88,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Ambiguous/Undecidable.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 431,
"size": 1378
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- An inductive definition of the sublist relation for types which have
-- a decidable equality. This is commonly known as Order Preserving
-- Embeddings (OPE).
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
open import Agda.Builtin.Equality using (_≡_)
module Data.List.Relation.Binary.Sublist.DecPropositional
{a} {A : Set a} (_≟_ : Decidable {A = A} _≡_)
where
open import Data.List.Relation.Binary.Equality.DecPropositional _≟_
using (_≡?_)
import Data.List.Relation.Binary.Sublist.DecSetoid as DecSetoidSublist
import Data.List.Relation.Binary.Sublist.Propositional as PropositionalSublist
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- Re-export core definitions and operations
open PropositionalSublist {A = A} public
open DecSetoidSublist (decSetoid _≟_) using (_⊆?_) public
------------------------------------------------------------------------
-- Additional relational properties
⊆-isDecPartialOrder : IsDecPartialOrder _≡_ _⊆_
⊆-isDecPartialOrder = record
{ isPartialOrder = ⊆-isPartialOrder
; _≟_ = _≡?_
; _≤?_ = _⊆?_
}
⊆-decPoset : DecPoset a a a
⊆-decPoset = record
{ isDecPartialOrder = ⊆-isDecPartialOrder
}
|
{
"alphanum_fraction": 0.5881133379,
"avg_line_length": 32.8863636364,
"ext": "agda",
"hexsha": "40bcb19e99e31abc346849d172172ff0d2b81f2a",
"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": "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/Sublist/DecPropositional.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/Sublist/DecPropositional.agda",
"max_line_length": 78,
"max_stars_count": 5,
"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/Sublist/DecPropositional.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": 355,
"size": 1447
}
|
module _ where
open import Agda.Primitive.Cubical
open import Agda.Builtin.Nat
postulate
PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ
{-# BUILTIN PATHP PathP #-}
postulate
A : Set
a : A
b : A
p : PathP (\ _ → A) a b
test1 : ∀ {p : PathP (\ _ → A) a a} {P : A → Set} → P (p i0) → P a
test1 x = x
test2 : ∀ {P : A → Set} → P (p i0) → P a
test2 x = x
q : (x : Nat) → PathP (\ _ → Nat) x x
q zero i = zero
q (suc n) i = suc (q n i)
test3 : ∀ {P : Nat → Set}{n : Nat} → P (q n i0) → P n
test3 x = x
|
{
"alphanum_fraction": 0.4990583804,
"avg_line_length": 17.7,
"ext": "agda",
"hexsha": "98031f4dd9d11d34d51f11a16756e2081095730f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/Issue2986.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/Issue2986.agda",
"max_line_length": 66,
"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/Issue2986.agda",
"max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z",
"num_tokens": 238,
"size": 531
}
|
module NothingAppliedToHiddenArg where
bad = {x}
|
{
"alphanum_fraction": 0.7843137255,
"avg_line_length": 10.2,
"ext": "agda",
"hexsha": "3f2981d86b40afa00b1d16bb33bcf579e385b5cd",
"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/NothingAppliedToHiddenArg.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/NothingAppliedToHiddenArg.agda",
"max_line_length": 38,
"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/NothingAppliedToHiddenArg.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": 13,
"size": 51
}
|
module Utils.Decidable where
open import Data.Nat
open import Data.Char
open import Data.String
open import Data.Bool
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable hiding (True; False)
open import Relation.Nullary
open import Data.Product
open import Data.Sum
open import Function
import Level as L
{-
A type class for decidable types.
The part we actually end up using in the formal semantics proofs is
mostly decidable equality (_≡⁇_).
-}
_=>_ : ∀ {α β} → Set α → Set β → Set (α L.⊔ β)
Dict => A = ⦃ _ : Dict ⦄ → A
infixr 5 _=>_
record Decidable {a}(A : Set a) : Set a where
constructor rec
field
decide : Dec A
DecRel : ∀ {a b}{A : Set a}{B : Set b} → (A → B → Set (a L.⊔ b)) → Set (a L.⊔ b)
DecRel Rel = ∀ {x y} → Decidable (Rel x y)
DecEq : ∀ {a} → Set a → Set a
DecEq A = DecRel (_≡_ {_} {A})
_⁇ : ∀ {a} A → Decidable {a} A => Dec A
_⁇ A ⦃ dict ⦄ = Decidable.decide dict
_≡⁇_ : ∀ {a A} → DecEq {a} A => ((x y : A) → Dec (x ≡ y))
x ≡⁇ y = (x ≡ y) ⁇
True : ∀ {a} A → Decidable {a} A => Set
True A = T ⌊ A ⁇ ⌋
F : Bool → Set
F = T ∘ not
False : ∀ {a} A → Decidable {a} A => Set
False A = F ⌊ A ⁇ ⌋
_≤⁇_ : ∀ a b → Dec (a ≤ b)
_≤⁇_ = _≤?_
_<⁇_ : ∀ a b → Dec (a < b)
a <⁇ b = suc a ≤⁇ b
module _ where
open import Data.Nat.Properties
_≤′⁇_ : ∀ a b → Dec (a ≤′ b)
_≤′⁇_ a b with a ≤⁇ b
... | yes p = yes (≤⇒≤′ p)
... | no p = no (p ∘ ≤′⇒≤)
_<′⁇_ : ∀ a b → Dec (a <′ b)
a <′⁇ b = suc a ≤′⁇ b
instance
DecEqBool : DecEq Bool
DecEqBool = rec (_ Data.Bool.≟ _)
instance
DecEqChar : DecEq Char
DecEqChar = rec (_ Data.Char.≟ _)
module _ where
open import Data.Fin
open import Data.Fin.Properties
instance
DecEqFin : ∀ {n} → DecEq (Fin n)
DecEqFin = rec (_ Data.Fin.Properties.≟ _)
instance
DecEqℕ : DecEq ℕ
DecEqℕ = rec (_ Data.Nat.≟ _)
instance
DecEqString : DecEq String
DecEqString = rec (_ Data.String.≟ _)
instance
Decℕ≤ : DecRel _≤_
Decℕ≤ = rec (_ ≤⁇ _)
instance
Decℕ≤′ : DecRel _≤′_
Decℕ≤′ = rec (_ ≤′⁇ _)
-- Conversions between decidable / boolean
--------------------------------------------------
T→∧ : ∀ {a b} → T (a ∧ b) → T a × T b
T→∧ {true} {true} x = _
T→∧ {true} {false} ()
T→∧ {false} ()
∧→T : ∀ {a b} → T a → T b → T (a ∧ b)
∧→T {true} {true} p1 p2 = _
∧→T {true} {false} p1 ()
∧→T {false} () p2
F-not-elim : ∀ {b} → F (not b) → T b
F-not-elim {true} p = p
F-not-elim {false} p = p
F-not-add : ∀ {b} → T b → F (not b)
F-not-add {true} p = p
F-not-add {false} p = p
F-not-≡ : ∀ b → T b ≡ F (not b)
F-not-≡ true = refl
F-not-≡ false = refl
TrueA→A : ∀ {a A}⦃ _ : Decidable {a} A ⦄ → True A → A
TrueA→A = toWitness
FalseA→¬A : ∀ {a A}⦃ _ : Decidable {a} A ⦄ → False A → ¬ A
FalseA→¬A = toWitnessFalse
A→TrueA : ∀ {a A}⦃ _ : Decidable {a} A ⦄ → A → True A
A→TrueA = fromWitness
¬A→FalseA : ∀ {a A}⦃ _ : Decidable {a} A ⦄ → ¬ A → False A
¬A→FalseA = fromWitnessFalse
T→≡true : ∀ {b} → T b → b ≡ true
T→≡true {true} p = refl
T→≡true {false} ()
≡true→T : ∀ {b} → b ≡ true → T b
≡true→T {true} p = _
≡true→T {false} ()
≡false→F : ∀ {b} → b ≡ false → F b
≡false→F {true} ()
≡false→F {false} p = _
F→≡false : ∀ {b} → F b → b ≡ false
F→≡false {true} ()
F→≡false {false} p = refl
A→≡true : ∀ {a A}{Q : Dec {a} A} → A → ⌊ Q ⌋ ≡ true
A→≡true = T→≡true ∘ fromWitness
¬A→≡false : ∀ {a A}{Q : Dec {a} A} → ¬ A → ⌊ Q ⌋ ≡ false
¬A→≡false = F→≡false ∘ fromWitnessFalse
≡true→A : ∀ {a A}{Q : Dec {a} A} → ⌊ Q ⌋ ≡ true → A
≡true→A = toWitness ∘ ≡true→T
≡false→¬A : ∀ {a A}{Q : Dec {a} A} → ⌊ Q ⌋ ≡ false → ¬ A
≡false→¬A = toWitnessFalse ∘ ≡false→F
-----------------------------------------------------------
instance
Dec¬ :
∀ {α A}
→ Decidable {α} A
=> Decidable (¬ A)
Dec¬ {_}{A} = rec dec¬ where
dec¬ : Dec (¬ A)
dec¬ with A ⁇
... | yes p = no (λ z → z p)
... | no ¬p = yes ¬p
instance
Dec⊎ :
∀ {α β A B}
→ Decidable {α} A
=> Decidable {β} B
=> Decidable (A ⊎ B)
Dec⊎ {_}{_}{A}{B} = rec dec⊎ where
dec⊎ : Dec (A ⊎ B)
dec⊎ with A ⁇ | B ⁇
... | yes p | _ = yes (inj₁ p)
... | _ | yes p = yes (inj₂ p)
... | no ¬p₁ | no ¬p₂ = no [ ¬p₁ , ¬p₂ ]′
instance
Dec× :
∀ {α β A B}
→ Decidable {α} A
=> Decidable {β} B
=> Decidable (A × B)
Dec× {_}{_}{A}{B} = rec dec× where
dec× : Dec (A × B)
dec× with A ⁇ | B ⁇
... | yes p | yes p₁ = yes (p , p₁)
... | yes p | no ¬p = no (¬p ∘ proj₂)
... | no ¬p | _ = no (¬p ∘ proj₁)
|
{
"alphanum_fraction": 0.5004415011,
"avg_line_length": 21.0697674419,
"ext": "agda",
"hexsha": "144cd033501a0b00fa0819346c1bc1b524194f2e",
"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": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AndrasKovacs/SemanticsWithApplications",
"max_forks_repo_path": "Utils/Decidable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"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": "AndrasKovacs/SemanticsWithApplications",
"max_issues_repo_path": "Utils/Decidable.agda",
"max_line_length": 80,
"max_stars_count": 8,
"max_stars_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AndrasKovacs/SemanticsWithApplications",
"max_stars_repo_path": "Utils/Decidable.agda",
"max_stars_repo_stars_event_max_datetime": "2020-02-02T10:01:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-09-12T04:25:39.000Z",
"num_tokens": 1991,
"size": 4530
}
|
-- pull in Haskell Ints
module int where
open import bool
open import string
postulate
int : Set
int0 : int
int1 : int
_+int_ : int → int → int
_*int_ : int → int → int
_-int_ : int → int → int
string-to-int : string → int
is-zero-int : int → 𝔹
{-# COMPILED_TYPE int Int #-}
{-# COMPILED int0 0 #-}
{-# COMPILED int1 1 #-}
{-# COMPILED _+int_ (+) #-}
{-# COMPILED _*int_ (*) #-}
{-# COMPILED _-int_ (-) #-}
{-# COMPILED string-to-int (\ x -> read x :: Int) #-}
{-# COMPILED is-zero-int ((==) 0) #-}
|
{
"alphanum_fraction": 0.5694980695,
"avg_line_length": 21.5833333333,
"ext": "agda",
"hexsha": "e0d138657692a90b445358f4cbd2f7546dd8b883",
"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": "int.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": "int.agda",
"max_line_length": 53,
"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": "int.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 184,
"size": 518
}
|
-- {-# OPTIONS -v tc.rec:100 -v tc.signature:20 #-}
module Issue414 where
record P : Set₁ where
field
q : Set
x : P
x = record { q = q }
-- Andreas 2011-05-19
-- record constructor should have been added to the signature
-- before record module is constructed!
|
{
"alphanum_fraction": 0.6605839416,
"avg_line_length": 21.0769230769,
"ext": "agda",
"hexsha": "8b15788575a650095395d8ba9b3b80784ab1f93e",
"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/Issue414.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/Issue414.agda",
"max_line_length": 61,
"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/Issue414.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": 79,
"size": 274
}
|
------------------------------------------------------------------------
-- Contexts, variables, context morphisms, context extensions, etc.
------------------------------------------------------------------------
-- The contexts, variables, etc. are parametrised by a universe.
open import Data.Universe.Indexed
module deBruijn.Context
{i u e} (Uni : IndexedUniverse i u e) where
-- Contexts, variables, context morphisms, etc.
import deBruijn.Context.Basics as Basics
open Basics Uni public
-- Context extensions with the rightmost element in the outermost
-- position.
import deBruijn.Context.Extension.Right as Right
open Right Uni public
-- Context extensions with the leftmost element in the outermost
-- position.
import deBruijn.Context.Extension.Left as Left
open Left Uni public
-- The two definitions of context extensions are isomorphic.
import deBruijn.Context.Extension.Isomorphic as Isomorphic
open Isomorphic Uni public
-- An abstraction: term-like things.
import deBruijn.Context.Term-like as Term-like
open Term-like Uni public
|
{
"alphanum_fraction": 0.6804901037,
"avg_line_length": 27.9210526316,
"ext": "agda",
"hexsha": "8f099c66bc485717b86c0a9c03a6aad8db6844d3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependently-typed-syntax",
"max_forks_repo_path": "deBruijn/Context.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/dependently-typed-syntax",
"max_issues_repo_path": "deBruijn/Context.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependently-typed-syntax",
"max_stars_repo_path": "deBruijn/Context.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z",
"num_tokens": 216,
"size": 1061
}
|
data D : Set where
c : D
s : D → D
predD : D → D
predD c = c
predD (s x) = x
f : D → D
f c = c
f (s n) with c
f x@(s _) | c = x
f (s _) | s _ = c
data E : D → Set where
e : E c
s : ∀ {x} → E x → E (s x)
predE : ∀ {d} → E d → E (predD d)
predE e = e
predE (s x) = x
g : ∀ {d} → E d → E (predD d)
g e = e
g (s x) with x
g y@(s _) | s z = predE y
g (s z@e) | e = predE z
|
{
"alphanum_fraction": 0.4230769231,
"avg_line_length": 13.4482758621,
"ext": "agda",
"hexsha": "434bc2c1138ff724b9d07cfe5375cc39dfc0111c",
"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/Issue2313.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/Issue2313.agda",
"max_line_length": 33,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2313.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": 201,
"size": 390
}
|
module Everything where
import Prelude
import Stack
import Syntax
import ProposedSemantics
import Semantics.Ono
import Semantics.BozicDosen
import Semantics.AlechinaEtAl
import Semantics.Iemhoff
import CompleteProposedSemantics
import CompleteSemantics.Ono
import CompleteSemantics.BozicDosen
import CompleteSemantics.AlechinaEtAl
import CompleteSemantics.Iemhoff
|
{
"alphanum_fraction": 0.8885869565,
"avg_line_length": 19.3684210526,
"ext": "agda",
"hexsha": "3567f065024b6ea5117c69d68a45e75f42ce4572",
"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": "accc6c57390c435728d568ae590a02b2776b8891",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/imla2017",
"max_forks_repo_path": "src/Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "accc6c57390c435728d568ae590a02b2776b8891",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/imla2017",
"max_issues_repo_path": "src/Everything.agda",
"max_line_length": 37,
"max_stars_count": 17,
"max_stars_repo_head_hexsha": "accc6c57390c435728d568ae590a02b2776b8891",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/imla2017",
"max_stars_repo_path": "src/Everything.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-17T13:02:58.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-02-27T05:04:55.000Z",
"num_tokens": 93,
"size": 368
}
|
{-# OPTIONS --cubical --safe #-}
open import Prelude hiding (sym; refl)
open import Relation.Binary
module Relation.Binary.Lattice {ℓ₁ ℓ₂ ℓ₃} {𝑆 : Type ℓ₁} (totalOrder : TotalOrder 𝑆 ℓ₂ ℓ₃) where
open TotalOrder totalOrder
import Path as ≡
min-max : 𝑆 → 𝑆 → 𝑆 × 𝑆
min-max x y = bool′ (y , x) (x , y) (x <ᵇ y)
_⊔_ : 𝑆 → 𝑆 → 𝑆
x ⊔ y = snd (min-max x y)
_⊓_ : 𝑆 → 𝑆 → 𝑆
x ⊓ y = fst (min-max x y)
min-max-assoc : ∀ x y z → map-Σ (_⊓ z) (_⊔ z) (min-max x y) ≡ map-Σ (x ⊓_) (x ⊔_) (min-max y z)
min-max-assoc x y z with x <? y | inspect (x <ᵇ_) y | y <? z | inspect (y <ᵇ_) z
min-max-assoc x y z | yes x≤y | 〖 xyp 〗 | yes y≤z | 〖 yzp 〗 with x <? z
min-max-assoc x y z | yes x≤y | 〖 xyp 〗 | yes y≤z | 〖 yzp 〗 | yes x≤z = cong₂ _,_ (cong (fst ∘ bool _ _) (≡.sym xyp)) (cong (snd ∘ bool _ _) yzp)
min-max-assoc x y z | yes x≤y | 〖 xyp 〗 | yes y≤z | 〖 yzp 〗 | no x≥z = ⊥-elim (x≥z (<-trans x≤y y≤z))
min-max-assoc x y z | no x≥y | 〖 xyp 〗 | yes y≤z | 〖 yzp 〗 = cong (_, (x ⊔ z)) (cong (fst ∘ bool _ _) yzp ; cong (fst ∘ bool _ _) (≡.sym xyp))
min-max-assoc x y z | yes x≤y | 〖 xyp 〗 | no y≥z | 〖 yzp 〗 = cong ((x ⊓ z) ,_) (cong (snd ∘ bool _ _) yzp ; cong (snd ∘ bool _ _) (≡.sym xyp))
min-max-assoc x y z | no x≥y | 〖 xyp 〗 | no y≥z | 〖 yzp 〗 with x <? z
min-max-assoc x y z | no x≥y | 〖 xyp 〗 | no y≥z | 〖 yzp 〗 | no x≥z = cong₂ _,_ (cong (fst ∘ bool _ _) yzp) (cong (snd ∘ bool _ _) (≡.sym xyp))
min-max-assoc x y z | no x≥y | 〖 xyp 〗 | no y≥z | 〖 yzp 〗 | yes x≤z = cong₂ _,_ (cong (fst ∘ bool _ _) yzp ; lemma) (lemma ; cong (snd ∘ bool _ _) (≡.sym xyp))
where
lemma : z ≡ x
lemma = antisym (≤-trans (≮⇒≥ y≥z) (≮⇒≥ x≥y)) (<⇒≤ x≤z)
⊓-assoc : ∀ x y z → (x ⊓ y) ⊓ z ≡ x ⊓ (y ⊓ z)
⊓-assoc x y z = cong fst (min-max-assoc x y z)
⊔-assoc : ∀ x y z → (x ⊔ y) ⊔ z ≡ x ⊔ (y ⊔ z)
⊔-assoc x y z = cong snd (min-max-assoc x y z)
min-max-comm : ∀ x y → min-max x y ≡ min-max y x
min-max-comm x y with x <? y | y <? x
min-max-comm x y | yes x<y | yes y<x = ⊥-elim (asym x<y y<x)
min-max-comm x y | no x≮y | yes y<x = ≡.refl
min-max-comm x y | yes x<y | no y≮x = ≡.refl
min-max-comm x y | no x≮y | no y≮x = cong₂ _,_ (conn y≮x x≮y) (conn x≮y y≮x)
⊓-comm : ∀ x y → x ⊓ y ≡ y ⊓ x
⊓-comm x y = cong fst (min-max-comm x y)
⊔-comm : ∀ x y → x ⊔ y ≡ y ⊔ x
⊔-comm x y = cong snd (min-max-comm x y)
min-max-idem : ∀ x → min-max x x ≡ (x , x)
min-max-idem x = bool {P = λ r → bool′ (x , x) (x , x) r ≡ (x , x)} ≡.refl ≡.refl (x <ᵇ x)
⊓-idem : ∀ x → x ⊓ x ≡ x
⊓-idem x = cong fst (min-max-idem x)
⊔-idem : ∀ x → x ⊔ x ≡ x
⊔-idem x = cong snd (min-max-idem x)
≤⊔ : ∀ x y → x ≤ x ⊔ y
≤⊔ x y with x <? y
≤⊔ x y | yes x<y = <⇒≤ x<y
≤⊔ x y | no x≮y = refl
⊓≤ : ∀ x y → x ⊓ y ≤ x
⊓≤ x y with x <? y
⊓≤ x y | yes x<y = refl
⊓≤ x y | no x≮y = ≮⇒≥ x≮y
|
{
"alphanum_fraction": 0.5025436047,
"avg_line_length": 38.2222222222,
"ext": "agda",
"hexsha": "3e0d96523ee4ed749afd3ca09e445c6ce5b418b0",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Relation/Binary/Lattice.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Relation/Binary/Lattice.agda",
"max_line_length": 161,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Relation/Binary/Lattice.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 1497,
"size": 2752
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cohomology.CupProduct.OnEM.InAllDegrees
open import cohomology.CupProduct.OnEM.CommutativityInAllDegrees
open import cohomology.EMModel
open import cohomology.Theory
open import groups.ToOmega
open import homotopy.EilenbergMacLane
open import homotopy.EilenbergMacLaneFunctor
open import homotopy.Freudenthal
open import homotopy.SuspensionLoopSpaceInverse
module cohomology.CupProduct.Definition {i} (X : Ptd i) where
private
module M {k} (A : AbGroup k) = CohomologyTheory (EM-Cohomology A)
open M
⊙×-diag : X ⊙→ X ⊙× X
⊙×-diag = (λ x → x , x) , idp
smin-map : ∀ {j k} {Y : Ptd j} {Z : Ptd k}
→ X ⊙→ Y
→ X ⊙→ Z
→ X ⊙→ Y ⊙× Z
smin-map f g = ⊙×-fmap f g ⊙∘ ⊙×-diag
smin-map-⊙×-swap : ∀ {j k} (Y : Ptd j) (Z : Ptd k)
(f : X ⊙→ Y)
(g : X ⊙→ Z)
→ ⊙×-swap ⊙∘ smin-map g f == smin-map f g
smin-map-⊙×-swap Y Z (_ , idp) (_ , idp) = idp
module _ (G : AbGroup i) (H : AbGroup i) where
private
module G⊗H = TensorProduct G H
module H⊗G = TensorProduct H G
open EMExplicit
⊙Ω×-cp-seq : ∀ (m n : ℕ) → (⊙Ω (⊙EM G (S m)) ⊙× ⊙Ω (⊙EM H (S n))) ⊙–→ ⊙Ω (⊙EM G⊗H.abgroup (S (m + n)))
⊙Ω×-cp-seq m n =
⊙<– (spectrum G⊗H.abgroup (m + n)) ◃⊙∘
⊙×-cp G H m n ◃⊙∘
⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf
⊙Ω×-cp : ∀ (m n : ℕ) → ⊙Ω (⊙EM G (S m)) ⊙× ⊙Ω (⊙EM H (S n)) ⊙→ ⊙Ω (⊙EM G⊗H.abgroup (S (m + n)))
⊙Ω×-cp m n = ⊙compose (⊙Ω×-cp-seq m n)
_∪_ : ∀ {m n : ℕ} → CEl G (pos m) X → CEl H (pos n) X → CEl G⊗H.abgroup (pos (m + n)) X
_∪_ {m} {n} = Trunc-fmap2 {n = 0} (λ s' t' → ⊙Ω×-cp m n ⊙∘ smin-map s' t')
module _ (G : AbGroup i) (H : AbGroup i) where
private
module G⊗H = TensorProduct G H
module H⊗G = TensorProduct H G
open EMExplicit
abstract
⊙Ω×-cp-comm : ∀ (m n : ℕ)
→ ⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘
⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ◃⊙∘
⊙Ω×-cp G H m n ◃⊙idf
=⊙∘
⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘
⊙Ω×-cp H G n m ◃⊙∘
⊙×-swap ◃⊙idf
⊙Ω×-cp-comm m n =
⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘
⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ◃⊙∘
⊙Ω×-cp G H m n ◃⊙idf
=⊙∘⟨ 2 & 1 & ⊙expand (⊙Ω×-cp-seq G H m n) ⟩
⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘
⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ◃⊙∘
⊙<– (spectrum G⊗H.abgroup (m + n)) ◃⊙∘
⊙×-cp G H m n ◃⊙∘
⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf
=⊙∘⟨ 1 & 2 & !⊙∘ $ ⊙<–-spectrum-natural G⊗H.abgroup H⊗G.abgroup G⊗H.swap (m + n) ⟩
⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘
⊙<– (spectrum H⊗G.abgroup (m + n)) ◃⊙∘
⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (m + n) ◃⊙∘
⊙×-cp G H m n ◃⊙∘
⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf
=⊙∘⟨ 0 & 2 & !⊙∘ $ ⊙transport-natural-=⊙∘
(+-comm m n)
(λ k → ⊙<– (spectrum H⊗G.abgroup k)) ⟩
⊙<– (spectrum H⊗G.abgroup (n + m)) ◃⊙∘
⊙transport (λ k → ⊙EM H⊗G.abgroup k) (+-comm m n) ◃⊙∘
⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (m + n) ◃⊙∘
⊙×-cp G H m n ◃⊙∘
⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf
=⊙∘⟨ 1 & 3 & ⊙×-cp-comm G H m n ⟩
⊙<– (spectrum H⊗G.abgroup (n + m)) ◃⊙∘
⊙cond-neg H⊗G.abgroup (n + m) (and (odd m) (odd n)) ◃⊙∘
⊙×-cp H G n m ◃⊙∘
⊙×-swap ◃⊙∘
⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf
=⊙∘⟨ 0 & 2 & ⊙transport-natural-=⊙∘
(Bool-elim (inv-path H⊗G.abgroup) idp (and (odd m) (odd n)))
(λ A → ⊙<– (spectrum A (n + m))) ⟩
⊙transport (λ A → ⊙Ω (⊙EM A (S (n + m)))) neg ◃⊙∘
⊙<– (spectrum H⊗G.abgroup (n + m)) ◃⊙∘
⊙×-cp H G n m ◃⊙∘
⊙×-swap ◃⊙∘
⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf
=⊙∘₁⟨ 0 & 1 &
⊙transport-⊙coe (λ A → ⊙Ω (⊙EM A (S (n + m)))) neg ∙
ap ⊙coe (ap-∘ ⊙Ω (λ A → ⊙EM A (S (n + m))) neg) ∙
! (⊙transport-⊙coe ⊙Ω (ap (λ A → ⊙EM A (S (n + m))) neg)) ∙
⊙transport-⊙Ω (ap (λ A → ⊙EM A (S (n + m))) neg) ∙
ap ⊙Ω-fmap (! (⊙transport-⊙coe (λ A → ⊙EM A (S (n + m))) neg)) ⟩
⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘
⊙<– (spectrum H⊗G.abgroup (n + m)) ◃⊙∘
⊙×-cp H G n m ◃⊙∘
⊙×-swap ◃⊙∘
⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf
=⊙∘⟨ 3 & 2 & =⊙∘-in {gs = ⊙×-fmap (⊙–> (spectrum H n)) (⊙–> (spectrum G m)) ◃⊙∘
⊙×-swap ◃⊙idf} $
! $ ⊙λ= $ ⊙×-swap-natural (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ⟩
⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘
⊙<– (spectrum H⊗G.abgroup (n + m)) ◃⊙∘
⊙×-cp H G n m ◃⊙∘
⊙×-fmap (⊙–> (spectrum H n)) (⊙–> (spectrum G m)) ◃⊙∘
⊙×-swap ◃⊙idf
=⊙∘⟨ 1 & 3 & ⊙contract ⟩
⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘
⊙Ω×-cp H G n m ◃⊙∘
⊙×-swap ◃⊙idf ∎⊙∘
where
neg : H⊗G.abgroup == H⊗G.abgroup
neg = Bool-elim (inv-path H⊗G.abgroup) idp (and (odd m) (odd n))
∪-swap : ∀ (m n : ℕ)
→ CEl G⊗H.abgroup (pos (m + n)) X → CEl H⊗G.abgroup (pos (n + m)) X
∪-swap m n =
transport (λ k → CEl H⊗G.abgroup (pos k) X) (+-comm m n) ∘
EM-CEl-coeff-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (pos (m + n)) X
maybe-inv : ∀ (n : ℤ) → Bool → CEl H⊗G.abgroup n X → CEl H⊗G.abgroup n X
maybe-inv n = Bool-rec (Group.inv (C H⊗G.abgroup n X)) (idf _)
private
_G∪H_ = _∪_ G H
_H∪G_ = _∪_ H G
∪-comm : ∀ {m n : ℕ}
(s : CEl G (pos m) X)
(t : CEl H (pos n) X)
→ ∪-swap m n (s G∪H t) ==
maybe-inv (pos (n + m)) (and (odd m) (odd n)) (t H∪G s)
∪-comm {m} {n} =
Trunc-elim {{λ s → Π-level (λ t → =-preserves-level Trunc-level)}} $ λ s' →
Trunc-elim {{λ t → =-preserves-level Trunc-level}} $ λ t' →
transport (λ k → CEl H⊗G.abgroup (pos k) X) (+-comm m n)
[ ⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ⊙∘
⊙Ω×-cp G H m n ⊙∘
smin-map s' t' ]
=⟨ app= step₁
[ ⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ⊙∘
⊙Ω×-cp G H m n ⊙∘
smin-map s' t' ] ⟩
[ ⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ⊙∘
⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ⊙∘
⊙Ω×-cp G H m n ⊙∘
smin-map s' t' ]
=⟨ ap [_] (=⊙∘-out (step₂ s' t')) ⟩
Trunc-fmap (⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ⊙∘_)
[ ⊙Ω×-cp H G n m ⊙∘ smin-map t' s' ]
=⟨ app= (step₃ (n + m) (and (odd m) (odd n))) [ ⊙Ω×-cp H G n m ⊙∘ smin-map t' s' ] ⟩
maybe-inv (pos (n + m)) (and (odd m) (odd n))
[ ⊙Ω×-cp H G n m ⊙∘ smin-map t' s' ] =∎
where
step₁ : transport (λ k → CEl H⊗G.abgroup (pos k) X) (+-comm m n) ==
Trunc-fmap (⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ⊙∘_)
step₁ =
transport (λ k → CEl H⊗G.abgroup (pos k) X) (+-comm m n)
=⟨ ap coe (ap-∘ (Trunc 0) (λ k → X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)) ⟩
transport (Trunc 0) (ap (λ k → X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n))
=⟨ transport-Trunc (ap (λ k → X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)) ⟩
Trunc-fmap (transport (λ k → X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n))
=⟨ ap (Trunc-fmap ∘ coe) (ap-∘ (X ⊙→_) (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)) ⟩
Trunc-fmap (transport (X ⊙→_) (ap (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)))
=⟨ ap Trunc-fmap $ λ= $ transport-post⊙∘ X (ap (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)) ⟩
Trunc-fmap (⊙coe (ap (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)) ⊙∘_)
=⟨ ap (λ g → Trunc-fmap (g ⊙∘_)) $
! $ ⊙transport-⊙coe (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ⟩
Trunc-fmap (⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ⊙∘_) =∎
step₂ : ∀ (s' : X ⊙→ ⊙Ω (⊙EM G (S m))) (t' : X ⊙→ ⊙Ω (⊙EM H (S n)))
→ ⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘
⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ◃⊙∘
⊙Ω×-cp G H m n ◃⊙∘
smin-map s' t' ◃⊙idf
=⊙∘
⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘
⊙Ω×-cp H G n m ◃⊙∘
smin-map t' s' ◃⊙idf
step₂ s' t' =
⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘
⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ◃⊙∘
⊙Ω×-cp G H m n ◃⊙∘
smin-map s' t' ◃⊙idf
=⊙∘⟨ 0 & 3 & ⊙Ω×-cp-comm m n ⟩
⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘
⊙Ω×-cp H G n m ◃⊙∘
⊙×-swap ◃⊙∘
smin-map s' t' ◃⊙idf
=⊙∘⟨ 2 & 2 & =⊙∘-in {gs = smin-map t' s' ◃⊙idf} $
smin-map-⊙×-swap (⊙Ω (⊙EM H (S n))) (⊙Ω (⊙EM G (S m))) t' s' ⟩
⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘
⊙Ω×-cp H G n m ◃⊙∘
smin-map t' s' ◃⊙idf ∎⊙∘
step₃ : ∀ (k : ℕ) (b : Bool) →
Trunc-fmap (⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S k) b) ⊙∘_) ==
maybe-inv (pos k) b
step₃ k false =
Trunc-fmap (⊙Ω-fmap (⊙idf (⊙EM H⊗G.abgroup (S k))) ⊙∘_)
=⟨ ap (λ g → Trunc-fmap (g ⊙∘_)) ⊙Ω-fmap-idf ⟩
Trunc-fmap (⊙idf (⊙Ω (⊙EM H⊗G.abgroup (S k))) ⊙∘_)
=⟨ ap Trunc-fmap (λ= (⊙λ= ∘ ⊙∘-unit-l)) ⟩
Trunc-fmap (idf (X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k))))
=⟨ λ= Trunc-fmap-idf ⟩
idf (Trunc 0 (X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k)))) =∎
step₃ k true =
Trunc-fmap (⊙Ω-fmap (⊙transport (λ A → ⊙EM A (S k)) (inv-path H⊗G.abgroup)) ⊙∘_)
=⟨ ap (λ f → Trunc-fmap (⊙Ω-fmap f ⊙∘_)) $
⊙transport-⊙EM-uaᴬᴳ H⊗G.abgroup H⊗G.abgroup (inv-iso H⊗G.abgroup) (S k) ⟩
Trunc-fmap (⊙Ω-fmap (⊙EM-fmap H⊗G.abgroup H⊗G.abgroup (inv-hom H⊗G.abgroup) (S k)) ⊙∘_)
=⟨ ap GroupHom.f (EM-C-coeff-fmap-inv-hom H⊗G.abgroup (pos k) X) ⟩
Group.inv (C H⊗G.abgroup (pos k) X) =∎
|
{
"alphanum_fraction": 0.457685158,
"avg_line_length": 44.0560344828,
"ext": "agda",
"hexsha": "e942301491e02ec5ba8f7e1f2ee00875873c1636",
"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": "theorems/cohomology/CupProduct/Definition.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": "theorems/cohomology/CupProduct/Definition.agda",
"max_line_length": 105,
"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": "theorems/cohomology/CupProduct/Definition.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": 5718,
"size": 10221
}
|
open import Agda.Builtin.Unit
data D : Set where
c₁ c₂ : D
@0 c₃ : D
f : @0 D → ⊤
f c₁ = tt
f c₂ = tt
f c₃ = tt
|
{
"alphanum_fraction": 0.5508474576,
"avg_line_length": 10.7272727273,
"ext": "agda",
"hexsha": "7cb9d2ff6f2263b28b72f312a8982a610d0d1907",
"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/Issue4638-1.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/Issue4638-1.agda",
"max_line_length": 29,
"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/Issue4638-1.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 59,
"size": 118
}
|
------------------------------------------------------------------------
-- This file contains the definition of a preorder as a category with --
-- additional properties. --
------------------------------------------------------------------------
module Category.Poset where
open import Level renaming (suc to lsuc)
open import Data.List
open import Data.Product hiding (map)
open import Data.Sum hiding (map)
open import Data.Empty
open import Data.Unit
open import Setoid.Total
open import Category.Category
open import Category.Preorder
open import Equality.Eq
record Poset {l : Level} : Set (lsuc l) where
field
-- The underlying category.
𝕊 : PO {l}
-- The poset axiom.
PSax : ∀{A B}{f : el (Hom (po-cat 𝕊) A B)}{g : el (Hom (po-cat 𝕊) B A)} → A ≅ B
open Poset public renaming (𝕊 to poset-cat)
_≇_ : {l : Level}{A B : Set l} → (a : A) → (b : B) → Set l
a ≇ b = (a ≅ b → ⊥)
postulate eq-dec : ∀{l}{A B : Set l} → (a : A) → (b : B) → a ≅ b ⊎ a ≇ b
PosetCat : {l : Level} → (J : Poset {l}) → Cat {l}
PosetCat J = (po-cat (poset-cat J))
PosetObj : {l : Level} → (J : Poset {l}) → Set l
PosetObj J = Obj (PosetCat J)
|
{
"alphanum_fraction": 0.527333894,
"avg_line_length": 30.4871794872,
"ext": "agda",
"hexsha": "9cad590b0dcfda5a8fe772da7448f5c497f75460",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "setoid-cats/Category/Poset.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "setoid-cats/Category/Poset.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "setoid-cats/Category/Poset.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 354,
"size": 1189
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Setoids.Setoids
module Setoids.Functions.Definition {a b c d : _} {A : Set a} {B : Set b} where
WellDefined : (S : Setoid {a} {c} A) (T : Setoid {b} {d} B) (f : A → B) → Set (a ⊔ c ⊔ d)
WellDefined S T f = {x y : A} → Setoid._∼_ S x y → Setoid._∼_ T (f x) (f y)
|
{
"alphanum_fraction": 0.5994832041,
"avg_line_length": 38.7,
"ext": "agda",
"hexsha": "1f04e6cf67ffdfe1c4f7918233f83c1853a59384",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Setoids/Functions/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": "Setoids/Functions/Definition.agda",
"max_line_length": 89,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Setoids/Functions/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": 154,
"size": 387
}
|
{-# OPTIONS --without-K #-}
open import HoTT
open import cohomology.FunctionOver
module cohomology.TwoPushouts where
-- g h
-- B --> C --> D K = A ⊔^B C / (f,g) d₁ = A <- B -> C
-- f| | | L = K ⊔^C D / (left,h) d₂ = K <- C -> D
-- v v v d = A <- B -> D
-- A --> K --> L
--
module TwoPushoutsEquiv {i j k l} {A : Type i} {B : Type j} {C : Type k}
{D : Type l} (f : B → A) (g : B → C) (h : C → D) where
private
d₁ : Span
d₁ = span A C B f g
d₂ : Span
d₂ = span (Pushout d₁) D C right h
d : Span
d = span A D B f (h ∘ g)
module Inner = PushoutRec {d = d₁} {D = Pushout d}
left
(right ∘ h)
glue
module Into = PushoutRec {d = d} {D = Pushout d₂}
(left ∘ left)
right
(λ b → ap left (glue b) ∙ glue (g b))
into : Pushout d -> Pushout d₂
into = Into.f
module Out = PushoutRec {d = d₂} {D = Pushout d}
Inner.f
right
(λ _ → idp)
out : Pushout d₂ → Pushout d
out = Out.f
private
square-extend-tr : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ b : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} (q : a₁₀ == b)
→ Square p₀₋ p₋₀ p₋₁ p₁₋
→ Square p₀₋ (p₋₀ ∙ q) p₋₁ (! q ∙' p₁₋)
square-extend-tr idp ids = ids
square-corner-bl : ∀ {i} {A : Type i} {a₀ a₁ : A} (q : a₀ == a₁)
→ Square (! q) idp q idp
square-corner-bl idp = ids
into-inner : (k : Pushout d₁) → into (Inner.f k) == left k
into-inner = Pushout-elim
(λ a → idp)
(λ c → ! (glue c))
(λ b → ↓-='-from-square $
(ap-∘ into Inner.f (glue b)
∙ ap (ap into) (Inner.glue-β b) ∙ Into.glue-β b)
∙v⊡ square-extend-tr (glue (g b)) vid-square)
abstract
into-out : (l : Pushout d₂) → into (out l) == l
into-out = Pushout-elim
into-inner
(λ d → idp)
(λ c → ↓-∘=idf-from-square into out $
ap (ap into) (Out.glue-β c) ∙v⊡ square-corner-bl (glue c))
out-into : (l : Pushout d) → out (into l) == l
out-into = Pushout-elim
(λ a → idp)
(λ d → idp)
(λ b → ↓-∘=idf-from-square out into $ vert-degen-square $
ap out (ap into (glue b))
=⟨ ap (ap out) (Into.glue-β b) ⟩
ap out (ap left (glue b) ∙ glue (g b))
=⟨ ap-∙ out (ap left (glue b)) (glue (g b)) ⟩
ap out (ap left (glue b)) ∙ ap out (glue (g b))
=⟨ ∘-ap out left (glue b) |in-ctx (λ w → w ∙ ap out (glue (g b))) ⟩
ap Inner.f (glue b) ∙ ap out (glue (g b))
=⟨ Out.glue-β (g b) |in-ctx (λ w → ap Inner.f (glue b) ∙ w) ⟩
ap Inner.f (glue b) ∙ idp
=⟨ ∙-unit-r _ ⟩
ap Inner.f (glue b)
=⟨ Inner.glue-β b ⟩
glue b ∎)
two-pushouts-equiv : Pushout d ≃ Pushout d₂
two-pushouts-equiv = equiv into out into-out out-into
two-pushouts : Lift {j = lmax l (lmax k (lmax j i))} (Pushout d) == Pushout d₂
two-pushouts = ua (two-pushouts-equiv ∘e lift-equiv)
two-pushouts-left : lift ∘ left == left ∘ left
[ (λ E → (A → E)) ↓ two-pushouts ]
two-pushouts-left = codomain-over-equiv _ _
two-pushouts-right : lift ∘ right == right [ (λ E → (D → E)) ↓ two-pushouts ]
two-pushouts-right = codomain-over-equiv _ _
two-pushouts-inner : lift ∘ Inner.f == left
[ (λ E → (Pushout d₁ → E)) ↓ two-pushouts ]
two-pushouts-inner = codomain-over-equiv _ _ ▹ λ= into-inner
-- g h
-- Y --> Z --> W K = X ⊔^Y Y / (f,g) ps₁ = X <- Y -> Z
-- f| | | L = Z ⊔^Z W / (left,h) ps₂ = K <- Z -> W
-- v v v ps = X <- Y -> W
-- X --> K --> L
--
module TwoPushoutsPtd {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}
(f : fst (Y ⊙→ X)) (g : fst (Y ⊙→ Z)) (h : fst (Z ⊙→ W)) where
private
ps₁ = ⊙span X Z Y f g
ps₂ = ⊙span (⊙Pushout ps₁) W Z (⊙right ps₁) h
ps = ⊙span X W Y f (h ⊙∘ g)
open TwoPushoutsEquiv (fst f) (fst g) (fst h) public
two-pushouts-ptd :
⊙Lift {j = lmax l (lmax k (lmax j i))} (⊙Pushout ps)
== ⊙Pushout ps₂
two-pushouts-ptd = ⊙ua (two-pushouts-equiv ∘e lift-equiv) idp
two-pushouts-⊙left :
⊙lift ⊙∘ ⊙left ps == ⊙left ps₂ ⊙∘ ⊙left ps₁
[ (λ V → fst (X ⊙→ V)) ↓ two-pushouts-ptd ]
two-pushouts-⊙left = codomain-over-⊙equiv _ _ _
two-pushouts-⊙right :
⊙lift ⊙∘ ⊙right ps == ⊙right ps₂
[ (λ V → fst (W ⊙→ V)) ↓ two-pushouts-ptd ]
two-pushouts-⊙right =
codomain-over-⊙equiv _ _ _ ▹ pair= idp (lemma f g h)
where
lemma : {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}
(f : fst (Y ⊙→ X)) (g : fst (Y ⊙→ Z)) (h : fst (Z ⊙→ W))
→ ap (TwoPushoutsEquiv.into (fst f) (fst g) (fst h)
∘ lower {j = lmax l (lmax k (lmax j i))})
(snd (⊙lift ⊙∘ ⊙right (⊙span X W Y f (h ⊙∘ g))))
∙ idp
== ap right (! (snd h)) ∙ ! (glue (snd Z))
∙' ap left (snd (⊙right (⊙span X Z Y f g)))
lemma {Y = Y} (f , idp) (g , idp) (h , idp) =
ap (2P.into ∘ lower) (ap lift (! (glue (snd Y))) ∙ idp) ∙ idp
=⟨ ∙-unit-r _ ⟩
ap (2P.into ∘ lower) (ap lift (! (glue (snd Y))) ∙ idp)
=⟨ ∙-unit-r _ |in-ctx (ap (2P.into ∘ lower)) ⟩
ap (2P.into ∘ lower) (ap lift (! (glue (snd Y))))
=⟨ ∘-ap (2P.into ∘ lower) lift _ ⟩
ap 2P.into (! (glue (snd Y)))
=⟨ ap-! 2P.into (glue (snd Y)) ⟩
! (ap 2P.into (glue (snd Y)))
=⟨ 2P.Into.glue-β (snd Y) |in-ctx ! ⟩
! (ap left (glue (snd Y)) ∙ glue (g (snd Y)))
=⟨ !-∙ (ap left (glue (snd Y))) (glue (g (snd Y))) ⟩
! (glue (g (snd Y))) ∙ ! (ap left (glue (snd Y)))
=⟨ !-ap left (glue (snd Y)) |in-ctx (λ w → ! (glue (g (snd Y))) ∙ w) ⟩
! (glue (g (snd Y))) ∙ ap left (! (glue (snd Y)))
=⟨ ∙=∙' (! (glue (g (snd Y)))) (ap left (! (glue (snd Y)))) ⟩
! (glue (g (snd Y))) ∙' ap left (! (glue (snd Y))) ∎
where
module 2P = TwoPushoutsEquiv f g h
two-pushouts-⊙inner : ⊙lift ⊙∘ (Inner.f , idp) == ⊙left ps₂
[ (λ V → fst (⊙Pushout ps₁ ⊙→ V)) ↓ two-pushouts-ptd ]
two-pushouts-⊙inner =
codomain-over-⊙equiv _ _ _ ▹ ⊙λ= into-inner idp
open TwoPushoutsEquiv
using (two-pushouts-equiv; two-pushouts; two-pushouts-left;
two-pushouts-right; two-pushouts-inner)
open TwoPushoutsPtd
using (two-pushouts-ptd; two-pushouts-⊙left; two-pushouts-⊙right;
two-pushouts-⊙inner)
|
{
"alphanum_fraction": 0.484307023,
"avg_line_length": 33.8736842105,
"ext": "agda",
"hexsha": "69d36c1e2abe9f19ea899e6864b877a5d0a8d00c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "cohomology/TwoPushouts.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "cohomology/TwoPushouts.agda",
"max_line_length": 80,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "cohomology/TwoPushouts.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 2665,
"size": 6436
}
|
data Foo : Set where
foo = Foo
-- Bad error message WAS:
-- A postulate block can only contain type signatures or instance blocks
|
{
"alphanum_fraction": 0.7368421053,
"avg_line_length": 22.1666666667,
"ext": "agda",
"hexsha": "f4c7e725cf8f10ebf8b52b08b4272547ca7f0713",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue1698-data.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue1698-data.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1698-data.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": 31,
"size": 133
}
|
{-# OPTIONS --without-K --safe #-}
module Definition.Typed.EqualityRelation where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Weakening using (_∷_⊆_)
-- Generic equality relation used with the logical relation
record EqRelSet : Set₁ where
constructor eqRel
field
---------------
-- Relations --
---------------
-- Equality of types
_⊢_≅_ : Con Term → (A B : Term) → Set
-- Equality of terms
_⊢_≅_∷_ : Con Term → (t u A : Term) → Set
-- Equality of neutral terms
_⊢_~_∷_ : Con Term → (t u A : Term) → Set
----------------
-- Properties --
----------------
-- Generic equality compatibility
~-to-≅ₜ : ∀ {k l A Γ}
→ Γ ⊢ k ~ l ∷ A
→ Γ ⊢ k ≅ l ∷ A
-- Judgmental conversion compatibility
≅-eq : ∀ {A B Γ}
→ Γ ⊢ A ≅ B
→ Γ ⊢ A ≡ B
≅ₜ-eq : ∀ {t u A Γ}
→ Γ ⊢ t ≅ u ∷ A
→ Γ ⊢ t ≡ u ∷ A
-- Universe
≅-univ : ∀ {A B Γ}
→ Γ ⊢ A ≅ B ∷ U
→ Γ ⊢ A ≅ B
-- Symmetry
≅-sym : ∀ {A B Γ} → Γ ⊢ A ≅ B → Γ ⊢ B ≅ A
≅ₜ-sym : ∀ {t u A Γ} → Γ ⊢ t ≅ u ∷ A → Γ ⊢ u ≅ t ∷ A
~-sym : ∀ {k l A Γ} → Γ ⊢ k ~ l ∷ A → Γ ⊢ l ~ k ∷ A
-- Transitivity
≅-trans : ∀ {A B C Γ} → Γ ⊢ A ≅ B → Γ ⊢ B ≅ C → Γ ⊢ A ≅ C
≅ₜ-trans : ∀ {t u v A Γ} → Γ ⊢ t ≅ u ∷ A → Γ ⊢ u ≅ v ∷ A → Γ ⊢ t ≅ v ∷ A
~-trans : ∀ {k l m A Γ} → Γ ⊢ k ~ l ∷ A → Γ ⊢ l ~ m ∷ A → Γ ⊢ k ~ m ∷ A
-- Conversion
≅-conv : ∀ {t u A B Γ} → Γ ⊢ t ≅ u ∷ A → Γ ⊢ A ≡ B → Γ ⊢ t ≅ u ∷ B
~-conv : ∀ {k l A B Γ} → Γ ⊢ k ~ l ∷ A → Γ ⊢ A ≡ B → Γ ⊢ k ~ l ∷ B
-- Weakening
≅-wk : ∀ {A B ρ Γ Δ}
→ ρ ∷ Δ ⊆ Γ
→ ⊢ Δ
→ Γ ⊢ A ≅ B
→ Δ ⊢ wk ρ A ≅ wk ρ B
≅ₜ-wk : ∀ {t u A ρ Γ Δ}
→ ρ ∷ Δ ⊆ Γ
→ ⊢ Δ
→ Γ ⊢ t ≅ u ∷ A
→ Δ ⊢ wk ρ t ≅ wk ρ u ∷ wk ρ A
~-wk : ∀ {k l A ρ Γ Δ}
→ ρ ∷ Δ ⊆ Γ
→ ⊢ Δ
→ Γ ⊢ k ~ l ∷ A
→ Δ ⊢ wk ρ k ~ wk ρ l ∷ wk ρ A
-- Weak head expansion
≅-red : ∀ {A A′ B B′ Γ}
→ Γ ⊢ A ⇒* A′
→ Γ ⊢ B ⇒* B′
→ Whnf A′
→ Whnf B′
→ Γ ⊢ A′ ≅ B′
→ Γ ⊢ A ≅ B
≅ₜ-red : ∀ {a a′ b b′ A B Γ}
→ Γ ⊢ A ⇒* B
→ Γ ⊢ a ⇒* a′ ∷ B
→ Γ ⊢ b ⇒* b′ ∷ B
→ Whnf B
→ Whnf a′
→ Whnf b′
→ Γ ⊢ a′ ≅ b′ ∷ B
→ Γ ⊢ a ≅ b ∷ A
-- Universe type reflexivity
≅-Urefl : ∀ {Γ} → ⊢ Γ → Γ ⊢ U ≅ U
-- Natural number type reflexivity
≅-ℕrefl : ∀ {Γ} → ⊢ Γ → Γ ⊢ ℕ ≅ ℕ
≅ₜ-ℕrefl : ∀ {Γ} → ⊢ Γ → Γ ⊢ ℕ ≅ ℕ ∷ U
-- Empty type reflexivity
≅-Emptyrefl : ∀ {Γ} → ⊢ Γ → Γ ⊢ Empty ≅ Empty
≅ₜ-Emptyrefl : ∀ {Γ} → ⊢ Γ → Γ ⊢ Empty ≅ Empty ∷ U
-- Unit type reflexivity
≅-Unitrefl : ∀ {Γ} → ⊢ Γ → Γ ⊢ Unit ≅ Unit
≅ₜ-Unitrefl : ∀ {Γ} → ⊢ Γ → Γ ⊢ Unit ≅ Unit ∷ U
-- Unit η-equality
≅ₜ-η-unit : ∀ {Γ e e'}
→ Γ ⊢ e ∷ Unit
→ Γ ⊢ e' ∷ Unit
→ Γ ⊢ e ≅ e' ∷ Unit
-- Π-congruence
≅-Π-cong : ∀ {F G H E Γ}
→ Γ ⊢ F
→ Γ ⊢ F ≅ H
→ Γ ∙ F ⊢ G ≅ E
→ Γ ⊢ Π F ▹ G ≅ Π H ▹ E
≅ₜ-Π-cong : ∀ {F G H E Γ}
→ Γ ⊢ F
→ Γ ⊢ F ≅ H ∷ U
→ Γ ∙ F ⊢ G ≅ E ∷ U
→ Γ ⊢ Π F ▹ G ≅ Π H ▹ E ∷ U
-- Σ-congruence
≅-Σ-cong : ∀ {F G H E Γ}
→ Γ ⊢ F
→ Γ ⊢ F ≅ H
→ Γ ∙ F ⊢ G ≅ E
→ Γ ⊢ Σ F ▹ G ≅ Σ H ▹ E
≅ₜ-Σ-cong : ∀ {F G H E Γ}
→ Γ ⊢ F
→ Γ ⊢ F ≅ H ∷ U
→ Γ ∙ F ⊢ G ≅ E ∷ U
→ Γ ⊢ Σ F ▹ G ≅ Σ H ▹ E ∷ U
-- Zero reflexivity
≅ₜ-zerorefl : ∀ {Γ} → ⊢ Γ → Γ ⊢ zero ≅ zero ∷ ℕ
-- Successor congruence
≅-suc-cong : ∀ {m n Γ} → Γ ⊢ m ≅ n ∷ ℕ → Γ ⊢ suc m ≅ suc n ∷ ℕ
-- η-equality
≅-η-eq : ∀ {f g F G Γ}
→ Γ ⊢ F
→ Γ ⊢ f ∷ Π F ▹ G
→ Γ ⊢ g ∷ Π F ▹ G
→ Function f
→ Function g
→ Γ ∙ F ⊢ wk1 f ∘ var 0 ≅ wk1 g ∘ var 0 ∷ G
→ Γ ⊢ f ≅ g ∷ Π F ▹ G
-- η for product types
≅-Σ-η : ∀ {p r F G Γ}
→ Γ ⊢ F
→ Γ ∙ F ⊢ G
→ Γ ⊢ p ∷ Σ F ▹ G
→ Γ ⊢ r ∷ Σ F ▹ G
→ Product p
→ Product r
→ Γ ⊢ fst p ≅ fst r ∷ F
→ Γ ⊢ snd p ≅ snd r ∷ G [ fst p ]
→ Γ ⊢ p ≅ r ∷ Σ F ▹ G
-- Variable reflexivity
~-var : ∀ {x A Γ} → Γ ⊢ var x ∷ A → Γ ⊢ var x ~ var x ∷ A
-- Application congruence
~-app : ∀ {a b f g F G Γ}
→ Γ ⊢ f ~ g ∷ Π F ▹ G
→ Γ ⊢ a ≅ b ∷ F
→ Γ ⊢ f ∘ a ~ g ∘ b ∷ G [ a ]
-- Product projections congruence
~-fst : ∀ {p r F G Γ}
→ Γ ⊢ F
→ Γ ∙ F ⊢ G
→ Γ ⊢ p ~ r ∷ Σ F ▹ G
→ Γ ⊢ fst p ~ fst r ∷ F
~-snd : ∀ {p r F G Γ}
→ Γ ⊢ F
→ Γ ∙ F ⊢ G
→ Γ ⊢ p ~ r ∷ Σ F ▹ G
→ Γ ⊢ snd p ~ snd r ∷ G [ fst p ]
-- Natural recursion congruence
~-natrec : ∀ {z z′ s s′ n n′ F F′ Γ}
→ Γ ∙ ℕ ⊢ F ≅ F′
→ Γ ⊢ z ≅ z′ ∷ F [ zero ]
→ Γ ⊢ s ≅ s′ ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)
→ Γ ⊢ n ~ n′ ∷ ℕ
→ Γ ⊢ natrec F z s n ~ natrec F′ z′ s′ n′ ∷ F [ n ]
-- Empty recursion congruence
~-Emptyrec : ∀ {n n′ F F′ Γ}
→ Γ ⊢ F ≅ F′
→ Γ ⊢ n ~ n′ ∷ Empty
→ Γ ⊢ Emptyrec F n ~ Emptyrec F′ n′ ∷ F
-- Star reflexivity
≅ₜ-starrefl : ∀ {Γ} → ⊢ Γ → Γ ⊢ star ≅ star ∷ Unit
≅ₜ-starrefl [Γ] = ≅ₜ-η-unit (starⱼ [Γ]) (starⱼ [Γ])
-- Composition of universe and generic equality compatibility
~-to-≅ : ∀ {k l Γ} → Γ ⊢ k ~ l ∷ U → Γ ⊢ k ≅ l
~-to-≅ k~l = ≅-univ (~-to-≅ₜ k~l)
≅-W-cong : ∀ {F G H E Γ} W
→ Γ ⊢ F
→ Γ ⊢ F ≅ H
→ Γ ∙ F ⊢ G ≅ E
→ Γ ⊢ ⟦ W ⟧ F ▹ G ≅ ⟦ W ⟧ H ▹ E
≅-W-cong BΠ = ≅-Π-cong
≅-W-cong BΣ = ≅-Σ-cong
≅ₜ-W-cong : ∀ {F G H E Γ} W
→ Γ ⊢ F
→ Γ ⊢ F ≅ H ∷ U
→ Γ ∙ F ⊢ G ≅ E ∷ U
→ Γ ⊢ ⟦ W ⟧ F ▹ G ≅ ⟦ W ⟧ H ▹ E ∷ U
≅ₜ-W-cong BΠ = ≅ₜ-Π-cong
≅ₜ-W-cong BΣ = ≅ₜ-Σ-cong
|
{
"alphanum_fraction": 0.3334403081,
"avg_line_length": 26.406779661,
"ext": "agda",
"hexsha": "e873435c91c7c39c5e95fb04774b75fe4b2a3249",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Vtec234/logrel-mltt",
"max_forks_repo_path": "Definition/Typed/EqualityRelation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Vtec234/logrel-mltt",
"max_issues_repo_path": "Definition/Typed/EqualityRelation.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Vtec234/logrel-mltt",
"max_stars_repo_path": "Definition/Typed/EqualityRelation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2851,
"size": 6232
}
|
module Oscar.Category.Morphism where
open import Oscar.Category.Setoid
open import Oscar.Level
open import Oscar.Property
open import Oscar.Data.Nat
record Morphism
{𝔬} (⋆ : Set 𝔬) 𝔪 𝔮
: Set (𝔬 ⊔ lsuc (𝔪 ⊔ 𝔮))
where
constructor #_
field
_⇒_ : ⋆ → ⋆ → Setoid 𝔪 𝔮
_↦_ : ⋆ → ⋆ → Set 𝔪
_↦_ x y = Setoid.⋆ (x ⇒ y)
infix 4 _≞_
_≞_ : ∀ {x y} → x ↦ y → x ↦ y → Set 𝔮
_≞_ {x} {y} = Setoid._≋_ (x ⇒ y)
instance IsSetoid↦ : ∀ {x y} → IsSetoid (_≞_ {x} {y})
IsSetoid↦ {x} {y} = Setoid.isSetoid (x ⇒ y)
-- IsSetoid↦ : ∀ {x y} → IsSetoid (x ↦ y) 𝔮
-- IsSetoid↦ {x} {y} = Setoid.isSetoid (x ⇒ y)
-- ⦃ isMorphism ⦄ : IsMorphism (λ {x} {y} → _≞_ {x} {y})
-- record Morphism 𝔬 𝔪 𝔮 : Set (lsuc (𝔬 ⊔ 𝔪 ⊔ 𝔮)) where
-- constructor ↑_
-- infix 4 _≞_
-- field
-- {⋆} : Set 𝔬
-- {_↦_} : ⋆ → ⋆ → Set 𝔪
-- _≞_ : ∀ {x y} → x ↦ y → x ↦ y → Set 𝔮
-- ⦃ isSetoid ⦄ : ∀ {x} {y} → IsSetoid (_≞_ {x} {y})
-- instance IsSetoid↦ : ∀ {x y} → IsSetoid (_≞_ {x} {y})
-- IsSetoid↦ {x} {y} = Setoid.isSetoid (x ⇒ y)
-- setoid : ∀ {x y} → Setoid 𝔪 𝔮
-- setoid {x} {y} = ↑ _≞_ {x} {y}
|
{
"alphanum_fraction": 0.4968722073,
"avg_line_length": 23.8085106383,
"ext": "agda",
"hexsha": "e8e0be3c0c5860468d5d7e02257b95dcc5add131",
"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-2/Oscar/Category/Morphism.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-2/Oscar/Category/Morphism.agda",
"max_line_length": 60,
"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-2/Oscar/Category/Morphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 588,
"size": 1119
}
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.Exact where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec)
open import Cubical.Algebra.Group.GroupPath
open import Cubical.Algebra.Group.Instances.Unit
-- TODO : Define exact sequences
-- (perhaps short, finite, ℕ-indexed and ℤ-indexed)
SES→isEquiv : ∀ {ℓ ℓ'} {L R : Group ℓ-zero}
→ {G : Group ℓ} {H : Group ℓ'}
→ Unit ≡ L
→ Unit ≡ R
→ (lhom : GroupHom L G) (midhom : GroupHom G H) (rhom : GroupHom H R)
→ ((x : _) → isInKer midhom x → isInIm lhom x)
→ ((x : _) → isInKer rhom x → isInIm midhom x)
→ isEquiv (fst midhom)
SES→isEquiv {R = R} {G = G} {H = H} =
J (λ L _ → Unit ≡ R →
(lhom : GroupHom L G) (midhom : GroupHom G H)
(rhom : GroupHom H R) →
((x : fst G) → isInKer midhom x → isInIm lhom x) →
((x : fst H) → isInKer rhom x → isInIm midhom x) →
isEquiv (fst midhom))
((J (λ R _ → (lhom : GroupHom Unit G) (midhom : GroupHom G H)
(rhom : GroupHom H R) →
((x : fst G) → isInKer midhom x → isInIm lhom x) →
((x : _) → isInKer rhom x → isInIm midhom x) →
isEquiv (fst midhom))
main))
where
main : (lhom : GroupHom Unit G) (midhom : GroupHom G H)
(rhom : GroupHom H Unit) →
((x : fst G) → isInKer midhom x → isInIm lhom x) →
((x : fst H) → isInKer rhom x → isInIm midhom x) →
isEquiv (fst midhom)
main lhom midhom rhom lexact rexact =
BijectionIsoToGroupEquiv {G = G} {H = H}
bijIso' .fst .snd
where
bijIso' : BijectionIso G H
BijectionIso.fun bijIso' = midhom
BijectionIso.inj bijIso' x inker =
pRec (GroupStr.is-set (snd G) _ _)
(λ s → sym (snd s) ∙ IsGroupHom.pres1 (snd lhom))
(lexact _ inker)
BijectionIso.surj bijIso' x = rexact x refl
|
{
"alphanum_fraction": 0.6032739528,
"avg_line_length": 37.7636363636,
"ext": "agda",
"hexsha": "c2fa70aff0d2068afb51bc5c8b06e99b6f8707d2",
"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": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "FernandoLarrain/cubical",
"max_forks_repo_path": "Cubical/Algebra/Group/Exact.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"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": "FernandoLarrain/cubical",
"max_issues_repo_path": "Cubical/Algebra/Group/Exact.agda",
"max_line_length": 71,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Algebra/Group/Exact.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T01:25:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-05T01:25:26.000Z",
"num_tokens": 707,
"size": 2077
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Monoidal.Construction.Minus2 where
-- Any -2-Category is Monoidal. Of course, One is Monoidal, but
-- we don't need to shrink to do this, it can be done directly.
-- The assumptions in the construction of a -2-Category are all
-- needed to make things work properly.
open import Data.Product using (proj₁; proj₂)
open import Categories.Minus2-Category
open import Categories.Category.Monoidal
import Categories.Morphism as M
-- Doing it manually is just as easy as going through Cartesian here
-2-Monoidal : ∀ {o ℓ e} → (C : -2-Category {o} {ℓ} {e}) → Monoidal (-2-Category.cat C)
-2-Monoidal C = record
{ ⊗ = record
{ F₀ = proj₁
; F₁ = proj₁
; identity = Hom-Conn
; homomorphism = Hom-Conn
; F-resp-≈ = λ _ → Hom-Conn
}
; unit = proj₁ Obj-Contr
; unitorˡ = λ {X} → proj₂ Obj-Contr X
; unitorʳ = M.≅.refl cat
; associator = M.≅.refl cat
; unitorˡ-commute-from = Hom-Conn
; unitorˡ-commute-to = Hom-Conn
; unitorʳ-commute-from = Hom-Conn
; unitorʳ-commute-to = Hom-Conn
; assoc-commute-from = Hom-Conn
; assoc-commute-to = Hom-Conn
; triangle = Hom-Conn
; pentagon = Hom-Conn
}
where
open -2-Category C
|
{
"alphanum_fraction": 0.6701954397,
"avg_line_length": 29.9512195122,
"ext": "agda",
"hexsha": "5c8d655828961c270eeeb76b4d5291097b569bf0",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Monoidal/Construction/Minus2.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Monoidal/Construction/Minus2.agda",
"max_line_length": 86,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Monoidal/Construction/Minus2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 406,
"size": 1228
}
|
{-# OPTIONS --without-K #-}
open import Base
open import Homotopy.PushoutDef
-- Suspension is defined as a particular case of pushout
module Spaces.Suspension {i} (A : Set i) where
suspension-diag : pushout-diag i
suspension-diag = diag unit , unit , A , (λ _ → tt) , (λ _ → tt)
suspension : Set i
suspension = pushout suspension-diag
north : suspension
north = left tt
south : suspension
south = right tt
paths : A → north ≡ south
paths x = glue x
suspension-rec : ∀ {j} (P : suspension → Set j) (n : P north) (s : P south)
(p : (x : A) → transport P (paths x) n ≡ s) → ((x : suspension) → P x)
suspension-rec P n s p = pushout-rec P (λ _ → n) (λ _ → s) p
suspension-β-paths : ∀ {j} (P : suspension → Set j) (n : P north) (s : P south)
(p : (x : A) → transport P (paths x) n ≡ s)
→ ((x : A) → apd (suspension-rec P n s p) (paths x) ≡ p x)
suspension-β-paths P n s p =
pushout-β-glue P (λ _ → n) (λ _ → s) p
suspension-rec-nondep : ∀ {j} (C : Set j) (n s : C) (p : A → n ≡ s)
→ (suspension → C)
suspension-rec-nondep C n s p =
pushout-rec-nondep C (λ _ → n) (λ _ → s) p
suspension-β-paths-nondep : ∀ {j} (C : Set j) (n s : C) (p : A → n ≡ s)
→ ((x : A) → ap (suspension-rec-nondep C n s p) (paths x) ≡ p x)
suspension-β-paths-nondep C n s p =
pushout-β-glue-nondep C (λ _ → n) (λ _ → s) p
|
{
"alphanum_fraction": 0.5937737282,
"avg_line_length": 29.9318181818,
"ext": "agda",
"hexsha": "e8e544d0ae466f74c40f45f9d2615db422ba1ccd",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Spaces/Suspension.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Spaces/Suspension.agda",
"max_line_length": 79,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "old/Spaces/Suspension.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": 516,
"size": 1317
}
|
{-# OPTIONS --safe #-}
module JVM.Contexts where
open import JVM.Types
open import Relation.Ternary.Construct.List.Overlapping Ty public
renaming
( overlap-rel to ctx-rel
; overlap-commutative to ctx-commutative
; overlap-semigroup to ctx-semigroup
; overlap-monoid to ctx-monoid)
|
{
"alphanum_fraction": 0.7375415282,
"avg_line_length": 25.0833333333,
"ext": "agda",
"hexsha": "57c03b4c341a1bb31fabe833e57f54941b744ca5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ajrouvoet/jvm.agda",
"max_forks_repo_path": "src/JVM/Contexts.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ajrouvoet/jvm.agda",
"max_issues_repo_path": "src/JVM/Contexts.agda",
"max_line_length": 65,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ajrouvoet/jvm.agda",
"max_stars_repo_path": "src/JVM/Contexts.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-28T21:49:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T14:07:17.000Z",
"num_tokens": 74,
"size": 301
}
|
{-# OPTIONS --no-qualified-instances #-}
module JVM.Printer where
open import Function
open import Data.Bool
open import Data.Product hiding (swap)
open import Data.List as L
open import Data.List.Relation.Unary.Any
open import Data.Nat as N
open import Data.Nat.Show as Nat
open import Data.Fin
open import Data.String as S
open import Relation.Unary
open import Relation.Ternary.Core
open import Relation.Ternary.Structures
open import Relation.Ternary.Structures.Syntax hiding (_∣_)
open import Relation.Binary.PropositionalEquality
open import Relation.Ternary.Monad
open import JVM.Types
open import JVM.Contexts using (indexOf)
open import JVM.Syntax.Values
open import JVM.Syntax.Instructions as I hiding (Instr)
open import JVM.Printer.Printer StackTy
open import JVM.Printer.Jasmin as J hiding (procedure)
private
module _ {T : Set} where
open import JVM.Model T public
const-instr : Const a → Instr
const-instr Const.null = aconst_null
const-instr (num x) = sipush x
const-instr (bool false) = iconst0
const-instr (bool true) = iconst1
load-instr : Ty → ℕ → Instr
load-instr (ref _) = aload
load-instr (array _) = iload
load-instr int = iload
load-instr boolean = iload
load-instr byte = iload
load-instr short = iload
load-instr long = iload
load-instr char = iload
store-instr : Ty → ℕ → Instr
store-instr (ref _) = astore
store-instr (array _) = aastore
store-instr int = istore
store-instr boolean = istore
store-instr byte = istore
store-instr short = istore
store-instr long = istore
store-instr char = istore
bop-instr : NativeBinOp a b c → Instr
bop-instr add = iadd
bop-instr sub = isub
bop-instr mul = imul
bop-instr div = idiv
bop-instr xor = ixor
if-instr : ∀ {as} → I.Comparator as → String → Instr
if-instr eq = if eq
if-instr ne = if ne
if-instr lt = if lt
if-instr ge = if ge
if-instr gt = if gt
if-instr le = if le
if-instr icmpge = if icmpge
if-instr icmpgt = if icmpgt
if-instr icmpeq = if icmpeq
if-instr icmpne = if icmpne
if-instr icmplt = if icmplt
if-instr icmple = if icmple
module _ {𝑭} where
prettyᵢ : ∀ {ψ₁ ψ₂} → ∀[ Down ⟨ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟩ ⇒ Printer Emp ]
prettyᵢ (↓ noop) = print (instr nop)
prettyᵢ (↓ pop) = print (instr pop)
prettyᵢ (↓ dup) = print (instr dup)
prettyᵢ (↓ swap) = print (instr swap)
prettyᵢ (↓ (push x)) = print (instr (const-instr x))
prettyᵢ (↓ (bop x)) = print (instr (bop-instr x))
prettyᵢ (↓ (load {a = a} r)) = do
print (instr (load-instr a (toℕ $ index r)))
prettyᵢ (↓ (store {a = a} r)) = do
print (instr (store-instr a (toℕ $ index r)))
prettyᵢ (↓ (goto x)) = do
emp n ← lookDown (↓ x)
print (instr (goto (Nat.show n)))
prettyᵢ (↓ (if c x)) = do
emp n ← lookDown (↓ x)
print (instr (if-instr c (Nat.show n)))
import JVM.Syntax.Bytecode.Printer ⟨ 𝑭 ∣_↝_⟩ prettyᵢ as Printer
pretty : ∀ {ψ₁ ψ₂ Φ} → ⟪ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟫ Φ → List Stat
pretty bc = execPrinter (Printer.pretty bc)
procedure : ∀ {ψ₁ ψ₂ Φ} → String → ⟪ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟫ Φ → Jasmin
procedure name bc = J.procedure name (L.length 𝑭) 10 (pretty bc)
|
{
"alphanum_fraction": 0.6781461217,
"avg_line_length": 29.3113207547,
"ext": "agda",
"hexsha": "6151fc2aa25aa7e514e4d55cda132d5f889f2a9f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ajrouvoet/jvm.agda",
"max_forks_repo_path": "src/JVM/Printer.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ajrouvoet/jvm.agda",
"max_issues_repo_path": "src/JVM/Printer.agda",
"max_line_length": 66,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ajrouvoet/jvm.agda",
"max_stars_repo_path": "src/JVM/Printer.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-28T21:49:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T14:07:17.000Z",
"num_tokens": 1073,
"size": 3107
}
|
module Generic.Test.Data where
open import Generic.Test.Data.Fin public
open import Generic.Test.Data.Lift public
open import Generic.Test.Data.Product public
open import Generic.Test.Data.List public
open import Generic.Test.Data.Maybe public
open import Generic.Test.Data.Vec public
open import Generic.Test.Data.W public
|
{
"alphanum_fraction": 0.7780979827,
"avg_line_length": 34.7,
"ext": "agda",
"hexsha": "ba4a48ad7c28f16054ad6d3c4d1431634ebbeb34",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z",
"max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Test/Data.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "turion/Generic",
"max_issues_repo_path": "src/Generic/Test/Data.agda",
"max_line_length": 44,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Test/Data.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z",
"num_tokens": 71,
"size": 347
}
|
-- binary search trees (not balanced)
open import bool
open import bool-thms2
open import eq
open import maybe
open import product
open import product-thms
open import bool-relations using (transitive ; total)
module z05-01-bst (A : Set) -- type of elements
(_≤A_ : A → A → 𝔹) -- ordering function
(≤A-trans : transitive _≤A_) -- proof of transitivity of given ordering
(≤A-total : total _≤A_) -- proof of totality of given ordering
where
{-
IAL
- relations.agda
- models binary relation on A as functions from A to A to Set
- bool-relations.agda
- models binary realtion on A as functions from A to A to 𝔹
Cannot use A→A→Set relations here because code cannot manipulate types.
But code can pattern match on values of type 𝔹, so boolean relations more useful.
-}
open import bool-relations _≤A_ hiding (transitive ; total)
open import minmax _≤A_ ≤A-trans ≤A-total
-- able to store values in bounds 'l' and 'u'
-- l(ower) bound
-- | u(upper) bound
-- v v
data bst : A → A → Set where
bst-leaf : ∀ {l u : A}
→ l ≤A u ≡ tt
→ bst l u
bst-node : ∀ {l l' u' u : A}
→ (d : A) -- value stored in this node
→ bst l' d -- left subtree of values ≤ stored value
→ bst d u' -- right subtree of values ≥ stored value
→ l ≤A l' ≡ tt
→ u' ≤A u ≡ tt
→ bst l u
------------------------------------------------------------------------------
bst-search : ∀ {l u : A}
→ (d : A) -- find a node that is isomorphic (_=A_) to d
→ bst l u
→ maybe (Σ A (λ d' → d iso𝔹 d' ≡ tt)) -- return that node or nothing
bst-search d (bst-leaf _) = nothing -- could return proof not in tree instead
-- compare given element with stored element
bst-search d (bst-node d' L R _ _) with keep (d ≤A d')
-- compare given element with stored element (other direction)
bst-search d (bst-node d' L R _ _) | tt , p1 with keep (d' ≤A d)
-- both are true implying iso, so return that element and proof
bst-search d (bst-node d' L R _ _) | tt , p1 | tt , p2 = just (d' , iso𝔹-intro p1 p2)
-- if either is false then search the appropriate branch
bst-search d (bst-node d' L R _ _) | tt , p1 | ff , p2 = bst-search d L -- search in left
bst-search d (bst-node d' L R _ _) | ff , p1 = bst-search d R -- search in right
------------------------------------------------------------------------------
-- change the lower bound from l' to l
bst-dec-lb : ∀ {l l' u' : A}
→ bst l' u'
→ l ≤A l' ≡ tt
→ bst l u'
bst-dec-lb (bst-leaf p) q = bst-leaf (≤A-trans q p)
bst-dec-lb (bst-node d L R p1 p2) q = bst-node d L R (≤A-trans q p1) p2
-- change the upper bound from u' to u
bst-inc-ub : ∀ {l' u' u : A}
→ bst l' u'
→ u' ≤A u ≡ tt
→ bst l' u
bst-inc-ub (bst-leaf p) q = bst-leaf (≤A-trans p q)
bst-inc-ub (bst-node d L R p1 p2) q = bst-node d L R p1 (≤A-trans p2 q)
bst-insert : ∀{l u : A}
→ (d : A) -- insert 'd'
→ bst l u -- into this 'bst'
→ bst (min d l) (max d u) -- type might change
bst-insert d (bst-leaf p) =
bst-node d (bst-leaf ≤A-refl) (bst-leaf ≤A-refl) min-≤1 max-≤1
bst-insert d (bst-node d' L R p1 p2) with keep (d ≤A d')
bst-insert d (bst-node d' L R p1 p2) | tt , p with bst-insert d L
bst-insert d (bst-node d' L R p1 p2) | tt , p | L' rewrite p =
bst-node d' L' (bst-inc-ub R (≤A-trans p2 max-≤2))
(min2-mono p1) ≤A-refl
bst-insert d (bst-node d' L R p1 p2) | ff , p with bst-insert d R
bst-insert d (bst-node d' L R p1 p2) | ff , p | R' rewrite p =
bst-node d' (bst-dec-lb L p1) R'
min-≤2 (max2-mono p2)
|
{
"alphanum_fraction": 0.5272030651,
"avg_line_length": 39.9489795918,
"ext": "agda",
"hexsha": "dccd7c84e870aee124d2542f0fb23fc0d7b2e3a4",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-bst.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-bst.agda",
"max_line_length": 94,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-bst.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 1218,
"size": 3915
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of unnormalized Rational numbers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Rational.Unnormalised.Properties where
open import Algebra
import Algebra.Consequences.Setoid as FC
open import Algebra.Consequences.Propositional
open import Data.Nat.Base using (suc)
import Data.Nat.Properties as ℕ
open import Data.Integer.Base as ℤ using (ℤ; +0; +[1+_]; 0ℤ; 1ℤ)
open import Data.Integer.Solver renaming (module +-*-Solver to ℤ-solver)
import Data.Integer.Properties as ℤ
import Data.Integer.Properties
open import Data.Rational.Unnormalised
open import Data.Product using (_,_)
open import Data.Sum.Base using ([_,_]′; inj₁; inj₂)
open import Function.Base using (_on_; _$_; _∘_)
open import Level using (0ℓ)
open import Relation.Nullary using (yes; no)
import Relation.Nullary.Decidable as Dec
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Algebra.Properties.CommutativeSemigroup ℤ.*-commutativeSemigroup
------------------------------------------------------------------------
-- Properties of ↥_ and ↧_
------------------------------------------------------------------------
↥↧≡⇒≡ : ∀ {p q} → ↥ p ≡ ↥ q → ↧ₙ p ≡ ↧ₙ q → p ≡ q
↥↧≡⇒≡ refl refl = refl
------------------------------------------------------------------------
-- Properties of _≃_
------------------------------------------------------------------------
drop-*≡* : ∀ {p q} → p ≃ q → ↥ p ℤ.* ↧ q ≡ ↥ q ℤ.* ↧ p
drop-*≡* (*≡* eq) = eq
≃-refl : Reflexive _≃_
≃-refl = *≡* refl
≃-reflexive : _≡_ ⇒ _≃_
≃-reflexive refl = *≡* refl
≃-sym : Symmetric _≃_
≃-sym (*≡* eq) = *≡* (sym eq)
≃-trans : Transitive _≃_
≃-trans {x} {y} {z} (*≡* ad≡cb) (*≡* cf≡ed) =
*≡* (ℤ.*-cancelʳ-≡ (↥ x ℤ.* ↧ z) (↥ z ℤ.* ↧ x) (↧ y) (λ()) (begin
↥ x ℤ.* ↧ z ℤ.* ↧ y ≡⟨ xy∙z≈xz∙y (↥ x) _ _ ⟩
↥ x ℤ.* ↧ y ℤ.* ↧ z ≡⟨ cong (ℤ._* ↧ z) ad≡cb ⟩
↥ y ℤ.* ↧ x ℤ.* ↧ z ≡⟨ xy∙z≈xz∙y (↥ y) _ _ ⟩
↥ y ℤ.* ↧ z ℤ.* ↧ x ≡⟨ cong (ℤ._* ↧ x) cf≡ed ⟩
↥ z ℤ.* ↧ y ℤ.* ↧ x ≡⟨ xy∙z≈xz∙y (↥ z) _ _ ⟩
↥ z ℤ.* ↧ x ℤ.* ↧ y ∎))
where open ≡-Reasoning
_≃?_ : Decidable _≃_
p ≃? q = Dec.map′ *≡* drop-*≡* (↥ p ℤ.* ↧ q ℤ.≟ ↥ q ℤ.* ↧ p)
≃-isEquivalence : IsEquivalence _≃_
≃-isEquivalence = record
{ refl = ≃-refl
; sym = ≃-sym
; trans = ≃-trans
}
≃-isDecEquivalence : IsDecEquivalence _≃_
≃-isDecEquivalence = record
{ isEquivalence = ≃-isEquivalence
; _≟_ = _≃?_
}
≃-setoid : Setoid 0ℓ 0ℓ
≃-setoid = record
{ isEquivalence = ≃-isEquivalence
}
≃-decSetoid : DecSetoid 0ℓ 0ℓ
≃-decSetoid = record
{ isDecEquivalence = ≃-isDecEquivalence
}
------------------------------------------------------------------------
-- Properties of _≤_
------------------------------------------------------------------------
-- Relational properties
drop-*≤* : ∀ {p q} → p ≤ q → (↥ p ℤ.* ↧ q) ℤ.≤ (↥ q ℤ.* ↧ p)
drop-*≤* (*≤* pq≤qp) = pq≤qp
≤-reflexive : _≃_ ⇒ _≤_
≤-reflexive (*≡* eq) = *≤* (ℤ.≤-reflexive eq)
≤-refl : Reflexive _≤_
≤-refl = ≤-reflexive ≃-refl
≤-trans : Transitive _≤_
≤-trans {i = p@(mkℚᵘ n₁ d₁-1)} {j = q@(mkℚᵘ n₂ d₂-1)} {k = r@(mkℚᵘ n₃ d₃-1)} (*≤* eq₁) (*≤* eq₂)
= let d₁ = ↧ p; d₂ = ↧ q; d₃ = ↧ r in *≤* $
ℤ.*-cancelʳ-≤-pos (n₁ ℤ.* d₃) (n₃ ℤ.* d₁) d₂-1 $ begin
(n₁ ℤ.* d₃) ℤ.* d₂ ≡⟨ ℤ.*-assoc n₁ d₃ d₂ ⟩
n₁ ℤ.* (d₃ ℤ.* d₂) ≡⟨ cong (n₁ ℤ.*_) (ℤ.*-comm d₃ d₂) ⟩
n₁ ℤ.* (d₂ ℤ.* d₃) ≡⟨ sym (ℤ.*-assoc n₁ d₂ d₃) ⟩
(n₁ ℤ.* d₂) ℤ.* d₃ ≤⟨ ℤ.*-monoʳ-≤-pos d₃-1 eq₁ ⟩
(n₂ ℤ.* d₁) ℤ.* d₃ ≡⟨ cong (ℤ._* d₃) (ℤ.*-comm n₂ d₁) ⟩
(d₁ ℤ.* n₂) ℤ.* d₃ ≡⟨ ℤ.*-assoc d₁ n₂ d₃ ⟩
d₁ ℤ.* (n₂ ℤ.* d₃) ≤⟨ ℤ.*-monoˡ-≤-pos d₁-1 eq₂ ⟩
d₁ ℤ.* (n₃ ℤ.* d₂) ≡⟨ sym (ℤ.*-assoc d₁ n₃ d₂) ⟩
(d₁ ℤ.* n₃) ℤ.* d₂ ≡⟨ cong (ℤ._* d₂) (ℤ.*-comm d₁ n₃) ⟩
(n₃ ℤ.* d₁) ℤ.* d₂ ∎
where open ℤ.≤-Reasoning
≤-antisym : Antisymmetric _≃_ _≤_
≤-antisym (*≤* le₁) (*≤* le₂) = *≡* (ℤ.≤-antisym le₁ le₂)
≤-total : Total _≤_
≤-total p q = [ inj₁ ∘ *≤* , inj₂ ∘ *≤* ]′ (ℤ.≤-total
(↥ p ℤ.* ↧ q)
(↥ q ℤ.* ↧ p))
infix 4 _≤?_
_≤?_ : Decidable _≤_
p ≤? q = Dec.map′ *≤* drop-*≤* (↥ p ℤ.* ↧ q ℤ.≤? ↥ q ℤ.* ↧ p)
≤-irrelevant : Irrelevant _≤_
≤-irrelevant (*≤* p≤q₁) (*≤* p≤q₂) = cong *≤* (ℤ.≤-irrelevant p≤q₁ p≤q₂)
------------------------------------------------------------------------
-- 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
≤-decTotalOrder : DecTotalOrder 0ℓ 0ℓ 0ℓ
≤-decTotalOrder = record
{ isDecTotalOrder = ≤-isDecTotalOrder
}
------------------------------------------------------------------------
-- Properties of _+_
------------------------------------------------------------------------
------------------------------------------------------------------------
-- Raw bundles
+-rawMagma : RawMagma 0ℓ 0ℓ
+-rawMagma = record
{ _≈_ = _≃_
; _∙_ = _+_
}
+-rawMonoid : RawMonoid 0ℓ 0ℓ
+-rawMonoid = record
{ _≈_ = _≃_
; _∙_ = _+_
; ε = 0ℚᵘ
}
+-0-rawGroup : RawGroup 0ℓ 0ℓ
+-0-rawGroup = record
{ Carrier = ℚᵘ
; _≈_ = _≃_
; _∙_ = _+_
; ε = 0ℚᵘ
; _⁻¹ = -_
}
+-*-rawRing : RawRing 0ℓ 0ℓ
+-*-rawRing = record
{ Carrier = ℚᵘ
; _≈_ = _≃_
; _+_ = _+_
; _*_ = _*_
; -_ = -_
; 0# = 0ℚᵘ
; 1# = 1ℚᵘ
}
------------------------------------------------------------------------
-- Algebraic properties
-- Congruence
+-cong : Congruent₂ _≃_ _+_
+-cong {x} {y} {u} {v} (*≡* ab′∼a′b) (*≡* cd′∼c′d) = *≡* (begin
(↥x ℤ.* ↧u ℤ.+ ↥u ℤ.* ↧x) ℤ.* (↧y ℤ.* ↧v) ≡⟨ solve 6 (λ ↥x ↧x ↧y ↥u ↧u ↧v →
(↥x :* ↧u :+ ↥u :* ↧x) :* (↧y :* ↧v) :=
(↥x :* ↧y :* (↧u :* ↧v)) :+ ↥u :* ↧v :* (↧x :* ↧y))
refl (↥ x) (↧ x) (↧ y) (↥ u) (↧ u) (↧ v) ⟩
↥x ℤ.* ↧y ℤ.* (↧u ℤ.* ↧v) ℤ.+ ↥u ℤ.* ↧v ℤ.* (↧x ℤ.* ↧y) ≡⟨ cong₂ ℤ._+_ (cong (ℤ._* (↧u ℤ.* ↧v)) ab′∼a′b)
(cong (ℤ._* (↧x ℤ.* ↧y)) cd′∼c′d) ⟩
↥y ℤ.* ↧x ℤ.* (↧u ℤ.* ↧v) ℤ.+ ↥v ℤ.* ↧u ℤ.* (↧x ℤ.* ↧y) ≡⟨ solve 6 (λ ↧x ↥y ↧y ↧u ↥v ↧v →
(↥y :* ↧x :* (↧u :* ↧v)) :+ ↥v :* ↧u :* (↧x :* ↧y) :=
(↥y :* ↧v :+ ↥v :* ↧y) :* (↧x :* ↧u))
refl (↧ x) (↥ y) (↧ y) (↧ u) (↥ v) (↧ v) ⟩
(↥y ℤ.* ↧v ℤ.+ ↥v ℤ.* ↧y) ℤ.* (↧x ℤ.* ↧u) ∎)
where
↥x = ↥ x; ↧x = ↧ x; ↥y = ↥ y; ↧y = ↧ y; ↥u = ↥ u; ↧u = ↧ u; ↥v = ↥ v; ↧v = ↧ v
open ≡-Reasoning
open ℤ-solver
-- Associativity
+-assoc-↥ : Associative (_≡_ on ↥_) _+_
+-assoc-↥ p q r = solve 6 (λ ↥p ↧p ↥q ↧q ↥r ↧r →
(↥p :* ↧q :+ ↥q :* ↧p) :* ↧r :+ ↥r :* (↧p :* ↧q) :=
↥p :* (↧q :* ↧r) :+ (↥q :* ↧r :+ ↥r :* ↧q) :* ↧p)
refl (↥ p) (↧ p) (↥ q) (↧ q) (↥ r) (↧ r)
where open ℤ-solver
+-assoc-↧ : Associative (_≡_ on ↧ₙ_) _+_
+-assoc-↧ p q r = ℕ.*-assoc (↧ₙ p) (↧ₙ q) (↧ₙ r)
+-assoc-≡ : Associative _≡_ _+_
+-assoc-≡ p q r = ↥↧≡⇒≡ (+-assoc-↥ p q r) (+-assoc-↧ p q r)
+-assoc : Associative _≃_ _+_
+-assoc p q r = ≃-reflexive (+-assoc-≡ p q r)
-- Commutativity
+-comm-↥ : Commutative (_≡_ on ↥_) _+_
+-comm-↥ p q = ℤ.+-comm (↥ p ℤ.* ↧ q) (↥ q ℤ.* ↧ p)
+-comm-↧ : Commutative (_≡_ on ↧ₙ_) _+_
+-comm-↧ p q = ℕ.*-comm (↧ₙ p) (↧ₙ q)
+-comm-≡ : Commutative _≡_ _+_
+-comm-≡ p q = ↥↧≡⇒≡ (+-comm-↥ p q) (+-comm-↧ p q)
+-comm : Commutative _≃_ _+_
+-comm p q = ≃-reflexive (+-comm-≡ p q)
-- Identities
+-identityˡ-↥ : LeftIdentity (_≡_ on ↥_) 0ℚᵘ _+_
+-identityˡ-↥ p = begin
0ℤ ℤ.* ↧ p ℤ.+ ↥ p ℤ.* 1ℤ ≡⟨ cong₂ ℤ._+_ (ℤ.*-zeroˡ (↧ p)) (ℤ.*-identityʳ (↥ p)) ⟩
0ℤ ℤ.+ ↥ p ≡⟨ ℤ.+-identityˡ (↥ p) ⟩
↥ p ∎
where open ≡-Reasoning
+-identityˡ-↧ : LeftIdentity (_≡_ on ↧ₙ_) 0ℚᵘ _+_
+-identityˡ-↧ p = ℕ.+-identityʳ (↧ₙ p)
+-identityˡ-≡ : LeftIdentity _≡_ 0ℚᵘ _+_
+-identityˡ-≡ p = ↥↧≡⇒≡ (+-identityˡ-↥ p) (+-identityˡ-↧ p)
+-identityˡ : LeftIdentity _≃_ 0ℚᵘ _+_
+-identityˡ p = ≃-reflexive (+-identityˡ-≡ p)
+-identityʳ-≡ : RightIdentity _≡_ 0ℚᵘ _+_
+-identityʳ-≡ = comm+idˡ⇒idʳ +-comm-≡ {e = 0ℚᵘ} +-identityˡ-≡
+-identityʳ : RightIdentity _≃_ 0ℚᵘ _+_
+-identityʳ p = ≃-reflexive (+-identityʳ-≡ p)
+-identity-≡ : Identity _≡_ 0ℚᵘ _+_
+-identity-≡ = +-identityˡ-≡ , +-identityʳ-≡
+-identity : Identity _≃_ 0ℚᵘ _+_
+-identity = +-identityˡ , +-identityʳ
+-inverseˡ : LeftInverse _≃_ 0ℚᵘ -_ _+_
+-inverseˡ p = *≡* let n = ↥ p; d = ↧ p in
((ℤ.- n) ℤ.* d ℤ.+ n ℤ.* d) ℤ.* 1ℤ ≡⟨ ℤ.*-identityʳ ((ℤ.- n) ℤ.* d ℤ.+ n ℤ.* d) ⟩
(ℤ.- n) ℤ.* d ℤ.+ n ℤ.* d ≡˘⟨ cong (ℤ._+ (n ℤ.* d)) (ℤ.neg-distribˡ-* n d) ⟩
ℤ.- (n ℤ.* d) ℤ.+ n ℤ.* d ≡⟨ ℤ.+-inverseˡ (n ℤ.* d) ⟩
0ℤ ∎ where open ≡-Reasoning
+-inverseʳ : RightInverse _≃_ 0ℚᵘ -_ _+_
+-inverseʳ p = *≡* let n = ↥ p; d = ↧ p in
(n ℤ.* d ℤ.+ (ℤ.- n) ℤ.* d) ℤ.* 1ℤ ≡⟨ ℤ.*-identityʳ (n ℤ.* d ℤ.+ (ℤ.- n) ℤ.* d) ⟩
n ℤ.* d ℤ.+ (ℤ.- n) ℤ.* d ≡˘⟨ cong (λ n+d → n ℤ.* d ℤ.+ n+d) (ℤ.neg-distribˡ-* n d) ⟩
n ℤ.* d ℤ.+ ℤ.- (n ℤ.* d) ≡⟨ ℤ.+-inverseʳ (n ℤ.* d) ⟩
0ℤ ∎ where open ≡-Reasoning
+-inverse : Inverse _≃_ 0ℚᵘ -_ _+_
+-inverse = +-inverseˡ , +-inverseʳ
-‿cong : Congruent₁ _≃_ (-_)
-‿cong {p} {q} (*≡* p≡q) = *≡* (begin
↥(- p) ℤ.* ↧ q ≡˘⟨ ℤ.*-identityˡ (ℤ.-(↥ p) ℤ.* ↧ q) ⟩
1ℤ ℤ.* (↥(- p) ℤ.* ↧ q) ≡⟨ sym (ℤ.*-assoc 1ℤ (↥(- p)) (↧ q)) ⟩
(1ℤ ℤ.* ℤ.-(↥ p)) ℤ.* ↧ q ≡˘⟨ cong (ℤ._* ↧ q) (ℤ.neg-distribʳ-* 1ℤ (↥ p)) ⟩
ℤ.-(1ℤ ℤ.* ↥ p) ℤ.* ↧ q ≡⟨ cong (ℤ._* ↧ q) (ℤ.neg-distribˡ-* 1ℤ (↥ p)) ⟩
((ℤ.- 1ℤ) ℤ.* ↥ p) ℤ.* ↧ q ≡⟨ ℤ.*-assoc (ℤ.- 1ℤ) (↥ p) (↧ q) ⟩
ℤ.- 1ℤ ℤ.* (↥ p ℤ.* ↧ q) ≡⟨ cong (λ r → ℤ.- 1ℤ ℤ.* r) p≡q ⟩
ℤ.- 1ℤ ℤ.* (↥ q ℤ.* ↧ p) ≡⟨ sym (ℤ.*-assoc (ℤ.- 1ℤ) (↥ q) (↧ p)) ⟩
(ℤ.- 1ℤ ℤ.* ↥ q) ℤ.* ↧ p ≡˘⟨ cong (ℤ._* ↧ p) (ℤ.neg-distribˡ-* 1ℤ (↥ q)) ⟩
ℤ.-(1ℤ ℤ.* ↥ q) ℤ.* ↧ p ≡⟨ cong (ℤ._* ↧ p) (ℤ.neg-distribʳ-* 1ℤ (↥ q)) ⟩
(1ℤ ℤ.* ↥(- q)) ℤ.* ↧ p ≡⟨ ℤ.*-assoc 1ℤ (ℤ.-(↥ q)) (↧ p) ⟩
1ℤ ℤ.* (↥(- q) ℤ.* ↧ p) ≡⟨ ℤ.*-identityˡ (↥(- q) ℤ.* ↧ p) ⟩
↥(- q) ℤ.* ↧ p ∎) where open ≡-Reasoning
------------------------------------------------------------------------
-- Algebraic structures
+-isMagma : IsMagma _≃_ _+_
+-isMagma = record
{ isEquivalence = ≃-isEquivalence
; ∙-cong = +-cong
}
+-isSemigroup : IsSemigroup _≃_ _+_
+-isSemigroup = record
{ isMagma = +-isMagma
; assoc = +-assoc
}
+-0-isMonoid : IsMonoid _≃_ _+_ 0ℚᵘ
+-0-isMonoid = record
{ isSemigroup = +-isSemigroup
; identity = +-identity
}
+-0-isCommutativeMonoid : IsCommutativeMonoid _≃_ _+_ 0ℚᵘ
+-0-isCommutativeMonoid = record
{ isMonoid = +-0-isMonoid
; comm = +-comm
}
+-0-isGroup : IsGroup _≃_ _+_ 0ℚᵘ (-_)
+-0-isGroup = record
{ isMonoid = +-0-isMonoid
; inverse = +-inverse
; ⁻¹-cong = -‿cong
}
+-0-isAbelianGroup : IsAbelianGroup _≃_ _+_ 0ℚᵘ (-_)
+-0-isAbelianGroup = record
{ isGroup = +-0-isGroup
; comm = +-comm
}
------------------------------------------------------------------------
-- Algebraic bundles
+-magma : Magma 0ℓ 0ℓ
+-magma = record
{ isMagma = +-isMagma
}
+-semigroup : Semigroup 0ℓ 0ℓ
+-semigroup = record
{ isSemigroup = +-isSemigroup
}
+-0-monoid : Monoid 0ℓ 0ℓ
+-0-monoid = record
{ isMonoid = +-0-isMonoid
}
+-0-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
+-0-commutativeMonoid = record
{ isCommutativeMonoid = +-0-isCommutativeMonoid
}
+-0-group : Group 0ℓ 0ℓ
+-0-group = record
{ isGroup = +-0-isGroup
}
+-0-abelianGroup : AbelianGroup 0ℓ 0ℓ
+-0-abelianGroup = record
{ isAbelianGroup = +-0-isAbelianGroup
}
------------------------------------------------------------------------
-- Properties of _*_
------------------------------------------------------------------------
------------------------------------------------------------------------
-- Raw bundles
*-rawMagma : RawMagma 0ℓ 0ℓ
*-rawMagma = record
{ _≈_ = _≃_
; _∙_ = _*_
}
*-rawMonoid : RawMonoid 0ℓ 0ℓ
*-rawMonoid = record
{ _≈_ = _≃_
; _∙_ = _*_
; ε = 1ℚᵘ
}
------------------------------------------------------------------------
-- Algebraic properties
*-cong : Congruent₂ _≃_ _*_
*-cong {x} {y} {u} {v} (*≡* ↥x↧y≡↥y↧x) (*≡* ↥u↧v≡↥v↧u) = *≡* (begin
(↥ x ℤ.* ↥ u) ℤ.* (↧ y ℤ.* ↧ v) ≡⟨ solve 4 (λ ↥x ↥u ↧y ↧v →
(↥x :* ↥u) :* (↧y :* ↧v) :=
(↥u :* ↧v) :* (↥x :* ↧y))
refl (↥ x) (↥ u) (↧ y) (↧ v) ⟩
(↥ u ℤ.* ↧ v) ℤ.* (↥ x ℤ.* ↧ y) ≡⟨ cong₂ ℤ._*_ ↥u↧v≡↥v↧u ↥x↧y≡↥y↧x ⟩
(↥ v ℤ.* ↧ u) ℤ.* (↥ y ℤ.* ↧ x) ≡⟨ solve 4 (λ ↥v ↧u ↥y ↧x →
(↥v :* ↧u) :* (↥y :* ↧x) :=
(↥y :* ↥v) :* (↧x :* ↧u))
refl (↥ v) (↧ u) (↥ y) (↧ x) ⟩
(↥ y ℤ.* ↥ v) ℤ.* (↧ x ℤ.* ↧ u) ∎)
where open ≡-Reasoning; open ℤ-solver
-- Associativity
*-assoc-↥ : Associative (_≡_ on ↥_) _*_
*-assoc-↥ p q r = ℤ.*-assoc (↥ p) (↥ q) (↥ r)
*-assoc-↧ : Associative (_≡_ on ↧ₙ_) _*_
*-assoc-↧ p q r = ℕ.*-assoc (↧ₙ p) (↧ₙ q) (↧ₙ r)
*-assoc-≡ : Associative _≡_ _*_
*-assoc-≡ p q r = ↥↧≡⇒≡ (*-assoc-↥ p q r) (*-assoc-↧ p q r)
*-assoc : Associative _≃_ _*_
*-assoc p q r = ≃-reflexive (*-assoc-≡ p q r)
-- Commutativity
*-comm-↥ : Commutative (_≡_ on ↥_) _*_
*-comm-↥ p q = ℤ.*-comm (↥ p) (↥ q)
*-comm-↧ : Commutative (_≡_ on ↧ₙ_) _*_
*-comm-↧ p q = ℕ.*-comm (↧ₙ p) (↧ₙ q)
*-comm-≡ : Commutative _≡_ _*_
*-comm-≡ p q = ↥↧≡⇒≡ (*-comm-↥ p q) (*-comm-↧ p q)
*-comm : Commutative _≃_ _*_
*-comm p q = ≃-reflexive (*-comm-≡ p q)
-- Identities
*-identityˡ-≡ : LeftIdentity _≡_ 1ℚᵘ _*_
*-identityˡ-≡ p = ↥↧≡⇒≡ (ℤ.*-identityˡ (↥ p)) (ℕ.+-identityʳ (↧ₙ p))
*-identityʳ-≡ : RightIdentity _≡_ 1ℚᵘ _*_
*-identityʳ-≡ = comm+idˡ⇒idʳ *-comm-≡ {e = 1ℚᵘ} *-identityˡ-≡
*-identity-≡ : Identity _≡_ 1ℚᵘ _*_
*-identity-≡ = *-identityˡ-≡ , *-identityʳ-≡
*-identityˡ : LeftIdentity _≃_ 1ℚᵘ _*_
*-identityˡ p = ≃-reflexive (*-identityˡ-≡ p)
*-identityʳ : RightIdentity _≃_ 1ℚᵘ _*_
*-identityʳ p = ≃-reflexive (*-identityʳ-≡ p)
*-identity : Identity _≃_ 1ℚᵘ _*_
*-identity = *-identityˡ , *-identityʳ
*-zeroˡ : LeftZero _≃_ 0ℚᵘ _*_
*-zeroˡ p = *≡* refl
*-zeroʳ : RightZero _≃_ 0ℚᵘ _*_
*-zeroʳ = FC.comm+zeˡ⇒zeʳ ≃-setoid *-comm *-zeroˡ
*-zero : Zero _≃_ 0ℚᵘ _*_
*-zero = *-zeroˡ , *-zeroʳ
*-distribˡ-+ : _DistributesOverˡ_ _≃_ _*_ _+_
*-distribˡ-+ p q r =
let ↥p = ↥ p; ↧p = ↧ p
↥q = ↥ q; ↧q = ↧ q
↥r = ↥ r; ↧r = ↧ r
eq : (↥p ℤ.* (↥q ℤ.* ↧r ℤ.+ ↥r ℤ.* ↧q)) ℤ.* (↧p ℤ.* ↧q ℤ.* (↧p ℤ.* ↧r)) ≡
(↥p ℤ.* ↥q ℤ.* (↧p ℤ.* ↧r) ℤ.+ ↥p ℤ.* ↥r ℤ.* (↧p ℤ.* ↧q)) ℤ.* (↧p ℤ.* (↧q ℤ.* ↧r))
eq = solve 6 (λ ↥p ↧p ↥q d e f →
(↥p :* (↥q :* f :+ e :* d)) :* (↧p :* d :* (↧p :* f)) :=
(↥p :* ↥q :* (↧p :* f) :+ ↥p :* e :* (↧p :* d)) :* (↧p :* (d :* f)))
refl ↥p ↧p ↥q ↧q ↥r ↧r
in *≡* eq where open ℤ-solver
*-distribʳ-+ : _DistributesOverʳ_ _≃_ _*_ _+_
*-distribʳ-+ = FC.comm+distrˡ⇒distrʳ ≃-setoid +-cong *-comm *-distribˡ-+
*-distrib-+ : _DistributesOver_ _≃_ _*_ _+_
*-distrib-+ = *-distribˡ-+ , *-distribʳ-+
------------------------------------------------------------------------
-- Algebraic structures
*-isMagma : IsMagma _≃_ _*_
*-isMagma = record
{ isEquivalence = ≃-isEquivalence
; ∙-cong = *-cong
}
*-isSemigroup : IsSemigroup _≃_ _*_
*-isSemigroup = record
{ isMagma = *-isMagma
; assoc = *-assoc
}
*-1-isMonoid : IsMonoid _≃_ _*_ 1ℚᵘ
*-1-isMonoid = record
{ isSemigroup = *-isSemigroup
; identity = *-identity
}
*-1-isCommutativeMonoid : IsCommutativeMonoid _≃_ _*_ 1ℚᵘ
*-1-isCommutativeMonoid = record
{ isMonoid = *-1-isMonoid
; comm = *-comm
}
+-*-isRing : IsRing _≃_ _+_ _*_ -_ 0ℚᵘ 1ℚᵘ
+-*-isRing = record
{ +-isAbelianGroup = +-0-isAbelianGroup
; *-isMonoid = *-1-isMonoid
; distrib = *-distrib-+
; zero = *-zero
}
+-*-isCommutativeRing : IsCommutativeRing _≃_ _+_ _*_ -_ 0ℚᵘ 1ℚᵘ
+-*-isCommutativeRing = record
{ isRing = +-*-isRing
; *-comm = *-comm
}
------------------------------------------------------------------------
-- Algebraic bundles
*-magma : Magma 0ℓ 0ℓ
*-magma = record
{ isMagma = *-isMagma
}
*-semigroup : Semigroup 0ℓ 0ℓ
*-semigroup = record
{ isSemigroup = *-isSemigroup
}
*-1-monoid : Monoid 0ℓ 0ℓ
*-1-monoid = record
{ isMonoid = *-1-isMonoid
}
*-1-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
*-1-commutativeMonoid = record
{ isCommutativeMonoid = *-1-isCommutativeMonoid
}
+-*-ring : Ring 0ℓ 0ℓ
+-*-ring = record
{ isRing = +-*-isRing
}
+-*-commutativeRing : CommutativeRing 0ℓ 0ℓ
+-*-commutativeRing = record
{ isCommutativeRing = +-*-isCommutativeRing
}
|
{
"alphanum_fraction": 0.4440433213,
"avg_line_length": 29.5279187817,
"ext": "agda",
"hexsha": "6f7316f0eb549cd26801f79a9e9ef91d3c97ac24",
"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/Rational/Unnormalised/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/Rational/Unnormalised/Properties.agda",
"max_line_length": 114,
"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/Rational/Unnormalised/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": 8490,
"size": 17451
}
|
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
data Maybe (A : Set) : Set where
nothing : Maybe A
just : A → Maybe A
postulate
String : Set
{-# BUILTIN STRING String #-}
infix 1000 ♯_
postulate
∞ : ∀ {a} (A : Set a) → Set a
♯_ : ∀ {a} {A : Set a} → A → ∞ A
♭ : ∀ {a} {A : Set a} → ∞ A → A
{-# BUILTIN INFINITY ∞ #-}
{-# BUILTIN SHARP ♯_ #-}
{-# BUILTIN FLAT ♭ #-}
infixr 5 _∷_
data Colist (A : Set) : Set where
[] : Colist A
_∷_ : (x : A) (xs : ∞ (Colist A)) → Colist A
postulate
Char : Set
{-# BUILTIN CHAR Char #-}
Costring : Set
Costring = Colist Char
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
data List {a} (A : Set a) : Set a where
[] : List A
_∷_ : (x : A) (xs : List A) → List A
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _∷_ #-}
private
primitive
primStringAppend : String → String → String
primStringToList : String → List Char
primStringFromList : List Char → String
infixr 5 _++_
_++_ : String → String → String
_++_ = primStringAppend
toList : String → List Char
toList = primStringToList
fromList : List Char → String
fromList = primStringFromList
fromListToColist : {A : Set} → List A → Colist A
fromListToColist [] = []
fromListToColist (x ∷ xs) = x ∷ ♯ fromListToColist xs
toCostring : String → Costring
toCostring s = fromListToColist (toList s)
------------------------------------------------------------------------
costringToString : Costring → ℕ → Maybe String
costringToString [] _ = just ""
costringToString (x ∷ xs) 0 with ♭ xs
... | [] = just (fromList (x ∷ []))
... | _ ∷ _ = nothing
costringToString (x ∷ xs) (suc n) with costringToString (♭ xs) n
... | nothing = nothing
... | just xs′ = just (fromList (x ∷ []) ++ xs′)
test0 : costringToString (toCostring "") 0 ≡ just ""
test0 = refl
test1 : costringToString (toCostring "apa") 3 ≡ just "apa"
test1 = refl
|
{
"alphanum_fraction": 0.5665301945,
"avg_line_length": 21.2391304348,
"ext": "agda",
"hexsha": "2946f41ff48068156969fd2d2ee891a64e79f978",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Succeed/Issue1323.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"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": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Succeed/Issue1323.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/Issue1323.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": 678,
"size": 1954
}
|
module Everything where
import Holes.Prelude
import Holes.Term
import Holes.Cong.Limited
import Holes.Cong.General
import Holes.Cong.Propositional
|
{
"alphanum_fraction": 0.8513513514,
"avg_line_length": 18.5,
"ext": "agda",
"hexsha": "dd247a36fbcca2466a0a3cc93ec5e2d08ebb3acb",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-02-02T18:57:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-01-27T14:57:39.000Z",
"max_forks_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-holes",
"max_forks_repo_path": "Everything.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_issues_repo_issues_event_max_datetime": "2020-08-31T20:58:33.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-16T10:47:58.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bch29/agda-holes",
"max_issues_repo_path": "Everything.agda",
"max_line_length": 31,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-holes",
"max_stars_repo_path": "Everything.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-03T15:02:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-01-28T10:56:46.000Z",
"num_tokens": 39,
"size": 148
}
|
module Issue118Comment9 where
open import Common.Level
open import Common.Coinduction
data Box (A : Set) : Set where
[_] : A → Box A
postulate I : Set
data P : I → Set where
c : ∀ {i} → Box (∞ (P i)) → P i
F : ∀ {i} → P i → I
F (c x) = _
G : ∀ {i} → Box (∞ (P i)) → I
G [ x ] = _
mutual
f : ∀ {i} (x : P i) → P (F x)
f (c x) = c (g x)
g : ∀ {i} (x : Box (∞ (P i))) → Box (∞ (P (G x)))
g [ x ] = [ ♯ f (♭ x) ]
-- The code above type checks, but the termination checker should
-- complain because the inferred definitions of F and G are
-- F (c x) = G x and G [ x ] = F (♭ x), respectively.
-- 2011-04-12 freezing: now the meta-variables remain uninstantiated.
-- good.
|
{
"alphanum_fraction": 0.5433526012,
"avg_line_length": 19.7714285714,
"ext": "agda",
"hexsha": "359e2f56bb82bea98d2cca8d1c4675ae6765c536",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue118Comment9.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue118Comment9.agda",
"max_line_length": 69,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue118Comment9.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": 263,
"size": 692
}
|
{-# OPTIONS --without-K --safe #-}
module Dodo.Binary.Maximal where
-- Stdlib imports
open import Level using (Level; _⊔_)
open import Function using (_∘_)
open import Data.Product using (_,_; ∃-syntax)
open import Data.Empty using (⊥-elim)
open import Relation.Nullary using (¬_)
open import Relation.Unary using (Pred)
open import Relation.Binary using (Rel)
open import Relation.Binary using (Trichotomous; tri<; tri≈; tri>)
-- Local imports
open import Dodo.Unary.Equality
open import Dodo.Unary.Unique
open import Dodo.Binary.Equality
-- # Definitions #
maximal : ∀ {a ℓ : Level} {A : Set a}
→ Rel A ℓ
--------------
→ Pred A (a ⊔ ℓ)
maximal r = λ x → ¬ (∃[ y ] r x y)
-- # Properties #
module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {≈ : Rel A ℓ₁} {< : Rel A ℓ₂} where
max-unique-tri : Trichotomous ≈ < → Unique₁ ≈ (maximal <)
max-unique-tri tri {x} {y} ¬∃z[x<z] ¬∃z[y<z] with tri x y
... | tri< x<y _ _ = ⊥-elim (¬∃z[x<z] (y , x<y))
... | tri≈ _ x≈y _ = x≈y
... | tri> _ _ y<x = ⊥-elim (¬∃z[y<z] (x , y<x))
module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Rel A ℓ₁} {Q : Rel A ℓ₂} where
max-flips-⊆ : P ⊆₂ Q → maximal Q ⊆₁ maximal P
max-flips-⊆ P⊆Q = ⊆: lemma
where
lemma : maximal Q ⊆₁' maximal P
lemma x ¬∃zQxz (z , Pxz) = ¬∃zQxz (z , ⊆₂-apply P⊆Q Pxz)
module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Rel A ℓ₁} {Q : Rel A ℓ₂} where
max-preserves-⇔ : P ⇔₂ Q → maximal P ⇔₁ maximal Q
max-preserves-⇔ = ⇔₁-sym ∘ ⇔₁-compose-⇔₂ max-flips-⊆ max-flips-⊆
|
{
"alphanum_fraction": 0.5681233933,
"avg_line_length": 29.358490566,
"ext": "agda",
"hexsha": "20c5c2889eb20637c3f055250391b58e4596de46",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Binary/Maximal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Binary/Maximal.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Binary/Maximal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 627,
"size": 1556
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.NaturalTransformation.NaturalIsomorphism.Functors where
open import Level
open import Categories.Category
open import Categories.Category.Construction.Functors
open import Categories.Functor
open import Categories.NaturalTransformation.NaturalIsomorphism
import Categories.Morphism as Mor
private
variable
o ℓ e : Level
C D : Category o ℓ e
-- isomorphism in Functors category is the same as natural isomorphism
module _ {F G : Functor C D} where
open Mor (Functors C D)
Functors-iso⇒NI : F ≅ G → NaturalIsomorphism F G
Functors-iso⇒NI F≅G = record
{ F⇒G = from
; F⇐G = to
; iso = λ X → record
{ isoˡ = isoˡ
; isoʳ = isoʳ
}
}
where open Mor._≅_ F≅G
NI⇒Functors-iso : NaturalIsomorphism F G → F ≅ G
NI⇒Functors-iso α = record
{ from = F⇒G
; to = F⇐G
; iso = record
{ isoˡ = isoˡ (iso _)
; isoʳ = isoʳ (iso _)
}
}
where open NaturalIsomorphism α
open Mor.Iso
|
{
"alphanum_fraction": 0.6543330088,
"avg_line_length": 22.8222222222,
"ext": "agda",
"hexsha": "8e1f28a0754663009b77a71bbe9635ca4853269a",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/NaturalTransformation/NaturalIsomorphism/Functors.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/NaturalTransformation/NaturalIsomorphism/Functors.agda",
"max_line_length": 73,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/NaturalTransformation/NaturalIsomorphism/Functors.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 341,
"size": 1027
}
|
{-
Part 4: Higher inductive types
• Set quotients via HITs
• Propositional truncation
• A little synthetic homotopy theory
-}
{-# OPTIONS --cubical #-}
module Part4 where
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Int hiding (_+_)
open import Cubical.Data.Nat hiding (elim)
open import Cubical.Data.Prod hiding (map)
open import Part1
open import Part2
open import Part3
-- Another thing that Cubical Agda adds is the possibility to define
-- higher inductive types. These are just like normal Agda datatypes,
-- but they have also "higher" constructors specifying non-trivial
-- paths, square, cubes, etc. in the type. These give a nice way of
-- defining set quotiented types as well as higher dimensional types
-- quotiented by some arbitrary relation.
-- Let's start by looking at some set quotient examples. The following
-- definition of finite multisets is due to Vikraman Choudhury and
-- Marcelo Fiore.
infixr 5 _∷_
data FMSet (A : Type ℓ) : Type ℓ where
[] : FMSet A
_∷_ : (x : A) → (xs : FMSet A) → FMSet A
comm : (x y : A) (xs : FMSet A) → x ∷ y ∷ xs ≡ y ∷ x ∷ xs
trunc : (xs ys : FMSet A) (p q : xs ≡ ys) → p ≡ q
infixr 30 _++_
_++_ : ∀ (xs ys : FMSet A) → FMSet A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ xs ++ ys
comm x y xs i ++ ys = comm x y (xs ++ ys) i
trunc xs zs p q i j ++ ys =
trunc (xs ++ ys) (zs ++ ys) (λ k → p k ++ ys) (λ k → q k ++ ys) i j
unitl-++ : (xs : FMSet A) → [] ++ xs ≡ xs
unitl-++ xs = refl
unitr-++ : (xs : FMSet A) → xs ++ [] ≡ xs
unitr-++ [] = refl
unitr-++ (x ∷ xs) = cong (x ∷_) (unitr-++ xs)
unitr-++ (comm x y xs i) j = comm x y (unitr-++ xs j) i
unitr-++ (trunc xs ys p q i k) j =
trunc (unitr-++ xs j) (unitr-++ ys j)
(λ k → unitr-++ (p k) j) (λ k → unitr-++ (q k) j) i k
-- Filling the goals for comm and trunc quickly gets tiresome and
-- useful lemmas about eliminating into propositions are proved in
-- Cubical.HITs.FiniteMultiset. As we're proving an equality of a set
-- truncated type we can prove the trunc and comm cases once and for
-- all so that we only have to give cases for [] and _∷_ when
-- constructing a family of propositions. This is a very common
-- pattern when working with set truncated HITs: first define the HIT,
-- then prove special purpose recursors and eliminators for
-- eliminating into types of different h-levels. All definitions are
-- then written using these recursors and eliminators and one get very
-- short proofs.
-- A more efficient version of finite multisets based on association
-- lists can be found in Cubical.HITs.AssocList.Base. It looks like
-- this:
data AssocList (A : Type ℓ) : Type ℓ where
⟨⟩ : AssocList A
⟨_,_⟩∷_ : (a : A) (n : ℕ) (xs : AssocList A) → AssocList A
per : (a b : A) (m n : ℕ) (xs : AssocList A)
→ ⟨ a , m ⟩∷ ⟨ b , n ⟩∷ xs ≡ ⟨ b , n ⟩∷ ⟨ a , m ⟩∷ xs
agg : (a : A) (m n : ℕ) (xs : AssocList A)
→ ⟨ a , m ⟩∷ ⟨ a , n ⟩∷ xs ≡ ⟨ a , m + n ⟩∷ xs
del : (a : A) (xs : AssocList A) → ⟨ a , 0 ⟩∷ xs ≡ xs
trunc : (xs ys : AssocList A) (p q : xs ≡ ys) → p ≡ q
-- Programming and proving is more complicated with AssocList compared
-- to FMSet. This kind of example occurs everywhere in programming and
-- mathematics: one representation is easier to work with, but not
-- efficient, while another is efficient but difficult to work with.
-- Using the SIP we can get the best of both worlds (see
-- https://arxiv.org/abs/2009.05547 for details).
-- Another nice CS example of a HIT can be found in Cubical.Data.Queue
-- where we define a queue datastructure based on two lists. These
-- examples are all special cases of set quotients and are very useful
-- for programming and set level mathematics. We can define the
-- general form as:
data _/_ (A : Type ℓ) (R : A → A → Type ℓ') : Type (ℓ-max ℓ ℓ') where
[_] : A → A / R
eq/ : (a b : A) → R a b → [ a ] ≡ [ b ]
trunc : (a b : A / R) (p q : a ≡ b) → p ≡ q
-- It's sometimes easier to work directly with _/_ instead of defining
-- special HITs as one can reuse lemmas for _/_ instead of reproving
-- things. For example, general lemmas about eliminating into
-- propositions have already been proved for _/_.
-- Proving that _/_ is "effective" (for prop-valued relation), i.e. that
--
-- ((a b : A) → [ a ] ≡ [ b ] → R a b)
--
-- requires univalence for propositions (hPropExt).
-- Set quotients let us define things like in normal math:
ℤ : Type₀
ℤ = (ℕ × ℕ) / rel
where
rel : (ℕ × ℕ) → (ℕ × ℕ) → Type₀
rel (x₀ , y₀) (x₁ , y₁) = x₀ + y₁ ≡ x₁ + y₀
-- Another useful class of HITs are truncations, especially
-- propositional truncation:
data ∥_∥ (A : Type ℓ) : Type ℓ where
∣_∣ : A → ∥ A ∥
squash : ∀ (x y : ∥ A ∥) → x ≡ y
-- This lets us define mere existence:
∃ : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')
∃ A B = ∥ Σ A B ∥
-- This is very useful to specify things where existence is weaker
-- than Σ. This lets us define things like surjective functions or the
-- image of a map which we cannot define properly in pre-HoTT type
-- theory.
-- We can define the recursor by pattern-matching
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
-- And the eliminator then follows easily:
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 → transport (λ i → P (squash ∣ x ∣ a i)) (f x)) a
-- A very important point is that propositional truncation is proof
-- relevant, so even though the elements are all equal one can still
-- extract interesting information from them. A fun example is the
-- "cost monad" which can be found in Cubical.HITs.Cost. There we pair
-- A with ∥ ℕ ∥ and use the truncated number to count the number of
-- recursive calls in various functions. As the number is truncated it
-- doesn't affect any properties of the functions, but by running
-- concrete computations we can extract the number of calls.
-------------------------------------------------------------------------
-- Another source of HITs are inspired by topology
-- We can define the circle as the following simple data declaration:
data S¹ : Type₀ where
base : S¹
loop : base ≡ base
-- We can write functions on S¹ using pattern-matching:
double : S¹ → S¹
double base = base
double (loop i) = (loop ∙ loop) i
-- Note that loop takes an i : I argument. This is not very surprising
-- as it's a path base ≡ base, but it's an important difference to
-- HoTT. Having the native notion of equality be heterogeneous makes
-- it possible to quite directly define a general schema for a large
-- class of HITs (more or less all in the HoTT book, with the
-- exception for the Cauchy reals (I think?)).
-- Let's use univalence to compute some winding numbers on the
-- circle. We first define a family of types over the circle whos
-- fibers are the integers.
helix : S¹ → Type₀
helix base = Int
helix (loop i) = sucPath i
-- The loopspace of the circle
ΩS¹ : Type₀
ΩS¹ = base ≡ base
-- We can then define a function computing how many times we've looped
-- around the circle by:
winding : ΩS¹ → Int
winding p = subst helix p (pos 0)
-- This reduces just fine:
_ : winding (λ i → double ((loop ∙ loop) i)) ≡ pos 4
_ = refl
-- This would not reduce in HoTT as univalence is an axiom. Having
-- things compute makes it possible to substantially simplify many
-- proofs from HoTT in Cubical Agda, more about this later.
-- We can in fact prove that winding is an equivalence, this relies on
-- the encode-decode method and Egbert will go through the proof in
-- detail. For details about how this proof looks in Cubical Agda see:
--
-- Cubical.HITs.S1.Base
-- Complex multiplication on S¹, used in the Hopf fibration
_⋆_ : S¹ → S¹ → S¹
base ⋆ x = x
loop i ⋆ base = loop i
loop i ⋆ loop j =
hcomp (λ k → λ { (i = i0) → loop (j ∨ ~ k)
; (i = i1) → loop (j ∧ k)
; (j = i0) → loop (i ∨ ~ k)
; (j = i1) → loop (i ∧ k) })
base
-- We can define the Torus as:
data Torus : Type₀ where
point : Torus
line1 : point ≡ point
line2 : point ≡ point
square : PathP (λ i → line1 i ≡ line1 i) line2 line2
-- The square corresponds to the usual folding diagram from topology:
--
-- line1
-- p ----------> p
-- ^ ^
-- ¦ ¦
-- line2 ¦ ¦ line2
-- ¦ ¦
-- p ----------> p
-- line1
-- Proving that it is equivalent to two circles is pretty much trivial:
t2c : Torus → S¹ × S¹
t2c point = (base , base)
t2c (line1 i) = (loop i , base)
t2c (line2 j) = (base , loop j)
t2c (square i j) = (loop i , loop j)
c2t : S¹ × S¹ → Torus
c2t (base , base) = point
c2t (loop i , base) = line1 i
c2t (base , loop j) = line2 j
c2t (loop i , loop j) = square i j
c2t-t2c : (t : Torus) → c2t (t2c t) ≡ t
c2t-t2c point = refl
c2t-t2c (line1 _) = refl
c2t-t2c (line2 _) = refl
c2t-t2c (square _ _) = refl
t2c-c2t : (p : S¹ × S¹) → t2c (c2t p) ≡ p
t2c-c2t (base , base) = refl
t2c-c2t (base , loop _) = refl
t2c-c2t (loop _ , base) = refl
t2c-c2t (loop _ , loop _) = refl
-- Using univalence we get the following equality:
Torus≡S¹×S¹ : Torus ≡ S¹ × S¹
Torus≡S¹×S¹ = isoToPath (iso t2c c2t t2c-c2t c2t-t2c)
-- We can also directly compute winding numbers on the torus
windingTorus : point ≡ point → Int × Int
windingTorus l = ( winding (λ i → proj₁ (t2c (l i)))
, winding (λ i → proj₂ (t2c (l i))))
_ : windingTorus (line1 ∙ sym line2) ≡ (pos 1 , negsuc 0)
_ = refl
-- This proof turned out to be much more complicated in HoTT as
-- eliminators out of HITs don't compute definitionally for higher
-- constructors. In Cubical Agda this is not a problem as all cases
-- reduce definitionally.
-- We have many more topological examples in the library, including
-- Klein bottle, RP^n, higher spheres, suspensions, join, wedges,
-- smash product:
-- open import Cubical.HITs.KleinBottle
-- open import Cubical.HITs.RPn
-- open import Cubical.HITs.S2
-- open import Cubical.HITs.S3
-- open import Cubical.HITs.Susp
-- open import Cubical.HITs.Join
-- open import Cubical.HITs.Wedge
-- open import Cubical.HITs.SmashProduct
-- There's also a proof of the "3x3 lemma" for pushouts in less than
-- 200LOC. In HoTT-Agda this took about 3000LOC. For details see:
-- https://github.com/HoTT/HoTT-Agda/tree/master/theorems/homotopy/3x3
-- open import Cubical.HITs.Pushout
-- We also defined the Hopf fibration and proved that its total space
-- is S³ in about 300LOC:
-- open import Cubical.HITs.Hopf
-- There is also some integer cohomology:
-- open import Cubical.ZCohomology.Everything
-- To compute cohomology groups of various spaces we need a bunch of
-- interesting theorems: Freudenthal suspension theorem,
-- Mayer-Vietoris sequence...
-- For further references about doing synthetic algebraic topology in
-- Cubical Agda see:
-- Cubical Synthetic Homotopy Theory
-- Anders Mörtberg, Loïc Pujet
-- https://staff.math.su.se/anders.mortberg/papers/cubicalsynthetic.pdf
-- Synthetic Cohomology Theory in Cubical Agda
-- Guillaume Brunerie, Anders Mörtberg, Axel Ljungström.
-- https://staff.math.su.se/anders.mortberg/papers/zcohomology.pdf
--- The end! ---
|
{
"alphanum_fraction": 0.6482752552,
"avg_line_length": 34.8588957055,
"ext": "agda",
"hexsha": "d3e688e48827c8da0c3d9945dcdd071a6d5d29bb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-08-02T16:16:34.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-08-02T16:16:34.000Z",
"max_forks_repo_head_hexsha": "19d72759e18e05d2c509f62d23a998573270140c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "williamdemeo/EPIT-2020",
"max_forks_repo_path": "04-cubical-type-theory/material/Part4.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "19d72759e18e05d2c509f62d23a998573270140c",
"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": "williamdemeo/EPIT-2020",
"max_issues_repo_path": "04-cubical-type-theory/material/Part4.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "19d72759e18e05d2c509f62d23a998573270140c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "williamdemeo/EPIT-2020",
"max_stars_repo_path": "04-cubical-type-theory/material/Part4.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3683,
"size": 11364
}
|
data ⊤ : Set where tt : ⊤
postulate
IndexL : Set
Ordered : IndexL → Set
¬ho-shr-morph : IndexL → IndexL
pres-¬ord : ∀ ind → Ordered (¬ho-shr-morph ind)
¬ord-morph : ∀ ind → Ordered ind → Set
postulate tt' : ⊤
poo : ∀ ind → ¬ord-morph (¬ho-shr-morph ind) (pres-¬ord ind)
poo ind with tt | ¬ho-shr-morph ind
... | _ | _ = {!!}
|
{
"alphanum_fraction": 0.5543175487,
"avg_line_length": 22.4375,
"ext": "agda",
"hexsha": "4e4b8d1c9cc2df66631a2307100f318f82d7f1ca",
"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/Issue2771.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/Issue2771.agda",
"max_line_length": 60,
"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/Issue2771.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 136,
"size": 359
}
|
{-# OPTIONS --experimental-irrelevance #-}
{-# OPTIONS --universe-polymorphism #-}
module IrrelevantLevelToSet where
open import Imports.Level
-- should fail, because Set i /= Set j for i /= j, so i is not irrelevant in Set i
MySet : .(i : Level) -> Set (suc i)
MySet i = Set i
|
{
"alphanum_fraction": 0.6857142857,
"avg_line_length": 28,
"ext": "agda",
"hexsha": "4dc63128accbf3a15d9a8d69cb8822f6aee1d85b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/fail/IrrelevantLevelToSet.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "np/agda-git-experiment",
"max_issues_repo_path": "test/fail/IrrelevantLevelToSet.agda",
"max_line_length": 82,
"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/fail/IrrelevantLevelToSet.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": 78,
"size": 280
}
|
module Lam where
f
: {A : Set}
→ A
→ A
f x
= (λ y z → z) x x
g
: {A : Set}
→ A
→ A
g {A = A} x
= (λ (y' : A) (z : A) → z) x x
|
{
"alphanum_fraction": 0.3310344828,
"avg_line_length": 8.5294117647,
"ext": "agda",
"hexsha": "0480c257a4bc839469d67e66f03570ce6c1c8595",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-01T16:38:14.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-01T16:38:14.000Z",
"max_forks_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "msuperdock/agda-unused",
"max_forks_repo_path": "data/expression/Lam.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"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": "msuperdock/agda-unused",
"max_issues_repo_path": "data/expression/Lam.agda",
"max_line_length": 32,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "msuperdock/agda-unused",
"max_stars_repo_path": "data/expression/Lam.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-01T16:38:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-29T09:38:43.000Z",
"num_tokens": 82,
"size": 145
}
|
------------------------------------------------------------------------
-- Big-step semantics for the untyped λ-calculus
------------------------------------------------------------------------
module Lambda.Substitution.OneSemantics where
open import Codata.Musical.Notation
open import Data.Fin
open import Function
open import Data.Nat
open import Lambda.Syntax
open WHNF
open import Lambda.Substitution
-- Semantic domain. ⊥ represents non-termination.
data Sem (n : ℕ) : Set where
⊥ : Sem n
val : (v : Value n) → Sem n
-- Big-step semantics.
mutual
infix 4 _⇒_ _⇒?_
data _⇒_ {n} : Tm n → Sem n → Set where
val : ∀ {v} → ⌜ v ⌝ ⇒ val v
app : ∀ {t₁ t₂ t v s}
(t₁⇓ : t₁ ⇒? val (ƛ t))
(t₂⇓ : t₂ ⇒? val v)
(t₁t₂⇒ : t / sub ⌜ v ⌝ ⇒? s) →
t₁ · t₂ ⇒ s
·ˡ : ∀ {t₁ t₂}
(t₁⇑ : t₁ ⇒? ⊥) →
t₁ · t₂ ⇒ ⊥
·ʳ : ∀ {t₁ t₂ v}
(t₁⇓ : t₁ ⇒? val v)
(t₂⇑ : t₂ ⇒? ⊥) →
t₁ · t₂ ⇒ ⊥
-- Conditional coinduction: coinduction only for diverging
-- computations.
_⇒?_ : ∀ {n} → Tm n → Sem n → Set
t ⇒? ⊥ = ∞ (t ⇒ ⊥)
t ⇒? val v = t ⇒ val v
-- Example.
Ω-loops : Ω ⇒ ⊥
Ω-loops = app val val (♯ Ω-loops)
|
{
"alphanum_fraction": 0.4526143791,
"avg_line_length": 22.6666666667,
"ext": "agda",
"hexsha": "89570c1bbf3a43845e37c98811eeb7146e768ae3",
"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": "Lambda/Substitution/OneSemantics.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": "Lambda/Substitution/OneSemantics.agda",
"max_line_length": 72,
"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": "Lambda/Substitution/OneSemantics.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": 450,
"size": 1224
}
|
-- simulating streams by Nat -> A
module Stream where
data Bool : Set where
true : Bool
false : Bool
if_then_else_ : forall {A} -> Bool -> A -> A -> A
if true then t else e = t
if false then t else e = e
data Nat : Set where
zero : Nat
succ : Nat -> Nat
Stream : Set -> Set
Stream A = Nat -> A
_::_ : forall {A} -> A -> Stream A -> Stream A
_::_ a as zero = a
_::_ a as (succ n) = as n
map : forall {A B} -> (A -> B) -> Stream A -> Stream B
map f as n = f (as n)
head : forall {A} -> Stream A -> A
head as = as zero
tail : forall {A} -> Stream A -> Stream A
tail as n = as (succ n)
-- construct the stream a :: f a :: f (f a) :: ...
iterate : forall {A} -> (A -> A) -> A -> Stream A
iterate f a zero = a
iterate f a (succ n) = iterate f (f a) n
zipWith : forall {A B C} -> (A -> B -> C) -> Stream A -> Stream B -> Stream C
zipWith f as bs n = f (as n) (bs n)
-- merge with with
merge : forall {A} -> (A -> A -> Bool) -> Stream A -> Stream A -> Stream A
merge le as bs with le (head as) (head bs)
merge le as bs | true = head as :: merge le (tail as) bs
merge le as bs | false = head bs :: merge le as (tail bs)
{-
-- without with
merge' : forall {A} -> (A -> A -> Bool) -> Stream A -> Stream A -> Stream A
merge' le as bs = if le (head as) (head bs)
then (head as :: merge' le (tail as) bs)
else (head bs :: merge' le as (tail bs))
-}
-- BOTH VARIANTS OF MERGE ARE NOT STRUCTURALLY RECURSIVE
|
{
"alphanum_fraction": 0.5582822086,
"avg_line_length": 25.2931034483,
"ext": "agda",
"hexsha": "24fd31458eb682dddd4148b0694f7905a77dd1f0",
"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": "examples/outdated-and-incorrect/Termination/Stream.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": "examples/outdated-and-incorrect/Termination/Stream.agda",
"max_line_length": 77,
"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": "examples/outdated-and-incorrect/Termination/Stream.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": 480,
"size": 1467
}
|
{-# OPTIONS --warning=error --safe --guardedness --without-K #-}
open import LogicalFormulae
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Naturals
open import Numbers.Naturals.Order
open import Numbers.Naturals.EuclideanAlgorithm
open import Lists.Lists
open import Numbers.Primes.PrimeNumbers
open import Decidable.Relations
open import Numbers.BinaryNaturals.Definition
open import Numbers.BinaryNaturals.Addition
open import Numbers.BinaryNaturals.Order
open import Sequences
open import Vectors
open import Orders.Total.Definition
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Partial.Sequences
open import Setoids.Orders.Total.Definition
open import Setoids.Setoids
open import Functions.Definition
open import Semirings.Definition
module ProjectEuler.Problem2 where
fibUnary : ℕ → ℕ
fibUnary zero = 1
fibUnary (succ zero) = 1
fibUnary (succ (succ n)) = fibUnary (succ n) +N fibUnary n
fibUnaryStrictlyPositive : (a : ℕ) → 0 <N fibUnary a
fibUnaryStrictlyPositive zero = le zero refl
fibUnaryStrictlyPositive (succ zero) = le zero refl
fibUnaryStrictlyPositive (succ (succ a)) = addStrongInequalities (fibUnaryStrictlyPositive (succ a)) (fibUnaryStrictlyPositive a)
fibUnaryIncreasing : (a : ℕ) → (fibUnary (succ a)) <N (fibUnary (succ (succ a)))
fibUnaryIncreasing zero = le zero refl
fibUnaryIncreasing (succ a) = identityOfIndiscernablesLeft _<N_ (additionPreservesInequalityOnLeft (fibUnary (succ a) +N fibUnary a) (fibUnaryStrictlyPositive (succ a))) (Semiring.sumZeroRight ℕSemiring (fibUnary (succ a) +N fibUnary a))
fibUnaryBiggerThanN : (a : ℕ) → (succ (succ (succ (succ a)))) <N fibUnary (succ (succ (succ (succ a))))
fibUnaryBiggerThanN zero = le zero refl
fibUnaryBiggerThanN (succ a) = TotalOrder.<Transitive ℕTotalOrder (succPreservesInequality (fibUnaryBiggerThanN a)) (ans ((fibUnary (succ a) +N fibUnary a) +N fibUnary (succ a)) ans')
where
ans : {t : ℕ} → (u : ℕ) → 1 <N u → succ t <N t +N u
ans {t} u (le x proof) rewrite Semiring.commutative ℕSemiring x 1 = le x (transitivity (applyEquality succ (Semiring.commutative ℕSemiring x (succ t))) (transitivity (applyEquality (λ i → succ (succ i)) (Semiring.commutative ℕSemiring t x)) (transitivity (applyEquality (_+N t) proof) (Semiring.commutative ℕSemiring u t))))
ans' : 1 <N (fibUnary (succ a) +N fibUnary a) +N fibUnary (succ a)
ans' with fibUnaryStrictlyPositive (succ a)
... | fibPos with fibUnary (succ a)
ans' | fibPos | succ bl rewrite Semiring.commutative ℕSemiring (bl +N fibUnary a) (succ bl) = succPreservesInequality (le (bl +N (bl +N fibUnary a)) (Semiring.sumZeroRight ℕSemiring _))
fibUnaryArchimedean : (a : ℕ) → Sg ℕ (λ i → a <N fibUnary i)
fibUnaryArchimedean zero = 0 , le zero refl
fibUnaryArchimedean (succ zero) = 2 , le zero refl
fibUnaryArchimedean (succ (succ zero)) = 3 , le zero refl
fibUnaryArchimedean (succ (succ (succ zero))) = 4 , le 1 refl
fibUnaryArchimedean (succ (succ (succ (succ a)))) = (succ (succ (succ (succ a)))) , fibUnaryBiggerThanN a
record FibEntry : Set where
field
prev : BinNat
curr : BinNat
nextFib : FibEntry → FibEntry
nextFib record { prev = prev ; curr = curr } = record { prev = curr ; curr = prev +B curr }
fib : Sequence BinNat
fib = Sequences.map FibEntry.curr (unfold nextFib record { prev = NToBinNat 0 ; curr = NToBinNat 1 })
fibMove : (n : ℕ) → FibEntry.prev (index (unfold nextFib (record { prev = [] ; curr = one :: [] })) (succ n)) ≡ FibEntry.curr (index (unfold nextFib (record { prev = [] ; curr = one :: [] })) n)
fibMove zero = refl
fibMove (succ n) rewrite indexAndUnfold nextFib (record { prev = [] ; curr = one :: [] }) (succ n) = refl
fibAlternative : (N : ℕ) → index fib N ≡ FibEntry.curr (index (unfold nextFib (record { prev = [] ; curr = one :: [] })) N)
fibAlternative n rewrite equalityCommutative (mapAndIndex (unfold nextFib record { prev = NToBinNat 0 ; curr = NToBinNat 1 }) FibEntry.curr n) = refl
fibAlternative' : (n : ℕ) → FibEntry.curr (index (unfold nextFib (record { prev = [] ; curr = one :: [] })) (succ n)) ≡ FibEntry.prev (index (unfold nextFib (record { prev = [] ; curr = one :: [] })) n) +B FibEntry.curr (index (unfold nextFib (record { prev = [] ; curr = one :: [] })) n)
fibAlternative' zero = refl
fibAlternative' (succ n) rewrite indexAndUnfold nextFib (record { prev = [] ; curr = one :: [] }) (succ n) = refl
fibsCanonical : (n : ℕ) → canonical (index fib n) ≡ index fib n
fibsCanonical zero = refl
fibsCanonical (succ zero) = refl
fibsCanonical (succ (succ n)) = transitivity (applyEquality canonical {index fib (succ (succ n))} {FibEntry.prev (index (unfold nextFib (nextFib (record { prev = [] ; curr = one :: [] }))) n) +B FibEntry.curr (index (unfold nextFib (nextFib (record { prev = [] ; curr = one :: [] }))) n)} (transitivity (fibAlternative (succ (succ n))) (fibAlternative' (succ n)))) (transitivity (sumCanonical (FibEntry.prev (index (unfold nextFib (nextFib (record { prev = [] ; curr = one :: [] }))) n)) (FibEntry.curr (index (unfold nextFib (nextFib (record { prev = [] ; curr = one :: [] }))) n)) (transitivity (transitivity (applyEquality canonical (fibMove n)) (transitivity (applyEquality canonical (equalityCommutative (fibAlternative n))) (transitivity (fibsCanonical n) (fibAlternative n)))) (equalityCommutative (fibMove n))) (transitivity (applyEquality canonical (mapAndIndex (unfold nextFib (nextFib (record { prev = [] ; curr = one :: [] }))) FibEntry.curr n)) (transitivity (fibsCanonical (succ n)) (equalityCommutative (mapAndIndex (unfold nextFib (nextFib (record { prev = [] ; curr = one :: [] }))) FibEntry.curr n))))) (equalityCommutative (transitivity (fibAlternative (succ (succ n))) (fibAlternative' (succ n)))))
fibStart : take 5 fib ≡ vecMap NToBinNat (1 ,- 1 ,- 2 ,- 3 ,- 5 ,- [])
fibStart = refl
fibsMatch : (n : ℕ) → binNatToN (index fib n) ≡ fibUnary n
fibsMatch zero = refl
fibsMatch (succ zero) = refl
fibsMatch (succ (succ n)) rewrite equalityCommutative (fibsMatch (succ n)) | equalityCommutative (fibsMatch n) | equalityCommutative (mapAndIndex (unfold nextFib record { prev = NToBinNat 0 ; curr = NToBinNat 1 }) FibEntry.curr (succ (succ n))) | indexAndUnfold nextFib (record { prev = [] ; curr = one :: [] }) (succ n) | equalityCommutative (mapAndIndex (unfold nextFib (nextFib (record { prev = [] ; curr = one :: [] }))) FibEntry.curr n) | equalityCommutative (mapAndIndex (unfold nextFib (record { prev = [] ; curr = one :: [] })) FibEntry.curr n) | indexAndUnfold nextFib (nextFib (record { prev = [] ; curr = one :: [] })) n | indexAndUnfold nextFib (record { prev = [] ; curr = one :: [] }) n = ans
where
x = FibEntry.curr (index (unfold nextFib (record { prev = [] ; curr = one :: [] })) n)
y = FibEntry.prev (index (unfold nextFib (record { prev = [] ; curr = one :: [] })) n)
ans : binNatToN (x +B (y +B x)) ≡ binNatToN (y +B x) +N binNatToN x
ans rewrite +BCommutative x (y +B x) = +BIsHom (y +B x) x
fibsMatch' : (n : ℕ) → NToBinNat (fibUnary n) ≡ index fib n
fibsMatch' n = transitivity (applyEquality NToBinNat (equalityCommutative (fibsMatch n))) (transitivity (binToBin (index fib n)) (fibsCanonical n))
ArchimedeanSequence : {a b c : _} {A : Set a} {S : Setoid {a} {b} A} {_<_ : Rel {a} {c} A} (pOrder : SetoidPartialOrder S _<_) (S : Sequence A) → Set (a ⊔ c)
ArchimedeanSequence {A = A} {_<_ = _<_} _ S = (x : A) → Sg ℕ (λ n → x < (index S n))
archimImpliesTailArchim : {a b c : _} {A : Set a} {S : Setoid {a} {b} A} {_<_ : Rel {a} {c} A} (pOrder : SetoidPartialOrder S _<_) {S : Sequence A} → ArchimedeanSequence pOrder S → (Sg ℕ (λ i → index S 0 < index S i)) → ArchimedeanSequence pOrder (Sequence.tail S)
archimImpliesTailArchim {S} pOrder arch 0small x with arch x
archimImpliesTailArchim pOrder {S} arch (zero , S0<SN) x | zero , pr = exFalso (SetoidPartialOrder.irreflexive pOrder S0<SN)
archimImpliesTailArchim pOrder {S} arch (succ N , S0<SN) x | zero , pr = N , SetoidPartialOrder.<Transitive pOrder pr S0<SN
archimImpliesTailArchim pOrder arch 0small x | succ N , pr = N , pr
takeUpTo : {a b c : _} {A : Set a} {S : Setoid {a} {b} A} {_<_ : Rel {a} {c} A} {pOrder : SetoidPartialOrder S _<_} {seq : Sequence A} → (arch : ArchimedeanSequence pOrder seq) → (lim : A) → List A
takeUpTo {seq = S} arch lim with arch lim
takeUpTo {seq = S} arch lim | zero , pr = []
takeUpTo {seq = S} arch lim | succ N , pr = vecToList (take N S)
archim : ArchimedeanSequence (partialOrderToSetoidPartialOrder BinNatOrder) fib
archim x with fibUnaryArchimedean (binNatToN x)
archim x | N , pr = N , u
where
t : (canonical x) <B (NToBinNat (binNatToN (index (Sequences.map FibEntry.curr (unfold nextFib (record { prev = [] ; curr = one :: [] }))) N)))
t rewrite (fibsMatch N) = identityOfIndiscernablesLeft _<B_ (translate' _ _ pr) (binToBin x)
u : x <B (index (Sequences.map FibEntry.curr (unfold nextFib (record { prev = [] ; curr = one :: [] }))) N)
u rewrite equalityCommutative (mapAndIndex (unfold nextFib (record { prev = [] ; curr = one :: [] })) FibEntry.curr N) with transitivity (canonicalFirst x (NToBinNat (fibUnary N)) Equal) (identityOfIndiscernablesLeft _<B_ (translate' (binNatToN x) (fibUnary N) pr) (binToBin x))
... | r = identityOfIndiscernablesRight {a = x} {b = NToBinNat (fibUnary N)} {c = FibEntry.curr (index (unfold nextFib (record { prev = [] ; curr = one :: [] })) N)} _<B_ r (transitivity (fibsMatch' N) (fibAlternative N))
isEven : BinNat → Set
isEven [] = True
isEven (zero :: xs) = True
isEven (one :: xs) = False
isEvenAgrees : (n : BinNat) → isEven n → 2 ∣ (binNatToN n)
isEvenAgrees [] nEven = divides (record { quot = zero ; rem = zero ; pr = refl ; remIsSmall = inl (le 1 refl) ; quotSmall = inl (le 1 refl)}) refl
isEvenAgrees (zero :: n) nEven = divides (record { quot = binNatToN n ; rem = zero ; pr = Semiring.sumZeroRight ℕSemiring _ ; remIsSmall = inl (le 1 refl) ; quotSmall = inl (le 1 refl) }) refl
isEvenIncrs : (n : BinNat) → isEven n → isEven (incr (incr n))
isEvenIncrs [] nEven = record {}
isEvenIncrs (zero :: n) nEven = record {}
isEvenAgrees' : (n : ℕ) → 2 ∣ n → isEven (NToBinNat n)
isEvenAgrees' zero nEven = record {}
isEvenAgrees' (succ zero) (divides record { quot = (succ zero) ; rem = zero ; pr = () ; remIsSmall = remIsSmall ; quotSmall = (inl x) } refl)
isEvenAgrees' (succ zero) (divides record { quot = (succ (succ quot)) ; rem = zero ; pr = () ; remIsSmall = remIsSmall ; quotSmall = (inl x) } refl)
isEvenAgrees' (succ (succ n)) (divides record { quot = succ quot ; rem = zero ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = inl 0<2 } refl) with isEvenAgrees' n (divides record { quot = quot ; rem = zero ; pr = transitivity (transitivity (Semiring.sumZeroRight ℕSemiring _) (Semiring.commutative ℕSemiring quot (quot +N 0))) (succInjective (succInjective (transitivity (equalityCommutative (applyEquality succ (transitivity (Semiring.sumZeroRight ℕSemiring (quot +N succ (quot +N zero))) (Semiring.commutative ℕSemiring quot (succ (quot +N 0)))))) pr))) ; remIsSmall = remIsSmall ; quotSmall = inl 0<2 } refl)
... | bl = isEvenIncrs (NToBinNat n) bl
isEvenWellDefined : (n m : BinNat) → canonical n ≡ canonical m → isEven n → isEven m
isEvenWellDefined [] [] n=m nEven = record {}
isEvenWellDefined [] (zero :: m) n=m nEven = record {}
isEvenWellDefined (zero :: n) [] n=m nEven = record {}
isEvenWellDefined (zero :: n) (zero :: m) n=m nEven = record {}
isEvenWellDefined (zero :: n) (one :: m) n=m nEven with canonical n
isEvenWellDefined (zero :: n) (one :: m) () nEven | []
isEvenWellDefined (zero :: n) (one :: m) () nEven | x :: bl
isEvenDecidable : DecidableRelation isEven
isEvenDecidable [] = inl (record {})
isEvenDecidable (zero :: x₁) = inl (record {})
isEvenDecidable (one :: x₁) = inr (λ x → x)
increasing : StrictlyIncreasing (partialOrderToSetoidPartialOrder BinNatOrder) (Sequence.tail fib)
increasing m = SetoidPartialOrder.<WellDefined (partialOrderToSetoidPartialOrder BinNatOrder) (fibsMatch' (succ m)) (fibsMatch' (succ (succ m))) (translate' (fibUnary (succ m)) (fibUnary (succ (succ m))) (fibUnaryIncreasing m))
-- increasingNaturalsBound : (S : Sequence ℕ) → StrictlyIncreasing S → (bound : ℕ) → List ℕ
-- increasingNaturalsBound s n = {!!}
{-
fibsLessThan4Mil : List BinNat
fibsLessThan4Mil = takeUpToMonotone {tOrder = BinNatTOrder} (archimImpliesTailArchim {tOrder = BinNatTOrder} archim (2 , ordersAgree 1 2 (le zero refl))) increasing (one :: one :: one :: one :: zero :: one :: zero :: zero :: zero :: zero :: one :: zero :: zero :: one :: zero :: zero :: zero :: zero :: zero :: zero :: zero :: one :: [])
evens : List BinNat
evens = filter' isEvenDecidable fibsLessThan4Mil
ans : BinNat
ans = fold _+B_ [] evens
-}
|
{
"alphanum_fraction": 0.6861348156,
"avg_line_length": 72.1638418079,
"ext": "agda",
"hexsha": "e9f35441db2d03bf357f90b58c7eb47039d367d4",
"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": "ProjectEuler/Problem2.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": "ProjectEuler/Problem2.agda",
"max_line_length": 1218,
"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": "ProjectEuler/Problem2.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": 4122,
"size": 12773
}
|
module MetaCannotDependOn where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
postulate
Vec : Nat -> Set -> Set
f : (A : Set) -> ((n : Nat) -> A -> Vec n Nat) -> Nat
err : Nat
err = f _ (\ n xs -> xs)
|
{
"alphanum_fraction": 0.5366972477,
"avg_line_length": 14.5333333333,
"ext": "agda",
"hexsha": "7e856583e6e2f41702a9c38597346d8f3d898e3d",
"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/MetaCannotDependOn.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/MetaCannotDependOn.agda",
"max_line_length": 55,
"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/MetaCannotDependOn.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": 78,
"size": 218
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Boring lemmas used in Data.Nat.GCD and Data.Nat.Coprimality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.GCD.Lemmas where
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Solver
open import Function
open import Relation.Binary.PropositionalEquality
open +-*-Solver
open ≡-Reasoning
private
distrib-comm : ∀ x k n → x * k + x * n ≡ x * (n + k)
distrib-comm =
solve 3 (λ x k n → x :* k :+ x :* n := x :* (n :+ k)) refl
distrib-comm₂ : ∀ d x k n → d + x * (n + k) ≡ d + x * k + x * n
distrib-comm₂ =
solve 4 (λ d x k n → d :+ x :* (n :+ k) := d :+ x :* k :+ x :* n) refl
-- Other properties
-- TODO: Can this proof be simplified? An automatic solver which can
-- handle ∸ would be nice...
lem₀ : ∀ i j m n → i * m ≡ j * m + n → (i ∸ j) * m ≡ n
lem₀ i j m n eq = begin
(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 ∎
lem₁ : ∀ i j → 2 + i ≤′ 2 + j + i
lem₁ i j = ≤⇒≤′ $ s≤s $ s≤s $ n≤m+n j i
lem₂ : ∀ d x {k n} →
d + x * k ≡ x * n → d + x * (n + k) ≡ 2 * x * n
lem₂ d x {k} {n} eq = begin
d + x * (n + k) ≡⟨ distrib-comm₂ d x k n ⟩
d + x * k + x * n ≡⟨ cong₂ _+_ eq refl ⟩
x * n + x * n ≡⟨ solve 3 (λ x n k → x :* n :+ x :* n
:= con 2 :* x :* n)
refl x n k ⟩
2 * x * n ∎
lem₃ : ∀ d x {i k n} →
d + (1 + x + i) * k ≡ x * n →
d + (1 + x + i) * (n + k) ≡ (1 + 2 * x + i) * n
lem₃ d x {i} {k} {n} eq = begin
d + y * (n + k) ≡⟨ distrib-comm₂ d y k n ⟩
d + y * k + y * n ≡⟨ cong₂ _+_ eq refl ⟩
x * n + y * n ≡⟨ solve 3 (λ x n i → x :* n :+ (con 1 :+ x :+ i) :* n
:= (con 1 :+ con 2 :* x :+ i) :* n)
refl x n i ⟩
(1 + 2 * x + i) * n ∎
where y = 1 + x + i
lem₄ : ∀ d y {k i} n →
d + y * k ≡ (1 + y + i) * n →
d + y * (n + k) ≡ (1 + 2 * y + i) * n
lem₄ d y {k} {i} n eq = begin
d + y * (n + k) ≡⟨ distrib-comm₂ d y k n ⟩
d + y * k + y * n ≡⟨ cong₂ _+_ eq refl ⟩
(1 + y + i) * n + y * n ≡⟨ solve 3 (λ y i n → (con 1 :+ y :+ i) :* n :+ y :* n
:= (con 1 :+ con 2 :* y :+ i) :* n)
refl y i n ⟩
(1 + 2 * y + i) * n ∎
lem₅ : ∀ d x {n k} →
d + x * n ≡ x * k →
d + 2 * x * n ≡ x * (n + k)
lem₅ d x {n} {k} eq = begin
d + 2 * x * n ≡⟨ solve 3 (λ d x n → d :+ con 2 :* x :* n
:= d :+ x :* n :+ x :* n)
refl d x n ⟩
d + x * n + x * n ≡⟨ cong₂ _+_ eq refl ⟩
x * k + x * n ≡⟨ distrib-comm x k n ⟩
x * (n + k) ∎
lem₆ : ∀ d x {n i k} →
d + x * n ≡ (1 + x + i) * k →
d + (1 + 2 * x + i) * n ≡ (1 + x + i) * (n + k)
lem₆ d x {n} {i} {k} eq = begin
d + (1 + 2 * x + i) * n ≡⟨ solve 4 (λ d x i n → d :+ (con 1 :+ con 2 :* x :+ i) :* n
:= d :+ x :* n :+ (con 1 :+ x :+ i) :* n)
refl d x i n ⟩
d + x * n + y * n ≡⟨ cong₂ _+_ eq refl ⟩
y * k + y * n ≡⟨ distrib-comm y k n ⟩
y * (n + k) ∎
where y = 1 + x + i
lem₇ : ∀ d y {i} n {k} →
d + (1 + y + i) * n ≡ y * k →
d + (1 + 2 * y + i) * n ≡ y * (n + k)
lem₇ d y {i} n {k} eq = begin
d + (1 + 2 * y + i) * n ≡⟨ solve 4 (λ d y i n → d :+ (con 1 :+ con 2 :* y :+ i) :* n
:= d :+ (con 1 :+ y :+ i) :* n :+ y :* n)
refl d y i n ⟩
d + (1 + y + i) * n + y * n ≡⟨ cong₂ _+_ eq refl ⟩
y * k + y * n ≡⟨ distrib-comm y k n ⟩
y * (n + k) ∎
lem₈ : ∀ {i j k q} x y →
1 + y * j ≡ x * i → j * k ≡ q * i →
k ≡ (x * k ∸ y * q) * i
lem₈ {i} {j} {k} {q} x y eq eq′ =
sym (lem₀ (x * k) (y * q) i k lemma)
where
lemma = begin
x * k * i ≡⟨ solve 3 (λ x k i → x :* k :* i
:= x :* i :* k)
refl x k i ⟩
x * i * k ≡⟨ cong (_* k) (sym eq) ⟩
(1 + y * j) * k ≡⟨ solve 3 (λ y j k → (con 1 :+ y :* j) :* k
:= y :* (j :* k) :+ k)
refl y j k ⟩
y * (j * k) + k ≡⟨ cong (λ n → y * n + k) eq′ ⟩
y * (q * i) + k ≡⟨ solve 4 (λ y q i k → y :* (q :* i) :+ k
:= y :* q :* i :+ k)
refl y q i k ⟩
y * q * i + k ∎
lem₉ : ∀ {i j k q} x y →
1 + x * i ≡ y * j → j * k ≡ q * i →
k ≡ (y * q ∸ x * k) * i
lem₉ {i} {j} {k} {q} x y eq eq′ =
sym (lem₀ (y * q) (x * k) i k lemma)
where
lem = solve 3 (λ a b c → a :* b :* c := b :* c :* a) refl
lemma = begin
y * q * i ≡⟨ lem y q i ⟩
q * i * y ≡⟨ cong (λ n → n * y) (sym eq′) ⟩
j * k * y ≡⟨ sym (lem y j k) ⟩
y * j * k ≡⟨ cong (λ n → n * k) (sym eq) ⟩
(1 + x * i) * k ≡⟨ solve 3 (λ x i k → (con 1 :+ x :* i) :* k
:= x :* k :* i :+ k)
refl x i k ⟩
x * k * i + k ∎
lem₁₀ : ∀ {a′} b c {d} e f → let a = suc a′ in
a + b * (c * d * a) ≡ e * (f * d * a) →
d ≡ 1
lem₁₀ {a′} b c {d} e f eq =
i*j≡1⇒j≡1 (e * f ∸ b * c) d
(lem₀ (e * f) (b * c) d 1
(*-cancelʳ-≡ (e * f * d) (b * c * d + 1) (begin
e * f * d * a ≡⟨ solve 4 (λ e f d a → e :* f :* d :* a
:= e :* (f :* d :* a))
refl e f d a ⟩
e * (f * d * a) ≡⟨ sym eq ⟩
a + b * (c * d * a) ≡⟨ solve 4 (λ a b c d → a :+ b :* (c :* d :* a)
:= (b :* c :* d :+ con 1) :* a)
refl a b c d ⟩
(b * c * d + 1) * a ∎)))
where a = suc a′
lem₁₁ : ∀ {i j m n k d} x y →
1 + y * j ≡ x * i → i * k ≡ m * d → j * k ≡ n * d →
k ≡ (x * m ∸ y * n) * d
lem₁₁ {i} {j} {m} {n} {k} {d} x y eq eq₁ eq₂ =
sym (lem₀ (x * m) (y * n) d k (begin
x * m * d ≡⟨ *-assoc x m d ⟩
x * (m * d) ≡⟨ cong (x *_) (sym eq₁) ⟩
x * (i * k) ≡⟨ sym (*-assoc x i k) ⟩
x * i * k ≡⟨ cong₂ _*_ (sym eq) refl ⟩
(1 + y * j) * k ≡⟨ solve 3 (λ y j k → (con 1 :+ y :* j) :* k
:= y :* (j :* k) :+ k)
refl y j k ⟩
y * (j * k) + k ≡⟨ cong (λ p → y * p + k) eq₂ ⟩
y * (n * d) + k ≡⟨ cong₂ _+_ (sym $ *-assoc y n d) refl ⟩
y * n * d + k ∎))
|
{
"alphanum_fraction": 0.2963433573,
"avg_line_length": 39.5698324022,
"ext": "agda",
"hexsha": "9658abce07d4be200cbb9cfd4c01111c9e4de219",
"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/GCD/Lemmas.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/GCD/Lemmas.agda",
"max_line_length": 93,
"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/GCD/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3083,
"size": 7083
}
|
-- {-# OPTIONS -v tc.size.solve:100 #-}
open import Agda.Builtin.Size
data Cx (U : Set) : Set where
⌀ : Cx U
_,_ : Cx U → U → Cx U
module _ {U : Set} where
data _⊆_ : Cx U → Cx U → Set where
done : ⌀ ⊆ ⌀
skip : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊆ (Γ′ , A)
keep : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → (Γ , A) ⊆ (Γ′ , A)
data _∈_ (A : U) : Cx U → Set where
top : ∀ {Γ} → A ∈ (Γ , A)
pop : ∀ {C Γ} → A ∈ Γ → A ∈ (Γ , C)
mono∈ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → A ∈ Γ → A ∈ Γ′
mono∈ done ()
mono∈ (skip η) i = pop (mono∈ η i)
mono∈ (keep η) top = top
mono∈ (keep η) (pop i) = pop (mono∈ η i)
refl⊆ : ∀ {Γ} → Γ ⊆ Γ
refl⊆ {⌀} = done
refl⊆ {Γ , A} = keep refl⊆
infixr 3 _⊃_
data Ty : Set where
ι : Ty
_⊃_ : Ty → Ty → Ty
infix 1 _⊢⟨_⟩_
data _⊢⟨_⟩_ (Γ : Cx Ty) : Size → Ty → Set where
var : ∀ {p A} → A ∈ Γ → Γ ⊢⟨ p ⟩ A
lam : ∀ {n A B} {o : Size< n} → Γ , A ⊢⟨ o ⟩ B → Γ ⊢⟨ n ⟩ A ⊃ B
app : ∀ {m A B} {l k : Size< m} → Γ ⊢⟨ k ⟩ A ⊃ B → Γ ⊢⟨ l ⟩ A → Γ ⊢⟨ m ⟩ B
mono⊢ : ∀ {m A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⟨ m ⟩ A → Γ′ ⊢⟨ m ⟩ A
mono⊢ η (var i) = var (mono∈ η i)
mono⊢ η (lam t) = lam (mono⊢ (keep η) t)
mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)
det : ∀ {i A B Γ} {j : Size< i} → Γ ⊢⟨ j ⟩ A ⊃ B → Γ , A ⊢⟨ i ⟩ B
det t = app (mono⊢ (skip refl⊆) t) (var top)
ccont : ∀ {m A B Γ} → Γ ⊢⟨ ↑ ↑ ↑ ↑ m ⟩ (A ⊃ A ⊃ B) ⊃ A ⊃ B
ccont = lam (lam (app (app (var (pop top)) (var top)) (var top)))
cont : ∀ {m A B Γ} {m′ : Size< m} → (Γ , A) , A ⊢⟨ ↑ ↑ m′ ⟩ B → Γ , A ⊢⟨ ↑ ↑ ↑ ↑ ↑ m ⟩ B
cont t = det (app ccont (lam (lam t)))
cont′ : ∀ {q A B Γ} {r : Size< q} → (Γ , A) , A ⊢⟨ {!q!} ⟩ B → Γ , A ⊢⟨ {!!} ⟩ B
cont′ t = det (app ccont (lam (lam t)))
|
{
"alphanum_fraction": 0.4005899705,
"avg_line_length": 30.2678571429,
"ext": "agda",
"hexsha": "e6911f55ed4785c25e0f69f4b9fe1fb2b251065f",
"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/interaction/Issue2096.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/interaction/Issue2096.agda",
"max_line_length": 88,
"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/interaction/Issue2096.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": 923,
"size": 1695
}
|
{-# OPTIONS --allow-unsolved-metas #-}
module finiteSetUtil where
open import Data.Nat hiding ( _≟_ )
open import Data.Fin renaming ( _<_ to _<<_ ; _>_ to _f>_ ; _≟_ to _f≟_ ) hiding (_≤_ )
open import Data.Fin.Properties hiding ( <-trans ) renaming ( <-cmp to <-fcmp )
open import Data.Empty
open import Relation.Nullary
open import Relation.Binary.Definitions
open import Relation.Binary.PropositionalEquality
open import logic
open import nat
open import finiteSet
open import fin
open import Data.Nat.Properties as NatP hiding ( _≟_ )
open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ )
record Found ( Q : Set ) (p : Q → Bool ) : Set where
field
found-q : Q
found-p : p found-q ≡ true
open Bijection
open import Axiom.Extensionality.Propositional
open import Level hiding (suc ; zero)
postulate f-extensionality : { n : Level} → Axiom.Extensionality.Propositional.Extensionality n n -- (Level.suc n)
module _ {Q : Set } (F : FiniteSet Q) where
open FiniteSet F
equal?-refl : { x : Q } → equal? x x ≡ true
equal?-refl {x} with F←Q x ≟ F←Q x
... | yes refl = refl
... | no ne = ⊥-elim (ne refl)
equal→refl : { x y : Q } → equal? x y ≡ true → x ≡ y
equal→refl {q0} {q1} eq with F←Q q0 ≟ F←Q q1
equal→refl {q0} {q1} refl | yes eq = begin
q0
≡⟨ sym ( finiso→ q0) ⟩
Q←F (F←Q q0)
≡⟨ cong (λ k → Q←F k ) eq ⟩
Q←F (F←Q q1)
≡⟨ finiso→ q1 ⟩
q1
∎ where open ≡-Reasoning
eqP : (x y : Q) → Dec ( x ≡ y )
eqP x y with F←Q x ≟ F←Q y
... | yes eq = yes (subst₂ (λ j k → j ≡ k ) (finiso→ x) (finiso→ y) (cong Q←F eq) )
... | no n = no (λ eq → n (cong F←Q eq))
End : (m : ℕ ) → (p : Q → Bool ) → Set
End m p = (i : Fin finite) → m ≤ toℕ i → p (Q←F i ) ≡ false
first-end : ( p : Q → Bool ) → End finite p
first-end p i i>n = ⊥-elim (nat-≤> i>n (fin<n {finite} {i}) )
next-end : {m : ℕ } → ( p : Q → Bool ) → End (suc m) p
→ (m<n : m < finite ) → p (Q←F (fromℕ< m<n )) ≡ false
→ End m p
next-end {m} p prev m<n np i m<i with NatP.<-cmp m (toℕ i)
next-end p prev m<n np i m<i | tri< a ¬b ¬c = prev i a
next-end p prev m<n np i m<i | tri> ¬a ¬b c = ⊥-elim ( nat-≤> m<i c )
next-end {m} p prev m<n np i m<i | tri≈ ¬a b ¬c = subst ( λ k → p (Q←F k) ≡ false) (m<n=i i b m<n ) np where
m<n=i : {n : ℕ } (i : Fin n) {m : ℕ } → m ≡ (toℕ i) → (m<n : m < n ) → fromℕ< m<n ≡ i
m<n=i i refl m<n = fromℕ<-toℕ i m<n
found : { p : Q → Bool } → (q : Q ) → p q ≡ true → exists p ≡ true
found {p} q pt = found1 finite (NatP.≤-refl ) ( first-end p ) where
found1 : (m : ℕ ) (m<n : m Data.Nat.≤ finite ) → ((i : Fin finite) → m ≤ toℕ i → p (Q←F i ) ≡ false ) → exists1 m m<n p ≡ true
found1 0 m<n end = ⊥-elim ( ¬-bool (subst (λ k → k ≡ false ) (cong (λ k → p k) (finiso→ q) ) (end (F←Q q) z≤n )) pt )
found1 (suc m) m<n end with bool-≡-? (p (Q←F (fromℕ< m<n))) true
found1 (suc m) m<n end | yes eq = subst (λ k → k \/ exists1 m (<to≤ m<n) p ≡ true ) (sym eq) (bool-or-4 {exists1 m (<to≤ m<n) p} )
found1 (suc m) m<n end | no np = begin
p (Q←F (fromℕ< m<n)) \/ exists1 m (<to≤ m<n) p
≡⟨ bool-or-1 (¬-bool-t np ) ⟩
exists1 m (<to≤ m<n) p
≡⟨ found1 m (<to≤ m<n) (next-end p end m<n (¬-bool-t np )) ⟩
true
∎ where open ≡-Reasoning
not-found : { p : Q → Bool } → ( (q : Q ) → p q ≡ false ) → exists p ≡ false
not-found {p} pn = not-found2 finite NatP.≤-refl where
not-found2 : (m : ℕ ) → (m<n : m Data.Nat.≤ finite ) → exists1 m m<n p ≡ false
not-found2 zero _ = refl
not-found2 ( suc m ) m<n with pn (Q←F (fromℕ< {m} {finite} m<n))
not-found2 (suc m) m<n | eq = begin
p (Q←F (fromℕ< m<n)) \/ exists1 m (<to≤ m<n) p
≡⟨ bool-or-1 eq ⟩
exists1 m (<to≤ m<n) p
≡⟨ not-found2 m (<to≤ m<n) ⟩
false
∎ where open ≡-Reasoning
found← : { p : Q → Bool } → exists p ≡ true → Found Q p
found← {p} exst = found2 finite NatP.≤-refl (first-end p ) where
found2 : (m : ℕ ) (m<n : m Data.Nat.≤ finite ) → End m p → Found Q p
found2 0 m<n end = ⊥-elim ( ¬-bool (not-found (λ q → end (F←Q q) z≤n ) ) (subst (λ k → exists k ≡ true) (sym lemma) exst ) ) where
lemma : (λ z → p (Q←F (F←Q z))) ≡ p
lemma = f-extensionality ( λ q → subst (λ k → p k ≡ p q ) (sym (finiso→ q)) refl )
found2 (suc m) m<n end with bool-≡-? (p (Q←F (fromℕ< m<n))) true
found2 (suc m) m<n end | yes eq = record { found-q = Q←F (fromℕ< m<n) ; found-p = eq }
found2 (suc m) m<n end | no np =
found2 m (<to≤ m<n) (next-end p end m<n (¬-bool-t np ))
not-found← : { p : Q → Bool } → exists p ≡ false → (q : Q ) → p q ≡ false
not-found← {p} np q = ¬-bool-t ( contra-position {_} {_} {_} {exists p ≡ true} (found q) (λ ep → ¬-bool np ep ) )
iso-fin : {A B : Set} → FiniteSet A → Bijection A B → FiniteSet B
iso-fin {A} {B} fin iso = record {
Q←F = λ f → fun→ iso ( FiniteSet.Q←F fin f )
; F←Q = λ b → FiniteSet.F←Q fin (fun← iso b )
; finiso→ = finiso→
; finiso← = finiso←
} where
finiso→ : (q : B) → fun→ iso (FiniteSet.Q←F fin (FiniteSet.F←Q fin (Bijection.fun← iso q))) ≡ q
finiso→ q = begin
fun→ iso (FiniteSet.Q←F fin (FiniteSet.F←Q fin (Bijection.fun← iso q)))
≡⟨ cong (λ k → fun→ iso k ) (FiniteSet.finiso→ fin _ ) ⟩
fun→ iso (Bijection.fun← iso q)
≡⟨ fiso→ iso _ ⟩
q
∎ where open ≡-Reasoning
finiso← : (f : Fin (FiniteSet.finite fin ))→ FiniteSet.F←Q fin (Bijection.fun← iso (Bijection.fun→ iso (FiniteSet.Q←F fin f))) ≡ f
finiso← f = begin
FiniteSet.F←Q fin (Bijection.fun← iso (Bijection.fun→ iso (FiniteSet.Q←F fin f)))
≡⟨ cong (λ k → FiniteSet.F←Q fin k ) (Bijection.fiso← iso _) ⟩
FiniteSet.F←Q fin (FiniteSet.Q←F fin f)
≡⟨ FiniteSet.finiso← fin _ ⟩
f
∎ where
open ≡-Reasoning
data One : Set where
one : One
fin-∨1 : {B : Set} → (fb : FiniteSet B ) → FiniteSet (One ∨ B)
fin-∨1 {B} fb = record {
Q←F = Q←F
; F←Q = F←Q
; finiso→ = finiso→
; finiso← = finiso←
} where
b = FiniteSet.finite fb
Q←F : Fin (suc b) → One ∨ B
Q←F zero = case1 one
Q←F (suc f) = case2 (FiniteSet.Q←F fb f)
F←Q : One ∨ B → Fin (suc b)
F←Q (case1 one) = zero
F←Q (case2 f ) = suc (FiniteSet.F←Q fb f)
finiso→ : (q : One ∨ B) → Q←F (F←Q q) ≡ q
finiso→ (case1 one) = refl
finiso→ (case2 b) = cong (λ k → case2 k ) (FiniteSet.finiso→ fb b)
finiso← : (q : Fin (suc b)) → F←Q (Q←F q) ≡ q
finiso← zero = refl
finiso← (suc f) = cong ( λ k → suc k ) (FiniteSet.finiso← fb f)
fin-∨2 : {B : Set} → ( a : ℕ ) → FiniteSet B → FiniteSet (Fin a ∨ B)
fin-∨2 {B} zero fb = iso-fin fb iso where
iso : Bijection B (Fin zero ∨ B)
iso = record {
fun← = fun←1
; fun→ = λ b → case2 b
; fiso→ = fiso→1
; fiso← = λ _ → refl
} where
fun←1 : Fin zero ∨ B → B
fun←1 (case2 x) = x
fiso→1 : (f : Fin zero ∨ B ) → case2 (fun←1 f) ≡ f
fiso→1 (case2 x) = refl
fin-∨2 {B} (suc a) fb = iso-fin (fin-∨1 (fin-∨2 a fb) ) iso
where
iso : Bijection (One ∨ (Fin a ∨ B) ) (Fin (suc a) ∨ B)
fun← iso (case1 zero) = case1 one
fun← iso (case1 (suc f)) = case2 (case1 f)
fun← iso (case2 b) = case2 (case2 b)
fun→ iso (case1 one) = case1 zero
fun→ iso (case2 (case1 f)) = case1 (suc f)
fun→ iso (case2 (case2 b)) = case2 b
fiso← iso (case1 one) = refl
fiso← iso (case2 (case1 x)) = refl
fiso← iso (case2 (case2 x)) = refl
fiso→ iso (case1 zero) = refl
fiso→ iso (case1 (suc x)) = refl
fiso→ iso (case2 x) = refl
FiniteSet→Fin : {A : Set} → (fin : FiniteSet A ) → Bijection (Fin (FiniteSet.finite fin)) A
fun← (FiniteSet→Fin fin) f = FiniteSet.F←Q fin f
fun→ (FiniteSet→Fin fin) f = FiniteSet.Q←F fin f
fiso← (FiniteSet→Fin fin) = FiniteSet.finiso← fin
fiso→ (FiniteSet→Fin fin) = FiniteSet.finiso→ fin
fin-∨ : {A B : Set} → FiniteSet A → FiniteSet B → FiniteSet (A ∨ B)
fin-∨ {A} {B} fa fb = iso-fin (fin-∨2 a fb ) iso2 where
a = FiniteSet.finite fa
ia = FiniteSet→Fin fa
iso2 : Bijection (Fin a ∨ B ) (A ∨ B)
fun← iso2 (case1 x) = case1 (fun← ia x )
fun← iso2 (case2 x) = case2 x
fun→ iso2 (case1 x) = case1 (fun→ ia x )
fun→ iso2 (case2 x) = case2 x
fiso← iso2 (case1 x) = cong ( λ k → case1 k ) (Bijection.fiso← ia x)
fiso← iso2 (case2 x) = refl
fiso→ iso2 (case1 x) = cong ( λ k → case1 k ) (Bijection.fiso→ ia x)
fiso→ iso2 (case2 x) = refl
open import Data.Product hiding ( map )
fin-× : {A B : Set} → FiniteSet A → FiniteSet B → FiniteSet (A × B)
fin-× {A} {B} fa fb with FiniteSet→Fin fa
... | a=f = iso-fin (fin-×-f a ) iso-1 where
a = FiniteSet.finite fa
b = FiniteSet.finite fb
iso-1 : Bijection (Fin a × B) ( A × B )
fun← iso-1 x = ( FiniteSet.F←Q fa (proj₁ x) , proj₂ x)
fun→ iso-1 x = ( FiniteSet.Q←F fa (proj₁ x) , proj₂ x)
fiso← iso-1 x = lemma where
lemma : (FiniteSet.F←Q fa (FiniteSet.Q←F fa (proj₁ x)) , proj₂ x) ≡ ( proj₁ x , proj₂ x )
lemma = cong ( λ k → ( k , proj₂ x ) ) (FiniteSet.finiso← fa _ )
fiso→ iso-1 x = cong ( λ k → ( k , proj₂ x ) ) (FiniteSet.finiso→ fa _ )
iso-2 : {a : ℕ } → Bijection (B ∨ (Fin a × B)) (Fin (suc a) × B)
fun← iso-2 (zero , b ) = case1 b
fun← iso-2 (suc fst , b ) = case2 ( fst , b )
fun→ iso-2 (case1 b) = ( zero , b )
fun→ iso-2 (case2 (a , b )) = ( suc a , b )
fiso← iso-2 (case1 x) = refl
fiso← iso-2 (case2 x) = refl
fiso→ iso-2 (zero , b ) = refl
fiso→ iso-2 (suc a , b ) = refl
fin-×-f : ( a : ℕ ) → FiniteSet ((Fin a) × B)
fin-×-f zero = record { Q←F = λ () ; F←Q = λ () ; finiso→ = λ () ; finiso← = λ () ; finite = 0 }
fin-×-f (suc a) = iso-fin ( fin-∨ fb ( fin-×-f a ) ) iso-2
open _∧_
fin-∧ : {A B : Set} → FiniteSet A → FiniteSet B → FiniteSet (A ∧ B)
fin-∧ {A} {B} fa fb with FiniteSet→Fin fa -- same thing for our tool
... | a=f = iso-fin (fin-×-f a ) iso-1 where
a = FiniteSet.finite fa
b = FiniteSet.finite fb
iso-1 : Bijection (Fin a ∧ B) ( A ∧ B )
fun← iso-1 x = record { proj1 = FiniteSet.F←Q fa (proj1 x) ; proj2 = proj2 x}
fun→ iso-1 x = record { proj1 = FiniteSet.Q←F fa (proj1 x) ; proj2 = proj2 x}
fiso← iso-1 x = lemma where
lemma : record { proj1 = FiniteSet.F←Q fa (FiniteSet.Q←F fa (proj1 x)) ; proj2 = proj2 x} ≡ record {proj1 = proj1 x ; proj2 = proj2 x }
lemma = cong ( λ k → record {proj1 = k ; proj2 = proj2 x } ) (FiniteSet.finiso← fa _ )
fiso→ iso-1 x = cong ( λ k → record {proj1 = k ; proj2 = proj2 x } ) (FiniteSet.finiso→ fa _ )
iso-2 : {a : ℕ } → Bijection (B ∨ (Fin a ∧ B)) (Fin (suc a) ∧ B)
fun← iso-2 (record { proj1 = zero ; proj2 = b }) = case1 b
fun← iso-2 (record { proj1 = suc fst ; proj2 = b }) = case2 ( record { proj1 = fst ; proj2 = b } )
fun→ iso-2 (case1 b) = record {proj1 = zero ; proj2 = b }
fun→ iso-2 (case2 (record { proj1 = a ; proj2 = b })) = record { proj1 = suc a ; proj2 = b }
fiso← iso-2 (case1 x) = refl
fiso← iso-2 (case2 x) = refl
fiso→ iso-2 (record { proj1 = zero ; proj2 = b }) = refl
fiso→ iso-2 (record { proj1 = suc a ; proj2 = b }) = refl
fin-×-f : ( a : ℕ ) → FiniteSet ((Fin a) ∧ B)
fin-×-f zero = record { Q←F = λ () ; F←Q = λ () ; finiso→ = λ () ; finiso← = λ () ; finite = 0 }
fin-×-f (suc a) = iso-fin ( fin-∨ fb ( fin-×-f a ) ) iso-2
-- import Data.Nat.DivMod
open import Data.Vec hiding ( map ; length )
import Data.Product
exp2 : (n : ℕ ) → exp 2 (suc n) ≡ exp 2 n Data.Nat.+ exp 2 n
exp2 n = begin
exp 2 (suc n)
≡⟨⟩
2 * ( exp 2 n )
≡⟨ *-comm 2 (exp 2 n) ⟩
( exp 2 n ) * 2
≡⟨ *-suc ( exp 2 n ) 1 ⟩
(exp 2 n ) Data.Nat.+ ( exp 2 n ) * 1
≡⟨ cong ( λ k → (exp 2 n ) Data.Nat.+ k ) (proj₂ *-identity (exp 2 n) ) ⟩
exp 2 n Data.Nat.+ exp 2 n
∎ where
open ≡-Reasoning
open Data.Product
cast-iso : {n m : ℕ } → (eq : n ≡ m ) → (f : Fin m ) → cast eq ( cast (sym eq ) f) ≡ f
cast-iso refl zero = refl
cast-iso refl (suc f) = cong ( λ k → suc k ) ( cast-iso refl f )
fin2List : {n : ℕ } → FiniteSet (Vec Bool n)
fin2List {zero} = record {
Q←F = λ _ → Vec.[]
; F←Q = λ _ → # 0
; finiso→ = finiso→
; finiso← = finiso←
} where
Q = Vec Bool zero
finiso→ : (q : Q) → [] ≡ q
finiso→ [] = refl
finiso← : (f : Fin (exp 2 zero)) → # 0 ≡ f
finiso← zero = refl
fin2List {suc n} = subst (λ k → FiniteSet (Vec Bool (suc n)) ) (sym (exp2 n)) ( iso-fin (fin-∨ (fin2List ) (fin2List )) iso )
where
QtoR : Vec Bool (suc n) → Vec Bool n ∨ Vec Bool n
QtoR ( true ∷ x ) = case1 x
QtoR ( false ∷ x ) = case2 x
RtoQ : Vec Bool n ∨ Vec Bool n → Vec Bool (suc n)
RtoQ ( case1 x ) = true ∷ x
RtoQ ( case2 x ) = false ∷ x
isoRQ : (x : Vec Bool (suc n) ) → RtoQ ( QtoR x ) ≡ x
isoRQ (true ∷ _ ) = refl
isoRQ (false ∷ _ ) = refl
isoQR : (x : Vec Bool n ∨ Vec Bool n ) → QtoR ( RtoQ x ) ≡ x
isoQR (case1 x) = refl
isoQR (case2 x) = refl
iso : Bijection (Vec Bool n ∨ Vec Bool n) (Vec Bool (suc n))
iso = record { fun← = QtoR ; fun→ = RtoQ ; fiso← = isoQR ; fiso→ = isoRQ }
F2L : {Q : Set } {n : ℕ } → (fin : FiniteSet Q ) → n < suc (FiniteSet.finite fin) → ( (q : Q) → toℕ (FiniteSet.F←Q fin q ) < n → Bool ) → Vec Bool n
F2L {Q} {zero} fin _ Q→B = []
F2L {Q} {suc n} fin (s≤s n<m) Q→B = Q→B (FiniteSet.Q←F fin (fromℕ< n<m)) lemma6 ∷ F2L {Q} fin (NatP.<-trans n<m a<sa ) qb1 where
lemma6 : toℕ (FiniteSet.F←Q fin (FiniteSet.Q←F fin (fromℕ< n<m))) < suc n
lemma6 = subst (λ k → toℕ k < suc n ) (sym (FiniteSet.finiso← fin _ )) (subst (λ k → k < suc n) (sym (toℕ-fromℕ< n<m )) a<sa )
qb1 : (q : Q) → toℕ (FiniteSet.F←Q fin q) < n → Bool
qb1 q q<n = Q→B q (NatP.<-trans q<n a<sa)
List2Func : { Q : Set } → {n : ℕ } → (fin : FiniteSet Q ) → n < suc (FiniteSet.finite fin) → Vec Bool n → Q → Bool
List2Func {Q} {zero} fin (s≤s z≤n) [] q = false
List2Func {Q} {suc n} fin (s≤s n<m) (h ∷ t) q with FiniteSet.F←Q fin q ≟ fromℕ< n<m
... | yes _ = h
... | no _ = List2Func {Q} fin (NatP.<-trans n<m a<sa ) t q
open import Level renaming ( suc to Suc ; zero to Zero)
open import Axiom.Extensionality.Propositional
-- postulate f-extensionality : { n : Level} → Axiom.Extensionality.Propositional.Extensionality n n
F2L-iso : { Q : Set } → (fin : FiniteSet Q ) → (x : Vec Bool (FiniteSet.finite fin) ) → F2L fin a<sa (λ q _ → List2Func fin a<sa x q ) ≡ x
F2L-iso {Q} fin x = f2l m a<sa x where
m = FiniteSet.finite fin
f2l : (n : ℕ ) → (n<m : n < suc m )→ (x : Vec Bool n ) → F2L fin n<m (λ q q<n → List2Func fin n<m x q ) ≡ x
f2l zero (s≤s z≤n) [] = refl
f2l (suc n) (s≤s n<m) (h ∷ t ) = lemma1 lemma2 lemma3f where
lemma1 : {n : ℕ } → {h h1 : Bool } → {t t1 : Vec Bool n } → h ≡ h1 → t ≡ t1 → h ∷ t ≡ h1 ∷ t1
lemma1 refl refl = refl
lemma2 : List2Func fin (s≤s n<m) (h ∷ t) (FiniteSet.Q←F fin (fromℕ< n<m)) ≡ h
lemma2 with FiniteSet.F←Q fin (FiniteSet.Q←F fin (fromℕ< n<m)) ≟ fromℕ< n<m
lemma2 | yes p = refl
lemma2 | no ¬p = ⊥-elim ( ¬p (FiniteSet.finiso← fin _) )
lemma4 : (q : Q ) → toℕ (FiniteSet.F←Q fin q ) < n → List2Func fin (s≤s n<m) (h ∷ t) q ≡ List2Func fin (NatP.<-trans n<m a<sa) t q
lemma4 q _ with FiniteSet.F←Q fin q ≟ fromℕ< n<m
lemma4 q lt | yes p = ⊥-elim ( nat-≡< (toℕ-fromℕ< n<m) (lemma5 n lt (cong (λ k → toℕ k) p))) where
lemma5 : {j k : ℕ } → ( n : ℕ) → suc j ≤ n → j ≡ k → k < n
lemma5 {zero} (suc n) (s≤s z≤n) refl = s≤s z≤n
lemma5 {suc j} (suc n) (s≤s lt) refl = s≤s (lemma5 {j} n lt refl)
lemma4 q _ | no ¬p = refl
lemma3f : F2L fin (NatP.<-trans n<m a<sa) (λ q q<n → List2Func fin (s≤s n<m) (h ∷ t) q ) ≡ t
lemma3f = begin
F2L fin (NatP.<-trans n<m a<sa) (λ q q<n → List2Func fin (s≤s n<m) (h ∷ t) q )
≡⟨ cong (λ k → F2L fin (NatP.<-trans n<m a<sa) ( λ q q<n → k q q<n ))
(f-extensionality ( λ q →
(f-extensionality ( λ q<n → lemma4 q q<n )))) ⟩
F2L fin (NatP.<-trans n<m a<sa) (λ q q<n → List2Func fin (NatP.<-trans n<m a<sa) t q )
≡⟨ f2l n (NatP.<-trans n<m a<sa ) t ⟩
t
∎ where
open ≡-Reasoning
L2F : {Q : Set } {n : ℕ } → (fin : FiniteSet Q ) → n < suc (FiniteSet.finite fin) → Vec Bool n → (q : Q ) → toℕ (FiniteSet.F←Q fin q ) < n → Bool
L2F fin n<m x q q<n = List2Func fin n<m x q
L2F-iso : { Q : Set } → (fin : FiniteSet Q ) → (f : Q → Bool ) → (q : Q ) → (L2F fin a<sa (F2L fin a<sa (λ q _ → f q) )) q (toℕ<n _) ≡ f q
L2F-iso {Q} fin f q = l2f m a<sa (toℕ<n _) where
m = FiniteSet.finite fin
lemma11f : {n : ℕ } → (n<m : n < m ) → ¬ ( FiniteSet.F←Q fin q ≡ fromℕ< n<m ) → toℕ (FiniteSet.F←Q fin q) ≤ n → toℕ (FiniteSet.F←Q fin q) < n
lemma11f n<m ¬q=n q≤n = lemma13 n<m (contra-position (lemma12 n<m _) ¬q=n ) q≤n where
lemma13 : {n nq : ℕ } → (n<m : n < m ) → ¬ ( nq ≡ n ) → nq ≤ n → nq < n
lemma13 {0} {0} (s≤s z≤n) nt z≤n = ⊥-elim ( nt refl )
lemma13 {suc _} {0} (s≤s (s≤s n<m)) nt z≤n = s≤s z≤n
lemma13 {suc n} {suc nq} n<m nt (s≤s nq≤n) = s≤s (lemma13 {n} {nq} (NatP.<-trans a<sa n<m ) (λ eq → nt ( cong ( λ k → suc k ) eq )) nq≤n)
lemma3f : {a b : ℕ } → (lt : a < b ) → fromℕ< (s≤s lt) ≡ suc (fromℕ< lt)
lemma3f (s≤s lt) = refl
lemma12f : {n m : ℕ } → (n<m : n < m ) → (f : Fin m ) → toℕ f ≡ n → f ≡ fromℕ< n<m
lemma12f {zero} {suc m} (s≤s z≤n) zero refl = refl
lemma12f {suc n} {suc m} (s≤s n<m) (suc f) refl = subst ( λ k → suc f ≡ k ) (sym (lemma3f n<m) ) ( cong ( λ k → suc k ) ( lemma12f {n} {m} n<m f refl ) )
l2f : (n : ℕ ) → (n<m : n < suc m ) → (q<n : toℕ (FiniteSet.F←Q fin q ) < n ) → (L2F fin n<m (F2L fin n<m (λ q _ → f q))) q q<n ≡ f q
l2f zero (s≤s z≤n) ()
l2f (suc n) (s≤s n<m) (s≤s n<q) with FiniteSet.F←Q fin q ≟ fromℕ< n<m
l2f (suc n) (s≤s n<m) (s≤s n<q) | yes p = begin
f (FiniteSet.Q←F fin (fromℕ< n<m))
≡⟨ cong ( λ k → f (FiniteSet.Q←F fin k )) (sym p) ⟩
f (FiniteSet.Q←F fin ( FiniteSet.F←Q fin q ))
≡⟨ cong ( λ k → f k ) (FiniteSet.finiso→ fin _ ) ⟩
f q
∎ where
open ≡-Reasoning
l2f (suc n) (s≤s n<m) (s≤s n<q) | no ¬p = l2f n (NatP.<-trans n<m a<sa) (lemma11f n<m ¬p n<q)
fin→ : {A : Set} → FiniteSet A → FiniteSet (A → Bool )
fin→ {A} fin = iso-fin fin2List iso where
a = FiniteSet.finite fin
iso : Bijection (Vec Bool a ) (A → Bool)
fun← iso x = F2L fin a<sa ( λ q _ → x q )
fun→ iso x = List2Func fin a<sa x
fiso← iso x = F2L-iso fin x
fiso→ iso x = lemma where
lemma : List2Func fin a<sa (F2L fin a<sa (λ q _ → x q)) ≡ x
lemma = f-extensionality ( λ q → L2F-iso fin x q )
Fin2Finite : ( n : ℕ ) → FiniteSet (Fin n)
Fin2Finite n = record { F←Q = λ x → x ; Q←F = λ x → x ; finiso← = λ q → refl ; finiso→ = λ q → refl }
data fin-less { n : ℕ } { A : Set } (fa : FiniteSet A ) (n<m : n < FiniteSet.finite fa ) : Set where
elm1 : (elm : A ) → toℕ (FiniteSet.F←Q fa elm ) < n → fin-less fa n<m
get-elm : { n : ℕ } { A : Set } {fa : FiniteSet A } {n<m : n < FiniteSet.finite fa } → fin-less fa n<m → A
get-elm (elm1 a _ ) = a
get-< : { n : ℕ } { A : Set } {fa : FiniteSet A } {n<m : n < FiniteSet.finite fa }→ (f : fin-less fa n<m ) → toℕ (FiniteSet.F←Q fa (get-elm f )) < n
get-< (elm1 _ b ) = b
fin-less-cong : { n : ℕ } { A : Set } (fa : FiniteSet A ) (n<m : n < FiniteSet.finite fa )
→ (x y : fin-less fa n<m ) → get-elm {n} {A} {fa} x ≡ get-elm {n} {A} {fa} y → get-< x ≅ get-< y → x ≡ y
fin-less-cong fa n<m (elm1 elm x) (elm1 elm x) refl HE.refl = refl
fin-< : {A : Set} → { n : ℕ } → (fa : FiniteSet A ) → (n<m : n < FiniteSet.finite fa ) → FiniteSet (fin-less fa n<m )
fin-< {A} {n} fa n<m = iso-fin (Fin2Finite n) iso where
m = FiniteSet.finite fa
iso : Bijection (Fin n) (fin-less fa n<m )
lemma8f : {i j n : ℕ } → ( i ≡ j ) → {i<n : i < n } → {j<n : j < n } → i<n ≅ j<n
lemma8f {zero} {zero} {suc n} refl {s≤s z≤n} {s≤s z≤n} = HE.refl
lemma8f {suc i} {suc i} {suc n} refl {s≤s i<n} {s≤s j<n} = HE.cong (λ k → s≤s k ) ( lemma8f {i} {i} refl )
lemma10f : {n i j : ℕ } → ( i ≡ j ) → {i<n : i < n } → {j<n : j < n } → fromℕ< i<n ≡ fromℕ< j<n
lemma10f refl = HE.≅-to-≡ (HE.cong (λ k → fromℕ< k ) (lemma8f refl ))
lemma3f : {a b c : ℕ } → { a<b : a < b } { b<c : b < c } { a<c : a < c } → NatP.<-trans a<b b<c ≡ a<c
lemma3f {a} {b} {c} {a<b} {b<c} {a<c} = HE.≅-to-≡ (lemma8f refl)
lemma11f : {n : ℕ } {x : Fin n } → (n<m : n < m ) → toℕ (fromℕ< (NatP.<-trans (toℕ<n x) n<m)) ≡ toℕ x
lemma11f {n} {x} n<m = begin
toℕ (fromℕ< (NatP.<-trans (toℕ<n x) n<m))
≡⟨ toℕ-fromℕ< _ ⟩
toℕ x
∎ where
open ≡-Reasoning
fun← iso (elm1 elm x) = fromℕ< x
fun→ iso x = elm1 (FiniteSet.Q←F fa (fromℕ< (NatP.<-trans x<n n<m ))) to<n where
x<n : toℕ x < n
x<n = toℕ<n x
to<n : toℕ (FiniteSet.F←Q fa (FiniteSet.Q←F fa (fromℕ< (NatP.<-trans x<n n<m)))) < n
to<n = subst (λ k → toℕ k < n ) (sym (FiniteSet.finiso← fa _ )) (subst (λ k → k < n ) (sym ( toℕ-fromℕ< (NatP.<-trans x<n n<m) )) x<n )
fiso← iso x = lemma2 where
lemma2 : fromℕ< (subst (λ k → toℕ k < n) (sym
(FiniteSet.finiso← fa (fromℕ< (NatP.<-trans (toℕ<n x) n<m)))) (subst (λ k → k < n)
(sym (toℕ-fromℕ< (NatP.<-trans (toℕ<n x) n<m))) (toℕ<n x))) ≡ x
lemma2 = begin
fromℕ< (subst (λ k → toℕ k < n) (sym
(FiniteSet.finiso← fa (fromℕ< (NatP.<-trans (toℕ<n x) n<m)))) (subst (λ k → k < n)
(sym (toℕ-fromℕ< (NatP.<-trans (toℕ<n x) n<m))) (toℕ<n x)))
≡⟨⟩
fromℕ< ( subst (λ k → toℕ ( k ) < n ) (sym (FiniteSet.finiso← fa _ )) lemma6 )
≡⟨ lemma10 (cong (λ k → toℕ k) (FiniteSet.finiso← fa _ ) ) ⟩
fromℕ< lemma6
≡⟨ lemma10 (lemma11 n<m ) ⟩
fromℕ< ( toℕ<n x )
≡⟨ fromℕ<-toℕ _ _ ⟩
x
∎ where
open ≡-Reasoning
lemma6 : toℕ (fromℕ< (NatP.<-trans (toℕ<n x) n<m)) < n
lemma6 = subst ( λ k → k < n ) (sym (toℕ-fromℕ< (NatP.<-trans (toℕ<n x) n<m))) (toℕ<n x )
fiso→ iso (elm1 elm x) = fin-less-cong fa n<m _ _ lemma (lemma8 (cong (λ k → toℕ (FiniteSet.F←Q fa k) ) lemma ) ) where
lemma13 : toℕ (fromℕ< x) ≡ toℕ (FiniteSet.F←Q fa elm)
lemma13 = begin
toℕ (fromℕ< x)
≡⟨ toℕ-fromℕ< _ ⟩
toℕ (FiniteSet.F←Q fa elm)
∎ where open ≡-Reasoning
lemma : FiniteSet.Q←F fa (fromℕ< (NatP.<-trans (toℕ<n (Bijection.fun← iso (elm1 elm x))) n<m)) ≡ elm
lemma = begin
FiniteSet.Q←F fa (fromℕ< (NatP.<-trans (toℕ<n (Bijection.fun← iso (elm1 elm x))) n<m))
≡⟨⟩
FiniteSet.Q←F fa (fromℕ< ( NatP.<-trans (toℕ<n ( fromℕ< x ) ) n<m))
≡⟨ cong (λ k → FiniteSet.Q←F fa k) (lemma10 lemma13 ) ⟩
FiniteSet.Q←F fa (fromℕ< ( NatP.<-trans x n<m))
≡⟨ cong (λ k → FiniteSet.Q←F fa (fromℕ< k )) (HE.≅-to-≡ (lemma8 refl)) ⟩
FiniteSet.Q←F fa (fromℕ< ( toℕ<n (FiniteSet.F←Q fa elm)))
≡⟨ cong (λ k → FiniteSet.Q←F fa k ) ( fromℕ<-toℕ _ _ ) ⟩
FiniteSet.Q←F fa (FiniteSet.F←Q fa elm )
≡⟨ FiniteSet.finiso→ fa _ ⟩
elm
∎ where open ≡-Reasoning
open import Data.List
open FiniteSet
memberQ : { Q : Set } (finq : FiniteSet Q) (q : Q) (qs : List Q ) → Bool
memberQ {Q} finq q [] = false
memberQ {Q} finq q (q0 ∷ qs) with equal? finq q q0
... | true = true
... | false = memberQ finq q qs
--
-- there is a duplicate element in finite list
--
phase2 : { Q : Set } (finq : FiniteSet Q) (q : Q) (qs : List Q ) → Bool
phase2 finq q [] = false
phase2 finq q (x ∷ qs) with equal? finq q x
... | true = true
... | false = phase2 finq q qs
phase1 : { Q : Set } (finq : FiniteSet Q) (q : Q) (qs : List Q ) → Bool
phase1 finq q [] = false
phase1 finq q (x ∷ qs) with equal? finq q x
... | true = phase2 finq q qs
... | false = phase1 finq q qs
dup-in-list : { Q : Set } (finq : FiniteSet Q) (q : Q) (qs : List Q ) → Bool
dup-in-list {Q} finq q qs = phase1 finq q qs
--
-- if length of the list is longer than kinds of a finite set, there is a duplicate
-- prove this based on the theorem on Data.Fin
--
dup-in-list+fin : { Q : Set } (finq : FiniteSet Q)
→ (q : Q) (qs : List Q )
→ fin-dup-in-list (F←Q finq q) (map (F←Q finq) qs) ≡ true
→ dup-in-list finq q qs ≡ true
dup-in-list+fin {Q} finq q qs p = i-phase1 qs p where
i-phase2 : (qs : List Q) → fin-phase2 (F←Q finq q) (map (F←Q finq) qs) ≡ true
→ phase2 finq q qs ≡ true
i-phase2 (x ∷ qs) p with equal? finq q x | inspect (equal? finq q ) x | <-fcmp (F←Q finq q) (F←Q finq x)
... | true | _ | t = refl
... | false | _ | tri< a ¬b ¬c = i-phase2 qs p
... | false | record { eq = eq } | tri≈ ¬a b ¬c = ⊥-elim (¬-bool eq
(subst₂ (λ j k → equal? finq j k ≡ true) (finiso→ finq q) (subst (λ k → Q←F finq k ≡ x) (sym b) (finiso→ finq x)) ( equal?-refl finq )))
... | false | _ | tri> ¬a ¬b c = i-phase2 qs p
i-phase1 : (qs : List Q) → fin-phase1 (F←Q finq q) (map (F←Q finq) qs) ≡ true
→ phase1 finq q qs ≡ true
i-phase1 (x ∷ qs) p with equal? finq q x | inspect (equal? finq q ) x | <-fcmp (F←Q finq q) (F←Q finq x)
... | true | record { eq = eq } | tri< a ¬b ¬c = ⊥-elim ( nat-≡< (cong (λ x → toℕ (F←Q finq x)) ( equal→refl finq eq )) a )
... | true | _ | tri≈ ¬a b ¬c = i-phase2 qs p
... | true | record { eq = eq} | tri> ¬a ¬b c = ⊥-elim ( nat-≡< (cong (λ x → toℕ (F←Q finq x)) (sym ( equal→refl finq eq ))) c )
... | false | _ | tri< a ¬b ¬c = i-phase1 qs p
... | false | record {eq = eq} | tri≈ ¬a b ¬c = ⊥-elim (¬-bool eq
(subst₂ (λ j k → equal? finq j k ≡ true) (finiso→ finq q) (subst (λ k → Q←F finq k ≡ x) (sym b) (finiso→ finq x)) ( equal?-refl finq )))
... | false | _ | tri> ¬a ¬b c = i-phase1 qs p
record Dup-in-list {Q : Set } (finq : FiniteSet Q) (qs : List Q) : Set where
field
dup : Q
is-dup : dup-in-list finq dup qs ≡ true
dup-in-list>n : {Q : Set } → (finq : FiniteSet Q) → (qs : List Q) → (len> : length qs > finite finq ) → Dup-in-list finq qs
dup-in-list>n {Q} finq qs lt = record { dup = Q←F finq (FDup-in-list.dup dl)
; is-dup = dup-in-list+fin finq (Q←F finq (FDup-in-list.dup dl)) qs dl01 } where
maplen : (qs : List Q) → length (map (F←Q finq) qs) ≡ length qs
maplen [] = refl
maplen (x ∷ qs) = cong suc (maplen qs)
dl : FDup-in-list (finite finq ) (map (F←Q finq) qs)
dl = fin-dup-in-list>n (map (F←Q finq) qs) (subst (λ k → k > finite finq ) (sym (maplen qs)) lt)
dl01 : fin-dup-in-list (F←Q finq (Q←F finq (FDup-in-list.dup dl))) (map (F←Q finq) qs) ≡ true
dl01 = subst (λ k → fin-dup-in-list k (map (F←Q finq) qs) ≡ true )
(sym (finiso← finq _)) ( FDup-in-list.is-dup dl )
|
{
"alphanum_fraction": 0.5169243168,
"avg_line_length": 48.4007092199,
"ext": "agda",
"hexsha": "ccf51ffdad96f2ff78bcd841fcd0c2bf12b0ddd1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/automaton-in-agda",
"max_forks_repo_path": "src/finiteSetUtil.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/automaton-in-agda",
"max_issues_repo_path": "src/finiteSetUtil.agda",
"max_line_length": 159,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/automaton-in-agda",
"max_stars_repo_path": "src/finiteSetUtil.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 11571,
"size": 27298
}
|
module STLC.Lib.MaybeElim where
open import Level
open import Function
open import Relation.Binary.PropositionalEquality
open import Data.Unit.Base
open import Data.Bool.Base
open import Data.Maybe.Base
infixl 1 _>>=ᵀ_ _>>=ᵗ_ _>>=⊤_
infixl 4 _<$>ᵗ_
infixr 1 _>=>ᵗ_
infixr 10 _<∘>ᵗ_
data _>>=ᵀ_ {α β} {A : Set α} : (mx : Maybe A) -> (∀ x -> mx ≡ just x -> Set β) -> Set β where
nothingᵗ : ∀ {B} -> nothing >>=ᵀ B
justᵗ : ∀ {x B} -> B x refl -> just x >>=ᵀ B
-- We could write (Set (maybe (const β) zero mx)),
-- but I don't want to introduce dependency at the type level.
FromJustᵗ : ∀ {α β} {A : Set α} {mx : Maybe A} {B : ∀ x -> mx ≡ just x -> Set β}
-> mx >>=ᵀ B -> Set β
FromJustᵗ nothingᵗ = Lift ⊤
FromJustᵗ (justᵗ {x} {B} y) = B x refl
fromJustᵗ : ∀ {α β} {A : Set α} {mx : Maybe A} {B : ∀ x -> mx ≡ just x -> Set β}
-> (yᵗ : mx >>=ᵀ B) -> FromJustᵗ yᵗ
fromJustᵗ nothingᵗ = _
fromJustᵗ (justᵗ y) = y
_>>=ᵗ_ : ∀ {α β} {A : Set α} {B : A -> Set β}
-> (mx : Maybe A) -> (∀ x -> B x) -> mx >>=ᵀ λ x _ -> B x
nothing >>=ᵗ f = nothingᵗ
just x >>=ᵗ f = justᵗ (f x)
_>>=⊤_ : ∀ {α β} {A : Set α} {B : A -> Set β}
-> (mx : Maybe A) -> (g : ∀ x -> B x) -> FromJustᵗ (mx >>=ᵗ g)
mx >>=⊤ g = fromJustᵗ $ mx >>=ᵗ g
runᵗ : ∀ {α β} {A : Set α} {mx : Maybe A} {B : ∀ x -> mx ≡ just x -> Set β} {x}
-> mx >>=ᵀ B -> (p : mx ≡ just x) -> B x p
runᵗ (justᵗ y) refl = y
_<$>ᵗ_ : ∀ {α β γ} {A : Set α} {mx : Maybe A}
{B : ∀ x -> mx ≡ just x -> Set β}
{C : ∀ {x} {p : mx ≡ just x} -> B x p -> Set γ}
-> (∀ {x} {p : mx ≡ just x} -> (y : B x p) -> C y)
-> (yᵗ : mx >>=ᵀ B)
-> mx >>=ᵀ λ _ -> C ∘ runᵗ yᵗ
g <$>ᵗ nothingᵗ = nothingᵗ
g <$>ᵗ justᵗ y = justᵗ (g y)
_>=>ᵗ_ : ∀ {α β γ} {A : Set α} {B : A -> Set β} {C : ∀ {x} -> B x -> Set γ}
-> (f : ∀ x -> Maybe (B x))
-> (∀ {x} -> (y : B x) -> C y)
-> ∀ x -> f x >>=ᵀ λ y _ -> C y
(f >=>ᵗ g) x = f x >>=ᵗ g
_<∘>ᵗ_ : ∀ {α β γ δ} {A : Set α} {B : A -> Set β} {f : ∀ x -> Maybe (B x)}
{C : ∀ x y -> f x ≡ just y -> Set γ}
{D : ∀ {x y} {p : f x ≡ just y} -> C x y p -> Set δ}
-> (∀ {x y} {p : f x ≡ just y} -> (z : C x y p) -> D z)
-> (g : ∀ x -> f x >>=ᵀ C x)
-> ∀ x -> f x >>=ᵀ λ _ -> D ∘ runᵗ (g x)
(h <∘>ᵗ g) x = h <$>ᵗ g x
|
{
"alphanum_fraction": 0.4342442357,
"avg_line_length": 35.4848484848,
"ext": "agda",
"hexsha": "fd05f0e802c6e2e936f46642d38d911abdabaaeb",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-06T19:34:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-13T12:44:41.000Z",
"max_forks_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ajnavarro/language-dataset",
"max_forks_repo_path": "data/github.com/effectfully/STLC/3826d7555f37d032d07cf414c7f6770fc32918f1/src/STLC/Lib/MaybeElim.agda",
"max_issues_count": 91,
"max_issues_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_issues_repo_issues_event_max_datetime": "2022-03-21T04:17:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-11-11T15:41:26.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ajnavarro/language-dataset",
"max_issues_repo_path": "data/github.com/effectfully/STLC/3826d7555f37d032d07cf414c7f6770fc32918f1/src/STLC/Lib/MaybeElim.agda",
"max_line_length": 94,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ajnavarro/language-dataset",
"max_stars_repo_path": "data/github.com/effectfully/STLC/3826d7555f37d032d07cf414c7f6770fc32918f1/src/STLC/Lib/MaybeElim.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-11T09:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-08-07T11:54:33.000Z",
"num_tokens": 1106,
"size": 2342
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some code related to indexed containers that uses heterogeneous
-- equality
------------------------------------------------------------------------
-- The notation and presentation here is perhaps close to those used
-- by Hancock and Hyvernat in "Programming interfaces and basic
-- topology" (2006).
{-# OPTIONS --with-K --safe --guardedness #-}
module Data.Container.Indexed.WithK where
open import Axiom.Extensionality.Heterogeneous using (Extensionality)
open import Data.Container.Indexed hiding (module PlainMorphism)
open import Data.Product as Prod hiding (map)
open import Function renaming (id to ⟨id⟩; _∘_ to _⟨∘⟩_)
open import Level
open import Relation.Unary using (Pred; _⊆_)
open import Relation.Binary.PropositionalEquality as P using (_≡_; refl)
open import Relation.Binary.HeterogeneousEquality as H using (_≅_; refl)
open import Relation.Binary.Indexed.Heterogeneous
------------------------------------------------------------------------
-- Equality, parametrised on an underlying relation.
Eq : ∀ {i o c r ℓ} {I : Set i} {O : Set o} (C : Container I O c r)
(X Y : Pred I ℓ) → IREL X Y ℓ → IREL (⟦ C ⟧ X) (⟦ C ⟧ Y) _
Eq C _ _ _≈_ {o₁} {o₂} (c , k) (c′ , k′) =
o₁ ≡ o₂ × c ≅ c′ × (∀ r r′ → r ≅ r′ → k r ≈ k′ r′)
private
-- Note that, if propositional equality were extensional, then Eq _≅_
-- and _≅_ would coincide.
Eq⇒≅ : ∀ {i o c r ℓ} {I : Set i} {O : Set o}
{C : Container I O c r} {X : Pred I ℓ} {o₁ o₂ : O}
{xs : ⟦ C ⟧ X o₁} {ys : ⟦ C ⟧ X o₂} → Extensionality r ℓ →
Eq C X X (λ x₁ x₂ → x₁ ≅ x₂) xs ys → xs ≅ ys
Eq⇒≅ {xs = c , k} {.c , k′} ext (refl , refl , k≈k′) =
H.cong (_,_ c) (ext (λ _ → refl) (λ r → k≈k′ r r refl))
setoid : ∀ {i o c r s} {I : Set i} {O : Set o} →
Container I O c r → IndexedSetoid I s _ → IndexedSetoid O _ _
setoid C X = record
{ Carrier = ⟦ C ⟧ X.Carrier
; _≈_ = _≈_
; isEquivalence = record
{ refl = refl , refl , λ { r .r refl → X.refl }
; sym = sym
; trans = λ { {_} {i = xs} {ys} {zs} → trans {_} {i = xs} {ys} {zs} }
}
}
where
module X = IndexedSetoid X
_≈_ : IRel (⟦ C ⟧ X.Carrier) _
_≈_ = Eq C X.Carrier X.Carrier X._≈_
sym : Symmetric (⟦ C ⟧ X.Carrier) _≈_
sym {_} {._} {_ , _} {._ , _} (refl , refl , k) =
refl , refl , λ { r .r refl → X.sym (k r r refl) }
trans : Transitive (⟦ C ⟧ X.Carrier) _≈_
trans {._} {_} {._} {_ , _} {._ , _} {._ , _}
(refl , refl , k) (refl , refl , k′) =
refl , refl , λ { r .r refl → X.trans (k r r refl) (k′ r r refl) }
------------------------------------------------------------------------
-- Functoriality
module Map where
identity : ∀ {i o c r s} {I : Set i} {O : Set o} (C : Container I O c r)
(X : IndexedSetoid I s _) → let module X = IndexedSetoid X in
∀ {o} {xs : ⟦ C ⟧ X.Carrier o} → Eq C X.Carrier X.Carrier
X._≈_ xs (map C {X.Carrier} ⟨id⟩ xs)
identity C X = IndexedSetoid.refl (setoid C X)
composition : ∀ {i o c r s ℓ₁ ℓ₂} {I : Set i} {O : Set o}
(C : Container I O c r) {X : Pred I ℓ₁} {Y : Pred I ℓ₂}
(Z : IndexedSetoid I s _) → let module Z = IndexedSetoid Z in
{f : Y ⊆ Z.Carrier} {g : X ⊆ Y} {o : O} {xs : ⟦ C ⟧ X o} →
Eq C Z.Carrier Z.Carrier Z._≈_
(map C {Y} f (map C {X} g xs))
(map C {X} (f ⟨∘⟩ g) xs)
composition C Z = IndexedSetoid.refl (setoid C Z)
------------------------------------------------------------------------
-- Plain morphisms
module PlainMorphism {i o c r} {I : Set i} {O : Set o} where
open Data.Container.Indexed.PlainMorphism
-- Naturality.
Natural : ∀ {ℓ} {C₁ C₂ : Container I O c r} →
((X : Pred I ℓ) → ⟦ C₁ ⟧ X ⊆ ⟦ C₂ ⟧ X) → Set _
Natural {C₁ = C₁} {C₂} m =
∀ {X} Y → let module Y = IndexedSetoid Y in (f : X ⊆ Y.Carrier) →
∀ {o} (xs : ⟦ C₁ ⟧ X o) →
Eq C₂ Y.Carrier Y.Carrier Y._≈_
(m Y.Carrier $ map C₁ {X} f xs) (map C₂ {X} f $ m X xs)
-- Natural transformations.
NT : ∀ {ℓ} (C₁ C₂ : Container I O c r) → Set _
NT {ℓ} C₁ C₂ = ∃ λ (m : (X : Pred I ℓ) → ⟦ C₁ ⟧ X ⊆ ⟦ C₂ ⟧ X) →
Natural m
-- Container morphisms are natural.
natural : ∀ {ℓ} (C₁ C₂ : Container I O c r) (m : C₁ ⇒ C₂) → Natural {ℓ} ⟪ m ⟫
natural _ _ m {X} Y f _ = refl , refl , λ { r .r refl → lemma (coherent m) }
where
module Y = IndexedSetoid Y
lemma : ∀ {i j} (eq : i ≡ j) {x} →
P.subst Y.Carrier eq (f x) Y.≈ f (P.subst X eq x)
lemma refl = Y.refl
-- In fact, all natural functions of the right type are container
-- morphisms.
complete : ∀ {C₁ C₂ : Container I O c r} (nt : NT C₁ C₂) →
∃ λ m → (X : IndexedSetoid I _ _) →
let module X = IndexedSetoid X in
∀ {o} (xs : ⟦ C₁ ⟧ X.Carrier o) →
Eq C₂ X.Carrier X.Carrier X._≈_
(proj₁ nt X.Carrier xs) (⟪ m ⟫ X.Carrier {o} xs)
complete {C₁} {C₂} (nt , nat) = m , (λ X xs → nat X
(λ { (r , eq) → P.subst (IndexedSetoid.Carrier X) eq (proj₂ xs r) })
(proj₁ xs , (λ r → r , refl)))
where
m : C₁ ⇒ C₂
m = record
{ command = λ c₁ → proj₁ (lemma c₁)
; response = λ {_} {c₁} r₂ → proj₁ (proj₂ (lemma c₁) r₂)
; coherent = λ {_} {c₁} {r₂} → proj₂ (proj₂ (lemma c₁) r₂)
}
where
lemma : ∀ {o} (c₁ : Command C₁ o) → Σ[ c₂ ∈ Command C₂ o ]
((r₂ : Response C₂ c₂) → Σ[ r₁ ∈ Response C₁ c₁ ]
next C₁ c₁ r₁ ≡ next C₂ c₂ r₂)
lemma c₁ = nt (λ i → Σ[ r₁ ∈ Response C₁ c₁ ] next C₁ c₁ r₁ ≡ i)
(c₁ , λ r₁ → r₁ , refl)
-- Composition commutes with ⟪_⟫.
∘-correct : {C₁ C₂ C₃ : Container I O c r}
(f : C₂ ⇒ C₃) (g : C₁ ⇒ C₂) (X : IndexedSetoid I (c ⊔ r) _) →
let module X = IndexedSetoid X in
∀ {o} {xs : ⟦ C₁ ⟧ X.Carrier o} →
Eq C₃ X.Carrier X.Carrier X._≈_
(⟪ f ∘ g ⟫ X.Carrier xs)
(⟪ f ⟫ X.Carrier (⟪ g ⟫ X.Carrier xs))
∘-correct f g X = refl , refl , λ { r .r refl → lemma (coherent g)
(coherent f) }
where
module X = IndexedSetoid X
lemma : ∀ {i j k} (eq₁ : i ≡ j) (eq₂ : j ≡ k) {x} →
P.subst X.Carrier (P.trans eq₁ eq₂) x
X.≈
P.subst X.Carrier eq₂ (P.subst X.Carrier eq₁ x)
lemma refl refl = X.refl
------------------------------------------------------------------------
-- All and any
-- Membership.
infix 4 _∈_
_∈_ : ∀ {i o c r ℓ} {I : Set i} {O : Set o}
{C : Container I O c r} {X : Pred I (i ⊔ ℓ)} → IREL X (⟦ C ⟧ X) _
_∈_ {C = C} {X} x xs = ◇ C {X = X} ((x ≅_) ⟨∘⟩ proj₂) (-, xs)
|
{
"alphanum_fraction": 0.480209546,
"avg_line_length": 37.347826087,
"ext": "agda",
"hexsha": "5fa10e4b829c0b98a9f770e891bce3df9f8940f0",
"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": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Indexed/WithK.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/Container/Indexed/WithK.agda",
"max_line_length": 79,
"max_stars_count": 5,
"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/Container/Indexed/WithK.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": 2470,
"size": 6872
}
|
module Logic.Classical.DoubleNegated where
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
open import Functional
open import Logic.Names
open import Logic.Propositional as Constructive using (¬¬_)
import Logic.Predicate as Constructive
open import Logic
import Lvl
open import Syntax.Type
open import Type
private variable ℓ ℓ₁ ℓ₂ : Lvl.Level
private variable X Y Z W : Stmt{ℓ}
private variable P : X → Stmt{ℓ}
-- Classical propositions are expressed as propositions wrapped in double negation.
-- TODO: I am not sure, but I think this works? My reasoning is the following:
-- • [¬¬]-elim ↔ excluded-middle
-- Double negation elimination is equivalent to excluded middle in constructive logic.
-- • Theory(ClassicalLogic) = Theory(ConstructiveLogic ∪ {excludedMiddle})
-- Constructive logic is classical logic without EM.
-- EM is the difference between classical and constructive.
-- • Theory(ClassicalLogic) ⊈ Theory(ConstructiveLogic)
-- • Theory(ClassicalLogic) ⊇ Theory(ConstructiveLogic)
-- This seems to be a common description of constructive logic.
-- • [¬¬]-intro ∈ Theory(ConstructiveLogic)
-- Double negation introduction exists in constructive logic.
-- • (∀φ. ¬¬¬¬φ → ¬¬φ) ∈ Theory(ConstructiveLogic)
-- Double negation elimination exists inside a double negation in constructive logic.
-- • Every natural deduction introduction/elimination rule in constructive logic can be expressed inside a double negation.
-- Therefore:
-- • Theory(ClassicalLogic) = Theory(ConstructiveLogic ∪ {[¬¬]-elim}).
-- • The theory inside double negation in constructive logic is (at least) a classical logic.
-- Because every intro/elim rule exists in there,
-- the propositions inside a double negation are at least a constructive logic.
-- But [¬¬]-elim also exists in there.
-- Therefore it is at least a classical logic.
-- This cannot be done with predicate logic because the translation for [∀] does not hold in both directions.
module _ where
infixl 1011 •_
infixl 1010 ¬_
infixl 1005 _∧_
infixl 1004 _∨_
infixl 1000 _⟵_ _⟷_ _⟶_
•_ : Stmt{ℓ} → Stmt
•_ = ¬¬_
_∧_ : Stmt{ℓ₁} → Stmt{ℓ₂} → Stmt
_∧_ = (¬¬_) ∘₂ (Constructive._∧_)
_⟶_ : Stmt{ℓ₁} → Stmt{ℓ₂} → Stmt
_⟶_ = (¬¬_) ∘₂ (_→ᶠ_)
_⟵_ : Stmt{ℓ₁} → Stmt{ℓ₂} → Stmt
_⟵_ = (¬¬_) ∘₂ (_←_)
_⟷_ : Stmt{ℓ₁} → Stmt{ℓ₂} → Stmt
_⟷_ = (¬¬_) ∘₂ (Constructive._↔_)
_∨_ : Stmt{ℓ₁} → Stmt{ℓ₂} → Stmt
_∨_ = (¬¬_) ∘₂ (Constructive._∨_)
⊥ : Stmt
⊥ = ¬¬ Constructive.⊥
⊤ : Stmt
⊤ = ¬¬ Constructive.⊤
¬_ : Stmt{ℓ} → Stmt
¬_ = (¬¬_) ∘ Constructive.¬_
∀ₗ : (X → Stmt{ℓ}) → Stmt
∀ₗ = (¬¬_) ∘ Constructive.∀ₗ ∘ ((¬¬_) ∘_)
∃ : (X → Stmt{ℓ}) → Stmt
∃ = (¬¬_) ∘ Constructive.∃
import Logic.Propositional.Theorems as Constructive
import Logic.Predicate.Theorems as Constructive
[→]ₗ-[¬¬]-elim : ((¬¬ X) → Y) → (X → Y)
[→]ₗ-[¬¬]-elim = liftᵣ(Constructive.[¬¬]-intro)
[→]ᵣ-[¬¬]-move-out : (X → (¬¬ Y)) → ¬¬(X → Y)
[→]ᵣ-[¬¬]-move-out xnny nxy = nxy (x ↦ Constructive.[⊥]-elim(xnny x (y ↦ nxy (const y))))
double-contrapositiveᵣ : (X → Y) → ((¬¬ X) → (¬¬ Y)) -- DoubleNegated(X → Y) → DoubleNegated(¬¬ X → ¬¬ Y)
double-contrapositiveᵣ = Constructive.contrapositiveᵣ ∘ Constructive.contrapositiveᵣ
[¬¬]-double-contrapositiveₗ : ¬¬(X → Y) ← ((¬¬ X) → (¬¬ Y))
[¬¬]-double-contrapositiveₗ p = [→]ᵣ-[¬¬]-move-out ([→]ₗ-[¬¬]-elim p)
-- Also called: Double-negation shift.
[¬¬][→]-preserving : ¬¬(X → Y) Constructive.↔ ((¬¬ X) → (¬¬ Y))
[¬¬][→]-preserving{X = X}{Y = Y} = Constructive.[↔]-intro l r where
l : ¬¬(X → Y) ← ((¬¬ X) → (¬¬ Y))
l = [→]ᵣ-[¬¬]-move-out ∘ [→]ₗ-[¬¬]-elim
r : ¬¬(X → Y) → ((¬¬ X) → (¬¬ Y))
r(nnxy)(nnx)(ny) =
((Constructive.[→]-elim
((xy ↦
((Constructive.[→]-elim
((Constructive.[→]-elim
((Constructive.[⊥]-elim
((Constructive.[→]-elim
((x ↦
((Constructive.[→]-elim
((Constructive.[→]-elim x xy) :of: Y)
(ny :of: (Y → Constructive.⊥))
) :of: Constructive.⊥)
) :of: (X → Constructive.⊥))
(nnx :of: ((X → Constructive.⊥) → Constructive.⊥))
) :of: Constructive.⊥)
) :of: X)
(xy :of: (X → Y))
) :of: Y)
(ny :of: (Y → Constructive.⊥))
) :of: Constructive.⊥)
) :of: ((X → Y) → Constructive.⊥))
(nnxy :of: ¬¬(X → Y))
) :of: Constructive.⊥)
------------------------------------------
-- Converting theorems with implication in constructive logic to classical logic
prop-intro : X → (¬¬ X)
prop-intro = Constructive.[¬¬]-intro
[→]₁-intro : (X → Y) → ((¬¬ X) → (¬¬ Y))
[→]₁-intro = double-contrapositiveᵣ
[→]₂-intro : (X → Y → Z) → ((¬¬ X) → (¬¬ Y) → (¬¬ Z))
[→]₂-intro(xyz) = (Constructive.[↔]-to-[→] [¬¬][→]-preserving) ∘ ([→]₁-intro(xyz))
[→]₃-intro : (X → Y → Z → W) → ((¬¬ X) → (¬¬ Y) → (¬¬ Z) → (¬¬ W))
[→]₃-intro(xyzw) = (Constructive.[↔]-to-[→] [¬¬][→]-preserving) ∘₂ ([→]₂-intro(xyzw))
------------------------------------------
-- Theorems
[→][∧]-assumptionₗ : ¬¬((X Constructive.∧ Y) → Z) ← ¬¬(X → Y → Z)
[→][∧]-assumptionₗ = [→]₁-intro(Tuple.uncurry)
[→][∧]-assumptionᵣ : ¬¬((X Constructive.∧ Y) → Z) → ¬¬(X → Y → Z)
[→][∧]-assumptionᵣ = [→]₁-intro(Tuple.curry)
[¬¬]-intro : (¬¬ X) → ¬¬(¬¬ X)
[¬¬]-intro = Constructive.[¬¬]-intro
------------------------------------------
-- Conjunction (AND)
[∧]-intro : (• X) → (• Y) → (X ∧ Y)
[∧]-intro = [→]₂-intro Constructive.[∧]-intro
[∧]-elimₗ : (X ∧ Y) → (• X)
[∧]-elimₗ = [→]₁-intro Constructive.[∧]-elimₗ
[∧]-elimᵣ : (X ∧ Y) → (• Y)
[∧]-elimᵣ = [→]₁-intro Constructive.[∧]-elimᵣ
------------------------------------------
-- Implication
[→]-elim : (X ⟶ Y) → (• X) → (• Y)
[→]-elim = [→]₂-intro(swap Constructive.[→]-elim)
[→]-intro : ((• X) → (• Y)) → (X ⟶ Y)
[→]-intro = [¬¬]-double-contrapositiveₗ
------------------------------------------
-- Reverse implication
[←]-intro : ((• Y) ← (• X)) → (Y ⟵ X)
[←]-intro = [¬¬]-double-contrapositiveₗ
[←]-elim : (• X) → (Y ⟵ X) → (• Y)
[←]-elim = [→]₂-intro(Constructive.[←]-elim)
------------------------------------------
-- Equivalence
[↔]-intro : ((• X) ← (• Y)) → ((• X) → (• Y)) → (X ⟷ Y)
[↔]-intro yx xy = ([→]₂-intro(Constructive.[↔]-intro)) ([→]-intro yx) ([→]-intro xy)
[↔]-elimₗ : (X ⟷ Y) → (• X) ← (• Y)
[↔]-elimₗ = [→]-elim ∘ ([→]₁-intro(Constructive.[↔]-to-[←]))
[↔]-elimᵣ : (X ⟷ Y) → (• X) → (• Y)
[↔]-elimᵣ = [→]-elim ∘ ([→]₁-intro(Constructive.[↔]-to-[→]))
------------------------------------------
-- Disjunction (OR)
[∨]-introₗ : (• X) → (X ∨ Y)
[∨]-introₗ = [→]₁-intro(Constructive.[∨]-introₗ)
[∨]-introᵣ : (• Y) → (X ∨ Y)
[∨]-introᵣ = [→]₁-intro(Constructive.[∨]-introᵣ)
[∨]-elim : ((• X) → (• Z)) → ((• Y) → (• Z)) → (X ∨ Y) → (¬¬ Z)
[∨]-elim xz yz = ([→]₃-intro(Constructive.[∨]-elim)) ([→]-intro xz) ([→]-intro yz)
------------------------------------------
-- Bottom (false, absurdity, empty, contradiction)
[⊥]-intro : (• X) → (¬ X) → ⊥
[⊥]-intro = [→]₂-intro(Constructive.[⊥]-intro)
[⊥]-elim : ⊥ → (• X)
[⊥]-elim = [→]₁-intro(Constructive.[⊥]-elim)
------------------------------------------
-- Top (true, truth, unit, validity)
[⊤]-intro : ⊤
[⊤]-intro = prop-intro(Constructive.[⊤]-intro)
------------------------------------------
-- Negation
[¬]-intro : ((• X) → ⊥) → (¬ X)
[¬]-intro = ([→]₁-intro(Constructive.[¬]-intro)) ∘ [→]-intro
[¬]-elim : ((¬ X) → ⊥) → (• X)
[¬]-elim nnx nx = nnx (apply nx) id
------------------------------------------
-- For-all quantification
[∀]-intro : (∀{x} → • P(x)) → (∀ₗ P)
[∀]-intro = apply
[∀]-elim : (∀ₗ P) → ∀{x} → • P(x)
[∀]-elim apx npx = apx(\px → apply npx px)
------------------------------------------
-- Existential quantification
[∃]-intro : ∀{x} → • P(x) → (∃ P)
[∃]-intro {x = x} = [→]₁-intro(proof ↦ Constructive.[∃]-intro (x) ⦃ proof ⦄)
[∃]-elim : (∀{x} → • P(x) → • X) → (∃ P) → • X
[∃]-elim apx nnep nx = nnep (Constructive.[∃]-elim (p ↦ apx (apply p) nx))
------------------------------------------
-- Theorems exclusive to classic logic (compared to constructive logic)
[¬¬]-elim : ¬¬(¬¬ X) → (• X)
[¬¬]-elim = Constructive.[¬¬¬]-elim
excluded-middle : (X ∨ (Constructive.¬ X))
excluded-middle{X = X} = Constructive.[¬¬]-excluded-middle
[→]-disjunctive-formᵣ : (X ⟶ Y) → (Constructive.¬ X ∨ Y)
[→]-disjunctive-formᵣ n-n-x→y n-nx∨y = (n-nx∨y ∘ Constructive.[∨]-introₗ) (n-n-x→y ∘ (n-nx∨y ∘ Constructive.[∨]-introᵣ ∘₂ apply))
-- contrapositiveₗ : (X ⟶ Y) ← ((Constructive.¬ X) ⟵ (Constructive.¬ Y))
-- contrapositiveₗ n-n-ny→nx = {!!}
-- Constructive.[→]-intro ([¬¬]-elim ∘ Constructive.contrapositiveᵣ(Constructive.[→]-elim n-n-ny→nx) ∘ Constructive.[¬¬]-intro)
module _ where
_∨ʷᵉᵃᵏ_ : Stmt{ℓ₁} → Stmt{ℓ₂} → Stmt
X ∨ʷᵉᵃᵏ Y = Constructive.¬((Constructive.¬ X) Constructive.∧ (Constructive.¬ Y))
[∨ʷᵉᵃᵏ]-introₗ : X → (X ∨ʷᵉᵃᵏ Y)
[∨ʷᵉᵃᵏ]-introₗ = swap Constructive.[∧]-elimₗ
[∨ʷᵉᵃᵏ]-introᵣ : Y → (X ∨ʷᵉᵃᵏ Y)
[∨ʷᵉᵃᵏ]-introᵣ = swap Constructive.[∧]-elimᵣ
[∨ʷᵉᵃᵏ]-elim : (X → Z) → (Y → Z) → DoubleNegationOn(Z) → (X ∨ʷᵉᵃᵏ Y) → Z
[∨ʷᵉᵃᵏ]-elim xz yz nnzz xy = nnzz(nz ↦ xy(Constructive.[∧]-intro (nz ∘ xz) (nz ∘ yz)))
∃ʷᵉᵃᵏ : (X → Stmt{ℓ}) → Stmt
∃ʷᵉᵃᵏ P = Constructive.¬(∀{x} → (Constructive.¬ P(x)))
[∃ʷᵉᵃᵏ]-intro : ∀(x) → ⦃ proof : P(x) ⦄ → (∃ʷᵉᵃᵏ P)
[∃ʷᵉᵃᵏ]-intro _ ⦃ px ⦄ axnpx = axnpx px
[∃ʷᵉᵃᵏ]-elim : (∀{x} → P(x) → X) → DoubleNegationOn(X) → (∃ʷᵉᵃᵏ P) → X
[∃ʷᵉᵃᵏ]-elim axpxx nnxx ep = nnxx(ep ∘ (_∘ axpxx))
|
{
"alphanum_fraction": 0.5012774655,
"avg_line_length": 34.2132867133,
"ext": "agda",
"hexsha": "af3a8e62ed1d5a86964ca3f47800374a1df47bda",
"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": "Logic/Classical/DoubleNegated.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": "Logic/Classical/DoubleNegated.agda",
"max_line_length": 131,
"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": "Logic/Classical/DoubleNegated.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": 4047,
"size": 9785
}
|
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Identity
open import HoTT.Identity.Boolean
open import HoTT.Identity.Coproduct
open import HoTT.Identity.Sigma
open import HoTT.Identity.Identity
open import HoTT.Identity.Pi
open import HoTT.Identity.NaturalNumber
open import HoTT.Transport.Identity
open import HoTT.Equivalence
open import HoTT.Equivalence.Lift
open import HoTT.Equivalence.Transport
open import HoTT.Homotopy
module HoTT.HLevel where
open variables
private variable n : ℕ
isContr : 𝒰 i → 𝒰 i
isContr A = Σ[ a ∶ A ] Π[ x ∶ A ] (a == x)
-- Use a record so that we can use instances (technique from HoTT-Agda)
record hlevel (n : ℕ) (A : 𝒰 i) : 𝒰 i
hlevel-type : ℕ → 𝒰 i → 𝒰 i
hlevel-type zero = isContr
hlevel-type (succ n) A = {x y : A} → hlevel n (x == y)
record hlevel n A where
inductive
eta-equality
constructor hlevel-in
field hlevel-out : hlevel-type n A
open hlevel public
center : ⦃ hlevel 0 A ⦄ → A
center ⦃ hlevel-in (c , _) ⦄ = c
contr : ⦃ _ : hlevel 0 A ⦄ {x : A} → center == x
contr ⦃ hlevel-in (_ , p) ⦄ = p _
isProp : 𝒰 i → 𝒰 i
isProp A = (x y : A) → x == y
record hlevel𝒰 (n : ℕ) (i : _) : 𝒰 (lsuc i) where
constructor type
infix 90 _ty
field
_ty : 𝒰 i
⦃ h ⦄ : hlevel n _ty
open hlevel𝒰 using (_ty) public
Prop𝒰 = hlevel𝒰 1
Prop𝒰₀ = Prop𝒰 lzero
isSet : 𝒰 i → 𝒰 i
isSet A = {x y : A} → isProp (x == y)
Set𝒰 = hlevel𝒰 2
Set𝒰₀ = Set𝒰 lzero
instance
=-hlevel : {x y : A} → ⦃ hlevel (succ n) A ⦄ → hlevel n (x == y)
=-hlevel ⦃ hlevel-in h ⦄ = h
_◃_ : 𝒰 i → 𝒰 j → 𝒰 (i ⊔ j)
A ◃ B = Σ (A → B) rinv
infixr 5 _◃_
-- Theorem 7.1.4
retract-hlevel : A ◃ B → ⦃ hlevel n A ⦄ → hlevel n B
retract-hlevel {n = zero} (p , s , ε) = hlevel-in (p center , λ b → ap p contr ∙ ε b)
retract-hlevel {A = A} {B = B} {n = succ n} (p , s , ε) =
hlevel-in (retract-hlevel {n = n} r)
where
-- t =
r : {y y' : B} → (s y == s y') ◃ (y == y')
r {y} {y'} = t , ap s , λ u →
ε y ⁻¹ ∙ ap p (ap s u) ∙ ε y' =⟨ _ ∙ₗ ap-∘ p s u ⁻¹ ∙ᵣ _ ⟩
ε y ⁻¹ ∙ ap (p ∘ s) u ∙ ε y' =⟨ assoc ⁻¹ ⟩
ε y ⁻¹ ∙ (ap (p ∘ s) u ∙ ε y') =⟨ pivotₗ (~-natural-id ε u) ⁻¹ ⟩
u ∎
where
open =-Reasoning
t : _
t q = ε y ⁻¹ ∙ ap p q ∙ ε y'
equiv-hlevel : A ≃ B → ⦃ hlevel n A ⦄ → hlevel n B
equiv-hlevel e = retract-hlevel (pr₁ e , qinv→rinv (isequiv→qinv (pr₂ e)))
Π-implicit-equiv : ({x : A} → P x) ≃ Π A P
Π-implicit-equiv = iso→eqv λ{.f x _ → x ; .g h → h _ ; .η _ → refl ; .ε _ → refl}
where open Iso
raise : ⦃ {_ : A} → hlevel n A ⦄ → hlevel (succ n) A
raise {n = zero} ⦃ f ⦄ = hlevel-in λ {x} →
hlevel-in (contr ⦃ f {x} ⦄ ⁻¹ ∙ contr , λ{refl → invₗ})
raise {n = succ n} ⦃ f ⦄ = hlevel-in λ {x} →
raise ⦃ =-hlevel ⦃ f {x} ⦄ ⦄
add : ℕ → ℕ → ℕ
add n zero = n
add n (succ m) = succ (add n m)
raise* : {A : 𝒰 i} → ⦃ hlevel n A ⦄ → {m : ℕ} → hlevel (add n (succ m)) A
raise* {m = zero} = raise
raise* {m = succ m} = raise ⦃ raise* ⦄
instance
Lift-hlevel : ⦃ hlevel n A ⦄ → hlevel n (Lift {i} A)
Lift-hlevel = equiv-hlevel (Lift-equiv ⁻¹ₑ)
𝟎-hlevel : hlevel (succ n) (𝟎 {i})
𝟎-hlevel {zero} = hlevel-in λ where {()}
𝟎-hlevel {succ _} = raise
𝟏-hlevel : hlevel n (𝟏 {i})
𝟏-hlevel {zero} = hlevel-in (★ , λ where ★ → refl)
𝟏-hlevel {succ _} = raise
𝟐-hlevel : hlevel (succ (succ n)) 𝟐
𝟐-hlevel {n} = hlevel-in (equiv-hlevel (=𝟐-equiv ⁻¹ₑ))
where
code-hlevel : {x y : 𝟐} → hlevel (succ n) (x =𝟐 y)
code-hlevel {0₂} {0₂} = ⟨⟩
code-hlevel {0₂} {1₂} = ⟨⟩
code-hlevel {1₂} {0₂} = ⟨⟩
code-hlevel {1₂} {1₂} = ⟨⟩
instance _ = code-hlevel
Π-hlevel : ⦃ {x : A} → hlevel n (P x) ⦄ → hlevel n (Π A P)
Π-hlevel {n = zero} = hlevel-in ((λ _ → center) , (λ _ → funext λ _ → contr))
Π-hlevel {n = succ n} = hlevel-in (equiv-hlevel (=Π-equiv ⁻¹ₑ))
Π-implicit-hlevel : ⦃ {x : A} → hlevel n (P x) ⦄ → hlevel n ({x : A} → P x)
Π-implicit-hlevel = equiv-hlevel (Π-implicit-equiv ⁻¹ₑ)
+-hlevel : ⦃ hlevel (succ (succ n)) A ⦄ → ⦃ hlevel (succ (succ n)) B ⦄ →
hlevel (succ (succ n)) (A + B)
+-hlevel {n} {A = A} {B = B} = hlevel-in (equiv-hlevel (=+-equiv ⁻¹ₑ))
where
code-hlevel : {x y : A + B} → hlevel (succ n) (x =+ y)
code-hlevel {inl _} {inl _} = ⟨⟩
code-hlevel {inl _} {inr _} = ⟨⟩
code-hlevel {inr _} {inl _} = ⟨⟩
code-hlevel {inr _} {inr _} = ⟨⟩
instance _ = code-hlevel
ℕ-hlevel : hlevel 2 ℕ
hlevel-out ℕ-hlevel {x} = equiv-hlevel (=ℕ-equiv ⁻¹ₑ)
where
code-hlevel : {x y : ℕ} → hlevel 1 (x =ℕ y)
code-hlevel {zero} {zero} = ⟨⟩
code-hlevel {zero} {succ y} = ⟨⟩
code-hlevel {succ x} {zero} = ⟨⟩
code-hlevel {succ x} {succ y} = code-hlevel {x}
instance _ = code-hlevel {x}
-- Make Σ-hlevel a private instance so it can be installed as-needed.
-- There are too many cases where we want to use some other instance
-- instead.
Σ-hlevel : ⦃ h₁ : hlevel n A ⦄ → ⦃ h₂ : {x : A} → hlevel n (P x) ⦄ → hlevel n (Σ A P)
private instance _ = Σ-hlevel
Σ-hlevel {n = zero} = hlevel-in ((center , center) , λ x → pair⁼' (contr , contr))
Σ-hlevel {n = succ n} = hlevel-in (equiv-hlevel (=Σ-equiv ⁻¹ₑ))
→-hlevel : ⦃ hlevel n B ⦄ → hlevel n (A → B)
→-hlevel = ⟨⟩
×-hlevel : ⦃ h₁ : hlevel n A ⦄ → ⦃ h₂ : hlevel n B ⦄ → hlevel n (A × B)
×-hlevel = ⟨⟩
isContr-hlevel : hlevel 1 (isContr A)
hlevel-out (isContr-hlevel {A = A}) {h} = ⟨⟩
where instance _ = raise* ⦃ hlevel-in h ⦄
hlevel-equiv : hlevel-type n A ≃ hlevel n A
hlevel-equiv = hlevel-in , qinv→isequiv (hlevel-out , (λ _ → refl) , (λ _ → refl))
instance
hlevel-hlevel : hlevel 1 (hlevel n A)
hlevel-hlevel {zero} = equiv-hlevel hlevel-equiv ⦃ isContr-hlevel ⦄
hlevel-hlevel {succ n} = equiv-hlevel hlevel-equiv
hlevel⁼ : ⦃ h₁ : hlevel n A ⦄ ⦃ h₂ : hlevel n B ⦄ → A == B → type A == type B
hlevel⁼ ⦃ h₁ ⦄ ⦃ h₂ ⦄ refl rewrite center ⦃ =-hlevel {x = h₁} {h₂} ⦄ = refl
hlevel1→isProp : ⦃ hlevel 1 A ⦄ → isProp A
hlevel1→isProp = center
hlevel2→isSet : ⦃ hlevel 2 A ⦄ → isSet A
hlevel2→isSet = center
isProp→hlevel1 : isProp A → hlevel 1 A
hlevel-out (isProp→hlevel1 f) {x} {y} = ⟨⟩
where instance _ = raise ⦃ hlevel-in (x , f x) ⦄
isProp-hlevel1 : hlevel 1 (isProp A)
hlevel-out isProp-hlevel1 {f} = ⟨⟩
where instance _ = raise ⦃ isProp→hlevel1 f ⦄
isProp-prop : isProp (isProp A)
isProp-prop = hlevel1→isProp ⦃ isProp-hlevel1 ⦄
isProp→isSet : isProp A → isSet A
isProp→isSet A-prop {x} {y} p q = center
where instance _ = raise ⦃ isProp→hlevel1 A-prop ⦄
isContr-prop : isProp (isContr A)
isContr-prop (a , p) (a' , p') = pair⁼ (p a' , center)
where instance _ = raise* ⦃ hlevel-in (a , p) ⦄
prop-equiv : ⦃ h₁ : hlevel 1 A ⦄ → ⦃ h₂ : hlevel 1 B ⦄ →
(A → B) → (B → A) → A ≃ B
prop-equiv f g = f , qinv→isequiv (g , (λ _ → center) , (λ _ → center))
Σ-contr₁ : ⦃ _ : hlevel 0 A ⦄ → Σ A P ≃ P center
Σ-contr₁ {A = A} {P = P} ⦃ h ⦄ = let open Iso in iso→eqv λ where
.f → transport P (contr ⁻¹) ∘ pr₂
.g y → center , y
.η x → pair⁼ (contr , Eqv.ε (transport-equiv (contr {A = A})) _)
.ε y → ap {x = contr ⁻¹} (λ p → transport P p y)
let instance _ = raise* ⦃ h ⦄ in center
Σ-contr₂ : ⦃ {x : A} → hlevel 0 (P x) ⦄ → Σ A P ≃ A
Σ-contr₂ = let open Iso in iso→eqv λ where
.f → pr₁
.g x → x , center
.η _ → pair⁼ (refl , contr)
.ε _ → refl
×-contr₁ : ⦃ hlevel 0 A ⦄ → A × B ≃ B
×-contr₁ = Σ-contr₁
×-contr₂ : ⦃ hlevel 0 B ⦄ → A × B ≃ A
×-contr₂ = Σ-contr₂
Π-contr₁ : ⦃ _ : hlevel 0 A ⦄ → Π A P ≃ P center
Π-contr₁ {A = A} {P = P} ⦃ h ⦄ = let open Iso in iso→eqv λ where
.f h → h center
.g x _ → transport P contr x
.η h → funext (λ _ → apd h contr)
.ε x → ap {x = contr} (λ p → transport P p x)
let instance _ = raise* ⦃ h ⦄ in center
=-contrₗ : (a : A) → hlevel 0 (Σ A (a ==_))
=-contrₗ a = hlevel-in ((a , refl) , λ (_ , p) →
pair⁼ (p , transport=-const-id p a refl ∙ unitₗ ⁻¹))
=-contrᵣ : (a : A) → hlevel 0 (Σ A (_== a))
=-contrᵣ a = hlevel-in ((a , refl) , λ (_ , p) →
pair⁼ (p ⁻¹ , transport=-id-const a (p ⁻¹) refl ∙ unitᵣ ⁻¹ ∙ invinv))
|
{
"alphanum_fraction": 0.5664624234,
"avg_line_length": 31.3607843137,
"ext": "agda",
"hexsha": "313268fe40662385ea10e2e72b6c6aa67be00170",
"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/HLevel.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/HLevel.agda",
"max_line_length": 85,
"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/HLevel.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3612,
"size": 7997
}
|
------------------------------------------------------------------------
-- Parsing of mixfix operators
------------------------------------------------------------------------
-- This module defines a grammar for the precedence graph g. The
-- grammar is neither left nor right recursive.
open import Mixfix.Expr
open import Mixfix.Acyclic.PrecedenceGraph
using (acyclic; precedence)
module Mixfix.Acyclic.Grammar
(g : PrecedenceGraphInterface.PrecedenceGraph acyclic)
where
open import Codata.Musical.Notation
open import Data.List using (List; []; _∷_)
open import Data.List.Membership.Propositional using (_∈_)
open import Data.List.Relation.Unary.Any using (here; there)
open import Data.List.NonEmpty using (foldr; foldl)
open import Data.Product
open import Data.Bool
import Data.String as String
import Relation.Binary.PropositionalEquality as P
open PrecedenceCorrect acyclic g
import StructurallyRecursiveDescentParsing.Simplified as Simplified
open Simplified hiding (Parser; ⟦_⟧)
open import Mixfix.Fixity
open import Mixfix.Operator
open import Mixfix.Acyclic.Lib renaming (ParserProg to Parser)
-- The following definition uses a lexicographic combination of
-- guarded corecursion and structural recursion. The only "corecursive
-- call", where the size of the inductive input can increase
-- arbitrarily, is the one in expr.
mutual
-- Expressions.
expr : ∞ (Parser (Expr g))
expr = ♯ precs g
-- Expressions corresponding to zero or more nodes in the precedence
-- graph: operator applications where the outermost operator has one
-- of the precedences ps. The graph g is used for internal
-- expressions.
precs : (ps : List Precedence) → Parser (Expr ps)
precs [] = fail
precs (p ∷ ps) = (λ e → here P.refl ∙ proj₂ e) <$> prec p
∣ weakenE <$> precs ps
-- Expressions corresponding to one node in the precedence graph:
-- operator applications where the outermost operator has
-- precedence p. The graph g is used for internal expressions.
prec : (p : Precedence) → Parser (∃ (ExprIn p))
prec (precedence ops sucs) =
⟪_⟫ <$> [ closed ]
∥ _⟨_⟩_ <$> p↑ ⊛ [ infx non ] ⊛ p↑
∥ appʳ <$> preRight + ⊛ p↑
∥ appˡ <$> p↑ ⊛ postLeft +
∥ fail
module Prec where
p = precedence ops sucs
-- [ fix ] parses the internal parts of operators with the
-- current precedence level and fixity fix.
[_] = λ (fix : Fixity) → inner (ops fix)
-- Operator applications where the outermost operator binds
-- tighter than the current precedence level.
p↑ = precs sucs
-- Right associative and prefix operators.
preRight : Parser (Outer p right → ExprIn p right)
preRight = ⟪_⟩_ <$> [ prefx ]
∣ _⟨_⟩ʳ_ <$> p↑ ⊛ [ infx right ]
-- Left associative and postfix operators.
postLeft : Parser (Outer p left → ExprIn p left)
postLeft = (λ op e₁ → e₁ ⟨ op ⟫ ) <$> [ postfx ]
∣ (λ op e₂ e₁ → e₁ ⟨ op ⟩ˡ e₂) <$> [ infx left ] ⊛ p↑
-- Post-processing for the non-empty lists returned by _+.
appʳ = λ fs e → foldr (λ f e → f (similar e)) (λ f → f (tighter e)) fs
appˡ = λ e fs → foldl (λ e f → f (similar e)) (λ f → f (tighter e)) fs
-- Internal parts (all name parts plus internal expressions) of
-- operators of the given precedence and fixity.
inner : ∀ {fix} (ops : List (∃ (Operator fix))) →
Parser (Inner ops)
inner [] = fail
inner ((_ , op) ∷ ops) =
(λ args → here P.refl ∙ args) <$> (expr between nameParts op)
∣ weakenI <$> inner ops
-- Expression parsers.
expression : Simplified.Parser NamePart false (Expr g)
expression = ⟦ ♭ expr ⟧
|
{
"alphanum_fraction": 0.6253319172,
"avg_line_length": 35.5283018868,
"ext": "agda",
"hexsha": "cd116460581de3ee96ada337e1480f61ce4d7de9",
"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": "Mixfix/Acyclic/Grammar.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": "Mixfix/Acyclic/Grammar.agda",
"max_line_length": 74,
"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": "Mixfix/Acyclic/Grammar.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": 1012,
"size": 3766
}
|
module Numeral.Finite.LinearSearch where -- TODO: Maybe move to Numeral.CoordinateVector.LinearSearch
open import Data.Boolean
open import Data.Boolean.Stmt
open import Data.List
import Data.List.Functions as List
open import Data.Option
import Data.Option.Functions as Option
open import Functional
open import Logic
open import Numeral.Finite
open import Numeral.Finite.Bound
open import Numeral.Natural
open import Structure.Relator.Ordering
private variable n : ℕ
private variable i j min max : 𝕟(n)
private variable f : 𝕟(n) → Bool
-- Finds the maximal argument satisfying the given decidable predicate by searching linearly.
-- Examples:
-- findMax{5} (10 ∣?_) = None
-- findMax{10} (10 ∣?_) = None
-- findMax{20} (10 ∣?_) = Some 10
-- findMax{21} (10 ∣?_) = Some 20
-- findMax{22} (10 ∣?_) = Some 20
-- findMax{100} (10 ∣?_) = Some 90
-- findMax{102} (10 ∣?_) = Some 100
-- Alternative implementation: findMax f = Option.map Wrapping.[−]_ (findMin(f ∘ Wrapping.[−]_))
findMax : (𝕟(n) → Bool) → Option(𝕟(n))
findMax {𝟎} f = None
findMax {𝐒(n)} f with f(maximum)
findMax {𝐒(n)} f | 𝑇 = Some maximum
findMax {𝐒(n)} f | 𝐹 = Option.map bound-𝐒 (findMax{n} (f ∘ bound-𝐒))
-- Finds the minimal argument satisfying the given decidable predicate by searching linearly.
-- Examples:
-- findMin{5} (10 ∣?_) = None
-- findMin{10} (10 ∣?_) = None
-- findMin{20} (10 ∣?_) = Some 10
-- findMin{21} (10 ∣?_) = Some 10
-- findMin{22} (10 ∣?_) = Some 10
-- findMin{100} (10 ∣?_) = Some 10
-- findMax{102} (10 ∣?_) = Some 10
findMin : (𝕟(n) → Bool) → Option(𝕟(n))
findMin{𝟎} f = None
findMin{𝐒(n)} f with f(𝟎)
findMin{𝐒(n)} f | 𝑇 = Some 𝟎
findMin{𝐒(n)} f | 𝐹 = Option.map 𝐒 (findMin{n} (f ∘ 𝐒))
-- Finds all arguments satisfying the given decidable predicate by searching linearly.
-- Examples:
-- findAll{10} (2 ∣?_) = [0,2,4,6,8]
findAll : (𝕟(n) → Bool) → List(𝕟(n))
findAll{𝟎} f = ∅
findAll{𝐒(n)} f = (if f(𝟎) then (𝟎 ⊰_) else id) (List.map 𝐒 (findAll{n} (f ∘ 𝐒)))
open import Data
open import Data.Boolean.Stmt.Proofs
open import Data.List.Relation.Membership using (_∈_)
open import Data.List.Relation.Membership.Proofs
open import Data.List.Relation.Pairwise
open import Data.List.Relation.Pairwise.Proofs
open import Data.List.Relation.Quantification
open import Data.List.Relation.Quantification.Proofs
open import Data.List.Sorting
open import Data.Option.Equiv.Id
open import Lang.Inspect
open import Logic.Propositional
open import Logic.Propositional.Theorems
open import Numeral.Finite.Oper.Comparisons
open import Numeral.Finite.Oper.Comparisons.Proofs
open import Numeral.Finite.Proofs
open import Numeral.Finite.Relation.Order as 𝕟 using (_≤_ ; _>_ ; _<_ ; [≤]-minimum ; [≤]-maximum)
import Numeral.Natural.Relation.Order as ℕ
open import Numeral.Natural.Relation.Order.Proofs as ℕ
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Relator.Properties
open import Structure.Relator
open import Type.Properties.Decidable
open import Type.Properties.Decidable.Proofs
{-
open import Syntax.Number
test : 𝕟(5) → Bool
test 𝟎 = 𝐹
test (𝐒 𝟎) = 𝐹
test (𝐒 (𝐒 𝟎)) = 𝑇
test (𝐒 (𝐒 (𝐒 𝟎))) = 𝐹
test (𝐒 (𝐒 (𝐒 (𝐒 𝟎)))) = 𝐹
test2 : 𝕟(1) → Bool
test2 𝟎 = 𝑇
test3 : findMax test2 ≡ Some 0
test3 = [≡]-intro
tst4 = {!Option.map bound-𝐒 (findMax (test ∘ bound-𝐒))!}
-}
findMax-None-correctness : (findMax f ≡ None) ↔ (∀{i} → IsFalse(f(i)))
findMax-None-correctness = [↔]-intro l r where
l : (findMax f ≡ None) ← (∀{i} → IsFalse(f(i)))
l {𝟎} {f} p = [≡]-intro
l {𝐒 n} {f} p with f(maximum) | inspect f(maximum)
... | 𝑇 | intro fmax with () ← disjointness p ([↔]-to-[←] IsTrue.is-𝑇 fmax)
... | 𝐹 | intro fmax = congruence₁(Option.map bound-𝐒) (l p)
r-result : IsFalse(f(maximum)) → (∀{i : 𝕟(n)} → IsFalse((f ∘ bound-𝐒) i)) → (∀{i : 𝕟(n)} → IsFalse(f(𝐒 i)))
r-result {𝐒 n} {f} p q {𝐒 i} = r-result {n}{f ∘ 𝐒} p (\{i} → q{𝐒 i}) {i}
r-result {𝐒 𝟎} {f} p q {𝟎} = p
r-result {𝐒 (𝐒 n)} {f} p q {𝟎} = q{𝐒 𝟎}
r : (findMax f ≡ None) → (∀{i} → IsFalse(f(i)))
r {𝐒 n} {f} p {i} with f(maximum) | inspect f(maximum)
r {𝐒 n} {f} p {𝐒 i} | 𝐹 | intro fmax = r-result {f = f} ([↔]-to-[←] IsFalse.is-𝐹 fmax) (\{i} → r {n}{f ∘ bound-𝐒} (map-None p) {i}) {i}
r {𝐒 𝟎} {f} p {𝟎} | 𝐹 | intro fmax = [↔]-to-[←] IsFalse.is-𝐹 fmax
r {𝐒 (𝐒 n)} {f} p {𝟎} | 𝐹 | intro fmax = r {𝐒 n} {f ∘ bound-𝐒} (map-None p) {𝟎}
findMax-Some-correctness : (findMax f ≡ Some(i)) → IsTrue(f(i))
findMax-Some-correctness {𝐒 n} {f} {i} eq with f(maximum) | inspect f(maximum)
findMax-Some-correctness {𝐒 n} {f} {.maximum} [≡]-intro | 𝑇 | intro fmax = [↔]-to-[←] IsTrue.is-𝑇 fmax
findMax-Some-correctness {𝐒 n} {f} {i} eq | 𝐹 | intro fmax with findMax(f ∘ bound-𝐒) | inspect findMax(f ∘ bound-𝐒)
findMax-Some-correctness {𝐒 n} {f} {.(_)} [≡]-intro | 𝐹 | intro fmax | Some x | intro p = findMax-Some-correctness {f = f ∘ bound-𝐒} p
findMin-None-correctness : (findMin f ≡ None) ↔ (∀{i} → IsFalse(f(i)))
findMin-None-correctness = [↔]-intro l r where
l : (findMin f ≡ None) ← (∀{i} → IsFalse(f(i)))
l {𝟎} {f} p = [≡]-intro
l {𝐒 n} {f} p with f(𝟎) | inspect f(𝟎)
... | 𝑇 | intro f0 with () ← disjointness p ([↔]-to-[←] IsTrue.is-𝑇 f0)
... | 𝐹 | intro f0 = congruence₁(Option.map 𝐒) (l p)
r : (findMin f ≡ None) → (∀{i} → IsFalse(f(i)))
r {𝐒 n} {f} p {i} with f(𝟎) | inspect f(𝟎)
r {𝐒 n} {f} p {𝟎} | 𝐹 | intro f0 = [↔]-to-[←] IsFalse.is-𝐹 f0
r {𝐒 n} {f} p {𝐒 i} | 𝐹 | intro f0 = r {f = f ∘ 𝐒} (injective(Option.map 𝐒) ⦃ map-injectivity ⦄ p)
findMin-Some-correctness : (findMin f ≡ Some(min)) → IsTrue(f(min))
findMin-Some-correctness {𝐒 n} {f} {min} eq with f(𝟎) | inspect f(𝟎)
findMin-Some-correctness {𝐒 n} {f} {𝟎} [≡]-intro | 𝑇 | intro f0 = [↔]-to-[←] IsTrue.is-𝑇 f0
findMin-Some-correctness {𝐒 n} {f} {𝟎} eq | 𝐹 | intro f0 with findMin{n} (f ∘ 𝐒)
findMin-Some-correctness {𝐒 n} {f} {𝟎} () | 𝐹 | intro f0 | None
findMin-Some-correctness {𝐒 n} {f} {𝟎} () | 𝐹 | intro f0 | Some _
findMin-Some-correctness {𝐒 n} {f} {𝐒 min} eq | 𝐹 | intro f0 = findMin-Some-correctness {n} {f ∘ 𝐒} {min} (injective(Option.map 𝐒) ⦃ map-injectivity ⦄ eq)
findMin-minimal-true : (findMin f ≡ Some(min)) → IsTrue(f(i)) → (min ≤ i)
findMin-minimal-true {𝐒 n} {f} {min} {i} eq p with f(𝟎) | inspect f(𝟎)
findMin-minimal-true {𝐒 n} {f} {.𝟎} {i} [≡]-intro p | 𝑇 | intro f0 = 𝕟.[≤]-minimum {a = i}
findMin-minimal-true {𝐒 n} {f} {𝟎} {i} eq p | 𝐹 | intro f0 with findMin{n} (f ∘ 𝐒)
findMin-minimal-true {𝐒 n} {f} {𝟎} {i} () p | 𝐹 | intro f0 | None
findMin-minimal-true {𝐒 n} {f} {𝟎} {i} () p | 𝐹 | intro f0 | Some _
findMin-minimal-true {𝐒 n} {f} {𝐒 min} {𝟎} eq p | 𝐹 | intro f0 = disjointness p ([↔]-to-[←] IsFalse.is-𝐹 f0)
findMin-minimal-true {𝐒 n} {f} {𝐒 min} {𝐒 i} eq p | 𝐹 | intro f0 = findMin-minimal-true {n} {f ∘ 𝐒} {min} {i} (injective(Option.map 𝐒) ⦃ map-injectivity ⦄ eq) p
findMin-minimal-false : (findMin f ≡ Some(min)) → (min > i) → IsFalse(f(i))
findMin-minimal-false {n}{f}{min}{i} eq =
[↔]-to-[←] false-true-opposites
∘ contrapositiveᵣ(findMin-minimal-true{n}{f}{min}{i} eq)
∘ [↔]-to-[←] decider-true ∘ substitute₁ₗ(IsTrue) (⋚-elim₃-negation-distribution {x = min}{y = i})
{-
instance
[≤]-with-[𝐒]-injective : ∀{a b} → Injective(\p → ℕ.[≤]-with-[𝐒] {a}{b} ⦃ p ⦄)
Injective.proof [≤]-with-[𝐒]-injective [≡]-intro = [≡]-intro
import Structure.Function.Names as Names
open import Function.Equals
bound-[≤]-injective : ∀{a b} → Injective ⦃ [≡]-equiv ⦄ ⦃ [⊜]-equiv ⦄ (bound-[≤] {a}{b})
bound-[≤]-injective {a}{b} = intro proof where
proof : Names.Injective ⦃ [≡]-equiv ⦄ ⦃ [⊜]-equiv ⦄ (bound-[≤] {a}{b})
proof {ℕ.[≤]-minimum} {ℕ.[≤]-minimum} p = [≡]-intro
proof {ℕ.[≤]-with-[𝐒] ⦃ x ⦄} {ℕ.[≤]-with-[𝐒] ⦃ y ⦄} (intro p) = {!(injective ⦃ ? ⦄ ⦃ ? ⦄ (𝕟.𝐒) ⦃ ? ⦄ {x = bound-[≤] x}{y = bound-[≤] y} p)!}
--Injective.proof bound-[≤]-injective {ℕ.[≤]-minimum} {ℕ.[≤]-minimum} p = [≡]-intro
--Injective.proof bound-[≤]-injective {ℕ.[≤]-with-[𝐒] {y = _} ⦃ x ⦄} {ℕ.[≤]-with-[𝐒] {y = _} ⦃ y ⦄} (intro p) = {!injective(𝐒) ⦃ ? ⦄ p!}
-- injective(𝐒) ⦃ [≤]-with-[𝐒]-injective ⦄
bound-𝐒-injective : Injective(bound-𝐒 {n})
Injective.proof bound-𝐒-injective {𝟎} {𝟎} p = [≡]-intro
Injective.proof bound-𝐒-injective {𝐒 x} {𝐒 y} p = congruence₁(𝐒) (Injective.proof bound-𝐒-injective {x} {y} (injective(𝐒) p))
-}
-- TODO
postulate findMax-maximal-true : (findMax f ≡ Some(max)) → IsTrue(f(i)) → (i ≤ max)
{-findMax-maximal {𝐒 n}{f} eq p with f(maximum) | inspect f(maximum)
findMax-maximal {𝐒 n} {f} {i = i} [≡]-intro p | 𝑇 | intro m = [≤]-maximum {𝐒 n}{i} (reflexivity(ℕ._≤_))
findMax-maximal {𝐒 n} {f} {i = i} eq p | 𝐹 | intro m with findMax{n} (f ∘ bound-𝐒) | inspect (findMax{n}) (f ∘ bound-𝐒)
findMax-maximal {𝐒 n} {f} {i = i} eq p | 𝐹 | intro m | Some x | intro findMax-x = {!findMax-maximal {n} {f ∘ bound-𝐒} {i = ?} !}
-}
{- TODO
test : ∀{i : 𝕟(𝐒(n))} → ¬(maximum{n} < i)
test {𝟎} {𝟎} p = p
test {𝐒 n} {𝟎} p = p
test {𝐒 n} {𝐒 i} p = test {n}{i} p
{-
findMax-maximal2 : (findMax f ≡ Some(max)) → (i > max) → IsFalse(f(i))
findMax-maximal2 {𝐒 n} {f} {max} {i} eq p with f(maximum) | inspect f(maximum)
findMax-maximal2 {𝐒 n} {f} {𝟎} {𝐒 i} eq p | 𝑇 | intro fmax with maximum-0(injective(Some) eq)
findMax-maximal2 {𝐒 .0} {f} {𝟎} {𝐒 ()} eq p | 𝑇 | intro fmax | [≡]-intro
findMax-maximal2 {𝐒 (𝐒 n)} {f} {𝐒 max} {𝐒 i} eq p | 𝑇 | intro fmax with f(bound-𝐒 maximum) | inspect (f ∘ bound-𝐒)(maximum)
findMax-maximal2 {𝐒 (𝐒 n)} {f} {𝐒 .maximum} {𝐒 i} [≡]-intro p | 𝑇 | intro fmax | 𝑇 | intro x with () ← test{n} p
findMax-maximal2 {𝐒 (𝐒 n)} {f} {𝐒 {.(𝐒 n)} .(maximum {n})} {𝐒 {.(𝐒 n)} i} ([≡]-intro {x = .(Some (𝐒 {𝐒 n} (maximum {n})))}) p | 𝑇 | intro fmax | 𝐹 | intro x with () ← test{n} p
findMax-maximal2 {𝐒 n} {f} {𝟎} {𝐒 i} eq p | 𝐹 | intro fmax = {!!}
findMax-maximal2 {𝐒 n} {f} {𝐒 max} {𝐒 i} eq p | 𝐹 | intro fmax = {!!}
-}
test2 : (bound-𝐒 i ≡ 𝟎) → (i ≡ 𝟎)
test2 {i = 𝟎} p = [≡]-intro
findMax-maximal : (findMax f ≡ Some(max)) → IsTrue(f(i)) → (i ≤ max)
findMax-maximal {𝐒 n}{f} eq p with f(maximum) | inspect f(maximum)
findMax-maximal {𝐒 n} {f} {_}{i} [≡]-intro p | 𝑇 | intro fmax = [≤]-maximum {𝐒 n}{i} (reflexivity(ℕ._≤_))
findMax-maximal {𝐒 n} {f} {max} {𝟎} eq p | 𝐹 | intro fmax = [≤]-minimum {a = max}
findMax-maximal {𝐒 (𝐒 n)} {f} {max} {𝐒 i} eq p | 𝐹 | intro fmax with f(bound-𝐒 maximum) | inspect (f ∘ bound-𝐒)(maximum)
findMax-maximal {𝐒 (𝐒 n)} {f} {𝟎} {𝐒 i} eq p | 𝐹 | intro fmax | 𝑇 | intro x = {!maximum-0(test2(injective(Some) eq))!}
findMax-maximal {𝐒 (𝐒 n)} {f} {𝐒 max} {𝐒 i} eq p | 𝐹 | intro fmax | 𝑇 | intro x = {!!}
... | 𝐹 | intro x = {!!}
-- findMax-maximal {f = f ∘ bound-𝐒} {i = i} (injective(Option.map bound-𝐒) ⦃ map-injectivity ⦃ ? ⦄ ⦄ {findMax(f ∘ bound-𝐒)} {Some 𝟎} eq)
{-findMax-maximal {𝐒 n} {f} {max} {i} eq p with f(maximum) | inspect f(maximum)
findMax-maximal {𝐒 n} {f} {.maximum} {i} [≡]-intro p | 𝑇 | intro fmax = [≤]-maximum {𝐒 n}{i}{n = n} (reflexivity(ℕ._≤_))
findMax-maximal {𝐒 n} {f} {max} {i} eq p | 𝐹 | intro fmax with findMax{n} (f ∘ bound-𝐒)
findMax-maximal {𝐒 n} {f} {max} {i} () p | 𝐹 | intro fmax | None
-}
{-findMax-maximal {𝐒 n} {f} {𝟎} {𝟎} eq p | 𝐹 | intro fmax | Some x = <>
findMax-maximal {𝐒 n} {f} {𝐒 max} {𝟎} eq p | 𝐹 | intro fmax | Some x = <>
findMax-maximal {𝐒(𝐒 n)} {f} {𝟎} {𝐒 i} eq p | 𝐹 | intro fmax | Some 𝟎 = {!findMax-maximal!}
findMax-maximal {𝐒 n} {f} {𝐒 max} {𝐒 i} eq p | 𝐹 | intro fmax | Some x = {!!}
-}
{-findMax-maximal {𝐒 n} {f} {.(bound-[≤] ([≤]-successor ([≡]-to-[≤] [≡]-intro)) x)} {𝟎} [≡]-intro p | 𝐹 | intro fmax | Some x = [≤]-minimum {a = bound-𝐒(x)}
findMax-maximal {𝐒 .(𝐒 _)} {f} {.(bound-[≤] ([≤]-successor ([≡]-to-[≤] [≡]-intro)) 𝟎)} {𝐒 i} [≡]-intro p | 𝐹 | intro fmax | Some 𝟎 = {!!}
findMax-maximal {𝐒 .(𝐒 _)} {f} {.(bound-[≤] ([≤]-successor ([≡]-to-[≤] [≡]-intro)) (𝐒 x))} {𝐒 i} [≡]-intro p | 𝐹 | intro fmax | Some (𝐒 x) = {!!}-}
-}
{-
open import Numeral.Finite.Oper
findMax-findMin : findMax f ≡ Option.map Wrapping.[−]_ (findMin(f ∘ Wrapping.[−]_))
findMax-findMin {𝟎} {f} = [≡]-intro
findMax-findMin {𝐒 n} {f} with f(maximum) | inspect f(maximum)
... | 𝑇 | intro fmax = [≡]-intro
... | 𝐹 | intro fmax = {!!}
-}
findAll-correctness : AllElements(IsTrue ∘ f)(findAll f)
findAll-correctness {𝟎} {f} = ∅
findAll-correctness {𝐒 n} {f} with f(𝟎) | inspect f(𝟎)
... | 𝑇 | intro f0 = ([↔]-to-[←] IsTrue.is-𝑇 f0) ⊰ (AllElements-mapᵣ 𝐒 id (findAll-correctness {n}{f ∘ 𝐒}))
... | 𝐹 | intro _ = AllElements-mapᵣ 𝐒 id (findAll-correctness {n}{f ∘ 𝐒})
findAll-completeness : IsTrue(f(i)) → (i ∈ findAll f)
findAll-completeness {𝐒 n} {f} {i} p with f(𝟎) | inspect f(𝟎)
findAll-completeness {𝐒 n} {f} {𝟎} p | 𝑇 | intro _ = • [≡]-intro
findAll-completeness {𝐒 n} {f} {𝐒 i} p | 𝑇 | intro _ = ⊰ [∈]-map (findAll-completeness{n}{f ∘ 𝐒}{i} p)
findAll-completeness {𝐒 n} {f} {𝟎} p | 𝐹 | intro f0 with () ← disjointness p ([↔]-to-[←] IsFalse.is-𝐹 f0)
findAll-completeness {𝐒 n} {f} {𝐒 i} p | 𝐹 | intro _ = [∈]-map (findAll-completeness {n} {f ∘ 𝐒} {i} p)
findAll-sorted : Sorted(_≤?_)(findAll f)
findAll-sorted {𝟎} {f} = AdjacentlyPairwise.empty
findAll-sorted {𝐒 𝟎} {f} with f(𝟎) | inspect f(𝟎)
findAll-sorted {𝐒 𝟎} {f} | 𝑇 | intro f0 = AdjacentlyPairwise.single
findAll-sorted {𝐒 𝟎} {f} | 𝐹 | intro f0 = AdjacentlyPairwise.empty
findAll-sorted {𝐒(𝐒 n)} {f} with f(𝟎) | f(𝐒 𝟎) | AdjacentlyPairwise-map {_▫₁_ = IsTrue ∘₂ _≤?_}{f = 𝐒}{_▫₂_ = IsTrue ∘₂ _≤?_} id (findAll-sorted {𝐒 n}{f ∘ 𝐒})
... | 𝑇 | 𝑇 | prev = AdjacentlyPairwise.step ⦃ <> ⦄ ⦃ prev ⦄
... | 𝑇 | 𝐹 | prev = AdjacentlyPairwise-prepend (\{ {𝟎} → <> ; {𝐒 _} → <>}) prev
... | 𝐹 | 𝑇 | prev = prev
... | 𝐹 | 𝐹 | prev = prev
|
{
"alphanum_fraction": 0.5895803184,
"avg_line_length": 51.375464684,
"ext": "agda",
"hexsha": "5f86f6deab3239a8e9108373177831f903dbbc7b",
"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/LinearSearch.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/LinearSearch.agda",
"max_line_length": 176,
"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/LinearSearch.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": 6453,
"size": 13820
}
|
{-# OPTIONS --safe #-}
module Cubical.HITs.FreeAbGroup.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
infixl 7 _·_
infix 20 _⁻¹
private variable
ℓ ℓ' : Level
A : Type ℓ
data FreeAbGroup (A : Type ℓ) : Type ℓ where
⟦_⟧ : A → FreeAbGroup A
ε : FreeAbGroup A
_·_ : FreeAbGroup A → FreeAbGroup A → FreeAbGroup A
_⁻¹ : FreeAbGroup A → FreeAbGroup A
assoc : ∀ x y z → x · (y · z) ≡ (x · y) · z
comm : ∀ x y → x · y ≡ y · x
identityᵣ : ∀ x → x · ε ≡ x
invᵣ : ∀ x → x · x ⁻¹ ≡ ε
trunc : isSet (FreeAbGroup A)
module Elim {B : FreeAbGroup A → Type ℓ'}
(⟦_⟧* : (x : A) → B ⟦ x ⟧)
(ε* : B ε)
(_·*_ : ∀ {x y} → B x → B y → B (x · y))
(_⁻¹* : ∀ {x} → B x → B (x ⁻¹))
(assoc* : ∀ {x y z} → (xs : B x) (ys : B y) (zs : B z)
→ PathP (λ i → B (assoc x y z i)) (xs ·* (ys ·* zs)) ((xs ·* ys) ·* zs))
(comm* : ∀ {x y} → (xs : B x) (ys : B y)
→ PathP (λ i → B (comm x y i)) (xs ·* ys) (ys ·* xs))
(identityᵣ* : ∀ {x} → (xs : B x)
→ PathP (λ i → B (identityᵣ x i)) (xs ·* ε*) xs)
(invᵣ* : ∀ {x} → (xs : B x)
→ PathP (λ i → B (invᵣ x i)) (xs ·* (xs ⁻¹*)) ε*)
(trunc* : ∀ xs → isSet (B xs)) where
f : (xs : FreeAbGroup A) → B xs
f ⟦ x ⟧ = ⟦ x ⟧*
f ε = ε*
f (xs · ys) = f xs ·* f ys
f (xs ⁻¹) = f xs ⁻¹*
f (assoc xs ys zs i) = assoc* (f xs) (f ys) (f zs) i
f (comm xs ys i) = comm* (f xs) (f ys) i
f (identityᵣ xs i) = identityᵣ* (f xs) i
f (invᵣ xs i) = invᵣ* (f xs) i
f (trunc xs ys p q i j) = isOfHLevel→isOfHLevelDep 2 trunc* (f xs) (f ys)
(cong f p) (cong f q) (trunc xs ys p q) i j
module ElimProp {B : FreeAbGroup A → Type ℓ'}
(BProp : {xs : FreeAbGroup A} → isProp (B xs))
(⟦_⟧* : (x : A) → B ⟦ x ⟧)
(ε* : B ε)
(_·*_ : ∀ {x y} → B x → B y → B (x · y))
(_⁻¹* : ∀ {x} → B x → B (x ⁻¹)) where
f : (xs : FreeAbGroup A) → B xs
f = Elim.f ⟦_⟧* ε* _·*_ _⁻¹*
(λ {x y z} xs ys zs → toPathP (BProp (transport (λ i → B (assoc x y z i)) (xs ·* (ys ·* zs))) ((xs ·* ys) ·* zs)))
(λ {x y} xs ys → toPathP (BProp (transport (λ i → B (comm x y i)) (xs ·* ys)) (ys ·* xs)))
(λ {x} xs → toPathP (BProp (transport (λ i → B (identityᵣ x i)) (xs ·* ε*)) xs))
(λ {x} xs → toPathP (BProp (transport (λ i → B (invᵣ x i)) (xs ·* (xs ⁻¹*))) ε*))
(λ _ → (isProp→isSet BProp))
module Rec {B : Type ℓ'} (BType : isSet B)
(⟦_⟧* : (x : A) → B)
(ε* : B)
(_·*_ : B → B → B)
(_⁻¹* : B → B)
(assoc* : (x y z : B) → x ·* (y ·* z) ≡ (x ·* y) ·* z)
(comm* : (x y : B) → x ·* y ≡ y ·* x)
(identityᵣ* : (x : B) → x ·* ε* ≡ x)
(invᵣ* : (x : B) → x ·* (x ⁻¹*) ≡ ε*)
where
f : FreeAbGroup A → B
f = Elim.f ⟦_⟧* ε* _·*_ _⁻¹* assoc* comm* identityᵣ* invᵣ* (const BType)
|
{
"alphanum_fraction": 0.4413256679,
"avg_line_length": 36.5061728395,
"ext": "agda",
"hexsha": "d377b0dce6866f3803e76299ab7840ffd0915f1f",
"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/HITs/FreeAbGroup/Base.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/HITs/FreeAbGroup/Base.agda",
"max_line_length": 118,
"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/HITs/FreeAbGroup/Base.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": 1376,
"size": 2957
}
|
{-# OPTIONS --type-in-type #-}
module chu where
open import functors
open import prelude
record Chu : Set where
constructor _,_!_
field
_⁺ _⁻ : Set
_Ω_ : _⁺ → _⁻ → Set
module _ (A@(A⁺ , A⁻ ! _Ω₁_) B@(B⁺ , B⁻ ! _Ω₂_) : Chu) where
record Chu[_,_] : Set where -- Morphisms of chu spaces
constructor _↔_!_
field
to : A⁺ → B⁺
from : B⁻ → A⁻
adj : ∀ a⁺ b⁻ → to a⁺ Ω₂ b⁻ ≡ a⁺ Ω₁ from b⁻
module _ {A@(A⁺ , A⁻ ! _Ω₁_)
B@(B⁺ , B⁻ ! _Ω₂_)
C@(C⁺ , C⁻ ! _Ω₃_) : Chu}
(F@(f ↔ fᵗ ! _†₁_) : Chu[ A , B ])
(G@(g ↔ gᵗ ! _†₂_) : Chu[ B , C ]) where
adj-comp : ∀ a⁺ c⁻ → (g ∘ f) a⁺ Ω₃ c⁻ ≡ a⁺ Ω₁ (fᵗ ∘ gᵗ) c⁻
adj-comp a⁺ c⁻ = trans (f a⁺ †₂ c⁻) -- g (f a⁺) Ω₃ c⁻
( a⁺ †₁ gᵗ c⁻) -- f a⁺ Ω₂ gᵗ c⁻
-- a⁺ Ω₁ fᵗ (gᵗ c⁻)
chu-comp : Chu[ A , C ]
chu-comp = (g ∘ f) ↔ (fᵗ ∘ gᵗ) ! adj-comp
instance
chu-cat : Category Chu[_,_]
chu-cat = 𝒾: (id ↔ id ! λ _ _ → refl)
▸: chu-comp
𝒾▸: (λ (_ ↔ _ ! _†_) → (λ x → _ ↔ _ ! x) ⟨$⟩
extensionality2 λ a⁺ b⁻ → trans-refl (a⁺ † b⁻))
▸𝒾: (λ _ → refl)
|
{
"alphanum_fraction": 0.3896414343,
"avg_line_length": 33.0263157895,
"ext": "agda",
"hexsha": "40878ff55ba439ece0b78fdc890d092b92dc0ffd",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-30T11:45:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-07-10T17:19:37.000Z",
"max_forks_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dspivak/poly",
"max_forks_repo_path": "code-examples/agda/chu.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_issues_repo_issues_event_max_datetime": "2022-01-12T10:06:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-02T02:29:39.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dspivak/poly",
"max_issues_repo_path": "code-examples/agda/chu.agda",
"max_line_length": 69,
"max_stars_count": 53,
"max_stars_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mstone/poly",
"max_stars_repo_path": "code-examples/agda/chu.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T23:08:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-18T16:31:04.000Z",
"num_tokens": 585,
"size": 1255
}
|
{-# OPTIONS --without-K #-}
module Agda.Builtin.IO where
postulate IO : ∀ {a} → Set a → Set a
{-# BUILTIN IO IO #-}
{-# FOREIGN GHC type AgdaIO a b = IO b #-}
{-# COMPILE GHC IO = type MAlonzo.Code.Agda.Builtin.IO.AgdaIO #-}
|
{
"alphanum_fraction": 0.6184210526,
"avg_line_length": 22.8,
"ext": "agda",
"hexsha": "b700f4f61c5dfd95730327fba300572dc3e324e4",
"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": "src/data/lib/prim/Agda/Builtin/IO.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": "src/data/lib/prim/Agda/Builtin/IO.agda",
"max_line_length": 65,
"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": "src/data/lib/prim/Agda/Builtin/IO.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": 69,
"size": 228
}
|
{-# OPTIONS --cubical --safe #-}
module Cubical.Structures.Semigroup where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Foundations.SIP renaming (SNS-PathP to SNS)
open import Cubical.Structures.NAryOp
private
variable
ℓ ℓ' : Level
raw-semigroup-structure : Type ℓ → Type ℓ
raw-semigroup-structure X = X → X → X
raw-semigroup-is-SNS : SNS {ℓ} raw-semigroup-structure _
raw-semigroup-is-SNS = nAryFunSNS 2
semigroup-axioms : (X : Type ℓ) → raw-semigroup-structure X → Type ℓ
semigroup-axioms X _·_ = isSet X ×
((x y z : X) → (x · (y · z)) ≡ ((x · y) · z))
semigroup-structure : Type ℓ → Type ℓ
semigroup-structure = add-to-structure (raw-semigroup-structure) semigroup-axioms
Semigroup : Type (ℓ-suc ℓ)
Semigroup {ℓ} = TypeWithStr ℓ semigroup-structure
-- Operations for extracting components
⟨_⟩ : Semigroup → Type ℓ
⟨ G , _ ⟩ = G
semigroup-operation : (G : Semigroup {ℓ}) → ⟨ G ⟩ → ⟨ G ⟩ → ⟨ G ⟩
semigroup-operation (_ , f , _) = f
module semigroup-operation-syntax where
semigroup-operation-syntax : (G : Semigroup {ℓ}) → ⟨ G ⟩ → ⟨ G ⟩ → ⟨ G ⟩
semigroup-operation-syntax = semigroup-operation
infixl 20 semigroup-operation-syntax
syntax semigroup-operation-syntax G x y = x ·⟨ G ⟩ y
open semigroup-operation-syntax
semigroup-isSet : (G : Semigroup {ℓ}) → isSet ⟨ G ⟩
semigroup-isSet (_ , _ , P , _) = P
semigroup-assoc : (G : Semigroup {ℓ})
→ (x y z : ⟨ G ⟩) → (x ·⟨ G ⟩ (y ·⟨ G ⟩ z)) ≡ ((x ·⟨ G ⟩ y) ·⟨ G ⟩ z)
semigroup-assoc (_ , _ , _ , P) = P
-- Semigroup equivalences
semigroup-iso : StrIso semigroup-structure ℓ
semigroup-iso = add-to-iso (nAryFunIso 2) semigroup-axioms
semigroup-axiom-isProp : (X : Type ℓ)
→ (s : raw-semigroup-structure X)
→ isProp (semigroup-axioms X s)
semigroup-axiom-isProp X _·_ = isPropΣ isPropIsSet
λ isSetX → isPropΠ (λ x → isPropΠ (λ y → isPropΠ (λ z → isSetX _ _)))
semigroup-is-SNS : SNS {ℓ} semigroup-structure semigroup-iso
semigroup-is-SNS = add-axioms-SNS _ semigroup-axiom-isProp (nAryFunSNS 2)
SemigroupPath : (M N : Semigroup {ℓ}) → (M ≃[ semigroup-iso ] N) ≃ (M ≡ N)
SemigroupPath = SIP semigroup-is-SNS
-- Semigroup ·syntax
module semigroup-·syntax (G : Semigroup {ℓ}) where
infixr 18 _·_
_·_ : ⟨ G ⟩ → ⟨ G ⟩ → ⟨ G ⟩
_·_ = semigroup-operation G
|
{
"alphanum_fraction": 0.64544722,
"avg_line_length": 30.2682926829,
"ext": "agda",
"hexsha": "0fb0e0ad6bb657f87ee1f1c9d1cb9f3520948a4a",
"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": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmester0/cubical",
"max_forks_repo_path": "Cubical/Structures/Semigroup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"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": "cmester0/cubical",
"max_issues_repo_path": "Cubical/Structures/Semigroup.agda",
"max_line_length": 101,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmester0/cubical",
"max_stars_repo_path": "Cubical/Structures/Semigroup.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-23T23:52:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-03-23T23:52:11.000Z",
"num_tokens": 862,
"size": 2482
}
|
open import Data.Char using ( Char )
open import Data.Bool using ( Bool )
module Data.Char.Classifier.Primitive where
postulate
isAscii : Char → Bool
isLatin1 : Char → Bool
isControl : Char → Bool
isSpace : Char → Bool
isLower : Char → Bool
isUpper : Char → Bool
isAlpha : Char → Bool
isAlphaNum : Char → Bool
isPrint : Char → Bool
isDigit : Char → Bool
isOctDigit : Char → Bool
isHexDigit : Char → Bool
{-# IMPORT Data.Char #-}
{-# COMPILED isAscii Data.Char.isAscii #-}
{-# COMPILED isLatin1 Data.Char.isLatin1 #-}
{-# COMPILED isControl Data.Char.isControl #-}
{-# COMPILED isSpace Data.Char.isSpace #-}
{-# COMPILED isLower Data.Char.isLower #-}
{-# COMPILED isUpper Data.Char.isUpper #-}
{-# COMPILED isAlpha Data.Char.isAlpha #-}
{-# COMPILED isAlphaNum Data.Char.isAlphaNum #-}
{-# COMPILED isPrint Data.Char.isPrint #-}
{-# COMPILED isDigit Data.Char.isDigit #-}
{-# COMPILED isOctDigit Data.Char.isOctDigit #-}
{-# COMPILED isHexDigit Data.Char.isHexDigit #-}
|
{
"alphanum_fraction": 0.6923847695,
"avg_line_length": 30.2424242424,
"ext": "agda",
"hexsha": "4637738f1dec47c150b8ce08da0663124f4c2e5a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:14.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:40:14.000Z",
"max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ilya-fiveisky/agda-system-io",
"max_forks_repo_path": "src/Data/Char/Classifier/Primitive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"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": "ilya-fiveisky/agda-system-io",
"max_issues_repo_path": "src/Data/Char/Classifier/Primitive.agda",
"max_line_length": 48,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ilya-fiveisky/agda-system-io",
"max_stars_repo_path": "src/Data/Char/Classifier/Primitive.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-24T13:51:16.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-02T23:17:59.000Z",
"num_tokens": 275,
"size": 998
}
|
{-# OPTIONS --safe #-}
module Cubical.Categories.Presheaf.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Categories.Category
open import Cubical.Categories.Instances.Sets
open import Cubical.Categories.Instances.Functors
PreShv : ∀ {ℓ ℓ'} → Category ℓ ℓ' → (ℓS : Level)
→ Category (ℓ-max (ℓ-max ℓ ℓ') (ℓ-suc ℓS))
(ℓ-max (ℓ-max ℓ ℓ') ℓS)
PreShv C ℓS = FUNCTOR (C ^op) (SET ℓS)
|
{
"alphanum_fraction": 0.6775700935,
"avg_line_length": 30.5714285714,
"ext": "agda",
"hexsha": "c1b4e2d7f4f6966046178f2fb42d4edb57f7ebcf",
"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": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Categories/Presheaf/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"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": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Categories/Presheaf/Base.agda",
"max_line_length": 49,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Categories/Presheaf/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 144,
"size": 428
}
|
------------------------------------------------------------------------------
-- Issue 12
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Issue12 where
postulate
D : Set
∃ : (A : D → Set) → Set
postulate foo : (B C : D → Set) → ∃ C → ∃ C
{-# ATP prove foo #-}
postulate bar : (B C : D → Set) → ∃ B → ∃ B
{-# ATP prove bar #-}
|
{
"alphanum_fraction": 0.3443223443,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "0d2eb86480841e2ac8e2a9fdb2a1642ed6a0db34",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/non-fol-theorems/Issue12.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/non-fol-theorems/Issue12.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/non-fol-theorems/Issue12.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": 120,
"size": 546
}
|
-- Andreas, 2012-04-18, bug reported by sanzhiyan
-- {-# OPTIONS -v tc.with:100 #-}
module Issue610-4 where
import Common.Level
open import Common.Equality
data ⊥ : Set where
record ⊤ : Set where
record A : Set₁ where
constructor set
field
.a : Set
.ack : A → Set
ack x = A.a x
hah : set ⊤ ≡ set ⊥
hah = refl
-- SHOULD FAIL for the same reason that the next decl fails
.moo : ⊥
moo with cong ack hah
moo | q = subst (λ x → x) q _
{- FAILS
.moo' : ⊥
moo' = subst (λ x → x) (cong ack hah) _
-}
baa : .⊥ → ⊥
baa ()
yoink : ⊥
yoink = baa moo
|
{
"alphanum_fraction": 0.6151079137,
"avg_line_length": 14.6315789474,
"ext": "agda",
"hexsha": "e2a7b39a4a514a6ffc7a7a394d53d948699dafe2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Issue610-4.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/fail/Issue610-4.agda",
"max_line_length": 59,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue610-4.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": 212,
"size": 556
}
|
-- Andreas, 2012-11-13 issue reported by joshkos
module Issue754 where
data RDesc (I : Set) : Set₁ where
∎ : RDesc I
ṿ : (i : I) → RDesc I
σ : (S : Set) (D : S → RDesc I) → RDesc I
data ROrn {I J} (e : J → I) : RDesc I → RDesc J → Set₁ where
∎ : ROrn e ∎ ∎
ṿ : ∀ j i → ROrn e (ṿ i) (ṿ j)
σ : (S : Set) → ∀ {D E} (O : ∀ s → ROrn e (D s) (E s)) → ROrn e (σ S D) (σ S E)
Δ : (T : Set) → ∀ {D E} (O : ∀ t → ROrn e D (E t)) → ROrn e D (σ T E)
scROrn : ∀ {I J K} {e : J → I} {f : K → J} {D E F} → ROrn e D E → ROrn f E F → ROrn (λ x → e (f x)) D F
scROrn ∎ ∎ = ∎
scROrn {e = e} ∎ (Δ T P) = Δ T λ t → scROrn {e = e} ∎ (P t) -- culprit?
scROrn (ṿ j i) (ṿ k .j) = ṿ k i
scROrn {e = e} (ṿ j i) (Δ T P) = Δ T λ t → scROrn {e = e} (ṿ j i) (P t) -- culprit?
scROrn (σ S O) (σ .S P) = σ S λ s → scROrn (O s) (P s)
scROrn (σ S O) (Δ T P) = Δ T λ t → scROrn (σ S O) (P t) -- culprit?
scROrn (Δ T O) (σ .T P) = Δ T λ t → scROrn (O t) (P t)
scROrn (Δ T O) (Δ T' P) = Δ T' λ t → scROrn (Δ T O) (P t)
-- Internal error message was:
-- blowUpSparseVec (n = 2) aux i=3 j=3 length l = 2
-- The error was triggered by some operations on matrix-shaped orders
-- which did not preserve the internal invariants of sparse matrices.
|
{
"alphanum_fraction": 0.4835501148,
"avg_line_length": 43.5666666667,
"ext": "agda",
"hexsha": "f4472838fc7909a51f75d86494b2fb78e24715e4",
"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/Issue754.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/Issue754.agda",
"max_line_length": 103,
"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/Issue754.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": 630,
"size": 1307
}
|
---------------------------------------------------------------
-- This file contains the definitions of several versions of --
-- subcategories. --
---------------------------------------------------------------
module Category.Subcategory where
open import Level
open import Data.Product
open import Setoid.Total
open import Relation.Relation
open import Category.Category
open Setoid
open SetoidFun
open Pred
open Subcarrier
open EqRel
open Cat
-- Categorical Predicate: A predicate on objects, and morphisms such
-- that the latter is closed under identities and composition.
record CatPred {l : Level} (ℂ : Cat {l}) : Set (lsuc l) where
field
oinc : Obj ℂ → Set l
minc : ∀{A B} → oinc A → oinc B → Pred {l} (Hom ℂ A B)
cp-idPf : ∀{A} → {p : oinc A} → pf (minc p p) (id ℂ {A})
cp-compPf : ∀{A B C} → (op₁ : (oinc A))
→ (op₂ : (oinc B))
→ (op₃ : (oinc C))
→ {f : el (Hom ℂ A B)}
→ {g : el (Hom ℂ B C)}
→ (pf (minc op₁ op₂) f)
→ (pf (minc op₂ op₃) g)
→ (pf (minc op₁ op₃) (f ○[ comp ℂ ] g))
open CatPred
-- Subcategories:
-- The restriction of a category ℂ to the category determined by the
-- categorical predicate P. Note that the objects of this category
-- are pairs of an object and a proof that the object belongs in the
-- category, and morphisms are similarly defined but using setoid
-- predicates.
subcatPred : {l : Level}{ℂ : Cat {l}}
→ (P : CatPred ℂ)
→ Cat {l}
subcatPred {_}{ℂ} P =
record
{ Obj = Σ[ x ∈ Obj ℂ ]( oinc P x)
; Hom = λ AP BP → let A = proj₁ AP
B = proj₁ BP
op₁ = proj₂ AP
op₂ = proj₂ BP
in Subsetoid (Hom ℂ A B) (minc P op₁ op₂)
; comp = λ {AP}{BP}{CP} →
let A = proj₁ AP
B = proj₁ BP
C = proj₁ CP
op₁ = proj₂ AP
op₂ = proj₂ BP
op₃ = proj₂ CP
in record {
appT = λ x →
record {
appT = λ x₁ →
record { subel = (subel x) ○[ comp ℂ ] (subel x₁) ;
insub = cp-compPf P op₁ op₂ op₃ (insub x) (insub x₁) } ;
extT = λ {y} {z} x₂ → eq-comp-right {_}{ℂ}{A}{B}{C}{subel x}{subel y}{subel z} x₂ } ;
extT = λ {f₁}{f₂} pf g₂ → extT (comp ℂ) pf (subel g₂) }
; id = λ {AP} → let A = proj₁ AP
A-op = proj₂ AP
in record { subel = id ℂ ; insub = cp-idPf P {_}{A-op} }
; assocPf = assocPf ℂ
; idPfCom = idPfCom ℂ
; idPf = idPf ℂ
}
-- Subcategories using subsetoids.
subcat : {l : Level}
→ (ℂ : Cat {l})(O : Set l)
→ (oinc : O → Obj ℂ)
→ (minc : ∀{A B} → Pred {l} (Hom ℂ (oinc A) (oinc B)))
→ (∀{A} → pf (minc {A}{A}) (id ℂ {oinc A}))
→ (∀{A B C}
→ {f : el (Hom ℂ (oinc A) (oinc B))}
→ {g : el (Hom ℂ (oinc B) (oinc C))}
→ (pf minc f)
→ (pf minc g)
→ (pf minc (f ○[ comp ℂ ] g)))
→ Cat {l}
subcat ℂ O oinc minc idPF compPF =
record {
Obj = O;
Hom = λ A B → Subsetoid (Hom ℂ (oinc A) (oinc B)) (minc {A}{B});
comp = λ {A} {B} {C} →
record { appT = λ x →
record { appT = λ x₁ →
record { subel = (subel x) ○[ comp ℂ ] (subel x₁);
insub = compPF {f = subel x}{subel x₁} (insub x) (insub x₁) };
extT = λ {y}{z} p → extT (appT (comp ℂ {oinc A}{oinc B}{oinc C}) (subel x)) {subel y}{subel z} p };
extT = λ {y}{z} x₁ x₂ → extT (comp ℂ {oinc A} {oinc B} {oinc C}) x₁ (subel x₂) };
id = λ {A} → record { subel = id ℂ {oinc A}; insub = idPF {A} };
assocPf = assocPf ℂ;
idPf = idPf ℂ;
idPfCom = idPfCom ℂ
}
-- An alternate definition of a subcategory where the predicate is not
-- a setoid predicate.
subcat-pred : {l : Level}
→ (ℂ : Cat {l})(O : Set l)
→ (oinc : O → Obj ℂ)
→ (minc : ∀{A B} → el (Hom ℂ (oinc A) (oinc B)) → Set l)
→ (∀{A} → minc (id ℂ {oinc A}))
→ (∀{A B C}
→ {f : el (Hom ℂ (oinc A) (oinc B))}
→ {g : el (Hom ℂ (oinc B) (oinc C))}
→ (minc f)
→ (minc g)
→ (minc (f ○[ comp ℂ ] g)))
→ Cat {l}
subcat-pred ℂ O oinc minc idPF compPF =
record {
Obj = O;
Hom = λ A B → ↓Setoid (Hom ℂ (oinc A) (oinc B)) (minc {A}{B});
comp = λ {A} {B} {C} → ↓BinSetoidFun (comp ℂ) compPF;
id = (id ℂ , idPF);
assocPf = assocPf ℂ;
idPf = idPf ℂ;
idPfCom = idPfCom ℂ}
|
{
"alphanum_fraction": 0.4408229782,
"avg_line_length": 37.1893939394,
"ext": "agda",
"hexsha": "35f836b1ec451466051406c0a235a535c6331933",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "setoid-cats/Category/Subcategory.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "setoid-cats/Category/Subcategory.agda",
"max_line_length": 126,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "setoid-cats/Category/Subcategory.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1662,
"size": 4909
}
|
-- Andreas, 2019-06-26, issue #3872, make --no-forcing a pragma option
{-# OPTIONS --no-forcing #-}
open import Agda.Builtin.Nat
data List {a} (A : Set a) : Set a where
[] : List A
_∷_ : A → List A → List A
pattern [_] x = x ∷ []
module _ {a} {A : Set a} where
_++_ : List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
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.
-- We need a way to tell the forcing machinery to not 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)
|
{
"alphanum_fraction": 0.5535055351,
"avg_line_length": 25.8095238095,
"ext": "agda",
"hexsha": "167a2423efd3e30ee8cc92d1ccaab32db625666d",
"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/Issue3872.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/Issue3872.agda",
"max_line_length": 78,
"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/Issue3872.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": 384,
"size": 1084
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly-Quotient where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat
open import Cubical.Data.Vec
open import Cubical.Data.Vec.OperationsNat
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Algebra.DirectSum.DirectSumHIT.Base
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.FGIdeal
open import Cubical.Algebra.CommRing.QuotientRing
open import Cubical.Algebra.CommRing.Instances.Int renaming (ℤCommRing to ℤCR)
open import Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly
renaming (PolyCommRing to A[X1,···,Xn] ; Poly to A[x1,···,xn])
private variable
ℓ : Level
-----------------------------------------------------------------------------
-- General Nth polynome / quotient
-- Better to declare an alias
PolyCommRing-Quotient : (A : CommRing ℓ) → {n m : ℕ} → FinVec (fst (A[X1,···,Xn] A n)) m → CommRing ℓ
PolyCommRing-Quotient A {n} {m} v = A[X1,···,Xn] A n / genIdeal (A[X1,···,Xn] A n) v
-----------------------------------------------------------------------------
-- Notation in the general case and some real cases 1, 2, 3
module _
(Ar@(A , Astr) : CommRing ℓ)
(n : ℕ)
where
<Xkʲ> : (k j : ℕ) → FinVec (A[x1,···,xn] Ar n) 1
<Xkʲ> k j zero = base (genδℕ-Vec n k j 0) (CommRingStr.1r Astr)
A[X1,···,Xn]/<Xkʲ> : (k j : ℕ) → CommRing ℓ
A[X1,···,Xn]/<Xkʲ> k j = (A[X1,···,Xn] Ar n) / (genIdeal ((A[X1,···,Xn] Ar n)) (<Xkʲ> k j))
A[x1,···,xn]/<xkʲ> : (k j : ℕ) → Type ℓ
A[x1,···,xn]/<xkʲ> k j = fst (A[X1,···,Xn]/<Xkʲ> k j)
<X1,···,Xn> : FinVec (A[x1,···,xn] Ar n) n
<X1,···,Xn> = λ k → base (δℕ-Vec n (toℕ k)) (CommRingStr.1r Astr)
A[X1,···,Xn]/<X1,···,Xn> : CommRing ℓ
A[X1,···,Xn]/<X1,···,Xn> = (A[X1,···,Xn] Ar n) / (genIdeal ((A[X1,···,Xn] Ar n)) <X1,···,Xn>)
A[x1,···,xn]/<x1,···,xn> : Type ℓ
A[x1,···,xn]/<x1,···,xn> = fst A[X1,···,Xn]/<X1,···,Xn>
|
{
"alphanum_fraction": 0.5886627907,
"avg_line_length": 35.5862068966,
"ext": "agda",
"hexsha": "b14638becab49bef29e3471f3bb65c1c45c8bbfa",
"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/CommRing/Instances/Polynomials/MultivariatePoly-Quotient.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/CommRing/Instances/Polynomials/MultivariatePoly-Quotient.agda",
"max_line_length": 101,
"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/CommRing/Instances/Polynomials/MultivariatePoly-Quotient.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 834,
"size": 2064
}
|
------------------------------------------------------------------------
-- Examples showing how Tree-sort can be used
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Tree-sort.Examples
{c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) where
open Derived-definitions-and-properties eq
open import Prelude
open import Bag-equivalence eq
import Nat eq as Nat
-- Comparison functions for natural numbers.
_≤?_ : ℕ → ℕ → Bool
m ≤? n with Nat.total m n
... | inj₁ m≤n = true
... | inj₂ n<m = false
import Tree-sort.Partial eq _≤?_ as P
open import Tree-sort.Full eq Nat._≤_ Nat.total as F using (cons; nil)
-- The sort functions return ordered lists.
orderedP : P.tree-sort (3 ∷ 1 ∷ 2 ∷ []) ≡ 1 ∷ 2 ∷ 3 ∷ []
orderedP = refl _
orderedF : F.tree-sort (3 ∷ 1 ∷ 2 ∷ []) ≡
cons 1 (cons 2 (cons 3 (nil _) _) _) _
orderedF = refl _
-- The sort functions return lists which are bag equivalent to the
-- input. This property can be used to establish bag equivalences
-- between concrete lists.
a-bag-equivalenceP : 1 ∷ 2 ∷ 3 ∷ [] ≈-bag 3 ∷ 1 ∷ 2 ∷ []
a-bag-equivalenceP = P.tree-sort-permutes (3 ∷ 1 ∷ 2 ∷ [])
a-bag-equivalenceF : 1 ∷ 2 ∷ 3 ∷ [] ≈-bag 3 ∷ 1 ∷ 2 ∷ []
a-bag-equivalenceF = F.tree-sort-permutes (3 ∷ 1 ∷ 2 ∷ [])
|
{
"alphanum_fraction": 0.5661375661,
"avg_line_length": 28.1489361702,
"ext": "agda",
"hexsha": "8576f8fa9c5a38601b85cdbb392a9c96d76de997",
"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/Tree-sort/Examples.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/Tree-sort/Examples.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/Tree-sort/Examples.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": 417,
"size": 1323
}
|
module main-old where
import parse
import run
open import lib
open import cedille-types
-- for parser for Cedille source files
import cedille
module parsem = parse cedille.gratr2-nt ptr
open parsem.pnoderiv cedille.rrs cedille.cedille-rtn
module pr = run ptr
open pr.noderiv {- from run.agda -}
-- for parser for options files
import options
import options-types
module parsem2 = parse options.gratr2-nt options-types.ptr
module options-parse = parsem2.pnoderiv options.rrs options.options-rtn
module pr2 = run options-types.ptr
module options-run = pr2.noderiv
-- for parser for Cedille comments & whitespace
import cws
import cws-types
module parsem3 = parse cws.gratr2-nt cws-types.ptr
module cws-parse = parsem3.pnoderiv cws.rrs cws.cws-rtn
module pr3 = run cws.ptr
module cws-run = pr3.noderiv
--open import cedille-find
--open import classify
open import ctxt
open import constants
--open import conversion
open import general-util
open import process-cmd
open import spans
open import syntax-util
open import to-string
open import toplevel-state
import interactive-cmds
open import rkt
opts : Set
opts = options-types.opts
{-------------------------------------------------------------------------------
.cede support
-------------------------------------------------------------------------------}
dot-cedille-directory : string → string
dot-cedille-directory dir = combineFileNames dir ".cedille"
cede-filename : (ced-path : string) → string
cede-filename ced-path =
let dir = takeDirectory ced-path in
let unit-name = base-filename (takeFileName ced-path) in
combineFileNames (dot-cedille-directory dir) (unit-name ^ ".cede")
-- .cede files are just a dump of the spans, prefixed by 'e' if there is an error
write-cede-file : (ced-path : string) → (ie : include-elt) → IO ⊤
write-cede-file ced-path ie =
-- putStrLn ("write-cede-file " ^ ced-path ^ " : " ^ contents) >>
let dir = takeDirectory ced-path in
createDirectoryIfMissing ff (dot-cedille-directory dir) >>
writeFile (cede-filename ced-path)
((if (include-elt.err ie) then "e" else "") ^
(include-elt-spans-to-string ie))
-- we assume the cede file is known to exist at this point
read-cede-file : (ced-path : string) → IO (𝔹 × string)
read-cede-file ced-path =
get-file-contents (cede-filename ced-path) >>= λ c → finish c
where finish : maybe string → IO (𝔹 × string)
finish nothing = return (tt , global-error-string ("Could not read the file " ^ cede-filename ced-path ^ "."))
finish (just ss) with string-to-𝕃char ss
finish (just ss) | ('e' :: ss') = forceFileRead ss >> return (tt , 𝕃char-to-string ss')
finish (just ss) | _ = forceFileRead ss >> return (ff , ss)
add-cedille-extension : string → string
add-cedille-extension x = x ^ "." ^ cedille-extension
find-imported-file : (dirs : 𝕃 string) → (unit-name : string) → IO string
find-imported-file [] unit-name = return (add-cedille-extension unit-name) -- assume the current directory if the unit is not found
find-imported-file (dir :: dirs) unit-name =
let e = combineFileNames dir (add-cedille-extension unit-name) in
doesFileExist e >>= λ b →
if b then
return e
else
find-imported-file dirs unit-name
-- return a list of pairs (i,p) where i is the import string in the file, and p is the full path for that imported file
find-imported-files : (dirs : 𝕃 string) → (imports : 𝕃 string) → IO (𝕃 (string × string))
find-imported-files dirs (u :: us) =
find-imported-file dirs u >>= λ p →
find-imported-files dirs us >>= λ ps →
return ((u , p) :: ps)
find-imported-files dirs [] = return []
ced-file-up-to-date : (ced-path : string) → IO 𝔹
ced-file-up-to-date ced-path =
let e = cede-filename ced-path in
doesFileExist e >>= λ b →
if b then
fileIsOlder ced-path e
else
return ff
paths-to-𝕃string : options-types.paths → 𝕃 string
paths-to-𝕃string options-types.PathsNil = []
paths-to-𝕃string (options-types.PathsCons p ps) = p :: paths-to-𝕃string ps
opts-get-include-path : opts → 𝕃 string
opts-get-include-path options-types.OptsNil = []
opts-get-include-path (options-types.OptsCons (options-types.Lib ps) oo) = (paths-to-𝕃string ps) ++ opts-get-include-path oo
opts-get-include-path (options-types.OptsCons options-types.NoCedeFiles oo) = opts-get-include-path oo
opts-get-include-path (options-types.OptsCons options-types.NoRktFiles oo) = opts-get-include-path oo
--opts-get-include-path (options-types.OptsCons _ oo) = opts-get-include-path oo
{- see if "no-cede-files" is turned on in the options file -}
opts-get-no-cede-files : opts → 𝔹
opts-get-no-cede-files options-types.OptsNil = ff
opts-get-no-cede-files (options-types.OptsCons options-types.NoCedeFiles oo) = tt
opts-get-no-cede-files (options-types.OptsCons options-types.NoRktFiles oo) = opts-get-no-cede-files oo
opts-get-no-cede-files (options-types.OptsCons (options-types.Lib _) oo) = opts-get-no-cede-files oo
{- see if "no-rkt-files" is turned on in the options file -}
opts-get-no-rkt-files : opts → 𝔹
opts-get-no-rkt-files options-types.OptsNil = ff
opts-get-no-rkt-files (options-types.OptsCons options-types.NoCedeFiles oo) = opts-get-no-rkt-files oo
opts-get-no-rkt-files (options-types.OptsCons options-types.NoRktFiles oo) = tt
opts-get-no-rkt-files (options-types.OptsCons (options-types.Lib _) oo) = opts-get-no-rkt-files oo
{- reparse the given file, and update its include-elt in the toplevel-state appropriately -}
reparse : toplevel-state → (filename : string) → IO toplevel-state
reparse st filename =
-- putStrLn ("reparsing " ^ filename) >>
doesFileExist filename >>= λ b →
(if b then
(readFiniteFile filename >>= processText)
else return (error-include-elt ("The file " ^ filename ^ " could not be opened for reading."))) >>= λ ie →
return (set-include-elt st filename ie)
where processText : string → IO include-elt
processText x with string-to-𝕃char x
processText x | s with runRtn s
processText x | s | inj₁ cs = return (error-include-elt ("Parse error in file " ^ filename ^ " at position " ^ (ℕ-to-string (length s ∸ length cs)) ^ "."))
processText x | s | inj₂ r with rewriteRun r
processText x | s | inj₂ r | ParseTree (parsed-start t) :: [] with cws-parse.runRtn s
processText x | s | inj₂ r | ParseTree (parsed-start t) :: [] | inj₁ cs = return (error-include-elt ("This shouldn't happen in " ^ filename ^ " at position "
^ (ℕ-to-string (length s ∸ length cs)) ^ "."))
processText x | s | inj₂ r | ParseTree (parsed-start t) :: [] | inj₂ r2 with cws-parse.rewriteRun r2
processText x | s | inj₂ r | ParseTree (parsed-start t) :: [] | inj₂ r2 | cws-run.ParseTree (cws-types.parsed-start t2) :: [] = find-imported-files (toplevel-state.include-path st)
(get-imports t) >>= λ deps → return
(new-include-elt filename deps t t2)
processText x | s | inj₂ r | ParseTree (parsed-start t) :: [] | inj₂ r2 | _ = return (error-include-elt ("Parse error in file " ^ filename ^ "."))
processText x | s | inj₂ r | _ = return (error-include-elt ("Parse error in file " ^ filename ^ "."))
add-spans-if-up-to-date : (up-to-date : 𝔹) → (use-cede-files : 𝔹) → (filename : string) → include-elt → IO include-elt
add-spans-if-up-to-date up-to-date use-cede-files filename ie =
if up-to-date && use-cede-files then
(read-cede-file filename >>= finish)
else
return ie
where finish : 𝔹 × string → IO include-elt
finish (err , ss) = return (set-do-type-check-include-elt (set-spans-string-include-elt ie err ss) ff)
{- make sure that the current ast and dependencies are stored in the
toplevel-state, updating the state as needed. -}
ensure-ast-deps : toplevel-state → (filename : string) → IO toplevel-state
ensure-ast-deps s filename with get-include-elt-if s filename
ensure-ast-deps s filename | nothing =
let ucf = (toplevel-state.use-cede-files s) in
reparse s filename >>= λ s →
ced-file-up-to-date filename >>= λ up-to-date →
add-spans-if-up-to-date up-to-date ucf filename (get-include-elt s filename) >>= λ ie →
return (set-include-elt s filename ie)
ensure-ast-deps s filename | just ie =
let ucf = (toplevel-state.use-cede-files s) in
ced-file-up-to-date filename >>= λ up-to-date →
if up-to-date then
(add-spans-if-up-to-date up-to-date (toplevel-state.use-cede-files s) filename (get-include-elt s filename) >>= λ ie →
return (set-include-elt s filename ie))
else reparse s filename
{- helper function for update-asts, which keeps track of the files we have seen so
we avoid importing the same file twice, and also avoid following cycles in the import
graph. -}
{-# TERMINATING #-}
update-astsh : stringset {- seen already -} → toplevel-state → (filename : string) →
IO (stringset {- seen already -} × toplevel-state)
update-astsh seen s filename =
-- putStrLn ("update-astsh [filename = " ^ filename ^ "]") >>
if stringset-contains seen filename then return (seen , s)
else (ensure-ast-deps s filename >>= cont (stringset-insert seen filename))
where cont : stringset → toplevel-state → IO (stringset × toplevel-state)
cont seen s with get-include-elt s filename
cont seen s | ie with include-elt.deps ie
cont seen s | ie | ds =
proc seen s ds
where proc : stringset → toplevel-state → 𝕃 string → IO (stringset × toplevel-state)
proc seen s [] =
if (list-any (get-do-type-check s) ds)
then return (seen , set-include-elt s filename (set-do-type-check-include-elt ie tt))
else return (seen , s)
proc seen s (d :: ds) = update-astsh seen s d >>= λ p →
proc (fst p) (snd p) ds
{- this function updates the ast associated with the given filename in the toplevel state.
So if we do not have an up-to-date .cede file (i.e., there is no such file at all,
or it is older than the given file), reparse the file. We do this recursively for all
dependencies (i.e., imports) of the file. -}
update-asts : toplevel-state → (filename : string) → IO toplevel-state
update-asts s filename = update-astsh empty-stringset s filename >>= λ p →
return (snd p)
{- this function checks the given file (if necessary), updates .cede and .rkt files (again, if necessary), and replies on stdout if appropriate -}
checkFile : toplevel-state → (filename : string) → (should-print-spans : 𝔹) → IO toplevel-state
checkFile s filename should-print-spans =
-- putStrLn ("checkFile " ^ filename) >>
update-asts s filename >>= λ s →
finish (process-file s filename) -- ignore-errors s filename)
where reply : toplevel-state → IO ⊤
reply s with get-include-elt-if s filename
reply s | nothing = putStrLn (global-error-string ("Internal error looking up information for file " ^ filename ^ "."))
reply s | just ie =
if should-print-spans then
putStrLn (include-elt-spans-to-string ie)
else return triv
finish : toplevel-state × mod-info → IO toplevel-state
finish (s , m) with s
finish (s , m) | mk-toplevel-state use-cede make-rkt ip mod is Γ =
writeo mod >>
reply s >>
return (mk-toplevel-state use-cede make-rkt ip [] is (ctxt-set-current-mod Γ m))
where
writeo : 𝕃 string → IO ⊤
writeo [] = return triv
writeo (f :: us) =
let ie = get-include-elt s f in
(if use-cede then (write-cede-file f ie) else (return triv)) >>
(if make-rkt then (write-rkt-file f (toplevel-state.Γ s) ie) else (return triv)) >>
writeo us
remove-dup-include-paths : 𝕃 string → 𝕃 string
remove-dup-include-paths l = stringset-strings (stringset-insert* empty-stringset l)
-- this is the function that handles requests (from the frontend) on standard input
{-# TERMINATING #-}
readCommandsFromFrontend : toplevel-state → IO ⊤
readCommandsFromFrontend s =
getLine >>= λ input →
let input-list : 𝕃 string
input-list = (string-split (undo-escape-string input) delimiter)
in (handleCommands input-list s) >>= λ s →
readCommandsFromFrontend s
where
delimiter : char
delimiter = '§'
errorCommand : 𝕃 string → toplevel-state → IO toplevel-state
errorCommand ls s = putStrLn (global-error-string "Invalid command sequence \"" ^ (𝕃-to-string (λ x → x) ", " ls) ^ "\".") >>= λ x → return s
debugCommand : toplevel-state → IO toplevel-state
debugCommand s = putStrLn (escape-string (toplevel-state-to-string s)) >>= λ x → return s
checkCommand : 𝕃 string → toplevel-state → IO toplevel-state
checkCommand (input :: []) s = canonicalizePath input >>= λ input-filename →
checkFile (set-include-path s (remove-dup-include-paths (takeDirectory input-filename :: toplevel-state.include-path s)))
input-filename tt {- should-print-spans -}
checkCommand ls s = errorCommand ls s
interactiveCommand : 𝕃 string → toplevel-state → IO toplevel-state
interactiveCommand xs s = interactive-cmds.interactive-cmd xs s
{- findCommand : 𝕃 string → toplevel-state → IO toplevel-state
findCommand (symbol :: []) s = putStrLn (find-symbols-to-JSON symbol (toplevel-state-lookup-occurrences symbol s)) >>= λ x → return s
findCommand _ s = errorCommand s -}
handleCommands : 𝕃 string → toplevel-state → IO toplevel-state
handleCommands ("check" :: xs) s = checkCommand xs s
handleCommands ("debug" :: []) s = debugCommand s
handleCommands ("interactive" :: xs) s = interactiveCommand xs s
-- handleCommands ("find" :: xs) s = findCommand xs s
handleCommands ls s = errorCommand ls s
-- function to process command-line arguments
processArgs : opts → 𝕃 string → IO ⊤
-- this is the case for when we are called with a single command-line argument, the name of the file to process
processArgs oo (input-filename :: []) =
canonicalizePath input-filename >>= λ input-filename →
checkFile (new-toplevel-state (takeDirectory input-filename :: opts-get-include-path oo) (~ (opts-get-no-cede-files oo)) (~ (opts-get-no-rkt-files oo)) )
input-filename ff {- should-print-spans -} >>= finish input-filename
where finish : string → toplevel-state → IO ⊤
finish input-filename s =
let ie = get-include-elt s input-filename in
if include-elt.err ie then (putStrLn (include-elt-spans-to-string ie)) else return triv
-- this is the case where we will go into a loop reading commands from stdin, from the fronted
processArgs oo [] = readCommandsFromFrontend (new-toplevel-state (opts-get-include-path oo) (~ (opts-get-no-cede-files oo)) (~ (opts-get-no-rkt-files oo)))
-- all other cases are errors
processArgs oo xs = putStrLn ("Run with the name of one file to process, or run with no command-line arguments and enter the\n"
^ "names of files one at a time followed by newlines (this is for the emacs mode).")
-- helper function to try to parse the options file
processOptions : string → string → (string ⊎ options-types.opts)
processOptions filename s with string-to-𝕃char s
... | i with options-parse.runRtn i
... | inj₁ cs =
inj₁ ("Parse error in file " ^ filename ^ " at position " ^ (ℕ-to-string (length i ∸ length cs)) ^ ".")
... | inj₂ r with options-parse.rewriteRun r
... | options-run.ParseTree (options-types.parsed-start (options-types.File oo)) :: [] = inj₂ oo
... | _ = inj₁ ("Parse error in file " ^ filename ^ ". ")
-- read the ~/.cedille/options file
readOptions : IO (string ⊎ options-types.opts)
readOptions =
getHomeDirectory >>= λ homedir →
let homecedir = dot-cedille-directory homedir in
let optsfile = combineFileNames homecedir options-file-name in
createDirectoryIfMissing ff homecedir >>
doesFileExist optsfile >>= λ b →
if b then
(readFiniteFile optsfile >>= λ f → return (processOptions optsfile f))
else
(return (inj₂ options-types.OptsNil))
postulate
initializeStdinToUTF8 : IO ⊤
setStdinNewlineMode : IO ⊤
{-# COMPILED initializeStdinToUTF8 System.IO.hSetEncoding System.IO.stdin System.IO.utf8 #-}
{-# COMPILED setStdinNewlineMode System.IO.hSetNewlineMode System.IO.stdin System.IO.universalNewlineMode #-}
-- main entrypoint for the backend
main : IO ⊤
main = initializeStdoutToUTF8 >>
initializeStdinToUTF8 >>
setStdoutNewlineMode >>
setStdinNewlineMode >>
readOptions >>=
next
where next : string ⊎ options-types.opts → IO ⊤
next (inj₁ s) = putStrLn (global-error-string s)
next (inj₂ oo) = getArgs >>= processArgs oo
|
{
"alphanum_fraction": 0.6378841138,
"avg_line_length": 49.8248587571,
"ext": "agda",
"hexsha": "a0fa76304d5d357533359b5b064d71d8a179d036",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xoltar/cedille",
"max_forks_repo_path": "src/main-old.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "xoltar/cedille",
"max_issues_repo_path": "src/main-old.agda",
"max_line_length": 188,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xoltar/cedille",
"max_stars_repo_path": "src/main-old.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4602,
"size": 17638
}
|
module Utils.HaskellFunctions where
open import bool
open import maybe
open import Utils.HaskellTypes
postulate _str-eq_ : String → String → 𝔹
{-# COMPILED _str-eq_ (==) #-}
infixr 20 _++s_
postulate _++s_ : String → String → String
{-# COMPILED _++s_ Data.Text.append #-}
fst : {A B : Set} → Prod A B → A
fst (x , y) = x
snd : {A B : Set} → Prod A B → B
snd (x , y) = y
fstT : {A B C : Set} → Triple A B C → A
fstT (triple x y z) = x
sndT : {A B C : Set} → Triple A B C → B
sndT (triple x y z) = y
trdT : {A B C : Set} → Triple A B C → C
trdT (triple x y z) = z
fstMapT : {A₁ A₂ B C : Set} → (A₁ → A₂) → Triple A₁ B C → Triple A₂ B C
fstMapT f (triple x y z) = triple (f x) y z
_++_ : {A : Set} → List A → List A → List A
[] ++ l₂ = l₂
(x :: l₁) ++ l₂ = x :: (l₁ ++ l₂)
map : {A B : Set} → (A → B) → List A → List B
map f [] = []
map f (x :: xs) = f x :: map f xs
list-member : {A : Set}(eq : A → A → 𝔹)(a : A)(l : List A) → 𝔹
list-member eq a [] = ff
list-member eq a (x :: xs) with eq a x
... | tt = tt
... | ff = list-member eq a xs
foldr : {A : Set}{B : Set} → (A → B → B) → B → List A → B
foldr f b [] = b
foldr f b (a :: as) = f a (foldr f b as)
foldl : {A : Set}{B : Set} → (B → A → B) → B → List A → B
foldl f b [] = b
foldl f b (x :: xs) = foldl f (f b x) xs
lookup : ∀{A B} → (A → A → 𝔹) → A → List (Prod A B) → maybe B
lookup _eq_ x [] = nothing
lookup _eq_ x ((y , b) :: l) with x eq y
... | tt = just b
... | ff = lookup _eq_ x l
disjoint : {A : Set} → (A → A → 𝔹) → List A → List A → 𝔹
disjoint _eq_ (x :: l₁) (y :: l₂) with x eq y
... | tt = ff
... | ff = disjoint _eq_ l₁ l₂
disjoint _ [] _ = tt
disjoint _ _ [] = tt
|
{
"alphanum_fraction": 0.5221078134,
"avg_line_length": 24.6417910448,
"ext": "agda",
"hexsha": "8114bc7ccff1b48ebfb8bca9be312dd1d8e774fd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "heades/Agda-LLS",
"max_forks_repo_path": "Source/ALL/Utils/HaskellFunctions.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_issues_repo_issues_event_max_datetime": "2017-04-05T17:30:16.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-27T14:52:46.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "heades/Agda-LLS",
"max_issues_repo_path": "Source/ALL/Utils/HaskellFunctions.agda",
"max_line_length": 71,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "heades/Agda-LLS",
"max_stars_repo_path": "Source/ALL/Utils/HaskellFunctions.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-02T23:41:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-09T20:53:53.000Z",
"num_tokens": 706,
"size": 1651
}
|
module Coirc.Network where
open import Function
open import Coinduction
open import Data.Unit
open import Data.String
open import Data.Maybe
open import IO
open import Coirc
open import Coirc.Parser
import Coirc.Network.Primitive as Prim
private
Handle = Prim.Handle
hConnect : String → IO Handle
hConnect s = lift (Prim.hConnect s)
hGetLine : Handle → IO String
hGetLine h =
♯ lift (Prim.hGetLine h) >>= λ s →
♯ (♯ putStrLn s >>
♯ return (s ++ "\n"))
hPutStr : Handle → String → IO ⊤
hPutStr h s = ♯ lift (Prim.hPutStr h s) >> ♯ return tt
hSend : Handle → String → IO ⊤
hSend h s =
♯ putStrLn ("> " ++ s) >>
♯ hPutStr h (s ++ "\r\n")
getEvent : Handle → IO (Maybe Event)
getEvent h = ♯ hGetLine h >>= (λ x → ♯ f x) where
f : String → IO (Maybe Event)
f = return ∘ parse-Event ∘ toList
runAction : Handle → Action → IO ⊤
runAction h (print text) =
putStrLn text
runAction h (nick name) =
hSend h ("NICK " ++ name)
runAction h (user name real) =
hSend h ("USER " ++ name ++ " 0 * :" ++ real)
runAction h (pong name) =
hSend h ("PONG " ++ name)
runAction h (join channel) =
hSend h ("JOIN " ++ channel)
runAction h (part channel) =
hSend h ("PART " ++ channel)
runAction h (privmsg target text) =
hSend h ("PRIVMSG " ++ target ++ " :" ++ text)
runAction h (quit text) =
hSend h ("QUIT :" ++ text)
runSP : Handle → Bot → IO ⊤
runSP h (get f) =
♯ getEvent h >>= λ e? →
♯ g e?
where
g : Maybe Event → IO ⊤
g nothing =
♯ putStrLn "<disconnect>" >>
♯ return tt
g (just e) = runSP h (f e)
runSP h (put a sp) =
♯ runAction h a >>
♯ runSP h (♭ sp)
runBot : Bot → String → IO ⊤
runBot bot server =
♯ hConnect server >>= λ h →
♯ runSP h bot
|
{
"alphanum_fraction": 0.5812917595,
"avg_line_length": 24.602739726,
"ext": "agda",
"hexsha": "8c31b94b6af1b099aa7168f7253d9f2662a45652",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:53:29.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:53:29.000Z",
"max_forks_repo_head_hexsha": "fd5b9aeb84851da56ce018ed15a7da1dcc949461",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/coirc",
"max_forks_repo_path": "src/Coirc/Network.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd5b9aeb84851da56ce018ed15a7da1dcc949461",
"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/coirc",
"max_issues_repo_path": "src/Coirc/Network.agda",
"max_line_length": 56,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd5b9aeb84851da56ce018ed15a7da1dcc949461",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/coirc",
"max_stars_repo_path": "src/Coirc/Network.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 603,
"size": 1796
}
|
------------------------------------------------------------------------------
-- Distributive laws on a binary operation: Task B
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module DistributiveLaws.TaskB.UnprovedATP where
open import DistributiveLaws.Base
------------------------------------------------------------------------------
-- 2018-06-28: The ATPs could not prove the theorem (300 sec).
postulate
prop₂ : ∀ u x y z →
(x · y · (z · u)) · ((x · y · (z · u)) · (x · z · (y · u))) ≡
x · z · (y · u)
{-# ATP prove prop₂ #-}
|
{
"alphanum_fraction": 0.3699346405,
"avg_line_length": 36.4285714286,
"ext": "agda",
"hexsha": "2ab5e3a122f2fe6790bcc70a13ac3d462e17ba3e",
"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/DistributiveLaws/TaskB/UnprovedATP.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/DistributiveLaws/TaskB/UnprovedATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/DistributiveLaws/TaskB/UnprovedATP.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": 158,
"size": 765
}
|
module DynTheory where
open import Prelude
open import T
---- Some theory about the dynamic semantics
module DynTheory where
-- prove some obvious theorems about iterated stepping
-- transitivity (which makes sense, given that it is the transitive closure)
eval-trans : ∀{A} {e e' e'' : TCExp A} →
e ~>* e' → e' ~>* e'' → e ~>* e''
eval-trans eval-refl E2 = E2
eval-trans (eval-cons S1 E1') E2 = eval-cons S1 (eval-trans E1' E2)
-- prove that we can life any compatibility rule from steps to eval
eval-compat : ∀{A B} {P : TCExp A -> TCExp B} →
(∀{e e'} → (e ~> e' → P e ~> P e')) →
{e e' : TCExp A} → e ~>* e' → P e ~>* P e'
eval-compat f eval-refl = eval-refl
eval-compat f (eval-cons S1 D) = eval-cons (f S1) (eval-compat f D)
-- Lemma we need to prove determism
not-val-and-step : ∀{C : Set} {A : TTp} {e e' : TCExp A} →
TVal e → e ~> e' →
C
not-val-and-step val-zero ()
not-val-and-step val-lam ()
not-val-and-step (val-suc v) (step-suc S1) = not-val-and-step v S1
-- Show that the dynamic semantics are a function
step-deterministic : ∀{A} → (e : TCExp A) → {e' e'' : TCExp A} →
e ~> e' → e ~> e'' ->
e' ≡ e''
-- Trivial contradictory cases
step-deterministic (var x) () S2
step-deterministic (Λ e) () S2
step-deterministic zero () S2
step-deterministic (Λ e $ e') step-beta (step-app-l ())
step-deterministic (Λ e $ e') (step-app-l ()) step-beta
step-deterministic (rec .zero e'' e₂) (step-rec ()) step-rec-z
step-deterministic (rec zero e₀ es) step-rec-z (step-rec ())
-- Nontrival contradictory cases
step-deterministic (rec (suc e) e₁ e₂) (step-rec (step-suc S1)) (step-rec-s v) = not-val-and-step v S1
step-deterministic (rec (suc e) e₁ e₂) (step-rec-s v) (step-rec (step-suc S2)) = not-val-and-step v S2
-- Normal cases
step-deterministic (e $ e') (step-app-l S1) (step-app-l S2) =
resp (λ x → x $ e') (step-deterministic e S1 S2)
step-deterministic (Λ e $ e') step-beta step-beta = Refl
step-deterministic (suc e) (step-suc S1) (step-suc S2) = resp suc (step-deterministic e S1 S2)
step-deterministic (rec e e₁ e₂) (step-rec S1) (step-rec S2) =
resp (λ x → rec x e₁ e₂) (step-deterministic e S1 S2)
step-deterministic (rec zero _ _) step-rec-z step-rec-z = Refl
step-deterministic (rec (suc e) e₁ e₂) (step-rec-s x) (step-rec-s x₁) = Refl
-- Prove that if we evaluate to two expressions, and one is a value,
-- then the other evaluates to it.
eval-finish : ∀{A} → {e : TCExp A} → {e' e'' : TCExp A} →
e ~>* e' → e ~>* e'' →
TVal e'' →
e' ~>* e''
eval-finish eval-refl E2 v = E2
eval-finish (eval-cons S1 E1) eval-refl v = not-val-and-step v S1
eval-finish (eval-cons S1 E1) (eval-cons S2 E2) v with step-deterministic _ S1 S2
... | Refl = eval-finish E1 E2 v
-- Prove that if we evaluate to two values, they are the same
eval-deterministic : ∀{A} → {e : TCExp A} → {e' e'' : TCExp A} →
e ~>* e' → e ~>* e'' →
TVal e' → TVal e'' →
e' ≡ e''
eval-deterministic E1 E2 v1 v2 with eval-finish E1 E2 v2
... | eval-refl = Refl
... | eval-cons S1 _ = not-val-and-step v1 S1
open DynTheory public
|
{
"alphanum_fraction": 0.5700412007,
"avg_line_length": 42.475,
"ext": "agda",
"hexsha": "554eef790a4d293a8db481b4745cd537f42e006f",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-05-04T22:37:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-26T11:39:14.000Z",
"max_forks_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "msullivan/godels-t",
"max_forks_repo_path": "DynTheory.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "msullivan/godels-t",
"max_issues_repo_path": "DynTheory.agda",
"max_line_length": 104,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "msullivan/godels-t",
"max_stars_repo_path": "DynTheory.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-22T00:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-25T01:52:57.000Z",
"num_tokens": 1157,
"size": 3398
}
|
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Nat.Mod where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat
open import Cubical.Data.Nat.Order
-- Defining x mod 0 to be 0. This way all the theorems below are true
-- for n : ℕ instead of n : ℕ₊₁.
------ Preliminary definitions ------
modInd : (n : ℕ) → ℕ → ℕ
modInd n = +induction n (λ _ → ℕ) (λ x _ → x) λ _ x → x
modIndBase : (n m : ℕ) → m < suc n → modInd n m ≡ m
modIndBase n = +inductionBase n (λ _ → ℕ) (λ x _ → x) (λ _ x → x)
modIndStep : (n m : ℕ) → modInd n (suc n + m) ≡ modInd n m
modIndStep n = +inductionStep n (λ _ → ℕ) (λ x _ → x) (λ _ x → x)
-------------------------------------
_mod_ : (x n : ℕ) → ℕ
x mod zero = 0
x mod (suc n) = modInd n x
mod< : (n x : ℕ) → x mod (suc n) < (suc n)
mod< n =
+induction n
(λ x → x mod (suc n) < suc n)
(λ x base → fst base
, (cong (λ x → fst base + suc x)
(modIndBase n x base)
∙ snd base))
λ x ind → fst ind
, cong (λ x → fst ind + suc x)
(modIndStep n x) ∙ snd ind
mod-rUnit : (n x : ℕ) → x mod n ≡ ((x + n) mod n)
mod-rUnit zero x = refl
mod-rUnit (suc n) x =
sym (modIndStep n x)
∙ cong (modInd n) (+-comm (suc n) x)
mod-lUnit : (n x : ℕ) → x mod n ≡ ((n + x) mod n)
mod-lUnit zero _ = refl
mod-lUnit (suc n) x = sym (modIndStep n x)
mod+mod≡mod : (n x y : ℕ)
→ (x + y) mod n ≡ (((x mod n) + (y mod n)) mod n)
mod+mod≡mod zero _ _ = refl
mod+mod≡mod (suc n) =
+induction n
(λ z → (x : ℕ)
→ ((z + x) mod (suc n))
≡ (((z mod (suc n)) + (x mod (suc n))) mod (suc n)))
(λ x p →
+induction n _
(λ y q → cong (modInd n)
(sym (cong₂ _+_ (modIndBase n x p)
(modIndBase n y q))))
λ y ind → cong (modInd n)
(cong (x +_) (+-comm (suc n) y)
∙ (+-assoc x y (suc n)))
∙∙ sym (mod-rUnit (suc n) (x + y))
∙∙ ind
∙ cong (λ z → modInd n
((modInd n x + z)))
(mod-rUnit (suc n) y
∙ cong (modInd n) (+-comm y (suc n))))
λ x p y →
cong (modInd n) (cong suc (sym (+-assoc n x y)))
∙∙ sym (mod-lUnit (suc n) (x + y))
∙∙ p y
∙ sym (cong (modInd n)
(cong (_+ modInd n y)
(cong (modInd n)
(+-comm (suc n) x) ∙ sym (mod-rUnit (suc n) x))))
mod-idempotent : {n : ℕ} (x : ℕ) → (x mod n) mod n ≡ x mod n
mod-idempotent {n = zero} _ = refl
mod-idempotent {n = suc n} =
+induction n (λ x → (x mod suc n) mod (suc n) ≡ x mod (suc n))
(λ x p → cong (_mod (suc n))
(modIndBase n x p))
λ x p → cong (_mod (suc n))
(modIndStep n x)
∙∙ p
∙∙ mod-rUnit (suc n) x
∙ (cong (_mod (suc n)) (+-comm x (suc n)))
mod-rCancel : (n x y : ℕ) → (x + y) mod n ≡ (x + y mod n) mod n
mod-rCancel zero x y = refl
mod-rCancel (suc n) x =
+induction n _
(λ y p → cong (λ z → (x + z) mod (suc n))
(sym (modIndBase n y p)))
λ y p → cong (_mod suc n) (+-assoc x (suc n) y
∙∙ (cong (_+ y) (+-comm x (suc n)))
∙∙ sym (+-assoc (suc n) x y))
∙∙ sym (mod-lUnit (suc n) (x + y))
∙∙ (p ∙ cong (λ z → (x + z) mod suc n) (mod-lUnit (suc n) y))
mod-lCancel : (n x y : ℕ) → (x + y) mod n ≡ (x mod n + y) mod n
mod-lCancel n x y =
cong (_mod n) (+-comm x y)
∙∙ mod-rCancel n y x
∙∙ cong (_mod n) (+-comm y (x mod n))
zero-charac : (n : ℕ) → n mod n ≡ 0
zero-charac zero = refl
zero-charac (suc n) = cong (_mod suc n) (+-comm 0 (suc n))
∙∙ modIndStep n 0
∙∙ modIndBase n 0 (n , (+-comm n 1))
-- remainder and quotient after division by n
-- Again, allowing for 0-division to get nicer syntax
remainder_/_ : (x n : ℕ) → ℕ
remainder x / zero = x
remainder x / suc n = x mod (suc n)
quotient_/_ : (x n : ℕ) → ℕ
quotient x / zero = 0
quotient x / suc n =
+induction n (λ _ → ℕ) (λ _ _ → 0) (λ _ → suc) x
≡remainder+quotient : (n x : ℕ)
→ (remainder x / n) + n · (quotient x / n) ≡ x
≡remainder+quotient zero x = +-comm x 0
≡remainder+quotient (suc n) =
+induction n
(λ x → (remainder x / (suc n)) + (suc n)
· (quotient x / (suc n)) ≡ x)
(λ x base → cong₂ _+_ (modIndBase n x base)
(cong ((suc n) ·_)
(+inductionBase n _ _ _ x base))
∙∙ cong (x +_) (·-comm n 0)
∙∙ +-comm x 0)
λ x ind → cong₂ _+_ (modIndStep n x)
(cong ((suc n) ·_) (+inductionStep n _ _ _ x))
∙∙ cong (modInd n x +_)
(·-suc (suc n) (+induction n _ _ _ x))
∙∙ cong (modInd n x +_)
(+-comm (suc n) ((suc n) · (+induction n _ _ _ x)))
∙∙ +-assoc (modInd n x) ((suc n) · +induction n _ _ _ x) (suc n)
∙∙ cong (_+ suc n) ind
∙ +-comm x (suc n)
private
test₀ : 100 mod 81 ≡ 19
test₀ = refl
test₁ : ((11 + (10 mod 3)) mod 3) ≡ 0
test₁ = refl
|
{
"alphanum_fraction": 0.4455686715,
"avg_line_length": 34.6558441558,
"ext": "agda",
"hexsha": "4eddabaf490104ef13b33c39b9d63b9ac12fe0a4",
"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": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "FernandoLarrain/cubical",
"max_forks_repo_path": "Cubical/Data/Nat/Mod.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"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": "FernandoLarrain/cubical",
"max_issues_repo_path": "Cubical/Data/Nat/Mod.agda",
"max_line_length": 74,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Data/Nat/Mod.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T21:49:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-05T21:49:23.000Z",
"num_tokens": 1957,
"size": 5337
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Group.MorphismProperties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Function using (_∘_)
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Functions.Embedding
open import Cubical.Data.Sigma
open import Cubical.Structures.Axioms
open import Cubical.Structures.NAryOp
open import Cubical.Structures.Pointed
open import Cubical.Structures.Semigroup hiding (⟨_⟩)
open import Cubical.Structures.Monoid hiding (⟨_⟩)
open import Cubical.Structures.Group.Base
open import Cubical.Structures.Group.Properties
open import Cubical.Structures.Group.Morphism
open Iso
private
variable
ℓ ℓ' ℓ'' : Level
isPropIsGroupHom : (G : Group {ℓ}) (H : Group {ℓ'}) {f : ⟨ G ⟩ → ⟨ H ⟩} → isProp (isGroupHom G H f)
isPropIsGroupHom G H {f} = isPropΠ2 λ a b → Group.is-set H _ _
isSetGroupHom : {G : Group {ℓ}} {H : Group {ℓ'}} → isSet (GroupHom G H)
isSetGroupHom {G = G} {H = H} = isOfHLevelRespectEquiv 2 equiv (isSetΣ (isSetΠ λ _ → is-set H) λ _ → isProp→isSet (isPropIsGroupHom G H)) where
open Group
equiv : (Σ[ g ∈ (Carrier G → Carrier H) ] (isGroupHom G H g)) ≃ GroupHom G H
equiv = isoToEquiv (iso (λ (g , m) → grouphom g m) (λ (grouphom g m) → g , m) (λ _ → refl) λ _ → refl)
-- Morphism composition
isGroupHomComp : {F : Group {ℓ}} {G : Group {ℓ'}} {H : Group {ℓ''}} →
(f : GroupHom F G) → (g : GroupHom G H) → isGroupHom F H (GroupHom.fun g ∘ GroupHom.fun f)
isGroupHomComp (grouphom f morph-f) (grouphom g morph-g) x y =
cong g (morph-f _ _) ∙ morph-g _ _
compGroupHom : {F : Group {ℓ}} {G : Group {ℓ'}} {H : Group {ℓ''}} → GroupHom F G → GroupHom G H → GroupHom F H
compGroupHom {F = F} {G = G} {H = H} f g = grouphom _ (isGroupHomComp f g)
compGroupEquiv : {F : Group {ℓ}} {G : Group {ℓ'}} {H : Group {ℓ''}} → GroupEquiv F G → GroupEquiv G H → GroupEquiv F H
compGroupEquiv {F = F} {G = G} {H = H} f g =
groupequiv (compEquiv f.eq g.eq) (isGroupHomComp f.hom g.hom) where
module f = GroupEquiv f
module g = GroupEquiv g
idGroupEquiv : (G : Group {ℓ}) → GroupEquiv G G
idGroupEquiv G = groupequiv (idEquiv (Group.Carrier G)) (λ _ _ → refl)
-- Isomorphism inversion
isGroupHomInv : {G : Group {ℓ}} {H : Group {ℓ'}} (f : GroupEquiv G H) → isGroupHom H G (invEq (GroupEquiv.eq f))
isGroupHomInv {G = G} {H = H} (groupequiv (f , eq) morph) h h' = isInj-f _ _ (
f (g (h ⋆² h') )
≡⟨ retEq (f , eq) _ ⟩
h ⋆² h'
≡⟨ sym (λ i → retEq (f , eq) h i ⋆² retEq (f , eq) h' i) ⟩
f (g h) ⋆² f (g h')
≡⟨ sym (morph _ _) ⟩
f (g h ⋆¹ g h') ∎)
where
_⋆¹_ = Group._+_ G
_⋆²_ = Group._+_ H
g = invEq (f , eq)
isEmbedding-f : isEmbedding f
isEmbedding-f = isEquiv→isEmbedding eq
isInj-f : (x y : ⟨ G ⟩) → f x ≡ f y → x ≡ y
isInj-f x y = invEq (_ , isEquiv→isEmbedding eq x y)
invGroupEquiv : {G : Group {ℓ}} {H : Group {ℓ'}} → GroupEquiv G H → GroupEquiv H G
invGroupEquiv {G = G} {H = H} f = groupequiv (invEquiv (eq f)) (isGroupHomInv f) where open GroupEquiv
groupHomEq : {G : Group {ℓ}} {H : Group {ℓ'}} {f g : GroupHom G H} → (GroupHom.fun f ≡ GroupHom.fun g) → f ≡ g
groupHomEq {G = G} {H = H} {grouphom f fm} {grouphom g gm} p i = grouphom (p i) (p-hom i) where
p-hom : PathP (λ i → isGroupHom G H (p i)) fm gm
p-hom = toPathP (isPropIsGroupHom G H _ _)
groupEquivEq : {G : Group {ℓ}} {H : Group {ℓ'}} {f g : GroupEquiv G H} → (GroupEquiv.eq f ≡ GroupEquiv.eq g) → f ≡ g
groupEquivEq {G = G} {H = H} {groupequiv f fm} {groupequiv g gm} p i = groupequiv (p i) (p-hom i) where
p-hom : PathP (λ i → isGroupHom G H (p i .fst)) fm gm
p-hom = toPathP (isPropIsGroupHom G H _ _)
module GroupΣTheory {ℓ} where
RawGroupStructure : Type ℓ → Type ℓ
RawGroupStructure = SemigroupΣTheory.RawSemigroupStructure
rawGroupUnivalentStr : UnivalentStr RawGroupStructure _
rawGroupUnivalentStr = SemigroupΣTheory.rawSemigroupUnivalentStr
-- The neutral element and the inverse function will be derived from the
-- axioms, instead of being defined in the RawGroupStructure in order
-- to have that group equivalences are equivalences that preserves
-- multiplication (so we don't have to show that they also preserve inversion
-- and neutral element, although they will preserve them).
GroupAxioms : (G : Type ℓ) → RawGroupStructure G → Type ℓ
GroupAxioms G _·_ =
IsSemigroup _·_
× (Σ[ e ∈ G ] ((x : G) → (x · e ≡ x) × (e · x ≡ x))
× ((x : G) → Σ[ x' ∈ G ] (x · x' ≡ e) × (x' · x ≡ e)))
GroupStructure : Type ℓ → Type ℓ
GroupStructure = AxiomsStructure RawGroupStructure GroupAxioms
GroupΣ : Type (ℓ-suc ℓ)
GroupΣ = TypeWithStr ℓ GroupStructure
-- Structured equivalences for groups are those for monoids (but different axioms)
GroupEquivStr : StrEquiv GroupStructure ℓ
GroupEquivStr = AxiomsEquivStr (BinaryFunEquivStr PointedEquivStr) GroupAxioms
open MonoidTheory
isPropGroupAxioms : (G : Type ℓ)
→ (s : RawGroupStructure G)
→ isProp (GroupAxioms G s)
isPropGroupAxioms G _+_ = isPropΣ (isPropIsSemigroup _) γ
where
γ : (h : IsSemigroup _+_) →
isProp (Σ[ e ∈ G ] ((x : G) → (x + e ≡ x) × (e + x ≡ x))
× ((x : G) → Σ[ x' ∈ G ] (x + x' ≡ e) × (x' + x ≡ e)))
γ h (e , P , _) (e' , Q , _) =
Σ≡Prop (λ x → isPropΣ (isPropΠ λ _ → isProp× (isSetG _ _) (isSetG _ _)) (β x))
(sym (fst (Q e)) ∙ snd (P e'))
where
isSetG : isSet G
isSetG = IsSemigroup.is-set h
β : (e : G) → ((x : G) → (x + e ≡ x) × (e + x ≡ x))
→ isProp ((x : G) → Σ[ x' ∈ G ] (x + x' ≡ e) × (x' + x ≡ e))
β e He =
isPropΠ λ { x (x' , _ , P) (x'' , Q , _) →
Σ≡Prop (λ _ → isProp× (isSetG _ _) (isSetG _ _))
(inv-lemma ℳ x x' x'' P Q) }
where
ℳ : Monoid
ℳ = makeMonoid e _+_ isSetG (IsSemigroup.assoc h) (λ x → He x .fst) (λ x → He x .snd)
Group→GroupΣ : Group → GroupΣ
Group→GroupΣ (group _ _ _ -_ isGroup) =
_ , _ , IsMonoid.isSemigroup (IsGroup.isMonoid isGroup) ,
_ , IsMonoid.identity (IsGroup.isMonoid isGroup) ,
λ x → (- x) , IsGroup.inverse isGroup x
GroupΣ→Group : GroupΣ → Group
GroupΣ→Group (_ , _ , SG , _ , H0g , w ) =
group _ _ _ (λ x → w x .fst) (isgroup (ismonoid SG H0g) λ x → w x .snd)
GroupIsoGroupΣ : Iso Group GroupΣ
GroupIsoGroupΣ = iso Group→GroupΣ GroupΣ→Group (λ _ → refl) (λ _ → refl)
groupUnivalentStr : UnivalentStr GroupStructure GroupEquivStr
groupUnivalentStr = axiomsUnivalentStr _ isPropGroupAxioms rawGroupUnivalentStr
GroupΣPath : (G H : GroupΣ) → (G ≃[ GroupEquivStr ] H) ≃ (G ≡ H)
GroupΣPath = SIP groupUnivalentStr
GroupEquivΣ : (G H : Group) → Type ℓ
GroupEquivΣ G H = Group→GroupΣ G ≃[ GroupEquivStr ] Group→GroupΣ H
GroupIsoΣPath : {G H : Group} → Iso (GroupEquiv G H) (GroupEquivΣ G H)
fun GroupIsoΣPath (groupequiv e h) = (e , h)
inv GroupIsoΣPath (e , h) = groupequiv e h
rightInv GroupIsoΣPath _ = refl
leftInv GroupIsoΣPath _ = refl
GroupPath : (G H : Group) → (GroupEquiv G H) ≃ (G ≡ H)
GroupPath G H =
GroupEquiv G H ≃⟨ isoToEquiv GroupIsoΣPath ⟩
GroupEquivΣ G H ≃⟨ GroupΣPath _ _ ⟩
Group→GroupΣ G ≡ Group→GroupΣ H ≃⟨ isoToEquiv (invIso (congIso GroupIsoGroupΣ)) ⟩
G ≡ H ■
-- Extract the characterization of equality of groups
GroupPath : (G H : Group {ℓ}) → (GroupEquiv G H) ≃ (G ≡ H)
GroupPath = GroupΣTheory.GroupPath
uaGroup : {G H : Group {ℓ}} → GroupEquiv G H → G ≡ H
uaGroup {G = G} {H = H} = equivFun (GroupPath G H)
carac-uaGroup : {G H : Group {ℓ}} (f : GroupEquiv G H) → cong Group.Carrier (uaGroup f) ≡ ua (GroupEquiv.eq f)
carac-uaGroup (groupequiv f m) =
(refl ∙∙ ua f ∙∙ refl)
≡⟨ sym (rUnit (ua f)) ⟩
ua f ∎
-- Group-ua functoriality
open Group
Group≡ : (G H : Group {ℓ}) → (
Σ[ p ∈ Carrier G ≡ Carrier H ]
Σ[ q ∈ PathP (λ i → p i) (0g G) (0g H) ]
Σ[ r ∈ PathP (λ i → p i → p i → p i) (_+_ G) (_+_ H) ]
Σ[ s ∈ PathP (λ i → p i → p i) (-_ G) (-_ H) ]
PathP (λ i → IsGroup (q i) (r i) (s i)) (isGroup G) (isGroup H))
≃ (G ≡ H)
Group≡ G H = isoToEquiv (iso
(λ (p , q , r , s , t) i → group (p i) (q i) (r i) (s i) (t i))
(λ p → cong Carrier p , cong 0g p , cong _+_ p , cong -_ p , cong isGroup p)
(λ _ → refl) (λ _ → refl))
caracGroup≡ : {G H : Group {ℓ}} (p q : G ≡ H) → cong Group.Carrier p ≡ cong Group.Carrier q → p ≡ q
caracGroup≡ {G = G} {H = H} p q t = cong (fst (Group≡ G H)) (Σ≡Prop (λ t →
isPropΣ
(isOfHLevelPathP' 1 (is-set H) _ _) λ t₁ → isPropΣ
(isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set H) _ _) λ t₂ → isPropΣ
(isOfHLevelPathP' 1 (isSetΠ λ _ → is-set H) _ _) λ t₃ →
isOfHLevelPathP 1 (isPropIsGroup _ _ _) _ _)
t)
uaGroupId : (G : Group {ℓ}) → uaGroup (idGroupEquiv G) ≡ refl
uaGroupId G = caracGroup≡ _ _ (carac-uaGroup (idGroupEquiv G) ∙ uaIdEquiv)
uaCompGroupEquiv : {F G H : Group {ℓ}} (f : GroupEquiv F G) (g : GroupEquiv G H) → uaGroup (compGroupEquiv f g) ≡ uaGroup f ∙ uaGroup g
uaCompGroupEquiv f g = caracGroup≡ _ _ (
cong Carrier (uaGroup (compGroupEquiv f g))
≡⟨ carac-uaGroup (compGroupEquiv f g) ⟩
ua (eq (compGroupEquiv f g))
≡⟨ uaCompEquiv _ _ ⟩
ua (eq f) ∙ ua (eq g)
≡⟨ cong (_∙ ua (eq g)) (sym (carac-uaGroup f)) ⟩
cong Carrier (uaGroup f) ∙ ua (eq g)
≡⟨ cong (cong Carrier (uaGroup f) ∙_) (sym (carac-uaGroup g)) ⟩
cong Carrier (uaGroup f) ∙ cong Carrier (uaGroup g)
≡⟨ sym (cong-∙ Carrier (uaGroup f) (uaGroup g)) ⟩
cong Carrier (uaGroup f ∙ uaGroup g) ∎) where
open GroupEquiv
|
{
"alphanum_fraction": 0.6176232002,
"avg_line_length": 41.7881355932,
"ext": "agda",
"hexsha": "9b575da4fe78f41c8221dd59dad84374a55f0393",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "RobertHarper/cubical",
"max_forks_repo_path": "Cubical/Structures/Group/MorphismProperties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"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": "RobertHarper/cubical",
"max_issues_repo_path": "Cubical/Structures/Group/MorphismProperties.agda",
"max_line_length": 143,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "RobertHarper/cubical",
"max_stars_repo_path": "Cubical/Structures/Group/MorphismProperties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3870,
"size": 9862
}
|
open import OutsideIn.Prelude
open import OutsideIn.X
module OutsideIn.Inference.Prenexer(x : X) where
import OutsideIn.Constraints as C
import OutsideIn.Expressions as E
open E(x)
open C(x)
open X(x)
private module PlusN-m n = Monad (PlusN-is-monad {n})
module PlusN-f n = Functor (Monad.is-functor (PlusN-is-monad {n}))
module Constraint-f {s} = Functor (constraint-is-functor {s})
module QC-f = Functor (qconstraint-is-functor)
data _prenex:_,_ {n : Set} : Constraint n Extended → (m : ℕ) → Constraint (n ⨁ m) Flat → Set where
PN-QC : ∀ {x} → QC x prenex: 0 , QC x
PN-∧ : ∀ {a b}{na nb}{a′}{b′} → a prenex: na , a′ → b prenex: nb , b′
→ (a ∧′ b) prenex: (na + nb) ,
(Constraint-f.map ((subst id (sym (PlusN-collect {n}{na}{nb}))) ∘ PlusN-m.unit nb) a′
∧′ Constraint-f.map ((subst id (sym (PlusN-collect {n}{na}{nb}))) ∘ PlusN-f.map nb (PlusN-m.unit na)) b′)
PN-Imp : ∀ {q}{c}{m}{c′}
→ c prenex: m , c′
→ Imp′ q c prenex: 0 , Imp (∃ m · q ⊃ c′)
PN-Ext : ∀ {x}{n}{x′} → x prenex: n , x′ → (Ⅎ_ x) prenex: suc n , x′
prenex : ∀ {n} → (C : Constraint n Extended) → ∃ (λ m → ∃ (λ C′ → C prenex: m , C′))
prenex (QC x) = _ , _ , PN-QC
prenex {n} (a ∧′ b) with prenex a | prenex b
... | na , a′ , p₁ | nb , b′ , p₂ = _ , _ , PN-∧ p₁ p₂
prenex {n} (Imp′ q c) with prenex c
... | m , c′ , p = _ , _ , PN-Imp p
prenex (Ⅎ_ x) with prenex x
... | n , x′ , p = _ , _ , PN-Ext p
|
{
"alphanum_fraction": 0.4975124378,
"avg_line_length": 47.2941176471,
"ext": "agda",
"hexsha": "15bb897fd8ce04b6e0af50137888a6a51b1f2a3d",
"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": "fc1fc1bba2af95806d9075296f9ed1074afa4c24",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "liamoc/outside-in",
"max_forks_repo_path": "OutsideIn/Inference/Prenexer.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fc1fc1bba2af95806d9075296f9ed1074afa4c24",
"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": "liamoc/outside-in",
"max_issues_repo_path": "OutsideIn/Inference/Prenexer.agda",
"max_line_length": 151,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "fc1fc1bba2af95806d9075296f9ed1074afa4c24",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "liamoc/outside-in",
"max_stars_repo_path": "OutsideIn/Inference/Prenexer.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-19T14:30:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-14T05:22:15.000Z",
"num_tokens": 598,
"size": 1608
}
|
module Class.Monad.Except where
open import Class.Monad
open import Class.Monoid
open import Data.Maybe
open import Level
private
variable
a : Level
A : Set a
record MonadExcept (M : Set a → Set a) {{_ : Monad M}} (E : Set a) : Set (suc a) where
field
throwError : E → M A
catchError : M A → (E → M A) → M A
appendIfError : {{_ : Monoid E}} → M A → E → M A
appendIfError x s = catchError x λ e → throwError (e + s)
maybeToError : Maybe A → E → M A
maybeToError (just x) e = return x
maybeToError nothing e = throwError e
tryElse : M A → M A → M A
tryElse x y = catchError x λ _ → y
open MonadExcept {{...}} public
|
{
"alphanum_fraction": 0.6305343511,
"avg_line_length": 22.5862068966,
"ext": "agda",
"hexsha": "c420d557ded8b5a7f5f7348ea633977a7ce8b11b",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z",
"max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "WhatisRT/meta-cedille",
"max_forks_repo_path": "stdlib-exts/Class/Monad/Except.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "WhatisRT/meta-cedille",
"max_issues_repo_path": "stdlib-exts/Class/Monad/Except.agda",
"max_line_length": 86,
"max_stars_count": 35,
"max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "WhatisRT/meta-cedille",
"max_stars_repo_path": "stdlib-exts/Class/Monad/Except.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z",
"num_tokens": 212,
"size": 655
}
|
-- Andreas, 2016-10-11, AIM XXIV, issue #2250
{-# OPTIONS --injective-type-constructors #-}
open import Common.Prelude
open import Common.Equality
abstract
f : Bool → Bool
f x = true
same : f true ≡ f false
same = refl
-- f should not be treated as injective here,
-- even though f true and f false do not reduce.
not-same : f true ≡ f false → ⊥
not-same () -- should be yellow
absurd : ⊥
absurd = not-same same
|
{
"alphanum_fraction": 0.6721311475,
"avg_line_length": 18.5652173913,
"ext": "agda",
"hexsha": "107eb0dd06a5b414c239cdf5538780011e1db0ce",
"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/Issue2250.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/Issue2250.agda",
"max_line_length": 48,
"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/Issue2250.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": 132,
"size": 427
}
|
open import Prelude renaming (_++_ to _++-List_)
open import Data.Maybe using (Maybe; just; nothing)
open import Data.Nat using (ℕ; suc; zero; _+_; _≤_; z≤n; s≤s; _≤?_) renaming (decTotalOrder to decTotalOrder-ℕ)
open import Data.Nat.Properties as ℕ-Props
open import Data.Nat.Properties.Simple using (+-suc; +-comm)
open import Data.Fin using (Fin; toℕ; fromℕ≤) renaming (inject+ to finject; raise to fraise; zero to fzero; suc to fsuc)
open import Relation.Binary.PropositionalEquality as P using (_≡_; refl; cong; sym)
open import Algebra using (module CommutativeSemiring; module DistributiveLattice)
open import Relation.Binary using (module DecTotalOrder)
open import RW.Language.RTerm
open import RW.Language.RTermUtils using (typeArity; typeResult)
-- Utility Module to handle (RTerm (Fin n)), or,
-- finite-scope terms.
--
-- Adapted from "Auto In Agda", by Pepijn Kokke and Wouter Swierstra.
-- https://github.com/pepijnkokke/AutoInAgda
--
module RW.Language.FinTerm where
-----------------------------------------
-- Unification/Instantiation
-- by Structural Recursion
--
-- We have to bypass some problems with the termination checker;
-- The trick is to represent variables using a finite datatype,
-- this way we can prove that the index of the variables to be
-- replaced decreases.
--
-- To work with FinTerms, as we'll call them:
FinTerm : ℕ → Set
FinTerm = RTerm ∘ Fin
-- We're going to need a lot of machinery to inject and raise
-- FinTerms in loads of different contexts.
--
-- The beginning of this module is reserved for that boilerplate.
--
--------------------------------------------
-- Fin Boilerplate
record Inject (T : ℕ → Set) : Set where
constructor inj
field
inject : ∀ {m} n → T m → T (m + n)
inject≤ : ∀ {m n} → m ≤ n → T m → T n
inject≤ {m} {n} p t = P.subst T (sym (Δ-correct p)) (inject (Δ p) t)
open Inject {{...}} using (inject; inject≤)
record Raise (T : ℕ → Set) : Set where
constructor rai
field
raise : ∀ {m} n → T m → T (n + m)
raise≤ : ∀ {m n} → m ≤ n → T m → T n
raise≤ {m} {n} p t = P.subst T (sym (P.trans (Δ-correct p) (+-comm m (Δ p)))) (raise (Δ p) t)
open Raise {{...}} using (raise; raise≤)
instance
InjectFin : Inject Fin
InjectFin = inj finject
RaiseFin : Raise Fin
RaiseFin = rai fraise
InjectRTerm : Inject FinTerm
InjectRTerm = inj (λ n → replace-A (ovar ∘ inject n))
RaiseRTerm : Raise FinTerm
RaiseRTerm = rai (λ n → replace-A (ovar ∘ raise n))
InjectRTerms : Inject (List ∘ FinTerm)
InjectRTerms = inj (λ n → map (inject n))
RaiseRTerms : Raise (List ∘ FinTerm)
RaiseRTerms = rai (λ n → map (raise n))
open DistributiveLattice ℕ-Props.distributiveLattice
using (_∧_; ∧-comm) public
open DecTotalOrder decTotalOrder-ℕ
using (total) public
private
supremumLemma : ∀{m n} → m ≤ n → m ∧ n ≡ n
supremumLemma z≤n = refl
supremumLemma (s≤s p) = cong suc (supremumLemma p)
-- Match indexes of injectable types.
match : ∀{m n} {I J} ⦃ i : Inject I ⦄ ⦃ j : Inject J ⦄
→ I m → J n → I (m ∧ n) × J (m ∧ n)
match {m} {n} i j with total m n
...| i1 m≤n rewrite supremumLemma m≤n = inject≤ m≤n i , j
...| i2 n≤m rewrite ∧-comm m n
| supremumLemma n≤m = i , inject≤ n≤m j
-- Conversion of regular terms to finite terms.
mutual
R2FinTerm : RTerm ℕ → ∃ FinTerm
R2FinTerm (ovar x) = suc x , ovar (fromℕ x)
R2FinTerm (ivar n) = 0 , ivar n
R2FinTerm (rlit l) = 0 , rlit l
R2FinTerm (rlam t) with R2FinTerm t
...| (n , t') = n , rlam t'
R2FinTerm (rapp n ts) with R2FinTerm* ts
...| (k , l) = k , rapp n l
R2FinTerm* : List (RTerm ℕ) → ∃ (List ∘ FinTerm)
R2FinTerm* [] = 0 , []
R2FinTerm* (x ∷ xs) with R2FinTerm x | R2FinTerm* xs
...| kx , x' | kxs , xs' with match x' xs'
...| rx , rxs = kx ∧ kxs , rx ∷ rxs
Fin2RTerm : ∀{n} → FinTerm n → RTerm ℕ
Fin2RTerm = replace-A (ovar ∘ toℕ)
R2FinType : RTerm ℕ → ∃ FinTerm
R2FinType t with typeArity t
...| ar = ar , replace-A fix-ovars t
where
fix-ovars : ℕ → FinTerm ar
fix-ovars fn with suc fn ≤? ar
...| yes prf = ovar (fromℕ≤ prf)
...| no _ = ivar fn
Fin2RTerm⊥ : FinTerm zero → RTerm ⊥
Fin2RTerm⊥ = replace-A (λ ())
|
{
"alphanum_fraction": 0.6078071183,
"avg_line_length": 32.9924242424,
"ext": "agda",
"hexsha": "f54b64fa4255f7c1e9f54f6ce5d0f565956a68ab",
"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": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "VictorCMiraldo/agda-rw",
"max_forks_repo_path": "RW/Language/FinTerm.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_issues_repo_issues_event_max_datetime": "2015-05-28T14:48:03.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-06T15:03:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "VictorCMiraldo/agda-rw",
"max_issues_repo_path": "RW/Language/FinTerm.agda",
"max_line_length": 120,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "VictorCMiraldo/agda-rw",
"max_stars_repo_path": "RW/Language/FinTerm.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-24T17:38:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-02-09T15:43:38.000Z",
"num_tokens": 1501,
"size": 4355
}
|
{-# OPTIONS --without-K #-}
open import M-types.Base.Core
open import M-types.Base.Sum
open import M-types.Base.Prod
open import M-types.Base.Eq
open import M-types.Base.Equi
open import M-types.Base.Axiom
module M-types.Base.Rel where
SpanRel : Ty ℓ → Ty (ℓ-suc ℓ)
SpanRel {ℓ} X = ∑[ ty ∈ Ty ℓ ] (ty → X) × (ty → X)
ρ₀ : {X : Ty ℓ₀} {Y Z : X → Ty ℓ₁} →
∏[ s ∈ ∑[ x ∈ X ] (Y x × Z x) ] Y (pr₀ s)
ρ₀ = pr₀ ∘ pr₁
ρ₁ : {X : Ty ℓ₀} {Y Z : X → Ty ℓ₁} →
∏[ s ∈ ∑[ x ∈ X ] (Y x × Z x) ] Z (pr₀ s)
ρ₁ = pr₁ ∘ pr₁
SpanRel-syntax : {X : Ty ℓ} →
∏[ ∼ ∈ SpanRel X ] ∏[ x₀ ∈ X ] ∏[ x₁ ∈ X ] Ty ℓ
SpanRel-syntax ∼ x₀ x₁ = ∑[ s ∈ (ty ∼) ] ((ρ₀ ∼ s ≡ x₀) × (ρ₁ ∼ s ≡ x₁))
syntax SpanRel-syntax ∼ x₀ x₁ = x₀ ⟨ ∼ ⟩ x₁
≡-spanRel : {X : Ty ℓ} →
SpanRel X
≡-spanRel {_} {X} = (X , id , id)
SpanRelMor : {X : Ty ℓ} →
SpanRel X → SpanRel X → Ty ℓ
SpanRelMor {_} {X} ∼ ≈ =
∑[ fun ∈ (ty ∼ → ty ≈) ]
(ρ₀ ≈ ∘ fun ≡ ρ₀ ∼) × (ρ₁ ≈ ∘ fun ≡ ρ₁ ∼)
com₀ : {X : Ty ℓ₀} {Y Z : X → Ty ℓ₁} →
∏[ s ∈ ∑[ x ∈ X ] (Y x × Z x) ] Y (pr₀ s)
com₀ = pr₀ ∘ pr₁
com₁ : {X : Ty ℓ₀} {Y Z : X → Ty ℓ₁} →
∏[ s ∈ ∑[ x ∈ X ] (Y x × Z x) ] Z (pr₀ s)
com₁ = pr₁ ∘ pr₁
id-spanRel : {X : Ty ℓ} {∼ : SpanRel X} →
SpanRelMor ∼ ∼
id-spanRel {_} {X} {∼} = (id , refl , refl)
infixr 9 _∘-spanRel_
_∘-spanRel_ : {X : Ty ℓ} {∼₀ ∼₁ ∼₂ : SpanRel X} →
SpanRelMor ∼₁ ∼₂ → SpanRelMor ∼₀ ∼₁ → SpanRelMor ∼₀ ∼₂
g ∘-spanRel f =
(
fun g ∘ fun f ,
ap (λ k → k ∘ fun f) (com₀ g) · com₀ f ,
ap (λ k → k ∘ fun f) (com₁ g) · com₁ f
)
DepRel : Ty ℓ → Ty (ℓ-suc ℓ)
DepRel {ℓ} X = X → X → Ty ℓ
DepRel-syntax : {X : Ty ℓ} →
∏[ ∼ ∈ DepRel X ] ∏[ x₀ ∈ X ] ∏[ x₁ ∈ X ] Ty ℓ
DepRel-syntax ∼ x₀ x₁ = ∼ x₀ x₁
syntax DepRel-syntax ∼ x₀ x₁ = x₀ [ ∼ ] x₁
≡-depRel : {X : Ty ℓ} →
DepRel X
≡-depRel = λ x₀ → λ x₁ → x₀ ≡ x₁
DepRelMor : {X : Ty ℓ} →
DepRel X → DepRel X → Ty ℓ
DepRelMor {_} {X} ∼ ≈ =
∏[ x₀ ∈ X ] ∏[ x₁ ∈ X ]
(x₀ [ ∼ ] x₁ → x₀ [ ≈ ] x₁)
id-depRel : {X : Ty ℓ} {∼ : DepRel X} →
DepRelMor ∼ ∼
id-depRel {_} {X} {∼} = λ x₀ → λ x₁ → id
infixr 9 _∘-depRel_
_∘-depRel_ : {X : Ty ℓ} {∼₀ ∼₁ ∼₂ : DepRel X} →
DepRelMor ∼₁ ∼₂ → DepRelMor ∼₀ ∼₁ → DepRelMor ∼₀ ∼₂
g ∘-depRel f = λ x₀ → λ x₁ → g x₀ x₁ ∘ f x₀ x₁
SpanRel→DepRel : {X : Ty ℓ} →
SpanRel X → DepRel X
SpanRel→DepRel {_} {X} ∼ = λ x₀ → λ x₁ → x₀ ⟨ ∼ ⟩ x₁
DepRel→SpanRel : {X : Ty ℓ} →
DepRel X → SpanRel X
DepRel→SpanRel {_} {X} ∼ =
(
(∑[ x₀ ∈ X ] ∑[ x₁ ∈ X ] x₀ [ ∼ ] x₁) ,
pr₀ ,
pr₀ ∘ pr₁
)
SpanRel→DepRel-pres : {X : Ty ℓ} →
∏[ ∼ ∈ SpanRel X ] ∏[ x₀ ∈ X ] ∏[ x₁ ∈ X ]
(x₀ [ SpanRel→DepRel ∼ ] x₁) ≡ (x₀ ⟨ ∼ ⟩ x₁)
SpanRel→DepRel-pres ∼ x₀ x₁ = refl
DepRel→SpanRel-pres : {X : Ty ℓ} →
∏[ ∼ ∈ DepRel X ] ∏[ x₀ ∈ X ] ∏[ x₁ ∈ X ]
(x₀ ⟨ DepRel→SpanRel ∼ ⟩ x₁) ≃ (x₀ [ ∼ ] x₁)
DepRel→SpanRel-pres ∼ x₀ x₁ =
(
(λ ((y₀ , y₁ , s) , p₀ , p₁) →
tra (λ x → x [ ∼ ] x₁) p₀ (tra (λ y → y₀ [ ∼ ] y) p₁ s)
) ,
Qinv→IsEqui (
(λ s → ((x₀ , x₁ , s) , refl , refl)) ,
(λ {((x₀ , x₁ , s) , refl , refl) → refl}) ,
(λ s → refl)
)
)
SpanRel→SpanRel-mor : {X : Ty ℓ} →
∏[ ∼ ∈ SpanRel X ] SpanRelMor ∼ (DepRel→SpanRel (SpanRel→DepRel ∼))
SpanRel→SpanRel-mor ∼ =
(
(λ s → (ρ₀ ∼ s , ρ₁ ∼ s , (s , refl , refl))) ,
refl ,
refl
)
DepRel→DepRel-mor : {X : Ty ℓ} →
∏[ ∼ ∈ DepRel X ] DepRelMor ∼ (SpanRel→DepRel (DepRel→SpanRel ∼))
DepRel→DepRel-mor ∼ = λ x₀ → λ x₁ → λ s → ((x₀ , x₁ , s) , refl , refl)
≡-SpanRel→DepRel-mor : {X : Ty ℓ} →
DepRelMor {ℓ} {X} (SpanRel→DepRel ≡-spanRel) ≡-depRel
≡-SpanRel→DepRel-mor = λ x₀ → λ x₁ → λ(s , p₀ , p₁) → p₀ ⁻¹ · p₁
≡-DepRel→SpanRel-mor : {X : Ty ℓ} →
SpanRelMor {ℓ} {X} (DepRel→SpanRel ≡-depRel) ≡-spanRel
≡-DepRel→SpanRel-mor =
(
(λ (x₀ , x₁ , p) → x₀) ,
refl ,
funext (λ (x₀ , x₁ , p) → p)
)
SpanRelMor→DepRelMor : {X : Ty ℓ} {∼ ≈ : SpanRel X} →
SpanRelMor ∼ ≈ → DepRelMor (SpanRel→DepRel ∼) (SpanRel→DepRel ≈)
SpanRelMor→DepRelMor (fun , refl , refl) x₀ x₁ (s , refl , refl) =
(
fun s ,
refl ,
refl
)
DepRelMor→SpanRelMor : {X : Ty ℓ} {∼ ≈ : DepRel X} →
DepRelMor ∼ ≈ → SpanRelMor (DepRel→SpanRel ∼) (DepRel→SpanRel ≈)
DepRelMor→SpanRelMor f =
(
(λ (x₀ , x₁ , s) → (x₀ , x₁ , f x₀ x₁ s)) ,
refl {_} {_} {pr₀} ,
refl
)
|
{
"alphanum_fraction": 0.4202224469,
"avg_line_length": 28.75,
"ext": "agda",
"hexsha": "565ea93906bd3093a6151ffec669d74125dd37bd",
"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": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DDOtten/M-types",
"max_forks_repo_path": "Base/Rel.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"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": "DDOtten/M-types",
"max_issues_repo_path": "Base/Rel.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DDOtten/M-types",
"max_stars_repo_path": "Base/Rel.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2225,
"size": 4945
}
|
module Data.Tree.Base where
open import Class.Monoid
open import Class.Show
open import Data.List using (List; sum; map; replicate; intersperse)
open import Data.Nat using (ℕ; suc)
open import Data.Nat.Instance
open import Data.String using (String)
open import Data.String.Instance
open import Function
data Tree (A : Set) : Set where
Node : A -> List (Tree A) -> Tree A
{-# TERMINATING #-}
lengthTree : ∀ {A} -> Tree A -> ℕ
lengthTree (Node x x₁) = 1 + sum (map lengthTree x₁)
-- show tree that is compatible with org mode
{-# TERMINATING #-}
showTreeOrg : ∀ {A} {{_ : Show A}} -> Tree A -> String
showTreeOrg = helper 1
where
helper : ∀ {A} {{_ : Show A}} -> ℕ -> Tree A -> String
helper level (Node x x₁) =
(concat $ replicate level "*") + " " + show x + "\n" +
(concat $ intersperse "\n" $ map (helper (suc level)) x₁) + "\n"
|
{
"alphanum_fraction": 0.6426076834,
"avg_line_length": 30.6785714286,
"ext": "agda",
"hexsha": "a23ea398237e887cf4e0037c7b1a6c3cebeb342d",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z",
"max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "WhatisRT/meta-cedille",
"max_forks_repo_path": "stdlib-exts/Data/Tree/Base.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "WhatisRT/meta-cedille",
"max_issues_repo_path": "stdlib-exts/Data/Tree/Base.agda",
"max_line_length": 70,
"max_stars_count": 35,
"max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "WhatisRT/meta-cedille",
"max_stars_repo_path": "stdlib-exts/Data/Tree/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z",
"num_tokens": 253,
"size": 859
}
|
{-# OPTIONS --without-K --safe #-}
module Dodo.Binary where
open import Dodo.Binary.Acyclic public
open import Dodo.Binary.Composition public
open import Dodo.Binary.Cycle public
open import Dodo.Binary.Dec public
open import Dodo.Binary.Disjoint public
open import Dodo.Binary.Domain public
open import Dodo.Binary.Empty public
open import Dodo.Binary.Equality public
open import Dodo.Binary.Filter public
open import Dodo.Binary.Flip public
open import Dodo.Binary.Functional public
open import Dodo.Binary.Identity public
open import Dodo.Binary.Immediate public
open import Dodo.Binary.Intersection public
open import Dodo.Binary.Irreflexive public
open import Dodo.Binary.Maximal public
open import Dodo.Binary.Precedes public
open import Dodo.Binary.Product public
open import Dodo.Binary.SplittableOrder public
open import Dodo.Binary.Subtraction public
open import Dodo.Binary.Transitive public
open import Dodo.Binary.Trichotomous public
open import Dodo.Binary.Union public
open ⊆₂-Reasoning public
open ⇔₂-Reasoning public
|
{
"alphanum_fraction": 0.8351012536,
"avg_line_length": 33.4516129032,
"ext": "agda",
"hexsha": "504ed316163ce253fc1e91e88265308a97e7d8b0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Binary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Binary.agda",
"max_line_length": 46,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Binary.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 242,
"size": 1037
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.