Search is not available for this dataset
text
string | meta
dict |
---|---|
------------------------------------------------------------------------
-- The syntax of a toy programming language that only supports
-- allocation and deallocation of memory
------------------------------------------------------------------------
module Only-allocation where
open import Equality.Propositional
open import Prelude
open import Prelude.Size
open import Colist equality-with-J
------------------------------------------------------------------------
-- Programs
-- Statements.
data Stmt : Type where
alloc dealloc : Stmt
-- Programs are potentially infinite sequences of statements.
Program : Size → Type
Program i = Colist Stmt i
------------------------------------------------------------------------
-- Some examples
-- A program that runs in bounded space.
bounded : ∀ {i} → Program i
bounded = alloc ∷′ dealloc ∷ λ { .force → bounded }
-- Another program that runs in bounded space.
bounded₂ : ∀ {i} → Program i
bounded₂ =
alloc ∷′ alloc ∷′
dealloc ∷′ dealloc ∷ λ { .force → bounded₂ }
-- A program that does not run in bounded space.
unbounded : ∀ {i} → Program i
unbounded = alloc ∷ λ { .force → unbounded }
|
{
"alphanum_fraction": 0.530224525,
"avg_line_length": 25.1739130435,
"ext": "agda",
"hexsha": "515eaa0614650ab8612a53ae01304d8b185840cf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/definitional-interpreters",
"max_forks_repo_path": "src/Only-allocation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/definitional-interpreters",
"max_issues_repo_path": "src/Only-allocation.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/definitional-interpreters",
"max_stars_repo_path": "src/Only-allocation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 225,
"size": 1158
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Adjoint.Instance.PosetCore where
-- The adjunction between the "forgetful" functor from Posets to
-- Setoids and the core functor for posets.
open import Level using (_⊔_)
import Function
open import Function.Equality using (Π; _⟶_)
open import Relation.Binary using (Setoid; Poset)
open import Relation.Binary.OrderMorphism using (_⇒-Poset_) renaming (_∘_ to _∙_)
open import Categories.Adjoint using (_⊣_)
import Categories.Adjoint.Instance.0-Truncation as Setd
import Categories.Adjoint.Instance.01-Truncation as Pos
open import Categories.Category using (Category)
open import Categories.Category.Construction.Thin
open import Categories.Category.Instance.Posets using (fun-resp-≈; Posets)
open import Categories.Category.Instance.Setoids using (Setoids)
open import Categories.Functor.Instance.Core using () renaming (Core to CatCore)
import Categories.Functor.Instance.Core as Cat
open import Categories.Functor using (Functor; _∘F_; id)
import Categories.Morphism as Morphism
open import Categories.Morphism.IsoEquiv using (⌞_⌟)
open import Categories.NaturalTransformation using (ntHelper)
open import Categories.NaturalTransformation.NaturalIsomorphism
using (_≃_; niHelper)
open Π
open _⇒-Poset_
-- The "forgetful" functor from Setoids to Posets (forgetting symmetry).
Forgetful : ∀ {c ℓ} → Functor (Setoids c ℓ) (Posets c ℓ ℓ)
Forgetful = record
{ F₀ = Forgetful₀
; F₁ = λ f → record { fun = _⟨$⟩_ f ; monotone = cong f }
; identity = λ {S} → refl S
; homomorphism = λ {_ _ S} → refl S
; F-resp-≈ = λ {S _} f≗g → f≗g (refl S)
}
where
Forgetful₀ : ∀ {c ℓ} → Setoid c ℓ → Poset c ℓ ℓ
Forgetful₀ S = record
{ _≈_ = _≈_
; _≤_ = _≈_
; isPartialOrder = record
{ isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = Function.id
; trans = trans
}
; antisym = Function.const
}
}
where open Setoid S
open Setoid
-- The "core" functor from Posets to Setoids.
--
-- This functor simply forgets the _≤_ relation, mapping a Poset to
-- the Setoid over which it is defined. This Setoid is the "core" of
-- the Poset in the sense that the "equality" _≈_ associated with the
-- Poset is really an equivalence, and antisymmetry ensures that this
-- equivalence is equivalent to the symmetric core of _≤_.
Core : ∀ {c ℓ₁ ℓ₂} → Functor (Posets c ℓ₁ ℓ₂) (Setoids c ℓ₁)
Core = record
{ F₀ = λ A → record { isEquivalence = isEquivalence A }
; F₁ = λ f → record { _⟨$⟩_ = fun f ; cong = fun-resp-≈ f }
; identity = Function.id
; homomorphism = λ {_ _ _ f g} → fun-resp-≈ (g ∙ f)
; F-resp-≈ = λ {_ B} {f _} f≗g x≈y → Eq.trans B (fun-resp-≈ f x≈y) f≗g
}
where open Poset
-- Core is right-adjoint to the forgetful functor
CoreAdj : ∀ {o ℓ} → Forgetful ⊣ Core {o} {ℓ} {ℓ}
CoreAdj = record
{ unit = ntHelper record { η = unit ; commute = cong }
; counit = ntHelper record { η = counit ; commute = λ {_ B} _ → Eq.refl B }
; zig = λ {S} → Setoid.refl S
; zag = Function.id
}
where
open Poset
open Functor Core using () renaming (F₀ to Core₀; F₁ to Core₁)
open Functor Forgetful using () renaming (F₀ to U₀ ; F₁ to U₁)
unit : ∀ S → S ⟶ Core₀ (U₀ S)
unit S = record { _⟨$⟩_ = Function.id ; cong = Function.id }
counit : ∀ A → U₀ (Core₀ A) ⇒-Poset A
counit C = record { fun = Function.id ; monotone = reflexive C }
-- The core functor commutes with inclusion, i.e. the core of a thin
-- category is the 0-Groupoid generated by the associated equivalence.
--
-- Note that the core functor does not commute with truncation,
-- because the latter forgets too much (there are many more isos in
-- the (0,1)-truncated category).
Core-commutes : ∀ {c ℓ} e → Setd.Inclusion e ∘F Core ≃
Cat.Core ∘F Pos.Inclusion {c} {ℓ ⊔ e} {ℓ} e
Core-commutes e = niHelper record
{ η = λ A → record { F₀ = Function.id ; F₁ = EqIsIso.≈⇒≅ e A }
; η⁻¹ = λ A → record { F₀ = Function.id ; F₁ = EqIsIso.≅⇒≈ e A }
; commute = λ {A B} f →
let open Morphism (Thin e B)
in niHelper record { η = λ _ → ≅.refl ; η⁻¹ = λ _ → ≅.refl }
; iso = λ A →
let open Poset A
open Morphism (Thin e A)
in record
{ isoˡ = niHelper record { η = λ _ → Eq.refl ; η⁻¹ = λ _ → Eq.refl }
; isoʳ = niHelper record { η = λ _ → ≅.refl ; η⁻¹ = λ _ → ≅.refl }
}
}
|
{
"alphanum_fraction": 0.6300679378,
"avg_line_length": 37.4016393443,
"ext": "agda",
"hexsha": "dc2195168e2cf1aa46609141717a6b6e09817bc1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Adjoint/Instance/PosetCore.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Adjoint/Instance/PosetCore.agda",
"max_line_length": 81,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Adjoint/Instance/PosetCore.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": 1483,
"size": 4563
}
|
--#include "prelude.agda"
--#include "PropPrelude.agda"
proof_reverse_nil :: PropPrelude.prop_reverse_nil
= ref@_ (reverse Unit Nil@_)
proof_append_nil_1 :: PropPrelude.prop_append_nil_1
= ?
proof_append_nil_2 :: PropPrelude.prop_append_nil_2
= \ (xs::List Unit) -> ref@_ (append Unit Nil@_ xs)
|
{
"alphanum_fraction": 0.7401315789,
"avg_line_length": 25.3333333333,
"ext": "agda",
"hexsha": "9e74606339a31c6d41af83445d186a028bd101f4",
"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": "4172bef9f4eede7e45dc002a70bf8c6dd9a56b5c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "siddharthist/hs2agda",
"max_forks_repo_path": "examples/queue/PropPrelude.proof.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "4172bef9f4eede7e45dc002a70bf8c6dd9a56b5c",
"max_issues_repo_issues_event_max_datetime": "2016-10-25T17:50:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-25T02:27:55.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "siddharthist/CoverTranslator",
"max_issues_repo_path": "examples/queue/PropPrelude.proof.agda",
"max_line_length": 53,
"max_stars_count": 17,
"max_stars_repo_head_hexsha": "4172bef9f4eede7e45dc002a70bf8c6dd9a56b5c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "siddharthist/hs2agda",
"max_stars_repo_path": "examples/queue/PropPrelude.proof.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-25T19:54:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-25T10:07:49.000Z",
"num_tokens": 96,
"size": 304
}
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.Adjunction.CompositionLaws where
open import Level
open import Relation.Binary using (Rel; IsEquivalence)
open import Data.Sum
open import Data.Product
open import Function using (flip)
open import Categories.Category
open import Categories.Functor hiding (equiv; assoc; identityˡ; identityʳ; ∘-resp-≡) renaming (id to idF; _≡_ to _≡F_; _∘_ to _∘F_)
open import Categories.NaturalTransformation hiding (equiv; setoid) renaming (id to idT; _≡_ to _≡T_)
open import Categories.Monad
open import Categories.Support.Equivalence
open import Categories.Adjunction
open import Categories.Adjunction.Composition
.assoc : ∀ {o₀ ℓ₀ e₀ o₁ ℓ₁ e₁ o₂ ℓ₂ e₂ o₃ ℓ₃ e₃}
{C₀ : Category o₀ ℓ₀ e₀} {C₁ : Category o₁ ℓ₁ e₁} {C₂ : Category o₂ ℓ₂ e₂} {C₃ : Category o₃ ℓ₃ e₃}
{F : Functor C₀ C₁} {G : Functor C₁ C₂} {H : Functor C₂ C₃}
{F′ : Functor C₁ C₀} {G′ : Functor C₂ C₁} {H′ : Functor C₃ C₂}
{T : F ⊣ F′} {U : G ⊣ G′} {V : H ⊣ H′}
→ (V ∘ U) ∘ T ≡ V ∘ (U ∘ T)
assoc {C₀ = C₀} {C₁} {C₂} {C₃} {F} {G} {H} {F′} {G′} {H′} {T} {U} {V} = (λ {x} → pf₀ {x}) , λ {x} → pf₁ {x}
where
module C₀ = Category C₀
module C₁ = Category C₁
module C₂ = Category C₂
module C₃ = Category C₃
module F = Functor F
module G = Functor G renaming (F₀ to G₀; F₁ to G₁; F-resp-≡ to G-resp-≡)
module H = Functor H renaming (F₀ to H₀; F₁ to H₁; F-resp-≡ to H-resp-≡)
module F′ = Functor F′ renaming (F₀ to F′₀; F₁ to F′₁; F-resp-≡ to F′-resp-≡)
module G′ = Functor G′ renaming (F₀ to G′₀; F₁ to G′₁; F-resp-≡ to G′-resp-≡)
module H′ = Functor H′ renaming (F₀ to H′₀; F₁ to H′₁; F-resp-≡ to H′-resp-≡)
module T = Adjunction T renaming (unit to Tη′; counit to Tε′)
module U = Adjunction U renaming (unit to Uη′; counit to Uε′)
module V = Adjunction V renaming (unit to Vη′; counit to Vε′)
module Tη = NaturalTransformation (Adjunction.unit T)
module Tε = NaturalTransformation (Adjunction.counit T)
module Uη = NaturalTransformation (Adjunction.unit U)
module Uε = NaturalTransformation (Adjunction.counit U)
module Vη = NaturalTransformation (Adjunction.unit V)
module Vε = NaturalTransformation (Adjunction.counit V)
pf₀ : {x : C₀.Obj} → F′.F′₁ (G′.G′₁ (Vη.η (G.G₀ (F.F₀ x))) C₁.∘ Uη.η (F.F₀ x)) C₀.∘
Tη.η x
C₀.≡
F′.F′₁ (G′.G′₁ (Vη.η (G.G₀ (F.F₀ x)))) C₀.∘
F′.F′₁ (Uη.η (F.F₀ x)) C₀.∘ Tη.η x
pf₀ {x} = begin
F′.F′₁ (G′.G′₁ (Vη.η (G.G₀ (F.F₀ x))) C₁.∘ Uη.η (F.F₀ x)) C₀.∘
Tη.η x
↓⟨ C₀.∘-resp-≡ˡ F′.homomorphism ⟩
C₀ [ F′.F′₁ (G′.G′₁ (Vη.η (G.G₀ (F.F₀ x)))) ∘
F′.F′₁ (Uη.η (F.F₀ x)) ]
C₀.∘ Tη.η x
↓⟨ C₀.assoc ⟩
F′.F′₁ (G′.G′₁ (Vη.η (G.G₀ (F.F₀ x)))) C₀.∘
F′.F′₁ (Uη.η (F.F₀ x)) C₀.∘ Tη.η x
∎
where open C₀.HomReasoning
pf₁ : {x : C₃.Obj} → (Vε.η x C₃.∘ H.H₁ (Uε.η (H′.H′₀ x))) C₃.∘
H.H₁ (G.G₁ (Tε.η (G′.G′₀ (H′.H′₀ x))))
C₃.≡
Vε.η x C₃.∘
H.H₁ (Uε.η (H′.H′₀ x) C₂.∘ G.G₁ (Tε.η (G′.G′₀ (H′.H′₀ x))))
pf₁ {x} = begin
(Vε.η x C₃.∘ H.H₁ (Uε.η (H′.H′₀ x))) C₃.∘
H.H₁ (G.G₁ (Tε.η (G′.G′₀ (H′.H′₀ x))))
↓⟨ C₃.assoc ⟩
Vε.η x C₃.∘
H.H₁ (Uε.η (H′.H′₀ x)) C₃.∘ H.H₁ (G.G₁ (Tε.η (G′.G′₀ (H′.H′₀ x))))
↑⟨ C₃.∘-resp-≡ʳ H.homomorphism ⟩
Vε.η x C₃.∘
H.H₁ (C₂ [ Uε.η (H′.H′₀ x) ∘ G.G₁ (Tε.η (G′.G′₀ (H′.H′₀ x))) ])
∎
where open C₃.HomReasoning
.identityˡ : ∀ {o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {F : Functor C D} {G : Functor D C} {T : F ⊣ G}
→ id ∘ T ≡ T
identityˡ {C = C} {D} {F} {G} {T} = ( (λ {x} → pf₀ {x}) , D.identityˡ )
where
module C = Category C
module D = Category D
module F = Functor F
module G = Functor G
module T = Adjunction T renaming (unit to Tη′; counit to Tε′)
module Tη = NaturalTransformation T.Tη′
module Tε = NaturalTransformation T.Tε′
pf₀ : {x : C.Obj} → G.F₁ D.id C.∘ NaturalTransformation.η Tη.op x C.≡
NaturalTransformation.η Tη.op x
pf₀ {x} = begin
G.F₁ D.id C.∘ NaturalTransformation.η Tη.op x
↓⟨ C.∘-resp-≡ˡ G.identity ⟩
C.id C.∘ NaturalTransformation.η Tη.op x
↓⟨ C.identityˡ ⟩
NaturalTransformation.η Tη.op x
∎
where open C.HomReasoning
.identityʳ : ∀ {o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {F : Functor C D} {G : Functor D C} {T : F ⊣ G}
→ T ∘ id ≡ T
identityʳ {C = C} {D} {F} {G} {T} = (λ {x} → C.identityʳ) , (λ {x} → pf₀ {x})
where
module C = Category C
module D = Category D
module F = Functor F
module G = Functor G
module T = Adjunction T renaming (unit to Tη′; counit to Tε′)
module Tη = NaturalTransformation T.Tη′
module Tε = NaturalTransformation T.Tε′
pf₀ : {x : D.Obj} → NaturalTransformation.η Tε.op x D.∘ F.F₁ C.id D.≡
NaturalTransformation.η Tε.op x
pf₀ {x} = begin
NaturalTransformation.η Tε.op x D.∘ F.F₁ C.id
↓⟨ D.∘-resp-≡ʳ F.identity ⟩
NaturalTransformation.η Tε.op x D.∘ D.id
↓⟨ D.identityʳ ⟩
NaturalTransformation.η Tε.op x
∎
where open D.HomReasoning
.∘-resp-≡ : ∀ {o₀ ℓ₀ e₀ o₁ ℓ₁ e₁ o₂ ℓ₂ e₂}
{A : Category o₀ ℓ₀ e₀} {B : Category o₁ ℓ₁ e₁} {C : Category o₂ ℓ₂ e₂}
{F : Functor B C} {G : Functor A B} {F′ : Functor C B} {G′ : Functor B A}
{T T′ : G ⊣ G′} {U U′ : F ⊣ F′}
→ T ≡ T′ → U ≡ U′ → U ∘ T ≡ U′ ∘ T′
∘-resp-≡ {A = A} {B} {C} {F} {G} {F′} {G′} {T} {T′} {U} {U′} (Tη≡T′η , Tε≡T′ε) (Uη≡U′η , Uε≡U′ε) =
(λ {x} → A.∘-resp-≡ (G′.F-resp-≡ Uη≡U′η) Tη≡T′η)
,
(λ {x} → C.∘-resp-≡ Uε≡U′ε (F.F-resp-≡ Tε≡T′ε))
where
module A = Category A
module B = Category B
module C = Category C
module F = Functor F
module G = Functor G
module F′ = Functor F′
module G′ = Functor G′
module T = Adjunction T renaming (unit to Tη′; counit to Tε′)
module U = Adjunction U renaming (unit to Uη′; counit to Uε′)
module T′ = Adjunction T′ renaming (unit to T′η′; counit to T′ε′)
module U′ = Adjunction U′ renaming (unit to U′η′; counit to U′ε′)
module Tη = NaturalTransformation (Adjunction.unit T)
module Tε = NaturalTransformation (Adjunction.counit T)
module Uη = NaturalTransformation (Adjunction.unit U)
module Uε = NaturalTransformation (Adjunction.counit U)
module T′η = NaturalTransformation (Adjunction.unit T′)
module T′ε = NaturalTransformation (Adjunction.counit T′)
module U′η = NaturalTransformation (Adjunction.unit U′)
module U′ε = NaturalTransformation (Adjunction.counit U′)
|
{
"alphanum_fraction": 0.5284894302,
"avg_line_length": 45.2088607595,
"ext": "agda",
"hexsha": "7562f82d5a2414e9703f1cff1f15ecfc61447bd0",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Adjunction/CompositionLaws.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Adjunction/CompositionLaws.agda",
"max_line_length": 131,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Adjunction/CompositionLaws.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 2867,
"size": 7143
}
|
{-# OPTIONS --without-K #-}
-- Some basic theorms about natural numbers.
module hott.types.nat.theorems where
open import hott.core
open import hott.functions
open import hott.types.nat
-- 0 is the right identity of addition.
x+0≡x : ∀(x : ℕ) → x + 0 ≡ x
x+0≡x 0 = begin 0 + 0 ≡ 0 by definition ∎
x+0≡x (succ n)
= begin succ n + 0 ≡ succ (n + 0) by definition
≡ succ n by ap succ (x+0≡x (n))
∎
-- Alternate from of 0 being right identity.
x≡x+0 : ∀(x : ℕ) → x ≡ x + 0
x≡x+0 n = x+0≡x n ⁻¹
-- This is really refl but it is better to use these when proving
-- properties about ℕ. One does not have to remember which is
-- definitional equality and which is not.
0+x≡x : ∀ (x : ℕ) → 0 + x ≡ x
0+x≡x n = begin 0 + n ≡ n by definition ∎
-- This is really refl but it is better to use these when proving
-- properties about ℕ. One does not have to remember which is
-- definitional equality and which is not.
x≡0+x : ∀ (x : ℕ) → x ≡ 0 + x
x≡0+x n = begin n ≡ 0 + n by definition ∎
-- Commutativity of addition.
x+y≡y+x : ∀ (x y : ℕ) → x + y ≡ y + x
x+y≡y+x 0 n
= begin 0 + n ≡ n by definition
≡ n + 0 by x≡x+0 (n)
∎
x+y≡y+x n 0
= begin n + 0 ≡ n by x+0≡x (n)
≡ 0 + n by definition
∎
x+y≡y+x (succ m) (succ n)
= begin succ m + succ n
≡ succ (m + succ n) by definition
≡ succ (succ n + m) by applying succ on x+y≡y+x m (succ n)
≡ succ (succ (n + m)) by definition
≡ succ (succ (m + n)) by applying succ ∘ succ on (x+y≡y+x n m)
≡ succ (succ m + n) by applying succ on definition
≡ succ (n + succ m) by applying succ on x+y≡y+x (succ m) n
≡ succ n + succ m by definition
∎
-- Associativity of +
x+[y+z]≡[x+y]+z : ∀ (x y z : ℕ) → x + (y + z) ≡ (x + y) + z
x+[y+z]≡[x+y]+z zero y z
= begin 0 + (y + z)
≡ y + z by definition
≡ (0 + y) + z by definition
∎
x+[y+z]≡[x+y]+z (succ x) y z
= begin succ x + (y + z)
≡ succ (x + (y + z)) by definition
≡ succ ((x + y) + z) by applying succ on x+[y+z]≡[x+y]+z x y z
≡ succ (x + y) + z by definition
≡ (succ x + y) + z by definition
∎
|
{
"alphanum_fraction": 0.5002139495,
"avg_line_length": 34.3676470588,
"ext": "agda",
"hexsha": "0ca782ed9a1f13c569bc58075551a95a7e8d60e4",
"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": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "piyush-kurur/hott",
"max_forks_repo_path": "agda/hott/types/nat/theorems.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"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": "piyush-kurur/hott",
"max_issues_repo_path": "agda/hott/types/nat/theorems.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "piyush-kurur/hott",
"max_stars_repo_path": "agda/hott/types/nat/theorems.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 867,
"size": 2337
}
|
{-# OPTIONS --cubical #-}
module Type.Cubical.InductivePath where
open import Functional
import Lvl
open import Type
import Type.Cubical as Cubical
open import Type.Cubical.InductiveInterval
private variable ℓ : Lvl.Level
private variable A B P : Type{ℓ}
private variable x y z : A
data Path {P : Type{ℓ}} : P → P → Type{ℓ} where
intro : (p : Interval → P) → Path(p(𝟎)) (p(𝟏))
point : (x : P) → Path x x
point x = intro(const x)
pointOn : ∀{x y : A} → Path x y → (Interval → A)
pointOn (intro p) = p
reverse : Path x y → Path y x
reverse(intro f) = intro(f ∘ flip)
spaceMap : Path A B → (A → B)
spaceMap (intro p) = transp p
{-
concat : Path x y → Path y z → Path x z
concat xy yz = {!xy yz!}
-}
module _ where
private variable X : Type{ℓ}
private variable Y : X → Type{ℓ}
{- TODO: Define an eliminator for Path and use it to prove this?
mapping : ∀{f g : (x : X) → Y(x)} → (∀{x} → Path(f(x)) (g(x))) → Path f g
mapping {X = X}{Y = Y}{f = f}{g = g} ppt = intro(i ↦ x ↦ {!pointOn(ppt{x}) i!}) where
p : (∀{x} → Path(f(x)) (g(x))) → Interval → (x : X) → Y(x)
p ppt i x with ppt{x}
... | q = {!q!}
-}
mappingPoint : ∀{f g : (x : X) → Y(x)} → Path f g → (∀{x} → Path(f(x)) (g(x)))
mappingPoint (intro pfg) {x} = intro (i ↦ pfg i x)
module _ where
private variable X X₁ X₂ Y Y₁ Y₂ : Type{ℓ}
map : (f : X → Y) → ∀{a b} → Path a b → Path (f(a)) (f(b))
map f (intro ab) = intro(f ∘ ab)
liftedSpaceMap : (S : X → Type{ℓ}) → ∀{a b} → Path a b → S(a) → S(b)
liftedSpaceMap S p = spaceMap(map S p)
|
{
"alphanum_fraction": 0.5653573728,
"avg_line_length": 26.775862069,
"ext": "agda",
"hexsha": "f412892be2ca2388dd54b2917f32d7fc60b749c5",
"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": "Type/Cubical/InductivePath.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": "Type/Cubical/InductivePath.agda",
"max_line_length": 87,
"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": "Type/Cubical/InductivePath.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": 592,
"size": 1553
}
|
------------------------------------------------------------------------
-- Some results related to strong bisimilarity for the delay monad
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude
module Bisimilarity.Delay-monad {a} {A : Type a} where
open import Delay-monad
open import Delay-monad.Bisimilarity as D using (force)
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Function-universe equality-with-J hiding (id; _∘_)
open import Labelled-transition-system
open import Labelled-transition-system.Delay-monad A
open import Bisimilarity delay-monad
import Bisimilarity.Equational-reasoning-instances
open import Equational-reasoning
------------------------------------------------------------------------
-- The direct and the indirect definitions of strong bisimilarity are
-- pointwise logically equivalent
-- An emulation of the constructor D.later.
later-cong : ∀ {i x y} →
[ i ] force x ∼′ force y → [ i ] later x ∼ later y
later-cong x∼′y =
⟨ (λ { later → _ , later , x∼′y })
, (λ { later → _ , later , x∼′y })
⟩
-- The direct definition of strong bisimilarity is contained in the
-- one obtained from the transition relation.
direct→indirect : ∀ {i x y} →
D.[ i ] x ∼ y → [ i ] x ∼ y
direct→indirect D.now = reflexive
direct→indirect (D.later p) = later-cong λ { .force →
direct→indirect (force p) }
-- The definition of strong bisimilarity obtained from the transition
-- relation is contained in the direct one.
indirect→direct : ∀ {i} x y → [ i ] x ∼ y → D.[ i ] x ∼ y
indirect→direct (now x) (now y) nx∼ny
with left-to-right nx∼ny now
... | _ , now , _ = D.now
indirect→direct (later x) (later y) lx∼ly
with left-to-right lx∼ly later
... | _ , later , x∼′y = D.later λ { .force →
indirect→direct _ _ (force x∼′y) }
indirect→direct (now x) (later y) nx∼ly
with left-to-right nx∼ly now
... | _ , () , _
indirect→direct (later x) (now y) lx∼ny
with left-to-right lx∼ny later
... | _ , () , _
-- The direct definition of strong bisimilarity is pointwise logically
-- equivalent to the one obtained from the transition relation.
--
-- TODO: Are the two definitions isomorphic?
direct⇔indirect : ∀ {i x y} → D.[ i ] x ∼ y ⇔ [ i ] x ∼ y
direct⇔indirect = record
{ to = direct→indirect
; from = indirect→direct _ _
}
|
{
"alphanum_fraction": 0.5991935484,
"avg_line_length": 31.7948717949,
"ext": "agda",
"hexsha": "3f2b17d38ea526355b8a194e120887bcfedf2988",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Bisimilarity/Delay-monad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/up-to",
"max_issues_repo_path": "src/Bisimilarity/Delay-monad.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Bisimilarity/Delay-monad.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 683,
"size": 2480
}
|
-- Andreas, 2018-04-16, inspired by issue #3032 reported by sattlerc
-- A termination issue without visible recursion.
postulate
A : Set
B : Set
t : B
mutual
data C : (b : B) → Set where
c : (x : C t) → C (foo t bar)
postulate
bar : C t
foo : (b : B) → C b → B
foo y (c x) = y
-- Should not termination check.
-- y is actually "foo t bar" here, a potentially non-terminating recursive call.
|
{
"alphanum_fraction": 0.6166666667,
"avg_line_length": 18.2608695652,
"ext": "agda",
"hexsha": "753256b265c3bcb9b42d5f108645c1382cd4de12",
"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/Issue3032-termination.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/Issue3032-termination.agda",
"max_line_length": 80,
"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/Issue3032-termination.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": 142,
"size": 420
}
|
------------------------------------------------------------------------------
-- Testing Agda internal term: @Def@
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Agda.InternalTerms.DefTerm1 where
------------------------------------------------------------------------------
postulate
D : Set
_≡_ : D → D → Set
P : D → Set
a : D
-- A definition with one argument.
postulate foo : P a
{-# ATP axiom foo #-}
-- We need to have at least one conjecture to generate a TPTP file.
postulate bar : ∀ d → d ≡ d
{-# ATP prove bar #-}
|
{
"alphanum_fraction": 0.3928571429,
"avg_line_length": 28,
"ext": "agda",
"hexsha": "bf8da4247c4a93b4970ed4bd740e7377ea7e591a",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/fol-theorems/Agda/InternalTerms/DefTerm1.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/fol-theorems/Agda/InternalTerms/DefTerm1.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/fol-theorems/Agda/InternalTerms/DefTerm1.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": 147,
"size": 756
}
|
{-# OPTIONS --safe #-}
module Cubical.HITs.Wedge where
open import Cubical.HITs.Wedge.Base public
|
{
"alphanum_fraction": 0.7474747475,
"avg_line_length": 19.8,
"ext": "agda",
"hexsha": "1cf2e974757279808ed2b1771fdbaa98afe5afeb",
"lang": "Agda",
"max_forks_count": 134,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z",
"max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "marcinjangrzybowski/cubical",
"max_forks_repo_path": "Cubical/HITs/Wedge.agda",
"max_issues_count": 584,
"max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "marcinjangrzybowski/cubical",
"max_issues_repo_path": "Cubical/HITs/Wedge.agda",
"max_line_length": 42,
"max_stars_count": 301,
"max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "marcinjangrzybowski/cubical",
"max_stars_repo_path": "Cubical/HITs/Wedge.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z",
"num_tokens": 27,
"size": 99
}
|
------------------------------------------------------------------------------
-- CS410 Exercise 5
--
-- Given the overrunning of exercise 4, I've decided to shift the deadline
-- for exercise 5 back to the end of semester 2, so you can have a wee go
-- in the last week of semester 1, but then focus on your CS408 projects.
--
-- Exercise 6 will follow directly on from this and share the deadline, but
-- it will be issued at Easter.
--
-- I don't know the precise deadline, because I have not yet been told the
-- mark upload deadline for the semester 2 exam board. I will give you as
-- much time as I can. Usually, I can make the deadline after the last
-- exam, but I haven't seen the timetable yet.
--
-- It's a good idea to start well before the exams, get the basics sorted,
-- then come back to it after the exams and apply polish.
------------------------------------------------------------------------------
module Ex5 where -- Conor: 1.5/15
open import CS410-Prelude
open import CS410-Nat
open import CS410-Vec
open import CS410-Indexed
open import CS410-Monoid
------------------------------------------------------------------------------
-- CHARACTERS AND STRINGS
------------------------------------------------------------------------------
{-
data List (X : Set) : Set where -- X scopes over the whole declaration...
[] : List X -- ...so you can use it here...
_::_ : X -> List X -> List X -- ...and here.
infixr 3 _::_
{-# BUILTIN BOOL Two #-}
{-# BUILTIN TRUE tt #-}
{-# BUILTIN FALSE ff #-}
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _::_ #-}
{-# COMPILED_DATA List [] [] (:) #-}
postulate -- this means that we just suppose the following things exist...
Char : Set
String : Set
{-# BUILTIN CHAR Char #-}
{-# COMPILED_TYPE Char Char #-}
{-# BUILTIN STRING String #-}
{-# COMPILED_TYPE String String #-}
primitive -- these are baked in; they even work!
primCharEquality : Char -> Char -> Two
primStringAppend : String -> String -> String
primStringToList : String -> List Char
primStringFromList : List Char -> String
-}
------------------------------------------------------------------------------
-- THE TILING MONAD (from lectures)
------------------------------------------------------------------------------
WH : Set
WH = Nat * Nat
data Tiling (X : WH -> Set)(wh : WH) : Set where
! : X wh -> Tiling X wh
joinH : (wl wr : Nat)(wq : wl +N wr == fst wh) ->
Tiling X (wl , snd wh) -> Tiling X (wr , snd wh) -> Tiling X wh
joinV : (ht hb : Nat)(hq : ht +N hb == snd wh) ->
Tiling X (fst wh , ht) -> Tiling X (fst wh , hb) -> Tiling X wh
TilingMonadIx : MonadIx Tiling
TilingMonadIx = record
{ retIx = !
; extendIx = help
} where
help : {P Q : WH -> Set} -> [ P -:> Tiling Q ] -> [ Tiling P -:> Tiling Q ]
help f (! p) = f p
help f (joinH wl wr wq t-l t-r) = joinH wl wr wq (help f t-l) (help f t-r)
help f (joinV ht hb hq t-t t-b) = joinV ht hb hq (help f t-t) (help f t-b)
-- That's the monad you'll need in this file, so let's open it.
open MonadIx TilingMonadIx
open FunctorIx (monadFunctorIx TilingMonadIx)
------------------------------------------------------------------------------
-- PASTE KITS
------------------------------------------------------------------------------
-- A PasteKit equips rectangular stuff with the means to stick
-- things the same height side-by-side, or things the same width
-- one-on-top-of-the-other
record PasteKit (X : WH -> Set) : Set where
field
pasteH : {wh : WH}(wl wr : Nat)(wq : wl +N wr == fst wh) ->
X (wl , snd wh) -> X (wr , snd wh) -> X wh
pasteV : {wh : WH}(ht hb : Nat)(hq : ht +N hb == snd wh) ->
X (fst wh , ht) -> X (fst wh , hb) -> X wh
-- ??? 5.1 (1 mark) -- Conor: 1/1
-- Show that if you have a PasteKit for X tiles, you can turn a
-- Tiling X into one big X.
paste : forall {X} -> PasteKit X -> [ Tiling X -:> X ]
paste {X} pk = go where
open PasteKit pk
go : [ Tiling X -:> X ]
go (! x) = x
go (joinH wl wr wq t0 t1) = pasteH wl wr wq (go t0 ) (go t1)
go (joinV ht hb hq t0 t1) = pasteV ht hb hq (go t0) (go t1)
------------------------------------------------------------------------------
-- CUT KITS
------------------------------------------------------------------------------
-- A CutKit consists of functions which split a rectangular thing in two,
-- horizontally or vertically.
record CutKit (X : WH -> Set) : Set where
field
cutH : {wh : WH}(wl wr : Nat)(wq : wl +N wr == fst wh) ->
X wh -> X (wl , snd wh) * X (wr , snd wh)
cutV : {wh : WH}(ht hb : Nat)(hq : ht +N hb == snd wh) ->
X wh -> X (fst wh , ht) * X (fst wh , hb)
------------------------------------------------------------------------------
-- MATRICES
------------------------------------------------------------------------------
Matrix : Set -> WH -> Set
Matrix C (w , h) = Vec (Vec C w) h
-- ??? 5.2 (2 marks) -- 0/2
-- Equip matrices with a PasteKit and a CutKit. Try to make good use of
-- the operations developed for vectors.
matrixPaste : {C : Set} -> PasteKit (Matrix C)
matrixPaste {C} = record
{ pasteH = mPH
; pasteV = mPV
} where
mPH : {wh : WH} (wl wr : Nat) -> wl +N wr == fst wh -> Matrix C (wl , snd wh) -> Matrix C (wr , snd wh) -> Matrix C wh
mPH wl wr wq ml mr = {!!}
mPV : {wh : WH} (ht hb : Nat) -> ht +N hb == snd wh -> Matrix C (fst wh , ht) -> Matrix C (fst wh , hb) -> Matrix C wh
mPV ht hb hq mt mb = {!vec !}
matrixCut : {C : Set} -> CutKit (Matrix C)
matrixCut {C} = record
{ cutH = mCH
; cutV = mCV
} where
mCH : {wh : WH} (wl wr : Nat) -> wl +N wr == fst wh ->
Matrix C wh -> Matrix C (wl , snd wh) * Matrix C (wr , snd wh)
mCH wl wr wq m = {!!}
mCV : {wh : WH} (ht hb : Nat) -> ht +N hb == snd wh ->
Matrix C wh -> Matrix C (fst wh , ht) * Matrix C (fst wh , hb)
mCV ht hb hq m = {!!}
---------------------------------------------------------------------------
-- COLOURS
---------------------------------------------------------------------------
-- We're going to be making displays from coloured text.
{-
data Colour : Set where
black red green yellow blue magenta cyan white : Colour
{-# COMPILED_DATA Colour HaskellSetup.Colour
HaskellSetup.Black HaskellSetup.Red HaskellSetup.Green
HaskellSetup.Yellow HaskellSetup.Blue HaskellSetup.Magenta
HaskellSetup.Cyan HaskellSetup.White #-}
-}
-- Each cell in a display has this information:
record Cell : Set where
constructor _-_/_
field
fgCo : Colour -- foreground colour
char : Char -- character to display in cell
bgCo : Colour -- background colour
-- e.g. white - '*' / black
-- Now,
-- Matrix Cell : WH -> Set
-- is a suitable notion of sized display
---------------------------------------------------------------------------
-- INTERLUDE: TESTING WITH TEXT
---------------------------------------------------------------------------
-- I've written some code which should help you see what you're doing.
-- Turn a list into a vector, either by truncating or padding with
-- a given dummy element.
paddy : {X : Set} -> X -> List X -> {n : Nat} -> Vec X n
paddy _ _ {zero} = []
paddy x [] {suc n} = x :: paddy x [] {n}
paddy x (y :: ys) {suc n} = y :: paddy x ys {n}
-- Turn some colours and a string into a vector of cells
_-_//_ : Colour -> String -> Colour -> {n : Nat} -> Vec Cell n
f - s // b = vapp (vapp (vec (_-_/_ f))
(paddy ' ' (primStringToList s)))
(vec b)
infixr 4 _-_//_
-- Build an example matrix
example1 : Matrix Cell (10 , 5)
example1 = black - "hydrogen" // white
:: black - "helium" // white
:: black - "lithium" // white
:: black - "beryllium" // white
:: black - "boron" // white
:: []
-- Cut it up
example23 : Matrix Cell (5 , 5) * Matrix Cell (5 , 5)
example23 = cutH 5 5 refl example1
where open CutKit matrixCut
-- Stick the bits back together, vertically
example4 : Matrix Cell (5 , 10)
example4 = pasteV 5 5 refl (fst example23) (snd example23)
where open PasteKit matrixPaste
---------------------------------------------------------------------------
-- CUTTING UP TILINGS
---------------------------------------------------------------------------
-- Previously...
-- ... we established what it is to be a CutKit, and we built CutKits
-- for some sorts of basic tile. Now we need to build the CutKit for
-- Tilings. Let's think about what that involves for a moment. We're going
-- to need a CutKit for basic tiles to stand a chance. But how do we
-- cut compound tiles?
--
-- Suppose we're writing cutH, and we have some
-- cq : cwl + cwr == w -- the "cut widths" equation
-- telling us where we want to make the cut in something of width w.
--
-- v
-- +--------:------+
-- | : |
-- | : |
-- +--cwl---:-cwr--+
-- : ^ :
-- :.......w.......:
--
-- The tricky part is when the tiling we're cutting here is built with
-- joinH twl twr tq tl tr
-- where
-- tq : twl + twr == w -- the "tiling widths" equation
--
-- There are three possible situations, all of which you must detect
-- and handle.
--
-- (i) you hit the sweet spot...
--
-- v
-- +--bwl---+-bwr--+
-- | | |
-- | | |
-- +--cwl---+-cwr--+
-- : ^ :
-- :.......w.......:
--
-- ...where the box is already divided in the place where the cut
-- has to go. Happy days.
--
-- (ii) you're cutting to the left of the join...
--
-- v
-- +--bwl-----+bwr-+
-- | : | |
-- | : | |
-- +--cwl---:-cwr--+
-- : ^ :
-- :.......w.......:
--
-- ...so you'll need to cut the left box in the correct place. You
-- will need some evidence about widths to do that. And then you'll
-- the have three pieces you can see in my diagram, so to complete
-- the cut, you will need to put two of those pieces together, which
-- will take more evidence.
--
-- (iii) you're cutting to the right of the join...
--
-- v
-- +--bwl-+--bwr---+
-- | | : |
-- | | : |
-- +--cwl---:-cwr--+
-- : ^ :
-- :.......w.......:
--
-- ...so you'll need to cut the right box in the correct place, and
-- reassemble the bits.
--
-- HINT: The next three tasks go together.
-- ??? 5.3.1 (1 mark) -- Conor: 0.5/1
-- COMPARING THE CUT POSITION
data CutComparable (x x' y y' n : Nat) : Set where
cutC : y == x -> CutComparable x x' y y' n
-- cutL :
-- cutR :
-- Give three constructors for this type which characterize the three
-- possibilities described above whenever
-- x + x' == n and y + y' == n
-- (E.g., take n to be w, x and x' to be cwl and cwr, y and y' to be
-- twl and twr. But later, you'll need to do use the same tool for
-- heights.)
--
-- You will need to investigate what evidence must be packaged in each
-- situation. On the one hand, you need to be able to *generate* the
-- evidence, with cutCompare, below. On the other hand, the evidence
-- must be *useful* when you come to write tilingCut, further below.
-- Don't expect to know what to put here from the get-go. Figure it
-- out by discovering what you *need*.
-- YOUR CONSTRUCTORS GO HERE
-- The following facts may come in handy.
sucInject : {m n : Nat} -> suc m == suc n -> m == n
sucInject refl = refl
sucRespect : {m n : Nat} -> m == n -> suc m == suc n
sucRespect refl = refl
-- ??? 5.3.2 (1 mark) -- Conor: 0/1
-- Show that whenever you have two ways to express the same n as a sum,
-- you can always deliver the CutComparable evidence.
cutCompare : (x x' y y' n : Nat) -> x +N x' == n -> y +N y' == n ->
CutComparable x x' y y' n
cutCompare x x' y y' n xq yq = {!!}
-- ??? 5.3.3 (2 marks) -- Conor: 0/2
-- A CUTKIT FOR TILINGS
-- Now, show that you can construct a CutKit for Tiling X, given a CutKit
-- for X. There will be key points where you get stuck for want of crucial
-- information. The purpose of CutCompare is to *describe* that
-- information. The purpose of cutCompare is to *compute* that information.
-- Note that cutH and cutV will work out very similarly, just exchanging
-- the roles of width and height.
-- Hint: good solutions are likely to use "with" a lot.
tilingCut : {X : WH -> Set} -> CutKit X -> CutKit (Tiling X)
tilingCut {X} ck = record { cutH = cH ; cutV = cV } where
open CutKit ck
cH : {wh : WH}(wl wr : Nat)(wq : wl +N wr == fst wh) ->
Tiling X wh -> Tiling X (wl , snd wh) * Tiling X (wr , snd wh)
cH cwl cwr cq t = {!!}
cV : {wh : WH}(ht hb : Nat)(hq : ht +N hb == snd wh) ->
Tiling X wh -> Tiling X (fst wh , ht) * Tiling X (fst wh , hb)
cV cht chb cq t = {!!}
---------------------------------------------------------------------------
-- SUPERIMPOSITION
---------------------------------------------------------------------------
-- ??? 5.4 (2 marks) -- Conor: 0/2
-- Suppose you have a tiling made of X tiles in front of a tiling made of
-- Y tiles. Suppose you have a CutKit for Y. Suppose you know how to
-- superimpose *one* X tile on a Y tiling to make a Z tiling. You should be
-- able to superimpose X tilings on Y tilings to get a Z tiling: you can but
-- the back Y tiling into pieces which fit with the individual X tiles in
-- front.
super : {X Y Z : WH -> Set} -> CutKit Y ->
[ X -:> Tiling Y -:> Tiling Z ] ->
[ Tiling X -:> Tiling Y -:> Tiling Z ]
super {X}{Y}{Z} ck m = go where
open CutKit (tilingCut ck)
go : [ Tiling X -:> Tiling Y -:> Tiling Z ]
go xt yt = {!!}
-- HINT: no new recursive operations are needed in the rest of this file.
-- You've done the hard work. Now get paid.
---------------------------------------------------------------------------
-- HOLES
---------------------------------------------------------------------------
-- ??? 5.5 (2 marks) -- Conor: 0/2
-- In order to build up displays in layers, we will need to work with
-- tilings where one sort of primitive tile is, in fact, a hole!
data HoleOr (X : WH -> Set)(wh : WH) : Set where
hole : HoleOr X wh -- a hole you can see through
block : X wh -> HoleOr X wh -- a block of stuff you can't see through
-- Explain how to see through a hole but not through a block
seeThrough : {X : WH -> Set} ->
[ HoleOr X -:> Tiling (HoleOr X) -:> Tiling (HoleOr X) ]
seeThrough hx thx = {!!}
-- Show that if X has a CutKit, then so has HoleOr X. Cutting up holes is
-- very easy as they don't put up much resistance.
holeCut : {X : WH -> Set} -> CutKit X -> CutKit (HoleOr X)
holeCut ck = record
{ cutH = {!!}
; cutV = {!!}
}
where open CutKit ck
-- Now, a rectangular layer is a tiling whose pieces are either holes or
-- blocks of coloured text.
Layer : WH -> Set
Layer = Tiling (HoleOr (Matrix Cell))
-- By making careful use of super and seeThrough, show how layers of a given
-- size have monoid structure, where the operation combines "front" and "back"
-- layers by making the back layer visible only through the holes in the front.
layerId : [ Layer ]
layerId = {!!}
layerOp : [ Layer -:> Layer -:> Layer ]
layerOp = super {!!} {!!}
-- I'd ask you to prove that the monoid laws hold (they do), but when I did it,
-- it was too much of a slog for too few ideas.
-- A typical display is made by superimposing a bunch of layers, but you might
-- still leave some holes, so we need to fill in a background. Use the MonadIx
-- structure of tilings to fill in each hole in a Layer with a matrix of black
-- (but who can tell?) spaces on a white background.
background : [ Layer -:> Tiling (Matrix Cell) ]
background = mapIx {!!}
---------------------------------------------------------------------------
-- CHANGES
---------------------------------------------------------------------------
-- Applications change what they display as you use them, of course. Often
-- they change a little at a time, so it's not necessary to repaint the
-- whole thing. Let's build tilings to represent just what changes.
data Change (wh : WH) : Set where
new : Layer wh -> Change wh
old : Change wh
-- The idea is that you make a top-level tiling to show which regions have
-- changed, and for the ones with new content, you give the layer which is
-- that content. So a Tiling Change tells you the difference between the
-- old layer and the new layer.
-- ??? 5.6 (1 mark) -- Conor: 0/1
-- You should be able to compute the changed layer given the change and the old
-- layer. Hint: This, also, is a job for super.
changed : [ Tiling Change -:> Layer -:> Layer ]
changed = super {!!} {!!}
---------------------------------------------------------------------------
-- UPDATA
---------------------------------------------------------------------------
-- ??? 5.7 (3 marks) -- Conor: 0/3
-- A notion related to "Change" is "Updata", but they're subtly different:
-- the actual content in a change is just the new stuff, and we've seen we
-- can grab any old parts from the old layer;
-- the Updata structure stores *all* the content, but each tile is tagged
-- with a bit which tells you if it comes from the change or was there
-- before.
record Updata (wh : WH) : Set where
constructor _-:_
field
updated : Two -- has it changed
content : HoleOr (Matrix Cell) wh -- what is it, anyway?
-- Correspondingly, you should be able to generate a Tiling Updata
-- from a Tiling Change and the old Layer. Work in two stages. First,
-- make a thing that generates a Tiling Updata from a Layer by
-- applying the same tag to all tiles.
tagLayer : Two -> [ Layer -:> Tiling Updata ]
tagLayer u = {!!}
-- Now you should be able to generate a version of "changed" that adds tags.
updata : [ Tiling Change -:> Layer -:> Tiling Updata ]
updata = {!!}
-- Last but not least, develop the monoid operations for Updata. Here's where
-- you sort out the logic for displaying changing layers. Content-wise, it should
-- be a lot like the Layer monoid, in that you can see the back stuff through
-- the holes in the front stuff. But what about the "updated" tags? Is there a
-- difference between an "old" hole in the front and a "new" hole in the front?
-- You will need to build a CutKit in order to use super appropriately.
updataId : [ Tiling Updata ]
updataId = {!!}
updataCut : CutKit Updata
updataCut = {!!}
updataOp : [ Tiling Updata -:> Tiling Updata -:> Tiling Updata ]
updataOp = {!!}
---------------------------------------------------------------------------
-- NEXT TIME...
---------------------------------------------------------------------------
-- We'll develop a notion of "Application" which can each display
-- their Layer, and respond to events by delivering a Tiling
-- Change. We'll develop a notion of "Desktop" which amounts to a
-- front-to-back stack of applications. The Desktop display updates
-- by superimposing the Tiling Updata which comes from the change made
-- by each application in the stack.
-- Once we've got that setup, we can run applications by getting events
-- from the keyboard, generating the Tiling Updata for the whole Desktop,
-- then use cursor movement to skip the unchanged parts and just rewrite
-- the regions which need it. It'll actually go!
|
{
"alphanum_fraction": 0.5459440057,
"avg_line_length": 35.3297101449,
"ext": "agda",
"hexsha": "d921a9f84131e8a3e178435e18d5f95b9f1773a8",
"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": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "clarkdm/CS410",
"max_forks_repo_path": "Ex5.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "clarkdm/CS410",
"max_issues_repo_path": "Ex5.agda",
"max_line_length": 120,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "clarkdm/CS410",
"max_stars_repo_path": "Ex5.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5251,
"size": 19502
}
|
-- Jesper, 2018-05-14: constructor patterns of the parent clause can
-- now be replaced by a variable in the with clause.
open import Common.Prelude
f : List Nat → List Nat
f [] = []
f (x ∷ xs) with Set
f xs | p = xs
|
{
"alphanum_fraction": 0.6757990868,
"avg_line_length": 21.9,
"ext": "agda",
"hexsha": "85d54f0d1d57e54aefc9e5321e778c10e5175a2c",
"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/WithConstructorToVariable.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/WithConstructorToVariable.agda",
"max_line_length": 68,
"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/WithConstructorToVariable.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 67,
"size": 219
}
|
private
record Dummy : Set₁ where
constructor ⟨_⟩
field
{h} : Set
nh : Set
pattern ⟪_,_⟫ h s = ⟨_⟩ {h} s
pattern ⟪_⟫ h = (⟨_⟩ {h} _)
|
{
"alphanum_fraction": 0.5064102564,
"avg_line_length": 15.6,
"ext": "agda",
"hexsha": "ea6ce6515fba02c59895e5e8a7990632b2453d7c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/OscarPattern.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/OscarPattern.agda",
"max_line_length": 29,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/OscarPattern.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 67,
"size": 156
}
|
{-# OPTIONS --without-K --exact-split --safe #-}
module Fragment.Extensions.CSemigroup.Nat where
open import Relation.Binary.PropositionalEquality as PE using (_≡_)
data ℕ⁺ : Set where
one : ℕ⁺
suc : ℕ⁺ → ℕ⁺
infixl 6 _+_
_+_ : ℕ⁺ → ℕ⁺ → ℕ⁺
one + x = suc x
suc x + y = suc (x + y)
+-suc : ∀ x y → x + suc y ≡ suc (x + y)
+-suc one y = PE.refl
+-suc (suc x) y = PE.cong suc (+-suc x y)
+-one : ∀ x → x + one ≡ suc x
+-one one = PE.refl
+-one (suc x) = PE.cong suc (+-one x)
+-assoc : ∀ x y z → (x + y) + z ≡ x + (y + z)
+-assoc one _ _ = PE.refl
+-assoc (suc x) y z = PE.cong suc (+-assoc x y z)
open PE.≡-Reasoning
+-comm : ∀ x y → x + y ≡ y + x
+-comm one one = PE.refl
+-comm one (suc y) = begin
one + (suc y) ≡⟨⟩
suc (suc y) ≡⟨ PE.sym (PE.cong suc (+-one y)) ⟩
suc (y + one) ≡⟨ PE.sym PE.refl ⟩
suc y + one ∎
+-comm (suc x) y = begin
suc x + y ≡⟨⟩
suc (x + y) ≡⟨ PE.cong suc (+-comm x y) ⟩
suc (y + x) ≡⟨ PE.sym (+-suc y x) ⟩
y + suc x ∎
|
{
"alphanum_fraction": 0.4960784314,
"avg_line_length": 23.7209302326,
"ext": "agda",
"hexsha": "3cd6e613007cc05b2011f3e033aafb3d259b6eef",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Extensions/CSemigroup/Nat.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Extensions/CSemigroup/Nat.agda",
"max_line_length": 67,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Extensions/CSemigroup/Nat.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 450,
"size": 1020
}
|
open import Agda.Builtin.Float
open import Agda.Builtin.Unit
open import Agda.Builtin.Reflection
open import Agda.Builtin.String
open import Agda.Builtin.Bool
open import Common.IO
data It (a : Float) : Set where
it : It a
Inf : Float
Inf = primFloatDiv 1.0 0.0
-Inf : Float
-Inf = primFloatNegate Inf
NaN : Float
NaN = primFloatDiv 0.0 0.0
-NaN : Float
-NaN = primFloatNegate NaN
_==_ = primFloatEquality
macro
literal : Float → Term → TC ⊤
literal x hole = unify hole (lit (float x))
nl = putStrLn ""
header = putStrLn " Inf -Inf NaN -NaN | x"
tick : Bool → String
tick true = " x "
tick false = " - "
check : Float → IO _
check x = putStr (tick (x == Inf)) ,,
putStr (tick (x == -Inf)) ,,
putStr (tick (x == NaN)) ,,
putStr (tick (x == -NaN)) ,,
putStr "| " ,, printFloat x ,,
nl
main : IO _
main =
header ,,
check (literal Inf) ,,
check (literal -Inf) ,,
check (literal NaN) ,,
check (literal -NaN)
|
{
"alphanum_fraction": 0.601,
"avg_line_length": 18.8679245283,
"ext": "agda",
"hexsha": "fe0bcb356ff9e01202ef6bee0599354e03bd4406",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Compiler/simple/Issue2218.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Compiler/simple/Issue2218.agda",
"max_line_length": 48,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Compiler/simple/Issue2218.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": 325,
"size": 1000
}
|
{-# OPTIONS --without-K --exact-split --rewriting #-}
open import lib.Basics
open import lib.PathGroupoid
open import lib.types.Bool
open import lib.types.Sigma
open import lib.types.Pi
open import lib.types.Coproduct
open import lib.types.Unit
open import lib.types.Empty
open import lib.NConnected
open import lib.NType
open import lib.NType2
open import lib.Equivalence
open import lib.types.Truncation
open import Util.Misc
open import Graphs.Definition
open import Graphs.Properties
open import Coequalizers.Definition
open import Coequalizers.EdgeCoproduct
open import Coequalizers.PreserveEquivalence
open import Coequalizers.TrivialExtension
{- Contains a useful lemma about extending subtrees used in the construction of spanning trees. -}
module Graphs.SubTrees where
{- We fix a graph E ⇉ V together with a family of types P over the vertex set. -}
module _ {i j k : ULevel} (E : Type i) (V : Type j) ⦃ gph : Graph E V ⦄
(P : V → Type k) where
private
ijk' = lmax i (lmax j k)
{- A crossing edge is an edge that has one end in P and one end outside P. -}
record Crossingedge : Type ijk' where
constructor
crossingedge
field
edge : E
dir : Bool
end-in-P : P (Bool-rec (π₀ edge) (π₁ edge) dir)
end-notin-P : ¬ (P (Bool-rec (π₁ edge) (π₀ edge) dir))
{- If the graph is connected, P is decidable and we are given a vertex in P and a vertex outside P,
then we can show there mereley exists an edge that crosses from P to ¬ P or vice versa. -}
findedge : (dec : (v : V) → Dec (P v)) (u v : V) (uInP : P u) (vNotinP : ¬ (P v)) (p : c[ u ] == c[ v ] :> V / E) → ∥ Crossingedge ∥
findedge dec u v uInP vNotinP p = equal-to-X c[ v ] p vNotinP
where
edgeequiv : (e : E) → ((¬ (P (π₀ e)) → ∥ Crossingedge ∥) ↔ (¬ (P (π₁ e)) → ∥ Crossingedge ∥))
edgeequiv e =
⊔-rec
(λ p0 → ⊔-rec
(λ p1 → (λ _ f → ⊥-elim (f p1)) , λ _ f → ⊥-elim (f p0))
(λ np1 → haveedge (crossingedge e true p0 np1))
(dec (π₁ e)))
(λ np0 → ⊔-rec
(λ p1 → haveedge (crossingedge e false p1 np0))
(λ np1 → (λ f _ → f np0) , λ f _ → f np1)
(dec (π₁ e)))
(dec ((π₀ e)))
where
haveedge : Crossingedge → ((¬ (P (π₀ e)) → ∥ Crossingedge ∥) ↔ (¬ (P (π₁ e)) → ∥ Crossingedge ∥))
haveedge ce = (λ _ _ → [ ce ]) , λ _ _ → [ ce ]
{- The key to the proof is to define a family of propositions X over the coequalizer of the graph.
For this to be well defined we need the lemma edgeequiv above, together with
propositional extensionality.
-}
X : V / E → Type (lmax j (lmax i k))
X = Coeq-rec (λ v' → ¬ (P v') → ∥ Crossingedge ∥ ) (λ e → prop-extensionality (edgeequiv e))
equal-to-X : (z : V / E) (p : c[ u ] == z) → X z
equal-to-X .(c[ u ]) idp = λ nu → ⊥-elim (nu uInP)
module _ {i j k l : ULevel} (E : Type i) (V : Type j) ⦃ gph : Graph E V ⦄ where
{- A subtree of E ⇉ V consists of a graph D ⇉ U such that U / D is contractible
together with injection D ↪ E and decidable injection U ↪ V making the obvious squares commute. -}
record SubTree (D : Type k) (U : Type l) : Type (lmax (lmax i j) (lmax k l)) where
constructor subtree
field
⦃ gphDU ⦄ : Graph D U
inD : D → E
inU : U → V
D-inj : is-inj inD
U-inj : is-inj inU
U-dec : (v : V) → Dec (hfiber inU v)
comm₀ : π₀ ∘ inD ∼ inU ∘ π₀
comm₁ : π₁ ∘ inD ∼ inU ∘ π₁
⦃ DUistree ⦄ : is-tree gphDU
{- If we are given subtree D ⇉ U and a vertex in V ∖ U, then we can extend the
subtree to a slightly larger one that contains one new vertex.
-}
extend-subtree : {D : Type k} {U : Type l} ⦃ conn : gph-is-connected gph ⦄ (decV : has-dec-eq V) → (t : SubTree D U) → (v : V) → ¬ (hfiber (SubTree.inU t) v) →
∥ SubTree (⊤ ⊔ D) (U ⊔ ⊤) ∥
extend-subtree {D} {U} decV record { gphDU = gphDU ; inD = inD ; inU = inU ; D-inj = D-inj ; U-inj = U-inj ; comm₀ = comm₀ ; comm₁ = comm₁ ; U-dec = U-dec} v f =
do -- we use do notation to help deal with iterated recursion on propositional truncation (see the definion of >>= in Util/Misc.agda)
u ← (Coeq-rec [_] (λ e → prop-has-all-paths _ _) (contr-center (⟨⟩ :> is-tree gphDU)))
p ← (conn-to-path c[ inU u ] c[ v ])
ce ← (findedge E V (hfiber inU) U-dec (inU u) v (u , idp) f p)
[ from-ce ce ]
where
from-ce : Crossingedge E V (λ v → (hfiber inU v)) → (SubTree (⊤ ⊔ D) (U ⊔ ⊤))
from-ce (crossingedge edge true end-in-P end-notin-P) =
record
{ inD = λ { (inl _) → edge ; (inr d) → inD d}
; inU = λ { (inl u) → inU u ; (inr _) → π₁ edge}
; D-inj = λ { (inl unit) →
λ { (inl unit) _ → idp ; (inr d) p → ⊥-elim (end-notin-P ((π₁ d) , ! (ap π₁ p ∙ comm₁ d)))}
; (inr d) →
λ { (inl unit) p → ⊥-elim (end-notin-P ((π₁ d) , ! (comm₁ d) ∙ ap π₁ p)) ; (inr d') p → ap inr (D-inj _ _ p)}}
; U-inj = λ { (inl u) →
λ { (inl u') p → ap inl (U-inj _ _ p) ; (inr unit) p → ⊥-elim (end-notin-P (u , p))}
; (inr unit) →
λ { (inl u) p → ⊥-elim (end-notin-P (u , (! p))) ; (inr unit) _ → idp}}
; U-dec = λ v → ⊔-rec (λ {(u , p) → inl ((inl u) , p)})
(λ f → ⊔-rec (λ p → inl ((inr unit) , ! p))
(λ g → inr (λ {(inl u , p) → f ((u , p)) ; (inr unit , p) → g (! p)}))
(decV v (π₁ edge)))
(U-dec v)
; comm₀ = λ { (inl x) → ! (snd end-in-P) ; (inr d) → comm₀ d}
; comm₁ = λ { (inl _) → idp ; (inr d) → comm₁ d}
; DUistree = equiv-preserves-level (extn-equiv ⁻¹)
}
where
instance
gphDU' : Graph (⊤ ⊔ D) (U ⊔ ⊤)
gphDU' = record { π₀ = λ { (inl _) → inl (fst end-in-P) ; (inr x) → inl (π₀ x) }
; π₁ = λ { (inl _) → inr unit ; (inr x) → inl (π₁ x) }}
extn-equiv : (U ⊔ ⊤) / (⊤ ⊔ D) ≃ U / D
extn-equiv =
(U ⊔ ⊤) / (⊤ ⊔ D)
≃⟨ edge-coproduct-expand ⟩
((U ⊔ ⊤) / ⊤) / D
≃⟨ (Coeq-emap (TExtensionCoeq-l.extn-equiv (fst end-in-P)) (ide D) (λ _ → idp) λ _ → idp) ⁻¹ ⟩
U / D
≃∎
where
open CoeqCoprodEquiv (U ⊔ ⊤) ⊤ D -- also defines instances for (U ⊔ ⊤) / ⊤) / D
from-ce (crossingedge edge false end-in-P end-notin-P) =
record
{ inD = λ { (inl _) → edge ; (inr d) → inD d}
; inU = λ { (inl u) → inU u ; (inr _) → π₀ edge}
; D-inj = λ { (inl unit) →
λ { (inl unit) _ → idp ; (inr d) p → ⊥-elim (end-notin-P ((π₀ d) , ! (ap π₀ p ∙ comm₀ d)))}
; (inr d) →
λ { (inl unit) p → ⊥-elim (end-notin-P ((π₀ d) , ! (comm₀ d) ∙ ap π₀ p)) ; (inr d') p → ap inr (D-inj _ _ p)}}
; U-inj = λ { (inl u) →
λ { (inl u') p → ap inl (U-inj _ _ p) ; (inr unit) p → ⊥-elim (end-notin-P (u , p))}
; (inr unit) →
λ { (inl u) p → ⊥-elim (end-notin-P (u , (! p))) ; (inr unit) _ → idp}}
; U-dec = λ v → ⊔-rec (λ {(u , p) → inl ((inl u) , p)})
(λ f → ⊔-rec (λ p → inl ((inr unit) , ! p))
(λ g → inr (λ {(inl u , p) → f ((u , p)) ; (inr unit , p) → g (! p)}))
(decV v (π₀ edge)))
(U-dec v)
; comm₀ = λ { (inl _) → idp ; (inr d) → comm₀ d}
; comm₁ = λ { (inl x) → ! (snd end-in-P) ; (inr d) → comm₁ d}
; DUistree = equiv-preserves-level (extn-equiv ⁻¹)
}
where
instance
gphDU' : Graph (⊤ ⊔ D) (U ⊔ ⊤)
gphDU' = record { π₀ = λ { (inl _) → inr unit ; (inr x) → inl (π₀ x) }
; π₁ = λ { (inl _) → inl (fst end-in-P) ; (inr x) → inl (π₁ x) }}
extn-equiv : (U ⊔ ⊤) / (⊤ ⊔ D) ≃ U / D
extn-equiv =
(U ⊔ ⊤) / (⊤ ⊔ D)
≃⟨ edge-coproduct-expand ⟩
((U ⊔ ⊤) / ⊤) / D
≃⟨ Coeq-emap (TExtensionCoeq-r.extn-equiv (fst end-in-P)) (ide D) (λ _ → idp) (λ _ → idp) ⁻¹ ⟩
U / D
≃∎
where
open CoeqCoprodEquiv (U ⊔ ⊤) ⊤ D -- also defines instances for (U ⊔ ⊤) / ⊤) / D
|
{
"alphanum_fraction": 0.4661937993,
"avg_line_length": 46.2486772487,
"ext": "agda",
"hexsha": "8dec64b33e12b4f847ba9c7a93c74aa5f7d005c2",
"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": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "awswan/nielsenschreier-hott",
"max_forks_repo_path": "main/Graphs/SubTrees.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"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": "awswan/nielsenschreier-hott",
"max_issues_repo_path": "main/Graphs/SubTrees.agda",
"max_line_length": 163,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "awswan/nielsenschreier-hott",
"max_stars_repo_path": "main/Graphs/SubTrees.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3103,
"size": 8741
}
|
open import Categories
open import Monads
import Monads.CatofAdj
import Monads.CatofAdj.TermAdjObj
module Monads.CatofAdj.TermAdjUniq
{a b}
{C : Cat {a}{b}}
(M : Monad C)
(A : Monads.CatofAdj.ObjAdj M)
(V : Monads.CatofAdj.HomAdj M A (Monads.CatofAdj.TermAdjObj.EMObj M))
where
open import Library
open import Functors
open import Adjunctions
open Monads.CatofAdj M
open import Monads.EM M
open Monads.CatofAdj.TermAdjObj M
open import Monads.CatofAdj.TermAdjHom M A
open import Categories.Terminal
open Fun
open Adj
open ObjAdj
open Cat
omaplem : OMap (HomAdj.K EMHom ) ≅ OMap (HomAdj.K V)
omaplem = ext
λ X → AlgEq (fcong X (cong OMap (HomAdj.Rlaw V)))
((ext λ Y →
dext
(λ {f} {f'} p →
trans
(trans
(trans
(stripsubst
(λ Z → Hom C Z (OMap (R (adj A)) X))
(HMap (R (adj A)) (right (adj A) f))
(fcong Y (cong OMap (law A))))
(cong' refl (cong
(λ (F : Obj (D A) → Obj C) →
λ (_ : Hom (D A) (OMap (L (adj A)) Y) X) →
Hom C (F (OMap (L (adj A)) Y)) (F X))
(cong OMap (HomAdj.Rlaw V)))
(icong' refl
(cong
(λ (F : Obj (D A) → Obj C) →
λ (z : Obj (D A)) →
Hom (D A) (OMap (L (adj A)) Y) z →
Hom C (F (OMap (L (adj A)) Y)) (F z))
(cong OMap (HomAdj.Rlaw V)))
(icong' refl
(cong
(λ (F : Obj (D A) → Obj C) →
λ (z : Obj (D A)) →
{Y₁ : Obj (D A)} → Hom (D A) z Y₁ → Hom C (F z) (F Y₁))
(cong OMap (HomAdj.Rlaw V)))
(cong HMap (HomAdj.Rlaw V)) (refl {x = OMap (L (adj A)) Y}))
(refl {x = X}))
(refl {x = right (adj A) f})))
(cong₃ (λ A₁ B → AlgMorph.amor {A₁} {B})
(fcong Y (cong OMap (HomAdj.Llaw V))) refl
(HomAdj.rightlaw V {Y} {X} {f})))
(cong (Alg.astr (OMap (HomAdj.K V) X) Y)
(trans
(stripsubst (Hom C Y) f (fcong X (cong OMap (HomAdj.Rlaw V))))
p)))))
hmaplem : {X Y : Obj (D A)} (f : Hom (D A) X Y) →
HMap (HomAdj.K EMHom) f ≅ HMap (HomAdj.K V) f
hmaplem {X}{Y} f = AlgMorphEq'
(fcong X omaplem)
(fcong Y omaplem)
(cong'
refl
(cong
(λ (F : Obj (D A) → Obj C) → λ (_ : Hom (D A) X Y) → Hom C (F X) (F Y))
(cong OMap (HomAdj.Rlaw V)))
(icong'
refl
(cong
(λ (F : Obj (D A) → Obj C) → λ (z : Obj (D A)) →
Hom (D A) X z → Hom C (F X) (F z))
(cong OMap (HomAdj.Rlaw V)))
(icong'
refl
(cong
(λ (F : Obj (D A) → Obj C) → λ (z : Obj (D A)) → {Y₁ : Obj (D A)} →
Hom (D A) z Y₁ → Hom C (F z) (F Y₁))
(cong OMap (HomAdj.Rlaw V)))
(cong HMap (HomAdj.Rlaw V))
(refl {x = X}))
(refl {x = Y}))
(refl {x = f}))
|
{
"alphanum_fraction": 0.43648,
"avg_line_length": 32.5520833333,
"ext": "agda",
"hexsha": "0723de25b4c086ce8e658f89551ff5d7b1aa9deb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "Monads/CatofAdj/TermAdjUniq.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "Monads/CatofAdj/TermAdjUniq.agda",
"max_line_length": 79,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "Monads/CatofAdj/TermAdjUniq.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 1112,
"size": 3125
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some properties about signs
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Sign.Properties where
open import Algebra
open import Data.Empty
open import Data.Sign
open import Data.Product using (_,_)
open import Function
open import Level using (0ℓ)
open import Relation.Binary.PropositionalEquality
open import Algebra.Structures {A = Sign} _≡_
open import Algebra.FunctionProperties {A = Sign} _≡_
-- The opposite of a sign is not equal to the sign.
s≢opposite[s] : ∀ s → s ≢ opposite s
s≢opposite[s] - ()
s≢opposite[s] + ()
opposite-injective : ∀ {s t} → opposite s ≡ opposite t → s ≡ t
opposite-injective { - } { - } refl = refl
opposite-injective { - } { + } ()
opposite-injective { + } { - } ()
opposite-injective { + } { + } refl = refl
------------------------------------------------------------------------
-- _*_
-- Algebraic properties of _*_
*-identityˡ : LeftIdentity + _*_
*-identityˡ _ = refl
*-identityʳ : RightIdentity + _*_
*-identityʳ - = refl
*-identityʳ + = refl
*-identity : Identity + _*_
*-identity = *-identityˡ , *-identityʳ
*-comm : Commutative _*_
*-comm + + = refl
*-comm + - = refl
*-comm - + = refl
*-comm - - = refl
*-assoc : Associative _*_
*-assoc + + _ = refl
*-assoc + - _ = refl
*-assoc - + _ = refl
*-assoc - - + = refl
*-assoc - - - = refl
*-cancelʳ-≡ : RightCancellative _*_
*-cancelʳ-≡ - - _ = refl
*-cancelʳ-≡ - + eq = ⊥-elim (s≢opposite[s] _ $ sym eq)
*-cancelʳ-≡ + - eq = ⊥-elim (s≢opposite[s] _ eq)
*-cancelʳ-≡ + + _ = refl
*-cancelˡ-≡ : LeftCancellative _*_
*-cancelˡ-≡ - eq = opposite-injective eq
*-cancelˡ-≡ + eq = eq
*-cancel-≡ : Cancellative _*_
*-cancel-≡ = *-cancelˡ-≡ , *-cancelʳ-≡
*-isMagma : IsMagma _*_
*-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _*_
}
*-magma : Magma 0ℓ 0ℓ
*-magma = record
{ isMagma = *-isMagma
}
*-isSemigroup : IsSemigroup _*_
*-isSemigroup = record
{ isMagma = *-isMagma
; assoc = *-assoc
}
*-semigroup : Semigroup 0ℓ 0ℓ
*-semigroup = record
{ isSemigroup = *-isSemigroup
}
*-isMonoid : IsMonoid _*_ +
*-isMonoid = record
{ isSemigroup = *-isSemigroup
; identity = *-identity
}
*-monoid : Monoid 0ℓ 0ℓ
*-monoid = record
{ isMonoid = *-isMonoid
}
-- Other properties of _*_
s*s≡+ : ∀ s → s * s ≡ +
s*s≡+ + = refl
s*s≡+ - = refl
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
opposite-not-equal = s≢opposite[s]
{-# WARNING_ON_USAGE opposite-not-equal
"Warning: opposite-not-equal was deprecated in v0.15.
Please use s≢opposite[s] instead."
#-}
opposite-cong = opposite-injective
{-# WARNING_ON_USAGE opposite-cong
"Warning: opposite-cong was deprecated in v0.15.
Please use opposite-injective instead."
#-}
cancel-*-left = *-cancelˡ-≡
{-# WARNING_ON_USAGE cancel-*-left
"Warning: cancel-*-left was deprecated in v0.15.
Please use *-cancelˡ-≡ instead."
#-}
cancel-*-right = *-cancelʳ-≡
{-# WARNING_ON_USAGE cancel-*-right
"Warning: cancel-*-right was deprecated in v0.15.
Please use *-cancelʳ-≡ instead."
#-}
*-cancellative = *-cancel-≡
{-# WARNING_ON_USAGE *-cancellative
"Warning: *-cancellative was deprecated in v0.15.
Please use *-cancel-≡ instead."
#-}
|
{
"alphanum_fraction": 0.5813689293,
"avg_line_length": 24.2827586207,
"ext": "agda",
"hexsha": "2491515a382409ee6a46138677da2ea8db5429ce",
"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/Sign/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Sign/Properties.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Sign/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1111,
"size": 3521
}
|
{-# OPTIONS --universe-polymorphism #-}
-- It's possible to compute levels
module ComputedLevels where
open import Common.Level
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
N-ary-level : Level → Level → ℕ → Level
N-ary-level ℓ₁ ℓ₂ zero = ℓ₂
N-ary-level ℓ₁ ℓ₂ (suc n) = ℓ₁ ⊔ N-ary-level ℓ₁ ℓ₂ n
N-ary : ∀ {ℓ₁ ℓ₂} (n : ℕ) → Set ℓ₁ → Set ℓ₂ → Set (N-ary-level ℓ₁ ℓ₂ n)
N-ary zero A B = B
N-ary (suc n) A B = A → N-ary n A B
|
{
"alphanum_fraction": 0.6120092379,
"avg_line_length": 21.65,
"ext": "agda",
"hexsha": "9aefcbcde376e2382f4d5bdc6b7354bb7e9289d1",
"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/ComputedLevels.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/ComputedLevels.agda",
"max_line_length": 71,
"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/ComputedLevels.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": 183,
"size": 433
}
|
module Ex2 where
open import Ex1
|
{
"alphanum_fraction": 0.7714285714,
"avg_line_length": 7,
"ext": "agda",
"hexsha": "b340682502da61354768677a106119985a56b5ba",
"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/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Ex2.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/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Ex2.agda",
"max_line_length": 16,
"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/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Ex2.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": 10,
"size": 35
}
|
module Examples.OpSem where
open import Luau.OpSem using (_⊢_⟶ᴱ_⊣_; _⊢_⟶ᴮ_⊣_; subst)
open import Luau.Syntax using (var; nil; local_←_; _∙_; done; return)
open import Luau.Heap using (emp)
x = var "x"
ex1 : emp ⊢ (local "x" ← nil ∙ return x ∙ done) ⟶ᴮ (return nil ∙ done) ⊣ emp
ex1 = subst
|
{
"alphanum_fraction": 0.6632653061,
"avg_line_length": 24.5,
"ext": "agda",
"hexsha": "4043869ed3ff21c5b222eb7ff17d514d906e0d1c",
"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": "5187e64f88953f34785ffe58acd0610ee5041f5f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "FreakingBarbarians/luau",
"max_forks_repo_path": "prototyping/Examples/OpSem.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f",
"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": "FreakingBarbarians/luau",
"max_issues_repo_path": "prototyping/Examples/OpSem.agda",
"max_line_length": 76,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FreakingBarbarians/luau",
"max_stars_repo_path": "prototyping/Examples/OpSem.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-11T21:30:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-11T21:30:17.000Z",
"num_tokens": 126,
"size": 294
}
|
-- Proof that consistent negative axioms do not jeopardize canonicity.
-- https://www.cs.bham.ac.uk/~mhe/papers/negative-axioms.pdf
{-# OPTIONS --without-K --safe #-}
module Application.NegativeAxioms.Canonicity where
open import Definition.Untyped as U
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.Weakening as T
open import Definition.Typed.Consequences.Inequality
open import Definition.Typed.Consequences.Injectivity
open import Definition.Typed.Consequences.Substitution
open import Definition.Typed.Consequences.Syntactic
open import Definition.Conversion.Consequences.Completeness
open import Definition.Conversion.FullReduction
open import Tools.Empty
open import Tools.Fin
open import Tools.Nat
open import Tools.Product
open import Tools.Sum using (_⊎_; inj₁; inj₂)
open import Tools.Unit
-- Preliminaries
---------------------------------------------------------------------------
private
Ty = Term
Cxt = Con Ty
variable
m m' : Nat
x : Fin m
ρ : Wk m m'
σ : Subst m m'
Γ Δ : Con Term m
A B C : Term m
t u : Term m
-- Numerals
data Numeral {m : Nat} : Term m → Set where
zeroₙ : Numeral zero
sucₙ : Numeral t → Numeral (suc t)
-- Negative types
---------------------------------------------------------------------------
-- A type is negative if all of its branches end in ⊥.
-- The prime example is negation ¬A.
data NegativeType (Γ : Cxt m) : Ty m → Set where
empty : NegativeType Γ Empty
pi : Γ ⊢ A
→ NegativeType (Γ ∙ A) B
→ NegativeType Γ (Π A ▹ B)
sigma : Γ ⊢ A
→ NegativeType Γ A
→ NegativeType (Γ ∙ A) B
→ NegativeType Γ (Σ A ▹ B)
conv : NegativeType Γ A
→ Γ ⊢ A ≡ B
→ NegativeType Γ B
-- Lemma: Negative types are closed under weakening.
wkNeg : ρ ∷ Δ ⊆ Γ → ⊢ Δ → NegativeType Γ A → NegativeType Δ (U.wk ρ A)
wkNeg w ⊢Δ empty
= empty
wkNeg w ⊢Δ (pi dA nB)
= pi dA' (wkNeg (lift w) (⊢Δ ∙ dA') nB)
where dA' = T.wk w ⊢Δ dA
wkNeg w ⊢Δ (sigma dA nA nB)
= sigma dA' (wkNeg w ⊢Δ nA) (wkNeg (lift w) (⊢Δ ∙ dA') nB)
where dA' = T.wk w ⊢Δ dA
wkNeg w ⊢Δ (conv n c)
= conv (wkNeg w ⊢Δ n) (wkEq w ⊢Δ c)
-- Lemma: Negative types are closed under parallel substitution.
subNeg : NegativeType Γ A → Δ ⊢ˢ σ ∷ Γ → ⊢ Δ → NegativeType Δ (subst σ A)
subNeg empty _ _ = empty
subNeg (pi ⊢A n) s ⊢Δ
= pi ⊢σA (subNeg n (liftSubst′ (wf ⊢A) ⊢Δ ⊢A s) (⊢Δ ∙ ⊢σA))
where ⊢σA = substitution ⊢A s ⊢Δ
subNeg (sigma ⊢A nA nB) s ⊢Δ
= sigma ⊢σA (subNeg nA s ⊢Δ) (subNeg nB (liftSubst′ (wf ⊢A) ⊢Δ ⊢A s) (⊢Δ ∙ ⊢σA))
where ⊢σA = substitution ⊢A s ⊢Δ
subNeg (conv n c) s ⊢Δ = conv (subNeg n s ⊢Δ) (substitutionEq c (substRefl s) ⊢Δ)
-- Corollary: Negative types are closed under single substitution.
subNeg1 : NegativeType (Γ ∙ A) B → Γ ⊢ t ∷ A → NegativeType Γ (B [ t ])
subNeg1 n ⊢t = subNeg n (singleSubst ⊢t) (wfTerm ⊢t)
-- Lemma: The first component of a negative Σ-type is negative.
fstNeg : NegativeType Γ C → Γ ⊢ C ≡ Σ A ▹ B → NegativeType Γ A
fstNeg empty c = ⊥-elim (Empty≢Σⱼ c)
fstNeg (pi _ _) c = ⊥-elim (Π≢Σ c)
fstNeg (sigma _ nA _) c = conv nA (proj₁ (Σ-injectivity c))
fstNeg (conv n c) c' = fstNeg n (trans c c')
-- Lemma: Any instance of the second component of a negative Σ-type is negative.
sndNeg : NegativeType Γ C → Γ ⊢ C ≡ Σ A ▹ B → Γ ⊢ t ∷ A → NegativeType Γ (B [ t ])
sndNeg empty c = ⊥-elim (Empty≢Σⱼ c)
sndNeg (pi _ _) c = ⊥-elim (Π≢Σ c)
sndNeg (sigma _ _ nB) c ⊢t = let (cA , cB) = Σ-injectivity c in
subNeg (conv nB cB) (singleSubst (conv ⊢t (sym cA))) (wfTerm ⊢t)
sndNeg (conv n c) c' = sndNeg n (trans c c')
-- Lemma: Any instance of the codomain of a negative Π-type is negative.
appNeg : NegativeType Γ C → Γ ⊢ C ≡ Π A ▹ B → Γ ⊢ t ∷ A → NegativeType Γ (B [ t ])
appNeg empty c = ⊥-elim (Empty≢Πⱼ c)
appNeg (sigma _ _ _) c = ⊥-elim (Π≢Σ (sym c))
appNeg (pi _ nB) c ⊢t = let (cA , cB) = injectivity c in
subNeg (conv nB cB) (singleSubst (conv ⊢t (sym cA))) (wfTerm ⊢t)
appNeg (conv n c) c' = appNeg n (trans c c')
-- Lemma: The type ℕ is not negative.
¬negℕ : NegativeType Γ C → Γ ⊢ C ≡ ℕ → ⊥
¬negℕ empty c = ℕ≢Emptyⱼ (sym c)
¬negℕ (pi _ _) c = ℕ≢Π (sym c)
¬negℕ (sigma _ _ _) c = ℕ≢Σ (sym c)
¬negℕ (conv n c) c' = ¬negℕ n (trans c c')
-- Negative contexts
---------------------------------------------------------------------------
-- A context is negative if all of its type entries are negative.
data NegativeContext : Con Ty m → Set where
ε : NegativeContext ε
_∙_ : NegativeContext Γ → NegativeType Γ A → NegativeContext (Γ ∙ A)
-- Lemma: Any entry in negative context is a negative type (needs weakening).
lookupNegative : ⊢ Γ → NegativeContext Γ → (x ∷ A ∈ Γ) → NegativeType Γ A
lookupNegative ⊢Γ∙A (nΓ ∙ nA) here
= wkNeg (step id) ⊢Γ∙A nA
lookupNegative ⊢Γ∙A@(⊢Γ ∙ Γ⊢A) (nΓ ∙ nA) (there h)
= wkNeg (step id) ⊢Γ∙A (lookupNegative ⊢Γ nΓ h)
-- Main results
---------------------------------------------------------------------------
-- We assume a negative, consistent context.
module Main (nΓ : NegativeContext Γ) (consistent : ∀{t} → Γ ⊢ t ∷ Empty → ⊥) where
-- Lemma: A neutral has negative type in a consistent negative context.
neNeg : (d : Γ ⊢ u ∷ A) (n : NfNeutral u) → NegativeType Γ A
neNeg (var ⊢Γ h ) (var _ ) = lookupNegative ⊢Γ nΓ h
neNeg (d ∘ⱼ ⊢t ) (∘ₙ n _ ) = appNeg (neNeg d n) (refl (syntacticTerm d)) ⊢t
neNeg (fstⱼ ⊢A A⊢B d ) (fstₙ n ) = fstNeg (neNeg d n) (refl (Σⱼ ⊢A ▹ A⊢B))
neNeg (sndⱼ ⊢A A⊢B d ) (sndₙ n ) = sndNeg (neNeg d n) (refl (Σⱼ ⊢A ▹ A⊢B)) (fstⱼ ⊢A A⊢B d)
neNeg (natrecⱼ _ _ _ d) (natrecₙ _ _ _ n ) = ⊥-elim (¬negℕ (neNeg d n) ⊢ℕ) where ⊢ℕ = refl (ℕⱼ (wfTerm d))
neNeg (Emptyrecⱼ _ d ) (Emptyrecₙ _ _ ) = ⊥-elim (consistent d)
neNeg (conv d c ) n = conv (neNeg d n) c
-- Lemma: A normal form of type ℕ is a numeral in a consistent negative context.
nfN : (d : Γ ⊢ u ∷ A)
→ (n : Nf u)
→ (c : Γ ⊢ A ≡ ℕ)
→ Numeral u
-- Case: neutrals. The type cannot be ℕ since it must be negative.
nfN d (ne n) c = ⊥-elim (¬negℕ (neNeg d n) c)
-- Case: numerals.
nfN (zeroⱼ x) zeroₙ c = zeroₙ
nfN (sucⱼ d) (sucₙ n) c = sucₙ (nfN d n c)
-- Case: conversion.
nfN (conv d c) n c' = nfN d n (trans c c')
-- Impossible cases: type is not ℕ.
-- * Canonical types
nfN (Πⱼ _ ▹ _) (Πₙ _ _) c = ⊥-elim (U≢ℕ c)
nfN (Σⱼ _ ▹ _) (Σₙ _ _) c = ⊥-elim (U≢ℕ c)
nfN (ℕⱼ _) ℕₙ c = ⊥-elim (U≢ℕ c)
nfN (Emptyⱼ _) Emptyₙ c = ⊥-elim (U≢ℕ c)
nfN (Unitⱼ _) Unitₙ c = ⊥-elim (U≢ℕ c)
-- * Canonical forms
nfN (lamⱼ _ _) (lamₙ _) c = ⊥-elim (ℕ≢Π (sym c))
nfN (prodⱼ _ _ _ _) (prodₙ _ _) c = ⊥-elim (ℕ≢Σ (sym c))
nfN (starⱼ _) starₙ c = ⊥-elim (ℕ≢Unitⱼ (sym c))
-- q.e.d
-- Canonicity theorem: Any well-typed term Γ ⊢ t : ℕ is convertible to a numeral.
thm : (⊢t : Γ ⊢ t ∷ ℕ) → ∃ λ u → Numeral u × Γ ⊢ t ≡ u ∷ ℕ
thm ⊢t with fullRedTerm (completeEqTerm (refl ⊢t))
... | u , nf , eq = u , nfN (proj₂ (proj₂ (syntacticEqTerm eq))) nf (refl (ℕⱼ (wfTerm ⊢t))) , eq
-- Q.E.D. 2021-05-27
|
{
"alphanum_fraction": 0.5711343038,
"avg_line_length": 32.9502262443,
"ext": "agda",
"hexsha": "547c75729487b6d3dc677cb7db2a1402e3e7932d",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-11-27T15:58:33.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-10-18T14:18:20.000Z",
"max_forks_repo_head_hexsha": "8bae792e335fb6b04ae2d8e162d472aa84c10343",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mr-ohman/logrel-ml",
"max_forks_repo_path": "Application/NegativeAxioms/Canonicity.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "8bae792e335fb6b04ae2d8e162d472aa84c10343",
"max_issues_repo_issues_event_max_datetime": "2021-02-22T10:37:24.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-22T12:49:23.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mr-ohman/logrel-ml",
"max_issues_repo_path": "Application/NegativeAxioms/Canonicity.agda",
"max_line_length": 108,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "8bae792e335fb6b04ae2d8e162d472aa84c10343",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mr-ohman/logrel-ml",
"max_stars_repo_path": "Application/NegativeAxioms/Canonicity.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:01:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-20T03:05:21.000Z",
"num_tokens": 2851,
"size": 7282
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Discrete where
open import Level
open import Data.Unit
open import Function
open import Relation.Binary.PropositionalEquality as ≡
open import Categories.Category
open import Categories.Functor
Discrete : ∀ {a} (A : Set a) → Category a a a
Discrete A = record
{ Obj = A
; _⇒_ = _≡_
; _≈_ = _≡_
; id = refl
; _∘_ = flip ≡.trans
; assoc = λ {_ _ _ _ g} → sym (trans-assoc g)
; sym-assoc = λ {_ _ _ _ g} → trans-assoc g
; identityˡ = λ {_ _ f} → trans-reflʳ f
; identityʳ = refl
; identity² = refl
; equiv = isEquivalence
; ∘-resp-≈ = λ where
refl refl → refl
}
module _ {a o ℓ e} {A : Set a} (C : Category o ℓ e) where
open Category C renaming (id to one)
module _ (f : A → Obj) where
lift-func : Functor (Discrete A) C
lift-func = record
{ F₀ = f
; F₁ = λ { refl → one }
; identity = Equiv.refl
; homomorphism = λ { {_} {_} {_} {refl} {refl} → Equiv.sym identity² }
; F-resp-≈ = λ { {_} {_} {refl} refl → Equiv.refl }
}
|
{
"alphanum_fraction": 0.5569285084,
"avg_line_length": 26.9761904762,
"ext": "agda",
"hexsha": "1ee8b52c3c76d22bc329446faccbf4527d45b045",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Discrete.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Discrete.agda",
"max_line_length": 76,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Discrete.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": 390,
"size": 1133
}
|
{-# OPTIONS --without-K #-}
module Equivalence where
open import Homotopy
open import PathOperations
open import Types
infix 1 _≃_
qinv : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B) → Set _
qinv {A = A} {B = B} f =
Σ (B → A) λ g → (f ∘ g ∼ id) × (g ∘ f ∼ id)
isequiv : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B) → Set _
isequiv {A = A} {B = B} f
= (Σ (B → A) λ g → f ∘ g ∼ id)
× (Σ (B → A) λ h → h ∘ f ∼ id)
_≃_ : ∀ {a b} (A : Set a) (B : Set b) → Set _
A ≃ B = Σ (A → B) isequiv
qi→eq : ∀ {a b} {A : Set a} {B : Set b}
{f : A → B} → qinv f → isequiv f
qi→eq (g , p , q) = (g , p) , (g , q)
eq→qi : ∀ {a b} {A : Set a} {B : Set b}
{f : A → B} → isequiv f → qinv f
eq→qi {f = f} ((g , p) , (h , q)) =
g , p , λ _ → q _ ⁻¹ · ap h (p _) · q _
≡→eq : ∀ {ℓ} {A : Set ℓ} {B : Set ℓ} → A ≡ B → A ≃ B
≡→eq p
= tr id p
, (tr id (p ⁻¹) , λ b → J
(λ _ B p → (b : B) → tr id p (tr id (p ⁻¹) b) ≡ b)
(λ _ _ → refl)
_ _ p b)
, (tr id (p ⁻¹) , λ a → J
(λ A _ p → (a : A) → tr id (p ⁻¹) (tr id p a) ≡ a)
(λ _ _ → refl)
_ _ p a)
refl-equiv : ∀ {a} {A : Set a} → A ≃ A
refl-equiv = id , (id , λ _ → refl) , (id , λ _ → refl)
sym-equiv : ∀ {a b} {A : Set a} {B : Set b} →
A ≃ B → B ≃ A
sym-equiv (f , (g , p) , (h , q))
= g
, (f , λ _ → q _ ⁻¹ · ap h (p _) · q _)
, (f , p)
trans-equiv : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
A ≃ B → B ≃ C → A ≃ C
trans-equiv
(f₁ , (g₁ , p₁) , (h₁ , q₁)) (f₂ , (g₂ , p₂) , (h₂ , q₂))
= f₂ ∘ f₁
, (g₁ ∘ g₂ , λ _ → ap f₂ (p₁ _) · p₂ _)
, (h₁ ∘ h₂ , λ _ → ap h₁ (q₂ _) · q₁ _)
|
{
"alphanum_fraction": 0.3977344242,
"avg_line_length": 25.6290322581,
"ext": "agda",
"hexsha": "33154bffbe1e68e0e32dc857033a0e66e4ea8eb0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/Equivalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/Equivalence.agda",
"max_line_length": 61,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/Equivalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 821,
"size": 1589
}
|
module RTN where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
{-# BUILTIN SUC suc #-}
{-# BUILTIN ZERO zero #-}
|
{
"alphanum_fraction": 0.5521472393,
"avg_line_length": 16.3,
"ext": "agda",
"hexsha": "7f0facb8ec611c148f7c8972fc751260bc16982c",
"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": "src/rts/RTN.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": "src/rts/RTN.agda",
"max_line_length": 29,
"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": "src/rts/RTN.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": 51,
"size": 163
}
|
{-# OPTIONS --without-K #-}
open import Data.Nat
open import Data.List using (List ; [] ; _∷_ ; length) renaming (_++_ to _++L_ )
open import Data.Vec using (Vec ; [] ; _∷_ ) renaming (_++_ to _++V_ )
open import Data.Fin hiding (_+_ ; _≤_ )
open import Data.Product
open import Data.Maybe
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Algebra
open import Level renaming (zero to lzero ; suc to lsuc)
open import Function using () renaming (case_of_ to CASE_OF_)
data Multiplicity : Set where
one : Multiplicity
omega : Multiplicity
-- Multiplicities with 0.
-- This is a deviation from the papers. Having 0 is convenient for handling uses of variables.
data Multiplicity₀ : Set where
zero : Multiplicity₀
one : Multiplicity₀
omega : Multiplicity₀
-- Embedding
M→M₀ : Multiplicity -> Multiplicity₀
M→M₀ one = one
M→M₀ omega = omega
-- Instead of having constructors, we have (additive) sums and
-- (multiplicative) products, together with iso-recursive types. The
-- type constructor Many can be used for representing non-linear
-- constructors.
data Ty : ℕ -> Set where
_⊕_ : ∀ {n} -> Ty n -> Ty n -> Ty n
tunit : ∀ {n} -> Ty n
_⊗_ : ∀ {n} -> Ty n -> Ty n -> Ty n
Many : ∀ {n} -> Multiplicity -> Ty n -> Ty n
_#_~>_ : ∀ {n} -> Ty n -> Multiplicity -> Ty n -> Ty n
_● : ∀ {n} -> Ty n -> Ty n
μ_ : ∀ {n} -> Ty (suc n) -> Ty n
tvar : ∀ {n} -> Fin n -> Ty n
_↔_ : ∀ {n} -> Ty n -> Ty n -> Ty n
_⊸_ : ∀ {n} -> Ty n -> Ty n -> Ty n
t ⊸ t' = t # one ~> t'
infixr 4 _⊗_
infixr 1 _⊕_
infixr 0 _#_~>_
infixr 0 _⊸_
tbool : Ty zero
tbool = tunit ⊕ tunit
module _ where
-- Several properties to handle recursive types.
open import Data.Nat.Properties
private
lemma : ∀ {m n} -> m ≤ n -> ∃[ k ] (k + m ≡ n)
lemma {n = n} z≤n = n , +-identityʳ n
lemma (s≤s r) with lemma r
... | k , refl = k , +-suc k _
weakenVarK : ∀ {m n k} -> k + m ≡ n -> Fin m -> Fin (k + m)
weakenVarK {k = zero} refl x = x
weakenVarK {n = suc n} {suc k} eq x = suc (weakenVarK {n = n} {k = k} (suc-injective eq) x)
weakenVar : ∀ {m n} -> m ≤ n -> Fin m -> Fin n
weakenVar r x with lemma r
... | k , r' = subst Fin r' (weakenVarK r' x)
substTyVar : ∀ {m n k} -> m + n ≤ k -> Fin (m + suc n) -> Ty k -> Ty k
substTyVar {zero} r zero t = t
substTyVar {zero} r (suc x) t = tvar (weakenVar r x)
substTyVar {suc m} {k = suc k} r zero t = tvar zero
substTyVar {suc m} (s≤s r) (suc x) t = substTyVar {m} (≤-trans r (≤-step ≤-refl)) x t
weaken : ∀ {m n} -> m ≤ n -> Ty m -> Ty n
weaken r (t ⊕ t₁) = weaken r t ⊕ weaken r t₁
weaken r tunit = tunit
weaken r (t ⊗ t₁) = weaken r t ⊗ weaken r t₁
weaken r (Many x t) = Many x (weaken r t)
weaken r (t # x ~> t₁) = weaken r t # x ~> weaken r t₁
weaken r (t ●) = weaken r t ●
weaken r (μ t) = μ (weaken (s≤s r) t)
weaken r (tvar x) = tvar (weakenVar r x)
weaken r (t₁ ↔ t₂) = weaken r t₁ ↔ weaken r t₂
substTyGen : ∀ {m n} -> Ty (m + suc n) -> Ty (m + n) -> Ty (m + n)
substTyGen (s₁ ⊕ s₂) t = substTyGen s₁ t ⊕ substTyGen s₂ t
substTyGen tunit t = tunit
substTyGen (s₁ ⊗ s₂) t = substTyGen s₁ t ⊗ substTyGen s₂ t
substTyGen (Many x s) t = Many x (substTyGen s t)
substTyGen (s # x ~> s₁) t = substTyGen s t # x ~> substTyGen s₁ t
substTyGen (s ●) t = (substTyGen s t) ●
substTyGen {m} (μ s) t = μ (substTyGen {m = suc m} s (weaken (n≤1+n _) t))
substTyGen (tvar x) t = substTyVar ≤-refl x t
substTyGen (s₁ ↔ s₂) t = substTyGen s₁ t ↔ substTyGen s₂ t
substTy : ∀ {n} -> Ty (suc n) -> Ty n -> Ty n
substTy = substTyGen {zero}
module TyExamples where
nat : ∀ {n} -> Ty n
nat = μ (tunit ⊕ tvar zero)
natlist : ∀ {n} -> Ty n
natlist = μ (tunit ⊕ (nat ⊗ tvar zero))
-- Instead of using environments that maps variables to pairs of types
-- and multiplicities, we use two sort of environments: one maps
-- variables to types and the other maps variables to multiplicities.
--
-- We will use de Bruijn indices for variables, and thus type
-- environments are represented as a list of types. The treatment of
-- multiplicity environment is similar but we assume that it has the
-- same length with the corresponding type environment; so we use Vec
-- for multiplicity environments.
TyEnv : Set
TyEnv = List (Ty zero)
MultEnv : ∀ ℕ -> Set
MultEnv n = Vec Multiplicity₀ n
-----------------------------------------------------------------------------
-- Operations and properties for multiplicities
mul : Multiplicity -> Multiplicity -> Multiplicity
mul one y = y
mul omega y = omega
mul₀ : Multiplicity₀ -> Multiplicity₀ -> Multiplicity₀
mul₀ zero y = zero
mul₀ one y = y
mul₀ omega zero = zero
mul₀ omega one = omega
mul₀ omega omega = omega
mul₀-m-zero : ∀ m -> mul₀ m zero ≡ zero
mul₀-m-zero zero = refl
mul₀-m-zero one = refl
mul₀-m-zero omega = refl
_×ₘ_ : ∀{n} -> Multiplicity -> MultEnv n -> MultEnv n
m ×ₘ Γ = Data.Vec.map (mul₀ (M→M₀ m)) Γ
add₀ : Multiplicity₀ -> Multiplicity₀ -> Multiplicity₀
add₀ zero m = m
add₀ one zero = one
add₀ one one = omega
add₀ one omega = omega
add₀ omega _ = omega
add₀-m-zero : ∀ m -> add₀ m zero ≡ m
add₀-m-zero zero = refl
add₀-m-zero one = refl
add₀-m-zero omega = refl
add₀-comm : ∀ x y -> add₀ x y ≡ add₀ y x
add₀-comm zero zero = refl
add₀-comm zero one = refl
add₀-comm zero omega = refl
add₀-comm one zero = refl
add₀-comm one one = refl
add₀-comm one omega = refl
add₀-comm omega zero = refl
add₀-comm omega one = refl
add₀-comm omega omega = refl
add₀-assoc : ∀ x y z -> add₀ (add₀ x y) z ≡ add₀ x (add₀ y z)
add₀-assoc zero y z = refl
add₀-assoc one zero z = refl
add₀-assoc one one zero = refl
add₀-assoc one one one = refl
add₀-assoc one one omega = refl
add₀-assoc one omega z = refl
add₀-assoc omega y z = refl
mul₀-dist-add₀ : ∀ x y z -> mul₀ x (add₀ y z) ≡ add₀ (mul₀ x y) (mul₀ x z)
mul₀-dist-add₀ zero y z = refl
mul₀-dist-add₀ one y z = refl
mul₀-dist-add₀ omega zero z = refl
mul₀-dist-add₀ omega one zero = refl
mul₀-dist-add₀ omega one one = refl
mul₀-dist-add₀ omega one omega = refl
mul₀-dist-add₀ omega omega z = refl
-----------------------------------------------------------------------------
-- Operations and properties for multiplicity environments
infixr 7 _×ₘ_
infixl 6 _+ₘ_
_+ₘ_ : ∀ {n} -> MultEnv n -> MultEnv n -> MultEnv n
[] +ₘ [] = []
(m₁ ∷ Δ₁) +ₘ (m₂ ∷ Δ₂) = add₀ m₁ m₂ ∷ (Δ₁ +ₘ Δ₂)
+ₘ-comm : ∀ {n} -> ∀ (Δ₁ Δ₂ : MultEnv n) -> Δ₁ +ₘ Δ₂ ≡ Δ₂ +ₘ Δ₁
+ₘ-comm [] [] = refl
+ₘ-comm (x₁ ∷ Δ₁) (x₂ ∷ Δ₂) =
begin
add₀ x₁ x₂ ∷ Δ₁ +ₘ Δ₂
≡⟨ cong (_∷ Δ₁ +ₘ Δ₂) (add₀-comm x₁ x₂) ⟩
add₀ x₂ x₁ ∷ Δ₁ +ₘ Δ₂
≡⟨ cong (add₀ x₂ x₁ ∷_) (+ₘ-comm Δ₁ Δ₂) ⟩
add₀ x₂ x₁ ∷ Δ₂ +ₘ Δ₁
∎
+ₘ-assoc : ∀ {n} -> ∀ (Δ₁ Δ₂ Δ₃ : MultEnv n) ->
(Δ₁ +ₘ Δ₂) +ₘ Δ₃ ≡ Δ₁ +ₘ (Δ₂ +ₘ Δ₃)
+ₘ-assoc [] [] [] = refl
+ₘ-assoc (x₁ ∷ Δ₁) (x₂ ∷ Δ₂) (x₃ ∷ Δ₃) =
begin
add₀ (add₀ x₁ x₂) x₃ ∷ Δ₁ +ₘ Δ₂ +ₘ Δ₃
≡⟨ cong₂ (_∷_) (add₀-assoc x₁ x₂ _) (+ₘ-assoc Δ₁ Δ₂ _) ⟩
add₀ x₁ (add₀ x₂ x₃) ∷ Δ₁ +ₘ (Δ₂ +ₘ Δ₃)
∎
-- The multiplicity environment that maps all variables into 0.
∅ : ∀ {n} -> MultEnv n
∅ = Data.Vec.replicate zero
∅-lid : ∀ {n} (Δ : MultEnv n) -> ∅ +ₘ Δ ≡ Δ
∅-lid [] = refl
∅-lid (x ∷ Δ) = cong (x ∷_) (∅-lid Δ)
∅-rid : ∀ {n} (Δ : MultEnv n) -> Δ +ₘ ∅ ≡ Δ
∅-rid [] = refl
∅-rid (x ∷ Δ) = cong₂ (_∷_) (add₀-m-zero x) (∅-rid Δ)
+ₘ-commutativeMonoid : ∀ (n : ℕ) -> CommutativeMonoid 0ℓ 0ℓ
+ₘ-commutativeMonoid n = record
{ Carrier = MultEnv n
; _≈_ = _≡_
; _∙_ = _+ₘ_
; ε = ∅
; isCommutativeMonoid = record { isMonoid = +ₘ-isMonoid ; comm = +ₘ-comm }
-- record {
-- isSemigroup = record { isMagma = record { isEquivalence = Relation.Binary.PropositionalEquality.isEquivalence ;
-- ∙-cong = cong₂ (_+ₘ_) } ;
-- assoc = +ₘ-assoc } ;
-- ; identityˡ = ∅-lid
-- ; comm = +ₘ-comm }
}
where
+ₘ-isMonoid : IsMonoid _≡_ _+ₘ_ ∅
+ₘ-isMonoid = record { isSemigroup = record { isMagma = record { isEquivalence = Relation.Binary.PropositionalEquality.isEquivalence ; ∙-cong = cong₂ (_+ₘ_) } ; assoc = +ₘ-assoc } ; identity = ∅-lid , ∅-rid }
+ₘ-transpose :
∀ {n} (Δ₁ Δ₂ Δ₃ Δ₄ : MultEnv n) ->
((Δ₁ +ₘ Δ₂) +ₘ (Δ₃ +ₘ Δ₄)) ≡ ((Δ₁ +ₘ Δ₃) +ₘ (Δ₂ +ₘ Δ₄))
+ₘ-transpose Δ₁ Δ₂ Δ₃ Δ₄ =
begin
(Δ₁ +ₘ Δ₂) +ₘ (Δ₃ +ₘ Δ₄)
≡⟨ +ₘ-assoc Δ₁ Δ₂ _ ⟩
Δ₁ +ₘ (Δ₂ +ₘ (Δ₃ +ₘ Δ₄))
≡⟨ cong (Δ₁ +ₘ_) (+ₘ-comm Δ₂ _) ⟩
(Δ₁ +ₘ ((Δ₃ +ₘ Δ₄) +ₘ Δ₂))
≡⟨ cong (Δ₁ +ₘ_) (+ₘ-assoc Δ₃ Δ₄ _) ⟩
(Δ₁ +ₘ (Δ₃ +ₘ (Δ₄ +ₘ Δ₂)))
≡⟨ cong (Δ₁ +ₘ_) (cong (Δ₃ +ₘ_) (+ₘ-comm Δ₄ _)) ⟩
(Δ₁ +ₘ (Δ₃ +ₘ (Δ₂ +ₘ Δ₄)))
≡⟨ sym (+ₘ-assoc Δ₁ Δ₃ _) ⟩
((Δ₁ +ₘ Δ₃) +ₘ (Δ₂ +ₘ Δ₄))
∎
one×ₘ : ∀ {n} (Δ : MultEnv n) -> one ×ₘ Δ ≡ Δ
one×ₘ [] = refl
one×ₘ (x ∷ Δ) = cong (_∷_ x) (one×ₘ Δ)
×ₘ∅ : ∀ {n} m -> m ×ₘ ∅ {n} ≡ ∅ {n}
×ₘ∅ {zero} m = refl
×ₘ∅ {suc n} one = cong (_∷_ zero) (×ₘ∅ one)
×ₘ∅ {suc n} omega = cong (_∷_ zero) (×ₘ∅ omega)
omega×ₘm×ₘ-omega×ₘ : ∀ {n} (m : Multiplicity) (Δ : MultEnv n) -> omega ×ₘ m ×ₘ Δ ≡ omega ×ₘ Δ
omega×ₘm×ₘ-omega×ₘ {zero} m [] = refl
omega×ₘm×ₘ-omega×ₘ {suc n} m (zero ∷ Δ) rewrite mul₀-m-zero (M→M₀ m) = cong (zero ∷_) (omega×ₘm×ₘ-omega×ₘ {n} m Δ)
omega×ₘm×ₘ-omega×ₘ {suc n} one (one ∷ Δ) = cong (omega ∷_) (omega×ₘm×ₘ-omega×ₘ {n} one Δ)
omega×ₘm×ₘ-omega×ₘ {suc n} omega (one ∷ Δ) = cong (omega ∷_) (omega×ₘm×ₘ-omega×ₘ {n} omega Δ)
omega×ₘm×ₘ-omega×ₘ {suc n} one (omega ∷ Δ) = cong (omega ∷_) (omega×ₘm×ₘ-omega×ₘ {n} one Δ)
omega×ₘm×ₘ-omega×ₘ {suc n} omega (omega ∷ Δ) = cong (omega ∷_) (omega×ₘm×ₘ-omega×ₘ {n} omega Δ)
mul-×ₘ : ∀ {n} m₁ m₂ (Δ : MultEnv n) -> mul m₁ m₂ ×ₘ Δ ≡ m₁ ×ₘ (m₂ ×ₘ Δ)
mul-×ₘ one m₂ Δ = sym (one×ₘ _)
mul-×ₘ omega m₂ Δ = sym (omega×ₘm×ₘ-omega×ₘ m₂ Δ)
module _ where
open import Data.Vec.Properties
omega×ₘ∅-inv : ∀ {n} (Δ : MultEnv n) -> omega ×ₘ Δ ≡ ∅ -> Δ ≡ ∅
omega×ₘ∅-inv [] eq = refl
omega×ₘ∅-inv (x ∷ Δ) eq with ∷-injective eq
omega×ₘ∅-inv (zero ∷ Δ) eq | eq₁ , eq₂ = cong (zero ∷_) (omega×ₘ∅-inv Δ eq₂)
add₀-0-0-inv : ∀ x y -> add₀ x y ≡ zero -> x ≡ zero × y ≡ zero
add₀-0-0-inv zero zero eq = refl , refl
add₀-0-0-inv one zero ()
add₀-0-0-inv one one ()
add₀-0-0-inv one omega ()
∅+ₘ∅-inv : ∀ {n} (Δ₁ Δ₂ : MultEnv n) -> Δ₁ +ₘ Δ₂ ≡ ∅ -> Δ₁ ≡ ∅ × Δ₂ ≡ ∅
∅+ₘ∅-inv [] [] eq = refl , refl
∅+ₘ∅-inv (x₁ ∷ Δ₁) (x₂ ∷ Δ₂) eq with ∷-injective eq
... | eq₁ , eq₂ with add₀-0-0-inv x₁ x₂ eq₁ | ∅+ₘ∅-inv Δ₁ Δ₂ eq₂
... | refl , refl | refl , refl = refl , refl
×ₘ-dist : ∀ {n} m (Δ₁ Δ₂ : MultEnv n) ->
(m ×ₘ (Δ₁ +ₘ Δ₂)) ≡ (m ×ₘ Δ₁) +ₘ (m ×ₘ Δ₂)
×ₘ-dist m [] [] = refl
×ₘ-dist m (x₁ ∷ Δ₁) (x₂ ∷ Δ₂) =
cong₂ (_∷_) (mul₀-dist-add₀ (M→M₀ m) x₁ x₂) (×ₘ-dist m Δ₁ Δ₂)
×ₘ-split : ∀ {n} m (Δ : MultEnv n) -> ∃[ Δ' ] (m ×ₘ Δ ≡ Δ +ₘ Δ' )
×ₘ-split m [] = [] , refl
×ₘ-split m (x ∷ Δ) with ×ₘ-split m Δ
×ₘ-split one (x ∷ Δ) | Δ' , eq = zero ∷ Δ' , cong₂ (_∷_) (sym (add₀-m-zero x)) eq
×ₘ-split omega (zero ∷ Δ) | Δ' , eq = zero ∷ Δ' , cong (_∷_ zero) eq
×ₘ-split omega (one ∷ Δ) | Δ' , eq = one ∷ Δ' , cong (_∷_ omega) eq
×ₘ-split omega (omega ∷ Δ) | Δ' , eq = one ∷ Δ' , cong (_∷_ omega) eq
-----------------------------------------------------------------------------
-- Constraints on multiplicity environments
open import Data.Vec.Relation.Unary.All
-- all-zero Δ essentially asserts that Δ is ∅
all-zero : ∀ {n} -> Vec Multiplicity₀ n -> Set
all-zero = All (λ x -> x ≡ zero)
all-zero-∅ : ∀ {n} -> all-zero {n} ∅
all-zero-∅ {zero} = []
all-zero-∅ {suc n} = refl ∷ all-zero-∅ {n}
all-zero-∅-inv : ∀ {n} -> (Δ : MultEnv n) -> all-zero {n} Δ -> Δ ≡ ∅
all-zero-∅-inv .[] [] = refl
all-zero-∅-inv .(zero ∷ _) (refl ∷ az) = cong (_∷_ zero) (all-zero-∅-inv _ az)
data no-omega : (m : Multiplicity₀) -> Set where
zero : no-omega zero
one : no-omega one
no-omega-dist : ∀ x y -> no-omega (add₀ x y) -> no-omega x × no-omega y
no-omega-dist zero y noω = zero , noω
no-omega-dist one zero noω = one , zero
-- all-no-omega Δ asserts that Δ(x) cannot be omega.
all-no-omega : ∀ {n} -> Vec Multiplicity₀ n -> Set
all-no-omega = All no-omega
-- Several properties of all-no-omega.
all-no-omega-∅ : ∀ {n} -> all-no-omega (∅ {n})
all-no-omega-∅ {zero} = []
all-no-omega-∅ {suc n} = zero ∷ all-no-omega-∅
all-no-omega-dist : ∀ {n} (Δ₁ Δ₂ : MultEnv n) -> all-no-omega (Δ₁ +ₘ Δ₂) ->
all-no-omega Δ₁ × all-no-omega Δ₂
all-no-omega-dist [] [] ano = [] , []
all-no-omega-dist (x₁ ∷ Δ₁) (x₂ ∷ Δ₂) (noω ∷ ano)
with no-omega-dist x₁ x₂ noω | all-no-omega-dist Δ₁ Δ₂ ano
... | no₁ , no₂ | ano₁ , ano₂ = no₁ ∷ ano₁ , no₂ ∷ ano₂
all-no-omega-dist-×ₘ :
∀ {n} m (Δ : MultEnv n) ->
all-no-omega (m ×ₘ Δ) -> all-no-omega Δ
all-no-omega-dist-×ₘ m [] ano = []
all-no-omega-dist-×ₘ one (x ∷ Δ) (px ∷ ano) = px ∷ (all-no-omega-dist-×ₘ one Δ ano)
all-no-omega-dist-×ₘ omega (zero ∷ Δ) (px ∷ ano) = zero ∷ all-no-omega-dist-×ₘ omega Δ ano
all-no-omega-weaken-right :
∀ {n} {Δ₁ Δ₂ : MultEnv n} {m} ->
all-no-omega (Δ₁ +ₘ m ×ₘ Δ₂) -> all-no-omega (Δ₁ +ₘ Δ₂)
all-no-omega-weaken-right {Δ₁ = Δ₁} {Δ₂} {m} ano with ×ₘ-split m Δ₂
... | Δ' , eq with all-no-omega-dist (Δ₁ +ₘ Δ₂) Δ' (subst all-no-omega lemma ano)
where
lemma : Δ₁ +ₘ m ×ₘ Δ₂ ≡ Δ₁ +ₘ Δ₂ +ₘ Δ'
lemma = begin
Δ₁ +ₘ m ×ₘ Δ₂
≡⟨ cong (Δ₁ +ₘ_) eq ⟩
Δ₁ +ₘ (Δ₂ +ₘ Δ')
≡⟨ sym (+ₘ-assoc Δ₁ Δ₂ _) ⟩
Δ₁ +ₘ Δ₂ +ₘ Δ'
∎
... | ano₁ , _ = ano₁
all-no-omega-omega×ₘ : ∀ {n} (Δ : MultEnv n) -> all-no-omega (omega ×ₘ Δ) -> Δ ≡ ∅
all-no-omega-omega×ₘ [] ano = refl
all-no-omega-omega×ₘ (zero ∷ Δ) (px ∷ ano) = cong (_∷_ zero) (all-no-omega-omega×ₘ Δ ano)
-----------------------------------------------------------------------------
-- Variables, or de Bruijn indices
data _∋_ : ∀ TyEnv -> Ty zero -> Set where
vz : ∀ {Γ : TyEnv} {a : Ty zero} -> (a ∷ Γ) ∋ a
vs : ∀ {Γ : TyEnv} {a b : Ty zero} -> Γ ∋ a -> (b ∷ Γ) ∋ a
-- 'discardable' means that a corresponding variable need not be used.
data discardable : Multiplicity₀ -> Set where
omega : discardable omega
zero : discardable zero
omega×ₘ-discardable : ∀ {n} (Δ : MultEnv n) -> All discardable (omega ×ₘ Δ)
omega×ₘ-discardable [] = []
omega×ₘ-discardable (zero ∷ Δ) = zero ∷ omega×ₘ-discardable Δ
omega×ₘ-discardable (one ∷ Δ) = omega ∷ omega×ₘ-discardable Δ
omega×ₘ-discardable (omega ∷ Δ) = omega ∷ omega×ₘ-discardable Δ
-- 'usable' means that a corresponding variable can be used.
data usable : Multiplicity₀ -> Set where
omega : usable omega
one : usable one
-- varOk means that the use of variable x in Γ is compatible with Δ; that is,
-- x is usable in Δ and other variables must be discardable in Δ.
data varOk : (Γ : TyEnv) {a : Ty zero} -> Γ ∋ a -> (Δ : MultEnv (length Γ)) -> Set where
there :
∀ {Γ : TyEnv} {m a b} {x : Γ ∋ a} {Δ} ->
(d : discardable m) ->
(ok : varOk Γ x Δ) ->
varOk (b ∷ Γ) (vs x) (m ∷ Δ)
here :
∀ {Γ : TyEnv} {a} {Δ} {m} ->
(u : usable m) ->
(ad : All discardable Δ) ->
varOk (a ∷ Γ) vz (m ∷ Δ)
-- varOk● is similar to varOk but is for invertible variables. The definition is simplified as
-- we assume Ξ cannot contain omega.
data varOk● : (Θ : TyEnv) {a : Ty zero} -> Θ ∋ a -> (Ξ : MultEnv (length Θ)) -> Set where
there :
∀ {Θ : TyEnv} {a b} {x : Θ ∋ a} {Ξ} ->
(ok : varOk● Θ x Ξ) ->
varOk● (b ∷ Θ) (vs x) (zero ∷ Ξ)
here :
∀ {Θ : TyEnv} {a} {Ξ} ->
(ad : all-zero Ξ) ->
varOk● (a ∷ Θ) vz (one ∷ Ξ)
-- Now, we are ready to define the intrinsically-typed syntax of Sparcl.
data Term : ∀ (Γ : TyEnv) -> MultEnv (length Γ) -> (Θ : TyEnv) -> MultEnv (length Θ) -> Ty zero -> Set where
var :
∀ {Γ Δ Θ A} ->
(x : Γ ∋ A) -> (ok : varOk Γ x Δ) ->
Term Γ Δ Θ ∅ A
abs :
∀ {Γ Δ Θ Ξ A B} -> (m : Multiplicity) ->
Term (A ∷ Γ) (M→M₀ m ∷ Δ) Θ Ξ B ->
Term Γ Δ Θ Ξ (A # m ~> B)
app :
∀ {Γ Δ₁ Δ₂ Θ Ξ₁ Ξ₂ A B m} ->
Term Γ Δ₁ Θ Ξ₁ (A # m ~> B) ->
Term Γ Δ₂ Θ Ξ₂ A ->
Term Γ (Δ₁ +ₘ m ×ₘ Δ₂) Θ (Ξ₁ +ₘ m ×ₘ Ξ₂) B
unit :
∀ {Γ Δ Θ} ->
(ad : All discardable Δ) ->
Term Γ Δ Θ ∅ tunit
letunit :
∀ {Γ Δ₀ Δ Θ Ξ₀ Ξ A} ->
(m : Multiplicity) ->
Term Γ Δ₀ Θ Ξ₀ tunit ->
Term Γ Δ Θ Ξ A ->
Term Γ (m ×ₘ Δ₀ +ₘ Δ) Θ (m ×ₘ Ξ₀ +ₘ Ξ) A
pair :
∀ {Γ Δ₁ Δ₂ Θ Ξ₁ Ξ₂ A B} ->
Term Γ Δ₁ Θ Ξ₁ A ->
Term Γ Δ₂ Θ Ξ₂ B ->
Term Γ (Δ₁ +ₘ Δ₂) Θ (Ξ₁ +ₘ Ξ₂) (A ⊗ B)
letpair :
∀ {Γ Δ₀ Δ Θ Ξ₀ Ξ A B C} ->
(m : Multiplicity) ->
Term Γ Δ₀ Θ Ξ₀ (A ⊗ B) ->
Term (A ∷ B ∷ Γ) (M→M₀ m ∷ M→M₀ m ∷ Δ) Θ Ξ C ->
Term Γ (m ×ₘ Δ₀ +ₘ Δ) Θ (m ×ₘ Ξ₀ +ₘ Ξ) C
many :
∀ {Γ Δ Θ Ξ A} ->
(m : Multiplicity) ->
Term Γ Δ Θ Ξ A ->
Term Γ (m ×ₘ Δ) Θ (m ×ₘ Ξ) (Many m A)
unmany :
∀ {Γ Δ₀ Δ Θ Ξ₀ Ξ m₀ A B} ->
(m : Multiplicity) ->
Term Γ Δ₀ Θ Ξ₀ (Many m₀ A) ->
Term (A ∷ Γ) (M→M₀ (mul m m₀) ∷ Δ) Θ Ξ B ->
Term Γ (m ×ₘ Δ₀ +ₘ Δ) Θ (m ×ₘ Ξ₀ +ₘ Ξ) B
inl :
∀ {Γ Δ Θ Ξ} {A B} ->
Term Γ Δ Θ Ξ A ->
Term Γ Δ Θ Ξ (A ⊕ B)
inr :
∀ {Γ Δ Θ Ξ} {A B} ->
Term Γ Δ Θ Ξ B ->
Term Γ Δ Θ Ξ (A ⊕ B)
case :
∀ {Γ Δ₀ Δ Θ Ξ₀ Ξ A B C} ->
(m : Multiplicity) ->
Term Γ Δ₀ Θ Ξ₀ (A ⊕ B) ->
Term (A ∷ Γ) (M→M₀ m ∷ Δ) Θ Ξ C ->
Term (B ∷ Γ) (M→M₀ m ∷ Δ) Θ Ξ C ->
Term Γ (m ×ₘ Δ₀ +ₘ Δ) Θ (m ×ₘ Ξ₀ +ₘ Ξ) C
roll :
∀ {Γ Δ Θ Ξ F} ->
Term Γ Δ Θ Ξ (substTy F (μ F)) ->
Term Γ Δ Θ Ξ (μ F)
unroll :
∀ {Γ Δ Θ Ξ F} ->
Term Γ Δ Θ Ξ (μ F) ->
Term Γ Δ Θ Ξ (substTy F (μ F))
unit● :
∀ {Γ Δ Θ} ->
(ad : All discardable Δ) ->
Term Γ Δ Θ ∅ (tunit ●)
letunit● :
∀ {Γ Δ₀ Δ Θ Ξ₀ Ξ A} ->
Term Γ Δ₀ Θ Ξ₀ (tunit ●) ->
Term Γ Δ Θ Ξ (A ●) ->
Term Γ (Δ₀ +ₘ Δ) Θ (Ξ₀ +ₘ Ξ) (A ●)
pair● :
∀ {Γ Δ₁ Δ₂ Θ Ξ₁ Ξ₂ A B} ->
Term Γ Δ₁ Θ Ξ₁ (A ●) ->
Term Γ Δ₂ Θ Ξ₂ (B ●) ->
Term Γ (Δ₁ +ₘ Δ₂) Θ (Ξ₁ +ₘ Ξ₂) ((A ⊗ B) ●)
letpair● :
∀ {Γ Δ₀ Δ Θ Ξ₀ Ξ A B C} ->
Term Γ Δ₀ Θ Ξ₀ ((A ⊗ B) ●) ->
Term Γ Δ (A ∷ B ∷ Θ) (one ∷ one ∷ Ξ) (C ●) ->
Term Γ (Δ₀ +ₘ Δ) Θ (Ξ₀ +ₘ Ξ) (C ●)
inl● :
∀ {Γ Δ Θ Ξ} {A B} ->
Term Γ Δ Θ Ξ (A ●) ->
Term Γ Δ Θ Ξ ((A ⊕ B) ●)
inr● :
∀ {Γ Δ Θ Ξ} {A B} ->
Term Γ Δ Θ Ξ (B ●) ->
Term Γ Δ Θ Ξ ((A ⊕ B) ●)
case● :
∀ {Γ Δ₀ Δ Δ' Θ Ξ₀ Ξ Ξ' A B C} ->
Term Γ Δ₀ Θ Ξ₀ ((A ⊕ B) ●) ->
Term Γ Δ (A ∷ Θ) (one ∷ Ξ) (C ●) ->
Term Γ Δ (B ∷ Θ) (one ∷ Ξ) (C ●) ->
Term Γ Δ' Θ Ξ' (C # omega ~> tbool) ->
Term Γ (Δ₀ +ₘ Δ +ₘ omega ×ₘ Δ') Θ (Ξ₀ +ₘ Ξ +ₘ omega ×ₘ Ξ') (C ●)
var● : ∀ {Γ Δ Θ Ξ A} ->
(x : Θ ∋ A) ->
(ad : All discardable Δ) -> varOk● Θ x Ξ ->
Term Γ Δ Θ Ξ (A ●)
pin : ∀ {Γ Δ₁ Δ₂ Θ Ξ₁ Ξ₂ A B} ->
Term Γ Δ₁ Θ Ξ₁ (A ●) ->
Term Γ Δ₂ Θ Ξ₂ (A # omega ~> B ●) ->
Term Γ (Δ₁ +ₘ Δ₂) Θ (Ξ₁ +ₘ Ξ₂) ((A ⊗ B) ●)
unlift :
∀ {Γ Δ Θ Ξ A B}
-> Term Γ Δ Θ Ξ (A ● ⊸ B ●)
-> Term Γ (omega ×ₘ Δ) Θ (omega ×ₘ Ξ) (A ↔ B)
fapp :
∀ {Γ Δ₁ Δ₂ Θ Ξ₁ Ξ₂ A B}
-> Term Γ Δ₁ Θ Ξ₁ (A ↔ B)
-> Term Γ Δ₂ Θ Ξ₂ A
-> Term Γ (Δ₁ +ₘ omega ×ₘ Δ₂) Θ (Ξ₁ +ₘ omega ×ₘ Ξ₂) B
bapp :
∀ {Γ Δ₁ Δ₂ Θ Ξ₁ Ξ₂ A B}
-> Term Γ Δ₁ Θ Ξ₁ (A ↔ B)
-> Term Γ Δ₂ Θ Ξ₂ B
-> Term Γ (Δ₁ +ₘ omega ×ₘ Δ₂) Θ (Ξ₁ +ₘ omega ×ₘ Ξ₂) A
-- fwd and bwd are obtained as derived constructs.
fwd :
∀ {Γ Δ₁ Δ₂ Θ Ξ₁ Ξ₂ A B} ->
Term Γ Δ₁ Θ Ξ₁ (A ● ⊸ B ●) ->
Term Γ Δ₂ Θ Ξ₂ A ->
Term Γ (omega ×ₘ Δ₁ +ₘ omega ×ₘ Δ₂) Θ (omega ×ₘ Ξ₁ +ₘ omega ×ₘ Ξ₂) B
fwd e1 e2 = fapp (unlift e1) e2
bwd :
∀ {Γ Δ₁ Δ₂ Θ Ξ₁ Ξ₂ A B} ->
Term Γ Δ₁ Θ Ξ₁ (A ● ⊸ B ●) ->
Term Γ Δ₂ Θ Ξ₂ B ->
Term Γ (omega ×ₘ Δ₁ +ₘ omega ×ₘ Δ₂) Θ (omega ×ₘ Ξ₁ +ₘ omega ×ₘ Ξ₂) A
bwd e1 e2 = bapp (unlift e1) e2
-- compatΘ Θ Ξ Θ' Ξ' asserts that environments ((Θ , Ξ) and
-- (Θ' , Ξ')) differ only in variables with multiplicity zero. That
-- is, (Θ , Ξ) and (Θ' , Ξ') denote the same environement in
-- paper's representation.
data compatΘ : (Θ : TyEnv) (Ξ : MultEnv (length Θ))
(Θ' : TyEnv) (Ξ' : MultEnv (length Θ')) -> Set where
compat-[] :
compatΘ [] [] [] []
compat-ext-here :
∀ {Θ Ξ Θ' Ξ' A} ->
compatΘ Θ Ξ Θ' Ξ' ->
compatΘ Θ Ξ (A ∷ Θ') (zero ∷ Ξ')
compat-reduce-here :
∀ {Θ Ξ Θ' Ξ' A} ->
compatΘ Θ Ξ Θ' Ξ' ->
compatΘ (A ∷ Θ) (zero ∷ Ξ) Θ' Ξ'
compat-skip :
∀ {Θ Ξ Θ' Ξ' A m } ->
compatΘ Θ Ξ Θ' Ξ' ->
compatΘ (A ∷ Θ) (m ∷ Ξ) (A ∷ Θ') (m ∷ Ξ')
-- Some useful examples of compatΘ
ext-id : ∀ {Θ Ξ} -> compatΘ Θ Ξ Θ Ξ
ext-id {[]} {[]} = compat-[]
ext-id {_ ∷ Θ} {_ ∷ Ξ} = compat-skip (ext-id {Θ} {Ξ})
smashΘ : ∀ {Θ} -> compatΘ Θ ∅ [] ∅
smashΘ {[]} = compat-[]
smashΘ {_ ∷ Θ} = compat-reduce-here smashΘ
extendΘ : ∀ {Θ} -> compatΘ [] ∅ Θ ∅
extendΘ {[]} = compat-[]
extendΘ {_ ∷ Θ} = compat-ext-here extendΘ
adjust∅Θ : ∀ {Θ Θ'} -> compatΘ Θ ∅ Θ' ∅
adjust∅Θ {[]} = extendΘ
adjust∅Θ {_ ∷ Θ} = compat-reduce-here adjust∅Θ
-- Some properties on compatΘ
compatΘ-∅ : ∀ {Θ Θ' Ξ'} -> compatΘ Θ ∅ Θ' Ξ' -> Ξ' ≡ ∅
compatΘ-∅ compat-[] = refl
compatΘ-∅ (compat-reduce-here ext) = compatΘ-∅ ext
compatΘ-∅ (compat-ext-here ext) = cong (_∷_ zero) (compatΘ-∅ ext)
compatΘ-∅ (compat-skip ext) = cong (_∷_ zero) (compatΘ-∅ ext)
compatΘ-split :
∀ {Θ Ξ₁ Ξ₂ Θ' Ξ'} ->
compatΘ Θ (Ξ₁ +ₘ Ξ₂) Θ' Ξ' ->
∃ λ (Ξ₁' : MultEnv (length Θ')) -> ∃ λ (Ξ₂' : MultEnv (length Θ')) ->
compatΘ Θ Ξ₁ Θ' Ξ₁' × compatΘ Θ Ξ₂ Θ' Ξ₂' × Ξ₁' +ₘ Ξ₂' ≡ Ξ'
compatΘ-split {[]} {[]} {[]} {.[]} {.[]} compat-[] = ∅ , ∅ , compat-[] , compat-[] , refl
compatΘ-split {[]} {[]} {[]} {.(_ ∷ _)} {.(zero ∷ _)} (compat-ext-here ext)
with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl =
zero ∷ Ξ₁' , zero ∷ Ξ₂' , compat-ext-here ext₁ , compat-ext-here ext₂ , refl
compatΘ-split {x ∷ Θ} {zero ∷ Ξ₁} {.zero ∷ Ξ₂} {[]} {[]} (compat-reduce-here ext)
with compatΘ-split ext
... | [] , [] , ext₁ , ext₂ , eq =
[] , [] , compat-reduce-here ext₁ , compat-reduce-here ext₂ , refl
compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {zero ∷ Ξ₂} {[]} {[]} ()
compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {one ∷ Ξ₂} {[]} {[]} ()
compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {omega ∷ Ξ₂} {[]} {[]} ()
compatΘ-split {x ∷ Θ} {zero ∷ Ξ₁} {x₂ ∷ Ξ₂} {x₃ ∷ Θ'} {.zero ∷ Ξ'} (compat-ext-here ext)
with compatΘ-split {x ∷ Θ} {zero ∷ Ξ₁} {x₂ ∷ Ξ₂} ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl =
zero ∷ Ξ₁' , zero ∷ Ξ₂' , compat-ext-here ext₁ , compat-ext-here ext₂ , refl
compatΘ-split {x ∷ Θ} {zero ∷ Ξ₁} {.zero ∷ Ξ₂} {x₃ ∷ Θ'} {x₄ ∷ Ξ'} (compat-reduce-here ext)
with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , eq =
Ξ₁' , Ξ₂' , compat-reduce-here ext₁ , compat-reduce-here ext₂ , eq
compatΘ-split {x ∷ Θ} {zero ∷ Ξ₁} {x₂ ∷ Ξ₂} {.x ∷ Θ'} {.x₂ ∷ Ξ'} (compat-skip ext)
with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl =
zero ∷ Ξ₁' , x₂ ∷ Ξ₂' , compat-skip ext₁ , compat-skip ext₂ , refl
compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {zero ∷ Ξ₂} {x₃ ∷ Θ'} {.zero ∷ Ξ'} (compat-ext-here ext)
with compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {zero ∷ Ξ₂} ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl =
zero ∷ Ξ₁' , zero ∷ Ξ₂' , compat-ext-here ext₁ , compat-ext-here ext₂ , refl
compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {zero ∷ Ξ₂} {.x ∷ Θ'} {.one ∷ Ξ'} (compat-skip ext)
with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl =
one ∷ Ξ₁' , zero ∷ Ξ₂' , compat-skip ext₁ , compat-skip ext₂ , refl
compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {one ∷ Ξ₂} {x₃ ∷ Θ'} {.zero ∷ Ξ'} (compat-ext-here ext)
with compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {one ∷ Ξ₂} ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl =
zero ∷ Ξ₁' , zero ∷ Ξ₂' , compat-ext-here ext₁ , compat-ext-here ext₂ , refl
compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {one ∷ Ξ₂} {.x ∷ Θ'} {.omega ∷ Ξ'} (compat-skip ext)
with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl =
one ∷ Ξ₁' , one ∷ Ξ₂' , compat-skip ext₁ , compat-skip ext₂ , refl
compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {omega ∷ Ξ₂} {x₃ ∷ Θ'} {.zero ∷ Ξ'} (compat-ext-here ext)
with compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {omega ∷ Ξ₂} ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl =
zero ∷ Ξ₁' , zero ∷ Ξ₂' , compat-ext-here ext₁ , compat-ext-here ext₂ , refl
compatΘ-split {x ∷ Θ} {one ∷ Ξ₁} {omega ∷ Ξ₂} {.x ∷ Θ'} {.omega ∷ Ξ'} (compat-skip ext)
with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl =
one ∷ Ξ₁' , omega ∷ Ξ₂' , compat-skip ext₁ , compat-skip ext₂ , refl
compatΘ-split {x ∷ Θ} {omega ∷ Ξ₁} {x₂ ∷ Ξ₂} {x₃ ∷ Θ'} {.zero ∷ Ξ'} (compat-ext-here ext)
with compatΘ-split {x ∷ Θ} {omega ∷ Ξ₁} {x₂ ∷ Ξ₂} ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl =
zero ∷ Ξ₁' , zero ∷ Ξ₂' , compat-ext-here ext₁ , compat-ext-here ext₂ , refl
compatΘ-split {x ∷ Θ} {omega ∷ Ξ₁} {x₂ ∷ Ξ₂} {.x ∷ Θ'} {.omega ∷ Ξ'} (compat-skip ext)
with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl =
omega ∷ Ξ₁' , x₂ ∷ Ξ₂' , compat-skip ext₁ , compat-skip ext₂ , refl
compatΘ-preserves-all-no-omega :
∀ {Θ Ξ Θ' Ξ'} ->
compatΘ Θ Ξ Θ' Ξ' -> all-no-omega Ξ -> all-no-omega Ξ'
compatΘ-preserves-all-no-omega compat-[] ano = ano
compatΘ-preserves-all-no-omega (compat-ext-here ext) ano = zero ∷ compatΘ-preserves-all-no-omega ext ano
compatΘ-preserves-all-no-omega (compat-reduce-here ext) (px ∷ ano) = compatΘ-preserves-all-no-omega ext ano
compatΘ-preserves-all-no-omega (compat-skip ext) (px ∷ ano) = px ∷ compatΘ-preserves-all-no-omega ext ano
compatΘ-preserves-all-zero :
∀ {Θ Ξ Θ' Ξ'} ->
compatΘ Θ Ξ Θ' Ξ' -> all-zero Ξ -> all-zero Ξ'
compatΘ-preserves-all-zero compat-[] az = az
compatΘ-preserves-all-zero (compat-ext-here ext) az = refl ∷ compatΘ-preserves-all-zero ext az
compatΘ-preserves-all-zero (compat-reduce-here ext) (px ∷ az) = compatΘ-preserves-all-zero ext az
compatΘ-preserves-all-zero (compat-skip ext) (px ∷ az) = px ∷ compatΘ-preserves-all-zero ext az
compatΘ-preserves-varOk● :
∀ {Θ Ξ Θ' Ξ' A} {x : Θ ∋ A} ->
compatΘ Θ Ξ Θ' Ξ' -> varOk● Θ x Ξ -> ∃ λ (x' : Θ' ∋ A) -> varOk● Θ' x' Ξ'
compatΘ-preserves-varOk● (compat-ext-here ext) ok with compatΘ-preserves-varOk● ext ok
... | x' , ok' = vs x' , there ok'
compatΘ-preserves-varOk● (compat-reduce-here ext) (there ok) = compatΘ-preserves-varOk● ext ok
compatΘ-preserves-varOk● (compat-skip ext) (there ok) with compatΘ-preserves-varOk● ext ok
... | x' , ok' = vs x' , there ok'
compatΘ-preserves-varOk● (compat-skip ext) (here ad) = vz , here (compatΘ-preserves-all-zero ext ad)
compatΘ-×ₘ :
∀ {Θ m Ξ Θ' Ξ'} ->
compatΘ Θ (m ×ₘ Ξ) Θ' Ξ' ->
∃ λ (Ξ'' : MultEnv (length Θ')) ->
compatΘ Θ Ξ Θ' Ξ'' × m ×ₘ Ξ'' ≡ Ξ'
compatΘ-×ₘ {[]} {m} {[]} {.[]} {.[]} compat-[] = [] , compat-[] , refl
compatΘ-×ₘ {[]} {m} {[]} {.(_ ∷ _)} {.(zero ∷ _)} (compat-ext-here ext) with compatΘ-×ₘ {[]} {m} {[]} ext
... | Ξ' , ext' , refl = zero ∷ Ξ' , compat-ext-here ext' , cong (_∷ m ×ₘ Ξ') (mul₀-m-zero _)
compatΘ-×ₘ {_ ∷ Θ} {one} {.zero ∷ Ξ} {[]} {[]} (compat-reduce-here ext) with compatΘ-×ₘ ext
... | [] , ext' , eq = [] , compat-reduce-here ext' , refl
compatΘ-×ₘ {_ ∷ Θ} {omega} {zero ∷ Ξ} {[]} {[]} (compat-reduce-here ext) with compatΘ-×ₘ ext
... | [] , ext' , eq = [] , compat-reduce-here ext' , refl
compatΘ-×ₘ {_ ∷ Θ} {one} {n ∷ Ξ} {_ ∷ Θ'} {.zero ∷ Ξ'} (compat-ext-here ext)
with compatΘ-×ₘ ext
... | Ξ'' , ext' , refl = zero ∷ Ξ'' , compat-ext-here ext' , refl
compatΘ-×ₘ {_ ∷ Θ} {one} {.zero ∷ Ξ} {_ ∷ Θ'} {n' ∷ Ξ'} (compat-reduce-here ext)
with compatΘ-×ₘ ext
... | Ξ'' , ext' , eq = Ξ'' , compat-reduce-here ext' , eq
compatΘ-×ₘ {_ ∷ Θ} {one} {n ∷ Ξ} {_ ∷ Θ'} {.n ∷ Ξ'} (compat-skip ext)
with compatΘ-×ₘ ext
... | Ξ'' , ext' , refl = n ∷ Ξ'' , compat-skip ext' , refl
compatΘ-×ₘ {_ ∷ Θ} {omega} {zero ∷ Ξ} {_ ∷ Θ'} {.zero ∷ Ξ'} (compat-ext-here ext)
with compatΘ-×ₘ {m = omega} {zero ∷ Ξ} ext
... | Ξ'' , ext' , refl = zero ∷ Ξ'' , compat-ext-here ext' , refl
compatΘ-×ₘ {_ ∷ Θ} {omega} {zero ∷ Ξ} {_ ∷ Θ'} {n' ∷ Ξ'} (compat-reduce-here ext)
with compatΘ-×ₘ ext
... | Ξ'' , ext' , eq = Ξ'' , compat-reduce-here ext' , eq
compatΘ-×ₘ {_ ∷ Θ} {omega} {zero ∷ Ξ} {_ ∷ Θ'} {.zero ∷ Ξ'} (compat-skip ext)
with compatΘ-×ₘ ext
... | Ξ'' , ext' , refl = zero ∷ Ξ'' , compat-skip ext' , refl
compatΘ-×ₘ {_ ∷ Θ} {omega} {one ∷ Ξ} {_ ∷ Θ'} {.zero ∷ Ξ'} (compat-ext-here ext)
with compatΘ-×ₘ {m = omega} {one ∷ Ξ} ext
... | Ξ'' , ext' , refl = zero ∷ Ξ'' , compat-ext-here ext' , refl
compatΘ-×ₘ {_ ∷ Θ} {omega} {one ∷ Ξ} {_ ∷ Θ'} {.omega ∷ Ξ'} (compat-skip ext)
with compatΘ-×ₘ ext
... | Ξ'' , ext' , refl = one ∷ Ξ'' , compat-skip ext' , refl
compatΘ-×ₘ {_ ∷ Θ} {omega} {omega ∷ Ξ} {_ ∷ Θ'} {.zero ∷ Ξ'} (compat-ext-here ext)
with compatΘ-×ₘ {m = omega} {omega ∷ Ξ} ext
... | Ξ'' , ext' , refl = zero ∷ Ξ'' , compat-ext-here ext' , refl
compatΘ-×ₘ {_ ∷ Θ} {omega} {omega ∷ Ξ} {_ ∷ Θ'} {.omega ∷ Ξ'} (compat-skip ext)
with compatΘ-×ₘ ext
... | Ξ'' , ext' , refl = omega ∷ Ξ'' , compat-skip ext' , refl
-- Well-typed terms can also be typed compatible environments.Due to a
-- historical reason, this property is called weakenΘ-term as
-- compatΘ was initially used only for adding variables with
-- multiplicity zero.
weakenΘ-term : ∀ {Γ Δ Θ Ξ Θ' Ξ' A} ->
compatΘ Θ Ξ Θ' Ξ' ->
Term Γ Δ Θ Ξ A ->
Term Γ Δ Θ' Ξ' A
weakenΘ-term ext (var x ok) with compatΘ-∅ ext
... | refl = var x ok
weakenΘ-term ext (abs m t) = abs m (weakenΘ-term ext t)
weakenΘ-term ext (app t₁ t₂) with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl with compatΘ-×ₘ ext₂
... | Ξ₂'' , ext₂' , refl = app (weakenΘ-term ext₁ t₁) (weakenΘ-term ext₂' t₂)
weakenΘ-term ext (unit ad) with compatΘ-∅ ext
... | refl = unit ad
weakenΘ-term ext (letunit m t₁ t₂) with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl with compatΘ-×ₘ ext₁
... | Ξ₁'' , ext₁' , refl = letunit m (weakenΘ-term ext₁' t₁) (weakenΘ-term ext₂ t₂)
weakenΘ-term ext (pair t₁ t₂) with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl = pair (weakenΘ-term ext₁ t₁) (weakenΘ-term ext₂ t₂)
weakenΘ-term ext (letpair m t₁ t₂) with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl with compatΘ-×ₘ ext₁
... | Ξ₁'' , ext₁' , refl = letpair m (weakenΘ-term ext₁' t₁) (weakenΘ-term ext₂ t₂)
weakenΘ-term ext (many m t) with compatΘ-×ₘ ext
... | Ξ'' , ext' , refl = many m (weakenΘ-term ext' t)
weakenΘ-term ext (unmany m' t₁ t₂) with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl with compatΘ-×ₘ ext₁
... | Ξ₁'' , ext₁' , refl = unmany m' (weakenΘ-term ext₁' t₁) (weakenΘ-term ext₂ t₂)
weakenΘ-term ext (inl t) = inl (weakenΘ-term ext t)
weakenΘ-term ext (inr t) = inr (weakenΘ-term ext t)
weakenΘ-term ext (case m t₀ t₁ t₂) with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl with compatΘ-×ₘ ext₁
... | Ξ₁'' , ext₁' , refl = case m (weakenΘ-term ext₁' t₀) (weakenΘ-term ext₂ t₁) (weakenΘ-term ext₂ t₂)
weakenΘ-term ext (roll t) = roll (weakenΘ-term ext t)
weakenΘ-term ext (unroll t) = unroll (weakenΘ-term ext t)
weakenΘ-term ext (unit● ad) with compatΘ-∅ ext
... | refl = unit● ad
weakenΘ-term ext (letunit● t₁ t₂)
with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl = letunit● (weakenΘ-term ext₁ t₁) (weakenΘ-term ext₂ t₂)
weakenΘ-term ext (pair● t₁ t₂)
with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl = pair● (weakenΘ-term ext₁ t₁) (weakenΘ-term ext₂ t₂)
weakenΘ-term ext (letpair● t₁ t₂)
with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl = letpair● (weakenΘ-term ext₁ t₁) (weakenΘ-term (compat-skip (compat-skip ext₂)) t₂)
weakenΘ-term ext (inl● t) = inl● (weakenΘ-term ext t)
weakenΘ-term ext (inr● t) = inr● (weakenΘ-term ext t)
weakenΘ-term ext (case● t t₁ t₂ t₃)
with compatΘ-split ext
... | _ , _ , ext₁₂ , ext₃ , refl with compatΘ-split ext₁₂
... | _ , _ , ext₁ , ext₂ , refl with compatΘ-×ₘ ext₃
... | _ , ext₃' , refl = case● (weakenΘ-term ext₁ t) (weakenΘ-term (compat-skip ext₂) t₁) (weakenΘ-term (compat-skip ext₂) t₂) (weakenΘ-term ext₃' t₃)
weakenΘ-term ext (var● x ad ok) with compatΘ-preserves-varOk● ext ok
... | x' , ok' = var● x' ad ok'
weakenΘ-term ext (pin t₁ t₂)
with compatΘ-split ext
... | Ξ₁' , Ξ₂' , ext₁ , ext₂ , refl = pin (weakenΘ-term ext₁ t₁) (weakenΘ-term ext₂ t₂)
weakenΘ-term ext (unlift t) =
CASE compatΘ-×ₘ ext OF λ {
(_ , ext' , refl) -> unlift (weakenΘ-term ext' t)
}
weakenΘ-term ext (fapp t₁ t₂) =
CASE compatΘ-split ext OF λ {
(_ , _ , ext₁ , ext₂ , refl) -> CASE compatΘ-×ₘ ext₂ OF λ {
(_ , ext₂' , refl) -> fapp (weakenΘ-term ext₁ t₁) (weakenΘ-term ext₂' t₂)
}
}
weakenΘ-term ext (bapp t₁ t₂) =
CASE compatΘ-split ext OF λ {
(_ , _ , ext₁ , ext₂ , refl) -> CASE compatΘ-×ₘ ext₂ OF λ {
(_ , ext₂' , refl) -> bapp (weakenΘ-term ext₁ t₁) (weakenΘ-term ext₂' t₂)
}
}
|
{
"alphanum_fraction": 0.5367338941,
"avg_line_length": 36.938752784,
"ext": "agda",
"hexsha": "bf95c673d500a82dbb8afb606fd2a78a180d4f71",
"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": "e2fb3a669e733a9020a51b24244d89abd8fcf725",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "kztk-m/sparcl-agda",
"max_forks_repo_path": "Syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e2fb3a669e733a9020a51b24244d89abd8fcf725",
"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": "kztk-m/sparcl-agda",
"max_issues_repo_path": "Syntax.agda",
"max_line_length": 213,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e2fb3a669e733a9020a51b24244d89abd8fcf725",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "kztk-m/sparcl-agda",
"max_stars_repo_path": "Syntax.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 14908,
"size": 33171
}
|
module GUIgeneric.GUIDefinitions where
open import GUIgeneric.Prelude
open import Relation.Binary.PropositionalEquality.TrustMe using (trustMe)
open import Relation.Nullary
data _⊎Comp_ {a b} (A : Set a) (B : Set b) : Set (a ⊔Level b) where
button : (x : A) → A ⊎Comp B
txtbox : (y : B) → A ⊎Comp B
data Direction : Set where
left right : Direction
data Comp : Set where
frame atomicComp : Comp
SubCompsIndex : Comp → Set
SubCompsIndex frame = ⊤
SubCompsIndex atomicComp = ⊥
data isSubComp : (c c' : Comp) → Set where
buttonFrame : isSubComp atomicComp frame
subComp : (c : Comp){c' : Comp}
(is : isSubComp c' c) → Comp
subComp .frame {cButton} buttonFrame = cButton
createParameters : Comp → Set
createParameters atomicComp = String ⊎Comp String
createParameters _ = ⊤
data IsOptimized : Set where
optimized notOptimzed : IsOptimized
data CompEls (c : Comp) : Set where
createC : createParameters c → CompEls c
add : {c' : Comp}(c'c : isSubComp c' c)
(e' : CompEls c')(e : CompEls c)(isOpt : IsOptimized)
→ CompEls c
data _<c_ : {c c' : Comp}(e : CompEls c)(e' : CompEls c') → Set where
addsub : {c' c : Comp}(c'c : isSubComp c' c)
(e' : CompEls c')
(e : CompEls c)
(isOpt : IsOptimized)
→ e' <c add c'c e' e isOpt
addlift : {c' c : Comp}(c'c : isSubComp c' c)
(e' : CompEls c')
(e : CompEls c)
(isOpt : IsOptimized)
→ e <c add c'c e' e isOpt
data _<c+_ : {c c' : Comp}(e : CompEls c)(e' : CompEls c') → Set where
in1 : {c c' : Comp} (e : CompEls c)(e' : CompEls c')
(ee' : e <c e') → e <c+ e'
in2 : {c c' c'' : Comp} (e : CompEls c)(e' : CompEls c')(e'' : CompEls c'')
(ee' : e <c e')(e'e'' : e' <c+ e'') → (e <c+ e'')
data _<=c+_ : {c c' : Comp}(e : CompEls c)(e' : CompEls c') → Set where
in0= : {c : Comp} (e : CompEls c)
→ e <=c+ e
in2= : {c c' c'' : Comp} (e : CompEls c)(e' : CompEls c')
(e'' : CompEls c'')
→ e <c e' → e' <=c+ e'' → e <=c+ e''
in1= : {c c' : Comp} (e : CompEls c)(e' : CompEls c')
(ee' : e <c e') → e <=c+ e'
in1= e e' ee' = in2= e e' e' ee' (in0= e')
trans<=c+ : {c c' c'' : Comp} (e : CompEls c)(e' : CompEls c')
(e'' : CompEls c'')
(ee' : e <=c+ e')
(e'e'' : e' <=c+ e'')
→ e <=c+ e''
trans<=c+ {c} {.c} {c''} e .e e'' (in0= .e) e'e'' = e'e''
trans<=c+ {c} {c'} {c''} e e' e'' (in2= .e e'₁ .e' ee'₁ e'₁e') e'e'' = in2= e e'₁ e'' ee'₁ (trans<=c+ e'₁ e' e'' e'₁e' e'e'')
--
-- DEC Equality
--
module _ where
sameOptimized : IsOptimized → IsOptimized → Bool
sameOptimized optimized optimized = true
sameOptimized notOptimzed notOptimzed = true
sameOptimized _ _ = false
_≟CompBool_ : {c c' : Comp} → CompEls c → CompEls c' → Bool
_≟CompBool_ {frame} {frame} (add c₁c₂ c₁ c₂ isOpt) (add c₃c₄ c₃ c₄ isOpt') =
(c₁ ≟CompBool c₃) ∧ (c₂ ≟CompBool c₄) ∧ (sameOptimized isOpt isOpt')
_≟CompBool_ {atomicComp} {atomicComp} (add {frame} () _ _ _)
_≟CompBool_ {atomicComp} {atomicComp} (add {atomicComp} () _ _ _)
_≟CompBool_ {frame} {frame} (createC tt) (createC tt) = true
_≟CompBool_ {atomicComp} {atomicComp} (createC (button x)) (createC (button y)) = x ==Str y
_≟CompBool_ {atomicComp} {atomicComp} (createC (txtbox x)) (createC (txtbox y)) = x ==Str y
_≟CompBool_ {atomicComp} {atomicComp} (createC (button x)) (createC (txtbox y)) = false
_≟CompBool_ {atomicComp} {atomicComp} (createC (txtbox x)) (createC (button y)) = false
_≟CompBool_ {frame} {atomicComp} _ _ = false
_≟CompBool_ {atomicComp} {frame} _ _ = false
createC _ ≟CompBool add _ _ _ _ = false
add _ _ _ _ ≟CompBool createC _ = false
unused = Dec
{- add buttonFrame a c notOptimzed ≡ add buttonFrame b d notOptimzedadd buttonFrame a c notOptimzed ≡ add buttonFrame b d notOptimzed -}
lemmaAddEqProj1 : ∀ {a} {c} {opt} {b} {d} {opt'} → add buttonFrame a c opt ≡ add buttonFrame b d opt' → a ≡ b
lemmaAddEqProj1 refl = refl
lemmaAddEqProj2 : ∀ {a} {c} {opt} {b} {d} {opt'} → add buttonFrame a c opt ≡ add buttonFrame b d opt' → c ≡ d
lemmaAddEqProj2 refl = refl
lemmaCreateCBtnEq : ∀ {s1} {s2} → ((createC (button s1)) ≡ (createC (button s2))) → (s1 ≡ s2)
lemmaCreateCBtnEq refl = refl
lemmaCreateCTxtbxEq : ∀ {s1} {s2} → ((createC (txtbox s1)) ≡ (createC (txtbox s2))) → (s1 ≡ s2)
lemmaCreateCTxtbxEq refl = refl
mutual
_≟CompFr_ : Decidable {A = CompEls frame} _≡_
createC tt ≟CompFr createC tt = Dec.yes refl
createC tt ≟CompFr add _ _ _ _ = Dec.no (λ ())
add _ _ _ _ ≟CompFr createC _ = Dec.no (λ ())
add _ _ _ optimized ≟CompFr add _ _ _ notOptimzed = Dec.no (λ ())
add _ _ _ notOptimzed ≟CompFr add _ _ _ optimized = Dec.no (λ ())
add buttonFrame a c optimized ≟CompFr add buttonFrame b d optimized with (a ≟Comp b) | (c ≟Comp d)
... | Dec.yes p | Dec.yes q = yes (cong₂ (λ x y → add buttonFrame x y optimized ) p q)
... | Dec.yes p | Dec.no ¬p = no (λ addp → ¬p (lemmaAddEqProj2 addp))
... | Dec.no ¬p | _ = no ((λ addp → ¬p (lemmaAddEqProj1 addp)))
add buttonFrame a c notOptimzed ≟CompFr add buttonFrame b d notOptimzed with (a ≟Comp b) | (c ≟Comp d)
... | yes p | yes q = yes (cong₂ (λ x y → add buttonFrame x y notOptimzed ) p q)
... | yes p | no ¬p = no (λ addp → ¬p (lemmaAddEqProj2 addp))
... | no ¬p | q = no ((λ addp → ¬p (lemmaAddEqProj1 addp)))
_≟Comp_ : {c : Comp} → Decidable {A = CompEls c} _≡_
_≟Comp_ (createC _) (add _ _ _ isOpt) = Dec.no (λ ())
_≟Comp_ (add _ _ _ isOpt) (createC _) = Dec.no (λ ())
_≟Comp_ {atomicComp} (add () a b isOpt) (add cd c d isOpt')
_≟Comp_ {frame} (createC tt) (createC tt) = Dec.yes refl
_≟Comp_ {atomicComp} (createC (button s1)) (createC (button s2)) with (s1 ≟Str s2)
... | Dec.yes p = Dec.yes (cong (createC ∘ button) p)
... | Dec.no q = Dec.no (λ neq → q (lemmaCreateCBtnEq neq) )
_≟Comp_ {atomicComp} (createC (txtbox s1)) (createC (txtbox s2)) with (s1 ≟Str s2)
... | Dec.yes p = Dec.yes (cong (createC ∘ txtbox) p)
... | Dec.no q = Dec.no (λ neq → q (lemmaCreateCTxtbxEq neq) )
_≟Comp_ {atomicComp} (createC (button s1)) (createC (txtbox s2)) = Dec.no (λ ())
_≟Comp_ {atomicComp} (createC (txtbox s1)) (createC (button s2)) = Dec.no (λ ())
_≟Comp_ {frame} (add c'c x x₁ isOpt) (add c'c₁ y y₁ isOpt₁) =
_≟CompFr_ (add c'c x x₁ isOpt) (add c'c₁ y y₁ isOpt₁)
create-frame : CompEls frame
create-frame = createC{frame} tt
create-button : (s : String) → CompEls atomicComp
create-button s = createC{atomicComp} (button s)
create-txtbox : (s : String) → CompEls atomicComp
create-txtbox s = createC{atomicComp} (txtbox s)
validAdd : (c c' : Comp) → Set
validAdd atomicComp frame = ⊤
validAdd _ _ = ⊥
addReturnType : (c c' : Comp){_ : validAdd c c'} → Set
addReturnType atomicComp frame = CompEls frame
addReturnType frame frame {()}
addReturnType frame atomicComp {()}
addReturnType atomicComp atomicComp {()}
add' : {c c' : Comp}{va : validAdd c c'} → CompEls c → CompEls c'
→ (isOpt : IsOptimized) → addReturnType c c'{va}
add' {atomicComp} {frame} bt fr isOpt = add buttonFrame bt fr isOpt
add' {frame} {frame} {()} isOpt
add' {frame} {atomicComp} {()} isOpt
add' {atomicComp} {atomicComp} {()} isOpt
properties : {c : Comp}(e : CompEls c) → Set
properties {c} (add c'c e e' isOpt) = properties e × properties e'
properties {frame} (createC x) = (ℕ × ℕ × ℕ × ℕ)
properties {atomicComp} (createC x) = WxColor
ComponentEls : Comp → Set
ComponentEls = CompEls
Component : Set
Component = Comp
|
{
"alphanum_fraction": 0.5940465358,
"avg_line_length": 32.8760683761,
"ext": "agda",
"hexsha": "b9af2b8e34705d69726a188645a419e5267f0052",
"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": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "stephanadls/state-dependent-gui",
"max_forks_repo_path": "examples/GUIgeneric/GUIDefinitions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"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": "stephanadls/state-dependent-gui",
"max_issues_repo_path": "examples/GUIgeneric/GUIDefinitions.agda",
"max_line_length": 136,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "stephanadls/state-dependent-gui",
"max_stars_repo_path": "examples/GUIgeneric/GUIDefinitions.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-31T17:20:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T15:37:39.000Z",
"num_tokens": 2962,
"size": 7693
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Natural numbers with fast addition (for use together with
-- DifferenceVec)
------------------------------------------------------------------------
module Data.DifferenceNat where
open import Data.Nat as N using (ℕ)
open import Function
infixl 6 _+_
Diffℕ : Set
Diffℕ = ℕ → ℕ
0# : Diffℕ
0# = λ k → k
suc : Diffℕ → Diffℕ
suc n = λ k → N.suc (n k)
1# : Diffℕ
1# = suc 0#
_+_ : Diffℕ → Diffℕ → Diffℕ
m + n = λ k → m (n k)
toℕ : Diffℕ → ℕ
toℕ n = n 0
-- fromℕ n is linear in the size of n.
fromℕ : ℕ → Diffℕ
fromℕ n = λ k → n ⟨ N._+_ ⟩ k
|
{
"alphanum_fraction": 0.4801223242,
"avg_line_length": 17.6756756757,
"ext": "agda",
"hexsha": "e60e38bdd6db89e70236a500c86b80ace003656e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/DifferenceNat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/DifferenceNat.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/DifferenceNat.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 213,
"size": 654
}
|
{-# OPTIONS --safe #-}
module Generics where
open import Data.Unit public using (⊤; tt)
open import Generics.Prelude public using (liftω; liftω-inst)
open import Generics.HasDesc public using (HasDesc)
open import Generics.Reflection public using (deriveDesc)
open import Generics.Helpers public
open import Generics.Constructions.Case public using (deriveCase)
open import Generics.Constructions.Cong public using (deriveCong)
open import Generics.Constructions.DecEq public using (DecEq; _≟_; deriveDecEq)
open import Generics.Constructions.Elim public using (deriveElim)
open import Generics.Constructions.Fold public using (deriveFold)
open import Generics.Constructions.Recursion public using (rec; Below)
open import Generics.Constructions.Show public using (Show; show; deriveShow)
|
{
"alphanum_fraction": 0.7250280584,
"avg_line_length": 52.4117647059,
"ext": "agda",
"hexsha": "f448f54574734af232b1de981a647f0b0e139b63",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z",
"max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/generics",
"max_forks_repo_path": "src/Generics.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "flupe/generics",
"max_issues_repo_path": "src/Generics.agda",
"max_line_length": 84,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/generics",
"max_stars_repo_path": "src/Generics.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z",
"num_tokens": 191,
"size": 891
}
|
module Data.BitVector.NumericOrder where
open import Data.Empty
open import Data.Sum
open import Data.Vec
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Data.Nat hiding (decTotalOrder; _≟_; _<_; _≤_; module _≤_; _≤?_; compare) renaming (zero to Nzero; suc to Nsuc)
open import Data.BitVector
open import Function
infix 4 _<_
infix 4 _≤_
mutual
data _<_ : ∀ {n} → BitVector n → BitVector n → Set where
b#<b# : ∀ {n} {x y : BitVector n} {b#} → (pf : x < y) → (b# ∷ x) < (b# ∷ y)
0#<1# : ∀ {n} {x y : BitVector n} → (pf : x ≤ y) → (0# ∷ x) < (1# ∷ y)
1#<0# : ∀ {n} {x y : BitVector n} → (pf : x < y) → (1# ∷ x) < (0# ∷ y)
-- Silly agda bug is preventing me from using the _≤_ name even though it's not in scope :(
data _≤_ : ∀ {n} → BitVector n → BitVector n → Set where
[]≤[] : [] ≤ []
b#≤b# : ∀ {n} {x y : BitVector n} {b#} → (pf : x ≤ y) → (b# ∷ x) ≤ (b# ∷ y)
0#≤1# : ∀ {n} {x y : BitVector n} → (pf : x ≤ y) → (0# ∷ x) ≤ (1# ∷ y)
1#≤0# : ∀ {n} {x y : BitVector n} → (pf : x < y) → (1# ∷ x) ≤ (0# ∷ y)
<-irr : ∀ {n} {x : BitVector n} → ¬ x < x
<-irr {0} ()
<-irr (b#<b# pf) = <-irr pf
≤-refl : ∀ {n} → _≡_ ⇒ (_≤_ {n})
≤-refl {0} {[]} refl = []≤[]
≤-refl {Nsuc n} {b# ∷ xs} refl = b#≤b# (≤-refl refl)
opposites : ∀ {n} {x y : BitVector n} → x ≤ y → y < x → ⊥
opposites []≤[] ()
opposites (b#≤b# pf₀) (b#<b# pf₁) = opposites pf₀ pf₁
opposites (0#≤1# pf₀) (1#<0# pf₁) = opposites pf₀ pf₁
opposites (1#≤0# pf₀) (0#<1# pf₁) = opposites pf₁ pf₀
≤-antisym : ∀ {n} → Antisymmetric _≡_ (_≤_ {n})
≤-antisym []≤[] q = refl
≤-antisym (b#≤b# pf₀) (b#≤b# pf₁) rewrite ≤-antisym pf₀ pf₁ = refl
≤-antisym (0#≤1# (b#≤b# pf₀)) (1#≤0# (b#<b# pf₁)) = ⊥-elim (opposites pf₀ pf₁)
≤-antisym (0#≤1# (1#≤0# pf₀)) (1#≤0# (0#<1# pf₁)) = ⊥-elim (opposites pf₁ pf₀)
≤-antisym (0#≤1# (0#≤1# pf₀)) (1#≤0# (1#<0# pf₁)) = ⊥-elim (opposites pf₀ pf₁)
≤-antisym (0#≤1# pf₀) (1#≤0# pf₁) = ⊥-elim (opposites pf₀ pf₁)
≤-antisym (1#≤0# pf₀) (0#≤1# pf₁) = ⊥-elim (opposites pf₁ pf₀)
mutual
≤-<-trans-< : ∀ {n} {x y z : BitVector n} → x ≤ y → y < z → x < z
≤-<-trans-< []≤[] ()
≤-<-trans-< (b#≤b# pf₀) (b#<b# pf₁) = b#<b# (≤-<-trans-< pf₀ pf₁)
≤-<-trans-< (b#≤b# pf₀) (0#<1# pf₁) = 0#<1# (≤-trans pf₀ pf₁)
≤-<-trans-< (b#≤b# pf₀) (1#<0# pf₁) = 1#<0# (≤-<-trans-< pf₀ pf₁)
≤-<-trans-< (0#≤1# pf₀) (b#<b# pf₁) = 0#<1# (≤-<-trans-≤ pf₀ pf₁)
≤-<-trans-< (0#≤1# pf₀) (1#<0# pf₁) = b#<b# (≤-<-trans-< pf₀ pf₁)
≤-<-trans-< (1#≤0# pf₀) (b#<b# pf₁) = 1#<0# (<-trans pf₀ pf₁)
≤-<-trans-< (1#≤0# pf₀) (0#<1# pf₁) = b#<b# (<-≤-trans-< pf₀ pf₁)
<-≤-trans-< : ∀ {n} {x y z : BitVector n} → x < y → y ≤ z → x < z
<-≤-trans-< (b#<b# pf₀) (b#≤b# pf₁) = b#<b# (<-≤-trans-< pf₀ pf₁)
<-≤-trans-< (b#<b# pf₀) (0#≤1# pf₁) = 0#<1# (<-≤-trans-≤ pf₀ pf₁)
<-≤-trans-< (b#<b# pf₀) (1#≤0# pf₁) = 1#<0# (<-trans pf₀ pf₁)
<-≤-trans-< (0#<1# pf₀) (b#≤b# pf₁) = 0#<1# (≤-trans pf₀ pf₁)
<-≤-trans-< (0#<1# pf₀) (1#≤0# pf₁) = b#<b# (≤-<-trans-< pf₀ pf₁)
<-≤-trans-< (1#<0# pf₀) (b#≤b# pf₁) = 1#<0# (<-≤-trans-< pf₀ pf₁)
<-≤-trans-< (1#<0# pf₀) (0#≤1# pf₁) = b#<b# (<-≤-trans-< pf₀ pf₁)
≤-<-trans-≤ : ∀ {n} {x y z : BitVector n} → x ≤ y → y < z → x ≤ z
≤-<-trans-≤ []≤[] ()
≤-<-trans-≤ (b#≤b# pf₀) (b#<b# pf₁) = b#≤b# (≤-<-trans-≤ pf₀ pf₁)
≤-<-trans-≤ (b#≤b# pf₀) (0#<1# pf₁) = 0#≤1# (≤-trans pf₀ pf₁)
≤-<-trans-≤ (b#≤b# pf₀) (1#<0# pf₁) = 1#≤0# (≤-<-trans-< pf₀ pf₁)
≤-<-trans-≤ (0#≤1# pf₀) (b#<b# pf₁) = 0#≤1# (≤-<-trans-≤ pf₀ pf₁)
≤-<-trans-≤ (0#≤1# pf₀) (1#<0# pf₁) = b#≤b# (≤-<-trans-≤ pf₀ pf₁)
≤-<-trans-≤ (1#≤0# pf₀) (b#<b# pf₁) = 1#≤0# (<-trans pf₀ pf₁)
≤-<-trans-≤ (1#≤0# pf₀) (0#<1# pf₁) = b#≤b# (<-≤-trans-≤ pf₀ pf₁)
<-≤-trans-≤ : ∀ {n} {x y z : BitVector n} → x < y → y ≤ z → x ≤ z
<-≤-trans-≤ (b#<b# pf₀) (b#≤b# pf₁) = b#≤b# (<-≤-trans-≤ pf₀ pf₁)
<-≤-trans-≤ (b#<b# pf₀) (0#≤1# pf₁) = 0#≤1# (<-≤-trans-≤ pf₀ pf₁)
<-≤-trans-≤ (b#<b# pf₀) (1#≤0# pf₁) = 1#≤0# (<-trans pf₀ pf₁)
<-≤-trans-≤ (0#<1# pf₀) (b#≤b# pf₁) = 0#≤1# (≤-trans pf₀ pf₁)
<-≤-trans-≤ (0#<1# pf₀) (1#≤0# pf₁) = b#≤b# (≤-<-trans-≤ pf₀ pf₁)
<-≤-trans-≤ (1#<0# pf₀) (b#≤b# pf₁) = 1#≤0# (<-≤-trans-< pf₀ pf₁)
<-≤-trans-≤ (1#<0# pf₀) (0#≤1# pf₁) = b#≤b# (<-≤-trans-≤ pf₀ pf₁)
<-trans : ∀ {n} → Transitive (_<_ {n})
<-trans (b#<b# pf₀) (b#<b# pf₁) = b#<b# (<-trans pf₀ pf₁)
<-trans (b#<b# pf₀) (0#<1# pf₁) = 0#<1# (<-≤-trans-≤ pf₀ pf₁)
<-trans (b#<b# pf₀) (1#<0# pf₁) = 1#<0# (<-trans pf₀ pf₁)
<-trans (0#<1# pf₀) (b#<b# pf₁) = 0#<1# (≤-<-trans-≤ pf₀ pf₁)
<-trans (0#<1# pf₀) (1#<0# pf₁) = b#<b# (≤-<-trans-< pf₀ pf₁)
<-trans (1#<0# pf₀) (b#<b# pf₁) = 1#<0# (<-trans pf₀ pf₁)
<-trans (1#<0# pf₀) (0#<1# pf₁) = b#<b# (<-≤-trans-< pf₀ pf₁)
≤-trans : ∀ {n} → Transitive (_≤_ {n})
≤-trans []≤[] []≤[] = []≤[]
≤-trans (b#≤b# pf₀) (b#≤b# pf₁) = b#≤b# (≤-trans pf₀ pf₁)
≤-trans (b#≤b# pf₀) (0#≤1# pf₁) = 0#≤1# (≤-trans pf₀ pf₁)
≤-trans (b#≤b# pf₀) (1#≤0# pf₁) = 1#≤0# (≤-<-trans-< pf₀ pf₁)
≤-trans (0#≤1# pf₀) (b#≤b# pf₁) = 0#≤1# (≤-trans pf₀ pf₁)
≤-trans (0#≤1# pf₀) (1#≤0# pf₁) = b#≤b# (≤-<-trans-≤ pf₀ pf₁)
≤-trans (1#≤0# pf₀) (b#≤b# pf₁) = 1#≤0# (<-≤-trans-< pf₀ pf₁)
≤-trans (1#≤0# pf₀) (0#≤1# pf₁) = b#≤b# (<-≤-trans-≤ pf₀ pf₁)
<⇒≤ : ∀ {n} {x y : BitVector n} → x < y → x ≤ y
<⇒≤ (b#<b# pf) = b#≤b# (<⇒≤ pf)
<⇒≤ (0#<1# pf) = 0#≤1# pf
<⇒≤ (1#<0# pf) = 1#≤0# pf
≤⇒≡⊎< : ∀ {n} → {x y : BitVector n} → x ≤ y → x ≡ y ⊎ x < y
≤⇒≡⊎< []≤[] = inj₁ refl
≤⇒≡⊎< (b#≤b# pf) with ≤⇒≡⊎< pf
... | inj₁ refl = inj₁ refl
... | inj₂ x<y = inj₂ (b#<b# x<y)
≤⇒≡⊎< (0#≤1# pf) = inj₂ (0#<1# pf)
≤⇒≡⊎< (1#≤0# pf) = inj₂ (1#<0# pf)
helper≢ : ∀ {n} {x y} {xs ys : BitVector n} → ¬ xs < ys → xs ≢ ys → ¬ x ∷ xs < y ∷ ys
helper≢ xs≮ys xs≢ys (b#<b# pf) = xs≮ys pf
helper≢ xs≮ys xs≢ys (1#<0# pf) = xs≮ys pf
helper≢ xs≮ys xs≢ys (0#<1# pf) with ≤⇒≡⊎< pf
... | inj₁ x≡y = xs≢ys x≡y
... | inj₂ x<y = xs≮ys x<y
helper≡ : ∀ {n} {xs : BitVector n} → ¬ 1# ∷ xs < 0# ∷ xs
helper≡ (1#<0# pf) = <-irr pf
compare : ∀ {n} → Trichotomous _≡_ (_<_ {n})
compare [] [] = tri≈ (λ ()) refl (λ ())
compare (x ∷ xs) (y ∷ ys) with compare xs ys
compare (0# ∷ xs) (0# ∷ ys) | tri< a ¬b ¬c = tri< (b#<b# a) (¬b ∘ cong tail) (helper≢ ¬c (¬b ∘ sym))
compare (0# ∷ xs) (1# ∷ ys) | tri< a ¬b ¬c = tri< (0#<1# (<⇒≤ a)) (¬b ∘ cong tail) (helper≢ ¬c (¬b ∘ sym))
compare (1# ∷ xs) (0# ∷ ys) | tri< a ¬b ¬c = tri< (1#<0# a) (¬b ∘ cong tail) (helper≢ ¬c (¬b ∘ sym))
compare (1# ∷ xs) (1# ∷ ys) | tri< a ¬b ¬c = tri< (b#<b# a) (¬b ∘ cong tail) (helper≢ ¬c (¬b ∘ sym))
compare (0# ∷ xs) (0# ∷ ._) | tri≈ ¬a refl ¬c = tri≈ <-irr refl <-irr
compare (0# ∷ xs) (1# ∷ ._) | tri≈ ¬a refl ¬c = tri< (0#<1# (≤-refl refl)) (λ ()) helper≡
compare (1# ∷ xs) (0# ∷ ._) | tri≈ ¬a refl ¬c = tri> helper≡ (λ ()) (0#<1# (≤-refl refl))
compare (1# ∷ xs) (1# ∷ ._) | tri≈ ¬a refl ¬c = tri≈ <-irr refl <-irr
compare (0# ∷ xs) (0# ∷ ys) | tri> ¬a ¬b c = tri> (helper≢ ¬a ¬b) (¬b ∘ cong tail) (b#<b# c)
compare (0# ∷ xs) (1# ∷ ys) | tri> ¬a ¬b c = tri> (helper≢ ¬a ¬b) (λ ()) (1#<0# c)
compare (1# ∷ xs) (0# ∷ ys) | tri> ¬a ¬b c = tri> (helper≢ ¬a ¬b) (λ ()) (0#<1# (<⇒≤ c))
compare (1# ∷ xs) (1# ∷ ys) | tri> ¬a ¬b c = tri> (helper≢ ¬a ¬b) (¬b ∘ cong tail) (b#<b# c)
≤-total : ∀ {n} → Total (_≤_ {n})
≤-total [] [] = inj₁ []≤[]
≤-total (x ∷ xs) (y ∷ ys) with compare xs ys
≤-total (0# ∷ xs) (0# ∷ ys) | tri< a ¬b ¬c = inj₁ (b#≤b# (<⇒≤ a))
≤-total (0# ∷ xs) (1# ∷ ys) | tri< a ¬b ¬c = inj₁ (0#≤1# (<⇒≤ a))
≤-total (1# ∷ xs) (0# ∷ ys) | tri< a ¬b ¬c = inj₁ (1#≤0# a)
≤-total (1# ∷ xs) (1# ∷ ys) | tri< a ¬b ¬c = inj₁ (b#≤b# (<⇒≤ a))
≤-total (0# ∷ xs) (0# ∷ ys) | tri≈ ¬a b ¬c = inj₁ (b#≤b# (≤-refl b))
≤-total (0# ∷ xs) (1# ∷ ys) | tri≈ ¬a b ¬c = inj₁ (0#≤1# (≤-refl b))
≤-total (1# ∷ xs) (0# ∷ ys) | tri≈ ¬a b ¬c = inj₂ (0#≤1# (≤-refl (sym b)))
≤-total (1# ∷ xs) (1# ∷ ys) | tri≈ ¬a b ¬c = inj₁ (b#≤b# (≤-refl b))
≤-total (0# ∷ xs) (0# ∷ ys) | tri> ¬a ¬b c = inj₂ (b#≤b# (<⇒≤ c))
≤-total (0# ∷ xs) (1# ∷ ys) | tri> ¬a ¬b c = inj₂ (1#≤0# c)
≤-total (1# ∷ xs) (0# ∷ ys) | tri> ¬a ¬b c = inj₂ (0#≤1# (<⇒≤ c))
≤-total (1# ∷ xs) (1# ∷ ys) | tri> ¬a ¬b c = inj₂ (b#≤b# (<⇒≤ c))
_≤?_ : ∀ {n} → Decidable (_≤_ {n})
x ≤? y with compare x y
... | tri< a ¬b ¬c = yes (<⇒≤ a)
... | tri≈ ¬a b ¬c = yes (≤-refl b)
... | tri> ¬a ¬b c = no helper
where helper : ¬ x ≤ y
helper x≤y with ≤⇒≡⊎< x≤y
... | inj₁ x≡y = ¬b x≡y
... | inj₂ x<y = ¬a x<y
decTotalOrder : ∀ {n} → DecTotalOrder _ _ _
decTotalOrder {n} = record
{ Carrier = BitVector n
; _≈_ = _≡_
; _≤_ = _≤_
; isDecTotalOrder = record
{ isTotalOrder = record
{ isPartialOrder = record
{ isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = ≤-refl
; trans = ≤-trans
}
; antisym = ≤-antisym
}
; total = ≤-total
}
; _≟_ = _≟_
; _≤?_ = _≤?_
}
}
strictTotalOrder : ∀ {n} → StrictTotalOrder _ _ _
strictTotalOrder {n} = record
{ Carrier = BitVector n
; _≈_ = _≡_
; _<_ = _<_
; isStrictTotalOrder = record
{ isEquivalence = isEquivalence
; trans = <-trans
; compare = compare
}
}
|
{
"alphanum_fraction": 0.4379292129,
"avg_line_length": 43.2191780822,
"ext": "agda",
"hexsha": "7ab7df40218216352a370b17a5452ba1b2e1a3d5",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-11-12T01:40:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-25T00:15:43.000Z",
"max_forks_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "copumpkin/bitvector",
"max_forks_repo_path": "Data/BitVector/NumericOrder.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_issues_repo_issues_event_max_datetime": "2016-05-25T02:00:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-05-25T02:00:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "copumpkin/bitvector",
"max_issues_repo_path": "Data/BitVector/NumericOrder.agda",
"max_line_length": 123,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/bitvector",
"max_stars_repo_path": "Data/BitVector/NumericOrder.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-12T01:41:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T07:19:55.000Z",
"num_tokens": 5250,
"size": 9465
}
|
{-# OPTIONS --cubical --safe #-}
open import Prelude
open import Relation.Binary
open import Function.Injective
module Relation.Binary.Construct.On
{a b ℓ₁ ℓ₂} {A : Type a} {B : Type b}
(f : A → B) (f-inj : Injective f)
(ord : TotalOrder B ℓ₁ ℓ₂)
where
open TotalOrder ord renaming (refl to ≤-refl)
_<′_ : A → A → Type _
x <′ y = f x < f y
_≤′_ : A → A → Type _
x ≤′ y = f x ≤ f y
on-ord : TotalOrder A ℓ₁ ℓ₂
StrictPreorder._<_ (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder on-ord)) = _<′_
StrictPreorder.trans (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder on-ord)) = <-trans
StrictPreorder.irrefl (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder on-ord)) = irrefl
StrictPartialOrder.conn (TotalOrder.strictPartialOrder on-ord) p q = f-inj _ _ (conn p q)
Preorder._≤_ (PartialOrder.preorder (TotalOrder.partialOrder on-ord)) = _≤′_
Preorder.refl (PartialOrder.preorder (TotalOrder.partialOrder on-ord)) = ≤-refl
Preorder.trans (PartialOrder.preorder (TotalOrder.partialOrder on-ord)) = ≤-trans
PartialOrder.antisym (TotalOrder.partialOrder on-ord) p q = f-inj _ _ (antisym p q)
TotalOrder._<?_ on-ord x y = f x <? f y
TotalOrder.≰⇒> on-ord = ≰⇒>
TotalOrder.≮⇒≥ on-ord = ≮⇒≥
|
{
"alphanum_fraction": 0.7154276579,
"avg_line_length": 37.9090909091,
"ext": "agda",
"hexsha": "abb2c0a19167187ef6242032379578fa3494d5ba",
"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/Construct/On.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/Construct/On.agda",
"max_line_length": 106,
"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/Construct/On.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": 429,
"size": 1251
}
|
-- Andreas, 2015-06-17
-- Postponing checkArguments dropped already inserted implicit arguments.
{-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.def.alias:100 -v tc.decl:10 -v tc.term.expr:20 -v tc.data.con:20 #-}
-- {-# OPTIONS -v tc.meta.assign:10 #-}
-- {-# OPTIONS -v tc.term.expr.args:80 #-}
-- {-# OPTIONS -v tc.term.args:30 #-}
postulate
S : Set
Cxt : Set
N : (Γ : Cxt) → Set
NeP : ∀ (i : S) Δ (n : N Δ) → Set
inhN : ∀ i Δ (v : N Δ) → NeP i Δ v
data Val (Δ : Cxt) : Set where
ne : ∀ (n : N Δ) → Val Δ
-- BEGIN mutual
data ValP i Δ : (v : Val Δ) → Set
NeO : _
data ValP i Δ where
cn : ∀ (n : N Δ) → NeO n i → ValP i Δ (ne n)
-- adding constructor cn : (n : N Δ) → _24 i Δ n → ValP i Δ (ne n)
-- LATER : term _24 i Δ n := NeO n i
-- SHOULD BE: term _24 i Δ n := NeO {Δ} i n
-- must be last in mutual block for error
-- implicit argument needed for error
-- NeO_[_] : ∀ {Δ} (n : N Δ) (i : S) → Set -- full type signature removes error
NeO = λ {Δ} n i → NeP i Δ n
-- END mutual
inhVal : ∀ i Δ (v : Val Δ) → ValP i Δ v
inhVal i Δ (ne n) = cn n (inhN i Δ n)
-- Checking inhN i Δ n : NeO n [ i ] --> λ i₁ → NeP i₁ n i
-- ANALYSIS:
-- checked type signature NeO : _20
-- checking constructor cn : (n : N Δ) → NeO n i → ValP i Δ (ne n)
-- adding constructor cn : (n : N Δ) → _24 i Δ n → ValP i Δ (ne n)
-- postponed checking arguments [n, i] against _20
-- progress: checked [] remaining [n, i] : _20
-- term _20 :>= {Δ : _27} → _29 {Δ}
-- term _20 :>= {Δ : _27} → _29 {Δ}
-- solving _20 := {Δ : _27} → _29 {Δ}
-- postponed checking arguments [n, i] against _29 {_Δ_30 i Δ n}
-- progress: checked [] remaining [n, i] : _29 {_Δ_30 i Δ n}
-- Checking λ n i → NeP i Δ n : _29 {Δ}
-- solving _29 := λ {Δ} → (n : N Δ) (i : S) → Set
-- solving _24 := (λ i Δ n → NeO n i)
|
{
"alphanum_fraction": 0.5606648199,
"avg_line_length": 31.1206896552,
"ext": "agda",
"hexsha": "6111fa0d0e7ed9edc02eeb7f88ede2cf8c2035a9",
"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/Issue1545.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/Issue1545.agda",
"max_line_length": 89,
"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/Issue1545.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": 706,
"size": 1805
}
|
{-# OPTIONS --cubical --safe #-}
module WellFounded where
open import Level
data Acc {a r} {A : Type a} (R : A → A → Type r) (x : A) : Type (a ℓ⊔ r) where
acc : (∀ y → R y x → Acc R y) → Acc R x
-- record Acc {a r} {A : Type a} (R : A → A → Type r) (x : A) : Type (a ℓ⊔ r) where
-- inductive
-- constructor acc
-- field step : ∀ y → R y x → Acc R y
-- open Acc public
WellFounded : ∀ {r} → (A → A → Type r) → Type _
WellFounded R = ∀ x → Acc R x
open import HLevels
open import Path
isPropAcc : ∀ {r} {R : A → A → Type r} {x : A} → isProp (Acc R x)
isPropAcc (acc x) (acc y) = cong acc (funExt λ n → funExt λ p → isPropAcc (x n p) (y n p))
|
{
"alphanum_fraction": 0.550304878,
"avg_line_length": 26.24,
"ext": "agda",
"hexsha": "9536ee891068c1784fe32b8a311d5ce5a633298a",
"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": "WellFounded.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": "WellFounded.agda",
"max_line_length": 90,
"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": "WellFounded.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": 258,
"size": 656
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Fixed-size tables of values, implemented as functions from 'Fin n'.
-- Similar to 'Data.Vec', but focusing on ease of retrieval instead of
-- ease of adding and removing elements.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Table where
open import Data.Table.Base public
open import Data.Bool using (true; false)
open import Data.Fin using (Fin; _≟_)
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse using (Inverse; _↔_)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Decidable using (⌊_⌋)
--------------------------------------------------------------------------------
-- Combinators
--------------------------------------------------------------------------------
-- Changes the order of elements in the table according to a permutation (i.e.
-- an 'Inverse' object on the indices).
permute : ∀ {m n a} {A : Set a} → Fin m ↔ Fin n → Table A n → Table A m
permute π = rearrange (Inverse.to π ⟨$⟩_)
-- The result of 'select z i t' takes the value of 'lookup t i' at index 'i',
-- and 'z' everywhere else.
select : ∀ {n} {a} {A : Set a} → A → Fin n → Table A n → Table A n
lookup (select z i t) j with j ≟ i
... | yes _ = lookup t i
... | no _ = z
|
{
"alphanum_fraction": 0.5272596844,
"avg_line_length": 35.7435897436,
"ext": "agda",
"hexsha": "4d0fc4f3a9e57ec24290c80a972bad445367cc28",
"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/Table.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/Table.agda",
"max_line_length": 80,
"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/Table.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 322,
"size": 1394
}
|
{- 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
-}
-- This module provides some scaffolding to define the handlers for our
-- implementation and connect them to the interface of the SystemModel.
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open import LibraBFT.Concrete.Records
open import LibraBFT.Concrete.System
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.Impl.IO.OBM.InputOutputHandlers
open import LibraBFT.Impl.IO.OBM.Properties.InputOutputHandlers
open import LibraBFT.Impl.Properties.Util
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochDep
open import LibraBFT.ImplShared.Interface.Output
open import LibraBFT.ImplShared.Util.Crypto
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.ByteString
open import Util.Encode
open import Util.KVMap
open import Util.Hash
open import Util.Lemmas
open import Util.PKCS
open import Util.Prelude
module LibraBFT.Impl.Handle.Properties where
open EpochConfig
import LibraBFT.Impl.Handle as Handle
open import LibraBFT.Impl.Handle.InitProperties
open initHandlerSpec
open ParamsWithInitAndHandlers Handle.InitHandler.initAndHandlers
open PeerCanSignForPK
open import Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms
Handle.InitHandler.initAndHandlers
PeerCanSignForPK PeerCanSignForPK-stable
open Invariants
open RoundManagerTransProps
-- TODO-1: Should 'invariantsCorrect' and direct corollaries be in a `Properties.Invariants` module?
------------------------------------------------------------------------------
-- For any peer in a reachable state, show that it respects RoundManager invariants.
invariantsCorrect
: ∀ pid (pre : SystemState)
→ initialised pre pid ≡ initd
→ ReachableSystemState pre
→ RoundManagerInv (peerStates pre pid)
--------------------------------------------------
-- AN UNINITIALIZED PEER.
-- A peer has NOT been initialized at 'step-0', therefore it cannot be initialized (i.e., absurd).
invariantsCorrect _ _ () step-0
--------------------------------------------------
-- A CHEATER DOES NOT MODIFY STATE NOR INITIALIZED.
-- pid : the peer we are reasoning about
-- pid' : the peer taking the step
-- in the cheat step case, if does not matter if pid == pid'
-- pre : the prestate of pid
-- pre' : pre state for this reachable state (before the step, i.e., cheat here)
-- preach : evidence that pre' is reachable
-- cheatStepDNMPeerStates₁ : Does Not Modify state
-- cheatStepDNMInitialised₁ : Does Not Modify initialized
invariantsCorrect pid pre ini (step-s {pre = pre'} preach (step-peer step@(step-cheat {pid'} _)))
-- Goal: RoundManagerInv (override (peerStates pre') pid' (peerStates pre' pid') pid)
rewrite cheatStepDNMPeerStates₁ {pid'} {pid} {pre = pre'} step unit
-- Goal: RoundManagerInv (peerStates pre' pid)
with trans (sym $ cheatStepDNMInitialised₁ step unit) ini
...| initialised-pre'-pid≡-initd -- preach : ReachableSystemState pre'
= invariantsCorrect pid pre' initialised-pre'-pid≡-initd preach
--------------------------------------------------
-- Honest steps for the rest of the proof.
-- Note: all these top-level 'invariantsCorrect' are the SAME clause,
-- each with different pattern matching.
--------------------------------------------------
-- PEERS CANNOT MODIFY EACH OTHER'S STATE NOR INITIALIZED STATUS.
-- Reasoning about pid.
-- Peer taking step is different (pid').
invariantsCorrect pid pre ini (step-s {pre = pre'} preach (step-peer step@(step-honest {pid'} sps)))
with pid ≟ pid'
...| no pid≢pid' -- NO case : step is for a different peer (pid') not this peer (pid).
-- In that case pid' cannot modify pid's state,
rewrite sym (pids≢StepDNMPeerStates {pre = pre'} sps pid≢pid')
-- nor pid's initialized status.
= invariantsCorrect pid pre' (trans (pids≢StepDNMInitialised {pre = pre'} sps pid≢pid') ini) preach
--------------------------------------------------
-- INITIALIZATION STEP
-- pre' is pre state of this init step
invariantsCorrect pid _ _ (step-s {pre = pre'} preach (step-peer (step-honest {outs = outs} (step-init {rm} rm×acts _))))
| yes refl -- YES is from the 'with' above
-- because this is the SAME clause except pattern matching deeper to get 'step-init'.
-- Goal: RoundManagerInv ... where peerStates pre' pid "contains" the 'rm' from init
rewrite override-target-≡ {a = pid} {b = rm} {f = peerStates pre'}
-- Goal: RoundManagerInv rm
with initHandlerSpec.contract pid fakeBootstrapInfo rm×acts
...| init-contract
= initHandlerSpec.ContractOk.rmInv init-contract
--------------------------------------------------
-- PROPOSAL MSG
invariantsCorrect pid _ _ (step-s {pre = pre'} preach (step-peer (step-honest (step-msg {sndr , P pm} m∈pool ini))))
| yes refl -- pid≡pid'
-- Goal: RoundManagerInv ... where peerStates pre' pid "contains" the proposal msg
with handleProposalSpec.contract! 0 pm (msgPool pre') (peerStates pre' pid)
...| c -- contract that says proposal has been handled
with handleProposalSpec.Contract.rmInv c
...| invPres -- RoundManagerInv (peerStates pre' pid)
-- → RoundManagerInv where state is updated from proposal message
with invariantsCorrect pid pre' ini preach
...| ic -- RoundManagerInv (peerStates pre' pid)
-- Modify state to contain "results" of handling the proposal.
rewrite override-target-≡ {a = pid} {b = LBFT-post (handleProposal 0 pm) (peerStates pre' pid)} {f = peerStates pre'}
= invPres ic
--------------------------------------------------
-- VOTE MSG
invariantsCorrect pid _ _ (step-s {pre = pre'} preach (step-peer (step-honest (step-msg {sndr , V vm} m∈pool ini))))
| yes refl -- pid≡pid'
with handleVoteSpec.Contract.rmInv $ handleVoteSpec.contract! 0 vm (msgPool pre') (peerStates pre' pid)
...| invPres
rewrite override-target-≡ {a = pid} {b = LBFT-post (handleVote 0 vm) (peerStates pre' pid)} {f = peerStates pre'}
= invPres (invariantsCorrect pid pre' ini preach)
--------------------------------------------------
-- COMMIT MSG
invariantsCorrect pid _ _ (step-s {pre = pre'} preach (step-peer (step-honest (step-msg {sndr , C cm} m∈pool ini))))
| yes refl -- pid≡pid'
rewrite override-target-≡ {a = pid} {b = LBFT-post (handle pid (C cm) 0) (peerStates pre' pid)} {f = peerStates pre'}
= invariantsCorrect pid pre' ini preach
------------------------------------------------------------------------------
-- All signatures represented in QCs that are in the RoundManager for each peer
-- have been sent before (i.e., no peer conjures a signature and makes a QC out of it
-- and stores it).
qcVoteSigsSentB4 :
∀ pid (st : SystemState)
→ initialised st pid ≡ initd
→ ReachableSystemState st
→ QCProps.SigsForVotes∈Rm-SentB4 (msgPool st) (peerStates st pid)
------------------------------------------------------------------------------
-- Handling any messages preserves the above 'qcVoteSigsSentB4' property.
-- Says this indirectly, via ReachableSystemState
-- then says the property holds after executing a handler from that ReachableSystemState.
-- "preserves"
-- - know it is true in the prestate (from qcVoteSigsSendB4)
-- - proving it's true in the poststate.
handlePreservesSigsB4 :
∀ {nm pid pre sndr}
→ initialised pre pid ≡ initd
→ ReachableSystemState pre
→ (sndr , nm) ∈ msgPool pre
→ QCProps.SigsForVotes∈Rm-SentB4 (msgPool pre) (LBFT-post (handle pid nm 0) (peerStates pre pid))
handlePreservesSigsB4 {nm} {pid} {pre} {sndr} ini preach m∈pool {qc} {v} {pk} = hyp
where
hPool = msgPool pre
hPre = peerStates pre pid
hPost = LBFT-post (handle pid nm 0) hPre
qcPost' : (nm' : NetworkMsg) → nm' ≡ nm → QCProps.∈Post⇒∈PreOr (_QC∈NM nm) hPre hPost
qcPost' (P pm) refl = qcPost
where open handleProposalSpec.Contract (handleProposalSpec.contract! 0 pm hPool hPre)
qcPost' (V vm) refl = qcPost
where open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm hPool hPre)
qcPost' (C cm) refl qc qc∈pre = Left qc∈pre
hyp : QCProps.SigForVote∈Rm-SentB4 v pk qc hPost hPool
hyp qc∈hpPst sig {vs} vs∈qcvs ≈v ¬bootstrap
with qcPost' nm refl qc qc∈hpPst
...| Left qc∈hpPre =
qcVoteSigsSentB4 pid pre ini preach qc∈hpPre sig vs∈qcvs ≈v ¬bootstrap
...| Right qc∈m =
mkMsgWithSig∈ nm v (vote∈qc vs∈qcvs ≈v qc∈m) sndr m∈pool sig (cong (_^∙ vSignature) ≈v)
------------------------------------------------------------------------------
qcVoteSigsSentB4 pid st () step-0
qcVoteSigsSentB4 pid st ini (step-s rss (step-peer {pid'} {pre = pre} step@(step-cheat cmc)))
rewrite cheatStepDNMPeerStates₁ {pid'} {pid} {pre = pre} step unit
with trans (sym $ cheatStepDNMInitialised₁ step unit) ini
...| initialised-pre-pid≡-initd
= QCProps.++-SigsForVote∈Rm-SentB4
{rm = peerStates pre pid} _ (qcVoteSigsSentB4 pid pre initialised-pre-pid≡-initd rss)
qcVoteSigsSentB4 pid st ini (step-s rss (step-peer {pid'} {pre = pre} (step-honest sps)))
with pid ≟ pid'
-- DIFFERENT PEER CASE
...| no pid≢pid'
rewrite sym (pids≢StepDNMPeerStates {pre = pre} sps pid≢pid')
= QCProps.++-SigsForVote∈Rm-SentB4
{rm = peerStates pre pid} _
(qcVoteSigsSentB4 pid pre (trans (pids≢StepDNMInitialised {pre = pre} sps pid≢pid') ini) rss)
...| yes refl
with sps
-- INIT CASE
...| step-init {rm} rm×acts _
= ret
where
ret : QCProps.SigsForVotes∈Rm-SentB4 (msgPool st) (peerStates st pid)
ret
with initHandlerSpec.contract pid fakeBootstrapInfo rm×acts
...| init-contract
rewrite override-target-≡ {a = pid} {b = rm} {f = peerStates pre}
= λ qc∈rm sig vs∈qc rbld≈ ¬bootstrap
→ ⊥-elim $
¬bootstrap
(initHandlerSpec.ContractOk.sigs∈bs
init-contract vs∈qc qc∈rm)
-- MSG CASE
...| step-msg {sndr , nm} m∈pool init
rewrite override-target-≡ {a = pid} {b = LBFT-post (handle pid nm 0) (peerStates pre pid)} {f = peerStates pre}
= QCProps.++-SigsForVote∈Rm-SentB4
{rm = LBFT-post (handle pid nm 0) (peerStates pre pid)} _
(handlePreservesSigsB4 init rss m∈pool)
------------------------------------------------------------------------------
qcVoteSigsSentB4-sps
: ∀ pid (pre : SystemState) {s acts}
→ ReachableSystemState pre
→ (StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s , acts))
→ ∀ {qc v pk}
→ qc QCProps.∈RoundManager s
→ WithVerSig pk v
→ ∀ {vs : Author × Signature} → let (pid , sig) = vs in
vs ∈ qcVotes qc → rebuildVote qc vs ≈Vote v
→ ¬ ∈BootstrapInfo-impl fakeBootstrapInfo sig
→ MsgWithSig∈ pk sig (msgPool pre)
qcVoteSigsSentB4-sps pid pre rss (step-init {rm} rm×acts _) qc∈s sig vs∈qcvs ≈v ¬bootstrap
with initHandlerSpec.contract pid fakeBootstrapInfo rm×acts
...| init-contract
rewrite sym $ ++-identityʳ (msgPool pre)
= QCProps.++-SigsForVote∈Rm-SentB4 {rm = rm} (msgPool pre)
(λ qc∈rm sig vs∈qc rbld≈ ¬bootstrap
→ ⊥-elim $
¬bootstrap
(initHandlerSpec.ContractOk.sigs∈bs
init-contract vs∈qc qc∈rm))
qc∈s sig vs∈qcvs ≈v ¬bootstrap
qcVoteSigsSentB4-sps pid pre rss (step-msg {sndr , m} m∈pool ini) {qc} {v} {pk} qc∈s sig {vs} vs∈qcvs ≈v ¬bootstrap
with m
-- TODO-2: refactor for DRY
...| P pm = help
where
hpPre = peerStates pre pid
open handleProposalSpec.Contract (handleProposalSpec.contract! 0 pm (msgPool pre) hpPre)
help : MsgWithSig∈ pk (proj₂ vs) (msgPool pre)
help
with qcPost qc qc∈s
...| Left qc∈pre = qcVoteSigsSentB4 pid pre ini rss qc∈pre sig vs∈qcvs ≈v ¬bootstrap
...| Right qc∈pm =
mkMsgWithSig∈ (P pm) v (vote∈qc vs∈qcvs ≈v qc∈pm) sndr m∈pool sig (cong (_^∙ vSignature) ≈v)
-- TODO-2: refactor for DRY
...| V vm = help
where
hvPre = peerStates pre pid
open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm (msgPool pre) hvPre)
help : MsgWithSig∈ pk (proj₂ vs) (msgPool pre)
help
with qcPost qc qc∈s
...| Left qc∈pre = qcVoteSigsSentB4 pid pre ini rss qc∈pre sig vs∈qcvs ≈v ¬bootstrap
...| Right qc∈vm =
mkMsgWithSig∈ (V vm) v (vote∈qc vs∈qcvs ≈v qc∈vm) sndr m∈pool sig (cong (_^∙ vSignature) ≈v)
...| C cm = qcVoteSigsSentB4 pid pre ini rss qc∈s sig vs∈qcvs ≈v ¬bootstrap
------------------------------------------------------------------------------
lastVotedRound-mono
: ∀ pid (pre : SystemState) {ppost} {msgs}
→ ReachableSystemState pre
→ initialised pre pid ≡ initd
→ StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (ppost , msgs)
→ peerStates pre pid ≡L ppost at rmEpoch
→ Meta.getLastVoteRound ((peerStates pre pid) ^∙ pssSafetyData-rm)
≤
Meta.getLastVoteRound (ppost ^∙ pssSafetyData-rm)
lastVotedRound-mono pid pre preach ini (step-init _ uni) epoch≡ =
case (trans (sym ini) uni) of λ ()
lastVotedRound-mono pid pre {ppost} preach ini₀ (step-msg {_ , m} m∈pool ini₁) epoch≡
with m
...| P pm rewrite sym $ StepPeer-post-lemma {pre = pre} (step-honest (step-msg m∈pool ini₁)) = help
where
hpPool = msgPool pre
hpPre = peerStates pre pid
hpPst = LBFT-post (handleProposal 0 pm) hpPre
hpOut = LBFT-outs (handleProposal 0 pm) hpPre
open handleProposalSpec.Contract (handleProposalSpec.contract! 0 pm hpPool hpPre {- hpReq -} )
open RoundManagerInv (invariantsCorrect pid pre ini₁ preach)
module VoteOld (lv≡ : hpPre ≡L hpPst at pssSafetyData-rm ∙ sdLastVote) where
help : Meta.getLastVoteRound (hpPre ^∙ pssSafetyData-rm) ≤ Meta.getLastVoteRound (hpPst ^∙ pssSafetyData-rm)
help = ≡⇒≤ (cong (Maybe-maybe {B = const ℕ} (_^∙ vRound) 0) lv≡)
module VoteNew {vote : Vote}
(lv≡v : just vote ≡ hpPst ^∙ pssSafetyData-rm ∙ sdLastVote)
(lvr< : hpPre [ _<_ ]L hpPst at pssSafetyData-rm ∙ sdLastVotedRound)
(lvr≡ : vote ^∙ vRound ≡ hpPst ^∙ pssSafetyData-rm ∙ sdLastVotedRound )
where
help : Meta.getLastVoteRound (hpPre ^∙ pssSafetyData-rm) ≤ Meta.getLastVoteRound (hpPst ^∙ pssSafetyData-rm)
help = ≤-trans (SafetyDataInv.lvRound≤ ∘ SafetyRulesInv.sdInv $ rmSafetyRulesInv ) (≤-trans (<⇒≤ lvr<) (≡⇒≤ (trans (sym lvr≡) $ cong (Maybe-maybe {B = const ℕ} (_^∙ vRound) 0) lv≡v)))
open Invariants
open Reqs (pm ^∙ pmProposal) (hpPre ^∙ lBlockTree)
open BlockTreeInv
open BlockStoreInv
open RoundManagerInv
rmi : _
rmi = invariantsCorrect pid pre ini₁ preach
help : Meta.getLastVoteRound (hpPre ^∙ pssSafetyData-rm) ≤ Meta.getLastVoteRound (hpPst ^∙ pssSafetyData-rm)
help
with BlockId-correct? (pm ^∙ pmProposal)
...| no ¬validProposal
= VoteOld.help (cong (_^∙ pssSafetyData-rm ∙ sdLastVote) (proj₁ $ invalidProposal ¬validProposal))
...| yes pmIdCorr
with voteAttemptCorrect pmIdCorr (nohc preach m∈pool pid ini₀ rmi refl pmIdCorr)
...| Voting.mkVoteAttemptCorrectWithEpochReq (inj₁ (_ , Voting.mkVoteUnsentCorrect noVoteMsgOuts nvg⊎vgusc)) sdEpoch≡?
with nvg⊎vgusc
...| inj₁ (mkVoteNotGenerated lv≡ lvr≤) = VoteOld.help lv≡
...| inj₂ (Voting.mkVoteGeneratedUnsavedCorrect vote (Voting.mkVoteGeneratedCorrect (mkVoteGenerated lv≡v voteSrc) blockTriggered))
with voteSrc
...| inj₁ (mkVoteOldGenerated lvr≡ lv≡) = VoteOld.help lv≡
...| inj₂ (mkVoteNewGenerated lvr< lvr≡) = VoteNew.help lv≡v lvr< lvr≡
help
| yes refl
| Voting.mkVoteAttemptCorrectWithEpochReq (Right (Voting.mkVoteSentCorrect vm _ _ (Voting.mkVoteGeneratedCorrect (mkVoteGenerated lv≡v voteSrc) _))) sdEpoch≡?
with voteSrc
...| Left (mkVoteOldGenerated lvr≡ lv≡) = VoteOld.help lv≡
...| Right (mkVoteNewGenerated lvr< lvr≡) = VoteNew.help lv≡v lvr< lvr≡
-- Receiving a vote or commit message does not update the last vote
...| V vm = ≡⇒≤ $ cong (Maybe-maybe (_^∙ vRound) 0 ∘ (_^∙ sdLastVote)) noSDChange
where
hvPre = peerStates pre pid
hvPst = LBFT-post (handle pid (V vm) 0) hvPre
open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm (msgPool pre) hvPre)
...| C cm = ≤-refl
------------------------------------------------------------------------------
qcVoteSigsSentB4-handle
: ∀ pid {pre m s acts}
→ ReachableSystemState pre
→ (StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s , acts))
→ send m ∈ acts
→ ∀ {qc v pk}
→ qc QC∈NM m
→ WithVerSig pk v
→ ∀ {vs : Author × Signature} → let (pid , sig) = vs in vs ∈ qcVotes qc
→ rebuildVote qc vs ≈Vote v
→ ¬ ∈BootstrapInfo-impl fakeBootstrapInfo sig
→ MsgWithSig∈ pk sig (msgPool pre)
qcVoteSigsSentB4-handle pid {pre} {m} {s} {acts} preach
(step-init {rm} rm×acts _)
send∈acts
{qc}
qc∈m sig vs∈qc v≈rbld ¬bootstrap
with initHandlerSpec.contract pid fakeBootstrapInfo rm×acts
...| init-contract
with initHandlerSpec.ContractOk.isInitPM init-contract send∈acts
...| _ , refl , noSigs = ⊥-elim (noSigs vs∈qc qc∈m)
qcVoteSigsSentB4-handle pid {pre} {m} {s} {acts} preach
sps@(step-msg {_ , nm} m∈pool ini)
m∈acts
{qc} qc∈m sig vs∈qc v≈rbld ¬bootstrap =
qcVoteSigsSentB4-sps pid pre preach sps qc∈rm sig vs∈qc v≈rbld ¬bootstrap
where
hdPool = msgPool pre
hdPre = peerStates pre pid
hdPst = LBFT-post (handle pid nm 0) hdPre
hdOut = LBFT-outs (handle pid nm 0) hdPre
qc∈rm : qc QCProps.∈RoundManager hdPst
qc∈rm
with sendMsg∈actions {hdOut} {st = hdPre} m∈acts
...| out , out∈hdOut , m∈out = All-lookup (outQcs∈RM1 nm refl) out∈hdOut qc m qc∈m m∈out
where
outQcs∈RM1 : (nm' : NetworkMsg) → nm ≡ nm' → QCProps.OutputQc∈RoundManager hdOut hdPst
outQcs∈RM1 (P pm) refl = outQcs∈RM
where open handleProposalSpec.Contract (handleProposalSpec.contract! 0 pm hdPool hdPre)
outQcs∈RM1 (V vm) refl = outQcs∈RM
where open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm hdPool hdPre)
|
{
"alphanum_fraction": 0.6526022,
"avg_line_length": 44.0313253012,
"ext": "agda",
"hexsha": "858aa312e2ff1e1a07059515eb0016ada419f44c",
"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/Handle/Properties.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/Handle/Properties.agda",
"max_line_length": 187,
"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/Handle/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5690,
"size": 18273
}
|
{-# OPTIONS --prop --without-K --rewriting #-}
-- Common cost monoids.
module Calf.CostMonoids where
open import Calf.CostMonoid
open import Data.Product
open import Relation.Binary.PropositionalEquality
ℕ-CostMonoid : CostMonoid
ℕ-CostMonoid = record
{ ℂ = ℕ
; _+_ = _+_
; zero = zero
; _≤_ = _≤_
; isCostMonoid = record
{ isMonoid = +-0-isMonoid
; isCancellative = record { ∙-cancel-≡ = +-cancel-≡ }
; isPreorder = ≤-isPreorder
; isMonotone = record { ∙-mono-≤ = +-mono-≤ }
}
}
where
open import Data.Nat
open import Data.Nat.Properties
ℕ-Work-ParCostMonoid : ParCostMonoid
ℕ-Work-ParCostMonoid = record
{ ℂ = ℕ
; _⊕_ = _+_
; 𝟘 = 0
; _⊗_ = _+_
; 𝟙 = 0
; _≤_ = _≤_
; isParCostMonoid = record
{ isMonoid = +-0-isMonoid
; isCommutativeMonoid = +-0-isCommutativeMonoid
; isCancellative = record { ∙-cancel-≡ = +-cancel-≡ }
; isPreorder = ≤-isPreorder
; isMonotone-⊕ = record { ∙-mono-≤ = +-mono-≤ }
; isMonotone-⊗ = record { ∙-mono-≤ = +-mono-≤ }
}
}
where
open import Data.Nat
open import Data.Nat.Properties
ℕ-Span-ParCostMonoid : ParCostMonoid
ℕ-Span-ParCostMonoid = record
{ ℂ = ℕ
; _⊕_ = _+_
; 𝟘 = 0
; _⊗_ = _⊔_
; 𝟙 = 0
; _≤_ = _≤_
; isParCostMonoid = record
{ isMonoid = +-0-isMonoid
; isCommutativeMonoid = ⊔-0-isCommutativeMonoid
; isPreorder = ≤-isPreorder
; isCancellative = record { ∙-cancel-≡ = +-cancel-≡ }
; isMonotone-⊕ = record { ∙-mono-≤ = +-mono-≤ }
; isMonotone-⊗ = record { ∙-mono-≤ = ⊔-mono-≤ }
}
}
where
open import Data.Nat
open import Data.Nat.Properties
combineParCostMonoids : ParCostMonoid → ParCostMonoid → ParCostMonoid
combineParCostMonoids pcm₁ pcm₂ = record
{ ℂ = ℂ pcm₁ × ℂ pcm₂
; _⊕_ = λ (a₁ , a₂) (b₁ , b₂) → _⊕_ pcm₁ a₁ b₁ , _⊕_ pcm₂ a₂ b₂
; 𝟘 = 𝟘 pcm₁ , 𝟘 pcm₂
; _⊗_ = λ (a₁ , a₂) (b₁ , b₂) → _⊗_ pcm₁ a₁ b₁ , _⊗_ pcm₂ a₂ b₂
; 𝟙 = 𝟙 pcm₁ , 𝟙 pcm₂
; _≤_ = λ (a₁ , a₂) (b₁ , b₂) → _≤_ pcm₁ a₁ b₁ × _≤_ pcm₂ a₂ b₂
; isParCostMonoid = record
{ isMonoid = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = λ h₁ h₂ →
cong₂ _,_
(cong₂ (_⊕_ pcm₁) (cong proj₁ h₁) (cong proj₁ h₂))
(cong₂ (_⊕_ pcm₂) (cong proj₂ h₁) (cong proj₂ h₂))
}
; assoc = λ (a₁ , a₂) (b₁ , b₂) (c₁ , c₂) → cong₂ _,_ (⊕-assoc pcm₁ a₁ b₁ c₁) (⊕-assoc pcm₂ a₂ b₂ c₂)
}
; identity =
(λ (a₁ , a₂) → cong₂ _,_ (⊕-identityˡ pcm₁ a₁) (⊕-identityˡ pcm₂ a₂)) ,
(λ (a₁ , a₂) → cong₂ _,_ (⊕-identityʳ pcm₁ a₁) (⊕-identityʳ pcm₂ a₂))
}
; isCommutativeMonoid = record
{ isMonoid = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = λ h₁ h₂ →
cong₂ _,_
(cong₂ (_⊗_ pcm₁) (cong proj₁ h₁) (cong proj₁ h₂))
(cong₂ (_⊗_ pcm₂) (cong proj₂ h₁) (cong proj₂ h₂))
}
; assoc = λ (a₁ , a₂) (b₁ , b₂) (c₁ , c₂) → cong₂ _,_ (⊗-assoc pcm₁ a₁ b₁ c₁) (⊗-assoc pcm₂ a₂ b₂ c₂)
}
; identity =
(λ (a₁ , a₂) → cong₂ _,_ (⊗-identityˡ pcm₁ a₁) (⊗-identityˡ pcm₂ a₂)) ,
(λ (a₁ , a₂) → cong₂ _,_ (⊗-identityʳ pcm₁ a₁) (⊗-identityʳ pcm₂ a₂))
}
; comm = λ (a₁ , a₂) (b₁ , b₂) → cong₂ _,_ (⊗-comm pcm₁ a₁ b₁) (⊗-comm pcm₂ a₂ b₂)
}
; isCancellative = record
{ ∙-cancel-≡ =
(λ (x₁ , x₂) h → cong₂ _,_ (⊕-cancelˡ-≡ pcm₁ x₁ (cong proj₁ h)) (⊕-cancelˡ-≡ pcm₂ x₂ (cong proj₂ h))) ,
(λ (y₁ , y₂) (z₁ , z₂) h → cong₂ _,_ (⊕-cancelʳ-≡ pcm₁ y₁ z₁ (cong proj₁ h)) (⊕-cancelʳ-≡ pcm₂ y₂ z₂ (cong proj₂ h)))
}
; isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = λ { refl → ≤-refl pcm₁ , ≤-refl pcm₂ }
; trans = λ (h₁ , h₂) (h₁' , h₂') → ≤-trans pcm₁ h₁ h₁' , ≤-trans pcm₂ h₂ h₂'
}
; isMonotone-⊕ = record
{ ∙-mono-≤ = λ (h₁ , h₂) (h₁' , h₂') → ⊕-mono-≤ pcm₁ h₁ h₁' , ⊕-mono-≤ pcm₂ h₂ h₂'
}
; isMonotone-⊗ = record
{ ∙-mono-≤ = λ (h₁ , h₂) (h₁' , h₂') → ⊗-mono-≤ pcm₁ h₁ h₁' , ⊗-mono-≤ pcm₂ h₂ h₂'
}
}
}
where open ParCostMonoid
ℕ²-ParCostMonoid : ParCostMonoid
ℕ²-ParCostMonoid = combineParCostMonoids ℕ-Work-ParCostMonoid ℕ-Span-ParCostMonoid
|
{
"alphanum_fraction": 0.5407373691,
"avg_line_length": 32.7910447761,
"ext": "agda",
"hexsha": "1331be2d113fc8d95ee85205b6575fe19a92d783",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Calf/CostMonoids.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Calf/CostMonoids.agda",
"max_line_length": 127,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Calf/CostMonoids.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 1960,
"size": 4394
}
|
module Data.Sum.Instance where
open import Class.Equality
open import Class.Monoid
open import Class.Show
open import Data.Bool using (false)
open import Data.String.Instance
open import Data.Sum
open import Data.Sum.Properties
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
instance
Sum-Eq : {A B : Set} -> {{_ : Eq A}} -> {{_ : Eq B}} -> Eq (A ⊎ B)
Sum-Eq = record { _≟_ = ≡-dec _≟_ _≟_ }
Sum-Show : {A B : Set} -> {{_ : Show A}} -> {{_ : Show B}} -> Show (A ⊎ B)
Sum-Show = record { show = λ { (inj₁ x) → "inj₁ " + show x ; (inj₂ y) → "inj₂ " + show y } }
Sum-EqB : {A B : Set} -> {{_ : EqB A}} -> {{_ : EqB B}} -> EqB (A ⊎ B)
Sum-EqB = record { _≣_ = λ { (inj₁ x) (inj₁ y) → x ≣ y
; (inj₁ x) (inj₂ y) → false
; (inj₂ x) (inj₁ y) → false
; (inj₂ x) (inj₂ y) → x ≣ y } }
|
{
"alphanum_fraction": 0.5286343612,
"avg_line_length": 36.32,
"ext": "agda",
"hexsha": "c1241b4a479bc25e2368010ea7ea9b6a1dc4c12c",
"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/Sum/Instance.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/Sum/Instance.agda",
"max_line_length": 94,
"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/Sum/Instance.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": 325,
"size": 908
}
|
open import Data.Bool using (Bool; true; false)
open import Data.Empty using (⊥)
open import Data.Unit using (⊤; tt)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)
open import Relation.Nullary using (¬_)
--data _≡_ {A : Set} (x : A) : A → Set where
-- refl : x ≡ x
trans : ∀ {a} {A : Set a} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
-- This can be done in Coq but not in Agda?
--disc'' : ∀ {x : Bool} → x ≡ x → x ≡ (¬ x) → ⊥
--disc'' = ?
-- How to prove this???
disc' : ∀ {a} {x : Set a} → x ≡ x → x ≡ (¬ x) → ⊥
disc' refl = ?
disc : ∀ {a} {x : Set a} → ¬ (x ≡ (¬ x))
disc {x} x≡¬x = ? -- disc' ? ? -- (refl {x}) x≡¬x
open import Data.Nat using (ℕ; suc; zero; _+_)
right-zero : ∀ n → n + 0 ≡ n
right-zero 0 = refl
right-zero (suc n) = cong suc (right-zero n)
comm : ∀ m n p → m + (n + p) ≡ (m + n) + p
comm 0 _ _ = refl
comm (suc m) n p = cong suc (comm m n p)
|
{
"alphanum_fraction": 0.5366120219,
"avg_line_length": 26.9117647059,
"ext": "agda",
"hexsha": "873e1c9b1fd72af1bd095292e94a30c5b168d262",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "helq/old_code",
"max_forks_repo_path": "proglangs-learning/Coq/agdag.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z",
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "helq/old_code",
"max_issues_repo_path": "proglangs-learning/Coq/agdag.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "helq/old_code",
"max_stars_repo_path": "proglangs-learning/Coq/agdag.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 374,
"size": 915
}
|
{-# OPTIONS --allow-unsolved-metas #-}
module Avionics.Probability where
--open import Data.Fin using (Fin; fromℕ<)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product using (_×_; _,_)
open import Data.Vec using (Vec; lookup)
open import Relation.Binary.PropositionalEquality using (refl)
open import Relation.Unary using (_∈_)
open import Avionics.Real using (
ℝ; _+_; _-_; _*_; _÷_; _^_; √_; 1/_; _^2;
-1/2; π; e; 2ℝ; 1ℝ; 0ℝ;
⟨0,∞⟩; [0,∞⟩; [0,1])
record Dist (Input : Set) : Set where
field
pdf : Input → ℝ
cdf : Input → ℝ
pdf→[0,∞⟩ : ∀ x → pdf x ∈ [0,∞⟩
cdf→[0,1] : ∀ x → cdf x ∈ [0,1]
--∫pdf≡cdf : ∫ pdf ≡ cdf
--∫pdf[-∞,∞]≡1ℝ : ∫ pdf [ -∞ , ∞ ] ≡ 1ℝ
record NormalDist : Set where
constructor ND
field
μ : ℝ
σ : ℝ
--.0<σ : 0ℝ <? σ
dist : Dist ℝ
dist = record
{
pdf = pdf
; cdf = ?
; pdf→[0,∞⟩ = ?
; cdf→[0,1] = ?
}
where
√2π = (√ (2ℝ * π))
1/⟨σ√2π⟩ = (1/ (σ * √2π))
pdf : ℝ → ℝ
pdf x = 1/⟨σ√2π⟩ * e ^ (-1/2 * (⟨x-μ⟩÷σ ^2))
where
⟨x-μ⟩÷σ = ((x - μ) ÷ σ)
-- Bivariate Normal Distribution
-- Representation taken from: https://upload.wikimedia.org/wikipedia/commons/a/a2/Cumulative_function_n_dimensional_Gaussians_12.2013.pdf
record BiNormalDist : Set where
constructor ND
field
μ₁ : ℝ
μ₂ : ℝ
σ₁ : ℝ
σ₂ : ℝ
ρ : ℝ
μ : ℝ × ℝ
μ = μ₁ , μ₂
Σ : ℝ × ℝ × ℝ × ℝ
Σ = σ₁ , (ρ * σ₁ * σ₂) , (ρ * σ₁ * σ₂) , σ₂
Σ-¹ : ℝ × ℝ × ℝ × ℝ
Σ-¹ = ( 1/1-ρ² * (1ℝ ÷ σ₁)
, 1/1-ρ² * -ρ/σ₁σ₂
, 1/1-ρ² * -ρ/σ₁σ₂
, 1/1-ρ² * (1ℝ ÷ σ₂))
where 1/1-ρ² = 1ℝ ÷ (1ℝ - ρ * ρ)
-ρ/σ₁σ₂ = (0ℝ - ρ) ÷ (σ₁ * σ₂)
dist : Dist ℝ
dist = record
{
pdf = ?
; cdf = ?
; pdf→[0,∞⟩ = ?
; cdf→[0,1] = ?
}
Mat : ℕ → Set
Mat n = Vec (Vec ℝ n) n
-- Multivariate Normal Distribution
record MultiNormal : Set where
constructor MultiND
field
n : ℕ
μ : Vec ℝ n
Σ : Mat n
dist : Dist (Vec ℝ n)
dist = record
{
pdf = ?
; cdf = ?
; pdf→[0,∞⟩ = ?
; cdf→[0,1] = ?
}
--num : Vec ℕ 2 → ℕ
--num vec = lookup vec (fromℕ< {0} _)
--num2 : MultiNormal → ℝ
--num2 mn = lookup μ (fromℕ< {0} _)
-- where open MultiNormal mn using (n; μ; Σ) --; dist)
-- --open Dist dist using (pdf)
|
{
"alphanum_fraction": 0.4948409286,
"avg_line_length": 20.954954955,
"ext": "agda",
"hexsha": "9f1ce6344719b71b44100c6a50ba46b48bf7f0bc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-09-20T00:36:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-09-20T00:36:09.000Z",
"max_forks_repo_head_hexsha": "bf518286f9d06dc6ea91e111be6ddedb3e2b728f",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "helq/safety-envelopes-sentinels",
"max_forks_repo_path": "agda/Avionics/Probability.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bf518286f9d06dc6ea91e111be6ddedb3e2b728f",
"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": "helq/safety-envelopes-sentinels",
"max_issues_repo_path": "agda/Avionics/Probability.agda",
"max_line_length": 137,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bf518286f9d06dc6ea91e111be6ddedb3e2b728f",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "helq/safety-envelopes-sentinels",
"max_stars_repo_path": "agda/Avionics/Probability.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1027,
"size": 2326
}
|
{-# IMPORT Issue223 #-}
data A : Set
{-# COMPILED_DECLARE_DATA A Issue223.A #-}
data B : Set
{-# COMPILED_DECLARE_DATA B Issue223.B #-}
data A where
BA : B → A
{-# COMPILED_DATA A Issue223.A Issue223.BA #-}
data B where
AB : A → B
BB : B
{-# COMPILED_DATA B Issue223.B Issue223.AB Issue223.BB #-}
|
{
"alphanum_fraction": 0.6482084691,
"avg_line_length": 18.0588235294,
"ext": "agda",
"hexsha": "69e4f62521e2fb1e0dbbf8785aa511e8345f1155",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Compiler/simple/Issue223.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/Compiler/simple/Issue223.agda",
"max_line_length": 58,
"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/Compiler/simple/Issue223.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 96,
"size": 307
}
|
{-# OPTIONS --cubical --safe --no-sized-types --no-guardedness #-}
module Agda.Builtin.Cubical.Path where
open import Agda.Primitive.Cubical
postulate
PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ
{-# BUILTIN PATHP PathP #-}
infix 4 _≡_
_≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
_≡_ {A = A} = PathP (λ _ → A)
{-# BUILTIN PATH _≡_ #-}
|
{
"alphanum_fraction": 0.5234375,
"avg_line_length": 24,
"ext": "agda",
"hexsha": "7e8e4d4856b883cb9a82c273f23a661f589918c3",
"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": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "phadej/agda",
"max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/Path.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"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": "phadej/agda",
"max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/Path.agda",
"max_line_length": 66,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "phadej/agda",
"max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/Path.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 154,
"size": 384
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Category.Monoidal.Core using (Monoidal)
module Categories.Category.Monoidal.Braided {o ℓ e} {C : Category o ℓ e} (M : Monoidal C) where
open import Level
open import Data.Product using (Σ; _,_)
open import Categories.Functor.Bifunctor
open import Categories.NaturalTransformation.NaturalIsomorphism
open Category C
open Commutation
private
variable
X Y Z : Obj
-- braided monoidal category
-- it has a braiding natural isomorphism has two hexagon identities.
-- these two identities are directly expressed in the morphism level.
record Braided : Set (levelOfTerm M) where
open Monoidal M public
field
braiding : NaturalIsomorphism ⊗ (flip-bifunctor ⊗)
module braiding = NaturalIsomorphism braiding
private
B : ∀ {X Y} → X ⊗₀ Y ⇒ Y ⊗₀ X
B {X} {Y} = braiding.⇒.η (X , Y)
field
hexagon₁ : [ (X ⊗₀ Y) ⊗₀ Z ⇒ Y ⊗₀ Z ⊗₀ X ]⟨
B ⊗₁ id ⇒⟨ (Y ⊗₀ X) ⊗₀ Z ⟩
associator.from ⇒⟨ Y ⊗₀ X ⊗₀ Z ⟩
id ⊗₁ B
≈ associator.from ⇒⟨ X ⊗₀ Y ⊗₀ Z ⟩
B ⇒⟨ (Y ⊗₀ Z) ⊗₀ X ⟩
associator.from
⟩
hexagon₂ : [ X ⊗₀ Y ⊗₀ Z ⇒ (Z ⊗₀ X) ⊗₀ Y ]⟨
id ⊗₁ B ⇒⟨ X ⊗₀ Z ⊗₀ Y ⟩
(associator.to ⇒⟨ (X ⊗₀ Z) ⊗₀ Y ⟩
B ⊗₁ id)
≈ associator.to ⇒⟨ (X ⊗₀ Y) ⊗₀ Z ⟩
(B ⇒⟨ Z ⊗₀ X ⊗₀ Y ⟩
associator.to)
⟩
|
{
"alphanum_fraction": 0.5039274924,
"avg_line_length": 30.6481481481,
"ext": "agda",
"hexsha": "58a26aa4b56b4098d8df7d97e504415eb528bab8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Monoidal/Braided.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Monoidal/Braided.agda",
"max_line_length": 95,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Monoidal/Braided.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 524,
"size": 1655
}
|
-- this is the first test I run
-- Its been a while since i used my brain, @KMx404
module test1 where
data 𝕟 : Set where
--zero : 𝕟 --its not practical to do so, we can use more efficient math formulas
suc : 𝕟 → 𝕟 -- since We have the value of zero => n, any next item succ will consider it as n.num
_+_ : 𝕟 → 𝕟 → 𝕟 -- Defining addition? I guess (wtf is guess? haha)
-- zero : zero
--zero + zero = zero
--zero + 𝕟 = 𝕟 -- Zero has no effect in addition
|
{
"alphanum_fraction": 0.6293995859,
"avg_line_length": 21.9545454545,
"ext": "agda",
"hexsha": "fae155c55e7162ac9cb57f6bf638a8024888c9a9",
"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": "b2cf336215025de01b3b3f4b2296f9afd7c2d295",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "KMx404/selfev.agda",
"max_forks_repo_path": "intro/tests/test1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b2cf336215025de01b3b3f4b2296f9afd7c2d295",
"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": "KMx404/selfev.agda",
"max_issues_repo_path": "intro/tests/test1.agda",
"max_line_length": 100,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "b2cf336215025de01b3b3f4b2296f9afd7c2d295",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "KMx404/selfev.agda",
"max_stars_repo_path": "intro/tests/test1.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-12T15:57:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-08-18T11:22:21.000Z",
"num_tokens": 160,
"size": 483
}
|
module Base.Free.Instance.Identity where
open import Data.Empty using (⊥)
open import Base.Free using (Free)
-- Representation of the `Identity` monad using free.
Shape : Set
Shape = ⊥
Position : Shape → Set
Position _ = ⊥
Identity : Set → Set
Identity = Free Shape Position
|
{
"alphanum_fraction": 0.7234042553,
"avg_line_length": 16.5882352941,
"ext": "agda",
"hexsha": "6e7a51e64916a78f7db0cf8b7ecb69ebc6a4c0b9",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-05-14T07:48:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-08T11:23:46.000Z",
"max_forks_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "FreeProving/free-compiler",
"max_forks_repo_path": "base/agda/Base/Free/Instance/Identity.agda",
"max_issues_count": 120,
"max_issues_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_issues_repo_issues_event_max_datetime": "2020-12-08T07:46:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-04-09T09:40:39.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "FreeProving/free-compiler",
"max_issues_repo_path": "base/agda/Base/Free/Instance/Identity.agda",
"max_line_length": 53,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "FreeProving/free-compiler",
"max_stars_repo_path": "base/agda/Base/Free/Instance/Identity.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-21T13:38:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-06T11:03:34.000Z",
"num_tokens": 71,
"size": 282
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.ZCohomology.Groups.Sn where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.MayerVietorisUnreduced
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.Groups.Connected
open import Cubical.ZCohomology.KcompPrelims
open import Cubical.ZCohomology.Groups.Prelims
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn
open import Cubical.HITs.S1
open import Cubical.HITs.Susp
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2 ; map to sMap)
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; elim to pElim ; elim2 to pElim2 ; ∥_∥ to ∥_∥₁ ; ∣_∣ to ∣_∣₁) hiding (map)
open import Cubical.Data.Bool
open import Cubical.Data.Sigma
open import Cubical.Data.Int renaming (_+_ to _+ℤ_; +-comm to +ℤ-comm ; +-assoc to +ℤ-assoc)
open import Cubical.Data.Nat
open import Cubical.HITs.Truncation renaming (elim to trElim ; map to trMap ; rec to trRec)
open import Cubical.Data.Unit
open import Cubical.Homotopy.Connected
open import Cubical.Algebra.Group
infixr 31 _□_
_□_ : _
_□_ = compGroupIso
open GroupEquiv
open vSES
open GroupIso
open GroupHom
open BijectionIso
Sn-connected : (n : ℕ) (x : typ (S₊∙ (suc n))) → ∥ pt (S₊∙ (suc n)) ≡ x ∥₁
Sn-connected zero = toPropElim (λ _ → propTruncIsProp) ∣ refl ∣₁
Sn-connected (suc zero) = suspToPropElim base (λ _ → propTruncIsProp) ∣ refl ∣₁
Sn-connected (suc (suc n)) = suspToPropElim north (λ _ → propTruncIsProp) ∣ refl ∣₁
H⁰-Sⁿ≅ℤ : (n : ℕ) → GroupIso (coHomGr 0 (S₊ (suc n))) intGroup
H⁰-Sⁿ≅ℤ zero = H⁰-connected base (Sn-connected 0)
H⁰-Sⁿ≅ℤ (suc n) = H⁰-connected north (Sn-connected (suc n))
-- -- ----------------------------------------------------------------------
--- We will need to switch between Sⁿ defined using suspensions and using pushouts
--- in order to apply Mayer Vietoris.
S1Iso : Iso S¹ (Pushout {A = Bool} (λ _ → tt) λ _ → tt)
S1Iso = S¹IsoSuspBool ⋄ invIso PushoutSuspIsoSusp
coHomPushout≅coHomSn : (n m : ℕ) → GroupIso (coHomGr m (S₊ (suc n)))
(coHomGr m (Pushout {A = S₊ n} (λ _ → tt) λ _ → tt))
coHomPushout≅coHomSn zero m =
Iso+Hom→GrIso (setTruncIso (domIso S1Iso))
(sElim2 (λ _ _ → isSet→isGroupoid setTruncIsSet _ _) (λ _ _ → refl))
coHomPushout≅coHomSn (suc n) m =
Iso+Hom→GrIso (setTruncIso (domIso (invIso PushoutSuspIsoSusp)))
(sElim2 (λ _ _ → isSet→isGroupoid setTruncIsSet _ _) (λ _ _ → refl))
-------------------------- H⁰(S⁰) -----------------------------
S0→Int : (a : Int × Int) → S₊ 0 → Int
S0→Int a true = fst a
S0→Int a false = snd a
H⁰-S⁰≅ℤ×ℤ : GroupIso (coHomGr 0 (S₊ 0)) (dirProd intGroup intGroup)
fun (map H⁰-S⁰≅ℤ×ℤ) = sRec (isSet× isSetInt isSetInt) λ f → (f true) , (f false)
isHom (map H⁰-S⁰≅ℤ×ℤ) = sElim2 (λ _ _ → isSet→isGroupoid (isSet× isSetInt isSetInt) _ _)
λ a b i → addLemma (a true) (b true) i , addLemma (a false) (b false) i
inv H⁰-S⁰≅ℤ×ℤ a = ∣ S0→Int a ∣₂
rightInv H⁰-S⁰≅ℤ×ℤ _ = refl
leftInv H⁰-S⁰≅ℤ×ℤ = sElim (λ _ → isSet→isGroupoid setTruncIsSet _ _)
λ f → cong ∣_∣₂ (funExt (λ {true → refl ; false → refl}))
------------------------- H¹(S⁰) ≅ 0 -------------------------------
private
Hⁿ-S0≃Kₙ×Kₙ : (n : ℕ) → Iso (S₊ 0 → coHomK (suc n)) (coHomK (suc n) × coHomK (suc n))
Iso.fun (Hⁿ-S0≃Kₙ×Kₙ n) f = (f true) , (f false)
Iso.inv (Hⁿ-S0≃Kₙ×Kₙ n) (a , b) true = a
Iso.inv (Hⁿ-S0≃Kₙ×Kₙ n) (a , b) false = b
Iso.rightInv (Hⁿ-S0≃Kₙ×Kₙ n) a = refl
Iso.leftInv (Hⁿ-S0≃Kₙ×Kₙ n) b = funExt λ {true → refl ; false → refl}
isContrHⁿ-S0 : (n : ℕ) → isContr (coHom (suc n) (S₊ 0))
isContrHⁿ-S0 n = isContrRetract (Iso.fun (setTruncIso (Hⁿ-S0≃Kₙ×Kₙ n)))
(Iso.inv (setTruncIso (Hⁿ-S0≃Kₙ×Kₙ n)))
(Iso.leftInv (setTruncIso (Hⁿ-S0≃Kₙ×Kₙ n)))
(isContrHelper n)
where
isContrHelper : (n : ℕ) → isContr (∥ (coHomK (suc n) × coHomK (suc n)) ∥₂)
fst (isContrHelper zero) = ∣ (0₁ , 0₁) ∣₂
snd (isContrHelper zero) = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ y → elim2 {B = λ x y → ∣ (0₁ , 0₁) ∣₂ ≡ ∣(x , y) ∣₂ }
(λ _ _ → isOfHLevelPlus {n = 2} 2 setTruncIsSet _ _)
(toPropElim2 (λ _ _ → setTruncIsSet _ _) refl) (fst y) (snd y)
isContrHelper (suc zero) = ∣ (0₂ , 0₂) ∣₂
, sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ y → elim2 {B = λ x y → ∣ (0₂ , 0₂) ∣₂ ≡ ∣(x , y) ∣₂ }
(λ _ _ → isOfHLevelPlus {n = 2} 3 setTruncIsSet _ _)
(suspToPropElim2 base (λ _ _ → setTruncIsSet _ _) refl) (fst y) (snd y)
isContrHelper (suc (suc n)) = ∣ (0ₖ (3 + n) , 0ₖ (3 + n)) ∣₂
, sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ y → elim2 {B = λ x y → ∣ (0ₖ (3 + n) , 0ₖ (3 + n)) ∣₂ ≡ ∣(x , y) ∣₂ }
(λ _ _ → isProp→isOfHLevelSuc (4 + n) (setTruncIsSet _ _))
(suspToPropElim2 north (λ _ _ → setTruncIsSet _ _) refl) (fst y) (snd y)
H¹-S⁰≅0 : (n : ℕ) → GroupIso (coHomGr (suc n) (S₊ 0)) trivialGroup
H¹-S⁰≅0 n = IsoContrGroupTrivialGroup (isContrHⁿ-S0 n)
------------------------- H²(S¹) ≅ 0 -------------------------------
Hⁿ-S¹≅0 : (n : ℕ) → GroupIso (coHomGr (2 + n) (S₊ 1)) trivialGroup
Hⁿ-S¹≅0 n = IsoContrGroupTrivialGroup
(isOfHLevelRetractFromIso 0 helper
(_ , helper2))
where
helper : Iso ⟨ coHomGr (2 + n) (S₊ 1)⟩ ∥ Σ (hLevelTrunc (4 + n) (S₊ (2 + n))) (λ x → ∥ x ≡ x ∥₂) ∥₂
helper = compIso (setTruncIso IsoFunSpaceS¹) IsoSetTruncateSndΣ
helper2 : (x : ∥ Σ (hLevelTrunc (4 + n) (S₊ (2 + n))) (λ x → ∥ x ≡ x ∥₂) ∥₂) → ∣ ∣ north ∣ , ∣ refl ∣₂ ∣₂ ≡ x
helper2 =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(uncurry
(trElim (λ _ → isOfHLevelΠ (4 + n) λ _ → isProp→isOfHLevelSuc (3 + n) (setTruncIsSet _ _))
(suspToPropElim (ptSn (suc n)) (λ _ → isPropΠ λ _ → setTruncIsSet _ _)
(sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ p
→ cong ∣_∣₂ (ΣPathP (refl , isContr→isProp helper3 _ _))))))
where
helper4 : isConnected (n + 3) (hLevelTrunc (4 + n) (S₊ (2 + n)))
helper4 = subst (λ m → isConnected m (hLevelTrunc (4 + n) (S₊ (2 + n)))) (+-comm 3 n)
(isOfHLevelRetractFromIso 0 (invIso (truncOfTruncIso (3 + n) 1)) (sphereConnected (2 + n)))
helper3 : isContr ∥ ∣ north ∣ ≡ ∣ north ∣ ∥₂
helper3 = isOfHLevelRetractFromIso 0 setTruncTrunc2Iso
(isConnectedPath 2 (isConnectedSubtr 3 n helper4) _ _)
-- --------------- H¹(Sⁿ), n ≥ 1 --------------------------------------------
H¹-Sⁿ≅0 : (n : ℕ) → GroupIso (coHomGr 1 (S₊ (2 + n))) trivialGroup
H¹-Sⁿ≅0 zero = IsoContrGroupTrivialGroup isContrH¹S²
where
isContrH¹S² : isContr ⟨ coHomGr 1 (S₊ 2) ⟩
isContrH¹S² = ∣ (λ _ → ∣ base ∣) ∣₂
, coHomPointedElim 0 north (λ _ → setTruncIsSet _ _)
λ f p → cong ∣_∣₂ (funExt λ x → sym p ∙∙ sym (spoke f north) ∙∙ spoke f x)
H¹-Sⁿ≅0 (suc n) = IsoContrGroupTrivialGroup isContrH¹S³⁺ⁿ
where
anIso : Iso ⟨ coHomGr 1 (S₊ (3 + n)) ⟩ ∥ (S₊ (3 + n) → hLevelTrunc (4 + n) (coHomK 1)) ∥₂
anIso =
setTruncIso
(codomainIso
(invIso (truncIdempotentIso (4 + n) (isOfHLevelPlus' {n = 1 + n} 3 (isOfHLevelTrunc 3)))))
isContrH¹S³⁺ⁿ-ish : (f : (S₊ (3 + n) → hLevelTrunc (4 + n) (coHomK 1)))
→ ∣ (λ _ → ∣ ∣ base ∣ ∣) ∣₂ ≡ ∣ f ∣₂
isContrH¹S³⁺ⁿ-ish f = ind (f north) refl
where
ind : (x : hLevelTrunc (4 + n) (coHomK 1))
→ x ≡ f north
→ ∣ (λ _ → ∣ ∣ base ∣ ∣) ∣₂ ≡ ∣ f ∣₂
ind = trElim (λ _ → isOfHLevelΠ (4 + n) λ _ → isOfHLevelPlus' {n = (3 + n)} 1 (setTruncIsSet _ _))
(trElim (λ _ → isOfHLevelΠ 3 λ _ → isOfHLevelPlus {n = 1} 2 (setTruncIsSet _ _))
(toPropElim (λ _ → isPropΠ λ _ → setTruncIsSet _ _)
λ p → cong ∣_∣₂ (funExt λ x → p ∙∙ sym (spoke f north) ∙∙ spoke f x)))
isContrH¹S³⁺ⁿ : isContr ⟨ coHomGr 1 (S₊ (3 + n)) ⟩
isContrH¹S³⁺ⁿ =
isOfHLevelRetractFromIso 0
anIso
(∣ (λ _ → ∣ ∣ base ∣ ∣) ∣₂
, sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) isContrH¹S³⁺ⁿ-ish)
--------- Direct proof of H¹(S¹) ≅ ℤ without Mayer-Vietoris -------
-- The strategy is to use the proof that ΩS¹ ≃ ℤ. Since we only have this for S¹ with the base/loop definition
-- we begin with some functions translating between H¹(S₊ 1) and ∥ S¹ → S¹ ∥₀. The latter type is easy to characterise,
-- by (S¹ → S¹) ≃ S¹ × ℤ (see Cubical.ZCohomology.Groups.Prelims). Truncating this leaves only ℤ, since S¹ is connected.
-- The translation mentioned above uses the basechange function. We use basechange-lemma (Cubical.ZCohomology.Groups.Prelims) to prove the basechange2⁻ preserves
-- path composition (in a more general sense than what is proved in basechange2⁻-morph)
-- We can now give the group equivalence. The first bit is just a big composition of our previously defined translations and is pretty uninteresting.
-- The harder step is proving that the equivalence is a morphism. This relies heavily on the fact that addition the cohomology groups essentially is defined using an
-- application of cong₂, which allows us to use basechange-lemma.
coHom1S1≃ℤ : GroupIso (coHomGr 1 (S₊ 1)) intGroup
coHom1S1≃ℤ = theIso
where
F = Iso.fun S¹→S¹≡S¹×Int
F⁻ = Iso.inv S¹→S¹≡S¹×Int
theIso : GroupIso (coHomGr 1 (S₊ 1)) intGroup
fun (map theIso) = sRec isSetInt (λ f → snd (F f))
isHom (map theIso) = sElim2 (λ _ _ → isOfHLevelPath 2 isSetInt _ _)
λ f g → ((λ i → winding (guy (ΩKn+1→Kn 1 (Kn→ΩKn+1 1 (f base) ∙ Kn→ΩKn+1 1 (g base)))
(λ i → S¹map (ΩKn+1→Kn 1 (Kn→ΩKn+1 1 (f (loop i)) ∙ Kn→ΩKn+1 1 (g (loop i))))))))
∙∙ cong winding (helper (f base) (g base) f g refl refl)
∙∙ winding-hom (guy (f base) (λ i → S¹map (f (loop i))))
(guy (g base) (λ i → S¹map (g (loop i))))
where
guy = basechange2⁻ ∘ S¹map
helper : (x y : coHomK 1) (f g : S₊ 1 → coHomK 1)
→ (f base) ≡ x
→ (g base) ≡ y
→ (guy (ΩKn+1→Kn 1 (Kn→ΩKn+1 1 (f base) ∙ Kn→ΩKn+1 1 (g base)))
(λ i → S¹map ((ΩKn+1→Kn 1 (Kn→ΩKn+1 1 (f (loop i)) ∙ Kn→ΩKn+1 1 (g (loop i)))))))
≡ (guy (f base)
(λ i → S¹map (f (loop i))))
∙ (guy (g base)
(λ i → S¹map ((g (loop i)))))
helper =
elim2 (λ _ _ → isGroupoidΠ4 λ _ _ _ _ → isOfHLevelPath 3 (isOfHLevelSuc 3 (isGroupoidS¹) base base) _ _)
(toPropElim2
(λ _ _ → isPropΠ4 λ _ _ _ _ → isGroupoidS¹ _ _ _ _)
λ f g reflf reflg →
basechange-lemma base base
(S¹map ∘ (ΩKn+1→Kn 1))
((Kn→ΩKn+1 1) ∘ f) ((Kn→ΩKn+1 1) ∘ g)
(cong (Kn→ΩKn+1 1) reflf ∙ Kn→ΩKn+10ₖ 1) (cong (Kn→ΩKn+1 1) reflg ∙ Kn→ΩKn+10ₖ 1)
∙ λ j → guy (Iso.leftInv (Iso-Kn-ΩKn+1 1) (f base) j)
(λ i → S¹map (Iso.leftInv (Iso-Kn-ΩKn+1 1) (f (loop i)) j))
∙ guy (Iso.leftInv (Iso-Kn-ΩKn+1 1) (g base) j)
(λ i → S¹map (Iso.leftInv (Iso-Kn-ΩKn+1 1) (g (loop i)) j)))
inv theIso a = ∣ (F⁻ (base , a)) ∣₂
rightInv theIso a = cong snd (Iso.rightInv S¹→S¹≡S¹×Int (base , a))
leftInv theIso = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ f → cong ((sRec setTruncIsSet ∣_∣₂)
∘ sRec setTruncIsSet λ x → ∣ F⁻ (x , (snd (F f))) ∣₂)
(Iso.inv PathIdTrunc₀Iso (isConnectedS¹ (fst (F f))))
∙ cong ∣_∣₂ (Iso.leftInv S¹→S¹≡S¹×Int f)
---------------------------- Hⁿ(Sⁿ) ≅ ℤ , n ≥ 1 -------------------
Hⁿ-Sⁿ≅ℤ : (n : ℕ) → GroupIso intGroup (coHomGr (suc n) (S₊ (suc n)))
Hⁿ-Sⁿ≅ℤ zero = invGroupIso coHom1S1≃ℤ
Hⁿ-Sⁿ≅ℤ (suc n) =
Hⁿ-Sⁿ≅ℤ n
□ vSES→GroupIso _ _ theIso
□ invGroupIso (coHomPushout≅coHomSn (suc n) (suc (suc n)))
where
module K = MV Unit Unit (S₊ (suc n)) (λ _ → tt) (λ _ → tt)
theIso : vSES (coHomGr (suc n) (S₊ (suc n))) (coHomGr (suc (suc n))
(Pushout {A = S₊ (suc n)} (λ _ → tt) (λ _ → tt)))
_
_
isTrivialLeft theIso p q = ΣPathP (isOfHLevelSuc 0 (isContrHⁿ-Unit n) (fst p) (fst q)
, isOfHLevelSuc 0 (isContrHⁿ-Unit n) (snd p) (snd q))
isTrivialRight theIso p q = ΣPathP (isOfHLevelSuc 0 (isContrHⁿ-Unit (suc n)) (fst p) (fst q)
, isOfHLevelSuc 0 (isContrHⁿ-Unit (suc n)) (snd p) (snd q))
left theIso = K.Δ (suc n)
right theIso = K.i (2 + n)
vSES.ϕ theIso = K.d (suc n)
Ker-ϕ⊂Im-left theIso = K.Ker-d⊂Im-Δ (suc n)
Ker-right⊂Im-ϕ theIso = K.Ker-i⊂Im-d (suc n)
{- More standard proof of H¹(S¹) ≅ ℤ using Mayer-Vietoris.
This is much slower than the direct proof, but let's keep it here for completeness.
-- --------------------------H¹(S¹) -----------------------------------
{-
In order to apply Mayer-Vietoris, we need the following lemma.
Given the following diagram
a ↦ (a , 0) ψ ϕ
A --> A × A -------> B ---> C
If ψ is an isomorphism and ϕ is surjective with ker ϕ ≡ {ψ (a , a) ∣ a ∈ A}, then C ≅ B
-}
diagonalIso : ∀ {ℓ ℓ' ℓ''} {A : Group {ℓ}} (B : Group {ℓ'}) {C : Group {ℓ''}}
(ψ : GroupIso (dirProd A A) B) (ϕ : GroupHom B C)
→ isSurjective _ _ ϕ
→ ((x : ⟨ B ⟩) → isInKer B C ϕ x
→ ∃[ y ∈ ⟨ A ⟩ ] x ≡ (fun (map ψ)) (y , y))
→ ((x : ⟨ B ⟩) → (∃[ y ∈ ⟨ A ⟩ ] x ≡ (fun (map ψ)) (y , y))
→ isInKer B C ϕ x)
→ GroupIso A C
diagonalIso {A = A} B {C = C} ψ ϕ issurj ker→diag diag→ker = BijectionIsoToGroupIso bijIso
where
open GroupStr
module A = GroupStr (snd A)
module B = GroupStr (snd B)
module C = GroupStr (snd C)
module A×A = GroupStr (snd (dirProd A A))
module ψ = GroupIso ψ
module ϕ = GroupHom ϕ
ψ⁻ = inv ψ
fstProj : GroupHom A (dirProd A A)
fun fstProj a = a , GroupStr.0g (snd A)
isHom fstProj g0 g1 i = (g0 A.+ g1) , GroupStr.lid (snd A) (GroupStr.0g (snd A)) (~ i)
bijIso : BijectionIso A C
map' bijIso = compGroupHom fstProj (compGroupHom (map ψ) ϕ)
inj bijIso a inker = pRec (isSetCarrier A _ _)
(λ {(a' , id) → (cong fst (sym (leftInv ψ (a , GroupStr.0g (snd A))) ∙∙ cong ψ⁻ id ∙∙ leftInv ψ (a' , a')))
∙ cong snd (sym (leftInv ψ (a' , a')) ∙∙ cong ψ⁻ (sym id) ∙∙ leftInv ψ (a , GroupStr.0g (snd A)))})
(ker→diag _ inker)
surj bijIso c =
pRec propTruncIsProp
(λ { (b , id) → ∣ (fst (ψ⁻ b) A.+ (A.- snd (ψ⁻ b)))
, ((sym (GroupStr.rid (snd C) _)
∙∙ cong ((fun ϕ) ((fun (map ψ)) (fst (ψ⁻ b) A.+ (A.- snd (ψ⁻ b)) , GroupStr.0g (snd A))) C.+_)
(sym (diag→ker (fun (map ψ) ((snd (ψ⁻ b)) , (snd (ψ⁻ b))))
∣ (snd (ψ⁻ b)) , refl ∣₁))
∙∙ sym ((isHom ϕ) _ _))
∙∙ cong (fun ϕ) (sym ((isHom (map ψ)) _ _)
∙∙ cong (fun (map ψ)) (ΣPathP (sym (GroupStr.assoc (snd A) _ _ _)
∙∙ cong (fst (ψ⁻ b) A.+_) (GroupStr.invl (snd A) _)
∙∙ GroupStr.rid (snd A) _
, (GroupStr.lid (snd A) _)))
∙∙ rightInv ψ b)
∙∙ id) ∣₁ })
(issurj c)
H¹-S¹≅ℤ : GroupIso intGroup (coHomGr 1 (S₊ 1))
H¹-S¹≅ℤ =
diagonalIso (coHomGr 0 (S₊ 0))
(invGroupIso H⁰-S⁰≅ℤ×ℤ)
(K.d 0)
(λ x → K.Ker-i⊂Im-d 0 x
(ΣPathP (isOfHLevelSuc 0 (isContrHⁿ-Unit 0) _ _
, isOfHLevelSuc 0 (isContrHⁿ-Unit 0) _ _)))
((sElim (λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 propTruncIsProp)
(λ x inker
→ pRec propTruncIsProp
(λ {((f , g) , id') → helper x f g id' inker})
((K.Ker-d⊂Im-Δ 0 ∣ x ∣₂ inker)))))
((sElim (λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ F surj
→ pRec (setTruncIsSet _ _)
(λ { (x , id) → K.Im-Δ⊂Ker-d 0 ∣ F ∣₂
∣ (∣ (λ _ → x) ∣₂ , ∣ (λ _ → 0) ∣₂) ,
(cong ∣_∣₂ (funExt (surjHelper x))) ∙ sym id ∣₁ })
surj) )
□ invGroupIso (coHomPushout≅coHomSn 0 1)
where
module K = MV Unit Unit (S₊ 0) (λ _ → tt) (λ _ → tt)
surjHelper : (x : Int) (x₁ : S₊ 0) → x -[ 0 ]ₖ 0 ≡ S0→Int (x , x) x₁
surjHelper x true = Iso.leftInv (Iso-Kn-ΩKn+1 0) x
surjHelper x false = Iso.leftInv (Iso-Kn-ΩKn+1 0) x
helper : (F : S₊ 0 → Int) (f g : ∥ (Unit → Int) ∥₂)
(id : GroupHom.fun (K.Δ 0) (f , g) ≡ ∣ F ∣₂)
→ isInKer (coHomGr 0 (S₊ 0))
(coHomGr 1 (Pushout (λ _ → tt) (λ _ → tt)))
(K.d 0)
∣ F ∣₂
→ ∃[ x ∈ Int ] ∣ F ∣₂ ≡ inv H⁰-S⁰≅ℤ×ℤ (x , x)
helper F =
sElim2 (λ _ _ → isOfHLevelΠ 2 λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 propTruncIsProp)
λ f g id inker
→ pRec propTruncIsProp
(λ ((a , b) , id2)
→ sElim2 {C = λ f g → GroupHom.fun (K.Δ 0) (f , g) ≡ ∣ F ∣₂ → _ }
(λ _ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 propTruncIsProp)
(λ f g id → ∣ (helper2 f g .fst) , (sym id ∙ sym (helper2 f g .snd)) ∣₁)
a b id2)
(MV.Ker-d⊂Im-Δ _ _ (S₊ 0) (λ _ → tt) (λ _ → tt) 0 ∣ F ∣₂ inker)
where
helper2 : (f g : Unit → Int)
→ Σ[ x ∈ Int ] (inv H⁰-S⁰≅ℤ×ℤ (x , x))
≡ GroupHom.fun (K.Δ 0) (∣ f ∣₂ , ∣ g ∣₂)
helper2 f g = (f _ -[ 0 ]ₖ g _) , cong ∣_∣₂ (funExt λ {true → refl ; false → refl})
-}
|
{
"alphanum_fraction": 0.5069498269,
"avg_line_length": 49.7506426735,
"ext": "agda",
"hexsha": "76ce1a137faf75587a7ea5e7bc9301bc9d90fe00",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ayberkt/cubical",
"max_forks_repo_path": "Cubical/ZCohomology/Groups/Sn.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ayberkt/cubical",
"max_issues_repo_path": "Cubical/ZCohomology/Groups/Sn.agda",
"max_line_length": 165,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ayberkt/cubical",
"max_stars_repo_path": "Cubical/ZCohomology/Groups/Sn.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7412,
"size": 19353
}
|
{-# OPTIONS --without-K #-}
module Coinduction where
infix 1000 ♯_
postulate
∞ : ∀ {i} (A : Set i) → Set i
♯_ : ∀ {i} {A : Set i} → A → ∞ A
♭ : ∀ {i} {A : Set i} → ∞ A → A
{-# BUILTIN INFINITY ∞ #-}
{-# BUILTIN SHARP ♯_ #-}
{-# BUILTIN FLAT ♭ #-}
|
{
"alphanum_fraction": 0.4552238806,
"avg_line_length": 17.8666666667,
"ext": "agda",
"hexsha": "6e4332f385c13416a2ac36c39a3636f987c0aed3",
"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/Coinduction.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/Coinduction.agda",
"max_line_length": 34,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "old/Coinduction.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": 115,
"size": 268
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Empty.Polymorphic where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
import Cubical.Data.Empty as Empty
⊥ : ∀ {ℓ} → Type ℓ
⊥ = Lift Empty.⊥
⊥-elim : ∀ {w ℓ} {Whatever : ⊥ {ℓ} → Type w} → (witness : ⊥ {ℓ}) → Whatever witness
⊥-elim ()
isProp⊥ : ∀ {ℓ} → isProp (⊥ {ℓ})
isProp⊥ ()
isContr⊥→A : ∀ {ℓ ℓ′} {A : Type ℓ′} → isContr (⊥ {ℓ} → A)
fst isContr⊥→A ()
snd isContr⊥→A f i ()
|
{
"alphanum_fraction": 0.6095041322,
"avg_line_length": 23.0476190476,
"ext": "agda",
"hexsha": "eeb0e840271126f5e72cc95c660b21d8d871d5a7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Data/Empty/Polymorphic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Data/Empty/Polymorphic.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Data/Empty/Polymorphic.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 209,
"size": 484
}
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.GradedRing.DirectSumHIT where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.AbGroup.Instances.DirectSumHIT
open import Cubical.Algebra.DirectSum.DirectSumHIT.Base
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
private variable
ℓ ℓ' : Level
-----------------------------------------------------------------------------
-- Def, notation, lemma
module GradedRing-⊕HIT-index
(IdM@(Idx , IdxStr) : Monoid ℓ)
(G : (n : Idx) → Type ℓ')
(Gstr : (n : Idx) → AbGroupStr (G n))
where
⊕G-AbGroup = ⊕HIT-AbGr Idx G Gstr
⊕G = ⊕HIT Idx G Gstr
open MonoidStr IdxStr renaming (is-set to isSetIdx)
open AbGroupStr (snd ⊕G-AbGroup)
renaming
( 0g to 0⊕
; _+_ to _+⊕_
; -_ to -⊕_
; +Assoc to +⊕Assoc
; +IdR to +⊕IdR
; +IdL to +⊕IdL
; +InvR to +⊕InvR
; +InvL to +⊕InvL
; +Comm to +⊕Comm
; is-set to isSet⊕G )
open AbGroupTheory ⊕G-AbGroup
open AbGroupStr
renaming
( +Assoc to +Assoc
; +IdR to +IdR
; +IdL to +IdL
; +InvR to +InvR
; +InvL to +InvL
; +Comm to +Comm
; is-set to isSetG )
module GradedRing-⊕HIT-⋆
(1⋆ : G ε)
(_⋆_ : {k l : Idx} → G k → G l → G (k · l))
(0-⋆ : {k l : Idx} → (b : G l) → (0g (Gstr k)) ⋆ b ≡ 0g (Gstr (k · l)))
(⋆-0 : {k l : Idx} → (a : G k) → a ⋆ (0g (Gstr l)) ≡ 0g (Gstr (k · l)))
(⋆Assoc : {k l m : Idx} → (a : G k) → (b : G l) → (c : G m) →
_≡_ {A = Σ[ k ∈ Idx ] G k} ((k · (l · m)) , (a ⋆ (b ⋆ c))) (((k · l) · m) , ((a ⋆ b) ⋆ c)))
(⋆IdR : {k : Idx} → (a : G k) → _≡_ {A = Σ[ k ∈ Idx ] G k} ( k · ε , a ⋆ 1⋆ ) (k , a))
(⋆IdL : {l : Idx} → (b : G l) → _≡_ {A = Σ[ k ∈ Idx ] G k} ( ε · l , 1⋆ ⋆ b ) (l , b))
(⋆DistR+ : {k l : Idx} → (a : G k) → (b c : G l) →
a ⋆ ((Gstr l) ._+_ b c) ≡ Gstr (k · l) ._+_ (a ⋆ b) (a ⋆ c))
(⋆DistL+ : {k l : Idx} → (a b : G k) → (c : G l) →
((Gstr k) ._+_ a b) ⋆ c ≡ Gstr (k · l) ._+_ (a ⋆ c) (b ⋆ c))
where
-----------------------------------------------------------------------------
-- Ring Properties
_prod_ : ⊕G → ⊕G → ⊕G
_prod_ = DS-Rec-Set.f _ _ _ _ (isSetΠ λ _ → isSet⊕G)
(λ _ → 0⊕)
(λ k a → DS-Rec-Set.f _ _ _ _ isSet⊕G
0⊕
(λ l b → base (k · l) (a ⋆ b))
_+⊕_
+⊕Assoc
+⊕IdR
+⊕Comm
(λ l → cong (base (k · l)) (⋆-0 a) ∙ base-neutral _)
λ l b c → base-add _ _ _ ∙ cong (base (k · l)) (sym (⋆DistR+ _ _ _)))
(λ xs ys y → (xs y) +⊕ (ys y))
(λ xs ys zs i y → +⊕Assoc (xs y) (ys y) (zs y) i)
(λ xs i y → +⊕IdR (xs y) i)
(λ xs ys i y → +⊕Comm (xs y) (ys y) i)
(λ k → funExt (DS-Ind-Prop.f _ _ _ _ (λ _ → isSet⊕G _ _)
refl
(λ l b → cong (base (k · l)) (0-⋆ _) ∙ base-neutral _)
λ {U V} ind-U ind-V → cong₂ _+⊕_ ind-U ind-V ∙ +⊕IdR _))
λ k a b → funExt (DS-Ind-Prop.f _ _ _ _ (λ _ → isSet⊕G _ _)
(+⊕IdR _)
(λ l c → base-add _ _ _ ∙ cong (base (k · l)) (sym (⋆DistL+ _ _ _)))
(λ {U V} ind-U ind-V → comm-4 _ _ _ _ ∙ cong₂ _+⊕_ ind-U ind-V))
1⊕ : ⊕G
1⊕ = base ε 1⋆
prodAssoc : (x y z : ⊕G) → x prod (y prod z) ≡ (x prod y) prod z
prodAssoc = DS-Ind-Prop.f _ _ _ _ (λ _ → isPropΠ2 λ _ _ → isSet⊕G _ _)
(λ _ _ → refl)
(λ k a → DS-Ind-Prop.f _ _ _ _ (λ _ → isPropΠ (λ _ → isSet⊕G _ _))
(λ z → refl)
(λ l b → DS-Ind-Prop.f _ _ _ _ (λ _ → isSet⊕G _ _)
refl
(λ m c → cong₂ base (cong fst (⋆Assoc _ _ _)) (cong snd (⋆Assoc _ _ _)))
λ {U V} ind-U ind-V → cong₂ _+⊕_ ind-U ind-V)
λ {U V} ind-U ind-V z → cong₂ _+⊕_ (ind-U z) (ind-V z))
λ {U V} ind-U ind-V y z → cong₂ _+⊕_ (ind-U y z) (ind-V y z)
prodIdR : (x : ⊕G) → x prod 1⊕ ≡ x
prodIdR = DS-Ind-Prop.f _ _ _ _ (λ _ → isSet⊕G _ _)
refl
(λ k a → cong₂ base (cong fst (⋆IdR _)) (cong snd (⋆IdR _)) )
λ {U V} ind-U ind-V → (cong₂ _+⊕_ ind-U ind-V)
prodIdL : (y : ⊕G) → 1⊕ prod y ≡ y
prodIdL = DS-Ind-Prop.f _ _ _ _ (λ _ → isSet⊕G _ _)
refl
(λ l b → cong₂ base (cong fst (⋆IdL _)) (cong snd (⋆IdL _)) )
λ {U V} ind-U ind-V → (cong₂ _+⊕_ ind-U ind-V)
prodDistR+ : (x y z : ⊕G) → x prod (y +⊕ z) ≡ (x prod y) +⊕ (x prod z)
prodDistR+ = DS-Ind-Prop.f _ _ _ _ (λ _ → isPropΠ2 (λ _ _ → isSet⊕G _ _))
(λ _ _ → sym (+⊕IdR _))
(λ k a y z → refl)
λ {U V} ind-U ind-V y z → cong₂ _+⊕_ (ind-U y z) (ind-V y z) ∙ comm-4 _ _ _ _
prodDistL+ : (x y z : ⊕G) → (x +⊕ y) prod z ≡ (x prod z) +⊕ (y prod z)
prodDistL+ = λ x y z → refl
-----------------------------------------------------------------------------
-- Ring Instances
⊕HITgradedRing-Ring : Ring (ℓ-max ℓ ℓ')
fst ⊕HITgradedRing-Ring = ⊕G
RingStr.0r (snd ⊕HITgradedRing-Ring) = 0⊕
RingStr.1r (snd ⊕HITgradedRing-Ring) = 1⊕
RingStr._+_ (snd ⊕HITgradedRing-Ring) = _+⊕_
RingStr._·_ (snd ⊕HITgradedRing-Ring) = _prod_
RingStr.- snd ⊕HITgradedRing-Ring = -⊕_
RingStr.isRing (snd ⊕HITgradedRing-Ring) = makeIsRing isSet⊕G
+⊕Assoc +⊕IdR +⊕InvR +⊕Comm
prodAssoc prodIdR prodIdL prodDistR+ prodDistL+
-----------------------------------------------------------------------------
-- CommRing extension
module ExtensionCommRing
(⋆Comm : {k l : Idx} → (a : G k) → (b : G l) →
_≡_ {A = Σ[ k ∈ Idx ] G k} ((k · l) , (a ⋆ b)) ((l · k) , (b ⋆ a)))
where
open RingTheory ⊕HITgradedRing-Ring
prodComm : (x y : ⊕G) → x prod y ≡ y prod x
prodComm = DS-Ind-Prop.f _ _ _ _ (λ _ → isPropΠ (λ _ → isSet⊕G _ _))
(λ y → sym (0RightAnnihilates y))
(λ k a → DS-Ind-Prop.f _ _ _ _ (λ _ → isSet⊕G _ _)
refl
(λ l b → cong₂ base (cong fst (⋆Comm _ _)) (cong snd (⋆Comm _ _)))
λ {U V} ind-U ind-V → cong₂ _+⊕_ ind-U ind-V)
λ {U V} ind-U ind-V Q → ((cong₂ _+⊕_ (ind-U Q) (ind-V Q)) ∙ sym (prodDistR+ Q U V))
⊕HITgradedRing-CommRing : CommRing (ℓ-max ℓ ℓ')
⊕HITgradedRing-CommRing = Ring→CommRing ⊕HITgradedRing-Ring prodComm
|
{
"alphanum_fraction": 0.4235563834,
"avg_line_length": 40.1091954023,
"ext": "agda",
"hexsha": "01928fbbc44823a3fd38df18d63b9e4e371686e1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/GradedRing/DirectSumHIT.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/GradedRing/DirectSumHIT.agda",
"max_line_length": 108,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/GradedRing/DirectSumHIT.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2817,
"size": 6979
}
|
{-# OPTIONS --without-K --safe #-}
open import Axiom.Extensionality.Propositional using (Extensionality)
module Cats.Category.Sets.Facts
(funext : ∀ {a b} → Extensionality a b)
where
open import Cats.Category.Sets.Facts.Exponential funext public using (hasExponentials)
open import Cats.Category.Sets.Facts.Initial public using (hasInitial)
open import Cats.Category.Sets.Facts.Product public using
(hasBinaryProducts ; hasFiniteProducts)
open import Cats.Category.Sets.Facts.Terminal public using (hasTerminal)
open import Cats.Category
open import Cats.Category.Sets using (Sets)
instance
isCCC : ∀ {l} → IsCCC (Sets l)
isCCC = record {}
|
{
"alphanum_fraction": 0.7709923664,
"avg_line_length": 31.1904761905,
"ext": "agda",
"hexsha": "2aec184ba449722ace5155ca4d558c02225619f6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/cats",
"max_forks_repo_path": "Cats/Category/Sets/Facts.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/cats",
"max_issues_repo_path": "Cats/Category/Sets/Facts.agda",
"max_line_length": 86,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/cats",
"max_stars_repo_path": "Cats/Category/Sets/Facts.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z",
"num_tokens": 161,
"size": 655
}
|
{-# OPTIONS --cubical --safe #-}
module Relation.Unary where
open import Relation.Nullary.Decidable
open import Level
open import Path
Decidable : (A → Type b) → Type _
Decidable P = ∀ x → Dec (P x)
AtMostOne : (A → Type b) → Type _
AtMostOne P = ∀ x y → P x → P y → x ≡ y
|
{
"alphanum_fraction": 0.6462093863,
"avg_line_length": 19.7857142857,
"ext": "agda",
"hexsha": "b19f5c0767e8fb23f659e0b881edf5c1a5f24dc2",
"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": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Relation/Unary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Relation/Unary.agda",
"max_line_length": 39,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Relation/Unary.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": 88,
"size": 277
}
|
open import Common.Prelude hiding (pred)
open import Common.Reflection
open import Common.Equality
un-function : Definition → FunDef
un-function (funDef cs) = funDef unknown cs
un-function _ = funDef unknown []
data Is-suc : Nat → Set where
is-suc : ∀ n → Is-suc (suc n)
pred : (n : Nat) → Is-suc n → Nat
pred ._ (is-suc n) = n
pred-def : FunDef
pred-def =
funDef (quoteTerm ((n : Nat) → Is-suc n → Nat))
(clause (vArg dot ∷ vArg (con (quote is-suc) (vArg (var "n") ∷ [])) ∷ [])
(var 0 []) ∷ [])
data Is-zero : Nat → Set where
is-zero : Is-zero zero
f : (n : Nat) → Is-zero n → Nat
f ._ is-zero = zero
f-def : FunDef
f-def =
funDef (quoteTerm ((n : Nat) → Is-zero n → Nat))
(clause (vArg dot ∷ vArg (con (quote is-zero) []) ∷ [])
(con (quote zero) []) ∷ [])
unquoteDecl pred' = define (vArg pred') pred-def
unquoteDecl f' = define (vArg f') f-def
check-pred : pred' 4 (is-suc _) ≡ 3
check-pred = refl
check-f : f' 0 is-zero ≡ 0
check-f = refl
|
{
"alphanum_fraction": 0.5747572816,
"avg_line_length": 24.5238095238,
"ext": "agda",
"hexsha": "0381bcd3202baa6897123c389e8136e3f49c6bf8",
"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/Succeed/Issue1227.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Succeed/Issue1227.agda",
"max_line_length": 82,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Succeed/Issue1227.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": 347,
"size": 1030
}
|
open import Prelude renaming (_<_ to _N<_)
module Implicits.Resolution.GenericFinite.Algorithm where
open import Induction.WellFounded
open import Induction.Nat
open import Data.Vec
open import Data.List
open import Data.Fin.Substitution
open import Data.Nat.Base using (_<′_)
open import Data.Maybe
open import Data.Nat hiding (_<_)
open import Data.Nat.Properties
open import Relation.Binary using (module DecTotalOrder)
open DecTotalOrder decTotalOrder using () renaming (refl to ≤-refl; trans to ≤-trans)
open import Implicits.Syntax
open import Implicits.Syntax.Type.Unification
open import Implicits.Substitutions
open import Implicits.Substitutions.Lemmas
open import Implicits.Resolution.GenericFinite.Resolution
open import Implicits.Resolution.GenericFinite.TerminationCondition
open import Implicits.Resolution.Termination
private
module M = MetaTypeMetaSubst
module Lemmas where
m<-Acc : ∀ {m ν} → MetaType m ν → Set
m<-Acc {m} {ν} r = Acc _m<_ (m , ν , r)
ρ<-Acc : ∀ {ν} → Type ν → Set
ρ<-Acc {ν} r = Acc _ρ<_ (ν , r)
module Arg<-well-founded where
open Lexicographic (_N<_) (const _ρ<_)
open import Induction.Nat
open import Data.Nat.Properties
module image = Subrelation {A = ℕ} {_N<_} {_<′_} ≤⇒≤′
arg<-well-founded : Well-founded _<_
arg<-well-founded = well-founded (image.well-founded <-well-founded) ρ<-well-founded
_arg<_ = _<_
-- Accessibility of the 'goal' type during resolution.
-- Either the *head* of the goal shrinks (Oliveira's termination condition)
-- Or the head size remains equal and the goal shrinks in an absolute sense.
Arg<-Acc : ∀ {ν} → Type ν → Set
Arg<-Acc a = Acc _arg<_ (h|| a || , (, a))
open Arg<-well-founded using (Arg<-Acc; arg<-well-founded) public
open Lemmas
module ResolutionAlgorithm (cond : TerminationCondition) where
open TerminationCondition cond
open ResolutionRules cond
mutual
match' : ∀ {m ν} (Δ : ICtx ν) (Φ : TCtx) τ → (r : MetaType m ν) →
T-Acc Φ →
m<-Acc r →
Maybe (Sub (flip MetaType ν) m zero)
match' Δ Φ τ (simpl x) f g = mgu (simpl x) τ
match' Δ Φ τ (a ⇒ b) f (acc g) with match' Δ Φ τ b f (g _ (b-m<-a⇒b a b))
match' Δ Φ τ (a ⇒ b) f (acc g) | nothing = nothing
match' Δ Φ τ (a ⇒ b) f (acc g) | just u
with (step Φ Δ (from-meta (a M./ u)) (from-meta (b M./ u)) τ) <? Φ
match' Δ Φ τ (a ⇒ b) (acc f) (acc g) | just u | yes Φ<
with resolve' Δ (step Φ Δ (from-meta (a M./ u)) (from-meta (b M./ u)) τ)
(from-meta (a M./ u)) (f _ Φ<)
match' Δ Φ τ (a ⇒ b) (acc f) (acc g) | just u | yes Φ< | true = just u
match' Δ Φ τ (a ⇒ b) (acc f) (acc g) | just u | yes Φ< | false = nothing
match' Δ Φ τ (a ⇒ b) (acc f) (acc g) | just u | no φ> = nothing
match' Δ Φ τ (∀' a) f (acc g) with match' Δ Φ τ (open-meta a) f (g _ (open-meta-a-m<-∀'a a))
match' Δ Φ τ (∀' a) f (acc g) | just p = just (tail p)
match' Δ Φ τ (∀' r) f (acc g) | nothing = nothing
-- match defers to match', which concerns itself with MetaTypes.
-- If match' finds a match, we can use the fact that we have zero unification variables open here
-- to show that we found the right thing.
match : ∀ {ν} (Δ : ICtx ν) (Φ : TCtx) τ r → T-Acc Φ → Bool
match Δ Φ τ a f = is-just (match' Δ Φ τ (to-meta {zero} a) f (m<-well-founded _))
match1st : ∀ {ν} (Δ : ICtx ν) (Φ : TCtx) (ρs : ICtx ν) → (τ : SimpleType ν) → T-Acc Φ → Bool
match1st Δ Φ [] τ Φ↓ = false
match1st Δ Φ (x ∷ xs) τ Φ↓ with match Δ Φ τ x Φ↓
match1st Δ Φ (x ∷ xs) τ Φ↓ | true = true
match1st Δ Φ (x ∷ xs) τ Φ↓ | false = match1st Δ Φ xs τ Φ↓
resolve' : ∀ {ν} (Δ : ICtx ν) (Φ : TCtx) r → T-Acc Φ → Bool
resolve' Δ Φ (simpl x) Φ↓ = match1st Δ Φ Δ x Φ↓
resolve' Δ Φ (a ⇒ b) Φ↓ = resolve' (a ∷ Δ) Φ b Φ↓
resolve' Δ Φ (∀' r) Φ↓ = resolve' (ictx-weaken Δ) Φ r Φ↓
resolve : ∀ {ν} (Δ : ICtx ν) (Φ : TCtx) r → Bool
resolve Δ Φ r = resolve' Δ Φ r (wf-< Φ)
|
{
"alphanum_fraction": 0.6142678348,
"avg_line_length": 38.786407767,
"ext": "agda",
"hexsha": "2377d1eb8d548ba65cd0f1e56248495f0bdf286a",
"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/GenericFinite/Algorithm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/GenericFinite/Algorithm.agda",
"max_line_length": 101,
"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/GenericFinite/Algorithm.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 1436,
"size": 3995
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- List Zipper-related properties
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Zipper.Properties where
open import Data.List.Base as List using (List ; [] ; _∷_)
open import Data.List.Properties
open import Data.List.Zipper
open import Data.Maybe.Base using (Maybe; just; nothing)
open import Data.Maybe.Relation.Unary.All using (All; just; nothing)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Function
-- Invariant: Zipper represents a given list
------------------------------------------------------------------------
module _ {a} {A : Set a} where
-- Stability under moving left or right
toList-left-identity : (zp : Zipper A) → All ((_≡_ on toList) zp) (left zp)
toList-left-identity (mkZipper [] val) = nothing
toList-left-identity (mkZipper (x ∷ ctx) val) = just $′ begin
List.reverse (x ∷ ctx) List.++ val
≡⟨ cong (List._++ val) (unfold-reverse x ctx) ⟩
(List.reverse ctx List.++ List.[ x ]) List.++ val
≡⟨ ++-assoc (List.reverse ctx) List.[ x ] val ⟩
toList (mkZipper ctx (x ∷ val))
∎
toList-right-identity : (zp : Zipper A) → All ((_≡_ on toList) zp) (right zp)
toList-right-identity (mkZipper ctx []) = nothing
toList-right-identity (mkZipper ctx (x ∷ val)) = just $′ begin
List.reverse ctx List.++ x ∷ val
≡⟨ sym (++-assoc (List.reverse ctx) List.[ x ] val) ⟩
(List.reverse ctx List.++ List.[ x ]) List.++ val
≡⟨ cong (List._++ val) (sym (unfold-reverse x ctx)) ⟩
List.reverse (x ∷ ctx) List.++ val
∎
-- Applying reverse does correspond to reversing the represented list
toList-reverse-commute : (zp : Zipper A) → toList (reverse zp) ≡ List.reverse (toList zp)
toList-reverse-commute (mkZipper ctx val) = begin
List.reverse val List.++ ctx
≡⟨ cong (List.reverse val List.++_) (sym (reverse-involutive ctx)) ⟩
List.reverse val List.++ List.reverse (List.reverse ctx)
≡⟨ sym (reverse-++-commute (List.reverse ctx) val) ⟩
List.reverse (List.reverse ctx List.++ val)
∎
-- Properties of the insertion functions
------------------------------------------------------------------------
-- _ˡ++_ properties
toList-ˡ++-commute : ∀ xs (zp : Zipper A) → toList (xs ˡ++ zp) ≡ xs List.++ toList zp
toList-ˡ++-commute xs (mkZipper ctx val) = begin
List.reverse (ctx List.++ List.reverse xs) List.++ val
≡⟨ cong (List._++ _) (reverse-++-commute ctx (List.reverse xs)) ⟩
(List.reverse (List.reverse xs) List.++ List.reverse ctx) List.++ val
≡⟨ ++-assoc (List.reverse (List.reverse xs)) (List.reverse ctx) val ⟩
List.reverse (List.reverse xs) List.++ List.reverse ctx List.++ val
≡⟨ cong (List._++ _) (reverse-involutive xs) ⟩
xs List.++ List.reverse ctx List.++ val
∎
ˡ++-assoc : ∀ xs ys (zp : Zipper A) → xs ˡ++ (ys ˡ++ zp) ≡ (xs List.++ ys) ˡ++ zp
ˡ++-assoc xs ys (mkZipper ctx val) = cong (λ ctx → mkZipper ctx val) $ begin
(ctx List.++ List.reverse ys) List.++ List.reverse xs
≡⟨ ++-assoc ctx _ _ ⟩
ctx List.++ List.reverse ys List.++ List.reverse xs
≡⟨ cong (ctx List.++_) (sym (reverse-++-commute xs ys)) ⟩
ctx List.++ List.reverse (xs List.++ ys)
∎
-- _ʳ++_ properties
ʳ++-assoc : ∀ xs ys (zp : Zipper A) → xs ʳ++ (ys ʳ++ zp) ≡ (ys List.++ xs) ʳ++ zp
ʳ++-assoc xs ys (mkZipper ctx val) = cong (λ ctx → mkZipper ctx val) $ begin
List.reverse xs List.++ List.reverse ys List.++ ctx
≡⟨ sym (++-assoc (List.reverse xs) (List.reverse ys) ctx) ⟩
(List.reverse xs List.++ List.reverse ys) List.++ ctx
≡⟨ cong (List._++ ctx) (sym (reverse-++-commute ys xs)) ⟩
List.reverse (ys List.++ xs) List.++ ctx
∎
-- _++ˡ_ properties
++ˡ-assoc : ∀ xs ys (zp : Zipper A) → zp ++ˡ xs ++ˡ ys ≡ zp ++ˡ (ys List.++ xs)
++ˡ-assoc xs ys (mkZipper ctx val) = cong (mkZipper ctx) $ sym $ ++-assoc ys xs val
-- _++ʳ_ properties
toList-++ʳ-commute : ∀ (zp : Zipper A) xs → toList (zp ++ʳ xs) ≡ toList zp List.++ xs
toList-++ʳ-commute (mkZipper ctx val) xs = begin
List.reverse ctx List.++ val List.++ xs
≡⟨ sym (++-assoc (List.reverse ctx) val xs) ⟩
(List.reverse ctx List.++ val) List.++ xs
∎
++ʳ-assoc : ∀ xs ys (zp : Zipper A) → zp ++ʳ xs ++ʳ ys ≡ zp ++ʳ (xs List.++ ys)
++ʳ-assoc xs ys (mkZipper ctx val) = cong (mkZipper ctx) $ ++-assoc val xs ys
-- List-like operations indeed correspond to their counterparts
------------------------------------------------------------------------
module _ {a b} {A : Set a} {B : Set b} where
toList-map-commute : ∀ (f : A → B) zp → toList (map f zp) ≡ List.map f (toList zp)
toList-map-commute f zp@(mkZipper ctx val) = begin
List.reverse (List.map f ctx) List.++ List.map f val
≡⟨ cong (List._++ _) (sym (reverse-map-commute f ctx)) ⟩
List.map f (List.reverse ctx) List.++ List.map f val
≡⟨ sym (map-++-commute f (List.reverse ctx) val) ⟩
List.map f (List.reverse ctx List.++ val)
∎
toList-foldr-commute : ∀ (c : A → B → B) n zp → foldr c n zp ≡ List.foldr c n (toList zp)
toList-foldr-commute c n (mkZipper ctx val) = begin
List.foldl (flip c) (List.foldr c n val) ctx
≡⟨ sym (reverse-foldr c (List.foldr c n val) ctx) ⟩
List.foldr c (List.foldr c n val) (List.reverse ctx)
≡⟨ sym (foldr-++ c n (List.reverse ctx) val) ⟩
List.foldr c n (List.reverse ctx List.++ val)
∎
|
{
"alphanum_fraction": 0.5787079163,
"avg_line_length": 40.7037037037,
"ext": "agda",
"hexsha": "7da32c5b89ccceaf1678d8c678dddb6d1e747062",
"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/Zipper/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Zipper/Properties.agda",
"max_line_length": 90,
"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/Zipper/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": 1817,
"size": 5495
}
|
module ImplicitRecordFields where
record R (X Y : Set) : Set₁ where
field
{A} : Set
f : A → A
{B C} D {E} : Set
g : B → C → E → X → Y
postulate A : Set
r : R A A
r = record
{ f = f
; B = A
; D = A
; g = λ (_ _ _ : _) → f
}
where
f : A → A
f x = x
data _≡_ {A : Set₁} (x : A) : A → Set where
refl : x ≡ x
lemma₁ : r ≡ record {}
lemma₁ = refl
lemma₂ : R.B r ≡ A
lemma₂ = refl
|
{
"alphanum_fraction": 0.4414414414,
"avg_line_length": 14.3225806452,
"ext": "agda",
"hexsha": "13c84a010a089bdbd5e91fc7a91710f439c49112",
"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/ImplicitRecordFields.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/ImplicitRecordFields.agda",
"max_line_length": 43,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/ImplicitRecordFields.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": 187,
"size": 444
}
|
-- Interpretation of partial weakenings as partial finite maps.
module Dimension.PartialWeakening.Model (E : Set) where
import Level
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Fin using (Fin; zero; suc)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Axiom.FunctionExtensionality
open import Control.Category
open import Control.Category.Functor
open import Control.Kleisli
open import Control.Monad using (IsMonad; module IsMonad)
import Control.Monad.Error as Err
open module Error = Err E using (Error; fail; return; errorIsMonad)
-- open import Dimension.PartialWeakening E -- horrible names
import Dimension.PartialWeakening as PW
open module PWeak = PW E
open IsMonad errorIsMonad hiding (return)
module Kl = IsCategory (kleisliIsCategory errorIsMonad)
-- Semantics given by application to a name in Fin n
apply : ∀ {n m} (f : PWeak n m) (i : Fin n) → Error (Fin m)
apply [] ()
apply (e ∷ f) zero = fail e
apply (e ∷ f) (suc i) = apply f i
apply (lift f) zero = return zero
apply (lift f) (suc i) = suc <$> apply f i
apply (weak f) i = suc <$> apply f i
-- Soundness of id
abstract
apply-id : ∀ n (i : Fin n) → apply id i ≡ return i
apply-id 0 ()
apply-id (suc n) zero = refl
apply-id (suc n) (suc i) with (apply id i) | (apply-id n i)
apply-id (suc n) (suc i) | .(return i) | refl = refl
-- Lemma: one inductive step
abstract
lift-lift-suc : ∀ {n m l} (f : PWeak n m) {g : PWeak m l} {i : Fin n} →
(ih : apply (comp f g) i ≡ apply f i >>= apply g) →
apply (comp (lift f) (lift g)) (suc i) ≡
apply (lift f) (suc i) >>= apply (lift g)
lift-lift-suc f {g = g} {i = i} ih = begin
apply (comp (lift f) (lift g)) (suc i)
≡⟨⟩ -- definition of comp
apply (lift (comp f g)) (suc i)
≡⟨⟩ -- definition of apply
suc <$> apply (comp f g) i
≡⟨ cong (_<$>_ suc) ih ⟩ -- induction hypothesis
suc <$> (apply f i >>= apply g)
≡⟨ map-after-bind (apply f i) ⟩ -- map commutes with bind I
(apply f i >>= λ j → suc <$> apply g j)
≡⟨⟩ -- definition of apply
(apply f i >>= λ j → apply (lift g) (suc j))
≡⟨ sym (bind-after-map (apply f i)) ⟩ -- map commutes with bind II
(suc <$> apply f i) >>= apply (lift g)
≡⟨⟩ -- definition of apply
apply (lift f) (suc i) >>= apply (lift g)
∎
-- Soundness of comp
abstract
apply-comp : ∀ {n m l} (f : PWeak n m) (g : PWeak m l) (i : Fin n) →
apply (comp f g) i ≡ apply f i >>= apply g
apply-comp [] g ()
apply-comp (e ∷ f) g zero = refl
apply-comp (e ∷ f) g (suc i) = apply-comp f g i
apply-comp (lift f) (e ∷ g) zero = refl
apply-comp (lift f) (e ∷ g) (suc i) rewrite apply-comp f g i with apply f i
... | fail e′ = refl
... | return j = refl
apply-comp (lift f) (lift g) zero = refl
apply-comp (lift f) (lift g) (suc i) = lift-lift-suc f (apply-comp f g i)
apply-comp (lift f) (weak g) i = begin
suc <$> apply (comp (lift f) g) i
≡⟨ cong (_<$>_ suc) (apply-comp (lift f) g i) ⟩ -- ind. hyp.
suc <$> (apply (lift f) i >>= apply g)
≡⟨ map-after-bind (apply (lift f) i) ⟩ -- move map
apply (lift f) i >>= (λ j → suc <$> apply g j)
∎
apply-comp (weak f) (e ∷ g) i rewrite apply-comp f g i = sym (bind-after-map (apply f i))
apply-comp (weak f) (lift g) i rewrite apply-comp f g i = begin
suc <$> (apply f i >>= apply g)
≡⟨ map-after-bind (apply f i) ⟩
apply f i >>= (λ j → suc <$> apply g j)
≡⟨⟩
apply f i >>= (λ j → apply (lift g) (suc j))
≡⟨ sym (bind-after-map (apply f i)) ⟩
(suc <$> apply f i) >>= apply (lift g)
∎
apply-comp (weak f) (weak g) i rewrite apply-comp (weak f) g i =
map-after-bind (apply (weak f) i)
-- The Kleisli category of partial finite maps Fin n → Error (Fin m)
PFin : (n m : ℕ) → Set
PFin n m = Fin n → Error (Fin m)
SPFin = λ n m → setoid (PFin n m)
pFinIsCategory : IsCategory SPFin
pFinIsCategory = record
{ ops = record
{ id = return
; _⟫_ = λ f g a → f a >>= g
}
; laws = record
{ id-first = fun-ext (bind-β _)
; id-last = fun-ext (λ a → bind-η _)
; ∘-assoc = λ f → fun-ext (λ a → bind-assoc (f a))
; ∘-cong = λ{ refl refl → refl }
}
}
PFIN : Category _ _ _
PFIN = record { Hom = SPFin; isCategory = pFinIsCategory }
-- The evaluation functor
-- ⟦_⟧ : ∀ {n m} → PWeak n m → PFin n m
-- ⟦ f ⟧ = apply f
applyIsFunctor : IsFunctor {C = PWEAK} {D = PFIN} (λ n → n)
applyIsFunctor = record
{ ops = record
{ map = apply
}
; laws = record
{ map-id = fun-ext (apply-id _)
; map-∘ = λ f → fun-ext (apply-comp f _)
}
}
|
{
"alphanum_fraction": 0.5558063192,
"avg_line_length": 26.9281767956,
"ext": "agda",
"hexsha": "98290ecb9e24dbe46f94281644cc7ad55b7360d3",
"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": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andreasabel/cubical",
"max_forks_repo_path": "src/Dimension/PartialWeakening/Model.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"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": "andreasabel/cubical",
"max_issues_repo_path": "src/Dimension/PartialWeakening/Model.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andreasabel/cubical",
"max_stars_repo_path": "src/Dimension/PartialWeakening/Model.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1640,
"size": 4874
}
|
{-# OPTIONS --no-universe-polymorphism #-}
open import Induction.WellFounded as WF
open import Data.Product
open import Relation.Binary.Core
open import Relation.Unary as U using (Decidable)
open import Relation.Nullary
import Level as L using (zero)
module DivideEtImpera where
{-- This module implements a quite general version of Divide and Conquer as desribed by Douglas R. Smith in his paper
"The Design of Divide and Conquer Algorithms" 1984. the function makeD&C requires a well founded relation, a decidable proposition
of whether a given input is primitive, a composition and a decomposition function, a special function g and a function dirSolve.
All of these functions have to fullfill certain conditions and lastly you also need an "induction principle" that describes that these
functions work well together. After putting in all this work, you can finally reap your reward: an algorithm that does what you want:
takes inputs that satisfy the input condition and returns results that satisfy the output condition.
--}
{-- these 2 functions should be somewhere in the agda standard libraries but i couln't find them so i just wrote them again --}
foldAcc : {A : Set} → {_<_ : Rel A L.zero} → {R : A → Set} →
(step : (x : A) → ((y : A) → _<_ y x → R y) → R x) →
(z : A) → Acc _<_ z → R z
foldAcc step z (acc a) = step z (λ y y<z → foldAcc step y (a y y<z))
wfInd : {A : Set} {_<_ : Rel A _} → (WellFounded _<_) →
{R : A → Set} →
(step : (x : A) → ((y : A) → _<_ y x → R y) → R x) →
(z : A) → R z
wfInd wf step z = foldAcc step z (wf z)
{- the algorithm itself as one huge function:
instead of requiring all the functions and then five axioms describing their behaiviour, i use
dependent types to embedd four of the axions in therespective function they describe and
only the last one (called "lemma" here) as an extra. See the paper for details -}
makeD&C1 : {D₁ R₁ D₂ R₂ : Set} {I₁ : D₁ → Set} {O₁ : D₁ → R₁ → Set} {I₂ : D₂ → Set}
{O₂ : D₂ → R₂ → Set} {O₃ : D₁ → (D₂ × D₁) → Set} {O₄ : (R₂ × R₁) → R₁ → Set}
{_<_ : Rel D₁ _} → (wf : Well-founded _<_) → {Prim : D₁ → Set} → (pDec : U.Decidable Prim) →
(decomp : (x : D₁) → I₁ x → ¬ Prim x → Σ (D₂ × D₁)
λ y → I₂ (proj₁ y) × (I₁ (proj₂ y)) × (_<_ (proj₂ y) x) × (O₃ x y) ) →
(comp : (u : (R₂ × R₁)) → Σ R₁ (O₄ u)) →
(g : (x : D₂) → I₂ x → Σ R₂ (O₂ x)) →
(dirSolve : (x : D₁) → I₁ x → Prim x → Σ R₁ (O₁ x)) →
(lemma : ∀{x₀ x₁ x₂ z₀ z₁ z₂} → O₃ x₀ (x₁ , x₂) → O₂ x₁ z₁ → O₁ x₂ z₂ → O₄ (z₁ , z₂) z₀ → O₁ x₀ z₀) →
(x : D₁) → I₁ x → Σ R₁ (O₁ x)
makeD&C1 {D₁ = D₁} {R₁ = R₁} {I₁ = I₁} {O₁ = O₁} {_<_ = _<_} wf {Prim} pDec decomp comp g dirSolve lemma x = wfInd wf step x where
step : (x : D₁) → ((y : D₁) → _<_ y x → I₁ y → Σ R₁ (O₁ y)) → I₁ x → Σ R₁ (O₁ x)
step x rec ix with (pDec x)
step x rec ix | (yes pfY) = dirSolve x ix pfY
step x rec ix | (no pfN) = let dec = decomp x ix pfN
decV = proj₁ dec
decV1 = proj₁ decV
decV2 = proj₂ decV
decP = proj₂ dec
decP1 = proj₁ decP
decP2 = proj₁ (proj₂ decP)
decP3 = proj₁ (proj₂ (proj₂ decP))
decP4 = proj₂ (proj₂ (proj₂ decP))
gRes = g decV1 decP1
gV = proj₁ gRes
gP = proj₂ gRes
fRes = rec decV2 decP3 decP2
fV = proj₁ fRes
fP = proj₂ fRes
com = comp (gV , fV)
comV = proj₁ com
comP = proj₂ com
proof = lemma decP4 gP fP comP
in (comV , proof)
{- it occurred to me, that a proper Divide and conquer algorithm should make (at least) two recursive calls,
the algorithm describen inthe pape, however, only makes one! So slightly modified it to fit in that extra
recursive calls but left the basic principle exactly the same in this second version -}
makeD&C2 : {D₁ R₁ D₂ R₂ : Set} {I₁ : D₁ → Set} {O₁ : D₁ → R₁ → Set} {I₂ : D₂ → Set}
{O₂ : D₂ → R₂ → Set} {O₃ : D₁ → (D₂ × (D₁ × D₁)) → Set} {O₄ : (R₂ × (R₁ × R₁)) → R₁ → Set}
{_<_ : Rel D₁ _} → (wf : Well-founded _<_) → {Prim : D₁ → Set} → (pDec : U.Decidable Prim) →
(decomp : (x : D₁) → I₁ x → ¬ Prim x → Σ (D₂ × (D₁ × D₁))
λ y → (I₂ (proj₁ y)) × (I₁ (proj₁ (proj₂ y))) × (I₁ (proj₂ (proj₂ y))) ×
(_<_ (proj₁ (proj₂ y)) x) × (_<_ (proj₂ (proj₂ y)) x) × (O₃ x y) ) →
(comp : (u : (R₂ × (R₁ × R₁)) ) → Σ R₁ (O₄ u)) →
(g : (x : D₂) → I₂ x → Σ R₂ (O₂ x)) →
(dirSolve : (x : D₁) → I₁ x → Prim x → Σ R₁ (O₁ x)) →
(lemma : ∀{x₀ x₁ x₂ x₃ z₀ z₁ z₂ z₃} → O₃ x₀ (x₁ , (x₂ , x₃ )) → O₂ x₁ z₁ → O₁ x₂ z₂
→ O₁ x₃ z₃ → O₄ (z₁ , (z₂ , z₃)) z₀ → O₁ x₀ z₀) →
(x : D₁) → I₁ x → Σ R₁ (O₁ x)
makeD&C2 {D₁ = D₁} {R₁ = R₁} {I₁ = I₁} {O₁ = O₁} {_<_ = _<_} wf {Prim} pDec decomp comp g dirSolve lemma x = wfInd wf step x where
step : (x : D₁) → ((y : D₁) → _<_ y x → I₁ y → Σ R₁ (O₁ y)) → I₁ x → Σ R₁ (O₁ x)
step x rec ix with (pDec x)
step x rec ix | (yes pfY) = dirSolve x ix pfY
step x rec ix | (no pfN) = let dec = decomp x ix pfN
decV = proj₁ dec
decV1 = proj₁ decV
decV2 = proj₁ (proj₂ decV)
decV3 = proj₂ (proj₂ decV)
decP = proj₂ dec
decP1 = proj₁ decP
decP2 = proj₁ (proj₂ decP)
decP3 = proj₁ (proj₂ (proj₂ decP))
decP4 = proj₁ (proj₂ (proj₂ (proj₂ decP)))
decP5 = proj₁ (proj₂ (proj₂ (proj₂ (proj₂ decP))))
decP6 = proj₂ (proj₂ (proj₂ (proj₂ (proj₂ decP))))
gRes = g decV1 decP1
gV = proj₁ gRes
gP = proj₂ gRes
f1Res = rec decV2 decP4 decP2
f1V = proj₁ f1Res
f1P = proj₂ f1Res
f2Res = rec decV3 decP5 decP3
f2V = proj₁ f2Res
f2P = proj₂ f2Res
com = comp (gV , (f1V , f2V))
comV = proj₁ com
comP = proj₂ com
proof = lemma decP6 gP f1P f2P comP
in (comV , proof)
|
{
"alphanum_fraction": 0.3127395084,
"avg_line_length": 81.053030303,
"ext": "agda",
"hexsha": "4e85b2ceaa9d1708f27881d9ea01f8fa9b6ffb4b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "99bd3a5e772563153d78f61c1bbca48d7809ff48",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "NAMEhzj/Divide-and-Conquer-in-Agda",
"max_forks_repo_path": "DivideEtImpera.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "99bd3a5e772563153d78f61c1bbca48d7809ff48",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "NAMEhzj/Divide-and-Conquer-in-Agda",
"max_issues_repo_path": "DivideEtImpera.agda",
"max_line_length": 137,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "99bd3a5e772563153d78f61c1bbca48d7809ff48",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "NAMEhzj/Divide-and-Conquer-in-Agda",
"max_stars_repo_path": "DivideEtImpera.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2311,
"size": 10699
}
|
------------------------------------------------------------------------------
-- Totality properties for Tree
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.Mirror.Tree.TotalityI where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.List
open import FOTC.Program.Mirror.Forest.TotalityI
open import FOTC.Program.Mirror.Mirror
open import FOTC.Program.Mirror.Type
------------------------------------------------------------------------------
mirror-Tree : ∀ {t} → Tree t → Tree (mirror · t)
mirror-Tree = Tree-mutual-ind {A} {B} hA B[] hB
where
A : D → Set
A t = Tree (mirror · t)
B : D → Set
B ts = Forest (map mirror ts)
hA : ∀ d {ts} → Forest ts → B ts → A (node d ts)
hA d {ts} Fts Bts = subst Tree
(sym (mirror-eq d ts))
(tree d (reverse-Forest Bts))
B[] : B []
B[] = subst Forest (sym (map-[] mirror)) fnil
hB : ∀ {t ts} → Tree t → A t → Forest ts → B ts → B (t ∷ ts)
hB {t} {ts} Tt At Fts Bts =
subst Forest (sym (map-∷ mirror t ts)) (fcons At Bts)
|
{
"alphanum_fraction": 0.467953668,
"avg_line_length": 31.5853658537,
"ext": "agda",
"hexsha": "99b76bc9f7ed01c7703a256da99ea8effd5d72fc",
"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/Mirror/Tree/TotalityI.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/Mirror/Tree/TotalityI.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/Mirror/Tree/TotalityI.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": 341,
"size": 1295
}
|
{-# OPTIONS --cubical --safe #-}
module Data.Binary.Testers where
open import Prelude
open import Data.Binary.Conversion.Fast.Strict
open import Data.Binary.Definition
open import Data.List using (List; _⋯_)
open import Data.List.Sugar using (liftA2)
test : (𝔹 → 𝔹 → 𝔹) →
(ℕ → ℕ → ℕ) →
ℕ → Type
test bf nf n = let ns = 0 ⋯ n in
liftA2 (λ n m → bf ⟦ n ⇑⟧ ⟦ m ⇑⟧) ns ns ≡
liftA2 (λ n m → ⟦ nf n m ⇑⟧) ns ns
import Data.Nat as ℕ
open import Data.Binary.Addition using (_+_)
open import Data.Binary.Multiplication using (_*_)
_ : test _+_ ℕ._+_ 15
_ = refl
_ : test _*_ ℕ._*_ 15
_ = refl
|
{
"alphanum_fraction": 0.6387520525,
"avg_line_length": 21.75,
"ext": "agda",
"hexsha": "f81148f8b3847913e886d65c0b7f444d8589c227",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Binary/Testers.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Binary/Testers.agda",
"max_line_length": 50,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Binary/Testers.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": 221,
"size": 609
}
|
module FFI.Data.Either where
{-# FOREIGN GHC import qualified Data.Either #-}
data Either (A B : Set) : Set where
Left : A → Either A B
Right : B → Either A B
{-# COMPILE GHC Either = data Data.Either.Either (Data.Either.Left|Data.Either.Right) #-}
mapLeft : ∀ {A B C} → (A → B) → (Either A C) → (Either B C)
mapLeft f (Left x) = Left (f x)
mapLeft f (Right x) = Right x
mapRight : ∀ {A B C} → (B → C) → (Either A B) → (Either A C)
mapRight f (Left x) = Left x
mapRight f (Right x) = Right (f x)
|
{
"alphanum_fraction": 0.6170634921,
"avg_line_length": 29.6470588235,
"ext": "agda",
"hexsha": "d024c695574f5e2ea911b641290be28fbd69fa29",
"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": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "XanderYZZ/luau",
"max_forks_repo_path": "prototyping/FFI/Data/Either.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"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": "XanderYZZ/luau",
"max_issues_repo_path": "prototyping/FFI/Data/Either.agda",
"max_line_length": 89,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Tr4shh/Roblox-Luau",
"max_stars_repo_path": "prototyping/FFI/Data/Either.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-11T21:30:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-11T21:30:17.000Z",
"num_tokens": 173,
"size": 504
}
|
module Prelude.Data.Natural where
open import Prelude.Core
open import Prelude.Classes
open import Prelude.Orders
----------------
-- Conversion --
----------------
record ToNatural {ℓ} (A : Set ℓ) : Set ℓ where
constructor mk[ToNatural]
field
𝕟 : A → ℕ
open ToNatural {{…}}
-----------
-- Order --
-----------
data _≤ⁿ_ : ℕ → ℕ → Set where
Zero : ∀ {n} → Zero ≤ⁿ n
Succ : ∀ {n₁ n₂} → n₁ ≤ⁿ n₂ → Succ n₁ ≤ⁿ Succ n₂
xRx⸢≤ⁿ⸣ : reflexive _≤ⁿ_
xRx⸢≤ⁿ⸣ {Zero} = Zero
xRx⸢≤ⁿ⸣ {Succ n} = Succ xRx⸢≤ⁿ⸣
⋈⸢≤ⁿ⸣ : antisymmetric _≤ⁿ_
⋈⸢≤ⁿ⸣ Zero Zero = ↯
⋈⸢≤ⁿ⸣ (Succ n₁≤n₂) (Succ n₂≤n₁) = res[•x] $ ⋈⸢≤ⁿ⸣ n₁≤n₂ n₂≤n₁
_⊚⸢≤ⁿ⸣_ : transitive _≤ⁿ_
n₁≤n₂ ⊚⸢≤ⁿ⸣ Zero = Zero
Succ n₂≤n₃ ⊚⸢≤ⁿ⸣ Succ n₁≤n₂ = Succ (n₂≤n₃ ⊚⸢≤ⁿ⸣ n₁≤n₂)
data _<ⁿ_ : ℕ → ℕ → Set where
Zero : ∀ {n} → Zero <ⁿ Succ n
Succ : ∀ {n₁ n₂} → n₁ <ⁿ n₂ → Succ n₁ <ⁿ Succ n₂
weaken[<]ⁿ : ∀ {n₁ n₂} → n₁ <ⁿ n₂ → n₁ ≤ⁿ n₂
weaken[<]ⁿ Zero = Zero
weaken[<]ⁿ (Succ <₁) = Succ (weaken[<]ⁿ <₁)
strict[<]ⁿ : ∀ {n₁ n₂} → n₁ <ⁿ n₂ → ¬ (n₂ ≤ⁿ n₁)
strict[<]ⁿ Zero ()
strict[<]ⁿ (Succ <₁) (Succ ≤₁) = strict[<]ⁿ <₁ ≤₁
complete[<]ⁿ : ∀ {n₁ n₂} → n₁ ≤ⁿ n₂ → ¬ (n₂ ≤ⁿ n₁) → n₁ <ⁿ n₂
complete[<]ⁿ {n₂ = Zero} Zero ¬≤ = exfalso (¬≤ Zero)
complete[<]ⁿ {n₂ = Succ n₂} Zero ¬≤ = Zero
complete[<]ⁿ (Succ ≤₁) ¬≤ = Succ (complete[<]ⁿ ≤₁ (λ ≤₂ → ¬≤ (Succ ≤₂)))
_⋚ⁿ_ : ℕ → ℕ → ⪥!
Zero ⋚ⁿ Zero = [≡]
Zero ⋚ⁿ Succ n₂ = [<]
Succ n₁ ⋚ⁿ Zero = [>]
Succ n₁ ⋚ⁿ Succ n₂ = n₁ ⋚ⁿ n₂
_⋚ⁿᴾ_ : ∀ n₁ n₂ → n₁ ⪥!ᴾ[ _<ⁿ_ ] n₂
Zero ⋚ⁿᴾ Zero = [≡] ↯
Zero ⋚ⁿᴾ Succ n₂ = [<] Zero
Succ n₁ ⋚ⁿᴾ Zero = [>] Zero
Succ n₁ ⋚ⁿᴾ Succ n₂ with n₁ ⋚ⁿᴾ n₂
… | [<] <₀ = [<] (Succ <₀)
… | [≡] ≡₀ rewrite ≡₀ = [≡] ↯
… | [>] >₀ = [>] (Succ >₀)
_⋚ⁿᴸ_ : ∀ n₁ n₂ → n₁ ⪥!ᴸ[ _<ⁿ_ ] n₂ ‖[ n₁ ⋚ⁿ n₂ , n₁ ⋚ⁿᴾ n₂ ]
Zero ⋚ⁿᴸ Zero = [≡]
Zero ⋚ⁿᴸ Succ n₂ = [<]
Succ n₁ ⋚ⁿᴸ Zero = [>]
Succ n₁ ⋚ⁿᴸ Succ n₂ with n₁ ⋚ⁿ n₂ | n₁ ⋚ⁿᴾ n₂ | n₁ ⋚ⁿᴸ n₂
… | [<] | [<] <₀ | [<] = [<]
… | [≡] | [≡] ≡₀ | [≡] rewrite ≡₀ = [≡]
… | [>] | [>] >₀ | [>] = [>]
instance
Reflexive[≤]ⁿ : Reflexive _≤ⁿ_
Reflexive[≤]ⁿ = record { xRx = xRx⸢≤ⁿ⸣ }
Antisymmetric[≤]ⁿ : Antisymmetric _≤ⁿ_
Antisymmetric[≤]ⁿ = record { ⋈ = ⋈⸢≤ⁿ⸣ }
Transitive[≤]ⁿ : Transitive _≤ⁿ_
Transitive[≤]ⁿ = record { _⊚_ = _⊚⸢≤ⁿ⸣_ }
Strict[<]ⁿ : Strict _≤ⁿ_ _<ⁿ_
Strict[<]ⁿ = record
{ weaken[≺] = weaken[<]ⁿ
; strict[≺] = strict[<]ⁿ
; complete[≺] = complete[<]ⁿ
}
Irreflexive[<]ⁿ : Irreflexive _<ⁿ_
Irreflexive[<]ⁿ = Irreflexive[<]/≤ _≤ⁿ_ _<ⁿ_
Asymmetric[<]ⁿ : Asymmetric _<ⁿ_
Asymmetric[<]ⁿ = Asymmetric[<]/≤ _≤ⁿ_ _<ⁿ_
Transitive[<]ⁿ : Transitive _<ⁿ_
Transitive[<]ⁿ = Transitive[<]/≤ _≤ⁿ_ _<ⁿ_
Totally[<]ⁿ : Totally _<ⁿ_
Totally[<]ⁿ = record
{ _⪥_ = _⋚ⁿ_
; _⪥ᴾ_ = _⋚ⁿᴾ_
; _⪥ᴸ_ = _⋚ⁿᴸ_
}
Order[ℕ] : Order 0ᴸ ℕ
Order[ℕ] = mk[Order] _≤ⁿ_ _<ⁿ_
weaken[≤]ⁿ : ∀ {n₁ n₂} → n₁ ≤ⁿ n₂ → n₁ ≤ⁿ Succ n₂
weaken[≤]ⁿ Zero = Zero
weaken[≤]ⁿ (Succ n₁≤n₂) = Succ (weaken[≤]ⁿ n₁≤n₂)
pred[≤]ⁿ : ∀ {n₁ n₂} → Succ n₁ ≤ⁿ n₂ → n₁ ≤ⁿ n₂
pred[≤]ⁿ (Succ x) = weaken[≤]ⁿ x
n≤succ : ∀ {n : ℕ} → n ≤ⁿ Succ n
n≤succ = weaken[≤]ⁿ xRx
rel[</≤]ⁿ : ∀ {n₁ n₂} → n₁ <ⁿ n₂ ↔ Succ n₁ ≤ⁿ n₂
rel[</≤]ⁿ = ⟨ LHS , RHS ⟩
where
LHS : ∀ {n₁ n₂} → n₁ <ⁿ n₂ → Succ n₁ ≤ⁿ n₂
LHS Zero = Succ Zero
LHS (Succ <₁) = Succ (LHS <₁)
RHS : ∀ {n₁ n₂} → Succ n₁ ≤ⁿ n₂ → n₁ <ⁿ n₂
RHS {Zero} (Succ ≤₁) = Zero
RHS {Succ n₃} (Succ ≤₁) = Succ (RHS ≤₁)
------------------
-- ≤ⁿ Decidable --
------------------
instance
DecRel[≡]ⁿ : DecRel (_≡_ {A = ℕ})
DecRel[≡]ⁿ = record
{ _⁇_ = ⁇[≡]/⪥[] _≤_ _<_
; _⁇ᴾ_ = ⁇ᴾ[≡]/⪥[] _≤_ _<_
; _⁇ᴸ_ = ⁇ᴸ[≡]/⪥[] _≤_ _<_
}
DecRel[≤]ⁿ : DecRel _≤ⁿ_
DecRel[≤]ⁿ = record
{ _⁇_ = ⁇[≤]/⪥[] _≤_ _<_
; _⁇ᴾ_ = ⁇ᴾ[≤]/⪥[] _≤_ _<_
; _⁇ᴸ_ = ⁇ᴸ[≤]/⪥[] _≤_ _<_
}
DecRel[<]ⁿ : DecRel _<ⁿ_
DecRel[<]ⁿ = record
{ _⁇_ = ⁇[<]/⪥[] _≤_ _<_
; _⁇ᴾ_ = ⁇ᴾ[<]/⪥[] _≤_ _<_
; _⁇ᴸ_ = ⁇ᴸ[<]/⪥[] _≤_ _<_
}
--------------
-- Addition --
--------------
_+ⁿ_ : ℕ → ℕ → ℕ
Zero +ⁿ n₂ = n₂
Succ n₁ +ⁿ n₂ = Succ (n₁ +ⁿ n₂)
left-unit[+]ⁿ : ∀ (n : ℕ) → 0 +ⁿ n ≡ n
left-unit[+]ⁿ n = ↯
right-unit[+]ⁿ : ∀ (n : ℕ) → n +ⁿ 0 ≡ n
right-unit[+]ⁿ Zero = ↯
right-unit[+]ⁿ (Succ n) rewrite right-unit[+]ⁿ n = ↯
associative[+]ⁿ : ∀ (n₁ n₂ n₃ : ℕ) → (n₁ +ⁿ n₂) +ⁿ n₃ ≡ n₁ +ⁿ (n₂ +ⁿ n₃)
associative[+]ⁿ Zero n₂ n₃ = ↯
associative[+]ⁿ (Succ n₁) n₂ n₃ rewrite associative[+]ⁿ n₁ n₂ n₃ = ↯
m+suc[n]=suc[m+n] : ∀ (n₁ n₂ : ℕ) → n₁ +ⁿ Succ n₂ ≡ Succ (n₁ +ⁿ n₂)
m+suc[n]=suc[m+n] Zero n₂ = ↯
m+suc[n]=suc[m+n] (Succ n₁) n₂ rewrite m+suc[n]=suc[m+n] n₁ n₂ = ↯
suc[m+n]=m+suc[n] : ∀ (n₁ n₂ : ℕ) → Succ (n₁ +ⁿ n₂) ≡ n₁ +ⁿ Succ n₂
suc[m+n]=m+suc[n] n₁ n₂ = ◇ $ m+suc[n]=suc[m+n] n₁ n₂
commutative[+]ⁿ : ∀ (n₁ n₂ : ℕ) → n₁ +ⁿ n₂ ≡ n₂ +ⁿ n₁
commutative[+]ⁿ Zero n₂ rewrite right-unit[+]ⁿ n₂ = ↯
commutative[+]ⁿ (Succ n₁) n₂ rewrite commutative[+]ⁿ n₁ n₂ | suc[m+n]=m+suc[n] n₂ n₁ = ↯
instance
Additive[ℕ] : Additive ℕ
Additive[ℕ] = record
{ zero = Zero
; _+_ = _+ⁿ_
; left-unit[+] = left-unit[+]ⁿ
; right-unit[+] = right-unit[+]ⁿ
; associative[+] = associative[+]ⁿ
; commutative[+] = commutative[+]ⁿ
}
--------------------
-- Multiplication --
--------------------
oneⁿ : ℕ
oneⁿ = Succ Zero
_×ⁿ_ : ℕ → ℕ → ℕ
Zero ×ⁿ n₂ = Zero
Succ n₁ ×ⁿ n₂ = n₂ +ⁿ (n₁ ×ⁿ n₂)
left-zero[×]ⁿ : ∀ n → zero ×ⁿ n ≡ zero
left-zero[×]ⁿ n = ↯
right-zero[×]ⁿ : ∀ n → n ×ⁿ zero ≡ zero
right-zero[×]ⁿ Zero = ↯
right-zero[×]ⁿ (Succ n) rewrite right-zero[×]ⁿ n = ↯
left-unit[×]ⁿ : ∀ n → oneⁿ ×ⁿ n ≡ n
left-unit[×]ⁿ n = right-unit[+]ⁿ n
right-unit[×]ⁿ : ∀ n → n ×ⁿ oneⁿ ≡ n
right-unit[×]ⁿ Zero = ↯
right-unit[×]ⁿ (Succ n) rewrite right-unit[×]ⁿ n = ↯
distributive[×]ⁿ : ∀ n₁ n₂ n₃ → (n₁ +ⁿ n₂) ×ⁿ n₃ ≡ (n₁ ×ⁿ n₃) +ⁿ (n₂ ×ⁿ n₃)
distributive[×]ⁿ Zero n₂ n₃ = ↯
distributive[×]ⁿ (Succ n₁) n₂ n₃ rewrite distributive[×]ⁿ n₁ n₂ n₃ | associative[+]ⁿ n₃ (n₁ ×ⁿ n₃) (n₂ ×ⁿ n₃) = ↯
associative[×]ⁿ : ∀ n₁ n₂ n₃ → (n₁ ×ⁿ n₂) ×ⁿ n₃ ≡ n₁ ×ⁿ (n₂ ×ⁿ n₃)
associative[×]ⁿ Zero n₂ n₃ = ↯
associative[×]ⁿ (Succ n₁) n₂ n₃ rewrite distributive[×]ⁿ n₂ (n₁ ×ⁿ n₂) n₃ | associative[×]ⁿ n₁ n₂ n₃ = ↯
commutative[×]ⁿ : ∀ n₁ n₂ → n₁ ×ⁿ n₂ ≡ n₂ ×ⁿ n₁
commutative[×]ⁿ Zero n₂ rewrite right-zero[×]ⁿ n₂ = ↯
commutative[×]ⁿ n₁ Zero rewrite right-zero[×]ⁿ n₁ = ↯
commutative[×]ⁿ (Succ n₁) (Succ n₂)
rewrite commutative[×]ⁿ n₁ (Succ n₂)
| commutative[×]ⁿ n₂ (Succ n₁)
| commutative[×]ⁿ n₁ n₂
| ◇ $ associative[+]ⁿ n₁ n₂ (n₂ ×ⁿ n₁)
| commutative[+]ⁿ n₁ n₂
| associative[+]ⁿ n₂ n₁ (n₂ ×ⁿ n₁)
= ↯
instance
Multiplicative[ℕ] : Multiplicative ℕ
Multiplicative[ℕ] = record
{ one = oneⁿ
; _×_ = _×ⁿ_
; left-zero[×] = left-zero[×]ⁿ
; right-zero[×] = right-zero[×]ⁿ
; left-unit[×] = left-unit[×]ⁿ
; right-unit[×] = right-unit[×]ⁿ
; associative[×] = associative[×]ⁿ
; commutative[×] = commutative[×]ⁿ
; distributive[×] = distributive[×]ⁿ
}
-----------------
-- Subtraction --
-----------------
_-ⁿ_‖_ : ∀ (n₁ n₂ : ℕ) → n₂ ≤ n₁ → ℕ
n₁ -ⁿ Zero ‖ Zero = n₁
Succ n₁ -ⁿ Succ n₂ ‖ Succ n₁≤n₂ = n₁ -ⁿ n₂ ‖ n₁≤n₂
correct[-ⁿ‖] : ∀ n₁ n₂ (n₂≤n₁ : n₂ ≤ n₁) → n₂ + (n₁ -ⁿ n₂ ‖ n₂≤n₁) ≡ n₁
correct[-ⁿ‖] n₁ Zero Zero = ↯
correct[-ⁿ‖] (Succ n₁) (Succ n₂) (Succ n₂≤n₁) rewrite correct[-ⁿ‖] n₁ n₂ n₂≤n₁ = ↯
n-n=0 : ∀ n → n -ⁿ n ‖ xRx ≡ Zero
n-n=0 Zero = ↯
n-n=0 (Succ n) rewrite n-n=0 n = ↯
n-0=n : ∀ n → n -ⁿ 0 ‖ Zero ≡ n
n-0=n n = ↯
suc[m-n]=suc[m]-n : ∀ n₁ n₂ (n₂≤n₁ : n₂ ≤ n₁) → Succ (n₁ -ⁿ n₂ ‖ n₂≤n₁) ≡ Succ n₁ -ⁿ n₂ ‖ weaken[≤]ⁿ n₂≤n₁
suc[m-n]=suc[m]-n n₁ Zero Zero = ↯
suc[m-n]=suc[m]-n (Succ n₁) (Succ n₂) (Succ n₂≤n₁) rewrite suc[m-n]=suc[m]-n n₁ n₂ n₂≤n₁ = ↯
instance
Subtractive/OK[ℕ] : Subtractive/OK ℕ
Subtractive/OK[ℕ] = record { ok[_-_] = _≥_ }
Subtractive[ℕ] : Subtractive/P ℕ
Subtractive[ℕ] = record
{ _-_‖_ = _-ⁿ_‖_
; correct[-‖] = correct[-ⁿ‖]
}
_-%ⁿ_ : ∀ (n₁ n₂ : ℕ) → ℕ ∨ ℕ
Zero -%ⁿ n₂ = Inr n₂
n₁ -%ⁿ Zero = Inl n₁
Succ n₁ -%ⁿ Succ n₂ = n₁ -%ⁿ n₂
correct[-%ⁿ]/spec : ℕ → ℕ → Set
correct[-%ⁿ]/spec n₁ n₂ with n₁ -%ⁿ n₂
… | Inl n = n₂ + n ≡ n₁
… | Inr n = n₁ + n ≡ n₂
correct[-%ⁿ] : ∀ n₁ n₂ → correct[-%ⁿ]/spec n₁ n₂
correct[-%ⁿ] Zero Zero = ↯
correct[-%ⁿ] Zero (Succ n₂) = ↯
correct[-%ⁿ] (Succ n₁) Zero = ↯
correct[-%ⁿ] (Succ n₁) (Succ n₂) with n₁ -%ⁿ n₂ | correct[-%ⁿ] n₁ n₂
… | Inl x | IH rewrite IH = ↯
… | Inr x | IH rewrite IH = ↯
--------------------------
-- Division and Modulus --
--------------------------
divmod-loop : ∀ (n₁ n₂ quo n₂-rem : ℕ) → n₂-rem ≤ n₂ → ∃ quo,n₂-rem ⦂ ℕ ∧ ℕ 𝑠𝑡 let ⟨ quo' , n₂-rem' ⟩ = quo,n₂-rem in n₂-rem' ≤ n₂
divmod-loop Zero n₂ quo n₂-rem n₂-rem≤n₂ = ⟨∃ ⟨ quo , n₂-rem ⟩ , n₂-rem≤n₂ ⟩
divmod-loop (Succ n₁) n₂ quo Zero n₂-rem≤n₂ = divmod-loop n₁ n₂ (Succ quo) n₂ xRx
divmod-loop (Succ n₁) n₂ quo (Succ n₂-rem) n₂-rem≤n₂ = divmod-loop n₁ n₂ quo n₂-rem (pred[≤]ⁿ n₂-rem≤n₂)
correct[divmod-loop] :
∀ (n₁ n₂ quo n₂-rem : ℕ) (n₂-rem≤n₂ : n₂-rem ≤ n₂)
→ let ⟨∃ ⟨ quo' , n₂-rem' ⟩ , n₂-rem'≤n₂ ⟩ = divmod-loop n₁ n₂ quo n₂-rem n₂-rem≤n₂ in
quo' × Succ n₂ + (n₂ - n₂-rem' ‖ n₂-rem'≤n₂) ≡ n₁ + (quo × Succ n₂) + (n₂ - n₂-rem ‖ n₂-rem≤n₂)
correct[divmod-loop] Zero n₂ quo n₂-rem n₂-rem≤n₂ = ↯
correct[divmod-loop] (Succ n₁) n₂ quo Zero Zero
with divmod-loop n₁ n₂ (Succ quo) n₂ xRx
| correct[divmod-loop] n₁ n₂ (Succ quo) n₂ xRx
… | ⟨∃ ⟨ quo' , n₂-rem' ⟩ , n₂-rem'≤n₂ ⟩ | IH
rewrite suc[m+n]=m+suc[n] n₁ (quo × Succ n₂ + n₂ - Zero ‖ Zero)
| n-n=0 n₂
| commutative[+] (quo × Succ n₂) n₂
| right-unit[+] (n₂ + quo × Succ n₂)
= IH
correct[divmod-loop] (Succ n₁) (Succ n₂) quo (Succ n₂-rem) (Succ n₂-rem≤n₂)
with divmod-loop n₁ (Succ n₂) quo n₂-rem (weaken[≤]ⁿ n₂-rem≤n₂)
| correct[divmod-loop] n₁ (Succ n₂) quo n₂-rem (weaken[≤]ⁿ n₂-rem≤n₂)
… | ⟨∃ ⟨ quo' , n₂-rem' ⟩ , n₂-rem'≤n₂ ⟩ | IH
rewrite suc[m+n]=m+suc[n] n₁ (quo × Succ (Succ n₂) + n₂ - n₂-rem ‖ n₂-rem≤n₂)
| suc[m+n]=m+suc[n] (quo × Succ (Succ n₂)) (n₂ - n₂-rem ‖ n₂-rem≤n₂)
| suc[m-n]=suc[m]-n n₂ n₂-rem n₂-rem≤n₂
= IH
_/%ⁿ_‖_ : ∀ (n₁ n₂ : ℕ) (0<n₂ : 0 < n₂) → ℕ ∧ ℕ
n₁ /%ⁿ Succ n₂ ‖ Zero with divmod-loop n₁ n₂ 0 n₂ xRx⸢≤ⁿ⸣
… | ⟨∃ ⟨ quo , n₂-rem ⟩ , n₂-rem≤n₂ ⟩ = ⟨ quo , n₂ - n₂-rem ‖ n₂-rem≤n₂ ⟩
correct[/%‖]ⁿ : ∀ n₁ n₂ (0<n₂ : 0 < n₂) → let ⟨ quo , rem ⟩ = n₁ /%ⁿ n₂ ‖ 0<n₂ in n₂ × quo + rem ≡ n₁
correct[/%‖]ⁿ n₁ (Succ n₂) Zero with divmod-loop n₁ n₂ 0 n₂ xRx | correct[divmod-loop] n₁ n₂ 0 n₂ xRx
… | ⟨∃ ⟨ quo , n₂-rem ⟩ , n₂-rem≤n₂ ⟩ | H rewrite n-n=0 n₂ | right-unit[+] n₁ | commutative[×] quo (Succ n₂) = H
instance
DivMod/OK[ℕ] : DivMod/OK ℕ
DivMod/OK[ℕ] = record
{ ok[_/%_] = (λ n₁ n₂ → 0 < n₂) }
DivMod[ℕ] : DivMod/P ℕ
DivMod[ℕ] = record
{ _/%_‖_ = _/%ⁿ_‖_
; correct[/%‖] = correct[/%‖]ⁿ
}
-------------
-- Bounded --
-------------
record ℕ≤[_] (nᵇ : ℕ) : Set where
constructor mk[ℕ≤]
field
n : ℕ
n≤nᵇ : n ≤ nᵇ
-- mk↯[ℕ≤] : ∀ {nᵇ} n → {{_ : ✓‼ (n ⁇[ _≤_ ] nᵇ)}} → ℕ≤[ nᵇ ]
-- mk↯[ℕ≤] {nᵇ} n {{_}} with n ⁇[ _≤_ ] nᵇ |
-- mk↯[ℕ≤] {nᵇ} n {{↯Rel}} | Rel n≤nᵇ = mk[ℕ≤] n n≤nᵇ
weaken[ℕ≤] : ∀ {nᵇ₁ nᵇ₂} → nᵇ₁ ≤ nᵇ₂ → ℕ≤[ nᵇ₁ ] → ℕ≤[ nᵇ₂ ]
weaken[ℕ≤] nᵇ₁≤nᵇ₂ (mk[ℕ≤] n n≤nᵇ₁) = mk[ℕ≤] n (nᵇ₁≤nᵇ₂ ⊚ n≤nᵇ₁)
instance
ToNatural[ℕ≤] : ∀ {nᵇ} → ToNatural ℕ≤[ nᵇ ]
ToNatural[ℕ≤] = mk[ToNatural] ℕ≤[_].n
record ℕ<[_] (nᵇ : ℕ) : Set where
constructor mk[ℕ<]
field
n : ℕ
n<nᵇ : n < nᵇ
-- mk↯[ℕ<] : ∀ {nᵇ} n → {{_ : rel (dec-rel[ _<_ ] n nᵇ)}} → ℕ<[ nᵇ ]
-- mk↯[ℕ<] {nᵇ} n {{_}} with dec-rel[ _<_ ] n nᵇ
-- mk↯[ℕ<] {nᵇ} n {{↯Rel}} | Rel n<nᵇ = mk[ℕ<] n n<nᵇ
weaken[ℕ<] : ∀ {nᵇ₁ nᵇ₂} → nᵇ₁ ≤ nᵇ₂ → ℕ<[ nᵇ₁ ] → ℕ<[ nᵇ₂ ]
weaken[ℕ<] nᵇ₁≤nᵇ₂ (mk[ℕ<] n n<nᵇ₁) = mk[ℕ<] n $ π₂ rel[</≤]ⁿ $ nᵇ₁≤nᵇ₂ ⊚ π₁ rel[</≤]ⁿ n<nᵇ₁
instance
ToNatural[ℕ<] : ∀ {nᵇ} → ToNatural ℕ<[ nᵇ ]
ToNatural[ℕ<] = mk[ToNatural] ℕ<[_].n
data fin : ℕ → Set where
Zero : ∀ {n} → fin (Succ n)
Succ : ∀ {n} → fin n → fin (Succ n)
mk[fin/<] : ∀ {nᵇ} n → n < nᵇ → fin nᵇ
mk[fin/<] Zero Zero = Zero
mk[fin/<] (Succ n) (Succ <₁) = Succ (mk[fin/<] n <₁)
mk[fin/ℕ<] : ∀ {nᵇ} → ℕ<[ nᵇ ] → fin nᵇ
mk[fin/ℕ<] (mk[ℕ<] n n<nᵇ) = mk[fin/<] n n<nᵇ
record ℕ⁺ : Set where
constructor mk[ℕ⁺]
field
n : ℕ
0<n : 0 < n
-- mk↯[ℕ⁺] : ∀ n {{_ : rel (dec-rel[ _<_ ] 0 n)}} → ℕ⁺
-- mk↯[ℕ⁺] n {{_}} with dec-rel[ _<_ ] 0 n
-- mk↯[ℕ⁺] n {{↯Rel}} | Rel 0<n = mk[ℕ⁺] n 0<n
instance
ToNatural[ℕ⁺] : ToNatural ℕ⁺
ToNatural[ℕ⁺] = mk[ToNatural] ℕ⁺.n
|
{
"alphanum_fraction": 0.5128079621,
"avg_line_length": 29.6803874092,
"ext": "agda",
"hexsha": "45f71daa9f9b2cbba6ef1912560a615d87c67e86",
"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/plum-umd/cgc/511fa41d8b635bbfe5779fa7fb24d5777dbcaaa5/Prelude/Data/Natural.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/plum-umd/cgc/511fa41d8b635bbfe5779fa7fb24d5777dbcaaa5/Prelude/Data/Natural.agda",
"max_line_length": 130,
"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/plum-umd/cgc/511fa41d8b635bbfe5779fa7fb24d5777dbcaaa5/Prelude/Data/Natural.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": 6979,
"size": 12258
}
|
module Issue591.M where
|
{
"alphanum_fraction": 0.8333333333,
"avg_line_length": 12,
"ext": "agda",
"hexsha": "2292e6815c2a3851a5644767dffc83ef89f4f409",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue591/M.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue591/M.agda",
"max_line_length": 23,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue591/M.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": 6,
"size": 24
}
|
{-# OPTIONS --without-K --safe #-}
module Experiment.TTG where
{-
data Phase : Set where
parse : Phase
scopecheck : Phase
typecheck : Phase
xVar : Phase → Set
xVar p = ?
idP : Phase → Set
idP p = ?
xNew : Phase → Set
data Exp (p : Phase) : Set where
var : xVar p → idP p → Exp p
new : xNew p → Exp p
-}
|
{
"alphanum_fraction": 0.6018808777,
"avg_line_length": 13.8695652174,
"ext": "agda",
"hexsha": "92d196d53bbba519a5ae8e47302591b80dbbf8c2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Experiment/TTG.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rei1024/agda-misc",
"max_issues_repo_path": "Experiment/TTG.agda",
"max_line_length": 34,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Experiment/TTG.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 107,
"size": 319
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.List.Relation.Binary.Permutation.Inductive.Properties directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Permutation.Inductive.Properties where
open import Data.List.Relation.Binary.Permutation.Inductive.Properties
public
{-# WARNING_ON_IMPORT
"Data.List.Relation.Permutation.Inductive.Properties was deprecated in v1.0.
Use Data.List.Relation.Binary.Permutation.Inductive.Properties instead."
#-}
|
{
"alphanum_fraction": 0.6144393241,
"avg_line_length": 34.2631578947,
"ext": "agda",
"hexsha": "2fd544c333ac3d344d816ff501483389687d6405",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Relation/Permutation/Inductive/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Permutation/Inductive/Properties.agda",
"max_line_length": 76,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Permutation/Inductive/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": 120,
"size": 651
}
|
module _ where
open import Agda.Builtin.Float
open import Common.Prelude hiding (_+_; _*_)
print : Float → IO Unit
print x = putStrLn (primShowFloat x)
printB : Bool → IO Unit
printB true = putStrLn "true"
printB false = putStrLn "false"
_+_ = primFloatPlus
_*_ = primFloatTimes
_/_ = primFloatDiv
_==_ = primFloatEquality
_<_ = primFloatLess
NaN : Float
NaN = 0.0 / 0.0
Inf : Float
Inf = 1.0 / 0.0
-Inf : Float
-Inf = -1.0 / 0.0
pi : Float
pi = 3.141592653589793
main : IO Unit
main =
putStr "123.0 = " ,, print 123.0 ,,
putStr "NaN = " ,, print NaN ,,
putStr "Inf = " ,, print Inf ,,
putStr "-Inf = " ,, print -Inf ,,
putStr "-0.0 = " ,, print -0.0 ,,
-- Disabled due to #1856 and #1857
-- putStr "√2 = " ,, print (primFloatTimes 2.0 (primSin (primFloatDiv pi 4.0))) ,,
-- putStr "e = " ,, print (primExp 1.0) ,,
putStr "NaN == NaN = " ,, printB (NaN == NaN) ,,
putStr "Inf == Inf = " ,, printB (Inf == Inf) ,,
putStr "NaN < -Inf = " ,, printB (NaN < -Inf) ,,
putStr "NaN < -5.0 = " ,, printB (NaN < -5.0) ,,
return unit
|
{
"alphanum_fraction": 0.5787037037,
"avg_line_length": 22.5,
"ext": "agda",
"hexsha": "d9d5d346cee324b45b7cba4ee6433cd8bc4e73ea",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Compiler/simple/Floats.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/Compiler/simple/Floats.agda",
"max_line_length": 87,
"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/Compiler/simple/Floats.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 412,
"size": 1080
}
|
-- Andreas, 2015-07-01 polarity of the size argument to data
-- needs to be considered for polarity of later definitions.
-- {-# OPTIONS -v tc.pos:10 -v tc.polarity:20 #-}
open import Common.Size
open import Common.Prelude
data D : (i : Size) → Set where
c : ∀ i → D (↑ i)
E : Bool → Size → Set
E true i = D i
E false i = D i
cast : ∀{i b} → E b i → E b (↑ i)
cast x = x
-- should succeed
|
{
"alphanum_fraction": 0.6206030151,
"avg_line_length": 19.9,
"ext": "agda",
"hexsha": "90d53258e9c959629dccf7a4432ccac3cde62be3",
"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/Succeed/PolaritySucSizeData.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/PolaritySucSizeData.agda",
"max_line_length": 60,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/PolaritySucSizeData.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": 131,
"size": 398
}
|
-- issue 685
module ShadowedLetBoundVar where
import Common.Level
record Wrap {a}(A : Set a) : Set a where
constructor wrap
field wrapped : A
-- let is not recursive
works : Set → Set
works x = let x = x in x
fails : Set → Set
fails A = let wrap A = wrap A in A
-- works now
|
{
"alphanum_fraction": 0.6725352113,
"avg_line_length": 15.7777777778,
"ext": "agda",
"hexsha": "32f3631a357595f1173c2996d47d644bda55088e",
"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/ShadowedLetBoundVar.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/ShadowedLetBoundVar.agda",
"max_line_length": 40,
"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/ShadowedLetBoundVar.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": 86,
"size": 284
}
|
module hott.topology where
open import hott.topology.loopspace public
|
{
"alphanum_fraction": 0.8450704225,
"avg_line_length": 17.75,
"ext": "agda",
"hexsha": "b4d6fa535aebaf33c71a1a2c629ce1a673538a86",
"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": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "piyush-kurur/hott",
"max_forks_repo_path": "agda/hott/topology.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"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": "piyush-kurur/hott",
"max_issues_repo_path": "agda/hott/topology.agda",
"max_line_length": 42,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "piyush-kurur/hott",
"max_stars_repo_path": "agda/hott/topology.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 16,
"size": 71
}
|
{-# OPTIONS --without-K --safe #-}
module Codiscrete where
open import Level using (Level; 0ℓ; lift; lower)
open import Data.Nat using (ℕ; suc)
open import Data.Fin hiding (lift)
open import Data.Unit
open import Function renaming (id to idf)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans)
open import Categories.Category.Groupoid
open import Categories.Category.Instance.One
open import Categories.Category.Equivalence using (StrongEquivalence; WeakInverse)
open import Categories.Functor using (Functor; _∘F_) renaming (id to idF)
open import Categories.Category using (Category)
open import Categories.NaturalTransformation using (NaturalTransformation)
open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_)
-- Codiscrete Groupoid on (n+1) points
CodiscreteGroupoid : (n : ℕ) → Groupoid 0ℓ 0ℓ 0ℓ
CodiscreteGroupoid n = record
{ category = record
{ Obj = Fin (suc n)
; _⇒_ = λ _ _ → ⊤
; _≈_ = _≡_
; assoc = refl
; sym-assoc = refl
; identityˡ = refl
; identityʳ = refl
; equiv = record { refl = refl ; sym = sym ; trans = trans }
; ∘-resp-≈ = λ _ _ → refl
}
; isGroupoid = record
{ _⁻¹ = idf
; iso = record { isoˡ = refl ; isoʳ = refl }
}
}
open Groupoid
Contractible : (n : ℕ) → (k : Fin (suc n)) →
StrongEquivalence (category (CodiscreteGroupoid n)) (One {0ℓ} {0ℓ} {0ℓ})
Contractible n k = record
{ F = F
; G = G
; weak-inverse = record
{ F∘G≈id = F∘G≃id
; G∘F≈id = G∘F≃id
}
}
where
C : Category _ _ _
C = category (CodiscreteGroupoid n)
O : Category 0ℓ 0ℓ 0ℓ
O = One
F : Functor C O
F = record
{ F₀ = λ _ → lift tt -- This is our 'GC' function
; F₁ = lift
; identity = lift tt
; homomorphism = lift tt
; F-resp-≈ = λ _ → lift tt
}
-- This is where 'k' is used:
G : Functor O C
G = record
{ F₀ = λ _ → k
; F₁ = lower
; identity = refl
; homomorphism = refl
; F-resp-≈ = λ _ → refl
}
F∘G≃id : F ∘F G ≃ idF
F∘G≃id = record
{ F⇒G = record { η = idf ; commute = idf }
; F⇐G = record { η = idf ; commute = idf }
}
G∘F≃id : G ∘F F ≃ idF
G∘F≃id = record
{ F⇒G = record { η = λ _ → tt ; commute = λ _ → refl }
; F⇐G = record { η = λ _ → tt ; commute = λ _ → refl }
; iso = λ X → record { isoˡ = refl ; isoʳ = refl }
}
|
{
"alphanum_fraction": 0.6077933079,
"avg_line_length": 27.4534883721,
"ext": "agda",
"hexsha": "b67c42b9ad51c8c500c683778ef942a586f9211b",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "fracGC/Codiscrete.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "fracGC/Codiscrete.agda",
"max_line_length": 82,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "fracGC/Codiscrete.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 857,
"size": 2361
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Basic types related to coinduction
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Codata.Musical.Notation where
open import Agda.Builtin.Coinduction public
|
{
"alphanum_fraction": 0.4208955224,
"avg_line_length": 27.9166666667,
"ext": "agda",
"hexsha": "98bb2e780614b9dce401b06a3420d1103d196a9e",
"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/Codata/Musical/Notation.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/Codata/Musical/Notation.agda",
"max_line_length": 72,
"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/Codata/Musical/Notation.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": 50,
"size": 335
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Core definitions for Strings
------------------------------------------------------------------------
module Data.String.Core where
open import Data.List using (List)
open import Data.Bool using (Bool; true; false)
open import Data.Char.Core using (Char)
------------------------------------------------------------------------
-- The type
postulate
String : Set
{-# BUILTIN STRING String #-}
{-# COMPILED_TYPE String String #-}
------------------------------------------------------------------------
-- Primitive operations
primitive
primStringAppend : String → String → String
primStringToList : String → List Char
primStringFromList : List Char → String
primStringEquality : String → String → Bool
primShowString : String → String
-- Here instead of Data.Char.Core to avoid an import cycle
primShowChar : Char → String
|
{
"alphanum_fraction": 0.5015479876,
"avg_line_length": 28.5,
"ext": "agda",
"hexsha": "718bf0dd099c854f6390de90fe944c7fca136820",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/String/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/String/Core.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/String/Core.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 168,
"size": 969
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some basic properties of Rings
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Algebra.Properties.Ring {r₁ r₂} (R : Ring r₁ r₂) where
open Ring R
import Algebra.Properties.AbelianGroup as AbelianGroupProperties
open import Function using (_$_)
open import Relation.Binary.Reasoning.Setoid setoid
------------------------------------------------------------------------
-- Export properties of abelian groups
open AbelianGroupProperties +-abelianGroup public
renaming
( ε⁻¹≈ε to -0#≈0#
; ∙-cancelˡ to +-cancelˡ
; ∙-cancelʳ to +-cancelʳ
; ∙-cancel to +-cancel
; ⁻¹-involutive to -‿involutive
; ⁻¹-injective to -‿injective
; ⁻¹-anti-homo-∙ to -‿anti-homo-+
; identityˡ-unique to +-identityˡ-unique
; identityʳ-unique to +-identityʳ-unique
; identity-unique to +-identity-unique
; inverseˡ-unique to +-inverseˡ-unique
; inverseʳ-unique to +-inverseʳ-unique
; ⁻¹-∙-comm to -‿+-comm
-- DEPRECATED
; left-identity-unique to +-left-identity-unique
; right-identity-unique to +-right-identity-unique
; left-inverse-unique to +-left-inverse-unique
; right-inverse-unique to +-right-inverse-unique
)
------------------------------------------------------------------------
-- Properties of -_
-‿distribˡ-* : ∀ x y → - (x * y) ≈ - x * y
-‿distribˡ-* x y = sym $ begin
- x * y ≈⟨ sym $ +-identityʳ _ ⟩
- x * y + 0# ≈⟨ +-congˡ $ sym (-‿inverseʳ _) ⟩
- x * y + (x * y + - (x * y)) ≈⟨ sym $ +-assoc _ _ _ ⟩
- x * y + x * y + - (x * y) ≈⟨ +-congʳ $ sym (distribʳ _ _ _) ⟩
(- x + x) * y + - (x * y) ≈⟨ +-congʳ $ *-congʳ $ -‿inverseˡ _ ⟩
0# * y + - (x * y) ≈⟨ +-congʳ $ zeroˡ _ ⟩
0# + - (x * y) ≈⟨ +-identityˡ _ ⟩
- (x * y) ∎
-‿distribʳ-* : ∀ x y → - (x * y) ≈ x * - y
-‿distribʳ-* x y = sym $ begin
x * - y ≈⟨ sym $ +-identityˡ _ ⟩
0# + x * - y ≈⟨ +-congʳ $ sym (-‿inverseˡ _) ⟩
- (x * y) + x * y + x * - y ≈⟨ +-assoc _ _ _ ⟩
- (x * y) + (x * y + x * - y) ≈⟨ +-congˡ $ sym (distribˡ _ _ _) ⟩
- (x * y) + x * (y + - y) ≈⟨ +-congˡ $ *-congˡ $ -‿inverseʳ _ ⟩
- (x * y) + x * 0# ≈⟨ +-congˡ $ zeroʳ _ ⟩
- (x * y) + 0# ≈⟨ +-identityʳ _ ⟩
- (x * y) ∎
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.1
-‿*-distribˡ : ∀ x y → - x * y ≈ - (x * y)
-‿*-distribˡ x y = sym (-‿distribˡ-* x y)
{-# WARNING_ON_USAGE -‿*-distribˡ
"Warning: -‿*-distribˡ was deprecated in v1.1.
Please use -‿distribˡ-* instead.
NOTE: the equality is flipped so you will need sym (-‿distribˡ-* ...)."
#-}
-‿*-distribʳ : ∀ x y → x * - y ≈ - (x * y)
-‿*-distribʳ x y = sym (-‿distribʳ-* x y)
{-# WARNING_ON_USAGE -‿*-distribʳ
"Warning: -‿*-distribʳ was deprecated in v1.1.
Please use -‿distribʳ-* instead.
NOTE: the equality is flipped so you will need sym (-‿distribʳ-* ...)."
#-}
|
{
"alphanum_fraction": 0.458788774,
"avg_line_length": 36.7934782609,
"ext": "agda",
"hexsha": "a16f302cd11d2409538d58165a44e540572965ec",
"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/Algebra/Properties/Ring.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/Algebra/Properties/Ring.agda",
"max_line_length": 72,
"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/Algebra/Properties/Ring.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": 1207,
"size": 3385
}
|
module Generic.Lib.Decidable where
open import Relation.Nullary public
open import Relation.Nullary.Decidable hiding (map) public
open import Relation.Binary using (Decidable) public
open import Generic.Lib.Intro
open import Generic.Lib.Equality.Propositional
open import Generic.Lib.Equality.Heteroindexed
open import Generic.Lib.Data.Sum
open import Generic.Lib.Data.Product
open import Relation.Nullary
import Data.String as String
infix 3 _#_
IsSet : ∀ {α} -> Set α -> Set α
IsSet A = Decidable {A = A} _≡_
record Eq {α} (A : Set α) : Set α where
infixl 5 _≟_ _==_
field _≟_ : IsSet A
_==_ : A -> A -> Bool
x == y = ⌊ x ≟ y ⌋
open Eq {{...}} public
record _↦_ {α} (A B : Set α) : Set α where
constructor packInj
field
to : A -> B
from : B -> A
from-to : from ∘ to ≗ id
-- Can't make it an instance, because otherwise it unreasonably breaks instance search.
viaInj : ∀ {α} {A B : Set α} {{bEq : Eq B}} -> A ↦ B -> Eq A
viaInj {A = A} {B} inj = record
{ _≟_ = flip (via-injection {A = ≡-Setoid A} {B = ≡-Setoid B}) _≟_ $ record
{ to = record
{ _⟨$⟩_ = to
; cong = cong to
}
; injective = λ q -> right (from-to _) (trans (cong from q) (from-to _))
}
} where open _↦_ inj
_#_ : ∀ {α} {A : Set α} -> A -> A -> Set
x # y = Dec (x ≡ y)
delim : ∀ {α π} {A : Set α} {P : Dec A -> Set π}
-> (∀ x -> P (yes x)) -> (∀ c -> P (no c)) -> (d : Dec A) -> P d
delim f g (yes x) = f x
delim f g (no c) = g c
drec : ∀ {α β} {A : Set α} {B : Set β} -> (A -> B) -> (¬ A -> B) -> Dec A -> B
drec = delim
dmap : ∀ {α β} {A : Set α} {B : Set β} -> (A -> B) -> (¬ A -> ¬ B) -> Dec A -> Dec B
dmap f g = drec (yes ∘ f) (no ∘ g)
sumM2 : ∀ {α β γ} {A : Set α} {B : Set β} {C : Set γ}
-> (A -> Dec C) -> (B -> Dec C) -> (¬ A -> ¬ B -> Dec C) -> Dec A -> Dec B -> Dec C
sumM2 f g h d e = drec f (λ c -> drec g (h c) e) d
prodM2 : ∀ {α β γ} {A : Set α} {B : Set β} {C : Set γ}
-> (A -> B -> Dec C) -> (¬ A -> Dec C) -> (¬ B -> Dec C) -> Dec A -> Dec B -> Dec C
prodM2 h f g d e = drec (λ x -> drec (h x) g e) f d
sumF2 : ∀ {α β γ} {A : Set α} {B : Set β} {C : Set γ}
-> (A -> C) -> (B -> C) -> (¬ A -> ¬ B -> ¬ C) -> Dec A -> Dec B -> Dec C
sumF2 f g h = sumM2 (yes ∘ f) (yes ∘ g) (no % ∘ h)
prodF2 : ∀ {α β γ} {A : Set α} {B : Set β} {C : Set γ}
-> (A -> B -> C) -> (¬ A -> ¬ C) -> (¬ B -> ¬ C) -> Dec A -> Dec B -> Dec C
prodF2 h f g = prodM2 (yes % ∘ h) (no ∘ f) (no ∘ g)
dcong : ∀ {α β} {A : Set α} {B : Set β} {x y}
-> (f : A -> B) -> (f x ≡ f y -> x ≡ y) -> x # y -> f x # f y
dcong f inj = dmap (cong f) (_∘ inj)
dcong₂ : ∀ {α β γ} {A : Set α} {B : Set β} {C : Set γ} {x₁ x₂ y₁ y₂}
-> (f : A -> B -> C)
-> (f x₁ y₁ ≡ f x₂ y₂ -> x₁ ≡ x₂ × y₁ ≡ y₂)
-> x₁ # x₂
-> y₁ # y₂
-> f x₁ y₁ # f x₂ y₂
dcong₂ f inj = prodF2 (cong₂ f) (λ c -> c ∘ proj₁ ∘ inj) (λ c -> c ∘ proj₂ ∘ inj)
dhcong₂ : ∀ {α β γ} {A : Set α} {B : A -> Set β} {C : Set γ} {x₁ x₂ y₁ y₂}
-> (f : ∀ x -> B x -> C)
-> (f x₁ y₁ ≡ f x₂ y₂ -> [ B ] y₁ ≅ y₂)
-> x₁ # x₂
-> (∀ y₂ -> y₁ # y₂)
-> f x₁ y₁ # f x₂ y₂
dhcong₂ f inj (yes refl) q = dcong (f _) (homo ∘ inj) (q _)
dhcong₂ f inj (no c) q = no (c ∘ inds ∘ inj)
dsubst : ∀ {α β γ} {A : Set α} {x y}
-> (B : A -> Set β)
-> (C : ∀ {x} -> B x -> Set γ)
-> x # y
-> (z : B x)
-> ((z : B y) -> C z)
-> (x ≢ y -> C z)
-> C z
dsubst B C (yes refl) z g h = g z
dsubst B C (no c) z g h = h c
dsubst′ : ∀ {α β γ} {A : Set α} {C : Set γ} {x y}
-> (B : A -> Set β) -> x # y -> B x -> (B y -> C) -> (x ≢ y -> C) -> C
dsubst′ B = dsubst B _
,-inj : ∀ {α β} {A : Set α} {B : A -> Set β} {x₁ x₂} {y₁ : B x₁} {y₂ : B x₂}
-> (x₁ , y₁) ≡ (x₂ , y₂) -> [ B ] y₁ ≅ y₂
,-inj refl = irefl
inj₁-inj : ∀ {α β} {A : Set α} {B : Set β} {x₁ x₂ : A}
-> inj₁ {B = B} x₁ ≡ inj₁ x₂ -> x₁ ≡ x₂
inj₁-inj refl = refl
inj₂-inj : ∀ {α β} {A : Set α} {B : Set β} {y₁ y₂ : B}
-> inj₂ {A = A} y₁ ≡ inj₂ y₂ -> y₁ ≡ y₂
inj₂-inj refl = refl
-- _<,>ᵈ_ : ∀ {α β} {A : Set α} {B : Set β} {x₁ x₂ : A} {y₁ y₂ : B}
-- -> x₁ # x₂ -> y₁ # y₂ -> x₁ , y₁ # x₂ , y₂
-- _<,>ᵈ_ = dcong₂ _,_ (inds-homo ∘ ,-inj)
-- _<,>ᵈᵒ_ : ∀ {α β} {A : Set α} {B : A -> Set β} {x₁ x₂} {y₁ : B x₁} {y₂ : B x₂}
-- -> x₁ # x₂ -> (∀ y₂ -> y₁ # y₂) -> x₁ , y₁ # x₂ , y₂
-- _<,>ᵈᵒ_ = dhcong₂ _,_ ,-inj
decSum : ∀ {α β} {A : Set α} {B : Set β}
-> IsSet A -> IsSet B -> IsSet (A ⊎ B)
decSum f g (inj₁ x₁) (inj₁ x₂) = dcong inj₁ inj₁-inj (f x₁ x₂)
decSum f g (inj₂ y₁) (inj₂ y₂) = dcong inj₂ inj₂-inj (g y₁ y₂)
decSum f g (inj₁ x₁) (inj₂ y₂) = no λ()
decSum f g (inj₂ y₁) (inj₁ x₂) = no λ()
decProd : ∀ {α β} {A : Set α} {B : A -> Set β}
-> IsSet A -> (∀ {x} -> IsSet (B x)) -> IsSet (Σ A B)
decProd f g (x₁ , y₁) (x₂ , y₂) = dhcong₂ _,_ ,-inj (f x₁ x₂) (g y₁)
module _ where
import Relation.Binary.PropositionalEquality as B
liftBase : ∀ {α} {A : Set α} {x y : A} -> x B.≡ y -> x ≡ y
liftBase B.refl = refl
lowerBase : ∀ {α} {A : Set α} {x y : A} -> x ≡ y -> x B.≡ y
lowerBase refl = B.refl
viaBase : ∀ {α} {A : Set α} -> Decidable (B._≡_ {A = A}) -> Eq A
viaBase d = record
{ _≟_ = flip (via-injection {A = ≡-Setoid _} {B = B.setoid _}) d $ record
{ to = record
{ _⟨$⟩_ = id
; cong = lowerBase
}
; injective = liftBase
}
}
|
{
"alphanum_fraction": 0.453532956,
"avg_line_length": 33.1939393939,
"ext": "agda",
"hexsha": "615407607b573ae913b33fb28a595f00b4843467",
"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": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Lib/Decidable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"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": "turion/Generic",
"max_issues_repo_path": "src/Generic/Lib/Decidable.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Lib/Decidable.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2468,
"size": 5477
}
|
-- The following deeply left-nested expression illustrates a problem
-- in a previous implementation of the occurrence machinery.
postulate A : Set
data List : Set where
nil : List
snoc : List → A → List
f : A → List
f x = snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc (snoc nil x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x) x
|
{
"alphanum_fraction": 0.5561755826,
"avg_line_length": 4913.1666666667,
"ext": "agda",
"hexsha": "b87d82833a98c4e8e72da4ef9d86a48b8b66aab9",
"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": "benchmark/misc/SlowOccurrences2.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": "benchmark/misc/SlowOccurrences2.agda",
"max_line_length": 58732,
"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": "benchmark/misc/SlowOccurrences2.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": 32684,
"size": 58958
}
|
{-# OPTIONS --show-implicit #-}
module PragmasRespected where
postulate
Foo : {A : Set₁} → Set
Bar : Foo {A = Set}
|
{
"alphanum_fraction": 0.6280991736,
"avg_line_length": 15.125,
"ext": "agda",
"hexsha": "55d06672d58b9f2d4bc6a6b30968eb04ae86b594",
"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/interaction/PragmasRespected.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/interaction/PragmasRespected.agda",
"max_line_length": 31,
"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/interaction/PragmasRespected.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": 39,
"size": 121
}
|
{-# OPTIONS --allow-unsolved-metas #-}
module gcd where
open import Data.Nat
open import Data.Nat.Properties
open import Data.Empty
open import Data.Unit using (⊤ ; tt)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Relation.Binary.Definitions
open import nat
open import logic
open Factor
gcd1 : ( i i0 j j0 : ℕ ) → ℕ
gcd1 zero i0 zero j0 with <-cmp i0 j0
... | tri< a ¬b ¬c = i0
... | tri≈ ¬a refl ¬c = i0
... | tri> ¬a ¬b c = j0
gcd1 zero i0 (suc zero) j0 = 1
gcd1 zero zero (suc (suc j)) j0 = j0
gcd1 zero (suc i0) (suc (suc j)) j0 = gcd1 i0 (suc i0) (suc j) (suc (suc j))
gcd1 (suc zero) i0 zero j0 = 1
gcd1 (suc (suc i)) i0 zero zero = i0
gcd1 (suc (suc i)) i0 zero (suc j0) = gcd1 (suc i) (suc (suc i)) j0 (suc j0)
gcd1 (suc i) i0 (suc j) j0 = gcd1 i i0 j j0
gcd : ( i j : ℕ ) → ℕ
gcd i j = gcd1 i i j j
gcd20 : (i : ℕ) → gcd i 0 ≡ i
gcd20 zero = refl
gcd20 (suc i) = gcd201 (suc i) where
gcd201 : (i : ℕ ) → gcd1 i i zero zero ≡ i
gcd201 zero = refl
gcd201 (suc zero) = refl
gcd201 (suc (suc i)) = refl
gcd22 : ( i i0 o o0 : ℕ ) → gcd1 (suc i) i0 (suc o) o0 ≡ gcd1 i i0 o o0
gcd22 zero i0 zero o0 = refl
gcd22 zero i0 (suc o) o0 = refl
gcd22 (suc i) i0 zero o0 = refl
gcd22 (suc i) i0 (suc o) o0 = refl
gcdmm : (n m : ℕ) → gcd1 n m n m ≡ m
gcdmm zero m with <-cmp m m
... | tri< a ¬b ¬c = refl
... | tri≈ ¬a refl ¬c = refl
... | tri> ¬a ¬b c = refl
gcdmm (suc n) m = subst (λ k → k ≡ m) (sym (gcd22 n m n m )) (gcdmm n m )
gcdsym2 : (i j : ℕ) → gcd1 zero i zero j ≡ gcd1 zero j zero i
gcdsym2 i j with <-cmp i j | <-cmp j i
... | tri< a ¬b ¬c | tri< a₁ ¬b₁ ¬c₁ = ⊥-elim (nat-<> a a₁)
... | tri< a ¬b ¬c | tri≈ ¬a b ¬c₁ = ⊥-elim (nat-≡< (sym b) a)
... | tri< a ¬b ¬c | tri> ¬a ¬b₁ c = refl
... | tri≈ ¬a b ¬c | tri< a ¬b ¬c₁ = ⊥-elim (nat-≡< (sym b) a)
... | tri≈ ¬a refl ¬c | tri≈ ¬a₁ refl ¬c₁ = refl
... | tri≈ ¬a b ¬c | tri> ¬a₁ ¬b c = ⊥-elim (nat-≡< b c)
... | tri> ¬a ¬b c | tri< a ¬b₁ ¬c = refl
... | tri> ¬a ¬b c | tri≈ ¬a₁ b ¬c = ⊥-elim (nat-≡< b c)
... | tri> ¬a ¬b c | tri> ¬a₁ ¬b₁ c₁ = ⊥-elim (nat-<> c c₁)
gcdsym1 : ( i i0 j j0 : ℕ ) → gcd1 i i0 j j0 ≡ gcd1 j j0 i i0
gcdsym1 zero zero zero zero = refl
gcdsym1 zero zero zero (suc j0) = refl
gcdsym1 zero (suc i0) zero zero = refl
gcdsym1 zero (suc i0) zero (suc j0) = gcdsym2 (suc i0) (suc j0)
gcdsym1 zero zero (suc zero) j0 = refl
gcdsym1 zero zero (suc (suc j)) j0 = refl
gcdsym1 zero (suc i0) (suc zero) j0 = refl
gcdsym1 zero (suc i0) (suc (suc j)) j0 = gcdsym1 i0 (suc i0) (suc j) (suc (suc j))
gcdsym1 (suc zero) i0 zero j0 = refl
gcdsym1 (suc (suc i)) i0 zero zero = refl
gcdsym1 (suc (suc i)) i0 zero (suc j0) = gcdsym1 (suc i) (suc (suc i))j0 (suc j0)
gcdsym1 (suc i) i0 (suc j) j0 = subst₂ (λ j k → j ≡ k ) (sym (gcd22 i _ _ _)) (sym (gcd22 j _ _ _)) (gcdsym1 i i0 j j0 )
gcdsym : { n m : ℕ} → gcd n m ≡ gcd m n
gcdsym {n} {m} = gcdsym1 n n m m
gcd11 : ( i : ℕ ) → gcd i i ≡ i
gcd11 i = gcdmm i i
gcd203 : (i : ℕ) → gcd1 (suc i) (suc i) i i ≡ 1
gcd203 zero = refl
gcd203 (suc i) = gcd205 (suc i) where
gcd205 : (j : ℕ) → gcd1 (suc j) (suc (suc i)) j (suc i) ≡ 1
gcd205 zero = refl
gcd205 (suc j) = subst (λ k → k ≡ 1) (gcd22 (suc j) (suc (suc i)) j (suc i)) (gcd205 j)
gcd204 : (i : ℕ) → gcd1 1 1 i i ≡ 1
gcd204 zero = refl
gcd204 (suc zero) = refl
gcd204 (suc (suc zero)) = refl
gcd204 (suc (suc (suc i))) = gcd204 (suc (suc i))
gcd+j : ( i j : ℕ ) → gcd (i + j) j ≡ gcd i j
gcd+j i j = gcd200 i i j j refl refl where
gcd202 : (i j1 : ℕ) → (i + suc j1) ≡ suc (i + j1)
gcd202 zero j1 = refl
gcd202 (suc i) j1 = cong suc (gcd202 i j1)
gcd201 : (i i0 j j0 j1 : ℕ) → gcd1 (i + j1) (i0 + suc j) j1 j0 ≡ gcd1 i (i0 + suc j) zero j0
gcd201 i i0 j j0 zero = subst (λ k → gcd1 k (i0 + suc j) zero j0 ≡ gcd1 i (i0 + suc j) zero j0 ) (+-comm zero i) refl
gcd201 i i0 j j0 (suc j1) = begin
gcd1 (i + suc j1) (i0 + suc j) (suc j1) j0 ≡⟨ cong (λ k → gcd1 k (i0 + suc j) (suc j1) j0 ) (gcd202 i j1) ⟩
gcd1 (suc (i + j1)) (i0 + suc j) (suc j1) j0 ≡⟨ gcd22 (i + j1) (i0 + suc j) j1 j0 ⟩
gcd1 (i + j1) (i0 + suc j) j1 j0 ≡⟨ gcd201 i i0 j j0 j1 ⟩
gcd1 i (i0 + suc j) zero j0 ∎ where open ≡-Reasoning
gcd200 : (i i0 j j0 : ℕ) → i ≡ i0 → j ≡ j0 → gcd1 (i + j) (i0 + j) j j0 ≡ gcd1 i i j0 j0
gcd200 i .i zero .0 refl refl = subst (λ k → gcd1 k k zero zero ≡ gcd1 i i zero zero ) (+-comm zero i) refl
gcd200 (suc (suc i)) i0 (suc j) (suc j0) i=i0 j=j0 = gcd201 (suc (suc i)) i0 j (suc j0) (suc j)
gcd200 zero zero (suc zero) .1 i=i0 refl = refl
gcd200 zero zero (suc (suc j)) .(suc (suc j)) i=i0 refl = begin
gcd1 (zero + suc (suc j)) (zero + suc (suc j)) (suc (suc j)) (suc (suc j)) ≡⟨ gcdmm (suc (suc j)) (suc (suc j)) ⟩
suc (suc j) ≡⟨ sym (gcd20 (suc (suc j))) ⟩
gcd1 zero zero (suc (suc j)) (suc (suc j)) ∎ where open ≡-Reasoning
gcd200 zero (suc i0) (suc j) .(suc j) () refl
gcd200 (suc zero) .1 (suc j) .(suc j) refl refl = begin
gcd1 (1 + suc j) (1 + suc j) (suc j) (suc j) ≡⟨ gcd203 (suc j) ⟩
1 ≡⟨ sym ( gcd204 (suc j)) ⟩
gcd1 1 1 (suc j) (suc j) ∎ where open ≡-Reasoning
gcd200 (suc (suc i)) i0 (suc j) zero i=i0 ()
open _∧_
gcd-gt : ( i i0 j j0 k : ℕ ) → k > 1 → (if : Factor k i) (i0f : Dividable k i0 ) (jf : Factor k j ) (j0f : Dividable k j0)
→ Dividable k (i - j) ∧ Dividable k (j - i)
→ Dividable k ( gcd1 i i0 j j0 )
gcd-gt zero i0 zero j0 k k>1 if i0f jf j0f i-j with <-cmp i0 j0
... | tri< a ¬b ¬c = i0f
... | tri≈ ¬a refl ¬c = i0f
... | tri> ¬a ¬b c = j0f
gcd-gt zero i0 (suc zero) j0 k k>1 if i0f jf j0f i-j = ⊥-elim (div1 k>1 (proj2 i-j)) -- can't happen
gcd-gt zero zero (suc (suc j)) j0 k k>1 if i0f jf j0f i-j = j0f
gcd-gt zero (suc i0) (suc (suc j)) j0 k k>1 if i0f jf j0f i-j =
gcd-gt i0 (suc i0) (suc j) (suc (suc j)) k k>1 (decf (DtoF i0f)) i0f (decf jf) (proj2 i-j) (div-div k>1 i0f (proj2 i-j))
gcd-gt (suc zero) i0 zero j0 k k>1 if i0f jf j0f i-j = ⊥-elim (div1 k>1 (proj1 i-j)) -- can't happen
gcd-gt (suc (suc i)) i0 zero zero k k>1 if i0f jf j0f i-j = i0f
gcd-gt (suc (suc i)) i0 zero (suc j0) k k>1 if i0f jf j0f i-j = --
gcd-gt (suc i) (suc (suc i)) j0 (suc j0) k k>1 (decf if) (proj1 i-j) (decf (DtoF j0f)) j0f (div-div k>1 (proj1 i-j) j0f )
gcd-gt (suc zero) i0 (suc j) j0 k k>1 if i0f jf j0f i-j =
gcd-gt zero i0 j j0 k k>1 (decf if) i0f (decf jf) j0f i-j
gcd-gt (suc (suc i)) i0 (suc j) j0 k k>1 if i0f jf j0f i-j =
gcd-gt (suc i) i0 j j0 k k>1 (decf if) i0f (decf jf) j0f i-j
gcd-div : ( i j k : ℕ ) → k > 1 → (if : Dividable k i) (jf : Dividable k j )
→ Dividable k ( gcd i j )
gcd-div i j k k>1 if jf = gcd-gt i i j j k k>1 (DtoF if) if (DtoF jf) jf (div-div k>1 if jf)
di-next : {i i0 j j0 : ℕ} → Dividable i0 ((j0 + suc i) - suc j ) ∧ Dividable j0 ((i0 + suc j) - suc i) →
Dividable i0 ((j0 + i) - j ) ∧ Dividable j0 ((i0 + j) - i)
di-next {i} {i0} {j} {j0} x =
⟪ ( subst (λ k → Dividable i0 (k - suc j)) ( begin
j0 + suc i ≡⟨ sym (+-assoc j0 1 i ) ⟩
(j0 + 1) + i ≡⟨ cong (λ k → k + i) (+-comm j0 _ ) ⟩
suc (j0 + i) ∎ ) (proj1 x) ) ,
( subst (λ k → Dividable j0 (k - suc i)) ( begin
i0 + suc j ≡⟨ sym (+-assoc i0 1 j ) ⟩
(i0 + 1) + j ≡⟨ cong (λ k → k + j) (+-comm i0 _ ) ⟩
suc (i0 + j) ∎ ) (proj2 x) ) ⟫
where open ≡-Reasoning
di-next1 : {i0 j j0 : ℕ} → Dividable (suc i0) ((j0 + 0) - (suc (suc j))) ∧ Dividable j0 (suc (i0 + suc (suc j)))
→ Dividable (suc i0) ((suc (suc j) + i0) - suc j) ∧ Dividable (suc (suc j)) ((suc i0 + suc j) - i0)
di-next1 {i0} {j} {j0} x =
⟪ record { factor = 1 ; is-factor = begin
1 * suc i0 + 0 ≡⟨ cong suc ( trans (+-comm _ 0) (+-comm _ 0) ) ⟩
suc i0 ≡⟨ sym (minus+y-y {suc i0} {j}) ⟩
(suc i0 + j) - j ≡⟨ cong (λ k → k - j ) (+-comm (suc i0) _ ) ⟩
(suc j + suc i0 ) - suc j ≡⟨ cong (λ k → k - suc j) (sym (+-assoc (suc j) 1 i0 )) ⟩
((suc j + 1) + i0) - suc j ≡⟨ cong (λ k → (k + i0) - suc j) (+-comm _ 1) ⟩
(suc (suc j) + i0) - suc j ∎ } ,
subst (λ k → Dividable (suc (suc j)) k) ( begin
suc (suc j) ≡⟨ sym ( minus+y-y {suc (suc j)}{i0} ) ⟩
(suc (suc j) + i0 ) - i0 ≡⟨ cong (λ k → (k + i0) - i0) (cong suc (+-comm 1 _ )) ⟩
((suc j + 1) + i0 ) - i0 ≡⟨ cong (λ k → k - i0) (+-assoc (suc j) 1 _ ) ⟩
(suc j + suc i0 ) - i0 ≡⟨ cong (λ k → k - i0) (+-comm (suc j) _) ⟩
((suc i0 + suc j) - i0) ∎ ) div= ⟫
where open ≡-Reasoning
gcd>0 : ( i j : ℕ ) → 0 < i → 0 < j → 0 < gcd i j
gcd>0 i j 0<i 0<j = gcd>01 i i j j 0<i 0<j where
gcd>01 : ( i i0 j j0 : ℕ ) → 0 < i0 → 0 < j0 → gcd1 i i0 j j0 > 0
gcd>01 zero i0 zero j0 0<i 0<j with <-cmp i0 j0
... | tri< a ¬b ¬c = 0<i
... | tri≈ ¬a refl ¬c = 0<i
... | tri> ¬a ¬b c = 0<j
gcd>01 zero i0 (suc zero) j0 0<i 0<j = s≤s z≤n
gcd>01 zero zero (suc (suc j)) j0 0<i 0<j = 0<j
gcd>01 zero (suc i0) (suc (suc j)) j0 0<i 0<j = gcd>01 i0 (suc i0) (suc j) (suc (suc j)) 0<i (s≤s z≤n) -- 0 < suc (suc j)
gcd>01 (suc zero) i0 zero j0 0<i 0<j = s≤s z≤n
gcd>01 (suc (suc i)) i0 zero zero 0<i 0<j = 0<i
gcd>01 (suc (suc i)) i0 zero (suc j0) 0<i 0<j = gcd>01 (suc i) (suc (suc i)) j0 (suc j0) (s≤s z≤n) 0<j
gcd>01 (suc i) i0 (suc j) j0 0<i 0<j = subst (λ k → 0 < k ) (sym (gcd033 i i0 j j0 )) (gcd>01 i i0 j j0 0<i 0<j ) where
gcd033 : (i i0 j j0 : ℕ) → gcd1 (suc i) i0 (suc j) j0 ≡ gcd1 i i0 j j0
gcd033 zero zero zero zero = refl
gcd033 zero zero (suc j) zero = refl
gcd033 (suc i) zero j zero = refl
gcd033 zero zero zero (suc j0) = refl
gcd033 (suc i) zero zero (suc j0) = refl
gcd033 zero zero (suc j) (suc j0) = refl
gcd033 (suc i) zero (suc j) (suc j0) = refl
gcd033 zero (suc i0) j j0 = refl
gcd033 (suc i) (suc i0) j j0 = refl
-- gcd loop invariant
--
record GCD ( i i0 j j0 : ℕ ) : Set where
field
i<i0 : i ≤ i0
j<j0 : j ≤ j0
div-i : Dividable i0 ((j0 + i) - j)
div-j : Dividable j0 ((i0 + j) - i)
div-11 : {i j : ℕ } → Dividable i ((j + i) - j)
div-11 {i} {j} = record { factor = 1 ; is-factor = begin
1 * i + 0 ≡⟨ +-comm _ 0 ⟩
i + 0 ≡⟨ +-comm _ 0 ⟩
i ≡⟨ sym (minus+y-y {i} {j}) ⟩
(i + j ) - j ≡⟨ cong (λ k → k - j ) (+-comm i j ) ⟩
(j + i) - j ∎ } where open ≡-Reasoning
div→gcd : {n k : ℕ } → k > 1 → Dividable k n → gcd n k ≡ k
div→gcd {n} {k} k>1 = n-induction {_} {_} {ℕ} {λ m → Dividable k m → gcd m k ≡ k } (λ x → x) I n where
decl : {m : ℕ } → 0 < m → m - k < m
decl {m} 0<m = y-x<y (<-trans a<sa k>1 ) 0<m
ind : (m : ℕ ) → (Dividable k (m - k) → gcd (m - k) k ≡ k) → Dividable k m → gcd m k ≡ k
ind m prev d with <-cmp (suc m) k
... | tri≈ ¬a refl ¬c = ⊥-elim ( div+1 k>1 d div= )
... | tri> ¬a ¬b c = subst (λ g → g ≡ k) ind1 ( prev (proj2 (div-div k>1 div= d))) where
ind1 : gcd (m - k) k ≡ gcd m k
ind1 = begin
gcd (m - k) k ≡⟨ sym (gcd+j (m - k) _) ⟩
gcd (m - k + k) k ≡⟨ cong (λ g → gcd g k) (minus+n {m} {k} c) ⟩
gcd m k ∎ where open ≡-Reasoning
... | tri< a ¬b ¬c with <-cmp 0 m
... | tri< a₁ ¬b₁ ¬c₁ = ⊥-elim ( div<k k>1 a₁ (<-trans a<sa a) d )
... | tri≈ ¬a refl ¬c₁ = subst (λ g → g ≡ k ) (gcdsym {k} {0} ) (gcd20 k)
fzero : (m : ℕ) → (m - k) ≡ zero → Dividable k m → gcd m k ≡ k
fzero 0 eq d = trans (gcdsym {0} {k} ) (gcd20 k)
fzero (suc m) eq d with <-cmp (suc m) k
... | tri< a ¬b ¬c = ⊥-elim ( div<k k>1 (s≤s z≤n) a d )
... | tri≈ ¬a refl ¬c = gcdmm k k
... | tri> ¬a ¬b c = ⊥-elim ( nat-≡< (sym eq) (minus>0 c) )
I : Ninduction ℕ _ (λ x → x)
I = record {
pnext = λ p → p - k
; fzero = λ {m} eq → fzero m eq
; decline = λ {m} lt → decl lt
; ind = λ {p} prev → ind p prev
}
GCDi : {i j : ℕ } → GCD i i j j
GCDi {i} {j} = record { i<i0 = refl-≤ ; j<j0 = refl-≤ ; div-i = div-11 {i} {j} ; div-j = div-11 {j} {i} }
GCD-sym : {i i0 j j0 : ℕ} → GCD i i0 j j0 → GCD j j0 i i0
GCD-sym g = record { i<i0 = GCD.j<j0 g ; j<j0 = GCD.i<i0 g ; div-i = GCD.div-j g ; div-j = GCD.div-i g }
pred-≤ : {i i0 : ℕ } → suc i ≤ suc i0 → i ≤ suc i0
pred-≤ {i} {i0} (s≤s lt) = ≤-trans lt refl-≤s
gcd-next : {i i0 j j0 : ℕ} → GCD (suc i) i0 (suc j) j0 → GCD i i0 j j0
gcd-next {i} {0} {j} {0} ()
gcd-next {i} {suc i0} {j} {suc j0} g = record { i<i0 = pred-≤ (GCD.i<i0 g) ; j<j0 = pred-≤ (GCD.j<j0 g)
; div-i = proj1 (di-next {i} {suc i0} {j} {suc j0} ⟪ GCD.div-i g , GCD.div-j g ⟫ )
; div-j = proj2 (di-next {i} {suc i0} {j} {suc j0} ⟪ GCD.div-i g , GCD.div-j g ⟫ ) }
gcd-next1 : {i0 j j0 : ℕ} → GCD 0 (suc i0) (suc (suc j)) j0 → GCD i0 (suc i0) (suc j) (suc (suc j))
gcd-next1 {i0} {j} {j0} g = record { i<i0 = refl-≤s ; j<j0 = refl-≤s
; div-i = proj1 (di-next1 ⟪ GCD.div-i g , GCD.div-j g ⟫ ) ; div-j = proj2 (di-next1 ⟪ GCD.div-i g , GCD.div-j g ⟫ ) }
-- gcd-dividable1 : ( i i0 j j0 : ℕ )
-- → Dividable i0 (j0 + i - j ) ∨ Dividable j0 (i0 + j - i)
-- → Dividable ( gcd1 i i0 j j0 ) i0 ∧ Dividable ( gcd1 i i0 j j0 ) j0
-- gcd-dividable1 zero i0 zero j0 with <-cmp i0 j0
-- ... | tri< a ¬b ¬c = ⟪ div= , {!!} ⟫ -- Dividable i0 (j0 + i - j ) ∧ Dividable j0 (i0 + j - i)
-- ... | tri≈ ¬a refl ¬c = {!!}
-- ... | tri> ¬a ¬b c = {!!}
-- gcd-dividable1 zero i0 (suc zero) j0 = {!!}
-- gcd-dividable1 i i0 j j0 = {!!}
gcd-dividable : ( i j : ℕ )
→ Dividable ( gcd i j ) i ∧ Dividable ( gcd i j ) j
gcd-dividable i j = f-induction {_} {_} {ℕ ∧ ℕ}
{λ p → Dividable ( gcd (proj1 p) (proj2 p) ) (proj1 p) ∧ Dividable ( gcd (proj1 p) (proj2 p) ) (proj2 p)} F I ⟪ i , j ⟫ where
F : ℕ ∧ ℕ → ℕ
F ⟪ 0 , 0 ⟫ = 0
F ⟪ 0 , suc j ⟫ = 0
F ⟪ suc i , 0 ⟫ = 0
F ⟪ suc i , suc j ⟫ with <-cmp i j
... | tri< a ¬b ¬c = suc j
... | tri≈ ¬a b ¬c = 0
... | tri> ¬a ¬b c = suc i
F0 : { i j : ℕ } → F ⟪ i , j ⟫ ≡ 0 → (i ≡ j) ∨ (i ≡ 0 ) ∨ (j ≡ 0)
F0 {zero} {zero} p = case1 refl
F0 {zero} {suc j} p = case2 (case1 refl)
F0 {suc i} {zero} p = case2 (case2 refl)
F0 {suc i} {suc j} p with <-cmp i j
... | tri< a ¬b ¬c = ⊥-elim ( nat-≡< (sym p) (s≤s z≤n ))
... | tri≈ ¬a refl ¬c = case1 refl
... | tri> ¬a ¬b c = ⊥-elim ( nat-≡< (sym p) (s≤s z≤n ))
F00 : {p : ℕ ∧ ℕ} → F p ≡ zero → Dividable (gcd (proj1 p) (proj2 p)) (proj1 p) ∧ Dividable (gcd (proj1 p) (proj2 p)) (proj2 p)
F00 {⟪ i , j ⟫} eq with F0 {i} {j} eq
... | case1 refl = ⟪ subst (λ k → Dividable k i) (sym (gcdmm i i)) div= , subst (λ k → Dividable k i) (sym (gcdmm i i)) div= ⟫
... | case2 (case1 refl) = ⟪ subst (λ k → Dividable k i) (sym (trans (gcdsym {0} {j} ) (gcd20 j)))div0
, subst (λ k → Dividable k j) (sym (trans (gcdsym {0} {j}) (gcd20 j))) div= ⟫
... | case2 (case2 refl) = ⟪ subst (λ k → Dividable k i) (sym (gcd20 i)) div=
, subst (λ k → Dividable k j) (sym (gcd20 i)) div0 ⟫
Fsym : {i j : ℕ } → F ⟪ i , j ⟫ ≡ F ⟪ j , i ⟫
Fsym {0} {0} = refl
Fsym {0} {suc j} = refl
Fsym {suc i} {0} = refl
Fsym {suc i} {suc j} with <-cmp i j | <-cmp j i
... | tri< a ¬b ¬c | tri< a₁ ¬b₁ ¬c₁ = ⊥-elim (nat-<> a a₁)
... | tri< a ¬b ¬c | tri≈ ¬a b ¬c₁ = ⊥-elim (¬b (sym b))
... | tri< a ¬b ¬c | tri> ¬a ¬b₁ c = refl
... | tri≈ ¬a refl ¬c | tri< a ¬b ¬c₁ = ⊥-elim (¬b refl)
... | tri≈ ¬a refl ¬c | tri≈ ¬a₁ refl ¬c₁ = refl
... | tri≈ ¬a refl ¬c | tri> ¬a₁ ¬b c = ⊥-elim (¬b refl)
... | tri> ¬a ¬b c | tri< a ¬b₁ ¬c = refl
... | tri> ¬a ¬b c | tri≈ ¬a₁ b ¬c = ⊥-elim (¬b (sym b))
... | tri> ¬a ¬b c | tri> ¬a₁ ¬b₁ c₁ = ⊥-elim (nat-<> c c₁)
record Fdec ( i j : ℕ ) : Set where
field
ni : ℕ
nj : ℕ
fdec : 0 < F ⟪ i , j ⟫ → F ⟪ ni , nj ⟫ < F ⟪ i , j ⟫
fd1 : ( i j k : ℕ ) → i < j → k ≡ j - i → F ⟪ suc i , k ⟫ < F ⟪ suc i , suc j ⟫
fd1 i j 0 i<j eq = ⊥-elim ( nat-≡< eq (minus>0 {i} {j} i<j ))
fd1 i j (suc k) i<j eq = fd2 i j k i<j eq where
fd2 : ( i j k : ℕ ) → i < j → suc k ≡ j - i → F ⟪ suc i , suc k ⟫ < F ⟪ suc i , suc j ⟫
fd2 i j k i<j eq with <-cmp i k | <-cmp i j
... | tri< a ¬b ¬c | tri< a₁ ¬b₁ ¬c₁ = fd3 where
fd3 : suc k < suc j -- suc j - suc i < suc j
fd3 = subst (λ g → g < suc j) (sym eq) (y-x<y {suc i} {suc j} (s≤s z≤n) (s≤s z≤n))
... | tri< a ¬b ¬c | tri≈ ¬a b ¬c₁ = ⊥-elim (⊥-elim (¬a i<j))
... | tri< a ¬b ¬c | tri> ¬a ¬b₁ c = ⊥-elim (⊥-elim (¬a i<j))
... | tri≈ ¬a b ¬c | tri< a ¬b ¬c₁ = s≤s z≤n
... | tri≈ ¬a b ¬c | tri≈ ¬a₁ b₁ ¬c₁ = ⊥-elim (¬a₁ i<j)
... | tri≈ ¬a b ¬c | tri> ¬a₁ ¬b c = s≤s z≤n -- i > j
... | tri> ¬a ¬b c | tri< a ¬b₁ ¬c = fd4 where
fd4 : suc i < suc j
fd4 = s≤s a
... | tri> ¬a ¬b c | tri≈ ¬a₁ b ¬c = ⊥-elim (¬a₁ i<j)
... | tri> ¬a ¬b c | tri> ¬a₁ ¬b₁ c₁ = ⊥-elim (¬a₁ i<j)
fedc0 : (i j : ℕ ) → Fdec i j
fedc0 0 0 = record { ni = 0 ; nj = 0 ; fdec = λ () }
fedc0 (suc i) 0 = record { ni = suc i ; nj = 0 ; fdec = λ () }
fedc0 0 (suc j) = record { ni = 0 ; nj = suc j ; fdec = λ () }
fedc0 (suc i) (suc j) with <-cmp i j
... | tri< i<j ¬b ¬c = record { ni = suc i ; nj = j - i ; fdec = λ lt → fd1 i j (j - i) i<j refl }
... | tri≈ ¬a refl ¬c = record { ni = suc i ; nj = suc j ; fdec = λ lt → ⊥-elim (nat-≡< fd0 lt) } where
fd0 : {i : ℕ } → 0 ≡ F ⟪ suc i , suc i ⟫
fd0 {i} with <-cmp i i
... | tri< a ¬b ¬c = ⊥-elim ( ¬b refl )
... | tri≈ ¬a b ¬c = refl
... | tri> ¬a ¬b c = ⊥-elim ( ¬b refl )
... | tri> ¬a ¬b c = record { ni = i - j ; nj = suc j ; fdec = λ lt →
subst₂ (λ s t → s < t) (Fsym {suc j} {i - j}) (Fsym {suc j} {suc i}) (fd1 j i (i - j) c refl ) }
ind3 : {i j : ℕ } → i < j
→ Dividable (gcd (suc i) (j - i)) (suc i)
→ Dividable (gcd (suc i) (suc j)) (suc i)
ind3 {i} {j} a prev =
subst (λ k → Dividable k (suc i)) ( begin
gcd (suc i) (j - i) ≡⟨ gcdsym {suc i} {j - i} ⟩
gcd (j - i ) (suc i) ≡⟨ sym (gcd+j (j - i) (suc i)) ⟩
gcd ((j - i) + suc i) (suc i) ≡⟨ cong (λ k → gcd k (suc i)) ( begin
(suc j - suc i) + suc i ≡⟨ minus+n {suc j} {suc i} (<-trans ( s≤s a) a<sa ) ⟩ -- i ≤ n → suc (suc i) ≤ suc (suc (suc n))
suc j ∎ ) ⟩
gcd (suc j) (suc i) ≡⟨ gcdsym {suc j} {suc i} ⟩
gcd (suc i) (suc j) ∎ ) prev where open ≡-Reasoning
ind7 : {i j : ℕ } → (i < j ) → (j - i) + suc i ≡ suc j
ind7 {i} {j} a = begin (suc j - suc i) + suc i ≡⟨ minus+n {suc j} {suc i} (<-trans (s≤s a) a<sa) ⟩
suc j ∎ where open ≡-Reasoning
ind6 : {i j k : ℕ } → i < j
→ Dividable k (j - i)
→ Dividable k (suc i)
→ Dividable k (suc j)
ind6 {i} {j} {k} i<j dj di = subst (λ g → Dividable k g ) (ind7 i<j) (proj1 (div+div dj di))
ind4 : {i j : ℕ } → i < j
→ Dividable (gcd (suc i) (j - i)) (j - i)
→ Dividable (gcd (suc i) (suc j)) (j - i)
ind4 {i} {j} i<j prev = subst (λ k → k) ( begin
Dividable (gcd (suc i) (j - i)) (j - i) ≡⟨ cong (λ k → Dividable k (j - i)) (gcdsym {suc i} ) ⟩
Dividable (gcd (j - i ) (suc i) ) (j - i) ≡⟨ cong (λ k → Dividable k (j - i)) ( sym (gcd+j (j - i) (suc i))) ⟩
Dividable (gcd ((j - i) + suc i) (suc i)) (j - i) ≡⟨ cong (λ k → Dividable (gcd k (suc i)) (j - i)) (ind7 i<j ) ⟩
Dividable (gcd (suc j) (suc i)) (j - i) ≡⟨ cong (λ k → Dividable k (j - i)) (gcdsym {suc j} ) ⟩
Dividable (gcd (suc i) (suc j)) (j - i) ∎ ) prev where open ≡-Reasoning
ind : ( i j : ℕ ) →
Dividable (gcd (Fdec.ni (fedc0 i j)) (Fdec.nj (fedc0 i j))) (Fdec.ni (fedc0 i j))
∧ Dividable (gcd (Fdec.ni (fedc0 i j)) (Fdec.nj (fedc0 i j))) (Fdec.nj (fedc0 i j))
→ Dividable (gcd i j) i ∧ Dividable (gcd i j) j
ind zero zero prev = ind0 where
ind0 : Dividable (gcd zero zero) zero ∧ Dividable (gcd zero zero) zero
ind0 = ⟪ div0 , div0 ⟫
ind zero (suc j) prev = ind1 where
ind1 : Dividable (gcd zero (suc j)) zero ∧ Dividable (gcd zero (suc j)) (suc j)
ind1 = ⟪ div0 , subst (λ k → Dividable k (suc j)) (sym (trans (gcdsym {zero} {suc j}) (gcd20 (suc j)))) div= ⟫
ind (suc i) zero prev = ind2 where
ind2 : Dividable (gcd (suc i) zero) (suc i) ∧ Dividable (gcd (suc i) zero) zero
ind2 = ⟪ subst (λ k → Dividable k (suc i)) (sym (trans refl (gcd20 (suc i)))) div= , div0 ⟫
ind (suc i) (suc j) prev with <-cmp i j
... | tri< a ¬b ¬c = ⟪ ind3 a (proj1 prev) , ind6 a (ind4 a (proj2 prev)) (ind3 a (proj1 prev) ) ⟫
... | tri≈ ¬a refl ¬c = ⟪ ind5 , ind5 ⟫ where
ind5 : Dividable (gcd (suc i) (suc i)) (suc i)
ind5 = subst (λ k → Dividable k (suc j)) (sym (gcdmm (suc i) (suc i))) div=
... | tri> ¬a ¬b c = ⟪ ind8 c (proj1 prev) (proj2 prev) , ind10 c (proj2 prev) ⟫ where
ind9 : {i j : ℕ} → i < j → gcd (j - i) (suc i) ≡ gcd (suc j) (suc i)
ind9 {i} {j} i<j = begin
gcd (j - i ) (suc i) ≡⟨ sym (gcd+j (j - i ) (suc i) ) ⟩
gcd (j - i + suc i) (suc i) ≡⟨ cong (λ k → gcd k (suc i)) (ind7 i<j ) ⟩
gcd (suc j) (suc i) ∎ where open ≡-Reasoning
ind8 : { i j : ℕ } → i < j
→ Dividable (gcd (j - i) (suc i)) (j - i)
→ Dividable (gcd (j - i) (suc i)) (suc i)
→ Dividable (gcd (suc j) (suc i)) (suc j)
ind8 {i} {j} i<j dji di = ind6 i<j (subst (λ k → Dividable k (j - i)) (ind9 i<j) dji) (subst (λ k → Dividable k (suc i)) (ind9 i<j) di)
ind10 : { i j : ℕ } → j < i
→ Dividable (gcd (i - j) (suc j)) (suc j)
→ Dividable (gcd (suc i) (suc j)) (suc j)
ind10 {i} {j} j<i dji = subst (λ g → Dividable g (suc j) ) (begin
gcd (i - j) (suc j) ≡⟨ sym (gcd+j (i - j) (suc j)) ⟩
gcd (i - j + suc j) (suc j) ≡⟨ cong (λ k → gcd k (suc j)) (ind7 j<i ) ⟩
gcd (suc i) (suc j) ∎ ) dji where open ≡-Reasoning
I : Finduction (ℕ ∧ ℕ) _ F
I = record {
fzero = F00
; pnext = λ p → ⟪ Fdec.ni (fedc0 (proj1 p) (proj2 p)) , Fdec.nj (fedc0 (proj1 p) (proj2 p)) ⟫
; decline = λ {p} lt → Fdec.fdec (fedc0 (proj1 p) (proj2 p)) lt
; ind = λ {p} prev → ind (proj1 p ) ( proj2 p ) prev
}
f-div>0 : { k i : ℕ } → (d : Dividable k i ) → 0 < i → 0 < Dividable.factor d
f-div>0 {k} {i} d 0<i with <-cmp 0 (Dividable.factor d)
... | tri< a ¬b ¬c = a
... | tri≈ ¬a b ¬c = ⊥-elim ( nat-≡< (begin
0 * k + 0 ≡⟨ cong (λ g → g * k + 0) b ⟩
Dividable.factor d * k + 0 ≡⟨ Dividable.is-factor d ⟩
i ∎ ) 0<i ) where open ≡-Reasoning
gcd-≤i : ( i j : ℕ ) → 0 < i → i ≤ j → gcd i j ≤ i
gcd-≤i zero _ () z≤n
gcd-≤i (suc i) (suc j) _ (s≤s i<j) = begin
gcd (suc i) (suc j) ≡⟨ sym m*1=m ⟩
gcd (suc i) (suc j) * 1 ≤⟨ *-monoʳ-≤ (gcd (suc i) (suc j)) (f-div>0 d (s≤s z≤n)) ⟩
gcd (suc i) (suc j) * f ≡⟨ +-comm 0 _ ⟩
gcd (suc i) (suc j) * f + 0 ≡⟨ cong (λ k → k + 0) (*-comm (gcd (suc i) (suc j)) _ ) ⟩
Dividable.factor (proj1 (gcd-dividable (suc i) (suc j))) * gcd (suc i) (suc j) + 0 ≡⟨ Dividable.is-factor (proj1 (gcd-dividable (suc i) (suc j))) ⟩
suc i ∎ where
d = proj1 (gcd-dividable (suc i) (suc j))
f = Dividable.factor (proj1 (gcd-dividable (suc i) (suc j)))
open ≤-Reasoning
gcd-≤ : { i j : ℕ } → 0 < i → 0 < j → gcd i j ≤ i
gcd-≤ {i} {j} 0<i 0<j with <-cmp i j
... | tri< a ¬b ¬c = gcd-≤i i j 0<i (<to≤ a)
... | tri≈ ¬a refl ¬c = gcd-≤i i j 0<i refl-≤
... | tri> ¬a ¬b c = ≤-trans (subst (λ k → k ≤ j) (gcdsym {j} {i}) (gcd-≤i j i 0<j (<to≤ c))) (<to≤ c)
record Euclid (i j gcd : ℕ ) : Set where
field
eqa : ℕ
eqb : ℕ
is-equ< : eqa * i > eqb * j → (eqa * i) - (eqb * j) ≡ gcd
is-equ> : eqb * j > eqa * i → (eqb * j) - (eqa * i) ≡ gcd
is-equ= : eqa * i ≡ eqb * j → 0 ≡ gcd
ge3 : {a b c d : ℕ } → b > a → b - a ≡ d - c → d > c
ge3 {a} {b} {c} {d} b>a eq = minus>0→x<y (subst (λ k → 0 < k ) eq (minus>0 b>a))
ge01 : ( i0 j j0 ea eb : ℕ )
→ ( di : GCD 0 (suc i0) (suc (suc j)) j0 )
→ (((ea + eb * (Dividable.factor (GCD.div-i di))) * suc i0) ≡ (ea * suc i0) + (eb * (Dividable.factor (GCD.div-i di)) ) * suc i0 )
∧ ( (eb * j0) ≡ (eb * suc (suc j) + (eb * (Dividable.factor (GCD.div-i di)) ) * suc i0) )
ge01 i0 j j0 ea eb di = ⟪ ge011 , ge012 ⟫ where
f = Dividable.factor (GCD.div-i di)
ge4 : suc (j0 + 0) > suc (suc j)
ge4 = subst (λ k → k > suc (suc j)) (+-comm 0 _ ) ( s≤s (GCD.j<j0 di ))
ge011 : (ea + eb * f) * suc i0 ≡ ea * suc i0 + eb * f * suc i0
ge011 = begin
(ea + eb * f) * suc i0 ≡⟨ *-distribʳ-+ (suc i0) ea _ ⟩
ea * suc i0 + eb * f * suc i0 ∎ where open ≡-Reasoning
ge012 : eb * j0 ≡ eb * suc (suc j) + eb * f * suc i0
ge012 = begin
eb * j0 ≡⟨ cong (λ k → eb * k) ( begin
j0 ≡⟨ +-comm 0 _ ⟩
j0 + 0 ≡⟨ sym (minus+n {j0 + 0} {suc (suc j)} ge4) ⟩
((j0 + 0) - (suc (suc j))) + suc (suc j) ≡⟨ +-comm _ (suc (suc j)) ⟩
suc (suc j) + ((j0 + 0) - suc (suc j)) ≡⟨ cong (λ k → suc (suc j) + k ) (sym (Dividable.is-factor (GCD.div-i di))) ⟩
suc (suc j) + (f * suc i0 + 0) ≡⟨ cong (λ k → suc (suc j) + k ) ( +-comm _ 0 ) ⟩
suc (suc j) + (f * suc i0 ) ∎ ) ⟩
eb * (suc (suc j) + (f * suc i0 ) ) ≡⟨ *-distribˡ-+ eb (suc (suc j)) (f * suc i0) ⟩
eb * suc (suc j) + eb * (f * suc i0) ≡⟨ cong (λ k → eb * suc (suc j) + k ) ((sym (*-assoc eb _ _ )) ) ⟩
eb * suc (suc j) + eb * f * suc i0 ∎ where open ≡-Reasoning
ge20 : {i0 j0 : ℕ } → i0 ≡ 0 → 0 ≡ gcd1 zero i0 zero j0
ge20 {i0} {zero} refl = refl
ge20 {i0} {suc j0} refl = refl
gcd-euclid1 : ( i i0 j j0 : ℕ ) → GCD i i0 j j0 → Euclid i0 j0 (gcd1 i i0 j j0)
gcd-euclid1 zero i0 zero j0 di with <-cmp i0 j0
... | tri< a' ¬b ¬c = record { eqa = 1 ; eqb = 0 ; is-equ< = λ _ → +-comm _ 0 ; is-equ> = λ () ; is-equ= = ge21 } where
ge21 : 1 * i0 ≡ 0 * j0 → 0 ≡ i0
ge21 eq = trans (sym eq) (+-comm i0 0)
... | tri≈ ¬a refl ¬c = record { eqa = 1 ; eqb = 0 ; is-equ< = λ _ → +-comm _ 0 ; is-equ> = λ () ; is-equ= = λ eq → trans (sym eq) (+-comm i0 0) }
... | tri> ¬a ¬b c = record { eqa = 0 ; eqb = 1 ; is-equ< = λ () ; is-equ> = λ _ → +-comm _ 0 ; is-equ= = ge22 } where
ge22 : 0 * i0 ≡ 1 * j0 → 0 ≡ j0
ge22 eq = trans eq (+-comm j0 0)
-- i<i0 : zero ≤ i0
-- j<j0 : 1 ≤ j0
-- div-i : Dividable i0 ((j0 + zero) - 1) -- fi * i0 ≡ (j0 + zero) - 1
-- div-j : Dividable j0 ((i0 + 1) - zero) -- fj * j0 ≡ (i0 + 1) - zero
gcd-euclid1 zero i0 (suc zero) j0 di = record { eqa = 1 ; eqb = Dividable.factor (GCD.div-j di) ; is-equ< = λ lt → ⊥-elim ( ge7 lt) ; is-equ> = λ _ → ge6
; is-equ= = λ eq → ⊥-elim (nat-≡< (sym (minus<=0 (subst (λ k → k ≤ 1 * i0) eq refl-≤ ))) (subst (λ k → 0 < k) (sym ge6) a<sa )) } where
ge6 : (Dividable.factor (GCD.div-j di) * j0) - (1 * i0) ≡ gcd1 zero i0 1 j0
ge6 = begin
(Dividable.factor (GCD.div-j di) * j0) - (1 * i0) ≡⟨ cong (λ k → k - (1 * i0)) (+-comm 0 _) ⟩
(Dividable.factor (GCD.div-j di) * j0 + 0) - (1 * i0) ≡⟨ cong (λ k → k - (1 * i0)) (Dividable.is-factor (GCD.div-j di) ) ⟩
((i0 + 1) - zero) - (1 * i0) ≡⟨ refl ⟩
(i0 + 1) - (i0 + 0) ≡⟨ minus+yx-yz {_} {i0} {0} ⟩
1 ∎ where open ≡-Reasoning
ge7 : ¬ ( 1 * i0 > Dividable.factor (GCD.div-j di) * j0 )
ge7 lt = ⊥-elim ( nat-≡< (sym ( minus<=0 (<to≤ lt))) (subst (λ k → 0 < k) (sym ge6) (s≤s z≤n)))
gcd-euclid1 zero zero (suc (suc j)) j0 di = record { eqa = 0 ; eqb = 1 ; is-equ< = λ () ; is-equ> = λ _ → +-comm _ 0
; is-equ= = λ eq → subst (λ k → 0 ≡ k) (+-comm _ 0) eq }
gcd-euclid1 zero (suc i0) (suc (suc j)) j0 di with gcd-euclid1 i0 (suc i0) (suc j) (suc (suc j)) ( gcd-next1 di )
... | e = record { eqa = ea + eb * f ; eqb = eb
; is-equ= = λ eq → Euclid.is-equ= e (ge23 eq)
; is-equ< = λ lt → subst (λ k → ((ea + eb * f) * suc i0) - (eb * j0) ≡ k ) (Euclid.is-equ< e (ge3 lt (ge1 ))) (ge1 )
; is-equ> = λ lt → subst (λ k → (eb * j0) - ((ea + eb * f) * suc i0) ≡ k ) (Euclid.is-equ> e (ge3 lt (ge2 ))) (ge2 ) } where
ea = Euclid.eqa e
eb = Euclid.eqb e
f = Dividable.factor (GCD.div-i di)
ge1 : ((ea + eb * f) * suc i0) - (eb * j0) ≡ (ea * suc i0) - (eb * suc (suc j))
ge1 = begin
((ea + eb * f) * suc i0) - (eb * j0) ≡⟨ cong₂ (λ j k → j - k ) (proj1 (ge01 i0 j j0 ea eb di)) (proj2 (ge01 i0 j j0 ea eb di)) ⟩
(ea * suc i0 + (eb * f ) * suc i0 ) - ( eb * suc (suc j) + ((eb * f) * (suc i0)) ) ≡⟨ minus+xy-zy {ea * suc i0} {(eb * f ) * suc i0} {eb * suc (suc j)} ⟩
(ea * suc i0) - (eb * suc (suc j)) ∎ where open ≡-Reasoning
ge2 : (eb * j0) - ((ea + eb * f) * suc i0) ≡ (eb * suc (suc j)) - (ea * suc i0)
ge2 = begin
(eb * j0) - ((ea + eb * f) * suc i0) ≡⟨ cong₂ (λ j k → j - k ) (proj2 (ge01 i0 j j0 ea eb di)) (proj1 (ge01 i0 j j0 ea eb di)) ⟩
( eb * suc (suc j) + ((eb * f) * (suc i0)) ) - (ea * suc i0 + (eb * f ) * suc i0 ) ≡⟨ minus+xy-zy {eb * suc (suc j)}{(eb * f ) * suc i0} {ea * suc i0} ⟩
(eb * suc (suc j)) - (ea * suc i0) ∎ where open ≡-Reasoning
ge23 : (ea + eb * f) * suc i0 ≡ eb * j0 → ea * suc i0 ≡ eb * suc (suc j)
ge23 eq = begin
ea * suc i0 ≡⟨ sym (minus+y-y {_} {(eb * f ) * suc i0} ) ⟩
(ea * suc i0 + ((eb * f ) * suc i0 )) - ((eb * f ) * suc i0 ) ≡⟨ cong (λ k → k - ((eb * f ) * suc i0 )) (sym ( proj1 (ge01 i0 j j0 ea eb di))) ⟩
((ea + eb * f) * suc i0) - ((eb * f ) * suc i0 ) ≡⟨ cong (λ k → k - ((eb * f ) * suc i0 )) eq ⟩
(eb * j0) - ((eb * f ) * suc i0 ) ≡⟨ cong (λ k → k - ((eb * f ) * suc i0 )) ( proj2 (ge01 i0 j j0 ea eb di)) ⟩
(eb * suc (suc j) + ((eb * f ) * suc i0 )) - ((eb * f ) * suc i0 ) ≡⟨ minus+y-y {_} {(eb * f ) * suc i0 } ⟩
eb * suc (suc j) ∎ where open ≡-Reasoning
gcd-euclid1 (suc zero) i0 zero j0 di = record { eqb = 1 ; eqa = Dividable.factor (GCD.div-i di) ; is-equ> = λ lt → ⊥-elim ( ge7' lt) ; is-equ< = λ _ → ge6'
; is-equ= = λ eq → ⊥-elim (nat-≡< (sym (minus<=0 (subst (λ k → k ≤ 1 * j0) (sym eq) refl-≤ ))) (subst (λ k → 0 < k) (sym ge6') a<sa )) } where
ge6' : (Dividable.factor (GCD.div-i di) * i0) - (1 * j0) ≡ gcd1 (suc zero) i0 zero j0
ge6' = begin
(Dividable.factor (GCD.div-i di) * i0) - (1 * j0) ≡⟨ cong (λ k → k - (1 * j0)) (+-comm 0 _) ⟩
(Dividable.factor (GCD.div-i di) * i0 + 0) - (1 * j0) ≡⟨ cong (λ k → k - (1 * j0)) (Dividable.is-factor (GCD.div-i di) ) ⟩
((j0 + 1) - zero) - (1 * j0) ≡⟨ refl ⟩
(j0 + 1) - (j0 + 0) ≡⟨ minus+yx-yz {_} {j0} {0} ⟩
1 ∎ where open ≡-Reasoning
ge7' : ¬ ( 1 * j0 > Dividable.factor (GCD.div-i di) * i0 )
ge7' lt = ⊥-elim ( nat-≡< (sym ( minus<=0 (<to≤ lt))) (subst (λ k → 0 < k) (sym ge6') (s≤s z≤n)))
gcd-euclid1 (suc (suc i)) i0 zero zero di = record { eqb = 0 ; eqa = 1 ; is-equ> = λ () ; is-equ< = λ _ → +-comm _ 0
; is-equ= = λ eq → subst (λ k → 0 ≡ k) (+-comm _ 0) (sym eq) }
gcd-euclid1 (suc (suc i)) i0 zero (suc j0) di with gcd-euclid1 (suc i) (suc (suc i)) j0 (suc j0) (GCD-sym (gcd-next1 (GCD-sym di)))
... | e = record { eqa = ea ; eqb = eb + ea * f
; is-equ= = λ eq → Euclid.is-equ= e (ge24 eq)
; is-equ< = λ lt → subst (λ k → ((ea * i0) - ((eb + ea * f) * suc j0)) ≡ k ) (Euclid.is-equ< e (ge3 lt ge4)) ge4
; is-equ> = λ lt → subst (λ k → (((eb + ea * f) * suc j0) - (ea * i0)) ≡ k ) (Euclid.is-equ> e (ge3 lt ge5)) ge5 } where
ea = Euclid.eqa e
eb = Euclid.eqb e
f = Dividable.factor (GCD.div-j di)
ge5 : (((eb + ea * f) * suc j0) - (ea * i0)) ≡ ((eb * suc j0) - (ea * suc (suc i)))
ge5 = begin
((eb + ea * f) * suc j0) - (ea * i0) ≡⟨ cong₂ (λ j k → j - k ) (proj1 (ge01 j0 i i0 eb ea (GCD-sym di) )) (proj2 (ge01 j0 i i0 eb ea (GCD-sym di) )) ⟩
( eb * suc j0 + (ea * f )* suc j0) - (ea * suc (suc i) + (ea * f )* suc j0) ≡⟨ minus+xy-zy {_} {(ea * f )* suc j0} {ea * suc (suc i)} ⟩
(eb * suc j0) - (ea * suc (suc i)) ∎ where open ≡-Reasoning
ge4 : ((ea * i0) - ((eb + ea * f) * suc j0)) ≡ ((ea * suc (suc i)) - (eb * suc j0))
ge4 = begin
(ea * i0) - ((eb + ea * f) * suc j0) ≡⟨ cong₂ (λ j k → j - k ) (proj2 (ge01 j0 i i0 eb ea (GCD-sym di) )) (proj1 (ge01 j0 i i0 eb ea (GCD-sym di) )) ⟩
(ea * suc (suc i) + (ea * f )* suc j0) - ( eb * suc j0 + (ea * f )* suc j0) ≡⟨ minus+xy-zy {ea * suc (suc i)} {(ea * f )* suc j0} { eb * suc j0} ⟩
(ea * suc (suc i)) - (eb * suc j0) ∎ where open ≡-Reasoning
ge24 : ea * i0 ≡ (eb + ea * f) * suc j0 → ea * suc (suc i) ≡ eb * suc j0
ge24 eq = begin
ea * suc (suc i) ≡⟨ sym ( minus+y-y {_} {(ea * f ) * suc j0 }) ⟩
(ea * suc (suc i) + (ea * f ) * suc j0 ) - ((ea * f ) * suc j0) ≡⟨ cong (λ k → k - ((ea * f ) * suc j0 )) (sym (proj2 (ge01 j0 i i0 eb ea (GCD-sym di) ))) ⟩
(ea * i0) - ((ea * f ) * suc j0) ≡⟨ cong (λ k → k - ((ea * f ) * suc j0 )) eq ⟩
((eb + ea * f) * suc j0) - ((ea * f ) * suc j0) ≡⟨ cong (λ k → k - ((ea * f ) * suc j0 )) ((proj1 (ge01 j0 i i0 eb ea (GCD-sym di)))) ⟩
( eb * suc j0 + (ea * f ) * suc j0 ) - ((ea * f ) * suc j0) ≡⟨ minus+y-y {_} {(ea * f ) * suc j0 } ⟩
eb * suc j0 ∎ where open ≡-Reasoning
gcd-euclid1 (suc zero) i0 (suc j) j0 di =
gcd-euclid1 zero i0 j j0 (gcd-next di)
gcd-euclid1 (suc (suc i)) i0 (suc j) j0 di =
gcd-euclid1 (suc i) i0 j j0 (gcd-next di)
ge12 : (p x : ℕ) → 0 < x → 1 < p → ((i : ℕ ) → i < p → 0 < i → gcd p i ≡ 1) → ( gcd p x ≡ 1 ) ∨ ( Dividable p x )
ge12 p x 0<x 1<p prime with decD {p} {x} 1<p
... | yes y = case2 y
... | no nx with <-cmp (gcd p x ) 1
... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (s≤s (gcd>0 p x (<-trans a<sa 1<p) 0<x) ) )
... | tri≈ ¬a b ¬c = case1 b
... | tri> ¬a ¬b c = ⊥-elim ( nat-≡< (sym (prime (gcd p x) ge13 (<to≤ c) )) ge18 ) where
-- 1 < gcd p x
ge13 : gcd p x < p -- gcd p x ≡ p → ¬ nx
ge13 with <-cmp (gcd p x ) p
... | tri< a ¬b ¬c = a
... | tri≈ ¬a b ¬c = ⊥-elim ( nx (subst (λ k → Dividable k x) b (proj2 (gcd-dividable p x ))))
... | tri> ¬a ¬b c = ⊥-elim ( nat-≤> (gcd-≤ (<-trans a<sa 1<p) 0<x) c )
ge19 : Dividable (gcd p x) p
ge19 = proj1 (gcd-dividable p x )
ge18 : 1 < gcd p (gcd p x) -- Dividable p (gcd p x) → gcd p (gcd p x) ≡ (gcd p x) > 1
ge18 = subst (λ k → 1 < k ) (sym (div→gcd {p} {gcd p x} c ge19 )) c
gcd-euclid : ( p a b : ℕ ) → 1 < p → 0 < a → 0 < b → ((i : ℕ ) → i < p → 0 < i → gcd p i ≡ 1) → Dividable p (a * b) → Dividable p a ∨ Dividable p b
gcd-euclid p a b 1<p 0<a 0<b prime div-ab with decD {p} {a} 1<p
... | yes y = case1 y
... | no np = case2 ge16 where
f = Dividable.factor div-ab
ge10 : gcd p a ≡ 1
ge10 with ge12 p a 0<a 1<p prime
... | case1 x = x
... | case2 x = ⊥-elim ( np x )
ge11 : Euclid p a (gcd p a)
ge11 = gcd-euclid1 p p a a GCDi
ea = Euclid.eqa ge11
eb = Euclid.eqb ge11
ge18 : (f * eb) * p ≡ b * (a * eb )
ge18 = begin
(f * eb) * p ≡⟨ *-assoc (f) (eb) p ⟩
f * (eb * p) ≡⟨ cong (λ k → f * k) (*-comm _ p) ⟩
f * (p * eb ) ≡⟨ sym (*-assoc (f) p (eb) ) ⟩
(f * p ) * eb ≡⟨ cong (λ k → k * eb ) (+-comm 0 (f * p )) ⟩
(f * p + 0) * eb ≡⟨ cong (λ k → k * eb) (((Dividable.is-factor div-ab))) ⟩
(a * b) * eb ≡⟨ cong (λ k → k * eb) (*-comm a b) ⟩
(b * a) * eb ≡⟨ *-assoc b a (eb ) ⟩
b * (a * eb ) ∎ where open ≡-Reasoning
ge19 : ( ea * p ) ≡ ( eb * a ) → ((b * ea) - (f * eb)) * p + 0 ≡ b
ge19 eq = ⊥-elim ( nat-≡< (Euclid.is-equ= ge11 eq) (subst (λ k → 0 < k ) (sym ge10) a<sa ) )
ge14 : ( ea * p ) > ( eb * a ) → ((b * ea) - (f * eb)) * p + 0 ≡ b
ge14 lt = begin
(((b * ea) - (f * eb)) * p) + 0 ≡⟨ +-comm _ 0 ⟩
((b * ea) - ((f * eb)) * p) ≡⟨ distr-minus-* {_} {f * eb} {p} ⟩
((b * ea) * p) - (((f * eb) * p)) ≡⟨ cong (λ k → ((b * ea) * p) - k ) ge18 ⟩
((b * ea) * p) - (b * (a * eb )) ≡⟨ cong (λ k → k - (b * (a * eb)) ) (*-assoc b _ p) ⟩
(b * (ea * p)) - (b * (a * eb )) ≡⟨ sym ( distr-minus-*' {b} {ea * p} {a * eb} ) ⟩
b * (( ea * p) - (a * eb) ) ≡⟨ cong (λ k → b * ( ( ea * p) - k)) (*-comm a (eb)) ⟩
(b * ( (ea * p)) - (eb * a) ) ≡⟨ cong (b *_) (Euclid.is-equ< ge11 lt )⟩
b * gcd p a ≡⟨ cong (b *_) ge10 ⟩
b * 1 ≡⟨ m*1=m ⟩
b ∎ where open ≡-Reasoning
ge15 : ( ea * p ) < ( eb * a ) → ((f * eb) - (b * ea ) ) * p + 0 ≡ b
ge15 lt = begin
((f * eb) - (b * ea) ) * p + 0 ≡⟨ +-comm _ 0 ⟩
((f * eb) - (b * ea) ) * p ≡⟨ distr-minus-* {_} {b * ea} {p} ⟩
((f * eb) * p) - ((b * ea) * p) ≡⟨ cong (λ k → k - ((b * ea) * p) ) ge18 ⟩
(b * (a * eb )) - ((b * ea) * p ) ≡⟨ cong (λ k → (b * (a * eb)) - k ) (*-assoc b _ p) ⟩
(b * (a * eb )) - (b * (ea * p) ) ≡⟨ sym ( distr-minus-*' {b} {a * eb} {ea * p} ) ⟩
b * ( (a * eb) - (ea * p) ) ≡⟨ cong (λ k → b * ( k - ( ea * p) )) (*-comm a (eb)) ⟩
b * ( (eb * a) - (ea * p) ) ≡⟨ cong (b *_) (Euclid.is-equ> ge11 lt) ⟩
b * gcd p a ≡⟨ cong (b *_) ge10 ⟩
b * 1 ≡⟨ m*1=m ⟩
b ∎ where open ≡-Reasoning
ge17 : (x y : ℕ ) → x ≡ y → x ≤ y
ge17 x x refl = refl-≤
ge16 : Dividable p b
ge16 with <-cmp ( ea * p ) ( eb * a )
... | tri< a ¬b ¬c = record { factor = (f * eb) - (b * ea) ; is-factor = ge15 a }
... | tri≈ ¬a eq ¬c = record { factor = (b * ea) - ( f * eb) ; is-factor = ge19 eq }
... | tri> ¬a ¬b c = record { factor = (b * ea) - (f * eb) ; is-factor = ge14 c }
gcdmul+1 : ( m n : ℕ ) → gcd (m * n + 1) n ≡ 1
gcdmul+1 zero n = gcd204 n
gcdmul+1 (suc m) n = begin
gcd (suc m * n + 1) n ≡⟨⟩
gcd (n + m * n + 1) n ≡⟨ cong (λ k → gcd k n ) (begin
n + m * n + 1 ≡⟨ cong (λ k → k + 1) (+-comm n _) ⟩
m * n + n + 1 ≡⟨ +-assoc (m * n) _ _ ⟩
m * n + (n + 1) ≡⟨ cong (λ k → m * n + k) (+-comm n _) ⟩
m * n + (1 + n) ≡⟨ sym ( +-assoc (m * n) _ _ ) ⟩
m * n + 1 + n ∎
) ⟩
gcd (m * n + 1 + n) n ≡⟨ gcd+j (m * n + 1) n ⟩
gcd (m * n + 1) n ≡⟨ gcdmul+1 m n ⟩
1 ∎ where open ≡-Reasoning
m*n=m→n : {m n : ℕ } → 0 < m → m * n ≡ m * 1 → n ≡ 1
m*n=m→n {suc m} {n} (s≤s lt) eq = *-cancelˡ-≡ m eq
|
{
"alphanum_fraction": 0.4469372322,
"avg_line_length": 56.7525035765,
"ext": "agda",
"hexsha": "6d0919825d4923f005613119e17436c6c8df4e91",
"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/gcd.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/gcd.agda",
"max_line_length": 165,
"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/gcd.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 18378,
"size": 39670
}
|
module Dave.Algebra.Naturals.Exponentiation where
open import Dave.Algebra.Naturals.Definition
open import Dave.Algebra.Naturals.Multiplication
open import Dave.Algebra.Naturals.Addition
_^_ : ℕ → ℕ → ℕ
a ^ zero = 1
a ^ suc b = (a ^ b) * a
infixl 8 _^_
^-distribₗ : ∀ (m n p : ℕ) → m ^ (n + p) ≡ (m ^ n) * (m ^ p)
^-distribₗ m zero p = refl
^-distribₗ m (suc n) p = begin
m ^ (suc n + p) ≡⟨⟩
m ^ suc (n + p) ≡⟨⟩
(m ^ (n + p)) * m ≡⟨ cong (λ a → a * m) (^-distribₗ m n p) ⟩
(m ^ n) * (m ^ p) * m ≡⟨ IsCommutativeMonoid.swap021 ℕ-*-IsCommutativeMonoid (m ^ n) (m ^ p) m ⟩
(m ^ n) * m * (m ^ p) ≡⟨⟩
(m ^ n) * (m ^ 1) * (m ^ p) ≡⟨ cong (λ a → a * (m ^ p)) (sym (^-distribₗ m n 1)) ⟩
(m ^ (n + 1)) * (m ^ p) ≡⟨ cong (λ a → (m ^ a) * (m ^ p)) (+-add1ᵣ n) ⟩
(m ^ suc n) * (m ^ p) ∎
^-distribᵣ : ∀ (m n p : ℕ) → (m * n) ^ p ≡ (m ^ p) * (n ^ p)
^-distribᵣ m n zero = refl
^-distribᵣ m n (suc p) = begin
(m * n) ^ suc p ≡⟨⟩
((m * n) ^ p) * (m * n) ≡⟨ cong (λ a → a * (m * n)) (^-distribᵣ m n p) ⟩
(m ^ p) * (n ^ p) * (m * n) ≡⟨ sym (IsSemigroup.assoc ℕ-*-IsSemigroup ((m ^ p) * (n ^ p)) m n) ⟩
(m ^ p) * (n ^ p) * m * n ≡⟨ cong (λ a → a * n) (IsCommutativeMonoid.swap021 ℕ-*-IsCommutativeMonoid (m ^ p) (n ^ p) m) ⟩
(m ^ p) * m * (n ^ p) * n ≡⟨ IsSemigroup.assoc ℕ-*-IsSemigroup ((m ^ p) * m) (n ^ p) n ⟩
(m ^ p) * m * ((n ^ p) * n) ≡⟨⟩
(m ^ p) * (m ^ 1) * ((n ^ p) * (n ^ 1)) ≡⟨ cong (λ a → a * ((n ^ p) * (n ^ 1))) (sym (^-distribₗ m p 1)) ⟩
(m ^ (p + 1)) * ((n ^ p) * (n ^ 1)) ≡⟨ cong (λ a → (m ^ a) * ((n ^ p) * (n ^ 1))) (+-add1ᵣ p) ⟩
(m ^ suc p) * ((n ^ p) * (n ^ 1)) ≡⟨ cong (λ a → (m ^ suc p) * a) (sym (^-distribₗ n p 1)) ⟩
(m ^ suc p) * (n ^ (p + 1)) ≡⟨ cong (λ a → (m ^ suc p) * (n ^ a)) (+-add1ᵣ p) ⟩
(m ^ suc p) * (n ^ suc p) ∎
^-*-assoc : ∀ (m n p : ℕ) → (m ^ n) ^ p ≡ m ^ (n * p)
^-*-assoc m n zero = sym (begin
m ^ (n * zero) ≡⟨ cong (λ a → m ^ a) (*-zero n) ⟩
1 ∎)
^-*-assoc m n (suc p) = begin
(m ^ n) ^ suc p ≡⟨⟩
(m ^ n) ^ p * (m ^ n) ≡⟨ cong (λ a → a * (m ^ n)) (^-*-assoc m n p) ⟩
m ^ (n * p) * (m ^ n) ≡⟨ sym (^-distribₗ m (n * p) n) ⟩
m ^ (n * p + n) ≡⟨ cong (λ a → m ^ a ) (sym (*-distrib1ᵣ-+ₗ n p)) ⟩
m ^ (n * (p + 1)) ≡⟨ cong (λ a → m ^ (n * a)) (+-add1ᵣ p) ⟩
m ^ (n * suc p) ∎
|
{
"alphanum_fraction": 0.3992363174,
"avg_line_length": 48.1020408163,
"ext": "agda",
"hexsha": "d7eadb1cd7c971af523b38211a8cc6ec700a3df2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DavidStahl97/formal-proofs",
"max_forks_repo_path": "Dave/Algebra/Naturals/Exponentiation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DavidStahl97/formal-proofs",
"max_issues_repo_path": "Dave/Algebra/Naturals/Exponentiation.agda",
"max_line_length": 126,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DavidStahl97/formal-proofs",
"max_stars_repo_path": "Dave/Algebra/Naturals/Exponentiation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1246,
"size": 2357
}
|
------------------------------------------------------------------------------
-- Lists of natural numbers
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Nat.List where
open import FOTC.Base
-- The FOTC lists of natural numbers type (inductive predicate for
-- total lists of natural numbers).
open import FOTC.Data.Nat.List.Type public
|
{
"alphanum_fraction": 0.4608540925,
"avg_line_length": 33.0588235294,
"ext": "agda",
"hexsha": "bc3daf07d730f44a61c9b048763125a293b65d1e",
"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/Data/Nat/List.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/Data/Nat/List.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/Data/Nat/List.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": 94,
"size": 562
}
|
open import Agda.Builtin.IO
open import Agda.Builtin.Unit
open import Agda.Builtin.Nat
data Unit : Set where
c : ⊤ → Nat → ⊤ → Unit
-- Note that the ⊤ arguments get erased and shouldn't be present in
-- the Haskell version of Unit.
{-# FOREIGN GHC data Unit = Unit Integer #-}
{-# COMPILE GHC Unit = data Unit (Unit) #-}
postulate print : Nat → IO ⊤
{-# COMPILE GHC print = print #-}
{-# COMPILE JS print = function (x) { return function(cb) { process.stdout.write(x + "\n"); cb(0) } } #-}
foo : Unit → IO ⊤
foo (c _ n _) = print n
main : IO ⊤
main = foo (c _ 12345 _)
|
{
"alphanum_fraction": 0.6384083045,
"avg_line_length": 25.1304347826,
"ext": "agda",
"hexsha": "0aff73a92646d97f720531a0758048a30249628e",
"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/Compiler/simple/Issue2921.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/Compiler/simple/Issue2921.agda",
"max_line_length": 106,
"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/Compiler/simple/Issue2921.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": 174,
"size": 578
}
|
-- Andreas, 2018-06-12, issue #2170
-- Reported by tomjack
{-# OPTIONS --irrelevant-projections --subtyping #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Bool
infixr 42 _,_
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
fst : A
snd : B fst
open Σ
record Irr (A : Set) : Set where
constructor irr
field
.unirr : A
open Irr
-- Usually, unirr (irr a) = .(a) which is DontCare a in internal syntax.
-- The DontCare protection of an irrelevant field could be circumvented
-- using subtyping irr : (.Bool → Irr Bool) ≤ (Bool → Irr Bool):
-- The argument a in (i a) would not have ArgInfo Irrelevant, even
-- after substitution irr/i. Since the DontCare came from the ArgInfo of a,
-- there was none. Now, the record constructor name also carries ArgInfo for
-- each of its fields, which is used to produce a DontCare.
bizarre : Irr (Σ (Bool → Irr Bool) (λ i → Σ (Irr Bool → Bool) (λ u → (a : Bool) → u (i a) ≡ a)))
bizarre = irr (irr , unirr , λ a → refl) -- Should not pass
-- Expected error:
-- .(a) != a of type Bool
-- when checking that the expression refl has type .(a) ≡ a
-- The rest is proving False.
data ⊥ : Set where
¬_ : Set → Set
¬ A = (A → ⊥)
true≠false : ¬ (true ≡ false)
true≠false ()
infixr 30 _∙_
_∙_ : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
refl ∙ q = q
infix 42 !_
!_ : {A : Set} {x y : A} → x ≡ y → y ≡ x
! refl = refl
map-irr : {A B : Set} → (A → B) → Irr A → Irr B
map-irr f (irr x) = irr (f x)
factivity : ¬ (Irr ⊥)
factivity (irr ())
bad : Irr (true ≡ false)
bad = map-irr (λ { (i , u , s) → ! (s true) ∙ s false }) bizarre
boom : ⊥
boom = factivity (map-irr true≠false bad)
-- the hole here is is .(a) ≡ a
-- bizarre' : Irr (Σ (Irr Bool → Bool) (λ u → (a : Bool) → u (irr a) ≡ a))
-- bizarre' = irr (unirr , (λ a → {!!}))
-- also fails, unirr (irr a) = .(a)
-- bizarre' : Irr (Σ (Bool → Irr Bool) (λ i → Σ (Irr Bool → Bool) (λ u → (a : Bool) → u (i a) ≡ a)))
-- bizarre' = irr (irr , unirr , (λ a → refl {x = unirr (irr a)})
|
{
"alphanum_fraction": 0.5886385896,
"avg_line_length": 26.8684210526,
"ext": "agda",
"hexsha": "1b388f3455c9b2fa23f8795c858cae1c58c0f8fa",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-18T13:34:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-18T13:34:07.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue2170-subtyping.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2015-09-15T15:49:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-09-15T15:49:15.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue2170-subtyping.agda",
"max_line_length": 100,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2170-subtyping.agda",
"max_stars_repo_stars_event_max_datetime": "2016-05-20T13:58:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-05-20T13:58:52.000Z",
"num_tokens": 770,
"size": 2042
}
|
module Issue73 where
record ImplicitField (a : Set) : Set where
field
aField : a
{anImplicitField} : a
open ImplicitField public
{-# COMPILE AGDA2HS ImplicitField class #-}
|
{
"alphanum_fraction": 0.6804123711,
"avg_line_length": 21.5555555556,
"ext": "agda",
"hexsha": "cc2139e5ae38f66c4457a5b6469fc1c5e17c87f8",
"lang": "Agda",
"max_forks_count": 18,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z",
"max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "seanpm2001/agda2hs",
"max_forks_repo_path": "test/Issue73.agda",
"max_issues_count": 63,
"max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "seanpm2001/agda2hs",
"max_issues_repo_path": "test/Issue73.agda",
"max_line_length": 43,
"max_stars_count": 55,
"max_stars_repo_head_hexsha": "703c66db29023f5538eaa841f38dc34e89473a3e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jespercockx/agda2hs",
"max_stars_repo_path": "test/Issue73.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z",
"num_tokens": 51,
"size": 194
}
|
module nfa136 where
open import logic
open import nfa
open import automaton
open import Data.List
open import finiteSet
open import Data.Fin
open import Relation.Binary.PropositionalEquality hiding ( [_] )
data StatesQ : Set where
q1 : StatesQ
q2 : StatesQ
q3 : StatesQ
data A2 : Set where
a0 : A2
b0 : A2
finStateQ : FiniteSet StatesQ
finStateQ = record {
Q←F = Q←F
; F←Q = F←Q
; finiso→ = finiso→
; finiso← = finiso←
} where
Q←F : Fin 3 → StatesQ
Q←F zero = q1
Q←F (suc zero) = q2
Q←F (suc (suc zero)) = q3
F←Q : StatesQ → Fin 3
F←Q q1 = zero
F←Q q2 = suc zero
F←Q q3 = suc (suc zero)
finiso→ : (q : StatesQ) → Q←F (F←Q q) ≡ q
finiso→ q1 = refl
finiso→ q2 = refl
finiso→ q3 = refl
finiso← : (f : Fin 3) → F←Q (Q←F f) ≡ f
finiso← zero = refl
finiso← (suc zero) = refl
finiso← (suc (suc zero)) = refl
finiso← (suc (suc (suc ())))
transition136 : StatesQ → A2 → StatesQ → Bool
transition136 q1 b0 q2 = true
transition136 q1 a0 q1 = true -- q1 → ep → q3
transition136 q2 a0 q2 = true
transition136 q2 a0 q3 = true
transition136 q2 b0 q3 = true
transition136 q3 a0 q1 = true
transition136 _ _ _ = false
end136 : StatesQ → Bool
end136 q1 = true
end136 _ = false
start136 : StatesQ → Bool
start136 q1 = true
start136 _ = false
exists136 : (StatesQ → Bool) → Bool
exists136 f = f q1 \/ f q2 \/ f q3
to-list-136 : (StatesQ → Bool) → List StatesQ
to-list-136 f = tl1 where
tl3 : List StatesQ
tl3 with f q3
... | true = q3 ∷ []
... | false = []
tl2 : List StatesQ
tl2 with f q2
... | true = q2 ∷ tl3
... | false = tl3
tl1 : List StatesQ
tl1 with f q1
... | true = q1 ∷ tl2
... | false = tl2
nfa136 : NAutomaton StatesQ A2
nfa136 = record { Nδ = transition136; Nend = end136 }
example136-1 = Naccept nfa136 exists136 start136( a0 ∷ b0 ∷ a0 ∷ a0 ∷ [] )
t146-1 = Ntrace nfa136 exists136 to-list-136 start136( a0 ∷ b0 ∷ a0 ∷ a0 ∷ [] )
example136-0 = Naccept nfa136 exists136 start136( a0 ∷ [] )
example136-2 = Naccept nfa136 exists136 start136( b0 ∷ a0 ∷ b0 ∷ a0 ∷ b0 ∷ [] )
t146-2 = Ntrace nfa136 exists136 to-list-136 start136( b0 ∷ a0 ∷ b0 ∷ a0 ∷ b0 ∷ [] )
open FiniteSet
nx : (StatesQ → Bool) → (List A2 ) → StatesQ → Bool
nx now [] = now
nx now ( i ∷ ni ) = (Nmoves nfa136 exists136 (nx now ni) i )
example136-3 = to-list-136 start136
example136-4 = to-list-136 (nx start136 ( a0 ∷ b0 ∷ a0 ∷ [] ))
open import sbconst2
fm136 : Automaton ( StatesQ → Bool ) A2
fm136 = subset-construction exists136 nfa136
open NAutomaton
lemma136 : ( x : List A2 ) → Naccept nfa136 exists136 start136 x ≡ accept fm136 start136 x
lemma136 x = lemma136-1 x start136 where
lemma136-1 : ( x : List A2 ) → ( states : StatesQ → Bool )
→ Naccept nfa136 exists136 states x ≡ accept fm136 states x
lemma136-1 [] _ = refl
lemma136-1 (h ∷ t) states = lemma136-1 t (δconv exists136 (Nδ nfa136) states h)
|
{
"alphanum_fraction": 0.6055737705,
"avg_line_length": 26.7543859649,
"ext": "agda",
"hexsha": "b4ee9c4ffbd31dbb1a211fb78e7d06bf4ced11e1",
"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/nfa136.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/nfa136.agda",
"max_line_length": 92,
"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/nfa136.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1164,
"size": 3050
}
|
open import Agda.Builtin.Sigma
open import Agda.Builtin.Equality
infix 1 Σ-syntax
Σ-syntax = Σ
syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B
pair : Set → Set
pair A = Σ[ _ ∈ A ] A
diag : Set → Set
diag A = Σ[ p ∈ pair A ] fst p ≡ snd p
diag-pat : Set → Set
diag-pat A = Σ[ p@(x , y) ∈ pair A ] p ≡ (y , x)
-- WAS: parse error for p@(x , y)
-- WANT: success
|
{
"alphanum_fraction": 0.5821727019,
"avg_line_length": 18.8947368421,
"ext": "agda",
"hexsha": "44b4b063e5df023b89f66e2e241e1a7242a6e87c",
"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/Issue1182.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/Issue1182.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/Succeed/Issue1182.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": 147,
"size": 359
}
|
{-# OPTIONS --without-K #-}
--
-- A pointed type is a type together with a point in it. This module
-- defines the universe of pointed types which we denote by Type● ℓ.
-- Like the type universe Type ℓ, it is an inhabitant of Type (ℓ + 1).
--
-- Editing notes:
-- ● : \ci followed by selecting the 1 option
-- ∙ : \.
module hott.core.universe.pointed where
open import hott.core.sigma
open import hott.core.universe
-- The pointed type is nothing but a dependent pair where the first
-- component is itself a type.
Type● : (ℓ : Level) → Type (lsuc ℓ)
Type● ℓ = Σ λ x → x
-- The level 0 of pointed types.
Type∙ = Type● lzero
Type∙₀ = Type● lzero
Type∙₁ = Type● lone
Type∙₂ = Type● ltwo
Type∙₃ = Type● lthree
Type∙₄ = Type● lfour
Type∙₅ = Type● lfive
Type∙₆ = Type● lsix
Type∙₇ = Type● lseven
Type∙₈ = Type● leight
Type∙₉ = Type● lnine
--
-- Topologically pointed types are spaces with a distinguished point
-- called the base. We give function to recover the space and the base
-- point from it. These are essentially the projections but we give
-- better names for it.
--
space : ∀{ℓ} → Type● ℓ → Type ℓ
space = fst
base : ∀{ℓ} → (A● : Type● ℓ) → space A●
base = snd
|
{
"alphanum_fraction": 0.6742616034,
"avg_line_length": 24.6875,
"ext": "agda",
"hexsha": "b37eac8e5b0ea445db5e3ddf26d55a1bb9c91418",
"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": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "piyush-kurur/hott",
"max_forks_repo_path": "agda/hott/core/universe/pointed.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"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": "piyush-kurur/hott",
"max_issues_repo_path": "agda/hott/core/universe/pointed.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "piyush-kurur/hott",
"max_stars_repo_path": "agda/hott/core/universe/pointed.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 383,
"size": 1185
}
|
{-# OPTIONS --universe-polymorphism #-}
module Graphs.Graph where
open import Level
open import Categories.Support.Equivalence
open import Relation.Binary
using (Rel; IsEquivalence; module IsEquivalence; Reflexive; Symmetric; Transitive)
renaming (_⇒_ to _⊆_)
open import Relation.Binary.PropositionalEquality
using ()
renaming (_≡_ to _≣_)
record Graph (o ℓ e : Level) : Set (suc (o ⊔ ℓ ⊔ e)) where
field
Obj : Set o
_↝_ : Obj → Obj → Set ℓ
_≈_ : {A B : Obj} → Rel (A ↝ B) e
.equiv : ∀ {A B : Obj} → IsEquivalence (_≈_ {A}{B})
edge-setoid : ∀ {A B : Obj} → Setoid ℓ e
edge-setoid {A}{B} = record
{ Carrier = A ↝ B
; _≈_ = _≈_
; isEquivalence = equiv
}
module Equiv {A B : Obj} where
private
module e = IsEquivalence
.q : IsEquivalence _≈_
q = equiv {A} {B}
.refl : Reflexive _≈_
refl = e.refl q
.trans : Transitive _≈_
trans = e.trans q
.sym : Symmetric _≈_
sym = e.sym q
.reflexive : _≣_ ⊆ _≈_
reflexive = e.reflexive q
_[_↝_] : ∀ {o ℓ e} → (G : Graph o ℓ e) → Graph.Obj G → Graph.Obj G → Set ℓ
G [ A ↝ B ] = Graph._↝_ G A B
_[_≈_] : ∀ {o ℓ e} → (G : Graph o ℓ e) → {A B : Graph.Obj G} → Rel (G [ A ↝ B ]) e
G [ f ≈ g ] = Graph._≈_ G f g
module Heterogeneous {o ℓ e} (G : Graph o ℓ e) where
open Graph G
open Equiv renaming (refl to refl′; sym to sym′; trans to trans′)
data _~_ {A B} (f : A ↝ B) : ∀ {X Y} → (X ↝ Y) → Set (ℓ ⊔ e) where
≈⇒~ : {g : A ↝ B} → .(f ≈ g) → f ~ g
refl : ∀ {A B} {f : A ↝ B} → f ~ f
refl = ≈⇒~ refl′
sym : ∀ {A B} {f : A ↝ B} {D E} {g : D ↝ E} → f ~ g → g ~ f
sym (≈⇒~ f≈g) = ≈⇒~ (sym′ f≈g)
trans : ∀ {A B} {f : A ↝ B}
{D E} {g : D ↝ E}
{F G} {h : F ↝ G}
→ f ~ g → g ~ h → f ~ h
trans (≈⇒~ f≈g) (≈⇒~ g≈h) = ≈⇒~ (trans′ f≈g g≈h)
_[_~_] : ∀ {o ℓ e} (G : Graph o ℓ e) {A B} (f : G [ A ↝ B ]) {X Y} (g : G [ X ↝ Y ]) → Set (ℓ ⊔ e)
G [ f ~ g ] = Heterogeneous._~_ G f g
|
{
"alphanum_fraction": 0.4932466233,
"avg_line_length": 29.3970588235,
"ext": "agda",
"hexsha": "89c9d2825d4d0f93a878567befadeb7bf5777ec0",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Graphs/Graph.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Graphs/Graph.agda",
"max_line_length": 98,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Graphs/Graph.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 887,
"size": 1999
}
|
------------------------------------------------------------------------
-- Up-to techniques for strong bisimilarity
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Labelled-transition-system
module Bisimilarity.Up-to {ℓ} (lts : LTS ℓ) where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Prelude.Size
open import Bisimilarity lts
import Bisimilarity.Equational-reasoning-instances
open import Equational-reasoning
open import Relation
import Up-to
open LTS lts
------------------------------------------------------------------------
-- The general up-to machinery, instantiated with the StepC container
open Up-to StepC public
------------------------------------------------------------------------
-- Some examples (based on techniques presented by Pous and Sangiorgi
-- in "Enhancements of the bisimulation proof method")
-- Up to bisimilarity.
Up-to-bisimilarity : Trans₂ ℓ Proc
Up-to-bisimilarity R = Bisimilarity ∞ ⊙ R ⊙ Bisimilarity ∞
-- Up to bisimilarity is monotone.
up-to-bisimilarity-monotone : Monotone Up-to-bisimilarity
up-to-bisimilarity-monotone R⊆S =
Σ-map id (Σ-map id (Σ-map id (Σ-map R⊆S id)))
-- Up to bisimilarity is size-preserving.
up-to-bisimilarity-size-preserving : Size-preserving Up-to-bisimilarity
up-to-bisimilarity-size-preserving
R⊆∼i {p₁ , p₄} (p₂ , p₁∼p₂ , p₃ , p₂Rp₃ , p₃∼p₄) =
p₁ ∼⟨ p₁∼p₂ ⟩
p₂ ∼⟨ R⊆∼i p₂Rp₃ ⟩
p₃ ∼⟨ p₃∼p₄ ⟩■
p₄
-- Up to union with bisimilarity.
Up-to-∪∼ : Trans₂ ℓ Proc
Up-to-∪∼ R = R ∪ Bisimilarity ∞
-- Up to union with bisimilarity is monotone.
up-to-∪∼-monotone : Monotone Up-to-∪∼
up-to-∪∼-monotone R⊆S = ⊎-map R⊆S id
-- Up to union with bisimilarity is size-preserving.
--
-- The proof is similar to parts of the proof of Corollary 6.3.15 from
-- Pous and Sangiorgi's "Enhancements of the bisimulation proof
-- method".
up-to-∪∼-size-preserving : Size-preserving Up-to-∪∼
up-to-∪∼-size-preserving =
∪-closure
id-size-preserving
(const-size-preserving (Bisimilarity ∞ ⊆⟨ id ⟩∎
Bisimilarity ∞ ∎))
-- Up to transitive closure.
Up-to-* : Trans₂ ℓ Proc
Up-to-* R = R *
-- Up to transitive closure is monotone.
up-to-*-monotone : Monotone Up-to-*
up-to-*-monotone R⊆S = Σ-map id (λ {n} → ^^-mono R⊆S n)
where
^^-mono : ∀ {R S} → R ⊆ S →
∀ n → R ^^ n ⊆ S ^^ n
^^-mono R⊆S zero = id
^^-mono R⊆S (suc n) = Σ-map id (Σ-map R⊆S (^^-mono R⊆S n))
-- Up to transitive closure is size-preserving.
up-to-*-size-preserving : Size-preserving Up-to-*
up-to-*-size-preserving =
_⇔_.from (monotone→⇔ up-to-*-monotone) drop-*
where
drop-* : ∀ {i} → Bisimilarity i * ⊆ Bisimilarity i
drop-* {x = p , .p} (zero , refl) = p ■
drop-* {x = p , r} (suc n , q , p∼q , ∼ⁿqr) =
p ∼⟨ p∼q ⟩
q ∼⟨ drop-* (n , ∼ⁿqr) ⟩■
r
|
{
"alphanum_fraction": 0.5851826562,
"avg_line_length": 28.1634615385,
"ext": "agda",
"hexsha": "6b7aeb0559c91ffa6272d6f474580af28ba06de2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Bisimilarity/Up-to.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/up-to",
"max_issues_repo_path": "src/Bisimilarity/Up-to.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Bisimilarity/Up-to.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1020,
"size": 2929
}
|
module Issue1232.List where
import Issue1232.Nat
|
{
"alphanum_fraction": 0.8235294118,
"avg_line_length": 10.2,
"ext": "agda",
"hexsha": "8b8339cdcde0328529c8151707502c427d9069e5",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue1232/List.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue1232/List.agda",
"max_line_length": 27,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue1232/List.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": 15,
"size": 51
}
|
record C (A : Set) : Set where
field f : A → A
open C {{...}}
module M (A : Set) where
data D : Set where
d : A → D
instance
CD : C D
CD = record { f = λ x → x }
data Bool : Set where
false true : Bool
open M Bool
-- Bug: M.CD is not considered in instance search
x : D
x = f (M.d false)
|
{
"alphanum_fraction": 0.5523809524,
"avg_line_length": 13.6956521739,
"ext": "agda",
"hexsha": "bcdb95762a64178703761d82fe80d71a652c6a17",
"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/Issue1238.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/Issue1238.agda",
"max_line_length": 49,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1238.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": 110,
"size": 315
}
|
{-# OPTIONS --cubical #-}
open import Cubical.Core.Everything
Sq : {A : Set} {a0 a1 b0 b1 : A}
(u : a0 ≡ a1) (v : b0 ≡ b1)
(r0 : a0 ≡ b0) (r1 : a1 ≡ b1)
→ Set
Sq u v r0 r1 = PathP (λ i → r0 i ≡ r1 i) u v
ConstSq : {A : Set} {a : A} (p : a ≡ a) →
Sq p p p p
ConstSq {A} p i j = compCCHM (λ _ → A)
(~ i ∨ i ∨ ~ j ∨ j)
(λ k → λ { (i = i0) → p j
; (i = i1) → p (k ∧ j)
; (j = i0) → p i
; (j = i1) → p (k ∧ i)
})
(p (i ∨ j))
|
{
"alphanum_fraction": 0.368,
"avg_line_length": 23.8095238095,
"ext": "agda",
"hexsha": "e63973a5e2ef010e1608ff0256510fdb00b4dd7b",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-03-12T21:33:35.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-10-07T01:38:12.000Z",
"max_forks_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "dubinsky/intellij-dtlc",
"max_forks_repo_path": "testData/parse/agda/ConstSquare.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_issues_repo_issues_event_max_datetime": "2021-03-15T17:04:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-30T04:29:32.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "dubinsky/intellij-dtlc",
"max_issues_repo_path": "testData/parse/agda/ConstSquare.agda",
"max_line_length": 44,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "dubinsky/intellij-dtlc",
"max_stars_repo_path": "testData/parse/agda/ConstSquare.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-29T13:18:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-05-11T16:26:38.000Z",
"num_tokens": 244,
"size": 500
}
|
open import Data.Empty using (⊥-elim)
open import Data.Fin using (Fin; _≟_)
open import Data.Nat using (ℕ)
open import Data.Product using (∃-syntax; _,_)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Vec using (lookup; _[_]≔_)
open import Data.Vec.Properties using (lookup∘update; lookup∘update′)
open import Relation.Nullary using (yes; no; ¬_)
open import Relation.Binary.PropositionalEquality using (sym; trans; _≡_; refl; cong; _≢_; module ≡-Reasoning)
open import Data.Product using (∃-syntax; _,_; proj₁; proj₂; _×_)
open ≡-Reasoning
open import Common
open import Global
open import Local
private
variable
n : ℕ
l : Label
p q : Fin n
g gSub : Global n
lSub : Local n
project : Global n -> Fin n -> Local n
project endG _
= endL
project (msgSingle p q p≢q l gSub) r
with p ≟ r | q ≟ r
... | yes _ | no _ = sendSingle q l (project gSub r)
... | no _ | yes _ = recvSingle p l (project gSub r)
... | no _ | no _ = project gSub r
... | yes refl | yes refl = ⊥-elim (p≢q refl)
proj-prefix-other :
(r s t : Fin n)
-> ∀{ r≢s }
-> (gSub : Global n)
-> r ≢ t
-> s ≢ t
-> project (msgSingle r s r≢s l gSub) t ≡ project gSub t
proj-prefix-other r s t _ r≢t s≢t
with r ≟ t | s ≟ t
... | yes refl | _ = ⊥-elim (r≢t refl)
... | _ | yes refl = ⊥-elim (s≢t refl)
... | no _ | no _ = refl
proj-prefix-send :
(r s : Fin n)
-> (gSub : Global n)
-> (r≢s : r ≢ s)
-> project (msgSingle r s r≢s l gSub) r ≡ sendSingle s l (project gSub r)
proj-prefix-send r s _ r≢s
with r ≟ r | s ≟ r
... | yes _ | no _ = refl
... | _ | yes refl = ⊥-elim (r≢s refl)
... | no r≢r | no _ = ⊥-elim (r≢r refl)
proj-prefix-recv :
(r s : Fin n)
-> (gSub : Global n)
-> (r≢s : r ≢ s)
-> project (msgSingle r s r≢s l gSub) s ≡ recvSingle r l (project gSub s)
proj-prefix-recv r s _ r≢s
with r ≟ s | s ≟ s
... | no _ | yes _ = refl
... | yes refl | _ = ⊥-elim (r≢s refl)
... | _ | no s≢s = ⊥-elim (s≢s refl)
record _↔_ { n : ℕ } (g : Global n) (c : Configuration n) : Set where
field
isProj : ∀(p : Fin n) -> lookup c p ≡ project g p
proj-inv-send :
project {n} g p ≡ sendSingle q l lSub
-> ∃[ p≢q ] ∃[ gSub ] g ≡ msgSingle p q p≢q l gSub × project gSub p ≡ lSub
⊎
∃[ r ] ∃[ s ] ∃[ r≢s ] ∃[ l′ ] ∃[ gSub ]
g ≡ msgSingle r s r≢s l′ gSub ×
r ≢ p ×
s ≢ p ×
project gSub p ≡ sendSingle q l lSub
proj-inv-send {g = g@endG} projSend = ⊥-elim (endL≢sendSingle projSend)
proj-inv-send {n} {g = g@(msgSingle r s r≢s l′ gSub)} {p} {q} {l} {ltSub} projSend
with r ≟ p | s ≟ p
... | yes refl | yes refl = ⊥-elim (r≢s refl)
... | no r≢p | no s≢p = inj₂ (r , s , r≢s , l′ , gSub , refl , r≢p , s≢p , projSend)
... | yes refl | no s≢p
with sendSingle-injective projSend
... | refl , refl , refl = inj₁ (r≢s , gSub , refl , refl)
proj-inv-recv :
project {n} g p ≡ recvSingle q l lSub
-> ∃[ p≢q ] ∃[ gSub ] g ≡ msgSingle q p p≢q l gSub × project gSub p ≡ lSub
⊎
∃[ r ] ∃[ s ] ∃[ r≢s ] ∃[ l′ ] ∃[ gSub ]
g ≡ msgSingle r s r≢s l′ gSub ×
r ≢ p ×
s ≢ p ×
project gSub p ≡ recvSingle q l lSub
proj-inv-recv {g = g@endG} projRecv = ⊥-elim (endL≢recvSingle projRecv)
proj-inv-recv {n} {g = g@(msgSingle r s r≢s l′ gSub)} {p} {q} {l} {lSub} projRecv
with r ≟ p | s ≟ p
... | yes refl | yes refl = ⊥-elim (r≢s refl)
... | no r≢p | no s≢p = inj₂ (r , s , r≢s , l′ , gSub , refl , r≢p , s≢p , projRecv)
... | no r≢p | yes refl
with recvSingle-injective projRecv
... | refl , refl , refl = inj₁ (r≢s , gSub , refl , refl)
proj-inv-send-recv :
∀ { lpSub lqSub }
-> project {n} g p ≡ sendSingle q l lpSub
-> project {n} g q ≡ recvSingle p l lqSub
-> ∃[ p≢q ] ∃[ gSub ] g ≡ msgSingle p q p≢q l gSub × project gSub p ≡ lpSub × project gSub q ≡ lqSub
⊎
∃[ r ] ∃[ s ] ∃[ r≢s ] ∃[ l′ ] ∃[ gSub ]
g ≡ msgSingle r s r≢s l′ gSub ×
r ≢ p ×
s ≢ p ×
r ≢ q ×
s ≢ q ×
project gSub p ≡ sendSingle q l lpSub ×
project gSub q ≡ recvSingle p l lqSub
proj-inv-send-recv {n} {g} {p} {q} {l} {lpSub} {lqSub} projSend projRecv
with proj-inv-send {n} {g} projSend | proj-inv-recv {n} {g} projRecv
... | inj₁ (p≢q₁ , gSub₁ , refl , proj-g₁-p)
| inj₁ (_ , _ , refl , proj-g₂-q)
= inj₁ (p≢q₁ , gSub₁ , refl , proj-g₁-p , proj-g₂-q)
proj-inv-send-recv {n} {g} {p} {q} {l} {ltp′} {ltq′} projSend projRecv
| inj₁ (_ , _ , refl , _)
| inj₂ (_ , _ , _ , _ , _ , refl , _ , s≢q , _)
= ⊥-elim (s≢q refl)
proj-inv-send-recv {n} {g} {p} {q} {l} {ltp′} {ltq′} projSend projRecv
| inj₂ (_ , _ , _ , _ , _ , refl , r≢p , _ , _)
| inj₁ (_ , _ , refl , _)
= ⊥-elim (r≢p refl)
proj-inv-send-recv {n} {g} {p} {q} {l} {ltp′} {ltq′} projSend projRecv
| inj₂ (r , s , r≢s , l′ , gSub₁ , refl , r≢p , s≢p , proj-g₁-p)
| inj₂ (_ , _ , _ , _ , gSub₂ , refl , r≢q , s≢q , proj-g₂-q)
= inj₂ (r , s , r≢s , l′ , gSub₁ , refl , r≢p , s≢p , r≢q , s≢q , proj-g₁-p , proj-g₂-q)
config-gt-remove-prefix :
∀ { p≢q gSub }
-> (g : Global n)
-> (c : Configuration n)
-> g ↔ c
-> g ≡ msgSingle p q p≢q l gSub
-> ∃[ cSub ] cSub ≡ (c [ p ]≔ project gSub p) [ q ]≔ project gSub q × gSub ↔ cSub
config-gt-remove-prefix {n} {p} {q} {_} {p≢q} {gSub} g c assoc refl
= cSub , refl , (record { isProj = isProj-gSub })
where
lpSub = project gSub p
lqSub = project gSub q
cSub = (c [ p ]≔ lpSub) [ q ]≔ lqSub
isProj-gSub : ∀ (r : Fin n) -> lookup cSub r ≡ project gSub r
isProj-gSub r
with p ≟ r | q ≟ r
... | yes refl | yes refl = ⊥-elim (p≢q refl)
... | yes refl | no _
rewrite lookup∘update′ p≢q (c [ p ]≔ lpSub) lqSub
rewrite lookup∘update p c lpSub
= refl
... | no _ | yes refl
rewrite lookup∘update q (c [ p ]≔ lpSub) lqSub
= refl
... | no p≢r | no q≢r
rewrite lookup∘update′ (¬≡-flip q≢r) (c [ p ]≔ lpSub) lqSub
rewrite lookup∘update′ (¬≡-flip p≢r) c lpSub
rewrite _↔_.isProj assoc r
= proj-prefix-other p q r gSub p≢r q≢r
|
{
"alphanum_fraction": 0.5223279059,
"avg_line_length": 36.2748538012,
"ext": "agda",
"hexsha": "0bd84c0d578a70287c4022d247b8be50a7fda246",
"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": "Projection.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": "Projection.agda",
"max_line_length": 110,
"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": "Projection.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": 2605,
"size": 6203
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of operations on strings
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.String.Properties where
open import Data.Bool.Base
open import Data.String.Base
import Data.Char.Properties as Charₚ
import Data.List.Properties as Listₚ
open import Function
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Decidable using (map′; ⌊_⌋)
open import Relation.Binary using (Decidable; Setoid; DecSetoid; StrictTotalOrder)
open import Relation.Binary.PropositionalEquality.Core
open import Data.List.Relation.Binary.Lex.Strict as StrictLex
import Relation.Binary.Construct.On as On
import Relation.Binary.PropositionalEquality as PropEq
------------------------------------------------------------------------
-- Primitive properties
open import Agda.Builtin.String.Properties public
renaming ( primStringToListInjective to toList-injective)
------------------------------------------------------------------------
-- Equality
infix 4 _≟_
_≟_ : Decidable {A = String} _≡_
x ≟ y = map′ (toList-injective x y) (cong toList)
$ Listₚ.≡-dec Charₚ._≟_ (toList x) (toList y)
setoid : Setoid _ _
setoid = PropEq.setoid String
decSetoid : DecSetoid _ _
decSetoid = PropEq.decSetoid _≟_
------------------------------------------------------------------------
-- Lexicographic ordering on strings.
strictTotalOrder : StrictTotalOrder _ _ _
strictTotalOrder =
On.strictTotalOrder
(StrictLex.<-strictTotalOrder Charₚ.strictTotalOrder)
toList
------------------------------------------------------------------------
-- Alternative Boolean equality test.
--
-- Why is the definition _==_ = primStringEquality not used? One
-- reason is that the present definition can sometimes improve type
-- inference, at least with the version of Agda that is current at the
-- time of writing: see unit-test below.
infix 4 _==_
_==_ : String → String → Bool
s₁ == s₂ = ⌊ s₁ ≟ s₂ ⌋
private
-- The following unit test does not type-check (at the time of
-- writing) if _==_ is replaced by primStringEquality.
data P : (String → Bool) → Set where
p : (c : String) → P (_==_ c)
unit-test : P (_==_ "")
unit-test = p _
|
{
"alphanum_fraction": 0.6008547009,
"avg_line_length": 30.3896103896,
"ext": "agda",
"hexsha": "6f844b536057d86edfc12b00e6c07b758a736a8f",
"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/String/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/String/Properties.agda",
"max_line_length": 82,
"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/String/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 533,
"size": 2340
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.FiniteMultiset.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Nat
open import Cubical.Data.Empty as ⊥
open import Cubical.Relation.Nullary
open import Cubical.HITs.FiniteMultiset.Base
open import Cubical.Structures.MultiSet
open import Cubical.Relation.Nullary.DecidableEq
private
variable
ℓ : Level
A : Type ℓ
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) (cong (_++ ys) p) (cong (_++ ys) q) i j
unitl-++ : ∀ (xs : FMSet A) → [] ++ xs ≡ xs
unitl-++ xs = refl
unitr-++ : ∀ (xs : FMSet A) → xs ++ [] ≡ xs
unitr-++ = ElimProp.f (trunc _ _) refl (λ x p → cong (_∷_ x) p)
assoc-++ : ∀ (xs ys zs : FMSet A) → xs ++ (ys ++ zs) ≡ (xs ++ ys) ++ zs
assoc-++ = ElimProp.f (isPropΠ2 (λ _ _ → trunc _ _))
(λ ys zs → refl)
(λ x p ys zs → cong (_∷_ x) (p ys zs))
cons-++ : ∀ (x : A) (xs : FMSet A) → x ∷ xs ≡ xs ++ [ x ]
cons-++ x = ElimProp.f (trunc _ _)
refl
(λ y {xs} p → comm x y xs ∙ cong (_∷_ y) p)
comm-++ : ∀ (xs ys : FMSet A) → xs ++ ys ≡ ys ++ xs
comm-++ = ElimProp.f (isPropΠ (λ _ → trunc _ _))
(λ ys → sym (unitr-++ ys))
(λ x {xs} p ys → cong (x ∷_) (p ys)
∙ cong (_++ xs) (cons-++ x ys)
∙ sym (assoc-++ ys [ x ] xs))
module FMSetUniversal {ℓ} {M : Type ℓ} (MSet : isSet M)
(e : M) (_⊗_ : M → M → M)
(comm-⊗ : ∀ x y → x ⊗ y ≡ y ⊗ x) (assoc-⊗ : ∀ x y z → x ⊗ (y ⊗ z) ≡ (x ⊗ y) ⊗ z)
(unit-⊗ : ∀ x → e ⊗ x ≡ x)
(f : A → M) where
f-extend : FMSet A → M
f-extend = Rec.f MSet e (λ x m → f x ⊗ m)
(λ x y m → comm-⊗ (f x) (f y ⊗ m) ∙ sym (assoc-⊗ (f y) m (f x)) ∙ cong (f y ⊗_) (comm-⊗ m (f x)))
f-extend-nil : f-extend [] ≡ e
f-extend-nil = refl
f-extend-cons : ∀ x xs → f-extend (x ∷ xs) ≡ f x ⊗ f-extend xs
f-extend-cons x xs = refl
f-extend-sing : ∀ x → f-extend [ x ] ≡ f x
f-extend-sing x = comm-⊗ (f x) e ∙ unit-⊗ (f x)
f-extend-++ : ∀ xs ys → f-extend (xs ++ ys) ≡ f-extend xs ⊗ f-extend ys
f-extend-++ = ElimProp.f (isPropΠ λ _ → MSet _ _)
(λ ys → sym (unit-⊗ (f-extend ys)))
(λ x {xs} p ys → cong (f x ⊗_) (p ys) ∙ assoc-⊗ (f x) (f-extend xs) (f-extend ys))
module _ (h : FMSet A → M) (h-nil : h [] ≡ e) (h-sing : ∀ x → h [ x ] ≡ f x)
(h-++ : ∀ xs ys → h (xs ++ ys) ≡ h xs ⊗ h ys) where
f-extend-unique : h ≡ f-extend
f-extend-unique = funExt (ElimProp.f (MSet _ _)
h-nil
(λ x {xs} p → (h-++ [ x ] xs) ∙ cong (_⊗ h xs) (h-sing x) ∙ cong (f x ⊗_) p))
-- We want to construct a multiset-structure on FMSet A, the empty set and insertion are given by the constructors,
-- for the count part we use the recursor
-- If A has decidable equality we can define the count-function:
module _(discA : Discrete A) where
FMScount-∷* : A → A → ℕ → ℕ
FMScount-∷* a x n with discA a x
... | yes a≡x = suc n
... | no a≢x = n
FMScount-comm* : (a x y : A) (n : ℕ)
→ FMScount-∷* a x (FMScount-∷* a y n)
≡ FMScount-∷* a y (FMScount-∷* a x n)
FMScount-comm* a x y n with discA a x | discA a y
... | yes a≡x | yes a≡y = refl
... | yes a≡x | no a≢y = refl
... | no a≢x | yes a≡y = refl
... | no a≢x | no a≢y = refl
FMScount : A → FMSet A → ℕ
FMScount a = Rec.f isSetℕ 0 (FMScount-∷* a) (FMScount-comm* a)
FMS-with-str : MultiSet A (Discrete→isSet discA)
FMS-with-str = (FMSet A , [] , _∷_ , FMScount)
-- We prove some useful properties of the FMScount function
FMScount-≡-lemma : ∀ {a} {x} xs → a ≡ x → FMScount a (x ∷ xs) ≡ suc (FMScount a xs)
FMScount-≡-lemma {a} {x} xs a≡x with discA a x
... | yes _ = refl
... | no a≢x = ⊥.rec (a≢x a≡x)
FMScount-≡-lemma-refl : ∀ {x} xs → FMScount x (x ∷ xs) ≡ suc (FMScount x xs)
FMScount-≡-lemma-refl {x} xs = FMScount-≡-lemma xs refl
FMScount-≢-lemma : ∀ {a} {x} xs → ¬ a ≡ x → FMScount a (x ∷ xs) ≡ FMScount a xs
FMScount-≢-lemma {a} {x} xs a≢x with discA a x
... | yes a≡x = ⊥.rec (a≢x a≡x)
... | no _ = refl
FMScount-0-lemma : ∀ xs → (∀ a → FMScount a xs ≡ 0) → xs ≡ []
FMScount-0-lemma = ElimProp.f (isPropΠ λ _ → trunc _ _) (λ _ → refl) θ
where
θ : ∀ x {xs} → ((∀ a → FMScount a xs ≡ 0) → xs ≡ [])
→ ((∀ a → FMScount a (x ∷ xs) ≡ 0) → (x ∷ xs) ≡ [])
θ x {xs} _ p = ⊥.rec (snotz (sym (FMScount-≡-lemma-refl xs) ∙ p x))
-- we define a function that removes an element a from a finite multiset once
-- by simultaneously defining two lemmas about it
remove1 : A → FMSet A → FMSet A
remove1 a [] = []
remove1 a (x ∷ xs) with (discA a x)
... | yes _ = xs
... | no _ = x ∷ remove1 a xs
remove1 a (comm x y xs i) with discA a x with discA a y
... | yes a≡x | yes a≡y = ((sym a≡y ∙ a≡x) i) ∷ xs
... | yes a≡x | no _ = y ∷ (eq i)
where
eq : xs ≡ remove1 a (x ∷ xs)
eq with discA a x
eq | yes _ = refl
eq | no a≢x = ⊥.rec (a≢x a≡x)
remove1 a (comm x y xs i) | no _ | yes a≡y = x ∷ (eq i)
where
eq : remove1 a (y ∷ xs) ≡ xs
eq with discA a y
eq | yes _ = refl
eq | no a≢y = ⊥.rec (a≢y a≡y)
remove1 a (comm x y xs i) | no a≢x | no a≢y = ((λ i → x ∷ (p i)) ∙∙ comm x y (remove1 a xs) ∙∙ (λ i → y ∷ (sym q i))) i
where
p : remove1 a (y ∷ xs) ≡ y ∷ (remove1 a xs)
p with discA a y
p | yes a≡y = ⊥.rec (a≢y a≡y)
p | no _ = refl
q : remove1 a (x ∷ xs) ≡ x ∷ (remove1 a xs)
q with discA a x
q | yes a≡x = ⊥.rec (a≢x a≡x)
q | no _ = refl
remove1 a (trunc xs ys p q i j) = trunc (remove1 a xs) (remove1 a ys) (cong (remove1 a) p) (cong (remove1 a) q) i j
remove1-≡-lemma : ∀ {a} {x} xs → a ≡ x → xs ≡ remove1 a (x ∷ xs)
remove1-≡-lemma {a} {x} xs a≡x with discA a x
... | yes _ = refl
... | no a≢x = ⊥.rec (a≢x a≡x)
remove1-≢-lemma : ∀ {a} {x} xs → ¬ a ≡ x → remove1 a (x ∷ xs) ≡ x ∷ remove1 a xs
remove1-≢-lemma {a} {x} xs a≢x with discA a x
... | yes a≡x = ⊥.rec (a≢x a≡x)
... | no _ = refl
remove1-predℕ-lemma : ∀ a xs → FMScount a (remove1 a xs) ≡ predℕ (FMScount a xs)
remove1-predℕ-lemma a = ElimProp.f (isSetℕ _ _) refl θ
where
θ : ∀ x {xs} → FMScount a (remove1 a xs) ≡ predℕ (FMScount a xs)
→ FMScount a (remove1 a (x ∷ xs)) ≡ predℕ (FMScount a (x ∷ xs))
θ x {xs} p with discA a x
... | yes _ = refl
... | no a≢x = FMScount-≢-lemma (remove1 a xs) a≢x ∙ p
remove1-zero-lemma : ∀ a xs → FMScount a xs ≡ zero → xs ≡ remove1 a xs
remove1-zero-lemma a = ElimProp.f (isPropΠ λ _ → trunc _ _) (λ _ → refl) θ
where
θ : ∀ x {xs} → (FMScount a xs ≡ zero → xs ≡ remove1 a xs)
→ FMScount a (x ∷ xs) ≡ zero → x ∷ xs ≡ remove1 a (x ∷ xs)
θ x {xs} hyp p with discA a x
... | yes _ = ⊥.rec (snotz p)
... | no _ = cong (x ∷_) (hyp p)
remove1-suc-lemma : ∀ a n xs → FMScount a xs ≡ suc n → xs ≡ a ∷ (remove1 a xs)
remove1-suc-lemma a n = ElimProp.f (isPropΠ λ _ → trunc _ _) (λ p → ⊥.rec (znots p)) θ
where
θ : ∀ x {xs} → (FMScount a xs ≡ suc n → xs ≡ a ∷ (remove1 a xs))
→ FMScount a (x ∷ xs) ≡ suc n → x ∷ xs ≡ a ∷ (remove1 a (x ∷ xs))
θ x {xs} hyp p with discA a x
... | yes a≡x = (λ i → (sym a≡x i) ∷ xs)
... | no a≢x = cong (x ∷_) (hyp p) ∙ comm x a (remove1 a xs)
FMScount-remove1-≢-lemma : ∀ {a} {x} xs → ¬ a ≡ x → FMScount a (remove1 x xs) ≡ FMScount a xs
FMScount-remove1-≢-lemma {a} {x} xs a≢x with discreteℕ (FMScount x xs) zero
... | yes p = cong (FMScount a) (sym (remove1-zero-lemma x xs p))
... | no ¬p = sym (FMScount-≢-lemma (remove1 x xs) a≢x) ∙ cong (FMScount a) eq₁
where
eq₁ : (x ∷ remove1 x xs) ≡ xs
eq₁ = sym (remove1-suc-lemma x (predℕ (FMScount x xs)) xs (suc-predℕ (FMScount x xs) ¬p))
|
{
"alphanum_fraction": 0.5004247057,
"avg_line_length": 37.4590909091,
"ext": "agda",
"hexsha": "66339011dc30820fa8a3bc9349e1f47197841af8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/HITs/FiniteMultiset/Properties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/HITs/FiniteMultiset/Properties.agda",
"max_line_length": 127,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/HITs/FiniteMultiset/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3484,
"size": 8241
}
|
{-# OPTIONS --show-implicit --verbose=tc.reconstruct:50 #-}
open import ExtractSac as ES using ()
open import Extract (ES.kompile-fun)
open import Data.Nat
open import Data.List as L using (List; []; _∷_)
open import Data.Vec as V using (Vec; []; _∷_)
open import Data.Fin using (Fin; zero; suc; #_)
open import Relation.Binary.PropositionalEquality
open import Reflection
open import Structures
open import ReflHelper
open import Function
open import Array.Base
-- Check that Vec² and List ∘ Vec are treated correctly.
-- Here we transpose a 2d array using Vec operations.
-- Note that we are using local where-defined functions.
test-20f : ∀ m n → Vec (Vec ℕ n) m → Vec (Vec ℕ m) n
test-20f 0 n [] = repl []
where
repl : ∀ {k} → Vec ℕ 0 → Vec _ k
repl {0} x = []
repl {suc _} x = x ∷ repl x
test-20f (suc _) n (x ∷ xs) = xzip x (test-20f _ n xs)
where
xzip : ∀ {n} → Vec _ n → Vec _ n → Vec _ n
xzip [] [] = []
xzip (x ∷ xs) (y ∷ ys) = (x ∷ y) ∷ xzip xs ys
test₂₀ : kompile test-20f [] [] ≡ ok _
test₂₀ = refl
-- simplified version of the test20 for debugging purposes.
test-20f′ : ∀ n → Vec ℕ n → Vec (Vec ℕ 1) n → Vec (Vec ℕ 2) n
test-20f′ n xs ys = xzip xs ys
where
xzip : ∀ {n} → Vec _ n → Vec _ n → Vec _ n
xzip [] [] = []
xzip (x ∷ xs) (y ∷ ys) = (x ∷ y) ∷ xzip xs ys
test₂₀′ : kompile test-20f′ [] [] ≡ ok _
test₂₀′ = refl
-- Make sure that we can handle lists of hom. objects
test-21f : ∀ n → List (Vec ℕ n)
test-21f n = []
test₂₁ : kompile test-21f [] [] ≡ ok _
test₂₁ = refl
-- Test that cons and friends work on a simple example
test-22f : ∀ n → Vec (Vec ℕ n) 1
test-22f n = repl 0 ∷ []
where
repl : ∀ {m} → ℕ → Vec ℕ m
repl {0} x = []
repl {suc _} x = x ∷ repl x
test₂₂ : kompile test-22f [] [] ≡ ok _
test₂₂ = refl
-- Test that polymorphic functions are failing with a reasonable error
test-23f : ∀ {X : Set} → X → X
test-23f x = x
test₂₃ : _≡_ {A = Prog} (kompile test-23f [] []) $ error _
test₂₃ = refl
-- FIXME: This gives a buggy assertion on the argument (that is not present)
test-24f : Vec ℕ (1 + 2)
test-24f = 1 ∷ 2 ∷ 3 ∷ []
test₂₄ : kompile test-24f [] [] ≡ ok _
test₂₄ = refl
-- Array stuff
test-25f : ℕ → Ar ℕ 1 V.[ 5 ]
test-25f n = cst n
test₂₅ : kompile test-25f [] [] ≡ ok _
test₂₅ = refl
-- Element-wise addition.
test-26f : ∀ {d s} → (a b : Ar ℕ d s) → Ar ℕ d s
test-26f a b = imap λ iv → sel a iv + sel b iv
test₂₆ : kompile test-26f [] [] ≡ ok _
test₂₆ = refl
test-27f : ∀ {d s} → (a b : Ar ℕ d s) → Ar ℕ d s
test-27f (imap a) (imap b) = imap λ iv → a iv + b iv
test₂₇ : kompile test-27f [] [] ≡ ok _
test₂₇ = refl
test-28f : ∀ {d s} → (a b : Ar ℕ d s) → Ar ℕ d s
test-28f (imap _) (imap a) = imap λ iv → a iv + 1
test₂₈ : kompile test-28f [] [] ≡ ok _
test₂₈ = refl
-- Testing for dot and absurd arguments of the imap.
test-29f : ∀ {d s} → (a b : Ar ℕ d s) → a ≡ b → Ar ℕ d s
test-29f (imap .a) (imap a) refl = imap λ iv → a iv + 1
test₂₉ : kompile test-29f [] [] ≡ ok _
test₂₉ = refl
-- We cannot write this:
--
-- open import Data.Empty
-- test-30f : Ar ⊥ 1 V.[ 1 ] → ⊥
-- test-30f (imap ())
--
-- even though `f` in imap has type Ix 1 [1] → ⊥, which doesn't exist.
-- If non-lambda is found as an argument of the imap.
test-31f : Ar ℕ 1 V.[ 10 ] → Ar ℕ 1 V.[ 10 ]
test-31f (imap f) = imap f
test₃₁ : kompile test-31f [] [] ≡ ok _
test₃₁ = refl
-- Index types
test-32f : Ix 2 (3 ∷ 4 ∷ []) → Fin 3
test-32f ix = ix-lookup ix (# 0)
test₃₂ : kompile test-32f [] [] ≡ ok _
test₃₂ = refl
module mat-mul where
postulate
asum : ∀ {n} → Ar ℕ 1 (n ∷ []) → ℕ
mm : ∀ {m n k} → let Mat a b = Ar ℕ 2 (a ∷ b ∷ []) in
Mat m n → Mat n k → Mat m k
mm (imap a) (imap b) = imap λ iv →
let i = ix-lookup iv (# 0)
j = ix-lookup iv (# 1)
in asum (imap λ kv → let k = ix-lookup kv (# 0)
in a (i ∷ k ∷ []) * b (k ∷ j ∷ []))
mm-kompiled = kompile mm [] (quote asum ∷ [])
test₃₃ : mm-kompiled ≡ ok _
test₃₃ = refl
-- This test ensurest that even if bound variables appear in
-- different order than in the telescope, we can still use them.
test-34f : ∀ {d s} → Ix (suc d) s → ℕ
test-34f {_}{x ∷ s} (_∷_ i ix) = x
test-34t = kompile test-34f [] []
test₃₄ : test-34t ≡ ok ("\n\n// Function Example-02.test-34f\n"
++ "int\nExample_02_test_34f(int x_1, int[.] x_2, int[.] x_4) {\n"
++ "/* assert (dim (x_4) == (1 + x_1)) */\n/* assert (x_4 < x_2) */\n"
++ "/* assert (shape (x_2)[[0]] == (1 + x_1)) */"
++ "int __ret;\nd = x_1;\nx = hd (x_2);\ns = tl (x_2);\n"
++ "i = hd (x_4);\nix = tl (x_4);\n__ret = x;\n"
++ "return __ret;\n}\n\n")
test₃₄ = refl
test-35f : ∀ {d s} → Ix (suc d) s → ℕ
test-35f {_} (_∷_ {d}{s}{x} i ix) = x
test₃₅ : kompile test-35f [] [] ≡ ok ("\n\n// Function Example-02.test-35f\n"
++ "int\nExample_02_test_35f(int x_1, int[.] x_2, int[.] x_4) {\n"
++ "/* assert (dim (x_4) == (1 + x_1)) */\n/* assert (x_4 < x_2) */\n"
++ "/* assert (shape (x_2)[[0]] == (1 + x_1)) */"
++ "int __ret;\nd = x_1;\nx = hd (x_2);\ns = tl (x_2);\n"
++ "i = hd (x_4);\nix = tl (x_4);\n__ret = x;\n"
++ "return __ret;\n}\n\n")
test₃₅ = refl
test-fold1 : ∀ {n} → Ar ℕ 1 V.[ n ] → Ar ℕ 1 V.[ n ]
test-fold1 a = imap λ iv → sel a iv + 5
test-fold : ∀ {n} → Ar ℕ 1 V.[ n ] → Ar ℕ 1 V.[ n ]
test-fold a = imap λ iv → sel (test-fold1 a) iv + 6
|
{
"alphanum_fraction": 0.5141146279,
"avg_line_length": 29.5202020202,
"ext": "agda",
"hexsha": "870ebe990a69f5d4083847f936c447979b74789f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "ashinkarov/agda-extractor",
"max_forks_repo_path": "Example-02.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "ashinkarov/agda-extractor",
"max_issues_repo_path": "Example-02.agda",
"max_line_length": 105,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "ashinkarov/agda-extractor",
"max_stars_repo_path": "Example-02.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-11T14:52:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-11T14:52:59.000Z",
"num_tokens": 2188,
"size": 5845
}
|
module Golden.Factorial where
open import Agda.Builtin.Nat
fac : Nat -> Nat
fac 0 = 1
fac (suc n) = suc n * fac n
a = fac 0
b = fac 10
|
{
"alphanum_fraction": 0.652173913,
"avg_line_length": 12.5454545455,
"ext": "agda",
"hexsha": "d3429e6c71279e2ad1559dce828faaeec4f218b0",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:48.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-05-24T10:45:59.000Z",
"max_forks_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-ocaml",
"max_forks_repo_path": "test/agda-ocaml/Golden/Factorial.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec",
"max_issues_repo_issues_event_max_datetime": "2018-11-05T21:28:57.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-29T13:37:52.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-ocaml",
"max_issues_repo_path": "test/agda-ocaml/Golden/Factorial.agda",
"max_line_length": 29,
"max_stars_count": 48,
"max_stars_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-ocaml",
"max_stars_repo_path": "test/agda-ocaml/Golden/Factorial.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-15T09:08:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-03-29T14:19:31.000Z",
"num_tokens": 54,
"size": 138
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- The binary relation defined by a constant
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Construct.Constant where
open import Relation.Binary
------------------------------------------------------------------------
-- Definition
Const : ∀ {a b c} {A : Set a} {B : Set b} → Set c → REL A B c
Const I = λ _ _ → I
------------------------------------------------------------------------
-- Properties
module _ {a c} (A : Set a) {C : Set c} where
refl : C → Reflexive {A = A} (Const C)
refl c = c
sym : Symmetric {A = A} (Const C)
sym c = c
trans : Transitive {A = A} (Const C)
trans c d = c
isEquivalence : C → IsEquivalence {A = A} (Const C)
isEquivalence c = record
{ refl = λ {x} → refl c {x}
; sym = λ {x} {y} → sym {x} {y}
; trans = λ {x} {y} {z} → trans {x} {y} {z}
}
setoid : C → Setoid a c
setoid x = record { isEquivalence = isEquivalence x }
|
{
"alphanum_fraction": 0.4194139194,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "93e9461310b2814c67d0fc8eda4ac781304a1a09",
"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/Relation/Binary/Construct/Constant.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/Relation/Binary/Construct/Constant.agda",
"max_line_length": 72,
"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/Relation/Binary/Construct/Constant.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": 289,
"size": 1092
}
|
module HOAny where
open import Agda.Builtin.Nat
open import Agda.Builtin.Bool
data Wrapper (M : Set → Set) : Set where
mnat : M Nat → Wrapper M
mbool : M Bool → Wrapper M
{-# FOREIGN GHC data AgdaWrapper m = Mnat (m Integer) | Mbool (m Bool) #-}
{-# COMPILE GHC Wrapper = data AgdaWrapper (Mnat | Mbool) #-}
map : ∀ {M N} → (∀ {n} → M n → N n) → Wrapper M → Wrapper N
map f (mnat mn) = mnat (f mn)
map f (mbool mb) = mbool (f mb)
-- Higher-order use of Any in the compiled code:
-- data AgdaWrapper m = Mnat (m Integer) | Mbool (m Bool)
-- map ::
-- (() -> ()) ->
-- (() -> ()) ->
-- (() -> AgdaAny -> AgdaAny) -> AgdaWrapper AgdaAny -> AgdaWrapper AgdaAny
-- WAS:
-- The expected kind to AgdaWrapper's argument is * -> *
-- but AgdaAny's kind is *
-- WANT: SUCCESS
-- made possible by making AgdaAny poly-kinded
open import Common.Prelude
main : IO Unit
main = putStrLn ""
|
{
"alphanum_fraction": 0.6208053691,
"avg_line_length": 24.1621621622,
"ext": "agda",
"hexsha": "0081f7d04fcdd98d0d7320f2a15db3a867f7fa24",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Compiler/simple/HOAny.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Compiler/simple/HOAny.agda",
"max_line_length": 76,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Compiler/simple/HOAny.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": 284,
"size": 894
}
|
open import Algebra using (CommutativeRing)
module AKS.Polynomial {c ℓ} (R : CommutativeRing c ℓ) where
open import AKS.Polynomial.Properties R public
|
{
"alphanum_fraction": 0.7857142857,
"avg_line_length": 22,
"ext": "agda",
"hexsha": "cca6922337eb31e72676c7af54e043f909db754b",
"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/Polynomial.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/Polynomial.agda",
"max_line_length": 59,
"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/Polynomial.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": 43,
"size": 154
}
|
-- Andreas, 2016-06-02
-- The filename "Issue.1947.agda" is invalid as "1947" is not a valid name.
module _ where
|
{
"alphanum_fraction": 0.7043478261,
"avg_line_length": 23,
"ext": "agda",
"hexsha": "35a7d01af419e6a37f11c4bac8e3a40feffd1a00",
"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/Issue.1947.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/Issue.1947.agda",
"max_line_length": 75,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue.1947.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 39,
"size": 115
}
|
import Lvl
module Structure.Groupoid {ℓₒ ℓₘ ℓₑ : Lvl.Level} where
open import Functional using (swap)
open import Logic
open import Logic.Predicate
open import Logic.Propositional
import Structure.Categorical.Names as Names
open import Structure.Categorical.Properties
open import Structure.Category{ℓₒ}{ℓₘ}{ℓₑ}
open import Structure.Operator
open import Structure.Relator.Equivalence
import Structure.Relator.Names as Names
open import Structure.Relator.Properties
open import Structure.Setoid
open import Type
{- TODO: It would be nice if groupoids were defined using a category as a record field and if categories were defined using a semicategory as a record field (they are "substructures" of each other) so that no code-duplication is necessary, but the problem is how long the projections/copatterns become with this approach.
postulate A B C : Type{Lvl.𝟎}
record R : Type{Lvl.𝟎} where
field
a : A
b : B
record R2 : Type{Lvl.𝟎} where
field
r : R
c : C
open R(r) public
-- a = R.a r
-- This is not possible, but would be nice:
r2 : R2
R2.a r2 = ?
R2.b r2 = ?
R2.c r2 = ?
-- One must write this:
r2 : R2
R2.r(R.a r2) = ?
R2.r(R.b r2) = ?
R2.c r2 = ?
which means that the copatterns would be longer and longer for each nesting a record has.
If Agda had support for "copattern/projection synonyms" or if the example above worked, then
-}
-- Obj is the collection of objects.
-- _⟶_ is the collection of morphisms.
module _
{Obj : Type{ℓₒ}}
(_⟶_ : Obj → Obj → Type{ℓₘ})
⦃ morphism-equiv : ∀{x y} → Equiv{ℓₑ}(x ⟶ y) ⦄
where
-- A groupoid is a structure on a relation called a morphism.
--
-- It can be seen as a generalization of the structure in invertible functions between a collection of types/sets.
-- More specifically, the algebraic properties of functions regarding composition and the identity function together with an function inverter.
-- In this case, sets are objects and functions are morphisms.
--
-- It can also be seen as a generalized algebraic structure, or more specifically a generalization of groups.
-- The type of a group's operator is usually restricted to a single type, but a groupoid allows it to vary (depending on the rules of morphism instead).
-- (One can loosely call a groupoid to be a group without the "closed" property of algebraic structures).
-- In this case, the binary operation is (_∘_) and the laws are the usual identity, associative and inverse laws.
--
-- An alternative interpretation of the definition:
-- A type (Obj) and a binary relation (Morphism) on this type is a groupoid when:
-- • The relator is transitive.
-- • The relator is reflexive.
-- • The relator is symmetric.
-- • The reflexivity proof inside the transitivity proof does not result in a new proof.
-- • Chains of the transitivity proofs can be applied in any order and the resulting proof will be the same.
-- • Transitivity of a proof of a pair and its symmetry is the reflexivity proof.
-- In other words, this is a specialized equivalence relation/setoid on `Obj`. If the morphism equivalence is trivial (always true) for a groupoid, then the groupoid describes the same structure as an equivalence relation does.
-- See `Relator.Equals.Category` for an example of this kind of binary relation.
--
-- A groupoid is the common pattern seen in all the examples above.
record Groupoid : Stmt{ℓₒ Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
field
_∘_ : Names.SwappedTransitivity(_⟶_)
id : Names.Reflexivity(_⟶_)
inv : Names.Symmetry(_⟶_)
infixr 20 _∘_
field
⦃ binaryOperator ⦄ : ∀{x y z} → BinaryOperator(_∘_ {x}{y}{z})
⦃ associativity ⦄ : Morphism.Associativity(\{x} → _∘_ {x})
⦃ identity ⦄ : Morphism.Identity(_∘_)(\{x} → id{x})
⦃ inverter ⦄ : Polymorphism.Inverter(_∘_)(\{x} → id{x})(inv)
-- This can be interpreted as proof of symmetry when `Morphism` is interpreted as a binary relation.
morphism-symmetry : Symmetry(_⟶_)
morphism-symmetry = intro inv
category : Category(_⟶_)
Category._∘_ category = _∘_
Category.id category = id
Category.binaryOperator category = binaryOperator
Category.associativity category = associativity
Category.identity category = identity
open Category(category) hiding (_∘_ ; id ; binaryOperator ; associativity ; identity) public
open Polymorphism.Inverter(_∘_)(\{x} → id{x})(inv)(inverter) renaming (left to inverterₗ ; right to inverterᵣ) public
morphism-equivalence : Equivalence(_⟶_)
Equivalence.reflexivity morphism-equivalence = morphism-reflexivity
Equivalence.symmetry morphism-equivalence = morphism-symmetry
Equivalence.transitivity morphism-equivalence = morphism-transitivity
object-equiv : Equiv(Obj)
object-equiv = intro(_⟶_) ⦃ morphism-equivalence ⦄
morphism-setoid : Setoid
morphism-setoid = [∃]-intro Obj ⦃ object-equiv ⦄
-- A category object can be used when one refers to a category as an object.
-- Examples of usage are in functors (morphism between categories) or in equivalences of categories.
record GroupoidObject : Stmt{Lvl.𝐒(ℓₒ Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ)} where
constructor intro
field
{Object} : Type{ℓₒ}
{Morphism} : Object → Object → Type{ℓₘ}
⦃ morphism-equiv ⦄ : ∀{x y} → Equiv{ℓₑ}(Morphism x y)
groupoid : Groupoid(Morphism)
open Groupoid(groupoid) public
instance
groupoid-instance = groupoid
|
{
"alphanum_fraction": 0.7086901075,
"avg_line_length": 41.5833333333,
"ext": "agda",
"hexsha": "3aedbaa78187115e94d2b9d60d4e86278c4a4d33",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Groupoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Groupoid.agda",
"max_line_length": 321,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Groupoid.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": 1559,
"size": 5489
}
|
{-# OPTIONS --universe-polymorphism #-}
module tests.Coind where
open import Prelude.IO
open import Prelude.Level
open import Prelude.Nat
open import Prelude.Unit
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
ones : Stream Nat
ones = 1 :: (♯ ones)
twos : Stream Nat
twos = 2 :: (♯ twos)
incr : Nat -> Stream Nat
incr n = n :: (♯ (incr (n + 1)))
printStream : Nat -> Stream Nat -> IO Unit
printStream Z _ = putStrLn ""
printStream (S steps) (n :: ns) =
printNat n ,,
printStream steps (♭ ns)
main : IO Unit
main =
printStream 10 twos ,,
printStream 10 ones ,,
printStream 10 (incr Z)
|
{
"alphanum_fraction": 0.5720930233,
"avg_line_length": 20,
"ext": "agda",
"hexsha": "b8efdfcf260fa625435dc343a667465729a2521f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "test/epic/tests/Coind.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/agda",
"max_issues_repo_path": "test/epic/tests/Coind.agda",
"max_line_length": 47,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/epic/tests/Coind.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 306,
"size": 860
}
|
module Logic.Propositional.Equiv where
import Lvl
open import Logic
open import Logic.Propositional
import Logic.Propositional.Theorems as Theorems
open import Structure.Relator.Equivalence
open import Structure.Relator.Properties
open import Structure.Setoid
open import Type
private variable ℓ ℓ₁ ℓ₂ ℓₑ ℓₑ₁ ℓₑ₂ : Lvl.Level
private variable T A B : Type{ℓ}
instance
[↔]-reflexivity : Reflexivity{ℓ₂ = ℓ}(_↔_)
[↔]-reflexivity = intro Theorems.[↔]-reflexivity
instance
[↔]-symmetry : Symmetry{ℓ₂ = ℓ}(_↔_)
[↔]-symmetry = intro Theorems.[↔]-symmetry
instance
[↔]-transitivity : Transitivity{ℓ₂ = ℓ}(_↔_)
[↔]-transitivity = intro Theorems.[↔]-transitivity
instance
[↔]-equivalence : Equivalence{ℓ₂ = ℓ}(_↔_)
[↔]-equivalence = intro
instance
[↔]-equiv : Equiv(Stmt{ℓ})
[↔]-equiv = intro(_↔_) ⦃ [↔]-equivalence ⦄
|
{
"alphanum_fraction": 0.7076923077,
"avg_line_length": 24.8529411765,
"ext": "agda",
"hexsha": "5934f78cdb3ea6c9c4cb99278bbffa5ffaf2d11d",
"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/Propositional/Equiv.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/Propositional/Equiv.agda",
"max_line_length": 52,
"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/Propositional/Equiv.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": 313,
"size": 845
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.