Search is not available for this dataset
text
string | meta
dict |
---|---|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Infinite merge operation for coinductive lists
------------------------------------------------------------------------
{-# OPTIONS --without-K --guardedness #-}
module Codata.Musical.Colist.Infinite-merge where
open import Codata.Musical.Notation
open import Codata.Musical.Colist as Colist hiding (_⋎_)
open import Data.Nat
open import Data.Nat.Properties
open import Data.Product as Prod
open import Data.Sum
open import Data.Sum.Properties
open import Data.Sum.Function.Propositional using (_⊎-cong_)
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as Inv using (_↔_; Inverse; inverse)
import Function.Related as Related
open import Function.Related.TypeIsomorphisms
open import Induction.Nat using (<′-wellFounded)
import Induction.WellFounded as WF
open import Relation.Binary.PropositionalEquality as P using (_≡_)
------------------------------------------------------------------------
-- Some code that is used to work around Agda's syntactic guardedness
-- checker.
private
infixr 5 _∷_ _⋎_
data ColistP {a} (A : Set a) : Set a where
[] : ColistP A
_∷_ : A → ∞ (ColistP A) → ColistP A
_⋎_ : ColistP A → ColistP A → ColistP A
data ColistW {a} (A : Set a) : Set a where
[] : ColistW A
_∷_ : A → ColistP A → ColistW A
program : ∀ {a} {A : Set a} → Colist A → ColistP A
program [] = []
program (x ∷ xs) = x ∷ ♯ program (♭ xs)
mutual
_⋎W_ : ∀ {a} {A : Set a} → ColistW A → ColistP A → ColistW A
[] ⋎W ys = whnf ys
(x ∷ xs) ⋎W ys = x ∷ (ys ⋎ xs)
whnf : ∀ {a} {A : Set a} → ColistP A → ColistW A
whnf [] = []
whnf (x ∷ xs) = x ∷ ♭ xs
whnf (xs ⋎ ys) = whnf xs ⋎W ys
mutual
⟦_⟧P : ∀ {a} {A : Set a} → ColistP A → Colist A
⟦ xs ⟧P = ⟦ whnf xs ⟧W
⟦_⟧W : ∀ {a} {A : Set a} → ColistW A → Colist A
⟦ [] ⟧W = []
⟦ x ∷ xs ⟧W = x ∷ ♯ ⟦ xs ⟧P
mutual
⋎-homP : ∀ {a} {A : Set a} (xs : ColistP A) {ys} →
⟦ xs ⋎ ys ⟧P ≈ ⟦ xs ⟧P Colist.⋎ ⟦ ys ⟧P
⋎-homP xs = ⋎-homW (whnf xs) _
⋎-homW : ∀ {a} {A : Set a} (xs : ColistW A) ys →
⟦ xs ⋎W ys ⟧W ≈ ⟦ xs ⟧W Colist.⋎ ⟦ ys ⟧P
⋎-homW (x ∷ xs) ys = x ∷ ♯ ⋎-homP ys
⋎-homW [] ys = begin ⟦ ys ⟧P ∎
where open ≈-Reasoning
⟦program⟧P : ∀ {a} {A : Set a} (xs : Colist A) →
⟦ program xs ⟧P ≈ xs
⟦program⟧P [] = []
⟦program⟧P (x ∷ xs) = x ∷ ♯ ⟦program⟧P (♭ xs)
Any-⋎P : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} →
Any P ⟦ program xs ⋎ ys ⟧P ↔ (Any P xs ⊎ Any P ⟦ ys ⟧P)
Any-⋎P {P = P} xs {ys} =
Any P ⟦ program xs ⋎ ys ⟧P ↔⟨ Any-cong Inv.id (⋎-homP (program xs)) ⟩
Any P (⟦ program xs ⟧P Colist.⋎ ⟦ ys ⟧P) ↔⟨ Any-⋎ _ ⟩
(Any P ⟦ program xs ⟧P ⊎ Any P ⟦ ys ⟧P) ↔⟨ Any-cong Inv.id (⟦program⟧P _) ⊎-cong (_ ∎) ⟩
(Any P xs ⊎ Any P ⟦ ys ⟧P) ∎
where open Related.EquationalReasoning
index-Any-⋎P :
∀ {a p} {A : Set a} {P : A → Set p} xs {ys}
(p : Any P ⟦ program xs ⋎ ys ⟧P) →
index p ≥′ [ index , index ]′ (Inverse.to (Any-⋎P xs) ⟨$⟩ p)
index-Any-⋎P xs p
with Any-resp id (⋎-homW (whnf (program xs)) _) p
| index-Any-resp {f = id} (⋎-homW (whnf (program xs)) _) p
index-Any-⋎P xs p | q | q≡p
with Inverse.to (Any-⋎ ⟦ program xs ⟧P) ⟨$⟩ q
| index-Any-⋎ ⟦ program xs ⟧P q
index-Any-⋎P xs p | q | q≡p | inj₂ r | r≤q rewrite q≡p = r≤q
index-Any-⋎P xs p | q | q≡p | inj₁ r | r≤q
with Any-resp id (⟦program⟧P xs) r
| index-Any-resp {f = id} (⟦program⟧P xs) r
index-Any-⋎P xs p | q | q≡p | inj₁ r | r≤q | s | s≡r
rewrite s≡r | q≡p = r≤q
------------------------------------------------------------------------
-- Infinite variant of _⋎_.
private
merge′ : ∀ {a} {A : Set a} → Colist (A × Colist A) → ColistP A
merge′ [] = []
merge′ ((x , xs) ∷ xss) = x ∷ ♯ (program xs ⋎ merge′ (♭ xss))
merge : ∀ {a} {A : Set a} → Colist (A × Colist A) → Colist A
merge xss = ⟦ merge′ xss ⟧P
------------------------------------------------------------------------
-- Any lemma for merge.
module _ {a p} {A : Set a} {P : A → Set p} where
Any-merge : ∀ xss → Any P (merge xss) ↔ Any (λ { (x , xs) → P x ⊎ Any P xs }) xss
Any-merge xss = inverse (proj₁ ∘ to xss) from (proj₂ ∘ to xss) to∘from
where
open P.≡-Reasoning
-- The from function.
Q = λ { (x , xs) → P x ⊎ Any P xs }
from : ∀ {xss} → Any Q xss → Any P (merge xss)
from (here (inj₁ p)) = here p
from (here (inj₂ p)) = there (Inverse.from (Any-⋎P _) ⟨$⟩ inj₁ p)
from (there {x = _ , xs} p) = there (Inverse.from (Any-⋎P xs) ⟨$⟩ inj₂ (from p))
-- The from function is injective.
from-injective : ∀ {xss} (p₁ p₂ : Any Q xss) →
from p₁ ≡ from p₂ → p₁ ≡ p₂
from-injective (here (inj₁ p)) (here (inj₁ .p)) P.refl = P.refl
from-injective (here (inj₁ _)) (here (inj₂ _)) ()
from-injective (here (inj₂ _)) (here (inj₁ _)) ()
from-injective (here (inj₂ p₁)) (here (inj₂ p₂)) eq =
P.cong (here ∘ inj₂) $
inj₁-injective $
Inverse.injective (Inv.sym (Any-⋎P _)) {x = inj₁ p₁} {y = inj₁ p₂} $
there-injective eq
from-injective (here (inj₁ _)) (there _) ()
from-injective (here (inj₂ p₁)) (there p₂) eq
with Inverse.injective (Inv.sym (Any-⋎P _))
{x = inj₁ p₁} {y = inj₂ (from p₂)}
(there-injective eq)
... | ()
from-injective (there _) (here (inj₁ _)) ()
from-injective (there p₁) (here (inj₂ p₂)) eq
with Inverse.injective (Inv.sym (Any-⋎P _))
{x = inj₂ (from p₁)} {y = inj₁ p₂}
(there-injective eq)
... | ()
from-injective (there {x = _ , xs} p₁) (there p₂) eq =
P.cong there $
from-injective p₁ p₂ $
inj₂-injective $
Inverse.injective (Inv.sym (Any-⋎P xs))
{x = inj₂ (from p₁)} {y = inj₂ (from p₂)} $
there-injective eq
-- The to function (defined as a right inverse of from).
Input = ∃ λ xss → Any P (merge xss)
Pred : Input → Set _
Pred (xss , p) = ∃ λ (q : Any Q xss) → from q ≡ p
to : ∀ xss p → Pred (xss , p)
to = λ xss p →
WF.All.wfRec (WF.InverseImage.wellFounded size <′-wellFounded) _
Pred step (xss , p)
where
size : Input → ℕ
size (_ , p) = index p
step : ∀ p → WF.WfRec (_<′_ on size) Pred p → Pred p
step ([] , ()) rec
step ((x , xs) ∷ xss , here p) rec = here (inj₁ p) , P.refl
step ((x , xs) ∷ xss , there p) rec
with Inverse.to (Any-⋎P xs) ⟨$⟩ p
| Inverse.left-inverse-of (Any-⋎P xs) p
| index-Any-⋎P xs p
... | inj₁ q | P.refl | _ = here (inj₂ q) , P.refl
... | inj₂ q | P.refl | q≤p =
Prod.map there
(P.cong (there ∘ _⟨$⟩_ (Inverse.from (Any-⋎P xs)) ∘ inj₂))
(rec (♭ xss , q) (s≤′s q≤p))
to∘from = λ p → from-injective _ _ (proj₂ (to xss (from p)))
-- Every member of xss is a member of merge xss, and vice versa (with
-- equal multiplicities).
∈-merge : ∀ {a} {A : Set a} {y : A} xss →
y ∈ merge xss ↔ ∃₂ λ x xs → (x , xs) ∈ xss × (y ≡ x ⊎ y ∈ xs)
∈-merge {y = y} xss =
y ∈ merge xss ↔⟨ Any-merge _ ⟩
Any (λ { (x , xs) → y ≡ x ⊎ y ∈ xs }) xss ↔⟨ Any-∈ ⟩
(∃ λ { (x , xs) → (x , xs) ∈ xss × (y ≡ x ⊎ y ∈ xs) }) ↔⟨ Σ-assoc ⟩
(∃₂ λ x xs → (x , xs) ∈ xss × (y ≡ x ⊎ y ∈ xs)) ∎
where open Related.EquationalReasoning
|
{
"alphanum_fraction": 0.4837837838,
"avg_line_length": 35.9722222222,
"ext": "agda",
"hexsha": "c06870cd3b96b5aedbb8e889a2e6fe5b7d2b065a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/Colist/Infinite-merge.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/Colist/Infinite-merge.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/Colist/Infinite-merge.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3024,
"size": 7770
}
|
------------------------------------------------------------------------
-- Order morphisms
------------------------------------------------------------------------
module Relation.Binary.OrderMorphism where
open import Relation.Binary
open Poset
import Data.Function as F
record _⇒-Poset_ (po₁ po₂ : Poset) : Set where
field
fun : carrier po₁ → carrier po₂
monotone : _≤_ po₁ =[ fun ]⇒ _≤_ po₂
_⇒-DTO_ : (dto₁ dto₂ : DecTotalOrder) → Set
dto₁ ⇒-DTO dto₂ = poset dto₁ ⇒-Poset poset dto₂
where open DecTotalOrder
open _⇒-Poset_
id : ∀ {po} → po ⇒-Poset po
id = record
{ fun = F.id
; monotone = F.id
}
_∘_ : ∀ {po₁ po₂ po₃} →
po₂ ⇒-Poset po₃ → po₁ ⇒-Poset po₂ → po₁ ⇒-Poset po₃
f ∘ g = record
{ fun = F._∘_ (fun f) (fun g)
; monotone = F._∘_ (monotone f) (monotone g)
}
const : ∀ {po₁ po₂} → carrier po₂ → po₁ ⇒-Poset po₂
const {po₂ = po₂} x = record
{ fun = F.const x
; monotone = F.const (refl po₂)
}
|
{
"alphanum_fraction": 0.512371134,
"avg_line_length": 24.25,
"ext": "agda",
"hexsha": "598381959c948e7e2c1596f5d482f52e562b4896",
"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/Relation/Binary/OrderMorphism.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/Relation/Binary/OrderMorphism.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Relation/Binary/OrderMorphism.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": 342,
"size": 970
}
|
------------------------------------------------------------------------
-- An example: A non-terminating program that runs in bounded stack
-- space
------------------------------------------------------------------------
module Lambda.Interpreter.Stack-sizes.Example where
open import Equality.Propositional as E using (refl)
open import Prelude
open import Prelude.Size
open import Colist E.equality-with-J as C
open import Conat E.equality-with-J as Conat hiding (pred)
open import Function-universe E.equality-with-J hiding (id; _∘_)
open import Monad E.equality-with-J
open import Nat E.equality-with-J
open import Vec.Data E.equality-with-J
open import Delay-monad
open import Delay-monad.Bisimilarity as D using (later; force)
open import Upper-bounds
import Lambda.Delay-crash-trace as DCT
import Lambda.Interpreter
import Lambda.Interpreter.Stack-sizes
open DCT.Delay-crash-trace
-- This module uses a name type with a single inhabitant, allowing
-- (and requiring) the definition and use of one named definition.
open import Lambda.Syntax ⊤
open Closure Tm
-- A definition that calls itself repeatedly using a tail call.
def : ⊤ → Tm 1
def tt = call tt (con true)
-- The two interpreters are instantiated with this definition.
open Lambda.Interpreter def
module I = Lambda.Interpreter.Stack-sizes def
-- A top-level term to get things going.
go : Tm 0
go = call tt (con true)
-- The semantics of go is the non-terminating computation never.
go-loops : ∀ {i} → D.[ i ] ⟦ go ⟧ [] ∼ never
go-loops = later λ { .force → go-loops }
-- Colists used to analyse the stack space usage of go.
loop-sizes : ∀ {i} → Colist ℕ i
loop-sizes = 1 ∷′ 2 ∷ λ { .force → loop-sizes }
go-sizes : Colist ℕ ∞
go-sizes = 0 ∷′ 1 ∷′ loop-sizes
-- When go is interpreted (starting with an empty stack) the stack
-- sizes that are encountered match the sizes in go-sizes.
stack-sizes-go∼go-sizes : ∀ {i} → C.[ i ] I.stack-sizes go ∼ go-sizes
stack-sizes-go∼go-sizes =
I.numbers (I.⟦ go ⟧ [] false) 0 C.∼⟨ ∷∼∷′ ⟩
0 ∷′ I.numbers (I.[ id , pred ] lam (def tt) [] ∙ con true) 1 C.∼⟨ (refl ∷ λ { .force → ∷∼∷′ }) ⟩
0 ∷′ 1 ∷′ I.numbers (I.⟦ def tt ⟧ ρ true >>= tell pred ∘ return) 1 C.∼⟨ (refl ∷ λ { .force → refl ∷ λ { .force → numbers-loop∼loop-sizes _ }}) ⟩
0 ∷′ 1 ∷′ loop-sizes C.∼⟨⟩
go-sizes C.∎
where
ρ = con true ∷ []
numbers-loop∼loop-sizes :
∀ {i} k → C.[ i ] I.numbers (I.⟦ def tt ⟧ ρ true >>= k) 1 ∼ loop-sizes
numbers-loop∼loop-sizes k =
I.numbers (I.⟦ def tt ⟧ ρ true >>= k) 1 C.∼⟨ ∷∼∷′ ⟩
1 ∷′ I.numbers (I.[ pred , id ] lam (def tt) [] ∙ con true >>= k) 2 C.∼⟨ (refl ∷ λ { .force → ∷∼∷′ }) ⟩
1 ∷′ 2 ∷′ I.numbers (I.⟦ def tt ⟧ ρ true >>= tell id ∘ return >>= k) 1 C.∼⟨ (refl ∷ λ { .force → refl ∷ λ { .force → I.numbers-cong (
DCT.symmetric (DCT.associativity (I.⟦ def tt ⟧ ρ true) _ _)) }}) ⟩
1 ∷′ 2 ∷′ I.numbers (I.⟦ def tt ⟧ ρ true >>= tell id ∘ k) 1 C.∼⟨ (refl ∷ λ { .force → refl ∷ λ { .force →
numbers-loop∼loop-sizes _ }}) ⟩
1 ∷′ 2 ∷′ loop-sizes C.∼⟨ (refl ∷ λ { .force → C.symmetric-∼ ∷∼∷′ }) ⟩
loop-sizes C.∎
-- The least upper bound of go-sizes is 2.
lub-go-sizes-2 : LUB go-sizes ⌜ 2 ⌝
lub-go-sizes-2 =
lub-∷ʳ zero (lub-∷ʳ 1≤2 lub-loop-sizes-2)
where
1≤2 = suc λ { .force → zero }
2∷[] = λ { .force → 2 ∷′ [] }
cycle-1-2∷[]∼loop-sizes :
∀ {i} → C.[ i ] cycle 1 2∷[] ∼ loop-sizes
cycle-1-2∷[]∼loop-sizes =
refl ∷ λ { .force → refl ∷ λ { .force → cycle-1-2∷[]∼loop-sizes }}
lub-loop-sizes-2 : LUB loop-sizes ⌜ 2 ⌝
lub-loop-sizes-2 = $⟨ lub-∷ʳ 1≤2 (lub-∷ˡ zero lub-[]) ⟩
LUB (1 ∷ 2∷[]) ⌜ 2 ⌝ ↝⟨ lub-cycle ⟩
LUB (cycle 1 2∷[]) ⌜ 2 ⌝ ↝⟨ LUB-∼ cycle-1-2∷[]∼loop-sizes (Conat.reflexive-∼ _) ⟩□
LUB loop-sizes ⌜ 2 ⌝ □
-- The maximum stack size encountered when running go (starting with
-- an empty stack) is 2.
go-bounded-stack : LUB (I.stack-sizes go) ⌜ 2 ⌝
go-bounded-stack =
LUB-∼ (C.symmetric-∼ stack-sizes-go∼go-sizes)
(Conat.reflexive-∼ _)
lub-go-sizes-2
|
{
"alphanum_fraction": 0.5320384014,
"avg_line_length": 37.6386554622,
"ext": "agda",
"hexsha": "3bcf14137c836b3a15b914e39ecf093004705f91",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/definitional-interpreters",
"max_forks_repo_path": "src/Lambda/Interpreter/Stack-sizes/Example.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/definitional-interpreters",
"max_issues_repo_path": "src/Lambda/Interpreter/Stack-sizes/Example.agda",
"max_line_length": 148,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/definitional-interpreters",
"max_stars_repo_path": "src/Lambda/Interpreter/Stack-sizes/Example.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1557,
"size": 4479
}
|
module Conway where
open import Data.Bool renaming (_≟_ to _B≟_)
open import Data.Nat renaming (_+_ to _ℕ+_ ; _*_ to _ℕ*_ ; _≟_ to _ℕ≟_)
open import Data.Integer
renaming (_+_ to _ℤ+_ ; _*_ to _ℤ*_ ; -_ to ℤ-_ ; _≟_ to _ℤ≟_)
open import Data.Rational renaming (_≟_ to _ℚ≟_)
open import Relation.Nullary.Core
open import Relation.Nullary.Decidable
open import Rat -- operations on rationals
------------------------------------------------------------------------------
-- Universe of games
data U : Set where
ZERO : U
ONE : U
PLUS : U → U → U
TIMES : U → U → U
NEG : U → U
RECIP : U → U
-- Conversion from the rationals to the universe of games
n2U : ℕ → U
n2U 0 = ZERO
n2U (suc n) = PLUS ONE (n2U n)
z2U : ℤ → U
z2U -[1+ n ] = NEG (n2U (ℕ.suc n))
z2U (+ n) = n2U n
q2U : ℚ → U
q2U p = TIMES (z2U (ℚ.numerator p)) (RECIP (n2U (ℕ.suc (ℚ.denominator-1 p))))
-- Conversion from the universe of games to the rationals
-- use meadows?
mutual
u2q : U → ℚ
u2q ZERO = 0ℚ
u2q ONE = 1ℚ
u2q (PLUS g h) = (u2q g) + (u2q h)
u2q (TIMES g h) = (u2q g) * (u2q h)
u2q (NEG g) = - (u2q g)
u2q (RECIP g) = 1/_ (u2q g) {{!!}}
-- need to know that | numerator (u2q g) | is not 0
u2q≢0 : (u : U) → {u≢0 : False (u2q u ℚ≟ 0ℚ)} → ℚ
u2q≢0 u {u≢0} with (u2q u ℚ≟ 0ℚ)
u2q≢0 u {()} | yes _
u2q≢0 u {_} | no _ = u2q u
------------------------------------------------------------------------------
-- Small tests
private
test₁ = q2U (- (+ 1 ÷ 3))
{--
TIMES
(NEG (PLUS ONE ZERO))
(RECIP (PLUS ONE (PLUS ONE (PLUS ONE ZERO))))
--}
------------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.4858490566,
"avg_line_length": 24.2285714286,
"ext": "agda",
"hexsha": "3c73f2642c9c73ad60ad3a40ad069ba4fa7ad4a9",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Conway.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Conway.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Conway.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 653,
"size": 1696
}
|
module puzzle where
---- 仮定
-- 猫か犬を飼っている人は山羊を飼ってない
-- 猫を飼ってない人は、犬かウサギを飼っている
-- 猫も山羊も飼っていない人は、ウサギを飼っている
--
---- 問題
-- 山羊を飼っている人は、犬を飼っていない
-- 山羊を飼っている人は、ウサギを飼っている
-- ウサギを飼っていない人は、猫を飼っている
module pet-research where
open import logic
open import Relation.Nullary
open import Data.Empty
postulate
lem : (a : Set) → a ∨ ( ¬ a )
record PetResearch ( Cat Dog Goat Rabbit : Set ) : Set where
field
fact1 : ( Cat ∨ Dog ) → ¬ Goat
fact2 : ¬ Cat → ( Dog ∨ Rabbit )
fact3 : ¬ ( Cat ∨ Goat ) → Rabbit
module tmp ( Cat Dog Goat Rabbit : Set ) (p : PetResearch Cat Dog Goat Rabbit ) where
open PetResearch
problem0 : Cat ∨ Dog ∨ Goat ∨ Rabbit
problem0 with lem Cat | lem Goat
... | case1 c | g = case1 c
... | c | case1 g = case2 ( case2 ( case1 g ) )
... | case2 ¬c | case2 ¬g = case2 ( case2 ( case2 ( fact3 p lemma1 ))) where
lemma1 : ¬ ( Cat ∨ Goat )
lemma1 (case1 c) = ¬c c
lemma1 (case2 g) = ¬g g
problem1 : Goat → ¬ Dog
problem1 g d = fact1 p (case2 d) g
problem2 : Goat → Rabbit
problem2 g with lem Cat | lem Dog
problem2 g | case1 c | d = ⊥-elim ( fact1 p (case1 c ) g )
problem2 g | case2 ¬c | case1 d = ⊥-elim ( fact1 p (case2 d ) g )
problem2 g | case2 ¬c | case2 ¬d with lem Rabbit
... | case1 r = r
... | case2 ¬r = fact3 p lemma2 where
lemma2 : ¬ ( Cat ∨ Goat )
lemma2 (case1 c) = ¬c c
lemma2 (case2 g) with fact2 p ¬c
lemma2 (case2 g) | case1 d = ¬d d
lemma2 (case2 g) | case2 r = ¬r r
problem3 : (¬ Rabbit ) → Cat
problem3 ¬r with lem Cat | lem Goat
problem3 ¬r | case1 c | g = c
problem3 ¬r | case2 ¬c | g = ⊥-elim ( ¬r ( fact3 p lemma3 )) where
lemma3 : ¬ ( Cat ∨ Goat )
lemma3 (case1 c) = ¬c c
lemma3 (case2 g) with fact2 p ¬c
lemma3 (case2 g) | case1 d = fact1 p (case2 d ) g
lemma3 (case2 g) | case2 r = ¬r r
module pet-research1 ( Cat Dog Goat Rabbit : Set ) where
open import Data.Bool
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
_=>_ : Bool → Bool → Bool
_ => true = true
false => _ = true
true => false = false
¬_ : Bool → Bool
¬ p = not p
problem0 : ( Cat Dog Goat Rabbit : Bool ) →
((( Cat ∨ Dog ) => (¬ Goat) ) ∧ ( (¬ Cat ) => ( Dog ∨ Rabbit ) ) ∧ ( ( ¬ ( Cat ∨ Goat ) ) => Rabbit ) )
=> (Cat ∨ Dog ∨ Goat ∨ Rabbit) ≡ true
problem0 true d g r = refl
problem0 false true g r = refl
problem0 false false true r = refl
problem0 false false false true = refl
problem0 false false false false = refl
problem1 : ( Cat Dog Goat Rabbit : Bool ) →
((( Cat ∨ Dog ) => (¬ Goat) ) ∧ ( (¬ Cat ) => ( Dog ∨ Rabbit ) ) ∧ ( ( ¬ ( Cat ∨ Goat ) ) => Rabbit ) )
=> ( Goat => ( ¬ Dog )) ≡ true
problem1 c false false r = refl
problem1 c true false r = refl
problem1 c false true r = refl
problem1 false true true r = refl
problem1 true true true r = refl
problem2 : ( Cat Dog Goat Rabbit : Bool ) →
((( Cat ∨ Dog ) => (¬ Goat) ) ∧ ( (¬ Cat ) => ( Dog ∨ Rabbit ) ) ∧ ( ( ¬ ( Cat ∨ Goat ) ) => Rabbit ) )
=> ( Goat => Rabbit ) ≡ true
problem2 c d false false = refl
problem2 c d false true = refl
problem2 c d true true = refl
problem2 true d true false = refl
problem2 false false true false = refl
problem2 false true true false = refl
problem3 : ( Cat Dog Goat Rabbit : Bool ) →
((( Cat ∨ Dog ) => (¬ Goat) ) ∧ ( (¬ Cat ) => ( Dog ∨ Rabbit ) ) ∧ ( ( ¬ ( Cat ∨ Goat ) ) => Rabbit ) )
=> ( (¬ Rabbit ) => Cat ) ≡ true
problem3 false d g true = refl
problem3 true d g true = refl
problem3 true d g false = refl
problem3 false false false false = refl
problem3 false false true false = refl
problem3 false true false false = refl
problem3 false true true false = refl
-- module pet-research2 ( Cat Dog Goat Rabbit : Set ) where
--
-- open import Data.Bool hiding ( _∨_ )
-- open import Relation.Binary
-- open import Relation.Binary.PropositionalEquality
--
-- ¬_ : Bool → Bool
-- ¬ p = p xor true
--
-- infixr 5 _∨_
-- _∨_ : Bool → Bool → Bool
-- a ∨ b = ¬ ( (¬ a) ∧ (¬ b ) )
--
-- _=>_ : Bool → Bool → Bool
-- a => b = (¬ a ) ∨ b
--
-- open import Data.Bool.Solver using (module xor-∧-Solver)
-- open xor-∧-Solver
--
-- problem0' : ( Cat : Bool ) → (Cat xor Cat ) ≡ false
-- problem0' = solve 1 (λ c → (c :+ c ) := con false ) refl
--
-- problem1' : ( Cat : Bool ) → (Cat ∧ (Cat xor true )) ≡ false
-- problem1' = solve 1 (λ c → ((c :* (c :+ con true )) ) := con false ) {!!}
--
-- open import Data.Nat
-- :¬_ : {n : ℕ} → Polynomial n → Polynomial n
-- :¬ p = p :+ con true
--
-- _:∨_ : {n : ℕ} → Polynomial n → Polynomial n → Polynomial n
-- a :∨ b = :¬ ( ( :¬ a ) :* ( :¬ b ))
--
-- _:=>_ : {n : ℕ} → Polynomial n → Polynomial n → Polynomial n
-- a :=> b = ( :¬ a ) :∨ b
--
-- _:∧_ = _:*_
--
-- infixr 6 _:∧_
-- infixr 5 _:∨_
--
-- problem0 : ( Cat Dog Goat Rabbit : Bool ) →
-- ((( Cat ∨ Dog ) => (¬ Goat) ) ∧ ( (¬ Cat ) => ( Dog ∨ Rabbit ) ) ∧ ( ( ¬ ( Cat ∨ Goat ) ) => Rabbit ) )
-- => (Cat ∨ Dog ∨ Goat ∨ Rabbit) ≡ true
-- problem0 = solve 4 ( λ Cat Dog Goat Rabbit → (
-- ( ((Cat :∨ Dog ) :=> (:¬ Goat)) :∧ ( ((:¬ Cat ) :=> ( Dog :∨ Rabbit )) :∧ (( :¬ ( Cat :∨ Goat ) ) :=> Rabbit) ))
-- :=> ( Cat :∨ (Dog :∨ ( Goat :∨ Rabbit))) ) := con true ) {!!}
--
-- problem1 : ( Cat Dog Goat Rabbit : Bool ) →
-- ((( Cat ∨ Dog ) => (¬ Goat) ) ∧ ( (¬ Cat ) => ( Dog ∨ Rabbit ) ) ∧ ( ( ¬ ( Cat ∨ Goat ) ) => Rabbit ) )
-- => ( Goat => ( ¬ Dog )) ≡ true
-- problem1 c false false r = {!!}
-- problem1 c true false r = {!!}
-- problem1 c false true r = {!!}
-- problem1 false true true r = refl
-- problem1 true true true r = refl
--
-- problem2 : ( Cat Dog Goat Rabbit : Bool ) →
-- ((( Cat ∨ Dog ) => (¬ Goat) ) ∧ ( (¬ Cat ) => ( Dog ∨ Rabbit ) ) ∧ ( ( ¬ ( Cat ∨ Goat ) ) => Rabbit ) )
-- => ( Goat => Rabbit ) ≡ true
-- problem2 c d false false = {!!}
-- problem2 c d false true = {!!}
-- problem2 c d true true = {!!}
-- problem2 true d true false = refl
-- problem2 false false true false = refl
-- problem2 false true true false = refl
--
-- problem3 : ( Cat Dog Goat Rabbit : Bool ) →
-- ((( Cat ∨ Dog ) => (¬ Goat) ) ∧ ( (¬ Cat ) => ( Dog ∨ Rabbit ) ) ∧ ( ( ¬ ( Cat ∨ Goat ) ) => Rabbit ) )
-- => ( (¬ Rabbit ) => Cat ) ≡ true
-- problem3 false d g true = {!!}
-- problem3 true d g true = {!!}
-- problem3 true d g false = {!!}
-- problem3 false false false false = refl
-- problem3 false false true false = refl
-- problem3 false true false false = refl
-- problem3 false true true false = refl
|
{
"alphanum_fraction": 0.5247860726,
"avg_line_length": 34.758974359,
"ext": "agda",
"hexsha": "96ce9153deef6a941ac421d21c7918ec289a178c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/automaton-in-agda",
"max_forks_repo_path": "src/puzzle.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/automaton-in-agda",
"max_issues_repo_path": "src/puzzle.agda",
"max_line_length": 122,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/automaton-in-agda",
"max_stars_repo_path": "src/puzzle.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2460,
"size": 6778
}
|
{-# OPTIONS --without-K --safe #-}
module Data.Binary where
open import Data.Binary.Definitions using (𝔹) public
open import Data.Binary.Operations.Semantics using (⟦_⇑⟧; ⟦_⇓⟧) public
open import Data.Binary.Operations.Addition using (_+_) public
open import Data.Binary.Operations.Multiplication using (_*_) public
open import Data.Binary.Operations.Unary using (inc; dec) public
|
{
"alphanum_fraction": 0.7074340528,
"avg_line_length": 41.7,
"ext": "agda",
"hexsha": "735756bbe4e9f76e1969e0b0ee2592cf5bcdb0fd",
"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": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-binary",
"max_forks_repo_path": "Data/Binary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"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-binary",
"max_issues_repo_path": "Data/Binary.agda",
"max_line_length": 75,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-binary",
"max_stars_repo_path": "Data/Binary.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-21T21:30:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-21T21:30:10.000Z",
"num_tokens": 108,
"size": 417
}
|
{-# OPTIONS --without-K #-}
module hott.level.closure.extra where
open import level
open import decidable
open import sum
open import level using (lsuc; ↑; lift)
open import equality.core
open import equality.calculus
open import function.core using (_∘_; const)
open import function.extensionality
open import function.isomorphism
open import sets.bool
open import sets.unit
open import sets.nat.core
-- open import sets.nat.ordering.leq.core
open import hott.level.core
open import hott.level.sets
open import hott.level.closure.core
open import hott.equivalence.core
using (weak-equiv; _≈_)
open import hott.univalence
open import sets.empty
abstract
-- Π preserves h-levels
Π-level : ∀ {i j n} {X : Set i}{Y : X → Set j}
→ ((x : X) → h n (Y x))
→ h n ((x : X) → Y x)
Π-level {n = 0} c = Π-contr c
Π-level {n = suc n} {X = X}{Y} hn = λ f g →
subst (h n) strong-funext (Π-level (λ x → hn x (f x) (g x)))
-- Σ preserves h-levels
Σ-level : ∀ {i j n} {X : Set i}{Y : X → Set j}
→ h n X → ((x : X) → h n (Y x))
→ h n (Σ X Y)
Σ-level {n = 0}{X = X}{Y} (x₀ , cx) hy =
(x₀ , proj₁ (hy x₀)) , λ { (x , y) → c x y }
where
c : (x : X)(y : Y x) → (x₀ , proj₁ (hy x₀)) ≡ (x , y)
c x y = ap (λ x → (x , proj₁ (hy x))) (cx x)
· ap (_,_ x) (proj₂ (hy x) y)
Σ-level {n = suc n} hx hy = λ a b → iso-level Σ-split-iso
(Σ-level (hx _ _) (λ p → hy (proj₁ b) _ _))
-- × preserves h-levels
×-level : ∀ {i j n}{X : Set i}{Y : Set j}
→ h n X → h n Y → h n (X × Y)
×-level hx hy = Σ-level hx (λ _ → hy)
-- ⊎ preserves h-levels
-- ⊎-level : ∀ {i j n}{X : Set i}{Y : Set j}
-- → 2 ≤ n → h n X → h n Y → h n (X ⊎ Y)
-- ⊎-level {i}{j}{n} {X}{Y} p hx hy = iso-level lem
-- (Σ-level (h! {p = decide p} bool-set) P-level)
-- where
-- P : Bool → Set (i ⊔ j)
-- P true = ↑ j X
-- P false = ↑ i Y
--
-- P-level : (b : Bool) → h n (P b)
-- P-level true = iso-level (lift-iso j X) hx
-- P-level false = iso-level (lift-iso i Y) hy
--
-- lem : Σ Bool P ≅ (X ⊎ Y)
-- lem = iso f g H K
-- where
-- f : (Σ Bool P) → (X ⊎ Y)
-- f (true , lift x) = inj₁ x
-- f (false , lift y) = inj₂ y
--
-- g : (X ⊎ Y) → (Σ Bool P)
-- g (inj₁ x) = (true , lift x)
-- g (inj₂ y) = (false , lift y)
--
-- H : (x : Σ Bool P) → g (f x) ≡ x
-- H (true , lift x) = refl
-- H (false , lift y) = refl
--
-- K : (x : X ⊎ Y) → f (g x) ≡ x
-- K (inj₁ x) = refl
-- K (inj₂ y) = refl
Π-level-impl : ∀ {i j n} {X : Set i}{Y : X → Set j}
→ ((x : X) → h n (Y x))
→ h n ({x : X} → Y x)
Π-level-impl {X = X}{Y} hY = iso-level impl-iso (Π-level hY)
-- being contractible is a proposition
contr-h1 : ∀ {i}(X : Set i) → h 1 (contr X)
contr-h1 X = prop⇒h1 λ { (x₀ , c₀) (x₁ , c₁) →
unapΣ (c₀ x₁ , contr⇒prop (lem (x₀ , c₀) x₁) _ _) }
where
lem : ∀ {i}{A : Set i} → contr A → (x : A) → contr ((x' : A) → x ≡ x')
lem c x = Π-level (λ x' → h↑ c x x')
-- being of h-level n is a proposition
hn-h1 : ∀ {i} n (X : Set i) → h 1 (h n X)
hn-h1 0 X = contr-h1 X
hn-h1 (suc n) X = Π-level λ x → Π-level λ y → hn-h1 n (x ≡ y)
-- being a weak equivalence is a proposition
weak-equiv-h1 : ∀ {i j}{X : Set i}{Y : Set j}
→ (f : X → Y)
→ h 1 (weak-equiv f)
weak-equiv-h1 f = Π-level λ y
→ contr-h1 _
⊎-h1 : ∀ {i j}{A : Set i}{B : Set j}
→ h 1 A → h 1 B → ¬ (A × B)
→ h 1 (A ⊎ B)
⊎-h1 {A = A}{B = B} hA hB u = prop⇒h1 ⊎-prop
where
⊎-prop : prop (A ⊎ B)
⊎-prop (inj₁ a) (inj₁ a') = ap inj₁ (h1⇒prop hA a a')
⊎-prop (inj₁ a) (inj₂ b') = ⊥-elim (u (a , b'))
⊎-prop (inj₂ b) (inj₁ a') = ⊥-elim (u (a' , b))
⊎-prop (inj₂ b) (inj₂ b') = ap inj₂ (h1⇒prop hB b b')
inj-level : ∀ {i j n}{A : Set i}{B : Set j}
→ (f : A → B)
→ h (suc n) A → h n (injective f)
inj-level f hA
= Π-level-impl λ x
→ Π-level-impl λ x'
→ Π-level λ p
→ hA x x'
↣-level : ∀ {i j n}{A : Set i}{B : Set j}
→ h (suc n) A → h n B → h n (A ↣ B)
↣-level hA hB
= Σ-level (Π-level λ _ → hB) λ f
→ inj-level f hA
¬-h1 : ∀ {i}{X : Set i} → h 1 (¬ X)
¬-h1 = Π-level λ _ → ⊥-prop
|
{
"alphanum_fraction": 0.4663483402,
"avg_line_length": 31.8695652174,
"ext": "agda",
"hexsha": "80310eb7c994e9625597657065302078b295fdcf",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "hott/level/closure/extra.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "hott/level/closure/extra.agda",
"max_line_length": 76,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "hott/level/closure/extra.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 1801,
"size": 4398
}
|
module Cats.Category.Zero where
open import Data.Empty using (⊥ ; ⊥-elim)
open import Level
open import Cats.Category
Zero : ∀ lo la l≈ → Category lo la l≈
Zero lo la l≈ = record
{ Obj = Lift lo ⊥
; _⇒_ = λ()
; _≈_ = λ {}
; id = λ{}
; _∘_ = λ{}
; equiv = λ{}
; ∘-resp = λ{}
; id-r = λ{}
; id-l = λ{}
; assoc = λ{}
}
|
{
"alphanum_fraction": 0.4807692308,
"avg_line_length": 16.5454545455,
"ext": "agda",
"hexsha": "c21ee7c85374cee4171850c95bde2e959eda0c17",
"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": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Category/Zero.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"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": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Category/Zero.agda",
"max_line_length": 41,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Category/Zero.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 135,
"size": 364
}
|
{-
Some theory about Bi-Invertible Equivalences
- BiInvEquiv to Iso
- BiInvEquiv to Equiv
- BiInvEquiv to HAEquiv
- Iso to BiInvEquiv
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.BiInvEquiv where
open import Cubical.Core.Glue
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HAEquiv
record BiInvEquiv {ℓ ℓ'} (A : Type ℓ) (B : Type ℓ') : Type (ℓ-max ℓ ℓ') where
constructor biInvEquiv
field
fun : A → B
invr : B → A
invr-rightInv : section fun invr
invl : B → A
invl-leftInv : retract fun invl
invr≡invl : ∀ b → invr b ≡ invl b
invr≡invl b = invr b ≡⟨ sym (invl-leftInv (invr b)) ⟩
invl (fun (invr b)) ≡⟨ cong invl (invr-rightInv b) ⟩
invl b ∎
invr-leftInv : retract fun invr
invr-leftInv a = invr≡invl (fun a) □ (invl-leftInv a)
invr≡invl-leftInv : ∀ a → PathP (λ j → invr≡invl (fun a) j ≡ a) (invr-leftInv a) (invl-leftInv a)
invr≡invl-leftInv a j i = compPath'-filler (invr≡invl (fun a)) (invl-leftInv a) (~ j) i
invl-rightInv : section fun invl
invl-rightInv a = sym (cong fun (invr≡invl a)) □ (invr-rightInv a)
invr≡invl-rightInv : ∀ a → PathP (λ j → fun (invr≡invl a j) ≡ a) (invr-rightInv a) (invl-rightInv a)
invr≡invl-rightInv a j i = compPath'-filler (sym (cong fun (invr≡invl a))) (invr-rightInv a) j i
module _ {ℓ} {A B : Type ℓ} (e : BiInvEquiv A B) where
open BiInvEquiv e
biInvEquiv→Iso-right : Iso A B
Iso.fun biInvEquiv→Iso-right = fun
Iso.inv biInvEquiv→Iso-right = invr
Iso.rightInv biInvEquiv→Iso-right = invr-rightInv
Iso.leftInv biInvEquiv→Iso-right = invr-leftInv
biInvEquiv→Iso-left : Iso A B
Iso.fun biInvEquiv→Iso-left = fun
Iso.inv biInvEquiv→Iso-left = invl
Iso.rightInv biInvEquiv→Iso-left = invl-rightInv
Iso.leftInv biInvEquiv→Iso-left = invl-leftInv
biInvEquiv→Equiv-right biInvEquiv→Equiv-left : A ≃ B
biInvEquiv→Equiv-right = fun , isoToIsEquiv biInvEquiv→Iso-right
biInvEquiv→Equiv-left = fun , isoToIsEquiv biInvEquiv→Iso-left
-- since Iso.rightInv ends up getting modified during iso→HAEquiv, in some sense biInvEquiv→Iso-left
-- is the most natural choice for forming a HAEquiv from a BiInvEquiv
biInvEquiv→HAEquiv : HAEquiv A B
biInvEquiv→HAEquiv = iso→HAEquiv biInvEquiv→Iso-left
module _ {ℓ} {A B : Type ℓ} (i : Iso A B) where
open Iso i
iso→BiInvEquiv : BiInvEquiv A B
BiInvEquiv.fun iso→BiInvEquiv = fun
BiInvEquiv.invr iso→BiInvEquiv = inv
BiInvEquiv.invr-rightInv iso→BiInvEquiv = rightInv
BiInvEquiv.invl iso→BiInvEquiv = inv
BiInvEquiv.invl-leftInv iso→BiInvEquiv = leftInv
|
{
"alphanum_fraction": 0.6823194593,
"avg_line_length": 33.0705882353,
"ext": "agda",
"hexsha": "082ad5be861c82063fca67db3b99b751b895f101",
"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": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/Foundations/BiInvEquiv.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"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": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/Foundations/BiInvEquiv.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/Foundations/BiInvEquiv.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1052,
"size": 2811
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lists where every consecutative pair of elements is related.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.Linked {a} {A : Set a} where
open import Data.List.Base using (List; []; _∷_)
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
open import Data.Product as Prod using (_,_; _×_; uncurry; <_,_>)
open import Function using (id; _∘_)
open import Level using (Level; _⊔_)
open import Relation.Binary as B using (Rel; _⇒_)
open import Relation.Binary.Construct.Intersection renaming (_∩_ to _∩ᵇ_)
open import Relation.Binary.PropositionalEquality
open import Relation.Unary as U renaming (_∩_ to _∩ᵘ_) hiding (_⇒_)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Decidable as Dec using (map′)
open import Relation.Nullary.Product using (_×-dec_)
private
variable
p q r ℓ : Level
------------------------------------------------------------------------
-- Definition
-- Linked R xs means that every consecutative pair of elements
-- in xs is a member of relation R.
infixr 5 _∷_
data Linked (R : Rel A ℓ) : List A → Set (a ⊔ ℓ) where
[] : Linked R []
[-] : ∀ {x} → Linked R (x ∷ [])
_∷_ : ∀ {x y xs} → R x y → Linked R (y ∷ xs) → Linked R (x ∷ y ∷ xs)
------------------------------------------------------------------------
-- Operations
module _ {R : Rel A p} {x y xs} where
head : Linked R (x ∷ y ∷ xs) → R x y
head (Rxy ∷ Rxs) = Rxy
tail : Linked R (x ∷ y ∷ xs) → Linked R (y ∷ xs)
tail (Rxy ∷ Rxs) = Rxs
module _ {R : Rel A p} {S : Rel A q} where
map : R ⇒ S → Linked R ⊆ Linked S
map R⇒S [] = []
map R⇒S [-] = [-]
map R⇒S (x~xs ∷ pxs) = R⇒S x~xs ∷ map R⇒S pxs
module _ {P : Rel A p} {Q : Rel A q} {R : Rel A r} where
zipWith : P ∩ᵇ Q ⇒ R → Linked P ∩ᵘ Linked Q ⊆ Linked R
zipWith f ([] , []) = []
zipWith f ([-] , [-]) = [-]
zipWith f (px ∷ pxs , qx ∷ qxs) = f (px , qx) ∷ zipWith f (pxs , qxs)
unzipWith : R ⇒ P ∩ᵇ Q → Linked R ⊆ Linked P ∩ᵘ Linked Q
unzipWith f [] = [] , []
unzipWith f [-] = [-] , [-]
unzipWith f (rx ∷ rxs) = Prod.zip _∷_ _∷_ (f rx) (unzipWith f rxs)
module _ {P : Rel A p} {Q : Rel A q} where
zip : Linked P ∩ᵘ Linked Q ⊆ Linked (P ∩ᵇ Q)
zip = zipWith id
unzip : Linked (P ∩ᵇ Q) ⊆ Linked P ∩ᵘ Linked Q
unzip = unzipWith id
------------------------------------------------------------------------
-- Properties of predicates preserved by Linked
module _ {R : Rel A ℓ} where
linked? : B.Decidable R → U.Decidable (Linked R)
linked? R? [] = yes []
linked? R? (x ∷ []) = yes [-]
linked? R? (x ∷ y ∷ xs) =
map′ (uncurry _∷_) < head , tail > (R? x y ×-dec linked? R? (y ∷ xs))
irrelevant : B.Irrelevant R → U.Irrelevant (Linked R)
irrelevant irr [] [] = refl
irrelevant irr [-] [-] = refl
irrelevant irr (px₁ ∷ pxs₁) (px₂ ∷ pxs₂) =
cong₂ _∷_ (irr px₁ px₂) (irrelevant irr pxs₁ pxs₂)
satisfiable : U.Satisfiable (Linked R)
satisfiable = [] , []
|
{
"alphanum_fraction": 0.5151796778,
"avg_line_length": 32.9387755102,
"ext": "agda",
"hexsha": "173de514b7166cf5626bd75c43b16dd514dab80f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Relation/Unary/Linked.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Unary/Linked.agda",
"max_line_length": 73,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Unary/Linked.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": 1054,
"size": 3228
}
|
{-# OPTIONS --cubical --safe --postfix-projections #-}
-- This file contains an implementation of the stack-based compiler for Hutton's
-- razor, as from:
--
-- P. Bahr and G. Hutton, “Calculating correct compilers,” Journal of
-- Functional Programming, vol. 25, no. e14, Sep. 2015,
-- doi: 10.1017/S0956796815000180.
--
-- The compiler is total and the evaluator is stack-safe, and furthermore we have
-- proven a full isomorphism between the code representation and the AST.
module Data.Dyck.Prog where
open import Prelude
open import Data.Nat using (_+_)
private variable n : ℕ
--------------------------------------------------------------------------------
-- We have 2 forms that we want to convert between: an AST and a flat code.
--------------------------------------------------------------------------------
data Expr : Type where
[_] : ℕ → Expr
_⊕_ : Expr → Expr → Expr
--------------------------------------------------------------------------------
-- We do the conversion with cayley forms of the dyck monoids
--------------------------------------------------------------------------------
⟨_⟩_↝_ : (ℕ → Type) → ℕ → ℕ → Type
⟨ C ⟩ n ↝ m = ∀ {i} → C (n + i) → C (m + i)
--------------------------------------------------------------------------------
-- An encoding of an AST
--------------------------------------------------------------------------------
data Code : ℕ → Type where
HALT : Code 1
PUSH : ℕ → ⟨ Code ⟩ 1 ↝ 0
ADD : ⟨ Code ⟩ 1 ↝ 2
--------------------------------------------------------------------------------
-- We will need a stack (a snoc-list)
--------------------------------------------------------------------------------
Stack : Type → ℕ → Type
Stack A zero = ⊤
Stack A (suc n) = Stack A n × A
infixl 5 _∷_
pattern _∷_ xs x = xs , x
foldl : (P : ℕ → Type) → (A → ⟨ P ⟩ 1 ↝ 0) → Stack A n → P n → P zero
foldl {n = zero} P f tt = id
foldl {n = suc n} P f (xs ∷ x) = foldl P f xs ∘ f x
private variable st : Stack Expr n
--------------------------------------------------------------------------------
-- Conversion to and from code
--------------------------------------------------------------------------------
-- Code n → ⟨ Stack Expr ⟩ n ↝ 1
code→expr⊙ : Code n → Stack Expr n → Expr
code→expr⊙ HALT (tt ∷ e) = e
code→expr⊙ (PUSH v is) st = code→expr⊙ is (st ∷ [ v ])
code→expr⊙ (ADD is) (st ∷ xs ∷ ys) = code→expr⊙ is (st ∷ xs ⊕ ys)
code→expr : Code 0 → Expr
code→expr ds = code→expr⊙ ds tt
expr→code⊙ : Expr → ⟨ Code ⟩ 1 ↝ 0
expr→code⊙ [ x ] = PUSH x
expr→code⊙ (xs ⊕ ys) = expr→code⊙ xs ∘ expr→code⊙ ys ∘ ADD
expr→code : Expr → Code 0
expr→code xs = expr→code⊙ xs HALT
--------------------------------------------------------------------------------
-- Proof of isomorphism
--------------------------------------------------------------------------------
expr→code→expr⊙ : {is : Code (1 + n)} (e : Expr) →
code→expr⊙ (expr→code⊙ e is) st ≡ code→expr⊙ is (st ∷ e)
expr→code→expr⊙ [ x ] = refl
expr→code→expr⊙ (xs ⊕ ys) = expr→code→expr⊙ xs ; expr→code→expr⊙ ys
code→expr→code⊙ : (is : Code n) →
expr→code (code→expr⊙ is st) ≡ foldl Code expr→code⊙ st is
code→expr→code⊙ HALT = refl
code→expr→code⊙ (PUSH i is) = code→expr→code⊙ is
code→expr→code⊙ (ADD is) = code→expr→code⊙ is
prog-iso : Code 0 ⇔ Expr
prog-iso .fun = code→expr
prog-iso .inv = expr→code
prog-iso .rightInv = expr→code→expr⊙
prog-iso .leftInv = code→expr→code⊙
|
{
"alphanum_fraction": 0.4383600917,
"avg_line_length": 34.5346534653,
"ext": "agda",
"hexsha": "17143778f05fc5cd421a873c7a906d247ffacaed",
"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/Dyck/Prog.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/Dyck/Prog.agda",
"max_line_length": 81,
"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/Dyck/Prog.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": 1028,
"size": 3488
}
|
open import Agda.Builtin.Equality
postulate
foo : (A : Set) → A ≡ A
helper : {W : Set} (A : Set) → W → W ≡ A → (A → Set) → Set
helper A w refl f = f w
bar : (A : Set) → A → Set
bar A a = let A≡A = foo A in helper A a (foo A) {!!} -- A≡A : A ≡ A
baz : (A : Set) → A → Set
baz A a = let A≡A = foo A in helper A a (foo A) λ a' → {!!} -- A≡A : a ≡ a
f : (A : Set) → A → Set → Set
f A x = let y = x in λ B → {!!} -- y : x
|
{
"alphanum_fraction": 0.4705882353,
"avg_line_length": 23.6111111111,
"ext": "agda",
"hexsha": "00a376e8b590918688fd9983c237b1e2350ba224",
"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/Issue1878.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/Issue1878.agda",
"max_line_length": 74,
"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/Issue1878.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": 191,
"size": 425
}
|
module cedille-syntax where
open import lib
open import ctxt
open import syntax-util
open import general-util
open import is-free
open import cedille-types
-- App, AppTp
infixl 10 _`_ _-_ _·_
-- Pattern and constructor
pattern _`_ t t' = App t NotErased t'
pattern _-_ t t' = App t Erased t'
pattern _·_ t T = AppTp t T
-- Beta
infix 9 β<_> β[_] β<_>[_] `β<_> `β[_] `β<_>[_]
pattern β = Beta _ NoTerm NoTerm
pattern β<_> t = Beta _ (SomeTerm t _) NoTerm
pattern β[_] t = Beta _ NoTerm (SomeTerm t _)
pattern β<_>[_] t t' = Beta _ (SomeTerm t _) (SomeTerm t' _)
`β = Beta pi-gen NoTerm NoTerm
`β<_> = λ t → Beta pi-gen (SomeTerm t pi-gen) NoTerm
`β[_] = λ t → Beta pi-gen NoTerm (SomeTerm t pi-gen)
`β<_>[_] = λ t t' → Beta pi-gen (SomeTerm t pi-gen) (SomeTerm t' pi-gen)
-- Chi
infixr 8 χ-_ χ_-_ `χ-_ `χ_-_
pattern χ-_ t = Chi _ NoType t
pattern χ_-_ T t = Chi _ (SomeType T) t
`χ-_ = Chi pi-gen NoType
`χ_-_ = λ T t → Chi pi-gen (SomeType T) t
-- Delta
infixr 8 δ-_ δ_-_ `δ-_ `δ_-_
pattern δ-_ t = Delta _ NoType t
pattern δ_-_ T t = Delta _ (SomeType T) t
`δ-_ = Delta pi-gen NoType
`δ_-_ = λ T t → Delta pi-gen (SomeType T) t
-- Epsilon
infixr 8 ε_ εl_ εr_ ε-_ εl-_ εr-_ `ε_ `εl_ `εr_ `ε-_ `εl-_ `εr-_
pattern ε_ t = Epsilon _ Both ff t
pattern εl_ t = Epsilon _ Left ff t
pattern εr_ t = Epsilon _ Right ff t
pattern ε-_ t = Epsilon _ Both tt t
pattern εl-_ t = Epsilon _ Left tt t
pattern εr-_ t = Epsilon _ Right tt t
`ε_ = Epsilon pi-gen Both ff
`εl_ = Epsilon pi-gen Left ff
`εr_ = Epsilon pi-gen Right ff
`ε-_ = Epsilon pi-gen Both tt
`εl-_ = Epsilon pi-gen Left tt
`εr-_ = Epsilon pi-gen Right tt
-- Hole
pattern ● = Hole _
`● = Hole pi-gen
-- IotaPair
pattern [_`,_] t₁ t₂ = IotaPair _ t₁ t₂ NoGuide _
pattern [_`,_*_₊_] t₁ t₂ x T = IotaPair _ t₁ t₂ (Guide _ x T) _ -- "₊" = "\_+"
`[_`,_] = λ t₁ t₂ → IotaPair pi-gen t₁ t₂ NoGuide pi-gen
`[_`,_*_₊_] = λ t₁ t₂ x T → IotaPair pi-gen t₁ t₂ (Guide pi-gen x T) pi-gen
-- IotaProj
infixl 5 _₊1 _₊2 _₊#_ _`₊1 _`₊2 _`₊#_
pattern _₊1 t = IotaProj t "1" _
pattern _₊2 t = IotaProj t "2" _
pattern _₊#_ t n = IotaProj t n _
_`₊1 = λ t → IotaProj t "1" pi-gen
_`₊2 = λ t → IotaProj t "2" pi-gen
_`₊#_ = λ t n → IotaProj t n pi-gen
-- Lam
infixr 4 λ`_₊_ λ`_:ₜ_₊_ λ`_:ₖ_₊_ Λ_₊_ Λ_:ₜ_₊_ Λ_:ₖ_₊_ `λ_₊_ `λ_:ₜ_₊_ `λ_:ₖ_₊_ `Λ_₊_ `Λ_:ₜ_₊_ `Λ_:ₖ_₊_
pattern λ`_₊_ x t = Lam _ NotErased _ x NoClass t
pattern λ`_:ₜ_₊_ x T t = Lam _ NotErased _ x (SomeClass (Tkt T)) t
pattern λ`_:ₖ_₊_ x k t = Lam _ NotErased _ x (SomeClass (Tkk k)) t
pattern Λ_₊_ x t = Lam _ Erased _ x NoClass t
pattern Λ_:ₜ_₊_ x T t = Lam _ Erased _ x (SomeClass (Tkt T)) t
pattern Λ_:ₖ_₊_ x k t = Lam _ Erased _ x (SomeClass (Tkk k)) t
`λ_₊_ = λ x t → Lam pi-gen NotErased pi-gen x NoClass t
`λ_:ₜ_₊_ = λ x T t → Lam pi-gen NotErased pi-gen x (SomeClass (Tkt T)) t
`λ_:ₖ_₊_ = λ x k t → Lam pi-gen NotErased pi-gen x (SomeClass (Tkk k)) t
`Λ_₊_ = λ x t → Lam pi-gen Erased pi-gen x NoClass t
`Λ_:ₜ_₊_ = λ x T t → Lam pi-gen Erased pi-gen x (SomeClass (Tkt T)) t
`Λ_:ₖ_₊_ = λ x k t → Lam pi-gen Erased pi-gen x (SomeClass (Tkk k)) t
-- Let
infixr 8 [_`=_]-_ [_:ₜ_`=_]-_ [_:ₖ_`=_]-_ -[_`=_]-_ -[_:ₜ_`=_]-_ -[_:ₖ_`=_]-_ `[_`=_]-_ `[_:ₜ_`=_]-_ `[_:ₖ_`=_]-_ `-[_`=_]-_ `-[_:ₜ_`=_]-_ `-[_:ₖ_`=_]-_
pattern [_`=_]-_ x t t' = Let _ NotErased (DefTerm _ x NoType t _) t'
pattern [_:ₜ_`=_]-_ x T t t' = Let _ NotErased (DefTerm _ x (SomeType T) t _) t'
pattern [_:ₖ_`=_]-_ x k T t' = Let _ NotErased (DefType _ x k T _) t'
pattern -[_`=_]-_ x t t' = Let _ Erased (DefTerm _ x NoType t _) t'
pattern -[_:ₜ_`=_]-_ x T t t' = Let _ Erased (DefTerm _ x (SomeType T) t _) t'
pattern -[_:ₖ_`=_]-_ x k T t' = Let _ Erased (DefType _ x k T _) t'
`[_`=_]-_ = λ x t t' → Let pi-gen NotErased (DefTerm pi-gen x NoType t) t'
`[_:ₜ_`=_]-_ = λ x T t t' → Let pi-gen NotErased (DefTerm pi-gen x (SomeType T) t) t'
`[_:ₖ_`=_]-_ = λ x k T t' → Let pi-gen NotErased (DefType pi-gen x k T) t'
`-[_`=_]-_ = λ x t t' → Let pi-gen Erased (DefTerm pi-gen x NoType t) t'
`-[_:ₜ_`=_]-_ = λ x T t t' → Let pi-gen Erased (DefTerm pi-gen x (SomeType T) t) t'
`-[_:ₖ_`=_]-_ = λ x k T t' → Let pi-gen Erased (DefType pi-gen x k T) t'
-- Open
infixr 8 open`_-_ `open_-_ close`_-_ `close_-_
pattern open`_-_ x t = Open _ OpacTrans _ x t
pattern close`_-_ x t = Open _ OpacOpaque _ x t
`open_-_ = Open pi-gen OpacTrans pi-gen
`close_-_ = Open pi-gen OpacOpaque pi-gen
--Parens
infix 4 ⦅_⦆ `⦅_⦆
pattern ⦅_⦆ t = Parens _ t _
`⦅_⦆ = λ t → Parens pi-gen t pi-gen
-- Phi
infix 8 φ_-_[_] `φ_-_[_]
pattern φ_-_[_] eq t₁ t₂ = Phi _ eq t₁ t₂ _
`φ_-_[_] = λ eq t₁ t₂ → Phi pi-gen eq t₁ t₂ pi-gen
-- Rho
infixr 8 ρ_-_ ρ<_>_-_ ρ_*_₊_-_ ρ<_>_*_₊_-_ ρ+_-_ ρ+<_>_-_ ρ+_*_₊_-_ ρ+<_>_*_₊_-_ `ρ_-_ `ρ<_>_-_ `ρ_*_₊_-_ `ρ<_>_*_₊_-_ `ρ+_-_ `ρ+<_>_-_ `ρ+_*_₊_-_ `ρ+<_>_*_₊_-_
pattern ρ_-_ t t' = Rho _ ff NoNums t NoGuide t'
pattern ρ<_>_-_ ns t t' = Rho _ ff (SomeNums ns) t NoGuide t'
pattern ρ_*_₊_-_ t x T t' = Rho _ ff NoNums t (Guide _ x T) t'
pattern ρ<_>_*_₊_-_ ns t x T t' = Rho _ ff (SomeNums ns) t (Guide _ x T) t'
pattern ρ+_-_ t t' = Rho _ tt NoNums t NoGuide t'
pattern ρ+<_>_-_ ns t t' = Rho _ tt (SomeNums ns) t NoGuide t'
pattern ρ+_*_₊_-_ t x T t' = Rho _ tt NoNums t (Guide _ x T) t'
pattern ρ+<_>_*_₊_-_ ns t x T t' = Rho _ tt (SomeNums ns) t (Guide _ x T) t'
`ρ_-_ = λ t t' → Rho pi-gen ff NoNums t NoGuide t'
`ρ<_>_-_ = λ ns t t' → Rho pi-gen ff (SomeNums ns) t NoGuide t'
`ρ_*_₊_-_ = λ t x T t' → Rho pi-gen ff NoNums t (Guide pi-gen x T) t'
`ρ<_>_*_₊_-_ = λ ns t x T t' → Rho pi-gen ff (SomeNums ns) t (Guide pi-gen x T) t'
`ρ+_-_ = λ t t' → Rho pi-gen tt NoNums t NoGuide t'
`ρ+<_>_-_ = λ ns t t' → Rho pi-gen tt (SomeNums ns) t NoGuide t'
`ρ+_*_₊_-_ = λ t x T t' → Rho pi-gen tt NoNums t (Guide pi-gen x T) t'
`ρ+<_>_*_₊_-_ = λ ns t x T t' → Rho pi-gen tt (SomeNums ns) t (Guide pi-gen x T) t'
-- Sigma
infixr 9 ς_ `ς_
pattern ς_ t = Sigma _ t
`ς_ = Sigma pi-gen
-- Theta
infix 9 θ_`_ θ+_`_ θ<_>_`_ `θ_`_ `θ+_`_ `θ<_>_`_
pattern θ_`_ t ts = Theta _ Abstract t ts
pattern θ+_`_ t ts = Theta _ AbstractEq t ts
pattern θ<_>_`_ vs t ts = Theta _ (AbstractVars vs) t ts
`θ_`_ = λ t ts → Theta pi-gen Abstract t ts
`θ+_`_ = λ t ts → Theta pi-gen AbstractEq t ts
`θ<_>_`_ = λ vs t ts → Theta pi-gen (AbstractVars vs) t ts
-- Mu
infix 9 μ_₊_[_] μ_₊_*_[_] `μ_₊_[_] `μ_₊_*_[_]
pattern μ_₊_[_] x t ms = Mu _ _ x t NoType _ ms _
pattern μ_₊_*_[_] x t T ms = Mu _ _ x t (SomeType T) _ ms _
`μ_₊_[_] = λ x t ms → Mu pi-gen pi-gen x t NoType pi-gen ms pi-gen
`μ_₊_*_[_] = λ x t T ms → Mu pi-gen pi-gen x t (SomeType T) pi-gen ms pi-gen
-- Mu'
infix 9 μ'_[_] μ'_*_[_] μ'<_>_[_] μ'<_>_*_[_] `μ'_[_] `μ'_*_[_] `μ'_[_] `μ'_*_[_]
pattern μ'_[_] t ms = Mu' _ NoTerm t NoType _ ms _
pattern μ'_*_[_] t T ms = Mu' _ NoTerm t (SomeType T) _ ms _
pattern μ'<_>_[_] t t' ms = Mu' _ (SomeTerm t) t' NoType _ ms _
pattern μ'<_>_*_[_] t t' T ms = Mu' _ (SomeTerm t) t' (SomeType T) _ ms _
`μ'_[_] = λ t ms → Mu' pi-gen NoTerm t NoType pi-gen ms pi-gen
`μ'_*_[_] = λ t T ms → Mu' pi-gen NoTerm t (SomeType T) pi-gen ms pi-gen
`μ'<_>_[_] = λ t t' ms → Mu' pi-gen (SomeTerm t pi-gen) t' NoType pi-gen ms pi-gen
`μ'<_>_*_[_] = λ t t' T ms → Mu' pi-gen (SomeTerm t pi-gen) t' (SomeType T) pi-gen ms pi-gen
-- Var
infixr 11 vₓ_ `vₓ_
pattern vₓ_ x = Var _ x
`vₓ_ = Var pi-gen
-- Abs
infixr 5 ∀`_:ₜ_₊_ ∀`_:ₖ_₊_ Π_:ₜ_₊_ Π_:ₖ_₊_ `∀_:ₜ_₊_ `∀_:ₖ_₊_ `Π_:ₜ_₊_ `Π_:ₖ_₊_
pattern ∀`_:ₜ_₊_ x T T' = Abs _ All _ x (Tkt T) T'
pattern ∀`_:ₖ_₊_ x k T = Abs _ All _ x (Tkk k) T
pattern Π_:ₜ_₊_ x T T' = Abs _ Pi _ x (Tkt T) T'
pattern Π_:ₖ_₊_ x k T = Abs _ Pi _ x (Tkk k) T
`∀_:ₜ_₊_ = λ x T T' → Abs pi-gen All pi-gen x (Tkt T) T'
`∀_:ₖ_₊_ = λ x k T → Abs pi-gen All pi-gen x (Tkk k) T
`Π_:ₜ_₊_ = λ x T T' → Abs pi-gen Pi pi-gen x (Tkt T) T'
`Π_:ₖ_₊_ = λ x k T → Abs pi-gen Pi pi-gen x (Tkk k) T
-- Iota
infix 4 ι_:ₜ_₊_ `ι_:ₜ_₊_
pattern ι_:ₜ_₊_ x T T' = Iota _ _ x T T'
`ι_:ₜ_₊_ = Iota pi-gen pi-gen
-- Lft
infix 4 ↑_₊_:ₗ_ `↑_₊_:ₗ_
pattern ↑_₊_:ₗ_ X t lT = Lft _ _ X t lT
`↑_₊_:ₗ_ = Lft pi-gen pi-gen
-- NoSpans
infix 4 [^_^] `[^_^]
pattern [^_^] T = NoSpans T _
`[^_^] = λ T → NoSpans T pi-gen
-- TpLet
infixr 5 [_`=_]ₜ-_ [_:ₜ_`=_]ₜ-_ [_:ₖ_`=_]ₜ-_ `[_`=_]ₜ-_ `[_:ₜ_`=_]ₜ-_ `[_:ₖ_`=_]ₜ-_
pattern [_`=_]ₜ-_ x t t' = TpLet _ (DefTerm _ x NoType t _) t'
pattern [_:ₜ_`=_]ₜ-_ x T t t' = TpLet _ (DefTerm _ x (SomeType T) t _) t'
pattern [_:ₖ_`=_]ₜ-_ x k T t' = TpLet _ (DefType _ x k T _) t'
`[_`=_]ₜ-_ = λ x t t' → TpLet pi-gen (DefTerm pi-gen x NoType t) t'
`[_:ₜ_`=_]ₜ-_ = λ x T t t' → TpLet pi-gen (DefTerm pi-gen x (SomeType T) t) t'
`[_:ₖ_`=_]ₜ-_ = λ x k T t' → TpLet pi-gen (DefType pi-gen x k T) t'
-- TpApp, TpAppt
infixl 10 _·ₜ_ _`ₜ_
-- Pattern and constructor
pattern _·ₜ_ T T' = TpApp T T'
pattern _`ₜ_ T t = TpAppt T t
-- TpArrow
infixr 5 _➔_ _➾_ -- "➔" = "\r" (↕ 5, ↔ 1), "➾" = "\r" (↕ 7, ↔ 8)
pattern _➔_ T T' = TpArrow T NotErased T'
pattern _➾_ T T' = TpArrow T Erased T'
-- TpEq
infix 4 [_≃_] `[_≃_]
pattern [_≃_] t₁ t₂ = TpEq _ t₁ t₂ _
`[_≃_] = λ t₁ t₂ → TpEq pi-gen t₁ t₂ pi-gen
-- TpHole
pattern ●ₜ = TpHole _
`●ₜ = TpHole pi-gen
-- TpLambda
infixr 4 λₜ_:ₜ_₊_ λₜ_:ₖ_₊_ `λₜ_:ₜ_₊_ `λₜ_:ₖ_₊_
pattern λₜ_:ₜ_₊_ x T T' = TpLambda _ _ x (Tkt T) T'
pattern λₜ_:ₖ_₊_ x k T = TpLambda _ _ x (Tkk k) T
`λₜ_:ₜ_₊_ = λ x T T' → TpLambda pi-gen pi-gen x (Tkt T) T'
`λₜ_:ₖ_₊_ = λ x k T → TpLambda pi-gen pi-gen x (Tkk k) T
-- TpParens
infix 4 ⦅_⦆ₜ `⦅_⦆ₜ
pattern ⦅_⦆ₜ T = TpParens _ T _
`⦅_⦆ₜ = λ T → TpParens pi-gen T pi-gen
-- TpVar
infix 11 Vₓ_ `Vₓ_
pattern Vₓ_ x = TpVar _ x
`Vₓ_ = TpVar pi-gen
-- KndArrow : kind → kind → kind
-- KndParens : posinfo → kind → posinfo → kind
infix 4 ⦅_⦆ₖ `⦅_⦆ₖ
pattern ⦅_⦆ₖ k = KndParens _ k _
`⦅_⦆ₖ = λ k → KndParens pi-gen k pi-gen
-- KndPi : posinfo → posinfo → bvar → tk → kind → kind
-- KndTpArrow : type → kind → kind
-- KndVar
infix 11 κ_`_ `κ_`_
pattern κ_`_ x as = KndVar _ x as
`κ_`_ = KndVar pi-gen
-- Star
pattern ★ = Star _
`★ = Star pi-gen
|
{
"alphanum_fraction": 0.6017043725,
"avg_line_length": 35.3297491039,
"ext": "agda",
"hexsha": "ec75aba090be5957368b4c613d7e1185a50452b0",
"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": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CarlOlson/cedille",
"max_forks_repo_path": "src/cedille-syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"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": "CarlOlson/cedille",
"max_issues_repo_path": "src/cedille-syntax.agda",
"max_line_length": 160,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CarlOlson/cedille",
"max_stars_repo_path": "src/cedille-syntax.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4784,
"size": 9857
}
|
{-# OPTIONS --without-K #-}
module mini-quine where
open import common
infixl 2 _▻_
infixl 3 _‘’_
infixr 1 _‘→’_
infixl 3 _‘’ₐ_
infixl 3 _w‘‘’’ₐ_
infixr 2 _‘∘’_
mutual
data Context : Set where
ε : Context
_▻_ : (Γ : Context) → Type Γ → Context
data Type : Context → Set where
W : ∀ {Γ A} → Type Γ → Type (Γ ▻ A)
W1 : ∀ {Γ A B} → Type (Γ ▻ B) → Type (Γ ▻ A ▻ (W {Γ = Γ} {A = A} B))
_‘’_ : ∀ {Γ A} → Type (Γ ▻ A) → Term {Γ} A → Type Γ
‘Typeε’ : ∀ {Γ} → Type Γ
‘□’ : ∀ {Γ} → Type (Γ ▻ ‘Typeε’)
_‘→’_ : ∀ {Γ} → Type Γ → Type Γ → Type Γ
Quine : Type (ε ▻ ‘Typeε’) → Type ε
‘⊤’ : ∀ {Γ} → Type Γ
‘⊥’ : ∀ {Γ} → Type Γ
data Term : {Γ : Context} → Type Γ → Set where
⌜_⌝ : ∀ {Γ} → Type ε → Term {Γ} ‘Typeε’
⌜_⌝t : ∀ {Γ T} → Term {ε} T → Term {Γ} (‘□’ ‘’ ⌜ T ⌝)
‘⌜‘VAR₀’⌝t’ : ∀ {T} → Term {ε ▻ ‘□’ ‘’ ⌜ T ⌝} (W (‘□’ ‘’ ⌜ ‘□’ ‘’ ⌜ T ⌝ ⌝))
‘λ∙’ : ∀ {Γ A B} → Term {Γ ▻ A} (W B) → Term {Γ} (A ‘→’ B)
‘VAR₀’ : ∀ {Γ T} → Term {Γ ▻ T} (W T)
_‘’ₐ_ : ∀ {Γ A B} → Term {Γ} (A ‘→’ B) → Term {Γ} A → Term {Γ} B
quine→ : ∀ {φ} → Term {ε} (Quine φ ‘→’ φ ‘’ ⌜ Quine φ ⌝)
quine← : ∀ {φ} → Term {ε} (φ ‘’ ⌜ Quine φ ⌝ ‘→’ Quine φ)
‘tt’ : ∀ {Γ} → Term {Γ} ‘⊤’
→SW1SV→W : ∀ {Γ T X A B} {x : Term X}
→ Term {Γ} (T ‘→’ (W1 A ‘’ ‘VAR₀’ ‘→’ W B) ‘’ x)
→ Term {Γ} (T ‘→’ A ‘’ x ‘→’ B)
←SW1SV→W : ∀ {Γ T X A B} {x : Term X}
→ Term {Γ} ((W1 A ‘’ ‘VAR₀’ ‘→’ W B) ‘’ x ‘→’ T)
→ Term {Γ} ((A ‘’ x ‘→’ B) ‘→’ T)
w : ∀ {Γ A T} → Term {Γ} A → Term {Γ ▻ T} (W A)
w→ : ∀ {Γ A B X} → Term {Γ} (A ‘→’ B) → Term {Γ ▻ X} (W A ‘→’ W B)
_‘∘’_ : ∀ {Γ A B C} → Term {Γ} (B ‘→’ C) → Term {Γ} (A ‘→’ B) → Term {Γ} (A ‘→’ C)
_w‘‘’’ₐ_ : ∀ {A B T} → Term {ε ▻ T} (W (‘□’ ‘’ ⌜ A ‘→’ B ⌝)) → Term {ε ▻ T} (W (‘□’ ‘’ ⌜ A ⌝)) → Term {ε ▻ T} (W (‘□’ ‘’ ⌜ B ⌝))
□ : Type ε → Set _
□ = Term {ε}
max-level : Level
max-level = lzero
mutual
Context⇓ : (Γ : Context) → Set (lsuc max-level)
Context⇓ ε = ⊤
Context⇓ (Γ ▻ T) = Σ (Context⇓ Γ) (Type⇓ {Γ} T)
Type⇓ : {Γ : Context} → Type Γ → Context⇓ Γ → Set max-level
Type⇓ (W T) Γ⇓ = Type⇓ T (Σ.proj₁ Γ⇓)
Type⇓ (W1 T) Γ⇓ = Type⇓ T ((Σ.proj₁ (Σ.proj₁ Γ⇓)) , (Σ.proj₂ Γ⇓))
Type⇓ (T ‘’ x) Γ⇓ = Type⇓ T (Γ⇓ , Term⇓ x Γ⇓)
Type⇓ ‘Typeε’ Γ⇓ = Lifted (Type ε)
Type⇓ ‘□’ Γ⇓ = Lifted (Term {ε} (lower (Σ.proj₂ Γ⇓)))
Type⇓ (A ‘→’ B) Γ⇓ = Type⇓ A Γ⇓ → Type⇓ B Γ⇓
Type⇓ ‘⊤’ Γ⇓ = ⊤
Type⇓ ‘⊥’ Γ⇓ = ⊥
Type⇓ (Quine φ) Γ⇓ = Type⇓ φ (Γ⇓ , (lift (Quine φ)))
Term⇓ : ∀ {Γ : Context} {T : Type Γ} → Term T → (Γ⇓ : Context⇓ Γ) → Type⇓ T Γ⇓
Term⇓ ⌜ x ⌝ Γ⇓ = lift x
Term⇓ ⌜ x ⌝t Γ⇓ = lift x
Term⇓ ‘⌜‘VAR₀’⌝t’ Γ⇓ = lift ⌜ (lower (Σ.proj₂ Γ⇓)) ⌝t
Term⇓ (f ‘’ₐ x) Γ⇓ = Term⇓ f Γ⇓ (Term⇓ x Γ⇓)
Term⇓ ‘tt’ Γ⇓ = tt
Term⇓ (quine→ {φ}) Γ⇓ x = x
Term⇓ (quine← {φ}) Γ⇓ x = x
Term⇓ (‘λ∙’ f) Γ⇓ x = Term⇓ f (Γ⇓ , x)
Term⇓ ‘VAR₀’ Γ⇓ = Σ.proj₂ Γ⇓
Term⇓ (←SW1SV→W f) = Term⇓ f
Term⇓ (→SW1SV→W f) = Term⇓ f
Term⇓ (w x) Γ⇓ = Term⇓ x (Σ.proj₁ Γ⇓)
Term⇓ (w→ f) Γ⇓ = Term⇓ f (Σ.proj₁ Γ⇓)
Term⇓ (g ‘∘’ f) Γ⇓ x = Term⇓ g Γ⇓ (Term⇓ f Γ⇓ x)
Term⇓ (f w‘‘’’ₐ x) Γ⇓ = lift (lower (Term⇓ f Γ⇓) ‘’ₐ lower (Term⇓ x Γ⇓))
module inner (‘X’ : Type ε) (‘f’ : Term {ε} (‘□’ ‘’ ⌜ ‘X’ ⌝ ‘→’ ‘X’)) where
‘H’ : Type ε
‘H’ = Quine (W1 ‘□’ ‘’ ‘VAR₀’ ‘→’ W ‘X’)
‘toH’ : □ ((‘□’ ‘’ ⌜ ‘H’ ⌝ ‘→’ ‘X’) ‘→’ ‘H’)
‘toH’ = ←SW1SV→W quine←
‘fromH’ : □ (‘H’ ‘→’ (‘□’ ‘’ ⌜ ‘H’ ⌝ ‘→’ ‘X’))
‘fromH’ = →SW1SV→W quine→
‘□‘H’→□‘X’’ : □ (‘□’ ‘’ ⌜ ‘H’ ⌝ ‘→’ ‘□’ ‘’ ⌜ ‘X’ ⌝)
‘□‘H’→□‘X’’ = ‘λ∙’ (w ⌜ ‘fromH’ ⌝t w‘‘’’ₐ ‘VAR₀’ w‘‘’’ₐ ‘⌜‘VAR₀’⌝t’)
‘h’ : Term ‘H’
‘h’ = ‘toH’ ‘’ₐ (‘f’ ‘∘’ ‘□‘H’→□‘X’’)
Lӧb : □ ‘X’
Lӧb = ‘fromH’ ‘’ₐ ‘h’ ‘’ₐ ⌜ ‘h’ ⌝t
Lӧb : ∀ {X} → Term {ε} (‘□’ ‘’ ⌜ X ⌝ ‘→’ X) → Term {ε} X
Lӧb {X} f = inner.Lӧb X f
⌞_⌟ : Type ε → Set _
⌞ T ⌟ = Type⇓ T tt
‘¬’_ : ∀ {Γ} → Type Γ → Type Γ
‘¬’ T = T ‘→’ ‘⊥’
lӧb : ∀ {‘X’} → □ (‘□’ ‘’ ⌜ ‘X’ ⌝ ‘→’ ‘X’) → ⌞ ‘X’ ⌟
lӧb f = Term⇓ (Lӧb f) tt
incompleteness : ¬ □ (‘¬’ (‘□’ ‘’ ⌜ ‘⊥’ ⌝))
incompleteness = lӧb
soundness : ¬ □ ‘⊥’
soundness x = Term⇓ x tt
non-emptyness : Σ (Type ε) (λ T → □ T)
non-emptyness = ‘⊤’ , ‘tt’
|
{
"alphanum_fraction": 0.3990747504,
"avg_line_length": 32.0859375,
"ext": "agda",
"hexsha": "4cef822d255cefe541075e9e560a9ced5f36ead0",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z",
"max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JasonGross/lob",
"max_forks_repo_path": "internal/mini-quine.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JasonGross/lob",
"max_issues_repo_path": "internal/mini-quine.agda",
"max_line_length": 132,
"max_stars_count": 19,
"max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JasonGross/lob",
"max_stars_repo_path": "internal/mini-quine.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z",
"num_tokens": 2593,
"size": 4107
}
|
------------------------------------------------------------------------
-- Types with decidable equality have unique identity proofs, and
-- related results
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
-- The part up to "decidable⇒set" follows a proof by Michael Hedberg
-- ("A coherence theorem for Martin-Löf's type theory", JFP 1998).
open import Equality
module Equality.Decidable-UIP
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open Derived-definitions-and-properties eq
open import Logical-equivalence using (module _⇔_)
open import H-level eq
open import Prelude
-- Weakly constant functions.
Constant : ∀ {a b} {A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b)
Constant f = ∀ x y → f x ≡ f y
-- Left inverses.
_Left-inverse-of_ : ∀ {a b} {A : Type a} {B : Type b} →
(B → A) → (A → B) → Type a
g Left-inverse-of f = ∀ x → g (f x) ≡ x
abstract
-- A set with a constant endofunction with a left inverse is a
-- proposition.
proposition : ∀ {a} {A : Type a} →
(f : ∃ λ (f : A → A) → Constant f) →
(∃ λ g → g Left-inverse-of (proj₁ f)) →
Is-proposition A
proposition (f , constant) (g , left-inverse) x y =
x ≡⟨ sym (left-inverse x) ⟩
g (f x) ≡⟨ cong g (constant x y) ⟩
g (f y) ≡⟨ left-inverse y ⟩∎
y ∎
-- Endofunction families on _≡_ always have left inverses.
left-inverse :
∀ {a} {A : Type a} (f : (x y : A) → x ≡ y → x ≡ y) →
∀ {x y} → ∃ λ g → g Left-inverse-of f x y
left-inverse {A = A} f {x} {y} =
(λ x≡y →
x ≡⟨ x≡y ⟩
y ≡⟨ sym (f y y (refl y)) ⟩∎
y ∎) ,
elim (λ {x y} x≡y → trans (f x y x≡y) (sym (f y y (refl y))) ≡ x≡y)
(λ _ → trans-symʳ _)
-- A type A is a set if there is a family of constant endofunctions
-- on _≡_ {A = A}.
constant⇒set :
∀ {a} {A : Type a} →
((x y : A) → ∃ λ (f : x ≡ y → x ≡ y) → Constant f) →
Is-set A
constant⇒set constant {x} {y} =
proposition (constant x y)
(left-inverse (λ x y → proj₁ $ constant x y))
-- If it is known whether or not a type is inhabited, then one can
-- define a constant endofunction for that type.
decidable⇒constant : ∀ {a} {A : Type a} → Dec A →
∃ λ (f : A → A) → Constant f
decidable⇒constant (yes x) = (const x , λ _ _ → refl x)
decidable⇒constant (no ¬x) = (id , λ _ → ⊥-elim ∘ ¬x)
-- Types with decidable equality are sets.
decidable⇒set : ∀ {a} {A : Type a} → Decidable-equality A → Is-set A
decidable⇒set dec =
constant⇒set (λ x y → decidable⇒constant (dec x y))
-- Non-dependent functions with propositional domains are constant.
propositional-domain⇒constant :
∀ {a b} {A : Type a} {B : Type b} →
Is-proposition A → (f : A → B) → Constant f
propositional-domain⇒constant A-prop f = λ x y →
cong f (A-prop x y)
-- If there is a propositional, reflexive relation on A, and related
-- elements are equal, then A is a set.
--
-- (The statement of this lemma is one part of the statement of
-- Theorem 7.2.2 in "Homotopy Type Theory: Univalent Foundations of
-- Mathematics" (first edition).)
propositional-identity⇒set :
∀ {a b} {A : Type a}
(B : A → A → Type b) →
(∀ x y → Is-proposition (B x y)) →
(∀ x → B x x) →
(∀ x y → B x y → x ≡ y) →
Is-set A
propositional-identity⇒set B B-prop B-refl f =
constant⇒set λ x y →
(λ eq → f x y (subst (B x) eq (B-refl x))) ,
(λ _ _ → propositional-domain⇒constant (B-prop x y) (f x y) _ _)
-- The function cong {x = x} {y = y} takes (weakly) constant
-- functions to constant functions.
--
-- This is Lemma 3.1 from van Doorn's "Constructing the
-- Propositional Truncation using Non-recursive HITs".
cong-preserves-Constant :
∀ {a b} {A : Type a} {B : Type b} {f : A → B} {x y : A} →
Constant f → Constant (cong {x = x} {y = y} f)
cong-preserves-Constant {f = f} {x = x} {y = y} c p q =
cong f p ≡⟨ lemma p ⟩
trans (sym (c x x)) (c x y) ≡⟨ sym (lemma q) ⟩∎
cong f q ∎
where
lemma : ∀ p → cong {x = x} {y = y} f p ≡ trans (sym (c x x)) (c x y)
lemma = elim
(λ {x y} p → cong {x = x} {y = y} f p ≡ trans (sym (c x x)) (c x y))
(λ x →
cong f (refl x) ≡⟨ cong-refl _ ⟩
refl (f x) ≡⟨ sym $ trans-symˡ _ ⟩∎
trans (sym (c x x)) (c x x) ∎)
-- The following two results come from "Generalizations of Hedberg's
-- Theorem" by Kraus, Escardó, Coquand and Altenkirch.
-- Proposition 3.
--
-- (I proved this result using cong-preserves-Constant.)
cong-constant :
∀ {a b} {A : Type a} {B : Type b} {f : A → B} {x} {x≡x : x ≡ x} →
Constant f →
cong f x≡x ≡ refl (f x)
cong-constant {f = f} {x} {x≡x} c =
cong f x≡x ≡⟨ cong-preserves-Constant c _ _ ⟩
cong f (refl x) ≡⟨ cong-refl _ ⟩∎
refl (f x) ∎
-- The "Fixed Point Lemma".
fixpoint-lemma :
∀ {a} {A : Type a} →
(f : A → A) →
Constant f →
Is-proposition (∃ λ x → f x ≡ x)
fixpoint-lemma f constant (x , fx≡x) (y , fy≡y) =
let x≡y = x ≡⟨ sym fx≡x ⟩
f x ≡⟨ constant x y ⟩
f y ≡⟨ fy≡y ⟩∎
y ∎
x≡x = x ≡⟨ sym fx≡x ⟩
f x ≡⟨ subst (λ z → f z ≡ z) (sym x≡y) fy≡y ⟩∎
x ∎
lemma =
subst (λ z → f z ≡ z) x≡x fx≡x ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong f x≡x)) (trans fx≡x (cong id x≡x)) ≡⟨ cong₂ (λ p q → trans (sym p) (trans _ q))
(cong-constant constant) (sym $ cong-id _) ⟩
trans (sym (refl (f x))) (trans fx≡x x≡x) ≡⟨ cong (λ p → trans p (trans fx≡x x≡x)) sym-refl ⟩
trans (refl (f x)) (trans fx≡x x≡x) ≡⟨ trans-reflˡ _ ⟩
trans fx≡x x≡x ≡⟨ sym $ trans-assoc _ _ _ ⟩
trans (trans fx≡x (sym fx≡x))
(subst (λ z → f z ≡ z) (sym x≡y) fy≡y) ≡⟨ cong (λ p → trans p (subst (λ z → f z ≡ z) (sym x≡y) fy≡y)) $
trans-symʳ _ ⟩
trans (refl (f x))
(subst (λ z → f z ≡ z) (sym x≡y) fy≡y) ≡⟨ trans-reflˡ _ ⟩∎
subst (λ z → f z ≡ z) (sym x≡y) fy≡y ∎
in
x , fx≡x ≡⟨ Σ-≡,≡→≡ x≡x lemma ⟩
x , subst (λ z → f z ≡ z) (sym x≡y) fy≡y ≡⟨ sym $ Σ-≡,≡→≡ (sym x≡y) (refl _) ⟩∎
y , fy≡y ∎
|
{
"alphanum_fraction": 0.4773529412,
"avg_line_length": 35.9788359788,
"ext": "agda",
"hexsha": "09746c13c7aa0f631161721de917f5d52c832475",
"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/Equality/Decidable-UIP.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/Equality/Decidable-UIP.agda",
"max_line_length": 129,
"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/Equality/Decidable-UIP.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": 2487,
"size": 6800
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Binary Trees
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Tree.Binary where
open import Level using (Level; _⊔_)
open import Data.List.Base using (List)
open import Data.DifferenceList as DiffList using (DiffList; []; _∷_; _∷ʳ_; _++_)
open import Data.Nat.Base using (ℕ; zero; suc; _+_)
open import Function.Base
open import Relation.Binary.PropositionalEquality
private
variable
a b : Level
A : Set a
B : Set b
data Tree (A : Set a) : Set a where
leaf : Tree A
node : Tree A → A → Tree A → Tree A
map : (A → B) → Tree A → Tree B
map f leaf = leaf
map f (node l m r) = node (map f l) (f m) (map f r)
size : Tree A → ℕ
size leaf = 0
size (node l m r) = size l + suc (size r)
foldr : (B → A → B → B) → B → Tree A → B
foldr nd lf leaf = lf
foldr nd lf (node l m r) = nd (foldr nd lf l) m (foldr nd lf r)
------------------------------------------------------------------------
-- Extraction to lists, depth first and left to right.
module Prefix where
toDiffList : Tree A → DiffList A
toDiffList = foldr (λ l m r → m ∷ l ++ r) []
toList : Tree A → List A
toList = DiffList.toList ∘′ toDiffList
module Infix where
toDiffList : Tree A → DiffList A
toDiffList = foldr (λ l m r → l ++ m ∷ r) []
toList : Tree A → List A
toList = DiffList.toList ∘′ toDiffList
module Suffix where
toDiffList : Tree A → DiffList A
toDiffList = foldr (λ l m r → l ++ r ∷ʳ m) []
toList : Tree A → List A
toList = DiffList.toList ∘′ toDiffList
|
{
"alphanum_fraction": 0.5434007134,
"avg_line_length": 25.4848484848,
"ext": "agda",
"hexsha": "15e82a66b5b59d83134401830640d86b7af1ec6b",
"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/Tree/Binary.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/Tree/Binary.agda",
"max_line_length": 81,
"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/Tree/Binary.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": 499,
"size": 1682
}
|
module Formalization.ClassicalPropositionalLogic.NaturalDeduction.Proofs where
open import Data.Boolean
open import Data.Either
open import Functional
open import Formalization.ClassicalPropositionalLogic.NaturalDeduction
open import Formalization.ClassicalPropositionalLogic.Place
open import Formalization.ClassicalPropositionalLogic.Syntax
import Lvl
open import Logic
import Logic.Propositional as Meta
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Sets.PredicateSet using (PredSet ; _∈_ ; _∉_ ; _∪_ ; _∪•_ ; _∖_ ; _⊆_ ; _⊇_ ; ∅ ; [≡]-to-[⊆] ; [≡]-to-[⊇]) renaming (•_ to singleton ; _≡_ to _≡ₛ_)
open import Type
private variable ℓₚ ℓ ℓ₁ ℓ₂ : Lvl.Level
private variable T A B : Type{ℓ}
private variable P : Type{ℓₚ}
private variable φ ψ γ : Formula(P)
private variable Γ : Formulas(P){ℓ}
private variable f : A → B
private variable s e : Bool
private variable p : P
module _ where
[¬]-intro-converse : ((Γ ∪ singleton(φ)) ⊢ ⊥) ← (Γ ⊢ (¬ φ))
[¬]-intro-converse {Γ = Γ}{φ = φ} Γ¬φ = [⊥]-intro (direct (Right [≡]-intro)) (weaken-union Γ¬φ)
excluded-middle : Γ ⊢ (φ ∨ (¬ φ))
excluded-middle =
([¬¬]-elim
([¬]-intro
([⊥]-intro
([∨]-introᵣ
([¬]-intro
([⊥]-intro
([∨]-introₗ (direct (Right [≡]-intro)))
(direct (Left (Right [≡]-intro)))
)
)
)
(direct (Right [≡]-intro))
)
)
)
[→]-disjunctive-form : (Γ ⊢ (φ ⟶ ψ)) Meta.↔ (Γ ⊢ ((¬ φ) ∨ ψ))
[→]-disjunctive-form = Meta.[↔]-intro l r where
l = [∨]-elim
([⟶]-intro ([⊥]-elim ([⊥]-intro
(direct (Right [≡]-intro))
(direct (Left (Right [≡]-intro)))
)))
([⟶]-intro (direct (Left (Right [≡]-intro))))
r = pq ↦
([∨]-elim
([∨]-introᵣ ([⟶]-elim (direct (Right [≡]-intro)) (weaken Left pq)))
([∨]-introₗ (direct (Right [≡]-intro)))
excluded-middle
)
[⟷]-negated : (Γ ⊢ (φ ⟷ ψ)) → (Γ ⊢ ((¬ φ) ⟷ (¬ ψ)))
[⟷]-negated p = [⟷]-intro
([¬]-intro ([⊥]-intro ([⟷]-elimᵣ (direct (Right [≡]-intro)) (weaken (Left ∘ Left) p)) (direct (Left (Right [≡]-intro)))))
(([¬]-intro ([⊥]-intro ([⟷]-elimₗ (direct (Right [≡]-intro)) (weaken (Left ∘ Left) p)) (direct (Left (Right [≡]-intro))))))
[⟷]-conjunction-disjunction-negation : (Γ ⊢ (φ ⟷ ψ)) Meta.↔ (Γ ⊢ ((φ ∧ ψ) ∨ ((¬ φ) ∧ (¬ ψ))))
[⟷]-conjunction-disjunction-negation = Meta.[↔]-intro l r where
l = [∨]-elim
([⟷]-intro
([∧]-elimₗ (direct (Left (Right [≡]-intro))))
([∧]-elimᵣ (direct (Left (Right [≡]-intro))))
)
([⟷]-intro
([⊥]-elim ([⊥]-intro (direct (Right [≡]-intro)) ([∧]-elimᵣ (direct (Left (Right [≡]-intro))))))
([⊥]-elim ([⊥]-intro (direct (Right [≡]-intro)) ([∧]-elimₗ (direct (Left (Right [≡]-intro))))))
)
r = p ↦ [∨]-elim
([∨]-introₗ ([∧]-intro
(direct (Right [≡]-intro))
([⟷]-elimᵣ (direct (Right [≡]-intro)) (weaken Left p))
))
([∨]-introᵣ ([∧]-intro
(direct (Right [≡]-intro))
([⟷]-elimᵣ (direct (Right [≡]-intro)) (weaken Left ([⟷]-negated p)))
))
excluded-middle
-- TODO: The two proofs contain very similar cases (the structure is identical in all cases). Are there any good ways to generalize? Maybe by using the strict variants?
positive-congruence : Positive(P) f → (Γ ⊢ (φ ⟶ ψ) ⟶ (f(φ) ⟶ f(ψ)))
negative-congruence : Negative(P) f → (Γ ⊢ (φ ⟶ ψ) ⟶ (f(φ) ⟵ f(ψ)))
positive-congruence identity = [⟶]-intro ([⟶]-intro ([⟶]-elim (direct (Right [≡]-intro)) (direct (Left (Right [≡]-intro)))))
positive-congruence (conjunctionₗ ctx) =
[⟶]-intro ([⟶]-intro ([∧]-intro
([∧]-elimₗ (direct (Right [≡]-intro)))
([⟶]-elim ([∧]-elimᵣ (direct (Right [≡]-intro))) ([⟶]-elim (direct (Left (Right [≡]-intro))) (positive-congruence ctx)))
))
positive-congruence (conjunctionᵣ ctx) =
[⟶]-intro ([⟶]-intro ([∧]-intro
([⟶]-elim ([∧]-elimₗ (direct (Right [≡]-intro))) ([⟶]-elim (direct (Left (Right [≡]-intro))) (positive-congruence ctx)))
([∧]-elimᵣ (direct (Right [≡]-intro)))
))
positive-congruence (disjunctionₗ ctx) =
[⟶]-intro ([⟶]-intro ([∨]-elim
([∨]-introₗ (direct (Right [≡]-intro)))
([∨]-introᵣ ([⟶]-elim (direct (Right [≡]-intro)) ([⟶]-elim (direct (Left (Left (Right [≡]-intro)))) (positive-congruence ctx))))
(direct (Right [≡]-intro))
))
positive-congruence (disjunctionᵣ ctx) =
[⟶]-intro ([⟶]-intro ([∨]-elim
([∨]-introₗ ([⟶]-elim (direct (Right [≡]-intro)) ([⟶]-elim (direct (Left (Left (Right [≡]-intro)))) (positive-congruence ctx))))
([∨]-introᵣ (direct (Right [≡]-intro)))
(direct (Right [≡]-intro))
))
positive-congruence (implicationₗ ctx) =
[⟶]-intro ([⟶]-intro ([⟶]-intro ([⟶]-elim
([⟶]-elim (direct(Right [≡]-intro)) (direct (Left (Right [≡]-intro))))
([⟶]-elim (direct (Left (Left (Right [≡]-intro)))) (positive-congruence ctx))
)))
positive-congruence (implicationᵣ ctx) =
[⟶]-intro ([⟶]-intro ([⟶]-intro ([⟶]-elim
([⟶]-elim (direct (Right [≡]-intro)) ([⟶]-elim (direct (Left (Left (Right [≡]-intro)))) (negative-congruence ctx)))
(direct (Left (Right [≡]-intro)))
)))
negative-congruence (conjunctionₗ ctx) =
[⟶]-intro ([⟶]-intro ([∧]-intro
([∧]-elimₗ (direct (Right [≡]-intro)))
([⟶]-elim ([∧]-elimᵣ (direct (Right [≡]-intro))) ([⟶]-elim (direct (Left (Right [≡]-intro))) (negative-congruence ctx)))
))
negative-congruence (conjunctionᵣ ctx) =
[⟶]-intro ([⟶]-intro ([∧]-intro
([⟶]-elim ([∧]-elimₗ (direct (Right [≡]-intro))) ([⟶]-elim (direct (Left (Right [≡]-intro))) (negative-congruence ctx)))
([∧]-elimᵣ (direct (Right [≡]-intro)))
))
negative-congruence (disjunctionₗ ctx) =
[⟶]-intro ([⟶]-intro ([∨]-elim
([∨]-introₗ (direct (Right [≡]-intro)))
([∨]-introᵣ ([⟶]-elim (direct (Right [≡]-intro)) ([⟶]-elim (direct (Left (Left (Right [≡]-intro)))) (negative-congruence ctx))))
(direct (Right [≡]-intro))
))
negative-congruence (disjunctionᵣ ctx) =
[⟶]-intro ([⟶]-intro ([∨]-elim
([∨]-introₗ ([⟶]-elim (direct (Right [≡]-intro)) ([⟶]-elim (direct (Left (Left (Right [≡]-intro)))) (negative-congruence ctx))))
([∨]-introᵣ (direct (Right [≡]-intro)))
(direct (Right [≡]-intro))
))
negative-congruence (implicationₗ ctx) =
[⟶]-intro ([⟶]-intro ([⟶]-intro ([⟶]-elim
([⟶]-elim (direct(Right [≡]-intro)) (direct (Left (Right [≡]-intro))))
([⟶]-elim (direct (Left (Left (Right [≡]-intro)))) (negative-congruence ctx))
)))
negative-congruence (implicationᵣ ctx) =
[⟶]-intro ([⟶]-intro ([⟶]-intro ([⟶]-elim
([⟶]-elim (direct (Right [≡]-intro)) ([⟶]-elim (direct (Left (Left (Right [≡]-intro)))) (positive-congruence ctx)))
(direct (Left (Right [≡]-intro)))
)))
-- TODO: Mainly for results in minimal logic
data NegativeFragment {P : Type{ℓₚ}} : Formula(P) → Type{Lvl.of(P)} where
atom : NegativeFragment(¬(• p))
bottom : NegativeFragment(⊥)
top : NegativeFragment(⊤)
neg : NegativeFragment(φ) → NegativeFragment(¬ φ)
and : NegativeFragment(φ) → NegativeFragment(ψ) → NegativeFragment(φ ∧ ψ)
impl : NegativeFragment(φ) → NegativeFragment(ψ) → NegativeFragment(φ ⟶ ψ)
eq : NegativeFragment(φ) → NegativeFragment(ψ) → NegativeFragment(φ ⟷ ψ)
open import Functional
open import Type.Dependent
open import Type.Dependent.Functions
module GGNegativeTranslation where
trans : Formula(P) → Formula(P)
trans (• p) = ¬(¬(• p))
trans ⊤ = ⊤
trans ⊥ = ⊥
trans (¬ φ) = ¬(trans φ)
trans (φ ∧ ψ) = (trans φ) ∧ (trans ψ)
trans (φ ∨ ψ) = ¬((¬(trans φ)) ∧ (¬(trans ψ)))
trans (φ ⟶ ψ) = (trans φ) ⟶ (trans ψ)
trans (φ ⟷ ψ) = (trans φ) ⟷ (trans ψ)
trans-negativeFragment : NegativeFragment(trans(φ))
trans-negativeFragment {φ = • p} = neg atom
trans-negativeFragment {φ = ⊤} = top
trans-negativeFragment {φ = ⊥} = bottom
trans-negativeFragment {φ = ¬ φ} = neg trans-negativeFragment
trans-negativeFragment {φ = φ ∧ ψ} = and trans-negativeFragment trans-negativeFragment
trans-negativeFragment {φ = φ ∨ ψ} = neg(and(neg trans-negativeFragment) (neg trans-negativeFragment))
trans-negativeFragment {φ = φ ⟶ ψ} = impl trans-negativeFragment trans-negativeFragment
trans-negativeFragment {φ = φ ⟷ ψ} = eq trans-negativeFragment trans-negativeFragment
|
{
"alphanum_fraction": 0.5719433101,
"avg_line_length": 42.6974358974,
"ext": "agda",
"hexsha": "03beb8ee32a1eb92f5158e4da707d457f1cf564a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Formalization/ClassicalPropositionalLogic/NaturalDeduction/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Formalization/ClassicalPropositionalLogic/NaturalDeduction/Proofs.agda",
"max_line_length": 168,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Formalization/ClassicalPropositionalLogic/NaturalDeduction/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 3075,
"size": 8326
}
|
------------------------------------------------------------------------
-- Finite sets (currently only some type signatures)
------------------------------------------------------------------------
module Data.Sets where
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.OrderMorphism
open import Data.Function
open import Data.List as L using (List)
open import Data.Product using (∃; _×_)
module Sets₁ (dto : DecTotalOrder) where
open DecTotalOrder dto public using (_≈_)
open DecTotalOrder dto hiding (_≈_)
infixr 6 _∪_
infix 5 _∈?_
infix 4 _∈_ _|≈|_
abstract postulate decSetoid : DecSetoid
<Set> : Set
<Set> = DecSetoid.carrier decSetoid
_|≈|_ : Rel <Set>
_|≈|_ = DecSetoid._≈_ decSetoid
abstract
postulate
empty : <Set>
insert : carrier → <Set> → <Set>
_∪_ : <Set> → <Set> → <Set>
_∈_ : carrier → <Set> → Set
_∈?_ : (x : carrier) → (s : <Set>) → Dec (x ∈ s)
toList : <Set> → List carrier
postulate
prop-∈-insert₁ : ∀ {x y s} → x ≈ y → x ∈ insert y s
prop-∈-insert₂ : ∀ {x y s} → x ∈ s → x ∈ insert y s
prop-∈-insert₃ : ∀ {x y s} → ¬ x ≈ y → x ∈ insert y s → x ∈ s
prop-∈-empty : ∀ {x} → ¬ x ∈ empty
prop-∈-∪ : ∀ {x s₁ s₂} → x ∈ s₁ → x ∈ s₁ ∪ s₂
prop-∪₁ : ∀ {s₁ s₂} → s₁ ∪ s₂ |≈| s₂ ∪ s₁
prop-∪₂ : ∀ {s₁ s₂ s₃} → s₁ ∪ (s₂ ∪ s₃) |≈| (s₁ ∪ s₂) ∪ s₃
prop-∈-|≈| : ∀ {x} → (λ s → x ∈ s) Respects _|≈|_
prop-∈-≈ : ∀ {s} → (λ x → x ∈ s) Respects _≈_
-- TODO: Postulates for toList.
singleton : carrier → <Set>
singleton x = insert x empty
⋃_ : List <Set> → <Set>
⋃_ = L.foldr _∪_ empty
fromList : List carrier → <Set>
fromList = L.foldr insert empty
_⊆_ : <Set> → <Set> → Set
s₁ ⊆ s₂ = ∀ x → x ∈ s₁ → x ∈ s₂
open Sets₁ public
open DecTotalOrder hiding (_≈_)
open _⇒-Poset_
abstract
postulate
map : ∀ {do₁ do₂} → do₁ ⇒-DTO do₂ → <Set> do₁ → <Set> do₂
mapToSet : ∀ {do₁ do₂} →
(carrier do₁ → <Set> do₂) →
<Set> do₁ → <Set> do₂
prop-map-∈₁ : ∀ {do₁ do₂ f x s} →
x ⟨ _∈_ do₁ ⟩₁ s →
fun f x ⟨ _∈_ do₂ ⟩₁ map f s
prop-map-∈₂ : ∀ {do₁ do₂ f y s} →
y ⟨ _∈_ do₂ ⟩₁ map f s →
∃ λ x → (fun f x ⟨ _≈_ do₂ ⟩₁ y) ×
( x ⟨ _∈_ do₁ ⟩₁ s)
prop-mapToSet₁ : ∀ {do₁ do₂ f x s} →
x ⟨ _∈_ do₁ ⟩₁ s →
f x ⟨ _⊆_ do₂ ⟩₁ mapToSet f s
prop-mapToSet₂ : ∀ {do₁ do₂ f y s} →
y ⟨ _∈_ do₂ ⟩₁ mapToSet f s →
∃ λ x → (y ⟨ _∈_ do₂ ⟩₁ f x) ×
(x ⟨ _∈_ do₁ ⟩₁ s)
|
{
"alphanum_fraction": 0.4665170221,
"avg_line_length": 28.1368421053,
"ext": "agda",
"hexsha": "c7a224a3104071541ef4af5007e61e869bf26946",
"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/Sets.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/Sets.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/Sets.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": 1053,
"size": 2673
}
|
module Proof where
open import Basics hiding (_==_)
open import Proc
open import Path
import Graph
private
open module G = Graph Nat
open module P = Process param hiding (U; T; _!_)
{-
Soundness:
if we get an answer there is a path
Completeness:
if there is a path we get an answer
-}
infix 18 _encodes_
data _encodes_ {G : Graph} :
{x y : Nat} -> List Node -> Path G x y -> Set where
nul-path : {x : Nat} -> stop :: [] encodes nul {x = x}
step-path : {x y z : Nat}{xs : List Node}
{step : Step G x y}{path : Path G y z} ->
xs encodes path ->
node y :: xs encodes step <> path
test : {G : Graph}{a b c : Nat}
{ab : Step G a b}{bc : Step G b c} ->
node b :: node c :: stop :: [] encodes
ab <> bc <> nul
test = step-path (step-path nul-path)
target : {G : Graph}{x y : Nat} -> Step G x y -> Nat
target {y = y} _ = y
encoding : {G : Graph}{x y : Nat} -> Path G x y -> List Node
encoding nul = stop :: []
encoding (step <> path) = node (target step) :: encoding path
lem-encode : {G : Graph}{x y : Nat}(path : Path G x y) ->
encoding path encodes path
lem-encode nul = nul-path
lem-encode (step <> path) = step-path (lem-encode path)
data WellFormed : List Node -> Set where
good-stop : WellFormed (stop :: [])
good-:: : forall {x xs} -> WellFormed xs -> WellFormed (node x :: xs)
data MalFormed : List Node -> Set where
bad-[] : MalFormed []
bad-:: : forall {x xs} -> MalFormed xs -> MalFormed (node x :: xs)
bad-stop : forall {x xs} -> MalFormed (stop :: x :: xs)
module Theorems (G : Graph)(start end : Nat) where
mainp = main G start end
Complete : Set
Complete = (path : Path G start end) ->
∃ \q -> Silent q /\
mainp -! encoding path !->* q
Sound : Set
Sound = forall q xs -> Silent q -> WellFormed xs ->
mainp -! xs !->* q ->
∃ \(path : Path G start end) -> xs encodes path
Sound-Fail : Set
Sound-Fail = forall q xs -> Silent q -> MalFormed xs ->
mainp -! xs !->* q -> Path G start end -> False
silent-edges : {a : U} -> Graph -> Proc a
silent-edges [] = o
silent-edges (_ :: G) = o || silent-edges G
silent-silent-edges : {a : U}(G : Graph) -> Silent (silent-edges {a} G)
silent-silent-edges [] = silent-o
silent-silent-edges (_ :: G) = silent-|| silent-o (silent-silent-edges G)
module Proofs (G : Graph) where
private open module T = Theorems G
complete : (start end : Nat) -> Complete start end
complete x .x nul =
∃-intro q (silent-q , run)
where
edg₁ = {! !}
edg₂ = {! !}
edg₃ = silent-edges G
silent-edg₃ : Silent edg₃
silent-edg₃ = silent-silent-edges G
q = φ /| o || o || edg₃
silent-q : Silent q
silent-q = silent-/| (silent-|| silent-o (silent-|| silent-o silent-edg₃))
rx-edg₁ : edges G -[ lift (forward stop (node x)) ]-> edg₁
rx-edg₁ = {! !}
rx-edg₂ : edg₁ -[ {! !} ]-> edg₂
rx-edg₂ = {! !}
run-edg₃ : φ /| o || o || edg₂ -! [] !->* φ /| o || o || edg₃
run-edg₃ = {! !}
tx-batter : (n : Nat) ->
if node n == node n
then backward stop ! o
else def (start x)
-! lift (backward stop) !-> o
tx-batter zero = tx-!
tx-batter (suc n) = tx-batter n
run : mainp x x -! stop :: [] !->* q
run = (tx-/| (tx-!|
(tx-def tx-!)
(rx-|| (rx-def rx->) rx-edg₁)))
>*>
(tx-/| (tx-|! rx-o (tx-!| (tx-batter x) rx-edg₂)))
>!>
run-edg₃
|
{
"alphanum_fraction": 0.517297739,
"avg_line_length": 27.6015037594,
"ext": "agda",
"hexsha": "10666ba728d368d4ddbb4dbddef755e4f1c9301a",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/cbs/Proof.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/cbs/Proof.agda",
"max_line_length": 80,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/cbs/Proof.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": 1186,
"size": 3671
}
|
module DifferentArities where
open import Common.Equality
open import Common.Prelude
f : Nat → Nat → Nat
f zero = λ x → x
f (suc n) m = f n (suc m)
testf1 : f zero ≡ λ x → x
testf1 = refl
testf2 : ∀ {n m} → f (suc n) m ≡ f n (suc m)
testf2 = refl
testf3 : f 4 5 ≡ 9
testf3 = refl
|
{
"alphanum_fraction": 0.6116838488,
"avg_line_length": 15.3157894737,
"ext": "agda",
"hexsha": "32934d2679574f4bef70470d27ff1960d5683242",
"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/DifferentArities.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/DifferentArities.agda",
"max_line_length": 44,
"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/DifferentArities.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": 123,
"size": 291
}
|
------------------------------------------------------------------------
-- Binary relations lifted to substitutions
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module Data.Fin.Substitution.Relation where
open import Data.Fin using (Fin; zero; suc)
open import Data.Fin.Substitution
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Nat using (ℕ; zero; suc)
open import Data.Vec.Relation.Binary.Pointwise.Inductive hiding (refl)
import Function as Fun
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)
-- Term relations.
--
-- A term relation R : TermRel T₁ T₂ is a ℕ-indexed family of binary
-- relations relating T₁-terms to T₂-terms.
TermRel : (ℕ → Set) → (ℕ → Set) → Set₁
TermRel T₁ T₂ = ∀ {n} → T₁ n → T₂ n → Set
-- Substitution relations.
--
-- A substitution relation R : SubRel T₁ T₂ is a ℕ²-indexed family
-- of binary relations relating T₁-substitutions to T₂-substitutions.
SubRel : (ℕ → Set) → (ℕ → Set) → Set₁
SubRel T₁ T₂ = ∀ {m n} → Sub T₁ m n → Sub T₂ m n → Set
module LiftTermRel (T₁ T₂ : ℕ → Set) where
-- Term relations lifted point-wise to corresponding substitutions.
--
-- Given a relation R on T₁ and T₂ terms, the family of relations
-- (lift R) relates T₁ and T₂ substitutions point-wise.
lift : TermRel T₁ T₂ → SubRel T₁ T₂
lift P σ₁ σ₂ = Pointwise P σ₁ σ₂
infix 4 _⟨_⟩_
-- Syntactic sugar: and infix version of lifting.
_⟨_⟩_ : ∀ {m n} → Sub T₁ m n → TermRel T₁ T₂ → Sub T₂ m n → Set
σ₁ ⟨ R ⟩ σ₂ = lift R σ₁ σ₂
------------------------------------------------------------------------
-- Generic substitutions lifted to relations
module _ {T₁ T₂} (_∼_ : TermRel T₁ T₂) where
open LiftTermRel T₁ T₂ using (_⟨_⟩_)
-- Extensions of substitutions lifted to relations.
record RelExtension (ext₁ : Extension T₁) (ext₂ : Extension T₂) : Set where
private
module E₁ = Extension ext₁
module E₂ = Extension ext₂
-- Weakening lifted to _∼_.
field weaken : ∀ {n} {t₁ : T₁ n} {t₂ : T₂ n} →
t₁ ∼ t₂ → E₁.weaken t₁ ∼ E₂.weaken t₂
infixr 5 _/∷_
-- Extension.
_/∷_ : ∀ {m n t₁ t₂} {σ₁ : Sub T₁ m n} {σ₂ : Sub T₂ m n} →
t₁ ∼ t₂ → σ₁ ⟨ _∼_ ⟩ σ₂ → t₁ E₁./∷ σ₁ ⟨ _∼_ ⟩ t₂ E₂./∷ σ₂
t₁∼t₂ /∷ σ₁∼σ₂ = t₁∼t₂ ∷ map⁺ weaken σ₁∼σ₂
-- Simple substitutions lifted to relations.
record RelSimple (simple₁ : Simple T₁) (simple₂ : Simple T₂) : Set where
private
module S₁ = SimpleExt simple₁
module S₂ = SimpleExt simple₂
field
extension : RelExtension S₁.extension S₂.extension
-- Relates variables.
var : ∀ {n} (x : Fin n) → S₁.var x ∼ S₂.var x
open RelExtension extension public
infix 10 _↑
infixl 10 _↑⋆_
-- Lifting.
_↑ : ∀ {m n} {σ₁ : Sub T₁ m n} {σ₂ : Sub T₂ m n} →
σ₁ ⟨ _∼_ ⟩ σ₂ → σ₁ S₁.↑ ⟨ _∼_ ⟩ σ₂ S₂.↑
σ₁∼σ₂ ↑ = var zero /∷ σ₁∼σ₂
_↑⋆_ : ∀ {m n} {σ₁ : Sub T₁ m n} {σ₂ : Sub T₂ m n} →
σ₁ ⟨ _∼_ ⟩ σ₂ → ∀ k → σ₁ S₁.↑⋆ k ⟨ _∼_ ⟩ σ₂ S₂.↑⋆ k
σ₁∼σ₂ ↑⋆ zero = σ₁∼σ₂
σ₁∼σ₂ ↑⋆ suc k = (σ₁∼σ₂ ↑⋆ k) ↑
-- The identity substitution.
id : ∀ {n} → S₁.id {n} ⟨ _∼_ ⟩ S₂.id {n}
id {zero} = []
id {suc n} = id ↑
-- Weakening.
wk⋆ : ∀ k {n} → S₁.wk⋆ k {n} ⟨ _∼_ ⟩ S₂.wk⋆ k {n}
wk⋆ zero = id
wk⋆ (suc k) = map⁺ weaken (wk⋆ k)
wk : ∀ {n} → S₁.wk {n} ⟨ _∼_ ⟩ S₂.wk {n}
wk = wk⋆ 1
-- A substitution which only replaces the first variable.
sub : ∀ {n} {t₁ : T₁ n} {t₂} → t₁ ∼ t₂ → S₁.sub t₁ ⟨ _∼_ ⟩ S₂.sub t₂
sub t₁~t₂ = t₁~t₂ ∷ id
-- Application of substitutions lifted to relations.
record RelApplication {T₁′ T₂′} (R : TermRel T₁′ T₂′)
(app₁ : Application T₁ T₁′)
(app₂ : Application T₂ T₂′) : Set where
private
module A₁ = Application app₁
module A₂ = Application app₂
open LiftTermRel T₁′ T₂′ using () renaming (_⟨_⟩_ to _⟨_⟩′_)
infixl 8 _/_
infixl 9 _⊙_
-- Post-application of substitutions to things.
field _/_ : ∀ {m n t₁ t₂} {σ₁ : Sub T₁′ m n} {σ₂ : Sub T₂′ m n} →
t₁ ∼ t₂ → σ₁ ⟨ R ⟩′ σ₂ → (t₁ A₁./ σ₁) ∼ (t₂ A₂./ σ₂)
-- Reverse composition. (Fits well with post-application.)
_⊙_ : ∀ {m n k} {σ₁ : Sub T₁ m n} {σ₂} {σ₁′ : Sub T₁′ n k} {σ₂′} →
σ₁ ⟨ _∼_ ⟩ σ₂ → σ₁′ ⟨ R ⟩′ σ₂′ → σ₁ A₁.⊙ σ₁′ ⟨ _∼_ ⟩ σ₂ A₂.⊙ σ₂′
σ₁∼σ₂ ⊙ σ₁∼σ₂′ = map⁺ (λ t₁∼t₂ → t₁∼t₂ / σ₁∼σ₂′) σ₁∼σ₂
-- A combination of the two records above.
record RelSubst (subst₁ : Subst T₁) (subst₂ : Subst T₂) : Set where
private
module S₁ = Subst subst₁
module S₂ = Subst subst₂
field
simple : RelSimple S₁.simple S₂.simple
application : RelApplication _∼_ S₁.application S₂.application
open RelSimple simple public
open RelApplication application public
------------------------------------------------------------------------
-- Instantiations and code for facilitating instantiations
-- Liftings from TermRel T₁ T₂ to TermRel T₁′ T₂′.
record RelLift {T₁ T₂ T₁′ T₂′} (_∼_ : TermRel T₁ T₂) (_∼′_ : TermRel T₁′ T₂′)
(l₁ : Lift T₁ T₁′) (l₂ : Lift T₂ T₂′) : Set where
private
module L₁ = Lift l₁
module L₂ = Lift l₂
field
simple : RelSimple _∼_ L₁.simple L₂.simple
lift : ∀ {n} {t₁ : T₁ n} {t₂} → t₁ ∼ t₂ → L₁.lift t₁ ∼′ L₂.lift t₂
open RelSimple simple public
-- Variable substitutions (renamings) lifted to equality.
module VarEqSubst where
private module V = VarSubst
infix 4 _⟨≡⟩_
_⟨≡⟩_ : SubRel Fin Fin
_⟨≡⟩_ = LiftTermRel.lift Fin Fin _≡_
subst : RelSubst _≡_ V.subst V.subst
subst = record
{ simple = record { extension = extension; var = λ _ → refl }
; application = record { _/_ = _/_ }
}
where
extension = record { weaken = cong suc }
_/_ : ∀ {m n x₁ x₂} {σ₁ σ₂ : Sub Fin n m} →
x₁ ≡ x₂ → σ₁ ⟨≡⟩ σ₂ → x₁ V./ σ₁ ≡ x₂ V./ σ₂
_/_ {x₁ = x} refl σ₁≡σ₂ = lookup σ₁≡σ₂ x
open RelSubst subst public
-- "Term" substitutions lifted to relations.
record TermRelSubst {T₁ T₂ : ℕ → Set} (_∼_ : TermRel T₁ T₂)
(ts₁ : TermSubst T₁) (ts₂ : TermSubst T₂) : Set₁ where
private
module S₁ = TermSubst ts₁
module S₂ = TermSubst ts₂
module V = VarEqSubst
field
var : ∀ {n} (x : Fin n) → S₁.var x ∼ S₂.var x
app : ∀ {T₁′ T₂′} (R : TermRel T₁′ T₂′)
(l₁ : Lift T₁′ T₁) (l₂ : Lift T₂′ T₂) → RelLift R _∼_ l₁ l₂ →
let open LiftTermRel T₁′ T₂′ using (_⟨_⟩_) in
∀ {m n t₁ t₂} {σ₁ : Sub T₁′ m n} {σ₂ : Sub T₂′ m n} →
t₁ ∼ t₂ → σ₁ ⟨ R ⟩ σ₂ → S₁.app l₁ t₁ σ₁ ∼ S₂.app l₂ t₂ σ₂
module RelLifted {T₁′ T₂′} (R : TermRel T₁′ T₂′)
(l₁ : Lift T₁′ T₁) (l₂ : Lift T₂′ T₂)
(lift : RelLift R _∼_ l₁ l₂) where
private
module L₁ = S₁.Lifted l₁
module L₂ = S₂.Lifted l₂
application : RelApplication _∼_ R L₁.application L₂.application
application = record { _/_ = app R l₁ l₂ lift }
varLift : RelLift _≡_ _∼_ S₁.varLift S₂.varLift
varLift = record { simple = V.simple; lift = lift }
where
lift : ∀ {n} {x₁ x₂ : Fin n} → x₁ ≡ x₂ → S₁.var x₁ ∼ S₂.var x₂
lift {x₁ = x} refl = var x
infix 8 _/Var_
_/Var_ : ∀ {m n t₁ t₂} {σ₁ σ₂ : Sub Fin m n} →
t₁ ∼ t₂ → σ₁ V.⟨≡⟩ σ₂ → (t₁ S₁./Var σ₁) ∼ (t₂ S₂./Var σ₂)
_/Var_ = app _≡_ S₁.varLift S₂.varLift varLift
simple : RelSimple _∼_ S₁.simple S₂.simple
simple = record
{ extension = record { weaken = λ t₁∼t₂ → t₁∼t₂ /Var V.wk }
; var = var
}
termLift : RelLift _∼_ _∼_ S₁.termLift S₂.termLift
termLift = record { simple = simple; lift = Fun.id }
subst : RelSubst _∼_ S₁.subst S₂.subst
subst = record
{ simple = simple
; application = RelLifted.application _∼_ S₁.termLift S₂.termLift termLift
}
open LiftTermRel T₁ T₂ public using (_⟨_⟩_)
open RelSubst subst public hiding (var; simple)
|
{
"alphanum_fraction": 0.5611375595,
"avg_line_length": 32.5795918367,
"ext": "agda",
"hexsha": "0ad1592dc4b2ebd78d32ede2fa4368f837446813",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/Data/Fin/Substitution/Relation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/Data/Fin/Substitution/Relation.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/Data/Fin/Substitution/Relation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3056,
"size": 7982
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cw.CW
open import cw.FinCW
open import cw.FinBoundary
open import cohomology.Theory
module cw.cohomology.cochainequiv.FirstCoboundaryCommSquare (OT : OrdinaryTheory lzero)
(⊙fin-skel : ⊙FinSkeleton 1) where
open OrdinaryTheory OT
open import cw.cohomology.WedgeOfCells OT ⊙⦉ ⊙fin-skel ⦊
open import cw.cohomology.reconstructed.TipAndAugment OT ⊙⦉ ⊙fcw-init ⊙fin-skel ⦊
open import cw.cohomology.reconstructed.TipCoboundary OT ⊙⦉ ⊙fin-skel ⦊
open import cw.cohomology.cochainequiv.DualizedFirstBoundary OT ⊙fin-skel
open import cw.cohomology.cochainequiv.FirstCoboundary OT ⊙fin-skel
private
fin-skel = ⊙FinSkeleton.skel ⊙fin-skel
I = AttachedFinSkeleton.numCells fin-skel
ac = ⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero
⊙fin-skel₋₁ = ⊙fcw-init ⊙fin-skel
fin-skel₋₁ = ⊙FinSkeleton.skel ⊙fin-skel₋₁
ac₋₁ = ⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel₋₁ lzero
abstract
rephrase-dualized-first-boundary-comm-sqr :
CommSquareEquiv
(λ g <I → Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (fdegree-last fin-skel <I <I₋₁)))
(_∘ᴳ fboundary-last fin-skel)
(FreeAbGroup-extend (C2-abgroup 0))
(FreeAbGroup-extend (C2-abgroup 0))
rephrase-dualized-first-boundary-comm-sqr =
comm-sqr (λ g →
equiv-adj'
(GroupIso.f-equiv (FreeAbGroup-extend-iso (C2-abgroup 0)))
(λ= λ <I → ! (rephrase-dualized-first-boundary-in-degree g <I))) ,
FreeAbGroup-extend-is-equiv (C2-abgroup 0) ,
FreeAbGroup-extend-is-equiv (C2-abgroup 0)
rephrase-cw-co∂-head-comm-sqr :
CommSquareEquiv
(λ g <I → Group.sum (C2 0) (λ <I' → Group.exp (C2 0) (g <I') (fdegree-last fin-skel <I <I')))
(GroupHom.f cw-co∂-head)
(GroupIso.g (C2×CX₀-diag-β ac₋₁))
(GroupIso.g (CXₙ/Xₙ₋₁-diag-β ac))
rephrase-cw-co∂-head-comm-sqr =
comm-sqr (λ g →
equiv-adj'
(GroupIso.g-equiv (CXₙ/Xₙ₋₁-diag-β ac))
(λ= λ <I → ! (rephrase-cw-co∂-head-in-degree g <I))) ,
(GroupIso.g-is-equiv (C2×CX₀-diag-β ac₋₁)) ,
(GroupIso.g-is-equiv (CXₙ/Xₙ₋₁-diag-β ac))
first-coboundary-comm-sqr :
CommSquareEquiv
(GroupHom.f cw-co∂-head)
(_∘ᴳ fboundary-last fin-skel)
(FreeAbGroup-extend (C2-abgroup 0) ∘ GroupIso.f (C2×CX₀-diag-β ac₋₁))
(FreeAbGroup-extend (C2-abgroup 0) ∘ GroupIso.f (CXₙ/Xₙ₋₁-diag-β ac))
first-coboundary-comm-sqr =
CommSquareEquiv-∘v
rephrase-dualized-first-boundary-comm-sqr
(CommSquareEquiv-inverse-v rephrase-cw-co∂-head-comm-sqr)
first-coboundary-comm-sqrᴳ :
CommSquareEquivᴳ
cw-co∂-head
(pre∘ᴳ-hom (C2-abgroup 0) (fboundary-last fin-skel))
(FreeAbGroup-extend-hom (C2-abgroup 0) ∘ᴳ GroupIso.f-hom (C2×CX₀-diag-β ac₋₁))
(FreeAbGroup-extend-hom (C2-abgroup 0) ∘ᴳ GroupIso.f-hom (CXₙ/Xₙ₋₁-diag-β ac))
first-coboundary-comm-sqrᴳ =
comm-sqrᴳ (fst first-coboundary-comm-sqr □$_) , snd first-coboundary-comm-sqr
|
{
"alphanum_fraction": 0.6751935375,
"avg_line_length": 39.0921052632,
"ext": "agda",
"hexsha": "704aba4aaa31e640c98a5f19c24c96f755173cdc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/cochainequiv/FirstCoboundaryCommSquare.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/cochainequiv/FirstCoboundaryCommSquare.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/cochainequiv/FirstCoboundaryCommSquare.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1162,
"size": 2971
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Paths
open import lib.types.TwoSemiCategory
open import lib.two-semi-categories.Functor
module lib.two-semi-categories.FunctorInverse where
module _ {k l} {B : Type k} {C : B → B → Type l}
(comp : {b b' b'' : B} → C b b' → C b' b'' → C b b'') where
coe-C : {b₁ b₁' b₂ b₂' : B}
→ b₁ == b₂
→ b₁' == b₂'
→ C b₁ b₁'
→ C b₂ b₂'
coe-C p p' = coe (ap2 C p p')
coe-comp : {b₁ b₁' b₁'' b₂ b₂' b₂'' : B}
→ (p : b₁ == b₂) (p' : b₁' == b₂') (p'' : b₁'' == b₂'')
→ (r : C b₁ b₁') (s : C b₁' b₁'')
→ coe-C p p'' (comp r s) == comp (coe-C p p' r) (coe-C p' p'' s)
coe-comp idp idp idp r s = idp
coe-comp-coh : {b₁ b₁' b₁'' b₁''' b₂ b₂' b₂'' b₂''' : B}
→ (assoc : {b b' b'' b''' : B}
→ (f : C b b') (g : C b' b'') (h : C b'' b''')
→ comp (comp f g) h == comp f (comp g h))
→ (p : b₁ == b₂) (p' : b₁' == b₂') (p'' : b₁'' == b₂'') (p''' : b₁''' == b₂''')
→ (f : C b₁ b₁') (g : C b₁' b₁'') (h : C b₁'' b₁''')
→ coe-comp p p'' p''' (comp f g) h ◃∙
ap (λ s → comp s (coe-C p'' p''' h)) (coe-comp p p' p'' f g) ◃∙
assoc (coe-C p p' f) (coe-C p' p'' g) (coe-C p'' p''' h) ◃∎
=ₛ
ap (coe-C p p''') (assoc f g h) ◃∙
coe-comp p p' p''' f (comp g h) ◃∙
ap (comp (coe-C p p' f)) (coe-comp p' p'' p''' g h) ◃∎
coe-comp-coh assoc idp idp idp idp f g h = =ₛ-in $
! (ap-idf (assoc f g h)) ∙ ! (∙-unit-r (ap (coe-C idp idp) (assoc f g h)))
module FunctorInverse
{i₁ j₁ i₂ j₂}
{C : TwoSemiCategory i₁ j₁} {D : TwoSemiCategory i₂ j₂}
(F : TwoSemiFunctor C D)
(F₀-is-equiv : is-equiv (TwoSemiFunctor.F₀ F))
(F₁-is-equiv : ∀ x y → is-equiv (TwoSemiFunctor.F₁ F {x} {y})) where
private
module C = TwoSemiCategory C
module D = TwoSemiCategory D
module F = TwoSemiFunctor F
module F₀-is-equiv = is-equiv F₀-is-equiv
module F₁-is-equiv (x y : C.El) = is-equiv (F₁-is-equiv x y)
F₀ = F.F₀
F₁ = F.F₁
G₀ : D.El → C.El
G₀ = F₀-is-equiv.g
D' : TwoSemiCategory i₂ j₂
D' =
record
{ El = D.El
; Arr = λ x y → D.Arr (F₀ (G₀ x)) (F₀ (G₀ y))
; Arr-level = λ x y → D.Arr-level (F₀ (G₀ x)) (F₀ (G₀ y))
; two-semi-cat-struct =
record
{ comp = λ f g → D.comp f g
; assoc = λ f g h → D.assoc f g h
; pentagon-identity = λ f g h i → D.pentagon-identity f g h i
}
}
N : TwoSemiFunctor D D'
N =
record
{ F₀ = idf D.El
; F₁ = λ {x} {y} f → coe (Arr-path x y) f
; pres-comp = λ {x} {y} {z} f g →
coe-comp D.comp (F₀-η x) (F₀-η y) (F₀-η z) f g
; pres-comp-coh = λ {w} {x} {y} {z} f g h →
coe-comp-coh D.comp D.assoc (F₀-η w) (F₀-η x) (F₀-η y) (F₀-η z) f g h
}
where
F₀-η : (x : D.El) → x == F₀ (G₀ x)
F₀-η x = ! (F₀-is-equiv.f-g x)
Arr-path : (x y : D.El) → D.Arr x y == D.Arr (F₀ (G₀ x)) (F₀ (G₀ y))
Arr-path x y = ap2 D.Arr (F₀-η x) (F₀-η y)
module N = TwoSemiFunctor N
G₁ : {x y : D.El} → D.Arr (F₀ (G₀ x)) (F₀ (G₀ y)) → C.Arr (G₀ x) (G₀ y)
G₁ {x} {y} f = F₁-is-equiv.g (G₀ x) (G₀ y) f
F₁-β : {x y : D.El} (f : D.Arr (F₀ (G₀ x)) (F₀ (G₀ y)))
→ F₁ (G₁ f) == f
F₁-β {x} {y} f = F₁-is-equiv.f-g (G₀ x) (G₀ y) f
F₁-η : {x y : D.El} (f : D.Arr (F₀ (G₀ x)) (F₀ (G₀ y)))
→ f == F₁ (G₁ f)
F₁-η f = ! (F₁-β f)
G₁-β : {x y : D.El} → (f : C.Arr (G₀ x) (G₀ y))
→ G₁ (F₁ f) == f
G₁-β {x} {y} f = F₁-is-equiv.g-f (G₀ x) (G₀ y) f
G₁-pres-comp-seq : {x y z : D.El}
(f : D.Arr (F₀ (G₀ x)) (F₀ (G₀ y)))
(g : D.Arr (F₀ (G₀ y)) (F₀ (G₀ z)))
→ G₁ (D.comp f g) =-= C.comp (G₁ f) (G₁ g)
G₁-pres-comp-seq {x} {y} {z} f g =
G₁ (D.comp f g)
=⟪ ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η g) ⟫
G₁ (D.comp (F₁ (G₁ f)) (F₁ (G₁ g)))
=⟪ ap G₁ (! (F.pres-comp (G₁ f) (G₁ g))) ⟫
G₁ (F₁ (C.comp (G₁ f) (G₁ g)))
=⟪ G₁-β (C.comp (G₁ f) (G₁ g)) ⟫
C.comp (G₁ f) (G₁ g) ∎∎
abstract
G₁-pres-comp : {x y z : D.El}
(f : D.Arr (F₀ (G₀ x)) (F₀ (G₀ y)))
(g : D.Arr (F₀ (G₀ y)) (F₀ (G₀ z)))
→ G₁ (D.comp f g) == C.comp (G₁ f) (G₁ g)
G₁-pres-comp f g = ↯ (G₁-pres-comp-seq f g)
G₁-pres-comp-β : {x y z : D.El}
(f : D.Arr (F₀ (G₀ x)) (F₀ (G₀ y)))
(g : D.Arr (F₀ (G₀ y)) (F₀ (G₀ z)))
→ G₁-pres-comp f g ◃∎ =ₛ G₁-pres-comp-seq f g
G₁-pres-comp-β f g = =ₛ-in idp
private
G₁-pres-comp-coh : {w x y z : D.El}
(f : D.Arr (F₀ (G₀ w)) (F₀ (G₀ x)))
(g : D.Arr (F₀ (G₀ x)) (F₀ (G₀ y)))
(h : D.Arr (F₀ (G₀ y)) (F₀ (G₀ z)))
→ G₁-pres-comp (D.comp f g) h ◃∙
ap (λ s → C.comp s (G₁ h)) (G₁-pres-comp f g) ◃∙
C.assoc (G₁ f) (G₁ g) (G₁ h) ◃∎
=ₛ
ap G₁ (D.assoc f g h) ◃∙
G₁-pres-comp f (D.comp g h) ◃∙
ap (C.comp (G₁ f)) (G₁-pres-comp g h) ◃∎
G₁-pres-comp-coh {w} {x} {y} {z} f g h =
G₁-pres-comp (D.comp f g) h ◃∙
ap (λ s → C.comp s (G₁ h)) (G₁-pres-comp f g) ◃∙
C.assoc (G₁ f) (G₁ g) (G₁ h) ◃∎
=ₛ⟨ 0 & 1 & G₁-pres-comp-β (D.comp f g) h ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp f g)) (F₁-η h) ◃∙
ap G₁ (! (F.pres-comp (G₁ (D.comp f g)) (G₁ h))) ◃∙
G₁-β (C.comp (G₁ (D.comp f g)) (G₁ h)) ◃∙
ap (λ s → C.comp s (G₁ h)) (G₁-pres-comp f g) ◃∙
C.assoc (G₁ f) (G₁ g) (G₁ h) ◃∎
=ₛ⟨ 2 & 2 & !ₛ $
homotopy-naturality
(λ s → G₁ (F₁ (C.comp s (G₁ h))))
(λ s → C.comp s (G₁ h))
(λ s → G₁-β (C.comp s (G₁ h)))
(G₁-pres-comp f g) ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp f g)) (F₁-η h) ◃∙
ap G₁ (! (F.pres-comp (G₁ (D.comp f g)) (G₁ h))) ◃∙
ap (λ s → G₁ (F₁ (C.comp s (G₁ h)))) (G₁-pres-comp f g) ◃∙
G₁-β (C.comp (C.comp (G₁ f) (G₁ g)) (G₁ h)) ◃∙
C.assoc (G₁ f) (G₁ g) (G₁ h) ◃∎
=ₛ⟨ 1 & 2 & !ₛ $
homotopy-naturality
(λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h))))
(λ s → G₁ (F₁ (C.comp s (G₁ h))))
(λ s → ap G₁ (! (F.pres-comp s (G₁ h))))
(G₁-pres-comp f g) ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp f g)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (G₁-pres-comp f g) ◃∙
ap G₁ (! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h))) ◃∙
G₁-β (C.comp (C.comp (G₁ f) (G₁ g)) (G₁ h)) ◃∙
C.assoc (G₁ f) (G₁ g) (G₁ h) ◃∎
=ₛ⟨ 1 & 1 & ap-seq-=ₛ (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (G₁-pres-comp-β f g) ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp f g)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η g)) ◃∙
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (ap G₁ (! (F.pres-comp (G₁ f) (G₁ g)))) ◃∙
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (G₁-β (C.comp (G₁ f) (G₁ g))) ◃∙
ap G₁ (! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h))) ◃∙
G₁-β (C.comp (C.comp (G₁ f) (G₁ g)) (G₁ h)) ◃∙
C.assoc (G₁ f) (G₁ g) (G₁ h) ◃∎
=ₛ₁⟨ 3 & 1 & step₅ ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp f g)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η g)) ◃∙
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (ap G₁ (! (F.pres-comp (G₁ f) (G₁ g)))) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β (F₁ (C.comp (G₁ f) (G₁ g)))) ◃∙
ap G₁ (! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h))) ◃∙
G₁-β (C.comp (C.comp (G₁ f) (G₁ g)) (G₁ h)) ◃∙
C.assoc (G₁ f) (G₁ g) (G₁ h) ◃∎
=ₛ₁⟨ 2 & 1 & ∘-ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) G₁ (! (F.pres-comp (G₁ f) (G₁ g))) ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp f g)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η g)) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ s)) (F₁ (G₁ h)))) (! (F.pres-comp (G₁ f) (G₁ g))) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β (F₁ (C.comp (G₁ f) (G₁ g)))) ◃∙
ap G₁ (! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h))) ◃∙
G₁-β (C.comp (C.comp (G₁ f) (G₁ g)) (G₁ h)) ◃∙
C.assoc (G₁ f) (G₁ g) (G₁ h) ◃∎
=ₛ⟨ 2 & 2 & homotopy-naturality
(λ s → G₁ (D.comp (F₁ (G₁ s)) (F₁ (G₁ h))))
(λ s → G₁ (D.comp s (F₁ (G₁ h))))
(λ t → ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β t))
(! (F.pres-comp (G₁ f) (G₁ g))) ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp f g)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η g)) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β (D.comp (F₁ (G₁ f)) (F₁ (G₁ g)))) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (! (F.pres-comp (G₁ f) (G₁ g))) ◃∙
ap G₁ (! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h))) ◃∙
G₁-β (C.comp (C.comp (G₁ f) (G₁ g)) (G₁ h)) ◃∙
C.assoc (G₁ f) (G₁ g) (G₁ h) ◃∎
=ₛ⟨ 0 & 3 & step₈ ⟩
ap (λ s → G₁ (D.comp (D.comp s g) h)) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) s) h)) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) s)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (! (F.pres-comp (G₁ f) (G₁ g))) ◃∙
ap G₁ (! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h))) ◃∙
G₁-β (C.comp (C.comp (G₁ f) (G₁ g)) (G₁ h)) ◃∙
C.assoc (G₁ f) (G₁ g) (G₁ h) ◃∎
=ₛ⟨ 5 & 2 & !ₛ $
homotopy-naturality-to-idf (G₁ ∘ F₁) G₁-β (C.assoc (G₁ f) (G₁ g) (G₁ h)) ⟩
ap (λ s → G₁ (D.comp (D.comp s g) h)) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) s) h)) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) s)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (! (F.pres-comp (G₁ f) (G₁ g))) ◃∙
ap G₁ (! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h))) ◃∙
ap (G₁ ∘ F₁) (C.assoc (G₁ f) (G₁ g) (G₁ h)) ◃∙
G₁-β (C.comp (G₁ f) (C.comp (G₁ g) (G₁ h))) ◃∎
=ₛ⟨ 3 & 3 & step₁₀ ⟩
ap (λ s → G₁ (D.comp (D.comp s g) h)) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) s) h)) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) s)) (F₁-η h) ◃∙
ap G₁ (D.assoc (F₁ (G₁ f)) (F₁ (G₁ g)) (F₁ (G₁ h))) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (! (F.pres-comp (G₁ g) (G₁ h))) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h)))) ◃∙
G₁-β (C.comp (G₁ f) (C.comp (G₁ g) (G₁ h))) ◃∎
=ₛ⟨ 0 & 4 & step₁₁ ⟩
ap G₁ (D.assoc f g h) ◃∙
ap (λ s → G₁ (D.comp s (D.comp g h))) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp s h))) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp (F₁ (G₁ g)) s))) (F₁-η h) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (! (F.pres-comp (G₁ g) (G₁ h))) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h)))) ◃∙
G₁-β (C.comp (G₁ f) (C.comp (G₁ g) (G₁ h))) ◃∎
=ₛ⟨ 1 & 3 & step₁₂ ⟩
ap G₁ (D.assoc f g h) ◃∙
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η g) (F₁-η h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (F₁-β (D.comp (F₁ (G₁ g)) (F₁ (G₁ h)))) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (! (F.pres-comp (G₁ g) (G₁ h))) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h)))) ◃∙
G₁-β (C.comp (G₁ f) (C.comp (G₁ g) (G₁ h))) ◃∎
=ₛ⟨ 3 & 2 & !ₛ $
homotopy-naturality
(G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁ ∘ G₁)
(G₁ ∘ D.comp (F₁ (G₁ f)))
(ap (G₁ ∘ D.comp (F₁ (G₁ f))) ∘ F₁-β)
(! (F.pres-comp (G₁ g) (G₁ h))) ⟩
ap G₁ (D.assoc f g h) ◃∙
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η g) (F₁-η h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁ ∘ G₁) (! (F.pres-comp (G₁ g) (G₁ h))) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (F₁-β (F₁ (C.comp (G₁ g) (G₁ h)))) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h)))) ◃∙
G₁-β (C.comp (G₁ f) (C.comp (G₁ g) (G₁ h))) ◃∎
=ₛ₁⟨ 3 & 1 & ap-∘ (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) G₁ (! (F.pres-comp (G₁ g) (G₁ h))) ⟩
ap G₁ (D.assoc f g h) ◃∙
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η g) (F₁-η h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (ap G₁ (! (F.pres-comp (G₁ g) (G₁ h)))) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (F₁-β (F₁ (C.comp (G₁ g) (G₁ h)))) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h)))) ◃∙
G₁-β (C.comp (G₁ f) (C.comp (G₁ g) (G₁ h))) ◃∎
=ₛ₁⟨ 4 & 1 &
! $ ap (ap (G₁ ∘ D.comp (F₁ (G₁ f)))) $
F₁-is-equiv.adj (G₀ x) (G₀ z) (C.comp (G₁ g) (G₁ h)) ⟩
ap G₁ (D.assoc f g h) ◃∙
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η g) (F₁-η h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (ap G₁ (! (F.pres-comp (G₁ g) (G₁ h)))) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (ap F₁ (G₁-β (C.comp (G₁ g) (G₁ h)))) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h)))) ◃∙
G₁-β (C.comp (G₁ f) (C.comp (G₁ g) (G₁ h))) ◃∎
=ₛ₁⟨ 4 & 1 & ∘-ap (G₁ ∘ D.comp (F₁ (G₁ f))) F₁ (G₁-β (C.comp (G₁ g) (G₁ h))) ⟩
ap G₁ (D.assoc f g h) ◃∙
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η g) (F₁-η h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (ap G₁ (! (F.pres-comp (G₁ g) (G₁ h)))) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (G₁-β (C.comp (G₁ g) (G₁ h))) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h)))) ◃∙
G₁-β (C.comp (G₁ f) (C.comp (G₁ g) (G₁ h))) ◃∎
=ₛ⟨ 2 & 3 & ap-seq-=ₛ (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (!ₛ (G₁-pres-comp-β g h)) ⟩
ap G₁ (D.assoc f g h) ◃∙
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (G₁-pres-comp g h) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h)))) ◃∙
G₁-β (C.comp (G₁ f) (C.comp (G₁ g) (G₁ h))) ◃∎
=ₛ⟨ 2 & 2 &
homotopy-naturality
(G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁)
(G₁ ∘ F₁ ∘ C.comp (G₁ f))
(λ s → ap G₁ (! (F.pres-comp (G₁ f) s)))
(G₁-pres-comp g h) ⟩
ap G₁ (D.assoc f g h) ◃∙
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (G₁ (D.comp g h)))) ◃∙
ap (G₁ ∘ F₁ ∘ C.comp (G₁ f)) (G₁-pres-comp g h) ◃∙
G₁-β (C.comp (G₁ f) (C.comp (G₁ g) (G₁ h))) ◃∎
=ₛ⟨ 3 & 2 &
homotopy-naturality
(G₁ ∘ F₁ ∘ C.comp (G₁ f))
(C.comp (G₁ f))
(G₁-β ∘ C.comp (G₁ f))
(G₁-pres-comp g h) ⟩
ap G₁ (D.assoc f g h) ◃∙
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (G₁ (D.comp g h)))) ◃∙
G₁-β (C.comp (G₁ f) (G₁ (D.comp g h))) ◃∙
ap (C.comp (G₁ f)) (G₁-pres-comp g h) ◃∎
=ₛ⟨ 1 & 3 & !ₛ (G₁-pres-comp-β f (D.comp g h)) ⟩
ap G₁ (D.assoc f g h) ◃∙
G₁-pres-comp f (D.comp g h) ◃∙
ap (C.comp (G₁ f)) (G₁-pres-comp g h) ◃∎ ∎ₛ
where
step₅ : ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (G₁-β (C.comp (G₁ f) (G₁ g)))
==
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β (F₁ (C.comp (G₁ f) (G₁ g))))
step₅ =
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (G₁-β (C.comp (G₁ f) (G₁ g)))
=⟨ ap-∘ (λ s → G₁ (D.comp s (F₁ (G₁ h)))) F₁ (G₁-β (C.comp (G₁ f) (G₁ g))) ⟩
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (ap F₁ (G₁-β (C.comp (G₁ f) (G₁ g))))
=⟨ ap (ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))))
(F₁-is-equiv.adj (G₀ w) (G₀ y) (C.comp (G₁ f) (G₁ g))) ⟩
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β (F₁ (C.comp (G₁ f) (G₁ g)))) =∎
step₈ : ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp f g)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η g)) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β (D.comp (F₁ (G₁ f)) (F₁ (G₁ g)))) ◃∎
=ₛ
ap (λ s → G₁ (D.comp (D.comp s g) h)) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) s) h)) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) s)) (F₁-η h) ◃∎
step₈ =
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp f g)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η g)) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β (D.comp (F₁ (G₁ f)) (F₁ (G₁ g)))) ◃∎
=ₛ₁⟨ 1 & 1 & ap (ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))))
(! (ap-ap2 G₁ D.comp (F₁-η f) (F₁-η g))) ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp f g)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) (ap G₁ (ap2 D.comp (F₁-η f) (F₁-η g))) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β (D.comp (F₁ (G₁ f)) (F₁ (G₁ g)))) ◃∎
=ₛ₁⟨ 1 & 1 & ∘-ap (λ s → G₁ (D.comp (F₁ s) (F₁ (G₁ h)))) G₁ (ap2 D.comp (F₁-η f) (F₁-η g)) ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp f g)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ s)) (F₁ (G₁ h)))) (ap2 D.comp (F₁-η f) (F₁-η g)) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β (D.comp (F₁ (G₁ f)) (F₁ (G₁ g)))) ◃∎
=ₛ⟨ 0 & 2 & !ₛ $
homotopy-naturality (λ s → G₁ (D.comp s h))
(λ s → G₁ (D.comp (F₁ (G₁ s)) (F₁ (G₁ h))))
(λ s → ap2 (λ s t → G₁ (D.comp s t)) (F₁-η s) (F₁-η h))
(ap2 D.comp (F₁-η f) (F₁-η g)) ⟩
ap (λ s → G₁ (D.comp s h)) (ap2 D.comp (F₁-η f) (F₁-η g)) ◃∙
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp (F₁ (G₁ f)) (F₁ (G₁ g)))) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β (D.comp (F₁ (G₁ f)) (F₁ (G₁ g)))) ◃∎
=ₛ⟨ 1 & 1 & ap2-out' (λ s t → G₁ (D.comp s t)) (F₁-η (D.comp (F₁ (G₁ f)) (F₁ (G₁ g)))) (F₁-η h) ⟩
ap (λ s → G₁ (D.comp s h)) (ap2 D.comp (F₁-η f) (F₁-η g)) ◃∙
ap (λ t → G₁ (D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) t)) (F₁-η h) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-η (D.comp (F₁ (G₁ f)) (F₁ (G₁ g)))) ◃∙
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (F₁-β (D.comp (F₁ (G₁ f)) (F₁ (G₁ g)))) ◃∎
=ₛ⟨ 2 & 2 &
ap-seq-=ₛ (λ s → G₁ (D.comp s (F₁ (G₁ h)))) $
=ₛ-in {s = F₁-η (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) ◃∙
F₁-β (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) ◃∎}
{t = D.comp (F₁ (G₁ f)) (F₁ (G₁ g)) ∎∎}
(!-inv-l (F₁-β (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))))) ⟩
ap (λ s → G₁ (D.comp s h)) (ap2 D.comp (F₁-η f) (F₁-η g)) ◃∙
ap (λ t → G₁ (D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) t)) (F₁-η h) ◃∎
=ₛ₁⟨ 0 & 1 & ap-ap2 (λ s → G₁ (D.comp s h)) D.comp (F₁-η f) (F₁-η g) ⟩
ap2 (λ s t → G₁ (D.comp (D.comp s t) h)) (F₁-η f) (F₁-η g) ◃∙
ap (λ t → G₁ (D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) t)) (F₁-η h) ◃∎
=ₛ⟨ 0 & 1 & ap2-out (λ s t → G₁ (D.comp (D.comp s t) h)) (F₁-η f) (F₁-η g) ⟩
ap (λ s → G₁ (D.comp (D.comp s g) h)) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) s) h)) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) s)) (F₁-η h) ◃∎ ∎ₛ
step₁₀' : ap (λ s → D.comp s (F₁ (G₁ h))) (! (F.pres-comp (G₁ f) (G₁ g))) ◃∙
! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h)) ◃∙
ap F₁ (C.assoc (G₁ f) (G₁ g) (G₁ h)) ◃∎
=ₛ
D.assoc (F₁ (G₁ f)) (F₁ (G₁ g)) (F₁ (G₁ h)) ◃∙
ap (D.comp (F₁ (G₁ f))) (! (F.pres-comp (G₁ g) (G₁ h))) ◃∙
! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h))) ◃∎
step₁₀' =
ap (λ s → D.comp s (F₁ (G₁ h))) (! (F.pres-comp (G₁ f) (G₁ g))) ◃∙
! e₀₋₁ ◃∙
e₀₋₄ ◃∎
=ₛ₁⟨ 0 & 1 & ap-! (λ s → D.comp s (F₁ (G₁ h))) (F.pres-comp (G₁ f) (G₁ g)) ⟩
! e₁₋₂ ◃∙ ! e₀₋₁ ◃∙ e₀₋₄ ◃∎
=ₛ⟨ post-rotate-seq-in {p = ! e₁₋₂ ◃∙ ! e₀₋₁ ◃∙ e₀₋₄ ◃∎} $
pre-rotate'-seq-in {p = e₀₋₁ ◃∙ e₁₋₂ ◃∎} $
!ₛ $ F.pres-comp-coh (G₁ f) (G₁ g) (G₁ h) ⟩
e₂₋₃ ◃∙ ! e₅₋₃ ◃∙ ! e₄₋₅ ◃∎
=ₛ₁⟨ 1 & 1 & !-ap (D.comp (F₁ (G₁ f))) (F.pres-comp (G₁ g) (G₁ h)) ⟩
e₂₋₃ ◃∙
ap (D.comp (F₁ (G₁ f))) (! (F.pres-comp (G₁ g) (G₁ h))) ◃∙
! e₄₋₅ ◃∎ ∎ₛ
where
t₀ : D.Arr (F₀ (G₀ w)) (F₀ (G₀ z))
t₀ = F₁ (C.comp (C.comp (G₁ f) (G₁ g)) (G₁ h))
t₁ : D.Arr (F₀ (G₀ w)) (F₀ (G₀ z))
t₁ = D.comp (F₁ (C.comp (G₁ f) (G₁ g))) (F₁ (G₁ h))
t₂ : D.Arr (F₀ (G₀ w)) (F₀ (G₀ z))
t₂ = D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) (F₁ (G₁ h))
t₃ : D.Arr (F₀ (G₀ w)) (F₀ (G₀ z))
t₃ = D.comp (F₁ (G₁ f)) (D.comp (F₁ (G₁ g)) (F₁ (G₁ h)))
t₄ : D.Arr (F₀ (G₀ w)) (F₀ (G₀ z))
t₄ = F₁ (C.comp (G₁ f) (C.comp (G₁ g) (G₁ h)))
t₅ = D.comp (F₁ (G₁ f)) (F₁ (C.comp (G₁ g) (G₁ h)))
e₀₋₁ : t₀ == t₁
e₀₋₁ = F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h)
e₁₋₂ : t₁ == t₂
e₁₋₂ = ap (λ s → D.comp s (F₁ (G₁ h))) (F.pres-comp (G₁ f) (G₁ g))
e₂₋₃ : t₂ == t₃
e₂₋₃ = D.assoc (F₁ (G₁ f)) (F₁ (G₁ g)) (F₁ (G₁ h))
e₀₋₄ : t₀ == t₄
e₀₋₄ = ap F₁ (C.assoc (G₁ f) (G₁ g) (G₁ h))
e₄₋₅ : t₄ == t₅
e₄₋₅ = F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h))
e₅₋₃ : t₅ == t₃
e₅₋₃ = ap (D.comp (F₁ (G₁ f))) (F.pres-comp (G₁ g) (G₁ h))
step₁₀ : ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (! (F.pres-comp (G₁ f) (G₁ g))) ◃∙
ap G₁ (! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h))) ◃∙
ap (G₁ ∘ F₁) (C.assoc (G₁ f) (G₁ g) (G₁ h)) ◃∎
=ₛ
ap G₁ (D.assoc (F₁ (G₁ f)) (F₁ (G₁ g)) (F₁ (G₁ h))) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (! (F.pres-comp (G₁ g) (G₁ h))) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h)))) ◃∎
step₁₀ =
ap (λ s → G₁ (D.comp s (F₁ (G₁ h)))) (! (F.pres-comp (G₁ f) (G₁ g))) ◃∙
ap G₁ (! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h))) ◃∙
ap (G₁ ∘ F₁) (C.assoc (G₁ f) (G₁ g) (G₁ h)) ◃∎
=ₛ₁⟨ 0 & 1 & ap-∘ G₁ (λ s → D.comp s (F₁ (G₁ h))) (! (F.pres-comp (G₁ f) (G₁ g))) ⟩
ap G₁ (ap (λ s → D.comp s (F₁ (G₁ h))) (! (F.pres-comp (G₁ f) (G₁ g)))) ◃∙
ap G₁ (! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h))) ◃∙
ap (G₁ ∘ F₁) (C.assoc (G₁ f) (G₁ g) (G₁ h)) ◃∎
=ₛ₁⟨ 2 & 1 & ap-∘ G₁ F₁ (C.assoc (G₁ f) (G₁ g) (G₁ h)) ⟩
ap G₁ (ap (λ s → D.comp s (F₁ (G₁ h))) (! (F.pres-comp (G₁ f) (G₁ g)))) ◃∙
ap G₁ (! (F.pres-comp (C.comp (G₁ f) (G₁ g)) (G₁ h))) ◃∙
ap G₁ (ap F₁ (C.assoc (G₁ f) (G₁ g) (G₁ h))) ◃∎
=ₛ⟨ ap-seq-=ₛ G₁ step₁₀' ⟩
ap G₁ (D.assoc (F₁ (G₁ f)) (F₁ (G₁ g)) (F₁ (G₁ h))) ◃∙
ap G₁ (ap (D.comp (F₁ (G₁ f))) (! (F.pres-comp (G₁ g) (G₁ h)))) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h)))) ◃∎
=ₛ₁⟨ 1 & 1 & ∘-ap G₁ (D.comp (F₁ (G₁ f))) (! (F.pres-comp (G₁ g) (G₁ h))) ⟩
ap G₁ (D.assoc (F₁ (G₁ f)) (F₁ (G₁ g)) (F₁ (G₁ h))) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (! (F.pres-comp (G₁ g) (G₁ h))) ◃∙
ap G₁ (! (F.pres-comp (G₁ f) (C.comp (G₁ g) (G₁ h)))) ◃∎ ∎ₛ
step₁₁ :
ap (λ s → G₁ (D.comp (D.comp s g) h)) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) s) h)) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) s)) (F₁-η h) ◃∙
ap G₁ (D.assoc (F₁ (G₁ f)) (F₁ (G₁ g)) (F₁ (G₁ h))) ◃∎
=ₛ
ap G₁ (D.assoc f g h) ◃∙
ap (λ s → G₁ (D.comp s (D.comp g h))) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp s h))) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp (F₁ (G₁ g)) s))) (F₁-η h) ◃∎
step₁₁ =
ap (λ s → G₁ (D.comp (D.comp s g) h)) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) s) h)) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) s)) (F₁-η h) ◃∙
ap G₁ (D.assoc (F₁ (G₁ f)) (F₁ (G₁ g)) (F₁ (G₁ h))) ◃∎
=ₛ⟨ 2 & 2 &
homotopy-naturality (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) (F₁ (G₁ g))) s))
(λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp (F₁ (G₁ g)) s)))
(λ s → ap G₁ (D.assoc (F₁ (G₁ f)) (F₁ (G₁ g)) s))
(F₁-η h) ⟩
ap (λ s → G₁ (D.comp (D.comp s g) h)) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) s) h)) (F₁-η g) ◃∙
ap G₁ (D.assoc (F₁ (G₁ f)) (F₁ (G₁ g)) h) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp (F₁ (G₁ g)) s))) (F₁-η h) ◃∎
=ₛ⟨ 1 & 2 &
homotopy-naturality (λ s → G₁ (D.comp (D.comp (F₁ (G₁ f)) s) h))
(λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp s h)))
(λ s → ap G₁ (D.assoc (F₁ (G₁ f)) s h))
(F₁-η g) ⟩
ap (λ s → G₁ (D.comp (D.comp s g) h)) (F₁-η f) ◃∙
ap G₁ (D.assoc (F₁ (G₁ f)) g h) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp s h))) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp (F₁ (G₁ g)) s))) (F₁-η h) ◃∎
=ₛ⟨ 0 & 2 &
homotopy-naturality (λ s → G₁ (D.comp (D.comp s g) h))
(λ s → G₁ (D.comp s (D.comp g h)))
(λ s → ap G₁ (D.assoc s g h))
(F₁-η f) ⟩
ap G₁ (D.assoc f g h) ◃∙
ap (λ s → G₁ (D.comp s (D.comp g h))) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp s h))) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp (F₁ (G₁ g)) s))) (F₁-η h) ◃∎ ∎ₛ
step₁₂ : ap (λ s → G₁ (D.comp s (D.comp g h))) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp s h))) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp (F₁ (G₁ g)) s))) (F₁-η h) ◃∎
=ₛ
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η g) (F₁-η h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (F₁-β (D.comp (F₁ (G₁ g)) (F₁ (G₁ h)))) ◃∎
step₁₂ =
ap (λ s → G₁ (D.comp s (D.comp g h))) (F₁-η f) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp s h))) (F₁-η g) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (D.comp (F₁ (G₁ g)) s))) (F₁-η h) ◃∎
=ₛ⟨ 1 & 2 & !ₛ (ap2-out (λ s t → G₁ (D.comp (F₁ (G₁ f)) (D.comp s t))) (F₁-η g) (F₁-η h)) ⟩
ap (λ s → G₁ (D.comp s (D.comp g h))) (F₁-η f) ◃∙
ap2 (λ s t → G₁ (D.comp (F₁ (G₁ f)) (D.comp s t))) (F₁-η g) (F₁-η h) ◃∎
=ₛ₁⟨ 1 & 1 & ! (ap-ap2 (G₁ ∘ D.comp (F₁ (G₁ f))) D.comp (F₁-η g) (F₁-η h)) ⟩
ap (λ s → G₁ (D.comp s (D.comp g h))) (F₁-η f) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (ap2 D.comp (F₁-η g) (F₁-η h)) ◃∎
=ₛ⟨ 2 & 0 &
ap-seq-=ₛ (G₁ ∘ D.comp (F₁ (G₁ f))) $
=ₛ-in {s = D.comp (F₁ (G₁ g)) (F₁ (G₁ h)) ∎∎}
{t = F₁-η (D.comp (F₁ (G₁ g)) (F₁ (G₁ h))) ◃∙
F₁-β (D.comp (F₁ (G₁ g)) (F₁ (G₁ h))) ◃∎}
(! (!-inv-l (F₁-β (D.comp (F₁ (G₁ g)) (F₁ (G₁ h)))))) ⟩
ap (λ s → G₁ (D.comp s (D.comp g h))) (F₁-η f) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (ap2 D.comp (F₁-η g) (F₁-η h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (F₁-η (D.comp (F₁ (G₁ g)) (F₁ (G₁ h)))) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (F₁-β (D.comp (F₁ (G₁ g)) (F₁ (G₁ h)))) ◃∎
=ₛ⟨ 1 & 2 &
homotopy-naturality (G₁ ∘ D.comp (F₁ (G₁ f)))
(G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁ ∘ G₁)
(ap (G₁ ∘ D.comp (F₁ (G₁ f))) ∘ F₁-η)
(ap2 D.comp (F₁-η g) (F₁-η h)) ⟩
ap (λ s → G₁ (D.comp s (D.comp g h))) (F₁-η f) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (F₁-η (D.comp g h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁ ∘ G₁) (ap2 D.comp (F₁-η g) (F₁-η h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (F₁-β (D.comp (F₁ (G₁ g)) (F₁ (G₁ h)))) ◃∎
=ₛ⟨ 0 & 2 & !ₛ (ap2-out (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h))) ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap (λ s → G₁ (D.comp (F₁ (G₁ f)) (F₁ (G₁ s)))) (ap2 D.comp (F₁-η g) (F₁-η h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (F₁-β (D.comp (F₁ (G₁ g)) (F₁ (G₁ h)))) ◃∎
=ₛ₁⟨ 1 & 1 & ap-ap2 (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁ ∘ G₁) D.comp (F₁-η g) (F₁-η h) ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap2 (λ s t → G₁ (D.comp (F₁ (G₁ f)) (F₁ (G₁ (D.comp s t))))) (F₁-η g) (F₁-η h) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (F₁-β (D.comp (F₁ (G₁ g)) (F₁ (G₁ h)))) ◃∎
=ₛ₁⟨ 1 & 1 &
! (ap-ap2 (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁)
(λ s t → G₁ (D.comp s t))
(F₁-η g)
(F₁-η h)) ⟩
ap2 (λ s t → G₁ (D.comp s t)) (F₁-η f) (F₁-η (D.comp g h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f)) ∘ F₁) (ap2 (λ s t → G₁ (D.comp s t)) (F₁-η g) (F₁-η h)) ◃∙
ap (G₁ ∘ D.comp (F₁ (G₁ f))) (F₁-β (D.comp (F₁ (G₁ g)) (F₁ (G₁ h)))) ◃∎ ∎ₛ
G : TwoSemiFunctor D' C
G =
record
{ F₀ = G₀
; F₁ = G₁
; pres-comp = G₁-pres-comp
; pres-comp-coh = G₁-pres-comp-coh
}
module G = TwoSemiFunctor G
module Comp = FunctorComposition N G
open Comp using () renaming (composition to functor) public
open TwoSemiFunctor functor public
abstract
pres-comp-β : {x y z : D.El} (f : D.Arr x y) (g : D.Arr y z)
→ pres-comp f g ◃∎
=ₛ
ap G.F₁ (N.pres-comp f g) ◃∙
G₁-pres-comp-seq (N.F₁ f) (N.F₁ g)
pres-comp-β f g =
pres-comp f g ◃∎
=ₛ⟨ Comp.pres-comp-β f g ⟩
ap G.F₁ (N.pres-comp f g) ◃∙
G₁-pres-comp (N.F₁ f) (N.F₁ g) ◃∎
=ₛ⟨ 1 & 1 & G₁-pres-comp-β (N.F₁ f) (N.F₁ g) ⟩
ap G.F₁ (N.pres-comp f g) ◃∙
G₁-pres-comp-seq (N.F₁ f) (N.F₁ g) ∎ₛ
open FunctorInverse
using ()
renaming (functor to functor-inverse) public
|
{
"alphanum_fraction": 0.3957586813,
"avg_line_length": 52.2074829932,
"ext": "agda",
"hexsha": "45388dcb8ba6e4d5c9fc2850d77f9c0334fde498",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/two-semi-categories/FunctorInverse.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/two-semi-categories/FunctorInverse.agda",
"max_line_length": 110,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/two-semi-categories/FunctorInverse.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": 15545,
"size": 30698
}
|
{-# OPTIONS --without-K --safe #-}
module Dodo.Nullary where
open import Dodo.Nullary.Disjoint public
open import Dodo.Nullary.Unique public
open import Dodo.Nullary.XOpt public
|
{
"alphanum_fraction": 0.7777777778,
"avg_line_length": 22.5,
"ext": "agda",
"hexsha": "e5c0c100f3548a00abe50c6780af9e299b7db64a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Nullary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Nullary.agda",
"max_line_length": 40,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Nullary.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 44,
"size": 180
}
|
-- WARNING: This file was generated automatically by Vehicle
-- and should not be modified manually!
-- Metadata
-- - Agda version: 2.6.2
-- - AISEC version: 0.1.0.1
-- - Time generated: ???
open import Data.Unit
module MyTestModule where
e1 : let x = ⊤ in x
e1 = checkProperty record
{ databasePath = DATABASE_PATH
; propertyUUID = ????
}
|
{
"alphanum_fraction": 0.6780626781,
"avg_line_length": 21.9375,
"ext": "agda",
"hexsha": "1a242244d333b730622c3c2457329fc5d0d31ea7",
"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": "7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Yiergot/vehicle",
"max_forks_repo_path": "examples/simple/let/let-output.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df",
"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": "Yiergot/vehicle",
"max_issues_repo_path": "examples/simple/let/let-output.agda",
"max_line_length": 60,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "Yiergot/vehicle",
"max_stars_repo_path": "examples/simple/let/let-output.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 107,
"size": 351
}
|
-- 2010-10-14
{-# OPTIONS --universe-polymorphism #-}
module ProjectionsPreserveGuardednessTrivialExample where
-- Coinduction is only available with universe polymorphism
postulate
Level : Set
zero : Level
suc : (i : Level) → Level
_⊔_ : Level → Level → Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO zero #-}
{-# BUILTIN LEVELSUC suc #-}
{-# BUILTIN LEVELMAX _⊔_ #-}
infixl 6 _⊔_
-- Coinduction
infix 1000 ♯_
postulate
∞ : ∀ {a} (A : Set a) → Set a
♯_ : ∀ {a} {A : Set a} → A → ∞ A
♭ : ∀ {a} {A : Set a} → ∞ A → A
{-# BUILTIN INFINITY ∞ #-}
{-# BUILTIN SHARP ♯_ #-}
{-# BUILTIN FLAT ♭ #-}
-- Products
infixr 4 _,_
infixr 2 _×_
record Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
open Σ public
syntax Σ A (λ x → B) = Σ[ x ∶ A ] B
_×_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a ⊔ b)
A × B = Σ[ x ∶ A ] B
-- Streams
infixr 5 _∷_
data Stream (A : Set) : Set where
_∷_ : (x : A) (xs : ∞ (Stream A)) → Stream A
mutual
repeat : {A : Set}(a : A) → Stream A
repeat a = a ∷ proj₂ (repeat' a)
repeat' : {A : Set}(a : A) → A × ∞ (Stream A)
repeat' a = a , ♯ repeat a
|
{
"alphanum_fraction": 0.5427385892,
"avg_line_length": 17.9850746269,
"ext": "agda",
"hexsha": "c7a637e152c27367377c135306675a14bf5cae9d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/succeed/ProjectionsPreserveGuardednessTrivialExample.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "np/agda-git-experiment",
"max_issues_repo_path": "test/succeed/ProjectionsPreserveGuardednessTrivialExample.agda",
"max_line_length": 62,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/ProjectionsPreserveGuardednessTrivialExample.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": 490,
"size": 1205
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Left-biased universe-sensitive functor and monad instances for These.
--
-- To minimize the universe level of the RawFunctor, we require that
-- elements of B are "lifted" to a copy of B at a higher universe level
-- (a ⊔ b).
-- See the Data.Product.Categorical.Examples for how this is done in a
-- Product-based similar setting.
------------------------------------------------------------------------
-- This functor can be understood as a notion of computation which can
-- either fail (this), succeed (that) or accumulate warnings whilst
-- delivering a successful computation (these).
-- It is a good alternative to Data.Product.Categorical when the notion
-- of warnings does not have a neutral element (e.g. List⁺).
{-# OPTIONS --without-K --safe #-}
open import Level
open import Algebra
module Data.These.Categorical.Left {c ℓ} (W : Semigroup c ℓ) (b : Level) where
open Semigroup W
open import Data.These.Categorical.Left.Base Carrier b public
open import Data.These
open import Category.Applicative
open import Category.Monad
module _ {a b} {A : Set a} {B : Set b} where
applicative : RawApplicative Theseₗ
applicative = record
{ pure = that
; _⊛_ = ap
} where
ap : ∀ {A B}→ Theseₗ (A → B) → Theseₗ A → Theseₗ B
ap (this w) t = this w
ap (that f) t = map₂ f t
ap (these w f) t = map (w ∙_) f t
monad : RawMonad Theseₗ
monad = record
{ return = that
; _>>=_ = bind
} where
bind : ∀ {A B} → Theseₗ A → (A → Theseₗ B) → Theseₗ B
bind (this w) f = this w
bind (that t) f = f t
bind (these w t) f = map₁ (w ∙_) (f t)
|
{
"alphanum_fraction": 0.6174377224,
"avg_line_length": 29.5789473684,
"ext": "agda",
"hexsha": "45f7b5ab67199f74a598eb86a44d95e3d8ea450a",
"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/These/Categorical/Left.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/These/Categorical/Left.agda",
"max_line_length": 78,
"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/These/Categorical/Left.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 475,
"size": 1686
}
|
{-# OPTIONS --without-K --safe #-}
module Dodo.Binary.Flip where
-- Stdlib imports
open import Level using (Level; _⊔_)
open import Function.Base using (flip)
open import Relation.Binary using (Rel; REL)
open import Relation.Binary using (Symmetric)
-- Local imports
open import Dodo.Binary.Equality
-- # Operations
-- ## Operations: ⊆₂
module _ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b}
{P : REL A B ℓ₁} {Q : REL A B ℓ₂} where
flip-⊆₂ : P ⊆₂ Q → flip P ⊆₂ flip Q
flip-⊆₂ (⊆: P⊆Q) = ⊆: (flip P⊆Q)
module _ {a ℓ₁ : Level} {A : Set a} {P : Rel A ℓ₁} where
flip-sym-⊆₂ : Symmetric P → P ⊆₂ flip P
flip-sym-⊆₂ symP = ⊆: (λ _ _ → symP)
-- ## Operations: ⇔₂
module _ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b}
{P : REL A B ℓ₁} {Q : REL A B ℓ₂} where
flip-⇔₂ : P ⇔₂ Q → flip P ⇔₂ flip Q
flip-⇔₂ = ⇔₂-compose flip-⊆₂ flip-⊆₂
module _ {a ℓ₁ : Level} {A : Set a} {P : Rel A ℓ₁} where
flip-sym-⇔₂ : Symmetric P → P ⇔₂ flip P
flip-sym-⇔₂ symP = ⇔₂-intro (flip-sym-⊆₂ symP) (flip-sym-⊆₂ symP)
|
{
"alphanum_fraction": 0.5893203883,
"avg_line_length": 23.4090909091,
"ext": "agda",
"hexsha": "1c91cdf988fe14c50e4e57426fcc5160fbedae3d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Binary/Flip.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Binary/Flip.agda",
"max_line_length": 67,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Binary/Flip.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 450,
"size": 1030
}
|
module MatchUpNames where
open import ParseTree
open import ScopeState
open import Data.Sum
open import Data.List hiding (lookup)
open import AgdaHelperFunctions
matchUpSignature : TypeSignature -> ScopeState TypeSignature
matchUpExpr : Expr -> ScopeState Expr
matchUpExpr (ident identifier₁) = do
x <- access identifier₁
return $ ident x
matchUpExpr (functionApp x x₁ {b} ) = do
r1 <- matchUpExpr x
r2 <- matchUpExpr x₁
return $ functionApp r1 r2 {b}
matchUpExpr (namedArgument arg {b} {bef} {aft}) = do
x <- matchUpSignature arg
return $ namedArgument x {b} {bef} {aft}
matchUpExpr x = return x
matchUpSignature (typeSignature funcName funcType) = do
newName <- access funcName
newType <- matchUpExpr funcType
return $ typeSignature newName newType
matchUpPragma : Pragma -> ScopeState Pragma
matchUpPragma (builtin concept definition) = do
x <- access definition
return $ builtin concept x
matchUpPragma x = return x
matchUpTree : ParseTree -> ScopeState ParseTree
matchUpTree (signature signature₁ range₁) = do
x <- matchUpSignature signature₁
return $ signature x range₁
matchUpTree (functionDefinition definitionOf params body range₁) = do
newDef <- access definitionOf
newParams <- mapState matchUpExpr params
newBody <- matchUpExpr body
return $ functionDefinition newDef newParams newBody range₁
matchUpTree (dataStructure dataName parameters indexInfo constructors range₁ {comments}) = do
newName <- access dataName
newParams <- mapState matchUpSignature parameters
newIndex <- matchUpExpr indexInfo
newCons <- mapState matchUpSignature constructors
return $ dataStructure newName newParams newIndex newCons range₁ {comments}
matchUpTree (pragma pragma₁ range₁) = do
x <- matchUpPragma pragma₁
return $ pragma x range₁
matchUpTree (moduleName id r) = do
x <- access id
return $ moduleName x r
matchUpTree x = return x
matchUpNames : List ParseTree -> ScopeState (List ParseTree)
matchUpNames list = mapState matchUpTree list
|
{
"alphanum_fraction": 0.7725,
"avg_line_length": 31.746031746,
"ext": "agda",
"hexsha": "d20610208dd31d299369f98c6d11ac0d671b09f3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "omega12345/RefactorAgda",
"max_forks_repo_path": "RefactorAgdaEngine/MatchUpNames.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "omega12345/RefactorAgda",
"max_issues_repo_path": "RefactorAgdaEngine/MatchUpNames.agda",
"max_line_length": 93,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "omega12345/RefactorAgda",
"max_stars_repo_path": "RefactorAgdaEngine/MatchUpNames.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z",
"num_tokens": 529,
"size": 2000
}
|
------------------------------------------------------------------------
-- Cyclic groups
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
import Equality.Path as P
module Group.Cyclic
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Prelude as P
hiding (id; _^_) renaming (_∘_ to _⊚_; _+_ to _⊕_)
open import Equality.Path.Isomorphisms eq
open import Equality.Path.Isomorphisms.Univalence eq
open import Equivalence-relation equality-with-J
using (Is-equivalence-relation)
open import Equivalence equality-with-J using (_≃_)
open import Erased.Cubical eq
open import Function-universe equality-with-J hiding (_∘_)
open import Group equality-with-J as G
using (Group; Abelian; _≃ᴳ_; Homomorphic)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as T using (∥_∥; ∣_∣)
open import Integer equality-with-J hiding (suc) renaming (_*_ to _⊛_)
import Nat equality-with-J as Nat
open import Quotient eq as Q using (_/_)
open Homomorphic
private
module ℤG = Group ℤ-group
private
variable
a : Level
A : Type a
g : A
G₁ G₂ : Group g
n : ℕ
i j k : ℤ
------------------------------------------------------------------------
-- Cyclic groups
-- The property of being generated by an element.
Generated-by : (G : Group g) → Group.Carrier G → Type g
Generated-by G g =
(x : Carrier) → ∥ (∃ λ (i : ℤ) → x ≡ g ^ i) ∥
where
open Group G
-- The property of being cyclic.
Cyclic : Group g → Type g
Cyclic G = ∥ ∃ (Generated-by G) ∥
-- Cyclic groups are abelian.
Cyclic→Abelian : (G : Group g) → Cyclic G → Abelian G
Cyclic→Abelian G c x y =
flip (T.rec Carrier-is-set) c λ (g , gen-by) →
flip (T.rec Carrier-is-set) (gen-by x) λ (i , x≡) →
flip (T.rec Carrier-is-set) (gen-by y) λ (j , y≡) →
x ∘ y ≡⟨ cong₂ _∘_ x≡ y≡ ⟩
g ^ i ∘ g ^ j ≡⟨ ^∘^ i ⟩
g ^ (i + j) ≡⟨ cong (g ^_) $ +-comm i ⟩
g ^ (j + i) ≡⟨ sym $ ^∘^ j ⟩
g ^ j ∘ g ^ i ≡⟨ sym $ cong₂ _∘_ y≡ x≡ ⟩∎
y ∘ x ∎
where
open Group G
-- If two groups are isomorphic, and one is generated by g, then the
-- other is generated by the image of g under the isomorphism.
≃ᴳ→Generated-by→Generated-by :
(G₁≃G₂ : G₁ ≃ᴳ G₂) →
Generated-by G₁ g →
Generated-by G₂ (to G₁≃G₂ g)
≃ᴳ→Generated-by→Generated-by
{G₁ = G₁} {G₂ = G₂} {g = g} G₁≃G₂ gen-by x =
flip T.∥∥-map (gen-by (_≃_.from (G₁≃G₂ .related) x)) λ (i , x≡) →
i
, (x ≡⟨ sym $ _≃_.from-to (G₁≃G₂ .related) x≡ ⟩
to G₁≃G₂ (g G₁.^ i) ≡⟨ G.→ᴳ-^ G₁≃G₂ g i ⟩∎
to G₁≃G₂ g G₂.^ i ∎)
where
module G₁ = Group G₁
module G₂ = Group G₂
-- If two groups are isomorphic, and one is cyclic, then the other one
-- is cyclic.
≃ᴳ→Cyclic→Cyclic : G₁ ≃ᴳ G₂ → Cyclic G₁ → Cyclic G₂
≃ᴳ→Cyclic→Cyclic G₁≃G₂ =
T.∥∥-map λ (_ , gen-by) →
_ , ≃ᴳ→Generated-by→Generated-by G₁≃G₂ gen-by
------------------------------------------------------------------------
-- The group of integers is cyclic
-- The group of integers is generated by + 1.
ℤ-generated-by-1 : Generated-by ℤ-group (+ 1)
ℤ-generated-by-1 i = ∣ i , sym (*-left-identity i) ∣
-- The group of integers is cyclic.
ℤ-cyclic : Cyclic ℤ-group
ℤ-cyclic = ∣ _ , ℤ-generated-by-1 ∣
------------------------------------------------------------------------
-- The group ℤ × ℤ is not cyclic
-- The direct product of the group of integers and the group of
-- integers is not cyclic.
ℤ×ℤ-not-cyclic : ¬ Cyclic (ℤ-group G.× ℤ-group)
ℤ×ℤ-not-cyclic =
T.rec ⊥-propositional λ (g , gen-by) →
flip (T.rec ⊥-propositional) (gen-by (+ 0 , + 1)) λ (i , 0,1≡) →
flip (T.rec ⊥-propositional) (gen-by (+ 1 , + 0)) λ (j , 1,0≡) →
lemma₂ g i j (0,1≡ , 1,0≡)
where
module G² = Group (ℤ-group G.× ℤ-group)
0≡*+→≡0 : ∀ n i → + 0 ≡ i *+ P.suc n → i ≡ + 0
0≡*+→≡0 n i 0≡ = case -⊎0⊎+ i of λ where
(inj₁ neg) → ⊥-elim $ ¬-0 (<0→*+suc<0 i n neg) (sym 0≡)
(inj₂ (inj₁ ≡0)) → ≡0
(inj₂ (inj₂ pos)) → ⊥-elim $ ¬+0 (>0→*+suc> i n pos) (sym 0≡)
1≢0* : ∀ i → + 1 ≢ + 0 ⊛ i
1≢0* i =
+ 1 ≡ + 0 ⊛ i ↝⟨ flip trans (ℤG.id^ i) ⟩
+ 1 ≡ + 0 ↝⟨ +[1+]≢- ⟩□
⊥ □
-≡0→≡0 : - i ≡ + 0 → i ≡ + 0
-≡0→≡0 {i = i} hyp =
i ≡⟨ sym $ ℤG.involutive _ ⟩
- - i ≡⟨ cong -_ hyp ⟩
- + 0 ≡⟨ ℤG.identity ⟩∎
+ 0 ∎
lemma₁ :
∀ g₁ g₂ i j →
¬ ((+ 0 ≡ g₁ ⊛ i × + 1 ≡ g₂ ⊛ i) ×
(+ 1 ≡ g₁ ⊛ j × + 0 ≡ g₂ ⊛ j))
lemma₁ _ _ (+ zero) _ =
(_ × + 1 ≡ + 0) × _ ↝⟨ proj₂ ⊚ proj₁ ⟩
+ 1 ≡ + 0 ↝⟨ +[1+]≢- ⟩□
⊥ □
lemma₁ g₁ g₂ (+ P.suc m) j =
(+ 0 ≡ g₁ *+ P.suc m × _) × (+ 1 ≡ g₁ ⊛ j × _) ↝⟨ Σ-map (0≡*+→≡0 m _ ⊚ proj₁) proj₁ ⟩
g₁ ≡ + 0 × + 1 ≡ g₁ ⊛ j ↝⟨ (λ (p , q) → trans q (cong (_⊛ j) p)) ⟩
+ 1 ≡ (+ 0) ⊛ j ↝⟨ 1≢0* j ⟩□
⊥ □
lemma₁ g₁ g₂ -[1+ m ] j =
(+ 0 ≡ (- g₁) *+ P.suc m × _) × (+ 1 ≡ g₁ ⊛ j × _) ↝⟨ Σ-map (0≡*+→≡0 m _ ⊚ proj₁) proj₁ ⟩
- g₁ ≡ + 0 × + 1 ≡ g₁ ⊛ j ↝⟨ Σ-map -≡0→≡0 P.id ⟩
g₁ ≡ + 0 × + 1 ≡ g₁ ⊛ j ↝⟨ (λ (p , q) → trans q (cong (_⊛ j) p)) ⟩
+ 1 ≡ (+ 0) ⊛ j ↝⟨ 1≢0* j ⟩□
⊥ □
lemma₂ : ∀ g i j → ¬ ((+ 0 , + 1) ≡ g G².^ i × (+ 1 , + 0) ≡ g G².^ j)
lemma₂ g@(g₁ , g₂) i j =
(+ 0 , + 1) ≡ g G².^ i × (+ 1 , + 0) ≡ g G².^ j ↝⟨ Σ-map (flip trans (G.^-× ℤ-group ℤ-group i))
(flip trans (G.^-× ℤ-group ℤ-group j)) ⟩
(+ 0 , + 1) ≡ (g₁ ⊛ i , g₂ ⊛ i) ×
(+ 1 , + 0) ≡ (g₁ ⊛ j , g₂ ⊛ j) ↔⟨ inverse $ ≡×≡↔≡ ×-cong ≡×≡↔≡ ⟩
(+ 0 ≡ g₁ ⊛ i × + 1 ≡ g₂ ⊛ i) ×
(+ 1 ≡ g₁ ⊛ j × + 0 ≡ g₂ ⊛ j) ↝⟨ lemma₁ g₁ g₂ i j ⟩□
⊥ □
-- The group of integers is not isomorphic to the direct product of
-- the group of integers and the group of integers.
ℤ≄ᴳℤ×ℤ : ¬ ℤ-group ≃ᴳ (ℤ-group G.× ℤ-group)
ℤ≄ᴳℤ×ℤ =
ℤ-group ≃ᴳ (ℤ-group G.× ℤ-group) ↝⟨ flip ≃ᴳ→Cyclic→Cyclic ℤ-cyclic ⟩
Cyclic (ℤ-group G.× ℤ-group) ↝⟨ ℤ×ℤ-not-cyclic ⟩□
⊥ □
-- The group of integers is not equal to the direct product of the
-- group of integers and the group of integers.
ℤ≢ℤ×ℤ : ℤ-group ≢ (ℤ-group G.× ℤ-group)
ℤ≢ℤ×ℤ =
ℤ-group ≡ (ℤ-group G.× ℤ-group) ↝⟨ flip (subst (ℤ-group ≃ᴳ_)) G.↝ᴳ-refl ⟩
ℤ-group ≃ᴳ (ℤ-group G.× ℤ-group) ↝⟨ ℤ≄ᴳℤ×ℤ ⟩□
⊥ □
------------------------------------------------------------------------
-- The "equality modulo n" relation
-- Equality modulo n.
infix 4 _≡_mod_
_≡_mod_ : ℤ → ℤ → ℕ → Type
i ≡ j mod n = ∥ (∃ λ k → i ≡ j + k *+ n) ∥
-- The relation _≡_mod n is an equivalence relation.
≡-mod-is-equivalence-relation :
∀ n → Is-equivalence-relation (_≡_mod n)
≡-mod-is-equivalence-relation n = λ where
.Is-equivalence-relation.reflexive {x = i} →
∣ + 0
, (i ≡⟨ sym +-right-identity ⟩
i + + 0 ≡⟨ cong (_+_ i) $ sym $ ℤG.id^+ n ⟩∎
i + + 0 *+ n ∎)
∣
.Is-equivalence-relation.symmetric {x = i} {y = j} →
T.∥∥-map λ (k , i≡j+kn) →
- k
, (j ≡⟨ sym +-right-identity ⟩
j + + 0 ≡⟨ cong (_+_ j) $ sym $ +-right-inverse (k *+ n) ⟩
j + (k *+ n - k *+ n) ≡⟨ cong (_+_ j) $ cong (_+_ (k *+ n)) $ ℤG.^+⁻¹ n ⟩
j + (k *+ n + - k *+ n) ≡⟨ +-assoc j ⟩
j + k *+ n + - k *+ n ≡⟨ cong (_+ - k *+ n) $ sym i≡j+kn ⟩∎
i + - k *+ n ∎)
.Is-equivalence-relation.transitive {x = i} {y = j} {z = k} →
T.rec (Π-closure ext 1 λ _ →
T.truncation-is-proposition) λ (l₁ , i≡j+l₁n) →
T.∥∥-map λ (l₂ , j≡k+l₂n) →
l₂ + l₁
, (i ≡⟨ i≡j+l₁n ⟩
j + l₁ *+ n ≡⟨ cong (_+ l₁ *+ n) j≡k+l₂n ⟩
k + l₂ *+ n + l₁ *+ n ≡⟨ sym $ +-assoc k ⟩
k + (l₂ *+ n + l₁ *+ n) ≡⟨ cong (_+_ k) $ sym $ *+-distrib-+ n ⟩∎
k + (l₂ + l₁) *+ n ∎)
-- If i and j are equal modulo n, then i + k and j + k are also equal
-- modulo n.
+-cong : ∀ n j → i ≡ j mod n → i + k ≡ j + k mod n
+-cong {i = i} {k = k} n j = T.∥∥-map λ (l , i≡j+ln) →
l
, (i + k ≡⟨ cong (_+ k) i≡j+ln ⟩
j + l *+ n + k ≡⟨ sym $ +-assoc j ⟩
j + (l *+ n + k) ≡⟨ cong (_+_ j) $ +-comm (l *+ n) ⟩
j + (k + l *+ n) ≡⟨ +-assoc j ⟩∎
j + k + l *+ n ∎)
-- If i and j are equal modulo n, then - i and - j are also equal
-- modulo n.
negate-cong : ∀ n j → i ≡ j mod n → - i ≡ - j mod n
negate-cong {i = i} n j = T.∥∥-map λ (k , i≡j+kn) →
- k
, (- i ≡⟨ cong -_ i≡j+kn ⟩
- (j + k *+ n) ≡⟨ ℤG.∘⁻¹ {p = j} ⟩
- (k *+ n) + - j ≡⟨ +-comm (- (k *+ n)) ⟩
- j + - (k *+ n) ≡⟨ cong (_+_ (- j)) $ ℤG.^+⁻¹ n ⟩∎
- j + - k *+ n ∎)
-- If i and j are equal modulo n, then i *+ m and j *+ m are equal
-- modulo m * n.
*+-cong : ∀ m → i ≡ j mod n → i *+ m ≡ j *+ m mod m * n
*+-cong {i = i} {j = j} {n = n} m = T.∥∥-map λ (k , i≡j+kn) →
k
, (i *+ m ≡⟨ cong (_*+ m) i≡j+kn ⟩
(j + k *+ n) *+ m ≡⟨ ℤG.∘^+≡^+∘^+ (+-comm j) m ⟩
j *+ m + k *+ n *+ m ≡⟨ cong (_+_ (j *+ m)) $ ℤG.^+^+≡^+* n ⟩
j *+ m + k *+ (n * m) ≡⟨ cong (_+_ (j *+ m)) $ cong (k *+_) $ Nat.*-comm n ⟩∎
j *+ m + k *+ (m * n) ∎)
-- If i and j are equal modulo 2 * n, then ⌊ i /2⌋ and ⌊ j /2⌋ are
-- equal modulo n.
⌊/2⌋-cong : ∀ j n → i ≡ j mod 2 * n → ⌊ i /2⌋ ≡ ⌊ j /2⌋ mod n
⌊/2⌋-cong {i = i} j n = T.∥∥-map λ (k , i≡j+k2n) →
k
, (⌊ i /2⌋ ≡⟨ cong ⌊_/2⌋ i≡j+k2n ⟩
⌊ j + k *+ (2 * n) /2⌋ ≡⟨ cong (⌊_/2⌋ ⊚ (_+_ j) ⊚ (k *+_)) $ sym $ Nat.*-comm n ⟩
⌊ j + k *+ (n * 2) /2⌋ ≡⟨ cong (⌊_/2⌋ ⊚ (_+_ j)) $ sym $ ℤG.^+^+≡^+* n ⟩
⌊ j + (k *+ n) *+ 2 /2⌋ ≡⟨ ⌊+*+2/2⌋≡ j ⟩∎
⌊ j /2⌋ + k *+ n ∎)
-- It is not the case that 0 is equal to 1 modulo n, if n is at least
-- 2.
0≢1mod2+ : ∀ n → ¬ + 0 ≡ + 1 mod 2 ⊕ n
0≢1mod2+ n = T.rec ⊥-propositional $ uncurry lemma
where
lemma : ∀ k → + 0 ≢ + 1 + k *+ (2 ⊕ n)
lemma (+ 0) =
+ 0 ≡ + 1 + + 0 *+ (2 ⊕ n) ↝⟨ flip trans (cong (_+_ (+ 1)) $ ℤG.id^+ (2 ⊕ n)) ⟩
+ 0 ≡ + 1 + + 0 ↔⟨⟩
+ 0 ≡ + 1 ↝⟨ +[1+]≢- ⊚ sym ⟩□
⊥ □
lemma (+ suc k) =
+ 0 ≡ + 1 + + suc k *+ (2 ⊕ n) ↝⟨ flip ¬+0 ⊚ sym ⟩
¬ Positive (+ 1 + + suc k *+ (2 ⊕ n)) ↝⟨ _⊚ >0→>0→+>0 (+ 1) (+ suc k *+ (2 ⊕ n)) _ ⟩
¬ Positive (+ suc k *+ (2 ⊕ n)) ↝⟨ _$ >0→*+suc> (+ suc k) (suc n) _ ⟩□
⊥ □
lemma -[1+ zero ] =
+ 0 ≡ + 1 + -[1+ 0 ] *+ (2 ⊕ n) ↝⟨ flip trans (+-assoc (+ 1) {j = -[1+ 0 ]} {k = -[1+ 0 ] *+ (1 ⊕ n)}) ⟩
+ 0 ≡ + 1 + -[1+ 0 ] + -[1+ 0 ] *+ (1 ⊕ n) ↝⟨ flip trans +-left-identity ⟩
+ 0 ≡ -[1+ 0 ] *+ (1 ⊕ n) ↝⟨ flip ¬-0 ⊚ sym ⟩
¬ Negative (-[1+ 0 ] *+ (1 ⊕ n)) ↝⟨ _$ <0→*+suc<0 -[1+ 0 ] n _ ⟩□
⊥ □
lemma -[1+ suc k ] =
+ 0 ≡ + 1 + -[1+ suc k ] *+ (2 ⊕ n) ↝⟨ flip trans (+-assoc (+ 1) {j = -[1+ suc k ]} {k = -[1+ suc k ] *+ (1 ⊕ n)}) ⟩
+ 0 ≡ + 1 + -[1+ suc k ] + -[1+ suc k ] *+ (1 ⊕ n) ↔⟨⟩
+ 0 ≡ -[1+ k ] + -[1+ suc k ] *+ (1 ⊕ n) ↝⟨ flip ¬-0 ⊚ sym ⟩
¬ Negative (-[1+ k ] + -[1+ suc k ] *+ (1 ⊕ n)) ↝⟨ _⊚ <0→<0→+<0 -[1+ k ] (-[1+ suc k ] *+ (1 ⊕ n)) _ ⟩
¬ Negative (-[1+ suc k ] *+ (1 ⊕ n)) ↝⟨ _$ <0→*+suc<0 -[1+ suc k ] n _ ⟩□
⊥ □
-- It is not the case that ⌊_/2⌋ distributes over _+_ modulo 2 ⊕ n
-- (for any n).
¬⌊+/2⌋≡⌊/2⌋+⌊/2⌋mod2+ :
¬ (∀ i j → ⌊ i + j /2⌋ ≡ ⌊ i /2⌋ + ⌊ j /2⌋ mod 2 ⊕ n)
¬⌊+/2⌋≡⌊/2⌋+⌊/2⌋mod2+ {n = n} =
(∀ i j → ⌊ i + j /2⌋ ≡ ⌊ i /2⌋ + ⌊ j /2⌋ mod 2 ⊕ n) ↝⟨ (_$ (+ 1)) ⊚ (_$ (+ 1)) ⟩
+ 1 ≡ + 0 mod 2 ⊕ n ↝⟨ ≡-mod-is-equivalence-relation (2 ⊕ n)
.Is-equivalence-relation.symmetric ⟩
+ 0 ≡ + 1 mod 2 ⊕ n ↝⟨ 0≢1mod2+ n ⟩□
⊥ □
------------------------------------------------------------------------
-- Finite cyclic groups
-- ℤ/[1+ n ]ℤ is the group of integers with addition modulo 1 + n (the
-- finite cyclic group of order 1 + n).
ℤ/[1+_]ℤ : ℕ → Group lzero
ℤ/[1+ n ]ℤ = λ where
.Group.Carrier → ℤ / (_≡_mod suc n)
.Group.Carrier-is-set → Q./-is-set
.Group._∘_ → _+′_
.Group.id → Q.[ + 0 ]
.Group._⁻¹ → -′_
.Group.left-identity → left-identity
.Group.right-identity → right-identity
.Group.assoc → assoc
.Group.left-inverse → left-inverse
.Group.right-inverse → right-inverse
where
_+′_ : ℤ / (_≡_mod suc n) → ℤ / (_≡_mod suc n) → ℤ / (_≡_mod suc n)
_+′_ = Q.rec λ where
.Q.[]ʳ i → _+_ i Q./-map λ j₁ j₂ →
j₁ ≡ j₂ mod suc n ↝⟨ +-cong (suc n) j₂ ⟩
j₁ + i ≡ j₂ + i mod suc n ↝⟨ ≡⇒↝ _ $ cong₂ (_≡_mod suc n) (+-comm j₁) (+-comm j₂) ⟩□
i + j₁ ≡ i + j₂ mod suc n □
.Q.is-setʳ →
Π-closure ext 2 λ _ →
Q./-is-set
.Q.[]-respects-relationʳ {x = i₁} {y = i₂} i₁≡i₂ →
⟨ext⟩ $ Q.elim-prop λ where
.Q.is-propositionʳ _ → Q./-is-set
.Q.[]ʳ j → $⟨ i₁≡i₂ ⟩
i₁ ≡ i₂ mod suc n ↝⟨ +-cong (suc n) i₂ ⟩
i₁ + j ≡ i₂ + j mod suc n ↝⟨ Q.[]-respects-relation ⟩□
Q.[ i₁ + j ] ≡ Q.[ i₂ + j ] □
-′_ : ℤ / (_≡_mod suc n) → ℤ / (_≡_mod suc n)
-′_ = -_ Q./-map λ i₁ i₂ →
i₁ ≡ i₂ mod suc n ↝⟨ negate-cong (suc n) i₂ ⟩□
- i₁ ≡ - i₂ mod suc n □
left-identity : ∀ i → Q.[ + 0 ] +′ i ≡ i
left-identity = Q.elim-prop λ where
.Q.is-propositionʳ _ → Q./-is-set
.Q.[]ʳ _ → cong Q.[_] +-left-identity
right-identity : ∀ i → i +′ Q.[ + 0 ] ≡ i
right-identity = Q.elim-prop λ where
.Q.is-propositionʳ _ → Q./-is-set
.Q.[]ʳ _ → cong Q.[_] +-right-identity
assoc : ∀ i j k → (i +′ (j +′ k)) ≡ ((i +′ j) +′ k)
assoc = Q.elim-prop λ where
.Q.is-propositionʳ _ → Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Q./-is-set
.Q.[]ʳ i → Q.elim-prop λ where
.Q.is-propositionʳ _ → Π-closure ext 1 λ _ →
Q./-is-set
.Q.[]ʳ _ → Q.elim-prop λ where
.Q.is-propositionʳ _ → Q./-is-set
.Q.[]ʳ _ → cong Q.[_] $ +-assoc i
left-inverse : ∀ i → ((-′ i) +′ i) ≡ Q.[ + 0 ]
left-inverse = Q.elim-prop λ where
.Q.is-propositionʳ _ → Q./-is-set
.Q.[]ʳ i → cong Q.[_] $ +-left-inverse i
right-inverse : ∀ i → (i +′ (-′ i)) ≡ Q.[ + 0 ]
right-inverse = Q.elim-prop λ where
.Q.is-propositionʳ _ → Q./-is-set
.Q.[]ʳ i → cong Q.[_] $ +-right-inverse i
-- ℤ/[1+ n ]ℤ is cyclic.
ℤ/ℤ-cyclic : Cyclic ℤ/[1+ n ]ℤ
ℤ/ℤ-cyclic {n = n} =
∣ Q.[ + 1 ]
, (Q.elim-prop λ where
.Q.is-propositionʳ _ → T.truncation-is-proposition
.Q.[]ʳ i →
∣ i
, (Q.[ i ] ≡⟨ cong Q.[_] $ sym $ *-left-identity i ⟩
Q.[ + 1 ⊛ i ] ≡⟨ lemma i ⟩∎
Q.[ + 1 ] ℤ/.^ i ∎)
∣)
∣
where
module ℤ/ = Group ℤ/[1+ n ]ℤ
*+-lemma : ∀ n → Q.[ + 1 *+ n ] ≡ Q.[ + 1 ] ℤ/.^+ n
*+-lemma zero = refl _
*+-lemma (suc n) =
Q.[ + 1 *+ suc n ] ≡⟨⟩
Q.[ + 1 ] ℤ/.∘ Q.[ + 1 *+ n ] ≡⟨ cong (Q.[ + 1 ] ℤ/.∘_) $ *+-lemma n ⟩∎
Q.[ + 1 ] ℤ/.∘ Q.[ + 1 ] ℤ/.^+ n ∎
lemma : ∀ i → Q.[ + 1 ⊛ i ] ≡ Q.[ + 1 ] ℤ/.^ i
lemma (+ n) = *+-lemma n
lemma -[1+ n ] =
Q.[ + 1 ⊛ -[1+ n ] ] ≡⟨⟩
Q.[ -[ 1 ] *+ suc n ] ≡⟨ cong Q.[_] $ sym $ ℤG.^+⁻¹ {p = + 1} (suc n) ⟩
Q.[ - (+ 1 *+ suc n) ] ≡⟨⟩
Q.[ + 1 *+ suc n ] ℤ/.⁻¹ ≡⟨ cong ℤ/._⁻¹ $ *+-lemma (suc n) ⟩
(Q.[ + 1 ] ℤ/.^+ suc n) ℤ/.⁻¹ ≡⟨ ℤ/.^+⁻¹ {p = Q.[ + 1 ]} (suc n) ⟩
(Q.[ + 1 ] ℤ/.⁻¹) ℤ/.^+ suc n ≡⟨⟩
Q.[ + 1 ] ℤ/.^ -[1+ n ] ∎
-- ℤ/[1+ n ]ℤ is abelian.
ℤ/ℤ-abelian : Abelian ℤ/[1+ n ]ℤ
ℤ/ℤ-abelian = Cyclic→Abelian ℤ/[1+ _ ]ℤ ℤ/ℤ-cyclic
-- For finite cyclic groups of order at least 2 the number 0 is not
-- equal to 1.
--
-- The proof uses propositional extensionality.
ℤ/ℤ-0≢1 :
∀ n →
_≢_ {A = Group.Carrier ℤ/[1+ suc n ]ℤ}
Q.[ + 0 ] Q.[ + 1 ]
ℤ/ℤ-0≢1 n =
Stable-¬
[ Q.[ + 0 ] ≡ Q.[ + 1 ] ↔⟨ inverse $
Q.related≃[equal]
prop-ext
(≡-mod-is-equivalence-relation (2 P.+ n))
T.truncation-is-proposition ⟩
(+ 0 ≡ + 1 mod 2 ⊕ n) ↝⟨ 0≢1mod2+ n ⟩□
⊥ □
]
-- If any element in ℤ/2ℤ is added to itself we get 0.
private
module ℤ/2ℤ = Group ℤ/[1+ 1 ]ℤ
ℤ/2ℤ-+≡0 : ∀ i → i ℤ/2ℤ.∘ i ≡ ℤ/2ℤ.id
ℤ/2ℤ-+≡0 = Q.elim-prop λ where
.Q.is-propositionʳ _ → Q./-is-set
.Q.[]ʳ i → Q.[]-respects-relation
∣ i
, (i + i ≡⟨ cong (_+_ i) $ sym +-right-identity ⟩
i + (i + + 0) ≡⟨⟩
i *+ 2 ≡⟨ sym +-left-identity ⟩∎
+ 0 + i *+ 2 ∎)
∣
|
{
"alphanum_fraction": 0.4011392766,
"avg_line_length": 36.1958762887,
"ext": "agda",
"hexsha": "e561318332bcd6d55d44d9bc00f4717663a2211d",
"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/Group/Cyclic.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/Group/Cyclic.agda",
"max_line_length": 136,
"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/Group/Cyclic.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": 8019,
"size": 17555
}
|
import Structure.Logic.Classical.NaturalDeduction
module Structure.Logic.Classical.PredicateBoundedQuantification {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} ⦃ classicLogic : _ ⦄ where
open Structure.Logic.Classical.NaturalDeduction.ClassicalLogic {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} (classicLogic)
open import Functional hiding (Domain)
open import Lang.Instance
import Lvl
open import Type.Dependent
-- Bounded universal quantifier
∀ₚ : (Domain → Formula) → (Domain → Formula) → Formula
∀ₚ(B)(P) = ∀ₗ(x ↦ B(x) ⟶ P(x))
[∀ₚ]-intro : ∀{B}{P} → (∀{x} → Proof(B(x)) → Proof(P(x))) → Proof(∀ₚ(B)(P))
[∀ₚ]-intro {B}{P} proof =
([∀].intro(\{x} →
([→].intro(bx ↦
proof{x}(bx)
))
))
[∀ₚ]-elim : ∀{B}{P} → Proof(∀ₚ(B)(P)) → ∀{x} → Proof(B(x)) → Proof(P(x))
[∀ₚ]-elim {B}{P} allSφ {x} bx =
([→].elim
([∀].elim allSφ{x})
(bx)
)
-- Bounded existential quantifier
∃ₚ : (Domain → Formula) → (Domain → Formula) → Formula
∃ₚ(B)(P) = ∃ₗ(x ↦ B(x) ∧ P(x))
[∃ₚ]-intro : ∀{B}{P}{x} → Proof(B(x)) → Proof(P(x)) → Proof(∃ₚ(B)(P))
[∃ₚ]-intro {B}{P}{x} bx φx =
([∃].intro{_}
{x}
([∧].intro
(bx)
(φx)
)
)
[∃ₚ]-elim : ∀{B}{P₁}{P₂} → (∀{x} → Proof(B(x)) → Proof(P₁(x)) → Proof(P₂)) → Proof(∃ₚ(B)(P₁)) → Proof(P₂)
[∃ₚ]-elim {B}{P₁}{P₂} proof existence =
([∃].elim{_}{P₂}
(\{x} → conj ↦ (
(proof
{x}
([∧].elimₗ(conj))
([∧].elimᵣ(conj))
)
))
(existence)
)
[∃ₚ]-to-[∃ₗ] : ∀{B P} → Proof(∃ₚ(B)(P)) → Proof(∃ₗ(P))
[∃ₚ]-to-[∃ₗ] ebp = [∃ₚ]-elim (\{x} → bx ↦ px ↦ [∃].intro px) (ebp)
[∃ₚ]-witness : ∀{B P} → ⦃ _ : Proof(∃ₚ B P) ⦄ → Domain
[∃ₚ]-witness ⦃ proof ⦄ = [∃]-witness ⦃ proof ⦄
[∃ₚ]-bound : ∀{B P} → ⦃ p : Proof(∃ₚ B P) ⦄ → Proof(B([∃ₚ]-witness{B}{P} ⦃ p ⦄))
[∃ₚ]-bound ⦃ proof ⦄ = [∧].elimₗ([∃]-proof ⦃ proof ⦄)
[∃ₚ]-proof : ∀{B P} → ⦃ p : Proof(∃ₚ B P) ⦄ → Proof(P([∃ₚ]-witness{B}{P} ⦃ p ⦄))
[∃ₚ]-proof ⦃ proof ⦄ = [∧].elimᵣ([∃]-proof ⦃ proof ⦄)
Uniqueₚ : (Domain → Formula) → (Domain → Formula) → Formula
Uniqueₚ(B)(P) = ∀ₚ(B)(x ↦ ∀ₚ(B)(y ↦ (P(x) ∧ P(y)) ⟶ (x ≡ y)))
-- Bounded unique existential quantifier
∃ₚ! : (Domain → Formula) → (Domain → Formula) → Formula
∃ₚ!(B)(P) = ((∃ₚ(B) P) ∧ Uniqueₚ(B)(P))
[∃ₚ!]-witness : ∀{B P} → ⦃ _ : Proof(∃ₚ! B P) ⦄ → Domain
[∃ₚ!]-witness ⦃ proof ⦄ = [∃ₚ]-witness ⦃ [∧].elimₗ proof ⦄
[∃ₚ!]-bound : ∀{B P} → ⦃ p : Proof(∃ₚ! B P) ⦄ → Proof(B([∃ₚ!]-witness{B}{P} ⦃ p ⦄))
[∃ₚ!]-bound ⦃ proof ⦄ = [∃ₚ]-bound ⦃ [∧].elimₗ proof ⦄
[∃ₚ!]-proof : ∀{B P} → ⦃ p : Proof(∃ₚ! B P) ⦄ → Proof(P([∃ₚ!]-witness{B}{P} ⦃ p ⦄))
[∃ₚ!]-proof ⦃ proof ⦄ = [∃ₚ]-proof ⦃ [∧].elimₗ proof ⦄
postulate [∃ₚ!]-unique : ∀{B P} → ⦃ p : Proof(∃ₚ! B P) ⦄ → Proof(∀ₗ(x ↦ P(x) ⟶ (x ≡ [∃ₚ!]-witness{B}{P} ⦃ p ⦄)))
boundedClassicalLogicSignature : (Domain → Formula) → Structure.Logic.Classical.NaturalDeduction.Domained.Predicate.Signature {ℓₗ} {Formula} {ℓₘₗ} (Proof) {ℓₒ} (Domain)
boundedClassicalLogicSignature(B) =
record{
∀ₗ = ∀ₚ(B) ;
∃ₗ = ∃ₚ(B)
}
-- TODO: This should make it possible to embed a theory inside of another theory (e.g. group theory in set theory), but does not work. How should I formulate something like this for it to work?
{-
module _ (B : Domain → Formula) {ℓₒ₂} {Domain₂} (dom : Domain₂ → Domain) (dom-proof : ∀{x} → Proof(B(dom(x)))) (dom⁻¹ : Domain → Domain₂) where
instance
boundedPredEqSignature : Structure.Logic.Classical.NaturalDeduction.Domained.Predicate.Signature {ℓₗ} {Formula} {ℓₘₗ} (Proof) {ℓₒ₂} (Domain₂)
boundedPredEqSignature =
record{
∀ₗ = P ↦ ∀ₗ(x ↦ B(x) ⟶ P(x)) ;
∃ₗ = P ↦ ∃ₚ(B) (x ↦ P(dom⁻¹ x))
}
instance
boundedPredEqTheory : Structure.Logic.Classical.NaturalDeduction.Domained.Predicate.Theory {ℓₗ} {Formula} {ℓₘₗ} (Proof) {ℓₒ₂} (Domain₂) ⦃ boundedPredEqSignature ⦄
boundedPredEqTheory =
record{
universalQuantification =
record{
intro = \{P} → proof ↦ [∀ₚ]-intro{B}{P ∘ dom⁻¹} (\{x} → bx ↦ proof{dom⁻¹ x}) ;
elim = \{P} → ap ↦ \{x} → [∀ₚ]-elim ap{dom x} (dom-proof{x})
} ;
existentialQuantification =
record{
intro = \{P}{a} → pa ↦ [∃ₚ]-intro{B}{P}{dom a} (dom-proof{a}) pa;
elim = \{P}{Z} → axpxz ↦ ep ↦ [∃ₚ]-elim{B}{P} (\{x} → bx ↦ px ↦ axpxz{dom⁻¹ x}(px)) ep
}
}
-}
{-
module _ (B : Domain → Formula) {ℓₒ₂} {Domain₂} (morph : (x : Domain) → Proof(B(x)) → Domain₂) (morph₂ : Domain₂ → Domain) (ident : ∀{x} → Proof(B(x)) → morph(morph₂(x))(proof) ≡ x) (proof : ∀{x} → Proof(B(morph₂(x)))) where
instance
boundedPredEqSignature : Structure.Logic.Classical.NaturalDeduction.Domained.Predicate.Signature {ℓₗ} {Formula} {ℓₘₗ} (Proof) {ℓₒ₂} (Domain₂)
boundedPredEqSignature =
record{
∀ₗ = ∀ₚ(B) ;
∃ₗ = ∃ₚ(B)
}
instance
boundedPredEqTheory : Structure.Logic.Classical.NaturalDeduction.Domained.Predicate.Theory {ℓₗ} {Formula} {ℓₘₗ} (Proof) {ℓₒ₂} (Domain₂) ⦃ boundedPredEqSignature ⦄
boundedPredEqTheory =
record{
universalQuantification =
record{
intro = \{P} → proof ↦ [∀ₚ]-intro{B}{P ∘ dom⁻¹} (\{x} → bx ↦ proof{dom⁻¹ x}) ;
elim = \{P} → ap ↦ \{x} → [∀ₚ]-elim ap{dom x} (dom-proof{x})
} ;
existentialQuantification =
record{
intro = \{P}{a} → pa ↦ [∃ₚ]-intro{B}{P}{dom a} (dom-proof{a}) pa;
elim = \{P}{Z} → axpxz ↦ ep ↦ [∃ₚ]-elim{B}{P} (\{x} → bx ↦ px ↦ axpxz{dom⁻¹ x}(px)) ep
}
}
-}
{-
module _ (B : Domain → Formula) where
instance
boundedPredEqSignature2 : Structure.Logic.Classical.NaturalDeduction.Domained.Predicate.Signature {ℓₗ} {Formula} {ℓₘₗ} (Proof) {ℓₒ} (Σ B Domain)
boundedPredEqSignature2 =
record{
∀ₗ = P ↦ ∀ₚ(B)(P) ;
∃ₗ = P ↦ ∃ₚ(B)(P)
}
instance
boundedPredEqTheory2 : Structure.Logic.Classical.NaturalDeduction.Domained.Predicate.Theory {ℓₗ} {Formula} {ℓₘₗ} (Proof) {ℓₒ} (Σ B Domain) ⦃ boundedPredEqSignature2 ⦄
boundedPredEqTheory2 =
record{
universalQuantification =
record{
intro = \{P} → proof ↦ [∀ₚ]-intro{B}{P} (\{x} → bx ↦ proof{dom⁻¹ x}) ;
elim = \{P} → ap ↦ \{x} → [∀ₚ]-elim ap{x} (dom-proof{x})
} ;
existentialQuantification =
record{
intro = \{P}{a} → pa ↦ [∃ₚ]-intro{B}{P}{dom a} (dom-proof{a}) pa;
elim = \{P}{Z} → axpxz ↦ ep ↦ [∃ₚ]-elim{B}{P} (\{x} → bx ↦ px ↦ axpxz{dom⁻¹ x}(px)) ep
}
}
-}
|
{
"alphanum_fraction": 0.5363188673,
"avg_line_length": 37.1314285714,
"ext": "agda",
"hexsha": "5a9d726c1561b074a589e986a300cc88755fed47",
"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": "old/Structure/Logic/Classical/PredicateBoundedQuantification.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": "old/Structure/Logic/Classical/PredicateBoundedQuantification.agda",
"max_line_length": 224,
"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": "old/Structure/Logic/Classical/PredicateBoundedQuantification.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": 2817,
"size": 6498
}
|
-- Andreas, 2013-10-21
-- Test case for CheckInternal extracted from The Agda standard library
-- Propositional (intensional) equality
module FunExt where
open import Common.Level
open import Common.Equality
Extensionality : (a b : Level) → Set _
Extensionality a b =
{A : Set a} {B : A → Set b} {f g : (x : A) → B x} →
(∀ x → f x ≡ g x) → f ≡ g
-- Functional extensionality implies a form of extensionality for
-- Π-types.
∀-extensionality :
∀ {a b} →
Extensionality a (lsuc b) →
{A : Set a} (B₁ B₂ : A → Set b) →
(∀ x → B₁ x ≡ B₂ x) → (∀ x → B₁ x) ≡ (∀ x → B₂ x)
∀-extensionality ext B₁ B₂ B₁≡B₂ with ext B₁≡B₂
∀-extensionality ext B .B B₁≡B₂ | refl = refl
|
{
"alphanum_fraction": 0.6292466765,
"avg_line_length": 27.08,
"ext": "agda",
"hexsha": "16f0d710e9864cf713ac88b48d535e10a15a798e",
"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/FunExt.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/FunExt.agda",
"max_line_length": 71,
"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/FunExt.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": 257,
"size": 677
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Helpers intended to ease the development of "tactics" which use
-- proof by reflection
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Data.Fin
open import Data.Nat
open import Data.Vec as Vec
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (module Equivalence)
open import Level
open import Relation.Binary
import Relation.Binary.PropositionalEquality as P
-- Think of the parameters as follows:
--
-- * Expr: A representation of code.
-- * var: The Expr type should support a notion of variables.
-- * ⟦_⟧: Computes the semantics of an expression. Takes an
-- environment mapping variables to something.
-- * ⟦_⇓⟧: Computes the semantics of the normal form of the
-- expression.
-- * correct: Normalisation preserves the semantics.
--
-- Given these parameters two "tactics" are returned, prove and solve.
--
-- For an example of the use of this module, see Algebra.RingSolver.
module Relation.Binary.Reflection
{e a s}
{Expr : ℕ → Set e} {A : Set a}
(Sem : Setoid a s)
(var : ∀ {n} → Fin n → Expr n)
(⟦_⟧ ⟦_⇓⟧ : ∀ {n} → Expr n → Vec A n → Setoid.Carrier Sem)
(correct : ∀ {n} (e : Expr n) ρ →
⟦ e ⇓⟧ ρ ⟨ Setoid._≈_ Sem ⟩ ⟦ e ⟧ ρ)
where
open import Data.Vec.N-ary
open import Data.Product
import Relation.Binary.Reasoning.Setoid as Eq
open Setoid Sem
open Eq Sem
-- If two normalised expressions are semantically equal, then their
-- non-normalised forms are also equal.
prove : ∀ {n} (ρ : Vec A n) e₁ e₂ →
⟦ e₁ ⇓⟧ ρ ≈ ⟦ e₂ ⇓⟧ ρ →
⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ
prove ρ e₁ e₂ hyp = begin
⟦ e₁ ⟧ ρ ≈⟨ sym (correct e₁ ρ) ⟩
⟦ e₁ ⇓⟧ ρ ≈⟨ hyp ⟩
⟦ e₂ ⇓⟧ ρ ≈⟨ correct e₂ ρ ⟩
⟦ e₂ ⟧ ρ ∎
-- Applies the function to all possible "variables".
close : ∀ {A : Set e} n → N-ary n (Expr n) A → A
close n f = f $ⁿ Vec.map var (allFin n)
-- A variant of prove which should in many cases be easier to use,
-- because variables and environments are handled in a less explicit
-- way.
--
-- If the type signature of solve is a bit daunting, then it may be
-- helpful to instantiate n with a small natural number and normalise
-- the remainder of the type.
solve : ∀ n (f : N-ary n (Expr n) (Expr n × Expr n)) →
Eqʰ n _≈_ (curryⁿ ⟦ proj₁ (close n f) ⇓⟧) (curryⁿ ⟦ proj₂ (close n f) ⇓⟧) →
Eq n _≈_ (curryⁿ ⟦ proj₁ (close n f) ⟧) (curryⁿ ⟦ proj₂ (close n f) ⟧)
solve n f hyp =
curryⁿ-cong _≈_ ⟦ proj₁ (close n f) ⟧ ⟦ proj₂ (close n f) ⟧
(λ ρ → prove ρ (proj₁ (close n f)) (proj₂ (close n f))
(curryⁿ-cong⁻¹ _≈_
⟦ proj₁ (close n f) ⇓⟧ ⟦ proj₂ (close n f) ⇓⟧
(Eqʰ-to-Eq n _≈_ hyp) ρ))
-- A variant of solve which does not require that the normal form
-- equality is proved for an arbitrary environment.
solve₁ : ∀ n (f : N-ary n (Expr n) (Expr n × Expr n)) →
∀ⁿ n (curryⁿ λ ρ →
⟦ proj₁ (close n f) ⇓⟧ ρ ≈ ⟦ proj₂ (close n f) ⇓⟧ ρ →
⟦ proj₁ (close n f) ⟧ ρ ≈ ⟦ proj₂ (close n f) ⟧ ρ)
solve₁ n f =
Equivalence.from (uncurry-∀ⁿ n) ⟨$⟩ λ ρ →
P.subst id (P.sym (left-inverse (λ _ → _ ≈ _ → _ ≈ _) ρ))
(prove ρ (proj₁ (close n f)) (proj₂ (close n f)))
-- A variant of _,_ which is intended to make uses of solve and solve₁
-- look a bit nicer.
infix 4 _⊜_
_⊜_ : ∀ {n} → Expr n → Expr n → Expr n × Expr n
_⊜_ = _,_
|
{
"alphanum_fraction": 0.5781554751,
"avg_line_length": 34.180952381,
"ext": "agda",
"hexsha": "4a32d79a7e9b8836c609a5d569220f1e8da39d30",
"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/Relation/Binary/Reflection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Reflection.agda",
"max_line_length": 77,
"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/Relation/Binary/Reflection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1214,
"size": 3589
}
|
{-# OPTIONS --cubical --safe #-}
module Algebra.Construct.Free.Semilattice.Relation.Unary.Any.Def where
open import Prelude hiding (⊥; ⊤)
open import Algebra.Construct.Free.Semilattice.Eliminators
open import Algebra.Construct.Free.Semilattice.Definition
open import Cubical.Foundations.HLevels
open import Data.Empty.UniversePolymorphic
open import HITs.PropositionalTruncation.Sugar
open import HITs.PropositionalTruncation.Properties
open import HITs.PropositionalTruncation
open import Data.Unit.UniversePolymorphic
private
variable p : Level
dup-◇ : (P : A → Type p) → (x : A) (xs : Type p) → ∥ P x ⊎ ∥ P x ⊎ xs ∥ ∥ ⇔ ∥ P x ⊎ xs ∥
dup-◇ P x xs .inv p = ∣ inr p ∣
dup-◇ P x xs .fun ps = ps >>= either (∣_∣ ∘ inl) id
dup-◇ P x xs .leftInv p = squash _ p
dup-◇ P x xs .rightInv p = squash p _
swap-◇ : {x y xs : Type p} → ∥ x ⊎ ∥ y ⊎ xs ∥ ∥ → ∥ y ⊎ ∥ x ⊎ xs ∥ ∥
swap-◇ p = p >>= either′ (∣_∣ ∘ inr ∘ ∣_∣ ∘ inl) (mapʳ (∣_∣ ∘ inr) ∥$∥_)
com-◇ : (P : A → Type p) → (x y : A) (xs : Type p) → ∥ P x ⊎ ∥ P y ⊎ xs ∥ ∥ ⇔ ∥ P y ⊎ ∥ P x ⊎ xs ∥ ∥
com-◇ P y z xs .fun = swap-◇
com-◇ P y z xs .inv = swap-◇
com-◇ P y z xs .leftInv p = squash _ p
com-◇ P y z xs .rightInv p = squash _ p
◇′ : (P : A → Type p) → 𝒦 A → hProp p
◇′ P =
𝒦-rec
isSetHProp
(λ { x (xs , _) → ∥ P x ⊎ xs ∥ , squash })
(⊥ , λ ())
(λ x xs → ΣProp≡ (λ _ → isPropIsProp) (isoToPath (dup-◇ P x (xs .fst))))
(λ x y xs → ΣProp≡ (λ _ → isPropIsProp) (isoToPath (com-◇ P x y (xs .fst))))
{-# INLINE ◇′ #-}
◇ : (P : A → Type p) → 𝒦 A → Type p
◇ P xs = ◇′ P xs .fst
isProp-◇ : ∀ {P : A → Type p} {xs} → isProp (◇ P xs)
isProp-◇ {P = P} {xs = xs} = ◇′ P xs .snd
|
{
"alphanum_fraction": 0.5729040097,
"avg_line_length": 34.2916666667,
"ext": "agda",
"hexsha": "0427caea7f047b8c8070f41f8645bb294474ac3a",
"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": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Algebra/Construct/Free/Semilattice/Relation/Unary/Any/Def.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Algebra/Construct/Free/Semilattice/Relation/Unary/Any/Def.agda",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Algebra/Construct/Free/Semilattice/Relation/Unary/Any/Def.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 733,
"size": 1646
}
|
{-# OPTIONS --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Fundamental {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Properties
open import Definition.LogicalRelation.Substitution.Conversion
open import Definition.LogicalRelation.Substitution.Reduction
open import Definition.LogicalRelation.Substitution.Reflexivity
open import Definition.LogicalRelation.Substitution.ProofIrrelevance
open import Definition.LogicalRelation.Substitution.MaybeEmbed
open import Definition.LogicalRelation.Substitution.Introductions.Nat
open import Definition.LogicalRelation.Substitution.Introductions.Natrec
open import Definition.LogicalRelation.Substitution.Introductions.Empty
open import Definition.LogicalRelation.Substitution.Introductions.Emptyrec
open import Definition.LogicalRelation.Substitution.Introductions.Universe
open import Definition.LogicalRelation.Substitution.Introductions.Pi
open import Definition.LogicalRelation.Substitution.Introductions.Sigma
open import Definition.LogicalRelation.Substitution.Introductions.Id
open import Definition.LogicalRelation.Substitution.Introductions.IdUPiPi
open import Definition.LogicalRelation.Substitution.Introductions.Cast
open import Definition.LogicalRelation.Substitution.Introductions.CastPi
open import Definition.LogicalRelation.Substitution.Introductions.IdPi
open import Definition.LogicalRelation.Substitution.Introductions.Lambda
open import Definition.LogicalRelation.Substitution.Introductions.Application
open import Definition.LogicalRelation.Substitution.Introductions.Pair
open import Definition.LogicalRelation.Substitution.Introductions.Fst
open import Definition.LogicalRelation.Substitution.Introductions.Snd
open import Definition.LogicalRelation.Substitution.Introductions.SingleSubst
open import Definition.LogicalRelation.Substitution.Introductions.Transp
open import Definition.LogicalRelation.Substitution.Introductions.IdRefl
open import Definition.LogicalRelation.Fundamental.Variable
import Definition.LogicalRelation.Substitution.ProofIrrelevance as PI
import Definition.LogicalRelation.Substitution.Irrelevance as S
open import Definition.LogicalRelation.Substitution.Weakening
open import Tools.Product
open import Tools.Unit
open import Tools.Nat
import Tools.PropositionalEquality as PE
-- Fundamental theorem for contexts.
valid : ∀ {Γ} → ⊢ Γ → ⊩ᵛ Γ
fundamental : ∀ {Γ A rA} (⊢A : Γ ⊢ A ^ rA) → Σ (⊩ᵛ Γ) (λ [Γ] → Γ ⊩ᵛ⟨ ∞ ⟩ A ^ rA / [Γ])
fundamentalEq : ∀{Γ A B rA} → Γ ⊢ A ≡ B ^ rA
→ ∃ λ ([Γ] : ⊩ᵛ Γ)
→ ∃₂ λ ([A] : Γ ⊩ᵛ⟨ ∞ ⟩ A ^ rA / [Γ]) ([B] : Γ ⊩ᵛ⟨ ∞ ⟩ B ^ rA / [Γ])
→ Γ ⊩ᵛ⟨ ∞ ⟩ A ≡ B ^ rA / [Γ] / [A]
fundamentalTerm : ∀{Γ A rA t} → Γ ⊢ t ∷ A ^ rA
→ ∃ λ ([Γ] : ⊩ᵛ Γ)
→ ∃ λ ([A] : Γ ⊩ᵛ⟨ ∞ ⟩ A ^ rA / [Γ])
→ Γ ⊩ᵛ⟨ ∞ ⟩ t ∷ A ^ rA / [Γ] / [A]
fundamentalTermEq : ∀{Γ A t t′ rA} → Γ ⊢ t ≡ t′ ∷ A ^ rA
→ ∃ λ ([Γ] : ⊩ᵛ Γ)
→ [ Γ ⊩ᵛ⟨ ∞ ⟩ t ≡ t′ ∷ A ^ rA / [Γ] ]
abstract
valid ε = ε
valid (⊢Γ ∙ A) = let [Γ] , [A] = fundamental A in [Γ] ∙ [A]
-- Fundamental theorem for types.
fundamental (Uⱼ x) = valid x , maybeEmbᵛ {A = Univ _ _} (valid x) (Uᵛ ∞< (valid x))
fundamental (univ {A} ⊢A) with fundamentalTerm ⊢A
fundamental (univ {A} ⊢A) | [Γ] , [U] , [A] =
[Γ] , maybeEmbᵛ {A = A} [Γ] (univᵛ {A} [Γ] (≡is≤ PE.refl) [U] [A])
-- Fundamental theorem for type equality.
fundamentalEq (univ {A} {B} x) with fundamentalTermEq x
fundamentalEq (univ {A} {B} x) | [Γ] , modelsTermEq [U] [t] [u] [t≡u] =
let [A] = maybeEmbᵛ {A = A} [Γ] (univᵛ {A} [Γ] (≡is≤ PE.refl) [U] [t])
[B] = maybeEmbᵛ {A = B} [Γ] (univᵛ {B} [Γ] (≡is≤ PE.refl) [U] [u])
in [Γ] , [A] , [B]
, (λ ⊢Δ [σ] → univEqEq (proj₁ ([U] ⊢Δ [σ]))
(proj₁ ([A] ⊢Δ [σ]))
([t≡u] ⊢Δ [σ]))
fundamentalEq (refl D) =
let [Γ] , [B] = fundamental D
in [Γ] , [B] , [B] , (λ ⊢Δ [σ] → reflEq (proj₁ ([B] ⊢Δ [σ])))
fundamentalEq (sym A≡B) with fundamentalEq A≡B
fundamentalEq (sym A≡B) | [Γ] , [B] , [A] , [B≡A] =
[Γ] , [A] , [B]
, (λ ⊢Δ [σ] → symEq (proj₁ ([B] ⊢Δ [σ]))
(proj₁ ([A] ⊢Δ [σ]))
([B≡A] ⊢Δ [σ]))
fundamentalEq (trans {A} {B₁} {B} A≡B₁ B₁≡B)
with fundamentalEq A≡B₁ | fundamentalEq B₁≡B
fundamentalEq (trans {A} {B₁} {B} A≡B B≡C) | [Γ] , [A] , [B₁] , [A≡B₁]
| [Γ]₁ , [B₁]₁ , [B] , [B₁≡B] =
[Γ] , [A] , S.irrelevance {A = B} [Γ]₁ [Γ] [B]
, (λ ⊢Δ [σ] →
let [σ]′ = S.irrelevanceSubst [Γ] [Γ]₁ ⊢Δ ⊢Δ [σ]
in transEq (proj₁ ([A] ⊢Δ [σ])) (proj₁ ([B₁] ⊢Δ [σ]))
(proj₁ ([B] ⊢Δ [σ]′)) ([A≡B₁] ⊢Δ [σ])
(irrelevanceEq (proj₁ ([B₁]₁ ⊢Δ [σ]′))
(proj₁ ([B₁] ⊢Δ [σ]))
([B₁≡B] ⊢Δ [σ]′)))
-- Fundamental theorem for terms.
fundamentalTerm (ℕⱼ x) = valid x , maybeEmbᵛ {A = Univ _ _} (valid x) (Uᵛ emb< (valid x)) , maybeEmbTermᵛ {A = Univ _ _} {t = ℕ} (valid x) (Uᵛ emb< (valid x)) (ℕᵗᵛ (valid x))
fundamentalTerm (Emptyⱼ {l} ⊢Γ) = let [Γ] = valid ⊢Γ
[U] = Uᵛ (proj₂ (levelBounded _)) [Γ]
in [Γ] , maybeEmbᵛ {A = Univ _ _} [Γ] [U] , maybeEmbTermᵛ {A = Univ _ _} {t = Empty l} [Γ] [U] (Emptyᵗᵛ {ll = l} [Γ] (proj₂ (levelBounded _)))
fundamentalTerm (Πⱼ_▹_▹_▹_ {F} {rF} {lF} {G} {lG} {rΠ} {lΠ} lF< lG< ⊢F ⊢G)
with fundamentalTerm ⊢F | fundamentalTerm ⊢G
... | [Γ] , [UF] , [F]ₜ | [Γ]₁ ∙ [F] , [UG] , [G]ₜ =
let [UF]′ = maybeEmbᵛ {A = Univ rF _} [Γ]₁ (Uᵛ (proj₂ (levelBounded lF)) [Γ]₁)
[UΠ] = maybeEmbᵛ {A = Univ rΠ _} [Γ]₁ (Uᵛ (proj₂ (levelBounded lΠ)) [Γ]₁)
[F]′ = maybeEmbᵛ {A = F} [Γ]₁ [F]
[UG]′ : _ ⊩ᵛ⟨ ∞ ⟩ Univ rΠ lG ^ [ ! , next lG ] / _∙_ {A = F} [Γ]₁ [F]′
[UG]′ = λ {Δ} {σ} → S.irrelevance {A = Univ rΠ lG} (_∙_ {A = F} [Γ]₁ [F]) (_∙_ {A = F} [Γ]₁ [F]′) (λ {Δ} {σ} → [UG] {Δ} {σ}) {Δ} {σ}
[F]ₜ′ = S.irrelevanceTerm {A = Univ rF _} {t = F} [Γ] [Γ]₁ [UF] [UF]′ [F]ₜ
[G]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = G} (_∙_ {A = F} [Γ]₁ [F]) (_∙_ {A = F} [Γ]₁ [F]′) (λ {Δ} {σ} → [UG] {Δ} {σ}) (λ {Δ} {σ} → [UG]′ {Δ} {σ}) [G]ₜ
in [Γ]₁ , [UΠ]
,
Πᵗᵛ {F} {G} {rF} {lF} {lG} {rΠ} {lΠ} lF< lG< [Γ]₁ [F]′ (λ {Δ} {σ} → [UG]′ {Δ} {σ}) [F]ₜ′ [G]ₜ′
fundamentalTerm (∃ⱼ_▹_ {F} {G} {l} ⊢F ⊢G)
with fundamentalTerm ⊢F | fundamentalTerm ⊢G
... | [Γ] , [UF] , [F]ₜ | [Γ]₁ ∙ [F] , [UG] , [G]ₜ =
let [UF]′ = maybeEmbᵛ {A = SProp _} [Γ]₁ (Uᵛ (proj₂ (levelBounded l)) [Γ]₁)
[UΠ] = maybeEmbᵛ {A = SProp _} [Γ]₁ (Uᵛ (proj₂ (levelBounded l)) [Γ]₁)
[F]′ = maybeEmbᵛ {A = F} [Γ]₁ [F]
[UG]′ : _ ⊩ᵛ⟨ ∞ ⟩ SProp l ^ [ ! , next l ] / _∙_ {A = F} [Γ]₁ [F]′
[UG]′ = λ {Δ} {σ} → S.irrelevance {A = Univ % l} (_∙_ {A = F} [Γ]₁ [F]) (_∙_ {A = F} [Γ]₁ [F]′) (λ {Δ} {σ} → [UG] {Δ} {σ}) {Δ} {σ}
[F]ₜ′ = S.irrelevanceTerm {A = SProp _} {t = F} [Γ] [Γ]₁ [UF] [UF]′ [F]ₜ
[G]ₜ′ = S.irrelevanceTerm {A = SProp _} {t = G} (_∙_ {A = F} [Γ]₁ [F]) (_∙_ {A = F} [Γ]₁ [F]′) (λ {Δ} {σ} → [UG] {Δ} {σ}) (λ {Δ} {σ} → [UG]′ {Δ} {σ}) [G]ₜ
in [Γ]₁ , [UΠ]
,
∃ᵗᵛ {F} {G} {l} [Γ]₁ [F]′ (λ {Δ} {σ} → [UG]′ {Δ} {σ}) [F]ₜ′ [G]ₜ′
fundamentalTerm (Idⱼ {A} {l} {t} {u} ⊢A ⊢t ⊢u)
with fundamentalTerm ⊢A | fundamentalTerm ⊢t | fundamentalTerm ⊢u
... | [Γ] , [UA] , [A]ₜ | [Γt] , [At] , [t]ₜ | [Γu] , [Au] , [u]ₜ =
let [SProp] = maybeEmbᵛ {A = SProp _} [Γu] (Uᵛ (proj₂ (levelBounded l)) [Γu])
[t]ₜ′ = S.irrelevanceTerm {A = A} {t = t} [Γt] [Γu] [At] [Au] [t]ₜ
[UA]′ = maybeEmbᵛ {A = Univ _ _} [Γu] (λ {Δ} {σ} → Uᵛ <next [Γu] {Δ} {σ})
[A]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A} [Γ] [Γu] (λ {Δ} {σ} → [UA] {Δ} {σ}) (λ {Δ} {σ} → [UA]′ {Δ} {σ}) [A]ₜ
in [Γu] , [SProp] , Idᵗᵛ {A = A} {t = t} {u = u } [Γu] [Au] [t]ₜ′ [u]ₜ [A]ₜ′
fundamentalTerm (var ⊢Γ x∷A) = valid ⊢Γ , fundamentalVar x∷A (valid ⊢Γ)
fundamentalTerm (lamⱼ {F} {r} {l} {rF} {lF} {G} {lG} {t} lF< lG< ⊢F ⊢t)
with fundamental ⊢F | fundamentalTerm ⊢t
... | [Γ] , [F] | [Γ]₁ , [G] , [t] =
let [G]′ = S.irrelevance {A = G} [Γ]₁ ([Γ] ∙ [F]) [G]
[t]′ = S.irrelevanceTerm {A = G} {t = t} [Γ]₁ ([Γ] ∙ [F]) [G] [G]′ [t]
in [Γ] , Πᵛ {F} {G} lF< lG< [Γ] [F] [G]′
, lamᵛ {F} {G} {rF} {lF} {lG} {l} {r} {t} lF< lG< [Γ] [F] [G]′ [t]′
fundamentalTerm (_∘ⱼ_ {g} {a} {F} {rF} {lF} {G} {lG} {r} {l} Dt Du)
with fundamentalTerm Dt | fundamentalTerm Du
... | [Γ] , [ΠFG] , [t] | [Γ]₁ , [F] , [u] =
let [ΠFG]′ = S.irrelevance {A = Π F ^ rF ° lF ▹ G ° lG ° l} [Γ] [Γ]₁ [ΠFG]
[t]′ = S.irrelevanceTerm {A = Π F ^ rF ° lF ▹ G ° lG ° l} {t = g} [Γ] [Γ]₁ [ΠFG] [ΠFG]′ [t]
[G[t]] = substSΠ {F} {G} {a} [Γ]₁ [F] [ΠFG]′ [u]
[t∘u] = appᵛ {F} {G} {rF} {lF} {lG} {r} {l} {g} {a} [Γ]₁ [F] [ΠFG]′ [t]′ [u]
in [Γ]₁ , [G[t]] , [t∘u]
fundamentalTerm (zeroⱼ x) = valid x , ℕᵛ (valid x) , zeroᵛ {l = ∞} (valid x)
fundamentalTerm (sucⱼ {n} t) with fundamentalTerm t
fundamentalTerm (sucⱼ {n} t) | [Γ] , [ℕ] , [n] =
[Γ] , [ℕ] , sucᵛ {n = n} [Γ] [ℕ] [n]
fundamentalTerm (natrecⱼ {G} {rG} {lG} {s} {z} {n} ⊢G ⊢z ⊢s ⊢n)
with fundamental ⊢G | fundamentalTerm ⊢z | fundamentalTerm ⊢s
| fundamentalTerm ⊢n
... | [Γ] , [G] | [Γ]₁ , [G₀] , [z] | [Γ]₂ , [G₊] , [s] | [Γ]₃ , [ℕ] , [n] =
let sType = Π ℕ ^ ! ° ⁰ ▹ (G ^ rG ° _ ▹▹ G [ suc (var 0) ]↑ ° _ ° lG) ° _ ° lG
[Γ]′ = [Γ]₃
[G]′ = S.irrelevance {A = G} [Γ] ([Γ]′ ∙ [ℕ]) [G]
[G₀]′ = S.irrelevance {A = G [ zero ]} [Γ]₁ [Γ]′ [G₀]
[G₊]′ = S.irrelevance {A = sType} [Γ]₂ [Γ]′ [G₊]
[Gₙ]′ = substS {F = ℕ} {G = G} {t = n} [Γ]′ [ℕ] [G]′ [n]
[z]′ = S.irrelevanceTerm {A = G [ zero ]} {t = z} [Γ]₁ [Γ]′
[G₀] [G₀]′ [z]
[s]′ = S.irrelevanceTerm {A = sType} {t = s} [Γ]₂ [Γ]′ [G₊] [G₊]′ [s]
in [Γ]′ , [Gₙ]′
, natrecᵛ {G} {rG} {lG} {z} {s} {n} [Γ]′ [ℕ] [G]′ [G₀]′ [G₊]′ [Gₙ]′ [z]′ [s]′ [n]
fundamentalTerm (⦅_,_,_,_⦆ⱼ {l} {F} {G} {t} {u} ⊢F ⊢G ⊢t ⊢u) with fundamental ⊢F | fundamental ⊢G | fundamentalTerm ⊢t | fundamentalTerm ⊢u
... | [ΓF] , [F]' | [ΓG] , [G] | [Γ] , [F] , [t]ₜ | [Γ]₁ , [G[t]] , [u]ₜ =
let [F]′ = S.irrelevance {A = F} [Γ] [Γ]₁ [F]
[G]′ = S.irrelevance {A = G} [ΓG] ([Γ]₁ ∙ [F]′) [G]
[t]ₜ′ = S.irrelevanceTerm {A = F} {t = t} [Γ] [Γ]₁ [F] [F]′ [t]ₜ
[u]ₜ′ = S.irrelevanceTerm {A = G [ t ]} {t = u} [Γ]₁ [Γ]₁ [G[t]] (substS {F} {G} {t} [Γ]₁ [F]′ [G]′ [t]ₜ′) [u]ₜ
in [Γ]₁ , ∃ᵛ {F} {G} {l∃ = l} [Γ]₁ [F]′ [G]′ , ⦅⦆ᵛ {F = F} {G = G} {t = t} {u = u} [Γ]₁ [F]′ [G]′ [t]ₜ′ [u]ₜ′
fundamentalTerm (fstⱼ {F} {G} {tu} {l} ⊢F ⊢G ⊢tu)
with fundamentalTerm ⊢F | fundamentalTerm ⊢G | fundamentalTerm ⊢tu
... | [ΓF] , [UF] , [F]ₜ | [ΓG] ∙ [F] , [UG] , [G]ₜ | [Γ] , [∃FG] , [tu]ₜ =
let [UF]′ = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l)) [Γ])
[F]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = F} [ΓF] [Γ] [UF] [UF]′ [F]ₜ
[F]′ = maybeEmbᵛ {A = F} [Γ] (univᵛ {A = F} [Γ] (≡is≤ PE.refl) [UF]′ [F]ₜ′)
[UG]′ = S.irrelevance {A = Univ _ _} (_∙_ {A = F} [ΓG] [F]) (_∙_ {A = F} [Γ] [F]′) (λ {Δ} {σ} → [UG] {Δ} {σ})
[G]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = G} (_∙_ {A = F} [ΓG] [F])
(_∙_ {A = F} [Γ] [F]′) (λ {Δ} {σ} → [UG] {Δ} {σ})
(λ {Δ} {σ} → [UG]′ {Δ} {σ}) [G]ₜ
[G]′ = maybeEmbᵛ {A = G} (_∙_ {A = F} [Γ] [F]′)
(univᵛ {A = G} (_∙_ {A = F} [Γ] [F]′) (≡is≤ PE.refl)
(λ {Δ} {σ} → [UG]′ {Δ} {σ}) [G]ₜ′)
[tu]ₜ′ = S.irrelevanceTerm {A = ∃ F ▹ G} {t = tu} [Γ] [Γ] [∃FG]
(∃ᵛ {F} {G} [Γ] [F]′ [G]′) [tu]ₜ
in [Γ] , [F]′ , fstᵛ {F = F} {G = G} {tu = tu} [Γ] [F]′ [G]′
(λ {Δ} {σ} → [UG]′ {Δ} {σ}) [F]ₜ′ [G]ₜ′ [tu]ₜ′
fundamentalTerm (sndⱼ {F} {G} {tu} {l} ⊢F ⊢G ⊢tu)
with fundamentalTerm ⊢F | fundamentalTerm ⊢G | fundamentalTerm ⊢tu
... | [ΓF] , [UF] , [F]ₜ | [ΓG] ∙ [F] , [UG] , [G]ₜ | [Γ] , [∃FG] , [tu]ₜ =
let [UF]′ = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l)) [Γ])
[F]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = F} [ΓF] [Γ] [UF] [UF]′ [F]ₜ
[F]′ = maybeEmbᵛ {A = F} [Γ] (univᵛ {A = F} [Γ] (≡is≤ PE.refl) [UF]′ [F]ₜ′)
[UG]′ = S.irrelevance {A = Univ _ _} (_∙_ {A = F} [ΓG] [F]) (_∙_ {A = F} [Γ] [F]′) (λ {Δ} {σ} → [UG] {Δ} {σ})
[G]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = G} (_∙_ {A = F} [ΓG] [F])
(_∙_ {A = F} [Γ] [F]′) (λ {Δ} {σ} → [UG] {Δ} {σ})
(λ {Δ} {σ} → [UG]′ {Δ} {σ}) [G]ₜ
[G]′ = maybeEmbᵛ {A = G} (_∙_ {A = F} [Γ] [F]′)
(univᵛ {A = G} (_∙_ {A = F} [Γ] [F]′) (≡is≤ PE.refl)
(λ {Δ} {σ} → [UG]′ {Δ} {σ}) [G]ₜ′)
[tu]ₜ′ = S.irrelevanceTerm {A = ∃ F ▹ G} {t = tu} [Γ] [Γ] [∃FG]
(∃ᵛ {F} {G} [Γ] [F]′ [G]′) [tu]ₜ
in [Γ] ,
substS {F} {G} {fst tu} [Γ] [F]′ [G]′ (fstᵛ {F = F} {G = G} {tu = tu} [Γ] [F]′ [G]′ (λ {Δ} {σ} → [UG]′ {Δ} {σ}) [F]ₜ′ [G]ₜ′ [tu]ₜ′) ,
sndᵛ {F = F} {G = G} {tu = tu} [Γ] [F]′ [G]′ (λ {Δ} {σ} → [UG]′ {Δ} {σ}) [F]ₜ′ [G]ₜ′ [tu]ₜ′
fundamentalTerm {Γ} (Idreflⱼ {A} {l} {t} ⊢t)
with fundamentalTerm ⊢t
... | [Γ] , [A] , [t] =
let [Id] = Idᵛ {A = A} {t = t} {u = t } [Γ] [A] [t] [t]
in [Γ] , [Id] , Idreflᵛ {Γ} {A} {l} {t} [Γ] [A] [t]
fundamentalTerm (transpⱼ {A} {l} {P} {t} {s} {u} {e} ⊢A ⊢P ⊢t ⊢s ⊢u ⊢e)
with fundamental ⊢A | fundamental ⊢P | fundamentalTerm ⊢t | fundamentalTerm ⊢s | fundamentalTerm ⊢u | fundamentalTerm ⊢e
... | [ΓA] , [A] | [ΓP] ∙ [A]' , [P] | [Γt] , [At] , [t] | [Γs] , [Pt] , [s] | [Γu] , [Au] , [u] | [Γe] , [Id] , [e] =
let [A]′ = S.irrelevance {A = A} [ΓA] [Γe] [A]
[P]′ = S.irrelevance {A = P} (_∙_ {A = A} [ΓP] [A]') (_∙_ {A = A} [Γe] [A]′) [P]
[t]′ = S.irrelevanceTerm {A = A} {t = t} [Γt] [Γe] [At] [A]′ [t]
[u]′ = S.irrelevanceTerm {A = A} {t = u} [Γu] [Γe] [Au] [A]′ [u]
[Pt]′ = substS {A} {P} {t} [Γe] [A]′ [P]′ [t]′
[s]′ = S.irrelevanceTerm {A = P [ t ] } {t = s} [Γs] [Γe] [Pt] [Pt]′ [s]
in [Γe] , substS {A} {P} {u} [Γe] [A]′ [P]′ [u]′ , transpᵗᵛ {A} {P} {l} {t} {s} {u} {e} [Γe] [A]′ [P]′ [t]′ [s]′ [u]′ [Id] [e]
fundamentalTerm (castⱼ {A} {B} {r} {e} {t} ⊢A ⊢B ⊢e ⊢t)
with fundamentalTerm ⊢A | fundamentalTerm ⊢B | fundamentalTerm ⊢e | fundamentalTerm ⊢t
... | [ΓA] , [UA] , [A]ₜ | [ΓB] , [UB] , [B]ₜ | [Γe] , [Id] , [e]ₜ | [Γ]₁ , [At] , [t]ₜ =
let [UA]′ = S.irrelevance {A = Univ _ _} [ΓA] [Γ]₁ [UA]
[A]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A} [ΓA] [Γ]₁ [UA] [UA]′ [A]ₜ
[B]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = B} [ΓB] [Γ]₁ [UB] [UA]′ [B]ₜ
[B] = maybeEmbᵛ {A = B} [Γ]₁ (univᵛ {A = B} [Γ]₁ (≡is≤ PE.refl) [UA]′ [B]ₜ′)
[Id]′ = S.irrelevance {A = Id (Univ r _) A B} [Γe] [Γ]₁ [Id]
[e]ₜ′ = S.irrelevanceTerm {A = Id (Univ r _) A B} {t = e} [Γe] [Γ]₁ [Id] [Id]′ [e]ₜ
in [Γ]₁ , [B] , castᵗᵛ {A} {B} {r} {t} {e} [Γ]₁ [UA]′ [A]ₜ′ [B]ₜ′ [At] [B] [t]ₜ [Id]′ [e]ₜ′
fundamentalTerm {Γ} (castreflⱼ {A} {t} ⊢A ⊢t)
with fundamentalTerm ⊢A | fundamentalTerm ⊢t
... | [ΓA] , [UA] , [A]ₜ | [Γ] , [A] , [t]ₜ =
let [UA]′ = S.irrelevance {A = Univ _ _} [ΓA] [Γ] [UA]
[A]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A} [ΓA] [Γ] [UA] [UA]′ [A]ₜ
[Id] = Idᵛ {A = A} {t = t} {u = cast ⁰ A A (Idrefl (U ⁰) A) t} [Γ] [A] [t]ₜ
(castᵗᵛ {A = A} {B = A} {t = t} {e = Idrefl (U ⁰) A} [Γ] [UA]′ [A]ₜ′ [A]ₜ′ [A] [A] [t]ₜ
(Idᵛ {A = U _} {t = A} {u = A} [Γ] [UA]′ [A]ₜ′ [A]ₜ′)
(Idreflᵛ {A = U _} {t = A} [Γ] [UA]′ [A]ₜ′))
in [Γ] , [Id] , castreflᵛ {Γ} {A} {t} [Γ] [UA]′ [A]ₜ′ [A] [t]ₜ
fundamentalTerm (Emptyrecⱼ {A} {lEmpty} {lA} {rA} {n} ⊢A ⊢n)
with fundamental ⊢A | fundamentalTerm ⊢n
... | [Γ] , [A] | [Γ]′ , [Empty] , [n] =
let [A]′ = S.irrelevance {A = A} [Γ] [Γ]′ [A]
in [Γ]′ , [A]′ , Emptyrecᵛ {A} {rA} {lA} {lEmpty} {n} [Γ]′ [Empty] [A]′ [n]
fundamentalTerm (conv {t} {A} {B} ⊢t A′≡A)
with fundamentalTerm ⊢t | fundamentalEq A′≡A
fundamentalTerm (conv {t} {A} {B} ⊢t A′≡A) | [Γ] , [A′] , [t]
| [Γ]₁ , [A′]₁ , [A] , [A′≡A] =
let [Γ]′ = [Γ]₁
[t]′ = S.irrelevanceTerm {A = A} {t = t} [Γ] [Γ]′ [A′] [A′]₁ [t]
in [Γ]′ , [A]
, convᵛ {t} {A} {B} [Γ]′ [A′]₁ [A] [A′≡A] [t]′
fundamentalTerm (univ 0<1 ⊢Γ) = let [Γ] = valid ⊢Γ
in [Γ] , (Uᵛ ∞< [Γ] , Uᵗᵛ [Γ])
-- Fundamental theorem for term equality.
fundamentalTermEq (refl D) with fundamentalTerm D
... | [Γ] , [A] , [t] =
[Γ] , modelsTermEq [A] [t] [t]
(λ ⊢Δ [σ] → reflEqTerm (proj₁ ([A] ⊢Δ [σ]))
(proj₁ ([t] ⊢Δ [σ])))
fundamentalTermEq (sym D) with fundamentalTermEq D
fundamentalTermEq (sym D) | [Γ] , modelsTermEq [A] [t′] [t] [t′≡t] =
[Γ] , modelsTermEq [A] [t] [t′]
(λ ⊢Δ [σ] → symEqTerm (proj₁ ([A] ⊢Δ [σ]))
([t′≡t] ⊢Δ [σ]))
fundamentalTermEq (trans {t} {u} {r} {A} t≡u u≡t′)
with fundamentalTermEq t≡u | fundamentalTermEq u≡t′
fundamentalTermEq (trans {t} {u} {r} {A} t≡u u≡t′)
| [Γ] , modelsTermEq [A] [t] [u] [t≡u]
| [Γ]₁ , modelsTermEq [A]₁ [t]₁ [u]₁ [t≡u]₁ =
let [r]′ = S.irrelevanceTerm {A = A} {t = r} [Γ]₁ [Γ] [A]₁ [A] [u]₁
in [Γ] , modelsTermEq [A] [t] [r]′
(λ ⊢Δ [σ] →
let [σ]′ = S.irrelevanceSubst [Γ] [Γ]₁ ⊢Δ ⊢Δ [σ]
[t≡u]₁′ = irrelevanceEqTerm (proj₁ ([A]₁ ⊢Δ [σ]′))
(proj₁ ([A] ⊢Δ [σ]))
([t≡u]₁ ⊢Δ [σ]′)
in transEqTerm (proj₁ ([A] ⊢Δ [σ]))
([t≡u] ⊢Δ [σ]) [t≡u]₁′)
fundamentalTermEq (conv {A} {B} {r} {t} {u} t≡u A′≡A)
with fundamentalTermEq t≡u | fundamentalEq A′≡A
fundamentalTermEq (conv {A} {B} {r} {t} {u} t≡u A′≡A)
| [Γ] , modelsTermEq [A′] [t] [u] [t≡u] | [Γ]₁ , [A′]₁ , [A] , [A′≡A] =
let [t]′ = S.irrelevanceTerm {A = A} {t = t} [Γ] [Γ]₁ [A′] [A′]₁ [t]
[u]′ = S.irrelevanceTerm {A = A} {t = u} [Γ] [Γ]₁ [A′] [A′]₁ [u]
[t]″ = convᵛ {t} {A} {B} [Γ]₁ [A′]₁ [A] [A′≡A] [t]′
[u]″ = convᵛ {u} {A} {B} [Γ]₁ [A′]₁ [A] [A′≡A] [u]′
in [Γ]₁
, modelsTermEq [A] [t]″ [u]″
(λ ⊢Δ [σ] →
let [σ]′ = S.irrelevanceSubst [Γ]₁ [Γ] ⊢Δ ⊢Δ [σ]
[t≡u]′ = irrelevanceEqTerm (proj₁ ([A′] ⊢Δ [σ]′))
(proj₁ ([A′]₁ ⊢Δ [σ]))
([t≡u] ⊢Δ [σ]′)
in convEqTerm₁ (proj₁ ([A′]₁ ⊢Δ [σ])) (proj₁ ([A] ⊢Δ [σ]))
([A′≡A] ⊢Δ [σ]) [t≡u]′)
fundamentalTermEq (Π-cong {E} {F} {G} {H} {rF} {lF} {rG} {lG} {lΠ} lF< lG< ⊢F F≡H G≡E)
with fundamental ⊢F | fundamentalTermEq F≡H | fundamentalTermEq G≡E
... | [Γ] , [F] | [Γ]₁ , modelsTermEq [U] [F]ₜ [H]ₜ [F≡H]ₜ
| [Γ]₂ , modelsTermEq [U]₁ [G]ₜ [E]ₜ [G≡E]ₜ =
let [U]′ = maybeEmbᵛ {A = Univ _ _} [Γ] (Uᵛ (proj₂ (levelBounded lF)) [Γ])
[UΠ] = maybeEmbᵛ {A = Univ _ _} [Γ] (Uᵛ (proj₂ (levelBounded lΠ)) [Γ])
[F]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = F} [Γ]₁ [Γ] [U] [U]′ [F]ₜ
[H]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = H} [Γ]₁ [Γ] [U] [U]′ [H]ₜ
[F]′ = S.irrelevance {A = F} [Γ] [Γ]₁ [F]
[H] = maybeEmbᵛ {A = H} [Γ] (univᵛ {A = H} [Γ] (≡is≤ PE.refl) [U]′ [H]ₜ′)
[F≡H] = S.irrelevanceEq {A = F} {B = H} [Γ]₁ [Γ] [F]′ [F]
(univEqᵛ {F} {H} [Γ]₁ [U] [F]′ [F≡H]ₜ)
[U]₁′ = S.irrelevance {A = Univ _ _} [Γ]₂ ([Γ] ∙ [F]) [U]₁
[U]₂′ = S.irrelevanceLift {A = Univ _ _} {F = F} {H = H} [Γ] [F] [H] [F≡H] (λ {Δ} {σ} → [U]₁′ {Δ} {σ})
[G]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = G} [Γ]₂ ([Γ] ∙ [F])
[U]₁ (λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [G]ₜ
[E]ₜ′ = S.irrelevanceTermLift {A = Univ _ _} {F = F} {H = H} {t = E}
[Γ] [F] [H] [F≡H]
(λ {Δ} {σ} → [U]₁′ {Δ} {σ})
(S.irrelevanceTerm {A = Univ _ _} {t = E} [Γ]₂ ([Γ] ∙ [F])
[U]₁ (λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [E]ₜ)
[F≡H]ₜ′ = S.irrelevanceEqTerm {A = Univ _ _} {t = F} {u = H}
[Γ]₁ [Γ] [U] [U]′ [F≡H]ₜ
[G≡E]ₜ′ = S.irrelevanceEqTerm {A = Univ _ _} {t = G} {u = E} [Γ]₂
(_∙_ {A = F} [Γ] [F]) [U]₁
(λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [G≡E]ₜ
in [Γ]
, modelsTermEq
[UΠ] -- looks like [U]′ but the implicits are different
(Πᵗᵛ {F} {G} lF< lG< [Γ] [F] (λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [F]ₜ′ [G]ₜ′ )
(Πᵗᵛ {H} {E} lF< lG< [Γ] [H] (λ {Δ} {σ} → [U]₂′ {Δ} {σ}) [H]ₜ′ [E]ₜ′)
(Π-congᵗᵛ {F} {G} {H} {E} lF< lG< [Γ] [F] [H]
(λ {Δ} {σ} → [U]₁′ {Δ} {σ}) (λ {Δ} {σ} → [U]₂′ {Δ} {σ})
[F]ₜ′ [G]ₜ′ [H]ₜ′ [E]ₜ′ [F≡H]ₜ′ [G≡E]ₜ′)
fundamentalTermEq (app-cong {a} {b} {f} {g} {F} {G} {rF} {lF} {lG} {l} f≡g a≡b)
with fundamentalTermEq f≡g | fundamentalTermEq a≡b
... | [Γ] , modelsTermEq [ΠFG] [f] [g] [f≡g]
| [Γ]₁ , modelsTermEq [F] [a] [b] [a≡b] =
let [ΠFG]′ = S.irrelevance {A = Π F ^ rF ° lF ▹ G ° lG ° l} [Γ] [Γ]₁ [ΠFG]
[f]′ = S.irrelevanceTerm {A = Π F ^ rF ° lF ▹ G ° lG ° l} {t = f} [Γ] [Γ]₁ [ΠFG] [ΠFG]′ [f]
[g]′ = S.irrelevanceTerm {A = Π F ^ rF ° lF ▹ G ° lG ° l} {t = g} [Γ] [Γ]₁ [ΠFG] [ΠFG]′ [g]
[f≡g]′ = S.irrelevanceEqTerm {A = Π F ^ rF ° lF ▹ G ° lG ° l} {t = f} {u = g}
[Γ] [Γ]₁ [ΠFG] [ΠFG]′ [f≡g]
[G[a]] = substSΠ {F} {G} {a} [Γ]₁ [F] [ΠFG]′ [a]
[G[b]] = substSΠ {F} {G} {b} [Γ]₁ [F] [ΠFG]′ [b]
[G[a]≡G[b]] = substSΠEq {F} {G} {F} {G} {a} {b} [Γ]₁ [F] [F] [ΠFG]′
[ΠFG]′ (reflᵛ {Π F ^ rF ° lF ▹ G ° lG ° l} [Γ]₁ [ΠFG]′) [a] [b] [a≡b]
in [Γ]₁ , modelsTermEq [G[a]]
(appᵛ {F} {G} {rF} {lF} {lG} { ! } {l} {f} {a} [Γ]₁ [F] [ΠFG]′ [f]′ [a])
(conv₂ᵛ {g ∘ b ^ l} {G [ a ]} {G [ b ]} [Γ]₁
[G[a]] [G[b]] [G[a]≡G[b]]
(appᵛ {F} {G} {rF} {lF} {lG} { ! } {l} {g} {b}
[Γ]₁ [F] [ΠFG]′ [g]′ [b]))
(app-congᵛ {F} {G} {rF} {lF} {lG} { ! } {l} {f} {g} {a} {b}
[Γ]₁ [F] [ΠFG]′ [f≡g]′ [a] [b] [a≡b])
fundamentalTermEq (β-red {a} {b} {F} {rF} {lF} {G} {lG} {l} l< l<' ⊢F ⊢b ⊢a)
with fundamental ⊢F | fundamentalTerm ⊢b | fundamentalTerm ⊢a
... | [Γ] , [F] | [Γ]₁ , [G] , [b] | [Γ]₂ , [F]₁ , [a] =
let [G]′ = S.irrelevance {A = G} [Γ]₁ ([Γ]₂ ∙ [F]₁) [G]
[b]′ = S.irrelevanceTerm {A = G} {t = b} [Γ]₁ ([Γ]₂ ∙ [F]₁) [G] [G]′ [b]
[G[a]] = substS {F} {G} {a} [Γ]₂ [F]₁ [G]′ [a]
[b[a]] = substSTerm {F} {G} {a} {b} [Γ]₂ [F]₁ [G]′ [b]′ [a]
[lam] , [eq] =
redSubstTermᵛ {G [ a ]} {(lam F ▹ b ^ l) ∘ a ^ l} {b [ a ]} [Γ]₂
(λ {Δ} {σ} ⊢Δ [σ] →
let [liftσ] = liftSubstS {F = F} [Γ]₂ ⊢Δ [F]₁ [σ]
⊢σF = escape (proj₁ ([F]₁ ⊢Δ [σ]))
⊢σb = escapeTerm (proj₁ ([G]′ (⊢Δ ∙ ⊢σF) [liftσ]))
(proj₁ ([b]′ (⊢Δ ∙ ⊢σF) [liftσ]))
⊢σa = escapeTerm (proj₁ ([F]₁ ⊢Δ [σ]))
(proj₁ ([a] ⊢Δ [σ]))
in PE.subst₂ (λ x y → _ ⊢ (lam (subst σ F) ▹ (subst (liftSubst σ) b) ^ _)
∘ (subst σ a) ^ _ ⇒ x ∷ y ^ _)
(PE.sym (singleSubstLift b a))
(PE.sym (singleSubstLift G a))
(β-red l< l<' ⊢σF ⊢σb ⊢σa))
[G[a]] [b[a]]
in [Γ]₂ , modelsTermEq [G[a]] [lam] [b[a]] [eq]
fundamentalTermEq (η-eq {f} {g} {F} {rF} {lF} {lG} {l} {G} lF< lG< ⊢F ⊢t ⊢t′ t≡t′) with
fundamental ⊢F | fundamentalTerm ⊢t |
fundamentalTerm ⊢t′ | fundamentalTermEq t≡t′
... | [Γ] , [F] | [Γ]₁ , [ΠFG] , [t] | [Γ]₂ , [ΠFG]₁ , [t′]
| [Γ]₃ , modelsTermEq [G] [t0] [t′0] [t0≡t′0] =
let [F]′ = S.irrelevance {A = F} [Γ] [Γ]₁ [F]
[G]′ = S.irrelevance {A = G} [Γ]₃ ([Γ]₁ ∙ [F]′) [G]
[t′]′ = S.irrelevanceTerm {A = Π F ^ rF ° lF ▹ G ° lG ° l} {t = g}
[Γ]₂ [Γ]₁ [ΠFG]₁ [ΠFG] [t′]
[ΠFG]″ = Πᵛ {F} {G} lF< lG< [Γ]₁ [F]′ [G]′
[t]″ = S.irrelevanceTerm {A = Π F ^ rF ° lF ▹ G ° lG ° l} {t = f}
[Γ]₁ [Γ]₁ [ΠFG] [ΠFG]″ [t]
[t′]″ = S.irrelevanceTerm {A = Π F ^ rF ° lF ▹ G ° lG ° l} {t = g}
[Γ]₂ [Γ]₁ [ΠFG]₁ [ΠFG]″ [t′]
[t0≡t′0]′ = S.irrelevanceEqTerm {A = G} {t = wk1 f ∘ var 0 ^ l}
{u = wk1 g ∘ var 0 ^ l}
[Γ]₃ ([Γ]₁ ∙ [F]′) [G] [G]′ [t0≡t′0]
[t≡t′] = η-eqᵛ {f} {g} {F} {G} lF< lG< [Γ]₁ [F]′ [G]′ [t]″ [t′]″ [t0≡t′0]′
[t≡t′]′ = S.irrelevanceEqTerm {A = Π F ^ rF ° lF ▹ G ° lG ° l} {t = f} {u = g}
[Γ]₁ [Γ]₁ [ΠFG]″ [ΠFG] [t≡t′]
in [Γ]₁ , modelsTermEq [ΠFG] [t] [t′]′ [t≡t′]′
fundamentalTermEq (suc-cong x) with fundamentalTermEq x
fundamentalTermEq (suc-cong {t} {u} x)
| [Γ] , modelsTermEq [A] [t] [u] [t≡u] =
let [suct] = sucᵛ {n = t} [Γ] [A] [t]
[sucu] = sucᵛ {n = u} [Γ] [A] [u]
in [Γ] , modelsTermEq [A] [suct] [sucu]
(λ ⊢Δ [σ] →
sucEqTerm (proj₁ ([A] ⊢Δ [σ])) ([t≡u] ⊢Δ [σ]))
fundamentalTermEq (natrec-cong {z} {z′} {s} {s′} {n} {n′} {F} {F′}
F≡F′ z≡z′ s≡s′ n≡n′)
with fundamentalEq F≡F′ |
fundamentalTermEq z≡z′ |
fundamentalTermEq s≡s′ |
fundamentalTermEq n≡n′
fundamentalTermEq (natrec-cong {z} {z′} {s} {s′} {n} {n′} {F} {F′} {l}
F≡F′ z≡z′ s≡s′ n≡n′) |
[Γ] , [F] , [F′] , [F≡F′] |
[Γ]₁ , modelsTermEq [F₀] [z] [z′] [z≡z′] |
[Γ]₂ , modelsTermEq [F₊] [s] [s′] [s≡s′] |
[Γ]₃ , modelsTermEq [ℕ] [n] [n′] [n≡n′] =
let sType = Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° l ▹▹ F [ suc (var 0) ]↑ ° l ° l) ° l ° l
s′Type = Π ℕ ^ ! ° ⁰ ▹ (F′ ^ ! ° l ▹▹ F′ [ suc (var 0) ]↑ ° l ° l) ° l ° l
[0] = S.irrelevanceTerm {l = ∞} {A = ℕ} {t = zero}
[Γ]₃ [Γ]₃ (ℕᵛ [Γ]₃) [ℕ] (zeroᵛ {l = ∞} [Γ]₃)
[F]′ = S.irrelevance {A = F} [Γ] ([Γ]₃ ∙ [ℕ]) [F]
[F₀]′ = S.irrelevance {A = F [ zero ]} [Γ]₁ [Γ]₃ [F₀]
[F₊]′ = S.irrelevance {A = sType} [Γ]₂ [Γ]₃ [F₊]
[Fₙ]′ = substS {ℕ} {F} {n} [Γ]₃ [ℕ] [F]′ [n]
[F′]′ = S.irrelevance {A = F′} [Γ] ([Γ]₃ ∙ [ℕ]) [F′]
[F₀]″ = substS {ℕ} {F} {zero} [Γ]₃ [ℕ] [F]′ [0]
[F′₀]′ = substS {ℕ} {F′} {zero} [Γ]₃ [ℕ] [F′]′ [0]
[F′₊]′ = sucCase {F′} [Γ]₃ [ℕ] [F′]′
[F′ₙ′]′ = substS {ℕ} {F′} {n′} [Γ]₃ [ℕ] [F′]′ [n′]
[ℕ≡ℕ] = reflᵛ {ℕ} [Γ]₃ [ℕ]
[0≡0] = reflᵗᵛ {ℕ} {zero} [Γ]₃ [ℕ] [0]
[F≡F′]′ = S.irrelevanceEq {A = F} {B = F′}
[Γ] ([Γ]₃ ∙ [ℕ]) [F] [F]′ [F≡F′]
[F₀≡F′₀] = substSEq {ℕ} {ℕ} {F} {F′} {zero} {zero}
[Γ]₃ [ℕ] [ℕ] [ℕ≡ℕ]
[F]′ [F′]′ [F≡F′]′ [0] [0] [0≡0]
[F₀≡F′₀]′ = S.irrelevanceEq {A = F [ zero ]} {B = F′ [ zero ]}
[Γ]₃ [Γ]₃ [F₀]″ [F₀]′ [F₀≡F′₀]
[F₊≡F′₊] = sucCaseCong {F} {F′} [Γ]₃ [ℕ] [F]′ [F′]′ [F≡F′]′
[F₊≡F′₊]′ = S.irrelevanceEq {A = sType} {B = s′Type}
[Γ]₃ [Γ]₃ (sucCase {F} [Γ]₃ [ℕ] [F]′)
[F₊]′ [F₊≡F′₊]
[Fₙ≡F′ₙ′]′ = substSEq {ℕ} {ℕ} {F} {F′} {n} {n′}
[Γ]₃ [ℕ] [ℕ] [ℕ≡ℕ] [F]′ [F′]′ [F≡F′]′
[n] [n′] [n≡n′]
[z]′ = S.irrelevanceTerm {A = F [ zero ]} {t = z}
[Γ]₁ [Γ]₃ [F₀] [F₀]′ [z]
[z′]′ = convᵛ {z′} {F [ zero ]} {F′ [ zero ]}
[Γ]₃ [F₀]′ [F′₀]′ [F₀≡F′₀]′
(S.irrelevanceTerm {A = F [ zero ]} {t = z′}
[Γ]₁ [Γ]₃ [F₀] [F₀]′ [z′])
[z≡z′]′ = S.irrelevanceEqTerm {A = F [ zero ]} {t = z} {u = z′}
[Γ]₁ [Γ]₃ [F₀] [F₀]′ [z≡z′]
[s]′ = S.irrelevanceTerm {A = sType} {t = s} [Γ]₂ [Γ]₃ [F₊] [F₊]′ [s]
[s′]′ = convᵛ {s′} {sType} {s′Type} [Γ]₃ [F₊]′ [F′₊]′ [F₊≡F′₊]′
(S.irrelevanceTerm {A = sType} {t = s′}
[Γ]₂ [Γ]₃ [F₊] [F₊]′ [s′])
[s≡s′]′ = S.irrelevanceEqTerm {A = sType} {t = s} {u = s′}
[Γ]₂ [Γ]₃ [F₊] [F₊]′ [s≡s′]
in [Γ]₃
, modelsTermEq [Fₙ]′
(natrecᵛ {F} { ! } {l} {z} {s} {n}
[Γ]₃ [ℕ] [F]′ [F₀]′ [F₊]′ [Fₙ]′ [z]′ [s]′ [n])
(conv₂ᵛ {natrec l F′ z′ s′ n′} {F [ n ]} {F′ [ n′ ]}
[Γ]₃ [Fₙ]′ [F′ₙ′]′ [Fₙ≡F′ₙ′]′
(natrecᵛ {F′} { ! } {l} {z′} {s′} {n′}
[Γ]₃ [ℕ] [F′]′ [F′₀]′ [F′₊]′ [F′ₙ′]′
[z′]′ [s′]′ [n′]))
(natrec-congᵛ {F} {F′} { ! } {l} {z} {z′} {s} {s′} {n} {n′}
[Γ]₃ [ℕ] [F]′ [F′]′ [F≡F′]′
[F₀]′ [F′₀]′ [F₀≡F′₀]′
[F₊]′ [F′₊]′ [F₊≡F′₊]′ [Fₙ]′
[z]′ [z′]′ [z≡z′]′
[s]′ [s′]′ [s≡s′]′ [n] [n′] [n≡n′])
fundamentalTermEq (natrec-zero {z} {s} {F} ⊢F ⊢z ⊢s)
with fundamental ⊢F | fundamentalTerm ⊢z | fundamentalTerm ⊢s
fundamentalTermEq (natrec-zero {z} {s} {F} {l} ⊢F ⊢z ⊢s) | [Γ] , [F]
| [Γ]₁ , [F₀] , [z] | [Γ]₂ , [F₊] , [s] =
let sType = Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° l ▹▹ F [ suc (var 0) ]↑ ° l ° l) ° l ° l
[Γ]′ = [Γ]₁
[ℕ]′ = ℕᵛ {l = ∞} [Γ]′
[F₊]′ = S.irrelevance {A = sType} [Γ]₂ [Γ]′ [F₊]
[s]′ = S.irrelevanceTerm {A = sType} {t = s} [Γ]₂ [Γ]′ [F₊] [F₊]′ [s]
[F]′ = S.irrelevance {A = F} [Γ] ([Γ]′ ∙ [ℕ]′) [F]
d , r =
redSubstTermᵛ {F [ zero ]} {natrec l F z s zero} {z} [Γ]′
(λ {Δ} {σ} ⊢Δ [σ] →
let ⊢ℕ = escape (proj₁ ([ℕ]′ ⊢Δ [σ]))
⊢F = escape (proj₁ ([F]′ (⊢Δ ∙ ⊢ℕ)
(liftSubstS {F = ℕ}
[Γ]′ ⊢Δ [ℕ]′ [σ])))
⊢z = PE.subst (λ x → Δ ⊢ subst σ z ∷ x ^ _)
(singleSubstLift F zero)
(escapeTerm (proj₁ ([F₀] ⊢Δ [σ]))
(proj₁ ([z] ⊢Δ [σ])))
⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x ^ [ ! , ι l ] )
(natrecSucCase σ F ! l)
(escapeTerm (proj₁ ([F₊]′ ⊢Δ [σ]))
(proj₁ ([s]′ ⊢Δ [σ])))
in PE.subst (λ x → Δ ⊢ subst σ (natrec l F z s zero)
⇒ subst σ z ∷ x ^ _)
(PE.sym (singleSubstLift F zero))
(natrec-zero ⊢F ⊢z ⊢s))
[F₀] [z]
in [Γ]′ , modelsTermEq [F₀] d [z] r
fundamentalTermEq (natrec-suc {n} {z} {s} {F} {lF} ⊢n ⊢F ⊢z ⊢s)
with fundamentalTerm ⊢n | fundamental ⊢F
| fundamentalTerm ⊢z | fundamentalTerm ⊢s
... | [Γ] , [ℕ] , [n] | [Γ]₁ , [F] | [Γ]₂ , [F₀] , [z] | [Γ]₃ , [F₊] , [s] =
let [ℕ]′ = S.irrelevance {A = ℕ} [Γ] [Γ]₃ [ℕ]
[n]′ = S.irrelevanceTerm {A = ℕ} {t = n} [Γ] [Γ]₃ [ℕ] [ℕ]′ [n]
[sucn] = sucᵛ {n = n} [Γ]₃ [ℕ]′ [n]′
[F₀]′ = S.irrelevance {A = F [ zero ]} [Γ]₂ [Γ]₃ [F₀]
[z]′ = S.irrelevanceTerm {A = F [ zero ]} {t = z}
[Γ]₂ [Γ]₃ [F₀] [F₀]′ [z]
[F]′ = S.irrelevance {A = F} [Γ]₁ ([Γ]₃ ∙ [ℕ]′) [F]
[F[sucn]] = substS {ℕ} {F} {suc n} [Γ]₃ [ℕ]′ [F]′ [sucn]
[Fₙ]′ = substS {ℕ} {F} {n} [Γ]₃ [ℕ]′ [F]′ [n]′
[natrecₙ] = natrecᵛ {F} { ! } {lF} {z} {s} {n}
[Γ]₃ [ℕ]′ [F]′ [F₀]′ [F₊] [Fₙ]′ [z]′ [s] [n]′
t = (s ∘ n ^ lF) ∘ (natrec lF F z s n) ^ lF
q = subst (liftSubst (sgSubst n))
(wk1 (F [ suc (var 0) ]↑))
y = S.irrelevanceTerm′
{A = q [ natrec lF F z s n ]} {A′ = F [ suc n ]} {t = t}
(natrecIrrelevantSubst′ F z s n) PE.refl [Γ]₃ [Γ]₃
(substSΠ {F [ n ]} {q} {natrec lF F z s n} [Γ]₃
(substS {ℕ} {F} {n} [Γ]₃ [ℕ]′ [F]′ [n]′)
(substSΠ {ℕ} {F ^ ! ° lF ▹▹ F [ suc (var 0) ]↑ ° lF ° lF} {n}
[Γ]₃ [ℕ]′ [F₊] [n]′)
[natrecₙ])
[F[sucn]]
(appᵛ {F [ n ]} {q} { ! } {lF} {lF} { ! } {lF} {s ∘ n ^ lF} {natrec lF F z s n} [Γ]₃ [Fₙ]′
(substSΠ {ℕ} {F ^ ! ° lF ▹▹ F [ suc (var 0) ]↑ ° lF ° lF} {n}
[Γ]₃ [ℕ]′ [F₊] [n]′)
(appᵛ {ℕ} {F ^ ! ° lF ▹▹ F [ suc (var 0) ]↑ ° lF ° lF} { ! } {⁰} {lF} { ! } {lF} {s} {n}
[Γ]₃ [ℕ]′ [F₊] [s] [n]′)
[natrecₙ])
d , r =
redSubstTermᵛ {F [ suc n ]} {natrec lF F z s (suc n)} {t } {∞} {_} [Γ]₃
(λ {Δ} {σ} ⊢Δ [σ] →
let ⊢n = escapeTerm (proj₁ ([ℕ]′ ⊢Δ [σ]))
(proj₁ ([n]′ ⊢Δ [σ]))
⊢ℕ = escape (proj₁ ([ℕ]′ ⊢Δ [σ]))
⊢F = escape (proj₁ ([F]′ (⊢Δ ∙ ⊢ℕ)
(liftSubstS {F = ℕ}
[Γ]₃ ⊢Δ [ℕ]′ [σ])))
⊢z = PE.subst (λ x → Δ ⊢ subst σ z ∷ x ^ _)
(singleSubstLift F zero)
(escapeTerm (proj₁ ([F₀]′ ⊢Δ [σ]))
(proj₁ ([z]′ ⊢Δ [σ])))
⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x ^ [ ! , ι lF ])
(natrecSucCase σ F ! lF)
(escapeTerm (proj₁ ([F₊] ⊢Δ [σ]))
(proj₁ ([s] ⊢Δ [σ])))
r = _⊢_⇒_∷_^_.natrec-suc {n = subst σ n}
{z = subst σ z} {s = subst σ s}
{F = subst (liftSubst σ) F}
⊢n ⊢F ⊢z ⊢s
in PE.subst (λ x → Δ ⊢ subst σ (natrec lF F z s (suc n))
⇒ (subst σ t) ∷ x ^ _)
(PE.trans (PE.trans (substCompEq F)
(substVar-to-subst (λ { 0 → PE.refl
; (1+ x) → PE.trans (subst-wk (σ x))
(subst-id (σ x))
})
F))
(PE.sym (substCompEq F)))
r)
[F[sucn]] y
in [Γ]₃ , modelsTermEq [F[sucn]] d y r
fundamentalTermEq (Emptyrec-cong {F} {F′} {n} {n′}
F≡F′ ⊢n ⊢n′)
with fundamentalEq F≡F′ | fundamentalTerm ⊢n | fundamentalTerm ⊢n′
fundamentalTermEq (Emptyrec-cong {F} {F′} {lF} {lEmpty} {n} {n′}
F≡F′ ⊢n ⊢n′) |
[Γ] , [F] , [F′] , [F≡F′] |
[Γn] , [Empty] , [n] | [Γn′] , [Empty]′ , [n′]
=
let [F]′ = S.irrelevance {A = F} [Γ] [Γn′] [F]
[F′]′ = S.irrelevance {A = F′} [Γ] [Γn′] [F′]
[n]′ = S.irrelevanceTerm {A = Empty _} {t = n} [Γn] [Γn′] [Empty] [Empty]′ [n]
[F≡F′]′ = S.irrelevanceEq {A = F} {B = F′} [Γ] [Γn′] [F] [F]′ [F≡F′]
in [Γn′]
, modelsTermEq [F]′ (Emptyrecᵛ {F} { ! } {lF} {lEmpty} {n} [Γn′] [Empty]′ [F]′ [n]′)
(conv₂ᵛ {Emptyrec lF lEmpty F′ n′} {F} {F′} { [ ! , ι lF ] } [Γn′] [F]′ [F′]′ [F≡F′]′
(Emptyrecᵛ {F′} { ! } {lF} {lEmpty} {n′} [Γn′] [Empty]′ [F′]′ [n′]))
(Emptyrec-congᵛ {F} {F′} { ! } {lF} {lEmpty} {n} {n′}
[Γn′] [Empty]′ [F]′ [F′]′ [F≡F′]′ [n]′ [n′])
fundamentalTermEq (proof-irrelevance ⊢t ⊢u) with fundamentalTerm ⊢t | fundamentalTerm ⊢u
fundamentalTermEq {A = A} {t = t} {t′ = t′} (proof-irrelevance ⊢t ⊢u) | [Γ] , [A] , [t] | [Γ]′ , [A]′ , [u] =
let [u]′ = S.irrelevanceTerm {A = A} {t = t′} [Γ]′ [Γ] [A]′ [A] [u]
in [Γ] , modelsTermEq [A] [t] [u]′
(PI.proof-irrelevanceᵛ {A = A} {t = t} {u = t′} [Γ] [A] [t] [u]′)
fundamentalTermEq (∃-cong {E} {F} {G} {H} {l} ⊢F F≡H G≡E)
with fundamental ⊢F | fundamentalTermEq F≡H | fundamentalTermEq G≡E
... | [Γ] , [F] | [Γ]₁ , modelsTermEq [U] [F]ₜ [H]ₜ [F≡H]ₜ
| [Γ]₂ , modelsTermEq [U]₁ [G]ₜ [E]ₜ [G≡E]ₜ =
let [U]′ = maybeEmbᵛ {A = Univ _ _} [Γ] (Uᵛ (proj₂ (levelBounded l)) [Γ])
[UΠ] = maybeEmbᵛ {A = Univ _ _} [Γ] (Uᵛ (proj₂ (levelBounded l)) [Γ])
[F]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = F} [Γ]₁ [Γ] [U] [U]′ [F]ₜ
[H]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = H} [Γ]₁ [Γ] [U] [U]′ [H]ₜ
[F]′ = S.irrelevance {A = F} [Γ] [Γ]₁ [F]
[H] = maybeEmbᵛ {A = H} [Γ] (univᵛ {A = H} [Γ] (≡is≤ PE.refl) [U]′ [H]ₜ′)
[F≡H] = S.irrelevanceEq {A = F} {B = H} [Γ]₁ [Γ] [F]′ [F]
(univEqᵛ {F} {H} [Γ]₁ [U] [F]′ [F≡H]ₜ)
[U]₁′ = S.irrelevance {A = Univ _ _} [Γ]₂ ([Γ] ∙ [F]) [U]₁
[U]₂′ = S.irrelevanceLift {A = Univ _ _} {F = F} {H = H} [Γ] [F] [H] [F≡H] (λ {Δ} {σ} → [U]₁′ {Δ} {σ})
[G]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = G} [Γ]₂ ([Γ] ∙ [F])
[U]₁ (λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [G]ₜ
[E]ₜ′ = S.irrelevanceTermLift {A = Univ _ _} {F = F} {H = H} {t = E}
[Γ] [F] [H] [F≡H]
(λ {Δ} {σ} → [U]₁′ {Δ} {σ})
(S.irrelevanceTerm {A = Univ _ _} {t = E} [Γ]₂ ([Γ] ∙ [F])
[U]₁ (λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [E]ₜ)
[F≡H]ₜ′ = S.irrelevanceEqTerm {A = Univ _ _} {t = F} {u = H}
[Γ]₁ [Γ] [U] [U]′ [F≡H]ₜ
[G≡E]ₜ′ = S.irrelevanceEqTerm {A = Univ _ _} {t = G} {u = E} [Γ]₂
(_∙_ {A = F} [Γ] [F]) [U]₁
(λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [G≡E]ₜ
in [Γ]
, modelsTermEq
[UΠ] -- looks like [U]′ but the implicits are different
(∃ᵗᵛ {F} {G} [Γ] [F] (λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [F]ₜ′ [G]ₜ′ )
(∃ᵗᵛ {H} {E} [Γ] [H] (λ {Δ} {σ} → [U]₂′ {Δ} {σ}) [H]ₜ′ [E]ₜ′)
(∃-congᵗᵛ {F} {G} {H} {E} [Γ] [F] [H]
(λ {Δ} {σ} → [U]₁′ {Δ} {σ}) (λ {Δ} {σ} → [U]₂′ {Δ} {σ})
[F]ₜ′ [G]ₜ′ [H]ₜ′ [E]ₜ′ [F≡H]ₜ′ [G≡E]ₜ′)
fundamentalTermEq (Id-cong {A} {A'} {l} {t} {t'} {u} {u'} A≡A' t≡t' u≡u')
with fundamentalTermEq A≡A' | fundamentalTermEq t≡t' | fundamentalTermEq u≡u'
... | [ΓA] , modelsTermEq [UA] [A]ₜ [A']ₜ [A≡A']ₜ | [Γt] , modelsTermEq [A] [t]ₜ [t']ₜ [t≡t']ₜ | [Γu] , modelsTermEq [A'] [u]ₜ [u']ₜ [u≡u']ₜ =
let [SProp] = maybeEmbᵛ {A = Univ _ _} [Γu] (Uᵛ {rU = %} <next [Γu])
[UA]′ = maybeEmbᵛ {A = U l} [Γu] (Uᵛ <next [Γu])
[A]ₜ′ = S.irrelevanceTerm {A = U l} {t = A} [ΓA] [Γu] [UA] (λ {Δ} {σ} → [UA]′ {Δ} {σ}) [A]ₜ
[A']ₜ′ = S.irrelevanceTerm {A = U l} {t = A'} [ΓA] [Γu] [UA] [UA]′ [A']ₜ
[A]′ = S.irrelevance {A = A} [Γt] [Γu] [A]
[A']ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A'} [ΓA] [Γu] [UA] [UA]′ [A']ₜ
[A']′ = maybeEmbᵛ {A = A'} [Γu] (univᵛ {A = A'} [Γu] (≡is≤ PE.refl) [UA]′ [A']ₜ′)
[A≡A']ₜ′ = S.irrelevanceEqTerm {A = Univ _ _} {t = A} {u = A'} [ΓA] [Γu] [UA] [UA]′ [A≡A']ₜ
[A≡A']′ = univEqᵛ {A = A} {B = A'} [Γu] [UA]′ [A]′ [A≡A']ₜ′
[t]ₜ′ = S.irrelevanceTerm {A = A} {t = t} [Γt] [Γu] [A] [A]′ [t]ₜ
[t']ₜ′ = convᵛ {t = t'} {A = A} {B = A'} [Γu] [A]′ [A']′ [A≡A']′ (S.irrelevanceTerm {A = A} {t = t'} [Γt] [Γu] [A] [A]′ [t']ₜ)
[u]ₜ′ = S.irrelevanceTerm {A = A} {t = u} [Γu] [Γu] [A'] [A]′ [u]ₜ
[u']ₜ′ = convᵛ {t = u'} {A = A} {B = A'} [Γu] [A]′ [A']′ [A≡A']′ (S.irrelevanceTerm {A = A} {t = u'} [Γu] [Γu] [A'] [A]′ [u']ₜ)
[t≡t']ₜ′ = S.irrelevanceEqTerm {A = A} {t = t} {u = t'} [Γt] [Γu] [A] [A]′ [t≡t']ₜ
[u≡u']ₜ′ = S.irrelevanceEqTerm {A = A} {t = u} {u = u'} [Γu] [Γu] [A'] [A]′ [u≡u']ₜ
in [Γu] , modelsTermEq [SProp] (Idᵗᵛ {A} {t} {u} [Γu] [A]′ [t]ₜ′ [u]ₜ′ [A]ₜ′)
(Idᵗᵛ {A'} {t'} {u'} [Γu] [A']′ [t']ₜ′ [u']ₜ′ [A']ₜ′)
(Id-congᵗᵛ {A} {A'} {t} {t'} {u} {u'} [Γu] [A]′ [t]ₜ′ [u]ₜ′ [A]ₜ′ [A']′ [t']ₜ′ [u']ₜ′ [A']ₜ′ [A≡A']ₜ′ [t≡t']ₜ′ [u≡u']ₜ′)
fundamentalTermEq {Γ} (Id-Π {A} {rA} {lA} {lB} {l} {B} {t} {u} lA≤ lB≤ ⊢A ⊢B ⊢t ⊢u)
with fundamentalTerm ⊢A | fundamentalTerm ⊢B | fundamentalTerm ⊢t | fundamentalTerm ⊢u
... | [ΓA] , [UA] , [A]ₜ | [ΓB] ∙ [AB] , [UB] , [B]ₜ | [Γt] , [Πt] , [t]ₜ | [Γu] , [Πu] , [u]ₜ =
let [SProp] = maybeEmbᵛ {A = Univ _ _} [Γu] (Uᵛ {rU = %} (proj₂ (levelBounded l)) [Γu])
[UA]′ = maybeEmbᵛ {A = Univ _ _} [Γu] (Uᵛ (proj₂ (levelBounded lA)) [Γu])
[A]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A} [ΓA] [Γu] [UA] [UA]′ [A]ₜ
[A] = maybeEmbᵛ {A = A} [Γu] (univᵛ {A = A} [Γu] (≡is≤ PE.refl) [UA]′ [A]ₜ′)
[ΓuA] = _∙_ {A = A} [Γu] [A]
[UB]′ = S.irrelevance {A = Univ _ _} (_∙_ {A = A} [ΓB] [AB]) (_∙_ {A = A} [Γu] [A]) (λ {Δ} {σ} → [UB] {Δ} {σ})
[B]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = B} (_∙_ {A = A} [ΓB] [AB]) [ΓuA] (λ {Δ} {σ} → [UB] {Δ} {σ}) (λ {Δ} {σ} → [UB]′ {Δ} {σ}) [B]ₜ
[t]ₜ′ = S.irrelevanceTerm {A = Π A ^ rA ° lA ▹ B ° lB ° l} {t = t} [Γt] [Γu] [Πt] [Πu] [t]ₜ
in [Γu] , Id-Πᵗᵛ [Γu] lA≤ lB≤ [A] (λ {Δ} {σ} → [UB]′ {Δ} {σ}) [A]ₜ′ [B]ₜ′ [Πu] [t]ₜ′ [u]ₜ
fundamentalTermEq {Γ} (Id-ℕ-00 ⊢Γ) =
let [Γ] = valid ⊢Γ
[SProp] = Uᵛ emb< [Γ]
[Unit] = Unitᵗᵛ {l = ⁰} [Γ]
[id] , [eq] = redSubstTermᵛ {SProp ⁰} {Id ℕ zero zero} {Unit} [Γ] (λ ⊢Δ [σ] → Id-ℕ-00 ⊢Δ) [SProp] [Unit]
in [Γ] , modelsTermEq (maybeEmbᵛ {A = SProp _} [Γ] [SProp]) [id] [Unit] [eq]
fundamentalTermEq (Id-ℕ-SS ⊢n ⊢m) with fundamentalTerm ⊢n | fundamentalTerm ⊢m
fundamentalTermEq (Id-ℕ-SS {n} {m} ⊢n ⊢m) | [Γ] , [ℕ] , [n] | [Γ]′ , [ℕ]′ , [m] =
let [SProp] = maybeEmbᵛ {A = SProp ⁰} [Γ]′ (Uᵛ emb< [Γ]′)
[Unit] = Unitᵗᵛ {l = ⁰} [Γ]′
⊢Γ = soundContext [Γ]′
[n]′ = S.irrelevanceTerm {A = ℕ} {t = n} [Γ] [Γ]′ [ℕ] [ℕ]′ [n]
Idnm = Idᵗᵛ {A = ℕ} {t = n} {u = m} [Γ]′ [ℕ]′ [n]′ [m] (ℕᵗᵛ [Γ]′)
⊢n′ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([ℕ]′ {Δ = Δ} {σ = σ} ⊢Δ [σ])) (proj₁ ([n]′ ⊢Δ [σ]))
⊢m′ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([ℕ]′ {Δ = Δ} {σ = σ} ⊢Δ [σ])) (proj₁ ([m] ⊢Δ [σ]))
[id] , [eq] = redSubstTermᵛ {SProp ⁰} {t = Id ℕ (suc n) (suc m)} {u = Id ℕ n m} [Γ]′ (λ {Δ} {σ} ⊢Δ [σ] → Id-ℕ-SS (⊢n′ {Δ} {σ} ⊢Δ [σ]) (⊢m′ {Δ} {σ} ⊢Δ [σ])) [SProp] Idnm
in [Γ]′ , modelsTermEq [SProp] [id] Idnm [eq]
fundamentalTermEq (Id-U-ℕℕ ⊢Γ) =
let [Γ] = valid ⊢Γ
[SProp] = Uᵛ ∞< [Γ]
[Unit] = Unitᵗᵛ {l = ¹} [Γ]
[id] , [eq] = redSubstTermᵛ {SProp ¹} {Id (U ⁰) ℕ ℕ} {Unit} [Γ] (λ ⊢Δ [σ] → Id-U-ℕℕ ⊢Δ) [SProp] [Unit]
in [Γ] , modelsTermEq (maybeEmbᵛ {A = SProp ¹} [Γ] [SProp]) [id] [Unit] [eq]
fundamentalTermEq (Id-ℕ-0S ⊢n) with fundamentalTerm ⊢n
fundamentalTermEq {Γ} (Id-ℕ-0S {n} ⊢n) | [Γ] , [ℕ] , [n] =
let [SProp] = maybeEmbᵛ {A = SProp ⁰} [Γ] (Uᵛ emb< [Γ])
[Empty] = Emptyᵗᵛ {ll = ⁰} [Γ] emb<
⊢n′ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([ℕ] {Δ = Δ} {σ = σ} ⊢Δ [σ])) (proj₁ ([n] ⊢Δ [σ]))
[id] , [eq] = redSubstTermᵛ {SProp ⁰} {t = Id ℕ zero (suc n)} {u = Empty _} [Γ] (λ {Δ} {σ} ⊢Δ [σ] → Id-ℕ-0S (⊢n′ {Δ} {σ} ⊢Δ [σ])) [SProp] [Empty]
in [Γ] , modelsTermEq [SProp] [id] [Empty] [eq]
fundamentalTermEq (Id-ℕ-S0 ⊢n) with fundamentalTerm ⊢n
fundamentalTermEq {Γ} (Id-ℕ-S0 {n} ⊢n) | [Γ] , [ℕ] , [n] =
let [SProp] = maybeEmbᵛ {A = SProp ⁰} [Γ] (Uᵛ emb< [Γ])
[Empty] = Emptyᵗᵛ {ll = ⁰} [Γ] emb<
⊢n′ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([ℕ] {Δ = Δ} {σ = σ} ⊢Δ [σ])) (proj₁ ([n] ⊢Δ [σ]))
[id] , [eq] = redSubstTermᵛ {SProp ⁰} {t = Id ℕ (suc n) zero} {u = Empty _} [Γ] (λ {Δ} {σ} ⊢Δ [σ] → Id-ℕ-S0 (⊢n′ {Δ} {σ} ⊢Δ [σ])) [SProp] [Empty]
in [Γ] , modelsTermEq [SProp] [id] [Empty] [eq]
fundamentalTermEq (Id-U-ℕΠ ⊢A ⊢B) with fundamentalTerm ⊢A | fundamentalTerm ⊢B
fundamentalTermEq {Γ} (Id-U-ℕΠ {A} {rA} {B} ⊢A ⊢B) | [Γ] , [UA] , [A]ᵗ | [Γ]₁ ∙ [A]₁ , [UB] , [B]ᵗ =
let [SProp] = Uᵛ {rU = %} ∞< [Γ]
[Empty] = Emptyᵗᵛ {ll = ¹} [Γ] ∞<
⊢AΔ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([UA] {Δ = Δ} {σ = σ} ⊢Δ [σ])) (proj₁ ([A]ᵗ ⊢Δ [σ]))
[A] = univᵛ {A = A} [Γ] (≡is≤ PE.refl) [UA] [A]ᵗ
⊢A = λ {Δ} {σ} ⊢Δ [σ] → escape (proj₁ ([A] {Δ} {σ} ⊢Δ [σ]))
[Γ∙A] : ⊩ᵛ (Γ ∙ A ^ [ rA , ι ⁰ ])
[Γ∙A] = [Γ] ∙ [A]
[UB]′ = S.irrelevance {A = Univ _ _} ([Γ]₁ ∙ [A]₁) [Γ∙A] (λ {Δ} {σ} → [UB] {Δ} {σ})
[B]ᵗ′ = S.irrelevanceTerm {A = Univ _ _} {t = B} ([Γ]₁ ∙ [A]₁) [Γ∙A] (λ {Δ} {σ} → [UB] {Δ} {σ}) (λ {Δ} {σ} → [UB]′ {Δ} {σ}) [B]ᵗ
⊢BΔ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([UB]′ {Δ} {σ} ⊢Δ [σ])) (proj₁ ([B]ᵗ′ {Δ} {σ} ⊢Δ [σ]))
[liftσ] = λ {Δ} {σ} ⊢Δ [σ] → liftSubstS {F = A} {σ = σ} {Δ = Δ} [Γ] ⊢Δ [A] [σ]
[id] , [eq] = redSubstTermᵛ {SProp ¹} {t = Id (U ⁰) ℕ (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰)} {u = Empty _} [Γ]
(λ {Δ} {σ} ⊢Δ [σ] → Id-U-ℕΠ (⊢AΔ {Δ} {σ} ⊢Δ [σ]) (⊢BΔ (⊢Δ ∙ ⊢A {Δ} {σ} ⊢Δ [σ]) ([liftσ] {Δ} {σ} ⊢Δ [σ])))
[SProp] [Empty]
in [Γ] , modelsTermEq [SProp] [id] [Empty] [eq]
fundamentalTermEq (Id-U-Πℕ ⊢A ⊢B) with fundamentalTerm ⊢A | fundamentalTerm ⊢B
fundamentalTermEq {Γ} (Id-U-Πℕ {A} {rA} {B} ⊢A ⊢B) | [Γ] , [UA] , [A]ᵗ | [Γ]₁ ∙ [A]₁ , [UB] , [B]ᵗ =
let [SProp] = Uᵛ {rU = %} ∞< [Γ]
[Empty] = Emptyᵗᵛ {ll = ¹} [Γ] ∞<
⊢AΔ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([UA] {Δ = Δ} {σ = σ} ⊢Δ [σ])) (proj₁ ([A]ᵗ ⊢Δ [σ]))
[A] = univᵛ {A = A} [Γ] (≡is≤ PE.refl) [UA] [A]ᵗ
⊢A = λ {Δ} {σ} ⊢Δ [σ] → escape (proj₁ ([A] {Δ} {σ} ⊢Δ [σ]))
[Γ∙A] : ⊩ᵛ (Γ ∙ A ^ [ rA , ι ⁰ ])
[Γ∙A] = [Γ] ∙ [A]
[UB]′ = S.irrelevance {A = Univ _ _} ([Γ]₁ ∙ [A]₁) [Γ∙A] (λ {Δ} {σ} → [UB] {Δ} {σ})
[B]ᵗ′ = S.irrelevanceTerm {A = Univ _ _} {t = B} ([Γ]₁ ∙ [A]₁) [Γ∙A] (λ {Δ} {σ} → [UB] {Δ} {σ}) (λ {Δ} {σ} → [UB]′ {Δ} {σ}) [B]ᵗ
⊢BΔ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([UB]′ {Δ} {σ} ⊢Δ [σ])) (proj₁ ([B]ᵗ′ {Δ} {σ} ⊢Δ [σ]))
[liftσ] = λ {Δ} {σ} ⊢Δ [σ] → liftSubstS {F = A} {σ = σ} {Δ = Δ} [Γ] ⊢Δ [A] [σ]
[id] , [eq] = redSubstTermᵛ {SProp ¹} {t = Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) ℕ} {u = Empty _} [Γ]
(λ {Δ} {σ} ⊢Δ [σ] → Id-U-Πℕ (⊢AΔ {Δ} {σ} ⊢Δ [σ]) (⊢BΔ (⊢Δ ∙ ⊢A {Δ} {σ} ⊢Δ [σ]) ([liftσ] {Δ} {σ} ⊢Δ [σ])))
[SProp] [Empty]
in [Γ] , modelsTermEq [SProp] [id] [Empty] [eq]
fundamentalTermEq {Γ} (Id-U-ΠΠ!% {A} {rA} {B} {A'} {rA'} {B'} eq ⊢A ⊢B ⊢A' ⊢B')
with fundamentalTerm ⊢A | fundamentalTerm ⊢B | fundamentalTerm ⊢A' | fundamentalTerm ⊢B'
... | [Γ] , [UA] , [A]ᵗ | [ΓB] , [UB] , [B]ᵗ | [ΓA'] , [UA'] , [A']ᵗ | [ΓB'] , [UB'] , [B']ᵗ =
let [SProp] = Uᵛ {rU = %} ∞< [Γ]
[Empty] = Emptyᵗᵛ {ll = ¹} [Γ] ∞<
⊢AΔ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([UA] {Δ = Δ} {σ = σ} ⊢Δ [σ])) (proj₁ ([A]ᵗ ⊢Δ [σ]))
[A] = univᵛ {A = A} [Γ] (≡is≤ PE.refl) [UA] [A]ᵗ
⊢A = λ {Δ} {σ} ⊢Δ [σ] → escape (proj₁ ([A] {Δ = Δ} {σ = σ} ⊢Δ [σ]))
[Γ∙A] : ⊩ᵛ (Γ ∙ A ^ [ rA , ι ⁰ ])
[Γ∙A] = [Γ] ∙ [A]
[UB]′ = S.irrelevance {A = Univ _ _} [ΓB] [Γ∙A] (λ {Δ} {σ} → [UB] {Δ} {σ})
[B]ᵗ′ = S.irrelevanceTerm {A = Univ _ _} {t = B} [ΓB] [Γ∙A] (λ {Δ} {σ} → [UB] {Δ} {σ}) (λ {Δ} {σ} → [UB]′ {Δ} {σ}) [B]ᵗ
⊢BΔ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([UB]′ {Δ} {σ} ⊢Δ [σ])) (proj₁ ([B]ᵗ′ {Δ} {σ} ⊢Δ [σ]))
[UA']′ = S.irrelevance {A = Univ _ _} ([ΓA']) [Γ] [UA']
[A']ᵗ′ = S.irrelevanceTerm {A = Univ _ _} {t = A'} ([ΓA']) [Γ] [UA'] [UA']′ [A']ᵗ
⊢AΔ' = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([UA']′ {Δ = Δ} {σ = σ} ⊢Δ [σ])) (proj₁ ([A']ᵗ′ ⊢Δ [σ]))
[A'] = univᵛ {A = A'} [Γ] (≡is≤ PE.refl) [UA']′ [A']ᵗ′
⊢A' = λ {Δ} {σ} ⊢Δ [σ] → escape (proj₁ ([A'] {Δ = Δ} {σ = σ} ⊢Δ [σ]))
[Γ∙A'] : ⊩ᵛ (Γ ∙ A' ^ [ rA' , ι ⁰ ])
[Γ∙A'] = [Γ] ∙ [A']
[UB']′ = S.irrelevance {A = Univ _ _} [ΓB'] [Γ∙A'] (λ {Δ} {σ} → [UB'] {Δ} {σ})
[B']ᵗ′ = S.irrelevanceTerm {A = Univ _ _} {t = B'} [ΓB'] [Γ∙A'] (λ {Δ} {σ} → [UB'] {Δ} {σ}) (λ {Δ} {σ} → [UB']′ {Δ} {σ}) [B']ᵗ
⊢BΔ' = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([UB']′ {Δ} {σ} ⊢Δ [σ])) (proj₁ ([B']ᵗ′ {Δ} {σ} ⊢Δ [σ]))
[id] , [eq] = redSubstTermᵛ {SProp ¹} {t = Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) (Π A' ^ rA' ° ⁰ ▹ B' ° ⁰ ° ⁰)} {u = Empty _} [Γ]
(λ {Δ} {σ} ⊢Δ [σ] → Id-U-ΠΠ!% eq (⊢AΔ {Δ} {σ} ⊢Δ [σ]) (⊢BΔ (⊢Δ ∙ ⊢A {Δ} {σ} ⊢Δ [σ]) (liftSubstS {F = A} [Γ] ⊢Δ [A] [σ]))
(⊢AΔ' {Δ} {σ} ⊢Δ [σ]) (⊢BΔ' (⊢Δ ∙ ⊢A' {Δ} {σ} ⊢Δ [σ]) (liftSubstS {F = A'} [Γ] ⊢Δ [A'] [σ])))
[SProp] [Empty]
in [Γ] , modelsTermEq [SProp] [id] [Empty] [eq]
fundamentalTermEq (cast-cong {A} {A'} {B} {B'} {e} {e'} {t} {t'} A≡A' B≡B' t≡t' ⊢e ⊢e')
with fundamentalTermEq A≡A' | fundamentalTermEq B≡B' | fundamentalTermEq t≡t' | fundamentalTerm ⊢e | fundamentalTerm ⊢e'
... | [Γ] , modelsTermEq [UA] [A]ₜ [A']ₜ [A≡A']ₜ | [Γ]₁ , modelsTermEq [UB] [B]ₜ [B']ₜ [B≡B']ₜ
| [Γ]₂ , modelsTermEq [A]₁ [t]ₜ [t']ₜ [t≡t']ₜ | [Γe] , [IdAB] , [e]ₜ
| [Γe'] , [IdAB'] , [e']ₜ =
let [A] = maybeEmbᵛ {A = A} [Γ] (univᵛ {A = A} [Γ] (≡is≤ PE.refl) [UA] [A]ₜ)
[B] = maybeEmbᵛ {A = B} [Γ]₁ (univᵛ {A = B} [Γ]₁ (≡is≤ PE.refl) [UB] [B]ₜ)
[UA]′ = S.irrelevance {A = Univ _ _} [Γ] [Γ]₂ [UA]
[A]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A} [Γ] [Γ]₂ [UA] [UA]′ [A]ₜ
[A']ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A'} [Γ] [Γ]₂ [UA] [UA]′ [A']ₜ
[UB]′ = S.irrelevance {A = Univ _ _} [Γ]₁ [Γ]₂ [UB]
[B]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = B} [Γ]₁ [Γ]₂ [UB] [UB]′ [B]ₜ
[B]ₜ′′ = S.irrelevanceTerm {A = Univ _ _} {t = B} [Γ]₁ [Γ]₂ [UB] [UA]′ [B]ₜ
[B']ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = B'} [Γ]₁ [Γ]₂ [UB] [UB]′ [B']ₜ
[B']ₜ′′ = S.irrelevanceTerm {A = Univ _ _} {t = B'} [Γ]₁ [Γ]₂ [UB] [UA]′ [B']ₜ
[A]′ = maybeEmbᵛ {A = A} [Γ]₂ (univᵛ {A = A} [Γ]₂ (≡is≤ PE.refl) [UA]′ [A]ₜ′)
[t]ₜ′ = S.irrelevanceTerm {A = A} {t = t} [Γ]₂ [Γ]₂ [A]₁ [A]′ [t]ₜ
[A']′ = maybeEmbᵛ {A = A'} [Γ]₂ (univᵛ {A = A'} [Γ]₂ (≡is≤ PE.refl) [UA]′ [A']ₜ′)
[t']ₜ′ = S.irrelevanceTerm {A = A} {t = t'} [Γ]₂ [Γ]₂ [A]₁ [A]′ [t']ₜ
[A≡A']ₜ′ = S.irrelevanceEqTerm {A = Univ _ _} {t = A} {u = A'} [Γ] [Γ]₂ [UA] [UA]′ [A≡A']ₜ
[A≡A']′ = S.irrelevanceEq {A = A} {B = A'} [Γ] [Γ]₂ [A] [A]′ (univEqᵛ {A = A} {B = A'} [Γ] [UA] [A] [A≡A']ₜ)
[t'A]ₜ = convᵛ {t'} {A} {A'} [Γ]₂ [A]′ [A']′ [A≡A']′ [t']ₜ′
[t≡t']ₜ′ = S.irrelevanceEqTerm {A = A} {t = t} {u = t'} [Γ]₂ [Γ]₂ [A]₁ [A]′ [t≡t']ₜ
[B]′ = maybeEmbᵛ {A = B} [Γ]₂ (univᵛ {A = B} [Γ]₂ (≡is≤ PE.refl) [UB]′ [B]ₜ′)
[B']′ = maybeEmbᵛ {A = B'} [Γ]₂ (univᵛ {A = B'} [Γ]₂ (≡is≤ PE.refl) [UB]′ [B']ₜ′)
[B≡B']ₜ′ = S.irrelevanceEqTerm {A = Univ _ _} {t = B} {u = B'} [Γ]₁ [Γ]₂ [UB] [UB]′ [B≡B']ₜ
[B≡B']′ = S.irrelevanceEq {A = B} {B = B'} [Γ]₁ [Γ]₂ [B] [B]′ (univEqᵛ {A = B} {B = B'} [Γ]₁ [UB] [B] [B≡B']ₜ)
[IdAB]′ = S.irrelevance {A = Id (Univ _ _) A B} [Γe] [Γ]₂ [IdAB]
[e]ₜ′ = S.irrelevanceTerm {A = Id (Univ _ _) A B} {t = e} [Γe] [Γ]₂ [IdAB] [IdAB]′ [e]ₜ
[IdAB']′ = S.irrelevance {A = Id (Univ _ _) A' B'} [Γe'] [Γ]₂ [IdAB']
[e']ₜ′ = S.irrelevanceTerm {A = Id (Univ _ _) A' B'} {t = e'} [Γe'] [Γ]₂ [IdAB'] [IdAB']′ [e']ₜ
in [Γ]₂
, modelsTermEq [B]′ (castᵗᵛ {A} {B} { ! } {t} {e} [Γ]₂ [UA]′ [A]ₜ′ [B]ₜ′′ [A]′ [B]′ [t]ₜ′ [IdAB]′ [e]ₜ′)
(conv₂ᵛ {cast _ A' B' e' t'} {B} {B'} [Γ]₂ [B]′ [B']′ [B≡B']′
(castᵗᵛ {A'} {B'} { ! } {t'} {e'} [Γ]₂ [UA]′ [A']ₜ′ [B']ₜ′′ [A']′ [B']′ [t'A]ₜ [IdAB']′ [e']ₜ′))
(cast-congᵗᵛ {A} {A'} {B} {B'} {t} {t'} {e} {e'} [Γ]₂ [UA]′ [UB]′ [A]ₜ′ [A']ₜ′ [B]ₜ′ [B']ₜ′ [A≡A']ₜ′ [B≡B']ₜ′ [A]′ [A']′ [B]′ [B']′ [t]ₜ′ [t'A]ₜ [t≡t']ₜ′
[IdAB]′ [e]ₜ′ [IdAB']′ [e']ₜ′)
fundamentalTermEq (cast-ℕ-0 {e} ⊢e) with fundamentalTerm ⊢e
... | [Γ] , [Id] , [e]ₜ =
let ⊢eΔ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([Id] {Δ} {σ} ⊢Δ [σ])) (proj₁ ([e]ₜ {Δ} {σ} ⊢Δ [σ]))
[zero] = zeroᵛ {l = ∞} [Γ]
[id] , [eq] = redSubstTermᵛ {ℕ} {cast ⁰ ℕ ℕ e zero} {zero} {∞} [Γ]
(λ {Δ} {σ} ⊢Δ [σ] → cast-ℕ-0 (⊢eΔ {Δ} {σ} ⊢Δ [σ]))
(ℕᵛ [Γ]) [zero]
in [Γ] , modelsTermEq (ℕᵛ [Γ]) [id] [zero] [eq]
fundamentalTermEq (cast-ℕ-S {e} {n} ⊢e ⊢n) with fundamentalTerm ⊢e | fundamentalTerm ⊢n
... | [Γ] , [Id] , [e]ₜ | [Γ]₁ , [ℕ] , [n]ₜ =
let [Id]′ = S.irrelevance {A = Id (U _) ℕ ℕ} [Γ] [Γ]₁ [Id]
[e]ₜ′ = S.irrelevanceTerm {A = Id (U _) ℕ ℕ} {t = e} [Γ] [Γ]₁ [Id] [Id]′ [e]ₜ
⊢eΔ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([Id]′ {Δ} {σ} ⊢Δ [σ])) (proj₁ ([e]ₜ′ {Δ} {σ} ⊢Δ [σ]))
⊢nΔ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([ℕ] {Δ} {σ} ⊢Δ [σ])) (proj₁ ([n]ₜ {Δ} {σ} ⊢Δ [σ]))
[suc-cast] = sucᵛ {n = cast ⁰ ℕ ℕ e n} [Γ]₁ [ℕ] (castᵗᵛ {ℕ} {ℕ} { ! } {n} {e} [Γ]₁ (maybeEmbᵛ {A = Univ _ _} [Γ]₁ (Uᵛ emb< [Γ]₁))
(ℕᵗᵛ [Γ]₁) (ℕᵗᵛ [Γ]₁) [ℕ] [ℕ] [n]ₜ [Id]′ [e]ₜ′)
[id] , [eq] = redSubstTermᵛ {ℕ} {cast ⁰ ℕ ℕ e (suc n)} {suc (cast ⁰ ℕ ℕ e n)} {∞} [Γ]₁
(λ {Δ} {σ} ⊢Δ [σ] → cast-ℕ-S (⊢eΔ {Δ} {σ} ⊢Δ [σ]) (⊢nΔ {Δ} {σ} ⊢Δ [σ]))
[ℕ] [suc-cast]
in [Γ]₁ , modelsTermEq [ℕ] [id] [suc-cast] [eq]
fundamentalTermEq {Γ} (cast-Π {A} {A'} {rA} {B} {B'} {e} {f} ⊢A ⊢B ⊢A' ⊢B' ⊢e ⊢f)
with fundamentalTerm ⊢A | fundamentalTerm ⊢B | fundamentalTerm ⊢A' | fundamentalTerm ⊢B' | fundamentalTerm ⊢e | fundamentalTerm ⊢f
... | [ΓA] , [UA] , [A]ₜ | [ΓB] ∙ [AB] , [UB] , [B]ₜ | [ΓA'] , [UA'] , [A']ₜ | [ΓB'] ∙ [AB'] , [UB'] , [B']ₜ | [Γ] , [Id] , [e]ₜ | [Γ]₁ , [ΠAB] , [f]ₜ =
let [UA]′ = maybeEmbᵛ {A = Univ rA _} [Γ]₁ (Uᵛ emb< [Γ]₁)
[A]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A} [ΓA] [Γ]₁ [UA] [UA]′ [A]ₜ
[A']ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A'} [ΓA'] [Γ]₁ [UA'] [UA]′ [A']ₜ
[A] = maybeEmbᵛ {A = A} [Γ]₁ (univᵛ {A = A} [Γ]₁ (≡is≤ PE.refl) [UA]′ [A]ₜ′)
[A'] = maybeEmbᵛ {A = A'} [Γ]₁ (univᵛ {A = A'} [Γ]₁ (≡is≤ PE.refl) [UA]′ [A']ₜ′)
[ΓB]₁ = [Γ]₁ ∙ [A]
[UB]′ = S.irrelevance {A = Univ _ _} {Γ = Γ ∙ A ^ _} ([ΓB] ∙ [AB]) [ΓB]₁ (λ {Δ} {σ} → [UB] {Δ} {σ})
[B]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = B} ([ΓB] ∙ [AB]) [ΓB]₁ (λ {Δ} {σ} → [UB] {Δ} {σ}) (λ {Δ} {σ} → [UB]′ {Δ} {σ}) [B]ₜ
[ΓB']₁ = [Γ]₁ ∙ [A']
[UB']′ = S.irrelevance {A = Univ _ _} {Γ = Γ ∙ A' ^ _} ([ΓB'] ∙ [AB']) [ΓB']₁ (λ {Δ} {σ} → [UB'] {Δ} {σ})
[B']ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = B'} ([ΓB'] ∙ [AB']) [ΓB']₁ (λ {Δ} {σ} → [UB'] {Δ} {σ}) (λ {Δ} {σ} → [UB']′ {Δ} {σ}) [B']ₜ
[B'] = maybeEmbᵛ {A = B'} [ΓB']₁ (univᵛ {A = B'} [ΓB']₁ (≡is≤ PE.refl) (λ {Δ} {σ} → [UB']′ {Δ} {σ}) [B']ₜ′)
[Id]′ = S.irrelevance {A = Id (Univ _ _) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) (Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰)} [Γ] [Γ]₁ [Id]
[e]ₜ′ = S.irrelevanceTerm {A = Id (Univ _ _) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰ ) (Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰)} {t = e} [Γ] [Γ]₁ [Id] [Id]′ [e]ₜ
in [Γ]₁ , cast-Πᵗᵛ {A} {B} {A'} {B'} {rA} {Γ} {e} {f} [Γ]₁ [A] [A'] (λ {Δ} {σ} → [UB]′ {Δ} {σ}) (λ {Δ} {σ} → [UB']′ {Δ} {σ})
[A]ₜ′ [B]ₜ′ [A']ₜ′ [B']ₜ′ [Id]′ [e]ₜ′ [ΠAB] [f]ₜ
fundamentalTermEq {Γ} (Id-SProp {A} {B} ⊢A ⊢B) with fundamentalTerm ⊢A | fundamentalTerm ⊢B
... | [ΓA] , [UA] , [A]ₜ | [ΓB] , [UB] , [B]ₜ =
let [SProp] = Uᵛ {rU = %} ∞< [ΓB]
[UA]′ = maybeEmbᵛ {A = Univ _ _} [ΓB] (Uᵛ emb< [ΓB])
[A]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A} [ΓA] [ΓB] [UA] [UA]′ [A]ₜ
[B]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = B} [ΓB] [ΓB] [UB] [UA]′ [B]ₜ
⊢AΔ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([UA]′ {Δ} {σ} ⊢Δ [σ])) (proj₁ ([A]ₜ′ ⊢Δ [σ]))
[A] = maybeEmbᵛ {A = A} [ΓB] (univᵛ {A = A} [ΓB] (≡is≤ PE.refl) [UA]′ [A]ₜ′)
[B] = maybeEmbᵛ {A = B} [ΓB] (univᵛ {A = B} [ΓB] (≡is≤ PE.refl) [UB] [B]ₜ)
⊢BΔ = λ {Δ} {σ} ⊢Δ [σ] → escapeTerm (proj₁ ([UB] {Δ} {σ} ⊢Δ [σ])) (proj₁ ([B]ₜ ⊢Δ [σ]))
_▹▹⁰_ = λ A B → A ^ % ° ⁰ ▹▹ B ° ⁰ ° ¹
Id-SProp-res = λ A B → (A ▹▹⁰ B) ×× (B ▹▹⁰ A)
[Id-SProp] : Γ ⊩ᵛ Id (SProp ⁰) A B ⇒ Id-SProp-res A B ∷ SProp ¹ ^ ∞ / [ΓB]
[Id-SProp] = λ {Δ} {σ} ⊢Δ [σ] → PE.subst (λ ret → Δ ⊢ Id (SProp ⁰) (subst σ A) (subst σ B) ⇒ ret ∷ SProp ¹ ^ ∞ )
(PE.cong₄ (λ a b c d → ∃ (Π a ^ % ° ⁰ ▹ b ° ⁰ ° ¹) ▹ (Π c ^ % ° ⁰ ▹ d ° ⁰ ° ¹))
PE.refl (PE.sym (Idsym-subst-lemma σ B)) (PE.sym (Idsym-subst-lemma σ B))
(PE.trans (PE.cong wk1d (PE.sym (Idsym-subst-lemma σ A))) (PE.sym (Idsym-subst-lemma-wk1d σ (wk1 A)))))
(Id-SProp {A = subst σ A} {B = subst σ B} (⊢AΔ {Δ} {σ} ⊢Δ [σ]) (⊢BΔ {Δ} {σ} ⊢Δ [σ]))
[A▹▹B]ₜ = ▹▹ᵗᵛ {F = A} {G = B} (<is≤ 0<1) (<is≤ 0<1) [ΓB] [A] [UA]′ [A]ₜ′ [B]ₜ′
[A▹▹B] = maybeEmbᵛ {A = A ▹▹⁰ B} [ΓB] (univᵛ {A = A ▹▹⁰ B} [ΓB] (≡is≤ PE.refl) [SProp] [A▹▹B]ₜ)
[B▹▹A]ₜ = ▹▹ᵗᵛ {F = B} {G = A} (<is≤ 0<1) (<is≤ 0<1) [ΓB] [B] [UA]′ [B]ₜ′ [A]ₜ′
[Id-SProp-res] : Γ ⊩ᵛ⟨ ∞ ⟩ Id-SProp-res A B ∷ SProp ¹ ^ [ ! , ∞ ] / [ΓB] / [SProp]
[Id-SProp-res] = ××ᵗᵛ {F = A ▹▹⁰ B} {G = B ▹▹⁰ A} [ΓB] [A▹▹B] [A▹▹B]ₜ [B▹▹A]ₜ
[id] , [eq] = redSubstTermᵛ {SProp ¹} {Id (SProp ⁰) A B} {Id-SProp-res A B}
[ΓB] (λ {Δ} {σ} ⊢Δ [σ] → [Id-SProp] {Δ} {σ} ⊢Δ [σ])
[SProp] [Id-SProp-res]
in [ΓB] , modelsTermEq [SProp] [id] [Id-SProp-res] [eq]
fundamentalTermEq (Id-U-ΠΠ ⊢A ⊢B ⊢A' ⊢B') with fundamentalTerm ⊢A | fundamentalTerm ⊢B | fundamentalTerm ⊢A' | fundamentalTerm ⊢B'
fundamentalTermEq (Id-U-ΠΠ {A} {A'} {rA} {B} {B'} ⊢A ⊢B ⊢A' ⊢B') | [Γ] , [UA] , [A]ₜ | [Γ]₁ ∙ [A]₁ , [UB] , [B]ₜ | [Γ]' , [UA'] , [A']ₜ | [Γ]₁' ∙ [A']₁ , [UB'] , [B']ₜ =
let [A]′ = S.irrelevance {A = A} [Γ] [Γ]₁' (maybeEmbᵛ {A = A} [Γ] (univᵛ {A = A} [Γ] (≡is≤ PE.refl) [UA] [A]ₜ))
[A']′ = S.irrelevance {A = A'} [Γ]' [Γ]₁' (maybeEmbᵛ {A = A'} [Γ]' (univᵛ {A = A'} [Γ]' (≡is≤ PE.refl) [UA'] [A']ₜ))
[UB]′ = S.irrelevance {A = Univ _ _} (_∙_ {A = A} [Γ]₁ [A]₁) (_∙_ {A = A} [Γ]₁' [A]′) (λ {Δ} {σ} → [UB] {Δ} {σ})
[UB']′ = S.irrelevance {A = Univ _ _} (_∙_ {A = A'} [Γ]₁' [A']₁) (_∙_ {A = A'} [Γ]₁' [A']′) (λ {Δ} {σ} → [UB'] {Δ} {σ})
[U] = maybeEmbᵛ {A = Univ rA _} [Γ]₁' (Uᵛ emb< [Γ]₁')
[A]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A} [Γ] [Γ]₁' [UA] [U] [A]ₜ
[A']ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = A'} [Γ]' [Γ]₁' [UA'] [U] [A']ₜ
[B]ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = B} (_∙_ {A = A} [Γ]₁ [A]₁) (_∙_ {A = A} [Γ]₁' [A]′) (λ {Δ} {σ} → [UB] {Δ} {σ}) (λ {Δ} {σ} → [UB]′ {Δ} {σ}) [B]ₜ
[B']ₜ′ = S.irrelevanceTerm {A = Univ _ _} {t = B'} (_∙_ {A = A'} [Γ]₁' [A']₁) (_∙_ {A = A'} [Γ]₁' [A']′) (λ {Δ} {σ} → [UB'] {Δ} {σ}) (λ {Δ} {σ} → [UB']′ {Δ} {σ}) [B']ₜ
in [Γ]₁' , Id-U-ΠΠᵗᵛ [Γ]₁' [A]′ [A']′ (λ {Δ} {σ} → [UB]′ {Δ} {σ}) (λ {Δ} {σ} → [UB']′ {Δ} {σ}) [A]ₜ′ [B]ₜ′ [A']ₜ′ [B']ₜ′
-- Fundamental theorem for substitutions.
fundamentalSubst : ∀ {Γ Δ σ} (⊢Γ : ⊢ Γ) (⊢Δ : ⊢ Δ)
→ Δ ⊢ˢ σ ∷ Γ
→ ∃ λ [Γ] → Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ
fundamentalSubst ε ⊢Δ [σ] = ε , tt
fundamentalSubst (⊢Γ ∙ ⊢A) ⊢Δ ([tailσ] , [headσ]) =
let [Γ] , [A] = fundamental ⊢A
[Δ] , [A]′ , [t] = fundamentalTerm [headσ]
[Γ]′ , [σ] = fundamentalSubst ⊢Γ ⊢Δ [tailσ]
[tailσ]′ = S.irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]
[idA] = proj₁ ([A]′ (soundContext [Δ]) (idSubstS [Δ]))
[idA]′ = proj₁ ([A] ⊢Δ [tailσ]′)
[idt] = proj₁ ([t] (soundContext [Δ]) (idSubstS [Δ]))
in [Γ] ∙ [A] , ([tailσ]′
, irrelevanceTerm″ (subst-id _) PE.refl PE.refl (subst-id _) [idA] [idA]′ [idt])
-- Fundamental theorem for substitution equality.
fundamentalSubstEq : ∀ {Γ Δ σ σ′} (⊢Γ : ⊢ Γ) (⊢Δ : ⊢ Δ)
→ Δ ⊢ˢ σ ≡ σ′ ∷ Γ
→ ∃₂ λ [Γ] [σ]
→ ∃ λ ([σ′] : Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]
fundamentalSubstEq ε ⊢Δ σ = ε , tt , tt , tt
fundamentalSubstEq (⊢Γ ∙ ⊢A) ⊢Δ (tailσ≡σ′ , headσ≡σ′) =
let [Γ] , [A] = fundamental ⊢A
[Γ]′ , [tailσ] , [tailσ′] , [tailσ≡σ′] = fundamentalSubstEq ⊢Γ ⊢Δ tailσ≡σ′
[Δ] , modelsTermEq [A]′ [t] [t′] [t≡t′] = fundamentalTermEq headσ≡σ′
[tailσ]′ = S.irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [tailσ]
[tailσ′]′ = S.irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [tailσ′]
[tailσ≡σ′]′ = S.irrelevanceSubstEq [Γ]′ [Γ] ⊢Δ ⊢Δ [tailσ] [tailσ]′ [tailσ≡σ′]
[idA] = proj₁ ([A]′ (soundContext [Δ]) (idSubstS [Δ]))
[idA]′ = proj₁ ([A] ⊢Δ [tailσ]′)
[idA]″ = proj₁ ([A] ⊢Δ [tailσ′]′)
[idt] = proj₁ ([t] (soundContext [Δ]) (idSubstS [Δ]))
[idt′] = proj₁ ([t′] (soundContext [Δ]) (idSubstS [Δ]))
[idt≡t′] = [t≡t′] (soundContext [Δ]) (idSubstS [Δ])
in [Γ] ∙ [A]
, ([tailσ]′ , irrelevanceTerm″ (subst-id _) PE.refl PE.refl (subst-id _) [idA] [idA]′ [idt])
, ([tailσ′]′ , convTerm₁ [idA]′ [idA]″
(proj₂ ([A] ⊢Δ [tailσ]′) [tailσ′]′ [tailσ≡σ′]′)
(irrelevanceTerm″ (subst-id _) PE.refl PE.refl (subst-id _)
[idA] [idA]′ [idt′]))
, ([tailσ≡σ′]′ , irrelevanceEqTerm″ PE.refl PE.refl (subst-id _) (subst-id _) (subst-id _)
[idA] [idA]′ [idt≡t′])
|
{
"alphanum_fraction": 0.3930807765,
"avg_line_length": 66.750261233,
"ext": "agda",
"hexsha": "f810c70123e3c83e2a419efdeac16fc0f90c0796",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Fundamental.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"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": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Fundamental.agda",
"max_line_length": 179,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Fundamental.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 33544,
"size": 63880
}
|
module Oscar.Data.Term.ThickAndThin.internal {𝔣} (FunctionName : Set 𝔣) where
open import Oscar.Class.AlphaConversion
import Oscar.Class.ThickAndThin as ⋆
open import Oscar.Data.Term FunctionName
open import Oscar.Data.Term.Injectivity FunctionName
open import Oscar.Data.Term.AlphaConversion FunctionName
open import Oscar.Data.Equality
open import Oscar.Data.Equality.properties
open import Oscar.Data.Fin
open import Oscar.Data.Fin.ThickAndThin
open import Oscar.Data.Nat
open import Oscar.Data.Vec
open import Oscar.Data.Vec.Injectivity
open import Oscar.Function
private
Fin⋆thin = ⋆.ThickAndThin.thin ThickAndThinFin
Fin⋆thick = ⋆.ThickAndThin.thick ThickAndThinFin
thin : ∀ {m} → Fin (suc m) → Term m → Term (suc m)
thin = _◂_ ∘ Fin⋆thin
thins : ∀ {m} → Fin (suc m) → ∀ {N} → Vec (Term m) N → Vec (Term (suc m)) N
thins y = Fin⋆thin y ◂_ -- TODO: make point-free
mutual
thin-injective : ∀ {m} (y : Fin (suc m)) {τ₁ τ₂ : Term m} → thin y τ₁ ≡ thin y τ₂ → τ₁ ≡ τ₂
thin-injective y {i _} {i _} eq
rewrite ⋆.thin-injective y (Term-i-inj eq)
= refl
thin-injective y {_ fork _} {_ fork _} eq
rewrite thin-injective y (Term-forkLeft-inj eq)
| thin-injective y (Term-forkRight-inj eq)
= refl
thin-injective _ {leaf} {leaf} _ = refl
thin-injective y {function _ _} {function _ _} eq rewrite Term-functionName-inj eq with Term-functionArity-inj eq
… | refl with Term-functionTerms-inj eq
… | eq' rewrite (thins-injective y eq') = refl
thin-injective _ {i _} {leaf} ()
thin-injective _ {i _} {_ fork _} ()
thin-injective _ {i _} {function _ _} ()
thin-injective _ {leaf} {i _} ()
thin-injective _ {leaf} {_ fork _} ()
thin-injective _ {leaf} {function _ _} ()
thin-injective _ {_ fork _} {i _} ()
thin-injective _ {_ fork _} {leaf} ()
thin-injective _ {_ fork _} {function _ _} ()
thin-injective _ {function _ _} {i _} ()
thin-injective _ {function _ _} {leaf} ()
thin-injective _ {function _ _} {_ fork _} ()
thins-injective : ∀ {m} (f : Fin (suc m)) → ∀ {N} {τs₁ τs₂ : Vec (Term m) N} → thins f τs₁ ≡ thins f τs₂ → τs₁ ≡ τs₂
thins-injective y {_} {[]} {[]} x₁ = refl
thins-injective y {_} {_ ∷ _} {_ ∷ _} eq
rewrite thin-injective y (Vec-head-inj eq)
| thins-injective y (Vec-tail-inj eq)
= refl
thick : ∀ {m} → Term (suc m) → Fin m → Term m
thick τ = flip _◂_ τ ∘ flip Fin⋆thick
thicks : ∀ {m N} → Terms N (suc m) → Fin m → Terms N m
thicks τ = flip _◂_ τ ∘ flip Fin⋆thick
|
{
"alphanum_fraction": 0.6585858586,
"avg_line_length": 36.3970588235,
"ext": "agda",
"hexsha": "9b7b82ec3d9bbb2254675143e890c4c3927817b5",
"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/Term/ThickAndThin/internal.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/Term/ThickAndThin/internal.agda",
"max_line_length": 118,
"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/Term/ThickAndThin/internal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 871,
"size": 2475
}
|
module Oscar.Data.Substitist {𝔣} (FunctionName : Set 𝔣) where
open import Oscar.Data.Fin
open import Oscar.Data.Nat
open import Oscar.Data.Product
open import Oscar.Data.Term FunctionName
open import Oscar.Data.AList
open import Oscar.Data.Equality
Substitist : Nat → Nat → Set 𝔣
Substitist m n = AList (λ m → Term m × Fin (suc m)) n m
pattern anil = []
pattern _asnoc_/_ σ t x = (t , x) ∷ σ
_⊸_ = Substitist
infixr 9 _∙_
_∙_ : ∀ {m n} → m ⊸ n → ∀ {l} → l ⊸ m → l ⊸ n
ρ ∙ anil = ρ
ρ ∙ (σ asnoc t / x) = (ρ ∙ σ) asnoc t / x
∙-associativity : ∀ {k l} (f : k ⊸ l) {m} (g : l ⊸ m) {n} (h : m ⊸ n) → (h ∙ g) ∙ f ≡ h ∙ g ∙ f
∙-associativity anil σ _ = refl
∙-associativity (τ asnoc t / x) ρ σ = cong (λ s → s asnoc t / x) (∙-associativity τ ρ σ)
ε : ∀ {n} → n ⊸ n
ε = anil
∙-left-identity : ∀ {m n} (σ : m ⊸ n) → ε ∙ σ ≡ σ
∙-left-identity anil = refl
∙-left-identity (σ asnoc t' / x) = cong (λ σ → σ asnoc t' / x) (∙-left-identity σ)
∙-right-identity : ∀ {m n} (σ : m ⊸ n) → σ ∙ ε ≡ σ
∙-right-identity _ = refl
open import Oscar.Category
semigroupoidSubstitist : Semigroupoid Substitist (λ {x y} → ≡-setoid (Substitist x y))
Semigroupoid._∙_ semigroupoidSubstitist = _∙_
Semigroupoid.∙-extensionality semigroupoidSubstitist refl refl = refl
Semigroupoid.∙-associativity semigroupoidSubstitist = ∙-associativity
Substitist' : Nat → Nat → Set 𝔣
Substitist' m n = AList (λ m → Term m × Fin (suc m)) m n
semigroupoidSubstitist' : Semigroupoid Substitist' (λ {x y} → ≡-setoid (Substitist' x y))
semigroupoidSubstitist' = Category'.semigroupoidAList
categorySubstitist : Category semigroupoidSubstitist
Category.ε categorySubstitist = ε
Category.ε-left-identity categorySubstitist = ∙-left-identity _
Category.ε-right-identity categorySubstitist = ∙-right-identity _
|
{
"alphanum_fraction": 0.6666666667,
"avg_line_length": 32.1818181818,
"ext": "agda",
"hexsha": "a6db59c47b3a70b0ac2e3bb756b4f41a67429a92",
"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/Substitist.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/Substitist.agda",
"max_line_length": 95,
"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/Substitist.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 700,
"size": 1770
}
|
module Prelude where
open import Data.Nat public
open import Data.Nat.Properties.Simple public
open import Data.Fin using (Fin; #_; suc; zero) public
open import Data.Unit using (tt; ⊤) public
open import Data.Empty public
open import Data.Bool using (true; false; Bool) public
open import Data.Product public using (∃; ∃₂; _×_; _,_; proj₁; proj₂; ,_) public
open import Relation.Binary.PropositionalEquality hiding ([_]) public
open ≡-Reasoning public
open import Relation.Nullary public
open import Relation.Nullary.Decidable using (True) public
open import Function using (_∘_; _$_; id; const; flip) public
|
{
"alphanum_fraction": 0.7662337662,
"avg_line_length": 30.8,
"ext": "agda",
"hexsha": "1e35a433db87e183602d7729744a58f21ee19f5f",
"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/Prelude.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/Prelude.agda",
"max_line_length": 80,
"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/Prelude.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": 159,
"size": 616
}
|
open import Categories
open import Functors
open import RMonads
module RMonads.CatofRAdj.InitRAdj {a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}
{J : Fun C D}(M : RMonad J) where
open import Library
open import Naturals hiding (Iso; module Iso)
open import RAdjunctions
open import RMonads.CatofRAdj M
open import Categories.Initial
open import RMonads.RKleisli M
open import RMonads.RKleisli.Functors M
open import RMonads.RKleisli.Adjunction M
open import RAdjunctions.RAdj2RMon
open Cat
open Fun
open RMonad M
open NatT
open RAdj
lemX : R KlAdj ○ L KlAdj ≅ TFun M
lemX = FunctorEq _ _ refl refl
KlObj : Obj CatofAdj
KlObj = record {
E = Kl;
adj = KlAdj;
law = lemX;
ηlaw = refl;
bindlaw = λ{X}{Y}{f} →
cong bind (stripsubst (Hom D (OMap J X))
f
(fcong Y (cong OMap (sym lemX))))}
where
open Cat
open ObjAdj
open import Isomorphism
open Iso
lemZ : {F G G' : Fun C D} → G ≅ G' → {α : NatT F G}{β : NatT F G'} →
α ≅ β →
∀{X} → cmp α {X} ≅ cmp β {X}
lemZ refl refl = refl
lemZ' : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{F F' G G' : Fun C D} →
F ≅ F' → G ≅ G' →
{α : NatT F G}{β : NatT F' G'} → α ≅ β →
∀{X} → cmp α {X} ≅ cmp β {X}
lemZ' refl refl refl = refl
lemfid : ∀{e f}{E : Cat {e}{f}}(L : Fun C E)(R : Fun E D)
(T : Fun C D)
(p : T ≅ R ○ L)
(η : ∀ {X} → Hom D (OMap J X) (OMap T X))
(right : {X : Obj C}{Y : Obj E} →
Hom D (OMap J X) (OMap R Y) → Hom E (OMap L X) Y) →
(left : {X : Obj C}{Y : Obj E} →
Hom E (OMap L X) Y → Hom D (OMap J X) (OMap R Y)) →
(q : {X : Obj C}{Y : Obj E}(f : Hom E (OMap L X) Y) → right (left f) ≅ f) →
(r : {X : Obj C} → left (iden E {OMap L X}) ≅ η {X}) →
{X : Obj C} →
right (subst (Hom D (OMap J X)) (fcong X (cong OMap p)) η)
≅
iden E {OMap L X}
lemfid {E = E} L R .(R ○ L) refl η right left q r {X} =
trans (cong right (sym r)) (q (iden E))
lemfcomp : ∀{e f}{E : Cat {e}{f}}(L : Fun C E)(R : Fun E D)(T : Fun C D)
(p : T ≅ R ○ L)
(bind : ∀{X Y} → Hom D (OMap J X) (OMap T Y) → Hom D (OMap T X) (OMap T Y)) →
(right : {X : Obj C} {Y : Obj E} →
Hom D (OMap J X) (OMap R Y) → Hom E (OMap L X) Y) →
(q : {X Y : Obj C} {f : Hom D (OMap J X) (OMap T Y)} →
HMap R (right (subst (Hom D (OMap J X)) (fcong Y (cong OMap p)) f))
≅
bind f) →
(r : {X X' : Obj C}{Y Y' : Obj E}
(f : Hom C X' X)(g : Hom E Y Y')
(h : Hom D (OMap J X) (OMap R Y)) →
right (comp D (HMap R g) (comp D h (HMap J f)))
≅
comp E g (comp E (right h) (HMap L f))) →
∀{X Y Z : Obj C}
{f : Hom D (OMap J Y) (OMap T Z)}
{g : Hom D (OMap J X) (OMap T Y)} →
right (subst (Hom D (OMap J X)) (fcong Z (cong OMap p)) (comp D (bind f) g))
≅
comp E (right (subst (Hom D (OMap J Y)) (fcong Z (cong OMap p)) f))
(right (subst (Hom D (OMap J X)) (fcong Y (cong OMap p)) g))
lemfcomp {E = E} L R .(R ○ L) refl bind right q r {X}{Y}{Z}{f}{g} =
trans (cong₂ (λ f g → right (comp D f g)) (sym (q {f = f})) (sym (idr D)))
(trans (cong (λ h → right (comp D (HMap R (right f)) (comp D g h)))
(sym (fid J)))
(trans (r (iden C) (right f) g)
(cong (comp E (right f))
(trans (cong (comp E (right g)) (fid L))
(idr E)))))
lemLlaw : ∀{e f}{E : Cat {e}{f}}(J : Fun C D)(L : Fun C E)(R : Fun E D)(T : Fun C D)
(p : T ≅ R ○ L)
(η : ∀ {X} → Hom D (OMap J X) (OMap T X)) →
(right : {X : Obj C} {Y : Obj E} →
Hom D (OMap J X) (OMap R Y) → Hom E (OMap L X) Y) →
(left : {X : Obj C} {Y : Obj E} →
Hom E (OMap L X) Y → Hom D (OMap J X) (OMap R Y)) →
(q : {X : Obj C} {Y : Obj E} (f : Hom E (OMap L X) Y) →
right (left f) ≅ f) →
(r : {X : Obj C} → left (iden E {OMap L X}) ≅ η {X}) →
(t : {X X' : Obj C}{Y Y' : Obj E}
(f : Hom C X' X)(g : Hom E Y Y')
(h : Hom D (OMap J X) (OMap R Y)) →
right (comp D (HMap R g) (comp D h (HMap J f)))
≅
comp E g (comp E (right h) (HMap L f)) ) →
{X Y : Obj C} (f : Hom C X Y) →
right (subst (Hom D (OMap J X))
(fcong Y (cong OMap p))
(comp D η (HMap J f)))
≅
HMap L f
lemLlaw {E = E} J L R .(R ○ L) refl η right left q r t {X}{Y} f =
trans (cong (λ g → right (comp D g (HMap J f))) (sym r))
(trans (cong right
(trans (sym (idl D))
(cong (λ g → comp D g (comp D (left (iden E))
(HMap J f)))
(sym (fid R)))))
(trans (trans (trans (t f (iden E) (left (iden E)))
(idl E))
(cong (λ g → comp E g (HMap L f)) (q (iden E))))
(idl E)))
K' : ∀{e}{f}(A : Obj (CatofAdj {e}{f})) → Fun (E KlObj) (E A)
K' A = record {
OMap = OMap (L (adj A));
HMap = λ{X}{Y} f →
right (adj A) (subst (Hom D (OMap J X))
(fcong Y (cong OMap (sym (ObjAdj.law A))))
f);
fid = lemfid
(L (adj A))
(R (adj A))
(TFun M)
(sym (law A))
η
(right (adj A))
(left (adj A))
(lawa (adj A))
(ObjAdj.ηlaw A);
fcomp = lemfcomp
(L (adj A))
(R (adj A))
(TFun M)
(sym (law A))
bind
(right (adj A))
(bindlaw A)
(natright (adj A))}
Llaw' : ∀{e}{f}(A : Obj (CatofAdj {e}{f})) → K' A ○ L (adj KlObj) ≅ L (adj A)
Llaw' A = FunctorEq
_
_
refl
(iext λ _ → iext λ _ → ext $ lemLlaw J
(L (adj A))
(R (adj A))
(TFun M)
(sym (law A))
η
(right (adj A))
(left (adj A))
(lawa (adj A))
(ηlaw A)
(natright (adj A)))
Rlaw' : ∀{e}{f}(A : Obj (CatofAdj {e}{f})) → R (adj KlObj) ≅ R (adj A) ○ K' A
Rlaw' A = FunctorEq _ _ (cong OMap (sym (law A)))
(iext λ _ → iext λ _ → ext λ _ → sym (bindlaw A))
rightlaw' : ∀{e f}(A : Obj (CatofAdj {e}{f})) →
{X : Obj C} {Y : Obj (E KlObj)}
{f : Hom D (OMap J X) (OMap (R (adj KlObj)) Y)} →
HMap (K' A) (right (adj KlObj) f) ≅
right (adj A) (subst (Hom D (OMap J X)) (fcong Y (cong OMap (Rlaw' A))) f)
rightlaw' A {X}{Y}{f} = cong (right (adj A)) (trans (stripsubst (Hom D (OMap J X)) f (fcong Y (cong OMap (sym (law A))))) (sym (stripsubst (Hom D (OMap J X)) f (fcong Y (cong OMap (Rlaw' A))))) )
KlHom : {A : Obj CatofAdj} → Hom CatofAdj KlObj A
KlHom {A = A} = record {
K = K' A;
Llaw = Llaw' A;
Rlaw = Rlaw' A;
rightlaw = rightlaw' A}
KlIsInit : Init CatofAdj KlObj
KlIsInit = record {
i = KlHom;
law = λ {X} {V} → HomAdjEq
_
_
((FunctorEq _ _ (cong OMap (sym (HomAdj.Llaw V)))
(iext λ A → iext λ B → ext λ f →
trans
(cong₂ (λ B₁ → right (adj X) {A} {B₁})
(sym (fcong B (cong OMap (HomAdj.Llaw V))))
(trans
(stripsubst (Hom D (OMap J A)) f
(fcong B (cong OMap (sym (law X)))))
(sym
(stripsubst (Hom D (OMap J A)) f
(fcong B (cong OMap (HomAdj.Rlaw V)))))))
(sym (HomAdj.rightlaw V)))))}
-- -}
|
{
"alphanum_fraction": 0.4200378072,
"avg_line_length": 36.0681818182,
"ext": "agda",
"hexsha": "725585ebff63d864448c803a864fd2d4671f4726",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "RMonads/CatofRAdj/InitRAdj.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "RMonads/CatofRAdj/InitRAdj.agda",
"max_line_length": 195,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "RMonads/CatofRAdj/InitRAdj.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 2997,
"size": 7935
}
|
module ASN1 where
open import ASN1.Untyped public
open import ASN1.BER public
open import ASN1.X509 public
|
{
"alphanum_fraction": 0.8240740741,
"avg_line_length": 18,
"ext": "agda",
"hexsha": "fdfae3f0c683ccb3f2504ca2dd268031b90f8935",
"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": "bbbeb679fa2c55a12f0cb345ad920c999c3f8fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "semenov-vladyslav/asn1-agda",
"max_forks_repo_path": "src/ASN1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bbbeb679fa2c55a12f0cb345ad920c999c3f8fa8",
"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/asn1-agda",
"max_issues_repo_path": "src/ASN1.agda",
"max_line_length": 31,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bbbeb679fa2c55a12f0cb345ad920c999c3f8fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "semenov-vladyslav/asn1-agda",
"max_stars_repo_path": "src/ASN1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 30,
"size": 108
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Group
open import lib.types.EilenbergMacLane1.Core
open import lib.groups.Homomorphism
open import lib.groups.LoopSpace
open import lib.two-semi-categories.FundamentalCategory
open import lib.two-semi-categories.Functor
open import lib.two-semi-categories.GroupToCategory
module lib.types.EilenbergMacLane1.Recursion {i} {G : Group i} where
private
module G = Group G
module EM₁Rec' {j} {C : Type j}
{{C-level : has-level 2 C}}
(embase* : C)
(emloop* : (g : G.El) → embase* == embase*)
(emloop-comp* : (g₁ g₂ : G.El) → emloop* (G.comp g₁ g₂) == emloop* g₁ ∙ emloop* g₂)
(emloop-coh* : (g₁ g₂ g₃ : G.El) →
emloop-comp* (G.comp g₁ g₂) g₃ ◃∙
ap (λ l → l ∙ emloop* g₃) (emloop-comp* g₁ g₂) ◃∙
∙-assoc (emloop* g₁) (emloop* g₂) (emloop* g₃) ◃∎
=ₛ
ap emloop* (G.assoc g₁ g₂ g₃) ◃∙
emloop-comp* g₁ (G.comp g₂ g₃) ◃∙
ap (λ l → emloop* g₁ ∙ l) (emloop-comp* g₂ g₃) ◃∎) where
private
P : EM₁ G → Type j
P _ = C
Q : embase' G == embase → Type j
Q p = embase* == embase* [ P ↓ p ]
emloop** : ∀ g → Q (emloop g)
emloop** g = ↓-cst-in (emloop* g)
emloop-comp** : ∀ g₁ g₂ →
emloop** (G.comp g₁ g₂) == emloop** g₁ ∙ᵈ emloop** g₂
[ Q ↓ emloop-comp g₁ g₂ ]
emloop-comp** g₁ g₂ =
↓-cst-in2 (emloop-comp* g₁ g₂) ▹
↓-cst-in-∙ (emloop g₁) (emloop g₂) (emloop* g₁) (emloop* g₂)
module _ (g₁ g₂ g₃ : G.El) where
s₀ : embase' G == embase
s₀ = emloop (G.comp (G.comp g₁ g₂) g₃)
s₁ : embase' G == embase
s₁ = emloop (G.comp g₁ g₂) ∙ emloop g₃
s₂ : embase' G == embase
s₂ = (emloop g₁ ∙ emloop g₂) ∙ emloop g₃
s₃ : embase' G == embase
s₃ = emloop g₁ ∙ (emloop g₂ ∙ emloop g₃)
s₄ : embase' G == embase
s₄ = emloop (G.comp g₁ (G.comp g₂ g₃))
s₅ : embase' G == embase
s₅ = emloop g₁ ∙ emloop (G.comp g₂ g₃)
e₀₁ : s₀ == s₁
e₀₁ = emloop-comp (G.comp g₁ g₂) g₃
e₁₂ : s₁ == s₂
e₁₂ = ap (_∙ emloop g₃) (emloop-comp g₁ g₂)
e₂₃ : s₂ == s₃
e₂₃ = ∙-assoc (emloop g₁) (emloop g₂) (emloop g₃)
e₀₄ : s₀ == s₄
e₀₄ = ap emloop (G.assoc g₁ g₂ g₃)
e₄₅ : s₄ == s₅
e₄₅ = emloop-comp g₁ (G.comp g₂ g₃)
e₅₃ : s₅ == s₃
e₅₃ = ap (emloop g₁ ∙_) (emloop-comp g₂ g₃)
φ : s₀ == s₃
φ = ↯ (e₀₁ ◃∙ e₁₂ ◃∙ e₂₃ ◃∎)
ψ : s₀ == s₃
ψ = ↯ (e₀₄ ◃∙ e₄₅ ◃∙ e₅₃ ◃∎)
φ=ψ : φ == ψ
φ=ψ = =ₛ-out (emloop-coh g₁ g₂ g₃)
s₀* : embase* == embase*
s₀* = emloop* (G.comp (G.comp g₁ g₂) g₃)
s₁* : embase* == embase*
s₁* = emloop* (G.comp g₁ g₂) ∙ emloop* g₃
s₂* : embase* == embase*
s₂* = (emloop* g₁ ∙ emloop* g₂) ∙ emloop* g₃
s₃* : embase* == embase*
s₃* = emloop* g₁ ∙ (emloop* g₂ ∙ emloop* g₃)
s₄* : embase* == embase*
s₄* = emloop* (G.comp g₁ (G.comp g₂ g₃))
s₅* : embase* == embase*
s₅* = emloop* g₁ ∙ emloop* (G.comp g₂ g₃)
e₀₁* : s₀* == s₁*
e₀₁* = emloop-comp* (G.comp g₁ g₂) g₃
e₁₂* : s₁* == s₂*
e₁₂* = ap (_∙ emloop* g₃) (emloop-comp* g₁ g₂)
e₂₃* : s₂* == s₃*
e₂₃* = ∙-assoc (emloop* g₁) (emloop* g₂) (emloop* g₃)
e₀₄* : s₀* == s₄*
e₀₄* = ap emloop* (G.assoc g₁ g₂ g₃)
e₄₅* : s₄* == s₅*
e₄₅* = emloop-comp* g₁ (G.comp g₂ g₃)
e₅₃* : s₅* == s₃*
e₅₃* = ap (emloop* g₁ ∙_) (emloop-comp* g₂ g₃)
φ* : s₀* == s₃*
φ* = ↯ (e₀₁* ◃∙ e₁₂* ◃∙ e₂₃* ◃∎)
ψ* : s₀* == s₃*
ψ* = ↯ (e₀₄* ◃∙ e₄₅* ◃∙ e₅₃* ◃∎)
φ*=ψ* : φ* == ψ*
φ*=ψ* = =ₛ-out (emloop-coh* g₁ g₂ g₃)
s₀** : Q s₀
s₀** = emloop** (G.comp (G.comp g₁ g₂) g₃)
s₁** : Q s₁
s₁** = emloop** (G.comp g₁ g₂) ∙ᵈ emloop** g₃
s₂** : Q s₂
s₂** = (emloop** g₁ ∙ᵈ emloop** g₂) ∙ᵈ emloop** g₃
s₃** : Q s₃
s₃** = emloop** g₁ ∙ᵈ (emloop** g₂ ∙ᵈ emloop** g₃)
s₄** : Q s₄
s₄** = emloop** (G.comp g₁ (G.comp g₂ g₃))
s₅** : Q s₅
s₅** = emloop** g₁ ∙ᵈ emloop** (G.comp g₂ g₃)
e₀₁** : s₀** == s₁** [ Q ↓ e₀₁ ]
e₀₁** = emloop-comp** (G.comp g₁ g₂) g₃
e₁₂** : s₁** == s₂** [ Q ↓ e₁₂ ]
e₁₂** = emloop-comp** g₁ g₂ ∙ᵈᵣ emloop** g₃
e₂₃** : s₂** == s₃** [ Q ↓ e₂₃ ]
e₂₃** = ∙ᵈ-assoc (emloop** g₁) (emloop** g₂) (emloop** g₃)
e₀₄** : s₀** == s₄** [ Q ↓ e₀₄ ]
e₀₄** = ↓-ap-in Q emloop (apd emloop** (G.assoc g₁ g₂ g₃))
e₄₅** : s₄** == s₅** [ Q ↓ e₄₅ ]
e₄₅** = emloop-comp** g₁ (G.comp g₂ g₃)
e₅₃** : s₅** == s₃** [ Q ↓ e₅₃ ]
e₅₃** = emloop** g₁ ∙ᵈₗ emloop-comp** g₂ g₃
φ** : s₀** == s₃** [ Q ↓ φ ]
φ** = e₀₁** ∙ᵈ e₁₂** ∙ᵈ e₂₃**
ψ** : s₀** == s₃** [ Q ↓ ψ ]
ψ** = e₀₄** ∙ᵈ e₄₅** ∙ᵈ e₅₃**
s₃-path₁ : ↓-cst-in {p = s₃} s₃* ==
emloop** g₁ ∙ᵈ ↓-cst-in (emloop* g₂ ∙ emloop* g₃)
s₃-path₁ = ↓-cst-in-∙ (emloop g₁) (emloop g₂ ∙ emloop g₃)
(emloop* g₁) (emloop* g₂ ∙ emloop* g₃)
s₃-path₂' : ↓-cst-in (emloop* g₂ ∙ emloop* g₃) ==
emloop** g₂ ∙ᵈ emloop** g₃
s₃-path₂' = ↓-cst-in-∙ (emloop g₂) (emloop g₃)
(emloop* g₂) (emloop* g₃)
s₃-path₂ : emloop** g₁ ∙ᵈ ↓-cst-in (emloop* g₂ ∙ emloop* g₃) == s₃**
s₃-path₂ = emloop** g₁ ∙ᵈₗ s₃-path₂'
s₃-path : ↓-cst-in s₃* == s₃**
s₃-path = s₃-path₁ ∙ s₃-path₂
*-to-**-path : (r : s₀ == s₃) → s₀* == s₃* → s₀** == s₃** [ Q ↓ r ]
*-to-**-path r q = ↓-cst-in2 {q = r} q ▹ s₃-path
φ-step : *-to-**-path φ φ* == φ**
φ-step =
↓-cst-in2 {q = φ} φ* ▹ s₃-path
=⟨ (↓-cst-in2-∙ {p₀₁ = e₀₁} {p₁₂ = e₁₂ ∙ e₂₃}
e₀₁* (e₁₂* ∙ e₂₃*)) ∙'ᵈᵣ s₃-path ⟩
(e₀₁*' ∙ᵈ ↓-cst-in2 {q = e₁₂ ∙ e₂₃} (e₁₂* ∙ e₂₃*)) ▹ s₃-path
=⟨ ap (λ y → (e₀₁*' ∙ᵈ y) ▹ s₃-path) $
↓-cst-in2-∙ {p₀₁ = e₁₂} {p₁₂ = e₂₃} e₁₂* e₂₃* ⟩
(e₀₁*' ∙ᵈ e₁₂*' ∙ᵈ e₂₃*') ▹ s₃-path
=⟨ ∙ᵈ-∙'ᵈ-assoc' e₀₁*' (e₁₂*' ∙ᵈ e₂₃*') s₃-path ⟩
e₀₁*' ∙ᵈ (e₁₂*' ∙ᵈ e₂₃*') ▹ s₃-path
=⟨ ap (e₀₁*' ∙ᵈ_) (∙ᵈ-∙'ᵈ-assoc' e₁₂*' e₂₃*' s₃-path) ⟩
e₀₁*' ∙ᵈ e₁₂*' ∙ᵈ e₂₃*' ▹ s₃-path
=⟨ ap (λ y → e₀₁*' ∙ᵈ e₁₂*' ∙ᵈ y) $
↓-cst-in-assoc {p₀ = emloop g₁} {p₁ = emloop g₂} {p₂ = emloop g₃}
(emloop* g₁) (emloop* g₂) (emloop* g₃) ⟩
e₀₁*' ∙ᵈ e₁₂*' ∙ᵈ f₂ ◃ f₃ ◃ e₂₃**
=⟨ ! (ap (e₀₁*' ∙ᵈ_) (▹∙ᵈ-∙ᵈ◃-assoc e₁₂*' f₂ (f₃ ◃ e₂₃**))) ⟩
e₀₁*' ∙ᵈ (e₁₂*' ▹ f₂) ∙ᵈ f₃ ◃ e₂₃**
=⟨ ap (λ y → e₀₁*' ∙ᵈ y ∙ᵈ f₃ ◃ e₂₃**) $
↓-cst-in2-whisker-right {p' = emloop g₃} {q' = emloop* g₃}
{p₀₁ = emloop-comp g₁ g₂}
(emloop-comp* g₁ g₂) ⟩
e₀₁*' ∙ᵈ (f₀ ◃ f₁) ∙ᵈ f₃ ◃ e₂₃**
=⟨ ap (e₀₁*' ∙ᵈ_) (∙ᵈ-assoc f₀ f₁ (f₃ ◃ e₂₃**)) ⟩
e₀₁*' ∙ᵈ f₀ ◃ f₁ ∙ᵈ f₃ ◃ e₂₃**
=⟨ ! (▹∙ᵈ-∙ᵈ◃-assoc e₀₁*' f₀ (f₁ ∙ᵈ f₃ ◃ e₂₃**)) ⟩
e₀₁** ∙ᵈ f₁ ∙ᵈ f₃ ◃ e₂₃**
=⟨ ! (ap (e₀₁** ∙ᵈ_) (▹∙ᵈ-∙ᵈ◃-assoc f₁ f₃ e₂₃**)) ⟩
e₀₁** ∙ᵈ (f₁ ▹ f₃) ∙ᵈ e₂₃**
=⟨ ! (ap (λ y → e₀₁** ∙ᵈ y ∙ᵈ e₂₃**) (∙ᵈᵣ-∙'ᵈ f₁' f₃' (emloop** g₃))) ⟩
φ** =∎
where
e₀₁*' : ↓-cst-in s₀* == ↓-cst-in s₁* [ Q ↓ e₀₁ ]
e₀₁*' = ↓-cst-in2 {q = e₀₁} e₀₁*
e₁₂*' : ↓-cst-in s₁* == ↓-cst-in s₂* [ Q ↓ e₁₂ ]
e₁₂*' = ↓-cst-in2 {q = e₁₂} e₁₂*
e₂₃*' : ↓-cst-in s₂* == ↓-cst-in s₃* [ Q ↓ e₂₃ ]
e₂₃*' = ↓-cst-in2 {q = e₂₃} e₂₃*
f₀ : ↓-cst-in (emloop* (G.comp g₁ g₂) ∙ emloop* g₃) ==
emloop** (G.comp g₁ g₂) ∙ᵈ emloop** g₃
f₀ = ↓-cst-in-∙ (emloop (G.comp g₁ g₂)) (emloop g₃)
(emloop* (G.comp g₁ g₂)) (emloop* g₃)
f₁' : emloop** (G.comp g₁ g₂) ==
↓-cst-in {p = emloop g₁ ∙ emloop g₂} (emloop* g₁ ∙ emloop* g₂)
[ Q ↓ emloop-comp' G g₁ g₂ ]
f₁' = ↓-cst-in2 {q = emloop-comp g₁ g₂} (emloop-comp* g₁ g₂)
f₁ : emloop** (G.comp g₁ g₂) ∙ᵈ emloop** g₃ ==
↓-cst-in {p = emloop g₁ ∙ emloop g₂} (emloop* g₁ ∙ emloop* g₂) ∙ᵈ emloop** g₃
[ Q ↓ ap (_∙ emloop' G g₃) (emloop-comp' G g₁ g₂) ]
f₁ = f₁' ∙ᵈᵣ emloop** g₃
f₂ : ↓-cst-in ((emloop* g₁ ∙ emloop* g₂) ∙ emloop* g₃) ==
↓-cst-in {p = emloop g₁ ∙ emloop g₂} (emloop* g₁ ∙ emloop* g₂) ∙ᵈ emloop** g₃
f₂ = ↓-cst-in-∙ (emloop g₁ ∙ emloop g₂) (emloop g₃)
(emloop* g₁ ∙ emloop* g₂) (emloop* g₃)
f₃' : ↓-cst-in {p = emloop g₁ ∙ emloop g₂} (emloop* g₁ ∙ emloop* g₂) ==
emloop** g₁ ∙ᵈ emloop** g₂
f₃' = ↓-cst-in-∙ (emloop g₁) (emloop g₂) (emloop* g₁) (emloop* g₂)
f₃ : ↓-cst-in {p = emloop g₁ ∙ emloop g₂} (emloop* g₁ ∙ emloop* g₂) ∙ᵈ emloop** g₃ ==
(emloop** g₁ ∙ᵈ emloop** g₂) ∙ᵈ emloop** g₃
f₃ = f₃' ∙ᵈᵣ emloop** g₃
ψ-step : *-to-**-path ψ ψ* == ψ**
ψ-step =
↓-cst-in2 {q = ψ} ψ* ▹ s₃-path
=⟨ ap (_▹ s₃-path) $
↓-cst-in2-∙ {p₀₁ = e₀₄} {p₁₂ = e₄₅ ∙ e₅₃}
e₀₄* (e₄₅* ∙ e₅₃*) ⟩
(e₀₄*' ∙ᵈ ↓-cst-in2 {q = e₄₅ ∙ e₅₃} (e₄₅* ∙ e₅₃*)) ▹ s₃-path
=⟨ ap (λ y → (e₀₄*' ∙ᵈ y) ▹ s₃-path) $
↓-cst-in2-∙ {p₀₁ = e₄₅} {p₁₂ = e₅₃} e₄₅* e₅₃* ⟩
(e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ e₅₃*') ▹ s₃-path
=⟨ ∙ᵈ-∙'ᵈ-assoc' e₀₄*' (e₄₅*' ∙ᵈ e₅₃*') s₃-path ⟩
e₀₄*' ∙ᵈ (e₄₅*' ∙ᵈ e₅₃*') ▹ s₃-path
=⟨ ap (e₀₄*' ∙ᵈ_) (∙ᵈ-∙'ᵈ-assoc' e₄₅*' e₅₃*' s₃-path) ⟩
e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ e₅₃*' ▹ s₃-path
=⟨ ap (λ y → e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ e₅₃*' ▹ y) (∙=∙' s₃-path₁ s₃-path₂) ⟩
e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ e₅₃*' ▹ (s₃-path₁ ∙' s₃-path₂)
=⟨ ! $ ap (λ y → e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ y) $
∙'ᵈ-assoc e₅₃*' s₃-path₁ s₃-path₂ ⟩
e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ (e₅₃*' ▹ s₃-path₁) ▹ s₃-path₂
=⟨ ap (λ y → e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ y ▹ s₃-path₂) $
↓-cst-in2-whisker-left {p = emloop g₁} {q = emloop* g₁}
{p₀₁' = emloop-comp g₂ g₃}
(emloop-comp* g₂ g₃) ⟩
e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ (f₀ ◃ f₁) ▹ s₃-path₂
=⟨ ap (λ y → e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ y) $
∙ᵈ-∙'ᵈ-assoc f₀ f₁ s₃-path₂ ⟩
e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ f₀ ◃ (f₁ ▹ s₃-path₂)
=⟨ ! $ ap (λ y → e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ f₀ ◃ y) $
∙ᵈₗ-∙'ᵈ f₁' s₃-path₂' (emloop** g₁) ⟩
e₀₄*' ∙ᵈ e₄₅*' ∙ᵈ f₀ ◃ e₅₃**
=⟨ ! (ap (e₀₄*' ∙ᵈ_) (▹∙ᵈ-∙ᵈ◃-assoc e₄₅*' f₀ e₅₃**)) ⟩
e₀₄*' ∙ᵈ e₄₅** ∙ᵈ e₅₃**
=⟨ ap (_∙ᵈ e₄₅** ∙ᵈ e₅₃**) $
↓-cst-in2-ap emloop emloop* (G.assoc g₁ g₂ g₃) ⟩
ψ** =∎
where
e₀₄*' : ↓-cst-in s₀* == ↓-cst-in s₄* [ Q ↓ e₀₄ ]
e₀₄*' = ↓-cst-in2 {q = e₀₄} e₀₄*
e₄₅*' : ↓-cst-in s₄* == ↓-cst-in s₅* [ Q ↓ e₄₅ ]
e₄₅*' = ↓-cst-in2 {q = e₄₅} e₄₅*
e₅₃*' : ↓-cst-in s₅* == ↓-cst-in s₃* [ Q ↓ e₅₃ ]
e₅₃*' = ↓-cst-in2 {q = e₅₃} e₅₃*
f₀ : ↓-cst-in (emloop* g₁ ∙ emloop* (G.comp g₂ g₃)) ==
emloop** g₁ ∙ᵈ ↓-cst-in (emloop* (G.comp g₂ g₃))
f₀ = ↓-cst-in-∙ (emloop g₁) (emloop' G (G.comp g₂ g₃))
(emloop* g₁) (emloop* (G.comp g₂ g₃))
f₁' : emloop** (G.comp g₂ g₃) == ↓-cst-in (emloop* g₂ ∙ emloop* g₃)
[ Q ↓ emloop-comp g₂ g₃ ]
f₁' = ↓-cst-in2 {q = emloop-comp g₂ g₃} (emloop-comp* g₂ g₃)
f₁ : emloop** g₁ ∙ᵈ emloop** (G.comp g₂ g₃) ==
emloop** g₁ ∙ᵈ ↓-cst-in (emloop* g₂ ∙ emloop* g₃)
[ Q ↓ ap (emloop g₁ ∙_) (emloop-comp g₂ g₃) ]
f₁ = emloop** g₁ ∙ᵈₗ f₁'
abstract
emloop-coh** : φ** == ψ** [ (λ q → s₀** == s₃** [ Q ↓ q ]) ↓ φ=ψ ]
emloop-coh** =
! φ-step ◃
ap (λ p* → *-to-**-path φ p*) φ*=ψ* ◃
apd (λ p → *-to-**-path p ψ*) φ=ψ ▹
ψ-step
module M = EM₁Elim {P = λ _ → C} {{λ _ → C-level}}
embase* emloop** emloop-comp** emloop-coh**
abstract
f : EM₁ G → C
f = M.f
embase-β : f embase ↦ embase*
embase-β = M.embase-β
{-# REWRITE embase-β #-}
emloop-β : (g : G.El) → ap f (emloop g) == emloop* g
emloop-β g = apd=cst-in (M.emloop-β g)
private
middle-fun : ∀ {i j} {A : Type i} {B : Type j}
{f : A → B} {a₀ a₁ a₂ : A}
(p₀₁ : a₀ == a₁) (p₁₂ : a₁ == a₂) (p₀₂ : a₀ == a₂)
(q₀₁ : f a₀ == f a₁) (q₁₂ : f a₁ == f a₂) (q₀₂ : f a₀ == f a₂)
(p-comp : p₀₂ == p₀₁ ∙ p₁₂)
→ apd f p₀₂ == ↓-cst-in {p = p₀₁} q₀₁ ∙ᵈ ↓-cst-in {p = p₁₂} q₁₂
[ (λ w → f a₀ == f a₂ [ (λ _ → B) ↓ w ]) ↓ p-comp ]
→ ap f p₀₂ == q₀₁ ∙ q₁₂
middle-fun {f = f} p₀₁ p₁₂ p₀₂ q₀₁ q₁₂ q₀₂ p-comp inner =
ap=↓-cst-out-apd f p₀₂ ∙
↓-cst-out2 inner ∙
↓-cst-out2 (! (↓-cst-in-∙ p₀₁ p₁₂ q₀₁ q₁₂)) ∙
↓-cst-β (p₀₁ ∙ p₁₂) (q₀₁ ∙ q₁₂)
emloop-comp-path-rewrite₁ : ∀ {i j} {A : Type i} {B : Type j}
{f : A → B} {a₀ a₁ a₂ : A}
(p₀₁ : a₀ == a₁) (p₁₂ : a₁ == a₂) (p₀₂ : a₀ == a₂)
(q₀₁ : f a₀ == f a₁) (q₁₂ : f a₁ == f a₂) (q₀₂ : f a₀ == f a₂)
(p-comp : p₀₂ == p₀₁ ∙ p₁₂)
(r₀₁ : apd f p₀₁ == ↓-cst-in q₀₁)
(r₁₂ : apd f p₁₂ == ↓-cst-in q₁₂)
→ ap (ap f) p-comp ∙
ap-∙ f p₀₁ p₁₂ ∙
ap2 _∙_ (apd=cst-in r₀₁) (apd=cst-in r₁₂)
==
middle-fun p₀₁ p₁₂ p₀₂ q₀₁ q₁₂ q₀₂ p-comp
(apd (apd f) p-comp ▹
apd-∙ f p₀₁ p₁₂ ∙
ap2 _∙ᵈ_ r₀₁ r₁₂)
emloop-comp-path-rewrite₁ idp idp .idp q₀₁ q₁₂ q₀₂ idp r₀₁ r₁₂ =
! (∙-unit-r (idp ∙' ap2 _∙_ r₀₁ r₁₂) ∙ ∙'-unit-l (ap2 _∙_ r₀₁ r₁₂))
emloop-comp-path-rewrite₂ : ∀ {i j} {A : Type i} {B : Type j}
{f : A → B} {a₀ a₁ a₂ : A}
(p₀₁ : a₀ == a₁) (p₁₂ : a₁ == a₂) (p₀₂ : a₀ == a₂)
(q₀₁ : f a₀ == f a₁) (q₁₂ : f a₁ == f a₂) (q₀₂ : f a₀ == f a₂)
(p-comp : p₀₂ == p₀₁ ∙ p₁₂) (q-comp : q₀₂ == q₀₁ ∙ q₁₂)
(r₀₁ : apd f p₀₁ == ↓-cst-in q₀₁)
(r₁₂ : apd f p₁₂ == ↓-cst-in q₁₂)
(r₀₂ : apd f p₀₂ == ↓-cst-in q₀₂)
→ middle-fun p₀₁ p₁₂ p₀₂ q₀₁ q₁₂ q₀₂ p-comp
(r₀₂ ◃
↓-cst-in2 {q = p-comp} q-comp ▹
↓-cst-in-∙ p₀₁ p₁₂ q₀₁ q₁₂)
==
apd=cst-in r₀₂ ∙
q-comp
emloop-comp-path-rewrite₂ idp idp .idp q₀₁ q₁₂ q₀₂ idp q-comp r₀₁ r₁₂ r₀₂ =
∙-unit-r (r₀₂ ∙ q-comp)
emloop-comp-path : (g₁ g₂ : G.El)
→ ap (ap f) (emloop-comp g₁ g₂) ◃∙
ap-∙ f (emloop g₁) (emloop g₂) ◃∙
ap2 _∙_ (emloop-β g₁) (emloop-β g₂) ◃∎
=ₛ
emloop-β (G.comp g₁ g₂) ◃∙
emloop-comp* g₁ g₂ ◃∎
emloop-comp-path g₁ g₂ = =ₛ-in $
ap (ap f) (emloop-comp g₁ g₂) ∙
ap-∙ f (emloop g₁) (emloop g₂) ∙
ap2 _∙_ (emloop-β g₁) (emloop-β g₂)
=⟨ emloop-comp-path-rewrite₁ p₀₁ p₁₂ p₀₂ q₀₁ q₁₂ q₀₂ p-comp r₀₁ r₁₂ ⟩
fun (apd (apd f) (emloop-comp g₁ g₂) ▹
apd-∙ f (emloop g₁) (emloop g₂) ∙
ap2 _∙ᵈ_ (M.emloop-β g₁) (M.emloop-β g₂))
=⟨ ap fun (M.emloop-comp-path g₁ g₂) ⟩
fun (M.emloop-β (G.comp g₁ g₂) ◃ emloop-comp** g₁ g₂)
=⟨ emloop-comp-path-rewrite₂ p₀₁ p₁₂ p₀₂ q₀₁ q₁₂ q₀₂ p-comp q-comp r₀₁ r₁₂ r₀₂ ⟩
emloop-β (G.comp g₁ g₂) ∙ emloop-comp* g₁ g₂ =∎
where
p₀₁ = emloop g₁
p₁₂ = emloop g₂
p₀₂ = emloop (G.comp g₁ g₂)
q₀₁ = emloop* g₁
q₁₂ = emloop* g₂
q₀₂ = emloop* (G.comp g₁ g₂)
r₀₁ = M.emloop-β g₁
r₁₂ = M.emloop-β g₂
r₀₂ = M.emloop-β (G.comp g₁ g₂)
p-comp = emloop-comp g₁ g₂
q-comp = emloop-comp* g₁ g₂
fun = middle-fun p₀₁ p₁₂ p₀₂ q₀₁ q₁₂ q₀₂ p-comp
module EM₁Rec {j} {C : Type j}
{{C-level : has-level 2 C}}
(F : TwoSemiFunctor (group-to-cat G) (2-type-fundamental-cat C {{C-level}})) where
private
module F = TwoSemiFunctor F
module M =
EM₁Rec' {C = C} {{C-level}}
(F.F₀ unit)
F.F₁
F.pres-comp
F.pres-comp-coh
abstract
f : EM₁ G → C
f = M.f
embase-β : f embase ↦ F.F₀ unit
embase-β = M.embase-β
{-# REWRITE embase-β #-}
emloop-β : (g : G.El) → ap f (emloop g) == F.F₁ g
emloop-β = M.emloop-β
emloop-comp-path : (g₁ g₂ : G.El)
→ ap (ap f) (emloop-comp g₁ g₂) ◃∙
ap-∙ f (emloop g₁) (emloop g₂) ◃∙
ap2 _∙_ (emloop-β g₁) (emloop-β g₂) ◃∎
=ₛ
emloop-β (G.comp g₁ g₂) ◃∙
F.pres-comp g₁ g₂ ◃∎
emloop-comp-path = M.emloop-comp-path
open EM₁Rec public using () renaming (f to EM₁-rec)
module EM₁Level₁Rec {j} {C : Type j}
{{C-level : has-level 1 C}}
(embase* : C)
(hom* : G →ᴳ (Ω^S-group 0 ⊙[ C , embase* ])) where
module M =
EM₁Rec' {{raise-level 1 C-level}}
embase* (GroupHom.f hom*) (GroupHom.pres-comp hom*)
(λ g₁ g₂ g₃ → =ₛ-in (prop-has-all-paths _ _))
abstract
f : EM₁ G → C
f = M.f
embase-β : f embase ↦ embase*
embase-β = M.embase-β
{-# REWRITE embase-β #-}
emloop-β : (g : G.El) → ap f (emloop g) == GroupHom.f hom* g
emloop-β = M.emloop-β
open EM₁Level₁Rec public using () renaming (f to EM₁-level₁-rec)
|
{
"alphanum_fraction": 0.4509678544,
"avg_line_length": 35.7650727651,
"ext": "agda",
"hexsha": "d29f9bb85b9db7babe4ff37ece8599936471176b",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/EilenbergMacLane1/Recursion.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/EilenbergMacLane1/Recursion.agda",
"max_line_length": 93,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/EilenbergMacLane1/Recursion.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": 8882,
"size": 17203
}
|
{-# OPTIONS --cubical-compatible #-}
postulate w/e : Set
data _==_ {A : Set} : A → A → Set where
idp : {a : A} → a == a
data Square {A : Set} {a : A} : {b c d : A} (p : a == b) (q : c == d) (r : a == c) (s : b == d) → Set where
ids : Square {a = a} idp idp idp idp
J1 : {A : Set} {a : A} {p : a == a} → Square p idp idp idp → Set
J1 ids = w/e
J2 : {A : Set} {a : A} {p : a == a} → Square idp p idp idp → Set
J2 ids = w/e
J3 : {A : Set} {a : A} {p : a == a} → Square idp idp p idp → Set
J3 ids = w/e
J4 : {A : Set} {a : A} {p : a == a} → Square idp idp idp p → Set
J4 ids = w/e
|
{
"alphanum_fraction": 0.4693877551,
"avg_line_length": 26.7272727273,
"ext": "agda",
"hexsha": "741eda6c55735a7ec9ee79d8cfad6db7a59fd4a1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue3034.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue3034.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue3034.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 272,
"size": 588
}
|
{-# OPTIONS --cubical --no-import-sorts #-}
module SpacesFirstAttempt where
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
private
variable
ℓ ℓ' ℓ'' : Level
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Relation.Nullary.Base -- ¬_
open import Cubical.Relation.Binary.Base -- Rel
open import Data.Nat.Base using (ℕ) renaming (_≤_ to _≤ₙ_)
record PoorField : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
Carrier : Type ℓ
-- comm ring
0f : Carrier
1f : Carrier
_+_ : Carrier → Carrier → Carrier
_·_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
-- lattice
_<_ : Rel Carrier Carrier ℓ' -- stronger than _#_ and _≤_
min : Carrier → Carrier → Carrier
max : Carrier → Carrier → Carrier
-- other
_#_ : Rel Carrier Carrier ℓ'
_≤_ : Rel Carrier Carrier ℓ'
∣_∣ᶠ' : Carrier → Σ[ x ∈ Carrier ] 0f ≤ x -- absolute value
_⁻¹ᶠ : (x : Carrier) → {{x # 0f}} → Carrier
conj : Carrier → Carrier -- complex conjugation (only for ℂ; this is the identity function on ℝ)
-- sqrt -- need that on ℝ₀⁺ to define a norm from an inner product
∣_∣ᶠ : Carrier → Carrier -- NOTE: well, this should be "into" ℝ₀⁺
∣ x ∣ᶠ = fst (∣ x ∣ᶠ')
_-_ : Carrier → Carrier → Carrier
x - y = x + (- y)
infix 9 _⁻¹ᶠ
infix 8 -_
infixl 7 _·_
infixl 6 _+_
infixl 6 _-_
infixl 4 _#_
infixl 4 _<_
infixl 4 _≤_
-- different "variants" of reals
-- this might be a "basis" for an instance-based, typeclass-like coercion "mechanism" between different "numbers"
--
-- NOTE: the intuition with "variants" might align with "subset" where different properties are available
-- from a "subset" in this manner, we want that it is "easy" to
-- - make use of properties from the "full" set
-- - this might be realized with an abuse of Agda's record-update syntax
-- - the "core" of such a mechanism is to have a proper naming-scheme (because record-update basically just matches names)
-- - "spontaneously enrich" some current context with a subset proof
-- and then make use of the subset lemmas on elements of the "whole" set
{- IDEA: for the organization of these definitions
we might have some "ur"-reals
these are "the" "numbers"
or even better: just "ur-numbers" to support functions from 𝕂 into ℝ₀⁺
being part of some concrete number type is attached via a hidden instance-proof property
this should be similar to a typeclass mechanism in Coq or Isabelle/HOL
TODO: maybe, when re-reading their papers, it becomes apparent that this is how it's done in Hölzl 2013 and the Coq-Port of their work
because I remember them writing something like "this work makes heavy use of typeclasses"
so we explicitly quantify over "numbers" and implicitly quantify over "properties"
the available properties must have the same name in each different number type
that way we can make use of Agda's record update syntax
(well, there can be exceptions since it is possible to rename stuff on the fly, but it'd be more convenient if the names already match)
we might decide NOT (!) to overload operations such as _<_ and similar
because having both overloaded - operations and numbers - is likely to generate resolving issues
AND we must be very aware when a type depends on a hidden argument
because in that case, we need to add an explicit coercion to our result
so we just accept that "inconvenience" and embrace a style where these "important" arguments/instances are treated differently
especially they should not be used anonymously
and this might also embrace an anonymous-module style to create a scope that is shared by both: the declaration and the definition of something
This might look ugly at first but that's okay if it works out
-}
record IsℝField (PF : PoorField {ℓ} {ℓ'}) : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
open PoorField PF
record Isℝ₀⁺Field (PF : PoorField {ℓ} {ℓ'}) : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
open PoorField PF
field
isℝField : IsℝField PF
isNonnegative : ∀ x → 0f ≤ x
open IsℝField isℝField public
record Isℝ⁺Field (PF : PoorField {ℓ} {ℓ'}) : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
open PoorField PF
field
isℝField : IsℝField PF
-- NOTE: 0f is not an element of ℝ⁺, so we do not have a neutral element for addition
-- so the following holds in a different way
-- isPositive : ∀ x → 0f < x
open IsℝField isℝField public
record Is𝕂Field (PF : PoorField {ℓ} {ℓ'}) : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
open PoorField PF
record ℝField : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
poorField : PoorField {ℓ} {ℓ'}
isℝField : IsℝField poorField
open PoorField poorField public
open IsℝField isℝField public
record ℝ₀⁺Field : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
poorField : PoorField {ℓ} {ℓ'}
isℝ₀⁺Field : Isℝ₀⁺Field poorField
open PoorField poorField public
open Isℝ₀⁺Field isℝ₀⁺Field public
record ℝ⁺Field : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
poorField : PoorField {ℓ} {ℓ'}
isℝ⁺Field : Isℝ⁺Field poorField
open PoorField poorField public
open Isℝ⁺Field isℝ⁺Field public
record 𝕂Field : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
poorField : PoorField {ℓ} {ℓ'}
is𝕂Field : Is𝕂Field poorField
open PoorField poorField public
open Is𝕂Field is𝕂Field public
postulate
ℝℓ ℝℓ' : Level
ℝF : ℝField {ℝℓ} {ℝℓ'} -- reals
ℝ⁺F : ℝ⁺Field {ℝℓ} {ℝℓ'} -- positive reals without 0
ℝ₀⁺F : ℝ₀⁺Field {ℝℓ} {ℝℓ'} -- positive reals with 0
-- we also often use ℂ in the application
-- we might often use ℝ in places where ℚ would suffice
-- we use 𝕂 for "ℝ or ℂ"
-- and we use ℕ, Fin k, ℤ of course
-- then, there is (exterior) algebra
-- NOTE: one could bring different "variants" of the reals into scope like so
-- but we are likely to omit populating the scope with overlapping reals as much as possible
open ℝField ℝF using () renaming
( Carrier to ℝ
)
open ℝ₀⁺Field ℝ₀⁺F using () renaming
( Carrier to ℝ₀⁺
; 0f to 0f₀⁺
)
open ℝ⁺Field ℝ⁺F using () renaming
( Carrier to ℝ⁺
)
---------- application -------------
{-
-- ∅ : ⊥ →
-- topology on a set X
record IsTopology
(X : Type ℓ)
(isOpen : X → Type ℓ')
(_∪_ : X → X → X)
(_∩_ : X → X → X)
: Type _ where
field
record TopologicalSpace : Type _ where
-}
record IsMetric {ℓ} {X : Type ℓ} (d : X → X → ℝ₀⁺) : Type (ℓ-max ℓ (ℓ-max ℝℓ ℝℓ')) where
open ℝ₀⁺Field ℝ₀⁺F
field
-- identity of indiscernibles
isPositiveOnNonzero : ∀ x y → 0f ≡ d x y → x ≡ y
isPositiveOnNonzero-back : ∀ x y → x ≡ y → 0f ≡ d x y
isSym : ∀ x y → d x y ≡ d y x
-- subadditivity / triangle inequality
isTriangleIneq : ∀ x y z → d x y ≤ d x z + d z y
record MetricSpace : Type (ℓ-max (ℓ-suc ℓ) (ℓ-max ℝℓ' ℝℓ)) where
field
Carrier : Type ℓ
d : Carrier → Carrier → ℝ₀⁺
isMetric : IsMetric d
open IsMetric isMetric public
𝕂ℓ = ℝℓ
𝕂ℓ' = ℝℓ'
module _ (𝕂F : 𝕂Field {𝕂ℓ} {𝕂ℓ'}) where
open 𝕂Field 𝕂F renaming (Carrier to 𝕂; 0f to 0ₛ; _+_ to _+ₛ_)
postulate
∣_∣ᵣ : 𝕂 → ℝ₀⁺
record IsVectorAddition {X : Type ℓ} (0v : X) (_+_ : X → X → X) (-_ : X → X) : Type (ℓ-max ℓ (ℓ-max 𝕂ℓ 𝕂ℓ')) where
field
isCommutative : ∀ x y → x + y ≡ y + x
isAssociative : ∀ x y z → (x + y) + z ≡ x + (y + z)
rid : ∀ x → x + 0v ≡ x
rid-back : ∀ x y → x + y ≡ x → y ≡ 0v
invr : ∀ x → x + (- x) ≡ 0v
record IsScalarMultiplication {X : Type ℓ} (0v : X) (_+_ : X → X → X) (-_ : X → X) (_·ₛ_ : 𝕂 → X → X) : Type (ℓ-max ℓ (ℓ-max 𝕂ℓ 𝕂ℓ')) where
field
·ₛ-dist-+ : ∀ α x y → α ·ₛ (x + y) ≡ (α ·ₛ x) + (α ·ₛ y)
0-left-nullifies : ∀ x → 0ₛ ·ₛ x ≡ 0v
+ₛ-dist-· : ∀ α β x → (α +ₛ β) ·ₛ x ≡ (α ·ₛ x) + (β ·ₛ x)
record VectorSpace : Type (ℓ-max (ℓ-suc ℓ) (ℓ-max 𝕂ℓ 𝕂ℓ')) where
field
Carrier : Type ℓ
0v : Carrier
_+_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
_·ₛ_ : 𝕂 → Carrier → Carrier
isVectorAddition : IsVectorAddition 0v _+_ (-_)
isScalarMultiplication : IsScalarMultiplication 0v _+_ -_ _·ₛ_
open IsVectorAddition isVectorAddition public
open IsScalarMultiplication isScalarMultiplication public
module _ (VS : VectorSpace {ℓ}) where
open VectorSpace VS using (_+_; _·ₛ_) renaming (Carrier to V; 0v to 0ᵥ)
open ℝ₀⁺Field ℝ₀⁺F using () renaming (0f to 0ᵣ; _≤_ to _≤ᵣ_; _+_ to _+ᵣ_; _·_ to _·ᵣ_)
record IsNorm (‖_‖ᵥ : V → ℝ₀⁺) : Type (ℓ-max ℓ (ℓ-max 𝕂ℓ 𝕂ℓ')) where
field
idToIndisc : ∀ x → ‖ x ‖ᵥ ≡ 0ᵣ → x ≡ 0ᵥ
idToIndisc-back : ∀ x → x ≡ 0ᵥ → ‖ x ‖ᵥ ≡ 0ᵣ
triangleIneq : ∀ x y → ‖ x + y ‖ᵥ ≤ᵣ ‖ x ‖ᵥ +ᵣ ‖ y ‖ᵥ
absLinear : ∀ α x → ‖ α ·ₛ x ‖ᵥ ≡ ∣ α ∣ᵣ ·ᵣ ‖ x ‖ᵥ
record NormedVectorSpace : Type (ℓ-max (ℓ-suc ℓ) (ℓ-max 𝕂ℓ 𝕂ℓ')) where
field
VS : VectorSpace {ℓ}
open VectorSpace VS public
field
‖_‖ᵥ : Carrier → ℝ₀⁺
isNorm : IsNorm VS ‖_‖ᵥ
open IsNorm isNorm public
-- cauchy w.r.t. a distance function
-- NOTE: Booij defines cauchy w.r.t. the rationals ℚ
IsCauchy : {X : Type ℓ} (d : X → X → ℝ₀⁺) → IsMetric d → (x : ℕ → X) → Type (ℓ-max ℝℓ ℝℓ')
IsCauchy d isMetric x =
let open ℝ₀⁺Field ℝ₀⁺F using () renaming (0f to 0ᵣ; _<_ to _<ᵣ_; _≤_ to _≤ᵣ_; _+_ to _+ᵣ_; _·_ to _·ᵣ_)
in ∀(ε : ℝ₀⁺) → 0ᵣ <ᵣ ε → Σ[ I ∈ ℕ ] ∀ m n → I ≤ₙ m → I ≤ₙ n → d (x m) (x n) <ᵣ ε
-- limit w.r.t. a metric
IsLimit : {X : Type ℓ} {d : X → X → ℝ₀⁺} → (isMetric : IsMetric d) → (x : ℕ → X) → X → Type (ℓ-max ℝℓ ℝℓ')
IsLimit {d = d} isMetric x a =
let open ℝ₀⁺Field ℝ₀⁺F using () renaming (0f to 0ᵣ; _<_ to _<ᵣ_; _≤_ to _≤ᵣ_; _+_ to _+ᵣ_; _·_ to _·ᵣ_)
in ∀(ε : ℝ₀⁺) → 0ᵣ <ᵣ ε → Σ[ I ∈ ℕ ] ∀ m → I ≤ₙ m → d (x m) a <ᵣ ε
IsCauchyConvergent : {X : Type ℓ} (d : X → X → ℝ₀⁺) → (isMetric : IsMetric d) → (x : ℕ → X) → IsCauchy d isMetric x → Type (ℓ-max ℓ (ℓ-max ℝℓ ℝℓ'))
IsCauchyConvergent {X = X} d isMetric x isCauchy = Σ[ a ∈ X ] IsLimit isMetric x a
record CompleteMetricSpace : Type (ℓ-max (ℓ-suc ℓ) (ℓ-max ℝℓ' ℝℓ)) where
field
MS : MetricSpace {ℓ}
open MetricSpace MS public
field
isCauchyComplete : ∀ x → (isCauchy : IsCauchy d isMetric x) → Σ[ a ∈ Carrier ] IsLimit isMetric x a
module Lemma-1 (𝕂F : 𝕂Field {𝕂ℓ} {𝕂ℓ'}) (NVS : NormedVectorSpace 𝕂F {ℓ}) where
open NormedVectorSpace NVS renaming (Carrier to V)
open ℝ₀⁺Field ℝ₀⁺F using () renaming (_≤_ to _≤ᵣ_; _+_ to _+ᵣ_)
d : V → V → ℝ₀⁺
d x y = ‖ x + (- y) ‖ᵥ
lemma-1 : IsMetric d
lemma-1 = record
{ isPositiveOnNonzero = {!!}
; isPositiveOnNonzero-back = {!!}
; isSym = {! λ x y → ?!}
; isTriangleIneq = {!!}
}
IsNormMetric : (V → V → ℝ₀⁺) → Type (ℓ-max ℓ ℝℓ)
IsNormMetric d' = ∀ x y → d' x y ≡ d x y
module _ (𝕂F : 𝕂Field {𝕂ℓ} {𝕂ℓ'}) where
record CompleteNormedVectorSpace : Type (ℓ-max (ℓ-suc ℓ) (ℓ-max 𝕂ℓ' 𝕂ℓ)) where
field
NVS : NormedVectorSpace 𝕂F {ℓ}
open NormedVectorSpace NVS public
d : Carrier → Carrier → ℝ₀⁺
d x y = ‖ x + (- y) ‖ᵥ
isMetric : IsMetric d
isMetric = Lemma-1.lemma-1 𝕂F NVS
field
isCauchyComplete : ∀ x → (isCauchy : IsCauchy d isMetric x) → Σ[ a ∈ Carrier ] IsLimit isMetric x a
BanachSpace = CompleteNormedVectorSpace
module _ (𝕂F : 𝕂Field {𝕂ℓ} {𝕂ℓ'}) (VS : VectorSpace 𝕂F {ℓ}) where
open 𝕂Field 𝕂F using (conj) renaming (Carrier to 𝕂; _·_ to _·ₖ_; _+_ to _+ₖ_)
open VectorSpace VS renaming (Carrier to V)
record IsInnerProduct (‹_,_›ᵥ : V → V → 𝕂) : Type (ℓ-max ℓ (ℓ-max 𝕂ℓ' 𝕂ℓ)) where
field
-- pos-definite : ∀ x → x ≠ 0v → ‹ x , x › ∈ ℝ⁺ -- TODO
conj-sym : ∀ x y → ‹ x , y ›ᵥ ≡ conj (‹ y , x ›ᵥ)
lin₁ : ∀ α x y → ‹ α ·ₛ x , y ›ᵥ ≡ α ·ₖ ‹ x , y ›ᵥ
+distrib₁ : ∀ x y z → ‹ x + y , z ›ᵥ ≡ ‹ x , z ›ᵥ +ₖ ‹ y , z ›ᵥ
-- If the positive-definite condition is replaced by merely requiring that ⟨ x , x ⟩ ≥ 0 for all x,
-- then one obtains the definition of positive semi-definite Hermitian form.
module _ (𝕂F : 𝕂Field {𝕂ℓ} {𝕂ℓ'}) where
open 𝕂Field 𝕂F using (conj) renaming (Carrier to 𝕂; _·_ to _·ₖ_; _+_ to _+ₖ_)
record InnerProductSpace : Type (ℓ-max (ℓ-suc ℓ) (ℓ-max 𝕂ℓ' 𝕂ℓ)) where
field
VS : VectorSpace 𝕂F {ℓ}
open VectorSpace VS public
field
‹_,_›ᵥ : Carrier → Carrier → 𝕂
isInnerProduct : IsInnerProduct 𝕂F VS ‹_,_›ᵥ
open IsInnerProduct isInnerProduct public
-- ‖_‖ᵥ : Carrier → ℝ₀⁺
-- ‖ x ‖ᵥ = sqrt (‹ x , x ›ᵥ)
-- isNorm : IsNorm VS ‖_‖ᵥ
-- isNorm = ?
-- d : Carrier → Carrier → ℝ₀⁺
-- d x y = ‖ x + (- y) ‖ᵥ
-- isMetric : IsMetric d
-- isMetric = Lemma-1.lemma-1 𝕂F NVS
-- NOTE: there are a lot of properties for InnerProductSpaces: https://en.wikipedia.org/wiki/Inner_product_space#Norm
record HilbertSpace : Type (ℓ-max (ℓ-suc ℓ) (ℓ-max 𝕂ℓ' 𝕂ℓ)) where
field
VS : VectorSpace 𝕂F {ℓ}
open VectorSpace VS public
field
‹_,_›ᵥ : Carrier → Carrier → 𝕂
isInnerProduct : IsInnerProduct 𝕂F VS ‹_,_›ᵥ
open IsInnerProduct isInnerProduct public
-- ‖_‖ᵥ : Carrier → ℝ₀⁺
-- ‖ x ‖ᵥ = sqrt (‹ x , x ›ᵥ)
-- isNorm : IsNorm VS ‖_‖ᵥ
-- isNorm = ?
-- d : Carrier → Carrier → ℝ₀⁺
-- d x y = ‖ x + (- y) ‖ᵥ
-- isMetric : IsMetric d
-- isMetric = Lemma-1.lemma-1 𝕂F NVS
-- field
-- isCauchyComplete : ∀ x → (isCauchy : IsCauchy d isMetric x) → Σ[ a ∈ Carrier ] IsLimit isMetric x a
-- NOTE:
-- we observe that stronger structure "replaces" weaker structure in the sequence
-- InnerProductSpace < NormedVectorSpace < MetricSpace
-- when we add Cauchy completeness, we get
-- HilbertSpace < BanachSpace < CompleteMetricSpace
-- next up: EuclideanSpace ?
-- see "Hölzl, Immler, Huffman 2013 - Type Classes and Filters for Mathematical Analysis in Isabelle/HOL"
-- here, they start with topological spaces, where we start with the real numbers
-- what about subspaces? How to formulate these?
{-
observed issues
- subspaces
- inclusions/coercions between different variants of "numbers"
- conj
- sqrt
- topological spaces (do we need them after all?)
- can we follow "Hölzl 2013" ?
- size issues:
the "amount" of ℓs is "high" and we are not ℓ-suc-ing to 𝕂ℓ and 𝕂ℓ'
but we are ℓ-suc-ing to ℓ in the definition of PoorField
so PoorField cannot be in ℓ-zero
- is IsCauchy defined for ε ∈ ℚ or for ε ∈ ℝ ?
in `Cubical.Data.Fin.Base` is written
Finite types.
Currently it is most convenient to define these as a subtype of the
natural numbers, because indexed inductive definitions don't behave
well with cubical Agda. This definition also has some more general
attractive properties, of course, such as easy conversion back to ℕ.
and then they state
Fin : ℕ → Type₀
Fin n = Σ[ k ∈ ℕ ] k < n
so Σ[ x ∈ 𝕏 ] (P x) kind of falls under what is called a "subtype"
next-up
- infimum and supremum on posets (and sub-posets / sub-lattices ?)
- we do only really need these on ℝ
- these do not necessarily exist in the subspace that we regard
- morphisms on these spaces
- (potentially) unbounded linear operators
- algebraic and continuous dual spaces
- Formulation of Riesz representation Theorem on Hilbert spaces
-}
|
{
"alphanum_fraction": 0.6257016055,
"avg_line_length": 35.4675925926,
"ext": "agda",
"hexsha": "c2c17920c0e0d83d7fd9885726d298b34192a27d",
"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": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "test/SpacesFirstAttempt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"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": "mchristianl/synthetic-reals",
"max_issues_repo_path": "test/SpacesFirstAttempt.agda",
"max_line_length": 147,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "test/SpacesFirstAttempt.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 5832,
"size": 15322
}
|
open import Relation.Binary.Core
module Order.Total {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Data.Sum
refl≤ : {x : A} → x ≤ x
refl≤ {x}
with tot≤ x x
... | inj₁ x≤x = x≤x
... | inj₂ x≤x = x≤x
|
{
"alphanum_fraction": 0.4716981132,
"avg_line_length": 18.9285714286,
"ext": "agda",
"hexsha": "37b39eb2f05ffe9992c0aae3948d6093ede23a3b",
"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/Order/Total.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/Order/Total.agda",
"max_line_length": 43,
"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/Order/Total.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": 105,
"size": 265
}
|
module hott.topology.loopspace.theorems where
open import hott.core
open import hott.core.theorems
open import hott.topology.loopspace.eckmann-hilton public
|
{
"alphanum_fraction": 0.8427672956,
"avg_line_length": 22.7142857143,
"ext": "agda",
"hexsha": "14339e62ef8dca060353492c887490f96dc3495f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "piyush-kurur/hott",
"max_forks_repo_path": "agda/hott/topology/loopspace/theorems.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "piyush-kurur/hott",
"max_issues_repo_path": "agda/hott/topology/loopspace/theorems.agda",
"max_line_length": 57,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "piyush-kurur/hott",
"max_stars_repo_path": "agda/hott/topology/loopspace/theorems.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 40,
"size": 159
}
|
module Data.Int.Literal where
open import Data.Nat using (ℕ)
open import Level using (suc)
record Negative {a} (A : Set a) : Set (suc a) where
field
Constraint : ℕ → Set a
fromNeg : (n : ℕ) → ⦃ Constraint n ⦄ → A
open Negative {{...}} public using (fromNeg)
{-# BUILTIN FROMNEG fromNeg #-}
|
{
"alphanum_fraction": 0.6435643564,
"avg_line_length": 23.3076923077,
"ext": "agda",
"hexsha": "46855c354ca0a6e488a38d04f30bf520a6d99c53",
"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/Data/Int/Literal.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/Data/Int/Literal.agda",
"max_line_length": 51,
"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/Data/Int/Literal.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": 96,
"size": 303
}
|
{-# OPTIONS --prop --cubical-compatible #-}
data _≡_ {A : Set} (x : A) : A → Prop where
refl : x ≡ x
|
{
"alphanum_fraction": 0.5384615385,
"avg_line_length": 20.8,
"ext": "agda",
"hexsha": "be754ead3a62d1b6ef271ce8c489050c5b42481c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue3433.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue3433.agda",
"max_line_length": 43,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue3433.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 39,
"size": 104
}
|
------------------------------------------------------------------------
-- A type for values that should be erased at run-time
------------------------------------------------------------------------
-- This module contains some basic definitions with few dependencies
-- (in particular, not Function-universe) that do not rely on
-- equality. See Erased and other modules under Erased for more
-- definitions. The definitions below are reexported from Erased.
{-# OPTIONS --without-K --safe #-}
module Erased.Basics where
open import Prelude
private
variable
a p q : Level
-- Erased A is like A, but the values are (supposed to be) erased at
-- run-time.
record Erased (@0 A : Type a) : Type a where
constructor [_]
field
@0 erased : A
open Erased public
-- A variant of [_] that does not take an erased argument.
[_]→ : {@0 A : Type a} → A → Erased A
[ x ]→ = [ x ]
-- A variant of [_]→.
[_∣_]→ : (@0 A : Type a) → A → Erased A
[_∣_]→ _ = [_]→
-- Erased preserves dependent functions.
map :
{@0 A : Type a} {@0 P : A → Type p} →
@0 ((x : A) → P x) → (x : Erased A) → Erased (P (erased x))
map f [ x ] = [ f x ]
-- A binary variant of map.
zip :
{@0 A : Type a} {@0 P : A → Type p} {@0 Q : {x : A} → P x → Type q} →
@0 ((x : A) (p : P x) → Q p) →
(([ x ]) : Erased A) (([ p ]) : Erased (P x)) → Erased (Q p)
zip f [ x ] [ p ] = [ f x p ]
|
{
"alphanum_fraction": 0.5231884058,
"avg_line_length": 25.5555555556,
"ext": "agda",
"hexsha": "a63107dc404cc1624f5b6aa11c018b4de65978fd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Erased/Basics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Erased/Basics.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Erased/Basics.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 417,
"size": 1380
}
|
{-# OPTIONS --without-K #-}
{-
Imports everything that is not imported by something else.
This is not supposed to be used anywhere, this is just a simple way to
do `make all'
This file is intentionally named index.agda so that
Agda will generate index.html.
-}
module index where
-- import Spaces.IntervalProps
-- import Algebra.F2NotCommutative
import homotopy.LoopSpaceCircle
import homotopy.HopfJunior
import homotopy.Hopf
-- cohomology
import cohomology.EMModel
import cohomology.Torus
import homotopy.SpaceFromGroups
import homotopy.CoverClassification
import homotopy.AnyUniversalCoverIsPathSet
import homotopy.PathSetIsInital
-- import Spaces.LoopSpaceDecidableWedgeCircles
-- import Homotopy.PullbackIsPullback
-- import Homotopy.PushoutIsPushout
-- import Homotopy.Truncation
-- import Sets.QuotientUP
import homotopy.PinSn
-- import Homotopy.VanKampen
import cw.CW
import cw.Sphere
import cw.Degree
|
{
"alphanum_fraction": 0.8090614887,
"avg_line_length": 18.54,
"ext": "agda",
"hexsha": "683e37c1430e1dfb8d26d9c8cd20b5b696918cff",
"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/index.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/index.agda",
"max_line_length": 70,
"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/index.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 248,
"size": 927
}
|
module Groups.Symm.S3 where
open import Equality
------------------------------------------------------------------------
-- definitions
bin-op : ∀ {a} (A : Set a) → Set a
bin-op A = A → A → A
------------------------------------------------------------------------
-- internal stuffs
private
record S₃ {a} (A : Set a) : Set a where
constructor ⟨_,_,_⟩-⟨_,_,_⟩-⟨_,_,_⟩
infixl 5 _×_
field
x y {e} : A
_×_ : bin-op A
assoc : ∀ a b c → a × b × c ≡ a × (b × c)
idₗ : ∀ n → n × e ≡ n
idᵣ : ∀ n → e × n ≡ n
law-xxx=e : x × x × x ≡ e
law-yy=e : y × y ≡ e
law-yx=xxy : y × x ≡ x × x × y
law-xyx=y : Set a
law-xyx=y = x × y × x ≡ y
xyx=y : law-xyx=y
xyx=y
rewrite assoc x y x
| law-yx=xxy
| sym (assoc x (x × x) y)
| sym (assoc x x x)
| law-xxx=e
= idᵣ y
------------------------------------------------------------------------
-- public aliases
s3-property-1 : ∀ {a} (A : S₃ (Set a)) → S₃.law-xyx=y A
s3-property-1 = S₃.xyx=y
|
{
"alphanum_fraction": 0.3518518519,
"avg_line_length": 23.4782608696,
"ext": "agda",
"hexsha": "618d09ccc57448b5ee9b03a921577a9d6b44a549",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ice1k/Theorems",
"max_forks_repo_path": "src/Groups/Symm/S3.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ice1k/Theorems",
"max_issues_repo_path": "src/Groups/Symm/S3.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ice1k/Theorems",
"max_stars_repo_path": "src/Groups/Symm/S3.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z",
"num_tokens": 368,
"size": 1080
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Order-theoretic lattices
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Lattice where
open import Algebra.FunctionProperties
open import Data.Product using (_×_; _,_)
open import Function using (flip)
open import Level using (suc; _⊔_)
open import Relation.Binary
------------------------------------------------------------------------
-- Relationships between orders and operators
open import Relation.Binary public using (Maximum; Minimum)
Supremum : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Op₂ A → Set _
Supremum _≤_ _∨_ =
∀ x y → x ≤ (x ∨ y) × y ≤ (x ∨ y) × ∀ z → x ≤ z → y ≤ z → (x ∨ y) ≤ z
Infimum : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Op₂ A → Set _
Infimum _≤_ = Supremum (flip _≤_)
Exponential : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Op₂ A → Op₂ A → Set _
Exponential _≤_ _∧_ _⇨_ =
∀ w x y → ((w ∧ x) ≤ y → w ≤ (x ⇨ y)) × (w ≤ (x ⇨ y) → (w ∧ x) ≤ y)
------------------------------------------------------------------------
-- Join semilattices
record IsJoinSemilattice {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
(_∨_ : Op₂ A) -- The join operation.
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
field
isPartialOrder : IsPartialOrder _≈_ _≤_
supremum : Supremum _≤_ _∨_
x≤x∨y : ∀ x y → x ≤ (x ∨ y)
x≤x∨y x y = let pf , _ , _ = supremum x y in pf
y≤x∨y : ∀ x y → y ≤ (x ∨ y)
y≤x∨y x y = let _ , pf , _ = supremum x y in pf
∨-least : ∀ {x y z} → x ≤ z → y ≤ z → (x ∨ y) ≤ z
∨-least {x} {y} {z} = let _ , _ , pf = supremum x y in pf z
open IsPartialOrder isPartialOrder public
record JoinSemilattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _≤_
infixr 6 _∨_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_≤_ : Rel Carrier ℓ₂ -- The partial order.
_∨_ : Op₂ Carrier -- The join operation.
isJoinSemilattice : IsJoinSemilattice _≈_ _≤_ _∨_
open IsJoinSemilattice isJoinSemilattice public
poset : Poset c ℓ₁ ℓ₂
poset = record { isPartialOrder = isPartialOrder }
open Poset poset public using (preorder)
record IsBoundedJoinSemilattice {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
(_∨_ : Op₂ A) -- The join operation.
(⊥ : A) -- The minimum.
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
field
isJoinSemilattice : IsJoinSemilattice _≈_ _≤_ _∨_
minimum : Minimum _≤_ ⊥
open IsJoinSemilattice isJoinSemilattice public
record BoundedJoinSemilattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _≤_
infixr 6 _∨_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_≤_ : Rel Carrier ℓ₂ -- The partial order.
_∨_ : Op₂ Carrier -- The join operation.
⊥ : Carrier -- The minimum.
isBoundedJoinSemilattice : IsBoundedJoinSemilattice _≈_ _≤_ _∨_ ⊥
open IsBoundedJoinSemilattice isBoundedJoinSemilattice public
joinSemilattice : JoinSemilattice c ℓ₁ ℓ₂
joinSemilattice = record { isJoinSemilattice = isJoinSemilattice }
joinSemiLattice = joinSemilattice
{-# WARNING_ON_USAGE joinSemiLattice
"Warning: joinSemiLattice was deprecated in v0.17.
Please use joinSemilattice instead."
#-}
open JoinSemilattice joinSemilattice public using (preorder; poset)
------------------------------------------------------------------------
-- Meet semilattices
record IsMeetSemilattice {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
(_∧_ : Op₂ A) -- The meet operation.
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
field
isPartialOrder : IsPartialOrder _≈_ _≤_
infimum : Infimum _≤_ _∧_
x∧y≤x : ∀ x y → (x ∧ y) ≤ x
x∧y≤x x y = let pf , _ , _ = infimum x y in pf
x∧y≤y : ∀ x y → (x ∧ y) ≤ y
x∧y≤y x y = let _ , pf , _ = infimum x y in pf
∧-greatest : ∀ {x y z} → x ≤ y → x ≤ z → x ≤ (y ∧ z)
∧-greatest {x} {y} {z} = let _ , _ , pf = infimum y z in pf x
open IsPartialOrder isPartialOrder public
record MeetSemilattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _≤_
infixr 7 _∧_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_≤_ : Rel Carrier ℓ₂ -- The partial order.
_∧_ : Op₂ Carrier -- The meet operation.
isMeetSemilattice : IsMeetSemilattice _≈_ _≤_ _∧_
open IsMeetSemilattice isMeetSemilattice public
poset : Poset c ℓ₁ ℓ₂
poset = record { isPartialOrder = isPartialOrder }
open Poset poset public using (preorder)
record IsBoundedMeetSemilattice {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
(_∧_ : Op₂ A) -- The join operation.
(⊤ : A) -- The maximum.
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
field
isMeetSemilattice : IsMeetSemilattice _≈_ _≤_ _∧_
maximum : Maximum _≤_ ⊤
open IsMeetSemilattice isMeetSemilattice public
record BoundedMeetSemilattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _≤_
infixr 7 _∧_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_≤_ : Rel Carrier ℓ₂ -- The partial order.
_∧_ : Op₂ Carrier -- The join operation.
⊤ : Carrier -- The maximum.
isBoundedMeetSemilattice : IsBoundedMeetSemilattice _≈_ _≤_ _∧_ ⊤
open IsBoundedMeetSemilattice isBoundedMeetSemilattice public
meetSemilattice : MeetSemilattice c ℓ₁ ℓ₂
meetSemilattice = record { isMeetSemilattice = isMeetSemilattice }
meetSemiLattice = meetSemilattice
{-# WARNING_ON_USAGE meetSemiLattice
"Warning: meetSemiLattice was deprecated in v0.17.
Please use meetSemilattice instead."
#-}
open MeetSemilattice meetSemilattice public using (preorder; poset)
------------------------------------------------------------------------
-- Lattices
record IsLattice {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
(_∨_ : Op₂ A) -- The join operation.
(_∧_ : Op₂ A) -- The meet operation.
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
field
isPartialOrder : IsPartialOrder _≈_ _≤_
supremum : Supremum _≤_ _∨_
infimum : Infimum _≤_ _∧_
isJoinSemilattice : IsJoinSemilattice _≈_ _≤_ _∨_
isJoinSemilattice = record
{ isPartialOrder = isPartialOrder
; supremum = supremum
}
isMeetSemilattice : IsMeetSemilattice _≈_ _≤_ _∧_
isMeetSemilattice = record
{ isPartialOrder = isPartialOrder
; infimum = infimum
}
open IsJoinSemilattice isJoinSemilattice public
using (x≤x∨y; y≤x∨y; ∨-least)
open IsMeetSemilattice isMeetSemilattice public
using (x∧y≤x; x∧y≤y; ∧-greatest)
open IsPartialOrder isPartialOrder public
record Lattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _≤_
infixr 6 _∨_
infixr 7 _∧_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_≤_ : Rel Carrier ℓ₂ -- The partial order.
_∨_ : Op₂ Carrier -- The join operation.
_∧_ : Op₂ Carrier -- The meet operation.
isLattice : IsLattice _≈_ _≤_ _∨_ _∧_
open IsLattice isLattice public
setoid : Setoid c ℓ₁
setoid = record { isEquivalence = isEquivalence }
joinSemilattice : JoinSemilattice c ℓ₁ ℓ₂
joinSemilattice = record { isJoinSemilattice = isJoinSemilattice }
meetSemilattice : MeetSemilattice c ℓ₁ ℓ₂
meetSemilattice = record { isMeetSemilattice = isMeetSemilattice }
open JoinSemilattice joinSemilattice public using (poset; preorder)
record IsDistributiveLattice {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
(_∨_ : Op₂ A) -- The join operation.
(_∧_ : Op₂ A) -- The meet operation.
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
field
isLattice : IsLattice _≈_ _≤_ _∨_ _∧_
∧-distribˡ-∨ : _DistributesOverˡ_ _≈_ _∧_ _∨_
open IsLattice isLattice public
record DistributiveLattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _≤_
infixr 6 _∨_
infixr 7 _∧_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_≤_ : Rel Carrier ℓ₂ -- The partial order.
_∨_ : Op₂ Carrier -- The join operation.
_∧_ : Op₂ Carrier -- The meet operation.
isDistributiveLattice : IsDistributiveLattice _≈_ _≤_ _∨_ _∧_
open IsDistributiveLattice isDistributiveLattice using (∧-distribˡ-∨) public
open IsDistributiveLattice isDistributiveLattice using (isLattice)
lattice : Lattice c ℓ₁ ℓ₂
lattice = record { isLattice = isLattice }
open Lattice lattice hiding (Carrier; _≈_; _≤_; _∨_; _∧_) public
record IsBoundedLattice {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
(_∨_ : Op₂ A) -- The join operation.
(_∧_ : Op₂ A) -- The meet operation.
(⊤ : A) -- The maximum.
(⊥ : A) -- The minimum.
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
field
isLattice : IsLattice _≈_ _≤_ _∨_ _∧_
maximum : Maximum _≤_ ⊤
minimum : Minimum _≤_ ⊥
open IsLattice isLattice public
isBoundedJoinSemilattice : IsBoundedJoinSemilattice _≈_ _≤_ _∨_ ⊥
isBoundedJoinSemilattice = record
{ isJoinSemilattice = isJoinSemilattice
; minimum = minimum
}
isBoundedMeetSemilattice : IsBoundedMeetSemilattice _≈_ _≤_ _∧_ ⊤
isBoundedMeetSemilattice = record
{ isMeetSemilattice = isMeetSemilattice
; maximum = maximum
}
record BoundedLattice c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _≤_
infixr 6 _∨_
infixr 7 _∧_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_≤_ : Rel Carrier ℓ₂ -- The partial order.
_∨_ : Op₂ Carrier -- The join operation.
_∧_ : Op₂ Carrier -- The meet operation.
⊤ : Carrier -- The maximum.
⊥ : Carrier -- The minimum.
isBoundedLattice : IsBoundedLattice _≈_ _≤_ _∨_ _∧_ ⊤ ⊥
open IsBoundedLattice isBoundedLattice public
boundedJoinSemilattice : BoundedJoinSemilattice c ℓ₁ ℓ₂
boundedJoinSemilattice = record
{ isBoundedJoinSemilattice = isBoundedJoinSemilattice }
boundedMeetSemilattice : BoundedMeetSemilattice c ℓ₁ ℓ₂
boundedMeetSemilattice = record
{ isBoundedMeetSemilattice = isBoundedMeetSemilattice }
lattice : Lattice c ℓ₁ ℓ₂
lattice = record { isLattice = isLattice }
open Lattice lattice public
using (joinSemilattice; meetSemilattice; poset; preorder; setoid)
------------------------------------------------------------------------
-- Heyting algebras (a bounded lattice with exponential operator)
record IsHeytingAlgebra {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
(_∨_ : Op₂ A) -- The join operation.
(_∧_ : Op₂ A) -- The meet operation.
(_⇨_ : Op₂ A) -- The exponential operation.
(⊤ : A) -- The maximum.
(⊥ : A) -- The minimum.
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
field
isBoundedLattice : IsBoundedLattice _≈_ _≤_ _∨_ _∧_ ⊤ ⊥
exponential : Exponential _≤_ _∧_ _⇨_
transpose-⇨ : ∀ {w x y} → (w ∧ x) ≤ y → w ≤ (x ⇨ y)
transpose-⇨ {w} {x} {y} = let pf , _ = exponential w x y in pf
transpose-∧ : ∀ {w x y} → w ≤ (x ⇨ y) → (w ∧ x) ≤ y
transpose-∧ {w} {x} {y} = let _ , pf = exponential w x y in pf
open IsBoundedLattice isBoundedLattice public
record HeytingAlgebra c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _≤_
infixr 5 _⇨_
infixr 6 _∨_
infixr 7 _∧_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_≤_ : Rel Carrier ℓ₂ -- The partial order.
_∨_ : Op₂ Carrier -- The join operation.
_∧_ : Op₂ Carrier -- The meet operation.
_⇨_ : Op₂ Carrier -- The exponential operation.
⊤ : Carrier -- The maximum.
⊥ : Carrier -- The minimum.
isHeytingAlgebra : IsHeytingAlgebra _≈_ _≤_ _∨_ _∧_ _⇨_ ⊤ ⊥
boundedLattice : BoundedLattice c ℓ₁ ℓ₂
boundedLattice = record
{ isBoundedLattice = IsHeytingAlgebra.isBoundedLattice isHeytingAlgebra }
open IsHeytingAlgebra isHeytingAlgebra
using (exponential; transpose-⇨; transpose-∧) public
open BoundedLattice boundedLattice
hiding (Carrier; _≈_; _≤_; _∨_; _∧_; ⊤; ⊥) public
------------------------------------------------------------------------
-- Boolean algebras (a specialized Heyting algebra)
record IsBooleanAlgebra {a ℓ₁ ℓ₂} {A : Set a}
(_≈_ : Rel A ℓ₁) -- The underlying equality.
(_≤_ : Rel A ℓ₂) -- The partial order.
(_∨_ : Op₂ A) -- The join operation.
(_∧_ : Op₂ A) -- The meet operation.
(¬_ : Op₁ A) -- The negation operation.
(⊤ : A) -- The maximum.
(⊥ : A) -- The minimum.
: Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
infixr 5 _⇨_
_⇨_ : Op₂ A
x ⇨ y = (¬ x) ∨ y
field
isHeytingAlgebra : IsHeytingAlgebra _≈_ _≤_ _∨_ _∧_ _⇨_ ⊤ ⊥
open IsHeytingAlgebra isHeytingAlgebra public
record BooleanAlgebra c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _≤_
infixr 6 _∨_
infixr 7 _∧_
infix 8 ¬_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_≤_ : Rel Carrier ℓ₂ -- The partial order.
_∨_ : Op₂ Carrier -- The join operation.
_∧_ : Op₂ Carrier -- The meet operation.
¬_ : Op₁ Carrier -- The negation operation.
⊤ : Carrier -- The maximum.
⊥ : Carrier -- The minimum.
isBooleanAlgebra : IsBooleanAlgebra _≈_ _≤_ _∨_ _∧_ ¬_ ⊤ ⊥
open IsBooleanAlgebra isBooleanAlgebra using (isHeytingAlgebra)
heytingAlgebra : HeytingAlgebra c ℓ₁ ℓ₂
heytingAlgebra = record { isHeytingAlgebra = isHeytingAlgebra }
open HeytingAlgebra heytingAlgebra public
hiding (Carrier; _≈_; _≤_; _∨_; _∧_; ⊤; ⊥)
|
{
"alphanum_fraction": 0.5389058137,
"avg_line_length": 37.1603773585,
"ext": "agda",
"hexsha": "d206e036cd7b9ed0656e9236f3abca2328bd742d",
"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/Relation/Binary/Lattice.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Lattice.agda",
"max_line_length": 78,
"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/Relation/Binary/Lattice.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5213,
"size": 15756
}
|
open import Prelude
open import Nat
open import Bij
module Int where
data Int : Set where
+_ : Nat → Int
-[1+_] : Nat → Int
int→nat : Int → Nat
int→nat (+ n) = 1+ (n + n)
int→nat -[1+ n ] = n + n
int→nat:inj : ∀{m n} →
int→nat m == int→nat n →
m == n
int→nat:inj {+ m} {+ n} eq rewrite even-inj {m} {n} (1+inj eq) = refl
int→nat:inj {+ m} { -[1+ n ]} eq = abort (even-not-odd {m} {n} eq)
int→nat:inj { -[1+ m ]} {+ n} eq = abort (even-not-odd {n} {m} (! eq))
int→nat:inj { -[1+ m ]} { -[1+ n ]} eq rewrite even-inj {m} {n} eq = refl
int→nat:surj : (n : Nat) → Σ[ m ∈ Int ] (int→nat m == n)
int→nat:surj Z = -[1+ Z ] , refl
int→nat:surj (1+ Z) = (+ Z) , refl
int→nat:surj (1+ (1+ n)) with int→nat:surj n
int→nat:surj (1+ (1+ .(1+ (n + n)))) | (+ n) , refl = (+ 1+ n) , 1+ap (1+ap n+1+m==1+n+m)
int→nat:surj (1+ (1+ .(n + n))) | -[1+ n ] , refl = -[1+ 1+ n ] , 1+ap n+1+m==1+n+m
instance
IntBij : bij Int Nat
IntBij = record {
convert = int→nat;
inj = int→nat:inj;
surj = int→nat:surj}
|
{
"alphanum_fraction": 0.4678733032,
"avg_line_length": 30.6944444444,
"ext": "agda",
"hexsha": "ed20ae2c4ac9e6b4e9dceac5fcc28fee5e4a0d6e",
"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": "db857f3e7dc9a4793f68504e6365d93ed75d7f88",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nickcollins/dependent-dicts-agda",
"max_forks_repo_path": "Int.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "db857f3e7dc9a4793f68504e6365d93ed75d7f88",
"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": "nickcollins/dependent-dicts-agda",
"max_issues_repo_path": "Int.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "db857f3e7dc9a4793f68504e6365d93ed75d7f88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nickcollins/dependent-dicts-agda",
"max_stars_repo_path": "Int.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 504,
"size": 1105
}
|
module Haskell.RangedSetsProp.RangesProperties where
open import Haskell.RangedSetsProp.library
open import Agda.Builtin.Equality
open import Agda.Builtin.Bool
open import Agda.Builtin.Nat renaming (_==_ to eqq; _<_ to ltt)
open import Haskell.Prim
open import Haskell.Prim.Ord
open import Haskell.Prim.Bool
open import Haskell.Prim.Maybe
open import Haskell.Prim.Enum
open import Haskell.Prim.Eq
open import Haskell.Prim.Foldable
open import Haskell.Prim.List
open import Haskell.Prim.Integer
open import Haskell.Prim.Double
open import Haskell.RangedSets.Boundaries
open import Haskell.RangedSets.Ranges
open import Haskell.RangedSetsProp.BoundariesProperties
postulate
prop_range_creation : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → {r1 r2 : Boundary a} →
{r3 r4 : Boundary a} → (r1 ≡ r3) → (r2 ≡ r4) → (Rg r1 r2) ≡ Rg r3 r4
prop_intersection_sym : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (r1 : Range a) → (r2 : Range a) →
rangeIntersection r1 r2 ≡ rangeIntersection r2 r1
prop_intersection_sym ⦃ o ⦄ ⦃ dio ⦄ r1@(Rg l1 u1) r2@(Rg l2 u2) =
begin
rangeIntersection r1 r2
=⟨⟩
if_then_else_ (rangeIsEmpty r1 || rangeIsEmpty r2) emptyRange (Rg (max l1 l2) (min u1 u2))
=⟨ cong (ifThenElseHelper emptyRange (Rg (max l1 l2) (min u1 u2))) (prop_or_sym (rangeIsEmpty r1) (rangeIsEmpty r2)) ⟩
if_then_else_ (rangeIsEmpty r2 || rangeIsEmpty r1) emptyRange (Rg (max l1 l2) (min u1 u2))
=⟨ cong (if_then_else_ (rangeIsEmpty r2 || rangeIsEmpty r1) emptyRange)
(prop_range_creation (prop_max_sym l1 l2) (prop_min_sym u1 u2)) ⟩
if_then_else_ (rangeIsEmpty r2 || rangeIsEmpty r1) emptyRange (Rg (max l2 l1) (min u2 u1))
=⟨⟩
rangeIntersection r2 r1
end
prop_singletonRangeHas : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (x : a) → (rangeHas ⦃ o ⦄ (singletonRange x) x) ≡ true
prop_singletonRangeHas ⦃ o ⦄ ⦃ dio ⦄ x =
begin
(rangeHas (singletonRange x) x)
=⟨⟩
(rangeHas (Rg (BoundaryBelow x) (BoundaryAbove x)) x)
=⟨⟩
((x />/ (BoundaryBelow x)) && (not (x />/ (BoundaryAbove x))))
=⟨⟩
((x >= x) && (not (x > x)))
=⟨ cong (_&& (not (x > x))) (gteq ⦃ o ⦄ refl) ⟩
(true && (not (x > x)))
=⟨ cong (true &&_) (gt ⦃ o ⦄ refl) ⟩
(true && true)
=⟨⟩
true
end
prop_singletonRangeHasOnly : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (x y : a) → (rangeHas ⦃ o ⦄ (singletonRange x) y) ≡ (x == y)
prop_singletonRangeHasOnly ⦃ o ⦄ ⦃ dio ⦄ v1 v2 =
begin
(rangeHas (singletonRange v1) v2)
=⟨⟩
(rangeHas (Rg (BoundaryBelow v1) (BoundaryAbove v1)) v2)
=⟨⟩
((v2 />/ (BoundaryBelow v1)) && (not (v2 />/ (BoundaryAbove v1))))
=⟨⟩
((v2 >= v1) && (not (v2 > v1)))
=⟨ eq1 v2 v1 ⟩
(v1 == v2)
end
prop_singletonRangeConverse : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (x : a) → rangeSingletonValue (singletonRange x) ≡ Just x
prop_singletonRangeConverse ⦃ o ⦄ ⦃ dio ⦄ v =
begin
rangeSingletonValue (singletonRange v)
=⟨⟩
rangeSingletonValue (Rg (BoundaryBelow v) (BoundaryAbove v))
=⟨⟩
if_then_else_ (v == v) (Just v) Nothing
=⟨ propIf2 (v == v) (eq0 ⦃ o ⦄ refl) ⟩
Just v
end
prop_emptyNonSingleton : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → rangeSingletonValue ⦃ o ⦄ ⦃ dio ⦄ emptyRange ≡ Nothing
prop_emptyNonSingleton = refl
prop_fullNonSingleton : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → rangeSingletonValue ⦃ o ⦄ ⦃ dio ⦄ fullRange ≡ Nothing
prop_fullNonSingleton = refl
rs : Double → Double → List (Range Double)
rs x y = (Rg (BoundaryBelow x) (BoundaryBelow y)) ∷ (Rg (BoundaryAbove x) (BoundaryBelow y)) ∷ (Rg (BoundaryBelow x) (BoundaryAbove y)) ∷ (Rg (BoundaryAbove x) (BoundaryAbove y)) ∷ []
length' : List a → Nat
length' [] = 0
length' (x ∷ []) = 1
length' (x ∷ xs) = 1 + (length' xs)
prop_unionRangeLengthHelper3 : ⦃ ord : Ord a ⦄ → ⦃ diso : DiscreteOrdered a ⦄
→ (r1 r2 : (Range a)) → (b : Bool)
→ ((eqq ((length' (if_then_else_ b ((Rg (min (rangeLower r1) (rangeLower r2)) (max (rangeUpper r1) (rangeUpper r2))) ∷ []) (r1 ∷ r2 ∷ [])))) 1)
|| (eqq (length' ((if_then_else_ b ((Rg (min (rangeLower r1) (rangeLower r2)) (max (rangeUpper r1) (rangeUpper r2))) ∷ []) (r1 ∷ r2 ∷ [])))) 2)) ≡ true
prop_unionRangeLengthHelper3 ⦃ o ⦄ ⦃ dio ⦄ r1@(Rg l1 u1) r2@(Rg l2 u2) true =
begin
((eqq (length' ((Rg (min l1 l2) (max u1 u2)) ∷ [])) 1) || (eqq (length' ((Rg (min l1 l2) (max u1 u2)) ∷ [])) 2))
=⟨⟩
((eqq 1 1) || (eqq 1 2))
=⟨⟩
(true || false)
=⟨⟩
true
end
prop_unionRangeLengthHelper3 ⦃ o ⦄ ⦃ dio ⦄ r1@(Rg l1 u1) r2@(Rg l2 u2) false =
begin
((eqq (length' (r1 ∷ r2 ∷ [])) 1) || (eqq (length' (r1 ∷ r2 ∷ [])) 2))
=⟨⟩
((eqq 2 1) || (eqq 2 2))
=⟨⟩
(false || true)
=⟨⟩
true
end
prop_unionRangeLengthHelper2 : ⦃ ord : Ord a ⦄ → ⦃ diso : DiscreteOrdered a ⦄
→ (r1 r2 : (Range a)) → (b : Bool)
→ ((eqq (length' (if_then_else_ b (r1 ∷ []) (rangeU2 r1 r2))) 1) || (eqq (length' ((if_then_else_ b (r1 ∷ []) (rangeU2 r1 r2)))) 2)) ≡ true
prop_unionRangeLengthHelper2 ⦃ o ⦄ ⦃ dio ⦄ r1@(Rg l1 u1) r2@(Rg l2 u2) true =
begin
((eqq (length' (r1 ∷ [])) 1) || (eqq (length' (r1 ∷ [])) 2))
=⟨⟩
((eqq 1 1) || (eqq 1 2))
=⟨⟩
(true || false)
=⟨⟩
true
end
prop_unionRangeLengthHelper2 ⦃ o ⦄ ⦃ dio ⦄ r1@(Rg l1 u1) r2@(Rg l2 u2) false =
begin
((eqq (length' (rangeU2 r1 r2)) 1) || (eqq (length' (rangeU2 r1 r2)) 2))
=⟨⟩
((eqq (length' (if_then_else_ ((max l1 l2) <= (min u1 u2)) ((Rg (min l1 l2) (max u1 u2)) ∷ []) (r1 ∷ r2 ∷ []))) 1)
|| (eqq (length' (if_then_else_ ((max l1 l2) <= (min u1 u2)) ((Rg (min l1 l2) (max u1 u2)) ∷ []) (r1 ∷ r2 ∷ []))) 2))
=⟨ prop_unionRangeLengthHelper3 r1 r2 (((max l1 l2) <= (min u1 u2))) ⟩
true
end
prop_unionRangeLengthHelper : ⦃ ord : Ord a ⦄ → ⦃ diso : DiscreteOrdered a ⦄
→ (r1 r2 : (Range a)) → (b : Bool)
→ ((eqq (length' (if_then_else_ b (r2 ∷ []) (rangeU1 r1 r2))) 1) || (eqq (length' ((if_then_else_ b (r2 ∷ []) (rangeU1 r1 r2)))) 2)) ≡ true
prop_unionRangeLengthHelper ⦃ o ⦄ ⦃ dio ⦄ r1@(Rg l1 u1) r2@(Rg l2 u2) true =
begin
((eqq (length' (r2 ∷ [])) 1) || (eqq (length' (r2 ∷ [])) 2))
=⟨⟩
((eqq 1 1) || (eqq 1 2))
=⟨⟩
(true || false)
=⟨⟩
true
end
prop_unionRangeLengthHelper ⦃ o ⦄ ⦃ dio ⦄ r1@(Rg l1 u1) r2@(Rg l2 u2) false =
begin
((eqq (length' (rangeU1 r1 r2)) 1) || (eqq (length' (rangeU1 r1 r2)) 2))
=⟨⟩
((eqq (length' (if_then_else_ (rangeIsEmpty r2) (r1 ∷ []) (rangeU2 r1 r2))) 1)
|| (eqq (length' (if_then_else_ (rangeIsEmpty r2) (r1 ∷ []) (rangeU2 r1 r2))) 2))
=⟨ prop_unionRangeLengthHelper2 r1 r2 (rangeIsEmpty r2) ⟩
true
end
prop_unionRangeLength : ⦃ ord : Ord a ⦄ → ⦃ diso : DiscreteOrdered a ⦄
→ (r1 r2 : (Range a)) → ((eqq (length' (rangeUnion r1 r2)) 1) || (eqq (length' (rangeUnion r1 r2)) 2)) ≡ true
prop_unionRangeLength ⦃ o ⦄ ⦃ dio ⦄ r1@(Rg l1 u1) r2@(Rg l2 u2) =
begin
((eqq (length' (rangeUnion r1 r2)) 1) || (eqq (length' (rangeUnion r1 r2)) 2))
=⟨⟩
((eqq (length' (if_then_else_ (rangeIsEmpty r1) (r2 ∷ []) (rangeU1 r1 r2))) 1) || (eqq (length' (if_then_else_ (rangeIsEmpty r1) (r2 ∷ []) (rangeU1 r1 r2))) 2))
=⟨ prop_unionRangeLengthHelper r1 r2 (rangeIsEmpty r1) ⟩
true
end
prop_UnionRange1 : ⦃ ord : Ord a ⦄ → ⦃ diso : DiscreteOrdered a ⦄
→ (r1 r2 : (Range a)) → ⦃ ne1 : IsFalse (rangeIsEmpty r1) ⦄ → ⦃ ne2 : IsFalse (rangeIsEmpty r2) ⦄
→ ⦃ ne3 : IsFalse ((max (rangeLower r1) (rangeLower r2)) <= (min (rangeUpper r1) (rangeUpper r2))) ⦄ → (n : a)
→ (rangeListHas1 n (rangeUnion ⦃ ord ⦄ ⦃ diso ⦄ r1 r2)) ≡ ((rangeHas ⦃ ord ⦄ r1 n) || (rangeHas ⦃ ord ⦄ r2 n))
prop_UnionRange1 ⦃ ord ⦄ ⦃ diso ⦄ r1@(Rg l1 u1) r2@(Rg l2 u2) ⦃ ne1 ⦄ ⦃ ne2 ⦄ ⦃ ne3 ⦄ n =
begin
(rangeListHas1 n (rangeUnion r1 r2))
=⟨⟩
(rangeListHas1 n (if_then_else_ (rangeIsEmpty r1) (r2 ∷ []) (rangeU1 r1 r2)))
=⟨ propIf (rangeListHas1 n) (rangeIsEmpty r1) ⟩
if_then_else_ (rangeIsEmpty r1) (rangeListHas1 n (r2 ∷ [])) (rangeListHas1 n (rangeU1 r1 r2))
=⟨ propIf3 (rangeIsEmpty r1) ne1 ⟩
rangeListHas1 n (rangeU1 r1 r2)
=⟨ cong (rangeListHas1 n) (propIf3 (rangeIsEmpty r2) ne2) ⟩
(rangeListHas1 n (rangeU2 r1 r2))
=⟨ cong (rangeListHas1 n) (propIf3 ((max l1 l2) <= (min u1 u2)) ne3) ⟩
(rangeListHas1 n (r1 ∷ r2 ∷ []))
=⟨⟩
((rangeHas r1 n) || (rangeHas r2 n))
end
-- prop_UnionRange1' : ⦃ ord : Ord a ⦄ → ⦃ diso : DiscreteOrdered a ⦄
-- → (r1 r2 : (Range a)) → ⦃ne1 : IsFalse (rangeIsEmpty r1)⦄ → ⦃ne2 : IsFalse (rangeIsEmpty r2)⦄
-- → ⦃ne3 : IsTrue ((max (rangeLower r1) (rangeLower r2)) <= (min (rangeUpper r1) (rangeUpper r2)))⦄ → (n : a)
-- → (rangeListHas1 n (rangeUnion ⦃ord⦄ ⦃diso⦄ r1 r2)) ≡ ((rangeHas ⦃ord⦄ r1 n) || (rangeHas ⦃ord⦄ r2 n))
-- prop_UnionRange1' ⦃ord⦄ ⦃diso⦄ r1@(Rg l1 u1) r2@(Rg l2 u2) ⦃ne1⦄ ⦃ne2⦄ ⦃ne3⦄ n =
-- begin
-- (rangeListHas1 n (rangeUnion r1 r2))
-- =⟨⟩
-- (rangeListHas1 n (if_then_else_ (rangeIsEmpty r1) (r2 ∷ []) (rangeU1 r1 r2)))
-- =⟨ propIf (rangeListHas1 n) (rangeIsEmpty r1) ⟩
-- if_then_else_ (rangeIsEmpty r1) (rangeListHas1 n (r2 ∷ [])) (rangeListHas1 n (rangeU1 r1 r2))
-- =⟨ propIf3 (rangeIsEmpty r1) ne1 ⟩
-- rangeListHas1 n (rangeU1 r1 r2)
-- =⟨ cong (rangeListHas1 n) (propIf3 (rangeIsEmpty r2) ne2) ⟩
-- (rangeListHas1 n (rangeU2 r1 r2))
-- =⟨ cong (rangeListHas1 n) (propIf2 ((max l1 l2) <= (min u1 u2)) ne3) ⟩
-- (rangeListHas1 n ((Rg (min l1 l2) (max u1 u2)) ∷ []))
-- =⟨⟩
-- ((n />/ (min l1 l2)) && not (n />/ (max u1 u2)))
-- =⟨⟩
-- ((n />/ (if (compare l1 l2 == LT) then l1 else l2)) && not (n />/ (if (compare u1 u2 == GT) then u1 else u2)))
-- =⟨⟩
-- ((rangeHas r1 n) || (rangeHas r2 n))
-- end
prop_emptyRange : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (r : Range a) → not (rangeIsEmpty r) ≡ (rangeLower r <= rangeUpper r)
prop_emptyRange ⦃ o ⦄ ⦃ dio ⦄ r@(Rg l u) =
begin
not (rangeIsEmpty r)
=⟨⟩
not (u <= l)
=⟨ eq2 u l ⟩
l < u
=⟨ lteq l u ⟩
l <= u
end
prop_rangeHas : ⦃ ord : Ord a ⦄ → ⦃ diso : DiscreteOrdered a ⦄ → {r : (Range a)} → {n : a}
→ (rangeHas1 ⦃ ord ⦄ n r) ≡ (rangeHas ⦃ ord ⦄ r n)
prop_rangeHas {r = (Rg x y)} {n} =
begin
rangeHas1 n (Rg x y)
=⟨⟩
(n />/ x) && (not (n />/ y))
=⟨⟩
rangeHas (Rg x y) n
end
prop_IntersectionRange : ⦃ ord : Ord a ⦄ → ⦃ diso : DiscreteOrdered a ⦄ → (r1 r2 : (Range a))
→ ⦃ ff : IsFalse (rangeIsEmpty r1 || rangeIsEmpty r2) ⦄ → (n : a)
→ ((rangeHas r1 n) && (rangeHas r2 n)) ≡ (rangeHas (rangeIntersection r1 r2) n)
prop_IntersectionRange ⦃ ord ⦄ ⦃ diso ⦄ r1@(Rg x1 y1) r2@(Rg x2 y2) ⦃ ff ⦄ n =
begin
((rangeHas r1 n) && (rangeHas r2 n))
=⟨⟩
((n />/ x1) && (not (n />/ y1))) && ((n />/ x2) && (not (n />/ y2)))
=⟨ prop_and_assoc (n />/ x1) (not (n />/ y1)) (n />/ x2 && (not (n />/ y2))) ⟩
((n />/ x1) && ((not (n />/ y1)) && ((n />/ x2) && (not (n />/ y2)))))
=⟨ cong ((n />/ x1) &&_) (sym (prop_and_assoc (not (n />/ y1)) (n />/ x2) (not (n />/ y2)))) ⟩
((n />/ x1) && (not (n />/ y1) && (n />/ x2)) && (not (n />/ y2)))
=⟨ sym (prop_and_assoc (n />/ x1) (not (n />/ y1) && (n />/ x2)) (not (n />/ y2))) ⟩
(((n />/ x1) && (not (n />/ y1) && (n />/ x2))) && (not (n />/ y2)))
=⟨ cong (_&& (not (n />/ y2))) (cong ((n />/ x1) &&_) (prop_and_comm (not (n />/ y1)) (n />/ x2))) ⟩
(((n />/ x1) && ((n />/ x2) && not (n />/ y1))) && (not (n />/ y2)))
=⟨ cong (_&& (not (n />/ y2))) (sym (prop_and_assoc (n />/ x1) (n />/ x2) (not (n />/ y1)))) ⟩
((((n />/ x1) && (n />/ x2)) && not (n />/ y1)) && (not (n />/ y2)))
=⟨ prop_and_assoc ((n />/ x1) && (n />/ x2)) (not (n />/ y1)) (not (n />/ y2)) ⟩
(((n />/ x1) && (n />/ x2)) && (not (n />/ y1) && (not (n />/ y2))))
=⟨ cong ((n />/ x1 && n />/ x2) &&_) (prop_demorgan2 (n />/ y1) (n />/ y2)) ⟩
(n />/ x1 && n />/ x2) && (not ((n />/ y1) || (n />/ y2)))
=⟨ cong (_&& (not ((n />/ y1) || (n />/ y2)))) (boundaries0 n x1 x2) ⟩
(n />/ (max x1 x2)) && (not ((n />/ y1) || (n />/ y2)))
=⟨ cong ((n />/ (max x1 x2)) &&_) (cong not (boundaries1 n y1 y2)) ⟩
(n />/ (max x1 x2)) && not (n />/ (min y1 y2))
=⟨⟩
rangeHas (Rg (max (rangeLower r1) (rangeLower r2)) (min (rangeUpper r1) (rangeUpper r2))) n
=⟨ sym (cong (rangeHas1 n) (propIf3 (rangeIsEmpty r1 || rangeIsEmpty r2) ff)) ⟩
rangeHas1 n (rangeIntersection r1 r2)
=⟨ prop_rangeHas ⦃ ord ⦄ ⦃ diso ⦄ {(rangeIntersection r1 r2)} ⟩
rangeHas (rangeIntersection r1 r2) n
end
prop_notEmptyRanges : ⦃ ord : Ord a ⦄ → ⦃ diso : DiscreteOrdered a ⦄ → (r1 r2 : (Range a))
→ (not ((rangeIsEmpty r1) || (rangeIsEmpty r2))) ≡ (((rangeLower r1) < (rangeUpper r1)) && ((rangeLower r2) < (rangeUpper r2)))
prop_notEmptyRanges ⦃ ord ⦄ ⦃ diso ⦄ r1@(Rg l1 u1) r2@(Rg l2 u2) =
begin
not ((rangeIsEmpty r1 )|| (rangeIsEmpty r2))
=⟨⟩
(not (((rangeUpper r1) <= (rangeLower r1)) || ((rangeUpper r2) <= (rangeLower r2))))
=⟨ sym (prop_demorgan2 ((rangeUpper r1) <= (rangeLower r1)) ((rangeUpper r2) <= (rangeLower r2))) ⟩
((not ((rangeUpper r1) <= (rangeLower r1)))) && (not ((rangeUpper r2) <= (rangeLower r2)))
=⟨ cong (not ((rangeUpper r1) <= (rangeLower r1)) &&_) (eq2 (rangeUpper r2) (rangeLower r2)) ⟩
((not ((rangeUpper r1) <= (rangeLower r1))) && ((rangeLower r2) < (rangeUpper r2)))
=⟨ cong (_&& ((rangeLower r2) < (rangeUpper r2))) (eq2 (rangeUpper r1) (rangeLower r1)) ⟩
(((rangeLower r1) < (rangeUpper r1)) && ((rangeLower r2) < (rangeUpper r2)))
end
prop_intersectionOverlap : ⦃ ord : Ord a ⦄ → ⦃ diso : DiscreteOrdered a ⦄ → (r1 r2 : (Range a))
→ ⦃ ff : IsFalse (rangeIsEmpty r1 || rangeIsEmpty r2) ⦄
→ ⦃ tr : IsTrue (((rangeLower r1) < (rangeUpper r1)) && ((rangeLower r2) < (rangeUpper r2))) ⦄
→ (rangeIsEmpty (rangeIntersection r1 r2)) ≡ not (rangeOverlap r1 r2)
prop_intersectionOverlap ⦃ ord ⦄ ⦃ diso ⦄ r1@(Rg _ _) r2@(Rg _ _) ⦃ ff ⦄ ⦃ tr ⦄ =
begin
(rangeIsEmpty (rangeIntersection r1 r2))
=⟨⟩
rangeIsEmpty (if_then_else_ (rangeIsEmpty r1 || rangeIsEmpty r2) emptyRange (Rg (max (rangeLower r1) (rangeLower r2)) (min (rangeUpper r1) (rangeUpper r2))))
=⟨ cong rangeIsEmpty (propIf3 (rangeIsEmpty r1 || rangeIsEmpty r2) ff) ⟩
(rangeIsEmpty (Rg (max (rangeLower r1) (rangeLower r2)) (min (rangeUpper r1) (rangeUpper r2))))
=⟨⟩
((min (rangeUpper r1) (rangeUpper r2)) <= (max (rangeLower r1) (rangeLower r2)))
=⟨ sym (prop_or_false ((min (rangeUpper r1) (rangeUpper r2)) <= (max (rangeLower r1) (rangeLower r2)))) ⟩
(false || ((min (rangeUpper r1) (rangeUpper r2)) <= (max (rangeLower r1) (rangeLower r2))))
=⟨ cong (_|| ((min (rangeUpper r1) (rangeUpper r2)) <= (max (rangeLower r1) (rangeLower r2)))) (sym (propIsFalse (rangeIsEmpty r1 || rangeIsEmpty r2) ff)) ⟩
(((rangeIsEmpty r1) || (rangeIsEmpty r2)) || ((min (rangeUpper r1) (rangeUpper r2)) <= (max (rangeLower r1) (rangeLower r2))))
=⟨ prop_or_assoc (rangeIsEmpty r1) (rangeIsEmpty r2) ((min (rangeUpper r1) (rangeUpper r2)) <= (max (rangeLower r1) (rangeLower r2))) ⟩
((rangeIsEmpty r1) || ((rangeIsEmpty r2) || ((min (rangeUpper r1) (rangeUpper r2)) <= (max (rangeLower r1) (rangeLower r2)))))
=⟨ cong ((rangeIsEmpty r1) ||_) (cong ((rangeIsEmpty r2) ||_) (eq3 (rangeUpper r1) (rangeUpper r2) (rangeLower r1) (rangeLower r2) ⦃ tr ⦄)) ⟩
((rangeIsEmpty r1) || ((rangeIsEmpty r2) || (rangeUpper r1 <= rangeLower r2 || rangeUpper r2 <= rangeLower r1)))
=⟨ not-not ((rangeIsEmpty r1) || (rangeIsEmpty r2) || (rangeUpper r1 <= rangeLower r2 || rangeUpper r2 <= rangeLower r1)) ⟩
not (not ((rangeIsEmpty r1) || (rangeIsEmpty r2) || (rangeUpper r1 <= rangeLower r2 || rangeUpper r2 <= rangeLower r1)))
=⟨ cong (not) (demorgan3 (rangeIsEmpty r1) (rangeIsEmpty r2) (rangeUpper r1 <= rangeLower r2) (rangeUpper r2 <= rangeLower r1)) ⟩
not (not (rangeIsEmpty r1) && not (rangeIsEmpty r2) && ((not (rangeUpper r1 <= rangeLower r2)) && (not (rangeUpper r2 <= rangeLower r1))))
=⟨ cong not (cong ((not (rangeIsEmpty r1)) &&_) (cong ((not (rangeIsEmpty r2)) &&_) (prop_demorgan2 (rangeUpper r1 <= rangeLower r2) (rangeUpper r2 <= rangeLower r1)))) ⟩
not (not (rangeIsEmpty r1) && not (rangeIsEmpty r2) && not ((rangeUpper r1 <= rangeLower r2) || (rangeUpper r2 <= rangeLower r1)))
=⟨⟩
not (rangeOverlap r1 r2)
end
|
{
"alphanum_fraction": 0.5528546204,
"avg_line_length": 50.1179941003,
"ext": "agda",
"hexsha": "32b05747fd996f61936f0393df819947b43c75ab",
"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": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ioanasv/agda2hs",
"max_forks_repo_path": "lib/Haskell/RangedSetsProp/RangesProperties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"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": "ioanasv/agda2hs",
"max_issues_repo_path": "lib/Haskell/RangedSetsProp/RangesProperties.agda",
"max_line_length": 183,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ioanasv/agda2hs",
"max_stars_repo_path": "lib/Haskell/RangedSetsProp/RangesProperties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:41:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:41:34.000Z",
"num_tokens": 7054,
"size": 16990
}
|
module Haskell.RangedSetsProp.library where
open import Agda.Builtin.Equality
open import Agda.Builtin.Bool
open import Haskell.Prim
open import Haskell.Prim.Ord
open import Haskell.Prim.Bool
open import Haskell.Prim.Eq
open import Haskell.Prim.Int
open import Haskell.Prim.List
open import Haskell.RangedSets.Boundaries
open import Haskell.RangedSets.Ranges
-- symmetry of equality
sym : {A : Set} {x y : A} → x ≡ y → y ≡ x
sym refl = refl
-- transitivity of equality
trans : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
-- congruence of equality
cong : {A B : Set} {x y : A} → (f : A → B) → x ≡ y → f x ≡ f y
cong f refl = refl
begin_ : {A : Set} → {x y : A} → x ≡ y → x ≡ y
begin p = p
_end : {A : Set} → (x : A) → x ≡ x
x end = refl
_=⟨_⟩_ : {A : Set} → (x : A) → {y z : A}
→ x ≡ y → y ≡ z → x ≡ z
x =⟨ p ⟩ q = trans p q
_=⟨⟩_ : {A : Set} → (x : A) → {y : A} → x ≡ y → x ≡ y
x =⟨⟩ q = x =⟨ refl ⟩ q
infix 1 begin_
infix 3 _end
infixr 2 _=⟨_⟩_
infixr 2 _=⟨⟩_
subst : {A : Set} {x y : A} → (P : A → Set) → x ≡ y → P x → P y
subst P refl p = p
isTrue&&₁ : {x y : Bool} → IsTrue (x && y) → IsTrue x
isTrue&&₂ : {x y : Bool} → IsTrue (x && y) → IsTrue y
isTrue&&₁ {true} _ = IsTrue.itsTrue
isTrue&&₁ {false} ()
isTrue&&₂ {true} p = p
isTrue&&₂ {false} ()
ifThenElseHelper : {a : Set ℓ} → a → a → Bool → a
ifThenElseHelper b c d = if_then_else_ d b c
propIf : {a b : Set} → {x y : a} (f : a → b) (c : Bool) → f (if c then x else y) ≡ (if c then f x else f y)
propIf f false = refl
propIf f true = refl
propIf2 : ⦃ Ord a ⦄ → {x y : a} (c : Bool) → IsTrue c → (if c then x else y) ≡ x
propIf2 true f = refl
propIf3 : ⦃ Ord a ⦄ → {x y : a} (c : Bool) → IsFalse c → (if c then x else y) ≡ y
propIf3 false f = refl
propIf2' : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → {x y : List (Range a)} (c : Bool) → IsTrue c → (if c then x else y) ≡ x
propIf2' true f = refl
propIf3' : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → {x y : List (Range a)} (c : Bool) → IsFalse c → (if c then x else y) ≡ y
propIf3' false f = refl
propIsFalse : (x : Bool) → IsFalse x → x ≡ false
propIsFalse false f = refl
propIsTrue : (x : Bool) → IsTrue x → x ≡ true
propIsTrue true f = refl
prop_or_and_eqiv_true : (x y : Bool) -> IsTrue x -> IsTrue y -> (x || y) ≡ (x && y)
prop_or_and_eqiv_true true true _ _ = refl
prop_or_and_eqiv_false : (x y : Bool) -> IsFalse x -> IsFalse y -> (x || y) ≡ (x && y)
prop_or_and_eqiv_false false false _ _ = refl
postulate
isTrueAndIsFalse1 : {b : Bool} -> IsTrue b -> IsFalse (not b)
isTrueAndIsFalse2 : {b : Bool} -> IsTrue (not b) -> IsFalse b
isTrueAndIsFalse3 : {b : Bool} -> IsFalse (not b) -> IsTrue b
isTrueAndIsFalse4 : {b : Bool} -> IsFalse b -> IsTrue (not b)
gteq : ⦃ o : Ord a ⦄ → ∀ {x y : a} → (x ≡ y) → (_>=_ ⦃ o ⦄ x y) ≡ true
lt : ⦃ o : Ord a ⦄ → (x y : a) → (x ≡ y) → IsFalse (_>_ ⦃ o ⦄ x y)
lteq : ⦃ o : Ord a ⦄ → (x y : a) → (_<_ ⦃ o ⦄ x y) ≡ (_<=_ ⦃ o ⦄ x y)
gt : ⦃ o : Ord a ⦄ → ∀ {x y : a} → (x ≡ y) → not (_>_ ⦃ o ⦄ x y) ≡ true
eq0 : ⦃ o : Ord a ⦄ → ∀ {x y : a} → (x ≡ y) → IsTrue (x == y)
eq1 : ⦃ o : Ord a ⦄ → (x y : a) → ((_>=_ ⦃ o ⦄ x y) && (not (_>_ ⦃ o ⦄ x y))) ≡ (y == x)
eq2 : ⦃ o : Ord a ⦄ → (x y : a) → not (_<=_ ⦃ o ⦄ x y) ≡ (_<_ ⦃ o ⦄ y x)
eq3 : ⦃ o : Ord a ⦄ → (x y i j : a) → ⦃ IsTrue ((_<_ ⦃ o ⦄ i x) && (_<_ ⦃ o ⦄ j y)) ⦄ → ((min ⦃ o ⦄ x y) <= (max ⦃ o ⦄ i j)) ≡ ((_<=_ ⦃ o ⦄ x j) || (_<=_ ⦃ o ⦄ y i))
eq4 : ⦃ o : Ord a ⦄ → ∀ {x y : a} → (x ≡ y) → ((compare x y) == EQ) ≡ true
boundaries0 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (x : a) → (b c : Boundary a) → ((x />/ b) && (x />/ c)) ≡ (x />/ (max b c))
boundaries1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (x : a) → (b c : Boundary a) → ((x />/ b) || (x />/ c)) ≡ (x />/ (min b c))
prop_and_assoc : (a b c : Bool) → ((a && b) && c) ≡ (a && (b && c))
prop_and_assoc true b c =
begin
((true && b) && c)
=⟨⟩
(b && c)
=⟨⟩
(true && (b && c))
end
prop_and_assoc false b c =
begin
((false && b) && c)
=⟨⟩
(false && c)
=⟨⟩
false
=⟨⟩
(false && (b && c))
end
prop_and_cancel : (a : Bool) {b : Bool} → (a && a && b) ≡ (a && b)
prop_and_cancel true = refl
prop_and_cancel false = refl
prop_or_assoc : (a b c : Bool) → ((a || b) || c) ≡ (a || (b || c))
prop_or_assoc true b c = refl
prop_or_assoc false b c = refl
prop_or_sym : (a b : Bool) → (a || b) ≡ (b || a)
prop_or_sym true true = refl
prop_or_sym true false = refl
prop_or_sym false true = refl
prop_or_sym false false = refl
prop_or_same_value : (a : Bool) → (a || a) ≡ a
prop_or_same_value true = refl
prop_or_same_value false = refl
prop_and_false : (a : Bool) → (a && false) ≡ false
prop_and_false true = refl
prop_and_false false = refl
prop_and_true : (a : Bool) → (a && true) ≡ a
prop_and_true true = refl
prop_and_true false = refl
prop_or_false : (a : Bool) → (false || a) ≡ a
prop_or_false true = refl
prop_or_false false = refl
prop_or_false2 : (a : Bool) → (a || false) ≡ a
prop_or_false2 true = refl
prop_or_false2 false = refl
prop_or_false3 : (a : Bool) → (a || true) ≡ true
prop_or_false3 true = refl
prop_or_false3 false = refl
prop_or_true : (a : Bool) → (true || a) ≡ true
prop_or_true true = refl
prop_or_true false = refl
prop_and_comm : (a b : Bool) → (a && b) ≡ (b && a)
prop_and_comm false b =
begin
(false && b)
=⟨⟩
false
=⟨ sym (prop_and_false b) ⟩
(b && false)
end
prop_and_comm true b =
begin
(true && b)
=⟨⟩
b
=⟨ sym (prop_and_true b) ⟩
(b && true)
end
prop_distr : (a b c : Bool) → ((a || b) && c) ≡ ((a && c) || (b && c))
prop_distr true b true = refl
prop_distr true true false = refl
prop_distr true false false = refl
prop_distr false true true = refl
prop_distr false true false = refl
prop_distr false false false = refl
prop_distr false false true = refl
prop_dnf : (a b c d : Bool) → ((a || b) && (c || d)) ≡ ((a && c) || (b && d) || (b && c) || (a && d))
prop_dnf true b true d = refl
prop_dnf true true false true = refl
prop_dnf true false false true = refl
prop_dnf true true false false = refl
prop_dnf true false false false = refl
prop_dnf false true true true = refl
prop_dnf false true false true = refl
prop_dnf false false true true = refl
prop_dnf false false true false = refl
prop_dnf false false false true = refl
prop_dnf false false false false = refl
prop_dnf false true true false = refl
prop_dnf false true false false = refl
prop_demorgan2 : (a b : Bool) → ((not a) && (not b)) ≡ (not (a || b))
prop_demorgan2 false b = refl
prop_demorgan2 true b = refl
prop_demorgan : (a b : Bool) → (not (a && b)) ≡ ((not a) || (not b))
prop_demorgan false b = refl
prop_demorgan true b = refl
not-not : (b : Bool) → b ≡ not (not b)
not-not false = refl
not-not true =
begin
not (not true)
=⟨⟩
not false
=⟨⟩
true
end
demorgan3 : (a b c d : Bool) → (not (a || b || c || d)) ≡ ((not a) && (not b) && (not c) && (not d))
demorgan3 true b c d = refl
demorgan3 false true c d = refl
demorgan3 false false true d = refl
demorgan3 false false false true = refl
demorgan3 false false false false = refl
|
{
"alphanum_fraction": 0.5587094988,
"avg_line_length": 30.6016949153,
"ext": "agda",
"hexsha": "2fd513ab257d4717418ccd1a42b40c298fdce162",
"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": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ioanasv/agda2hs",
"max_forks_repo_path": "lib/Haskell/RangedSetsProp/library.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"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": "ioanasv/agda2hs",
"max_issues_repo_path": "lib/Haskell/RangedSetsProp/library.agda",
"max_line_length": 168,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ioanasv/agda2hs",
"max_stars_repo_path": "lib/Haskell/RangedSetsProp/library.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:41:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:41:34.000Z",
"num_tokens": 2930,
"size": 7222
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Several kinds of "relatedness" for containers such as equivalences,
-- surjections and bijections
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Container.Related where
open import Level using (_⊔_)
open import Data.Container.Core
import Function.Related as Related
open import Relation.Binary
open import Data.Container.Membership
open Related public
using (Kind; Symmetric-kind)
renaming ( implication to subset
; reverse-implication to superset
; equivalence to set
; injection to subbag
; reverse-injection to superbag
; bijection to bag
)
[_]-Order : ∀ {s p ℓ} → Kind → Container s p → Set ℓ →
Preorder (s ⊔ p ⊔ ℓ) (s ⊔ p ⊔ ℓ) (p ⊔ ℓ)
[ k ]-Order C X = Related.InducedPreorder₂ k (_∈_ {C = C} {X = X})
[_]-Equality : ∀ {s p ℓ} → Symmetric-kind → Container s p → Set ℓ →
Setoid (s ⊔ p ⊔ ℓ) (p ⊔ ℓ)
[ k ]-Equality C X = Related.InducedEquivalence₂ k (_∈_ {C = C} {X = X})
infix 4 _∼[_]_
_∼[_]_ : ∀ {s p x} {C : Container s p} {X : Set x} →
⟦ C ⟧ X → Kind → ⟦ C ⟧ X → Set (p ⊔ x)
_∼[_]_ {C = C} {X} xs k ys = Preorder._∼_ ([ k ]-Order C X) xs ys
|
{
"alphanum_fraction": 0.5144927536,
"avg_line_length": 34.5,
"ext": "agda",
"hexsha": "0117335e355bd590c78d8dd1202fe346385f943b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Related.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Related.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Related.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": 404,
"size": 1380
}
|
{-# OPTIONS --without-K #-}
module EquivEquiv where
open import Level using (Level; _⊔_)
open import Data.Product using (_,_; proj₁; proj₂)
open import Data.Sum using (inj₁; inj₂)
open import Relation.Binary using (Setoid)
import Relation.Binary.PropositionalEquality as P
using (_≡_; refl; sym; trans; cong; module ≡-Reasoning)
import Relation.Binary.EqReasoning as EqR
open import Function using (id; _∘_)
open import Equiv
using (module isqinv; qinv; _≃_; id≃; sym≃; _●_;
_∼_; refl∼; sym∼; trans∼; cong∘r; cong∘l;
_⊎≃_; β₁; β₂; gg; β⊎₁; β⊎₂)
------------------------------------------------------------------------------
-- Extensional equivalence of equivalences
-- We need g to "pin down" the inverse, else we get lots of unsolved
-- metas.
infix 4 _≋_
record _≋_ {ℓ ℓ' : Level} {A : Set ℓ} {B : Set ℓ'} (eq₁ eq₂ : A ≃ B) :
Set (ℓ ⊔ ℓ') where
constructor eq
open isqinv
field
f≡ : proj₁ eq₁ ∼ proj₁ eq₂
g≡ : g (proj₂ eq₁) ∼ g (proj₂ eq₂)
-- the proof could use ∼-Reasoning if we had defined it
g≡′ : g (proj₂ eq₁) ∼ g (proj₂ eq₂)
g≡′ =
trans∼ (cong∘r g₁ (refl∼ {f = id})) ( -- id ∘ g₁
trans∼ (cong∘r g₁ (sym∼ (β (proj₂ eq₂))))
(trans∼ (cong∘l g₂ (cong∘r g₁ (sym∼ f≡))) (
(cong∘l g₂ (α (proj₂ eq₁))))))
where
g₁ = g (proj₂ eq₁)
g₂ = g (proj₂ eq₂)
f₁ = proj₁ eq₁
f₂ = proj₁ eq₂
-- The equivalence of equivalences is an equivalence relation that
-- respects composition
id≋ : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} {x : A ≃ B} → x ≋ x
id≋ = record { f≡ = λ _ → P.refl ; g≡ = λ _ → P.refl }
sym≋ : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} {x y : A ≃ B} → x ≋ y → y ≋ x
sym≋ (eq f≡ g≡) = eq (λ a → P.sym (f≡ a)) (λ b → P.sym (g≡ b))
flip≋ : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} {x y : A ≃ B} →
x ≋ y → (sym≃ x) ≋ (sym≃ y)
flip≋ (eq f≡ g≡) = eq g≡ f≡
flip-sym≋ : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} {x y : A ≃ B}→
x ≋ y → sym≃ y ≋ sym≃ x
flip-sym≋ (eq f≡ g≡) = eq (sym∼ g≡) (sym∼ f≡)
trans≋ : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} {x y z : A ≃ B} →
x ≋ y → y ≋ z → x ≋ z
trans≋ (eq f≡ g≡) (eq h≡ i≡) =
eq (λ a → P.trans (f≡ a) (h≡ a)) (λ b → P.trans (g≡ b) (i≡ b))
_◎_ : {A B C : Set} {f h : B ≃ C} {g i : A ≃ B} → f ≋ h → g ≋ i →
(f ● g) ≋ (h ● i)
_◎_ {f = f} {h} {g} {i}
(eq f≡ g≡) (eq h≡ i≡) = eq fwd bwd
-- eq (λ x → {!!} ) -- P.trans (P.cong f (h≡ x)) (f≡ (i x)))
-- (λ x → {!!} ) -- P.trans (P.cong g⁻¹ (g≡ x)) (i≡ (h⁻¹ x)))
where
open P.≡-Reasoning
fwd : proj₁ (f ● g) ∼ proj₁ (h ● i)
fwd x = begin (
proj₁ (f ● g) x
≡⟨ β₁ x ⟩
proj₁ f (proj₁ g x)
≡⟨ f≡ (proj₁ g x) ⟩
proj₁ h (proj₁ g x)
≡⟨ P.cong (proj₁ h) (h≡ x) ⟩
proj₁ h (proj₁ i x)
≡⟨ P.sym (β₁ x) ⟩
proj₁ (h ● i) x ∎)
bwd : gg (f ● g) ∼ gg (h ● i)
bwd x =
begin (
gg (f ● g) x
≡⟨ β₂ x ⟩
gg g (gg f x)
≡⟨ i≡ (gg f x) ⟩
gg i (gg f x)
≡⟨ P.cong (gg i) (g≡ x) ⟩
gg i (gg h x)
≡⟨ P.sym (β₂ x) ⟩
gg (h ● i) x ∎)
rinv≋ : ∀ {ℓ} {A B : Set ℓ} (x : A ≃ B) →
(x ● (sym≃ x)) ≋ id≃ {A = B}
rinv≋ (_ , qinv _ α _) = eq (trans∼ β₁ α) (trans∼ β₂ α)
linv≋ : ∀ {ℓ} {A B : Set ℓ} (e : A ≃ B) → ((sym≃ e) ● e) ≋ id≃
linv≋ (_ , qinv _ _ β) = eq (trans∼ β₁ β) (trans∼ β₂ β)
lid≋ : ∀ {ℓ} {A B : Set ℓ} {f : A ≃ B} → (id≃ ● f) ≋ f
lid≋ = eq β₁ β₂
rid≋ : ∀ {ℓ} {A B : Set ℓ} {f : A ≃ B} → (f ● id≃) ≋ f
rid≋ = eq β₁ β₂
--
{-
symsym : ∀ {A B : Set} {f : A ≃ B} → sym≃ (sym≃ f) ≋ f
symsym = eq (λ _ → P.refl) (λ _ → P.refl)
-}
sym≃● : ∀ {A B C : Set} {g : B ≃ C} {f : A ≃ B} →
sym≃ (g ● f) ≋ sym≃ f ● sym≃ g
sym≃● {g = (g , qinv g⁻¹ _ _)} {(f , qinv f⁻¹ _ _)} =
eq (trans∼ β₂ (sym∼ β₁)) (trans∼ β₁ (sym∼ β₂))
-- underlying it all, it uses ∘ and ≡, thus associativity is immediate
●-assoc : {A B C D : Set} {f : A ≃ B} {g : B ≃ C} {h : C ≃ D} →
((h ● g) ● f) ≋ (h ● (g ● f))
●-assoc {f = f} {g} {h} = eq fwd bwd
where
open P.≡-Reasoning
fwd : proj₁ ((h ● g) ● f) ∼ proj₁ (h ● (g ● f))
fwd x = begin (
proj₁ ((h ● g) ● f) x
≡⟨ β₁ x ⟩
proj₁ (h ● g) (proj₁ f x)
≡⟨ β₁ (proj₁ f x) ⟩
proj₁ h (proj₁ g (proj₁ f x))
≡⟨ P.cong (proj₁ h) (P.sym (β₁ x)) ⟩
proj₁ h (proj₁ (g ● f) x)
≡⟨ P.sym (β₁ x) ⟩
proj₁ (h ● (g ● f)) x ∎)
bwd : gg ((h ● g) ● f) ∼ gg (h ● (g ● f))
bwd x = begin (
gg ((h ● g) ● f) x
≡⟨ β₂ x ⟩
gg f (gg (h ● g) x)
≡⟨ P.cong (gg f) (β₂ x) ⟩
gg f (gg g (gg h x))
≡⟨ P.sym (β₂ (gg h x)) ⟩
gg (g ● f) (gg h x)
≡⟨ P.sym (β₂ x) ⟩
gg (h ● (g ● f)) x ∎)
●-assocl : {A B C D : Set} {f : A ≃ B} {g : B ≃ C} {h : C ≃ D} →
h ● (g ● f) ≋ (h ● g) ● f
●-assocl {f = f} {g} {h} = sym≋ (●-assoc {f = f} {g} {h})
-- The setoid of equivalences under ≋
_S≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Setoid (ℓ ⊔ ℓ') (ℓ ⊔ ℓ')
_S≃_ A B = record
{ Carrier = A ≃ B
; _≈_ = _≋_
; isEquivalence = record
{ refl = id≋
; sym = sym≋
; trans = trans≋
}
}
module ≋-Reasoning where
module _ {a b} {A : Set a} {B : Set b} where
open EqR (A S≃ B) public
hiding (_≡⟨_⟩_; _≡⟨⟩_) renaming (_≈⟨_⟩_ to _≋⟨_⟩_)
------------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.4287056171,
"avg_line_length": 29.087431694,
"ext": "agda",
"hexsha": "84e1e1123e6c00f6aefb0371d23548d7d24d9000",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/EquivEquiv.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/EquivEquiv.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/EquivEquiv.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 2579,
"size": 5323
}
|
module Cats.Functor where
open import Level
open import Relation.Binary using (_Preserves_⟶_)
open import Cats.Category.Base
open import Cats.Util.Function using () renaming (_∘_ to _⊙_)
open import Cats.Util.SetoidMorphism using (_⇒_ ; IsInjective ; IsSurjective)
open import Cats.Util.SetoidMorphism.Iso using
( IsIso ; _≅_ ; IsIso→≅ ; Injective∧Surjective→Iso ; Iso→Injective
; Iso→Surjective )
import Cats.Category.Constructions.Iso as Iso
open Iso.Build._≅_
infixr 9 _∘_
record Functor {lo la l≈ lo′ la′ l≈′}
(C : Category lo la l≈)
(D : Category lo′ la′ l≈′)
: Set (lo ⊔ la ⊔ l≈ ⊔ lo′ ⊔ la′ ⊔ l≈′) where
private
module C = Category C
module C≅ = Iso.Build C
module D = Category D
module D≅ = Iso.Build D
field
fobj : C.Obj → D.Obj
fmap : ∀ {A B} → A C.⇒ B → fobj A D.⇒ fobj B
fmap-resp : ∀ {A B} → fmap {A} {B} Preserves C._≈_ ⟶ D._≈_
fmap-id : ∀ {A} → fmap (C.id {A}) D.≈ D.id
fmap-∘ : ∀ {A B C} {f : B C.⇒ C} {g : A C.⇒ B}
→ fmap f D.∘ fmap g D.≈ fmap (f C.∘ g)
sfmap : ∀ {a b} → C.Hom a b ⇒ D.Hom (fobj a) (fobj b)
sfmap = record
{ arr = fmap
; resp = fmap-resp
}
fobj-resp : fobj Preserves C≅._≅_ ⟶ D≅._≅_
fobj-resp {i} {j} x≅y
= record
{ forth = fmap (forth x≅y)
; back = fmap (back x≅y)
; back-forth
= begin
fmap (back x≅y) D.∘ fmap (forth x≅y)
≈⟨ fmap-∘ ⟩
fmap (back x≅y C.∘ forth x≅y)
≈⟨ fmap-resp (back-forth x≅y) ⟩
fmap C.id
≈⟨ fmap-id ⟩
D.id
∎
; forth-back
= begin
fmap (forth x≅y) D.∘ fmap (back x≅y)
≈⟨ fmap-∘ ⟩
fmap (forth x≅y C.∘ back x≅y)
≈⟨ fmap-resp (forth-back x≅y) ⟩
fmap C.id
≈⟨ fmap-id ⟩
D.id
∎
}
where
open D.≈-Reasoning
open Functor public
id : ∀ {lo la l≈} {C : Category lo la l≈} → Functor C C
id {C = C} = record
{ fobj = λ x → x
; fmap = λ f → f
; fmap-resp = λ eq → eq
; fmap-id = C.≈.refl
; fmap-∘ = C.≈.refl
}
where
module C = Category C
_∘_ : ∀ {lo la l≈ lo′ la′ l≈′ lo″ la″ l≈″}
→ {C : Category lo la l≈}
→ {D : Category lo′ la′ l≈′}
→ {E : Category lo″ la″ l≈″}
→ Functor D E → Functor C D → Functor C E
_∘_ {E = E} F G = record
{ fobj = fobj F ⊙ fobj G
; fmap = fmap F ⊙ fmap G
; fmap-resp = fmap-resp F ⊙ fmap-resp G
; fmap-id = E.≈.trans (fmap-resp F (fmap-id G)) (fmap-id F)
; fmap-∘ = E.≈.trans (fmap-∘ F) (fmap-resp F (fmap-∘ G))
}
where
module E = Category E
module _ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈} {D : Category lo′ la′ l≈′}
(F : Functor C D)
where
private
module C = Category C
module D = Category D
IsFaithful : Set (lo ⊔ la ⊔ l≈ ⊔ l≈′)
IsFaithful = ∀ {a b} → IsInjective (sfmap F {a} {b})
IsFull : Set (lo ⊔ la ⊔ la′ ⊔ l≈′)
IsFull = ∀ {a b} → IsSurjective (sfmap F {a} {b})
IsEmbedding : Set (lo ⊔ la ⊔ l≈ ⊔ la′ ⊔ l≈′)
IsEmbedding = ∀ {a b} → IsIso (sfmap F {a} {b})
Embedding→≅ : IsEmbedding → ∀ {a b} → C.Hom a b ≅ D.Hom (fobj F a) (fobj F b)
Embedding→≅ embedding = IsIso→≅ (sfmap F) embedding
Full∧Faithful→Embedding : IsFull → IsFaithful → IsEmbedding
Full∧Faithful→Embedding full faithful
= Injective∧Surjective→Iso faithful full
Embedding→Full : IsEmbedding → IsFull
Embedding→Full embedding = Iso→Surjective embedding
Embedding→Faithful : IsEmbedding → IsFaithful
Embedding→Faithful embedding = Iso→Injective embedding
|
{
"alphanum_fraction": 0.5376254181,
"avg_line_length": 24.9166666667,
"ext": "agda",
"hexsha": "6d6d7d8e64d3a3b1ef480e53b1a39b839358b176",
"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": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Functor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"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": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Functor.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Functor.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1457,
"size": 3588
}
|
{-# OPTIONS --prop --without-K --rewriting #-}
-- Step effect.
open import Calf.CostMonoid
module Calf.Step (costMonoid : CostMonoid) where
open CostMonoid costMonoid
open import Calf.Prelude
open import Calf.Metalanguage
open import Calf.PhaseDistinction
open import Relation.Binary.PropositionalEquality
cost : tp neg
cost = meta ℂ
postulate
step : ∀ (B : tp neg) → cmp cost → cmp B → cmp B
step/id : ∀ {B : tp neg} {e : cmp B} →
step B zero e ≡ e
{-# REWRITE step/id #-}
step/concat : ∀ {B e p q} →
step B p (step B q e) ≡ step B (p + q) e
{-# REWRITE step/concat #-}
U_step : ∀ {A} {X : val A → tp neg} {e n} → U (tbind {A} (step (F A) n e) X) ≡ U (tbind {A} e X)
{-# REWRITE U_step #-}
Π/step : ∀ {A} {X : val A → tp neg} {f : cmp (Π A X)} {n} → step (Π A X) n f ≡ λ x → step (X x) n (f x)
{-# REWRITE Π/step #-}
bind/step : ∀ {A} {X} {e f n} → bind {A} X (step (F A) n e) f ≡ step X n (bind {A} X e f)
dbind/step : ∀ {A} {X : val A → tp neg} {e f n} → dbind {A} X (step (F A) n e) f ≡ step (tbind {A} e X) n (dbind {A} X e f)
{-# REWRITE bind/step dbind/step #-}
step/ext : ∀ X → (e : cmp X) → (c : ℂ) → ◯ (step X c e ≡ e)
-- sadly the above cannot be made an Agda rewrite rule
|
{
"alphanum_fraction": 0.5662063363,
"avg_line_length": 30.775,
"ext": "agda",
"hexsha": "da25f2be68908437b2f9aeda00bbea4f56949afb",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Calf/Step.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Calf/Step.agda",
"max_line_length": 125,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Calf/Step.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 491,
"size": 1231
}
|
open import Prelude hiding (module Fin) renaming (_≟_ to _N≟_)
module Implicits.Syntax.Type where
open import Data.Fin.Substitution
open import Data.Nat.Properties as NatProps
open import Data.Star using (Star; ε; _◅_)
open import Data.List
open import Data.List.All hiding (map)
open import Data.Maybe hiding (map; All)
open import Data.Product hiding (map)
open import Data.Fin as Fin hiding (_+_)
open import Data.Fin.Properties as FinProp using ()
open import Extensions.Nat
import Data.Vec
infixr 10 _→'_
infixr 10 _⇒_
mutual
data SimpleType (ν : ℕ) : Set where
tc : ℕ → SimpleType ν
tvar : (n : Fin ν) → SimpleType ν
_→'_ : Type ν → Type ν → SimpleType ν
data Type (ν : ℕ) : Set where
simpl : SimpleType ν → Type ν
_⇒_ : Type ν → Type ν → Type ν
∀' : Type (suc ν) → Type ν
TVar : ∀ {ν} → Fin ν → Type ν
TVar = simpl ∘ tvar
TC : ∀ {ν} → ℕ → Type ν
TC = simpl ∘ tc
is-∀' : ∀ {ν} → Type ν → Set
is-∀' (simpl x) = ⊥
is-∀' (_ ⇒ _) = ⊥
is-∀' (∀' x) = ⊤
fvars : ∀ {ν} → Type ν → List (Fin ν)
fvars (simpl (tc x)) = List.[]
fvars (simpl (tvar n)) = n List.∷ List.[]
fvars (simpl (x →' y)) = fvars x ++ fvars y
fvars (a ⇒ b) = fvars a ++ fvars b
fvars (∀' a) = gfilter (λ{ (Fin.zero) → nothing; (suc n) → just n}) (fvars a)
occ : ∀ {ν} → ℕ → Type ν → ℕ
occ α (simpl (tc x)) = 0
occ α (simpl (tvar n)) with α N≟ (toℕ n)
occ α (simpl (tvar n)) | yes p = 1
occ α (simpl (tvar n)) | no ¬p = 0
occ α (simpl (a →' b)) = occ α a + occ α b
occ α (a ⇒ b) = occ α a + occ α b
occ α (∀' b) = occ α b
module Functions where
-- proposition that states that the given polytype
-- is a (possibly polymorphic) function
data IsFunction {ν : ℕ} : Type ν → Set where
lambda : (a b : Type ν) → IsFunction (simpl $ a →' b)
∀'-lambda : ∀ {f} → IsFunction f → IsFunction (∀' f)
-- decision procedure for IsFunction
is-function : ∀ {ν} → (a : Type ν) → Dec (IsFunction a)
is-function (simpl (tc _)) = no (λ ())
is-function (simpl (tvar n)) = no (λ ())
is-function (simpl (a →' b)) = yes (lambda a b)
is-function (x ⇒ x₁) = no (λ ())
is-function (∀' a) with is-function a
is-function (∀' a) | yes a-is-f = yes $ ∀'-lambda a-is-f
is-function (∀' a) | no a-not-f = no (λ{ (∀'-lambda a-is-f) → a-not-f a-is-f })
domain : ∀ {ν} {f : Type ν} → IsFunction f → Type ν
domain (lambda a b) = a
domain (∀'-lambda f) = ∀' (domain f)
codomain : ∀ {ν} {f : Type ν} → IsFunction f → Type ν
codomain (lambda a b) = b
codomain (∀'-lambda f) = ∀' (codomain f)
module Rules where
-- proposition that states that the given polytype
-- is a (possibly polymorphic) rule type
data IsRule {ν : ℕ} : Type ν → Set where
rule : (a b : Type ν) → IsRule (a ⇒ b)
∀'-rule : ∀ {f} → IsRule f → IsRule (∀' f)
-- decision procedure for IsRule
is-rule : ∀ {ν} → (a : Type ν) → Dec (IsRule a)
is-rule (simpl (tc _)) = no (λ ())
is-rule (simpl (tvar n)) = no (λ ())
is-rule (simpl (a →' b)) = no (λ ())
is-rule (a ⇒ b) = yes (rule a b)
is-rule (∀' a) with is-rule a
is-rule (∀' a) | yes a-is-f = yes $ ∀'-rule a-is-f
is-rule (∀' a) | no a-not-f = no (λ{ (∀'-rule a-is-f) → a-not-f a-is-f })
domain : ∀ {ν} {f : Type ν} → IsRule f → Type ν
domain (rule a b) = a
domain (∀'-rule f) = ∀' (domain f)
codomain : ∀ {ν} {f : Type ν} → IsRule f → Type ν
codomain (rule a b) = b
codomain (∀'-rule f) = ∀' (codomain f)
to-function : ∀ {ν} {f : Type ν} → IsRule f → Type ν
to-function (rule a b) = simpl (a →' b)
to-function (∀'-rule f) = ∀' (to-function f)
-- decidable equality on types
_≟_ : ∀ {ν} → (a b : Type ν) → Dec (a ≡ b)
simpl (tc x) ≟ simpl (tc y) with x N≟ y
simpl (tc x) ≟ simpl (tc y) | yes p = yes (cong (simpl ∘ tc) p)
simpl (tc x) ≟ simpl (tc y) | no ¬p = no (λ x=y → ¬p $ helper x=y )
where
helper : ∀ {x y} → (simpl (tc x)) ≡ (simpl (tc y)) → x ≡ y
helper refl = refl
simpl (tc x) ≟ simpl (tvar n) = no (λ ())
simpl (tc x) ≟ simpl (x₁ →' x₂) = no (λ ())
simpl (tvar n) ≟ simpl (tc x) = no (λ ())
simpl (tvar n) ≟ simpl (tvar m) with n FinProp.≟ m
simpl (tvar n) ≟ simpl (tvar m) | yes n≡m = yes (cong (simpl ∘ tvar) n≡m)
simpl (tvar n) ≟ simpl (tvar m) | no n≢m = no (λ x=y → n≢m $ helper x=y)
where
helper : ∀ {n m} → (simpl (tvar n)) ≡ (simpl (tvar m)) → n ≡ m
helper refl = refl
simpl (tvar n) ≟ simpl (x →' x₁) = no (λ ())
simpl (a →' b) ≟ simpl (tc x₂) = no (λ ())
simpl (a →' b) ≟ simpl (tvar n) = no (λ ())
simpl (a →' b) ≟ simpl (a' →' b') with a ≟ a' | b ≟ b'
simpl (a →' b) ≟ simpl (a' →' b') | yes p | yes q = yes (cong₂ (λ u v → simpl $ u →' v) p q)
simpl (a →' b) ≟ simpl (a' →' b') | yes p | no ¬q = no (λ x → ¬q (helper x) )
where
helper : ∀ {a b a' b'} → (simpl $ a →' b) ≡ (simpl $ a' →' b') → b ≡ b'
helper refl = refl
simpl (a →' b) ≟ simpl (a' →' b') | no ¬p | _ = no (λ x → ¬p (helper x) )
where
helper : ∀ {a b a' b'} → (simpl $ a →' b) ≡ (simpl $ a' →' b') → a ≡ a'
helper refl = refl
simpl (tc x) ≟ (b ⇒ b₁) = no (λ ())
simpl (tvar n) ≟ (b ⇒ b₁) = no (λ ())
simpl (x →' x₁) ≟ (b ⇒ b₁) = no (λ ())
simpl (tc x) ≟ ∀' b = no (λ ())
simpl (tvar n) ≟ ∀' b = no (λ ())
simpl (x →' x₁) ≟ ∀' b = no (λ ())
(a ⇒ b) ≟ simpl x = no (λ ())
(a ⇒ b) ≟ (a' ⇒ b') with a ≟ a' | b ≟ b'
(a ⇒ b) ≟ (a' ⇒ b') | yes p | yes q = yes (cong₂ (λ u v → u ⇒ v) p q)
(a ⇒ b) ≟ (a' ⇒ b') | yes p | no ¬q = no (λ x → ¬q (helper x) )
where
helper : ∀ {a b a' b'} → (a ⇒ b) ≡ (a' ⇒ b') → b ≡ b'
helper refl = refl
(a ⇒ b) ≟ (a' ⇒ b') | no ¬p | _ = no (λ x → ¬p (helper x) )
where
helper : ∀ {a b a' b'} → (a ⇒ b) ≡ (a' ⇒ b') → a ≡ a'
helper refl = refl
(a ⇒ a₁) ≟ ∀' b = no (λ ())
∀' a ≟ simpl x = no (λ ())
∀' a ≟ (b ⇒ b₁) = no (λ ())
∀' a ≟ ∀' b with a ≟ b
∀' a ≟ ∀' b | yes p = yes (cong ∀' p)
∀' a ≟ ∀' b | no ¬p = no (λ u → ¬p (helper u))
where
helper : ∀ {ν} {a b : Type (suc ν)} → ∀' a ≡ ∀' b → a ≡ b
helper refl = refl
-- 'head' of the context type
_◁ : ∀ {ν} → Type ν → ∃ λ μ → Type μ
simpl x ◁ = , simpl x
(a ⇒ b) ◁ = b ◁
∀' a ◁ = a ◁
mutual
data occ' {ν} : Fin ν → Type ν → Set where
⇒-left : ∀ {n a b} → (occ' n a) → occ' n (a ⇒ b)
⇒-right : ∀ {n a b} → (occ' n b) → occ' n (a ⇒ b)
∀' : ∀ {a n} → (occ' (suc n) a) → occ' n (∀' a)
data occS {ν} : Fin ν → SimpleType ν → Set where
tvar : (n : Fin ν) → occS n (tvar n)
→'-left : ∀ {n a b} → (occ' n a) → occS n (a →' b)
→'-right : ∀ {n a b} → (occ' n b) → occS n (a →' b)
data _⊢unamb_ {ν} : List (Fin ν) → Type ν → Set where
ua-simp : ∀ l {τ} → All (λ e → occS e τ) l → l ⊢unamb (simpl τ)
ua-iabs : ∀ {l a b} → l ⊢unamb b → [] ⊢unamb a → l ⊢unamb (a ⇒ b)
ua-tabs : ∀ {l} {a : Type (suc ν)} → (zero List.∷ (map suc l)) ⊢unamb a →
l ⊢unamb (∀' a)
module unamb-test where
x : Type 1
x = ∀' (simpl (tvar zero))
px : [] ⊢unamb x
px = ua-tabs (ua-simp (zero ∷ []) (tvar zero All.∷ All.[]))
y : Type 1
y = ∀' (simpl (tvar (suc zero)))
¬py : ¬ ([] ⊢unamb y)
¬py (ua-tabs (ua-simp .(zero ∷ []) (() All.∷ x)))
z : Type 1
z = ∀' (β ⇒ α)
where
α = (simpl (tvar zero))
β = (simpl (tvar (suc zero)))
pz : [] ⊢unamb z
pz = ua-tabs
(ua-iabs (ua-simp (zero ∷ []) (tvar zero All.∷ All.[]))
(ua-simp [] All.[]))
z' : Type 1
z' = ∀' (α ⇒ β)
where
α = (simpl (tvar zero))
β = (simpl (tvar (suc zero)))
¬pz' : ¬ ([] ⊢unamb z')
¬pz' (ua-tabs (ua-iabs (ua-simp .(zero ∷ []) (() All.∷ pxs)) x₁))
read∘show : Type 1
read∘show = ∀' ((simpl (string →' α)) ⇒ ((simpl (α →' string)) ⇒ (simpl (string →' string))))
where
α = (simpl (tvar zero))
string = (simpl (tvar (suc zero)))
¬pread∘show : ¬ [] ⊢unamb read∘show
¬pread∘show (ua-tabs (ua-iabs (ua-iabs (ua-simp .(zero ∷ []) (→'-left () All.∷ _)) _) _))
¬pread∘show (ua-tabs (ua-iabs (ua-iabs (ua-simp .(zero ∷ []) (→'-right () All.∷ _)) _) _))
open unamb-test
|
{
"alphanum_fraction": 0.5008224725,
"avg_line_length": 32.7925311203,
"ext": "agda",
"hexsha": "f0aa126ed630737a4ddeaecb545935814a3b1420",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Syntax/Type.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Syntax/Type.agda",
"max_line_length": 95,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Syntax/Type.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 3373,
"size": 7903
}
|
module Lectures.Three where
open import Lectures.One
open import Lectures.Two
-- Introduce propositional equality
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
-- Comment on precendences
infix 10 _≡_
record Equivalence (_~_ : ∀ {A : Set} → A → A → Set) : Set₁ where
field
reflexive : ∀ {A} {a : A} → a ~ a
symmetric : ∀ {A} {a b : A} → a ~ b → b ~ a
transitive : ∀ {A} {a b c : A} → a ~ b → b ~ c → a ~ c
open Equivalence
sym : ∀ {A} {a b : A} → a ≡ b → b ≡ a
sym refl = refl
trans : ∀ {A} {a b c : A} → a ≡ b → b ≡ c → a ≡ c
trans refl refl = refl
-- Comment on copatterns
≡-Equivalence : Equivalence _≡_
reflexive ≡-Equivalence = refl
symmetric ≡-Equivalence = sym
transitive ≡-Equivalence = trans
cong : ∀ {A B} {a b : A} → (f : A → B) → a ≡ b → f a ≡ f b
cong f refl = refl
-- Leibniz equality?
subst : ∀ {A} {x y : A} {P : A → Set} → P x → x ≡ y → P y
subst p refl = p
_ : _+_ ≡ _+_
_ = refl
-- _ : _+_ ≡ λ x y → y + x
-- _ = {!refl!}
-- Comment on postulates
postulate
extensionality : {A B : Set} {f g : A → B} → (∀ x → f x ≡ g x) → f ≡ g
+-idʳ : ∀ x → x ≡ x + 0
+-idʳ zero = refl
+-idʳ (suc x) = cong suc (+-idʳ _)
+-suc : ∀ x y → suc (x + y) ≡ x + suc y
+-suc zero y = refl
+-suc (suc x) y = cong suc (+-suc _ _)
+-comm : ∀ x y → x + y ≡ y + x
+-comm zero y = +-idʳ _
+-comm (suc x) y = trans (cong suc (+-comm x y)) (+-suc _ _)
+-assoc : ∀ x y z → x + (y + z) ≡ (x + y) + z
+-assoc zero y z = refl
+-assoc (suc x) y z = cong suc (+-assoc x y z)
|
{
"alphanum_fraction": 0.5225048924,
"avg_line_length": 22.5441176471,
"ext": "agda",
"hexsha": "c4f26ccf189349bdecf799194b0c1e0f4ff079bb",
"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": "d9359c5bfd0eaf69efe1113945d7f3145f6b2dff",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "UoG-Agda/Agda101",
"max_forks_repo_path": "Lectures/Three.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9359c5bfd0eaf69efe1113945d7f3145f6b2dff",
"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": "UoG-Agda/Agda101",
"max_issues_repo_path": "Lectures/Three.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d9359c5bfd0eaf69efe1113945d7f3145f6b2dff",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UoG-Agda/Agda101",
"max_stars_repo_path": "Lectures/Three.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 659,
"size": 1533
}
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.Support.SetoidFunctions where
open import Level
open import Function using (_on_)
open import Relation.Binary as B using (_=[_]⇒_)
open import Relation.Binary.PropositionalEquality using () renaming (cong to ≡-cong; cong₂ to ≡-cong₂)
open import Data.Product using (<_,_>; _×_; _,_)
open import Categories.Support.Equivalence
infixr 0 _⟶_
record _⟶_ {cf ℓf ct ℓt} (From : Setoid cf ℓf) (To : Setoid ct ℓt) :
Set (cf ⊔ ℓf ⊔ ct ⊔ ℓt) where
infixl 5 _⟨$⟩_
field
_⟨$⟩_ : (x : Setoid.Carrier From) → Setoid.Carrier To
.cong : Setoid._≈_ From =[ _⟨$⟩_ ]⇒ Setoid._≈_ To
open _⟶_ public
id : ∀ {a₁ a₂} {A : Setoid a₁ a₂} → A ⟶ A
id = record { _⟨$⟩_ = Function.id; cong = Function.id }
infixr 9 _∙_
_∙_ : ∀ {ca ℓa} {A : Setoid ca ℓa}
{cb ℓb} {B : Setoid cb ℓb}
{cc ℓc} {C : Setoid cc ℓc} →
B ⟶ C → A ⟶ B → A ⟶ C
f ∙ g = record
{ _⟨$⟩_ = Function._∘_ (_⟨$⟩_ f) (_⟨$⟩_ g)
; cong = Function._∘_ (cong f) (cong g)
}
const : ∀ {ca ℓa} {A : Setoid ca ℓa}
{cb ℓb} {B : Setoid cb ℓb} →
Setoid.Carrier B → A ⟶ B
const {B = B} b = record
{ _⟨$⟩_ = Function.const b
; cong = Function.const (Setoid.refl B)
}
→-to-⟶ : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → (set→setoid A ⟶ set→setoid B)
→-to-⟶ f = record { _⟨$⟩_ = f; cong = ≡-cong f }
------------------------------------------------------------------------
-- Function setoids
setoid : ∀ {cf ℓf ct ℓt}
(From : Setoid cf ℓf) →
Setoid ct ℓt →
Setoid _ _
setoid From To = record
{ Carrier = From ⟶ To
; _≈_ = λ f g → ∀ {x y} → x ≈₁ y → f ⟨$⟩ x ≈₂ g ⟨$⟩ y
; isEquivalence = record
{ refl = λ {f} → cong f
; sym = λ f∼g x∼y → To.sym (f∼g (From.sym x∼y))
; trans = λ f∼g g∼h x∼y → To.trans (f∼g From.refl) (g∼h x∼y)
}
}
where
open module From = Setoid From using () renaming (_≈_ to _≈₁_)
open module To = Setoid To using () renaming (_≈_ to _≈₂_)
infixr 0 _⇨_
_⇨_ : ∀ {cf ℓf ct ℓt} → Setoid cf ℓf → Setoid ct ℓt → Setoid _ _
From ⇨ To = setoid From To
⟪_,_⟫ : ∀ {cf ℓf ct₁ ℓt₁ ct₂ ℓt₂} {From : Setoid cf ℓf} {To₁ : Setoid ct₁ ℓt₁} {To₂ : Setoid ct₂ ℓt₂} (f₁ : From ⟶ To₁) (f₂ : From ⟶ To₂) → (From ⟶ (To₁ ×-setoid To₂))
⟪ f₁ , f₂ ⟫ = record { _⟨$⟩_ = < (_⟨$⟩_ f₁) , (_⟨$⟩_ f₂) >
; cong = < cong f₁ , cong f₂ > }
⟪_,_⟫′ : ∀ {cf ℓf ct₁ ct₂} {From : Setoid cf ℓf} {To₁ : Set ct₁} {To₂ : Set ct₂} (f₁ : From ⟶ set→setoid To₁) (f₂ : From ⟶ set→setoid To₂) → (From ⟶ set→setoid (To₁ × To₂))
⟪ f₁ , f₂ ⟫′ = record { _⟨$⟩_ = < (_⟨$⟩_ f₁) , (_⟨$⟩_ f₂) >
; cong = λ x≈y → ≡-cong₂ _,_ (cong f₁ x≈y) (cong f₂ x≈y) }
|
{
"alphanum_fraction": 0.522945966,
"avg_line_length": 33.775,
"ext": "agda",
"hexsha": "c8c0d4a69dd2004ca67b446fd9440240622afcf1",
"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/Support/SetoidFunctions.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/Support/SetoidFunctions.agda",
"max_line_length": 172,
"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/Support/SetoidFunctions.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": 1203,
"size": 2702
}
|
{-# OPTIONS --without-K --exact-split --safe #-}
module Fragment.Equational.Theory.Base where
open import Function using (_∘_)
open import Fragment.Algebra.Signature
open import Fragment.Algebra.Free
open import Fragment.Algebra.Algebra
open import Fragment.Algebra.Properties
open import Data.Nat using (ℕ)
open import Data.Fin using (Fin)
open import Data.Product using (_×_; map)
Eq : (Σ : Signature) → (n : ℕ) → Set
Eq Σ n = ∥ F Σ n ∥ × ∥ F Σ n ∥
record Theory : Set₁ where
field
Σ : Signature
eqs : ℕ → Set
_⟦_⟧ₑ : ∀ {arity} → eqs arity → Eq Σ arity
open Signature Σ
open Theory public
data ExtendedEq (Θ : Theory) (E : ℕ → Set) : ℕ → Set where
newₑ : ∀ {n} → E n → ExtendedEq Θ E n
oldₑ : ∀ {n} → eqs Θ n → ExtendedEq Θ E n
_⦅_⦆ₒ : (Θ : Theory) → (O : ℕ → Set) → Theory
Θ ⦅ O ⦆ₒ = record { Σ = (Σ Θ) ⦅ O ⦆
; eqs = eqs Θ
; _⟦_⟧ₑ = (map extend extend) ∘ Θ ⟦_⟧ₑ
}
_⦅_/_⦆ : (Θ : Theory)
→ (E : ℕ → Set)
→ (∀ {n} → E n → Eq (Σ Θ) n)
→ Theory
Θ ⦅ E / ⟦_⟧' ⦆ = record { Σ = Σ Θ
; eqs = ExtendedEq Θ E
; _⟦_⟧ₑ = withE
}
where withE : ∀ {n} → ExtendedEq Θ E n → Eq (Σ Θ) n
withE (newₑ eq) = ⟦ eq ⟧'
withE (oldₑ eq) = Θ ⟦ eq ⟧ₑ
_⦅_∣_/_⦆ : (Θ : Theory)
→ (O : ℕ → Set)
→ (E : ℕ → Set)
→ (∀ {n} → E n → Eq ((Σ Θ) ⦅ O ⦆) n)
→ Theory
Θ ⦅ O ∣ E / ⟦_⟧' ⦆ = (Θ ⦅ O ⦆ₒ) ⦅ E / ⟦_⟧' ⦆
|
{
"alphanum_fraction": 0.4765625,
"avg_line_length": 26.9473684211,
"ext": "agda",
"hexsha": "cfc59a92de92477a42e02e1141f1c965ae6006ca",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Equational/Theory/Base.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Equational/Theory/Base.agda",
"max_line_length": 58,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Equational/Theory/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 639,
"size": 1536
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Group.Algebra where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Function using (_∘_)
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Sigma
open import Cubical.Data.Unit
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Algebra.Group.Morphism
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.HITs.PropositionalTruncation hiding (map)
open Iso
open GroupHom
private
variable
ℓ ℓ' ℓ₁ ℓ₂ ℓ₃ : Level
------- elementary properties of morphisms --------
module _ (G : Group {ℓ}) (H : Group {ℓ'}) where
module G = GroupStr (snd G)
module H = GroupStr (snd H)
-0≡0 : G.- G.0g ≡ G.0g
-0≡0 = sym (G.lid _) ∙ G.invr _
-- ϕ(0) ≡ 0
morph0→0 : (f : GroupHom G H) → f .fun G.0g ≡ H.0g
morph0→0 fh@(grouphom f _) =
f G.0g ≡⟨ sym (H.rid _) ⟩
f G.0g H.+ H.0g ≡⟨ (λ i → f G.0g H.+ H.invr (f G.0g) (~ i)) ⟩
f G.0g H.+ (f G.0g H.- f G.0g) ≡⟨ H.assoc _ _ _ ⟩
(f G.0g H.+ f G.0g) H.- f G.0g ≡⟨ sym (cong (λ x → x H.+ (H.- f G.0g))
(sym (cong f (G.lid _)) ∙ isHom fh G.0g G.0g)) ⟩
f G.0g H.- f G.0g ≡⟨ H.invr _ ⟩
H.0g ∎
-- ϕ(- x) = - ϕ(x)
morphMinus : (f : GroupHom G H) → (g : ⟨ G ⟩) → f .fun (G.- g) ≡ H.- (f .fun g)
morphMinus fc@(grouphom f fh) g =
f (G.- g) ≡⟨ sym (H.rid _) ⟩
f (G.- g) H.+ H.0g ≡⟨ cong (f (G.- g) H.+_) (sym (H.invr _)) ⟩
f (G.- g) H.+ (f g H.- f g) ≡⟨ H.assoc _ _ _ ⟩
(f (G.- g) H.+ f g) H.- f g ≡⟨ cong (H._+ (H.- f g)) helper ⟩
H.0g H.- f g ≡⟨ H.lid _ ⟩
H.- f g ∎
where
helper : f (G.- g) H.+ f g ≡ H.0g
helper = sym (fh (G.- g) g) ∙∙ cong f (G.invl g) ∙∙ morph0→0 fc
-- ----------- Alternative notions of isomorphisms --------------
record GroupIso {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where
constructor iso
field
map : GroupHom G H
inv : ⟨ H ⟩ → ⟨ G ⟩
rightInv : section (GroupHom.fun map) inv
leftInv : retract (GroupHom.fun map) inv
record BijectionIso {ℓ ℓ'} (A : Group {ℓ}) (B : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where
constructor bij-iso
field
map' : GroupHom A B
inj : isInjective A B map'
surj : isSurjective A B map'
-- "Very" short exact sequences
-- i.e. an exact sequence A → B → C → D where A and D are trivial
record vSES {ℓ ℓ' ℓ'' ℓ'''} (A : Group {ℓ}) (B : Group {ℓ'}) (leftGr : Group {ℓ''}) (rightGr : Group {ℓ'''})
: Type (ℓ-suc (ℓ-max ℓ (ℓ-max ℓ' (ℓ-max ℓ'' ℓ''')))) where
constructor ses
field
isTrivialLeft : isProp ⟨ leftGr ⟩
isTrivialRight : isProp ⟨ rightGr ⟩
left : GroupHom leftGr A
right : GroupHom B rightGr
ϕ : GroupHom A B
Ker-ϕ⊂Im-left : (x : ⟨ A ⟩)
→ isInKer A B ϕ x
→ isInIm leftGr A left x
Ker-right⊂Im-ϕ : (x : ⟨ B ⟩)
→ isInKer B rightGr right x
→ isInIm A B ϕ x
open BijectionIso
open GroupIso
open vSES
Iso+Hom→GrIso : {G : Group {ℓ}} {H : Group {ℓ₁}} → (e : Iso ⟨ G ⟩ ⟨ H ⟩) → isGroupHom G H (Iso.fun e) → GroupIso G H
fun (map (Iso+Hom→GrIso e hom)) = Iso.fun e
isHom (map (Iso+Hom→GrIso e hom)) = hom
inv (Iso+Hom→GrIso e hom) = Iso.inv e
rightInv (Iso+Hom→GrIso e hom) = Iso.rightInv e
leftInv (Iso+Hom→GrIso e hom) = Iso.leftInv e
compGroupIso : {G : Group {ℓ}} {H : Group {ℓ₁}} {A : Group {ℓ₂}} → GroupIso G H → GroupIso H A → GroupIso G A
map (compGroupIso iso1 iso2) = compGroupHom (map iso1) (map iso2)
inv (compGroupIso iso1 iso2) = inv iso1 ∘ inv iso2
rightInv (compGroupIso iso1 iso2) a = cong (fun (map iso2)) (rightInv iso1 _) ∙ rightInv iso2 a
leftInv (compGroupIso iso1 iso2) a = cong (inv iso1) (leftInv iso2 _) ∙ leftInv iso1 a
isGroupHomInv' : {G : Group {ℓ}} {H : Group {ℓ₁}} (f : GroupIso G H) → isGroupHom H G (inv f)
isGroupHomInv' {G = G} {H = H} f h h' = isInj-f _ _ (
f' (g (h ⋆² h')) ≡⟨ (rightInv f) _ ⟩
(h ⋆² h') ≡⟨ sym (cong₂ _⋆²_ (rightInv f h) (rightInv f h')) ⟩
(f' (g h) ⋆² f' (g h')) ≡⟨ sym (isHom (map f) _ _) ⟩
f' (g h ⋆¹ g h') ∎)
where
f' = fun (map f)
_⋆¹_ = GroupStr._+_ (snd G)
_⋆²_ = GroupStr._+_ (snd H)
g = inv f
isInj-f : (x y : ⟨ G ⟩) → f' x ≡ f' y → x ≡ y
isInj-f x y p = sym (leftInv f _) ∙∙ cong g p ∙∙ leftInv f _
invGroupIso : {G : Group {ℓ}} {H : Group {ℓ₁}} → GroupIso G H → GroupIso H G
fun (map (invGroupIso iso1)) = inv iso1
isHom (map (invGroupIso iso1)) = isGroupHomInv' iso1
inv (invGroupIso iso1) = fun (map iso1)
rightInv (invGroupIso iso1) = leftInv iso1
leftInv (invGroupIso iso1) = rightInv iso1
dirProdGroupIso : {G : Group {ℓ}} {H : Group {ℓ₁}} {A : Group {ℓ₂}} {B : Group {ℓ₃}}
→ GroupIso G H → GroupIso A B → GroupIso (dirProd G A) (dirProd H B)
fun (map (dirProdGroupIso iso1 iso2)) prod = fun (map iso1) (fst prod) , fun (map iso2) (snd prod)
isHom (map (dirProdGroupIso iso1 iso2)) a b = ΣPathP (isHom (map iso1) (fst a) (fst b) , isHom (map iso2) (snd a) (snd b))
inv (dirProdGroupIso iso1 iso2) prod = (inv iso1) (fst prod) , (inv iso2) (snd prod)
rightInv (dirProdGroupIso iso1 iso2) a = ΣPathP (rightInv iso1 (fst a) , (rightInv iso2 (snd a)))
leftInv (dirProdGroupIso iso1 iso2) a = ΣPathP (leftInv iso1 (fst a) , (leftInv iso2 (snd a)))
GrIsoToGrEquiv : {G : Group {ℓ}} {H : Group {ℓ₂}} → GroupIso G H → GroupEquiv G H
GroupEquiv.eq (GrIsoToGrEquiv i) = isoToEquiv (iso (fun (map i)) (inv i) (rightInv i) (leftInv i))
GroupEquiv.isHom (GrIsoToGrEquiv i) = isHom (map i)
--- Proofs that BijectionIso and vSES both induce isomorphisms ---
BijectionIsoToGroupIso : {A : Group {ℓ}} {B : Group {ℓ'}} → BijectionIso A B → GroupIso A B
BijectionIsoToGroupIso {A = A} {B = B} i = grIso
where
module A = GroupStr (snd A)
module B = GroupStr (snd B)
f = fun (map' i)
helper : (b : _) → isProp (Σ[ a ∈ ⟨ A ⟩ ] f a ≡ b)
helper _ a b =
Σ≡Prop (λ _ → isSetCarrier B _ _)
(fst a ≡⟨ sym (A.rid _) ⟩
fst a A.+ A.0g ≡⟨ cong (fst a A.+_) (sym (A.invl _)) ⟩
fst a A.+ ((A.- fst b) A.+ fst b) ≡⟨ A.assoc _ _ _ ⟩
(fst a A.- fst b) A.+ fst b ≡⟨ cong (A._+ fst b) idHelper ⟩
A.0g A.+ fst b ≡⟨ A.lid _ ⟩
fst b ∎)
where
idHelper : fst a A.- fst b ≡ A.0g
idHelper =
inj i _
(isHom (map' i) (fst a) (A.- (fst b))
∙ (cong (f (fst a) B.+_) (morphMinus A B (map' i) (fst b))
∙∙ cong (B._+ (B.- f (fst b))) (snd a ∙ sym (snd b))
∙∙ B.invr (f (fst b))))
grIso : GroupIso A B
map grIso = map' i
inv grIso b = (rec (helper b) (λ a → a) (surj i b)) .fst
rightInv grIso b = (rec (helper b) (λ a → a) (surj i b)) .snd
leftInv grIso b j = rec (helper (f b)) (λ a → a) (propTruncIsProp (surj i (f b)) ∣ b , refl ∣ j) .fst
BijectionIsoToGroupEquiv : {A : Group {ℓ}} {B : Group {ℓ₂}} → BijectionIso A B → GroupEquiv A B
BijectionIsoToGroupEquiv i = GrIsoToGrEquiv (BijectionIsoToGroupIso i)
vSES→GroupIso : ∀ {ℓ ℓ' ℓ'' ℓ'''} {A : Group {ℓ}} {B : Group {ℓ'}} (leftGr : Group {ℓ''}) (rightGr : Group {ℓ'''})
→ vSES A B leftGr rightGr
→ GroupIso A B
vSES→GroupIso {A = A} lGr rGr vses = BijectionIsoToGroupIso theIso
where
theIso : BijectionIso _ _
map' theIso = vSES.ϕ vses
inj theIso a inker = rec (isSetCarrier A _ _)
(λ (a , p) → sym p
∙∙ cong (fun (left vses)) (isTrivialLeft vses a _)
∙∙ morph0→0 lGr A (left vses))
(Ker-ϕ⊂Im-left vses a inker)
surj theIso a = Ker-right⊂Im-ϕ vses a (isTrivialRight vses _ _)
vSES→GroupEquiv : {A : Group {ℓ}} {B : Group {ℓ₁}} (leftGr : Group {ℓ₂}) (rightGr : Group {ℓ₃})
→ vSES A B leftGr rightGr
→ GroupEquiv A B
vSES→GroupEquiv {A = A} lGr rGr vses = GrIsoToGrEquiv (vSES→GroupIso lGr rGr vses)
-- The trivial group is a unit.
lUnitGroupIso : ∀ {ℓ} {G : Group {ℓ}} → GroupIso (dirProd trivialGroup G) G
fun (map lUnitGroupIso) = snd
isHom (map lUnitGroupIso) _ _ = refl
inv lUnitGroupIso g = tt , g
rightInv lUnitGroupIso _ = refl
leftInv lUnitGroupIso _ = refl
rUnitGroupIso : ∀ {ℓ} {G : Group {ℓ}} → GroupIso (dirProd G trivialGroup) G
fun (map rUnitGroupIso) = fst
isHom (map rUnitGroupIso) _ _ = refl
inv rUnitGroupIso g = g , tt
rightInv rUnitGroupIso _ = refl
leftInv rUnitGroupIso _ = refl
lUnitGroupEquiv : ∀ {ℓ} {G : Group {ℓ}} → GroupEquiv (dirProd trivialGroup G) G
lUnitGroupEquiv = GrIsoToGrEquiv lUnitGroupIso
rUnitGroupEquiv : ∀ {ℓ} {G : Group {ℓ}} → GroupEquiv (dirProd G trivialGroup) G
rUnitGroupEquiv = GrIsoToGrEquiv rUnitGroupIso
IsoContrGroupTrivialGroup : {G : Group {ℓ}} → isContr ⟨ G ⟩ → GroupIso G trivialGroup
fun (map (IsoContrGroupTrivialGroup contr)) _ = tt
isHom (map (IsoContrGroupTrivialGroup contr)) _ _ = refl
inv (IsoContrGroupTrivialGroup contr) x = fst contr
rightInv (IsoContrGroupTrivialGroup contr) x = refl
leftInv (IsoContrGroupTrivialGroup contr) x = snd contr x
contrGroup≅trivialGroup : {G : Group {ℓ}} → isContr ⟨ G ⟩ → GroupEquiv G trivialGroup
contrGroup≅trivialGroup contr = GrIsoToGrEquiv (IsoContrGroupTrivialGroup contr)
GroupIso→Iso : {A : Group {ℓ}} {B : Group {ℓ₁}} → GroupIso A B → Iso ⟨ A ⟩ ⟨ B ⟩
fun (GroupIso→Iso i) = fun (map i)
inv (GroupIso→Iso i) = inv i
rightInv (GroupIso→Iso i) = rightInv i
leftInv (GroupIso→Iso i) = leftInv i
congIdLeft≡congIdRight : {A : Type ℓ} (_+A_ : A → A → A) (-A_ : A → A)
(0A : A)
(rUnitA : (x : A) → x +A 0A ≡ x)
(lUnitA : (x : A) → 0A +A x ≡ x)
→ (r≡l : rUnitA 0A ≡ lUnitA 0A)
→ (p : 0A ≡ 0A) →
cong (0A +A_) p ≡ cong (_+A 0A) p
congIdLeft≡congIdRight _+A_ -A_ 0A rUnitA lUnitA r≡l p =
rUnit (cong (0A +A_) p)
∙∙ ((λ i → (λ j → lUnitA 0A (i ∧ j)) ∙∙ cong (λ x → lUnitA x i) p ∙∙ λ j → lUnitA 0A (i ∧ ~ j))
∙∙ cong₂ (λ x y → x ∙∙ p ∙∙ y) (sym r≡l) (cong sym (sym r≡l))
∙∙ λ i → (λ j → rUnitA 0A (~ i ∧ j)) ∙∙ cong (λ x → rUnitA x (~ i)) p ∙∙ λ j → rUnitA 0A (~ i ∧ ~ j))
∙∙ sym (rUnit (cong (_+A 0A) p))
|
{
"alphanum_fraction": 0.5733958114,
"avg_line_length": 40.6887159533,
"ext": "agda",
"hexsha": "1deae02bfeaaf1bb7f4ce390efa59210b7c5221d",
"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": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/Algebra/Group/Algebra.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"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": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/Algebra/Group/Algebra.agda",
"max_line_length": 122,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/Algebra/Group/Algebra.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4189,
"size": 10457
}
|
{-# OPTIONS --copatterns --sized-types #-}
-- {-# OPTIONS -v tc.size.solve:60 #-}
open import Common.Size
open import Common.Prelude
open import Common.Product
-- Sized streams via head/tail.
record Stream {i : Size} (A : Set) : Set where
coinductive
constructor delay
field
force : ∀ {j : Size< i} → A × Stream {j} A
open Stream public
_∷ˢ_ : ∀{i A} → A → Stream {i} A → Stream {↑ i} A
force (a ∷ˢ s) = a , s
-- Prepending a list to a stream.
_++ˢ_ : ∀ {i A} → List A → Stream {i} A → Stream {i} A
(a ∷ as) ++ˢ s = a ∷ˢ (as ++ˢ s)
[] ++ˢ s = s
|
{
"alphanum_fraction": 0.582010582,
"avg_line_length": 22.68,
"ext": "agda",
"hexsha": "7e093d0912b2e119d3d33562c4732c67d8f5fa68",
"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/OutStream.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/OutStream.agda",
"max_line_length": 54,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/OutStream.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": 208,
"size": 567
}
|
{-# OPTIONS --without-K --safe #-}
-- The Underlying category of an Enriched category over a Monoidal category V
open import Categories.Category.Monoidal using (Monoidal)
open import Categories.Category.Core renaming (Category to Setoid-Category)
module Categories.Enriched.Category.Underlying {o ℓ e} {V : Setoid-Category o ℓ e}
(M : Monoidal V) where
open import Level
open import Function using (_$_)
open import Categories.Enriched.Category
open import Categories.Category.Helper
open import Categories.Category.Monoidal.Properties M using (module Kelly's)
open import Categories.Category.Monoidal.Reasoning M
open import Categories.Category.Monoidal.Utilities M using (module Shorthands)
open import Categories.Morphism.Reasoning V
import Categories.Morphism.IsoEquiv V as IsoEquiv
open Setoid-Category V renaming (Obj to ObjV; id to idV)
open Monoidal M
open Shorthands
open IsoEquiv._≃_
-- A V-category C does not have morphisms of its own, but the
-- collection of V-morphisms from the monoidal unit into the
-- hom-objects of C forms a setoid. This induces the *underlying*
-- category of C.
Underlying : {c : Level} (C : Category M c) → Setoid-Category c ℓ e
Underlying C = categoryHelper (record
{ Obj = Obj
; _⇒_ = λ A B → unit ⇒ hom A B
; _≈_ = λ f g → f ≈ g
; id = id
; _∘_ = λ f g → ⊚ ∘ f ⊗₁ g ∘ λ⇐
; assoc = λ {_} {_} {_} {_} {f} {g} {h} →
begin
⊚ ∘ (⊚ ∘ h ⊗₁ g ∘ λ⇐) ⊗₁ f ∘ λ⇐ ≈˘⟨ refl⟩∘⟨ assoc ⟩⊗⟨refl ⟩∘⟨refl ⟩
⊚ ∘ ((⊚ ∘ h ⊗₁ g) ∘ λ⇐) ⊗₁ f ∘ λ⇐ ≈⟨ refl⟩∘⟨ pushˡ split₁ʳ ⟩
⊚ ∘ (⊚ ∘ h ⊗₁ g) ⊗₁ f ∘ (λ⇐ ⊗₁ idV) ∘ λ⇐ ≈⟨ pullˡ ⊚-assoc-var ⟩
(⊚ ∘ h ⊗₁ (⊚ ∘ g ⊗₁ f) ∘ α⇒) ∘ (λ⇐ ⊗₁ idV) ∘ λ⇐ ≈˘⟨ pushˡ (pushʳ (pushʳ
(switch-tofromˡ associator (to-≈ Kelly's.coherence-iso₁)))) ⟩
(⊚ ∘ h ⊗₁ (⊚ ∘ g ⊗₁ f) ∘ λ⇐) ∘ λ⇐ ≈⟨ pullʳ (pullʳ unitorˡ-commute-to) ⟩
⊚ ∘ h ⊗₁ (⊚ ∘ g ⊗₁ f) ∘ idV ⊗₁ λ⇐ ∘ λ⇐ ≈˘⟨ refl⟩∘⟨ pushˡ split₂ʳ ⟩
⊚ ∘ h ⊗₁ ((⊚ ∘ g ⊗₁ f) ∘ λ⇐) ∘ λ⇐ ≈⟨ refl⟩∘⟨ refl⟩⊗⟨ assoc ⟩∘⟨refl ⟩
⊚ ∘ h ⊗₁ (⊚ ∘ g ⊗₁ f ∘ λ⇐) ∘ λ⇐
∎
; identityˡ = λ {_} {_} {f} → begin
⊚ ∘ id ⊗₁ f ∘ λ⇐ ≈⟨ refl⟩∘⟨ serialize₁₂ ⟩∘⟨refl ⟩
⊚ ∘ (id ⊗₁ idV ∘ idV ⊗₁ f) ∘ λ⇐ ≈˘⟨ refl⟩∘⟨ pushʳ unitorˡ-commute-to ⟩
⊚ ∘ id ⊗₁ idV ∘ λ⇐ ∘ f ≈⟨ pullˡ unitˡ ⟩
λ⇒ ∘ λ⇐ ∘ f ≈⟨ cancelˡ unitorˡ.isoʳ ⟩
f ∎
; identityʳ = λ {_} {_} {f} → begin
⊚ ∘ f ⊗₁ id ∘ λ⇐ ≈⟨ refl⟩∘⟨ serialize₂₁ ⟩∘⟨refl ⟩
⊚ ∘ (idV ⊗₁ id ∘ f ⊗₁ idV) ∘ λ⇐ ≈⟨ pullˡ (pullˡ unitʳ) ⟩
(unitorʳ.from ∘ f ⊗₁ idV) ∘ λ⇐ ≈⟨ unitorʳ-commute-from ⟩∘⟨refl ⟩
(f ∘ unitorʳ.from) ∘ λ⇐ ≈˘⟨ (refl⟩∘⟨ Kelly's.coherence₃) ⟩∘⟨refl ⟩
(f ∘ λ⇒) ∘ λ⇐ ≈⟨ cancelʳ unitorˡ.isoʳ ⟩
f ∎
; equiv = equiv
; ∘-resp-≈ = λ eq₁ eq₂ → ∘-resp-≈ʳ $ ∘-resp-≈ˡ $ ⊗-resp-≈ eq₁ eq₂
})
where open Category C
module Underlying {c} (C : Category M c) = Setoid-Category (Underlying C)
|
{
"alphanum_fraction": 0.5196202532,
"avg_line_length": 46.4705882353,
"ext": "agda",
"hexsha": "ea57a46c0910bae1a40090f1eeca09a38f6940e2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Enriched/Category/Underlying.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Enriched/Category/Underlying.agda",
"max_line_length": 121,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Enriched/Category/Underlying.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": 1404,
"size": 3160
}
|
{-
This second-order signature was created from the following second-order syntax description:
syntax UTLC | Λ
type
* : 0-ary
term
app : * * -> * | _$_ l20
lam : *.* -> * | ƛ_ r10
theory
(ƛβ) b : *.* a : * |> app (lam (x.b[x]), a) = b[a]
(ƛη) f : * |> lam (x.app (f, x)) = f
(lβ) b : *.* a : * |> letd (a, x. b) = b[a]
-}
module UTLC.Signature where
open import SOAS.Context
open import SOAS.Common
open import SOAS.Syntax.Signature *T public
open import SOAS.Syntax.Build *T public
-- Operator symbols
data Λₒ : Set where
appₒ lamₒ : Λₒ
-- Term signature
Λ:Sig : Signature Λₒ
Λ:Sig = sig λ
{ appₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ *
; lamₒ → (* ⊢₁ *) ⟼₁ *
}
open Signature Λ:Sig public
|
{
"alphanum_fraction": 0.5579809004,
"avg_line_length": 17.8780487805,
"ext": "agda",
"hexsha": "c672d9810759a91dc883b8344a6adf8f883102f0",
"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/UTLC/Signature.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/UTLC/Signature.agda",
"max_line_length": 91,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/UTLC/Signature.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 295,
"size": 733
}
|
module InterpretCommand where
open import ParseTree
open import Data.List
open import Data.Nat
open import ScopeState
open import Data.Sum hiding (map)
open import Data.Bool
open import Data.String hiding (_++_)
open import Data.Maybe hiding (map)
open import Data.Product hiding (map)
open import AgdaHelperFunctions
getRange : ParseTree -> Range
getRange (signature _ range₁) = range₁
getRange (functionDefinition _ _ _ range₁) = range₁
getRange (dataStructure _ _ _ _ range₁) = range₁
getRange (pragma _ range₁) = range₁
getRange (openImport _ _ _ range₁) = range₁
getRange (moduleName _ range₁) = range₁
_<=_ : ℕ -> ℕ -> Bool
zero <= zero = true
zero <= suc m = true
suc n <= zero = false
suc n <= suc m = n <= m
isInRange : Range -> ℕ -> Bool
isInRange (range lastUnaffected lastAffected) what = ((lastUnaffected + 1) <= what) ∧ (what <= (lastAffected + 1))
firstActualValue : {A : Set} -> List (Maybe A) -> Maybe A
firstActualValue [] = nothing
firstActualValue (just x ∷ list) = just x
firstActualValue (nothing ∷ list) = firstActualValue list
findInIdentifier : ℕ -> Identifier -> Maybe ℕ
findInIdentifier n (identifier name isInRange₁ scope declaration)
with isInRange₁ n
... | inside = just declaration
... | x = nothing
findInSignature : ℕ -> TypeSignature -> Maybe ℕ
findInExpr : ℕ -> Expr -> Maybe ℕ
findInExpr n numLit = nothing
findInExpr n (ident i) = findInIdentifier n i
findInExpr n hole = nothing
findInExpr n (functionApp e e₁) = firstActualValue (findInExpr n e ∷ findInExpr n e₁ ∷ [])
findInExpr n (implicit e) = findInExpr n e
findInExpr n underscore = nothing
findInExpr n (namedArgument arg) = findInSignature n arg
findInSignature n (typeSignature funcName funcType) =
firstActualValue (findInIdentifier n funcName ∷ findInExpr n funcType ∷ [])
findInParseTree : ℕ -> ParseTree -> Maybe ℕ
findInParseTree n (signature signature₁ range₁) = findInSignature n signature₁
findInParseTree n (functionDefinition definitionOf params body range₁) =
firstActualValue (findInIdentifier n definitionOf ∷ findInExpr n body ∷ map (findInExpr n) params)
findInParseTree n (dataStructure dataName parameters indexInfo constructors range₁) = firstActualValue ((findInIdentifier n dataName ∷ findInExpr n indexInfo ∷ map (findInSignature n) parameters) ++ map (findInSignature n) constructors)
findInParseTree n (pragma (builtin concept definition) range₁) =
findInIdentifier n definition
findInParseTree _ _ = nothing
getDeclarationIDForPoint : List ParseTree -> ℕ -> Maybe ℕ
getDeclarationIDForPoint [] point = nothing
getDeclarationIDForPoint (x ∷ list) point with isInRange (getRange x) point
getDeclarationIDForPoint (x ∷ list) point | false =
getDeclarationIDForPoint list point
getDeclarationIDForPoint (x ∷ list) point | true = findInParseTree point x
-- for argument rearranging
--TODO fix this when adding more detailed source position data
getArgNumber : ℕ -> ℕ -> Expr -> ScopeState ℕ
getArgNumber point currArgNumber (functionApp t t₁ {true}) = do
just _ <- return $ findInExpr point t
where _ -> getArgNumber point (currArgNumber + 1) t₁
return currArgNumber
getArgNumber point currArgNumber t = fail "Point seems to be in result."
getFuncIdAndArgNumberInParseTree : ℕ -> ParseTree -> ScopeState (ℕ × ℕ)
getFuncIdAndArgNumberInParseTree n (signature (typeSignature (identifier name isInRange₁ scope declaration) funcType) range₁) = do
argNum <- getArgNumber n zero funcType
return $ declaration , argNum
getFuncIdAndArgNumberInParseTree _ _ = fail "Point not in signature"
getFuncIdAndArgNumber : List ParseTree -> ℕ -> ScopeState (ℕ × ℕ)
getFuncIdAndArgNumber [] point = fail "Point not in code"
getFuncIdAndArgNumber (x ∷ list) point with isInRange (getRange x) point
getFuncIdAndArgNumber (x ∷ list) point | false =
getFuncIdAndArgNumber list point
getFuncIdAndArgNumber (x ∷ list) point | true = getFuncIdAndArgNumberInParseTree point x
|
{
"alphanum_fraction": 0.7641340496,
"avg_line_length": 41.1473684211,
"ext": "agda",
"hexsha": "07d286709b77b54efe293eabc6e2aa85e727924a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "omega12345/RefactorAgda",
"max_forks_repo_path": "RefactorAgdaEngine/InterpretCommand.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "omega12345/RefactorAgda",
"max_issues_repo_path": "RefactorAgdaEngine/InterpretCommand.agda",
"max_line_length": 236,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "omega12345/RefactorAgda",
"max_stars_repo_path": "RefactorAgdaEngine/InterpretCommand.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z",
"num_tokens": 1080,
"size": 3909
}
|
{-# OPTIONS --without-K --exact-split --safe #-}
open import Fragment.Algebra.Signature
module Fragment.Equational.Theory.Laws (Σ : Signature) where
open import Fragment.Equational.Theory.Base using (Eq)
open import Function using (_∘_)
open import Data.Empty using (⊥)
open import Data.Fin using (#_)
open import Data.Sum using (inj₁; inj₂)
open import Data.Product using (_,_)
import Relation.Binary.PropositionalEquality as PE
open import Fragment.Algebra.Free Σ
open import Fragment.Algebra.Free.Syntax Σ (PE.setoid ⊥)
module _ where
private
a = # 0
dne : ops Σ 1 → Eq Σ 1
dne ~ = ⟨ ~ ⟩₁ ⟨ ~ ⟩₁ ⟨ a ⟩ , ⟨ a ⟩
module _ (e : ops Σ 0) where
private
a = # 0
idₗ : ops Σ 2 → Eq Σ 1
idₗ • = ⟨ e ⟩₀ ⟨ • ⟩₂ ⟨ a ⟩ , ⟨ a ⟩
idᵣ : ops Σ 2 → Eq Σ 1
idᵣ • = ⟨ a ⟩ ⟨ • ⟩₂ ⟨ e ⟩₀ , ⟨ a ⟩
anₗ : ops Σ 2 → Eq Σ 1
anₗ • = ⟨ e ⟩₀ ⟨ • ⟩₂ ⟨ a ⟩ , ⟨ e ⟩₀
anᵣ : ops Σ 2 → Eq Σ 1
anᵣ • = ⟨ a ⟩ ⟨ • ⟩₂ ⟨ e ⟩₀ , ⟨ e ⟩₀
invₗ : ops Σ 1 → ops Σ 2 → Eq Σ 1
invₗ ~ • = (⟨ ~ ⟩₁ ⟨ a ⟩) ⟨ • ⟩₂ ⟨ a ⟩ , ⟨ e ⟩₀
invᵣ : ops Σ 1 → ops Σ 2 → Eq Σ 1
invᵣ ~ • = ⟨ a ⟩ ⟨ • ⟩₂ (⟨ ~ ⟩₁ ⟨ a ⟩) , ⟨ e ⟩₀
module _ where
private
a = # 0
b = # 1
c = # 2
hom : ops Σ 1 → ∀ {n} → ops Σ n → Eq Σ n
hom h {n} f =
⟨ h ⟩₁ term f (map ⟨_⟩ (allFin n))
,
term f (map (⟨ h ⟩₁_ ∘ ⟨_⟩) (allFin n))
where open import Data.Vec using (map; allFin)
comm : ops Σ 2 → Eq Σ 2
comm • = ⟨ a ⟩ ⟨ • ⟩₂ ⟨ b ⟩ , ⟨ b ⟩ ⟨ • ⟩₂ ⟨ a ⟩
assoc : ops Σ 2 → Eq Σ 3
assoc • =
(⟨ a ⟩ ⟨ • ⟩₂ ⟨ b ⟩) ⟨ • ⟩₂ ⟨ c ⟩
,
⟨ a ⟩ ⟨ • ⟩₂ (⟨ b ⟩ ⟨ • ⟩₂ ⟨ c ⟩)
|
{
"alphanum_fraction": 0.4943324937,
"avg_line_length": 21.7534246575,
"ext": "agda",
"hexsha": "40aef704ec3f146b1fb6845ae846e62898f4dcdb",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Equational/Theory/Laws.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Equational/Theory/Laws.agda",
"max_line_length": 60,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Equational/Theory/Laws.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 744,
"size": 1588
}
|
------------------------------------------------------------------------------
-- Properties of the mirror function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.Mirror.PropertiesATP where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.List
open import FOTC.Data.List.PropertiesATP using ( reverse-[x]≡[x] )
open import FOTC.Program.Mirror.Forest.PropertiesATP
open import FOTC.Program.Mirror.Forest.TotalityATP
open import FOTC.Program.Mirror.Mirror
open import FOTC.Program.Mirror.Tree.TotalityATP
open import FOTC.Program.Mirror.Type
------------------------------------------------------------------------------
mirror-involutive : ∀ {t} → Tree t → mirror · (mirror · t) ≡ t
helper : ∀ {ts} → Forest ts →
reverse (map mirror (reverse (map mirror ts))) ≡ ts
mirror-involutive (tree d fnil) = prf
where postulate prf : mirror · (mirror · node d []) ≡ node d []
{-# ATP prove prf #-}
mirror-involutive (tree d (fcons {t} {ts} Tt Fts)) = prf
where postulate prf : mirror · (mirror · node d (t ∷ ts)) ≡ node d (t ∷ ts)
{-# ATP prove prf helper #-}
helper fnil = prf
where postulate prf : reverse (map mirror (reverse (map mirror []))) ≡ []
{-# ATP prove prf #-}
helper (fcons {t} {ts} Tt Fts) =
prf (map-++ mirror
mirror-Tree
(reverse-Forest (map-Forest mirror mirror-Tree Fts))
(mirror · t ∷ []))
(mirror-involutive Tt)
(helper Fts)
where
postulate
-- We help the ATPs proving the first hypothesis.
prf : (map mirror (reverse (map mirror ts) ++ (mirror · t ∷ [])) ≡
map mirror
(reverse (map mirror ts)) ++ (map mirror (mirror · t ∷ []))) →
mirror · (mirror · t) ≡ t →
reverse (map mirror (reverse (map mirror ts))) ≡ ts →
reverse (map mirror (reverse (map mirror (t ∷ ts)))) ≡ t ∷ ts
{-# ATP prove prf reverse-∷ mirror-Tree map-Forest reverse-++
reverse-Forest reverse-[x]≡[x] #-}
|
{
"alphanum_fraction": 0.5334224599,
"avg_line_length": 38.6896551724,
"ext": "agda",
"hexsha": "52f82ec0f040e5c6f3ad47a06f901d742fb34ad5",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/Mirror/PropertiesATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/Mirror/PropertiesATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/Mirror/PropertiesATP.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 588,
"size": 2244
}
|
module RecordUpdateSyntax where
open import Common.Prelude
open import Common.Equality
data Param : Nat → Set where
param : ∀ n → Param (suc n)
record R : Set where
field
{i} : Nat
p : Param i
s : Nat
old : R
old = record { p = param 0; s = 1 }
-- Simple update, it should be able to infer the type and the implicit.
new : _
new = record old { p = param 1 }
new′ : R
new′ = record { i = 2; p = param 1; s = 1 }
-- Here's a needlessly complex update.
upd-p-s : _ → _ → _ → R
upd-p-s zero s r = record r { p = param zero; s = s }
upd-p-s (suc n) s r = record (upd-p-s n 0 r) { p = param n; s = s }
eq₁ : new ≡ new′
eq₁ = refl
eq₂ : upd-p-s zero 1 (record new { s = 0 }) ≡ old
eq₂ = refl
-- Check that instance arguments are handled properly
postulate
T : Nat → Set
instance
t0 : T 0
t1 : T 1
record Instance : Set where
field
n : Nat
{{t}} : T n
r0 : Instance
r0 = record { n = 0 }
r1 : Instance
r1 = record r0 { n = 1 }
check : Instance.t r1 ≡ t1
check = refl
|
{
"alphanum_fraction": 0.5934718101,
"avg_line_length": 18.0535714286,
"ext": "agda",
"hexsha": "4be1c937b0e104bf38c97d9916b7afbc25d31386",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Succeed/RecordUpdateSyntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Succeed/RecordUpdateSyntax.agda",
"max_line_length": 71,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/RecordUpdateSyntax.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": 359,
"size": 1011
}
|
module Thesis.Derive where
open import Thesis.Lang
open import Thesis.Changes
open import Thesis.LangChanges
open import Thesis.LangOps
open import Relation.Binary.PropositionalEquality
Γ≼ΔΓ : ∀ {Γ} → Γ ≼ ΔΓ Γ
Γ≼ΔΓ {∅} = ∅
Γ≼ΔΓ {τ • Γ} = drop Δt τ • keep τ • Γ≼ΔΓ
fit : ∀ {τ Γ} → Term Γ τ → Term (ΔΓ Γ) τ
fit = weaken Γ≼ΔΓ
⟦Γ≼ΔΓ⟧ : ∀ {Γ ρ1 ρ2 dρ} → (dρρ : [ Γ ]Γ dρ from ρ1 to ρ2) →
ρ1 ≡ ⟦ Γ≼ΔΓ ⟧≼ dρ
⟦Γ≼ΔΓ⟧ v∅ = refl
⟦Γ≼ΔΓ⟧ (dvv v• dρρ) = cong₂ _•_ refl (⟦Γ≼ΔΓ⟧ dρρ)
fit-sound : ∀ {Γ τ} → (t : Term Γ τ) →
∀ {dρ ρ1 ρ2} → [ Γ ]Γ dρ from ρ1 to ρ2 →
⟦ t ⟧Term ρ1 ≡ ⟦ fit t ⟧Term dρ
fit-sound t dρρ = trans
(cong ⟦ t ⟧Term (⟦Γ≼ΔΓ⟧ dρρ))
(sym (weaken-sound t _))
deriveConst : ∀ {τ} →
Const τ →
Term ∅ (Δt τ)
deriveConst unit = const unit
deriveConst (lit n) = const (lit (+ 0))
deriveConst plus = abs (abs (abs (abs (app₂ (const plus) (var (that (that this))) (var this)))))
-- minus = λ m n → m - n
-- dminus = λ m dm n dn → (m + dm) - (n + dn) - (m - n) = dm - dn
deriveConst minus = abs (abs (abs (abs (app₂ (const minus) (var (that (that this))) (var this)))))
deriveConst cons = abs (abs (abs (abs (app (app (const cons) (var (that (that this)))) (var this)))))
deriveConst fst = abs (abs (app (const fst) (var this)))
deriveConst snd = abs (abs (app (const snd) (var this)))
deriveConst linj = abs (abs (app (const linj) (app (const linj) (var this))))
deriveConst rinj = abs (abs (app (const linj) (app (const rinj) (var this))))
deriveConst (match {t1} {t2} {t3}) =
-- λ s ds f df g dg →
abs (abs (abs (abs (abs (abs
-- match ds
(app₃ (const match) (var (that (that (that (that this)))))
-- λ ds₁ → match ds₁
(abs (app₃ (const match) (var this)
-- case inj₁ da → absV 1 (λ da → match s
(abs (app₃ (const match) (var (that (that (that (that (that (that (that this))))))))
-- λ a → app₂ df a da
(abs (app₂ (var (that (that (that (that (that this)))))) (var this) (var (that this))))
-- absurd: λ b → dg b (nil b)
(abs (app₂ (var (that (that (that this)))) (var this) (app (onilτo t2) (var this))))))
-- case inj₂ db → absV 1 (λ db → match s
(abs (app₃ (const match) (var (that (that (that (that (that (that (that this))))))))
-- absurd: λ a → df a (nil a)
(abs (app₂ (var (that (that (that (that (that this)))))) (var this) (app (onilτo t1) (var this))))
-- λ b → app₂ dg b db
(abs (app₂ (var (that (that (that this)))) (var this) (var (that this))))))))
-- recomputation branch:
-- λ s2 → ominus (match s2 (f ⊕ df) (g ⊕ dg)) (match s f g)
(abs (app₂ (ominusτo t3)
-- (match s2 (f ⊕ df) (g ⊕ dg))
(app₃ (const match)
(var this)
(app₂ (oplusτo (t1 ⇒ t3))
(var (that (that (that (that this)))))
(var (that (that (that this)))))
(app₂ (oplusτo (t2 ⇒ t3))
(var (that (that this)))
(var (that this))))
-- (match s f g)
(app₃ (const match)
(var (that (that (that (that (that (that this)))))))
(var (that (that (that (that this)))))
(var (that (that this))))))))))))
{-
derive (λ s f g → match s f g) =
λ s ds f df g dg →
case ds of
ch1 da →
case s of
inj1 a → df a da
inj2 b → {- absurd -} dg b (nil b)
ch2 db →
case s of
inj2 b → dg b db
inj1 a → {- absurd -} df a (nil a)
rp s2 →
match (f ⊕ df) (g ⊕ dg) s2 ⊝
match f g s
-}
derive-var : ∀ {Γ τ} → Var Γ τ → Var (ΔΓ Γ) (Δt τ)
derive-var this = this
derive-var (that x) = that (that (derive-var x))
derive : ∀ {Γ τ} → Term Γ τ → Term (ΔΓ Γ) (Δt τ)
derive (const c) = weaken (∅≼Γ {ΔΓ _}) (deriveConst c)
derive (var x) = var (derive-var x)
derive (app s t) = app (app (derive s) (fit t)) (derive t)
derive (abs t) = abs (abs (derive t))
⟦_⟧ΔVar : ∀ {Γ τ} → (x : Var Γ τ) → (ρ : ⟦ Γ ⟧Context) (dρ : ChΓ Γ) → Chτ τ
⟦ x ⟧ΔVar ρ dρ = ⟦ derive-var x ⟧Var dρ
⟦_⟧ΔTerm : ∀ {Γ τ} → (t : Term Γ τ) → (ρ : ⟦ Γ ⟧Context) (dρ : ChΓ Γ) → Chτ τ
⟦ t ⟧ΔTerm ρ dρ = ⟦ derive t ⟧Term dρ
⟦_⟧ΔConst : ∀ {τ} (c : Const τ) → Chτ τ
⟦ c ⟧ΔConst = ⟦ deriveConst c ⟧Term ∅
⟦_⟧ΔConst-rewrite : ∀ {τ Γ} (c : Const τ) (ρ : ⟦ Γ ⟧Context) dρ → ⟦_⟧ΔTerm (const c) ρ dρ ≡ ⟦ c ⟧ΔConst
⟦ c ⟧ΔConst-rewrite ρ dρ rewrite weaken-sound {Γ₁≼Γ₂ = ∅≼Γ} (deriveConst c) dρ | ⟦∅≼Γ⟧-∅ dρ = refl
module _ {t1 t2 t3 : Type}
(f : ⟦ t1 ⟧Type → ⟦ t3 ⟧Type)
(df : Chτ (t1 ⇒ t3))
(g : ⟦ t2 ⟧Type → ⟦ t3 ⟧Type)
(dg : Chτ (t2 ⇒ t3))
where
private
Γ : Context
Γ = sum t1 t2 •
(t2 ⇒ Δt t2 ⇒ Δt t3) •
(t2 ⇒ t3) •
(t1 ⇒ Δt t1 ⇒ Δt t3) •
(t1 ⇒ t3) •
sum (sum (Δt t1) (Δt t2)) (sum t1 t2) •
sum t1 t2 • ∅
module _ where
private
Γ′ Γ′′ : Context
Γ′ = t2 • (t2 ⇒ Δt t2 ⇒ Δt t3) • (t2 ⇒ t3) • Γ
Γ′′ = t2 • Γ′
changeMatchSem-lem1 :
∀ a1 b2 →
⟦ match ⟧ΔConst (inj₁ a1) (inj₂ (inj₂ b2)) f df g dg
≡
g b2 ⊕ dg b2 (nil b2) ⊝ f a1
changeMatchSem-lem1 a1 b2 rewrite ominusτ-equiv-ext t2 Γ′′ | oplusτ-equiv-ext t3 Γ′ | ominusτ-equiv-ext t3 Γ = refl
module _ where
private
Γ′ Γ′′ : Context
Γ′ = t1 • (t1 ⇒ Δt t1 ⇒ Δt t3) • (t1 ⇒ t3) • Γ
Γ′′ = t1 • Γ′
changeMatchSem-lem2 :
∀ b1 a2 →
⟦ match ⟧ΔConst (inj₂ b1) (inj₂ (inj₁ a2)) f df g dg
≡
f a2 ⊕ df a2 (nil a2) ⊝ g b1
changeMatchSem-lem2 b1 a2 rewrite ominusτ-equiv-ext t1 Γ′′ | oplusτ-equiv-ext t3 Γ′ | ominusτ-equiv-ext t3 Γ = refl
module _ where
private
Γ′ Γ′′ : Context
Γ′ = t1 • (t1 ⇒ Δt t1 ⇒ Δt t3) • (t1 ⇒ t3) • Γ
Γ′′ = t1 • Γ′
changeMatchSem-lem3 :
∀ a1 a2 →
⟦ match ⟧ΔConst (inj₁ a1) (inj₂ (inj₁ a2)) f df g dg ≡
f a2 ⊕ df a2 (nil a2) ⊝ f a1
changeMatchSem-lem3 a1 a2 rewrite ominusτ-equiv-ext t1 Γ′′ | oplusτ-equiv-ext t3 Γ′ | ominusτ-equiv-ext t3 Γ = refl
module _ where
private
Γ′ Γ′′ : Context
Γ′ = t2 • (t2 ⇒ Δt t2 ⇒ Δt t3) • (t2 ⇒ t3) • Γ
Γ′′ = t2 • Γ′
changeMatchSem-lem4 :
∀ b1 b2 →
⟦ match ⟧ΔConst (inj₂ b1) (inj₂ (inj₂ b2)) f df g dg
≡
g b2 ⊕ dg b2 (nil b2) ⊝ g b1
changeMatchSem-lem4 b1 b2 rewrite ominusτ-equiv-ext t2 Γ′′ | oplusτ-equiv-ext t3 Γ′ | ominusτ-equiv-ext t3 Γ = refl
|
{
"alphanum_fraction": 0.524940239,
"avg_line_length": 35.4519774011,
"ext": "agda",
"hexsha": "0e7a6508d1b828ff2ec9567a252c090c79c232dd",
"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/Derive.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/Derive.agda",
"max_line_length": 119,
"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/Derive.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": 2722,
"size": 6275
}
|
module z where
------------------------------------------------------------------------------
-- 1 intro
-- data types
data Nat : Set where
zero : Nat
suc : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
--------------------------------------------------
-- begin : from later - here to use in tests
data Bool : Set where
true : Bool
false : Bool
data IsTrue : Bool → Set where
is-true : IsTrue true
_=Nat_ : Nat → Nat → Bool
zero =Nat zero = true
(suc x) =Nat (suc y) = x =Nat y
_ =Nat _ = false
-- end : from later
--------------------------------------------------
-- pattern matching
_+_ : Nat → Nat → Nat
zero + y = y
(suc x) + y = suc (x + y)
infixl 9 _+_
-- {-# BUILTIN NATPLUS _+_ #-}
-- ex 1.1
halve : Nat → Nat
halve zero = zero
halve (suc zero) = zero
halve (suc (suc n)) = suc (halve n)
halve-0 : IsTrue (halve 0 =Nat 0)
halve-0 = is-true
halve-1 : IsTrue (halve 1 =Nat 0)
halve-1 = is-true
halve-2 : IsTrue (halve 2 =Nat 1)
halve-2 = is-true
halve-3 : IsTrue (halve 3 =Nat 1)
halve-3 = is-true
halve-4 : IsTrue (halve 4 =Nat 2)
halve-4 = is-true
halve-14 : IsTrue (halve 14 =Nat 7)
halve-14 = is-true
halve-15 : IsTrue (halve 15 =Nat 7)
halve-15 = is-true
halve-16 : IsTrue (halve 16 =Nat 8)
halve-16 = is-true
-- ex 1.2
_*_ : Nat → Nat → Nat
zero * y = zero
(suc x) * y = y + (x * y)
2*0 : IsTrue ((2 * 0) =Nat 0)
2*0 = is-true
2*1 : IsTrue ((2 * 1) =Nat 2)
2*1 = is-true
2*2 : IsTrue ((2 * 2) =Nat 4)
2*2 = is-true
3*3 : IsTrue ((3 * 3) =Nat 9)
3*3 = is-true
4*4 : IsTrue ((4 * 4) =Nat 16)
4*4 = is-true
{-
-- ex 1.3
data Bool : Set where
true : Bool
false : Bool
-}
not : Bool → Bool
not true = false
not false = true
_&&_ : Bool → Bool → Bool
_&&_ true y = y
_&&_ false _ = false
_||_ : Bool → Bool → Bool
_||_ true _ = true
_||_ false y = y
-- types are 1st class
-- equivalent to Haskell type alias : type MyNat = Nat
MyNat : Set
MyNat = Nat
-- Set used to implement polymorphic functions
idA : (A : Set) → A → A
idA _ x = x
-- implicit args
id : {A : Set} → A → A
id x = x
-- polymorphic data types
data List (A : Set) : Set where
[] : List A
_::_ : A → List A → List A
infixr 5 _::_
-- ex 1.4
length : {A : Set} → List A → Nat
length [] = zero
length (_ :: xs) = 1 + length xs
_++_ : {A : Set} → List A → List A → List A
_++_ [] l2 = l2
_++_ (x :: xs) l2 = x :: xs ++ l2
map : { A B : Set } → (A → B) → List A → List B
map _ [] = []
map f (x :: xs) = f x :: map f xs
-- ex 1.5
data Maybe (A : Set) : Set where
just : A → Maybe A
nothing : Maybe A
lookup : {A : Set} → List A → Nat → Maybe A
lookup [] _ = nothing
lookup (x :: _) zero = just x
lookup (_ :: xs) (suc n) = lookup xs n
_=List-Nat_ : List Nat → List Nat → Bool
[] =List-Nat [] = true
(x :: xs) =List-Nat (y :: ys) = (x =Nat y) && (xs =List-Nat ys)
_ =List-Nat _ = false
ex-xs : List Nat
ex-xs = 0 :: 1 :: 2 :: 3 :: []
length++ : IsTrue ((length ex-xs + length ex-xs) =Nat (length (ex-xs ++ ex-xs)))
length++ = is-true
map2* : IsTrue (map (2 *_) ex-xs =List-Nat (0 :: 2 :: 4 :: 6 :: []))
map2* = is-true
_=Maybe-Nat_ : Maybe Nat → Maybe Nat → Bool
nothing =Maybe-Nat nothing = true
(just x) =Maybe-Nat (just y) = x =Nat y
_ =Maybe-Nat _ = false
lookup[]0 : IsTrue (lookup [] 0 =Maybe-Nat nothing)
lookup[]0 = is-true
lookupex-xs0 : IsTrue (lookup ex-xs 0 =Maybe-Nat (just 0))
lookupex-xs0 = is-true
lookupex-xs1 : IsTrue (lookup ex-xs 1 =Maybe-Nat (just 1))
lookupex-xs1 = is-true
lookupex-xs9 : IsTrue (lookup ex-xs 9 =Maybe-Nat nothing)
lookupex-xs9 = is-true
data _×_ (A B : Set) : Set where
_,_ : A → B → A × B
infixr 4 _,_
fst : {A B : Set} → A × B → A
fst (a , _) = a
snd : {A B : Set} → A × B → B
snd (_ , b) = b
-- ex 1.6
-- NO. Regardless of the value of 'Nat', there is NO way to construct an A if given [].
------------------------------------------------------------------------------
-- 2 dependent types
-- parameter : bound for ENTIRE def
-- index : varies according to constructor
-- v v
data Vec (A : Set) : Nat → Set where -- Vec is dependent TYPE
[] : Vec A 0
_::_ : {n : Nat} → A → Vec A n → Vec A (suc n)
--infixr 5 _::_
-- dependent FUNCTION : return TYPE depends on inputs
zeroes : (n : Nat) → Vec Nat n
zeroes zero = []
zeroes (suc n) = 0 :: zeroes n
-- ex 2.1
downFrom : (n : Nat) → Vec Nat n
downFrom zero = []
downFrom (suc n) = n :: downFrom n
_=Vec-Nat_ : {n : Nat} → Vec Nat n → Vec Nat n → Bool
[] =Vec-Nat [] = true
(x :: xs) =Vec-Nat (y :: ys) = (x =Nat y) && (xs =Vec-Nat ys)
downFrom0 : IsTrue (downFrom 0 =Vec-Nat [])
downFrom0 = is-true
downFrom1 : IsTrue (downFrom 1 =Vec-Nat (0 :: []))
downFrom1 = is-true
downFrom2 : IsTrue (downFrom 2 =Vec-Nat (1 :: 0 :: []))
downFrom2 = is-true
downFrom3 : IsTrue (downFrom 3 =Vec-Nat (2 :: 1 :: 0 :: []))
downFrom3 = is-true
downFrom7 : IsTrue (downFrom 7 =Vec-Nat (6 :: 5 :: 4 :: 3 :: 2 :: 1 :: 0 :: []))
downFrom7 = is-true
-- ex 2.2
tail : {A : Set} {n : Nat} → Vec A (suc n) → Vec A n
tail (_ :: xs) = xs
-- ex 2.3
dotProduct : {n : Nat} → Vec Nat n → Vec Nat n → Nat
dotProduct [] [] = 0
dotProduct (x :: xs) (y :: ys) = (x * y) + dotProduct xs ys
dotProduct32 : IsTrue (dotProduct (1 :: 2 :: 3 :: []) (1 :: 5 :: 7 :: []) =Nat 32)
dotProduct32 = is-true
-- finite type family
data Fin : Nat → Set where
zero : {n : Nat} → Fin (suc n)
suc : {n : Nat} → Fin n → Fin (suc n)
lookupVec : {A : Set} {n : Nat} → Vec A n → Fin n → A
lookupVec [] ()
lookupVec (x :: _) zero = x
lookupVec (_ :: xs) (suc i) = lookupVec xs i
-- ex 2.4
putVec : {A : Set} {n : Nat} → Fin n → A → Vec A n → Vec A n
putVec zero a (_ :: xs) = a :: xs
putVec (suc i) a (x :: xs) = x :: putVec i a xs
ex-vxs : Vec Nat 4
ex-vxs = 0 :: 1 :: 2 :: 3 :: []
lookupVecex-vxs0 : IsTrue (lookupVec ex-vxs zero =Nat 0)
lookupVecex-vxs0 = is-true
lookupVecex-vxs3 : IsTrue (lookupVec ex-vxs (suc (suc (suc zero))) =Nat 3)
lookupVecex-vxs3 = is-true
putVecex-vxs3 : IsTrue (putVec (suc (suc zero)) 22 ex-vxs =Vec-Nat (0 :: 1 :: 22 :: 3 :: []))
putVecex-vxs3 = is-true
{-
dependent pair type - aka Σ type
aka Σ type because can be seen as sum (or disjoint union) of all the types B x
- where 1st component is viewed as a label indicating
which type of the family the 2nd belong to
generalization of pair type A × B
- where type of 2nd component can be different depending on value of 1st
- e.g., Σ Nat (Vec Bool)
(or equivalently, Σ Nat (λn → Vec Bool n))
contains elements
2 , (true :: false :: [])
and
0 , []
but not
2 , [] (since [] does not have type Vec Bool 2).
-}
-- function
-- v
data Σ (A : Set) (B : A → Set) : Set where
_,_ : (x : A) → B x → Σ A B
-- see Σ as generalization of normal pair : normal pair ignores its input
_×'_ : (A B : Set) → Set
A ×' B = Σ A (λ _ → B)
-- ex 2.5
×-to-×' : {A B : Set} → (A × B) → (A ×' B)
×-to-×' (a , b) = a , b
×'-to-× : {A B : Set} → (A ×' B) → (A × B)
×'-to-× (a , b) = a , b
-- Σ USE CASE : hide type info
-- e.g., hide length of vector
List' : (A : Set) → Set
List' A = Σ Nat (Vec A)
-- ex 2.6
list-to-vec : {A : Set} → (l : List A) → Vec A (length l)
list-to-vec [] = []
list-to-vec (x :: xs) = x :: list-to-vec xs
vec-to-list : {A : Set} {n : Nat} → Vec A n → List A
vec-to-list [] = []
vec-to-list (x :: xs) = x :: vec-to-list xs
list-to-list' : {A : Set} → List A → List' A
list-to-list' l = length l , list-to-vec l
list'-to-list : {A : Set} → List' A → List A
list'-to-list (_ , v) = vec-to-list v
-- if Nat relations existed at this point this function would be very different
lookup-List' : {A : Set} → List' A -> Nat -> Maybe A
lookup-List' (_ , []) _ = nothing
lookup-List' (_ , (x :: _)) zero = just x
lookup-List' (_ , (_ :: xs)) (suc n) = lookup-List' ((list-to-list' (vec-to-list xs))) n
ex-l'xs : List' Nat
ex-l'xs = (4 , 0 :: 1 :: 2 :: 3 :: [])
lookup-List'[]0 : IsTrue (lookup-List' (0 , []) 0 =Maybe-Nat nothing)
lookup-List'[]0 = is-true
lookup-List'ex-l'xs0 : IsTrue (lookup-List' ex-l'xs 0 =Maybe-Nat (just 0))
lookup-List'ex-l'xs0 = is-true
lookup-List'ex-l'xs1 : IsTrue (lookup-List' ex-l'xs 1 =Maybe-Nat (just 1))
lookup-List'ex-l'xs1 = is-true
lookup-List'ex-l'xs9 : IsTrue (lookup-List' ex-l'xs 9 =Maybe-Nat nothing)
lookup-List'ex-l'xs9 = is-true
------------------------------------------------------------------------------
-- 3 The Curry-Howard correspondence
-- can interpret logical propositions — such as “P and Q”, “not P”, “P implies Q”, ...
-- as types whose inhabitants are valid proofs of that proposition.
--------------------------------------------------
-- PROPOSITIONAL LOGIC
-- ex 3.1
data Either (A B : Set) : Set where
left : A → Either A B
right : B → Either A B
cases : {A B C : Set} → Either A B → (A → C) → (B → C) → C
cases (left a) fac _ = fac a
cases (right b) _ fbc = fbc b
cases-left : IsTrue (cases (left 3) (2 +_) (2 *_) =Nat 5)
cases-left = is-true
cases-right : IsTrue (cases (right 3) (2 +_) (2 *_) =Nat 6)
cases-right = is-true
{-
-------------------------
TRUTH : true : the proposition that always holds no matter what.
Proving it is straightforward: do not need to provide any assumptions.
Assuming true in a proof does not provide any new information.
'true' corresponds to the unit type
-}
data ⊤ : Set where
tt : ⊤
{-
-------------------------
FALSITY. the proposition that is never true.
There are no ways to prove it.
Represented by empty type : datatype with no constructors
-}
data ⊥ : Set where
{-
given a proof p of “false” (which can't happen because no constructors)
- “ex falso quodlibet” : “from falsity follows anything”)
- can can get a proof of any proposition
-}
absurd : {A : Set} → ⊥ → A
absurd ()
{-
-------------------------
NEGATION : the type P → ⊥
EQUIVALENCE. “P is equivalent to Q” as (P → Q) × (Q → P)
Propositional logic versus boolean logic.
types ⊤ and ⊥ seem similar to booleans true and false
- true and false are VALUES : can manipulate and return
- ⊤ and and ⊥ are TYPES
- not possible to check whether a given type ⊤ or ⊥
-}
curryCompose : {P Q R : Set} → (P → Q) × (Q → R) -> (P → R)
curryCompose (f , g) = λ x → g (f x)
-- ex 3.2
if-A-then-B-implies-A : {A B : Set} → A → (B → A)
if-A-then-B-implies-A a = λ _ → a
if-A-and-true-then-A-or-false : {A : Set} → (A × ⊤) → Either A ⊥
if-A-and-true-then-A-or-false (a , ⊤) = left a
uncurry : {A B C : Set} → (A → (B → C)) → (A × B) → C
uncurry f = λ a×b → f (fst a×b) (snd a×b)
ex32x : {A B C : Set} → (A × Either B C) → Either (A × B) (A × C)
ex32x (a , left b) = left (a , b)
ex32x (a , right c) = right (a , c)
ex32y : {A B C D : Set} → ((A → C) × (B → D)) → (A × B) → (C × D)
ex32y (ac , bd) (a , b) = ac a , bd b
{-
--------------------------------------------------
-- PREDICATE LOGIC
to prove propositions that say something about a given VALUE or FUNCTION
e.g., 6 is even
length (map f xs) is equal to length xs for all xs
there exists a number n such that n + n = 12
Curry-Howard : propositions are types
can define new propositions by defining new data types
e.g.,
-}
-- index
-- v
data IsEven : Nat → Set where
even-zero : IsEven zero
even-suc2 : {n : Nat} → IsEven n → IsEven (suc (suc n))
6-is-even : IsEven 6
6-is-even = even-suc2 (even-suc2 (even-suc2 even-zero))
7-is-not-even : IsEven 7 → ⊥
7-is-not-even (even-suc2 (even-suc2 (even-suc2 ())))
-- ^ -- absurb pattern as arg
{-
-- useful predicate
-- states that a given Bool is true
data IsTrue : Bool → Set where
is-true : IsTrue true
_=Nat_ : Nat → Nat → Bool
zero =Nat zero = true
(suc x) =Nat (suc y) = x =Nat y
_ =Nat _ = false
-}
length-is-3 : IsTrue (length (1 :: 2 :: 3 :: []) =Nat 3)
length-is-3 = is-true
{-
Defining properties as functions.
Can define properties as
- data types, or
- functions that return a value of type Set
e..g.,
-}
IsTrue’ : Bool → Set
IsTrue’ true = ⊤
IsTrue’ false = ⊥
{-
Function approach often results in proofs that are shorter, but less readable.
Also less general, as some types (e.g., identity type in next section)
can only be defined as a data type.
BEST PRACTICE: use data types (not functions)
--------------------------------------------------
UNIVERSAL QUANTIFICATION : “∀ x of type A, P(x)”
to prove : provide proof of P(v) for EVERY concrete value v : A.
i.e., a function λv → P v
in opposite direction
assume a f of “∀ x of type A, P(x)”
and given a concrete v : A
then can the proof to the case of v to get a proof f v of P(v)
under Curry-Howard, universal quantification corresponds to dependent function
(x : A) → P x
-}
double : Nat → Nat
double zero = zero
double (suc n) = suc (suc (double n))
-- ∀ n : Nat, double n is an even number
-- 'double-is-even' is a dependent function : return TYPE depends on input VALUE
-- pattern matching here is "proof by cases"
-- recursion here is "induction on n"
double-is-even : (n : Nat) → IsEven (double n)
double-is-even zero = even-zero
double-is-even (suc m) = even-suc2 (double-is-even m)
n-equals-n : (n : Nat) → IsTrue (n =Nat n)
n-equals-n zero = is-true
n-equals-n (suc m) = n-equals-n m
{-
--------------------------------------------------
EXISTENTIAL QUANTIFICATION : “∃ a x : A such that P( x )”
to prove : provide a concrete v : A, and a proof that P(v) holds
i.e. a pair (v : A, P v)
in opposite direction
given proof z of “∃ a x : A such that P( x )”
then extract the witness fst z : A
and the proof snd z : P (fst z)
under Curry-Howard, existential quantification corresponds to the dependent pair type
Σ A ( λ x → P x ).
-}
-- ∃ an n such that n + n = 12
half-a-dozen : Σ Nat (λ n → IsTrue ((n + n) =Nat 12))
half-a-dozen = 6 , is-true
-- any number n is either 0 or the successor of another number m
-- ∀ n, n is 0
-- or ∃ m such that n is suc m
zero-or-suc : (n : Nat) → Either (IsTrue (n =Nat 0))
(Σ Nat (λ m → IsTrue (n =Nat (suc m))))
zero-or-suc zero = left is-true
zero-or-suc (suc m) = right (m , n-equals-n m)
{-
--------------------------------------------------
Propositional logic Type System
------------------------------------------------------------
proposition P type
proof of a proposition p : P program of a type
conjunction P × Q pair type
disjunction Either P Q either type
implication P → Q function type
truth ⊤ unit type
falsity ⊥ empty type
negation P → ⊥ function to ⊥
equivalence (P → Q) × (Q → P) pair of two functions
------------------------------------------------------------
Predicate log
universal quantification (x : A) → P x dependent function type
existential quantification Σ A (λ x → P x ) dependent pair type
--------------------------------------------------
-- IDENTITY TYPE : EQUALITY at any type (to avoid =Nat, =Vec-Nat, ...)
Martin-Löf introduced a new type x ≡ y, called the IDENTITY TYPE (NOT FUNCTION)
if x and y are equal, then x ≡ y has a single inhabitant refl
- behaves like the unit type ⊤
if x and y are distinct, then x ≡ y has no constructors
- behaves like the empty type ⊥
-}
data _≡_ {A : Set} : A → A → Set where
-- ‘reflexivity’
refl : {x : A} → x ≡ x
infix 4 _≡_
{-# BUILTIN EQUALITY _≡_ #-}
one-plus-one-IsTrue : IsTrue ((1 + 1) =Nat 2)
one-plus-one-IsTrue = is-true
one-plus-one : 1 + 1 ≡ 2
one-plus-one = refl
{-
zero-not-one-not-IsTrue : IsTrue (0 =Nat 1)
zero-not-one-not-IsTrue = {!!}
-}
zero-not-one : 0 ≡ 1 → ⊥
zero-not-one ()
-- prove facts about polymorphic types
id-returns-input : {A : Set}
→ (x : A)
→ id x ≡ x
id-returns-input _ = refl
-- unit tests using identity type
length-test1 : length (1 :: 2 :: []) ≡ 2
length-test1 = refl
-- symmetry of equality
sym : {A : Set} {x y : A} → x ≡ y → y ≡ x
sym refl = refl
-- transitivity of equality
trans : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
-- congruence of equality
cong : {A B : Set} {x y : A} → (f : A → B) → x ≡ y → f x ≡ f y
cong f refl = refl
{-
If a and b can be unified by instantiating some of the variables, then can match on refl.
If a and b are different (e.g. different constructors), then match on absurb pattern ().
Agda canNOT always tell if they are different.
-}
------------------------------------------------------------------------------
-- 4 EQUATIONAL REASONING
begin_ : {A : Set} → {x y : A} → x ≡ y → x ≡ y
begin p = p
_end : {A : Set} → (x : A) → x ≡ x
x end = refl
_=⟨_⟩_ : {A : Set} → (x : A) → {y z : A} → x ≡ y → y ≡ z → x ≡ z
x =⟨ p ⟩ q = trans p q
_=⟨⟩_ : {A : Set} → (x : A) → {y : A} → x ≡ y → x ≡ y
x =⟨⟩ q = x =⟨ refl ⟩ q
infix 1 begin_
infix 3 _end
infixr 2 _=⟨_⟩_
infixr 2 _=⟨⟩_
-- create singleton list
[_] : {A : Set} → A → List A
[ x ] = x :: []
reverse : {A : Set} → List A → List A
reverse [] = []
reverse (x :: xs) = reverse xs ++ [ x ]
-- reverse has no effect on singleton lists
reverse-singleton : {A : Set}
→ (x : A)
→ reverse [ x ] ≡ [ x ]
reverse-singleton x =
begin
reverse [ x ] =⟨⟩ -- definition of [_]
reverse (x :: []) =⟨⟩ -- applying reverse (second clause)
reverse [] ++ [ x ] =⟨⟩ -- applying reverse (first clause)
[] ++ [ x ] =⟨⟩ -- applying _++_
[ x ]
end
-- proof by cases and induction
not-not : (b : Bool)
→ not (not b) ≡ b
not-not true =
begin
not (not true) =⟨⟩
not false =⟨⟩ -- apply inner not
true -- apply not
end
not-not false =
begin
not (not false) =⟨⟩
not true =⟨⟩
false
end
-- prove fact about Nat by induction (i.e., recursion)
add-n-zero : (n : Nat)
→ n + zero ≡ n
add-n-zero zero =
begin
zero + zero =⟨⟩
zero =⟨⟩
zero
end
add-n-zero (suc n) =
begin
(suc n) + zero =⟨⟩ -- applying +
suc (n + zero) =⟨ cong suc (add-n-zero n) ⟩ -- using induction hypothesis
suc n
end
add-n-zero' : (n : Nat)
→ n + zero ≡ n
add-n-zero' zero = refl
add-n-zero' (suc n) = cong suc (add-n-zero' n)
add-assoc : (x y z : Nat)
→ x + (y + z) ≡ (x + y) + z
add-assoc zero y z =
begin
zero + (y + z) =⟨⟩ -- def of +
y + z =⟨⟩ -- unapply +
(zero + y) + z
end
add-assoc (suc x) y z =
begin
(suc x) + (y + z) =⟨⟩ -- def of +
suc (x + (y + z)) =⟨ cong suc (add-assoc x y z) ⟩ -- inductive hypo
suc ((x + y) + z) =⟨⟩ -- unapply outer add
(suc (x + y)) + z =⟨⟩ -- unapply inner add
((suc x) + y) + z
end
-- ex 4.1
add-suc : (m n : Nat)
→ m + suc n ≡ suc (m + n)
add-suc zero n =
begin
zero + suc n =⟨⟩ -- def of +
suc n =⟨⟩
suc (zero + n)
end
add-suc (suc m) n = -- cong suc (add-suc m n)
begin
suc m + suc n =⟨⟩ -- def of +
suc (m + suc n) =⟨ cong suc (add-suc m n) ⟩
suc (suc m + n)
end
--use add-suc and add-n-zero
+-comm : (m n : Nat)
→ m + n ≡ n + m
+-comm zero n = sym (add-n-zero n)
+-comm (suc m) n
rewrite -- suc m + n ≡ n + suc m
-- suc (m + n) ≡ n + suc m
+-comm m n -- suc (n + m) ≡ n + suc m
| sym (add-suc n m) -- n + suc m ≡ n + suc m
= refl
+-comm' : (m n : Nat)
→ m + n ≡ n + m
+-comm' zero n =
begin
zero + n =⟨⟩ -- def of +
n =⟨ sym (add-n-zero n) ⟩ -- add zero to right
n + zero
end
+-comm' (suc m) n =
begin
suc m + n =⟨⟩ -- def of +
suc (m + n) =⟨ cong suc (+-comm m n) ⟩
suc (n + m) =⟨ sym (add-suc n m) ⟩
n + suc m
end
--------------------------------------------------
-- induction on lists
-- ex 4.2
replicate : {A : Set} → Nat → A → List A
replicate zero x = []
replicate (suc n) x = x :: replicate n x
length-replicate : {A : Set} {a : A}
→ (n : Nat)
→ length (replicate n a) ≡ n
length-replicate zero = refl
length-replicate (suc n) = cong suc (length-replicate n)
-- ex 4.3
append-[] : {A : Set}
→ (xs : List A)
→ xs ++ [] ≡ xs
append-[] [] = refl
append-[] (x :: xs) = cong (x ::_) (append-[] xs)
append-assoc : {A : Set}
→ (xs ys zs : List A)
→ (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs)
append-assoc [] ys zs = refl
append-assoc (x :: xs) ys zs -- (((x :: xs) ++ ys) ++ zs) ≡ ((x :: xs) ++ (ys ++ zs))
-- x :: ((xs ++ ys) ++ zs) ≡ x :: (xs ++ (ys ++ zs))
= cong (x ::_) (append-assoc xs ys zs)
reverse-distributivity : {A : Set}
→ (xs ys : List A)
→ reverse (xs ++ ys) ≡ reverse ys ++ reverse xs
reverse-distributivity [] ys = sym (append-[] (reverse ys))
reverse-distributivity (x :: xs) ys
-- reverse ((x :: xs) ++ ys) ≡ (reverse ys ++ reverse (x :: xs))
-- (reverse (xs ++ ys) ++ (x :: [])) ≡ (reverse ys ++ (reverse xs ++ (x :: [])))
rewrite
reverse-distributivity xs ys
-- ((reverse ys ++ reverse xs) ++ (x :: []))
-- ≡ (reverse ys ++ (reverse xs ++ (x :: [])))
| sym (append-assoc (reverse ys) (reverse xs) (x :: []))
= refl
reverse-reverse : {A : Set}
→ (xs : List A)
→ reverse (reverse xs) ≡ xs
reverse-reverse [] = refl
reverse-reverse (x :: xs) -- reverse (reverse (x :: xs)) ≡ x :: xs
-- reverse (reverse xs ++ (x :: [])) ≡ x :: xs
rewrite
-- NOTE
-- v
reverse-distributivity (reverse xs) [ x ]
-- x :: reverse (reverse xs) ≡ x :: xs
-- can rewrite here then refl
--| reverse-reverse xs -- x :: xs ≡ x :: xs
--= refl
-- or use 'cong' on rightof '='
= cong (x ::_) (reverse-reverse xs)
{-
map satisfies functor laws:
- identity : map id = id
- composition : map (g . h) = map g . h
-}
map-id : {A : Set}
→ (xs : List A)
→ map id xs ≡ xs
map-id [] = refl
map-id (x :: xs) -- map id (x :: xs) ≡ x :: xs
-- id x :: map id xs ≡ x :: xs
= cong (x ::_) (map-id xs)
_◦_ : {A B C : Set} → (B → C) → (A → B) → (A → C)
g ◦ h = λ x → g (h x)
map-compose : {A B C : Set}
→ (f : B → C) → (g : A → B) → (xs : List A)
→ map (f ◦ g) xs ≡ map f (map g xs)
map-compose f g [] = refl
map-compose f g (x :: xs)
-- map (f ◦ g) (x :: xs) ≡ map f (map g (x :: xs))
-- (f ◦ g) x :: map (f ◦ g) xs ≡ f (g x) :: map f (map g xs)
{- this
rewrite
sym (map-compose f g xs)
-- f (g x) :: map (λ x₁ → f (g x₁)) xs ≡
f (g x) :: map (λ x₁ → f (g x₁)) xs
= refl
-}
-- or this
= cong (f (g x) ::_) (map-compose f g xs)
-- ex 4.4
length-map : {A B : Set} {f : A → B}
→ (xs : List A)
→ length (map f xs) ≡ length xs
length-map [] = refl
length-map (x :: xs) -- length (map f (x :: xs)) ≡ length (x :: xs)
-- suc (length (map f xs)) ≡ suc (length xs)
= cong suc (length-map xs)
-- ex 4.5
take : {A : Set} → List A → Nat → List A
take _ zero = []
take [] (suc n) = []
take (x :: xs) (suc n) = x :: take xs n
take-0 : take ex-xs 0 ≡ []
take-0 = refl
take-1 : take ex-xs 1 ≡ 0 :: []
take-1 = refl
take-2 : take ex-xs 2 ≡ 0 :: 1 :: []
take-2 = refl
take-3 : take ex-xs 3 ≡ 0 :: 1 :: 2 :: []
take-3 = refl
take-4 : take ex-xs 4 ≡ ex-xs
take-4 = refl
take-5 : take ex-xs 5 ≡ ex-xs
take-5 = refl
drop : {A : Set} → List A → Nat → List A
drop xs zero = xs
drop [] (suc x) = []
drop (_ :: xs) (suc n) = drop xs n
drop-0 : drop ex-xs 0 ≡ ex-xs
drop-0 = refl
drop-1 : drop ex-xs 1 ≡ 1 :: 2 :: 3 :: []
drop-1 = refl
drop-2 : drop ex-xs 2 ≡ 2 :: 3 :: []
drop-2 = refl
drop-3 : drop ex-xs 3 ≡ 3 :: []
drop-3 = refl
drop-4 : drop ex-xs 4 ≡ []
drop-4 = refl
drop-5 : drop ex-xs 5 ≡ []
drop-5 = refl
take-drop : {A : Set} → (xs : List A) → (n : Nat) → take xs n ++ drop xs n ≡ xs
take-drop [] zero = refl
take-drop [] (suc n) = refl
take-drop (x :: xs) zero = refl
take-drop (x :: xs) (suc n) -- (take (x :: xs) (suc n) ++ drop (x :: xs) (suc n)) ≡ x :: xs
-- x :: (take xs n ++ drop xs n) ≡ x :: xs
= cong (x ::_) (take-drop xs n)
--------------------------------------------------
-- verifying optimizations
-- list optimization
reverse-acc : {A : Set} → List A → List A → List A
reverse-acc [] ys = ys
reverse-acc (x :: xs) ys = reverse-acc xs (x :: ys)
reverse' : {A : Set} → List A → List A
reverse' xs = reverse-acc xs []
reverse-acc-lemma : {A : Set}
→ (xs ys : List A)
→ reverse-acc xs ys ≡ reverse xs ++ ys
reverse-acc-lemma [] _ = refl
reverse-acc-lemma (x :: xs) ys -- reverse-acc (x :: xs) ys ≡ (reverse (x :: xs) ++ ys)
-- reverse-acc xs (x :: ys) ≡ ((reverse xs ++ (x :: [])) ++ ys)
rewrite
append-assoc (reverse xs) [ x ] ys
-- reverse-acc xs (x :: ys) ≡ (reverse xs ++ (x :: ys))
| reverse-acc-lemma xs (x :: ys)
-- (reverse xs ++ (x :: ys)) ≡ (reverse xs ++ (x :: ys))
= refl
reverse'-reverse : {A : Set}
→ (xs : List A)
→ reverse' xs ≡ reverse xs
reverse'-reverse [] = refl
reverse'-reverse (x :: xs) -- reverse' (x :: xs) ≡ reverse (x :: xs)
-- reverse' (x :: xs) ≡ (reverse xs ++ (x :: []))
rewrite
reverse-acc-lemma xs [ x ] -- (reverse xs ++ (x :: [])) ≡ (reverse xs ++ (x :: []))
= refl
-- tree optimization
data Tree (A : Set) : Set where
leaf : A → Tree A
node : Tree A → Tree A → Tree A
flatten : {A : Set} → Tree A → List A
flatten (leaf a) = [ a ]
flatten (node t1 t2) = flatten t1 ++ flatten t2
flatten-acc : {A : Set} → Tree A → List A → List A
flatten-acc (leaf x) xs = x :: xs
flatten-acc (node t1 t2) xs = flatten-acc t1 (flatten-acc t2 xs)
flatten' : {A : Set} → Tree A → List A
flatten' t = flatten-acc t []
flatten-acc-lemma : {A : Set}
→ (t : Tree A) → (ys : List A)
→ flatten-acc t ys ≡ flatten t ++ ys
flatten-acc-lemma (leaf x) _ = refl
flatten-acc-lemma (node t1 t2) ys
-- flatten-acc (node t1 t2) ys ≡ (flatten (node t1 t2) ++ ys)
-- flatten-acc t1 (flatten-acc t2 ys) ≡ ((flatten t1 ++ flatten t2) ++ ys)
rewrite
flatten-acc-lemma t1 (flatten-acc t2 ys)
-- (flatten t1 ++ flatten-acc t2 ys) ≡ ((flatten t1 ++ flatten t2) ++ ys)
| flatten-acc-lemma t2 ys
-- (flatten t1 ++ (flatten t2 ++ ys)) ≡ ((flatten t1 ++ flatten t2) ++ ys)
| append-assoc (flatten t1) (flatten t2) ys
-- (flatten t1 ++ (flatten t2 ++ ys)) ≡ (flatten t1 ++ (flatten t2 ++ ys))
= refl
flatten-acc-flatten : {A : Set}
→ (t : Tree A) → (ys : List A)
→ flatten-acc t ys ≡ flatten t ++ ys
flatten-acc-flatten (leaf x) ys = refl
-- flatten-acc (leaf x) ys ≡ (flatten (leaf x) ++ ys)
flatten-acc-flatten (node t1 t2) ys
-- flatten-acc (node t1 t2) ys ≡ (flatten (node t1 t2) ++ ys)
-- flatten-acc t1 (flatten-acc t2 ys) ≡ ((flatten t1 ++ flatten t2) ++ ys)
rewrite
flatten-acc-lemma t2 ys
-- flatten-acc t1 (flatten t2 ++ ys) ≡ ((flatten t1 ++ flatten t2) ++ ys)
| flatten-acc-lemma t1 (flatten t2 ++ ys)
-- (flatten t1 ++ (flatten t2 ++ ys)) ≡ ((flatten t1 ++ flatten t2) ++ ys)
| append-assoc (flatten t1) (flatten t2) ys
-- (flatten t1 ++ (flatten t2 ++ ys)) ≡ (flatten t1 ++ (flatten t2 ++ ys))
= refl
-- ex 4.6
flatten'-flatten : {A : Set}
→ (t : Tree A)
→ flatten' t ≡ flatten t
flatten'-flatten (leaf x) = refl
flatten'-flatten (node t1 t2)
-- flatten' (node t1 t2) ≡ flatten (node t1 t2)
-- flatten' (node t1 t2) ≡ (flatten t1 ++ flatten t2)
rewrite
sym (flatten-acc-flatten t1 (flatten t2))
-- flatten-acc t1 (flatten-acc t2 []) ≡ flatten-acc t1 (flatten t2)
| flatten-acc-flatten t2 []
-- flatten-acc t1 (flatten t2 ++ []) ≡ flatten-acc t1 (flatten t2)
| append-[] (flatten t2)
-- flatten-acc t1 (flatten t2) ≡ flatten-acc t1 (flatten t2)
= refl
--------------------------------------------------
-- compiler correctness
data Expr : Set where
valE : Nat → Expr
addE : Expr → Expr → Expr
eval : Expr → Nat
eval (valE x) = x
eval (addE e1 e2) = eval e1 + eval e2
data Op : Set where
PUSH : Nat → Op
ADD : Op
Stack = List Nat
Code = List Op
exec : Code → Stack → Stack
exec [] s = s
exec (PUSH x :: c) s = exec c (x :: s)
exec (ADD :: c) (m :: n :: s) = exec c (n + m :: s)
exec (ADD :: c) _ = []
compile' : Expr → Code → Code
compile' (valE x) c = PUSH x :: c
compile' (addE e1 e2) c = compile' e1 (compile' e2 (ADD :: c))
compile : Expr → Code
compile e = compile' e []
compile'-exec-eval : (e : Expr) → (s : Stack) → (c : Code)
→ exec (compile' e c) s ≡ exec c (eval e :: s)
compile'-exec-eval (valE _) _ _ = refl
compile'-exec-eval (addE e1 e2) s c
-- exec (compile' (addE e1 e2) c) s ≡ exec c (eval (addE e1 e2) :: s)
-- exec (compile' e1 (compile' e2 (ADD :: c))) s ≡ exec c (eval e1 + eval e2 :: s)
rewrite
compile'-exec-eval e1 s (compile' e2 (ADD :: c))
-- exec (compile' e2 (ADD :: c)) (eval e1 :: s) ≡ exec c (eval e1 + eval e2 :: s)
| compile'-exec-eval e2 (eval e1 :: s) (ADD :: c)
-- exec c (eval e1 + eval e2 :: s) ≡ exec c (eval e1 + eval e2 :: s)
= refl
compile-exec-eval : (e : Expr) → exec (compile e) [] ≡ [ eval e ]
compile-exec-eval e = compile'-exec-eval e [] []
|
{
"alphanum_fraction": 0.4924240008,
"avg_line_length": 29.7146919431,
"ext": "agda",
"hexsha": "43858fda06af1dbd85accae6afff72b146d88105",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/paper/2021-03-Jesper_Cockx-Programming_and_Proving_in_Agda/z.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/paper/2021-03-Jesper_Cockx-Programming_and_Proving_in_Agda/z.agda",
"max_line_length": 99,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/paper/2021-03-Jesper_Cockx-Programming_and_Proving_in_Agda/z.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 10670,
"size": 31349
}
|
module hott.topology.theorems where
open import hott.topology
open import hott.topology.loopspace.theorems public
|
{
"alphanum_fraction": 0.852173913,
"avg_line_length": 23,
"ext": "agda",
"hexsha": "e69db0eab5cf4a8618016d974cdcae7b2acc4da1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "piyush-kurur/hott",
"max_forks_repo_path": "agda/hott/topology/theorems.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "piyush-kurur/hott",
"max_issues_repo_path": "agda/hott/topology/theorems.agda",
"max_line_length": 51,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "piyush-kurur/hott",
"max_stars_repo_path": "agda/hott/topology/theorems.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 28,
"size": 115
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Axiom.Omniscience where
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Transport
open import Cubical.Data.Bool
renaming (Bool to 𝟚; Bool→Type to ⟨_⟩)
open import Cubical.Data.Empty as Empty
open import Cubical.Data.Sum as Sum
open import Cubical.HITs.PropositionalTruncation as PT
open import Cubical.Relation.Nullary
private
variable
ℓ ℓ' : Level
A : Type ℓ
-- Lesser limited principle of omniscience
--
-- If two decidable predicates cannot both be satisfied, we can
-- determine that one predicate cannot be satisfied.
LLPO : Type ℓ → Type ℓ
LLPO A
= ∀(P Q : A → 𝟚)
→ (∀ x y → ⟨ P x ⟩ → ⟨ Q y ⟩ → ⊥)
→ ∥ (∀ x → ¬ ⟨ P x ⟩) ⊎ (∀ y → ¬ ⟨ Q y ⟩) ∥₁
isPropLLPO : isProp (LLPO A)
isPropLLPO = isPropΠ3 λ _ _ _ → squash₁
-- As above, but without ensuring propositionality
LLPO∞ : Type ℓ → Type ℓ
LLPO∞ A
= ∀(P Q : A → 𝟚)
→ (∀ x y → ⟨ P x ⟩ → ⟨ Q y ⟩ → ⊥)
→ (∀ x → ¬ ⟨ P x ⟩) ⊎ (∀ y → ¬ ⟨ Q y ⟩)
LLPO∞→LLPO : LLPO∞ A → LLPO A
LLPO∞→LLPO llpo' P Q ¬both = ∣ llpo' P Q ¬both ∣₁
-- Weak limited principle of omniscience
--
-- It is decidable whether or not a decidable predicate never holds.
WLPO : Type ℓ → Type ℓ
WLPO A = ∀(P : A → 𝟚) → Dec (∀ x → ¬ ⟨ P x ⟩)
WLPO' : Type ℓ → Type ℓ
WLPO' A = ∀(P : A → 𝟚) → Dec (P ≡ const false)
isPropWLPO : isProp (WLPO A)
isPropWLPO = isPropΠ λ P → isPropDec (isPropΠ λ x → isProp¬ ⟨ P x ⟩)
isPropWLPO' : isProp (WLPO' A)
isPropWLPO' = isPropΠ λ P → isPropDec (isSet→ isSetBool P (const false))
module WLPO≃ where
points : (P : A → 𝟚) → P ≡ const false → ∀ x → ¬ ⟨ P x ⟩
points P p x = subst (λ Q → ⟨ Q x ⟩) p
total : (P : A → 𝟚) → (∀ x → ¬ ⟨ P x ⟩) → P ≡ const false
total P never i x with P x | never x
... | false | _ = false
... | true | ¬⊤ = Empty.rec {A = true ≡ false} (¬⊤ _) i
open Iso
total≡points : ∀(P : A → 𝟚) → (P ≡ const false) ≡ (∀ x → ¬ ⟨ P x ⟩)
total≡points P = isoToPath λ where
.fun → points P
.inv → total P
.rightInv never → isPropΠ (λ x → isProp¬ ⟨ P x ⟩) _ never
.leftInv α≡f → isSet→ isSetBool P (const false) _ α≡f
WLPO≡WLPO' : WLPO A ≡ WLPO' A
WLPO≡WLPO' {A = A} i = (P : A → 𝟚) → Dec (WLPO≃.total≡points P (~ i))
WLPO→LLPO∞ : WLPO A → LLPO∞ A
WLPO→LLPO∞ {A = A} womn P Q ¬both with womn P
... | yes ∀¬P = inl ∀¬P
... | no ¬∀¬P = inr ∀¬Q where
∀¬Q : ∀ y → ¬ ⟨ Q y ⟩
∀¬Q y Qy = ¬∀¬P (λ x Px → ¬both x y Px Qy)
-- Limited principle of omniscience
--
-- Either a decidable predicate never holds, or it does
LPO : Type ℓ → Type ℓ
LPO A = ∀(P : A → 𝟚) → (∀ x → ¬ ⟨ P x ⟩) ⊎ ∥ Σ[ x ∈ A ] ⟨ P x ⟩ ∥₁
LPO→WLPO : LPO A → WLPO A
LPO→WLPO omn P with omn P
... | inl ∀¬P = yes ∀¬P
... | inr ∃P = no λ ∀¬P → PT.rec isProp⊥ (uncurry ∀¬P) ∃P
-- As above, but without truncation.
LPO∞ : Type ℓ → Type ℓ
LPO∞ A = ∀(P : A → 𝟚) → (∀ x → ¬ ⟨ P x ⟩) ⊎ (Σ[ x ∈ A ] ⟨ P x ⟩)
LPO∞→LPO : LPO∞ A → LPO A
LPO∞→LPO omn P = Sum.map (idfun _) ∣_∣₁ (omn P)
|
{
"alphanum_fraction": 0.5827664399,
"avg_line_length": 28.5833333333,
"ext": "agda",
"hexsha": "b12801aa931190880b284f985471c6ae7212fd2f",
"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/Axiom/Omniscience.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/Axiom/Omniscience.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Axiom/Omniscience.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": 1326,
"size": 3087
}
|
------------------------------------------------------------------------------
-- Properties of the divisibility relation
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Data.Nat.Divisibility.NotBy0.Properties where
open import Common.FOL.Relation.Binary.EqReasoning
open import LTC-PCF.Base
open import LTC-PCF.Base.Properties
open import LTC-PCF.Data.Nat
open import LTC-PCF.Data.Nat.Properties
open import LTC-PCF.Data.Nat.Divisibility.NotBy0
open import LTC-PCF.Data.Nat.Inequalities
open import LTC-PCF.Data.Nat.Inequalities.Properties
open import LTC-PCF.Data.Nat.Properties
------------------------------------------------------------------------------
-- Any positive number divides 0.
S∣0 : ∀ {n} → N n → succ₁ n ∣ zero
S∣0 {n} Nn = S≢0 , _ , nzero , sym (*-leftZero (succ₁ n))
-- 0 doesn't divide any number.
0∤x : ∀ {n} → ¬ (zero ∣ n)
0∤x (0≢0 , _) = ⊥-elim (0≢0 refl)
-- The divisibility relation is reflexive for positive numbers.
∣-refl-S : ∀ {n} → N n → succ₁ n ∣ succ₁ n
∣-refl-S {n} Nn = S≢0 , _ , nsucc nzero , sym (*-leftIdentity (nsucc Nn))
-- If x divides y and z then x divides y ∸ z.
x∣y→x∣z→x∣y∸z-helper : ∀ {m n o k k'} → N m → N k → N k' →
n ≡ k * succ₁ m →
o ≡ k' * succ₁ m →
n ∸ o ≡ (k ∸ k') * succ₁ m
x∣y→x∣z→x∣y∸z-helper {m} {n} {o} {k} {k'} Nm Nk Nk' h₁ h₂ =
n ∸ o ≡⟨ ∸-leftCong h₁ ⟩
k * succ₁ m ∸ o ≡⟨ ∸-rightCong h₂ ⟩
(k * succ₁ m) ∸ (k' * succ₁ m) ≡⟨ sym (*∸-leftDistributive Nk Nk' (nsucc Nm)) ⟩
(k ∸ k') * succ₁ m ∎
x∣y→x∣z→x∣y∸z : ∀ {m n o} → N m → N n → N o → m ∣ n → m ∣ o → m ∣ n ∸ o
x∣y→x∣z→x∣y∸z nzero Nn No (0≢0 , _) m∣o = ⊥-elim (0≢0 refl)
x∣y→x∣z→x∣y∸z {n = n} {o} (nsucc {m} Nm) Nn No
(_ , k , Nk , h₁)
(_ , k' , Nk' , h₂) =
(λ S≡0 → ⊥-elim (S≢0 S≡0))
, k ∸ k' , ∸-N Nk Nk' , x∣y→x∣z→x∣y∸z-helper Nm Nk Nk' h₁ h₂
-- If x divides y and z then x divides y + z.
x∣y→x∣z→x∣y+z-helper : ∀ {m n o k k'} → N m → N k → N k' →
n ≡ k * succ₁ m →
o ≡ k' * succ₁ m →
n + o ≡ (k + k') * succ₁ m
x∣y→x∣z→x∣y+z-helper {m} {n} {o} {k} {k'} Nm Nk Nk' h₁ h₂ =
n + o ≡⟨ +-leftCong h₁ ⟩
k * succ₁ m + o ≡⟨ +-rightCong h₂ ⟩
(k * succ₁ m) + (k' * succ₁ m) ≡⟨ sym (*+-leftDistributive Nk Nk' (nsucc Nm)) ⟩
(k + k') * succ₁ m ∎
x∣y→x∣z→x∣y+z : ∀ {m n o} → N m → N n → N o → m ∣ n → m ∣ o → m ∣ n + o
x∣y→x∣z→x∣y+z nzero Nn No (0≢0 , _) m∣o = ⊥-elim (0≢0 refl)
x∣y→x∣z→x∣y+z {n = n} {o} (nsucc {m} Nm) Nn No
(_ , k , Nk , h₁)
(_ , k' , Nk' , h₂) =
(λ S≡0 → ⊥-elim (S≢0 S≡0))
, k + k' , +-N Nk Nk' , x∣y→x∣z→x∣y+z-helper Nm Nk Nk' h₁ h₂
-- If x divides y and y is positive, then x ≤ y.
x∣S→x≤S : ∀ {m n} → N m → N n → m ∣ (succ₁ n) → m ≤ succ₁ n
x∣S→x≤S nzero Nn (0≢0 , _) = ⊥-elim (0≢0 refl)
x∣S→x≤S (nsucc {m} Nm) Nn (_ , .zero , nzero , Sn≡0*Sm) =
⊥-elim (0≢S (trans (sym (*-leftZero (succ₁ m))) (sym Sn≡0*Sm)))
x∣S→x≤S (nsucc {m} Nm) Nn (_ , .(succ₁ k) , nsucc {k} Nk , Sn≡Sk*Sm) =
subst (λ t₁ → succ₁ m ≤ t₁)
(sym Sn≡Sk*Sm)
(subst (λ t₂ → succ₁ m ≤ t₂)
(sym (*-Sx k (succ₁ m)))
(x≤x+y (nsucc Nm) (*-N Nk (nsucc Nm))))
|
{
"alphanum_fraction": 0.4425591099,
"avg_line_length": 42.2941176471,
"ext": "agda",
"hexsha": "a85c5a2fbdfd7a717dd0621e4c5564fa573fed7f",
"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/LTC-PCF/Data/Nat/Divisibility/NotBy0/Properties.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/LTC-PCF/Data/Nat/Divisibility/NotBy0/Properties.agda",
"max_line_length": 81,
"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/LTC-PCF/Data/Nat/Divisibility/NotBy0/Properties.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": 1543,
"size": 3595
}
|
{-
Finite Types
This file formalize the notion of Rijke finite type,
which is a direct generalization of Bishop finite set.
Basically, a type is (Rijke) n-finite if its i-th order
homotopy groups πᵢ are Bishop finite for i ≤ n.
Referrences:
https://github.com/EgbertRijke/OEIS-A000001
-}
{-# OPTIONS --safe #-}
module Cubical.Data.FinType.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.HITs.SetTruncation
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.Data.FinSet
private
variable
ℓ ℓ' : Level
n : ℕ
X : Type ℓ
-- the (Rijke) finite type
isFinType : (n : ℕ) → Type ℓ → Type ℓ
isFinType 0 X = isFinSet ∥ X ∥₂
isFinType (suc n) X = (isFinType 0 X) × ((a b : X) → isFinType n (a ≡ b))
isPropIsFinType : isProp (isFinType n X)
isPropIsFinType {n = 0} = isPropIsFinSet
isPropIsFinType {n = suc n} = isProp× isPropIsFinSet (isPropΠ2 (λ _ _ → isPropIsFinType {n = n}))
-- the type of finite types
FinType : (ℓ : Level)(n : ℕ) → Type (ℓ-suc ℓ)
FinType ℓ n = TypeWithStr ℓ (isFinType n)
-- basic numerical implications
isFinTypeSuc→isFinType : isFinType (suc n) X → isFinType n X
isFinTypeSuc→isFinType {n = 0} p = p .fst
isFinTypeSuc→isFinType {n = suc n} p .fst = p .fst
isFinTypeSuc→isFinType {n = suc n} p .snd a b = isFinTypeSuc→isFinType {n = n} (p .snd a b)
isFinType→isFinType0 : isFinType n X → isFinType 0 X
isFinType→isFinType0 {n = 0} p = p
isFinType→isFinType0 {n = suc n} p = p .fst
isFinTypeSuc→isFinType1 : isFinType (suc n) X → isFinType 1 X
isFinTypeSuc→isFinType1 {n = 0} p = p
isFinTypeSuc→isFinType1 {n = suc n} p .fst = p .fst
isFinTypeSuc→isFinType1 {n = suc n} p .snd a b = isFinType→isFinType0 {n = suc n} (p .snd a b)
|
{
"alphanum_fraction": 0.7079646018,
"avg_line_length": 28.25,
"ext": "agda",
"hexsha": "b700e887f35f8cc4b60fddf3397031974846b4cf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Data/FinType/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Data/FinType/Base.agda",
"max_line_length": 97,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Data/FinType/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 677,
"size": 1808
}
|
{-# OPTIONS --without-K --safe #-}
module Strict where
open import Agda.Builtin.Strict public
open import Level
infixr 0 _$!_
_$!_ : {A : Type a} {B : A → Type b} → (∀ x → B x) → ∀ x → B x
f $! x = primForce x f
{-# INLINE _$!_ #-}
infixr 0 let-bang
let-bang : {A : Type a} {B : A → Type b} → ∀ x → (∀ x → B x) → B x
let-bang = primForce
{-# INLINE let-bang #-}
syntax let-bang v (λ x → e) = let! x =! v in! e
infixr 0 lambda-bang
lambda-bang : {A : Type a} {B : A → Type b} → (∀ x → B x) → ∀ x → B x
lambda-bang f x = primForce x f
{-# INLINE lambda-bang #-}
syntax lambda-bang (λ x → e) = λ! x →! e
|
{
"alphanum_fraction": 0.5526315789,
"avg_line_length": 23.3846153846,
"ext": "agda",
"hexsha": "0f6975ad4457021d7af7233845e9812dd9bcd7cb",
"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": "Strict.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": "Strict.agda",
"max_line_length": 69,
"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": "Strict.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": 236,
"size": 608
}
|
module lambda.stack where
open import Relation.Binary.PropositionalEquality
infixr 40 _▸_
infixl 35 _∈_
data stack (T : Set) : Set where
ε : stack T
_▸_ : stack T → T → stack T
data _∈_ {T : Set} (x : T) : stack T → Set where
here : ∀ {Γ} → x ∈ Γ ▸ x
there : ∀ {Γ y} → x ∈ Γ → x ∈ Γ ▸ y
data _⊇_ {T : Set} : stack T → stack T → Set where
bot : ε ⊇ ε
skip : ∀ {Γ Δ x} → Γ ⊇ Δ → Γ ▸ x ⊇ Δ
keep : ∀ {Γ Δ x} → Γ ⊇ Δ → Γ ▸ x ⊇ Δ ▸ x
module _ {T : Set} where
id : ∀ {Γ : stack T} → Γ ⊇ Γ
id {ε} = bot
id {Γ ▸ x} = keep id
shift : ∀ {Γ Δ} {x : T} → Γ ⊇ Δ → x ∈ Δ → x ∈ Γ
shift bot ()
shift (skip x) v = there (shift x v)
shift (keep _) here = here
shift (keep x) (there y) = there (shift x y)
shift-id : ∀ {Γ : stack T} {x} → (e : x ∈ Γ) → shift id e ≡ e
shift-id here = refl
shift-id (there e) = cong there (shift-id e)
_∘⊇_ : {Γ Δ Λ : stack T} → Γ ⊇ Δ → Δ ⊇ Λ → Γ ⊇ Λ
bot ∘⊇ bot = bot
skip x ∘⊇ y = skip (x ∘⊇ y)
keep x ∘⊇ skip y = skip (x ∘⊇ y)
keep x ∘⊇ keep y = keep (x ∘⊇ y)
∘⊇-idˡ : {Γ Δ : stack T} → (w : Γ ⊇ Δ) → id ∘⊇ w ≡ w
∘⊇-idˡ bot = refl
∘⊇-idˡ (skip x) = cong skip (∘⊇-idˡ x)
∘⊇-idˡ (keep x) = cong keep (∘⊇-idˡ x)
∘⊇-idʳ : {Δ Γ : stack T} → (w : Γ ⊇ Δ) → w ∘⊇ id ≡ w
∘⊇-idʳ bot = refl
∘⊇-idʳ (skip x) = cong skip (∘⊇-idʳ x)
∘⊇-idʳ (keep x) = cong keep (∘⊇-idʳ x)
∘⊇-assoc : {Γ Δ Λ Ω : stack T} → (w₁ : Γ ⊇ Δ) → (w₂ : Δ ⊇ Λ) → (w₃ : Λ ⊇ Ω) → (w₁ ∘⊇ w₂) ∘⊇ w₃ ≡ w₁ ∘⊇ (w₂ ∘⊇ w₃)
∘⊇-assoc bot bot bot = refl
∘⊇-assoc (skip w₁) w₂ w₃ = cong skip (∘⊇-assoc w₁ w₂ w₃)
∘⊇-assoc (keep w₁) (skip w₂) w₃ = cong skip (∘⊇-assoc w₁ w₂ w₃)
∘⊇-assoc (keep w₁) (keep w₂) (skip w₃) = cong skip (∘⊇-assoc w₁ w₂ w₃)
∘⊇-assoc (keep w₁) (keep w₂) (keep w₃) = cong keep (∘⊇-assoc w₁ w₂ w₃)
|
{
"alphanum_fraction": 0.4883852691,
"avg_line_length": 29.4166666667,
"ext": "agda",
"hexsha": "d1bf880ddc0f28b602c8549f145c61855c42d51f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "09a231d9b3057d57b864070188ed9fe14a07eda2",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "Lapin0t/lambda",
"max_forks_repo_path": "lambda/stack.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09a231d9b3057d57b864070188ed9fe14a07eda2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "Lapin0t/lambda",
"max_issues_repo_path": "lambda/stack.agda",
"max_line_length": 115,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "09a231d9b3057d57b864070188ed9fe14a07eda2",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "Lapin0t/lambda",
"max_stars_repo_path": "lambda/stack.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 981,
"size": 1765
}
|
data ⊥ : Set where
p0 : Set → Set
p0 A = A
p1 : ⊥ → Set
p1 ()
p2 : ⊥ → ⊥
p2 ()
p3 : Set → ⊥
p3 = ?
|
{
"alphanum_fraction": 0.4077669903,
"avg_line_length": 7.3571428571,
"ext": "agda",
"hexsha": "5510f683b3fb14886071d8f018fa026eac4c1431",
"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": "9576d5b76e6a868992dbe52930712ac67697bed2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "anqurvanillapy/fpl",
"max_forks_repo_path": "agda/implication.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2",
"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": "anqurvanillapy/fpl",
"max_issues_repo_path": "agda/implication.agda",
"max_line_length": 18,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "anqurvanillapy/fpl",
"max_stars_repo_path": "agda/implication.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-24T22:47:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-24T22:47:47.000Z",
"num_tokens": 55,
"size": 103
}
|
record Additive {ℓ} (A : Set ℓ) : Set ℓ where
field
zero : A
_+_ : A → A → A
open Additive {{...}} public
record Subtractive {ℓ} (A : Set ℓ) {{ADD : Additive A}} : Set ℓ where
field
_-_ : A → A → A
neg : A → A
neg x = zero - x
open Subtractive {{...}} public
check : ∀ ℓ (A : Set ℓ) (ADD : Additive A) (SUB : Subtractive A {{ADD}}) → A → A
check ℓ A ADD SUB x = Subtractive.neg {ℓ} {A} {{ADD}} SUB x
|
{
"alphanum_fraction": 0.5422535211,
"avg_line_length": 21.3,
"ext": "agda",
"hexsha": "9cd089e6e3b84b7fb637247ab359ea4ec2136cc4",
"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/Issue1847.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/Issue1847.agda",
"max_line_length": 80,
"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/Issue1847.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": 168,
"size": 426
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Group.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Sigma
open import Cubical.Data.Prod renaming (_×_ to _×'_)
open import Cubical.Data.Int renaming (_+_ to _+Int_ ; _-_ to _-Int_)
open import Cubical.Data.Unit
open import Cubical.Algebra.Monoid hiding (⟨_⟩)
open import Cubical.Algebra.Semigroup hiding (⟨_⟩)
open import Cubical.Foundations.HLevels
private
variable
ℓ : Level
record IsGroup {G : Type ℓ}
(0g : G) (_+_ : G → G → G) (-_ : G → G) : Type ℓ where
no-eta-equality
constructor isgroup
field
isMonoid : IsMonoid 0g _+_
inverse : (x : G) → (x + (- x) ≡ 0g) × ((- x) + x ≡ 0g)
open IsMonoid isMonoid public
infixl 6 _-_
_-_ : G → G → G
x - y = x + (- y)
invl : (x : G) → (- x) + x ≡ 0g
invl x = inverse x .snd
invr : (x : G) → x + (- x) ≡ 0g
invr x = inverse x .fst
η-isGroup : {G : Type ℓ} {0g 0g' : G} {_+_ _+'_ : G → G → G} { -_ -'_ : G → G}
→ 0g ≡ 0g'
→ _+_ ≡ _+'_
→ -_ ≡ -'_
→ IsGroup 0g _+_ -_ ≡ IsGroup 0g' _+'_ -'_
η-isGroup id1 id2 id3 i = IsGroup (id1 i) (id2 i) (id3 i)
record Group : Type (ℓ-suc ℓ) where
no-eta-equality
constructor group
field
Carrier : Type ℓ
0g : Carrier
_+_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
isGroup : IsGroup 0g _+_ -_
infix 8 -_
infixr 7 _+_
open IsGroup isGroup public
Group₀ : Type₁
Group₀ = Group {ℓ-zero}
-- Extractor for the carrier type
⟨_⟩ : Group → Type ℓ
⟨_⟩ = Group.Carrier
isSetGroup : (G : Group {ℓ}) → isSet ⟨ G ⟩
isSetGroup G = Group.isGroup G .IsGroup.isMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
makeIsGroup : {G : Type ℓ} {0g : G} {_+_ : G → G → G} { -_ : G → G}
(is-setG : isSet G)
(assoc : (x y z : G) → x + (y + z) ≡ (x + y) + z)
(rid : (x : G) → x + 0g ≡ x)
(lid : (x : G) → 0g + x ≡ x)
(rinv : (x : G) → x + (- x) ≡ 0g)
(linv : (x : G) → (- x) + x ≡ 0g)
→ IsGroup 0g _+_ -_
IsGroup.isMonoid (makeIsGroup is-setG assoc rid lid rinv linv) = makeIsMonoid is-setG assoc rid lid
IsGroup.inverse (makeIsGroup is-setG assoc rid lid rinv linv) = λ x → rinv x , linv x
makeGroup : {G : Type ℓ} (0g : G) (_+_ : G → G → G) (-_ : G → G)
(is-setG : isSet G)
(assoc : (x y z : G) → x + (y + z) ≡ (x + y) + z)
(rid : (x : G) → x + 0g ≡ x)
(lid : (x : G) → 0g + x ≡ x)
(rinv : (x : G) → x + (- x) ≡ 0g)
(linv : (x : G) → (- x) + x ≡ 0g)
→ Group
Group.Carrier (makeGroup 0g _+_ -_ is-setG assoc rid lid rinv linv) = _
Group.0g (makeGroup 0g _+_ -_ is-setG assoc rid lid rinv linv) = 0g
Group._+_ (makeGroup 0g _+_ -_ is-setG assoc rid lid rinv linv) = _+_
Group.- makeGroup 0g _+_ -_ is-setG assoc rid lid rinv linv = -_
Group.isGroup (makeGroup 0g _+_ -_ is-setG assoc rid lid rinv linv) = makeIsGroup is-setG assoc rid lid rinv linv
makeGroup-right : ∀ {ℓ} {A : Type ℓ}
→ (id : A)
→ (comp : A → A → A)
→ (inv : A → A)
→ (set : isSet A)
→ (assoc : ∀ a b c → comp a (comp b c) ≡ comp (comp a b) c)
→ (rUnit : ∀ a → comp a id ≡ a)
→ (rCancel : ∀ a → comp a (inv a) ≡ id)
→ Group
makeGroup-right {A = A} id comp inv set assoc rUnit rCancel =
makeGroup id comp inv set assoc rUnit lUnit rCancel lCancel
where
_⨀_ = comp
abstract
lCancel : ∀ a → comp (inv a) a ≡ id
lCancel a =
inv a ⨀ a
≡⟨ sym (rUnit (comp (inv a) a)) ⟩
(inv a ⨀ a) ⨀ id
≡⟨ cong (comp (comp (inv a) a)) (sym (rCancel (inv a))) ⟩
(inv a ⨀ a) ⨀ (inv a ⨀ (inv (inv a)))
≡⟨ assoc _ _ _ ⟩
((inv a ⨀ a) ⨀ (inv a)) ⨀ (inv (inv a))
≡⟨ cong (λ □ → □ ⨀ _) (sym (assoc _ _ _)) ⟩
(inv a ⨀ (a ⨀ inv a)) ⨀ (inv (inv a))
≡⟨ cong (λ □ → (inv a ⨀ □) ⨀ (inv (inv a))) (rCancel a) ⟩
(inv a ⨀ id) ⨀ (inv (inv a))
≡⟨ cong (λ □ → □ ⨀ (inv (inv a))) (rUnit (inv a)) ⟩
inv a ⨀ (inv (inv a))
≡⟨ rCancel (inv a) ⟩
id
∎
lUnit : ∀ a → comp id a ≡ a
lUnit a =
id ⨀ a
≡⟨ cong (λ b → comp b a) (sym (rCancel a)) ⟩
(a ⨀ inv a) ⨀ a
≡⟨ sym (assoc _ _ _) ⟩
a ⨀ (inv a ⨀ a)
≡⟨ cong (comp a) (lCancel a) ⟩
a ⨀ id
≡⟨ rUnit a ⟩
a
∎
makeGroup-left : ∀ {ℓ} {A : Type ℓ}
→ (id : A)
→ (comp : A → A → A)
→ (inv : A → A)
→ (set : isSet A)
→ (assoc : ∀ a b c → comp a (comp b c) ≡ comp (comp a b) c)
→ (lUnit : ∀ a → comp id a ≡ a)
→ (lCancel : ∀ a → comp (inv a) a ≡ id)
→ Group
makeGroup-left {A = A} id comp inv set assoc lUnit lCancel =
makeGroup id comp inv set assoc rUnit lUnit rCancel lCancel
where
abstract
rCancel : ∀ a → comp a (inv a) ≡ id
rCancel a =
comp a (inv a)
≡⟨ sym (lUnit (comp a (inv a))) ⟩
comp id (comp a (inv a))
≡⟨ cong (λ b → comp b (comp a (inv a))) (sym (lCancel (inv a))) ⟩
comp (comp (inv (inv a)) (inv a)) (comp a (inv a))
≡⟨ sym (assoc (inv (inv a)) (inv a) (comp a (inv a))) ⟩
comp (inv (inv a)) (comp (inv a) (comp a (inv a)))
≡⟨ cong (comp (inv (inv a))) (assoc (inv a) a (inv a)) ⟩
comp (inv (inv a)) (comp (comp (inv a) a) (inv a))
≡⟨ cong (λ b → comp (inv (inv a)) (comp b (inv a))) (lCancel a) ⟩
comp (inv (inv a)) (comp id (inv a))
≡⟨ cong (comp (inv (inv a))) (lUnit (inv a)) ⟩
comp (inv (inv a)) (inv a)
≡⟨ lCancel (inv a) ⟩
id
∎
rUnit : ∀ a → comp a id ≡ a
rUnit a =
comp a id
≡⟨ cong (comp a) (sym (lCancel a)) ⟩
comp a (comp (inv a) a)
≡⟨ assoc a (inv a) a ⟩
comp (comp a (inv a)) a
≡⟨ cong (λ b → comp b a) (rCancel a) ⟩
comp id a
≡⟨ lUnit a ⟩
a
∎
open Group
open IsGroup
η-Group : {G H : Group {ℓ}}
→ (p : ⟨ G ⟩ ≡ ⟨ H ⟩)
→ (q : PathP (λ i → p i) (0g G) (0g H))
→ (r : PathP (λ i → (p i) → (p i) → (p i)) (_+_ G) (_+_ H))
→ (s : PathP (λ i → p i → p i) (-_ G) (-_ H))
→ PathP (λ i → IsGroup (q i) (r i) (s i)) (isGroup G) (isGroup H)
→ G ≡ H
Carrier (η-Group p _ _ _ _ i) = p i
0g (η-Group _ q _ _ _ i) = q i
_+_ (η-Group _ _ r _ _ i) = r i
- η-Group _ _ _ s t i = s i
isGroup (η-Group _ _ _ _ t i) = t i
isSetCarrier : ∀ {ℓ} → (G : Group {ℓ}) → isSet ⟨ G ⟩
isSetCarrier G = IsSemigroup.is-set (IsMonoid.isSemigroup (isMonoid G))
open IsMonoid
open IsSemigroup
dirProd : ∀ {ℓ ℓ'} → Group {ℓ} → Group {ℓ'} → Group
Carrier (dirProd A B) = Carrier A × Carrier B
0g (dirProd A B) = (0g A) , (0g B)
_+_ (dirProd A B) a b = (_+_ A (fst a) (fst b)) , _+_ B (snd a) (snd b)
-_ (dirProd A B) a = (-_ A (fst a)) , (-_ B (snd a))
is-set (isSemigroup (isMonoid (isGroup (dirProd A B)))) =
isOfHLevelΣ 2 (isSetCarrier A) λ _ → isSetCarrier B
assoc (isSemigroup (isMonoid (isGroup (dirProd A B)))) x y z i =
assoc (isGroup A) (fst x) (fst y) (fst z) i , assoc (isGroup B) (snd x) (snd y) (snd z) i
identity (isMonoid (isGroup (dirProd A B))) x =
(λ i → IsGroup.rid (isGroup A) (fst x) i , IsGroup.rid (isGroup B) (snd x) i)
, λ i → IsGroup.lid (isGroup A) (fst x) i , IsGroup.lid (isGroup B) (snd x) i
inverse (isGroup (dirProd A B)) x =
(λ i → (fst (inverse (isGroup A) (fst x)) i) , (fst (inverse (isGroup B) (snd x)) i))
, λ i → (snd (inverse (isGroup A) (fst x)) i) , (snd (inverse (isGroup B) (snd x)) i)
trivialGroup : Group₀
Carrier trivialGroup = Unit
0g trivialGroup = _
_+_ trivialGroup _ _ = _
-_ trivialGroup _ = _
is-set (isSemigroup (isMonoid (isGroup trivialGroup))) = isSetUnit
assoc (isSemigroup (isMonoid (isGroup trivialGroup))) _ _ _ = refl
identity (isMonoid (isGroup trivialGroup)) _ = refl , refl
inverse (isGroup trivialGroup) _ = refl , refl
intGroup : Group₀
Carrier intGroup = Int
0g intGroup = 0
_+_ intGroup = _+Int_
- intGroup = 0 -Int_
is-set (isSemigroup (isMonoid (isGroup intGroup))) = isSetInt
assoc (isSemigroup (isMonoid (isGroup intGroup))) = +-assoc
identity (isMonoid (isGroup intGroup)) x = refl , (+-comm (pos 0) x)
inverse (isGroup intGroup) x = +-comm x (pos 0 -Int x) ∙ minusPlus x 0 , (minusPlus x 0)
|
{
"alphanum_fraction": 0.5183854354,
"avg_line_length": 34.0775510204,
"ext": "agda",
"hexsha": "91b4df6fd398c945aa15705f67376232a11c3cd6",
"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": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "knrafto/cubical",
"max_forks_repo_path": "Cubical/Algebra/Group/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"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": "knrafto/cubical",
"max_issues_repo_path": "Cubical/Algebra/Group/Base.agda",
"max_line_length": 113,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "knrafto/cubical",
"max_stars_repo_path": "Cubical/Algebra/Group/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3351,
"size": 8349
}
|
module Sets.PredicateSet.Proofs where
import Lvl
open import Functional
import Logic.Propositional as Logic
import Logic.Propositional.Theorems as Logic
import Logic.Predicate
import Sets.PredicateSet
import Structure.Relator.Properties
import Type
-- [⊆][⊇]-equivalence : ∀{A}{B} → (A ⊆ B) ↔ (B ⊇ A)
module _ {ℓₗ}{ℓₒ} {T : Set(ℓₒ)} where
open Sets.PredicateSet
open Structure.Relator.Properties
private
Stmt = Logic.Stmt{ℓₗ Lvl.⊔ ℓₒ}
PredSet' : Set(Lvl.𝐒(ℓₗ Lvl.⊔ ℓₒ))
PredSet' = PredSet{ℓₗ}{ℓₒ} (T)
_⊆'_ : PredSet' → PredSet' → Stmt
_⊆'_ = _⊆_ {ℓₗ}{ℓₗ} {ℓₒ} {T}
_⊇'_ : PredSet' → PredSet' → Stmt
_⊇'_ = _⊇_ {ℓₗ}{ℓₗ} {ℓₒ} {T}
_≡'_ : PredSet' → PredSet' → Stmt
_≡'_ = _≡_ {ℓₗ}{ℓₗ} {ℓₒ} {T}
-- TODO: PredSet' has a greater level than Stmt? Not possible with Reflexivity or even Logic.Predicate
-- Refl : (PredSet' → PredSet' → Stmt) → Stmt
-- Refl(_▫_) = Reflexivity{_}{_} {PredSet'} (_▫_)
-- TODO: This is alright...
-- Refl : (T → T → Stmt) → Stmt
-- Refl(_▫_) = (∀{x : T} → (x ▫ x))
-- ...but not this
-- Refl : (PredSet' → PredSet' → Stmt) → Stmt
-- Refl(_▫_) = (∀{x : PredSet'} → (x ▫ x))
[⊆]-reflexivity : ∀{A} → (A ⊆' A)
[⊆]-reflexivity = id
[⊆]-transitivity : ∀{A B C} → (A ⊆' B) → (B ⊆' C) → (A ⊆' C)
[⊆]-transitivity ab bc = bc ∘ ab
[⊆]-antisymmetry : ∀{A B} → (A ⊇' B) → (A ⊆' B) → (A ≡' B)
[⊆]-antisymmetry = Logic.[∧]-intro
|
{
"alphanum_fraction": 0.5411051213,
"avg_line_length": 28,
"ext": "agda",
"hexsha": "d4c1582eb58da6b2ed2df9fdd88180942441ed8f",
"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": "old/Sets/PredicateSet/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Sets/PredicateSet/Proofs.agda",
"max_line_length": 106,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Sets/PredicateSet/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 658,
"size": 1484
}
|
module AsP where
f
: {A : Set}
→ A
→ A
→ A
f x@y z@w
= x
g
: {A : Set}
→ A
→ A
→ A
g x@y z'@w'
with y
... | _
= x
|
{
"alphanum_fraction": 0.345323741,
"avg_line_length": 6.619047619,
"ext": "agda",
"hexsha": "2b665f2348e18a364d775966056980969cfca469",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-01T16:38:14.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-01T16:38:14.000Z",
"max_forks_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "msuperdock/agda-unused",
"max_forks_repo_path": "data/pattern/AsP.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "msuperdock/agda-unused",
"max_issues_repo_path": "data/pattern/AsP.agda",
"max_line_length": 16,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "msuperdock/agda-unused",
"max_stars_repo_path": "data/pattern/AsP.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-01T16:38:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-29T09:38:43.000Z",
"num_tokens": 79,
"size": 139
}
|
module Lemmachine.Resource where
import Lemmachine.Resource.Universe
open import Data.Product
open import Data.List
private
module U = Lemmachine.Resource.Universe
open U using (Code; El)
Hook = Σ Code El
Hooks = List Hook
_⇒_ : {A : Set}{B : A → Set} → (a : A) → B a → (Σ A B)
_⇒_ = _,_
record Resource : Set where
field
resourceExists : El U.resourceExists
serviceAvailable : El U.serviceAvailable
isAuthorized : El U.isAuthorized
forbidden : El U.forbidden
allowMissingPost : El U.allowMissingPost
malformedRequest : El U.malformedRequest
uriTooLong : El U.uriTooLong
knownContentType : El U.knownContentType
validContentHeaders : El U.validContentHeaders
validEntityLength : El U.validEntityLength
options : El U.options
allowedMethods : El U.allowedMethods
knownMethods : El U.knownMethods
deleteResource : El U.deleteResource
deleteCompleted : El U.deleteCompleted
postIsCreate : El U.postIsCreate
createPath : El U.createPath
processPost : El U.processPost
contentTypesProvided : El U.contentTypesProvided
languageAvailable : El U.languageAvailable
contentTypesAccepted : El U.contentTypesAccepted
charsetsProvided : El U.charsetsProvided
encodingsProvided : El U.encodingsProvided
variances : El U.variances
isConflict : El U.isConflict
multipleChoices : El U.multipleChoices
previouslyExisted : El U.previouslyExisted
movedPermanently : El U.movedPermanently
movedTemporarily : El U.movedTemporarily
lastModified : El U.lastModified
expires : El U.expires
generateETag : El U.generateETag
finishRequest : El U.finishRequest
body : El U.body
|
{
"alphanum_fraction": 0.7387971698,
"avg_line_length": 32.6153846154,
"ext": "agda",
"hexsha": "15fc1844773090034bc931ffad6675d2a71baaeb",
"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/Resource.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/Resource.agda",
"max_line_length": 54,
"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/Resource.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": 447,
"size": 1696
}
|
module _ where
postulate
U : Set
u : U
module M (x : U) where
postulate f : U → U
module M₁ = M (M.f u u) -- this caused a 'recursive display form' error
|
{
"alphanum_fraction": 0.6181818182,
"avg_line_length": 13.75,
"ext": "agda",
"hexsha": "73782bc83a9c8a7a77706c01860755f4ebf2a65f",
"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/Issue1870.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/Issue1870.agda",
"max_line_length": 72,
"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/Issue1870.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 59,
"size": 165
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import stash.modalities.gbm.GbmUtil
module stash.modalities.JoinAdj {i j k}
(A : Type i) (B : Type j) (C : Type k) where
private
module From (f : B → C) (γ : A → hfiber cst f)
= JoinRec (fst ∘ γ) f (λ a b → app= (snd (γ a)) b)
from-β : (f : B → C) (γ : A → hfiber cst f)
(a : A) (b : B) → ap (From.f f γ) (jglue a b) == app= (snd (γ a)) b
from-β f γ a b = From.glue-β f γ a b
to : (A * B → C) → Σ (B → C) (λ f → A → hfiber cst f)
to φ = φ ∘ right , (λ a → φ (left a) , λ= (λ b → ap φ (glue (a , b))))
from : Σ (B → C) (λ f → A → hfiber cst f) → A * B → C
from (f , γ) = From.f f γ
abstract
to-from : (ψ : Σ (B → C) (λ f → A → hfiber cst f)) → to (from ψ) == ψ
to-from (f , γ) = pair= idp (λ= coh)
where coh : (a : A) → from (f , γ) (left a) , λ= (λ b → ap (from (f , γ)) (glue (a , b))) == γ a
coh a = pair= idp (ap λ= (λ= (λ b → from-β f γ a b)) ∙ ! (λ=-η (snd (γ a))))
from-to : (φ : A * B → C) → from (to φ) == φ
from-to φ = λ= (Join-elim (λ a → idp) (λ b → idp) (λ a b → ↓-==-in (coh a b)))
where coh : ∀ a b → ap φ (jglue a b) == ap (from (to φ)) (jglue a b) ∙ idp
coh a b = ap φ (jglue a b)
=⟨ ! (app=-β (λ b → ap φ (jglue a b)) b) ⟩
app= (λ= (λ b → ap φ (jglue a b))) b
=⟨ ! (from-β (fst (to φ)) (snd (to φ)) a b) ⟩
ap (From.f (fst (to φ)) (snd (to φ))) (jglue a b)
=⟨ ! (∙-unit-r (ap (from (to φ)) (jglue a b))) ⟩
ap (from (to φ)) (jglue a b) ∙ idp
=∎
join-adj : (A * B → C) ≃ Σ (B → C) (λ f → A → hfiber cst f)
join-adj = equiv to from to-from from-to
|
{
"alphanum_fraction": 0.4082295615,
"avg_line_length": 38.4791666667,
"ext": "agda",
"hexsha": "5be73f0f10b3fae753cf0b6efd2373d05d1ed04d",
"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/JoinAdj.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/JoinAdj.agda",
"max_line_length": 104,
"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/JoinAdj.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": 743,
"size": 1847
}
|
------------------------------------------------------------------------
-- A virtual machine
------------------------------------------------------------------------
module Lambda.VirtualMachine where
open import Category.Monad
open import Category.Monad.Partiality as P
using (_⊥; never); open P._⊥
open import Codata.Musical.Notation
open import Data.Empty using (⊥-elim)
open import Data.Fin
open import Data.List hiding (lookup)
open import Data.Maybe
open import Data.Nat
open import Data.Product as Prod
open import Data.Vec using (Vec; []; _∷_; lookup)
open import Function.Base
import Level
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
hiding (return)
open import Relation.Binary.PropositionalEquality as PE using (_≡_)
open import Relation.Nullary
open RawMonad (P.monad {f = Level.zero})
open import Lambda.Syntax
private module C = Closure Tm
------------------------------------------------------------------------
-- Instruction set
mutual
-- Instructions.
data Instr (n : ℕ) : Set where
var : (x : Fin n) → Instr n
con : (i : ℕ) → Instr n
clo : (c : Code (suc n)) → Instr n
app : Instr n
ret : Instr n
-- Code.
Code : ℕ → Set
Code n = List (Instr n)
-- Environments and values.
open Closure Code
------------------------------------------------------------------------
-- Compiler
-- The compiler takes a code continuation.
comp : ∀ {n} → Tm n → Code n → Code n
comp (con i) c = con i ∷ c
comp (var x) c = var x ∷ c
comp (ƛ t) c = clo (comp t [ ret ]) ∷ c
comp (t₁ · t₂) c = comp t₁ (comp t₂ (app ∷ c))
-- Environments and values can also be compiled.
mutual
comp-env : ∀ {n} → C.Env n → Env n
comp-env [] = []
comp-env (v ∷ ρ) = comp-val v ∷ comp-env ρ
comp-val : C.Value → Value
comp-val (C.con i) = con i
comp-val (C.ƛ t ρ) = ƛ (comp t [ ret ]) (comp-env ρ)
-- lookup x is homomorphic with respect to comp-env/comp-val.
lookup-hom : ∀ {n} (x : Fin n) ρ →
lookup (comp-env ρ) x ≡ comp-val (lookup ρ x)
lookup-hom zero (v ∷ ρ) = PE.refl
lookup-hom (suc x) (v ∷ ρ) = lookup-hom x ρ
------------------------------------------------------------------------
-- Stacks and states
-- Stacks.
data StackElement : Set where
val : (v : Value) → StackElement
ret : ∀ {n} (c : Code n) (ρ : Env n) → StackElement
Stack : Set
Stack = List StackElement
-- States.
data State : Set where
⟨_,_,_⟩ : ∀ {n} (c : Code n) (s : Stack) (ρ : Env n) → State
------------------------------------------------------------------------
-- Relational semantics of the VM
module Relational where
infix 4 _⟶_
data _⟶_ : State → State → Set where
var : ∀ {n} {x : Fin n} {c s ρ} →
⟨ var x ∷ c , s , ρ ⟩ ⟶ ⟨ c , val (lookup ρ x) ∷ s , ρ ⟩
con : ∀ {n i} {c : Code n} {s ρ} →
⟨ con i ∷ c , s , ρ ⟩ ⟶ ⟨ c , val (con i) ∷ s , ρ ⟩
clo : ∀ {n} {c : Code n} {c′ s ρ} →
⟨ clo c′ ∷ c , s , ρ ⟩ ⟶ ⟨ c , val (ƛ c′ ρ) ∷ s , ρ ⟩
app : ∀ {n} {c : Code n} {v n′} {c′ : Code (suc n′)} {ρ′ s ρ} →
⟨ app ∷ c , val v ∷ val (ƛ c′ ρ′) ∷ s , ρ ⟩ ⟶ ⟨ c′ , ret c ρ ∷ s , v ∷ ρ′ ⟩
ret : ∀ {n} {c : Code n} {v n′} {c′ : Code n′} {ρ′ s ρ} →
⟨ ret ∷ c , val v ∷ ret c′ ρ′ ∷ s , ρ ⟩ ⟶ ⟨ c′ , val v ∷ s , ρ′ ⟩
-- Final (stuck) states.
Final : State → Set
Final s = ∄ λ s′ → s ⟶ s′
-- s ⇓ v means that s is a successful final state, and that the
-- corresponding value is v.
infix 4 _⇓_
data _⇓_ : State → Value → Set where
final : ∀ {v} → ⟨ [] , val v ∷ [] , [] ⟩ ⇓ v
-- Sanity check.
⇓-final : ∀ {s v} → s ⇓ v → Final s
⇓-final final (_ , ())
-- Crashing stuck states.
Stuck : State → Set
Stuck s = Final s × ∄ (λ v → s ⇓ v)
-- Reflexive transitive closure.
infix 4 _⟶⋆_
_⟶⋆_ : State → State → Set
_⟶⋆_ = Star _⟶_
-- Infinite sequences of steps.
infixr 5 _◅_
infix 4 _⟶∞
data _⟶∞ : State → Set where
_◅_ : ∀ {s₁ s₂} (s₁⟶s₂ : s₁ ⟶ s₂) (s₂⟶∞ : ∞ (s₂ ⟶∞)) → s₁ ⟶∞
-- A variant of _⟶∞ which is easier to use.
module InfiniteSequence where
infix 4 _⟶∞′
infix 3 _⟶∞⟨_⟩
infixr 2 _⟶⟨_⟩′_ _⟶⋆⟨_⟩′_
data _⟶∞′ : State → Set where
_⟶⟨_⟩′_ : ∀ s₁ {s₂} (s₁⟶s₂ : s₁ ⟶ s₂) (s₂⟶∞ : ∞ (s₂ ⟶∞′)) → s₁ ⟶∞′
_⟶⋆⟨_⟩′_ : ∀ s₁ {s₂} (s₁⟶⋆s₂ : s₁ ⟶⋆ s₂) (s₂⟶∞ : s₂ ⟶∞′) → s₁ ⟶∞′
_⟶∞⟨_⟩ : ∀ s (s⟶∞ : s ⟶∞′) → s ⟶∞′
sound : ∀ {s} → s ⟶∞′ → s ⟶∞
sound (s₁ ⟶⟨ s₁⟶s₂ ⟩′ s₂⟶∞) = s₁⟶s₂ ◅ ♯ (sound (♭ s₂⟶∞))
sound (s ⟶⋆⟨ ε ⟩′ s⟶∞) = sound s⟶∞
sound (s₁ ⟶⋆⟨ s₁⟶s₂ ◅ s₂⟶⋆s₃ ⟩′ s₃⟶∞) = s₁⟶s₂ ◅ ♯ (sound (_ ⟶⋆⟨ s₂⟶⋆s₃ ⟩′ s₃⟶∞))
sound (s ⟶∞⟨ s⟶∞ ⟩) = sound s⟶∞
complete : ∀ {s} → s ⟶∞ → s ⟶∞′
complete (s₁⟶s₂ ◅ s₂⟶∞) = _ ⟶⟨ s₁⟶s₂ ⟩′ ♯ complete (♭ s₂⟶∞)
------------------------------------------------------------------------
-- Functional semantics of the VM
module Functional where
-- The result of running the VM one step.
data Result : Set where
continue : (s : State) → Result
done : (v : Value) → Result
crash : Result
-- A single step of the computation.
step : State → Result
step ⟨ [] , val v ∷ [] , [] ⟩ = done v
step ⟨ var x ∷ c , s , ρ ⟩ = continue ⟨ c , val (lookup ρ x) ∷ s , ρ ⟩
step ⟨ con i ∷ c , s , ρ ⟩ = continue ⟨ c , val (con i) ∷ s , ρ ⟩
step ⟨ clo c′ ∷ c , s , ρ ⟩ = continue ⟨ c , val (ƛ c′ ρ) ∷ s , ρ ⟩
step ⟨ app ∷ c , val v ∷ val (ƛ c′ ρ′) ∷ s , ρ ⟩ = continue ⟨ c′ , ret c ρ ∷ s , v ∷ ρ′ ⟩
step ⟨ ret ∷ c , val v ∷ ret c′ ρ′ ∷ s , ρ ⟩ = continue ⟨ c′ , val v ∷ s , ρ′ ⟩
step _ = crash
-- The VM.
exec : State → Maybe Value ⊥
exec s with step s
... | continue s′ = later (♯ exec s′)
... | done v = return (just v)
... | crash = return nothing
-- Equality for partial computations returning Maybe Value.
--
-- Note that propositional equality is used for the underlying
-- values, which can include code components. In other words, if
-- v₁ ≈ v₂, then any code components in these values have to be
-- /syntactically/ equal.
module Equality where
private
open module PEq {A : Set} = P.Equality {A = A} _≡_ public
using (_≈_; now; later; laterˡ)
open P public using (later⁻¹; now≉never)
module EqReasoning {A : Set} = P.Reasoning {A = A} PE.isEquivalence
------------------------------------------------------------------------
-- Equivalence proof
module Equivalence where
open Relational
open Functional
open Functional.Equality
----------------------------------------------------------------------
-- Classification of states
-- Inductive characterisation of states which are stuck and not
-- final.
data Crashing : State → Set where
crash₁ : ∀ {n ρ} → Crashing (⟨_,_,_⟩ { n} [] [] ρ )
crash₂ : ∀ {n n′ c ρ′ s ρ} → Crashing (⟨_,_,_⟩ { n} [] ( ret {n′} c ρ′ ∷ s ) ρ )
crash₃ : ∀ {n v e s ρ} → Crashing (⟨_,_,_⟩ { n} [] (val v ∷ e ∷ s ) ρ )
crash₄ : ∀ {n v₁ v₂ ρ} → Crashing (⟨_,_,_⟩ {suc n} [] ( val v₁ ∷ []) (v₂ ∷ ρ))
crash₅ : ∀ {n c ρ} → Crashing (⟨_,_,_⟩ { n} (app ∷ c) [] ρ )
crash₆ : ∀ {n c v ρ} → Crashing (⟨_,_,_⟩ { n} (app ∷ c) ( val v ∷ []) ρ )
crash₇ : ∀ {n c n′ c′ ρ′ s ρ} → Crashing (⟨_,_,_⟩ { n} (app ∷ c) ( ret {n′} c′ ρ′ ∷ s ) ρ )
crash₈ : ∀ {n c v i s ρ} → Crashing (⟨_,_,_⟩ { n} (app ∷ c) (val v ∷ val (con i) ∷ s ) ρ )
crash₉ : ∀ {n c v n′ c′ ρ′ s ρ} → Crashing (⟨_,_,_⟩ { n} (app ∷ c) (val v ∷ ret {n′} c′ ρ′ ∷ s ) ρ )
crash₁₀ : ∀ {n c ρ} → Crashing (⟨_,_,_⟩ { n} (ret ∷ c) [] ρ )
crash₁₁ : ∀ {n c v ρ} → Crashing (⟨_,_,_⟩ { n} (ret ∷ c) ( val v ∷ []) ρ )
crash₁₂ : ∀ {n c n′ c′ ρ′ s ρ} → Crashing (⟨_,_,_⟩ { n} (ret ∷ c) ( ret {n′} c′ ρ′ ∷ s ) ρ )
crash₁₃ : ∀ {n c v₁ v₂ s ρ} → Crashing (⟨_,_,_⟩ { n} (ret ∷ c) (val v₁ ∷ val v₂ ∷ s ) ρ )
-- There are three kinds of states.
data Kind (s : State) : Set where
done : ∀ {v} (s⇓v : s ⇓ v) → Kind s
continue : ∀ {s′} (s⟶s′ : s ⟶ s′) → Kind s
crash : (s↯ : Crashing s) → Kind s
-- We can assign (at least) one kind to every state.
kind : ∀ s → Kind s
kind ⟨ [] , val v ∷ [] , [] ⟩ = done final
kind ⟨ var x ∷ c , s , ρ ⟩ = continue var
kind ⟨ con i ∷ c , s , ρ ⟩ = continue con
kind ⟨ clo c′ ∷ c , s , ρ ⟩ = continue clo
kind ⟨ app ∷ c , val v ∷ val (ƛ c′ ρ′) ∷ s , ρ ⟩ = continue app
kind ⟨ ret ∷ c , val v ∷ ret c′ ρ′ ∷ s , ρ ⟩ = continue ret
kind ⟨ [] , [] , _ ⟩ = crash crash₁
kind ⟨ [] , ret _ _ ∷ _ , _ ⟩ = crash crash₂
kind ⟨ [] , val _ ∷ _ ∷ _ , _ ⟩ = crash crash₃
kind ⟨ [] , val _ ∷ [] , _ ∷ _ ⟩ = crash crash₄
kind ⟨ app ∷ _ , [] , _ ⟩ = crash crash₅
kind ⟨ app ∷ _ , val _ ∷ [] , _ ⟩ = crash crash₆
kind ⟨ app ∷ _ , ret _ _ ∷ _ , _ ⟩ = crash crash₇
kind ⟨ app ∷ _ , val _ ∷ val (con _) ∷ _ , _ ⟩ = crash crash₈
kind ⟨ app ∷ _ , val _ ∷ ret _ _ ∷ _ , _ ⟩ = crash crash₉
kind ⟨ ret ∷ _ , [] , _ ⟩ = crash crash₁₀
kind ⟨ ret ∷ _ , val _ ∷ [] , _ ⟩ = crash crash₁₁
kind ⟨ ret ∷ _ , ret _ _ ∷ _ , _ ⟩ = crash crash₁₂
kind ⟨ ret ∷ _ , val _ ∷ val _ ∷ _ , _ ⟩ = crash crash₁₃
-- The functional semantics crashes for crashing states.
exec-crashes : ∀ {s} → Crashing s → exec s ≈ return nothing
exec-crashes crash₁ = now PE.refl
exec-crashes crash₂ = now PE.refl
exec-crashes crash₃ = now PE.refl
exec-crashes crash₄ = now PE.refl
exec-crashes crash₅ = now PE.refl
exec-crashes crash₆ = now PE.refl
exec-crashes crash₇ = now PE.refl
exec-crashes crash₈ = now PE.refl
exec-crashes crash₉ = now PE.refl
exec-crashes crash₁₀ = now PE.refl
exec-crashes crash₁₁ = now PE.refl
exec-crashes crash₁₂ = now PE.refl
exec-crashes crash₁₃ = now PE.refl
-- The relational semantics also crashes for crashing states.
⟶-crashes : ∀ {s} → Crashing s → Stuck s
⟶-crashes s↯ = (helper₁ s↯ , helper₂ s↯)
where
helper₁ : ∀ {s} → Crashing s → Final s
helper₁ crash₁ (_ , ())
helper₁ crash₂ (_ , ())
helper₁ crash₃ (_ , ())
helper₁ crash₄ (_ , ())
helper₁ crash₅ (_ , ())
helper₁ crash₆ (_ , ())
helper₁ crash₇ (_ , ())
helper₁ crash₈ (_ , ())
helper₁ crash₉ (_ , ())
helper₁ crash₁₀ (_ , ())
helper₁ crash₁₁ (_ , ())
helper₁ crash₁₂ (_ , ())
helper₁ crash₁₃ (_ , ())
helper₂ : ∀ {s} → Crashing s → ∄ λ v → s ⇓ v
helper₂ crash₁ (_ , ())
helper₂ crash₂ (_ , ())
helper₂ crash₃ (_ , ())
helper₂ crash₄ (_ , ())
helper₂ crash₅ (_ , ())
helper₂ crash₆ (_ , ())
helper₂ crash₇ (_ , ())
helper₂ crash₈ (_ , ())
helper₂ crash₉ (_ , ())
helper₂ crash₁₀ (_ , ())
helper₂ crash₁₁ (_ , ())
helper₂ crash₁₂ (_ , ())
helper₂ crash₁₃ (_ , ())
----------------------------------------------------------------------
-- The relational semantics is sound with respect to the functional
-- one
-- Note that these proofs implicitly establish that the relational
-- semantics is deterministic.
⇒⇓ : ∀ {s s′ v} → s ⟶⋆ s′ → s′ ⇓ v → exec s ≈ return (just v)
⇒⇓ ε final = now PE.refl
⇒⇓ (var ◅ s⟶⋆) ⇓ = laterˡ (⇒⇓ s⟶⋆ ⇓)
⇒⇓ (con ◅ s⟶⋆) ⇓ = laterˡ (⇒⇓ s⟶⋆ ⇓)
⇒⇓ (clo ◅ s⟶⋆) ⇓ = laterˡ (⇒⇓ s⟶⋆ ⇓)
⇒⇓ (app ◅ s⟶⋆) ⇓ = laterˡ (⇒⇓ s⟶⋆ ⇓)
⇒⇓ (ret ◅ s⟶⋆) ⇓ = laterˡ (⇒⇓ s⟶⋆ ⇓)
⇒⇑ : ∀ {s} → s ⟶∞ → exec s ≈ never
⇒⇑ (var ◅ s⟶∞) = later (♯ (⇒⇑ (♭ s⟶∞)))
⇒⇑ (con ◅ s⟶∞) = later (♯ (⇒⇑ (♭ s⟶∞)))
⇒⇑ (clo ◅ s⟶∞) = later (♯ (⇒⇑ (♭ s⟶∞)))
⇒⇑ (app ◅ s⟶∞) = later (♯ (⇒⇑ (♭ s⟶∞)))
⇒⇑ (ret ◅ s⟶∞) = later (♯ (⇒⇑ (♭ s⟶∞)))
⇒↯ : ∀ {s} → ∃ (λ s′ → s ⟶⋆ s′ × Stuck s′) → exec s ≈ return nothing
⇒↯ (_ , var ◅ s⟶⋆ , ↯) = laterˡ (⇒↯ (_ , s⟶⋆ , ↯))
⇒↯ (_ , con ◅ s⟶⋆ , ↯) = laterˡ (⇒↯ (_ , s⟶⋆ , ↯))
⇒↯ (_ , clo ◅ s⟶⋆ , ↯) = laterˡ (⇒↯ (_ , s⟶⋆ , ↯))
⇒↯ (_ , app ◅ s⟶⋆ , ↯) = laterˡ (⇒↯ (_ , s⟶⋆ , ↯))
⇒↯ (_ , ret ◅ s⟶⋆ , ↯) = laterˡ (⇒↯ (_ , s⟶⋆ , ↯))
⇒↯ (s , ε , ↯) with kind s
... | done s⇓v = ⊥-elim (proj₂ ↯ (-, s⇓v))
... | continue s₁⟶s₂ = ⊥-elim (proj₁ ↯ (-, s₁⟶s₂))
... | crash s↯ = exec-crashes s↯
----------------------------------------------------------------------
-- The relational semantics is complete with respect to the
-- functional one
⇐⇓ : ∀ {s v} → exec s ≈ return (just v) → ∃ λ s′ → s ⟶⋆ s′ × s′ ⇓ v
⇐⇓ {s = s} ⇓ with kind s
⇐⇓ (now PE.refl) | done final = (_ , ε , final)
⇐⇓ (laterˡ ⇓) | continue var = Prod.map id (Prod.map (_◅_ var) id) (⇐⇓ ⇓)
⇐⇓ (laterˡ ⇓) | continue con = Prod.map id (Prod.map (_◅_ con) id) (⇐⇓ ⇓)
⇐⇓ (laterˡ ⇓) | continue clo = Prod.map id (Prod.map (_◅_ clo) id) (⇐⇓ ⇓)
⇐⇓ (laterˡ ⇓) | continue app = Prod.map id (Prod.map (_◅_ app) id) (⇐⇓ ⇓)
⇐⇓ (laterˡ ⇓) | continue ret = Prod.map id (Prod.map (_◅_ ret) id) (⇐⇓ ⇓)
⇐⇓ {s} {v} ⇓ | crash s↯ with
return (just v) ≈⟨ sym ⇓ ⟩
exec s ≈⟨ exec-crashes s↯ ⟩
return nothing ∎
where open EqReasoning
... | now ()
⇐⇑ : ∀ {s} → exec s ≈ never → s ⟶∞
⇐⇑ {s = s} ⇑ with kind s
⇐⇑ ⇑ | done final = ⊥-elim (now≉never ⇑)
⇐⇑ ⇑ | continue var = var ◅ ♯ ⇐⇑ (later⁻¹ ⇑)
⇐⇑ ⇑ | continue con = con ◅ ♯ ⇐⇑ (later⁻¹ ⇑)
⇐⇑ ⇑ | continue clo = clo ◅ ♯ ⇐⇑ (later⁻¹ ⇑)
⇐⇑ ⇑ | continue app = app ◅ ♯ ⇐⇑ (later⁻¹ ⇑)
⇐⇑ ⇑ | continue ret = ret ◅ ♯ ⇐⇑ (later⁻¹ ⇑)
⇐⇑ {s} ⇑ | crash s↯ = ⊥-elim (now≉never (
return nothing ≈⟨ sym $ exec-crashes s↯ ⟩
exec s ≈⟨ ⇑ ⟩
never ∎))
where open EqReasoning
⇐↯ : ∀ {s} → exec s ≈ return nothing → ∃ λ s′ → s ⟶⋆ s′ × Stuck s′
⇐↯ {s = s} ↯ with kind s
⇐↯ (now ()) | done final
⇐↯ (laterˡ ↯) | continue var = Prod.map id (Prod.map (_◅_ var) id) $ ⇐↯ ↯
⇐↯ (laterˡ ↯) | continue con = Prod.map id (Prod.map (_◅_ con) id) $ ⇐↯ ↯
⇐↯ (laterˡ ↯) | continue clo = Prod.map id (Prod.map (_◅_ clo) id) $ ⇐↯ ↯
⇐↯ (laterˡ ↯) | continue app = Prod.map id (Prod.map (_◅_ app) id) $ ⇐↯ ↯
⇐↯ (laterˡ ↯) | continue ret = Prod.map id (Prod.map (_◅_ ret) id) $ ⇐↯ ↯
⇐↯ ↯ | crash s↯ = (_ , ε , ⟶-crashes s↯)
|
{
"alphanum_fraction": 0.4410785619,
"avg_line_length": 36.1927710843,
"ext": "agda",
"hexsha": "ecab07c5e2e3ff92fe1104c0c1e2bfb8f1502ed4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "Lambda/VirtualMachine.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "Lambda/VirtualMachine.agda",
"max_line_length": 115,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "Lambda/VirtualMachine.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 6177,
"size": 15020
}
|
{-# OPTIONS --without-K --safe #-}
module FreshUtil where
open import Level using (Level; _⊔_; Lift)
open import Data.Empty
open import Data.Product using (∃; _,_; -,_)
open import Data.Sum.Base using (_⊎_; [_,_]′; inj₁; inj₂)
open import Function.Equivalence using (_⇔_; equivalence)
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Sum using (_⊎-dec_)
open import Relation.Unary as U
open import Relation.Binary as B using (Rel)
open import Data.List.Fresh.Relation.Unary.Any
open import Data.List.Fresh using (List#; []; cons; _∷#_; _#_)
open import Relation.Binary.PropositionalEquality hiding ( [_] )
private
variable
ax px rx ay py ry az pz rz : Level
AX : Set ax
AY : Set ay
AZ : Set az
module _ {AX : Set ax} {RX : Rel AX rx} (PX : Pred AX px) {AY : Set ay} {RY : Rel AY ry} (PY : Pred AY py) {AZ : Set az} {RZ : Rel AZ rz} (PZ : Pred AZ pz) where
-------------
FLinsert : AZ → List# AZ RZ → List# AZ RZ
FLfresh : (a x : AZ ) → (y : List# AZ RZ ) → RZ a x
-- → # AZ ? a y → fresh AZ ? a (FLinsert x y)
FLinsert = {!!}
FLfresh = {!!}
x∈FLins : (x : AZ) → (xs : List# AZ RZ) → Any (x ≡_) (FLinsert x xs)
x∈FLins = {!!}
insAny : {x h : AZ } → (xs : List# AZ RZ) → Any (x ≡_) xs → Any (x ≡_) (FLinsert h xs)
insAny = {!!}
-- FLinsert {zero} f0 y = f0 ∷# []
-- FLinsert {suc n} x [] = x ∷# []
-- FLinsert {suc n} x (cons a y x₁) with FLcmp x a
-- ... | tri≈ ¬a b ¬c = cons a y x₁
-- ... | tri< lt ¬b ¬c = cons x ( cons a y x₁) ( Level.lift (fromWitness lt ) , ttf lt y x₁)
-- FLinsert {suc n} x (cons a [] x₁) | tri> ¬a ¬b lt = cons a ( x ∷# [] ) ( Level.lift (fromWitness lt) , Level.lift tt )
-- FLinsert {suc n} x (cons a y yr) | tri> ¬a ¬b a<x = cons a (FLinsert x y) (FLfresh a x y a<x yr )
--
-- FLfresh a x [] a<x (Level.lift tt) = Level.lift (fromWitness a<x) , Level.lift tt
-- FLfresh a x (cons b [] (Level.lift tt)) a<x (Level.lift a<b , a<y) with FLcmp x b
-- ... | tri< x<b ¬b ¬c = Level.lift (fromWitness a<x) , Level.lift a<b , Level.lift tt
-- ... | tri≈ ¬a refl ¬c = Level.lift (fromWitness a<x) , Level.lift tt
-- ... | tri> ¬a ¬b b<x = Level.lift a<b , Level.lift (fromWitness (f<-trans (toWitness a<b) b<x)) , Level.lift tt
-- FLfresh a x (cons b y br) a<x (Level.lift a<b , a<y) with FLcmp x b
-- ... | tri< x<b ¬b ¬c = Level.lift (fromWitness a<x) , Level.lift a<b , ttf (toWitness a<b) y br
-- ... | tri≈ ¬a refl ¬c = Level.lift (fromWitness a<x) , ttf a<x y br
-- FLfresh a x (cons b [] br) a<x (Level.lift a<b , a<y) | tri> ¬a ¬b b<x =
-- Level.lift a<b , Level.lift (fromWitness (f<-trans (toWitness a<b) b<x)) , Level.lift tt
-- FLfresh a x (cons b (cons a₁ y x₁) br) a<x (Level.lift a<b , a<y) | tri> ¬a ¬b b<x =
-- Level.lift a<b , FLfresh a x (cons a₁ y x₁) a<x a<y
-- all cobmbination in P and Q (could be more general)
record AnyPair (X : List# AX RX ) (Y : List# AY RY ) (fpq : (p : AX) (q : AY) → AZ) : Set
(ax ⊔ px ⊔ rx ⊔ ay ⊔ py ⊔ ry ⊔ az ⊔ pz ⊔ rz ) where
field
pairList : List# AZ RZ
pairAny : (p : AX) (q : AY)
→ Any ( p ≡_ ) X → Any ( q ≡_ ) Y
→ Any (fpq p q ≡_) pairList
-------------
-- (p,q) (p,qn) .... (p,q0)
-- pn,q
-- : AnyPair FL0 FL0 P Q
-- p0,q
open AnyPair
anyPair : (P : List# AX RX) (Q : List# AY RY) → (fpq : (p : AX) (q : AY) → AZ) → AnyPair P Q fpq
anyPair [] [] _ = record { pairList = [] ; pairAny = λ _ _ () }
anyPair [] (cons q Q qr) _ = record { pairList = [] ; pairAny = λ _ _ () }
anyPair (cons p P pr) [] _ = record { pairList = [] ; pairAny = λ _ _ _ () }
anyPair (cons p P pr) (cons q Q qr) fpq = record { pairList = FLinsert (fpq p q) (pairListQ Q) ; pairAny = anyc0n } where
pairListP : (P1 : List# AX RX) → List# AZ RZ
pairListP [] = pairList (anyPair P Q fpq)
pairListP (cons p₁ P1 x) = FLinsert (fpq p₁ q) (pairListP P1)
pairListQ : (Q1 : List# AY RY) → List# AZ RZ
pairListQ [] = pairListP P
pairListQ (cons q₁ Q1 qr₁) = FLinsert (fpq p q₁) (pairListQ Q1)
anyc0n : (p₁ : AX) (q₁ : AY) → Any (_≡_ p₁) (cons p P pr) → Any (_≡_ q₁) (cons q Q qr)
→ Any (_≡_ (fpq p₁ q₁)) (FLinsert (fpq p q) (pairListQ Q))
anyc0n p₁ q₁ (here refl) (here refl) = x∈FLins _ (pairListQ Q )
anyc0n p₁ q₁ (here refl) (there anyq) = insAny (pairListQ Q) (anyc01 Q anyq) where
anyc01 : (Q1 : List# AY RY) → Any (_≡_ q₁) Q1 → Any (_≡_ (fpq p₁ q₁)) (pairListQ Q1)
anyc01 (cons q Q1 qr₂) (here refl) = x∈FLins _ _
anyc01 (cons q₂ Q1 qr₂) (there any) = insAny _ (anyc01 Q1 any)
anyc0n p₁ q₁ (there anyp) (here refl) = insAny _ (anyc02 Q) where
anyc03 : (P1 : List# AX RX) → Any (_≡_ p₁) P1 → Any (_≡_ (fpq p₁ q₁)) (pairListP P1)
anyc03 (cons a P1 x) (here refl) = x∈FLins _ _
anyc03 (cons a P1 x) (there any) = insAny _ ( anyc03 P1 any)
anyc02 : (Q1 : List# AY RY) → Any (_≡_ (fpq p₁ q₁)) (pairListQ Q1)
anyc02 [] = anyc03 P anyp
anyc02 (cons a Q1 x) = insAny _ (anyc02 Q1)
anyc0n p₁ q₁ (there anyp) (there anyq) = insAny (pairListQ Q) (anyc04 Q) where
anyc05 : (P1 : List# AX RX) → Any (_≡_ (fpq p₁ q₁)) (pairListP P1)
anyc05 [] = pairAny (anyPair P Q fpq) p₁ q₁ anyp anyq
anyc05 (cons a P1 x) = insAny _ (anyc05 P1)
anyc04 : (Q1 : List# AY RY) → Any (_≡_ (fpq p₁ q₁)) (pairListQ Q1)
anyc04 [] = anyc05 P
anyc04 (cons a Q1 x) = insAny _ (anyc04 Q1)
|
{
"alphanum_fraction": 0.5140482128,
"avg_line_length": 54.1891891892,
"ext": "agda",
"hexsha": "97b422c35b54531de669286d912de5149e1c6f3b",
"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": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/Galois",
"max_forks_repo_path": "src/FreshUtil.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/Galois",
"max_issues_repo_path": "src/FreshUtil.agda",
"max_line_length": 161,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/Galois",
"max_stars_repo_path": "src/FreshUtil.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-16T03:37:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-16T03:37:05.000Z",
"num_tokens": 2222,
"size": 6015
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Bicategory using (Bicategory)
-- The 1-cell dual (op) and 2-cell dual (co) of a given bicategory.
module Categories.Bicategory.Opposite where
open import Data.Product using (_,_)
import Categories.Bicategory.Extras as BicategoryExtras
open import Categories.Category using (Category)
import Categories.Category.Cartesian as Cartesian
import Categories.Morphism as Morphism
import Categories.Morphism.Reasoning as MorphismReasoning
open import Categories.Category.Product using (Swap)
open import Categories.Functor using (Functor; _∘F_)
open import Categories.NaturalTransformation.NaturalIsomorphism
using (NaturalIsomorphism; niHelper)
-- There several ways to dualize a bicategory:
--
-- * flip the 1-cells (op C), or
-- * flip the 2-cells (co C).
-- * flip both (coop C).
--
-- We implement all three.
module _ {o ℓ e t} (C : Bicategory o ℓ e t) where
open BicategoryExtras C
open Shorthands
private
module MR {A} {B} where
open Morphism (hom A B) public using (module ≅)
open MorphismReasoning (hom A B) public using (switch-tofromʳ)
open MR
-- The 1-cell dual of C.
--
-- NOTE. The definition here is specialized to the particular choice
-- of tensor product (cartesian) and braiding (swap) used in the
-- definition of Bicategories. We could instead have defined the
-- `enriched' field using the generic `op' operation defined in
-- Categories.Enriched.Category.Opposite, but that would have resulted
-- in much more complicated proofs of the triangle and pentagon
-- identities. That's because the definition of associativity and the
-- unit laws in the generic opposite enriched category has to work for
-- any choice of braiding and is therefore more involved. When these
-- laws become natural isomorphism in the definition of Bicategories,
-- they turn into long chains consisting of mostly identity morphisms
-- that make the types of the triangle and pentagon identities
-- enormous. We can avoid this by specializing the definitions of the
-- associators and unitors below.
--
-- Note also that this version of `op' is almost a (definitional)
-- involution. The problematic fields are the triangle and pentagon
-- identities which are not involutive on the nose. This could be
-- fixed by adding additional fields (in the style of `sym-assoc' in
-- Category). To also support `co` and `coop` would require two more
-- variants of each equation, so there would be quite a lot of
-- redundancy in the end.
op : Bicategory o ℓ e t
op = record
{ enriched = record
{ Obj = Obj
; hom = λ A B → hom B A
; id = id
; ⊚ = ⊚ ∘F Swap
; ⊚-assoc = niHelper (record
{ η = λ{ ((f , g) , h) → ⊚-assoc.⇐.η ((h , g) , f) }
; η⁻¹ = λ{ ((f , g) , h) → ⊚-assoc.⇒.η ((h , g) , f) }
; commute = λ{ ((α , β) , γ) → ⊚-assoc.⇐.commute ((γ , β) , α) }
; iso = λ _ → record
{ isoˡ = ⊚-assoc.iso.isoʳ _ ; isoʳ = ⊚-assoc.iso.isoˡ _ }
})
; unitˡ = niHelper (record
{ η = λ{ (_ , g) → unitʳ.⇒.η (g , _) }
; η⁻¹ = λ{ (_ , g) → unitʳ.⇐.η (g , _) }
; commute = λ{ (_ , β) → unitʳ.⇒.commute (β , _) }
; iso = λ{ (_ , g) → record
{ isoˡ = unitʳ.iso.isoˡ (g , _) ; isoʳ = unitʳ.iso.isoʳ (g , _) } }
})
; unitʳ = niHelper (record
{ η = λ{ (f , _) → unitˡ.⇒.η (_ , f) }
; η⁻¹ = λ{ (f , _) → unitˡ.⇐.η (_ , f) }
; commute = λ{ (α , _) → unitˡ.⇒.commute (_ , α) }
; iso = λ{ (f , _) → record
{ isoˡ = unitˡ.iso.isoˡ (_ , f) ; isoʳ = unitˡ.iso.isoʳ (_ , f) } }
})
}
; triangle = λ {_ _ _ f g} → begin
ρ⇒ ◁ g ∘ᵥ α⇐ ≈˘⟨ switch-tofromʳ (≅.sym associator) triangle ⟩
f ▷ λ⇒ ∎
; pentagon = λ {_ _ _ _ _ f g h i} → begin
α⇐ ◁ i ∘ᵥ α⇐ ∘ᵥ f ▷ α⇐ ≈˘⟨ hom.assoc ⟩
(α⇐ ◁ i ∘ᵥ α⇐) ∘ᵥ f ▷ α⇐ ≈⟨ pentagon-inv ⟩
α⇐ ∘ᵥ α⇐ ∎
}
where open hom.HomReasoning
-- The 2-cell dual of C.
co : Bicategory o ℓ e t
co = record
{ enriched = record
{ Obj = Obj
; hom = λ A B → Category.op (hom A B)
; id = Functor.op id
; ⊚ = Functor.op ⊚
; ⊚-assoc = NaturalIsomorphism.op′ ⊚-assoc
; unitˡ = NaturalIsomorphism.op′ unitˡ
; unitʳ = NaturalIsomorphism.op′ unitʳ
}
; triangle = triangle-inv
; pentagon = pentagon-inv
}
-- The combined 1- and 2-cell dual of C.
coop : ∀ {o ℓ e t} → Bicategory o ℓ e t → Bicategory o ℓ e t
coop C = co (op C)
|
{
"alphanum_fraction": 0.5919675283,
"avg_line_length": 37.75,
"ext": "agda",
"hexsha": "1459192c3d9b502cd363c953dc819efec7c6c86e",
"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/Bicategory/Opposite.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/Bicategory/Opposite.agda",
"max_line_length": 77,
"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/Bicategory/Opposite.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": 1569,
"size": 4681
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Groups.Definition
open import Sets.EquivalenceRelations
open import Setoids.Functions.Extension
module Groups.SymmetricGroups.Definition where
data SymmetryGroupElements {a b : _} {A : Set a} (S : Setoid {a} {b} A) : Set (a ⊔ b) where
sym : {f : A → A} → SetoidBijection S S f → SymmetryGroupElements S
symmetricSetoid : {a b : _} {A : Set a} (S : Setoid {a} {b} A) → Setoid (SymmetryGroupElements S)
Setoid._∼_ (symmetricSetoid S) (sym {f} bijF) (sym {g} bijG) = ExtensionallyEqual {S = S} {S} (SetoidBijection.wellDefined bijF) (SetoidBijection.wellDefined bijG)
Equivalence.reflexive (Setoid.eq (symmetricSetoid S)) {sym {f} bijF} = extensionallyEqualReflexive S S f (SetoidBijection.wellDefined bijF) (SetoidBijection.wellDefined bijF)
Equivalence.symmetric (Setoid.eq (symmetricSetoid S)) {sym {f} bijF} {sym {g} bijG} f~g = extensionallyEqualSymmetric S S f g (SetoidBijection.wellDefined bijF) (SetoidBijection.wellDefined bijG) f~g
Equivalence.transitive (Setoid.eq (symmetricSetoid S)) {sym {f} bijF} {sym {g} bijG} {sym {h} bijH} f~g g~h = extensionallyEqualTransitive S S f g h (SetoidBijection.wellDefined bijF) (SetoidBijection.wellDefined bijG) (SetoidBijection.wellDefined bijH) f~g g~h
symmetricGroupOp : {a b : _} {A : Set a} {S : Setoid {a} {b} A} (f g : SymmetryGroupElements S) → SymmetryGroupElements S
symmetricGroupOp (sym {f} bijF) (sym {g} bijG) = sym (setoidBijComp bijG bijF)
symmetricGroupInv : {a b : _} {A : Set a} (S : Setoid {a} {b} A) → SymmetryGroupElements S → SymmetryGroupElements S
symmetricGroupInv S (sym {f} bijF) with setoidBijectiveImpliesInvertible bijF
... | record { inverse = inverse ; inverseWellDefined = iwd ; isLeft = isLeft ; isRight = isRight } = sym (setoidInvertibleImpliesBijective (record { fWellDefined = iwd ; inverse = f ; inverseWellDefined = SetoidInjection.wellDefined (SetoidBijection.inj bijF) ; isLeft = λ b → isRight b ; isRight = λ b → isLeft b }))
symmetricGroupInvIsLeft : {a b : _} {A : Set a} (S : Setoid {a} {b} A) → {x : SymmetryGroupElements S} → Setoid._∼_ (symmetricSetoid S) (symmetricGroupOp (symmetricGroupInv S x) x) (sym setoidIdIsBijective)
symmetricGroupInvIsLeft {A = A} S {sym {f = f} fBij} = ans
where
ans : {x : A} → Setoid._∼_ S (SetoidInvertible.inverse (setoidBijectiveImpliesInvertible fBij) (f x)) x
ans {x} with SetoidSurjection.surjective (SetoidBijection.surj fBij) {f x}
ans {x} | a , b = SetoidInjection.injective (SetoidBijection.inj fBij) b
symmetricGroupInvIsRight : {a b : _} {A : Set a} (S : Setoid {a} {b} A) → {x : SymmetryGroupElements S} → Setoid._∼_ (symmetricSetoid S) (symmetricGroupOp x (symmetricGroupInv S x)) (sym setoidIdIsBijective)
symmetricGroupInvIsRight {A = A} S {sym {f = f} fBij} = ans
where
ans : {x : A} → Setoid._∼_ S (f (SetoidInvertible.inverse (setoidBijectiveImpliesInvertible fBij) x)) x
ans {x} with SetoidSurjection.surjective (SetoidBijection.surj fBij) {x}
ans {x} | a , b = b
symmetricGroup : {a b : _} {A : Set a} (S : Setoid {a} {b} A) → Group (symmetricSetoid S) (symmetricGroupOp {A = A})
Group.+WellDefined (symmetricGroup A) {sym {m} bijM} {sym {n} bijN} {sym {x} bijX} {sym {y} bijY} m~x n~y = transitive m~x (SetoidBijection.wellDefined bijX n~y)
where
open Equivalence (Setoid.eq A)
Group.0G (symmetricGroup A) = sym setoidIdIsBijective
Group.inverse (symmetricGroup S) = symmetricGroupInv S
Group.+Associative (symmetricGroup A) {sym {f} bijF} {sym {g} bijG} {sym {h} bijH} = Equivalence.reflexive (Setoid.eq A)
Group.identRight (symmetricGroup A) {sym {f} bijF} = Equivalence.reflexive (Setoid.eq A)
Group.identLeft (symmetricGroup A) {sym {f} bijF} = Equivalence.reflexive (Setoid.eq A)
Group.invLeft (symmetricGroup S) {x} = symmetricGroupInvIsLeft S {x}
Group.invRight (symmetricGroup S) {x} = symmetricGroupInvIsRight S {x}
|
{
"alphanum_fraction": 0.7211105553,
"avg_line_length": 75.4339622642,
"ext": "agda",
"hexsha": "0ec8ab2e9f3fa2f75b1672bfcfe6f8f07a66cb99",
"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": "Groups/SymmetricGroups/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/SymmetricGroups/Definition.agda",
"max_line_length": 318,
"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": "Groups/SymmetricGroups/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 1435,
"size": 3998
}
|
import Relation.Unary.Monotone as Mono
open import Relation.Binary using (Preorder)
open import Relation.Binary.PropositionalEquality
open import Level
module Category.Monad.Monotone.Heap
-- preordered heap types
{ℓ}(pre : Preorder ℓ ℓ ℓ)
-- types
(T : Set ℓ)
-- weakenable values
(V : T → Preorder.Carrier pre → Set ℓ) ⦃ wkV : ∀ {a} → Mono.Monotone pre (V a) ⦄
-- heaps indexed by the heap type
(H : Preorder.Carrier pre → Set ℓ)
-- weakenable heap type membership
(_∈_ : T → Preorder.Carrier pre → Set ℓ) ⦃ wk∈ : ∀ {a} → Mono.Monotone pre (_∈_ a) ⦄ where
open Preorder pre renaming (Carrier to I; _∼_ to _≤_; refl to ≤-refl; trans to ≤-trans)
open import Data.Unit using (⊤; tt)
open import Relation.Unary hiding (_∈_)
open import Relation.Unary.PredicateTransformer using (Pt)
open import Relation.Unary.Monotone pre
open import Data.Product
open import Category.Monad
open import Category.Monad.Monotone pre
open import Category.Monad.Identity
open import Category.Monad.Monotone.State pre H
record HeapMonad (M : Pt I ℓ) : Set (suc ℓ) where
field
⦃ super ⦄ : StateMonad M
open StateMonad super public
field
store : ∀ {a} → V a ⊆ M (λ W → a ∈ W)
modify : ∀ {a} → _∈_ a ⊆ V a ⇒ M (λ W' → Lift ⊤)
deref : ∀ {a} → _∈_ a ⊆ M (V a)
module _ ⦃ m : RawMPMonad M ⦄ where
open RawMPMonad m
open import Data.List.All as All
storeₙ : ∀ {W as} → All (λ a → V a W) as → M (λ W' → All (λ a → a ∈ W') as) W
storeₙ vs = sequenceM (All.map (λ v {x} ext → store (wk ext v)) vs)
|
{
"alphanum_fraction": 0.6569010417,
"avg_line_length": 32,
"ext": "agda",
"hexsha": "1fc1f1ff87477d64a450f113dc58d4fc6fd81ca1",
"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/Category/Monad/Monotone/Heap.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/Category/Monad/Monotone/Heap.agda",
"max_line_length": 92,
"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/Category/Monad/Monotone/Heap.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": 531,
"size": 1536
}
|
module BasicT.Metatheory.Gentzen-BasicTarski where
open import BasicT.Syntax.Gentzen public
open import BasicT.Semantics.BasicTarski public
-- Soundness with respect to all models, or evaluation.
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (lam t) γ = λ a → eval t (γ , a)
eval (app t u) γ = eval t γ $ eval u γ
eval (pair t u) γ = eval t γ , eval u γ
eval (fst t) γ = π₁ (eval t γ)
eval (snd t) γ = π₂ (eval t γ)
eval unit γ = ∙
eval true γ = true
eval false γ = false
eval (if t u v) γ = ifᴮ (eval t γ) (eval u γ) (eval v γ)
eval zero γ = zero
eval (suc t) γ = suc (eval t γ)
eval (it t u v) γ = itᴺ (eval t γ) (eval u γ) (eval v γ)
eval (rec t u v) γ = recᴺ (eval t γ) (eval u γ) (eval v γ)
-- TODO: Correctness of evaluation with respect to conversion.
|
{
"alphanum_fraction": 0.6011976048,
"avg_line_length": 30.9259259259,
"ext": "agda",
"hexsha": "c539cdf3e4af305f63e08ed240d8d74dc5765d11",
"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": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "BasicT/Metatheory/Gentzen-BasicTarski.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "BasicT/Metatheory/Gentzen-BasicTarski.agda",
"max_line_length": 62,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "BasicT/Metatheory/Gentzen-BasicTarski.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 306,
"size": 835
}
|
{-# OPTIONS --without-K #-}
module Pifextensional where
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; cong; cong₂; module ≡-Reasoning)
open ≡-Reasoning
open import Data.Empty using (⊥)
open import Data.Unit using (⊤; tt)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_)
open import Groupoid
------------------------------------------------------------------------------
-- Level 0:
-- ZERO is a type with no elements
-- ONE is a type with one element 'tt'
-- PLUS ONE ONE is a type with elements 'false' and 'true'
-- and so on for all finite types built from ZERO, ONE, PLUS, and TIMES
--
-- We also have that U is a type with elements ZERO, ONE, PLUS ONE ONE,
-- TIMES BOOL BOOL, etc.
data U : Set where
ZERO : U
ONE : U
PLUS : U → U → U
TIMES : U → U → U
⟦_⟧ : U → Set
⟦ ZERO ⟧ = ⊥
⟦ ONE ⟧ = ⊤
⟦ PLUS t₁ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧
⟦ TIMES t₁ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧
-- Abbreviations for examples
BOOL BOOL² : U
BOOL = PLUS ONE ONE
BOOL² = TIMES BOOL BOOL
false⟷ true⟷ : ⟦ BOOL ⟧
false⟷ = inj₁ tt
true⟷ = inj₂ tt
-- For any finite type (t : U) there is no non-trivial path structure
-- between the elements of t. All such finite types are discrete
-- groupoids
--
-- For U, there are non-trivial paths between its points. In the
-- conventional HoTT presentation, a path between t₁ and t₂ is
-- postulated by univalence for each equivalence between t₁ and t₂. In
-- the context of finite types, an equivalence corresponds to a
-- permutation as each permutation has a unique inverse
-- permutation. Thus instead of the detour using univalence, we can
-- give an inductive definition of all possible permutations between
-- finite types which naturally induces paths between the points. More
-- precisely, two types t₁ and t₂ have a path between them if there is
-- a permutation (c : t₁ ⟷ t₂). The fact that c is a permutation
-- guarantees, by construction, that (c ◎ ! c ∼ id⟷) and (! c ◎ c ∼
-- id⟷). A complete set of generators for all possible permutations
-- between finite types is given by the following definition. Note
-- that these permutations do not reach inside the types and hence do
-- not generate paths between the points within the types. The paths
-- are just between the types themselves.
infix 30 _⟷_
infixr 50 _◎_
data _⟷_ : U → U → Set where
unite₊ : {t : U} → PLUS ZERO t ⟷ t
uniti₊ : {t : U} → t ⟷ PLUS ZERO t
swap₊ : {t₁ t₂ : U} → PLUS t₁ t₂ ⟷ PLUS t₂ t₁
assocl₊ : {t₁ t₂ t₃ : U} → PLUS t₁ (PLUS t₂ t₃) ⟷ PLUS (PLUS t₁ t₂) t₃
assocr₊ : {t₁ t₂ t₃ : U} → PLUS (PLUS t₁ t₂) t₃ ⟷ PLUS t₁ (PLUS t₂ t₃)
unite⋆ : {t : U} → TIMES ONE t ⟷ t
uniti⋆ : {t : U} → t ⟷ TIMES ONE t
swap⋆ : {t₁ t₂ : U} → TIMES t₁ t₂ ⟷ TIMES t₂ t₁
assocl⋆ : {t₁ t₂ t₃ : U} → TIMES t₁ (TIMES t₂ t₃) ⟷ TIMES (TIMES t₁ t₂) t₃
assocr⋆ : {t₁ t₂ t₃ : U} → TIMES (TIMES t₁ t₂) t₃ ⟷ TIMES t₁ (TIMES t₂ t₃)
distz : {t : U} → TIMES ZERO t ⟷ ZERO
factorz : {t : U} → ZERO ⟷ TIMES ZERO t
dist : {t₁ t₂ t₃ : U} →
TIMES (PLUS t₁ t₂) t₃ ⟷ PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)
factor : {t₁ t₂ t₃ : U} →
PLUS (TIMES t₁ t₃) (TIMES t₂ t₃) ⟷ TIMES (PLUS t₁ t₂) t₃
id⟷ : {t : U} → t ⟷ t
_◎_ : {t₁ t₂ t₃ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_⊕_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (PLUS t₁ t₂ ⟷ PLUS t₃ t₄)
_⊗_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (TIMES t₁ t₂ ⟷ TIMES t₃ t₄)
-- Nicer syntax that shows intermediate values instead of the above
-- point-free notation of permutations
infixr 2 _⟷⟨_⟩_
infix 2 _□
_⟷⟨_⟩_ : (t₁ : U) {t₂ : U} {t₃ : U} →
(t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_ ⟷⟨ α ⟩ β = α ◎ β
_□ : (t : U) → {t : U} → (t ⟷ t)
_□ t = id⟷
-- Many ways of negating a BOOL. Again, it is absolutely critical that there
-- is NO path between false⟷ and true⟷. These permutations instead are based
-- on paths between x and neg (neg x) which are the trivial paths on each of
-- the two points in BOOL.
neg₁ neg₂ neg₃ neg₄ neg₅ : BOOL ⟷ BOOL
neg₁ = swap₊
neg₂ = id⟷ ◎ swap₊
neg₃ = swap₊ ◎ swap₊ ◎ swap₊
neg₄ = swap₊ ◎ id⟷
neg₅ = uniti⋆ ◎ swap⋆ ◎ (swap₊ ⊗ id⟷) ◎ swap⋆ ◎ unite⋆
-- CNOT
CNOT : BOOL² ⟷ BOOL²
CNOT = TIMES (PLUS x y) BOOL
⟷⟨ dist ⟩
PLUS (TIMES x BOOL) (TIMES y BOOL)
⟷⟨ id⟷ ⊕ (id⟷ ⊗ swap₊) ⟩
PLUS (TIMES x BOOL) (TIMES y BOOL)
⟷⟨ factor ⟩
TIMES (PLUS x y) BOOL □
where x = ONE; y = ONE
-- TOFFOLI
TOFFOLI : TIMES BOOL BOOL² ⟷ TIMES BOOL BOOL²
TOFFOLI = TIMES (PLUS x y) BOOL²
⟷⟨ dist ⟩
PLUS (TIMES x BOOL²) (TIMES y BOOL²)
⟷⟨ id⟷ ⊕ (id⟷ ⊗ CNOT) ⟩
PLUS (TIMES x BOOL²) (TIMES y BOOL²)
⟷⟨ factor ⟩
TIMES (PLUS x y) BOOL² □
where x = ONE; y = ONE
-- Every permutation has an inverse. There are actually many syntactically
-- different inverses but they are all equivalent.
! : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₁)
! unite₊ = uniti₊
! uniti₊ = unite₊
! swap₊ = swap₊
! assocl₊ = assocr₊
! assocr₊ = assocl₊
! unite⋆ = uniti⋆
! uniti⋆ = unite⋆
! swap⋆ = swap⋆
! assocl⋆ = assocr⋆
! assocr⋆ = assocl⋆
! distz = factorz
! factorz = distz
! dist = factor
! factor = dist
! id⟷ = id⟷
! (c₁ ◎ c₂) = ! c₂ ◎ ! c₁
! (c₁ ⊕ c₂) = (! c₁) ⊕ (! c₂)
! (c₁ ⊗ c₂) = (! c₁) ⊗ (! c₂)
!! : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → ! (! c) ≡ c
!! {c = unite₊} = refl
!! {c = uniti₊} = refl
!! {c = swap₊} = refl
!! {c = assocl₊} = refl
!! {c = assocr₊} = refl
!! {c = unite⋆} = refl
!! {c = uniti⋆} = refl
!! {c = swap⋆} = refl
!! {c = assocl⋆} = refl
!! {c = assocr⋆} = refl
!! {c = distz} = refl
!! {c = factorz} = refl
!! {c = dist} = refl
!! {c = factor} = refl
!! {c = id⟷} = refl
!! {c = c₁ ◎ c₂} =
begin (! (! (c₁ ◎ c₂))
≡⟨ refl ⟩
! (! c₂ ◎ ! c₁)
≡⟨ refl ⟩
! (! c₁) ◎ ! (! c₂)
≡⟨ cong₂ _◎_ (!! {c = c₁}) (!! {c = c₂}) ⟩
c₁ ◎ c₂ ∎)
!! {c = c₁ ⊕ c₂} =
begin (! (! (c₁ ⊕ c₂))
≡⟨ refl ⟩
! (! c₁) ⊕ ! (! c₂)
≡⟨ cong₂ _⊕_ (!! {c = c₁}) (!! {c = c₂}) ⟩
c₁ ⊕ c₂ ∎)
!! {c = c₁ ⊗ c₂} =
begin (! (! (c₁ ⊗ c₂))
≡⟨ refl ⟩
! (! c₁) ⊗ ! (! c₂)
≡⟨ cong₂ _⊗_ (!! {c = c₁}) (!! {c = c₂}) ⟩
c₁ ⊗ c₂ ∎)
------------------------------------------------------------------------------
-- Extensional view of 2paths.
--
-- There is a 2path between two permutations p and q if for each x, the
-- result of p(x) and q(x) are identical.
-- First we define the extensional view of a permutation as a function.
ap : {t₁ t₂ : U} → (t₁ ⟷ t₂) → ⟦ t₁ ⟧ → ⟦ t₂ ⟧
ap unite₊ (inj₁ ()) -- absurd
ap unite₊ (inj₂ v) = v
ap uniti₊ v = inj₂ v
ap swap₊ (inj₁ v) = inj₂ v
ap swap₊ (inj₂ v) = inj₁ v
ap assocl₊ (inj₁ v) = inj₁ (inj₁ v)
ap assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v)
ap assocl₊ (inj₂ (inj₂ v)) = inj₂ v
ap assocr₊ (inj₁ (inj₁ v)) = inj₁ v
ap assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v)
ap assocr₊ (inj₂ v) = inj₂ (inj₂ v)
ap unite⋆ (tt , v) = v
ap uniti⋆ v = (tt , v)
ap swap⋆ (v₁ , v₂) = (v₂ , v₁)
ap assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃)
ap assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃))
ap distz (() , _) -- absurd
ap factorz () -- absurd
ap dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃)
ap dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃)
ap factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃)
ap factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃)
ap id⟷ v = v
ap (c₁ ◎ c₂) v = ap c₂ (ap c₁ v)
ap (c₁ ⊕ c₂) (inj₁ v) = inj₁ (ap c₁ v)
ap (c₁ ⊕ c₂) (inj₂ v) = inj₂ (ap c₂ v)
ap (c₁ ⊗ c₂) (v₁ , v₂) = (ap c₁ v₁ , ap c₂ v₂)
α◎!α : {t₁ t₂ : U} {α : t₁ ⟷ t₂} {v : ⟦ t₁ ⟧} → ap (α ◎ ! α) v ≡ v
α◎!α {α = unite₊} {inj₁ ()}
α◎!α {α = unite₊} {inj₂ v} = refl
α◎!α {α = uniti₊} {v} = refl
α◎!α {α = swap₊} {inj₁ v} = refl
α◎!α {α = swap₊} {inj₂ v} = refl
α◎!α {α = assocl₊} {inj₁ v} = refl
α◎!α {α = assocl₊} {inj₂ (inj₁ v)} = refl
α◎!α {α = assocl₊} {inj₂ (inj₂ v)} = refl
α◎!α {α = assocr₊} {inj₁ (inj₁ v)} = refl
α◎!α {α = assocr₊} {inj₁ (inj₂ v)} = refl
α◎!α {α = assocr₊} {inj₂ v} = refl
α◎!α {α = unite⋆} {v} = refl
α◎!α {α = uniti⋆} {v} = refl
α◎!α {α = swap⋆} {v} = refl
α◎!α {α = assocl⋆} {v} = refl
α◎!α {α = assocr⋆} {v} = refl
α◎!α {α = distz} {(() , _)}
α◎!α {α = factorz} {()}
α◎!α {α = dist} {(inj₁ v₁ , v₂)} = refl
α◎!α {α = dist} {(inj₂ v₁ , v₂)} = refl
α◎!α {α = factor} {inj₁ v} = refl
α◎!α {α = factor} {inj₂ v} = refl
α◎!α {α = id⟷} {v} = refl
α◎!α {α = α₁ ◎ α₂} {v} =
begin
ap ((α₁ ◎ α₂) ◎ ! (α₁ ◎ α₂)) v
≡⟨ refl ⟩
ap (! α₁) (ap (α₂ ◎ ! α₂) (ap α₁ v))
≡⟨ cong (λ v' → ap (! α₁) v') (α◎!α {α = α₂} {v = ap α₁ v}) ⟩
ap (! α₁) (ap α₁ v)
≡⟨ α◎!α {α = α₁} {v = v} ⟩
v ∎
α◎!α {α = α₁ ⊕ α₂} {inj₁ v} =
begin
ap ((α₁ ⊕ α₂) ◎ ! (α₁ ⊕ α₂)) (inj₁ v)
≡⟨ refl ⟩
inj₁ (ap (! α₁) (ap α₁ v))
≡⟨ cong inj₁ (α◎!α {α = α₁} {v}) ⟩
inj₁ v ∎
α◎!α {α = α₁ ⊕ α₂} {inj₂ v} =
begin
ap ((α₁ ⊕ α₂) ◎ ! (α₁ ⊕ α₂)) (inj₂ v)
≡⟨ refl ⟩
inj₂ (ap (! α₂) (ap α₂ v))
≡⟨ cong inj₂ (α◎!α {α = α₂} {v}) ⟩
inj₂ v ∎
α◎!α {α = α₁ ⊗ α₂} {(v₁ , v₂)} =
begin
ap ((α₁ ⊗ α₂) ◎ ! (α₁ ⊗ α₂)) (v₁ , v₂)
≡⟨ refl ⟩
(ap (! α₁) (ap α₁ v₁) , ap (! α₂) (ap α₂ v₂))
≡⟨ cong₂ (_,_) (α◎!α {α = α₁} {v = v₁}) (α◎!α {α = α₂} {v = v₂}) ⟩
(v₁ , v₂) ∎
!α◎α : {t₁ t₂ : U} {α : t₁ ⟷ t₂} {v : ⟦ t₂ ⟧} → ap (! α ◎ α) v ≡ v
!α◎α {α = unite₊} {v} = refl
!α◎α {α = uniti₊} {inj₁ ()}
!α◎α {α = uniti₊} {inj₂ v} = refl
!α◎α {α = swap₊} {inj₁ v} = refl
!α◎α {α = swap₊} {inj₂ v} = refl
!α◎α {α = assocl₊} {inj₁ (inj₁ v)} = refl
!α◎α {α = assocl₊} {inj₁ (inj₂ v)} = refl
!α◎α {α = assocl₊} {inj₂ v} = refl
!α◎α {α = assocr₊} {inj₁ v} = refl
!α◎α {α = assocr₊} {inj₂ (inj₁ v)} = refl
!α◎α {α = assocr₊} {inj₂ (inj₂ v)} = refl
!α◎α {α = unite⋆} {v} = refl
!α◎α {α = uniti⋆} {v} = refl
!α◎α {α = swap⋆} {v} = refl
!α◎α {α = assocl⋆} {v} = refl
!α◎α {α = assocr⋆} {v} = refl
!α◎α {α = distz} {()}
!α◎α {α = factorz} {(() , _)}
!α◎α {α = dist} {inj₁ v} = refl
!α◎α {α = dist} {inj₂ v} = refl
!α◎α {α = factor} {(inj₁ v₁ , v₂)} = refl
!α◎α {α = factor} {(inj₂ v₁ , v₂)} = refl
!α◎α {α = id⟷} {v} = refl
!α◎α {α = α₁ ◎ α₂} {v} =
begin
ap (! (α₁ ◎ α₂) ◎ (α₁ ◎ α₂)) v
≡⟨ refl ⟩
ap α₂ (ap (! α₁ ◎ α₁) (ap (! α₂) v))
≡⟨ cong (λ v' → ap α₂ v') (!α◎α {α = α₁} {v = ap (! α₂) v}) ⟩
ap α₂ (ap (! α₂) v)
≡⟨ !α◎α {α = α₂} {v = v} ⟩
v ∎
!α◎α {α = α₁ ⊕ α₂} {inj₁ v} =
begin
ap (! (α₁ ⊕ α₂) ◎ (α₁ ⊕ α₂)) (inj₁ v)
≡⟨ refl ⟩
inj₁ (ap α₁ (ap (! α₁) v))
≡⟨ cong inj₁ (!α◎α {α = α₁} {v}) ⟩
inj₁ v ∎
!α◎α {α = α₁ ⊕ α₂} {inj₂ v} =
begin
ap (! (α₁ ⊕ α₂) ◎ (α₁ ⊕ α₂)) (inj₂ v)
≡⟨ refl ⟩
inj₂ (ap α₂ (ap (! α₂) v))
≡⟨ cong inj₂ (!α◎α {α = α₂} {v}) ⟩
inj₂ v ∎
!α◎α {α = α₁ ⊗ α₂} {(v₁ , v₂)} =
begin
ap (! (α₁ ⊗ α₂) ◎ (α₁ ⊗ α₂)) (v₁ , v₂)
≡⟨ refl ⟩
(ap α₁ (ap (! α₁) v₁) , ap α₂ (ap (! α₂) v₂))
≡⟨ cong₂ (_,_) (!α◎α {α = α₁} {v = v₁}) (!α◎α {α = α₂} {v = v₂}) ⟩
(v₁ , v₂) ∎
-- Two permutations, viewed extensionally, are equivalent if they map
-- each value x to the same value. Generally we would only require
-- that the resulting values y and z have a path between them, but
-- because the internals of each type are discrete groupoids, this
-- reduces to saying that y and z are identical.
infix 10 _∼_
_∼_ : ∀ {t₁ t₂} → (p q : t₁ ⟷ t₂) → Set
_∼_ {t₁} {t₂} p q = (x : ⟦ t₁ ⟧) → ap p x ≡ ap q x
α◎!α∼id⟷ : {t₁ t₂ : U} {α : t₁ ⟷ t₂} → α ◎ ! α ∼ id⟷
α◎!α∼id⟷ {α = α} v = α◎!α {α = α} {v}
!α◎α∼id⟷ : {t₁ t₂ : U} {α : t₁ ⟷ t₂} → ! α ◎ α ∼ id⟷
!α◎α∼id⟷ {t₁} {t₂} {α} v = !α◎α {α = α} {v}
resp◎ : {t₁ t₂ t₃ : U} {p q : t₁ ⟷ t₂} {r s : t₂ ⟷ t₃} →
(α : p ∼ q) → (β : r ∼ s) → (p ◎ r) ∼ (q ◎ s)
resp◎ {t₁} {t₂} {t₃} {p} {q} {r} {s} α β v =
begin
ap (p ◎ r) v
≡⟨ refl ⟩
ap r (ap p v)
≡⟨ cong (λ v → ap r v) (α v) ⟩
ap r (ap q v)
≡⟨ β (ap q v) ⟩
ap (q ◎ s) v ∎
-- Because we representing combinators semantically as functions (not as
-- permutations), we have to use function extensionality to compare the
-- semantic representation. This need to be changed by making use of a proper
-- representation of permutations instead of plain functions.
postulate
funExtP : {A B : Set} {f g : A → B} → ((x : A) → f x ≡ g x) → (f ≡ g)
-- Two extensionally equivalent combinators are semantically
-- equivalent. Again, if we had a proper representation of permutations, this
-- would reduce to comparing the two representations without involving
-- function extensionality.
ext2id : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ∼ c₂) → ap c₁ ≡ ap c₂
ext2id {t₁} {t₂} {c₁} {c₂} c₁∼c₂ =
funExtP {⟦ t₁ ⟧} {⟦ t₂ ⟧} {ap c₁} {ap c₂} c₁∼c₂
-- The equivalence ∼ of paths makes U a 1groupoid: the points are
-- types (t : U); the 1paths are ⟷; and the 2paths between them are
-- based on extensional equivalence ∼
G : 1Groupoid
G = record
{ set = U
; _↝_ = _⟷_
; _≈_ = _∼_
; id = id⟷
; _∘_ = λ p q → q ◎ p
; _⁻¹ = !
; lneutr = λ _ _ → refl
; rneutr = λ _ _ → refl
; assoc = λ _ _ _ _ → refl
; equiv = record {
refl = λ _ → refl
; sym = λ α x → sym (α x)
; trans = λ α β x → trans (α x) (β x)
}
; linv = λ {t₁} {t₂} α → α◎!α∼id⟷ {t₁} {t₂} {α}
; rinv = λ {t₁} {t₂} α → !α◎α∼id⟷ {t₁} {t₂} {α}
; ∘-resp-≈ = λ {t₁} {t₂} {t₃} {p} {q} {r} {s} p∼q r∼s →
resp◎ {t₁} {t₂} {t₃} {r} {s} {p} {q} r∼s p∼q
}
------------------------------------------------------------------------------
-- Picture so far:
--
-- path p
-- =====================
-- || || ||
-- || ||2path ||
-- || || ||
-- || || path q ||
-- t₁ =================t₂
-- || ... ||
-- =====================
--
-- The types t₁, t₂, etc are discrete groupoids. The paths between
-- them correspond to permutations. Each syntactically different
-- permutation corresponds to a path but equivalent permutations are
-- connected by 2paths. But now we want an alternative definition of
-- 2paths that is structural, i.e., that looks at the actual
-- construction of the path t₁ ⟷ t₂ in terms of combinators... The
-- theorem we want is that α ∼ β iff we can rewrite α to β using
-- various syntactic structural rules. We start with a collection of
-- simplication rules and then try to show they are complete.
-- Simplification rules
infix 30 _⇔_
data _⇔_ : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₁ ⟷ t₂) → Set where
assoc◎l : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₃ ⟷ t₄} →
(c₁ ◎ (c₂ ◎ c₃)) ⇔ ((c₁ ◎ c₂) ◎ c₃)
assoc◎r : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₃ ⟷ t₄} →
((c₁ ◎ c₂) ◎ c₃) ⇔ (c₁ ◎ (c₂ ◎ c₃))
assoc⊕l : {t₁ t₂ t₃ t₄ t₅ t₆ : U}
{c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} →
(c₁ ⊕ (c₂ ⊕ c₃)) ⇔ (assocl₊ ◎ ((c₁ ⊕ c₂) ⊕ c₃) ◎ assocr₊)
assoc⊕r : {t₁ t₂ t₃ t₄ t₅ t₆ : U}
{c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} →
(assocl₊ ◎ ((c₁ ⊕ c₂) ⊕ c₃) ◎ assocr₊) ⇔ (c₁ ⊕ (c₂ ⊕ c₃))
assoc⊗l : {t₁ t₂ t₃ t₄ t₅ t₆ : U}
{c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} →
(c₁ ⊗ (c₂ ⊗ c₃)) ⇔ (assocl⋆ ◎ ((c₁ ⊗ c₂) ⊗ c₃) ◎ assocr⋆)
assoc⊗r : {t₁ t₂ t₃ t₄ t₅ t₆ : U}
{c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} →
(assocl⋆ ◎ ((c₁ ⊗ c₂) ⊗ c₃) ◎ assocr⋆) ⇔ (c₁ ⊗ (c₂ ⊗ c₃))
dist⇔ : {t₁ t₂ t₃ t₄ t₅ t₆ : U}
{c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} →
((c₁ ⊕ c₂) ⊗ c₃) ⇔ (dist ◎ ((c₁ ⊗ c₃) ⊕ (c₂ ⊗ c₃)) ◎ factor)
factor⇔ : {t₁ t₂ t₃ t₄ t₅ t₆ : U}
{c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} →
(dist ◎ ((c₁ ⊗ c₃) ⊕ (c₂ ⊗ c₃)) ◎ factor) ⇔ ((c₁ ⊕ c₂) ⊗ c₃)
idl◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (id⟷ ◎ c) ⇔ c
idl◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ⇔ id⟷ ◎ c
idr◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (c ◎ id⟷) ⇔ c
idr◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ⇔ (c ◎ id⟷)
linv◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (c ◎ ! c) ⇔ id⟷
linv◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → id⟷ ⇔ (c ◎ ! c)
rinv◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (! c ◎ c) ⇔ id⟷
rinv◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → id⟷ ⇔ (! c ◎ c)
unitel₊⇔ : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} →
(unite₊ ◎ c₂) ⇔ ((c₁ ⊕ c₂) ◎ unite₊)
uniter₊⇔ : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} →
((c₁ ⊕ c₂) ◎ unite₊) ⇔ (unite₊ ◎ c₂)
unitil₊⇔ : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} →
(uniti₊ ◎ (c₁ ⊕ c₂)) ⇔ (c₂ ◎ uniti₊)
unitir₊⇔ : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} →
(c₂ ◎ uniti₊) ⇔ (uniti₊ ◎ (c₁ ⊕ c₂))
unitial₊⇔ : {t₁ t₂ : U} → (uniti₊ {PLUS t₁ t₂} ◎ assocl₊) ⇔ (uniti₊ ⊕ id⟷)
unitiar₊⇔ : {t₁ t₂ : U} → (uniti₊ {t₁} ⊕ id⟷ {t₂}) ⇔ (uniti₊ ◎ assocl₊)
swapl₊⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} →
(swap₊ ◎ (c₁ ⊕ c₂)) ⇔ ((c₂ ⊕ c₁) ◎ swap₊)
swapr₊⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} →
((c₂ ⊕ c₁) ◎ swap₊) ⇔ (swap₊ ◎ (c₁ ⊕ c₂))
unitel⋆⇔ : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} →
(unite⋆ ◎ c₂) ⇔ ((c₁ ⊗ c₂) ◎ unite⋆)
uniter⋆⇔ : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} →
((c₁ ⊗ c₂) ◎ unite⋆) ⇔ (unite⋆ ◎ c₂)
unitil⋆⇔ : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} →
(uniti⋆ ◎ (c₁ ⊗ c₂)) ⇔ (c₂ ◎ uniti⋆)
unitir⋆⇔ : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} →
(c₂ ◎ uniti⋆) ⇔ (uniti⋆ ◎ (c₁ ⊗ c₂))
unitial⋆⇔ : {t₁ t₂ : U} → (uniti⋆ {TIMES t₁ t₂} ◎ assocl⋆) ⇔ (uniti⋆ ⊗ id⟷)
unitiar⋆⇔ : {t₁ t₂ : U} → (uniti⋆ {t₁} ⊗ id⟷ {t₂}) ⇔ (uniti⋆ ◎ assocl⋆)
swapl⋆⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} →
(swap⋆ ◎ (c₁ ⊗ c₂)) ⇔ ((c₂ ⊗ c₁) ◎ swap⋆)
swapr⋆⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} →
((c₂ ⊗ c₁) ◎ swap⋆) ⇔ (swap⋆ ◎ (c₁ ⊗ c₂))
swapfl⋆⇔ : {t₁ t₂ t₃ : U} →
(swap₊ {TIMES t₂ t₃} {TIMES t₁ t₃} ◎ factor) ⇔
(factor ◎ (swap₊ {t₂} {t₁} ⊗ id⟷))
swapfr⋆⇔ : {t₁ t₂ t₃ : U} →
(factor ◎ (swap₊ {t₂} {t₁} ⊗ id⟷)) ⇔
(swap₊ {TIMES t₂ t₃} {TIMES t₁ t₃} ◎ factor)
id⇔ : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ⇔ c
trans⇔ : {t₁ t₂ : U} {c₁ c₂ c₃ : t₁ ⟷ t₂} →
(c₁ ⇔ c₂) → (c₂ ⇔ c₃) → (c₁ ⇔ c₃)
resp◎⇔ : {t₁ t₂ t₃ : U}
{c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₁ ⟷ t₂} {c₄ : t₂ ⟷ t₃} →
(c₁ ⇔ c₃) → (c₂ ⇔ c₄) → (c₁ ◎ c₂) ⇔ (c₃ ◎ c₄)
resp⊕⇔ : {t₁ t₂ t₃ t₄ : U}
{c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₁ ⟷ t₂} {c₄ : t₃ ⟷ t₄} →
(c₁ ⇔ c₃) → (c₂ ⇔ c₄) → (c₁ ⊕ c₂) ⇔ (c₃ ⊕ c₄)
resp⊗⇔ : {t₁ t₂ t₃ t₄ : U}
{c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₁ ⟷ t₂} {c₄ : t₃ ⟷ t₄} →
(c₁ ⇔ c₃) → (c₂ ⇔ c₄) → (c₁ ⊗ c₂) ⇔ (c₃ ⊗ c₄)
-- better syntax for writing 2paths
infix 2 _▤
infixr 2 _⇔⟨_⟩_
_⇔⟨_⟩_ : {t₁ t₂ : U} (c₁ : t₁ ⟷ t₂) {c₂ : t₁ ⟷ t₂} {c₃ : t₁ ⟷ t₂} →
(c₁ ⇔ c₂) → (c₂ ⇔ c₃) → (c₁ ⇔ c₃)
_ ⇔⟨ α ⟩ β = trans⇔ α β
_▤ : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → (c ⇔ c)
_▤ c = id⇔
-- Inverses for 2paths
2! : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ⇔ c₂) → (c₂ ⇔ c₁)
2! assoc◎l = assoc◎r
2! assoc◎r = assoc◎l
2! assoc⊕l = assoc⊕r
2! assoc⊕r = assoc⊕l
2! assoc⊗l = assoc⊗r
2! assoc⊗r = assoc⊗l
2! dist⇔ = factor⇔
2! factor⇔ = dist⇔
2! idl◎l = idl◎r
2! idl◎r = idl◎l
2! idr◎l = idr◎r
2! idr◎r = idr◎l
2! linv◎l = linv◎r
2! linv◎r = linv◎l
2! rinv◎l = rinv◎r
2! rinv◎r = rinv◎l
2! unitel₊⇔ = uniter₊⇔
2! uniter₊⇔ = unitel₊⇔
2! unitil₊⇔ = unitir₊⇔
2! unitir₊⇔ = unitil₊⇔
2! swapl₊⇔ = swapr₊⇔
2! swapr₊⇔ = swapl₊⇔
2! unitial₊⇔ = unitiar₊⇔
2! unitiar₊⇔ = unitial₊⇔
2! unitel⋆⇔ = uniter⋆⇔
2! uniter⋆⇔ = unitel⋆⇔
2! unitil⋆⇔ = unitir⋆⇔
2! unitir⋆⇔ = unitil⋆⇔
2! unitial⋆⇔ = unitiar⋆⇔
2! unitiar⋆⇔ = unitial⋆⇔
2! swapl⋆⇔ = swapr⋆⇔
2! swapr⋆⇔ = swapl⋆⇔
2! swapfl⋆⇔ = swapfr⋆⇔
2! swapfr⋆⇔ = swapfl⋆⇔
2! id⇔ = id⇔
2! (trans⇔ α β) = trans⇔ (2! β) (2! α)
2! (resp◎⇔ α β) = resp◎⇔ (2! α) (2! β)
2! (resp⊕⇔ α β) = resp⊕⇔ (2! α) (2! β)
2! (resp⊗⇔ α β) = resp⊗⇔ (2! α) (2! β)
-- a nice example of 2 paths
negEx : neg₅ ⇔ neg₁
negEx = uniti⋆ ◎ (swap⋆ ◎ ((swap₊ ⊗ id⟷) ◎ (swap⋆ ◎ unite⋆)))
⇔⟨ resp◎⇔ id⇔ assoc◎l ⟩
uniti⋆ ◎ ((swap⋆ ◎ (swap₊ ⊗ id⟷)) ◎ (swap⋆ ◎ unite⋆))
⇔⟨ resp◎⇔ id⇔ (resp◎⇔ swapl⋆⇔ id⇔) ⟩
uniti⋆ ◎ (((id⟷ ⊗ swap₊) ◎ swap⋆) ◎ (swap⋆ ◎ unite⋆))
⇔⟨ resp◎⇔ id⇔ assoc◎r ⟩
uniti⋆ ◎ ((id⟷ ⊗ swap₊) ◎ (swap⋆ ◎ (swap⋆ ◎ unite⋆)))
⇔⟨ resp◎⇔ id⇔ (resp◎⇔ id⇔ assoc◎l) ⟩
uniti⋆ ◎ ((id⟷ ⊗ swap₊) ◎ ((swap⋆ ◎ swap⋆) ◎ unite⋆))
⇔⟨ resp◎⇔ id⇔ (resp◎⇔ id⇔ (resp◎⇔ linv◎l id⇔)) ⟩
uniti⋆ ◎ ((id⟷ ⊗ swap₊) ◎ (id⟷ ◎ unite⋆))
⇔⟨ resp◎⇔ id⇔ (resp◎⇔ id⇔ idl◎l) ⟩
uniti⋆ ◎ ((id⟷ ⊗ swap₊) ◎ unite⋆)
⇔⟨ assoc◎l ⟩
(uniti⋆ ◎ (id⟷ ⊗ swap₊)) ◎ unite⋆
⇔⟨ resp◎⇔ unitil⋆⇔ id⇔ ⟩
(swap₊ ◎ uniti⋆) ◎ unite⋆
⇔⟨ assoc◎r ⟩
swap₊ ◎ (uniti⋆ ◎ unite⋆)
⇔⟨ resp◎⇔ id⇔ linv◎l ⟩
swap₊ ◎ id⟷
⇔⟨ idr◎l ⟩
swap₊ ▤
-- The equivalence ⇔ of paths is rich enough to make U a 1groupoid:
-- the points are types (t : U); the 1paths are ⟷; and the 2paths
-- between them are based on the simplification rules ⇔
G' : 1Groupoid
G' = record
{ set = U
; _↝_ = _⟷_
; _≈_ = _⇔_
; id = id⟷
; _∘_ = λ p q → q ◎ p
; _⁻¹ = !
; lneutr = λ _ → idr◎l
; rneutr = λ _ → idl◎l
; assoc = λ _ _ _ → assoc◎l
; equiv = record {
refl = id⇔
; sym = 2!
; trans = trans⇔
}
; linv = λ {t₁} {t₂} α → linv◎l
; rinv = λ {t₁} {t₂} α → rinv◎l
; ∘-resp-≈ = λ p∼q r∼s → resp◎⇔ r∼s p∼q
}
------------------------------------------------------------------------------
-- Soundness and completeness
--
-- Proof of soundness and completeness: now we want to verify that ⇔
-- is sound and complete with respect to ∼. The statement to prove is
-- that for all c₁ and c₂, we have c₁ ∼ c₂ iff c₁ ⇔ c₂
postulate -- to do eventually but should be fairly easy
soundnessP : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ⇔ c₂) → (c₁ ∼ c₂)
-- postulate -- proved below
-- completenessP : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ∼ c₂) → (c₁ ⇔ c₂)
-- The idea is to invert evaluation and use that to extract from each
-- extensional representation of a combinator, a canonical syntactic
-- representative
postulate
invertP : {t₁ t₂ : U} → (⟦ t₁ ⟧ → ⟦ t₂ ⟧) → (t₁ ⟷ t₂)
canonical : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₁ ⟷ t₂)
canonical c = invertP (ap c)
-- Note that if c₁ ⇔ c₂, then by soundness c₁ ∼ c₂ and hence their
-- canonical representatives are identical.
canonicalWellDefined : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} →
(c₁ ⇔ c₂) → (canonical c₁ ≡ canonical c₂)
canonicalWellDefined {t₁} {t₂} {c₁} {c₂} α =
cong invertP (ext2id {t₁} {t₂} {c₁} {c₂} (soundnessP α))
-- If we can prove that every combinator is equal to its normal form
-- then we can prove completeness.
postulate
inversionP : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ⇔ canonical c
resp≡⇔ : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ≡ c₂) → (c₁ ⇔ c₂)
resp≡⇔ {t₁} {t₂} {c₁} {c₂} p rewrite p = id⇔
completeness : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ∼ c₂) → (c₁ ⇔ c₂)
completeness {t₁} {t₂} {c₁} {c₂} c₁∼c₂ =
c₁
⇔⟨ inversionP ⟩
canonical c₁
⇔⟨ resp≡⇔ (cong invertP (ext2id {t₁} {t₂} {c₁} {c₂} c₁∼c₂)) ⟩
canonical c₂
⇔⟨ 2! inversionP ⟩
c₂ ▤
-- To summarize, completeness can be proved if we can define the following
-- two functions:
--
-- * a function that extracts a canonical combinator out of the
-- semantic representation of a permutation:
-- invertP : {t₁ t₂ : U} → (⟦ t₁ ⟧ → ⟦ t₂ ⟧) → (t₁ ⟷ t₂)
-- * a function that proves that every combinator can be rewritten to this
-- canonical form:
-- inversionP : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ⇔ canonical c
--
-- This all uses function extensionality. It is possible to get rid of
-- that if we use an accurate representation of permutations.
------------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.476699708,
"avg_line_length": 34.6833095578,
"ext": "agda",
"hexsha": "db32387d4ac09d9deee83452ab34304995cd78ad",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Pifextensional.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Pifextensional.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Pifextensional.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 12342,
"size": 24313
}
|
open import Prelude hiding (_<_)
module Implicits.Resolution.GenericFinite.Resolution where
open import Coinduction
open import Data.List
open import Data.List.Any
open Membership-≡
open import Data.Fin.Substitution
open import Relation.Binary using (Rel)
open import Implicits.Syntax
open import Implicits.Syntax.Type.Unification
open import Implicits.Substitutions
open import Implicits.Substitutions.Lemmas.MetaType
open import Implicits.Resolution.Termination
open import Implicits.Resolution.GenericFinite.TerminationCondition
private
module M = MetaTypeMetaSubst
module ResolutionRules (cond : TerminationCondition) where
open TerminationCondition cond
mutual
data _,_⊢_↓_ {ν} (Δ : ICtx ν) : (Φ : TCtx) → Type ν → SimpleType ν → Set where
i-simp : ∀ {Φ} a → Δ , Φ ⊢ simpl a ↓ a
i-iabs : ∀ {Φ ρ₁ ρ₂ a} → let Φ' = (step Φ Δ ρ₁ ρ₂ a) in
Φ' < Φ → Δ , Φ' ⊢ᵣ ρ₁ → Δ , Φ ⊢ ρ₂ ↓ a → Δ , Φ ⊢ ρ₁ ⇒ ρ₂ ↓ a
i-tabs : ∀ {Φ ρ a} b → Δ , Φ ⊢ ρ tp[/tp b ] ↓ a → Δ , Φ ⊢ ∀' ρ ↓ a
data _,_⊢ᵣ_ {ν} (Δ : ICtx ν) : TCtx → Type ν → Set where
r-simp : ∀ {Φ r τ} → r ∈ Δ → Δ , Φ ⊢ r ↓ τ → Δ , Φ ⊢ᵣ simpl τ
r-iabs : ∀ {Φ} ρ₁ {ρ₂} → ((ρ₁ ∷ Δ) , Φ ⊢ᵣ ρ₂) → Δ , Φ ⊢ᵣ (ρ₁ ⇒ ρ₂)
r-tabs : ∀ {Φ ρ} → ictx-weaken Δ , Φ ⊢ᵣ ρ → Δ , Φ ⊢ᵣ ∀' ρ
|
{
"alphanum_fraction": 0.6277258567,
"avg_line_length": 35.6666666667,
"ext": "agda",
"hexsha": "08e7ca59d42f665e1cb2b05d603102ea469bcba0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/GenericFinite/Resolution.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/GenericFinite/Resolution.agda",
"max_line_length": 82,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/GenericFinite/Resolution.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": 518,
"size": 1284
}
|
module Haskell.Prim.Bounded where
open import Agda.Builtin.Nat
open import Agda.Builtin.Bool
open import Agda.Builtin.Char
open import Agda.Builtin.Equality
open import Agda.Builtin.List
open import Haskell.Prim
open import Haskell.Prim.Eq
open import Haskell.Prim.Int
open import Haskell.Prim.Maybe
open import Haskell.Prim.Ord
open import Haskell.Prim.Tuple
open import Haskell.Prim.Word
--------------------------------------------------
-- Bounded
record BoundedBelow (a : Set) : Set where
field
minBound : a
record BoundedAbove (a : Set) : Set where
field
maxBound : a
record Bounded (a : Set) : Set where
field
overlap ⦃ below ⦄ : BoundedBelow a
overlap ⦃ above ⦄ : BoundedAbove a
open BoundedBelow ⦃ ... ⦄ public
open BoundedAbove ⦃ ... ⦄ public
instance
iBounded : ⦃ BoundedBelow a ⦄ → ⦃ BoundedAbove a ⦄ → Bounded a
iBounded .Bounded.below = it
iBounded .Bounded.above = it
instance
iBoundedBelowNatural : BoundedBelow Nat
iBoundedBelowNatural .minBound = 0
iBoundedBelowWord : BoundedBelow Word
iBoundedBelowWord .minBound = 0
iBoundedAboveWord : BoundedAbove Word
iBoundedAboveWord .maxBound = 18446744073709551615
iBoundedBelowInt : BoundedBelow Int
iBoundedBelowInt .minBound = -9223372036854775808
iBoundedAboveInt : BoundedAbove Int
iBoundedAboveInt .maxBound = 9223372036854775807
iBoundedBelowBool : BoundedBelow Bool
iBoundedBelowBool .minBound = false
iBoundedAboveBool : BoundedAbove Bool
iBoundedAboveBool .maxBound = true
iBoundedBelowChar : BoundedBelow Char
iBoundedBelowChar .minBound = '\0'
iBoundedAboveChar : BoundedAbove Char
iBoundedAboveChar .maxBound = '\1114111'
iBoundedBelowTuple₀ : BoundedBelow (Tuple [])
iBoundedBelowTuple₀ .minBound = []
iBoundedAboveTuple₀ : BoundedAbove (Tuple [])
iBoundedAboveTuple₀ .maxBound = []
iBoundedBelowTuple : ∀ {as} → ⦃ BoundedBelow a ⦄ → ⦃ BoundedBelow (Tuple as) ⦄ → BoundedBelow (Tuple (a ∷ as))
iBoundedBelowTuple .minBound = minBound ∷ minBound
iBoundedAboveTuple : ∀ {as} → ⦃ BoundedAbove a ⦄ → ⦃ BoundedAbove (Tuple as) ⦄ → BoundedAbove (Tuple (a ∷ as))
iBoundedAboveTuple .maxBound = maxBound ∷ maxBound
iBoundedBelowOrdering : BoundedBelow Ordering
iBoundedBelowOrdering .minBound = LT
iBoundedAboveOrdering : BoundedAbove Ordering
iBoundedAboveOrdering .maxBound = GT
-- Sanity checks
private
_ : addWord maxBound 1 ≡ minBound
_ = refl
_ : addInt maxBound 1 ≡ minBound
_ = refl
|
{
"alphanum_fraction": 0.7360549717,
"avg_line_length": 27.797752809,
"ext": "agda",
"hexsha": "add0cd1454a4836512a0567aa888b34a307d5f33",
"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": "4cb28f1b5032948b19b977b390fa260be292abf6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/agda2hs",
"max_forks_repo_path": "lib/Haskell/Prim/Bounded.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6",
"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": "flupe/agda2hs",
"max_issues_repo_path": "lib/Haskell/Prim/Bounded.agda",
"max_line_length": 112,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/agda2hs",
"max_stars_repo_path": "lib/Haskell/Prim/Bounded.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 803,
"size": 2474
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
module C1 {@♭ i₁ j₁ : ULevel}
(@♭ I : Type i₁)
(@♭ R : I → Type j₁)
(@♭ r₀ : (index : I) → R index) where
-- We assume the family R satisfies Axiom C0
open import Axiom.C0 {i₁} {j₁} I R
open import Basics
open import Flat
open import Sharp
open import lib.types.Bool
open import Bool
open import lib.Equivalence2
open import lib.types.Coproduct
_is-discrete-C0 : {i : ULevel} (A : Type i) → Type _
_is-discrete-C0 {i} A = (index : I) → (is-equiv {i = i} (λ (a : A) → (λ (r : R index) → a)))
discrete-C0-eq : {i : ULevel} {A : Type i} (p : A is-discrete-C0) (index : I)
→ A ≃ ((R index) → A)
discrete-C0-eq p index = _ , (p index)
prop-is-discrete-C0 : {i : ULevel} (P : PropT i) → (P holds) is-discrete-C0
prop-is-discrete-C0 P =
(λ index →
is-eq to
fro
(λ f → λ= (λ r → prop-path (P holds-is-a-prop) (f (r₀ index)) (f r)))
(λ p → prop-path (P holds-is-a-prop) (fro {index} (to p)) p))
where
to : {index : I} → P holds → (r : R index) → P holds
to = λ p _ → p
fro : {index : I} → ((r : R index) → P holds) → P holds
fro {index} = λ f → f (r₀ index)
crisp-prop-is-discrete : {@♭ i : ULevel} (@♭ P : PropT i) → (P holds) is-discrete
crisp-prop-is-discrete P = C0 (P holds) (prop-is-discrete-C0 P)
⊥-is-discrete : ⊥ is-discrete
⊥-is-discrete = crisp-prop-is-discrete False
-- Mapping into a C0 discrete gives a C0 discrete space.
-- The argument is by swapping the order of application.
Π-♭-C0 : {i j : ULevel} {A : Type i}
{B : A → Type j} (p : (a : A) → (B a) is-discrete-C0)
→ ((a : A) → B a) is-discrete-C0
Π-♭-C0 {A = A} {B = B} p =
λ index → _ is-an-equivalence-because
(fro index) is-inverse-by
to-fro index and fro-to index
where
fro : (index : I) → ((R index) → (a : A) → B a) → (a : A) → B a
fro index f a = (<– (discrete-C0-eq (p a) index)) (λ r → f r a)
abstract
to-fro : ∀ index f → (λ _ → fro index f) == f
to-fro index f = -- We swap the order of r and a and use the discreteness of B a
λ= $ λ r →
λ= $ λ a →
app= (lemma a) r
where
lemma : ∀ a → (λ _ → fro index f a) == (λ r → f r a)
lemma a = <–-inv-r (discrete-C0-eq (p a) index) $ λ r → f r a
fro-to : ∀ index f → (fro index (λ _ → f)) == f
fro-to index f =
λ= $ λ a →
<–-inv-l (discrete-C0-eq (p a) index) $ f a
-- Crisp propositions are codiscrete
crisp-prop-is-codiscrete : {@♭ i : ULevel} (@♭ P : PropT i) → (P holds) is-codiscrete
crisp-prop-is-codiscrete P =
(P holds) is-codiscrete-because -- We give the map going the other way:
♯ (P holds) –⟨ map₁ ⟩→ ♭ (♯ (P holds)) –⟨ map₂ ⟩→ ♭ (P holds) –⟨ _↓♭ ⟩→ P holds →∎
is-retract-by (λ _ → prop-path (snd P) _ _)
where
map₁ : ♯ (P holds) → ♭ (♯ (P holds))
map₁ = <– (discrete-eq (crisp-prop-is-discrete (♯ₙ P)))
map₂ : ♭ (♯ (P holds)) → ♭ (P holds)
map₂ = –> ♭♯-eq
¬-is-codiscrete : ∀ {i} (A : Type i) → (¬ A) is-codiscrete
¬-is-codiscrete {i} A = -- mapping into a codiscrete is codiscrete.
replete (Π-codisc {A = A} (λ _ → ⊥)) (lemma₁ ⁻¹)
where
lemma₁ : (A → ⊥) ≃ (A → ♯ ⊥)-- ⊥ is codiscrete b/c it is crisp.
lemma₁ = post∘-equiv (codisc-eq (crisp-prop-is-codiscrete False))
open import lib.types.Modality
replete = (Modality.local-is-replete {i}) ♯-modality
♭-commutes-with-¬ : {@♭ i : ULevel} {@♭ A : Type i} → ♭ (¬ A) ≃ ¬ (♭ A)
♭-commutes-with-¬ {i = i} {A = A} =
♭ (¬ A)
≃⟨ ♭→e {A = ¬ A} {B = A → ♯ ⊥} lemma₁ ⟩
♭ (A → ♯ ⊥)
≃⟨ ♭♯-adjoint ⁻¹ ⟩
♭ (¬ (♭ A))
≃⟨ discrete-eq (crisp-prop-is-discrete (¬ (♭ A) , proof)) ⟩
¬ (♭ A)
≃∎
where
lemma₁ : (A → ⊥) ≃ (A → ♯ ⊥)-- ⊥ is codiscrete b/c it is crisp.
lemma₁ = post∘-equiv (codisc-eq (crisp-prop-is-codiscrete False))
proof : ¬ (♭ A) is-a-prop
proof = mapping-into-prop-is-a-prop (λ _ → False holds-is-a-prop)
-- Hereafter, we use LEM
open import LEM
open import NotNot
module _ {@♭ i : ULevel} where
record Γ : Type (lsucc i) where
constructor ctx
field
ᶜP : PropT i
ᶜnnp : ¬¬ (ᶜP holds) holds
open Γ
♯-prop-is-¬¬ : (P : PropT i) → ((♯ₙ P) holds) ≃ ((¬¬ (P holds)) holds)
♯-prop-is-¬¬ P =
iff-to-≃ {P = ♯ₙ P} {Q = ¬¬ (P holds)}
-- ⇒
(♯ₙ P holds
–⟨ (λ a → let♯ u ^♯:= a in♯ ((continue u) ^♯)) ⟩→
♯ₙ (¬¬ (P holds)) holds
–⟨ un♯ (¬-is-codiscrete (¬ (P holds))) ⟩→
¬¬ (P holds) holds
→∎)
-- ⇐
(λ nnp → {!let♯ γ ::= (ctx P nnp) in♯ (helper (ᶜP γ) (ᶜnnp γ)) ^^♯-in-family (λ (@♭ γ : Γ) → (ᶜP γ) holds) !})
where
helper : (@♭ P : PropT i) → ((¬¬ (P holds)) holds) ::→ (P holds)
helper P nnp = (un¬¬-crisp {P = P} nnp)
|
{
"alphanum_fraction": 0.4792147806,
"avg_line_length": 35.3469387755,
"ext": "agda",
"hexsha": "d64171fa74f3048ac1a6bbd16902fd5b6cd73659",
"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": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "glangmead/formalization",
"max_forks_repo_path": "cohesion/david_jaz_261/C1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a",
"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": "glangmead/formalization",
"max_issues_repo_path": "cohesion/david_jaz_261/C1.agda",
"max_line_length": 118,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "glangmead/formalization",
"max_stars_repo_path": "cohesion/david_jaz_261/C1.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-13T05:51:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-06T17:39:22.000Z",
"num_tokens": 2006,
"size": 5196
}
|
-- this is so this can be imported even though it has unresolved holes
{-# OPTIONS --allow-unsolved-metas #-}
module v01-01-basics where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
data day : Set where
mon : day
tue : day
wed : day
thu : day
fri : day
sat : day
sun : day
next-weekday : day → day
next-weekday mon = tue
next-weekday tue = wed
next-weekday wed = thu
next-weekday thu = fri
next-weekday fri = mon
next-weekday sat = mon
next-weekday sun = mon
_ : next-weekday fri ≡ mon
_ = refl
_ : next-weekday (next-weekday sat) ≡ tue
_ = refl
data bool : Set where
true : bool
false : bool
negb : bool → bool
negb true = false
negb false = true
andb : bool → bool → bool
andb true b2 = b2
andb false _ = false
orb : bool → bool → bool
orb true _ = true
orb false b2 = b2
_ : orb false false ≡ false
_ = refl
_ : orb false true ≡ true
_ = refl
_ : orb true false ≡ true
_ = refl
_ : orb true true ≡ true
_ = refl
nandb : bool → bool → bool
nandb true true = false
nandb _ _ = true
_ : nandb false false ≡ true
_ = refl
_ : nandb false true ≡ true
_ = refl
_ : nandb true false ≡ true
_ = refl
_ : nandb true true ≡ false
_ = refl
andb3 : bool → bool → bool → bool
andb3 true true true = true
andb3 _ _ _ = false
_ : andb3 true true true ≡ true
_ = refl
_ : andb3 false true true ≡ false
_ = refl
_ : andb3 true false true ≡ false
_ = refl
_ : andb3 true true false ≡ false
_ = refl
data rgb : Set where
red : rgb
green : rgb
blue : rgb
data color : Set where
black : color
white : color
primary : rgb → color
monochrome : color → bool
monochrome black = true
monochrome white = true
monochrome (primary _) = false
isred : color → bool
isred (primary red) = true
isred _ = false
data bit : Set where
B0 : bit
B1 : bit
data nybble : Set where
bits : (b0 b1 b2 b3 : bit) → nybble
all-zero : nybble → bool
all-zero (bits B0 B0 B0 B0) = true
all-zero _ = false
_ : all-zero (bits B1 B0 B1 B0) ≡ false
_ = refl
_ : all-zero (bits B0 B0 B0 B0) ≡ true
_ = refl
data nat : Set where
O : nat
S : nat → nat
pred : nat → nat
pred O = O
pred (S n) = n
{-# BUILTIN NATURAL nat #-}
_ : S (S (S (S O))) ≡ 4
_ = refl
minustwo : nat → nat
minustwo O = O
minustwo (S O) = O
minustwo (S (S n)) = n
_ : minustwo 4 ≡ 2
_ = refl
evenb : nat → bool
evenb O = true
evenb (S O) = false
evenb (S (S n)) = evenb n
oddb : nat → bool
oddb n = negb (evenb n)
_ : oddb 1 ≡ true
_ = refl
_ : oddb 4 ≡ false
_ = refl
plus : nat → nat → nat
plus O m = m
plus (S n) m = S (plus n m)
_ : plus 3 2 ≡ 5
_ = refl
mult : nat → nat → nat
mult O m = 0
mult (S n) m = plus m (mult n m)
_ : mult 3 3 ≡ 9
_ = refl
minus : nat → nat → nat
minus O _ = O
minus x O = x
minus (S n) (S m) = minus n m
exp : (base power : nat) → nat
exp _ O = S O
exp b (S p) = mult b (exp b p)
_ : exp 2 0 ≡ 1
_ = refl
_ : exp 2 1 ≡ 2
_ = refl
_ : exp 2 2 ≡ 4
_ = refl
_ : exp 2 3 ≡ 8
_ = refl
factorial : nat → nat
factorial O = 1
factorial (S n) = mult (S n) (factorial n)
_ : factorial 3 ≡ 6
_ = refl
_ : factorial 5 ≡ mult 10 12
_ = refl
_+_ : nat → nat → nat
_+_ = plus
_-_ : nat → nat → nat
_-_ = minus
_*_ : nat → nat → nat
_*_ = mult
infixl 6 _+_ _-_
infixl 7 _*_
{-# BUILTIN NATPLUS _+_ #-}
{-# BUILTIN NATTIMES _*_ #-}
{-# BUILTIN NATMINUS _-_ #-}
eqb : (n m : nat) → bool
eqb O O = true
eqb O (S _) = false
eqb (S _) O = false
eqb (S l) (S r) = eqb l r
leb : (n m : nat) → bool
leb O _ = true
leb (S n) O = false
leb (S n) (S m) = leb n m
_ : leb 2 2 ≡ true
_ = refl
_ : leb 2 4 ≡ true
_ = refl
_ : leb 4 2 ≡ false
_ = refl
_=?_ : (n m : nat) → bool
_=?_ = eqb
_<=?_ : (n m : nat) → bool
_<=?_ = leb
infix 4 _=?_
infix 4 _<=?_
_ : (4 <=? 2) ≡ false
_ = refl
ltb : (n m : nat) → bool
ltb O O = false
ltb O (S m) = true
ltb (S n) O = false
ltb (S n) (S m) = ltb n m
_<?_ : (n m : nat) → bool
_<?_ = ltb
infix 4 _<?_
_ : ltb 2 2 ≡ false
_ = refl
_ : ltb 2 4 ≡ true
_ = refl
_ : ltb 4 2 ≡ false
_ = refl
-- proof by simplification
plus-O-n : ∀ {n : nat} → 0 + n ≡ n
plus-O-n = refl
plus-1-l : ∀ {n : nat} → 1 + n ≡ S n
plus-1-l = refl
mult-O-l : ∀ {n : nat} → 0 * n ≡ 0
mult-O-l = refl
-- proof by rewriting
plus-id-example : ∀ {n m : nat}
→ n ≡ m
→ n + n ≡ m + m
plus-id-example n≡m rewrite n≡m = refl
plus_id_exercise : ∀ {n m o : nat}
→ n ≡ m
→ m ≡ o
→ n + m ≡ m + o
plus_id_exercise n≡m m≡o rewrite n≡m | m≡o = refl
*0 : ∀ (m : nat) → m * 0 ≡ 0
*0 0 = refl
*0 (S m) = *0 m
mult-n-O : ∀ (n : nat) → 0 ≡ n * 0
mult-n-O n rewrite *0 n = refl
*1 : ∀ (n : nat) → n * 1 ≡ n
*1 0 = refl
*1 (S n) rewrite *1 n = refl
1* : ∀ (n : nat) → 1 * n ≡ n
1* 0 = refl
1* (S n) rewrite 1* n = refl
mult-n-Sm : ∀ (n m : nat) → n * m + n ≡ n * S m
mult-n-Sm O m = refl
mult-n-Sm n O rewrite *0 n | plus-O-n {n} | *1 n = refl
mult-n-Sm (S n) (S m) = {!!} -- TODO
mult-n-0-m-0 : ∀ (p q : nat)
→ (p * 0) + (q * 0) ≡ 0
mult-n-0-m-0 p q rewrite *0 p | *0 q = refl
mult-n-1 : ∀ (p : nat) → p * 1 ≡ p
mult-n-1 = *1
-- proof by case analysis
plus-1-neq-0 : ∀ (n : nat) → ((n + 1) =? 0) ≡ false
plus-1-neq-0 O = refl
plus-1-neq-0 (S n) rewrite plus-1-neq-0 n = refl
negb-involutive : ∀ (b : bool) → negb (negb b) ≡ b
negb-involutive true = refl
negb-involutive false = refl
andb-commutative : ∀ (b c : bool) → andb b c ≡ andb c b
andb-commutative false false = refl
andb-commutative false true = refl
andb-commutative true false = refl
andb-commutative true true = refl
andb3-exchange : ∀ (b c d : bool) → andb (andb b c) d ≡ andb (andb b d) c
andb3-exchange true true true = refl
andb3-exchange true true false = refl
andb3-exchange true false true = refl
andb3-exchange true false false = refl
andb3-exchange false true true = refl
andb3-exchange false true false = refl
andb3-exchange false false true = refl
andb3-exchange false false false = refl
andb-true-elim2 : ∀ (b c : bool)
→ andb b c ≡ true
→ c ≡ true
andb-true-elim2 false _ ()
andb-true-elim2 true false ()
andb-true-elim2 true true _ = refl
zero-nbeq-plus-1 : ∀ (n : nat) → (0 =? (n + 1)) ≡ false
zero-nbeq-plus-1 O = refl
zero-nbeq-plus-1 (S n) rewrite zero-nbeq-plus-1 n = refl
identity-fn-applied-twice : ∀ {f : bool → bool} (b : bool)
→ f b ≡ b
→ f (f b) ≡ b
identity-fn-applied-twice b p rewrite p | p = refl
negation-fn-applied-twice : ∀ {f : bool → bool} {b : bool} -- TODO
→ f b ≡ negb b
→ f (f b) ≡ b
negation-fn-applied-twice {f} {false} p = {!!} -- TODO
negation-fn-applied-twice {f} {true} p = {!!} -- TODO
andb-eq-orb : ∀ (b c : bool)
→ andb b c ≡ orb b c
→ b ≡ c
andb-eq-orb true c p rewrite p = refl
andb-eq-orb false c p rewrite p = refl
-- NOTE: lowest order bit is on LEFT
data bin : Set where
Z : bin
B₀ : bin → bin
B₁ : bin → bin
incr : bin → bin
incr Z = B₁ Z
incr (B₀ x) = B₁ x
incr (B₁ x) = B₀ (incr x)
bin-to-nat : bin → nat
bin-to-nat Z = 0
bin-to-nat (B₀ x) = 2 * (bin-to-nat x)
bin-to-nat (B₁ x) = 1 + 2 * (bin-to-nat x)
_ : (incr (B₁ Z)) ≡ B₀ (B₁ Z)
_ = refl
_ : (incr (B₀ (B₁ Z))) ≡ B₁ (B₁ Z)
_ = refl
_ : (incr (B₁ (B₁ Z))) ≡ B₀ (B₀ (B₁ Z))
_ = refl
_ : bin-to-nat (B₀ (B₁ Z)) ≡ 2
_ = refl
_ : bin-to-nat (incr (B₁ Z)) ≡ 1 + bin-to-nat (B₁ Z)
_ = refl
_ : bin-to-nat (incr (incr (B₁ Z))) ≡ 2 + bin-to-nat (B₁ Z)
_ = refl
|
{
"alphanum_fraction": 0.5602734324,
"avg_line_length": 19.4056122449,
"ext": "agda",
"hexsha": "c558fa386b713a5e93bc278797c75acd7380432b",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/book/SFHC/v01-01-basics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/book/SFHC/v01-01-basics.agda",
"max_line_length": 73,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/book/SFHC/v01-01-basics.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 3222,
"size": 7607
}
|
open import Agda.Builtin.Unit
open import Agda.Builtin.List
open import Agda.Builtin.Reflection
id : {A : Set} → A → A
id x = x
macro
tac : Term → TC ⊤
tac hole = unify hole (def (quote id) (arg (arg-info visible relevant) (var 0 []) ∷ []))
test : {A : Set} → A → A
test x = {!tac!}
|
{
"alphanum_fraction": 0.6206896552,
"avg_line_length": 20.7142857143,
"ext": "agda",
"hexsha": "17d0b50de5b3f039ae17ed45c3881b055e8b63ff",
"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": "96860c1612fe64e5cdcc4ea6cb05b6b31673ca31",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "msuperdock/agda",
"max_forks_repo_path": "test/interaction/Issue3486.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "96860c1612fe64e5cdcc4ea6cb05b6b31673ca31",
"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": "msuperdock/agda",
"max_issues_repo_path": "test/interaction/Issue3486.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "96860c1612fe64e5cdcc4ea6cb05b6b31673ca31",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "msuperdock/agda",
"max_stars_repo_path": "test/interaction/Issue3486.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 101,
"size": 290
}
|
module bijection where
open import Level renaming ( zero to Zero ; suc to Suc )
open import Data.Nat
open import Data.Maybe
open import Data.List hiding ([_] ; sum )
open import Data.Nat.Properties
open import Relation.Nullary
open import Data.Empty
open import Data.Unit hiding ( _≤_ )
open import Relation.Binary.Core hiding (_⇔_)
open import Relation.Binary.Definitions
open import Relation.Binary.PropositionalEquality
open import logic
open import nat
-- record Bijection {n m : Level} (R : Set n) (S : Set m) : Set (n Level.⊔ m) where
-- field
-- fun← : S → R
-- fun→ : R → S
-- fiso← : (x : R) → fun← ( fun→ x ) ≡ x
-- fiso→ : (x : S ) → fun→ ( fun← x ) ≡ x
--
-- injection : {n m : Level} (R : Set n) (S : Set m) (f : R → S ) → Set (n Level.⊔ m)
-- injection R S f = (x y : R) → f x ≡ f y → x ≡ y
open Bijection
bi-trans : {n m l : Level} (R : Set n) (S : Set m) (T : Set l) → Bijection R S → Bijection S T → Bijection R T
bi-trans R S T rs st = record { fun← = λ x → fun← rs ( fun← st x ) ; fun→ = λ x → fun→ st ( fun→ rs x )
; fiso← = λ x → trans (cong (λ k → fun← rs k) (fiso← st (fun→ rs x))) ( fiso← rs x)
; fiso→ = λ x → trans (cong (λ k → fun→ st k) (fiso→ rs (fun← st x))) ( fiso→ st x) }
bid : {n : Level} (R : Set n) → Bijection R R
bid {n} R = record { fun← = λ x → x ; fun→ = λ x → x ; fiso← = λ _ → refl ; fiso→ = λ _ → refl }
bi-sym : {n m : Level} (R : Set n) (S : Set m) → Bijection R S → Bijection S R
bi-sym R S eq = record { fun← = fun→ eq ; fun→ = fun← eq ; fiso← = fiso→ eq ; fiso→ = fiso← eq }
open import Relation.Binary.Structures
bijIsEquivalence : {n : Level } → IsEquivalence (Bijection {n} {n})
bijIsEquivalence = record { refl = λ {R} → bid R ; sym = λ {R} {S} → bi-sym R S ; trans = λ {R} {S} {T} → bi-trans R S T }
-- ¬ A = A → ⊥
--
-- famous diagnostic function
--
diag : {S : Set } (b : Bijection ( S → Bool ) S) → S → Bool
diag b n = not (fun← b n n)
diagonal : { S : Set } → ¬ Bijection ( S → Bool ) S
diagonal {S} b = diagn1 (fun→ b (λ n → diag b n) ) refl where
diagn1 : (n : S ) → ¬ (fun→ b (λ n → diag b n) ≡ n )
diagn1 n dn = ¬t=f (diag b n ) ( begin
not (diag b n)
≡⟨⟩
not (not fun← b n n)
≡⟨ cong (λ k → not (k n) ) (sym (fiso← b _)) ⟩
not (fun← b (fun→ b (diag b)) n)
≡⟨ cong (λ k → not (fun← b k n) ) dn ⟩
not (fun← b n n)
≡⟨⟩
diag b n
∎ ) where open ≡-Reasoning
b1 : (b : Bijection ( ℕ → Bool ) ℕ) → ℕ
b1 b = fun→ b (diag b)
b-iso : (b : Bijection ( ℕ → Bool ) ℕ) → fun← b (b1 b) ≡ (diag b)
b-iso b = fiso← b _
--
-- ℕ <=> ℕ + 1
--
to1 : {n : Level} {R : Set n} → Bijection ℕ R → Bijection ℕ (⊤ ∨ R )
to1 {n} {R} b = record {
fun← = to11
; fun→ = to12
; fiso← = to13
; fiso→ = to14
} where
to11 : ⊤ ∨ R → ℕ
to11 (case1 tt) = 0
to11 (case2 x) = suc ( fun← b x )
to12 : ℕ → ⊤ ∨ R
to12 zero = case1 tt
to12 (suc n) = case2 ( fun→ b n)
to13 : (x : ℕ) → to11 (to12 x) ≡ x
to13 zero = refl
to13 (suc x) = cong suc (fiso← b x)
to14 : (x : ⊤ ∨ R) → to12 (to11 x) ≡ x
to14 (case1 x) = refl
to14 (case2 x) = cong case2 (fiso→ b x)
open _∧_
record NN ( i : ℕ) (nxn→n : ℕ → ℕ → ℕ) (n→nxn : ℕ → ℕ ∧ ℕ) : Set where
field
j k sum stage : ℕ
nn : j + k ≡ sum
ni : i ≡ j + stage -- not used
k1 : nxn→n j k ≡ i
k0 : n→nxn i ≡ ⟪ j , k ⟫
nn-unique : {j0 k0 : ℕ } → nxn→n j0 k0 ≡ i → ⟪ j , k ⟫ ≡ ⟪ j0 , k0 ⟫
i≤0→i≡0 : {i : ℕ } → i ≤ 0 → i ≡ 0
i≤0→i≡0 {0} z≤n = refl
nxn : Bijection ℕ (ℕ ∧ ℕ)
nxn = record {
fun← = λ p → nxn→n (proj1 p) (proj2 p)
; fun→ = n→nxn
; fiso← = n-id
; fiso→ = λ x → nn-id (proj1 x) (proj2 x)
} where
nxn→n : ℕ → ℕ → ℕ
nxn→n zero zero = zero
nxn→n zero (suc j) = j + suc (nxn→n zero j)
nxn→n (suc i) zero = suc i + suc (nxn→n i zero)
nxn→n (suc i) (suc j) = suc i + suc j + suc (nxn→n i (suc j))
n→nxn : ℕ → ℕ ∧ ℕ
n→nxn zero = ⟪ 0 , 0 ⟫
n→nxn (suc i) with n→nxn i
... | ⟪ x , zero ⟫ = ⟪ zero , suc x ⟫
... | ⟪ x , suc y ⟫ = ⟪ suc x , y ⟫
nxn→n0 : { j k : ℕ } → nxn→n j k ≡ 0 → ( j ≡ 0 ) ∧ ( k ≡ 0 )
nxn→n0 {zero} {zero} eq = ⟪ refl , refl ⟫
nxn→n0 {zero} {(suc k)} eq = ⊥-elim ( nat-≡< (sym eq) (subst (λ k → 0 < k) (+-comm _ k) (s≤s z≤n)))
nxn→n0 {(suc j)} {zero} eq = ⊥-elim ( nat-≡< (sym eq) (s≤s z≤n) )
nxn→n0 {(suc j)} {(suc k)} eq = ⊥-elim ( nat-≡< (sym eq) (s≤s z≤n) )
nid20 : (i : ℕ) → i + (nxn→n 0 i) ≡ nxn→n i 0
nid20 zero = refl -- suc (i + (i + suc (nxn→n 0 i))) ≡ suc (i + suc (nxn→n i 0))
nid20 (suc i) = begin
suc (i + (i + suc (nxn→n 0 i))) ≡⟨ cong (λ k → suc (i + k)) (sym (+-assoc i 1 (nxn→n 0 i))) ⟩
suc (i + ((i + 1) + nxn→n 0 i)) ≡⟨ cong (λ k → suc (i + (k + nxn→n 0 i))) (+-comm i 1) ⟩
suc (i + suc (i + nxn→n 0 i)) ≡⟨ cong ( λ k → suc (i + suc k)) (nid20 i) ⟩
suc (i + suc (nxn→n i 0)) ∎ where open ≡-Reasoning
nid4 : {i j : ℕ} → i + 1 + j ≡ i + suc j
nid4 {zero} {j} = refl
nid4 {suc i} {j} = cong suc (nid4 {i} {j} )
nid5 : {i j k : ℕ} → i + suc (suc j) + suc k ≡ i + suc j + suc (suc k )
nid5 {zero} {j} {k} = begin
suc (suc j) + suc k ≡⟨ +-assoc 1 (suc j) _ ⟩
1 + (suc j + suc k) ≡⟨ +-comm 1 _ ⟩
(suc j + suc k) + 1 ≡⟨ +-assoc (suc j) (suc k) _ ⟩
suc j + (suc k + 1) ≡⟨ cong (λ k → suc j + k ) (+-comm (suc k) 1) ⟩
suc j + suc (suc k) ∎ where open ≡-Reasoning
nid5 {suc i} {j} {k} = cong suc (nid5 {i} {j} {k} )
-- increment in ths same stage
nid2 : (i j : ℕ) → suc (nxn→n i (suc j)) ≡ nxn→n (suc i) j
nid2 zero zero = refl
nid2 zero (suc j) = refl
nid2 (suc i) zero = begin
suc (nxn→n (suc i) 1) ≡⟨ refl ⟩
suc (suc (i + 1 + suc (nxn→n i 1))) ≡⟨ cong (λ k → suc (suc k)) nid4 ⟩
suc (suc (i + suc (suc (nxn→n i 1)))) ≡⟨ cong (λ k → suc (suc (i + suc (suc k)))) (nid3 i) ⟩
suc (suc (i + suc (suc (i + suc (nxn→n i 0))))) ≡⟨ refl ⟩
nxn→n (suc (suc i)) zero ∎ where
open ≡-Reasoning
nid3 : (i : ℕ) → nxn→n i 1 ≡ i + suc (nxn→n i 0)
nid3 zero = refl
nid3 (suc i) = begin
suc (i + 1 + suc (nxn→n i 1)) ≡⟨ cong suc nid4 ⟩
suc (i + suc (suc (nxn→n i 1))) ≡⟨ cong (λ k → suc (i + suc (suc k))) (nid3 i) ⟩
suc (i + suc (suc (i + suc (nxn→n i 0)))) ∎
nid2 (suc i) (suc j) = begin
suc (nxn→n (suc i) (suc (suc j))) ≡⟨ refl ⟩
suc (suc (i + suc (suc j) + suc (nxn→n i (suc (suc j))))) ≡⟨ cong (λ k → suc (suc (i + suc (suc j) + k))) (nid2 i (suc j)) ⟩
suc (suc (i + suc (suc j) + suc (i + suc j + suc (nxn→n i (suc j))))) ≡⟨ cong ( λ k → suc (suc k)) nid5 ⟩
suc (suc (i + suc j + suc (suc (i + suc j + suc (nxn→n i (suc j)))))) ≡⟨ refl ⟩
nxn→n (suc (suc i)) (suc j) ∎ where
open ≡-Reasoning
-- increment ths stage
nid00 : (i : ℕ) → suc (nxn→n i 0) ≡ nxn→n 0 (suc i)
nid00 zero = refl
nid00 (suc i) = begin
suc (suc (i + suc (nxn→n i 0))) ≡⟨ cong (λ k → suc (suc (i + k ))) (nid00 i) ⟩
suc (suc (i + (nxn→n 0 (suc i)))) ≡⟨ refl ⟩
suc (suc (i + (i + suc (nxn→n 0 i)))) ≡⟨ cong suc (sym ( +-assoc 1 i (i + suc (nxn→n 0 i)))) ⟩
suc ((1 + i) + (i + suc (nxn→n 0 i))) ≡⟨ cong (λ k → suc (k + (i + suc (nxn→n 0 i)))) (+-comm 1 i) ⟩
suc ((i + 1) + (i + suc (nxn→n 0 i))) ≡⟨ cong suc (+-assoc i 1 (i + suc (nxn→n 0 i))) ⟩
suc (i + suc (i + suc (nxn→n 0 i))) ∎ where open ≡-Reasoning
-----
--
-- create the invariant NN for all n
--
nn : ( i : ℕ) → NN i nxn→n n→nxn
nn zero = record { j = 0 ; k = 0 ; sum = 0 ; stage = 0 ; nn = refl ; ni = refl ; k1 = refl ; k0 = refl
; nn-unique = λ {j0} {k0} eq → cong₂ (λ x y → ⟪ x , y ⟫) (sym (proj1 (nxn→n0 eq))) (sym (proj2 (nxn→n0 {j0} {k0} eq))) }
nn (suc i) with NN.k (nn i) | inspect NN.k (nn i)
... | zero | record { eq = eq } = record { k = suc (NN.sum (nn i)) ; j = 0 ; sum = suc (NN.sum (nn i)) ; stage = suc (NN.sum (nn i)) + (NN.stage (nn i))
; nn = refl
; ni = nn01 ; k1 = nn02 ; k0 = nn03 ; nn-unique = nn04 } where
---
--- increment the stage
---
sum = NN.sum (nn i)
stage = NN.stage (nn i)
j = NN.j (nn i)
nn01 : suc i ≡ 0 + (suc sum + stage )
nn01 = begin
suc i ≡⟨ cong suc (NN.ni (nn i)) ⟩
suc ((NN.j (nn i) ) + stage ) ≡⟨ cong (λ k → suc (k + stage )) (+-comm 0 _ ) ⟩
suc ((NN.j (nn i) + 0 ) + stage ) ≡⟨ cong (λ k → suc ((NN.j (nn i) + k) + stage )) (sym eq) ⟩
suc ((NN.j (nn i) + NN.k (nn i)) + stage ) ≡⟨ cong (λ k → suc ( k + stage )) (NN.nn (nn i)) ⟩
0 + (suc sum + stage ) ∎ where open ≡-Reasoning
nn02 : nxn→n 0 (suc sum) ≡ suc i
nn02 = begin
sum + suc (nxn→n 0 sum) ≡⟨ sym (+-assoc sum 1 (nxn→n 0 sum)) ⟩
(sum + 1) + nxn→n 0 sum ≡⟨ cong (λ k → k + nxn→n 0 sum ) (+-comm sum 1 )⟩
suc (sum + nxn→n 0 sum) ≡⟨ cong suc (nid20 sum ) ⟩
suc (nxn→n sum 0) ≡⟨ cong (λ k → suc (nxn→n k 0 )) (sym (NN.nn (nn i))) ⟩
suc (nxn→n (NN.j (nn i) + (NN.k (nn i)) ) 0) ≡⟨ cong₂ (λ j k → suc (nxn→n (NN.j (nn i) + j) k )) eq (sym eq) ⟩
suc (nxn→n (NN.j (nn i) + 0 ) (NN.k (nn i))) ≡⟨ cong (λ k → suc ( nxn→n k (NN.k (nn i)))) (+-comm (NN.j (nn i)) 0) ⟩
suc (nxn→n (NN.j (nn i)) (NN.k (nn i))) ≡⟨ cong suc (NN.k1 (nn i) ) ⟩
suc i ∎ where open ≡-Reasoning
nn03 : n→nxn (suc i) ≡ ⟪ 0 , suc (NN.sum (nn i)) ⟫ -- k0 : n→nxn i ≡ ⟪ NN.j (nn i) = sum , NN.k (nn i) = 0 ⟫
nn03 with n→nxn i | inspect n→nxn i
... | ⟪ x , zero ⟫ | record { eq = eq1 } = begin
⟪ zero , suc x ⟫ ≡⟨ cong (λ k → ⟪ zero , suc k ⟫) (sym (cong proj1 eq1)) ⟩
⟪ zero , suc (proj1 (n→nxn i)) ⟫ ≡⟨ cong (λ k → ⟪ zero , suc k ⟫) (cong proj1 (NN.k0 (nn i))) ⟩
⟪ zero , suc (NN.j (nn i)) ⟫ ≡⟨ cong (λ k → ⟪ zero , suc k ⟫) (+-comm 0 _ ) ⟩
⟪ zero , suc (NN.j (nn i) + 0) ⟫ ≡⟨ cong (λ k → ⟪ zero , suc (NN.j (nn i) + k) ⟫ ) (sym eq) ⟩
⟪ zero , suc (NN.j (nn i) + NN.k (nn i)) ⟫ ≡⟨ cong (λ k → ⟪ zero , suc k ⟫ ) (NN.nn (nn i)) ⟩
⟪ 0 , suc sum ⟫ ∎ where open ≡-Reasoning
... | ⟪ x , suc y ⟫ | record { eq = eq1 } = ⊥-elim ( nat-≡< (sym (cong proj2 (NN.k0 (nn i)))) (begin
suc (NN.k (nn i)) ≡⟨ cong suc eq ⟩
suc 0 ≤⟨ s≤s z≤n ⟩
suc y ≡⟨ sym (cong proj2 eq1) ⟩
proj2 (n→nxn i) ∎ )) where open ≤-Reasoning
-- nid2 : (i j : ℕ) → suc (nxn→n i (suc j)) ≡ nxn→n (suc i) j
nn04 : {j0 k0 : ℕ} → nxn→n j0 k0 ≡ suc i → ⟪ 0 , suc (NN.sum (nn i)) ⟫ ≡ ⟪ j0 , k0 ⟫
nn04 {zero} {suc k0} eq1 = cong (λ k → ⟪ 0 , k ⟫ ) (cong suc (sym nn08)) where -- eq : nxn→n zero (suc k0) ≡ suc i --
nn07 : nxn→n k0 0 ≡ i
nn07 = cong pred ( begin
suc ( nxn→n k0 0 ) ≡⟨ nid00 k0 ⟩
nxn→n 0 (suc k0 ) ≡⟨ eq1 ⟩
suc i ∎ ) where open ≡-Reasoning
nn08 : k0 ≡ sum
nn08 = begin
k0 ≡⟨ cong proj1 (sym (NN.nn-unique (nn i) nn07)) ⟩
NN.j (nn i) ≡⟨ +-comm 0 _ ⟩
NN.j (nn i) + 0 ≡⟨ cong (λ k → NN.j (nn i) + k) (sym eq) ⟩
NN.j (nn i) + NN.k (nn i) ≡⟨ NN.nn (nn i) ⟩
sum ∎ where open ≡-Reasoning
nn04 {suc j0} {k0} eq1 = ⊥-elim ( nat-≡< (cong proj2 (nn06 nn05)) (subst (λ k → k < suc k0) (sym eq) (s≤s z≤n))) where
nn05 : nxn→n j0 (suc k0) ≡ i
nn05 = begin
nxn→n j0 (suc k0) ≡⟨ cong pred ( begin
suc (nxn→n j0 (suc k0)) ≡⟨ nid2 j0 k0 ⟩
nxn→n (suc j0) k0 ≡⟨ eq1 ⟩
suc i ∎ ) ⟩
i ∎ where open ≡-Reasoning
nn06 : nxn→n j0 (suc k0) ≡ i → ⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡ ⟪ j0 , suc k0 ⟫
nn06 = NN.nn-unique (nn i)
... | suc k | record {eq = eq} = record { k = k ; j = suc (NN.j (nn i)) ; sum = NN.sum (nn i) ; stage = NN.stage (nn i) ; nn = nn10
; ni = cong suc (NN.ni (nn i)) ; k1 = nn11 ; k0 = nn12 ; nn-unique = nn13 } where
---
--- increment in a stage
---
nn10 : suc (NN.j (nn i)) + k ≡ NN.sum (nn i)
nn10 = begin
suc (NN.j (nn i)) + k ≡⟨ cong (λ x → x + k) (+-comm 1 _) ⟩
(NN.j (nn i) + 1) + k ≡⟨ +-assoc (NN.j (nn i)) 1 k ⟩
NN.j (nn i) + suc k ≡⟨ cong (λ k → NN.j (nn i) + k) (sym eq) ⟩
NN.j (nn i) + NN.k (nn i) ≡⟨ NN.nn (nn i) ⟩
NN.sum (nn i) ∎ where open ≡-Reasoning
nn11 : nxn→n (suc (NN.j (nn i))) k ≡ suc i -- nxn→n ( NN.j (nn i)) (NN.k (nn i) ≡ i
nn11 = begin
nxn→n (suc (NN.j (nn i))) k ≡⟨ sym (nid2 (NN.j (nn i)) k) ⟩
suc (nxn→n (NN.j (nn i)) (suc k)) ≡⟨ cong (λ k → suc (nxn→n (NN.j (nn i)) k)) (sym eq) ⟩
suc (nxn→n ( NN.j (nn i)) (NN.k (nn i))) ≡⟨ cong suc (NN.k1 (nn i)) ⟩
suc i ∎ where open ≡-Reasoning
nn18 : zero < NN.k (nn i)
nn18 = subst (λ k → 0 < k ) ( begin
suc k ≡⟨ sym eq ⟩
NN.k (nn i) ∎ ) (s≤s z≤n ) where open ≡-Reasoning
nn12 : n→nxn (suc i) ≡ ⟪ suc (NN.j (nn i)) , k ⟫ -- n→nxn i ≡ ⟪ NN.j (nn i) , NN.k (nn i) ⟫
nn12 with n→nxn i | inspect n→nxn i
... | ⟪ x , zero ⟫ | record { eq = eq1 } = ⊥-elim ( nat-≡< (sym (cong proj2 eq1))
(subst (λ k → 0 < k ) ( begin
suc k ≡⟨ sym eq ⟩
NN.k (nn i) ≡⟨ cong proj2 (sym (NN.k0 (nn i)) ) ⟩
proj2 (n→nxn i) ∎ ) (s≤s z≤n )) ) where open ≡-Reasoning -- eq1 n→nxn i ≡ ⟪ x , zero ⟫
... | ⟪ x , suc y ⟫ | record { eq = eq1 } = begin -- n→nxn i ≡ ⟪ x , suc y ⟫
⟪ suc x , y ⟫ ≡⟨ refl ⟩
⟪ suc x , pred (suc y) ⟫ ≡⟨ cong (λ k → ⟪ suc (proj1 k) , pred (proj2 k) ⟫) ( begin
⟪ x , suc y ⟫ ≡⟨ sym eq1 ⟩
n→nxn i ≡⟨ NN.k0 (nn i) ⟩
⟪ NN.j (nn i) , NN.k (nn i) ⟫ ∎ ) ⟩
⟪ suc (NN.j (nn i)) , pred (NN.k (nn i)) ⟫ ≡⟨ cong (λ k → ⟪ suc (NN.j (nn i)) , pred k ⟫) eq ⟩
⟪ suc (NN.j (nn i)) , k ⟫ ∎ where open ≡-Reasoning
nn13 : {j0 k0 : ℕ} → nxn→n j0 k0 ≡ suc i → ⟪ suc (NN.j (nn i)) , k ⟫ ≡ ⟪ j0 , k0 ⟫
nn13 {zero} {suc k0} eq1 = ⊥-elim ( nat-≡< (sym (cong proj2 nn17)) nn18 ) where -- (nxn→n zero (suc k0)) ≡ suc i
nn16 : nxn→n k0 zero ≡ i
nn16 = cong pred ( subst (λ k → k ≡ suc i) (sym ( nid00 k0 )) eq1 )
nn17 : ⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡ ⟪ k0 , zero ⟫
nn17 = NN.nn-unique (nn i) nn16
nn13 {suc j0} {k0} eq1 = begin
⟪ suc (NN.j (nn i)) , pred (suc k) ⟫ ≡⟨ cong (λ k → ⟪ suc (NN.j (nn i)) , pred k ⟫ ) (sym eq) ⟩
⟪ suc (NN.j (nn i)) , pred (NN.k (nn i)) ⟫ ≡⟨ cong (λ k → ⟪ suc (proj1 k) , pred (proj2 k) ⟫) ( begin
⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡⟨ nn15 ⟩
⟪ j0 , suc k0 ⟫ ∎ ) ⟩
⟪ suc j0 , k0 ⟫ ∎ where -- nxn→n (suc j0) k0 ≡ suc i
open ≡-Reasoning
nn14 : nxn→n j0 (suc k0) ≡ i
nn14 = cong pred ( subst (λ k → k ≡ suc i) (sym ( nid2 j0 k0 )) eq1 )
nn15 : ⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡ ⟪ j0 , suc k0 ⟫
nn15 = NN.nn-unique (nn i) nn14
n-id : (i : ℕ) → nxn→n (proj1 (n→nxn i)) (proj2 (n→nxn i)) ≡ i
n-id i = subst (λ k → nxn→n (proj1 k) (proj2 k) ≡ i ) (sym (NN.k0 (nn i))) (NN.k1 (nn i))
nn-id : (j k : ℕ) → n→nxn (nxn→n j k) ≡ ⟪ j , k ⟫
nn-id j k = begin
n→nxn (nxn→n j k) ≡⟨ NN.k0 (nn (nxn→n j k)) ⟩
⟪ NN.j (nn (nxn→n j k)) , NN.k (nn (nxn→n j k)) ⟫ ≡⟨ NN.nn-unique (nn (nxn→n j k)) refl ⟩
⟪ j , k ⟫ ∎ where open ≡-Reasoning
-- [] 0
-- 0 → 1
-- 1 → 2
-- 01 → 3
-- 11 → 4
-- ...
--
-- binary invariant
--
record LB (n : ℕ) (lton : List Bool → ℕ ) : Set where
field
nlist : List Bool
isBin : lton nlist ≡ n
isUnique : (x : List Bool) → lton x ≡ n → nlist ≡ x -- we don't need this
lb+1 : List Bool → List Bool
lb+1 [] = false ∷ []
lb+1 (false ∷ t) = true ∷ t
lb+1 (true ∷ t) = false ∷ lb+1 t
lb-1 : List Bool → List Bool
lb-1 [] = []
lb-1 (true ∷ t) = false ∷ t
lb-1 (false ∷ t) with lb-1 t
... | [] = true ∷ []
... | x ∷ t1 = true ∷ x ∷ t1
LBℕ : Bijection ℕ ( List Bool )
LBℕ = record {
fun← = λ x → lton x
; fun→ = λ n → LB.nlist (lb n)
; fiso← = λ n → LB.isBin (lb n)
; fiso→ = λ x → LB.isUnique (lb (lton x)) x refl
} where
lton1 : List Bool → ℕ
lton1 [] = 1
lton1 (true ∷ t) = suc (lton1 t + lton1 t)
lton1 (false ∷ t) = lton1 t + lton1 t
lton : List Bool → ℕ
lton x = pred (lton1 x)
lton1>0 : (x : List Bool ) → 0 < lton1 x
lton1>0 [] = a<sa
lton1>0 (true ∷ x₁) = 0<s
lton1>0 (false ∷ t) = ≤-trans (lton1>0 t) x≤x+y
2lton1>0 : (t : List Bool ) → 0 < lton1 t + lton1 t
2lton1>0 t = ≤-trans (lton1>0 t) x≤x+y
lb=3 : {x y : ℕ} → 0 < x → 0 < y → 1 ≤ pred (x + y)
lb=3 {suc x} {suc y} (s≤s 0<x) (s≤s 0<y) = subst (λ k → 1 ≤ k ) (+-comm (suc y) _ ) (s≤s z≤n)
lton-cons>0 : {x : Bool} {y : List Bool } → 0 < lton (x ∷ y)
lton-cons>0 {true} {[]} = refl-≤s
lton-cons>0 {true} {x ∷ y} = ≤-trans ( lb=3 (lton1>0 (x ∷ y)) (lton1>0 (x ∷ y))) px≤x
lton-cons>0 {false} {[]} = refl-≤
lton-cons>0 {false} {x ∷ y} = lb=3 (lton1>0 (x ∷ y)) (lton1>0 (x ∷ y))
lb=0 : {x y : ℕ } → pred x < pred y → suc (x + x ∸ 1) < suc (y + y ∸ 1)
lb=0 {0} {suc y} lt = s≤s (subst (λ k → 0 < k ) (+-comm (suc y) y ) 0<s)
lb=0 {suc x} {suc y} lt = begin
suc (suc ((suc x + suc x) ∸ 1)) ≡⟨ refl ⟩
suc (suc x) + suc x ≡⟨ refl ⟩
suc (suc x + suc x) ≤⟨ <-plus (s≤s lt) ⟩
suc y + suc x <⟨ <-plus-0 {suc x} {suc y} {suc y} (s≤s lt) ⟩
suc y + suc y ≡⟨ refl ⟩
suc ((suc y + suc y) ∸ 1) ∎ where open ≤-Reasoning
lb=2 : {x y : ℕ } → pred x < pred y → suc (x + x ) < suc (y + y )
lb=2 {zero} {suc y} lt = s≤s 0<s
lb=2 {suc x} {suc y} lt = s≤s (lb=0 {suc x} {suc y} lt)
lb=1 : {x y : List Bool} {z : Bool} → lton (z ∷ x) ≡ lton (z ∷ y) → lton x ≡ lton y
lb=1 {x} {y} {true} eq with <-cmp (lton x) (lton y)
... | tri< a ¬b ¬c = ⊥-elim (nat-≡< (cong suc eq) (lb=2 {lton1 x} {lton1 y} a))
... | tri≈ ¬a b ¬c = b
... | tri> ¬a ¬b c = ⊥-elim (nat-≡< (cong suc (sym eq)) (lb=2 {lton1 y} {lton1 x} c))
lb=1 {x} {y} {false} eq with <-cmp (lton x) (lton y)
... | tri< a ¬b ¬c = ⊥-elim (nat-≡< (cong suc eq) (lb=0 {lton1 x} {lton1 y} a))
... | tri≈ ¬a b ¬c = b
... | tri> ¬a ¬b c = ⊥-elim (nat-≡< (cong suc (sym eq)) (lb=0 {lton1 y} {lton1 x} c))
---
--- lton is unique in a head
---
lb-tf : {x y : List Bool } → ¬ (lton (true ∷ x) ≡ lton (false ∷ y))
lb-tf {x} {y} eq with <-cmp (lton1 x) (lton1 y)
... | tri< a ¬b ¬c = ⊥-elim ( nat-≡< eq (lb=01 a)) where
lb=01 : {x y : ℕ } → x < y → x + x < (y + y ∸ 1)
lb=01 {x} {y} x<y = begin
suc (x + x) ≡⟨ refl ⟩
suc x + x ≤⟨ ≤-plus x<y ⟩
y + x ≡⟨ refl ⟩
pred (suc y + x) ≡⟨ cong (λ k → pred ( k + x)) (+-comm 1 y) ⟩
pred ((y + 1) + x ) ≡⟨ cong pred (+-assoc y 1 x) ⟩
pred (y + suc x) ≤⟨ px≤py (≤-plus-0 {suc x} {y} {y} x<y) ⟩
(y + y) ∸ 1 ∎ where open ≤-Reasoning
... | tri> ¬a ¬b c = ⊥-elim ( nat-≡< (sym eq) (lb=02 c) ) where
lb=02 : {x y : ℕ } → x < y → x + x ∸ 1 < y + y
lb=02 {0} {y} lt = ≤-trans lt x≤x+y
lb=02 {suc x} {y} lt = begin
suc ( suc x + suc x ∸ 1 ) ≡⟨ refl ⟩
suc x + suc x ≤⟨ ≤-plus {suc x} (<to≤ lt) ⟩
y + suc x ≤⟨ ≤-plus-0 (<to≤ lt) ⟩
y + y ∎ where open ≤-Reasoning
... | tri≈ ¬a b ¬c = ⊥-elim ( nat-≡< (sym eq) ( begin
suc (lton1 y + lton1 y ∸ 1) ≡⟨ sucprd ( 2lton1>0 y) ⟩
lton1 y + lton1 y ≡⟨ cong (λ k → k + k ) (sym b) ⟩
lton1 x + lton1 x ∎ )) where open ≤-Reasoning
---
--- lton uniqueness
---
lb=b : (x y : List Bool) → lton x ≡ lton y → x ≡ y
lb=b [] [] eq = refl
lb=b [] (x ∷ y) eq = ⊥-elim ( nat-≡< eq (lton-cons>0 {x} {y} ))
lb=b (x ∷ y) [] eq = ⊥-elim ( nat-≡< (sym eq) (lton-cons>0 {x} {y} ))
lb=b (true ∷ x) (false ∷ y) eq = ⊥-elim ( lb-tf {x} {y} eq )
lb=b (false ∷ x) (true ∷ y) eq = ⊥-elim ( lb-tf {y} {x} (sym eq) )
lb=b (true ∷ x) (true ∷ y) eq = cong (λ k → true ∷ k ) (lb=b x y (lb=1 {x} {y} {true} eq))
lb=b (false ∷ x) (false ∷ y) eq = cong (λ k → false ∷ k ) (lb=b x y (lb=1 {x} {y} {false} eq))
lb : (n : ℕ) → LB n lton
lb zero = record { nlist = [] ; isBin = refl ; isUnique = lb05 } where
lb05 : (x : List Bool) → lton x ≡ zero → [] ≡ x
lb05 x eq = lb=b [] x (sym eq)
lb (suc n) with LB.nlist (lb n) | inspect LB.nlist (lb n)
... | [] | record { eq = eq } = record { nlist = false ∷ [] ; isUnique = lb06 ; isBin = lb10 } where
open ≡-Reasoning
lb10 : lton1 (false ∷ []) ∸ 1 ≡ suc n
lb10 = begin
lton (false ∷ []) ≡⟨ refl ⟩
suc 0 ≡⟨ refl ⟩
suc (lton []) ≡⟨ cong (λ k → suc (lton k)) (sym eq) ⟩
suc (lton (LB.nlist (lb n))) ≡⟨ cong suc (LB.isBin (lb n) ) ⟩
suc n ∎
lb06 : (x : List Bool) → pred (lton1 x ) ≡ suc n → false ∷ [] ≡ x
lb06 x eq1 = lb=b (false ∷ []) x (trans lb10 (sym eq1)) -- lton (false ∷ []) ≡ lton x
... | false ∷ t | record { eq = eq } = record { nlist = true ∷ t ; isBin = lb01 ; isUnique = lb09 } where
lb01 : lton (true ∷ t) ≡ suc n
lb01 = begin
lton (true ∷ t) ≡⟨ refl ⟩
lton1 t + lton1 t ≡⟨ sym ( sucprd (2lton1>0 t) ) ⟩
suc (pred (lton1 t + lton1 t )) ≡⟨ refl ⟩
suc (lton (false ∷ t)) ≡⟨ cong (λ k → suc (lton k )) (sym eq) ⟩
suc (lton (LB.nlist (lb n))) ≡⟨ cong suc (LB.isBin (lb n)) ⟩
suc n ∎ where open ≡-Reasoning
lb09 : (x : List Bool) → lton1 x ∸ 1 ≡ suc n → true ∷ t ≡ x
lb09 x eq1 = lb=b (true ∷ t) x (trans lb01 (sym eq1) ) -- lton (true ∷ t) ≡ lton x
... | true ∷ t | record { eq = eq } = record { nlist = lb+1 (true ∷ t) ; isBin = lb02 (true ∷ t) lb03 ; isUnique = lb07 } where
lb03 : lton (true ∷ t) ≡ n
lb03 = begin
lton (true ∷ t) ≡⟨ cong (λ k → lton k ) (sym eq ) ⟩
lton (LB.nlist (lb n)) ≡⟨ LB.isBin (lb n) ⟩
n ∎ where open ≡-Reasoning
add11 : (x1 : ℕ ) → suc x1 + suc x1 ≡ suc (suc (x1 + x1))
add11 zero = refl
add11 (suc x) = cong (λ k → suc (suc k)) (trans (+-comm x _) (cong suc (+-comm _ x)))
lb04 : (t : List Bool) → suc (lton1 t) ≡ lton1 (lb+1 t)
lb04 [] = refl
lb04 (false ∷ t) = refl
lb04 (true ∷ []) = refl
lb04 (true ∷ t0 ) = begin
suc (suc (lton1 t0 + lton1 t0)) ≡⟨ sym (add11 (lton1 t0)) ⟩
suc (lton1 t0) + suc (lton1 t0) ≡⟨ cong (λ k → k + k ) (lb04 t0 ) ⟩
lton1 (lb+1 t0) + lton1 (lb+1 t0) ∎ where
open ≡-Reasoning
lb02 : (t : List Bool) → lton t ≡ n → lton (lb+1 t) ≡ suc n
lb02 [] refl = refl
lb02 t eq1 = begin
lton (lb+1 t) ≡⟨ refl ⟩
pred (lton1 (lb+1 t)) ≡⟨ cong pred (sym (lb04 t)) ⟩
pred (suc (lton1 t)) ≡⟨ sym (sucprd (lton1>0 t)) ⟩
suc (pred (lton1 t)) ≡⟨ refl ⟩
suc (lton t) ≡⟨ cong suc eq1 ⟩
suc n ∎ where open ≡-Reasoning
lb07 : (x : List Bool) → pred (lton1 x ) ≡ suc n → lb+1 (true ∷ t) ≡ x
lb07 x eq1 = lb=b (lb+1 (true ∷ t)) x (trans ( lb02 (true ∷ t) lb03 ) (sym eq1))
|
{
"alphanum_fraction": 0.4224228682,
"avg_line_length": 48.1442495127,
"ext": "agda",
"hexsha": "0e640b3a95da81aef38c6c3894038523065ffc3a",
"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": "64d5f1ec0a6d81b7b9c45a289f669bbf32c9c891",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/HyperReal-in-agda",
"max_forks_repo_path": "src/bijection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "64d5f1ec0a6d81b7b9c45a289f669bbf32c9c891",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/HyperReal-in-agda",
"max_issues_repo_path": "src/bijection.agda",
"max_line_length": 159,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "64d5f1ec0a6d81b7b9c45a289f669bbf32c9c891",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/HyperReal-in-agda",
"max_stars_repo_path": "src/bijection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 10941,
"size": 24698
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.TLevel
module experimental.Category where
record CategoryStructure {i j} (Obj : Type i)
(Mor : Obj → Obj → Type j) : Type (lmax i j) where
constructor category-structure
field
comp : {o₁ o₂ o₃ : Obj} → Mor o₁ o₂ → Mor o₂ o₃ → Mor o₁ o₃
idm : {o : Obj} → Mor o o
unit-r : ∀ {o₁ o₂} (m : Mor o₁ o₂) → comp m idm == m
unit-l : ∀ {o₁ o₂} (m : Mor o₁ o₂) → comp idm m == m
record Category i j : Type (lsucc (lmax i j)) where
constructor category
field
Obj : Type i
Mor : Obj → Obj → Type j
Mor-level : ∀ {o₁ o₂} → is-set (Mor o₁ o₂)
cat-struct : CategoryStructure Obj Mor
open CategoryStructure cat-struct public
|
{
"alphanum_fraction": 0.6335078534,
"avg_line_length": 29.3846153846,
"ext": "agda",
"hexsha": "8267be47fbdb7f9e94987adaf839ae36e5a95946",
"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/Category.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/Category.agda",
"max_line_length": 63,
"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/Category.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": 262,
"size": 764
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.