Search is not available for this dataset
text
string | meta
dict |
---|---|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED, please use `Data.Record` directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Decidable)
open import Relation.Binary.PropositionalEquality using (_≡_)
module Record {ℓ} (Label : Set ℓ) (_≟_ : Decidable {A = Label} _≡_) where
{-# WARNING_ON_IMPORT
"Record was deprecated in v1.1.
Use Data.Record instead."
#-}
open import Data.Record Label _≟_ public
|
{
"alphanum_fraction": 0.5423728814,
"avg_line_length": 29.5,
"ext": "agda",
"hexsha": "54715ab98e5ecca94bada6afe114a535e0bad027",
"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/Record.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/Record.agda",
"max_line_length": 73,
"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/Record.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": 123,
"size": 590
}
|
{-# OPTIONS --rewriting --confluence-check #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
record Box (A : Set) : Set where
constructor box
field
unbox : A
open Box
postulate
A : Set
a b : A
f : (X : Set) → X → A
g : (X : Set) → X
rewf₁ : f (Box A) (box a) ≡ a
rewf₂ : (X : Set) → f X (g X) ≡ b
rewg : g (Box A) .unbox ≡ a
test = f (Box A) (g (Box A))
{-# REWRITE rewf₁ rewg #-}
rewg-contracted : g (Box A) ≡ box a
rewg-contracted = refl
foo : test ≡ a
foo = refl
{-# REWRITE rewf₂ #-}
bar : test ≡ b
bar = refl
fails : a ≡ b
fails = refl
|
{
"alphanum_fraction": 0.5792079208,
"avg_line_length": 14.7804878049,
"ext": "agda",
"hexsha": "6f0b0f8b448b68c1e967388f1ca9d63574cf6aba",
"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/Issue3810c.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/Issue3810c.agda",
"max_line_length": 46,
"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/Issue3810c.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 235,
"size": 606
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Construction.Diagonal where
-- A variety of Diagonal functors
open import Level
open import Data.Product using (_,_)
open import Categories.Category
open import Categories.Functor
open import Categories.Category.Product
open import Categories.Category.Construction.Functors
open import Categories.Functor.Construction.Constant
open import Categories.NaturalTransformation using (ntHelper)
import Categories.Functor.Power as Power
private
variable
o ℓ e o′ ℓ′ e′ : Level
Δ : (C : Category o ℓ e) → Functor C (Product C C)
Δ C = record
{ F₀ = λ x → x , x
; F₁ = λ f → f , f
; identity = refl , refl
; homomorphism = refl , refl
; F-resp-≈ = λ x → x , x
}
where
open Category C
open Equiv
Δ′ : (I : Set) → (C : Category o ℓ e) → Functor C (Power.Exp C I)
Δ′ I C = record
{ F₀ = λ x _ → x
; F₁ = λ f _ → f
; identity = λ _ → refl
; homomorphism = λ _ → refl
; F-resp-≈ = λ x _ → x
}
where open Category.Equiv C
ΔF : {C : Category o ℓ e} (I : Category o′ ℓ′ e′) → Functor C (Functors I C)
ΔF {C = C} I = record
{ F₀ = const
; F₁ = λ f → ntHelper record { η = λ _ → f; commute = λ _ → C.identityʳ ○ ⟺ C.identityˡ }
; identity = refl
; homomorphism = refl
; F-resp-≈ = λ x → x
}
where
module C = Category C
open C.Equiv
open C.HomReasoning using (_○_; ⟺)
|
{
"alphanum_fraction": 0.6020477816,
"avg_line_length": 26.1607142857,
"ext": "agda",
"hexsha": "b0a02cc9d1a5ebeb3175fc7a7f4c93c65c4dfcc2",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Functor/Construction/Diagonal.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Functor/Construction/Diagonal.agda",
"max_line_length": 101,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Functor/Construction/Diagonal.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 483,
"size": 1465
}
|
{-# OPTIONS --cubical --no-exact-split --safe #-}
module Cubical.Data.NatMinusOne.Base where
open import Cubical.Core.Primitives
open import Cubical.Data.Nat
data ℕ₋₁ : Set where
neg1 : ℕ₋₁
suc : (n : ℕ₋₁) → ℕ₋₁
_+₋₁_ : ℕ → ℕ₋₁ → ℕ₋₁
0 +₋₁ n = n
suc m +₋₁ n = suc (m +₋₁ n)
ℕ→ℕ₋₁ : ℕ → ℕ₋₁
ℕ→ℕ₋₁ n = suc (n +₋₁ neg1)
1+_ : ℕ₋₁ → ℕ
1+ neg1 = zero
1+ suc n = suc (1+ n)
-1+_ : ℕ → ℕ₋₁
-1+ zero = neg1
-1+ suc n = suc (-1+ n)
|
{
"alphanum_fraction": 0.5552995392,
"avg_line_length": 17.36,
"ext": "agda",
"hexsha": "ebc9b9778ec0c2ee25b4872f7158a06a72439fbf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Data/NatMinusOne/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Data/NatMinusOne/Base.agda",
"max_line_length": 49,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Data/NatMinusOne/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 218,
"size": 434
}
|
module fib1 where
data ℕ : Set where
Z : ℕ
S : ℕ -> ℕ
_+_ : ℕ -> ℕ -> ℕ
n + Z = n
n + S m = S (n + m)
one : ℕ
one = S Z
fib : ℕ -> ℕ
fib Z = one
fib (S Z) = one
fib (S (S n)) = fib n + fib (S n)
|
{
"alphanum_fraction": 0.4099099099,
"avg_line_length": 11.6842105263,
"ext": "agda",
"hexsha": "b86b813c518a2bf0b9c9d0de5cfdbf57fe957f61",
"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": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejtokarcik/agda-semantics",
"max_forks_repo_path": "tests/covered/fib1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"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": "andrejtokarcik/agda-semantics",
"max_issues_repo_path": "tests/covered/fib1.agda",
"max_line_length": 33,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejtokarcik/agda-semantics",
"max_stars_repo_path": "tests/covered/fib1.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z",
"num_tokens": 97,
"size": 222
}
|
import Lvl
open import Structure.Operator.Vector
open import Structure.Setoid
open import Type
module Structure.Operator.Vector.Eigen
{ℓᵥ ℓₛ ℓᵥₑ ℓₛₑ}
{V : Type{ℓᵥ}} ⦃ equiv-V : Equiv{ℓᵥₑ}(V) ⦄
{S : Type{ℓₛ}} ⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄
(_+ᵥ_ : V → V → V)
(_⋅ₛᵥ_ : S → V → V)
(_+ₛ_ _⋅ₛ_ : S → S → S)
⦃ vectorSpace : VectorSpace(_+ᵥ_)(_⋅ₛᵥ_)(_+ₛ_)(_⋅ₛ_) ⦄
where
open VectorSpace(vectorSpace)
open import Logic
open import Logic.Predicate
open import Logic.Propositional
open import Syntax.Function
-- v is a eigenvector for the eigenvalue 𝜆 of the linear transformation f.
-- Multiplication by an eigenvalue can replace a linear transformation for certain vectors.
Eigenpair : (V → V) → S → V → Stmt
Eigenpair(f)(𝜆)(v) = ((v ≢ 𝟎ᵥ) ∧ (f(v) ≡ 𝜆 ⋅ₛᵥ v))
Eigenvector : (V → V) → V → Stmt
Eigenvector(f)(v) = ∃(𝜆 ↦ Eigenpair(f)(𝜆)(v))
Eigenvalue : (V → V) → S → Stmt
Eigenvalue(f)(𝜆) = ∃(v ↦ Eigenpair(f)(𝜆)(v))
|
{
"alphanum_fraction": 0.6502145923,
"avg_line_length": 28.2424242424,
"ext": "agda",
"hexsha": "97eef677ec3db47dea6f0e2ff89ce3e2fdbe49e9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Operator/Vector/Eigen.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Operator/Vector/Eigen.agda",
"max_line_length": 91,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Operator/Vector/Eigen.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": 418,
"size": 932
}
|
{-# OPTIONS --without-K #-}
open import Base
open import Homotopy.Truncation
open import Homotopy.Connected
open import Spaces.Suspension
open import Homotopy.PushoutDef
import Homotopy.PushoutUP as PushoutUP
-- In this file I prove that if [A] is n-connected and its (n+1)-truncation is
-- inhabited, then [suspension A] is (n+1)-connected.
--
-- The hypothesis that [τ (S n) A] is inhabited is not necessary, it can be
-- removed but it’s simpler to assume it
module Homotopy.ConnectedSuspension
{i} (A : Set i) {n : ℕ₋₂} (p : is-connected n A) (x₀ : τ (S n) A) where
-- The (n+1)-truncation of the suspension is a pushout of the following diagram
τ-susp-diag : pushout-diag i
τ-susp-diag = diag τ (S n) unit , τ (S n) unit , τ (S n) A
, τ-extend-nondep (λ _ → proj tt)
, τ-extend-nondep (λ _ → proj tt)
module τ-susp-H = PushoutUP τ-susp-diag (is-truncated (S n))
import Homotopy.TruncationRightExact (S n) (suspension-diag A) as Exact
abstract
trunc-cocone : τ-susp-H.cocone (τ (S n) (suspension A))
trunc-cocone = Exact.cocone-τpushout
trunc-is-pushout : τ-susp-H.is-pushout (τ (S n) (suspension A)) trunc-cocone
trunc-is-pushout = Exact.τpushout-is-pushout
-- The previous diagram is equivalent to the following
susp-diag : pushout-diag i
susp-diag = suspension-diag (τ (S n) A)
module susp-H = PushoutUP susp-diag (is-truncated (S n))
-- To be moved
τ-unit-to-unit : τ (S n) (unit {i}) → unit {i}
τ-unit-to-unit _ = tt
abstract
τ-unit-to-unit-is-equiv : is-equiv τ-unit-to-unit
τ-unit-to-unit-is-equiv =
iso-is-eq _ (λ _ → proj tt)
(λ _ → refl)
(τ-extend
⦃ λ _ → ≡-is-truncated (S n) (τ-is-truncated (S n) _) ⦄
(λ _ → refl))
τ-unit-equiv-unit : τ (S n) unit ≃ unit
τ-unit-equiv-unit = (τ-unit-to-unit , τ-unit-to-unit-is-equiv)
-- / To be moved
abstract
τ-susp-equal-susp : τ-susp-diag ≡ susp-diag
τ-susp-equal-susp = pushout-diag-eq τ-unit-equiv-unit τ-unit-equiv-unit
(id-equiv _) (λ _ → refl) (λ _ → refl)
-- But we prove by hand that the point is also a pushout of this diagram
unit-cocone : susp-H.cocone unit
unit-cocone = (id _ susp-H., id _ , cst refl)
private
factor-pushout : (E : Set i) → (susp-H.cocone E → (unit {i} → E))
factor-pushout E c = susp-H.A→top c
x : {E : Set i} → (susp-H.cocone E → E)
x c = susp-H.A→top c tt
y : {E : Set i} → (susp-H.cocone E → E)
y c = susp-H.B→top c tt
x≡y : {E : Set i} (c : susp-H.cocone E) → x c ≡ y c
x≡y c = susp-H.h c x₀
ττA-is-contr : is-contr (τ n (τ (S n) A))
ττA-is-contr = equiv-types-truncated _ (τ-equiv-ττ n A) p
susp-H-unit-is-pushout : susp-H.is-pushout unit unit-cocone
susp-H-unit-is-pushout E ⦃ P-E ⦄ =
iso-is-eq _
(factor-pushout E)
(λ c →
susp-H.cocone-eq-raw _ refl (funext (λ _ → x≡y c))
(app-is-inj x₀ ττA-is-contr (P-E _ _)
(trans-Π2 _ (λ v _ → susp-H.A→top c tt ≡ v tt)
(funext (λ r → susp-H.h c x₀)) _ _
∘ (trans-cst≡app _ (λ u → u tt) (funext (λ r → susp-H.h c x₀)) _
∘ happly (happly-funext (λ _ → susp-H.h c x₀)) tt))))
(λ _ → refl)
-- Type of (S n)-truncated pushout-diagrams (this should probably be defined
-- more generally in Homotopy.PushoutDef or something)
truncated-diag : Set _
truncated-diag = Σ (pushout-diag i)
(λ d → (is-truncated (S n) (pushout-diag.A d))
× ((is-truncated (S n) (pushout-diag.B d))
× (is-truncated (S n) (pushout-diag.C d))))
τ-susp-trunc-diag : truncated-diag
τ-susp-trunc-diag = (τ-susp-diag , (τ-is-truncated (S n) _ ,
(τ-is-truncated (S n) _ ,
τ-is-truncated (S n) _)))
susp-trunc-diag : truncated-diag
susp-trunc-diag = (susp-diag , (unit-is-truncated-S#instance ,
(unit-is-truncated-S#instance ,
τ-is-truncated (S n) _)))
-- The two diagrams are equal as truncated diagrams
abstract
τ-susp-trunc-equal-susp-trunc : τ-susp-trunc-diag ≡ susp-trunc-diag
τ-susp-trunc-equal-susp-trunc = Σ-eq τ-susp-equal-susp
(Σ-eq (π₁ (is-truncated-is-prop (S n) _ _))
(Σ-eq (π₁ (is-truncated-is-prop (S n) _ _))
(π₁ (is-truncated-is-prop (S n) _ _))))
new-cocone : (d : truncated-diag) → (Set i → Set i)
new-cocone (d , (_ , (_ , _))) =
PushoutUP.cocone d (is-truncated (S n))
new-is-pushout : (d : truncated-diag)
→ ((D : Set i) ⦃ PD : is-truncated (S n) D ⦄
(Dcocone : new-cocone d D) → Set _)
new-is-pushout (d , (_ , (_ , _))) =
PushoutUP.is-pushout d (is-truncated (S n))
unit-new-cocone : (d : truncated-diag) → new-cocone d unit
unit-new-cocone d = ((λ _ → tt) PushoutUP., (λ _ → tt) , (λ _ → refl))
unit-is-pushout : (d : truncated-diag) → Set _
unit-is-pushout d = new-is-pushout d unit (unit-new-cocone d)
abstract
unit-τ-is-pushout :
τ-susp-H.is-pushout unit (unit-new-cocone τ-susp-trunc-diag)
unit-τ-is-pushout =
transport unit-is-pushout (! τ-susp-trunc-equal-susp-trunc)
susp-H-unit-is-pushout
private
unit-equiv-τSnΣA : unit {i} ≃ τ (S n) (suspension A)
unit-equiv-τSnΣA =
τ-susp-H.pushout-equiv-pushout
unit (unit-new-cocone τ-susp-trunc-diag) unit-τ-is-pushout
(τ (S n) (suspension A)) trunc-cocone trunc-is-pushout
abstract
suspension-is-connected-S : is-connected (S n) (suspension A)
suspension-is-connected-S =
equiv-types-truncated _ unit-equiv-τSnΣA unit-is-contr
|
{
"alphanum_fraction": 0.5995357972,
"avg_line_length": 35.2264150943,
"ext": "agda",
"hexsha": "0633216785983a7f3a56ffc2c52b6270e30bff1e",
"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/Homotopy/ConnectedSuspension.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/Homotopy/ConnectedSuspension.agda",
"max_line_length": 79,
"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/Homotopy/ConnectedSuspension.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": 1897,
"size": 5601
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Bool
open import lib.types.FunctionSeq
open import lib.types.Paths
open import lib.types.Pointed
open import lib.types.Suspension.Core
open import lib.types.Suspension.Trunc
open import lib.types.Truncation
module lib.types.Suspension.Flip where
module SuspFlip {i} {A : Type i} = SuspRec
(south' A) north (! ∘ merid)
Susp-flip : ∀ {i} {A : Type i} → Susp A → Susp A
Susp-flip = SuspFlip.f
Susp-flip-σloop-seq : ∀ {i} (X : Ptd i) (x : de⊙ X)
→ ap Susp-flip (σloop X x) =-= ! (merid x) ∙ merid (pt X)
Susp-flip-σloop-seq X x =
ap Susp-flip (merid x ∙ ! (merid (pt X)))
=⟪ ap-∙ Susp-flip (merid x) (! (merid (pt X))) ⟫
ap Susp-flip (merid x) ∙ ap Susp-flip (! (merid (pt X)))
=⟪ ap2 _∙_
(! (!-! (ap Susp-flip (merid x))) ∙ ap ! (r x))
(ap-! Susp-flip (merid (pt X)) ∙ r (pt X)) ⟫
! (merid x) ∙ merid (pt X) ∎∎
where
r : (x : de⊙ X) → ! (ap Susp-flip (merid x)) == merid x
r x = ap ! (SuspFlip.merid-β x) ∙ !-! (merid x)
Susp-flip-σloop : ∀ {i} (X : Ptd i) (x : de⊙ X)
→ ap Susp-flip (σloop X x) == ! (merid x) ∙ merid (pt X)
Susp-flip-σloop X x = ↯ (Susp-flip-σloop-seq X x)
Susp-flip-σloop-pt : ∀ {i} (X : Ptd i)
→ Susp-flip-σloop X (pt X) ◃∎
=ₛ
ap (ap Susp-flip) (!-inv-r (merid (pt X))) ◃∙
! (!-inv-l (merid (pt X))) ◃∎
Susp-flip-σloop-pt X =
Susp-flip-σloop X (pt X) ◃∎
=ₛ⟨ expand (Susp-flip-σloop-seq X (pt X)) ⟩
Susp-flip-σloop-seq X (pt X)
=ₛ⟨ coh Susp-flip (merid (pt X)) (merid (pt X))
(ap ! (SuspFlip.merid-β (pt X)) ∙ !-! (merid (pt X))) ⟩
ap (ap Susp-flip) (!-inv-r (merid (pt X))) ◃∙
! (!-inv-l (merid (pt X))) ◃∎ ∎ₛ
where
coh : ∀ {j k} {A : Type j} {B : Type k} (f : A → B)
{a₀ a₁ : A} (p : a₀ == a₁)
(q : f a₁ == f a₀)
(r : ! (ap f p) == q)
→ ap-∙ f p (! p) ◃∙
ap2 _∙_ (! (!-! (ap f p)) ∙ ap ! r) (ap-! f p ∙ r) ◃∎
=ₛ
ap (ap f) (!-inv-r p) ◃∙
! (!-inv-l q) ◃∎
coh f p@idp q@.idp r@idp = =ₛ-in idp
maybe-Susp-flip : ∀ {i} {A : Type i} → Bool → Susp A → Susp A
maybe-Susp-flip true = Susp-flip
maybe-Susp-flip false = idf _
⊙Susp-flip : ∀ {i} (X : Ptd i) → ⊙Susp (de⊙ X) ⊙→ ⊙Susp (de⊙ X)
⊙Susp-flip X = (Susp-flip , ! (merid (pt X)))
⊙maybe-Susp-flip : ∀ {i} (X : Ptd i) → Bool → ⊙Susp (de⊙ X) ⊙→ ⊙Susp (de⊙ X)
⊙maybe-Susp-flip X true = ⊙Susp-flip X
⊙maybe-Susp-flip X false = ⊙idf (⊙Susp (de⊙ X))
de⊙-⊙maybe-Susp-flip : ∀ {i} (X : Ptd i) (b : Bool)
→ fst (⊙maybe-Susp-flip X b) == maybe-Susp-flip b
de⊙-⊙maybe-Susp-flip X true = idp
de⊙-⊙maybe-Susp-flip X false = idp
Susp-flip-flip : ∀ {i} {A : Type i} (sa : Susp A)
→ Susp-flip (Susp-flip sa) == sa
Susp-flip-flip =
Susp-elim
idp
idp $ λ a → ↓-='-in' $
ap (λ z → z) (merid a)
=⟨ ap-idf (merid a) ⟩
merid a
=⟨ ! (!-! (merid a)) ⟩
! (! (merid a))
=⟨ ap ! (! (SuspFlip.merid-β a)) ⟩
! (ap Susp-flip (merid a))
=⟨ !-ap Susp-flip (merid a) ⟩
ap Susp-flip (! (merid a))
=⟨ ap (ap Susp-flip) (! (SuspFlip.merid-β a)) ⟩
ap Susp-flip (ap Susp-flip (merid a))
=⟨ ∘-ap Susp-flip Susp-flip (merid a) ⟩
ap (Susp-flip ∘ Susp-flip) (merid a) =∎
⊙Susp-flip-flip : ∀ {i} {X : Ptd i}
→ ⊙Susp-flip X ◃⊙∘ ⊙Susp-flip X ◃⊙idf =⊙∘ ⊙idf-seq
⊙Susp-flip-flip {_} {X} =
⊙seq-λ= Susp-flip-flip $
ap Susp-flip (! (merid (pt X))) ◃∙
! (merid (pt X)) ◃∎
=ₛ₁⟨ 0 & 1 & ap-! Susp-flip (merid (pt X)) ⟩
! (ap Susp-flip (merid (pt X))) ◃∙
! (merid (pt X)) ◃∎
=ₛ₁⟨ 0 & 1 & ap ! (SuspFlip.merid-β (pt X)) ⟩
! (! (merid (pt X))) ◃∙
! (merid (pt X)) ◃∎
=ₛ₁⟨ !-inv-l (! (merid (pt X))) ⟩
idp ◃∎ ∎ₛ
⊙maybe-Susp-flip-flip : ∀ {i} (X : Ptd i) (b c : Bool)
→ ⊙maybe-Susp-flip X b ◃⊙∘ ⊙maybe-Susp-flip X c ◃⊙idf
=⊙∘
⊙maybe-Susp-flip X (xor b c) ◃⊙idf
⊙maybe-Susp-flip-flip X true true =
⊙Susp-flip X ◃⊙∘ ⊙Susp-flip X ◃⊙idf
=⊙∘⟨ ⊙Susp-flip-flip ⟩
⊙idf-seq
=⊙∘⟨ ⊙contract ⟩
⊙idf _ ◃⊙idf ∎⊙∘
⊙maybe-Susp-flip-flip X true false = =⊙∘-in idp
⊙maybe-Susp-flip-flip X false true = =⊙∘-in (⊙λ= (⊙∘-unit-l (⊙Susp-flip X)))
⊙maybe-Susp-flip-flip X false false = =⊙∘-in idp
Susp-flip-equiv : ∀ {i} {A : Type i} → Susp A ≃ Susp A
Susp-flip-equiv {A = A} =
equiv Susp-flip Susp-flip Susp-flip-flip Susp-flip-flip
Susp-flip-natural : ∀ {i} {j} {A : Type i} {B : Type j} (f : A → B)
→ ∀ σ → Susp-flip (Susp-fmap f σ) == Susp-fmap f (Susp-flip σ)
Susp-flip-natural f = Susp-elim idp idp $ λ y → ↓-='-in' $
ap (Susp-fmap f ∘ Susp-flip) (merid y)
=⟨ ap-∘ (Susp-fmap f) Susp-flip (merid y) ⟩
ap (Susp-fmap f) (ap Susp-flip (merid y))
=⟨ ap (ap (Susp-fmap f)) (SuspFlip.merid-β y) ⟩
ap (Susp-fmap f) (! (merid y))
=⟨ ap-! (Susp-fmap f) (merid y) ⟩
! (ap (Susp-fmap f) (merid y))
=⟨ ap ! (SuspFmap.merid-β f y) ⟩
! (merid (f y))
=⟨ ! (SuspFlip.merid-β (f y)) ⟩
ap Susp-flip (merid (f y))
=⟨ ! (ap (ap Susp-flip) (SuspFmap.merid-β f y)) ⟩
ap Susp-flip (ap (Susp-fmap f) (merid y))
=⟨ ∘-ap Susp-flip (Susp-fmap f) (merid y) ⟩
ap (Susp-flip ∘ Susp-fmap f) (merid y) =∎
⊙Susp-flip-natural : ∀ {i} {j} {X : Ptd i} {Y : Ptd j} (f : X ⊙→ Y)
→ ⊙Susp-flip Y ⊙∘ ⊙Susp-fmap (fst f) == ⊙Susp-fmap (fst f) ⊙∘ ⊙Susp-flip X
⊙Susp-flip-natural {_} {_} {X} {Y} f =
pair= (λ= (Susp-flip-natural (fst f))) $
↓-app=cst-in $ ! $ =ₛ-out {t = ! (merid (pt Y)) ◃∎} $
app= (λ= (Susp-flip-natural (fst f))) north ◃∙
ap (Susp-fmap (fst f)) (! (merid (pt X))) ◃∙
idp ◃∎
=ₛ⟨ 2 & 1 & expand [] ⟩
app= (λ= (Susp-flip-natural (fst f))) north ◃∙
ap (Susp-fmap (fst f)) (! (merid (pt X))) ◃∎
=ₛ₁⟨ 0 & 1 & app=-β (Susp-flip-natural (fst f)) north ⟩
idp ◃∙
ap (Susp-fmap (fst f)) (! (merid (pt X))) ◃∎
=ₛ⟨ 0 & 1 & expand [] ⟩
ap (Susp-fmap (fst f)) (! (merid (pt X))) ◃∎
=ₛ₁⟨ ap-! (Susp-fmap (fst f)) (merid (pt X)) ⟩
! (ap (Susp-fmap (fst f)) (merid (pt X))) ◃∎
=ₛ₁⟨ ap ! (SuspFmap.merid-β (fst f) (pt X)) ⟩
! (merid (fst f (pt X))) ◃∎
=ₛ₁⟨ ap (! ∘ merid) (snd f) ⟩
! (merid (pt Y)) ◃∎ ∎ₛ
module _ {i} {A : Type i} where
Susp-fmap-flip : (x : Susp (Susp A))
→ Susp-fmap Susp-flip x == Susp-flip x
Susp-fmap-flip =
Susp-elim
{P = λ x → Susp-fmap Susp-flip x == Susp-flip x}
(merid north)
(! (merid south)) $ λ y →
↓-='-in-=ₛ $
merid north ◃∙
ap Susp-flip (merid y) ◃∎
=ₛ₁⟨ 1 & 1 & SuspFlip.merid-β y ⟩
merid north ◃∙
! (merid y) ◃∎
=ₛ⟨ =ₛ-in {t = merid (Susp-flip y) ◃∙ ! (merid south) ◃∎} $
Susp-elim
{P = λ y → merid north ∙ ! (merid y) == merid (Susp-flip y) ∙ ! (merid south)}
(!-inv-r (merid north) ∙ ! (!-inv-r (merid south)))
idp
(λ a → ↓-='-in-=ₛ $
(!-inv-r (merid north) ∙ ! (!-inv-r (merid south))) ◃∙
ap (λ z → merid (Susp-flip z) ∙ ! (merid south)) (merid a) ◃∎
=ₛ⟨ 0 & 1 & expand (!-inv-r (merid north) ◃∙ ! (!-inv-r (merid south)) ◃∎) ⟩
!-inv-r (merid north) ◃∙
! (!-inv-r (merid south)) ◃∙
ap (λ z → merid (Susp-flip z) ∙ ! (merid south)) (merid a) ◃∎
=ₛ₁⟨ 2 & 1 & ap-∘ (λ z' → merid z' ∙ ! (merid south)) Susp-flip (merid a) ⟩
!-inv-r (merid north) ◃∙
! (!-inv-r (merid south)) ◃∙
ap (λ z' → merid z' ∙ ! (merid south)) (ap Susp-flip (merid a)) ◃∎
=ₛ₁⟨ 2 & 1 & ap (ap (λ z' → merid z' ∙ ! (merid south)))
(SuspFlip.merid-β a) ⟩
!-inv-r (merid north) ◃∙
! (!-inv-r (merid south)) ◃∙
ap (λ z' → merid z' ∙ ! (merid south)) (! (merid a)) ◃∎
=ₛ₁⟨ 2 & 1 & ap-∘ (_∙ ! (merid south)) merid (! (merid a)) ⟩
!-inv-r (merid north) ◃∙
! (!-inv-r (merid south)) ◃∙
ap (_∙ ! (merid south)) (ap merid (! (merid a))) ◃∎
=ₛ₁⟨ 2 & 1 & ap (ap (_∙ ! (merid south))) (ap-! merid (merid a)) ⟩
!-inv-r (merid north) ◃∙
! (!-inv-r (merid south)) ◃∙
ap (_∙ ! (merid south)) (! (ap merid (merid a))) ◃∎
=ₛ⟨ coh-helper (ap merid (merid a)) ⟩
ap (λ q → merid north ∙ ! q) (ap merid (merid a)) ◃∎
=ₛ₁⟨ ∘-ap (λ q → merid north ∙ ! q) merid (merid a) ⟩
ap (λ z → merid north ∙ ! (merid z)) (merid a) ◃∎
=ₛ⟨ 1 & 0 & contract ⟩
ap (λ z → merid north ∙ ! (merid z)) (merid a) ◃∙ idp ◃∎ ∎ₛ)
y ⟩
merid (Susp-flip y) ◃∙
! (merid south) ◃∎
=ₛ₁⟨ 0 & 1 & ! (SuspFmap.merid-β Susp-flip y) ⟩
ap (Susp-fmap Susp-flip) (merid y) ◃∙
! (merid south) ◃∎ ∎ₛ
where
coh-helper : ∀ {j} {B : Type j}
{b-north b-south : B}
{merid₁ merid₂ : b-north == b-south}
(p : merid₁ == merid₂)
→ !-inv-r merid₁ ◃∙
! (!-inv-r merid₂) ◃∙
ap (_∙ ! merid₂) (! p) ◃∎
=ₛ
ap (λ q → merid₁ ∙ ! q) p ◃∎
coh-helper {merid₁ = idp} {merid₂ = .idp} idp =
=ₛ-in idp
⊙Susp-fmap-Susp-flip : ⊙Susp-fmap Susp-flip == ⊙Susp-flip (⊙Susp A)
⊙Susp-fmap-Susp-flip =
⊙λ=' Susp-fmap-flip (↓-idf=cst-in (! (!-inv-r (merid north))))
⊙Susp-fmap-maybe-Susp-flip : ∀ (b : Bool)
→ ⊙Susp-fmap (maybe-Susp-flip b) == ⊙maybe-Susp-flip (⊙Susp A) b
⊙Susp-fmap-maybe-Susp-flip true = ⊙Susp-fmap-Susp-flip
⊙Susp-fmap-maybe-Susp-flip false = =⊙∘-out (⊙Susp-fmap-idf _)
⊙maybe-Susp-flip-natural : ∀ {i} {j} {X : Ptd i} {Y : Ptd j} (f : X ⊙→ Y) (b : Bool)
→ ⊙Susp-fmap (fst f) ⊙∘ ⊙maybe-Susp-flip X b ==
⊙maybe-Susp-flip Y b ⊙∘ ⊙Susp-fmap (fst f)
⊙maybe-Susp-flip-natural f true = ! (⊙Susp-flip-natural f)
⊙maybe-Susp-flip-natural f false = ⊙λ= (⊙∘-unit-l (⊙Susp-fmap (fst f)))
module _ {i} (A : Type i) (m : ℕ₋₂) where
Susp-Trunc-swap-Susp-flip :
Susp-Trunc-swap A m ∘ Susp-flip ∼
Trunc-fmap Susp-flip ∘ Susp-Trunc-swap A m
Susp-Trunc-swap-Susp-flip =
Susp-elim
idp
idp $
Trunc-elim {{λ t → ↓-level (=-preserves-level Trunc-level)}} $ λ a →
↓-='-in' $
ap (Trunc-fmap Susp-flip ∘ Susp-Trunc-swap A m) (merid [ a ])
=⟨ ap-∘ (Trunc-fmap Susp-flip) (Susp-Trunc-swap A m) (merid [ a ]) ⟩
ap (Trunc-fmap Susp-flip) (ap (Susp-Trunc-swap A m) (merid [ a ]))
=⟨ ap (ap (Trunc-fmap Susp-flip)) (SuspTruncSwap.merid-β A m [ a ]) ⟩
ap (Trunc-fmap Susp-flip) (ap [_] (merid a))
=⟨ ∘-ap (Trunc-fmap Susp-flip) [_] (merid a) ⟩
ap ([_] ∘ Susp-flip) (merid a)
=⟨ ap-∘ [_] Susp-flip (merid a) ⟩
ap [_] (ap Susp-flip (merid a))
=⟨ ap (ap [_]) (SuspFlip.merid-β a) ⟩
ap [_] (! (merid a))
=⟨ ap-! [_] (merid a) ⟩
! (ap [_] (merid a))
=⟨ ap ! (! (SuspTruncSwap.merid-β A m [ a ])) ⟩
! (ap (Susp-Trunc-swap A m) (merid [ a ]))
=⟨ !-ap (Susp-Trunc-swap A m) (merid [ a ]) ⟩
ap (Susp-Trunc-swap A m) (! (merid [ a ]))
=⟨ ap (ap (Susp-Trunc-swap A m)) (! (SuspFlip.merid-β [ a ])) ⟩
ap (Susp-Trunc-swap A m) (ap Susp-flip (merid [ a ]))
=⟨ ∘-ap (Susp-Trunc-swap A m) Susp-flip (merid [ a ]) ⟩
ap (Susp-Trunc-swap A m ∘ Susp-flip) (merid [ a ]) =∎
abstract
⊙Susp-Trunc-swap-⊙Susp-flip : ∀ {i} {X : Ptd i} (m : ℕ₋₂)
→ ⊙Susp-Trunc-swap (de⊙ X) m ◃⊙∘
⊙Susp-flip (⊙Trunc m X) ◃⊙idf
=⊙∘
⊙Trunc-fmap (⊙Susp-flip X) ◃⊙∘
⊙Susp-Trunc-swap (de⊙ X) m ◃⊙idf
⊙Susp-Trunc-swap-⊙Susp-flip {X = X} m =
⊙seq-λ= (Susp-Trunc-swap-Susp-flip (de⊙ X) m) $ !ₛ $
idp ◃∙
idp ◃∙
ap [_] (! (merid (pt X))) ◃∎
=ₛ⟨ 0 & 1 & expand [] ⟩
idp ◃∙
ap [_] (! (merid (pt X))) ◃∎
=ₛ⟨ 0 & 1 & expand [] ⟩
ap [_] (! (merid (pt X))) ◃∎
=ₛ₁⟨ ap-! [_] (merid (pt X)) ⟩
! (ap [_] (merid (pt X))) ◃∎
=ₛ₁⟨ ! $ ap ! $ SuspTruncSwap.merid-β (de⊙ X) m [ pt X ] ⟩
! (ap (Susp-Trunc-swap (de⊙ X) m) (merid [ pt X ])) ◃∎
=ₛ₁⟨ !-ap (Susp-Trunc-swap (de⊙ X) m) (merid [ pt X ]) ⟩
ap (Susp-Trunc-swap (de⊙ X) m) (! (merid [ pt X ])) ◃∎
=ₛ⟨ 1 & 0 & contract ⟩
ap (Susp-Trunc-swap (de⊙ X) m) (! (merid [ pt X ])) ◃∙
idp ◃∎ ∎ₛ
|
{
"alphanum_fraction": 0.4881473528,
"avg_line_length": 38.072327044,
"ext": "agda",
"hexsha": "917b29cbb8aa22b6b7d14ffb7068f70362b4e757",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/Suspension/Flip.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Suspension/Flip.agda",
"max_line_length": 93,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/Suspension/Flip.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": 5732,
"size": 12107
}
|
module Oscar.Class.Congruity where
open import Oscar.Class.Extensionality
open import Oscar.Level
record Congruity {a} {A : Set a} {ℓ₁} (_≋₁_ : A → A → Set ℓ₁)
{b} {B : Set b} {ℓ₂} (_≋₂_ : B → B → Set ℓ₂)
: Set (a ⊔ ℓ₁ ⊔ b ⊔ ℓ₂) where
field
congruity : ∀ (μ : A → B) {x y} → x ≋₁ y → μ x ≋₂ μ y
instance ′extensionality : ∀ (μ : A → B) → Extensionality _≋₁_ (λ ⋆ → _≋₂_ ⋆) μ μ
Extensionality.extensionality (′extensionality μ) = congruity μ
open Congruity ⦃ … ⦄ public -- hiding (′extensionality)
|
{
"alphanum_fraction": 0.5895522388,
"avg_line_length": 31.5294117647,
"ext": "agda",
"hexsha": "c45805cd0ff2f1dfe87b8f59ea2a5d9aba9c90e1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Class/Congruity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Class/Congruity.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Class/Congruity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 216,
"size": 536
}
|
-- 2014-07-27 Andreas, issue reported by phadei
module _ where
-- trait A { type T <: A }
record A (self : Set) (T : Set) : Set₁ where
inductive
field
T⊂A : T → A T self
-- trait C extends A with B { type T <: C }
record C (self : Set) (T : Set) : Set₁ where
inductive
field
a : A T self
T⊂C : T → C T self
-- A with B { type T <: A with B { type T <: ... } }
record AB (self : Set) (T : Set) : Set₁ where
field
c : C T self
postulate
Nat Bool : Set
-- Let's give Nat a A∧B trait, with T = Bool
Nat-AB : AB Nat Bool
Nat-AB = {!!}
-- WAS: Non-termination of type-checker (eta-expansion).
-- SHOULD BE: an unsolved meta.
|
{
"alphanum_fraction": 0.586259542,
"avg_line_length": 19.8484848485,
"ext": "agda",
"hexsha": "27909593f9b5c4be498ea1af025ce8cefd54c965",
"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/Issue1239.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/Issue1239.agda",
"max_line_length": 56,
"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/Issue1239.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": 233,
"size": 655
}
|
∙_ : Set₁ → Set₁
∙ X = X
Foo : Set
Foo = ∙ Set
|
{
"alphanum_fraction": 0.4791666667,
"avg_line_length": 8,
"ext": "agda",
"hexsha": "d285ce5342f9527cacf9cd9e864fad467043ae81",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Sections-14.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Sections-14.agda",
"max_line_length": 16,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Sections-14.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": 26,
"size": 48
}
|
open import Agda.Builtin.List
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
open import Agda.Builtin.Reflection
pattern vArg x = arg (arg-info visible (modality relevant quantity-ω)) x
macro
macaroo : Term → TC ⊤
macaroo hole = unify hole (con (quote suc) (vArg unknown ∷ []))
test : Nat
test = macaroo
|
{
"alphanum_fraction": 0.7368421053,
"avg_line_length": 23.0714285714,
"ext": "agda",
"hexsha": "12dfae697ed40200283864f7df443ce14b65e156",
"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": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "Seanpm2001-Agda-lang/agda",
"max_forks_repo_path": "test/interaction/Issue5700.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "Seanpm2001-Agda-lang/agda",
"max_issues_repo_path": "test/interaction/Issue5700.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "6b13364d36eeb60d8ec15eaf8effe23c73401900",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "sseefried/agda",
"max_stars_repo_path": "test/interaction/Issue5700.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": 95,
"size": 323
}
|
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.RingAlgebras where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Algebra
open import Cubical.Categories.Category
open Category
open AlgebraHoms
private
variable
ℓ ℓ' : Level
module _ (R : Ring ℓ) where
AlgebrasCategory : Category (ℓ-suc (ℓ-max ℓ ℓ')) (ℓ-max ℓ ℓ')
ob AlgebrasCategory = Algebra R _
Hom[_,_] AlgebrasCategory = AlgebraHom
id AlgebrasCategory {A} = idAlgebraHom A
_⋆_ AlgebrasCategory = compAlgebraHom
⋆IdL AlgebrasCategory = compIdAlgebraHom
⋆IdR AlgebrasCategory = idCompAlgebraHom
⋆Assoc AlgebrasCategory = compAssocAlgebraHom
isSetHom AlgebrasCategory = isSetAlgebraHom _ _
|
{
"alphanum_fraction": 0.7590966123,
"avg_line_length": 27.4827586207,
"ext": "agda",
"hexsha": "3d84499ce129672577d60e93ffc5685cc5ef34dc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Categories/Instances/RingAlgebras.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Categories/Instances/RingAlgebras.agda",
"max_line_length": 63,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Categories/Instances/RingAlgebras.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 251,
"size": 797
}
|
open import Signature
module Program (Σ : Sig) (V : Set) where
open import Function
open import Data.Empty
open import Data.Unit
open import Data.Product as Prod renaming (Σ to ⨿)
open import Data.Nat
open import Data.Fin
open import Data.List
open import Terms Σ
FinFam : Set → Set
FinFam X = ⨿ ℕ λ n → (Fin n → X)
dom : ∀{X} → FinFam X → Set
dom (n , _) = Fin n
get : ∀{X} (F : FinFam X) → dom F → X
get (_ , f) k = f k
domEmpty : ∀{X} → FinFam X → Set
domEmpty (zero , _) = ⊤
domEmpty (suc _ , _) = ⊥
record Clause : Set where
constructor _⊢_
field
body : FinFam (T V)
head : T V
open Clause public
-- | A program consists of two finite sets of inductive and coinductive clauses.
Program : Set
Program = FinFam Clause × FinFam Clause
dom-μ : Program → Set
dom-μ = dom ∘ proj₁
dom-ν : Program → Set
dom-ν = dom ∘ proj₂
geth-μ : (P : Program) → dom-μ P → T V
geth-μ P = head ∘ get (proj₁ P)
getb-μ : (P : Program) → dom-μ P → FinFam (T V)
getb-μ P = body ∘ get (proj₁ P)
geth-ν : (P : Program) → dom-ν P → T V
geth-ν P = head ∘ get (proj₂ P)
getb-ν : (P : Program) → dom-ν P → FinFam (T V)
getb-ν P = body ∘ get (proj₂ P)
|
{
"alphanum_fraction": 0.627826087,
"avg_line_length": 20.9090909091,
"ext": "agda",
"hexsha": "eec07889d6b27d394d1b08b8b22d5d8cb1adf683",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "LP/Program.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hbasold/Sandbox",
"max_issues_repo_path": "LP/Program.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "LP/Program.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 438,
"size": 1150
}
|
-- Andreas, 2017-04-24, issue #2552
-- Let bindings in top-level module telescope
-- make top-level interactive commands crash.
-- {-# OPTIONS -v interaction.top:20 #-}
open import Agda.Primitive
module _ (let foo = lzero) (A : Set) where
-- C-c C-n A
-- WAS:
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/Interaction/BasicOps.hs:882
-- Should work now
-- Still problematic:
-- C-c C-n foo
-- Panic: unbound variable foo
-- when inferring the type of foo
|
{
"alphanum_fraction": 0.6967370441,
"avg_line_length": 21.7083333333,
"ext": "agda",
"hexsha": "69b14ebd050abbe765d9d8a3f7ece2e289e66267",
"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/Issue2552.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/Issue2552.agda",
"max_line_length": 67,
"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/Issue2552.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": 144,
"size": 521
}
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.RingSolver.RawAlgebra where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.Int renaming (_+_ to _+ℤ_ ; _·_ to _·ℤ_ ; -_ to -ℤ_ ; _-_ to _-ℤ_ ; +Assoc to +ℤAssoc ; +Comm to +ℤComm ; -DistL· to -ℤDistL·ℤ)
open import Cubical.Algebra.RingSolver.RawRing renaming (⟨_⟩ to ⟨_⟩ᵣ)
open import Cubical.Algebra.RingSolver.IntAsRawRing
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Ring
private
variable
ℓ ℓ′ : Level
record RawAlgebra (R : RawRing ℓ) (ℓ′ : Level) : Type (ℓ-suc (ℓ-max ℓ ℓ′)) where
constructor rawalgebra
field
Carrier : Type ℓ′
scalar : ⟨ R ⟩ᵣ → Carrier
0r : Carrier
1r : Carrier
_+_ : Carrier → Carrier → Carrier
_·_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
infixl 8 _·_
infixl 7 -_
infixl 6 _+_
⟨_⟩ : {R : RawRing ℓ} → RawAlgebra R ℓ′ → Type ℓ′
⟨_⟩ = RawAlgebra.Carrier
{-
Mapping to integer scalars and its (homorphism) properties.
-}
module _ (R : CommRing ℓ) where
open CommRingStr (snd R)
open Cubical.Algebra.Ring.RingTheory (CommRing→Ring R)
scalarℕ : ℕ → (fst R)
scalarℕ ℕ.zero = 0r
scalarℕ (ℕ.suc ℕ.zero) = 1r
scalarℕ (ℕ.suc (ℕ.suc n)) = 1r + scalarℕ (ℕ.suc n)
scalar : ℤ → (fst R)
scalar (pos k) = scalarℕ k
scalar (negsuc k) = - scalarℕ (ℕ.suc k)
-DistScalar : (k : ℤ)
→ scalar (-ℤ k) ≡ - (scalar k)
-DistScalar (pos ℕ.zero) = sym 0Selfinverse
-DistScalar (pos (ℕ.suc n)) = refl
-DistScalar (negsuc n) = sym (-Idempotent _)
lemmaSuc : (k : ℤ)
→ scalar (sucℤ k) ≡ 1r + scalar k
lemmaSuc (pos ℕ.zero) = sym (+Rid _)
lemmaSuc (pos (ℕ.suc ℕ.zero)) = refl
lemmaSuc (pos (ℕ.suc (ℕ.suc n))) = refl
lemmaSuc (negsuc ℕ.zero) = sym (+Rinv _)
lemmaSuc (negsuc (ℕ.suc n)) =
scalar (negsuc n) ≡⟨ sym (+Lid (scalar (negsuc n))) ⟩
0r + scalar (negsuc n) ≡[ i ]⟨ +Rinv 1r (~ i) + scalar (negsuc n) ⟩
(1r - 1r) + scalar (negsuc n) ≡⟨ sym (+Assoc _ _ _) ⟩
1r + (- 1r + - scalar (pos (ℕ.suc n))) ≡[ i ]⟨ 1r + -Dist 1r (scalar (pos (ℕ.suc n))) i ⟩
1r + -(1r + scalar (pos (ℕ.suc n))) ≡⟨ refl ⟩
1r + -(scalar (pos (ℕ.suc (ℕ.suc n)))) ≡⟨ refl ⟩
1r + scalar (negsuc (ℕ.suc n)) ∎
lemmaPred : (k : ℤ)
→ scalar (predℤ k) ≡ - 1r + scalar k
lemmaPred k = sym(
- 1r + scalar k ≡[ i ]⟨ - 1r + scalar (sucPred k (~ i)) ⟩
- 1r + scalar (sucℤ (predℤ k)) ≡[ i ]⟨ - 1r + lemmaSuc (predℤ k) i ⟩
- 1r + (1r + scalar (predℤ k)) ≡⟨ +Assoc _ _ _ ⟩
(- 1r + 1r) + scalar (predℤ k) ≡[ i ]⟨ +Linv 1r i + scalar (predℤ k) ⟩
0r + scalar (predℤ k) ≡⟨ +Lid _ ⟩
scalar (predℤ k) ∎)
+HomScalar : (k l : ℤ)
→ scalar (k +ℤ l) ≡ (scalar k) + (scalar l)
+HomScalar (pos ℕ.zero) l =
scalar (0 +ℤ l) ≡[ i ]⟨ scalar (sym (pos0+ l) i) ⟩
scalar l ≡⟨ sym (+Lid _) ⟩
0r + scalar l ≡⟨ refl ⟩
scalar 0 + scalar l ∎
+HomScalar (pos (ℕ.suc ℕ.zero)) l =
scalar (1 +ℤ l) ≡[ i ]⟨ scalar (+ℤComm 1 l i) ⟩
scalar (l +ℤ 1) ≡⟨ refl ⟩
scalar (sucℤ l) ≡⟨ lemmaSuc l ⟩
1r + scalar l ≡⟨ refl ⟩
scalar (pos (ℕ.suc ℕ.zero)) + scalar l ∎
+HomScalar (pos (ℕ.suc (ℕ.suc n))) l =
scalar (pos (ℕ.suc (ℕ.suc n)) +ℤ l) ≡⟨ refl ⟩
scalar ((pos (ℕ.suc n) +ℤ 1) +ℤ l) ≡[ i ]⟨ scalar ((+ℤComm (pos (ℕ.suc n)) 1 i) +ℤ l) ⟩
scalar ((1 +ℤ (pos (ℕ.suc n))) +ℤ l) ≡[ i ]⟨ scalar (+ℤAssoc 1 (pos (ℕ.suc n)) l (~ i)) ⟩
scalar (1 +ℤ (pos (ℕ.suc n) +ℤ l)) ≡⟨ +HomScalar (pos (ℕ.suc ℕ.zero)) (pos (ℕ.suc n) +ℤ l) ⟩
scalar 1 + scalar (pos (ℕ.suc n) +ℤ l) ≡⟨ refl ⟩
1r + (scalar (pos (ℕ.suc n) +ℤ l)) ≡[ i ]⟨ 1r + +HomScalar (pos (ℕ.suc n)) l i ⟩
1r + (scalar (pos (ℕ.suc n)) + scalar l) ≡⟨ +Assoc _ _ _ ⟩
(1r + scalar (pos (ℕ.suc n))) + scalar l ≡⟨ refl ⟩
scalar (pos (ℕ.suc (ℕ.suc n))) + scalar l ∎
+HomScalar (negsuc ℕ.zero) l =
scalar (-1 +ℤ l) ≡[ i ]⟨ scalar (+ℤComm -1 l i) ⟩
scalar (l +ℤ -1) ≡⟨ refl ⟩
scalar (predℤ l) ≡⟨ lemmaPred l ⟩
- 1r + scalar l ≡⟨ refl ⟩
scalar -1 + scalar l ∎
+HomScalar (negsuc (ℕ.suc n)) l =
scalar (negsuc (ℕ.suc n) +ℤ l) ≡⟨ refl ⟩
scalar ((negsuc n +ℤ -1) +ℤ l) ≡[ i ]⟨ scalar (+ℤComm (negsuc n) -1 i +ℤ l) ⟩
scalar ((-1 +ℤ negsuc n) +ℤ l) ≡[ i ]⟨ scalar (+ℤAssoc -1 (negsuc n) l (~ i)) ⟩
scalar (-1 +ℤ (negsuc n +ℤ l)) ≡⟨ +HomScalar -1 (negsuc n +ℤ l) ⟩
- 1r + scalar (negsuc n +ℤ l) ≡[ i ]⟨ - 1r + +HomScalar (negsuc n) l i ⟩
- 1r + (scalar (negsuc n) + scalar l) ≡⟨ +Assoc (- 1r) _ _ ⟩
(- 1r + (scalar (negsuc n))) + scalar l ≡⟨ refl ⟩
(- 1r + - scalar (pos (ℕ.suc n))) + scalar l ≡[ i ]⟨ -Dist 1r (scalar (pos (ℕ.suc n))) i + scalar l ⟩
(- (1r + scalar (pos (ℕ.suc n)))) + scalar l ≡⟨ refl ⟩
scalar (negsuc (ℕ.suc n)) + scalar l ∎
lemma1 : (n : ℕ)
→ 1r + scalar (pos n) ≡ scalar (pos (ℕ.suc n))
lemma1 ℕ.zero = +Rid _
lemma1 (ℕ.suc k) = refl
lemma-1 : (n : ℕ)
→ - 1r + scalar (negsuc n) ≡ scalar (negsuc (ℕ.suc n))
lemma-1 ℕ.zero = -Dist _ _
lemma-1 (ℕ.suc k) =
- 1r + scalar (negsuc (ℕ.suc k)) ≡⟨ refl ⟩
- 1r + - scalar (pos (ℕ.suc (ℕ.suc k))) ≡⟨ -Dist _ _ ⟩
- (1r + scalar (pos (ℕ.suc (ℕ.suc k)))) ≡⟨ refl ⟩
scalar (negsuc (ℕ.suc (ℕ.suc k))) ∎
·HomScalar : (k l : ℤ)
→ scalar (k ·ℤ l) ≡ scalar k · scalar l
·HomScalar (pos ℕ.zero) l = 0r ≡⟨ sym (0LeftAnnihilates (scalar l)) ⟩ 0r · scalar l ∎
·HomScalar (pos (ℕ.suc n)) l =
scalar (l +ℤ (pos n ·ℤ l)) ≡⟨ +HomScalar l (pos n ·ℤ l) ⟩
scalar l + scalar (pos n ·ℤ l) ≡[ i ]⟨ scalar l + ·HomScalar (pos n) l i ⟩
scalar l + (scalar (pos n) · scalar l) ≡[ i ]⟨ ·Lid (scalar l) (~ i) + (scalar (pos n) · scalar l) ⟩
1r · scalar l + (scalar (pos n) · scalar l) ≡⟨ sym (·Ldist+ 1r _ _) ⟩
(1r + scalar (pos n)) · scalar l ≡[ i ]⟨ lemma1 n i · scalar l ⟩
scalar (pos (ℕ.suc n)) · scalar l ∎
·HomScalar (negsuc ℕ.zero) l =
scalar (-ℤ l) ≡⟨ -DistScalar l ⟩
- scalar l ≡[ i ]⟨ - (·Lid (scalar l) (~ i)) ⟩
- (1r · scalar l) ≡⟨ sym (-DistL· _ _) ⟩
- 1r · scalar l ≡⟨ refl ⟩
scalar (negsuc ℕ.zero) · scalar l ∎
·HomScalar (negsuc (ℕ.suc n)) l =
scalar ((-ℤ l) +ℤ (negsuc n ·ℤ l)) ≡⟨ +HomScalar (-ℤ l) (negsuc n ·ℤ l) ⟩
scalar (-ℤ l) + scalar (negsuc n ·ℤ l) ≡[ i ]⟨ -DistScalar l i + scalar (negsuc n ·ℤ l) ⟩
- scalar l + scalar (negsuc n ·ℤ l) ≡[ i ]⟨ - scalar l + ·HomScalar (negsuc n) l i ⟩
- scalar l + scalar (negsuc n) · scalar l ≡[ i ]⟨ (- ·Lid (scalar l) (~ i))
+ scalar (negsuc n) · scalar l ⟩
- (1r · scalar l) + scalar (negsuc n) · scalar l ≡[ i ]⟨ -DistL· 1r (scalar l) (~ i)
+ scalar (negsuc n) · scalar l ⟩
- 1r · scalar l + scalar (negsuc n) · scalar l ≡⟨ sym (·Ldist+ _ _ _) ⟩
(- 1r + scalar (negsuc n)) · scalar l ≡[ i ]⟨ lemma-1 n i · scalar l ⟩
scalar (negsuc (ℕ.suc n)) · scalar l ∎
CommRing→RawℤAlgebra : CommRing ℓ → RawAlgebra ℤAsRawRing ℓ
CommRing→RawℤAlgebra (R , commringstr 0r 1r _+_ _·_ -_ isCommRing) =
rawalgebra R (scalar ((R , commringstr 0r 1r _+_ _·_ -_ isCommRing))) 0r 1r _+_ _·_ -_
|
{
"alphanum_fraction": 0.4869143368,
"avg_line_length": 44.2542372881,
"ext": "agda",
"hexsha": "a0ba97aa6fb59304f4ef6ca45b36b8d28542ff47",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Algebra/RingSolver/RawAlgebra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Algebra/RingSolver/RawAlgebra.agda",
"max_line_length": 152,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Algebra/RingSolver/RawAlgebra.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3348,
"size": 7833
}
|
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Simply-typed changes (Fig. 3 and Fig. 4d)
------------------------------------------------------------------------
import Parametric.Syntax.Type as Type
module Parametric.Change.Type
(Base : Type.Structure)
where
open Type.Structure Base
-- Extension point: Simply-typed changes of base types.
Structure : Set
Structure = Base → Type
module Structure (ΔBase : Structure) where
-- We provide: Simply-typed changes on simple types.
ΔType : Type → Type
ΔType (base ι) = ΔBase ι
ΔType (σ ⇒ τ) = σ ⇒ ΔType σ ⇒ ΔType τ
-- And we also provide context merging.
open import Base.Change.Context ΔType public
|
{
"alphanum_fraction": 0.5710344828,
"avg_line_length": 26.8518518519,
"ext": "agda",
"hexsha": "295d1d912ae496a39acf28cc2e455e08d7e7f71b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Parametric/Change/Type.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Parametric/Change/Type.agda",
"max_line_length": 72,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Parametric/Change/Type.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 170,
"size": 725
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module homotopy.ModalWedgeExtension {i} (M : Modality i)
{A : Type i} {a₀ : A} {B : Type i} {b₀ : B} where
open Modality M
private
X = ⊙[ A , a₀ ]
Y = ⊙[ B , b₀ ]
open import homotopy.FiberOfWedgeToProduct X Y
record args : Type (lsucc i) where
field
join-conn : (a : A) (b : B) → is-◯-connected ((a₀ == a) * (b₀ == b))
R : A → B → ◯-Type
f : (a : A) → fst (R a b₀)
g : (b : B) → fst (R a₀ b)
p : f a₀ == g b₀
module _ (r : args) where
open args r
abstract
∨-to-×-is-◯-equiv : is-◯-equiv (∨-to-× {X = X} {Y = Y})
∨-to-×-is-◯-equiv (a , b) = equiv-preserves-◯-conn (fiber-thm a b ⁻¹) (join-conn a b)
module A∨BToR = WedgeElim f g
(↓-ap-out= (fst ∘ uncurry R) ∨-to-× wglue (∨-to-×-glue-β {X = X} {Y = Y}) p)
A∨B-to-R : ∀ w → fst (uncurry R (∨-to-× w))
A∨B-to-R = A∨BToR.f
ext : (a : A) → (b : B) → fst (R a b)
ext = curry $ ◯-extend ∨-to-×-is-◯-equiv (uncurry R) A∨B-to-R
module _ {r : args} where
open args r
abstract
β-l : (a : A) → ext r a b₀ == f a
β-l a = ◯-extend-β (∨-to-×-is-◯-equiv r) (uncurry R) (A∨B-to-R r) (winl a)
β-r : (b : B) → ext r a₀ b == g b
β-r b = ◯-extend-β (∨-to-×-is-◯-equiv r) (uncurry R) (A∨B-to-R r) (winr b)
coh : ! (β-l a₀) ∙ β-r b₀ == p
coh = ap (! (β-l a₀) ∙_) (! (∙'-unit-l (β-r b₀)) ∙ ! lemma₁)
∙ ! (∙-assoc (! (β-l a₀)) (β-l a₀) p)
∙ ap (_∙ p) (!-inv-l (β-l a₀))
where
-- maybe this has been proved somewhere?
lemma₀ : ∀ {i j k} {A : Type i} {B : Type j} (C : (b : B) → Type k)
(f : A → B) {x y} (p : x == y) {q : f x == f y} (r : ap f p == q)
{cx cx' : C (f x)} {cy cy' : C (f y)}
(s : cx' == cy' [ C ↓ q ]) (t : cx == cy [ C ↓ q ])
(u : cx == cx') (v : cy == cy')
→ u ◃ ↓-ap-out= C f p r s == ↓-ap-out= C f p r t ▹ v
→ u ◃ s == t ▹ v
lemma₀ C f idp idp idp idp u v u=v = u=v
lemma₁ : β-l a₀ ∙ p == idp ∙' β-r b₀
lemma₁ = lemma₀ (fst ∘ uncurry R) ∨-to-× wglue ∨-to-×-glue-β
p idp (β-l a₀) (β-r b₀)
( ap (β-l a₀ ◃_) (! (A∨BToR.glue-β r))
∙ ↓-=-out (apd (◯-extend-β (∨-to-×-is-◯-equiv r) (uncurry R) (A∨B-to-R r)) wglue)
∙ ap (_▹ β-r b₀)
(apd-∘'' (◯-extend (∨-to-×-is-◯-equiv r) (uncurry R) (A∨B-to-R r))
∨-to-× wglue ∨-to-×-glue-β))
|
{
"alphanum_fraction": 0.4236883943,
"avg_line_length": 35.4366197183,
"ext": "agda",
"hexsha": "0a570d4de5118202b994b7d218b0d709655fb896",
"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": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/ModalWedgeExtension.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"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": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/ModalWedgeExtension.agda",
"max_line_length": 93,
"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": "theorems/homotopy/ModalWedgeExtension.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": 1141,
"size": 2516
}
|
{-# OPTIONS --without-K --safe #-}
open import Level
-- This is really a degenerate version of Categories.Category.Instance.Zero
-- Here EmptySet is not given an explicit name, it is an alias for Lift o ⊥
module Categories.Category.Instance.EmptySet where
open import Data.Unit
open import Data.Empty using (⊥; ⊥-elim)
open import Function.Equality using (Π)
open Π using (_⟨$⟩_)
open import Relation.Binary using (Setoid)
open import Relation.Binary.PropositionalEquality using (refl)
open import Categories.Category.Instance.Sets
open import Categories.Category.Instance.Setoids
import Categories.Object.Initial as Init
module _ {o : Level} where
open Init (Sets o)
EmptySet-⊥ : Initial
EmptySet-⊥ = record { ⊥ = Lift o ⊥ ; ⊥-is-initial = record { ! = λ { {A} (lift x) → ⊥-elim x } ; !-unique = λ { f {()} } } }
module _ {c ℓ : Level} where
open Init (Setoids c ℓ)
EmptySetoid : Setoid c ℓ
EmptySetoid = record
{ Carrier = Lift c ⊥
; _≈_ = λ _ _ → Lift ℓ ⊤
}
EmptySetoid-⊥ : Initial
EmptySetoid-⊥ = record
{ ⊥ = EmptySetoid
; ⊥-is-initial = record
{ ! = record
{ _⟨$⟩_ = λ { () }
; cong = λ { {()} }
}
; !-unique = λ { _ {()} }
}
}
|
{
"alphanum_fraction": 0.6164931946,
"avg_line_length": 26.5744680851,
"ext": "agda",
"hexsha": "021f0ae6f38af81cfac77115dd1a70ea6cf3d6f9",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Instance/EmptySet.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Instance/EmptySet.agda",
"max_line_length": 126,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Instance/EmptySet.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 382,
"size": 1249
}
|
open import Data.Nat using ( ℕ )
module README ( n : ℕ ) where
------------------------------------------------------------------------------
-- Agda-Prop Library.
-- Deep Embedding for Propositional Logic.
------------------------------------------------------------------------------
open import Data.PropFormula n public
|
{
"alphanum_fraction": 0.3773006135,
"avg_line_length": 32.6,
"ext": "agda",
"hexsha": "d0c0673d7807830d72daa03b51cea3fc559f057b",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2017-12-01T17:01:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-03-30T16:41:56.000Z",
"max_forks_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jonaprieto/agda-prop",
"max_forks_repo_path": "README.agda",
"max_issues_count": 18,
"max_issues_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_issues_repo_issues_event_max_datetime": "2017-12-18T16:34:21.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-08T14:33:10.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jonaprieto/agda-prop",
"max_issues_repo_path": "README.agda",
"max_line_length": 78,
"max_stars_count": 13,
"max_stars_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jonaprieto/agda-prop",
"max_stars_repo_path": "README.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T03:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-01T16:45:41.000Z",
"num_tokens": 45,
"size": 326
}
|
{-
Technical results about elementary transformations
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.Matrix.Elementaries where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Data.Nat hiding (_+_ ; _·_)
open import Cubical.Data.Nat.Order
open import Cubical.Data.Empty as Empty
open import Cubical.Data.Bool
open import Cubical.Data.FinData renaming (znots to znotsFin ; snotz to snotzFin)
open import Cubical.Relation.Nullary
open import Cubical.Algebra.RingSolver.Reflection
open import Cubical.Algebra.Ring.BigOps
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Matrix
open import Cubical.Algebra.Matrix.CommRingCoefficient
open import Cubical.Algebra.Matrix.RowTransformation
private
variable
ℓ : Level
A : Type ℓ
m n k l : ℕ
module ElemTransformation (𝓡 : CommRing ℓ) where
private
R = 𝓡 .fst
open CommRingStr (𝓡 .snd) renaming ( is-set to isSetR )
open KroneckerDelta (CommRing→Ring 𝓡)
open Sum (CommRing→Ring 𝓡)
open Coefficient 𝓡
open LinearTransformation 𝓡
open SimRel
open Sim
open isLinear
open isLinear2×2
-- Swapping the first row with another
swapMat : Mat 2 2
swapMat zero zero = 0r
swapMat zero one = 1r
swapMat one zero = 1r
swapMat one one = 0r
uniSwapMat : swapMat ⋆ swapMat ≡ 𝟙
uniSwapMat t zero zero =
(mul2 swapMat swapMat zero zero ∙ helper) t
where helper : 0r · 0r + 1r · 1r ≡ 1r
helper = solve 𝓡
uniSwapMat t zero one =
(mul2 swapMat swapMat zero one ∙ helper) t
where helper : 0r · 1r + 1r · 0r ≡ 0r
helper = solve 𝓡
uniSwapMat t one zero =
(mul2 swapMat swapMat one zero ∙ helper) t
where helper : 1r · 0r + 0r · 1r ≡ 0r
helper = solve 𝓡
uniSwapMat t one one =
(mul2 swapMat swapMat one one ∙ helper) t
where helper : 1r · 1r + 0r · 0r ≡ 1r
helper = solve 𝓡
isInvSwapMat2 : isInv swapMat
isInvSwapMat2 .fst = swapMat
isInvSwapMat2 .snd .fst = uniSwapMat
isInvSwapMat2 .snd .snd = uniSwapMat
swapRow2 : Mat 2 n → Mat 2 n
swapRow2 M zero = M one
swapRow2 M one = M zero
isLinear2×2SwapRow2 : isLinear2×2 {n = n} swapRow2
isLinear2×2SwapRow2 .transMat _ = swapMat
isLinear2×2SwapRow2 .transEq M t zero j =
((mul2 swapMat M zero j) ∙ helper _ _) (~ t)
where helper : (a b : R) → 0r · a + 1r · b ≡ b
helper = solve 𝓡
isLinear2×2SwapRow2 .transEq M t one j =
((mul2 swapMat M one j) ∙ helper _ _) (~ t)
where helper : (a b : R) → 1r · a + 0r · b ≡ a
helper = solve 𝓡
swapRow : (i₀ : Fin m)(M : Mat (suc m) n) → Mat (suc m) n
swapRow i M zero = M (suc i)
swapRow zero M one = M zero
swapRow zero M (suc (suc i)) = M (suc (suc i))
swapRow (suc i₀) M one = M one
swapRow (suc i₀) M (suc (suc i)) = swapRow i₀ (takeRowsᶜ M) (suc i)
swapRowMat : (i₀ : Fin m) → Mat (suc m) (suc m)
swapRowMat = trans2RowsMat swapMat
swapRowEq : (i₀ : Fin m)(M : Mat (suc m) n) → swapRow i₀ M ≡ swapRowMat i₀ ⋆ M
swapRowEq {m = suc m} zero M t zero j =
(helper1 _ _
∙ (λ t → 0r · M zero j + ∑Mulr1 _ (λ i → M (suc i) j) zero (~ t))
∙ (λ t → 0r · M zero j + ∑ (λ i → helper2 (δ i zero) (M (suc i) j) t))) t
where helper1 : (a b : R) → b ≡ 0r · a + b
helper1 = solve 𝓡
helper2 : (a b : R) → b · a ≡ (1r · a) · b
helper2 = solve 𝓡
swapRowEq {m = suc m} zero M t one j =
(helper _
∙ (λ t → (1r · 1r) · M zero j + ∑Mul0r (λ i → M (suc i) j) (~ t))) t
where helper : (a : R) → a ≡ (1r · 1r) · a + 0r
helper = solve 𝓡
swapRowEq {m = suc m} zero M t (suc (suc i)) j =
(helper _ _
∙ (λ t → (1r · 0r) · M zero j + ∑Mul1r _ (λ l → M (suc l) j) (suc i) (~ t))) t
where helper : (a b : R) → b ≡ (1r · 0r) · a + b
helper = solve 𝓡
swapRowEq {m = suc m} (suc i₀) M t zero j =
(helper1 _ _
∙ (λ t → 0r · M zero j + ∑Mul1r _ (λ i → M (suc i) j) (suc i₀) (~ t))
∙ (λ t → 0r · M zero j + ∑ (λ l → helper2 (δ (suc i₀) l) (M (suc l) j) t))) t
where helper1 : (a b : R) → b ≡ 0r · a + b
helper1 = solve 𝓡
helper2 : (a b : R) → a · b ≡ (1r · a) · b
helper2 = solve 𝓡
swapRowEq {m = suc m} (suc i₀) M t one j =
(helper _ _ --helper1 _ _
∙ (λ t → (1r · 0r) · M zero j + ∑Mul1r _ (λ i → M (suc i) j) zero (~ t))) t
where helper : (a b : R) → b ≡ (1r · 0r) · a + b
helper = solve 𝓡
swapRowEq {m = suc m} (suc i₀) M t (suc (suc i)) j =
((λ t → swapRowEq i₀ (takeRowsᶜ M) t (suc i) j)
∙ helper _ (M one j) _) t
where helper : (a b c : R) → a + c ≡ a + (0r · b + c)
helper = solve 𝓡
isLinearSwapRow : (i : Fin m) → isLinear (swapRow {n = n} i)
isLinearSwapRow i .transMat _ = swapRowMat i
isLinearSwapRow i .transEq = swapRowEq i
isInvSwapMat : (i : Fin m)(M : Mat (suc m) (suc n)) → isInv (isLinearSwapRow i .transMat M)
isInvSwapMat i _ = isInvTrans2RowsMat _ i isInvSwapMat2
-- Similarity defined by swapping
record SwapFirstRow (i : Fin m)(M : Mat (suc m) (suc n)) : Type ℓ where
field
sim : Sim M
swapEq : (j : Fin (suc n)) → M (suc i) j ≡ sim .result zero j
record SwapFirstCol (j : Fin n)(M : Mat (suc m) (suc n)) : Type ℓ where
field
sim : Sim M
swapEq : (i : Fin (suc m)) → M i (suc j) ≡ sim .result i zero
record SwapPivot (i : Fin (suc m))(j : Fin (suc n))(M : Mat (suc m) (suc n)) : Type ℓ where
field
sim : Sim M
swapEq : M i j ≡ sim .result zero zero
open SwapFirstRow
open SwapFirstCol
open SwapPivot
swapFirstRow : (i : Fin m)(M : Mat (suc m) (suc n)) → SwapFirstRow i M
swapFirstRow i M .sim .result = swapRow i M
swapFirstRow i M .sim .simrel .transMatL = isLinearSwapRow i .transMat M
swapFirstRow i M .sim .simrel .transMatR = 𝟙
swapFirstRow i M .sim .simrel .transEq = isLinearSwapRow i .transEq _ ∙ sym (⋆rUnit _)
swapFirstRow i M .sim .simrel .isInvTransL = isInvSwapMat i M
swapFirstRow i M .sim .simrel .isInvTransR = isInv𝟙
swapFirstRow i M .swapEq j = refl
swapFirstCol : (j : Fin n)(M : Mat (suc m) (suc n)) → SwapFirstCol j M
swapFirstCol j M .sim .result = (swapRow j (M ᵗ))ᵗ
swapFirstCol j M .sim .simrel .transMatL = 𝟙
swapFirstCol j M .sim .simrel .transMatR = (isLinearSwapRow j .transMat (M ᵗ))ᵗ
swapFirstCol j M .sim .simrel .transEq =
let P = isLinearSwapRow j .transMat (M ᵗ) in
(λ t → (isLinearSwapRow j .transEq (M ᵗ) t)ᵗ)
∙ compᵗ P (M ᵗ)
∙ (λ t → idemᵗ M t ⋆ P ᵗ)
∙ (λ t → ⋆lUnit M (~ t) ⋆ P ᵗ)
swapFirstCol j M .sim .simrel .isInvTransL = isInv𝟙
swapFirstCol j M .sim .simrel .isInvTransR =
isInvᵗ {M = isLinearSwapRow j .transMat (M ᵗ)} (isInvSwapMat j (M ᵗ))
swapFirstCol j M .swapEq i t = M i (suc j)
swapPivot : (i : Fin (suc m))(j : Fin (suc n))(M : Mat (suc m) (suc n)) → SwapPivot i j M
swapPivot zero zero M .sim = idSim M
swapPivot zero zero M .swapEq = refl
swapPivot (suc i) zero M .sim = swapFirstRow i M .sim
swapPivot (suc i) zero M .swapEq = refl
swapPivot zero (suc j) M .sim = swapFirstCol j M .sim
swapPivot zero (suc j) M .swapEq = refl
swapPivot (suc i) (suc j) M .sim = compSim (swapFirstRow i M .sim) (swapFirstCol j _ .sim)
swapPivot (suc i) (suc j) M .swapEq = refl
-- Add the first row to another
addMat : Mat 2 2
addMat zero zero = 1r
addMat zero one = 0r
addMat one zero = 1r
addMat one one = 1r
subMat : Mat 2 2
subMat zero zero = 1r
subMat zero one = 0r
subMat one zero = - 1r
subMat one one = 1r
add⋆subMat : addMat ⋆ subMat ≡ 𝟙
add⋆subMat t zero zero =
(mul2 addMat subMat zero zero ∙ helper) t
where helper : 1r · 1r + 0r · - 1r ≡ 1r
helper = solve 𝓡
add⋆subMat t zero one =
(mul2 addMat subMat zero one ∙ helper) t
where helper : 1r · 0r + 0r · 1r ≡ 0r
helper = solve 𝓡
add⋆subMat t one zero =
(mul2 addMat subMat one zero ∙ helper) t
where helper : 1r · 1r + 1r · - 1r ≡ 0r
helper = solve 𝓡
add⋆subMat t one one =
(mul2 addMat subMat one one ∙ helper) t
where helper : 1r · 0r + 1r · 1r ≡ 1r
helper = solve 𝓡
sub⋆addMat : subMat ⋆ addMat ≡ 𝟙
sub⋆addMat t zero zero =
(mul2 subMat addMat zero zero ∙ helper) t
where helper : 1r · 1r + 0r · 1r ≡ 1r
helper = solve 𝓡
sub⋆addMat t zero one =
(mul2 subMat addMat zero one ∙ helper) t
where helper : 1r · 0r + 0r · 1r ≡ 0r
helper = solve 𝓡
sub⋆addMat t one zero =
(mul2 subMat addMat one zero ∙ helper) t
where helper : - 1r · 1r + 1r · 1r ≡ 0r
helper = solve 𝓡
sub⋆addMat t one one =
(mul2 subMat addMat one one ∙ helper) t
where helper : - 1r · 0r + 1r · 1r ≡ 1r
helper = solve 𝓡
isInvAddMat2 : isInv addMat
isInvAddMat2 .fst = subMat
isInvAddMat2 .snd .fst = add⋆subMat
isInvAddMat2 .snd .snd = sub⋆addMat
addRow2 : Mat 2 n → Mat 2 n
addRow2 M zero = M zero
addRow2 M one j = M zero j + M one j
isLinear2AddRow2 : isLinear2×2 {n = n} addRow2
isLinear2AddRow2 .transMat _ = addMat
isLinear2AddRow2 .transEq M t zero j =
((mul2 addMat M zero j) ∙ helper _ _) (~ t)
where helper : (a b : R) → 1r · a + 0r · b ≡ a
helper = solve 𝓡
isLinear2AddRow2 .transEq M t one j =
((mul2 addMat M one j) ∙ helper _ _) (~ t)
where helper : (a b : R) → 1r · a + 1r · b ≡ a + b
helper = solve 𝓡
-- Add the first row to all other rows
addRows : Mat (suc m) n → Mat (suc m) n
addRows M zero = M zero
addRows M (suc i) j = M zero j + M (suc i) j
private
firstRowStayInvariant : (M : Mat (suc m) n) → M zero ≡ transRows addRow2 M zero
firstRowStayInvariant = invRow₀ _ (λ _ → refl)
addRowsEq : (M : Mat (suc m) n) → transRows addRow2 M ≡ addRows M
addRowsEq M t zero = firstRowStayInvariant M (~ t)
addRowsEq M t one j = M zero j + M one j
addRowsEq M t (suc (suc i)) j = takeCombShufRows addRow2 (λ N → addRowsEq N t) M (suc (suc i)) j
isLinearAddRows : isLinear (addRows {m = m} {n = suc n})
isLinearAddRows =
let isLinear = isLinearTransRows _ isLinear2AddRow2 _
in record
{ transMat = isLinear .transMat
; transEq = (λ M → sym (addRowsEq M) ∙ isLinear .transEq M) }
isInvAddRows : (M : Mat (suc m) (suc n)) → isInv (isLinearAddRows .transMat M)
isInvAddRows = isInvTransRows _ _ (λ _ → isInvAddMat2)
-- Similarity defined by adding rows
record AddFirstRow (M : Mat (suc m) (suc n)) : Type ℓ where
field
sim : Sim M
inv₀ : M zero ≡ sim .result zero
addEq : (i : Fin m)(j : Fin (suc n)) → M zero j + M (suc i) j ≡ sim .result (suc i) j
open AddFirstRow
addFirstRow : (M : Mat (suc m) (suc n)) → AddFirstRow M
addFirstRow M .sim .result = addRows M
addFirstRow M .sim .simrel .transMatL = isLinearAddRows .transMat M
addFirstRow M .sim .simrel .transMatR = 𝟙
addFirstRow M .sim .simrel .transEq = isLinearAddRows .transEq _ ∙ sym (⋆rUnit _)
addFirstRow M .sim .simrel .isInvTransL = isInvAddRows M
addFirstRow M .sim .simrel .isInvTransR = isInv𝟙
addFirstRow M .inv₀ = refl
addFirstRow M .addEq i j = refl
|
{
"alphanum_fraction": 0.603205699,
"avg_line_length": 34.7678018576,
"ext": "agda",
"hexsha": "c8c07c7e18c403df4d945c4ec5a6667994b2a12f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Algebra/Matrix/Elementaries.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Algebra/Matrix/Elementaries.agda",
"max_line_length": 98,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Algebra/Matrix/Elementaries.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4560,
"size": 11230
}
|
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Coproduct
open import lib.types.Paths
open import lib.types.Pointed
open import lib.types.Pushout
open import lib.types.PushoutFlattening
open import lib.types.Span
open import lib.types.Unit
-- Wedge of two pointed types is defined as a particular case of pushout
module lib.types.Wedge where
module _ {i j} (X : Ptd i) (Y : Ptd j) where
wedge-span : Span
wedge-span = span (fst X) (fst Y) Unit (λ _ → snd X) (λ _ → snd Y)
Wedge : Type (lmax i j)
Wedge = Pushout wedge-span
infix 80 _∨_
_∨_ = Wedge
module _ {i j} {X : Ptd i} {Y : Ptd j} where
winl : fst X → X ∨ Y
winl x = left x
winr : fst Y → X ∨ Y
winr y = right y
wglue : winl (snd X) == winr (snd Y)
wglue = glue tt
module _ {i j} (X : Ptd i) (Y : Ptd j) where
⊙Wedge : Ptd (lmax i j)
⊙Wedge = ⊙[ Wedge X Y , winl (snd X) ]
infix 80 _⊙∨_
_⊙∨_ = ⊙Wedge
module _ {i j} {X : Ptd i} {Y : Ptd j} where
⊙winl : fst (X ⊙→ X ⊙∨ Y)
⊙winl = (winl , idp)
⊙winr : fst (Y ⊙→ X ⊙∨ Y)
⊙winr = (winr , ! wglue)
module _ {i j} {X : Ptd i} {Y : Ptd j} where
module WedgeElim {k} {P : X ∨ Y → Type k}
(winl* : (x : fst X) → P (winl x)) (winr* : (y : fst Y) → P (winr y))
(wglue* : winl* (snd X) == winr* (snd Y) [ P ↓ wglue ]) where
private
module M = PushoutElim winl* winr* (λ _ → wglue*)
f = M.f
glue-β = M.glue-β unit
open WedgeElim public using () renaming (f to Wedge-elim)
module WedgeRec {k} {C : Type k} (winl* : fst X → C) (winr* : fst Y → C)
(wglue* : winl* (snd X) == winr* (snd Y)) where
private
module M = PushoutRec {d = wedge-span X Y} winl* winr* (λ _ → wglue*)
f = M.f
glue-β = M.glue-β unit
add-wglue : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ fst (X ⊙⊔ Y) → X ∨ Y
add-wglue (inl x) = winl x
add-wglue (inr y) = winr y
⊙add-wglue : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ fst (X ⊙⊔ Y ⊙→ X ⊙∨ Y)
⊙add-wglue = (add-wglue , idp)
module ⊙WedgeRec {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(g : fst (X ⊙→ Z)) (h : fst (Y ⊙→ Z)) where
open WedgeRec (fst g) (fst h) (snd g ∙ ! (snd h)) public
⊙f : fst (X ⊙∨ Y ⊙→ Z)
⊙f = (f , snd g)
⊙winl-β : ⊙f ⊙∘ ⊙winl == g
⊙winl-β = idp
⊙winr-β : ⊙f ⊙∘ ⊙winr == h
⊙winr-β = ⊙λ= (λ _ → idp) $
ap (λ w → w ∙ snd g)
(ap-! f wglue ∙ ap ! glue-β ∙ !-∙ (snd g) (! (snd h)))
∙ ∙-assoc (! (! (snd h))) (! (snd g)) (snd g)
∙ ap (λ w → ! (! (snd h)) ∙ w) (!-inv-l (snd g))
∙ ∙-unit-r (! (! (snd h)))
∙ !-! (snd h)
⊙wedge-rec = ⊙WedgeRec.⊙f
⊙wedge-rec-post∘ : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}
(k : fst (Z ⊙→ W)) (g : fst (X ⊙→ Z)) (h : fst (Y ⊙→ Z))
→ k ⊙∘ ⊙wedge-rec g h == ⊙wedge-rec (k ⊙∘ g) (k ⊙∘ h)
⊙wedge-rec-post∘ k g h = ⊙λ=
(Wedge-elim (λ _ → idp) (λ _ → idp)
(↓-='-in $ ⊙WedgeRec.glue-β (k ⊙∘ g) (k ⊙∘ h)
∙ lemma (fst k) (snd g) (snd h) (snd k)
∙ ! (ap (ap (fst k)) (⊙WedgeRec.glue-β g h))
∙ ∘-ap (fst k) (fst (⊙wedge-rec g h)) wglue))
idp
where
lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {x y z : A} {w : B}
(p : x == z) (q : y == z) (r : f z == w)
→ (ap f p ∙ r) ∙ ! (ap f q ∙ r) == ap f (p ∙ ! q)
lemma f idp idp idp = idp
⊙wedge-rec-η : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ ⊙wedge-rec ⊙winl ⊙winr == ⊙idf (X ⊙∨ Y)
⊙wedge-rec-η = ⊙λ=
(Wedge-elim (λ _ → idp) (λ _ → idp)
(↓-='-in $ ap-idf wglue
∙ ! (!-! wglue)
∙ ! (⊙WedgeRec.glue-β ⊙winl ⊙winr)))
idp
module Fold {i} {X : Ptd i} = ⊙WedgeRec (⊙idf X) (⊙idf X)
fold = Fold.f
⊙fold = Fold.⊙f
module _ {i j} (X : Ptd i) (Y : Ptd j) where
module Projl = ⊙WedgeRec (⊙idf X) (⊙cst {X = Y})
module Projr = ⊙WedgeRec (⊙cst {X = X}) (⊙idf Y)
projl = Projl.f
projr = Projr.f
⊙projl = Projl.⊙f
⊙projr = Projr.⊙f
|
{
"alphanum_fraction": 0.497005988,
"avg_line_length": 25.9527027027,
"ext": "agda",
"hexsha": "a1ccb9059f0c41de457aadd344d110c378062d53",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "lib/types/Wedge.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "lib/types/Wedge.agda",
"max_line_length": 78,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "lib/types/Wedge.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 1849,
"size": 3841
}
|
open import Categories
open import Monads
module Monads.Kleisli.Adjunction {a b}{C : Cat {a}{b}}(M : Monad C) where
open Cat C
open Monad M
open import Library
open import Functors
open import Monads.Kleisli M
open import Adjunctions
open import Monads.Kleisli.Functors M
open Fun
KlAdj : Adj C Kl
KlAdj = record {
L = KlL;
R = KlR;
left = id;
right = id;
lawa = λ _ → refl;
lawb = λ _ → refl;
natleft = lem;
natright = lem}
where
lem = λ {X}{X'}{Y}{Y'} (f : Hom X' X)(g : Hom Y (T Y')) h →
proof
comp (bind g) (comp h f)
≅⟨ cong (λ h → comp (bind g) (comp h f)) (sym law2) ⟩
comp (bind g) (comp (comp (bind h) η) f)
≅⟨ cong (comp (bind g)) ass ⟩
comp (bind g) (comp (bind h) (comp η f))
∎
|
{
"alphanum_fraction": 0.5719794344,
"avg_line_length": 22.2285714286,
"ext": "agda",
"hexsha": "1b4e9d072b017a146fff5503097e06fae56c9bf3",
"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/Kleisli/Adjunction.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/Kleisli/Adjunction.agda",
"max_line_length": 73,
"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/Kleisli/Adjunction.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": 298,
"size": 778
}
|
------------------------------------------------------------------------------
-- Conversion rules for the Collatz function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.Collatz.ConversionRulesATP where
open import FOT.FOTC.Program.Collatz.CollatzConditionals
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.UnaryNumbers
open import FOTC.Program.Collatz.Data.Nat
------------------------------------------------------------------------------
-- Conversion rules for the Collatz function.
postulate
collatz-0 : collatz 0' ≡ 1'
collatz-1 : collatz 1' ≡ 1'
collatz-even : ∀ {n} → Even (succ₁ (succ₁ n)) →
collatz (succ₁ (succ₁ n)) ≡
collatz (div (succ₁ (succ₁ n)) 2')
collatz-noteven : ∀ {n} → NotEven (succ₁ (succ₁ n)) →
collatz (succ₁ (succ₁ n)) ≡
collatz (3' * (succ₁ (succ₁ n)) + 1')
{-# ATP prove collatz-0 #-}
{-# ATP prove collatz-1 #-}
{-# ATP prove collatz-even #-}
{-# ATP prove collatz-noteven #-}
|
{
"alphanum_fraction": 0.4830575256,
"avg_line_length": 37.3235294118,
"ext": "agda",
"hexsha": "b8984c4bcb64bce5455c42072ed5b5fc846c417e",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/FOTC/Program/Collatz/ConversionRulesATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/FOTC/Program/Collatz/ConversionRulesATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/FOTC/Program/Collatz/ConversionRulesATP.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": 307,
"size": 1269
}
|
module Untyped.Main where
open import Function
open import Data.Nat
open import Data.Unit
open import Data.Product
open import Data.List
open import Data.Sum
open import Category.Monad
open import Strict
open import Untyped.Monads
open import Untyped.Abstract
open M
-- the monad in which we interpret expressions into command trees
M : Set → Set
M = ReaderT Env (Free Cmd ⟦_⟧)
record ServerState : Set where
constructor server
field
threads : ThreadPool
nextChan : ℕ
links : List ℕ
queues : List (List Val)
empty : ServerState
empty = record { threads = []; links = []; queues = []; nextChan = 0 }
SchedM : Set → Set
SchedM = StateT ServerState id
SchedM? : Set → Set
SchedM? = ExceptT Blocked (StateT ServerState id)
instance
free-monad' = free-monad
{- The monad that interprets expressions into threads -}
m-monad : RawMonad M
m-monad = reader-monad Env (Free Cmd ⟦_⟧) ⦃ free-monad ⦄
m-reader : MonadReader M Env
m-reader = record
{ ask = Free.pure
; local = λ f c E → c (f E) }
m-comm : MonadComm M Chan Val
m-comm = record
{ recv = λ c E → impure (inj₁ (Comm.recv c)) Free.pure
; send = λ c v E → impure (inj₁ (Comm.send c v)) Free.pure
; close = λ c E → impure (inj₁ (Comm.clos c)) Free.pure }
m-res : MonadResumption M Closure Chan
m-res = record
{ yield = λ _ → impure (inj₂ Threading.yield) Free.pure
; fork = λ clos _ → impure (inj₂ (Threading.fork clos)) Free.pure }
{- The monad that executes threads -}
s-monad : RawMonad SchedM
s-monad = state-monad ServerState id ⦃ id-monad ⦄
s-state : MonadState SchedM ServerState
s-state = state-monad-state ServerState id ⦃ id-monad ⦄
s-thread-state : MonadState SchedM ThreadPool
s-thread-state = focus-monad-state
ServerState.threads
(λ thr s → record s { threads = thr })
s-state
s-writer : MonadWriter SchedM ThreadPool
s-writer = record
{ write = λ pool → do
modify λ st → record st { threads = ServerState.threads st ++ pool }
return tt
}
s?-monad : RawMonad SchedM?
s?-monad = except-monad
s?-monad-except : MonadExcept SchedM? Blocked
s?-monad-except = except-monad-except
newChan : SchedM (Chan × Chan)
newChan = do
c ← gets ServerState.nextChan
let left = c
let right = c + 1
modify (λ st → record st
{ nextChan = c + 2
; links = ServerState.links st ++ (right ∷ left ∷ [])
; queues = ServerState.queues st ++ ([] ∷ [] ∷ []) })
return (left , right)
instance
s-comm : MonadComm SchedM? ℕ Val
s-comm = record
{ recv = λ ch → do
queue ← gets (unsafeLookup ch ∘ ServerState.queues)
case queue of λ where
[] → throw blocked
(x ∷ xs) → do
modify λ st →
(record st { queues = unsafeUpdate ch (ServerState.queues st) xs})
return x
; send = λ ch v → do
ch⁻¹ ← gets (unsafeLookup ch ∘ ServerState.links)
queue ← gets (unsafeLookup ch⁻¹ ∘ ServerState.queues)
modify λ st →
record st { queues = unsafeUpdate ch⁻¹ (ServerState.queues st) (queue ∷ʳ v) }
return tt
; close = λ ch → do
return tt
}
s-res : MonadResumption SchedM? Closure Chan
s-res = record
{ yield = return tt
; fork = λ where
⟨ env ⊢ e ⟩ →
do
(l , r) ← newChan
schedule [ thread $ eval ⦃ m-monad ⦄ e (extend (chan l) env) ]
return r
}
handler : (c : Cmd) → Cont Cmd ⟦_⟧ c Val → SchedM ⊤
handler c k s =
let (s' , r) = handle {SchedM?} c s in
case r of λ where
(exc e) → schedule [ thread (impure c k) ] s' -- reschedule
(✓ v) → schedule [ thread (k v) ] s'
atomic : Thread → SchedM ⊤
atomic (thread (Free.pure x)) = return tt
atomic (thread (impure cmd x)) = handler cmd x
run : Exp → ℕ
run e =
let
main = thread $ eval e []
(s , v) = robin ⦃ s-monad ⦄ atomic (record empty { threads = [ main ]})
in case (ServerState.threads s) of λ where
[] → 0
_ → 1
example : Exp
example =
let
slave = ƛ (Exp.send (var 0) (nat 3))
master = Exp.receive (Exp.fork slave)
in master
import IO
main = do
let val = run example
case val of λ where
0 → IO.run (IO.putStrLn "done!")
_ → IO.run (IO.putStrLn "?!")
|
{
"alphanum_fraction": 0.5923408112,
"avg_line_length": 26.1124260355,
"ext": "agda",
"hexsha": "f14f21e6378189bd8b649f3e6b15f63e9f357c46",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z",
"max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/linear.agda",
"max_forks_repo_path": "src/Untyped/Main.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "laMudri/linear.agda",
"max_issues_repo_path": "src/Untyped/Main.agda",
"max_line_length": 95,
"max_stars_count": 34,
"max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/linear.agda",
"max_stars_repo_path": "src/Untyped/Main.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z",
"num_tokens": 1377,
"size": 4413
}
|
module _ where
data Sigma (A : Set)(B : A → Set) : Set where
_,_ : (x : A) → B x → Sigma A B
record Top : Set where
_o_ : {A B : Set}{C : Set1} →
(f : B → C) → (g : A → B) → (A → C)
f o g = \ x → f (g x)
mutual
data U : Set where
top : U
sig : (X : U) → (T X → U) → U
T : U → Set
T top = Top
T (sig a b) = Sigma (T a) (T o b)
|
{
"alphanum_fraction": 0.4369747899,
"avg_line_length": 17,
"ext": "agda",
"hexsha": "3906b24d5e03224d32031bd172ad0479b609748a",
"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/Issue695.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/Issue695.agda",
"max_line_length": 45,
"max_stars_count": 2,
"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/Issue695.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 160,
"size": 357
}
|
open import Agda.Builtin.IO
open import Agda.Builtin.Unit
record Box (A : Set) : Set where
field
unbox : A
open Box public
record R : Set where
coinductive
field
force : Box R
open R public
r : R
unbox (force r) = r
postulate
seq : {A B : Set} → A → B → B
return : {A : Set} → A → IO A
{-# COMPILE GHC return = \_ -> return #-}
{-# COMPILE GHC seq = \_ _ -> seq #-}
main : IO ⊤
main = seq r (return tt)
|
{
"alphanum_fraction": 0.5795454545,
"avg_line_length": 15.1724137931,
"ext": "agda",
"hexsha": "00507814696ccde5dc48283d1f1872245f6f79a7",
"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/Issue2909-1.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Compiler/simple/Issue2909-1.agda",
"max_line_length": 43,
"max_stars_count": 7,
"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/Issue2909-1.agda",
"max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z",
"num_tokens": 151,
"size": 440
}
|
module Selective.Examples.ChatAO where
open import Selective.ActorMonad
open import Selective.Libraries.Channel
open import Selective.Libraries.Call2
open import Selective.Libraries.ActiveObjects
open import Prelude
hiding (Maybe)
open import Data.Maybe as Maybe
hiding (map)
open import Data.List.Properties
open import Category.Monad
open import Debug
open import Data.Nat.Show using (show)
RoomName = ℕ
ClientName = ℕ
Room-to-Client : InboxShape
record Client : Set where
field
name : ClientName
channel : UniqueTag
ClientList : Set
ClientList = List Client
record RoomState : Set₁ where
field
clients : ClientList
cl-to-context : ClientList → TypingContext
cl-to-context = map λ _ → Room-to-Client
rs-to-context : RoomState → TypingContext
rs-to-context rs = let open RoomState
in cl-to-context (rs .clients)
record ChatMessageContent : Set where
constructor chat-from_message:_
field
sender : ClientName
message : String
SendChatMessage : MessageType
SendChatMessage = [ ValueType ChatMessageContent ]ˡ
ReceiveChatMessage : MessageType
ReceiveChatMessage = ValueType UniqueTag ∷ [ ValueType ChatMessageContent ]ˡ
chat-message-header : ActiveMethod
chat-message-header = VoidMethod [ SendChatMessage ]ˡ
Room-to-Client = [ ReceiveChatMessage ]ˡ
AddToRoom : MessageType
AddToRoom = ValueType UniqueTag ∷ ValueType ClientName ∷ [ ReferenceType Room-to-Client ]ˡ
add-to-room-header : ActiveMethod
add-to-room-header = VoidMethod [ AddToRoom ]ˡ
LeaveRoom : MessageType
LeaveRoom = [ ValueType ClientName ]ˡ
leave-room-header : ActiveMethod
leave-room-header = VoidMethod [ LeaveRoom ]ˡ
room-methods : List ActiveMethod
room-methods = chat-message-header ∷ leave-room-header ∷ [ add-to-room-header ]ˡ
room-inbox = methods-shape room-methods
add-to-room : (active-method room-inbox RoomState rs-to-context add-to-room-header)
add-to-room _ (Msg Z (tag ∷ client-name ∷ _ ∷ [])) state = do
let
open RoomState
state' = record { clients = record { name = client-name ; channel = tag } ∷ state .clients }
strengthen (Z ∷ ⊆-refl)
return₁ state'
add-to-room _ (Msg (S ()) _)
record RoomLeave (rs : ClientList) (name : ClientName) : Set₁ where
field
filtered : ClientList
subs : (cl-to-context filtered) ⊆ (cl-to-context rs)
leave-room : (active-method room-inbox RoomState rs-to-context leave-room-header)
leave-room _ (Msg Z (client-name ∷ [])) state = do
let
open RoomState
open RoomLeave
rl = remove-first-client (state .clients) client-name
state' = record { clients = rl .filtered }
debug ("client#" || show client-name || " left the room") (strengthen (rl .subs))
return₁ state'
where
remove-first-client : (cl : ClientList) → (name : ClientName) → RoomLeave cl name
remove-first-client [] name = record { filtered = [] ; subs = [] }
remove-first-client (x ∷ cl) name with ((Client.name x) ≟ name)
... | (yes _) = record { filtered = cl ; subs = ⊆-suc ⊆-refl }
... | (no _) =
let
rec = remove-first-client cl name
open RoomLeave
in record { filtered = x ∷ rec .filtered ; subs = Z ∷ ⊆-suc (rec .subs) }
leave-room _ (Msg (S ()) _) _
chat-message : (active-method room-inbox RoomState rs-to-context chat-message-header)
chat-message _ (Msg Z ((chat-from sender message: message) ∷ [])) state = do
let
open RoomState
debug-msg = ("room sending " || show (pred (length (state .clients))) || " messages from " || show sender || ": " || message)
debug debug-msg (send-to-others (state .clients) sender message)
return₁ state
where
++-temp-fix : (l r : ClientList) → (x : Client) → (l ++ (x ∷ r)) ≡ ((l ∷ʳ x) ++ r)
++-temp-fix [] r x = refl
++-temp-fix (x₁ ∷ l) r x = cong (_∷_ x₁) (++-temp-fix l r x)
send-to-others : ∀ {i} → (cl : ClientList) →
ClientName →
String →
∞ActorM i room-inbox ⊤₁ (cl-to-context cl) (λ _ → cl-to-context cl)
send-to-others [] _ _ = return _
send-to-others cl@(_ ∷ _) name message = send-loop [] cl
where
build-pointer : (l r : ClientList) →
cl-to-context r ⊢ Room-to-Client →
(cl-to-context (l ++ r)) ⊢ Room-to-Client
build-pointer [] r p = p
build-pointer (x ∷ l) r p = S (build-pointer l r p)
recurse : ∀ {i} → (l r : ClientList) → (x : Client) →
∞ActorM i room-inbox ⊤₁ (cl-to-context (l ++ (x ∷ r))) (λ _ → (cl-to-context (l ++ (x ∷ r))))
send-loop : ∀ {i} → (l r : ClientList) →
∞ActorM i room-inbox ⊤₁ (cl-to-context (l ++ r)) (λ _ → cl-to-context (l ++ r))
send-loop l [] = return _
send-loop l (x ∷ r) with ((Client.name x) ≟ name)
... | (yes _) = recurse l r x
... | (no _) = let p = build-pointer l (x ∷ r) Z
in debug ("Sending to " || show (Client.name x) || ": " || message) (p ![t: Z ] (lift (Client.channel x) ∷ [ lift (chat-from name message: message) ]ᵃ) ) >> recurse l r x
recurse l r x rewrite ++-temp-fix l r x = send-loop (l ∷ʳ x) r
chat-message _ (Msg (S ()) _) _
room : ActiveObject
room = record {
state-type = RoomState
; vars = rs-to-context
; methods = room-methods
; extra-messages = []
; handlers = chat-message ∷ leave-room ∷ [ add-to-room ]ᵃ
}
Client-to-Room : InboxShape
Client-to-Room = SendChatMessage ∷ [ LeaveRoom ]ˡ
-- =============
-- JOIN ROOM
-- =============
data JoinRoomSuccess : Set where
JR-SUCCESS : RoomName → JoinRoomSuccess
data JoinRoomFail : Set where
JR-FAIL : RoomName → JoinRoomFail
data JoinRoomStatus : Set where
JRS-SUCCESS JRS-FAIL : RoomName → JoinRoomStatus
JoinRoomSuccessReply : MessageType
JoinRoomSuccessReply = ValueType UniqueTag ∷ ValueType JoinRoomSuccess ∷ [ ReferenceType Client-to-Room ]ˡ
JoinRoomFailReply : MessageType
JoinRoomFailReply = ValueType UniqueTag ∷ [ ValueType JoinRoomFail ]ˡ
JoinRoomReplyInterface : InboxShape
JoinRoomReplyInterface = JoinRoomSuccessReply ∷ JoinRoomFailReply ∷ Room-to-Client
JoinRoom : MessageType
JoinRoom = ValueType UniqueTag ∷ ReferenceType JoinRoomReplyInterface ∷ ValueType RoomName ∷ [ ValueType ClientName ]ˡ
-- =============
-- CREATE ROOM
-- =============
data CreateRoomResult : Set where
CR-SUCCESS CR-EXISTS : RoomName → CreateRoomResult
CreateRoomReply : MessageType
CreateRoomReply = ValueType UniqueTag ∷ [ ValueType CreateRoomResult ]ˡ
CreateRoom : MessageType
CreateRoom = ValueType UniqueTag ∷ ReferenceType [ CreateRoomReply ]ˡ ∷ [ ValueType RoomName ]ˡ
-- ============
-- LIST ROOMS
-- ============
RoomList : Set
RoomList = List RoomName
ListRoomsReply : MessageType
ListRoomsReply = ValueType UniqueTag ∷ [ ValueType RoomList ]ˡ
ListRooms : MessageType
ListRooms = ValueType UniqueTag ∷ [ ReferenceType [ ListRoomsReply ]ˡ ]ˡ
-- ===
--
-- ===
Client-to-RoomManager : InboxShape
Client-to-RoomManager = JoinRoom ∷ CreateRoom ∷ [ ListRooms ]ˡ
RoomManagerInterface : InboxShape
RoomManagerInterface = Client-to-RoomManager
GetRoomManagerReply : MessageType
GetRoomManagerReply = ValueType UniqueTag ∷ [ ReferenceType RoomManagerInterface ]ˡ
GetRoomManager : MessageType
GetRoomManager = ValueType UniqueTag ∷ [ ReferenceType [ GetRoomManagerReply ]ˡ ]ˡ
get-room-manager-ci : ChannelInitiation
get-room-manager-ci = record {
request = [ GetRoomManager ]ˡ
; response = record {
channel-shape = [ GetRoomManagerReply ]ˡ
; all-tagged = (HasTag _) ∷ [] }
; request-tagged = (HasTag+Ref _) ∷ []
}
get-room-manager-header : ActiveMethod
get-room-manager-header = ResponseMethod get-room-manager-ci
RoomSupervisorInterface : InboxShape
RoomSupervisorInterface = [ GetRoomManager ]ˡ
ClientSupervisorInterface : InboxShape
ClientSupervisorInterface =
[ ReferenceType RoomSupervisorInterface ]ˡ ∷ [ GetRoomManagerReply ]ˡ
--
--
--
-- ======================
-- ROOM MANAGER METHODS
-- ======================
join-room-header : ActiveMethod
join-room-header = VoidMethod [ JoinRoom ]ˡ
create-room-ci : ChannelInitiation
create-room-ci = record {
request = [ CreateRoom ]ˡ
; response = record {
channel-shape = [ CreateRoomReply ]ˡ
; all-tagged = (HasTag _) ∷ [] }
; request-tagged = (HasTag+Ref _) ∷ []
}
create-room-header : ActiveMethod
create-room-header = ResponseMethod create-room-ci
list-rooms-header : ActiveMethod
list-rooms-header = ResponseMethod (record {
request = [ ListRooms ]ˡ
; response = record {
channel-shape = [ ListRoomsReply ]ˡ
; all-tagged = (HasTag _) ∷ []
}
; request-tagged = (HasTag+Ref _) ∷ []
})
record RoomManagerState : Set₁ where
field
rooms : RoomList
rms-to-context : RoomManagerState → TypingContext
rms-to-context rms =
let
open RoomManagerState
rl-to-context : RoomList → TypingContext
rl-to-context = map λ _ → room-inbox
in rl-to-context (rms .rooms)
room-manager-methods : List ActiveMethod
room-manager-methods = join-room-header ∷ create-room-header ∷ [ list-rooms-header ]ˡ
room-manager-inbox = methods-shape room-manager-methods
list-rooms : active-method room-manager-inbox RoomManagerState rms-to-context list-rooms-header
list-rooms _ msg state =
let
open RoomManagerState
in return₁ (record {
new-state = state
; reply = SendM Z ((lift (state .rooms)) ∷ [])
})
lookup-room : ∀ {i} → {Γ : TypingContext} →
(rms : RoomManagerState) →
RoomName →
∞ActorM i room-manager-inbox (Maybe ((Γ ++ (rms-to-context rms)) ⊢ room-inbox)) (Γ ++ (rms-to-context rms)) (λ _ → Γ ++ (rms-to-context rms))
lookup-room rms name =
let open RoomManagerState
in return₁ (loop _ (rms .rooms))
where
rl-to-context : RoomList → TypingContext
rl-to-context = map λ _ → room-inbox
loop : (Γ : TypingContext) → (rl : RoomList) → Maybe ((Γ ++ rl-to-context rl) ⊢ room-inbox)
loop [] [] = nothing
loop [] (x ∷ xs) with (x ≟ name)
... | (yes p) = just Z
... | (no _) = RawMonad._>>=_ Maybe.monad (loop [] xs) λ p → just (S p)
loop (x ∷ Γ) rl = RawMonad._>>=_ Maybe.monad (loop Γ rl) (λ p → just (S p))
create-room : active-method room-manager-inbox RoomManagerState rms-to-context create-room-header
create-room _ input@(_ sent Msg Z (room-name ∷ [])) state = do
p ← lookup-room state room-name
handle-create-room p
where
open ResponseInput
return-type = ActiveReply create-room-ci RoomManagerState rms-to-context input
precondition = reply-state-vars rms-to-context input state
postcondition = reply-vars rms-to-context input
handle-create-room : ∀ {i} → Maybe (precondition ⊢ room-inbox) →
∞ActorM i
room-manager-inbox
return-type
precondition
postcondition
handle-create-room (just x) = return₁ (record { new-state = state ; reply = SendM Z ((lift (CR-EXISTS room-name)) ∷ []) })
handle-create-room nothing = do
spawn∞ (run-active-object room (record { clients = [] }))
let
open RoomManagerState
state' : RoomManagerState
state' = record { rooms = room-name ∷ state .rooms}
strengthen ((S Z) ∷ (Z ∷ (⊆-suc (⊆-suc ⊆-refl))))
return₁ (record { new-state = state' ; reply = SendM Z ((lift (CR-SUCCESS room-name)) ∷ []) })
create-room _ (_ sent Msg (S ()) _) _
join-room : active-method room-manager-inbox RoomManagerState rms-to-context join-room-header
join-room _ (Msg Z (tag ∷ _ ∷ room-name ∷ client-name ∷ [])) state = do
p ← lookup-room state room-name
handle-join-room p Z
return₁ state
where
handle-join-room : ∀ {i Γ} → Maybe (Γ ⊢ room-inbox) → Γ ⊢ JoinRoomReplyInterface → ∞ActorM i room-manager-inbox ⊤₁ Γ (λ _ → Γ)
handle-join-room (just rp) cp = do
(rp ![t: S (S Z) ] ((lift tag) ∷ ((lift client-name) ∷ (([ cp ]>: [ S (S Z) ]ᵐ) ∷ []))))
(cp ![t: Z ] ((lift tag) ∷ ((lift (JR-SUCCESS room-name)) ∷ (([ rp ]>: (Z ∷ [ S Z ]ᵐ)) ∷ []))))
handle-join-room nothing cp = cp ![t: S Z ] ((lift tag) ∷ ((lift (JR-FAIL room-name)) ∷ []))
join-room _ (Msg (S ()) _) _
room-manager : ActiveObject
room-manager = record {
state-type = RoomManagerState
; vars = rms-to-context
; methods = room-manager-methods
; extra-messages = []
; handlers = join-room ∷ (create-room ∷ (list-rooms ∷ []))
}
-- =================
-- ROOM SUPERVISOR
-- =================
rs-context : TypingContext
rs-context = [ room-manager-inbox ]ˡ
rs-vars : ⊤₁ → TypingContext
rs-vars _ = rs-context
room-supervisor-methods : List ActiveMethod
room-supervisor-methods = [ get-room-manager-header ]ˡ
rs-inbox = methods-shape room-supervisor-methods
get-room-manager-handler : active-method rs-inbox ⊤₁ rs-vars get-room-manager-header
get-room-manager-handler _ (_ sent Msg Z received-fields) _ = return₁ (record { new-state = _ ; reply = SendM Z [ [ (S Z) ]>: ⊆-refl ]ᵃ })
get-room-manager-handler _ (_ sent Msg (S ()) _) _
room-supervisor-ao : ActiveObject
room-supervisor-ao = record
{ state-type = ⊤₁
; vars = λ _ → rs-context
; methods = room-supervisor-methods
; extra-messages = []
; handlers = [ get-room-manager-handler ]ᵃ
}
-- room-supervisor spawns the room-manager
-- and provides an interface for getting a reference to the current room-manager
-- we don't ever change that instance, but we could if we want
room-supervisor : ∀ {i} → ActorM i RoomSupervisorInterface ⊤₁ [] (λ _ → rs-context)
room-supervisor = begin do
spawn∞ (run-active-object room-manager (record { rooms = [] }))
run-active-object room-supervisor-ao _
-- ================
-- CLIENT GENERAL
-- ================
ClientInterface : InboxShape
ClientInterface = [ ReferenceType RoomManagerInterface ]ˡ ∷ CreateRoomReply ∷ ListRoomsReply ∷ JoinRoomReplyInterface
busy-wait : ∀ {i IS Γ} → ℕ → ∞ActorM i IS ⊤₁ Γ (λ _ → Γ)
busy-wait zero = return _
busy-wait (suc n) = return tt >> busy-wait n
client-get-room-manager : ∀ {i} → ∞ActorM i ClientInterface ⊤₁ [] (λ _ → [ RoomManagerInterface ]ˡ)
client-get-room-manager = do
record { msg = Msg Z _} ← (selective-receive (λ {
(Msg Z x₁) → true
; (Msg (S _) _) → false
}))
where
record { msg = (Msg (S _) _) ; msg-ok = ()}
return _
client-create-room : ∀ {i } →
{Γ : TypingContext} →
Γ ⊢ RoomManagerInterface →
UniqueTag →
RoomName →
∞ActorM i ClientInterface (Lift (lsuc lzero) CreateRoomResult) Γ (λ _ → Γ)
client-create-room p tag name = do
Msg Z (_ ∷ cr ∷ []) ← (call create-room-ci (record {
var = p
; chosen-field = Z
; fields = (lift name) ∷ []
; session = record {
can-request = (S Z) ∷ []
; response-session = record {
can-receive = (S Z) ∷ []
; tag = tag
}
}
}))
where
Msg (S ()) _
return cr
add-if-join-success : TypingContext →
Lift (lsuc lzero) JoinRoomStatus →
TypingContext
add-if-join-success Γ (lift (JRS-SUCCESS x)) = Client-to-Room ∷ Γ
add-if-join-success Γ (lift (JRS-FAIL x)) = Γ
client-join-room : ∀ {i Γ} →
Γ ⊢ RoomManagerInterface →
UniqueTag →
RoomName →
ClientName →
∞ActorM i ClientInterface (Lift (lsuc lzero) JoinRoomStatus) Γ (add-if-join-success Γ)
client-join-room p tag room-name client-name = do
self
S p ![t: Z ] (lift tag ∷ (([ Z ]>: ⊆-suc (⊆-suc (⊆-suc ⊆-refl))) ∷ (lift room-name) ∷ [ lift client-name ]ᵃ))
(strengthen (⊆-suc ⊆-refl))
m ← (selective-receive (select-join-reply tag))
handle-message m
where
select-join-reply : UniqueTag → MessageFilter ClientInterface
select-join-reply tag (Msg Z _) = false
select-join-reply tag (Msg (S Z) _) = false
select-join-reply tag (Msg (S (S Z)) _) = false
select-join-reply tag (Msg (S (S (S Z))) (tag' ∷ _)) = ⌊ tag ≟ tag' ⌋
select-join-reply tag (Msg (S (S (S (S Z)))) (tag' ∷ _)) = ⌊ tag ≟ tag' ⌋
select-join-reply tag (Msg (S (S (S (S (S Z))))) x₁) = false
select-join-reply tag (Msg (S (S (S (S (S (S ())))))) _)
handle-message : ∀ {tag i Γ} → (m : SelectedMessage (select-join-reply tag)) →
∞ActorM i ClientInterface (Lift (lsuc lzero) JoinRoomStatus)
(add-selected-references Γ m) (add-if-join-success Γ)
handle-message record { msg = (Msg Z _) ; msg-ok = () }
handle-message record { msg = (Msg (S Z) _) ; msg-ok = () }
handle-message record { msg = (Msg (S (S Z)) _) ; msg-ok = () }
handle-message record { msg = (Msg (S (S (S Z))) (_ ∷ JR-SUCCESS room-name ∷ _ ∷ [])) } = return (JRS-SUCCESS room-name)
handle-message record { msg = (Msg (S (S (S (S Z)))) (_ ∷ JR-FAIL room-name ∷ [])) } = return (JRS-FAIL room-name)
handle-message record { msg = (Msg (S (S (S (S (S Z))))) _) ; msg-ok = () }
handle-message record { msg = (Msg (S (S (S (S (S (S ())))))) _) }
client-send-message : ∀ {i Γ} →
Γ ⊢ Client-to-Room →
ClientName →
String →
∞ActorM i ClientInterface ⊤₁ Γ (λ _ → Γ)
client-send-message p client-name message = p ![t: Z ] ([ lift (chat-from client-name message: message) ]ᵃ)
client-receive-message : ∀ {i Γ} →
∞ActorM i ClientInterface (Lift (lsuc lzero) ChatMessageContent) Γ (λ _ → Γ)
client-receive-message = do
m ← (selective-receive select-message)
handle-message m
where
select-message : MessageFilter ClientInterface
select-message (Msg (S (S (S (S (S Z))))) _) = true
select-message (Msg _ _) = false
handle-message : ∀ {i Γ} → (m : SelectedMessage select-message) →
∞ActorM i ClientInterface (Lift (lsuc lzero) ChatMessageContent) (add-selected-references Γ m) (λ _ → Γ)
handle-message record { msg = (Msg Z _) ; msg-ok = () }
handle-message record { msg = (Msg (S Z) _) ; msg-ok = () }
handle-message record { msg = (Msg (S (S Z)) _) ; msg-ok = () }
handle-message record { msg = (Msg (S (S (S Z))) x₁) ; msg-ok = () }
handle-message record { msg = (Msg (S (S (S (S Z)))) _) ; msg-ok = () }
handle-message record { msg = (Msg (S (S (S (S (S Z))))) (_ ∷ m ∷ f)) ; msg-ok = _ } = return m
handle-message record { msg = (Msg (S (S (S (S (S (S ())))))) _) }
client-leave-room : ∀ {i Γ} →
Γ ⊢ Client-to-Room →
ClientName →
∞ActorM i ClientInterface ⊤₁ Γ (λ _ → Γ)
client-leave-room p name = p ![t: S Z ] [ lift name ]ᵃ
debug-chat : {a : Level} {A : Set a} → ClientName → ChatMessageContent → A → A
debug-chat client-name content = let open ChatMessageContent
in debug ("client#" || show client-name || " received \"" || content .message || "\" from client#" || show (content .sender))
-- ==========
-- CLIENT 1
-- ==========
room1-2 = 1
room2-3 = 2
room3-1 = 3
room1-2-3 = 4
name1 = 1
client1 : ∀ {i} → ActorM i ClientInterface ⊤₁ [] (λ _ → [])
client1 = begin do
client-get-room-manager
_ ← (client-create-room Z 0 room1-2)
_ ← (client-create-room Z 1 room3-1)
_ ← (client-create-room Z 2 room1-2-3)
lift (JRS-SUCCESS joined-room) ← (client-join-room Z 3 room3-1 name1)
where
(lift (JRS-FAIL failed-room)) → strengthen []
lift (JRS-SUCCESS joined-room) ← (client-join-room (S Z) 4 room1-2 name1)
where
(lift (JRS-FAIL failed-room)) → strengthen []
lift (JRS-SUCCESS joined-room) ← (client-join-room (S (S Z)) 5 room1-2-3 name1)
where
(lift (JRS-FAIL failed-room)) → strengthen []
busy-wait 100
(client-send-message (S Z) name1 "hi from 1 to 2")
(client-send-message Z name1 "hi from 1 to 2-3")
let open ChatMessageContent
lift m1 ← client-receive-message
lift m2 ← debug-chat name1 m1 client-receive-message
lift m3 ← debug-chat name1 m2 client-receive-message
debug-chat name1 m3 (client-send-message Z name1 "hi1 from 1 to 2-3")
(client-send-message Z name1 "hi2 from 1 to 2-3")
(client-send-message Z name1 "hi3 from 1 to 2-3")
client-leave-room (S Z) name1
client-leave-room (Z) name1
(strengthen [])
-- ==========
-- CLIENT 2
-- ==========
name2 = 2
client2 : ∀ {i} → ActorM i ClientInterface ⊤₁ [] (λ _ → [])
client2 = begin do
client-get-room-manager
_ ← (client-create-room Z 0 room1-2)
_ ← (client-create-room Z 1 room2-3)
_ ← (client-create-room Z 2 room1-2-3)
lift (JRS-SUCCESS joined-room) ← (client-join-room Z 3 room1-2 name2)
where
(lift (JRS-FAIL failed-room)) → strengthen []
lift (JRS-SUCCESS joined-room) ← (client-join-room (S Z) 4 room2-3 name2)
where
(lift (JRS-FAIL failed-room)) → strengthen []
lift (JRS-SUCCESS joined-room) ← (client-join-room (S (S Z)) 5 room1-2-3 name2)
where
(lift (JRS-FAIL failed-room)) → strengthen []
busy-wait 100
debug "client2 send message" (client-send-message (S Z) name2 "hi from 2 to 3")
debug "client2 send message" (client-send-message Z name2 "hi from 2 to 1-3")
let open ChatMessageContent
lift m1 ← client-receive-message
lift m2 ← debug-chat name2 m1 client-receive-message
lift m3 ← debug-chat name2 m2 client-receive-message
client-leave-room (S Z) name2
client-leave-room (Z) name2
debug-chat name2 m3 (strengthen [])
-- ==========
-- CLIENT 3
-- ==========
name3 = 3
client3 : ∀ {i} → ActorM i ClientInterface ⊤₁ [] (λ _ → [])
client3 = begin do
client-get-room-manager
_ ← (client-create-room Z 0 room2-3)
_ ← (client-create-room Z 1 room3-1)
_ ← (client-create-room Z 2 room1-2-3)
lift (JRS-SUCCESS joined-room) ← (client-join-room Z 3 room2-3 name3)
where
(lift (JRS-FAIL failed-room)) → strengthen []
lift (JRS-SUCCESS joined-room) ← (client-join-room (S Z) 4 room3-1 name3)
where
(lift (JRS-FAIL failed-room)) → strengthen []
lift (JRS-SUCCESS joined-room) ← (client-join-room (S (S Z)) 5 room1-2-3 name3)
where
(lift (JRS-FAIL failed-room)) → strengthen []
busy-wait 100
debug "client3 send message" (client-send-message (S Z) name3 "hi from 3 to 1")
debug "client3 send message" (client-send-message Z name3 "hi from 3 to 1-2")
let open ChatMessageContent
lift m1 ← client-receive-message
lift m2 ← debug-chat name3 m1 client-receive-message
lift m3 ← debug-chat name3 m2 client-receive-message
debug-chat name3 m3 (client-leave-room Z name3)
client-leave-room (S Z) name3
client-leave-room Z name3
(strengthen [])
-- ===================
-- CLIENT SUPERVISOR
-- ===================
cs-context : TypingContext
cs-context = RoomManagerInterface ∷ RoomSupervisorInterface ∷ []
client-supervisor : ∀ {i} → ActorM i ClientSupervisorInterface ⊤₁ [] (λ _ → cs-context)
client-supervisor = begin do
wait-for-room-supervisor
(get-room-manager Z 0)
spawn-clients
where
wait-for-room-supervisor : ∀ {i Γ} → ∞ActorM i ClientSupervisorInterface ⊤₁ Γ (λ _ → RoomSupervisorInterface ∷ Γ)
wait-for-room-supervisor = do
record { msg = Msg Z f } ← (selective-receive (λ {
(Msg Z _) → true
; (Msg (S _) _) → false
}))
where
record { msg = (Msg (S _) _) ; msg-ok = () }
return _
get-room-manager : ∀ {i Γ} →
Γ ⊢ RoomSupervisorInterface →
UniqueTag →
∞ActorM i ClientSupervisorInterface ⊤₁ Γ (λ _ → RoomManagerInterface ∷ Γ)
get-room-manager p tag = do
Msg Z f ← (call get-room-manager-ci (record {
var = p
; chosen-field = Z
; fields = []
; session = record {
can-request = ⊆-refl
; response-session = record {
can-receive = (S Z) ∷ []
; tag = tag }
}
}))
where
Msg (S ()) _
return _
spawn-clients : ∀ {i} → ∞ActorM i ClientSupervisorInterface ⊤₁ cs-context (λ _ → cs-context)
spawn-clients = do
spawn client1
Z ![t: Z ] [ [ S Z ]>: ⊆-refl ]ᵃ
(strengthen (⊆-suc ⊆-refl))
(spawn client2)
Z ![t: Z ] [ [ S Z ]>: ⊆-refl ]ᵃ
(strengthen (⊆-suc ⊆-refl))
(spawn client3)
Z ![t: Z ] [ [ S Z ]>: ⊆-refl ]ᵃ
(strengthen (⊆-suc ⊆-refl))
-- chat-supervisor is the top-most actor
-- it spawns and connects the ClientRegistry to the RoomRegistry
chat-supervisor : ∀ {i} → ∞ActorM i [] ⊤₁ [] (λ _ → [])
chat-supervisor = do
spawn room-supervisor
spawn client-supervisor
Z ![t: Z ] [ [ S Z ]>: ⊆-refl ]ᵃ
strengthen []
|
{
"alphanum_fraction": 0.5961787947,
"avg_line_length": 36.9187227866,
"ext": "agda",
"hexsha": "fe1a883a099585718b6f87c061c8879269e0af81",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/singly-typed-actors",
"max_forks_repo_path": "src/Selective/Examples/ChatAO.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Zalastax/singly-typed-actors",
"max_issues_repo_path": "src/Selective/Examples/ChatAO.agda",
"max_line_length": 181,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/thesis",
"max_stars_repo_path": "src/Selective/Examples/ChatAO.agda",
"max_stars_repo_stars_event_max_datetime": "2018-02-02T16:44:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-02-02T16:44:43.000Z",
"num_tokens": 7360,
"size": 25437
}
|
------------------------------------------------------------------------
-- Laws related to _∣_ and fail
------------------------------------------------------------------------
module TotalParserCombinators.Laws.AdditiveMonoid where
open import Algebra
open import Codata.Musical.Notation
import Data.List.Relation.Binary.BagAndSetEquality as Eq
open import Data.Product using (proj₁; proj₂)
open import Function
private
module BagMonoid {k} {A : Set} =
CommutativeMonoid (Eq.commutativeMonoid k A)
open import TotalParserCombinators.Derivative
open import TotalParserCombinators.Congruence
open import TotalParserCombinators.Parser
------------------------------------------------------------------------
-- _∣_ and fail form a commutative monoid
-- This monoid is idempotent if language equivalence is used.
commutative : ∀ {Tok R xs₁ xs₂}
(p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂) →
p₁ ∣ p₂ ≅P p₂ ∣ p₁
commutative {xs₁ = xs₁} {xs₂} p₁ p₂ =
BagMonoid.comm xs₁ xs₂ ∷ λ t → ♯ commutative (D t p₁) (D t p₂)
left-identity : ∀ {Tok R xs} (p : Parser Tok R xs) → fail ∣ p ≅P p
left-identity {xs = xs} p =
proj₁ BagMonoid.identity xs ∷ λ t → ♯ left-identity (D t p)
right-identity : ∀ {Tok R xs} (p : Parser Tok R xs) → p ∣ fail ≅P p
right-identity {xs = xs} p =
proj₂ BagMonoid.identity xs ∷ λ t → ♯ right-identity (D t p)
associative : ∀ {Tok R xs₁ xs₂ xs₃}
(p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂)
(p₃ : Parser Tok R xs₃) →
(p₁ ∣ p₂) ∣ p₃ ≅P p₁ ∣ (p₂ ∣ p₃)
associative {xs₁ = xs₁} p₁ p₂ p₃ =
BagMonoid.assoc xs₁ _ _ ∷ λ t →
♯ associative (D t p₁) (D t p₂) (D t p₃)
-- Note that this law uses language equivalence, not parser
-- equivalence.
idempotent : ∀ {Tok R xs} (p : Parser Tok R xs) → p ∣ p ≈P p
idempotent {xs = xs} p =
Eq.++-idempotent xs ∷ λ t → ♯ idempotent (D t p)
------------------------------------------------------------------------
-- A lemma which can be convenient when proving distributivity laws
swap : ∀ {Tok R xs₁ xs₂ xs₃ xs₄}
(p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂)
(p₃ : Parser Tok R xs₃) (p₄ : Parser Tok R xs₄) →
(p₁ ∣ p₂) ∣ (p₃ ∣ p₄) ≅P (p₁ ∣ p₃) ∣ (p₂ ∣ p₄)
swap p₁ p₂ p₃ p₄ =
(p₁ ∣ p₂) ∣ (p₃ ∣ p₄) ≅⟨ associative p₁ p₂ (p₃ ∣ p₄) ⟩
p₁ ∣ (p₂ ∣ (p₃ ∣ p₄)) ≅⟨ (p₁ ∎) ∣ (
p₂ ∣ (p₃ ∣ p₄) ≅⟨ sym $ associative p₂ p₃ p₄ ⟩
(p₂ ∣ p₃) ∣ p₄ ≅⟨ commutative p₂ p₃ ∣ (p₄ ∎) ⟩
(p₃ ∣ p₂) ∣ p₄ ≅⟨ associative p₃ p₂ p₄ ⟩
p₃ ∣ (p₂ ∣ p₄) ∎) ⟩
p₁ ∣ (p₃ ∣ (p₂ ∣ p₄)) ≅⟨ sym $ associative p₁ p₃ (p₂ ∣ p₄) ⟩
(p₁ ∣ p₃) ∣ (p₂ ∣ p₄) ∎
|
{
"alphanum_fraction": 0.5320512821,
"avg_line_length": 37.3521126761,
"ext": "agda",
"hexsha": "64fb203ddbe0cd335ca4ed18fe51a4f04b9b7153",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "TotalParserCombinators/Laws/AdditiveMonoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "TotalParserCombinators/Laws/AdditiveMonoid.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "TotalParserCombinators/Laws/AdditiveMonoid.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 1020,
"size": 2652
}
|
module Web.URI.Scheme where
open import Web.URI.Scheme.Primitive public using ( Scheme? ; http: ; https: ; ε )
|
{
"alphanum_fraction": 0.7232142857,
"avg_line_length": 28,
"ext": "agda",
"hexsha": "af54f7e9539304c30e0033415c97ffecdb6bd381",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:37:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:37:59.000Z",
"max_forks_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-web-uri",
"max_forks_repo_path": "src/Web/URI/Scheme.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-web-uri",
"max_issues_repo_path": "src/Web/URI/Scheme.agda",
"max_line_length": 82,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-uri",
"max_stars_repo_path": "src/Web/URI/Scheme.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-23T04:56:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-23T04:56:25.000Z",
"num_tokens": 27,
"size": 112
}
|
module PreludeBool where
import AlonzoPrelude
open AlonzoPrelude
-- import Logic.Base
infixr 20 _||_
infixr 30 _&&_
data Bool : Set where
false : Bool
true : Bool
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
_&&_ : Bool -> Bool -> Bool
true && x = x
false && _ = false
_||_ : Bool -> Bool -> Bool
true || _ = true
false || x = x
not : Bool -> Bool
not true = false
not false = true
-- open Logic.Base
IsTrue : Bool -> Set
IsTrue true = True
IsTrue false = False
IsFalse : Bool -> Set
IsFalse x = IsTrue (not x)
if_then_else_ : {A : Set} -> Bool -> A -> A -> A
if true then x else y = x
if false then x else y = y
if'_then_else_ : {A : Set} -> (x : Bool) -> (IsTrue x -> A) -> (IsFalse x -> A) -> A
if' true then f else g = f tt
if' false then f else g = g tt
|
{
"alphanum_fraction": 0.6007281553,
"avg_line_length": 16.8163265306,
"ext": "agda",
"hexsha": "e5ae1e874d27d6523b38896c6c5f4db3c84ee246",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/Alonzo/PreludeBool.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/Alonzo/PreludeBool.agda",
"max_line_length": 84,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/Alonzo/PreludeBool.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": 282,
"size": 824
}
|
module Examples where
open import LF
open import IIRD
open import IIRDr
-- Some helper functions
infixl 50 _+OP_
_+OP_ : {I : Set}{D : I -> Set1}{E : Set1} -> OP I D E -> OP I D E -> OP I D E
γ₀ +OP γ₁ = σ Two (\x -> case₂ x γ₀ γ₁)
-- First something simple.
bool : OPr One (\_ -> One')
bool _ = ι★r +OP ι★r
Bool : Set
Bool = Ur bool ★
false : Bool
false = intror < ★₀ | ★ >
true : Bool
true = intror < ★₁ | ★ >
-- We don't have universe subtyping, and we only setup large elimination rules.
if_then_else_ : {A : Set1} -> Bool -> A -> A -> A
if_then_else_ {A} b x y = Rr bool (\_ _ -> A) (\_ a _ -> case₂ (π₀ a) y x) ★ b
-- Something recursive
nat : OPr One (\_ -> One')
nat _ = ι★r +OP δ One (\_ -> ★) (\_ -> ι★r)
Nat : Set
Nat = Ur nat ★
zero : Nat
zero = intror < ★₀ | ★ >
suc : Nat -> Nat
suc n = intror < ★₁ | < (\_ -> n) | ★ > >
|
{
"alphanum_fraction": 0.558685446,
"avg_line_length": 18.1276595745,
"ext": "agda",
"hexsha": "e6c5f903c4b0f94ad9cd71819c781cd51715ea89",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/iird/Examples.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/iird/Examples.agda",
"max_line_length": 79,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/iird/Examples.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": 323,
"size": 852
}
|
{-
This second-order signature was created from the following second-order syntax description:
syntax Prod | P
type
_⊗_ : 2-ary | l40
term
pair : α β -> α ⊗ β | ⟨_,_⟩
fst : α ⊗ β -> α
snd : α ⊗ β -> β
theory
(fβ) a : α b : β |> fst (pair(a, b)) = a
(sβ) a : α b : β |> snd (pair(a, b)) = b
(pη) p : α ⊗ β |> pair (fst(p), snd(p)) = p
-}
module Prod.Signature where
open import SOAS.Context
-- Type declaration
data PT : Set where
_⊗_ : PT → PT → PT
infixl 40 _⊗_
open import SOAS.Syntax.Signature PT public
open import SOAS.Syntax.Build PT public
-- Operator symbols
data Pₒ : Set where
pairₒ fstₒ sndₒ : {α β : PT} → Pₒ
-- Term signature
P:Sig : Signature Pₒ
P:Sig = sig λ
{ (pairₒ {α}{β}) → (⊢₀ α) , (⊢₀ β) ⟼₂ α ⊗ β
; (fstₒ {α}{β}) → (⊢₀ α ⊗ β) ⟼₁ α
; (sndₒ {α}{β}) → (⊢₀ α ⊗ β) ⟼₁ β
}
open Signature P:Sig public
|
{
"alphanum_fraction": 0.5550510783,
"avg_line_length": 19.152173913,
"ext": "agda",
"hexsha": "7552e7d313d57a4e47c4e72c0092a3de6cff060d",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/Prod/Signature.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/Prod/Signature.agda",
"max_line_length": 91,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/Prod/Signature.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 380,
"size": 881
}
|
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
open import Agda.Builtin.Reflection renaming (bindTC to _>>=_)
open import Agda.Builtin.List
open import Agda.Builtin.Sigma
open import Agda.Builtin.Equality
open import Agda.Primitive
record X {a} (A : Set a) : Set a where
field fld : A
d : X Nat
d = record { fld = 5 }
-- Here we test that suppressing reduction of lzero has no effect on the reconstruction
-- of parameters. Essentially, we ignore ReduceDefs annotations when reconstructing
-- hidden parameters.
macro
x : Term → TC ⊤
x hole = do
(function (clause tel ps t ∷ [])) ← withReconstructed (getDefinition (quote d))
where _ → quoteTC "ERROR" >>= unify hole
a ← withReconstructed (dontReduceDefs (quote lzero ∷ []) (normalise t))
quoteTC a >>= unify hole
-- If we were to consider suppressed reduction of lzero, we end up with
-- Set ≠ Set lzero.
test₁ : Term
test₁ = x
map : ∀ {a b}{A : Set a}{B : Set b} → (A → B) → List A → List B
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
reverse : ∀ {a}{A : Set a} → List A → List A
reverse {A = A} xs = reverseAcc xs []
where
reverseAcc : List A → List A → List A
reverseAcc [] a = a
reverseAcc (x ∷ xs) a = reverseAcc xs (x ∷ a)
foo : Nat → Nat
foo x = 1 + x
bar : Nat → Nat
bar x = foo (foo (x))
-- Here we test that normalisation respects ReduceDefs
-- when parameter reconstruction is on.
macro
y : Term → TC ⊤
y hole = do
(function (clause tel ps t ∷ [])) ← withReconstructed (dontReduceDefs (quote foo ∷ []) (getDefinition (quote bar)))
where _ → quoteTC "ERROR" >>= unify hole
t ← inContext (reverse tel)
(withReconstructed (dontReduceDefs (quote foo ∷ []) (normalise t)))
quoteTC t >>= unify hole
test₂ : y ≡ def (quote foo) (arg _ (def (quote foo) _) ∷ [])
test₂ = refl
|
{
"alphanum_fraction": 0.6427795874,
"avg_line_length": 29.2380952381,
"ext": "agda",
"hexsha": "65cb10110f70ae3b6bff2d2d97cb63ceb456c5c0",
"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": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "Seanpm2001-Agda-lang/agda",
"max_forks_repo_path": "test/Succeed/recons-with-reducedefs.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "Seanpm2001-Agda-lang/agda",
"max_issues_repo_path": "test/Succeed/recons-with-reducedefs.agda",
"max_line_length": 121,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/recons-with-reducedefs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:25:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:25:14.000Z",
"num_tokens": 558,
"size": 1842
}
|
{- Category of reactive types -}
module CategoryTheory.Instances.Reactive where
open import CategoryTheory.Categories
open import CategoryTheory.BCCCs
open import Data.Nat using (ℕ ; zero ; suc ; _+_) public
open import Data.Unit using () renaming (⊤ to top) public
open import Data.Product
open import Data.Empty using (⊥-elim) renaming (⊥ to bot) public
open import Data.Sum renaming ([_,_] to ⟦_,_⟧)
import Function as F using (_∘_)
-- || Reactive types
-- Time-indexed types.
τ : Set₁
τ = ℕ -> Set
-- Time-indexed functions.
_⇴_ : τ -> τ -> Set
A ⇴ B = ∀(n : ℕ) -> A n -> B n
infixr 10 _⇴_
-- Category of reactive types
ℝeactive : Category lzero
ℝeactive = record
{ obj = τ
; _~>_ = _⇴_
; id = λ n a -> a
; _∘_ = λ g f -> λ n a -> g n (f n a)
; _≈_ = λ f g -> ∀ {n : ℕ} {a} -> f n a ≡ g n a
; id-left = refl
; id-right = refl
; ∘-assoc = refl
; ≈-equiv = record { refl = refl
; sym = λ x → sym x
; trans = λ p q → trans p q }
; ≈-cong = ≈-cong-ℝ
}
where
≈-cong-ℝ : ∀{A B C : τ} {f f′ : A ⇴ B} {g g′ : B ⇴ C}
-> (∀ {n a} -> f n a ≡ f′ n a)
-> (∀ {n b} -> g n b ≡ g′ n b)
-> (∀ {n a} -> g n (f n a) ≡ g′ n (f′ n a))
≈-cong-ℝ {f′ = f′} fe ge {n} {a′}
rewrite fe {n} {a′}
| ge {n} {f′ n a′} = refl
-- Bicartesian closed structure for reactive types
ℝeactive-BCCC : BicartesianClosed ℝeactive
ℝeactive-BCCC = record
{ cart = record
{ term = record
{ ⊤ = λ n → top
; ! = λ n _ → top.tt
; !-unique = λ m → refl
}
; prod = λ A B → record
{ A⊗B = λ n → A n × B n
; π₁ = λ n → proj₁
; π₂ = λ n → proj₂
; ⟨_,_⟩ = λ f g n a → (f n a , g n a)
; π₁-comm = λ {P} {p₁} {p₂} {n} {a} → refl
; π₂-comm = λ {P} {p₁} {p₂} {n} {a} → refl
; ⊗-unique = λ pr1 pr2 → unique-cart (ext λ a → ext λ n → pr1 {a} {n})
(ext λ a → ext λ n → pr2 {a} {n})
}
}
; cocart = record
{ init = record
{ ⊥ = λ n → bot
; ¡ = λ {A} n → λ ()
; ¡-unique = λ {A} m {n} → λ {}
}
; sum = λ A B → record
{ A⊕B = λ n → A n ⊎ B n
; ι₁ = λ n → inj₁
; ι₂ = λ n → inj₂
; [_⁏_] = sum
; ι₁-comm = λ {S} {i₁} {i₂} {n} {a} → refl
; ι₂-comm = λ {S} {i₁} {i₂} {n} {a} → refl
; ⊕-unique = λ {S} {i₁} {i₂} {m} pr1 pr2 →
unique-cocart {m = m} (ext λ a → ext λ n → pr1 {a} {n})
(ext λ a → ext λ n → pr2 {a} {n})
}
}
; closed = record
{ exp = λ A B → record
{ A⇒B = λ n → A n -> B n
; eval = λ n z → proj₁ z (proj₂ z)
; Λ = λ f n a b → f n (a , b)
; Λ-comm = refl
; Λ-unique = λ pr → unique-closed (ext λ n → ext λ a → pr {n} {a})
; Λ-cong = λ pr → ext λ _ → pr
}
}
}
where
open Category ℝeactive
unique-cart : ∀{A B P : τ}
-> {p₁ : P ⇴ A} {p₂ : P ⇴ B} {m : P ⇴ (λ n -> A n × B n)}
-> (λ _ → proj₁) ∘ m ≡ p₁ -> (λ _ → proj₂) ∘ m ≡ p₂
-> ∀{n : ℕ}{a : P n} -> (p₁ n a , p₂ n a) ≡ m n a
unique-cart refl refl = refl
sum : {A B S : obj} → A ⇴ S → B ⇴ S → (λ n → A n ⊎ B n) ⇴ S
sum f g n (inj₁ x) = f n x
sum f g n (inj₂ y) = g n y
unique-cocart : ∀{A B S : τ}
-> {i₁ : A ⇴ S} {i₂ : B ⇴ S} {m : (λ n -> A n ⊎ B n) ⇴ S}
-> m ∘ (λ _ -> inj₁) ≡ i₁ -> m ∘ (λ _ -> inj₂) ≡ i₂
-> ∀{n : ℕ}{a : A n ⊎ B n} -> sum i₁ i₂ n a ≡ m n a
unique-cocart refl refl {n} {inj₁ x} = refl
unique-cocart refl refl {n} {inj₂ y} = refl
unique-closed : ∀{A B E : τ}
-> {e : (λ n -> E n × A n) ⇴ B} {m : E ⇴ (λ n -> A n -> B n)}
-> (λ n fa → proj₁ fa (proj₂ fa)) ∘ ((λ n (a : E n × A n) -> ( (m n F.∘ proj₁) a , proj₂ a ))) ≡ e
-> ∀{n}{a : E n} -> (λ b → e n (a , b)) ≡ m n a
unique-closed refl = refl
-- | Top-level shorthands for distinguished BCCC objects and morphisms
open BicartesianClosed ℝeactive-BCCC public
open Category ℝeactive hiding (begin_ ; _∎) public
ℝeactive-cart : Cartesian ℝeactive
ℝeactive-cart = cart
-- Non-canonical distribution morphism
dist : ∀{A B C : τ} -> A ⊗ (B ⊕ C) ⇴ (A ⊗ B) ⊕ (A ⊗ C)
dist n (a , inj₁ b) = inj₁ (a , b)
dist n (a , inj₂ c) = inj₂ (a , c)
dist2 : ∀{A B C D : τ} -> A ⊗ (B ⊕ C ⊕ D) ⇴ (A ⊗ B) ⊕ (A ⊗ C) ⊕ (A ⊗ D)
dist2 n (a , inj₁ (inj₁ b)) = inj₁ (inj₁ (a , b))
dist2 n (a , inj₁ (inj₂ c)) = inj₁ (inj₂ (a , c))
dist2 n (a , inj₂ d) = inj₂ (a , d)
-- ℝeactive is distributive
dist-ℝ : ∀{A B C : τ} -> (A ⊗ B) ⊕ (A ⊗ C) <~> A ⊗ (B ⊕ C)
dist-ℝ = record
{ iso~> = [ id * ι₁ ⁏ id * ι₂ ]
; iso<~ = dist
; iso-id₁ = dist-iso-id₁
; iso-id₂ = dist-iso-id₂
}
where
dist-iso-id₁ : ∀{A B C : τ} -> dist {A}{B}{C} ∘ [ id * ι₁ ⁏ id * ι₂ ] ≈ id
dist-iso-id₁ {n = n} {inj₁ (a , b)} = refl
dist-iso-id₁ {n = n} {inj₂ (a , c)} = refl
dist-iso-id₂ : ∀{A B C : τ} -> [ id * ι₁ ⁏ id * ι₂ ] ∘ dist {A}{B}{C} ≈ id
dist-iso-id₂ {n = n} {a , inj₁ b} = refl
dist-iso-id₂ {n = n} {a , inj₂ c} = refl
|
{
"alphanum_fraction": 0.4098716326,
"avg_line_length": 35.4551282051,
"ext": "agda",
"hexsha": "f8e2ad4eb5d9d6399203dbb336f9026265692710",
"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": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DimaSamoz/temporal-type-systems",
"max_forks_repo_path": "src/CategoryTheory/Instances/Reactive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"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": "DimaSamoz/temporal-type-systems",
"max_issues_repo_path": "src/CategoryTheory/Instances/Reactive.agda",
"max_line_length": 112,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DimaSamoz/temporal-type-systems",
"max_stars_repo_path": "src/CategoryTheory/Instances/Reactive.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z",
"num_tokens": 2204,
"size": 5531
}
|
------------------------------------------------------------------------------
-- Testing the translation of definitions
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Definition01d where
infixl 6 _+_
infix 4 _≡_
postulate
D : Set
zero : D
succ : D → D
_≡_ : D → D → Set
data N : D → Set where
zN : N zero
sN : ∀ {n} → N n → N (succ n)
N-ind : (A : D → Set) →
A zero →
(∀ {n} → A n → A (succ n)) →
∀ {n} → N n → A n
N-ind A A0 h zN = A0
N-ind A A0 h (sN Nn) = h (N-ind A A0 h Nn)
postulate
_+_ : D → D → D
+-0x : ∀ n → zero + n ≡ n
+-Sx : ∀ m n → succ m + n ≡ succ (m + n)
{-# ATP axioms +-0x +-Sx #-}
-- We test the translation of the definition of a unary predicate.
A : D → Set
A i = zero + i ≡ i
{-# ATP definition A #-}
postulate A0 : A zero
{-# ATP prove A0 #-}
postulate is : ∀ {i} → A i → A (succ i)
{-# ATP prove is #-}
+-leftIdentity : ∀ {n} → N n → zero + n ≡ n
+-leftIdentity = N-ind A A0 is
|
{
"alphanum_fraction": 0.4318374259,
"avg_line_length": 22.7115384615,
"ext": "agda",
"hexsha": "f74ced03d402f12eae69ca081c34a2a19548f959",
"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/Definition01d.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/Definition01d.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/Definition01d.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": 377,
"size": 1181
}
|
{-
This second-order equational theory was created from the following second-order syntax description:
syntax Prod | P
type
_⊗_ : 2-ary | l40
term
pair : α β -> α ⊗ β | ⟨_,_⟩
fst : α ⊗ β -> α
snd : α ⊗ β -> β
theory
(fβ) a : α b : β |> fst (pair(a, b)) = a
(sβ) a : α b : β |> snd (pair(a, b)) = b
(pη) p : α ⊗ β |> pair (fst(p), snd(p)) = p
-}
module Prod.Equality where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Families.Build
open import SOAS.ContextMaps.Inductive
open import Prod.Signature
open import Prod.Syntax
open import SOAS.Metatheory.SecondOrder.Metasubstitution P:Syn
open import SOAS.Metatheory.SecondOrder.Equality P:Syn
private
variable
α β γ τ : PT
Γ Δ Π : Ctx
infix 1 _▹_⊢_≋ₐ_
-- Axioms of equality
data _▹_⊢_≋ₐ_ : ∀ 𝔐 Γ {α} → (𝔐 ▷ P) α Γ → (𝔐 ▷ P) α Γ → Set where
fβ : ⁅ α ⁆ ⁅ β ⁆̣ ▹ ∅ ⊢ fst ⟨ 𝔞 , 𝔟 ⟩ ≋ₐ 𝔞
sβ : ⁅ α ⁆ ⁅ β ⁆̣ ▹ ∅ ⊢ snd ⟨ 𝔞 , 𝔟 ⟩ ≋ₐ 𝔟
pη : ⁅ α ⊗ β ⁆̣ ▹ ∅ ⊢ ⟨ fst 𝔞 , snd 𝔞 ⟩ ≋ₐ 𝔞
open EqLogic _▹_⊢_≋ₐ_
open ≋-Reasoning
|
{
"alphanum_fraction": 0.5904590459,
"avg_line_length": 22.22,
"ext": "agda",
"hexsha": "e2289d09ff28bb952824e6f75fde77a6ca0bfa28",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/Prod/Equality.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/Prod/Equality.agda",
"max_line_length": 99,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/Prod/Equality.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 501,
"size": 1111
}
|
{-# OPTIONS --cubical --safe #-}
module Algebra.Construct.Free.Semilattice.Relation.Unary.All.Properties where
open import Prelude hiding (⊥; ⊤)
open import Algebra.Construct.Free.Semilattice.Eliminators
open import Algebra.Construct.Free.Semilattice.Definition
open import Cubical.Foundations.HLevels
open import Data.Empty.UniversePolymorphic
open import HITs.PropositionalTruncation.Sugar
open import HITs.PropositionalTruncation.Properties
open import HITs.PropositionalTruncation
open import Data.Unit.UniversePolymorphic
open import Algebra.Construct.Free.Semilattice.Relation.Unary.All.Def
open import Algebra.Construct.Free.Semilattice.Relation.Unary.Membership
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Relation.Nullary.Decidable.Properties
open import Relation.Nullary.Decidable.Logic
private
variable p : Level
P∈◇ : ∀ {p} {P : A → Type p} → ∀ x xs → x ∈ xs → ◻ P xs → ∥ P x ∥
P∈◇ {A = A} {P = P} = λ x → ∥ P∈◇′ x ∥⇓
where
P∈◇′ : (x : A) → xs ∈𝒦 A ⇒∥ (x ∈ xs → ◻ P xs → ∥ P x ∥) ∥
∥ P∈◇′ x ∥-prop p q i x∈xs ◻Pxs = squash (p x∈xs ◻Pxs) (q x∈xs ◻Pxs) i
∥ P∈◇′ x ∥[] ()
∥ P∈◇′ x ∥ y ∷ ys ⟨ Pys ⟩ x∈xs ◻Pxs =
x∈xs >>=
either′
(λ y≡x → subst (∥_∥ ∘ P) y≡x (◻Pxs .fst))
(λ x∈ys → Pys x∈ys (◻Pxs .snd))
|
{
"alphanum_fraction": 0.6824534161,
"avg_line_length": 36.8,
"ext": "agda",
"hexsha": "2f9afd2d15da51cba9474f1fc15745fb23eb1163",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Algebra/Construct/Free/Semilattice/Relation/Unary/All/Properties.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/Algebra/Construct/Free/Semilattice/Relation/Unary/All/Properties.agda",
"max_line_length": 77,
"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/Algebra/Construct/Free/Semilattice/Relation/Unary/All/Properties.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": 483,
"size": 1288
}
|
module Example where
loop : Set
loop = loop
_∞_ : Set -> Set -> Set
x ∞ y = x ∞ y
data Nat : Set where
zero : Nat
succ : Nat -> Nat
id : Nat -> Nat
id zero = zero
id (succ n) = succ (id n)
bad : Nat -> Nat
bad n = bad n
_+_ : Nat -> Nat -> Nat
zero + n = n
(succ m) + n = succ (m + n)
bad2 : Nat -> Nat
bad2 (succ x) = bad2 x + bad2 (succ x)
bad2 x = bad2 x
data Bool : Set where
true : Bool
false : Bool
_&&_ : Bool -> Bool -> Bool
true && a = a
false && a = false
mutual
even : Nat -> Bool
even zero = true
even (succ n) = odd n
odd : Nat -> Bool
odd zero = false
odd (succ n) = even n
data Ty : {_ : Nat} -> Set where
Base : forall {n} -> Ty {succ n}
Arr : forall {n} -> Ty {n} -> Ty {n} -> Ty {succ n}
eqty : forall {n} -> Ty {n} -> Ty {n} -> Bool
eqty Base Base = true
eqty (Arr a b) (Arr a' b') = (eqty a a') && (eqty b b')
eqty _ _ = false
subty : forall {n} -> Ty {n} -> Ty {n} -> Bool
subty Base Base = true
subty (Arr a b) (Arr a' b') = (subty a' a) && (subty b b')
subty _ _ = false
-- the following is enough for making it termination check
subty' : forall {n} -> Ty {n} -> Ty {n} -> Bool
subty' Base Base = true
subty' {succ n} (Arr a b) (Arr a' b')
= (subty' a' a) && (subty' b b')
subty' _ _ = false
subty'' : forall {n} -> Ty {n} -> Ty {n} -> Bool
subty'' Base Base = true
subty'' {succ n} (Arr {.n} a b) (Arr .{n} a'' b'')
= (subty'' {n} a'' a) && (subty'' {n} b b'')
subty'' _ _ = false
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
add : Nat × Nat -> Nat
add (zero , m) = m
add (succ n , m) = succ (add (n , m))
eq : Nat × Nat -> Bool
eq (zero , zero ) = true
eq (succ n , succ m) = eq (n , m)
eq _ = false
-- the following should not termination check
mutual
f : Nat -> Nat -> Nat
f zero y = zero
f (succ x) zero = zero
f (succ x) (succ y) = (g x (succ y)) + (f (succ (succ x)) y)
g : Nat -> Nat -> Nat
g zero y = zero
g (succ x) zero = zero
g (succ x) (succ y) = (f (succ x) (succ y)) + (g x (succ (succ y)))
mutual
badf : Nat × Nat -> Nat
badf (zero , y) = zero
badf (succ x , zero) = zero
badf (succ x , succ y) = badg (x , succ y) + badf (succ (succ x) , y)
badg : Nat × Nat -> Nat
badg (zero , y) = zero
badg (succ x , zero) = zero
badg (succ x , succ y) = badf (succ x , succ y) + badg (x , succ (succ y))
-- these are ok, however
mutual
f' : Nat -> Nat -> Nat
f' zero y = zero
f' (succ x) zero = zero
f' (succ x) (succ y) = (g' x (succ y)) + (f' (succ (succ x)) y)
g' : Nat -> Nat -> Nat
g' zero y = zero
g' (succ x) zero = zero
g' (succ x) (succ y) = (f' (succ x) (succ y)) + (g' x (succ y))
-- these are ok, however
bla : Nat
bla = succ (succ zero)
mutual
f'' : Nat -> Nat -> Nat
f'' zero y = zero
f'' (succ x) zero = zero
f'' (succ x) (succ y) = (g'' x (succ y)) + (f'' bla y)
g'' : Nat -> Nat -> Nat
g'' zero y = zero
g'' (succ x) zero = zero
g'' (succ x) (succ y) = (f'' (succ x) (succ y)) + (g'' x (succ y))
-- Ackermann
ack : Nat -> Nat -> Nat
ack zero y = succ y
ack (succ x) zero = ack x (succ zero)
ack (succ x) (succ y) = ack x (ack (succ x) y)
ack' : Nat × Nat -> Nat
ack' (zero , y) = succ y
ack' (succ x , zero) = ack' (x , succ zero)
ack' (succ x , succ y) = ack' (x , ack' (succ x , y))
-- Maximum of 3 numbers
max3 : Nat -> Nat -> Nat -> Nat
max3 zero zero z = z
max3 zero y zero = y
max3 x zero zero = x
max3 (succ x) (succ y) zero = succ (max3 x y zero)
max3 (succ x) zero (succ z) = succ (max3 x zero z)
max3 zero (succ y) (succ z) = succ (max3 zero y z)
max3 (succ x) (succ y) (succ z) = succ (max3 x y z)
-- addition of Ordinals
data Ord : Set where
ozero : Ord
olim : (Nat -> Ord) -> Ord
addord : Ord -> Ord -> Ord
addord x ozero = x
addord x (olim f) = olim (\ n -> addord x (f n))
-- Higher-order example which should not pass the termination checker.
-- (Not the current one, anyway.)
foo : Ord -> (Nat -> Ord) -> Ord
foo ozero g = ozero
foo (olim f) g = olim (\n -> foo (g n) f)
-- Examples checking that a function can be used with several
-- different numbers of arguments on the right-hand side.
const : {a b : Set1} -> a -> b -> a
const x _ = x
ok : Nat -> Nat -> Set
ok zero y = Nat
ok (succ x) y = const Nat (const (ok x y) (ok x))
notOK : Set -> Set
notOK x = const (notOK Ord) notOK
-- An example which should fail (37 is an arbitrary number):
data ⊤ : Set where
tt : ⊤
mutual
foo37 : ⊤ -> ⊤
foo37 x = bar37 x
bar37 : ⊤ -> ⊤
bar37 tt = foo37 tt
-- Some examples involving with.
-- Not OK:
withNo : Nat -> Nat
withNo n with n
withNo n | m = withNo m
-- OK:
withYes : Nat -> Nat
withYes n with n
withYes n | zero = zero
withYes n | succ m = withYes m
-- Some rather convoluted examples.
-- OK:
number : Nat
number = zero
where
data Foo12 : Nat -> Set where
foo12 : Foo12 number
-- Should the occurrence of number' in the type signature of foo12
-- really be highlighted here?
number' : Nat
number' with zero
number' | x = g12 foo12
where
data Foo12 : Nat -> Set where
foo12 : Foo12 number'
abstract
g12 : {i : Nat} -> Foo12 i -> Nat
g12 foo12 = zero
-- Tests highlighting (but does not type check yet):
-- number'' : Nat
-- number'' with zero
-- number'' | x = g12 (foo12 x)
-- where
-- data Foo12 : Nat -> Set where
-- foo12 : (n : Nat) -> Foo12 (number'' | n)
-- abstract
-- g12 : {i : Nat} -> Foo12 i -> Nat
-- g12 (foo12 n) = n
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
infixr 50 _::_
-- butlast function
good1 : {A : Set} -> List A -> A
good1 (a :: []) = a
good1 (a :: b :: bs) = good1 (b :: bs)
infixl 10 _⊕_
postulate
_⊕_ : {A : Set} -> A -> A -> A -- non-deterministic choice
-- a funny formulation of insert
-- insert (a :: l) inserts a into l
insert : {A : Set} -> List A -> List A
insert [] = []
insert (a :: []) = a :: []
insert (a :: b :: bs) = a :: b :: bs ⊕ -- case a <= b
b :: insert (a :: bs) -- case a > b
-- list flattening
flat : {A : Set} -> List (List A) -> List A
flat [] = []
flat ([] :: ll) = flat ll
flat ((x :: l) :: ll) = x :: flat (l :: ll)
-- leaf-labelled trees
data Tree (A : Set) : Set where
leaf : A -> Tree A
node : Tree A -> Tree A -> Tree A
-- flattening (does not termination check)
tflat : {A : Set} -> Tree A -> List A
tflat (leaf a) = a :: []
tflat (node (leaf a) r) = a :: tflat r
tflat (node (node l1 l2) r) = tflat (node l1 (node l2 r))
-- Maximum of 3 numbers
-- mixing tupling and swapping: does not work with structured orders
max3' : Nat × Nat -> Nat -> Nat
max3' (zero , zero) z = z
max3' (zero , y) zero = y
max3' (x , zero) zero = x
max3' (succ x , succ y) zero = succ (max3' (x , y) zero)
max3' (succ x , zero) (succ z) = succ (max3' (x , z) zero)
max3' (zero , succ y) (succ z) = succ (max3' (y , z) zero)
max3' (succ x , succ y) (succ z) = succ (max3' (z , x) y)
|
{
"alphanum_fraction": 0.5452456191,
"avg_line_length": 21.6884735202,
"ext": "agda",
"hexsha": "64283e91cbe5f58f93131714d02b09f5bdf0955c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/Termination/Example.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/Termination/Example.agda",
"max_line_length": 77,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/Termination/Example.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": 2588,
"size": 6962
}
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.Adjunction.Composition where
open import Level
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.Adjunction
infixr 9 _∘_
_∘_ : ∀ {o ℓ e} {o₁ ℓ₁ e₁} {o₂ ℓ₂ e₂} {C : Category o ℓ e} {D : Category o₁ ℓ₁ e₁} {E : Category o₂ ℓ₂ e₂}
{F : Functor D C} {G : Functor C D} {H : Functor E D} {I : Functor D E} →
Adjunction F G → Adjunction H I → Adjunction (F ∘F H) (I ∘F G)
_∘_ {C = C} {D} {E} {F} {G} {H} {I} X Y = record
{ unit = (I ∘ˡ (Xη′ ∘ʳ H)) ∘₁ Yη′
; counit = Xε′ ∘₁ (F ∘ˡ (Yε′ ∘ʳ G))
; zig = λ {x} → zig′ {x}
; zag = λ {x} → zag′ {x}
}
where
module C = Category C
module D = Category D
module E = Category E
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 I = Functor I renaming (F₀ to I₀; F₁ to I₁; F-resp-≡ to I-resp-≡)
module X′ = Adjunction X renaming (unit to Xη′; counit to Xε′)
module Y′ = Adjunction Y renaming (unit to Yη′; counit to Yε′)
module Xη = NaturalTransformation (Adjunction.unit X) renaming (η to ηX)
module Yη = NaturalTransformation (Adjunction.unit Y) renaming (η to ηY)
module Xε = NaturalTransformation (Adjunction.counit X) renaming (η to εX)
module Yε = NaturalTransformation (Adjunction.counit Y) renaming (η to εY)
open C
open D
open E
open F
open G
open H
open I
open X′
open Y′
open Xη
open Yη
open Xε
open Yε
.zig′ : {x : E.Obj} →
C.id C.≡
(εX (F₀ (H₀ x)) C.∘ F₁ (εY (G₀ (F₀ (H₀ x))))) C.∘
F₁ (H₁ (I₁ (ηX (H₀ x)) E.∘ ηY x))
zig′ {x} =
begin
C.id
↑⟨ F.identity ⟩
F₁ D.id
↓⟨ F-resp-≡ Y′.zig ⟩
F₁ (D [ εY (H₀ x) ∘ H₁ (ηY x) ])
↓⟨ F.homomorphism ⟩
F₁ (εY (H₀ x)) C.∘ F₁ (H₁ (ηY x))
↑⟨ C.∘-resp-≡ˡ C.identityˡ ⟩
(C.id C.∘ F₁ (εY (H₀ x))) C.∘
F₁ (H₁ (ηY x))
↓⟨ C.∘-resp-≡ˡ (C.∘-resp-≡ˡ X′.zig) ⟩
((εX (F₀ (H₀ x)) C.∘ F₁ (ηX (H₀ x))) C.∘ F₁ (εY (H₀ x))) C.∘
F₁ (H₁ (ηY x))
↓⟨ C.∘-resp-≡ˡ C.assoc ⟩
(εX (F₀ (H₀ x)) C.∘ F₁ (ηX (H₀ x)) C.∘ F₁ (εY (H₀ x))) C.∘
F₁ (H₁ (ηY x))
↓⟨ C.assoc ⟩
εX (F₀ (H₀ x)) C.∘ (F₁ (ηX (H₀ x)) C.∘ F₁ (εY (H₀ x))) C.∘ F₁ (H₁ (ηY x))
↑⟨ C.∘-resp-≡ʳ (C.∘-resp-≡ˡ F.homomorphism) ⟩
εX (F₀ (H₀ x)) C.∘ F₁ (ηX (H₀ x) D.∘ εY (H₀ x)) C.∘ F₁ (H₁ (ηY x))
↑⟨ C.∘-resp-≡ʳ F.homomorphism ⟩
εX (F₀ (H₀ x)) C.∘ F₁ ((ηX (H₀ x) D.∘ εY (H₀ x)) D.∘ H₁ (ηY x))
↑⟨ C.∘-resp-≡ʳ (F-resp-≡ (D.∘-resp-≡ˡ (Yε.commute (ηX (H₀ x))))) ⟩
εX (F₀ (H₀ x)) C.∘
F₁ ((εY (G₀ (F₀ (H₀ x))) D.∘ H₁ (I₁ (ηX (H₀ x)))) D.∘ H₁ (ηY x))
↓⟨ C.∘-resp-≡ʳ (F-resp-≡ D.assoc) ⟩
εX (F₀ (H₀ x)) C.∘
F₁ (εY (G₀ (F₀ (H₀ x))) D.∘ D [ H₁ (I₁ (ηX (H₀ x))) ∘ H₁ (ηY x) ])
↑⟨ C.∘-resp-≡ʳ (F-resp-≡ (D.∘-resp-≡ʳ H.homomorphism)) ⟩
εX (F₀ (H₀ x)) C.∘
F₁ (D [ εY (G₀ (F₀ (H₀ x))) ∘ H₁ (I₁ (ηX (H₀ x)) E.∘ ηY x) ])
↓⟨ C.∘-resp-≡ʳ F.homomorphism ⟩
εX (F₀ (H₀ x)) C.∘
F₁ (εY (G₀ (F₀ (H₀ x)))) C.∘ F₁ (H₁ (I₁ (ηX (H₀ x)) E.∘ ηY x))
↑⟨ C.assoc ⟩
(εX (F₀ (H₀ x)) C.∘ F₁ (εY (G₀ (F₀ (H₀ x))))) C.∘
F₁ (H₁ (I₁ (ηX (H₀ x)) E.∘ ηY x))
∎
where open C.HomReasoning
.zag′ : {x : C.Obj} →
E.id E.≡
I₁ (G₁ (εX x C.∘ F₁ (εY (G₀ x)))) E.∘
I₁ (ηX (H₀ (I₀ (G₀ x)))) E.∘ ηY (I₀ (G₀ x))
zag′ {x} =
begin
E.id
↓⟨ Y′.zag ⟩
(I₁ (εY (G₀ x))) E.∘ (ηY (I₀ (G₀ x)))
↑⟨ E.∘-resp-≡ˡ (I-resp-≡ D.identityˡ) ⟩
(I₁ (D.id D.∘ (εY (G₀ x)))) E.∘ (ηY (I₀ (G₀ x)))
↓⟨ E.∘-resp-≡ˡ (I-resp-≡ (D.∘-resp-≡ˡ X′.zag)) ⟩
(I₁ ((G₁ (εX x) D.∘ (ηX (G₀ x))) D.∘ (εY (G₀ x)))) E.∘ (ηY (I₀ (G₀ x)))
↓⟨ E.∘-resp-≡ˡ (I-resp-≡ D.assoc) ⟩
I₁ (G₁ (εX x) D.∘ ηX (G₀ x) D.∘ εY (G₀ x)) E.∘ ηY (I₀ (G₀ x))
↓⟨ E.∘-resp-≡ˡ (I-resp-≡ (D.∘-resp-≡ʳ (Xη.commute (εY (G₀ x))))) ⟩
I₁ (G₁ (εX x) D.∘ G₁ (F₁ (εY (G₀ x))) D.∘ ηX (H₀ (I₀ (G₀ x)))) E.∘
ηY (I₀ (G₀ x))
↑⟨ E.∘-resp-≡ˡ (I-resp-≡ D.assoc) ⟩
I₁ (D [ G₁ (εX x) ∘ G₁ (F₁ (εY (G₀ x))) ] D.∘ ηX (H₀ (I₀ (G₀ x))))
E.∘ ηY (I₀ (G₀ x))
↑⟨ E.∘-resp-≡ˡ (I-resp-≡ (D.∘-resp-≡ˡ G.homomorphism)) ⟩
I₁ (D [ G₁ (εX x C.∘ F₁ (εY (G₀ x))) ∘ ηX (H₀ (I₀ (G₀ x))) ]) E.∘
ηY (I₀ (G₀ x))
↓⟨ E.∘-resp-≡ˡ I.homomorphism ⟩
(I₁ (G₁ (εX x C.∘ F₁ (εY (G₀ x)))) E.∘ I₁ (ηX (H₀ (I₀ (G₀ x))))) E.∘
ηY (I₀ (G₀ x))
↓⟨ E.assoc ⟩
I₁ (G₁ (εX x C.∘ F₁ (εY (G₀ x)))) E.∘
I₁ (ηX (H₀ (I₀ (G₀ x)))) E.∘ ηY (I₀ (G₀ x))
∎
where open E.HomReasoning
|
{
"alphanum_fraction": 0.4468659595,
"avg_line_length": 40.5078125,
"ext": "agda",
"hexsha": "4f1262fb46f1239f1127db4e408697cc242ebc2a",
"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/Composition.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/Composition.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/Composition.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": 2641,
"size": 5185
}
|
module Lec7 where
open import Lec1Done
data List (X : Set) : Set where
[] : List X
_,-_ : X -> List X -> List X
foldrL : {X T : Set} -> (X -> T -> T) -> T -> List X -> T
foldrL c n [] = n
foldrL c n (x ,- xs) = c x (foldrL c n xs)
data Bwd (X : Set) : Set where
[] : Bwd X
_-,_ : Bwd X -> X -> Bwd X
infixl 3 _-,_
data _<=_ {X : Set} : (xz yz : Bwd X) -> Set where
oz : [] <= []
os : {xz yz : Bwd X}{y : X} -> xz <= yz -> (xz -, y) <= (yz -, y)
o' : {xz yz : Bwd X}{y : X} -> xz <= yz -> xz <= (yz -, y)
oe : {X : Set}{xz : Bwd X} -> [] <= xz
oe {_} {[]} = oz
oe {_} {xz -, _} = o' oe
oi : {X : Set}{xz : Bwd X} -> xz <= xz
oi {_} {[]} = oz
oi {_} {xz -, _} = os oi -- look here...
_<o<_ : {X : Set}{xz yz zz : Bwd X} -> xz <= yz -> yz <= zz -> xz <= zz
th <o< o' ph = o' (th <o< ph)
oz <o< oz = oz
os th <o< os ph = os (th <o< ph) -- ...and here
o' th <o< os ph = o' (th <o< ph)
Elem : {X : Set} -> X -> Bwd X -> Set
Elem x yz = ([] -, x) <= yz
data Ty : Set where
one : Ty
list : Ty -> Ty
_=>_ : Ty -> Ty -> Ty
infixr 4 _=>_
Val : Ty -> Set
Val one = One
Val (list T) = List (Val T)
Val (S => T) = Val S -> Val T
data Tm (Tz : Bwd Ty) : Ty -> Set where
var : {T : Ty} -> Elem T Tz -> Tm Tz T
<> : Tm Tz one
[] : {T : Ty} -> Tm Tz (list T)
_,-_ : {T : Ty} -> Tm Tz T -> Tm Tz (list T) -> Tm Tz (list T)
foldr : {S T : Ty} ->
Tm Tz (S => T => T) ->
Tm Tz T ->
Tm Tz (list S)
-> Tm Tz T
lam : {S T : Ty} ->
Tm (Tz -, S) T
-> Tm Tz (S => T)
_$$_ : {S T : Ty} ->
Tm Tz (S => T) ->
Tm Tz S
-> Tm Tz T
infixl 3 _$$_
All : {X : Set} -> (X -> Set) -> Bwd X -> Set
All P [] = One
All P (xz -, x) = All P xz * P x
all : {X : Set}{P Q : X -> Set}(f : (x : X) -> P x -> Q x) -> (xz : Bwd X) -> All P xz -> All Q xz
all f [] <> = <>
all f (xz -, x) (pz , p) = all f xz pz , f x p
Env : Bwd Ty -> Set
Env = All Val
select : {X : Set}{P : X -> Set}{Sz Tz : Bwd X} -> Sz <= Tz -> All P Tz -> All P Sz
select oz <> = <>
select (os x) (vz , v) = select x vz , v
select (o' x) (vz , v) = select x vz
eval : {Tz : Bwd Ty}{T : Ty} -> Env Tz -> Tm Tz T -> Val T
eval vz (var x) with select x vz
eval vz (var x) | <> , v = v
eval vz <> = <>
eval vz [] = []
eval vz (t ,- ts) = eval vz t ,- eval vz ts
eval vz (foldr c n ts) = foldrL (eval vz c) (eval vz n) (eval vz ts)
eval vz (lam t) = \ s -> eval (vz , s) t
eval vz (f $$ s) = eval vz f (eval vz s)
append : {Tz : Bwd Ty}{T : Ty} ->
Tm Tz (list T => list T => list T)
append = lam (lam (foldr (lam (lam (var (o' (os oe)) ,- var (os oe))))
(var (os oe)) (var (o' (os oe)))))
test : Val (list one)
test = eval {[]} <> (append $$ (<> ,- []) $$ (<> ,- []))
thin : {Sz Tz : Bwd Ty} -> Sz <= Tz -> {S : Ty} -> Tm Sz S -> Tm Tz S
thin th (var x) = var (x <o< th)
thin th <> = <>
thin th [] = []
thin th (t ,- ts) = thin th t ,- thin th ts
thin th (foldr c n ts) = foldr (thin th c) (thin th n) (thin th ts)
thin th (lam t) = lam (thin (os th) t)
thin th (f $$ s) = thin th f $$ thin th s
Subst : Bwd Ty -> Bwd Ty -> Set
Subst Sz Tz = All (Tm Tz) Sz
subst : {Sz Tz : Bwd Ty} -> Subst Sz Tz -> {S : Ty} -> Tm Sz S -> Tm Tz S
subst tz (var x) with select x tz
subst tz (var x) | <> , t = t
subst tz <> = <>
subst tz [] = []
subst tz (t ,- ts) = subst tz t ,- subst tz ts
subst tz (foldr c n ts) = foldr (subst tz c) (subst tz n) (subst tz ts)
subst tz (lam t) = lam (subst (all (\ T -> thin (o' oi)) _ tz , (var (os oe))) t)
subst tz (f $$ s) = subst tz f $$ subst tz s
record Action (M : Bwd Ty -> Bwd Ty -> Set) : Set where
field
varA : forall {S Sz Tz} -> M Sz Tz -> Elem S Sz -> Tm Tz S
lamA : forall {S Sz Tz} -> M Sz Tz -> M (Sz -, S) (Tz -, S)
act : {Sz Tz : Bwd Ty} -> M Sz Tz -> {S : Ty} -> Tm Sz S -> Tm Tz S
act m (var x) = varA m x
act m <> = <>
act m [] = []
act m (t ,- ts) = act m t ,- act m ts
act m (foldr c n ts) = foldr (act m c) (act m n) (act m ts)
act m (lam t) = lam (act (lamA m) t)
act m (f $$ s) = act m f $$ act m s
THIN : Action _<=_
Action.varA THIN th x = var (x <o< th)
Action.lamA THIN = os
SUBST : Action Subst
Action.varA SUBST tz x with select x tz
... | <> , t = t
Action.lamA SUBST tz = all (\ T -> Action.act THIN (o' oi)) _ tz , (var (os oe))
-- substitution
-- thinning
-- abstr-action
|
{
"alphanum_fraction": 0.4587837838,
"avg_line_length": 28.2802547771,
"ext": "agda",
"hexsha": "fe2674d07d9dc9216c345357978f19eadb884821",
"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/Lec7.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/Lec7.agda",
"max_line_length": 98,
"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/Lec7.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": 1851,
"size": 4440
}
|
module lambda.vec where
open import Data.Nat
open import Data.Fin hiding (_+_)
infixr 40 _▸_
data vec (T : Set) : ℕ → Set where
ε : vec T 0
_▸_ : ∀ {n} → vec T n → T → vec T (suc n)
lookup : ∀ {n} → {T : Set} → Fin n → vec T n → T
lookup zero (Γ ▸ x) = x
lookup (suc i) (Γ ▸ x) = lookup i Γ
|
{
"alphanum_fraction": 0.5652173913,
"avg_line_length": 19.9333333333,
"ext": "agda",
"hexsha": "4d43d3caf85031b156ab1e156935a3b8106cd268",
"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": "09a231d9b3057d57b864070188ed9fe14a07eda2",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "Lapin0t/lambda",
"max_forks_repo_path": "lambda/vec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09a231d9b3057d57b864070188ed9fe14a07eda2",
"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": "Lapin0t/lambda",
"max_issues_repo_path": "lambda/vec.agda",
"max_line_length": 48,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "09a231d9b3057d57b864070188ed9fe14a07eda2",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "Lapin0t/lambda",
"max_stars_repo_path": "lambda/vec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 126,
"size": 299
}
|
{-# OPTIONS --without-K #-}
module PiIter where
open import Level using (_⊔_) renaming (zero to l0; suc to lsuc)
open import Universe using (Universe)
open import Categories.Category using (Category)
open import Categories.Groupoid using (Groupoid)
open import Categories.Functor using (Functor)
open import Data.Empty using (⊥)
open import Data.Unit using (⊤; tt)
open import Data.Sum hiding ([_,_])
open import Data.Product
open import Relation.Binary.PropositionalEquality as P
open import Function using (flip)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Nat.Properties.Simple using (+-right-identity)
open import Data.Integer using (ℤ;+_;-[1+_]) renaming (suc to ℤsuc; -_ to ℤ-; _+_ to _ℤ+_)
open import PiU using (U; ZERO; ONE; PLUS; TIMES; toℕ)
open import PiLevel0
open import PiLevel1
open import PiEquiv renaming (eval to ap; evalB to apB)
open import Equiv
infix 40 _^_
_^_ : {τ : U} → (p : τ ⟷ τ) → (k : ℤ) → (τ ⟷ τ)
p ^ (+ 0) = id⟷
p ^ (+ (suc k)) = p ◎ (p ^ (+ k))
p ^ -[1+ 0 ] = ! p
p ^ (-[1+ (suc k) ]) = (! p) ◎ (p ^ -[1+ k ])
-- useful properties of ^
-- because ^ is iterated composition of the same thing,
-- then by associativity, we can hive off compositions
-- from left or right
assoc1 : {τ : U} → {p : τ ⟷ τ} → (m : ℕ) →
(p ◎ (p ^ (+ m))) ⇔ ((p ^ (+ m)) ◎ p)
assoc1 ℕ.zero = trans⇔ idr◎l idl◎r
assoc1 (suc m) = trans⇔ (id⇔ ⊡ assoc1 m) assoc◎l
assoc1- : {τ : U} → {p : τ ⟷ τ} → (m : ℕ) →
((! p) ◎ (p ^ -[1+ m ])) ⇔ ((p ^ -[1+ m ]) ◎ (! p))
assoc1- ℕ.zero = id⇔
assoc1- (suc m) = trans⇔ (id⇔ ⊡ assoc1- m) assoc◎l
-- more generally
assoc1g : {τ : U} → {p : τ ⟷ τ} → (i : ℤ) →
(p ◎ (p ^ i)) ⇔ ((p ^ i) ◎ p)
assoc1g (+_ n) = assoc1 n
assoc1g (-[1+_] zero) = trans⇔ linv◎l rinv◎r
assoc1g (-[1+_] (suc n)) = trans⇔ assoc◎l (trans⇔ (linv◎l ⊡ id⇔) (
trans⇔ idl◎l (2! (trans⇔ (assoc1- n ⊡ id⇔) (trans⇔ assoc◎r
(trans⇔ (id⇔ ⊡ rinv◎l) idr◎l))))))
-- Property of ^: negating exponent is same as
-- composing in the other direction, then reversing.
^⇔! : {τ : U} → {p : τ ⟷ τ} → (k : ℤ) →
(p ^ (ℤ- k)) ⇔ ! (p ^ k)
^⇔! (+_ ℕ.zero) = id⇔
-- need to dig deeper, as we end up negating
^⇔! (+_ (suc ℕ.zero)) = idl◎r
^⇔! (+_ (suc (suc n))) = trans⇔ (assoc1- n) (^⇔! (+ suc n) ⊡ id⇔)
^⇔! {p = p} (-[1+_] ℕ.zero) = trans⇔ idr◎l (2! !!⇔id) -- (!!⇔id {c = p})
^⇔! {p = p} (-[1+_] (suc n)) =
trans⇔ (assoc1 (suc n)) ((^⇔! -[1+ n ]) ⊡ 2! !!⇔id) -- (!!⇔id p))
-- first match on m, n, then proof is purely PiLevel1
lower : {τ : U} {p : τ ⟷ τ} (m n : ℤ) →
p ^ (m ℤ+ n) ⇔ ((p ^ m) ◎ (p ^ n))
lower (+_ ℕ.zero) (+_ n) = idl◎r
lower (+_ ℕ.zero) (-[1+_] n) = idl◎r
lower (+_ (suc m)) (+_ n) =
trans⇔ (id⇔ ⊡ lower (+ m) (+ n)) assoc◎l
lower {p = p} (+_ (suc m)) (-[1+_] ℕ.zero) =
trans⇔ idr◎r (trans⇔ (id⇔ ⊡ linv◎r) (
trans⇔ assoc◎l (2! (assoc1 m) ⊡ id⇔))) -- p ^ ((m + 1) -1)
lower (+_ (suc m)) (-[1+_] (suc n)) = -- p ^ ((m + 1) -(1+1+n)
trans⇔ (lower (+ m) (-[1+ n ])) (
trans⇔ ((trans⇔ idr◎r (id⇔ ⊡ linv◎r)) ⊡ id⇔) (
trans⇔ assoc◎r (trans⇔ (id⇔ ⊡ assoc◎r) (
trans⇔ assoc◎l (2! (assoc1 m) ⊡ id⇔)))))
lower (-[1+_] m) (+_ ℕ.zero) = idr◎r
lower (-[1+_] ℕ.zero) (+_ (suc n)) = 2! (trans⇔ assoc◎l (
trans⇔ (rinv◎l ⊡ id⇔) idl◎l))
lower (-[1+_] (suc m)) (+_ (suc n)) = -- p ^ (-(1+m) + (n+1))
trans⇔ (lower (-[1+ m ]) (+ n)) (
trans⇔ ((trans⇔ idr◎r (id⇔ ⊡ rinv◎r)) ⊡ id⇔) (
trans⇔ assoc◎r (trans⇔ (id⇔ ⊡ assoc◎r) (
trans⇔ assoc◎l ((2! (assoc1- m)) ⊡ id⇔)))))
lower (-[1+_] ℕ.zero) (-[1+_] n) = id⇔
lower (-[1+_] (suc m)) (-[1+_] n) = -- p ^ (-(1+1+m) - (1+n))
trans⇔ (id⇔ ⊡ lower (-[1+ m ]) (-[1+ n ])) assoc◎l
-- i.e. Iter is: for all i, any p' such that
-- p' ⇔ p ^ i
record Iter {τ : U} (p : τ ⟷ τ) : Set where
constructor iter
field
i : ℤ
p' : τ ⟷ τ
p'⇔p^i : p' ⇔ (p ^ i)
-- Equality of Iter.
record _≡c_ {τ : U} {p : τ ⟷ τ} (q r : Iter p) : Set where
constructor eqc
field
iter≡ : Iter.i q ≡ Iter.i r
p⇔ : Iter.p' q ⇔ Iter.p' r
-- Iterates of id⟷
id^i≡id : {t : U} (i : ℤ) → (id⟷ ^ i) ⇔ (id⟷ {t})
id^i≡id (+_ zero) = id⇔
id^i≡id (+_ (suc n)) = trans⇔ idl◎l (id^i≡id (+ n))
id^i≡id (-[1+_] zero) = id⇔
id^i≡id (-[1+_] (suc n)) = trans⇔ idl◎l (id^i≡id -[1+ n ])
|
{
"alphanum_fraction": 0.5178871549,
"avg_line_length": 33.5887096774,
"ext": "agda",
"hexsha": "d750edc561521259331819733002822d0d567473",
"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": "Univalence/PiIter.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": "Univalence/PiIter.agda",
"max_line_length": 90,
"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": "Univalence/PiIter.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": 2033,
"size": 4165
}
|
-- An ATP conjecture must be used with postulates.
-- This error is detected by TypeChecking.Rules.Decl.
module ATPBadConjecture2 where
data Bool : Set where
false true : Bool
{-# ATP prove Bool #-}
|
{
"alphanum_fraction": 0.7317073171,
"avg_line_length": 18.6363636364,
"ext": "agda",
"hexsha": "2e8dbffc63d97204273bc14515d7c5f011256cef",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "asr/eagda",
"max_forks_repo_path": "test/fail/ATPBadConjecture2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "asr/eagda",
"max_issues_repo_path": "test/fail/ATPBadConjecture2.agda",
"max_line_length": 53,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "asr/eagda",
"max_stars_repo_path": "test/fail/ATPBadConjecture2.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": 51,
"size": 205
}
|
{-# OPTIONS --sized-types #-}
module Automaton.Deterministic.FormalLanguage where
open import Automaton.Deterministic.Finite
open import Automaton.Deterministic
open import Data.Boolean
import Data.Boolean.Operators
open Data.Boolean.Operators.Programming
open import Data.List renaming (∅ to [])
open import Functional
import Lvl
open import Type
open import Type.Size.Finite
private variable ℓ ℓ₁ ℓ₂ ℓₚ : Lvl.Level
private variable Q Q₁ Q₂ State : Type{ℓ}
private variable Σ Σ₁ Σ₂ Alphabet : Type{ℓ}
module Language where
open import Logic.Propositional
open import Logic.Predicate
open import FormalLanguage
open import FormalLanguage.Equals
open import Relator.Equals
open import Relator.Equals.Proofs
import Type.Dependent as Type
-- The language accepted by a DFA.
-- This is a linguistic interpretation of an automaton, that it is a grammar of the language.
-- A language accepts the empty word when the start state is a final state.
-- The language of a suffix is the transition function applied to the start state.
𝔏 : ∀{s} → DFA{ℓₚ = ℓₚ}(Q)(Σ) → Language(Σ){s}
Language.accepts-ε (𝔏(d)) = DFA.isFinal d (DFA.start d)
Language.suffix-lang (𝔏(d)) c = 𝔏(DFA.transitionedAutomaton d c)
RegularLanguage : ∀{s}{ℓₚ ℓₑ₁} → Language(Σ) → Type
RegularLanguage{Σ = Σ}{s = s}{ℓₚ = ℓₚ}{ℓₑ₁ = ℓₑ₁} L = ∃{Obj = Type.Σ(Type{ℓₑ₁})(Q ↦ DFA{ℓₚ = ℓₚ}(Q)(Σ))}(\(Type.intro _ auto) → (𝔏(auto) ≅[ s ]≅ L))
module Proofs where
open Language
open import Logic.Propositional
open import Relator.Equals
open import Relator.Equals.Proofs
open import FormalLanguage
open FormalLanguage.Oper hiding (∁_)
open import Syntax.Transitivity
-- TODO: Is this wrong?
-- step-isWordAccepted : ∀{Q}{Σ} → (auto : DFA(Q)(Σ)) → ∀{c}{w} → DFA.isWordAccepted(auto)(c ⊰ w) ≡ DFA.isWordAccepted(Dfa (DFA.δ auto) (DFA.δ(auto)(DFA.q₀(auto))(c)) (DFA.F auto))(w)
-- step-isWordAccepted auto {c}{[]} = [≡]-intro
-- step-isWordAccepted auto {c}{w} = congruence₁(DFA.F(auto)) [≡]-intro
Language-isWordAccepted : ∀{Q}{Σ} → (auto : DFA(Q)(Σ)) → ∀{w} → ({!DFA.isWordAccepted auto w!} ≡ (w ∈? 𝔏(auto)))
{-
Language-isWordAccepted : ∀{Q}{Σ} → (auto : DFA(Q)(Σ)) → ∀{w} → (DFA.isWordAccepted(auto)(w) ≡ w ∈? 𝔏(auto))
Language-isWordAccepted auto {[]} = [≡]-intro
Language-isWordAccepted auto {x ⊰ w} =
DFA.isWordAccepted(auto)(x ⊰ w) 🝖[ _≡_ ]-[]
δ̂(q₀)(x ⊰ w) ∈ F 🝖[ _≡_ ]-[]
δ̂(δ(q₀) x) w ∈ F 🝖[ _≡_ ]-[ {!Language-isWordAccepted (transitionedAutomaton auto x) {w}!} ]
DFA.isWordAccepted(transitionedAutomaton auto x) w 🝖[ _≡_ ]-[ Language-isWordAccepted (transitionedAutomaton auto x) {w} ]
w ∈? Language.suffix-lang(𝔏(auto))(x) 🝖[ _≡_ ]-[]
(x ⊰ w) ∈? 𝔏(auto) 🝖-end
where
open DFA(auto)
open LetterNotation
-- [≡]-with {!DFA.F(auto)!} (Language-isWordAccepted {Σ = Σ} auto {w})
-}
-- Language-isWordAccepted (_) {[]} = [≡]-intro
-- Language-isWordAccepted (Dfa δ q₀ F) {c ⊰ w} = test(Dfa δ q₀ F){c ⊰ w} -- Language-isWordAccepted (Dfa δ (δ(q₀)(c)) F) {w}
-- DFA.isWordAccepted(auto)(c ⊰ w)
-- DFA.isWordAccepted(Dfa δ q₀ F)(c ⊰ w)
-- F(δ̂(q₀)(c ⊰ w))
-- F(δ̂(δ(q₀)(c))(w))
-- (c ⊰ w) ∈? (𝔏(auto))
-- (c ⊰ w) ∈? (𝔏(Dfa δ q₀ F))
-- w ∈? (Language.suffix-lang(𝔏(Dfa δ q₀ F))(c))
-- w ∈? (𝔏(Dfa δ (δ(q₀)(c)) F))
{-
module _ (auto : Deterministic(Q)(Σ)) where
δ̂-with-[++] : ∀{q : Q}{w₁ w₂ : Word(Σ)} → Deterministic.δ̂(auto)(q)(w₁ ++ w₂) ≡ DFA.δ̂(auto)(DFA.δ̂(auto)(q)(w₁))(w₂)
δ̂-with-[++] {_}{[]} = [≡]-intro
δ̂-with-[++] {q}{a ⊰ w₁}{w₂} = δ̂-with-[++] {Deterministic.δ(auto)(q)(a)}{w₁}{w₂}
[∁]-δ̂ : ∀{q : Q}{w : Word(Σ)} → DFA.δ̂(∁ auto)(q)(w) ≡ DFA.δ̂(auto)(q)(w)
[∁]-δ̂ {_}{[]} = [≡]-intro
[∁]-δ̂ {q}{a ⊰ w} = [∁]-δ̂ {DFA.δ(∁ auto)(q)(a)}{w}
[∁]-isWordAccepted : ∀{w} → DFA.isWordAccepted(∁ auto)(w) ≡ !(DFA.isWordAccepted(auto)(w))
[∁]-isWordAccepted {w} = [≡]-with(x ↦ !(DFA.F(auto)(x))) ([∁]-δ̂{DFA.q₀(auto)}{w})
-- TODO: Prove ∁ postulates regarding languages before accepting them, because the definition of ∁ for languages might be wrong.
-- [∁]-language : 𝔏(∁ auto) ≡ Oper.∁(𝔏(auto))
-- [∁]-language = proof(auto) where
-- proof : (auto : DFA(Q)(Σ)) → 𝔏(∁ auto) ≡ Oper.∁(𝔏(auto))
-- proof(Dfa δ q₀ F) = [≡]-substitutionₗ {Lvl.𝟎}{Lvl.𝐒(Lvl.𝟎)} [∁]-language {expr ↦ Lang (! F(q₀)) (c ↦ expr(c))} ([≡]-intro {Lvl.𝟎}{Lvl.𝐒(Lvl.𝟎)})
-- [≡]-substitution-fnₗ : ∀{T₁ T₂}{x y : T₁ → T₂} → ((c : T₁) → (x(c) ≡ y(c))) → ∀{f : (T₁ → T₂) → TypeN{ℓ₃}} → f(x) ← f(y)
-- [≡]-substitution-fnₗ [≡]-intro = id?
-- 𝔏(∁(Dfa δ q₀ F))
-- = 𝔏(Dfa δ q₀ ((!_) ∘ F))
-- = Lang ((!_) ∘ F)(q₀)) (c ↦ 𝔏(Dfa δ (δ(q₀)(c)) ((!_) ∘ F)))
-- Oper.∁(𝔏(Dfa δ q₀ F))
-- = Lang (! F(q₀)) (c ↦ ∁(𝔏(Dfa δ (δ(q₀)(c)) F)))
-- = ?
-- testtt : ∀{auto} → Language.accepts-ε(𝔏{Q}{Σ}(∁ auto)) ≡ ! Language.accepts-ε(𝔏(auto))
-- testtt : ∀{auto} → Language.accepts-ε(𝔏{Q}{Σ}(∁ auto)) ≡ Language.accepts-ε(Oper.∁ 𝔏(auto))
-- testtt {_} = [≡]-intro
-- testtt2 : ∀{auto}{c} → Language.suffix-lang(𝔏(∁ auto))(c) ≡ Oper.∁(Language.suffix-lang(𝔏(auto))(c))
-- testtt2 : ∀{auto}{c} → Language.suffix-lang(𝔏(∁ auto))(c) ≡ Language.suffix-lang(Oper.∁(𝔏(auto)))(c)
-- testtt2 : ∀{auto}{c} → Language.suffix-lang(Oper.∁(𝔏{Q}{Σ}(auto)))(c) ≡ Oper.∁(Language.suffix-lang(𝔏(auto))(c))
-- testtt2 {Dfa δ q₀ F}{_} = [≡]-intro
module _ (auto : DFA(Q₁)(Σ)) (auto₂ : DFA(Q₂)(Σ)) where
[⨯]-δ̂ : ∀{q₁ : Q₁}{q₂ : Q₂}{w : Word(Σ)} → DFA.δ̂(auto ⨯ auto₂)(q₁ , q₂)(w) ≡ (DFA.δ̂(auto)(q₁)(w) , DFA.δ̂(auto₂)(q₂)(w))
[⨯]-δ̂ {_}{_}{[]} = [≡]-intro
[⨯]-δ̂ {q₁}{q₂}{a ⊰ w} = [⨯]-δ̂ {DFA.δ(auto)(q₁)(a)}{DFA.δ(auto₂)(q₂)(a)}{w}
[+]-δ̂ : ∀{q₁ : Q₁}{q₂ : Q₂}{w : Word(Σ)} → DFA.δ̂(auto + auto₂)(q₁ , q₂)(w) ≡ (DFA.δ̂(auto)(q₁)(w) , DFA.δ̂(auto₂)(q₂)(w))
[+]-δ̂ {_}{_}{[]} = [≡]-intro
[+]-δ̂ {q₁}{q₂}{a ⊰ w} = [+]-δ̂ {DFA.δ(auto)(q₁)(a)}{DFA.δ(auto₂)(q₂)(a)}{w}
-- TODO: δ̂-on-[𝁼]
[⨯]-isWordAccepted : ∀{w} → DFA.isWordAccepted(auto ⨯ auto₂)(w) ≡ DFA.isWordAccepted(auto)(w) && DFA.isWordAccepted(auto₂)(w)
[⨯]-isWordAccepted {w} = [≡]-with(DFA.F(auto ⨯ auto₂)) ([⨯]-δ̂{DFA.q₀(auto)}{DFA.q₀(auto₂)}{w})
[+]-isWordAccepted : ∀{w} → DFA.isWordAccepted(auto + auto₂)(w) ≡ DFA.isWordAccepted(auto)(w) || DFA.isWordAccepted(auto₂)(w)
[+]-isWordAccepted {w} = [≡]-with(DFA.F(auto + auto₂)) ([+]-δ̂{DFA.q₀(auto)}{DFA.q₀(auto₂)}{w})
-- TODO: Prove postulates
postulate [⨯]-language : 𝔏(auto ⨯ auto₂) ≡ 𝔏(auto) ∩ 𝔏(auto₂)
postulate [+]-language : 𝔏(auto + auto₂) ≡ 𝔏(auto) ∪ 𝔏(auto₂)
-}
|
{
"alphanum_fraction": 0.5520726527,
"avg_line_length": 47.7412587413,
"ext": "agda",
"hexsha": "e4a07c715f03feacf5b4ea6d524d985c8659ec57",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Automaton/Deterministic/FormalLanguage.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Automaton/Deterministic/FormalLanguage.agda",
"max_line_length": 185,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Automaton/Deterministic/FormalLanguage.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": 2896,
"size": 6827
}
|
module Array.Repr where
open import Array.Base
open import Data.Nat
open import Data.Vec as V
open import Data.Fin using (Fin; zero; suc; raise)
open import Relation.Binary.PropositionalEquality
open import Function
-- This is a function that inductively generates a Vec-based type
-- for the given arguments of Ar.
repr-t : ∀ {a} → (X : Set a) → (n : ℕ) → (s : Vec ℕ n) → Set a
repr-t X zero s = X
repr-t X (suc n) (x ∷ s) = Vec (repr-t X n s) x
a→rt : ∀ {a}{X : Set a}{n s} → Ar X n s → repr-t X n s
a→rt {n = zero} {s = []} (imap f) = f []
a→rt {n = suc n} {x ∷ s} (imap f) = tabulate λ i → a→rt (imap (λ iv → f (i ∷ iv)))
rt→a : ∀ {a}{X : Set a}{n s} → repr-t X n s → Ar X n s
rt→a {n = zero} {s} x = imap (λ _ → x)
rt→a {n = suc n} {s ∷ _} x = imap λ where
(i ∷ iv) → case rt→a (lookup x i) of λ where
(imap f) → f iv
-- This is an inductive type for tensors
data Tensor {a} (X : Set a) : (n : ℕ) → (s : Vec ℕ n) → Set a where
zz : (x : X) → Tensor X 0 []
ss : ∀ {n m}{s : Vec ℕ n} → (v : Vec (Tensor X n s) m) → Tensor X (1 + n) (m ∷ s)
-- Ugh, well... This is big because we have to formulate point-wise equality.
data EqTen {a} (X : Set a) : (n : ℕ) → ∀ {s s₁} → Tensor X n s → Tensor X n s₁ → Set a where
zeq : ∀ {x} → EqTen X 0 (zz x) (zz x)
s[] : ∀ {n}{s s₁ : Vec ℕ n}
→ (∀ i → lookup s i ≡ lookup s₁ i)
→ EqTen X (1 + n) (ss {s = s} []) (ss {s = s₁} [])
s∷ : ∀ {n}{s s₁ : Vec ℕ n}{m}
→ (∀ i → lookup s i ≡ lookup s₁ i)
→ ∀ {x y xs ys}
→ EqTen X n {s = s} {s₁ = s₁} x y
→ EqTen X (1 + n) (ss {m = m} xs) (ss {m = m} ys)
→ EqTen X (1 + n) (ss (x ∷ xs)) (ss (y ∷ ys))
a→tensor : ∀ {a}{X : Set a}{n s} → Ar X n s → Tensor X n s
a→tensor {n = zero} {s = []} (imap f) = zz (f [])
a→tensor {n = suc n}{s = s ∷ _} (imap f) = ss $ tabulate λ i → a→tensor (imap (λ iv → f (i ∷ iv)))
tensor→a : ∀ {a}{X : Set a}{n s} → Tensor X n s → Ar X n s --(lookup s)
tensor→a {s = []} (zz x) = imap (λ _ → x)
tensor→a {s = a ∷ s} (ss v) = imap λ where
(i ∷ iv) → case tensor→a (lookup v i) of λ where
(imap f) → f iv
t→rt : ∀ {a}{X : Set a}{n s} → Tensor X n s → repr-t X n s
t→rt {s = []} (zz x) = x
t→rt {s = x₁ ∷ s} (ss v) = V.map t→rt v
rt→t : ∀ {a}{X : Set a}{n s} → repr-t X n s → Tensor X n s
rt→t {s = []} x = zz x
rt→t {s = _ ∷ _} x = ss (V.map rt→t x)
module test-repr where
a : Ar ℕ 2 (3 ∷ 3 ∷ [])
a = cst 42
at = (a→tensor a)
aₜ = tensor→a at
rt = a→rt a
a₁ = rt→a {n = 2} {s = 3 ∷ 3 ∷ []} rt
test₁ : t→rt at ≡ rt
test₁ = refl
-- This one is quite tricky to show
--test₂ : ∀ iv → sel a₁ iv ≡ sel aₜ iv
--test₂ iv = {!!}
|
{
"alphanum_fraction": 0.4680624556,
"avg_line_length": 33.1529411765,
"ext": "agda",
"hexsha": "07ddfc6d29122d49b828558930615c3f604986d6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-10-12T07:19:48.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-10-12T07:19:48.000Z",
"max_forks_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "ashinkarov/agda-array",
"max_forks_repo_path": "Array/Repr.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5",
"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-array",
"max_issues_repo_path": "Array/Repr.agda",
"max_line_length": 98,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "ashinkarov/agda-array",
"max_stars_repo_path": "Array/Repr.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-15T14:21:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-09T13:53:46.000Z",
"num_tokens": 1151,
"size": 2818
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Cost.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
private
variable
ℓ : Level
A B C : Type ℓ
Cost : (A : Type ℓ) → Type ℓ
Cost A = A × ∥ ℕ ∥
-- To compare two elements of Cost A we only need to look at the first parts
Cost≡ : (x y : Cost A) → x .fst ≡ y .fst → x ≡ y
Cost≡ _ _ = Σ≡Prop λ _ → squash
-- To make it easier to program with Cost A we prove that it forms a
-- monad which counts the number of calls to >>=. We could also turn
-- it into a proper state monad which tracks the cost, but for the
-- programs we write later this simple version suffices
_>>=_ : Cost A → (A → Cost B) → Cost B
(x , m) >>= g with g x
... | (y , n) = (y , map suc (map2 _+_ m n))
return : A → Cost A
return x = (x , ∣ 0 ∣)
-- The monad laws all hold by Cost≡
>>=-return : (f : Cost A) → f >>= return ≡ f
>>=-return f = Cost≡ _ _ refl
return->>= : (a : A) (f : A → Cost B) → return a >>= f ≡ f a
return->>= a f = Cost≡ _ _ refl
>>=-assoc : (f : Cost A) (g : A → Cost B) (h : B → Cost C)
→ (f >>= g) >>= h ≡ f >>= (λ x → g x >>= h)
>>=-assoc f g h = Cost≡ _ _ refl
-- An inefficient version of addition which recurses on both arguments
addBad : ℕ → ℕ → Cost ℕ
addBad 0 0 = return 0
addBad 0 (suc y) = do
x ← addBad 0 y
return (suc x)
addBad (suc x) y = do
z ← addBad x y
return (suc z)
-- More efficient addition which only recurse on the first argument
add : ℕ → ℕ → Cost ℕ
add 0 y = return y
add (suc x) y = do
z ← add x y
return (suc z)
private
-- addBad x y will do x + y calls
_ : addBad 3 5 ≡ (8 , ∣ 8 ∣)
_ = refl
-- add x y will only do x recursive calls
_ : add 3 5 ≡ (8 , ∣ 3 ∣)
_ = refl
-- Despite addBad and add having different cost we can still prove
-- that they are equal functions
add≡addBad : add ≡ addBad
add≡addBad i x y = Cost≡ (add x y) (addBad x y) (rem x y) i
where
rem : (x y : ℕ) → add x y .fst ≡ addBad x y .fst
rem 0 0 = refl
rem 0 (suc y) = cong suc (rem 0 y)
rem (suc x) y = cong suc (rem x y)
-- Another example: computing Fibonacci numbers
fib : ℕ → Cost ℕ
fib 0 = return 0
fib 1 = return 1
fib (suc (suc x)) = do
y ← fib (suc x)
z ← fib x
return (y + z)
fibTail : ℕ → Cost ℕ
fibTail 0 = return 0
fibTail (suc x) = fibAux x 1 0
where
fibAux : ℕ → ℕ → ℕ → Cost ℕ
fibAux 0 res _ = return res
fibAux (suc x) res prev = do
r ← fibAux x (res + prev) res
return r
private
_ : fib 10 ≡ (55 , ∣ 176 ∣)
_ = refl
_ : fibTail 10 ≡ (55 , ∣ 9 ∣)
_ = refl
_ : fib 20 ≡ (6765 , ∣ 21890 ∣)
_ = refl
_ : fibTail 20 ≡ (6765 , ∣ 19 ∣)
_ = refl
-- Exercise left to the reader: prove that fib and fibTail are equal functions
-- fib≡fibTail : fib ≡ fibTail
-- fib≡fibTail i x = Cost≡ (fib x) (fibTail x) (rem x) i
-- where
-- rem : (x : ℕ) → fib x .fst ≡ fibTail x .fst
-- rem zero = refl
-- rem (suc zero) = refl
-- rem (suc (suc x)) = {!!}
|
{
"alphanum_fraction": 0.5878962536,
"avg_line_length": 24.984,
"ext": "agda",
"hexsha": "53c4c3c9581fe2d917e918f18e9d7fd7b16cc55d",
"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/Cost/Base.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/Cost/Base.agda",
"max_line_length": 78,
"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/Cost/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1179,
"size": 3123
}
|
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Structures.MultiSet where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.SIP
open import Cubical.Functions.FunExtEquiv
open import Cubical.Structures.Auto
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
private
variable
ℓ : Level
module _ (A : Type ℓ) (Aset : isSet A) where
CountStructure : Type ℓ → Type ℓ
CountStructure X = A → X → ℕ
CountEquivStr = AutoEquivStr CountStructure
countUnivalentStr : UnivalentStr _ CountEquivStr
countUnivalentStr = autoUnivalentStr CountStructure
Count : Type (ℓ-suc ℓ)
Count = TypeWithStr ℓ CountStructure
MultiSetStructure : Type ℓ → Type ℓ
MultiSetStructure X = X × (A → X → X) × (A → X → ℕ)
MultiSetEquivStr = AutoEquivStr MultiSetStructure
multiSetUnivalentStr : UnivalentStr _ MultiSetEquivStr
multiSetUnivalentStr = autoUnivalentStr MultiSetStructure
MultiSet : Type (ℓ-suc ℓ)
MultiSet = TypeWithStr ℓ MultiSetStructure
|
{
"alphanum_fraction": 0.7804232804,
"avg_line_length": 26.3720930233,
"ext": "agda",
"hexsha": "422f470d343f78847195d3e277f64515a62662e9",
"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/Structures/MultiSet.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/Structures/MultiSet.agda",
"max_line_length": 67,
"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/Structures/MultiSet.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 325,
"size": 1134
}
|
{-# OPTIONS --without-K --exact-split --rewriting #-}
open import lib.Basics
open import lib.PathOver
open import lib.PathGroupoid
open import lib.types.Pushout
open import lib.types.Span
open import lib.types.Coproduct
open import lib.types.Sigma
open import Graphs.Definition hiding (π₀ ; π₁)
open import Util.Misc
module Coequalizers.Definition where
Coeq : ∀ {i j} {E : Type i} {V : Type j} → (Graph E V) → Type (lmax i j)
Coeq {E = E} {V = V} (graph π₀ π₁) = Pushout (span V V (V ⊔ E) (⊔-rec (idf V) π₀) (⊔-rec (idf V) π₁))
{- It's often clearer to write coequalizers as V / E, where V and E are the
vertex and egde types, ommiting the endpoint maps. We implement this idea in
agda using instance arguments.
-}
module _ {i j : ULevel} where
_/_ : (V : Type j) (E : Type i) ⦃ gph : Graph E V ⦄ → Type (lmax i j)
_/_ V E ⦃ gph ⦄ = Coeq gph
infix 80 _/_
module _ {i j : ULevel} {V : Type i} {E : Type j} {gph : Graph E V} where
open Graph gph
cspan : Span
cspan = span V V (V ⊔ E) (⊔-rec (idf V) π₀) (⊔-rec (idf V) π₁)
c[_] : V → Coeq gph
c[ v ] = left v
quot : (e : E) → c[ π₀ e ] == c[ π₁ e ]
quot e = glue (inr e) ∙ ! (glue (inl (π₁ e)))
private
lemma : {j : ULevel} {X : Coeq gph → Type j} {a b c : Coeq gph} (p : a == b) (q : c == b) {x : X a} {y : X b} {z : X c} → (x == z [ X ↓ (p ∙ ! q) ]) →
(z == y [ X ↓ q ]) → (x == y [ X ↓ p ])
lemma idp idp r s = r ∙ s
module _ {j : ULevel} (X : Coeq gph → Type j) (x : (v : V) → X c[ v ])
(p : (e : E) → x (π₀ e) == x (π₁ e) [ X ↓ quot e ]) where
Coeq-elim : (z : Coeq gph) → X z
Coeq-elim = Pushout-elim x (λ v → transport X (glue (inl v)) (x v)) λ {(inl v) → transp-↓' _ _ _ ; (inr e) → lemma _ _ (p e) (transp-↓' _ _ _)}
Coeq-β= : (e : E) → apd Coeq-elim (quot e) == p e
Coeq-β= e =
apd Coeq-elim (quot e)
=⟨ apd-∙ Coeq-elim (glue (inr e)) (! (glue (inl (π₁ e)))) ⟩
apd Coeq-elim (glue (inr e)) ∙ᵈ apd Coeq-elim (! (glue (inl (π₁ e))))
=⟨ PushoutElim.glue-β _ _ _ _ ∙ᵈᵣ apd Coeq-elim (! (glue (inl (π₁ e)))) ⟩
lemma _ _ (p e) (transp-↓' _ _ _) ∙ᵈ apd Coeq-elim (! (glue (inl (π₁ e))))
=⟨ lemma _ _ (p e) (transp-↓' _ _ _) ∙ᵈₗ apd-! Coeq-elim (glue (inl (π₁ e))) ⟩
lemma _ _ (p e) (transp-↓' _ _ _) ∙ᵈ !ᵈ (apd Coeq-elim (glue (inl (π₁ e))))
=⟨ lemma _ _ (p e) (transp-↓' _ _ _) ∙ᵈₗ ap !ᵈ (PushoutElim.glue-β x ((λ v → transport X (glue (inl v)) (x v))) _ (inl (π₁ e))) ⟩
lemma _ _ (p e) (transp-↓' _ _ _) ∙ᵈ !ᵈ (transp-↓' X (glue (inl (π₁ e))) _)
=⟨ lemma2 _ _ (p e) (transp-↓' X (glue (inl (π₁ e))) _) ⟩
p e
=∎
where
lemma2 : {a b c : Coeq gph} (p : a == b) (q : c == b) {x : X a} {y : X b} {z : X c} → (r : x == z [ X ↓ (p ∙ ! q) ]) →
(s : z == y [ X ↓ q ]) → lemma p q r s ∙ᵈ !ᵈ s == r
lemma2 idp idp idp idp = idp
Coeq-rec : ∀ {j} {X : Type j} (x : V → X) (p : (e : E) → x (π₀ e) == x (π₁ e)) →
Coeq gph → X
Coeq-rec {X = X} x p = Coeq-elim (λ _ → X) x λ e → ↓-cst-in (p e)
Coeq-rec-β= : ∀ {j} {X : Type j} (x : V → X) (p : (e : E) → x (π₀ e) == x (π₁ e))
(e : E) → ap (Coeq-rec x p) (quot e) == p e
Coeq-rec-β= {X = X} x p e = apd=cst-in (Coeq-β= _ _ _ _)
private
E' : V → V → Type (lmax i j)
E' u v = Σ E (λ e → (u == π₀ e) × (π₁ e == v))
|
{
"alphanum_fraction": 0.4926974665,
"avg_line_length": 37.6966292135,
"ext": "agda",
"hexsha": "716c6a0734af4a879510ee7d33e6095918253e5a",
"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/Coequalizers/Definition.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/Coequalizers/Definition.agda",
"max_line_length": 154,
"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/Coequalizers/Definition.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1534,
"size": 3355
}
|
{-# OPTIONS --sized-types #-}
module SNat.Properties where
open import Size
open import SNat
open import SNat.Order
open import SNat.Order.Properties
open import SNat.Sum
lemma-≅subtyping : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≅ n → m ≅ subtyping n
lemma-≅subtyping z≅z = z≅z
lemma-≅subtyping (s≅s m≅n) = s≅s (lemma-≅subtyping m≅n)
lemma-subtyping≅ : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≅ n → subtyping m ≅ n
lemma-subtyping≅ z≅z = z≅z
lemma-subtyping≅ (s≅s m≅n) = s≅s (lemma-subtyping≅ m≅n)
lemma-subtyping≅subtyping : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≅ n → subtyping m ≅ subtyping n
lemma-subtyping≅subtyping z≅z = z≅z
lemma-subtyping≅subtyping (s≅s m≅n) = s≅s (lemma-subtyping≅subtyping m≅n)
lemma-≤′subtyping : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≤′ n → m ≤′ subtyping n
lemma-≤′subtyping (≤′-eq m≅n) = ≤′-eq (lemma-≅subtyping m≅n)
lemma-≤′subtyping (≤′-step m≤′n) = ≤′-step (lemma-≤′subtyping m≤′n)
lemma-subtyping≤′ : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≤′ n → subtyping m ≤′ n
lemma-subtyping≤′ (≤′-eq m≅n) = ≤′-eq (lemma-subtyping≅ m≅n)
lemma-subtyping≤′ (≤′-step m≤′n) = ≤′-step (lemma-subtyping≤′ m≤′n)
lemma-subtyping≤subtyping : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≤ n → subtyping m ≤ subtyping n
lemma-subtyping≤subtyping (z≤n n) = z≤n (subtyping n)
lemma-subtyping≤subtyping (s≤s m≤n) = s≤s (lemma-subtyping≤subtyping m≤n)
lemma-subtyping≤′subtyping : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≤′ n → subtyping m ≤′ subtyping n
lemma-subtyping≤′subtyping m≤′n = lemma-≤-≤′ (lemma-subtyping≤subtyping (lemma-≤′-≤ m≤′n))
--
lemma-≅-/2 : {ι ι' : Size}{m : SNat {ι}}{n : SNat {ι'}} → m ≅ n → m /2 ≅ n /2
lemma-≅-/2 z≅z = z≅z
lemma-≅-/2 (s≅s z≅z) = z≅z
lemma-≅-/2 (s≅s (s≅s m≅n)) = s≅s (lemma-subtyping≅subtyping (lemma-≅-/2 m≅n))
lemma-n/2≤′sn/2 : {ι : Size}(n : SNat {ι}) → n /2 ≤′ (succ n) /2
lemma-n/2≤′sn/2 zero = lemma-z≤′n zero
lemma-n/2≤′sn/2 (succ zero) = lemma-z≤′n (succ zero)
lemma-n/2≤′sn/2 (succ (succ n)) = lemma-s≤′s (lemma-subtyping≤′subtyping (lemma-n/2≤′sn/2 n))
--
lemma-m≤′m+n : (m n : SNat) → m ≤′ (m + n)
lemma-m≤′m+n zero n = lemma-z≤′n n
lemma-m≤′m+n (succ m) n = lemma-s≤′s (lemma-m≤′m+n m n)
lemma-2m≤′m+n+m+n : (m n : SNat) → (m + m) ≤′ ((m + n) + (m + n))
lemma-2m≤′m+n+m+n m n rewrite +-assoc-left (m + n) m n | +-comm (m + n) m | +-assoc-left m m n | +-assoc-right (m + m) n n = lemma-m≤′m+n (m + m) (n + n)
lemma-2m≅2n : {m n : SNat} → m ≅ n → (m + m) ≅ (n + n)
lemma-2m≅2n z≅z = z≅z
lemma-2m≅2n (s≅s {m = m} {n = n} m≅n) rewrite +-assoc-succ m m | +-assoc-succ n n = s≅s (s≅s (lemma-2m≅2n m≅n))
lemma-2m≤′2n : {m n : SNat} → m ≤′ n → (m + m) ≤′ (n + n)
lemma-2m≤′2n (≤′-eq m≅n) = ≤′-eq (lemma-2m≅2n m≅n)
lemma-2m≤′2n (≤′-step {n = n} m≤′n) rewrite +-assoc-succ n n = ≤′-step (≤′-step (lemma-2m≤′2n m≤′n))
lemma-n≤′2n : (n : SNat) → n ≤′ (n + n)
lemma-n≤′2n n = lemma-m≤′m+n n n
+-right-monotony-≅ : {m n : SNat}(k : SNat) → m ≅ n → (m + k) ≅ (n + k)
+-right-monotony-≅ k z≅z = refl≅
+-right-monotony-≅ k (s≅s m≅n) = s≅s (+-right-monotony-≅ k m≅n)
+-right-monotony-≤′ : {m n : SNat}(k : SNat) → m ≤′ n → (m + k) ≤′ (n + k)
+-right-monotony-≤′ k (≤′-eq m≅n) = ≤′-eq (+-right-monotony-≅ k m≅n)
+-right-monotony-≤′ k (≤′-step m≤′n) = ≤′-step (+-right-monotony-≤′ k m≤′n)
+-left-monotony-≤′ : {m n : SNat}(k : SNat) → m ≤′ n → (k + m) ≤′ (k + n)
+-left-monotony-≤′ {m} {n} k m≤′n rewrite +-comm k m | +-comm k n = +-right-monotony-≤′ k m≤′n
lemma-4m≤′n+m+n+m : {m n : SNat} → m ≤′ n → ((m + m) + (m + m)) ≤′ ((n + m) + (n + m))
lemma-4m≤′n+m+n+m {m} {n} m≤′n rewrite +-comm n m = lemma-2m≤′2n (+-left-monotony-≤′ m m≤′n)
lemma-n≤′2n/2 : (n : SNat) → n ≤′ (n + n) /2
lemma-n≤′2n/2 zero = ≤′-eq z≅z
lemma-n≤′2n/2 (succ n) rewrite +-assoc-succ (succ n) n = lemma-s≤′s (lemma-≤′subtyping (lemma-n≤′2n/2 n))
lemma-2n/2≤′n : (n : SNat) → (n + n) /2 ≤′ n
lemma-2n/2≤′n zero = refl≤′
lemma-2n/2≤′n (succ n) rewrite +-assoc-succ (succ n) n = lemma-s≤′s (lemma-subtyping≤′ (lemma-2n/2≤′n n))
lemma-n+1≤′2n+2/2 : (n : SNat) → succ n ≤′ (succ (succ (n + n))) /2
lemma-n+1≤′2n+2/2 zero = refl≤′
lemma-n+1≤′2n+2/2 (succ n) rewrite +-assoc-succ (succ n) n = lemma-s≤′s (lemma-≤′subtyping (lemma-s≤′s (lemma-≤′subtyping (lemma-n≤′2n/2 n))))
|
{
"alphanum_fraction": 0.5486746423,
"avg_line_length": 45.3510638298,
"ext": "agda",
"hexsha": "7cc1e1a14372ced8fd4060957c44d5a04235eebe",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/SNat/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/SNat/Properties.agda",
"max_line_length": 153,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/SNat/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 2210,
"size": 4263
}
|
module FreeTheorems where
open import Level using () renaming (zero to ℓ₀)
open import Data.Nat using (ℕ)
open import Data.List using (List ; map)
open import Data.Vec using (Vec) renaming (map to mapV)
open import Function using (_∘_)
open import Relation.Binary.PropositionalEquality using (_≗_)
import GetTypes
module ListList where
get-type : Set₁
get-type = {A : Set} → List A → List A
open GetTypes.ListList public
postulate
free-theorem : (get : get-type) → {α β : Set} → (f : α → β) → get ∘ map f ≗ map f ∘ get
assume-get : get-type → Get
assume-get get = record { get = get; free-theorem = free-theorem get }
module VecVec where
get-type : (ℕ → ℕ) → Set₁
get-type getlen = {A : Set} {n : ℕ} → Vec A n → Vec A (getlen n)
open GetTypes.VecVec public
postulate
free-theorem : {getlen : ℕ → ℕ} → (get : get-type getlen) → {α β : Set} → (f : α → β) → {n : ℕ} → get {_} {n} ∘ mapV f ≗ mapV f ∘ get
assume-get : {getlen : ℕ → ℕ} → (get : get-type getlen) → Get
assume-get {getlen} get = record { getlen = getlen; get = get; free-theorem = free-theorem get }
module PartialVecVec where
get-type : {I : Set} → (I → ℕ) → (I → ℕ) → Set₁
get-type {I} gl₁ gl₂ = {A : Set} {i : I} → Vec A (gl₁ i) → Vec A (gl₂ i)
open GetTypes.PartialVecVec public
postulate
free-theorem : {I : Set} → (gl₁ : I → ℕ) → (gl₂ : I → ℕ) (get : get-type gl₁ gl₂) → {α β : Set} → (f : α → β) → {i : I} → get {_} {i} ∘ mapV f ≗ mapV f ∘ get
assume-get : {I : Set} → (gl₁ : I → ℕ) → (gl₂ : I → ℕ) (get : get-type gl₁ gl₂) → Get
assume-get {I} gl₁ gl₂ get = record { I = I; gl₁ = gl₁; gl₂ = gl₂; get = get; free-theorem = free-theorem gl₁ gl₂ get }
|
{
"alphanum_fraction": 0.6023809524,
"avg_line_length": 35.7446808511,
"ext": "agda",
"hexsha": "25759e08a3b76967047b1f38880d566612bae22a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jvoigtlaender/bidiragda",
"max_forks_repo_path": "FreeTheorems.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jvoigtlaender/bidiragda",
"max_issues_repo_path": "FreeTheorems.agda",
"max_line_length": 162,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jvoigtlaender/bidiragda",
"max_stars_repo_path": "FreeTheorems.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 619,
"size": 1680
}
|
module SyntaxForOperators where
postulate _+_ : Set → Set → Set
syntax _+_ A B = A ⊎ B
|
{
"alphanum_fraction": 0.6853932584,
"avg_line_length": 14.8333333333,
"ext": "agda",
"hexsha": "6c50d921888bc855511174ed4990851bfa930039",
"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/SyntaxForOperators.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/SyntaxForOperators.agda",
"max_line_length": 31,
"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/SyntaxForOperators.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 28,
"size": 89
}
|
module Formalization.LambdaCalculus.Terms.Combinators where
import Lvl
open import Data
open import Formalization.LambdaCalculus
open import Numeral.Natural
open import Numeral.Finite
open import Syntax.Number
open import Type
module _ where
open ExplicitLambdaSyntax
I = 𝜆 0 0 -- Identity
K = 𝜆 0 (𝜆 1 0) -- Constant / Left of pair
𝈲 = 𝜆 0 (𝜆 1 1) -- Right of pair
S = 𝜆 0 (𝜆 1 (𝜆 2 ((0 ← 2) ← (1 ← 2)))) -- General composition
B = 𝜆 0 (𝜆 1 (𝜆 2 (0 ← (1 ← 2)))) -- Composition
C = 𝜆 0 (𝜆 1 (𝜆 2 ((0 ← 2) ← 1)))
W = 𝜆 0 (𝜆 1 ((0 ← 1) ← 1))
U = 𝜆 0 (0 ← 0) -- Self application
ω = U
Ω = ω ← ω
Y = 𝜆 0 ((𝜆 1 (0 ← (1 ← 1))) ← (𝜆 1 (0 ← (1 ← 1))))
-- TODO: Move everything below
open import Formalization.LambdaCalculus.SyntaxTransformation
module Boolean where
open ExplicitLambdaSyntax
𝑇 = K
𝐹 = 𝈲
If = 𝜆 0 (𝜆 1 (𝜆 2 (0 ← 1 ← 2)))
module Tuple where
open Boolean
open ExplicitLambdaSyntax
Pair = 𝜆 0 (𝜆 1 (𝜆 2 (2 ← 0 ← 1)))
Projₗ = 𝜆 0 (0 ← var-𝐒 K)
Projᵣ = 𝜆 0 (0 ← var-𝐒 𝈲)
-- Natural numbers (Church numerals).
module Natural where
open ExplicitLambdaSyntax
λ𝟎 = 𝈲
λ𝐒 = 𝜆 0 (𝜆 1 (𝜆 2 (1 ← (0 ← 1 ← 2))))
ℕrepr₂ : ℕ → Term(2)
ℕrepr₂ 𝟎 = 1
ℕrepr₂ (𝐒(n)) = 0 ← ℕrepr₂ n
ℕrepr = \n → 𝜆 0 (𝜆 1 (ℕrepr₂ n))
-- TODO: Prove (λ𝐒 ←ⁿ λ𝟎) β-reduces to (ℕrepr n)
module β-proofs where
open import Formalization.LambdaCalculus.Semantics.Reduction
open import Logic.Propositional hiding (_←_)
open import Logic.Predicate
open import ReductionSystem
open import Relator.ReflexiveTransitiveClosure renaming (trans to _🝖_)
open import Structure.Relator
open import Structure.Relator.Properties
open import Type.Dependent
open ExplicitLambdaSyntax
private variable n : ℕ
private variable f g h x y z : Term(n)
Ω-self-reduces : Ω β⇴ Ω
Ω-self-reduces = β
Ω-no-normal-form : ¬ NormalForm(_β⇴_)(Ω)
Ω-no-normal-form (intro p) = p(Ω-self-reduces)
-- Also called: Church-Rosser's theorem.
-- TODO: Seems like the proof can be a bit complicated?
postulate β-star-confluence : ∀{d} → Confluence(_β⇴*_ {d})
I-reduction : ((I ← x) β⇴ x)
I-reduction = β
K-reduction : ((K ← x ← y) β⇴* x)
K-reduction {x}{y} = super(cong-applyₗ β) 🝖 super β -- 🝖 substitute₂ₗ(_β⇴*_) (symmetry(_≡_) (substitute-var-𝐒 {0}{x}{y})) refl
𝈲-reduction : ((𝈲 ← x ← y) β⇴* y)
𝈲-reduction {x}{y} = super(cong-applyₗ β) 🝖 super β
B-reduction : ((B ← f ← g ← x) β⇴* (f ← (g ← x)))
B-reduction = super(cong-applyₗ(cong-applyₗ β)) 🝖 super(cong-applyₗ β) 🝖 super β
C-reduction : ((C ← f ← g ← x) β⇴* ((f ← x) ← g))
C-reduction = super(cong-applyₗ(cong-applyₗ β)) 🝖 super(cong-applyₗ β) 🝖 super β
S-reduction : ((S ← f ← g ← x) β⇴* ((f ← x) ← (g ← x)))
S-reduction = super(cong-applyₗ(cong-applyₗ β)) 🝖 super(cong-applyₗ β) 🝖 super β
Y-reduction : ∀{f} → ((Y ← f) β⥈* (f ← (Y ← f)))
Y-reduction = super([∨]-introᵣ β) 🝖 super([∨]-introᵣ β) 🝖 super([∨]-introₗ(cong-applyᵣ β))
module _ where
open Boolean
If-𝑇-reduction : ((If ← 𝑇 ← x ← y) β⇴* x)
If-𝑇-reduction = super(cong-applyₗ(cong-applyₗ β)) 🝖 super(cong-applyₗ β) 🝖 super β 🝖 K-reduction
If-𝐹-reduction : ((If ← 𝐹 ← x ← y) β⇴* y)
If-𝐹-reduction = super(cong-applyₗ(cong-applyₗ β)) 🝖 super(cong-applyₗ β) 🝖 super β 🝖 𝈲-reduction
module _ where
open Tuple
Pair-projₗ-reduction : (Projₗ ← (Pair ← x ← y)) β⇴* x
Pair-projₗ-reduction = super β 🝖 super(cong-applyₗ(cong-applyₗ β)) 🝖 super(cong-applyₗ β) 🝖 super β 🝖 super(cong-applyₗ β) 🝖 super β
Pair-projᵣ-reduction : (Projᵣ ← (Pair ← x ← y)) β⇴* y
Pair-projᵣ-reduction = super β 🝖 super(cong-applyₗ(cong-applyₗ β)) 🝖 super(cong-applyₗ β) 🝖 super β 🝖 super(cong-applyₗ β) 🝖 super β
module _ where
open import Function.Iteration
open Natural
{-
-- λ𝟎 β⇴* ℕrepr 𝟎
λ𝐒-of-ℕrepr : (λ𝐒 ← ℕrepr(n)) β⇴* ℕrepr(𝐒(n))
λ𝐒-of-ℕrepr = super {!cong-applyₗ ?!}
ℕrepr-correctness : (((λ𝐒 ←_) ^ n) λ𝟎) β⇴* (ℕrepr n)
ℕrepr-correctness {𝟎} = refl
ℕrepr-correctness {𝐒 n} = super {!!} 🝖 super {!ℕrepr-correctness {n}!}
-}
|
{
"alphanum_fraction": 0.5931920971,
"avg_line_length": 30.4420289855,
"ext": "agda",
"hexsha": "e4829da638f718f2e3639e3e63fe1881be656c97",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Formalization/LambdaCalculus/Terms/Combinators.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Formalization/LambdaCalculus/Terms/Combinators.agda",
"max_line_length": 136,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Formalization/LambdaCalculus/Terms/Combinators.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": 1845,
"size": 4201
}
|
open import Common.Prelude
postulate
foo_bar_ : (b : Bool) → if b then Nat else Bool → Set
Test : Set
Test = foo_bar 5
|
{
"alphanum_fraction": 0.6910569106,
"avg_line_length": 15.375,
"ext": "agda",
"hexsha": "4f3dd68010c20b6f9cfd12876444bb151e07e2c2",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Sections-2.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Sections-2.agda",
"max_line_length": 55,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Sections-2.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": 40,
"size": 123
}
|
module AbstractModuleMacro where
import Common.Issue481Parametrized as P
abstract
module M = P Set
|
{
"alphanum_fraction": 0.8155339806,
"avg_line_length": 14.7142857143,
"ext": "agda",
"hexsha": "d9841db8ce9993b7743611bfc77a1284ea312ba1",
"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/fail/AbstractModuleMacro.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/AbstractModuleMacro.agda",
"max_line_length": 39,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/AbstractModuleMacro.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": 26,
"size": 103
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.ZCohomology.Properties where
open import Cubical.ZCohomology.Base
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Univalence
open import Cubical.Data.Empty
open import Cubical.Data.Sigma hiding (_×_)
open import Cubical.HITs.Susp
open import Cubical.HITs.Wedge
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2)
open import Cubical.HITs.Nullification
open import Cubical.Data.Int hiding (_+_)
open import Cubical.Data.Nat
open import Cubical.Data.Prod
open import Cubical.HITs.Truncation renaming (elim to trElim ; map to trMap ; rec to trRec ; elim3 to trElim3)
open import Cubical.Homotopy.Loopspace
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.Freudenthal
open import Cubical.HITs.SmashProduct.Base
open import Cubical.Structures.Group
open import Cubical.HITs.Pushout
open import Cubical.Data.Sum.Base
open import Cubical.Data.HomotopyGroup
open import Cubical.Data.Bool hiding (_⊕_)
open import Cubical.ZCohomology.KcompPrelims
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
A' : Pointed ℓ
{- Equivalence between cohomology of A and reduced cohomology of (A + 1) -}
coHomRed+1Equiv : (n : ℕ) →
(A : Type ℓ) →
(coHom n A) ≡ (coHomRed n ((A ⊎ Unit , inr (tt))))
coHomRed+1Equiv zero A i = ∥ helpLemma {C = (Int , pos 0)} i ∥₂
module coHomRed+1 where
helpLemma : {C : Pointed ℓ} → ( (A → (typ C)) ≡ ((((A ⊎ Unit) , inr (tt)) →∙ C)))
helpLemma {C = C} = isoToPath (iso map1
map2
(λ b → linvPf b)
(λ _ → refl))
where
map1 : (A → typ C) → ((((A ⊎ Unit) , inr (tt)) →∙ C))
map1 f = map1' , refl
module helpmap where
map1' : A ⊎ Unit → fst C
map1' (inl x) = f x
map1' (inr x) = pt C
map2 : ((((A ⊎ Unit) , inr (tt)) →∙ C)) → (A → typ C)
map2 (g , pf) x = g (inl x)
linvPf : (b :((((A ⊎ Unit) , inr (tt)) →∙ C))) → map1 (map2 b) ≡ b
linvPf (f , snd) i = (λ x → helper x i) , λ j → snd ((~ i) ∨ j)
where
helper : (x : A ⊎ Unit) → ((helpmap.map1') (map2 (f , snd)) x) ≡ f x
helper (inl x) = refl
helper (inr tt) = sym snd
coHomRed+1Equiv (suc n) A i = ∥ coHomRed+1.helpLemma A i {C = ((coHomK (suc n)) , ∣ north ∣)} i ∥₂
-----------
Kn→ΩKn+1 : (n : ℕ) → coHomK n → typ (Ω (coHomK-ptd (suc n)))
Kn→ΩKn+1 n = Iso.fun (Iso2-Kn-ΩKn+1 n)
ΩKn+1→Kn : {n : ℕ} → typ (Ω (coHomK-ptd (suc n))) → coHomK n
ΩKn+1→Kn {n = n} = Iso.inv (Iso2-Kn-ΩKn+1 n)
Kn≃ΩKn+1 : {n : ℕ} → coHomK n ≃ typ (Ω (coHomK-ptd (suc n)))
Kn≃ΩKn+1 {n = n} = isoToEquiv (Iso-Kn-ΩKn+1 n)
---------- Algebra/Group stuff --------
0ₖ : {n : ℕ} → coHomK n
0ₖ {n = zero} = pt (coHomK-ptd 0)
0ₖ {n = suc n} = pt (coHomK-ptd (suc n))
infixr 35 _+ₖ_
_+ₖ_ : {n : ℕ} → coHomK n → coHomK n → coHomK n
_+ₖ_ {n = n} x y = ΩKn+1→Kn (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y)
-ₖ_ : {n : ℕ} → coHomK n → coHomK n
-ₖ_ {n = n} x = ΩKn+1→Kn (sym (Kn→ΩKn+1 n x))
Kn→ΩKn+10ₖ : (n : ℕ) → Kn→ΩKn+1 n 0ₖ ≡ refl
Kn→ΩKn+10ₖ zero = refl
Kn→ΩKn+10ₖ (suc n) = (λ i → cong ∣_∣ (rCancel (merid north) i))
rUnitₖ : {n : ℕ} (x : coHomK n) → x +ₖ 0ₖ ≡ x
rUnitₖ {n = zero} x = cong ΩKn+1→Kn (sym (rUnit (Kn→ΩKn+1 zero x))) ∙
Iso.leftInv (Iso2-Kn-ΩKn+1 zero) x
rUnitₖ {n = suc n} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 (suc n) x ∙ Kn→ΩKn+10ₖ (suc n) i)) ∙
(λ i → ΩKn+1→Kn (rUnit (Kn→ΩKn+1 (suc n) x) (~ i))) ∙
Iso.leftInv (Iso2-Kn-ΩKn+1 (suc n)) x
lUnitₖ : {n : ℕ} (x : coHomK n) → 0ₖ +ₖ x ≡ x
lUnitₖ {n = zero} x = cong ΩKn+1→Kn (sym (lUnit (Kn→ΩKn+1 zero x))) ∙
Iso.leftInv (Iso2-Kn-ΩKn+1 zero) x
lUnitₖ {n = suc n} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc n) i ∙ Kn→ΩKn+1 (suc n) x)) ∙
(λ i → ΩKn+1→Kn (lUnit (Kn→ΩKn+1 (suc n) x) (~ i))) ∙
Iso.leftInv (Iso2-Kn-ΩKn+1 (suc n)) x
rCancelₖ : {n : ℕ} (x : coHomK n) → x +ₖ (-ₖ x) ≡ 0ₖ
rCancelₖ {n = zero} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 zero x ∙ Iso.rightInv (Iso2-Kn-ΩKn+1 zero) (sym (Kn→ΩKn+1 zero x)) i)) ∙
cong ΩKn+1→Kn (rCancel (Kn→ΩKn+1 zero x))
rCancelₖ {n = suc zero} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 1 x ∙ Iso.rightInv (Iso2-Kn-ΩKn+1 1) (sym (Kn→ΩKn+1 1 x)) i)) ∙
cong ΩKn+1→Kn (rCancel (Kn→ΩKn+1 1 x))
rCancelₖ {n = suc (suc n)} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 (2 + n) x ∙ Iso.rightInv (Iso2-Kn-ΩKn+1 (2 + n)) (sym (Kn→ΩKn+1 (2 + n) x)) i)) ∙
cong ΩKn+1→Kn (rCancel (Kn→ΩKn+1 (2 + n) x)) ∙
(λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc (suc n)) (~ i))) ∙
Iso.leftInv (Iso2-Kn-ΩKn+1 (suc (suc n))) 0ₖ
lCancelₖ : {n : ℕ} (x : coHomK n) → (-ₖ x) +ₖ x ≡ 0ₖ
lCancelₖ {n = zero} x = (λ i → ΩKn+1→Kn (Iso.rightInv (Iso2-Kn-ΩKn+1 zero) (sym (Kn→ΩKn+1 zero x)) i ∙ Kn→ΩKn+1 zero x)) ∙
cong ΩKn+1→Kn (lCancel (Kn→ΩKn+1 zero x))
lCancelₖ {n = suc zero} x = ((λ i → ΩKn+1→Kn (Iso.rightInv (Iso2-Kn-ΩKn+1 1) (sym (Kn→ΩKn+1 1 x)) i ∙ Kn→ΩKn+1 1 x))) ∙
cong ΩKn+1→Kn (lCancel (Kn→ΩKn+1 1 x))
lCancelₖ {n = suc (suc n)} x = (λ i → ΩKn+1→Kn (Iso.rightInv (Iso2-Kn-ΩKn+1 (2 + n)) (sym (Kn→ΩKn+1 (2 + n) x)) i ∙ Kn→ΩKn+1 (2 + n) x)) ∙
cong ΩKn+1→Kn (lCancel (Kn→ΩKn+1 (2 + n) x)) ∙
(λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc (suc n)) (~ i))) ∙
Iso.leftInv (Iso2-Kn-ΩKn+1 (suc (suc n))) 0ₖ
assocₖ : {n : ℕ} (x y z : coHomK n) → ((x +ₖ y) +ₖ z) ≡ (x +ₖ (y +ₖ z))
assocₖ {n = n} x y z = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 n (ΩKn+1→Kn (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y)) ∙ Kn→ΩKn+1 n z)) ∙
(λ i → ΩKn+1→Kn (Iso.rightInv (Iso2-Kn-ΩKn+1 n) (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y) i ∙ Kn→ΩKn+1 n z)) ∙
(λ i → ΩKn+1→Kn (assoc (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) (Kn→ΩKn+1 n z) (~ i))) ∙
(λ i → ΩKn+1→Kn ((Kn→ΩKn+1 n x) ∙ Iso.rightInv (Iso2-Kn-ΩKn+1 n) ((Kn→ΩKn+1 n y ∙ Kn→ΩKn+1 n z)) (~ i)))
commₖ : {n : ℕ} (x y : coHomK n) → (x +ₖ y) ≡ (y +ₖ x)
commₖ {n = n} x y i = ΩKn+1→Kn (EH-instance (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) i)
where
EH-instance : (p q : typ (Ω ((∥ S₊ (suc n) ∥ (2 + (suc n))) , ∣ north ∣))) → p ∙ q ≡ q ∙ p
EH-instance = transport (λ i → (p q : K-Id n (~ i)) → p ∙ q ≡ q ∙ p)
λ p q → Eckmann-Hilton 0 p q
where
K-Id : (n : HLevel) → typ (Ω (hLevelTrunc (3 + n) (S₊ (1 + n)) , ∣ north ∣)) ≡ typ ((Ω^ 2) (hLevelTrunc (4 + n) (S₊ (2 + n)) , ∣ north ∣ ))
K-Id n = (λ i → typ (Ω (isoToPath (Iso2-Kn-ΩKn+1 (suc n)) i , hcomp (λ k → λ { (i = i0) → ∣ north ∣
; (i = i1) → transportRefl (λ j → ∣ rCancel (merid north) k j ∣) k})
(transp (λ j → isoToPath (Iso2-Kn-ΩKn+1 (suc n)) (i ∧ j)) (~ i) ∣ north ∣))))
-distrₖ : {n : ℕ} → (x y : coHomK n) → -ₖ (x +ₖ y) ≡ (-ₖ x) +ₖ (-ₖ y)
-distrₖ {n = n} x y = (λ i → ΩKn+1→Kn (sym (Kn→ΩKn+1 n (ΩKn+1→Kn (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y))))) ∙
(λ i → ΩKn+1→Kn (sym (Iso.rightInv (Iso2-Kn-ΩKn+1 n) (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y) i))) ∙
(λ i → ΩKn+1→Kn (symDistr (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) i)) ∙
(λ i → ΩKn+1→Kn (Iso.rightInv (Iso2-Kn-ΩKn+1 n) (sym (Kn→ΩKn+1 n y)) (~ i) ∙ (Iso.rightInv (Iso2-Kn-ΩKn+1 n) (sym (Kn→ΩKn+1 n x)) (~ i)))) ∙
commₖ (-ₖ y) (-ₖ x)
---- Group structure of cohomology groups ---
private
§ : isSet ∥ A ∥₂
§ = setTruncIsSet
_+ₕ_ : {n : ℕ} → coHom n A → coHom n A → coHom n A
_+ₕ_ = sElim2 (λ _ _ → §) λ a b → ∣ (λ x → a x +ₖ b x) ∣₂
-ₕ : {n : ℕ} → coHom n A → coHom n A
-ₕ = sRec § λ a → ∣ (λ x → -ₖ a x) ∣₂
0ₕ : {n : ℕ} → coHom n A
0ₕ = ∣ (λ _ → 0ₖ) ∣₂
rUnitₕ : {n : ℕ} (x : coHom n A) → x +ₕ 0ₕ ≡ x
rUnitₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))
λ a i → ∣ funExt (λ x → rUnitₖ (a x)) i ∣₂
lUnitₕ : {n : ℕ} (x : coHom n A) → 0ₕ +ₕ x ≡ x
lUnitₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))
λ a i → ∣ funExt (λ x → lUnitₖ (a x)) i ∣₂
rCancelₕ : {n : ℕ} (x : coHom n A) → x +ₕ (-ₕ x) ≡ 0ₕ
rCancelₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))
λ a i → ∣ funExt (λ x → rCancelₖ (a x)) i ∣₂
lCancelₕ : {n : ℕ} (x : coHom n A) → (-ₕ x) +ₕ x ≡ 0ₕ
lCancelₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))
λ a i → ∣ funExt (λ x → lCancelₖ (a x)) i ∣₂
assocₕ : {n : ℕ} (x y z : coHom n A) → ((x +ₕ y) +ₕ z) ≡ (x +ₕ (y +ₕ z))
assocₕ = elim3 (λ _ _ _ → isOfHLevelPath 1 (§ _ _))
λ a b c i → ∣ funExt (λ x → assocₖ (a x) (b x) (c x)) i ∣₂
commₕ : {n : ℕ} (x y : coHom n A) → (x +ₕ y) ≡ (y +ₕ x)
commₕ {n = n} = sElim2 (λ _ _ → isOfHLevelPath 1 (§ _ _))
λ a b i → ∣ funExt (λ x → commₖ (a x) (b x)) i ∣₂
---- Group structure of reduced cohomology groups (in progress - might need K to compute properly first) ---
+ₕ∙ : {A : Pointed ℓ} (n : ℕ) → coHomRed n A → coHomRed n A → coHomRed n A
+ₕ∙ zero = sElim2 (λ _ _ → §) λ { (a , pa) (b , pb) → ∣ (λ x → a x +ₖ b x) , (λ i → (pa i +ₖ pb i)) ∣₂ }
+ₕ∙ (suc n) = sElim2 (λ _ _ → §) λ { (a , pa) (b , pb) → ∣ (λ x → a x +ₖ b x) , (λ i → pa i +ₖ pb i) ∙ lUnitₖ 0ₖ ∣₂ }
-ₕ∙ : {A : Pointed ℓ} (n : ℕ) → coHomRed n A → coHomRed n A
-ₕ∙ zero = sRec § λ {(a , pt) → ∣ (λ x → -ₖ a x ) , (λ i → -ₖ (pt i)) ∣₂}
-ₕ∙ (suc zero) = sRec § λ {(a , pt) → ∣ (λ x → -ₖ a x ) , (λ i → -ₖ (pt i)) ∙ (λ i → ΩKn+1→Kn (sym (Kn→ΩKn+10ₖ (suc zero) i))) ∣₂}
-ₕ∙ (suc (suc n)) = sRec § λ {(a , pt) → ∣ (λ x → -ₖ a x ) , (λ i → -ₖ (pt i)) ∙
(λ i → ΩKn+1→Kn (sym (Kn→ΩKn+10ₖ (suc (suc n)) i))) ∙
(λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc (suc n)) (~ i))) ∙
Iso.leftInv (Iso2-Kn-ΩKn+1 (suc (suc n))) ∣ north ∣ ∣₂}
0ₕ∙ : {A : Pointed ℓ} (n : ℕ) → coHomRed n A
0ₕ∙ zero = ∣ (λ _ → 0ₖ) , refl ∣₂
0ₕ∙ (suc n) = ∣ (λ _ → 0ₖ) , refl ∣₂
|
{
"alphanum_fraction": 0.4911734164,
"avg_line_length": 46.6651982379,
"ext": "agda",
"hexsha": "ac57dd851fec3d86e4f0df80c2bd26208a93c1e5",
"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": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/ZCohomology/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/ZCohomology/Properties.agda",
"max_line_length": 162,
"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/ZCohomology/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4917,
"size": 10593
}
|
------------------------------------------------------------------------
-- Some partiality algebra properties
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
open import Prelude hiding (T)
open import Partiality-algebra as PA hiding (id; _∘_)
module Partiality-algebra.Properties
{a p q} {A : Type a} (P : Partiality-algebra p q A) where
open import Equality.Propositional.Cubical
open import Function-universe equality-with-J hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional equality-with-paths
open import Nat equality-with-J as Nat
open Partiality-algebra P
------------------------------------------------------------------------
-- Some predicates
-- A termination predicate: x ⇓ y means that x terminates with the
-- value y.
infix 4 _⇓_ _⇑
_⇓_ : T → A → Type p
x ⇓ y = x ≡ now y
-- A non-termination predicate.
_⇑ : T → Type p
x ⇑ = x ≡ never
------------------------------------------------------------------------
-- Preorder reasoning combinators
infix -1 finally-⊑
infix -1 _■
infixr -2 _⊑⟨_⟩_ _⊑⟨⟩_ _≡⟨_⟩⊑_
_⊑⟨_⟩_ : (x {y z} : T) → x ⊑ y → y ⊑ z → x ⊑ z
_ ⊑⟨ x⊑y ⟩ y⊑z = ⊑-trans x⊑y y⊑z
_⊑⟨⟩_ : (x {y} : T) → x ⊑ y → x ⊑ y
_ ⊑⟨⟩ x⊑y = x⊑y
_≡⟨_⟩⊑_ : (x {y z} : T) → x ≡ y →
y ⊑ z → x ⊑ z
_ ≡⟨ refl ⟩⊑ y⊑z = y⊑z
_■ : (x : T) → x ⊑ x
x ■ = ⊑-refl x
finally-⊑ : (x y : T) → x ⊑ y → x ⊑ y
finally-⊑ _ _ x⊑y = x⊑y
syntax finally-⊑ x y x⊑y = x ⊑⟨ x⊑y ⟩■ y ■
------------------------------------------------------------------------
-- Some simple lemmas
-- If every element in one increasing sequence is bounded by some
-- element in another, then the least upper bound of the first
-- sequence is bounded by the least upper bound of the second one.
⊑→⨆⊑⨆ : ∀ {s₁ s₂} {f : ℕ → ℕ} →
(∀ n → s₁ [ n ] ⊑ s₂ [ f n ]) → ⨆ s₁ ⊑ ⨆ s₂
⊑→⨆⊑⨆ {s₁} {s₂} {f} s₁⊑s₂ =
least-upper-bound _ _ λ n →
s₁ [ n ] ⊑⟨ s₁⊑s₂ n ⟩
s₂ [ f n ] ⊑⟨ upper-bound _ _ ⟩■
⨆ s₂ ■
-- A variant of the previous lemma.
∃⊑→⨆⊑⨆ : ∀ {s₁ s₂} →
(∀ m → ∃ λ n → s₁ [ m ] ⊑ s₂ [ n ]) → ⨆ s₁ ⊑ ⨆ s₂
∃⊑→⨆⊑⨆ s₁⊑s₂ = ⊑→⨆⊑⨆ (proj₂ ∘ s₁⊑s₂)
-- ⨆ is monotone.
⨆-mono : {s₁ s₂ : Increasing-sequence} →
(∀ n → s₁ [ n ] ⊑ s₂ [ n ]) → ⨆ s₁ ⊑ ⨆ s₂
⨆-mono = ⊑→⨆⊑⨆
-- Later elements in an increasing sequence are larger.
later-larger : (s : Increasing-sequence) →
∀ {m n} → m ≤ n → s [ m ] ⊑ s [ n ]
later-larger s {m} (≤-refl′ refl) = s [ m ] ■
later-larger s {m} (≤-step′ {k = n} p refl) =
s [ m ] ⊑⟨ later-larger s p ⟩
s [ n ] ⊑⟨ increasing s n ⟩■
s [ suc n ] ■
-- If the final elements of an increasing sequence have an upper
-- bound, then all elements have this upper bound.
upper-bound-≤→upper-bound :
∀ (s : Increasing-sequence) {m x} →
(∀ n → m ≤ n → s [ n ] ⊑ x) →
∀ n → s [ n ] ⊑ x
upper-bound-≤→upper-bound s {m} {x} is-ub n with Nat.total m n
... | inj₁ m≤n = is-ub n m≤n
... | inj₂ n≤m =
s [ n ] ⊑⟨ later-larger s n≤m ⟩
s [ m ] ⊑⟨ is-ub m ≤-refl ⟩■
x ■
-- Only never is smaller than or equal to never.
only-never-⊑-never : {x : T} → x ⊑ never → x ≡ never
only-never-⊑-never x⊑never = antisymmetry x⊑never (never⊑ _)
------------------------------------------------------------------------
-- Tails
-- The tail of an increasing sequence.
tailˢ : Increasing-sequence → Increasing-sequence
tailˢ = Σ-map (_∘ suc) (_∘ suc)
-- The tail has the same least upper bound as the full sequence.
⨆tail≡⨆ : ∀ s → ⨆ (tailˢ s) ≡ ⨆ s
⨆tail≡⨆ s = antisymmetry
(⊑→⨆⊑⨆ λ n → s [ suc n ] ⊑⟨⟩
s [ suc n ] ■)
(⨆-mono λ n → s [ n ] ⊑⟨ increasing s n ⟩■
s [ suc n ] ■)
------------------------------------------------------------------------
-- Constant sequences
-- One way to form a constant sequence.
constˢ : T → Increasing-sequence
constˢ x = const x , const (⊑-refl x)
-- The least upper bound of a constant sequence is equal to the
-- value in the sequence.
⨆-const : ∀ {x : T} {inc} → ⨆ (const x , inc) ≡ x
⨆-const {x} =
antisymmetry (least-upper-bound _ _ (λ _ → ⊑-refl x))
(upper-bound _ 0)
------------------------------------------------------------------------
-- Box and diamond
-- Box.
□ : ∀ {ℓ} → (A → Type ℓ) → T → Type (a ⊔ p ⊔ ℓ)
□ P x = ∀ y → x ⇓ y → P y
-- Diamond.
◇ : ∀ {ℓ} → (A → Type ℓ) → T → Type (a ⊔ p ⊔ ℓ)
◇ P x = ∥ (∃ λ y → x ⇓ y × P y) ∥
-- All h-levels are closed under box.
□-closure : ∀ {ℓ} {P : A → Type ℓ} {x} n →
(∀ x → H-level n (P x)) → H-level n (□ P x)
□-closure n h =
Π-closure ext n λ y →
Π-closure ext n λ _ →
h y
-- A "constructor" for ◇. For more "constructors" for □ and ◇, see
-- Partiality-monad.Inductive.Alternative-order.
◇-now :
∀ {ℓ} {P : A → Type ℓ} →
∀ {x} → P x → ◇ P (now x)
◇-now p = ∣ _ , refl , p ∣
------------------------------------------------------------------------
-- An alternative characterisation of _⊑_
-- A relation which, /for the partiality monad/, is pointwise
-- equivalent to _⊑_. See
-- Partiality-monad.Inductive.Alternative-order.≼≃⊑ for the proof.
_≼_ : T → T → Type (a ⊔ p)
x ≼ y = ∀ z → x ⇓ z → y ⇓ z
-- _≼_ is propositional.
≼-propositional : ∀ {x y} → Is-proposition (x ≼ y)
≼-propositional =
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
T-is-set
-- _≼_ is transitive.
≼-trans : ∀ {x y z} → x ≼ y → y ≼ z → x ≼ z
≼-trans {x} {y} {z} x≼y y≼z u =
x ⇓ u ↝⟨ x≼y u ⟩
y ⇓ u ↝⟨ y≼z u ⟩□
z ⇓ u □
------------------------------------------------------------------------
-- Combinators that can be used to prove that two least upper bounds
-- are equal
-- For an example of how these combinators can be used, see
-- Lambda.Partiality-monad.Inductive.Compiler-correctness.
-- A relation between sequences.
infix 4 _≳[_]_
record _≳[_]_ (s₁ : ℕ → T) (n : ℕ) (s₂ : ℕ → T) : Type p where
constructor wrap
field
run : ∃ λ k → s₁ (k + n) ≡ s₂ n
open _≳[_]_ public
steps-≳ : ∀ {s₁ n s₂} → s₁ ≳[ n ] s₂ → ℕ
steps-≳ = proj₁ ∘ run
-- If two increasing sequences are related in a certain way, then
-- their least upper bounds are equal.
≳→⨆≡⨆ : ∀ {s₁ s₂} k →
(∀ {n} → proj₁ s₁ ≳[ n ] proj₁ s₂ ∘ (k +_)) →
⨆ s₁ ≡ ⨆ s₂
≳→⨆≡⨆ {s₁} {s₂} k s₁≳s₂ = antisymmetry
(⊑→⨆⊑⨆ λ n →
let m , s₁[m+n]≡s₂[k+n] = run s₁≳s₂ in
s₁ [ n ] ⊑⟨ later-larger s₁ (m≤n+m _ m) ⟩
s₁ [ m + n ] ≡⟨ s₁[m+n]≡s₂[k+n] ⟩⊑
s₂ [ k + n ] ■)
(⊑→⨆⊑⨆ λ n →
let m , s₁[m+n]≡s₂[k+n] = run s₁≳s₂ in
s₂ [ n ] ⊑⟨ later-larger s₂ (m≤n+m _ k) ⟩
s₂ [ k + n ] ≡⟨ sym s₁[m+n]≡s₂[k+n] ⟩⊑
s₁ [ m + n ] ■)
-- Preorder-like reasoning combinators.
infix -1 _∎≳
infixr -2 _≳⟨⟩_ trans-≳ trans-≡≳ trans-∀≡≳
_∎≳ : ∀ s {n} → s ≳[ n ] s
run (_ ∎≳) = 0 , refl
_≳⟨⟩_ : ∀ {n} s₁ {s₂} → s₁ ≳[ n ] s₂ → s₁ ≳[ n ] s₂
_ ≳⟨⟩ s₁≳s₂ = s₁≳s₂
trans-≳ : ∀ {n} s₁ {s₂ s₃}
(s₂≳s₃ : s₂ ≳[ n ] s₃) →
s₁ ≳[ steps-≳ s₂≳s₃ + n ] s₂ →
s₁ ≳[ n ] s₃
run (trans-≳ {n} s₁ {s₂} {s₃} s₂≳s₃ s₁≳s₂) =
let k₁ , eq₁ = run s₂≳s₃
k₂ , eq₂ = run s₁≳s₂
in
k₂ + k₁
, (s₁ ((k₂ + k₁) + n) ≡⟨ cong s₁ (sym $ +-assoc k₂) ⟩
s₁ (k₂ + (k₁ + n)) ≡⟨ eq₂ ⟩
s₂ (k₁ + n) ≡⟨ eq₁ ⟩∎
s₃ n ∎)
trans-≡≳ : ∀ {n} s₁ {s₂ s₃}
(s₂≳s₃ : s₂ ≳[ n ] s₃) →
s₁ (steps-≳ s₂≳s₃ + n) ≡ s₂ (steps-≳ s₂≳s₃ + n) →
s₁ ≳[ n ] s₃
trans-≡≳ _ s₂≳s₃ s₁≡s₂ = _ ≳⟨ wrap (0 , s₁≡s₂) ⟩ s₂≳s₃
trans-∀≡≳ : ∀ {n} s₁ {s₂ s₃} →
s₂ ≳[ n ] s₃ →
(∀ n → s₁ n ≡ s₂ n) →
s₁ ≳[ n ] s₃
trans-∀≡≳ _ s₂≳s₃ s₁≡s₂ = trans-≡≳ _ s₂≳s₃ (s₁≡s₂ _)
syntax trans-≳ s₁ s₂≳s₃ s₁≳s₂ = s₁ ≳⟨ s₁≳s₂ ⟩ s₂≳s₃
syntax trans-≡≳ s₁ s₂≳s₃ s₁≡s₂ = s₁ ≡⟨ s₁≡s₂ ⟩≳ s₂≳s₃
syntax trans-∀≡≳ s₁ s₂≳s₃ s₁≡s₂ = s₁ ∀≡⟨ s₁≡s₂ ⟩≳ s₂≳s₃
-- Some "stepping" combinators.
later : ∀ {n s₁ s₂} →
s₁ ∘ suc ≳[ n ] s₂ ∘ suc → s₁ ≳[ suc n ] s₂
run (later {n} {s₁} {s₂} s₁≳s₂) =
let k , eq = run s₁≳s₂
in
k
, (s₁ (k + suc n) ≡⟨ cong s₁ (sym $ suc+≡+suc k) ⟩
s₁ (suc k + n) ≡⟨ eq ⟩∎
s₂ (suc n) ∎)
earlier : ∀ {n s₁ s₂} →
s₁ ≳[ suc n ] s₂ → s₁ ∘ suc ≳[ n ] s₂ ∘ suc
run (earlier {n} {s₁} {s₂} s₁≳s₂) =
let k , eq = run s₁≳s₂
in
k
, (s₁ (suc k + n) ≡⟨ cong s₁ (suc+≡+suc k) ⟩
s₁ (k + suc n) ≡⟨ eq ⟩∎
s₂ (suc n) ∎)
laterˡ : ∀ {n s₁ s₂} → s₁ ∘ suc ≳[ n ] s₂ → s₁ ≳[ n ] s₂
run (laterˡ s₁≳s₂) = Σ-map suc id (run s₁≳s₂)
step⇓ : ∀ {n s} → s ≳[ n ] s ∘ suc
step⇓ = laterˡ (_ ∎≳)
|
{
"alphanum_fraction": 0.4639681797,
"avg_line_length": 26.7962382445,
"ext": "agda",
"hexsha": "67fe42a287a267ba4458b8445283a7f0af5ed829",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Partiality-algebra/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Partiality-algebra/Properties.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Partiality-algebra/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 3938,
"size": 8548
}
|
-- You can use _ in a binding position in notation.
module WildcardNotation where
data Σ (A : Set) (B : A → Set) : Set where
_,_ : ∀ x → B x → Σ A B
syntax Σ A (λ _ → B) = A × B
swap : ∀ {A B} → A × B → B × A
swap (x , y) = y , x
syntax compose (λ _ → x) (λ _ → y) = x instead-of y
compose : {A B C : Set} → (B → C) → (A → B) → (A → C)
compose f g = λ x → f (g x)
open import Common.Prelude
open import Common.Equality
thm₁ : swap (1 , 2) ≡ (2 , 1)
thm₁ = refl
thm₂ : (a b : Nat) → (5 instead-of a) b ≡ 5
thm₂ a b = refl
|
{
"alphanum_fraction": 0.5433962264,
"avg_line_length": 22.0833333333,
"ext": "agda",
"hexsha": "276290e146a1da3508a51a6fbef786f54567c026",
"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/WildcardNotation.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/WildcardNotation.agda",
"max_line_length": 53,
"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/WildcardNotation.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": 222,
"size": 530
}
|
module Data.Either.Proofs where
import Lvl
open import Data
open import Data.Either as Either
open import Data.Either.Equiv
open import Function.Equals
open import Functional
open import Logic.Propositional
open import Logic.Predicate
open import Structure.Setoid
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Function.Domain.Proofs
open import Structure.Function.Multi
open import Structure.Operator
open import Structure.Relator.Properties
open import Syntax.Transitivity
open import Type
private variable ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₑ₄ ℓₑ₅ ℓₑ₆ : Lvl.Level
private variable A B C A₁ A₂ A₃ B₁ B₂ B₃ : Type{ℓ}
module _ ⦃ equiv-C : Equiv{ℓₑ₃}(C) ⦄ where
map1-values : {f : A → C}{g : B → C}{e : A ‖ B} → (∃(x ↦ map1 f g e ≡ f(x)) ∨ ∃(x ↦ map1 f g e ≡ g(x)))
map1-values {e = Either.Left a} = [∨]-introₗ ([∃]-intro a ⦃ reflexivity(_≡_) ⦄)
map1-values {e = Either.Right b} = [∨]-introᵣ ([∃]-intro b ⦃ reflexivity(_≡_) ⦄)
module _ where
module _ ⦃ _ : Equiv{ℓₑ}(A ‖ B) ⦄ where
mapLeft-preserves-id : Names.Preserving₀ ⦃ [⊜]-equiv ⦄ (mapLeft {A₁ = A}{B = B})(id)(id)
_⊜_.proof (mapLeft-preserves-id) {Left x} = reflexivity(_≡_)
_⊜_.proof (mapLeft-preserves-id) {Right x} = reflexivity(_≡_)
mapRight-preserves-id : Names.Preserving₀ ⦃ [⊜]-equiv ⦄ (mapRight {A = A}{B₁ = B})(id)(id)
_⊜_.proof (mapRight-preserves-id) {Left x} = reflexivity(_≡_)
_⊜_.proof (mapRight-preserves-id) {Right x} = reflexivity(_≡_)
swap-involution : (Either.swap ∘ Either.swap {A = A}{B = B} ⊜ id)
_⊜_.proof swap-involution {Left _} = reflexivity(_≡_)
_⊜_.proof swap-involution {Right _} = reflexivity(_≡_)
module _ ⦃ _ : let _ = A₁ ; _ = A₂ ; _ = A₃ ; _ = B in Equiv{ℓₑ}(A₃ ‖ B) ⦄ {f : A₂ → A₃} {g : A₁ → A₂} where
mapLeft-preserves-[∘] : (mapLeft(f ∘ g) ⊜ (mapLeft f) ∘ (mapLeft g))
_⊜_.proof mapLeft-preserves-[∘] {Left x} = reflexivity(_≡_)
_⊜_.proof mapLeft-preserves-[∘] {Right x} = reflexivity(_≡_)
module _ ⦃ _ : let _ = A ; _ = B₁ ; _ = B₂ ; _ = B₃ in Equiv{ℓₑ}(A ‖ B₃) ⦄ {f : B₂ → B₃} {g : B₁ → B₂} where
mapRight-preserves-[∘] : (mapRight(f ∘ g) ⊜ (mapRight f) ∘ (mapRight g))
_⊜_.proof mapRight-preserves-[∘] {Left x} = reflexivity(_≡_)
_⊜_.proof mapRight-preserves-[∘] {Right x} = reflexivity(_≡_)
module _ ⦃ _ : Equiv{ℓₑ}(A ‖ B) ⦄ where
map-preserves-id : (map id id ⊜ id)
_⊜_.proof map-preserves-id {Left x} = reflexivity(_≡_)
_⊜_.proof map-preserves-id {Right x} = reflexivity(_≡_)
module _
⦃ equiv-A₁ : Equiv{ℓₑ₁}(A₁) ⦄
⦃ equiv-B₁ : Equiv{ℓₑ₂}(B₁) ⦄
⦃ equiv-A₂ : Equiv{ℓₑ₃}(A₂) ⦄
⦃ equiv-B₂ : Equiv{ℓₑ₄}(B₂) ⦄
⦃ equiv-AB₁ : Equiv{ℓₑ₅}(A₁ ‖ B₁) ⦄ ⦃ ext-AB₁ : Extensionality(equiv-AB₁) ⦄
⦃ equiv-AB₂ : Equiv{ℓₑ₆}(A₂ ‖ B₂) ⦄ ⦃ ext-AB₂ : Extensionality(equiv-AB₂) ⦄
{f : A₁ → A₂}
{g : B₁ → B₂}
where
open Extensionality ⦃ … ⦄
instance
map-function : BinaryOperator(Either.map {A₁ = A₁}{A₂ = A₂}{B₁ = B₁}{B₂ = B₂})
_⊜_.proof (BinaryOperator.congruence map-function (intro p₁) (intro p₂)) {Left _} = congruence₁(Left) p₁
_⊜_.proof (BinaryOperator.congruence map-function (intro p₁) (intro p₂)) {Right _} = congruence₁(Right) p₂
instance
map-injective : ⦃ inj-f : Injective(f) ⦄ → ⦃ inj-g : Injective(g) ⦄ → Injective(Either.map f g)
Injective.proof map-injective {Left x} {Left y} p = congruence₁(Either.Left) (injective(f) (injective(Either.Left) p))
Injective.proof map-injective {Left x} {Right y} p with () ← Left-Right-inequality p
Injective.proof map-injective {Right x} {Left y} p with () ← Left-Right-inequality (symmetry(_≡_) p)
Injective.proof map-injective {Right x} {Right y} p = congruence₁(Either.Right) (injective(g) (injective(Either.Right) p))
instance
map-surjective : ⦃ surj-f : Surjective(f) ⦄ → ⦃ surj-g : Surjective(g) ⦄ → Surjective(Either.map f g)
Surjective.proof map-surjective {Left y} with [∃]-intro x ⦃ p ⦄ ← surjective(f){y} = [∃]-intro (Left x) ⦃ congruence₁(Left) p ⦄
Surjective.proof map-surjective {Right y} with [∃]-intro x ⦃ p ⦄ ← surjective(g){y} = [∃]-intro (Right x) ⦃ congruence₁(Right) p ⦄
instance
map-bijective : ⦃ bij-f : Bijective(f) ⦄ → ⦃ bij-g : Bijective(g) ⦄ → Bijective(Either.map f g)
map-bijective = injective-surjective-to-bijective(Either.map f g) where
instance
inj-f : Injective(f)
inj-f = bijective-to-injective(f)
instance
inj-g : Injective(g)
inj-g = bijective-to-injective(g)
instance
surj-f : Surjective(f)
surj-f = bijective-to-surjective(f)
instance
surj-g : Surjective(g)
surj-g = bijective-to-surjective(g)
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
⦃ equiv-AB : Equiv{ℓₑ}(A ‖ B) ⦄ ⦃ ext-AB : Extensionality(equiv-AB) ⦄
where
map-mapLeft-mapRight : ∀{f : B → A}{g : C → B} → (map f g ≡ mapLeft f ∘ mapRight g)
_⊜_.proof (map-mapLeft-mapRight) {[∨]-introₗ _} = reflexivity(_≡_)
_⊜_.proof (map-mapLeft-mapRight) {[∨]-introᵣ _} = reflexivity(_≡_)
instance
map1-function : ⦃ equiv-C : Equiv{ℓₑ₃}(C) ⦄ → BinaryOperator{B = (A ‖ B) → C}(map1)
_⊜_.proof (BinaryOperator.congruence map1-function (intro p₁) (intro p₂)) {Left _} = p₁
_⊜_.proof (BinaryOperator.congruence map1-function (intro p₁) (intro p₂)) {Right _} = p₂
|
{
"alphanum_fraction": 0.634529148,
"avg_line_length": 45.3559322034,
"ext": "agda",
"hexsha": "3882c2189058953d92c486473d80301f3e3a01a5",
"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": "Data/Either/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/Either/Proofs.agda",
"max_line_length": 134,
"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": "Data/Either/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 2198,
"size": 5352
}
|
{-# OPTIONS --guardedness #-}
open import Agda.Builtin.Equality
open import Data.Empty
-- base : Size
-- next : Delay → Size
-- later : Size → Delay
record Delay : Set
data Size : Set
record Delay where
coinductive
constructor later
field now : Size
open Delay
data Size where
base : Size
next : Delay → Size
-- ω ≡ next ω' ≡ next (later (next ω')) ≡ ...
-- ≡ next (later ω) ≡ ...
ω : Size
ω = next ω' -- next (later (next ω))
where
ω' : Delay
-- ω' = later (next ω')
now ω' = next ω'
next' : Size → Size
next' s = next (later s)
{-# ETA Delay #-}
lim : ω ≡ next' ω
lim = refl
data FSize : Size → Set where
fbase : FSize base
fnext : {d : Delay} → FSize (now d) → FSize (next d)
inf : FSize ω → ⊥
inf (fnext s) = inf s
data Nat : Size → Set where
zero : (s : Size) → Nat (next' s)
succ : (s : Size) → Nat s → Nat (next' s)
shift : ∀ s → Nat s → Nat (next' s)
shift _ (zero s) = zero (next' s)
shift _ (succ s n) = succ (next' s) (shift s n)
postulate blocker : ∀ s → Nat s → Nat s
-- The guard condition passes due to recursion on n,
-- not due to recusion on the size, since it doesn't know that
-- `now s` is in fact smaller than s without using Agda's sized types
-- (or the old version of coinductive types with musical notation).
zeroify : ∀ s → Nat s → Nat s
zeroify base ()
zeroify (next s) (zero _) = zero _
zeroify (next s) (succ _ n) = shift (now s) (zeroify (now s) (blocker (now s) n))
|
{
"alphanum_fraction": 0.6143154969,
"avg_line_length": 22.8412698413,
"ext": "agda",
"hexsha": "107a72458be8734ebfa4e893eda79078315b6ab0",
"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": "8fe15af8f9b5021dc50bcf96665e0988abf28f3c",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "ionathanch/msc-thesis",
"max_forks_repo_path": "code/InftyConat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fe15af8f9b5021dc50bcf96665e0988abf28f3c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "ionathanch/msc-thesis",
"max_issues_repo_path": "code/InftyConat.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fe15af8f9b5021dc50bcf96665e0988abf28f3c",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "ionathanch/msc-thesis",
"max_stars_repo_path": "code/InftyConat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 491,
"size": 1439
}
|
{-# OPTIONS --without-K #-}
open import BaseOver
module Spaces.FlatteningTypes {i j k}
(A : Set i) (B : Set j) (f g : B → A)
(C : A → Set k) (D : (b : B) → C (f b) ≃ C (g b)) where
ijk = max i (max j k)
module BaseHIT where
{-
data W : Set where
cc : A → W
pp : (b : B) → cc (f b) ≡ cc (g b)
-}
private
data #W : Set ijk where
#cc : A → #W
W : Set ijk
W = #W
cc : A → W
cc = #cc
postulate
pp : (b : B) → cc (f b) ≡ cc (g b)
W-rec : ∀ {ℓ} (P : W → Set ℓ) (cc* : (a : A) → P (cc a))
(pp* : (b : B) → cc* (f b) == cc* (g b) [ P ↓ pp b ])
→ ((w : W) → P w)
W-rec P cc* pp* (#cc a) = cc* a
postulate
W-rec-β : ∀ {ℓ} (P : W → Set ℓ) (cc* : (a : A) → P (cc a))
(pp* : (b : B) → cc* (f b) == cc* (g b) [ P ↓ pp b ])
→ ((b : B) → apd (W-rec P cc* pp*) (pp b) ≡ pp* b)
W-rec-nondep : ∀ {ℓ} (P : Set ℓ) (cc* : A → P)
(pp* : (b : B) → cc* (f b) ≡ cc* (g b))
→ (W → P)
W-rec-nondep P cc* pp* (#cc a) = cc* a
postulate
W-rec-nondep-β : ∀ {ℓ} (P : Set ℓ) (cc* : A → P)
(pp* : (b : B) → cc* (f b) ≡ cc* (g b))
→ ((b : B) → ap (W-rec-nondep P cc* pp*) (pp b) ≡ pp* b)
open BaseHIT public
module FlattenedHIT where
{-
data Wt : Set where
cct : (a : A) → C a → Wt
pp : (b : B) (d : C (f b)) → cct (f b) d ≡ cct (g b) (π₁ (D b) d)
-}
private
data #Wt : Set ijk where
#cct : (a : A) (c : C a) → #Wt
Wt : Set ijk
Wt = #Wt
cct : (a : A) → C a → Wt
cct = #cct
postulate
ppt : (b : B) (d : C (f b)) → cct (f b) d ≡ cct (g b) (π₁ (D b) d)
Wt-rec : ∀ {ℓ} (P : Wt → Set ℓ) (cct* : (a : A) (c : C a) → P (cct a c))
(ppt* : (b : B) (d : C (f b)) →
cct* (f b) d == cct* (g b) (π₁ (D b) d) [ P ↓ ppt b d ])
→ ((w : Wt) → P w)
Wt-rec P cct* ppt* (#cct a c) = cct* a c
postulate
Wt-rec-β : ∀ {ℓ} (P : Wt → Set ℓ) (cct* : (a : A) (c : C a) → P (cct a c))
(ppt* : (b : B) (d : C (f b)) →
cct* (f b) d == cct* (g b) (π₁ (D b) d) [ P ↓ ppt b d ])
→ ((b : B) (d : C (f b)) → apd (Wt-rec P cct* ppt*) (ppt b d) ≡ ppt* b d)
Wt-rec-nondep : ∀ {ℓ} (P : Set ℓ) (cct* : (a : A) → C a → P)
(ppt* : (b : B) (d : C (f b)) → cct* (f b) d ≡ cct* (g b) (π₁ (D b) d))
→ (Wt → P)
Wt-rec-nondep P cct* ppt* (#cct a c) = cct* a c
postulate
Wt-rec-nondep-β : ∀ {ℓ} (P : Set ℓ) (cct* : (a : A) → C a → P)
(ppt* : (b : B) (d : C (f b)) → cct* (f b) d ≡ cct* (g b) (π₁ (D b) d))
→ ((b : B) (d : C (f b))
→ ap (Wt-rec-nondep P cct* ppt*) (ppt b d) ≡ ppt* b d)
open FlattenedHIT public
-- Here is the fibration
D-eq : (b : B) → C (f b) ≡ C (g b)
D-eq b = ua-in (D b)
P : W → Set k
P = W-rec-nondep _ C D-eq
pp-path : (b : B) (d : C (f b)) → π₁ (ua-out (ap P (pp b))) d ≡ π₁ (D b) d
pp-path b d =
π₁ (ua-out (ap P (pp b))) d
≡⟨ W-rec-nondep-β _ C D-eq _ |in-ctx (λ u → π₁ (ua-out u) d) ⟩
π₁ (ua-out (ua-in (D b))) d
≡⟨ ua-β (D b) |in-ctx (λ u → π₁ u d) ⟩
π₁ (D b) d ∎
lem : ∀ {i} {A : Set i} {x y z : A} (p : x ≡ y) (q : y ≡ z)
→ ! p ∘ (p ∘' q) ≡ q
lem refl refl = refl
-- Dependent path in [P] over [pp b]
module _ {b : B} {d : C (f b)} {d' : C (g b)} where
↓-pp-in : (π₁ (D b) d ≡ d' → d == d' [ P ↓ pp b ])
↓-pp-in p = to-transp-in P (pp b) (pp-path b d ∘' p)
↓-pp-out : (d == d' [ P ↓ pp b ] → π₁ (D b) d ≡ d')
↓-pp-out p = ! (pp-path b d) ∘ to-transp-out p
↓-pp-β : (q : π₁ (D b) d ≡ d') → ↓-pp-out (↓-pp-in q) ≡ q
↓-pp-β q =
↓-pp-out (↓-pp-in q)
≡⟨ refl ⟩
! (pp-path b d) ∘ to-transp-out (to-transp-in P (pp b) (pp-path b d ∘' q))
≡⟨ to-transp-β P (pp b) (pp-path b d ∘' q) |in-ctx (λ u → ! (pp-path b d) ∘ u) ⟩
! (pp-path b d) ∘ (pp-path b d ∘' q)
≡⟨ lem (pp-path b d) q ⟩
q ∎
|
{
"alphanum_fraction": 0.401471361,
"avg_line_length": 28.1925925926,
"ext": "agda",
"hexsha": "d1cb049d27fd95ad9df82051238a3da9be6d62be",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Spaces/FlatteningTypes.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Spaces/FlatteningTypes.agda",
"max_line_length": 95,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "old/Spaces/FlatteningTypes.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": 1885,
"size": 3806
}
|
{-# OPTIONS -v treeless.opt:20 #-}
module _ where
open import Agda.Builtin.Nat renaming (_<_ to _<?_)
open import Common.Prelude
open import Common.Equality
data _<_ (a b : Nat) : Set where
diff : (k : Nat) → b ≡ suc k + a → a < b
data Comparison {a} {A : Set a} (_<_ : A → A → Set a) (x y : A) : Set a where
less : x < y → Comparison _<_ x y
equal : x ≡ y → Comparison _<_ x y
greater : y < x → Comparison _<_ x y
compare : (a b : Nat) → Comparison _<_ a b
compare a b with a <? b
... | true = less (diff (b ∸ suc a) primTrustMe)
... | false with b <? a
... | true = greater (diff (a ∸ suc b) primTrustMe)
... | false = equal primTrustMe
{-# INLINE compare #-}
-- This should compile to two calls of _<?_ and only the possible cases.
compare-lots : (a b : Nat) → String
compare-lots a b with compare a b | compare (suc a) (suc b)
compare-lots a b | less (diff k eq) | less (diff k₁ eq₁) = "less-less"
compare-lots a .a | less (diff k eq) | equal refl = "less-equal"
compare-lots a _ | less (diff k refl) | greater (diff j eq) = "less-greater"
compare-lots a .a | equal refl | less (diff k eq₁) = "equal-less"
compare-lots a b | equal eq | equal eq₁ = "equal-equal"
compare-lots a .a | equal refl | greater (diff k eq₁) = "equal-greater"
compare-lots _ b | greater (diff k refl) | less (diff j eq) = "greater-less"
compare-lots _ b | greater (diff k refl) | equal eq = "greater-equal"
compare-lots a b | greater (diff k eq) | greater (diff k₁ eq₁) = "greater-greater"
main : IO Unit
main = putStrLn (compare-lots 1500 2000) ,,
putStrLn (compare-lots 2000 1500) ,,
putStrLn (compare-lots 2000 2000)
|
{
"alphanum_fraction": 0.6336996337,
"avg_line_length": 39,
"ext": "agda",
"hexsha": "7702bd8b26c578403cb1661abedb247c539d60f9",
"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/CompareNat.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Compiler/simple/CompareNat.agda",
"max_line_length": 82,
"max_stars_count": 7,
"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/CompareNat.agda",
"max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z",
"num_tokens": 541,
"size": 1638
}
|
{-# OPTIONS --without-K #-}
module hott.equivalence.inverse where
open import level
open import sum
open import function.core
open import function.isomorphism.core
open import function.isomorphism.utils
open import function.isomorphism.properties
open import function.extensionality
open import function.overloading
open import equality.core
open import sets.unit
open import sets.nat.core using (suc)
open import hott.level
open import hott.equivalence.core
open import hott.equivalence.alternative
open import hott.univalence
module _ {i j}{A : Set i}{B : Set j} where
record inverse (f : A → B) : Set (i ⊔ j) where
constructor mk-inverse
field
g : B → A
α : (x : A) → g (f x) ≡ x
β : (y : B) → f (g y) ≡ y
isom : A ≅ B
isom = iso f g α β
iso⇒inv : (f : A ≅ B) → inverse (apply f)
iso⇒inv (iso f g α β) = mk-inverse g α β
inverse-struct-iso : (f : A → B)
→ inverse f
≅ ( Σ (B → A) λ g
→ Σ ((x : A) → g (f x) ≡ x) λ α
→ ((y : B) → f (g y) ≡ y) )
inverse-struct-iso f = record
{ to = λ { (mk-inverse g α β) → (g , α , β) }
; from = λ { (g , α , β) → (mk-inverse g α β) }
; iso₁ = λ _ → refl
; iso₂ = λ _ → refl }
≅-inv-struct-iso : (A ≅ B) ≅ Σ (A → B) inverse
≅-inv-struct-iso = trans≅ ≅-struct-iso
(Σ-ap-iso₂ (λ f → sym≅ (inverse-struct-iso f)))
ind-≈ : (P : ∀ {i}{A B : Set i} → A ≈ B → Set i)
→ (∀ {i}{A : Set i} → P {A = A} (≡⇒≈ refl))
→ ∀ {i}{A B : Set i}(eq : A ≈ B) → P eq
ind-≈ P d {A = A} eq = subst P (_≅_.iso₂ uni-iso eq)
(lem (≈⇒≡ eq))
where
lem : ∀ {i}{A B : Set i}
→ (p : A ≡ B)
→ P (≡⇒≈ p)
lem refl = d
inverse-nonprop' : ∀ {i}{A : Set i}
→ inverse (λ (x : A) → x)
≅ ((x : A) → x ≡ x)
inverse-nonprop' {i}{A} = begin
inverse id'
≅⟨ inverse-struct-iso id' ⟩
( Σ (A → A) λ g
→ Σ ((x : A) → g x ≡ x) λ α
→ ((y : A) → g y ≡ y) )
≅⟨ ( Σ-ap-iso₂ λ g
→ Σ-ap-iso₁ strong-funext-iso ) ⟩
( Σ (A → A) λ g
→ Σ (g ≡ id') λ α
→ ((y : A) → g y ≡ y) )
≅⟨ sym≅ Σ-assoc-iso ⟩
( Σ (singleton' id') λ { (g , α)
→ ((y : A) → g y ≡ y) } )
≅⟨ trans≅ (Σ-ap-iso' (contr-⊤-iso (singl-contr' id'))
(λ _ → refl≅))
×-left-unit ⟩
((x : A) → x ≡ x)
∎
where
open ≅-Reasoning
id' : A → A
id' x = x
inverse-nonprop : ∀ {i}{A B : Set i}
→ (f : A → B)
→ weak-equiv f
→ inverse f
≅ ((x : A) → x ≡ x)
inverse-nonprop {i}{A} f we = ind-≈ P inverse-nonprop' (f , we)
where
P : ∀ {i}{A B : Set i} → A ≈ B → Set _
P {A = A} (f , we) = inverse f ≅ ((x : A) → x ≡ x)
|
{
"alphanum_fraction": 0.4625044851,
"avg_line_length": 28.7319587629,
"ext": "agda",
"hexsha": "240624d5f14d2ccda715df8f1f4021882f14615c",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/hott/equivalence/inverse.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/hott/equivalence/inverse.agda",
"max_line_length": 63,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "hott/equivalence/inverse.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 1095,
"size": 2787
}
|
{-# OPTIONS --cubical --allow-unsolved-metas #-}
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
module _ where
data D {ℓ} (A : Set ℓ) : Set ℓ where
c : PathP _ _ _
|
{
"alphanum_fraction": 0.6923076923,
"avg_line_length": 19.5,
"ext": "agda",
"hexsha": "ed04f7d7b603627c11cc4f16b428cff10ac1f9f7",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Succeed/Issue3659.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Succeed/Issue3659.agda",
"max_line_length": 48,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Succeed/Issue3659.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 66,
"size": 195
}
|
{-# OPTIONS --without-K --safe #-}
-- Pi combinators inspired by duals and traced monoidal categories
module Trace where
open import Data.Product using (Σ; _,_; proj₁; proj₂)
open import Relation.Binary.PropositionalEquality
using (_≡_; subst)
open import PiFrac
------------------------------------------------------------------
dual : {A B : 𝕌} → (f : A ⟷ B) → (v : ⟦ A ⟧ ) →
(𝟙/● B [ eval f v ] ⟷ 𝟙/● A [ v ])
dual f v = uniti⋆l ⊚ (η v ⊗ id⟷) ⊚ ((lift f ⊗ id⟷) ⊗ id⟷) ⊚
assocr⋆ ⊚ (id⟷ ⊗ swap⋆) ⊚ assocl⋆ ⊚ (ε (eval f v) ⊗ id⟷) ⊚ unite⋆l
-- name, coname
name : {A B : 𝕌} → (f : A ⟷ B) → (v : ⟦ A ⟧ ) → 𝟙 ⟷ ● B [ eval f v ] ×ᵤ 𝟙/● A [ v ]
name f v = η v ⊚ (lift f ⊗ id⟷)
coname : {A B : 𝕌} → (f : A ⟷ B) → (v : ⟦ A ⟧ ) → ● A [ v ] ×ᵤ 𝟙/● B [ eval f v ] ⟷ 𝟙
coname f v = (lift f ⊗ id⟷) ⊚ ε (eval f v)
-- and 'trace' reveals something neat: we can't choose just any random 'a' and 'c'
-- to start with, but we need that make a coherence choice of a and c !!
trace : {A B C : 𝕌} (a : ⟦ A ⟧ ) → (f : A ×ᵤ C ⟷ B ×ᵤ C) →
(coh : Σ ⟦ C ⟧ (λ c → proj₂ (eval f (a , c)) ≡ c)) →
● A [ a ] ⟷ ● B [ proj₁ (eval f (a , proj₁ coh)) ]
trace {A} {B} {C} a f (c , choice) =
uniti⋆r ⊚ -- A ×ᵤ 1
(id⟷ ⊗ η c) ⊚ -- A ×ᵤ (C ×ᵤ 1/C)
assocl⋆ ⊚ -- (A ×ᵤ C) ×ᵤ 1/C
(tensorr ⊗ id⟷) ⊚ -- bring in the ●
(lift f ⊗ id⟷) ⊚ -- (B ×ᵤ C) ×ᵤ 1/C
(tensorl ⊗ id⟷) ⊚ -- bring out the ●
assocr⋆ ⊚ -- B ×ᵤ (C ×ᵤ 1/C)
(id⟷ ⊗ (subst fixer choice id⟷ ⊚ ε c)) ⊚ -- B ×ᵤ 1
unite⋆r
where
fixer : ⟦ C ⟧ → Set
fixer d = (● C [ proj₂ (eval f (a , c)) ] ×ᵤ 𝟙/● C [ d ]) ⟷ (● C [ d ] ×ᵤ 𝟙/● C [ d ])
|
{
"alphanum_fraction": 0.4489920586,
"avg_line_length": 36.3777777778,
"ext": "agda",
"hexsha": "2bdc8c2351bf3bbb060e862031cc287bfc163dca",
"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/Trace.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/Trace.agda",
"max_line_length": 90,
"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/Trace.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": 804,
"size": 1637
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- The unit type
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Unit where
import Relation.Binary.PropositionalEquality as PropEq
------------------------------------------------------------------------
-- Re-export contents of base module
open import Data.Unit.Base public
------------------------------------------------------------------------
-- Re-export query operations
open import Data.Unit.Properties public
using (_≟_; _≤?_)
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.1
setoid = Data.Unit.Properties.≡-setoid
{-# WARNING_ON_USAGE setoid
"Warning: setoid was deprecated in v1.1.
Please use ≡-setoid from Data.Unit.Properties instead."
#-}
decSetoid = Data.Unit.Properties.≡-decSetoid
{-# WARNING_ON_USAGE decSetoid
"Warning: decSetoid was deprecated in v1.1.
Please use ≡-decSetoid from Data.Unit.Properties instead."
#-}
total = Data.Unit.Properties.≡-total
{-# WARNING_ON_USAGE total
"Warning: total was deprecated in v1.1.
Please use ≡-total from Data.Unit.Properties instead"
#-}
poset = Data.Unit.Properties.≡-poset
{-# WARNING_ON_USAGE poset
"Warning: poset was deprecated in v1.1.
Please use ≡-poset from Data.Unit.Properties instead."
#-}
decTotalOrder = Data.Unit.Properties.≡-decTotalOrder
{-# WARNING_ON_USAGE decTotalOrder
"Warning: decTotalOrder was deprecated in v1.1.
Please use ≡-decTotalOrder from Data.Unit.Properties instead."
#-}
preorder = PropEq.preorder ⊤
{-# WARNING_ON_USAGE decTotalOrder
"Warning: preorder was deprecated in v1.1.
Please use ≡-preorder from Data.Unit.Properties instead."
#-}
|
{
"alphanum_fraction": 0.5859053498,
"avg_line_length": 31.3548387097,
"ext": "agda",
"hexsha": "1490fdd99db01017b56b751dcbc9d5b6e0869d38",
"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/Unit.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/Unit.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/Data/Unit.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": 416,
"size": 1944
}
|
module Logic where
data True : Set where
tt : True
data False : Set where
|
{
"alphanum_fraction": 0.6875,
"avg_line_length": 8.8888888889,
"ext": "agda",
"hexsha": "205ea18fdfd958207cb931c194f56cebec56648d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/tactics/ac/Logic.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/tactics/ac/Logic.agda",
"max_line_length": 22,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/tactics/ac/Logic.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": 22,
"size": 80
}
|
module Data.Option.Equiv where
import Lvl
open import Data.Option
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Setoid
open import Type
private variable ℓ ℓₑ ℓₑₐ : Lvl.Level
private variable A : Type{ℓ}
record Extensionality ⦃ equiv-A : Equiv{ℓₑₐ}(A) ⦄ (equiv : Equiv{ℓₑ}(Option(A))) : Type{Lvl.of(A) Lvl.⊔ ℓₑₐ Lvl.⊔ ℓₑ} where
constructor intro
private instance _ = equiv
field
⦃ Some-function ⦄ : Function Some
⦃ Some-injective ⦄ : Injective Some
cases-inequality : ∀{x : A} → (None ≢ Some(x))
|
{
"alphanum_fraction": 0.7102473498,
"avg_line_length": 28.3,
"ext": "agda",
"hexsha": "657dbb105cd24ccc4b7df6f712dda4d104842062",
"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": "Data/Option/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": "Data/Option/Equiv.agda",
"max_line_length": 123,
"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": "Data/Option/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": 199,
"size": 566
}
|
{-# OPTIONS --copatterns --sized-types --experimental-irrelevance #-}
-- {-# OPTIONS --show-implicit --show-irrelevant #-}
-- {-# OPTIONS -v tc.polarity:10 -v tc.pos:15 -v tc.size.solve:100 #-}
module SizedCoinductiveRecords where
open import Common.Size
{- THIS WOULD BE A BETTER TYPING FOR sizeSuc, but it requires builtin Size<
sizeSuc : (i : Size) → Size< (↑ (↑ i))
sizeSuc i = ↑ i
-}
-- -- Subtyping for Size<
-- Andreas, 2015-03-15: Functions returning sizes are now illegal:
-- emb< : {i : Size} → Size< i → Size
-- emb< {i} j = j
-- Use Size< hypotheses
data Empty : {i : Size} → Set where
empty : {i : Size} → Empty {i} → Empty {↑ i}
subEmpty : {i : Size}{j : Size< i} → Empty {j} → Empty {i}
subEmpty x = x
-- SHOULD FAIL:
-- fail : {i : Size}{j : Size< i} → Empty {i} → Empty {j}
-- fail x = x
-- -- Covariance for Size<
-- Andreas, 2015-03-15: Functions returning sizes are now illegal:
-- co : {i : Size}{j : Size< i} → Size< j → Size< i
-- co k = k
-- Contravariance for bounded quantification
Bounded : Size → Set
Bounded i = (j : Size< i) → Empty {j}
contra : {i : Size}{j : Size< i} → Bounded i → Bounded j
contra k = k
-- sized naturals
data Nat {i : Size} : Set where
zero : Nat
suc : {j : Size< i} → Nat {j} → Nat
-- polarity of successor
data Bool : Set where
true false : Bool
-- a natural number
one : Nat
one = suc {i = ∞} zero
mySuc : {i : Size} → Nat {i} → Nat {↑ i}
mySuc x = suc x
pred : {i : Size} → Nat {↑ i} → Nat {i}
pred zero = zero
pred (suc n) = n
shift : {i : Size} → (Nat → Nat {↑ i}) → Nat → Nat {i}
shift f n = pred (f (suc n))
{- Does not type check
loop : {i : Size} → Nat {i} → (Nat → Nat {i}) → Set
loop (suc n) f = loop n (shift f)
loop zero = Nat
-}
data ⊥ : Set where
record ⊤ : Set where
mono : {i : Size}{j : Size< i} → Nat {j} → Nat {i}
mono n = n
id : {i : Size} → Nat {i} → Nat {i}
id (zero) = zero
id (suc n) = suc (id n)
monus : {i : Size} → Nat {i} → Nat → Nat {i}
monus x zero = x
monus zero y = zero
monus (suc x) (suc y) = monus x y
div : {i : Size} → Nat {i} → Nat → Nat {i}
div zero y = zero
div (suc x) y = suc (div (monus x y) y)
-- postulate _∪_ : {i : Size} → Size< i → Size< i → Size< i
{-
max : {i : Size} → Nat {i} → Nat {i} → Nat {i}
max zero n = n
max m zero = m
max {i} (suc {j = j} m) (suc {j = k} n) = suc {j = j ∪ k} (max {j ∪ k} m n)
-}
-- omega inst
{- DOES NOT MAKE SENSE:
omegaBad' : (F : Size → Set) (i : Size) (j : Size< i)
(f : (k : Size< (↑ j)) → F k) → F j
omegaBad' F i j f = f j
-}
-- fix
A : Size → Set
A i = Nat {i} → Nat
{-# TERMINATING #-}
fix : (f : (i : Size) → ((j : Size< i) → A j) → A i) → (i : Size) → A i
fix f i zero = zero
fix f i (suc {j} n) = f i (λ j → fix f j) (suc n)
-- forever : {i : Size} → ({j : Size< i} → Nat {i} → Nat {j}) → Nat {i} → ⊥
-- forever {i} f n = forever f (f {{!!}} n)
-- sized streams
module STREAM where
record Stream (A : Set) {i : Size} : Set where
coinductive
constructor _∷_
field
head : A
tail : {j : Size< i} → Stream A {j}
open Stream
map : {A B : Set}(f : A → B){i : Size} → Stream A {i} → Stream B {i}
head (map f s) = f (head s)
tail (map f s) = map f (tail s)
-- stream antitone
anti : {A : Set}{i : Size}{j : Size< i} → Stream A {i} → Stream A {j}
anti s = s
anti' : {A : Set}{i : Size}{j : Size< i} → (Stream A {j} → A) → (Stream A {i} → A)
anti' f = f
-- Spanning tree
data List (A : Set) {i : Size} : Set where
[] : List A
_∷_ : {j : Size< i}(x : A)(xs : List A {j}) → List A
map : {A B : Set}(f : A → B){i : Size} → List A {i} → List B {i}
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
module Graph (I : Set)(adj : I → List I) where
record Span {i : Size} : Set where
coinductive
constructor span
field
root : I
nodes : {j : Size< i} → List (Span {j})
open Span
tree : {i : Size} → I → Span {i}
root (tree root) = root
nodes (tree root) = map (tree) (adj root)
|
{
"alphanum_fraction": 0.533266129,
"avg_line_length": 23.0697674419,
"ext": "agda",
"hexsha": "5254b9a589ecc9e898d7a376a66ed20a4ca73ab0",
"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/Succeed/SizedCoinductiveRecords.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Succeed/SizedCoinductiveRecords.agda",
"max_line_length": 84,
"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/Succeed/SizedCoinductiveRecords.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1525,
"size": 3968
}
|
module Validation where
open import OscarPrelude
open import 𝓐ssertion
open import HasSatisfaction
open import Interpretation
module _ {A} ⦃ _ : HasSatisfaction A ⦄
where
⊨_ : A → Set
⊨ x = (I : Interpretation) → I ⊨ x
⊭_ : A → Set
⊭_ = ¬_ ∘ ⊨_
|
{
"alphanum_fraction": 0.6539923954,
"avg_line_length": 15.4705882353,
"ext": "agda",
"hexsha": "6df84fafa9ce874c98bed93bc6ffba952e416600",
"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/Validation.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/Validation.agda",
"max_line_length": 38,
"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/Validation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 98,
"size": 263
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.HopfInvariant.Base where
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.Group.Base
open import Cubical.Homotopy.Group.SuspensionMap
open import Cubical.Relation.Nullary
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.MayerVietorisUnreduced
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.Groups.Wedge
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.ZCohomology.RingStructure.CupProduct
open import Cubical.ZCohomology.RingStructure.GradedCommutativity
open import Cubical.ZCohomology.Gysin
open import Cubical.Foundations.Path
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Function
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
open import Cubical.Data.Int hiding (_+'_)
open import Cubical.Data.Nat renaming (_+_ to _+ℕ_ ; _·_ to _·ℕ_)
open import Cubical.Data.Unit
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.ZAction
open import Cubical.Algebra.Group.Exact
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Instances.Int
open import Cubical.Algebra.Group.Instances.Unit
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.HITs.Wedge
open import Cubical.HITs.Truncation
renaming (rec to trRec)
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)
-- The pushout of the hopf invariant
HopfInvariantPush : (n : ℕ)
→ (f : S₊ (3 +ℕ n +ℕ n) → S₊ (2 +ℕ n))
→ Type _
HopfInvariantPush n f = Pushout (λ _ → tt) f
Hopfα : (n : ℕ)
→ (f : S₊∙ (3 +ℕ n +ℕ n) →∙ S₊∙ (2 +ℕ n))
→ coHom (2 +ℕ n) (HopfInvariantPush n (fst f))
Hopfα n f = ∣ (λ { (inl x) → 0ₖ _
; (inr x) → ∣ x ∣
; (push a i) → help a (~ i)}) ∣₂
where
help : (a : S₊ (3 +ℕ n +ℕ n)) → ∣ fst f a ∣ ≡ 0ₖ (2 +ℕ n)
help = sphereElim _ (λ _ → isOfHLevelPlus' {n = n} (3 +ℕ n)
(isOfHLevelPath' (3 +ℕ n) (isOfHLevelTrunc (4 +ℕ n)) _ _))
(cong ∣_∣ₕ (snd f))
Hopfβ : (n : ℕ)
→ (f : S₊∙ (3 +ℕ n +ℕ n) →∙ S₊∙ (2 +ℕ n))
→ coHom (4 +ℕ (n +ℕ n)) (HopfInvariantPush n (fst f))
Hopfβ n f = fst (MV.d _ _ _ (λ _ → tt) (fst f) (3 +ℕ n +ℕ n)) ∣ ∣_∣ ∣₂
-- To define the Hopf invariant, we need to establish the
-- non-trivial isos of Hⁿ(HopfInvariant).
module _ (n : ℕ) (f : S₊∙ (3 +ℕ n +ℕ n) →∙ S₊∙ (2 +ℕ n)) where
module M = MV _ _ _ (λ _ → tt) (fst f)
¬lemHopf : (n m : ℕ) → ¬ suc (suc (m +ℕ n)) ≡ suc n
¬lemHopf zero zero p = snotz (cong predℕ p)
¬lemHopf (suc n) zero p = ¬lemHopf n zero (cong predℕ p)
¬lemHopf zero (suc m) p = snotz (cong predℕ p)
¬lemHopf (suc n) (suc m) p =
¬lemHopf n (suc m) (cong (suc ∘ suc )
(sym (+-suc m n)) ∙ (cong predℕ p))
SphereHopfCohomIso :
GroupEquiv
(coHomGr (3 +ℕ n +ℕ n) (S₊ (3 +ℕ n +ℕ n)))
((coHomGr (suc (3 +ℕ n +ℕ n)) (HopfInvariantPush _ (fst f))))
fst (fst SphereHopfCohomIso) =
fst (MV.d _ _ _ (λ _ → tt) (fst f) (3 +ℕ n +ℕ n))
snd (fst SphereHopfCohomIso) = help
where
abstract
help : isEquiv (fst (MV.d _ _ _ (λ _ → tt) (fst f)
(3 +ℕ n +ℕ n)))
help =
SES→isEquiv
(isContr→≡UnitGroup
(isContrΣ (GroupIsoUnitGroup→isContr (invGroupIso (Hⁿ-Unit≅0 _)))
λ _ → GroupIsoUnitGroup→isContr
(invGroupIso (Hⁿ-Sᵐ≅0 _ _ (¬lemHopf n n)))))
(isContr→≡UnitGroup
(isContrΣ (GroupIsoUnitGroup→isContr
(invGroupIso (Hⁿ-Unit≅0 _)))
λ _ → GroupIsoUnitGroup→isContr
(invGroupIso (Hⁿ-Sᵐ≅0 _ _ (¬lemHopf n (suc n))))))
(M.Δ (3 +ℕ n +ℕ n))
(M.d (3 +ℕ n +ℕ n))
(M.i (4 +ℕ n +ℕ n))
(M.Ker-d⊂Im-Δ _)
(M.Ker-i⊂Im-d _)
snd SphereHopfCohomIso = d-inv
where
-- Currently, type checking is very slow without the abstract flag.
-- TODO : Remove abstract
abstract
d-inv : IsGroupHom (snd (coHomGr (3 +ℕ n +ℕ n) (S₊ (3 +ℕ n +ℕ n))))
(fst (MV.d _ _ _ (λ _ → tt) (fst f) (3 +ℕ n +ℕ n)))
(snd (coHomGr (suc (3 +ℕ n +ℕ n))
(Pushout (λ _ → tt) (fst f))))
d-inv = snd (MV.d _ _ _ (λ _ → tt) (fst f) (3 +ℕ n +ℕ n))
Hopfβ-Iso : GroupIso (coHomGr (suc (3 +ℕ n +ℕ n))
(HopfInvariantPush _ (fst f)))
ℤGroup
fst Hopfβ-Iso = compIso (invIso (equivToIso (fst SphereHopfCohomIso)))
(fst (Hⁿ-Sⁿ≅ℤ (suc (suc (n +ℕ n)))))
snd Hopfβ-Iso = grHom
where
abstract
grHom :
IsGroupHom (coHomGr (suc (3 +ℕ n +ℕ n))
(Pushout (λ _ → tt) (fst f)) .snd)
(λ x → Iso.fun (fst ((Hⁿ-Sⁿ≅ℤ (suc (suc (n +ℕ n))))))
(invEq (fst SphereHopfCohomIso) x))
(ℤGroup .snd)
grHom = snd (compGroupIso
(GroupEquiv→GroupIso (invGroupEquiv (SphereHopfCohomIso)))
(Hⁿ-Sⁿ≅ℤ (suc (suc (n +ℕ n)))))
Hⁿ-Sⁿ≅ℤ-nice-generator : (n : ℕ) → Iso.inv (fst (Hⁿ-Sⁿ≅ℤ (suc n))) 1 ≡ ∣ ∣_∣ ∣₂
Hⁿ-Sⁿ≅ℤ-nice-generator zero = Iso.leftInv (fst (Hⁿ-Sⁿ≅ℤ (suc zero))) _
Hⁿ-Sⁿ≅ℤ-nice-generator (suc n) =
(λ i → Iso.inv (fst (suspensionAx-Sn (suc n) (suc n)))
(Hⁿ-Sⁿ≅ℤ-nice-generator n i))
∙ cong ∣_∣₂
(funExt λ { north → refl
; south → cong ∣_∣ₕ (merid north)
; (merid a i) j → ∣ compPath-filler (merid a)
(sym (merid north)) (~ j) i ∣ₕ})
Hopfβ↦1 : (n : ℕ) (f : S₊∙ (3 +ℕ n +ℕ n) →∙ S₊∙ (2 +ℕ n))
→ Iso.fun (fst (Hopfβ-Iso n f)) (Hopfβ n f) ≡ 1
Hopfβ↦1 n f =
sym (cong (Iso.fun (fst (Hopfβ-Iso n f))) lem)
∙ Iso.rightInv (fst (Hopfβ-Iso n f)) (pos 1)
where
lem : Iso.inv (fst (Hopfβ-Iso n f)) (pos 1) ≡ Hopfβ n f
lem = (λ i → fst (MV.d _ _ _ (λ _ → tt) (fst f) (3 +ℕ n +ℕ n))
(Hⁿ-Sⁿ≅ℤ-nice-generator _ i))
∙ cong ∣_∣₂ (funExt (λ { (inl x) → refl
; (inr x) → refl
; (push a i) → refl}))
module _ (n : ℕ) (f : S₊∙ (3 +ℕ n +ℕ n) →∙ S₊∙ (2 +ℕ n)) where
private
2+n = 2 +ℕ n
H = HopfInvariantPush n (fst f)
H→Sphere : coHom 2+n H → coHom 2+n (S₊ (suc (suc n)))
H→Sphere = sMap (_∘ inr)
grHom : IsGroupHom (snd (coHomGr 2+n H))
H→Sphere (snd (coHomGr 2+n (S₊ (suc (suc n)))))
grHom =
makeIsGroupHom
(sElim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f g → refl)
preSphere→H : (g : (S₊ (suc (suc n)) → coHomK 2+n))
→ H → coHomK (2 +ℕ n)
preSphere→H g (inl x) = 0ₖ _
preSphere→H g (inr x) = g x -ₖ g north
preSphere→H g (push a i) = lem a i
where
lem : (a : S₊ (suc (suc (suc (n +ℕ n)))))
→ 0ₖ (suc (suc n)) ≡ g (fst f a) -ₖ g north
lem =
sphereElim _
(λ x → isOfHLevelPlus' {n = n} (3 +ℕ n)
(isOfHLevelTrunc (4 +ℕ n) _ _))
(sym (rCancelₖ _ (g north))
∙ cong (λ x → g x -ₖ g north) (sym (snd f)))
Sphere→H : coHom 2+n (S₊ (suc (suc n))) → coHom 2+n H
Sphere→H = sMap preSphere→H
conCohom2+n : (x : _) → ∥ x ≡ 0ₖ (suc (suc n)) ∥₁
conCohom2+n =
coHomK-elim _ (λ _ → isProp→isOfHLevelSuc (suc n) squash₁) ∣ refl ∣₁
HIPSphereCohomIso :
Iso (coHom (2 +ℕ n) (HopfInvariantPush n (fst f)))
(coHom (2 +ℕ n) (S₊ (2 +ℕ n)))
Iso.fun HIPSphereCohomIso = H→Sphere
Iso.inv HIPSphereCohomIso = Sphere→H
Iso.rightInv HIPSphereCohomIso =
sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ g → pRec (squash₂ _ _)
(λ p → cong ∣_∣₂ (funExt λ x → cong (g x +ₖ_) (cong (-ₖ_) p)
∙ rUnitₖ _ (g x)))
(conCohom2+n (g north))
Iso.leftInv HIPSphereCohomIso =
sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ g →
pRec (squash₂ _ _)
(pRec (isPropΠ (λ _ → squash₂ _ _))
(λ gn gtt →
trRec (isProp→isOfHLevelSuc n (squash₂ _ _))
(λ r → cong ∣_∣₂ (funExt λ {
(inl x) → sym gtt
; (inr x) → (λ i → g (inr x) -ₖ gn i)
∙ rUnitₖ _ (g (inr x))
; (push a i)
→ sphereElim _
{A = λ a →
PathP (λ i → preSphere→H (λ x → g (inr x))
(push a i)
≡ g (push a i))
(sym gtt)
((λ i → g (inr (fst f a)) -ₖ gn i)
∙ rUnitₖ _ (g (inr (fst f a))))}
(λ _ → isOfHLevelPathP' (suc (suc (suc (n +ℕ n))))
(isOfHLevelPath (suc (suc (suc (suc (n +ℕ n)))))
(isOfHLevelPlus' {n = n} (suc (suc (suc (suc n))))
(isOfHLevelTrunc (suc (suc (suc (suc n)))))) _ _) _ _)
r a i}))
(push-helper g gtt gn))
(conCohom2+n (g (inr north))))
(conCohom2+n (g (inl tt)))
where
push-helper : (g : HopfInvariantPush n (fst f) → coHomK (suc (suc n)))
→ (gtt : g (inl tt) ≡ 0ₖ (suc (suc n)))
→ (gn : g (inr north) ≡ 0ₖ (suc (suc n)))
→ hLevelTrunc (suc n)
(PathP (λ i → preSphere→H (λ x → g (inr x)) (push north i)
≡ g (push north i))
(sym gtt)
((λ i → g (inr (fst f north)) -ₖ gn i)
∙ rUnitₖ _ (g (inr (fst f north)))))
push-helper g gtt gn =
isConnectedPathP _ (isConnectedPath _ (isConnectedKn _) _ _) _ _ .fst
Hopfα-Iso : GroupIso (coHomGr (2 +ℕ n) (HopfInvariantPush n (fst f))) ℤGroup
Hopfα-Iso =
compGroupIso
(HIPSphereCohomIso , grHom)
(Hⁿ-Sⁿ≅ℤ (suc n))
Hopfα-Iso-α : (n : ℕ) (f : _)
→ Iso.fun (fst (Hopfα-Iso n f)) (Hopfα n f)
≡ 1
Hopfα-Iso-α n f =
sym (cong (Iso.fun (fst (Hⁿ-Sⁿ≅ℤ (suc n)))) (Hⁿ-Sⁿ≅ℤ-nice-generator n))
∙ Iso.rightInv (fst (Hⁿ-Sⁿ≅ℤ (suc n))) (pos 1)
where
hz : Iso.fun (HIPSphereCohomIso n f) (Hopfα n f) ≡ ∣ ∣_∣ ∣₂
hz = refl
⌣-α : (n : ℕ) → (f : S₊∙ (3 +ℕ (n +ℕ n)) →∙ S₊∙ (2 +ℕ n)) → _
⌣-α n f = Hopfα n f ⌣ Hopfα n f
HopfInvariant : (n : ℕ)
→ (f : S₊∙ (3 +ℕ (n +ℕ n)) →∙ S₊∙ (2 +ℕ n))
→ ℤ
HopfInvariant n f = Iso.fun (fst (Hopfβ-Iso n f))
(subst (λ x → coHom x (HopfInvariantPush n (fst f)))
(λ i → suc (suc (suc (+-suc n n i))))
(⌣-α n f))
HopfInvariant-π' : (n : ℕ) → π' (3 +ℕ (n +ℕ n)) (S₊∙ (2 +ℕ n)) → ℤ
HopfInvariant-π' n = sRec isSetℤ (HopfInvariant n)
HopfInvariant-π : (n : ℕ) → π (3 +ℕ (n +ℕ n)) (S₊∙ (2 +ℕ n)) → ℤ
HopfInvariant-π n = sRec isSetℤ λ x → HopfInvariant-π' n ∣ Ω→SphereMap _ x ∣₂
-- Elimination principle for the pushout defining the Hopf Invariant
HopfInvariantPushElim :
∀ {ℓ} n → (f : _)
→ {P : HopfInvariantPush n f → Type ℓ}
→ (isOfHLevel (suc (suc (suc (suc (n +ℕ n))))) (P (inl tt)))
→ (e : P (inl tt))
(g : (x : _) → P (inr x))
(r : PathP (λ i → P (push north i)) e (g (f north)))
→ (x : _) → P x
HopfInvariantPushElim n f {P = P} hlev e g r (inl x) = e
HopfInvariantPushElim n f {P = P} hlev e g r (inr x) = g x
HopfInvariantPushElim n f {P = P} hlev e g r (push a i₁) = help a i₁
where
help : (a : Susp (Susp (S₊ (suc (n +ℕ n)))))
→ PathP (λ i → P (push a i)) e (g (f a))
help =
sphereElim _
(sphereElim _
(λ _ → isProp→isOfHLevelSuc (suc (suc (n +ℕ n)))
(isPropIsOfHLevel _))
(isOfHLevelPathP' (suc (suc (suc (n +ℕ n))))
(subst (isOfHLevel (suc (suc (suc (suc (n +ℕ n))))))
(cong P (push north))
hlev) _ _)) r
|
{
"alphanum_fraction": 0.5129133858,
"avg_line_length": 40.0630914826,
"ext": "agda",
"hexsha": "3640040682ba360de18c265bf3c8befd7fbc98f1",
"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/Homotopy/HopfInvariant/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Homotopy/HopfInvariant/Base.agda",
"max_line_length": 80,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Homotopy/HopfInvariant/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 4883,
"size": 12700
}
|
module Truncation where
open import Cubical.Foundations.Prelude
private
variable
ℓ ℓ₁ : Level
data Susp (A : Type ℓ) : Type ℓ where
north : Susp A
south : Susp A
merid : A → north ≡ south
SuspF : {A : Type ℓ} {B : Type ℓ₁} → (A → B) → Susp A → Susp B
SuspF f north = north
SuspF f south = south
SuspF f (merid a i) = merid (f a) i
data ℕ : Type where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
data ⊥ : Type where
S : ℕ → Type
S 0 = ⊥
S (suc n) = Susp (S n)
data ⊤ : Type where
⋆ : ⊤
D : ℕ → Type
D 0 = ⊤
D (suc n) = Susp (D n)
S→D : {n : ℕ} → S n → D n
S→D {suc n} = SuspF S→D
data ∥_∥_ (A : Type ℓ) (n : ℕ) : Type ℓ where
∣_∣ : A → ∥ A ∥ n
hub : (f : S n → ∥ A ∥ n) (u : D n) → ∥ A ∥ n
spoke : (f : S n → ∥ A ∥ n) (s : S n) → f s ≡ hub f (S→D s)
isOfHLevel : ℕ → Type ℓ → Type ℓ
isOfHLevel 0 A = A
isOfHLevel (suc n) A = (x y : A) → isOfHLevel n (x ≡ y)
sphereFill : (n : ℕ) (A : Type ℓ) (f : S n → A) → Type ℓ
sphereFill n A f = Σ (D n → A) (λ f' → (s : S n) → f s ≡ f' (S→D s))
isSphereFilled : ℕ → Type ℓ → Type ℓ
isSphereFilled n A = (f : S n → A) → sphereFill n A f
isSphereFilled∥∥ : (n : ℕ) (A : Type ℓ) → isSphereFilled n (∥ A ∥ n)
isSphereFilled∥∥ n A f = hub f , spoke f
isSphereFilledDesc : (n : ℕ) (A : Type ℓ)
→ isSphereFilled (suc n) A → (x y : A) → isSphereFilled n (x ≡ y)
isSphereFilledDesc n A h x y g = g' , r
where
f : S (suc n) → A
f north = x
f south = y
f (merid u i) = g u i
g' : D n → x ≡ y
g' u i =
hcomp
(λ j →
λ { (i = i0) → h f .snd north (~ j)
; (i = i1) → h f .snd south (~ j) })
(h f .fst (merid u i))
r : (s : S n) → g s ≡ g' (S→D s)
r s i j =
hcomp
(λ k →
λ { (i = i0) → g s j
; (j = i0) → h f .snd north (i ∧ ~ k)
; (j = i1) → h f .snd south (i ∧ ~ k) })
(h f .snd (merid s j) i)
isSphereFilled→isOfHLevel : (n : ℕ) (A : Type ℓ)
→ isSphereFilled n A → isOfHLevel n A
isSphereFilled→isOfHLevel zero A h = h (λ ()) .fst ⋆
isSphereFilled→isOfHLevel (suc n) A h x y =
isSphereFilled→isOfHLevel n (x ≡ y) (isSphereFilledDesc n A h x y)
isSphereFilledAsc : (n : ℕ) (A : Type ℓ)
→ ((x y : A) → isSphereFilled n (x ≡ y)) → isSphereFilled (suc n) A
isSphereFilledAsc n A h f = f' , r
where
g : S n → f north ≡ f south
g s i = f (merid s i)
f' : D (suc n) → A
f' north = f north
f' south = f south
f' (merid u i) = h (f north) (f south) g .fst u i
r : (s : S (suc n)) → f s ≡ f' (S→D s)
r north = refl
r south = refl
r (merid s i) j = h (f north) (f south) g .snd s j i
isOfHLevel→isSphereFilled : (n : ℕ) (A : Type ℓ)
→ isOfHLevel n A → isSphereFilled n A
isOfHLevel→isSphereFilled 0 A h f = (λ _ → h) , λ ()
isOfHLevel→isSphereFilled (suc n) A h f =
isSphereFilledAsc n A
(λ x y → isOfHLevel→isSphereFilled n (x ≡ y) (h x y)) f
isOfHLevelTrunc : (n : ℕ) (A : Type ℓ) → isOfHLevel n (∥ A ∥ n)
isOfHLevelTrunc n A = isSphereFilled→isOfHLevel n (∥ A ∥ n) (isSphereFilled∥∥ n A)
rec : {n : ℕ} {A : Type ℓ} {B : Type ℓ₁}
→ isOfHLevel n B
→ (A → B) → ∥ A ∥ n → B
rec {n = n} {A = A} {B = B} hB g = helper
where
h : isSphereFilled n B
h = isOfHLevel→isSphereFilled n B hB
helper : ∥ A ∥ n → B
helper ∣ x ∣ = g x
helper (hub f u) = h (λ s → helper (f s)) .fst u
helper (spoke f s i) = h (λ s → helper (f s)) .snd s i
sphereFillDep : (n : ℕ) (A : Type ℓ) (B : A → Type ℓ₁)
(f₀' : D n → A)
→ ((s : S n) → B (f₀' (S→D s)))
→ Type _
sphereFillDep n A B f₀' f = Σ ((u : D n) → B (f₀' u)) (λ f' → (s : S n) → f s ≡ f' (S→D s))
isSphereFilledDep : ℕ → (A : Type ℓ) (B : A → Type ℓ₁) → Type _
isSphereFilledDep n A B =
(f₀' : D n → A)
(f : (s : S n) → B (f₀' (S→D s)))
→ sphereFillDep n A B f₀' f
isSphereFilledDepAsc : (n : ℕ) {A : Type ℓ} (B : A → Type ℓ₁)
→ ((x₀ y₀ : A) (x₁ : B x₀) (y₁ : B y₀) → isSphereFilledDep n (x₀ ≡ y₀) (λ p → PathP (λ i → B (p i)) x₁ y₁))
→ isSphereFilledDep (suc n) A B
isSphereFilledDepAsc n {A = A} B hB f₀' f = f' , r
where
g₀' : (u : D n) → f₀' north ≡ f₀' south
g₀' u i = f₀' (merid u i)
g : (s : S n) → PathP (λ i → B (g₀' (S→D s) i)) (f north) (f south)
g s i = f (merid s i)
f' : (u : D (suc n)) → B (f₀' u)
f' north = f north
f' south = f south
f' (merid u i) = hB (f₀' north) (f₀' south) (f north) (f south) g₀' g .fst u i
r : (s : S (suc n)) → f s ≡ f' (S→D s)
r north = refl
r south = refl
r (merid s i) j = hB (f₀' north) (f₀' south) (f north) (f south) g₀' g .snd s j i
isOfHLevel→isSphereFilledDep : (n : ℕ) {A : Type ℓ} (B : A → Type ℓ₁)
→ ((a : A) → isOfHLevel n (B a)) → isSphereFilledDep n A B
isOfHLevel→isSphereFilledDep 0 B hB f₀' f = (λ u → hB (f₀' u)) , λ ()
isOfHLevel→isSphereFilledDep (suc n) {A = A} B hB =
isSphereFilledDepAsc n B
(λ x₀ y₀ x₁ y₁ →
isOfHLevel→isSphereFilledDep n {A = x₀ ≡ y₀} (λ p → PathP (λ i → B (p i)) x₁ y₁)
(λ p → J (λ y₀ p → (y₁ : B y₀) → isOfHLevel n (PathP (λ i → B (p i)) x₁ y₁)) (hB x₀ x₁) p y₁))
elim : {n : ℕ} {A : Type ℓ} {B : ∥ A ∥ n → Type ℓ₁}
(hB : (x : ∥ A ∥ n) → isOfHLevel n (B x))
(g : (a : A) → B (∣ a ∣)) (x : ∥ A ∥ n) → B x
elim {n = n} {A = A} {B = B} hB g = helper
where
h : isSphereFilledDep n (∥ A ∥ n) B
h = isOfHLevel→isSphereFilledDep n B hB
helper : (x : ∥ A ∥ n) → B x
helper ∣ a ∣ = g a
helper (hub f u) = h (hub f) (λ s → subst B (spoke f s) (helper (f s))) .fst u
helper (spoke f s i) =
hcomp
(λ j →
λ { (i = i0) → helper (f s)
; (i = i1) → h (hub f) (λ s → subst B (spoke f s) (helper (f s))) .snd s j })
(subst-filler B (spoke f s) (helper (f s)) i)
|
{
"alphanum_fraction": 0.5159337725,
"avg_line_length": 29.4083769634,
"ext": "agda",
"hexsha": "e8ca20eea09d309b512fbeec1746067175531fed",
"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": "3aa0425c12e2edeb284ab8588a2b25ea46ae4394",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "howsiyu/hott-notes",
"max_forks_repo_path": "Truncation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3aa0425c12e2edeb284ab8588a2b25ea46ae4394",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "howsiyu/hott-notes",
"max_issues_repo_path": "Truncation.agda",
"max_line_length": 109,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3aa0425c12e2edeb284ab8588a2b25ea46ae4394",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "howsiyu/hott-notes",
"max_stars_repo_path": "Truncation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2613,
"size": 5617
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
module Haskell.Modules.Either where
open import Data.Bool using (Bool; true; false; not)
import Data.Sum as DS renaming ([_,_] to either)
open import Function using (_∘_)
open import Level renaming (_⊔_ to _ℓ⊔_)
Either : ∀ {a b} → Set a → Set b → Set (a ℓ⊔ b)
Either A B = A DS.⊎ B
pattern Left x = DS.inj₁ x
pattern Right x = DS.inj₂ x
either = DS.either
isLeft : ∀ {a b} {A : Set a} {B : Set b} → Either A B → Bool
isLeft (Left _) = true
isLeft (Right _) = false
isRight : ∀ {a b} {A : Set a} {B : Set b} → Either A B → Bool
isRight = not ∘ isLeft
|
{
"alphanum_fraction": 0.6606060606,
"avg_line_length": 28.4482758621,
"ext": "agda",
"hexsha": "16f73c29b580475ecbf08f1e002d9e7ba103fced",
"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/Haskell/Modules/Either.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/Haskell/Modules/Either.agda",
"max_line_length": 111,
"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/Haskell/Modules/Either.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 272,
"size": 825
}
|
------------------------------------------------------------------------------
-- The Booleans properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Bool.PropertiesI where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Data.Bool
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesI
open import FOTC.Data.Nat.Type
------------------------------------------------------------------------------
-- Congruence properties
&&-leftCong : ∀ {a b c} → a ≡ b → a && c ≡ b && c
&&-leftCong refl = refl
&&-rightCong : ∀ {a b c} → b ≡ c → a && b ≡ a && c
&&-rightCong refl = refl
&&-cong : ∀ {a b c d } → a ≡ c → b ≡ d → a && b ≡ c && d
&&-cong refl refl = refl
notCong : ∀ {a b} → a ≡ b → not a ≡ not b
notCong refl = refl
------------------------------------------------------------------------------
-- Basic properties
t&&x≡x : ∀ b → true && b ≡ b
t&&x≡x b = if-true b
f&&x≡f : ∀ b → false && b ≡ false
f&&x≡f b = if-false false
not-t : not true ≡ false
not-t = if-true false
not-f : not false ≡ true
not-f = if-false true
&&-Bool : ∀ {a b} → Bool a → Bool b → Bool (a && b)
&&-Bool {b = b} btrue Bb = subst Bool (sym (t&&x≡x b)) Bb
&&-Bool {b = b} bfalse Bb = subst Bool (sym (f&&x≡f b)) bfalse
not-Bool : ∀ {b} → Bool b → Bool (not b)
not-Bool btrue = subst Bool (sym not-t) bfalse
not-Bool bfalse = subst Bool (sym not-f) btrue
&&-comm : ∀ {a b} → Bool a → Bool b → a && b ≡ b && a
&&-comm btrue btrue = refl
&&-comm btrue bfalse = trans (t&&x≡x false) (sym (f&&x≡f true))
&&-comm bfalse btrue = trans (f&&x≡f true) (sym (t&&x≡x false))
&&-comm bfalse bfalse = refl
&&-assoc : ∀ {a b c} → Bool a → Bool b → Bool c → (a && b) && c ≡ a && b && c
&&-assoc btrue btrue btrue = &&-cong (t&&x≡x true) (sym (t&&x≡x true))
&&-assoc btrue btrue bfalse = &&-cong (t&&x≡x true) (sym (t&&x≡x false))
&&-assoc btrue bfalse btrue =
(true && false) && true ≡⟨ &&-comm (&&-Bool btrue bfalse) btrue ⟩
true && (true && false) ≡⟨ t&&x≡x (true && false) ⟩
true && false ≡⟨ &&-rightCong (sym (f&&x≡f true)) ⟩
true && false && true ∎
&&-assoc btrue bfalse bfalse =
(true && false) && false ≡⟨ &&-comm (&&-Bool btrue bfalse) bfalse ⟩
false && (true && false) ≡⟨ f&&x≡f (true && false) ⟩
false ≡⟨ sym (f&&x≡f false) ⟩
false && false ≡⟨ sym (t&&x≡x (false && false)) ⟩
true && false && false ∎
&&-assoc bfalse btrue btrue = &&-cong (f&&x≡f true) (sym (t&&x≡x true))
&&-assoc bfalse btrue bfalse = &&-cong (f&&x≡f true) (sym (t&&x≡x false))
&&-assoc bfalse bfalse btrue =
(false && false) && true ≡⟨ &&-comm (&&-Bool bfalse bfalse) btrue ⟩
true && (false && false) ≡⟨ t&&x≡x (false && false) ⟩
false && false ≡⟨ f&&x≡f false ⟩
false ≡⟨ sym (f&&x≡f (false && true)) ⟩
false && false && true ∎
&&-assoc bfalse bfalse bfalse = &&-cong (f&&x≡f false) (sym (f&&x≡f false))
&&-list₂-t : ∀ {a b} → Bool a → Bool b → a && b ≡ true → a ≡ true ∧ b ≡ true
&&-list₂-t btrue btrue h = refl , refl
&&-list₂-t btrue bfalse h = ⊥-elim (t≢f (trans (sym h) (t&&x≡x false)))
&&-list₂-t bfalse btrue h = ⊥-elim (t≢f (trans (sym h) (f&&x≡f true)))
&&-list₂-t bfalse bfalse h = ⊥-elim (t≢f (trans (sym h) (f&&x≡f false)))
&&-list₂-t₁ : ∀ {a b} → Bool a → Bool b → a && b ≡ true → a ≡ true
&&-list₂-t₁ Ba Bb h = ∧-proj₁ (&&-list₂-t Ba Bb h)
&&-list₂-t₂ : ∀ {a b} → Bool a → Bool b → a && b ≡ true → b ≡ true
&&-list₂-t₂ Ba Bb h = ∧-proj₂ (&&-list₂-t Ba Bb h)
&&-list₂-all-t : ∀ {a b} → Bool a → Bool b →
(a ≡ true ∧ b ≡ true) →
a && b ≡ true
&&-list₂-all-t btrue btrue h = t&&x≡x true
&&-list₂-all-t btrue bfalse (h₁ , h₂) = ⊥-elim (t≢f (sym h₂))
&&-list₂-all-t bfalse Bb (h₁ , h₂) = ⊥-elim (t≢f (sym h₁))
&&-list₃-all-t : ∀ {a b c} → Bool a → Bool b → Bool c →
a ≡ true ∧ b ≡ true ∧ c ≡ true →
a && b && c ≡ true
&&-list₃-all-t btrue btrue btrue h = trans (t&&x≡x (true && true)) (t&&x≡x true)
&&-list₃-all-t btrue btrue bfalse (h₁ , h₂ , h₃) = ⊥-elim (t≢f (sym h₃))
&&-list₃-all-t btrue bfalse Bc (h₁ , h₂ , h₃) = ⊥-elim (t≢f (sym h₂))
&&-list₃-all-t bfalse Bb Bc (h₁ , h₂ , h₃) = ⊥-elim (t≢f (sym h₁))
&&-list₄-all-t : ∀ {a b c d} → Bool a → Bool b → Bool c → Bool d →
a ≡ true ∧ b ≡ true ∧ c ≡ true ∧ d ≡ true →
a && b && c && d ≡ true
&&-list₄-all-t btrue btrue btrue btrue h =
trans₂ (t&&x≡x (true && true && true)) (t&&x≡x (true && true)) (t&&x≡x true)
&&-list₄-all-t btrue btrue btrue bfalse (h₁ , h₂ , h₃ , h₄) = ⊥-elim (t≢f (sym h₄))
&&-list₄-all-t btrue btrue bfalse Bd (h₁ , h₂ , h₃ , h₄) = ⊥-elim (t≢f (sym h₃))
&&-list₄-all-t btrue bfalse Bc Bd (h₁ , h₂ , h₃ , h₄) = ⊥-elim (t≢f (sym h₂))
&&-list₄-all-t bfalse Bb Bc Bd (h₁ , h₂ , h₃ , h₄) = ⊥-elim (t≢f (sym h₁))
&&-list₄-some-f : ∀ {a b c d} → Bool a → Bool b → Bool c → Bool d →
a ≡ false ∨ b ≡ false ∨ c ≡ false ∨ d ≡ false →
a && b && c && d ≡ false
&&-list₄-some-f btrue Bb Bc Bd (inj₁ h) = ⊥-elim (t≢f h)
&&-list₄-some-f btrue btrue Bc Bd (inj₂ (inj₁ h)) = ⊥-elim (t≢f h)
&&-list₄-some-f btrue btrue btrue Bd (inj₂ (inj₂ (inj₁ h))) = ⊥-elim (t≢f h)
&&-list₄-some-f btrue btrue btrue btrue (inj₂ (inj₂ (inj₂ h))) = ⊥-elim (t≢f h)
&&-list₄-some-f btrue btrue btrue bfalse (inj₂ (inj₂ (inj₂ h))) =
trans (t&&x≡x (true && true && false))
(trans (t&&x≡x (true && false)) (t&&x≡x false))
&&-list₄-some-f btrue btrue bfalse btrue (inj₂ (inj₂ (inj₁ h))) =
trans (t&&x≡x (true && false && true))
(trans (t&&x≡x (false && true)) (f&&x≡f true))
&&-list₄-some-f btrue btrue bfalse btrue (inj₂ (inj₂ (inj₂ h))) = ⊥-elim (t≢f h)
&&-list₄-some-f btrue btrue bfalse bfalse (inj₂ (inj₂ h)) =
trans (t&&x≡x (true && false && false))
(trans (t&&x≡x (false && false)) (f&&x≡f false))
&&-list₄-some-f {c = c} {d} btrue bfalse Bc Bd (inj₂ h) =
trans (t&&x≡x (false && c && d)) (f&&x≡f (c && d))
&&-list₄-some-f {b = b} {c} {d} bfalse Bb Bc Bd _ = f&&x≡f (b && c && d)
&&-list₄-t : ∀ {a b c d} → Bool a → Bool b → Bool c → Bool d →
a && b && c && d ≡ true →
a ≡ true ∧ b ≡ true ∧ c ≡ true ∧ d ≡ true
&&-list₄-t btrue btrue btrue btrue h = refl , refl , refl , refl
&&-list₄-t btrue btrue btrue bfalse h =
⊥-elim (t≢f
(trans (sym h)
(&&-list₄-some-f btrue btrue btrue bfalse (inj₂ (inj₂ (inj₂ refl))))))
&&-list₄-t btrue btrue bfalse Bd h =
⊥-elim (t≢f
(trans (sym h)
(&&-list₄-some-f btrue btrue bfalse Bd (inj₂ (inj₂ (inj₁ refl))))))
&&-list₄-t btrue bfalse Bc Bd h =
⊥-elim (t≢f
(trans (sym h) (&&-list₄-some-f btrue bfalse Bc Bd (inj₂ (inj₁ refl)))))
&&-list₄-t bfalse Bb Bc Bd h =
⊥-elim (t≢f (trans (sym h) (&&-list₄-some-f bfalse Bb Bc Bd (inj₁ refl))))
&&-list₄-t₁ : ∀ {a b c d} → Bool a → Bool b → Bool c → Bool d →
a && b && c && d ≡ true → a ≡ true
&&-list₄-t₁ Ba Bb Bc Bd h = ∧-proj₁ (&&-list₄-t Ba Bb Bc Bd h)
&&-list₄-t₂ : ∀ {a b c d} → Bool a → Bool b → Bool c → Bool d →
a && b && c && d ≡ true → b ≡ true
&&-list₄-t₂ Ba Bb Bc Bd h = ∧-proj₁ (∧-proj₂ (&&-list₄-t Ba Bb Bc Bd h))
&&-list₄-t₃ : ∀ {a b c d} → Bool a → Bool b → Bool c → Bool d →
a && b && c && d ≡ true → c ≡ true
&&-list₄-t₃ Ba Bb Bc Bd h =
∧-proj₁ (∧-proj₂ (∧-proj₂ (&&-list₄-t Ba Bb Bc Bd h)))
&&-list₄-t₄ : ∀ {a b c d} → Bool a → Bool b → Bool c → Bool d →
a && b && c && d ≡ true → d ≡ true
&&-list₄-t₄ Ba Bb Bc Bd h =
∧-proj₂ (∧-proj₂ (∧-proj₂ (&&-list₄-t Ba Bb Bc Bd h)))
x≢not-x : ∀ {b} → Bool b → b ≢ not b
x≢not-x btrue h = t≢f (trans h not-t)
x≢not-x bfalse h = t≢f (sym (trans h not-f))
not-x≢x : ∀ {b} → Bool b → not b ≢ b
not-x≢x Bb h = x≢not-x Bb (sym h)
not-involutive : ∀ {b} → Bool b → not (not b) ≡ b
not-involutive btrue = trans (notCong not-t) not-f
not-involutive bfalse = trans (notCong not-f) not-t
------------------------------------------------------------------------------
-- Properties with inequalities
lt-Bool : ∀ {m n} → N m → N n → Bool (lt m n)
lt-Bool nzero nzero = subst Bool (sym lt-00) bfalse
lt-Bool nzero (nsucc {n} Nn) = subst Bool (sym (lt-0S n)) btrue
lt-Bool (nsucc {m} Nm) nzero = subst Bool (sym (lt-S0 m)) bfalse
lt-Bool (nsucc {m} Nm) (nsucc {n} Nn) = subst Bool (sym (lt-SS m n)) (lt-Bool Nm Nn)
le-Bool : ∀ {m n} → N m → N n → Bool (le m n)
le-Bool {n = n} nzero Nn = subst Bool (sym (lt-0S n)) btrue
le-Bool (nsucc Nm) nzero = subst Bool (sym (Sx≰0 Nm)) bfalse
le-Bool (nsucc {m} Nm) (nsucc {n} Nn) =
subst Bool (sym (lt-SS m (succ₁ n))) (le-Bool Nm Nn)
|
{
"alphanum_fraction": 0.5009474975,
"avg_line_length": 43.3381642512,
"ext": "agda",
"hexsha": "d85ede5d61bd67b2cea493dcfd0b119da9a8cd8f",
"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/Bool/PropertiesI.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/Bool/PropertiesI.agda",
"max_line_length": 88,
"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/Bool/PropertiesI.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": 3739,
"size": 8971
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Concepts from rewriting theory
-- Definitions are based on "Term Rewriting Systems" by J.W. Klop
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Rewriting where
open import Agda.Builtin.Equality using (_≡_ ; refl)
open import Data.Product using (_×_ ; ∃ ; -,_; _,_ ; proj₁ ; proj₂)
open import Data.Empty
open import Data.Sum.Base as Sum using (_⊎_)
open import Function using (flip)
open import Induction.WellFounded
open import Level
open import Relation.Binary.Core
open import Relation.Binary.Construct.Closure.Equivalence using (EqClosure)
open import Relation.Binary.Construct.Closure.Equivalence.Properties
open import Relation.Binary.Construct.Closure.Reflexive
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
open import Relation.Binary.Construct.Closure.Symmetric
open import Relation.Binary.Construct.Closure.Transitive
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
-- The following definitions are taken from Klop [5]
module _ {a ℓ} {A : Set a} (_⟶_ : Rel A ℓ) where
private
_⟵_ = flip _⟶_
_—↠_ = Star _⟶_
_↔_ = EqClosure _⟶_
IsNormalForm : A → Set _
IsNormalForm a = ¬ ∃ λ b → (a ⟶ b)
HasNormalForm : A → Set _
HasNormalForm b = ∃ λ a → IsNormalForm a × (b —↠ a)
NormalForm : Set _
NormalForm = ∀ {a b} → IsNormalForm a → b ↔ a → b —↠ a
WeaklyNormalizing : Set _
WeaklyNormalizing = ∀ a → HasNormalForm a
StronglyNormalizing : Set _
StronglyNormalizing = WellFounded _⟵_
UniqueNormalForm : Set _
UniqueNormalForm = ∀ {a b} → IsNormalForm a → IsNormalForm b → a ↔ b → a ≡ b
Confluent : Set _
Confluent = ∀ {A B C} → A —↠ B → A —↠ C → ∃ λ D → (B —↠ D) × (C —↠ D)
WeaklyConfluent : Set _
WeaklyConfluent = ∀ {A B C} → A ⟶ B → A ⟶ C → ∃ λ D → (B —↠ D) × (C —↠ D)
Deterministic : ∀ {a b ℓ₁ ℓ₂} → {A : Set a} → {B : Set b} → Rel B ℓ₁ → REL A B ℓ₂ → Set _
Deterministic _≈_ _—→_ = ∀ {x y z} → x —→ y → x —→ z → y ≈ z
module _ {a ℓ} {A : Set a} {_⟶_ : Rel A ℓ} where
private
_—↠_ = Star _⟶_
_↔_ = EqClosure _⟶_
_⟶₊_ = Plus _⟶_
det⇒conf : Deterministic _≡_ _⟶_ → Confluent _⟶_
det⇒conf det ε rs₂ = -, rs₂ , ε
det⇒conf det rs₁ ε = -, ε , rs₁
det⇒conf det (r₁ ◅ rs₁) (r₂ ◅ rs₂)
rewrite det r₁ r₂ = det⇒conf det rs₁ rs₂
conf⇒wcr : Confluent _⟶_ → WeaklyConfluent _⟶_
conf⇒wcr c fst snd = c (fst ◅ ε) (snd ◅ ε)
conf⇒nf : Confluent _⟶_ → NormalForm _⟶_
conf⇒nf c aIsNF ε = ε
conf⇒nf c aIsNF (fwd x ◅ rest) = x ◅ conf⇒nf c aIsNF rest
conf⇒nf c aIsNF (bwd y ◅ rest) with c (y ◅ ε) (conf⇒nf c aIsNF rest)
... | _ , _ , x ◅ _ = ⊥-elim (aIsNF (_ , x))
... | _ , left , ε = left
conf⇒unf : Confluent _⟶_ → UniqueNormalForm _⟶_
conf⇒unf _ _ _ ε = refl
conf⇒unf _ aIsNF _ (fwd x ◅ _) = ⊥-elim (aIsNF (_ , x))
conf⇒unf c aIsNF bIsNF (bwd y ◅ r) with c (y ◅ ε) (conf⇒nf c bIsNF r)
... | _ , ε , x ◅ _ = ⊥-elim (bIsNF (_ , x))
... | _ , x ◅ _ , _ = ⊥-elim (aIsNF (_ , x))
... | _ , ε , ε = refl
un&wn⇒cr : UniqueNormalForm _⟶_ → WeaklyNormalizing _⟶_ → Confluent _⟶_
un&wn⇒cr un wn {a} {b} {c} aToB aToC with wn b | wn c
... | (d , (d-nf , bToD)) | (e , (e-nf , cToE))
with un d-nf e-nf (a—↠b&a—↠c⇒b↔c (aToB ◅◅ bToD) (aToC ◅◅ cToE))
... | refl = d , bToD , cToE
-- Newman's lemma
sn&wcr⇒cr : StronglyNormalizing _⟶₊_ → WeaklyConfluent _⟶_ → Confluent _⟶_
sn&wcr⇒cr sn wcr = helper (sn _) where
starToPlus : ∀ {a b c} → (a ⟶ b) → b —↠ c → a ⟶₊ c
starToPlus aToB ε = [ aToB ]
starToPlus {a} aToB (e ◅ bToC) = a ∼⁺⟨ [ aToB ] ⟩ (starToPlus e bToC)
helper : ∀ {a b c} → (acc : Acc (flip _⟶₊_) a) →
a —↠ b → a —↠ c → ∃ λ d → (b —↠ d) × (c —↠ d)
helper _ ε snd = -, snd , ε
helper _ fst ε = -, ε , fst
helper (acc g) (toJ ◅ fst) (toK ◅ snd) = result where
wcrProof = wcr toJ toK
innerPoint = proj₁ wcrProof
jToInner = proj₁ (proj₂ wcrProof)
kToInner = proj₂ (proj₂ wcrProof)
lhs = helper (g _ [ toJ ]) fst jToInner
rhs = helper (g _ [ toK ]) snd kToInner
fromAB = proj₁ (proj₂ lhs)
fromInnerB = proj₂ (proj₂ lhs)
fromAC = proj₁ (proj₂ rhs)
fromInnerC = proj₂ (proj₂ rhs)
aToInner : _ ⟶₊ innerPoint
aToInner = starToPlus toJ jToInner
finalRecursion = helper (g innerPoint aToInner) fromInnerB fromInnerC
bMidToDest = proj₁ (proj₂ finalRecursion)
cMidToDest = proj₂ (proj₂ finalRecursion)
result : ∃ λ d → (_ —↠ d) × (_ —↠ d)
result = _ , fromAB ◅◅ bMidToDest , fromAC ◅◅ cMidToDest
|
{
"alphanum_fraction": 0.5680789798,
"avg_line_length": 34.7285714286,
"ext": "agda",
"hexsha": "2a3c59d0050bfa32921892c6a36cd6195e26ed0a",
"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/Relation/Binary/Rewriting.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/Relation/Binary/Rewriting.agda",
"max_line_length": 89,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Relation/Binary/Rewriting.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": 1868,
"size": 4862
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Semirings.Definition
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Integers.RingStructure.Ring
open import Groups.Orders.Archimedean
open import Rings.Orders.Partial.Definition
open import Numbers.Integers.Order
module Numbers.Integers.RingStructure.Archimedean where
open import Groups.Cyclic.Definition ℤGroup
open import Semirings.Solver ℕSemiring multiplicationNIsCommutative
private
lemma : (x y : ℕ) → positiveEltPower (nonneg x) y ≡ nonneg (x *N y)
lemma x zero rewrite Semiring.productZeroRight ℕSemiring x = refl
lemma x (succ y) rewrite lemma x y | multiplicationNIsCommutative x (succ y) | multiplicationNIsCommutative y x = equalityCommutative (+Zinherits x (x *N y))
ℤArchimedean : Archimedean (toGroup ℤRing ℤPOrderedRing)
ℤArchimedean (nonneg (succ a)) (nonneg (succ b)) 0<a 0<b = succ (succ b) , t
where
v : b +N (a +N (a +N a *N b)) ≡ a +N (a +N (b +N a *N b))
v rewrite Semiring.+Associative ℕSemiring a a (a *N b) | Semiring.+Associative ℕSemiring b (a +N a) (a *N b) | Semiring.+Associative ℕSemiring a b (a *N b) | Semiring.+Associative ℕSemiring a (a +N b) (a *N b) | Semiring.commutative ℕSemiring b (a +N a) | Semiring.+Associative ℕSemiring a a b = refl
u : succ ((a +N (a +N a *N b)) +N b) ≡ a +N succ (a +N (b +N a *N b))
u = from (succ (plus (plus (const a) (plus (const a) (times (const a) (const b)))) (const b))) to (plus (const a) (succ (plus (const a) (plus (const b) (times (const a) (const b)))))) by applyEquality succ v
t : nonneg (succ b) <Z nonneg (succ a) +Z (nonneg (succ a) +Z positiveEltPower (nonneg (succ a)) b)
t rewrite lemma (succ a) b = lessInherits (succPreservesInequality (le (a +N (a +N a *N b)) u))
|
{
"alphanum_fraction": 0.7007658643,
"avg_line_length": 58.9677419355,
"ext": "agda",
"hexsha": "dd6ec5e4f34cf52ad8107e3fab63a17b43be0951",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Numbers/Integers/RingStructure/Archimedean.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Numbers/Integers/RingStructure/Archimedean.agda",
"max_line_length": 304,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Numbers/Integers/RingStructure/Archimedean.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 614,
"size": 1828
}
|
------------------------------------------------------------------------
-- Subject reduction for typing in Fω with interval kinds
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
-- This module proves a variant of subject reduction (aka the
-- "preservation" theorem) for term reduction in Fω with interval
-- kinds. The subject reduction property proved here is weaker than
-- the one typically found in the literature on other variants of Fω:
-- subject reduction does not hold in arbitrary typing contexts in Fω
-- with interval types because type variables of interval kind can be
-- used to introduce arbitrary typing (in)equalities into the
-- subtyping relation. In other words, subject reduction does not
-- hold for full β-reduction as reductions under type abstractions are
-- not safe in general. Note, however, that subject reduction does
-- hold for arbitrary β-reductions in *types* (see `pres-Tp∈-→β*' in
-- the Kinding.Declarative.Validity module for a proof).
--
-- NOTE. Here we use the CBV evaluation strategy, but this is
-- unnecessarily restrictive. Other evaluation strategies work so
-- long as they do not allow reductions under type abstractions.
--
-- Together with the "progress" theorem from Typing.Progress, subject
-- reduction ensures type safety. For details, see e.g.
--
-- * B. C. Pierce, TAPL (2002), pp. 95.
--
-- * A. Wright and M. Felleisen, "A Syntactic Approach to Type
-- Soundness" (1994).
module FOmegaInt.Typing.Preservation where
open import Data.Product using (_,_)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive using (ε; _◅_)
open import Relation.Binary.PropositionalEquality using (subst)
open import Relation.Nullary.Negation using (contradiction)
open import FOmegaInt.Syntax
open import FOmegaInt.Typing
open import FOmegaInt.Typing.Inversion
open import FOmegaInt.Reduction.Cbv
open import FOmegaInt.Reduction.Full
open Syntax
open TermCtx
open Substitution using (_[_]; weaken-sub)
open Typing
open TypedSubstitution using (Tm∈-[]; <:-[])
-- Types of closed terms are preserved under single-step reduction.
pres : ∀ {a b c} → [] ⊢Tm a ∈ c → a →v b → [] ⊢Tm b ∈ c
pres (∈-var () _ _)
pres (∈-∀-i k-kd a∈b) ()
pres (∈-→-i a∈* b∈c c∈*) ()
pres (∈-∀-e Λja∈Πkc b∈k) (cont-⊡ j a b) with Tm∈-gen Λja∈Πkc
... | ∈-∀-i j-kd a∈d Πjd<:Πkc =
let k<∷j , d<:c = <:-∀-inv Πjd<:Πkc
in ∈-⇑ (Tm∈-[] a∈d (∈-tp (∈-⇑ b∈k k<∷j))) (<:-[] d<:c (∈-tp b∈k))
pres (∈-∀-e a∈Πcd b∈c) (a→e ⊡ b) = ∈-∀-e (pres a∈Πcd a→e) b∈c
pres (∈-→-e ƛea∈c⇒d v∈c) (cont-· e a v) with Tm∈-gen ƛea∈c⇒d
... | ∈-→-i e∈* a∈f e⇒f<:c⇒d =
let c<:e , f<:d = <:-→-inv e⇒f<:c⇒d
in ∈-⇑ (subst (_ ⊢Tm _ ∈_) (weaken-sub _) (Tm∈-[] a∈f (∈-tm (∈-⇑ v∈c c<:e))))
f<:d
pres (∈-→-e a∈c⇒d b∈c) (a→e ·₁ b) = ∈-→-e (pres a∈c⇒d a→e) b∈c
pres (∈-→-e a∈c⇒d b∈c) (v ·₂ b→e) = ∈-→-e a∈c⇒d (pres b∈c b→e)
pres (∈-⇑ a∈c c<:d) a→b = ∈-⇑ (pres a∈c a→b) c<:d
-- Weak preservation (aka subject reduction): types of closed terms
-- are preserved under reduction.
pres* : ∀ {a b c} → [] ⊢Tm a ∈ c → a →v* b → [] ⊢Tm b ∈ c
pres* a∈c ε = a∈c
pres* a∈d (a→b ◅ b→*c) = pres* (pres a∈d a→b) b→*c
|
{
"alphanum_fraction": 0.6186467103,
"avg_line_length": 42.76,
"ext": "agda",
"hexsha": "1ee3b8b2ba48ca67657aff6c9e0a0d1e01bf8bf9",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-05-14T10:25:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-05-13T22:29:48.000Z",
"max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/FOmegaInt/Typing/Preservation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T08:54:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-05-14T08:09:40.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/FOmegaInt/Typing/Preservation.agda",
"max_line_length": 80,
"max_stars_count": 12,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/FOmegaInt/Typing/Preservation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-27T05:53:06.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-06-13T16:05:35.000Z",
"num_tokens": 1199,
"size": 3207
}
|
module Unsolved-meta-in-module-telescope (A : _) where
|
{
"alphanum_fraction": 0.7636363636,
"avg_line_length": 27.5,
"ext": "agda",
"hexsha": "6c21eda98555ca23a9df03c25a716c7f54fd87fe",
"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/Unsolved-meta-in-module-telescope.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/Unsolved-meta-in-module-telescope.agda",
"max_line_length": 54,
"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/Unsolved-meta-in-module-telescope.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": 14,
"size": 55
}
|
module Categories.Category.Construction.CartesianClosedFunctors where
open import Categories.Category
open import Categories.Category.CartesianClosed.Bundle
open import Categories.Functor.CartesianClosed
open import Categories.NaturalTransformation using (NaturalTransformation; id; _∘ᵥ_)
import Categories.NaturalTransformation.Equivalence as NTEq
open import Categories.NaturalTransformation.NaturalIsomorphism
import Categories.NaturalTransformation.NaturalIsomorphism.Equivalence as Eq
open import Data.Product using (_,_)
open import Level
private
variable o ℓ e o′ ℓ′ e′ : Level
CCCat≅ : (C : CartesianClosedCategory o ℓ e)
-> (D : CartesianClosedCategory o′ ℓ′ e′)
-> Category (levelOfTerm C ⊔ levelOfTerm D) (o ⊔ ℓ ⊔ ℓ′ ⊔ e′) (o ⊔ e′)
CCCat≅ C D = record
{ Obj = CartesianClosedF C D
; _⇒_ = λ F G → NaturalIsomorphism (CartesianClosedF.F F) (CartesianClosedF.F G)
; _≈_ = Eq._≅_
; id = refl
; _∘_ = _ⓘᵥ_
; assoc = assoc , sym-assoc
; sym-assoc = sym-assoc , assoc
; identityˡ = identityˡ , identityʳ
; identityʳ = identityʳ , identityˡ
; identity² = identity² , identity²
; equiv = Eq.≅-isEquivalence
; ∘-resp-≈ = λ (f≅h , f≅h′) (g≅i , g≅i′) → ∘-resp-≈ f≅h g≅i , ∘-resp-≈ g≅i′ f≅h′
}
where
open Category (CartesianClosedCategory.U D)
|
{
"alphanum_fraction": 0.6357388316,
"avg_line_length": 39.3243243243,
"ext": "agda",
"hexsha": "c6ac3b1254154180c17ea4775b8df4adbb8a78ff",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "elpinal/exsub-ccc",
"max_forks_repo_path": "Categories/Category/Construction/CartesianClosedFunctors.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "elpinal/exsub-ccc",
"max_issues_repo_path": "Categories/Category/Construction/CartesianClosedFunctors.agda",
"max_line_length": 95,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "elpinal/exsub-ccc",
"max_stars_repo_path": "Categories/Category/Construction/CartesianClosedFunctors.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T13:30:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-05T06:16:32.000Z",
"num_tokens": 440,
"size": 1455
}
|
module #4 where
open import Relation.Binary.PropositionalEquality
open import Data.Product
open import Data.Nat
{-
Exercise 2.4. Define, by induction on n, a general notion of n-dimensional path in a
type A, simultaneously with the type of boundaries for such paths.
-}
-- We need pointed sets for this part
Set• : ∀ i → Set _
Set• i = Σ (Set i) λ X → X
Ω₁ : ∀ {i} → Set• i → Set• i
Ω₁ (X , x) = ((x ≡ x) , refl)
Ωⁿ : ∀ {i} → ℕ → Set• i → Set• _
Ωⁿ 0 x = x
Ωⁿ (suc n) x = Ωⁿ n (Ω₁ x)
|
{
"alphanum_fraction": 0.6336032389,
"avg_line_length": 22.4545454545,
"ext": "agda",
"hexsha": "5269c19790ef64c337477691ad2cfa2f59901444",
"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": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CodaFi/HoTT-Exercises",
"max_forks_repo_path": "Chapter2/#4.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"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": "CodaFi/HoTT-Exercises",
"max_issues_repo_path": "Chapter2/#4.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CodaFi/HoTT-Exercises",
"max_stars_repo_path": "Chapter2/#4.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 185,
"size": 494
}
|
module Function.Iteration where
open import Data
open import Functional
open import Numeral.Natural
open import Type
open import Syntax.Number
module _ {ℓ} {T : Type{ℓ}} where
-- Repeated function composition
-- Example:
-- f ^ 0 = id
-- f ^ 1 = f
-- f ^ 2 = f ∘ f
-- f ^ 3 = f ∘ f ∘ f
-- f ^ 4 = f ∘ f ∘ f ∘ f
_^_ : (T → T) → ℕ → (T → T)
_^_ f 𝟎 = id
_^_ f (𝐒(n)) = f ∘ (f ^ n)
_⁰ : (T → T) → (T → T)
_⁰ = _^ 0
_¹ : (T → T) → (T → T)
_¹ = _^ 1
_² : (T → T) → (T → T)
_² = _^ 2
_³ : (T → T) → (T → T)
_³ = _^ 3
_⁴ : (T → T) → (T → T)
_⁴ = _^ 4
_⁵ : (T → T) → (T → T)
_⁵ = _^ 5
_⁶ : (T → T) → (T → T)
_⁶ = _^ 6
_⁷ : (T → T) → (T → T)
_⁷ = _^ 7
_⁸ : (T → T) → (T → T)
_⁸ = _^ 8
_⁹ : (T → T) → (T → T)
_⁹ = _^ 9
module _ {ℓ₁}{ℓ₂} {X : Type{ℓ₁}} {Y : Type{ℓ₂}} where
-- Repeat a binary operation n times for the same element and an initial element
-- Example: repeatₗ 3 id (_∘_) f = ((id ∘ f) ∘ f) ∘ f
-- Example in Haskell: (foldl (.) (id) (take 5 (repeat f)))
-- Implementation in Haskell: (\n null op elem -> foldl op null (take n (repeat elem))) :: Int -> a -> (b -> a -> b) -> b -> b
repeatₗ : ℕ → (Y → X → Y) → (Y → X → Y)
repeatₗ n (_▫_) null elem = ((_▫ elem) ^ n) (null)
-- Repeat a binary operation n times for the same element and an initial element
-- Example: repeatᵣ 3 id (_∘_) f = f ∘ (f ∘ (f ∘ id))
-- Implementation in Haskell: (\n elem op null -> foldr op null (take n (repeat elem))) :: Int -> a -> (a -> b -> b) -> b -> b
repeatᵣ : ℕ → (X → Y → Y) → (X → Y → Y)
repeatᵣ n (_▫_) elem = (elem ▫_) ^ n
module _ {ℓ} {X : Type{ℓ}} where
-- Repeat a binary operation n times for the same element and using the default element on zero.
-- Examples:
-- repeatₗ 0 def (_∘_) f = def
-- repeatₗ 1 def (_∘_) f = f
-- repeatₗ 4 def (_∘_) f = ((f ∘ f) ∘ f) ∘ f
repeatₗ-default : ℕ → (X → X → X) → X → (X → X)
repeatₗ-default 𝟎 _ def _ = def
repeatₗ-default (𝐒(n)) (_▫_) _ elem = repeatₗ(n) (_▫_) elem elem
-- Repeat a binary operation n times for the same element and using the default element on zero.
-- Examples:
-- repeatᵣ 0 f (_∘_) def = def
-- repeatᵣ 1 f (_∘_) def = f
-- repeatᵣ 4 f (_∘_) def = f ∘ (f ∘ (f ∘ f))
repeatᵣ-default : ℕ → (X → X → X) → X → (X → X)
repeatᵣ-default 𝟎 _ _ def = def
repeatᵣ-default (𝐒(n)) (_▫_) elem _ = repeatᵣ(n) (_▫_) elem elem
|
{
"alphanum_fraction": 0.5018329939,
"avg_line_length": 29.578313253,
"ext": "agda",
"hexsha": "851cfd054fb8bcbe96db1c338bd41835c36984e6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Function/Iteration.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Function/Iteration.agda",
"max_line_length": 128,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Function/Iteration.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": 1086,
"size": 2455
}
|
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Properties.Conversion {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.RedSteps
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Tools.Embedding
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Conversion of syntactic reduction closures.
convRed:*: : ∀ {t u A B Γ} → Γ ⊢ t :⇒*: u ∷ A → Γ ⊢ A ≡ B → Γ ⊢ t :⇒*: u ∷ B
convRed:*: [ ⊢t , ⊢u , d ] A≡B = [ conv ⊢t A≡B , conv ⊢u A≡B , conv* d A≡B ]
mutual
-- Helper function for conversion of terms converting from left to right.
convTermT₁ : ∀ {l l′ Γ A B t} {[A] : Γ ⊩⟨ l ⟩ A} {[B] : Γ ⊩⟨ l′ ⟩ B}
→ ShapeView Γ l l′ A B [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l ⟩ t ∷ A / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B / [B]
convTermT₁ (ℕᵥ D D′) A≡B (ιx (ℕₜ n d n≡n prop)) = ιx (ℕₜ n d n≡n prop)
convTermT₁ (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ιx (ne₌ M D′ neM K≡M))
(ιx (neₜ k d (neNfₜ neK₂ ⊢k k≡k))) =
let K≡K₁ = PE.subst (λ x → _ ⊢ _ ≡ x)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(≅-eq (~-to-≅ K≡M))
in ιx (neₜ k (convRed:*: d K≡K₁)
(neNfₜ neK₂ (conv ⊢k K≡K₁) (~-conv k≡k K≡K₁)))
convTermT₁ {Γ = Γ} (Πᵥ (Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ f d funcF f≡f [f] [f]₁) =
let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
F₁≡F′ , G₁≡G′ = Π-PE-injectivity ΠF₁G₁≡ΠF′G′
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ▹ G ≡ x) (PE.sym ΠF₁G₁≡ΠF′G′)
(≅-eq A≡B)
in Πₜ f (convRed:*: d ΠFG≡ΠF₁G₁) funcF (≅-conv f≡f ΠFG≡ΠF₁G₁)
(λ {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₂ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[b]₁ = convTerm₂ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [b]
[a≡b]₁ = convEqTerm₂ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a≡b]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a]₁)
([G≡G′] [ρ] ⊢Δ [a]₁)
in convEqTerm₁ ([G] [ρ] ⊢Δ [a]₁) ([G]₁ [ρ] ⊢Δ [a]) [G≡G₁]
([f] [ρ] ⊢Δ [a]₁ [b]₁ [a≡b]₁))
(λ {ρ} [ρ] ⊢Δ [a] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₂ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a]₁)
([G≡G′] [ρ] ⊢Δ [a]₁)
in convTerm₁ ([G] [ρ] ⊢Δ [a]₁) ([G]₁ [ρ] ⊢Δ [a]) [G≡G₁] ([f]₁ [ρ] ⊢Δ [a]₁))
convTermT₁ (Uᵥ .⁰ 0<1 ⊢Γ .⁰ 0<1 ⊢Γ₁) A≡B t = t
convTermT₁ (emb⁰¹ PE.refl x) (ιx A≡B) (ιx t) = convTermT₁ x A≡B t
convTermT₁ (emb¹⁰ PE.refl x) A≡B t = ιx (convTermT₁ x A≡B t)
-- Helper function for conversion of terms converting from right to left.
convTermT₂ : ∀ {l l′ Γ A B t} {[A] : Γ ⊩⟨ l ⟩ A} {[B] : Γ ⊩⟨ l′ ⟩ B}
→ ShapeView Γ l l′ A B [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B / [B]
→ Γ ⊩⟨ l ⟩ t ∷ A / [A]
convTermT₂ (ℕᵥ D D′) A≡B (ιx (ℕₜ n d n≡n prop)) = ιx (ℕₜ n d n≡n prop)
convTermT₂ (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ιx (ne₌ M D′ neM K≡M))
(ιx (neₜ k d (neNfₜ neK₂ ⊢k k≡k))) =
let K₁≡K = PE.subst (λ x → _ ⊢ x ≡ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(sym (≅-eq (~-to-≅ K≡M)))
in ιx (neₜ k (convRed:*: d K₁≡K)
(neNfₜ neK₂ (conv ⊢k K₁≡K) (~-conv k≡k K₁≡K)))
convTermT₂ {Γ = Γ} (Πᵥ (Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ f d funcF f≡f [f] [f]₁) =
let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
F₁≡F′ , G₁≡G′ = Π-PE-injectivity ΠF₁G₁≡ΠF′G′
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ▹ G ≡ x)
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in Πₜ f (convRed:*: d (sym ΠFG≡ΠF₁G₁)) funcF (≅-conv f≡f (sym ΠFG≡ΠF₁G₁))
(λ {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₁ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[b]₁ = convTerm₁ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [b]
[a≡b]₁ = convEqTerm₁ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a≡b]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a])
([G≡G′] [ρ] ⊢Δ [a])
in convEqTerm₂ ([G] [ρ] ⊢Δ [a]) ([G]₁ [ρ] ⊢Δ [a]₁)
[G≡G₁] ([f] [ρ] ⊢Δ [a]₁ [b]₁ [a≡b]₁))
(λ {ρ} [ρ] ⊢Δ [a] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₁ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a])
([G≡G′] [ρ] ⊢Δ [a])
in convTerm₂ ([G] [ρ] ⊢Δ [a]) ([G]₁ [ρ] ⊢Δ [a]₁)
[G≡G₁] ([f]₁ [ρ] ⊢Δ [a]₁))
convTermT₂ (Uᵥ .⁰ 0<1 ⊢Γ .⁰ 0<1 ⊢Γ₁) A≡B t = t
convTermT₂ (emb⁰¹ PE.refl x) (ιx A≡B) t = ιx (convTermT₂ x A≡B t)
convTermT₂ (emb¹⁰ PE.refl x) A≡B (ιx t) = convTermT₂ x A≡B t
-- Conversion of terms converting from left to right.
convTerm₁ : ∀ {Γ A B t l l′} ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l ⟩ t ∷ A / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B / [B]
convTerm₁ [A] [B] A≡B t = convTermT₁ (goodCases [A] [B] A≡B) A≡B t
-- Conversion of terms converting from right to left.
convTerm₂ : ∀ {Γ A B t l l′} ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B / [B]
→ Γ ⊩⟨ l ⟩ t ∷ A / [A]
convTerm₂ [A] [B] A≡B t = convTermT₂ (goodCases [A] [B] A≡B) A≡B t
-- Conversion of terms converting from right to left
-- with some propsitionally equal types.
convTerm₂′ : ∀ {Γ A B B′ t l l′} → B PE.≡ B′
→ ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B′ / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B / [B]
→ Γ ⊩⟨ l ⟩ t ∷ A / [A]
convTerm₂′ PE.refl [A] [B] A≡B t = convTerm₂ [A] [B] A≡B t
-- Helper function for conversion of term equality converting from left to right.
convEqTermT₁ : ∀ {l l′ Γ A B t u} {[A] : Γ ⊩⟨ l ⟩ A} {[B] : Γ ⊩⟨ l′ ⟩ B}
→ ShapeView Γ l l′ A B [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B / [B]
convEqTermT₁ (ℕᵥ D D′) A≡B (ιx (ℕₜ₌ k k′ d d′ k≡k′ prop)) = ιx (ℕₜ₌ k k′ d d′ k≡k′ prop)
convEqTermT₁ (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ιx (ne₌ M D′ neM K≡M))
(ιx (neₜ₌ k m d d′ (neNfₜ₌ neK₂ neM₁ k≡m))) =
let K≡K₁ = PE.subst (λ x → _ ⊢ _ ≡ x)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(≅-eq (~-to-≅ K≡M))
in ιx (neₜ₌ k m (convRed:*: d K≡K₁)
(convRed:*: d′ K≡K₁)
(neNfₜ₌ neK₂ neM₁ (~-conv k≡m K≡K₁)))
convEqTermT₁ {Γ = Γ} (Πᵥ (Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ₌ f g d d′ funcF funcG t≡u [t] [u] [t≡u]) =
let [A] = Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext
[B] = Πᵣ′ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁
[A≡B] = Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]
ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ▹ G ≡ x)
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in Πₜ₌ f g (convRed:*: d ΠFG≡ΠF₁G₁) (convRed:*: d′ ΠFG≡ΠF₁G₁)
funcF funcG (≅-conv t≡u ΠFG≡ΠF₁G₁)
(convTerm₁ [A] [B] [A≡B] [t]) (convTerm₁ [A] [B] [A≡B] [u])
(λ {ρ} [ρ] ⊢Δ [a] →
let F₁≡F′ , G₁≡G′ = Π-PE-injectivity (whrDet* (red D₁ , Πₙ) (D′ , Πₙ))
[F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₂ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a]₁)
([G≡G′] [ρ] ⊢Δ [a]₁)
in convEqTerm₁ ([G] [ρ] ⊢Δ [a]₁) ([G]₁ [ρ] ⊢Δ [a])
[G≡G₁] ([t≡u] [ρ] ⊢Δ [a]₁))
convEqTermT₁ (Uᵥ .⁰ 0<1 ⊢Γ .⁰ 0<1 ⊢Γ₁) A≡B t≡u = t≡u
convEqTermT₁ (emb⁰¹ PE.refl x) (ιx A≡B) (ιx t≡u) = convEqTermT₁ x A≡B t≡u
convEqTermT₁ (emb¹⁰ PE.refl x) A≡B t≡u = ιx (convEqTermT₁ x A≡B t≡u)
-- Helper function for conversion of term equality converting from right to left.
convEqTermT₂ : ∀ {l l′ Γ A B t u} {[A] : Γ ⊩⟨ l ⟩ A} {[B] : Γ ⊩⟨ l′ ⟩ B}
→ ShapeView Γ l l′ A B [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B / [B]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]
convEqTermT₂ (ℕᵥ D D′) A≡B (ιx (ℕₜ₌ k k′ d d′ k≡k′ prop)) = ιx (ℕₜ₌ k k′ d d′ k≡k′ prop)
convEqTermT₂ (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ιx (ne₌ M D′ neM K≡M))
(ιx (neₜ₌ k m d d′ (neNfₜ₌ neK₂ neM₁ k≡m))) =
let K₁≡K = PE.subst (λ x → _ ⊢ x ≡ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(sym (≅-eq (~-to-≅ K≡M)))
in ιx (neₜ₌ k m (convRed:*: d K₁≡K) (convRed:*: d′ K₁≡K)
(neNfₜ₌ neK₂ neM₁ (~-conv k≡m K₁≡K)))
convEqTermT₂ {Γ = Γ} (Πᵥ (Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ₌ f g d d′ funcF funcG t≡u [t] [u] [t≡u]) =
let [A] = Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext
[B] = Πᵣ′ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁
[A≡B] = Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]
ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ▹ G ≡ x)
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in Πₜ₌ f g (convRed:*: d (sym ΠFG≡ΠF₁G₁)) (convRed:*: d′ (sym ΠFG≡ΠF₁G₁))
funcF funcG (≅-conv t≡u (sym ΠFG≡ΠF₁G₁))
(convTerm₂ [A] [B] [A≡B] [t]) (convTerm₂ [A] [B] [A≡B] [u])
(λ {ρ} [ρ] ⊢Δ [a] →
let F₁≡F′ , G₁≡G′ = Π-PE-injectivity (whrDet* (red D₁ , Πₙ) (D′ , Πₙ))
[F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₁ ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a])
([G≡G′] [ρ] ⊢Δ [a])
in convEqTerm₂ ([G] [ρ] ⊢Δ [a]) ([G]₁ [ρ] ⊢Δ [a]₁)
[G≡G₁] ([t≡u] [ρ] ⊢Δ [a]₁))
convEqTermT₂ (Uᵥ .⁰ 0<1 ⊢Γ .⁰ 0<1 ⊢Γ₁) A≡B t≡u = t≡u
convEqTermT₂ (emb⁰¹ PE.refl x) (ιx A≡B) t≡u = ιx (convEqTermT₂ x A≡B t≡u)
convEqTermT₂ (emb¹⁰ PE.refl x) A≡B (ιx t≡u) = convEqTermT₂ x A≡B t≡u
-- Conversion of term equality converting from left to right.
convEqTerm₁ : ∀ {l l′ Γ A B t u} ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B / [B]
convEqTerm₁ [A] [B] A≡B t≡u = convEqTermT₁ (goodCases [A] [B] A≡B) A≡B t≡u
-- Conversion of term equality converting from right to left.
convEqTerm₂ : ∀ {l l′ Γ A B t u} ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B / [B]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]
convEqTerm₂ [A] [B] A≡B t≡u = convEqTermT₂ (goodCases [A] [B] A≡B) A≡B t≡u
|
{
"alphanum_fraction": 0.3884751373,
"avg_line_length": 54.2571428571,
"ext": "agda",
"hexsha": "33cea7a353a126816d7969cfe78fbc6d47cd8054",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Properties/Conversion.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Properties/Conversion.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Properties/Conversion.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6648,
"size": 13293
}
|
-- Reported by Andrea, 2014-05-xx
-- We cannot prune from a meta if one of its arguments is a lambda.
-- (In some cases we could, but it is hard to get this right,
-- probably needs a flow analysis.)
-- {-# OPTIONS -v tc.meta.assign:25 -v tc.meta.kill:40 #-}
open import Common.Equality
open import Common.Product
postulate
F : Set → Set
A : Set
test : let H : Set
H = _
M : ((Set → Set) → Set) → Set
M = _
in {Z : Set} → H ≡ F (M (\ G → A → G Z))
× F H ≡ F (F (A → A))
× M ≡ \ K → K (\ _ → A)
test = refl
, refl
, refl
#1 : {A : Set} →
let H : Set
H = _
M : (Set → Set) → Set → Set
M = _
in {Z : Set} → H ≡ F (M (\ _ → A) Z)
× M ≡ (\ F X → F X)
#1 = refl , refl
|
{
"alphanum_fraction": 0.4449818622,
"avg_line_length": 22.9722222222,
"ext": "agda",
"hexsha": "869b0618867c82c0d1f9a4ed0dd20c67663dde1e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue1153.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/Issue1153.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "masondesu/agda",
"max_stars_repo_path": "test/succeed/Issue1153.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 269,
"size": 827
}
|
module Type.Size where
import Lvl
open import Logic
open import Logic.Propositional
open import Logic.Predicate
open import Structure.Setoid
open import Structure.Function.Domain
open import Type
private variable ℓ ℓ₁ ℓ₂ ℓₑ ℓₑ₁ ℓₑ₂ : Lvl.Level
_≍_ : (A : Type{ℓ₁}) → ⦃ _ : Equiv{ℓₑ₁}(A) ⦄ → (B : Type{ℓ₂}) → ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → Stmt
A ≍ B = ∃{Obj = A → B}(Bijective)
_≼_ : (A : Type{ℓ₁}) → ⦃ _ : Equiv{ℓₑ₁}(A) ⦄ → (B : Type{ℓ₂}) → ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → Stmt
A ≼ B = ∃{Obj = A → B}(Injective)
_≽_ : (A : Type{ℓ₁}) → (B : Type{ℓ₂}) → ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → Stmt
A ≽ B = ∃{Obj = A → B}(Surjective)
_≭_ : (A : Type{ℓ₁}) → ⦃ _ : Equiv{ℓₑ₁}(A) ⦄ → (B : Type{ℓ₂}) → ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → Stmt
A ≭ B = ¬(A ≍ B)
_≺_ : (A : Type{ℓ₁}) → ⦃ _ : Equiv{ℓₑ₁}(A) ⦄ → (B : Type{ℓ₂}) → ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → Stmt
A ≺ B = (A ≼ B) ∧ (A ≭ B)
_≻_ : (A : Type{ℓ₁}) → ⦃ _ : Equiv{ℓₑ₁}(A) ⦄ → (B : Type{ℓ₂}) → ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → Stmt
A ≻ B = (A ≽ B) ∧ (A ≭ B)
|
{
"alphanum_fraction": 0.5171339564,
"avg_line_length": 32.1,
"ext": "agda",
"hexsha": "3a6bf593498e60345df36830584c69c935f2974c",
"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/Size.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/Size.agda",
"max_line_length": 92,
"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/Size.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": 552,
"size": 963
}
|
------------------------------------------------------------------------
-- Definitional interpreters can model systems with unbounded space
------------------------------------------------------------------------
-- As a follow-up to the development in Bounded-space I asked Ancona,
-- Dagnino and Zucca for further examples of properties for which it
-- is not clear to them if definitional interpreters work well. They
-- asked for a semantics that returns the largest heap size used by
-- the program, or infinity if there is no bound on this size. They
-- also asked how one can prove that a program transformation does not
-- increase the maximum heap usage.
-- It is impossible to write an Agda program that computes the maximum
-- heap usage, but one can at least produce a potentially infinite
-- list containing all heap sizes encountered in the execution of a
-- program, and then reason about this list. This approach is taken
-- below.
module Unbounded-space where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Tactic.By.Propositional
open import Prelude.Size
open import Colist equality-with-J as Colist
open import Conat equality-with-J as Conat
hiding (pred) renaming (_+_ to _⊕_)
open import Function-universe equality-with-J as F hiding (_∘_)
open import Nat equality-with-J as Nat using (_≤_; _≤↑_; pred)
open import Omniscience equality-with-J
open import Only-allocation
open import Upper-bounds
------------------------------------------------------------------------
-- Definitional interpreter
-- Modifies the heap size according to the given instruction.
modify : Stmt → ℕ → ℕ
modify alloc = suc
modify dealloc = pred
-- A definitional interpreter. It returns a trace of all heap sizes
-- encountered during the program's run. The input is the initial heap
-- size.
mutual
⟦_⟧ : ∀ {i} → Program i → ℕ → Colist ℕ i
⟦ p ⟧ h = h ∷ ⟦ p ⟧′ h
⟦_⟧′ : ∀ {i} → Program i → ℕ → Colist′ ℕ i
⟦ [] ⟧′ h .force = []
⟦ s ∷ p ⟧′ h .force = ⟦ p .force ⟧ (modify s h)
------------------------------------------------------------------------
-- The maximum heap usage predicate
-- The smallest heap size that is required to run the given program
-- when the initial heap is empty.
Heap-usage : Program ∞ → Conat ∞ → Type
Heap-usage p n = LUB (⟦ p ⟧ 0) n
-- The smallest extra heap size that is required to run the given
-- program, for arbitrary initial heaps.
Heap-usage′ : Program ∞ → Conat ∞ → Type
Heap-usage′ p n =
(∀ h → [ ∞ ] ⟦ p ⟧ h ⊑ n ⊕ ⌜ h ⌝)
×
(∀ n′ → (∀ h → [ ∞ ] ⟦ p ⟧ h ⊑ n′ ⊕ ⌜ h ⌝) → [ ∞ ] n ≤ n′)
-- The number n is an upper bound of the heap size required for a
-- program when it is started with an empty heap iff, for any initial
-- heap h, n plus the size of h is an upper bound.
--
-- Note that this kind of property might not hold for a more
-- complicated programming language, in which a program's actions
-- could depend on the contents of the initial heap.
∀⟦⟧⊑⇔⟦⟧⊑ :
∀ {p n i} →
[ i ] ⟦ p ⟧ 0 ⊑ n ⇔ (∀ h → [ i ] ⟦ p ⟧ h ⊑ n ⊕ ⌜ h ⌝)
∀⟦⟧⊑⇔⟦⟧⊑ {p} {n} {i} = record
{ to = to p
; from = (∀ h → [ i ] ⟦ p ⟧ h ⊑ n ⊕ ⌜ h ⌝) ↝⟨ _$ 0 ⟩
[ i ] ⟦ p ⟧ 0 ⊑ n ⊕ ⌜ 0 ⌝ ↝⟨ flip transitive-⊑≤ (∼→≤ (+-right-identity _)) ⟩□
[ i ] ⟦ p ⟧ 0 ⊑ n □
}
where
+⊕-cong :
∀ {m₁ m₂ n i} → [ i ] ⌜ m₁ ⌝ ≤ m₂ → [ i ] ⌜ m₁ + n ⌝ ≤ m₂ ⊕ ⌜ n ⌝
+⊕-cong {m₁} {m₂} {n} {i} =
[ i ] ⌜ m₁ ⌝ ≤ m₂ ↝⟨ _+-mono reflexive-≤ _ ⟩
[ i ] ⌜ m₁ ⌝ ⊕ ⌜ n ⌝ ≤ m₂ ⊕ ⌜ n ⌝ ↝⟨ transitive-≤ (∼→≤ (⌜⌝-+ m₁)) ⟩□
[ i ] ⌜ m₁ + n ⌝ ≤ m₂ ⊕ ⌜ n ⌝ □
to : ∀ {m i} p →
[ i ] ⟦ p ⟧ m ⊑ n → ∀ h → [ i ] ⟦ p ⟧ (m + h) ⊑ n ⊕ ⌜ h ⌝
to [] (m≤n ∷ _) _ = +⊕-cong m≤n ∷ λ { .force → [] }
to (s ∷ p) (m≤n ∷ p⊑) h = +⊕-cong m≤n ∷ λ { .force →
to′ _ s (force p⊑) }
where
to′ : ∀ {i} m s →
[ i ] ⟦ force p ⟧ (modify s m) ⊑ n →
[ i ] ⟦ force p ⟧ (modify s (m + h)) ⊑ n ⊕ ⌜ h ⌝
to′ _ alloc p⊑ = to (force p) p⊑ h
to′ (suc m) dealloc p⊑ = to (force p) p⊑ h
to′ zero dealloc p⊑ = transitive-⊑≤ (to (force p) p⊑ (pred h))
(reflexive-≤ n
+-mono
⌜⌝-mono (Nat.pred≤ _))
-- Heap-usage p n holds iff Heap-usage′ p n holds. For this reason the
-- former, less complicated definition will be used below.
Heap-usage⇔Heap-usage′ :
∀ p n → Heap-usage p n ⇔ Heap-usage′ p n
Heap-usage⇔Heap-usage′ p n =
([ ∞ ] ⟦ p ⟧ 0 ⊑ n ↝⟨ ∀⟦⟧⊑⇔⟦⟧⊑ ⟩□
(∀ h → [ ∞ ] ⟦ p ⟧ h ⊑ n ⊕ ⌜ h ⌝) □)
×-cong
((∀ n′ → [ ∞ ] ⟦ p ⟧ 0 ⊑ n′ → [ ∞ ] n ≤ n′) ↝⟨ ∀-cong _ (λ _ → →-cong _ ∀⟦⟧⊑⇔⟦⟧⊑ F.id) ⟩□
(∀ n′ → (∀ h → [ ∞ ] ⟦ p ⟧ h ⊑ n′ ⊕ ⌜ h ⌝) → [ ∞ ] n ≤ n′) □)
-- The maximum heap usage is unique (up to bisimilarity).
max-unique :
∀ {p m n i} →
Heap-usage p m → Heap-usage p n → Conat.[ i ] m ∼ n
max-unique = lub-unique
-- Heap-usage p respects bisimilarity.
max-respects-∼ :
∀ {p q m n} →
Colist.[ ∞ ] ⟦ p ⟧ 0 ∼ ⟦ q ⟧ 0 →
Conat.[ ∞ ] m ∼ n →
Heap-usage p m → Heap-usage q n
max-respects-∼ {p} {q} {m} {n} p∼q m∼n = Σ-map
([ ∞ ] ⟦ p ⟧ 0 ⊑ m ↝⟨ (λ hyp → transitive-⊑≤ (□-∼ p∼q hyp) (∼→≤ m∼n)) ⟩□
[ ∞ ] ⟦ q ⟧ 0 ⊑ n □)
((∀ o → [ ∞ ] ⟦ p ⟧ 0 ⊑ o → [ ∞ ] m ≤ o) ↝⟨ (λ hyp₁ o hyp₂ → transitive-≤ (∼→≤ (Conat.symmetric-∼ m∼n))
(hyp₁ o (□-∼ (Colist.symmetric-∼ p∼q) hyp₂))) ⟩□
(∀ o → [ ∞ ] ⟦ q ⟧ 0 ⊑ o → [ ∞ ] n ≤ o) □)
-- If the semantics of a program started in the empty heap does not
-- have a finite upper bound, then the maximum heap usage of the
-- program is infinity.
no-finite-max→infinite-max :
∀ p → (∀ n → ¬ [ ∞ ] ⟦ p ⟧ 0 ⊑ ⌜ n ⌝) → Heap-usage p infinity
no-finite-max→infinite-max p hyp =
(⟦ p ⟧ 0 ⊑infinity)
, λ n′ →
[ ∞ ] ⟦ p ⟧ 0 ⊑ n′ ↝⟨ no-finite→infinite hyp ⟩
Conat.[ ∞ ] n′ ∼ infinity ↝⟨ ∼→≤ ∘ Conat.symmetric-∼ ⟩□
[ ∞ ] infinity ≤ n′ □
-- If the maximum heap usage could always be determined (in a certain
-- sense), then WLPO (which is a constructive taboo) would hold.
max→wlpo : (∀ p → ∃ λ n → Heap-usage p n) → WLPO
max→wlpo find-max = λ f → case find-max (p f) of λ where
(zero , max-0) → inj₁ (_⇔_.to 0⇔≡false max-0)
(suc _ , max-+) → inj₂ (+→≢false max-+)
where
-- If f takes the value true, then p f contains exactly one
-- occurrence of alloc, at the first index for which f takes the
-- value true. Otherwise p f contains zero occurrences of alloc.
p : ∀ {i} → (ℕ → Bool) → Program i
p f = helper (f 0)
module P where
helper : ∀ {i} → Bool → Program i
helper =
if_then alloc ∷′ []
else dealloc ∷ λ { .force → p (λ n → f (1 + n)) }
-- The maximum heap usage of p f is zero iff f always takes the
-- value false.
0⇔≡false :
∀ {f} → Heap-usage (p f) ⌜ 0 ⌝ ⇔ (∀ n → f n ≡ false)
0⇔≡false = record
{ to = →≡false _ ∘ proj₁
; from = λ ≡false →
≡false→ _ ≡false Nat.≤-refl
, (λ _ _ → zero)
}
where
→≡false : ∀ f → [ ∞ ] ⟦ p f ⟧ 0 ⊑ ⌜ 0 ⌝ → ∀ n → f n ≡ false
→≡false f ⟦pf⟧0⊑0 _ = helper _ _ refl ⟦pf⟧0⊑0
where
helper : ∀ b n →
f 0 ≡ b →
[ ∞ ] ⟦ P.helper f b ⟧ 0 ⊑ ⌜ 0 ⌝ →
f n ≡ false
helper false zero f0≡false = λ _ → f0≡false
helper false (suc n) _ =
[ ∞ ] ⟦ P.helper f false ⟧ 0 ⊑ ⌜ 0 ⌝ ↝⟨ □-tail ⟩
[ ∞ ] ⟦ p (f ∘ suc) ⟧ 0 ⊑ ⌜ 0 ⌝ ↝⟨ (λ hyp → →≡false (f ∘ suc) hyp n) ⟩□
(f ∘ suc) n ≡ false □
helper true n _ =
[ ∞ ] ⟦ P.helper f true ⟧ 0 ⊑ ⌜ 0 ⌝ ↝⟨ □-head ∘ □-tail ⟩
([ ∞ ] ⌜ 1 ⌝ ≤ ⌜ 0 ⌝) ↝⟨ ⌜⌝-mono⁻¹ ⟩
1 ≤ 0 ↝⟨ Nat.+≮ 0 ⟩
⊥ ↝⟨ ⊥-elim ⟩□
f n ≡ false □
≡false→ :
∀ {m n i} f →
(∀ n → f n ≡ false) →
m ≤ n → [ i ] ⟦ p f ⟧ m ⊑ ⌜ n ⌝
≡false→ {m} {n} f ≡false m≤n with f 0 | ≡false 0
... | true | ()
... | false | _ =
zero +-mono ⌜⌝-mono m≤n ∷ λ { .force →
≡false→ (f ∘ suc) (≡false ∘ suc) (
pred m Nat.≤⟨ Nat.pred≤ _ ⟩
m Nat.≤⟨ m≤n ⟩∎
n ∎≤) }
-- If the maximum heap usage of p f is positive, then f does not
-- always take the value false.
+→≢false :
∀ {f n} → Heap-usage (p f) (suc n) → ¬ (∀ n → f n ≡ false)
+→≢false {f} {n} =
Heap-usage (p f) (suc n) ↝⟨ (λ max-+ →
Heap-usage (p f) ⌜ 0 ⌝ ↝⟨ max-unique max-+ ⟩
Conat.[ ∞ ] suc n ∼ ⌜ 0 ⌝ ↝⟨ (λ ()) ⟩□
⊥ □) ⟩
¬ Heap-usage (p f) ⌜ 0 ⌝ ↝⟨ (λ hyp ≡false → hyp (_⇔_.from 0⇔≡false ≡false)) ⟩□
¬ (∀ n → f n ≡ false) □
-- In fact, WLPO is logically equivalent to a certain formulation of
-- "the maximum heap usage can always be determined".
wlpo⇔max : WLPO ⇔ (∀ p → ∃ λ n → Heap-usage p n)
wlpo⇔max = record
{ to = λ wlpo p → wlpo→lub wlpo (⟦ p ⟧ 0)
; from = max→wlpo
}
-- We also get that WLPO is logically equivalent to a certain
-- formulation of "least upper bounds of colists of natural numbers
-- can always be determined".
wlpo⇔lub : WLPO ⇔ (∀ ms → ∃ λ n → LUB ms n)
wlpo⇔lub = record
{ to = wlpo→lub
; from = λ find-lub → max→wlpo (λ p → find-lub (⟦ p ⟧ 0))
}
------------------------------------------------------------------------
-- Some examples
-- When this semantics is used all three programs are non-terminating,
-- in the sense that their traces are infinitely long.
bounded-loops :
∀ {i n} → Conat.[ i ] length (⟦ bounded ⟧ n) ∼ infinity
bounded-loops =
suc λ { .force →
suc λ { .force →
bounded-loops }}
bounded₂-loops :
∀ {i n} → Conat.[ i ] length (⟦ bounded₂ ⟧ n) ∼ infinity
bounded₂-loops =
suc λ { .force →
suc λ { .force →
suc λ { .force →
suc λ { .force →
bounded₂-loops }}}}
unbounded-loops :
∀ {i n} → Conat.[ i ] length (⟦ unbounded ⟧ n) ∼ infinity
unbounded-loops =
suc λ { .force →
unbounded-loops }
-- Zero is not an upper bound of the semantics of bounded when it is
-- started with an empty heap.
⟦bounded⟧⋢0 : ¬ [ ∞ ] ⟦ bounded ⟧ 0 ⊑ ⌜ 0 ⌝
⟦bounded⟧⋢0 =
[ ∞ ] ⟦ bounded ⟧ 0 ⊑ ⌜ 0 ⌝ ↝⟨ □-head ∘ □-tail ⟩
[ ∞ ] ⌜ 1 ⌝ ≤ ⌜ 0 ⌝ ↝⟨ ⌜⌝-mono⁻¹ ⟩
(1 ≤ 0) ↝⟨ Nat.+≮ 0 ⟩□
⊥ □
-- However, one is.
⟦bounded⟧⊑1 :
∀ {i} → [ i ] ⟦ bounded ⟧ 0 ⊑ ⌜ 1 ⌝
⟦bounded⟧⊑1 =
≤suc ∷ λ { .force →
reflexive-≤ _ ∷ λ { .force →
⟦bounded⟧⊑1 }}
-- The maximum heap usage of bounded is 1.
max-bounded-1 : Heap-usage bounded ⌜ 1 ⌝
max-bounded-1 =
⟦bounded⟧⊑1
, λ n′ →
[ ∞ ] ⟦ bounded ⟧ 0 ⊑ n′ ↝⟨ □-head ∘ □-tail ⟩□
[ ∞ ] ⌜ 1 ⌝ ≤ n′ □
-- Two is an upper bound of the semantics of bounded₂ when it is
-- started in an empty heap.
⟦bounded₂⟧⊑2 :
∀ {i} → [ i ] ⟦ bounded₂ ⟧ 0 ⊑ ⌜ 2 ⌝
⟦bounded₂⟧⊑2 =
zero ∷ λ { .force →
suc (λ { .force → zero }) ∷ λ { .force →
reflexive-≤ _ ∷ λ { .force →
suc (λ { .force → zero }) ∷ λ { .force →
⟦bounded₂⟧⊑2 }}}}
-- The maximum heap usage of bounded₂ is 2.
max-bounded₂-2 : Heap-usage bounded₂ ⌜ 2 ⌝
max-bounded₂-2 =
⟦bounded₂⟧⊑2
, λ n′ →
[ ∞ ] ⟦ bounded₂ ⟧ 0 ⊑ n′ ↝⟨ □-head ∘ □-tail ∘ □-tail ⟩□
[ ∞ ] ⌜ 2 ⌝ ≤ n′ □
-- There is no finite upper bound of the semantics of unbounded.
⟦unbounded⟧⋢⌜⌝ :
∀ {n} → ¬ [ ∞ ] ⟦ unbounded ⟧ 0 ⊑ ⌜ n ⌝
⟦unbounded⟧⋢⌜⌝ {n} = helper (Nat.≤→≤↑ (Nat.zero≤ _))
where
helper :
∀ {h} → h ≤↑ 1 + n → ¬ [ ∞ ] ⟦ unbounded ⟧ h ⊑ ⌜ n ⌝
helper (Nat.≤↑-refl refl) =
[ ∞ ] ⟦ unbounded ⟧ (1 + n) ⊑ ⌜ n ⌝ ↝⟨ □-head ⟩
[ ∞ ] ⌜ 1 + n ⌝ ≤ ⌜ n ⌝ ↝⟨ ⌜⌝-mono⁻¹ ⟩
(1 + n ≤ n) ↝⟨ Nat.+≮ 0 ⟩□
⊥ □
helper {h} (Nat.≤↑-step 1+h≤1+n) =
[ ∞ ] ⟦ unbounded ⟧ h ⊑ ⌜ n ⌝ ↝⟨ □-tail ⟩
[ ∞ ] ⟦ unbounded ⟧ (1 + h) ⊑ ⌜ n ⌝ ↝⟨ helper 1+h≤1+n ⟩□
⊥ □
-- The maximum heap usage of unbounded is infinity.
max-unbounded-∞ : Heap-usage unbounded infinity
max-unbounded-∞ =
no-finite-max→infinite-max unbounded λ _ → ⟦unbounded⟧⋢⌜⌝
------------------------------------------------------------------------
-- A simple optimiser
-- An optimiser that replaces subsequences of the form "alloc, alloc,
-- dealloc" with "alloc".
opt : ∀ {i} → Program ∞ → Program i
opt [] = []
opt (dealloc ∷ p) = dealloc ∷ λ { .force → opt (p .force) }
opt {i} (alloc ∷ p) = opt₁ (p .force)
module Opt where
default : Program i
default = alloc ∷ λ { .force → opt (p .force) }
opt₂ : Program ∞ → Program i
opt₂ (dealloc ∷ p″) = alloc ∷ λ { .force → opt (p″ .force) }
opt₂ _ = default
opt₁ : Program ∞ → Program i
opt₁ (alloc ∷ p′) = opt₂ (p′ .force)
opt₁ _ = default
-- The semantics of opt bounded₂ matches that of bounded.
opt-bounded₂∼bounded :
∀ {i n} →
Colist.[ i ] ⟦ opt bounded₂ ⟧ n ∼ ⟦ bounded ⟧ n
opt-bounded₂∼bounded =
refl ∷ λ { .force →
refl ∷ λ { .force →
opt-bounded₂∼bounded }}
-- Sometimes the optimised program's maximum heap usage is less than
-- that of the original program.
opt-improves :
∃ λ p → Heap-usage p ⌜ 2 ⌝ × Heap-usage (opt p) ⌜ 1 ⌝
opt-improves =
bounded₂
, max-bounded₂-2
, max-respects-∼
(Colist.symmetric-∼ opt-bounded₂∼bounded)
(_ ∎∼)
max-bounded-1
-- The optimised program's maximum heap usage is at most as large as
-- that of the original program (assuming that these maximums exist).
mutual
opt-correct :
∀ {i m n} p →
Heap-usage (opt p) m → Heap-usage p n → [ i ] m ≤ n
opt-correct p max₁ max₂ =
_⇔_.to (≲⇔least-upper-bounds-≤ max₁ max₂) (opt-correct-≲ p)
opt-correct-≲ : ∀ {h i} p → [ i ] ⟦ opt p ⟧ h ≲ ⟦ p ⟧ h
opt-correct-≲ {h} [] =
⟦ opt [] ⟧ h ∼⟨ ∷∼∷′ ⟩≲
h ∷′ [] ∼⟨ Colist.symmetric-∼ ∷∼∷′ ⟩□≲
⟦ [] ⟧ h
opt-correct-≲ {h} (dealloc ∷ p) =
⟦ opt (dealloc ∷ p) ⟧ h ∼⟨ ∷∼∷′ ⟩≲
h ∷′ ⟦ opt (p .force) ⟧ (pred h) ≲⟨ (cons′-≲ λ { hyp .force → opt-correct-≲ (p .force) hyp }) ⟩
h ∷′ ⟦ p .force ⟧ (pred h) ∼⟨ Colist.symmetric-∼ ∷∼∷′ ⟩□≲
⟦ dealloc ∷ p ⟧ h
opt-correct-≲ {h} (alloc ∷ p) =
⟦ opt (alloc ∷ p) ⟧ h ≡⟨⟩≲
⟦ Opt.opt₁ p (p .force) ⟧ h ≲⟨ opt-correct₁ _ refl ⟩
h ∷′ ⟦ p .force ⟧ (1 + h) ∼⟨ Colist.symmetric-∼ ∷∼∷′ ⟩□≲
⟦ alloc ∷ p ⟧ h
where
default-correct :
∀ {p′ i} →
p′ ≡ p .force →
[ i ] ⟦ Opt.default p ⟧ h ≲ h ∷′ ⟦ p′ ⟧ (1 + h)
default-correct refl =
⟦ Opt.default p ⟧ h ∼⟨ ∷∼∷′ ⟩≲
h ∷′ ⟦ opt (p .force) ⟧ (1 + h) ≲⟨ (cons′-≲ λ { hyp .force → opt-correct-≲ (p .force) hyp }) ⟩□
h ∷′ ⟦ p .force ⟧ (1 + h)
opt-correct₁ :
∀ {i} p′ →
p′ ≡ p .force →
[ i ] ⟦ Opt.opt₁ p p′ ⟧ h ≲ h ∷′ ⟦ p′ ⟧ (1 + h)
opt-correct₁ [] []≡ = default-correct []≡
opt-correct₁ (dealloc ∷ p′) d∷≡ = default-correct d∷≡
opt-correct₁ (alloc ∷ p′) a∷≡ =
⟦ Opt.opt₂ p (p′ .force) ⟧ h ≲⟨ opt-correct₂ (p′ .force) refl ⟩
h ∷′ 1 + h ∷′ ⟦ p′ .force ⟧ (2 + h) ∼⟨ (refl ∷ λ { .force → Colist.symmetric-∼ ∷∼∷′ }) ⟩□≲
h ∷′ ⟦ alloc ∷ p′ ⟧ (1 + h)
where
default-correct′ :
∀ {i p″} →
p″ ≡ p′ .force →
[ i ] ⟦ Opt.default p ⟧ h ≲ h ∷′ 1 + h ∷′ ⟦ p″ ⟧ (2 + h)
default-correct′ refl =
⟦ Opt.default p ⟧ h ≲⟨ default-correct refl ⟩
h ∷′ ⟦ p .force ⟧ (1 + h) ≡⟨ by a∷≡ ⟩≲
h ∷′ ⟦ alloc ∷ p′ ⟧ (1 + h) ∼⟨ (refl ∷ λ { .force → ∷∼∷′ }) ⟩□≲
h ∷′ 1 + h ∷′ ⟦ p′ .force ⟧ (2 + h)
opt-correct₂ :
∀ {i} p″ →
p″ ≡ p′ .force →
[ i ] ⟦ Opt.opt₂ p p″ ⟧ h ≲ h ∷′ 1 + h ∷′ ⟦ p″ ⟧ (2 + h)
opt-correct₂ [] []≡ = default-correct′ []≡
opt-correct₂ (alloc ∷ p″) a∷≡ = default-correct′ a∷≡
opt-correct₂ (dealloc ∷ p″) _ =
⟦ Opt.opt₂ p (dealloc ∷ p″) ⟧ h ∼⟨ ∷∼∷′ ⟩≲
h ∷′ ⟦ opt (p″ .force) ⟧ (1 + h) ≲⟨ (cons′-≲ λ { hyp .force → opt-correct-≲ (p″ .force) hyp }) ⟩
h ∷′ ⟦ p″ .force ⟧ (1 + h) ≲⟨ (cons′-≲ λ { hyp .force → consʳ-≲ (consʳ-≲ (_ □≲)) hyp }) ⟩
h ∷′ 1 + h ∷′ 2 + h ∷′ ⟦ p″ .force ⟧ (1 + h) ∼⟨ (refl ∷ λ { .force → refl ∷ λ { .force → Colist.symmetric-∼ ∷∼∷′ } }) ⟩□≲
h ∷′ 1 + h ∷′ ⟦ dealloc ∷ p″ ⟧ (2 + h)
|
{
"alphanum_fraction": 0.4684738835,
"avg_line_length": 34.4451345756,
"ext": "agda",
"hexsha": "f5dfad036c2f27b670cc64d65c19ee24205243ab",
"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/Unbounded-space.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/Unbounded-space.agda",
"max_line_length": 130,
"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/Unbounded-space.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6988,
"size": 16637
}
|
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.SuspSectionDecomp
open import homotopy.CofiberComp
module homotopy.SuspProduct where
module SuspProduct {i} {j} (X : Ptd i) (Y : Ptd j) where
private
i₁ : fst (X ⊙→ X ⊙× Y)
i₁ = ((λ x → (x , snd Y)) , idp)
i₂ : fst (Y ⊙→ X ⊙× Y)
i₂ = ((λ y → (snd X , y)) , idp)
j₂ : fst (⊙Cof i₁) → fst Y
j₂ = CofiberRec.f (snd Y) snd (λ x → idp)
⊙path : ⊙Susp (X ⊙× Y) == ⊙Susp X ⊙∨ (⊙Susp Y ⊙∨ ⊙Susp (X ⊙∧ Y))
⊙path =
⊙ua (⊙≃-in (SuspSectionDecomp.eq i₁ fst (λ x → idp))
(! $ ap winl $ merid (snd X)))
∙ ap (λ Z → ⊙Susp X ⊙∨ Z)
(⊙ua (⊙≃-in (SuspSectionDecomp.eq (⊙cfcod' i₁ ⊙∘ i₂) j₂ (λ y → idp))
(! $ ap winl $ merid (snd Y))))
∙ ap (λ Z → ⊙Susp X ⊙∨ (⊙Susp Y ⊙∨ ⊙Susp Z))
(CofiberComp.⊙path i₁ i₂)
|
{
"alphanum_fraction": 0.4924330617,
"avg_line_length": 28.6333333333,
"ext": "agda",
"hexsha": "dd2667b3131be2cef210244ee25bfc401ec0f5e9",
"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": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/SuspProduct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"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": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/SuspProduct.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/SuspProduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 391,
"size": 859
}
|
open import Data.Product using ( ∃ ; _×_ ; _,_ )
open import Data.Sum using ( inj₁ ; inj₂ )
open import Relation.Nullary using ( Dec ; yes ; no )
open import Relation.Unary using ( _∈_ ; _∉_ ; ∅ ; U ; _∪_ ; _∩_ ; ∁ )
open import Web.Semantic.DL.Concept using ( Concept ; ⟨_⟩ ; ¬⟨_⟩ ; ⊤ ; ⊥ ; _⊓_ ; _⊔_ ; ∀[_]_ ; ∃⟨_⟩_ ; ≤1 ; >1 ; neg )
open import Web.Semantic.DL.Role.Model using ( _⟦_⟧₂ ; ⟦⟧₂-resp-≈ ; ⟦⟧₂-resp-≲ ; ⟦⟧₂-galois )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox.Interp using ( Interp ; Δ ; _⊨_≈_ ; _⊨_≉_ ; con ; con-≈ ; ≈-refl ; ≈-sym ; ≈-trans )
open import Web.Semantic.DL.TBox.Interp.Morphism using ( _≲_ ; _≃_ ; ≲-resp-con ; ≲-resp-≈ ; ≃-impl-≲ ; ≃-impl-≳ ; ≃-iso ; ≃-iso⁻¹ ; ≃-image ; ≃-image⁻¹ ; ≃-refl-≈ ; ≃-sym )
open import Web.Semantic.Util using ( Subset ; tt ; _∘_ ; ExclMiddle ; elim )
module Web.Semantic.DL.Concept.Model {Σ : Signature} where
_⟦_⟧₁ : ∀ (I : Interp Σ) → Concept Σ → Subset (Δ I)
I ⟦ ⟨ c ⟩ ⟧₁ = con I c
I ⟦ ¬⟨ c ⟩ ⟧₁ = ∁ (con I c)
I ⟦ ⊤ ⟧₁ = U
I ⟦ ⊥ ⟧₁ = ∅
I ⟦ C ⊓ D ⟧₁ = I ⟦ C ⟧₁ ∩ I ⟦ D ⟧₁
I ⟦ C ⊔ D ⟧₁ = I ⟦ C ⟧₁ ∪ I ⟦ D ⟧₁
I ⟦ ∀[ R ] C ⟧₁ = λ x → ∀ y → ((x , y) ∈ I ⟦ R ⟧₂) → (y ∈ I ⟦ C ⟧₁)
I ⟦ ∃⟨ R ⟩ C ⟧₁ = λ x → ∃ λ y → ((x , y) ∈ I ⟦ R ⟧₂) × (y ∈ I ⟦ C ⟧₁)
I ⟦ ≤1 R ⟧₁ = λ x → ∀ y z → ((x , y) ∈ I ⟦ R ⟧₂) → ((x , z) ∈ I ⟦ R ⟧₂) → (I ⊨ y ≈ z)
I ⟦ >1 R ⟧₁ = λ x → ∃ λ y → ∃ λ z → ((x , y) ∈ I ⟦ R ⟧₂) × ((x , z) ∈ I ⟦ R ⟧₂) × (I ⊨ y ≉ z)
⟦⟧₁-resp-≈ : ∀ I C {x y} → (x ∈ I ⟦ C ⟧₁) → (I ⊨ x ≈ y) → (y ∈ I ⟦ C ⟧₁)
⟦⟧₁-resp-≈ I ⟨ c ⟩ x∈⟦c⟧ x≈y =
con-≈ I c x∈⟦c⟧ x≈y
⟦⟧₁-resp-≈ I ¬⟨ c ⟩ x∉⟦c⟧ x≈y =
λ y∈⟦c⟧ → x∉⟦c⟧ (con-≈ I c y∈⟦c⟧ (≈-sym I x≈y))
⟦⟧₁-resp-≈ I ⊤ x∈⊤ x≈y =
tt
⟦⟧₁-resp-≈ I (C ⊓ D) (x∈⟦C⟧ , x∈⟦D⟧) x≈y =
(⟦⟧₁-resp-≈ I C x∈⟦C⟧ x≈y , ⟦⟧₁-resp-≈ I D x∈⟦D⟧ x≈y)
⟦⟧₁-resp-≈ I (C ⊔ D) (inj₁ x∈⟦C⟧) x≈y =
inj₁ (⟦⟧₁-resp-≈ I C x∈⟦C⟧ x≈y)
⟦⟧₁-resp-≈ I (C ⊔ D) (inj₂ x∈⟦D⟧) x≈y =
inj₂ (⟦⟧₁-resp-≈ I D x∈⟦D⟧ x≈y)
⟦⟧₁-resp-≈ I (∀[ R ] C) x∈⟦∀RC⟧ x≈y =
λ z yz∈⟦R⟧ → x∈⟦∀RC⟧ z (⟦⟧₂-resp-≈ I R x≈y yz∈⟦R⟧ (≈-refl I))
⟦⟧₁-resp-≈ I (∃⟨ R ⟩ C) (z , xz∈⟦R⟧ , z∈⟦C⟧) x≈y =
(z , ⟦⟧₂-resp-≈ I R (≈-sym I x≈y) xz∈⟦R⟧ (≈-refl I) , z∈⟦C⟧)
⟦⟧₁-resp-≈ I (≤1 R) x∈⟦≤1R⟧ x≈y =
λ w z yw∈⟦R⟧ yz∈⟦R⟧ → x∈⟦≤1R⟧ w z
(⟦⟧₂-resp-≈ I R x≈y yw∈⟦R⟧ (≈-refl I))
(⟦⟧₂-resp-≈ I R x≈y yz∈⟦R⟧ (≈-refl I))
⟦⟧₁-resp-≈ I (>1 R) (w , z , xw∈⟦R⟧ , xz∈⟦R⟧ , w≉z) x≈y =
( w , z
, ⟦⟧₂-resp-≈ I R (≈-sym I x≈y) xw∈⟦R⟧ (≈-refl I)
, ⟦⟧₂-resp-≈ I R (≈-sym I x≈y) xz∈⟦R⟧ (≈-refl I)
, w≉z)
⟦⟧₁-resp-≈ I ⊥ () x≈y
mutual
⟦⟧₁-refl-≃ : ∀ {I J : Interp Σ} → (I≃J : I ≃ J) → ∀ {x} C → (≃-image⁻¹ I≃J x ∈ I ⟦ C ⟧₁) → (x ∈ J ⟦ C ⟧₁)
⟦⟧₁-refl-≃ {I} {J} I≃J {x} C x∈⟦C⟧ = ⟦⟧₁-resp-≈ J C (⟦⟧₁-resp-≃ I≃J C x∈⟦C⟧) (≃-iso⁻¹ I≃J x)
⟦⟧₁-resp-≃ : ∀ {I J : Interp Σ} → (I≃J : I ≃ J) → ∀ {x} C → (x ∈ I ⟦ C ⟧₁) → (≃-image I≃J x ∈ J ⟦ C ⟧₁)
⟦⟧₁-resp-≃ {I} {J} I≃J ⟨ c ⟩ x∈⟦c⟧ =
≲-resp-con (≃-impl-≲ I≃J) x∈⟦c⟧
⟦⟧₁-resp-≃ {I} {J} I≃J {x} ¬⟨ c ⟩ x∉⟦c⟧ =
λ x∈⟦c⟧ → x∉⟦c⟧ (con-≈ I c (≲-resp-con (≃-impl-≳ I≃J) x∈⟦c⟧) (≃-iso I≃J x))
⟦⟧₁-resp-≃ {I} {J} I≃J ⊤ _ =
tt
⟦⟧₁-resp-≃ {I} {J} I≃J ⊥ ()
⟦⟧₁-resp-≃ {I} {J} I≃J (C ⊓ D) (x∈⟦C⟧ , x∈⟦D⟧) =
(⟦⟧₁-resp-≃ I≃J C x∈⟦C⟧ , ⟦⟧₁-resp-≃ I≃J D x∈⟦D⟧)
⟦⟧₁-resp-≃ {I} {J} I≃J (C ⊔ D) (inj₁ x∈⟦C⟧) =
inj₁ (⟦⟧₁-resp-≃ I≃J C x∈⟦C⟧)
⟦⟧₁-resp-≃ {I} {J} I≃J (C ⊔ D) (inj₂ x∈⟦D⟧) =
inj₂ (⟦⟧₁-resp-≃ I≃J D x∈⟦D⟧)
⟦⟧₁-resp-≃ {I} {J} I≃J (∀[ R ] C) x∈⟦∀RC⟧ =
λ y xy∈⟦R⟧ → ⟦⟧₁-refl-≃ I≃J C
(x∈⟦∀RC⟧ (≃-image⁻¹ I≃J y) (⟦⟧₂-galois (≃-sym I≃J) R xy∈⟦R⟧))
⟦⟧₁-resp-≃ {I} {J} I≃J (∃⟨ R ⟩ C) (y , xy∈⟦R⟧ , y∈⟦C⟧) =
( ≃-image I≃J y
, ⟦⟧₂-resp-≲ (≃-impl-≲ I≃J) R xy∈⟦R⟧
, ⟦⟧₁-resp-≃ I≃J C y∈⟦C⟧ )
⟦⟧₁-resp-≃ {I} {J} I≃J (≤1 R) x∈⟦≤1R⟧ =
λ y z xy∈⟦R⟧ xz∈⟦R⟧ → ≃-refl-≈ I≃J
(x∈⟦≤1R⟧ (≃-image⁻¹ I≃J y) (≃-image⁻¹ I≃J z)
(⟦⟧₂-galois (≃-sym I≃J) R xy∈⟦R⟧) (⟦⟧₂-galois (≃-sym I≃J) R xz∈⟦R⟧))
⟦⟧₁-resp-≃ {I} {J} I≃J (>1 R) (y , z , xy∈⟦R⟧ , xz∈⟦R⟧ , y≉z) =
( ≃-image I≃J y , ≃-image I≃J z
, ⟦⟧₂-resp-≲ (≃-impl-≲ I≃J) R xy∈⟦R⟧
, ⟦⟧₂-resp-≲ (≃-impl-≲ I≃J) R xz∈⟦R⟧
, y≉z ∘ ≃-refl-≈ (≃-sym I≃J) )
neg-sound : ∀ I {x} C → (x ∈ I ⟦ neg C ⟧₁) → (x ∉ I ⟦ C ⟧₁)
neg-sound I ⟨ c ⟩ x∉⟦c⟧ x∈⟦c⟧ = x∉⟦c⟧ x∈⟦c⟧
neg-sound I ¬⟨ c ⟩ x∈⟦c⟧ x∉⟦c⟧ = x∉⟦c⟧ x∈⟦c⟧
neg-sound I ⊤ () _
neg-sound I ⊥ _ ()
neg-sound I (C ⊓ D) (inj₁ x∈⟦¬C⟧) (x∈⟦C⟧ , x∈⟦D⟧) = neg-sound I C x∈⟦¬C⟧ x∈⟦C⟧
neg-sound I (C ⊓ D) (inj₂ x∈⟦¬D⟧) (x∈⟦C⟧ , x∈⟦D⟧) = neg-sound I D x∈⟦¬D⟧ x∈⟦D⟧
neg-sound I (C ⊔ D) (x∈⟦¬C⟧ , x∈⟦¬D⟧) (inj₁ x∈⟦C⟧) = neg-sound I C x∈⟦¬C⟧ x∈⟦C⟧
neg-sound I (C ⊔ D) (x∈⟦¬C⟧ , x∈⟦¬D⟧) (inj₂ x∈⟦D⟧) = neg-sound I D x∈⟦¬D⟧ x∈⟦D⟧
neg-sound I (∀[ R ] C) (y , xy∈⟦R⟧ , y∈⟦¬C⟧) x∈⟦∀RC⟧ = neg-sound I C y∈⟦¬C⟧ (x∈⟦∀RC⟧ y xy∈⟦R⟧)
neg-sound I (∃⟨ R ⟩ C) x∈⟦∀R¬C⟧ (y , xy∈⟦R⟧ , y∈⟦C⟧) = neg-sound I C (x∈⟦∀R¬C⟧ y xy∈⟦R⟧) y∈⟦C⟧
neg-sound I (≤1 R) (y , z , xy∈⟦R⟧ , xz∈⟦R⟧ , y≉z) x∈⟦≤1R⟧ = y≉z (x∈⟦≤1R⟧ y z xy∈⟦R⟧ xz∈⟦R⟧)
neg-sound I (>1 R) x∈⟦≤1R⟧ (y , z , xy∈⟦R⟧ , xz∈⟦R⟧ , y≉z) = y≉z (x∈⟦≤1R⟧ y z xy∈⟦R⟧ xz∈⟦R⟧)
neg-complete : ExclMiddle → ∀ I {x} C → (x ∉ I ⟦ C ⟧₁) → (x ∈ I ⟦ neg C ⟧₁)
neg-complete excl-middle I ⟨ c ⟩ x∉⟦c⟧ = x∉⟦c⟧
neg-complete excl-middle I {x} ¬⟨ c ⟩ ¬x∉⟦c⟧ with excl-middle (x ∈ con I c)
neg-complete excl-middle I ¬⟨ c ⟩ ¬x∉⟦c⟧ | yes x∈⟦c⟧ = x∈⟦c⟧
neg-complete excl-middle I ¬⟨ c ⟩ ¬x∉⟦c⟧ | no x∉⟦c⟧ = elim (¬x∉⟦c⟧ x∉⟦c⟧)
neg-complete excl-middle I ⊤ x∉⟦⊤⟧ = x∉⟦⊤⟧ tt
neg-complete excl-middle I ⊥ x∉⟦⊥⟧ = tt
neg-complete excl-middle I {x} (C ⊓ D) x∉⟦C⊓D⟧ with excl-middle (x ∈ I ⟦ C ⟧₁)
neg-complete excl-middle I (C ⊓ D) x∉⟦C⊓D⟧ | yes x∈⟦C⟧ =
inj₂ (neg-complete excl-middle I D (λ x∈⟦D⟧ → x∉⟦C⊓D⟧ (x∈⟦C⟧ , x∈⟦D⟧)))
neg-complete excl-middle I (C ⊓ D) x∉⟦C⊓D⟧ | no x∉⟦C⟧ =
inj₁ (neg-complete excl-middle I C x∉⟦C⟧)
neg-complete excl-middle I (C ⊔ D) x∉⟦C⊔D⟧ =
( neg-complete excl-middle I C (x∉⟦C⊔D⟧ ∘ inj₁)
, neg-complete excl-middle I D (x∉⟦C⊔D⟧ ∘ inj₂))
neg-complete excl-middle I {x} (∀[ R ] C) x∉⟦∀RC⟧
with excl-middle (∃ λ y → ((x , y) ∈ I ⟦ R ⟧₂) × (y ∉ I ⟦ C ⟧₁))
neg-complete excl-middle I {x} (∀[ R ] C) x∉⟦∀RC⟧ | yes (y , xy∈⟦R⟧ , y∉⟦C⟧) =
(y , xy∈⟦R⟧ , neg-complete excl-middle I C y∉⟦C⟧)
neg-complete excl-middle I {x} (∀[ R ] C) x∉⟦∀RC⟧ | no ∄xy∈⟦R⟧∙y∉⟦C⟧ =
elim (x∉⟦∀RC⟧ lemma) where
lemma : x ∈ I ⟦ ∀[ R ] C ⟧₁
lemma y xy∈⟦R⟧ with excl-middle (y ∈ I ⟦ C ⟧₁)
lemma y xy∈⟦R⟧ | yes y∈⟦C⟧ = y∈⟦C⟧
lemma y xy∈⟦R⟧ | no y∉⟦C⟧ = elim (∄xy∈⟦R⟧∙y∉⟦C⟧ (y , xy∈⟦R⟧ , y∉⟦C⟧))
neg-complete excl-middle I (∃⟨ R ⟩ C) x∉⟦∃RC⟧ =
λ y xy∈⟦R⟧ → neg-complete excl-middle I C
(λ y∈⟦C⟧ → x∉⟦∃RC⟧ (y , xy∈⟦R⟧ , y∈⟦C⟧))
neg-complete excl-middle I {x} (≤1 R) x∉⟦≤1R⟧ = lemma where
lemma : x ∈ I ⟦ >1 R ⟧₁
lemma with excl-middle (x ∈ I ⟦ >1 R ⟧₁)
lemma | yes x∈⟦>1R⟧ = x∈⟦>1R⟧
lemma | no x∉⟦>1R⟧ = elim (x∉⟦≤1R⟧ lemma′) where
lemma′ : x ∈ I ⟦ ≤1 R ⟧₁
lemma′ y z xy∈⟦R⟧ xz∈⟦R⟧ with excl-middle (I ⊨ y ≈ z)
lemma′ y z xy∈⟦R⟧ xz∈⟦R⟧ | yes y≈z = y≈z
lemma′ y z xy∈⟦R⟧ xz∈⟦R⟧ | no y≉z =
elim (x∉⟦>1R⟧ (y , z , xy∈⟦R⟧ , xz∈⟦R⟧ , y≉z))
neg-complete excl-middle I {x} (>1 R) x∉⟦>1R⟧ = lemma where
lemma : x ∈ I ⟦ ≤1 R ⟧₁
lemma y z xy∈⟦R⟧ xz∈⟦R⟧ with excl-middle (I ⊨ y ≈ z)
lemma y z xy∈⟦R⟧ xz∈⟦R⟧ | yes y≈z = y≈z
lemma y z xy∈⟦R⟧ xz∈⟦R⟧ | no y≉z =
elim (x∉⟦>1R⟧ (y , z , xy∈⟦R⟧ , xz∈⟦R⟧ , y≉z))
|
{
"alphanum_fraction": 0.421436142,
"avg_line_length": 50.6577181208,
"ext": "agda",
"hexsha": "d623d08b7490942095bec66a5dd1bc102e86f945",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/Concept/Model.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/Concept/Model.agda",
"max_line_length": 173,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/Concept/Model.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 5130,
"size": 7548
}
|
{-# OPTIONS --universe-polymorphism --no-irrelevant-projections --without-K #-}
module SafeFlagSafePragmas where
|
{
"alphanum_fraction": 0.7719298246,
"avg_line_length": 28.5,
"ext": "agda",
"hexsha": "ae76f3ca006be8743883ea6ca83f81498f6e0aea",
"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/SafeFlagSafePragmas.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/SafeFlagSafePragmas.agda",
"max_line_length": 79,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/SafeFlagSafePragmas.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 28,
"size": 114
}
|
module *-assoc where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; cong)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_)
open import *-distrib-+ using (*-distrib-+)
-- 積の結合律 (associativity)
*-assoc : ∀ (m n p : ℕ) → (m * n) * p ≡ m * (n * p)
*-assoc zero n p =
begin
(zero * n) * p
≡⟨⟩
zero * p
≡⟨⟩
zero
≡⟨⟩
zero * (n * p)
∎
*-assoc (suc m) n p =
begin
((suc m) * n) * p
≡⟨⟩
(n + m * n) * p
≡⟨ *-distrib-+ n (m * n) p ⟩
(n * p) + m * n * p
≡⟨ cong ((n * p) +_) (*-assoc m n p) ⟩
(n * p) + m * (n * p)
≡⟨⟩
(suc m) * (n * p)
∎
|
{
"alphanum_fraction": 0.466367713,
"avg_line_length": 19.6764705882,
"ext": "agda",
"hexsha": "5600163ee3442b375da8314157fef2093ded19ee",
"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": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/induction/*-assoc.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"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": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/induction/*-assoc.agda",
"max_line_length": 53,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/induction/*-assoc.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 327,
"size": 669
}
|
open import Agda.Primitive using (Level; lsuc)
variable
ℓ p : Level
A B : Set ℓ
x y z : A
postulate
easy : A
record R a : Set (lsuc a) where
field
_≡_ : {A : Set a} → A → A → Set a
module _ (r : ∀ ℓ → R ℓ) where
open module R′ {ℓ} = R (r ℓ)
postulate
refl : (x : A) → x ≡ x
cong : (f : A → B) → x ≡ y → f x ≡ f y
subst : (P : A → Set p) → x ≡ y → P x → P y
trans : x ≡ y → y ≡ z → x ≡ z
elim : (P : {x y : A} → x ≡ y → Set p) →
(∀ x → P (refl x)) →
(x≡y : x ≡ y) → P x≡y
elim-refl : (P : {x y : A} → x ≡ y → Set p)
(r : ∀ x → P (refl x)) →
elim P r (refl x) ≡ r x
[subst≡]≡[trans≡trans] :
{p : x ≡ y} {q : x ≡ x} {r : y ≡ y} →
(subst (λ z → z ≡ z) p q ≡ r)
≡
(trans q p ≡ trans p r)
[subst≡]≡[trans≡trans] {p = p} {q} {r} = elim
(λ {x y} p → {q : x ≡ x} {r : y ≡ y} →
(subst (λ z → z ≡ z) p q ≡ r)
≡
(trans q p ≡ trans p r))
(λ _ → easy)
p
[subst≡]≡[trans≡trans]-refl :
{q r : x ≡ x} →
[subst≡]≡[trans≡trans] {p = refl x} {q = q} {r = r} ≡
easy
[subst≡]≡[trans≡trans]-refl {q = q} {r = r} =
cong (λ f → f {q = q} {r = r})
(elim-refl (λ {x y} _ → {q : x ≡ x} {r : y ≡ y} → _) _)
|
{
"alphanum_fraction": 0.3701201201,
"avg_line_length": 26.1176470588,
"ext": "agda",
"hexsha": "f13915f46d54fabf71ab6da84e876e9512118faf",
"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/Issue3960a.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/Issue3960a.agda",
"max_line_length": 61,
"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/Issue3960a.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": 622,
"size": 1332
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly-notationZ where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.FGIdeal
open import Cubical.Algebra.CommRing.QuotientRing
open import Cubical.Algebra.CommRing.Instances.Int
open import Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly
renaming (PolyCommRing to A[X1,···,Xn] ; Poly to A[x1,···,xn])
open import Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly-Quotient
-- Notations for ℤ polynomial rings
ℤ[X] : CommRing ℓ-zero
ℤ[X] = A[X1,···,Xn] ℤCommRing 1
ℤ[x] : Type ℓ-zero
ℤ[x] = fst ℤ[X]
ℤ[X,Y] : CommRing ℓ-zero
ℤ[X,Y] = A[X1,···,Xn] ℤCommRing 2
ℤ[x,y] : Type ℓ-zero
ℤ[x,y] = fst ℤ[X,Y]
ℤ[X,Y,Z] : CommRing ℓ-zero
ℤ[X,Y,Z] = A[X1,···,Xn] ℤCommRing 3
ℤ[x,y,z] : Type ℓ-zero
ℤ[x,y,z] = fst ℤ[X,Y,Z]
ℤ[X1,···,Xn] : (n : ℕ) → CommRing ℓ-zero
ℤ[X1,···,Xn] n = A[X1,···,Xn] ℤCommRing n
ℤ[x1,···,xn] : (n : ℕ) → Type ℓ-zero
ℤ[x1,···,xn] n = fst (ℤ[X1,···,Xn] n)
-- Notation for quotiented ℤ polynomial ring
<X> : FinVec ℤ[x] 1
<X> = <Xkʲ> ℤCommRing 1 0 1
<X²> : FinVec ℤ[x] 1
<X²> = <Xkʲ> ℤCommRing 1 0 2
<X³> : FinVec ℤ[x] 1
<X³> = <Xkʲ> ℤCommRing 1 0 3
<Xᵏ> : (k : ℕ) → FinVec ℤ[x] 1
<Xᵏ> k = <Xkʲ> ℤCommRing 1 0 k
ℤ[X]/X : CommRing ℓ-zero
ℤ[X]/X = A[X1,···,Xn]/<Xkʲ> ℤCommRing 1 0 1
ℤ[x]/x : Type ℓ-zero
ℤ[x]/x = fst ℤ[X]/X
ℤ[X]/X² : CommRing ℓ-zero
ℤ[X]/X² = A[X1,···,Xn]/<Xkʲ> ℤCommRing 1 0 2
ℤ[x]/x² : Type ℓ-zero
ℤ[x]/x² = fst ℤ[X]/X²
ℤ[X]/X³ : CommRing ℓ-zero
ℤ[X]/X³ = A[X1,···,Xn]/<Xkʲ> ℤCommRing 1 0 3
ℤ[x]/x³ : Type ℓ-zero
ℤ[x]/x³ = fst ℤ[X]/X³
ℤ[X1,···,Xn]/<X1,···,Xn> : (n : ℕ) → CommRing ℓ-zero
ℤ[X1,···,Xn]/<X1,···,Xn> n = A[X1,···,Xn]/<X1,···,Xn> ℤCommRing n
ℤ[x1,···,xn]/<x1,···,xn> : (n : ℕ) → Type ℓ-zero
ℤ[x1,···,xn]/<x1,···,xn> n = fst (ℤ[X1,···,Xn]/<X1,···,Xn> n)
-- Warning there is two possible definitions of ℤ[X]
-- they only holds up to a path
ℤ'[X]/X : CommRing ℓ-zero
ℤ'[X]/X = A[X1,···,Xn]/<X1,···,Xn> ℤCommRing 1
-- there is a unification problem that keep pop in up everytime I modify something
-- equivℤ[X] : ℤ'[X]/X ≡ ℤ[X]/X
-- equivℤ[X] = cong₂ _/_ refl (cong (λ X → genIdeal (A[X1,···,Xn] ℤCommRing {!!}) X) {!!})
|
{
"alphanum_fraction": 0.6259198692,
"avg_line_length": 24.7070707071,
"ext": "agda",
"hexsha": "edeb3ebf1eefab1f23a3433937ff6c1b8e1ba6d2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRing/Instances/Polynomials/MultivariatePoly-notationZ.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRing/Instances/Polynomials/MultivariatePoly-notationZ.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRing/Instances/Polynomials/MultivariatePoly-notationZ.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1155,
"size": 2446
}
|
{-# OPTIONS --without-K --safe #-}
-- a categorical (i.e. non-skeletal) version of Lawvere Theory,
-- as per https://ncatlab.org/nlab/show/Lawvere+theory
module Categories.Theory.Lawvere where
open import Data.Nat using (ℕ)
open import Data.Product using (Σ; _,_)
open import Level
open import Categories.Category.Cartesian
open import Categories.Category using (Category; _[_,_])
open import Categories.Category.Instance.Setoids
open import Categories.Category.Monoidal.Instance.Setoids using (Setoids-Cartesian)
open import Categories.Category.Product
open import Categories.Functor using (Functor; _∘F_) renaming (id to idF)
open import Categories.Functor.Cartesian
open import Categories.Functor.Cartesian.Properties
import Categories.Morphism as Mor
open import Categories.NaturalTransformation using (NaturalTransformation)
private
variable
o ℓ e o′ ℓ′ e′ o″ ℓ″ e″ : Level
record FiniteProduct (o ℓ e : Level) : Set (suc (o ⊔ ℓ ⊔ e)) where
field
T : Category o ℓ e
open Mor T
field
cart : Cartesian T
generic : Category.Obj T
open Cartesian cart using (power)
field
obj-iso-to-generic-power : (x : Category.Obj T) → Σ ℕ (λ n → x ≅ power generic n)
record LT-Hom (T₁ : FiniteProduct o ℓ e) (T₂ : FiniteProduct o′ ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
private
module T₁ = FiniteProduct T₁
module T₂ = FiniteProduct T₂
field
F : Functor T₁.T T₂.T
cartF : CartesianF T₁.cart T₂.cart F
LT-id : {A : FiniteProduct o ℓ e} → LT-Hom A A
LT-id = record { F = idF ; cartF = idF-Cartesian }
LT-∘ : {A : FiniteProduct o ℓ e} {B : FiniteProduct o′ ℓ′ e′} {C : FiniteProduct o″ ℓ″ e″} →
LT-Hom B C → LT-Hom A B → LT-Hom A C
LT-∘ G H = record { F = F G ∘F F H ; cartF = ∘-Cartesian (cartF G) (cartF H) }
where open LT-Hom
record T-Algebra (FP : FiniteProduct o ℓ e) : Set (o ⊔ ℓ ⊔ e ⊔ suc (ℓ′ ⊔ e′)) where
private
module FP = FiniteProduct FP
field
Mod : Functor FP.T (Setoids ℓ′ e′)
Cart : CartesianF FP.cart Setoids-Cartesian Mod
|
{
"alphanum_fraction": 0.6875310482,
"avg_line_length": 33,
"ext": "agda",
"hexsha": "664f6f133b0eeb7970fcd33a98e6b11dd17d14d1",
"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": "6cbfdf3f1be15ef513435e3b85faae92cb1ac36f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bond15/agda-categories",
"max_forks_repo_path": "src/Categories/Theory/Lawvere.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6cbfdf3f1be15ef513435e3b85faae92cb1ac36f",
"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": "bond15/agda-categories",
"max_issues_repo_path": "src/Categories/Theory/Lawvere.agda",
"max_line_length": 109,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6cbfdf3f1be15ef513435e3b85faae92cb1ac36f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bond15/agda-categories",
"max_stars_repo_path": "src/Categories/Theory/Lawvere.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 652,
"size": 2013
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Impl.OBM.Rust.Duration as Duration
open import LibraBFT.ImplShared.Consensus.Types.EpochIndep
open import Util.Prelude
module LibraBFT.Impl.OBM.Time where
postulate -- TODO-1 : iPlus, timeT
iPlus : Instant → Duration → Instant
timeT : Instant
|
{
"alphanum_fraction": 0.77582846,
"avg_line_length": 32.0625,
"ext": "agda",
"hexsha": "5db1857ca71d1b91af17e3c9c2fc0eb0af34433b",
"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/OBM/Time.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/OBM/Time.agda",
"max_line_length": 111,
"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/OBM/Time.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 143,
"size": 513
}
|
-- WARNING: This file was generated automatically by Vehicle
-- and should not be modified manually!
-- Metadata
-- - Agda version: 2.6.2
-- - AISEC version: 0.1.0.1
-- - Time generated: ???
{-# OPTIONS --allow-exec #-}
open import Vehicle
open import Vehicle.Data.Tensor
open import Data.Unit
open import Data.Nat as ℕ using (ℕ)
open import Data.Integer as ℤ using (ℤ)
open import Data.Fin as Fin using (Fin; #_)
open import Data.List
open import Relation.Binary.PropositionalEquality
module simple-quantifier-temp-output where
abstract
bool : ∀ (x : ℤ) → ⊤
bool = checkSpecification record
{ proofCache = "/home/matthew/Code/AISEC/vehicle/proofcache.vclp"
}
abstract
expandedExpr : ∀ (x : Tensor ℤ (2 ∷ [])) → x (# 0) ≡ x (# 1)
expandedExpr = checkSpecification record
{ proofCache = "/home/matthew/Code/AISEC/vehicle/proofcache.vclp"
}
abstract
multiple : ∀ (x : ℕ) → ∀ (y : ℕ) → x ≡ y
multiple = checkSpecification record
{ proofCache = "/home/matthew/Code/AISEC/vehicle/proofcache.vclp"
}
|
{
"alphanum_fraction": 0.6829501916,
"avg_line_length": 28.2162162162,
"ext": "agda",
"hexsha": "703952d5a10d6605005fb89cf690aa6952c5c265",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vehicle-lang/vehicle",
"max_forks_repo_path": "test/Test/Compile/Golden/simple-quantifier/simple-quantifier-output.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T20:49:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-07T14:09:13.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vehicle-lang/vehicle",
"max_issues_repo_path": "test/Test/Compile/Golden/simple-quantifier/simple-quantifier-output.agda",
"max_line_length": 71,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vehicle-lang/vehicle",
"max_stars_repo_path": "test/Test/Compile/Golden/simple-quantifier/simple-quantifier-output.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-17T18:51:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-10T12:56:42.000Z",
"num_tokens": 314,
"size": 1044
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Bool where
open import Cubical.Data.Bool.Base public
open import Cubical.Data.Bool.Properties public
|
{
"alphanum_fraction": 0.7643678161,
"avg_line_length": 24.8571428571,
"ext": "agda",
"hexsha": "0fa75086fdf58e90a7acc4415a3656d4eec3ccdd",
"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/Data/Bool.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/Data/Bool.agda",
"max_line_length": 50,
"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/Data/Bool.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 39,
"size": 174
}
|
{-# OPTIONS --safe #-}
module Cubical.Categories.Limits.Limits where
open import Cubical.Foundations.Prelude
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.NaturalTransformation
private
variable
ℓJ ℓJ' ℓC ℓC' : Level
ℓ ℓ' ℓ'' : Level
module _ {J : Category ℓJ ℓJ'}
{C : Category ℓC ℓC'} where
open Category
open Functor
open NatTrans
-- functor which sends all objects to c and all
-- morphisms to the identity
constF : (c : C .ob) → Functor J C
constF c .F-ob _ = c
constF c .F-hom _ = C .id
constF c .F-id = refl
constF c .F-seq _ _ = sym (C .⋆IdL _)
-- a cone is a natural transformation from the constant functor at x to K
Cone : (K : Functor J C) → C .ob → Type _
Cone K x = NatTrans (constF x) K
module _ {K : Functor J C} where
-- precomposes a cone with a morphism
_◼_ : ∀ {d c : C .ob}
→ (f : C [ d , c ])
→ Cone K c
→ Cone K d
(f ◼ μ) .N-ob x = f ⋆⟨ C ⟩ μ ⟦ x ⟧
(f ◼ μ) .N-hom {x = x} {y} k
= C .id ⋆⟨ C ⟩ (f ⋆⟨ C ⟩ μ ⟦ y ⟧)
≡⟨ C .⋆IdL _ ⟩
f ⋆⟨ C ⟩ μ ⟦ y ⟧
≡⟨ cong (λ v → f ⋆⟨ C ⟩ v) (sym (C .⋆IdL _)) ⟩
f ⋆⟨ C ⟩ (C .id ⋆⟨ C ⟩ μ ⟦ y ⟧)
≡⟨ cong (λ v → f ⋆⟨ C ⟩ v) (μ .N-hom k) ⟩
f ⋆⟨ C ⟩ (μ ⟦ x ⟧ ⋆⟨ C ⟩ K ⟪ k ⟫)
≡⟨ sym (C .⋆Assoc _ _ _) ⟩
f ⋆⟨ C ⟩ μ ⟦ x ⟧ ⋆⟨ C ⟩ K ⟪ k ⟫
∎
-- μ factors ν if there's a morphism such that the natural transformation
-- from precomposing it with ν gives you back μ
_factors_ : {u v : C .ob} (μ : Cone K u) (ν : Cone K v) → Type _
_factors_ {u} {v} μ ν = Σ[ mor ∈ C [ v , u ] ] ν ≡ (mor ◼ μ)
-- μ uniquely factors ν if the factor from above is contractible
_uniquelyFactors_ : {u v : C .ob} (μ : Cone K u) (ν : Cone K v) → Type _
_uniquelyFactors_ {u} {v} μ ν = isContr (μ factors ν)
module _ (K : Functor J C) where
-- a Limit is a cone such that all cones are uniquely factored by it
record isLimit (head : C .ob) : Type (ℓ-max (ℓ-max ℓJ ℓJ') (ℓ-max ℓC ℓC')) where
constructor islimit
field
cone : Cone K head
-- TODO: change this to terminal object in category of Cones?
up : ∀ {v} (ν : Cone K v) → cone uniquelyFactors ν
record Limit : Type (ℓ-max (ℓ-max ℓJ ℓJ') (ℓ-max ℓC ℓC')) where
field
head : C .ob
islim : isLimit head
-- a Category is complete if it has all limits
complete' : {ℓJ ℓJ' : Level} (C : Category ℓC ℓC') → Type _
complete' {ℓJ = ℓJ} {ℓJ'} C = (J : Category ℓJ ℓJ') (K : Functor J C) → Limit K
complete : (C : Category ℓC ℓC') → Typeω
complete C = ∀ {ℓJ ℓJ'} → complete' {ℓJ = ℓJ} {ℓJ'} C
|
{
"alphanum_fraction": 0.5511342507,
"avg_line_length": 31.6352941176,
"ext": "agda",
"hexsha": "b96f83d70b939a767c5197b269e7218003acb316",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lpw25/cubical",
"max_forks_repo_path": "Cubical/Categories/Limits/Limits.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "lpw25/cubical",
"max_issues_repo_path": "Cubical/Categories/Limits/Limits.agda",
"max_line_length": 85,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lpw25/cubical",
"max_stars_repo_path": "Cubical/Categories/Limits/Limits.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1093,
"size": 2689
}
|
{-# OPTIONS --cubical --safe #-}
module Algebra.Construct.Free.Semilattice.Relation.Unary.Any.Map where
open import Prelude hiding (⊥; ⊤)
open import Algebra.Construct.Free.Semilattice.Eliminators
open import Algebra.Construct.Free.Semilattice.Definition
open import Cubical.Foundations.HLevels
open import Data.Empty.UniversePolymorphic
open import HITs.PropositionalTruncation.Sugar
open import HITs.PropositionalTruncation.Properties
open import HITs.PropositionalTruncation
open import Data.Unit.UniversePolymorphic
open import Algebra.Construct.Free.Semilattice.Relation.Unary.Any.Def
open import Algebra.Construct.Free.Semilattice.Relation.Unary.Membership
private
variable p : Level
variable P : A → Type p
-- map-◇-fn : ∀ x → P x → ∀ y xs → (x ∈ xs → ◇ P xs) → (y ≡ x) ⊎ (x ∈ xs) → ◇ P (y ∷ xs)
-- map-◇-fn {P = P} x Px y xs k (inl y≡x) = ∣ inl (subst P (sym y≡x) Px) ∣
-- map-◇-fn x Px y xs k (inr x∈xs) = ∣ inr (k x∈xs) ∣
-- map-◇-prop : ∀ (x : A) {xs} → isProp (x ∈ xs → ◇ P xs)
-- map-◇-prop {P = P} x {xs} p q i x∈xs = ◇′ P xs .snd (p x∈xs) (q x∈xs) i
-- map-◇ : ∀ (x : A) → P x → (xs : 𝒦 A) → x ∈ xs → ◇ P xs
-- map-◇ {A = A} {P = P} x Px =
-- 𝒦-elim-prop {A = A} {P = λ ys → x ∈ ys → ◇ P ys}
-- (map-◇-prop {A = A} {P = P} x)
-- (λ y xs Pxs → recPropTrunc squash (map-◇-fn x Px y xs Pxs))
-- (λ ())
|
{
"alphanum_fraction": 0.630044843,
"avg_line_length": 39.3529411765,
"ext": "agda",
"hexsha": "b5069ca349f9578745213db38bc5b98657c2543d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Algebra/Construct/Free/Semilattice/Relation/Unary/Any/Map.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/Algebra/Construct/Free/Semilattice/Relation/Unary/Any/Map.agda",
"max_line_length": 88,
"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/Algebra/Construct/Free/Semilattice/Relation/Unary/Any/Map.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": 526,
"size": 1338
}
|
open import Prelude
module Implicits.Substitutions.Lemmas.Type where
open import Implicits.Syntax.Type
open import Implicits.Substitutions
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
open import Data.Vec.Properties
open import Extensions.Substitution
open import Data.Star using (Star; ε; _◅_)
open import Data.Product hiding (map)
typeLemmas : TermLemmas Type
typeLemmas = record { termSubst = TypeSubst.typeSubst; app-var = refl ; /✶-↑✶ = Lemma./✶-↑✶ }
where
open TypeSubst
module Lemma {T₁ T₂} {lift₁ : Lift T₁ Type} {lift₂ : Lift T₂ Type} where
open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_)
open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_)
/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → (simpl (tvar x)) /✶₁ σs₁ ↑✶₁ k ≡ (simpl (tvar x)) /✶₂ σs₂ ↑✶₂ k) →
∀ k t → t /✶₁ σs₁ ↑✶₁ k ≡ t /✶₂ σs₂ ↑✶₂ k
/✶-↑✶ ρs₁ ρs₂ hyp k (simpl (tvar x)) = hyp k x
/✶-↑✶ ρs₁ ρs₂ hyp k (simpl (tc c)) = begin
(simpl $ tc c) /✶₁ ρs₁ ↑✶₁ k
≡⟨ TypeApp.tc-/✶-↑✶ _ k ρs₁ ⟩
(simpl $ tc c)
≡⟨ sym $ TypeApp.tc-/✶-↑✶ _ k ρs₂ ⟩
(simpl $ tc c) /✶₂ ρs₂ ↑✶₂ k ∎
/✶-↑✶ ρs₁ ρs₂ hyp k (simpl (a →' b)) = begin
(simpl $ a →' b) /✶₁ ρs₁ ↑✶₁ k
≡⟨ TypeApp.→'-/✶-↑✶ _ k ρs₁ ⟩
simpl ((a /✶₁ ρs₁ ↑✶₁ k) →' (b /✶₁ ρs₁ ↑✶₁ k))
≡⟨ cong₂ (λ a b → simpl (a →' b)) (/✶-↑✶ ρs₁ ρs₂ hyp k a) (/✶-↑✶ ρs₁ ρs₂ hyp k b) ⟩
simpl ((a /✶₂ ρs₂ ↑✶₂ k) →' (b /✶₂ ρs₂ ↑✶₂ k))
≡⟨ sym (TypeApp.→'-/✶-↑✶ _ k ρs₂) ⟩
(simpl $ a →' b) /✶₂ ρs₂ ↑✶₂ k
∎
/✶-↑✶ ρs₁ ρs₂ hyp k (a ⇒ b) = begin
(a ⇒ b) /✶₁ ρs₁ ↑✶₁ k
≡⟨ TypeApp.⇒-/✶-↑✶ _ k ρs₁ ⟩ --
(a /✶₁ ρs₁ ↑✶₁ k) ⇒ (b /✶₁ ρs₁ ↑✶₁ k)
≡⟨ cong₂ _⇒_ (/✶-↑✶ ρs₁ ρs₂ hyp k a) (/✶-↑✶ ρs₁ ρs₂ hyp k b) ⟩
(a /✶₂ ρs₂ ↑✶₂ k) ⇒ (b /✶₂ ρs₂ ↑✶₂ k)
≡⟨ sym (TypeApp.⇒-/✶-↑✶ _ k ρs₂) ⟩
(a ⇒ b) /✶₂ ρs₂ ↑✶₂ k
∎
/✶-↑✶ ρs₁ ρs₂ hyp k (∀' a) = begin
(∀' a) /✶₁ ρs₁ ↑✶₁ k
≡⟨ TypeApp.∀'-/✶-↑✶ _ k ρs₁ ⟩
∀' (a /✶₁ ρs₁ ↑✶₁ (suc k))
≡⟨ cong ∀' (/✶-↑✶ ρs₁ ρs₂ hyp (suc k) a) ⟩
∀' (a /✶₂ ρs₂ ↑✶₂ (suc k))
≡⟨ sym (TypeApp.∀'-/✶-↑✶ _ k ρs₂) ⟩
(∀' a) /✶₂ ρs₂ ↑✶₂ k
∎
open TermLemmas typeLemmas public hiding (var; id)
open AdditionalLemmas typeLemmas public
open TypeSubst using (module Lifted)
-- The above lemma /✶-↑✶ specialized to single substitutions
/-↑⋆ : ∀ {T₁ T₂} {lift₁ : Lift T₁ Type} {lift₂ : Lift T₂ Type} →
let open Lifted lift₁ using () renaming (_↑⋆_ to _↑⋆₁_; _/_ to _/₁_)
open Lifted lift₂ using () renaming (_↑⋆_ to _↑⋆₂_; _/_ to _/₂_)
in
∀ {n k} (ρ₁ : Sub T₁ n k) (ρ₂ : Sub T₂ n k) →
(∀ i x → (simpl (tvar x)) /₁ ρ₁ ↑⋆₁ i ≡ (simpl (tvar x)) /₂ ρ₂ ↑⋆₂ i) →
∀ i a → a /₁ ρ₁ ↑⋆₁ i ≡ a /₂ ρ₂ ↑⋆₂ i
/-↑⋆ ρ₁ ρ₂ hyp i a = /✶-↑✶ (ρ₁ ◅ ε) (ρ₂ ◅ ε) hyp i a
-- weakening a simple type gives a simple type
simpl-wk : ∀ {ν} k (τ : SimpleType (k + ν)) → ∃ λ τ' → (simpl τ) / wk ↑⋆ k ≡ simpl τ'
simpl-wk k (tc x) = , refl
simpl-wk k (tvar n) = , var-/-wk-↑⋆ k n
simpl-wk k (x →' x₁) = , refl
|
{
"alphanum_fraction": 0.4809160305,
"avg_line_length": 40.4320987654,
"ext": "agda",
"hexsha": "acafd68497036b1ce53c1185d5854984f6eb8160",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Substitutions/Lemmas/Type.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Substitutions/Lemmas/Type.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/Substitutions/Lemmas/Type.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": 1659,
"size": 3275
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Coinductive lists
------------------------------------------------------------------------
{-# OPTIONS --without-K --sized-types --guardedness #-}
module Codata.Musical.Colist where
open import Category.Monad
open import Codata.Musical.Notation
open import Codata.Musical.Conat using (Coℕ; zero; suc)
open import Data.Bool.Base using (Bool; true; false)
open import Data.BoundedVec.Inefficient as BVec
using (BoundedVec; []; _∷_)
open import Data.Empty using (⊥)
open import Data.Maybe using (Maybe; nothing; just; Is-just)
open import Data.Maybe.Relation.Unary.Any using (just)
open import Data.Nat.Base using (ℕ; zero; suc; _≥′_; ≤′-refl; ≤′-step)
open import Data.Nat.Properties using (s≤′s)
open import Data.List.Base using (List; []; _∷_)
open import Data.List.NonEmpty using (List⁺; _∷_)
open import Data.Product as Prod using (∃; _×_; _,_)
open import Data.Sum as Sum using (_⊎_; inj₁; inj₂; [_,_]′)
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as Inv using (_↔_; _↔̇_; Inverse; inverse)
open import Level using (_⊔_)
open import Relation.Binary
import Relation.Binary.Construct.FromRel as Ind
import Relation.Binary.Reasoning.Preorder as PreR
import Relation.Binary.Reasoning.PartialOrder as POR
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary
open import Relation.Nullary.Negation
module ¬¬Monad {p} where
open RawMonad (¬¬-Monad {p}) public
open ¬¬Monad -- we don't want the RawMonad content to be opened publicly
------------------------------------------------------------------------
-- The type
infixr 5 _∷_
data Colist {a} (A : Set a) : Set a where
[] : Colist A
_∷_ : (x : A) (xs : ∞ (Colist A)) → Colist A
{-# FOREIGN GHC
data AgdaColist a = Nil | Cons a (MAlonzo.RTE.Inf (AgdaColist a))
type AgdaColist' l a = AgdaColist a
#-}
{-# COMPILE GHC Colist = data AgdaColist' (Nil | Cons) #-}
{-# COMPILE UHC Colist = data __LIST__ (__NIL__ | __CONS__) #-}
module Colist-injective {a} {A : Set a} where
∷-injectiveˡ : ∀ {x y : A} {xs ys} → (Colist A ∋ x ∷ xs) ≡ y ∷ ys → x ≡ y
∷-injectiveˡ P.refl = P.refl
∷-injectiveʳ : ∀ {x y : A} {xs ys} → (Colist A ∋ x ∷ xs) ≡ y ∷ ys → xs ≡ ys
∷-injectiveʳ P.refl = P.refl
data Any {a p} {A : Set a} (P : A → Set p) :
Colist A → Set (a ⊔ p) where
here : ∀ {x xs} (px : P x) → Any P (x ∷ xs)
there : ∀ {x xs} (pxs : Any P (♭ xs)) → Any P (x ∷ xs)
module _ {a p} {A : Set a} {P : A → Set p} where
here-injective : ∀ {x xs p q} → (Any P (x ∷ xs) ∋ here p) ≡ here q → p ≡ q
here-injective P.refl = P.refl
there-injective : ∀ {x xs p q} → (Any P (x ∷ xs) ∋ there p) ≡ there q → p ≡ q
there-injective P.refl = P.refl
data All {a p} {A : Set a} (P : A → Set p) :
Colist A → Set (a ⊔ p) where
[] : All P []
_∷_ : ∀ {x xs} (px : P x) (pxs : ∞ (All P (♭ xs))) → All P (x ∷ xs)
module All-injective {a p} {A : Set a} {P : A → Set p} where
∷-injectiveˡ : ∀ {x xs} {px qx pxs qxs} →
(All P (x ∷ xs) ∋ px ∷ pxs) ≡ qx ∷ qxs → px ≡ qx
∷-injectiveˡ P.refl = P.refl
∷-injectiveʳ : ∀ {x xs} {px qx pxs qxs} →
(All P (x ∷ xs) ∋ px ∷ pxs) ≡ qx ∷ qxs → pxs ≡ qxs
∷-injectiveʳ P.refl = P.refl
------------------------------------------------------------------------
-- Some operations
null : ∀ {a} {A : Set a} → Colist A → Bool
null [] = true
null (_ ∷ _) = false
length : ∀ {a} {A : Set a} → Colist A → Coℕ
length [] = zero
length (x ∷ xs) = suc (♯ length (♭ xs))
map : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → Colist A → Colist B
map f [] = []
map f (x ∷ xs) = f x ∷ ♯ map f (♭ xs)
fromList : ∀ {a} {A : Set a} → List A → Colist A
fromList [] = []
fromList (x ∷ xs) = x ∷ ♯ fromList xs
take : ∀ {a} {A : Set a} (n : ℕ) → Colist A → BoundedVec A n
take zero xs = []
take (suc n) [] = []
take (suc n) (x ∷ xs) = x ∷ take n (♭ xs)
replicate : ∀ {a} {A : Set a} → Coℕ → A → Colist A
replicate zero x = []
replicate (suc n) x = x ∷ ♯ replicate (♭ n) x
lookup : ∀ {a} {A : Set a} → ℕ → Colist A → Maybe A
lookup n [] = nothing
lookup zero (x ∷ xs) = just x
lookup (suc n) (x ∷ xs) = lookup n (♭ xs)
infixr 5 _++_
_++_ : ∀ {a} {A : Set a} → Colist A → Colist A → Colist A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ ♯ (♭ xs ++ ys)
-- Interleaves the two colists (until the shorter one, if any, has
-- been exhausted).
infixr 5 _⋎_
_⋎_ : ∀ {a} {A : Set a} → Colist A → Colist A → Colist A
[] ⋎ ys = ys
(x ∷ xs) ⋎ ys = x ∷ ♯ (ys ⋎ ♭ xs)
concat : ∀ {a} {A : Set a} → Colist (List⁺ A) → Colist A
concat [] = []
concat ((x ∷ []) ∷ xss) = x ∷ ♯ concat (♭ xss)
concat ((x ∷ (y ∷ xs)) ∷ xss) = x ∷ ♯ concat ((y ∷ xs) ∷ xss)
[_] : ∀ {a} {A : Set a} → A → Colist A
[ x ] = x ∷ ♯ []
------------------------------------------------------------------------
-- Any lemmas
-- Any lemma for map.
Any-map : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p}
{f : A → B} {xs} →
Any P (map f xs) ↔ Any (P ∘ f) xs
Any-map {P = P} {f} {xs} = inverse to from from∘to to∘from
where
to : ∀ {xs} → Any P (map f xs) → Any (P ∘ f) xs
to {[]} ()
to {x ∷ xs} (here px) = here px
to {x ∷ xs} (there p) = there (to p)
from : ∀ {xs} → Any (P ∘ f) xs → Any P (map f xs)
from (here px) = here px
from (there p) = there (from p)
from∘to : ∀ {xs} (p : Any P (map f xs)) → from (to p) ≡ p
from∘to {[]} ()
from∘to {x ∷ xs} (here px) = P.refl
from∘to {x ∷ xs} (there p) = P.cong there (from∘to p)
to∘from : ∀ {xs} (p : Any (P ∘ f) xs) → to (from p) ≡ p
to∘from (here px) = P.refl
to∘from (there p) = P.cong there (to∘from p)
-- Any lemma for _⋎_. This lemma implies that every member of xs or ys
-- is a member of xs ⋎ ys, and vice versa.
Any-⋎ : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} →
Any P (xs ⋎ ys) ↔ (Any P xs ⊎ Any P ys)
Any-⋎ {P = P} = λ xs → record
{ to = P.→-to-⟶ (to xs)
; from = P.→-to-⟶ (from xs)
; inverse-of = record
{ left-inverse-of = from∘to xs
; right-inverse-of = to∘from xs
}
}
where
to : ∀ xs {ys} → Any P (xs ⋎ ys) → Any P xs ⊎ Any P ys
to [] p = inj₂ p
to (x ∷ xs) (here px) = inj₁ (here px)
to (x ∷ xs) (there p) = [ inj₂ , inj₁ ∘ there ]′ (to _ p)
mutual
from-left : ∀ {xs ys} → Any P xs → Any P (xs ⋎ ys)
from-left (here px) = here px
from-left {ys = ys} (there p) = there (from-right ys p)
from-right : ∀ xs {ys} → Any P ys → Any P (xs ⋎ ys)
from-right [] p = p
from-right (x ∷ xs) p = there (from-left p)
from : ∀ xs {ys} → Any P xs ⊎ Any P ys → Any P (xs ⋎ ys)
from xs = Sum.[ from-left , from-right xs ]
from∘to : ∀ xs {ys} (p : Any P (xs ⋎ ys)) → from xs (to xs p) ≡ p
from∘to [] p = P.refl
from∘to (x ∷ xs) (here px) = P.refl
from∘to (x ∷ xs) {ys = ys} (there p) with to ys p | from∘to ys p
from∘to (x ∷ xs) {ys = ys} (there .(from-left q)) | inj₁ q | P.refl = P.refl
from∘to (x ∷ xs) {ys = ys} (there .(from-right ys q)) | inj₂ q | P.refl = P.refl
mutual
to∘from-left : ∀ {xs ys} (p : Any P xs) →
to xs {ys = ys} (from-left p) ≡ inj₁ p
to∘from-left (here px) = P.refl
to∘from-left {ys = ys} (there p)
rewrite to∘from-right ys p = P.refl
to∘from-right : ∀ xs {ys} (p : Any P ys) →
to xs (from-right xs p) ≡ inj₂ p
to∘from-right [] p = P.refl
to∘from-right (x ∷ xs) {ys = ys} p
rewrite to∘from-left {xs = ys} {ys = ♭ xs} p = P.refl
to∘from : ∀ xs {ys} (p : Any P xs ⊎ Any P ys) → to xs (from xs p) ≡ p
to∘from xs = Sum.[ to∘from-left , to∘from-right xs ]
------------------------------------------------------------------------
-- Equality
-- xs ≈ ys means that xs and ys are equal.
infix 4 _≈_
data _≈_ {a} {A : Set a} : (xs ys : Colist A) → Set a where
[] : [] ≈ []
_∷_ : ∀ x {xs ys} (xs≈ : ∞ (♭ xs ≈ ♭ ys)) → x ∷ xs ≈ x ∷ ys
-- The equality relation forms a setoid.
setoid : ∀ {ℓ} → Set ℓ → Setoid _ _
setoid A = record
{ Carrier = Colist A
; _≈_ = _≈_
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
}
where
refl : Reflexive _≈_
refl {[]} = []
refl {x ∷ xs} = x ∷ ♯ refl
sym : Symmetric _≈_
sym [] = []
sym (x ∷ xs≈) = x ∷ ♯ sym (♭ xs≈)
trans : Transitive _≈_
trans [] [] = []
trans (x ∷ xs≈) (.x ∷ ys≈) = x ∷ ♯ trans (♭ xs≈) (♭ ys≈)
module ≈-Reasoning where
import Relation.Binary.Reasoning.Setoid as EqR
private
open module R {a} {A : Set a} = EqR (setoid A) public
-- map preserves equality.
map-cong : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B) → _≈_ =[ map f ]⇒ _≈_
map-cong f [] = []
map-cong f (x ∷ xs≈) = f x ∷ ♯ map-cong f (♭ xs≈)
-- Any respects pointwise implication (for the predicate) and equality
-- (for the colist).
Any-resp : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q}
{xs ys} → (∀ {x} → P x → Q x) → xs ≈ ys →
Any P xs → Any Q ys
Any-resp f (x ∷ xs≈) (here px) = here (f px)
Any-resp f (x ∷ xs≈) (there p) = there (Any-resp f (♭ xs≈) p)
-- Any maps pointwise isomorphic predicates and equal colists to
-- isomorphic types.
Any-cong : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q}
{xs ys} → P ↔̇ Q → xs ≈ ys → Any P xs ↔ Any Q ys
Any-cong {A = A} {P} {Q} {xs} {ys} P↔Q = λ xs≈ys → record
{ to = P.→-to-⟶ (to xs≈ys)
; from = P.→-to-⟶ (from xs≈ys)
; inverse-of = record
{ left-inverse-of = from∘to _
; right-inverse-of = to∘from _
}
}
where
open Setoid (setoid _) using (sym)
to : ∀ {xs ys} → xs ≈ ys → Any P xs → Any Q ys
to xs≈ys = Any-resp (Inverse.to P↔Q ⟨$⟩_) xs≈ys
from : ∀ {xs ys} → xs ≈ ys → Any Q ys → Any P xs
from xs≈ys = Any-resp (Inverse.from P↔Q ⟨$⟩_) (sym xs≈ys)
to∘from : ∀ {xs ys} (xs≈ys : xs ≈ ys) (q : Any Q ys) →
to xs≈ys (from xs≈ys q) ≡ q
to∘from (x ∷ xs≈) (there q) = P.cong there (to∘from (♭ xs≈) q)
to∘from (x ∷ xs≈) (here qx) =
P.cong here (Inverse.right-inverse-of P↔Q qx)
from∘to : ∀ {xs ys} (xs≈ys : xs ≈ ys) (p : Any P xs) →
from xs≈ys (to xs≈ys p) ≡ p
from∘to (x ∷ xs≈) (there p) = P.cong there (from∘to (♭ xs≈) p)
from∘to (x ∷ xs≈) (here px) =
P.cong here (Inverse.left-inverse-of P↔Q px)
------------------------------------------------------------------------
-- Indices
-- Converts Any proofs to indices into the colist. The index can also
-- be seen as the size of the proof.
index : ∀ {a p} {A : Set a} {P : A → Set p} {xs} → Any P xs → ℕ
index (here px) = zero
index (there p) = suc (index p)
-- The position returned by index is guaranteed to be within bounds.
lookup-index : ∀ {a p} {A : Set a} {P : A → Set p} {xs} (p : Any P xs) →
Is-just (lookup (index p) xs)
lookup-index (here px) = just _
lookup-index (there p) = lookup-index p
-- Any-resp preserves the index.
index-Any-resp :
∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q}
{f : ∀ {x} → P x → Q x} {xs ys}
(xs≈ys : xs ≈ ys) (p : Any P xs) →
index (Any-resp f xs≈ys p) ≡ index p
index-Any-resp (x ∷ xs≈) (here px) = P.refl
index-Any-resp (x ∷ xs≈) (there p) =
P.cong suc (index-Any-resp (♭ xs≈) p)
-- The left-to-right direction of Any-⋎ returns a proof whose size is
-- no larger than that of the input proof.
index-Any-⋎ :
∀ {a p} {A : Set a} {P : A → Set p} xs {ys} (p : Any P (xs ⋎ ys)) →
index p ≥′ [ index , index ]′ (Inverse.to (Any-⋎ xs) ⟨$⟩ p)
index-Any-⋎ [] p = ≤′-refl
index-Any-⋎ (x ∷ xs) (here px) = ≤′-refl
index-Any-⋎ (x ∷ xs) {ys = ys} (there p)
with Inverse.to (Any-⋎ ys) ⟨$⟩ p | index-Any-⋎ ys p
... | inj₁ q | q≤p = ≤′-step q≤p
... | inj₂ q | q≤p = s≤′s q≤p
------------------------------------------------------------------------
-- Memberships, subsets, prefixes
-- x ∈ xs means that x is a member of xs.
infix 4 _∈_
_∈_ : ∀ {a} → {A : Set a} → A → Colist A → Set a
x ∈ xs = Any (_≡_ x) xs
-- xs ⊆ ys means that xs is a subset of ys.
infix 4 _⊆_
_⊆_ : ∀ {a} → {A : Set a} → Colist A → Colist A → Set a
xs ⊆ ys = ∀ {x} → x ∈ xs → x ∈ ys
-- xs ⊑ ys means that xs is a prefix of ys.
infix 4 _⊑_
data _⊑_ {a} {A : Set a} : Colist A → Colist A → Set a where
[] : ∀ {ys} → [] ⊑ ys
_∷_ : ∀ x {xs ys} (p : ∞ (♭ xs ⊑ ♭ ys)) → x ∷ xs ⊑ x ∷ ys
-- Any can be expressed using _∈_ (and vice versa).
Any-∈ : ∀ {a p} {A : Set a} {P : A → Set p} {xs} →
Any P xs ↔ ∃ λ x → x ∈ xs × P x
Any-∈ {P = P} = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ (λ { (x , x∈xs , p) → from x∈xs p })
; inverse-of = record
{ left-inverse-of = from∘to
; right-inverse-of = λ { (x , x∈xs , p) → to∘from x∈xs p }
}
}
where
to : ∀ {xs} → Any P xs → ∃ λ x → x ∈ xs × P x
to (here p) = _ , here P.refl , p
to (there p) = Prod.map id (Prod.map there id) (to p)
from : ∀ {x xs} → x ∈ xs → P x → Any P xs
from (here P.refl) p = here p
from (there x∈xs) p = there (from x∈xs p)
to∘from : ∀ {x xs} (x∈xs : x ∈ xs) (p : P x) →
to (from x∈xs p) ≡ (x , x∈xs , p)
to∘from (here P.refl) p = P.refl
to∘from (there x∈xs) p =
P.cong (Prod.map id (Prod.map there id)) (to∘from x∈xs p)
from∘to : ∀ {xs} (p : Any P xs) →
let (x , x∈xs , px) = to p in from x∈xs px ≡ p
from∘to (here _) = P.refl
from∘to (there p) = P.cong there (from∘to p)
-- Prefixes are subsets.
⊑⇒⊆ : ∀ {a} → {A : Set a} → _⊑_ {A = A} ⇒ _⊆_
⊑⇒⊆ [] ()
⊑⇒⊆ (x ∷ xs⊑ys) (here ≡x) = here ≡x
⊑⇒⊆ (_ ∷ xs⊑ys) (there x∈xs) = there (⊑⇒⊆ (♭ xs⊑ys) x∈xs)
-- The prefix relation forms a poset.
⊑-Poset : ∀ {ℓ} → Set ℓ → Poset _ _ _
⊑-Poset A = record
{ Carrier = Colist A
; _≈_ = _≈_
; _≤_ = _⊑_
; isPartialOrder = record
{ isPreorder = record
{ isEquivalence = Setoid.isEquivalence (setoid A)
; reflexive = reflexive
; trans = trans
}
; antisym = antisym
}
}
where
reflexive : _≈_ ⇒ _⊑_
reflexive [] = []
reflexive (x ∷ xs≈) = x ∷ ♯ reflexive (♭ xs≈)
trans : Transitive _⊑_
trans [] _ = []
trans (x ∷ xs≈) (.x ∷ ys≈) = x ∷ ♯ trans (♭ xs≈) (♭ ys≈)
tail : ∀ {x xs y ys} → x ∷ xs ⊑ y ∷ ys → ♭ xs ⊑ ♭ ys
tail (_ ∷ p) = ♭ p
antisym : Antisymmetric _≈_ _⊑_
antisym [] [] = []
antisym (x ∷ p₁) p₂ = x ∷ ♯ antisym (♭ p₁) (tail p₂)
module ⊑-Reasoning where
private
open module R {a} {A : Set a} = POR (⊑-Poset A)
public renaming (_≤⟨_⟩_ to _⊑⟨_⟩_)
-- The subset relation forms a preorder.
⊆-Preorder : ∀ {ℓ} → Set ℓ → Preorder _ _ _
⊆-Preorder A = Ind.preorder (setoid A) _∈_
(λ xs≈ys → ⊑⇒⊆ (⊑P.reflexive xs≈ys))
where module ⊑P = Poset (⊑-Poset A)
module ⊆-Reasoning where
private
open module R {a} {A : Set a} = PreR (⊆-Preorder A)
public renaming (_∼⟨_⟩_ to _⊆⟨_⟩_)
infix 1 _∈⟨_⟩_
_∈⟨_⟩_ : ∀ {a} {A : Set a} (x : A) {xs ys} →
x ∈ xs → xs IsRelatedTo ys → x ∈ ys
x ∈⟨ x∈xs ⟩ xs⊆ys = (begin xs⊆ys) x∈xs
-- take returns a prefix.
take-⊑ : ∀ {a} {A : Set a} n (xs : Colist A) →
let toColist = fromList {a} ∘ BVec.toList in
toColist (take n xs) ⊑ xs
take-⊑ zero xs = []
take-⊑ (suc n) [] = []
take-⊑ (suc n) (x ∷ xs) = x ∷ ♯ take-⊑ n (♭ xs)
------------------------------------------------------------------------
-- Finiteness and infiniteness
-- Finite xs means that xs has finite length.
data Finite {a} {A : Set a} : Colist A → Set a where
[] : Finite []
_∷_ : ∀ x {xs} (fin : Finite (♭ xs)) → Finite (x ∷ xs)
module Finite-injective {a} {A : Set a} where
∷-injective : ∀ {x : A} {xs p q} → (Finite (x ∷ xs) ∋ x ∷ p) ≡ x ∷ q → p ≡ q
∷-injective P.refl = P.refl
-- Infinite xs means that xs has infinite length.
data Infinite {a} {A : Set a} : Colist A → Set a where
_∷_ : ∀ x {xs} (inf : ∞ (Infinite (♭ xs))) → Infinite (x ∷ xs)
module Infinite-injective {a} {A : Set a} where
∷-injective : ∀ {x : A} {xs p q} → (Infinite (x ∷ xs) ∋ x ∷ p) ≡ x ∷ q → p ≡ q
∷-injective P.refl = P.refl
-- Colists which are not finite are infinite.
not-finite-is-infinite :
∀ {a} {A : Set a} (xs : Colist A) → ¬ Finite xs → Infinite xs
not-finite-is-infinite [] hyp with hyp []
... | ()
not-finite-is-infinite (x ∷ xs) hyp =
x ∷ ♯ not-finite-is-infinite (♭ xs) (hyp ∘ _∷_ x)
-- Colists are either finite or infinite (classically).
finite-or-infinite :
∀ {a} {A : Set a} (xs : Colist A) → ¬ ¬ (Finite xs ⊎ Infinite xs)
finite-or-infinite xs = helper <$> excluded-middle
where
helper : Dec (Finite xs) → Finite xs ⊎ Infinite xs
helper (yes fin) = inj₁ fin
helper (no ¬fin) = inj₂ $ not-finite-is-infinite xs ¬fin
-- Colists are not both finite and infinite.
not-finite-and-infinite :
∀ {a} {A : Set a} {xs : Colist A} → Finite xs → Infinite xs → ⊥
not-finite-and-infinite [] ()
not-finite-and-infinite (x ∷ fin) (.x ∷ inf) =
not-finite-and-infinite fin (♭ inf)
------------------------------------------------------------------------
-- Legacy
import Codata.Colist as C
open import Codata.Thunk
import Size
module _ {a} {A : Set a} where
fromMusical : ∀ {i} → Colist A → C.Colist A i
fromMusical [] = C.[]
fromMusical (x ∷ xs) = x C.∷ λ where .force → fromMusical (♭ xs)
toMusical : C.Colist A Size.∞ → Colist A
toMusical C.[] = []
toMusical (x C.∷ xs) = x ∷ ♯ toMusical (xs .force)
|
{
"alphanum_fraction": 0.5011256191,
"avg_line_length": 31.6720142602,
"ext": "agda",
"hexsha": "6102f519b4b68e0c3dbd7c4303900cb8e0abebb1",
"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/Codata/Musical/Colist.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/Colist.agda",
"max_line_length": 83,
"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/Codata/Musical/Colist.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7053,
"size": 17768
}
|
data ⊥ : Set where
data Maybe : Set where
just : ⊥ → Maybe
nothing : Maybe
test : Set → Set
test x with nothing
test x | just ()
test x | nothing = test x
|
{
"alphanum_fraction": 0.6335403727,
"avg_line_length": 14.6363636364,
"ext": "agda",
"hexsha": "5e45ae12b939d0d04313f8a61154fe0098f26620",
"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/Issue2583.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/Issue2583.agda",
"max_line_length": 25,
"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/Issue2583.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": 50,
"size": 161
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.