Search is not available for this dataset
text
string | meta
dict |
---|---|
module Natural where
open import Equality
open import Cubical.Data.Nat.Properties public
open import Data.Empty
open import Data.Nat as ℕ public hiding (_+_; _*_; _^_)
open import Data.Nat.Properties public hiding (+-assoc; +-suc)
open import Data.Unit
open import Function
open import Syntax
instance
ℕ-plus-syntax : plus-syntax-simple ℕ ℕ ℕ
ℕ-plus-syntax = record { _+_ = ℕ._+_ }
ℕ-times-syntax : times-syntax-simple ℕ ℕ ℕ
ℕ-times-syntax = record { _*_ = ℕ._*_ }
ℕ-raise-syntax : raise-syntax-simple ℕ ℕ ℕ
ℕ-raise-syntax = record { _^_ = ℕ._^_ }
+-cross : (a b c d : ℕ) → (a + b) + (c + d) ≡ (a + c) + (b + d)
+-cross a b c d =
(a + b) + (c + d)
≡⟨ sym (+-assoc a _ _) ⟩
a + (b + (c + d))
≡⟨ cong (a +_) (+-assoc b _ _) ⟩
a + ((b + c) + d)
≡⟨ cong (a +_) (cong (_+ d) ⟨ +-comm b c ⟩) ⟩
a + ((c + b) + d)
≡⟨ cong (a +_) (sym (+-assoc c _ _)) ⟩
a + (c + (b + d))
≡⟨ +-assoc a _ _ ⟩
(a + c) + (b + d)
∎
instance
ℕ-Number : Number ℕ
ℕ-Number = record { Constraint = λ _ → ⊤ ; fromNat = λ x → x }
| {
"alphanum_fraction": 0.5494296578,
"avg_line_length": 26.3,
"ext": "agda",
"hexsha": "c0ef3ecc382b2247538959f708d59fea07ca8fc2",
"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": "67ea7b96228c592daf79e800ebe4a7c12ed7221e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kcsmnt0/numbers",
"max_forks_repo_path": "src/Natural.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "67ea7b96228c592daf79e800ebe4a7c12ed7221e",
"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": "kcsmnt0/numbers",
"max_issues_repo_path": "src/Natural.agda",
"max_line_length": 64,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "67ea7b96228c592daf79e800ebe4a7c12ed7221e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kcsmnt0/numbers",
"max_stars_repo_path": "src/Natural.agda",
"max_stars_repo_stars_event_max_datetime": "2020-01-16T07:16:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-05-20T01:29:41.000Z",
"num_tokens": 399,
"size": 1052
} |
{-# OPTIONS --universe-polymorphism #-}
module Issue286 where
open import Common.Level
data Bool : Set where
true false : Bool
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
data _≡_ {ℓ : Level} {A : Set ℓ} : A → A → Set ℓ where
refl : {a : A} → a ≡ a
{-# BUILTIN EQUALITY _≡_ #-}
primitive
primEraseEquality : ∀ {a} {A : Set a} {x y : A} → x ≡ y → x ≡ y
{-# BUILTIN STRING String #-}
primitive
primStringEquality : String → String → Bool
data Maybe (A : Set) : Set where
just : A → Maybe A
nothing : Maybe A
_≟_ : (s₁ s₂ : String) → Maybe (s₁ ≡ s₂)
s₁ ≟ s₂ with primStringEquality s₁ s₂
... | true = just (primEraseEquality trustMe)
where postulate trustMe : _ ≡ _
... | false = nothing
_≟′_ : (s₁ s₂ : String) → Maybe (s₁ ≡ s₂)
s₁ ≟′ s₂ with s₁ ≟ s₂
s ≟′ .s | just refl = just refl
_ ≟′ _ | nothing = nothing
test : Maybe ("" ≡ "")
test = "" ≟′ ""
ok : test ≡ just refl
ok = refl
| {
"alphanum_fraction": 0.5851619645,
"avg_line_length": 20.3617021277,
"ext": "agda",
"hexsha": "03b5f493d6768cb91346a6c499d81ad58c483516",
"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": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "bennn/agda",
"max_forks_repo_path": "test/Succeed/Issue286.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"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": "bennn/agda",
"max_issues_repo_path": "test/Succeed/Issue286.agda",
"max_line_length": 65,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "bennn/agda",
"max_stars_repo_path": "test/Succeed/Issue286.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 348,
"size": 957
} |
{-# OPTIONS -v5 #-}
module Debug where
postulate Foo : Set
| {
"alphanum_fraction": 0.6557377049,
"avg_line_length": 10.1666666667,
"ext": "agda",
"hexsha": "6f4c71765fe80e3b655a6c23112ecb3644b2f565",
"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/Debug.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/Debug.agda",
"max_line_length": 19,
"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/Debug.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": 16,
"size": 61
} |
{-# OPTIONS --cubical --no-exact-split --safe #-}
module Cubical.Data.Queue.Base where
open import Cubical.Foundations.Everything
open import Cubical.Foundations.SIP
open import Cubical.Structures.Queue
open import Cubical.Data.Unit
open import Cubical.Data.Sum
open import Cubical.Data.List
open import Cubical.Data.Prod.Base hiding (_×_) renaming (_×Σ_ to _×_)
module _ (A : Type ℓ) (Aset : isSet A) where
open Queues-on A Aset
-- following Cavallo we can now define 1Lists and 2Lists as Queues on A
-- and prove that there is a queue-iso between them, this then gives us a path
1List : Queue
1List = (Q , emp , push , pop)
where
Q = List A
emp = []
push = _∷_
pop : Q → Unit ⊎ (Q × A)
pop [] = inl tt
pop (x ∷ []) = inr ([] , x)
pop (x ∷ x' ∷ xs) = pop-map-forward (push x) (pop (x' ∷ xs))
-- for later convenience
Q₁ = typ 1List
emp₁ = str 1List .fst
push₁ = str 1List .snd .fst
pop₁ = str 1List .snd .snd
-- Now for 2Lists
data Q₂ : Set ℓ where
Q₂⟨_,_⟩ : (xs ys : List A) → Q₂
tilt : ∀ xs ys z → Q₂⟨ xs ++ [ z ] , ys ⟩ ≡ Q₂⟨ xs , ys ++ [ z ] ⟩
trunc : (q q' : Q₂) (α β : q ≡ q') → α ≡ β
multitilt : (xs ys zs : List A) → Q₂⟨ xs ++ rev zs , ys ⟩ ≡ Q₂⟨ xs , ys ++ zs ⟩
multitilt xs ys [] = cong₂ Q₂⟨_,_⟩ (++-unit-r xs) (sym (++-unit-r ys))
multitilt xs ys (z ∷ zs) =
cong (λ ws → Q₂⟨ ws , ys ⟩) (sym (++-assoc xs (rev zs) [ z ]))
∙ tilt (xs ++ rev zs) ys z
∙ multitilt xs (ys ++ [ z ]) zs
∙ cong (λ ws → Q₂⟨ xs , ws ⟩) (++-assoc ys [ z ] zs)
-- push into the first list, pop from the second if possible
emp₂ : Q₂
emp₂ = Q₂⟨ [] , [] ⟩
push₂ : A → Q₂ → Q₂
push₂ a Q₂⟨ xs , ys ⟩ = Q₂⟨ a ∷ xs , ys ⟩
push₂ a (tilt xs ys z i) = tilt (a ∷ xs) ys z i
push₂ a (trunc q q' α β i j) =
trunc _ _ (cong (push₂ a) α) (cong (push₂ a) β) i j
pop₂Flush : List A → Unit ⊎ (Q₂ × A)
pop₂Flush [] = inl tt
pop₂Flush (x ∷ xs) = inr (Q₂⟨ [] , xs ⟩ , x)
pop₂ : Q₂ → Unit ⊎ (Q₂ × A)
pop₂ Q₂⟨ xs , [] ⟩ = pop₂Flush (rev xs)
pop₂ Q₂⟨ xs , y ∷ ys ⟩ = inr (Q₂⟨ xs , ys ⟩ , y)
pop₂ (tilt xs [] z i) = path i
where
path : pop₂Flush (rev (xs ++ [ z ])) ≡ inr (Q₂⟨ xs , [] ⟩ , z)
path =
cong pop₂Flush (rev-++ xs [ z ])
∙ cong (λ q → inr (q , z)) (sym (multitilt [] [] (rev xs)))
∙ cong (λ ys → inr (Q₂⟨ ys , [] ⟩ , z)) (rev-rev xs)
pop₂ (tilt xs (y ∷ ys) z i) = inr (tilt xs ys z i , y)
pop₂ (trunc q q' α β i j) =
isOfHLevelSum 0
(isProp→isSet isPropUnit)
(isOfHLevelΣ 2 trunc λ _ → Aset)
(pop₂ q) (pop₂ q') (cong pop₂ α) (cong pop₂ β)
i j
2List : Queue
2List = (Q₂ , emp₂ , push₂ , pop₂)
-- We construct an equivalence Q₁≃Q₂ and prove that this is a queue-iso
quot : Q₁ → Q₂
quot xs = Q₂⟨ xs , [] ⟩
eval : Q₂ → Q₁
eval Q₂⟨ xs , ys ⟩ = xs ++ rev ys
eval (tilt xs ys z i) = path i
where
path : (xs ++ [ z ]) ++ rev ys ≡ xs ++ rev (ys ++ [ z ])
path =
++-assoc xs [ z ] (rev ys)
∙ cong (_++_ xs) (sym (rev-++ ys [ z ]))
eval (trunc q q' α β i j) = -- truncated case
isOfHLevelList 0 Aset (eval q) (eval q') (cong eval α) (cong eval β) i j
quot∘eval : ∀ q → quot (eval q) ≡ q
quot∘eval Q₂⟨ xs , ys ⟩ = multitilt xs [] ys
quot∘eval (tilt xs ys z i) = -- truncated case
isOfHLevelPathP'
{A = λ i → quot (eval (tilt xs ys z i)) ≡ tilt xs ys z i}
0
(λ _ → trunc _ _)
(multitilt (xs ++ [ z ]) [] ys) (multitilt xs [] (ys ++ [ z ]))
.fst i
quot∘eval (trunc q q' α β i j) = -- truncated case
isOfHLevelPathP'
{A = λ i →
PathP (λ j → quot (eval (trunc q q' α β i j)) ≡ trunc q q' α β i j)
(quot∘eval q) (quot∘eval q')}
0
(λ _ → isOfHLevelPathP' 1 (λ _ → isOfHLevelSuc 2 trunc _ _) _ _)
(cong quot∘eval α) (cong quot∘eval β)
.fst i j
eval∘quot : ∀ xs → eval (quot xs) ≡ xs
eval∘quot = ++-unit-r
-- We get our desired equivalence
quotEquiv : Q₁ ≃ Q₂
quotEquiv = isoToEquiv (iso quot eval quot∘eval eval∘quot)
-- Now it only remains to prove that this is a queue-iso
quot∘emp : quot emp₁ ≡ emp₂
quot∘emp = refl
quot∘push : ∀ x xs → quot (push₁ x xs) ≡ push₂ x (quot xs)
quot∘push x xs = refl
quot∘pop : ∀ xs → pop-map-forward quot (pop₁ xs) ≡ pop₂ (quot xs)
quot∘pop [] = refl
quot∘pop (x ∷ []) = refl
quot∘pop (x ∷ x' ∷ xs) =
pop-map-forward-∘ quot (push₁ x) (pop₁ (x' ∷ xs))
∙ sym (pop-map-forward-∘ (push₂ x) quot (pop₁ (x' ∷ xs)))
∙ cong (pop-map-forward (push₂ x)) (quot∘pop (x' ∷ xs))
∙ lemma x x' (rev xs)
where
lemma : ∀ x x' ys
→ pop-map-forward (push₂ x) (pop₂Flush (ys ++ [ x' ]))
≡ pop₂Flush ((ys ++ [ x' ]) ++ [ x ])
lemma x x' [] i = inr (tilt [] [] x i , x')
lemma x x' (y ∷ ys) i = inr (tilt [] (ys ++ [ x' ]) x i , y)
quotEquiv-is-queue-iso : queue-iso 1List 2List quotEquiv
quotEquiv-is-queue-iso = quot∘emp , quot∘push , quot∘pop
-- And we get the desired Path
Path-1List-2List : 1List ≡ 2List
Path-1List-2List = SIP queue-structure queue-iso Queue-is-SNS 1List 2List .fst
(quotEquiv , quotEquiv-is-queue-iso)
| {
"alphanum_fraction": 0.5548271752,
"avg_line_length": 29.4385964912,
"ext": "agda",
"hexsha": "0734a03fa53a37a5a990a76eee837c1eacdaa763",
"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": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "borsiemir/cubical",
"max_forks_repo_path": "Cubical/Data/Queue/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"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": "borsiemir/cubical",
"max_issues_repo_path": "Cubical/Data/Queue/Base.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "borsiemir/cubical",
"max_stars_repo_path": "Cubical/Data/Queue/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2040,
"size": 5034
} |
open import Oscar.Prelude
open import Oscar.Class.IsPrecategory
open import Oscar.Class.Surjection
open import Oscar.Class.Smap
open import Oscar.Class.Surjtranscommutativity
open import Oscar.Class.Surjextensionality
open import Oscar.Class.Transitivity
module Oscar.Class.IsPrefunctor where
module _
{𝔬₁} {𝔒₁ : Ø 𝔬₁}
{𝔯₁} (_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
{ℓ₁} (_∼̇₁_ : ∀ {x y} → x ∼₁ y → x ∼₁ y → Ø ℓ₁)
(_↦₁_ : Transitivity.type _∼₁_)
{𝔬₂} {𝔒₂ : Ø 𝔬₂}
{𝔯₂} (_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
{ℓ₂} (_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂)
(_↦₂_ : Transitivity.type _∼₂_)
{surjection : Surjection.type 𝔒₁ 𝔒₂}
(smap : Smap.type _∼₁_ _∼₂_ surjection surjection)
where
record IsPrefunctor : Ø 𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂ where
constructor ∁
field
overlap ⦃ `IsPrecategory₁ ⦄ : IsPrecategory _∼₁_ _∼̇₁_ _↦₁_
overlap ⦃ `IsPrecategory₂ ⦄ : IsPrecategory _∼₂_ _∼̇₂_ _↦₂_
overlap ⦃ `𝓢urjtranscommutativity ⦄ : Surjtranscommutativity.class _∼₁_ _∼₂_ _∼̇₂_ smap _↦₁_ _↦₂_
⦃ `𝓢urjextensionality ⦄ : Surjextensionality.class _∼₁_ _∼̇₁_ _∼₂_ _∼̇₂_ surjection smap
| {
"alphanum_fraction": 0.6618049225,
"avg_line_length": 35.3870967742,
"ext": "agda",
"hexsha": "480e15d73875f9b89e3db055d8a9114b92344c9c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Class/IsPrefunctor.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Class/IsPrefunctor.agda",
"max_line_length": 103,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Class/IsPrefunctor.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 546,
"size": 1097
} |
{-# OPTIONS --cubical #-}
module README where
------------------------------------------------------------------------
-- Chapter 2: Programming and Proving in Cubical Agda
------------------------------------------------------------------------
-- 2.1: Basic Functional Programming in Agda
import Snippets.Bool using
( Bool -- 2.1
; Boolean
; a-boolean)
-- 2.2: Some Functions
import Snippets.Bool using
( not
; module LambdaNot)
import Function using
( id
)
import Snippets.Nat using
( ℕ -- 2.2
; add
; _-_ -- 2.3
; module NonCoveringSub
; _+_ -- 2.4
; module NonTermAdd
)
-- 2.3: An Expression Evaluator
import Snippets.Expr using
( Op -- 2.5
; Expr -- 2.6
; module IncorrectEval -- 2.7
)
-- 2.4: Safe Evaluation with Maybe
import Data.Maybe using
( Maybe -- 2.8
)
import Snippets.Maybe using
( maybe-two
; maybe-func
)
import Snippets.Expr using
( _-_ -- 2.9
; ⟦_⟧
)
import Data.Maybe.Sugar using
( pure
; _<*>_
; _>>=_ -- 2.10
)
-- 2.5: Statically Proving the Evaluation is Safe
import Snippets.Expr using
( example-eval
; is-just
)
import Data.Bool using
( T
)
import Data.Empty using
( ⊥
)
import Snippets.Introduction using
( ⊤
)
import Data.Empty using
( ¬_
)
import Snippets.Expr using
( Pair -- 2.11
; Valid -- 2.12
; ⟦_⟧!
; example-static-eval -- 2.13
)
import Snippets.Implicits using
( module Normal
; module ImplicitType -- 2.14
)
-- 2.6: Equalities
import Snippets.Equality using
( module MLTTEquality -- 2.15
; sym
)
-- 2.7: Some Proofs of Equality
import Snippets.Equality using
( refl -- 2.16
)
import Snippets.Expr using
( example-static-proof
)
import Data.Nat.Properties using
( +-assoc
)
-- 2.8: Quotients
import Cubical.HITs.S1 using
( S¹ -- 2.17
)
-- 2.9: Basic Type Formers
import Snippets.Formers using
( ℕ-or-String
; Pair
; fst
; snd
; pair
)
import Data.Sigma using
( Σ
; _×_ -- 2.18
)
import Data.Sum using
( _⊎_ -- 2.19
)
-- 2.11: Comparing Classical and Constructive Proofs in Agda
import Snippets.Classical using
( Classical -- 2.20
; lem
; pure
; _>>=_
)
import Relation.Nullary.Stable using
( Stable
)
------------------------------------------------------------------------
-- Chapter 3: Finiteness Predicates
------------------------------------------------------------------------
-- 3.1: Split Enumerability
import Cardinality.Finite.SplitEnumerable.Container using
( ℰ!
)
import Container.List using
( List -- 3.1
)
import Data.Fin.Base using
(module DisplayImpl)
import Data.List using
(List)
import Container using
( ⟦_⟧ -- 3.3
)
import Container.Membership using
( _∈_ -- 3.4
)
import Function.Fiber using
( fiber -- 3.5
)
import Function.Surjective using
( SplitSurjective -- 3.6
; _↠!_
)
import Cardinality.Finite.SplitEnumerable using
( ℰ!⇔Fin↠!
)
import Data.Sigma.Properties using
( reassoc
)
import Cardinality.Finite.SplitEnumerable using
( split-enum-is-split-surj
; ℰ!⟨2⟩ -- 3.7
)
import Function.Surjective.Properties using
( ↠!-ident
)
import Relation.Nullary.Discrete using
( Discrete
)
import Snippets.Dec using
( Dec
)
import Function.Injective using
( Injective
; _↣_
)
import Function.Injective.Properties using
(Discrete-pull-inj)
import Function.Surjective.Properties using
( surj-to-inj
; Discrete-distrib-surj
)
import Cardinality.Finite.SplitEnumerable using
(ℰ!⇒Discrete)
-- 3.2: Manifest Bishop Finiteness
import Cardinality.Finite.SplitEnumerable using
( module BoolSlop -- 3.8
)
import HLevels using
( isContr -- 3.9
)
import Container.Membership using
( _∈!_ -- 3.10
)
import Cardinality.Finite.ManifestBishop.Container using
( ℬ
)
import Snippets.Equivalence using
( isEquiv -- 3.11
; _≃_
)
import Cardinality.Finite.ManifestBishop using
( ℬ⇔Fin≃
)
-- 3.3: Cardinal Finiteness
import Cardinality.Finite.SplitEnumerable using
( ℰ!⟨2⟩
; ℰ!⟨2⟩′
)
import HLevels using
( isProp -- 3.12
)
import HITs.PropositionalTruncation using
( ∥_∥ -- 3.13
; rec -- 3.14
)
import Cardinality.Finite.Cardinal using
( 𝒞
; 𝒞⇒Discrete
)
import Relation.Nullary.Discrete.Properties using
( isPropDiscrete
)
import HLevels using
( isSet -- 3.15
)
import Relation.Nullary.Discrete.Properties using
( Discrete→isSet
)
import HITs.PropositionalTruncation using
( rec→set -- 3.16
)
import Cardinality.Finite.Cardinal using
( cardinality-is-unique
)
import Data.List.Sort using
( insert
; sort
; sort-sorts
; sort-perm
)
import Data.List.Relation.Binary.Permutation using
( _↭_
)
import Data.List.Sort using
( sorted-perm-eq
; perm-invar
)
import Cardinality.Finite.Cardinal using
( ¬⟨𝒞⋂ℬᶜ⟩
)
import Snippets.Classical using
( classical-impl
)
-- 3.4: Manifest Enumerability
import Cubical.HITs.S1 using
( S¹ -- 3.19
)
import HLevels using
( isGroupoid -- 3.20
)
import Cardinality.Finite.ManifestEnumerable.Container using
( ℰ
)
import Cardinality.Finite.ManifestEnumerable using
( ℰ⟨S¹⟩
)
import Cubical.HITs.S1 using
( isConnectedS¹
)
import Function.Surjective using
( Surjective -- 3.21
; _↠_
)
import Cardinality.Finite.ManifestEnumerable using
( ℰ⇔Fin↠
)
import HITs.PropositionalTruncation.Properties using
( recompute -- 3.22
)
-- 3.5: Kuratowski Finiteness
import Algebra.Construct.Free.Semilattice using
( 𝒦 -- 3.23
)
import Algebra.Construct.Free.Semilattice.Direct using
( 𝒦
)
import Algebra.Construct.Free.Semilattice.Relation.Unary.Membership using
( _∈_
)
import Cardinality.Finite.Kuratowski using
( 𝒦ᶠ
; 𝒞⇔𝒦×Discrete -- 3.24
)
------------------------------------------------------------------------
-- Chapter 4: Topos
------------------------------------------------------------------------
-- 4.1: Categories in HoTT
import Categories using
( PreCategory -- 4.1
)
-- 4.2: The Category of Sets
import Categories.HSets using
( Ob
)
-- 4.3: Closure
import Cardinality.Finite.SplitEnumerable using
( _|Σ|_
; sup-Σ
)
import Cardinality.Finite.ManifestBishop using
( _|Π|_
)
import Data.Tuple.UniverseMonomorphic using
( Tuple
)
import Cardinality.Finite.Cardinal using
( _∥×∥_
; 𝒞⇒Choice
)
-- 4.4: The Absence of the Subobject Classifier
import Snippets.Topos using
( Prop-univ
; prop-resize
)
------------------------------------------------------------------------
-- Chapter 5: Search
------------------------------------------------------------------------
import Snippets.Bool using
( _∧_
; ∧-assoc -- 5.1
; some-assoc
)
-- 5.1: How to make the Typechecker do Automation
import Snippets.Bool using
( obvious
; True
; toWitness
; extremely-obvious
)
-- 5.2: Omniscience
import Relation.Nullary.Omniscience using
( Exhaustible
; Omniscient
)
import Relation.Nullary.Decidable.Properties using
( Dec→DoubleNegElim
)
import Relation.Nullary.Omniscience using
( Omniscient→Exhaustible
)
import Cardinality.Finite.Kuratowski using
( 𝒦ᶠ⇒Exhaustible
)
import Cardinality.Finite.ManifestEnumerable using
( ℰ⇒Omniscient
)
import Relation.Nullary.Omniscience using
( Prop-Omniscient
)
import Cardinality.Finite.Kuratowski using
( 𝒦ᶠ⇒Prop-Omniscient
)
-- 5.3: An Interface for Proof Automation
import Cardinality.Finite.SplitEnumerable.Search using
( ∀?
; ∃?
; module PreInst
)
import Snippets.Bool using
( module PreInst′
)
import Cardinality.Finite.SplitEnumerable.Search using
( module WithInst
)
import Snippets.Bool using
( ∧-idem -- 5.2
; module BadCurrying
)
import Instance using
( it
)
import Data.Product.NAry using
( Levels
; max-level
; Types
; ⦅_⦆⁺
; ⦅_⦆
; ArgForm
; _[_]→_
; [_$]
; Π[_$]
; ⦅_⦆[_]→_
; pi-arrs-plus
; Π[_^_$]
)
import Cardinality.Finite.SplitEnumerable.Search using
( ∃?ⁿ
; ∃↯ⁿ
)
import Snippets.Bool using
( ∧-comm
)
-- 5.4: Countdown
import Countdown using
( ℰ!⟨Vec⟩
; ℰ!⟨Op⟩
; module WrongPerm
; module IsoPerm
; Perm
; ℰ!⟨Perm⟩
)
import Dyck using
( Dyck
; module NonParamTree
)
import Countdown using
( ExprTree
; Transformation
; ℰ!⟨ExprTree⟩
; ℰ!⟨Transformation⟩
; eval
; _!⟨_⟩!_
; Solution
; exampleSolutions
)
------------------------------------------------------------------------
-- Chapter 6: Countably Infinite Types
------------------------------------------------------------------------
-- 6.1: Countability
import Cardinality.Infinite.Split using
( ℵ!
)
import Codata.Stream using
( Stream
)
import Cardinality.Infinite.Split using
( ℵ!⇔ℕ↠!
)
-- 6.2: Closure
import Data.List.Kleene using
( _⁺
; _⋆
)
import Cardinality.Infinite.Split using
( _*⋆_[_]
; _*_
; _|Σ|_
; |star|
; cantor-diag
)
| {
"alphanum_fraction": 0.6128815081,
"avg_line_length": 15.3920552677,
"ext": "agda",
"hexsha": "f3bdc3bfa8ea1970b07f0f9477856dd52b54a2a8",
"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": "9c5e8b6f546bee952e92db0b73bfc12592bf3152",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/masters-thesis",
"max_forks_repo_path": "agda/README.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9c5e8b6f546bee952e92db0b73bfc12592bf3152",
"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/masters-thesis",
"max_issues_repo_path": "agda/README.agda",
"max_line_length": 73,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "9c5e8b6f546bee952e92db0b73bfc12592bf3152",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/masters-thesis",
"max_stars_repo_path": "agda/README.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z",
"num_tokens": 2871,
"size": 8912
} |
{-# OPTIONS --copatterns #-}
record U : Set where
coinductive
field out : U
u : {A : Set} → U
u = {!!}
record Wrap (A : Set) : Set where
field
wrapped : A
wrap : ∀{A}{a : A} → Wrap A
wrap = {!!}
| {
"alphanum_fraction": 0.5238095238,
"avg_line_length": 12.3529411765,
"ext": "agda",
"hexsha": "30e789da2d83487646d351ab3774903f20b53b9c",
"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/interaction/Issue1516.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue1516.agda",
"max_line_length": 33,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue1516.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": 76,
"size": 210
} |
{-
Copyright (c) 2017 Diego Pedraza.
This is Free/Libre Open Source Software, released under the MIT License.
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-}
module R2 where
open import Data.List using (List; _∷_; _++_; [_]; [])
open import Data.Nat
open import Data.Bool
record Pair (A B : Set) : Set where
constructor _,_
field
fst : A
snd : B
{- ---------------------------------------------------------------
Ejercicio 1.1. Definir la función
sumaImpares :: nat ⇒ nat
tal que (sumaImpares n) es la suma de los n primeros números
impares. Por ejemplo,
sumaImpares 5 = 25
---------------------------------------------------------------- -}
sumaImpares : ℕ → ℕ
sumaImpares 0 = 0
sumaImpares (suc n) = (2 * n + 1) + sumaImpares n
{- ---------------------------------------------------------------
Ejercicio 1.2. Demostrar que
sumaImpares n = n*n
----------------------------------------------------------------- -}
_≡_ : ℕ → ℕ → Bool
0 ≡ 0 = true
(suc n) ≡ (suc m) = n ≡ m
n ≡ 0 = false
0 ≡ m = false
lemaSumaImpares : {n : ℕ} → (sumaImpares n) ≡ (n * n)
lemaSumaImpares {zero} = ?
lemaSumaImpares {suc n} = ?
{-
{- ---------------------------------------------------------------
Ejercicio 2.1. Definir la función
sumaPotenciasDeDosMasUno :: nat ⇒ nat
tal que
(sumaPotenciasDeDosMasUno n) = 1 + 2^0 + 2^1 + 2^2 + ... + 2^n.
Por ejemplo,
sumaPotenciasDeDosMasUno 3 = 16
---------------------------------------------------------------- -}
fun sumaPotenciasDeDosMasUno :: "nat ⇒ nat" where
"sumaPotenciasDeDosMasUno n = undefined"
{- ---------------------------------------------------------------
Ejercicio 2.2. Demostrar que
sumaPotenciasDeDosMasUno n = 2^(n+1)
----------------------------------------------------------------- -}
lemma "sumaPotenciasDeDosMasUno n = 2^(n+1)"
oops
{- ---------------------------------------------------------------
Ejercicio 3.1. Definir la función
copia :: nat ⇒ 'a ⇒ 'a list
tal que (copia n x) es la lista formado por n copias del elemento
x. Por ejemplo,
copia 3 x = [x,x,x]
---------------------------------------------------------------- -}
fun copia :: "nat ⇒ 'a ⇒ 'a list" where
"copia n x = undefined"
{- ---------------------------------------------------------------
Ejercicio 3.2. Definir la función
todos :: ('a ⇒ bool) ⇒ 'a list ⇒ bool
tal que (todos p xs) se verifica si todos los elementos de xs cumplen
la propiedad p. Por ejemplo,
todos (λx. x>(1::nat)) [2,6,4] = True
todos (λx. x>(2::nat)) [2,6,4] = False
Nota: La conjunción se representa por ∧
--------------------------------------------------------------- -}
fun todos :: "('a ⇒ bool) ⇒ 'a list ⇒ bool" where
"todos p xs = undefined"
{- ---------------------------------------------------------------
Ejercicio 3.3. Demostrar que todos los elementos de (copia n x) son
iguales a x.
----------------------------------------------------------------- -}
lemma "todos (λy. y=x) (copia n x)"
oops
{- ---------------------------------------------------------------
Ejercicio 4.1. Definir, recursivamente y sin usar (@), la función
amplia :: 'a list ⇒ 'a ⇒ 'a list
tal que (amplia xs y) es la lista obtenida añadiendo el elemento y al
final de la lista xs. Por ejemplo,
amplia [d,a] t = [d,a,t]
---------------------------------------------------------------- -}
fun amplia :: "'a list ⇒ 'a ⇒ 'a list" where
"amplia xs y = undefined"
{- ---------------------------------------------------------------
Ejercicio 4.2. Demostrar que
amplia xs y = xs @ [y]
----------------------------------------------------------------- -}
lemma "amplia xs y = xs @ [y]"
oops
-}
| {
"alphanum_fraction": 0.4290147401,
"avg_line_length": 32.225,
"ext": "agda",
"hexsha": "5acd9e505de31ab89114175458b6ef1104de696e",
"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": "cc2e64e1a42ac225c3d1a6a998721f916065418b",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "Zegeri/TFG-TeoriaCategorias",
"max_forks_repo_path": "Ejercicios/Agda/R2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cc2e64e1a42ac225c3d1a6a998721f916065418b",
"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": "Zegeri/TFG-TeoriaCategorias",
"max_issues_repo_path": "Ejercicios/Agda/R2.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cc2e64e1a42ac225c3d1a6a998721f916065418b",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "Zegeri/TFG-TeoriaCategorias",
"max_stars_repo_path": "Ejercicios/Agda/R2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1035,
"size": 3867
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.NatSolver.Solver where
open import Cubical.Foundations.Prelude
open import Cubical.Data.FinData
open import Cubical.Data.Nat
open import Cubical.Data.Nat.Order using (zero-≤)
open import Cubical.Data.Vec.Base
open import Cubical.Algebra.NatSolver.NatExpression
open import Cubical.Algebra.NatSolver.HornerForms
open import Cubical.Algebra.NatSolver.EvalHom
private
variable
ℓ : Level
module EqualityToNormalform where
open Eval
open IteratedHornerOperations
open HomomorphismProperties
normalize : {n : ℕ} → Expr n → IteratedHornerForms n
normalize {n = n} (K r) = Constant n r
normalize {n = n} (∣ k) = Variable n k
normalize (x +' y) =
(normalize x) +ₕ (normalize y)
normalize (x ·' y) =
(normalize x) ·ₕ (normalize y)
isEqualToNormalform :
{n : ℕ}
(e : Expr n) (xs : Vec ℕ n)
→ eval (normalize e) xs ≡ ⟦ e ⟧ xs
isEqualToNormalform (K r) [] = refl
isEqualToNormalform {n = ℕ.suc n} (K r) (x ∷ xs) =
eval (Constant (ℕ.suc n) r) (x ∷ xs) ≡⟨ refl ⟩
eval (0ₕ ·X+ Constant n r) (x ∷ xs) ≡⟨ refl ⟩
eval 0ₕ (x ∷ xs) · x + eval (Constant n r) xs
≡⟨ cong (λ u → u · x + eval (Constant n r) xs) (eval0H (x ∷ xs)) ⟩
0 · x + eval (Constant n r) xs
≡⟨ refl ⟩
eval (Constant n r) xs
≡⟨ isEqualToNormalform (K r) xs ⟩
r ∎
isEqualToNormalform (∣ zero) (x ∷ xs) =
eval (1ₕ ·X+ 0ₕ) (x ∷ xs) ≡⟨ refl ⟩
eval 1ₕ (x ∷ xs) · x + eval 0ₕ xs ≡⟨ cong (λ u → u · x + eval 0ₕ xs)
(eval1ₕ (x ∷ xs)) ⟩
1 · x + eval 0ₕ xs ≡⟨ cong (λ u → 1 · x + u ) (eval0H xs) ⟩
1 · x + 0 ≡⟨ +-zero _ ⟩
1 · x ≡⟨ ·-identityˡ _ ⟩
x ∎
isEqualToNormalform {n = ℕ.suc n} (∣ (suc k)) (x ∷ xs) =
eval (0ₕ ·X+ Variable n k) (x ∷ xs) ≡⟨ refl ⟩
eval 0ₕ (x ∷ xs) · x + eval (Variable n k) xs
≡⟨ cong (λ u → u · x + eval (Variable n k) xs) (eval0H (x ∷ xs)) ⟩
0 · x + eval (Variable n k) xs
≡⟨ refl ⟩
eval (Variable n k) xs
≡⟨ isEqualToNormalform (∣ k) xs ⟩
⟦ ∣ (suc k) ⟧ (x ∷ xs) ∎
isEqualToNormalform (e +' e₁) [] =
eval (normalize e +ₕ normalize e₁) []
≡⟨ +Homeval (normalize e) _ [] ⟩
eval (normalize e) []
+ eval (normalize e₁) []
≡⟨ cong (λ u → u + eval (normalize e₁) [])
(isEqualToNormalform e []) ⟩
⟦ e ⟧ []
+ eval (normalize e₁) []
≡⟨ cong (λ u → ⟦ e ⟧ [] + u) (isEqualToNormalform e₁ []) ⟩
⟦ e ⟧ [] + ⟦ e₁ ⟧ [] ∎
isEqualToNormalform (e +' e₁) (x ∷ xs) =
eval (normalize e
+ₕ normalize e₁) (x ∷ xs)
≡⟨ +Homeval (normalize e) _ (x ∷ xs) ⟩
eval (normalize e) (x ∷ xs)
+ eval (normalize e₁) (x ∷ xs)
≡⟨ cong (λ u → u + eval (normalize e₁) (x ∷ xs))
(isEqualToNormalform e (x ∷ xs)) ⟩
⟦ e ⟧ (x ∷ xs)
+ eval (normalize e₁) (x ∷ xs)
≡⟨ cong (λ u → ⟦ e ⟧ (x ∷ xs) + u)
(isEqualToNormalform e₁ (x ∷ xs)) ⟩
⟦ e ⟧ (x ∷ xs) + ⟦ e₁ ⟧ (x ∷ xs) ∎
isEqualToNormalform (e ·' e₁) [] =
eval (normalize e ·ₕ normalize e₁) []
≡⟨ ·Homeval (normalize e) _ [] ⟩
eval (normalize e) []
· eval (normalize e₁) []
≡⟨ cong (λ u → u · eval (normalize e₁) [])
(isEqualToNormalform e []) ⟩
⟦ e ⟧ []
· eval (normalize e₁) []
≡⟨ cong (λ u → ⟦ e ⟧ [] · u) (isEqualToNormalform e₁ []) ⟩
⟦ e ⟧ [] · ⟦ e₁ ⟧ [] ∎
isEqualToNormalform (e ·' e₁) (x ∷ xs) =
eval (normalize e ·ₕ normalize e₁) (x ∷ xs)
≡⟨ ·Homeval (normalize e) _ (x ∷ xs) ⟩
eval (normalize e) (x ∷ xs)
· eval (normalize e₁) (x ∷ xs)
≡⟨ cong (λ u → u · eval (normalize e₁) (x ∷ xs))
(isEqualToNormalform e (x ∷ xs)) ⟩
⟦ e ⟧ (x ∷ xs)
· eval (normalize e₁) (x ∷ xs)
≡⟨ cong (λ u → ⟦ e ⟧ (x ∷ xs) · u)
(isEqualToNormalform e₁ (x ∷ xs)) ⟩
⟦ e ⟧ (x ∷ xs) · ⟦ e₁ ⟧ (x ∷ xs) ∎
solve :
{n : ℕ} (e₁ e₂ : Expr n) (xs : Vec ℕ n)
(p : eval (normalize e₁) xs ≡ eval (normalize e₂) xs)
→ ⟦ e₁ ⟧ xs ≡ ⟦ e₂ ⟧ xs
solve e₁ e₂ xs p =
⟦ e₁ ⟧ xs ≡⟨ sym (isEqualToNormalform e₁ xs) ⟩
eval (normalize e₁) xs ≡⟨ p ⟩
eval (normalize e₂) xs ≡⟨ isEqualToNormalform e₂ xs ⟩
⟦ e₂ ⟧ xs ∎
| {
"alphanum_fraction": 0.4879910213,
"avg_line_length": 35.9274193548,
"ext": "agda",
"hexsha": "fa15aab9a4ef8f3c82f09891d49bec32af8b079d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Algebra/NatSolver/Solver.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Algebra/NatSolver/Solver.agda",
"max_line_length": 80,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Algebra/NatSolver/Solver.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 1739,
"size": 4455
} |
open import Nat
open import Prelude
open import Hazelnut-core
module Hazelnut-deterministic where
-- theorem 2
-- the same action applied to the same type makes the same resultant
-- type.
actdet1 : {t t' t'' : τ̂} {α : action} →
(t + α +> t') →
(t + α +> t'') →
(t' == t'')
actdet1 TMFirstChild TMFirstChild = refl
actdet1 TMParent1 TMParent1 = refl
actdet1 TMParent1 (TMZip1 ())
actdet1 TMParent2 TMParent2 = refl
actdet1 TMParent2 (TMZip2 ())
actdet1 TMNextSib TMNextSib = refl
actdet1 TMNextSib (TMZip1 ())
actdet1 TMPrevSib TMPrevSib = refl
actdet1 TMPrevSib (TMZip2 ())
actdet1 TMDel TMDel = refl
actdet1 TMConArrow TMConArrow = refl
actdet1 TMConNum TMConNum = refl
actdet1 (TMZip1 ()) TMParent1
actdet1 (TMZip1 ()) TMNextSib
actdet1 (TMZip1 p1) (TMZip1 p2) with actdet1 p1 p2
... | refl = refl
actdet1 (TMZip2 ()) TMParent2
actdet1 (TMZip2 ()) TMPrevSib
actdet1 (TMZip2 p1) (TMZip2 p2) with actdet1 p1 p2
... | refl = refl
-- all expressions only move to one other expression
movedet : {e e' e'' : ê} {δ : direction} →
(e + move δ +>e e') →
(e + move δ +>e e'') →
e' == e''
movedet EMAscFirstChild EMAscFirstChild = refl
movedet EMAscParent1 EMAscParent1 = refl
movedet EMAscParent2 EMAscParent2 = refl
movedet EMAscNextSib EMAscNextSib = refl
movedet EMAscPrevSib EMAscPrevSib = refl
movedet EMLamFirstChild EMLamFirstChild = refl
movedet EMLamParent EMLamParent = refl
movedet EMPlusFirstChild EMPlusFirstChild = refl
movedet EMPlusParent1 EMPlusParent1 = refl
movedet EMPlusParent2 EMPlusParent2 = refl
movedet EMPlusNextSib EMPlusNextSib = refl
movedet EMPlusPrevSib EMPlusPrevSib = refl
movedet EMApFirstChild EMApFirstChild = refl
movedet EMApParent1 EMApParent1 = refl
movedet EMApParent2 EMApParent2 = refl
movedet EMApNextSib EMApNextSib = refl
movedet EMApPrevSib EMApPrevSib = refl
movedet EMFHoleFirstChild EMFHoleFirstChild = refl
movedet EMFHoleParent EMFHoleParent = refl
-- if a move action on a synthetic action makes a new form, it's unique
synthmovedet : {Γ : ·ctx} {e e' e'' : ê} {t' t'' : τ̇} {δ : direction} →
(Γ ⊢ e => t' ~ move δ ~> e'' => t'') →
(e + move δ +>e e') →
e'' == e'
synthmovedet (SAMove EMAscFirstChild) EMAscFirstChild = refl
synthmovedet (SAMove EMAscParent1) EMAscParent1 = refl
synthmovedet (SAMove EMAscParent2) EMAscParent2 = refl
synthmovedet (SAMove EMAscNextSib) EMAscNextSib = refl
synthmovedet (SAMove EMAscPrevSib) EMAscPrevSib = refl
synthmovedet (SAMove EMLamFirstChild) EMLamFirstChild = refl
synthmovedet (SAMove EMLamParent) EMLamParent = refl
synthmovedet (SAMove EMPlusFirstChild) EMPlusFirstChild = refl
synthmovedet (SAMove EMPlusParent1) EMPlusParent1 = refl
synthmovedet (SAMove EMPlusParent2) EMPlusParent2 = refl
synthmovedet (SAMove EMPlusNextSib) EMPlusNextSib = refl
synthmovedet (SAMove EMPlusPrevSib) EMPlusPrevSib = refl
synthmovedet (SAMove EMApFirstChild) EMApFirstChild = refl
synthmovedet (SAMove EMApParent1) EMApParent1 = refl
synthmovedet (SAMove EMApParent2) EMApParent2 = refl
synthmovedet (SAMove EMApNextSib) EMApNextSib = refl
synthmovedet (SAMove EMApPrevSib) EMApPrevSib = refl
synthmovedet (SAMove EMFHoleFirstChild) EMFHoleFirstChild = refl
synthmovedet (SAMove EMFHoleParent) EMFHoleParent = refl
-- all these cases lead to absurdities after a few levels
synthmovedet (SAZipAsc1 (AASubsume _ (SAMove ()) _)) EMAscParent1
synthmovedet (SAZipAsc1 (AAMove ())) EMAscParent1
synthmovedet (SAZipAsc1 (AASubsume _ (SAMove ()) _)) EMAscNextSib
synthmovedet (SAZipAsc1 (AAMove ())) EMAscNextSib
synthmovedet (SAZipAsc2 () _) EMAscParent2
synthmovedet (SAZipAsc2 () _) EMAscPrevSib
synthmovedet (SAZipAp1 _ (SAMove ()) (ASubsume _ _)) EMApParent1
synthmovedet (SAZipAp1 _ (SAMove ()) (ALam _ _)) EMApParent1
synthmovedet (SAZipAp1 _ (SAMove ()) _) EMApNextSib
synthmovedet (SAZipAp2 _ (SAMove ()) _) EMApParent1
synthmovedet (SAZipAp2 _ (SAMove ()) _) EMApNextSib
synthmovedet (SAZipAp3 _ (AASubsume _ (SAMove ()) _)) EMApParent2
synthmovedet (SAZipAp3 _ (AAMove ())) EMApParent2
synthmovedet (SAZipAp3 _ (AASubsume _ (SAMove ()) _)) EMApPrevSib
synthmovedet (SAZipAp3 _ (AAMove ())) EMApPrevSib
synthmovedet (SAZipAp4 _ (AASubsume _ (SAMove ()) _)) EMApParent2
synthmovedet (SAZipAp4 _ (AAMove ())) EMApParent2
synthmovedet (SAZipAp4 _ (AASubsume _ (SAMove ()) _)) EMApPrevSib
synthmovedet (SAZipAp4 _ (AAMove ())) EMApPrevSib
synthmovedet (SAZipPlus1 (AASubsume _ (SAMove ()) _)) EMPlusParent1
synthmovedet (SAZipPlus1 (AAMove ())) EMPlusParent1
synthmovedet (SAZipPlus1 (AASubsume _ (SAMove ()) _)) EMPlusNextSib
synthmovedet (SAZipPlus1 (AAMove ())) EMPlusNextSib
synthmovedet (SAZipPlus2 (AASubsume _ (SAMove ()) _)) EMPlusParent2
synthmovedet (SAZipPlus2 (AAMove ())) EMPlusParent2
synthmovedet (SAZipPlus2 (AASubsume _ (SAMove ()) _)) EMPlusPrevSib
synthmovedet (SAZipPlus2 (AAMove ())) EMPlusPrevSib
synthmovedet (SAZipHole1 _ (SAMove ()) x) EMFHoleParent
synthmovedet (SAZipHole2 _ (SAMove ())) EMFHoleParent
-- these are all a bunch of small techincal lemmas for the cases below. i
-- don't understand why some of them can't be inlined.
lem1 : {Γ : ·ctx} {t1 t2 : τ̇} →
Γ ⊢ <||> <= (t1 ==> t2) →
(t1 ==> t2) ~ (<||> ==> <||>)
lem1 (ASubsume SEHole TCHole1) = TCArr TCHole1 TCHole1
lem3 : ∀{ Γ e t } → Γ ⊢ (e ·: t) <= t → Γ ⊢ e <= t
lem3 (ASubsume (SAsc x) x₁) = x
lem4 : ∀{ Γ e eh t t2 } →
Γ ⊢ e ∘ (eh ◆e) => t →
Γ ⊢ e => (t2 ==> t) →
Γ ⊢ (eh ◆e) <= t2
lem4 (SAp (SAsc x₁) x) (SAsc x₂) = x
lem4 {Γ = G} (SAp (SVar x₁) x) (SVar x₂)
with ctxunicity {Γ = G} x₁ x₂
... | refl = x
lem4 (SAp (SAp d1 x₁) x) (SAp d2 x₂)
with synthunicity d1 d2
... | refl = x
lem4 (SApHole () x) (SAsc x₁)
lem4 {Γ = G} (SApHole (SVar x₁) x) (SVar x₂)
with ctxunicity {Γ = G} x₁ x₂
... | ()
lem4 (SApHole (SAp d1 x₁) x) (SAp d2 x₂)
with synthunicity d1 d2
... | ()
lem4 (SApHole (SApHole d1 x₁) x) (SAp d2 x₂)
with synthunicity d1 d2
... | ()
lem5 : ∀ {Γ e eh} →
Γ ⊢ e => <||> →
Γ ⊢ e ∘ (eh ◆e) => <||> →
Γ ⊢ eh ◆e <= <||>
lem5 d1 (SAp d2 x) with synthunicity d1 d2
... | ()
lem5 d1 (SApHole d2 x) = x
lem6 : ∀ {Γ e1 e2} →
Γ ⊢ e1 ·+ e2 => num →
Γ ⊢ e1 <= num × Γ ⊢ e2 <= num
lem6 (SPlus x x₁) = x , x₁
lem7 : ∀{Γ e t e' t'} →
Γ ⊢ <| e |> => <||> →
Γ ⊢ ▹ e ◃ => t ~ move parent ~> e' => t' →
⊥
lem7 (SFHole _) (SAMove ())
lem8a : ∀ {Γ e e' t} →
Γ ⊢ ▹ e ◃ ~ move nextSib ~> e' ⇐ t → ⊥
lem8a (AASubsume x (SAMove ()) x₂)
lem8a (AAMove ())
-- expressions in focus don't move to next sib
lem8s : ∀ {Γ e e' t t'} →
Γ ⊢ ▹ e ◃ => t ~ move nextSib ~> e' => t' → ⊥
lem8s (SAMove ())
-- expressions in focus don't move to prev sib
lem9a : ∀ {Γ e e' t} →
Γ ⊢ ▹ e ◃ ~ move prevSib ~> e' ⇐ t → ⊥
lem9a (AASubsume x (SAMove ()) x₂)
lem9a (AAMove ())
-- expressions in focus don't move to prev sib
lem9s : ∀ {Γ e e' t t'} →
Γ ⊢ ▹ e ◃ => t ~ move prevSib ~> e' => t' → ⊥
lem9s (SAMove ())
lem10 : ∀{Γ x t1 t2 e} →
Γ ⊢ ·λ x (e ◆e) <= (t1 ==> t2) →
(Γ ,, (x , t1)) ⊢ e ◆e <= t2
lem10 (ASubsume () x₂)
lem10 (ALam x₁ d1) = d1
-- expressions in focus don't move to parent
lem11 : ∀ {Γ e e' t} →
Γ ⊢ ▹ e ◃ ~ move parent ~> e' ⇐ t → ⊥
lem11 (AASubsume x (SAMove ()) x₂)
lem11 (AAMove ())
-- if a type isn't compatible with hole to hole, it isn't compatible with
-- any function type at all.
lem12 : {t : τ̇} → (t ~̸ (<||> ==> <||>)) → ((t1 t2 : τ̇) → t ~̸ (t1 ==> t2))
lem12 {num} p t1 t2 ()
lem12 {<||>} p t1 t2 TCHole2 = p TCHole2
lem12 {(t ==> t')} p t1 t2 x = p (TCArr TCHole1 TCHole1)
mutual
-- an action on an expression in a synthetic position produces one
-- resultant expression and type.
actdet2 : {Γ : ·ctx} {e e' e'' : ê} {t t' t'' : τ̇} {α : action} →
(Γ ⊢ (e ◆e) => t) →
(Γ ⊢ e => t ~ α ~> e' => t') →
(Γ ⊢ e => t ~ α ~> e'' => t'') →
(e' == e'' × t' == t'')
actdet2 wt (SAMove x) (SAMove x₁) = movedet x x₁ , refl
-- every other case of move in the left is an absurdity after a
-- couple of levels
actdet2 wt (SAMove EMAscParent1) (SAZipAsc1 (AASubsume _ (SAMove ()) _))
actdet2 wt (SAMove EMAscParent1) (SAZipAsc1 (AAMove ()))
actdet2 wt (SAMove EMAscNextSib) (SAZipAsc1 (AASubsume _ (SAMove ()) _))
actdet2 wt (SAMove EMAscNextSib) (SAZipAsc1 (AAMove ()))
actdet2 wt (SAMove EMAscParent2) (SAZipAsc2 () x₂)
actdet2 wt (SAMove EMAscPrevSib) (SAZipAsc2 () x₂)
actdet2 wt (SAMove EMApParent1) (SAZipAp1 x₁ (SAMove ()) x₂)
actdet2 wt (SAMove EMApNextSib) (SAZipAp1 x₁ (SAMove ()) x₂)
actdet2 wt (SAMove EMApParent1) (SAZipAp2 x₁ (SAMove ()) x₂)
actdet2 wt (SAMove EMApNextSib) (SAZipAp2 x₁ (SAMove ()) x₂)
actdet2 wt (SAMove EMApParent2) (SAZipAp3 x₁ (AASubsume x (SAMove ()) x₃))
actdet2 wt (SAMove EMApParent2) (SAZipAp3 x₁ (AAMove ()))
actdet2 wt (SAMove EMApPrevSib) (SAZipAp3 x₁ (AASubsume x (SAMove ()) x₃))
actdet2 wt (SAMove EMApPrevSib) (SAZipAp3 x₁ (AAMove ()))
actdet2 wt (SAMove EMApParent2) (SAZipAp4 x₁ (AASubsume x (SAMove ()) x₃))
actdet2 wt (SAMove EMApParent2) (SAZipAp4 x₁ (AAMove ()))
actdet2 wt (SAMove EMApPrevSib) (SAZipAp4 x₁ (AASubsume x (SAMove ()) x₃))
actdet2 wt (SAMove EMApPrevSib) (SAZipAp4 x₁ (AAMove ()))
actdet2 wt (SAMove EMPlusParent1) (SAZipPlus1 (AASubsume x (SAMove ()) x₂))
actdet2 wt (SAMove EMPlusParent1) (SAZipPlus1 (AAMove ()))
actdet2 wt (SAMove EMPlusNextSib) (SAZipPlus1 (AASubsume x (SAMove ()) x₂))
actdet2 wt (SAMove EMPlusNextSib) (SAZipPlus1 (AAMove ()))
actdet2 wt (SAMove EMPlusParent2) (SAZipPlus2 (AASubsume x (SAMove ()) x₂))
actdet2 wt (SAMove EMPlusParent2) (SAZipPlus2 (AAMove ()))
actdet2 wt (SAMove EMPlusPrevSib) (SAZipPlus2 (AASubsume x (SAMove ()) x₂))
actdet2 wt (SAMove EMPlusPrevSib) (SAZipPlus2 (AAMove ()))
actdet2 wt (SAMove EMFHoleParent) (SAZipHole1 x₁ (SAMove ()) x₂)
actdet2 wt (SAMove EMFHoleParent) (SAZipHole2 x₁ (SAMove ()))
actdet2 wt SADel SADel = refl , refl
actdet2 wt SAConAsc SAConAsc = refl , refl
actdet2 {Γ = G} wt (SAConVar p) (SAConVar p₁)
with ctxunicity {Γ = G} p p₁
... | refl = refl , refl
actdet2 wt (SAConLam x₁) (SAConLam x₂) = refl , refl
actdet2 wt SAConAp1 SAConAp1 = refl , refl
actdet2 wt SAConAp1 (SAConAp3 x) = abort (lem12 x _ _ TCRefl)
actdet2 wt SAConAp2 SAConAp2 = refl , refl
actdet2 wt SAConAp2 (SAConAp3 x) = abort (x TCHole2)
actdet2 wt (SAConAp3 x) SAConAp1 = abort (lem12 x _ _ TCRefl)
actdet2 wt (SAConAp3 x) SAConAp2 = abort (x TCHole2)
actdet2 wt (SAConAp3 x) (SAConAp3 x₁) = refl , refl
actdet2 wt SAConArg SAConArg = refl , refl
actdet2 wt SAConNumlit SAConNumlit = refl , refl
actdet2 wt (SAConPlus1 x) (SAConPlus1 x₁) = refl , refl
actdet2 wt (SAConPlus1 x) (SAConPlus2 x₁) = abort (x₁ x)
actdet2 wt (SAConPlus2 x) (SAConPlus1 x₁) = abort (x x₁)
actdet2 wt (SAConPlus2 x) (SAConPlus2 x₁) = refl , refl
actdet2 wt (SAFinish x) (SAFinish x₁)
with synthunicity x x₁
... | refl = refl , refl
actdet2 wt (SAZipAsc1 (AASubsume _ (SAMove ()) _)) (SAMove EMAscParent1)
actdet2 wt (SAZipAsc1 (AAMove ())) (SAMove EMAscParent1)
actdet2 wt (SAZipAsc1 x) (SAMove EMAscNextSib) = abort (lem8a x)
actdet2 {t = t} wt (SAZipAsc1 x) (SAZipAsc1 x₁) =
ap1 (λ q → q ·:₁ t) (actdet3 (lem3 (ASubsume wt TCRefl)) x x₁) , refl
actdet2 wt (SAZipAsc2 () x₁) (SAMove EMAscParent2)
actdet2 wt (SAZipAsc2 () x₁) (SAMove EMAscPrevSib)
actdet2 wt (SAZipAsc2 x x₁) (SAZipAsc2 x₂ x₃) with actdet1 x x₂
... | refl = refl , refl
actdet2 wt (SAZipAp1 x (SAMove ()) x₁) (SAMove EMApParent1)
actdet2 wt (SAZipAp1 x (SAMove ()) x₁) (SAMove EMApNextSib)
actdet2 wt (SAZipAp1 x d1 x₁) (SAZipAp1 x₂ d2 x₃)
with synthunicity x₂ x
... | refl with actdet2 x d1 d2 -- todo: double-barrelded with here ..
... | p1 , refl = (ap1 (λ q → q ∘₁ _) p1) , refl
actdet2 wt (SAZipAp1 x d1 x₁) (SAZipAp2 x₂ d2 x₃)
with synthunicity x x₂
... | refl with actdet2 x d1 d2 -- todo: .. and here
actdet2 wt (SAZipAp1 _ _ _ ) (SAZipAp2 _ _ _) | refl | _ , ()
actdet2 wt (SAZipAp2 x (SAMove ()) x₁) (SAMove EMApParent1)
actdet2 wt (SAZipAp2 x (SAMove ()) x₁) (SAMove EMApNextSib)
actdet2 wt (SAZipAp2 x d1 x₁) (SAZipAp1 x₂ d2 x₃)
with synthunicity x x₂
... | refl with actdet2 x d1 d2
actdet2 wt (SAZipAp2 x d1 x₁) (SAZipAp1 x₂ d2 x₃) | refl | p1 , ()
actdet2 wt (SAZipAp2 x d1 _) (SAZipAp2 x₂ d2 _)
with synthunicity x x₂
... | refl = (ap1 (λ q → q ∘₁ _) (π1 (actdet2 x₂ d1 d2))) , refl
actdet2 wt (SAZipAp3 x (AASubsume x₁ (SAMove ()) x₃)) (SAMove EMApParent2)
actdet2 wt (SAZipAp3 x (AAMove ())) (SAMove EMApParent2)
actdet2 wt (SAZipAp3 x x₁) (SAMove EMApPrevSib) = abort (lem9a x₁)
actdet2 wt (SAZipAp3 {eh = eh} x x₁) (SAZipAp3 x₂ x₃)
with synthunicity x x₂
... | refl = ap1 (_∘₂_ _) (actdet3 (lem4 {eh = eh} wt x) x₁ x₃) , refl
actdet2 wt (SAZipAp3 x x₁) (SAZipAp4 x₂ x₃)
with synthunicity x x₂
... | ()
actdet2 wt (SAZipAp4 x (AASubsume x₁ (SAMove ()) x₃)) (SAMove EMApParent2)
actdet2 wt (SAZipAp4 x (AAMove ())) (SAMove EMApParent2)
actdet2 wt (SAZipAp4 x (AASubsume x₁ x₂ x₃)) (SAMove EMApPrevSib) = abort (lem9s x₂)
actdet2 wt (SAZipAp4 x (AAMove ())) (SAMove EMApPrevSib)
actdet2 wt (SAZipAp4 x x₁) (SAZipAp3 x₂ x₃)
with synthunicity x x₂
... | ()
actdet2 wt (SAZipAp4 {eh = eh} x x₁ ) (SAZipAp4 x₂ x₃)
with actdet3 (lem5 {eh = eh} x₂ wt) x₁ x₃
... | refl = refl , refl
actdet2 wt (SAZipPlus1 (AASubsume x (SAMove ()) x₂)) (SAMove EMPlusParent1)
actdet2 wt (SAZipPlus1 (AAMove ())) (SAMove EMPlusParent1)
actdet2 wt (SAZipPlus1 (AASubsume x x₁ x₂)) (SAMove EMPlusNextSib) = abort (lem8s x₁)
actdet2 wt (SAZipPlus1 (AAMove ())) (SAMove EMPlusNextSib)
actdet2 wt (SAZipPlus1 x) (SAZipPlus1 x₁)
with actdet3 (π1 (lem6 wt)) x x₁ -- todo: not sure why this needs to be a lemma
... | refl = refl , refl
actdet2 wt (SAZipPlus2 (AASubsume x (SAMove ()) x₂)) (SAMove EMPlusParent2)
actdet2 wt (SAZipPlus2 (AASubsume x x₁ x₂)) (SAMove EMPlusPrevSib) = abort (lem9s x₁)
actdet2 wt (SAZipPlus2 (AAMove ())) (SAMove EMPlusParent2)
actdet2 wt (SAZipPlus2 (AAMove ())) (SAMove EMPlusPrevSib)
actdet2 wt (SAZipPlus2 x) (SAZipPlus2 x₁)
with actdet3 (π2 (lem6 wt)) x x₁ -- .. or this one
... | refl = refl , refl
actdet2 wt (SAZipHole1 x d1 x₁) (SAMove EMFHoleParent) = abort (lem7 wt d1)
actdet2 wt (SAZipHole1 x d1 x₁) (SAZipHole1 x₂ d2 x₃)
with synthunicity x x₂
... | refl with actdet2 x d1 d2
... | refl , refl = refl , refl
actdet2 wt (SAZipHole1 x d1 x₁) (SAZipHole2 x₂ d2)
with synthunicity x x₂
... | refl with actdet2 x d1 d2
... | p , _ = abort (x₁ p)
actdet2 wt (SAZipHole2 x d1) (SAMove EMFHoleParent) = abort (lem7 wt d1)
actdet2 wt (SAZipHole2 x d1) (SAZipHole1 x₁ d2 x₂)
with synthunicity x x₁
... | refl with actdet2 x d1 d2
... | p , q = abort (x₂ (! p))
actdet2 wt (SAZipHole2 x d1) (SAZipHole2 x₁ d2)
with synthunicity x x₁
... | refl with actdet2 x d1 d2
... | refl , refl = refl , refl
-- an action on an expression in an analytic position produces one
-- resultant expression and type.
actdet3 : {Γ : ·ctx} {e e' e'' : ê} {t : τ̇} {α : action} →
(Γ ⊢ (e ◆e) <= t) →
(Γ ⊢ e ~ α ~> e' ⇐ t) →
(Γ ⊢ e ~ α ~> e'' ⇐ t) →
(e' == e'')
actdet3 D1 (AASubsume x x₁ x₂) (AASubsume x₃ x₄ x₅)
with synthunicity x x₃
... | refl = π1 (actdet2 x x₁ x₄)
actdet3 D1 (AASubsume _ y _) (AAMove w) = synthmovedet y w
actdet3 D1 (AASubsume _ SADel _) AADel = refl
actdet3 D1 (AASubsume {p = p} x SAConAsc x₂) AAConAsc = abort (π1 p refl)
actdet3 {Γ = G} (ASubsume x x₁) (AASubsume x₂ (SAConVar p) x₄) (AAConVar x₅ p₁)
with ctxunicity {Γ = G} p p₁
... | refl = abort (x₅ x₄)
actdet3 D1 (AASubsume {p = p} x₁ (SAConLam x₂) x₃) (AAConLam1 x₄) = abort (π2 p _ refl)
actdet3 D1 (AASubsume x₁ (SAConLam x₃) x₂) (AAConLam2 x₄ x₅) = abort (x₅ x₂)
actdet3 D1 (AASubsume x SAConNumlit x₂) (AAConNumlit x₃) = abort (x₃ x₂)
actdet3 D1 (AASubsume x (SAFinish x₁) x₂) (AAFinish x₃) = refl
actdet3 D1 (AASubsume x₁ (SAMove EMLamParent) x₂) (AAZipLam x₄ (AASubsume x₃ (SAMove ()) x₆))
actdet3 D1 (AASubsume x₁ (SAMove EMLamParent) x₂) (AAZipLam x₄ (AAMove ()))
actdet3 D1 (AAMove x) (AASubsume x₁ x₂ x₃) = ! (synthmovedet x₂ x)
actdet3 D1 (AAMove x) (AAMove x₁) = movedet x x₁
actdet3 D1 (AAMove EMLamParent) (AAZipLam x₃ (AASubsume x₁ (SAMove ()) x₄))
actdet3 D1 (AAMove EMLamParent) (AAZipLam x₃ (AAMove ()))
actdet3 D1 AADel (AASubsume _ SADel _) = refl
actdet3 D1 AADel AADel = refl
actdet3 D1 AAConAsc (AASubsume {p = p} x SAConAsc x₂) = abort (π1 p refl)
actdet3 D1 AAConAsc AAConAsc = refl
actdet3 {Γ = G} D1 (AAConVar x₁ p) (AASubsume x₂ (SAConVar p₁) x₄)
with ctxunicity {Γ = G} p p₁
... | refl = abort (x₁ x₄)
actdet3 D1 (AAConVar x₁ p) (AAConVar x₂ p₁) = refl
actdet3 D1 (AAConLam1 x₃) (AASubsume {p = p} SEHole (SAConLam x₅) x₆) = abort (π2 p _ refl)
actdet3 D1 (AAConLam1 x₁) (AAConLam1 x₂) = refl
actdet3 D1 (AAConLam1 x₃) (AAConLam2 x₄ x₅) = abort (x₅ (lem1 D1))
actdet3 D1 (AAConLam2 x₁ x₂) (AASubsume x₃ (SAConLam x₄) x₅) = abort (x₂ x₅)
actdet3 D1 (AAConLam2 x₁ x₂) (AAConLam1 x₃) = abort (x₂ (lem1 D1))
actdet3 D1 (AAConLam2 x₁ x₂) (AAConLam2 x₃ x₄) = refl
actdet3 D1 (AAConNumlit x) (AASubsume x₁ SAConNumlit x₃) = abort (x x₃)
actdet3 D1 (AAConNumlit x) (AAConNumlit x₁) = refl
actdet3 D1 (AAFinish x) (AASubsume x₁ (SAFinish x₂) x₃) = refl
actdet3 D1 (AAFinish x) (AAFinish x₁) = refl
actdet3 D1 (AAZipLam x₃ D2) (AASubsume x₁ (SAMove EMLamParent) x₄) = abort (lem11 D2)
actdet3 D1 (AAZipLam x₃ (AASubsume x₁ (SAMove ()) x₄)) (AAMove EMLamParent)
actdet3 D1 (AAZipLam x₃ (AAMove ())) (AAMove EMLamParent)
actdet3 D1 (AAZipLam {e = e} x₃ D2) (AAZipLam x₁ D3)
with actdet3 (lem10 {e = e} D1) D2 D3
... | refl = refl
| {
"alphanum_fraction": 0.6315000268,
"avg_line_length": 43.5268065268,
"ext": "agda",
"hexsha": "f0a4e4db5235e6fc3be40f1e7a847a10e38e7ac4",
"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": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ivoysey/agda-tfp16",
"max_forks_repo_path": "Hazelnut-deterministic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"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": "ivoysey/agda-tfp16",
"max_issues_repo_path": "Hazelnut-deterministic.agda",
"max_line_length": 97,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ivoysey/agda-tfp16",
"max_stars_repo_path": "Hazelnut-deterministic.agda",
"max_stars_repo_stars_event_max_datetime": "2016-04-14T02:19:58.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-09T13:35:22.000Z",
"num_tokens": 7802,
"size": 18673
} |
module Text.Greek.SBLGNT-Query where
open import Data.Bool
open import Data.Nat hiding (_≟_)
open import Data.List
open import Data.Maybe
open import Data.Product hiding (map)
open import Function
open import Relation.Binary.PropositionalEquality
open import Text.Greek.Bible
open import Text.Greek.Script
open import Text.Greek.SBLGNT.1John
texts = ΙΩΑΝΝΟΥ-Α ∷ []
wordCount = length ΙΩΑΝΝΟΥ-Α
--tokenCount = length (concat ΙΩΑΝΝΟΥ-Α)
getLetters : Word → List Token
getLetters (word x _) = x
tokens = concatMap getLetters ΙΩΑΝΝΟΥ-Α
adjacent-accent : (Token → Maybe Accent) → List Token → List (Σ Token (const Token))
adjacent-accent f [] = []
adjacent-accent f (_ ∷ []) = []
adjacent-accent f (t₁ ∷ t₂ ∷ ts) with (f t₁) , (f t₂) , adjacent-accent f (t₂ ∷ ts)
… | (just circumflex-mark , just circumflex-mark , ts′) = (t₁ , t₂) ∷ ts′
… | (_ , _ , ts′) = ts′
adj = adjacent-accent get-accent tokens
| {
"alphanum_fraction": 0.7116022099,
"avg_line_length": 28.28125,
"ext": "agda",
"hexsha": "de00ecd1cf1786dfc9d1d81caf8d5f59851ab41e",
"lang": "Agda",
"max_forks_count": 5,
"max_forks_repo_forks_event_max_datetime": "2017-06-11T11:25:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-27T22:34:13.000Z",
"max_forks_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "scott-fleischman/GreekGrammar",
"max_forks_repo_path": "agda/Text/Greek/SBLGNT-Query.agda",
"max_issues_count": 13,
"max_issues_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_issues_repo_issues_event_max_datetime": "2020-09-07T11:58:38.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-28T20:04:08.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "scott-fleischman/GreekGrammar",
"max_issues_repo_path": "agda/Text/Greek/SBLGNT-Query.agda",
"max_line_length": 84,
"max_stars_count": 44,
"max_stars_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "scott-fleischman/GreekGrammar",
"max_stars_repo_path": "agda/Text/Greek/SBLGNT-Query.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-06T15:41:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-29T14:48:51.000Z",
"num_tokens": 332,
"size": 905
} |
{-# OPTIONS --without-K #-}
open import Type using (Type₀; Type_)
open import Type.Identities
open import Function.NP using (Π; _∘_; const)
open import Function.Extensionality using (FunExt)
open import Data.One using (0₁)
open import Data.Two.Base using (0₂; 1₂)
open import Data.Product.NP using (_,_; fst)
open import Data.Sum.NP using (inl; inr)
open import Relation.Binary.PropositionalEquality.NP using (_≡_; idp; ap; !_; _∙_; tr)
open import HoTT using (ua; UA; module Equivalences)
open Equivalences using (_≃_)
open import Explore.Core
open import Explore.Zero
open import Explore.One
open import Explore.Two
open import Explore.Product
open Explore.Product.Operators
open import Explore.Sum
open import Explore.Properties
open import Explore.Explorable
open import Explore.Isomorphism
import Explore.Universe.Type
module Explore.Universe.FromE
(X : Type₀) (Xᵉ : ∀ {ℓ} → Explore ℓ X) where
open Explore.Universe.Type {X}
explore : ∀ {ℓ} u → Explore ℓ (El u)
explore 𝟘ᵁ = 𝟘ᵉ
explore 𝟙ᵁ = 𝟙ᵉ
explore 𝟚ᵁ = 𝟚ᵉ
explore (u₀ ×ᵁ u₁) = explore u₀ ×ᵉ explore u₁
explore (u₀ ⊎ᵁ u₁) = explore u₀ ⊎ᵉ explore u₁
explore (Σᵁ u f) = exploreΣ (explore u) λ {x} → explore (f x)
explore Xᵁ = Xᵉ
explore (≃ᵁ u A e) = explore-iso e (explore u)
module FromXⁱ (Xⁱ : ∀ {ℓ p} → ExploreInd p (Xᵉ {ℓ})) where
explore-ind : ∀ {ℓ p} u → ExploreInd {ℓ} p (explore u)
explore-ind 𝟘ᵁ = 𝟘ⁱ
explore-ind 𝟙ᵁ = 𝟙ⁱ
explore-ind 𝟚ᵁ = 𝟚ⁱ
explore-ind (u₀ ×ᵁ u₁) = explore-ind u₀ ×ⁱ explore-ind u₁
explore-ind (u₀ ⊎ᵁ u₁) = explore-ind u₀ ⊎ⁱ explore-ind u₁
explore-ind (Σᵁ u f) = exploreΣ-ind (explore-ind u) λ {x} → explore-ind (f x)
explore-ind Xᵁ = Xⁱ
explore-ind (≃ᵁ u A e) = explore-iso-ind e (explore-ind u)
module _ (u : U) where
private
uᵉ : ∀ {ℓ} → Explore ℓ (El u)
uᵉ = explore u
uⁱ : ∀ {ℓ p} → ExploreInd {ℓ} p uᵉ
uⁱ = explore-ind u
open FromExploreInd uⁱ public hiding (⟦explore⟧)
ΣᵉU : ∀ {ℓ} → (El u → Type ℓ) → Type ℓ
ΣᵉU = Σᵉ uᵉ
ΠᵉU : ∀ {ℓ} → (El u → Type ℓ) → Type ℓ
ΠᵉU = Πᵉ uᵉ
module Xᴱ = FromExploreInd Xⁱ
ΣᵉX : ∀ {ℓ} → (X → Type ℓ) → Type ℓ
ΣᵉX = Σᵉ Xᵉ
ΠᵉX : ∀ {ℓ} → (X → Type ℓ) → Type ℓ
ΠᵉX = Πᵉ Xᵉ
open Adequacy _≡_
module FromXˢ-ok (Xˢ-ok : Adequate-sum Xᴱ.sum){{_ : UA}}{{_ : FunExt}} where
adequate-sum : ∀ u → Adequate-sum (sum u)
adequate-sum 𝟘ᵁ = 𝟘ˢ-ok
adequate-sum 𝟙ᵁ = 𝟙ˢ-ok
adequate-sum 𝟚ᵁ = 𝟚ˢ-ok
adequate-sum (u₀ ×ᵁ u₁) = adequate-sumΣ (adequate-sum u₀) (adequate-sum u₁)
adequate-sum (u₀ ⊎ᵁ u₁) = adequate-sum⊎ (adequate-sum u₀) (adequate-sum u₁)
adequate-sum (Σᵁ u f) = adequate-sumΣ (adequate-sum u) (λ {x} → adequate-sum (f x))
adequate-sum Xᵁ = Xˢ-ok
adequate-sum (≃ᵁ u A e) = sum-iso-ok e (adequate-sum u)
module FromXˡ (Xˡ : ∀ {ℓ} → Lookup {ℓ} Xᵉ) where
lookup : ∀ {ℓ} u → Lookup {ℓ} (explore u)
lookup 𝟘ᵁ = 𝟘ˡ
lookup 𝟙ᵁ = 𝟙ˡ
lookup 𝟚ᵁ = 𝟚ˡ
lookup (u₀ ×ᵁ u₁) = lookup× {eᴬ = explore u₀} {eᴮ = explore u₁} (lookup u₀) (lookup u₁)
lookup (u₀ ⊎ᵁ u₁) = lookup⊎ {eᴬ = explore u₀} {eᴮ = explore u₁} (lookup u₀) (lookup u₁)
lookup (Σᵁ u f) = lookupΣ {eᴬ = explore u} {eᴮ = λ {x} → explore (f x)} (lookup u) (λ {x} → lookup (f x))
lookup Xᵁ = Xˡ
lookup (≃ᵁ u A e) = lookup-iso e {Aᵉ = explore u} (lookup u)
module FromXᶠ (Xᶠ : ∀ {ℓ} → Focus {ℓ} Xᵉ) where
focus : ∀ {ℓ} u → Focus {ℓ} (explore u)
focus 𝟘ᵁ = 𝟘ᶠ
focus 𝟙ᵁ = 𝟙ᶠ
focus 𝟚ᵁ = 𝟚ᶠ
focus (u₀ ×ᵁ u₁) = focus× {eᴬ = explore u₀} {eᴮ = explore u₁} (focus u₀) (focus u₁)
focus (u₀ ⊎ᵁ u₁) = focus⊎ {eᴬ = explore u₀} {eᴮ = explore u₁} (focus u₀) (focus u₁)
focus (Σᵁ u f) = focusΣ {eᴬ = explore u} {eᴮ = λ {x} → explore (f x)} (focus u) (λ {x} → focus (f x))
focus Xᵁ = Xᶠ
focus (≃ᵁ u A e) = focus-iso e {Aᵉ = explore u} (focus u)
module FromΣᵉX-ok (ΣᵉX-ok : ∀ {ℓ} → Adequate-Σ {ℓ} ΣᵉX){{_ : UA}}{{_ : FunExt}} where
Σᵉ-ok : ∀ {ℓ} u → Adequate-Σ {ℓ} (ΣᵉU u)
Σᵉ-ok 𝟘ᵁ = Σᵉ𝟘-ok
Σᵉ-ok 𝟙ᵁ = Σᵉ𝟙-ok
Σᵉ-ok 𝟚ᵁ = Σᵉ𝟚-ok
Σᵉ-ok (u₀ ×ᵁ u) = Σᵉ×-ok {eᴬ = explore u₀} {eᴮ = explore u} (Σᵉ-ok u₀) (Σᵉ-ok u)
Σᵉ-ok (u₀ ⊎ᵁ u) = Σᵉ⊎-ok {eᴬ = explore u₀} {eᴮ = explore u} (Σᵉ-ok u₀) (Σᵉ-ok u)
Σᵉ-ok (Σᵁ u f) = ΣᵉΣ-ok {eᴬ = explore u} {eᴮ = λ {x} → explore (f x)} (Σᵉ-ok u) (λ {x} → Σᵉ-ok (f x))
Σᵉ-ok Xᵁ = ΣᵉX-ok
Σᵉ-ok (≃ᵁ u A e) = Σ-iso-ok e {Aᵉ = explore u} (Σᵉ-ok u)
module FromΠᵉX-ok (ΠᵉX-ok : ∀ {ℓ} → Adequate-Π {ℓ} ΠᵉX){{_ : UA}}{{_ : FunExt}} where
Πᵉ-ok : ∀ {ℓ} u → Adequate-Π {ℓ} (ΠᵉU u)
Πᵉ-ok 𝟘ᵁ = Πᵉ𝟘-ok
Πᵉ-ok 𝟙ᵁ = Πᵉ𝟙-ok
Πᵉ-ok 𝟚ᵁ = Πᵉ𝟚-ok
Πᵉ-ok (u₀ ×ᵁ u) = Πᵉ×-ok {eᴬ = explore u₀} {eᴮ = explore u} (Πᵉ-ok u₀) (Πᵉ-ok u)
Πᵉ-ok (u₀ ⊎ᵁ u) = Πᵉ⊎-ok {eᴬ = explore u₀} {eᴮ = explore u} (Πᵉ-ok u₀) (Πᵉ-ok u)
Πᵉ-ok (Σᵁ u f) = ΠᵉΣ-ok {eᴬ = explore u} {eᴮ = λ {x} → explore (f x)} (Πᵉ-ok u) (λ {x} → Πᵉ-ok (f x))
Πᵉ-ok Xᵁ = ΠᵉX-ok
Πᵉ-ok (≃ᵁ u A e) = Π-iso-ok e {Aᵉ = explore u} (Πᵉ-ok u)
module From⟦Xᵉ⟧≡ (⟦Xᵉ⟧≡ : ∀ {ℓ₀ ℓ₁} ℓᵣ → ⟦Explore⟧ {ℓ₀} {ℓ₁} ℓᵣ _≡_ Xᵉ Xᵉ) {ℓ₀ ℓ₁} ℓᵣ where
⟦explore⟧≡ : ∀ u → ⟦Explore⟧ {ℓ₀} {ℓ₁} ℓᵣ _≡_ (explore u) (explore u)
⟦explore⟧≡ 𝟘ᵁ = ⟦𝟘ᵉ⟧ {ℓᵣ = ℓᵣ}
⟦explore⟧≡ 𝟙ᵁ = ⟦𝟙ᵉ⟧ {ℓᵣ = ℓᵣ} {_≡_} {idp}
⟦explore⟧≡ 𝟚ᵁ = ⟦𝟚ᵉ⟧ {ℓᵣ = ℓᵣ} {_≡_} {idp} {idp}
⟦explore⟧≡ (u₀ ×ᵁ u₁) = ⟦explore×⟧≡ {ℓᵣ = ℓᵣ} (⟦explore⟧≡ u₀) (⟦explore⟧≡ u₁)
⟦explore⟧≡ (u₀ ⊎ᵁ u₁) = ⟦explore⊎⟧≡ {ℓᵣ = ℓᵣ} (⟦explore⟧≡ u₀) (⟦explore⟧≡ u₁)
⟦explore⟧≡ (Σᵁ u F) = ⟦exploreΣ⟧≡ {ℓᵣ = ℓᵣ} (⟦explore⟧≡ u) (λ x → ⟦explore⟧≡ (F x))
⟦explore⟧≡ Xᵁ = ⟦Xᵉ⟧≡ ℓᵣ
⟦explore⟧≡ (≃ᵁ u A e) = ⟦explore-iso⟧ e {ℓᵣ = ℓᵣ} (ap (fst e)) (⟦explore⟧≡ u)
module FromΠX (ΠX : (X → U) → U) where
Πᵁ : (u : U) (v : El u → U) → U
Πᵁ 𝟘ᵁ v = 𝟙ᵁ
Πᵁ 𝟙ᵁ v = v _
Πᵁ 𝟚ᵁ v = v 0₂ ×ᵁ v 1₂
Πᵁ (u ×ᵁ u₁) v = Πᵁ u λ x → Πᵁ u₁ λ y → v (x , y)
Πᵁ (u ⊎ᵁ u₁) v = (Πᵁ u (v ∘ inl)) ×ᵁ (Πᵁ u₁ (v ∘ inr))
Πᵁ (Σᵁ u f) v = Πᵁ u λ x → Πᵁ (f x) (v ∘ _,_ x)
Πᵁ Xᵁ v = ΠX v
Πᵁ (≃ᵁ u A e)v = Πᵁ u (v ∘ fst e)
_→ᵁ_ : (u : U) (v : U) → U
u →ᵁ v = Πᵁ u (const v)
module FromΠX≃ (ΠX≃ : ∀ v → El (ΠX v) ≃ Π X (El ∘ v)) where
private
module ΠX≃ {v} = Equivalences.Equiv (ΠX≃ v)
module _ {{_ : FunExt}}{{_ : UA}} where
Πᵁ-Π : ∀ u v → El (Πᵁ u v) ≡ Π (El u) (El ∘ v)
Πᵁ-Π 𝟘ᵁ v = ! Π𝟘-uniq₀ _
Πᵁ-Π 𝟙ᵁ v = ! Π𝟙-uniq _
Πᵁ-Π 𝟚ᵁ v = ! Π𝟚-×
Πᵁ-Π (u ×ᵁ u₁) v = Πᵁ-Π u (λ x → Πᵁ u₁ (v ∘ _,_ x)) ∙ Π=′ _ (λ _ → Πᵁ-Π u₁ _) ∙ ! ΠΣ-curry
Πᵁ-Π (u ⊎ᵁ u₁) v = ×= (Πᵁ-Π u (v ∘ inl)) (Πᵁ-Π u₁ (v ∘ inr)) ∙ ! dist-×-Π
Πᵁ-Π (Σᵁ u f) v = Πᵁ-Π u (λ x → Πᵁ (f _) (v ∘ _,_ x)) ∙ Π=′ _ (λ _ → Πᵁ-Π (f _) _) ∙ ! ΠΣ-curry
Πᵁ-Π Xᵁ v = ua (ΠX≃ v)
Πᵁ-Π (≃ᵁ u A e)v = Πᵁ-Π u (v ∘ fst e) ∙ Π≃ e λ _ → idp
→ᵁ-→ : ∀ u v → El (u →ᵁ v) ≡ (El u → El v)
→ᵁ-→ u v = Πᵁ-Π u (const v)
Πᵁ→Π : ∀ u v → El (Πᵁ u v) → Π (El u) (El ∘ v)
Πᵁ→Π 𝟘ᵁ v x₂ ()
Πᵁ→Π 𝟙ᵁ v x₂ x₃ = x₂
Πᵁ→Π 𝟚ᵁ v (x , y) 0₂ = x
Πᵁ→Π 𝟚ᵁ v (x , y) 1₂ = y
Πᵁ→Π (u ×ᵁ u₁) v x (z , t) = Πᵁ→Π u₁ (v ∘ _,_ z) (Πᵁ→Π u (λ x → Πᵁ u₁ (v ∘ _,_ x)) x z) t
Πᵁ→Π (u ⊎ᵁ _) v (x , _) (inl y) = Πᵁ→Π u (v ∘ inl) x y
Πᵁ→Π (_ ⊎ᵁ u) v (_ , x) (inr y) = Πᵁ→Π u (v ∘ inr) x y
Πᵁ→Π (Σᵁ u f) v x (y , z) = Πᵁ→Π (f _) (v ∘ _,_ y) (Πᵁ→Π u (λ x → Πᵁ (f _) (v ∘ _,_ x)) x y) z
Πᵁ→Π Xᵁ v = ΠX≃.·→
Πᵁ→Π (≃ᵁ u A e) v f x = tr (El ∘ v) (·←-inv-r x) (Πᵁ→Π u (v ∘ ·→) f (·← x))
where open Equivalences.Equiv e
Π→Πᵁ : ∀ u v → Π (El u) (El ∘ v) → El (Πᵁ u v)
Π→Πᵁ 𝟘ᵁ v f = 0₁
Π→Πᵁ 𝟙ᵁ v f = f 0₁
Π→Πᵁ 𝟚ᵁ v f = f 0₂ , f 1₂
Π→Πᵁ (u ×ᵁ u₁) v f = Π→Πᵁ u (λ x → Πᵁ u₁ (v ∘ _,_ x))
(λ x → Π→Πᵁ u₁ (v ∘ _,_ x) (f ∘ _,_ x))
Π→Πᵁ (u ⊎ᵁ u₁) v f = Π→Πᵁ u (v ∘ inl) (f ∘ inl) ,
Π→Πᵁ u₁ (v ∘ inr) (f ∘ inr)
Π→Πᵁ (Σᵁ u F) v f = Π→Πᵁ u (λ x → Πᵁ (F x) (v ∘ _,_ x))
(λ x → Π→Πᵁ (F x) (v ∘ _,_ x) (f ∘ _,_ x))
Π→Πᵁ Xᵁ v = ΠX≃.·←
Π→Πᵁ (≃ᵁ u A e) v f = Π→Πᵁ u (v ∘ ·→) (f ∘ ·→)
where open Equivalences.Equiv e
→ᵁ→→ : ∀ u v → El (u →ᵁ v) → (El u → El v)
→ᵁ→→ u v = Πᵁ→Π u (const v)
→→→ᵁ : ∀ u v → (El u → El v) → El (u →ᵁ v)
→→→ᵁ u v = Π→Πᵁ u (const v)
| {
"alphanum_fraction": 0.513221737,
"avg_line_length": 40.6108374384,
"ext": "agda",
"hexsha": "8b6a80e358e539d8c29a3a17d275872bec7707db",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/Universe/FromE.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/Universe/FromE.agda",
"max_line_length": 109,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/Universe/FromE.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 5151,
"size": 8244
} |
open import FRP.JS.Bool using ( Bool ; true ; false ; not ; _∨_ )
open import FRP.JS.True using ( True )
open import FRP.JS.Maybe using ( Maybe ; just ; nothing )
open import FRP.JS.Primitive using ( ℤ ; String )
module FRP.JS.Float where
infixr 4 _≤_ _<_ _≟_ _≠_
infixl 6 _+_ _-_
infixl 7 _*_ _/_ _/?_
open import FRP.JS.Primitive public using ( ℝ )
primitive
primFloatPlus : ℝ -> ℝ -> ℝ
primFloatMinus : ℝ -> ℝ -> ℝ
primFloatTimes : ℝ -> ℝ -> ℝ
primFloatDiv : ℝ -> ℝ -> ℝ
primFloatLess : ℝ -> ℝ -> Bool
primFloor : ℝ -> ℤ
primCeiling : ℝ -> ℤ
primExp : ℝ -> ℝ
primLog : ℝ -> ℝ
primSin : ℝ -> ℝ
primShowFloat : ℝ -> String
primShowInteger : ℤ → String
primIntegerToFloat : ℤ → ℝ
_+_ = primFloatPlus
_-_ = primFloatMinus
_*_ = primFloatTimes
_<_ = primFloatLess
⌊_⌋ = primFloor
⌈_⌉ = primCeiling
exp = primExp
log = primLog
sin = primSin
{-# COMPILED_JS _+_ function(x) { return function(y) { return x + y; }; } #-}
{-# COMPILED_JS _-_ function(x) { return function(y) { return x - y; }; } #-}
{-# COMPILED_JS _*_ function(x) { return function(y) { return x * y; }; } #-}
{-# COMPILED_JS _<_ function(x) { return function(y) { return x < y; }; } #-}
{-# COMPILED_JS ⌊_⌋ Math.floor #-}
{-# COMPILED_JS ⌈_⌉ Math.ceil #-}
{-# COMPILED_JS exp Math.exp #-}
{-# COMPILED_JS log Math.log #-}
{-# COMPILED_JS sin Math.sin #-}
-_ : ℝ → ℝ
- x = 0.0 - x
_≠_ : ℝ → ℝ → Bool
(x ≠ y) = (x < y) ∨ (y < x)
_≟_ : ℝ → ℝ → Bool
(x ≟ y) = not (x ≠ y)
_≤_ : ℝ → ℝ → Bool
(x ≤ y) = not (y < x)
-- Some hoop-jumping to avoid division by zero, so we don't end up with
-- Infinity, -Infinity or NaN.
_/_ : (x y : ℝ) → {y≠0 : True (y ≠ 0.0)} → ℝ
x / y = primFloatDiv x y
_/?_ : ℝ → ℝ → Maybe ℝ
x /? 0.0 = nothing
x /? y = just (primFloatDiv x y)
show : ℝ → String
show x
with (x ≟ primIntegerToFloat ⌊ x ⌋)
... | true = primShowInteger ⌊ x ⌋
... | false = primShowFloat x
{-# COMPILED_JS -_ function(x) { return -x; } #-}
{-# COMPILED_JS _≠_ function(x) { return function(y) { return x !== y; }; } #-}
{-# COMPILED_JS _≟_ function(x) { return function(y) { return x === y; }; } #-}
{-# COMPILED_JS _≤_ function(x) { return function(y) { return x <= y; }; } #-}
{-# COMPILED_JS _/_ function(x) { return function(y) { return function() { return x / y; }; }; } #-}
{-# COMPILED_JS _/?_ function(x) { return function(y) { if (y === 0) { return null; } else { return x / y; } }; } #-}
{-# COMPILED_JS show function(x) { return x.toString(); } #-}
| {
"alphanum_fraction": 0.5589485891,
"avg_line_length": 30.0813953488,
"ext": "agda",
"hexsha": "1b54de3c75a99b560f2685b2469e75acf8c92b87",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z",
"max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_forks_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-frp-js",
"max_forks_repo_path": "src/agda/FRP/JS/Float.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-frp-js",
"max_issues_repo_path": "src/agda/FRP/JS/Float.agda",
"max_line_length": 118,
"max_stars_count": 63,
"max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_stars_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-frp-js",
"max_stars_repo_path": "src/agda/FRP/JS/Float.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z",
"num_tokens": 929,
"size": 2587
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some Vec-related properties
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Properties where
open import Algebra.FunctionProperties
open import Data.Empty using (⊥-elim)
open import Data.Fin as Fin using (Fin; zero; suc; toℕ; fromℕ)
open import Data.Fin.Properties using (_+′_)
open import Data.List.Base as List using (List)
open import Data.Nat
open import Data.Nat.Properties using (+-assoc; ≤-step)
open import Data.Product as Prod
using (_×_; _,_; proj₁; proj₂; <_,_>; uncurry)
open import Data.Vec
open import Function
open import Function.Inverse using (_↔_; inverse)
open import Relation.Binary as B hiding (Decidable)
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≢_; refl; _≗_)
open import Relation.Unary using (Pred; Decidable)
open import Relation.Nullary using (yes; no)
------------------------------------------------------------------------
-- Properties of propositional equality over vectors
module _ {a} {A : Set a} {n} {x y : A} {xs ys : Vec A n} where
∷-injectiveˡ : x ∷ xs ≡ y ∷ ys → x ≡ y
∷-injectiveˡ refl = refl
∷-injectiveʳ : x ∷ xs ≡ y ∷ ys → xs ≡ ys
∷-injectiveʳ refl = refl
∷-injective : (x ∷ xs) ≡ (y ∷ ys) → x ≡ y × xs ≡ ys
∷-injective refl = refl , refl
module _ {a} {A : Set a} where
≡-dec : B.Decidable _≡_ → ∀ {n} → B.Decidable {A = Vec A n} _≡_
≡-dec _≟_ [] [] = yes refl
≡-dec _≟_ (x ∷ xs) (y ∷ ys) with x ≟ y | ≡-dec _≟_ xs ys
... | yes refl | yes refl = yes refl
... | no x≢y | _ = no (x≢y ∘ ∷-injectiveˡ)
... | yes _ | no xs≢ys = no (xs≢ys ∘ ∷-injectiveʳ)
------------------------------------------------------------------------
-- _[_]=_
module _ {a} {A : Set a} where
[]=-injective : ∀ {n} {xs : Vec A n} {i x y} →
xs [ i ]= x → xs [ i ]= y → x ≡ y
[]=-injective here here = refl
[]=-injective (there xsᵢ≡x) (there xsᵢ≡y) = []=-injective xsᵢ≡x xsᵢ≡y
-- See also Data.Vec.Properties.WithK.[]=-irrelevant.
------------------------------------------------------------------------
-- lookup
module _ {a} {A : Set a} where
[]=⇒lookup : ∀ {n} {x : A} {xs} {i : Fin n} →
xs [ i ]= x → lookup xs i ≡ x
[]=⇒lookup here = refl
[]=⇒lookup (there xs[i]=x) = []=⇒lookup xs[i]=x
lookup⇒[]= : ∀ {n} (i : Fin n) {x : A} xs →
lookup xs i ≡ x → xs [ i ]= x
lookup⇒[]= zero (_ ∷ _) refl = here
lookup⇒[]= (suc i) (_ ∷ xs) p = there (lookup⇒[]= i xs p)
[]=↔lookup : ∀ {n i} {x} {xs : Vec A n} →
xs [ i ]= x ↔ lookup xs i ≡ x
[]=↔lookup {i = i} =
inverse []=⇒lookup (lookup⇒[]= _ _)
lookup⇒[]=∘[]=⇒lookup ([]=⇒lookup∘lookup⇒[]= _ i)
where
lookup⇒[]=∘[]=⇒lookup :
∀ {n x xs} {i : Fin n} (p : xs [ i ]= x) →
lookup⇒[]= i xs ([]=⇒lookup p) ≡ p
lookup⇒[]=∘[]=⇒lookup here = refl
lookup⇒[]=∘[]=⇒lookup (there p) =
P.cong there (lookup⇒[]=∘[]=⇒lookup p)
[]=⇒lookup∘lookup⇒[]= :
∀ {n} xs (i : Fin n) {x} (p : lookup xs i ≡ x) →
[]=⇒lookup (lookup⇒[]= i xs p) ≡ p
[]=⇒lookup∘lookup⇒[]= (x ∷ xs) zero refl = refl
[]=⇒lookup∘lookup⇒[]= (x ∷ xs) (suc i) p =
[]=⇒lookup∘lookup⇒[]= xs i p
------------------------------------------------------------------------
-- updateAt (_[_]%=_)
module _ {a} {A : Set a} where
-- (+) updateAt i actually updates the element at index i.
updateAt-updates : ∀ {n} (i : Fin n) {f : A → A} (xs : Vec A n) {x : A} →
xs [ i ]= x → (updateAt i f xs) [ i ]= f x
updateAt-updates zero (x ∷ xs) here = here
updateAt-updates (suc i) (x ∷ xs) (there loc) = there (updateAt-updates i xs loc)
-- (-) updateAt i does not touch the elements at other indices.
updateAt-minimal : ∀ {n} (i j : Fin n) {f : A → A} {x : A} (xs : Vec A n) →
i ≢ j → xs [ i ]= x → (updateAt j f xs) [ i ]= x
updateAt-minimal zero zero (x ∷ xs) 0≢0 here = ⊥-elim (0≢0 refl)
updateAt-minimal zero (suc j) (x ∷ xs) _ here = here
updateAt-minimal (suc i) zero (x ∷ xs) _ (there loc) = there loc
updateAt-minimal (suc i) (suc j) (x ∷ xs) i≢j (there loc) =
there (updateAt-minimal i j xs (i≢j ∘ P.cong suc) loc)
-- The other properties are consequences of (+) and (-).
-- We spell the most natural properties out.
-- Direct inductive proofs are in most cases easier than just using
-- the defining properties.
-- In the explanations, we make use of shorthand f = g ↾ x
-- meaning that f and g agree at point x, i.e. f x ≡ g x.
-- updateAt i is a morphism from the monoid of endofunctions A → A
-- to the monoid of endofunctions Vec A n → Vec A n
-- 1a. relative identity: f = id ↾ (lookup xs i)
-- implies updateAt i f = id ↾ xs
updateAt-id-relative : ∀ {n} (i : Fin n) (xs : Vec A n) {f : A → A} →
f (lookup xs i) ≡ lookup xs i →
updateAt i f xs ≡ xs
updateAt-id-relative zero (x ∷ xs) eq = P.cong (_∷ xs) eq
updateAt-id-relative (suc i) (x ∷ xs) eq = P.cong (x ∷_) (updateAt-id-relative i xs eq)
-- 1b. identity: updateAt i id ≗ id
updateAt-id : ∀ {n} (i : Fin n) (xs : Vec A n) →
updateAt i id xs ≡ xs
updateAt-id i xs = updateAt-id-relative i xs refl
-- 2a. relative composition: f ∘ g = h ↾ (lookup i xs)
-- implies updateAt i f ∘ updateAt i g ≗ updateAt i h
updateAt-compose-relative : ∀ {n} (i : Fin n) {f g h : A → A} (xs : Vec A n) →
f (g (lookup xs i)) ≡ h (lookup xs i) →
updateAt i f (updateAt i g xs) ≡ updateAt i h xs
updateAt-compose-relative zero (x ∷ xs) fg=h = P.cong (_∷ xs) fg=h
updateAt-compose-relative (suc i) (x ∷ xs) fg=h =
P.cong (x ∷_) (updateAt-compose-relative i xs fg=h)
-- 2b. composition: updateAt i f ∘ updateAt i g ≗ updateAt i (f ∘ g)
updateAt-compose : ∀ {n} (i : Fin n) {f g : A → A} →
updateAt i f ∘ updateAt i g ≗ updateAt i (f ∘ g)
updateAt-compose i xs = updateAt-compose-relative i xs refl
-- 3. congruence: updateAt i is a congruence wrt. extensional equality.
-- 3a. If f = g ↾ (lookup i xs)
-- then updateAt i f = updateAt i g ↾ xs
updateAt-cong-relative : ∀ {n} (i : Fin n) {f g : A → A} (xs : Vec A n) →
f (lookup xs i) ≡ g (lookup xs i) →
updateAt i f xs ≡ updateAt i g xs
updateAt-cong-relative zero (x ∷ xs) f=g = P.cong (_∷ xs) f=g
updateAt-cong-relative (suc i) (x ∷ xs) f=g = P.cong (x ∷_) (updateAt-cong-relative i xs f=g)
-- 3b. congruence: f ≗ g → updateAt i f ≗ updateAt i g
updateAt-cong : ∀ {n} (i : Fin n) {f g : A → A} →
f ≗ g → updateAt i f ≗ updateAt i g
updateAt-cong i f≗g xs = updateAt-cong-relative i xs (f≗g (lookup xs i))
-- The order of updates at different indices i ≢ j does not matter.
-- This a consequence of updateAt-updates and updateAt-minimal
-- but easier to prove inductively.
updateAt-commutes : ∀ {n} (i j : Fin n) {f g : A → A} → i ≢ j →
updateAt i f ∘ updateAt j g ≗ updateAt j g ∘ updateAt i f
updateAt-commutes zero zero 0≢0 (x ∷ xs) = ⊥-elim (0≢0 refl)
updateAt-commutes zero (suc j) i≢j (x ∷ xs) = refl
updateAt-commutes (suc i) zero i≢j (x ∷ xs) = refl
updateAt-commutes (suc i) (suc j) i≢j (x ∷ xs) =
P.cong (x ∷_) (updateAt-commutes i j (i≢j ∘ P.cong suc) xs)
-- lookup after updateAt reduces.
-- For same index this is an easy consequence of updateAt-updates
-- using []=↔lookup.
lookup∘updateAt : ∀ {n} (i : Fin n) {f : A → A} →
∀ xs → lookup (updateAt i f xs) i ≡ f (lookup xs i)
lookup∘updateAt i xs =
[]=⇒lookup (updateAt-updates i xs (lookup⇒[]= i _ refl))
-- For different indices it easily follows from updateAt-minimal.
lookup∘updateAt′ : ∀ {n} (i j : Fin n) {f : A → A} → i ≢ j →
∀ xs → lookup (updateAt j f xs) i ≡ lookup xs i
lookup∘updateAt′ i j xs i≢j =
[]=⇒lookup (updateAt-minimal i j i≢j xs (lookup⇒[]= i _ refl))
-- Aliases for notation _[_]%=_
[]%=-id : ∀ {n} (xs : Vec A n) (i : Fin n) → xs [ i ]%= id ≡ xs
[]%=-id xs i = updateAt-id i xs
[]%=-compose : ∀ {n} (xs : Vec A n) (i : Fin n) {f g : A → A} →
xs [ i ]%= f
[ i ]%= g
≡ xs [ i ]%= g ∘ f
[]%=-compose xs i = updateAt-compose i xs
------------------------------------------------------------------------
-- _[_]≔_ (update)
--
-- _[_]≔_ is defined in terms of updateAt, and all of its properties
-- are special cases of the ones for updateAt.
module _ {a} {A : Set a} where
[]≔-idempotent : ∀ {n} (xs : Vec A n) (i : Fin n) {x₁ x₂ : A} →
(xs [ i ]≔ x₁) [ i ]≔ x₂ ≡ xs [ i ]≔ x₂
[]≔-idempotent xs i = updateAt-compose i xs
[]≔-commutes : ∀ {n} (xs : Vec A n) (i j : Fin n) {x y : A} → i ≢ j →
(xs [ i ]≔ x) [ j ]≔ y ≡ (xs [ j ]≔ y) [ i ]≔ x
[]≔-commutes xs i j i≢j = updateAt-commutes j i (i≢j ∘ P.sym) xs
[]≔-updates : ∀ {n} (xs : Vec A n) (i : Fin n) {x : A} →
(xs [ i ]≔ x) [ i ]= x
[]≔-updates xs i = updateAt-updates i xs (lookup⇒[]= i xs refl)
[]≔-minimal : ∀ {n} (xs : Vec A n) (i j : Fin n) {x y : A} → i ≢ j →
xs [ i ]= x → (xs [ j ]≔ y) [ i ]= x
[]≔-minimal xs i j i≢j loc = updateAt-minimal i j xs i≢j loc
[]≔-lookup : ∀ {n} (xs : Vec A n) (i : Fin n) →
xs [ i ]≔ lookup xs i ≡ xs
[]≔-lookup xs i = updateAt-id-relative i xs refl
lookup∘update : ∀ {n} (i : Fin n) (xs : Vec A n) x →
lookup (xs [ i ]≔ x) i ≡ x
lookup∘update i xs x = lookup∘updateAt i xs
lookup∘update′ : ∀ {n} {i j : Fin n} → i ≢ j → ∀ (xs : Vec A n) y →
lookup (xs [ j ]≔ y) i ≡ lookup xs i
lookup∘update′ {n} {i} {j} i≢j xs y = lookup∘updateAt′ i j i≢j xs
------------------------------------------------------------------------
-- map
map-id : ∀ {a n} {A : Set a} → map {n = n} {A} id ≗ id
map-id [] = refl
map-id (x ∷ xs) = P.cong (x ∷_) (map-id xs)
map-cong : ∀ {a b n} {A : Set a} {B : Set b} {f g : A → B} →
f ≗ g → map {n = n} f ≗ map g
map-cong f≗g [] = refl
map-cong f≗g (x ∷ xs) = P.cong₂ _∷_ (f≗g x) (map-cong f≗g xs)
map-∘ : ∀ {a b c n} {A : Set a} {B : Set b} {C : Set c}
(f : B → C) (g : A → B) →
map {n = n} (f ∘ g) ≗ map f ∘ map g
map-∘ f g [] = refl
map-∘ f g (x ∷ xs) = P.cong (f (g x) ∷_) (map-∘ f g xs)
lookup-map : ∀ {a b n} {A : Set a} {B : Set b}
(i : Fin n) (f : A → B) (xs : Vec A n) →
lookup (map f xs) i ≡ f (lookup xs i)
lookup-map zero f (x ∷ xs) = refl
lookup-map (suc i) f (x ∷ xs) = lookup-map i f xs
map-updateAt : ∀ {n a b} {A : Set a} {B : Set b} →
∀ {f : A → B} {g : A → A} {h : B → B} (xs : Vec A n) (i : Fin n)
→ f (g (lookup xs i)) ≡ h (f (lookup xs i))
→ map f (updateAt i g xs) ≡ updateAt i h (map f xs)
map-updateAt (x ∷ xs) zero eq = P.cong (_∷ _) eq
map-updateAt (x ∷ xs) (suc i) eq = P.cong (_ ∷_) (map-updateAt xs i eq)
map-[]≔ : ∀ {n a b} {A : Set a} {B : Set b}
(f : A → B) (xs : Vec A n) (i : Fin n) {x : A} →
map f (xs [ i ]≔ x) ≡ map f xs [ i ]≔ f x
map-[]≔ f xs i = map-updateAt xs i refl
------------------------------------------------------------------------
-- _++_
module _ {a} {A : Set a} {m} {ys ys' : Vec A m} where
-- See also Data.Vec.Properties.WithK.++-assoc.
++-injectiveˡ : ∀ {n} (xs xs' : Vec A n) →
xs ++ ys ≡ xs' ++ ys' → xs ≡ xs'
++-injectiveˡ [] [] _ = refl
++-injectiveˡ (x ∷ xs) (x' ∷ xs') eq =
P.cong₂ _∷_ (∷-injectiveˡ eq) (++-injectiveˡ _ _ (∷-injectiveʳ eq))
++-injectiveʳ : ∀ {n} (xs xs' : Vec A n) →
xs ++ ys ≡ xs' ++ ys' → ys ≡ ys'
++-injectiveʳ [] [] eq = eq
++-injectiveʳ (x ∷ xs) (x' ∷ xs') eq =
++-injectiveʳ xs xs' (∷-injectiveʳ eq)
++-injective : ∀ {n} (xs xs' : Vec A n) →
xs ++ ys ≡ xs' ++ ys' → xs ≡ xs' × ys ≡ ys'
++-injective xs xs' eq =
(++-injectiveˡ xs xs' eq , ++-injectiveʳ xs xs' eq)
module _ {a} {A : Set a} where
lookup-++-< : ∀ {m n} (xs : Vec A m) (ys : Vec A n) →
∀ i (i<m : toℕ i < m) →
lookup (xs ++ ys)i ≡ lookup xs (Fin.fromℕ≤ i<m)
lookup-++-< [] ys i ()
lookup-++-< (x ∷ xs) ys zero (s≤s z≤n) = refl
lookup-++-< (x ∷ xs) ys (suc i) (s≤s (s≤s i<m)) =
lookup-++-< xs ys i (s≤s i<m)
lookup-++-≥ : ∀ {m n} (xs : Vec A m) (ys : Vec A n) →
∀ i (i≥m : toℕ i ≥ m) →
lookup (xs ++ ys) i ≡ lookup ys (Fin.reduce≥ i i≥m)
lookup-++-≥ [] ys i i≥m = refl
lookup-++-≥ (x ∷ xs) ys zero ()
lookup-++-≥ (x ∷ xs) ys (suc i) (s≤s i≥m) = lookup-++-≥ xs ys i i≥m
lookup-++-inject+ : ∀ {m n} (xs : Vec A m) (ys : Vec A n) i →
lookup (xs ++ ys) (Fin.inject+ n i) ≡ lookup xs i
lookup-++-inject+ [] ys ()
lookup-++-inject+ (x ∷ xs) ys zero = refl
lookup-++-inject+ (x ∷ xs) ys (suc i) = lookup-++-inject+ xs ys i
lookup-++-+′ : ∀ {m n} (xs : Vec A m) (ys : Vec A n) i →
lookup (xs ++ ys) (fromℕ m +′ i) ≡ lookup ys i
lookup-++-+′ [] ys zero = refl
lookup-++-+′ [] (y ∷ xs) (suc i) = lookup-++-+′ [] xs i
lookup-++-+′ (x ∷ xs) ys i = lookup-++-+′ xs ys i
[]≔-++-inject+ : ∀ {m n x} (xs : Vec A m) (ys : Vec A n) i →
(xs ++ ys) [ Fin.inject+ n i ]≔ x ≡ (xs [ i ]≔ x) ++ ys
[]≔-++-inject+ [] ys ()
[]≔-++-inject+ (x ∷ xs) ys zero = refl
[]≔-++-inject+ (x ∷ xs) ys (suc i) =
P.cong (x ∷_) $ []≔-++-inject+ xs ys i
------------------------------------------------------------------------
-- zipWith
module _ {a} {A : Set a} {f : A → A → A} where
zipWith-assoc : Associative _≡_ f → ∀ {n} →
Associative _≡_ (zipWith {n = n} f)
zipWith-assoc assoc [] [] [] = refl
zipWith-assoc assoc (x ∷ xs) (y ∷ ys) (z ∷ zs) =
P.cong₂ _∷_ (assoc x y z) (zipWith-assoc assoc xs ys zs)
zipWith-idem : Idempotent _≡_ f → ∀ {n} →
Idempotent _≡_ (zipWith {n = n} f)
zipWith-idem idem [] = refl
zipWith-idem idem (x ∷ xs) =
P.cong₂ _∷_ (idem x) (zipWith-idem idem xs)
zipWith-identityˡ : ∀ {1#} → LeftIdentity _≡_ 1# f → ∀ {n} →
LeftIdentity _≡_ (replicate 1#) (zipWith {n = n} f)
zipWith-identityˡ idˡ [] = refl
zipWith-identityˡ idˡ (x ∷ xs) =
P.cong₂ _∷_ (idˡ x) (zipWith-identityˡ idˡ xs)
zipWith-identityʳ : ∀ {1#} → RightIdentity _≡_ 1# f → ∀ {n} →
RightIdentity _≡_ (replicate 1#) (zipWith {n = n} f)
zipWith-identityʳ idʳ [] = refl
zipWith-identityʳ idʳ (x ∷ xs) =
P.cong₂ _∷_ (idʳ x) (zipWith-identityʳ idʳ xs)
zipWith-zeroˡ : ∀ {0#} → LeftZero _≡_ 0# f → ∀ {n} →
LeftZero _≡_ (replicate 0#) (zipWith {n = n} f)
zipWith-zeroˡ zeˡ [] = refl
zipWith-zeroˡ zeˡ (x ∷ xs) =
P.cong₂ _∷_ (zeˡ x) (zipWith-zeroˡ zeˡ xs)
zipWith-zeroʳ : ∀ {0#} → RightZero _≡_ 0# f → ∀ {n} →
RightZero _≡_ (replicate 0#) (zipWith {n = n} f)
zipWith-zeroʳ zeʳ [] = refl
zipWith-zeroʳ zeʳ (x ∷ xs) =
P.cong₂ _∷_ (zeʳ x) (zipWith-zeroʳ zeʳ xs)
zipWith-inverseˡ : ∀ {⁻¹ 0#} → LeftInverse _≡_ 0# ⁻¹ f → ∀ {n} →
LeftInverse _≡_ (replicate {n = n} 0#) (map ⁻¹) (zipWith f)
zipWith-inverseˡ invˡ [] = refl
zipWith-inverseˡ invˡ (x ∷ xs) =
P.cong₂ _∷_ (invˡ x) (zipWith-inverseˡ invˡ xs)
zipWith-inverseʳ : ∀ {⁻¹ 0#} → RightInverse _≡_ 0# ⁻¹ f → ∀ {n} →
RightInverse _≡_ (replicate {n = n} 0#) (map ⁻¹) (zipWith f)
zipWith-inverseʳ invʳ [] = refl
zipWith-inverseʳ invʳ (x ∷ xs) =
P.cong₂ _∷_ (invʳ x) (zipWith-inverseʳ invʳ xs)
zipWith-distribˡ : ∀ {g} → _DistributesOverˡ_ _≡_ f g → ∀ {n} →
_DistributesOverˡ_ _≡_ (zipWith {n = n} f) (zipWith g)
zipWith-distribˡ distribˡ [] [] [] = refl
zipWith-distribˡ distribˡ (x ∷ xs) (y ∷ ys) (z ∷ zs) =
P.cong₂ _∷_ (distribˡ x y z) (zipWith-distribˡ distribˡ xs ys zs)
zipWith-distribʳ : ∀ {g} → _DistributesOverʳ_ _≡_ f g → ∀ {n} →
_DistributesOverʳ_ _≡_ (zipWith {n = n} f) (zipWith g)
zipWith-distribʳ distribʳ [] [] [] = refl
zipWith-distribʳ distribʳ (x ∷ xs) (y ∷ ys) (z ∷ zs) =
P.cong₂ _∷_ (distribʳ x y z) (zipWith-distribʳ distribʳ xs ys zs)
zipWith-absorbs : ∀ {g} → _Absorbs_ _≡_ f g → ∀ {n} →
_Absorbs_ _≡_ (zipWith {n = n} f) (zipWith g)
zipWith-absorbs abs [] [] = refl
zipWith-absorbs abs (x ∷ xs) (y ∷ ys) =
P.cong₂ _∷_ (abs x y) (zipWith-absorbs abs xs ys)
module _ {a b} {A : Set a} {B : Set b} {f : A → A → B} where
zipWith-comm : (∀ x y → f x y ≡ f y x) → ∀ {n}
(xs ys : Vec A n) → zipWith f xs ys ≡ zipWith f ys xs
zipWith-comm comm [] [] = refl
zipWith-comm comm (x ∷ xs) (y ∷ ys) =
P.cong₂ _∷_ (comm x y) (zipWith-comm comm xs ys)
module _ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} where
zipWith-map₁ : ∀ {n} (_⊕_ : B → C → D) (f : A → B)
(xs : Vec A n) (ys : Vec C n) →
zipWith _⊕_ (map f xs) ys ≡ zipWith (λ x y → f x ⊕ y) xs ys
zipWith-map₁ _⊕_ f [] [] = refl
zipWith-map₁ _⊕_ f (x ∷ xs) (y ∷ ys) =
P.cong (f x ⊕ y ∷_) (zipWith-map₁ _⊕_ f xs ys)
zipWith-map₂ : ∀ {n} (_⊕_ : A → C → D) (f : B → C)
(xs : Vec A n) (ys : Vec B n) →
zipWith _⊕_ xs (map f ys) ≡ zipWith (λ x y → x ⊕ f y) xs ys
zipWith-map₂ _⊕_ f [] [] = refl
zipWith-map₂ _⊕_ f (x ∷ xs) (y ∷ ys) =
P.cong (x ⊕ f y ∷_) (zipWith-map₂ _⊕_ f xs ys)
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
lookup-zipWith : ∀ (f : A → B → C) {n} (i : Fin n) xs ys →
lookup (zipWith f xs ys) i ≡ f (lookup xs i) (lookup ys i)
lookup-zipWith _ zero (x ∷ _) (y ∷ _) = refl
lookup-zipWith _ (suc i) (_ ∷ xs) (_ ∷ ys) = lookup-zipWith _ i xs ys
------------------------------------------------------------------------
-- zip
module _ {a b} {A : Set a} {B : Set b} where
lookup-zip : ∀ {n} (i : Fin n) (xs : Vec A n) (ys : Vec B n) →
lookup (zip xs ys) i ≡ (lookup xs i , lookup ys i)
lookup-zip = lookup-zipWith _,_
-- map lifts projections to vectors of products.
map-proj₁-zip : ∀ {n} (xs : Vec A n) (ys : Vec B n) →
map proj₁ (zip xs ys) ≡ xs
map-proj₁-zip [] [] = refl
map-proj₁-zip (x ∷ xs) (y ∷ ys) = P.cong (x ∷_) (map-proj₁-zip xs ys)
map-proj₂-zip : ∀ {n} (xs : Vec A n) (ys : Vec B n) →
map proj₂ (zip xs ys) ≡ ys
map-proj₂-zip [] [] = refl
map-proj₂-zip (x ∷ xs) (y ∷ ys) = P.cong (y ∷_) (map-proj₂-zip xs ys)
-- map lifts pairing to vectors of products.
map-<,>-zip : ∀ {a b c n} {A : Set a} {B : Set b} {C : Set c}
(f : A → B) (g : A → C) (xs : Vec A n) →
map < f , g > xs ≡ zip (map f xs) (map g xs)
map-<,>-zip f g [] = P.refl
map-<,>-zip f g (x ∷ xs) = P.cong (_ ∷_) (map-<,>-zip f g xs)
map-zip : ∀ {a b c d n} {A : Set a} {B : Set b} {C : Set c} {D : Set d}
(f : A → B) (g : C → D) (xs : Vec A n) (ys : Vec C n) →
map (Prod.map f g) (zip xs ys) ≡ zip (map f xs) (map g ys)
map-zip f g [] [] = refl
map-zip f g (x ∷ xs) (y ∷ ys) = P.cong (_ ∷_) (map-zip f g xs ys)
------------------------------------------------------------------------
-- unzip
module _ {a b} {A : Set a} {B : Set b} where
lookup-unzip : ∀ {n} (i : Fin n) (xys : Vec (A × B) n) →
let xs , ys = unzip xys
in (lookup xs i , lookup ys i) ≡ lookup xys i
lookup-unzip () []
lookup-unzip zero ((x , y) ∷ xys) = refl
lookup-unzip (suc i) ((x , y) ∷ xys) = lookup-unzip i xys
map-unzip : ∀ {c d n} {C : Set c} {D : Set d}
(f : A → B) (g : C → D) (xys : Vec (A × C) n) →
let xs , ys = unzip xys
in (map f xs , map g ys) ≡ unzip (map (Prod.map f g) xys)
map-unzip f g [] = refl
map-unzip f g ((x , y) ∷ xys) =
P.cong (Prod.map (f x ∷_) (g y ∷_)) (map-unzip f g xys)
-- Products of vectors are isomorphic to vectors of products.
unzip∘zip : ∀ {n} (xs : Vec A n) (ys : Vec B n) →
unzip (zip xs ys) ≡ (xs , ys)
unzip∘zip [] [] = refl
unzip∘zip (x ∷ xs) (y ∷ ys) =
P.cong (Prod.map (x ∷_) (y ∷_)) (unzip∘zip xs ys)
zip∘unzip : ∀ {n} (xys : Vec (A × B) n) →
uncurry zip (unzip xys) ≡ xys
zip∘unzip [] = refl
zip∘unzip ((x , y) ∷ xys) = P.cong ((x , y) ∷_) (zip∘unzip xys)
×v↔v× : ∀ {n} → (Vec A n × Vec B n) ↔ Vec (A × B) n
×v↔v× = inverse (uncurry zip) unzip (uncurry unzip∘zip) zip∘unzip
------------------------------------------------------------------------
-- _⊛_
module _ {a b} {A : Set a} {B : Set b} where
lookup-⊛ : ∀ {n} i (fs : Vec (A → B) n) (xs : Vec A n) →
lookup (fs ⊛ xs) i ≡ (lookup fs i $ lookup xs i)
lookup-⊛ zero (f ∷ fs) (x ∷ xs) = refl
lookup-⊛ (suc i) (f ∷ fs) (x ∷ xs) = lookup-⊛ i fs xs
map-is-⊛ : ∀ {n} (f : A → B) (xs : Vec A n) →
map f xs ≡ (replicate f ⊛ xs)
map-is-⊛ f [] = refl
map-is-⊛ f (x ∷ xs) = P.cong (_ ∷_) (map-is-⊛ f xs)
⊛-is-zipWith : ∀ {n} (fs : Vec (A → B) n) (xs : Vec A n) →
(fs ⊛ xs) ≡ zipWith _$_ fs xs
⊛-is-zipWith [] [] = refl
⊛-is-zipWith (f ∷ fs) (x ∷ xs) = P.cong (f x ∷_) (⊛-is-zipWith fs xs)
zipWith-is-⊛ : ∀ {c} {C : Set c} {n} (f : A → B → C) →
(xs : Vec A n) (ys : Vec B n) →
zipWith f xs ys ≡ (replicate f ⊛ xs ⊛ ys)
zipWith-is-⊛ f [] [] = refl
zipWith-is-⊛ f (x ∷ xs) (y ∷ ys) = P.cong (_ ∷_) (zipWith-is-⊛ f xs ys)
------------------------------------------------------------------------
-- foldr
-- See also Data.Vec.Properties.WithK.foldr-cong.
-- The (uniqueness part of the) universality property for foldr.
foldr-universal : ∀ {a b} {A : Set a} (B : ℕ → Set b)
(f : ∀ {n} → A → B n → B (suc n)) {e}
(h : ∀ {n} → Vec A n → B n) →
h [] ≡ e →
(∀ {n} x → h ∘ (x ∷_) ≗ f {n} x ∘ h) →
∀ {n} → h ≗ foldr B {n} f e
foldr-universal B f {_} h base step [] = base
foldr-universal B f {e} h base step (x ∷ xs) = begin
h (x ∷ xs)
≡⟨ step x xs ⟩
f x (h xs)
≡⟨ P.cong (f x) (foldr-universal B f h base step xs) ⟩
f x (foldr B f e xs)
∎
where open P.≡-Reasoning
foldr-fusion : ∀ {a b c} {A : Set a}
{B : ℕ → Set b} {f : ∀ {n} → A → B n → B (suc n)} e
{C : ℕ → Set c} {g : ∀ {n} → A → C n → C (suc n)}
(h : ∀ {n} → B n → C n) →
(∀ {n} x → h ∘ f {n} x ≗ g x ∘ h) →
∀ {n} → h ∘ foldr B {n} f e ≗ foldr C g (h e)
foldr-fusion {B = B} {f} e {C} h fuse =
foldr-universal C _ _ refl (λ x xs → fuse x (foldr B f e xs))
idIsFold : ∀ {a n} {A : Set a} → id ≗ foldr (Vec A) {n} _∷_ []
idIsFold = foldr-universal _ _ id refl (λ _ _ → refl)
------------------------------------------------------------------------
-- sum
sum-++-commute : ∀ {m n} (xs : Vec ℕ m) {ys : Vec ℕ n} →
sum (xs ++ ys) ≡ sum xs + sum ys
sum-++-commute [] {_} = refl
sum-++-commute (x ∷ xs) {ys} = begin
x + sum (xs ++ ys) ≡⟨ P.cong (x +_) (sum-++-commute xs) ⟩
x + (sum xs + sum ys) ≡⟨ P.sym (+-assoc x (sum xs) (sum ys)) ⟩
sum (x ∷ xs) + sum ys ∎
where open P.≡-Reasoning
------------------------------------------------------------------------
-- replicate
lookup-replicate : ∀ {a n} {A : Set a} (i : Fin n) (x : A) →
lookup (replicate x) i ≡ x
lookup-replicate zero = λ _ → refl
lookup-replicate (suc i) = lookup-replicate i
map-replicate : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) (x : A) →
∀ n → map f (replicate x) ≡ replicate {n = n} (f x)
map-replicate f x zero = refl
map-replicate f x (suc n) = P.cong (f x ∷_) (map-replicate f x n)
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
zipWith-replicate₁ : ∀ {n} (_⊕_ : A → B → C) (x : A) (ys : Vec B n) →
zipWith _⊕_ (replicate x) ys ≡ map (x ⊕_) ys
zipWith-replicate₁ _⊕_ x [] = refl
zipWith-replicate₁ _⊕_ x (y ∷ ys) =
P.cong (x ⊕ y ∷_) (zipWith-replicate₁ _⊕_ x ys)
zipWith-replicate₂ : ∀ {n} (_⊕_ : A → B → C) (xs : Vec A n) (y : B) →
zipWith _⊕_ xs (replicate y) ≡ map (_⊕ y) xs
zipWith-replicate₂ _⊕_ [] y = refl
zipWith-replicate₂ _⊕_ (x ∷ xs) y =
P.cong (x ⊕ y ∷_) (zipWith-replicate₂ _⊕_ xs y)
------------------------------------------------------------------------
-- tabulate
lookup∘tabulate : ∀ {a n} {A : Set a} (f : Fin n → A) (i : Fin n) →
lookup (tabulate f) i ≡ f i
lookup∘tabulate f zero = refl
lookup∘tabulate f (suc i) = lookup∘tabulate (f ∘ suc) i
tabulate∘lookup : ∀ {a n} {A : Set a} (xs : Vec A n) →
tabulate (lookup xs) ≡ xs
tabulate∘lookup [] = refl
tabulate∘lookup (x ∷ xs) = P.cong (x ∷_) (tabulate∘lookup xs)
tabulate-∘ : ∀ {n a b} {A : Set a} {B : Set b}
(f : A → B) (g : Fin n → A) →
tabulate (f ∘ g) ≡ map f (tabulate g)
tabulate-∘ {zero} f g = refl
tabulate-∘ {suc n} f g = P.cong (f (g zero) ∷_) (tabulate-∘ f (g ∘ suc))
tabulate-cong : ∀ {n a} {A : Set a} {f g : Fin n → A} → f ≗ g → tabulate f ≡ tabulate g
tabulate-cong {zero} p = refl
tabulate-cong {suc n} p = P.cong₂ _∷_ (p zero) (tabulate-cong (p ∘ suc))
------------------------------------------------------------------------
-- allFin
lookup-allFin : ∀ {n} (i : Fin n) → lookup (allFin n) i ≡ i
lookup-allFin = lookup∘tabulate id
allFin-map : ∀ n → allFin (suc n) ≡ zero ∷ map suc (allFin n)
allFin-map n = P.cong (zero ∷_) $ tabulate-∘ suc id
tabulate-allFin : ∀ {n a} {A : Set a} (f : Fin n → A) →
tabulate f ≡ map f (allFin n)
tabulate-allFin f = tabulate-∘ f id
-- If you look up every possible index, in increasing order, then you
-- get back the vector you started with.
map-lookup-allFin : ∀ {a} {A : Set a} {n} (xs : Vec A n) →
map (lookup xs) (allFin n) ≡ xs
map-lookup-allFin {n = n} xs = begin
map (lookup xs) (allFin n) ≡˘⟨ tabulate-∘ (lookup xs) id ⟩
tabulate (lookup xs) ≡⟨ tabulate∘lookup xs ⟩
xs ∎
where open P.≡-Reasoning
------------------------------------------------------------------------
-- count
module _ {a p} {A : Set a} {P : Pred A p} (P? : Decidable P) where
count≤n : ∀ {n} (xs : Vec A n) → count P? xs ≤ n
count≤n [] = z≤n
count≤n (x ∷ xs) with P? x
... | yes _ = s≤s (count≤n xs)
... | no _ = ≤-step (count≤n xs)
------------------------------------------------------------------------
-- insert
module _ {a} {A : Set a} where
insert-lookup : ∀ {n} (xs : Vec A n) (i : Fin (suc n)) (v : A) →
lookup (insert xs i v) i ≡ v
insert-lookup xs zero v = refl
insert-lookup [] (suc ()) v
insert-lookup (x ∷ xs) (suc i) v = insert-lookup xs i v
insert-punchIn : ∀ {n} (xs : Vec A n) (i : Fin (suc n)) (v : A)
(j : Fin n) →
lookup (insert xs i v) (Fin.punchIn i j) ≡ lookup xs j
insert-punchIn xs zero v j = refl
insert-punchIn [] (suc ()) v j
insert-punchIn (x ∷ xs) (suc i) v zero = refl
insert-punchIn (x ∷ xs) (suc i) v (suc j) = insert-punchIn xs i v j
remove-punchOut : ∀ {n} (xs : Vec A (suc n))
{i : Fin (suc n)} {j : Fin (suc n)} (i≢j : i ≢ j) →
lookup (remove xs i) (Fin.punchOut i≢j) ≡ lookup xs j
remove-punchOut (x ∷ xs) {zero} {zero} i≢j = ⊥-elim (i≢j refl)
remove-punchOut (x ∷ xs) {zero} {suc j} i≢j = refl
remove-punchOut (x ∷ []) {suc ()} {j} i≢j
remove-punchOut (x ∷ y ∷ xs) {suc i} {zero} i≢j = refl
remove-punchOut (x ∷ y ∷ xs) {suc i} {suc j} i≢j =
remove-punchOut (y ∷ xs) (i≢j ∘ P.cong suc)
------------------------------------------------------------------------
-- remove
remove-insert : ∀ {n} (xs : Vec A n) (i : Fin (suc n)) (v : A) →
remove (insert xs i v) i ≡ xs
remove-insert xs zero v = refl
remove-insert [] (suc ()) v
remove-insert (x ∷ xs) (suc zero) v = refl
remove-insert (x ∷ []) (suc (suc ())) v
remove-insert (x ∷ y ∷ xs) (suc (suc i)) v =
P.cong (x ∷_) (remove-insert (y ∷ xs) (suc i) v)
insert-remove : ∀ {n} (xs : Vec A (suc n)) (i : Fin (suc n)) →
insert (remove xs i) i (lookup xs i) ≡ xs
insert-remove (x ∷ xs) zero = refl
insert-remove (x ∷ []) (suc ())
insert-remove (x ∷ y ∷ xs) (suc i) =
P.cong (x ∷_) (insert-remove (y ∷ xs) i)
------------------------------------------------------------------------
-- Conversion function
module _ {a} {A : Set a} where
toList∘fromList : (xs : List A) → toList (fromList xs) ≡ xs
toList∘fromList List.[] = refl
toList∘fromList (x List.∷ xs) = P.cong (x List.∷_) (toList∘fromList xs)
| {
"alphanum_fraction": 0.4662379421,
"avg_line_length": 39.9256756757,
"ext": "agda",
"hexsha": "835b7c1e17f0444d424c41b25c4da8eae586d585",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Properties.agda",
"max_line_length": 95,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 11592,
"size": 29545
} |
-- ASR (2016-12-23). UHC and GHC have different behaviours. This test
-- only is disabled for the UHC backend.
-- Issue #1856: UHC prints doubles with lower precision than GHC
--
-- For example, printing √2
--
-- GHC (8.0.1): 1.4142135623730951
-- UHC (1.1.9.5): 1.414213562373095
module _ where
open import Common.Prelude
print : Float → IO Unit
print x = putStrLn (primShowFloat x)
pi : Float
pi = 3.141592653589793
main : IO Unit
main =
-- See Issue #1856.
putStr "√2 = " ,, print (primFloatSqrt 2.0) ,,
putStr "√2 = " ,, print (primFloatTimes 2.0 (primSin (primFloatDiv pi 4.0))) ,,
return unit
| {
"alphanum_fraction": 0.6731707317,
"avg_line_length": 22.7777777778,
"ext": "agda",
"hexsha": "b4200b4b025e00f81906e739e951f3a8e6462c03",
"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/Compiler/simple/FloatsUHCFails.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"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": "hborum/agda",
"max_issues_repo_path": "test/Compiler/simple/FloatsUHCFails.agda",
"max_line_length": 81,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Compiler/simple/FloatsUHCFails.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": 218,
"size": 615
} |
data A : Set₁ → Set where
C : (S : Set₁) → A S
| {
"alphanum_fraction": 0.5,
"avg_line_length": 12.5,
"ext": "agda",
"hexsha": "91df63311b8a124a7121aa4e247bc44172c85f11",
"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/Issue3131.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/Issue3131.agda",
"max_line_length": 25,
"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/Issue3131.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": 23,
"size": 50
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
import LibraBFT.Yasm.Types as LYT
import LibraBFT.Yasm.Base as LYB
import LibraBFT.Yasm.System as LYS
-- This module provides some definitions and properties that facilitate
-- proofs of properties about a distributed system modeled by Yasm.System
-- paramaterized by some SystemParameters.
module LibraBFT.Yasm.Properties
(ℓ-PeerState : Level)
(ℓ-VSFP : Level)
(parms : LYB.SystemParameters ℓ-PeerState)
-- In addition to the parameters used by the rest of the system model, this module
-- needs to relate Members to PKs and PeerIds, so that StepPeerState-AllValidParts
-- can be defined. This enables the application to prove that honest peers sign
-- new messages only for their own public key. The system model does not know that
-- directly.
-- A ValidPartForPK collects the assumptions about what a /part/ in the outputs of an honest verifier
-- satisfies: (i) the epoch field is consistent with the existent epochs and (ii) the verifier is
-- a member of the associated epoch config, and (iii) has the given PK in that epoch.
(ValidSenderForPK : LYS.ValidSenderForPK-type ℓ-PeerState ℓ-VSFP parms)
-- A valid part remains valid across state transitions (including cheat steps)
(ValidSenderForPK-stable : LYS.ValidSenderForPK-stable-type ℓ-PeerState ℓ-VSFP parms ValidSenderForPK)
where
open LYB.SystemParameters parms
open import LibraBFT.Yasm.Base
open import LibraBFT.Yasm.System ℓ-PeerState ℓ-VSFP parms
open import Util.FunctionOverride PeerId _≟PeerId_
-- A few handy properties for transporting information about whether a Signature is ∈GenInfo to
-- another type containing the same signature
transp-∈GenInfo₀ : ∀ {pk p1 p2}
→ (ver1 : WithVerSig {Part} ⦃ Part-sig ⦄ pk p1)
→ (ver2 : WithVerSig {Part} ⦃ Part-sig ⦄ pk p2)
→ ver-signature ver1 ≡ ver-signature ver2
→ ∈GenInfo (ver-signature ver1)
→ ∈GenInfo (ver-signature ver2)
transp-∈GenInfo₀ ver1 ver2 sigs≡ init = subst ∈GenInfo sigs≡ init
transp-¬∈GenInfo₁ : ∀ {pk pool sig}
→ ¬ ∈GenInfo sig
→ (mws : MsgWithSig∈ pk sig pool)
→ ¬ ∈GenInfo (ver-signature (msgSigned mws))
transp-¬∈GenInfo₁ ¬init mws rewrite sym (msgSameSig mws) = ¬init
transp-¬∈GenInfo₂ : ∀ {pk sig1 sig2 pool}
→ (mws1 : MsgWithSig∈ pk sig1 pool)
→ ¬ (∈GenInfo (ver-signature (msgSigned mws1)))
→ (mws2 : MsgWithSig∈ pk sig2 pool)
→ sig2 ≡ sig1
→ ¬ (∈GenInfo (ver-signature (msgSigned mws2)))
transp-¬∈GenInfo₂ mws1 ¬init mws2 refl = ¬subst {P = ∈GenInfo} ¬init (trans (msgSameSig mws2) (sym (msgSameSig mws1)))
¬cheatForgeNew : ∀ {pid pk vsig mst outs m}{st : SystemState}
→ (sp : StepPeer st pid mst outs)
→ outs ≡ LYT.send m ∷ []
→ (ic : isCheat sp)
→ Meta-Honest-PK pk
→ (mws : MsgWithSig∈ pk vsig ((pid , m) ∷ msgPool st))
→ ¬ (∈GenInfo (ver-signature (msgSigned mws)))
→ MsgWithSig∈ pk vsig (msgPool st)
¬cheatForgeNew {st = st} sc@(step-cheat isch) refl _ hpk mws ¬init
with msg∈pool mws
...| there m∈pool = mkMsgWithSig∈ (msgWhole mws) (msgPart mws) (msg⊆ mws) (msgSender mws) m∈pool (msgSigned mws) (msgSameSig mws)
...| here m∈pool
with cong proj₂ m∈pool
...| refl
with isch (msg⊆ mws) (msgSigned mws) ¬init
...| inj₁ dis = ⊥-elim (hpk dis)
...| inj₂ mws' rewrite msgSameSig mws = mws'
ValidSenderForPK-stable-* : ∀{st : SystemState}{st' : SystemState}
→ ReachableSystemState st
→ Step* st st' → ∀{part α pk}
→ ValidSenderForPK st part α pk
→ ValidSenderForPK st' part α pk
ValidSenderForPK-stable-* _ step-0 v = v
ValidSenderForPK-stable-* r (step-s {pre = st''} st''reach x) {part} {α} {pk} v =
ValidSenderForPK-stable (Step*-trans r st''reach) x
(ValidSenderForPK-stable-* r st''reach v)
-- We say that an implementation produces only valid parts iff all parts of every message in the
-- output of a 'StepPeerState' are either: (i) a valid new part (i.e., the part is valid and no
-- message with the same signature has been sent previously), or (ii) a message has been sent
-- with the same signature.
StepPeerState-AllValidParts : Set (ℓ-VSFP ℓ⊔ ℓ+1 ℓ-PeerState)
StepPeerState-AllValidParts = ∀{s m part pk outs}{α}{st : SystemState}
→ (r : ReachableSystemState st)
→ Meta-Honest-PK pk
→ (sps : StepPeerState α (msgPool st) (initialised st) (peerStates st α) (s , outs))
→ LYT.send m ∈ outs → part ⊂Msg m → (ver : WithVerSig pk part)
→ ¬ (∈GenInfo (ver-signature ver))
-- Note that we require that α can send for the PK according to the *post* state. This allows
-- sufficient generality to ensure that a peer can sign and send a message for an epoch even if
-- it changed to the epoch in the same step. If this is too painful, we could require that the
-- peer can sign for the PK already in the prestate, which would require, for example,
-- initialising a peer to be a separate step from sending its first signed message, which in
-- turn could preclude some valid implementations.
→ (ValidSenderForPK (StepPeer-post {pre = st} (step-honest sps)) part α pk × ¬ (MsgWithSig∈ pk (ver-signature ver) (msgPool st)))
⊎ MsgWithSig∈ pk (ver-signature ver) (msgPool st)
-- A /part/ was introduced by a specific step when:
IsValidNewPart : ∀{pre : SystemState}{post : SystemState} → Signature → PK → Step pre post → Set (ℓ-VSFP ℓ⊔ ℓ+1 ℓ-PeerState)
-- said step is a /step-peer/ and
IsValidNewPart {pre} {post} sig pk (step-peer {pid = pid} pstep)
-- the part has never been seen before
= ReachableSystemState pre
× ¬ ∈GenInfo sig
× ¬ (MsgWithSig∈ pk sig (msgPool pre))
× Σ (MsgWithSig∈ pk sig (msgPool (StepPeer-post pstep)))
(λ m → msgSender m ≡ pid × initialised post pid ≡ initd × ValidSenderForPK post (msgPart m) (msgSender m) pk)
mwsAndVspk-stable : ∀{st : SystemState}{st' : SystemState}
→ ReachableSystemState st
→ Step* st st'
→ ∀ {pk sig}
→ (mws : MsgWithSig∈ pk sig (msgPool st))
→ initialised st (msgSender mws) ≡ initd
→ ValidSenderForPK st (msgPart mws) (msgSender mws) pk
→ Σ (MsgWithSig∈ pk sig (msgPool st')) λ mws' →
ValidSenderForPK st' (msgPart mws') (msgSender mws') pk
mwsAndVspk-stable {_} {st'} r tr {pk} {sig} mws ini vpk = MsgWithSig∈-Step* tr mws
, subst₂ (λ p s → ValidSenderForPK st' p s pk)
(MsgWithSig∈-Step*-part tr mws)
(MsgWithSig∈-Step*-sender tr mws)
(ValidSenderForPK-stable-* r tr vpk)
-- When we can prove that the implementation provided by 'parms' at the
-- top of this module satisfies 'StepPeerState-AllValidParts', we can
-- prove a number of useful structural properties:
-- TODO-2: Refactor into a file (LibraBFT.Yasm.Properties.Structural) later on
-- if this grows too large.
module Structural (sps-avp : StepPeerState-AllValidParts) where
-- We can unwind the state and highlight the step where a part was
-- originally sent. This 'unwind' function combined with Any-Step-elim
-- enables a powerful form of reasoning. The 'honestVoteEpoch' below
-- exemplifies this well.
unwind : ∀{st : SystemState}(tr : ReachableSystemState st)
→ ∀{p m σ pk} → Meta-Honest-PK pk
→ p ⊂Msg m → (σ , m) ∈ msgPool st → (ver : WithVerSig pk p)
→ ¬ ∈GenInfo (ver-signature ver)
→ Any-Step (IsValidNewPart (ver-signature ver) pk) tr
unwind (step-s tr (step-peer {pid = β} {outs = outs} {pre = pre} sp)) hpk p⊂m m∈sm sig ¬init
with Any-++⁻ (actionsToSentMessages β outs) {msgPool pre} m∈sm
...| inj₂ furtherBack = step-there (unwind tr hpk p⊂m furtherBack sig ¬init)
...| inj₁ thisStep
with sp
...| step-cheat isCheat
with thisStep
...| here refl
with isCheat p⊂m sig ¬init
...| inj₁ abs = ⊥-elim (hpk abs)
...| inj₂ sentb4
with unwind tr {p = msgPart sentb4} hpk (msg⊆ sentb4) (msg∈pool sentb4) (msgSigned sentb4)
(transp-¬∈GenInfo₁ ¬init sentb4)
...| res rewrite msgSameSig sentb4 = step-there res
unwind (step-s tr (step-peer {pid = β} {outs = outs} {pre = pre} sp)) hpk p⊂m m∈sm sig ¬init
| inj₁ thisStep
| step-honest x
with senderMsgPair∈⇒send∈ outs thisStep
...| m∈outs , refl
with sps-avp tr hpk x m∈outs p⊂m sig ¬init
...| inj₂ sentb4 with unwind tr {p = msgPart sentb4} hpk (msg⊆ sentb4) (msg∈pool sentb4) (msgSigned sentb4)
(¬subst {P = ∈GenInfo} ¬init (msgSameSig sentb4))
...| res rewrite msgSameSig sentb4 = step-there res
unwind (step-s tr (step-peer {pid = β} {outs = outs} {pre = pre} sp)) {p} hpk p⊂m m∈sm sig ¬init
| inj₁ thisStep
| step-honest x
| m∈outs , refl
| inj₁ (valid-part , notBefore) = step-here tr (tr , ¬init , notBefore , mws∈pool , refl , override-target-≡ , valid-part)
where mws∈pool : MsgWithSig∈ _ (WithSig.signature Part-sig _ (isSigned sig)) (actionsToSentMessages β outs ++ msgPool pre)
mws∈pool = MsgWithSig∈-++ˡ (mkMsgWithSig∈ _ _ p⊂m β thisStep sig refl)
-- Unwind is inconvenient to use by itself because we have to do
-- induction on Any-Step-elim. The 'honestPartValid' property below
-- provides a fairly general result conveniently: for every part
-- verifiable with an honest PK, there is a msg with the same
-- signature that is valid for some pid.
honestPartValid : ∀ {st} → ReachableSystemState st → ∀ {pk nm v sender}
→ Meta-Honest-PK pk
→ v ⊂Msg nm → (sender , nm) ∈ msgPool st → (ver : WithVerSig pk v)
→ ¬ ∈GenInfo (ver-signature ver)
→ Σ (MsgWithSig∈ pk (ver-signature ver) (msgPool st))
(λ msg → (ValidSenderForPK st (msgPart msg) (msgSender msg) pk))
honestPartValid {st} r {pk = pk} hpk v⊂m m∈pool ver ¬init
-- We extract two pieces of important information from the place where the part 'v'
-- was first sent: (a) there is a message with the same signature /in the current pool/
-- and (b) its epoch is less than e.
= Any-Step-elim (λ { {st = step-peer {pid = pid} (step-honest sps)} (preReach , ¬init , ¬sentb4 , new , refl , ini , valid) tr
→ mwsAndVspk-stable (step-s preReach (step-peer (step-honest sps))) tr new ini valid
; {st = step-peer {pid = pid} {pre = pre} (step-cheat {pid} sps)} (preReach , ¬init , ¬sentb4 , new , refl , valid) tr
→ ⊥-elim (¬sentb4 (¬cheatForgeNew {st = pre} (step-cheat sps) refl unit hpk new (transp-¬∈GenInfo₁ ¬init new)))
})
(unwind r hpk v⊂m m∈pool ver ¬init)
-- Unforgeability is also an important property stating that every part that is
-- verified with an honest public key has either been sent by α or is a replay
-- of another message sent before.
ext-unforgeability'
: ∀{α m part pk}{st : SystemState} → ReachableSystemState st
-- If a message m has been sent by α, containing part
→ (α , m) ∈ msgPool st → part ⊂Msg m
-- And the part can be verified with an honest public key,
→ (sig : WithVerSig pk part) → ¬ ∈GenInfo (ver-signature sig)
→ Meta-Honest-PK pk
-- then either the part is a valid part by α (meaning that α can
-- sign the part itself) or a message with the same signature has
-- been sent previously.
→ ValidSenderForPK st part α pk
⊎ MsgWithSig∈ pk (ver-signature sig) (msgPool st)
ext-unforgeability' {part = part} (step-s st (step-peer {pid = β} {outs = outs} {pre = pre} sp)) m∈sm p⊆m sig ¬init hpk
with Any-++⁻ (actionsToSentMessages β outs) {msgPool pre} m∈sm
...| inj₂ furtherBack = MsgWithSig∈-++ʳ <⊎$> ⊎-map (ValidSenderForPK-stable st (step-peer sp)) id
(ext-unforgeability' st furtherBack p⊆m sig ¬init hpk)
...| inj₁ thisStep
with sp
...| step-cheat isCheat
with thisStep
...| here refl
with isCheat p⊆m sig ¬init
...| inj₁ abs = ⊥-elim (hpk abs)
...| inj₂ sentb4 = inj₂ (MsgWithSig∈-++ʳ sentb4)
ext-unforgeability' {α = α} {m = m} {part = part} (step-s st (step-peer {pid = β} {outs = outs} {pre = pre} sp)) m∈sm p⊆m sig ¬init hpk
| inj₁ thisStep
| step-honest x
with senderMsgPair∈⇒send∈ outs thisStep
...| m∈outs , refl = ⊎-map proj₁ MsgWithSig∈-++ʳ (sps-avp st hpk x m∈outs p⊆m sig ¬init)
-- The ext-unforgeability' property can be collapsed in a single clause.
-- TODO-2: so far, ext-unforgeability is used only to get a MsgWithSig∈ that is passed to
-- msgWithSigSentByAuthor, which duplicates some of the reasoning in the proof of
-- ext-unforgeability'; should these properties possibly be combined into one simpler proof?
ext-unforgeability
: ∀{α₀ m part pk}{st : SystemState} → ReachableSystemState st
→ (α₀ , m) ∈ msgPool st → part ⊂Msg m
→ (sig : WithVerSig pk part) → ¬ ∈GenInfo (ver-signature sig)
→ Meta-Honest-PK pk
→ MsgWithSig∈ pk (ver-signature sig) (msgPool st)
ext-unforgeability {α₀} {m} {st = st} rst m∈sm p⊂m sig ¬init hpk
with ext-unforgeability' rst m∈sm p⊂m sig ¬init hpk
...| inj₁ p
= mkMsgWithSig∈ _ _ p⊂m α₀ m∈sm sig refl
...| inj₂ sentb4 = sentb4
msgWithSigSentByAuthor : ∀ {pk sig}{st : SystemState}
→ ReachableSystemState st
→ Meta-Honest-PK pk
→ (mws : MsgWithSig∈ pk sig (msgPool st))
→ ¬ (∈GenInfo (ver-signature (msgSigned mws)))
→ (Σ (MsgWithSig∈ pk sig (msgPool st))
λ mws' → ValidSenderForPK st (msgPart mws') (msgSender mws') pk)
msgWithSigSentByAuthor step-0 _ ()
msgWithSigSentByAuthor {pk} {sig} (step-s {pre = pre} preach (step-peer theStep@(step-cheat cheatCons))) hpk mws ¬init
with (¬cheatForgeNew theStep refl unit hpk mws ¬init)
...| mws'
with msgWithSigSentByAuthor preach hpk mws' (transp-¬∈GenInfo₂ mws ¬init (MsgWithSig∈-++ʳ mws') refl)
...| (mws'' , vpb'') = MsgWithSig∈-++ʳ mws'' , ValidSenderForPK-stable preach (step-peer theStep) vpb''
msgWithSigSentByAuthor (step-s {pre = pre} preach theStep@(step-peer {pid = pid} {outs = outs} (step-honest sps))) hpk mws ¬init
with Any-++⁻ (actionsToSentMessages pid outs) {msgPool pre} (msg∈pool mws)
...| inj₂ furtherBack
with msgWithSigSentByAuthor preach hpk (MsgWithSig∈-transp mws furtherBack) ¬init
...| (mws' , vpb') = MsgWithSig∈-++ʳ mws' , ValidSenderForPK-stable preach theStep vpb'
msgWithSigSentByAuthor (step-s {pre = pre} preach theStep@(step-peer {pid = pid} {outs = outs} (step-honest sps))) hpk mws ¬init
| inj₁ thisStep
with senderMsgPair∈⇒send∈ outs thisStep
...| m∈outs , refl
with sps-avp preach hpk sps m∈outs (msg⊆ mws) (msgSigned mws) ¬init
...| inj₁ (vpbα₀ , _) = mws , vpbα₀
...| inj₂ mws'
with msgWithSigSentByAuthor preach hpk mws' (transp-¬∈GenInfo₂ mws ¬init (MsgWithSig∈-++ʳ mws') (msgSameSig mws))
...| (mws'' , vpb'') rewrite sym (msgSameSig mws) = MsgWithSig∈-++ʳ mws'' , ValidSenderForPK-stable preach theStep vpb''
newMsg⊎msgSentB4 : ∀ {pk v m pid sndr s' outs} {st : SystemState}
→ (r : ReachableSystemState st)
→ (stP : StepPeerState pid (msgPool st) (initialised st) (peerStates st pid) (s' , outs))
→ Meta-Honest-PK pk → (sig : WithVerSig pk v)
→ ¬ (∈GenInfo (ver-signature sig))
→ v ⊂Msg m → (sndr , m) ∈ msgPool (StepPeer-post {pre = st} (step-honest stP))
→ ( LYT.send m ∈ outs × ValidSenderForPK (StepPeer-post {pre = st} (step-honest stP)) v pid pk
× ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool st)))
⊎ MsgWithSig∈ pk (ver-signature sig) (msgPool st)
newMsg⊎msgSentB4 {pk} {v} {m} {pid} {sndr} {s'} {outs} {st} r stP pkH sig ¬init v⊂m m∈post
with Any-++⁻ (actionsToSentMessages pid outs) m∈post
...| inj₂ m∈preSt = inj₂ (mkMsgWithSig∈ m v v⊂m sndr m∈preSt sig refl)
...| inj₁ nm∈outs
with senderMsgPair∈⇒send∈ outs nm∈outs
...| m∈outs , refl
with sps-avp r pkH stP m∈outs v⊂m sig ¬init
...| inj₁ newVote = inj₁ (m∈outs , newVote)
...| inj₂ msb4 = inj₂ msb4
-- This could potentially be more general, for example covering the whole SystemState, rather than
-- just one peer's state. However, this would put more burden on the user and is not required so
-- far.
CarrierProp : Set (1ℓ ℓ⊔ ℓ-PeerState)
CarrierProp = Part → PeerState → Set
module _ (P : CarrierProp) where
record PropCarrier (pk : PK) (sig : Signature) (st : SystemState) : Set (ℓ-VSFP ℓ⊔ ℓ+1 ℓ-PeerState) where
constructor mkCarrier
field
carrStReach : ReachableSystemState st -- Enables use of invariants when proving that steps preserve carrProp
carrSent : MsgWithSig∈ pk sig (msgPool st)
carrInitd : initialised st (msgSender carrSent) ≡ initd
carrValid : ValidSenderForPK st (msgPart carrSent) (msgSender carrSent) pk
carrProp : P (msgPart carrSent) (peerStates st (msgSender carrSent))
open PropCarrier public
PeerStepPreserves : Set (ℓ-VSFP ℓ⊔ ℓ+1 ℓ-PeerState)
PeerStepPreserves = ∀ {ps' outs pk sig}{pre : SystemState}
→ (r : ReachableSystemState pre)
→ (pc : PropCarrier pk sig pre)
→ (sps : StepPeerState (msgSender (carrSent pc))
(msgPool pre)
(initialised pre)
(peerStates pre (msgSender (carrSent pc)))
(ps' , outs))
→ P (msgPart (carrSent pc)) ps'
module _ (PSP : PeerStepPreserves) where
Carrier-transp : ∀ {pk sig} {pre : SystemState}{post : SystemState}
→ (theStep : Step pre post)
→ PropCarrier pk sig pre
→ PropCarrier pk sig post
Carrier-transp {pk} {pre = pre} {post} theStep@(step-peer {pid = pid} {st'} {pre = .pre} sps) pc@(mkCarrier r mws ini vpk prop)
with step-s r theStep
...| postReach
with sps
...| cheatStep@(step-cheat isch) = mkCarrier postReach (MsgWithSig∈-++ʳ mws)
(trans (cong (λ f → f (msgSender mws)) (cheatStepDNMInitialised cheatStep unit)) ini) -- PeerStates not changed by cheat steps
(ValidSenderForPK-stable {pre} r (step-peer cheatStep) vpk)
(subst (λ ps → P (msgPart mws) (ps (msgSender mws))) (sym (cheatStepDNMPeerStates {pre = pre} (step-cheat isch) unit)) prop)
...| honStep@(step-honest {st = st} sps')
with msgSender mws ≟PeerId pid
...| no neq = mkCarrier postReach (MsgWithSig∈-++ʳ mws) (trans (sym (override-target-≢ neq)) ini)
(ValidSenderForPK-stable {pre} r (step-peer (step-honest sps')) vpk)
(subst (λ ps → P (msgPart mws) ps) (override-target-≢ {f = peerStates pre} neq) prop)
...| yes refl = mkCarrier postReach (MsgWithSig∈-++ʳ mws) override-target-≡
(ValidSenderForPK-stable {part = msgPart mws} {pk = pk} r (step-peer honStep) vpk)
(subst (λ ps → P (msgPart mws) ps) (sym override-target-≡) (PSP r pc sps'))
| {
"alphanum_fraction": 0.5969136687,
"avg_line_length": 58.7949438202,
"ext": "agda",
"hexsha": "68a847c3bef2db36b95418745a8d5eadaf1f4e69",
"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": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Yasm/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"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": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Yasm/Properties.agda",
"max_line_length": 164,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Yasm/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6334,
"size": 20931
} |
open import Type
open import Structure.Relator
open import Structure.Setoid renaming (_≡_ to _≡ₑ_)
module Structure.Sets.ZFC.Classical {ℓₛ ℓₗ ℓₑ} {S : Type{ℓₛ}} ⦃ equiv : Equiv{ℓₑ}(S) ⦄ (_∈_ : S → S → Type{ℓₗ}) ⦃ [∈]-binaryRelator : BinaryRelator(_∈_) ⦄ where
open import Data.Either as Either using ()
open import Functional
open import Logic.Classical
open import Logic.Predicate
open import Logic.Propositional
open import Logic.Propositional.Theorems
import Lvl
open import Structure.Operator
open import Structure.Relator.Proofs
open import Structure.Relator.Properties
import Structure.Sets.Names
open Structure.Sets.Names.From-[∈] (_∈_)
open Structure.Sets.Names.Relations (_∈_)
open import Structure.Sets.ZFC(_∈_) ⦃ [∈]-binaryRelator ⦄
open import Syntax.Function
open import Syntax.Implication
open import Syntax.Transitivity
private variable ℓ : Lvl.Level
private variable T A B : Type{ℓ}
private variable x : S
module _ ⦃ zfc : ZFC ⦄ where
open ZFC(zfc)
-- ZFC implies excluded middle.
-- Note that this only requires the following set related axioms:
-- • Set extensionality (Not really neccessary if every equality is replaced with set equality instead).
-- • Axiom of choice (TODO: Is this really neccessary? The proof only uses the choice function on finite sets? Further investigation on choice functions for finite sets would clear this up).
-- • Choice functions are functions.
-- • Restricted set comprehension.
-- • Existence of at least two different sets (In this proof, ∅ and {∅} (𝑇 and 𝐹) is used).
-- • Existence of a set containing the two different sets, and the existence of all subsets of this set.
-- Also called: Diaconescu's theorem, Goodman–Myhill theorem.
excluded-middle-by-choice : ∀{P : Type{ℓ}} → Classical(P)
excluded-middle-by-choice{P = P} = intro $ᵢₙₛₜ
let
instance
pos-rel : UnaryRelator(x ↦ P ∨ (x ≡ 𝑇))
pos-rel = [∨]-unaryRelator ⦃ rel-Q = binary-unaryRelatorᵣ ⦄
instance
neg-rel : UnaryRelator(x ↦ P ∨ (x ≡ 𝐹))
neg-rel = [∨]-unaryRelator ⦃ rel-Q = binary-unaryRelatorᵣ ⦄
pos = filter (x ↦ P ∨ (x ≡ 𝑇)) BoolSet
neg = filter (x ↦ P ∨ (x ≡ 𝐹)) BoolSet
-- The contents of pos by definition. A subset of BoolSet which is equal to BoolSet when P, {𝑇} otherwise.
pos-containment : (x ∈ pos) ↔ (x ∈ BoolSet) ∧ (P ∨ (x ≡ 𝑇))
pos-containment = restricted-comprehension
-- The contents of neg by definition. A subset of BoolSet which is equal to BoolSet when P, {𝐹} otherwise.
neg-containment : (x ∈ neg) ↔ (x ∈ BoolSet) ∧ (P ∨ (x ≡ 𝐹))
neg-containment = restricted-comprehension
-- pos is non-empty because it should at least contain 𝑇 from filtering BoolSet.
instance
ne-pos : NonEmpty(pos)
ne-pos = [↔]-to-[←] (nonEmpty-filter) ([∃]-intro 𝑇 ⦃ [∧]-intro 𝑇-in-BoolSet ([∨]-introᵣ (\{_} → [↔]-reflexivity)) ⦄)
-- neg is non-empty because it should at least contain 𝐹 from filtering BoolSet.
instance
ne-neg : NonEmpty(neg)
ne-neg = [↔]-to-[←] (nonEmpty-filter) ([∃]-intro 𝐹 ⦃ [∧]-intro 𝐹-in-BoolSet ([∨]-introᵣ (\{_} → [↔]-reflexivity)) ⦄)
-- Chooses an element in respective sets pos and neg.
pos-choose = choose (pair pos neg) pos
neg-choose = choose (pair pos neg) neg
-- By definition of pos, either P holds or pos-choose have to be 𝑇.
pos-choice : P ∨ (pos-choose ≡ 𝑇)
pos-choice = [∧]-elimᵣ ([↔]-to-[→] pos-containment (choice {pair pos neg} {pos} ⦃ ne-pos ⦄ ⦃ pair-contains-left ⦄))
-- By definition of neg, either P holds or neg-choose have to be 𝐹.
neg-choice : P ∨ (neg-choose ≡ 𝐹)
neg-choice = [∧]-elimᵣ ([↔]-to-[→] neg-containment (choice {pair pos neg} {neg} ⦃ ne-neg ⦄ ⦃ pair-contains-right ⦄))
in
• ( -- Contrapositive of the argument below states that if pos-choose and neg-choose is inequal, then (¬ P)
(_⇒ -- When P holds, both pos and neg is BoolSet, so they are equal. The pos-choose and neg-choose is the choice function applied to the equal sets pos and neg respectively, and because choose is a function (it respects equality, specifically set equality), pos-choose and neg-choose is also equal.
P ⇒-[ (\p {x} → [↔]-transitivity (pos-containment {x}) ([↔]-transitivity ([∧]-mapᵣ-[↔] ([↔]-intro (const([∨]-introₗ p)) (const([∨]-introₗ p)))) ([↔]-symmetry (neg-containment {x})))) ]
(pos ≡ neg) ⇒-[ [↔]-to-[←] set-extensionality ]
(pos ≡ₑ neg) ⇒-[ congruence₂(choose) (reflexivity(_≡ₑ_)) ]
(pos-choose ≡ₑ neg-choose) ⇒-end
) ⇒
(P → (pos-choose ≡ₑ neg-choose)) ⇒-[ contrapositiveᵣ ]
((¬ P) ← (pos-choose ≢ neg-choose)) ⇒-end
)
• ( -- The case other than P is that pos and neg only contains 𝑇 and 𝐹 respectively. This forces pos-choose and neg-choose to be 𝑇 and 𝐹 respectively, which means that they are inequal.
• pos-choice
• neg-choice
⇒₂-[ [∧]-intro ]
(P ∨ (pos-choose ≡ 𝑇)) ∧ (P ∨ (neg-choose ≡ 𝐹)) ⇒-[ [↔]-to-[←] [∨][∧]-distributivityₗ ]
P ∨ ((pos-choose ≡ 𝑇) ∧ (neg-choose ≡ 𝐹)) ⇒-[ Either.mapRight (\{([∧]-intro p0 n1) → [≡][≢]-semitransitivityᵣ([≡][≢]-semitransitivityₗ ([↔]-to-[←] set-extensionality p0) zero-one-ineq) (symmetry(_≡ₑ_) ([↔]-to-[←] set-extensionality n1))}) ]
P ∨ (pos-choose ≢ neg-choose) ⇒-end
)
⇒₂-[ Either.mapRight ]
(P ∨ (¬ P)) ⇒-end
| {
"alphanum_fraction": 0.6248191027,
"avg_line_length": 52.6476190476,
"ext": "agda",
"hexsha": "1daec78cc4875922e4f3782aed83abc252804464",
"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/Sets/ZFC/Classical.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/Sets/ZFC/Classical.agda",
"max_line_length": 306,
"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/Sets/ZFC/Classical.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": 1830,
"size": 5528
} |
------------------------------------------------------------------------------
-- Division program
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module define a division program using repeated subtraction
-- (Dybjer 1985).
-- Peter Dybjer. Program verification in a logical theory of
-- constructions. In Jean-Pierre Jouannaud, editor. Functional
-- Programming Languages and Computer Architecture, volume 201 of
-- LNCS, 1985, pages 334-349. Appears in revised form as Programming
-- Methodology Group Report 26, June 1986.
module FOTC.Program.Division.Division where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Inequalities
------------------------------------------------------------------------------
postulate
div : D → D → D
div-eq : ∀ i j → div i j ≡ (if (lt i j) then zero else succ₁ (div (i ∸ j) j))
{-# ATP axiom div-eq #-}
| {
"alphanum_fraction": 0.5279560037,
"avg_line_length": 35.1935483871,
"ext": "agda",
"hexsha": "962d0ef64f2c94e6517f1038790f7b630d9e439d",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/Division/Division.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/Division/Division.agda",
"max_line_length": 79,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/Division/Division.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": 232,
"size": 1091
} |
{-# OPTIONS --without-K #-}
module Data.ByteString.Primitive.Lazy where
open import Data.Word8.Primitive using (Word8)
open import Agda.Builtin.Nat using (Nat)
open import Data.Colist using (Colist)
open import Agda.Builtin.String using (String)
open import Agda.Builtin.Bool using (Bool)
open import Agda.Builtin.IO using (IO)
open import Data.Tuple.Base using (Pair)
{-# FOREIGN GHC import qualified Data.Word #-}
{-# FOREIGN GHC import qualified Data.Text #-}
{-# FOREIGN GHC import qualified Data.ByteString.Lazy #-}
open import Foreign.Haskell using (Unit)
open import Data.ByteString.Primitive.Int
postulate
ByteStringLazy : Set
readBinaryFileLazy : String → IO ByteStringLazy
writeBinaryFileLazy : String → ByteStringLazy → IO Unit
Colist←Lazy : ByteStringLazy → Colist Word8
Colist→Lazy : Colist Word8 → ByteStringLazy
emptyLazy : ByteStringLazy
nullLazy : ByteStringLazy → Bool
lengthLazy : ByteStringLazy → Int64
headLazy : ByteStringLazy → Word8
tailLazy : ByteStringLazy → ByteStringLazy
indexLazy : ByteStringLazy → Int64 → Word8
splitAtLazy : Int64 → ByteStringLazy → Pair ByteStringLazy ByteStringLazy
appendLazy : ByteStringLazy → ByteStringLazy → ByteStringLazy
{-# COMPILE GHC ByteStringLazy = type
Data.ByteString.Lazy.ByteString
#-}
{-# COMPILE GHC readBinaryFileLazy =
( Data.ByteString.Lazy.readFile
. Data.Text.unpack
)
#-}
{-# COMPILE GHC writeBinaryFileLazy =
( Data.ByteString.Lazy.writeFile
. Data.Text.unpack
)
#-}
{-# COMPILE GHC Colist←Lazy =
( Data.ByteString.Lazy.unpack ) #-}
{-# COMPILE GHC Colist→Lazy =
( Data.ByteString.Lazy.pack ) #-}
{-# COMPILE GHC emptyLazy = (Data.ByteString.Lazy.empty) #-}
{-# COMPILE GHC nullLazy = (Data.ByteString.Lazy.null) #-}
{-# COMPILE GHC lengthLazy = (Data.ByteString.Lazy.length) #-}
{-# COMPILE GHC headLazy = (Data.ByteString.Lazy.head) #-}
{-# COMPILE GHC tailLazy = (Data.ByteString.Lazy.tail) #-}
{-# COMPILE GHC indexLazy = (Data.ByteString.Lazy.index) #-}
{-# COMPILE GHC appendLazy = (Data.ByteString.Lazy.append) #-}
{-# COMPILE GHC splitAtLazy = (Data.ByteString.Lazy.splitAt) #-}
| {
"alphanum_fraction": 0.7233348859,
"avg_line_length": 35.1967213115,
"ext": "agda",
"hexsha": "3f77ec7cd273778aefa036d3c629888da37899a7",
"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": "98a53f35fca27e3379cf851a9a6bdfe5bd8c9626",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "semenov-vladyslav/bytes-agda",
"max_forks_repo_path": "src/Data/ByteString/Primitive/Lazy.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98a53f35fca27e3379cf851a9a6bdfe5bd8c9626",
"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": "semenov-vladyslav/bytes-agda",
"max_issues_repo_path": "src/Data/ByteString/Primitive/Lazy.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98a53f35fca27e3379cf851a9a6bdfe5bd8c9626",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "semenov-vladyslav/bytes-agda",
"max_stars_repo_path": "src/Data/ByteString/Primitive/Lazy.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 526,
"size": 2147
} |
module Oscar.Data.Permutation.Properties where
open import Data.Permutation.Properties public
open import Data.Nat
open import Oscar.Data.Vec renaming (delete to deleteV)
open import Oscar.Data.Vec.Properties
open import Oscar.Data.Permutation
∈-enum : ∀ {n m} (i : Inj n m) → i ∈ enum n m
∈-enum {zero} [] = here
∈-enum {suc n} (i ∷ is) = ∈-map₂ _∷_ (∈-allFin i) (∈-enum is)
open import Data.Fin
open import Relation.Binary.PropositionalEquality
permute-correct : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) →
[ v ≡Permutation permute p v ] p
permute-correct [] [] = λ ()
permute-correct (p ∷ ps) (_ ∷ _) zero = here
permute-correct (p ∷ ps) v@(_ ∷ _) (suc f) =
let bs = permute ps (deleteV p v)
delresult = permute-correct ps (deleteV p v)
in
there ((subst (bs [ f ]=_) (lookup-delete-thin p (< ps > f) v) ((delresult f))))
open import Data.Product
open import Relation.Binary.PropositionalEquality
enumPermutations-complete : ∀ {a n} {A : Set a} → (xs : Vec A n) → ∀ ys → xs ∃≡Permutation ys → ys ∈ enumPermutations xs
enumPermutations-complete [] [] ([] , xs=ys|p) = here
enumPermutations-complete (x ∷ xs) (y ∷ ys) (p ∷ ps , xs=ys|p∷ps) = {!!}
| {
"alphanum_fraction": 0.645295587,
"avg_line_length": 35.3235294118,
"ext": "agda",
"hexsha": "990b68eb38ae35571a2acea530e242d11477ac21",
"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/Data/Permutation/Properties.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/Data/Permutation/Properties.agda",
"max_line_length": 120,
"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/Data/Permutation/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 408,
"size": 1201
} |
module SubstTheory where
open import Prelude
open import T
-- I originally used postulated extensional equality to reason about
-- identical substitutions. As it turns out, it's actually somewhat
-- cleaner to appeal to a proof that using identically performing subst
-- functions produce the same outputs.
---- (Lots of theory. *Lots*. Too much. Sigh.)
module SubstTheory where
Ren≡ : ∀ {Γ Γ'}(f g : TRen Γ Γ') → Set
Ren≡ f g = ∀ {A} x → f {A} x ≡ g {A} x
-- Some theorems about renamings
wkeq : ∀{Γ Γ' A} {f g : TRen Γ Γ'} → Ren≡ f g → Ren≡ (wk {A = A} f) (wk g)
wkeq eq Z = Refl
wkeq eq (S n) = resp S (eq n)
-- Prove that applying equal renamings produces equal outputs
reneq : ∀{Γ Γ' A} {f g : TRen Γ Γ'} → Ren≡ f g → (e : TExp Γ A) → ren f e ≡ ren g e
reneq eq (var x) = resp var (eq x)
reneq eq (Λ e) = resp Λ (reneq (wkeq eq) e)
reneq eq (e₁ $ e₂) = resp2 _$_ (reneq eq e₁) (reneq eq e₂)
reneq eq zero = Refl
reneq eq (suc e) = resp suc (reneq eq e)
reneq eq (rec e e₀ es) = resp3 rec (reneq eq e) (reneq eq e₀) (reneq (wkeq eq) es)
wkid : ∀{Γ A C} (x : A ∈ C :: Γ) → wk renId x ≡ renId x
wkid Z = Refl
wkid (S n) = Refl
renid : ∀{Γ A} (e : TExp Γ A) → ren renId e ≡ id _ e
renid (var x) = Refl
renid (Λ e) = resp Λ (reneq wkid e ≡≡ renid e)
renid (e₁ $ e₂) = resp2 _$_ (renid e₁) (renid e₂)
renid zero = Refl
renid (suc e) = resp suc (renid e)
renid (rec e e₀ es) = resp3 rec (renid e) (renid e₀)
(reneq wkid es ≡≡ renid es)
wkcomp : ∀ {B Γ Γ'}(f : TRen Γ Γ')(g : TRen B Γ) {C A} (x : A ∈ (C :: B)) →
wk (renComp f g) x ≡ (wk f o wk g) x
wkcomp f g Z = Refl
wkcomp f g (S n) = Refl
rencomp : ∀ {B Γ Γ'}(f : TRen Γ Γ')(g : TRen B Γ) {A} (e : TExp B A) →
ren (renComp f g) e ≡ (ren f o ren g) e
rencomp f g (var x) = Refl
rencomp f g (Λ e) = resp Λ (reneq (wkcomp f g) e
≡≡ (rencomp (wk f) (wk g) e))
rencomp f g (e₁ $ e₂) = resp2 _$_ (rencomp f g e₁) (rencomp f g e₂)
rencomp f g zero = Refl
rencomp f g (suc e) = resp suc (rencomp f g e)
rencomp f g (rec e e₀ es) = resp3 rec (rencomp f g e) (rencomp f g e₀)
(reneq (wkcomp f g) es
≡≡ (rencomp (wk f) (wk g) es))
Sub≡ : ∀ {Γ Γ'}(f g : TSubst Γ Γ') → Set
Sub≡ f g = ∀ {A} x → f {A} x ≡ g {A} x
lifteq : ∀{Γ Γ' A} {f g : TSubst Γ Γ'} → Sub≡ f g → Sub≡ (liftγ {A = A} f) (liftγ g)
lifteq eq Z = Refl
lifteq eq (S n) = resp (λ x → ren S x) (eq n)
-- Prove that applying equal substs produces equal outputs
subeq : ∀{Γ Γ' A} {f g : TSubst Γ Γ'} → Sub≡ f g → (e : TExp Γ A) → ssubst f e ≡ ssubst g e
subeq eq (var x) = eq x
subeq eq (Λ e) = resp Λ (subeq (lifteq eq) e)
subeq eq (e₁ $ e₂) = resp2 _$_ (subeq eq e₁) (subeq eq e₂)
subeq eq zero = Refl
subeq eq (suc e) = resp suc (subeq eq e)
subeq eq (rec e e₀ es) = resp3 rec (subeq eq e) (subeq eq e₀) (subeq (lifteq eq) es)
-- Theorems about renaming and substitution
renwklift : ∀{K Γ Δ C}(f : TRen Γ Δ)(g : TSubst K Γ){A}(x : A ∈ (C :: K)) →
(ren (wk f) o (liftγ g)) x ≡ liftγ (ren f o g) x
renwklift f g Z = Refl
renwklift f g (S n) = symm (rencomp (wk f) S (g n)) ≡≡ rencomp S f (g n)
rensub : ∀{B Γ Δ}(f : TRen Γ Δ)(g : TSubst B Γ){A}(e : TExp B A) →
(ren f o ssubst g) e ≡ ssubst (ren f o g) e
rensub f g (var x) = Refl
rensub f g (Λ e) = resp Λ ((rensub (wk f) (liftγ g) e) ≡≡
subeq (renwklift f g) e)
rensub f g (e₁ $ e₂) = resp2 _$_ (rensub f g e₁) (rensub f g e₂)
rensub f g zero = Refl
rensub f g (suc e) = resp suc (rensub f g e)
rensub f g (rec e e₀ es) = resp3 rec (rensub f g e) (rensub f g e₀)
((rensub (wk f) (liftγ g) es) ≡≡
subeq (renwklift f g) es)
liftwk : ∀{K Γ Δ C}(f : TSubst Γ Δ)(g : TRen K Γ){A}(x : A ∈ (C :: K)) →
(liftγ f o wk g) x ≡ liftγ (f o g) x
liftwk f g Z = Refl
liftwk f g (S n) = Refl
subren : ∀{B Γ Δ}(f : TSubst Γ Δ)(g : TRen B Γ){A}(e : TExp B A) →
(ssubst f o ren g) e ≡ ssubst (f o g) e
subren f g (var x) = Refl
subren f g (Λ e) = resp Λ ((subren (liftγ f) (wk g) e) ≡≡
subeq (liftwk f g) e)
subren f g (e₁ $ e₂) = resp2 _$_ (subren f g e₁) (subren f g e₂)
subren f g zero = Refl
subren f g (suc e) = resp suc (subren f g e)
subren f g (rec e e₀ es) = resp3 rec (subren f g e) (subren f g e₀)
((subren (liftγ f) (wk g) es) ≡≡
subeq (liftwk f g) es)
-- first monad law, the second holds definitionally
liftid : ∀{Γ A C} (x : A ∈ C :: Γ) → liftγ emptyγ x ≡ emptyγ x
liftid Z = Refl
liftid (S n) = Refl
subid : ∀{Γ}{A} (e : TExp Γ A) → ssubst emptyγ e ≡ id _ e
subid (var x) = Refl
subid (Λ e) = resp Λ (subeq liftid e ≡≡ subid e)
subid (e₁ $ e₂) = resp2 _$_ (subid e₁) (subid e₂)
subid zero = Refl
subid (suc e) = resp suc (subid e)
subid (rec e e₀ es) = resp3 rec (subid e) (subid e₀)
(subeq liftid es ≡≡ subid es)
-- third monad law
liftcomp : ∀ {B Γ Γ'}(f : TSubst Γ Γ')(g : TSubst B Γ) {C A} (x : A ∈ (C :: B)) →
liftγ (subComp f g) x ≡ (ssubst (liftγ f) o liftγ g) x
liftcomp f g Z = Refl
liftcomp f g (S n) = rensub S f (g n) ≡≡ symm (subren (liftγ f) S (g n))
subcomp : ∀{B Γ Γ'}(f : TSubst Γ Γ')(g : TSubst B Γ){A}(t : TExp B A) →
ssubst (subComp f g) t ≡ (ssubst f o ssubst g) t
subcomp f g (var x) = Refl
subcomp f g (Λ e) = resp Λ (subeq (liftcomp f g) e
≡≡ (subcomp (liftγ f) (liftγ g) e))
subcomp f g (e₁ $ e₂) = resp2 _$_ (subcomp f g e₁) (subcomp f g e₂)
subcomp f g zero = Refl
subcomp f g (suc e) = resp suc (subcomp f g e)
subcomp f g (rec e e₀ es) = resp3 rec (subcomp f g e) (subcomp f g e₀)
(subeq (liftcomp f g) es
≡≡ (subcomp (liftγ f) (liftγ g) es))
-- The lemma about combining substitutions that we are actually
-- going to need. Being able to prove this lemma was the cause
-- of most of the grief during this proof.
combine-subst-noob : ∀ {Γ A C} → (γ : TSubst Γ []) →
(e : TExp (A :: Γ) C) →
(e' : TCExp A) →
ssubst (extendγ γ e') e ≡
ssubst (singγ e') (ssubst (liftγ γ) e)
combine-subst-noob γ e e' = subcomp (singγ e') (liftγ γ) e
-- A lemma we need to define our relations on substs that respect relns
extend-nofail-s : ∀{Γ Γ' A B} → (γ : TSubst Γ Γ') → (e : TExp Γ' A) → (n : B ∈ Γ) →
γ n ≡ (extendγ γ e) (S n)
extend-nofail-s γ e n = symm (subren (singγ e) S (γ n) ≡≡ subid (γ n))
-- A closed subst is the identity
closed-is-empty-ren : (γ : TRen [] []) → Ren≡ γ renId
closed-is-empty-ren γ ()
closed-is-empty : (γ : TSubst [] []) → Sub≡ γ emptyγ
closed-is-empty γ ()
-- A substitution made on a closed term is the identity substitution
closed-ren : ∀{A} → (γ : TRen [] []) → (e : TCExp A) → ren γ e ≡ e
closed-ren γ e = reneq (closed-is-empty-ren γ) e ≡≡ renid e
closed-subst : ∀{A} → (γ : TSubst [] []) → (e : TCExp A) → ssubst γ e ≡ e
closed-subst γ e = subeq (closed-is-empty γ) e ≡≡ subid e
-- lift of a closed subst, also identity - feel like there is a nicer way to do this
lift-closed-is-empty : ∀{A} (γ : TSubst [] []) → Sub≡ (liftγ {A = A} γ) emptyγ
lift-closed-is-empty γ Z = Refl
lift-closed-is-empty γ (S x) = resp (ren _) (closed-is-empty γ x)
lift-closed-subst : ∀{A B} → (γ : TSubst [] []) → (e : TExp (B :: []) A) → ssubst (liftγ γ) e ≡ e
lift-closed-subst γ e = subeq (lift-closed-is-empty γ) e ≡≡ subid e
compose-subst-noob : ∀{Γ} {C} → (γ : TSubst Γ []) →
(e : TExp Γ C) →
{A : TTp} → (x : A ∈ C :: Γ) →
subComp (singγ (ssubst γ e)) (liftγ γ) x ≡
subComp γ (singγ e) x
compose-subst-noob γ e Z = Refl
compose-subst-noob γ e (S x) = subren (singγ (ssubst γ e)) (λ y → S y) (γ x) ≡≡ subid (γ x)
drop-fix : ∀{Γ A} → (γ : TSubst (A :: Γ) []) → Sub≡ γ (subComp (singγ (γ Z)) (liftγ (dropγ γ)))
drop-fix γ Z = Refl
drop-fix γ (S x) = symm (subren (singγ (γ Z)) S (γ (S x)) ≡≡ subid (γ (S x)))
open SubstTheory public
| {
"alphanum_fraction": 0.526761235,
"avg_line_length": 42.8010204082,
"ext": "agda",
"hexsha": "636d3ad446ba8f304765d9dd4ea7a197328d3250",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-05-04T22:37:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-26T11:39:14.000Z",
"max_forks_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "msullivan/godels-t",
"max_forks_repo_path": "SubstTheory.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "msullivan/godels-t",
"max_issues_repo_path": "SubstTheory.agda",
"max_line_length": 99,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "msullivan/godels-t",
"max_stars_repo_path": "SubstTheory.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-22T00:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-25T01:52:57.000Z",
"num_tokens": 3431,
"size": 8389
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Half adjoint equivalences
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Function.HalfAdjointEquivalence where
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as Inv using (_↔_; module Inverse)
open import Level
open import Relation.Binary.PropositionalEquality
-- Half adjoint equivalences (see the HoTT book).
record _≃_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where
field
to : A → B
from : B → A
left-inverse-of : ∀ x → from (to x) ≡ x
right-inverse-of : ∀ x → to (from x) ≡ x
left-right :
∀ x → cong to (left-inverse-of x) ≡ right-inverse-of (to x)
-- Half adjoint equivalences can be turned into inverses.
inverse : A ↔ B
inverse = Inv.inverse to from left-inverse-of right-inverse-of
-- The forward direction of a half adjoint equivalence is injective.
injective : ∀ {x y} → to x ≡ to y → x ≡ y
injective {x} {y} to-x≡to-y =
x ≡⟨ sym (left-inverse-of _) ⟩
from (to x) ≡⟨ cong from to-x≡to-y ⟩
from (to y) ≡⟨ left-inverse-of _ ⟩
y ∎
where
open ≡-Reasoning
-- Inverses can be turned into half adjoint equivalences.
--
-- (This proof is based on one in the HoTT book.)
↔→≃ : ∀ {a b} {A : Set a} {B : Set b} → A ↔ B → A ≃ B
↔→≃ A↔B = record
{ to = to ⟨$⟩_
; from = from ⟨$⟩_
; left-inverse-of = left-inverse-of
; right-inverse-of = right-inverse-of
; left-right = left-right
}
where
open ≡-Reasoning
open module A↔B = Inverse A↔B using (to; from; left-inverse-of)
right-inverse-of : ∀ x → to ⟨$⟩ (from ⟨$⟩ x) ≡ x
right-inverse-of x =
to ⟨$⟩ (from ⟨$⟩ x) ≡⟨ sym (A↔B.right-inverse-of _) ⟩
to ⟨$⟩ (from ⟨$⟩ (to ⟨$⟩ (from ⟨$⟩ x))) ≡⟨ cong (to ⟨$⟩_) (left-inverse-of _) ⟩
to ⟨$⟩ (from ⟨$⟩ x) ≡⟨ A↔B.right-inverse-of _ ⟩
x ∎
left-right :
∀ x →
cong (to ⟨$⟩_) (left-inverse-of x) ≡ right-inverse-of (to ⟨$⟩ x)
left-right x =
cong (to ⟨$⟩_) (left-inverse-of x) ≡⟨⟩
trans refl (cong (to ⟨$⟩_) (left-inverse-of _)) ≡⟨ cong (λ p → trans p (cong (to ⟨$⟩_) _))
(sym (trans-symˡ (A↔B.right-inverse-of _))) ⟩
trans (trans (sym (A↔B.right-inverse-of _))
(A↔B.right-inverse-of _))
(cong (to ⟨$⟩_) (left-inverse-of _)) ≡⟨ trans-assoc (sym (A↔B.right-inverse-of _)) ⟩
trans (sym (A↔B.right-inverse-of _))
(trans (A↔B.right-inverse-of _)
(cong (to ⟨$⟩_) (left-inverse-of _))) ≡⟨ cong (trans (sym (A↔B.right-inverse-of _))) lemma ⟩
trans (sym (A↔B.right-inverse-of _))
(trans (cong (to ⟨$⟩_) (left-inverse-of _))
(trans (A↔B.right-inverse-of _) refl)) ≡⟨⟩
right-inverse-of (to ⟨$⟩ x) ∎
where
lemma =
trans (A↔B.right-inverse-of _)
(cong (to ⟨$⟩_) (left-inverse-of _)) ≡⟨ cong (trans (A↔B.right-inverse-of _)) (sym (cong-id _)) ⟩
trans (A↔B.right-inverse-of _)
(cong id (cong (to ⟨$⟩_) (left-inverse-of _))) ≡⟨ sym (naturality A↔B.right-inverse-of) ⟩
trans (cong ((to ⟨$⟩_) ∘ (from ⟨$⟩_))
(cong (to ⟨$⟩_) (left-inverse-of _)))
(A↔B.right-inverse-of _) ≡⟨ cong (λ p → trans p (A↔B.right-inverse-of _))
(sym (cong-∘ _)) ⟩
trans (cong ((to ⟨$⟩_) ∘ (from ⟨$⟩_) ∘ (to ⟨$⟩_))
(left-inverse-of _))
(A↔B.right-inverse-of _) ≡⟨ cong (λ p → trans p (A↔B.right-inverse-of _))
(cong-∘ _) ⟩
trans (cong (to ⟨$⟩_)
(cong ((from ⟨$⟩_) ∘ (to ⟨$⟩_))
(left-inverse-of _)))
(A↔B.right-inverse-of _) ≡⟨ cong (λ p → trans (cong (to ⟨$⟩_) p) _)
(cong-≡id left-inverse-of) ⟩
trans (cong (to ⟨$⟩_) (left-inverse-of _))
(A↔B.right-inverse-of _) ≡⟨ cong (trans (cong (to ⟨$⟩_) (left-inverse-of _)))
(sym (trans-reflʳ _)) ⟩
trans (cong (to ⟨$⟩_) (left-inverse-of _))
(trans (A↔B.right-inverse-of _) refl) ∎
| {
"alphanum_fraction": 0.4577039275,
"avg_line_length": 40.649122807,
"ext": "agda",
"hexsha": "268d03d46acecaac6be6e0f7cdf1688fb687e7c5",
"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/Function/HalfAdjointEquivalence.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/Function/HalfAdjointEquivalence.agda",
"max_line_length": 117,
"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/Function/HalfAdjointEquivalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1450,
"size": 4634
} |
{-# OPTIONS --cubical #-}
open import Agda.Builtin.Cubical.Path
open import Agda.Primitive
open import Agda.Primitive.Cubical
open import Agda.Builtin.Bool
variable
a p : Level
A : Set a
P : A → Set p
x y : A
refl : x ≡ x
refl {x = x} = λ _ → x
data Interval : Set where
left right : Interval
line : left ≡ right
h2 : Bool → Interval
h2 true = left
h2 false = right
-- `left` and `right` are distinct canonical forms,
-- so `h2 ? = left` imples `? = true`.
--
-- Added this test to make sure we do not always give up on
-- injectivity when targeting a HIT.
_ : h2 _ ≡ left
_ = refl
| {
"alphanum_fraction": 0.6253968254,
"avg_line_length": 18.5294117647,
"ext": "agda",
"hexsha": "20c425a205cc3557297aa94a7e5871f6f23bb428",
"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/InjectivityHITs.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/InjectivityHITs.agda",
"max_line_length": 59,
"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/InjectivityHITs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 200,
"size": 630
} |
{-# OPTIONS --sized-types #-}
module SList.Order {A : Set}(_≤_ : A → A → Set) where
open import List.Sorted _≤_
open import Size
open import SList
data _*≤_ : {ι : Size} → A → SList A {ι} → Set where
genx : {ι : Size}{b : A}
→ (_*≤_) {↑ ι} b snil
gecx : {ι : Size}{b x : A}{xs : SList A {ι}}
→ b ≤ x
→ b *≤ xs
→ b *≤ (x ∙ xs)
data _≤*_ : {ι : Size} → SList A {ι} → A → Set where
lenx : {ι : Size}{t : A}
→ (_≤*_) {↑ ι} snil t
lecx : {ι : Size}{x t : A}{xs : SList A {ι}}
→ x ≤ t
→ xs ≤* t
→ (x ∙ xs) ≤* t
| {
"alphanum_fraction": 0.3716814159,
"avg_line_length": 27.12,
"ext": "agda",
"hexsha": "f1aab2fd78ddcd60d189b7079ad13e2aa3dac2f9",
"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/SList/Order.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/SList/Order.agda",
"max_line_length": 53,
"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/SList/Order.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": 253,
"size": 678
} |
{-# OPTIONS --copatterns #-}
module examplesPaperJFP.IOGraphicsLib where
open import Data.Bool.Base
open import Data.Char.Base
open import Data.Nat.Base hiding (_⊓_; _+_; _*_)
open import Data.List.Base hiding (_++_)
open import Data.Integer.Base hiding (suc)
open import Data.String.Base
open import Data.Maybe.Base
open import Function
open import Size
open import SizedIO.Base
open import SizedIO.IOGraphicsLib hiding (GraphicsCommands; GraphicsResponses; GraphicsInterface; IOGraphics) renaming (Size to WindowSize)
open import NativeInt --PrimTypeHelpers
open import NativeIO
data GraphicsCommands : Set where
getWindowEvent : Window → GraphicsCommands
openWindow : String → Maybe Point → ℕ → ℕ
→ RedrawMode → Maybe Word32
→ GraphicsCommands
closeWindow : Window → GraphicsCommands
drawInWindow : Window → Graphic → GraphicsCommands
GraphicsResponses : GraphicsCommands → Set
GraphicsResponses (getWindowEvent _) = Event
GraphicsResponses (openWindow _ _ _ _ _ _) = Window
GraphicsResponses (closeWindow _) = Unit
GraphicsResponses (drawInWindow _ _) = Unit
GraphicsInterface : IOInterface
Command GraphicsInterface = GraphicsCommands
Response GraphicsInterface = GraphicsResponses
IOGraphics : Size → Set → Set
IOGraphics i = IO GraphicsInterface i
translateNative : (c : GraphicsCommands) → NativeIO (GraphicsResponses c)
translateNative (getWindowEvent w) = nativeGetWindowEvent w
translateNative (openWindow str point n1 n2 m w) = nativeOpenWindowExNat str point n1 n2 m w
translateNative (closeWindow w) = nativeCloseWindow w
translateNative (drawInWindow w g) = nativeDrawInWindow w g
| {
"alphanum_fraction": 0.7004883342,
"avg_line_length": 33.5090909091,
"ext": "agda",
"hexsha": "1c148f38a445faa847242d5840150a73f56122d8",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/examplesPaperJFP/IOGraphicsLib.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"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/ooAgda",
"max_issues_repo_path": "examples/examplesPaperJFP/IOGraphicsLib.agda",
"max_line_length": 139,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/examplesPaperJFP/IOGraphicsLib.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 437,
"size": 1843
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Modulo.Base where
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Prelude
open import Cubical.Data.Empty
open import Cubical.Data.Fin
open import Cubical.Data.Nat
open import Cubical.Data.Unit renaming (Unit to ⊤)
open import Cubical.Relation.Nullary
NonZero : ℕ → Type₀
NonZero 0 = ⊥
NonZero _ = ⊤
private
variable
ℓ : Level
k : ℕ
-- The Modulo type is similar to the Fin type, but instead of being
-- inhabited by canonical values, the inhabitants are all naturals,
-- and paths are added between numbers that have the same residue.
--
-- This representation makes it easier to do certain arithmetic
-- without changing the modulus. For instance, we can just add any
-- natural to a Modulo k to get another, whereas with Fin k, we must
-- calculate the canonical representative.
--
-- The reason the path constructor is guarded is to avoid adding
-- non-trivial path structure to the k=0 case. If it were not guarded,
-- each `Modulo 0` would become like the circle, and guarding the
-- constructor is somewhat easier to work with than truncation.
--
-- Note also that unlike `Fin 0`, `Modulo 0` is equivalent to the naturals.
data Modulo (k : ℕ) : Type₀ where
embed : (n : ℕ) → Modulo k
pre-step : NonZero k → (n : ℕ) → embed n ≡ embed (k + n)
-- When we are working with k = suc k₀, the `step` alias is much
-- we can use this alias.
pattern step n i = pre-step _ n i
-- Helper to avoid having to case on `k` in certain places.
ztep : ∀{k} n → Path (Modulo k) (embed n) (embed (k + n))
ztep {0} n = refl
ztep {suc k} n = step n
-- The standard eliminator for `Modulo`.
elim
: (P : ∀ k → Modulo k → Type ℓ)
→ (e : ∀ k n → P k (embed n))
→ (st : ∀ k n → PathP (λ i → P (suc k) (step n i)) (e (suc k) n) (e (suc k) (suc k + n)))
→ (m : Modulo k) → P k m
elim P e st (embed n) = e _ n
elim {k = suc k} P e st (step n i) = st k n i
| {
"alphanum_fraction": 0.6850665352,
"avg_line_length": 32.7258064516,
"ext": "agda",
"hexsha": "c7005a40756f7e74078344257c0754bdd5a9c75a",
"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/HITs/Modulo/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/HITs/Modulo/Base.agda",
"max_line_length": 91,
"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/HITs/Modulo/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 617,
"size": 2029
} |
------------------------------------------------------------------------
-- The list container
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Container.List
{c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) where
open Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_; module _⇔_)
open import Prelude as P hiding (List; []; _∷_; id; _∘_)
open import Bag-equivalence eq
using () renaming (_≈-bag_ to _≈-bagL_; _∈_ to _∈L_; Any to AnyL)
open import Bijection eq using (_↔_; module _↔_; Σ-≡,≡↔≡)
open import Container eq
open import Fin eq
open import Function-universe eq
open import H-level.Closure eq
import List eq as L
open import Surjection eq using (_↠_)
------------------------------------------------------------------------
-- The type
-- Lists.
List : Container lzero
List = ℕ ▷ Fin
------------------------------------------------------------------------
-- The definitions of lists and bag equivalence for lists given in
-- Container/Container.List and in Prelude/Bag-equivalence are closely
-- related
-- There is a split surjection from ⟦ List ⟧ A to P.List A.
List↠List : {A : Type} → ⟦ List ⟧ A ↠ P.List A
List↠List {A} = record
{ logical-equivalence = record
{ to = uncurry to
; from = from
}
; right-inverse-of = to∘from
}
where
to : (n : ℕ) → (Fin n → A) → P.List A
to zero f = P.[]
to (suc n) f = P._∷_ (f fzero) (to n (f ∘ fsuc))
from = λ xs → (L.length xs , L.index xs)
to∘from : ∀ xs → uncurry to (from xs) ≡ xs
to∘from P.[] = refl _
to∘from (P._∷_ x xs) = cong (P._∷_ x) (to∘from xs)
-- If we assume that equality of functions is extensional, then we can
-- also prove that the two definitions are isomorphic.
List↔List : Extensionality lzero lzero →
{A : Type} → ⟦ List ⟧ A ↔ P.List A
List↔List ext {A} = record
{ surjection = List↠List
; left-inverse-of = uncurry from∘to
}
where
open _↠_ List↠List
from∘to : ∀ n f → from (to (n , f)) ≡ (n , f)
from∘to zero f = cong (_,_ _) (apply-ext ext λ ())
from∘to (suc n) f =
(suc (L.length (to xs)) , L.index (P._∷_ x (to xs))) ≡⟨ elim¹ (λ {ys} _ → _≡_ {A = ⟦ List ⟧ A}
(suc (L.length (to xs)) , L.index (P._∷_ x (to xs)))
(suc (proj₁ ys) , [ (λ _ → x) , proj₂ ys ]))
(cong (suc (L.length (to xs)) ,_) $ apply-ext ext
[ (λ _ → refl _) , (λ _ → refl _) ])
(from∘to n (f ∘ inj₂)) ⟩
(suc n , [ (λ _ → x) , f ∘ inj₂ ]) ≡⟨ cong (_,_ _) (apply-ext ext [ (λ _ → refl _) , (λ _ → refl _) ]) ⟩∎
(suc n , f) ∎
where
x = f (inj₁ tt)
xs = (n , f ∘ inj₂)
-- The two definitions of Any are isomorphic (both via "to" and
-- "from").
Any↔Any-to : {A : Type} (P : A → Type) (xs : ⟦ List ⟧ A) →
Any P xs ↔ AnyL P (_↠_.to List↠List xs)
Any↔Any-to {A} P = uncurry Any↔Any-to′
where
Any↔Any-to′ : (n : ℕ) (lkup : Fin n → A) →
Any {C = List} P (n , lkup) ↔
AnyL P (_↠_.to List↠List (n , lkup))
Any↔Any-to′ zero lkup =
(∃ λ (p : Fin zero) → P (lkup p)) ↔⟨ ∃-Fin-zero _ ⟩
⊥ □
Any↔Any-to′ (suc n) lkup =
(∃ λ (p : Fin (suc n)) → P (lkup p)) ↔⟨ ∃-Fin-suc _ ⟩
P (lkup fzero) ⊎ Any {C = List} P (n , lkup ∘ fsuc) ↔⟨ id ⊎-cong Any↔Any-to′ n (lkup ∘ fsuc) ⟩
P (lkup fzero) ⊎ AnyL P (_↠_.to List↠List (n , lkup ∘ fsuc)) □
Any-from↔Any : {A : Type} (P : A → Type) (xs : P.List A) →
Any P (_↠_.from List↠List xs) ↔ AnyL P xs
Any-from↔Any P P.[] =
(∃ λ (p : Fin zero) → P (L.index P.[] p)) ↔⟨ ∃-Fin-zero _ ⟩
⊥ □
Any-from↔Any P (P._∷_ x xs) =
(∃ λ (p : Fin (suc (L.length xs))) → P (L.index (P._∷_ x xs) p)) ↔⟨ ∃-Fin-suc _ ⟩
P x ⊎ Any {C = List} P (_↠_.from List↠List xs) ↔⟨ id ⊎-cong Any-from↔Any P xs ⟩
P x ⊎ AnyL P xs □
-- The definition of bag equivalence in Bag-equivalence and the one in
-- Container, instantiated with the List container, are logically
-- equivalent (both via "to" and "from").
≈-⇔-to-≈-to :
{A : Type} {xs ys : ⟦ List ⟧ A} →
xs ≈-bag ys ⇔ _↠_.to List↠List xs ≈-bagL _↠_.to List↠List ys
≈-⇔-to-≈-to {xs = xs} {ys} = record
{ to = λ xs≈ys z →
z ∈L (_↠_.to List↠List xs) ↔⟨ inverse $ Any↔Any-to _ xs ⟩
z ∈ xs ↔⟨ xs≈ys z ⟩
z ∈ ys ↔⟨ Any↔Any-to _ ys ⟩
z ∈L (_↠_.to List↠List ys) □
; from = λ xs≈ys z →
z ∈ xs ↔⟨ Any↔Any-to _ xs ⟩
z ∈L (_↠_.to List↠List xs) ↔⟨ xs≈ys z ⟩
z ∈L (_↠_.to List↠List ys) ↔⟨ inverse $ Any↔Any-to _ ys ⟩
z ∈ ys □
}
≈-⇔-from-≈-from :
{A : Type} {xs ys : P.List A} →
xs ≈-bagL ys ⇔ _↠_.from List↠List xs ≈-bag _↠_.from List↠List ys
≈-⇔-from-≈-from {xs = xs} {ys} = record
{ to = λ xs≈ys z →
z ∈ (_↠_.from List↠List xs) ↔⟨ Any-from↔Any _ xs ⟩
z ∈L xs ↔⟨ xs≈ys z ⟩
z ∈L ys ↔⟨ inverse $ Any-from↔Any _ ys ⟩
z ∈ (_↠_.from List↠List ys) □
; from = λ xs≈ys z →
z ∈L xs ↔⟨ inverse $ Any-from↔Any _ xs ⟩
z ∈ (_↠_.from List↠List xs) ↔⟨ xs≈ys z ⟩
z ∈ (_↠_.from List↠List ys) ↔⟨ Any-from↔Any _ ys ⟩
z ∈L ys □
}
------------------------------------------------------------------------
-- Constructors
[] : {A : Type} → ⟦ List ⟧ A
[] = (zero , λ ())
infixr 5 _∷_
_∷_ : {A : Type} → A → ⟦ List ⟧ A → ⟦ List ⟧ A
x ∷ (n , lkup) = (suc n , [ (λ _ → x) , lkup ])
-- Even if we don't assume extensionality we can prove that
-- intensionally distinct implementations of the constructors are bag
-- equivalent.
[]≈ : {A : Type} {lkup : _ → A} →
_≈-bag_ {C₂ = List} [] (zero , lkup)
[]≈ _ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (() , _) }
; from = λ { (() , _) }
}
; right-inverse-of = λ { (() , _) }
}
; left-inverse-of = λ { (() , _) }
}
∷≈ : ∀ {A : Type} {n} {lkup : _ → A} →
_≈-bag_ {C₂ = List}
(lkup (inj₁ tt) ∷ (n , lkup ∘ inj₂))
(suc n , lkup)
∷≈ _ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (inj₁ tt , eq) → (inj₁ tt , eq)
; (inj₂ s , eq) → (inj₂ s , eq)
}
; from = λ { (inj₁ tt , eq) → (inj₁ tt , eq)
; (inj₂ s , eq) → (inj₂ s , eq)
}
}
; right-inverse-of = λ { (inj₁ tt , eq) → refl _
; (inj₂ s , eq) → refl _
}
}
; left-inverse-of = λ { (inj₁ tt , eq) → refl _
; (inj₂ s , eq) → refl _
}
}
-- Any lemmas for the constructors.
Any-[] : {A : Type} (P : A → Type) →
Any P [] ↔ ⊥₀
Any-[] _ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (() , _) }
; from = λ ()
}
; right-inverse-of = λ ()
}
; left-inverse-of = λ { (() , _) }
}
Any-∷ : ∀ {A : Type} (P : A → Type) {x xs} →
Any P (x ∷ xs) ↔ P x ⊎ Any P xs
Any-∷ _ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (inj₁ tt , eq) → inj₁ eq
; (inj₂ s , eq) → inj₂ (s , eq)
}
; from = λ { (inj₁ eq) → (inj₁ tt , eq)
; (inj₂ (s , eq)) → (inj₂ s , eq)
}
}
; right-inverse-of = λ { (inj₁ eq) → refl _
; (inj₂ (s , eq)) → refl _
}
}
; left-inverse-of = λ { (inj₁ tt , eq) → refl _
; (inj₂ s , eq) → refl _
}
}
------------------------------------------------------------------------
-- More functions
-- A fold for lists. (Well, this is not a catamorphism, it is a
-- paramorphism.)
fold : {A B : Type} → B → (A → ⟦ List ⟧ A → B → B) → ⟦ List ⟧ A → B
fold {A} {B} nl cns = uncurry fold′
where
fold′ : (n : ℕ) → (Fin n → A) → B
fold′ zero lkup = nl
fold′ (suc n) lkup =
cns (lkup fzero) (n , lkup ∘ fsuc) (fold′ n (lkup ∘ fsuc))
-- A lemma which can be used to prove properties about fold.
--
-- The "respects bag equivalence" argument could be omitted if
-- equality of functions were extensional.
fold-lemma : ∀ {A B : Type} {nl : B} {cns : A → ⟦ List ⟧ A → B → B}
(P : ⟦ List ⟧ A → B → Type) →
(∀ xs ys → xs ≈-bag ys → ∀ b → P xs b → P ys b) →
P [] nl →
(∀ x xs b → P xs b → P (x ∷ xs) (cns x xs b)) →
∀ xs → P xs (fold nl cns xs)
fold-lemma {A} {nl = nl} {cns} P resp P-nl P-cns = uncurry fold′-lemma
where
fold′-lemma : ∀ n (lkup : Fin n → A) →
P (n , lkup) (fold nl cns (n , lkup))
fold′-lemma zero lkup = resp _ _ []≈ _ P-nl
fold′-lemma (suc n) lkup = resp _ _ ∷≈ _ $
P-cns _ _ _ $ fold′-lemma n (lkup ∘ fsuc)
-- Why have I included both fold and fold-lemma rather than simply a
-- dependent eliminator? I tried this, and could easily define the
-- functions I wanted to define. However, the functions were defined
-- together with (partial) correctness proofs, and were unnecessarily
-- hard to read. I wanted to be able to define functions which were
-- easy to read, like the _++_ function below, and then have the
-- option to prove properties about them, like Any-++.
--
-- Unfortunately this turned out to be harder than expected. When
-- proving the Any-++ lemma it seemed as if I had to prove that _++_
-- preserves bag equivalence in its first argument in order to
-- instantiate the "respects bag equivalence" argument. However, my
-- preferred proof of this property uses Any-++…
--
-- An alternative could be to assume that equality of functions is
-- extensional, in which case the "respects bag equivalence" argument
-- could be removed. Another option would be to listen to Conor
-- McBride and avoid higher-order representations of first-order data.
-- Append.
infixr 5 _++_
_++_ : {A : Type} → ⟦ List ⟧ A → ⟦ List ⟧ A → ⟦ List ⟧ A
xs ++ ys = fold ys (λ z _ zs → z ∷ zs) xs
-- An Any lemma for append.
Any-++ : ∀ {A : Type} (P : A → Type) xs ys →
Any P (xs ++ ys) ↔ Any P xs ⊎ Any P ys
Any-++ P xs ys = fold-lemma
(λ xs xs++ys → Any P xs++ys ↔ Any P xs ⊎ Any P ys)
(λ us vs us≈vs us++ys hyp →
Any P us++ys ↔⟨ hyp ⟩
Any P us ⊎ Any P ys ↔⟨ _⇔_.to (∼⇔∼″ us vs) us≈vs P ⊎-cong id ⟩
Any P vs ⊎ Any P ys □)
(Any P ys ↔⟨ inverse ⊎-left-identity ⟩
⊥ ⊎ Any P ys ↔⟨ inverse (Any-[] P) ⊎-cong id ⟩
Any P [] ⊎ Any P ys □)
(λ x xs xs++ys ih →
Any P (x ∷ xs++ys) ↔⟨ Any-∷ P ⟩
P x ⊎ Any P xs++ys ↔⟨ id ⊎-cong ih ⟩
P x ⊎ Any P xs ⊎ Any P ys ↔⟨ ⊎-assoc ⟩
(P x ⊎ Any P xs) ⊎ Any P ys ↔⟨ inverse (Any-∷ P) ⊎-cong id ⟩
Any P (x ∷ xs) ⊎ Any P ys □)
xs
| {
"alphanum_fraction": 0.4558823529,
"avg_line_length": 35.900621118,
"ext": "agda",
"hexsha": "1cce8fbcfcd7886656ecbfaeb3542f4d79abdaf8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Container/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Container/List.agda",
"max_line_length": 135,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Container/List.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 4006,
"size": 11560
} |
{-# OPTIONS --erased-cubical --safe #-}
module Music where
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _≤_; _≤?_)
open import Data.Integer using (ℤ; +_)
open import Data.List using (List; foldr; []; _∷_; reverse; sum; map)
open import Data.Product using (_×_; _,_)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Vec using (Vec; []; _∷_; replicate; concat; zipWith; toList; _++_; foldr₁; take; drop) renaming (map to vmap)
open import Function using (_∘_)
open import Data.Nat.Properties using (<⇒≤)
open import Relation.Nullary using (yes; no)
open import Relation.Binary.PropositionalEquality using (sym; subst)
open import Nat
open import Note
open import Pitch
open import Interval
-- A point in the music grid, which can either be a tone,
-- a continuation of a previous tone, or a rest.
data Point : Set where
tone : Pitch → Point
hold : Pitch → Point
rest : Point
data Melody (n : ℕ) : Set where
melody : Vec Point n → Melody n
unmelody : {n : ℕ} → Melody n → Vec Point n
unmelody (melody ps) = ps
infixr 5 _m++_
_m++_ : {m n : ℕ} → Melody m → Melody n → Melody (m + n)
melody a m++ melody b = melody (a ++ b)
note→melody : (n : Note) → Melody (noteDuration n)
note→melody (tone zero p) = melody []
note→melody (tone (suc d) p) = melody (tone p ∷ replicate (hold p))
note→melody (rest _) = melody (replicate rest)
notes→melody : (ns : List Note) → Melody (sum (map noteDuration ns))
notes→melody [] = melody []
notes→melody (n ∷ ns) = note→melody n m++ notes→melody ns
pitches→melody : {n : ℕ} → (d : Duration) → (ps : Vec Pitch n) → Melody (n * d)
pitches→melody d ps = melody (concat (vmap (unmelody ∘ note→melody ∘ tone d) ps))
-- Assumes melody is well-formed in that a held note has the
-- same pitch as the note before it.
-- Does not consolidate rests.
melody→notes : {n : ℕ} → Melody n → List Note
melody→notes (melody m) = (reverse ∘ mn 0 ∘ reverse ∘ toList) m
where mn : ℕ → List Point → List Note -- c is the number of held points
mn c [] = []
mn c (tone p ∷ ps) = tone (suc c) p ∷ mn 0 ps
mn c (hold _ ∷ ps) = mn (suc c) ps
mn c (rest ∷ ps) = rest 1 ∷ mn 0 ps
transposePoint : ℤ → Point → Point
transposePoint k (tone p) = tone (transposePitch k p)
transposePoint k (hold p) = hold (transposePitch k p)
transposePoint k rest = rest
transposeMelody : {n : ℕ} → ℤ → Melody n → Melody n
transposeMelody k = melody ∘ vmap (transposePoint k) ∘ unmelody
data Chord (n : ℕ) : Set where
chord : Vec Point n → Chord n
unchord : {n : ℕ} → Chord n → Vec Point n
unchord (chord ps) = ps
-- We represent music as a v × d grid where v is the number of voices and d is the duration.
-- The primary representation is as parallel melodies (counterpoint).
data Counterpoint (v : ℕ) (d : ℕ): Set where
cp : Vec (Melody d) v → Counterpoint v d
uncp : {v d : ℕ} → Counterpoint v d → Vec (Melody d) v
uncp (cp m) = m
-- An alternative representation of music is as a series of chords (harmonic progression).
data Harmony (v : ℕ) (d : ℕ): Set where
harmony : Vec (Chord v) d → Harmony v d
unharmony : {v d : ℕ} → Harmony v d → Vec (Chord v) d
unharmony (harmony h) = h
pitches→harmony : {n : ℕ} (d : Duration) → (ps : Vec Pitch n) → Harmony n d
pitches→harmony zero ps = harmony []
pitches→harmony (suc d) ps = harmony (chord (vmap tone ps) ∷ replicate (chord (vmap hold ps)))
pitchPair→Harmony : (d : Duration) → PitchPair → Harmony 2 d
pitchPair→Harmony d (p , q) = pitches→harmony d (p ∷ q ∷ [])
pitchInterval→Harmony : (d : Duration) → PitchInterval → Harmony 2 d
pitchInterval→Harmony d = pitchPair→Harmony d ∘ pitchIntervalToPitchPair
{-
pitchIntervalsToCounterpoint : PitchInterval → Counterpoint
pitchIntervalsToCounterpoint = pitchPairToCounterpoint ∘ pitchIntervalToPitchPair
-}
addEmptyVoice : {v d : ℕ} → Harmony v d → Harmony (suc v) d
addEmptyVoice (harmony h) = harmony (vmap (chord ∘ (rest ∷_) ∘ unchord) h)
infixl 5 _+H+_
_+H+_ : {v d d' : ℕ} → Harmony v d → Harmony v d' → Harmony v (d + d')
h +H+ h' = harmony (unharmony h ++ unharmony h')
foldIntoHarmony : {k n : ℕ} (ds : Vec Duration (suc k)) → (pss : Vec (Vec Pitch n) (suc k)) → Harmony n (foldr₁ _+_ ds)
foldIntoHarmony (d ∷ []) (ps ∷ []) = pitches→harmony d ps
foldIntoHarmony (d ∷ d' ∷ ds) (ps ∷ ps' ∷ pss) = (pitches→harmony d ps) +H+ (foldIntoHarmony (d' ∷ ds) (ps' ∷ pss))
-- matrix transposition
mtranspose : {A : Set}{m n : ℕ} → Vec (Vec A n) m → Vec (Vec A m) n
mtranspose [] = replicate []
mtranspose (xs ∷ xss) = zipWith _∷_ xs (mtranspose xss)
counterpoint→harmony : {v d : ℕ} → Counterpoint v d → Harmony v d
counterpoint→harmony = harmony ∘ vmap chord ∘ mtranspose ∘ vmap unmelody ∘ uncp
harmony→counterpoint : {v d : ℕ} → Harmony v d → Counterpoint v d
harmony→counterpoint = cp ∘ vmap melody ∘ mtranspose ∘ vmap unchord ∘ unharmony
-- Fix length of a melody, either truncating or padding with rests
fixLength : {m : ℕ} → (n : ℕ) → Melody m → Melody n
fixLength {m} n (melody ns) with <-∨-≥ n m
... | inj₁ n<m = melody (take n (subst (Vec Point) (sym (m+n-m=n n m {<⇒≤ n<m})) ns))
... | inj₂ m≤n = melody (subst (Vec Point) (m+n-m=n m n) (ns ++ replicate {n = n - m ⟨ m≤n ⟩} rest))
holdToTone : Point → Point
holdToTone (tone p) = tone p
holdToTone (hold p) = tone p
holdToTone rest = rest
firstHoldToTone : {n : ℕ} → Melody n → Melody n
firstHoldToTone (melody []) = melody []
firstHoldToTone (melody (x ∷ xs)) = melody (holdToTone x ∷ xs)
-- Drop points, but convert any held tones to tones.
dropPoints : {n : ℕ} → (m : ℕ) → Melody (m + n) → Melody n
dropPoints m = firstHoldToTone ∘ melody ∘ drop m ∘ unmelody
| {
"alphanum_fraction": 0.6486296557,
"avg_line_length": 38.7210884354,
"ext": "agda",
"hexsha": "1bb126fd6ce8091e8c456c512e09f41199cf2a78",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "agda/Music.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "agda/Music.agda",
"max_line_length": 130,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "agda/Music.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 1953,
"size": 5692
} |
module tests.String where
open import Prelude.IO
open import Prelude.List
open import Prelude.String
open import Prelude.Unit
testString : String
testString = "To boldly go where no man gone before"
printList : forall {A} -> (A -> IO Unit) -> List A -> IO Unit
printList p [] = return unit
printList p (x :: xs) =
p x ,,
printList p xs
main : IO Unit
main =
putStrLn testString ,,
printList printChar (fromString testString) ,,
putStrLn "" ,,
putStrLn (fromList (fromString testString)) ,,
return unit
| {
"alphanum_fraction": 0.6859813084,
"avg_line_length": 21.4,
"ext": "agda",
"hexsha": "a8c28d976605b9e3aaaa0bc23b91e43cdba41c50",
"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/epic/tests/String.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/epic/tests/String.agda",
"max_line_length": 61,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/epic/tests/String.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": 140,
"size": 535
} |
{-# OPTIONS --safe --without-K #-}
open import Relation.Binary
module Data.List.Membership.Setoid.Trans {a p} (S : Setoid a p) where
open Setoid S
open import Data.List.Membership.Setoid (S)
open import Data.List.Any
≈-trans-∈ : ∀ {x y xs} → x ≈ y → y ∈ xs → x ∈ xs
≈-trans-∈ x≈y (here px) = here (trans x≈y px)
≈-trans-∈ x≈y (there p) = there (≈-trans-∈ x≈y p)
| {
"alphanum_fraction": 0.6318681319,
"avg_line_length": 30.3333333333,
"ext": "agda",
"hexsha": "de639efbf196032e0098f0d6ce4d50443309115c",
"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": "d4cd2a3442a9b58e6139499d16a2b31268f27f80",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "tizmd/agda-distinct-disjoint",
"max_forks_repo_path": "src/Data/List/Membership/Setoid/Trans.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d4cd2a3442a9b58e6139499d16a2b31268f27f80",
"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": "tizmd/agda-distinct-disjoint",
"max_issues_repo_path": "src/Data/List/Membership/Setoid/Trans.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d4cd2a3442a9b58e6139499d16a2b31268f27f80",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "tizmd/agda-distinct-disjoint",
"max_stars_repo_path": "src/Data/List/Membership/Setoid/Trans.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 141,
"size": 364
} |
-- {-# OPTIONS --no-coverage-check #-}
-- {-# OPTIONS -v tc.lhs:40 #-}
module FlexibleFunArity where
open import Common.Equality
data Bool : Set where true false : Bool
data Maybe (A : Set) : Set where
nothing : Maybe A
just : A → Maybe A
Case : {A : Set} → Maybe A → Set → Set → Set
Case nothing B C = B
Case (just _) B C = C
sample : {A : Set} (m : Maybe A) → Case m Bool (Maybe A → Bool)
sample (just a) (just b) = true
sample (just a) nothing = false
sample nothing = true
g : Bool -> Bool -> Bool
g false true = false
g true = \ x -> true
g false false = true
-- g true false = false -- Unreachable clause
testg1 : ∀ {x} → g true x ≡ true
testg1 = refl
testg2 : g false true ≡ false
testg2 = refl
testg3 : g false false ≡ true
testg3 = refl
T : Bool -> Set
T true = Bool
T false = Bool -> Bool
f : (b : Bool) -> T b
f false true = false
f false false = true
f true = true
testf1 : f true ≡ true
testf1 = refl
testf2 : f false true ≡ false
testf2 = refl
testf3 : f false false ≡ true
testf3 = refl
{- checking clause
f false true
starts with
f (b : Bool) : T b
splits on b
f true -- no match, discard
f false -- matches
instantiate type
f false : T false = Bool -> Bool
extend clause
f false (y : Bool) : Bool
split on y
f false true -- matches
f false false -- no match, discard
done
-}
{- coverage check starts with
f (x : Bool)
splits on x
f true -- finds clause 1
f false
NEW: remaing clauses have bigger arity, so expands to
f false (y : Bool)
splits on y
f false true -- finds clause 2
f false false -- finds clause 3
done
-}
| {
"alphanum_fraction": 0.6249232658,
"avg_line_length": 15.2242990654,
"ext": "agda",
"hexsha": "1bb0ce1b708d94069f5c7cec134dff49c00b7cd8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/FlexibleFunArity.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/FlexibleFunArity.agda",
"max_line_length": 63,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/FlexibleFunArity.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": 533,
"size": 1629
} |
-- Andreas, 2019-02-23, issue #3578.
-- Preserve types as much as possible during pattern matching.
-- New unifier (from Agda 2.5.1) was normalizing too much.
-- {-# OPTIONS -v tc.lhs.unify:45 #-}
data Nat : Set where
zero : Nat
postulate
MustNotBeNamed : Set
A = MustNotBeNamed
data P : Nat → Set where
z : A → P zero
test : ∀{n} → P n → Set
test (z x) = {!x!} -- C-c C-,
-- EXPECTED:
--
-- Goal: Set
-- ——————————————
-- x : A
| {
"alphanum_fraction": 0.5833333333,
"avg_line_length": 17.0769230769,
"ext": "agda",
"hexsha": "0d534d19fb062533309239df92afd9066cdfbef6",
"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/Issue3578.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/Issue3578.agda",
"max_line_length": 62,
"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/Issue3578.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": 157,
"size": 444
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.SetTruncation where
open import Cubical.HITs.SetTruncation.Base public
open import Cubical.HITs.SetTruncation.Properties public
| {
"alphanum_fraction": 0.8,
"avg_line_length": 33.3333333333,
"ext": "agda",
"hexsha": "5343e69e67152ec77c2ac5146e86bbd8fcc9dc3c",
"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/SetTruncation.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/SetTruncation.agda",
"max_line_length": 56,
"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/SetTruncation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 54,
"size": 200
} |
-- Testing termination using subpatterns
module TerminationSubpattern where
-- a list with two different conses
data EOList (A : Set) : Set where
Nil : EOList A
ECons : A -> EOList A -> EOList A
OCons : A -> EOList A -> EOList A
butLastWithDefault : {A : Set} -> A -> EOList A -> A
butLastWithDefault a Nil = a
butLastWithDefault a (ECons b l) = butLastWithDefault b l
butLastWithDefault a (OCons b l) = butLastWithDefault b l
-- a very stupid implementation:
butLastWithDefault' : {A : Set} -> A -> EOList A -> A
butLastWithDefault' a Nil = a
butLastWithDefault' a (ECons b Nil) = b
butLastWithDefault' a (OCons b Nil) = b
butLastWithDefault' a (ECons b (OCons c l)) = butLastWithDefault' b (OCons c l)
butLastWithDefault' a (ECons b (ECons c l)) = butLastWithDefault' b (ECons c l)
butLastWithDefault' a (OCons b (OCons c l)) = butLastWithDefault' b (OCons c l)
butLastWithDefault' a (OCons b (ECons c l)) = butLastWithDefault' b (ECons c l)
-- terminates, because, e.g. in the last line
--
-- ECons c l is a subpattern of OCons b (ECons c l)
-- another justification is with structured orders
-- if all constructors are considered equivalent
| {
"alphanum_fraction": 0.70794193,
"avg_line_length": 34.4411764706,
"ext": "agda",
"hexsha": "f2821954b56df4317b81baa3cc02395d52646e84",
"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/TerminationSubpattern.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/TerminationSubpattern.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/TerminationSubpattern.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": 370,
"size": 1171
} |
module Lemmachine.Runner where
{-# IMPORT Lemmachine.FFI #-}
open import Lemmachine.Resource
open import Lemmachine.Resource.Configure
open import Lemmachine.Request
open import Lemmachine.Response
open import Lemmachine.Utils
open import Lemmachine.Resolve
open import Data.Unit
open import Data.Nat
open import Data.String
open import Data.Function
open import Foreign.Haskell
open import IO.Primitive
private
data Data-Request : Set where
request :
Method →
Version →
IP →
LocalPath →
Path →
RawPath →
PathTokens →
RequestHeaders →
Body →
Cookie →
QueryString →
Port →
Data-Request
{-# COMPILED_DATA Data-Request
Lemmachine.FFI.Request
Lemmachine.FFI.Request
#-}
toRequest : Data-Request → Request
toRequest (request
method
version
peer
dispPath
path
rawPath
pathTokens
headers
body
cookie
queryString
port
) = record {
method = method
; version = version
; peer = peer
; dispPath = dispPath
; path = path
; rawPath = rawPath
; pathTokens = pathTokens
; headers = headers
; reqBody = body
; cookie = cookie
; queryString = queryString
; port = port
}
data Data-Response : Set where
response : String → ResponseHeaders → String → Data-Response
{-# COMPILED_DATA Data-Response
Lemmachine.FFI.Response
Lemmachine.FFI.Response
#-}
fromResponse : Response → Data-Response
fromResponse resp = response
(showStatus $ Response.status resp)
(Response.headers resp)
(Response.body resp)
Data-resolve : Application → Data-Request → Data-Response
Data-resolve app req = fromResponse $ app (toRequest req)
postulate run : (Data-Request → Data-Response) → IO Unit
{-# COMPILED run Lemmachine.FFI.run #-}
runResolve : Application → IO Unit
runResolve app = run $ Data-resolve app
| {
"alphanum_fraction": 0.6678719008,
"avg_line_length": 21.7528089888,
"ext": "agda",
"hexsha": "11503fdaabb83cd141e8a17de7cbc45c924661a2",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "src/Lemmachine/Runner.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "src/Lemmachine/Runner.agda",
"max_line_length": 64,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "src/Lemmachine/Runner.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 492,
"size": 1936
} |
module Common.MAlonzo where
open import Common.Prelude hiding (putStrLn)
open import Common.Coinduction
{-# IMPORT Data.Text.IO #-}
postulate
putStrLn : ∞ String → IO Unit
{-# COMPILED putStrLn Data.Text.IO.putStrLn #-}
main = putStrLn (♯ "This is a dummy main routine.")
mainPrint : String → _
mainPrint s = putStrLn (♯ s)
mainPrintNat : Nat → _
mainPrintNat n = putStrLn (♯ (natToString n))
| {
"alphanum_fraction": 0.7096774194,
"avg_line_length": 19.1904761905,
"ext": "agda",
"hexsha": "c26b550db68489c7e44fd06ef09e38ebbd485f00",
"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/Common/MAlonzo.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/Common/MAlonzo.agda",
"max_line_length": 51,
"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/Common/MAlonzo.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 107,
"size": 403
} |
import cedille-options
open import general-util
open import lib
module process-cmd
(options : cedille-options.options)
{mF : Set → Set}
{{_ : monad mF}}
(progress-update : string → 𝔹 → mF ⊤) where
--open import cedille-find
open import cedille-types
open import classify options {mF}
open import constants
open import conversion
open import ctxt
open import is-free
open import spans options {mF}
open import syntax-util
open import toplevel-state options {mF}
-- open import to-string
import cws-types
import cws
-- generate spans from the given comments-and-whitespace syntax tree
process-cwst-etys : cws-types.entities → spanM ⊤
process-cwst-ety : cws-types.entity → spanM ⊤
process-cwst-etys (cws-types.Entity ety etys) = (process-cwst-ety ety) ≫span process-cwst-etys etys
process-cwst-etys cws-types.EndEntity = spanMr triv
process-cwst-ety cws-types.EntityNonws = spanMr triv
process-cwst-ety (cws-types.EntityWs pi pi') = spanMr triv -- spanM-add (whitespace-span pi pi')
process-cwst-ety (cws-types.EntityComment pi pi') = spanM-add (comment-span pi pi')
process-cwst : toplevel-state → filepath → spanM toplevel-state
process-cwst s filename with include-elt.cwst (get-include-elt s filename)
process-cwst s filename | nothing = spanMr s
process-cwst s filename | just (cws-types.File etys) = process-cwst-etys etys ≫span spanMr s
process-t : Set → Set
process-t X = toplevel-state → X → (need-to-check : 𝔹) → spanM toplevel-state
check-and-add-params : posinfo → params → spanM (𝕃 (string × restore-def))
check-and-add-params pi' (ParamsCons p@(Decl pi1 pi1' me x atk pi2) ps') =
check-tk atk ≫span
spanM-add (Decl-span param pi1 x atk pi' {- make this span go to the end of the def, so nesting will work
properly for computing the context in the frontend -}) ≫span
add-tk' (me-erased me) pi1' x atk ≫=span λ mi →
check-and-add-params pi' ps' ≫=span λ ms → spanMr ((x , mi) :: ms)
check-and-add-params _ ParamsNil = spanMr []
dont-check-and-add-params : posinfo → params → spanM (𝕃 (string × restore-def))
dont-check-and-add-params pi' (ParamsCons p@(Decl pi1 pi1' me x atk pi2) ps') =
add-tk' (me-erased me) pi1' x atk ≫=span λ mi →
dont-check-and-add-params pi' ps' ≫=span λ ms → spanMr ((x , mi) :: ms)
dont-check-and-add-params _ ParamsNil = spanMr []
optAs-posinfo-var : optAs → (posinfo × var) → spanM (posinfo × var)
optAs-posinfo-var NoOptAs = spanMr
optAs-posinfo-var (SomeOptAs pi x) orig = get-ctxt λ Γ →
spanM-add (Import-module-span Γ orig ParamsNil [ not-for-navigation ] nothing) ≫span spanMr (pi , x)
add-params-kind : params → kind → kind
add-params-kind (ParamsCons (Decl pi pi' m v k' pi'') ps) k =
KndPi pi pi' v k' (add-params-kind ps k)
add-params-kind ParamsNil k = k
{-# TERMINATING #-}
process-consts : dataConsts → params → spanM ⊤
process-cmd : process-t cmd
process-cmds : process-t cmds
process-params : process-t (posinfo × params)
process-start : toplevel-state → filepath → (progress-name : string) → start → (need-to-check : 𝔹) → spanM toplevel-state
process-file : toplevel-state → filepath → (progress-name : string) → mF (toplevel-state × mod-info)
process-cmd (mk-toplevel-state ip fns is Γ) (DefTermOrType op (DefTerm pi x (SomeType tp) t) pi') tt {- check -} =
set-ctxt Γ ≫span
check-type tp (just star) ≫span
let tp' = qualif-type Γ tp in
check-term t (just tp') ≫span
check-erased-margs t (just tp') ≫span
get-ctxt (λ Γ →
let Γ' = ctxt-term-def pi globalScope op x t tp' Γ in
spanM-add (DefTerm-span Γ' pi x checking (just tp) t pi' []) ≫span
check-redefined pi x (mk-toplevel-state ip fns is Γ)
(spanM-add (uncurry (Var-span Γ' pi x checking) (compileFail-in Γ t)) ≫span
spanMr (mk-toplevel-state ip fns is Γ')))
process-cmd (mk-toplevel-state ip fns is Γ) (DefTermOrType op (DefTerm pi x (SomeType tp) t) pi') ff {- skip checking -} =
let tp' = qualif-type Γ tp in
check-redefined pi x (mk-toplevel-state ip fns is Γ)
(spanMr (mk-toplevel-state ip fns is (ctxt-term-def pi globalScope op x t tp' Γ)))
process-cmd (mk-toplevel-state ip fns is Γ) (DefTermOrType op (DefTerm pi x NoType t) pi') _ =
set-ctxt Γ ≫span
check-term t nothing ≫=span λ mtp →
check-erased-margs t nothing ≫span
get-ctxt (λ Γ →
let Γ' = maybe-else
(ctxt-term-udef pi globalScope op x t Γ)
(λ tp → ctxt-term-def pi globalScope op x t tp Γ) mtp in
spanM-add (DefTerm-span Γ' pi x synthesizing mtp t pi' []) ≫span
check-redefined pi x (mk-toplevel-state ip fns is Γ)
(spanM-add (uncurry (Var-span Γ' pi x synthesizing) (compileFail-in Γ t)) ≫span
spanMr (mk-toplevel-state ip fns is Γ')))
process-cmd (mk-toplevel-state ip fns is Γ) (DefTermOrType op (DefType pi x k tp) pi') tt {- check -} =
set-ctxt Γ ≫span
check-kind k ≫span
let k' = qualif-kind Γ k in
check-type tp (just k') ≫span
get-ctxt (λ Γ →
let Γ' = ctxt-type-def pi globalScope op x tp k' Γ in
spanM-add (DefType-span Γ' pi x checking (just k) tp pi' []) ≫span
check-redefined pi x (mk-toplevel-state ip fns is Γ)
(spanM-add (TpVar-span Γ' pi x checking [] nothing) ≫span
spanMr (mk-toplevel-state ip fns is Γ')))
process-cmd (mk-toplevel-state ip fns is Γ) (DefTermOrType op (DefType pi x k tp) pi') ff {- skip checking -} =
let k' = qualif-kind Γ k in
check-redefined pi x (mk-toplevel-state ip fns is Γ)
(spanMr (mk-toplevel-state ip fns is (ctxt-type-def pi globalScope op x tp k' Γ)))
process-cmd (mk-toplevel-state ip fns is Γ) (DefKind pi x ps k pi') tt {- check -} =
set-ctxt Γ ≫span
check-and-add-params pi' ps ≫=span λ ms →
check-kind k ≫span
get-ctxt (λ Γ →
let Γ' = ctxt-kind-def pi x ps k Γ in
spanM-add (DefKind-span Γ' pi x k pi') ≫span
check-redefined pi x (mk-toplevel-state ip fns is Γ)
(spanM-add (KndVar-span Γ' (pi , x) (posinfo-plus-str pi x) ps checking [] nothing) ≫span
spanMr (mk-toplevel-state ip fns is (ctxt-restore-info* Γ' ms))))
process-cmd (mk-toplevel-state ip fns is Γ) (DefKind pi x ps k pi') ff {- skip checking -} =
set-ctxt Γ ≫span
dont-check-and-add-params pi' ps ≫=span λ ms →
get-ctxt (λ Γ →
let Γ' = ctxt-kind-def pi x ps k Γ in
check-redefined pi x (mk-toplevel-state ip fns is Γ)
(spanMr (mk-toplevel-state ip fns is (ctxt-restore-info* Γ' ms))))
-- TODO ignore checking but still gen spans if need-to-check false?
process-cmd s (ImportCmd (Import pi op pi' x oa as pi'')) _ =
let fnₒ = ctxt-get-current-filename (toplevel-state.Γ s)
ie = get-include-elt s fnₒ in
case trie-lookup (include-elt.import-to-dep ie) x of λ where
nothing → spanM-add (Import-span pi "missing" pi'' [] (just ("File not found: " ^ x)))
≫span spanMr (set-include-elt s fnₒ (record ie {err = tt}))
(just fnᵢ) Γ ss →
process-file s fnᵢ x ≫=monad uncurry λ s _ →
(let s-e = scope-file s fnₒ fnᵢ oa (qualif-args (toplevel-state.Γ s) as) in
process-import op oa fnₒ fnᵢ (lookup-mod-params (toplevel-state.Γ s) fnᵢ) (maybe-else' (lookup-mod-params (toplevel-state.Γ s) fnₒ) ParamsNil id) ≫=span λ e →
spanM-add (Import-span pi fnᵢ pi'' [] (snd s-e maybe-or e)) ≫span spanMr (fst s-e)) Γ ss
where
-- When importing a file publicly, you may use any number of arguments as long as the
-- parameters of the current module are not free in them.
-- You may then use any number of single-variable parameters from the current module
-- as arguments as long as they retain the same order as before and have no non-parameter
-- arguments between them
-- (so parameters A, B, C, ..., Z can be used as arguments ∙ C ∙ X, but not ∙ X ∙ C)
public-import-params-ok : params → args → err-m
public-import-params-ok ps = h nothing where
err = just "You can only use parameters for arguments to public imports if the are in order at the end"
params-order : params → trie ℕ
params-order = h 0 where
h : ℕ → params → trie ℕ
h n ParamsNil = empty-trie
h n (ParamsCons (Decl _ _ me x atk _) ps) = trie-insert (h (suc n) ps) x n
arg-var : arg → maybe var
arg-var (TermArg me (Var pi x)) = just x
arg-var (TypeArg (TpVar pi x)) = just x
arg-var _ = nothing
pso = params-order ps
ps-free : arg → err-m → err-m
ps-free a e = if ~ are-free-in-args check-erased pso (ArgsCons a ArgsNil) then e else err
h : maybe ℕ → args → err-m
h c (ArgsCons a as) =
maybe-else' (arg-var a ≫=maybe trie-lookup pso)
(maybe-else' c (ps-free a $ h nothing as) λ _ → err) λ aₙ →
maybe-else' c (h (just aₙ) as) λ cₙ →
if cₙ ≥ aₙ then err else h (just aₙ) as
h n ArgsNil = nothing
process-import : optPublic → optAs → (cur imp : filepath) → maybe params → params → spanM err-m
process-import op oa fnₒ fnᵢ nothing _ = spanMr (just "Undefined module import (this probably shouldn't happen?)")
-- process-import op oa fnₒ fnᵢ (just psᵢ) nothing = spanMr (just "Current module undefined (this shouldn't happen!)")
process-import IsPublic (SomeOptAs _ _) fnₒ fnᵢ (just psᵢ) {-(just-} psₒ {-)-} = spanMr (just "Public import aren't allowed to be qualified")
process-import op oa fnₒ fnᵢ (just psᵢ) {-(just-} psₒ {-)-} =
optAs-posinfo-var oa (pi' , x) ≫=span λ pi-v →
with-ctxt (toplevel-state.Γ s)
(check-args-against-params (just (location-data (fnᵢ , first-position))) pi-v psᵢ as) ≫span
spanMr (maybe-if (optPublic-is-public op) ≫maybe
public-import-params-ok psₒ (qualif-args (toplevel-state.Γ s) as))
process-cmd (mk-toplevel-state ip fns is Γ) (DefDatatype dd@(Datatype pi pix x ps k cs _) pi') _ =
set-ctxt Γ ≫span
check-kind (add-params-kind ps k) ≫span --
get-ctxt (λ Γ →
let Γ' = ctxt-datatype-def pi x (qualif-params Γ ps) (qualif-kind Γ (add-params-kind ps k)) (Datatype pi pix x ps k cs pi') Γ in
set-ctxt Γ' ≫span
spanM-add (DefDatatype-span pi pix x pi') ≫span
spanM-add (TpVar-span Γ' pix x checking [] nothing) ≫span
process-consts cs ps ≫span
get-ctxt (λ Γ →
spanMr (mk-toplevel-state ip fns is Γ))) --(ctxt-restore-info* Γ ms))))
-- the call to ctxt-update-symbol-occurrences is for cedille-find functionality
process-cmds (mk-toplevel-state include-path files is Γ) (CmdsNext c cs) need-to-check =
process-cmd (mk-toplevel-state include-path files is Γ) c need-to-check ≫=span λ s →
process-cmds s cs need-to-check
process-cmds s CmdsStart need-to-check = set-ctxt (toplevel-state.Γ s) ≫span spanMr s
-- TODO ignore checking but still qualify if need-to-check false?
process-params s (pi , ps) need-to-check =
set-ctxt (toplevel-state.Γ s) ≫span
check-and-add-params pi ps ≫=span λ _ →
spanM-set-params ps ≫span
get-ctxt λ Γ →
spanMr (record s {Γ = ctxt-add-current-params Γ})
process-start s filename pn (File pi0 is pi1 pi2 mn ps cs pi3) need-to-check =
λ Γ ss → progress-update pn need-to-check ≫monad
(process-cmds s (imps-to-cmds is) need-to-check ≫=span λ s →
process-params s (pi0 , ps) need-to-check ≫=span λ s →
process-cmds s cs need-to-check ≫=span λ s →
process-cwst s filename ≫=span λ s →
spanM-add (File-span (toplevel-state.Γ s) pi0 (posinfo-plus pi3 1) filename) ≫span
let pi2' = posinfo-plus-str pi2 mn in
spanM-add (Module-span pi2 pi2') ≫span
spanM-add (Module-header-span pi1 pi2') ≫span
spanMr s) Γ ss
{- process (type-check if necessary) the given file.
We assume the given top-level state has a syntax tree associated with the file. -}
process-file s filename pn with get-include-elt s filename
process-file s filename pn | ie =
proceed s (include-elt.ast ie) (set-need-to-add-symbols-to-context-include-elt ie ff) ≫=monad λ where
(s , ie , ret-mod) → returnM (set-include-elt s filename ie , ret-mod)
{- update the include-elt and the toplevel state (but we will push the updated include-elt into the toplevel state
just above, after proceed finishes. -}
where proceed : toplevel-state → maybe start → include-elt → mF (toplevel-state × include-elt × mod-info)
proceed s nothing ie' = progress-update filename tt ≫monad returnM (s , ie' , ctxt-get-current-mod (toplevel-state.Γ s)) {- should not happen -}
proceed s (just x) ie' with include-elt.need-to-add-symbols-to-context ie {- this indeed should be ie, not ie' -}
proceed (mk-toplevel-state ip fns is Γ) (just x) ie' | tt
with include-elt.do-type-check ie | ctxt-get-current-mod Γ
proceed (mk-toplevel-state ip fns is Γ) (just x) ie' | tt | do-check | prev-mod =
let Γ = ctxt-initiate-file Γ filename (start-modname x) in
process-start (mk-toplevel-state ip fns (trie-insert is filename ie') Γ)
filename pn x do-check Γ empty-spans ≫=monad cont
where cont : toplevel-state × ctxt × spans → mF (toplevel-state × include-elt × mod-info)
cont (mk-toplevel-state ip fns is Γ , Γ' @ (mk-ctxt ret-mod _ _ _ _) , ss) =
progress-update pn do-check ≫monad returnM
(mk-toplevel-state ip (if do-check then (filename :: fns) else fns) is
(ctxt-set-current-mod Γ prev-mod) ,
(if do-check then set-spans-include-elt ie' ss else ie') , ret-mod)
proceed s (just x) ie' | _ = returnM (s , ie' , ctxt-get-current-mod (toplevel-state.Γ s))
process-consts DataNull ps = spanMok
process-consts (DataCons (DataConst pi c tp) cs) ps =
get-ctxt (λ Γ →
let t = abs-expand-type' ps tp in -- add-param-type ps (qualif-type Γ tp)
check-type t (just star) ≫span
set-ctxt (ctxt-const-def pi c (qualif-type Γ t) Γ) ≫span
spanM-add (DefDataConst-span pi c) ≫span
process-consts cs ps)
| {
"alphanum_fraction": 0.6521180084,
"avg_line_length": 51.0912408759,
"ext": "agda",
"hexsha": "8970e99c97a36fed79fe5c68a6b1dd21fa0ff5fd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xoltar/cedille",
"max_forks_repo_path": "src/process-cmd.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "xoltar/cedille",
"max_issues_repo_path": "src/process-cmd.agda",
"max_line_length": 167,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xoltar/cedille",
"max_stars_repo_path": "src/process-cmd.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4425,
"size": 13999
} |
------------------------------------------------------------------------------
-- All the distributive laws modules
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module DistributiveLaws.Everything where
open import DistributiveLaws.Base
open import DistributiveLaws.Base.Consistency.Axioms
open import DistributiveLaws.PropertiesI
open import DistributiveLaws.Lemma3-ATP
open import DistributiveLaws.Lemma4-ATP
open import DistributiveLaws.Lemma5-ATP
open import DistributiveLaws.Lemma6-ATP
open import DistributiveLaws.TaskB-AllStepsATP
open import DistributiveLaws.TaskB-HalvedStepsATP
open import DistributiveLaws.TaskB-I
open import DistributiveLaws.TaskB-TopDownATP
open import DistributiveLaws.TaskB.UnprovedATP
| {
"alphanum_fraction": 0.6487068966,
"avg_line_length": 35.6923076923,
"ext": "agda",
"hexsha": "c062d29acf11537288936d399d444f23efd08c46",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/DistributiveLaws/Everything.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/DistributiveLaws/Everything.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/DistributiveLaws/Everything.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": 202,
"size": 928
} |
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.McCarthy91.WF-Relation.Induction.NonAcc.TerminationCheckIssue
where
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
postulate someℕ : ℕ
{-# TERMINATING #-}
foo : ℕ → ℕ → ℕ
foo n zero = 10
foo zero (succ m) = foo zero someℕ
foo (succ n) (succ m) = foo n (succ m)
{-# TERMINATING #-}
bar : ℕ → ℕ → ℕ
bar n zero = 10
bar zero (succ m) = bar m someℕ
bar (succ n) (succ m) = bar n (succ m)
{-# TERMINATING #-}
foobar : ℕ → ℕ → ℕ
foobar n zero = 10
foobar zero (succ m) with someℕ
... | zero = 10
... | succ o = foobar m (succ o)
foobar (succ n) (succ m) = foobar n (succ m)
| {
"alphanum_fraction": 0.5634824667,
"avg_line_length": 22.9722222222,
"ext": "agda",
"hexsha": "41288fc9e1b077fc458a78de43f0972e387be303",
"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/McCarthy91/WF-Relation/Induction/NonAcc/TerminationCheckIssue.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/McCarthy91/WF-Relation/Induction/NonAcc/TerminationCheckIssue.agda",
"max_line_length": 85,
"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/McCarthy91/WF-Relation/Induction/NonAcc/TerminationCheckIssue.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": 263,
"size": 827
} |
-- Andreas, 2016-12-20, issue #2349
{-# OPTIONS --show-implicit #-}
open import Agda.Primitive
open import Agda.Builtin.Equality
data D {{a}} (A : Set a) : Set a where
c : {{a : A}} (b : A) → D A
test : ∀ ℓ (A : Set ℓ) (x : D A) (a : A) → x ≡ c {{ℓ}} {{a = a}} a
test ℓ A x a = refl
-- ERROR:
-- x != c {{a}} of type D {{ℓ}} A
-- when checking that the expression refl has type
-- _≡_ {ℓ} {D {{ℓ}} A} x (c {{a}})
-- Note that (c {{a}}) is ill-typed here.
| {
"alphanum_fraction": 0.5291576674,
"avg_line_length": 23.15,
"ext": "agda",
"hexsha": "089fe6c381eb28661e6f9f4bdb46a416a67faa4b",
"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/Fail/Issue2349-instance-visible.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/Issue2349-instance-visible.agda",
"max_line_length": 66,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/Issue2349-instance-visible.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": 188,
"size": 463
} |
-- Andreas, 2012-09-15
-- Positive effects of making Agda recognize constant functions.
-- Arguments to constant functions are ignored in definitional equality.
{-# OPTIONS --copatterns #-}
module NonvariantPolarity where
open import Common.Equality
data ⊥ : Set where
record ⊤ : Set where
constructor trivial
data Bool : Set where
true false : Bool
True : Bool → Set
True true = ⊤
True false = ⊥
module IgnoreArg where
-- A function ignoring its first argument
knot : Bool → Bool → Bool
knot x true = false
knot x false = true
test : (y : Bool) → knot true y ≡ knot false y
test y = refl
module UnusedModulePar where
-- An unused module parameter
module M (x : Bool) where
not : Bool → Bool
not true = false
not false = true
open M true
open M false renaming (not to not′)
test : (y : Bool) → not y ≡ not′ y
test y = refl
module CoinductiveUnit where
record Unit : Set where
coinductive
constructor delay
field force : Unit
open Unit
-- The identity on Unit does not match on its argument, so it is constant.
id : Unit → Unit
force (id x) = id (force x)
idConst : (x y : Unit) → id x ≡ id y
idConst x y = refl
-- That does not imply x ≡ y (needs bisimulation).
| {
"alphanum_fraction": 0.6690647482,
"avg_line_length": 20.1774193548,
"ext": "agda",
"hexsha": "1b7c45ea99bb885839a4b038f70dd7df056384ed",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/NonvariantPolarity.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/NonvariantPolarity.agda",
"max_line_length": 76,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/NonvariantPolarity.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": 358,
"size": 1251
} |
{-
This file contains:
- Pushout-products of two maps;
- The connectivity of pushout-product maps.
-}
{-# OPTIONS --safe #-}
module Cubical.HITs.Pushout.PushoutProduct where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.HITs.Pushout.Base
open import Cubical.HITs.Pushout.Properties
open import Cubical.Homotopy.Connected
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
A : Type ℓ
B : Type ℓ'
X : Type ℓ''
Y : Type ℓ'''
-- The definition of pushout-product
PushProd : (f : X → A)(g : Y → B) → Type _
PushProd f g = Pushout (map-× (idfun _) g) (map-× f (idfun _))
_×̂_ : (f : X → A)(g : Y → B) → PushProd f g → A × B
(f ×̂ g) (inl (x , b)) = f x , b
(f ×̂ g) (inr (a , y)) = a , g y
(f ×̂ g) (push (x , y) i) = f x , g y
infixr 5 _×̂_
module _
(m n : ℕ)(f : X → A)(g : Y → B)
(connf : isConnectedFun m f)
(conng : isConnectedFun n g)
(P : A × B → TypeOfHLevel ℓ (m + n)) where
module _
(sec : (x : PushProd f g) → P ((f ×̂ g) x) .fst) where
private
fam : A → Type _
fam a = Σ[ k ∈ ((b : B) → P (a , b) .fst) ] ((y : Y) → k (g y) ≡ sec (inr (a , y)))
open Iso
fiberEquiv : (a : A)
→ fam a ≃ fiber (λ(s : (b : B) → P (a , b) .fst) → s ∘ g) (λ y → sec (inr (a , y)))
fiberEquiv a = isoToEquiv
(iso (λ (k , p) → k , λ i y → p y i)
(λ (k , p) → k , λ y i → p i y)
(λ _ → refl) (λ _ → refl))
is-m-trunc-fam : (a : A) → isOfHLevel m (fam a)
is-m-trunc-fam a =
isOfHLevelRespectEquiv _ (invEquiv (fiberEquiv a))
(isOfHLevelPrecomposeConnected m n (λ b → P (a , b)) g conng _)
sec-fam : (x : X) → fam (f x)
sec-fam x = (λ b → sec (inl (x , b))) , (λ y i → sec (push (x , y) i))
map-iso = elim.isIsoPrecompose f _ (λ a → fam a , is-m-trunc-fam a) connf
k = map-iso .inv sec-fam
ϕ = map-iso .rightInv sec-fam
ext : (x : A × B) → P x .fst
ext (a , b) = k a .fst b
ext-path : (x : PushProd f g) → ext ((f ×̂ g) x) ≡ sec x
ext-path (inl (x , b)) i = ϕ i x .fst b
ext-path (inr (a , y)) i = k a .snd y i
ext-path (push (x , y) i) j =
hcomp (λ k → λ
{ (i = i0) → ϕ j x .snd y i0
; (i = i1) → ϕ i0 x .snd y (j ∨ ~ k)
; (j = i0) → ϕ i0 x .snd y (i ∧ ~ k)
; (j = i1) → ϕ i1 x .snd y i })
(ϕ j x .snd y i)
lifting : hasSection (λ(s : (x : A × B) → P x .fst) → s ∘ (f ×̂ g))
lifting .fst sec = ext sec
lifting .snd sec i x = ext-path sec x i
-- The connectivity of pushout-product
isConnected×̂ : {m n : ℕ}{f : A → B}{g : X → Y}
→ isConnectedFun m f → isConnectedFun n g
→ isConnectedFun (m + n) (f ×̂ g)
isConnected×̂ congf congg =
elim.isConnectedPrecompose _ _ (lifting _ _ _ _ congf congg)
| {
"alphanum_fraction": 0.5389182058,
"avg_line_length": 28.0740740741,
"ext": "agda",
"hexsha": "edc5db256855f898f1006c5b0061f9ea6abe90a2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/HITs/Pushout/PushoutProduct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/HITs/Pushout/PushoutProduct.agda",
"max_line_length": 91,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/HITs/Pushout/PushoutProduct.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": 1182,
"size": 3032
} |
module SystemF.SmallStep where
open import Prelude
open import Data.Sum
open import Data.Product
open import Data.Vec hiding ([_])
open import SystemF.WellTyped
open import SystemF.Substitutions
open import SystemF.Substitutions.Lemmas
infixl 4 _≻_
-- irreducible System F terms
data Value {ν n} : Term ν n → Set where
λ' : ∀ τ t → Value (λ' τ t)
Λ : ∀ t → Value (Λ t)
-- single step reduction of System F terms
data _≻_ {ν n} : Term ν n → Term ν n → Set where
-- redexes
reduce-[] : ∀ t a → (Λ t) [ a ] ≻ t tm[/tp a ]
reduce-· : ∀ a t {u} → (λ' a t) · u ≻ t tm[/tm u ]
-- contextual closure
step-·₁ : ∀ {t t' u} → t ≻ t' → t · u ≻ t' · u
step-·₂ : ∀ {t u u'} → u ≻ u' → t · u ≻ t · u'
step-λ-body : ∀ {a t t'} → t ≻ t' → λ' a t ≻ λ' a t'
step-Λ-body : ∀ {t t'} → t ≻ t' → Λ t ≻ Λ t'
step-[] : ∀ {t t' a} → t ≻ t' → t [ a ] ≻ t' [ a ]
-- multi-step reductions
data _≻⋆_ {ν n} : Term ν n → Term ν n → Set where
≻-step : ∀ {t u} → t ≻ u → t ≻⋆ u
≻-trans : ∀ {t u v} → t ≻⋆ u → u ≻⋆ v → t ≻⋆ v
∀'-value-lemma : ∀ {ν n} {Γ : Ctx ν n} {t a} → Γ ⊢ t ∈ ∀' a → Value t → ∃ λ e → t ≡ Λ e
∀'-value-lemma () (λ' τ t)
∀'-value-lemma (Λ t∈∀a) (Λ t) = t , refl
→'-value-lemma : ∀ {ν n} {Γ : Ctx ν n} {t a b} → Γ ⊢ t ∈ (a →' b) → Value t →
∃ λ e → (t ≡ λ' a e) × ((a ∷ Γ) ⊢ e ∈ b)
→'-value-lemma () (Λ t)
→'-value-lemma (λ' a ⊢t∈a→b) (λ' .a t) = t , refl , ⊢t∈a→b
-- progress: welltyped terms are either values or can be reduced
progress : ∀ {ν τ} {t : Term ν 0} → [] ⊢ t ∈ τ → Value t ⊎ ∃ (_≻_ t)
progress (var ())
progress (Λ {t = t} ⊢t) = inj₁ (Λ t)
progress (λ' {t = t} a ⊢t) = inj₁ (λ' a t)
progress (_[_] ⊢t a) with progress ⊢t
-- we can rule out the possibility that t is both well typed and a value,
-- but not a lambda
-- leaving only cases that can make progress
progress (_[_] ⊢t a ) | inj₁ (λ' τ t') with ∀'-value-lemma ⊢t (λ' τ t')
progress (() [ a ]) | inj₁ (λ' τ t') | t≡Λe
progress (⊢t [ a ]) | inj₁ (Λ t) = inj₂ (, reduce-[] t a)
progress (⊢t [ a ]) | inj₂ (_ , y≻y') = inj₂ (, step-[] y≻y')
-- similar to above
progress (⊢f · ⊢t) with progress ⊢f | progress ⊢t
progress (⊢f · ⊢t) | inj₁ (λ' τ t) | inj₁ y-isval = inj₂ (, reduce-· τ t)
progress (⊢f · ⊢t) | inj₁ (Λ t) | inj₁ y-isval with →'-value-lemma ⊢f (Λ t)
progress (() · ⊢t) | inj₁ (Λ t) | inj₁ y-isval | f≡a→'b
progress (_·_ {f = f} wf-f ⊢t) | _ | inj₂ (_ , y≻y') = inj₂ (, step-·₂ y≻y')
progress (_·_ {t = t} ⊢f ⊢t) | inj₂ (_ , f≻f') | _ = inj₂ (, step-·₁ f≻f')
-- preservation: reduction preserves well-typedness
≻-preserves : ∀ {ν n} {Γ : Ctx ν n} {t t' τ} → Γ ⊢ t ∈ τ → t ≻ t' → Γ ⊢ t' ∈ τ
≻-preserves (var x) ()
≻-preserves (Λ ⊢t) (step-Λ-body t≻t') = Λ (≻-preserves ⊢t t≻t')
≻-preserves (λ' a ⊢t) (step-λ-body t≻t') = λ' a (≻-preserves ⊢t t≻t')
-- goal: (Λ t) [ a ] and t tm[/tp a ] have the same type
≻-preserves (⊢t [ a ]) (reduce-[] t .a) = WtTypeLemmas.tm[/tp]-preserves ⊢t a
≻-preserves (⊢t [ a ]) (step-[] t≻t') = (≻-preserves ⊢t t≻t') [ a ]
-- goal: (λ' a t) · u and t tm[/tm u ] have the same type
≻-preserves (λ' a ⊢t · ⊢u) (reduce-· .a t₁) = WtTermLemmas.tm[/tm]-preserves ⊢t ⊢u
≻-preserves (⊢t · ⊢u) (step-·₁ t≻t') = (≻-preserves ⊢t t≻t') · ⊢u
≻-preserves (⊢t · ⊢u) (step-·₂ u≻u') = ⊢t · (≻-preserves ⊢u u≻u')
| {
"alphanum_fraction": 0.5205057046,
"avg_line_length": 39.5487804878,
"ext": "agda",
"hexsha": "eb682c5d3c3ef78e64fab9845e716ac6f717624e",
"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/SystemF/SmallStep.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/SystemF/SmallStep.agda",
"max_line_length": 87,
"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/SystemF/SmallStep.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": 1537,
"size": 3243
} |
------------------------------------------------------------------------
-- Properties of non-empty lists
------------------------------------------------------------------------
module Data.List.NonEmpty.Properties where
open import Algebra
open import Category.Monad
open import Data.Function
open import Data.Product
open import Data.List as List using (List; []; _∷_; _++_)
open RawMonad List.monad using () renaming (_>>=_ to _⋆>>=_)
private module LM {A} = Monoid (List.monoid A)
open import Data.List.NonEmpty as List⁺
open RawMonad List⁺.monad
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
η : ∀ {A} (xs : List⁺ A) → head xs ∷ tail xs ≡ List⁺.toList xs
η [ x ] = refl
η (x ∷ xs) = refl
toList-fromList : ∀ {A} x (xs : List A) →
x ∷ xs ≡ List⁺.toList (List⁺.fromList x xs)
toList-fromList x [] = refl
toList-fromList x (y ∷ xs) = cong (_∷_ x) (toList-fromList y xs)
toList-⁺++ : ∀ {A} (xs : List⁺ A) ys →
List⁺.toList xs ++ ys ≡
List⁺.toList (xs ⁺++ ys)
toList-⁺++ [ x ] ys = toList-fromList x ys
toList-⁺++ (x ∷ xs) ys = cong (_∷_ x) (toList-⁺++ xs ys)
toList-⁺++⁺ : ∀ {A} (xs ys : List⁺ A) →
List⁺.toList xs ++ List⁺.toList ys ≡
List⁺.toList (xs ⁺++⁺ ys)
toList-⁺++⁺ [ x ] ys = refl
toList-⁺++⁺ (x ∷ xs) ys = cong (_∷_ x) (toList-⁺++⁺ xs ys)
toList->>= : ∀ {A B} (f : A → List⁺ B) (xs : List⁺ A) →
(List⁺.toList xs ⋆>>= List⁺.toList ∘ f) ≡
(List⁺.toList (xs >>= f))
toList->>= f [ x ] = proj₂ LM.identity _
toList->>= f (x ∷ xs) = begin
List⁺.toList (f x) ++ (List⁺.toList xs ⋆>>= List⁺.toList ∘ f) ≡⟨ cong (_++_ (List⁺.toList (f x))) (toList->>= f xs) ⟩
List⁺.toList (f x) ++ List⁺.toList (xs >>= f) ≡⟨ toList-⁺++⁺ (f x) (xs >>= f) ⟩
List⁺.toList (f x ⁺++⁺ (xs >>= f)) ∎
| {
"alphanum_fraction": 0.4951974386,
"avg_line_length": 39.0416666667,
"ext": "agda",
"hexsha": "34e71ff7cba8b9fd9c21a994893a0797bd296db7",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/List/NonEmpty/Properties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/List/NonEmpty/Properties.agda",
"max_line_length": 119,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/List/NonEmpty/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 667,
"size": 1874
} |
module Thesis.SIRelBigStep.DLang where
open import Thesis.SIRelBigStep.DSyntax public
open import Thesis.SIRelBigStep.DOpSem public
open import Thesis.SIRelBigStep.DLangDerive public
| {
"alphanum_fraction": 0.8695652174,
"avg_line_length": 30.6666666667,
"ext": "agda",
"hexsha": "d41baf5638d55995a7bbeeb1b880ef8280de6c91",
"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": "Thesis/SIRelBigStep/DLang.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": "Thesis/SIRelBigStep/DLang.agda",
"max_line_length": 50,
"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": "Thesis/SIRelBigStep/DLang.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": 50,
"size": 184
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Universes
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Universe where
open import Data.Product
open import Level
------------------------------------------------------------------------
-- Definition
record Universe u e : Set (suc (u ⊔ e)) where
field
U : Set u -- Codes.
El : U → Set e -- Decoding function.
| {
"alphanum_fraction": 0.3618677043,
"avg_line_length": 24.4761904762,
"ext": "agda",
"hexsha": "ff250fdf76dcddd3373a9424db17cdb58293bbba",
"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/Universe.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/Universe.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/Universe.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": 86,
"size": 514
} |
------------------------------------------------------------------------------
-- First-order logic theorems
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module contains some examples showing the use of the ATPs for
-- proving first-order logic theorems.
module FOL.TheoremsATP where
open import FOL.Base
------------------------------------------------------------------------------
-- We postulate some formulae and propositional functions.
postulate
A : Set
A¹ B¹ : D → Set
A² : D → D → Set
-- The introduction and elimination rules for the quantifiers are theorems.
{-
φ(x)
----------- ∀-intro
∀x.φ(x)
∀x.φ(x)
----------- ∀-elim
φ(t)
φ(t)
----------- ∃-intro
∃x.φ(x)
∃x.φ(x) φ(x) → ψ
---------------------- ∃-elim
ψ
-}
postulate
∀-intro : ((x : D) → A¹ x) → ∀ x → A¹ x
∀-intro' : ((x : D) → A¹ x) → ⋀ A¹
∀-elim : (t : D) → (∀ x → A¹ x) → A¹ t
∀-elim' : (t : D) → ⋀ A¹ → A¹ t
∃-intro : (t : D) → A¹ t → ∃ A¹
∃-elim : ∃ A¹ → ((x : D) → A¹ x → A) → A
{-# ATP prove ∀-intro #-}
{-# ATP prove ∀-intro' #-}
{-# ATP prove ∀-elim #-}
{-# ATP prove ∀-elim' #-}
{-# ATP prove ∃-intro #-}
{-# ATP prove ∃-elim #-}
-- Generalization of De Morgan's laws.
postulate
gDM₁ : ¬ (∀ x → A¹ x) ↔ (∃[ x ] ¬ (A¹ x))
gDM₂ : ¬ (∃ A¹) ↔ (∀ x → ¬ (A¹ x))
gDM₃ : (∀ x → A¹ x) ↔ ¬ (∃[ x ] ¬ (A¹ x))
gDM₄ : ∃ A¹ ↔ ¬ (∀ x → ¬ (A¹ x))
{-# ATP prove gDM₁ #-}
{-# ATP prove gDM₂ #-}
{-# ATP prove gDM₃ #-}
{-# ATP prove gDM₄ #-}
-- The order of quantifiers of the same sort is irrelevant.
postulate
∀-ord : (∀ x y → A² x y) ↔ (∀ y x → A² x y)
∃-ord : (∃[ x ] ∃[ y ] A² x y) ↔ (∃[ y ] ∃[ x ] A² x y)
{-# ATP prove ∀-ord #-}
{-# ATP prove ∃-ord #-}
-- Quantification over a variable that does not occur can be erased or
-- added.
postulate ∃-erase-add : (∃[ x ] A ∧ A¹ x) ↔ A ∧ (∃[ x ] A¹ x)
{-# ATP prove ∃-erase-add #-}
-- Distributes laws for the quantifiers.
postulate
∀-dist : (∀ x → A¹ x ∧ B¹ x) ↔ ((∀ x → A¹ x) ∧ (∀ x → B¹ x))
∃-dist : (∃[ x ] (A¹ x ∨ B¹ x)) ↔ (∃ A¹ ∨ ∃ B¹)
{-# ATP prove ∀-dist #-}
{-# ATP prove ∃-dist #-}
-- Interchange of quantifiers.
-- The related theorem ∀x∃y.Axy → ∃y∀x.Axy is not (classically) valid.
postulate ∃∀ : ∃[ x ] (∀ y → A² x y) → ∀ y → ∃[ x ] A² x y
{-# ATP prove ∃∀ #-}
-- ∃ in terms of ∀ and ¬.
postulate
∃→¬∀¬ : ∃[ x ] A¹ x → ¬ (∀ {x} → ¬ A¹ x)
∃¬→¬∀ : ∃[ x ] ¬ A¹ x → ¬ (∀ {x} → A¹ x)
{-# ATP prove ∃→¬∀¬ #-}
{-# ATP prove ∃¬→¬∀ #-}
-- ∀ in terms of ∃ and ¬.
postulate
∀→¬∃¬ : (∀ {x} → A¹ x) → ¬ (∃[ x ] ¬ A¹ x)
∀¬→¬∃ : (∀ {x} → ¬ A¹ x) → ¬ (∃[ x ] A¹ x)
{-# ATP prove ∀→¬∃¬ #-}
{-# ATP prove ∀¬→¬∃ #-}
-- Distribution of ∃ and ∨.
postulate ∃∨ : ∃[ x ](A¹ x ∨ B¹ x) → (∃[ x ] A¹ x) ∨ (∃[ x ] B¹ x)
{-# ATP prove ∃∨ #-}
| {
"alphanum_fraction": 0.4221256684,
"avg_line_length": 27.4495412844,
"ext": "agda",
"hexsha": "4654c5c0aabb153bb23ffe8f91ea69a59caf2f71",
"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/FOL/TheoremsATP.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/FOL/TheoremsATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOL/TheoremsATP.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": 1137,
"size": 2992
} |
open import Logic
open import Structure.Setoid
open import Structure.Operator.Ring
open import Structure.OrderedField
open import Type
module Structure.OrderedField.AbsoluteValue
{ℓ ℓₗ ℓₑ}
{F : Type{ℓ}}
⦃ equiv : Equiv{ℓₑ}(F) ⦄
(_+_ _⋅_ : F → F → F)
(_≤_ : F → F → Stmt{ℓₗ})
⦃ ring : Ring(_+_)(_⋅_) ⦄ -- TODO: The definition does not require a ring, only some kind of total order compatible with an operation with an identity and an inverse
-- ⦃ identity : Identity(_+_) ⦄
-- ⦃ inverseFunction : InverseFunction(_+_)(−_) ⦄
⦃ ordered : Ordered(_+_)(_⋅_)(_≤_) ⦄
where
open Ring(ring)
open Ordered(ordered)
import Lvl
open import Data.Boolean
open import Data.Boolean.Proofs
import Data.Either as Either
open import Functional
open import Logic.IntroInstances
open import Logic.Propositional
open import Structure.Function.Domain
open import Structure.Function.Ordering
open import Structure.Function
open import Structure.Operator
open import Structure.Operator.Proofs
open import Structure.Operator.Properties
open import Structure.Operator.Ring.Proofs
open import Structure.Relator.Properties
open import Syntax.Implication
open import Syntax.Transitivity
‖_‖ : F → F
‖ x ‖ = if Either.isRight(converseTotal(_≤_){𝟎}{x}) then (− x) else x
instance
abs-function : Function(‖_‖)
Function.congruence abs-function {x}{y} xy with converseTotal(_≤_){𝟎}{x} | converseTotal(_≤_){𝟎}{y}
... | Either.Left p | Either.Left q = xy
... | Either.Left p | Either.Right q = antisymmetry(_≤_)(_≡_) (sub₂(_≡_)(_≤_) xy 🝖 q) p 🝖 antisymmetry(_≤_)(_≡_) ([↔]-to-[→] [≤]-flip-negative q) ([↔]-to-[→] [≤]-flip-positive(p 🝖 sub₂(_≡_)(_≤_) xy))
... | Either.Right p | Either.Left q = antisymmetry(_≤_)(_≡_) ([↔]-to-[→] [≤]-flip-positive(q 🝖 sub₂(_≡_)(_≤_) (symmetry(_≡_) xy))) ([↔]-to-[→] [≤]-flip-negative p) 🝖 antisymmetry(_≤_)(_≡_) q (sub₂(_≡_)(_≤_) (symmetry(_≡_) xy) 🝖 p)
... | Either.Right p | Either.Right q = congruence₁(−_) xy
abs-positive : ∀{x} → (‖ x ‖ ≥ 𝟎)
abs-positive{x} = if-either-bool-intro {P = _≥ 𝟎} {x = x} {y = − x} id ([↔]-to-[→] [≤]-flip-negative) (converseTotal(_≤_){𝟎}{x})
abs-values : ∀{x} → (‖ x ‖ ≡ x) ∨ (‖ x ‖ ≡ − x)
abs-values{x} with converseTotal(_≤_){𝟎}{x}
... | [∨]-introₗ _ = [∨]-introₗ (reflexivity(_≡_))
... | [∨]-introᵣ _ = [∨]-introᵣ (reflexivity(_≡_))
abs-of-zero : (‖ 𝟎 ‖ ≡ 𝟎)
abs-of-zero with abs-values{𝟎}
... | Either.Left p = p
... | Either.Right p = p 🝖 [−]-of-𝟎
abs-when-zero : ∀{x} → (‖ x ‖ ≡ 𝟎) ↔ (x ≡ 𝟎)
abs-when-zero{x} = [↔]-intro (p ↦ congruence₁(‖_‖) p 🝖 abs-of-zero) (p ↦ symmetry(_≡_) ([∨]-elim id (q ↦ p 🝖 symmetry(_≡_) ([↔]-to-[→] [−]-is-𝟎 (symmetry(_≡_) q 🝖 p))) abs-values) 🝖 p)
abs-of-negation : ∀{x} → (‖ − x ‖ ≡ ‖ x ‖)
abs-of-negation{x} with converseTotal(_≤_){𝟎}{x} | converseTotal(_≤_){𝟎}{− x}
... | [∨]-introₗ _ | [∨]-introᵣ _ = involution(−_)
... | [∨]-introᵣ _ | [∨]-introₗ _ = reflexivity(_≡_)
... | [∨]-introₗ zx | [∨]-introₗ znx = antisymmetry(_≤_)(_≡_) (nxz 🝖 zx) (xz 🝖 znx) where
nxz : (− x) ≤ 𝟎
nxz = [↔]-to-[←] [≤]-flip-negative (zx 🝖 (sub₂(_≡_)(_≤_) $ symmetry(_≡_) $ involution(−_)))
xz : x ≤ 𝟎
xz = [↔]-to-[←] [≤]-flip-negative znx
... | [∨]-introᵣ xz | [∨]-introᵣ nxz = antisymmetry(_≤_)(_≡_) (involution(−_) 🝖-subₗ (xz 🝖 znx)) (nxz 🝖 zx 🝖-subᵣ symmetry(_≡_) (involution(−_))) where
znx : 𝟎 ≤ (− x)
znx = [↔]-to-[→] [≤]-flip-negative xz
zx : 𝟎 ≤ x
zx = [↔]-to-[→] [≤]-flip-negative nxz 🝖 (sub₂(_≡_)(_≤_) $ involution(−_))
instance
abs-idempotent : Idempotent(‖_‖)
Idempotent.proof abs-idempotent {x} with abs-values{x}
... | Either.Left p = congruence₁(‖_‖) p
... | Either.Right p = congruence₁(‖_‖) p 🝖 abs-of-negation
abs-order : ∀{x} → ((− ‖ x ‖) ≤ ‖ x ‖)
abs-order{x} = [↔]-to-[→] [≤]-flip-positive(abs-positive{x}) 🝖 abs-positive{x}
abs-order-pos : ∀{x} → (x ≤ ‖ x ‖)
abs-order-pos {x} with converseTotal(_≤_){𝟎}{x}
... | Either.Left p = reflexivity(_≤_)
... | Either.Right p = p 🝖 [↔]-to-[→] [≤]-flip-negative p
abs-order-neg : ∀{x} → ((− x) ≤ ‖ x ‖)
abs-order-neg {x} with converseTotal(_≤_){𝟎}{x}
... | Either.Left p = [↔]-to-[→] [≤]-flip-positive p 🝖 p
... | Either.Right p = reflexivity(_≤_)
abs-of-positive : ∀{x} → (𝟎 ≤ x) → (‖ x ‖ ≡ x)
abs-of-positive {x} ox = antisymmetry(_≤_)(_≡_) p abs-order-pos where
p : ‖ x ‖ ≤ x
p with converseTotal(_≤_){𝟎}{x}
... | Either.Left _ = reflexivity(_≤_)
... | Either.Right _ = [↔]-to-[→] [≤]-flip-positive ox 🝖 ox
-- Alternative 1:
-- with abs-values{x}
-- ... | Either.Left p = p
-- ... | Either.Right p = [↔]-to-[←] abs-when-zero xzero 🝖 symmetry(_≡_) xzero where
-- xzero : (x ≡ 𝟎)
-- xzero = antisymmetry(_≤_)(_≡_) ([↔]-to-[←] [≤]-flip-negative (abs-positive{x} 🝖 sub₂(_≡_)(_≤_) p)) ox
-- Alternative 2: antisymmetry(_≤_)(_≡_) (sub₂(_≡_)(_≤_) p 🝖 [≤]-flip-positive ox 🝖 ox) (sub₂(_≡_)(_≤_) (symmetry(_≡_) (congruence₁(−_) p 🝖 [−−]-elim)) 🝖 abs-order{x})
abs-of-negative : ∀{x} → (x ≤ 𝟎) → (‖ x ‖ ≡ − x)
abs-of-negative {x} xo = antisymmetry(_≤_)(_≡_) p abs-order-neg where
p : ‖ x ‖ ≤ (− x)
p with converseTotal(_≤_){𝟎}{x}
... | Either.Left _ = xo 🝖 [↔]-to-[→] [≤]-flip-negative xo
... | Either.Right _ = reflexivity(_≤_)
-- Alternative 1:
-- with abs-values{x}
-- ... | Either.Right p = p
-- ... | Either.Left p = symmetry(_≡_) abs-of-negation 🝖 [↔]-to-[←] abs-when-zero xzero 🝖 symmetry(_≡_) xzero where
-- xzero : (− x ≡ 𝟎)
-- xzero = antisymmetry(_≤_)(_≡_) ([↔]-to-[←] [≤]-flip-negative (abs-positive{x} 🝖 sub₂(_≡_)(_≤_) p 🝖 sub₂(_≡_)(_≤_) (symmetry(_≡_) [−−]-elim))) ([↔]-to-[→] [≤]-flip-negative xo)
abs-triangle-inequality : ∀{x y} → (‖ x + y ‖ ≤ (‖ x ‖ + ‖ y ‖))
abs-triangle-inequality {x}{y} with converseTotal(_≤_){𝟎}{x + y}
... | Either.Left p =
(x + y) 🝖[ _≤_ ]-[ [≤][+]-preserve abs-order-pos abs-order-pos ]
(‖ x ‖ + ‖ y ‖) 🝖-end
... | Either.Right p =
−(x + y) 🝖[ _≡_ ]-[ [+]-negation-distribution ]-sub
(− x) + (− y) 🝖[ _≤_ ]-[ [≤][+]-preserve abs-order-neg abs-order-neg ]
(‖ x ‖ + ‖ y ‖) 🝖-end
-- TODO: True in rings? Only division rings? Maybe ≤ instead of ≡ is better because of zero divisors
-- abs-scaling : ∀{a x} → (‖ a ⋅ x ‖ ≡ (‖ a ‖ ⋅ ‖ x ‖))
-- abs-scaling{a}{x} with converseTotal(_≤_){𝟎}{a ⋅ x} | converseTotal(_≤_){𝟎}{a} | converseTotal(_≤_){𝟎}{x}
{-... | Either.Left p =
(a ⋅ x) 🝖[ _≡_ ]-[ {!!} ]
(‖ a ‖ ⋅ ‖ x ‖) 🝖-end
... | Either.Right p = {!!}
-}
-- Distance
_𝄩_ : F → F → F
x 𝄩 y = ‖ x − y ‖
open import Structure.Function.Proofs
open import Structure.Operator.Proofs.Util
instance
[𝄩]-binaryOperator : BinaryOperator(_𝄩_)
[𝄩]-binaryOperator = [∘₂]-function {f = ‖_‖} ⦃ oper = [−]-binaryOperator ⦄
instance
[𝄩]-commutativity : Commutativity(_𝄩_)
Commutativity.proof [𝄩]-commutativity {x}{y} =
‖ x − y ‖ 🝖-[ abs-of-negation ]-sym
‖ −(x − y) ‖ 🝖-[ congruence₁(‖_‖) [−]-negation-distribution ]
‖ y − x ‖ 🝖-end
[𝄩]-triangle-inequality : ∀{x y z} → ((x 𝄩 z) ≤ ((x 𝄩 y) + (y 𝄩 z)))
[𝄩]-triangle-inequality {x}{y}{z} =
x 𝄩 z 🝖[ _≤_ ]-[]
‖ x − z ‖ 🝖[ _≡_ ]-[ congruence₁(‖_‖) (congruence₂ₗ(_−_) ⦃ [−]-binaryOperator ⦄ (z) (symmetry(_≡_) (identityᵣ(_+_)(𝟎)))) ]-sub
‖ (x + 𝟎) − z ‖ 🝖[ _≡_ ]-[ congruence₁(‖_‖) (congruence₂ₗ(_−_) ⦃ [−]-binaryOperator ⦄ (z) (congruence₂ᵣ(_+_)(x) (symmetry(_≡_) (inverseFunctionₗ(_+_)(−_))))) ]-sub
‖ (x + ((− y) + y)) − z ‖ 🝖[ _≡_ ]-[ congruence₁(‖_‖) ((One.associate4-213-222 {_▫_ = _+_} {a = x}{− y}{y}{− z})) ]-sub
‖ (x + (− y)) + (y − z) ‖ 🝖[ _≤_ ]-[]
‖ (x − y) + (y − z) ‖ 🝖[ _≤_ ]-[ abs-triangle-inequality ]
(‖ x − y ‖) + (‖ y − z ‖) 🝖[ _≤_ ]-[]
(x 𝄩 y) + (y 𝄩 z) 🝖-end
[𝄩]-self : ∀{x y} → (x 𝄩 y ≡ 𝟎) ↔ (x ≡ y)
[𝄩]-self {x}{y} = [↔]-intro l r where
l =
(x ≡ y) ⇒-[ symmetry(_≡_) ∘ congruence₂ᵣ(_𝄩_)(x) ]
(x 𝄩 y ≡ x 𝄩 x) ⇒-[]
(_ ≡ ‖ x − x ‖) ⇒-[ _🝖 congruence₁(‖_‖) (inverseFunctionᵣ(_+_)(−_)) ]
(_ ≡ ‖ 𝟎 ‖) ⇒-[ _🝖 abs-of-zero ]
(_ ≡ 𝟎) ⇒-end
r =
(x 𝄩 y ≡ 𝟎) ⇒-[ [↔]-to-[→] (abs-when-zero{x − y}) ]
(x − y ≡ 𝟎) ⇒-[ [↔]-to-[→] [−]-difference-is-𝟎 ]
(x ≡ y) ⇒-end
| {
"alphanum_fraction": 0.5411330049,
"avg_line_length": 42.7368421053,
"ext": "agda",
"hexsha": "28b53fbd7c3d06957aa2c695d62fdeccc01d1975",
"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/OrderedField/AbsoluteValue.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/OrderedField/AbsoluteValue.agda",
"max_line_length": 234,
"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/OrderedField/AbsoluteValue.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": 3743,
"size": 8120
} |
open import Data.Product using (∃; ∃-syntax; _×_; _,_)
open import DeBruijn
open import Parallel
open import Beta
par-diamond : ∀ {n} {M N N′ : Term n}
→ M ⇉ N → M ⇉ N′
-----------------------
→ ∃[ L ] (N ⇉ L × N′ ⇉ L)
par-diamond (⇉-c {x = x}) ⇉-c = # x , ⇉-c , ⇉-c
par-diamond (⇉-ƛ p1) (⇉-ƛ p2)
with par-diamond p1 p2
... | L′ , p3 , p4 =
ƛ L′ , ⇉-ƛ p3 , ⇉-ƛ p4
par-diamond (⇉-ξ p1 p3) (⇉-ξ p2 p4)
with par-diamond p1 p2
... | L₃ , p5 , p6
with par-diamond p3 p4
... | M₃ , p7 , p8 =
L₃ · M₃ , ⇉-ξ p5 p7 , ⇉-ξ p6 p8
par-diamond (⇉-ξ (⇉-ƛ p1) p3) (⇉-β p2 p4)
with par-diamond p1 p2
... | N₃ , p5 , p6
with par-diamond p3 p4
... | M₃ , p7 , p8 =
N₃ [ M₃ ] , ⇉-β p5 p7 , sub-par p6 p8
par-diamond (⇉-β p1 p3) (⇉-ξ (⇉-ƛ p2) p4)
with par-diamond p1 p2
... | N₃ , p5 , p6
with par-diamond p3 p4
... | M₃ , p7 , p8 =
N₃ [ M₃ ] , sub-par p5 p7 , ⇉-β p6 p8
par-diamond (⇉-β p1 p3) (⇉-β p2 p4)
with par-diamond p1 p2
... | N₃ , p5 , p6
with par-diamond p3 p4
... | M₃ , p7 , p8 =
N₃ [ M₃ ] , sub-par p5 p7 , sub-par p6 p8
strip : ∀ {n} {M A B : Term n}
→ M ⇉ A → M ⇉* B
------------------------
→ ∃[ N ] (A ⇉* N × B ⇉ N)
strip {A = A} M⇉A (M ∎) = A , (A ∎) , M⇉A
strip {A = A} M⇉A (M ⇉⟨ M⇉M′ ⟩ M′⇉*B)
with par-diamond M⇉A M⇉M′
... | N , A⇉N , M′⇉N
with strip M′⇉N M′⇉*B
... | N′ , N⇉*N′ , B⇉N′ =
N′ , (A ⇉⟨ A⇉N ⟩ N⇉*N′) , B⇉N′
par-confluence : ∀ {n} {M A B : Term n}
→ M ⇉* A → M ⇉* B
------------------------
→ ∃[ N ] (A ⇉* N × B ⇉* N)
par-confluence {B = B} (M ∎) M⇉*B = B , M⇉*B , (B ∎)
par-confluence {B = B} (M ⇉⟨ M⇉A ⟩ A⇉*A′) M⇉*B
with strip M⇉A M⇉*B
... | N , A⇉*N , B⇉N
with par-confluence A⇉*A′ A⇉*N
... | N′ , A′⇉*N′ , N⇉*N′ =
N′ , A′⇉*N′ , (B ⇉⟨ B⇉N ⟩ N⇉*N′)
confluence : ∀ {n} {M A B : Term n}
→ M —↠ A → M —↠ B
------------------------
→ ∃[ N ] (A —↠ N × B —↠ N)
confluence M—↠A M—↠B
with par-confluence (betas-pars M—↠A) (betas-pars M—↠B)
... | N , A⇉*N , B⇉*N =
N , pars-betas A⇉*N , pars-betas B⇉*N
| {
"alphanum_fraction": 0.4041159963,
"avg_line_length": 27.7662337662,
"ext": "agda",
"hexsha": "0bfa2ec4e3695485ad828b1e8527b60af9027404",
"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": "2fa17f7738cc7da967375be928137adc4be38696",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "iwilare/church-rosser",
"max_forks_repo_path": "ConfluenceParallel.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696",
"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": "iwilare/church-rosser",
"max_issues_repo_path": "ConfluenceParallel.agda",
"max_line_length": 59,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "iwilare/church-rosser",
"max_stars_repo_path": "ConfluenceParallel.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-22T01:43:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-06-02T07:27:54.000Z",
"num_tokens": 1183,
"size": 2138
} |
------------------------------------------------------------------------------
-- Mendelson's substitution
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOL.MendelsonSubstI where
-- First-order logic with equality.
open import Common.FOL.FOL-Eq public
------------------------------------------------------------------------------
-- Mendelson's [2015] substitution (p. 93).
-- (A7) x = y ⇒ (A(x,x) ⇒ B(x,y)) (substitutivity of equality)
-- Using pattern matching.
mendelsonSubst : (A : D → D → Set) → ∀ {x y} → x ≡ y → A x x → A x y
mendelsonSubst A refl Axx = Axx
-- From `subst` to Mendelson substitution.
subst→mendelsonSubst : (A : D → D → Set) → ∀ {x y} → x ≡ y → A x x → A x y
subst→mendelsonSubst A {x} = subst (λ z → A x z)
-- From Mendelson substitution to `subst`.
mendelsonSubst→subst : (A : D → Set) → ∀ {x y} → x ≡ y → A x → A y
mendelsonSubst→subst A = mendelsonSubst (λ _ → A)
------------------------------------------------------------------------------
-- References
-- Mendelson, Elliott (2015). Introduction to Mathematical Logic. CRC
-- Press, 6th edition.
| {
"alphanum_fraction": 0.4640672783,
"avg_line_length": 34.4210526316,
"ext": "agda",
"hexsha": "9c192fd154f9a075b76810416a8de6d9e9600b5c",
"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/FOL/MendelsonSubstI.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/FOL/MendelsonSubstI.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/FOL/MendelsonSubstI.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": 329,
"size": 1308
} |
------------------------------------------------------------------------
-- Code related to the delay monad
--
-- Nils Anders Danielsson
------------------------------------------------------------------------
{-# OPTIONS --cubical --sized-types #-}
module README where
-- The concept referred to as the delay monad here is the monad
-- presented by Capretta in "General Recursion via Coinductive Types".
------------------------------------------------------------------------
-- The delay monad
-- The delay monad, defined coinductively.
import Delay-monad
-- A type used to index a combined definition of strong and weak
-- bisimilarity and expansion.
import Delay-monad.Bisimilarity.Kind
-- A combined definition of strong and weak bisimilarity and
-- expansion, along with various properties.
import Delay-monad.Bisimilarity
-- Strong bisimilarity for partially defined values, along with a
-- proof showing that this relation is pointwise isomorphic to path
-- equality.
import Delay-monad.Bisimilarity.For-all-sizes
-- A variant of weak bisimilarity that can be used to relate the
-- number of steps in two computations.
import Delay-monad.Quantitative-weak-bisimilarity
-- Termination.
import Delay-monad.Termination
-- Alternative definitions of weak bisimilarity.
import Delay-monad.Bisimilarity.Alternative
-- An observation about weak bisimilarity.
import Delay-monad.Bisimilarity.Observation
-- Some negative results related to weak bisimilarity and expansion.
import Delay-monad.Bisimilarity.Negative
-- An example showing that transitivity-like proofs that are not
-- size-preserving can sometimes be used in a compositional way.
import Delay-monad.Bisimilarity.Transitivity-constructor
-- A partial order.
import Delay-monad.Partial-order
-- Least upper bounds.
import Delay-monad.Least-upper-bound
-- The delay monad is a monad up to strong bisimilarity.
import Delay-monad.Monad
-- The "always true" predicate, □.
import Delay-monad.Always
-- A combinator for running two (independent) computations in
-- sequence.
import Delay-monad.Sequential
-- A combinator for running two computations in parallel.
import Delay-monad.Parallel
------------------------------------------------------------------------
-- A variant of the delay monad with a sized type parameter
-- The delay monad, defined coinductively, with a sized type
-- parameter.
import Delay-monad.Sized
-- A combined definition of strong and weak bisimilarity and
-- expansion, along with various properties.
import Delay-monad.Sized.Bisimilarity
-- Strong bisimilarity for partially defined values, along with a
-- proof showing that this relation is pointwise isomorphic to path
-- equality.
import Delay-monad.Sized.Bisimilarity.For-all-sizes
-- Termination.
import Delay-monad.Sized.Termination
-- Alternative definitions of weak bisimilarity.
import Delay-monad.Sized.Bisimilarity.Alternative
-- Some negative results related to weak bisimilarity and expansion.
import Delay-monad.Sized.Bisimilarity.Negative
-- A partial order.
import Delay-monad.Sized.Partial-order
-- Least upper bounds.
import Delay-monad.Sized.Least-upper-bound
-- A monad-like structure.
import Delay-monad.Sized.Monad
-- The "always true" predicate, □.
import Delay-monad.Sized.Always
| {
"alphanum_fraction": 0.7127272727,
"avg_line_length": 24.6268656716,
"ext": "agda",
"hexsha": "cc399a67a8af104a11aab06d01639b0824491f5a",
"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": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/delay-monad",
"max_forks_repo_path": "README.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"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/delay-monad",
"max_issues_repo_path": "README.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/delay-monad",
"max_stars_repo_path": "README.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 713,
"size": 3300
} |
{-
This file contains:
- Definition of type quotients (i.e. non-truncated quotients)
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.TypeQuotients.Base where
open import Cubical.Core.Primitives
-- Type quotients as a higher inductive type:
data _/ₜ_ {ℓ ℓ'} (A : Type ℓ) (R : A → A → Type ℓ') : Type (ℓ-max ℓ ℓ') where
[_] : (a : A) → A /ₜ R
eq/ : (a b : A) → (r : R a b) → [ a ] ≡ [ b ]
| {
"alphanum_fraction": 0.6028368794,
"avg_line_length": 23.5,
"ext": "agda",
"hexsha": "9d364f13e04dfae750907c8a3ecc8bab4b220fb9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/HITs/TypeQuotients/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/HITs/TypeQuotients/Base.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/HITs/TypeQuotients/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 156,
"size": 423
} |
------------------------------------------------------------------------
-- Code related to the abstract "Type Theory with Weak J" by Thorsten
-- Altenkirch, Paolo Capriotti, Thierry Coquand, Nils Anders
-- Danielsson, Simon Huber and Nicolai Kraus
--
-- The code is written by Nils Anders Danielsson
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module README.Weak-J where
-- For the equality between the two equalities, see proof₁≡proof₂.
--
-- For the main result about contractibility of the type of pairs
-- containing J functions and the corresponding β-rule, see
-- Equality-with-J-contractible.
--
-- Note that there are minor differences between the code and the
-- presentation in the abstract.
import Equality.Instances-related
| {
"alphanum_fraction": 0.6186335404,
"avg_line_length": 35,
"ext": "agda",
"hexsha": "feaf9b5b01bce858a0e7475879325c0244123adc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "README/Weak-J.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "README/Weak-J.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "README/Weak-J.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 162,
"size": 805
} |
open import Data.Nat
open import Data.Fin using (Fin; #_; suc; zero)
open import Data.List as List hiding (null)
open import Data.List.Membership.Propositional
open import Data.List.Relation.Unary.Any
open import Data.List.Relation.Unary.All
open import Data.Integer hiding (suc)
open import Data.Product hiding (map)
open import Data.Unit
open import Data.Star hiding (return ; _>>=_ ; map)
open import Relation.Binary.PropositionalEquality hiding ([_])
open ≡-Reasoning
open import Data.Empty
-- This file contains the syntax for the definitional interpreter for
-- MJ using scopes and frames, described in Section 5 of the paper.
-- The definitions are parameterized by a scope graph of size `k`, as
-- usual:
module MJSF.Syntax (k : ℕ) where
private
Scope : Set
Scope = Fin k
-- Return types, method parameters, and field types in MJ are given by
-- `VTy`:
data VTy : Set where
void : VTy
int : VTy
ref : Scope → VTy
-- The scope graph library is parameterized by a single kind of type,
-- to be used for all declarations. But there are three different
-- kinds of names (declarations) in MJ: value declarations (e.g., for
-- fields and method parameters); method declarations; and class
-- declarations.
--
-- We use the following type to "tag" and distinguish the various
-- kinds of declarations.
data Ty : Set where
vᵗ : VTy → Ty
mᵗ : List VTy → VTy → Ty
cᵗ : Scope → Scope → Ty
-- We specialize the scopes-and-frames library to the size of our
-- scope graph, and the tagged type for declarations above:
open import ScopesFrames.ScopesFrames k Ty hiding (Scope)
-------------
-- HAS TAG --
-------------
-- As summarized above, declarations may be either value-typed,
-- method-typed, or class-typed. We introduce some parameterized
-- predicates which only hold for a particular tag. This is useful
-- for saying that some list of types `ts : List Ty` only contains
-- value types, and that a particular property holds for each of those
-- value types. For example, the type `All (#v (λ _ → ⊤)) ts`
-- guarantees that `ts` contains only value types, and does not
-- constrain the value types further (due to the use of `⊤`).
data #v : (VTy → Set) → Ty → Set where
#v' : ∀ {t p} → p t → #v p (vᵗ t)
data #m : (List VTy → VTy → Set) → Ty → Set where
#m' : ∀ {ts rt p} → p ts rt → #m p (mᵗ ts rt)
data #c (sʳ : Scope) (p : Scope → Set) : Ty → Set where
#c' : ∀ {s} → p s → #c sʳ p (cᵗ sʳ s)
module SyntaxG (g : Graph) where
open UsesGraph g
-------------------------------
-- SUBTYPING AND INHERITANCE --
-------------------------------
-- As summarized in the paper, we define sub-typing in terms of
-- inheritance edges between class scopes in the scope graph:
_<:_ : Scope → Scope → Set
_<:_ = _⟶_
-- Scope graphs may be cyclic, and there is (in theory) nothing that
-- prevents classes from mutually extending one another, thereby
-- creating cyclic inheritance chains. The following `Inherits`
-- type witnesses that a given class scope has a finite set of
-- inheritance steps. This property is useful for defining object
-- initialization in a way that lets Agda prove that object
-- initialization takes finite time (i.e., no need for fuel).
data Inherits : Scope → Scope → Set where
obj : ∀ s {ds sʳ} ⦃ shape : g s ≡ (ds , [ sʳ ]) ⦄ → Inherits s s
super : ∀ {s ds sʳ sᵖ s'} ⦃ shape : g s ≡ (ds , sʳ ∷ sᵖ ∷ []) ⦄ → Inherits sᵖ s' → Inherits s s'
------------
-- SYNTAX --
------------
-- The expressions of MJ where the `s` in `Expr s t` is the lexical
-- context scope:
data Expr (s : Scope) : VTy → Set where
call : ∀ {s' ts t} → Expr s (ref s') → -- receiver
(s' ↦ (mᵗ ts t)) → -- path to method declaration
All (Expr s) ts → -- argument list
Expr s t
get : ∀ {s' t} → Expr s (ref s') → (s' ↦ vᵗ t) → Expr s t
var : ∀ {t} → (s ↦ vᵗ t) → Expr s t
new : ∀ {sʳ s'} → s ↦ cᵗ sʳ s' → Expr s (ref s') -- path to class declaration
null : ∀ {s'} → Expr s (ref s')
num : ℤ → Expr s int
iop : (ℤ → ℤ → ℤ) → (l r : Expr s int) → Expr s int
upcast : ∀ {t' t} → t' <: t → Expr s (ref t') → Expr s (ref t)
this : ∀ {s' self} → s ⟶ s' → self ∈ edgesOf s' → -- the `self` of objects is given by the lexical parent edge of a method
Expr s (ref self)
-- The statements of MJ where the `s` in `Stmt s t s'` is the
-- lexical context scope before the statement `t` is the return type
-- of the statement, and `s'` is the leixcal context scope after the
-- statement.
mutual
data Stmt (s : Scope)(r : VTy) : Scope → Set where
run : ∀ {t'} → Expr s t' → Stmt s r s
ifz : ∀ {s' s'' : Scope} → Expr s int → Stmt s r s → Stmt s r s → Stmt s r s -- branches are blocks
set : ∀ {s' t'} → Expr s (ref s') → (s' ↦ vᵗ t') → Expr s t' → Stmt s r s
loc : ∀ (s' : Scope)(t' : VTy)⦃ shape : g s' ≡ ([ vᵗ t' ] , [ s ]) ⦄ → Stmt s r s' -- local variable scope `s'` is connected to lexical context scope `s`
asgn : ∀ {t'} → (s ↦ vᵗ t') → Expr s t' → Stmt s r s
ret : Expr s r → Stmt s r s
block : ∀ {s'} → Stmts s r s' → Stmt s r s
-- A block of statements is given by a sequence of statements
-- whose scopes are lexically nested (if at all):
Stmts : Scope → VTy → Scope → Set
Stmts s r s' = Star (λ s s' → Stmt s r s') s s'
-- Method bodies have a mandatory return expression, except for
-- `void` typed method bodies:
data Body (s : Scope) : VTy → Set where
body : ∀ {s' t} → Stmts s t s' → Expr s' t → Body s t
body-void : ∀ {s'} → Stmts s void s' → Body s void
-- A method defines the scope shape mandating that the method type
-- parameters are declarations of the method body scope, and that
-- the method body scope is connected to the scope of the class
-- where they are defined. The `s` in `Meth s ts t` is the scope of
-- the surrounding class.
data Meth (s : Scope) : List VTy → VTy → Set where
meth : ∀ {ts rt}(s' : Scope)
⦃ shape : g s' ≡ (List.map vᵗ ts , [ s ]) ⦄ →
Body s' rt →
Meth s ts rt
-- A class definition has an optional path to a super class; the
-- only difference between a `class0` and a `class1` is that a
-- `class1` has a path from the root scope `sʳ` to another class
-- declaration, i.e., the super class.
--
-- The `sʳ` in `Class sʳ s` is the root scope (representing the
-- class table), and the `s` is the scope of the defined class.
--
-- We distinguish three kinds of class members in MJ:
--
-- * Fields, typed by `fs`.
--
-- * Methods, typed by `ms`, where for each method type signature
-- `mᵗ ts t` in `ms` there is a well-typed method `Meth s ts t`.
--
-- * Overriding methods, typed by `oms`, where for each method type
-- signature `mᵗ ts t` in `oms` there is a path from the current
-- class scope to a method declaration in a parent class scope,
-- and a well-typed method `Meth s ts t` which overrides the
-- method corresponding to that declaration.
data Class (sʳ s : Scope) : Set where
class1 : ∀ {ms fs oms sᵖ} →
sʳ ↦ (cᵗ sʳ sᵖ) →
⦃ shape : g s ≡ (ms ++ fs , sʳ ∷ sᵖ ∷ []) ⦄ →
All (#m (Meth s)) ms →
All (#v (λ _ → ⊤)) fs →
All (#m (λ ts rt → (s ↦ (mᵗ ts rt)) × Meth s ts rt )) oms → -- overrides
Class sʳ s
class0 : ∀ {ms fs oms} →
⦃ shape : g s ≡ (ms ++ fs , [ sʳ ]) ⦄ →
All (#m (Meth s)) ms → -- only methods
All (#v (λ _ → ⊤)) fs → -- only values
All (#m (λ ts rt → (s ↦ (mᵗ ts rt)) × Meth s ts rt )) oms → -- overrides
Class sʳ s
-- A program consists of a sequence of well-typed class definitions
-- and a main function to be evaluated in the context of the root
-- scope. The root scope has only class-typed declarations, and has
-- no parent edges:
data Program (sʳ : Scope)(a : VTy) : Set where
program :
∀ cs ⦃ shape : g sʳ ≡ (cs , []) ⦄ →
-- implementation of all the classes
All (#c sʳ (λ s → Class sʳ s × ∃ λ s' → Inherits s s')) cs →
-- main function
Body sʳ a →
Program sʳ a
| {
"alphanum_fraction": 0.5875956023,
"avg_line_length": 38.5622119816,
"ext": "agda",
"hexsha": "bf2e092ff3b685ff337a1d183acfcc540971c64e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJSF/Syntax.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJSF/Syntax.agda",
"max_line_length": 161,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJSF/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 2650,
"size": 8368
} |
module Misc.PosBinary where -- Positive Binary Numbers
open import Data.Nat
open import Data.List
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym)
open import Induction.WellFounded
open import Induction.Nat using (<-well-founded)
data Bin+ : Set where
[] : Bin+
1∷_ : Bin+ → Bin+
2∷_ : Bin+ → Bin+
decimal : Bin+ → ℕ
decimal [] = 0
decimal (1∷ xs) = 1 + 2 * decimal xs
decimal (2∷ xs) = 2 + 2 * decimal xs
-- A even/odd view. Surprised that we don't have it in StdLib
data Div2 : ℕ → Set where
even : ∀ n → Div2 (2 * n)
odd : ∀ n → Div2 (1 + 2 * n)
open import Data.Nat.Properties.Simple using (+-suc)
-- +-suc : ∀ m n → m + suc n ≡ suc (m + n)
open import Data.Nat.Properties using (m≤′m+n)
-- m≤′m+n : ∀ m n → m ≤′ m + n
_div2 : ∀ n → Div2 n
zero div2 = even 0
suc n div2 with n div2
suc .(n + (n + 0)) div2 | even n = odd n
suc .(suc (n + (n + 0))) div2 | odd n
rewrite sym (+-suc n (n + zero)) = even (1 + n)
bin+' : (n : ℕ) → Acc _<′_ n → Bin+
bin+' n _ with n div2
bin+' .0 _ | even zero = []
bin+' .(suc (m + suc (m + 0))) (acc rs) | even (suc m) =
2∷ bin+' m (rs m (m≤′m+n (suc m) _))
bin+' .(suc (m + (m + 0))) (acc rs) | odd m =
1∷ bin+' m (rs m (m≤′m+n (suc m) _))
bin+ : ℕ → Bin+
bin+ n = bin+' n (<-well-founded n)
{- For reference.
bin' : (n : ℕ) → Acc _<′_ n → List ℕ
bin' n _ with n div2
bin' .0 (acc rs) | even 0 = []
bin' .(suc m + (suc m + 0)) (acc rs) | even (suc m) =
0 ∷ bin' m (rs m (m≤′m+n (suc m) _))
bin' .(suc (m + (m + 0))) (acc rs) | odd m =
1 ∷ bin' m (rs m (m≤′m+n (suc m) _))
bin : ℕ → List ℕ
bin n = bin' n (<-well-founded n)
-}
lInv' : ∀ n → (ac : Acc _<′_ n) → decimal (bin+' n ac) ≡ n
lInv' n ac with n div2
lInv' .0 ac | even zero = refl
lInv' .(suc (m + suc (m + 0))) (acc rs) | even (suc m)
rewrite lInv' m (rs m (m≤′m+n (suc m) (suc (m + zero))))
| +-suc m (m + 0) = refl
lInv' .(suc (m + (m + 0))) (acc rs) | odd m
rewrite lInv' m (rs m (m≤′m+n (suc m) (m + zero))) = refl
lInv : ∀ n → decimal (bin+ n) ≡ n
lInv n = lInv' n (<-well-founded n)
| {
"alphanum_fraction": 0.5226628895,
"avg_line_length": 28.24,
"ext": "agda",
"hexsha": "ce3ece786399470079de66c00a77ccfc61e0ba85",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "legacy/Misc/PosBinary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "legacy/Misc/PosBinary.agda",
"max_line_length": 61,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "legacy/Misc/PosBinary.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 901,
"size": 2118
} |
module Tactic.Nat.Simpl where
open import Prelude hiding (abs)
open import Builtin.Reflection
open import Tactic.Reflection.Quote
open import Tactic.Reflection
open import Tactic.Nat.Reflect
open import Tactic.Nat.NF
open import Tactic.Nat.Exp
open import Tactic.Nat.Auto
open import Tactic.Nat.Auto.Lemmas
open import Tactic.Nat.Simpl.Lemmas
module _ {Atom : Set} {{_ : Eq Atom}} {{_ : Ord Atom}} where
ExpEq : Exp Atom × Exp Atom → Env Atom → Set
ExpEq (e₁ , e₂) ρ = ⟦ e₁ ⟧e ρ ≡ ⟦ e₂ ⟧e ρ
CancelEq : Exp Atom × Exp Atom → Env Atom → Set
CancelEq (e₁ , e₂) ρ = NFEqS (cancel (norm e₁) (norm e₂)) ρ
⟦_⟧h : List (Exp Atom × Exp Atom) → Env Atom → Set
⟦ [] ⟧h ρ = ⊥
⟦ h ∷ [] ⟧h ρ = ExpEq h ρ
⟦ h ∷ g ⟧h ρ = ExpEq h ρ → ⟦ g ⟧h ρ
⟦_⟧hs : List (Exp Atom × Exp Atom) → Env Atom → Set
⟦ [] ⟧hs ρ = ⊥
⟦ h ∷ [] ⟧hs ρ = CancelEq h ρ
⟦ h ∷ g ⟧hs ρ = CancelEq h ρ → ⟦ g ⟧hs ρ
simplifyEq : ∀ eq (ρ : Env Atom) → CancelEq eq ρ → ExpEq eq ρ
simplifyEq (e₁ , e₂) ρ H = liftNFEq e₁ e₂ ρ (cancel-sound (norm e₁) (norm e₂) ρ H)
complicateEq : ∀ eq ρ → ExpEq eq ρ → CancelEq eq ρ
complicateEq (e₁ , e₂) ρ H =
cancel-complete (norm e₁) (norm e₂) ρ
(unliftNFEq e₁ e₂ ρ H)
simplifyH : ∀ goal ρ → ⟦ goal ⟧hs ρ → ⟦ goal ⟧h ρ
simplifyH [] ρ ()
simplifyH (h ∷ []) ρ H = simplifyEq h ρ H
simplifyH (h ∷ h₂ ∷ g) ρ H = λ H₁ → simplifyH (h₂ ∷ g) ρ $ H (complicateEq h ρ H₁)
simplify-tactic : {x y : Nat} → x ≡ y → Type → TC Term
simplify-tactic {x} {y} prf g = do
`x ← quoteTC x
`y ← quoteTC y
`prf ← quoteTC prf
let h = def₂ (quote _≡_) `x `y
t = pi (vArg h) (abs "_" (weaken 1 g))
just (goal , Γ) ← termToHyps t
where nothing → typeError (strErr "Invalid goal" ∷ termErr t ∷ [])
pure $ def (quote flip)
$ vArg (def (quote simplifyH)
( vArg (` goal)
∷ vArg (quotedEnv Γ) ∷ [] ))
∷ vArg `prf ∷ []
assumed-tactic : {x y : Nat} → x ≡ y → Type → TC Term
assumed-tactic {x} {y} prf g = do
`x ← withNormalisation true $ quoteTC x
`y ← withNormalisation true $ quoteTC y
`prf ← quoteTC prf
let h = def (quote _≡_) (hArg unknown ∷ hArg (def₀ (quote Nat)) ∷ vArg `x ∷ vArg `y ∷ [])
let t = pi (vArg h) (abs "_" (weaken 1 g))
just (goal , Γ) ← termToHyps t
where nothing → typeError (strErr "Invalid goal" ∷ termErr t ∷ [])
pure $
def (quote simplifyH) ( vArg (` goal)
∷ vArg (quotedEnv Γ)
∷ vArg (def (quote id) [])
∷ vArg `prf ∷ [] )
macro
follows-from : {x y : Nat} → x ≡ y → Tactic
follows-from prf hole = do
goal ← inferNormalisedType hole
unify hole =<< assumed-tactic prf goal
simplify : {x y : Nat} → x ≡ y → Tactic
simplify prf hole = do
goal ← inferNormalisedType hole
unify hole =<< simplify-tactic prf goal
| {
"alphanum_fraction": 0.5691452397,
"avg_line_length": 33.4651162791,
"ext": "agda",
"hexsha": "52bb8cbc2ea2f680d81c432d70a3a430807e28a9",
"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": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "src/Tactic/Nat/Simpl.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"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": "lclem/agda-prelude",
"max_issues_repo_path": "src/Tactic/Nat/Simpl.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "src/Tactic/Nat/Simpl.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1119,
"size": 2878
} |
module Celeste where
open import Data.Nat using (ℕ; _⊔_; zero)
open import Data.String using (String)
open import Data.Vec using (Vec)
open import Data.Unsigned using (Unsigned)
open import Data.Signed using (Signed)
open import Data.Float using (Float)
private
variable
word-size : ℕ
mutual
data Type : ℕ → Set where
string : Type zero
int8 : Type zero
uint8 : Type zero
int16 : Type zero
uint16 : Type zero
int32 : Type zero
uint32 : Type zero
int64 : Type zero
uint64 : Type zero
int128 : Type zero
uint128 : Type zero
int-word : Type zero
uint-word : Type zero
float32 : Type zero
float64 : Type zero
_×_ : {m n : ℕ} → Type m → Type n → Type (m ⊔ n)
_⟶_ : {m n : ℕ} → Type m → Type n → Type (m ⊔ n)
data Expr : {n : ℕ} → Type n → Set where
str-lit : String → Expr string
int8-lit : Signed 8 → Expr int8
uint8-lit : Unsigned 8 → Expr uint8
int16-lit : Signed 16 → Expr int16
uint16-lit : Unsigned 16 → Expr uint16
int32-lit : Signed 32 → Expr int32
uint32-lit : Unsigned 32 → Expr uint32
int64-lit : Signed 64 → Expr int64
uint64-lit : Unsigned 64 → Expr uint64
int128-lit : Signed 128 → Expr int128
uint128-lit : Unsigned 128 → Expr uint128
int-word-lit : Signed word-size → Expr int-word
uint-word-lit : Unsigned word-size → Expr uint-word
float32-lit : Float → Expr float32
float64-lit : Float → Expr float64
| {
"alphanum_fraction": 0.6437886067,
"avg_line_length": 29.14,
"ext": "agda",
"hexsha": "3131f70ec47ffca1b404a2229fce54616c1a9d7b",
"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": "9f5129d97ee7b89fb8e43136779a78806b7506ab",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "brunoczim/Celeste",
"max_forks_repo_path": "formalization/Celeste.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f5129d97ee7b89fb8e43136779a78806b7506ab",
"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": "brunoczim/Celeste",
"max_issues_repo_path": "formalization/Celeste.agda",
"max_line_length": 55,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9f5129d97ee7b89fb8e43136779a78806b7506ab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "brunoczim/Celeste",
"max_stars_repo_path": "formalization/Celeste.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-16T17:31:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-16T17:31:57.000Z",
"num_tokens": 461,
"size": 1457
} |
------------------------------------------------------------------------
-- The parser equivalence proof language is sound
------------------------------------------------------------------------
module TotalParserCombinators.Congruence.Sound where
open import Category.Monad
open import Codata.Musical.Notation
open import Data.List
open import Data.List.Membership.Propositional using (_∈_)
import Data.List.Categorical as ListMonad
open import Data.List.Relation.Binary.BagAndSetEquality
renaming (_∼[_]_ to _List-∼[_]_)
open import Data.Maybe hiding (_>>=_)
open import Data.Product
open import Function
import Function.Related as Related
open import Level
open import Relation.Binary
import Relation.Binary.PropositionalEquality as P
open Related using (SK-sym)
open Related.EquationalReasoning
renaming (_∼⟨_⟩_ to _∼⟨_⟩′_; _∎ to _∎′)
open RawMonad {f = zero} ListMonad.monad
using () renaming (_⊛_ to _⊛′_; _>>=_ to _>>=′_)
private
module BSOrd {k} {A : Set} = Preorder ([ k ]-Order A)
open import TotalParserCombinators.Derivative using (D)
open import TotalParserCombinators.CoinductiveEquality as CE
using (_∼[_]c_; _∷_)
open import TotalParserCombinators.Congruence
open import TotalParserCombinators.Laws
open import TotalParserCombinators.Lib using (return⋆)
open import TotalParserCombinators.Parser
open import TotalParserCombinators.Semantics using (_∼[_]_)
------------------------------------------------------------------------
-- Some lemmas
private
⊛flatten-lemma : ∀ {k} {R₁ R₂ : Set} {fs₁ fs₂ : List (R₁ → R₂)}
(xs₁ xs₂ : Maybe (List R₁)) →
fs₁ List-∼[ k ] fs₂ →
flatten xs₁ List-∼[ k ] flatten xs₂ →
fs₁ ⊛flatten xs₁ List-∼[ k ] fs₂ ⊛flatten xs₂
⊛flatten-lemma {k} {fs₁ = fs₁} {fs₂} xs₁ xs₂ fs₁≈fs₂ = helper xs₁ xs₂
where
helper : ∀ xs₁ xs₂ →
flatten xs₁ List-∼[ k ] flatten xs₂ →
fs₁ ⊛flatten xs₁ List-∼[ k ] fs₂ ⊛flatten xs₂
helper nothing nothing []∼[] = BSOrd.refl
helper (just xs₁) (just xs₂) xs₁≈xs₂ = ⊛-cong fs₁≈fs₂ xs₁≈xs₂
helper nothing (just xs₂) []≈xs₂ {x} =
x ∈ [] ↔⟨ BSOrd.reflexive $ P.sym $
ListMonad.Applicative.right-zero fs₂ ⟩
x ∈ (fs₂ ⊛′ []) ∼⟨ ⊛-cong (BSOrd.refl {x = fs₂}) []≈xs₂ ⟩′
x ∈ (fs₂ ⊛′ xs₂) ∎′
helper (just xs₁) nothing xs₁∼[] {x} =
x ∈ (fs₁ ⊛′ xs₁) ∼⟨ ⊛-cong (BSOrd.refl {x = fs₁}) xs₁∼[] ⟩′
x ∈ (fs₁ ⊛′ []) ↔⟨ BSOrd.reflexive $
ListMonad.Applicative.right-zero fs₁ ⟩
x ∈ [] ∎′
[]-⊛flatten : ∀ {A B : Set} (xs : Maybe (List A)) →
[] ⊛flatten xs List-∼[ bag ] [] {A = B}
[]-⊛flatten nothing = BSOrd.refl
[]-⊛flatten (just xs) = BSOrd.refl
bind-lemma : ∀ {k} {R₁ R₂ : Set} {xs₁ xs₂ : Maybe (List R₁)}
(f₁ f₂ : Maybe (R₁ → List R₂)) →
flatten xs₁ List-∼[ k ] flatten xs₂ →
(∀ x → apply f₁ x List-∼[ k ] apply f₂ x) →
bind xs₁ f₁ List-∼[ k ] bind xs₂ f₂
bind-lemma {k} {xs₁ = xs₁} {xs₂} f₁ f₂ xs₁≈xs₂ = helper f₁ f₂
where
helper : ∀ f₁ f₂ →
(∀ x → apply f₁ x List-∼[ k ] apply f₂ x) →
bind xs₁ f₁ List-∼[ k ] bind xs₂ f₂
helper nothing nothing []∼[] = BSOrd.refl
helper (just f₁) (just f₂) f₁≈f₂ = >>=-cong xs₁≈xs₂ f₁≈f₂
helper nothing (just f₂) []≈f₂ {x} =
x ∈ [] ∼⟨ BSOrd.reflexive $ P.sym $
ListMonad.MonadProperties.right-zero (flatten xs₂) ⟩′
x ∈ (flatten xs₂ >>=′ λ _ → []) ∼⟨ >>=-cong (BSOrd.refl {x = flatten xs₂}) []≈f₂ ⟩′
x ∈ (flatten xs₂ >>=′ f₂) ∎′
helper (just f₁) nothing f₁∼[] {x} =
x ∈ (flatten xs₁ >>=′ f₁) ∼⟨ >>=-cong (BSOrd.refl {x = flatten xs₁}) f₁∼[] ⟩′
x ∈ (flatten xs₁ >>=′ λ _ → []) ∼⟨ BSOrd.reflexive $
ListMonad.MonadProperties.right-zero (flatten xs₁) ⟩′
x ∈ [] ∎′
bind-nothing : ∀ {A B : Set} (f : Maybe (A → List B)) →
bind nothing f List-∼[ bag ] []
bind-nothing nothing = BSOrd.refl
bind-nothing (just f) = BSOrd.refl
------------------------------------------------------------------------
-- Equality is closed under initial-bag
initial-bag-cong :
∀ {k Tok R xs₁ xs₂} {p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ∼[ k ]P p₂ → initial-bag p₁ List-∼[ k ] initial-bag p₂
initial-bag-cong (xs₁≈xs₂ ∷ Dp₁≈Dp₂) = xs₁≈xs₂
initial-bag-cong (p ∎) = BSOrd.refl
initial-bag-cong (p₁ ∼⟨ p₁≈p₂ ⟩ p₂≈p₃) = _ ∼⟨ initial-bag-cong p₁≈p₂ ⟩′ initial-bag-cong p₂≈p₃
initial-bag-cong (p₁ ≅⟨ p₁≅p₂ ⟩ p₂≈p₃) = _ ↔⟨ initial-bag-cong p₁≅p₂ ⟩ initial-bag-cong p₂≈p₃
initial-bag-cong (sym p₁≈p₂) = SK-sym (initial-bag-cong p₁≈p₂)
initial-bag-cong (return x₁≡x₂) = BSOrd.reflexive $ P.cong [_] x₁≡x₂
initial-bag-cong fail = BSOrd.refl
initial-bag-cong token = BSOrd.refl
initial-bag-cong (p₁≈p₃ ∣ p₂≈p₄) = ++-cong (initial-bag-cong p₁≈p₃) (initial-bag-cong p₂≈p₄)
initial-bag-cong (f₁≗f₂ <$> p₁≈p₂) = map-cong f₁≗f₂ $ initial-bag-cong p₁≈p₂
initial-bag-cong (nonempty p₁≈p₂) = BSOrd.refl
initial-bag-cong (cast {xs₁ = xs₁} {xs₂ = xs₂}
{xs₁′ = xs₁′} {xs₂′ = xs₂′}
{xs₁≈xs₁′ = xs₁≈xs₁′} {xs₂≈xs₂′ = xs₂≈xs₂′}
p₁≈p₂) {x} =
x ∈ xs₁′ ↔⟨ SK-sym xs₁≈xs₁′ ⟩
x ∈ xs₁ ∼⟨ initial-bag-cong p₁≈p₂ ⟩′
x ∈ xs₂ ↔⟨ xs₂≈xs₂′ ⟩
x ∈ xs₂′ ∎′
initial-bag-cong ([ nothing - _ ] p₁≈p₃ ⊛ p₂≈p₄) = BSOrd.refl
initial-bag-cong ([ just (xs₁ , xs₂) - just _ ] p₁≈p₃ ⊛ p₂≈p₄) = ⊛flatten-lemma xs₁ xs₂
(initial-bag-cong p₁≈p₃) (initial-bag-cong p₂≈p₄)
initial-bag-cong ([ just (xs₁ , xs₂) - nothing ] p₁≈p₃ ⊛ p₂≈p₄) {x} =
x ∈ [] ⊛flatten xs₁ ↔⟨ []-⊛flatten xs₁ ⟩
x ∈ [] ↔⟨ SK-sym $ []-⊛flatten xs₂ ⟩
x ∈ [] ⊛flatten xs₂ ∎′
initial-bag-cong ([ nothing - _ ] p₁≈p₃ >>= p₂≈p₄) = BSOrd.refl
initial-bag-cong ([ just (f₁ , f₂) - just _ ] p₁≈p₃ >>= p₂≈p₄) = bind-lemma f₁ f₂
(initial-bag-cong p₁≈p₃) (λ x → initial-bag-cong (p₂≈p₄ x))
initial-bag-cong ([ just (f₁ , f₂) - nothing ] p₁≈p₃ >>= p₂≈p₄) {x} =
x ∈ bind nothing f₁ ↔⟨ bind-nothing f₁ ⟩
x ∈ [] ↔⟨ SK-sym $ bind-nothing f₂ ⟩
x ∈ bind nothing f₂ ∎′
------------------------------------------------------------------------
-- Equality is closed under D
D-cong : ∀ {k Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ∼[ k ]P p₂ → ∀ {t} → D t p₁ ∼[ k ]P D t p₂
D-cong (xs₁≈xs₂ ∷ Dp₁≈Dp₂) {t} = ♭ (Dp₁≈Dp₂ t)
D-cong (p ∎) {t} = D t p ∎
D-cong (p₁ ∼⟨ p₁≈p₂ ⟩ p₂≈p₃) {t} = D t p₁ ∼⟨ D-cong p₁≈p₂ ⟩ D-cong p₂≈p₃
D-cong (p₁ ≅⟨ p₁≅p₂ ⟩ p₂≈p₃) {t} = D t p₁ ≅⟨ D-cong p₁≅p₂ ⟩ D-cong p₂≈p₃
D-cong (sym p₁≈p₂) = _∼[_]P_.sym (D-cong p₁≈p₂)
D-cong (return x₁≡x₂) = fail ∎
D-cong fail = fail ∎
D-cong token {t} = return t ∎
D-cong (p₁≈p₃ ∣ p₂≈p₄) = D-cong p₁≈p₃ ∣ D-cong p₂≈p₄
D-cong (f₁≗f₂ <$> p₁≈p₂) = f₁≗f₂ <$> D-cong p₁≈p₂
D-cong (nonempty p₁≈p₂) = D-cong p₁≈p₂
D-cong (cast p₁≈p₂) = D-cong p₁≈p₂
D-cong ([_-_]_⊛_ nothing nothing {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ ⊛ p₂) ∼⟨ [ nothing - just (○ , ○) ] ♯ D-cong (♭ p₁≈p₃) ⊛ ♭ p₂≈p₄ ⟩
D t (p₃ ⊛ p₄) ∎
D-cong ([_-_]_⊛_ nothing (just (fs₁ , fs₂)) {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ ⊛ p₂) ≅⟨ D.D-⊛ p₁ p₂ ⟩
D t (♭ p₁) ⊛ ♭? p₂ ∣ return⋆ (flatten fs₁) ⊛ D t (♭? p₂) ≅⟨ [ ○ - ◌ - ○ - ○ ] D t (♭ p₁) ∎ ⊛ (♭? p₂ ∎) ∣ (_ ∎) ⟩
♯ D t (♭ p₁) ⊛ ♭? p₂ ∣ return⋆ (flatten fs₁) ⊛ D t (♭? p₂) ∼⟨ [ nothing - just (○ , ○) ] ♯ D-cong (♭ p₁≈p₃) ⊛ p₂≈p₄ ∣
[ just (○ , ○) - just (○ , ○) ]
Return⋆.cong (initial-bag-cong (♭ p₁≈p₃)) ⊛ D-cong p₂≈p₄ ⟩
♯ D t (♭ p₃) ⊛ ♭? p₄ ∣ return⋆ (flatten fs₂) ⊛ D t (♭? p₄) ≅⟨ [ ◌ - ○ - ○ - ○ ] D t (♭ p₃) ∎ ⊛ (♭? p₄ ∎) ∣ (_ ∎) ⟩
D t (♭ p₃) ⊛ ♭? p₄ ∣ return⋆ (flatten fs₂) ⊛ D t (♭? p₄) ≅⟨ _∼[_]P_.sym $ D.D-⊛ p₃ p₄ ⟩
D t (p₃ ⊛ p₄) ∎
D-cong ([_-_]_⊛_ (just _) nothing {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ ⊛ p₂) ≅⟨ D.D-⊛ p₁ p₂ ⟩
D t (♭? p₁) ⊛ ♭ p₂ ∣ return⋆ [] ⊛ D t (♭ p₂) ≅⟨ (D t (♭? p₁) ⊛ ♭ p₂ ∎) ∣
[ ○ - ○ - ○ - ◌ ] return⋆ [] ∎ ⊛ (D t (♭ p₂) ∎) ⟩
D t (♭? p₁) ⊛ ♭ p₂ ∣ return⋆ [] ⊛ ♯ D t (♭ p₂) ∼⟨ [ just (○ , ○) - just (○ , ○) ] D-cong p₁≈p₃ ⊛ ♭ p₂≈p₄ ∣
[ just (○ , ○) - nothing ] (return⋆ [] ∎) ⊛ ♯ D-cong (♭ p₂≈p₄) ⟩
D t (♭? p₃) ⊛ ♭ p₄ ∣ return⋆ [] ⊛ ♯ D t (♭ p₄) ≅⟨ (D t (♭? p₃) ⊛ ♭ p₄ ∎) ∣
[ ○ - ○ - ◌ - ○ ] return⋆ [] ∎ ⊛ (D t (♭ p₄) ∎) ⟩
D t (♭? p₃) ⊛ ♭ p₄ ∣ return⋆ [] ⊛ D t (♭ p₄) ≅⟨ _∼[_]P_.sym $ D.D-⊛ p₃ p₄ ⟩
D t (p₃ ⊛ p₄) ∎
D-cong ([_-_]_⊛_ (just _) (just (fs₁ , fs₂)) {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ ⊛ p₂) ≅⟨ D.D-⊛ p₁ p₂ ⟩
D t (♭? p₁) ⊛ ♭? p₂ ∣ return⋆ (flatten fs₁) ⊛ D t (♭? p₂) ∼⟨ [ just (○ , ○) - just (○ , ○) ] D-cong p₁≈p₃ ⊛ p₂≈p₄ ∣
[ just (○ , ○) - just (○ , ○) ] Return⋆.cong (initial-bag-cong p₁≈p₃) ⊛
D-cong p₂≈p₄ ⟩
D t (♭? p₃) ⊛ ♭? p₄ ∣ return⋆ (flatten fs₂) ⊛ D t (♭? p₄) ≅⟨ _∼[_]P_.sym $ D.D-⊛ p₃ p₄ ⟩
D t (p₃ ⊛ p₄) ∎
D-cong ([_-_]_>>=_ nothing nothing {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ >>= p₂) ∼⟨ [ nothing - just (○ , ○) ] ♯ D-cong (♭ p₁≈p₃) >>= (♭ ∘ p₂≈p₄) ⟩
D t (p₃ >>= p₄) ∎
D-cong ([_-_]_>>=_ nothing (just (xs₁ , xs₂)) {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ >>= p₂) ≅⟨ D.D->>= p₁ p₂ ⟩
D t (♭ p₁) >>= (♭? ∘ p₂) ∣ return⋆ (flatten xs₁) >>= (D t ∘ ♭? ∘ p₂) ≅⟨ [ ○ - ◌ - ○ - ○ ] D t (♭ p₁) ∎ >>= (λ x → ♭? (p₂ x) ∎) ∣
(_ ∎) ⟩
♯ D t (♭ p₁) >>= (♭? ∘ p₂) ∣ return⋆ (flatten xs₁) >>= (D t ∘ ♭? ∘ p₂) ∼⟨ [ nothing - just (○ , ○) ] ♯ D-cong (♭ p₁≈p₃) >>= p₂≈p₄ ∣
[ just (○ , ○) - just (○ , ○) ]
Return⋆.cong (initial-bag-cong (♭ p₁≈p₃)) >>=
(λ x → D-cong (p₂≈p₄ x)) ⟩
♯ D t (♭ p₃) >>= (♭? ∘ p₄) ∣ return⋆ (flatten xs₂) >>= (D t ∘ ♭? ∘ p₄) ≅⟨ [ ◌ - ○ - ○ - ○ ] D t (♭ p₃) ∎ >>= (λ x → ♭? (p₄ x) ∎) ∣
(_ ∎) ⟩
D t (♭ p₃) >>= (♭? ∘ p₄) ∣ return⋆ (flatten xs₂) >>= (D t ∘ ♭? ∘ p₄) ≅⟨ _∼[_]P_.sym $ D.D->>= p₃ p₄ ⟩
D t (p₃ >>= p₄) ∎
D-cong ([_-_]_>>=_ (just _) nothing {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ >>= p₂) ≅⟨ D.D->>= p₁ p₂ ⟩
D t (♭? p₁) >>= (♭ ∘ p₂) ∣ return⋆ [] >>= (D t ∘ ♭ ∘ p₂) ≅⟨ (D t (♭? p₁) >>= (♭ ∘ p₂) ∎) ∣
[ ○ - ○ - ○ - ◌ ] return⋆ [] ∎ >>= (λ x → D t (♭ (p₂ x)) ∎) ⟩
D t (♭? p₁) >>= (♭ ∘ p₂) ∣ return⋆ [] >>= (λ x → ♯ D t (♭ (p₂ x))) ∼⟨ [ just (○ , ○) - just (○ , ○) ] D-cong p₁≈p₃ >>= (♭ ∘ p₂≈p₄) ∣
[ just (○ , ○) - nothing ] (return⋆ [] ∎) >>=
(λ x → ♯ D-cong (♭ (p₂≈p₄ x))) ⟩
D t (♭? p₃) >>= (♭ ∘ p₄) ∣ return⋆ [] >>= (λ x → ♯ D t (♭ (p₄ x))) ≅⟨ (D t (♭? p₃) >>= (♭ ∘ p₄) ∎) ∣
[ ○ - ○ - ◌ - ○ ] return⋆ [] ∎ >>= (λ x → D t (♭ (p₄ x)) ∎) ⟩
D t (♭? p₃) >>= (♭ ∘ p₄) ∣ return⋆ [] >>= (D t ∘ ♭ ∘ p₄) ≅⟨ _∼[_]P_.sym $ D.D->>= p₃ p₄ ⟩
D t (p₃ >>= p₄) ∎
D-cong ([_-_]_>>=_ (just _) (just (xs₁ , xs₂)) {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ >>= p₂) ≅⟨ D.D->>= p₁ p₂ ⟩
D t (♭? p₁) >>= (♭? ∘ p₂) ∣ return⋆ (flatten xs₁) >>= (D t ∘ ♭? ∘ p₂) ∼⟨ [ just (○ , ○) - just (○ , ○) ] D-cong p₁≈p₃ >>= p₂≈p₄ ∣
[ just (○ , ○) - just (○ , ○) ]
Return⋆.cong (initial-bag-cong p₁≈p₃) >>=
(λ x → D-cong (p₂≈p₄ x)) ⟩
D t (♭? p₃) >>= (♭? ∘ p₄) ∣ return⋆ (flatten xs₂) >>= (D t ∘ ♭? ∘ p₄) ≅⟨ _∼[_]P_.sym $ D.D->>= p₃ p₄ ⟩
D t (p₃ >>= p₄) ∎
------------------------------------------------------------------------
-- Soundness
sound : ∀ {k Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁}
{p₂ : Parser Tok R xs₂} →
p₁ ∼[ k ]P p₂ → p₁ ∼[ k ] p₂
sound = CE.sound ∘ sound′
where
sound′ : ∀ {k Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁}
{p₂ : Parser Tok R xs₂} →
p₁ ∼[ k ]P p₂ → p₁ ∼[ k ]c p₂
sound′ p₁≈p₂ = initial-bag-cong p₁≈p₂ ∷ λ t → ♯ sound′ (D-cong p₁≈p₂)
| {
"alphanum_fraction": 0.3893384441,
"avg_line_length": 58.4564315353,
"ext": "agda",
"hexsha": "c5f61abd5a97d2d055a50889f55cd0d0e0ae41c3",
"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/Congruence/Sound.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/Congruence/Sound.agda",
"max_line_length": 135,
"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/Congruence/Sound.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": 6077,
"size": 14088
} |
module _ where
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat
variable
f : Nat → Nat
-- Drops the argument to f!
foo : (n : Nat) → f n ≡ n → f (f n) ≡ n
foo n eq rewrite eq = eq
| {
"alphanum_fraction": 0.65,
"avg_line_length": 15.3846153846,
"ext": "agda",
"hexsha": "9819dd62aab248de20f0066925f60ae362273a75",
"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/Issue3290.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/Issue3290.agda",
"max_line_length": 39,
"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/Issue3290.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": 70,
"size": 200
} |
{-# OPTIONS --without-K #-}
module algebra.monoid.mset where
open import level
open import algebra.monoid.core
open import algebra.monoid.morphism
open import algebra.semigroup
open import equality.core
open import hott.level
module _ {i}(M : Set i) ⦃ mM : IsMonoid M ⦄ where
open IsMonoid ⦃ ... ⦄
record IsMSet {j} (X : Set j) : Set (i ⊔ j) where
constructor mk-is-mset
field
_◂_ : M → X → X
◂-hom : (m₁ m₂ : M)(x : X) → (m₁ * m₂) ◂ x ≡ m₁ ◂ (m₂ ◂ x)
◂-id : (x : X) → e ◂ x ≡ x
mset-level : h 2 X
open IsMSet ⦃ ... ⦄
module _ {j k}
{X : Set j} ⦃ xM : IsMSet X ⦄
{Y : Set k} ⦃ yM : IsMSet Y ⦄ where
IsMSetMorphism : (X → Y) → Set (i ⊔ j ⊔ k)
IsMSetMorphism f = (m : M)(x : X) → f (m ◂ x) ≡ m ◂ f x
is-mset-morphism-level : h 2 Y → (f : X → Y)
→ h 1 (IsMSetMorphism f)
is-mset-morphism-level hY f = Π-level λ m → Π-level λ x → hY _ _
| {
"alphanum_fraction": 0.5449620802,
"avg_line_length": 28.84375,
"ext": "agda",
"hexsha": "97305d6516481f38aa08516de724071355e9bfd8",
"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/algebra/monoid/mset.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/algebra/monoid/mset.agda",
"max_line_length": 68,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/algebra/monoid/mset.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 384,
"size": 923
} |
-- Andreas, 2013-10-27
{-# OPTIONS --copatterns #-}
module Issue907a where
import Common.Level
open import Common.Prelude
open import Common.Product
data Vec (A : Set) : Nat → Set where
[] : Vec A zero
test : ∀ {A} → Σ Nat λ n → Vec A n
proj₁ test = zero
proj₂ test = []
| {
"alphanum_fraction": 0.6582733813,
"avg_line_length": 16.3529411765,
"ext": "agda",
"hexsha": "651b7fd483965f17720f7e593551b9dff879ff98",
"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/Issue907a.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/Issue907a.agda",
"max_line_length": 36,
"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/Issue907a.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": 87,
"size": 278
} |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.SuspAdjointLoop
open import cohomology.WithCoefficients
module cohomology.SuspAdjointLoopIso where
module SuspAdjointLoopIso {i j} (X : Ptd i) (Y : Ptd j) where
module ΣAΩ = SuspAdjointLoop X (⊙Ω Y)
GSΣ = →Ω-group-structure (⊙Susp X) Y
GSΩ = →Ω-group-structure X (⊙Ω Y)
open GroupStructure
comp-path : (p q : fst (⊙Ω (⊙Ω Y))) → ap2 _∙_ p q == p ∙ q
comp-path p q = ap2-out _∙_ p q ∙ ap2 _∙_ (lemma p) (ap-idf q)
where
lemma : ∀ {i} {A : Type i} {x y : A} {p q : x == y} (α : p == q)
→ ap (λ r → r ∙ idp) α == ∙-unit-r p ∙ α ∙' ! (∙-unit-r q)
lemma {p = idp} idp = idp
pres-comp-inner : (H₁ H₂ : fst (⊙Susp X ⊙→ ⊙Ω Y))
→ ΣAΩ.R (comp GSΣ H₁ H₂) == comp GSΩ (ΣAΩ.R H₁) (ΣAΩ.R H₂)
pres-comp-inner H₁ H₂ =
transport
(λ {(op , op-path) →
ΣAΩ.R (comp GSΣ H₁ H₂) ==
transport (λ b → Σ (fst X → _) (λ h → h (snd X) == b)) op-path
(ΣAΩ.comp-lift (snd X) idp idp op (ΣAΩ.R H₁) (ΣAΩ.R H₂))})
(pair= (λ= (λ p → λ= (comp-path p)))
{b = idp} {b' = idp} (↓-app=cst-in snd-path))
(ΣAΩ.pres-comp _∙_ H₁ H₂)
where
snd-path : idp == ap (λ f → f idp idp) (λ= (λ p → λ= (comp-path p))) ∙ idp
snd-path =
idp
=⟨ ! (app=-β (comp-path idp) idp) ⟩
app= (λ= (comp-path idp)) idp
=⟨ ap (λ q → app= q idp) (! (app=-β (λ p → λ= (comp-path p)) idp)) ⟩
app= (app= (λ= (λ p → λ= (comp-path p))) idp) idp
=⟨ ∘-ap (λ z → z idp) (λ z → z idp) (λ= (λ p → λ= (comp-path p))) ⟩
ap (λ f → f idp idp) (λ= (λ p → λ= (comp-path p)))
=⟨ ! (∙-unit-r _) ⟩
ap (λ f → f idp idp) (λ= (λ p → λ= (comp-path p))) ∙ idp ∎
iso : →Ω-Group (⊙Susp X) Y ≃ᴳ →Ω-Group X (⊙Ω Y)
iso = Trunc-Group-iso ΣAΩ.R pres-comp-inner (snd (ΣAΩ.eqv))
| {
"alphanum_fraction": 0.5021786492,
"avg_line_length": 37.4693877551,
"ext": "agda",
"hexsha": "b35fccdbda6307c87512714a3a241170ac2235a1",
"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": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danbornside/HoTT-Agda",
"max_forks_repo_path": "cohomology/SuspAdjointLoopIso.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"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": "danbornside/HoTT-Agda",
"max_issues_repo_path": "cohomology/SuspAdjointLoopIso.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danbornside/HoTT-Agda",
"max_stars_repo_path": "cohomology/SuspAdjointLoopIso.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 856,
"size": 1836
} |
{-
This second-order equational theory was created from the following second-order syntax description:
syntax Unit | U
type
𝟙 : 0-ary
term
unit : 𝟙
theory
(𝟙η) u : 𝟙 |> u = unit
-}
module Unit.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 Unit.Signature
open import Unit.Syntax
open import SOAS.Metatheory.SecondOrder.Metasubstitution U:Syn
open import SOAS.Metatheory.SecondOrder.Equality U:Syn
private
variable
α β γ τ : UT
Γ Δ Π : Ctx
infix 1 _▹_⊢_≋ₐ_
-- Axioms of equality
data _▹_⊢_≋ₐ_ : ∀ 𝔐 Γ {α} → (𝔐 ▷ U) α Γ → (𝔐 ▷ U) α Γ → Set where
𝟙η : ⁅ 𝟙 ⁆̣ ▹ ∅ ⊢ 𝔞 ≋ₐ unit
open EqLogic _▹_⊢_≋ₐ_
open ≋-Reasoning
| {
"alphanum_fraction": 0.7105263158,
"avg_line_length": 18.1363636364,
"ext": "agda",
"hexsha": "71c0b94c154a1ac3e17689db096bef9b1534d96a",
"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/Unit/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/Unit/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/Unit/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": 313,
"size": 798
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.CoHSpace
open import cohomology.Theory
module cohomology.CoHSpace {i} (CT : CohomologyTheory i) (n : ℤ)
{X : Ptd i} (CHSS : CoHSpaceStructure X) where
open CohomologyTheory CT
open CoHSpaceStructure CHSS
open import cohomology.Wedge CT n
abstract
private
lemma-l : CEl-fmap n ⊙coμ ∘ CEl-fmap n ⊙projl ∼ idf _
lemma-l x =
∘-CEl-fmap n ⊙coμ ⊙projl x
∙ ap (λ f → CEl-fmap n f x) (⊙λ= ⊙unit-r)
∙ CEl-fmap-idf n x
lemma-r : CEl-fmap n ⊙coμ ∘ CEl-fmap n ⊙projr ∼ idf _
lemma-r x =
∘-CEl-fmap n ⊙coμ ⊙projr x
∙ ap (λ f → CEl-fmap n f x) (⊙λ= ⊙unit-l)
∙ CEl-fmap-idf n x
C-fmap-coμ : ∀ x → CEl-fmap n ⊙coμ x == Group.comp (C n X) (CEl-fmap n ⊙winl x) (CEl-fmap n ⊙winr x)
C-fmap-coμ x =
CEl-fmap n ⊙coμ x
=⟨ C-Wedge-out-η-comm-sqr X X (C-fmap n ⊙coμ) □$ᴳ x ⟩
Group.comp (C n X)
(CEl-fmap n ⊙coμ (CEl-fmap n ⊙projl (CEl-fmap n ⊙winl x)))
(CEl-fmap n ⊙coμ (CEl-fmap n ⊙projr (CEl-fmap n ⊙winr x)))
=⟨ ap2 (Group.comp (C n X)) (lemma-l (CEl-fmap n ⊙winl x)) (lemma-r (CEl-fmap n ⊙winr x)) ⟩
Group.comp (C n X) (CEl-fmap n ⊙winl x) (CEl-fmap n ⊙winr x)
=∎
| {
"alphanum_fraction": 0.588474026,
"avg_line_length": 32.4210526316,
"ext": "agda",
"hexsha": "b11449a91cd799e6c2f9841477a05c14ccf0f950",
"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/cohomology/CoHSpace.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/cohomology/CoHSpace.agda",
"max_line_length": 102,
"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/cohomology/CoHSpace.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": 555,
"size": 1232
} |
{-# OPTIONS --without-K #-}
--open import HoTT
open import homotopy.3x3.PushoutPushout
open import homotopy.3x3.Transpose
import homotopy.3x3.To as To
import homotopy.3x3.From as From
open import homotopy.3x3.Common
module homotopy.3x3.ToFrom {i} (d : Span^2 {i}) where
open Span^2 d
open M d hiding (Pushout^2)
open M (transpose d) using () renaming (A₀∙ to A∙₀; A₂∙ to A∙₂; A₄∙ to A∙₄;
module F₁∙ to F∙₁; f₁∙ to f∙₁;
module F₃∙ to F∙₃; f₃∙ to f∙₃;
v-h-span to h-v-span)
open M using (Pushout^2)
open To d
open From d
open import homotopy.3x3.ToFromInit d
open import homotopy.3x3.ToFrom2 d
open import homotopy.3x3.ToFrom3 d
to-from-g-g : (c : A₂₂) → (to-from-g-l (f₁₂ c) , ↓-='-out (apd (to-from-r ∘ f∙₃) (glue c)) , ↓-='-out (apd (ap to ∘ ap from ∘ glue) (glue c))
=□□ ↓-='-out (apd glue (glue c)) , ↓-='-out (apd (to-from-l ∘ f∙₁) (glue c)) , to-from-g-r (f₃₂ c))
to-from-g-g c = coh _ lemma1 lemma3 _ _ (↓-='-out (apd glue (glue c))) lemma2
where
open M2 c
open M3 c
to-from-g-g' : (c : A₂₂) → to-from-g-l (f₁₂ c) == to-from-g-r (f₃₂ c) [ (λ c → (to-from-l (f∙₁ c) , glue c =□ ap to (ap from (glue c)) , to-from-r (f∙₃ c))) ↓ glue c ]
to-from-g-g' c = ↓-=□-in (to-from-g-g c)
module ToFromG = PushoutElim {d = span _ _ _ f₁₂ f₃₂} {P = λ c → (to-from-l (f∙₁ c) , glue c =□ ap to (ap from (glue c)) , to-from-r (f∙₃ c))}
to-from-g-l to-from-g-r to-from-g-g'
to-from-g : (c : A∙₂) → (to-from-l (f∙₁ c) , glue c =□ ap to (ap from (glue c)) , to-from-r (f∙₃ c))
to-from-g = ToFromG.f
to-from-g' : (c : A∙₂) → to-from-l (f∙₁ c) == to-from-r (f∙₃ c) [ (λ z → to (from z) == z) ↓ glue c ]
to-from-g' c = ↓-∘=idf-in to from (to-from-g c)
to-from : (x : Pushout^2 (transpose d)) → to (from x) == x
to-from = Pushout-elim to-from-l to-from-r to-from-g'
| {
"alphanum_fraction": 0.5354969574,
"avg_line_length": 41.0833333333,
"ext": "agda",
"hexsha": "37b7ddc91dcd3155516f58f98b67a45444a61ae3",
"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": "homotopy/3x3/ToFrom.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": "homotopy/3x3/ToFrom.agda",
"max_line_length": 167,
"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": "homotopy/3x3/ToFrom.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": 806,
"size": 1972
} |
module SubstantiveDischargeIsConsistent where
open import HasNegation
open import HasSubstantiveDischarge
record SubstantiveDischargeIsConsistent (+ : Set) (- : Set) ⦃ _ : HasNegation (-) ⦄ ⦃ _ : HasSubstantiveDischarge (+) (-) ⦄ : Set₁
where
field
≽-consistent : {+ : +} → { - : - } → + ≽ - → + ⋡ ~ -
open SubstantiveDischargeIsConsistent ⦃ … ⦄ public
{-# DISPLAY SubstantiveDischargeIsConsistent.≽-consistent _ = ≽-consistent #-}
| {
"alphanum_fraction": 0.6824324324,
"avg_line_length": 29.6,
"ext": "agda",
"hexsha": "f5f9b77f0fbdd85dcab8c00348a2767f98502bad",
"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/SubstantiveDischargeIsConsistent.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/SubstantiveDischargeIsConsistent.agda",
"max_line_length": 130,
"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/SubstantiveDischargeIsConsistent.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 153,
"size": 444
} |
------------------------------------------------------------------------
-- Closure properties for h-levels
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
-- Partly based on Voevodsky's work on so-called univalent
-- foundations.
open import Equality
module H-level.Closure
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Bijection eq as Bijection hiding (id; _∘_)
open Derived-definitions-and-properties eq
import Equality.Decidable-UIP eq as DUIP
open import Equality.Decision-procedures eq
open import H-level eq
open import Logical-equivalence hiding (id; _∘_)
open import Nat eq as Nat
open import Prelude
open import Surjection eq as Surjection hiding (id; _∘_)
------------------------------------------------------------------------
-- The unit type
-- The unit type is contractible.
⊤-contractible : Contractible ⊤
⊤-contractible = (_ , λ _ → refl _)
-- A type is contractible iff it is in bijective correspondence with
-- the unit type.
contractible⇔↔⊤ : ∀ {a} {A : Type a} → Contractible A ⇔ (A ↔ ⊤)
contractible⇔↔⊤ = record
{ to = flip contractible-isomorphic ⊤-contractible
; from = λ A↔⊤ → respects-surjection
(_↔_.surjection (Bijection.inverse A↔⊤))
0
⊤-contractible
}
------------------------------------------------------------------------
-- The empty type
abstract
-- The empty type is not contractible.
¬-⊥-contractible : ∀ {ℓ} → ¬ Contractible (⊥ {ℓ = ℓ})
¬-⊥-contractible = ⊥-elim ∘ proj₁
-- The empty type is propositional.
⊥-propositional : ∀ {ℓ} → Is-proposition (⊥ {ℓ = ℓ})
⊥-propositional x = ⊥-elim x
-- Thus any uninhabited type is also propositional.
uninhabited-propositional : ∀ {a} {A : Type a} →
¬ A → Is-proposition A
uninhabited-propositional ¬A =
respects-surjection (_↔_.surjection $ ⊥↔uninhabited {ℓ = # 0} ¬A) 1
⊥-propositional
------------------------------------------------------------------------
-- Booleans
abstract
-- The booleans are not propositional.
¬-Bool-propositional : ¬ Is-proposition Bool
¬-Bool-propositional propositional =
Bool.true≢false $
propositional true false
-- The booleans form a set.
Bool-set : Is-set Bool
Bool-set = DUIP.decidable⇒set Bool._≟_
------------------------------------------------------------------------
-- Natural numbers
abstract
-- ℕ is not propositional.
¬-ℕ-propositional : ¬ Is-proposition ℕ
¬-ℕ-propositional ℕ-prop = 0≢+ $ ℕ-prop 0 1
-- ℕ is a set.
ℕ-set : Is-set ℕ
ℕ-set = DUIP.decidable⇒set Nat._≟_
-- Nat._≤_ is not a family of contractible types.
¬-≤-contractible : ¬ (∀ {m n} → Contractible (m Nat.≤ n))
¬-≤-contractible ≤-contr with proj₁ (≤-contr {m = 1} {n = 0})
... | ≤-refl′ 1≡0 = 0≢+ (sym 1≡0)
... | ≤-step′ _ +≡0 = 0≢+ (sym +≡0)
-- Nat._≤_ is a family of propositions.
≤-propositional : ∀ {m n} → Is-proposition (m Nat.≤ n)
≤-propositional = irr
where
lemma : ∀ {m n k} → m ≡ n → m ≤ k → suc k ≡ n → ⊥₀
lemma {m} {n} {k} m≡n m≤k 1+k≡n = <-irreflexive (
suc n ≡⟨ cong suc $ sym m≡n ⟩≤
suc m ≤⟨ suc≤suc m≤k ⟩
suc k ≡⟨ 1+k≡n ⟩≤
n ∎≤)
cong-≤-step′ :
∀ {m n k₁ k₂}
{p₁ : m ≤ k₁} {q₁ : suc k₁ ≡ n}
{p₂ : m ≤ k₂} {q₂ : suc k₂ ≡ n} →
(k₁≡k₂ : k₁ ≡ k₂) →
subst (m ≤_) k₁≡k₂ p₁ ≡ p₂ →
subst (λ k → suc k ≡ n) k₁≡k₂ q₁ ≡ q₂ →
≤-step′ p₁ q₁ ≡ ≤-step′ p₂ q₂
cong-≤-step′ {p₁ = p₁} {q₁} {p₂} {q₂} k₁≡k₂ p-eq q-eq =
cong (λ { (k , p , q) → ≤-step′ {k = k} p q })
(Σ-≡,≡→≡
k₁≡k₂
(subst (λ k → _ ≤ k × suc k ≡ _) k₁≡k₂ (p₁ , q₁) ≡⟨ push-subst-, _ _ ⟩
(subst (_ ≤_) k₁≡k₂ p₁ , subst (λ k → suc k ≡ _) k₁≡k₂ q₁) ≡⟨ cong₂ _,_ p-eq q-eq ⟩∎
(p₂ , q₂) ∎))
irr : ∀ {m n} → Is-proposition (m Nat.≤ n)
irr (≤-refl′ q₁) (≤-refl′ q₂) = cong ≤-refl′ $ ℕ-set q₁ q₂
irr (≤-refl′ q₁) (≤-step′ p₂ q₂) = ⊥-elim (lemma q₁ p₂ q₂)
irr (≤-step′ p₁ q₁) (≤-refl′ q₂) = ⊥-elim (lemma q₂ p₁ q₁)
irr {n = n} (≤-step′ {k = k₁} p₁ q₁)
(≤-step′ {k = k₂} p₂ q₂) =
cong-≤-step′ (cancel-suc (suc k₁ ≡⟨ q₁ ⟩
n ≡⟨ sym q₂ ⟩∎
suc k₂ ∎))
(irr _ p₂)
(ℕ-set _ _)
-- Nat.Distinct is not a family of contractible types.
¬-Distinct-contractible :
¬ (∀ m n → Contractible (Nat.Distinct m n))
¬-Distinct-contractible Distinct-contr =
proj₁ (Distinct-contr 0 0)
-- Distinct is a family of propositions.
Distinct-propositional : ∀ m n → Is-proposition (Distinct m n)
Distinct-propositional zero zero = ⊥-propositional
Distinct-propositional zero (suc n) = mono₁ 0 ⊤-contractible
Distinct-propositional (suc m) zero = mono₁ 0 ⊤-contractible
Distinct-propositional (suc m) (suc n) = Distinct-propositional m n
------------------------------------------------------------------------
-- Π-types
-- Closure of contractibility under Π A is logically equivalent to
-- having extensional equality for functions from A.
Π-closure-contractible⇔extensionality :
∀ {a b} {A : Type a} →
({B : A → Type b} →
(∀ x → Contractible (B x)) → Contractible ((x : A) → B x)) ⇔
({B : A → Type b} → Extensionality′ A B)
Π-closure-contractible⇔extensionality {b = b} {A} = record
{ to = ⇒
; from = λ ext cB →
((λ x → proj₁ (cB x)) , λ f → ext λ x → proj₂ (cB x) (f x))
}
where
⇒ : ({B : A → Type b} →
(∀ x → Contractible (B x)) → Contractible ((x : A) → B x)) →
(∀ {B} → Extensionality′ A B)
⇒ closure {B} {f} {g} f≡g =
f ≡⟨ sym (cong (λ c → λ x → proj₁ (c x)) $
proj₂ contractible (λ x → (f x , f≡g x))) ⟩
(λ x → proj₁ (proj₁ contractible x)) ≡⟨ cong (λ c → λ x → proj₁ (c x)) $
proj₂ contractible (λ x → (g x , refl (g x))) ⟩∎
g ∎
where
contractible : Contractible ((x : A) → Singleton (g x))
contractible = closure (singleton-contractible ∘ g)
abstract
-- Given (generalised) extensionality one can define an
-- extensionality proof which is well-behaved.
extensionality⇒well-behaved-extensionality :
∀ {a b} {A : Type a} →
({B : A → Type b} → Extensionality′ A B) →
{B : A → Type b} → Well-behaved-extensionality A B
extensionality⇒well-behaved-extensionality {A = A} ext {B} =
(λ {_} → ext′) , λ f →
ext′ (refl ∘ f) ≡⟨ trans-symˡ _ ⟩∎
refl f ∎
where
ext′ : Extensionality′ A B
ext′ = to (from ext)
where open _⇔_ Π-closure-contractible⇔extensionality
-- A potential inverse of extensionality. (See Equivalence for a proof
-- which shows that this function has an inverse, assuming
-- extensionality.)
ext⁻¹ : ∀ {a b} {A : Type a} {B : A → Type b} {f g : (x : A) → B x} →
f ≡ g → (∀ x → f x ≡ g x)
ext⁻¹ f≡g = λ x → cong (λ h → h x) f≡g
abstract
-- "Evaluation rule" for ext⁻¹.
ext⁻¹-refl : ∀ {a b} {A : Type a} {B : A → Type b}
(f : (x : A) → B x) {x} →
ext⁻¹ (refl f) x ≡ refl (f x)
ext⁻¹-refl f {x} = cong-refl (λ h → h x)
-- Given extensionality there is a (split) surjection from
-- ∀ x → f x ≡ g x to f ≡ g.
ext-surj : ∀ {a b} →
Extensionality a b →
{A : Type a} {B : A → Type b} {f g : (x : A) → B x} →
(∀ x → f x ≡ g x) ↠ (f ≡ g)
ext-surj {b = b} ext {A} {B} = record
{ logical-equivalence = record
{ to = to
; from = ext⁻¹
}
; right-inverse-of =
elim (λ {f g} f≡g → to (ext⁻¹ f≡g) ≡ f≡g) λ h →
proj₁ ext′ (ext⁻¹ (refl h)) ≡⟨ cong (proj₁ ext′) (proj₁ ext′ λ _ →
ext⁻¹-refl h) ⟩
proj₁ ext′ (refl ∘ h) ≡⟨ proj₂ ext′ h ⟩∎
refl h ∎
}
where
ext′ : {B : A → Type b} → Well-behaved-extensionality A B
ext′ = extensionality⇒well-behaved-extensionality (apply-ext ext)
to : {f g : (x : A) → B x} → (∀ x → f x ≡ g x) → f ≡ g
to = proj₁ ext′
-- H-level′ is closed under Π A (assuming extensionality).
Π-closure′ :
∀ {a b} {A : Type a} {B : A → Type b} →
Extensionality a b →
∀ n → (∀ x → H-level′ n (B x)) → H-level′ n ((x : A) → B x)
Π-closure′ ext zero =
_⇔_.from Π-closure-contractible⇔extensionality (apply-ext ext)
Π-closure′ ext (suc n) = λ h f g →
respects-surjection′ (ext-surj ext) n $
Π-closure′ ext n (λ x → h x (f x) (g x))
-- H-level is closed under Π A (assuming extensionality).
Π-closure : ∀ {a b} {A : Type a} {B : A → Type b} →
Extensionality a b →
∀ n → (∀ x → H-level n (B x)) → H-level n ((x : A) → B x)
Π-closure ext n h =
_⇔_.from H-level⇔H-level′ $
Π-closure′ ext n (λ x → _⇔_.to H-level⇔H-level′ (h x))
-- This also applies to the implicit function space.
implicit-Π-closure :
∀ {a b} {A : Type a} {B : A → Type b} →
Extensionality a b →
∀ n → (∀ x → H-level n (B x)) → H-level n ({x : A} → B x)
implicit-Π-closure ext n =
respects-surjection
(_↔_.surjection $ Bijection.inverse implicit-Π↔Π) n ∘
Π-closure ext n
abstract
-- Negated types are propositional, assuming extensionality.
¬-propositional :
∀ {a} {A : Type a} →
Extensionality a lzero →
Is-proposition (¬ A)
¬-propositional ext = Π-closure ext 1 (λ _ → ⊥-propositional)
-- The type ∀ y → x ≡ y is a proposition (assuming extensionality).
--
-- This is Lemma 4.1 from van Doorn's "Constructing the Propositional
-- Truncation using Non-recursive HITs" (perhaps the proof is not
-- quite identical to van Doorn's).
Π≡-proposition :
∀ {a} {A : Type a} →
Extensionality a a →
(x : A) → Is-proposition (∀ y → x ≡ y)
Π≡-proposition {A = A} ext x =
[inhabited⇒+]⇒+ 0 λ f →
let prop : Is-proposition A
prop u v =
u ≡⟨ sym (f u) ⟩
x ≡⟨ f v ⟩∎
v ∎
in
Π-closure ext 1 λ _ →
mono₁ 1 prop
------------------------------------------------------------------------
-- Σ-types
-- H-level′ is closed under Σ.
Σ-closure′ :
∀ {a b} {A : Type a} {B : A → Type b} n →
H-level′ n A → (∀ x → H-level′ n (B x)) → H-level′ n (Σ A B)
Σ-closure′ {A = A} {B} zero (x , irrA) hB =
((x , proj₁ (hB x)) , λ p →
(x , proj₁ (hB x)) ≡⟨ elim (λ {x y} _ → _≡_ {A = Σ A B} (x , proj₁ (hB x))
(y , proj₁ (hB y)))
(λ _ → refl _)
(irrA (proj₁ p)) ⟩
(proj₁ p , proj₁ (hB (proj₁ p))) ≡⟨ cong (_,_ (proj₁ p)) (proj₂ (hB (proj₁ p)) (proj₂ p)) ⟩∎
p ∎)
Σ-closure′ {B = B} (suc n) hA hB = λ p₁ p₂ →
respects-surjection′ (_↔_.surjection Σ-≡,≡↔≡) n $
Σ-closure′ n (hA (proj₁ p₁) (proj₁ p₂))
(λ pr₁p₁≡pr₁p₂ →
hB (proj₁ p₂) (subst B pr₁p₁≡pr₁p₂ (proj₂ p₁)) (proj₂ p₂))
-- H-level is closed under Σ.
Σ-closure : ∀ {a b} {A : Type a} {B : A → Type b} n →
H-level n A → (∀ x → H-level n (B x)) → H-level n (Σ A B)
Σ-closure n hA hB =
_⇔_.from H-level⇔H-level′
(Σ-closure′ n (_⇔_.to H-level⇔H-level′ hA)
(_⇔_.to H-level⇔H-level′ ∘ hB))
abstract
-- In the case of contractibility the codomain only needs to have
-- the right h-level (0) for a single index.
Σ-closure-contractible :
∀ {a b} {A : Type a} {B : A → Type b} →
(c : Contractible A) → Contractible (B (proj₁ c)) →
Contractible (Σ A B)
Σ-closure-contractible {B = B} cA (b , irrB) = Σ-closure 0 cA cB
where
cB : ∀ a → Contractible (B a)
cB a =
subst B (proj₂ cA a) b , λ b′ →
subst B (proj₂ cA a) b ≡⟨ cong (subst B (proj₂ cA a)) $
irrB (subst B (sym $ proj₂ cA a) b′) ⟩
subst B (proj₂ cA a) (subst B (sym $ proj₂ cA a) b′) ≡⟨ subst-subst-sym _ _ _ ⟩∎
b′ ∎
-- H-level is closed under _×_.
×-closure : ∀ {a b} {A : Type a} {B : Type b} n →
H-level n A → H-level n B → H-level n (A × B)
×-closure n hA hB = Σ-closure n hA (const hB)
-- If B a is inhabited for all a, and Σ A B has h-level n, then A
-- also has h-level n.
--
-- One cannot, in general, replace ∀ a → B a with ∀ a → ∥ B a ∥ (see
-- Circle.¬-generalised-proj₁-closure). However, this is possible if
-- B is constant (see H-level.Truncation.Propositional.H-level-×₁).
proj₁-closure :
∀ {a b} {A : Type a} {B : A → Type b} →
(∀ a → B a) →
∀ n → H-level n (Σ A B) → H-level n A
proj₁-closure {A = A} {B} inhabited = respects-surjection surj
where
surj : Σ A B ↠ A
surj = record
{ logical-equivalence = record
{ to = proj₁
; from = λ x → x , inhabited x
}
; right-inverse-of = refl
}
-- If A is inhabited and A × B has h-level n, then B also has
-- h-level n.
proj₂-closure :
∀ {a b} {A : Type a} {B : Type b} →
A →
∀ n → H-level n (A × B) → H-level n B
proj₂-closure {A = A} {B} inhabited = respects-surjection surj
where
surj : A × B ↠ B
surj = record
{ logical-equivalence = record
{ to = proj₂
; from = λ x → inhabited , x
}
; right-inverse-of = refl
}
------------------------------------------------------------------------
-- Logical equivalences, split surjections and bijections
-- H-level n is closed under the type formers _⇔_, _↠_ and _↔_
-- (assuming extensionality).
⇔-closure :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
∀ n → H-level n A → H-level n B → H-level n (A ⇔ B)
⇔-closure {a} {b} ext n hA hB =
respects-surjection
(record
{ logical-equivalence = record
{ to = _
; from = λ A⇔B → _⇔_.to A⇔B , _⇔_.from A⇔B
}
; right-inverse-of = λ _ → refl _
})
n
(×-closure n
(Π-closure (lower-extensionality b a ext) n (λ _ → hB))
(Π-closure (lower-extensionality a b ext) n (λ _ → hA)))
↠-closure :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
∀ n → H-level n A → H-level n B → H-level n (A ↠ B)
↠-closure {a} {b} ext n hA hB =
respects-surjection
(record
{ logical-equivalence = record
{ to = _
; from = λ A↠B → _↠_.logical-equivalence A↠B ,
_↠_.right-inverse-of A↠B
}
; right-inverse-of = λ _ → refl _
})
n
(Σ-closure n (⇔-closure ext n hA hB) λ _ →
Π-closure (lower-extensionality a a ext) n λ _ →
⇒≡ _ hB)
↔-closure :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
∀ n → H-level n A → H-level n B → H-level n (A ↔ B)
↔-closure {a} {b} ext n hA hB =
respects-surjection
(record
{ logical-equivalence = record
{ to = _
; from = λ A↔B → _↔_.surjection A↔B ,
_↔_.left-inverse-of A↔B
}
; right-inverse-of = λ _ → refl _
})
n
(Σ-closure n (↠-closure ext n hA hB) λ _ →
Π-closure (lower-extensionality b b ext) n λ _ →
⇒≡ _ hA)
------------------------------------------------------------------------
-- Lifted types
-- All H-levels are closed under lifting.
↑-closure : ∀ {a b} {A : Type a} n → H-level n A → H-level n (↑ b A)
↑-closure =
respects-surjection (_↔_.surjection (Bijection.inverse ↑↔))
-- All H-levels are also closed under removal of lifting.
↑⁻¹-closure : ∀ {a b} {A : Type a} n → H-level n (↑ b A) → H-level n A
↑⁻¹-closure = respects-surjection (_↔_.surjection ↑↔)
------------------------------------------------------------------------
-- W-types
-- W-types are isomorphic to Σ-types containing W-types.
W-unfolding : ∀ {a b} {A : Type a} {B : A → Type b} →
W A B ↔ ∃ λ (x : A) → B x → W A B
W-unfolding = record
{ surjection = record
{ logical-equivalence = record
{ to = λ w → headᵂ w , tailᵂ w
; from = uncurry sup
}
; right-inverse-of = refl
}
; left-inverse-of = left-inverse-of
}
where
left-inverse-of : (w : W _ _) → sup (headᵂ w) (tailᵂ w) ≡ w
left-inverse-of (sup x f) = refl (sup x f)
abstract
-- Equality between elements of a W-type can be proved using a pair
-- of equalities (assuming extensionality).
W-≡,≡↠≡ : ∀ {a b} {A : Type a} {B : A → Type b} →
Extensionality b (a ⊔ b) →
∀ {x y} {f : B x → W A B} {g : B y → W A B} →
(∃ λ (p : x ≡ y) → ∀ i → f i ≡ g (subst B p i)) ↠
(sup x f ≡ sup y g)
W-≡,≡↠≡ {a} {A = A} {B} ext {x} {y} {f} {g} =
(∃ λ (p : x ≡ y) → ∀ i → f i ≡ g (subst B p i)) ↠⟨ Surjection.∃-cong lemma ⟩
(∃ λ (p : x ≡ y) → subst (λ x → B x → W A B) p f ≡ g) ↠⟨ _↔_.surjection Σ-≡,≡↔≡ ⟩
(_≡_ {A = ∃ λ (x : A) → B x → W A B} (x , f) (y , g)) ↠⟨ ↠-≡ (_↔_.surjection (Bijection.inverse (W-unfolding {A = A} {B = B}))) ⟩□
(sup x f ≡ sup y g) □
where
lemma : (p : x ≡ y) →
(∀ i → f i ≡ g (subst B p i)) ↠
(subst (λ x → B x → W A B) p f ≡ g)
lemma p = elim
(λ {x y} p → (f : B x → W A B) (g : B y → W A B) →
(∀ i → f i ≡ g (subst B p i)) ↠
(subst (λ x → B x → W A B) p f ≡ g))
(λ x f g →
(∀ i → f i ≡ g (subst B (refl x) i)) ↠⟨ subst (λ h → (∀ i → f i ≡ g (h i)) ↠ (∀ i → f i ≡ g i))
(sym (apply-ext (lower-extensionality lzero a ext) (subst-refl B)))
Surjection.id ⟩
(∀ i → f i ≡ g i) ↠⟨ ext-surj ext ⟩
(f ≡ g) ↠⟨ subst (λ h → (f ≡ g) ↠ (h ≡ g))
(sym $ subst-refl (λ x' → B x' → W A B) f)
Surjection.id ⟩□
(subst (λ x → B x → W A B) (refl x) f ≡ g) □)
p f g
-- H-level is not closed under W.
¬-W-closure-contractible : ∀ {a b} →
¬ (∀ {A : Type a} {B : A → Type b} →
Contractible A → (∀ x → Contractible (B x)) →
Contractible (W A B))
¬-W-closure-contractible closure =
inhabited⇒W-empty (const (lift tt)) $
proj₁ $
closure (↑-closure 0 ⊤-contractible)
(const (↑-closure 0 ⊤-contractible))
¬-W-closure : ∀ {a b} →
¬ (∀ {A : Type a} {B : A → Type b} n →
H-level n A → (∀ x → H-level n (B x)) → H-level n (W A B))
¬-W-closure closure = ¬-W-closure-contractible (closure 0)
-- However, all positive h-levels are closed under W (assuming
-- extensionality).
W-closure′ :
∀ {a b} {A : Type a} {B : A → Type b} →
Extensionality b (a ⊔ b) →
∀ n → H-level′ (1 + n) A → H-level′ (1 + n) (W A B)
W-closure′ {A = A} {B} ext n h = closure
where
closure : (x y : W A B) → H-level′ n (x ≡ y)
closure (sup x f) (sup y g) =
respects-surjection′ (W-≡,≡↠≡ ext) n $
Σ-closure′ n (h x y) (λ _ →
Π-closure′ ext n (λ i → closure (f _) (g _)))
W-closure :
∀ {a b} {A : Type a} {B : A → Type b} →
Extensionality b (a ⊔ b) →
∀ n → H-level (1 + n) A → H-level (1 + n) (W A B)
W-closure ext n h =
_⇔_.from H-level⇔H-level′
(W-closure′ ext n (_⇔_.to H-level⇔H-level′ h))
------------------------------------------------------------------------
-- H-levels
abstract
-- Contractible is /not/ a comonad in the category of types and
-- functions, because map cannot be defined, but we can at least
-- define the following functions.
counit : ∀ {a} {A : Type a} → Contractible A → A
counit = proj₁
cojoin : ∀ {a} {A : Type a} →
Extensionality a a →
Contractible A → Contractible (Contractible A)
cojoin {A = A} ext contr = contr₃
where
x : A
x = proj₁ contr
contr₁ : Contractible (∀ y → x ≡ y)
contr₁ = Π-closure′ ext 0 (mono₁′ 0 contr x)
contr₂ : (x : A) → Contractible (∀ y → x ≡ y)
contr₂ x =
subst (λ x → Contractible (∀ y → x ≡ y)) (proj₂ contr x) contr₁
contr₃ : Contractible (∃ λ (x : A) → ∀ y → x ≡ y)
contr₃ = Σ-closure 0 contr contr₂
-- Contractible is not necessarily contractible.
¬-Contractible-contractible :
¬ ({A : Type} → Contractible (Contractible A))
¬-Contractible-contractible contr = proj₁ $ proj₁ $ contr {A = ⊥}
-- Contractible is propositional (assuming extensionality).
Contractible-propositional :
∀ {a} {A : Type a} →
Extensionality a a →
Is-proposition (Contractible A)
Contractible-propositional ext =
[inhabited⇒contractible]⇒propositional (cojoin ext)
-- H-level′ is closed under λ P → For-iterated-equality n P A.
H-level′-For-iterated-equality :
∀ {p A} {P : Type p → Type p} →
Extensionality p p →
∀ m n →
(∀ {A} → H-level′ m (P A)) →
H-level′ m (For-iterated-equality n P A)
H-level′-For-iterated-equality ext m zero hyp = hyp
H-level′-For-iterated-equality ext m (suc n) hyp =
Π-closure′ ext m λ _ →
Π-closure′ ext m λ _ →
H-level′-For-iterated-equality ext m n hyp
-- A variant of the previous result.
H-level′-For-iterated-equality′ :
∀ {p A} {P : Type p → Type p} →
Extensionality p p →
∀ m n {o} →
H-level′ (n + o) A →
(∀ {A} → H-level′ o A → H-level′ m (P A)) →
H-level′ m (For-iterated-equality n P A)
H-level′-For-iterated-equality′ ext m zero hyp₁ hyp₂ = hyp₂ hyp₁
H-level′-For-iterated-equality′ ext m (suc n) hyp₁ hyp₂ =
Π-closure′ ext m λ _ →
Π-closure′ ext m λ _ →
H-level′-For-iterated-equality′ ext m n (hyp₁ _ _) hyp₂
-- H-level is closed under λ P → For-iterated-equality n P A.
H-level-For-iterated-equality :
∀ {p A} {P : Type p → Type p} →
Extensionality p p →
∀ m n →
(∀ {A} → H-level m (P A)) →
H-level m (For-iterated-equality n P A)
H-level-For-iterated-equality ext m n hyp =
_⇔_.from H-level⇔H-level′ $
H-level′-For-iterated-equality ext m n $
_⇔_.to H-level⇔H-level′ hyp
-- A variant of the previous result.
H-level-For-iterated-equality′ :
∀ {p A} {P : Type p → Type p} →
Extensionality p p →
∀ m n {o} →
H-level (n + o) A →
(∀ {A} → H-level o A → H-level m (P A)) →
H-level m (For-iterated-equality n P A)
H-level-For-iterated-equality′ ext m n hyp₁ hyp₂ =
_⇔_.from (H-level⇔H-level′ {n = m}) $
H-level′-For-iterated-equality′ ext m n
(_⇔_.to H-level⇔H-level′ hyp₁)
(_⇔_.to H-level⇔H-level′ ∘ hyp₂ ∘ _⇔_.from H-level⇔H-level′)
-- H-level′ is pointwise propositional (assuming extensionality).
H-level′-propositional :
∀ {a} → Extensionality a a →
∀ {A : Type a} n → Is-proposition (H-level′ n A)
H-level′-propositional ext n =
_⇔_.from (H-level⇔H-level′ {n = 1}) $
H-level′-For-iterated-equality ext 1 n $
_⇔_.to (H-level⇔H-level′ {n = 1}) $
Contractible-propositional ext
-- The property Is-proposition A is a proposition (assuming
-- extensionality).
--
-- This result is proved in the HoTT book (first edition,
-- Lemma 3.3.5).
Is-proposition-propositional :
∀ {a} {A : Type a} → Extensionality a a →
Is-proposition (Is-proposition A)
Is-proposition-propositional ext = [inhabited⇒+]⇒+ 0 λ p →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
⇒≡ 1 p
-- All h-levels are propositional (assuming extensionality).
H-level-propositional :
∀ {a} → Extensionality a a →
∀ {A : Type a} n → Is-proposition (H-level n A)
H-level-propositional ext zero =
Contractible-propositional ext
H-level-propositional ext (suc zero) =
Is-proposition-propositional ext
H-level-propositional {A} ext (suc (suc n)) =
implicit-Π-closure ext 1 λ x →
implicit-Π-closure ext 1 λ y →
H-level-propositional ext {A = x ≡ y} (suc n)
-- Uniqueness-of-identity-proofs is pointwise propositional
-- (assuming extensionality).
UIP-propositional :
∀ {ℓ} → Extensionality (lsuc ℓ) ℓ →
Is-proposition (Uniqueness-of-identity-proofs ℓ)
UIP-propositional ext =
implicit-Π-closure ext 1 λ A →
H-level-propositional (lower-extensionality _ lzero ext) 2
------------------------------------------------------------------------
-- Binary sums
abstract
-- Binary sums can be expressed using Σ and Bool (with large
-- elimination).
sum-as-pair : ∀ {a b} {A : Type a} {B : Type b} →
(A ⊎ B) ↔ (∃ λ (x : Bool) → if x then ↑ b A else ↑ a B)
sum-as-pair {a} {b} {A} {B} = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = [ refl ∘ inj₁ {B = B} , refl ∘ inj₂ {A = A} ]
}
where
to : A ⊎ B → (∃ λ (x : Bool) → if x then ↑ b A else ↑ a B)
to = [ _,_ true ∘ lift , _,_ false ∘ lift ]
from : (∃ λ (x : Bool) → if x then ↑ b A else ↑ a B) → A ⊎ B
from (true , x) = inj₁ $ lower x
from (false , y) = inj₂ $ lower y
to∘from : (y : ∃ λ x → if x then ↑ b A else ↑ a B) →
to (from y) ≡ y
to∘from (true , x) = refl _
to∘from (false , y) = refl _
-- H-level is not closed under _⊎_.
¬-⊎-propositional : ∀ {a b} {A : Type a} {B : Type b} →
A → B → ¬ Is-proposition (A ⊎ B)
¬-⊎-propositional x y hA⊎B = ⊎.inj₁≢inj₂ $ hA⊎B (inj₁ x) (inj₂ y)
¬-⊎-closure : ∀ {a b} →
¬ (∀ {A : Type a} {B : Type b} n →
H-level n A → H-level n B → H-level n (A ⊎ B))
¬-⊎-closure ⊎-closure =
¬-⊎-propositional (lift tt) (lift tt) $
mono₁ 0 $
⊎-closure 0 (↑-closure 0 ⊤-contractible)
(↑-closure 0 ⊤-contractible)
-- However, all levels greater than or equal to 2 are closed under
-- _⊎_.
⊎-closure :
∀ {a b} {A : Type a} {B : Type b} n →
H-level (2 + n) A → H-level (2 + n) B → H-level (2 + n) (A ⊎ B)
⊎-closure {a} {b} {A} {B} n hA hB =
respects-surjection
(_↔_.surjection $ Bijection.inverse sum-as-pair)
(2 + n)
(Σ-closure (2 + n) Bool-2+n if-2+n)
where
Bool-2+n : H-level (2 + n) Bool
Bool-2+n = mono (m≤m+n 2 n) Bool-set
if-2+n : (x : Bool) → H-level (2 + n) (if x then ↑ b A else ↑ a B)
if-2+n true = respects-surjection
(_↔_.surjection $ Bijection.inverse ↑↔)
(2 + n) hA
if-2+n false = respects-surjection
(_↔_.surjection $ Bijection.inverse ↑↔)
(2 + n) hB
-- Furthermore, if A and B are propositions and mutually exclusive,
-- then A ⊎ B is a proposition.
⊎-closure-propositional :
∀ {a b} {A : Type a} {B : Type b} →
(A → B → ⊥₀) →
Is-proposition A → Is-proposition B → Is-proposition (A ⊎ B)
⊎-closure-propositional A→B→⊥ A-prop B-prop = λ where
(inj₁ a₁) (inj₁ a₂) → cong inj₁ (A-prop a₁ a₂)
(inj₁ a₁) (inj₂ b₂) → ⊥-elim (A→B→⊥ a₁ b₂)
(inj₂ b₁) (inj₁ a₂) → ⊥-elim (A→B→⊥ a₂ b₁)
(inj₂ b₁) (inj₂ b₂) → cong inj₂ (B-prop b₁ b₂)
-- All levels greater than or equal to 2 are also closed under
-- Maybe.
Maybe-closure :
∀ {a} {A : Type a} n →
H-level (2 + n) A → H-level (2 + n) (Maybe A)
Maybe-closure n h =
⊎-closure n (mono (zero≤ (2 + n)) ⊤-contractible) h
-- T is pointwise propositional.
T-propositional :
∀ {a b} {A : Type a} {B : Type b} →
(x : A ⊎ B) → Is-proposition (T x)
T-propositional (inj₁ _) = mono₁ 0 ⊤-contractible
T-propositional (inj₂ _) = ⊥-propositional
-- Furthermore Is-proposition is closed under Dec (assuming
-- extensionality).
Dec-closure-propositional :
∀ {a} {A : Type a} →
Extensionality a lzero →
Is-proposition A → Is-proposition (Dec A)
Dec-closure-propositional {A = A} ext p = λ where
(yes a) (yes a′) → cong yes $ p a a′
(yes a) (no ¬a) → ⊥-elim (¬a a)
(no ¬a) (yes a) → ⊥-elim (¬a a)
(no ¬a) (no ¬a′) → cong no $ ¬-propositional ext ¬a ¬a′
-- Is-proposition is also closed under _Xor_ (assuming
-- extensionality).
Xor-closure-propositional :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (# 0) →
Is-proposition A → Is-proposition B →
Is-proposition (A Xor B)
Xor-closure-propositional {ℓa} {ℓb} {A} {B} ext pA pB = λ where
(inj₁ (a , ¬b)) (inj₂ (¬a , b)) → ⊥-elim (¬a a)
(inj₂ (¬a , b)) (inj₁ (a , ¬b)) → ⊥-elim (¬b b)
(inj₁ (a , ¬b)) (inj₁ (a′ , ¬b′)) →
cong₂ (λ x y → inj₁ (x , y))
(pA a a′)
(apply-ext (lower-extensionality ℓa _ ext) λ b → ⊥-elim (¬b b))
(inj₂ (¬a , b)) (inj₂ (¬a′ , b′)) →
cong₂ (λ x y → inj₂ (x , y))
(apply-ext (lower-extensionality ℓb _ ext) λ a → ⊥-elim (¬a a))
(pB b b′)
-- However, H-level is not closed under _Xor_.
¬-Xor-closure-contractible : ∀ {a b} →
¬ ({A : Type a} {B : Type b} →
Contractible A → Contractible B → Contractible (A Xor B))
¬-Xor-closure-contractible closure
with proj₁ $ closure (↑-closure 0 ⊤-contractible)
(↑-closure 0 ⊤-contractible)
... | inj₁ (_ , ¬⊤) = ¬⊤ _
... | inj₂ (¬⊤ , _) = ¬⊤ _
-- Alternative definition of ⊎-closure (for Type₀).
module Alternative-proof where
-- Is-set is closed under _⊎_, by an argument similar to the one
-- Hedberg used to prove that decidable equality implies
-- uniqueness of identity proofs.
⊎-closure-set : {A B : Type} →
Is-set A → Is-set B → Is-set (A ⊎ B)
⊎-closure-set {A} {B} A-set B-set = DUIP.constant⇒set c
where
c : (x y : A ⊎ B) → ∃ λ (f : x ≡ y → x ≡ y) → DUIP.Constant f
c (inj₁ x) (inj₁ y) = (cong inj₁ ∘ ⊎.cancel-inj₁ , λ p q → cong (cong inj₁) $ A-set (⊎.cancel-inj₁ p) (⊎.cancel-inj₁ q))
c (inj₂ x) (inj₂ y) = (cong inj₂ ∘ ⊎.cancel-inj₂ , λ p q → cong (cong inj₂) $ B-set (⊎.cancel-inj₂ p) (⊎.cancel-inj₂ q))
c (inj₁ x) (inj₂ y) = (⊥-elim ∘ ⊎.inj₁≢inj₂ , λ _ → ⊥-elim ∘ ⊎.inj₁≢inj₂)
c (inj₂ x) (inj₁ y) = (⊥-elim ∘ ⊎.inj₁≢inj₂ ∘ sym , λ _ → ⊥-elim ∘ ⊎.inj₁≢inj₂ ∘ sym)
-- H-level is closed under _⊎_ for other levels greater than or equal
-- to 2 too.
⊎-closure′ :
∀ {A B : Type} n →
H-level (2 + n) A → H-level (2 + n) B → H-level (2 + n) (A ⊎ B)
⊎-closure′ zero = ⊎-closure-set
⊎-closure′ {A} {B} (suc n) = clos
where
clos : H-level (3 + n) A → H-level (3 + n) B → H-level (3 + n) (A ⊎ B)
clos hA hB {x = inj₁ x} {y = inj₁ y} = respects-surjection (_↔_.surjection ≡↔inj₁≡inj₁) (2 + n) hA
clos hA hB {x = inj₂ x} {y = inj₂ y} = respects-surjection (_↔_.surjection ≡↔inj₂≡inj₂) (2 + n) hB
clos hA hB {x = inj₁ x} {y = inj₂ y} {x = p} = ⊥-elim (⊎.inj₁≢inj₂ p)
clos hA hB {x = inj₂ x} {y = inj₁ y} {x = p} = ⊥-elim (⊎.inj₁≢inj₂ (sym p))
| {
"alphanum_fraction": 0.5049990386,
"avg_line_length": 34.1422319475,
"ext": "agda",
"hexsha": "bdc3ce21717fa026124c87240070d5afdeebdf69",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/H-level/Closure.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/H-level/Closure.agda",
"max_line_length": 135,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/H-level/Closure.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 11584,
"size": 31206
} |
open import Coinduction using ( ∞ ; ♭ ; ♯_ )
open import Data.Bool using ( Bool ; true ; false )
open import Data.Empty using ( ⊥ ; ⊥-elim )
open import Data.Unit using ( ⊤ ; tt )
open import System.IO.Transducers.Lazy using
( _⇒_ ; inp ; out ; done ; choice ) renaming
( ⟦_⟧ to ⟦_⟧' ; _⟫_ to _⟫'_
; _[&]_ to _[&]'_ ; _⟨&⟩_ to _⟨&⟩'_ ; assoc to assoc' )
open import System.IO.Transducers.Session using ( Session ; I ; Σ ; Γ ; _/_ ; IsΣ ; ⟨_⟩ ; _&_ ; ¿ ; _⊕_ )
open import System.IO.Transducers.Trace using ( Trace ; [] ; _∷_ )
module System.IO.Transducers.Strict where
infixr 4 _⇛_
infixr 6 _⟫_
infixr 8 _[&]_ _⟨&⟩_
-- Strict tranducers are ones which perform input before any output
data Strict : ∀ {S T} → (S ⇒ T) → Set₁ where
inp : ∀ {A V F T} P → (Strict (inp {A} {V} {F} {T} P))
done : ∀ {S} → (Strict (done {S}))
-- Slightly annoyingly, _≡_ has different cardinalities
-- in different versions of the standard library.
-- Until 1.4 of agda-stdlib is more widely distributed,
-- we define a specialized version of _≡_ here.
data _≡_ (S : Session) : Session → Set₁ where
refl : S ≡ S
-- S ⇛ T is the type of strict transducers regarded as functions
_⇛_ : Session → Session → Set₁
I ⇛ T = I ≡ T
Σ V F ⇛ T = ∀ a → (♭ F a) ⇒ T
-- Identity transducer
id : ∀ {S} → S ⇛ S
id {I} = refl
id {Σ V F} = λ a → out a done
-- Inclusion of strict in lazy transducers
ι : ∀ {S T} → (S ⇛ T) → (S ⇒ T)
ι {I} refl = done
ι {Σ V F} P = inp (♯ P)
-- Composition
_⟫_ : ∀ {S T U} → (S ⇛ T) → (T ⇛ U) → (S ⇛ U)
_⟫_ {I} refl refl = refl
_⟫_ {Σ V F} {I} P refl = P
_⟫_ {Σ V F} {Σ W G} P Q = λ a → (P a ⟫' ι Q)
-- & on transducers
_[&]_ : ∀ {S T U V} → (S ⇛ T) → (U ⇛ V) → ((S & U) ⇛ (T & V))
_[&]_ {I} refl Q = Q
_[&]_ {Σ V F} P Q = λ a → (P a [&]' ι Q)
-- Associativity of &
assoc : ∀ {S T U} → ((S & (T & U)) ⇛ ((S & T) & U))
assoc {I} {T} {U} = id {T & U}
assoc {Σ V F} {T} {U} = λ a → out a (assoc' {♭ F a})
-- Mediating morphism for &
_⟨&⟩_ : ∀ {S T U} → (S ⇛ T) → (S ⇛ U) → (S ⇛ T & U)
_⟨&⟩_ {I} refl refl = refl
_⟨&⟩_ {Σ V F} P Q = λ a → (P a ⟨&⟩' Q a)
| {
"alphanum_fraction": 0.5262417994,
"avg_line_length": 28.8378378378,
"ext": "agda",
"hexsha": "aca561faa819f1b2986bcad84c7acd125bb341b4",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z",
"max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ilya-fiveisky/agda-system-io",
"max_forks_repo_path": "src/System/IO/Transducers/Strict.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ilya-fiveisky/agda-system-io",
"max_issues_repo_path": "src/System/IO/Transducers/Strict.agda",
"max_line_length": 105,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ilya-fiveisky/agda-system-io",
"max_stars_repo_path": "src/System/IO/Transducers/Strict.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z",
"num_tokens": 907,
"size": 2134
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import stash.modalities.gbm.GbmUtil
module stash.modalities.gbm.PullbackSplit where
-- L --> B K = A ×_D C / (f,h) d₁ = A -> D <- C
-- | |g L = B ×_A K / (g,left) d₂ = B -> A <- K
-- v v d = B -> D <- C
-- K --> A
-- | |f
-- v v
-- C --> D
-- h
module PullbackLSplit {i j k l} {A : Type i} {B : Type j} {C : Type k}
{D : Type l} (f : A → D) (g : B → A) (h : C → D) where
private
d₁ : Cospan
d₁ = cospan C A D h f
d₂ : Cospan
d₂ = cospan (Pullback d₁) B A Pullback.b g
d : Cospan
d = cospan C B D h (f ∘ g)
split-equiv : Pullback d ≃ Pullback d₂
split-equiv = equiv to from to-from from-to
where to : Pullback d → Pullback d₂
to (pullback c b p) = pullback (pullback c (g b) p) b idp
from : Pullback d₂ → Pullback d
from (pullback (pullback c a p) b idp) = pullback c b p
to-from : (x : Pullback d₂) → to (from x) == x
to-from (pullback _ b idp) = idp
from-to : (x : Pullback d) → from (to x) == x
from-to _ = idp
record CospanMap {i₀ j₀ k₀ i₁ j₁ k₁} (cospan₀ : Cospan {i₀} {j₀} {k₀}) (cospan₁ : Cospan {i₁} {j₁} {k₁})
: Type (lmax (lmax (lmax i₀ j₀) k₀) (lmax (lmax i₁ j₁) k₁)) where
constructor cospan-map
module cospan₀ = Cospan cospan₀
module cospan₁ = Cospan cospan₁
field
hA : cospan₀.A → cospan₁.A
hB : cospan₀.B → cospan₁.B
hC : cospan₀.C → cospan₁.C
f-commutes : CommSquare cospan₀.f cospan₁.f hA hC
g-commutes : CommSquare cospan₀.g cospan₁.g hB hC
CospanEquiv : ∀ {i₀ j₀ k₀ i₁ j₁ k₁} (cospan₀ : Cospan {i₀} {j₀} {k₀}) (cospan₁ : Cospan {i₁} {j₁} {k₁})
→ Type (lmax (lmax (lmax i₀ j₀) k₀) (lmax (lmax i₁ j₁) k₁))
CospanEquiv cospan₀ cospan₁ = Σ (CospanMap cospan₀ cospan₁)
(λ cospan-map → is-equiv (CospanMap.hA cospan-map)
× is-equiv (CospanMap.hB cospan-map)
× is-equiv (CospanMap.hC cospan-map))
CospanEquiv-inverse : ∀ {i₀ j₀ k₀ i₁ j₁ k₁} {cospan₀ : Cospan {i₀} {j₀} {k₀}} {cospan₁ : Cospan {i₁} {j₁} {k₁}}
→ CospanEquiv cospan₀ cospan₁ → CospanEquiv cospan₁ cospan₀
CospanEquiv-inverse (cospan-map hA hB hC f-commutes g-commutes , hA-ise , hB-ise , hC-ise)
= (cospan-map hA.g hB.g hC.g
(CommSquare-inverse-v f-commutes hA-ise hC-ise)
(CommSquare-inverse-v g-commutes hB-ise hC-ise))
, ( is-equiv-inverse hA-ise
, is-equiv-inverse hB-ise
, is-equiv-inverse hC-ise)
where module hA = is-equiv hA-ise
module hB = is-equiv hB-ise
module hC = is-equiv hC-ise
module PullbackFmap {i₀ j₀ k₀ i₁ j₁ k₁} {cospan₀ : Cospan {i₀} {j₀} {k₀}}
{cospan₁ : Cospan {i₁} {j₁} {k₁}} (cospan-map : CospanMap cospan₀ cospan₁) where
f : Pullback cospan₀ → Pullback cospan₁
f (pullback a b h) = pullback
(CospanMap.hA cospan-map a)
(CospanMap.hB cospan-map b)
(! (commutes (CospanMap.f-commutes cospan-map) a) ∙
ap (λ x → CospanMap.hC cospan-map x) h ∙
(commutes (CospanMap.g-commutes cospan-map) b))
Pullback-fmap = PullbackFmap.f
module _ {i₀ j₀ k₀ i₁ j₁ k₁} {cospan₀ : Cospan {i₀} {j₀} {k₀}}
{cospan₁ : Cospan {i₁} {j₁} {k₁}} (cospan-equiv : CospanEquiv cospan₀ cospan₁) where
private
module cospan₀ = Cospan cospan₀
module cospan₁ = Cospan cospan₁
cospan-to = fst cospan-equiv
cospan-from = fst (CospanEquiv-inverse cospan-equiv)
module cospan-to = CospanMap cospan-to
module cospan-from = CospanMap cospan-from
module To = PullbackFmap cospan-to
module From = PullbackFmap cospan-from
cospan-ise = snd cospan-equiv
hA-ise = fst cospan-ise
hB-ise = fst (snd cospan-ise)
hC-ise = snd (snd cospan-ise)
module hA-ise = is-equiv hA-ise
module hB-ise = is-equiv hB-ise
module hC-ise = is-equiv hC-ise
f = cospan₀.f
g = cospan₀.g
f' = cospan₁.f
g' = cospan₁.g
α = commutes cospan-to.f-commutes
β = commutes cospan-to.g-commutes
α' = commutes cospan-from.f-commutes
β' = commutes cospan-from.g-commutes
hA = cospan-to.hA
hB = cospan-to.hB
hC = cospan-to.hC
kA = cospan-from.hA
kB = cospan-from.hB
kC = cospan-from.hC
module kA-ise = is-equiv (is-equiv-inverse hA-ise)
module kB-ise = is-equiv (is-equiv-inverse hB-ise)
module kC-ise = is-equiv (is-equiv-inverse hC-ise)
kA-ise = is-equiv-inverse hA-ise
kB-ise = is-equiv-inverse hB-ise
kC-ise = is-equiv-inverse hC-ise
to = To.f
from = From.f
from-to : ∀ x → from (to x) == x
from-to (pullback a b h) = pullback= _ (hA-ise.g-f a) (hB-ise.g-f b) goal
where eq₀ = hC-ise.g-f (f a) ∙ h ∙ ! (hC-ise.g-f (g b))
=⟨ ! (ap-idf h) |in-ctx (λ x → hC-ise.g-f (f a) ∙ x ∙ ! (hC-ise.g-f (g b))) ⟩
hC-ise.g-f (f a) ∙ ap (idf _) h ∙ ! (hC-ise.g-f (g b))
=⟨ ! (∙-assoc (hC-ise.g-f (f a)) _ _) ⟩
(hC-ise.g-f (f a) ∙ ap (idf _) h) ∙ ! (hC-ise.g-f (g b))
=⟨ ↓-==-out (apd hC-ise.g-f h) |in-ctx (λ x → x ∙ ! (hC-ise.g-f (g b))) ⟩
(ap (kC ∘ hC) h ∙ hC-ise.g-f (g b)) ∙ ! (hC-ise.g-f (g b))
=⟨ ∙-assoc (ap (kC ∘ hC) h) _ _ ⟩
ap (kC ∘ hC) h ∙ hC-ise.g-f (g b) ∙ ! (hC-ise.g-f (g b))
=⟨ !-inv-r (hC-ise.g-f (g b)) |in-ctx (λ x → ap (kC ∘ hC) h ∙ x) ⟩
ap (kC ∘ hC) h ∙ idp
=⟨ ∙-unit-r (ap (kC ∘ hC) h) ⟩
ap (kC ∘ hC) h ∎
eq₁ = β' (hB b)
=⟨ ! (hB-ise.adj b) |in-ctx (λ x → ap kC (! (β (kB (hB b)) ∙ ap g' x)) ∙ hC-ise.g-f (g (kB (hB b)))) ⟩
ap kC (! (β (kB (hB b)) ∙ ap g' (ap hB (hB-ise.g-f b)))) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ ∘-ap g' hB (hB-ise.g-f b) |in-ctx (λ x → ap kC (! (β (kB (hB b)) ∙ x)) ∙ hC-ise.g-f (g (kB (hB b)))) ⟩
ap kC (! (β (kB (hB b)) ∙ ap (g' ∘ hB) (hB-ise.g-f b))) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ ↓-==-out (apd β (hB-ise.g-f b)) |in-ctx (λ x → ap kC (! x) ∙ hC-ise.g-f (g (kB (hB b)))) ⟩
ap kC (! (ap (hC ∘ g) (hB-ise.g-f b) ∙ β b)) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ ap-! kC (ap (hC ∘ g) (hB-ise.g-f b) ∙ β b) |in-ctx (λ x → x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩
! (ap kC (ap (hC ∘ g) (hB-ise.g-f b) ∙ β b)) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ ap-∙ kC (ap (hC ∘ g) (hB-ise.g-f b)) (β b) |in-ctx (λ x → ! x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩
! (ap kC (ap (hC ∘ g) (hB-ise.g-f b)) ∙ ap kC (β b)) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ !-∙ (ap kC (ap (hC ∘ g) (hB-ise.g-f b))) (ap kC (β b)) |in-ctx (λ x → x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩
(! (ap kC (β b)) ∙ ! (ap kC (ap (hC ∘ g) (hB-ise.g-f b)))) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ ∙-assoc (! (ap kC (β b))) _ _ ⟩
! (ap kC (β b)) ∙ ! (ap kC (ap (hC ∘ g) (hB-ise.g-f b))) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ ∘-ap kC (hC ∘ g) (hB-ise.g-f b) |in-ctx (λ x → ! (ap kC (β b)) ∙ ! x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩
! (ap kC (β b)) ∙ ! (ap (kC ∘ hC ∘ g) (hB-ise.g-f b)) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ ! (∘-ap (kC ∘ hC) g (hB-ise.g-f b)) |in-ctx (λ x → ! (ap kC (β b)) ∙ ! x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩
! (ap kC (β b)) ∙ ! (ap (kC ∘ hC) (ap g (hB-ise.g-f b))) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ eqv-square' (hC , hC-ise) (ap g (hB-ise.g-f b)) |in-ctx (λ x → ! (ap kC (β b)) ∙ ! x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩
! (ap kC (β b)) ∙ ! (hC-ise.g-f (g (kB (hB b))) ∙ (ap g (hB-ise.g-f b)) ∙ ! (hC-ise.g-f (g b))) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ !-∙ (hC-ise.g-f (g (kB (hB b)))) ((ap g (hB-ise.g-f b)) ∙ ! (hC-ise.g-f (g b))) |in-ctx (λ x → ! (ap kC (β b)) ∙ x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩
! (ap kC (β b)) ∙ (! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b))) ∙ ! (hC-ise.g-f (g (kB (hB b))))) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ ∙-assoc (! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b)))) _ _ |in-ctx (λ x → ! (ap kC (β b)) ∙ x) ⟩
! (ap kC (β b)) ∙ ! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b))) ∙ ! (hC-ise.g-f (g (kB (hB b)))) ∙ hC-ise.g-f (g (kB (hB b)))
=⟨ !-inv-l (hC-ise.g-f (g (kB (hB b)))) |in-ctx (λ x → ! (ap kC (β b)) ∙ ! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b))) ∙ x) ⟩
! (ap kC (β b)) ∙ ! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b))) ∙ idp
=⟨ ∙-unit-r (! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b)))) |in-ctx (λ x → ! (ap kC (β b)) ∙ x) ⟩
! (ap kC (β b)) ∙ ! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b)))
=⟨ !-∙ (ap g (hB-ise.g-f b)) (! (hC-ise.g-f (g b))) |in-ctx (λ x → ! (ap kC (β b)) ∙ x) ⟩
! (ap kC (β b)) ∙ ! (! (hC-ise.g-f (g b))) ∙ ! (ap g (hB-ise.g-f b))
=⟨ !-! (hC-ise.g-f (g b)) |in-ctx (λ x → ! (ap kC (β b)) ∙ x ∙ ! (ap g (hB-ise.g-f b))) ⟩
! (ap kC (β b)) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b)) ∎
eq₂ = α' (hA a)
=⟨ ! (hA-ise.adj a) |in-ctx (λ x → ap kC (! (α (kA (hA a)) ∙ ap f' x)) ∙ hC-ise.g-f (f (kA (hA a)))) ⟩
ap kC (! (α (kA (hA a)) ∙ ap f' (ap hA (hA-ise.g-f a)))) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ ∘-ap f' hA (hA-ise.g-f a) |in-ctx (λ x → ap kC (! (α (kA (hA a)) ∙ x)) ∙ hC-ise.g-f (f (kA (hA a)))) ⟩
ap kC (! (α (kA (hA a)) ∙ ap (f' ∘ hA) (hA-ise.g-f a))) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ ↓-==-out (apd α (hA-ise.g-f a)) |in-ctx (λ x → ap kC (! x) ∙ hC-ise.g-f (f (kA (hA a)))) ⟩
ap kC (! (ap (hC ∘ f) (hA-ise.g-f a) ∙ α a)) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ ap-! kC (ap (hC ∘ f) (hA-ise.g-f a) ∙ α a) |in-ctx (λ x → x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩
! (ap kC (ap (hC ∘ f) (hA-ise.g-f a) ∙ α a)) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ ap-∙ kC (ap (hC ∘ f) (hA-ise.g-f a)) (α a) |in-ctx (λ x → ! x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩
! (ap kC (ap (hC ∘ f) (hA-ise.g-f a)) ∙ ap kC (α a)) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ !-∙ (ap kC (ap (hC ∘ f) (hA-ise.g-f a))) (ap kC (α a)) |in-ctx (λ x → x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩
(! (ap kC (α a)) ∙ ! (ap kC (ap (hC ∘ f) (hA-ise.g-f a)))) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ ∙-assoc (! (ap kC (α a))) _ _ ⟩
! (ap kC (α a)) ∙ ! (ap kC (ap (hC ∘ f) (hA-ise.g-f a))) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ ∘-ap kC (hC ∘ f) (hA-ise.g-f a) |in-ctx (λ x → ! (ap kC (α a)) ∙ ! x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩
! (ap kC (α a)) ∙ ! (ap (kC ∘ hC ∘ f) (hA-ise.g-f a)) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ ! (∘-ap (kC ∘ hC) f (hA-ise.g-f a)) |in-ctx (λ x → ! (ap kC (α a)) ∙ ! x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩
! (ap kC (α a)) ∙ ! (ap (kC ∘ hC) (ap f (hA-ise.g-f a))) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ eqv-square' (hC , hC-ise) (ap f (hA-ise.g-f a)) |in-ctx (λ x → ! (ap kC (α a)) ∙ ! x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩
! (ap kC (α a)) ∙ ! (hC-ise.g-f (f (kA (hA a))) ∙ (ap f (hA-ise.g-f a)) ∙ ! (hC-ise.g-f (f a))) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ !-∙ (hC-ise.g-f (f (kA (hA a)))) ((ap f (hA-ise.g-f a)) ∙ ! (hC-ise.g-f (f a))) |in-ctx (λ x → ! (ap kC (α a)) ∙ x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩
! (ap kC (α a)) ∙ (! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a))) ∙ ! (hC-ise.g-f (f (kA (hA a))))) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ ∙-assoc (! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a)))) _ _ |in-ctx (λ x → ! (ap kC (α a)) ∙ x) ⟩
! (ap kC (α a)) ∙ ! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a))) ∙ ! (hC-ise.g-f (f (kA (hA a)))) ∙ hC-ise.g-f (f (kA (hA a)))
=⟨ !-inv-l (hC-ise.g-f (f (kA (hA a)))) |in-ctx (λ x → ! (ap kC (α a)) ∙ ! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a))) ∙ x) ⟩
! (ap kC (α a)) ∙ ! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a))) ∙ idp
=⟨ ∙-unit-r (! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a)))) |in-ctx (λ x → ! (ap kC (α a)) ∙ x) ⟩
! (ap kC (α a)) ∙ ! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a)))
=⟨ !-∙ (ap f (hA-ise.g-f a)) (! (hC-ise.g-f (f a))) |in-ctx (λ x → ! (ap kC (α a)) ∙ x) ⟩
! (ap kC (α a)) ∙ ! (! (hC-ise.g-f (f a))) ∙ ! (ap f (hA-ise.g-f a))
=⟨ !-! (hC-ise.g-f (f a)) |in-ctx (λ x → ! (ap kC (α a)) ∙ x ∙ ! (ap f (hA-ise.g-f a))) ⟩
! (ap kC (α a)) ∙ hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a)) ∎
lem = ! (α' (hA a)) ∙ ap kC (! (α a) ∙ ap hC h ∙ β b) ∙ β' (hB b)
=⟨ ap-∙ kC (! (α a)) (ap hC h ∙ β b) |in-ctx (λ x → ! (α' (hA a)) ∙ x ∙ β' (hB b)) ⟩
! (α' (hA a)) ∙ (ap kC (! (α a)) ∙ ap kC (ap hC h ∙ β b)) ∙ β' (hB b)
=⟨ ∙-assoc (ap kC (! (α a))) (ap kC (ap hC h ∙ β b)) (β' (hB b)) |in-ctx (λ x → ! (α' (hA a)) ∙ x) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap kC (ap hC h ∙ β b) ∙ β' (hB b)
=⟨ ap-∙ kC (ap hC h) (β b) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x ∙ β' (hB b)) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (ap kC (ap hC h) ∙ ap kC (β b)) ∙ β' (hB b)
=⟨ ∙-assoc (ap kC (ap hC h)) (ap kC (β b)) (β' (hB b)) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap kC (ap hC h) ∙ ap kC (β b) ∙ β' (hB b)
=⟨ ∘-ap kC hC h |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x ∙ ap kC (β b) ∙ β' (hB b)) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ ap kC (β b) ∙ β' (hB b)
=⟨ eq₁ |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ ap kC (β b) ∙ x) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ ap kC (β b) ∙ ! (ap kC (β b)) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))
=⟨ ! (∙-assoc (ap kC (β b)) _ _) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ x) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ (ap kC (β b) ∙ ! (ap kC (β b))) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))
=⟨ !-inv-r (ap kC (β b)) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ x ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))
=⟨ ! eq₀ |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h ∙ ! (hC-ise.g-f (g b))) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))
=⟨ ! (∙-assoc (hC-ise.g-f (f a)) _ _) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ((hC-ise.g-f (f a) ∙ h) ∙ ! (hC-ise.g-f (g b))) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))
=⟨ ∙-assoc (hC-ise.g-f (f a) ∙ h) _ _ |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h) ∙ ! (hC-ise.g-f (g b)) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))
=⟨ ! (∙-assoc (! (hC-ise.g-f (g b))) _ _) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h) ∙ x) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h) ∙ (! (hC-ise.g-f (g b)) ∙ hC-ise.g-f (g b)) ∙ ! (ap g (hB-ise.g-f b))
=⟨ !-inv-l (hC-ise.g-f (g b)) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h) ∙ x ∙ ! (ap g (hB-ise.g-f b))) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h) ∙ ! (ap g (hB-ise.g-f b))
=⟨ ∙-assoc (hC-ise.g-f (f a)) _ _ |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x) ⟩
! (α' (hA a)) ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))
=⟨ eq₂ |in-ctx (λ x → ! x ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩
! (! (ap kC (α a)) ∙ hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))
=⟨ !-∙ (! (ap kC (α a))) _ |in-ctx (λ x → x ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩
(! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ ! (! (ap kC (α a)))) ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))
=⟨ ∙-assoc (! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a)))) _ _ ⟩
! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ ! (! (ap kC (α a))) ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))
=⟨ ap-! kC (α a) |in-ctx (λ x → ! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ ! (! (ap kC (α a))) ∙ x ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩
! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ ! (! (ap kC (α a))) ∙ ! (ap kC (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))
=⟨ ! (∙-assoc (! (! (ap kC (α a)))) _ _) |in-ctx (λ x → ! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ x) ⟩
! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ (! (! (ap kC (α a))) ∙ ! (ap kC (α a))) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))
=⟨ !-inv-l (! (ap kC (α a))) |in-ctx (λ x → ! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ x ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩
! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))
=⟨ !-∙ (hC-ise.g-f (f a)) _ |in-ctx (λ x → x ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩
(! (! (ap f (hA-ise.g-f a))) ∙ ! (hC-ise.g-f (f a))) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))
=⟨ ∙-assoc (! (! (ap f (hA-ise.g-f a)))) _ _ ⟩
! (! (ap f (hA-ise.g-f a))) ∙ ! (hC-ise.g-f (f a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))
=⟨ ! (∙-assoc (! (hC-ise.g-f (f a))) _ _) |in-ctx (λ x → ! (! (ap f (hA-ise.g-f a))) ∙ x) ⟩
! (! (ap f (hA-ise.g-f a))) ∙ (! (hC-ise.g-f (f a)) ∙ hC-ise.g-f (f a)) ∙ h ∙ ! (ap g (hB-ise.g-f b))
=⟨ !-inv-l (hC-ise.g-f (f a)) |in-ctx (λ x → ! (! (ap f (hA-ise.g-f a))) ∙ x ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩
! (! (ap f (hA-ise.g-f a))) ∙ h ∙ ! (ap g (hB-ise.g-f b))
=⟨ !-! (ap f (hA-ise.g-f a)) |in-ctx (λ x → x ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩
ap f (hA-ise.g-f a) ∙ h ∙ ! (ap g (hB-ise.g-f b)) ∎
goal = (! (α' (hA a)) ∙ ap kC (! (α a) ∙ ap hC h ∙ β b) ∙ β' (hB b)) ∙ ap g (hB-ise.g-f b)
=⟨ lem |in-ctx (λ x → x ∙ ap g (hB-ise.g-f b)) ⟩
(ap f (hA-ise.g-f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ∙ ap g (hB-ise.g-f b)
=⟨ ∙-assoc (ap f (hA-ise.g-f a)) (h ∙ ! (ap g (hB-ise.g-f b))) _ ⟩
ap f (hA-ise.g-f a) ∙ (h ∙ ! (ap g (hB-ise.g-f b))) ∙ ap g (hB-ise.g-f b)
=⟨ ∙-assoc h _ _ |in-ctx (λ x → ap f (hA-ise.g-f a) ∙ x) ⟩
ap f (hA-ise.g-f a) ∙ h ∙ ! (ap g (hB-ise.g-f b)) ∙ ap g (hB-ise.g-f b)
=⟨ !-inv-l (ap g (hB-ise.g-f b)) |in-ctx (λ x → ap f (hA-ise.g-f a) ∙ h ∙ x) ⟩
ap f (hA-ise.g-f a) ∙ h ∙ idp
=⟨ ∙-unit-r h |in-ctx (λ x → ap f (hA-ise.g-f a) ∙ x) ⟩
ap f (hA-ise.g-f a) ∙ h ∎
postulate
to-from : ∀ y → to (from y) == y
-- to-from (pullback a b h) = pullback= _ (hA-ise.f-g a) (hB-ise.f-g b) {!!}
Pullback-emap : Pullback cospan₀ ≃ Pullback cospan₁
Pullback-emap = equiv to from to-from from-to
| {
"alphanum_fraction": 0.3967332481,
"avg_line_length": 68.2080536913,
"ext": "agda",
"hexsha": "b1a4068d69c5ae46db6b7164fd08ee8fa5b5e5e3",
"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/stash/modalities/gbm/PullbackSplit.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/stash/modalities/gbm/PullbackSplit.agda",
"max_line_length": 177,
"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/stash/modalities/gbm/PullbackSplit.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": 9685,
"size": 20326
} |
{-
Closure properties of FinSet under several type constructors.
-}
{-# OPTIONS --safe #-}
module Cubical.Data.FinSet.Constructors where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.HITs.PropositionalTruncation renaming (rec to TruncRec)
open import Cubical.Data.Nat
open import Cubical.Data.Unit
open import Cubical.Data.Empty renaming (rec to EmptyRec)
open import Cubical.Data.Sum
open import Cubical.Data.Sigma
open import Cubical.Data.Fin
open import Cubical.Data.SumFin renaming (Fin to SumFin) hiding (discreteFin)
open import Cubical.Data.FinSet.Base
open import Cubical.Data.FinSet.Properties
open import Cubical.Data.FinSet.FiniteChoice
open import Cubical.Relation.Nullary
open import Cubical.Functions.Embedding
open import Cubical.Functions.Surjection
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
module _
(X : Type ℓ)(p : ≃Fin X) where
≃Fin∥∥ : ≃Fin ∥ X ∥
≃Fin∥∥ = ≃SumFin→Fin (_ , compEquiv (propTrunc≃ (≃Fin→SumFin p .snd)) (SumFin∥∥≃ _))
module _
(X : Type ℓ )(p : ≃Fin X)
(Y : Type ℓ')(q : ≃Fin Y) where
≃Fin⊎ : ≃Fin (X ⊎ Y)
≃Fin⊎ = ≃SumFin→Fin (_ , compEquiv (⊎-equiv (≃Fin→SumFin p .snd) (≃Fin→SumFin q .snd)) (SumFin⊎≃ _ _))
≃Fin× : ≃Fin (X × Y)
≃Fin× = ≃SumFin→Fin (_ , compEquiv (Σ-cong-equiv (≃Fin→SumFin p .snd) (λ _ → ≃Fin→SumFin q .snd)) (SumFin×≃ _ _))
module _
(X : Type ℓ )(p : ≃Fin X)
(Y : X → Type ℓ')(q : (x : X) → ≃Fin (Y x)) where
private
p' = ≃Fin→SumFin p
m = p' .fst
e = p' .snd
q' : (x : X) → ≃SumFin (Y x)
q' x = ≃Fin→SumFin (q x)
f : (x : X) → ℕ
f x = q' x .fst
≃SumFinΣ : ≃SumFin (Σ X Y)
≃SumFinΣ = _ ,
Σ-cong-equiv {B' = λ x → Y (invEq (p' .snd) x)} (p' .snd) (transpFamily p')
⋆ Σ-cong-equiv-snd (λ x → q' (invEq e x) .snd)
⋆ SumFinΣ≃ _ _
≃SumFinΠ : ≃SumFin ((x : X) → Y x)
≃SumFinΠ = _ ,
equivΠ {B' = λ x → Y (invEq (p' .snd) x)} (p' .snd) (transpFamily p')
⋆ equivΠCod (λ x → q' (invEq e x) .snd)
⋆ SumFinΠ≃ _ _
≃FinΣ : ≃Fin (Σ X Y)
≃FinΣ = ≃SumFin→Fin ≃SumFinΣ
≃FinΠ : ≃Fin ((x : X) → Y x)
≃FinΠ = ≃SumFin→Fin ≃SumFinΠ
module _
(X : FinSet ℓ)
(Y : X .fst → FinSet ℓ') where
isFinSetΣ : isFinSet (Σ (X .fst) (λ x → Y x .fst))
isFinSetΣ =
elim2 (λ _ _ → isPropIsFinSet {A = Σ (X .fst) (λ x → Y x .fst)})
(λ p q → ∣ ≃FinΣ (X .fst) p (λ x → Y x .fst) q ∣)
(X .snd) (choice X (λ x → ≃Fin (Y x .fst)) (λ x → Y x .snd))
isFinSetΠ : isFinSet ((x : X .fst) → Y x .fst)
isFinSetΠ =
elim2 (λ _ _ → isPropIsFinSet {A = ((x : X .fst) → Y x .fst)})
(λ p q → ∣ ≃FinΠ (X .fst) p (λ x → Y x .fst) q ∣)
(X .snd) (choice X (λ x → ≃Fin (Y x .fst)) (λ x → Y x .snd))
module _
(X : FinSet ℓ)
(Y : X .fst → FinSet ℓ')
(Z : (x : X .fst) → Y x .fst → FinSet ℓ'') where
isFinSetΠ2 : isFinSet ((x : X .fst) → (y : Y x .fst) → Z x y .fst)
isFinSetΠ2 = isFinSetΠ X (λ x → _ , isFinSetΠ (Y x) (Z x))
module _
(X : FinSet ℓ)
(Y : X .fst → FinSet ℓ')
(Z : (x : X .fst) → Y x .fst → FinSet ℓ'')
(W : (x : X .fst) → (y : Y x .fst) → Z x y .fst → FinSet ℓ''') where
isFinSetΠ3 : isFinSet ((x : X .fst) → (y : Y x .fst) → (z : Z x y .fst) → W x y z .fst)
isFinSetΠ3 = isFinSetΠ X (λ x → _ , isFinSetΠ2 (Y x) (Z x) (W x))
module _
(X : FinSet ℓ) where
isFinSet≡ : (a b : X .fst) → isFinSet (a ≡ b)
isFinSet≡ a b = isDecProp→isFinSet (isFinSet→isSet (X .snd) a b) (isFinSet→Discrete (X .snd) a b)
isFinSetIsContr : isFinSet (isContr (X .fst))
isFinSetIsContr = isFinSetΣ X (λ x → _ , (isFinSetΠ X (λ y → _ , isFinSet≡ x y)))
isFinSet∥∥ : isFinSet ∥ X .fst ∥
isFinSet∥∥ = TruncRec isPropIsFinSet (λ p → ∣ ≃Fin∥∥ (X .fst) p ∣) (X .snd)
module _
(X : FinSet ℓ )
(Y : FinSet ℓ')
(f : X .fst → Y .fst) where
isFinSetFiber : (y : Y .fst) → isFinSet (fiber f y)
isFinSetFiber y = isFinSetΣ X (λ x → _ , isFinSet≡ Y (f x) y)
isFinSetIsEquiv : isFinSet (isEquiv f)
isFinSetIsEquiv =
EquivPresIsFinSet
(invEquiv (isEquiv≃isEquiv' f))
(isFinSetΠ Y (λ y → _ , isFinSetIsContr (_ , isFinSetFiber y)))
module _
(X : FinSet ℓ )
(Y : FinSet ℓ') where
isFinSet⊎ : isFinSet (X .fst ⊎ Y .fst)
isFinSet⊎ = elim2 (λ _ _ → isPropIsFinSet) (λ p q → ∣ ≃Fin⊎ (X .fst) p (Y .fst) q ∣) (X .snd) (Y .snd)
isFinSet× : isFinSet (X .fst × Y .fst)
isFinSet× = elim2 (λ _ _ → isPropIsFinSet) (λ p q → ∣ ≃Fin× (X .fst) p (Y .fst) q ∣) (X .snd) (Y .snd)
isFinSet→ : isFinSet (X .fst → Y .fst)
isFinSet→ = isFinSetΠ X (λ _ → Y)
isFinSet≃ : isFinSet (X .fst ≃ Y .fst)
isFinSet≃ = isFinSetΣ (_ , isFinSet→) (λ f → _ , isFinSetIsEquiv X Y f)
module _
(X : FinSet ℓ) where
isFinSet¬ : isFinSet (¬ (X .fst))
isFinSet¬ = isFinSet→ X (⊥ , ∣ 0 , uninhabEquiv (λ x → x) ¬Fin0 ∣)
module _
(X : FinSet ℓ) where
isFinSetNonEmpty : isFinSet (NonEmpty (X .fst))
isFinSetNonEmpty = isFinSet¬ (_ , isFinSet¬ X)
module _
(X : FinSet ℓ )
(Y : FinSet ℓ')
(f : X .fst → Y .fst) where
isFinSetIsEmbedding : isFinSet (isEmbedding f)
isFinSetIsEmbedding =
isFinSetΠ2 X (λ _ → X)
(λ a b → _ , isFinSetIsEquiv (_ , isFinSet≡ X a b) (_ , isFinSet≡ Y (f a) (f b)) (cong f))
isFinSetIsSurjection : isFinSet (isSurjection f)
isFinSetIsSurjection =
isFinSetΠ Y (λ y → _ , isFinSet∥∥ (_ , isFinSetFiber X Y f y))
module _
(X : FinSet ℓ )
(Y : FinSet ℓ') where
isFinSet↪ : isFinSet (X .fst ↪ Y .fst)
isFinSet↪ = isFinSetΣ (_ , isFinSet→ X Y) (λ f → _ , isFinSetIsEmbedding X Y f)
isFinSet↠ : isFinSet (X .fst ↠ Y .fst)
isFinSet↠ = isFinSetΣ (_ , isFinSet→ X Y) (λ f → _ , isFinSetIsSurjection X Y f)
| {
"alphanum_fraction": 0.5826439007,
"avg_line_length": 28.8375634518,
"ext": "agda",
"hexsha": "7221a9b014332cdf3c83b634b1595168480b2e3a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Data/FinSet/Constructors.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Data/FinSet/Constructors.agda",
"max_line_length": 115,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Data/FinSet/Constructors.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 2530,
"size": 5681
} |
{-# OPTIONS --cubical --safe #-}
module Data.Sigma.Unique where
open import Data.Sigma.Base
open import Level
open import Path
∃! : ∀ {a b} {A : Type a} → (A → Type b) → Type (a ℓ⊔ b)
∃! B = ∃ x × B x × (∀ {y} → B y → x ≡ y)
infixr 4.5 ∃!-syntax
∃!-syntax : ∀ {a b} {A : Type a} (B : A → Type b) → Type (a ℓ⊔ b)
∃!-syntax = ∃!
syntax ∃!-syntax (λ x → e) = ∃ x ! × e
| {
"alphanum_fraction": 0.5148247978,
"avg_line_length": 21.8235294118,
"ext": "agda",
"hexsha": "9b19d398f147fb29b1912945bb88bcc9334e149d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Sigma/Unique.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Sigma/Unique.agda",
"max_line_length": 65,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Sigma/Unique.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": 168,
"size": 371
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- An inductive definition of the heterogeneous prefix relation
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.Prefix.Heterogeneous where
open import Level
open import Data.List.Base as List using (List; []; _∷_)
open import Data.List.Relation.Binary.Pointwise
using (Pointwise; []; _∷_)
open import Data.Product using (∃; _×_; _,_; uncurry)
open import Relation.Binary using (REL; _⇒_)
module _ {a b r} {A : Set a} {B : Set b} (R : REL A B r) where
data Prefix : REL (List A) (List B) (a ⊔ b ⊔ r) where
[] : ∀ {bs} → Prefix [] bs
_∷_ : ∀ {a b as bs} → R a b → Prefix as bs → Prefix (a ∷ as) (b ∷ bs)
data PrefixView (as : List A) : List B → Set (a ⊔ b ⊔ r) where
_++_ : ∀ {cs} → Pointwise R as cs → ∀ ds → PrefixView as (cs List.++ ds)
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} {a b as bs} where
head : Prefix R (a ∷ as) (b ∷ bs) → R a b
head (r ∷ rs) = r
tail : Prefix R (a ∷ as) (b ∷ bs) → Prefix R as bs
tail (r ∷ rs) = rs
uncons : Prefix R (a ∷ as) (b ∷ bs) → R a b × Prefix R as bs
uncons (r ∷ rs) = r , rs
module _ {a b r s} {A : Set a} {B : Set b} {R : REL A B r} {S : REL A B s} where
map : R ⇒ S → Prefix R ⇒ Prefix S
map R⇒S [] = []
map R⇒S (r ∷ rs) = R⇒S r ∷ map R⇒S rs
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
toView : ∀ {as bs} → Prefix R as bs → PrefixView R as bs
toView [] = [] ++ _
toView (r ∷ rs) with toView rs
... | rs′ ++ ds = (r ∷ rs′) ++ ds
fromView : ∀ {as bs} → PrefixView R as bs → Prefix R as bs
fromView ([] ++ ds) = []
fromView ((r ∷ rs) ++ ds) = r ∷ fromView (rs ++ ds)
| {
"alphanum_fraction": 0.5052169138,
"avg_line_length": 33.7222222222,
"ext": "agda",
"hexsha": "ba86166a74245cb13c2ea1ee43d398bb89ee698e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Prefix/Heterogeneous.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Prefix/Heterogeneous.agda",
"max_line_length": 80,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Prefix/Heterogeneous.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": 653,
"size": 1821
} |
module Structure.Category.Action where
open import Structure.Category.Functor
| {
"alphanum_fraction": 0.85,
"avg_line_length": 16,
"ext": "agda",
"hexsha": "42709e97b0683ca0e53ebb4b2234ebdb87b0e673",
"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/Category/Action.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/Category/Action.agda",
"max_line_length": 38,
"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/Category/Action.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": 14,
"size": 80
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Coproduct
open import lib.types.Sigma
open import lib.types.Pi
open import lib.types.Fin
open import lib.types.Nat
open import lib.types.Empty
open import lib.NType2
open import lib.Equivalence2
open import Util.Misc
open import Util.Coproducts
{- Some useful lemmas about working with finite sets. E.g. An injection from a finite set
to itself is an equivalence, an injection from a finite set to a large finite set has
at least one element not in its image.
-}
module Util.Finite where
ℕ=-to-Fin= : {n : ℕ} {x y : Fin n} → (fst x == fst y) → x == y
ℕ=-to-Fin= p = pair= p prop-has-all-paths-↓
finite-lpo : {i : ULevel} {n : ℕ} (P : Fin n → Type i) (dec : (x : Fin n) → Dec (P x)) →
(Σ (Fin n) P ⊔ ((x : Fin n) → ¬ (P x)))
finite-lpo {n = 0} P dec = inr (λ x _ → –> Fin-equiv-Empty x)
finite-lpo {i} {n = S n} P dec = ⊔-fmap (–> el) (–> er) lemma
where
P' : Fin n ⊔ ⊤ → Type i
P' z = P (<– Fin-equiv-Coprod z)
el : Σ (Fin n ⊔ ⊤) P' ≃ Σ (Fin (S n)) P
el = Σ-emap-l P (Fin-equiv-Coprod ⁻¹)
er : ((x : Fin n ⊔ ⊤) → ¬ (P' x)) ≃ ((x : Fin (S n)) → ¬ (P x))
er = Π-emap-l (¬ ∘ P) (Fin-equiv-Coprod ⁻¹)
lemma : Σ (Fin n ⊔ ⊤) P' ⊔ ((x : Fin n ⊔ ⊤) → ¬ (P' x))
lemma = ⊔-rec (λ np → inl ((inl (fst np)) , (snd np)))
(λ f → ⊔-rec (λ p → inl ((inr unit) , p)) (λ np → inr (λ { (inl k) → f k ; (inr _) → np})) (dec (n , ltS))) (finite-lpo {n = n} (P' ∘ inl) λ x → dec (<– Fin-equiv-Coprod (inl x)))
fin-img-dec : {i : ULevel} {A : Type i} (dec : has-dec-eq A) {n : ℕ} (inc : Fin n → A) → (a : A) → ((hfiber inc a) ⊔ ¬ (hfiber inc a))
fin-img-dec dec inc a = ⊔-rec (λ np → inl np) (λ f → inr (λ np → f (fst np) (snd np))) (finite-lpo (λ k → inc k == a) λ k → dec (inc k) a)
Fin-eq : {n : ℕ} {x y : Fin n} → (fst x == fst y) → x == y
Fin-eq p = pair= p prop-has-all-paths-↓
<-or-≥ : (n m : ℕ) → ((n < m) ⊔ (m ≤ n))
<-or-≥ n m = ⊔-rec (λ p → inr (inl (! p))) (⊔-rec inl (λ l → inr (inr l))) (ℕ-trichotomy n m)
≤-or-> : (n m : ℕ) → ((n ≤ m) ⊔ (m < n))
≤-or-> m n = ⊔-rec (inl ∘ inl) (⊔-fmap inr (idf _)) (ℕ-trichotomy m n)
<-≤-trans : {l m n : ℕ} → (l < m) → (m ≤ n) → (l < n)
<-≤-trans p (inl q) = transport _ q p
<-≤-trans p (inr q) = <-trans p q
≤-<-trans : {l m n : ℕ} → (l ≤ m) → (m < n) → (l < n)
≤-<-trans (inl p) q = transport _ (! p) q
≤-<-trans (inr p) q = <-trans p q
<S≠-to-< : {a b : ℕ} → (a < S b) → (a ≠ b) → (a < b)
<S≠-to-< ltS ne = ⊥-elim (ne idp)
<S≠-to-< (ltSR lt) ne = lt
module _ {n : ℕ} (k : Fin n) where
private
degeneracy-aux : (x : Fin (S n)) → ((fst x ≤ fst k) ⊔ (fst k < fst x)) → Fin n
degeneracy-aux x (inl z) = (fst x) , ≤-<-trans z (snd k)
degeneracy-aux (.(S (fst k)) , snd) (inr ltS) = k
degeneracy-aux (.(S _) , snd) (inr (ltSR z)) = _ , (<-cancel-S snd)
degeneracy-almost-inj-aux : {x y : Fin (S n)} → (fst x ≠ fst k) → (fst y ≠ fst k) →
(z : ((fst x) ≤ (fst k)) ⊔ ((fst k) < (fst x))) → (w : ((fst y) ≤ (fst k)) ⊔ ((fst k) < (fst y))) →
(degeneracy-aux x z == degeneracy-aux y w) → x == y
degeneracy-almost-inj-aux f g (inl z) (inl w) p = ℕ=-to-Fin= (ap fst p)
degeneracy-almost-inj-aux f g (inl z) (inr ltS) p = ⊥-rec (f (ap fst p))
degeneracy-almost-inj-aux f g (inl z) (inr (ltSR w)) p = ⊥-rec (<-to-≠ (≤-<-trans z w) (ap fst p))
degeneracy-almost-inj-aux f g (inr ltS) (inl w) p = ⊥-rec (g (ap fst (! p)))
degeneracy-almost-inj-aux f g (inr (ltSR z)) (inl w) p = ⊥-rec (<-to-≠ (≤-<-trans w z) (ap fst (! p)))
degeneracy-almost-inj-aux f g (inr ltS) (inr ltS) p = ℕ=-to-Fin= idp
degeneracy-almost-inj-aux f g (inr ltS) (inr (ltSR w)) p = ℕ=-to-Fin= (ap S (ap fst p))
degeneracy-almost-inj-aux f g (inr (ltSR z)) (inr ltS) p = ℕ=-to-Fin= (ap S (ap fst p))
degeneracy-almost-inj-aux f g (inr (ltSR z)) (inr (ltSR w)) p = ℕ=-to-Fin= (ap S (ap fst p))
abstract
degeneracy : (x : Fin (S n)) → Fin n
degeneracy x = degeneracy-aux x (≤-or-> _ _)
degeneracy-almost-inj : {x y : Fin (S n)} → (fst x ≠ fst k) → (fst y ≠ fst k) →
(degeneracy x == degeneracy y) → x == y
degeneracy-almost-inj f g = degeneracy-almost-inj-aux f g (≤-or-> _ _) (≤-or-> _ _)
Fin-hfiber-dec : {i : ULevel} {X : Type i} {n : ℕ} (dec : has-dec-eq X) → (f : Fin n → X) →
(x : X) → Dec (hfiber f x)
Fin-hfiber-dec dec f x = ⊔-fmap (idf _) (λ g p → g (fst p) (snd p))
(finite-lpo (λ z → f z == x) (λ z → dec (f z) x))
Fin-inj-to-surj : (n : ℕ) → (inc : Fin n → Fin n) → (inc-inj : is-inj inc) → (y : Fin n) → hfiber inc y
Fin-inj-to-surj O inc inc-inj y = ⊥-rec (–> Fin-equiv-Empty y)
Fin-inj-to-surj (S n) inc inc-inj y =
⊔-rec (λ p → n<Sn , (! p))
(λ f → ⊔-rec (λ p → case1 p f) (λ g → case2 g f) (Fin-has-dec-eq k n<Sn))
(Fin-has-dec-eq y k)
where
n<Sn = (n , ltS)
k = inc n<Sn
case1 : k == n<Sn → (y ≠ k) → hfiber inc y
case1 p f = Fin-S (fst x') , ℕ=-to-Fin= (ap fst (snd x'))
where
inc' : Fin n → Fin n
inc' x = (fst (inc (Fin-S x))) , <S≠-to-< (snd (inc (Fin-S x))) λ q → <-to-≠ (snd x) (ap fst (inc-inj _ _ (ℕ=-to-Fin= q ∙ ! p)))
inc-inj' : is-inj inc'
inc-inj' x x' p = Fin-S-is-inj _ _ (inc-inj _ _ (ℕ=-to-Fin= (ap fst p)))
y' : Fin n
y' = (fst y) , (<S≠-to-< (snd y) (λ q → f (ℕ=-to-Fin= q ∙ ! p)))
x' : hfiber inc' y'
x' = Fin-inj-to-surj n inc' inc-inj' y'
case2 : k ≠ n<Sn → (y ≠ k) → hfiber inc y
case2 f g = Fin-S (fst x') , degeneracy-almost-inj k' (λ q → <-to-≠ (snd (fst x')) (ap fst (inc-inj (Fin-S (fst x')) n<Sn (ℕ=-to-Fin= q))))
(λ q → g (ℕ=-to-Fin= q)) (snd x')
where
k' = (fst k) , (<S≠-to-< (snd k) (λ q → f (ℕ=-to-Fin= q)))
inc' : Fin n → Fin n
inc' x = degeneracy k' (inc (Fin-S x))
inc-inj' : is-inj inc'
inc-inj' x x' p =
Fin-S-is-inj _ _ (inc-inj _ _ (degeneracy-almost-inj k' (λ q → <-to-≠ (snd x) (ap fst (inc-inj _ _ (ℕ=-to-Fin= q))))
(λ q → <-to-≠ (snd x') (ap fst (inc-inj _ _ (ℕ=-to-Fin= q))))
p))
x' : hfiber inc' (degeneracy k' y)
x' = Fin-inj-to-surj n inc' inc-inj' ((degeneracy k' y))
Fin-inj-to-equiv : {n : ℕ} → (inc : Fin (S n) → Fin (S n)) → (inc-inj : is-inj inc) → (is-equiv inc)
Fin-inj-to-equiv inc inc-inj =
contr-map-is-equiv λ x → inhab-prop-is-contr (Fin-inj-to-surj _ inc inc-inj x) ⦃ inj-to-embed ⦃ Fin-is-set ⦄ inc inc-inj x ⦄
Fin-smaller-is-smaller : {m n : ℕ} (l : m < n) (f : Fin m → Fin n) → Σ (Fin n) (λ k → ¬ (hfiber f k))
Fin-smaller-is-smaller {m} {n} l f = ⊔-cancel-r (finite-lpo _ (λ k → ⊔-rec (λ x → inr (λ g → g x)) inl (Fin-hfiber-dec Fin-has-dec-eq f k))) lemma
where
lemma : ((k : Fin n) → ¬ (¬ (hfiber f k))) → ⊥
lemma g = <-to-≠ (snd (g'' (fst k))) (ap fst (snd k))
where
g' : (k : Fin n) → (hfiber f k)
g' k = ⊔-cancel-r (Fin-hfiber-dec Fin-has-dec-eq f k) (g k)
g'' : Fin n → Fin m
g'' = fst ∘ g'
g''-is-inj : is-inj g''
g''-is-inj y y' p = ! (snd (g' y)) ∙ ap f p ∙ snd (g' y')
h : Fin n → Fin n
h k = (fst (g'' k)) , (<-trans (snd (g'' k)) l)
h-is-inj : is-inj h
h-is-inj x y p = g''-is-inj _ _ (ℕ=-to-Fin= (ap fst p))
k : hfiber h (m , l)
k = Fin-inj-to-surj n h h-is-inj ((m , l))
| {
"alphanum_fraction": 0.485025955,
"avg_line_length": 42.6875,
"ext": "agda",
"hexsha": "37d6df2051c5d675f298cca96fd7566d0a2fc91e",
"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/Util/Finite.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/Util/Finite.agda",
"max_line_length": 185,
"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/Util/Finite.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3225,
"size": 7513
} |
{-# OPTIONS --without-K --type-in-type #-}
module UnbiasedCategory where
open import Agda.Builtin.Equality
module TypedLists where
data TypedList (index : Set) (type : index -> index -> Set) : index -> index -> Set where
empty : {a : index} -> TypedList index type a a
fby : {a b c : index} -> type a b -> TypedList index type b c -> TypedList index type a c
open TypedList public
append : forall {index : Set} {type : index -> index -> Set} {a b c : index} ->
TypedList index type a b -> TypedList index type b c -> TypedList index type a c
append empty s = s
append (fby x l) s = fby x (append l s)
concat : forall {index : Set} {type : index -> index -> Set} {a b : index} ->
TypedList index (TypedList index type) a b -> TypedList index type a b
concat empty = empty
concat (fby l s) = append l (concat s)
map : forall {index : Set} {p : index -> index -> Set} {q : index -> index -> Set} {a b : index} ->
(forall {a b : index} -> p a b -> q a b) ->
TypedList index p a b -> TypedList index q a b
map transform empty = empty
map transform (fby x l) = fby (transform x) (map transform l)
fold : forall {index : Set} {type : index -> index -> Set} {p : index -> index -> Set} {a b : index} ->
(f : forall {a} {b} {c} -> type a b -> p b c -> p a c) -> (z : forall {a} -> p a a) -> TypedList index type a b -> p a b
fold f z empty = z
fold f z (fby x l) = f x (fold f z l)
open TypedLists public
module Equality where
cong : {A B : Set} {x y : A} -> (f : A -> B) -> (x ≡ y) -> f x ≡ f y
cong f refl = refl
app : {A B : Set} {f g : A -> B} -> (f ≡ g) -> (a : A) -> f a ≡ g a
app {A} {B} {f} {g} refl a = refl
symm : {A : Set} {x y : A} -> (x ≡ y) -> (y ≡ x)
symm refl = refl
infixr 2 _≡⟨_⟩_
_≡⟨_⟩_ : {A : Set} (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ refl ⟩ p2 = p2
infix 3 _∎
_∎ : {A : Set} (x : A) → x ≡ x
x ∎ = refl
postulate
funext : {A B : Set} {f g : A -> B} -> ({a : A} -> f a ≡ g a) -> (f ≡ g)
open Equality public
record Category : Set where
field
object : Set
hom : object -> object -> Set
compose : {a b : object} -> TypedList object hom a b -> hom a b
associativity : {a b : object} -> (l : TypedList object (TypedList object hom) a b) ->
compose (concat l) ≡ compose (map compose l)
open Category {{...}} public
record CategoryConstructor : Set where
field
object : Set
hom : object -> object -> Set
_>>_ : {a b c : object} -> hom a b -> hom b c -> hom a c
id : {a : object} -> hom a a
left-unital : {a b : object} {f : hom a b} -> (id >> f) ≡ f
right-unital : {a b : object} {f : hom a b} -> (id >> f) ≡ f
associative : {a b c d : object} {f : hom a b} {g : hom b c} {h : hom c d} ->
(f >> g) >> h ≡ f >> (g >> h)
open CategoryConstructor public
mkCategory : CategoryConstructor -> Category
mkCategory record
{ object = object
; hom = hom
; _>>_ = _>>_
; id = id
; left-unital = left-unital
; right-unital = right-unital
; associative = associative
} = record
{ object = object
; hom = hom
; compose = byFolding
; associativity = associativityTotal
}
where
byFolding : {a b : object} -> TypedList object hom a b -> hom a b
byFolding = fold _>>_ id
lemma-fold-append : forall {a b c : object} ->
(p : TypedList object hom a b) -> (q : TypedList object hom b c) ->
byFolding (append p q) ≡ byFolding (fby (byFolding p) q)
lemma-fold-append empty q = symm left-unital
lemma-fold-append (fby f p) q =
byFolding (fby f (append p q))
≡⟨ refl ⟩
f >> byFolding (append p q)
≡⟨ cong (_>>_ f) (lemma-fold-append p q) ⟩
f >> byFolding (fby (byFolding p) q)
≡⟨ refl ⟩
f >> (byFolding p >> byFolding q)
≡⟨ symm associative ⟩
byFolding (fby f p) >> byFolding q
≡⟨ refl ⟩
byFolding (fby (byFolding (fby f p)) q) ∎
associativityTotal : {a b : object}
(l : TypedList object (TypedList object hom) a b) →
byFolding (concat l) ≡ byFolding (map byFolding l)
associativityTotal {a} {a} empty = refl
associativityTotal {a} {b} (fby l s) =
byFolding (append l (concat s))
≡⟨ lemma-fold-append l (concat s) ⟩
byFolding (fby (byFolding l) (concat s))
≡⟨ refl ⟩
byFolding l >> byFolding (concat s)
≡⟨ cong (_>>_ (byFolding l)) (associativityTotal s) ⟩
byFolding l >> byFolding (map byFolding s)
≡⟨ refl ⟩
byFolding (fby (byFolding l) (map byFolding s)) ∎
categoryOfSets : Category
categoryOfSets = mkCategory
( record
{ object = Set
; hom = λ A B -> (A -> B)
; _>>_ = λ f g a -> g (f a)
; id = λ x -> x
; left-unital = refl
; right-unital = refl
; associative = refl
})
| {
"alphanum_fraction": 0.5623549272,
"avg_line_length": 33.609929078,
"ext": "agda",
"hexsha": "f32da00eaceddce85b12a126ed5cffcb4ee12166",
"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": "4d1c0f305639b6569ba71563e6262adbed3b65cc",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "mroman42/unbiased-category-agda",
"max_forks_repo_path": "UnbiasedCategory.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4d1c0f305639b6569ba71563e6262adbed3b65cc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "mroman42/unbiased-category-agda",
"max_issues_repo_path": "UnbiasedCategory.agda",
"max_line_length": 124,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "4d1c0f305639b6569ba71563e6262adbed3b65cc",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "mroman42/unbiased-category-agda",
"max_stars_repo_path": "UnbiasedCategory.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-20T17:54:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-20T17:54:39.000Z",
"num_tokens": 1701,
"size": 4739
} |
module L.Data.Bool.Properties where
open import L.Data.Bool.Core
open import L.Base.Id.Core
open import L.Base.Coproduct.Core
!∃tt∧!∃ff : (x : Bool) → (x ≡ ff) + (x ≡ tt)
!∃tt∧!∃ff = if (λ b → (b ≡ ff) + (b ≡ tt)) (inr refl) (inl refl)
| {
"alphanum_fraction": 0.6092436975,
"avg_line_length": 26.4444444444,
"ext": "agda",
"hexsha": "83a761ee76bd8660d8fc72399a8852a8f4d7b539",
"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": "83707537b182ba8906228ac0bcb9ccef972eaaa3",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "borszag/smallib",
"max_forks_repo_path": "src/L/Data/Bool/Properties.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "83707537b182ba8906228ac0bcb9ccef972eaaa3",
"max_issues_repo_issues_event_max_datetime": "2020-11-09T16:40:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-10-19T10:13:16.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "borszag/smallib",
"max_issues_repo_path": "src/L/Data/Bool/Properties.agda",
"max_line_length": 64,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "83707537b182ba8906228ac0bcb9ccef972eaaa3",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "borszag/smallib",
"max_stars_repo_path": "src/L/Data/Bool/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 99,
"size": 238
} |
{-# OPTIONS --without-K --safe #-}
module Tools.Fin where
open import Tools.Nat
open import Tools.Nullary
open import Tools.PropositionalEquality
open import Data.Fin.Properties using (suc-injective)
open import Data.Fin public using (Fin) renaming (zero to x0 ; suc to _+1)
-- Decidability of equality
_≟ⱽ_ : {n : Nat} → (x y : Fin n) → Dec (x ≡ y)
x0 ≟ⱽ x0 = yes refl
x0 ≟ⱽ (y +1) = no (λ ())
(x +1) ≟ⱽ x0 = no (λ ())
(x +1) ≟ⱽ (y +1) = map (cong _+1) suc-injective (x ≟ⱽ y)
| {
"alphanum_fraction": 0.6384297521,
"avg_line_length": 23.0476190476,
"ext": "agda",
"hexsha": "5dd499f7481c8b25ddec89886babd5341e1f15fb",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-11-27T15:58:33.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-10-18T14:18:20.000Z",
"max_forks_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "fhlkfy/logrel-mltt",
"max_forks_repo_path": "Tools/Fin.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391",
"max_issues_repo_issues_event_max_datetime": "2021-02-22T10:37:24.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-22T12:49:23.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "fhlkfy/logrel-mltt",
"max_issues_repo_path": "Tools/Fin.agda",
"max_line_length": 74,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "fhlkfy/logrel-mltt",
"max_stars_repo_path": "Tools/Fin.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:01:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-20T03:05:21.000Z",
"num_tokens": 187,
"size": 484
} |
{-
- Automatically generate UARel and DUARel instances
-}
{-# OPTIONS --no-exact-split --safe #-}
module Cubical.Displayed.Auto where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Displayed.Base
open import Cubical.Displayed.Subst
open import Cubical.Displayed.Morphism
open import Cubical.Displayed.Constant
open import Cubical.Displayed.Function
open import Cubical.Displayed.Generic
open import Cubical.Displayed.Sigma
open import Cubical.Displayed.Unit
open import Cubical.Displayed.Universe
open import Cubical.Data.List.Base
open import Cubical.Data.Nat.Base
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Unit.Base
import Agda.Builtin.Reflection as R
open import Cubical.Reflection.Base
-- Descriptor language
mutual
data UARelDesc : ∀ {ℓA ℓ≅A} {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) → Typeω where
generic : ∀ {ℓA} {A : Type ℓA} → UARelDesc (𝒮-generic A)
univ : ∀ ℓU → UARelDesc (𝒮-Univ ℓU)
-- Having a special descriptor for non-dependent × helps to avoid
-- combinatorial explosion. Automation will try to apply this first.
prod : ∀ {ℓA ℓ≅A ℓB ℓ≅B}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A} (dA : UARelDesc 𝒮-A)
{B : Type ℓB} {𝒮-B : UARel B ℓ≅B} (dB : UARelDesc 𝒮-B)
→ UARelDesc (𝒮-A ×𝒮 𝒮-B)
sigma : ∀ {ℓA ℓ≅A ℓB ℓ≅B}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A} (dA : UARelDesc 𝒮-A)
{B : A → Type ℓB} {𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B} (dB : DUARelDesc 𝒮-A 𝒮ᴰ-B)
→ UARelDesc (∫ 𝒮ᴰ-B)
param : ∀ {ℓA ℓB ℓ≅B} (A : Type ℓA)
{B : Type ℓB} {𝒮-B : UARel B ℓ≅B} (dB : UARelDesc 𝒮-B)
→ UARelDesc (A →𝒮 𝒮-B)
pi : ∀ {ℓA ℓ≅A ℓB ℓ≅B}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A} (dA : UARelDesc 𝒮-A)
{B : A → Type ℓB} {𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B} (dB : DUARelDesc 𝒮-A 𝒮ᴰ-B)
→ UARelDesc (𝒮-Π 𝒮-A 𝒮ᴰ-B)
unit : UARelDesc 𝒮-Unit
-- Projections from one UARel to another
data UARelReindex : ∀ {ℓA ℓ≅A ℓC ℓ≅C}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{C : Type ℓC} {𝒮-C : UARel C ℓ≅C}
(f : UARelHom 𝒮-A 𝒮-C)
→ Typeω
where
id : ∀ {ℓA ℓ≅A} {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
→ UARelReindex (𝒮-id 𝒮-A)
∘fst : ∀ {ℓA ℓ≅A ℓB ℓ≅B ℓC ℓ≅C}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} {𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B}
{C : Type ℓC} {𝒮-C : UARel C ℓ≅C}
{f : UARelHom 𝒮-A 𝒮-C}
→ UARelReindex f
→ UARelReindex (𝒮-∘ f (𝒮-fst {𝒮ᴰ-B = 𝒮ᴰ-B}))
∘snd : ∀ {ℓA ℓ≅A ℓB ℓ≅B ℓC ℓ≅C}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : Type ℓB} {𝒮-B : UARel B ℓ≅B}
{C : Type ℓC} {𝒮-C : UARel C ℓ≅C}
{f : UARelHom 𝒮-B 𝒮-C}
→ UARelReindex f
→ UARelReindex (𝒮-∘ f (𝒮-snd {𝒮-A = 𝒮-A}))
∘app : ∀ {ℓA ℓB ℓ≅B ℓC ℓ≅C}
{A : Type ℓA}
{B : Type ℓB} {𝒮-B : UARel B ℓ≅B}
{C : Type ℓC} {𝒮-C : UARel C ℓ≅C}
{f : UARelHom 𝒮-B 𝒮-C}
→ UARelReindex f
→ (a : A) → UARelReindex (𝒮-∘ f (𝒮-app a))
data SubstRelDesc : ∀ {ℓA ℓ≅A ℓB}
{A : Type ℓA} (𝒮-A : UARel A ℓ≅A)
{B : A → Type ℓB} (𝒮ˢ-B : SubstRel 𝒮-A B) → Typeω
where
generic : ∀ {ℓA ℓ≅A ℓB} {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB}
→ SubstRelDesc 𝒮-A (𝒮ˢ-generic 𝒮-A B)
constant : ∀ {ℓA ℓ≅A ℓB}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : Type ℓB}
→ SubstRelDesc 𝒮-A (𝒮ˢ-const 𝒮-A B)
-- We have an element DUARel over any 𝒮-A with a proejction to a universe
-- that can be described with UARelReindex
el : ∀ {ℓA ℓ≅A ℓU} {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{f : UARelHom 𝒮-A (𝒮-Univ ℓU)}
→ UARelReindex f
→ SubstRelDesc 𝒮-A (𝒮ˢ-reindex f (𝒮ˢ-El ℓU))
prod : ∀ {ℓA ℓ≅A ℓB ℓC}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} {𝒮ˢ-B : SubstRel 𝒮-A B} (dB : SubstRelDesc 𝒮-A 𝒮ˢ-B)
{C : A → Type ℓC} {𝒮ˢ-C : SubstRel 𝒮-A C} (dC : SubstRelDesc 𝒮-A 𝒮ˢ-C)
→ SubstRelDesc 𝒮-A (𝒮ˢ-B ×𝒮ˢ 𝒮ˢ-C)
sigma : ∀ {ℓA ℓ≅A ℓB ℓC}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} {𝒮ˢ-B : SubstRel 𝒮-A B} (dB : SubstRelDesc 𝒮-A 𝒮ˢ-B)
{C : Σ A B → Type ℓC} {𝒮ˢ-C : SubstRel (∫ˢ 𝒮ˢ-B) C} (dC : SubstRelDesc (∫ˢ 𝒮ˢ-B) 𝒮ˢ-C)
→ SubstRelDesc 𝒮-A (𝒮ˢ-Σ 𝒮ˢ-B 𝒮ˢ-C)
pi : ∀ {ℓA ℓ≅A ℓB ℓC}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} {𝒮ˢ-B : SubstRel 𝒮-A B} (dB : SubstRelDesc 𝒮-A 𝒮ˢ-B)
{C : Σ A B → Type ℓC} {𝒮ˢ-C : SubstRel (∫ˢ 𝒮ˢ-B) C} (dC : SubstRelDesc (∫ˢ 𝒮ˢ-B) 𝒮ˢ-C)
→ SubstRelDesc 𝒮-A (𝒮ˢ-Π 𝒮ˢ-B 𝒮ˢ-C)
data DUARelDesc : ∀ {ℓA ℓ≅A ℓB ℓ≅B}
{A : Type ℓA} (𝒮-A : UARel A ℓ≅A)
{B : A → Type ℓB} (𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B) → Typeω
where
generic : ∀ {ℓA ℓ≅A ℓB} {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB}
→ DUARelDesc 𝒮-A (𝒮ᴰ-generic 𝒮-A B)
constant : ∀ {ℓA ℓ≅A ℓB ℓ≅B}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : Type ℓB} {𝒮-B : UARel B ℓ≅B}
→ UARelDesc 𝒮-B
→ DUARelDesc 𝒮-A (𝒮ᴰ-const 𝒮-A 𝒮-B)
el : ∀ {ℓA ℓ≅A ℓU} {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{f : UARelHom 𝒮-A (𝒮-Univ ℓU)}
→ UARelReindex f
→ DUARelDesc 𝒮-A (𝒮ᴰ-reindex f (𝒮ᴰ-El ℓU))
prod : ∀ {ℓA ℓ≅A ℓB ℓ≅B ℓC ℓ≅C}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} {𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B} (dB : DUARelDesc 𝒮-A 𝒮ᴰ-B)
{C : A → Type ℓC} {𝒮ᴰ-C : DUARel 𝒮-A C ℓ≅C} (dC : DUARelDesc 𝒮-A 𝒮ᴰ-C)
→ DUARelDesc 𝒮-A (𝒮ᴰ-B ×𝒮ᴰ 𝒮ᴰ-C)
sigma : ∀ {ℓA ℓ≅A ℓB ℓ≅B ℓC ℓ≅C}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} {𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B} (dB : DUARelDesc 𝒮-A 𝒮ᴰ-B)
{C : Σ A B → Type ℓC} {𝒮ᴰ-C : DUARel (∫ 𝒮ᴰ-B) C ℓ≅C} (dC : DUARelDesc (∫ 𝒮ᴰ-B) 𝒮ᴰ-C)
→ DUARelDesc 𝒮-A (𝒮ᴰ-Σ 𝒮ᴰ-B 𝒮ᴰ-C)
pi : ∀ {ℓA ℓ≅A ℓB ℓ≅B ℓC ℓ≅C}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} {𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B} (dB : DUARelDesc 𝒮-A 𝒮ᴰ-B)
{C : Σ A B → Type ℓC} {𝒮ᴰ-C : DUARel (∫ 𝒮ᴰ-B) C ℓ≅C} (dC : DUARelDesc (∫ 𝒮ᴰ-B) 𝒮ᴰ-C)
→ DUARelDesc 𝒮-A (𝒮ᴰ-Π 𝒮ᴰ-B 𝒮ᴰ-C)
piˢ : ∀ {ℓA ℓ≅A ℓB ℓC ℓ≅C}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} {𝒮ˢ-B : SubstRel 𝒮-A B} (dB : SubstRelDesc 𝒮-A 𝒮ˢ-B)
{C : Σ A B → Type ℓC} {𝒮ᴰ-C : DUARel (∫ˢ 𝒮ˢ-B) C ℓ≅C} (dC : DUARelDesc (∫ˢ 𝒮ˢ-B) 𝒮ᴰ-C)
→ DUARelDesc 𝒮-A (𝒮ᴰ-Πˢ 𝒮ˢ-B 𝒮ᴰ-C)
private
getUARel : ∀ {ℓA ℓ≅A} {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
→ UARelDesc 𝒮-A → UARel A ℓ≅A
getUARel {𝒮-A = 𝒮-A} _ = 𝒮-A
getDUARel : ∀ {ℓA ℓ≅A ℓB ℓ≅B}
{A : Type ℓA} {𝒮-A : UARel A ℓ≅A}
{B : A → Type ℓB} {𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B}
→ DUARelDesc 𝒮-A 𝒮ᴰ-B → DUARel 𝒮-A B ℓ≅B
getDUARel {𝒮ᴰ-B = 𝒮ᴰ-B} _ = 𝒮ᴰ-B
-- Magic number
private
FUEL = 10000
mutual
autoUARelDesc : ℕ → R.Term → R.TC Unit
autoUARelDesc zero hole = R.typeError [ R.strErr "Out of fuel" ]
autoUARelDesc (suc n) hole =
tryUniv <|> tryProd <|> trySigma <|> tryParam <|> tryPi <|> tryUnit <|> useGeneric
where
tryUniv : R.TC Unit
tryUniv = R.unify (R.con (quote UARelDesc.univ) [ varg R.unknown ]) hole
tryBinary : R.Name → R.TC Unit
tryBinary name =
newMeta R.unknown >>= λ hole₁ →
newMeta R.unknown >>= λ hole₂ →
R.unify (R.con name (hole₁ v∷ hole₂ v∷ [])) hole >>
autoUARelDesc n hole₁ >>
autoDUARelDesc n hole₂
tryParam : R.TC Unit
tryParam =
newMeta R.unknown >>= λ paramTy →
newMeta R.unknown >>= λ hole₁ →
R.unify (R.con (quote UARelDesc.param) (paramTy v∷ hole₁ v∷ [])) hole >>
autoUARelDesc n hole₁
tryProd = tryBinary (quote UARelDesc.prod)
trySigma = tryBinary (quote UARelDesc.sigma)
tryPi = tryBinary (quote UARelDesc.pi)
tryUnit : R.TC Unit
tryUnit = R.unify (R.con (quote UARelDesc.unit) []) hole
useGeneric : R.TC Unit
useGeneric = R.unify (R.con (quote UARelDesc.generic) []) hole
autoUARelReindex : ℕ → R.Term → R.TC Unit
autoUARelReindex zero hole = R.typeError [ R.strErr "Out of fuel" ]
autoUARelReindex (suc n) hole =
tryId <|> tryFst <|> trySnd <|> tryApp
where
tryId : R.TC Unit
tryId = R.unify (R.con (quote UARelReindex.id) []) hole
tryUnary : R.Name → R.TC Unit
tryUnary name =
newMeta R.unknown >>= λ hole₁ →
R.unify (R.con name [ varg hole₁ ]) hole >>
autoUARelReindex n hole₁
tryFst = tryUnary (quote UARelReindex.∘fst)
trySnd = tryUnary (quote UARelReindex.∘snd)
tryApp : R.TC Unit
tryApp =
newMeta R.unknown >>= λ hole₁ →
newMeta R.unknown >>= λ param →
R.unify (R.con (quote UARelReindex.∘app) (hole₁ v∷ param v∷ [])) hole >>
autoUARelReindex n hole₁
autoSubstRelDesc : ℕ → R.Term → R.TC Unit
autoSubstRelDesc zero hole = R.typeError [ R.strErr "Out of fuel" ]
autoSubstRelDesc (suc n) hole =
tryConstant <|> tryEl <|> tryProd <|> trySigma <|> tryPi <|> useGeneric
where
tryConstant : R.TC Unit
tryConstant =
R.unify (R.con (quote SubstRelDesc.constant) []) hole
tryEl : R.TC Unit
tryEl =
newMeta R.unknown >>= λ hole₁ →
R.unify (R.con (quote SubstRelDesc.el) [ varg hole₁ ]) hole >>
autoUARelReindex n hole₁
tryBinary : R.Name → R.TC Unit
tryBinary name =
newMeta R.unknown >>= λ hole₁ →
newMeta R.unknown >>= λ hole₂ →
R.unify (R.con name (hole₁ v∷ hole₂ v∷ [])) hole >>
autoSubstRelDesc n hole₁ >>
autoSubstRelDesc n hole₂
tryProd = tryBinary (quote SubstRelDesc.prod)
trySigma = tryBinary (quote SubstRelDesc.sigma)
tryPi = tryBinary (quote SubstRelDesc.pi)
useGeneric : R.TC Unit
useGeneric = R.unify (R.con (quote SubstRelDesc.generic) []) hole
autoDUARelDesc : ℕ → R.Term → R.TC Unit
autoDUARelDesc zero hole = R.typeError [ R.strErr "Out of fuel" ]
autoDUARelDesc (suc n) hole =
tryConstant <|> tryEl <|> tryProd <|> trySigma <|> tryPiˢ <|> tryPi <|> useGeneric
where
tryConstant : R.TC Unit
tryConstant =
newMeta R.unknown >>= λ hole₁ →
R.unify (R.con (quote DUARelDesc.constant) [ varg hole₁ ]) hole >>
autoUARelDesc n hole₁
tryEl : R.TC Unit
tryEl =
newMeta R.unknown >>= λ hole₁ →
R.unify (R.con (quote DUARelDesc.el) [ varg hole₁ ]) hole >>
autoUARelReindex n hole₁
tryBinary : R.Name → R.TC Unit
tryBinary name =
newMeta R.unknown >>= λ hole₁ →
newMeta R.unknown >>= λ hole₂ →
R.unify (R.con name (hole₁ v∷ hole₂ v∷ [])) hole >>
autoDUARelDesc n hole₁ >>
autoDUARelDesc n hole₂
tryProd = tryBinary (quote DUARelDesc.prod)
trySigma = tryBinary (quote DUARelDesc.sigma)
tryPi = tryBinary (quote DUARelDesc.pi)
tryPiˢ : R.TC Unit
tryPiˢ =
newMeta R.unknown >>= λ hole₁ →
newMeta R.unknown >>= λ hole₂ →
R.unify (R.con (quote DUARelDesc.piˢ) (hole₁ v∷ hole₂ v∷ [])) hole >>
autoSubstRelDesc n hole₁ >>
autoDUARelDesc n hole₂
useGeneric : R.TC Unit
useGeneric = R.unify (R.con (quote DUARelDesc.generic) []) hole
module DisplayedAutoMacro where
autoUARel : ∀ {ℓA} (A : Type ℓA) → ℕ → R.Term → R.TC Unit
autoUARel A n hole =
R.quoteTC A >>= λ `A` →
newMeta R.unknown >>= λ desc →
makeAuxiliaryDef "autoUA"
(R.def (quote UARel) (`A` v∷ R.unknown v∷ []))
(R.def (quote getUARel) [ varg desc ])
>>= λ uaTerm →
R.unify hole uaTerm >>
autoUARelDesc n desc
autoDUARel : ∀ {ℓA ℓ≅A ℓB} {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) (B : A → Type ℓB)
→ ℕ → R.Term → R.TC Unit
autoDUARel 𝒮-A B n hole =
R.quoteTC 𝒮-A >>= λ `𝒮-A` →
R.quoteTC B >>= λ `B` →
newMeta R.unknown >>= λ desc →
makeAuxiliaryDef "autoDUA"
(R.def (quote DUARel) (`𝒮-A` v∷ `B` v∷ R.unknown v∷ []))
(R.def (quote getDUARel) [ varg desc ])
>>= λ duaTerm →
R.unify hole duaTerm >>
autoDUARelDesc n desc
macro
autoUARel : ∀ {ℓA} (A : Type ℓA) → R.Term → R.TC Unit
autoUARel A = DisplayedAutoMacro.autoUARel A FUEL
autoDUARel : ∀ {ℓA ℓ≅A ℓB} {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) (B : A → Type ℓB)
→ R.Term → R.TC Unit
autoDUARel 𝒮-A B = DisplayedAutoMacro.autoDUARel 𝒮-A B FUEL
private
module Example (A : Type) (a₀ : A) where
example0 : DUARel (autoUARel Type) (λ X → X → A × X) ℓ-zero
example0 = autoDUARel _ _
example0' : {X Y : Type} (e : X ≃ Y)
(f : X → A × X) (g : Y → A × Y)
→ (∀ x → (f x .fst ≡ g (e .fst x) .fst) × (e .fst (f x .snd) ≡ g (e .fst x) .snd))
→ PathP (λ i → ua e i → A × ua e i) f g
example0' e f g = example0 .DUARel.uaᴰ f e g .fst
-- An example where a DUARel is parameterized over a pair of types
example1 : DUARel (autoUARel (Type × Type)) (λ (X , Z) → X → Z) ℓ-zero
example1 = autoDUARel _ _
example1' : {X Y : Type} (e : X ≃ Y) {Z W : Type} (h : Z ≃ W)
(f : X → Z) (g : Y → W)
→ (∀ x → h .fst (f x) ≡ g (e .fst x))
→ PathP (λ i → ua e i → ua h i) f g
example1' e h f g = example1 .DUARel.uaᴰ f (e , h) g .fst
-- An example where a DUARel is parameterized over a family of types
example2 : DUARel (autoUARel (A → Type)) (λ B → B a₀) ℓ-zero
example2 = autoDUARel _ _
example2' : {B C : A → Type} (e : (a : A) → B a ≃ C a)
(b : B a₀) (c : C a₀)
→ e a₀ .fst b ≡ c
→ PathP (λ i → ua (e a₀) i) b c
example2' e b c = example2 .DUARel.uaᴰ b e c .fst
| {
"alphanum_fraction": 0.5698778833,
"avg_line_length": 34.0153846154,
"ext": "agda",
"hexsha": "37e648d84cbeb35a844257e856739eb9f113640d",
"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/Displayed/Auto.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/Displayed/Auto.agda",
"max_line_length": 92,
"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/Displayed/Auto.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6291,
"size": 13266
} |
{-# OPTIONS --cubical --safe #-}
module Diatonic where
open import Data.Bool using (Bool; false; true; if_then_else_; _∧_)
open import Data.Empty using (⊥)
open import Data.Fin using (Fin; toℕ; #_; _≟_) renaming (zero to fz; suc to fs)
open import Data.Integer using (ℤ; +_; -[1+_]; _+_)
open import Data.Integer.DivMod using (_modℕ_)
open import Data.Nat using (ℕ; zero; suc; _∸_) renaming (_+_ to _+ℕ_; _≡ᵇ_ to _==_)
open import Data.Nat.DivMod using (_mod_)
open import Data.Unit using (⊤)
open import Data.Vec using (Vec; []; _∷_; head; foldl; take; reverse; lookup; updateAt)
open import Function using (_∘_)
open import Interval using (Upi; maj3; min3)
open import Pitch using (Pitch; s7; PC; pitchToClass)
data Mode : Set where
major : Mode
minor : Mode
DiatonicDegree : Set
DiatonicDegree = Fin s7
infix 4 _≡ᵈ_
_≡ᵈ_ : DiatonicDegree → DiatonicDegree → Bool
d ≡ᵈ e = toℕ d == toℕ e
-- round down
pitchClass→Degree : Mode → PC → DiatonicDegree
pitchClass→Degree major (fz) = # 0
pitchClass→Degree major ((fs fz)) = # 0
pitchClass→Degree major ((fs (fs fz))) = # 1
pitchClass→Degree major ((fs (fs (fs fz)))) = # 1
pitchClass→Degree major ((fs (fs (fs (fs fz))))) = # 2
pitchClass→Degree major ((fs (fs (fs (fs (fs fz)))))) = # 3
pitchClass→Degree major ((fs (fs (fs (fs (fs (fs fz))))))) = # 3
pitchClass→Degree major ((fs (fs (fs (fs (fs (fs (fs fz)))))))) = # 4
pitchClass→Degree major ((fs (fs (fs (fs (fs (fs (fs (fs fz))))))))) = # 4
pitchClass→Degree major ((fs (fs (fs (fs (fs (fs (fs (fs (fs fz)))))))))) = # 5
pitchClass→Degree major ((fs (fs (fs (fs (fs (fs (fs (fs (fs (fs fz))))))))))) = # 5
pitchClass→Degree major ((fs (fs (fs (fs (fs (fs (fs (fs (fs (fs (fs fz)))))))))))) = # 6
pitchClass→Degree minor (fz) = # 0
pitchClass→Degree minor ((fs fz)) = # 0
pitchClass→Degree minor ((fs (fs fz))) = # 1
pitchClass→Degree minor ((fs (fs (fs fz)))) = # 2
pitchClass→Degree minor ((fs (fs (fs (fs fz))))) = # 2
pitchClass→Degree minor ((fs (fs (fs (fs (fs fz)))))) = # 3
pitchClass→Degree minor ((fs (fs (fs (fs (fs (fs fz))))))) = # 3
pitchClass→Degree minor ((fs (fs (fs (fs (fs (fs (fs fz)))))))) = # 4
pitchClass→Degree minor ((fs (fs (fs (fs (fs (fs (fs (fs fz))))))))) = # 5
pitchClass→Degree minor ((fs (fs (fs (fs (fs (fs (fs (fs (fs fz)))))))))) = # 5
pitchClass→Degree minor ((fs (fs (fs (fs (fs (fs (fs (fs (fs (fs fz))))))))))) = # 6
pitchClass→Degree minor ((fs (fs (fs (fs (fs (fs (fs (fs (fs (fs (fs fz)))))))))))) = # 6
degree→PC : Mode → DiatonicDegree → PC
degree→PC major fz = (# 0)
degree→PC major (fs fz) = (# 2)
degree→PC major (fs (fs fz)) = (# 4)
degree→PC major (fs (fs (fs fz))) = (# 5)
degree→PC major (fs (fs (fs (fs fz)))) = (# 7)
degree→PC major (fs (fs (fs (fs (fs fz))))) = (# 9)
degree→PC major (fs (fs (fs (fs (fs (fs fz)))))) = (# 11)
degree→PC minor fz = (# 0)
degree→PC minor (fs fz) = (# 2)
degree→PC minor (fs (fs fz)) = (# 3)
degree→PC minor (fs (fs (fs fz))) = (# 5)
degree→PC minor (fs (fs (fs (fs fz)))) = (# 7)
degree→PC minor (fs (fs (fs (fs (fs fz))))) = (# 8)
degree→PC minor (fs (fs (fs (fs (fs (fs fz)))))) = (# 10)
pitch→DegreeCMajor : Pitch → DiatonicDegree
pitch→DegreeCMajor = pitchClass→Degree major ∘ pitchToClass
d1 d2 d3 d4 d5 d6 d7 : DiatonicDegree
d1 = # 0
d2 = # 1
d3 = # 2
d4 = # 3
d5 = # 4
d6 = # 5
d7 = # 6
data Accidental : Set where
♭3 : ℕ → Accidental -- 3+n flats
𝄫 : Accidental
♭ : Accidental
♮ : Accidental
♯ : Accidental
𝄪 : Accidental
♯3 : ℕ → Accidental -- 3+n sharps
-- pitch class letter name with accidental
data PCL : Set where
A : Accidental → PCL
B : Accidental → PCL
C : Accidental → PCL
D : Accidental → PCL
E : Accidental → PCL
F : Accidental → PCL
G : Accidental → PCL
-- Accidental modifier.
accMod : Accidental → ℤ
accMod (♭3 n) = -[1+ (n +ℕ 2) ]
accMod 𝄫 = -[1+ 1 ]
accMod ♭ = -[1+ 0 ]
accMod ♮ = + 0
accMod ♯ = + 1
accMod 𝄪 = + 2
accMod (♯3 n) = + (n +ℕ 3)
flatten : (a : Accidental) → Accidental
flatten (♭3 n) = ♭3 (suc n)
flatten 𝄫 = ♭3 zero
flatten ♭ = 𝄫
flatten ♮ = ♭
flatten ♯ = ♮
flatten 𝄪 = ♯
flatten (♯3 zero) = 𝄪
flatten (♯3 (suc n)) = ♯3 n
sharpen : Accidental → Accidental
sharpen (♭3 (suc n)) = ♭3 n
sharpen (♭3 zero) = 𝄫
sharpen 𝄫 = ♭
sharpen ♭ = ♮
sharpen ♮ = ♯
sharpen ♯ = 𝄪
sharpen 𝄪 = ♯3 zero
sharpen (♯3 n) = ♯3 (suc n)
-- Convert raw PCL letter to ℕ (in range [0,11]); C normalized to 0
letter→ℕ : PCL → ℕ
letter→ℕ (A _) = 9
letter→ℕ (B _) = 11
letter→ℕ (C _) = 0
letter→ℕ (D _) = 2
letter→ℕ (E _) = 4
letter→ℕ (F _) = 5
letter→ℕ (G _) = 7
accidental : PCL → Accidental
accidental (A x) = x
accidental (B x) = x
accidental (C x) = x
accidental (D x) = x
accidental (E x) = x
accidental (F x) = x
accidental (G x) = x
modifyAccidental : (Accidental → Accidental) → PCL → PCL
modifyAccidental f (A x) = A (f x)
modifyAccidental f (B x) = B (f x)
modifyAccidental f (C x) = C (f x)
modifyAccidental f (D x) = D (f x)
modifyAccidental f (E x) = E (f x)
modifyAccidental f (F x) = F (f x)
modifyAccidental f (G x) = G (f x)
-- Convert PCL to PC with C♮ normalized to 0.
pclToC : PCL → PC
pclToC pc = ((((+ (letter→ℕ pc)) + accMod (accidental pc)) modℕ 12) mod 12)
data Key : Set where
key : PCL → Mode → Key
keyMode : Key → Mode
keyMode (key _ mode) = mode
data Step : Set where
half : Step
whole : Step
stepUp : Step → PCL → PCL
stepUp half (A x) = B (flatten x)
stepUp half (B x) = C x
stepUp half (C x) = D (flatten x)
stepUp half (D x) = E (flatten x)
stepUp half (E x) = F x
stepUp half (F x) = G (flatten x)
stepUp half (G x) = A (flatten x)
stepUp whole (A x) = B x
stepUp whole (B x) = C (sharpen x)
stepUp whole (C x) = D x
stepUp whole (D x) = E x
stepUp whole (E x) = F (sharpen x)
stepUp whole (F x) = G x
stepUp whole (G x) = A x
scaleSteps : Mode → Vec Step s7
scaleSteps major = whole ∷ whole ∷ half ∷ whole ∷ whole ∷ whole ∷ half ∷ []
scaleSteps minor = whole ∷ half ∷ whole ∷ whole ∷ half ∷ whole ∷ whole ∷ []
scaleNotes : Key → Vec PCL s7
scaleNotes (key pc m) =
let f : {n : ℕ} → Vec PCL (suc n) → Step → Vec PCL (suc (suc n))
f pcs step = stepUp step (head pcs) ∷ pcs
in reverse (foldl (Vec PCL ∘ suc) f (pc ∷ []) (take 6 (scaleSteps m)))
data Root : Set where
I : Root
II : Root
III : Root
IV : Root
V : Root
VI : Root
VII : Root
data Quality : Set where
maj : Quality
min : Quality
aug : Quality
dim : Quality
_dd+_ : DiatonicDegree → ℕ → DiatonicDegree
d dd+ n = (toℕ d +ℕ n) mod s7
thirdUp : DiatonicDegree → DiatonicDegree
thirdUp d = d dd+ 2
data Triad : Set where
triad : Root → Quality → Triad
root→DiatonicDegree : Root → DiatonicDegree
root→DiatonicDegree I = d1
root→DiatonicDegree II = d2
root→DiatonicDegree III = d3
root→DiatonicDegree IV = d4
root→DiatonicDegree V = d5
root→DiatonicDegree VI = d6
root→DiatonicDegree VII = d7
diatonicDegree→Root : DiatonicDegree → Root
diatonicDegree→Root fz = I
diatonicDegree→Root (fs fz) = II
diatonicDegree→Root (fs (fs fz)) = III
diatonicDegree→Root (fs (fs (fs fz))) = IV
diatonicDegree→Root (fs (fs (fs (fs fz)))) = V
diatonicDegree→Root (fs (fs (fs (fs (fs fz))))) = VI
diatonicDegree→Root (fs (fs (fs (fs (fs (fs fz)))))) = VII
rootQuality : Mode → Root → Quality
rootQuality major I = maj
rootQuality major II = min
rootQuality major III = min
rootQuality major IV = maj
rootQuality major V = maj
rootQuality major VI = min
rootQuality major VII = dim
rootQuality minor I = min
rootQuality minor II = dim
rootQuality minor III = maj
rootQuality minor IV = min
rootQuality minor V = min
rootQuality minor VI = maj
rootQuality minor VII = maj
root→PC : Key → Root → PC
root→PC (key _ mode) = degree→PC mode ∘ root→DiatonicDegree
diatonicDegree→PCL : Key → DiatonicDegree → PCL
diatonicDegree→PCL k dd = lookup (scaleNotes k) dd
root→PCL : Key → Root → PCL
root→PCL k = diatonicDegree→PCL k ∘ root→DiatonicDegree
-- Lower interval is first.
triadQuality : Upi → Upi → Quality
triadQuality i1 i2 =
if (i1 == maj3) ∧ (i2 == min3) then maj
else if (i1 == min3) ∧ (i2 == maj3) then min
else if (i1 == min3) ∧ (i2 == min3) then dim
else if (i1 == maj3) ∧ (i2 == maj3) then aug
else maj -- should not happen
makeTriad : Mode → Root → Triad
makeTriad m r =
let d1 = root→DiatonicDegree r
d2 = thirdUp d1
d3 = thirdUp d2
p1 = degree→PC m d1
p2 = degree→PC m d2
p3 = degree→PC m d3
i1 = toℕ p2 ∸ toℕ p1 -- TODO: See if want to use ℤ
i2 = toℕ p3 ∸ toℕ p2
in triad r (triadQuality i1 i2)
diatonic7thNotes : Key → Root → Vec PCL 4
diatonic7thNotes k root =
let d1 = root→DiatonicDegree root
d2 = thirdUp d1
d3 = thirdUp d2
d4 = thirdUp d3
ns = scaleNotes k
in lookup ns d1 ∷ lookup ns d2 ∷ lookup ns d3 ∷ lookup ns d4 ∷ []
triadNotes : Key → Root → Vec PCL 3
triadNotes k = take 3 ∘ diatonic7thNotes k
_V/_ : Key → Root → Vec PCL 3
k V/ r = triadNotes (key (root→PCL k r) major) V
_V⁷/_ : Key → Root → Vec PCL 4
k V⁷/ r = diatonic7thNotes (key (root→PCL k r) major) V
_viiᵒ⁷/_ : Key → Root → Vec PCL 4
k viiᵒ⁷/ r = updateAt (# 3) (modifyAccidental flatten) (diatonic7thNotes (key (root→PCL k r) major) VII)
----------
a1 = triadNotes (key (G ♭) major) III
a2 = diatonic7thNotes (key (G ♯) major) V
a3 = diatonic7thNotes (key (E ♮) major) V
a4 = diatonic7thNotes (key (B ♭) major) VI
a5 = scaleNotes (key (G ♯) major)
a6 = scaleNotes (key (G ♭) major)
a7 = scaleNotes (key (B ♮) minor)
a8 = (key (G ♮) major) V/ V
a9 = (key (B ♭) major) V⁷/ II
a10 = (key (F ♯) minor) viiᵒ⁷/ III
| {
"alphanum_fraction": 0.548828125,
"avg_line_length": 32.3855421687,
"ext": "agda",
"hexsha": "9fbc27d28ae4fdc540d078da56f509932c16c4a2",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "agda/Diatonic.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "agda/Diatonic.agda",
"max_line_length": 104,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "agda/Diatonic.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 3857,
"size": 10752
} |
module MJSF.Examples.DynamicDispatch where
open import Prelude
open import Data.Star
open import Data.Bool
open import Data.List
open import Data.Integer
open import Data.List.Membership.Propositional
open import Data.List.Relation.Unary.Any
open import Data.List.Relation.Unary.All hiding (lookup)
open import Data.Product hiding (Σ)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable
k : ℕ
k = 10
open import MJSF.Syntax k
open import ScopesFrames.ScopesFrames k Ty
{-
class Int {
public int x;
public int get() {
System.out.println("never");
return x;
}
public int set(Int y) {
x = y.x;
return this.get();
}
}
class IntInc extends Int {
public int get() {
return x + 1;
}
public int inc(Int y) {
Int x = new Int();
x.x = y.x + 1;
return set(x);
}
}
class Main {
public static void main(String[] args) {
Int y = new Int();
y.x = 18;
IntInc x = new IntInc();
x.x = 0;
// should print 20 because we use the get() of IntInc
System.out.println(x.inc(y));
}
}
-}
Root : Scope
Root = # 0
Int : Scope
Int = # 1
IntInc : Scope
IntInc = # 2
-- Main class omitted; main() function is given below, as child scope
-- of the root scope.
classes : List Ty
classes = (cᵗ Root Int ∷
cᵗ Root IntInc ∷ [])
Int-methods Int-fields : List Ty
Int-fields =
{- x -} vᵗ int
∷ []
Int-methods =
{- Int.get -} mᵗ [] int ∷
{- Int.set -} mᵗ (ref Int ∷ []) int ∷
[]
IntInc-methods IntInc-fields : List Ty
IntInc-methods =
-- {- IntInc.get -} mᵗ [] int ∷
{- IntInc.inc -} mᵗ (ref Int ∷ []) int ∷
[]
IntInc-fields = []
g : Graph
-- root scope
g zero =
classes , []
-- class scope of Int class
g (suc zero) =
(Int-methods ++ Int-fields) , zero ∷ []
-- class scope of IntInc class
g (suc (suc zero)) =
(IntInc-methods ++ IntInc-fields) , zero ∷ # 1 ∷ []
-- scope of Int.get method; 3
g (suc (suc (suc zero))) =
[] , Int ∷ []
-- scope of Int.set method; 4
g (suc (suc (suc (suc zero)))) =
vᵗ (ref Int) ∷ [] , Int ∷ []
-- scope of IntInc.get method; 5
g (suc (suc (suc (suc (suc zero))))) =
[] , IntInc ∷ []
-- scope of IntInc.inc method; 6
g (suc (suc (suc (suc (suc (suc zero)))))) =
vᵗ (ref Int) ∷ [] , IntInc ∷ []
-- local variable scope of Int.inc method; 7
g (suc (suc (suc (suc (suc (suc (suc zero))))))) =
vᵗ (ref Int) ∷ [] , # 6 ∷ []
-- x local variable scope of Main.main method; 8
g (suc (suc (suc (suc (suc (suc (suc (suc zero)))))))) =
vᵗ (ref Int) ∷ [] , Root ∷ []
-- y local variable scope of Main.main method; 9
g (suc (suc (suc (suc (suc (suc (suc (suc (suc zero))))))))) =
vᵗ (ref IntInc) ∷ [] , # 8 ∷ []
g (suc (suc (suc (suc (suc (suc (suc (suc (suc (suc ()))))))))))
open SyntaxG g
open UsesGraph g
IntImpl : Class Root Int
IntImpl =
class0 {ms = Int-methods} {fs = Int-fields}
-- methods
(#m' (meth (# 3)
(body ε
(var (path ((here refl) ∷ []) (there (there (here refl))))))) ∷
(#m' (meth (# 4)
(body ( asgn (path ((here refl) ∷ [])
(there (there (here refl))))
(get (var (path [] (here refl)))
(path [] (there (there (here refl)))))
◅ ε)
(call (this [] (here refl))
(path [] (here refl))
[])))) ∷ [])
-- fields
((#v' tt) ∷ [])
-- overrides
[]
IntIncImpl : Class Root IntInc
IntIncImpl =
class1 {ms = IntInc-methods} {fs = IntInc-fields}
-- path to parent
(path [] (here refl))
-- methods
(#m'
(meth
(# 6)
(body
( loc (# 7) (ref Int)
◅ asgn (path [] (here refl))
(new (path ((here refl) ∷ ((here refl) ∷ ((here refl) ∷ [])))
(here refl)))
◅ set (var (path [] (here refl)))
(path [] (there (there (here refl))))
(iop Data.Integer._+_
(get (var (path ((here refl) ∷ []) (here refl)))
(path [] (there (there (here refl)))))
(num (+ 1)))
◅ ε)
(call (this (here refl ∷ []) (here refl))
(path (there (here refl) ∷ []) (there (here refl)))
((var (path [] (here refl))) ∷ [])))) ∷
[])
-- fields
[]
-- overrides
(#m'
(path ((there (here refl)) ∷ []) (here refl) ,
(meth
(# 5)
(body
ε
(iop Data.Integer._+_
(var (path ((here refl) ∷ ((there (here refl)) ∷ []))
(there (there (here refl)))))
(num (+ 1)))))) ∷ [])
main : Body Root int
main =
body
( (loc (# 8) (ref Int))
◅ asgn (path [] (here refl))
(new (path (here refl ∷ []) (here refl)))
◅ set (var (path [] (here refl)))
(path [] (there (there (here refl))))
(num (+ 18))
◅ loc (# 9) (ref IntInc)
◅ asgn (path [] (here refl))
(new (path (here refl ∷ here refl ∷ [])
(there (here refl))))
◅ set (var (path [] (here refl)))
(path (there (here refl) ∷ []) (there (there (here refl))))
(num (+ 0))
◅ ε)
(call (var (path [] (here refl)))
(path [] (here refl))
(var (path ((here refl) ∷ []) (here refl)) ∷ []))
p : Program Root int
p = program classes
(#c' (IntImpl , Int , obj Int ⦃ refl ⦄) ∷
(#c' (IntIncImpl , Int , (super ⦃ refl ⦄ (obj Int ⦃ refl ⦄)))) ∷
[]) main
open import MJSF.Semantics
open Semantics _ g
open import MJSF.Values
open ValuesG _ g
test : p ⇓⟨ 100 ⟩ (λ v → v ≡ num (+ 20) )
test = refl
| {
"alphanum_fraction": 0.4830335935,
"avg_line_length": 25.188034188,
"ext": "agda",
"hexsha": "4949fa5ce1426383069fe3b5b9d5b6370d164fad",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJSF/Examples/DynamicDispatch.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJSF/Examples/DynamicDispatch.agda",
"max_line_length": 84,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJSF/Examples/DynamicDispatch.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 1851,
"size": 5894
} |
-- Andreas, 2016-12-31, issue #2374
-- Use hiding info to disambiguate overloaded projections.
-- {-# OPTIONS -v tc.lhs.split:40 #-}
postulate A B : Set
module M where
record R : Set₂ where
field
F : Set₁
module Order1 where
open M.R
open M.R {{...}}
test : M.R
F test = Set
inst : M.R
F {{inst}} = Set
module Order2 where
open M.R {{...}}
open M.R
test : M.R
F test = Set
inst : M.R
F {{inst}} = Set
module N (A : Set) where
record R : Set₂ where
field
F : Set₁
module Par1 where
open N.R {A = A}
module RB = N.R {A = B}; open RB {{...}}
test : N.R A
F test = Set
inst : N.R B
F {{inst}} = Set
module Par2 where
module RA = N.R {A = A}; open RA {{...}}
open N.R {A = B}
test : N.R B
F test = Set
inst : N.R A
F {{inst}} = Set
-- All should be accepted.
| {
"alphanum_fraction": 0.5455621302,
"avg_line_length": 13.8524590164,
"ext": "agda",
"hexsha": "4caf8c7d3f2a1f2f825f8fe0ee137c3cf4d8d6ae",
"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/Issue2374.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/Issue2374.agda",
"max_line_length": 58,
"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/Issue2374.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": 303,
"size": 845
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.Vec.Relation.Binary.Equality.Setoid directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Data.Vec.Relation.Equality.Setoid
{a ℓ} (S : Setoid a ℓ) where
open import Data.Vec.Relation.Binary.Equality.Setoid S public
{-# WARNING_ON_IMPORT
"Data.Vec.Relation.Equality.Setoid was deprecated in v1.0.
Use Data.Vec.Relation.Binary.Equality.Setoid instead."
#-}
| {
"alphanum_fraction": 0.5707317073,
"avg_line_length": 29.2857142857,
"ext": "agda",
"hexsha": "56d85f6de78180ae4c96abb7f0daf1175e674d62",
"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/Vec/Relation/Equality/Setoid.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/Vec/Relation/Equality/Setoid.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/Vec/Relation/Equality/Setoid.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": 130,
"size": 615
} |
{-# OPTIONS --without-K #-}
--open import HoTT
open import homotopy.3x3.PushoutPushout
open import homotopy.3x3.Transpose
import homotopy.3x3.To as To
import homotopy.3x3.From as From
open import homotopy.3x3.Common
module homotopy.3x3.ToFrom3 {i} (d : Span^2 {i}) where
open Span^2 d
open M d hiding (Pushout^2)
open M (transpose d) using () renaming (A₀∙ to A∙₀; A₂∙ to A∙₂; A₄∙ to A∙₄;
module F₁∙ to F∙₁; f₁∙ to f∙₁;
module F₃∙ to F∙₃; f₃∙ to f∙₃;
v-h-span to h-v-span)
open M using (Pushout^2)
open To d
open From d
open import homotopy.3x3.ToFromInit d
open import homotopy.3x3.ToFrom2 d
module M3 (c : A₂₂) where
open M2 c
lemma2-3 =
ap□ to (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)
∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /)
=⟨ ap□-∙□-i/ to _ (E∙₂Red.lhs-o c) (E∙₂Red.rhs-o c) ⟩
ap□ to (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /))
∙□-i/ ap (ap to) (E∙₂Red.lhs-o c) / ap (ap to) (E∙₂Red.rhs-o c) /
=⟨ lemma2-4 |in-ctx (λ u → u ∙□-i/ ap (ap to) (E∙₂Red.lhs-o c) / ap (ap to) (E∙₂Red.rhs-o c) /) ⟩
↓-='-out (apd (glue {d = h-v-span}) (glue c))
∙□-i/ E₂∙Red.lhs-i c / E₂∙Red.rhs-i c /
∙□-o/ ∘-ap to left (glue (f₁₂ c)) ∙ I₀∙.glue-β (f₁₂ c) / ! (∘-ap to right (glue (f₃₂ c)) ∙ I₄∙.glue-β (f₃₂ c)) /
∙□-i/ (To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c)))
/ (! (To.glue-β (left (f₂₁ c)))) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)) /
∙□-i/ E∙₂Red.ap-ap-coh!-lhs-o c to / E∙₂Red.ap-ap-coh!-rhs-o c to /
∙□-i/ ap (ap to) (E∙₂Red.lhs-o c) / ap (ap to) (E∙₂Red.rhs-o c) / ∎
lemma2'-3 =
ap-∘ to (i∙₄ ∘ f∙₃) (glue c)
∙ ap (ap to) (E∙₂Red.lhs-o c)
∙ E∙₂Red.ap-ap-coh!-lhs-o c to
∙ ((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))
∙ E₂∙Red.lhs-i c
=⟨ coh2 (ap to)
(ap-∘ to (i∙₄ ∘ f∙₃) (glue c))
(ap-∘ i∙₄ f∙₃ (glue c))
_
_
_
(ap-∙∙!'`∘`∘ to (left ∘ right) (right ∘ right) (H₁₃ c) (glue (right (f₂₃ c))) (H₃₃ c))
((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))
(! (ap-∙∙!`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c)))
(ap-! (ap right) (F∙₃.glue-β c))
_
⟩
(ap-∘ to (i∙₄ ∘ f∙₃) (glue c)
∙ ap (ap to) (ap-∘ i∙₄ f∙₃ (glue c))
∙ ap (ap to) (F∙₃.glue-β c |in-ctx (ap i∙₄)))
∙ (ap (ap to) (ap-∙∙!`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c))
∙ ap (ap to) (I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))
∙ ap-∙∙!'`∘`∘ to (left ∘ right) (right ∘ right) (H₁₃ c) (glue (right (f₂₃ c))) (H₃₃ c))
∙ (((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))
∙ ! (ap-∙∙!`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ∘-ap right f∙₃ (glue c))
=⟨ ap-∘-ap-∙∙!'2`∘`∘-coh to i∙₄ left right (H₁₃ c) (I∙₄.glue-β (f₂₃ c)) (H₃₃ c)
|in-ctx (λ u → (ap-∘ to (i∙₄ ∘ f∙₃) (glue c)
∙ ap (ap to) (ap-∘ i∙₄ f∙₃ (glue c))
∙ ap (ap to) (F∙₃.glue-β c |in-ctx (ap i∙₄)))
∙ u
∙ (((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))
∙ ! (ap-∙∙!`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ∘-ap right f∙₃ (glue c))) ⟩
(ap-∘ to (i∙₄ ∘ f∙₃) (glue c)
∙ ap (ap to) (ap-∘ i∙₄ f∙₃ (glue c))
∙ ap (ap to) (F∙₃.glue-β c |in-ctx (ap i∙₄)))
∙ (ap (ap to) (ap-∙∙`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c)))
∙ ap (ap to) (I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ ap-∙∙!`∘`∘ to (left ∘ right) (right ∘ right) (H₁₃ c) (glue (right (f₂₃ c))) (H₃₃ c))
∙ (((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))
∙ ! (ap-∙∙!`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ∘-ap right f∙₃ (glue c))
=⟨ coh5 (ap-∘ to (i∙₄ ∘ f∙₃) (glue c)
∙ ap (ap to) (ap-∘ i∙₄ f∙₃ (glue c))
∙ ap (ap to) (F∙₃.glue-β c |in-ctx (ap i∙₄)))
(ap (ap to) (ap-∙∙`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c))))
(ap (ap to) (I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c)))))
(ap-∙∙!`∘`∘ to (left ∘ right) (right ∘ right) (H₁₃ c) (glue (right (f₂₃ c))) (H₃₃ c))
((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))
(! (ap-∙∙!`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c)))
(! (ap (ap right) (F∙₃.glue-β c)) ∙ ∘-ap right f∙₃ (glue c))
(ap-∙∙`∘`∘ to (left ∘ right) (right ∘ right) (H₁₃ c) (glue (right (f₂₃ c))) (! (H₃₃ c)))
((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
(! (ap-∙∙`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c))))
(ap-! (right ∘ right) (H₃₃ c) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ ap right (glue (f₂₃ c)) ∙ u))
(ap-∙∙!`∘`∘-coh1 to (left ∘ right) (right ∘ right) (H₁₃ c) (To.glue-β (right (f₂₃ c))) (H₃₃ c))
(ap-∙∙!`∘`∘-coh2 right left right (H₁₃ c) {glue (f₂₃ c)} (H₃₃ c))
⟩
(ap-∘ to (i∙₄ ∘ f∙₃) (glue c)
∙ ap (ap to) (ap-∘ i∙₄ f∙₃ (glue c))
∙ ap (ap to) (F∙₃.glue-β c |in-ctx (ap i∙₄)))
∙ (ap (ap to) (ap-∙∙`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c)))
∙ ap (ap to) (I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ ap-∙∙`∘`∘ to (left ∘ right) (right ∘ right) (H₁₃ c) (glue (right (f₂₃ c))) (! (H₃₃ c)))
∙ (((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ ! (ap-∙∙`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c)))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ∘-ap right f∙₃ (glue c))
=⟨ ap-∘-ap-∙∙`∘`∘-coh to i∙₄ left right (H₁₃ c) (I∙₄.glue-β (f₂₃ c)) (! (H₃₃ c))
|in-ctx (λ u →
(ap-∘ to (i∙₄ ∘ f∙₃) (glue c)
∙ ap (ap to) (ap-∘ i∙₄ f∙₃ (glue c))
∙ ap (ap to) (F∙₃.glue-β c |in-ctx (ap i∙₄)))
∙ u
∙ (((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ ! (ap-∙∙`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c)))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ∘-ap right f∙₃ (glue c))) ⟩
(ap-∘ to (i∙₄ ∘ f∙₃) (glue c)
∙ ap (ap to) (ap-∘ i∙₄ f∙₃ (glue c))
∙ ap (ap to) (F∙₃.glue-β c |in-ctx (ap i∙₄)))
∙ (∘-ap to i∙₄ (ap left (H₁₃ c) ∙ glue (f₂₃ c) ∙ ap right (! (H₃₃ c)))
∙ ap-∙∙`∘`∘ (to ∘ i∙₄) left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c))
∙ (ap-∘ to i∙₄ (glue (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ (ap (ap to) (I∙₄.glue-β (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c)))))
∙ (((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ (! (ap-∙∙`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c))))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ∘-ap right f∙₃ (glue c))
=⟨ coh3 (ap-∘ to (i∙₄ ∘ f∙₃) (glue c))
(ap (ap to) (ap-∘ i∙₄ f∙₃ (glue c)))
(ap (ap to) (F∙₃.glue-β c |in-ctx (ap i∙₄)))
(∘-ap to i∙₄ (ap left (H₁₃ c) ∙ glue (f₂₃ c) ∙ ap right (! (H₃₃ c))))
_
_ ⟩
(ap-∘ to (i∙₄ ∘ f∙₃) (glue c)
∙ ap (ap to) (ap-∘ i∙₄ f∙₃ (glue c))
∙ ap (ap to) (F∙₃.glue-β c |in-ctx (ap i∙₄))
∙ ∘-ap to i∙₄ (ap left (H₁₃ c) ∙ glue (f₂₃ c) ∙ ap right (! (H₃₃ c))))
∙ (ap-∙∙`∘`∘ (to ∘ i∙₄) left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c))
∙ (ap-∘ to i∙₄ (glue (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ (ap (ap to) (I∙₄.glue-β (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c)))))
∙ ((To.glue-β (right (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ ! (ap-∙∙`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c)))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ∘-ap right f∙₃ (glue c))
=⟨ ap-∘-coh to i∙₄ f∙₃ (glue c) (F∙₃.glue-β c)
|in-ctx (λ u → u ∙ (ap-∙∙`∘`∘ (to ∘ i∙₄) left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c))
∙ (ap-∘ to i∙₄ (glue (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ (ap (ap to) (I∙₄.glue-β (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c)))))
∙ ((To.glue-β (right (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ ! (ap-∙∙`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c)))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ∘-ap right f∙₃ (glue c))) ⟩
(ap-∘ (to ∘ i∙₄) f∙₃ (glue c)
∙ (ap (ap (to ∘ i∙₄)) (F∙₃.glue-β c)))
∙ (ap-∙∙`∘`∘ (to ∘ i∙₄) left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c))
∙ (ap-∘ to i∙₄ (glue (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ (ap (ap to) (I∙₄.glue-β (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c)))))
∙ ((To.glue-β (right (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ ! (ap-∙∙`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c)))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ∘-ap right f∙₃ (glue c))
=⟨ !-ap-∘-inv right f∙₃ (glue c)
|in-ctx (λ u → (ap-∘ (to ∘ i∙₄) f∙₃ (glue c)
∙ (ap (ap (to ∘ i∙₄)) (F∙₃.glue-β c)))
∙ (ap-∙∙`∘`∘ (to ∘ i∙₄) left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c))
∙ (ap-∘ to i∙₄ (glue (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ (ap (ap to) (I∙₄.glue-β (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c)))))
∙ ((To.glue-β (right (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ ! (ap-∙∙`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c)))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ u)) ⟩
(ap-∘ (to ∘ i∙₄) f∙₃ (glue c)
∙ (ap (ap (to ∘ i∙₄)) (F∙₃.glue-β c)))
∙ (ap-∙∙`∘`∘ (to ∘ i∙₄) left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c))
∙ (ap-∘ to i∙₄ (glue (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ (ap (ap to) (I∙₄.glue-β (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c)))))
∙ ((To.glue-β (right (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ ! (ap-∙∙`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c)))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ! (ap-∘ right f∙₃ (glue c)))
=⟨ !-∘-ap-inv (to ∘ i∙₄) f∙₃ (glue c)
|in-ctx (λ u → (u
∙ (ap (ap (to ∘ i∙₄)) (F∙₃.glue-β c)))
∙ (ap-∙∙`∘`∘ (to ∘ i∙₄) left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c))
∙ (ap-∘ to i∙₄ (glue (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ (ap (ap to) (I∙₄.glue-β (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c)))))
∙ ((To.glue-β (right (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ ! (ap-∙∙`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c)))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ! (ap-∘ right f∙₃ (glue c)))) ⟩
(! (∘-ap (to ∘ i∙₄) f∙₃ (glue c))
∙ (ap (ap (to ∘ i∙₄)) (F∙₃.glue-β c)))
∙ (ap-∙∙`∘`∘ (to ∘ i∙₄) left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c))
∙ (ap-∘ to i∙₄ (glue (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ (ap (ap to) (I∙₄.glue-β (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c)))))
∙ ((To.glue-β (right (f₂₃ c)) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c))))
∙ ! (ap-∙∙`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (! (H₃₃ c)))
∙ ! (ap (ap right) (F∙₃.glue-β c))
∙ ! (ap-∘ right f∙₃ (glue c)))
=⟨ coh4 (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ap (right ∘ right) (! (H₃₃ c)))
(∘-ap (to ∘ i∙₄) f∙₃ (glue c)) _ _ _ _ _ _ _ _ ⟩
! end-lemma1 ∎ where
coh2 : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {a b c d e : A} {g h k l m n : B}
(p : g == f a) (q : a == b) (r : b == c) (s : c == d) (t : d == e) (u : f e == h) (v : h == k)
(w : k == l) {x x' : l == m} (eq-x : x == x') (y : m == n)
→ p ∙ ap f (_ =⟨ q ⟩ _ =⟨ r ⟩ _ =⟨ s ⟩ _ =⟨ t ⟩ _ ∎) ∙ u ∙ v ∙ (_ =⟨ w ⟩ _ =⟨ x ⟩ _ =⟨ y ⟩ _ ∎)
== (p ∙ ap f q ∙ ap f r) ∙ (ap f s ∙ ap f t ∙ u) ∙ (v ∙ w ∙ x' ∙ y)
coh2 f p idp idp idp idp idp idp idp {x = idp} idp idp = ! (∙-unit-r (p ∙ idp))
coh3 : ∀ {i} {A : Type i} {a b c d e f g : A} (p : a == b) (q : b == c) (r : c == d) (s : d == e)
(t : e == f) (u : f == g)
→ (p ∙ q ∙ r) ∙ (s ∙ t) ∙ u == (p ∙ q ∙ r ∙ s) ∙ t ∙ u
coh3 idp idp idp idp idp idp = idp
coh4 : ∀ {i j} {A : Type i} {B : Type j} (h : A → B)
{a b c d : A} {e f g k l m : B} (p : f == e) (q : f == g) (r : g == h a) (s : a == b) (t : b == c)
(u : c == d) (v : k == h d) (w : l == k) (x : m == l)
→ (! p ∙ q) ∙ (r ∙ (s |in-ctx h) ∙ (t |in-ctx h)) ∙ ((u |in-ctx h) ∙ (! v) ∙ (! w) ∙ ! x)
== ! (_ =⟨ x ⟩ _ =⟨ w ⟩ _ =⟨ v ⟩ _ =⟨ ! (_ =⟨ s ⟩ _ =⟨ t ⟩ _ =⟨ u ⟩ _ ∎) |in-ctx h ⟩ _ =⟨ ! r ⟩ _ =⟨ ! q ⟩ _ =⟨ p ⟩ _ ∎)
coh4 h idp idp r idp idp idp v idp idp = ch r v where
ch : ∀ {i} {B : Type i} {a b c : B} (r : a == b) (v : c == b)
→ (r ∙ idp) ∙ ! v ∙ idp == ! (_ =⟨ idp ⟩ _ =⟨ idp ⟩ _ =⟨ v ⟩ _ =⟨ idp ⟩ _ =⟨ ! r ⟩ _ ∎)
ch idp idp = idp
coh5 : ∀ {i} {A : Type i} {a b c d e e' f f' g h : A} (p : a == b) (q : b == c)
(r : c == d) (s : d == e) (t : e == f) (u : f == g) (v : g == h) (s' : d == e')
(t' : e' == f') (u' : f' == g) (w : f' == f) (α : s ∙ t == s' ∙ t' ∙ w) (β : w ∙ u == u')
→ p ∙ (q ∙ r ∙ s) ∙ (t ∙ u ∙ v)
== p ∙ (q ∙ r ∙ s') ∙ (t' ∙ u' ∙ v)
coh5 idp idp idp idp idp idp idp idp idp ._ ._ idp idp = idp
lemma2'-4 =
E₂∙Red.rhs-i c
∙ ((! (To.glue-β (left (f₂₁ c)))) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)))
∙ E∙₂Red.ap-ap-coh!-rhs-o c to
∙ ap (ap to) (E∙₂Red.rhs-o c)
∙ ∘-ap to (i∙₀ ∘ f∙₁) (glue c)
=⟨ coh2 (ap to)
(ap-∘ left f∙₁ (glue c))
(F∙₁.glue-β c |in-ctx (ap left))
(ap-!∙∙`∘`∘ left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))
((! (To.glue-β (left (f₂₁ c)))) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)))
(ap-∘ to (i∙₀ ∘ f∙₁) (glue c))
(ap-∘ i∙₀ f∙₁ (glue c))
((F∙₁.glue-β c) |in-ctx ap i∙₀)
(ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))
((I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)))
(ap-!'∙∙`∘`∘ to (left ∘ left) (right ∘ left) (H₁₁ c) (glue (left (f₂₁ c))) (H₃₁ c))
(!-ap (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)) (I∙₀.glue-β (f₂₁ c)))
(!-ap (ap i∙₀) (F∙₁.glue-β c))
(!-ap-∘ i∙₀ f∙₁ (glue c))
(!-∘-ap to (i∙₀ ∘ f∙₁) (glue c)) ⟩
ap-∘ left f∙₁ (glue c)
∙ (F∙₁.glue-β c |in-ctx (ap left))
∙ (ap-!∙∙`∘`∘ left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))
∙ ((! (To.glue-β (left (f₂₁ c)))) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)))
∙ ! ((ap-∘ to (i∙₀ ∘ f∙₁) (glue c)
∙ ap (ap to) (ap-∘ i∙₀ f∙₁ (glue c))
∙ ap (ap to) ((F∙₁.glue-β c) |in-ctx (λ u → ap i∙₀ u)))
∙ (ap (ap to) (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))
∙ ap (ap to) ((I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)))
∙ ap-!'∙∙`∘`∘ to (left ∘ left) (right ∘ left) (H₁₁ c) (glue (left (f₂₁ c))) (H₃₁ c)))
=⟨ lm |in-ctx (λ u →
ap-∘ left f∙₁ (glue c)
∙ ap (ap left) (F∙₁.glue-β c)
∙ ap-!∙∙`∘`∘ left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)
∙ ((! (To.glue-β (left (f₂₁ c)))) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)))
∙ ! u) ⟩
ap-∘ left f∙₁ (glue c)
∙ (F∙₁.glue-β c |in-ctx (ap left))
∙ ap-!∙∙`∘`∘ left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)
∙ ((! (To.glue-β (left (f₂₁ c)))) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)))
∙ ! ((ap-∘ (to ∘ i∙₀) f∙₁ (glue c)
∙ ap (ap (to ∘ i∙₀)) (F∙₁.glue-β c))
∙ (ap-∙∙`∘`∘ (to ∘ i∙₀) left right (! (H₁₁ c)) (glue (f₂₁ c)) (H₃₁ c)
∙ (ap-∘ to i∙₀ (glue (f₂₁ c)) |in-ctx (λ u → ap (left ∘ left) (! (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)))
∙ ((I∙₀.glue-β (f₂₁ c) |in-ctx ap to) |in-ctx (λ u → ap (left ∘ left) (! (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)))
∙ (ap-! (left ∘ left) (H₁₁ c) |in-ctx (λ u → u ∙ ap to (glue (left (f₂₁ c))) ∙ ap (left ∘ right) (H₃₁ c)))))
=⟨ coh3 {f = λ u → ap (left ∘ left) (! (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)}
{p = ap-∘ left f∙₁ (glue c)}
{ap (ap left) (F∙₁.glue-β c)}
{ap-∙∙`∘`∘ left left right (! (H₁₁ c)) (glue (f₂₁ c)) (H₃₁ c)}
{ap-∘ to i∙₀ (glue (f₂₁ c))}
{I∙₀.glue-β (f₂₁ c) |in-ctx ap to}
{To.glue-β (left (f₂₁ c))}
{ap-∙∙`∘`∘ (to ∘ i∙₀) left right (! (H₁₁ c)) (glue (f₂₁ c)) (H₃₁ c)}
{ap (ap (to ∘ i∙₀)) (F∙₁.glue-β c)}
{ap-∘ (to ∘ i∙₀) f∙₁ (glue c)}
(!-ap-∘ (to ∘ i∙₀) f∙₁ (glue c))
{ap-!∙∙`∘`∘ left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)}
{(! (To.glue-β (left (f₂₁ c)))) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c))}
{ap-! (left ∘ left) (H₁₁ c) |in-ctx (λ u → u ∙ ap to (glue (left (f₂₁ c))) ∙ ap (left ∘ right) (H₃₁ c))}
(ap-!∙∙`∘`∘-coh left left right (H₁₁ c) (! (To.glue-β (left (f₂₁ c)))) (H₃₁ c)) ⟩
end-lemma3 ∎ where
coh2 : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {a b c d e o : B} (p : a == b) (q : b == c) (r : c == d) (s : d == e)
{g h l m n : A} (y : o == f g) (x : g == h) (w : h == l) (v : l == m) (u : m == n) (t : f n == e)
{u' : n == m} (γ : ! u == u') {w' : l == h} (δ : ! w == w') {x' : h == g} (α : ! x == x') {y' : f g == o} (β : ! y' == y)
→
(_ =⟨ p ⟩ _ =⟨ q ⟩ _ =⟨ r ⟩ _ ∎) ∙ s ∙ ! t ∙ ap f (_ =⟨ u' ⟩ _ =⟨ ! v ⟩ _ =⟨ w' ⟩ _ =⟨ x' ⟩ _ ∎) ∙ y'
== p ∙ q ∙ r ∙ s ∙ ! ((y ∙ ap f x ∙ ap f w) ∙ (ap f v ∙ ap f u ∙ t))
coh2 f idp idp idp idp .idp idp idp idp idp idp idp idp idp {y' = idp} idp = idp
coh3 : ∀ {i j} {A : Type i} {B : Type j} {f : A → B} {a b c d e g o o' : B} {h k l m : A}
{p : a == b} {q : b == c} {r : c == f m} {v : h == k} {w : k == l} {x : l == m}
{s : d == f h} {t : e == d} {u : g == e} {u' : e == g} (α : ! u == u')
{r' : c == o} {x' : o == o'} {y : f l == o'}
(β : (r' ∙ x' ∙ ! y) == (r ∙' (! x |in-ctx f)))
→
p ∙ q ∙ r' ∙ x' ∙ ! ((u ∙ t) ∙ (s ∙ (v |in-ctx f) ∙ (w |in-ctx f) ∙ y))
==
(_ =⟨ p ⟩ _ =⟨ q ⟩ _ =⟨ r ⟩ _ =⟨ ! (_ =⟨ v ⟩ _ =⟨ w ⟩ _ =⟨ x ⟩ _ ∎) |in-ctx f ⟩
_ =⟨ ! s ⟩ _ =⟨ ! t ⟩ _ =⟨ u' ⟩ _ ∎)
coh3 {p = idp} {idp} {._} {idp} {idp} {idp} {s} {idp} {idp} idp {idp} {idp} {y} idp = coh' s y where
coh' : ∀ {i} {B : Type i} {a b c : B} (s : a == b) (y : b == c)
→ ! (s ∙ y) == (_ =⟨ idp ⟩ _ =⟨ idp ⟩ _ =⟨ ! y ⟩ _ =⟨ idp ⟩ _ =⟨ ! s ⟩ _ ∎)
coh' idp idp = idp
lm =
(ap-∘ to (i∙₀ ∘ f∙₁) (glue c)
∙ ap (ap to) (ap-∘ i∙₀ f∙₁ (glue c))
∙ ap (ap to) ((F∙₁.glue-β c) |in-ctx (λ u → ap i∙₀ u)))
∙ (ap (ap to) (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))
∙ ap (ap to) ((I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)))
∙ ap-!'∙∙`∘`∘ to (left ∘ left) (right ∘ left) (H₁₁ c) (glue (left (f₂₁ c))) (H₃₁ c))
=⟨ ap-∘-coh2 to i∙₀ f∙₁ (glue c) (F∙₁.glue-β c) |in-ctx (λ u → u ∙ (ap (ap to) (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))
∙ ap (ap to) ((I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)))
∙ ap-!'∙∙`∘`∘ to (left ∘ left) (right ∘ left) (H₁₁ c) (glue (left (f₂₁ c))) (H₃₁ c))) ⟩
(ap-∘ (to ∘ i∙₀) f∙₁ (glue c)
∙ ap (ap (to ∘ i∙₀)) (F∙₁.glue-β c)
∙ ap-∘ to i∙₀ (ap left (! (H₁₁ c)) ∙ glue (f₂₁ c) ∙ ap right (H₃₁ c)))
∙ (ap (ap to) (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))
∙ ap (ap to) ((I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)))
∙ ap-!'∙∙`∘`∘ to (left ∘ left) (right ∘ left) (H₁₁ c) (glue (left (f₂₁ c))) (H₃₁ c))
=⟨ assoc (ap-∘ (to ∘ i∙₀) f∙₁ (glue c))
(ap (ap (to ∘ i∙₀)) (F∙₁.glue-β c))
(ap-∘ to i∙₀ (ap left (! (H₁₁ c)) ∙ glue (f₂₁ c) ∙ ap right (H₃₁ c)))
(ap (ap to) (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)))
(ap (ap to) ((I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c))))
(ap-!'∙∙`∘`∘ to (left ∘ left) (right ∘ left) (H₁₁ c) (glue (left (f₂₁ c))) (H₃₁ c)) ⟩
(ap-∘ (to ∘ i∙₀) f∙₁ (glue c)
∙ ap (ap (to ∘ i∙₀)) (F∙₁.glue-β c))
∙ (ap-∘ to i∙₀ (ap left (! (H₁₁ c)) ∙ glue (f₂₁ c) ∙ ap right (H₃₁ c))
∙ ap (ap to) (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))
∙ ap (ap to) ((I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)))
∙ ap-!'∙∙`∘`∘ to (left ∘ left) (right ∘ left) (H₁₁ c) (glue (left (f₂₁ c))) (H₃₁ c))
=⟨ ap-∘-ap-∙∙5`∘`∘-coh to i∙₀ left right (H₁₁ c) (I∙₀.glue-β (f₂₁ c)) (H₃₁ c) |in-ctx (λ u → (ap-∘ (to ∘ i∙₀) f∙₁ (glue c) ∙ ap (ap (to ∘ i∙₀)) (F∙₁.glue-β c)) ∙ u) ⟩
(ap-∘ (to ∘ i∙₀) f∙₁ (glue c)
∙ ap (ap (to ∘ i∙₀)) (F∙₁.glue-β c))
∙ (ap-∙∙`∘`∘ (to ∘ i∙₀) left right (! (H₁₁ c)) (glue (f₂₁ c)) (H₃₁ c)
∙ (ap-∘ to i∙₀ (glue (f₂₁ c)) |in-ctx (λ u → ap (left ∘ left) (! (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)))
∙ ((I∙₀.glue-β (f₂₁ c) |in-ctx ap to) |in-ctx (λ u → ap (left ∘ left) (! (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)))
∙ (ap-! (left ∘ left) (H₁₁ c) |in-ctx (λ u → u ∙ ap to (glue (left (f₂₁ c))) ∙ ap (left ∘ right) (H₃₁ c)))) ∎ where
assoc : ∀ {i} {A : Type i} {a b c d e f g : A} (p : a == b) (q : b == c) (r : c == d) (s : d == e) (t : e == f) (u : f == g)
→ (p ∙ q ∙ r) ∙ (s ∙ t ∙ u) == (p ∙ q) ∙ (r ∙ s ∙ t ∙ u)
assoc idp idp idp idp idp idp = idp
lemma2-2' =
ap□ to (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)
∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /)
∙□-i/ ap-∘ to (i∙₄ ∘ f∙₃) (glue c) / ∘-ap to (i∙₀ ∘ f∙₁) (glue c) /
=⟨ lemma2-3 |in-ctx (λ u → u ∙□-i/ ap-∘ to (i∙₄ ∘ f∙₃) (glue c) / ∘-ap to (i∙₀ ∘ f∙₁) (glue c) /) ⟩
↓-='-out (apd (glue {d = h-v-span}) (glue c))
∙□-i/ E₂∙Red.lhs-i c / E₂∙Red.rhs-i c /
∙□-o/ ∘-ap to left (glue (f₁₂ c)) ∙ I₀∙.glue-β (f₁₂ c) / ! (∘-ap to right (glue (f₃₂ c)) ∙ I₄∙.glue-β (f₃₂ c)) /
∙□-i/ (To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c)))
/ (! (To.glue-β (left (f₂₁ c)))) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)) /
∙□-i/ E∙₂Red.ap-ap-coh!-lhs-o c to / E∙₂Red.ap-ap-coh!-rhs-o c to /
∙□-i/ ap (ap to) (E∙₂Red.lhs-o c) / ap (ap to) (E∙₂Red.rhs-o c) /
∙□-i/ ap-∘ to (i∙₄ ∘ f∙₃) (glue c) / ∘-ap to (i∙₀ ∘ f∙₁) (glue c) /
=⟨ assoc (↓-='-out (apd (glue {d = h-v-span}) (glue c))) (E₂∙Red.lhs-i c) ((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c)))) (E∙₂Red.ap-ap-coh!-lhs-o c to) (ap (ap to) (E∙₂Red.lhs-o c)) (ap-∘ to (i∙₄ ∘ f∙₃) (glue c)) _ _ _ _ _ (∘-ap to left (glue (f₁₂ c)) ∙ I₀∙.glue-β (f₁₂ c)) _ ⟩
↓-='-out (apd (glue {d = h-v-span}) (glue c))
∙□-o/ ∘-ap to left (glue (f₁₂ c)) ∙ I₀∙.glue-β (f₁₂ c) / ! (∘-ap to right (glue (f₃₂ c)) ∙ I₄∙.glue-β (f₃₂ c)) /
∙□-i/ ap-∘ to (i∙₄ ∘ f∙₃) (glue c)
∙ ap (ap to) (E∙₂Red.lhs-o c)
∙ E∙₂Red.ap-ap-coh!-lhs-o c to
∙ ((To.glue-β (right (f₂₃ c))) |in-ctx (λ u → ap (right ∘ left) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))
∙ E₂∙Red.lhs-i c
/ E₂∙Red.rhs-i c
∙ ((! (To.glue-β (left (f₂₁ c)))) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (left ∘ right) (H₃₁ c)))
∙ E∙₂Red.ap-ap-coh!-rhs-o c to
∙ ap (ap to) (E∙₂Red.rhs-o c)
∙ ∘-ap to (i∙₀ ∘ f∙₁) (glue c) /
=⟨ ∙□-i/-rewrite (↓-='-out (apd (glue {d = h-v-span}) (glue c))
∙□-o/ ∘-ap to left (glue (f₁₂ c)) ∙ I₀∙.glue-β (f₁₂ c) / ! (∘-ap to right (glue (f₃₂ c)) ∙ I₄∙.glue-β (f₃₂ c)) /) lemma2'-3 lemma2'-4 ⟩
↓-='-out (apd (glue {d = h-v-span}) (glue c))
∙□-o/ ∘-ap to left (glue (f₁₂ c)) ∙ I₀∙.glue-β (f₁₂ c) / ! (∘-ap to right (glue (f₃₂ c)) ∙ I₄∙.glue-β (f₃₂ c)) /
∙□-i/ ! end-lemma1 / end-lemma3 / ∎ where
assoc : ∀ {i} {A : Type i} {a b b' c : A} {u u' : a == b} {v v1 v2 v3 v4 v5 : b == c}
{w w1 w2 w3 w4 w5 : a == b'} {x x' : b' == c} (α : (u , v =□ w , x))
(p1 : v1 == v) (p2 : v2 == v1) (p3 : v3 == v2) (p4 : v4 == v3) (p5 : v5 == v4)
(q1 : w == w1) (q2 : w1 == w2) (q3 : w2 == w3) (q4 : w3 == w4) (q5 : w4 == w5)
(r : u' == u) (s : x == x')
→ α ∙□-i/ p1 / q1 / ∙□-o/ r / s / ∙□-i/ p2 / q2 / ∙□-i/ p3 / q3 / ∙□-i/ p4 / q4 / ∙□-i/ p5 / q5 /
== α ∙□-o/ r / s / ∙□-i/ p5 ∙ p4 ∙ p3 ∙ p2 ∙ p1 / q1 ∙ q2 ∙ q3 ∙ q4 ∙ q5 /
assoc α idp idp idp idp idp idp idp idp idp idp idp idp = idp
lemma2-2 =
ap↓ (ap to) (↓-='-in (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)
∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /))
=⟨ ap↓-↓-='-in-β _ _ to (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)
∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /) ⟩
↓-='-in ((ap□ to (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)
∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /))
∙□-i/ ap-∘ to (i∙₄ ∘ f∙₃) (glue c) / ∘-ap to (i∙₀ ∘ f∙₁) (glue c) /)
=⟨ lemma2-2' |in-ctx ↓-='-in ⟩
↓-='-in (↓-='-out (apd (glue {d = h-v-span}) (glue c))
∙□-o/ ∘-ap to left (glue (f₁₂ c)) ∙ I₀∙.glue-β (f₁₂ c) / ! (∘-ap to right (glue (f₃₂ c)) ∙ I₄∙.glue-β (f₃₂ c)) /
∙□-i/ ! end-lemma1 / end-lemma3 /) ∎
lemma2-1 =
apd (ap to ∘ ap from ∘ glue) (glue c)
=⟨ apd-∘' (ap to ∘ ap from) glue (glue c) ⟩
ap↓ (ap to ∘ ap from) (apd (glue {d = h-v-span}) (glue c))
=⟨ ap↓-∘ (ap to) (ap from) (apd glue (glue c)) ⟩
ap↓ (ap to) (ap↓ (ap from) (apd glue (glue c)))
=⟨ from-glue-glue-β c |in-ctx (ap↓ (ap to)) ⟩
ap↓ (ap to) ((↓-='-in (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)
∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /))
◃/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) /)
=⟨ ap↓-◃/ (ap to) _ (From.glue-β (left (f₁₂ c))) _ ⟩
ap↓ (ap to) (↓-='-in (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)
∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /))
◃/ ap (ap to) (From.glue-β (left (f₁₂ c))) / ap (ap to) (! (From.glue-β (right (f₃₂ c)))) /
=⟨ lemma2-2 |in-ctx (λ u → u ◃/ ap (ap to) (From.glue-β (left (f₁₂ c))) / ap (ap to) (! (From.glue-β (right (f₃₂ c)))) /) ⟩
↓-='-in (↓-='-out (apd (glue {d = h-v-span}) (glue c))
∙□-o/ ∘-ap to left (glue (f₁₂ c)) ∙ I₀∙.glue-β (f₁₂ c) / ! (∘-ap to right (glue (f₃₂ c)) ∙ I₄∙.glue-β (f₃₂ c)) /
∙□-i/ ! end-lemma1 / end-lemma3 /)
◃/ ap (ap to) (From.glue-β (left (f₁₂ c))) / ap (ap to) (! (From.glue-β (right (f₃₂ c)))) / ∎
lemma2 =
↓-='-out (apd (ap to ∘ ap from ∘ glue) (glue c))
=⟨ lemma2-1 |in-ctx ↓-='-out ⟩
↓-='-out (↓-='-in (↓-='-out (apd (glue {d = h-v-span}) (glue c))
∙□-o/ ∘-ap to left (glue (f₁₂ c)) ∙ I₀∙.glue-β (f₁₂ c)
/ ! (∘-ap to right (glue (f₃₂ c)) ∙ I₄∙.glue-β (f₃₂ c)) /
∙□-i/ ! end-lemma1
/ end-lemma3 /)
◃/ ap (ap to) (From.glue-β (left (f₁₂ c))) / ap (ap to) (! (From.glue-β (right (f₃₂ c)))) /)
=⟨ thing (↓-='-out (apd (glue {d = h-v-span}) (glue c))
∙□-o/ ∘-ap to left (glue (f₁₂ c)) ∙ I₀∙.glue-β (f₁₂ c)
/ ! (∘-ap to right (glue (f₃₂ c)) ∙ I₄∙.glue-β (f₃₂ c)) /
∙□-i/ ! end-lemma1
/ end-lemma3 /) (ap (ap to) (From.glue-β (left (f₁₂ c)))) (ap (ap to) (! (From.glue-β (right (f₃₂ c))))) ⟩
↓-='-out (apd (glue {d = h-v-span}) (glue c))
∙□-o/ ∘-ap to left (glue (f₁₂ c)) ∙ I₀∙.glue-β (f₁₂ c)
/ ! (∘-ap to right (glue (f₃₂ c)) ∙ I₄∙.glue-β (f₃₂ c)) /
∙□-i/ ! end-lemma1
/ end-lemma3 /
∙□-o/ ap (ap to) (From.glue-β (left (f₁₂ c))) / ap (ap to) (! (From.glue-β (right (f₃₂ c)))) /
=⟨ ch (↓-='-out (apd (glue {d = h-v-span}) (glue c))) (∘-ap to left (glue (f₁₂ c)))
(ap-∘ to left (glue (f₁₂ c))) (!-∘-ap to left (glue (f₁₂ c))) (I₀∙.glue-β (f₁₂ c)) (∘-ap to right (glue (f₃₂ c)))
(ap-∘ to right (glue (f₃₂ c))) (!-∘-ap to right (glue (f₃₂ c))) (I₄∙.glue-β (f₃₂ c)) (! end-lemma1) end-lemma3
(ap (ap to) (From.glue-β (left (f₁₂ c)))) (! (From.glue-β (left (f₁₂ c))) |in-ctx ap to) (!-ap (ap to) (From.glue-β (left (f₁₂ c)))) (ap (ap to) (! (From.glue-β (right (f₃₂ c))))) ⟩
↓-='-out (apd (glue {d = h-v-span}) (glue c))
∙□-i/ ! end-lemma1
/ end-lemma3 /
∙□-o/ ! (to-from-g-l (f₁₂ c))
/ to-from-g-r (f₃₂ c) / ∎ where
ch : ∀ {i} {A : Type i} {a b b' c : A} {p₁ p₂ p₃ p₄ : a == b} {q₁ q₂ : b == c} {r₁ r₂ : a == b'}
{s₁ s₂ s₃ s₄ : b' == c} (α : (p₁ , q₁ =□ r₁ , s₁)) (β₁ : p₃ == p₂) (β₁-inv : p₂ == p₃)
(eq : ! β₁ == β₁-inv) (β₂ : p₂ == p₁) (β'₁ : s₃ == s₂)
(β'₁-inv : s₂ == s₃) (eq' : ! β'₁ == β'₁-inv) (β'₂ : s₂ == s₁)
(γ : q₂ == q₁) (γ' : r₁ == r₂) (β₃ : p₄ == p₃) (β₃-inv : p₃ == p₄) (eq₃ : ! β₃ == β₃-inv) (β'₃ : s₃ == s₄)
→
α ∙□-o/ β₁ ∙ β₂ / ! (β'₁ ∙ β'₂) /
∙□-i/ γ / γ' /
∙□-o/ β₃ / β'₃ /
==
α ∙□-i/ γ / γ' /
∙□-o/ ! (_ =⟨ ! β₂ ⟩ _ =⟨ β₁-inv ⟩ _ =⟨ β₃-inv ⟩ _ ∎) / (_ =⟨ ! β'₂ ⟩ _ =⟨ β'₁-inv ⟩ _ =⟨ β'₃ ⟩ _ ∎) /
ch α idp .idp idp idp idp .idp idp idp idp idp idp .idp idp idp = idp
| {
"alphanum_fraction": 0.4012542034,
"avg_line_length": 58.8395721925,
"ext": "agda",
"hexsha": "f52aefb7f696051ca2ec0272071a2cba8f5f5e56",
"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": "homotopy/3x3/ToFrom3.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": "homotopy/3x3/ToFrom3.agda",
"max_line_length": 348,
"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": "homotopy/3x3/ToFrom3.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": 17770,
"size": 33009
} |
module calculus.properties where
open import utility
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.Properties
open import Esterel.Lang.CanFunction
using (Canθₛ ; Canθₛₕ ; [S]-env)
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; sig ; []env ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.Context
using (EvaluationContext ; EvaluationContext1 ; _⟦_⟧e ; _≐_⟦_⟧e ;
Context ; Context1 ; _⟦_⟧c ; _≐_⟦_⟧c ; dchole)
open import Esterel.Variable.Signal as Signal
using (Signal)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar)
open import Esterel.Context.Properties
open import Relation.Nullary
using (¬_)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl)
open import Data.Empty
using (⊥ ; ⊥-elim)
import Data.FiniteMap
open import Data.List
using (List ; _∷_ ; [] ; _++_)
open import Data.List.All as All
using (All ; _∷_ ; [])
open import Data.Nat
using (ℕ ; zero ; suc ; _+_)
open import Data.Product
using (Σ-syntax ; Σ ; _,_ ; proj₁ ; proj₂ ; _×_ ; _,′_ ; ∃)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Relation.Binary.PropositionalEquality
open import sn-calculus
open import calculus
open import par-swap
open import par-swap.union-properties using (∥R∪sn≡ₑ-consistent)
open import binding-preserve using (CB-preservation*)
⟶*-concat : ∀ {p q r} -> p ⟶* q -> q ⟶* r -> p ⟶* r
⟶*-concat [refl] q⟶*r = q⟶*r
⟶*-concat ([step] p⟶q p⟶*q) q⟶*r = [step] p⟶q (⟶*-concat p⟶*q q⟶*r)
⟶*->∥R*∪sn⟶* : ∀ {p q} -> p ⟶* q -> p ∥R*∪sn⟶* q
⟶*->∥R*∪sn⟶* = thm where
thm : ∀ {p q} -> p ⟶* q -> p ∥R*∪sn⟶* q
thm [refl] = ∪refl
thm ([step] ([context] C dc p⟶₁p') p'⟶*q) with thm p'⟶*q
thm ([step] ([context] C dc [par-swap]) p'⟶*q) | R
= ∪∥R* (∥Rn (∥Rstep{C} dc) ∥R0) R
thm ([step] ([context] C dc ([par-nothing] doneq)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rpar-done-right hnothin doneq)) rrefl) R
thm ([step] ([context] C dc ([par-1exit] n pausedq)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rpar-done-right (hexit n) (dpaused pausedq))) rrefl) R
thm ([step] ([context] C dc ([par-2exit] n m)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rpar-done-right (hexit n) (dhalted (hexit m)))) rrefl) R
thm ([step] ([context] C dc ([is-present] S S∈ θ[S]≡present de)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (ris-present{S = S} S∈ θ[S]≡present de)) rrefl) R
thm ([step] ([context] C dc ([is-absent] S S∈ θ[S]≡absent de)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (ris-absent{S = S} S∈ θ[S]≡absent de)) rrefl) R
thm ([step] ([context] C dc ([emit] S∈ ¬S≡a de)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (remit S∈ ¬S≡a de)) rrefl) R
thm ([step] ([context] C dc [loop-unroll]) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc rloop-unroll) rrefl) R
thm ([step] ([context] C dc [seq-done]) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc rseq-done) rrefl) R
thm ([step] ([context] C dc [seq-exit]) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc rseq-exit) rrefl) R
thm ([step] ([context] C dc [loopˢ-exit]) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc rloopˢ-exit) rrefl) R
thm ([step] ([context] C dc ([suspend-done] haltedp)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rsuspend-done haltedp)) rrefl) R
thm ([step] ([context] C dc ([trap-done] haltedp)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rtrap-done haltedp)) rrefl) R
thm ([step] ([context] C dc [raise-signal]) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc rraise-signal) rrefl) R
thm ([step] ([context] C dc ([raise-shared] all-readyeθ de)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rraise-shared all-readyeθ de)) rrefl) R
thm ([step] ([context] C dc ([set-shared-value-old] e' s∈ θ[s]≡old de)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rset-shared-value-old e' s∈ θ[s]≡old de)) rrefl) R
thm ([step] ([context] C dc ([set-shared-value-new] e' s∈ θ[s]≡n de)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rset-shared-value-new e' s∈ θ[s]≡n de)) rrefl) R
thm ([step] ([context] C dc ([raise-var] all-readyeθ de)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rraise-var all-readyeθ de)) rrefl) R
thm ([step] ([context] C dc ([set-var] x∈ all-readyeθ de)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rset-var x∈ all-readyeθ de)) rrefl) R
thm ([step] ([context] C dc ([if-false] x∈ θ[x]≡z de)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rif-false x∈ θ[x]≡z de)) rrefl) R
thm ([step] ([context] C dc ([if-true] x∈ θ[x]≡s de)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rif-true x∈ θ[x]≡s de)) rrefl) R
thm ([step] ([context] C dc ([absence] S S∈ θ[S]≡unknown S∉Canθₛ)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rabsence{S = S} S∈ θ[S]≡unknown S∉Canθₛ)) rrefl) R
thm ([step] ([context] C dc ([readyness] s s∈ θ[s]≡old⊎θ[s]≡new s∉Canθₛₕ)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rreadyness{s = s} s∈ θ[s]≡old⊎θ[s]≡new s∉Canθₛₕ)) rrefl) R
thm ([step] ([context] C dc ([merge] de)) p'⟶*q) | R
= ∪sn⟶* (rstep (rcontext C dc (rmerge de)) rrefl) R
∥R*∪sn⟶*->⟶* : ∀ {p q} -> p ∥R*∪sn⟶* q -> p ⟶* q
∥R*∪sn⟶*->⟶* = thm where
p∥R*q->p⟶*q : ∀ {p q} -> p ∥R* q -> p ⟶* q
p∥R*q->p⟶*q ∥R0 = [refl]
p∥R*q->p⟶*q (∥Rn (∥Rstep d≐C⟦p∥q⟧c) p∥R*q)
= [step] ([context] _ d≐C⟦p∥q⟧c [par-swap]) (p∥R*q->p⟶*q p∥R*q)
sn* : ∀ {p q} -> p sn⟶* q -> p ⟶* q
sn* rrefl = [refl]
sn* (rstep (rcontext C dc step) more) with sn* more
sn* (rstep (rcontext C dc (rpar-done-right hnothin q')) _) | R
= [step] ([context] C dc ([par-nothing] q')) R
sn* (rstep (rcontext C dc (rpar-done-right (hexit n) (dhalted hnothin))) _) | R
= [step] ([context] C dc [par-swap])
([step] ([context] C Crefl ([par-nothing] (dhalted (hexit n))))
R)
sn* (rstep (rcontext C dc (rpar-done-right (hexit n) (dhalted (hexit m)))) _) | R
= [step] ([context] C dc ([par-2exit] n m)) R
sn* (rstep (rcontext C dc (rpar-done-right (hexit n) (dpaused p/paused))) _) | R
= [step] ([context] C dc ([par-1exit] n p/paused)) R
sn* (rstep (rcontext C dc (rpar-done-left (dhalted hnothin) q')) more) | R
= [step] ([context] C dc ([par-nothing] (dhalted q'))) R
sn* (rstep (rcontext C dc (rpar-done-left (dhalted (hexit n)) hnothin)) more) | R
= [step] ([context] C dc [par-swap])
([step] ([context] C Crefl ([par-nothing] (dhalted (hexit n))))
R)
sn* (rstep (rcontext C dc (rpar-done-left (dhalted (hexit n)) (hexit m))) more) | R
= [step] ([context] C dc ([par-2exit] n m)) R
sn* (rstep (rcontext C dc (rpar-done-left (dpaused p/paused) hnothin)) more) | R
= [step] ([context] C dc [par-swap])
([step] ([context] C Crefl ([par-nothing] (dpaused p/paused)))
R)
sn* (rstep (rcontext C dc (rpar-done-left (dpaused p/paused) (hexit n))) more) | R
= [step] ([context] C dc [par-swap])
([step] ([context] C Crefl ([par-1exit] n p/paused))
R)
sn* (rstep (rcontext C dc (ris-present{S = S} S∈ x x₁)) _) | R
= [step] ([context] C dc ([is-present] S S∈ x x₁)) R
sn* (rstep (rcontext C dc (ris-absent{S = S} S∈ x x₁)) _) | R
= [step] ([context] C dc ([is-absent] S S∈ x x₁)) R
sn* (rstep (rcontext C dc (remit S∈ ¬S≡a x)) _) | R
= [step] ([context] C dc ([emit] S∈ ¬S≡a x)) R
sn* (rstep (rcontext C dc rloop-unroll) _) | R
= [step] ([context] C dc [loop-unroll]) R
sn* (rstep (rcontext C dc rseq-done) _) | R
= [step] ([context] C dc [seq-done]) R
sn* (rstep (rcontext C dc rseq-exit) _) | R
= [step] ([context] C dc [seq-exit]) R
sn* (rstep (rcontext C dc rloopˢ-exit) _) | R
= [step] ([context] C dc [loopˢ-exit]) R
sn* (rstep (rcontext C dc (rsuspend-done x)) _) | R
= [step] ([context] C dc ([suspend-done] x)) R
sn* (rstep (rcontext C dc (rtrap-done p')) _) | R
= [step] ([context] C dc ([trap-done] p')) R
sn* (rstep (rcontext C dc rraise-signal) _) | R
= [step] ([context] C dc [raise-signal]) R
sn* (rstep (rcontext C dc (rraise-shared e' x)) _) | R
= [step] ([context] C dc ([raise-shared] e' x)) R
sn* (rstep (rcontext C dc (rset-shared-value-old e' s∈ x x₁)) _) | R
= [step] ([context] C dc ([set-shared-value-old] e' s∈ x x₁)) R
sn* (rstep (rcontext C dc (rset-shared-value-new e' s∈ x x₁)) _) | R
= [step] ([context] C dc ([set-shared-value-new] e' s∈ x x₁)) R
sn* (rstep (rcontext C dc (rraise-var e' x₁)) _) | R
= [step] ([context] C dc ([raise-var] e' x₁)) R
sn* (rstep (rcontext C dc (rset-var x∈ e' x₁)) _) | R
= [step] ([context] C dc ([set-var] x∈ e' x₁)) R
sn* (rstep (rcontext C dc (rif-false x∈ x₁ x₂)) _) | R
= [step] ([context] C dc ([if-false] x∈ x₁ x₂)) R
sn* (rstep (rcontext C dc (rif-true x∈ x₁ x₂)) _) | R
= [step] ([context] C dc ([if-true] x∈ x₁ x₂)) R
sn* (rstep (rcontext C dc (rabsence{S = S} S∈ x x₁)) _) | R
= [step] ([context] C dc ([absence] S S∈ x x₁)) R
sn* (rstep (rcontext C dc (rreadyness{s = s} s∈ x x₁)) _) | R
= [step] ([context] C dc ([readyness] s s∈ x x₁)) R
sn* (rstep (rcontext C dc (rmerge x)) _) | R
= [step] ([context] C dc ([merge] x)) R
thm : ∀ {p q} -> p ∥R*∪sn⟶* q -> p ⟶* q
thm (∪∥R* p∥R*q p∥R*∪sn⟶*q)
= ⟶*-concat (p∥R*q->p⟶*q p∥R*q) (thm p∥R*∪sn⟶*q)
thm (∪sn⟶* psn⟶*q p∥R*∪sn⟶*q)
= ⟶*-concat (sn* psn⟶*q) (thm p∥R*∪sn⟶*q)
thm ∪refl = [refl]
≡ₑ-to-∥R∪sn≡ₑ : ∀ {p q} ->
p ≡ₑ q # [] ->
p ∥R∪sn≡ₑ q
≡ₑ-to-∥R∪sn≡ₑ
= λ p≡ₑq#[] → thm Crefl Crefl p≡ₑq#[] where
lift-∥R* : ∀ {p q} ->
p ∥R* q ->
p ∥R∪sn≡ₑ q
lift-∥R* ∥R0 = ∪ref
lift-∥R* (∥Rn p∥Rr r⟶q)
= ∪trn (∪stp∥ p∥Rr) (lift-∥R* r⟶q)
lift-sn⟶* : ∀ {p q} ->
p sn⟶* q ->
p ∥R∪sn≡ₑ q
lift-sn⟶* rrefl = ∪ref
lift-sn⟶* (rstep psn⟶r r⟶q)
= ∪trn (∪stpsn psn⟶r) (lift-sn⟶* r⟶q)
lift-∪ : ∀ {p q} ->
p ∥R*∪sn⟶* q ->
p ∥R∪sn≡ₑ q
lift-∪ (∪∥R* p∥R*r r⟶*q)
= ∪trn (lift-∥R* p∥R*r) (lift-∪ r⟶*q)
lift-∪ (∪sn⟶* psn⟶*r r⟶*q)
= ∪trn (lift-sn⟶* psn⟶*r) (lift-∪ r⟶*q)
lift-∪ ∪refl = ∪ref
thm : ∀ {p′ p q′ q C} ->
(p′C : p′ ≐ C ⟦ p ⟧c) ->
(q′C : q′ ≐ C ⟦ q ⟧c) ->
p ≡ₑ q # C ->
p′ ∥R∪sn≡ₑ q′
thm p′C q′C ≡ₑrefl
rewrite sym (unplugc p′C) | sym (unplugc q′C)
= ∪ref
thm p′C q′C (≡ₑtran p≡ₑr r≡ₑq)
with thm p′C Crefl p≡ₑr
... | p′∪≡r′
with thm Crefl q′C r≡ₑq
... | r′∪≡q′ = ∪trn p′∪≡r′ r′∪≡q′
thm p′C q′C (≡ₑsymm CBq p≡ₑq)
with thm q′C p′C p≡ₑq
... | q∪≡p rewrite sym (unplugc q′C)
= ∪sym q∪≡p CBq
thm p′C q′C (≡ₑctxt pC′ qC′ C′⟦p₂⟧≡ₑC′⟦q₂⟧)
= thm (C++ p′C pC′)
(C++ q′C qC′)
C′⟦p₂⟧≡ₑC′⟦q₂⟧
thm p′C q′C (≡ₑstep p⟶₁q)
with ⟶*->∥R*∪sn⟶* ([step] ([context] _ p′C p⟶₁q) [refl])
... | p′∥R*∪sn⟶*q′ rewrite sym (unplugc q′C)
= lift-∪ p′∥R*∪sn⟶*q′
∥R∪sn≡-to-≡ₑ : ∀ {p q} ->
p ∥R∪sn≡ₑ q ->
p ≡ₑ q # []
∥R∪sn≡-to-≡ₑ = thm where
lift⟶* : ∀ {p q} ->
p ⟶* q ->
p ≡ₑ q # []
lift⟶* [refl] = ≡ₑrefl
lift⟶* ([step] ([context] C dc p⟶₁p') r⟶*q) =
≡ₑtran (≡ₑctxt dc Crefl (≡ₑstep p⟶₁p'))
(lift⟶* r⟶*q)
thm : ∀ {p q} ->
p ∥R∪sn≡ₑ q ->
p ≡ₑ q # []
thm (∪stpsn psn⟶q) =
lift⟶*
(∥R*∪sn⟶*->⟶*
(∪sn⟶* (rstep psn⟶q rrefl)
∪refl))
thm (∪stp∥ (∥Rstep d≐C⟦p∥q⟧c))
= ≡ₑctxt d≐C⟦p∥q⟧c Crefl
(≡ₑstep [par-swap])
thm (∪sym q∪≡p CBq)
with thm q∪≡p
... | q≡ₑp
= ≡ₑsymm CBq q≡ₑp
thm ∪ref = ≡ₑrefl
thm (∪trn p∪≡r r∪≡q)
with thm p∪≡r
... | p≡ₑr
with thm r∪≡q
... | r≡ₑq
= ≡ₑtran p≡ₑr r≡ₑq
≡ₑ-consistent : ∀{p q BV FV}
→ CorrectBinding p BV FV
→ p ≡ₑ q # []
→ Σ[ r ∈ Term ] p ⟶* r × q ⟶* r
≡ₑ-consistent CB eq with ∥R∪sn≡ₑ-consistent CB (≡ₑ-to-∥R∪sn≡ₑ eq)
≡ₑ-consistent CB₁ eq | r , p∥⟶*r , q∥⟶*r
= r , (∥R*∪sn⟶*->⟶* p∥⟶*r) , (∥R*∪sn⟶*->⟶* q∥⟶*r)
∥R*-preserve-CB : ∀ p q → (⊢C⟦p⟧ : CB p) → (p∥R*q : p ∥R* q) → CB q
∥R*-preserve-CB p .p ⊢C⟦p⟧ ∥R0 = ⊢C⟦p⟧
∥R*-preserve-CB p q₁ ⊢C⟦p⟧ (∥Rn (∥Rstep d≐C⟦p∥q⟧c) p∥R*q) with binding-extractc' ⊢C⟦p⟧ d≐C⟦p∥q⟧c
... | (FV' , BV') , CB2 with CB2
... | (CBpar{BVp = BVp}{FVp = FVp} y y₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) with n
where
n = binding-substc' ⊢C⟦p⟧ d≐C⟦p∥q⟧c CB2 (∪-comm-⊆-left BVp ⊆-refl) ((∪-comm-⊆-left FVp ⊆-refl)) ((CBpar y₁ y (distinct-sym BVp≠BVq) (distinct-sym BVp≠FVq) (distinct-sym FVp≠BVq) (distinct'-sym Xp≠Xq)))
... | (_ , _ , cb) with BVFVcorrect _ _ _ cb
... | refl , refl = ∥R*-preserve-CB _ _ cb p∥R*q
∥R*∪sn⟶*-preserve-CB : ∀ p q → (⊢C⟦p⟧ : CB p) → (p∥R*∪sn⟶*q : p ∥R*∪sn⟶* q) → CB q
∥R*∪sn⟶*-preserve-CB p q ⊢C⟦p⟧ (∪∥R* p∥R*q p∥R*∪sn⟶*q)
= ∥R*∪sn⟶*-preserve-CB _ _ (∥R*-preserve-CB _ _ ⊢C⟦p⟧ p∥R*q) p∥R*∪sn⟶*q
∥R*∪sn⟶*-preserve-CB p q ⊢C⟦p⟧ (∪sn⟶* psn⟶*q p∥R*∪sn⟶*q)
= ∥R*∪sn⟶*-preserve-CB _ _ next p∥R*∪sn⟶*q
where
next = CB-preservation* p _ ⊢C⟦p⟧ psn⟶*q
∥R*∪sn⟶*-preserve-CB p .p ⊢C⟦p⟧ ∪refl = ⊢C⟦p⟧
⟶₁-preserve-CB : ∀ p q C → (⊢C⟦p⟧ : CB (C ⟦ p ⟧c)) → (p⟶₁q : p ⟶₁ q) → CB (C ⟦ q ⟧c)
⟶₁-preserve-CB p q C ⊢C⟦p⟧ p⟶₁q with (⟶*->∥R*∪sn⟶* ([step] ([context] C Crefl p⟶₁q) [refl]))
... | p∥R*∪sn⟶*q = ∥R*∪sn⟶*-preserve-CB (C ⟦ p ⟧c) (C ⟦ q ⟧c) ⊢C⟦p⟧ p∥R*∪sn⟶*q
| {
"alphanum_fraction": 0.5442192717,
"avg_line_length": 40.246875,
"ext": "agda",
"hexsha": "430a8b1e1ba17530fd658d47bb058d9e5e96723f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/calculus/properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/calculus/properties.agda",
"max_line_length": 206,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/calculus/properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 6655,
"size": 12879
} |
------------------------------------------------------------------------
-- Groupoids
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Groupoid
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Prelude hiding (id; _∘_; _^_)
open import Bijection eq hiding (id; _∘_)
open Derived-definitions-and-properties eq
open import Integer.Basics eq as Int using (ℤ; +_; -[1+_])
import Nat eq as Nat
private
variable
a : Level
A : Type a
w x y z : A
n : ℕ
j : ℤ
-- Groupoids using _≡_ as the underlying equality.
record Groupoid o ℓ : Type (lsuc (o ⊔ ℓ)) where
infix 8 _⁻¹
infixr 7 _∘_
infix 4 _∼_
field
Object : Type o
_∼_ : Object → Object → Type ℓ
id : x ∼ x
_∘_ : y ∼ z → x ∼ y → x ∼ z
_⁻¹ : x ∼ y → y ∼ x
left-identity : (p : x ∼ y) → id ∘ p ≡ p
right-identity : (p : x ∼ y) → p ∘ id ≡ p
assoc : (p : y ∼ z) (q : x ∼ y) (r : w ∼ x) →
p ∘ (q ∘ r) ≡ (p ∘ q) ∘ r
left-inverse : (p : x ∼ y) → p ⁻¹ ∘ p ≡ id
right-inverse : (p : x ∼ y) → p ∘ p ⁻¹ ≡ id
-- Note that this definition should perhaps contain more coherence
-- properties: we have not assumed that _≡_ is proof-irrelevant.
private
variable
p p₁ p₂ q q₁ q₂ r : x ∼ y
-- Some derived properties.
abstract
-- The identity is an identity for the inverse operator as well.
identity : id {x = x} ⁻¹ ≡ id
identity =
id ⁻¹ ≡⟨ sym $ right-identity (id ⁻¹) ⟩
id ⁻¹ ∘ id ≡⟨ left-inverse id ⟩∎
id ∎
-- If p is idempotent with respect to _∘_, then p is equal to the
-- identity element.
idempotent⇒≡id : p ∘ p ≡ p → p ≡ id
idempotent⇒≡id {p = p} p∘p≡p =
p ≡⟨ sym $ left-identity _ ⟩
id ∘ p ≡⟨ cong (_∘ _) $ sym $ left-inverse _ ⟩
(p ⁻¹ ∘ p) ∘ p ≡⟨ sym $ assoc _ _ _ ⟩
p ⁻¹ ∘ (p ∘ p) ≡⟨ cong (p ⁻¹ ∘_) p∘p≡p ⟩
p ⁻¹ ∘ p ≡⟨ left-inverse _ ⟩∎
id ∎
-- Groupoids are left-cancellative and right-cancellative.
left-cancellative :
p ∘ q₁ ≡ p ∘ q₂ → q₁ ≡ q₂
left-cancellative {p = p} {q₁ = q₁} {q₂ = q₂} p∘q₁≡p∘q₂ =
q₁ ≡⟨ sym $ left-identity _ ⟩
id ∘ q₁ ≡⟨ cong (_∘ _) $ sym $ left-inverse _ ⟩
(p ⁻¹ ∘ p) ∘ q₁ ≡⟨ sym $ assoc _ _ _ ⟩
p ⁻¹ ∘ (p ∘ q₁) ≡⟨ cong (p ⁻¹ ∘_) p∘q₁≡p∘q₂ ⟩
p ⁻¹ ∘ (p ∘ q₂) ≡⟨ assoc _ _ _ ⟩
(p ⁻¹ ∘ p) ∘ q₂ ≡⟨ cong (_∘ _) $ left-inverse _ ⟩
id ∘ q₂ ≡⟨ left-identity _ ⟩∎
q₂ ∎
right-cancellative :
p₁ ∘ q ≡ p₂ ∘ q → p₁ ≡ p₂
right-cancellative {p₁ = p₁} {q = q} {p₂ = p₂} p₁∘q≡p₂∘q =
p₁ ≡⟨ sym $ right-identity _ ⟩
p₁ ∘ id ≡⟨ cong (_ ∘_) $ sym $ right-inverse _ ⟩
p₁ ∘ (q ∘ q ⁻¹) ≡⟨ assoc _ _ _ ⟩
(p₁ ∘ q) ∘ q ⁻¹ ≡⟨ cong (_∘ q ⁻¹) p₁∘q≡p₂∘q ⟩
(p₂ ∘ q) ∘ q ⁻¹ ≡⟨ sym $ assoc _ _ _ ⟩
p₂ ∘ (q ∘ q ⁻¹) ≡⟨ cong (_ ∘_) $ right-inverse _ ⟩
p₂ ∘ id ≡⟨ right-identity _ ⟩∎
p₂ ∎
-- The inverse operator is involutive.
involutive : (p : x ∼ y) → p ⁻¹ ⁻¹ ≡ p
involutive p =
p ⁻¹ ⁻¹ ≡⟨ sym $ right-identity (p ⁻¹ ⁻¹) ⟩
p ⁻¹ ⁻¹ ∘ id ≡⟨ sym $ cong (_∘_ (p ⁻¹ ⁻¹)) (left-inverse p) ⟩
p ⁻¹ ⁻¹ ∘ (p ⁻¹ ∘ p) ≡⟨ assoc _ _ _ ⟩
(p ⁻¹ ⁻¹ ∘ p ⁻¹) ∘ p ≡⟨ cong (λ q → q ∘ p) (left-inverse (p ⁻¹)) ⟩
id ∘ p ≡⟨ left-identity p ⟩∎
p ∎
-- A lemma that can be used to move something from one side of an
-- equality to the other.
⁻¹∘≡→≡∘ : p ⁻¹ ∘ q ≡ r → q ≡ p ∘ r
⁻¹∘≡→≡∘ {p = p} {q = q} {r = r} hyp =
q ≡⟨ sym $ left-identity _ ⟩
id ∘ q ≡⟨ cong (_∘ _) $ sym $ right-inverse _ ⟩
(p ∘ p ⁻¹) ∘ q ≡⟨ sym $ assoc _ _ _ ⟩
p ∘ (p ⁻¹ ∘ q) ≡⟨ cong (_ ∘_) hyp ⟩∎
p ∘ r ∎
-- A corollary.
⁻¹∘≡id→≡ : p ⁻¹ ∘ q ≡ id → q ≡ p
⁻¹∘≡id→≡ {p = p} {q = q} hyp =
q ≡⟨ ⁻¹∘≡→≡∘ hyp ⟩
p ∘ id ≡⟨ right-identity _ ⟩∎
p ∎
-- Another lemma that can be used to move something from one side
-- of an equality to the other.
∘⁻¹≡→≡∘ : p ∘ q ⁻¹ ≡ r → p ≡ r ∘ q
∘⁻¹≡→≡∘ {p = p} {q = q} {r = r} hyp =
p ≡⟨ sym $ right-identity _ ⟩
p ∘ id ≡⟨ cong (_ ∘_) $ sym $ left-inverse _ ⟩
p ∘ (q ⁻¹ ∘ q) ≡⟨ assoc _ _ _ ⟩
(p ∘ q ⁻¹) ∘ q ≡⟨ cong (_∘ _) hyp ⟩∎
r ∘ q ∎
-- A corollary.
∘⁻¹≡id→≡ : p ∘ q ⁻¹ ≡ id → p ≡ q
∘⁻¹≡id→≡ {p = p} {q = q} hyp =
p ≡⟨ ∘⁻¹≡→≡∘ hyp ⟩
id ∘ q ≡⟨ left-identity _ ⟩∎
q ∎
-- A lemma relating _∘_ and _⁻¹.
∘⁻¹ : (p ∘ q) ⁻¹ ≡ q ⁻¹ ∘ p ⁻¹
∘⁻¹ {p = p} {q = q} = right-cancellative
((p ∘ q) ⁻¹ ∘ (p ∘ q) ≡⟨ left-inverse _ ⟩
id ≡⟨ sym $ left-inverse _ ⟩
q ⁻¹ ∘ q ≡⟨ cong (q ⁻¹ ∘_) $ sym $ left-identity _ ⟩
q ⁻¹ ∘ (id ∘ q) ≡⟨ cong (q ⁻¹ ∘_) $ cong (_∘ _) $ sym $ left-inverse _ ⟩
q ⁻¹ ∘ ((p ⁻¹ ∘ p) ∘ q) ≡⟨ cong (q ⁻¹ ∘_) $ sym $ assoc _ _ _ ⟩
q ⁻¹ ∘ (p ⁻¹ ∘ (p ∘ q)) ≡⟨ assoc _ _ _ ⟩∎
(q ⁻¹ ∘ p ⁻¹) ∘ (p ∘ q) ∎)
-- If p ∘ q is equal to id, then q is equal to p ⁻¹.
⁻¹-unique-right : p ∘ q ≡ id → q ≡ p ⁻¹
⁻¹-unique-right {p = p} {q = q} ∘≡id = ⁻¹∘≡id→≡
(p ⁻¹ ⁻¹ ∘ q ≡⟨ cong (_∘ _) $ involutive _ ⟩
p ∘ q ≡⟨ ∘≡id ⟩∎
id ∎)
-- If p ∘ q is equal to id, then p is equal to q ⁻¹.
⁻¹-unique-left : p ∘ q ≡ id → p ≡ q ⁻¹
⁻¹-unique-left {p = p} {q = q} ∘≡id = ∘⁻¹≡id→≡
(p ∘ q ⁻¹ ⁻¹ ≡⟨ cong (_ ∘_) $ involutive _ ⟩
p ∘ q ≡⟨ ∘≡id ⟩∎
id ∎)
-- The inverse operator is a bijection.
⁻¹-bijection : x ∼ y ↔ y ∼ x
⁻¹-bijection = record
{ surjection = record
{ logical-equivalence = record
{ to = _⁻¹
; from = _⁻¹
}
; right-inverse-of = involutive
}
; left-inverse-of = involutive
}
-- Exponentiation.
infixl 8 _^+_
infixr 8 _^_
_^+_ : x ∼ x → ℕ → x ∼ x
p ^+ 0 = id
p ^+ suc n = p ∘ p ^+ n
_^_ : x ∼ x → ℤ → x ∼ x
p ^ + n = p ^+ n
p ^ -[1+ n ] = (p ⁻¹) ^+ suc n
-- _^+_ is homomorphic with respect to _∘_/_+_.
^+∘^+ : ∀ m → p ^+ m ∘ p ^+ n ≡ p ^+ (m + n)
^+∘^+ {p = p} {n = n} zero =
id ∘ p ^+ n ≡⟨ left-identity _ ⟩∎
p ^+ n ∎
^+∘^+ {p = p} {n = n} (suc m) =
(p ∘ p ^+ m) ∘ p ^+ n ≡⟨ sym $ assoc _ _ _ ⟩
p ∘ (p ^+ m ∘ p ^+ n) ≡⟨ cong (_ ∘_) $ ^+∘^+ m ⟩∎
p ∘ p ^+ (m + n) ∎
-- Some rearrangement lemmas for _^+_.
∘^+≡^+∘ :
p ∘ q ≡ q ∘ p →
∀ n → p ∘ q ^+ n ≡ q ^+ n ∘ p
∘^+≡^+∘ {p = p} _ zero =
p ∘ id ≡⟨ right-identity _ ⟩
p ≡⟨ sym $ left-identity _ ⟩∎
id ∘ p ∎
∘^+≡^+∘ {p = p} {q = q} comm (suc n) =
p ∘ (q ∘ q ^+ n) ≡⟨ assoc _ _ _ ⟩
(p ∘ q) ∘ q ^+ n ≡⟨ cong (_∘ q ^+ n) comm ⟩
(q ∘ p) ∘ q ^+ n ≡⟨ sym $ assoc _ _ _ ⟩
q ∘ (p ∘ q ^+ n) ≡⟨ cong (q ∘_) $ ∘^+≡^+∘ comm n ⟩
q ∘ (q ^+ n ∘ p) ≡⟨ assoc _ _ _ ⟩∎
(q ∘ q ^+ n) ∘ p ∎
^+∘^+≡^+∘^+ : ∀ m n → p ^+ m ∘ p ^+ n ≡ p ^+ n ∘ p ^+ m
^+∘^+≡^+∘^+ {p = p} m n =
p ^+ m ∘ p ^+ n ≡⟨ ^+∘^+ m ⟩
p ^+ (m + n) ≡⟨ cong (p ^+_) $ Nat.+-comm m ⟩
p ^+ (n + m) ≡⟨ sym $ ^+∘^+ n ⟩∎
p ^+ n ∘ p ^+ m ∎
private
-- Some lemmas which are used to define ^∘^ below.
lemma₁ : ∀ n → (p ∘ p ^+ n) ∘ (p ⁻¹ ∘ q) ≡ p ^+ n ∘ q
lemma₁ {p = p} {q = q} n =
(p ∘ p ^+ n) ∘ (p ⁻¹ ∘ q) ≡⟨ cong (_∘ (p ⁻¹ ∘ q)) $ ∘^+≡^+∘ (refl _) n ⟩
(p ^+ n ∘ p) ∘ (p ⁻¹ ∘ q) ≡⟨ sym $ assoc _ _ _ ⟩
p ^+ n ∘ (p ∘ (p ⁻¹ ∘ q)) ≡⟨ cong (p ^+ n ∘_) $ assoc _ _ _ ⟩
p ^+ n ∘ ((p ∘ p ⁻¹) ∘ q) ≡⟨ cong (p ^+ n ∘_) $ cong (_∘ q) $ right-inverse _ ⟩
p ^+ n ∘ (id ∘ q) ≡⟨ cong (p ^+ n ∘_) $ left-identity _ ⟩∎
p ^+ n ∘ q ∎
lemma₂ : ∀ n → (p ⁻¹ ∘ (p ⁻¹) ^+ n) ∘ (p ∘ q) ≡ (p ⁻¹) ^+ n ∘ q
lemma₂ {p = p} {q = q} n =
(p ⁻¹ ∘ (p ⁻¹) ^+ n) ∘ (p ∘ q) ≡⟨ cong (λ r → (p ⁻¹ ∘ (p ⁻¹) ^+ n) ∘ (r ∘ q)) $ sym $ involutive _ ⟩
(p ⁻¹ ∘ (p ⁻¹) ^+ n) ∘ (p ⁻¹ ⁻¹ ∘ q) ≡⟨ lemma₁ n ⟩∎
(p ⁻¹) ^+ n ∘ q ∎
lemma₃ : ∀ m n → p ^+ m ∘ (p ⁻¹) ^+ suc n ≡ p ^ Int.+ m +-[1+ n ]
lemma₃ {p = p} zero n =
id ∘ (p ⁻¹) ^+ suc n ≡⟨ left-identity _ ⟩∎
(p ⁻¹) ^+ suc n ∎
lemma₃ {p = p} (suc m) zero =
(p ∘ p ^+ m) ∘ p ⁻¹ ∘ id ≡⟨ lemma₁ m ⟩
p ^+ m ∘ id ≡⟨ right-identity _ ⟩∎
p ^+ m ∎
lemma₃ {p = p} (suc m) (suc n) =
(p ∘ p ^+ m) ∘ (p ⁻¹ ∘ (p ⁻¹) ^+ suc n) ≡⟨ lemma₁ m ⟩
p ^+ m ∘ (p ⁻¹) ^+ suc n ≡⟨ lemma₃ m n ⟩∎
p ^ Int.+ m +-[1+ n ] ∎
lemma₄ : ∀ m n → (p ⁻¹) ^+ suc m ∘ p ^+ n ≡ p ^ Int.+ n +-[1+ m ]
lemma₄ {p = p} m zero =
(p ⁻¹) ^+ suc m ∘ id ≡⟨ right-identity _ ⟩∎
(p ⁻¹) ^+ suc m ∎
lemma₄ {p = p} zero (suc n) =
(p ⁻¹ ∘ id) ∘ p ∘ p ^+ n ≡⟨ lemma₂ zero ⟩
id ∘ p ^+ n ≡⟨ left-identity _ ⟩∎
p ^+ n ∎
lemma₄ {p = p} (suc m) (suc n) =
(p ⁻¹ ∘ (p ⁻¹) ^+ suc m) ∘ (p ∘ p ^+ n) ≡⟨ lemma₂ (suc m) ⟩
(p ⁻¹) ^+ suc m ∘ p ^+ n ≡⟨ lemma₄ m n ⟩∎
p ^ Int.+ n +-[1+ m ] ∎
-- _^_ is homomorphic with respect to _∘_/Int._+_.
^∘^ : ∀ i → p ^ i ∘ p ^ j ≡ p ^ (i Int.+ j)
^∘^ {j = + _} (+ m) = ^+∘^+ m
^∘^ {j = -[1+ n ]} (+ m) = lemma₃ m n
^∘^ {j = + n} -[1+ m ] = lemma₄ m n
^∘^ {p = p} {j = -[1+ n ]} -[1+ m ] =
(p ⁻¹) ^+ suc m ∘ (p ⁻¹) ^+ suc n ≡⟨ ^+∘^+ (suc m) ⟩
(p ⁻¹) ^+ (suc m + suc n) ≡⟨ cong ((p ⁻¹) ^+_) $ cong suc $ sym $ Nat.suc+≡+suc m ⟩∎
(p ⁻¹) ^+ (2 + m + n) ∎
-- _^+ n commutes with _⁻¹.
^+⁻¹ : ∀ n → (p ^+ n) ⁻¹ ≡ (p ⁻¹) ^+ n
^+⁻¹ zero = identity
^+⁻¹ {p = p} (suc n) =
(p ∘ p ^+ n) ⁻¹ ≡⟨ ∘⁻¹ ⟩
(p ^+ n) ⁻¹ ∘ p ⁻¹ ≡⟨ cong (_∘ p ⁻¹) $ ^+⁻¹ n ⟩
(p ⁻¹) ^+ n ∘ p ⁻¹ ≡⟨ sym $ ∘^+≡^+∘ (refl _) n ⟩∎
p ⁻¹ ∘ (p ⁻¹) ^+ n ∎
-- _^ i commutes with _⁻¹.
^⁻¹ : ∀ i → (p ^ i) ⁻¹ ≡ (p ⁻¹) ^ i
^⁻¹ (+ n) = ^+⁻¹ n
^⁻¹ -[1+ n ] = ^+⁻¹ (suc n)
-- Any power of id is equal to id.
id^+ : ∀ n → id ^+ n ≡ id {x = x}
id^+ zero = refl _
id^+ (suc n) =
id ∘ id ^+ n ≡⟨ left-identity _ ⟩
id ^+ n ≡⟨ id^+ n ⟩∎
id ∎
id^ : ∀ i → id ^ i ≡ id {x = x}
id^ (+ n) = id^+ n
id^ -[1+ n ] =
(id ⁻¹) ^+ suc n ≡⟨ sym $ ^+⁻¹ (suc n) ⟩
(id ^+ suc n) ⁻¹ ≡⟨ cong _⁻¹ $ id^+ (suc n) ⟩
id ⁻¹ ≡⟨ identity ⟩∎
id ∎
private
lemma₅ : ∀ m n → p ^+ suc m ^+ n ≡ p ^+ n ∘ p ^+ m ^+ n
lemma₅ _ zero =
id ≡⟨ sym $ left-identity _ ⟩∎
id ∘ id ∎
lemma₅ {p = p} m (suc n) =
p ^+ suc m ∘ p ^+ suc m ^+ n ≡⟨ cong (p ^+ suc m ∘_) $ lemma₅ m n ⟩
p ^+ suc m ∘ (p ^+ n ∘ p ^+ m ^+ n) ≡⟨ assoc _ _ _ ⟩
(p ^+ suc m ∘ p ^+ n) ∘ p ^+ m ^+ n ≡⟨⟩
((p ∘ p ^+ m) ∘ p ^+ n) ∘ p ^+ m ^+ n ≡⟨ cong (_∘ p ^+ m ^+ n) $ sym $ assoc _ _ _ ⟩
(p ∘ p ^+ m ∘ p ^+ n) ∘ p ^+ m ^+ n ≡⟨ cong (_∘ p ^+ m ^+ n) $ cong (p ∘_) $ ^+∘^+≡^+∘^+ m n ⟩
(p ∘ p ^+ n ∘ p ^+ m) ∘ p ^+ m ^+ n ≡⟨ cong (_∘ p ^+ m ^+ n) $ assoc _ _ _ ⟩
((p ∘ p ^+ n) ∘ p ^+ m) ∘ p ^+ m ^+ n ≡⟨ sym $ assoc _ _ _ ⟩∎
(p ∘ p ^+ n) ∘ p ^+ m ∘ p ^+ m ^+ n ∎
-- More rearrangement lemmas for _^+_.
^+^+≡^+* : ∀ m → p ^+ m ^+ n ≡ p ^+ (m * n)
^+^+≡^+* {n = n} zero =
id ^+ n ≡⟨ id^+ n ⟩∎
id ∎
^+^+≡^+* {p = p} {n = n} (suc m) =
p ^+ suc m ^+ n ≡⟨ lemma₅ m n ⟩
p ^+ n ∘ p ^+ m ^+ n ≡⟨ cong (p ^+ n ∘_) $ ^+^+≡^+* m ⟩
p ^+ n ∘ p ^+ (m * n) ≡⟨ ^+∘^+ n ⟩
p ^+ (n + m * n) ≡⟨⟩
p ^+ (suc m * n) ∎
∘^+≡^+∘^+ :
p ∘ q ≡ q ∘ p →
∀ n →
(p ∘ q) ^+ n ≡ p ^+ n ∘ q ^+ n
∘^+≡^+∘^+ _ zero =
id ≡⟨ sym $ left-identity _ ⟩∎
id ∘ id ∎
∘^+≡^+∘^+ {p = p} {q = q} comm (suc n) =
(p ∘ q) ^+ suc n ≡⟨⟩
(p ∘ q) ∘ (p ∘ q) ^+ n ≡⟨ cong ((p ∘ q) ∘_) $ ∘^+≡^+∘^+ comm n ⟩
(p ∘ q) ∘ (p ^+ n ∘ q ^+ n) ≡⟨ sym $ assoc _ _ _ ⟩
p ∘ (q ∘ p ^+ n ∘ q ^+ n) ≡⟨ cong (p ∘_) $ assoc _ _ _ ⟩
p ∘ ((q ∘ p ^+ n) ∘ q ^+ n) ≡⟨ cong (p ∘_) $ cong (_∘ (q ^+ n)) $ ∘^+≡^+∘ (sym comm) n ⟩
p ∘ ((p ^+ n ∘ q) ∘ q ^+ n) ≡⟨ cong (p ∘_) $ sym $ assoc _ _ _ ⟩
p ∘ (p ^+ n ∘ q ∘ q ^+ n) ≡⟨ assoc _ _ _ ⟩
(p ∘ p ^+ n) ∘ q ∘ q ^+ n ≡⟨⟩
p ^+ suc n ∘ q ^+ suc n ∎
| {
"alphanum_fraction": 0.3525208104,
"avg_line_length": 33.598944591,
"ext": "agda",
"hexsha": "e3c81f6477a5f6ab533722f713d64db7dbf3e0ab",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Groupoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Groupoid.agda",
"max_line_length": 113,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Groupoid.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 6538,
"size": 12734
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties connecting left-scaling and right-scaling
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
-- The properties are parameterised by the three carriers and
-- the result equality.
module Algebra.Module.Definitions.Bi
{a a′ b ℓb} (A : Set a) (A′ : Set a′) {B : Set b} (_≈_ : Rel B ℓb)
where
open import Algebra.Core
Associative : Opₗ A B → Opᵣ A′ B → Set _
Associative _∙ₗ_ _∙ᵣ_ = ∀ x m y → ((x ∙ₗ m) ∙ᵣ y) ≈ (x ∙ₗ (m ∙ᵣ y))
| {
"alphanum_fraction": 0.4961119751,
"avg_line_length": 29.2272727273,
"ext": "agda",
"hexsha": "23b812dc48ae78297e7bf67af06a6317079c5277",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Algebra/Module/Definitions/Bi.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Algebra/Module/Definitions/Bi.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/Module/Definitions/Bi.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": 186,
"size": 643
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Complete where
open import Level
open import Categories.Category
open import Categories.Category.Construction.Cones
open import Categories.Functor
open import Categories.Diagram.Cone.Properties
open import Categories.Diagram.Limit using (Limit)
Complete : (o ℓ e : Level) {o′ ℓ′ e′ : Level} (C : Category o′ ℓ′ e′) → Set _
Complete o ℓ e C = ∀ {J : Category o ℓ e} (F : Functor J C) → Limit F
-- a functor between diagrams corresponds to a morphism between limits
module _ {o ℓ e o′ ℓ′ e′} {C : Category o′ ℓ′ e′} (Com : Complete o ℓ e C)
{J J′ : Category o ℓ e} (F : Functor J′ J) (G : Functor J C) where
private
module C = Category C
module J = Category J
module J′ = Category J′
module F = Functor F
module G = Functor G
F⇒arr : Cones (G ∘F F) [ F-map-Coneʳ F (Limit.limit (Com G)) , Limit.limit (Com (G ∘F F)) ]
F⇒arr = Limit.rep-cone (Com (G ∘F F)) (F-map-Coneʳ F (Limit.limit (Com G)))
| {
"alphanum_fraction": 0.6576032226,
"avg_line_length": 34.2413793103,
"ext": "agda",
"hexsha": "dd23aafc715b8a0021b7e73a419fa446b745314c",
"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/Complete.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/Complete.agda",
"max_line_length": 93,
"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/Complete.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": 325,
"size": 993
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.EilenbergMacLane
open import homotopy.EilenbergMacLane1
open import homotopy.EilenbergMacLaneFunctor
open import homotopy.SmashFmapConn
open import homotopy.IterSuspSmash
open import cohomology.CupProduct.OnEM.InLowDegrees2
module cohomology.CupProduct.OnEM.InAllDegrees where
module _ {i} (A : AbGroup i) where
private
module A = AbGroup A
open EMExplicit
inv-path : A == A
inv-path = uaᴬᴳ A A (inv-iso A)
⊙cond-neg : ∀ (k : ℕ) → Bool
→ ⊙EM A k ⊙→ ⊙EM A k
⊙cond-neg k b =
⊙transport (λ G → ⊙EM G k) {x = A} {y = A} (Bool-elim inv-path idp b)
⊙cond-neg-∘ : ∀ (k : ℕ) (b c : Bool)
→ ⊙cond-neg k b ◃⊙∘ ⊙cond-neg k c ◃⊙idf
=⊙∘
⊙cond-neg k (xor b c) ◃⊙idf
⊙cond-neg-∘ k true true =
⊙transport (λ G → ⊙EM G k) {x = A} {y = A} inv-path ◃⊙∘
⊙transport (λ G → ⊙EM G k) {x = A} {y = A} inv-path ◃⊙idf
=⊙∘₁⟨ 0 & 1 & ⊙transport-⊙EM-uaᴬᴳ A A (inv-iso A) k ⟩
⊙EM-fmap A A (–>ᴳ (inv-iso A)) k ◃⊙∘
⊙transport (λ G → ⊙EM G k) {x = A} {y = A} inv-path ◃⊙idf
=⊙∘₁⟨ 1 & 1 & ⊙transport-⊙EM-uaᴬᴳ A A (inv-iso A) k ⟩
⊙EM-fmap A A (–>ᴳ (inv-iso A)) k ◃⊙∘
⊙EM-fmap A A (–>ᴳ (inv-iso A)) k ◃⊙idf
=⊙∘₁⟨ ! $ ⊙EM-fmap-∘ A A A (–>ᴳ (inv-iso A)) (–>ᴳ (inv-iso A)) k ⟩
⊙EM-fmap A A (–>ᴳ (inv-iso A) ∘ᴳ –>ᴳ (inv-iso A)) k ◃⊙idf
=⊙∘₁⟨ ap (λ φ → ⊙EM-fmap A A φ k) $
group-hom= {ψ = idhom _} (λ= A.inv-inv) ⟩
⊙EM-fmap A A (idhom _) k ◃⊙idf
=⊙∘₁⟨ ⊙EM-fmap-idhom A k ⟩
⊙idf _ ◃⊙idf ∎⊙∘
⊙cond-neg-∘ k true false = =⊙∘-in idp
⊙cond-neg-∘ k false true = =⊙∘-in (⊙λ= (⊙∘-unit-l (⊙cond-neg k true)))
⊙cond-neg-∘ k false false = =⊙∘-in idp
⊙maybe-Susp^-flip-⊙cond-neg : ∀ (k : ℕ) (b : Bool)
→ (k == 0 → b == false)
→ ⊙Trunc-fmap (⊙maybe-Susp^-flip k b) == ⊙cond-neg (S k) b
⊙maybe-Susp^-flip-⊙cond-neg O b h =
⊙Trunc-fmap (⊙idf (⊙EM₁ A.grp))
=⟨ ⊙λ= ⊙Trunc-fmap-⊙idf ⟩
⊙idf (⊙EM A 1)
=⟨ ap (⊙cond-neg 1) (! (h idp)) ⟩
⊙cond-neg 1 b =∎
⊙maybe-Susp^-flip-⊙cond-neg (S k) true h =
⊙Trunc-fmap (⊙Susp-flip (⊙Susp^ k (⊙EM₁ A.grp)))
=⟨ ! (⊙EM-neg=⊙Trunc-fmap-⊙Susp-flip A k) ⟩
⊙EM-neg A (S (S k))
=⟨ ! (⊙transport-⊙EM-uaᴬᴳ A A (inv-iso A) (S (S k))) ⟩
⊙transport (λ G → ⊙EM G (S (S k))) {x = A} {y = A} inv-path =∎
⊙maybe-Susp^-flip-⊙cond-neg (S k) false h = ⊙λ= (⊙Trunc-fmap-⊙idf)
⊙EM2-Susp-seq : ∀ (k : ℕ)
→ ⊙Susp^ k (⊙EM A 2) ⊙–→ ⊙EM A (S (S k))
⊙EM2-Susp-seq k =
⊙transport (λ l → ⊙Trunc l (⊙Susp^ (S k) (⊙EM₁ A.grp))) (+2+-comm ⟨ k ⟩₋₂ 2) ◃⊙∘
⊙Trunc-fmap (⊙Susp^-swap k 1 {⊙EM₁ A.grp}) ◃⊙∘
⊙Susp^-Trunc-swap (⊙Susp (EM₁ A.grp)) 2 k ◃⊙idf
⊙EM2-Susp : ∀ (k : ℕ)
→ ⊙Susp^ k (⊙EM A 2) ⊙→ ⊙EM A (S (S k))
⊙EM2-Susp k = ⊙compose (⊙EM2-Susp-seq k)
⊙EM2-Susp-⊙maybe-Susp^-flip : ∀ (k : ℕ) (b : Bool)
→ (k == 0 → b == false)
→ ⊙EM2-Susp k ◃⊙∘
⊙maybe-Susp^-flip k b ◃⊙idf
=⊙∘
⊙Trunc-fmap (⊙maybe-Susp^-flip {X = ⊙EM₁ A.grp} (S k) b) ◃⊙∘
⊙EM2-Susp k ◃⊙idf
⊙EM2-Susp-⊙maybe-Susp^-flip k b h =
⊙EM2-Susp k ◃⊙∘
⊙maybe-Susp^-flip k b ◃⊙idf
=⊙∘⟨ 0 & 1 & ⊙expand (⊙EM2-Susp-seq k) ⟩
⊙transport (λ l → ⊙Trunc l (⊙Susp^ (S k) (⊙EM₁ A.grp))) (+2+-comm ⟨ k ⟩₋₂ 2) ◃⊙∘
⊙Trunc-fmap (⊙Susp^-swap k 1 {⊙EM₁ A.grp}) ◃⊙∘
⊙Susp^-Trunc-swap (⊙Susp (EM₁ A.grp)) 2 k ◃⊙∘
⊙maybe-Susp^-flip k b ◃⊙idf
=⊙∘⟨ 2 & 2 & ⊙Susp^-Trunc-swap-⊙maybe-Susp^-flip (⊙Susp (EM₁ A.grp)) 2 k b ⟩
⊙transport (λ l → ⊙Trunc l (⊙Susp^ (S k) (⊙EM₁ A.grp))) (+2+-comm ⟨ k ⟩₋₂ 2) ◃⊙∘
⊙Trunc-fmap (⊙Susp^-swap k 1 {⊙EM₁ A.grp}) ◃⊙∘
⊙Trunc-fmap (⊙maybe-Susp^-flip k b) ◃⊙∘
⊙Susp^-Trunc-swap (⊙Susp (EM₁ A.grp)) 2 k ◃⊙idf
=⊙∘⟨ 1 & 2 & ⊙Trunc-fmap-seq-=⊙∘ p ⟩
⊙transport (λ l → ⊙Trunc l (⊙Susp^ (S k) (⊙EM₁ A.grp))) (+2+-comm ⟨ k ⟩₋₂ 2) ◃⊙∘
⊙Trunc-fmap (⊙maybe-Susp-flip (⊙Susp^ k (⊙EM₁ A.grp)) b) ◃⊙∘
⊙Trunc-fmap (⊙Susp^-swap k 1 {⊙EM₁ A.grp}) ◃⊙∘
⊙Susp^-Trunc-swap (⊙Susp (EM₁ A.grp)) 2 k ◃⊙idf
=⊙∘⟨ 0 & 2 & !⊙∘ $
⊙transport-natural-=⊙∘
(+2+-comm ⟨ k ⟩₋₂ 2)
(λ l → ⊙Trunc-fmap {n = l} (⊙maybe-Susp^-flip (S k) b)) ⟩
⊙Trunc-fmap (⊙maybe-Susp-flip (⊙Susp^ k (⊙EM₁ A.grp)) b) ◃⊙∘
⊙transport (λ l → ⊙Trunc l (⊙Susp^ (S k) (⊙EM₁ A.grp))) (+2+-comm ⟨ k ⟩₋₂ 2) ◃⊙∘
⊙Trunc-fmap (⊙Susp^-swap k 1 {⊙EM₁ A.grp}) ◃⊙∘
⊙Susp^-Trunc-swap (⊙Susp (EM₁ A.grp)) 2 k ◃⊙idf
=⊙∘⟨ 1 & 3 & ⊙contract ⟩
⊙Trunc-fmap (⊙maybe-Susp-flip (⊙Susp^ k (⊙EM₁ A.grp)) b) ◃⊙∘
⊙EM2-Susp k ◃⊙idf ∎⊙∘
where
p : ⊙Susp^-swap k 1 {⊙EM₁ A.grp} ◃⊙∘
⊙maybe-Susp^-flip k b ◃⊙idf
=⊙∘
⊙maybe-Susp^-flip {X = ⊙EM₁ A.grp} (S k) b ◃⊙∘
⊙Susp^-swap k 1 {⊙EM₁ A.grp} ◃⊙idf
p =
⊙Susp^-swap k 1 {⊙EM₁ A.grp} ◃⊙∘
⊙maybe-Susp^-flip k b ◃⊙idf
=⊙∘⟨ !⊙∘ $ ⊙maybe-Susp^-flip-⊙Susp^-comm (⊙EM₁ A.grp) k 1 b ⟩
⊙Susp-fmap (fst (⊙maybe-Susp^-flip k b)) ◃⊙∘
⊙coe (⊙Susp^-comm k 1) ◃⊙idf
=⊙∘₁⟨ 0 & 1 & ap ⊙Susp-fmap (de⊙-⊙maybe-Susp^-flip k b) ∙
⊙Susp-fmap-maybe-Susp^-flip k b h ⟩
⊙maybe-Susp-flip (⊙Susp^ k (⊙EM₁ A.grp)) b ◃⊙∘
⊙Susp^-swap k 1 ◃⊙idf ∎⊙∘
⊙cpₕₕ''-seq : ∀ (m n : ℕ)
→ ⊙Susp^ (m + n) (⊙EM A 2) ⊙–→ ⊙EM A (S m + S n)
⊙cpₕₕ''-seq m n =
⊙cond-neg (S m + S n) (odd n) ◃⊙∘
⊙transport (⊙EM A) (! (+-βr (S m) n)) ◃⊙∘
⊙EM2-Susp (m + n) ◃⊙idf
⊙cpₕₕ'' : ∀ (m n : ℕ)
→ ⊙Susp^ (m + n) (⊙EM A 2) ⊙→ ⊙EM A (S m + S n)
⊙cpₕₕ'' m n = ⊙compose (⊙cpₕₕ''-seq m n)
module _ {i j} {X : Ptd i} {Y : Ptd j} where
→-⊙→-uncurry : ∀ {k} {Z : Ptd k}
→ (de⊙ X → Y ⊙→ Z)
→ X ⊙× Y ⊙→ Z
→-⊙→-uncurry f =
uncurry (λ x y → fst (f x) y) , snd (f (pt X))
module _ {i} {j} (G : AbGroup i) (H : AbGroup j) where
private
module G = AbGroup G
module H = AbGroup H
module G⊗H = TensorProduct G H
open EMExplicit
⊙∧-cpₕₕ'-seq : ∀ (m n : ℕ)
→ (⊙Susp^ m (⊙EM₁ G.grp) ⊙∧ ⊙Susp^ n (⊙EM₁ H.grp))
⊙–→
⊙EM G⊗H.abgroup (S m + S n)
⊙∧-cpₕₕ'-seq m n =
⊙cpₕₕ'' G⊗H.abgroup m n ◃⊙∘
⊙Susp^-fmap (m + n) (⊙∧-cp₁₁ G H) ◃⊙∘
⊙Σ^∧Σ^-out (⊙EM₁ G.grp) (⊙EM₁ H.grp) m n ◃⊙idf
⊙∧-cpₕₕ' : ∀ (m n : ℕ)
→ ⊙Susp^ m (⊙EM₁ G.grp) ⊙∧ ⊙Susp^ n (⊙EM₁ H.grp) ⊙→ ⊙EM G⊗H.abgroup (S m + S n)
⊙∧-cpₕₕ' m n = ⊙compose (⊙∧-cpₕₕ'-seq m n)
∧-cpₕₕ' : ∀ (m n : ℕ)
→ ⊙Susp^ m (⊙EM₁ G.grp) ∧ ⊙Susp^ n (⊙EM₁ H.grp)
→ EM G⊗H.abgroup (S m + S n)
∧-cpₕₕ' m n = fst (⊙∧-cpₕₕ' m n)
⊙smash-truncate : ∀ (m n : ℕ)
→ ⊙Susp^ m (⊙EM₁ G.grp) ⊙∧ ⊙Susp^ n (⊙EM₁ H.grp)
⊙→ ⊙EM G (S m) ⊙∧ ⊙EM H (S n)
⊙smash-truncate m n =
⊙∧-fmap
([_] {n = ⟨ S m ⟩} {A = Susp^ m (EM₁ G.grp)} , idp)
([_] {n = ⟨ S n ⟩} {A = Susp^ n (EM₁ H.grp)} , idp)
smash-truncate : ∀ (m n : ℕ)
→ ⊙Susp^ m (⊙EM₁ G.grp) ∧ ⊙Susp^ n (⊙EM₁ H.grp)
→ ⊙EM G (S m) ∧ ⊙EM H (S n)
smash-truncate m n = fst (⊙smash-truncate m n)
smash-truncate-conn : ∀ (m n : ℕ)
→ has-conn-fibers ⟨ S m + S n ⟩ (smash-truncate m n)
smash-truncate-conn m n =
transport (λ k → has-conn-fibers k (smash-truncate m n)) p $
∧-fmap-conn
([_] {n = ⟨ S m ⟩} {A = Susp^ m (EM₁ G.grp)} , idp)
([_] {n = ⟨ S n ⟩} {A = Susp^ n (EM₁ H.grp)} , idp)
(EM-conn G m)
(⊙Susp^-conn' n {{EM₁-conn}})
(trunc-proj-conn (Susp^ m (EM₁ G.grp)) ⟨ S m ⟩)
(trunc-proj-conn (Susp^ n (EM₁ H.grp)) ⟨ S n ⟩)
where
p₁ : ⟨ n ⟩₋₁ +2+ ⟨ S m ⟩ == ⟨ S m + S n ⟩
p₁ =
⟨ n ⟩₋₁ +2+ ⟨ S m ⟩
=⟨ ! (+-+2+ (S n) (S (S (S m)))) ⟩
⟨ n + S (S (S m)) ⟩₋₁
=⟨ ap ⟨_⟩₋₁ (+-βr n (S (S m))) ⟩
⟨ n + S (S m) ⟩
=⟨ ap ⟨_⟩ (+-βr n (S m)) ⟩
⟨ S n + S m ⟩
=⟨ ap ⟨_⟩ (+-comm (S n) (S m)) ⟩
⟨ S m + S n ⟩ =∎
p₂ : ⟨ m ⟩₋₁ +2+ ⟨ S n ⟩ == ⟨ S m + S n ⟩
p₂ =
⟨ m ⟩₋₁ +2+ ⟨ S n ⟩
=⟨ ! (+-+2+ (S m) (S (S (S n)))) ⟩
⟨ m + S (S (S n)) ⟩₋₁
=⟨ ap ⟨_⟩₋₁ (+-βr m (S (S n))) ⟩
⟨ m + S (S n) ⟩
=⟨ ap ⟨_⟩ (+-βr m (S n)) ⟩
⟨ S m + S n ⟩ =∎
p : minT (⟨ n ⟩₋₁ +2+ ⟨ S m ⟩) (⟨ m ⟩₋₁ +2+ ⟨ S n ⟩) == ⟨ S m + S n ⟩
p =
minT (⟨ n ⟩₋₁ +2+ ⟨ S m ⟩) (⟨ m ⟩₋₁ +2+ ⟨ S n ⟩)
=⟨ ap2 minT p₁ p₂ ⟩
minT ⟨ S m + S n ⟩ ⟨ S m + S n ⟩
=⟨ minT-out-l ≤T-refl ⟩
⟨ S m + S n ⟩ =∎
module SmashCPₕₕ (m n : ℕ) =
⊙ConnExtend
{Z = ⊙EM G⊗H.abgroup (S m + S n)}
{n = ⟨ S m + S n ⟩}
(⊙smash-truncate m n)
(smash-truncate-conn m n)
(EM-level G⊗H.abgroup (S m + S n))
⊙∧-cpₕₕ : ∀ (m n : ℕ)
→ ⊙EM G (S m) ⊙∧ ⊙EM H (S n) ⊙→ ⊙EM G⊗H.abgroup (S m + S n)
⊙∧-cpₕₕ m n = SmashCPₕₕ.⊙ext m n (⊙∧-cpₕₕ' m n)
∧-cpₕₕ : ∀ (m n : ℕ)
→ ⊙EM G (S m) ∧ ⊙EM H (S n)
→ EM G⊗H.abgroup (S m + S n)
∧-cpₕₕ m n = fst (⊙∧-cpₕₕ m n)
⊙×-cpₕₕ-seq : ∀ (m n : ℕ)
→ ⊙EM G (S m) ⊙× ⊙EM H (S n) ⊙–→ ⊙EM G⊗H.abgroup (S m + S n)
⊙×-cpₕₕ-seq m n = ⊙∧-cpₕₕ m n ◃⊙∘ ×-⊙to-∧ ◃⊙idf
⊙×-cpₕₕ : ∀ (m n : ℕ)
→ ⊙EM G (S m) ⊙× ⊙EM H (S n) ⊙→ ⊙EM G⊗H.abgroup (S m + S n)
⊙×-cpₕₕ m n = ⊙compose (⊙×-cpₕₕ-seq m n)
{-
cp₀ₕ' : ∀ (n : ℕ) → G.El → EM H (S n) → EM G⊗H.abgroup (S n)
cp₀ₕ' n g y = EM-fmap H G⊗H.abgroup (G⊗H.ins-r-hom g) (S n) y
×-cp₀ₕ' : ∀ (n : ℕ)
→ G.El × EM H (S n) → EM G⊗H.abgroup (S n)
×-cp₀ₕ' n = uncurry (cp₀ₕ' n)
-}
⊙×-cp₀ₕ' : ∀ (n : ℕ)
→ G.⊙El ⊙× ⊙EM H (S n) ⊙→ ⊙EM G⊗H.abgroup (S n)
⊙×-cp₀ₕ' n =
→-⊙→-uncurry (λ g → ⊙EM-fmap H G⊗H.abgroup (G⊗H.ins-r-hom g) (S n))
-- ×-cp₀ₕ' n , snd (⊙EM-fmap H G⊗H.abgroup (G⊗H.ins-r-hom G.ident) (S n))
⊙×-cp₀ₕ-seq : ∀ (n : ℕ)
→ ⊙EM G 0 ⊙× ⊙EM H (S n) ⊙–→ ⊙EM G⊗H.abgroup (S n)
⊙×-cp₀ₕ-seq n =
⊙×-cp₀ₕ' n ◃⊙∘
⊙×-fmap (⊙<– (⊙emloop-equiv G.grp)) (⊙idf (⊙EM H (S n))) ◃⊙idf
⊙×-cp₀ₕ : ∀ (n : ℕ)
→ ⊙EM G 0 ⊙× ⊙EM H (S n) ⊙→ ⊙EM G⊗H.abgroup (S n)
⊙×-cp₀ₕ n = ⊙compose (⊙×-cp₀ₕ-seq n)
×-cp₀ₕ : ∀ (n : ℕ)
→ EM G 0 × EM H (S n) → EM G⊗H.abgroup (S n)
×-cp₀ₕ n = fst (⊙×-cp₀ₕ n)
{-
cpₕ₀' : ∀ (m : ℕ) → EM G (S m) → H.El → EM G⊗H.abgroup (S m)
cpₕ₀' m x h = EM-fmap G G⊗H.abgroup (G⊗H.ins-l-hom h) (S m) x
×-cpₕ₀' : ∀ (m : ℕ)
→ EM G (S m) × H.El → EM G⊗H.abgroup (S m)
×-cpₕ₀' m = uncurry (cpₕ₀' m)
-}
⊙×-cpₕ₀' : ∀ (m : ℕ)
→ ⊙EM G (S m) ⊙× H.⊙El ⊙→ ⊙EM G⊗H.abgroup (S m)
⊙×-cpₕ₀' m =
→-⊙→-uncurry (λ h → ⊙EM-fmap G G⊗H.abgroup (G⊗H.ins-l-hom h) (S m)) ⊙∘
⊙×-swap
-- ×-cpₕ₀' m , snd (⊙EM-fmap G G⊗H.abgroup (G⊗H.ins-l-hom H.ident) (S m))
⊙×-cpₕ₀-seq : ∀ (m : ℕ)
→ ⊙EM G (S m) ⊙× ⊙EM H 0 ⊙–→ ⊙EM G⊗H.abgroup (S m + 0)
⊙×-cpₕ₀-seq m =
⊙transport (⊙EM G⊗H.abgroup) (! (+-unit-r (S m))) ◃⊙∘
⊙×-cpₕ₀' m ◃⊙∘
⊙×-fmap (⊙idf (⊙EM G (S m))) (⊙<– (⊙emloop-equiv H.grp)) ◃⊙idf
⊙×-cpₕ₀ : ∀ (m : ℕ)
→ ⊙EM G (S m) ⊙× ⊙EM H 0 ⊙→ ⊙EM G⊗H.abgroup (S m + 0)
⊙×-cpₕ₀ m = ⊙compose (⊙×-cpₕ₀-seq m)
×-cpₕ₀ : ∀ (m : ℕ)
→ EM G (S m) × EM H 0 → EM G⊗H.abgroup (S m + 0)
×-cpₕ₀ m = fst (⊙×-cpₕ₀ m)
⊙×-cp : ∀ (m n : ℕ)
→ ⊙EM G m ⊙× ⊙EM H n
⊙→ ⊙EM G⊗H.abgroup (m + n)
⊙×-cp 0 0 = ⊙×-cp₀₀ G H
⊙×-cp 0 (S n) = ⊙×-cp₀ₕ n
⊙×-cp (S m) 0 = ⊙×-cpₕ₀ m
⊙×-cp (S m) (S n) = ⊙×-cpₕₕ m n
| {
"alphanum_fraction": 0.4459716068,
"avg_line_length": 34.3447204969,
"ext": "agda",
"hexsha": "2402f7b85e7b784e737f6d522d063e786acbf8e0",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "theorems/cohomology/CupProduct/OnEM/InAllDegrees.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "theorems/cohomology/CupProduct/OnEM/InAllDegrees.agda",
"max_line_length": 84,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "theorems/cohomology/CupProduct/OnEM/InAllDegrees.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": 6535,
"size": 11059
} |
open import Level using (_⊔_)
open import Function using (_$_)
open import Algebra using (CommutativeRing)
module AKS.Modular.Equivalence {c ℓ} (R : CommutativeRing c ℓ) where
open CommutativeRing R using (0#; 1#; _+_; _*_; -_; _-_)
renaming (Carrier to C)
open CommutativeRing R using (+-cong; +-congˡ; +-congʳ; +-identityʳ; +-assoc; +-comm)
open CommutativeRing R using (-‿inverseʳ; -‿inverseˡ; -‿cong)
open CommutativeRing R using (zeroˡ; distribʳ; distribˡ; *-congˡ; *-assoc; *-comm)
open CommutativeRing R using (_≈_; isEquivalence; setoid; ring)
renaming (refl to ≈-refl; sym to ≈-sym)
open import Relation.Binary.Reasoning.Setoid setoid
open import Algebra.Properties.Ring ring using (-‿distribˡ-*; -‿+-comm; -‿involutive; -0#≈0#)
infix 4 _≈_[mod_]
record _≈_[mod_] (x : C) (y : C) (n : C) : Set (c ⊔ ℓ) where
constructor modulo
field
k : C
x-y≈k*n : x - y ≈ k * n
refl : ∀ {x} {y} {n} → x ≈ y → x ≈ y [mod n ]
refl {x} {y} {n} x≈y = modulo 0# $ begin
x - y ≈⟨ +-congˡ (-‿cong (≈-sym x≈y)) ⟩
x - x ≈⟨ -‿inverseʳ x ⟩
0# ≈⟨ ≈-sym (zeroˡ n) ⟩
0# * n ∎
sym : ∀ {x y} {n} → x ≈ y [mod n ] → y ≈ x [mod n ]
sym {x} {y} {n} (modulo k x-y≈k*n) = modulo (- k) $ begin
y - x ≈⟨ +-congʳ (≈-sym (-‿involutive y)) ⟩
- (- y) - x ≈⟨ -‿+-comm (- y) x ⟩
- (- y + x) ≈⟨ -‿cong (+-comm (- y) x) ⟩
- (x - y) ≈⟨ -‿cong x-y≈k*n ⟩
- (k * n) ≈⟨ -‿distribˡ-* k n ⟩
- k * n ∎
trans : ∀ {x y z} {n} → x ≈ y [mod n ] → y ≈ z [mod n ] → x ≈ z [mod n ]
trans {x} {y} {z} {n} (modulo k₁ x-y≈k₁*n) (modulo k₂ y-z≈k₂*n) = modulo (k₁ + k₂) $ begin
x - z ≈⟨ +-congʳ (≈-sym (+-identityʳ x)) ⟩
x + 0# - z ≈⟨ +-congʳ (+-congˡ (≈-sym (-‿inverseˡ y))) ⟩
x + (- y + y) - z ≈⟨ +-congʳ (≈-sym (+-assoc x (- y) y)) ⟩
(x - y) + y - z ≈⟨ +-assoc (x - y) y (- z) ⟩
(x - y) + (y - z) ≈⟨ +-cong x-y≈k₁*n y-z≈k₂*n ⟩
(k₁ * n) + (k₂ * n) ≈⟨ ≈-sym (distribʳ n k₁ k₂) ⟩
(k₁ + k₂) * n ∎
+-compat : ∀ {a₁ a₂ b₁ b₂} {n} → a₁ ≈ b₁ [mod n ] → a₂ ≈ b₂ [mod n ] → a₁ + a₂ ≈ b₁ + b₂ [mod n ]
+-compat {a₁} {a₂} {b₁} {b₂} {n} (modulo k₁ a₁-b₁≈k₁*n) (modulo k₂ a₂-b₂≈k₂*n) = modulo (k₁ + k₂) $ begin
a₁ + a₂ - (b₁ + b₂) ≈⟨ +-assoc a₁ a₂ (- (b₁ + b₂)) ⟩
a₁ + (a₂ - (b₁ + b₂)) ≈⟨ +-congˡ (+-congˡ (≈-sym (-‿+-comm b₁ b₂))) ⟩
a₁ + (a₂ + (- b₁ - b₂)) ≈⟨ +-congˡ (≈-sym (+-assoc a₂ (- b₁) (- b₂))) ⟩
a₁ + (a₂ - b₁ - b₂) ≈⟨ +-congˡ (+-congʳ (+-comm a₂ (- b₁))) ⟩
a₁ + (- b₁ + a₂ - b₂) ≈⟨ +-congˡ (+-assoc (- b₁) a₂ (- b₂)) ⟩
a₁ + (- b₁ + (a₂ - b₂)) ≈⟨ ≈-sym (+-assoc a₁ (- b₁) (a₂ - b₂)) ⟩
(a₁ - b₁) + (a₂ - b₂) ≈⟨ +-cong a₁-b₁≈k₁*n a₂-b₂≈k₂*n ⟩
(k₁ * n) + (k₂ * n) ≈⟨ ≈-sym (distribʳ n k₁ k₂) ⟩
(k₁ + k₂) * n ∎
*-compat : ∀ {a₁ a₂ b₁ b₂} {n} → a₁ ≈ b₁ [mod n ] → a₂ ≈ b₂ [mod n ] → a₁ * a₂ ≈ b₁ * b₂ [mod n ]
*-compat {a₁} {a₂} {b₁} {b₂} {n} (modulo k₁ a₁-b₁≈k₁*n) (modulo k₂ a₂-b₂≈k₂*n) = modulo (a₂ * k₁ + b₁ * k₂) $ begin
a₁ * a₂ - b₁ * b₂ ≈⟨ +-congˡ (-‿cong (*-comm b₁ b₂)) ⟩
a₁ * a₂ - b₂ * b₁ ≈⟨ +-congʳ (≈-sym (+-identityʳ (a₁ * a₂))) ⟩
a₁ * a₂ + 0# - b₂ * b₁ ≈⟨ +-congʳ (+-congˡ lemma) ⟩
a₁ * a₂ + (- (b₁ * a₂) + a₂ * b₁) - b₂ * b₁ ≈⟨ +-congʳ (≈-sym (+-assoc (a₁ * a₂) (- (b₁ * a₂)) (a₂ * b₁))) ⟩
a₁ * a₂ - b₁ * a₂ + a₂ * b₁ - b₂ * b₁ ≈⟨ +-assoc (a₁ * a₂ - b₁ * a₂) (a₂ * b₁) (- (b₂ * b₁)) ⟩
(a₁ * a₂ - b₁ * a₂) + (a₂ * b₁ - b₂ * b₁) ≈⟨ +-cong (+-congˡ (-‿distribˡ-* b₁ a₂)) (+-congˡ (-‿distribˡ-* b₂ b₁)) ⟩
(a₁ * a₂ + (- b₁) * a₂) + (a₂ * b₁ + (- b₂) * b₁) ≈⟨ +-cong (≈-sym (distribʳ a₂ a₁ (- b₁))) (≈-sym (distribʳ b₁ a₂ (- b₂))) ⟩
(a₁ - b₁) * a₂ + (a₂ - b₂) * b₁ ≈⟨ +-cong (*-comm (a₁ - b₁) a₂) (*-comm (a₂ - b₂) b₁) ⟩
a₂ * (a₁ - b₁) + b₁ * (a₂ - b₂) ≈⟨ +-cong (*-congˡ a₁-b₁≈k₁*n) (*-congˡ a₂-b₂≈k₂*n) ⟩
a₂ * (k₁ * n) + b₁ * (k₂ * n) ≈⟨ +-cong (≈-sym (*-assoc a₂ k₁ n)) (≈-sym (*-assoc b₁ k₂ n)) ⟩
a₂ * k₁ * n + b₁ * k₂ * n ≈⟨ ≈-sym (distribʳ n (a₂ * k₁) (b₁ * k₂)) ⟩
(a₂ * k₁ + b₁ * k₂) * n ∎
where
lemma : 0# ≈ - (b₁ * a₂) + a₂ * b₁
lemma = begin
0# ≈⟨ ≈-sym (-‿inverseˡ (b₁ * a₂)) ⟩
- (b₁ * a₂) + b₁ * a₂ ≈⟨ +-congˡ (*-comm b₁ a₂) ⟩
- (b₁ * a₂) + a₂ * b₁ ∎
n*x≈0 : ∀ {x} {n} → n * x ≈ 0# [mod n ]
n*x≈0 {x} {n} = modulo x $ begin
n * x - 0# ≈⟨ +-congˡ -0#≈0# ⟩
n * x + 0# ≈⟨ +-identityʳ (n * x) ⟩
n * x ≈⟨ *-comm n x ⟩
x * n ∎
| {
"alphanum_fraction": 0.4345132743,
"avg_line_length": 50.7865168539,
"ext": "agda",
"hexsha": "37f9ba530bd3701fc2bc101df3843a8e2cb411fc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/thesis",
"max_forks_repo_path": "proofs/AKS/Modular/Equivalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mckeankylej/thesis",
"max_issues_repo_path": "proofs/AKS/Modular/Equivalence.agda",
"max_line_length": 127,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/thesis",
"max_stars_repo_path": "proofs/AKS/Modular/Equivalence.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z",
"num_tokens": 2458,
"size": 4520
} |
{-# OPTIONS --prop --rewriting --confluence-check #-}
open import Agda.Primitive
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat renaming (Nat to ℕ; _+_ to _+ℕ_)
infix 4 _≐_
data _≐_ {ℓ} {A : Set ℓ} (x : A) : A → Prop ℓ where
refl : x ≐ x
{-# BUILTIN REWRITE _≐_ #-}
variable
ℓ : Level
A B C : Set ℓ
x y z : A
cong : (f : A → B) → x ≐ y → f x ≐ f y
cong f refl = refl
data ℤ : Set where
zero : ℤ
pred suc : ℤ → ℤ
postulate
pred-suc : (x : ℤ) → pred (suc x) ≐ x
suc-pred : (x : ℤ) → suc (pred x) ≐ x
{-# REWRITE pred-suc suc-pred #-}
_+_ : ℤ → ℤ → ℤ
zero + y = y
pred x + y = pred (x + y)
suc x + y = suc (x + y)
-_ : ℤ → ℤ
- zero = zero
- pred x = suc (- x)
- suc x = pred (- x)
data ℤ′ : Set where
+[_] : ℕ → ℤ′
-[1+_] : ℕ → ℤ′
suc′ : ℤ′ → ℤ′
suc′ +[ x ] = +[ suc x ]
suc′ -[1+ zero ] = +[ zero ]
suc′ -[1+ suc x ] = -[1+ x ]
pred′ : ℤ′ → ℤ′
pred′ +[ zero ] = -[1+ zero ]
pred′ +[ suc x ] = +[ x ]
pred′ -[1+ x ] = -[1+ suc x ]
suc-pred′ : suc′ (pred′ x) ≐ x
suc-pred′ {+[ zero ]} = refl
suc-pred′ {+[ suc x ]} = refl
suc-pred′ { -[1+ x ]} = refl
pred-suc′ : pred′ (suc′ x) ≐ x
pred-suc′ {+[ x ]} = refl
pred-suc′ { -[1+ zero ]} = refl
pred-suc′ { -[1+ suc x ]} = refl
{-# REWRITE suc-pred′ pred-suc′ #-}
norm : ℤ → ℤ′
norm zero = +[ 0 ]
norm (pred x) = pred′ (norm x)
norm (suc x) = suc′ (norm x)
free : ℤ′ → ℤ
free +[ zero ] = zero
free +[ suc x ] = suc (free +[ x ])
free -[1+ zero ] = pred zero
free -[1+ suc x ] = pred (free -[1+ x ])
| {
"alphanum_fraction": 0.4976651101,
"avg_line_length": 19.4675324675,
"ext": "agda",
"hexsha": "f4b10aea4e908f0d7ed45bb493f4f8e3d4b5cc1b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.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/ConstructorRewriteConfluence.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/ConstructorRewriteConfluence.agda",
"max_line_length": 61,
"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/ConstructorRewriteConfluence.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": 686,
"size": 1499
} |
open import Nat
open import Prelude
open import core
module judgemental-inconsistency where
data incon : τ̇ → τ̇ → Set where
ICNumArr1 : {t1 t2 : τ̇} → incon num (t1 ==> t2)
ICNumArr2 : {t1 t2 : τ̇} → incon (t1 ==> t2) num
ICArr1 : {t1 t2 t3 t4 : τ̇} →
incon t1 t3 →
incon (t1 ==> t2) (t3 ==> t4)
ICArr2 : {t1 t2 t3 t4 : τ̇} →
incon t2 t4 →
incon (t1 ==> t2) (t3 ==> t4)
-- inconsistency is symmetric
inconsym : ∀ {t1 t2} → incon t1 t2 → incon t2 t1
inconsym ICNumArr1 = ICNumArr2
inconsym ICNumArr2 = ICNumArr1
inconsym (ICArr1 x) = ICArr1 (inconsym x)
inconsym (ICArr2 x) = ICArr2 (inconsym x)
--inconsistency isn't reflexive
incon-nrefl : ∀{t} → incon t t → ⊥
incon-nrefl (ICArr1 x) = incon-nrefl x
incon-nrefl (ICArr2 x) = incon-nrefl x
-- first half of iso
to~̸ : (t1 t2 : τ̇) → incon t1 t2 → t1 ~̸ t2
to~̸ .num ._ ICNumArr1 ()
to~̸ ._ .num ICNumArr2 ()
to~̸ ._ ._ (ICArr1 incon) TCRefl = abort (incon-nrefl incon)
to~̸ ._ ._ (ICArr1 incon) (TCArr x x₁) = to~̸ _ _ incon x
to~̸ ._ ._ (ICArr2 incon) TCRefl = abort (incon-nrefl incon)
to~̸ ._ ._ (ICArr2 incon) (TCArr x x₁) = (to~̸ _ _ incon x₁)
-- second half of iso
from~̸ : (t1 t2 : τ̇) → t1 ~̸ t2 → incon t1 t2
from~̸ num (t2 ==> t3) ncon = ICNumArr1
from~̸ (t1 ==> t2) num ncon = ICNumArr2
from~̸ (t1 ==> t2) (t3 ==> t4) ncon with ~dec t1 t3
... | Inl qq = ICArr2 (from~̸ t2 t4 (λ x → ncon (TCArr qq x)))
... | Inr qq = ICArr1 (from~̸ _ _ qq)
-- the remaining consistent types all lead to absurdities
from~̸ num num ncon = abort (ncon TCRefl)
from~̸ num ⦇-⦈ ncon = abort (ncon TCHole1)
from~̸ ⦇-⦈ num ncon = abort (ncon TCHole2)
from~̸ ⦇-⦈ ⦇-⦈ ncon = abort (ncon TCRefl)
from~̸ ⦇-⦈ (t2 ==> t3) ncon = abort (ncon TCHole2)
from~̸ (t1 ==> t2) ⦇-⦈ ncon = abort (ncon TCHole1)
-- need to display that at least one of the round-trips above is stable
-- for this to be structure preserving and really an iso.
rt1 : (t1 t2 : τ̇) → (x : t1 ~̸ t2) → (to~̸ t1 t2 (from~̸ t1 t2 x)) == x
rt1 num (t2 ==> t3) x = funext (λ x₁ → abort (x x₁))
rt1 (t1 ==> t2) num x = funext (λ x₁ → abort (x x₁))
rt1 (t1 ==> t2) (t3 ==> t4) x = funext (λ x₁ → abort (x x₁))
rt1 num num x = abort (x TCRefl)
rt1 num ⦇-⦈ x = abort (x TCHole1)
rt1 ⦇-⦈ num x = abort (x TCHole2)
rt1 ⦇-⦈ ⦇-⦈ x = abort (x TCRefl)
rt1 ⦇-⦈ (t2 ==> t3) x = abort (x TCHole2)
rt1 (t1 ==> t2) ⦇-⦈ x = abort (x TCHole1)
-- if inconsistency at arrows is proof-irrelevant, then all of
-- inconsistency is proof-irrelevant
incon-irrelev : (arr-incon-irrelev : {t1 t2 t3 t4 : τ̇} (x y : incon (t1 ==> t2) (t3 ==> t4)) → x == y) →
(t1 t2 : τ̇) (x y : incon t1 t2) → x == y
incon-irrelev arr-incon-irrelev .num _ ICNumArr1 ICNumArr1 = refl
incon-irrelev arr-incon-irrelev _ .num ICNumArr2 ICNumArr2 = refl
incon-irrelev arr-incon-irrelev _ _ (ICArr1 x) (ICArr1 y) = ap1 ICArr1 (incon-irrelev arr-incon-irrelev _ _ x y)
incon-irrelev arr-incon-irrelev _ _ (ICArr1 x) (ICArr2 y) = arr-incon-irrelev (ICArr1 x) (ICArr2 y)
incon-irrelev arr-incon-irrelev _ _ (ICArr2 x) (ICArr1 y) = arr-incon-irrelev (ICArr2 x) (ICArr1 y)
incon-irrelev arr-incon-irrelev _ _ (ICArr2 x) (ICArr2 y) = ap1 ICArr2 (incon-irrelev arr-incon-irrelev _ _ x y )
-- if inconsistency at arrows is proof-irrelevant, then the round trip is
-- stable up to equality
rt2 : (arr-incon-irrelev : {t1 t2 t3 t4 : τ̇} (x y : incon (t1 ==> t2) (t3 ==> t4)) → x == y) →
(t1 t2 : τ̇) → (x : incon t1 t2) → (from~̸ t1 t2 (to~̸ t1 t2 x)) == x
rt2 arr-incon-irrelev .num _ ICNumArr1 = refl
rt2 arr-incon-irrelev _ .num ICNumArr2 = refl
rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr1 x) with ~dec t1 t3
rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr1 x₁) | Inl x = abort (to~̸ t1 t3 x₁ x)
rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr1 x₁) | Inr x = ap1 ICArr1 (incon-irrelev arr-incon-irrelev t1 t3 (from~̸ t1 t3 x) x₁)
rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr2 x) with ~dec t1 t3
rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr2 x₁) | Inl x = ap1 ICArr2 (incon-irrelev arr-incon-irrelev t2 t4 (from~̸ t2 t4 (to~̸ t2 t4 x₁)) x₁)
rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr2 x₁) | Inr x = arr-incon-irrelev (ICArr1 (from~̸ t1 t3 x)) (ICArr2 x₁)
-- if inconsistency at arrows is proof-irrelevant, then the two
-- defintions of inconsistency are isomorphic
incon-iso : (arr-incon-irrelev : {t1 t2 t3 t4 : τ̇} (x y : incon (t1 ==> t2) (t3 ==> t4)) → x == y)
→ (t1 t2 : τ̇) → (incon t1 t2) ≃ (t1 ~̸ t2)
incon-iso arr-incon-irrelev t1 t2 = (to~̸ t1 t2) , (from~̸ t1 t2) , (rt2 arr-incon-irrelev t1 t2) , (rt1 t1 t2)
| {
"alphanum_fraction": 0.5773322422,
"avg_line_length": 52,
"ext": "agda",
"hexsha": "ba4b6c5221a88d0dae69a700aa1fd4621b2014a8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-07-03T03:45:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-07-03T03:45:07.000Z",
"max_forks_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/agda-popl17",
"max_forks_repo_path": "judgemental-inconsistency.agda",
"max_issues_count": 37,
"max_issues_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_issues_repo_issues_event_max_datetime": "2016-11-09T18:13:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-07-07T16:23:11.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/agda-popl17",
"max_issues_repo_path": "judgemental-inconsistency.agda",
"max_line_length": 154,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/agda-popl17",
"max_stars_repo_path": "judgemental-inconsistency.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-11T12:30:50.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-01T22:44:11.000Z",
"num_tokens": 2209,
"size": 4888
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import stash.modalities.Orthogonality
module stash.modalities.NullifyFamily where
module _ {ℓ} {I : Type ℓ} (X : I → Type ℓ) (A : Type ℓ) where
private
data #NullifyAll : Type ℓ where
#inj : A → #NullifyAll
#apex : (i : I) → (X i → #NullifyAll) → #NullifyAll
NullifyAll : Type ℓ
NullifyAll = #NullifyAll
inj : A → NullifyAll
inj = #inj
apex : (i : I) → (X i → #NullifyAll) → #NullifyAll
apex = #apex
postulate
apex-path : (i : I) (α : X i → NullifyAll) (x : X i) → apex i α == α x
apex-cst : (i : I) (n : NullifyAll) → apex i (λ _ → n) == n
apex-adj : (i : I) (n : NullifyAll) → ap (Δ NullifyAll (X i)) (apex-cst i n) == λ= (apex-path i (Δ NullifyAll (X i) n))
module NullifyAllElim (Q : NullifyAll → Type ℓ) (is-null : ⟦ X ⊥ Q ⟧) (φ : Π A (Q ∘ inj)) where
f : Π NullifyAll Q
f (#inj a) = φ a
f (#apex i α) = is-equiv.g (is-null i (#apex i α)) α'
where α' : X i → Q (#apex i α)
α' x = transport! Q (apex-path i α x) (f (α x))
module _ {ℓ} {I : Type ℓ} (X : I → Type ℓ) where
nullify-is-null : (A : Type ℓ) → ⟦ X ⊥ NullifyAll X A ⟧ₗ
is-equiv.g (nullify-is-null A i) = apex X A i
is-equiv.f-g (nullify-is-null A i) α = λ= (λ x → apex-path X A i α x)
is-equiv.g-f (nullify-is-null A i) = apex-cst X A i
is-equiv.adj (nullify-is-null A i) = apex-adj X A i
open Modality
NullifyAllModality : Modality ℓ
is-local NullifyAllModality A = ⟦ X ⊥ A ⟧ₗ
is-local-is-prop NullifyAllModality {A} = Π-level (λ i → is-equiv-is-prop)
◯ NullifyAllModality A = NullifyAll X A
◯-is-local NullifyAllModality {A} = nullify-is-null A
η NullifyAllModality {A} = inj X A
◯-elim NullifyAllModality Q Q-is-null φ = NullifyAllElim.f X _ Q (λ i n → Q-is-null n i) φ
◯-elim-β NullifyAllModality Q Q-is-null φ a = idp
◯-== NullifyAllModality {A} a₀ a₁ i = is-eq _ squash inv-l inv-r
where a₀' : NullifyAll X A
a₀' = apex X A i (λ _ → a₀)
a₁' : NullifyAll X A
a₁' = apex X A i (λ _ → a₁)
squash : (X i → a₀ == a₁) → a₀ == a₁
squash φ = ! (apex-cst X A i a₀) ∙ cyl ∙ apex-cst X A i a₁
where cyl : a₀' == a₁'
cyl = ap (apex X A i) (λ= φ)
inv-l : (φ : X i → a₀ == a₁) → (λ _ → squash φ) == φ
inv-l φ = {!!}
inv-r : (p : a₀ == a₁) → squash (λ _ → p) == p
inv-r p = {!!}
-- Main idea is to use this coherence ... (and possibly the other adjoint as well)
-- apex-adj : (i : I) (n : NullifyAll) → ap (Δ NullifyAll (X i)) (apex-cst i n) == λ= (apex-path i (Δ NullifyAll (X i) n))
| {
"alphanum_fraction": 0.5220640569,
"avg_line_length": 35.125,
"ext": "agda",
"hexsha": "a85415252cc2284c367bccdc0ce8cdad41d5ba85",
"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/stash/modalities/NullifyFamily.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/stash/modalities/NullifyFamily.agda",
"max_line_length": 134,
"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/stash/modalities/NullifyFamily.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": 1059,
"size": 2810
} |
open import Data.Bool using ( Bool ; true ; false ; if_then_else_ )
open import Data.Empty using ( ⊥-elim )
open import Data.Product using ( _×_ ; _,_ )
open import Data.Sum using ( inj₁ ; inj₂ )
open import Relation.Unary using ( _∈_ ; _∉_ )
open import Web.Semantic.DL.Concept using ( neg )
open import Web.Semantic.DL.Concept.Model using ( _⟦_⟧₁ ; neg-sound )
open import Web.Semantic.DL.Concept.Skolemization using
( CSkolems ; cskolem ; cskolem-sound )
open import Web.Semantic.DL.FOL using
( Formula ; true ; false ; _∧_ ; _∈₁_ ; _∈₂_ ; _∼_ ; ∀₁ )
open import Web.Semantic.DL.FOL.Model using ( _⊨f_ )
open import Web.Semantic.DL.Role.Skolemization using
( rskolem ; rskolem⇒ ; rskolem-sound ; rskolem⇒-sound )
open import Web.Semantic.DL.Role.Model using ( _⟦_⟧₂ )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using
( TBox ; ε ; _,_ ;_⊑₁_ ; _⊑₂_ ; Dis ; Ref ; Irr ; Tra )
open import Web.Semantic.DL.TBox.Model using ( _⊨t_ )
open import Web.Semantic.Util using ( True ; tt )
module Web.Semantic.DL.TBox.Skolemization {Σ : Signature} where
TSkolems : Set → TBox Σ → Set
TSkolems Δ ε = True
TSkolems Δ (T , U) = (TSkolems Δ T) × (TSkolems Δ U)
TSkolems Δ (C ⊑₁ D) = (Δ → Bool) × (CSkolems Δ (neg C)) × (CSkolems Δ D)
TSkolems Δ (Q ⊑₂ R) = True
TSkolems Δ (Dis Q R) = True
TSkolems Δ (Ref R) = True
TSkolems Δ (Irr R) = True
TSkolems Δ (Tra R) = True
tskolem : ∀ {Δ} T → (TSkolems Δ T) → Formula Σ Δ
tskolem ε Φ = true
tskolem (T , U) (Φ , Ψ) = (tskolem T Φ) ∧ (tskolem U Ψ)
tskolem (C ⊑₁ D) (φ , Φ , Ψ) = ∀₁ λ x →
if (φ x) then (cskolem (neg C) Φ x) else (cskolem D Ψ x)
tskolem (Q ⊑₂ R) Φ = ∀₁ λ x → ∀₁ λ y →
rskolem⇒ Q x y (rskolem R x y)
tskolem (Dis Q R) Φ = ∀₁ λ x → ∀₁ λ y →
rskolem⇒ Q x y (rskolem⇒ R x y false)
tskolem (Ref R) Φ = ∀₁ λ x →
rskolem R x x
tskolem (Irr R) Φ = ∀₁ λ x →
rskolem⇒ R x x false
tskolem (Tra R) Φ = ∀₁ λ x → ∀₁ λ y → ∀₁ λ z →
rskolem⇒ R x y (rskolem⇒ R y z (rskolem R x z))
tskolem-sound : ∀ I T Φ → (I ⊨f tskolem T Φ) → (I ⊨t T)
tskolem-sound I ε Φ _ = tt
tskolem-sound I (T , U) (Φ , Ψ) (I⊨T , I⊨U) =
(tskolem-sound I T Φ I⊨T , tskolem-sound I U Ψ I⊨U)
tskolem-sound I (C ⊑₁ D) (φ , Φ , Ψ) I⊨C⊑D = lemma where
lemma : ∀ {x} → (x ∈ I ⟦ C ⟧₁) → (x ∈ I ⟦ D ⟧₁)
lemma {x} x∈⟦C⟧ with φ x | I⊨C⊑D x
lemma {x} x∈⟦C⟧ | true | x∈⟦¬C⟧ =
⊥-elim (neg-sound I C (cskolem-sound I (neg C) Φ x x∈⟦¬C⟧) x∈⟦C⟧)
lemma {x} x∈⟦C⟧ | false | x∈⟦D⟧ =
cskolem-sound I D Ψ x x∈⟦D⟧
tskolem-sound I (Q ⊑₂ R) Φ I⊨Q⊑R = lemma where
lemma : ∀ {xy} → (xy ∈ I ⟦ Q ⟧₂) → (xy ∈ I ⟦ R ⟧₂)
lemma {x , y} xy∈⟦Q⟧ =
rskolem-sound I R x y (rskolem⇒-sound I Q x y _ (I⊨Q⊑R x y) xy∈⟦Q⟧)
tskolem-sound I (Dis Q R) Φ I⊨DisQR = lemma where
lemma : ∀ {xy} → (xy ∈ I ⟦ Q ⟧₂) → (xy ∉ I ⟦ R ⟧₂)
lemma {x , y} xy∈⟦Q⟧ =
rskolem⇒-sound I R x y _ (rskolem⇒-sound I Q x y _ (I⊨DisQR x y) xy∈⟦Q⟧)
tskolem-sound I (Ref R) Φ I⊨RefR = λ x → rskolem-sound I R x x (I⊨RefR x)
tskolem-sound I (Irr R) Φ I⊨IrrR = λ x → rskolem⇒-sound I R x x _ (I⊨IrrR x)
tskolem-sound I (Tra R) Φ I⊨TraR =
λ {x} {y} {z} xy∈⟦R⟧ yz∈⟦R⟧ → rskolem-sound I R x z
(rskolem⇒-sound I R y z _ (rskolem⇒-sound I R x y _ (I⊨TraR x y z) xy∈⟦R⟧) yz∈⟦R⟧) | {
"alphanum_fraction": 0.5978901644,
"avg_line_length": 44.1506849315,
"ext": "agda",
"hexsha": "eb8b9b160385c818871b89890f895d9d22805127",
"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/TBox/Skolemization.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/TBox/Skolemization.agda",
"max_line_length": 86,
"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/TBox/Skolemization.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": 1621,
"size": 3223
} |
module examplesPaperJFP.CatTerm where
open import examplesPaperJFP.BasicIO hiding (main)
open import examplesPaperJFP.Console hiding (main)
open import examplesPaperJFP.NativeIOSafe
cat : IO ConsoleInterface Unit
force cat =
exec′ getLine λ{ nothing → return unit ; (just line) → delay (
exec′ (putStrLn line) λ _ →
cat )}
| {
"alphanum_fraction": 0.7016574586,
"avg_line_length": 30.1666666667,
"ext": "agda",
"hexsha": "6748914ae783edfa4fa13228a41fc7bd06c7d8ce",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/examplesPaperJFP/CatTerm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"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/ooAgda",
"max_issues_repo_path": "examples/examplesPaperJFP/CatTerm.agda",
"max_line_length": 73,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/examplesPaperJFP/CatTerm.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 91,
"size": 362
} |
open import Prelude
open import Nat
open import core
open import contexts
open import disjointness
-- this module contains lemmas and properties about the holes-disjoint
-- judgement that double check that it acts as we would expect
module holes-disjoint-checks where
-- these lemmas are all structurally recursive and quite
-- mechanical. morally, they establish the properties about reduction
-- that would be obvious / baked into Agda if holes-disjoint was defined
-- as a function rather than a judgement (datatype), or if we had defined
-- all the O(n^2) cases rather than relying on a little indirection to
-- only have O(n) cases. that work has to go somewhwere, and we prefer
-- that it goes here.
ds-lem-asc : ∀{e1 e2 τ} → holes-disjoint e2 e1 → holes-disjoint e2 (e1 ·: τ)
ds-lem-asc HDConst = HDConst
ds-lem-asc (HDAsc hd) = HDAsc (ds-lem-asc hd)
ds-lem-asc HDVar = HDVar
ds-lem-asc (HDLam1 hd) = HDLam1 (ds-lem-asc hd)
ds-lem-asc (HDLam2 hd) = HDLam2 (ds-lem-asc hd)
ds-lem-asc (HDHole x) = HDHole (HNAsc x)
ds-lem-asc (HDNEHole x hd) = HDNEHole (HNAsc x) (ds-lem-asc hd)
ds-lem-asc (HDAp hd hd₁) = HDAp (ds-lem-asc hd) (ds-lem-asc hd₁)
ds-lem-asc (HDFst hd) = HDFst (ds-lem-asc hd)
ds-lem-asc (HDSnd hd) = HDSnd (ds-lem-asc hd)
ds-lem-asc (HDPair hd hd₁) = HDPair (ds-lem-asc hd) (ds-lem-asc hd₁)
ds-lem-lam1 : ∀{e1 e2 x} → holes-disjoint e2 e1 → holes-disjoint e2 (·λ x e1)
ds-lem-lam1 HDConst = HDConst
ds-lem-lam1 (HDAsc hd) = HDAsc (ds-lem-lam1 hd)
ds-lem-lam1 HDVar = HDVar
ds-lem-lam1 (HDLam1 hd) = HDLam1 (ds-lem-lam1 hd)
ds-lem-lam1 (HDLam2 hd) = HDLam2 (ds-lem-lam1 hd)
ds-lem-lam1 (HDHole x₁) = HDHole (HNLam1 x₁)
ds-lem-lam1 (HDNEHole x₁ hd) = HDNEHole (HNLam1 x₁) (ds-lem-lam1 hd)
ds-lem-lam1 (HDAp hd hd₁) = HDAp (ds-lem-lam1 hd) (ds-lem-lam1 hd₁)
ds-lem-lam1 (HDFst hd) = HDFst (ds-lem-lam1 hd)
ds-lem-lam1 (HDSnd hd) = HDSnd (ds-lem-lam1 hd)
ds-lem-lam1 (HDPair hd hd₁) = HDPair (ds-lem-lam1 hd) (ds-lem-lam1 hd₁)
ds-lem-lam2 : ∀{e1 e2 x τ} → holes-disjoint e2 e1 → holes-disjoint e2 (·λ x [ τ ] e1)
ds-lem-lam2 HDConst = HDConst
ds-lem-lam2 (HDAsc hd) = HDAsc (ds-lem-lam2 hd)
ds-lem-lam2 HDVar = HDVar
ds-lem-lam2 (HDLam1 hd) = HDLam1 (ds-lem-lam2 hd)
ds-lem-lam2 (HDLam2 hd) = HDLam2 (ds-lem-lam2 hd)
ds-lem-lam2 (HDHole x₁) = HDHole (HNLam2 x₁)
ds-lem-lam2 (HDNEHole x₁ hd) = HDNEHole (HNLam2 x₁) (ds-lem-lam2 hd)
ds-lem-lam2 (HDAp hd hd₁) = HDAp (ds-lem-lam2 hd) (ds-lem-lam2 hd₁)
ds-lem-lam2 (HDFst hd) = HDFst (ds-lem-lam2 hd)
ds-lem-lam2 (HDSnd hd) = HDSnd (ds-lem-lam2 hd)
ds-lem-lam2 (HDPair hd hd₁) = HDPair (ds-lem-lam2 hd) (ds-lem-lam2 hd₁)
ds-lem-nehole : ∀{e e1 u} → holes-disjoint e e1 → hole-name-new e u → holes-disjoint e ⦇⌜ e1 ⌟⦈[ u ]
ds-lem-nehole HDConst ν = HDConst
ds-lem-nehole (HDAsc hd) (HNAsc ν) = HDAsc (ds-lem-nehole hd ν)
ds-lem-nehole HDVar ν = HDVar
ds-lem-nehole (HDLam1 hd) (HNLam1 ν) = HDLam1 (ds-lem-nehole hd ν)
ds-lem-nehole (HDLam2 hd) (HNLam2 ν) = HDLam2 (ds-lem-nehole hd ν)
ds-lem-nehole (HDHole x) (HNHole x₁) = HDHole (HNNEHole (flip x₁) x)
ds-lem-nehole (HDNEHole x hd) (HNNEHole x₁ ν) = HDNEHole (HNNEHole (flip x₁) x) (ds-lem-nehole hd ν)
ds-lem-nehole (HDAp hd hd₁) (HNAp ν ν₁) = HDAp (ds-lem-nehole hd ν) (ds-lem-nehole hd₁ ν₁)
ds-lem-nehole (HDFst hd) (HNFst v) = HDFst (ds-lem-nehole hd v)
ds-lem-nehole (HDSnd hd) (HNSnd v) = HDSnd (ds-lem-nehole hd v)
ds-lem-nehole (HDPair hd hd₁) (HNPair v v₁) = HDPair (ds-lem-nehole hd v) (ds-lem-nehole hd₁ v₁)
ds-lem-ap : ∀{e1 e2 e3} → holes-disjoint e3 e1 → holes-disjoint e3 e2 → holes-disjoint e3 (e1 ∘ e2)
ds-lem-ap HDConst hd2 = HDConst
ds-lem-ap (HDAsc hd1) (HDAsc hd2) = HDAsc (ds-lem-ap hd1 hd2)
ds-lem-ap HDVar hd2 = HDVar
ds-lem-ap (HDLam1 hd1) (HDLam1 hd2) = HDLam1 (ds-lem-ap hd1 hd2)
ds-lem-ap (HDLam2 hd1) (HDLam2 hd2) = HDLam2 (ds-lem-ap hd1 hd2)
ds-lem-ap (HDHole x) (HDHole x₁) = HDHole (HNAp x x₁)
ds-lem-ap (HDNEHole x hd1) (HDNEHole x₁ hd2) = HDNEHole (HNAp x x₁) (ds-lem-ap hd1 hd2)
ds-lem-ap (HDAp hd1 hd2) (HDAp hd3 hd4) = HDAp (ds-lem-ap hd1 hd3) (ds-lem-ap hd2 hd4)
ds-lem-ap (HDFst hd) (HDFst hd2) = HDFst (ds-lem-ap hd hd2)
ds-lem-ap (HDSnd hd) (HDSnd hd2) = HDSnd (ds-lem-ap hd hd2)
ds-lem-ap (HDPair hd1 hd2) (HDPair hd3 hd4) = HDPair (ds-lem-ap hd1 hd3) (ds-lem-ap hd2 hd4)
ds-lem-pair : ∀{e1 e2 e3} → holes-disjoint e3 e1 → holes-disjoint e3 e2 → holes-disjoint e3 ⟨ e1 , e2 ⟩
ds-lem-pair HDConst HDConst = HDConst
ds-lem-pair (HDAsc hd1) (HDAsc hd2) = HDAsc (ds-lem-pair hd1 hd2)
ds-lem-pair HDVar HDVar = HDVar
ds-lem-pair (HDLam1 hd1) (HDLam1 hd2) = HDLam1 (ds-lem-pair hd1 hd2)
ds-lem-pair (HDLam2 hd1) (HDLam2 hd2) = HDLam2 (ds-lem-pair hd1 hd2)
ds-lem-pair (HDHole x) (HDHole x₁) = HDHole (HNPair x x₁)
ds-lem-pair (HDNEHole x hd1) (HDNEHole x₁ hd2) = HDNEHole (HNPair x x₁) (ds-lem-pair hd1 hd2)
ds-lem-pair (HDAp hd1 hd2) (HDAp hd3 hd4) = HDAp (ds-lem-pair hd1 hd3) (ds-lem-pair hd2 hd4)
ds-lem-pair (HDFst hd1) (HDFst hd2) = HDFst (ds-lem-pair hd1 hd2)
ds-lem-pair (HDSnd hd1) (HDSnd hd2) = HDSnd (ds-lem-pair hd1 hd2)
ds-lem-pair (HDPair hd1 hd2) (HDPair hd3 hd4) = HDPair (ds-lem-pair hd1 hd3) (ds-lem-pair hd2 hd4)
ds-lem-fst : ∀{e e'} → holes-disjoint e' e → holes-disjoint e' (fst e)
ds-lem-fst HDConst = HDConst
ds-lem-fst (HDAsc hd) = HDAsc (ds-lem-fst hd)
ds-lem-fst HDVar = HDVar
ds-lem-fst (HDLam1 hd) = HDLam1 (ds-lem-fst hd)
ds-lem-fst (HDLam2 hd) = HDLam2 (ds-lem-fst hd)
ds-lem-fst (HDHole x) = HDHole (HNFst x)
ds-lem-fst (HDNEHole x hd) = HDNEHole (HNFst x) (ds-lem-fst hd)
ds-lem-fst (HDAp hd hd₁) = HDAp (ds-lem-fst hd) (ds-lem-fst hd₁)
ds-lem-fst (HDFst hd) = HDFst (ds-lem-fst hd)
ds-lem-fst (HDSnd hd) = HDSnd (ds-lem-fst hd)
ds-lem-fst (HDPair hd hd₁) = HDPair (ds-lem-fst hd) (ds-lem-fst hd₁)
ds-lem-snd : ∀{e e'} → holes-disjoint e' e → holes-disjoint e' (snd e)
ds-lem-snd HDConst = HDConst
ds-lem-snd (HDAsc hd) = HDAsc (ds-lem-snd hd)
ds-lem-snd HDVar = HDVar
ds-lem-snd (HDLam1 hd) = HDLam1 (ds-lem-snd hd)
ds-lem-snd (HDLam2 hd) = HDLam2 (ds-lem-snd hd)
ds-lem-snd (HDHole x) = HDHole (HNSnd x)
ds-lem-snd (HDNEHole x hd) = HDNEHole (HNSnd x) (ds-lem-snd hd)
ds-lem-snd (HDAp hd hd₁) = HDAp (ds-lem-snd hd) (ds-lem-snd hd₁)
ds-lem-snd (HDFst hd) = HDFst (ds-lem-snd hd)
ds-lem-snd (HDSnd hd) = HDSnd (ds-lem-snd hd)
ds-lem-snd (HDPair hd hd₁) = HDPair (ds-lem-snd hd) (ds-lem-snd hd₁)
-- holes-disjoint is symmetric
disjoint-sym : (e1 e2 : eexp) → holes-disjoint e1 e2 → holes-disjoint e2 e1
disjoint-sym .c c HDConst = HDConst
disjoint-sym .c (e2 ·: x) HDConst = HDAsc (disjoint-sym _ _ HDConst)
disjoint-sym .c (X x) HDConst = HDVar
disjoint-sym .c (·λ x e2) HDConst = HDLam1 (disjoint-sym c e2 HDConst)
disjoint-sym .c (·λ x [ x₁ ] e2) HDConst = HDLam2 (disjoint-sym c e2 HDConst)
disjoint-sym .c ⦇⦈[ x ] HDConst = HDHole HNConst
disjoint-sym .c ⦇⌜ e2 ⌟⦈[ x ] HDConst = HDNEHole HNConst (disjoint-sym c e2 HDConst)
disjoint-sym .c (e2 ∘ e3) HDConst = HDAp (disjoint-sym c e2 HDConst) (disjoint-sym c e3 HDConst)
disjoint-sym .c ⟨ e2 , e3 ⟩ HDConst = HDPair (disjoint-sym c e2 HDConst) (disjoint-sym c e3 HDConst)
disjoint-sym .c (fst e2) HDConst = HDFst (disjoint-sym c e2 HDConst)
disjoint-sym .c (snd e2) HDConst = HDSnd (disjoint-sym c e2 HDConst)
disjoint-sym _ c (HDAsc hd) = HDConst
disjoint-sym _ (e2 ·: x) (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ·: x) (HDAsc hd) | HDAsc ih = HDAsc (ds-lem-asc ih)
disjoint-sym _ (X x) (HDAsc hd) = HDVar
disjoint-sym _ (·λ x e2) (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x e2) (HDAsc hd) | HDLam1 ih = HDLam1 (ds-lem-asc ih)
disjoint-sym _ (·λ x [ x₁ ] e2) (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x [ x₁ ] e2) (HDAsc hd) | HDLam2 ih = HDLam2 (ds-lem-asc ih)
disjoint-sym _ ⦇⦈[ x ] (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⦈[ x ] (HDAsc hd) | HDHole x₁ = HDHole (HNAsc x₁)
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDAsc hd) | HDNEHole x₁ ih = HDNEHole (HNAsc x₁) (ds-lem-asc ih)
disjoint-sym _ (e2 ∘ e3) (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ∘ e3) (HDAsc hd) | HDAp ih ih₁ = HDAp (ds-lem-asc ih) (ds-lem-asc ih₁)
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym .(_ ·: _) ⟨ e2 , e3 ⟩ (HDAsc hd) | HDPair ih ih₁ = HDPair (ds-lem-asc ih) (ds-lem-asc ih₁)
disjoint-sym _ (fst e2) (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym .(_ ·: _) (fst e2) (HDAsc hd) | HDFst ih = HDFst (ds-lem-asc ih)
disjoint-sym _ (snd e2) (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym .(_ ·: _) (snd e2) (HDAsc hd) | HDSnd ih = HDSnd (ds-lem-asc ih)
disjoint-sym _ c HDVar = HDConst
disjoint-sym _ (e2 ·: x₁) HDVar = HDAsc (disjoint-sym _ e2 HDVar)
disjoint-sym _ (X x₁) HDVar = HDVar
disjoint-sym _ (·λ x₁ e2) HDVar = HDLam1 (disjoint-sym _ e2 HDVar)
disjoint-sym _ (·λ x₁ [ x₂ ] e2) HDVar = HDLam2 (disjoint-sym _ e2 HDVar)
disjoint-sym _ ⦇⦈[ x₁ ] HDVar = HDHole HNVar
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x₁ ] HDVar = HDNEHole HNVar (disjoint-sym _ e2 HDVar)
disjoint-sym _ (e2 ∘ e3) HDVar = HDAp (disjoint-sym _ e2 HDVar) (disjoint-sym _ e3 HDVar)
disjoint-sym _ ⟨ e2 , e3 ⟩ HDVar = HDPair (disjoint-sym (X _) e2 HDVar)
(disjoint-sym (X _) e3 HDVar)
disjoint-sym _ (fst e2) HDVar = HDFst (disjoint-sym (X _) e2 HDVar)
disjoint-sym _ (snd e2) HDVar = HDSnd (disjoint-sym (X _) e2 HDVar)
disjoint-sym _ c (HDLam1 hd) = HDConst
disjoint-sym _ (e2 ·: x₁) (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ·: x₁) (HDLam1 hd) | HDAsc ih = HDAsc (ds-lem-lam1 ih)
disjoint-sym _ (X x₁) (HDLam1 hd) = HDVar
disjoint-sym _ (·λ x₁ e2) (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x₁ e2) (HDLam1 hd) | HDLam1 ih = HDLam1 (ds-lem-lam1 ih)
disjoint-sym _ (·λ x₁ [ x₂ ] e2) (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x₁ [ x₂ ] e2) (HDLam1 hd) | HDLam2 ih = HDLam2 (ds-lem-lam1 ih)
disjoint-sym _ ⦇⦈[ x₁ ] (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⦈[ x₁ ] (HDLam1 hd) | HDHole x = HDHole (HNLam1 x)
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x₁ ] (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x₁ ] (HDLam1 hd) | HDNEHole x ih = HDNEHole (HNLam1 x) (ds-lem-lam1 ih)
disjoint-sym _ (e2 ∘ e3) (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ∘ e3) (HDLam1 hd) | HDAp ih ih₁ = HDAp (ds-lem-lam1 ih) (ds-lem-lam1 ih₁)
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDLam1 hd) | HDPair ih ih₁ = HDPair (ds-lem-lam1 ih) (ds-lem-lam1 ih₁)
disjoint-sym _ (fst e2) (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ (fst e2) (HDLam1 hd) | HDFst ih = HDFst (ds-lem-lam1 ih)
disjoint-sym _ (snd e2) (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ (snd e2) (HDLam1 hd) | HDSnd ih = HDSnd (ds-lem-lam1 ih)
disjoint-sym _ c (HDLam2 hd) = HDConst
disjoint-sym _ (e2 ·: x₁) (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ·: x₁) (HDLam2 hd) | HDAsc ih = HDAsc (ds-lem-lam2 ih)
disjoint-sym _ (X x₁) (HDLam2 hd) = HDVar
disjoint-sym _ (·λ x₁ e2) (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x₁ e2) (HDLam2 hd) | HDLam1 ih = HDLam1 (ds-lem-lam2 ih)
disjoint-sym _ (·λ x₁ [ x₂ ] e2) (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x₁ [ x₂ ] e2) (HDLam2 hd) | HDLam2 ih = HDLam2 (ds-lem-lam2 ih)
disjoint-sym _ ⦇⦈[ x₁ ] (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⦈[ x₁ ] (HDLam2 hd) | HDHole x = HDHole (HNLam2 x)
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x₁ ] (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x₁ ] (HDLam2 hd) | HDNEHole x ih = HDNEHole (HNLam2 x) (ds-lem-lam2 ih)
disjoint-sym _ (e2 ∘ e3) (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ∘ e3) (HDLam2 hd) | HDAp ih ih₁ = HDAp (ds-lem-lam2 ih) (ds-lem-lam2 ih₁)
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDLam2 hd) | HDPair ih ih₁ = HDPair (ds-lem-lam2 ih) (ds-lem-lam2 ih₁)
disjoint-sym _ (fst e2) (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ (fst e2) (HDLam2 hd) | HDFst ih = HDFst (ds-lem-lam2 ih)
disjoint-sym _ (snd e2) (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ (snd e2) (HDLam2 hd) | HDSnd ih = HDSnd (ds-lem-lam2 ih)
disjoint-sym _ c (HDHole x) = HDConst
disjoint-sym _ (e2 ·: x) (HDHole (HNAsc x₁)) = HDAsc (disjoint-sym ⦇⦈[ _ ] e2 (HDHole x₁))
disjoint-sym _ (X x) (HDHole x₁) = HDVar
disjoint-sym _ (·λ x e2) (HDHole (HNLam1 x₁)) = HDLam1 (disjoint-sym ⦇⦈[ _ ] e2 (HDHole x₁))
disjoint-sym _ (·λ x [ x₁ ] e2) (HDHole (HNLam2 x₂)) = HDLam2 (disjoint-sym ⦇⦈[ _ ] e2 (HDHole x₂))
disjoint-sym _ ⦇⦈[ x ] (HDHole (HNHole x₁)) = HDHole (HNHole (flip x₁))
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ u' ] (HDHole (HNNEHole x x₁)) = HDNEHole (HNHole (flip x)) (disjoint-sym ⦇⦈[ _ ] e2 (HDHole x₁))
disjoint-sym _ (e2 ∘ e3) (HDHole (HNAp x x₁)) = HDAp (disjoint-sym ⦇⦈[ _ ] e2 (HDHole x))
(disjoint-sym ⦇⦈[ _ ] e3 (HDHole x₁))
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDHole (HNPair x1 x2)) = HDPair (disjoint-sym ⦇⦈[ _ ] e2 (HDHole x1)) (disjoint-sym ⦇⦈[ _ ] e3 (HDHole x2))
disjoint-sym _ (fst e2) (HDHole (HNFst x)) = HDFst (disjoint-sym ⦇⦈[ _ ] e2 (HDHole x))
disjoint-sym _ (snd e2) (HDHole (HNSnd x)) = HDSnd (disjoint-sym ⦇⦈[ _ ] e2 (HDHole x))
disjoint-sym _ c (HDNEHole x hd) = HDConst
disjoint-sym _ (e2 ·: x) (HDNEHole x₁ hd) with disjoint-sym _ _ hd
disjoint-sym _ (e ·: x) (HDNEHole (HNAsc x₁) hd) | HDAsc ih = HDAsc (ds-lem-nehole ih x₁)
disjoint-sym _ (X x) (HDNEHole x₁ hd) = HDVar
disjoint-sym _ (·λ x e2) (HDNEHole x₁ hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x e2) (HDNEHole (HNLam1 x₁) hd) | HDLam1 ih = HDLam1 (ds-lem-nehole ih x₁)
disjoint-sym _ (·λ x [ x₁ ] e2) (HDNEHole x₂ hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x [ x₁ ] e2) (HDNEHole (HNLam2 x₂) hd) | HDLam2 ih = HDLam2 (ds-lem-nehole ih x₂)
disjoint-sym _ ⦇⦈[ x ] (HDNEHole x₁ hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⦈[ x ] (HDNEHole (HNHole x₂) hd) | HDHole x₁ = HDHole (HNNEHole (flip x₂) x₁)
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDNEHole x₁ hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDNEHole (HNNEHole x₂ x₃) hd) | HDNEHole x₁ ih = HDNEHole (HNNEHole (flip x₂) x₁) (ds-lem-nehole ih x₃)
disjoint-sym _ (e2 ∘ e3) (HDNEHole x hd) with disjoint-sym _ _ hd
disjoint-sym _ (e1 ∘ e3) (HDNEHole (HNAp x x₁) hd) | HDAp ih ih₁ = HDAp (ds-lem-nehole ih x) (ds-lem-nehole ih₁ x₁)
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDNEHole x hd) with disjoint-sym _ _ hd
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDNEHole (HNPair x x₁) hd) | HDPair ih ih₁ = HDPair (ds-lem-nehole ih x) (ds-lem-nehole ih₁ x₁)
disjoint-sym _ (fst e2) (HDNEHole x hd) with disjoint-sym _ _ hd
disjoint-sym _ (fst e2) (HDNEHole (HNFst x1) hd) | HDFst ih = HDFst (ds-lem-nehole ih x1)
disjoint-sym _ (snd e2) (HDNEHole x hd) with disjoint-sym _ _ hd
disjoint-sym _ (snd e2) (HDNEHole (HNSnd x1) hd) | HDSnd ih = HDSnd (ds-lem-nehole ih x1)
disjoint-sym _ c (HDAp hd hd₁) = HDConst
disjoint-sym _ (e3 ·: x) (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (e3 ·: x) (HDAp hd hd₁) | HDAsc ih | HDAsc ih1 = HDAsc (ds-lem-ap ih ih1)
disjoint-sym _ (X x) (HDAp hd hd₁) = HDVar
disjoint-sym _ (·λ x e3) (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (·λ x e3) (HDAp hd hd₁) | HDLam1 ih | HDLam1 ih1 = HDLam1 (ds-lem-ap ih ih1)
disjoint-sym _ (·λ x [ x₁ ] e3) (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (·λ x [ x₁ ] e3) (HDAp hd hd₁) | HDLam2 ih | HDLam2 ih1 = HDLam2 (ds-lem-ap ih ih1)
disjoint-sym _ ⦇⦈[ x ] (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ ⦇⦈[ x ] (HDAp hd hd₁) | HDHole x₁ | HDHole x₂ = HDHole (HNAp x₁ x₂)
disjoint-sym _ ⦇⌜ e3 ⌟⦈[ x ] (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ ⦇⌜ e3 ⌟⦈[ x ] (HDAp hd hd₁) | HDNEHole x₁ ih | HDNEHole x₂ ih1 = HDNEHole (HNAp x₁ x₂) (ds-lem-ap ih ih1)
disjoint-sym _ (e3 ∘ e4) (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (e3 ∘ e4) (HDAp hd hd₁) | HDAp ih ih₁ | HDAp ih1 ih2 = HDAp (ds-lem-ap ih ih1) (ds-lem-ap ih₁ ih2)
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDAp hd hd₁) | HDPair ih ih₁ | HDPair ih1 ih2 = HDPair (ds-lem-ap ih ih1) (ds-lem-ap ih₁ ih2)
disjoint-sym _ (fst e2) (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (fst e2) (HDAp hd hd₁) | HDFst ih | HDFst ih1 = HDFst (ds-lem-ap ih ih1)
disjoint-sym _ (snd e2) (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (snd e2) (HDAp hd hd₁) | HDSnd ih | HDSnd ih1 = HDSnd (ds-lem-ap ih ih1)
disjoint-sym _ c (HDFst hd) = HDConst
disjoint-sym _ (e2 ·: x) (HDFst hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ·: x) (HDFst hd) | HDAsc ih = HDAsc (ds-lem-fst ih)
disjoint-sym _ (X x) (HDFst hd) = HDVar
disjoint-sym _ (·λ x e2) (HDFst hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x e2) (HDFst hd) | HDLam1 ih = HDLam1 (ds-lem-fst ih)
disjoint-sym _ (·λ x [ x₁ ] e2) (HDFst hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x [ x₁ ] e2) (HDFst hd) | HDLam2 ih = HDLam2 (ds-lem-fst ih)
disjoint-sym _ ⦇⦈[ x ] (HDFst hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⦈[ x ] (HDFst hd) | HDHole ih = HDHole (HNFst ih)
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDFst hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDFst hd) | HDNEHole x₁ ih = HDNEHole (HNFst x₁) (ds-lem-fst ih)
disjoint-sym _ (e2 ∘ e3) (HDFst hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ∘ e3) (HDFst hd) | HDAp ih ih₁ = HDAp (ds-lem-fst ih) (ds-lem-fst ih₁)
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDFst hd) with disjoint-sym _ _ hd
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDFst hd) | HDPair ih ih₁ = HDPair (ds-lem-fst ih) (ds-lem-fst ih₁)
disjoint-sym _ (fst e2) (HDFst hd) with disjoint-sym _ _ hd
disjoint-sym _ (fst e2) (HDFst hd) | HDFst ih = HDFst (ds-lem-fst ih)
disjoint-sym _ (snd e2) (HDFst hd) with disjoint-sym _ _ hd
disjoint-sym _ (snd e2) (HDFst hd) | HDSnd ih = HDSnd (ds-lem-fst ih)
disjoint-sym _ c (HDSnd hd) = HDConst
disjoint-sym _ (e2 ·: x) (HDSnd hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ·: x) (HDSnd hd) | HDAsc ih = HDAsc (ds-lem-snd ih)
disjoint-sym _ (X x) (HDSnd hd) = HDVar
disjoint-sym _ (·λ x e2) (HDSnd hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x e2) (HDSnd hd) | HDLam1 ih = HDLam1 (ds-lem-snd ih)
disjoint-sym _ (·λ x [ x₁ ] e2) (HDSnd hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x [ x₁ ] e2) (HDSnd hd) | HDLam2 ih = HDLam2 (ds-lem-snd ih)
disjoint-sym _ ⦇⦈[ x ] (HDSnd hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⦈[ x ] (HDSnd hd) | HDHole ih = HDHole (HNSnd ih)
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDSnd hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDSnd hd) | HDNEHole x₁ ih = HDNEHole (HNSnd x₁) (ds-lem-snd ih)
disjoint-sym _ (e2 ∘ e3) (HDSnd hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ∘ e3) (HDSnd hd) | HDAp ih ih₁ = HDAp (ds-lem-snd ih) (ds-lem-snd ih₁)
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDSnd hd) with disjoint-sym _ _ hd
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDSnd hd) | HDPair ih ih₁ = HDPair (ds-lem-snd ih) (ds-lem-snd ih₁)
disjoint-sym _ (fst e2) (HDSnd hd) with disjoint-sym _ _ hd
disjoint-sym _ (fst e2) (HDSnd hd) | HDFst ih = HDFst (ds-lem-snd ih)
disjoint-sym _ (snd e2) (HDSnd hd) with disjoint-sym _ _ hd
disjoint-sym _ (snd e2) (HDSnd hd) | HDSnd ih = HDSnd (ds-lem-snd ih)
disjoint-sym _ c (HDPair hd hd₁) = HDConst
disjoint-sym _ (e3 ·: x) (HDPair hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (e3 ·: x) (HDPair hd hd₁) | HDAsc ih | HDAsc ih1 = HDAsc (ds-lem-pair ih ih1)
disjoint-sym _ (X x) (HDPair hd hd₁) = HDVar
disjoint-sym _ (·λ x e3) (HDPair hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (·λ x e3) (HDPair hd hd₁) | HDLam1 ih | HDLam1 ih1 = HDLam1 (ds-lem-pair ih ih1)
disjoint-sym _ (·λ x [ x₁ ] e3) (HDPair hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (·λ x [ x₁ ] e3) (HDPair hd hd₁) | HDLam2 ih | HDLam2 ih1 = HDLam2 (ds-lem-pair ih ih1)
disjoint-sym _ ⦇⦈[ x ] (HDPair hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ ⦇⦈[ x ] (HDPair hd hd₁) | HDHole x₁ | HDHole x₂ = HDHole (HNPair x₁ x₂)
disjoint-sym _ ⦇⌜ e3 ⌟⦈[ x ] (HDPair hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ ⦇⌜ e3 ⌟⦈[ x ] (HDPair hd hd₁) | HDNEHole x₁ ih | HDNEHole x₂ ih1 = HDNEHole (HNPair x₁ x₂) (ds-lem-pair ih ih1)
disjoint-sym _ (e3 ∘ e4) (HDPair hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (e3 ∘ e4) (HDPair hd hd₁) | HDAp ih ih₁ | HDAp ih1 ih2 = HDAp (ds-lem-pair ih ih1) (ds-lem-pair ih₁ ih2)
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDPair hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ ⟨ e2 , e3 ⟩ (HDPair hd hd₁) | HDPair ih ih₁ | HDPair ih1 ih2 = HDPair (ds-lem-pair ih ih1) (ds-lem-pair ih₁ ih2)
disjoint-sym _ (fst e2) (HDPair hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (fst e2) (HDPair hd hd₁) | HDFst ih | HDFst ih1 = HDFst (ds-lem-pair ih ih1)
disjoint-sym _ (snd e2) (HDPair hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (snd e2) (HDPair hd hd₁) | HDSnd ih | HDSnd ih1 = HDSnd (ds-lem-pair ih ih1)
-- note that this is false, so holes-disjoint isn't transitive
-- disjoint-new : ∀{e1 e2 u} → holes-disjoint e1 e2 → hole-name-new e1 u → hole-name-new e2 u
-- it's also not reflexive, because ⦇⦈[ u ] isn't hole-disjoint with
-- itself since refl : u == u; it's also not anti-reflexive, because the
-- expression c *is* hole-disjoint with itself (albeit vacuously)
| {
"alphanum_fraction": 0.6472537449,
"avg_line_length": 65.3709198813,
"ext": "agda",
"hexsha": "e9453934af922fdd6f54af6ad23e49496b1c7ac4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-livelits-agda",
"max_forks_repo_path": "holes-disjoint-checks.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_issues_repo_issues_event_max_datetime": "2020-10-20T20:44:13.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-30T20:27:56.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazel-palette-agda",
"max_issues_repo_path": "holes-disjoint-checks.agda",
"max_line_length": 137,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazel-palette-agda",
"max_stars_repo_path": "holes-disjoint-checks.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T15:38:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-04T06:45:06.000Z",
"num_tokens": 10126,
"size": 22030
} |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Agda.ISetoids.Cocomplete.Helpers where
open import Level
open import Relation.Binary using (Setoid; module Setoid; Preorder; module Preorder; Rel; _=[_]⇒_)
open import Data.Product using (Σ; _,_; Σ-syntax)
-- import Relation.Binary.EqReasoning as EqReasoning
open import Categories.Support.Equivalence using (module I→R-Wrapper; setoid-i→r; squash) renaming (Setoid to ISetoid; module Setoid to ISetoid)
open import Categories.Support.SetoidFunctions using (module _⟶_)
open import Categories.Support.PropositionalEquality
import Categories.Support.ZigZag as ZigZag
open import Categories.Category
open import Categories.Functor
open import Categories.Agda
open import Categories.Colimit
open import Categories.Object.Initial
open import Categories.Cocones
open import Categories.Cocone
open I→R-Wrapper
ding : Level → Level
ding ℓ = ℓ
module ColimitCocone {o ℓ e c ℓ′} {J : Category o ℓ e} (F : Functor J (ISetoids (c ⊔ ding (o ⊔ ℓ ⊔ e)) (c ⊔ ℓ′ ⊔ ding (o ⊔ ℓ ⊔ e)))) where
c′ = c ⊔ ding (o ⊔ ℓ ⊔ e)
ℓ″ = c ⊔ ℓ′ ⊔ ding (o ⊔ ℓ ⊔ e)
C = ISetoids c′ ℓ″
D = Cocones F
module J = Category J
open Functor F
open ISetoid
open _⟶_
vertex-carrier = Σ[ x ∈ J.Obj ] Carrier (F₀ x)
-- this lets us build a preorder out of an irrelevant setoid, since there
-- are no irrelevant preorders
dot-setoid : (j : J.Obj) → Setoid c′ ℓ″
dot-setoid j = setoid-i→r (F₀ j)
module DotSetoid (j : J.Obj) = Setoid (dot-setoid j)
open DotSetoid using () renaming (_≈_ to _[_≈_])
-- _↝_ means that an arrow in the diagram directly constrains the two
-- objects of vertex-carrier to be equal. completing this to an
-- equivalence relation gives us the setoid we need
_↝_ : (x y : vertex-carrier) → Set ℓ″
(X , x) ↝ (Y , y) = Σ[ f ∈ J [ X , Y ] ] (Y [ (F₁ f ⟨$⟩ x) ≈ y ])
↝-preorder : Preorder c′ c′ ℓ″
↝-preorder = record
{ Carrier = vertex-carrier
; _≈_ = _≣_
; _∼_ = _↝_
; isPreorder = record
{ isEquivalence = ≣-isEquivalence
; reflexive = ↝-reflexive
; trans = ↝-trans
}
}
where
↝-refl : ∀ {i} → (i ↝ i)
↝-refl {X , x} = J.id , squash (identity (refl (F₀ X)))
↝-reflexive : ∀ {i j} → (i ≣ j) → (i ↝ j)
↝-reflexive ≣-refl = ↝-refl
-- the nice proof. pretty proof!
{-
↝-trans : ∀ {i j k} → (i ↝ j) → (j ↝ k) → (i ↝ k)
↝-trans {_ , i} {_ , j} {k₁ , k} (f , squash fi≈j) (g , gj≈k) =
J [ g ∘ f ] , (
begin
F₁ (J [ g ∘ f ]) ⟨$⟩ i
≈⟨ squash homomorphism ⟩
F₁ g ⟨$⟩ (F₁ f ⟨$⟩ i)
≈⟨ squash (cong (F₁ g) fi≈j) ⟩
F₁ g ⟨$⟩ j
≈⟨ gj≈k ⟩
k
∎ )
where
open EqReasoning (dot-setoid k₁)
-}
-- the ugly proof that loads before the sun burns out.
↝-trans : ∀ {i j k} → (i ↝ j) → (j ↝ k) → (i ↝ k)
↝-trans {X , _} {k = Z , _} (f , squash fx≈y) (g , gy≈z) =
J [ g ∘ f ] , DotSetoid.trans Z (squash (trans (F₀ Z) (homomorphism (refl (F₀ X))) (cong (F₁ g) fx≈y))) gy≈z
vertex = ZigZag.isetoid ↝-preorder
⊥ : Cocone F
⊥ = record
{ N = vertex
; ψ = λ X → record
{ _⟨$⟩_ = _,_ X
; cong = λ pf → ZigZag.disorient (ZigZag.slish (J.id , squash (identity pf)))
-- cong would be easier if i'd used the proper dotwise equality for
-- ↝-preorder above ... since this is basically the proof ↝ respects it
}
; commute = λ {X Y} f {x : _} {y : _} (x≈y : _) → ZigZag.disorient (ZigZag.slish (f , (squash (cong (F₁ f) x≈y))))
}
! : {A : Cocone F} → CoconeMorphism {F = F} ⊥ A
! {A} = record
{ f = record
{ _⟨$⟩_ = my-f
; cong = ZigZag.iminimal ↝-preorder A.N my-f my-precong
}
; commute = λ {X x y} x≈y → cong (A.ψ X) x≈y
}
where
module A = Cocone A
my-f : vertex-carrier → Carrier A.N
my-f (X , x) = A.ψ X ⟨$⟩ x
.my-precong : _↝_ =[ my-f ]⇒ (_≈_ A.N)
my-precong {X , x} {Y , y} (f , squash fx≈y) = trans A.N (A.commute f (refl (F₀ X))) (cong (A.ψ Y) (irr fx≈y))
| {
"alphanum_fraction": 0.5730616302,
"avg_line_length": 32.9836065574,
"ext": "agda",
"hexsha": "2ca32b5c7cadb09db79b3ee8f4135fc94b1d9053",
"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/Agda/ISetoids/Cocomplete/Helpers.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/Agda/ISetoids/Cocomplete/Helpers.agda",
"max_line_length": 144,
"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/Agda/ISetoids/Cocomplete/Helpers.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": 1563,
"size": 4024
} |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.JoinComm
open import homotopy.JoinAssocCubical
module homotopy.JoinSusp where
module _ {i} {A : Type i} where
private
module Into = JoinRec {A = Bool} {B = A}
{D = Suspension A}
(if_then north else south)
(λ _ → south)
(λ {(true , a) → merid a;
(false , a) → idp})
into = Into.f
module Out = SuspensionRec {C = Bool * A}
(left true)
(left false)
(λ a → glue (true , a) ∙ ! (glue (false , a)))
out = Out.f
into-out : ∀ σ → into (out σ) == σ
into-out = Suspension-elim
idp
idp
(↓-∘=idf-from-square into out ∘ λ a → vert-degen-square $
ap (ap into) (Out.merid-β a)
∙ ap-∙ into (glue (true , a)) (! (glue (false , a)))
∙ (Into.glue-β (true , a)
∙2 (ap-! into (glue (false , a))
∙ ap ! (Into.glue-β (false , a))))
∙ ∙-unit-r _)
out-into : ∀ j → out (into j) == j
out-into = Join-elim
(λ{true → idp ; false → idp})
(λ a → glue (false , a))
(↓-∘=idf-from-square out into ∘
λ {(true , a) →
(ap (ap out) (Into.glue-β (true , a)) ∙ Out.merid-β a)
∙v⊡ (vid-square {p = glue (true , a)}
⊡h rt-square (glue (false , a)))
⊡v∙ ∙-unit-r _;
(false , a) →
ap (ap out) (Into.glue-β (false , a)) ∙v⊡ connection})
*-Bool-equiv-Suspension : Bool * A ≃ Suspension A
*-Bool-equiv-Suspension = equiv into out into-out out-into
*-Lift-Bool-equiv-Suspension : Lift {j = i} Bool * A ≃ Suspension A
*-Lift-Bool-equiv-Suspension = *-Bool-equiv-Suspension ∘e equiv-* lower-equiv (ide A)
*-Bool = ua *-Bool-equiv-Suspension
module _ {i} (X : Ptd i) where
⊙*-⊙Bool : ⊙Bool ⊙* X == ⊙Susp X
⊙*-⊙Bool = ⊙ua (⊙≃-in *-Bool-equiv-Suspension idp)
⊙*-⊙Lift-⊙Bool : ⊙Lift {j = i} ⊙Bool ⊙* X == ⊙Susp X
⊙*-⊙Lift-⊙Bool = ⊙ua (⊙≃-in *-Lift-Bool-equiv-Suspension idp)
module _ {i j} {A : Type i} {B : Type j} where
*-Suspension : Suspension A * B == Suspension (A * B)
*-Suspension =
ap (_* B) (! *-Bool)
∙ join-rearrange-path
∙ ua swap-equiv
∙ *-Bool
∙ ap Suspension (ua swap-equiv)
module _ {i j} (X : Ptd i) (Y : Ptd j) where
⊙*-⊙Susp : ⊙Susp X ⊙* Y == ⊙Susp (X ⊙* Y)
⊙*-⊙Susp =
ap (_⊙* Y) (! (⊙*-⊙Bool X))
∙ join-rearrange-⊙path (⊙Sphere 0) X Y
∙ ⊙ua (⊙≃-in swap-equiv (! (glue _)))
∙ ⊙*-⊙Bool (Y ⊙* X)
∙ ap (λ A → (Suspension A , north)) (ua swap-equiv)
module _ {i} where
⊙*-⊙Sphere : (m : ℕ) (X : Ptd i) → ⊙Sphere m ⊙* X == ⊙Susp^ (S m) X
⊙*-⊙Sphere O X = ⊙*-⊙Bool X
⊙*-⊙Sphere (S m) X = ⊙*-⊙Susp (⊙Sphere m) X
∙ ap ⊙Susp (⊙*-⊙Sphere m X)
⊙*-⊙Lift-⊙Sphere : (m : ℕ) (X : Ptd i) → ⊙Lift {j = i} (⊙Sphere m) ⊙* X == ⊙Susp^ (S m) X
⊙*-⊙Lift-⊙Sphere O X = ⊙*-⊙Lift-⊙Bool X
⊙*-⊙Lift-⊙Sphere (S m) X = ap (_⊙* X) (! $ ⊙Susp-⊙Lift (⊙Sphere m))
∙ ⊙*-⊙Susp (⊙Lift (⊙Sphere m)) X
∙ ap ⊙Susp (⊙*-⊙Lift-⊙Sphere m X)
| {
"alphanum_fraction": 0.47703516,
"avg_line_length": 30.9509803922,
"ext": "agda",
"hexsha": "8e3bfb0f7e3aeb2f64445ff8b15663532df04c4a",
"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/JoinSusp.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/JoinSusp.agda",
"max_line_length": 91,
"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/JoinSusp.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1303,
"size": 3157
} |
{-# OPTIONS --safe --warning=error --without-K --guardedness #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Setoids.Setoids
open import Rings.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Orders.Total.Definition
open import Groups.Definition
open import Groups.Lemmas
open import Fields.Fields
open import Sets.EquivalenceRelations
open import Sequences
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Functions.Definition
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Naturals.Order.Lemmas
open import Semirings.Definition
module Fields.CauchyCompletion.Comparison {m n o : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {_<_ : Rel {m} {o} A} {pOrder : SetoidPartialOrder S _<_} {R : Ring S _+_ _*_} {pRing : PartiallyOrderedRing R pOrder} (order : TotallyOrderedRing pRing) (F : Field R) where
open Setoid S
open SetoidTotalOrder (TotallyOrderedRing.total order)
open SetoidPartialOrder pOrder
open Equivalence eq
open PartiallyOrderedRing pRing
open Ring R
open Group additiveGroup
open Field F
open import Fields.Orders.Lemmas {F = F} {pRing} (record { oRing = order })
open import Rings.Orders.Partial.Lemmas pRing
open import Rings.Orders.Total.Lemmas order
open import Rings.Orders.Total.AbsoluteValue order
open import Fields.Lemmas F
open import Fields.CauchyCompletion.Definition order F
open import Fields.CauchyCompletion.Setoid order F
open import Fields.CauchyCompletion.Group order F
open import Fields.Orders.Total.Lemmas {F = F} (record { oRing = order })
-- "<C rational", where the r indicates where the rational number goes
record _<Cr_ (a : CauchyCompletion) (b : A) : Set (m ⊔ o) where
field
e : A
0<e : 0G < e
N : ℕ
property : ((m : ℕ) → (N<m : N <N m) → (e + index (CauchyCompletion.elts a) m) < b)
<CrWellDefinedRight : (a : CauchyCompletion) (b c : A) → b ∼ c → a <Cr b → a <Cr c
<CrWellDefinedRight a b c b=c record { e = ε ; 0<e = 0<e ; N = N ; property = pr } = record { e = ε ; 0<e = 0<e ; N = N ; property = λ m N<m → <WellDefined (Equivalence.reflexive eq) b=c (pr m N<m) }
private
<CrWellDefinedLemma : (a b e/2 e : A) (0<e : 0G < e) (pr : e/2 + e/2 ∼ e) → abs (a + inverse b) < e/2 → (e/2 + b) < (e + a)
<CrWellDefinedLemma a b e/2 e 0<e pr a-b<e with totality 0G (a + inverse b)
<CrWellDefinedLemma a b e/2 e 0<e pr a-b<e | inl (inl 0<a-b) = ringAddInequalities (halfLess e/2 e 0<e pr) (<WellDefined identLeft (Equivalence.transitive eq (Equivalence.symmetric eq +Associative) (Equivalence.transitive eq (+WellDefined (Equivalence.reflexive eq) invLeft) identRight)) (orderRespectsAddition 0<a-b b))
<CrWellDefinedLemma a b e/2 e 0<e pr a-b<e | inl (inr a-b<0) = <WellDefined (Equivalence.transitive eq (+WellDefined (invContravariant (Ring.additiveGroup R)) groupIsAbelian) (Equivalence.transitive eq (Equivalence.transitive eq +Associative (+WellDefined (Equivalence.transitive eq (Equivalence.symmetric eq +Associative) (Equivalence.transitive eq (+WellDefined (invTwice additiveGroup b) invLeft) identRight)) (Equivalence.reflexive eq))) groupIsAbelian)) (Equivalence.transitive eq +Associative (+WellDefined pr (Equivalence.reflexive eq))) (orderRespectsAddition a-b<e (e/2 + a))
<CrWellDefinedLemma a b e/2 e 0<e pr a-b<e | inr 0=a-b = <WellDefined (Equivalence.reflexive eq) (+WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq (transferToRight (Ring.additiveGroup R) (Equivalence.symmetric eq 0=a-b)))) (orderRespectsAddition (halfLess e/2 e 0<e pr) b)
<CrWellDefinedLeft : (a b : CauchyCompletion) (c : A) → Setoid._∼_ cauchyCompletionSetoid a b → a <Cr c → b <Cr c
<CrWellDefinedLeft a b c a=b record { e = ε ; 0<e = 0<e ; N = N ; property = pr } with halve charNot2 ε
... | e/2 , prE/2 with halvePositive e/2 (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq prE/2) 0<e)
... | 0<e/2 with a=b e/2 0<e/2
... | N2 , prN2 = record { e = e/2 ; 0<e = 0<e/2 ; N = N +N N2 ; property = ans }
where
ans : (m : ℕ) → (N<m : (N +N N2) <N m) → (e/2 + index (CauchyCompletion.elts b) m) < c
ans m N<m with prN2 {m} (inequalityShrinkRight N<m)
... | bl rewrite indexAndApply (CauchyCompletion.elts a) (map inverse (CauchyCompletion.elts b)) _+_ {m} | equalityCommutative (mapAndIndex (CauchyCompletion.elts b) inverse m) = SetoidPartialOrder.<Transitive pOrder (<CrWellDefinedLemma (index (CauchyCompletion.elts a) m) (index (CauchyCompletion.elts b) m) e/2 ε 0<e prE/2 bl) (pr m (inequalityShrinkLeft N<m))
<CrWellDefined : (a b : CauchyCompletion) (c d : A) → Setoid._∼_ cauchyCompletionSetoid a b → c ∼ d → a <Cr c → b <Cr d
<CrWellDefined a b c d a=b c=d a<c = <CrWellDefinedLeft a b d a=b (<CrWellDefinedRight a c d c=d a<c)
record _r<C_ (a : A) (b : CauchyCompletion) : Set (m ⊔ o) where
field
e : A
0<e : 0G < e
N : ℕ
pr : (m : ℕ) → (N<m : N <N m) → (a + e) < index (CauchyCompletion.elts b) m
r<CWellDefinedLeft : (a b : A) (c : CauchyCompletion) → (a ∼ b) → (a r<C c) → b r<C c
r<CWellDefinedLeft a b c a=b record { e = e ; 0<e = 0<e ; N = N ; pr = pr } = record { e = e ; 0<e = 0<e ; N = N ; pr = λ m N<m → <WellDefined (+WellDefined a=b (Equivalence.reflexive eq)) (Equivalence.reflexive eq) (pr m N<m) }
private
r<CWellDefinedLemma : (a b c e e/2 : A) (_ : e/2 + e/2 ∼ e) (0<e : 0G < e) (_ : abs (a + inverse b) < e/2) (_ : (c + e) < a) → (c + e/2) < b
r<CWellDefinedLemma a b c e e/2 prE/2 0<e pr c+e<a with totality 0G (a + inverse b)
r<CWellDefinedLemma a b c e e/2 prE/2 0<e pr c+e<a | inl (inl 0<a-b) = SetoidPartialOrder.<Transitive pOrder (<WellDefined (Equivalence.transitive eq (Equivalence.symmetric eq +Associative) (+WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (+WellDefined (Equivalence.symmetric eq prE/2) (Equivalence.reflexive eq)) (Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.symmetric eq +Associative) (+WellDefined (Equivalence.reflexive eq) invRight)) identRight)))) (Equivalence.reflexive eq) (orderRespectsAddition c+e<a (inverse e/2))) (<WellDefined (Equivalence.transitive eq +Associative (+WellDefined (Equivalence.transitive eq (Equivalence.symmetric eq +Associative) (Equivalence.transitive eq (+WellDefined (Equivalence.reflexive eq) invLeft) identRight)) (Equivalence.reflexive eq))) (Equivalence.transitive eq groupIsAbelian (Equivalence.transitive eq (Equivalence.symmetric eq +Associative) (Equivalence.transitive eq (+WellDefined (Equivalence.reflexive eq) (invLeft)) identRight))) (orderRespectsAddition pr (b + inverse e/2)))
r<CWellDefinedLemma a b c e e/2 prE/2 0<e pr c+e<a | inl (inr a-b<0) = SetoidPartialOrder.<Transitive pOrder (SetoidPartialOrder.<Transitive pOrder (<WellDefined groupIsAbelian groupIsAbelian (orderRespectsAddition (halfLess e/2 e 0<e prE/2) c)) c+e<a) (<WellDefined (Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.symmetric eq +Associative) (+WellDefined (Equivalence.reflexive eq) invLeft)) identRight) identLeft (orderRespectsAddition a-b<0 b))
r<CWellDefinedLemma a b c e e/2 prE/2 0<e pr c+e<a | inr 0=a-b = SetoidPartialOrder.<Transitive pOrder (<WellDefined groupIsAbelian (Equivalence.reflexive eq) (orderRespectsAddition (halfLess e/2 e 0<e prE/2) c)) (<WellDefined (groupIsAbelian {c} {e}) (transferToRight additiveGroup (Equivalence.symmetric eq 0=a-b)) c+e<a)
r<CWellDefinedRight : (a b : CauchyCompletion) (c : A) → Setoid._∼_ cauchyCompletionSetoid a b → c r<C a → c r<C b
r<CWellDefinedRight a b c a=b record { e = e ; 0<e = 0<e ; N = N ; pr = pr } with halve charNot2 e
... | e/2 , prE/2 with halvePositive e/2 (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq prE/2) 0<e)
... | 0<e/2 with a=b e/2 0<e/2
... | N2 , prN2 = record { e = e/2 ; 0<e = 0<e/2 ; N = N +N N2 ; pr = ans }
where
ans : (m : ℕ) → (N<m : (N +N N2) <N m) → (c + e/2) < index (CauchyCompletion.elts b) m
ans m N<m with prN2 {m} (inequalityShrinkRight N<m)
... | bl rewrite indexAndApply (CauchyCompletion.elts a) (map inverse (CauchyCompletion.elts b)) _+_ {m} | equalityCommutative (mapAndIndex (CauchyCompletion.elts b) inverse m) = r<CWellDefinedLemma (index (CauchyCompletion.elts a) m) (index (CauchyCompletion.elts b) m) c e e/2 prE/2 0<e bl (pr m (inequalityShrinkLeft N<m))
record _<C_ (a : CauchyCompletion) (b : CauchyCompletion) : Set (m ⊔ o) where
field
i : A
a<i : a <Cr i
i<b : i r<C b
<CWellDefined : {a b c d : CauchyCompletion} → Setoid._∼_ cauchyCompletionSetoid a b → Setoid._∼_ cauchyCompletionSetoid c d → a <C c → b <C d
<CWellDefined {a} {b} {c} {d} a=b c=d record { i = bound ; a<i = a<bound ; i<b = bound<b } = record { i = bound ; a<i = <CrWellDefinedLeft a b bound a=b a<bound ; i<b = r<CWellDefinedRight c d bound c=d bound<b }
<CInheritedL : {a b : A} → a < b → injection a <Cr b
<CInheritedL {a} {b} a<b with dense charNot2 a<b
... | between , (a<between ,, between<b) = record { e = between + inverse a ; 0<e = <WellDefined invRight (Equivalence.reflexive eq) (orderRespectsAddition a<between (inverse a)) ; N = 0 ; property = λ m _ → <WellDefined (Equivalence.transitive eq (Equivalence.symmetric eq identRight) (Equivalence.transitive eq (+WellDefined (Equivalence.reflexive eq) (ans a m)) +Associative)) (Equivalence.reflexive eq) between<b }
where
ans : (x : A) (m : ℕ) → 0G ∼ inverse x + index (constSequence x) m
ans x m rewrite indexAndConst x m = Equivalence.symmetric eq invLeft
<CInheritedR : {a b : A} → a < b → a r<C injection b
<CInheritedR {a} {b} a<b with dense charNot2 a<b
... | between , (a<between ,, between<b) = record { e = between + inverse a ; 0<e = <WellDefined invRight (Equivalence.reflexive eq) (orderRespectsAddition a<between (inverse a)) ; N = 0 ; pr = λ m _ → <WellDefined (Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.symmetric eq identRight) (+WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq invLeft))) +Associative) groupIsAbelian) (identityOfIndiscernablesLeft _∼_ (Equivalence.reflexive eq) (indexAndConst b m)) between<b }
<CInherited : {a b : A} → a < b → (injection a) <C (injection b)
<CInherited {a} {b} a<b with dense charNot2 a<b
... | between , (a<between ,, between<b) = record { i = between ; a<i = <CInheritedL a<between ; i<b = <CInheritedR between<b }
<CCollapsesL : (a b : A) → (injection a) <Cr b → a < b
<CCollapsesL a b record { e = e ; 0<e = 0<i ; N = N ; property = pr } with pr (succ N) (le 0 refl)
... | bl rewrite indexAndConst a N = <Transitive (<WellDefined identLeft reflexive (orderRespectsAddition 0<i a)) bl
<CCollapsesR : (a b : A) → a r<C injection b → a < b
<CCollapsesR a b record { e = e ; 0<e = 0<e ; N = N ; pr = pr } with pr (succ N) (le 0 refl)
... | bl rewrite indexAndConst b N = <Transitive (<WellDefined identLeft groupIsAbelian (orderRespectsAddition 0<e a)) bl
<CCollapses : {a b : A} → (injection a) <C (injection b) → a < b
<CCollapses {a} {b} record { i = inter ; a<i = pr1 ; i<b = pr2 } = <Transitive (<CCollapsesL a inter pr1) (<CCollapsesR inter b pr2)
<CRelaxL : {a : A} {b : CauchyCompletion} → a r<C b → injection a <C b
<CRelaxL {a} {b} record { e = e ; 0<e = 0<e ; N = N ; pr = pr } with halve charNot2 e
... | e/2 , e/2pr = record { i = a + e/2 ; a<i = <CInheritedL (<WellDefined identLeft groupIsAbelian (orderRespectsAddition (halvePositive' e/2pr 0<e) a)) ; i<b = record { e = e/2 ; 0<e = halvePositive' e/2pr 0<e ; N = N ; pr = λ m N<m → <WellDefined (transitive (+WellDefined reflexive (symmetric e/2pr)) +Associative) reflexive (pr m N<m) } }
<CRelaxL' : {a : A} {b : CauchyCompletion} → injection a <C b → a r<C b
<CRelaxL' {a} {b} record { i = i ; a<i = a<i ; i<b = record { e = e ; 0<e = 0<e ; N = N ; pr = pr } } = record { e = e ; 0<e = 0<e ; N = N ; pr = λ m N<m → <Transitive (orderRespectsAddition (<CCollapsesL _ _ a<i) e) (pr m N<m) }
<CRelaxR : {a : CauchyCompletion} {b : A} → a <Cr b → a <C injection b
<CRelaxR {a} {b} record { e = ε ; 0<e = 0<ε ; N = N ; property = property } with halve charNot2 ε
... | e/2 , e/2+e/2=e = record { i = b + inverse e/2 ; a<i = record { e = e/2 ; 0<e = halvePositive' e/2+e/2=e 0<ε ; N = N ; property = λ m N<m → <WellDefined (transitive groupIsAbelian (transitive +Associative (+WellDefined (transitive (+WellDefined reflexive (symmetric e/2+e/2=e)) (transitive +Associative (transitive (+WellDefined invLeft reflexive) identLeft))) reflexive))) reflexive (orderRespectsAddition (property m N<m) (inverse e/2)) } ; i<b = <CInheritedR (<WellDefined groupIsAbelian identLeft (orderRespectsAddition (<WellDefined reflexive (invIdent additiveGroup) (ringSwapNegatives (<WellDefined (symmetric (invTwice additiveGroup 0R)) (symmetric (invTwice additiveGroup e/2)) (halvePositive' e/2+e/2=e 0<ε)))) b)) }
<CRelaxR' : {a : CauchyCompletion} {b : A} → a <C injection b → a <Cr b
<CRelaxR' {a} {b} record { i = i ; a<i = record { e = ε ; 0<e = 0<ε ; N = N ; property = property } ; i<b = i<b } = record { e = ε ; 0<e = 0<ε ; N = N ; property = λ m N<m → <Transitive (property m N<m) (<CCollapsesR _ _ i<b) }
flip<CR : {a : CauchyCompletion} {b : A} → a <Cr b → inverse b r<C Group.inverse CGroup a
_r<C_.e (flip<CR {a} {b} record { e = e ; 0<e = 0<e ; N = N ; property = property }) = e
_r<C_.0<e (flip<CR {a} {b} record { e = e ; 0<e = 0<e ; N = N ; property = property }) = 0<e
_r<C_.N (flip<CR {a} {b} record { e = e ; 0<e = 0<e ; N = N ; property = property }) = N
_r<C_.pr (flip<CR {a} {b} record { e = e ; 0<e = 0<e ; N = N ; property = property }) m N<m with property m N<m
... | bl = <WellDefined (transitive (transitive (symmetric +Associative) (+WellDefined reflexive (transitive groupIsAbelian (transitive (symmetric +Associative) (transitive (+WellDefined reflexive invLeft) identRight))))) groupIsAbelian) (transitive +Associative (transitive (+WellDefined invRight reflexive) (transitive identLeft (identityOfIndiscernablesRight _∼_ reflexive (mapAndIndex (CauchyCompletion.elts a) inverse m))))) (orderRespectsAddition bl (inverse b + inverse (index (CauchyCompletion.elts a) m)))
flipR<C : {a : A} {b : CauchyCompletion} → a r<C b → Group.inverse CGroup b <Cr inverse a
_<Cr_.e (flipR<C record { e = e ; 0<e = 0<e ; N = N ; pr = pr }) = e
_<Cr_.0<e (flipR<C record { e = e ; 0<e = 0<e ; N = N ; pr = pr }) = 0<e
_<Cr_.N (flipR<C record { e = e ; 0<e = 0<e ; N = N ; pr = pr }) = N
_<Cr_.property (flipR<C {a} {b} record { e = e ; 0<e = 0<e ; N = N ; pr = pr }) m N<m with pr m N<m
... | t = <WellDefined (transitive (+WellDefined groupIsAbelian (+WellDefined reflexive (identityOfIndiscernablesRight _∼_ reflexive (mapAndIndex (CauchyCompletion.elts b) inverse m)))) (transitive (symmetric +Associative) (+WellDefined reflexive (transitive +Associative (transitive (+WellDefined invRight reflexive) identLeft))))) (transitive groupIsAbelian (transitive (symmetric +Associative) (transitive (+WellDefined reflexive invLeft) identRight))) (orderRespectsAddition t (inverse a + inverse (index (CauchyCompletion.elts b) m)))
flip<C : {a b : CauchyCompletion} → a <C b → Group.inverse CGroup b <C Group.inverse CGroup a
flip<C {a} {b} record { i = i ; a<i = a<i ; i<b = i<b } = record { i = inverse i ; a<i = flipR<C i<b ; i<b = flip<CR a<i }
flip<C' : {a b : CauchyCompletion} → Group.inverse CGroup b <C Group.inverse CGroup a → a <C b
flip<C' {a} {b} a<b = <CWellDefined (invTwice CGroup a) (invTwice CGroup b) (flip<C a<b)
<CIrreflexive : {a : CauchyCompletion} → a <C a → False
<CIrreflexive {a} record { i = bound ; a<i = record { e = bA ; 0<e = 0<bA ; N = Na ; property = prA } ; i<b = record { e = bB ; 0<e = 0<bB ; N = Nb ; pr = prB } } with prA (succ Na +N Nb) (le Nb (applyEquality succ (Semiring.commutative ℕSemiring Nb Na)))
... | bl with prB (succ Na +N Nb) (le Na refl)
... | bl2 with <WellDefined (Equivalence.transitive eq +Associative (+WellDefined (Equivalence.transitive eq (Equivalence.symmetric eq +Associative) groupIsAbelian) (Equivalence.reflexive eq))) groupIsAbelian (ringAddInequalities bl bl2)
... | bad = irreflexive (SetoidPartialOrder.<Transitive pOrder (<WellDefined identLeft +Associative (<WellDefined (Equivalence.reflexive eq) groupIsAbelian (orderRespectsAddition (<WellDefined identLeft (Equivalence.reflexive eq) (ringAddInequalities 0<bA 0<bB)) (index (CauchyCompletion.elts a) (succ Na +N Nb) + bound)))) bad)
<CTransitive : {a b c : CauchyCompletion} → a <C b → b <C c → a <C c
<CTransitive {a} {b} {c} record { i = boundA ; a<i = record { e = eL ; 0<e = 0<eL ; N = NL ; property = prL } ; i<b = record { e = eR ; 0<e = 0<eR ; N = Nr ; pr = prR } } record { i = boundB ; a<i = record { e = fL ; 0<e = 0<fL ; N = Nfl ; property = prFl } ; i<b = record { e = fR ; 0<e = 0<fR ; N = N ; pr = prFR } } = record { i = boundA ; a<i = record { e = eL ; 0<e = 0<eL ; N = NL ; property = prL } ; i<b = record { e = eR ; 0<e = 0<eR ; N = (Nr +N Nfl) +N N ; pr = λ m N<m → SetoidPartialOrder.<Transitive pOrder (SetoidPartialOrder.<Transitive pOrder (SetoidPartialOrder.<Transitive pOrder (SetoidPartialOrder.<Transitive pOrder (prR m (inequalityShrinkLeft {Nr} (inequalityShrinkLeft N<m))) (<WellDefined identLeft (Equivalence.reflexive eq) (orderRespectsAddition 0<fL (index (CauchyCompletion.elts b) m)))) (prFl m (inequalityShrinkRight {Nr} (inequalityShrinkLeft N<m)))) (<WellDefined identLeft groupIsAbelian (orderRespectsAddition 0<fR boundB))) (prFR m (inequalityShrinkRight N<m)) } }
<COrder : SetoidPartialOrder cauchyCompletionSetoid _<C_
SetoidPartialOrder.<WellDefined <COrder {a} {b} {c} {d} a=b c=d a<c = <CWellDefined {a} {b} {c} {d} a=b c=d a<c
SetoidPartialOrder.irreflexive <COrder {a} a<a = <CIrreflexive {a} a<a
SetoidPartialOrder.<Transitive <COrder {a} {b} {c} a<b b<c = <CTransitive {a} {b} {c} a<b b<c
| {
"alphanum_fraction": 0.6799215906,
"avg_line_length": 97.5683060109,
"ext": "agda",
"hexsha": "153cd5ac28a3b1f5b83bf39fb2f2064318d59dbe",
"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": "Fields/CauchyCompletion/Comparison.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": "Fields/CauchyCompletion/Comparison.agda",
"max_line_length": 1069,
"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": "Fields/CauchyCompletion/Comparison.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": 6358,
"size": 17855
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Morphism.Duality {o ℓ e} (C : Category o ℓ e) where
open Category C
import Categories.Morphism as M
private
module Op = M op
open M C
open import Categories.Morphism.Properties C
private
variable
A B X Y : Obj
f g h : A ⇒ B
Mono⇒op-Epi : Mono f → Op.Epi f
Mono⇒op-Epi mono = mono
Epi⇒op-Mono : Epi f → Op.Mono f
Epi⇒op-Mono epi = epi
Iso⇒op-Iso : Iso f g → Op.Iso g f
Iso⇒op-Iso iso = record
{ isoˡ = isoˡ
; isoʳ = isoʳ
}
where open Iso iso
op-Iso⇒Iso : Op.Iso g f → Iso f g
op-Iso⇒Iso iso = record
{ isoˡ = isoˡ
; isoʳ = isoʳ
}
where open Op.Iso iso
≅⇒op-≅ : A ≅ B → A Op.≅ B
≅⇒op-≅ A≅B = record
{ from = to
; to = from
; iso = record -- I don't understand why Agda doesn't allow me to apply Iso⇒op-Iso
{ isoˡ = isoˡ
; isoʳ = isoʳ
}
}
where open _≅_ A≅B
op-≅⇒≅ : A Op.≅ B → A ≅ B
op-≅⇒≅ A≅B = record
{ from = to
; to = from
; iso = record
{ isoˡ = isoˡ
; isoʳ = isoʳ
}
}
where open Op._≅_ A≅B
| {
"alphanum_fraction": 0.5855940131,
"avg_line_length": 17.2419354839,
"ext": "agda",
"hexsha": "ec9d0fad5f5945cd013aa422160d252919a9ccb3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Morphism/Duality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Morphism/Duality.agda",
"max_line_length": 85,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Morphism/Duality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 475,
"size": 1069
} |
Subsets and Splits