hexsha
stringlengths 40
40
| size
int64 3
1.05M
| ext
stringclasses 163
values | lang
stringclasses 53
values | max_stars_repo_path
stringlengths 3
945
| max_stars_repo_name
stringlengths 4
112
| max_stars_repo_head_hexsha
stringlengths 40
78
| max_stars_repo_licenses
listlengths 1
10
| max_stars_count
float64 1
191k
⌀ | max_stars_repo_stars_event_min_datetime
stringlengths 24
24
⌀ | max_stars_repo_stars_event_max_datetime
stringlengths 24
24
⌀ | max_issues_repo_path
stringlengths 3
945
| max_issues_repo_name
stringlengths 4
113
| max_issues_repo_head_hexsha
stringlengths 40
78
| max_issues_repo_licenses
listlengths 1
10
| max_issues_count
float64 1
116k
⌀ | max_issues_repo_issues_event_min_datetime
stringlengths 24
24
⌀ | max_issues_repo_issues_event_max_datetime
stringlengths 24
24
⌀ | max_forks_repo_path
stringlengths 3
945
| max_forks_repo_name
stringlengths 4
113
| max_forks_repo_head_hexsha
stringlengths 40
78
| max_forks_repo_licenses
listlengths 1
10
| max_forks_count
float64 1
105k
⌀ | max_forks_repo_forks_event_min_datetime
stringlengths 24
24
⌀ | max_forks_repo_forks_event_max_datetime
stringlengths 24
24
⌀ | content
stringlengths 3
1.05M
| avg_line_length
float64 1
966k
| max_line_length
int64 1
977k
| alphanum_fraction
float64 0
1
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4eddabaf490104ef13b33c39b9d63b9ac12fe0a4
| 5,337
|
agda
|
Agda
|
Cubical/Data/Nat/Mod.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-02-05T01:25:26.000Z
|
2022-02-05T01:25:26.000Z
|
Cubical/Data/Nat/Mod.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Data/Nat/Mod.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Nat.Mod where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat
open import Cubical.Data.Nat.Order
-- Defining x mod 0 to be 0. This way all the theorems below are true
-- for n : ℕ instead of n : ℕ₊₁.
------ Preliminary definitions ------
modInd : (n : ℕ) → ℕ → ℕ
modInd n = +induction n (λ _ → ℕ) (λ x _ → x) λ _ x → x
modIndBase : (n m : ℕ) → m < suc n → modInd n m ≡ m
modIndBase n = +inductionBase n (λ _ → ℕ) (λ x _ → x) (λ _ x → x)
modIndStep : (n m : ℕ) → modInd n (suc n + m) ≡ modInd n m
modIndStep n = +inductionStep n (λ _ → ℕ) (λ x _ → x) (λ _ x → x)
-------------------------------------
_mod_ : (x n : ℕ) → ℕ
x mod zero = 0
x mod (suc n) = modInd n x
mod< : (n x : ℕ) → x mod (suc n) < (suc n)
mod< n =
+induction n
(λ x → x mod (suc n) < suc n)
(λ x base → fst base
, (cong (λ x → fst base + suc x)
(modIndBase n x base)
∙ snd base))
λ x ind → fst ind
, cong (λ x → fst ind + suc x)
(modIndStep n x) ∙ snd ind
mod-rUnit : (n x : ℕ) → x mod n ≡ ((x + n) mod n)
mod-rUnit zero x = refl
mod-rUnit (suc n) x =
sym (modIndStep n x)
∙ cong (modInd n) (+-comm (suc n) x)
mod-lUnit : (n x : ℕ) → x mod n ≡ ((n + x) mod n)
mod-lUnit zero _ = refl
mod-lUnit (suc n) x = sym (modIndStep n x)
mod+mod≡mod : (n x y : ℕ)
→ (x + y) mod n ≡ (((x mod n) + (y mod n)) mod n)
mod+mod≡mod zero _ _ = refl
mod+mod≡mod (suc n) =
+induction n
(λ z → (x : ℕ)
→ ((z + x) mod (suc n))
≡ (((z mod (suc n)) + (x mod (suc n))) mod (suc n)))
(λ x p →
+induction n _
(λ y q → cong (modInd n)
(sym (cong₂ _+_ (modIndBase n x p)
(modIndBase n y q))))
λ y ind → cong (modInd n)
(cong (x +_) (+-comm (suc n) y)
∙ (+-assoc x y (suc n)))
∙∙ sym (mod-rUnit (suc n) (x + y))
∙∙ ind
∙ cong (λ z → modInd n
((modInd n x + z)))
(mod-rUnit (suc n) y
∙ cong (modInd n) (+-comm y (suc n))))
λ x p y →
cong (modInd n) (cong suc (sym (+-assoc n x y)))
∙∙ sym (mod-lUnit (suc n) (x + y))
∙∙ p y
∙ sym (cong (modInd n)
(cong (_+ modInd n y)
(cong (modInd n)
(+-comm (suc n) x) ∙ sym (mod-rUnit (suc n) x))))
mod-idempotent : {n : ℕ} (x : ℕ) → (x mod n) mod n ≡ x mod n
mod-idempotent {n = zero} _ = refl
mod-idempotent {n = suc n} =
+induction n (λ x → (x mod suc n) mod (suc n) ≡ x mod (suc n))
(λ x p → cong (_mod (suc n))
(modIndBase n x p))
λ x p → cong (_mod (suc n))
(modIndStep n x)
∙∙ p
∙∙ mod-rUnit (suc n) x
∙ (cong (_mod (suc n)) (+-comm x (suc n)))
mod-rCancel : (n x y : ℕ) → (x + y) mod n ≡ (x + y mod n) mod n
mod-rCancel zero x y = refl
mod-rCancel (suc n) x =
+induction n _
(λ y p → cong (λ z → (x + z) mod (suc n))
(sym (modIndBase n y p)))
λ y p → cong (_mod suc n) (+-assoc x (suc n) y
∙∙ (cong (_+ y) (+-comm x (suc n)))
∙∙ sym (+-assoc (suc n) x y))
∙∙ sym (mod-lUnit (suc n) (x + y))
∙∙ (p ∙ cong (λ z → (x + z) mod suc n) (mod-lUnit (suc n) y))
mod-lCancel : (n x y : ℕ) → (x + y) mod n ≡ (x mod n + y) mod n
mod-lCancel n x y =
cong (_mod n) (+-comm x y)
∙∙ mod-rCancel n y x
∙∙ cong (_mod n) (+-comm y (x mod n))
zero-charac : (n : ℕ) → n mod n ≡ 0
zero-charac zero = refl
zero-charac (suc n) = cong (_mod suc n) (+-comm 0 (suc n))
∙∙ modIndStep n 0
∙∙ modIndBase n 0 (n , (+-comm n 1))
-- remainder and quotient after division by n
-- Again, allowing for 0-division to get nicer syntax
remainder_/_ : (x n : ℕ) → ℕ
remainder x / zero = x
remainder x / suc n = x mod (suc n)
quotient_/_ : (x n : ℕ) → ℕ
quotient x / zero = 0
quotient x / suc n =
+induction n (λ _ → ℕ) (λ _ _ → 0) (λ _ → suc) x
≡remainder+quotient : (n x : ℕ)
→ (remainder x / n) + n · (quotient x / n) ≡ x
≡remainder+quotient zero x = +-comm x 0
≡remainder+quotient (suc n) =
+induction n
(λ x → (remainder x / (suc n)) + (suc n)
· (quotient x / (suc n)) ≡ x)
(λ x base → cong₂ _+_ (modIndBase n x base)
(cong ((suc n) ·_)
(+inductionBase n _ _ _ x base))
∙∙ cong (x +_) (·-comm n 0)
∙∙ +-comm x 0)
λ x ind → cong₂ _+_ (modIndStep n x)
(cong ((suc n) ·_) (+inductionStep n _ _ _ x))
∙∙ cong (modInd n x +_)
(·-suc (suc n) (+induction n _ _ _ x))
∙∙ cong (modInd n x +_)
(+-comm (suc n) ((suc n) · (+induction n _ _ _ x)))
∙∙ +-assoc (modInd n x) ((suc n) · +induction n _ _ _ x) (suc n)
∙∙ cong (_+ suc n) ind
∙ +-comm x (suc n)
private
test₀ : 100 mod 81 ≡ 19
test₀ = refl
test₁ : ((11 + (10 mod 3)) mod 3) ≡ 0
test₁ = refl
| 34.655844
| 74
| 0.445569
|
343f4442654fe18a6fced8c3ee6d39e91c812aba
| 4,879
|
agda
|
Agda
|
F2a.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
F2a.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
F2a.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
-- {-# OPTIONS --without-K #-}
module F2a where
open import Agda.Prim
open import Data.Unit
open import Data.Nat hiding (_⊔_)
open import Data.Sum
open import Data.Product
open import Function
open import Relation.Binary.PropositionalEquality
open import Paths
open import Evaluator
------------------------------------------------------------------------------
--
-- General structure and idea
--
-- We have pointed types (Paths.agda)
-- We have paths between pointed types (Paths.agda)
-- We have functions between pointed types (that use ≡ to make sure the
-- basepoint is respected) (F2a.agda)
-- Then we use univalence to connect these two independently developed
-- notions (F2a.agda)
-- Because our paths are richer than just refl and our functions are
-- more restricted than arbitrary functions, and in fact because our
-- path constructors are sound and complete for the class of functions
-- we consider, we hope to _prove_ univalence
--
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Equivalences between raw functions and types
-- This is generalized below to pointed types
-- Two functions are ∼ is they map each argument to related results
_∼_ : ∀ {ℓ ℓ'} → {A : Set ℓ} {P : A → Set ℓ'} →
(f g : (x : A) → P x) → Set (ℓ ⊔ ℓ')
_∼_ {ℓ} {ℓ'} {A} {P} f g = (x : A) → f x ≡ g x
-- quasi-inverses
record qinv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) :
Set (ℓ ⊔ ℓ') where
constructor mkqinv
field
g : B → A
α : (f ∘ g) ∼ id
β : (g ∘ f) ∼ id
idqinv : ∀ {ℓ} → {A : Set ℓ} → qinv {ℓ} {ℓ} {A} {A} id
idqinv = record {
g = id ;
α = λ b → refl ;
β = λ a → refl
}
-- equivalences
record isequiv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) :
Set (ℓ ⊔ ℓ') where
constructor mkisequiv
field
g : B → A
α : (f ∘ g) ∼ id
h : B → A
β : (h ∘ f) ∼ id
equiv₁ : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {f : A → B} → qinv f → isequiv f
equiv₁ (mkqinv qg qα qβ) = mkisequiv qg qα qg qβ
_≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ ⊔ ℓ')
A ≃ B = Σ (A → B) isequiv
idequiv : ∀ {ℓ} {A : Set ℓ} → A ≃ A
idequiv = (id , equiv₁ idqinv)
-- Function extensionality
{--
happly : ∀ {ℓ} {A B : Set ℓ} {f g : A → B} → (Path f g) → (f ∼ g)
happly {ℓ} {A} {B} {f} {g} p =
(pathInd
(λ _ → f ∼ g) -- f ∼ g
(λ {AA} a x → {!!}) {!!}
{!!} {!!} {!!} {!!} {!!} {!!}
{!!} {!!} (λ a b x → {!cong (evalB p) (eval-resp-• (p))!})
{!!} {!!} {!!} {!!} {!!} {!!}
(λ a x → {!!}) (λ p₁ q x x₁ x₂ → x x₂)
(λ p₁ q x x₁ x₂ → x x₂) (λ p₁ q x x₁ x₂ → x x₂) (λ p₁ q x x₁ x₂ → x₁ x₂))
{A → B} {A → B} {f} {g} p
postulate
funextP : {A B : Set} {f g : A → B} →
isequiv {A = Path f g} {B = f ∼ g} happly
funext : {A B : Set} {f g : A → B} → (f ∼ g) → (Path f g)
funext = isequiv.g funextP
-- Universes; univalence
idtoeqv : {A B : Set} → (Path A B) → (A ≃ B)
idtoeqv {A} {B} p = {!!}
{--
(pathInd
(λ {S₁} {S₂} {A} {B} p → {!!})
{!!} {!!}
{!!} {!!} {!!} {!!} {!!} {!!}
{!!} {!!} {!!}
{!!} {!!} {!!} {!!} {!!} {!!}
{!!} {!!} {!!} {!!} {!!})
{Set} {Set} {A} {B} p
--}
postulate
univalence : {ℓ : Level} {A B : Set ℓ} → (Path A B) ≃ (A ≃ B)
--}
path2fun : {ℓ : Level} {A B : Set ℓ} → (Path A B) → (A ≃ B)
path2fun p = ( {!!} , {!!})
------------------------------------------------------------------------------
-- Functions and equivalences between pointed types
-- Univalence as a postulate for now but hopefully we can actually prove it
-- since the pi-combinators are sound and complete for isomorphisms between
-- finite types
--postulate
-- univalence• : {ℓ : Level} {A• B• : Set• {ℓ}} → (Path A• B•) ≃• (A• ≃• B•)
{--
record isequiv• {ℓ} {A B : Set} {A• B• : Set• {ℓ}} (f• : A• →• B•) :
Set (lsuc ℓ) where
constructor mkisequiv•
field
equi : isequiv (fun f•)
path' : Path (• A•) (• B•)
_≈•_ : ∀ {ℓ} {A B : Set} (A• B• : Set• {ℓ}) → Set (lsuc ℓ)
_≈•_ {_} {A} {B} A• B• = Σ (A• →• B•) (isequiv• {_} {A} {B})
--}
------------------------------------------------------------------------------
-- Univalence for pointed types
eval• : {ℓ : Level} {A• B• : Set• {ℓ}} → A• ⇛ B• → (A• →• B•)
eval• c = record { fun = eval c ; resp• = eval-resp-• c }
evalB• : {ℓ : Level} {A• B• : Set• {ℓ}} → A• ⇛ B• → (B• →• A•)
evalB• c = record { fun = evalB c ; resp• = evalB-resp-• c }
-- This is at the wrong level... We need to define equivalences ≃ between
-- pointed sets too...
{--
path2iso : {ℓ : Level} {A• B• : Set• {ℓ}} → A• ⇛ B• → ∣ A• ∣ ≃ ∣ B• ∣
path2iso {ℓ} {a} {b} p = (eval p ,
mkisequiv (evalB p) (λ x → {!!}) (evalB p) (λ x → {!eval∘evalB p!}))
--}
------------------------------------------------------------------------------
--}
| 28.869822
| 78
| 0.455216
|
7c35e924c8c2f498294e93c591287f4179d85a8c
| 2,611
|
agda
|
Agda
|
test/Succeed/EtaContractionDefBody.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/EtaContractionDefBody.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/EtaContractionDefBody.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- 2010-11-16
-- compactification of Data.Set.Decoration.gmapAll
--
-- This test case fails if we remove instantiateFull
-- (and with it eta-contraction) from definition bodies in Def.hs
-- see Issue 361
-- {-# OPTIONS -v tc.polarity:15 -v tc.pos:25 #-}
module EtaContractionDefBody where
------------------------------------------------------------------------
-- Binary relations
-- Homogeneous binary relations
Rel : Set → Set1
Rel A = A → A → Set
-- Generalised implication. If P ≡ Q it can be read as "f preserves
-- P".
_=[_]⇒_ : {A B : Set} →
Rel A → (A → B) → Rel B → Set
P =[ f ]⇒ Q = ∀ {x y} → P x y → Q (f x) (f y)
record Σ₂ {A B : Set}
(T : A → B → Set) : Set where
constructor pack₂
field
{x} : A
{y} : B
proof : T x y
-- Data.Star
infixr 5 _◅_
-- Reflexive transitive closure.
data Star {I : Set} (T : Rel I) : Rel I where
ε : ∀ {i} → Star T i i
_◅_ : ∀ {i j k} (x : T i j) (xs : Star T j k) → Star T i k
-- The type of _◅_ is Trans T (Star T) (Star T); I expanded
-- the definition in order to be able to name the arguments (x
-- and xs).
-- A generalised variant of map which allows the index type to change.
gmap : ∀ {I} {T : Rel I} {J} {U : Rel J} →
(f : I → J) → T =[ f ]⇒ U → Star T =[ f ]⇒ Star U
gmap f g ε = ε
gmap f g (x ◅ xs) = g x ◅ gmap f g xs
-- Data.Star.Decoration
EdgePred : ∀ {I} → Rel I → Set₁
EdgePred T = ∀ {i j} → T i j → Set
-- Decorating an edge with more information.
data DecoratedWith {I : Set} {T : Rel I} (P : EdgePred T)
: Rel (Σ₂ (Star T)) where
↦ : ∀ {i j k} {x : T i j} {xs : Star T j k}
(p : P x) → DecoratedWith P (pack₂ (x ◅ xs)) (pack₂ xs)
-- Star-lists decorated with extra information. All P xs means that
-- all edges in xs satisfy P.
All : ∀ {I} {T : Rel I} → EdgePred T → EdgePred (Star T)
All P {j = j} xs =
Star (DecoratedWith P) (pack₂ xs) (pack₂ {y = j} ε)
-- We can map over decorated vectors.
gmapAll : ∀ {I} {T : Rel I} {P : EdgePred T}
{J} {U : Rel J} {Q : EdgePred U}
{i j} {xs : Star T i j}
(f : I → J) (g : T =[ f ]⇒ U) →
(∀ {i j} {x : T i j} → P x → Q (g x)) →
All P xs → All {T = U} Q (gmap f g xs)
gmapAll f g h ε = ε
gmapAll f g h (↦ x ◅ xs) = ↦ (h x) ◅ gmapAll f g h xs
{- THIS WOULD BE THE ERROR MESSAGE:
/Users/abel/cover/alfa/Agda2/test/succeed/EtaContractionDefBody.agda:76,15-16
xs != ε of type Star (λ .i' .j → T .i' .j) j j
when checking that the pattern ε has type
Star (DecoratedWith (λ {.i} {.j} → P)) (pack₂ xs) (pack₂ ε)
-}
| 28.380435
| 77
| 0.532746
|
3dcf085852969381a79840cd62f631be7e677cbd
| 13,047
|
agda
|
Agda
|
vendor/stdlib/src/Relation/Binary/Sum.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Relation/Binary/Sum.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Relation/Binary/Sum.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- Sums of binary relations
------------------------------------------------------------------------
module Relation.Binary.Sum where
open import Data.Function
open import Data.Sum as Sum
open import Data.Product
open import Data.Unit using (⊤)
open import Data.Empty
open import Relation.Nullary
open import Relation.Binary
infixr 1 _⊎-Rel_ _⊎-<_
------------------------------------------------------------------------
-- Sums of relations
-- Generalised sum.
data ⊎ʳ (P : Set) {a₁ : Set} (_∼₁_ : Rel a₁)
{a₂ : Set} (_∼₂_ : Rel a₂)
: a₁ ⊎ a₂ → a₁ ⊎ a₂ → Set where
₁∼₂ : ∀ {x y} (p : P) → ⊎ʳ P _∼₁_ _∼₂_ (inj₁ x) (inj₂ y)
₁∼₁ : ∀ {x y} (x∼₁y : x ∼₁ y) → ⊎ʳ P _∼₁_ _∼₂_ (inj₁ x) (inj₁ y)
₂∼₂ : ∀ {x y} (x∼₂y : x ∼₂ y) → ⊎ʳ P _∼₁_ _∼₂_ (inj₂ x) (inj₂ y)
-- Pointwise sum.
_⊎-Rel_ : ∀ {a₁} (_∼₁_ : Rel a₁) →
∀ {a₂} (_∼₂_ : Rel a₂) →
Rel (a₁ ⊎ a₂)
_⊎-Rel_ = ⊎ʳ ⊥
-- All things to the left are smaller than (or equal to, depending on
-- the underlying equality) all things to the right.
_⊎-<_ : ∀ {a₁} (_∼₁_ : Rel a₁) →
∀ {a₂} (_∼₂_ : Rel a₂) →
Rel (a₁ ⊎ a₂)
_⊎-<_ = ⊎ʳ ⊤
------------------------------------------------------------------------
-- Helpers
private
₁≁₂ : ∀ {a₁} {∼₁ : Rel a₁} →
∀ {a₂} {∼₂ : Rel a₂} →
∀ {x y} → ¬ (inj₁ x ⟨ ∼₁ ⊎-Rel ∼₂ ⟩₁ inj₂ y)
₁≁₂ (₁∼₂ ())
drop-inj₁ : ∀ {a₁} {∼₁ : Rel a₁} →
∀ {a₂} {∼₂ : Rel a₂} →
∀ {P x y} → inj₁ x ⟨ ⊎ʳ P ∼₁ ∼₂ ⟩₁ inj₁ y → ∼₁ x y
drop-inj₁ (₁∼₁ x∼y) = x∼y
drop-inj₂ : ∀ {a₁} {∼₁ : Rel a₁} →
∀ {a₂} {∼₂ : Rel a₂} →
∀ {P x y} → inj₂ x ⟨ ⊎ʳ P ∼₁ ∼₂ ⟩₁ inj₂ y → ∼₂ x y
drop-inj₂ (₂∼₂ x∼y) = x∼y
------------------------------------------------------------------------
-- Some properties which are preserved by the relation formers above
_⊎-reflexive_ : ∀ {a₁} {≈₁ ∼₁ : Rel a₁} → ≈₁ ⇒ ∼₁ →
∀ {a₂} {≈₂ ∼₂ : Rel a₂} → ≈₂ ⇒ ∼₂ →
∀ {P} → (≈₁ ⊎-Rel ≈₂) ⇒ (⊎ʳ P ∼₁ ∼₂)
refl₁ ⊎-reflexive refl₂ = refl
where
refl : (_ ⊎-Rel _) ⇒ (⊎ʳ _ _ _)
refl (₁∼₁ x₁≈y₁) = ₁∼₁ (refl₁ x₁≈y₁)
refl (₂∼₂ x₂≈y₂) = ₂∼₂ (refl₂ x₂≈y₂)
refl (₁∼₂ ())
_⊎-refl_ : ∀ {a₁} {∼₁ : Rel a₁} → Reflexive ∼₁ →
∀ {a₂} {∼₂ : Rel a₂} → Reflexive ∼₂ →
Reflexive (∼₁ ⊎-Rel ∼₂)
refl₁ ⊎-refl refl₂ = refl
where
refl : Reflexive (_ ⊎-Rel _)
refl {x = inj₁ _} = ₁∼₁ refl₁
refl {x = inj₂ _} = ₂∼₂ refl₂
_⊎-irreflexive_ : ∀ {a₁} {≈₁ <₁ : Rel a₁} → Irreflexive ≈₁ <₁ →
∀ {a₂} {≈₂ <₂ : Rel a₂} → Irreflexive ≈₂ <₂ →
∀ {P} → Irreflexive (≈₁ ⊎-Rel ≈₂) (⊎ʳ P <₁ <₂)
irrefl₁ ⊎-irreflexive irrefl₂ = irrefl
where
irrefl : Irreflexive (_ ⊎-Rel _) (⊎ʳ _ _ _)
irrefl (₁∼₁ x₁≈y₁) (₁∼₁ x₁<y₁) = irrefl₁ x₁≈y₁ x₁<y₁
irrefl (₂∼₂ x₂≈y₂) (₂∼₂ x₂<y₂) = irrefl₂ x₂≈y₂ x₂<y₂
irrefl (₁∼₂ ()) _
_⊎-symmetric_ : ∀ {a₁} {∼₁ : Rel a₁} → Symmetric ∼₁ →
∀ {a₂} {∼₂ : Rel a₂} → Symmetric ∼₂ →
Symmetric (∼₁ ⊎-Rel ∼₂)
sym₁ ⊎-symmetric sym₂ = sym
where
sym : Symmetric (_ ⊎-Rel _)
sym (₁∼₁ x₁∼y₁) = ₁∼₁ (sym₁ x₁∼y₁)
sym (₂∼₂ x₂∼y₂) = ₂∼₂ (sym₂ x₂∼y₂)
sym (₁∼₂ ())
_⊎-transitive_ : ∀ {a₁} {∼₁ : Rel a₁} → Transitive ∼₁ →
∀ {a₂} {∼₂ : Rel a₂} → Transitive ∼₂ →
∀ {P} → Transitive (⊎ʳ P ∼₁ ∼₂)
trans₁ ⊎-transitive trans₂ = trans
where
trans : Transitive (⊎ʳ _ _ _)
trans (₁∼₁ x∼y) (₁∼₁ y∼z) = ₁∼₁ (trans₁ x∼y y∼z)
trans (₂∼₂ x∼y) (₂∼₂ y∼z) = ₂∼₂ (trans₂ x∼y y∼z)
trans (₁∼₂ p) (₂∼₂ _) = ₁∼₂ p
trans (₁∼₁ _) (₁∼₂ p) = ₁∼₂ p
_⊎-antisymmetric_ : ∀ {a₁} {≈₁ ≤₁ : Rel a₁} → Antisymmetric ≈₁ ≤₁ →
∀ {a₂} {≈₂ ≤₂ : Rel a₂} → Antisymmetric ≈₂ ≤₂ →
∀ {P} → Antisymmetric (≈₁ ⊎-Rel ≈₂) (⊎ʳ P ≤₁ ≤₂)
antisym₁ ⊎-antisymmetric antisym₂ = antisym
where
antisym : Antisymmetric (_ ⊎-Rel _) (⊎ʳ _ _ _)
antisym (₁∼₁ x≤y) (₁∼₁ y≤x) = ₁∼₁ (antisym₁ x≤y y≤x)
antisym (₂∼₂ x≤y) (₂∼₂ y≤x) = ₂∼₂ (antisym₂ x≤y y≤x)
antisym (₁∼₂ _) ()
_⊎-asymmetric_ : ∀ {a₁} {<₁ : Rel a₁} → Asymmetric <₁ →
∀ {a₂} {<₂ : Rel a₂} → Asymmetric <₂ →
∀ {P} → Asymmetric (⊎ʳ P <₁ <₂)
asym₁ ⊎-asymmetric asym₂ = asym
where
asym : Asymmetric (⊎ʳ _ _ _)
asym (₁∼₁ x<y) (₁∼₁ y<x) = asym₁ x<y y<x
asym (₂∼₂ x<y) (₂∼₂ y<x) = asym₂ x<y y<x
asym (₁∼₂ _) ()
_⊎-≈-respects₂_ : ∀ {a₁} {≈₁ ∼₁ : Rel a₁} → ∼₁ Respects₂ ≈₁ →
∀ {a₂} {≈₂ ∼₂ : Rel a₂} → ∼₂ Respects₂ ≈₂ →
∀ {P} → (⊎ʳ P ∼₁ ∼₂) Respects₂ (≈₁ ⊎-Rel ≈₂)
_⊎-≈-respects₂_ {≈₁ = ≈₁} {∼₁ = ∼₁} resp₁
{≈₂ = ≈₂} {∼₂ = ∼₂} resp₂ {P} =
(λ {_ _ _} → resp¹) ,
(λ {_ _ _} → resp²)
where
resp¹ : ∀ {x} → ((⊎ʳ P ∼₁ ∼₂) x) Respects (≈₁ ⊎-Rel ≈₂)
resp¹ (₁∼₁ y≈y') (₁∼₁ x∼y) = ₁∼₁ (proj₁ resp₁ y≈y' x∼y)
resp¹ (₂∼₂ y≈y') (₂∼₂ x∼y) = ₂∼₂ (proj₁ resp₂ y≈y' x∼y)
resp¹ (₂∼₂ y≈y') (₁∼₂ p) = (₁∼₂ p)
resp¹ (₁∼₂ ()) _
resp² : ∀ {y}
→ (flip₁ (⊎ʳ P ∼₁ ∼₂) y) Respects (≈₁ ⊎-Rel ≈₂)
resp² (₁∼₁ x≈x') (₁∼₁ x∼y) = ₁∼₁ (proj₂ resp₁ x≈x' x∼y)
resp² (₂∼₂ x≈x') (₂∼₂ x∼y) = ₂∼₂ (proj₂ resp₂ x≈x' x∼y)
resp² (₁∼₁ x≈x') (₁∼₂ p) = (₁∼₂ p)
resp² (₁∼₂ ()) _
_⊎-substitutive_ : ∀ {a₁} {∼₁ : Rel a₁} → Substitutive ∼₁ →
∀ {a₂} {∼₂ : Rel a₂} → Substitutive ∼₂ →
Substitutive (∼₁ ⊎-Rel ∼₂)
subst₁ ⊎-substitutive subst₂ = subst
where
subst : Substitutive (_ ⊎-Rel _)
subst P (₁∼₁ x∼y) Px = subst₁ (λ z → P (inj₁ z)) x∼y Px
subst P (₂∼₂ x∼y) Px = subst₂ (λ z → P (inj₂ z)) x∼y Px
subst P (₁∼₂ ()) Px
⊎-decidable : ∀ {a₁} {∼₁ : Rel a₁} → Decidable ∼₁ →
∀ {a₂} {∼₂ : Rel a₂} → Decidable ∼₂ →
∀ {P} → (∀ {x y} → Dec (inj₁ x ⟨ ⊎ʳ P ∼₁ ∼₂ ⟩₁ inj₂ y)) →
Decidable (⊎ʳ P ∼₁ ∼₂)
⊎-decidable {∼₁ = ∼₁} dec₁ {∼₂ = ∼₂} dec₂ {P} dec₁₂ = dec
where
dec : Decidable (⊎ʳ P ∼₁ ∼₂)
dec (inj₁ x) (inj₁ y) with dec₁ x y
... | yes x∼y = yes (₁∼₁ x∼y)
... | no x≁y = no (x≁y ∘ drop-inj₁)
dec (inj₂ x) (inj₂ y) with dec₂ x y
... | yes x∼y = yes (₂∼₂ x∼y)
... | no x≁y = no (x≁y ∘ drop-inj₂)
dec (inj₁ x) (inj₂ y) = dec₁₂
dec (inj₂ x) (inj₁ y) = no (λ())
_⊎-<-total_ : ∀ {a₁} {≤₁ : Rel a₁} → Total ≤₁ →
∀ {a₂} {≤₂ : Rel a₂} → Total ≤₂ →
Total (≤₁ ⊎-< ≤₂)
total₁ ⊎-<-total total₂ = total
where
total : Total (_ ⊎-< _)
total (inj₁ x) (inj₁ y) = Sum.map ₁∼₁ ₁∼₁ $ total₁ x y
total (inj₂ x) (inj₂ y) = Sum.map ₂∼₂ ₂∼₂ $ total₂ x y
total (inj₁ x) (inj₂ y) = inj₁ (₁∼₂ _)
total (inj₂ x) (inj₁ y) = inj₂ (₁∼₂ _)
_⊎-<-trichotomous_ : ∀ {a₁} {≈₁ <₁ : Rel a₁} → Trichotomous ≈₁ <₁ →
∀ {a₂} {≈₂ <₂ : Rel a₂} → Trichotomous ≈₂ <₂ →
Trichotomous (≈₁ ⊎-Rel ≈₂) (<₁ ⊎-< <₂)
_⊎-<-trichotomous_ {≈₁ = ≈₁} {<₁ = <₁} tri₁
{≈₂ = ≈₂} {<₂ = <₂} tri₂ = tri
where
tri : Trichotomous (≈₁ ⊎-Rel ≈₂) (<₁ ⊎-< <₂)
tri (inj₁ x) (inj₂ y) = tri< (₁∼₂ _) ₁≁₂ (λ())
tri (inj₂ x) (inj₁ y) = tri> (λ()) (λ()) (₁∼₂ _)
tri (inj₁ x) (inj₁ y) with tri₁ x y
... | tri< x<y x≉y x≯y =
tri< (₁∼₁ x<y) (x≉y ∘ drop-inj₁) (x≯y ∘ drop-inj₁)
... | tri≈ x≮y x≈y x≯y =
tri≈ (x≮y ∘ drop-inj₁) (₁∼₁ x≈y) (x≯y ∘ drop-inj₁)
... | tri> x≮y x≉y x>y =
tri> (x≮y ∘ drop-inj₁) (x≉y ∘ drop-inj₁) (₁∼₁ x>y)
tri (inj₂ x) (inj₂ y) with tri₂ x y
... | tri< x<y x≉y x≯y =
tri< (₂∼₂ x<y) (x≉y ∘ drop-inj₂) (x≯y ∘ drop-inj₂)
... | tri≈ x≮y x≈y x≯y =
tri≈ (x≮y ∘ drop-inj₂) (₂∼₂ x≈y) (x≯y ∘ drop-inj₂)
... | tri> x≮y x≉y x>y =
tri> (x≮y ∘ drop-inj₂) (x≉y ∘ drop-inj₂) (₂∼₂ x>y)
------------------------------------------------------------------------
-- Some collections of properties which are preserved
_⊎-isEquivalence_ : ∀ {a₁} {≈₁ : Rel a₁} → IsEquivalence ≈₁ →
∀ {a₂} {≈₂ : Rel a₂} → IsEquivalence ≈₂ →
IsEquivalence (≈₁ ⊎-Rel ≈₂)
eq₁ ⊎-isEquivalence eq₂ = record
{ refl = refl eq₁ ⊎-refl refl eq₂
; sym = sym eq₁ ⊎-symmetric sym eq₂
; trans = trans eq₁ ⊎-transitive trans eq₂
}
where open IsEquivalence
_⊎-isPreorder_ : ∀ {a₁} {≈₁ ∼₁ : Rel a₁} → IsPreorder ≈₁ ∼₁ →
∀ {a₂} {≈₂ ∼₂ : Rel a₂} → IsPreorder ≈₂ ∼₂ →
∀ {P} → IsPreorder (≈₁ ⊎-Rel ≈₂) (⊎ʳ P ∼₁ ∼₂)
pre₁ ⊎-isPreorder pre₂ = record
{ isEquivalence = isEquivalence pre₁ ⊎-isEquivalence
isEquivalence pre₂
; reflexive = reflexive pre₁ ⊎-reflexive reflexive pre₂
; trans = trans pre₁ ⊎-transitive trans pre₂
; ∼-resp-≈ = ∼-resp-≈ pre₁ ⊎-≈-respects₂ ∼-resp-≈ pre₂
}
where open IsPreorder
_⊎-isDecEquivalence_ : ∀ {a₁} {≈₁ : Rel a₁} → IsDecEquivalence ≈₁ →
∀ {a₂} {≈₂ : Rel a₂} → IsDecEquivalence ≈₂ →
IsDecEquivalence (≈₁ ⊎-Rel ≈₂)
eq₁ ⊎-isDecEquivalence eq₂ = record
{ isEquivalence = isEquivalence eq₁ ⊎-isEquivalence
isEquivalence eq₂
; _≟_ = ⊎-decidable (_≟_ eq₁) (_≟_ eq₂) (no ₁≁₂)
}
where open IsDecEquivalence
_⊎-isPartialOrder_ : ∀ {a₁} {≈₁ ≤₁ : Rel a₁} → IsPartialOrder ≈₁ ≤₁ →
∀ {a₂} {≈₂ ≤₂ : Rel a₂} → IsPartialOrder ≈₂ ≤₂ →
∀ {P} → IsPartialOrder (≈₁ ⊎-Rel ≈₂) (⊎ʳ P ≤₁ ≤₂)
po₁ ⊎-isPartialOrder po₂ = record
{ isPreorder = isPreorder po₁ ⊎-isPreorder isPreorder po₂
; antisym = antisym po₁ ⊎-antisymmetric antisym po₂
}
where open IsPartialOrder
_⊎-isStrictPartialOrder_ :
∀ {a₁} {≈₁ <₁ : Rel a₁} → IsStrictPartialOrder ≈₁ <₁ →
∀ {a₂} {≈₂ <₂ : Rel a₂} → IsStrictPartialOrder ≈₂ <₂ →
∀ {P} → IsStrictPartialOrder (≈₁ ⊎-Rel ≈₂) (⊎ʳ P <₁ <₂)
spo₁ ⊎-isStrictPartialOrder spo₂ = record
{ isEquivalence = isEquivalence spo₁ ⊎-isEquivalence
isEquivalence spo₂
; irrefl = irrefl spo₁ ⊎-irreflexive irrefl spo₂
; trans = trans spo₁ ⊎-transitive trans spo₂
; <-resp-≈ = <-resp-≈ spo₁ ⊎-≈-respects₂ <-resp-≈ spo₂
}
where open IsStrictPartialOrder
_⊎-<-isTotalOrder_ : ∀ {a₁} {≈₁ ≤₁ : Rel a₁} → IsTotalOrder ≈₁ ≤₁ →
∀ {a₂} {≈₂ ≤₂ : Rel a₂} → IsTotalOrder ≈₂ ≤₂ →
IsTotalOrder (≈₁ ⊎-Rel ≈₂) (≤₁ ⊎-< ≤₂)
to₁ ⊎-<-isTotalOrder to₂ = record
{ isPartialOrder = isPartialOrder to₁ ⊎-isPartialOrder
isPartialOrder to₂
; total = total to₁ ⊎-<-total total to₂
}
where open IsTotalOrder
_⊎-<-isDecTotalOrder_ :
∀ {a₁} {≈₁ ≤₁ : Rel a₁} → IsDecTotalOrder ≈₁ ≤₁ →
∀ {a₂} {≈₂ ≤₂ : Rel a₂} → IsDecTotalOrder ≈₂ ≤₂ →
IsDecTotalOrder (≈₁ ⊎-Rel ≈₂) (≤₁ ⊎-< ≤₂)
to₁ ⊎-<-isDecTotalOrder to₂ = record
{ isTotalOrder = isTotalOrder to₁ ⊎-<-isTotalOrder isTotalOrder to₂
; _≟_ = ⊎-decidable (_≟_ to₁) (_≟_ to₂) (no ₁≁₂)
; _≤?_ = ⊎-decidable (_≤?_ to₁) (_≤?_ to₂) (yes (₁∼₂ _))
}
where open IsDecTotalOrder
------------------------------------------------------------------------
-- The game can be taken even further...
_⊎-setoid_ : Setoid → Setoid → Setoid
s₁ ⊎-setoid s₂ = record
{ isEquivalence = isEquivalence s₁ ⊎-isEquivalence isEquivalence s₂
} where open Setoid
_⊎-preorder_ : Preorder → Preorder → Preorder
p₁ ⊎-preorder p₂ = record
{ _∼_ = _∼_ p₁ ⊎-Rel _∼_ p₂
; isPreorder = isPreorder p₁ ⊎-isPreorder isPreorder p₂
} where open Preorder
_⊎-decSetoid_ : DecSetoid → DecSetoid → DecSetoid
ds₁ ⊎-decSetoid ds₂ = record
{ isDecEquivalence = isDecEquivalence ds₁ ⊎-isDecEquivalence
isDecEquivalence ds₂
} where open DecSetoid
_⊎-poset_ : Poset → Poset → Poset
po₁ ⊎-poset po₂ = record
{ _≤_ = _≤_ po₁ ⊎-Rel _≤_ po₂
; isPartialOrder = isPartialOrder po₁ ⊎-isPartialOrder
isPartialOrder po₂
} where open Poset
_⊎-<-poset_ : Poset → Poset → Poset
po₁ ⊎-<-poset po₂ = record
{ _≤_ = _≤_ po₁ ⊎-< _≤_ po₂
; isPartialOrder = isPartialOrder po₁ ⊎-isPartialOrder
isPartialOrder po₂
} where open Poset
_⊎-<-strictPartialOrder_ :
StrictPartialOrder → StrictPartialOrder → StrictPartialOrder
spo₁ ⊎-<-strictPartialOrder spo₂ = record
{ _<_ = _<_ spo₁ ⊎-< _<_ spo₂
; isStrictPartialOrder = isStrictPartialOrder spo₁
⊎-isStrictPartialOrder
isStrictPartialOrder spo₂
} where open StrictPartialOrder
_⊎-<-totalOrder_ : TotalOrder → TotalOrder → TotalOrder
to₁ ⊎-<-totalOrder to₂ = record
{ isTotalOrder = isTotalOrder to₁ ⊎-<-isTotalOrder isTotalOrder to₂
} where open TotalOrder
_⊎-<-decTotalOrder_ : DecTotalOrder → DecTotalOrder → DecTotalOrder
to₁ ⊎-<-decTotalOrder to₂ = record
{ isDecTotalOrder = isDecTotalOrder to₁ ⊎-<-isDecTotalOrder
isDecTotalOrder to₂
} where open DecTotalOrder
| 37.277143
| 72
| 0.490994
|
06fc64b6bc0264c0cc1bce4a7a61b10ed348ce0e
| 399
|
agda
|
Agda
|
test/Succeed/Issue2824.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2824.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2824.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2017-11-01, issue #2824
-- allow built-in pragmas before top-level module header
{-# OPTIONS --rewriting --confluence-check #-}
open import Agda.Builtin.Equality
{-# BUILTIN REWRITE _≡_ #-}
module Issue2824 (A : Set) where -- This is the top-level module header.
postulate
P : A → Set
a b : A
a→b : a ≡ b
{-# REWRITE a→b #-}
test : P a → P b
test x = x
-- Should succeed.
| 17.347826
| 73
| 0.639098
|
0396163950f9e3e2d6008de7b5f961ed1e3c7b7d
| 880
|
agda
|
Agda
|
core/lib/groups/Groups.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
core/lib/groups/Groups.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
core/lib/groups/Groups.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
module lib.groups.Groups where
open import lib.groups.CommutingSquare public
open import lib.groups.FreeAbelianGroup public
open import lib.groups.FreeGroup public
open import lib.groups.GeneratedAbelianGroup public
open import lib.groups.GeneratedGroup public
open import lib.groups.GroupProduct public
open import lib.groups.Homomorphism public
open import lib.groups.HomotopyGroup public
open import lib.groups.Int public
open import lib.groups.Isomorphism public
open import lib.groups.Lift public
open import lib.groups.LoopSpace public
open import lib.groups.QuotientGroup public
open import lib.groups.PullbackGroup public
open import lib.groups.Subgroup public
open import lib.groups.SubgroupProp public
open import lib.groups.TensorProduct public
open import lib.groups.TruncationGroup public
open import lib.groups.Unit public
| 35.2
| 51
| 0.843182
|
7c9feeb64fc9e7ec1dfb9b8ed0f4e11ace353260
| 9,536
|
agda
|
Agda
|
src/Dijkstra/RWS.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/Dijkstra/RWS.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/Dijkstra/RWS.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
-- This module provides functionality for proving properties about
-- programs written using this RWS monad. The main definitions are:
-- - RWS-weakestPre, a large elimination that, given an RWS program and a
-- post condition for the program, produces the weakest precondition needed
-- to satisfy that post condition. Branches in code using the constructors
-- `RWS-if` and friends are translated into products, with each component of
-- the product corresponding to a possible branch taken.
-- - RWS-Contract is the type of proofs that, given a stateful computation and
-- a post condition, the weakest precondition suffices to prove that post
-- condition.
-- - RWS-contract proves RWS-Contract, i.e., for every stateful computation
-- `m` and post condition `P`, given a proof over a pre-state `pre` the
-- weakest precondition for `P` holds, then postcondition `P` holds for the
-- post-state obtained from running `m` in state `pre`.
module Dijkstra.RWS where
open import Agda.Builtin.Equality using (_≡_; refl)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Haskell.Modules.RWS
open import Haskell.Prelude
private
variable
Ev Wr St : Set
A B C : Set
-- Preconditions are predicates over environments and prestates.
RWS-Pre : (Ev St : Set) → Set₁
RWS-Pre Ev St = (ev : Ev) (pre : St) → Set
-- Postconditions are predicates over a result, poststate, and list of outputs.
RWS-Post : (Wr St A : Set) → Set₁
RWS-Post Wr St A = (x : A) (post : St) (outs : List Wr) → Set
RWS-Post-⇒ : (P Q : RWS-Post Wr St A) → Set
RWS-Post-⇒ P Q = ∀ r st outs → P r st outs → Q r st outs
-- RWS-weakestPre computes a predicate transformer: it maps a RWS
-- computation `m` and desired postcondition `Post` to the weakest precondition
-- needed to prove `P` holds after running `m`.
RWS-PredTrans : (Ev Wr St A : Set) → Set₁
RWS-PredTrans Ev Wr St A = RWS-Post Wr St A → RWS-Pre Ev St
-- When RWS computations are sequenced, e.g., `RWS-bind m λ x → f x`,
-- outputs are concatenated. The postcondition desired for the above sequence
-- becomes a postcondition for `f x` in which the outputs of `m` are prepended
-- to the outputs of `f x`.
RWS-Post++ : ∀ {Wr St A} → RWS-Post Wr St A → List Wr → RWS-Post Wr St A
RWS-Post++ P outs x post outs₁ = P x post (outs ++ outs₁)
-- Consider again the sequence `RWS-bind m₁ λ x → f x`. We also translate a
-- postcondition `P` for the sequence into a postcondition for `m` ---
-- specifically, the post condition we want for `m` is that the weakest
-- precondition for `RWS-Post++ P outs` holds, where `outs` are the outputs of
-- `m`.
RWS-weakestPre-bindPost : (ev : Ev) (f : A → RWS Ev Wr St B) → RWS-Post Wr St B → RWS-Post Wr St A
RWS-weakestPre-ebindPost : (ev : Ev) (f : A → RWS Ev Wr St (Either C B)) → RWS-Post Wr St (Either C B) → RWS-Post Wr St (Either C A)
RWS-weakestPre : (m : RWS Ev Wr St A) → RWS-PredTrans Ev Wr St A
RWS-weakestPre (RWS-return x) P ev pre = P x pre []
RWS-weakestPre (RWS-bind m f) P ev pre =
RWS-weakestPre m (RWS-weakestPre-bindPost ev f P) ev pre
RWS-weakestPre (RWS-gets f) P ev pre = P (f pre) pre []
RWS-weakestPre (RWS-put post) P ev pre = P unit post []
RWS-weakestPre RWS-ask P ev pre = P ev pre []
RWS-weakestPre (RWS-tell outs) P ev pre = P unit pre outs
RWS-weakestPre (RWS-if (clause (b ≔ c) gs)) P ev pre =
(toBool b ≡ true → RWS-weakestPre c P ev pre)
× (toBool b ≡ false → RWS-weakestPre (RWS-if gs) P ev pre)
RWS-weakestPre (RWS-if (otherwise≔ c)) P ev pre =
RWS-weakestPre c P ev pre
RWS-weakestPre (RWS-either f₁ f₂ e) P ev pre =
(∀ x → (e ≡ Left x) →
RWS-weakestPre (f₁ x) P ev pre)
× (∀ y → (e ≡ Right y) →
RWS-weakestPre (f₂ y) P ev pre)
RWS-weakestPre (RWS-ebind m f) P ev pre =
RWS-weakestPre m (RWS-weakestPre-ebindPost ev f P) ev pre
RWS-weakestPre (RWS-maybe f₁ f₂ m) P ev pre =
(m ≡ nothing → RWS-weakestPre f₁ P ev pre)
× (∀ j → m ≡ just j → RWS-weakestPre (f₂ j) P ev pre)
RWS-weakestPre-ebindPost ev f Post (Left r) post outs =
Post (Left r) post outs
RWS-weakestPre-ebindPost ev f Post (Right r) post outs =
∀ c → c ≡ r → RWS-weakestPre (f c) (RWS-Post++ Post outs) ev post
RWS-weakestPre-bindPost ev f Post x post outs =
∀ r → r ≡ x → RWS-weakestPre (f r) (RWS-Post++ Post outs) ev post
-- The post condition `P` holds for `m` with environment `ev` and prestate `pre`
RWS-Post-True : (P : RWS-Post Wr St A) (m : RWS Ev Wr St A) (ev : Ev) (pre : St) → Set
RWS-Post-True P m ev pre =
let (x , post , outs) = RWS-run m ev pre in
P x post outs
-- For every RWS computation `m`, `RWS-Contract m` is the type of proofs that,
-- for all post conditions `P`, starting environments `ev` and prestates `pre`,
-- to prove that `P` holds after running `m` in `ev` and `pre`, it suffices to
-- provide a proof of the weakest precondition for `P` with respect to `m`,
-- `ev`, and `pre`.
RWS-Contract : (m : RWS Ev Wr St A) → Set₁
RWS-Contract{Ev}{Wr}{St}{A} m =
(P : RWS-Post Wr St A)
→ (ev : Ev) (pre : St) → RWS-weakestPre m P ev pre
→ RWS-Post-True P m ev pre
-- This proves that `RWS-weakestPre` gives a *sufficient* precondition for
-- establishing a desired postcondition. Note thought that it does not prove
-- that this precondition is the weakest such one; even though this is true, it
-- is not important for our purposes.
RWS-contract : (m : RWS Ev Wr St A) → RWS-Contract m
RWS-contract (RWS-return x₁) P ev pre wp = wp
RWS-contract (RWS-bind m f) P ev pre wp
with RWS-contract m _ ev pre wp
...| con
with RWS-run m ev pre
...| x₁ , st₁ , outs₁ =
RWS-contract (f x₁) _ ev st₁ (con x₁ refl)
RWS-contract (RWS-gets f) P ev pre wp = wp
RWS-contract (RWS-put x₁) P ev pre wp = wp
RWS-contract RWS-ask P ev pre wp = wp
RWS-contract (RWS-tell x₁) P ev pre wp = wp
RWS-contract{Ev}{Wr}{St}{A} (RWS-if gs) P ev pre wp = RWS-contract-if gs P ev pre wp
where
RWS-contract-if : (gs : Guards (RWS Ev Wr St A)) → RWS-Contract (RWS-if gs)
RWS-contract-if (clause (b ≔ c) gs) P ev pre (wp₁ , wp₂)
with toBool b
...| true = RWS-contract c _ ev pre (wp₁ refl)
...| false = RWS-contract-if gs _ ev pre (wp₂ refl)
RWS-contract-if (otherwise≔ x) P ev pre wp =
RWS-contract x P ev pre wp
RWS-contract (RWS-either f₁ f₂ (Left x)) P ev pre (wp₁ , wp₂) =
RWS-contract (f₁ x) _ ev pre (wp₁ x refl)
RWS-contract (RWS-either f₁ f₂ (Right y)) P ev pre (wp₁ , wp₂) =
RWS-contract (f₂ y) _ ev pre (wp₂ y refl)
RWS-contract (RWS-ebind m f) P ev pre wp
with RWS-contract m _ ev pre wp
...| con
with RWS-run m ev pre
... | Left x , st₁ , outs₁ = con
... | Right y , st₁ , outs₁ = RWS-contract (f y) _ ev st₁ (con y refl)
RWS-contract (RWS-maybe f₁ f₂ nothing) P ev pre (wp₁ , wp₂)
= RWS-contract f₁ _ ev pre (wp₁ refl)
RWS-contract (RWS-maybe f₁ f₂ (just x)) P ev pre (wp₁ , wp₂) =
RWS-contract (f₂ x) _ ev pre (wp₂ x refl)
-- This helper function is primarily used to take a proof concerning one
-- computation `m` and show that that proof implies a property concerning a
-- larger computation which contains `m`.
RWS-⇒
: ∀ {P Q : RWS-Post Wr St A}
→ ∀ m (ev : Ev) st
→ RWS-weakestPre m P ev st
→ RWS-Post-⇒ P Q
→ RWS-weakestPre m Q ev st
RWS-⇒ (RWS-return x) ev st pre pf = pf x st [] pre
RWS-⇒ (RWS-bind m f) ev st pre pf =
RWS-⇒
m ev st pre
(λ r₁ st₁ outs₁ pf₁ x x≡ →
RWS-⇒
(f x) ev st₁ (pf₁ x x≡)
(λ r₂ st₂ outs₂ pf₂ → pf r₂ st₂ (outs₁ ++ outs₂) pf₂))
RWS-⇒ (RWS-gets f) ev st pre pf = pf _ _ _ pre
RWS-⇒ (RWS-put x) ev st pre pf = pf _ _ _ pre
RWS-⇒ RWS-ask ev st pre pf = pf _ _ _ pre
RWS-⇒ (RWS-tell x) ev st pre pf = pf _ _ _ pre
RWS-⇒ (RWS-if (otherwise≔ x)) ev st pre pf = RWS-⇒ x ev st pre pf
RWS-⇒ (RWS-if (clause (b ≔ c) cs)) ev st (pre₁ , pre₂) pf =
(λ pf' → RWS-⇒ c ev st (pre₁ pf') pf)
, λ pf' → RWS-⇒ (RWS-if cs) ev st (pre₂ pf') pf
proj₁ (RWS-⇒ (RWS-either f₁ f₂ (Left x)) ev st (pre₁ , pre₂) pf) x₁ x₁≡ =
RWS-⇒ (f₁ x₁) ev st (pre₁ x₁ x₁≡) pf
proj₂ (RWS-⇒ (RWS-either f₁ f₂ (Left x) ) ev st (pre₁ , pre₂) pf) y ()
proj₁ (RWS-⇒ (RWS-either f₁ f₂ (Right y)) ev st (pre₁ , pre₂) pf) y₁ ()
proj₂ (RWS-⇒ (RWS-either f₁ f₂ (Right y)) ev st (pre₁ , pre₂) pf) y₁ y₁≡ =
RWS-⇒ (f₂ y₁) ev st (pre₂ y₁ y₁≡) pf
RWS-⇒ (RWS-ebind m f) ev st pre pf =
RWS-⇒ m ev st pre
(λ { (Left x₁) st₁ outs x → pf _ _ _ x
; (Right y) st₁ outs x → λ c x₁ →
RWS-⇒ (f c) ev st₁ (x c x₁) (λ r st₂ outs₁ x₂ → pf r st₂ (outs ++ outs₁) x₂) })
proj₁ (RWS-⇒ (RWS-maybe m f x) ev st (pre₁ , pre₂) pf) ≡nothing = RWS-⇒ m ev st (pre₁ ≡nothing) pf
proj₂ (RWS-⇒ (RWS-maybe m f x) ev st (pre₁ , pre₂) pf) b b≡ = RWS-⇒ (f b) ev st (pre₂ b b≡) pf
RWS-⇒-bind
: ∀ {P : RWS-Post Wr St A}
{Q : RWS-Post Wr St B}
→ {f : A → RWS Ev Wr St B}
→ ∀ m ev st
→ RWS-weakestPre m P ev st
→ RWS-Post-⇒ P (RWS-weakestPre-bindPost ev f Q)
→ RWS-weakestPre (RWS-bind m f) Q ev st
RWS-⇒-bind m ev st con pf =
RWS-⇒ m ev st con pf
RWS-⇒-ebind
: ∀ {P : RWS-Post Wr St (Either C A)}
{Q : RWS-Post Wr St (Either C B)}
→ {f : A → RWS Ev Wr St (Either C B)}
→ ∀ m ev st
→ RWS-weakestPre m P ev st
→ RWS-Post-⇒ P (RWS-weakestPre-ebindPost ev f Q)
→ RWS-weakestPre (RWS-ebind m f) Q ev st
RWS-⇒-ebind m ev st con pf =
RWS-⇒ m ev st con pf
| 44.353488
| 132
| 0.643456
|
43c8ba5e0e0c62781c37f10ff73a251f918e410e
| 177
|
agda
|
Agda
|
test/Succeed/Issue2372ImportInst.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2372ImportInst.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2372ImportInst.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2017-01-01, issue 2372, reported by m0davis
open import Issue2372Inst
f : r → Set₁
f _ = Set
-- WAS: No instance of type R was found in scope.
-- Should succeed
| 16.090909
| 55
| 0.694915
|
0d992d54181d582e56a306e4f2beb7bc658b5489
| 14,347
|
agda
|
Agda
|
archive/agda-1/UnifyTermF.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-1/UnifyTermF.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-1/UnifyTermF.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
module UnifyTermF (FunctionName : Set) where
open import Data.Fin using (Fin; suc; zero)
open import Data.Nat using (ℕ; suc; zero)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong₂; cong; sym; trans)
open import Function using (_∘_; flip)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Data.Product using (∃; _,_; _×_)
open import Data.Empty using (⊥-elim)
open import Data.Vec using (Vec; []; _∷_) renaming (map to mapV)
data Term (n : ℕ) : Set where
i : (x : Fin n) -> Term n
leaf : Term n
_fork_ : (s t : Term n) -> Term n
function : FunctionName → ∀ {f} → Vec (Term n) f → Term n
Term-function-inj-FunctionName : ∀ {fn₁ fn₂} {n N₁ N₂} {ts₁ : Vec (Term n) N₁} {ts₂ : Vec (Term n) N₂} → Term.function fn₁ ts₁ ≡ Term.function fn₂ ts₂ → fn₁ ≡ fn₂
Term-function-inj-FunctionName refl = refl
Term-function-inj-VecSize : ∀ {fn₁ fn₂} {n N₁ N₂} {ts₁ : Vec (Term n) N₁} {ts₂ : Vec (Term n) N₂} → Term.function fn₁ ts₁ ≡ Term.function fn₂ ts₂ → N₁ ≡ N₂
Term-function-inj-VecSize refl = refl
Term-function-inj-Vector : ∀ {fn₁ fn₂} {n N} {ts₁ : Vec (Term n) N} {ts₂ : Vec (Term n) N} → Term.function fn₁ ts₁ ≡ Term.function fn₂ ts₂ → ts₁ ≡ ts₂
Term-function-inj-Vector refl = refl
Term-fork-inj-left : ∀ {n} {l₁ r₁ l₂ r₂ : Term n} → l₁ fork r₁ ≡ l₂ fork r₂ → l₁ ≡ l₂
Term-fork-inj-left refl = refl
Term-fork-inj-right : ∀ {n} {l₁ r₁ l₂ r₂ : Term n} → l₁ fork r₁ ≡ l₂ fork r₂ → r₁ ≡ r₂
Term-fork-inj-right refl = refl
open import Relation.Binary.HeterogeneousEquality using (_≅_; refl)
Term-function-inj-HetVector : ∀ {fn₁ fn₂} {n N₁ N₂} {ts₁ : Vec (Term n) N₁} {ts₂ : Vec (Term n) N₂} → Term.function fn₁ ts₁ ≡ Term.function fn₂ ts₂ → ts₁ ≅ ts₂
Term-function-inj-HetVector refl = refl
_~>_ : (m n : ℕ) -> Set
m ~> n = Fin m -> Term n
▹ : ∀ {m n} -> (r : Fin m -> Fin n) -> Fin m -> Term n
▹ r = i ∘ r
Property⋆ : (m : ℕ) -> Set1
Property⋆ m = ∀ {n} -> (Fin m -> Term n) -> Set
record Substitution (T : ℕ → Set) : Set where
field
_◃_ : ∀ {m n} -> (f : m ~> n) -> T m -> T n
Unifies⋆ : ∀ {m} (s t : T m) -> Property⋆ m
Unifies⋆ s t f = f ◃ s ≡ f ◃ t
open Substitution ⦃ … ⦄ public
{-# DISPLAY Substitution._◃_ _ = _◃_ #-}
mutual
instance SubstitutionTerm : Substitution Term
Substitution._◃_ SubstitutionTerm = _◃′_ where
_◃′_ : ∀ {m n} -> (f : m ~> n) -> Term m -> Term n
f ◃′ i x = f x
f ◃′ leaf = leaf
f ◃′ (s fork t) = (f ◃ s) fork (f ◃ t)
f ◃′ (function fn ts) = function fn (f ◃ ts)
instance SubstitutionVecTerm : ∀ {N} → Substitution (flip Vec N ∘ Term )
Substitution._◃_ (SubstitutionVecTerm {N}) = _◃′_ where
_◃′_ : ∀ {m n} -> (f : m ~> n) -> Vec (Term m) N -> Vec (Term n) N
f ◃′ [] = []
f ◃′ (t ∷ ts) = f ◃ t ∷ f ◃ ts
_≐_ : {m n : ℕ} -> (Fin m -> Term n) -> (Fin m -> Term n) -> Set
f ≐ g = ∀ x -> f x ≡ g x
record SubstitutionExtensionality (T : ℕ → Set) ⦃ _ : Substitution T ⦄ : Set₁ where
field
◃ext : ∀ {m n} {f g : Fin m -> Term n} -> f ≐ g -> (t : T m) -> f ◃ t ≡ g ◃ t
open SubstitutionExtensionality ⦃ … ⦄ public
mutual
instance SubstitutionExtensionalityTerm : SubstitutionExtensionality Term
SubstitutionExtensionality.◃ext SubstitutionExtensionalityTerm = ◃ext′ where
◃ext′ : ∀ {m n} {f g : Fin m -> Term n} -> f ≐ g -> ∀ t -> f ◃ t ≡ g ◃ t
◃ext′ p (i x) = p x
◃ext′ p leaf = refl
◃ext′ p (s fork t) = cong₂ _fork_ (◃ext p s) (◃ext p t)
◃ext′ p (function fn ts) = cong (function fn) (◃ext p ts)
instance SubstitutionExtensionalityVecTerm : ∀ {N} → SubstitutionExtensionality (flip Vec N ∘ Term)
SubstitutionExtensionality.◃ext (SubstitutionExtensionalityVecTerm {N}) = λ x → ◃ext′ x where
◃ext′ : ∀ {m n} {f g : Fin m -> Term n} -> f ≐ g -> ∀ {N} (t : Vec (Term m) N) -> f ◃ t ≡ g ◃ t
◃ext′ p [] = refl
◃ext′ p (t ∷ ts) = cong₂ _∷_ (◃ext p t) (◃ext p ts)
_◇_ : ∀ {l m n : ℕ } -> (f : Fin m -> Term n) (g : Fin l -> Term m) -> Fin l -> Term n
f ◇ g = (f ◃_) ∘ g
≐-cong : ∀ {m n o} {f : m ~> n} {g} (h : _ ~> o) -> f ≐ g -> (h ◇ f) ≐ (h ◇ g)
≐-cong h f≐g t = cong (h ◃_) (f≐g t)
≐-sym : ∀ {m n} {f : m ~> n} {g} -> f ≐ g -> g ≐ f
≐-sym f≐g = sym ∘ f≐g
open import Prelude using (it)
module Sub where
record Fact1 (T : ℕ → Set) ⦃ _ : Substitution T ⦄ : Set where
field
fact1 : ∀ {n} -> (t : T n) -> i ◃ t ≡ t
open Fact1 ⦃ … ⦄ public
mutual
instance Fact1Term : Fact1 Term
Fact1.fact1 Fact1Term (i x) = refl
Fact1.fact1 Fact1Term leaf = refl
Fact1.fact1 Fact1Term (s fork t) = cong₂ _fork_ (fact1 s) (fact1 t)
Fact1.fact1 Fact1Term (function fn ts) = cong (function fn) (fact1 ts)
instance Fact1TermVec : ∀ {N} → Fact1 (flip Vec N ∘ Term)
Fact1.fact1 Fact1TermVec [] = refl
Fact1.fact1 Fact1TermVec (t ∷ ts) = cong₂ _∷_ (fact1 t) (fact1 ts)
record Fact2 (T : ℕ → Set) ⦃ _ : Substitution T ⦄ : Set where
field
-- ⦃ s ⦄ : Substitution T
fact2 : ∀ {l m n} -> {f : Fin m -> Term n} {g : _} (t : T l) → (f ◇ g) ◃ t ≡ f ◃ (g ◃ t)
open Fact2 ⦃ … ⦄ public
mutual
instance Fact2Term : Fact2 Term
-- Fact2.s Fact2Term = SubstitutionTerm
Fact2.fact2 Fact2Term (i x) = refl
Fact2.fact2 Fact2Term leaf = refl
Fact2.fact2 Fact2Term (s fork t) = cong₂ _fork_ (fact2 s) (fact2 t)
Fact2.fact2 Fact2Term {f = f} {g = g} (function fn ts) = cong (function fn) (fact2 {f = f} {g = g} ts) -- fact2 ts
instance Fact2TermVec : ∀ {N} → Fact2 (flip Vec N ∘ Term)
-- Fact2.s Fact2TermVec = SubstitutionVecTerm
Fact2.fact2 Fact2TermVec [] = refl
Fact2.fact2 Fact2TermVec (t ∷ ts) = cong₂ _∷_ (fact2 t) (fact2 ts)
fact3 : ∀ {l m n} (f : Fin m -> Term n) (r : Fin l -> Fin m) -> (f ◇ (▹ r)) ≡ (f ∘ r)
fact3 f r = refl
◃ext' : ∀ {m n o} {f : Fin m -> Term n}{g : Fin m -> Term o}{h} -> f ≐ (h ◇ g) -> ∀ (t : Term _) -> f ◃ t ≡ h ◃ (g ◃ t)
◃ext' p t = trans (◃ext p t) (Sub.fact2 t)
open import Agda.Primitive
Injectivity : ∀ {a} {A : Set a} {b} {B : Set b} (f : A → B) → Set (a ⊔ b)
Injectivity f = ∀ {x y} → f x ≡ f y → x ≡ y
Injectivity₂ : ∀ {a} {A : Set a} {b} {B : Set b} {c} {C : Set c} (f : A → B → C) → Set (a ⊔ b ⊔ c)
Injectivity₂ f = ∀ {w x y z} → f w x ≡ f y z → x ≡ z
record Injective {a} {A : Set a} {b} {B : Set b} (f : A → B) : Set (a ⊔ b) where
field injectivity : ∀ x y → f x ≡ f y → x ≡ y
open Injective public -- ⦃ … ⦄ public
record Thin (T : ℕ → Set) : Set where
field
thin : ∀ {n} -> Fin (suc n) → T n → T (suc n)
thinfact1 : ∀ {n} (f : Fin (suc n)) → Injectivity (thin f)
term-i-inj : ∀ {n} → Injectivity (Term.i {n})
term-i-inj refl = refl
term-fork-l-inj : ∀ {n} → Injectivity₂ (flip (_fork_ {n}))
term-fork-l-inj refl = refl
term-fork-r-inj : ∀ {n} → Injectivity₂ (_fork_ {n})
term-fork-r-inj refl = refl
open Thin ⦃ … ⦄ public
p : ∀ {n} -> Fin (suc (suc n)) -> Fin (suc n)
p (suc x) = x
p zero = zero
instance ThinFin : Thin Fin
Thin.thin ThinFin zero y = suc y
Thin.thin ThinFin (suc x) zero = zero
Thin.thin ThinFin (suc x) (suc y) = suc (thin x y)
Thin.thinfact1 ThinFin zero refl = refl
Thin.thinfact1 ThinFin (suc x) {zero} {zero} r = refl
Thin.thinfact1 ThinFin (suc x) {zero} {(suc z)} ()
Thin.thinfact1 ThinFin (suc x) {(suc y)} {zero} ()
Thin.thinfact1 ThinFin (suc x) {(suc y)} {(suc z)} r =
cong suc (thinfact1 x (cong p r))
{- TODO defining using the below leads to termination checker problem -}
tfact1 : ∀ {n} (x : Fin (suc n)) (y : Fin _) (z : Fin n) -> thin x y ≡ thin x z -> y ≡ z
tfact1 zero y .y refl = refl
tfact1 (suc x) zero zero r = refl
tfact1 (suc x) zero (suc z) ()
tfact1 (suc x) (suc y) zero ()
tfact1 (suc x) (suc y) (suc z) r = cong suc (tfact1 x y z (cong p r))
mutual
mapTerm : ∀ {n m} → (Fin n → Fin m) → Term n → Term m
mapTerm x (i x₁) = i (x x₁)
mapTerm x leaf = leaf
mapTerm x (x₁ fork x₂) = mapTerm x x₁ fork mapTerm x x₂
mapTerm x (function x₁ x₂) = function x₁ (mapTerms x x₂)
mapTerms : ∀ {n m} → (Fin n → Fin m) → ∀ {N} → Vec (Term n) N → Vec (Term m) N
mapTerms x [] = []
mapTerms x (x₁ ∷ x₂) = mapTerm x x₁ ∷ mapTerms x x₂
mutual
thinfact1Term : ∀ {n} (f : Fin (suc n)) → Injectivity (mapTerm (thin f))
thinfact1Term x₁ {i x} {i x₃} x₂ = cong i (thinfact1 x₁ (term-i-inj x₂))
thinfact1Term x₁ {i x} {leaf} ()
thinfact1Term x₁ {i x} {y fork y₁} ()
thinfact1Term x₁ {i x} {function x₂ x₃} ()
thinfact1Term x₁ {leaf} {i x} ()
thinfact1Term x₁ {leaf} {leaf} x₂ = refl
thinfact1Term x₁ {leaf} {y fork y₁} ()
thinfact1Term x₁ {leaf} {function x x₂} ()
thinfact1Term x₁ {x fork x₂} {i x₃} ()
thinfact1Term x₁ {x fork x₂} {leaf} ()
thinfact1Term x₁ {x fork x₂} {y fork y₁} x₃ = cong₂ _fork_ (thinfact1Term x₁ (term-fork-l-inj x₃)) ((thinfact1Term x₁ (term-fork-r-inj x₃)))
thinfact1Term x₁ {x fork x₂} {function x₃ x₄} ()
thinfact1Term x₁ {function x x₂} {i x₃} ()
thinfact1Term x₁ {function x x₂} {leaf} ()
thinfact1Term x₁ {function x x₂} {y fork y₁} ()
thinfact1Term x₁ {function f1 {n} ts1} {function f2 ts2} r rewrite Term-function-inj-FunctionName r with Term-function-inj-VecSize r
thinfact1Term x₁ {function f1 {n} ts1} {function f2 ts2} r | refl with Term-function-inj-Vector r
thinfact1Term {m} x₁ {function f1 {n} ts1} {function f2 {.n} ts2} r | refl | w = cong (function f2) (((thinfact1Terms x₁ w)))
thinfact1Terms : ∀ {N} {n} (f : Fin (suc n)) → Injectivity (mapTerms (thin f) {N})
thinfact1Terms {.0} f {[]} {[]} x₁ = refl
thinfact1Terms {.(suc _)} f {x ∷ x₁} {x₂ ∷ y} x₃ = cong₂ _∷_ (thinfact1Term f (cong Data.Vec.head x₃)) (thinfact1Terms f (cong Data.Vec.tail x₃))
mutual
instance ThinTerm : Thin Term
Thin.thin ThinTerm = mapTerm ∘ thin
Thin.thinfact1 ThinTerm = thinfact1Term
instance ThinTermVec : ∀ {N} → Thin (flip Vec N ∘ Term)
Thin.thin ThinTermVec x x₁ = mapTerms (thin x) x₁
Thin.thinfact1 ThinTermVec = thinfact1Terms
module ThinFact where
fact2 : ∀ {n} x (y : Fin n) -> ¬ thin x y ≡ x
fact2 zero y ()
fact2 (suc x) zero ()
fact2 (suc x) (suc y) r = fact2 x y (cong p r)
fact3 : ∀{n} x (y : Fin (suc n)) -> ¬ x ≡ y -> ∃ λ y' -> thin x y' ≡ y
fact3 zero zero ne = ⊥-elim (ne refl)
fact3 zero (suc y) _ = y , refl
fact3 {zero} (suc ()) _ _
fact3 {suc n} (suc x) zero ne = zero , refl
fact3 {suc n} (suc x) (suc y) ne with y | fact3 x y (ne ∘ cong suc)
... | .(thin x y') | y' , refl = suc y' , refl
open import Data.Maybe
open import Category.Functor
open import Category.Monad
import Level
open RawMonad (Data.Maybe.monad {Level.zero})
thick : ∀ {n} -> (x y : Fin (suc n)) -> Maybe (Fin n)
thick zero zero = nothing
thick zero (suc y) = just y
thick {zero} (suc ()) _
thick {suc _} (suc x) zero = just zero
thick {suc _} (suc x) (suc y) = suc <$> (thick x y)
open import Data.Sum
_≡Fin_ : ∀ {n} -> (x y : Fin n) -> Dec (x ≡ y)
zero ≡Fin zero = yes refl
zero ≡Fin suc y = no λ ()
suc x ≡Fin zero = no λ ()
suc {suc _} x ≡Fin suc y with x ≡Fin y
... | yes r = yes (cong suc r)
... | no r = no λ e -> r (cong p e)
suc {zero} () ≡Fin _
module Thick where
half1 : ∀ {n} (x : Fin (suc n)) -> thick x x ≡ nothing
half1 zero = refl
half1 {suc _} (suc x) = cong (_<$>_ suc) (half1 x)
half1 {zero} (suc ())
half2 : ∀ {n} (x : Fin (suc n)) y -> ∀ y' -> thin x y' ≡ y -> thick x y ≡ just y'
half2 zero zero y' ()
half2 zero (suc y) .y refl = refl
half2 {suc n} (suc x) zero zero refl = refl
half2 {suc _} (suc _) zero (suc _) ()
half2 {suc n} (suc x) (suc y) zero ()
half2 {suc n} (suc x) (suc .(thin x y')) (suc y') refl with thick x (thin x y') | half2 x (thin x y') y' refl
... | .(just y') | refl = refl
half2 {zero} (suc ()) _ _ _
fact1 : ∀ {n} (x : Fin (suc n)) y r
-> thick x y ≡ r
-> x ≡ y × r ≡ nothing ⊎ ∃ λ y' -> thin x y' ≡ y × r ≡ just y'
fact1 x y .(thick x y) refl with x ≡Fin y
fact1 x .x ._ refl | yes refl = inj₁ (refl , half1 x)
... | no el with ThinFact.fact3 x y el
... | y' , thinxy'=y = inj₂ (y' , ( thinxy'=y , half2 x y y' thinxy'=y ))
record Check (T : ℕ → Set) : Set where
field
check : ∀{n} (x : Fin (suc n)) (t : T (suc n)) -> Maybe (T n)
open Check ⦃ … ⦄ public
_<*>_ = _⊛_
mutual
instance CheckTerm : Check Term
Check.check CheckTerm x (i y) = i <$> thick x y
Check.check CheckTerm x leaf = just leaf
Check.check CheckTerm x (s fork t) = _fork_ <$> check x s ⊛ check x t
Check.check CheckTerm x (function fn ts) = ⦇ (function fn) (check x ts) ⦈
instance CheckTermVec : ∀ {N} → Check (flip Vec N ∘ Term)
Check.check CheckTermVec x [] = just []
Check.check CheckTermVec x (t ∷ ts) = ⦇ check x t ∷ check x ts ⦈
_for_ : ∀ {n} (t' : Term n) (x : Fin (suc n)) -> Fin (suc n) -> Term n
(t' for x) y = maybe′ i t' (thick x y)
data AList : ℕ -> ℕ -> Set where
anil : ∀ {n} -> AList n n
_asnoc_/_ : ∀ {m n} (σ : AList m n) (t' : Term m) (x : Fin (suc m))
-> AList (suc m) n
sub : ∀ {m n} (σ : AList m n) -> Fin m -> Term n
sub anil = i
sub (σ asnoc t' / x) = sub σ ◇ (t' for x)
_++_ : ∀ {l m n} (ρ : AList m n) (σ : AList l m) -> AList l n
ρ ++ anil = ρ
ρ ++ (σ asnoc t' / x) = (ρ ++ σ) asnoc t' / x
++-assoc : ∀ {l m n o} (ρ : AList l m) (σ : AList n _) (τ : AList o _) -> ρ ++ (σ ++ τ) ≡ (ρ ++ σ) ++ τ
++-assoc ρ σ anil = refl
++-assoc ρ σ (τ asnoc t / x) = cong (λ s -> s asnoc t / x) (++-assoc ρ σ τ)
module SubList where
anil-id-l : ∀ {m n} (σ : AList m n) -> anil ++ σ ≡ σ
anil-id-l anil = refl
anil-id-l (σ asnoc t' / x) = cong (λ σ -> σ asnoc t' / x) (anil-id-l σ)
fact1 : ∀ {l m n} (ρ : AList m n) (σ : AList l m) -> sub (ρ ++ σ) ≐ (sub ρ ◇ sub σ)
fact1 ρ anil v = refl
fact1 {suc l} {m} {n} r (s asnoc t' / x) v = trans hyp-on-terms ◃-assoc
where
t = (t' for x) v
hyp-on-terms = ◃ext (fact1 r s) t
◃-assoc = Sub.fact2 t
_∃asnoc_/_ : ∀ {m} (a : ∃ (AList m)) (t' : Term m) (x : Fin (suc m))
-> ∃ (AList (suc m))
(n , σ) ∃asnoc t' / x = n , σ asnoc t' / x
flexFlex : ∀ {m} (x y : Fin m) -> ∃ (AList m)
flexFlex {suc m} x y with thick x y
... | just y' = m , anil asnoc i y' / x
... | nothing = suc m , anil
flexFlex {zero} () _
flexRigid : ∀ {m} (x : Fin m) (t : Term m) -> Maybe (∃(AList m))
flexRigid {suc m} x t with check x t
... | just t' = just (m , anil asnoc t' / x)
... | nothing = nothing
flexRigid {zero} () _
| 36.693095
| 162
| 0.565484
|
0d65a7dff4b5863c262174378cbdf2afeaf1ae5b
| 639
|
agda
|
Agda
|
test/Succeed/Using.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Using.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Using.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Using where
module Dummy where
data DummySet1 : Set where ds1 : DummySet1
data DummySet2 : Set where ds2 : DummySet2
open Dummy
using (DummySet1)
open Dummy -- checking that newline + comment is allowed before "using"
using (DummySet2)
-- Andreas, 2020-06-06, issue #4704
-- Allow repetions in `using` directives, but emit warning.
open Dummy
using (DummySet1; DummySet1)
using (DummySet1)
-- EXPECTED: dead code highlighting for 2nd and 3rd occurrence and warning:
-- Duplicates in using directive: DummySet1 DummySet1
-- when scope checking the declaration
-- open Dummy using (DummySet1; DummySet1; DummySet1)
| 27.782609
| 75
| 0.752739
|
3f3223ca434efd65f9808da438ddbc50140fee0b
| 194
|
agda
|
Agda
|
agda/Data/Empty/Base.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Data/Empty/Base.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Data/Empty/Base.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Data.Empty.Base where
open import Cubical.Data.Empty using (⊥; ⊥-elim; isProp⊥) public
open import Level
infix 4.5 ¬_
¬_ : Type a → Type a
¬ A = A → ⊥
| 17.636364
| 64
| 0.64433
|
a073d177a91e0b0524a18e1018799d3d3a400ebe
| 3,190
|
agda
|
Agda
|
src/Categories/Category/Construction/F-Algebras.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/Construction/F-Algebras.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/Construction/F-Algebras.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Construction.F-Algebras where
open import Level
open import Data.Product using (proj₁; proj₂)
open import Categories.Category
open import Categories.Functor hiding (id)
open import Categories.Functor.Algebra
open import Categories.Object.Initial
import Categories.Morphism.Reasoning as MR
import Categories.Morphism as Mor using (_≅_)
private
variable
o ℓ e : Level
𝒞 : Category o ℓ e
F-Algebras : {𝒞 : Category o ℓ e} → Endofunctor 𝒞 → Category (ℓ ⊔ o) (e ⊔ ℓ) e
F-Algebras {𝒞 = 𝒞} F = record
{ Obj = F-Algebra F
; _⇒_ = F-Algebra-Morphism
; _≈_ = λ α₁ α₂ → f α₁ ≈ f α₂
; _∘_ = λ α₁ α₂ → record { f = f α₁ ∘ f α₂ ; commutes = commut α₁ α₂ }
; id = record { f = id ; commutes = id-comm-sym ○ ⟺ (∘-resp-≈ʳ identity) }
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = record
{ refl = refl
; sym = sym
; trans = trans
}
; ∘-resp-≈ = ∘-resp-≈
}
where
open Category 𝒞
open MR 𝒞
open HomReasoning
open Equiv
open Functor F
open F-Algebra-Morphism
open F-Algebra
commut : {A B C : F-Algebra F} (α₁ : F-Algebra-Morphism B C) (α₂ : F-Algebra-Morphism A B) →
(f α₁ ∘ f α₂) ∘ α A ≈ α C ∘ F₁ (f α₁ ∘ f α₂)
commut {A} {B} {C} α₁ α₂ = begin
(f α₁ ∘ f α₂) ∘ α A ≈⟨ pullʳ (commutes α₂) ⟩
f α₁ ∘ (α B ∘ F₁ (f α₂)) ≈⟨ pullˡ (commutes α₁) ⟩
(α C ∘ F₁ (f α₁)) ∘ F₁ (f α₂) ≈⟨ pullʳ (⟺ homomorphism) ⟩
α C ∘ F₁ (f α₁ ∘ f α₂) ∎
module Lambek {𝒞 : Category o ℓ e} {F : Endofunctor 𝒞} (I : Initial (F-Algebras F)) where
open Category 𝒞
open Definitions 𝒞
open Functor F
open F-Algebra using (α)
open MR 𝒞 using (glue)
open Mor 𝒞
open Initial I -- so ⊥ is an F-Algebra, which is initial
-- While an expert might be able to decipher the proof at the nLab
-- (https://ncatlab.org/nlab/show/initial+algebra+of+an+endofunctor)
-- I (JC) have found that the notes at
-- http://www.cs.ru.nl/~jrot/coalgebra/ak-algebras.pdf
-- are easier to follow, and lead to the full proof below.
private
module ⊥ = F-Algebra ⊥
A = ⊥.A
a : F₀ A ⇒ A
a = ⊥.α
-- The F-Algebra structure that will make things work
F⊥ : F-Algebra F
F⊥ = iterate ⊥
-- By initiality, we get the following morphism
f : F-Algebra-Morphism ⊥ F⊥
f = !
module FAM = F-Algebra-Morphism f
i : A ⇒ F₀ A
i = FAM.f
a∘f : F-Algebra-Morphism ⊥ ⊥
a∘f = record
{ f = a ∘ i
; commutes = glue triv FAM.commutes ○ ∘-resp-≈ʳ (⟺ homomorphism)
}
where
open HomReasoning using (_○_; ⟺)
triv : CommutativeSquare (α F⊥) (α F⊥) a a
triv = Equiv.refl
lambek : A ≅ F₀ A
lambek = record
{ from = i
; to = a
; iso = record
{ isoˡ = ⊥-id a∘f
; isoʳ = begin
i ∘ a ≈⟨ F-Algebra-Morphism.commutes f ⟩
F₁ a ∘ F₁ i ≈˘⟨ homomorphism ⟩
F₁ (a ∘ i) ≈⟨ F-resp-≈ (⊥-id a∘f) ⟩
F₁ id ≈⟨ identity ⟩
id ∎
}
}
where
open HomReasoning
| 27.73913
| 96
| 0.566771
|
35c3e04559f18f4f9c2cf0bfb0d9f62dec81a580
| 3,101
|
agda
|
Agda
|
Cubical/Algebra/Lattice/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-02-05T01:25:26.000Z
|
2022-02-05T01:25:26.000Z
|
Cubical/Algebra/Lattice/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Lattice/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.Lattice.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open import Cubical.Structures.Macro
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.CommMonoid
open import Cubical.Algebra.Semilattice
open import Cubical.Algebra.Lattice.Base
open import Cubical.Relation.Binary.Poset
private
variable
ℓ : Level
module LatticeTheory (L' : Lattice ℓ) where
private L = fst L'
open LatticeStr (snd L')
0lLeftAnnihilates∧l : ∀ (x : L) → 0l ∧l x ≡ 0l
0lLeftAnnihilates∧l x = 0l ∧l x ≡⟨ cong (0l ∧l_) (sym (∨lLid _)) ⟩
0l ∧l (0l ∨l x) ≡⟨ ∧lAbsorb∨l _ _ ⟩
0l ∎
0lRightAnnihilates∧l : ∀ (x : L) → x ∧l 0l ≡ 0l
0lRightAnnihilates∧l _ = ∧lComm _ _ ∙ 0lLeftAnnihilates∧l _
1lLeftAnnihilates∨l : ∀ (x : L) → 1l ∨l x ≡ 1l
1lLeftAnnihilates∨l x = 1l ∨l x ≡⟨ cong (1l ∨l_) (sym (∧lLid _)) ⟩
1l ∨l (1l ∧l x) ≡⟨ ∨lAbsorb∧l _ _ ⟩
1l ∎
1lRightAnnihilates∨l : ∀ (x : L) → x ∨l 1l ≡ 1l
1lRightAnnihilates∨l _ = ∨lComm _ _ ∙ 1lLeftAnnihilates∨l _
module Order (L' : Lattice ℓ) where
private L = fst L'
open LatticeStr (snd L')
open JoinSemilattice (Lattice→JoinSemilattice L') renaming (_≤_ to _≤j_ ; IndPoset to JoinPoset)
open MeetSemilattice (Lattice→MeetSemilattice L') renaming (_≤_ to _≤m_ ; IndPoset to MeetPoset)
≤j→≤m : ∀ x y → x ≤j y → x ≤m y
≤j→≤m x y x∨ly≡y = x ∧l y ≡⟨ cong (x ∧l_) (sym x∨ly≡y) ⟩
x ∧l (x ∨l y) ≡⟨ ∧lAbsorb∨l _ _ ⟩
x ∎
≤m→≤j : ∀ x y → x ≤m y → x ≤j y
≤m→≤j x y x∧ly≡x = x ∨l y ≡⟨ ∨lComm _ _ ⟩
y ∨l x ≡⟨ cong (y ∨l_) (sym x∧ly≡x) ⟩
y ∨l (x ∧l y) ≡⟨ cong (y ∨l_) (∧lComm _ _) ⟩
y ∨l (y ∧l x) ≡⟨ ∨lAbsorb∧l _ _ ⟩
y ∎
≤Equiv : ∀ (x y : L) → (x ≤j y) ≃ (x ≤m y)
≤Equiv x y = propBiimpl→Equiv (isSetLattice L' _ _) (isSetLattice L' _ _) (≤j→≤m x y) (≤m→≤j x y)
IndPosetPath : JoinPoset ≡ MeetPoset
IndPosetPath = PosetPath _ _ .fst ((idEquiv _) , isposetequiv ≤Equiv )
-- transport inequalities from ≤m to ≤j
∧lIsMinJoin : ∀ x y z → z ≤j x → z ≤j y → z ≤j x ∧l y
∧lIsMinJoin _ _ _ z≤jx z≤jy = ≤m→≤j _ _ (∧lIsMin _ _ _ (≤j→≤m _ _ z≤jx) (≤j→≤m _ _ z≤jy))
∧≤LCancelJoin : ∀ x y → x ∧l y ≤j y
∧≤LCancelJoin x y = ≤m→≤j _ _ (∧≤LCancel x y)
module _ {L M : Lattice ℓ} (φ ψ : LatticeHom L M) where
open LatticeStr ⦃...⦄
open IsLatticeHom
private
instance
_ = L
_ = M
_ = snd L
_ = snd M
LatticeHom≡f : fst φ ≡ fst ψ → φ ≡ ψ
LatticeHom≡f = Σ≡Prop λ f → isPropIsLatticeHom _ f _
| 32.302083
| 98
| 0.599484
|
5eae370bf74545bbf63dc7b70068f71f24e573c3
| 19,896
|
agda
|
Agda
|
Cubical/ZCohomology/MayerVietorisUnreduced.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/MayerVietorisUnreduced.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/ZCohomology/MayerVietorisUnreduced.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.ZCohomology.MayerVietorisUnreduced where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.KcompPrelims
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Sigma
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn
open import Cubical.HITs.S1
open import Cubical.HITs.Susp
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to sRec2 ; elim to sElim ; elim2 to sElim2)
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; elim to pElim ; elim2 to pElim2 ; ∥_∥ to ∥_∥₁ ; ∣_∣ to ∣_∣₁)
open import Cubical.Data.Nat
open import Cubical.Data.Prod hiding (_×_)
open import Cubical.Algebra.Group
open import Cubical.HITs.Truncation renaming (elim to trElim ; map to trMap ; rec to trRec ; elim3 to trElim3)
open GroupHom
module MV {ℓ ℓ' ℓ''} (A : Type ℓ) (B : Type ℓ') (C : Type ℓ'') (f : C → A) (g : C → B) where
-- Proof from Brunerie 2016.
-- We first define the three morphisms involved: i, Δ and d.
private
i* : (n : ℕ) → coHom n (Pushout f g) → coHom n A × coHom n B
i* _ = sRec (isSet× setTruncIsSet setTruncIsSet) λ δ → ∣ (λ x → δ (inl x)) ∣₂ , ∣ (λ x → δ (inr x)) ∣₂
iIsHom : (n : ℕ) → isGroupHom (coHomGr n (Pushout f g)) (×coHomGr n A B) (i* n)
iIsHom _ = sElim2 (λ _ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _) λ _ _ → refl
i : (n : ℕ) → GroupHom (coHomGr n (Pushout f g)) (×coHomGr n A B)
GroupHom.fun (i n) = i* n
GroupHom.isHom (i n) = iIsHom n
private
distrLem : (n : ℕ) (x y z w : coHomK n) → (x +[ n ]ₖ y) -[ n ]ₖ (z +[ n ]ₖ w) ≡ (x -[ n ]ₖ z) +[ n ]ₖ (y -[ n ]ₖ w)
distrLem n x y z w =
cong (ΩKn+1→Kn n) (cong₂ (λ q p → q ∙ sym p) (+ₖ→∙ n x y) (+ₖ→∙ n z w)
∙∙ cong ((Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y) ∙_) (symDistr (Kn→ΩKn+1 n z) (Kn→ΩKn+1 n w))
∙∙ ((sym (assoc (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) _))
∙∙ cong (Kn→ΩKn+1 n x ∙_) (assoc (Kn→ΩKn+1 n y) (sym (Kn→ΩKn+1 n w)) (sym (Kn→ΩKn+1 n z)))
∙∙ (cong (Kn→ΩKn+1 n x ∙_) (isCommΩK (suc n) _ _)
∙∙ assoc _ _ _
∙∙ cong₂ _∙_ (sym (Iso.rightInv (Iso-Kn-ΩKn+1 n) (Kn→ΩKn+1 n x ∙ sym (Kn→ΩKn+1 n z))))
(sym (Iso.rightInv (Iso-Kn-ΩKn+1 n) (Kn→ΩKn+1 n y ∙ sym (Kn→ΩKn+1 n w)))))))
Δ' : (n : ℕ) → ⟨ ×coHomGr n A B ⟩ → ⟨ coHomGr n C ⟩
Δ' n (α , β) = coHomFun n f α -[ n ]ₕ coHomFun n g β
Δ'-isMorph : (n : ℕ) → isGroupHom (×coHomGr n A B) (coHomGr n C) (Δ' n)
Δ'-isMorph n =
prodElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _ )
λ f' x1 g' x2 i → ∣ (λ x → distrLem n (f' (f x)) (g' (f x)) (x1 (g x)) (x2 (g x)) i) ∣₂
Δ : (n : ℕ) → GroupHom (×coHomGr n A B) (coHomGr n C)
GroupHom.fun (Δ n) = Δ' n
GroupHom.isHom (Δ n) = Δ'-isMorph n
d-pre : (n : ℕ) → (C → coHomK n) → Pushout f g → coHomK (suc n)
d-pre n γ (inl x) = 0ₖ (suc n)
d-pre n γ (inr x) = 0ₖ (suc n)
d-pre zero γ (push a i) = Kn→ΩKn+1 zero (γ a) i
d-pre (suc n) γ (push a i) = Kn→ΩKn+1 (suc n) (γ a) i
dHomHelperPath : (n : ℕ) (h l : C → coHomK n) (a : C) → I → I → coHomK (suc n)
dHomHelperPath zero h l a i j =
hcomp (λ k → λ { (i = i0) → lUnitₖ 1 (0ₖ 1) (~ j)
; (i = i1) → lUnitₖ 1 (0ₖ 1) (~ j)
; (j = i0) → +ₖ→∙ 0 (h a) (l a) (~ k) i
; (j = i1) → cong₂Funct (λ x y → x +[ 1 ]ₖ y)
(Kn→ΩKn+1 0 (h a)) (Kn→ΩKn+1 0 (l a)) (~ k) i})
(bottom i j)
where
bottom : I → I → coHomK 1
bottom i j = hcomp (λ k → λ { (i = i0) → lUnitₖ 1 (0ₖ 1) (~ j)
; (i = i1) → lUnitₖ 1 (Kn→ΩKn+1 0 (l a) k) (~ j) })
(anotherbottom i j)
where
anotherbottom : I → I → coHomK 1
anotherbottom i j = hcomp (λ k → λ { (i = i0) → rUnitlUnit0 1 k (~ j)
; (i = i1) → rUnitlUnit0 1 k (~ j)
; (j = i0) → Kn→ΩKn+1 0 (h a) i
; (j = i1) → Kn→ΩKn+1 0 (h a) i +[ 1 ]ₖ 0ₖ 1 })
(rUnitₖ 1 (Kn→ΩKn+1 0 (h a) i) (~ j))
dHomHelperPath (suc n) h l a i j =
hcomp (λ k → λ { (i = i0) → lUnitₖ (2 + n) (0ₖ (2 + n)) (~ j)
; (i = i1) → lUnitₖ (2 + n) (0ₖ (2 + n)) (~ j)
; (j = i0) → +ₖ→∙ (suc n) (h a) (l a) (~ k) i
; (j = i1) → cong₂Funct (λ x y → x +[ 2 + n ]ₖ y)
(Kn→ΩKn+1 (suc n) (h a)) (Kn→ΩKn+1 (suc n) (l a)) (~ k) i})
(bottom i j)
where
bottom : I → I → coHomK (2 + n)
bottom i j = hcomp (λ k → λ { (i = i0) → lUnitₖ (2 + n) (0ₖ (2 + n)) (~ j)
; (i = i1) → lUnitₖ (2 + n) (Kn→ΩKn+1 (suc n) (l a) k) (~ j) })
(anotherbottom i j)
where
anotherbottom : I → I → coHomK (2 + n)
anotherbottom i j = hcomp (λ k → λ { (i = i0) → rUnitlUnit0 (2 + n) k (~ j)
; (i = i1) → rUnitlUnit0 (2 + n) k (~ j)
; (j = i0) → Kn→ΩKn+1 (suc n) (h a) i
; (j = i1) → Kn→ΩKn+1 (suc n) (h a) i +[ 2 + n ]ₖ (0ₖ (2 + n)) })
(rUnitₖ (2 + n) (Kn→ΩKn+1 (suc n) (h a) i) (~ j))
dHomHelper : (n : ℕ) (h l : C → coHomK n) (x : Pushout f g)
→ d-pre n (λ x → h x +[ n ]ₖ l x) x ≡ d-pre n h x +[ suc n ]ₖ d-pre n l x
dHomHelper n h l (inl x) = sym (lUnitₖ (suc n) (0ₖ (suc n)))
dHomHelper n h l (inr x) = sym (lUnitₖ (suc n) (0ₖ (suc n)))
dHomHelper zero h l (push a i) j = dHomHelperPath zero h l a i j
dHomHelper (suc n) h l (push a i) j = dHomHelperPath (suc n) h l a i j
dIsHom : (n : ℕ) → isGroupHom (coHomGr n C) (coHomGr (suc n) (Pushout f g)) (sRec setTruncIsSet λ a → ∣ d-pre n a ∣₂)
dIsHom zero = sElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ f g i → ∣ funExt (λ x → dHomHelper zero f g x) i ∣₂
dIsHom (suc n) = sElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ f g i → ∣ funExt (λ x → dHomHelper (suc n) f g x) i ∣₂
d : (n : ℕ) → GroupHom (coHomGr n C) (coHomGr (suc n) (Pushout f g))
GroupHom.fun (d n) = sRec setTruncIsSet λ a → ∣ d-pre n a ∣₂
GroupHom.isHom (d n) = dIsHom n
-- The long exact sequence
Im-d⊂Ker-i : (n : ℕ) (x : ⟨ (coHomGr (suc n) (Pushout f g)) ⟩)
→ isInIm (coHomGr n C) (coHomGr (suc n) (Pushout f g)) (d n) x
→ isInKer (coHomGr (suc n) (Pushout f g)) (×coHomGr (suc n) A B) (i (suc n)) x
Im-d⊂Ker-i n = sElim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _)
λ a → pRec (isOfHLevelPath' 1 (isSet× setTruncIsSet setTruncIsSet) _ _)
(sigmaElim (λ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _)
λ δ b i → sRec (isSet× setTruncIsSet setTruncIsSet)
(λ δ → ∣ (λ x → δ (inl x)) ∣₂ , ∣ (λ x → δ (inr x)) ∣₂ ) (b (~ i)))
Ker-i⊂Im-d : (n : ℕ) (x : ⟨ coHomGr (suc n) (Pushout f g) ⟩)
→ isInKer (coHomGr (suc n) (Pushout f g)) (×coHomGr (suc n) A B) (i (suc n)) x
→ isInIm (coHomGr n C) (coHomGr (suc n) (Pushout f g)) (d n) x
Ker-i⊂Im-d zero =
sElim (λ _ → isSetΠ λ _ → isProp→isSet propTruncIsProp)
λ a p → pRec {A = (λ x → a (inl x)) ≡ λ _ → 0ₖ 1}
(isProp→ propTruncIsProp)
(λ p1 → pRec propTruncIsProp λ p2 → ∣ ∣ (λ c → ΩKn+1→Kn 0 (sym (cong (λ F → F (f c)) p1)
∙∙ cong a (push c)
∙∙ cong (λ F → F (g c)) p2)) ∣₂
, cong ∣_∣₂ (funExt (λ δ → helper a p1 p2 δ)) ∣₁)
(Iso.fun PathIdTrunc₀Iso (cong fst p))
(Iso.fun PathIdTrunc₀Iso (cong snd p))
where
helper : (F : (Pushout f g) → hLevelTrunc 3 (S₊ 1))
(p1 : Path (_ → hLevelTrunc 3 (S₊ 1)) (λ a₁ → F (inl a₁)) (λ _ → ∣ base ∣))
(p2 : Path (_ → hLevelTrunc 3 (S₊ 1)) (λ a₁ → F (inr a₁)) (λ _ → ∣ base ∣))
→ (δ : Pushout f g)
→ d-pre 0 (λ c → ΩKn+1→Kn 0 ((λ i₁ → p1 (~ i₁) (f c))
∙∙ cong F (push c)
∙∙ cong (λ F → F (g c)) p2)) δ
≡ F δ
helper F p1 p2 (inl x) = sym (cong (λ f → f x) p1)
helper F p1 p2 (inr x) = sym (cong (λ f → f x) p2)
helper F p1 p2 (push a i) j =
hcomp (λ k → λ { (i = i0) → p1 (~ j) (f a)
; (i = i1) → p2 (~ j) (g a)
; (j = i0) → Iso.rightInv (Iso-Kn-ΩKn+1 0) ((λ i₁ → p1 (~ i₁) (f a))
∙∙ cong F (push a)
∙∙ cong (λ F₁ → F₁ (g a)) p2) (~ k) i
; (j = i1) → F (push a i)})
(doubleCompPath-filler (sym (cong (λ F → F (f a)) p1)) (cong F (push a)) (cong (λ F → F (g a)) p2) (~ j) i)
Ker-i⊂Im-d (suc n) =
sElim (λ _ → isSetΠ λ _ → isProp→isSet propTruncIsProp)
λ a p → pRec {A = (λ x → a (inl x)) ≡ λ _ → 0ₖ (2 + n)} (isProp→ propTruncIsProp)
(λ p1 → pRec propTruncIsProp λ p2 → ∣ ∣ (λ c → ΩKn+1→Kn (suc n) (sym (cong (λ F → F (f c)) p1)
∙∙ cong a (push c)
∙∙ cong (λ F → F (g c)) p2)) ∣₂
, cong ∣_∣₂ (funExt (λ δ → helper a p1 p2 δ)) ∣₁)
(Iso.fun PathIdTrunc₀Iso (cong fst p))
(Iso.fun PathIdTrunc₀Iso (cong snd p))
where
helper : (F : (Pushout f g) → hLevelTrunc (4 + n) (S₊ (2 + n)))
(p1 : Path (_ → hLevelTrunc (4 + n) (S₊ (2 + n))) (λ a₁ → F (inl a₁)) (λ _ → ∣ north ∣))
(p2 : Path (_ → hLevelTrunc (4 + n) (S₊ (2 + n))) (λ a₁ → F (inr a₁)) (λ _ → ∣ north ∣))
→ (δ : (Pushout f g))
→ d-pre (suc n) (λ c → ΩKn+1→Kn (suc n) ((λ i₁ → p1 (~ i₁) (f c))
∙∙ cong F (push c)
∙∙ cong (λ F → F (g c)) p2)) δ
≡ F δ
helper F p1 p2 (inl x) = sym (cong (λ f → f x) p1)
helper F p1 p2 (inr x) = sym (cong (λ f → f x) p2)
helper F p1 p2 (push a i) j =
hcomp (λ k → λ { (i = i0) → p1 (~ j) (f a)
; (i = i1) → p2 (~ j) (g a)
; (j = i0) → Iso.rightInv (Iso-Kn-ΩKn+1 (suc n)) ((λ i₁ → p1 (~ i₁) (f a))
∙∙ cong F (push a)
∙∙ cong (λ F₁ → F₁ (g a)) p2) (~ k) i
; (j = i1) → F (push a i)})
(doubleCompPath-filler (sym (cong (λ F → F (f a)) p1)) (cong F (push a)) (cong (λ F → F (g a)) p2) (~ j) i)
open GroupHom
Im-i⊂Ker-Δ : (n : ℕ) (x : ⟨ ×coHomGr n A B ⟩)
→ isInIm (coHomGr n (Pushout f g)) (×coHomGr n A B) (i n) x
→ isInKer (×coHomGr n A B) (coHomGr n C) (Δ n) x
Im-i⊂Ker-Δ n (Fa , Fb) =
sElim {B = λ Fa → (Fb : _) → isInIm (coHomGr n (Pushout f g)) (×coHomGr n A B) (i n) (Fa , Fb)
→ isInKer (×coHomGr n A B) (coHomGr n C) (Δ n) (Fa , Fb)}
(λ _ → isSetΠ2 λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(λ Fa → sElim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ Fb → pRec (setTruncIsSet _ _)
(sigmaElim (λ x → isProp→isSet (setTruncIsSet _ _))
λ Fd p → helper n Fa Fb Fd p))
Fa
Fb
where
helper : (n : ℕ) (Fa : A → coHomK n) (Fb : B → coHomK n) (Fd : (Pushout f g) → coHomK n)
→ (fun (i n) ∣ Fd ∣₂ ≡ (∣ Fa ∣₂ , ∣ Fb ∣₂))
→ (fun (Δ n)) (∣ Fa ∣₂ , ∣ Fb ∣₂) ≡ 0ₕ n
helper zero Fa Fb Fd p = cong (fun (Δ zero)) (sym p)
∙∙ (λ i → ∣ (λ x → Fd (inl (f x))) ∣₂ -[ 0 ]ₕ ∣ (λ x → Fd (push x (~ i))) ∣₂ )
∙∙ cancelₕ 0 ∣ (λ x → Fd (inl (f x))) ∣₂
helper (suc n) Fa Fb Fd p = cong (fun (Δ (suc n))) (sym p)
∙∙ (λ i → ∣ (λ x → Fd (inl (f x))) ∣₂ -[ (suc n) ]ₕ ∣ (λ x → Fd (push x (~ i))) ∣₂)
∙∙ cancelₕ (suc n) ∣ (λ x → Fd (inl (f x))) ∣₂
Ker-Δ⊂Im-i : (n : ℕ) (a : ⟨ ×coHomGr n A B ⟩)
→ isInKer (×coHomGr n A B) (coHomGr n C) (Δ n) a
→ isInIm (coHomGr n (Pushout f g)) (×coHomGr n A B) (i n) a
Ker-Δ⊂Im-i n = prodElim (λ _ → isSetΠ (λ _ → isProp→isSet propTruncIsProp))
(λ Fa Fb p → pRec propTruncIsProp
(λ q → ∣ ∣ helpFun Fa Fb q ∣₂ , refl ∣₁)
(helper Fa Fb p))
where
helper : (Fa : A → coHomK n) (Fb : B → coHomK n)
→ fun (Δ n) (∣ Fa ∣₂ , ∣ Fb ∣₂) ≡ 0ₕ n
→ ∥ Path (_ → _) (λ c → Fa (f c)) (λ c → Fb (g c)) ∥₁
helper Fa Fb p = Iso.fun PathIdTrunc₀Iso
(sym (-+cancelₕ n ∣ (λ c → Fa (f c)) ∣₂ ∣ (λ c → Fb (g c)) ∣₂)
∙∙ cong (λ x → x +[ n ]ₕ ∣ (λ c → Fb (g c)) ∣₂) p
∙∙ lUnitₕ n _)
helpFun : (Fa : A → coHomK n) (Fb : B → coHomK n)
→ ((λ c → Fa (f c)) ≡ (λ c → Fb (g c)))
→ Pushout f g → coHomK n
helpFun Fa Fb p (inl x) = Fa x
helpFun Fa Fb p (inr x) = Fb x
helpFun Fa Fb p (push a i) = p i a
private
distrHelper : (n : ℕ) (p q : _)
→ ΩKn+1→Kn n p +[ n ]ₖ (-[ n ]ₖ ΩKn+1→Kn n q) ≡ ΩKn+1→Kn n (p ∙ sym q)
distrHelper n p q i =
ΩKn+1→Kn n (Iso.rightInv (Iso-Kn-ΩKn+1 n) p i
∙ Iso.rightInv (Iso-Kn-ΩKn+1 n) (sym (Iso.rightInv (Iso-Kn-ΩKn+1 n) q i)) i)
Ker-d⊂Im-Δ : (n : ℕ) (a : coHom n C)
→ isInKer (coHomGr n C) (coHomGr (suc n) (Pushout f g)) (d n) a
→ isInIm (×coHomGr n A B) (coHomGr n C) (Δ n) a
Ker-d⊂Im-Δ zero =
sElim (λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 propTruncIsProp)
λ Fc p → pRec propTruncIsProp (λ p → ∣ (∣ (λ a → ΩKn+1→Kn 0 (cong (λ f → f (inl a)) p)) ∣₂ ,
∣ (λ b → ΩKn+1→Kn 0 (cong (λ f → f (inr b)) p)) ∣₂) ,
Iso.inv (PathIdTrunc₀Iso) ∣ funExt (λ c → helper2 Fc p c) ∣₁ ∣₁)
(Iso.fun (PathIdTrunc₀Iso) p)
where
helper2 : (Fc : C → coHomK 0)
(p : d-pre 0 Fc ≡ (λ _ → ∣ base ∣)) (c : C)
→ ΩKn+1→Kn 0 (λ i₁ → p i₁ (inl (f c))) -[ 0 ]ₖ (ΩKn+1→Kn 0 (λ i₁ → p i₁ (inr (g c)))) ≡ Fc c
helper2 Fc p c = cong₂ (λ x y → ΩKn+1→Kn 0 (x ∙ sym y)) (Iso.rightInv (Iso-Kn-ΩKn+1 0) (λ i₁ → p i₁ (inl (f c))))
(Iso.rightInv (Iso-Kn-ΩKn+1 0) (λ i₁ → p i₁ (inr (g c))))
∙∙ cong (ΩKn+1→Kn 0) (sym ((PathP→compPathR (cong (λ f → cong f (push c)) p))
∙ (λ i → (λ i₁ → p i₁ (inl (f c)))
∙ (lUnit (sym (λ i₁ → p i₁ (inr (g c)))) (~ i)))))
∙∙ Iso.leftInv (Iso-Kn-ΩKn+1 zero) (Fc c)
Ker-d⊂Im-Δ (suc n) =
sElim (λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 propTruncIsProp)
λ Fc p → pRec propTruncIsProp (λ p → ∣ (∣ (λ a → ΩKn+1→Kn (suc n) (cong (λ f → f (inl a)) p)) ∣₂ ,
∣ (λ b → ΩKn+1→Kn (suc n) (cong (λ f → f (inr b)) p)) ∣₂) ,
Iso.inv (PathIdTrunc₀Iso) ∣ funExt (λ c → helper2 Fc p c) ∣₁ ∣₁)
(Iso.fun (PathIdTrunc₀Iso) p)
where
helper2 : (Fc : C → coHomK (suc n))
(p : d-pre (suc n) Fc ≡ (λ _ → ∣ north ∣)) (c : C)
→ ΩKn+1→Kn (suc n) (λ i₁ → p i₁ (inl (f c))) -[ (suc n) ]ₖ (ΩKn+1→Kn (suc n) (λ i₁ → p i₁ (inr (g c)))) ≡ Fc c
helper2 Fc p c = cong₂ (λ x y → ΩKn+1→Kn (suc n) (x ∙ sym y)) (Iso.rightInv (Iso-Kn-ΩKn+1 (suc n)) (λ i₁ → p i₁ (inl (f c))))
(Iso.rightInv (Iso-Kn-ΩKn+1 (suc n)) (λ i₁ → p i₁ (inr (g c))))
∙∙ cong (ΩKn+1→Kn (suc n)) (sym ((PathP→compPathR (cong (λ f → cong f (push c)) p))
∙ (λ i → (λ i₁ → p i₁ (inl (f c)))
∙ (lUnit (sym (λ i₁ → p i₁ (inr (g c)))) (~ i)))))
∙∙ Iso.leftInv (Iso-Kn-ΩKn+1 (suc n)) (Fc c)
Im-Δ⊂Ker-d : (n : ℕ) (a : coHom n C)
→ isInIm (×coHomGr n A B) (coHomGr n C) (Δ n) a
→ isInKer (coHomGr n C) (coHomGr (suc n) (Pushout f g)) (d n) a
Im-Δ⊂Ker-d n =
sElim (λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ Fc → pRec (isOfHLevelPath' 1 setTruncIsSet _ _)
(sigmaProdElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ Fa Fb p → pRec (isOfHLevelPath' 1 setTruncIsSet _ _)
(λ q → ((λ i → fun (d n) ∣ (q (~ i)) ∣₂) ∙ dΔ-Id n Fa Fb))
(Iso.fun (PathIdTrunc₀Iso) p))
where
d-preLeftId : (n : ℕ) (Fa : A → coHomK n)(d : (Pushout f g))
→ d-pre n (Fa ∘ f) d ≡ 0ₖ (suc n)
d-preLeftId zero Fa (inl x) = Kn→ΩKn+1 0 (Fa x)
d-preLeftId (suc n) Fa (inl x) = Kn→ΩKn+1 (suc n) (Fa x)
d-preLeftId zero Fa (inr x) = refl
d-preLeftId (suc n) Fa (inr x) = refl
d-preLeftId zero Fa (push a i) j = Kn→ΩKn+1 zero (Fa (f a)) (j ∨ i)
d-preLeftId (suc n) Fa (push a i) j = Kn→ΩKn+1 (suc n) (Fa (f a)) (j ∨ i)
d-preRightId : (n : ℕ) (Fb : B → coHomK n) (d : (Pushout f g))
→ d-pre n (Fb ∘ g) d ≡ 0ₖ (suc n)
d-preRightId n Fb (inl x) = refl
d-preRightId zero Fb (inr x) = sym (Kn→ΩKn+1 0 (Fb x))
d-preRightId (suc n) Fb (inr x) = sym (Kn→ΩKn+1 (suc n) (Fb x))
d-preRightId zero Fb (push a i) j = Kn→ΩKn+1 zero (Fb (g a)) (~ j ∧ i)
d-preRightId (suc n) Fb (push a i) j = Kn→ΩKn+1 (suc n) (Fb (g a)) (~ j ∧ i)
dΔ-Id : (n : ℕ) (Fa : A → coHomK n) (Fb : B → coHomK n)
→ fun (d n) (fun (Δ n) (∣ Fa ∣₂ , ∣ Fb ∣₂)) ≡ 0ₕ (suc n)
dΔ-Id zero Fa Fb = -distrLemma 0 1 (d zero) ∣ Fa ∘ f ∣₂ ∣ Fb ∘ g ∣₂
∙∙ (λ i → ∣ (λ x → d-preLeftId zero Fa x i) ∣₂ -[ 1 ]ₕ ∣ (λ x → d-preRightId zero Fb x i) ∣₂)
∙∙ cancelₕ 1 (0ₕ 1)
dΔ-Id (suc n) Fa Fb = -distrLemma (suc n) (2 + n) (d (suc n)) ∣ Fa ∘ f ∣₂ ∣ Fb ∘ g ∣₂
∙∙ (λ i → ∣ (λ x → d-preLeftId (suc n) Fa x i) ∣₂ -[ (2 + n) ]ₕ ∣ (λ x → d-preRightId (suc n) Fb x i) ∣₂)
∙∙ cancelₕ (2 + n) (0ₕ (2 + n))
| 58.175439
| 133
| 0.420889
|
7cfe769ed1c880c35040c143f8a2eb21663525f0
| 182
|
agda
|
Agda
|
test/Common/Char.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | null | null | null |
test/Common/Char.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | 6
|
2021-10-18T08:12:24.000Z
|
2021-11-24T08:31:10.000Z
|
test/Common/Char.agda
|
antoinevanmuylder/agda
|
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
|
[
"BSD-2-Clause"
] | null | null | null |
{-# OPTIONS --cubical-compatible #-}
module Common.Char where
open import Agda.Builtin.Char public
open import Common.Bool
charEq : Char -> Char -> Bool
charEq = primCharEquality
| 18.2
| 36
| 0.747253
|
1433e12a92d751bdd270b4fe4992b17b061d2030
| 5,471
|
agda
|
Agda
|
Cubical/HITs/SetQuotients/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/SetQuotients/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/SetQuotients/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-
Set quotients:
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.SetQuotients.Properties where
open import Cubical.HITs.SetQuotients.Base
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.HAEquiv
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary.Base
open import Cubical.HITs.PropositionalTruncation as PropTrunc using (∥_∥; ∣_∣; squash)
open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₀; ∣_∣₀; squash₀)
-- Type quotients
private
variable
ℓ ℓ' ℓ'' : Level
A : Type ℓ
R : A → A → Type ℓ'
B : A / R → Type ℓ''
elimEq/ : (Bprop : (x : A / R ) → isProp (B x))
{x y : A / R}
(eq : x ≡ y)
(bx : B x)
(by : B y) →
PathP (λ i → B (eq i)) bx by
elimEq/ {B = B} Bprop {x = x} =
J (λ y eq → ∀ bx by → PathP (λ i → B (eq i)) bx by) (λ bx by → Bprop x bx by)
elimProp : ((x : A / R ) → isProp (B x)) →
(f : (a : A) → B ( [ a ])) →
(x : A / R) → B x
elimProp Bprop f [ x ] = f x
elimProp Bprop f (squash/ x y p q i j) =
isOfHLevel→isOfHLevelDep 2 (λ x → isProp→isSet (Bprop x))
(g x) (g y) (cong g p) (cong g q) (squash/ x y p q) i j
where
g = elimProp Bprop f
elimProp Bprop f (eq/ a b r i) = elimEq/ Bprop (eq/ a b r) (f a) (f b) i
-- lemma 6.10.2 in hott book
-- TODO: defined truncated Sigma as ∃
[]surjective : (x : A / R) → ∥ Σ[ a ∈ A ] [ a ] ≡ x ∥
[]surjective = elimProp (λ x → squash) (λ a → ∣ a , refl ∣)
elim : {B : A / R → Type ℓ} →
(Bset : (x : A / R) → isSet (B x)) →
(f : (a : A) → (B [ a ])) →
(feq : (a b : A) (r : R a b) →
PathP (λ i → B (eq/ a b r i)) (f a) (f b)) →
(x : A / R) → B x
elim Bset f feq [ a ] = f a
elim Bset f feq (eq/ a b r i) = feq a b r i
elim Bset f feq (squash/ x y p q i j) =
isOfHLevel→isOfHLevelDep 2 Bset
(g x) (g y) (cong g p) (cong g q) (squash/ x y p q) i j
where
g = elim Bset f feq
setQuotUniversal : {B : Type ℓ} (Bset : isSet B) →
(A / R → B) ≃ (Σ[ f ∈ (A → B) ] ((a b : A) → R a b → f a ≡ f b))
setQuotUniversal Bset = isoToEquiv (iso intro out outRightInv outLeftInv)
where
intro = λ g → (λ a → g [ a ]) , λ a b r i → g (eq/ a b r i)
out = λ h → elim (λ x → Bset) (fst h) (snd h)
outRightInv : ∀ h → intro (out h) ≡ h
outRightInv h = refl
outLeftInv : ∀ g → out (intro g) ≡ g
outLeftInv = λ g → funExt (λ x → PropTrunc.elim {P = λ sur → out (intro g) x ≡ g x}
(λ sur → Bset (out (intro g) x) (g x))
(λ sur → cong (out (intro g)) (sym (snd sur)) ∙ (cong g (snd sur))) ([]surjective x)
)
open BinaryRelation
effective : (Rprop : isPropValued R) (Requiv : isEquivRel R) (a b : A) → [ a ] ≡ [ b ] → R a b
effective {A = A} {R = R} Rprop (EquivRel R/refl R/sym R/trans) a b p = transport aa≡ab (R/refl _)
where
helper : A / R → hProp _
helper = elim (λ _ → isSetHProp) (λ c → (R a c , Rprop a c))
(λ c d cd → ΣProp≡ (λ _ → isPropIsProp)
(ua (PropEquiv→Equiv (Rprop a c) (Rprop a d)
(λ ac → R/trans _ _ _ ac cd) (λ ad → R/trans _ _ _ ad (R/sym _ _ cd)))))
aa≡ab : R a a ≡ R a b
aa≡ab i = fst (helper (p i))
isEquivRel→isEffective : isPropValued R → isEquivRel R → isEffective R
isEquivRel→isEffective {R = R} Rprop Req a b = isoToEquiv (iso intro out intro-out out-intro)
where
intro : [ a ] ≡ [ b ] → R a b
intro = effective Rprop Req a b
out : R a b → [ a ] ≡ [ b ]
out = eq/ a b
intro-out : ∀ x → intro (out x) ≡ x
intro-out ab = Rprop a b _ _
out-intro : ∀ x → out (intro x) ≡ x
out-intro eq = squash/ _ _ _ _
discreteSetQuotients : Discrete A → isPropValued R → isEquivRel R → (∀ a₀ a₁ → Dec (R a₀ a₁)) → Discrete (A / R)
discreteSetQuotients {A = A} {R = R} Adis Rprop Req Rdec =
elim (λ a₀ → isSetPi (λ a₁ → isProp→isSet (isPropDec (squash/ a₀ a₁))))
discreteSetQuotients' discreteSetQuotients'-eq
where
discreteSetQuotients' : (a : A) (y : A / R) → Dec ([ a ] ≡ y)
discreteSetQuotients' a₀ = elim ((λ a₁ → isProp→isSet (isPropDec (squash/ [ a₀ ] a₁)))) dis dis-eq
where
dis : (a₁ : A) → Dec ([ a₀ ] ≡ [ a₁ ])
dis a₁ with Rdec a₀ a₁
... | (yes p) = yes (eq/ a₀ a₁ p)
... | (no ¬p) = no λ eq → ¬p (effective Rprop Req a₀ a₁ eq )
dis-eq : (a b : A) (r : R a b) →
PathP (λ i → Dec ([ a₀ ] ≡ eq/ a b r i)) (dis a) (dis b)
dis-eq a b ab = J (λ b ab → ∀ k → PathP (λ i → Dec ([ a₀ ] ≡ ab i)) (dis a) k)
(λ k → isPropDec (squash/ _ _) _ _) (eq/ a b ab) (dis b)
discreteSetQuotients'-eq : (a b : A) (r : R a b) →
PathP (λ i → (y : A / R) → Dec (eq/ a b r i ≡ y))
(discreteSetQuotients' a) (discreteSetQuotients' b)
discreteSetQuotients'-eq a b ab =
J (λ b ab → ∀ k → PathP (λ i → (y : A / R) → Dec (ab i ≡ y))
(discreteSetQuotients' a) k)
(λ k → funExt (λ x → isPropDec (squash/ _ _) _ _)) (eq/ a b ab) (discreteSetQuotients' b)
| 36.718121
| 142
| 0.522025
|
0dff57d66bfc33753b25e17a77e65a75fed8c630
| 2,906
|
agda
|
Agda
|
test/succeed/Reflection.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2019-11-27T04:41:05.000Z
|
2019-11-27T04:41:05.000Z
|
test/succeed/Reflection.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/Reflection.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --universe-polymorphism #-}
module Reflection where
open import Common.Prelude hiding (Unit; module Unit) renaming (Nat to ℕ)
open import Common.Reflect
data _≡_ {a}{A : Set a}(x : A) : A → Set a where
refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
{-# BUILTIN REFL refl #-}
data Id {A : Set}(x : A) : (B : Set) → B → Set where
course : Id x A x
primitive
primTrustMe : ∀{a}{A : Set a}{x y : A} → x ≡ y
open import Common.Level
unEl : Type → Term
unEl (el _ t) = t
argᵛʳ : ∀{A} → A → Arg A
argᵛʳ = arg (arginfo visible relevant)
argʰʳ : ∀{A} → A → Arg A
argʰʳ = arg (arginfo hidden relevant)
el₀ : Term → Type
el₀ = el (lit 0)
el₁ : Term → Type
el₁ = el (lit 1)
set₀ : Type
set₀ = el₁ (sort (lit 0))
unCheck : Term → Term
unCheck (def x (_ ∷ _ ∷ arg _ t ∷ [])) = t
unCheck t = unknown
mutual
data Check {a}{A : Set a}(x : A) : Set where
_is_of_ : (t t′ : Term) →
Id (primTrustMe {x = unCheck t} {t′}
)
(t′ ≡ t′) refl → Check x
`Check : QName
`Check = quote Check
test₁ : Check ({A : Set} → A → A)
test₁ = quoteGoal t in
t is pi (argʰʳ set₀) (el₀ (pi (argᵛʳ (el₀ (var 0 []))) (el₀ (var 1 []))))
of course
test₂ : (X : Set) → Check (λ (x : X) → x)
test₂ X = quoteGoal t in
t is lam visible (var 0 []) of course
infixr 40 _`∷_
_`∷_ : Term → Term → Term
x `∷ xs = con (quote _∷_) (argᵛʳ x ∷ argᵛʳ xs ∷ [])
`[] = con (quote []) []
`true = con (quote true) []
`false = con (quote false) []
test₃ : Check (true ∷ false ∷ [])
test₃ = quoteGoal t in
t is `true `∷ `false `∷ `[] of course
`List : Term → Term
`List A = def (quote List) (argᵛʳ A ∷ [])
`ℕ = def (quote ℕ) []
`Term : Term
`Term = def (quote Term) []
`Type : Term
`Type = def (quote Type) []
`Sort : Term
`Sort = def (quote Sort) []
test₄ : Check (List ℕ)
test₄ = quoteGoal t in
t is `List `ℕ of course
test₅ : primQNameType (quote Term) ≡ set₀
test₅ = refl
-- TODO => test₆ : primQNameType (quote set₀) ≡ el unknown `Type ≢ el₀ `Type
test₆ : unEl (primQNameType (quote set₀)) ≡ `Type
test₆ = refl
test₇ : primQNameType (quote Sort.lit) ≡ el₀ (pi (argᵛʳ (el₀ `ℕ)) (el₀ `Sort))
test₇ = refl
mutual
ℕdef : DataDef
ℕdef = _
test₈ : dataDef ℕdef ≡ primQNameDefinition (quote ℕ)
test₈ = refl
test₉ : primDataConstructors ℕdef ≡ quote ℕ.zero ∷ quote ℕ.suc ∷ []
test₉ = refl
test₁₀ : primQNameDefinition (quote ℕ.zero) ≡ dataConstructor
test₁₀ = refl
postulate
a : ℕ
test₁₁ : primQNameDefinition (quote a) ≡ axiom
test₁₁ = refl
test₁₂ : primQNameDefinition (quote primQNameDefinition) ≡ prim
test₁₂ = refl
record Unit : Set where
mutual
UnitDef : RecordDef
UnitDef = _
test₁₃ : recordDef UnitDef ≡ primQNameDefinition (quote Unit)
test₁₃ = refl
test₁₄ : Check 1
test₁₄ = quoteGoal t in
t is con ( quote ℕ.suc ) (argᵛʳ (con (quote ℕ.zero) []) ∷ [])
of course
| 21.686567
| 81
| 0.596008
|
0bb0d1c6eead39753bc84bf58bd91ee47a5ffe45
| 1,489
|
agda
|
Agda
|
examples/outdated-and-incorrect/cbs/Hear.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/outdated-and-incorrect/cbs/Hear.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/outdated-and-incorrect/cbs/Hear.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Proc
module Hear (param : Param) where
open import Basics
private open module P = Process param
open Tran
hear : {a : U}{p : Proc a} -> Guard p -> LT a -> Proc a
hear {p = p} g bot = p
hear og (lift v) = o
hear (w !g p) (lift v) = w ! p
hear (>g f) (lift v) = f v
hear (_ ! _ +g f) (lift v) = f v
hear (g1 ||g g2) (lift v) = hear g1 (lift v) || hear g2 (lift v)
hear (φ /|g g) (lift v) = φ /| hear g (downV φ v)
hear (defg x g) (lift v) = hear g (lift v)
sound : {a : U}{p : Proc a}(g : Guard p){w : LT a} ->
p -[ w ]-> hear g w
sound g {bot} = qtau
sound og {lift v} = rx-o
sound (>g _) {lift v} = rx->
sound (w !g p) {lift v} = rx-!
sound (w ! p +g f) {lift v} = rx-+
sound (g1 ||g g2) {lift v} = rx-|| (sound g1) (sound g2)
sound (φ /|g g) {lift v} = rx-/| (sound g)
sound (defg x g) {lift v} = rx-def (sound g)
uniq : {a : U}{p : Proc a}{w : LT a}{px py : Proc a} ->
p -[ w ]-> px -> p -[ w ]-> py -> px == py
uniq qtau qtau = refl
uniq rx-o rx-o = refl
uniq rx-> rx-> = refl
uniq rx-! rx-! = refl
uniq rx-+ rx-+ = refl
uniq (rx-|| l1 r1) (rx-|| l2 r2) with uniq l1 l2 | uniq r1 r2
... | refl | refl = refl
uniq (rx-/| r1) (rx-/| r2) with uniq r1 r2
... | refl = refl
uniq (rx-def r1) (rx-def r2) with uniq r1 r2
... | refl = refl
complete : {a : U}{p : Proc a}(g : Guard p){w : LT a}{p' : Proc a} ->
p -[ w ]-> p' -> p' == hear g w
complete g r = uniq r (sound g)
| 30.387755
| 69
| 0.496306
|
7c8796a6252e050ecabd7e7bdba2a991ee112d07
| 8,466
|
agda
|
Agda
|
list-thms.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 29
|
2019-02-06T13:09:31.000Z
|
2022-03-04T15:05:12.000Z
|
list-thms.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 8
|
2018-07-09T22:53:38.000Z
|
2022-03-22T03:43:34.000Z
|
list-thms.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 17
|
2018-12-03T22:38:15.000Z
|
2021-11-28T20:13:21.000Z
|
module list-thms where
-- see list-thms2 for more
open import bool
open import bool-thms
open import bool-thms2
open import functions
open import list
open import nat
open import nat-thms
open import product-thms
open import logic
++[] : ∀{ℓ}{A : Set ℓ} → (l : 𝕃 A) → l ++ [] ≡ l
++[] [] = refl
++[] (x :: xs) rewrite ++[] xs = refl
++-assoc : ∀ {ℓ}{A : Set ℓ} (l1 l2 l3 : 𝕃 A) →
(l1 ++ l2) ++ l3 ≡ l1 ++ (l2 ++ l3)
++-assoc [] l2 l3 = refl
++-assoc (x :: xs) l2 l3 rewrite ++-assoc xs l2 l3 = refl
length-++ : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) →
length (l1 ++ l2) ≡ (length l1) + (length l2)
length-++ [] l2 = refl
length-++ (h :: t) l2 rewrite length-++ t l2 = refl
map-append : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} →
(f : A → B) (l1 l2 : 𝕃 A) →
map f (l1 ++ l2) ≡ (map f l1) ++ (map f l2)
map-append f [] l2 = refl
map-append f (x :: xs) l2 rewrite map-append f xs l2 = refl
map-compose : ∀ {ℓ ℓ' ℓ''} {A : Set ℓ} {B : Set ℓ'}{C : Set ℓ''} →
(f : B → C) (g : A → B) (l : 𝕃 A) →
map f (map g l) ≡ map (f ∘ g) l
map-compose f g [] = refl
map-compose f g (x :: xs) rewrite map-compose f g xs = refl
foldr-append : ∀{ℓ₁ ℓ₂}{A : Set ℓ₁}{B : Set ℓ₂}{l₁ l₂ : 𝕃 (A → 𝕃 B)}{a : A}
→ (foldr (λ f → _++_ (f a)) [] l₁) ++ (foldr (λ f → _++_ (f a)) [] l₂) ≡ foldr (λ f → _++_ (f a)) [] (l₁ ++ l₂)
foldr-append {l₁ = []}{_}{a} = refl
foldr-append {l₁ = x :: l₁}{l₂}{a}
rewrite
++-assoc (x a) (foldr (λ f → _++_ (f a)) [] l₁) (foldr (λ f → _++_ (f a)) [] l₂)
| foldr-append {l₁ = l₁}{l₂}{a}
= refl
invert𝕃 : ∀{ℓ}{A : Set ℓ}{t : A}{ts : 𝕃 A} → t :: ts ≢ []
invert𝕃 ()
length-repeat : ∀{ℓ}{A : Set ℓ} (n : ℕ) (a : A) → length (repeat n a) ≡ n
length-repeat 0 a = refl
length-repeat (suc n) a rewrite length-repeat n a = refl
map-repeat : ∀ {ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'}(n : ℕ)(a : A)(f : A → B) → map f (repeat n a) ≡ repeat n (f a)
map-repeat 0 a f = refl
map-repeat (suc x) a f rewrite map-repeat x a f = refl
length-map : ∀{ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B)(l : 𝕃 A) → length (map f l) ≡ length l
length-map f [] = refl
length-map f (head :: tail) rewrite length-map f tail = refl
length-reverse-helper : ∀{ℓ}{A : Set ℓ}(h l : 𝕃 A) →
length (reverse-helper h l) ≡ length h + length l
length-reverse-helper h [] rewrite +0 (length h) = refl
length-reverse-helper h (x :: xs) rewrite length-reverse-helper (x :: h) xs = sym (+suc (length h) (length xs))
length-reverse : ∀{ℓ}{A : Set ℓ}(l : 𝕃 A) → length (reverse l) ≡ length l
length-reverse l = length-reverse-helper [] l
reverse-++h : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) → reverse-helper l1 l2 ≡ reverse-helper [] l2 ++ l1
reverse-++h l1 [] = refl
reverse-++h l1 (x :: xs) rewrite reverse-++h (x :: l1) xs | reverse-++h (x :: []) xs | ++-assoc (reverse xs) (x :: []) l1 = refl
reverse-++ : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) → reverse(l1 ++ l2) ≡ reverse(l2) ++ reverse(l1)
reverse-++ [] l2 rewrite ++[] (reverse l2) = refl
reverse-++ (x :: xs) l2 rewrite reverse-++h (x :: []) (xs ++ l2) | reverse-++ xs l2 | ++-assoc (reverse l2) (reverse xs) (x :: []) | sym (reverse-++h (x :: []) xs) = refl
=𝕃-refl : ∀{ℓ}{A : Set ℓ}{l1 : 𝕃 A} → (eq : A → A → 𝔹) → ((x y : A) → x ≡ y → eq x y ≡ tt) → =𝕃 eq l1 l1 ≡ tt
=𝕃-refl{l1 = []} eq rise = refl
=𝕃-refl{l1 = x :: xs} eq rise = &&-combo (rise x x refl) (=𝕃-refl{l1 = xs} eq rise)
≡𝕃-from-= : ∀{ℓ}{A : Set ℓ}{l1 l2 : 𝕃 A} → (eq : A → A → 𝔹) → ((x y : A) → eq x y ≡ tt → x ≡ y) → =𝕃 eq l1 l2 ≡ tt → l1 ≡ l2
≡𝕃-from-={l1 = []}{[]} eq drop p = refl
≡𝕃-from-={l1 = x :: xs}{[]} eq drop ()
≡𝕃-from-={l1 = []}{y :: ys} eq drop ()
≡𝕃-from-={l1 = x :: xs}{y :: ys} eq drop p rewrite ≡𝕃-from-={l1 = xs} eq drop (&&-snd{eq x y}{=𝕃 eq xs ys} p) | drop x y (&&-fst p) = refl
=𝕃-from-≡ : ∀{ℓ}{A : Set ℓ}{l1 l2 : 𝕃 A} → (eq : A → A → 𝔹) → ((x y : A) → x ≡ y → eq x y ≡ tt) → l1 ≡ l2 → =𝕃 eq l1 l2 ≡ tt
=𝕃-from-≡{l2 = l2} eq rise p rewrite p = =𝕃-refl{l1 = l2} eq rise
multi++-assoc : ∀{ℓ}{A : Set ℓ} → (Ls : 𝕃 (𝕃 A)) → (l0 : 𝕃 A) → (foldr _++_ [] Ls) ++ l0 ≡ (foldr _++_ [] (Ls ++ [ l0 ]))
multi++-assoc [] l' rewrite ++[] l' = refl
multi++-assoc (l :: ls) l' rewrite ++-assoc l (foldr _++_ [] ls) l' | multi++-assoc ls l' = refl
concat-foldr : ∀{ℓ}{A : Set ℓ} → (ls : 𝕃 (𝕃 A)) → (l : 𝕃 A) → concat ls ++ l ≡ foldr _++_ l ls
concat-foldr [] l = refl
concat-foldr (l' :: ls) l rewrite ++-assoc l' (concat ls) l | concat-foldr ls l = refl
--concat-foldr (l' :: (l'' :: ls)) l rewrite ++-assoc l' (concat (l'' :: ls)) l | concat-foldr (l'' :: ls) l = refl
longer-trans : ∀{ℓ}{A : Set ℓ}(l1 l2 l3 : 𝕃 A) →
l1 longer l2 ≡ tt →
l2 longer l3 ≡ tt →
l1 longer l3 ≡ tt
longer-trans [] l2 l3 () q
longer-trans (x :: l1) [] l3 p ()
longer-trans (x :: l1) (x₁ :: l2) [] p q = refl
longer-trans (x :: l1) (x₁ :: l2) (x₂ :: l3) p q = longer-trans l1 l2 l3 p q
filter-idem : ∀{ℓ}{A : Set ℓ}(p : A → 𝔹)(l : 𝕃 A) →
(filter p (filter p l)) ≡ (filter p l)
filter-idem p [] = refl
filter-idem p (x :: l) with keep (p x)
filter-idem p (x :: l) | tt , p' rewrite p' | p' | filter-idem p l = refl
filter-idem p (x :: l) | ff , p' rewrite p' = filter-idem p l
length-filter : ∀{ℓ}{A : Set ℓ}(p : A → 𝔹)(l : 𝕃 A) →
length (filter p l) ≤ length l ≡ tt
length-filter p [] = refl
length-filter p (x :: l) with p x
length-filter p (x :: l) | tt = length-filter p l
length-filter p (x :: l) | ff =
≤-trans{length (filter p l)} (length-filter p l) (≤-suc (length l))
filter-++ : ∀{ℓ}{A : Set ℓ}(p : A → 𝔹)(l1 l2 : 𝕃 A) → filter p (l1 ++ l2) ≡ filter p l1 ++ filter p l2
filter-++ p [] l2 = refl
filter-++ p (x :: l1) l2 with p x
filter-++ p (x :: l1) l2 | tt rewrite (filter-++ p l1 l2) = refl
filter-++ p (x :: l1) l2 | ff rewrite (filter-++ p l1 l2) = refl
remove-++ : ∀{ℓ}{A : Set ℓ}(eq : A → A → 𝔹)(a : A)(l1 l2 : 𝕃 A) →
remove eq a (l1 ++ l2) ≡ remove eq a l1 ++ remove eq a l2
remove-++ eq a l1 l2 = filter-++ (λ x → ~ (eq a x)) l1 l2
::-injective : ∀{ℓ}{A : Set ℓ}{x y : A}{xs ys : 𝕃 A} →
x :: xs ≡ y :: ys → x ≡ y ∧ xs ≡ ys
::-injective refl = refl , refl
concat-++ : ∀{ℓ}{A : Set ℓ}(ls1 ls2 : 𝕃 (𝕃 A)) → concat (ls1 ++ ls2) ≡ (concat ls1) ++ (concat ls2)
concat-++ [] ls2 = refl
concat-++ (l :: ls) ls2 rewrite concat-++ ls ls2 = sym (++-assoc l (concat ls) (concat ls2))
-- This holds as long as we have the equations p₁ and p₂. We know
-- that these equations are consistant to adopt, because they are
-- equivalent up and an isomorphism, and hence, by univalence they are
-- consistent as equations. The respective isomorphisms can be found
-- in products-thms.agda.
all-pred-append : ∀{X : Set}{f : X → Set}{l₁ l₂}
→ (p₁ : ∀{ℓ}{A : Set ℓ} → A ≡ (⊤ ∧ A))
→ (p₂ : ∀{ℓ}{A B C : Set ℓ} → (A ∧ (B ∧ C)) ≡ ((A ∧ B) ∧ C))
→ all-pred f (l₁ ++ l₂) ≡ ((all-pred f l₁) ∧ (all-pred f l₂))
all-pred-append {l₁ = []} {l₂} p₁ p₂ = p₁
all-pred-append {X}{f}{x :: l₁} {l₂} p₁ p₂ rewrite all-pred-append {X}{f}{l₁ = l₁} {l₂} p₁ p₂ = p₂
map-proj-⊎₁ : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (l : 𝕃 A) →
proj-⊎₁ {A = A}{B} (map inj₁ l) ≡ l
map-proj-⊎₁ [] = refl
map-proj-⊎₁ {A = A}{B} (x :: l) rewrite map-proj-⊎₁ {A = A}{B} l = refl
map-proj-⊎₂ : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (l : 𝕃 B) →
proj-⊎₂ {A = A}{B} (map inj₂ l) ≡ l
map-proj-⊎₂ [] = refl
map-proj-⊎₂ {A = A}{B} (x :: l) rewrite map-proj-⊎₂ {A = A}{B} l = refl
map-proj-⊎₂-[] : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (l : 𝕃 A) →
proj-⊎₂ {A = A}{B} (map inj₁ l) ≡ []
map-proj-⊎₂-[] [] = refl
map-proj-⊎₂-[] {A = A}{B} (x :: l) rewrite map-proj-⊎₂-[] {A = A}{B} l = refl
map-proj-⊎₁-[] : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (l : 𝕃 B) →
proj-⊎₁ {A = A}{B} (map inj₂ l) ≡ []
map-proj-⊎₁-[] [] = refl
map-proj-⊎₁-[] {A = A}{B} (x :: l) rewrite map-proj-⊎₁-[] {A = A}{B} l = refl
is-empty-++ : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) → is-empty (l1 ++ l2) ≡ is-empty l1 && is-empty l2
is-empty-++ [] l2 = refl
is-empty-++ (x :: l1) l2 = refl
is-empty-ff-length : ∀{ℓ}{A : Set ℓ}(l : 𝕃 A) → is-empty l ≡ ff → length l =ℕ 0 ≡ ff
is-empty-ff-length [] ()
is-empty-ff-length (x :: l) p = refl
list-all-append : ∀{ℓ}{A : Set ℓ}(p : A → 𝔹)(l l' : 𝕃 A) →
list-all p (l ++ l') ≡ list-all p l && list-all p l'
list-all-append p [] l' = refl
list-all-append p (x :: l) l' rewrite list-all-append p l l' | &&-assoc (p x) (list-all p l) (list-all p l') = refl
| 44.557895
| 171
| 0.504134
|
4ea78719c60db9cccff4c11f29c696acbc46a1f1
| 96
|
agda
|
Agda
|
test/Succeed/Issue481PonderImportMe.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue481PonderImportMe.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue481PonderImportMe.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Issue481PonderBase using (List)
module Issue481PonderImportMe (as bs : List) where
| 24
| 50
| 0.8125
|
7cd6cfda84361c33bacc94e3f6c69ade214e51fa
| 5,332
|
agda
|
Agda
|
Cubical/Experiments/ZCohomology/Benchmarks.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Experiments/ZCohomology/Benchmarks.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Experiments/ZCohomology/Benchmarks.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-
Please do not move this file. Changes should only be made if
necessary.
This file contains benchmarks for the paper:
Synthetic Cohomology Theory in Cubical Agda
Command to run the benchmarks and get timings:
agda -v profile.definitions:10 Benchmarks.agda
This assumes that there is no Benchmarks.agdai file. If there is one,
then it should be removed before the above command is run.
-}
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Experiments.ZCohomology.Benchmarks where
open import Cubical.Foundations.Everything
open import Cubical.Data.Nat
open import Cubical.Data.Bool
open import Cubical.Data.Int
open import Cubical.HITs.Sn
open import Cubical.Algebra.Group
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.ZCohomology.Groups.Wedge
open import Cubical.ZCohomology.Groups.Torus
open import Cubical.ZCohomology.Groups.KleinBottle
open import Cubical.ZCohomology.Groups.WedgeOfSpheres
open import Cubical.ZCohomology.Groups.RP2
open import Cubical.Data.Sigma
open import Cubical.HITs.KleinBottle
open import Cubical.HITs.RPn.Base
open GroupHom
open GroupIso
-- S¹ (everything fast)
module S1-tests where
ϕ : coHom 1 (S₊ 1) → Int
ϕ = fun (map (Hⁿ-Sⁿ≅ℤ 0))
ϕ⁻¹ : Int → coHom 1 (S₊ 1)
ϕ⁻¹ = inv (Hⁿ-Sⁿ≅ℤ 0)
test₁ : ϕ (ϕ⁻¹ 0) ≡ 0 -- 30ms
test₁ = refl
test₂ : ϕ (ϕ⁻¹ 1) ≡ 1 -- <10ms
test₂ = refl
test₃ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 0) ≡ 0 -- <10ms
test₃ = refl
test₄ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 1) ≡ 1 -- 10ms
test₄ = refl
test₅ : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 0) ≡ 1 -- 11ms
test₅ = refl
test₆ : ϕ (ϕ⁻¹ -3 +ₕ ϕ⁻¹ 4) ≡ 1 -- 29ms
test₆ = refl
test₇ : ϕ (ϕ⁻¹ -5 +ₕ ϕ⁻¹ -2) ≡ -7 -- 28ms
test₇ = refl
-- S²
module S2-tests where
ϕ : coHom 2 (S₊ 2) → Int
ϕ = fun (map (Hⁿ-Sⁿ≅ℤ 1))
ϕ⁻¹ : Int → coHom 2 (S₊ 2)
ϕ⁻¹ = inv (Hⁿ-Sⁿ≅ℤ 1)
test₁ : ϕ (ϕ⁻¹ 0) ≡ 0 -- 13ms
test₁ = refl
test₂ : ϕ (ϕ⁻¹ 1) ≡ 1 -- 16ms
test₂ = refl
test₃ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 0) ≡ 0 -- 278ms
test₃ = refl
test₄ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 1) ≡ 1 -- 290ms
test₄ = refl
{-
test₅ : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 0) ≡ 1 -- nope
test₅ = refl
test₆ : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 1) ≡ 2 -- nope
test₆ = refl
test₇ : ϕ (ϕ⁻¹ 2 +ₕ ϕ⁻¹ 4) ≡ 6 -- nope
test₇ = refl
-}
module S1∨S1∨S2-tests₁ where -- everything fast
ϕ : coHom 1 S²⋁S¹⋁S¹ → Int × Int
ϕ = fun (map H¹-S²⋁S¹⋁S¹)
ϕ⁻¹ : Int × Int → coHom 1 S²⋁S¹⋁S¹
ϕ⁻¹ = inv H¹-S²⋁S¹⋁S¹
test₁ : ϕ (ϕ⁻¹ (0 , 0)) ≡ (0 , 0) -- <10ms
test₁ = refl
test₂ : ϕ (ϕ⁻¹ (3 , 1)) ≡ (3 , 1) -- 21ms
test₂ = refl
test₃ : ϕ (ϕ⁻¹ (0 , 0) +ₕ ϕ⁻¹ (0 , 0)) ≡ (0 , 0) -- 15ms
test₃ = refl
test₄ : ϕ (ϕ⁻¹ (0 , 1) +ₕ ϕ⁻¹ (1 , 0)) ≡ (1 , 1) -- 21ms
test₄ = refl
test₅ : ϕ (ϕ⁻¹ (3 , 2) +ₕ ϕ⁻¹ (-1 , 5)) ≡ (2 , 7) -- 47ms
test₅ = refl
module S1∨S1∨S2-tests₂ where
ϕ : coHom 2 S²⋁S¹⋁S¹ → Int
ϕ = fun (map H²-S²⋁S¹⋁S¹)
ϕ⁻¹ : Int → coHom 2 S²⋁S¹⋁S¹
ϕ⁻¹ = inv H²-S²⋁S¹⋁S¹
test₁ : ϕ (ϕ⁻¹ 0) ≡ 0 -- 157ms
test₁ = refl
test₂ : ϕ (ϕ⁻¹ 3) ≡ 3 -- 119ms
test₂ = refl
test₃ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 0) ≡ 0 -- 1,820ms
test₃ = refl
module Torus-test₁ where -- fast
ϕ : coHom 1 (S₊ 1 × S₊ 1) → Int × Int
ϕ = fun (map H¹-T²≅ℤ×ℤ)
ϕ⁻¹ : Int × Int → coHom 1 (S₊ 1 × S₊ 1)
ϕ⁻¹ = inv H¹-T²≅ℤ×ℤ
test₁ : ϕ (ϕ⁻¹ (0 , 0)) ≡ (0 , 0) -- <10ms
test₁ = refl
test₂ : ϕ (ϕ⁻¹ (3 , 1)) ≡ (3 , 1) -- 18ms
test₂ = refl
test₃ : ϕ (ϕ⁻¹ (0 , 0) +ₕ ϕ⁻¹ (0 , 0)) ≡ (0 , 0) -- 15ms
test₃ = refl
test₄ : ϕ (ϕ⁻¹ (0 , 1) +ₕ ϕ⁻¹ (1 , 0)) ≡ (1 , 1) -- 20ms
test₄ = refl
test₅ : ϕ (ϕ⁻¹ (-3 , 2) +ₕ ϕ⁻¹ (-1 , 5)) ≡ (-4 , 7) -- 44ms
test₅ = refl
module Torus-test₂ where
ϕ : coHom 2 (S₊ 1 × S₊ 1) → Int
ϕ = fun (map H²-T²≅ℤ)
ϕ⁻¹ : Int → coHom 2 (S₊ 1 × S₊ 1)
ϕ⁻¹ = inv H²-T²≅ℤ
test₁ : ϕ (ϕ⁻¹ 0) ≡ 0 -- 121ms
test₁ = refl
test₂ : ϕ (ϕ⁻¹ 3) ≡ 3 -- 142ms
test₂ = refl
test₃ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 0) ≡ 0 -- 3,674ms
test₃ = refl
test₄ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 1) ≡ 1 -- 3,772ms
test₄ = refl
{-
test₅ : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 0) ≡ 1 -- nope
test₅ = refl
-}
module Klein-test₁ where -- fast
ϕ : coHom 1 KleinBottle → Int
ϕ = fun (map H¹-𝕂²≅ℤ)
ϕ⁻¹ : Int → coHom 1 KleinBottle
ϕ⁻¹ = inv H¹-𝕂²≅ℤ
test₁ : ϕ (ϕ⁻¹ 0) ≡ 0 -- <10ms
test₁ = refl
test₂ : ϕ (ϕ⁻¹ 3) ≡ 3 -- 12ms
test₂ = refl
test₃ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 0) ≡ 0 -- <10ms
test₃ = refl
test₄ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 1) ≡ 1 -- 11ms
test₄ = refl
test₅ : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 0) ≡ 1 -- 12ms
test₅ = refl
test₆ : ϕ (ϕ⁻¹ -3 +ₕ ϕ⁻¹ 4) ≡ 1 -- 29ms
test₆ = refl
test₇ : ϕ (ϕ⁻¹ -5 +ₕ ϕ⁻¹ -2) ≡ -7 -- 29ms
test₇ = refl
-- The example in the paper:
test : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 2) ≡ 3 -- 15ms
test = refl
module Klein-test₂ where
ϕ : coHom 2 KleinBottle → Bool
ϕ = fun (map H²-𝕂²≅Bool)
ϕ⁻¹ : Bool → coHom 2 KleinBottle
ϕ⁻¹ = inv H²-𝕂²≅Bool
{-
test₀ : ϕ (0ₕ _) ≡ true -- fails already here...
test₀ = refl
-}
module RP2-test₂ where
ϕ : coHom 2 RP² → Bool
ϕ = fun (map H²-RP²≅Bool)
ϕ⁻¹ : Bool → coHom 2 RP²
ϕ⁻¹ = inv H²-RP²≅Bool
test₀ : ϕ (0ₕ _) ≡ true -- 1,210ms (unlike for Klein, this works)
test₀ = refl
{-
test₁ : ϕ (ϕ⁻¹ true) ≡ true -- nope
test₁ = refl
-}
| 20.507692
| 70
| 0.560578
|
3055800aa7ad38106ec0cbeb371dcbcea77c963a
| 1,595
|
agda
|
Agda
|
extra/extra/RewriteWTF.agda
|
krzygorz/plfa.github.io
|
10a3203624f2ea937b3892176db5de825d0c46b4
|
[
"CC-BY-4.0"
] | 1,003
|
2018-07-05T18:15:14.000Z
|
2022-03-27T07:03:28.000Z
|
extra/extra/RewriteWTF.agda
|
krzygorz/plfa.github.io
|
10a3203624f2ea937b3892176db5de825d0c46b4
|
[
"CC-BY-4.0"
] | 323
|
2018-07-05T22:34:34.000Z
|
2022-03-30T07:42:57.000Z
|
extra/extra/RewriteWTF.agda
|
krzygorz/plfa.github.io
|
10a3203624f2ea937b3892176db5de825d0c46b4
|
[
"CC-BY-4.0"
] | 304
|
2018-07-16T18:24:59.000Z
|
2022-03-28T11:35:02.000Z
|
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym; trans; cong)
open Eq.≡-Reasoning
open import Data.Nat using (ℕ; zero; suc; _+_; _*_)
open import Data.Nat.Properties.Simple using (+-suc)
open import Data.Product using (∃; ∃-syntax; _,_)
data even : ℕ → Set
data odd : ℕ → Set
data even where
even-zero : even zero
even-suc : ∀ {n : ℕ} → odd n → even (suc n)
data odd where
odd-suc : ∀ {n : ℕ} → even n → odd (suc n)
lemma : ∀ (m : ℕ) → 2 * suc m ≡ suc (suc (2 * m))
lemma m =
begin
2 * suc m
≡⟨⟩
suc m + (suc m + zero)
≡⟨⟩
suc (m + (suc (m + zero)))
≡⟨ cong suc (+-suc m (m + zero)) ⟩
suc (suc (m + (m + zero)))
≡⟨⟩
suc (suc (2 * m))
∎
∃-even : ∀ {n : ℕ} → even n → ∃[ m ] (2 * m ≡ n)
∃-odd : ∀ {n : ℕ} → odd n → ∃[ m ] (1 + 2 * m ≡ n)
∃-even even-zero = zero , refl
∃-even (even-suc o) with ∃-odd o
... | m , refl = suc m , lemma m
∃-odd (odd-suc e) with ∃-even e
... | m , refl = m , refl
∃-even′ : ∀ {n : ℕ} → even n → ∃[ m ] (n ≡ 2 * m)
∃-odd′ : ∀ {n : ℕ} → odd n → ∃[ m ] (n ≡ 1 + 2 * m)
∃-even′ even-zero = zero , refl
∃-even′ (even-suc o) with ∃-odd′ o
... | m , eqn rewrite eqn | +-suc m (m + 0) = suc m , {!!}
∃-odd′ (odd-suc e) with ∃-even′ e
... | m , eqn rewrite eqn = m , refl
data Even : ℕ → Set where
ev0 : Even zero
ev2 : ∀ {n} → Even n → Even (suc (suc n))
ev-ex : ∀ {n : ℕ} → Even n → ∃[ m ] (2 * m ≡ n)
ev-ex ev0 = (zero , refl)
ev-ex (ev2 ev) with ev-ex ev
... | (m , refl) = (suc m , lemma m)
| 26.147541
| 78
| 0.473354
|
37120dcd9255d4ede41e428d38f223e559bf5474
| 4,548
|
agda
|
Agda
|
src/plfa-code/Decidable.agda
|
chirsz-ever/plfa-code
|
ec5b359a8c22bf5268cae3c36a97e6737c75d5f3
|
[
"MIT"
] | null | null | null |
src/plfa-code/Decidable.agda
|
chirsz-ever/plfa-code
|
ec5b359a8c22bf5268cae3c36a97e6737c75d5f3
|
[
"MIT"
] | null | null | null |
src/plfa-code/Decidable.agda
|
chirsz-ever/plfa-code
|
ec5b359a8c22bf5268cae3c36a97e6737c75d5f3
|
[
"MIT"
] | null | null | null |
module plfa-code.Decidable where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product using (_×_) renaming (_,_ to ⟨_,_⟩)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Relation.Nullary using (¬_)
open import Relation.Nullary.Negation using ()
renaming (contradiction to ¬¬-intro)
open import Data.Unit using (⊤; tt)
open import Data.Empty using (⊥; ⊥-elim)
open import plfa-code.Relations using (_<_; z<s; s<s)
open import plfa-code.Isomorphism using (_⇔_)
data Bool : Set where
true : Bool
false : Bool
open Data.Nat using (_≤_; z≤n; s≤s)
infix 4 _≤ᵇ_
_≤ᵇ_ : ℕ → ℕ → Bool
zero ≤ᵇ n = true
suc m ≤ᵇ zero = false
suc m ≤ᵇ suc n = m ≤ᵇ n
_ : (2 ≤ᵇ 4) ≡ true
_ =
begin
2 ≤ᵇ 4
≡⟨⟩
1 ≤ᵇ 3
≡⟨⟩
0 ≤ᵇ 2
≡⟨⟩
true
∎
_ : (4 ≤ᵇ 2) ≡ false
_ =
begin
4 ≤ᵇ 2
≡⟨⟩
3 ≤ᵇ 1
≡⟨⟩
2 ≤ᵇ 0
≡⟨⟩
false
∎
T : Bool → Set
T true = ⊤
T false = ⊥
T→≡ : ∀ (b : Bool) → T b → b ≡ true
T→≡ true tt = refl
T→≡ false ()
≡→T : ∀ {b : Bool} → b ≡ true → T b
≡→T refl = tt
≤ᵇ→≤ : ∀ (m n : ℕ) → T (m ≤ᵇ n) → m ≤ n
≤ᵇ→≤ zero n tt = z≤n
≤ᵇ→≤ (suc m) zero ()
≤ᵇ→≤ (suc m) (suc n) t = s≤s (≤ᵇ→≤ m n t)
≤→≤ᵇ : ∀ {m n : ℕ} → m ≤ n → T (m ≤ᵇ n)
≤→≤ᵇ z≤n = tt
≤→≤ᵇ (s≤s m≤n) = ≤→≤ᵇ m≤n
data Dec (A : Set) : Set where
yes : A → Dec A
no : ¬ A → Dec A
¬s≤z : ∀ {m : ℕ} → ¬ (suc m ≤ zero)
¬s≤z ()
¬s≤s : ∀ {m n : ℕ} → ¬ (m ≤ n) → ¬ (suc m ≤ suc n)
¬s≤s ¬m≤n (s≤s m≤n) = ¬m≤n m≤n
_≤?_ : ∀ (m n : ℕ) → Dec (m ≤ n)
zero ≤? n = yes z≤n
suc m ≤? zero = no ¬s≤z
suc m ≤? suc n with m ≤? n
... | yes m≤n = yes (s≤s m≤n)
... | no ¬m≤n = no (¬s≤s ¬m≤n)
---------- practice ----------
open Eq using (cong)
_<?_ : ∀ (m n : ℕ) → Dec (m < n)
zero <? zero = no (λ ())
zero <? suc n = yes z<s
suc m <? zero = no (λ ())
suc m <? suc n with m <? n
... | yes m<n = yes (s<s m<n)
... | no ¬m<n = no λ{ (s<s m<n) → ¬m<n m<n}
_≡ℕ?_ : ∀ (m n : ℕ) → Dec (m ≡ n)
zero ≡ℕ? zero = yes refl
zero ≡ℕ? suc n = no (λ ())
suc m ≡ℕ? zero = no (λ ())
suc m ≡ℕ? suc n with m ≡ℕ? n
(suc m ≡ℕ? suc n) | yes m≡n = yes (cong suc m≡n)
(suc m ≡ℕ? suc n) | no ¬m≡n = no λ{ refl → ¬m≡n refl}
------------------------------
_≤?′_ : ∀ (m n : ℕ) → Dec (m ≤ n)
m ≤?′ n with m ≤ᵇ n | ≤ᵇ→≤ m n | ≤→≤ᵇ {m} {n}
... | true | p | _ = yes (p tt)
... | false | _ | ¬p = no ¬p
⌊_⌋ : ∀ {A : Set} → Dec A → Bool
⌊ yes _ ⌋ = true
⌊ no _ ⌋ = false
_≤ᵇ′_ : ℕ → ℕ → Bool
m ≤ᵇ′ n = ⌊ m ≤? n ⌋
toWitness : ∀ {A : Set} {D : Dec A} → T ⌊ D ⌋ → A
toWitness {A} {yes x} tt = x
toWitness {A} {no ¬x} ()
fromWitness : ∀ {A : Set} {D : Dec A} → A → T ⌊ D ⌋
fromWitness {A} {yes x} _ = tt
fromWitness {A} {no ¬x} x = ¬x x
≤ᵇ′→≤ : ∀ {m n : ℕ} → T (m ≤ᵇ′ n) → m ≤ n
≤ᵇ′→≤ = toWitness
≤→≤ᵇ′ : ∀ {m n : ℕ} → m ≤ n → T (m ≤ᵇ′ n)
≤→≤ᵇ′ = fromWitness
infixr 6 _∧_
_∧_ : Bool → Bool → Bool
true ∧ true = true
false ∧ _ = false
_ ∧ false = false
infixr 6 _×-dec_
_×-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A × B)
yes x ×-dec yes y = yes ⟨ x , y ⟩
no ¬x ×-dec _ = no λ{ ⟨ x , y ⟩ → ¬x x}
_ ×-dec no ¬y = no λ{ ⟨ x , y ⟩ → ¬y y}
infixr 5 _∨_
_∨_ : Bool → Bool → Bool
true ∨ _ = true
_ ∨ true = true
false ∨ false = false
infixr 5 _⊎-dec_
_⊎-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A ⊎ B)
yes x ⊎-dec _ = yes (inj₁ x)
_ ⊎-dec yes y = yes (inj₂ y)
no ¬x ⊎-dec no ¬y = no λ{ (inj₁ x) → ¬x x ; (inj₂ y) → ¬y y }
not : Bool → Bool
not true = false
not false = true
¬? : ∀ {A : Set} → Dec A → Dec (¬ A)
¬? (yes x) = no (¬¬-intro x)
¬? (no ¬x) = yes ¬x
_⊃_ : Bool → Bool → Bool
_ ⊃ true = true
false ⊃ _ = true
true ⊃ false = false
_→-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A → B)
_ →-dec yes y = yes (λ _ → y)
no ¬x →-dec _ = yes (λ x → ⊥-elim (¬x x))
yes x →-dec no ¬y = no (λ f → ¬y (f x))
---------- practice ----------
∧-× : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ ∧ ⌊ y ⌋ ≡ ⌊ x ×-dec y ⌋
∧-× (yes x) (yes y) = refl
∧-× (yes x) (no ¬y) = refl
∧-× (no x) _ = refl
-- I think there is a typo, so I write ∨-⊎ instead of the origin ∨-×
∨-⊎ : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ ∨ ⌊ y ⌋ ≡ ⌊ x ⊎-dec y ⌋
∨-⊎ (yes x) _ = refl
∨-⊎ (no ¬x) (yes y) = refl
∨-⊎ (no ¬x) (no ¬y) = refl
not-¬ : ∀ {A : Set} (x : Dec A) → not ⌊ x ⌋ ≡ ⌊ ¬? x ⌋
not-¬ (yes x) = refl
not-¬ (no ¬x) = refl
| 22.854271
| 75
| 0.442832
|
3698e70ec144bae45ba794d74b4cbc40d4e73d05
| 5,509
|
agda
|
Agda
|
Groups/FinitePermutations.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Groups/FinitePermutations.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Groups/FinitePermutations.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Numbers.Naturals.Semiring -- for length
open import Lists.Lists
open import Functions.Definition
--open import Groups.Actions
module Groups.FinitePermutations where
allInsertions : {a : _} {A : Set a} (x : A) (l : List A) → List (List A)
allInsertions x [] = [ x ] :: []
allInsertions x (y :: l) = (x :: (y :: l)) :: (map (λ i → y :: i) (allInsertions x l))
permutations : {a : _} {A : Set a} (l : List A) → List (List A)
permutations [] = [ [] ]
permutations (x :: l) = flatten (map (allInsertions x) (permutations l))
factorial : ℕ → ℕ
factorial zero = 1
factorial (succ n) = (succ n) *N factorial n
factCheck : factorial 5 ≡ 120
factCheck = refl
allInsertionsLength : {a : _} {A : Set a} (x : A) (l : List A) → length (allInsertions x l) ≡ succ (length l)
allInsertionsLength x [] = refl
allInsertionsLength x (y :: l) = applyEquality succ (transitivity (equalityCommutative (lengthMap (allInsertions x l) {f = y ::_})) (allInsertionsLength x l))
allInsertionsLength' : {a : _} {A : Set a} (x : A) (l : List A) → allTrue (λ i → length i ≡ succ (length l)) (allInsertions x l)
allInsertionsLength' x [] = refl ,, record {}
allInsertionsLength' x (y :: l) with allInsertionsLength' x l
... | bl = refl ,, allTrueMap (λ i → length i ≡ succ (succ (length l))) (y ::_) (allInsertions x l) (allTrueExtension (λ z → length z ≡ succ (length l)) ((λ i → length i ≡ succ (succ (length l))) ∘ (y ::_)) (allInsertions x l) (λ {x} → λ p → applyEquality succ p) bl)
permutationsCheck : permutations (3 :: 4 :: []) ≡ (3 :: 4 :: []) :: (4 :: 3 :: []) :: []
permutationsCheck = refl
permsAllSameLength : {a : _} {A : Set a} (l : List A) → allTrue (λ i → length i ≡ length l) (permutations l)
permsAllSameLength [] = refl ,, record {}
permsAllSameLength (x :: l) with permsAllSameLength l
... | bl = allTrueFlatten (λ i → length i ≡ succ (length l)) (map (allInsertions x) (permutations l)) (allTrueMap (allTrue (λ i → length i ≡ succ (length l))) (allInsertions x) (permutations l) (allTrueExtension (λ z → length z ≡ length l) (allTrue (λ i → length i ≡ succ (length l)) ∘ allInsertions x) (permutations l) lemma bl))
where
lemma : {m : List _} → (lenM=lenL : length m ≡ length l) → allTrue (λ i → length i ≡ succ (length l)) (allInsertions x m)
lemma {m} lm=ll rewrite equalityCommutative lm=ll = allInsertionsLength' x m
allTrueEqual : {a b : _} {A : Set a} {B : Set b} (f : A → B) (equalTo : B) (l : List A) → allTrue (λ i → f i ≡ equalTo) l → map f l ≡ replicate (length l) equalTo
allTrueEqual f equalTo [] pr = refl
allTrueEqual f equalTo (x :: l) (fst ,, snd) rewrite fst | allTrueEqual f equalTo l snd = refl
totalReplicate : (l len : ℕ) → fold _+N_ 0 (replicate len l) ≡ l *N len
totalReplicate l zero rewrite multiplicationNIsCommutative l 0 = refl
totalReplicate l (succ len) rewrite totalReplicate l len | multiplicationNIsCommutative l (succ len) = applyEquality (l +N_) (multiplicationNIsCommutative l len)
permsLen : {a : _} {A : Set a} (l : List A) → length (permutations l) ≡ factorial (length l)
permsLen [] = refl
permsLen (x :: l) = transitivity (lengthFlatten (map (allInsertions x) (permutations l))) (transitivity (applyEquality (fold _+N_ 0) (mapMap (permutations l))) (transitivity (applyEquality (fold _+N_ 0) (mapExtension (permutations l) (length ∘ allInsertions x) (succ ∘ length) λ {y} → allInsertionsLength x y)) (transitivity (applyEquality (fold _+N_ 0) lemma) (transitivity (totalReplicate (succ (length l)) (length (permutations l))) ans))))
where
lemma : map (λ a → succ (length a)) (permutations l) ≡ replicate (length (permutations l)) (succ (length l))
lemma = allTrueEqual (λ a → succ (length a)) (succ (length l)) (permutations l) (allTrueExtension (λ z → length z ≡ length l) (λ i → succ (length i) ≡ succ (length l)) (permutations l) (λ pr → applyEquality succ pr) (permsAllSameLength l))
ans : length (permutations l) +N length l *N length (permutations l) ≡ factorial (length l) +N length l *N factorial (length l)
ans rewrite permsLen l = refl
--act : GroupAction (symmetricGroup (symmetricSetoid (reflSetoid (FinSet n))))
--act = ?
{- TODO: show that symmetricGroup acts in the obvious way on permutations FinSet
listElements : {a : _} {A : Set a} (l : List A) → Set
listElements [] = False
listElements (x :: l) = True || listElements l
listElement : {a : _} {A : Set a} {l : List A} (elt : listElements l) → A
listElement {l = []} ()
listElement {l = x :: l} (inl record {}) = x
listElement {l = x :: l} (inr elt) = listElement {l = l} elt
backwardRange : ℕ → List ℕ
backwardRange zero = []
backwardRange (succ n) = n :: backwardRange n
backwardRangeLength : {n : ℕ} → length (backwardRange n) ≡ n
backwardRangeLength {zero} = refl
backwardRangeLength {succ n} rewrite backwardRangeLength {n} = refl
applyPermutation : {n : ℕ} → (f : FinSet n → FinSet n) → listElements (permutations (backwardRange n)) → listElements (permutations (backwardRange n))
applyPermutation {zero} f (inl record {}) = inl (record {})
applyPermutation {zero} f (inr ())
applyPermutation {succ n} f elt = {!!}
finitePermutations : (n : ℕ) → SetoidToSet (symmetricSetoid (reflSetoid (FinSet n))) (listElements (permutations (backwardRange n)))
SetoidToSet.project (finitePermutations n) (sym {f} fBij) = {!!}
SetoidToSet.wellDefined (finitePermutations n) = {!!}
SetoidToSet.surj (finitePermutations n) = {!!}
SetoidToSet.inj (finitePermutations n) = {!!}
-}
| 57.385417
| 443
| 0.669632
|
14cb484c1c4f07368809dde95f9cbfcf085d5857
| 2,129
|
agda
|
Agda
|
src/Selective/Examples/CalculatorProtocol.agda
|
Zalastax/singly-typed-actors
|
ae541df13d069df4eb1464f29fbaa9804aad439f
|
[
"MIT"
] | 1
|
2019-10-29T09:30:26.000Z
|
2019-10-29T09:30:26.000Z
|
src/Selective/Examples/CalculatorProtocol.agda
|
Zalastax/singly-typed-actors
|
ae541df13d069df4eb1464f29fbaa9804aad439f
|
[
"MIT"
] | null | null | null |
src/Selective/Examples/CalculatorProtocol.agda
|
Zalastax/singly-typed-actors
|
ae541df13d069df4eb1464f29fbaa9804aad439f
|
[
"MIT"
] | null | null | null |
module Selective.Examples.CalculatorProtocol where
open import Selective.Libraries.Call2
open import Prelude
open import Debug
open import Data.Nat.Show using (show)
ℕ-ReplyMessage : MessageType
ℕ-ReplyMessage = ValueType UniqueTag ∷ [ ValueType ℕ ]ˡ
ℕ-Reply : InboxShape
ℕ-Reply = [ ℕ-ReplyMessage ]ˡ
ℕ×ℕ→ℕ-Message : MessageType
ℕ×ℕ→ℕ-Message = ValueType UniqueTag ∷ ReferenceType ℕ-Reply ∷ ValueType ℕ ∷ [ ValueType ℕ ]ˡ
Calculate : InboxShape
Calculate = [ ℕ×ℕ→ℕ-Message ]ˡ
CalculateProtocol : ChannelInitiation
CalculateProtocol = record
{ request = Calculate
; response = record {
channel-shape = ℕ-Reply
; all-tagged = (HasTag _) ∷ []
}
; request-tagged = [ HasTag+Ref _ ]ᵃ
}
ℕ×ℕ→ℕ-ci : ChannelInitiation
ℕ×ℕ→ℕ-ci = record {
request = Calculate
; response = record { channel-shape = ℕ-Reply ; all-tagged = (HasTag _) ∷ [] }
; request-tagged = (HasTag+Ref _) ∷ [] }
Calculator : InboxShape
Calculator = ℕ×ℕ→ℕ-Message ∷ [ ℕ×ℕ→ℕ-Message ]ˡ
TestBox : InboxShape
TestBox = ℕ-Reply
calculator-test-actor : ∀{i} →
∞ActorM (↑ i) Calculator (Lift (lsuc lzero) ⊤) [] (λ _ → []) →
∞ActorM i TestBox (Lift (lsuc lzero) ℕ) [] (λ _ → [])
calculator-test-actor calculator-actor = do
spawn∞ calculator-actor
Msg Z (_ ∷ n ∷ []) ← call CalculateProtocol (record {
var = Z
; chosen-field = Z
; fields = lift 32 ∷ [ lift 10 ]ᵃ
; session = record {
can-request = [ Z ]ᵐ -- Pick add method
; response-session = record {
can-receive = [ Z ]ᵐ
; tag = 0
}
}
})
where
Msg (S ()) _
Msg Z (_ ∷ m ∷ []) ← debug (show n) (call CalculateProtocol (record {
var = Z
; chosen-field = Z
; fields = lift n ∷ [ lift 10 ]ᵃ
; session = record {
can-request = [ S Z ]ᵐ -- Pick multiply method
; response-session = record {
can-receive = [ Z ]ᵐ
; tag = 1
}
}
}))
where
Msg (S ()) _
debug (show m) (strengthen [])
return m
| 27.294872
| 92
| 0.565054
|
4ee1c791b7ad13a60593407b04d130e0ebac82f9
| 8,231
|
agda
|
Agda
|
src/Categories/NaturalTransformation/Dinatural.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/NaturalTransformation/Dinatural.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/NaturalTransformation/Dinatural.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Categories.NaturalTransformation.Dinatural where
open import Level
open import Data.Product
open import Relation.Binary using (Rel; IsEquivalence; Setoid)
open import Categories.Category
open import Categories.NaturalTransformation as NT hiding (_∘ʳ_)
open import Categories.Functor
open import Categories.Functor.Construction.Constant
open import Categories.Functor.Bifunctor
open import Categories.Category.Product
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e : Level
C D E : Category o ℓ e
record DinaturalTransformation (F G : Bifunctor (Category.op C) C D) : Set (levelOfTerm F) where
eta-equality
private
module C = Category C
module D = Category D
module F = Functor F
module G = Functor G
open D hiding (op)
open Commutation
field
α : ∀ X → D [ F.F₀ (X , X) , G.F₀ (X , X) ]
commute : ∀ {X Y} (f : C [ X , Y ]) →
[ F.F₀ (Y , X) ⇒ G.F₀ (X , Y) ]⟨
F.F₁ (f , C.id) ⇒⟨ F.F₀ (X , X) ⟩
α X ⇒⟨ G.F₀ (X , X) ⟩
G.F₁ (C.id , f)
≈ F.F₁ (C.id , f) ⇒⟨ F.F₀ (Y , Y) ⟩
α Y ⇒⟨ G.F₀ (Y , Y) ⟩
G.F₁ (f , C.id)
⟩
-- We add this extra proof, because, again, we want to ensure the opposite of the
-- opposite of dinatural transformation is definitionally equal to itself.
op-commute : ∀ {X Y} (f : C [ X , Y ]) →
[ F.F₀ (Y , X) ⇒ G.F₀ (X , Y) ]⟨
F.F₁ (C.id , f) ⇒⟨ F.F₀ (Y , Y) ⟩
(α Y ⇒⟨ G.F₀ (Y , Y) ⟩
G.F₁ (f , C.id))
≈ F.F₁ (f , C.id) ⇒⟨ F.F₀ (X , X) ⟩
(α X ⇒⟨ G.F₀ (X , X) ⟩
G.F₁ (C.id , f))
⟩
op : DinaturalTransformation G.op F.op
op = record
{ α = α
; commute = op-commute
; op-commute = commute
}
-- to reduce the burden of constructing a DinaturalTransformation, we introduce
-- another helper.
record DTHelper (F G : Bifunctor (Category.op C) C D) : Set (levelOfTerm F) where
private
module C = Category C
module D = Category D
module F = Functor F
module G = Functor G
open D hiding (op)
open Commutation
field
α : ∀ X → D [ F.F₀ (X , X) , G.F₀ (X , X) ]
commute : ∀ {X Y} (f : C [ X , Y ]) →
[ F.F₀ (Y , X) ⇒ G.F₀ (X , Y) ]⟨
F.F₁ (f , C.id) ⇒⟨ F.F₀ (X , X) ⟩
α X ⇒⟨ G.F₀ (X , X) ⟩
G.F₁ (C.id , f)
≈ F.F₁ (C.id , f) ⇒⟨ F.F₀ (Y , Y) ⟩
α Y ⇒⟨ G.F₀ (Y , Y) ⟩
G.F₁ (f , C.id)
⟩
dtHelper : ∀ {F G : Bifunctor (Category.op C) C D} → DTHelper F G → DinaturalTransformation F G
dtHelper {D = D} θ = record
{ α = α
; commute = commute
; op-commute = λ f → assoc ○ ⟺ (commute f) ○ sym-assoc
}
where open DTHelper θ
open Category D
open HomReasoning
module _ {F G H : Bifunctor (Category.op C) C D} where
private
module C = Category C
open Category D
open HomReasoning
open Functor
open MR D
infixr 9 _<∘_
infixl 9 _∘>_
_<∘_ : NaturalTransformation G H → DinaturalTransformation F G → DinaturalTransformation F H
θ <∘ β = dtHelper record
{ α = λ X → η (X , X) ∘ α X
; commute = λ {X Y} f → begin
F₁ H (C.id , f) ∘ (η (X , X) ∘ α X) ∘ F₁ F (f , C.id) ≈˘⟨ pushˡ (pushˡ (θ.commute (C.id , f))) ⟩
((η (X , Y) ∘ F₁ G (C.id , f)) ∘ α X) ∘ F₁ F (f , C.id) ≈⟨ assoc ○ pullʳ (β.commute f) ⟩
η (X , Y) ∘ F₁ G (f , C.id) ∘ α Y ∘ F₁ F (C.id , f) ≈⟨ pullˡ (θ.commute (f , C.id)) ○ pullʳ sym-assoc ⟩
F₁ H (f , C.id) ∘ (η (Y , Y) ∘ α Y) ∘ F₁ F (C.id , f) ∎
}
where module θ = NaturalTransformation θ
module β = DinaturalTransformation β
open θ
open β
_∘>_ : DinaturalTransformation G H → NaturalTransformation F G → DinaturalTransformation F H
β ∘> θ = dtHelper record
{ α = λ X → α X ∘ η (X , X)
; commute = λ {X Y} f → begin
F₁ H (C.id , f) ∘ (α X ∘ η (X , X)) ∘ F₁ F (f , C.id) ≈⟨ refl⟩∘⟨ pullʳ (θ.commute (f , C.id)) ⟩
F₁ H (C.id , f) ∘ α X ∘ F₁ G (f , C.id) ∘ η (Y , X) ≈⟨ ∘-resp-≈ʳ sym-assoc ○ sym-assoc ⟩
(F₁ H (C.id , f) ∘ α X ∘ F₁ G (f , C.id)) ∘ η (Y , X) ≈⟨ β.commute f ⟩∘⟨refl ⟩
(F₁ H (f , C.id) ∘ α Y ∘ F₁ G (C.id , f)) ∘ η (Y , X) ≈˘⟨ pushʳ (assoc ○ pushʳ (θ.commute (C.id , f))) ⟩
F₁ H (f , C.id) ∘ (α Y ∘ η (Y , Y)) ∘ F₁ F (C.id , f) ∎
}
where module θ = NaturalTransformation θ
module β = DinaturalTransformation β
open θ
open β
module _ {F G : Bifunctor (Category.op C) C D} where
private
module C = Category C
open Category D
open HomReasoning
open Functor
open MR D
infixl 9 _∘ʳ_
_∘ʳ_ : ∀ {E : Category o ℓ e} →
DinaturalTransformation F G → (K : Functor E C) → DinaturalTransformation (F ∘F ((Functor.op K) ⁂ K)) (G ∘F ((Functor.op K) ⁂ K))
_∘ʳ_ {E = E} β K = dtHelper record
{ α = λ X → α (F₀ K X)
; commute = λ {X Y} f → begin
F₁ G (F₁ K E.id , F₁ K f) ∘ α (F₀ K X) ∘ F₁ F (F₁ K f , F₁ K E.id)
≈⟨ F-resp-≈ G (identity K , C.Equiv.refl) ⟩∘⟨ refl ⟩∘⟨ F-resp-≈ F (C.Equiv.refl , identity K) ⟩
F₁ G (C.id , F₁ K f) ∘ α (F₀ K X) ∘ F₁ F (F₁ K f , C.id)
≈⟨ commute (F₁ K f) ⟩
F₁ G (F₁ K f , C.id) ∘ α (F₀ K Y) ∘ F₁ F (C.id , F₁ K f)
≈˘⟨ F-resp-≈ G (C.Equiv.refl , identity K) ⟩∘⟨ refl ⟩∘⟨ F-resp-≈ F (identity K , C.Equiv.refl) ⟩
F₁ G (F₁ K f , F₁ K E.id) ∘ α (F₀ K Y) ∘ F₁ F (F₁ K E.id , F₁ K f)
∎
}
where module β = DinaturalTransformation β
module E = Category E
open β
infix 4 _≃_
_≃_ : Rel (DinaturalTransformation F G) _
β ≃ δ = ∀ {X} → α β X ≈ α δ X
where open DinaturalTransformation
≃-isEquivalence : IsEquivalence _≃_
≃-isEquivalence = record
{ refl = refl
; sym = λ eq → sym eq
; trans = λ eq eq′ → trans eq eq′
}
≃-setoid : Setoid _ _
≃-setoid = record
{ Carrier = DinaturalTransformation F G
; _≈_ = _≃_
; isEquivalence = ≃-isEquivalence
}
-- for convenience, the following are some helpers for the cases
-- in which the bifunctor on the right is extranatural.
Extranaturalʳ : ∀ {C : Category o ℓ e} → Category.Obj D → (F : Bifunctor (Category.op C) C D) → Set _
Extranaturalʳ A F = DinaturalTransformation (const A) F
Extranaturalˡ : ∀ {C : Category o ℓ e} → (F : Bifunctor (Category.op C) C D) → Category.Obj D → Set _
Extranaturalˡ F A = DinaturalTransformation F (const A)
module _ {F : Bifunctor (Category.op C) C D} where
open Category D
private
module C = Category C
variable
A : Obj
X Y : C.Obj
f : X C.⇒ Y
open Functor F
open HomReasoning
open MR D
extranaturalʳ : (a : ∀ X → A ⇒ F₀ (X , X)) →
(∀ {X X′ f} → F₁ (C.id , f) ∘ a X ≈ F₁ (f , C.id) ∘ a X′) →
Extranaturalʳ A F
extranaturalʳ a comm = dtHelper record
{ α = a
; commute = λ f → ∘-resp-≈ʳ identityʳ ○ comm ○ ∘-resp-≈ʳ (⟺ identityʳ)
}
open DinaturalTransformation
extranatural-commʳ : (β : DinaturalTransformation (const A) F) →
F₁ (C.id , f) ∘ α β X ≈ F₁ (f , C.id) ∘ α β Y
extranatural-commʳ {f = f} β = ∘-resp-≈ʳ (⟺ identityʳ) ○ commute β f ○ ∘-resp-≈ʳ identityʳ
-- the dual case, the bifunctor on the left is extranatural.
extranaturalˡ : (a : ∀ X → F₀ (X , X) ⇒ A) →
(∀ {X X′ f} → a X ∘ F₁ (f , C.id) ≈ a X′ ∘ F₁ (C.id , f)) →
Extranaturalˡ F A
extranaturalˡ a comm = dtHelper record
{ α = a
; commute = λ f → pullˡ identityˡ ○ comm ○ ⟺ (pullˡ identityˡ)
}
extranatural-commˡ : (β : DinaturalTransformation F (const A)) →
α β X ∘ F₁ (f , C.id) ≈ α β Y ∘ F₁ (C.id , f)
extranatural-commˡ {f = f} β = ⟺ (pullˡ identityˡ) ○ commute β f ○ pullˡ identityˡ
| 35.632035
| 140
| 0.505163
|
2199796768a36600c51971065d1ef153553f957e
| 17,074
|
agda
|
Agda
|
Cubical/Categories/Presheaf/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Presheaf/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Presheaf/Properties.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Categories.Presheaf.Properties where
open import Cubical.Categories.Category
open import Cubical.Categories.NaturalTransformation
open import Cubical.Categories.Instances.Sets
open import Cubical.Categories.Instances.Functors
open import Cubical.Categories.Functor
open import Cubical.Categories.Presheaf.Base
open import Cubical.Categories.Equivalence
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv using (fiber)
open import Cubical.Data.Sigma
import Cubical.Categories.Morphism as Morphism
import Cubical.Categories.Constructions.Slice as Slice
import Cubical.Categories.Constructions.Elements as Elements
import Cubical.Functions.Fibration as Fibration
private
variable
ℓ ℓ' : Level
e e' : Level
-- (PreShv C) / F ≃ᶜ PreShv (∫ᴾ F)
module _ (C : Precategory ℓ ℓ') (F : Functor (C ^op) (SET ℓ)) where
open Precategory
open Functor
open _≃ᶜ_
open isEquivalence
open NatTrans
open NatIso
open Slice (PreShv C) F ⦃ isC = isCatPreShv {C = C} ⦄
open Elements {C = C}
open Fibration.ForSets
-- specific case of fiber under natural transformation
fibersEqIfRepsEqNatTrans : ∀ {A} (ϕ : A ⇒ F) {c x x'} {px : x ≡ x'} {a' : fiber (ϕ ⟦ c ⟧) x} {b' : fiber (ϕ ⟦ c ⟧) x'}
→ fst a' ≡ fst b'
→ PathP (λ i → fiber (ϕ ⟦ c ⟧) (px i)) a' b'
fibersEqIfRepsEqNatTrans ϕ {c} {x} {x'} {px} {a , fiba} {b , fibb} p
= fibersEqIfRepsEq {isSetB = snd (F ⟅ c ⟆)} (ϕ ⟦ c ⟧) p
-- ========================================
-- K : Slice → PreShv
-- ========================================
-- action on (slice) objects
K-ob : (s : SliceCat .ob) → (PreShv (∫ᴾ F) .ob)
-- we take (c , x) to the fiber in A of ϕ over x
K-ob (sliceob {A} ϕ) .F-ob (c , x)
= (fiber (ϕ ⟦ c ⟧) x)
, isOfHLevelΣ 2 (snd (A ⟅ c ⟆)) λ _ → isSet→isGroupoid (snd (F ⟅ c ⟆)) _ _
-- for morphisms, we just apply A ⟪ h ⟫ (plus equality proof)
K-ob (sliceob {A} ϕ) .F-hom {d , y} {c , x} (h , com) (b , eq)
= ((A ⟪ h ⟫) b)
, ((ϕ ⟦ c ⟧) ((A ⟪ h ⟫) b)
≡[ i ]⟨ (ϕ .N-hom h) i b ⟩
(F ⟪ h ⟫) ((ϕ ⟦ d ⟧) b)
≡[ i ]⟨ (F ⟪ h ⟫) (eq i) ⟩
(F ⟪ h ⟫) y
≡⟨ sym com ⟩
x
∎)
-- functoriality follows from functoriality of A
K-ob (sliceob {A} ϕ) .F-id {x = (c , x)}
= funExt λ { (a , fibp)
→ fibersEqIfRepsEqNatTrans ϕ (λ i → A .F-id i a) }
K-ob (sliceob {A} ϕ) .F-seq {x = (c , x)} {(d , y)} {(e , z)} (f' , eq1) (g' , eq2)
= funExt λ { ( a , fibp )
→ fibersEqIfRepsEqNatTrans ϕ (λ i → (A .F-seq f' g') i a) }
-- action on morphisms (in this case, natural transformation)
K-hom : {sA sB : SliceCat .ob}
→ (ε : SliceCat [ sA , sB ])
→ (K-ob sA) ⇒ (K-ob sB)
K-hom {sA = s1@(sliceob {A} ϕ)} {s2@(sliceob {B} ψ)} (slicehom ε com) = natTrans η-ob (λ h → funExt (η-hom h))
where
P = K-ob s1
Q = K-ob s2
-- just apply the natural transformation (ε) we're given
-- this ensures that we stay in the fiber over x due to the commutativity given by slicenesss
η-ob : (el : (∫ᴾ F) .ob) → (fst (P ⟅ el ⟆) → fst (Q ⟅ el ⟆) )
η-ob (c , x) (a , ϕa≡x) = ((ε ⟦ c ⟧) a) , εψ≡ϕ ∙ ϕa≡x
where
εψ≡ϕ : (ψ ⟦ c ⟧) ((ε ⟦ c ⟧) a) ≡ (ϕ ⟦ c ⟧) a
εψ≡ϕ i = ((com i) ⟦ c ⟧) a
η-hom : ∀ {el1 el2} (h : (∫ᴾ F) [ el1 , el2 ]) (ae : fst (P ⟅ el2 ⟆)) → η-ob el1 ((P ⟪ h ⟫) ae) ≡ (Q ⟪ h ⟫) (η-ob el2 ae)
η-hom {el1 = (c , x)} {d , y} (h , eqh) (a , eqa)
= fibersEqIfRepsEqNatTrans ψ (λ i → ε .N-hom h i a)
K : Functor SliceCat (PreShv (∫ᴾ F))
K .F-ob = K-ob
K .F-hom = K-hom
K .F-id = makeNatTransPath
(funExt λ cx@(c , x)
→ funExt λ aeq@(a , eq)
→ fibersEqIfRepsEq {isSetB = snd (F ⟅ c ⟆)} _ refl)
K .F-seq (slicehom α eqa) (slicehom β eqb)
= makeNatTransPath
(funExt λ cx@(c , x)
→ funExt λ aeq@(a , eq)
→ fibersEqIfRepsEq {isSetB = snd (F ⟅ c ⟆)} _ refl)
-- ========================================
-- L : PreShv → Slice
-- ========================================
-- action on objects (presheaves)
L-ob : (P : PreShv (∫ᴾ F) .ob)
→ SliceCat .ob
L-ob P = sliceob {S-ob = L-ob-ob} L-ob-hom
where
-- sends c to the disjoint union of all the images under P
LF-ob : (c : C .ob) → (SET _) .ob
LF-ob c = (Σ[ x ∈ fst (F ⟅ c ⟆) ] fst (P ⟅ c , x ⟆)) , isSetΣ (snd (F ⟅ c ⟆)) (λ x → snd (P ⟅ c , x ⟆))
-- defines a function piecewise over the fibers by applying P
LF-hom : ∀ {x y}
→ (f : C [ y , x ])
→ (SET _) [ LF-ob x , LF-ob y ]
LF-hom {x = c} {d} f (x , a) = ((F ⟪ f ⟫) x) , (P ⟪ f , refl ⟫) a
L-ob-ob : Functor (C ^op) (SET _)
L-ob-ob .F-ob = LF-ob
L-ob-ob .F-hom = LF-hom
L-ob-ob .F-id {x = c}
= funExt idFunExt
where
idFunExt : ∀ (un : fst (LF-ob c))
→ (LF-hom (C .id c) un) ≡ un
idFunExt (x , X) = ΣPathP (leftEq , rightEq)
where
leftEq : (F ⟪ C .id c ⟫) x ≡ x
leftEq i = F .F-id i x
rightEq : PathP (λ i → fst (P ⟅ c , leftEq i ⟆))
((P ⟪ C .id c , refl ⟫) X) X
rightEq = left ▷ right
where
-- the id morphism in (∫ᴾ F)
∫id = C .id c , sym (funExt⁻ (F .F-id) x ∙ refl)
-- functoriality of P gives us close to what we want
right : (P ⟪ ∫id ⟫) X ≡ X
right i = P .F-id i X
-- but need to do more work to show that (C .id c , refl) ≡ ∫id
left : PathP (λ i → fst (P ⟅ c , leftEq i ⟆))
((P ⟪ C .id c , refl ⟫) X)
((P ⟪ ∫id ⟫) X)
left i = (P ⟪ ∫ᴾhomEq {F = F} (C .id c , refl) ∫id (λ i → (c , leftEq i)) refl refl i ⟫) X
L-ob-ob .F-seq {x = c} {d} {e} f g
= funExt seqFunEq
where
seqFunEq : ∀ (un : fst (LF-ob c))
→ (LF-hom (g ⋆⟨ C ⟩ f) un) ≡ (LF-hom g) (LF-hom f un)
seqFunEq un@(x , X) = ΣPathP (leftEq , rightEq)
where
-- the left component is comparing the action of F on x
-- equality follows from functoriality of F
-- leftEq : fst (LF-hom (g ⋆⟨ C ⟩ f) un) ≡ fst ((LF-hom g) (LF-hom f un))
leftEq : (F ⟪ g ⋆⟨ C ⟩ f ⟫) x ≡ (F ⟪ g ⟫) ((F ⟪ f ⟫) x)
leftEq i = F .F-seq f g i x
-- on the right, equality also follows from functoriality of P
-- but it's more complicated because of heterogeneity
-- since leftEq is not a definitional equality
rightEq : PathP (λ i → fst (P ⟅ e , leftEq i ⟆))
((P ⟪ g ⋆⟨ C ⟩ f , refl ⟫) X)
((P ⟪ g , refl ⟫) ((P ⟪ f , refl ⟫) X))
rightEq = left ▷ right
where
-- functoriality of P only gets us to this weird composition on the left
right : (P ⟪ (g , refl) ⋆⟨ (∫ᴾ F) ⟩ (f , refl) ⟫) X ≡ (P ⟪ g , refl ⟫) ((P ⟪ f , refl ⟫) X)
right i = P .F-seq (f , refl) (g , refl) i X
-- so we need to show that this composition is actually equal to the one we want
left : PathP (λ i → fst (P ⟅ e , leftEq i ⟆))
((P ⟪ g ⋆⟨ C ⟩ f , refl ⟫) X)
((P ⟪ (g , refl) ⋆⟨ (∫ᴾ F) ⟩ (f , refl) ⟫) X)
left i = (P ⟪ ∫ᴾhomEq {F = F} (g ⋆⟨ C ⟩ f , refl) ((g , refl) ⋆⟨ (∫ᴾ F) ⟩ (f , refl)) (λ i → (e , leftEq i)) refl refl i ⟫) X
L-ob-hom : L-ob-ob ⇒ F
L-ob-hom .N-ob c (x , _) = x
L-ob-hom .N-hom f = funExt λ (x , _) → refl
-- action on morphisms (aka natural transformations between presheaves)
-- is essentially the identity (plus equality proofs for naturality and slice commutativity)
L-hom : ∀ {P Q} → PreShv (∫ᴾ F) [ P , Q ] →
SliceCat [ L-ob P , L-ob Q ]
L-hom {P} {Q} η = slicehom arr com
where
A = S-ob (L-ob P)
ϕ = S-arr (L-ob P)
B = S-ob (L-ob Q)
ψ = S-arr (L-ob Q)
arr : A ⇒ B
arr .N-ob c (x , X) = x , ((η ⟦ c , x ⟧) X)
arr .N-hom {c} {d} f = funExt natu
where
natuType : fst (A ⟅ c ⟆) → Type _
natuType xX@(x , X) = ((F ⟪ f ⟫) x , (η ⟦ d , (F ⟪ f ⟫) x ⟧) ((P ⟪ f , refl ⟫) X)) ≡ ((F ⟪ f ⟫) x , (Q ⟪ f , refl ⟫) ((η ⟦ c , x ⟧) X))
natu : ∀ (xX : fst (A ⟅ c ⟆)) → natuType xX
natu (x , X) = ΣPathP (refl , λ i → (η .N-hom (f , refl) i) X)
com : arr ⋆⟨ PreShv C ⟩ ψ ≡ ϕ
com = makeNatTransPath (funExt comFunExt)
where
comFunExt : ∀ (c : C .ob)
→ (arr ●ᵛ ψ) ⟦ c ⟧ ≡ ϕ ⟦ c ⟧
comFunExt c = funExt λ x → refl
L : Functor (PreShv (∫ᴾ F)) SliceCat
L .F-ob = L-ob
L .F-hom = L-hom
L .F-id {cx} = SliceHom-≡-intro' (makeNatTransPath (funExt λ c → refl))
L .F-seq {cx} {dy} P Q = SliceHom-≡-intro' (makeNatTransPath (funExt λ c → refl))
-- ========================================
-- η : 𝟙 ≅ LK
-- ========================================
module _ where
open Iso
open Morphism renaming (isIso to isIsoC)
-- the iso we need
-- a type is isomorphic to the disjoint union of all its fibers
typeSectionIso : ∀ {A B : Type ℓ} {isSetB : isSet B} → (ϕ : A → B)
→ Iso A (Σ[ b ∈ B ] fiber ϕ b)
typeSectionIso ϕ .fun a = (ϕ a) , (a , refl)
typeSectionIso ϕ .inv (b , (a , eq)) = a
typeSectionIso {isSetB = isSetB} ϕ .rightInv (b , (a , eq))
= ΣPathP (eq
, ΣPathP (refl
, isOfHLevel→isOfHLevelDep 1 (λ b' → isSetB _ _) refl eq eq))
typeSectionIso ϕ .leftInv a = refl
-- the natural transformation
-- just applies typeSectionIso
ηTrans : 𝟙⟨ SliceCat ⟩ ⇒ (L ∘F K)
ηTrans .N-ob sob@(sliceob {A} ϕ) = slicehom A⇒LK comm
where
LKA = S-ob (L ⟅ K ⟅ sob ⟆ ⟆)
ψ = S-arr (L ⟅ K ⟅ sob ⟆ ⟆)
A⇒LK : A ⇒ LKA
A⇒LK .N-ob c = typeSectionIso {isSetB = snd (F ⟅ c ⟆)} (ϕ ⟦ c ⟧) .fun
A⇒LK .N-hom {c} {d} f = funExt homFunExt
where
homFunExt : (x : fst (A ⟅ c ⟆))
→ (((ϕ ⟦ d ⟧) ((A ⟪ f ⟫) x)) , ((A ⟪ f ⟫) x , refl)) ≡ ((F ⟪ f ⟫) ((ϕ ⟦ c ⟧) x) , (A ⟪ f ⟫) x , _)
homFunExt x = ΣPathP ((λ i → (ϕ .N-hom f i) x) , fibersEqIfRepsEqNatTrans ϕ refl)
comm : (A⇒LK) ●ᵛ ψ ≡ ϕ
comm = makeNatTransPath (funExt λ x → refl)
ηTrans .N-hom {sliceob {A} α} {sliceob {B} β} (slicehom ϕ eq)
= SliceHom-≡-intro' (makeNatTransPath (funExt (λ c → funExt λ a → natFunExt c a)))
where
natFunExt : ∀ (c : C .ob) (a : fst (A ⟅ c ⟆))
→ ((β ⟦ c ⟧) ((ϕ ⟦ c ⟧) a) , (ϕ ⟦ c ⟧) a , _) ≡ ((α ⟦ c ⟧) a , (ϕ ⟦ c ⟧) a , _)
natFunExt c a = ΣPathP ((λ i → ((eq i) ⟦ c ⟧) a) , fibersEqIfRepsEqNatTrans β refl)
-- isomorphism follows from typeSectionIso
ηIso : ∀ (sob : SliceCat .ob)
→ isIsoC {C = SliceCat} (ηTrans ⟦ sob ⟧)
ηIso sob@(sliceob ϕ) = sliceIso _ _ (FUNCTORIso _ _ _ isIsoCf)
where
isIsoCf : ∀ (c : C .ob)
→ isIsoC (ηTrans .N-ob sob .S-hom ⟦ c ⟧)
isIsoCf c = CatIso→isIso (Iso→CatIso (typeSectionIso {isSetB = snd (F ⟅ c ⟆)} (ϕ ⟦ c ⟧)))
-- ========================================
-- ε : KL ≅ 𝟙
-- ========================================
module _ where
open Iso
open Morphism renaming (isIso to isIsoC)
-- the iso we deserve
-- says that a type family at x is isomorphic to the fiber over x of that type family packaged up
typeFiberIso : ∀ {ℓ ℓ'} {A : Type ℓ} {isSetA : isSet A} {x} (B : A → Type ℓ')
→ Iso (B x) (fiber {A = Σ[ a ∈ A ] B a} (λ (x , _) → x) x)
typeFiberIso {x = x} _ .fun b = (x , b) , refl
typeFiberIso _ .inv ((a , b) , eq) = subst _ eq b
typeFiberIso {isSetA = isSetA} {x = x} B .rightInv ((a , b) , eq)
= fibersEqIfRepsEq {isSetB = isSetA} (λ (x , _) → x) (ΣPathP (sym eq , symP (transport-filler (λ i → B (eq i)) b)))
typeFiberIso {x = x} _ .leftInv b = sym (transport-filler refl b)
-- the natural isomorphism
-- applies typeFiberIso (inv)
εTrans : (K ∘F L) ⇒ 𝟙⟨ PreShv (∫ᴾ F) ⟩
εTrans .N-ob P = natTrans γ-ob (λ f → funExt (λ a → γ-homFunExt f a))
where
KLP = K ⟅ L ⟅ P ⟆ ⟆
γ-ob : (el : (∫ᴾ F) .ob)
→ (fst (KLP ⟅ el ⟆) → fst (P ⟅ el ⟆) )
γ-ob el@(c , _) = typeFiberIso {isSetA = snd (F ⟅ c ⟆)} (λ x → fst (P ⟅ c , x ⟆)) .inv
-- naturality
-- the annoying part is all the substs
γ-homFunExt : ∀ {el2 el1} → (f' : (∫ᴾ F) [ el2 , el1 ])
→ (∀ (a : fst (KLP ⟅ el1 ⟆)) → γ-ob el2 ((KLP ⟪ f' ⟫) a) ≡ (P ⟪ f' ⟫) (γ-ob el1 a))
γ-homFunExt {d , y} {c , x} f'@(f , comm) a@((x' , X') , eq) i
= comp (λ j → fst (P ⟅ d , eq' j ⟆)) (λ j → λ { (i = i0) → left j
; (i = i1) → right j }) ((P ⟪ f , refl ⟫) X')
where
-- fiber equality proof that we get from an application of KLP
eq' = snd ((KLP ⟪ f' ⟫) a)
-- top right of the commuting diagram
-- "remove" the subst from the inside
right : PathP (λ i → fst (P ⟅ d , eq' i ⟆)) ((P ⟪ f , refl ⟫) X') ((P ⟪ f , comm ⟫) (subst _ eq X'))
right i = (P ⟪ f , refl≡comm i ⟫) (X'≡subst i)
where
refl≡comm : PathP (λ i → (eq' i) ≡ (F ⟪ f ⟫) (eq i)) refl comm
refl≡comm = isOfHLevel→isOfHLevelDep 1 (λ (v , w) → snd (F ⟅ d ⟆) v ((F ⟪ f ⟫) w)) refl comm λ i → (eq' i , eq i)
X'≡subst : PathP (λ i → fst (P ⟅ c , eq i ⟆)) X' (subst _ eq X')
X'≡subst = transport-filler (λ i → fst (P ⟅ c , eq i ⟆)) X'
-- bottom left of the commuting diagram
-- "remove" the subst from the outside
left : PathP (λ i → fst (P ⟅ d , eq' i ⟆)) ((P ⟪ f , refl ⟫) X') (subst (λ v → fst (P ⟅ d , v ⟆)) eq' ((P ⟪ f , refl ⟫) X'))
left = transport-filler (λ i → fst (P ⟅ d , eq' i ⟆)) ((P ⟪ f , refl ⟫) X')
εTrans .N-hom {P} {Q} α = makeNatTransPath (funExt λ cx → funExt λ xX' → ε-homFunExt cx xX')
where
KLP = K ⟅ L ⟅ P ⟆ ⟆
-- naturality of the above construction applies a similar argument as in `γ-homFunExt`
ε-homFunExt : ∀ (cx@(c , x) : (∫ᴾ F) .ob) (xX'@((x' , X') , eq) : fst (KLP ⟅ cx ⟆))
→ subst (λ v → fst (Q ⟅ c , v ⟆)) (snd ((K ⟪ L ⟪ α ⟫ ⟫ ⟦ cx ⟧) xX')) ((α ⟦ c , x' ⟧) X')
≡ (α ⟦ c , x ⟧) (subst _ eq X')
ε-homFunExt cx@(c , x) xX'@((x' , X') , eq) i
= comp (λ j → fst (Q ⟅ c , eq j ⟆)) (λ j → λ { (i = i0) → left j
; (i = i1) → right j }) ((α ⟦ c , x' ⟧) X')
where
eq' : x' ≡ x
eq' = snd ((K ⟪ L ⟪ α ⟫ ⟫ ⟦ cx ⟧) xX')
right : PathP (λ i → fst (Q ⟅ c , eq i ⟆)) ((α ⟦ c , x' ⟧) X') ((α ⟦ c , x ⟧) (subst _ eq X'))
right i = (α ⟦ c , eq i ⟧) (X'≡subst i)
where
-- this is exactly the same as the one from before, can refactor?
X'≡subst : PathP (λ i → fst (P ⟅ c , eq i ⟆)) X' (subst _ eq X')
X'≡subst = transport-filler _ _
-- extracted out type since need to use in in 'left' body as well
leftTy : (x' ≡ x) → Type _
leftTy eq* = PathP (λ i → fst (Q ⟅ c , eq* i ⟆)) ((α ⟦ c , x' ⟧) X') (subst (λ v → fst (Q ⟅ c , v ⟆)) eq' ((α ⟦ c , x' ⟧) X'))
left : leftTy eq
left = subst
(λ eq* → leftTy eq*)
eq'≡eq
(transport-filler _ _)
where
eq'≡eq : eq' ≡ eq
eq'≡eq = snd (F ⟅ c ⟆) _ _ eq' eq
εIso : ∀ (P : PreShv (∫ᴾ F) .ob)
→ isIsoC {C = PreShv (∫ᴾ F)} (εTrans ⟦ P ⟧)
εIso P = FUNCTORIso _ _ _ isIsoC'
where
isIsoC' : ∀ (cx : (∫ᴾ F) .ob)
→ isIsoC {C = SET _} ((εTrans ⟦ P ⟧) ⟦ cx ⟧)
isIsoC' cx@(c , _) = CatIso→isIso (Iso→CatIso (invIso (typeFiberIso {isSetA = snd (F ⟅ c ⟆)} _)))
-- putting it all together
preshvSlice≃preshvElem : SliceCat ≃ᶜ PreShv (∫ᴾ F)
preshvSlice≃preshvElem .func = K
preshvSlice≃preshvElem .isEquiv .invFunc = L
preshvSlice≃preshvElem .isEquiv .η .trans = ηTrans
preshvSlice≃preshvElem .isEquiv .η .nIso = ηIso
preshvSlice≃preshvElem .isEquiv .ε .trans = εTrans
preshvSlice≃preshvElem .isEquiv .ε .nIso = εIso
| 43.779487
| 145
| 0.455078
|
36bf6eaba4c26b72ef60d6002668c154bf377e14
| 1,263
|
agda
|
Agda
|
src/fot/FOTC/Program/Division/TotalityATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Program/Division/TotalityATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Program/Division/TotalityATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Totality properties of the division
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.Division.TotalityATP where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Inequalities
open import FOTC.Program.Division.Division
open import FOTC.Program.Division.Specification
------------------------------------------------------------------------------
-- The division is total when the dividend is less than the divisor.
postulate div-x<y-N : ∀ {i j} → i < j → N (div i j)
{-# ATP prove div-x<y-N #-}
-- The division is total when the dividend is greater or equal than
-- the divisor.
-- N (div (i ∸ j) j) i ≮j → div i j ≡ succ (div (i ∸ j) j)
------------------------------------------------------------------
-- N (div i j)
postulate div-x≮y-N : ∀ {i j} →
(divSpec (i ∸ j) j (div (i ∸ j) j)) →
i ≮ j →
N (div i j)
{-# ATP prove div-x≮y-N #-}
| 36.085714
| 78
| 0.429929
|
0d913994c9f6e4e21cb34ea86752f4ca59a4219b
| 11,702
|
agda
|
Agda
|
src/nat.agda
|
shinji-kono/Galois
|
bf000643c139f40d5783e962bb3b63353ba3d6e4
|
[
"MIT"
] | 1
|
2021-10-16T03:37:05.000Z
|
2021-10-16T03:37:05.000Z
|
src/nat.agda
|
shinji-kono/Galois
|
bf000643c139f40d5783e962bb3b63353ba3d6e4
|
[
"MIT"
] | null | null | null |
src/nat.agda
|
shinji-kono/Galois
|
bf000643c139f40d5783e962bb3b63353ba3d6e4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --allow-unsolved-metas #-}
module nat where
open import Data.Nat
open import Data.Nat.Properties
open import Data.Empty
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Relation.Binary.Core
open import Relation.Binary.Definitions
open import logic
nat-<> : { x y : ℕ } → x < y → y < x → ⊥
nat-<> (s≤s x<y) (s≤s y<x) = nat-<> x<y y<x
nat-≤> : { x y : ℕ } → x ≤ y → y < x → ⊥
nat-≤> (s≤s x<y) (s≤s y<x) = nat-≤> x<y y<x
nat-<≡ : { x : ℕ } → x < x → ⊥
nat-<≡ (s≤s lt) = nat-<≡ lt
nat-≡< : { x y : ℕ } → x ≡ y → x < y → ⊥
nat-≡< refl lt = nat-<≡ lt
¬a≤a : {la : ℕ} → suc la ≤ la → ⊥
¬a≤a (s≤s lt) = ¬a≤a lt
a<sa : {la : ℕ} → la < suc la
a<sa {zero} = s≤s z≤n
a<sa {suc la} = s≤s a<sa
refl-≤s : {x : ℕ } → x ≤ suc x
refl-≤s {zero} = z≤n
refl-≤s {suc x} = s≤s (refl-≤s {x})
a≤sa : {x : ℕ } → x ≤ suc x
a≤sa {zero} = z≤n
a≤sa {suc x} = s≤s (a≤sa {x})
=→¬< : {x : ℕ } → ¬ ( x < x )
=→¬< {zero} ()
=→¬< {suc x} (s≤s lt) = =→¬< lt
>→¬< : {x y : ℕ } → (x < y ) → ¬ ( y < x )
>→¬< (s≤s x<y) (s≤s y<x) = >→¬< x<y y<x
<-∨ : { x y : ℕ } → x < suc y → ( (x ≡ y ) ∨ (x < y) )
<-∨ {zero} {zero} (s≤s z≤n) = case1 refl
<-∨ {zero} {suc y} (s≤s lt) = case2 (s≤s z≤n)
<-∨ {suc x} {zero} (s≤s ())
<-∨ {suc x} {suc y} (s≤s lt) with <-∨ {x} {y} lt
<-∨ {suc x} {suc y} (s≤s lt) | case1 eq = case1 (cong (λ k → suc k ) eq)
<-∨ {suc x} {suc y} (s≤s lt) | case2 lt1 = case2 (s≤s lt1)
n≤n : (n : ℕ) → n Data.Nat.≤ n
n≤n zero = z≤n
n≤n (suc n) = s≤s (n≤n n)
<→m≤n : {m n : ℕ} → m < n → m Data.Nat.≤ n
<→m≤n {zero} lt = z≤n
<→m≤n {suc m} {zero} ()
<→m≤n {suc m} {suc n} (s≤s lt) = s≤s (<→m≤n lt)
max : (x y : ℕ) → ℕ
max zero zero = zero
max zero (suc x) = (suc x)
max (suc x) zero = (suc x)
max (suc x) (suc y) = suc ( max x y )
-- _*_ : ℕ → ℕ → ℕ
-- _*_ zero _ = zero
-- _*_ (suc n) m = m + ( n * m )
exp : ℕ → ℕ → ℕ
exp _ zero = 1
exp n (suc m) = n * ( exp n m )
minus : (a b : ℕ ) → ℕ
minus a zero = a
minus zero (suc b) = zero
minus (suc a) (suc b) = minus a b
_-_ = minus
m+= : {i j m : ℕ } → m + i ≡ m + j → i ≡ j
m+= {i} {j} {zero} refl = refl
m+= {i} {j} {suc m} eq = m+= {i} {j} {m} ( cong (λ k → pred k ) eq )
+m= : {i j m : ℕ } → i + m ≡ j + m → i ≡ j
+m= {i} {j} {m} eq = m+= ( subst₂ (λ j k → j ≡ k ) (+-comm i _ ) (+-comm j _ ) eq )
less-1 : { n m : ℕ } → suc n < m → n < m
less-1 {zero} {suc (suc _)} (s≤s (s≤s z≤n)) = s≤s z≤n
less-1 {suc n} {suc m} (s≤s lt) = s≤s (less-1 {n} {m} lt)
sa=b→a<b : { n m : ℕ } → suc n ≡ m → n < m
sa=b→a<b {0} {suc zero} refl = s≤s z≤n
sa=b→a<b {suc n} {suc (suc n)} refl = s≤s (sa=b→a<b refl)
minus+n : {x y : ℕ } → suc x > y → minus x y + y ≡ x
minus+n {x} {zero} _ = trans (sym (+-comm zero _ )) refl
minus+n {zero} {suc y} (s≤s ())
minus+n {suc x} {suc y} (s≤s lt) = begin
minus (suc x) (suc y) + suc y
≡⟨ +-comm _ (suc y) ⟩
suc y + minus x y
≡⟨ cong ( λ k → suc k ) (
begin
y + minus x y
≡⟨ +-comm y _ ⟩
minus x y + y
≡⟨ minus+n {x} {y} lt ⟩
x
∎
) ⟩
suc x
∎ where open ≡-Reasoning
sn-m=sn-m : {m n : ℕ } → m ≤ n → suc n - m ≡ suc ( n - m )
sn-m=sn-m {0} {n} z≤n = refl
sn-m=sn-m {suc m} {suc n} (s≤s m<n) = sn-m=sn-m m<n
si-sn=i-n : {i n : ℕ } → n < i → suc (i - suc n) ≡ (i - n)
si-sn=i-n {i} {n} n<i = begin
suc (i - suc n) ≡⟨ sym (sn-m=sn-m n<i ) ⟩
suc i - suc n ≡⟨⟩
i - n
∎ where
open ≡-Reasoning
n-m<n : (n m : ℕ ) → n - m ≤ n
n-m<n zero zero = z≤n
n-m<n (suc n) zero = s≤s (n-m<n n zero)
n-m<n zero (suc m) = z≤n
n-m<n (suc n) (suc m) = ≤-trans (n-m<n n m ) refl-≤s
n-n-m=m : {m n : ℕ } → m ≤ n → m ≡ (n - (n - m))
n-n-m=m {0} {zero} z≤n = refl
n-n-m=m {0} {suc n} z≤n = n-n-m=m {0} {n} z≤n
n-n-m=m {suc m} {suc n} (s≤s m≤n) = sym ( begin
suc n - ( n - m ) ≡⟨ sn-m=sn-m (n-m<n n m) ⟩
suc (n - ( n - m )) ≡⟨ cong (λ k → suc k ) (sym (n-n-m=m m≤n)) ⟩
suc m
∎ ) where
open ≡-Reasoning
0<s : {x : ℕ } → zero < suc x
0<s {_} = s≤s z≤n
<-minus-0 : {x y z : ℕ } → z + x < z + y → x < y
<-minus-0 {x} {suc _} {zero} lt = lt
<-minus-0 {x} {y} {suc z} (s≤s lt) = <-minus-0 {x} {y} {z} lt
<-minus : {x y z : ℕ } → x + z < y + z → x < y
<-minus {x} {y} {z} lt = <-minus-0 ( subst₂ ( λ j k → j < k ) (+-comm x _) (+-comm y _ ) lt )
x≤x+y : {z y : ℕ } → z ≤ z + y
x≤x+y {zero} {y} = z≤n
x≤x+y {suc z} {y} = s≤s (x≤x+y {z} {y})
<-plus : {x y z : ℕ } → x < y → x + z < y + z
<-plus {zero} {suc y} {z} (s≤s z≤n) = s≤s (subst (λ k → z ≤ k ) (+-comm z _ ) x≤x+y )
<-plus {suc x} {suc y} {z} (s≤s lt) = s≤s (<-plus {x} {y} {z} lt)
<-plus-0 : {x y z : ℕ } → x < y → z + x < z + y
<-plus-0 {x} {y} {z} lt = subst₂ (λ j k → j < k ) (+-comm _ z) (+-comm _ z) ( <-plus {x} {y} {z} lt )
≤-plus : {x y z : ℕ } → x ≤ y → x + z ≤ y + z
≤-plus {0} {y} {zero} z≤n = z≤n
≤-plus {0} {y} {suc z} z≤n = subst (λ k → z < k ) (+-comm _ y ) x≤x+y
≤-plus {suc x} {suc y} {z} (s≤s lt) = s≤s ( ≤-plus {x} {y} {z} lt )
≤-plus-0 : {x y z : ℕ } → x ≤ y → z + x ≤ z + y
≤-plus-0 {x} {y} {zero} lt = lt
≤-plus-0 {x} {y} {suc z} lt = s≤s ( ≤-plus-0 {x} {y} {z} lt )
x+y<z→x<z : {x y z : ℕ } → x + y < z → x < z
x+y<z→x<z {zero} {y} {suc z} (s≤s lt1) = s≤s z≤n
x+y<z→x<z {suc x} {y} {suc z} (s≤s lt1) = s≤s ( x+y<z→x<z {x} {y} {z} lt1 )
*≤ : {x y z : ℕ } → x ≤ y → x * z ≤ y * z
*≤ lt = *-mono-≤ lt ≤-refl
*< : {x y z : ℕ } → x < y → x * suc z < y * suc z
*< {zero} {suc y} lt = s≤s z≤n
*< {suc x} {suc y} (s≤s lt) = <-plus-0 (*< lt)
<to<s : {x y : ℕ } → x < y → x < suc y
<to<s {zero} {suc y} (s≤s lt) = s≤s z≤n
<to<s {suc x} {suc y} (s≤s lt) = s≤s (<to<s {x} {y} lt)
<tos<s : {x y : ℕ } → x < y → suc x < suc y
<tos<s {zero} {suc y} (s≤s z≤n) = s≤s (s≤s z≤n)
<tos<s {suc x} {suc y} (s≤s lt) = s≤s (<tos<s {x} {y} lt)
≤to< : {x y : ℕ } → x < y → x ≤ y
≤to< {zero} {suc y} (s≤s z≤n) = z≤n
≤to< {suc x} {suc y} (s≤s lt) = s≤s (≤to< {x} {y} lt)
x<y→≤ : {x y : ℕ } → x < y → x ≤ suc y
x<y→≤ {zero} {.(suc _)} (s≤s z≤n) = z≤n
x<y→≤ {suc x} {suc y} (s≤s lt) = s≤s (x<y→≤ {x} {y} lt)
open import Data.Product
minus<=0 : {x y : ℕ } → x ≤ y → minus x y ≡ 0
minus<=0 {0} {zero} z≤n = refl
minus<=0 {0} {suc y} z≤n = refl
minus<=0 {suc x} {suc y} (s≤s le) = minus<=0 {x} {y} le
minus>0 : {x y : ℕ } → x < y → 0 < minus y x
minus>0 {zero} {suc _} (s≤s z≤n) = s≤s z≤n
minus>0 {suc x} {suc y} (s≤s lt) = minus>0 {x} {y} lt
distr-minus-* : {x y z : ℕ } → (minus x y) * z ≡ minus (x * z) (y * z)
distr-minus-* {x} {zero} {z} = refl
distr-minus-* {x} {suc y} {z} with <-cmp x y
distr-minus-* {x} {suc y} {z} | tri< a ¬b ¬c = begin
minus x (suc y) * z
≡⟨ cong (λ k → k * z ) (minus<=0 {x} {suc y} (x<y→≤ a)) ⟩
0 * z
≡⟨ sym (minus<=0 {x * z} {z + y * z} le ) ⟩
minus (x * z) (z + y * z)
∎ where
open ≡-Reasoning
le : x * z ≤ z + y * z
le = ≤-trans lemma (subst (λ k → y * z ≤ k ) (+-comm _ z ) (x≤x+y {y * z} {z} ) ) where
lemma : x * z ≤ y * z
lemma = *≤ {x} {y} {z} (≤to< a)
distr-minus-* {x} {suc y} {z} | tri≈ ¬a refl ¬c = begin
minus x (suc y) * z
≡⟨ cong (λ k → k * z ) (minus<=0 {x} {suc y} refl-≤s ) ⟩
0 * z
≡⟨ sym (minus<=0 {x * z} {z + y * z} (lt {x} {z} )) ⟩
minus (x * z) (z + y * z)
∎ where
open ≡-Reasoning
lt : {x z : ℕ } → x * z ≤ z + x * z
lt {zero} {zero} = z≤n
lt {suc x} {zero} = lt {x} {zero}
lt {x} {suc z} = ≤-trans lemma refl-≤s where
lemma : x * suc z ≤ z + x * suc z
lemma = subst (λ k → x * suc z ≤ k ) (+-comm _ z) (x≤x+y {x * suc z} {z})
distr-minus-* {x} {suc y} {z} | tri> ¬a ¬b c = +m= {_} {_} {suc y * z} ( begin
minus x (suc y) * z + suc y * z
≡⟨ sym (proj₂ *-distrib-+ z (minus x (suc y) ) _) ⟩
( minus x (suc y) + suc y ) * z
≡⟨ cong (λ k → k * z) (minus+n {x} {suc y} (s≤s c)) ⟩
x * z
≡⟨ sym (minus+n {x * z} {suc y * z} (s≤s (lt c))) ⟩
minus (x * z) (suc y * z) + suc y * z
∎ ) where
open ≡-Reasoning
lt : {x y z : ℕ } → suc y ≤ x → z + y * z ≤ x * z
lt {x} {y} {z} le = *≤ le
minus- : {x y z : ℕ } → suc x > z + y → minus (minus x y) z ≡ minus x (y + z)
minus- {x} {y} {z} gt = +m= {_} {_} {z} ( begin
minus (minus x y) z + z
≡⟨ minus+n {_} {z} lemma ⟩
minus x y
≡⟨ +m= {_} {_} {y} ( begin
minus x y + y
≡⟨ minus+n {_} {y} lemma1 ⟩
x
≡⟨ sym ( minus+n {_} {z + y} gt ) ⟩
minus x (z + y) + (z + y)
≡⟨ sym ( +-assoc (minus x (z + y)) _ _ ) ⟩
minus x (z + y) + z + y
∎ ) ⟩
minus x (z + y) + z
≡⟨ cong (λ k → minus x k + z ) (+-comm _ y ) ⟩
minus x (y + z) + z
∎ ) where
open ≡-Reasoning
lemma1 : suc x > y
lemma1 = x+y<z→x<z (subst (λ k → k < suc x ) (+-comm z _ ) gt )
lemma : suc (minus x y) > z
lemma = <-minus {_} {_} {y} ( subst ( λ x → z + y < suc x ) (sym (minus+n {x} {y} lemma1 )) gt )
minus-* : {M k n : ℕ } → n < k → minus k (suc n) * M ≡ minus (minus k n * M ) M
minus-* {zero} {k} {n} lt = begin
minus k (suc n) * zero
≡⟨ *-comm (minus k (suc n)) zero ⟩
zero * minus k (suc n)
≡⟨⟩
0 * minus k n
≡⟨ *-comm 0 (minus k n) ⟩
minus (minus k n * 0 ) 0
∎ where
open ≡-Reasoning
minus-* {suc m} {k} {n} lt with <-cmp k 1
minus-* {suc m} {.0} {zero} lt | tri< (s≤s z≤n) ¬b ¬c = refl
minus-* {suc m} {.0} {suc n} lt | tri< (s≤s z≤n) ¬b ¬c = refl
minus-* {suc zero} {.1} {zero} lt | tri≈ ¬a refl ¬c = refl
minus-* {suc (suc m)} {.1} {zero} lt | tri≈ ¬a refl ¬c = minus-* {suc m} {1} {zero} lt
minus-* {suc m} {.1} {suc n} (s≤s ()) | tri≈ ¬a refl ¬c
minus-* {suc m} {k} {n} lt | tri> ¬a ¬b c = begin
minus k (suc n) * M
≡⟨ distr-minus-* {k} {suc n} {M} ⟩
minus (k * M ) ((suc n) * M)
≡⟨⟩
minus (k * M ) (M + n * M )
≡⟨ cong (λ x → minus (k * M) x) (+-comm M _ ) ⟩
minus (k * M ) ((n * M) + M )
≡⟨ sym ( minus- {k * M} {n * M} (lemma lt) ) ⟩
minus (minus (k * M ) (n * M)) M
≡⟨ cong (λ x → minus x M ) ( sym ( distr-minus-* {k} {n} )) ⟩
minus (minus k n * M ) M
∎ where
M = suc m
lemma : {n k m : ℕ } → n < k → suc (k * suc m) > suc m + n * suc m
lemma {zero} {suc k} {m} (s≤s lt) = s≤s (s≤s (subst (λ x → x ≤ m + k * suc m) (+-comm 0 _ ) x≤x+y ))
lemma {suc n} {suc k} {m} lt = begin
suc (suc m + suc n * suc m)
≡⟨⟩
suc ( suc (suc n) * suc m)
≤⟨ ≤-plus-0 {_} {_} {1} (*≤ lt ) ⟩
suc (suc k * suc m)
∎ where open ≤-Reasoning
open ≡-Reasoning
open import Data.List
ℕL-inject : {h h1 : ℕ } {x y : List ℕ } → h ∷ x ≡ h1 ∷ y → h ≡ h1
ℕL-inject refl = refl
ℕL-inject-t : {h h1 : ℕ } {x y : List ℕ } → h ∷ x ≡ h1 ∷ y → x ≡ y
ℕL-inject-t refl = refl
ℕL-eq? : (x y : List ℕ ) → Dec (x ≡ y )
ℕL-eq? [] [] = yes refl
ℕL-eq? [] (x ∷ y) = no (λ ())
ℕL-eq? (x ∷ x₁) [] = no (λ ())
ℕL-eq? (h ∷ x) (h1 ∷ y) with h ≟ h1 | ℕL-eq? x y
... | yes y1 | yes y2 = yes ( cong₂ (λ j k → j ∷ k ) y1 y2 )
... | yes y1 | no n = no (λ e → n (ℕL-inject-t e))
... | no n | t = no (λ e → n (ℕL-inject e))
| 34.316716
| 113
| 0.398223
|
049bc70d3796e5d20e31c486b871863d3a1dcb29
| 1,314
|
agda
|
Agda
|
src/Sigma/Renaming/Properties.agda
|
johnyob/agda-sigma
|
bb895fa8a3ccbefbd2c4a135c79744ba06895be7
|
[
"MIT"
] | null | null | null |
src/Sigma/Renaming/Properties.agda
|
johnyob/agda-sigma
|
bb895fa8a3ccbefbd2c4a135c79744ba06895be7
|
[
"MIT"
] | null | null | null |
src/Sigma/Renaming/Properties.agda
|
johnyob/agda-sigma
|
bb895fa8a3ccbefbd2c4a135c79744ba06895be7
|
[
"MIT"
] | null | null | null |
module Sigma.Renaming.Properties where
open import Data.Nat using (ℕ; _+_; zero; suc)
open import Data.Fin using (Fin; zero; suc)
open import Sigma.Subst.Core
open import Sigma.Renaming.Base
open import Sigma.Subst.Properties using (extensionality)
open import Function using (_∘_)
open import Relation.Binary.PropositionalEquality as Eq
using (_≡_; refl; cong; cong₂)
open Eq.≡-Reasoning
-- ------------------------------------------------------------------------
⇑-cong : ∀ { m n } { ρ₁ ρ₂ : Ren m n }
→ ρ₁ ≡ ρ₂
-- -----------
→ ρ₁ ⇑ ≡ ρ₂ ⇑
⇑-cong ρ₁≡ρ₂ = cong (_⇑) ρ₁≡ρ₂
⇑✶-cong : ∀ { m n } k { ρ₁ ρ₂ : Ren m n }
→ ρ₁ ≡ ρ₂
-- -----------
→ ρ₁ ⇑✶ k ≡ ρ₂ ⇑✶ k
⇑✶-cong k ρ₁≡ρ₂ = cong (_⇑✶ k) ρ₁≡ρ₂
-- ------------------------------------------------------------------------
∘-⇑-distrib : ∀ { m n k } ( ρ₁ : Ren m n ) ( ρ₂ : Ren n k )
→ (ρ₂ ⇑ ∘ ρ₁ ⇑) ≡ (ρ₂ ∘ ρ₁) ⇑
∘-⇑-distrib ρ₁ ρ₂ = extensionality lemma
where
lemma : ∀ x → (ρ₂ ⇑ ∘ ρ₁ ⇑) x ≡ ((ρ₂ ∘ ρ₁) ⇑) x
lemma zero = refl
lemma (suc x) = refl
-- TODO:
-- generalized for ⇑✶
-- ------------------------------------------------------------------------
⇑-id : ∀ { n } → (id { n }) ⇑ ≡ id
⇑-id = extensionality lemma
where
lemma : ∀ { n } x → (id { n } ⇑) x ≡ x
lemma zero = refl
lemma (suc x) = refl
| 25.269231
| 75
| 0.449772
|
145e7e3148dd3fa84d63fd76ba5de3209aa99bc3
| 6,784
|
agda
|
Agda
|
src/Web/Semantic/DL/Category/Properties/Tensor/AssocNatural.agda
|
bblfish/agda-web-semantic
|
38fbc3af7062ba5c3d7d289b2b4bcfb995d99057
|
[
"MIT"
] | 1
|
2022-02-22T09:43:23.000Z
|
2022-02-22T09:43:23.000Z
|
src/Web/Semantic/DL/Category/Properties/Tensor/AssocNatural.agda
|
bblfish/agda-web-semantic
|
38fbc3af7062ba5c3d7d289b2b4bcfb995d99057
|
[
"MIT"
] | null | null | null |
src/Web/Semantic/DL/Category/Properties/Tensor/AssocNatural.agda
|
bblfish/agda-web-semantic
|
38fbc3af7062ba5c3d7d289b2b4bcfb995d99057
|
[
"MIT"
] | null | null | null |
open import Data.Product using ( proj₁ ; proj₂ )
open import Data.Sum using ( _⊎_ ; inj₁ ; inj₂ )
open import Relation.Binary.PropositionalEquality using ( refl )
open import Web.Semantic.DL.ABox.Interp using ( ⌊_⌋ ; ind ; _*_ )
open import Web.Semantic.DL.ABox.Interp.Morphism using ( _,_ )
open import Web.Semantic.DL.ABox.Model using
( _⊨a_ ; on-bnode ; bnodes ; _,_ ; ⊨a-resp-≲ )
open import Web.Semantic.DL.Category.Composition using ( _∙_ )
open import Web.Semantic.DL.Category.Properties.Composition.Lemmas using
( compose-left ; compose-right ; compose-resp-⊨a )
open import Web.Semantic.DL.Category.Properties.Tensor.Lemmas using
( tensor-up ; tensor-down ; tensor-resp-⊨a )
open import Web.Semantic.DL.Category.Object using ( Object ; IN ; fin )
open import Web.Semantic.DL.Category.Morphism using
( _⇒_ ; BN ; impl ; _⊑_ ; _≣_ ; _,_ )
open import Web.Semantic.DL.Category.Tensor using ( _⊗_ ; _⟨⊗⟩_ )
open import Web.Semantic.DL.Category.Unit using ( I )
open import Web.Semantic.DL.Category.Wiring using
( wires-≈ ; wires-≈⁻¹ ; assoc )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox )
open import Web.Semantic.DL.TBox.Interp using
( Δ ; _⊨_≈_ ; ≈-refl ; ≈-refl′ ; ≈-sym )
open import Web.Semantic.DL.TBox.Interp.Morphism using ( ≲-refl )
open import Web.Semantic.Util using
( _∘_ ; False ; ⊎-assoc ; ⊎-assoc⁻¹
; _⊕_⊕_ ; inode ; bnode ; enode ; left ; right ; up ; down )
module Web.Semantic.DL.Category.Properties.Tensor.AssocNatural
{Σ : Signature} {S T : TBox Σ} where
assoc-natural : ∀ {A₁ A₂ A₃ B₁ B₂ B₃ : Object S T}
(F₁ : A₁ ⇒ B₁) (F₂ : A₂ ⇒ B₂) (F₃ : A₃ ⇒ B₃) →
(((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) ∙ assoc B₁ B₂ B₃ ≣
assoc A₁ A₂ A₃ ∙ (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)))
assoc-natural {A₁} {A₂} {A₃} {B₁} {B₂} {B₃} F₁ F₂ F₃ = (LHS⊑RHS , RHS⊑LHS) where
LHS⊑RHS : ((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) ∙ assoc B₁ B₂ B₃ ⊑
assoc A₁ A₂ A₃ ∙ (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃))
LHS⊑RHS J J⊨STA J⊨LHS = (f , J⊨RHS) where
f : (False ⊕ (IN A₁ ⊎ (IN A₂ ⊎ IN A₃)) ⊕ (BN F₁ ⊎ (BN F₂ ⊎ BN F₃))) → Δ ⌊ J ⌋
f (inode ())
f (bnode x) = ind J (inode (⊎-assoc⁻¹ x))
f (enode v) = ind J (bnode (inode (⊎-assoc⁻¹ v)))
lemma₁ : ∀ x →
⌊ J ⌋ ⊨ ind J (left (up (up x))) ≈
on-bnode {Σ} f (ind J) (right (up x))
lemma₁ (inode x) = ≈-refl ⌊ J ⌋
lemma₁ (bnode v) = ≈-refl ⌊ J ⌋
lemma₁ (enode y) = wires-≈ ⊎-assoc⁻¹
(proj₂ (fin (B₁ ⊗ (B₂ ⊗ B₃))) (inj₁ y))
(compose-right ((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) (assoc B₁ B₂ B₃) J J⊨LHS)
lemma₂ : ∀ x →
⌊ J ⌋ ⊨ ind J (left (up (down x))) ≈
on-bnode {Σ} f (ind J) (right (down (up x)))
lemma₂ (inode x) = ≈-refl ⌊ J ⌋
lemma₂ (bnode v) = ≈-refl ⌊ J ⌋
lemma₂ (enode y) = wires-≈ ⊎-assoc⁻¹
(proj₂ (fin (B₁ ⊗ (B₂ ⊗ B₃))) (inj₂ (inj₁ y)))
(compose-right ((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) (assoc B₁ B₂ B₃) J J⊨LHS)
lemma₃ : ∀ x →
⌊ J ⌋ ⊨ ind J (left (down x)) ≈
on-bnode {Σ} f (ind J) (right (down (down x)))
lemma₃ (inode x) = ≈-refl ⌊ J ⌋
lemma₃ (bnode v) = ≈-refl ⌊ J ⌋
lemma₃ (enode y) = wires-≈ ⊎-assoc⁻¹
(proj₂ (fin (B₁ ⊗ (B₂ ⊗ B₃))) (inj₂ (inj₂ y)))
(compose-right ((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) (assoc B₁ B₂ B₃) J J⊨LHS)
J⊨RHS : bnodes J f ⊨a impl (assoc A₁ A₂ A₃ ∙ (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)))
J⊨RHS = compose-resp-⊨a (assoc A₁ A₂ A₃) (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)) (bnodes J f)
(wires-≈⁻¹ ⊎-assoc⁻¹ (λ x → ≈-refl ⌊ J ⌋) (proj₁ (fin (A₁ ⊗ (A₂ ⊗ A₃)))))
(tensor-resp-⊨a F₁ (F₂ ⟨⊗⟩ F₃) (right * bnodes J f)
(⊨a-resp-≲ (≲-refl ⌊ J ⌋ , lemma₁) (impl F₁)
(tensor-up F₁ F₂ (up * left * J)
(tensor-up (F₁ ⟨⊗⟩ F₂) F₃ (left * J)
(compose-left ((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) (assoc B₁ B₂ B₃) J J⊨LHS))))
(tensor-resp-⊨a F₂ F₃ (down * right * bnodes J f)
(⊨a-resp-≲ (≲-refl ⌊ J ⌋ , lemma₂) (impl F₂)
(tensor-down F₁ F₂ (up * left * J)
(tensor-up (F₁ ⟨⊗⟩ F₂) F₃ (left * J)
(compose-left ((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) (assoc B₁ B₂ B₃) J J⊨LHS))))
(⊨a-resp-≲ (≲-refl ⌊ J ⌋ , lemma₃) (impl F₃)
(tensor-down (F₁ ⟨⊗⟩ F₂) F₃ (left * J)
(compose-left ((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) (assoc B₁ B₂ B₃) J J⊨LHS)))))
RHS⊑LHS : assoc A₁ A₂ A₃ ∙ (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)) ⊑
((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) ∙ assoc B₁ B₂ B₃
RHS⊑LHS J J⊨STA J⊨RHS = (f , J⊨LHS) where
f : (((BN F₁ ⊎ BN F₂) ⊎ BN F₃) ⊕ ((IN B₁ ⊎ IN B₂) ⊎ IN B₃) ⊕ False) → Δ ⌊ J ⌋
f (inode v) = ind J (bnode (enode (⊎-assoc v)))
f (bnode y) = ind J (enode (⊎-assoc y))
f (enode ())
lemma₀ : ∀ x →
⌊ J ⌋ ⊨ ind J (enode (⊎-assoc (⊎-assoc⁻¹ x))) ≈ ind J (enode x)
lemma₀ (inj₁ x) = ≈-refl ⌊ J ⌋
lemma₀ (inj₂ (inj₁ x)) = ≈-refl ⌊ J ⌋
lemma₀ (inj₂ (inj₂ y)) = ≈-refl ⌊ J ⌋
lemma₁ : ∀ x → ⌊ J ⌋ ⊨ ind J (right (up x)) ≈
on-bnode {Σ} f (ind J) (left (up (up x)))
lemma₁ (inode x) = ≈-sym ⌊ J ⌋ (wires-≈ ⊎-assoc⁻¹
(proj₂ (fin (A₁ ⊗ (A₂ ⊗ A₃))) (inj₁ x))
(compose-left (assoc A₁ A₂ A₃) (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)) J J⊨RHS))
lemma₁ (bnode v) = ≈-refl ⌊ J ⌋
lemma₁ (enode y) = ≈-refl ⌊ J ⌋
lemma₂ : ∀ x → ⌊ J ⌋ ⊨ ind J (right (down (up x))) ≈
on-bnode {Σ} f (ind J) (left (up (down x)))
lemma₂ (inode x) = ≈-sym ⌊ J ⌋ (wires-≈ ⊎-assoc⁻¹
(proj₂ (fin (A₁ ⊗ (A₂ ⊗ A₃))) (inj₂ (inj₁ x)))
(compose-left (assoc A₁ A₂ A₃) (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)) J J⊨RHS))
lemma₂ (bnode v) = ≈-refl ⌊ J ⌋
lemma₂ (enode y) = ≈-refl ⌊ J ⌋
lemma₃ : ∀ x → ⌊ J ⌋ ⊨ ind J (right (down (down x))) ≈
on-bnode {Σ} f (ind J) (left (down x))
lemma₃ (inode x) = ≈-sym ⌊ J ⌋ (wires-≈ ⊎-assoc⁻¹
(proj₂ (fin (A₁ ⊗ (A₂ ⊗ A₃))) (inj₂ (inj₂ x)))
(compose-left (assoc A₁ A₂ A₃) (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)) J J⊨RHS))
lemma₃ (bnode v) = ≈-refl ⌊ J ⌋
lemma₃ (enode y) = ≈-refl ⌊ J ⌋
J⊨LHS : bnodes J f ⊨a impl (((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) ∙ assoc B₁ B₂ B₃)
J⊨LHS = compose-resp-⊨a ((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) (assoc B₁ B₂ B₃) (bnodes J f)
(tensor-resp-⊨a (F₁ ⟨⊗⟩ F₂) F₃ (left * bnodes J f)
(tensor-resp-⊨a F₁ F₂ (up * left * bnodes J f)
(⊨a-resp-≲ (≲-refl ⌊ J ⌋ , lemma₁) (impl F₁)
(tensor-up F₁ (F₂ ⟨⊗⟩ F₃) (right * J)
(compose-right (assoc A₁ A₂ A₃) (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)) J J⊨RHS)))
(⊨a-resp-≲ (≲-refl ⌊ J ⌋ , lemma₂) (impl F₂)
(tensor-up F₂ F₃ (down * right * J)
(tensor-down F₁ (F₂ ⟨⊗⟩ F₃) (right * J)
(compose-right (assoc A₁ A₂ A₃) (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)) J J⊨RHS)))))
(⊨a-resp-≲ (≲-refl ⌊ J ⌋ , lemma₃) (impl F₃)
(tensor-down F₂ F₃ (down * right * J)
(tensor-down F₁ (F₂ ⟨⊗⟩ F₃) (right * J)
(compose-right (assoc A₁ A₂ A₃) (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)) J J⊨RHS)))))
(wires-≈⁻¹ ⊎-assoc⁻¹ lemma₀ (proj₁ (fin (B₁ ⊗ (B₂ ⊗ B₃)))))
| 46.465753
| 82
| 0.512529
|
144cd033501a0b00fa0819346c1bc1b524194f2e
| 4,530
|
agda
|
Agda
|
Utils/Decidable.agda
|
AndrasKovacs/SemanticsWithApplications
|
05200d60b4a4b2c6fa37806ced9247055d24db94
|
[
"MIT"
] | 8
|
2016-09-12T04:25:39.000Z
|
2020-02-02T10:01:52.000Z
|
Utils/Decidable.agda
|
AndrasKovacs/SemanticsWithApplications
|
05200d60b4a4b2c6fa37806ced9247055d24db94
|
[
"MIT"
] | null | null | null |
Utils/Decidable.agda
|
AndrasKovacs/SemanticsWithApplications
|
05200d60b4a4b2c6fa37806ced9247055d24db94
|
[
"MIT"
] | null | null | null |
module Utils.Decidable where
open import Data.Nat
open import Data.Char
open import Data.String
open import Data.Bool
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable hiding (True; False)
open import Relation.Nullary
open import Data.Product
open import Data.Sum
open import Function
import Level as L
{-
A type class for decidable types.
The part we actually end up using in the formal semantics proofs is
mostly decidable equality (_≡⁇_).
-}
_=>_ : ∀ {α β} → Set α → Set β → Set (α L.⊔ β)
Dict => A = ⦃ _ : Dict ⦄ → A
infixr 5 _=>_
record Decidable {a}(A : Set a) : Set a where
constructor rec
field
decide : Dec A
DecRel : ∀ {a b}{A : Set a}{B : Set b} → (A → B → Set (a L.⊔ b)) → Set (a L.⊔ b)
DecRel Rel = ∀ {x y} → Decidable (Rel x y)
DecEq : ∀ {a} → Set a → Set a
DecEq A = DecRel (_≡_ {_} {A})
_⁇ : ∀ {a} A → Decidable {a} A => Dec A
_⁇ A ⦃ dict ⦄ = Decidable.decide dict
_≡⁇_ : ∀ {a A} → DecEq {a} A => ((x y : A) → Dec (x ≡ y))
x ≡⁇ y = (x ≡ y) ⁇
True : ∀ {a} A → Decidable {a} A => Set
True A = T ⌊ A ⁇ ⌋
F : Bool → Set
F = T ∘ not
False : ∀ {a} A → Decidable {a} A => Set
False A = F ⌊ A ⁇ ⌋
_≤⁇_ : ∀ a b → Dec (a ≤ b)
_≤⁇_ = _≤?_
_<⁇_ : ∀ a b → Dec (a < b)
a <⁇ b = suc a ≤⁇ b
module _ where
open import Data.Nat.Properties
_≤′⁇_ : ∀ a b → Dec (a ≤′ b)
_≤′⁇_ a b with a ≤⁇ b
... | yes p = yes (≤⇒≤′ p)
... | no p = no (p ∘ ≤′⇒≤)
_<′⁇_ : ∀ a b → Dec (a <′ b)
a <′⁇ b = suc a ≤′⁇ b
instance
DecEqBool : DecEq Bool
DecEqBool = rec (_ Data.Bool.≟ _)
instance
DecEqChar : DecEq Char
DecEqChar = rec (_ Data.Char.≟ _)
module _ where
open import Data.Fin
open import Data.Fin.Properties
instance
DecEqFin : ∀ {n} → DecEq (Fin n)
DecEqFin = rec (_ Data.Fin.Properties.≟ _)
instance
DecEqℕ : DecEq ℕ
DecEqℕ = rec (_ Data.Nat.≟ _)
instance
DecEqString : DecEq String
DecEqString = rec (_ Data.String.≟ _)
instance
Decℕ≤ : DecRel _≤_
Decℕ≤ = rec (_ ≤⁇ _)
instance
Decℕ≤′ : DecRel _≤′_
Decℕ≤′ = rec (_ ≤′⁇ _)
-- Conversions between decidable / boolean
--------------------------------------------------
T→∧ : ∀ {a b} → T (a ∧ b) → T a × T b
T→∧ {true} {true} x = _
T→∧ {true} {false} ()
T→∧ {false} ()
∧→T : ∀ {a b} → T a → T b → T (a ∧ b)
∧→T {true} {true} p1 p2 = _
∧→T {true} {false} p1 ()
∧→T {false} () p2
F-not-elim : ∀ {b} → F (not b) → T b
F-not-elim {true} p = p
F-not-elim {false} p = p
F-not-add : ∀ {b} → T b → F (not b)
F-not-add {true} p = p
F-not-add {false} p = p
F-not-≡ : ∀ b → T b ≡ F (not b)
F-not-≡ true = refl
F-not-≡ false = refl
TrueA→A : ∀ {a A}⦃ _ : Decidable {a} A ⦄ → True A → A
TrueA→A = toWitness
FalseA→¬A : ∀ {a A}⦃ _ : Decidable {a} A ⦄ → False A → ¬ A
FalseA→¬A = toWitnessFalse
A→TrueA : ∀ {a A}⦃ _ : Decidable {a} A ⦄ → A → True A
A→TrueA = fromWitness
¬A→FalseA : ∀ {a A}⦃ _ : Decidable {a} A ⦄ → ¬ A → False A
¬A→FalseA = fromWitnessFalse
T→≡true : ∀ {b} → T b → b ≡ true
T→≡true {true} p = refl
T→≡true {false} ()
≡true→T : ∀ {b} → b ≡ true → T b
≡true→T {true} p = _
≡true→T {false} ()
≡false→F : ∀ {b} → b ≡ false → F b
≡false→F {true} ()
≡false→F {false} p = _
F→≡false : ∀ {b} → F b → b ≡ false
F→≡false {true} ()
F→≡false {false} p = refl
A→≡true : ∀ {a A}{Q : Dec {a} A} → A → ⌊ Q ⌋ ≡ true
A→≡true = T→≡true ∘ fromWitness
¬A→≡false : ∀ {a A}{Q : Dec {a} A} → ¬ A → ⌊ Q ⌋ ≡ false
¬A→≡false = F→≡false ∘ fromWitnessFalse
≡true→A : ∀ {a A}{Q : Dec {a} A} → ⌊ Q ⌋ ≡ true → A
≡true→A = toWitness ∘ ≡true→T
≡false→¬A : ∀ {a A}{Q : Dec {a} A} → ⌊ Q ⌋ ≡ false → ¬ A
≡false→¬A = toWitnessFalse ∘ ≡false→F
-----------------------------------------------------------
instance
Dec¬ :
∀ {α A}
→ Decidable {α} A
=> Decidable (¬ A)
Dec¬ {_}{A} = rec dec¬ where
dec¬ : Dec (¬ A)
dec¬ with A ⁇
... | yes p = no (λ z → z p)
... | no ¬p = yes ¬p
instance
Dec⊎ :
∀ {α β A B}
→ Decidable {α} A
=> Decidable {β} B
=> Decidable (A ⊎ B)
Dec⊎ {_}{_}{A}{B} = rec dec⊎ where
dec⊎ : Dec (A ⊎ B)
dec⊎ with A ⁇ | B ⁇
... | yes p | _ = yes (inj₁ p)
... | _ | yes p = yes (inj₂ p)
... | no ¬p₁ | no ¬p₂ = no [ ¬p₁ , ¬p₂ ]′
instance
Dec× :
∀ {α β A B}
→ Decidable {α} A
=> Decidable {β} B
=> Decidable (A × B)
Dec× {_}{_}{A}{B} = rec dec× where
dec× : Dec (A × B)
dec× with A ⁇ | B ⁇
... | yes p | yes p₁ = yes (p , p₁)
... | yes p | no ¬p = no (¬p ∘ proj₂)
... | no ¬p | _ = no (¬p ∘ proj₁)
| 21.069767
| 80
| 0.500442
|
1b2c2eabec808ae507d15f48ab9fc808d32b7cd4
| 579
|
agda
|
Agda
|
test/Succeed/Issue3034.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue3034.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue3034.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --without-K #-}
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
| 26.318182
| 107
| 0.46114
|
1a1710042ed4982d3fa3dc25a8ca41a4a42fde6a
| 122
|
agda
|
Agda
|
test/interaction/Issue2447/Operator-error.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue2447/Operator-error.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue2447/Operator-error.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue2447.Operator-error where
import Issue2447.M
_+_ : Set → Set → Set
A + _ = A
F : Set → Set
F A = A + A + A
| 12.2
| 37
| 0.614754
|
43ce18b77348f65eed7976e13d6bc81138a2db0c
| 554
|
agda
|
Agda
|
src/Ethambda/System.agda
|
fredefox/ethambda-agda
|
18e1f9271a3ce76319cdfbcffe027c2088a418aa
|
[
"BSD-3-Clause"
] | null | null | null |
src/Ethambda/System.agda
|
fredefox/ethambda-agda
|
18e1f9271a3ce76319cdfbcffe027c2088a418aa
|
[
"BSD-3-Clause"
] | null | null | null |
src/Ethambda/System.agda
|
fredefox/ethambda-agda
|
18e1f9271a3ce76319cdfbcffe027c2088a418aa
|
[
"BSD-3-Clause"
] | null | null | null |
-- | The core type system.
module Ethambda.System where
open import Ethambda.Common using () -- ((<.>), (<.))
data Tp : Type -> Type where
Var : a -> Tp a
Fun : Tp a -> Tp a -> Tp a
Show a => Show (Tp a) where
show t = case t of
-- Var a => ?foo
Var a => show a
Fun a0 b0 => mbrackets a0 <+> "→" <+> show b0
-- where
-- brackets : String -> String
-- brackets s = "(" <+> s <+> ")"
-- mbrackets : Show a => Tp a -> String
-- mbrackets a = case a of
-- Var _ => neutral
-- Fun _ _ => brackets (show a)
| 25.181818
| 53
| 0.509025
|
36d1f59755b4ed900f3566d67748c0a799c0a4ac
| 6,724
|
agda
|
Agda
|
agda-stdlib/src/Data/List/Relation/Unary/All.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/List/Relation/Unary/All.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/Relation/Unary/All.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lists where all elements satisfy a given property
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.All where
open import Category.Applicative
open import Category.Monad
open import Data.Empty using (⊥)
open import Data.List.Base as List using (List; []; _∷_)
open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
open import Data.List.Membership.Propositional using (_∈_)
open import Data.Product as Prod
using (∃; -,_; _×_; _,_; proj₁; proj₂; uncurry)
open import Function
open import Level
open import Relation.Nullary hiding (Irrelevant)
import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Product using (_×-dec_)
open import Relation.Unary hiding (_∈_)
open import Relation.Binary.PropositionalEquality as P
private
variable
a b p q r : Level
A : Set a
B : Set b
------------------------------------------------------------------------
-- Definitions
-- Given a predicate P, then All P xs means that every element in xs
-- satisfies P. See `Relation.Unary` for an explanation of predicates.
infixr 5 _∷_
data All {A : Set a} (P : Pred A p) : Pred (List A) (a ⊔ p) where
[] : All P []
_∷_ : ∀ {x xs} (px : P x) (pxs : All P xs) → All P (x ∷ xs)
-- All P xs is a finite map from indices x ∈ xs to content P x.
-- Relation pxs [ i ]= px states that, in map pxs, key i : x ∈ xs points to value px.
infix 4 _[_]=_
data _[_]=_ {A : Set a} {P : Pred A p} :
∀ {x xs} → All P xs → x ∈ xs → P x → Set (a ⊔ p) where
here : ∀ {x xs} {px : P x} {pxs : All P xs} →
px ∷ pxs [ here refl ]= px
there : ∀ {x xs y} {px : P x} {pxs : All P xs} {py : P y} {i : x ∈ xs} →
pxs [ i ]= px →
py ∷ pxs [ there i ]= px
-- A list is empty if having an element is impossible.
Null : Pred (List A) _
Null = All (λ _ → ⊥)
------------------------------------------------------------------------
-- Operations on All
module _ {P : Pred A p} where
uncons : ∀ {x xs} → All P (x ∷ xs) → P x × All P xs
uncons (px ∷ pxs) = px , pxs
head : ∀ {x xs} → All P (x ∷ xs) → P x
head = proj₁ ∘ uncons
tail : ∀ {x xs} → All P (x ∷ xs) → All P xs
tail = proj₂ ∘ uncons
tabulate : ∀ {xs} → (∀ {x} → x ∈ xs → P x) → All P xs
tabulate {xs = []} hyp = []
tabulate {xs = x ∷ xs} hyp = hyp (here refl) ∷ tabulate (hyp ∘ there)
reduce : (f : ∀ {x} → P x → B) → ∀ {xs} → All P xs → List B
reduce f [] = []
reduce f (px ∷ pxs) = f px ∷ reduce f pxs
construct : (f : B → ∃ P) (xs : List B) → ∃ (All P)
construct f [] = [] , []
construct f (x ∷ xs) = Prod.zip _∷_ _∷_ (f x) (construct f xs)
fromList : (xs : List (∃ P)) → All P (List.map proj₁ xs)
fromList [] = []
fromList ((x , p) ∷ xps) = p ∷ fromList xps
toList : ∀ {xs} → All P xs → List (∃ P)
toList pxs = reduce (λ {x} px → x , px) pxs
module _ {P : Pred A p} {Q : Pred A q} where
map : P ⊆ Q → All P ⊆ All Q
map g [] = []
map g (px ∷ pxs) = g px ∷ map g pxs
module _ {P : Pred A p} {Q : Pred A q} {R : Pred A r} where
zipWith : P ∩ Q ⊆ R → All P ∩ All Q ⊆ All R
zipWith f ([] , []) = []
zipWith f (px ∷ pxs , qx ∷ qxs) = f (px , qx) ∷ zipWith f (pxs , qxs)
unzipWith : R ⊆ P ∩ Q → All R ⊆ All P ∩ All Q
unzipWith f [] = [] , []
unzipWith f (rx ∷ rxs) = Prod.zip _∷_ _∷_ (f rx) (unzipWith f rxs)
module _ {P : Pred A p} {Q : Pred A q} where
zip : All P ∩ All Q ⊆ All (P ∩ Q)
zip = zipWith id
unzip : All (P ∩ Q) ⊆ All P ∩ All Q
unzip = unzipWith id
self : ∀ {xs : List A} → All (const A) xs
self = tabulate (λ {x} _ → x)
------------------------------------------------------------------------
-- (weak) updateAt
module _ {P : Pred A p} where
infixl 6 _[_]%=_ _[_]≔_
updateAt : ∀ {x xs} → x ∈ xs → (P x → P x) → All P xs → All P xs
updateAt () f []
updateAt (here refl) f (px ∷ pxs) = f px ∷ pxs
updateAt (there i) f (px ∷ pxs) = px ∷ updateAt i f pxs
_[_]%=_ : ∀ {x xs} → All P xs → x ∈ xs → (P x → P x) → All P xs
pxs [ i ]%= f = updateAt i f pxs
_[_]≔_ : ∀ {x xs} → All P xs → x ∈ xs → P x → All P xs
pxs [ i ]≔ px = pxs [ i ]%= const px
------------------------------------------------------------------------
-- Traversable-like functions
module _ (p : Level) {A : Set a} {P : Pred A (a ⊔ p)}
{F : Set (a ⊔ p) → Set (a ⊔ p)}
(App : RawApplicative F)
where
open RawApplicative App
sequenceA : All (F ∘′ P) ⊆ F ∘′ All P
sequenceA [] = pure []
sequenceA (x ∷ xs) = _∷_ <$> x ⊛ sequenceA xs
mapA : ∀ {Q : Pred A q} → (Q ⊆ F ∘′ P) → All Q ⊆ (F ∘′ All P)
mapA f = sequenceA ∘′ map f
forA : ∀ {Q : Pred A q} {xs} → All Q xs → (Q ⊆ F ∘′ P) → F (All P xs)
forA qxs f = mapA f qxs
module _ (p : Level) {A : Set a} {P : Pred A (a ⊔ p)}
{M : Set (a ⊔ p) → Set (a ⊔ p)}
(Mon : RawMonad M)
where
private App = RawMonad.rawIApplicative Mon
sequenceM : All (M ∘′ P) ⊆ M ∘′ All P
sequenceM = sequenceA p App
mapM : ∀ {Q : Pred A q} → (Q ⊆ M ∘′ P) → All Q ⊆ (M ∘′ All P)
mapM = mapA p App
forM : ∀ {Q : Pred A q} {xs} → All Q xs → (Q ⊆ M ∘′ P) → M (All P xs)
forM = forA p App
------------------------------------------------------------------------
-- Generalised lookup based on a proof of Any
module _ {P : Pred A p} {Q : Pred A q} where
lookupAny : ∀ {xs} → All P xs → (i : Any Q xs) → (P ∩ Q) (Any.lookup i)
lookupAny (px ∷ pxs) (here qx) = px , qx
lookupAny (px ∷ pxs) (there i) = lookupAny pxs i
module _ {P : Pred A p} {Q : Pred A q} {R : Pred A r} where
lookupWith : ∀[ P ⇒ Q ⇒ R ] → ∀ {xs} → All P xs → (i : Any Q xs) →
R (Any.lookup i)
lookupWith f pxs i = Prod.uncurry f (lookupAny pxs i)
module _ {P : Pred A p} where
lookup : ∀ {xs} → All P xs → (∀ {x} → x ∈ xs → P x)
lookup pxs = lookupWith (λ { px refl → px }) pxs
------------------------------------------------------------------------
-- Properties of predicates preserved by All
module _ {P : Pred A p} where
all : Decidable P → Decidable (All P)
all p [] = yes []
all p (x ∷ xs) = Dec.map′ (uncurry _∷_) uncons (p x ×-dec all p xs)
universal : Universal P → Universal (All P)
universal u [] = []
universal u (x ∷ xs) = u x ∷ universal u xs
irrelevant : Irrelevant P → Irrelevant (All P)
irrelevant irr [] [] = P.refl
irrelevant irr (px₁ ∷ pxs₁) (px₂ ∷ pxs₂) =
P.cong₂ _∷_ (irr px₁ px₂) (irrelevant irr pxs₁ pxs₂)
satisfiable : Satisfiable (All P)
satisfiable = [] , []
| 30.703196
| 85
| 0.495687
|
4e8fc920b271e7aa581d36c35bdc387b50fbac9d
| 1,730
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Suffix/Heterogeneous.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Suffix/Heterogeneous.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Suffix/Heterogeneous.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- An inductive definition of the heterogeneous suffix relation
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.Suffix.Heterogeneous where
open import Level
open import Relation.Binary using (REL; _⇒_)
open import Data.List.Base as List using (List; []; _∷_)
open import Data.List.Relation.Binary.Pointwise as Pointwise
using (Pointwise; []; _∷_)
module _ {a b r} {A : Set a} {B : Set b} (R : REL A B r) where
data Suffix : REL (List A) (List B) (a ⊔ b ⊔ r) where
here : ∀ {as bs} → Pointwise R as bs → Suffix as bs
there : ∀ {b as bs} → Suffix as bs → Suffix as (b ∷ bs)
data SuffixView (as : List A) : List B → Set (a ⊔ b ⊔ r) where
_++_ : ∀ cs {ds} → Pointwise R as ds → SuffixView as (cs List.++ ds)
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
tail : ∀ {a as bs} → Suffix R (a ∷ as) bs → Suffix R as bs
tail (here (_ ∷ rs)) = there (here rs)
tail (there x) = there (tail x)
module _ {a b r s} {A : Set a} {B : Set b} {R : REL A B r} {S : REL A B s} where
map : R ⇒ S → Suffix R ⇒ Suffix S
map R⇒S (here rs) = here (Pointwise.map R⇒S rs)
map R⇒S (there suf) = there (map R⇒S suf)
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
toView : ∀ {as bs} → Suffix R as bs → SuffixView R as bs
toView (here rs) = [] ++ rs
toView (there {c} suf) with toView suf
... | cs ++ rs = (c ∷ cs) ++ rs
fromView : ∀ {as bs} → SuffixView R as bs → Suffix R as bs
fromView ([] ++ rs) = here rs
fromView ((c ∷ cs) ++ rs) = there (fromView (cs ++ rs))
| 36.041667
| 80
| 0.537572
|
0dbb6bb5aefee298f23f4b438814dc9404f7e283
| 4,518
|
agda
|
Agda
|
Numeral/Natural/Oper/Modulo/Proofs/Algorithm.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Numeral/Natural/Oper/Modulo/Proofs/Algorithm.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Numeral/Natural/Oper/Modulo/Proofs/Algorithm.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Numeral.Natural.Oper.Modulo.Proofs.Algorithm where
import Lvl
open import Logic
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Modulo
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Oper.Proofs.Order
open import Numeral.Natural.Relation
open import Numeral.Natural.Relation.Order
open import Numeral.Natural.Relation.Order.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Function
open import Structure.Operator.Properties
open import Structure.Relator.Properties
open import Syntax.Function
open import Syntax.Transitivity
open import Type
-- The many steps variant of: `[ r , b ] 𝐒(a') mod' 𝐒(b') = [ 𝐒(r) , b ] a' mod' b'` from the definition.
mod'-ind-step : ∀{r b' a b c} → [ r , b' ] (a + c) mod' (b + c) ≡ [ (r + c) , b' ] a mod' b
mod'-ind-step {_}{_} {_}{_}{𝟎} = [≡]-intro
mod'-ind-step {r}{b'}{a}{b}{𝐒 c} = mod'-ind-step {𝐒 r}{b'}{a}{b}{c = c}
-- The many steps variant of: `[ r , b ] 𝐒(a') mod' 𝐒(b') = [ 𝐒(r) , b ] a' mod' b'` from the definition when the dividend is greater than the modulus.
mod'-ind-step-modulo : ∀{r m' a m} → [ r , m' ] (a + m) mod' m ≡ [ (r + m) , m' ] a mod' 𝟎
mod'-ind-step-modulo {r}{m'}{a}{𝟎} =
[ r , m' ] (a + 𝟎) mod' 𝟎 🝖[ _≡_ ]-[]
[ (r + 𝟎) , m' ] a mod' 𝟎 🝖-end
mod'-ind-step-modulo {r}{m'}{a}{𝐒 m} =
[ r , m' ] (a + 𝐒(m)) mod' 𝐒(m) 🝖[ _≡_ ]-[]
[ r , m' ] 𝐒(a + m) mod' 𝐒(m) 🝖[ _≡_ ]-[]
[ 𝐒(r) , m' ] (a + m) mod' m 🝖[ _≡_ ]-[ mod'-ind-step-modulo {𝐒 r}{m'}{a}{m} ]
[ 𝐒(r + m) , m' ] a mod' 𝟎 🝖[ _≡_ ]-[]
[ (r + 𝐒(m)) , m' ] a mod' 𝟎 🝖-end
-- When states and modulus is zero, the result is zero.
mod'-zero-all-except-dividend : ∀{a} → ([ 0 , 0 ] a mod' 0 ≡ 0)
mod'-zero-all-except-dividend {𝟎} = [≡]-intro
mod'-zero-all-except-dividend {𝐒(a)} = mod'-zero-all-except-dividend {a}
mod'-greater-dividend : ∀{r b' a b} → (a > b) → ([ r , b' ] a mod' b ≡ [ 𝟎 , b' ] (a −₀ 𝐒(b)) mod' b')
mod'-greater-dividend {r} {b'} {.(𝐒 _)} {𝟎} (succ ab) = [≡]-intro
mod'-greater-dividend {r} {b'} {.(𝐒 _)} {𝐒 b} (succ ab) = mod'-greater-dividend ab
mod'-zero-modulo-greater-dividend : ∀{r a b} → (a > b) → ([ r , 𝟎 ] a mod' b ≡ 𝟎)
mod'-zero-modulo-greater-dividend {r} {.𝟏} {𝟎} (succ {y = 𝟎} ab) = [≡]-intro
mod'-zero-modulo-greater-dividend {r} {.(𝐒 (𝐒 a))} {𝟎} (succ {y = 𝐒 a} ab) = mod'-zero-all-except-dividend {a}
mod'-zero-modulo-greater-dividend {r} {.(𝐒 _)} {𝐒 b} (succ ab) = mod'-zero-modulo-greater-dividend ab
mod'-lesser-dividend : ∀{r b' a b} → (a ≤ b) → ([ r , b' ] a mod' b ≡ r + a)
mod'-lesser-dividend {r} {b'} min = [≡]-intro
mod'-lesser-dividend {r} {b'} (succ ab) = mod'-lesser-dividend {𝐒 r} {b'} ab
-- When the number is the temporary modulus, the result is zero.
mod'-equal-dividend : ∀{r b' b} → ([ r , b' ] 𝐒(b) mod' b) ≡ 𝟎
mod'-equal-dividend {r}{b'}{b} = mod'-greater-dividend {r}{b'} (reflexivity(_≤_) {𝐒 b})
mod'-sumᵣ-modulo : ∀{r b' a b} → ([ r , b' ] (a + 𝐒(b)) mod' b) ≡ ([ 𝟎 , b' ] a mod' b')
mod'-sumᵣ-modulo {r}{b'}{a}{b} = mod'-greater-dividend {r}{b'}{a + 𝐒(b)}{b} (succ([≤]-of-[+]ᵣ {a}{b})) 🝖 congruence₁(a ↦ [ 𝟎 , b' ] a mod' b') (inverseOperᵣ(_+_)(_−₀_) {a}{b})
-- When the
mod'-sumₗ-modulo : ∀{r b' a b} → ([ r , b' ] (𝐒(b) + a) mod' b) ≡ ([ 𝟎 , b' ] a mod' b')
mod'-sumₗ-modulo {r}{b'}{a}{b} = congruence₁(a ↦ [ r , b' ] a mod' b) (commutativity(_+_) {𝐒(b)}{a}) 🝖 mod'-sumᵣ-modulo {r}{b'}{a}{b}
mod'-maxᵣ : ∀{r b a b'} → ⦃ _ : (b' ≤ b) ⦄ → (([ r , r + b ] a mod' b') ≤ r + b)
mod'-maxᵣ {r} {b} {𝟎} {b'} ⦃ b'b ⦄ = [≤]-of-[+]ₗ
mod'-maxᵣ {r} {𝟎} {𝐒 a} {.0} ⦃ min ⦄ = mod'-maxᵣ {𝟎} {r} {a} {r} ⦃ reflexivity(_≤_) ⦄
mod'-maxᵣ {r} {𝐒 b} {𝐒 a} {.0} ⦃ min ⦄ = mod'-maxᵣ {𝟎} {𝐒(r + b)} {a} {𝐒(r + b)} ⦃ reflexivity(_≤_) ⦄
mod'-maxᵣ {r} {𝐒 b} {𝐒 a} {𝐒 b'} ⦃ succ {b'} p ⦄ = mod'-maxᵣ {𝐒 r} {b} {a} {b'} ⦃ p ⦄
mod'-maxₗ : ∀{r b a b'} → (([ r , b ] a mod' b') ≤ r + a)
mod'-maxₗ {𝟎} {_} {𝟎} {_} = min
mod'-maxₗ {𝐒 r}{b} {𝟎} {𝐒 b'} = mod'-maxₗ {𝐒 r}{𝟎}{𝟎}{b'}
mod'-maxₗ {𝐒 r}{𝐒 b}{𝟎} {b'} = mod'-maxₗ {𝐒 r}{b}{𝟎}{b'}
mod'-maxₗ {𝐒 r}{b} {𝐒 a}{𝟎} = mod'-maxₗ {𝟎} {b} {a} {b} 🝖 [≤]-successor ([≤]-successor ([≤]-of-[+]ᵣ {r}))
mod'-maxₗ {r} {b} {𝐒 a}{𝐒 b'} = mod'-maxₗ {𝐒 r} {b} {a} {b'}
mod'-maxₗ {𝟎} {𝟎} {𝐒 a}{𝟎} = [≤]-successor(mod'-maxₗ {𝟎} {𝟎} {a} {𝟎})
mod'-maxₗ {𝟎} {𝐒 b}{𝐒 a}{𝟎} = [≤]-successor(mod'-maxₗ {0} {𝐒 b} {a} {𝐒 b})
mod'-maxₗ {𝐒 r}{𝟎} {𝟎} {𝟎} = succ(mod'-maxₗ {r}{𝟎}{𝟎}{𝟎})
| 54.433735
| 175
| 0.519699
|
21ccd0a4aabac35e51b1689421f4572fc266d4e5
| 174
|
agda
|
Agda
|
thesisExamples/TooFewArgsWrongType.agda
|
JoeyEremondi/lambda-pi-constraint
|
64a1b4c6632153d75cba540f7c91f40b49375e2f
|
[
"BSD-3-Clause"
] | 16
|
2017-03-16T11:14:56.000Z
|
2021-02-05T20:21:46.000Z
|
thesisExamples/TooFewArgsWrongType.agda
|
JoeyEremondi/lambda-pi-constraint
|
64a1b4c6632153d75cba540f7c91f40b49375e2f
|
[
"BSD-3-Clause"
] | null | null | null |
thesisExamples/TooFewArgsWrongType.agda
|
JoeyEremondi/lambda-pi-constraint
|
64a1b4c6632153d75cba540f7c91f40b49375e2f
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --type-in-type #-}
module TooFewArgsWrongType where
open import AgdaPrelude
myFun : Vec Nat Zero -> Nat -> Nat
myFun x y = y
myApp : Nat
myApp = (myFun Zero)
| 15.818182
| 34
| 0.683908
|
1bcd733d3adefd605ef6c9dccaea9680ca66cc96
| 4,973
|
agda
|
Agda
|
agda-stdlib/src/Data/Rational/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Rational/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Rational/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Rational numbers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Rational.Base where
open import Function using (id)
open import Data.Integer.Base as ℤ using (ℤ; ∣_∣; +_; -[1+_])
import Data.Integer.GCD as ℤ
import Data.Integer.DivMod as ℤ
open import Data.Nat.GCD
open import Data.Nat.Divisibility as ℕDiv using (divides; 0∣⇒≡0)
open import Data.Nat.Coprimality as C using (Coprime; Bézout-coprime; coprime-/gcd)
open import Data.Nat.Base as ℕ using (ℕ; zero; suc) hiding (module ℕ)
import Data.Nat.DivMod as ℕ
open import Data.Rational.Unnormalised using (ℚᵘ; mkℚᵘ; _≢0)
open import Data.Product
open import Data.Sum.Base using (inj₂)
open import Level using (0ℓ)
open import Relation.Nullary using (¬_)
open import Relation.Nullary.Decidable using (False; fromWitnessFalse; toWitnessFalse)
open import Relation.Nullary.Negation using (contradiction)
open import Relation.Binary using (Rel)
open import Relation.Binary.PropositionalEquality
using (_≡_; _≢_; refl; subst; cong; cong₂; module ≡-Reasoning)
open ≡-Reasoning
-- Note, these are re-exported publicly to maintain backwards
-- compatability. Although we are unable (?) to put a warning on them,
-- using these from `Data.Rational` should be viewed as a deprecated
-- feature.
open import Data.Integer public using (+0; +[1+_])
------------------------------------------------------------------------
-- Rational numbers in reduced form. Note that there is exactly one
-- way to represent every rational number.
record ℚ : Set where
constructor mkℚ
field
numerator : ℤ
denominator-1 : ℕ
.isCoprime : Coprime ∣ numerator ∣ (suc denominator-1)
denominatorℕ : ℕ
denominatorℕ = suc denominator-1
denominator : ℤ
denominator = + denominatorℕ
open ℚ public using ()
renaming
( numerator to ↥_
; denominator to ↧_
; denominatorℕ to ↧ₙ_
)
mkℚ+ : ∀ n d → .{d≢0 : d ≢0} → .(Coprime n d) → ℚ
mkℚ+ n (suc d) coprime = mkℚ (+ n) d coprime
------------------------------------------------------------------------
-- Equality of rational numbers (coincides with _≡_)
infix 4 _≃_
_≃_ : Rel ℚ 0ℓ
p ≃ q = (↥ p ℤ.* ↧ q) ≡ (↥ q ℤ.* ↧ p)
------------------------------------------------------------------------
-- Ordering of rationals
infix 4 _≤_ _<_ _≥_ _>_ _≰_ _≱_ _≮_ _≯_
data _≤_ : Rel ℚ 0ℓ where
*≤* : ∀ {p q} → (↥ p ℤ.* ↧ q) ℤ.≤ (↥ q ℤ.* ↧ p) → p ≤ q
data _<_ : Rel ℚ 0ℓ where
*<* : ∀ {p q} → (↥ p ℤ.* ↧ q) ℤ.< (↥ q ℤ.* ↧ p) → p < q
_≥_ : Rel ℚ 0ℓ
x ≥ y = y ≤ x
_>_ : Rel ℚ 0ℓ
x > y = y < x
_≰_ : Rel ℚ 0ℓ
x ≰ y = ¬ (x ≤ y)
_≱_ : Rel ℚ 0ℓ
x ≱ y = ¬ (x ≥ y)
_≮_ : Rel ℚ 0ℓ
x ≮ y = ¬ (x < y)
_≯_ : Rel ℚ 0ℓ
x ≯ y = ¬ (x > y)
------------------------------------------------------------------------
-- Negation
-_ : ℚ → ℚ
- mkℚ -[1+ n ] d prf = mkℚ +[1+ n ] d prf
- mkℚ +0 d prf = mkℚ +0 d prf
- mkℚ +[1+ n ] d prf = mkℚ -[1+ n ] d prf
------------------------------------------------------------------------
-- Constructing rationals
-- A constructor for ℚ that takes two natural numbers, say 6 and 21,
-- and returns them in a normalized form, e.g. say 2 and 7
normalize : ∀ (m n : ℕ) {n≢0 : n ≢0} → ℚ
normalize m n {n≢0} = mkℚ+ (m ℕ./ gcd m n) (n ℕ./ gcd m n)
{n/g≢0} (coprime-/gcd m n {g≢0})
where
g≢0 = fromWitnessFalse (gcd[m,n]≢0 m n (inj₂ (toWitnessFalse n≢0)))
n/g≢0 = fromWitnessFalse (n/gcd[m,n]≢0 m n {n≢0} {g≢0})
-- A constructor for ℚ that (unlike mkℚ) automatically normalises it's
-- arguments. See the constants section below for how to use this operator.
infixl 7 _/_
_/_ : (n : ℤ) (d : ℕ) → {d≢0 : d ≢0} → ℚ
(+ n / d) {d≢0} = normalize n d {d≢0}
(-[1+ n ] / d) {d≢0} = - normalize (suc n) d {d≢0}
------------------------------------------------------------------------------
-- Some constants
0ℚ : ℚ
0ℚ = + 0 / 1
1ℚ : ℚ
1ℚ = + 1 / 1
½ : ℚ
½ = + 1 / 2
-½ : ℚ
-½ = - ½
------------------------------------------------------------------------------
-- Operations on rationals
infix 8 -_ 1/_
infixl 7 _*_ _÷_
infixl 6 _-_ _+_
-- addition
_+_ : ℚ → ℚ → ℚ
p + q = (↥ p ℤ.* ↧ q ℤ.+ ↥ q ℤ.* ↧ p) / (↧ₙ p ℕ.* ↧ₙ q)
-- multiplication
_*_ : ℚ → ℚ → ℚ
p * q = (↥ p ℤ.* ↥ q) / (↧ₙ p ℕ.* ↧ₙ q)
-- subtraction
_-_ : ℚ → ℚ → ℚ
p - q = p + (- q)
-- reciprocal: requires a proof that the numerator is not zero
1/_ : (p : ℚ) → .{n≢0 : ∣ ↥ p ∣ ≢0} → ℚ
1/ mkℚ +[1+ n ] d prf = mkℚ +[1+ d ] n (C.sym prf)
1/ mkℚ -[1+ n ] d prf = mkℚ -[1+ d ] n (C.sym prf)
-- division: requires a proof that the denominator is not zero
_÷_ : (p q : ℚ) → .{n≢0 : ∣ ↥ q ∣ ≢0} → ℚ
(p ÷ q) {n≢0} = p * (1/ q) {n≢0}
------------------------------------------------------------------------
-- Conversion to and from unnormalized rationals
toℚᵘ : ℚ → ℚᵘ
toℚᵘ (mkℚ n d-1 _) = mkℚᵘ n d-1
fromℚᵘ : ℚᵘ → ℚ
fromℚᵘ (mkℚᵘ n d-1) = n / suc d-1
| 26.173684
| 86
| 0.509149
|
7c347bbcde4ba3259ecc12ce4c6cac3ed55b24eb
| 4,156
|
agda
|
Agda
|
agda/sn-calculus-compatconf/pot.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 3
|
2020-04-16T10:58:53.000Z
|
2020-07-01T03:59:31.000Z
|
agda/sn-calculus-compatconf/pot.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | null | null | null |
agda/sn-calculus-compatconf/pot.agda
|
florence/esterel-calculus
|
4340bef3f8df42ab8167735d35a4cf56243a45cd
|
[
"MIT"
] | 1
|
2020-04-15T20:02:49.000Z
|
2020-04-15T20:02:49.000Z
|
module sn-calculus-compatconf.pot where
open import can-function-preserve
using (canₖ-monotonic ; canₛ-monotonic ; canₛₕ-monotonic)
open import sn-calculus
open import utility renaming (_U̬_ to _∪_)
open import context-properties
using (->pot-view)
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.CanFunction
using (Can ; Canₛ ; Canₛₕ ; Canₖ ; Canθ ; Canθₛ ; Canθₛₕ ; Canθₖ)
open import Esterel.Lang.CanFunction.Properties
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; Dom ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.Context
using (Context ; Context1 ; _⟦_⟧c ; _≐_⟦_⟧c)
open import Esterel.Context.Properties
using (unplugc)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ)
open import Relation.Nullary
using (¬_ ; Dec ; yes ; no)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; sym ; cong ; trans ; subst ; module ≡-Reasoning)
open import Data.Bool
using (Bool ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; _∷_ ; [] ; _++_)
open import Data.List.Any
using (Any ; any ; here ; there)
open import Data.List.Any.Properties
using ()
renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)
open import Data.Maybe
using (Maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; zero ; suc ; _+_) renaming (_⊔_ to _⊔ℕ_)
open import Data.Product
using (Σ-syntax ; Σ ; _,_ ; _,′_ ; proj₁ ; proj₂ ; _×_ ; ∃)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Function using (_∘_ ; id ; _∋_)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
open ->pot-view
open Context1
open _≐_⟦_⟧c
{-
(p)
ρθ. C⟦pin⟧ -- sn⟶₁ -> ρθ' C⟦pin⟧
(ρθ) C⟦pin⟧ -- sn⟶₁ -> (ρθ) C⟦qin⟧
-}
1-steplρ-pot-lemma : ∀{C θ p pin qin θ' BV FV A} →
{ρθpsn⟶₁ρθ'p : ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θ' , A ⟩· p} →
->pot-view ρθpsn⟶₁ρθ'p refl refl →
CorrectBinding pin BV FV →
p ≐ C ⟦ pin ⟧c →
pin sn⟶₁ qin →
ρ⟨ θ , A ⟩· C ⟦ qin ⟧c sn⟶₁ ρ⟨ θ' , A ⟩· C ⟦ qin ⟧c
1-steplρ-pot-lemma {C} {θ} {_} {pin} {qin}
{ρθpsn⟶₁ρθ'p = .(rabsence {S = S} S∈ θS≡unknown S∉can-p-θ)}
(vabsence S S∈ θS≡unknown S∉can-p-θ)
cb p≐C⟦pin⟧ pinsn⟶₁qin with sym (unplugc p≐C⟦pin⟧)
... | refl
= rabsence {S = S} S∈ θS≡unknown
(λ S∈can-q-θ →
S∉can-p-θ
(canθₛ-plug 0 (Env.sig θ) C pin qin
(λ θ* → canₛ-monotonic θ* _ _ cb pinsn⟶₁qin ∘ _ₛ)
(λ θ* → canₖ-monotonic θ* _ _ cb pinsn⟶₁qin)
Env.[]env (Signal.unwrap S) S∈can-q-θ))
1-steplρ-pot-lemma {C} {θ} {_} {pin} {qin}
{ρθpsn⟶₁ρθ'p = .(rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
(vreadyness {θ = .θ} s s∈ θs≡old⊎θs≡new s∉can-p-θ)
cb p≐C⟦pin⟧ pinsn⟶₁qin with sym (unplugc p≐C⟦pin⟧)
... | refl
= rreadyness {s = s} s∈ θs≡old⊎θs≡new
(λ s∈can-q-θ →
s∉can-p-θ
(canθₛₕ-plug 0 (Env.sig θ) C pin qin
(λ θ* → canₛₕ-monotonic θ* _ _ cb pinsn⟶₁qin ∘ _ₛₕ)
(λ θ* → canₖ-monotonic θ* _ _ cb pinsn⟶₁qin)
(λ θ* → canₛ-monotonic θ* _ _ cb pinsn⟶₁qin ∘ _ₛ)
Env.[]env (SharedVar.unwrap s)
s∈can-q-θ))
-- Wrapper around 1-steplρ-pot-lemma.
1-steplρ-pot : ∀{p q θ θ' BV FV A} →
{ρθpsn⟶₁ρθ'p : ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θ' , A ⟩· p} →
CorrectBinding (ρ⟨ θ , A ⟩· p) BV FV →
->pot-view ρθpsn⟶₁ρθ'p refl refl →
p sn⟶ q →
(ρ⟨ θ' , A ⟩· p sn⟶* ρ⟨ θ' , A ⟩· q ×
ρ⟨ θ , A ⟩· q sn⟶* ρ⟨ θ' , A ⟩· q)
1-steplρ-pot cb@(CBρ cb') pot psn⟶q@(rcontext _ p≐C⟦pin⟧ pinsn⟶₁qin) =
sn⟶*-inclusion (rcontext _ (dcenv p≐C⟦pin⟧) pinsn⟶₁qin) ,′
sn⟶*-inclusion
(sn⟶-inclusion
(1-steplρ-pot-lemma pot
(proj₂ (binding-extractc' cb' p≐C⟦pin⟧))
p≐C⟦pin⟧ pinsn⟶₁qin))
| 32.217054
| 97
| 0.616939
|
d19502dafbabc2237efa745859b7e56e4f902021
| 161
|
agda
|
Agda
|
Cubical/Data/List.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/Data/List.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/Data/List.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.List where
open import Cubical.Data.List.Base public
open import Cubical.Data.List.Properties public
| 26.833333
| 47
| 0.745342
|
296c825fabd87bd9dd909fc33bdeeab2016a36a3
| 264
|
agda
|
Agda
|
intro/intro.agda
|
KMx404/selfev.agda
|
b2cf336215025de01b3b3f4b2296f9afd7c2d295
|
[
"MIT"
] | 2
|
2020-08-18T11:22:21.000Z
|
2020-09-12T15:57:18.000Z
|
intro/intro.agda
|
KMx404/selfev.agda
|
b2cf336215025de01b3b3f4b2296f9afd7c2d295
|
[
"MIT"
] | null | null | null |
intro/intro.agda
|
KMx404/selfev.agda
|
b2cf336215025de01b3b3f4b2296f9afd7c2d295
|
[
"MIT"
] | null | null | null |
-- Let's play with agda.
-- Am i having fun doing this? @KMx404
module intro where --load the file with C-c - like that
data Bool: Set where
true : Bool
false : Bool
data Empty: Set Empty
Empty : Empty -- I'm gonna leave this here. Moving to tests
| 17.6
| 62
| 0.670455
|
38fef0777b93adc285a90c4fdba5fdc9b7305c74
| 7,977
|
agda
|
Agda
|
nicolai/thesis/Pointed.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
nicolai/thesis/Pointed.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | null | null | null |
nicolai/thesis/Pointed.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
{- This module serves to develop some basic theory about pointed types.
After defining the usual notions of pointed types, pointed equivalences,
and loop spaces, we derive a version of univalence for pointed equivalences
and observe that univalence between identical types is a pointed equivalence.
We define pointed versions of dependent sums and products using the usual
notion of pointed families and observe that they commute in a certain sense
with taking loop spaces. -}
module Pointed where
open import lib.Basics hiding (_⊔_)
open import lib.NType2
open import lib.types.Nat hiding (_+_)
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.TLevel
open import Preliminaries
open import UniverseOfNTypes
{- This file contains
2.2.15: Fam•
and
2.2.17: has-level-equiv-contr-loops (see end of file)
-}
{- Pointed types.
A pointed type is a type (base) together with a chosen element (pt).
The loop space construction Ω takes a pointed type and returns the type
of all loops at the given basepoint. The trivial loop is taken as
canonical element, thus forming a new pointed type. -}
Type• : (i : ULevel) → Type (lsucc i)
Type• i = Σ (Type i) (idf _)
module _ {i} (X : Type• i) where
base = fst X
pt = snd X
-- Definition 2.2.15
{- Pointed families.
A pointed family over a pointed type is a family over the base
together with a inhabitant of the family at the point.
Note that pointed types are equivalent to pointed families
over the pointed unit type (not shown here). -}
Fam• : ∀ {i} (X : Type• i) (j : ULevel) → Type (i ⊔ lsucc j)
Fam• X j = Σ (base X → Type j) (λ P → P (pt X))
-- Alternate definition: Σ (n -Type i) ⟦_⟧
_-Type•_ : (n : ℕ₋₂) (i : ULevel) → Type (lsucc i)
n -Type• i = Σ (Type• i) (has-level n ∘ base)
-- For alternate definition: Σ-≤ (n -Type-≤ i) raise
_-Type•-≤_ : (n : ℕ₋₂) (i : ULevel) → S n -Type lsucc i
n -Type•-≤ i = ((n -Type• i)
, equiv-preserves-level Σ-comm-snd
(snd (Σ-≤ (n -Type-≤ i) raise)))
{- Pointed equivalences.
An equivalence of pointed types is an equivalences of the bases
that preserves the points -}
_≃•_ : ∀ {i j} → Type• i → Type• j → Set (i ⊔ j)
A ≃• B = Σ (base A ≃ base B) (λ f → –> f (pt A) == pt B)
ide• : ∀ {i} (X : Type• i) → X ≃• X
ide• _ = ide _ , idp
_∘e•_ : ∀ {i j k} {X : Type• i} {Y : Type• j} {Z : Type• k}
→ Y ≃• Z → X ≃• Y → X ≃• Z
(u , p) ∘e• (v , q) = (u ∘e v , ap (–> u) q ∙ p)
_⁻¹• : ∀ {i j} {X : Type• i} {Y : Type• j} → X ≃• Y → Y ≃• X
(u , p) ⁻¹• = u ⁻¹ , ap (<– u) (! p) ∙ <–-inv-l u _
-- Equational reasoning for pointed equivalences.
infix 2 _≃•∎
infixr 2 _≃•⟨_⟩_
_≃•⟨_⟩_ : ∀ {i j k} (X : Type• i) {Y : Type• j} {Z : Type• k}
→ X ≃• Y → Y ≃• Z → X ≃• Z
_ ≃•⟨ u ⟩ v = v ∘e• u
_≃•∎ : ∀ {i} (X : Type• i) → X ≃• X
_≃•∎ = ide•
-- The loop space construction.
Ω : ∀ {i} → Type• i → Type• i
Ω (A , a) = ((a == a) , idp)
Ω-≤ : ∀ {i} {n : ℕ₋₂} → (S n) -Type• i → n -Type• i
Ω-≤ ((A , a) , t) = (Ω (A , a) , t a a)
-- Loop spaces are preserved by pointed equivalences.
equiv-Ω : ∀ {i j} {X : Type• i} {Y : Type• j} → X ≃• Y → Ω X ≃• Ω Y
equiv-Ω (u , p) = split u p where
split : ∀ u {a} {b} → –> u a == b → Ω (_ , a) ≃• Ω (_ , b)
split u idp = (equiv-ap u _ _ , idp)
equiv-Ω^ : ∀ {i j} {X : Type• i} {Y : Type• j} (n : ℕ)
→ X ≃• Y → (Ω ^ n) X ≃• (Ω ^ n) Y
equiv-Ω^ 0 e = e
equiv-Ω^ (S n) e = equiv-Ω^ n (equiv-Ω e)
{- We call a pointed type n-truncated if its base is.
Constructing the loop space decrements the truncation level. -}
has-level• : ∀ {i} → ℕ₋₂ → Type• i → Type i
has-level• n = has-level n ∘ base
trunc-many : ∀ {i} {X : Type• i} {k : ℕ} (n : ℕ)
→ has-level• ((k + n) -2) X
→ has-level• (k -2) ((Ω ^ n) X)
trunc-many 0 t = t
trunc-many (S n) t = trunc-many n (t _ _)
--Ω^-≤ : ∀ {i} {k : ℕ} (n : ℕ) → (k + n -2) -Type• i → (k -2) -Type• i
--Ω^-≤ O X = X
--Ω^-≤ (S n) X = Ω^-≤ n (Ω-≤ X)
Ω^-≤ : ∀ {i} {k : ℕ} (n : ℕ) → ((k + n) -2) -Type• i → (k -2) -Type• i
Ω^-≤ n (X , t) = ((Ω ^ n) X , trunc-many n t)
Ω^-≤' : ∀ {i} {k : ℕ} (n : ℕ) → ((n + k) -2) -Type• i → (k -2) -Type• i
Ω^-≤' n (X , t) =
((Ω ^ n) X , trunc-many n (transport (λ z → has-level• (z -2) X)
(+-comm _ n) t))
{- Pointedness allows for a more direct notion of contractibility.
Beware that is-contr• will be equivalent --- not definitionally equal ---
to has-level∙ ⟨-2⟩. -}
module _ {i} (X : Type• i) where
is-contr• : Type i
is-contr• = ∀ a → pt X == a
{- Since pointed types are always inhabited,
being contractible and propositional is equivalent. -}
module _ {i} {X : Type• i} where
contr•-equiv-contr : is-contr• X ≃ is-contr (base X)
contr•-equiv-contr = prop-equiv'
(λ c → Π-level (λ a → raise-level-<T (ltSR ltS) c _ _))
(cst is-contr-is-prop)
(λ x → (pt X , x))
(λ y _ → prop-has-all-paths (contr-is-prop y) _ _)
is-contr•-is-prop : is-prop (is-contr• X)
is-contr•-is-prop = equiv-preserves-level (contr•-equiv-contr ⁻¹)
is-contr-is-prop
prop-equiv-contr : is-prop (base X) ≃ is-contr (base X)
prop-equiv-contr = prop-equiv is-prop-is-prop
is-contr-is-prop
(inhab-prop-is-contr (pt X))
contr-is-prop
contr•-equiv-prop : is-contr• X ≃ is-prop (base X)
contr•-equiv-prop = prop-equiv-contr ⁻¹ ∘e contr•-equiv-contr
-- Pointed equivalences preserve (pointed) contractibility.
equiv-is-contr• : ∀ {i j} {X : Type• i} {Y : Type• j}
→ X ≃• Y → is-contr• X ≃ is-contr• Y
equiv-is-contr• (u , p) = contr•-equiv-contr ⁻¹
∘e equiv-level u
∘e contr•-equiv-contr
-- Univalence for pointed equivalences.
module _ {i} {A B : Type• i} where
ua•-equiv : (A ≃• B) ≃ (A == B)
ua•-equiv =
A ≃• B
≃⟨ ide _ ⟩
Σ (base A ≃ base B) (λ f → –> f (pt A) == pt B)
≃⟨ equiv-Σ-fst _ (snd (ua-equiv ⁻¹)) ⁻¹ ⟩
Σ (base A == base B) (λ q → coe q (pt A) == pt B)
≃⟨ equiv-Σ-snd (λ q → coe-equiv (ap (λ f → coe f (pt A) == pt B)
(! (ap-idf q)))) ⟩
Σ (base A == base B) (λ q → coe (ap (idf _) q) (pt A) == pt B)
≃⟨ equiv-Σ-snd (λ q → to-transp-equiv _ q ⁻¹) ⟩
Σ (base A == base B) (λ q → pt A == pt B [ idf _ ↓ q ])
≃⟨ =Σ-eqv _ _ ⟩
A == B
≃∎
ua• : A ≃• B → A == B
ua• = –> ua•-equiv
coe•-equiv : A == B → A ≃• B
coe•-equiv = <– ua•-equiv
-- Normal univalence can be made pointed in the endo-setting.
module _ {i} {A : Type i} where
ua-equiv• : ((A ≃ A) , ide _) ≃• ((A == A) , idp)
ua-equiv• = ((ua-equiv ⁻¹) , idp) ⁻¹•
-- Lemma 2.2.17
{- The induction step for Lemma 7.2.9 in the HoTT Book is
more complicated than necesarry. Associating iterated loop spaces in
the reverse order, we can do it with the prerequisites 7.2.7 and 7.2.8
(of the book) as well as further auxiliary steps. -}
has-level-equiv-contr-loops : ∀ {i} {n : ℕ} {A : Type i}
→ has-level (n -1) A
≃ ((a : A) → is-contr• ((Ω ^ n) (A , a)))
has-level-equiv-contr-loops {n = O} {A} =
is-prop A ≃⟨ prop-equiv-inhab-to-contr ⟩
(A → is-contr A) ≃⟨ equiv-Π-r (λ _ → contr•-equiv-contr ⁻¹) ⟩
((a : A) → is-contr• (A , a)) ≃∎
has-level-equiv-contr-loops {n = S n} {A} = equiv-Π-r lem where
lem = λ a →
(((b : A) → has-level (n -1) (a == b)))
≃⟨ equiv-Π-r (λ _ → has-level-equiv-contr-loops) ⟩
(((b : A) (p : a == b) → is-contr• ((Ω ^ n) ((a == b) , p))))
≃⟨ Π₁-contr (pathfrom-is-contr _) ∘e curry-equiv ⁻¹ ⟩
is-contr• ((Ω ^ n) ((a == a) , idp))
≃∎
| 35.453333
| 80
| 0.519619
|
0d5e62ac1c9bb4e10d78b05430b8bac399a4750f
| 809
|
agda
|
Agda
|
agda-stdlib/src/Category/Functor/Predicate.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Category/Functor/Predicate.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Category/Functor/Predicate.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Functors on indexed sets (predicates)
------------------------------------------------------------------------
-- Note that currently the functor laws are not included here.
{-# OPTIONS --without-K --safe #-}
module Category.Functor.Predicate where
open import Function
open import Level
open import Relation.Unary
open import Relation.Unary.PredicateTransformer using (PT)
private
variable
i j ℓ₁ ℓ₂ : Level
record RawPFunctor {I : Set i} {J : Set j}
(F : PT I J ℓ₁ ℓ₂) : Set (i ⊔ j ⊔ suc ℓ₁ ⊔ suc ℓ₂)
where
infixl 4 _<$>_ _<$_
field
_<$>_ : ∀ {P Q} → P ⊆ Q → F P ⊆ F Q
_<$_ : ∀ {P Q} → (∀ {i} → P i) → F Q ⊆ F P
x <$ y = const x <$> y
| 25.28125
| 72
| 0.482077
|
3f8f337ce9f29d37c14648c697750edf28095c97
| 2,922
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/Any.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/Any.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/Any.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lists where at least one element satisfies a given property
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.Any {a} {A : Set a} where
open import Data.Empty
open import Data.Fin
open import Data.List.Base as List using (List; []; [_]; _∷_)
open import Data.Product as Prod using (∃; _,_)
open import Data.Sum as Sum using (_⊎_; inj₁; inj₂)
open import Level using (_⊔_)
open import Relation.Nullary using (¬_; yes; no)
import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Negation using (contradiction)
open import Relation.Unary hiding (_∈_)
------------------------------------------------------------------------
-- Any P xs means that at least one element in xs satisfies P.
data Any {p} (P : A → Set p) : List A → Set (a ⊔ p) where
here : ∀ {x xs} (px : P x) → Any P (x ∷ xs)
there : ∀ {x xs} (pxs : Any P xs) → Any P (x ∷ xs)
------------------------------------------------------------------------
-- Operations on Any
module _ {p} {P : A → Set p} {x xs} where
head : ¬ Any P xs → Any P (x ∷ xs) → P x
head ¬pxs (here px) = px
head ¬pxs (there pxs) = contradiction pxs ¬pxs
tail : ¬ P x → Any P (x ∷ xs) → Any P xs
tail ¬px (here px) = ⊥-elim (¬px px)
tail ¬px (there pxs) = pxs
map : ∀ {p q} {P : A → Set p} {Q : A → Set q} → P ⊆ Q → Any P ⊆ Any Q
map g (here px) = here (g px)
map g (there pxs) = there (map g pxs)
module _ {p} {P : A → Set p} where
-- `index x∈xs` is the list position (zero-based) which `x∈xs` points to.
index : ∀ {xs} → Any P xs → Fin (List.length xs)
index (here px) = zero
index (there pxs) = suc (index pxs)
lookup : ∀ {xs} → Any P xs → A
lookup {xs} p = List.lookup xs (index p)
_∷=_ : ∀ {xs} → Any P xs → A → List A
_∷=_ {xs} x∈xs v = xs List.[ index x∈xs ]∷= v
infixl 4 _─_
_─_ : ∀ xs → Any P xs → List A
xs ─ x∈xs = xs List.─ index x∈xs
-- If any element satisfies P, then P is satisfied.
satisfied : ∀ {p} {P : A → Set p} {xs} → Any P xs → ∃ P
satisfied (here px) = _ , px
satisfied (there pxs) = satisfied pxs
module _ {p} {P : A → Set p} {x xs} where
toSum : Any P (x ∷ xs) → P x ⊎ Any P xs
toSum (here px) = inj₁ px
toSum (there pxs) = inj₂ pxs
fromSum : P x ⊎ Any P xs → Any P (x ∷ xs)
fromSum (inj₁ px) = here px
fromSum (inj₂ pxs) = there pxs
------------------------------------------------------------------------
-- Properties of predicates preserved by Any
module _ {p} {P : A → Set p} where
any : Decidable P → Decidable (Any P)
any P? [] = no λ()
any P? (x ∷ xs) with P? x
... | yes px = yes (here px)
... | no ¬px = Dec.map′ there (tail ¬px) (any P? xs)
satisfiable : Satisfiable P → Satisfiable (Any P)
satisfiable (x , Px) = [ x ] , here Px
| 32.10989
| 75
| 0.517796
|
fd01c8ac1b18aaa6b7c8902a982753e94e1a8a1a
| 2,981
|
agda
|
Agda
|
src/Categories/Category/Restriction/Properties.agda
|
yourboynico/agda-categories
|
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/Restriction/Properties.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/Restriction/Properties.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
-- Some properties of Restriction Categories
-- The first few lemmas are from Cocket & Lack, Lemma 2.1 and 2.2
module Categories.Category.Restriction.Properties where
open import Data.Product using (Σ; _,_)
open import Level using (Level; _⊔_)
open import Categories.Category.Core using (Category)
open import Categories.Category.Restriction using (Restriction)
open import Categories.Category.SubCategory
open import Categories.Morphism using (Mono)
open import Categories.Morphism.Idempotent using (Idempotent)
open import Categories.Morphism.Properties using (Mono-id)
import Categories.Morphism.Reasoning as MR
module _ {o ℓ e : Level} {𝒞 : Category o ℓ e} (R : Restriction 𝒞) where
open Category 𝒞
open Restriction R
open HomReasoning
open MR 𝒞 using (elimˡ; introʳ)
private
variable
A B C : Obj
f : A ⇒ B
g : B ⇒ C
↓f-idempotent : (A ⇒ B) → Idempotent 𝒞 A
↓f-idempotent f = record { idem = f ↓ ; idempotent = ⟺ ↓-denestʳ ○ ↓-cong pidʳ }
-- a special version of ↓ being a partial left identity
↓-pidˡ-gf : f ↓ ∘ (g ∘ f) ↓ ≈ (g ∘ f) ↓
↓-pidˡ-gf {f = f} {g = g} = begin
f ↓ ∘ (g ∘ f) ↓ ≈⟨ ↓-comm ⟩
(g ∘ f) ↓ ∘ f ↓ ≈˘⟨ ↓-denestʳ ⟩
((g ∘ f) ∘ f ↓) ↓ ≈⟨ ↓-cong assoc ⟩
(g ∘ (f ∘ f ↓)) ↓ ≈⟨ ↓-cong (∘-resp-≈ʳ pidʳ) ⟩
(g ∘ f) ↓ ∎
-- left denesting looks different in its conclusion
↓-denestˡ : (g ↓ ∘ f) ↓ ≈ (g ∘ f) ↓
↓-denestˡ {g = g} {f = f} = begin
(g ↓ ∘ f) ↓ ≈⟨ ↓-cong ↓-skew-comm ⟩
(f ∘ (g ∘ f) ↓) ↓ ≈⟨ ↓-denestʳ ⟩
f ↓ ∘ (g ∘ f) ↓ ≈⟨ ↓-pidˡ-gf ⟩
(g ∘ f) ↓ ∎
↓-idempotent : f ↓ ↓ ≈ f ↓
↓-idempotent {f = f} = begin
f ↓ ↓ ≈˘⟨ ↓-cong identityʳ ⟩
(f ↓ ∘ id) ↓ ≈⟨ ↓-denestˡ ⟩
(f ∘ id) ↓ ≈⟨ ↓-cong identityʳ ⟩
f ↓ ∎
↓↓denest : (g ↓ ∘ f ↓) ↓ ≈ g ↓ ∘ f ↓
↓↓denest {g = g} {f = f} = begin
(g ↓ ∘ f ↓) ↓ ≈⟨ ↓-denestʳ ⟩
g ↓ ↓ ∘ f ↓ ≈⟨ (↓-idempotent ⟩∘⟨refl) ⟩
g ↓ ∘ f ↓ ∎
Mono⇒f↓≈id : Mono 𝒞 f → f ↓ ≈ id
Mono⇒f↓≈id {f = f} mono = mono (f ↓) id (pidʳ ○ ⟺ identityʳ)
-- if the domain of g is at least that of f, then the restriction coincides
↓⊃⇒≈ : f ∘ g ↓ ≈ f → f ↓ ≈ f ↓ ∘ g ↓
↓⊃⇒≈ {f = f} {g = g} fg↓≈f = ⟺ (↓-cong fg↓≈f) ○ ↓-denestʳ
Mono⇒Total : Mono 𝒞 f → total f
Mono⇒Total = Mono⇒f↓≈id
∘-pres-total : {A B C : Obj} {f : B ⇒ C} {g : A ⇒ B} → total f → total g → total (f ∘ g)
∘-pres-total {f = f} {g = g} tf tg = begin
(f ∘ g) ↓ ≈˘⟨ ↓-denestˡ ⟩
(f ↓ ∘ g) ↓ ≈⟨ ↓-cong (elimˡ tf) ⟩
g ↓ ≈⟨ tg ⟩
id ∎
total-gf⇒total-f : total (g ∘ f) → total f
total-gf⇒total-f {g = g} {f = f} tgf = begin
f ↓ ≈⟨ introʳ tgf ⟩
f ↓ ∘ (g ∘ f) ↓ ≈⟨ ↓-pidˡ-gf ⟩
(g ∘ f) ↓ ≈⟨ tgf ⟩
id ∎
total-SubCat : SubCat 𝒞 Obj
total-SubCat = record
{ U = λ x → x
; R = total
; Rid = Mono⇒Total (Mono-id 𝒞)
; _∘R_ = ∘-pres-total
}
Total : Category o (ℓ ⊔ e) e
Total = SubCategory 𝒞 total-SubCat
| 30.418367
| 90
| 0.515599
|
1b3c544c607aa13455a68b8824cab1f92abdb252
| 21,417
|
agda
|
Agda
|
src/to-string.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 328
|
2018-09-14T20:06:09.000Z
|
2022-03-26T10:33:07.000Z
|
src/to-string.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 123
|
2018-09-17T10:53:20.000Z
|
2022-01-12T03:51:28.000Z
|
src/to-string.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 34
|
2018-09-17T11:51:36.000Z
|
2022-02-20T18:33:16.000Z
|
import cedille-options
module to-string (options : cedille-options.options) where
open import cedille-types
open import constants
open import syntax-util
open import ctxt
open import rename
open import general-util
open import datatype-util
open import type-util
open import free-vars
open import json
data expr-side : Set where
left : expr-side
right : expr-side
neither : expr-side
is-left : expr-side → 𝔹
is-left left = tt
is-left _ = ff
is-right : expr-side → 𝔹
is-right right = tt
is-right _ = ff
exprd-eq : exprd → exprd → 𝔹
exprd-eq TERM TERM = tt
exprd-eq TYPE TYPE = tt
exprd-eq KIND KIND = tt
exprd-eq _ _ = ff
is-eq-op : {ed : exprd} → ⟦ ed ⟧ → 𝔹
is-eq-op{TERM} (VarSigma _) = tt
is-eq-op{TERM} (Rho _ _ _ _) = tt
is-eq-op{TERM} (Phi _ _ _) = tt
is-eq-op{TERM} (Delta _ _ _) = tt
is-eq-op _ = ff
pattern arrow-var = "_arrow_"
pattern TpArrow tp me tp' = TpAbs me arrow-var (Tkt tp) tp'
pattern KdArrow tk kd = KdAbs arrow-var tk kd
is-arrow : {ed : exprd} → ⟦ ed ⟧ → 𝔹
is-arrow {TYPE} (TpArrow _ _ _) = tt
is-arrow {KIND} (KdArrow _ _) = tt
is-arrow _ = ff
is-type-level-app : ∀ {ed} → ⟦ ed ⟧ → 𝔹
is-type-level-app {TYPE} (TpApp T tT) = tt
is-type-level-app _ = ff
{- need-parens e1 e2 s
returns tt iff we need parens when e1 occurs as the given
side s of parent expression e2. -}
need-parens : {ed : exprd} → {ed' : exprd} → ⟦ ed ⟧ → ⟦ ed' ⟧ → expr-side → 𝔹
need-parens {TYPE} {TYPE} (TpAbs _ _ _ _) (TpArrow _ _ _) left = tt
need-parens {TYPE} {TYPE} (TpIota _ _ _) (TpArrow _ _ _) left = tt
need-parens {KIND} {KIND} (KdAbs _ _ _) (KdArrow _ _) left = tt
need-parens {TYPE} {KIND} (TpAbs _ _ _ _) (KdArrow _ _) left = tt
need-parens {TYPE} {KIND} (TpIota _ _ _) (KdArrow _ _) left = tt
need-parens {TERM} {_} (Var x) p lr = ff
need-parens {TERM} {_} (Hole pi) p lr = ff
need-parens {TERM} {_} (IotaPair t₁ t₂ x Tₓ) p lr = ff
need-parens {TERM} {_} (IotaProj t n) p lr = ff
need-parens {TYPE} {_} (TpVar x) p lr = ff
need-parens {TYPE} {_} (TpEq t₁ t₂) p lr = ff
need-parens {TYPE} {_} (TpHole pi) p lr = ff
need-parens {KIND} {_} (KdHole pi) p lr = ff
need-parens {KIND} {_} KdStar p lr = ff
need-parens {_} {TERM} _ (IotaPair t₁ t₂ x Tₓ) lr = ff
need-parens {_} {TYPE} _ (TpEq t₁ t₂) lr = ff
need-parens {_} {TERM} _ (Beta ot ot') lr = ff
need-parens {_} {TERM} _ (Phi tₑ t₁ t₂) lr = is-left lr
need-parens {_} {TERM} _ (Rho _ _ _ _) right = ff
need-parens {_} {TERM} _ (Delta _ _ _) right = ff
need-parens {_} {TERM} _ (LetTm _ _ _ _ _) lr = ff
need-parens {_} {TERM} _ (LetTp _ _ _ _) lr = ff
need-parens {_} {TERM} _ (Lam _ _ _ _) lr = ff
need-parens {_} {TERM} _ (Mu _ _ _ _ _) right = ff
need-parens {_} {TYPE} _ (TpLam _ _ _) lr = ff
need-parens {_} {TYPE} _ (TpAbs _ _ _ _) lr = ff
need-parens {_} {KIND} _ (KdAbs _ _ _) neither = ff
need-parens {_} {TYPE} _ (TpIota _ _ _) lr = ff
need-parens {TERM} {_} (App t t') p lr = tt
need-parens {TERM} {_} (AppE t tT) p lr = tt
need-parens {TERM} {_} (Beta ot ot') p lr = ff
need-parens {TERM} {_} (Delta _ T t) p lr = tt
need-parens {TERM} {_} (Lam me x tk? t) p lr = tt
need-parens {TERM} {_} (LetTm me x T t t') p lr = tt
need-parens {TERM} {_} (LetTp x T t t') p lr = tt
need-parens {TERM} {_} (Phi tₑ t₁ t₂) p lr = tt
need-parens {TERM} {_} (Rho tₑ x Tₓ t) p lr = tt
need-parens {TERM} {_} (VarSigma t) p lr = ~ is-eq-op p
need-parens {TERM} {_} (Mu _ _ _ _ _) p lr = tt
need-parens {TERM} {_} (Sigma _ _ _ _ _) p lr = tt
need-parens {TYPE} {e} (TpAbs me x tk T) p lr = ~ exprd-eq e TYPE || ~ is-arrow p || is-left lr
need-parens {TYPE} {_} (TpIota x T₁ T₂) p lr = tt
need-parens {TYPE} {_} (TpApp T tT) p lr = ~ is-arrow p && (~ is-type-level-app p || is-right lr)
need-parens {TYPE} {_} (TpLam x tk T) p lr = tt
need-parens {KIND} {_} (KdAbs x tk k) p lr = ~ is-arrow p || is-left lr
pattern ced-ops-drop-spine = cedille-options.options.mk-options _ _ _ _ ff _ _ _ ff _ _ _
pattern ced-ops-conv-arr = cedille-options.options.mk-options _ _ _ _ _ _ _ _ ff _ _ _
pattern ced-ops-conv-abs = cedille-options.options.mk-options _ _ _ _ _ _ _ _ tt _ _ _
drop-spine : cedille-options.options → {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
drop-spine ops @ ced-ops-drop-spine = h
where
drop-mod-argse : (mod : args) → (actual : args) → args
drop-mod-argse (ArgE _ :: asₘ) (ArgE _ :: asₐ) = drop-mod-argse asₘ asₐ
drop-mod-argse (Arg _ :: asₘ) (Arg t :: asₐ) = drop-mod-argse asₘ asₐ
drop-mod-argse (_ :: asₘ) asₐ@(Arg t :: _) = drop-mod-argse asₘ asₐ
-- ^ Relevant term arg, so wait until we find its corresponding relevant module arg ^
drop-mod-argse _ asₐ = asₐ
drop-mod-args-term : ctxt → var × args → term
drop-mod-args-term Γ (v , as) =
let uqv = unqual-all (ctxt.qual Γ) v in
flip recompose-apps (Var uqv) $
maybe-else' (ifMaybe (~ v =string uqv) $ ctxt-get-qi Γ uqv)
as λ qi → drop-mod-argse (snd qi) as
drop-mod-args-type : ctxt → var × 𝕃 tmtp → type
drop-mod-args-type Γ (v , as) =
let uqv = unqual-all (ctxt.qual Γ) v in
flip recompose-tpapps (TpVar uqv) $
maybe-else' (ifMaybe (~ v =string uqv) $ ctxt-qualif-args-length Γ Erased uqv)
as λ n → drop n as
h : {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
h {TERM} Γ t = maybe-else' (decompose-var-headed t) t (drop-mod-args-term Γ)
h {TYPE} Γ T = maybe-else' (decompose-tpvar-headed T) T (drop-mod-args-type Γ)
h Γ x = x
drop-spine ops Γ x = x
to-string-rewrite : {ed : exprd} → ctxt → cedille-options.options → ⟦ ed ⟧ → Σi exprd ⟦_⟧
to-string-rewrite{TYPE} Γ ced-ops-conv-arr (TpAbs me x (Tkt T) T') = , TpAbs me (if is-free-in x T' then x else arrow-var) (Tkt T) T'
to-string-rewrite{KIND} Γ ced-ops-conv-arr (KdAbs x tk k) = , KdAbs (if is-free-in x k then x else arrow-var) tk k
to-string-rewrite{TERM} Γ ops (VarSigma t) with to-string-rewrite Γ ops t
...| ,_ {TERM} (VarSigma t') = , t'
...| t? = , VarSigma t
to-string-rewrite Γ ops x = , drop-spine ops Γ x
-------------------------------
open import pretty
use-newlines : 𝔹
use-newlines =
~ iszero (cedille-options.options.pretty-print-columns options)
&& cedille-options.options.pretty-print options
doc-to-rope : DOC → rope
doc-to-rope = if use-newlines
then pretty (cedille-options.options.pretty-print-columns options)
else flatten-out
strM : Set
strM = {ed : exprd} → DOC → ℕ → 𝕃 tag → ctxt → maybe ⟦ ed ⟧ → expr-side → DOC × ℕ × 𝕃 tag
strEmpty : strM
strEmpty s n ts Γ pe lr = s , n , ts
to-stringh : {ed : exprd} → ⟦ ed ⟧ → strM
strM-Γ : (ctxt → strM) → strM
strM-Γ f s n ts Γ = f Γ s n ts Γ
infixr 2 _>>str_
_>>str_ : strM → strM → strM
(m >>str m') s n ts Γ pe lr with m s n ts Γ pe lr
(m >>str m') s n ts Γ pe lr | s' , n' , ts' = m' s' n' ts' Γ pe lr
strAdd : string → strM
strAdd s s' n ts Γ pe lr = s' <> TEXT [[ s ]] , n + string-length s , ts
strLine : strM
strLine s n ts Γ pe lr = s <> LINE , suc n , ts
strNest : ℕ → strM → strM
strNest i m s n ts Γ pe lr with m nil n ts Γ pe lr
...| s' , n' , ts' = s <> nest i s' , n' , ts'
strFold' : (ℕ → ℕ) → {ed : exprd} → 𝕃 (ℕ × strM) → ℕ → 𝕃 tag → ctxt → maybe ⟦ ed ⟧ → expr-side → 𝕃 (ℕ × DOC) × ℕ × 𝕃 tag
strFold' l [] n ts Γ pe lr = [] , n , ts
strFold' l ((i , x) :: []) n ts Γ pe lr with x nil n ts Γ pe lr
...| sₓ , nₓ , tsₓ = [ i , sₓ ] , nₓ , tsₓ
strFold' l ((i , x) :: xs) n ts Γ pe lr with x nil n ts Γ pe lr
...| sₓ , nₓ , tsₓ with strFold' l xs (l nₓ) tsₓ Γ pe lr
...| sₓₛ , nₓₛ , tsₓₛ = (i , sₓ) :: sₓₛ , nₓₛ , tsₓₛ
strFold : (ℕ → ℕ) → (𝕃 (ℕ × DOC) → DOC) → 𝕃 (ℕ × strM) → strM
strFold l f ms s n ts Γ pe lr with strFold' l ms n ts Γ pe lr
...| s' , n' , ts' = s <> f s' , n' , ts'
strFoldi : ℕ → (ℕ → ℕ) → (𝕃 DOC → DOC) → 𝕃 strM → strM
strFoldi i l f = strNest i ∘' strFold suc (f ∘' map snd) ∘' map (_,_ 0)
-- Either fit all args on one line, or give each their own line
strList : ℕ → 𝕃 strM → strM
strList i = strFoldi i suc λ ms → flatten (spread ms) :<|> stack ms
-- Fit as many args on each line as possible
-- (n = number of strM args)
-- (𝕃 strM so that optional args (nil) are possible)
strBreak : (n : ℕ) → fold n strM λ X → ℕ → 𝕃 strM → X
strBreak = h [] where
h : 𝕃 (ℕ × strM) → (n : ℕ) → fold n strM λ X → ℕ → 𝕃 strM → X
h ms (suc n) i m = h (map (_,_ i) m ++ ms) n
h ms zero = strFold suc filln $ reverse ms
strBracket : char → strM → char → strM
strBracket l m r s n ts Γ pe lr with m nil (suc (suc n)) ts Γ pe lr
...| s' , n' , ts' = s <> bracket (char-to-string l) s' (char-to-string r) , suc (suc n') , ts'
strΓ' : defScope → var → strM → strM
strΓ' ds v m s n ts Γ =
let gl = ds iff globalScope
v' = if gl then (ctxt.mn Γ # v) else v in
m s n ts
(record Γ {
qual = qualif-insert-params (ctxt.qual Γ) v' (unqual-local v) (if gl then ctxt.ps Γ else []);
i = trie-insert (ctxt.i Γ) v' (var-decl , missing-location)
})
strΓ : var → strM → strM
strΓ x m s n ts Γ = m s n ts (ctxt-var-decl x Γ)
ctxt-get-file-id : ctxt → (filename : string) → ℕ
ctxt-get-file-id = trie-lookup-else 0 ∘ ctxt.id-map
make-loc-tag : ctxt → (filename start-to end-to : string) → (start-from end-from : ℕ) → tag
make-loc-tag Γ fn s e = make-tag "loc"
(("fn" , json-nat (ctxt-get-file-id Γ fn)) ::
("s" , json-raw [[ s ]]) :: ("e" , json-raw [[ e ]]) :: [])
var-loc-tag : ctxt → location → var → 𝕃 (string × 𝕃 tag)
var-loc-tag Γ ("missing" , "missing") x = []
var-loc-tag Γ ("" , _) x = []
var-loc-tag Γ (_ , "") x = []
var-loc-tag Γ (fn , pi) x =
let fn-tag = "fn" , json-nat (ctxt-get-file-id Γ fn)
s-tag = "s" , json-raw [[ pi ]]
e-tag = "e" , json-raw [[ posinfo-plus-str pi x ]] in
[ "loc" , fn-tag :: s-tag :: e-tag :: [] ]
var-tags : ctxt → var → var → 𝕃 (string × 𝕃 tag)
var-tags Γ qv uqv =
(if qv =string qualif-var Γ uqv then id else ("shadowed" , []) ::_)
(var-loc-tag Γ (ctxt-var-location Γ qv) uqv)
strAddTags : string → 𝕃 (string × 𝕃 tag) → strM
strAddTags sₙ tsₙ sₒ n tsₒ Γ pe lr =
let n' = n + string-length sₙ in
sₒ <> TEXT [[ sₙ ]] , n' , map (uncurry λ k vs → make-tag k vs n n') tsₙ ++ tsₒ
strVar : var → strM
strVar v = strM-Γ λ Γ →
let uqv = unqual-local v -- $ unqual-all (ctxt-get-qualif Γ) v
uqv' = if cedille-options.options.show-qualified-vars options then v else uqv in
strAddTags uqv' (var-tags Γ (qualif-var Γ v) uqv)
strKvar : var → strM
strKvar v = strM-Γ λ Γ → strVar (unqual-all (ctxt.qual Γ) v)
-- Only necessary to unqual-local because of module parameters
strBvar : var → (class body : strM) → strM
strBvar v cm bm = strAdd (unqual-local v) >>str cm >>str strΓ' localScope v bm
strMetaVar : var → span-location → strM
strMetaVar x (fn , pi , pi') s n ts Γ pe lr =
let n' = n + string-length x in
s <> TEXT [[ x ]] , n' , make-loc-tag Γ fn pi pi' n n' :: ts
{-# TERMINATING #-}
term-to-stringh : term → strM
type-to-stringh : type → strM
kind-to-stringh : kind → strM
ctr-to-string : ctr → strM
case-to-string : case → strM
cases-to-string : cases → strM
caseArgs-to-string : case-args → strM → strM
params-to-string : params → strM
params-to-string' : strM → params → strM
params-to-string'' : params → strM → strM
optTerm-to-string : maybe term → char → char → 𝕃 strM
optClass-to-string : maybe tpkd → strM
optType-to-string : maybe char → maybe type → 𝕃 strM
arg-to-string : arg → strM
args-to-string : args → strM
binder-to-string : erased? → string
lam-to-string : erased? → string
arrowtype-to-string : erased? → string
vars-to-string : 𝕃 var → strM
bracketL : erased? → string
bracketR : erased? → string
braceL : erased? → string
braceR : erased? → string
opacity-to-string : opacity → string
hole-to-string : posinfo → strM
to-string-ed : {ed : exprd} → ⟦ ed ⟧ → strM
to-string-ed{TERM} = term-to-stringh
to-string-ed{TYPE} = type-to-stringh
to-string-ed{KIND} = kind-to-stringh
to-stringh' : {ed : exprd} → expr-side → ⟦ ed ⟧ → strM
to-stringh' {ed} lr t {ed'} s n ts Γ mp lr' =
elim-Σi (to-string-rewrite Γ options t) λ t' →
parens-if (maybe𝔹 mp (λ pe → need-parens t' pe lr)) (to-string-ed t') s n ts Γ (just t') lr
where
parens-if : 𝔹 → strM → strM
parens-if p s = if p then (strAdd "(" >>str strNest 1 s >>str strAdd ")") else s
to-stringl : {ed : exprd} → ⟦ ed ⟧ → strM
to-stringr : {ed : exprd} → ⟦ ed ⟧ → strM
to-stringl = to-stringh' left
to-stringr = to-stringh' right
to-stringh = to-stringh' neither
set-parent : ∀ {ed} → ⟦ ed ⟧ → strM → strM
set-parent t m s n ts Γ _ lr = m s n ts Γ (just t) lr
apps-to-string : ∀ {ll : 𝔹} → (if ll then term else type) → strM
apps-to-string {tt} t with decompose-apps t
...| tₕ , as = set-parent t $ strList 2
(to-stringl tₕ :: map arg-to-string as)
apps-to-string {ff} T with decompose-tpapps T
...| Tₕ , as = set-parent T $ strList 2
(to-stringl Tₕ :: map arg-to-string (tmtps-to-args ff as))
lams-to-string : term → strM
lams-to-string t =
elim-pair (decompose-lams-pretty t) λ xs b →
set-parent t $ strFold suc filln $ foldr {B = 𝕃 (ℕ × strM)}
(λ {(x , me , oc) r →
(1 , (strAdd (lam-to-string me) >>str strAdd " " >>str
strBvar x (strNest 4 (optClass-to-string oc)) (strAdd " ."))) ::
map (map-snd $ strΓ' localScope x) r}) [ 2 , to-stringr b ] xs
where
decompose-lams-pretty : term → 𝕃 (var × erased? × maybe tpkd) × term
decompose-lams-pretty = h [] where
h : 𝕃 (var × erased? × maybe tpkd) → term → 𝕃 (var × erased? × maybe tpkd) × term
h acc (Lam me x oc t) = h ((x , me , oc) :: acc) t
h acc t = reverse acc , t
term-to-stringh (App t t') = apps-to-string (App t t')
term-to-stringh (AppE t tT) = apps-to-string (AppE t tT)
term-to-stringh (Beta t t') = strBreak 3
0 [ strAdd "β" ]
2 [ strAdd "<" >>str to-stringh (erase t ) >>str strAdd ">" ]
2 [ strAdd "{|" >>str to-stringh (erase t') >>str strAdd "|}" ]
term-to-stringh (Delta _ T t) = strBreak 3
0 [ strAdd "δ" ]
2 [ to-stringl T >>str strAdd " -" ]
1 [ to-stringr t ]
term-to-stringh (Hole pi) = hole-to-string pi
term-to-stringh (IotaPair t₁ t₂ x Tₓ) = strBreak 3
1 [ strAdd "[ " >>str to-stringh t₁ >>str strAdd "," ]
1 [ to-stringh t₂ ]
1 [ strAdd "@ " >>str
strBvar x (strAdd " . ") (strNest (5 + string-length x) (to-stringh Tₓ)) >>str
strAdd " ]" ]
term-to-stringh (IotaProj t n) = to-stringh t >>str strAdd (if n iff ι1 then ".1" else ".2")
term-to-stringh (Lam me x oc t) = lams-to-string (Lam me x oc t)
term-to-stringh (LetTm me x T t t') = strBreak 4
1 [ strAdd (bracketL me) >>str strAdd (unqual-local x) ]
5 ( optType-to-string (just ':') T )
3 [ strAdd "= " >>str to-stringh t >>str strAdd (bracketR me) ]
1 [ strΓ' localScope x (to-stringr t') ]
term-to-stringh (LetTp x k T t) = strBreak 4
1 [ strAdd (bracketL NotErased) >>str strAdd (unqual-local x) ]
5 [ strAdd ": " >>str to-stringh k ]
3 [ strAdd "= " >>str to-stringh T >>str strAdd (bracketR NotErased) ]
1 [ strΓ' localScope x (to-stringr t) ]
term-to-stringh (Phi tₑ t₁ t₂) = strBreak 3
0 [ strAdd "φ " >>str to-stringl tₑ >>str strAdd " -" ]
2 [ to-stringh t₁ ]
2 [ strAdd "{| " >>str to-stringr (erase t₂) >>str strAdd " |}" ]
term-to-stringh (Rho tₑ x Tₓ t) = strBreak 3
0 [ strAdd "ρ " >>str to-stringl tₑ ]
1 [ strAdd "@ " >>str strBvar x (strAdd " . ") (to-stringh (erase Tₓ)) ]
1 [ strAdd "- " >>str strNest 2 (to-stringr t) ]
term-to-stringh (VarSigma t) = strAdd "ς " >>str to-stringh t
term-to-stringh (Var x) = strVar x
term-to-stringh (Mu x t ot t~ cs) =
strAdd "μ " >>str
strBvar x
(strAdd " . " >>str strBreak 2
2 [ to-stringl t ]
3 ( optType-to-string (just '@') ot ))
(strAdd " " >>str strBracket '{' (cases-to-string cs) '}')
term-to-stringh (Sigma ot t oT t~ cs) =
strAdd "σ " >>str strBreak 3
2 (maybe-else' {B = 𝕃 strM} ot []
λ t → [ strAdd "<" >>str to-stringh t >>str strAdd ">" ])
2 [ to-stringl t ]
3 ( optType-to-string (just '@') oT ) >>str
strAdd " " >>str strBracket '{' (cases-to-string cs) '}'
type-to-stringh (TpArrow T a T') = strBreak 2
2 [ to-stringl T >>str strAdd (arrowtype-to-string a) ]
2 [ to-stringr T' ]
type-to-stringh (TpAbs me x tk T) = strBreak 2
3 [ strAdd (binder-to-string me ^ " ") >>str
strBvar x (strAdd " : " >>str to-stringl -tk' tk >>str strAdd " .") strEmpty ]
1 [ strΓ' localScope x (to-stringh T) ]
type-to-stringh (TpIota x T₁ T₂) = strBreak 2
2 [ strAdd "ι " >>str
strBvar x (strAdd " : " >>str to-stringh T₁ >>str strAdd " .") strEmpty ]
2 [ strΓ' localScope x (to-stringh T₂) ]
type-to-stringh (TpApp T tT) = apps-to-string (TpApp T tT)
type-to-stringh (TpEq t₁ t₂) = strBreak 2
2 [ strAdd "{ " >>str to-stringh (erase t₁) ]
2 [ strAdd "≃ " >>str to-stringh (erase t₂) >>str strAdd " }" ]
type-to-stringh (TpHole pi) = hole-to-string pi
type-to-stringh (TpLam x tk T) = strBreak 2
3 [ strAdd "λ " >>str
strBvar x (strAdd " : " >>str to-stringh -tk' tk >>str strAdd " .") strEmpty ]
1 [ strΓ' localScope x (to-stringr T) ]
type-to-stringh (TpVar x) = strVar x
kind-to-stringh (KdArrow k k') = strBreak 2
2 [ to-stringl -tk' k >>str strAdd " ➔" ]
2 [ to-stringr k' ]
kind-to-stringh (KdAbs x tk k) = strBreak 2
4 [ strAdd "Π " >>str
strBvar x (strAdd " : " >>str to-stringl -tk' tk >>str strAdd " .") strEmpty ]
1 [ strΓ' localScope x (to-stringh k) ]
kind-to-stringh (KdHole pi) = hole-to-string pi
kind-to-stringh KdStar = strAdd "★"
hole-to-string pi = strM-Γ λ Γ → strAddTags "●" (var-loc-tag Γ (split-var pi) "●")
optTerm-to-string nothing c1 c2 = []
optTerm-to-string (just t) c1 c2 =
[ strAdd (𝕃char-to-string (c1 :: [ ' ' ])) >>str
to-stringh t >>str
strAdd (𝕃char-to-string (' ' :: [ c2 ])) ]
optClass-to-string nothing = strEmpty
optClass-to-string (just atk) = strAdd " : " >>str to-stringh -tk' atk
optType-to-string pfx nothing = []
optType-to-string pfx (just T) =
[ maybe-else strEmpty (λ pfx → strAdd (𝕃char-to-string (pfx :: [ ' ' ]))) pfx >>str to-stringh T ]
arg-to-string (Arg t) = to-stringr t
arg-to-string (ArgE (Ttm t)) = strAdd "-" >>str strNest 1 (to-stringr t)
arg-to-string (ArgE (Ttp T)) = strAdd "·" >>str strNest 2 (to-stringr T)
args-to-string = set-parent (App (Hole pi-gen) (Hole pi-gen)) ∘ foldr' strEmpty λ t x → strAdd " " >>str arg-to-string t >>str x
binder-to-string tt = "∀"
binder-to-string ff = "Π"
lam-to-string tt = "Λ"
lam-to-string ff = "λ"
arrowtype-to-string ff = " ➔"
arrowtype-to-string tt = " ➾"
opacity-to-string opacity-open = ""
opacity-to-string opacity-closed = "opaque "
vars-to-string [] = strEmpty
vars-to-string (v :: []) = strVar v
vars-to-string (v :: vs) = strVar v >>str strAdd " " >>str vars-to-string vs
ctr-to-string (Ctr x T) = strAdd x >>str strAdd " : " >>str to-stringh T
case-to-string (Case x as t _) =
strM-Γ λ Γ →
let as-f = λ x as → strVar x >>str caseArgs-to-string as (strAdd " ➔ " >>str to-stringr t) in
case (env-lookup Γ x , options) of uncurry λ where
(just (ctr-def mps T _ _ _ , _ , _)) ced-ops-drop-spine →
as-f (unqual-all (ctxt.qual Γ) x) as
_ _ → as-f x as
cases-to-string = h use-newlines where
h : 𝔹 → cases → strM
h _ [] = strEmpty
h tt (m :: []) = strAdd "| " >>str case-to-string m
h tt (m :: ms) = strAdd "| " >>str case-to-string m >>str strLine >>str h tt ms
h ff (m :: []) = case-to-string m
h ff (m :: ms) = case-to-string m >>str strAdd " | " >>str h ff ms
caseArgs-to-string [] m = m
caseArgs-to-string (CaseArg _ x (just (Tkk _)) :: as) m = strAdd " ·" >>str strBvar x strEmpty (caseArgs-to-string as m)
caseArgs-to-string (CaseArg ff x _ :: as) m = strAdd " " >>str strBvar x strEmpty (caseArgs-to-string as m)
caseArgs-to-string (CaseArg tt x _ :: as) m = strAdd " -" >>str strBvar x strEmpty (caseArgs-to-string as m)
braceL me = if me then "{" else "("
braceR me = if me then "}" else ")"
bracketL me = if me then "{ " else "[ "
bracketR me = if me then " } -" else " ] -"
param-to-string : param → (strM → strM) × strM
param-to-string (Param me v atk) =
strΓ' localScope v ,
(strAdd (braceL me) >>str
strAdd (unqual-local v) >>str
strAdd " : " >>str
to-stringh -tk' atk >>str
strAdd (braceR me))
params-to-string'' ps f = elim-pair (foldr (λ p → uncurry λ g ms → elim-pair (param-to-string p) λ h m → g ∘ h , m :: map h ms) (id , []) ps) λ g ms → strList 2 (strEmpty :: ms) >>str g f
params-to-string' f [] = f
params-to-string' f (p :: []) = elim-pair (param-to-string p) λ g m → m >>str g f
params-to-string' f (p :: ps) = elim-pair (param-to-string p) λ g m → m >>str strAdd " " >>str params-to-string' (g f) ps
params-to-string = params-to-string' strEmpty
strRun : ctxt → strM → rope
strRun Γ m = doc-to-rope $ fst $ m {TERM} NIL 0 [] Γ nothing neither
strRunTag : (name : string) → ctxt → strM → tagged-val
strRunTag name Γ m with m {TERM} NIL 0 [] Γ nothing neither
...| s , n , ts = name , doc-to-rope s , ts
to-stringe : {ed : exprd} → ⟦ ed ⟧ → strM
to-stringe = to-stringh ∘' (if cedille-options.options.erase-types options then erase else id)
to-string-tag : {ed : exprd} → string → ctxt → ⟦ ed ⟧ → tagged-val
to-string-tag name Γ t = strRunTag name Γ (to-stringe t)
to-string : {ed : exprd} → ctxt → ⟦ ed ⟧ → rope
to-string Γ t = strRun Γ (to-stringh t)
tpkd-to-stringe : tpkd → strM
tpkd-to-stringe = to-stringe -tk'_
tpkd-to-string : ctxt → tpkd → rope
tpkd-to-string Γ atk = strRun Γ (tpkd-to-stringe atk)
params-to-string-tag : string → ctxt → params → tagged-val
params-to-string-tag name Γ ps = strRunTag name Γ (params-to-string ps)
| 36.989637
| 187
| 0.607415
|
7cddaf75e4e9b84a95b171918939bbfa26b5ea6c
| 222
|
agda
|
Agda
|
test/interaction/Issue3161.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue3161.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue3161.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2018-07-21, issue #3161
-- Insert space before brace if preceeded by `-`.
-- (Symmetric case was already fixed in #269).
data Pol : Set where
+ - : Pol
f : {x : Pol} → Set
f {x} = {!x!} -- Split on x here
| 22.2
| 49
| 0.599099
|
30e2e1725fb4bd4d1e22d6351e484dfc2193293e
| 511
|
agda
|
Agda
|
test/Compiler/simple/QNameOrder.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Compiler/simple/QNameOrder.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Compiler/simple/QNameOrder.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module _ where
open import Agda.Builtin.Reflection
open import Agda.Builtin.Bool
open import Agda.Builtin.Unit
open import Agda.Builtin.String
open import Common.Prelude
_<_ = primQNameLess
True : Bool → Set
True true = ⊤
True false = ⊥
zzz aaa : ⊤
zzz = _
aaa = _
⊥-elim : {A : Set} → ⊥ → A
⊥-elim ()
check : (x y : Name) → True (x < y) → String
check x y prf with x < y
check x y prf | true = "A-ok"
check x y prf | false = ⊥-elim prf
main : IO Unit
main = putStrLn (check (quote zzz) (quote aaa) _)
| 17.033333
| 49
| 0.655577
|
14fee3485ff6b9c9fc75f29a7f15e59f90a64158
| 17,063
|
agda
|
Agda
|
Cubical/Foundations/Prelude.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Prelude.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Prelude.agda
|
ByteBucket123/cubical
|
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
|
[
"MIT"
] | 1
|
2021-03-12T20:08:45.000Z
|
2021-03-12T20:08:45.000Z
|
{-
This file proves a variety of basic results about paths:
- refl, sym, cong and composition of paths. This is used to set up
equational reasoning.
- Transport, subst and functional extensionality
- J and its computation rule (up to a path)
- Σ-types and contractibility of singletons
- Converting PathP to and from a homogeneous path with transp
- Direct definitions of lower h-levels
- Export natural numbers
- Export universe lifting
-}
{-# OPTIONS --safe #-}
module Cubical.Foundations.Prelude where
open import Cubical.Core.Primitives public
infixr 30 _∙_
infix 3 _∎
infixr 2 _≡⟨_⟩_
infixr 2.5 _≡⟨_⟩≡⟨_⟩_
-- Basic theory about paths. These proofs should typically be
-- inlined. This module also makes equational reasoning work with
-- (non-dependent) paths.
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : A → Type ℓ
x y z w : A
refl : x ≡ x
refl {x = x} = λ _ → x
{-# INLINE refl #-}
sym : x ≡ y → y ≡ x
sym p i = p (~ i)
{-# INLINE sym #-}
symP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} →
(p : PathP A x y) → PathP (λ i → A (~ i)) y x
symP p j = p (~ j)
cong : ∀ (f : (a : A) → B a) (p : x ≡ y) →
PathP (λ i → B (p i)) (f x) (f y)
cong f p i = f (p i)
{-# INLINE cong #-}
cong₂ : ∀ {C : (a : A) → (b : B a) → Type ℓ} →
(f : (a : A) → (b : B a) → C a b) →
(p : x ≡ y) →
{u : B x} {v : B y} (q : PathP (λ i → B (p i)) u v) →
PathP (λ i → C (p i) (q i)) (f x u) (f y v)
cong₂ f p q i = f (p i) (q i)
{-# INLINE cong₂ #-}
{- The most natural notion of homogenous path composition
in a cubical setting is double composition:
x ∙ ∙ ∙ > w
^ ^
p⁻¹ | | r ^
| | j |
y — — — > z ∙ — >
q i
`p ∙∙ q ∙∙ r` gives the line at the top,
`doubleCompPath-filler p q r` gives the whole square
-}
doubleComp-faces : {x y z w : A } (p : x ≡ y) (r : z ≡ w)
→ (i : I) (j : I) → Partial (i ∨ ~ i) A
doubleComp-faces p r i j (i = i0) = p (~ j)
doubleComp-faces p r i j (i = i1) = r j
_∙∙_∙∙_ : w ≡ x → x ≡ y → y ≡ z → w ≡ z
(p ∙∙ q ∙∙ r) i =
hcomp (doubleComp-faces p r i) (q i)
doubleCompPath-filler : (p : x ≡ y) (q : y ≡ z) (r : z ≡ w)
→ PathP (λ j → p (~ j) ≡ r j) q (p ∙∙ q ∙∙ r)
doubleCompPath-filler p q r j i =
hfill (doubleComp-faces p r i) (inS (q i)) j
-- any two definitions of double composition are equal
compPath-unique : ∀ (p : x ≡ y) (q : y ≡ z) (r : z ≡ w)
→ (α β : Σ[ s ∈ x ≡ w ] PathP (λ j → p (~ j) ≡ r j) q s)
→ α ≡ β
compPath-unique p q r (α , α-filler) (β , β-filler) t
= (λ i → cb i1 i) , (λ j i → cb j i)
where cb : I → I → _
cb j i = hfill (λ j → λ { (t = i0) → α-filler j i
; (t = i1) → β-filler j i
; (i = i0) → p (~ j)
; (i = i1) → r j })
(inS (q i)) j
{- For single homogenous path composition, we take `p = refl`:
x ∙ ∙ ∙ > z
‖ ^
‖ | r ^
‖ | j |
x — — — > y ∙ — >
q i
`q ∙ r` gives the line at the top,
`compPath-filler q r` gives the whole square
-}
_∙_ : x ≡ y → y ≡ z → x ≡ z
p ∙ q = refl ∙∙ p ∙∙ q
compPath-filler : (p : x ≡ y) (q : y ≡ z) → PathP (λ j → x ≡ q j) p (p ∙ q)
compPath-filler p q = doubleCompPath-filler refl p q
-- We could have also defined single composition by taking `r = refl`:
_∙'_ : x ≡ y → y ≡ z → x ≡ z
p ∙' q = p ∙∙ q ∙∙ refl
compPath'-filler : (p : x ≡ y) (q : y ≡ z) → PathP (λ j → p (~ j) ≡ z) q (p ∙' q)
compPath'-filler p q = doubleCompPath-filler p q refl
-- It's easy to show that `p ∙ q` also has such a filler:
compPath-filler' : (p : x ≡ y) (q : y ≡ z) → PathP (λ j → p (~ j) ≡ z) q (p ∙ q)
compPath-filler' {z = z} p q j i =
hcomp (λ k → λ { (i = i0) → p (~ j)
; (i = i1) → q k
; (j = i0) → q (i ∧ k) })
(p (i ∨ ~ j))
-- Note: We can omit a (j = i1) case here since when (j = i1), the whole expression is
-- definitionally equal to `p ∙ q`. (Notice that `p ∙ q` is also an hcomp.) Nevertheless,
-- we could have given `compPath-filler p q k i` as the (j = i1) case.
-- From this, we can show that these two notions of composition are the same
compPath≡compPath' : (p : x ≡ y) (q : y ≡ z) → p ∙ q ≡ p ∙' q
compPath≡compPath' p q j =
compPath-unique p q refl (p ∙ q , compPath-filler' p q)
(p ∙' q , compPath'-filler p q) j .fst
-- Heterogeneous path composition and its filler:
compPathP : ∀ {A : I → Type ℓ} {x : A i0} {y : A i1} {B_i1 : Type ℓ} {B : (A i1) ≡ B_i1} {z : B i1}
→ PathP A x y → PathP (λ i → B i) y z → PathP (λ j → ((λ i → A i) ∙ B) j) x z
compPathP {A = A} {x = x} {B = B} p q i =
comp (λ j → compPath-filler (λ i → A i) B j i)
(λ j → λ { (i = i0) → x ;
(i = i1) → q j })
(p i)
compPathP' : ∀ {ℓ ℓ'} {A : Type ℓ} {B : A → Type ℓ'} {x y z : A} {x' : B x} {y' : B y} {z' : B z} {p : x ≡ y} {q : y ≡ z}
(P : PathP (λ i → B (p i)) x' y') (Q : PathP (λ i → B (q i)) y' z')
→ PathP (λ i → B ((p ∙ q) i)) x' z'
compPathP' {B = B} {x' = x'} {p = p} {q = q} P Q i =
comp (λ j → B (compPath-filler p q j i))
(λ j → λ { (i = i0) → x' ;
(i = i1) → Q j })
(P i)
compPathP-filler : ∀ {A : I → Type ℓ} {x : A i0} {y : A i1} {B_i1 : Type ℓ} {B : A i1 ≡ B_i1} {z : B i1}
→ (p : PathP A x y) (q : PathP (λ i → B i) y z)
→ PathP (λ j → PathP (λ k → (compPath-filler (λ i → A i) B j k)) x (q j)) p (compPathP p q)
compPathP-filler {A = A} {x = x} {B = B} p q j i =
fill (λ j → compPath-filler (λ i → A i) B j i)
(λ j → λ { (i = i0) → x ;
(i = i1) → q j })
(inS (p i)) j
compPathP'-filler : ∀ {ℓ ℓ'} {A : Type ℓ} {B : A → Type ℓ'} {x y z : A} {x' : B x} {y' : B y} {z' : B z} {p : x ≡ y} {q : y ≡ z}
(P : PathP (λ i → B (p i)) x' y') (Q : PathP (λ i → B (q i)) y' z')
→ PathP (λ j → PathP (λ i → B (compPath-filler p q j i)) x' (Q j)) P (compPathP' {x = x} {y = y} {x' = x'} {y' = y'} P Q)
compPathP'-filler {B = B} {x' = x'} {p = p} {q = q} P Q j i =
fill (λ j → B (compPath-filler p q j i))
(λ j → λ { (i = i0) → x' ;
(i = i1) → Q j })
(inS (P i))
j
_≡⟨_⟩_ : (x : A) → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ x≡y ⟩ y≡z = x≡y ∙ y≡z
≡⟨⟩-syntax : (x : A) → x ≡ y → y ≡ z → x ≡ z
≡⟨⟩-syntax = _≡⟨_⟩_
infixr 2 ≡⟨⟩-syntax
syntax ≡⟨⟩-syntax x (λ i → B) y = x ≡[ i ]⟨ B ⟩ y
≡⟨⟩⟨⟩-syntax : (x y : A) → x ≡ y → y ≡ z → z ≡ w → x ≡ w
≡⟨⟩⟨⟩-syntax x y p q r = p ∙∙ q ∙∙ r
infixr 3 ≡⟨⟩⟨⟩-syntax
syntax ≡⟨⟩⟨⟩-syntax x y B C = x ≡⟨ B ⟩≡ y ≡⟨ C ⟩≡
_≡⟨_⟩≡⟨_⟩_ : (x : A) → x ≡ y → y ≡ z → z ≡ w → x ≡ w
_ ≡⟨ x≡y ⟩≡⟨ y≡z ⟩ z≡w = x≡y ∙∙ y≡z ∙∙ z≡w
_∎ : (x : A) → x ≡ x
_ ∎ = refl
-- Transport, subst and functional extensionality
-- transport is a special case of transp
transport : {A B : Type ℓ} → A ≡ B → A → B
transport p a = transp (λ i → p i) i0 a
-- Transporting in a constant family is the identity function (up to a
-- path). If we would have regularity this would be definitional.
transportRefl : (x : A) → transport refl x ≡ x
transportRefl {A = A} x i = transp (λ _ → A) i x
transport-filler : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) (x : A)
→ PathP (λ i → p i) x (transport p x)
transport-filler p x i = transp (λ j → p (i ∧ j)) (~ i) x
-- We want B to be explicit in subst
subst : (B : A → Type ℓ') (p : x ≡ y) → B x → B y
subst B p pa = transport (λ i → B (p i)) pa
subst2 : ∀ {ℓ' ℓ''} {B : Type ℓ'} {z w : B} (C : A → B → Type ℓ'')
(p : x ≡ y) (q : z ≡ w) → C x z → C y w
subst2 B p q b = transport (λ i → B (p i) (q i)) b
substRefl : (px : B x) → subst B refl px ≡ px
substRefl px = transportRefl px
subst-filler : (B : A → Type ℓ') (p : x ≡ y) (b : B x)
→ PathP (λ i → B (p i)) b (subst B p b)
subst-filler B p = transport-filler (cong B p)
funExt : {B : A → I → Type ℓ'}
{f : (x : A) → B x i0} {g : (x : A) → B x i1}
→ ((x : A) → PathP (B x) (f x) (g x))
→ PathP (λ i → (x : A) → B x i) f g
funExt p i x = p x i
implicitFunExt : {B : A → I → Type ℓ'}
{f : {x : A} → B x i0} {g : {x : A} → B x i1}
→ ({x : A} → PathP (B x) (f {x}) (g {x}))
→ PathP (λ i → {x : A} → B x i) f g
implicitFunExt p i {x} = p {x} i
-- the inverse to funExt (see Functions.FunExtEquiv), converting paths
-- between functions to homotopies; `funExt⁻` is called `happly` and
-- defined by path induction in the HoTT book (see function 2.9.2 in
-- section 2.9)
funExt⁻ : {B : A → I → Type ℓ'}
{f : (x : A) → B x i0} {g : (x : A) → B x i1}
→ PathP (λ i → (x : A) → B x i) f g
→ ((x : A) → PathP (B x) (f x) (g x))
funExt⁻ eq x i = eq i x
-- J for paths and its computation rule
module _ (P : ∀ y → x ≡ y → Type ℓ') (d : P x refl) where
J : (p : x ≡ y) → P y p
J p = transport (λ i → P (p i) (λ j → p (i ∧ j))) d
JRefl : J refl ≡ d
JRefl = transportRefl d
J-∙ : (p : x ≡ y) (q : y ≡ z)
→ J (p ∙ q) ≡ transport (λ i → P (q i) (λ j → compPath-filler p q i j)) (J p)
J-∙ p q k =
transp
(λ i → P (q (i ∨ ~ k))
(λ j → compPath-filler p q (i ∨ ~ k) j)) (~ k)
(J (λ j → compPath-filler p q (~ k) j))
-- Converting to and from a PathP
module _ {A : I → Type ℓ} {x : A i0} {y : A i1} where
toPathP : transp (\ i → A i) i0 x ≡ y → PathP A x y
toPathP p i = hcomp (λ j → λ { (i = i0) → x
; (i = i1) → p j })
(transp (λ j → A (i ∧ j)) (~ i) x)
fromPathP : PathP A x y → transp (\ i → A i) i0 x ≡ y
fromPathP p i = transp (λ j → A (i ∨ j)) i (p i)
-- Whiskering a dependent path by a path
_◁_ : ∀ {ℓ} {A : I → Type ℓ} {a₀ a₀' : A i0} {a₁ : A i1}
→ a₀ ≡ a₀' → PathP A a₀' a₁ → PathP A a₀ a₁
(p ◁ q) i =
hcomp (λ j → λ {(i = i0) → p (~ j); (i = i1) → q i1}) (q i)
_▷_ : ∀ {ℓ} {A : I → Type ℓ} {a₀ : A i0} {a₁ a₁' : A i1}
→ PathP A a₀ a₁ → a₁ ≡ a₁' → PathP A a₀ a₁'
(p ▷ q) i =
hcomp (λ j → λ {(i = i0) → p i0; (i = i1) → q j}) (p i)
-- Direct definitions of lower h-levels
isContr : Type ℓ → Type ℓ
isContr A = Σ[ x ∈ A ] (∀ y → x ≡ y)
isProp : Type ℓ → Type ℓ
isProp A = (x y : A) → x ≡ y
isSet : Type ℓ → Type ℓ
isSet A = (x y : A) → isProp (x ≡ y)
isGroupoid : Type ℓ → Type ℓ
isGroupoid A = ∀ a b → isSet (Path A a b)
is2Groupoid : Type ℓ → Type ℓ
is2Groupoid A = ∀ a b → isGroupoid (Path A a b)
-- Contractibility of singletons
singlP : (A : I → Type ℓ) (a : A i0) → Type _
singlP A a = Σ[ x ∈ A i1 ] PathP A a x
singl : (a : A) → Type _
singl {A = A} a = singlP (λ _ → A) a
isContrSingl : (a : A) → isContr (singl a)
isContrSingl a = (a , refl) , λ p i → p .snd i , λ j → p .snd (i ∧ j)
isContrSinglP : (A : I → Type ℓ) (a : A i0) → isContr (singlP A a)
isContrSinglP A a .fst = _ , transport-filler (λ i → A i) a
isContrSinglP A a .snd (x , p) i =
_ , λ j → fill (\ i → A i) (λ j → λ {(i = i0) → transport-filler (λ i → A i) a j; (i = i1) → p j}) (inS a) j
SquareP :
(A : I → I → Type ℓ)
{a₀₀ : A i0 i0} {a₀₁ : A i0 i1} (a₀₋ : PathP (λ j → A i0 j) a₀₀ a₀₁)
{a₁₀ : A i1 i0} {a₁₁ : A i1 i1} (a₁₋ : PathP (λ j → A i1 j) a₁₀ a₁₁)
(a₋₀ : PathP (λ i → A i i0) a₀₀ a₁₀) (a₋₁ : PathP (λ i → A i i1) a₀₁ a₁₁)
→ Type ℓ
SquareP A a₀₋ a₁₋ a₋₀ a₋₁ = PathP (λ i → PathP (λ j → A i j) (a₋₀ i) (a₋₁ i)) a₀₋ a₁₋
Square :
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ Type _
Square a₀₋ a₁₋ a₋₀ a₋₁ = PathP (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋
isSet' : Type ℓ → Type ℓ
isSet' A =
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ Square a₀₋ a₁₋ a₋₀ a₋₁
Cube :
{a₀₀₀ a₀₀₁ : A} {a₀₀₋ : a₀₀₀ ≡ a₀₀₁}
{a₀₁₀ a₀₁₁ : A} {a₀₁₋ : a₀₁₀ ≡ a₀₁₁}
{a₀₋₀ : a₀₀₀ ≡ a₀₁₀} {a₀₋₁ : a₀₀₁ ≡ a₀₁₁}
(a₀₋₋ : Square a₀₀₋ a₀₁₋ a₀₋₀ a₀₋₁)
{a₁₀₀ a₁₀₁ : A} {a₁₀₋ : a₁₀₀ ≡ a₁₀₁}
{a₁₁₀ a₁₁₁ : A} {a₁₁₋ : a₁₁₀ ≡ a₁₁₁}
{a₁₋₀ : a₁₀₀ ≡ a₁₁₀} {a₁₋₁ : a₁₀₁ ≡ a₁₁₁}
(a₁₋₋ : Square a₁₀₋ a₁₁₋ a₁₋₀ a₁₋₁)
{a₋₀₀ : a₀₀₀ ≡ a₁₀₀} {a₋₀₁ : a₀₀₁ ≡ a₁₀₁}
(a₋₀₋ : Square a₀₀₋ a₁₀₋ a₋₀₀ a₋₀₁)
{a₋₁₀ : a₀₁₀ ≡ a₁₁₀} {a₋₁₁ : a₀₁₁ ≡ a₁₁₁}
(a₋₁₋ : Square a₀₁₋ a₁₁₋ a₋₁₀ a₋₁₁)
(a₋₋₀ : Square a₀₋₀ a₁₋₀ a₋₀₀ a₋₁₀)
(a₋₋₁ : Square a₀₋₁ a₁₋₁ a₋₀₁ a₋₁₁)
→ Type _
Cube a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁ =
PathP (λ i → Square (a₋₀₋ i) (a₋₁₋ i) (a₋₋₀ i) (a₋₋₁ i)) a₀₋₋ a₁₋₋
isGroupoid' : Type ℓ → Type ℓ
isGroupoid' A =
{a₀₀₀ a₀₀₁ : A} {a₀₀₋ : a₀₀₀ ≡ a₀₀₁}
{a₀₁₀ a₀₁₁ : A} {a₀₁₋ : a₀₁₀ ≡ a₀₁₁}
{a₀₋₀ : a₀₀₀ ≡ a₀₁₀} {a₀₋₁ : a₀₀₁ ≡ a₀₁₁}
(a₀₋₋ : Square a₀₀₋ a₀₁₋ a₀₋₀ a₀₋₁)
{a₁₀₀ a₁₀₁ : A} {a₁₀₋ : a₁₀₀ ≡ a₁₀₁}
{a₁₁₀ a₁₁₁ : A} {a₁₁₋ : a₁₁₀ ≡ a₁₁₁}
{a₁₋₀ : a₁₀₀ ≡ a₁₁₀} {a₁₋₁ : a₁₀₁ ≡ a₁₁₁}
(a₁₋₋ : Square a₁₀₋ a₁₁₋ a₁₋₀ a₁₋₁)
{a₋₀₀ : a₀₀₀ ≡ a₁₀₀} {a₋₀₁ : a₀₀₁ ≡ a₁₀₁}
(a₋₀₋ : Square a₀₀₋ a₁₀₋ a₋₀₀ a₋₀₁)
{a₋₁₀ : a₀₁₀ ≡ a₁₁₀} {a₋₁₁ : a₀₁₁ ≡ a₁₁₁}
(a₋₁₋ : Square a₀₁₋ a₁₁₋ a₋₁₀ a₋₁₁)
(a₋₋₀ : Square a₀₋₀ a₁₋₀ a₋₀₀ a₋₁₀)
(a₋₋₁ : Square a₀₋₁ a₁₋₁ a₋₀₁ a₋₁₁)
→ Cube a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁
-- Essential consequences of isProp and isContr
isProp→PathP : ∀ {B : I → Type ℓ} → ((i : I) → isProp (B i))
→ (b0 : B i0) (b1 : B i1)
→ PathP (λ i → B i) b0 b1
isProp→PathP hB b0 b1 = toPathP (hB _ _ _)
isPropIsContr : isProp (isContr A)
isPropIsContr (c0 , h0) (c1 , h1) j =
h0 c1 j , λ y i → hcomp (λ k → λ { (i = i0) → h0 (h0 c1 j) k;
(i = i1) → h0 y k;
(j = i0) → h0 (h0 y i) k;
(j = i1) → h0 (h1 y i) k}) c0
isContr→isProp : isContr A → isProp A
isContr→isProp (x , p) a b i =
hcomp (λ j → λ { (i = i0) → p a j
; (i = i1) → p b j }) x
isProp→isSet : isProp A → isSet A
isProp→isSet h a b p q j i =
hcomp (λ k → λ { (i = i0) → h a a k
; (i = i1) → h a b k
; (j = i0) → h a (p i) k
; (j = i1) → h a (q i) k }) a
isProp→isSet' : isProp A → isSet' A
isProp→isSet' h {a} p q r s i j =
hcomp (λ k → λ { (i = i0) → h a (p j) k
; (i = i1) → h a (q j) k
; (j = i0) → h a (r i) k
; (j = i1) → h a (s i) k}) a
isPropIsProp : isProp (isProp A)
isPropIsProp f g i a b = isProp→isSet f a b (f a b) (g a b) i
isPropSingl : {a : A} → isProp (singl a)
isPropSingl = isContr→isProp (isContrSingl _)
isPropSinglP : {A : I → Type ℓ} {a : A i0} → isProp (singlP A a)
isPropSinglP = isContr→isProp (isContrSinglP _ _)
-- Universe lifting
record Lift {i j} (A : Type i) : Type (ℓ-max i j) where
constructor lift
field
lower : A
open Lift public
liftExt : ∀ {A : Type ℓ} {a b : Lift {ℓ} {ℓ'} A} → (lower a ≡ lower b) → a ≡ b
liftExt x i = lift (x i)
doubleCompPath-filler∙ : {a b c d : A} (p : a ≡ b) (q : b ≡ c) (r : c ≡ d)
→ PathP (λ i → p i ≡ r (~ i)) (p ∙ q ∙ r) q
doubleCompPath-filler∙ {A = A} {b = b} p q r j i =
hcomp (λ k → λ { (i = i0) → p j
; (i = i1) → side j k
; (j = i1) → q (i ∧ k)})
(p (j ∨ i))
where
side : I → I → A
side i j =
hcomp (λ k → λ { (i = i1) → q j
; (j = i0) → b
; (j = i1) → r (~ i ∧ k)})
(q j)
PathP→compPathL : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ PathP (λ i → p i ≡ q i) r s
→ sym p ∙ r ∙ q ≡ s
PathP→compPathL {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (j ∨ k)
; (i = i1) → q (j ∨ k)
; (j = i0) → doubleCompPath-filler∙ (sym p) r q (~ k) i
; (j = i1) → s i })
(P j i)
PathP→compPathR : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ PathP (λ i → p i ≡ q i) r s
→ r ≡ p ∙ s ∙ sym q
PathP→compPathR {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (j ∧ (~ k))
; (i = i1) → q (j ∧ (~ k))
; (j = i0) → r i
; (j = i1) → doubleCompPath-filler∙ p s (sym q) (~ k) i})
(P j i)
-- otherdir
compPathL→PathP : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ sym p ∙ r ∙ q ≡ s
→ PathP (λ i → p i ≡ q i) r s
compPathL→PathP {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (~ k ∨ j)
; (i = i1) → q (~ k ∨ j)
; (j = i0) → doubleCompPath-filler∙ (sym p) r q k i
; (j = i1) → s i})
(P j i)
compPathR→PathP : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ r ≡ p ∙ s ∙ sym q
→ PathP (λ i → p i ≡ q i) r s
compPathR→PathP {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (k ∧ j)
; (i = i1) → q (k ∧ j)
; (j = i0) → r i
; (j = i1) → doubleCompPath-filler∙ p s (sym q) k i})
(P j i)
| 33.456863
| 131
| 0.453203
|
a17f9c4231aa19389b592c608c779b7b68dc98c4
| 5,125
|
agda
|
Agda
|
Cubical/HITs/Colimit/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Colimit/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/Colimit/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-
Homotopy colimits of graphs
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Colimit.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Graph
-- Cones under a diagram
record Cocone ℓ {ℓd ℓv ℓe} {I : Graph ℓv ℓe} (F : Diag ℓd I) (X : Type ℓ)
: Type (ℓ-suc (ℓ-max ℓ (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd)))) where
field
leg : ∀ (j : Obj I) → F $ j → X
com : ∀ {j k} (f : Hom I j k) → leg k ∘ F <$> f ≡ leg j
postcomp : ∀ {ℓ'} {Y : Type ℓ'} → (X → Y) → Cocone ℓ' F Y
leg (postcomp h) j = h ∘ leg j
com (postcomp h) f = cong (h ∘_) (com f)
open Cocone public
-- Σ (Type ℓ) (Cocone ℓ F) forms a category:
module _ {ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} where
private
-- the "lower star" functor
_* : ∀ {ℓ ℓ'} {X : Type ℓ} {Y : Type ℓ'} → (X → Y) → Cocone _ F X → Cocone _ F Y
(h *) C = postcomp C h
CoconeMor : ∀ {ℓ ℓ'} → Σ (Type ℓ) (Cocone ℓ F) → Σ (Type ℓ') (Cocone ℓ' F) → Type _
CoconeMor (X , C) (Y , D) = Σ[ h ∈ (X → Y) ] (h *) C ≡ D
idCoconeMor : ∀ {ℓ} (Cp : Σ (Type ℓ) (Cocone ℓ F)) → CoconeMor Cp Cp
idCoconeMor Cp = (λ x → x) , refl
compCoconeMor : ∀ {ℓ ℓ' ℓ''} {C : Σ (Type ℓ) (Cocone ℓ F)} {D : Σ (Type ℓ') (Cocone ℓ' F)}
{E : Σ (Type ℓ'') (Cocone ℓ'' F)}
→ CoconeMor D E → CoconeMor C D → CoconeMor C E
compCoconeMor (g , q) (f , p) = g ∘ f , (cong (g *) p) ∙ q
-- Universal cocones are initial objects in the category Σ (Type ℓ) (Cocone ℓ F)
module _ {ℓ ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} {X : Type ℓ} where
isUniversalAt : ∀ ℓq → Cocone ℓ F X → Type (ℓ-max ℓ (ℓ-suc (ℓ-max ℓq (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd)))))
isUniversalAt ℓq C = ∀ (Y : Type ℓq) → isEquiv {A = (X → Y)} {B = Cocone ℓq F Y} (postcomp C)
-- (unfolding isEquiv, this ^ is equivalent to what one might expect:)
-- ∀ (Y : Type ℓ) (D : Cocone ℓ F Y) → ∃![ h ∈ (X → Y) ] (h *) C ≡ D
-- (≡ isContr (CoconeMor (X , C) (Y , D)))
isPropIsUniversalAt : ∀ ℓq (C : Cocone ℓ F X) → isProp (isUniversalAt ℓq C)
isPropIsUniversalAt ℓq C = isPropΠ (λ Y → isPropIsEquiv (postcomp C))
isUniversal : Cocone ℓ F X → Typeω
isUniversal C = ∀ ℓq → isUniversalAt ℓq C
-- Colimits are universal cocones
record isColimit {ℓ ℓd ℓv ℓe} {I : Graph ℓv ℓe} (F : Diag ℓd I) (X : Type ℓ) : Typeω where
field
cone : Cocone ℓ F X
univ : isUniversal cone
open isColimit public
module _ {ℓ ℓ' ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} {X : Type ℓ} {Y : Type ℓ'} where
postcomp⁻¹ : isColimit F X → Cocone ℓ' F Y → (X → Y)
postcomp⁻¹ cl = invEq (_ , univ cl _ Y)
postcomp⁻¹-inv : (cl : isColimit F X) (D : Cocone ℓ' F Y) → (postcomp (cone cl) (postcomp⁻¹ cl D)) ≡ D
postcomp⁻¹-inv cl D = retEq (_ , univ cl _ Y) D
postcomp⁻¹-mor : (cl : isColimit F X) (D : Cocone ℓ' F Y) → CoconeMor (X , cone cl) (Y , D)
postcomp⁻¹-mor cl D = (postcomp⁻¹ cl D) , (postcomp⁻¹-inv cl D)
-- Colimits are unique
module _ {ℓ ℓ' ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} {X : Type ℓ} {Y : Type ℓ'} where
uniqColimit : isColimit F X → isColimit F Y → X ≃ Y
uniqColimit cl cl'
= isoToEquiv (iso (fst fwd) (fst bwd)
(λ x i → fst (isContr→isProp (equiv-proof (univ cl' ℓ' Y) (cone cl'))
(compCoconeMor fwd bwd)
(idCoconeMor (Y , cone cl')) i) x)
(λ x i → fst (isContr→isProp (equiv-proof (univ cl ℓ X) (cone cl))
(compCoconeMor bwd fwd)
(idCoconeMor (X , cone cl)) i) x))
where fwd : CoconeMor (X , cone cl ) (Y , cone cl')
bwd : CoconeMor (Y , cone cl') (X , cone cl )
fwd = postcomp⁻¹-mor cl (cone cl')
bwd = postcomp⁻¹-mor cl' (cone cl)
-- Colimits always exist
data colim {ℓd ℓe ℓv} {I : Graph ℓv ℓe} (F : Diag ℓd I) : Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd))) where
colim-leg : ∀ (j : Obj I) → F $ j → colim F
colim-com : ∀ {j k} (f : Hom I j k) → colim-leg k ∘ F <$> f ≡ colim-leg j
module _ {ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} where
colimCone : Cocone _ F (colim F)
leg colimCone = colim-leg
com colimCone = colim-com
rec : ∀ {ℓ} {X : Type ℓ} → Cocone ℓ F X → (colim F → X)
rec C (colim-leg j A) = leg C j A
rec C (colim-com f i A) = com C f i A
colimIsColimit : isColimit F (colim F)
cone colimIsColimit = colimCone
univ colimIsColimit ℓq Y
= isoToIsEquiv record { fun = postcomp colimCone
; inv = rec
; rightInv = λ C → refl
; leftInv = λ h → funExt (eq h) }
where eq : ∀ h (x : colim _) → rec (postcomp colimCone h) x ≡ h x
eq h (colim-leg j A) = refl
eq h (colim-com f i A) = refl
| 38.533835
| 109
| 0.534829
|
7c0afb15c2cf8e76936a053dfeabf98846a453b9
| 65
|
agda
|
Agda
|
test/Fail/Issue1078/A.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1078/A.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1078/A.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue1078.A where
open import Common.Level using (Level)
| 16.25
| 38
| 0.8
|
3541e266a567b7ad17c7fa8a234aeda066824bd8
| 1,376
|
agda
|
Agda
|
examples/outdated-and-incorrect/Alonzo/AlonzoPrelude.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
examples/outdated-and-incorrect/Alonzo/AlonzoPrelude.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/outdated-and-incorrect/Alonzo/AlonzoPrelude.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module AlonzoPrelude where
open import RTN public
import RTP -- magic module - Run Time Primitives
Int : Set
Int = RTP.Int
Float : Set
Float = RTP.Float
String : Set
String = RTP.String
Char : Set
Char = RTP.Char
data True : Set where
tt : True
{-
record True : Set where
tt : True
tt = record{}
-}
data False : Set where
elim-False : {A : Set} -> False -> A
elim-False ()
-- _∘_ : {A,B,C:Set} -> (B -> C) -> (A -> B) -> A -> C
-- f ∘ g = \x -> f (g x)
id : {A : Set} -> A -> A
id x = x
infixr 90 _○_
_○_ : {A B C : Set} -> (B -> C) -> (A -> B) -> A -> C
(f ○ g) x = f (g x)
infixr 0 _$_
_$_ : {A B : Set} -> (A -> B) -> A -> B
f $ x = f x
flip : {A B C : Set} -> (A -> B -> C) -> B -> A -> C
flip f x y = f y x
const : {A B : Set} -> A -> B -> A
const x _ = x
typeOf : {A : Set} -> A -> Set
typeOf {A} _ = A
data _×_ (A B : Set) : Set where
<_,_> : A -> B -> A × B
fst : {A B : Set} -> A × B -> A
fst < x , y > = x
snd : {A B : Set} -> A × B -> B
snd < x , y > = y
{-
infixr 10 _::_
data List (A:Set) : Set where
nil : List A
_::_ : A -> List A -> List A
[_] : {A:Set} -> A -> List A
[ x ] = x :: nil
-}
{-# BUILTIN INTEGER Int #-}
-- {-# BUILTIN STRING String #-}
-- {-# BUILTIN FLOAT Float #-}
{-# BUILTIN CHAR Char #-}
| 17.2
| 56
| 0.441134
|
4e98801b39ea5719cac4fe22a97dcc147386add2
| 2,880
|
agda
|
Agda
|
agda/Singleton.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
agda/Singleton.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
agda/Singleton.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
module Singleton where
open import Level
open import Data.Unit
open import Data.Product
open import Function
open import Relation.Binary
open import Function.Inverse
open import Function.Equality as FE
open import Relation.Binary.PropositionalEquality as P
open import Pi using (⟦_⟧; _⟷_ )
embed₁ : Set → Set
embed₁ b = Σ b (λ _ → ⊤)
B-to-Σ⊤ : {B : Set} → B → embed₁ B
B-to-Σ⊤ v = (v , tt)
Σ⊤-to-B : {B : Set} → embed₁ B → B
Σ⊤-to-B (v , _) = v
BΣ₁ : ∀ {b} → Inverse (P.setoid b) (P.setoid (embed₁ b))
BΣ₁ = record {
to = record { _⟨$⟩_ = B-to-Σ⊤; cong = P.cong B-to-Σ⊤ }
; from = record { _⟨$⟩_ = Σ⊤-to-B; cong = P.cong Σ⊤-to-B }
; inverse-of = record { left-inverse-of = λ _ → refl
; right-inverse-of = λ x → refl } }
data Singleton {c : Level} {A : Set c} : A → Set c where
singleton : (x : A) -> Singleton x
-- That a Singleton type is a setoid is not needed, but here is the proof anyways.
data _∼_ {c : Level} {A : Set c} {v : A} (x : Singleton v) (y : Singleton v) : Set c where
uniq : x ∼ y
∼Equiv : {c : Level} {A : Set c} {v : A} → IsEquivalence {_} {_} {Singleton v} _∼_
∼Equiv {v = v } = record {
refl = uniq
; sym = λ _ → uniq
; trans = λ _ _ → uniq }
SingSetoid : {c c : Level} → (A : Setoid c c) → (Setoid.Carrier A) → Setoid c c
SingSetoid A v = record {
Carrier = Singleton v
; _≈_ = _∼_
; isEquivalence = ∼Equiv }
-- We can map a type to its Σ of Singletons and back.
embed₂ : Set → Set
embed₂ b = Σ b Singleton
B-to-ΣS : {B : Set} → B → embed₂ B
B-to-ΣS v = (v , singleton v)
ΣS-to-B : {B : Set} → embed₂ B → B
ΣS-to-B x = proj₁ x
right-inverse : ∀ {c} {b : Set c} → (x : Σ b (Singleton {A = b})) → (proj₁ x , singleton (proj₁ x)) ≡ x
right-inverse (v , singleton .v) = refl
BΣ₂ : ∀ {b} → Inverse (P.setoid b) (P.setoid (embed₂ b))
BΣ₂ = record {
to = record { _⟨$⟩_ = B-to-ΣS; cong = P.cong B-to-ΣS }
; from = record { _⟨$⟩_ = ΣS-to-B; cong = P.cong ΣS-to-B }
; inverse-of = record { left-inverse-of = λ x → refl
; right-inverse-of = right-inverse } }
-- A generalized idea of a permutation: a bijection between any two types
Permutation : Set → Set -> Set
Permutation a b = Inverse (P.setoid a) (P.setoid b)
-- Now, what we really want is to interpret Pi combinators as
-- permutations. We need a refined version of embed₂ which
-- allows us to use a permutation to transport things.
embed₃ : {l : Level} → (S T : Setoid l l) → Inverse S T → Setoid l l
embed₃ S T f = record {
Carrier = Σ A (λ b → Singleton (to f ⟨$⟩ b))
; _≈_ = _≡_
; isEquivalence = P.isEquivalence }
where open Inverse {From = S} {T}
A = Setoid.Carrier S
| 34.285714
| 103
| 0.553819
|
2e11f899608fb43a5e00ea0af4620cb9bb71e5b0
| 8,683
|
agda
|
Agda
|
agda-stdlib/src/Data/List/Countdown.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/List/Countdown.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/Countdown.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- A data structure which keeps track of an upper bound on the number
-- of elements /not/ in a given list
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Level using (0ℓ)
open import Relation.Binary
module Data.List.Countdown (D : DecSetoid 0ℓ 0ℓ) where
open import Data.Empty
open import Data.Fin.Base using (Fin; zero; suc; punchOut)
open import Data.Fin.Properties
using (suc-injective; punchOut-injective)
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
open import Function.Injection
using (Injection; module Injection)
open import Data.Bool.Base using (true; false)
open import Data.List hiding (lookup)
open import Data.List.Relation.Unary.Any as Any using (here; there)
open import Data.Nat.Base using (ℕ; zero; suc)
open import Data.Product
open import Data.Sum.Base
open import Data.Sum.Properties
open import Relation.Nullary.Reflects using (invert)
open import Relation.Nullary
open import Relation.Nullary.Decidable using (dec-true; dec-false)
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; cong)
open PropEq.≡-Reasoning
private
open module D = DecSetoid D
hiding (refl) renaming (Carrier to Elem)
open import Data.List.Membership.Setoid D.setoid
------------------------------------------------------------------------
-- Helper functions
private
-- The /first/ occurrence of x in xs.
first-occurrence : ∀ {xs} x → x ∈ xs → x ∈ xs
first-occurrence x (here x≈y) = here x≈y
first-occurrence x (there {x = y} x∈xs) with x ≟ y
... | true because [x≈y] = here (invert [x≈y])
... | false because _ = there $ first-occurrence x x∈xs
-- The index of the first occurrence of x in xs.
first-index : ∀ {xs} x → x ∈ xs → Fin (length xs)
first-index x x∈xs = Any.index $ first-occurrence x x∈xs
-- first-index preserves equality of its first argument.
first-index-cong : ∀ {x₁ x₂ xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
x₁ ≈ x₂ → first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs
first-index-cong {x₁} {x₂} x₁∈xs x₂∈xs x₁≈x₂ = helper x₁∈xs x₂∈xs
where
helper : ∀ {xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs
helper (here x₁≈x) (here x₂≈x) = refl
helper (here x₁≈x) (there {x = x} x₂∈xs)
with x₂ ≟ x | dec-true (x₂ ≟ x) (trans (sym x₁≈x₂) x₁≈x)
... | _ | refl = refl
helper (there {x = x} x₁∈xs) (here x₂≈x)
with x₁ ≟ x | dec-true (x₁ ≟ x) (trans x₁≈x₂ x₂≈x)
... | _ | refl = refl
helper (there {x = x} x₁∈xs) (there x₂∈xs) with x₁ ≟ x | x₂ ≟ x
... | true because _ | true because _ = refl
... | false because _ | false because _ = cong suc $ helper x₁∈xs x₂∈xs
... | yes x₁≈x | no x₂≉x = ⊥-elim (x₂≉x (trans (sym x₁≈x₂) x₁≈x))
... | no x₁≉x | yes x₂≈x = ⊥-elim (x₁≉x (trans x₁≈x₂ x₂≈x))
-- first-index is injective in its first argument.
first-index-injective
: ∀ {x₁ x₂ xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs → x₁ ≈ x₂
first-index-injective {x₁} {x₂} = helper
where
helper : ∀ {xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs → x₁ ≈ x₂
helper (here x₁≈x) (here x₂≈x) _ = trans x₁≈x (sym x₂≈x)
helper (here x₁≈x) (there {x = x} x₂∈xs) _ with x₂ ≟ x
helper (here x₁≈x) (there {x = x} x₂∈xs) _ | yes x₂≈x = trans x₁≈x (sym x₂≈x)
helper (here x₁≈x) (there {x = x} x₂∈xs) () | no x₂≉x
helper (there {x = x} x₁∈xs) (here x₂≈x) _ with x₁ ≟ x
helper (there {x = x} x₁∈xs) (here x₂≈x) _ | yes x₁≈x = trans x₁≈x (sym x₂≈x)
helper (there {x = x} x₁∈xs) (here x₂≈x) () | no x₁≉x
helper (there {x = x} x₁∈xs) (there x₂∈xs) _ with x₁ ≟ x | x₂ ≟ x
helper (there {x = x} x₁∈xs) (there x₂∈xs) _ | yes x₁≈x | yes x₂≈x = trans x₁≈x (sym x₂≈x)
helper (there {x = x} x₁∈xs) (there x₂∈xs) () | yes x₁≈x | no x₂≉x
helper (there {x = x} x₁∈xs) (there x₂∈xs) () | no x₁≉x | yes x₂≈x
helper (there {x = x} x₁∈xs) (there x₂∈xs) eq | no x₁≉x | no x₂≉x =
helper x₁∈xs x₂∈xs (suc-injective eq)
------------------------------------------------------------------------
-- The countdown data structure
-- If counted ⊕ n is inhabited then there are at most n values of type
-- Elem which are not members of counted (up to _≈_). You can read the
-- symbol _⊕_ as partitioning Elem into two parts: counted and
-- uncounted.
infix 4 _⊕_
record _⊕_ (counted : List Elem) (n : ℕ) : Set where
field
-- An element can be of two kinds:
-- ⑴ It is provably in counted.
-- ⑵ It is one of at most n elements which may or may not be in
-- counted. The "at most n" part is guaranteed by the field
-- "injective".
kind : ∀ x → x ∈ counted ⊎ Fin n
injective : ∀ {x y i} → kind x ≡ inj₂ i → kind y ≡ inj₂ i → x ≈ y
-- A countdown can be initialised by proving that Elem is finite.
empty : ∀ {n} → Injection D.setoid (PropEq.setoid (Fin n)) → [] ⊕ n
empty inj =
record { kind = inj₂ ∘ _⟨$⟩_ to
; injective = λ {x} {y} {i} eq₁ eq₂ → injective (begin
to ⟨$⟩ x ≡⟨ inj₂-injective eq₁ ⟩
i ≡⟨ PropEq.sym $ inj₂-injective eq₂ ⟩
to ⟨$⟩ y ∎)
}
where open Injection inj
-- A countdown can also be initialised by proving that Elem is finite.
emptyFromList : (counted : List Elem) → (∀ x → x ∈ counted) →
[] ⊕ length counted
emptyFromList counted complete = empty record
{ to = record
{ _⟨$⟩_ = λ x → first-index x (complete x)
; cong = first-index-cong (complete _) (complete _)
}
; injective = first-index-injective (complete _) (complete _)
}
-- Finds out if an element has been counted yet.
lookup : ∀ {counted n} → counted ⊕ n → ∀ x → Dec (x ∈ counted)
lookup {counted} _ x = Any.any (_≟_ x) counted
-- When no element remains to be counted all elements have been
-- counted.
lookup! : ∀ {counted} → counted ⊕ zero → ∀ x → x ∈ counted
lookup! counted⊕0 x with _⊕_.kind counted⊕0 x
... | inj₁ x∈counted = x∈counted
... | inj₂ ()
private
-- A variant of lookup!.
lookup‼ : ∀ {m counted} →
counted ⊕ m → ∀ x → x ∉ counted → ∃ λ n → m ≡ suc n
lookup‼ {suc m} counted⊕n x x∉counted = (m , refl)
lookup‼ {zero} counted⊕n x x∉counted =
⊥-elim (x∉counted $ lookup! counted⊕n x)
-- Counts a previously uncounted element.
insert : ∀ {counted n} →
counted ⊕ suc n → ∀ x → x ∉ counted → x ∷ counted ⊕ n
insert {counted} {n} counted⊕1+n x x∉counted =
record { kind = kind′; injective = inj }
where
open _⊕_ counted⊕1+n
helper : ∀ x y i {j} →
kind x ≡ inj₂ i → kind y ≡ inj₂ j → i ≡ j → x ≈ y
helper _ _ _ eq₁ eq₂ refl = injective eq₁ eq₂
kind′ : ∀ y → y ∈ x ∷ counted ⊎ Fin n
kind′ y with y ≟ x | kind x | kind y | helper x y
kind′ y | yes y≈x | _ | _ | _ = inj₁ (here y≈x)
kind′ y | _ | inj₁ x∈counted | _ | _ = ⊥-elim (x∉counted x∈counted)
kind′ y | _ | _ | inj₁ y∈counted | _ = inj₁ (there y∈counted)
kind′ y | no y≉x | inj₂ i | inj₂ j | hlp =
inj₂ (punchOut (y≉x ∘ sym ∘ hlp _ refl refl))
inj : ∀ {y z i} → kind′ y ≡ inj₂ i → kind′ z ≡ inj₂ i → y ≈ z
inj {y} {z} eq₁ eq₂ with y ≟ x | z ≟ x | kind x | kind y | kind z
| helper x y | helper x z | helper y z
inj () _ | yes _ | _ | _ | _ | _ | _ | _ | _
inj _ () | _ | yes _ | _ | _ | _ | _ | _ | _
inj _ _ | no _ | no _ | inj₁ x∈counted | _ | _ | _ | _ | _ = ⊥-elim (x∉counted x∈counted)
inj () _ | no _ | no _ | inj₂ _ | inj₁ _ | _ | _ | _ | _
inj _ () | no _ | no _ | inj₂ _ | _ | inj₁ _ | _ | _ | _
inj eq₁ eq₂ | no _ | no _ | inj₂ i | inj₂ _ | inj₂ _ | _ | _ | hlp =
hlp _ refl refl $
punchOut-injective {i = i} _ _ $
(PropEq.trans (inj₂-injective eq₁) (PropEq.sym (inj₂-injective eq₂)))
-- Counts an element if it has not already been counted.
lookupOrInsert : ∀ {counted m} →
counted ⊕ m →
∀ x → x ∈ counted ⊎
∃ λ n → m ≡ suc n × x ∷ counted ⊕ n
lookupOrInsert counted⊕n x with lookup counted⊕n x
... | yes x∈counted = inj₁ x∈counted
... | no x∉counted with lookup‼ counted⊕n x x∉counted
... | (n , refl) = inj₂ (n , refl , insert counted⊕n x x∉counted)
| 40.199074
| 107
| 0.551883
|
4ed3dbb6e9c7c535e87a4e6f42af8a16412010c5
| 32
|
agda
|
Agda
|
Categories/Pushout.agda
|
copumpkin/categories
|
36f4181d751e2ecb54db219911d8c69afe8ba892
|
[
"BSD-3-Clause"
] | 98
|
2015-04-15T14:57:33.000Z
|
2022-03-08T05:20:36.000Z
|
Categories/Pushout.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 19
|
2015-05-23T06:47:10.000Z
|
2019-08-09T16:31:40.000Z
|
Categories/Pushout.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 23
|
2015-02-05T13:03:09.000Z
|
2021-11-11T13:50:56.000Z
|
module Categories.Pushout where
| 16
| 31
| 0.875
|
367a1fc1faa311b4aa7539c2ad9197a23b65c122
| 4,083
|
agda
|
Agda
|
LibraBFT/Base/Types.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Base/Types.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Base/Types.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Hash
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Encode
-- The ground types that are common across Abstract, Concrete and Impl
-- and some utility types
module LibraBFT.Base.Types where
EpochId : Set
EpochId = ℕ
Round : Set
Round = ℕ
-- This was intended to be a simple way to flag meta-information without having it
-- getting in the way. It's important to ensure that an implementation does not
-- use various information, such as who is honest. However, we found this got in
-- the way too much during development, so for now we get a similar effect by using
-- a naming convention and enforcement via grep and eyeballs. Maybe one day...
Meta : ∀{ℓ} → Set ℓ → Set ℓ
Meta x = x
-- An EPRound is a 'compound round'; that is,
-- is a round coupled with an epoch id. As most of our
-- proofs are per-epoch so far, these are not used, but
-- they may be in future.
EpRound : Set
EpRound = EpochId × Round
sucr : EpRound → EpRound
sucr (e , r) = (e , suc r)
epr-epoch : EpRound → EpochId
epr-epoch = proj₁
epr-round : EpRound → Round
epr-round = proj₂
epr₀ : EpRound
epr₀ = (0 , 0)
-- Compound rounds admit a total order
data _<ER_ : EpRound → EpRound → Set where
ince : ∀{e₀ e₁ r₀ r₁} → e₀ < e₁ → (e₀ , r₀) <ER (e₁ , r₁)
incr : ∀{e r₀ r₁} → r₀ < r₁ → (e , r₀) <ER (e , r₁)
<ER-irrelevant : Irrelevant _<ER_
<ER-irrelevant (ince x) (ince x₁) = cong ince (<-irrelevant x x₁)
<ER-irrelevant (ince x) (incr x₁) = ⊥-elim (<-irrefl refl x)
<ER-irrelevant (incr x) (ince x₁) = ⊥-elim (<-irrefl refl x₁)
<ER-irrelevant (incr x) (incr x₁) = cong incr (<-irrelevant x x₁)
<ER-asym : Asymmetric _<ER_
<ER-asym (ince x) (ince x₁) = <-asym x x₁
<ER-asym (ince x) (incr x₁) = <-irrefl refl x
<ER-asym (incr x) (ince x₁) = <-irrefl refl x₁
<ER-asym (incr x) (incr x₁) = <-asym x x₁
<ER-trans : Transitive _<ER_
<ER-trans (ince x) (ince x₁) = ince (<-trans x x₁)
<ER-trans (ince x) (incr x₁) = ince x
<ER-trans (incr x) (ince x₁) = ince x₁
<ER-trans (incr x) (incr x₁) = incr (<-trans x x₁)
<ER-irrefl : Irreflexive _≡_ _<ER_
<ER-irrefl refl (ince x) = <-irrefl refl x
<ER-irrefl refl (incr x) = <-irrefl refl x
postulate -- prove, if needed/used
<ER-cmp : Trichotomous _≡_ _<ER_
{- This <ER relation is not currently used. If it turns out to be
used: TODO-1: finish this proof
<ER-cmp (e₀ , r₀) (e₁ , r₁) with <-cmp e₀ e₁
...| tri≈ e₀≮e₁ refl e₁≮e₀ = {!!} {!!} {!!}
...| tri< e₀<e₁ e₀≢e₁ e₁≮e₀ = tri< (ince e₀<e₁) {!!} {!!}
...| tri> e₀≮e₁ e₀≢e₁ e₁<e₀ = {!!}
-}
ep≮epr₀ : ∀{ep} → ¬ (ep <ER epr₀)
ep≮epr₀ (ince ())
ep≮epr₀ (incr ())
_≤ER_ : EpRound → EpRound → Set
er₀ ≤ER er₁ = er₀ ≡ er₁ ⊎ er₀ <ER er₁
≤ER⇒epoch≤ : ∀{er₀ er₁} → er₀ ≤ER er₁ → epr-epoch er₀ ≤ epr-epoch er₁
≤ER⇒epoch≤ (inj₁ refl) = ≤-refl
≤ER⇒epoch≤ (inj₂ (ince x)) = <⇒≤ x
≤ER⇒epoch≤ (inj₂ (incr x)) = ≤-refl
≤ER⇒round≤ : ∀{er₀ er₁} → er₀ ≤ER er₁ → epr-epoch er₀ ≡ epr-epoch er₁ → epr-round er₀ ≤ epr-round er₁
≤ER⇒round≤ (inj₁ refl) hyp1 = ≤-refl
≤ER⇒round≤ (inj₂ (ince x)) refl = ⊥-elim (<-irrefl refl x)
≤ER⇒round≤ (inj₂ (incr x)) hyp1 = <⇒≤ x
≤ER-intro : ∀{e₀ e₁ r₀ r₁} → e₀ ≤ e₁ → r₀ ≤ r₁ → (e₀ , r₀) ≤ER (e₁ , r₁)
≤ER-intro {e0} {e1} {r0} {r1} e r
with e0 ≟ℕ e1
...| no le = inj₂ (ince (≤∧≢⇒< e le))
...| yes refl
with r0 ≟ℕ r1
...| no le = inj₂ (incr (≤∧≢⇒< r le))
...| yes refl = inj₁ refl
er≤0⇒er≡0 : ∀{er} → er ≤ER epr₀ → er ≡ epr₀
er≤0⇒er≡0 (inj₁ x) = x
er≤0⇒er≡0 (inj₂ (ince ()))
er≤0⇒er≡0 (inj₂ (incr ()))
<⇒≤ER : ∀{er₀ er₁} → er₀ <ER er₁ → er₀ ≤ER er₁
<⇒≤ER = inj₂
≤ER-refl : Reflexive _≤ER_
≤ER-refl = inj₁ refl
postulate -- prove, if needed/used
≤ER-trans : Transitive _≤ER_
| 32.927419
| 111
| 0.605682
|
7cd7654b58328c39d0085354770a0f64ed44ef57
| 382
|
agda
|
Agda
|
src/Definitions/Semiring.agda
|
Akshobhya1234/Agda-Algebra
|
72030f78934877ad67bf4e36e74e43845cabbf55
|
[
"MIT"
] | 2
|
2021-08-15T06:16:13.000Z
|
2021-08-17T09:14:03.000Z
|
src/Definitions/Semiring.agda
|
Akshobhya1234/Agda-Algebra
|
72030f78934877ad67bf4e36e74e43845cabbf55
|
[
"MIT"
] | 3
|
2022-01-02T20:50:34.000Z
|
2022-01-31T18:19:52.000Z
|
src/Definitions/Semiring.agda
|
Akshobhya1234/agda-NonAssociativeAlgebra
|
443e831e536b756acbd1afd0d6bae7bc0d288048
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Algebra.Bundles using (Semiring)
-- Credit: This definition is taken from the stdlib issue #1175
-- As given by @MatthewDaggitt and @mechvel
module Definitions.Semiring {α α≈} (R : Semiring α α≈)
where
open Semiring R
record NonZero (x : Carrier) : Set α≈ where
constructor mkNonZero
field
nonZero : x ≉ 0#
| 23.875
| 63
| 0.675393
|
7c102e8cfabc63a931abd4b95569682dcaa75022
| 4,648
|
agda
|
Agda
|
Core.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | 1
|
2019-10-07T17:36:42.000Z
|
2019-10-07T17:36:42.000Z
|
Core.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | null | null | null |
Core.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | null | null | null |
-- Copyright: (c) 2016 Ertugrul Söylemez
-- License: BSD3
-- Maintainer: Ertugrul Söylemez <esz@posteo.de>
--
-- This module contains definitions that are fundamental and/or used
-- everywhere.
module Core where
open import Agda.Builtin.Equality public
renaming (refl to ≡-refl)
using (_≡_)
open import Agda.Builtin.FromNat public
open import Agda.Builtin.FromNeg public
open import Agda.Builtin.FromString public
open import Agda.Builtin.Unit using (⊤; tt) public
open import Agda.Primitive using (Level; lsuc; lzero; _⊔_) public
-- An empty type (or a false hypothesis).
data ⊥ : Set where
-- Dependent sums (or existential quantification).
record Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where
constructor _,_
field
fst : A
snd : B fst
open Σ public
infixr 4 _,_
infixr 0 _because_ _because:_
∃ : ∀ {a b} {A : Set a} (B : A → Set b) → Set (a ⊔ b)
∃ = Σ _
_because_ : ∀ {a b} {A : Set a} {B : A → Set b} → (x : A) → B x → Σ A B
_because_ = _,_
_because:_ : ∀ {a b} {A : Set a} {B : A → Set b} → (x : A) → B x → Σ A B
_because:_ = _,_
_×_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a ⊔ b)
A × B = Σ A (λ _ → B)
infixr 7 _×_
-- Tagged unions.
data Either {a} {b} (A : Set a) (B : Set b) : Set (a ⊔ b) where
Left : A → Either A B
Right : B → Either A B
-- Equivalence relations.
record Equiv {a r} (A : Set a) : Set (a ⊔ lsuc r) where
field
_≈_ : A → A → Set r
refl : ∀ {x} → x ≈ x
sym : ∀ {x y} → x ≈ y → y ≈ x
trans : ∀ {x y z} → x ≈ y → y ≈ z → x ≈ z
infix 4 _≈_
-- Helper functions for equational reasoning.
begin_ : ∀ {x y} → x ≈ y → x ≈ y
begin_ p = p
_≈[_]_ : ∀ x {y z} → x ≈ y → y ≈ z → x ≈ z
_ ≈[ x≈y ] y≈z = trans x≈y y≈z
_≈[]_ : ∀ x {y} → x ≈ y → x ≈ y
_ ≈[] p = p
_qed : ∀ (x : A) → x ≈ x
_qed _ = refl
infix 1 begin_
infixr 2 _≈[_]_ _≈[]_
infix 3 _qed
PropEq : ∀ {a} → (A : Set a) → Equiv A
PropEq A =
record {
_≈_ = _≡_;
refl = ≡-refl;
sym = sym';
trans = trans'
}
where
sym' : ∀ {x y} → x ≡ y → y ≡ x
sym' ≡-refl = ≡-refl
trans' : ∀ {x y z} → x ≡ y → y ≡ z → x ≡ z
trans' ≡-refl q = q
module PropEq {a} {A : Set a} = Equiv (PropEq A)
FuncEq : ∀ {a b} (A : Set a) (B : Set b) → Equiv (A → B)
FuncEq A B =
record {
_≈_ = λ f g → ∀ x → f x ≡ g x;
refl = λ _ → ≡-refl;
sym = λ p x → PropEq.sym (p x);
trans = λ p q x → PropEq.trans (p x) (q x)
}
module FuncEq {a b} {A : Set a} {B : Set b} = Equiv (FuncEq A B)
cong : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) {x y} → x ≡ y → f x ≡ f y
cong _ ≡-refl = ≡-refl
cong2 :
∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
(f : A → B → C)
→ ∀ {x1 x2 : A} {y1 y2 : B}
→ x1 ≡ x2
→ y1 ≡ y2
→ f x1 y1 ≡ f x2 y2
cong2 _ ≡-refl ≡-refl = ≡-refl
-- Partial orders.
record PartialOrder {a re rl} (A : Set a) : Set (a ⊔ lsuc (re ⊔ rl)) where
field Eq : Equiv {r = re} A
module ≈ = Equiv Eq
open ≈ public using (_≈_)
field
_≤_ : (x : A) → (y : A) → Set rl
antisym : ∀ {x y} → x ≤ y → y ≤ x → x ≈ y
refl' : ∀ {x y} → x ≈ y → x ≤ y
trans : ∀ {x y z} → x ≤ y → y ≤ z → x ≤ z
infix 4 _≤_
refl : ∀ {x} → x ≤ x
refl = refl' ≈.refl
-- Helper functions for transitivity reasoning.
begin_ : ∀ {x y} → x ≤ y → x ≤ y
begin_ p = p
_≤[_]_ : ∀ x {y z} → x ≤ y → y ≤ z → x ≤ z
_ ≤[ x≤y ] y≤z = trans x≤y y≤z
_≤[]_ : ∀ x {y} → x ≤ y → x ≤ y
_ ≤[] p = p
_qed : ∀ (x : A) → x ≤ x
_qed _ = refl
infix 1 begin_
infixr 2 _≤[_]_ _≤[]_
infix 3 _qed
-- Total orders.
record TotalOrder {a re rl} (A : Set a) : Set (a ⊔ lsuc (re ⊔ rl)) where
field partialOrder : PartialOrder {a} {re} {rl} A
open PartialOrder partialOrder public
field
total : ∀ x y → Either (x ≤ y) (y ≤ x)
-- Low-priority function application.
_$_ : ∀ {a} {A : Set a} → A → A
_$_ f = f
infixr 0 _$_
-- Given two predicates, this is the predicate that requires both.
_and_ : ∀ {a r1 r2} {A : Set a} → (A → Set r1) → (A → Set r2) → A → Set (r1 ⊔ r2)
(P and Q) x = P x × Q x
infixr 6 _and_
-- Use instance resolution to find a value of the target type.
it : ∀ {a} {A : Set a} {{_ : A}} → A
it {{x}} = x
-- Not.
not : ∀ {a} → Set a → Set a
not A = A → ⊥
-- Given two predicates, this is the predicate that requires at least
-- one of them.
_or_ : ∀ {a r1 r2} {A : Set a} → (A → Set r1) → (A → Set r2) → A → Set (r1 ⊔ r2)
(P or Q) x = Either (P x) (Q x)
-- Values with inline type signatures.
the : ∀ {a} (A : Set a) → A → A
the _ x = x
-- Decidable properties.
data Decision {a} (P : Set a) : Set a where
yes : (p : P) → Decision P
no : (np : not P) → Decision P
| 20.936937
| 81
| 0.516351
|
363435c89ebab9d0e8ebd48948e9a888bd2ac8d8
| 11,421
|
agda
|
Agda
|
fracGC/PiMemSem.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
fracGC/PiMemSem.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
fracGC/PiMemSem.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --without-K --safe #-}
module PiMemSem where
open import Function
open import Data.Nat
open import Data.Nat.Properties
open import Data.Fin as Fin using (Fin; zero; suc)
open import Data.Vec
open import Data.Vec.Relation.Unary.Any.Properties
open import Data.Vec.Any hiding (map)
open import Data.Empty using (⊥)
open import Data.Unit using (⊤; tt)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_; proj₁; proj₂; Σ-syntax)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; cong; cong₂; subst)
infixr 70 _×ᵤ_
infixr 60 _+ᵤ_
infixr 50 _⊚_
infix 80 ∣_∣
infix 100 !_
data 𝕌 : Set where
𝟘 : 𝕌
𝟙 : 𝕌
_+ᵤ_ : 𝕌 → 𝕌 → 𝕌
_×ᵤ_ : 𝕌 → 𝕌 → 𝕌
⟦_⟧ : (A : 𝕌) → Set
⟦ 𝟘 ⟧ = ⊥
⟦ 𝟙 ⟧ = ⊤
⟦ t₁ +ᵤ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧
⟦ t₁ ×ᵤ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧
data _⟷_ : 𝕌 → 𝕌 → Set where
unite₊l : {t : 𝕌} → 𝟘 +ᵤ t ⟷ t
uniti₊l : {t : 𝕌} → t ⟷ 𝟘 +ᵤ t
unite₊r : {t : 𝕌} → t +ᵤ 𝟘 ⟷ t
uniti₊r : {t : 𝕌} → t ⟷ t +ᵤ 𝟘
swap₊ : {t₁ t₂ : 𝕌} → t₁ +ᵤ t₂ ⟷ t₂ +ᵤ t₁
assocl₊ : {t₁ t₂ t₃ : 𝕌} → t₁ +ᵤ (t₂ +ᵤ t₃) ⟷ (t₁ +ᵤ t₂) +ᵤ t₃
assocr₊ : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) +ᵤ t₃ ⟷ t₁ +ᵤ (t₂ +ᵤ t₃)
unite⋆l : {t : 𝕌} → 𝟙 ×ᵤ t ⟷ t
uniti⋆l : {t : 𝕌} → t ⟷ 𝟙 ×ᵤ t
unite⋆r : {t : 𝕌} → t ×ᵤ 𝟙 ⟷ t
uniti⋆r : {t : 𝕌} → t ⟷ t ×ᵤ 𝟙
swap⋆ : {t₁ t₂ : 𝕌} → t₁ ×ᵤ t₂ ⟷ t₂ ×ᵤ t₁
assocl⋆ : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ ×ᵤ t₃) ⟷ (t₁ ×ᵤ t₂) ×ᵤ t₃
assocr⋆ : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₂) ×ᵤ t₃ ⟷ t₁ ×ᵤ (t₂ ×ᵤ t₃)
absorbr : {t : 𝕌} → 𝟘 ×ᵤ t ⟷ 𝟘
absorbl : {t : 𝕌} → t ×ᵤ 𝟘 ⟷ 𝟘
factorzr : {t : 𝕌} → 𝟘 ⟷ t ×ᵤ 𝟘
factorzl : {t : 𝕌} → 𝟘 ⟷ 𝟘 ×ᵤ t
dist : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) ×ᵤ t₃ ⟷ (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃)
factor : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃) ⟷ (t₁ +ᵤ t₂) ×ᵤ t₃
distl : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ +ᵤ t₃) ⟷ (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃)
factorl : {t₁ t₂ t₃ : 𝕌 } → (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃) ⟷ t₁ ×ᵤ (t₂ +ᵤ t₃)
id⟷ : {t : 𝕌} → t ⟷ t
_⊚_ : {t₁ t₂ t₃ : 𝕌} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_⊕_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (t₁ +ᵤ t₂ ⟷ t₃ +ᵤ t₄)
_⊗_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (t₁ ×ᵤ t₂ ⟷ t₃ ×ᵤ t₄)
!_ : {A B : 𝕌} → A ⟷ B → B ⟷ A
! unite₊l = uniti₊l
! uniti₊l = unite₊l
! unite₊r = uniti₊r
! uniti₊r = unite₊r
! swap₊ = swap₊
! assocl₊ = assocr₊
! assocr₊ = assocl₊
! unite⋆l = uniti⋆l
! uniti⋆l = unite⋆l
! unite⋆r = uniti⋆r
! uniti⋆r = unite⋆r
! swap⋆ = swap⋆
! assocl⋆ = assocr⋆
! assocr⋆ = assocl⋆
! absorbr = factorzl
! absorbl = factorzr
! factorzr = absorbl
! factorzl = absorbr
! dist = factor
! factor = dist
! distl = factorl
! factorl = distl
! id⟷ = id⟷
! (c₁ ⊚ c₂) = (! c₂) ⊚ (! c₁)
! (c₁ ⊕ c₂) = (! c₁) ⊕ (! c₂)
! (c₁ ⊗ c₂) = (! c₁) ⊗ (! c₂)
∣_∣ : (A : 𝕌) → ℕ
∣ 𝟘 ∣ = 0
∣ 𝟙 ∣ = 1
∣ A₁ +ᵤ A₂ ∣ = ∣ A₁ ∣ + ∣ A₂ ∣
∣ A₁ ×ᵤ A₂ ∣ = ∣ A₁ ∣ * ∣ A₂ ∣
Vec× : ∀ {n m} {A B : Set} → Vec A n → Vec B m → Vec (A × B) (n * m)
Vec× va vb = concat (map (λ a₁ → map (a₁ ,_) vb) va)
∈map : ∀ {ℓ₁ ℓ₂} {n} {A : Set ℓ₁} {B : Set ℓ₂} {v : Vec A n} → (f : A → B) → (a : A)
→ Any (a ≡_) v → Any (f a ≡_) (map f v)
∈map f a (here refl) = here refl
∈map f a (there a∈v) = there (∈map f a a∈v)
inVec× : ∀ {n m} {A B : Set} → (va : Vec A n) → (vb : Vec B m)
→ (a : A) (b : B)
→ Any (a ≡_) va → Any (b ≡_) vb
→ Any ((a , b) ≡_) (Vec× va vb)
inVec× (a ∷ va) vb .a b (here refl) b∈vb = ++⁺ˡ {xs = map (a ,_) vb} (∈map _ _ b∈vb)
inVec× (x ∷ va) vb a b (there a∈va) b∈vb = ++⁺ʳ (map (x ,_) vb) (inVec× va vb a b a∈va b∈vb)
any≡← : ∀ {ℓ} {A : Set ℓ} {n} {a} → (v : Vec A n) → (i : Fin n) → a ≡ lookup v i → Any (a ≡_) v
any≡← (_ ∷ _) Fin.0F refl = here refl
any≡← (_ ∷ v) (suc i) refl = there (any≡← v i refl)
Enum : (A : 𝕌) → Vec ⟦ A ⟧ ∣ A ∣
Enum 𝟘 = []
Enum 𝟙 = tt ∷ []
Enum (A₁ +ᵤ A₂) = map inj₁ (Enum A₁) ++ map inj₂ (Enum A₂)
Enum (A₁ ×ᵤ A₂) = Vec× (Enum A₁) (Enum A₂)
Find : {A : 𝕌} (x : ⟦ A ⟧) → Σ[ i ∈ Fin ∣ A ∣ ] (x ≡ lookup (Enum A) i)
Find {𝟘} ()
Find {𝟙} tt = index tt∈𝟙 , lookup-index tt∈𝟙
where
tt∈𝟙 : Any (tt ≡_) (Enum 𝟙)
tt∈𝟙 = here refl
Find {A₁ +ᵤ A₂} (inj₁ x) =
let i , p₁ = Find x in
let x∈A₁ : Any ((inj₁ x) ≡_) (Enum (A₁ +ᵤ A₂))
x∈A₁ = ++⁺ˡ {xs = map inj₁ (Enum A₁)} (∈map inj₁ x (any≡← _ i p₁)) in
index x∈A₁ , lookup-index x∈A₁
Find {A₁ +ᵤ A₂} (inj₂ y) =
let j , p₂ = Find y in
let y∈A₂ : Any ((inj₂ y) ≡_) (Enum (A₁ +ᵤ A₂))
y∈A₂ = ++⁺ʳ (map inj₁ (Enum A₁)) (∈map inj₂ y (any≡← _ j p₂)) in
index y∈A₂ , lookup-index y∈A₂
Find {A₁ ×ᵤ A₂} (x , y) =
let i , p₁ = Find x
j , p₂ = Find y in
let xy∈A₁×A₂ : Any ((x , y) ≡_) (Enum (A₁ ×ᵤ A₂))
xy∈A₁×A₂ = inVec× (Enum A₁) (Enum A₂) x y (any≡← (Enum A₁) i p₁) (any≡← (Enum A₂) j p₂) in
index xy∈A₁×A₂ , lookup-index xy∈A₁×A₂
Find' : {A : 𝕌} (x : ⟦ A ⟧) → Fin ∣ A ∣
Find' = proj₁ ∘ Find
card= : {t₁ t₂ : 𝕌} (C : t₁ ⟷ t₂) → (∣ t₁ ∣ ≡ ∣ t₂ ∣)
card= unite₊l = refl
card= uniti₊l = refl
card= unite₊r = +-identityʳ _
card= uniti₊r = sym $ +-identityʳ _
card= {t₁ +ᵤ t₂} swap₊ = +-comm ∣ t₁ ∣ ∣ t₂ ∣
card= {t₁ +ᵤ t₂ +ᵤ t₃} assocl₊ = sym $ +-assoc ∣ t₁ ∣ _ _
card= {(t₁ +ᵤ t₂) +ᵤ t₃} assocr₊ = +-assoc ∣ t₁ ∣ ∣ t₂ ∣ _
card= {_} {t₂} unite⋆l rewrite +-identityʳ ∣ t₂ ∣ = refl
card= {t₁} {_} uniti⋆l rewrite +-identityʳ ∣ t₁ ∣ = refl
card= {_} {t₂} unite⋆r rewrite *-identityʳ ∣ t₂ ∣ = refl
card= {t₁} {_} uniti⋆r rewrite *-identityʳ ∣ t₁ ∣ = refl
card= {t₁ ×ᵤ t₂} {_} swap⋆ rewrite *-comm ∣ t₁ ∣ ∣ t₂ ∣ = refl
card= {t₁ ×ᵤ t₂ ×ᵤ t₃} {_} assocl⋆ rewrite *-assoc ∣ t₁ ∣ ∣ t₂ ∣ (∣ t₃ ∣) = refl
card= {(t₁ ×ᵤ t₂) ×ᵤ t₃} {_} assocr⋆ rewrite *-assoc ∣ t₁ ∣ ∣ t₂ ∣ (∣ t₃ ∣) = refl
card= absorbr = refl
card= {t ×ᵤ 𝟘} {_} absorbl rewrite *-zeroʳ ∣ t ∣ = refl
card= {_} {t ×ᵤ 𝟘} factorzr rewrite *-zeroʳ ∣ t ∣ = refl
card= factorzl = refl
card= {(t₁ +ᵤ t₂) ×ᵤ t₃} {_} dist rewrite *-distribʳ-+ ∣ t₃ ∣ ∣ t₁ ∣ (∣ t₂ ∣) = refl
card= {_} {(t₁ +ᵤ t₂) ×ᵤ t₃} factor rewrite *-distribʳ-+ ∣ t₃ ∣ ∣ t₁ ∣ (∣ t₂ ∣) = refl
card= {t₃ ×ᵤ (t₁ +ᵤ t₂)} {_} distl rewrite *-distribˡ-+ ∣ t₃ ∣ ∣ t₁ ∣ (∣ t₂ ∣) = refl
card= {_} {t₃ ×ᵤ (t₁ +ᵤ t₂)} factorl rewrite *-distribˡ-+ ∣ t₃ ∣ ∣ t₁ ∣ (∣ t₂ ∣) = refl
card= id⟷ = refl
card= (c₁ ⊚ c₂) = trans (card= c₁) (card= c₂)
card= (c₁ ⊕ c₂) = cong₂ _+_ (card= c₁) (card= c₂)
card= (c₁ ⊗ c₂) = cong₂ _*_ (card= c₁) (card= c₂)
data State (A : 𝕌) : Set where
⟪_[_]⟫ : Vec ⟦ A ⟧ ∣ A ∣ → Fin ∣ A ∣ → State A
resolve : {A : 𝕌} → State A → ⟦ A ⟧
resolve ⟪ v [ i ]⟫ = lookup v i
st : {A B : 𝕌} → ⟦ A ⟧ → (c : A ⟷ B) → Σ[ C ∈ 𝕌 ] (C ⟷ B × State C)
st (inj₂ y) (unite₊l {t}) = _ , id⟷ , ⟪ Enum t [ Find' y ]⟫
st a (uniti₊l {t}) = _ , id⟷ , ⟪ (Enum (𝟘 +ᵤ t)) [ Find' a ]⟫
st (inj₁ x) (unite₊r {t}) = _ , id⟷ , ⟪ Enum t [ Find' x ]⟫
st a (uniti₊r {t}) = _ , id⟷ , ⟪ (Enum (t +ᵤ 𝟘)) [ Find' {t +ᵤ 𝟘} (inj₁ a) ]⟫
st (inj₁ x) (swap₊ {t₁} {t₂}) = _ , id⟷ , ⟪ Enum _ [ Find' {t₂ +ᵤ t₁} (inj₂ x) ]⟫
st (inj₂ y) (swap₊ {t₁} {t₂}) = _ , id⟷ , ⟪ Enum _ [ Find' {t₂ +ᵤ t₁} (inj₁ y) ]⟫
st (inj₁ x) (assocl₊ {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {(t₁ +ᵤ t₂) +ᵤ t₃} (inj₁ (inj₁ x)) ]⟫
st (inj₂ (inj₁ x)) (assocl₊ {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {(t₁ +ᵤ t₂) +ᵤ t₃} (inj₁ (inj₂ x)) ]⟫
st (inj₂ (inj₂ y)) (assocl₊ {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {(t₁ +ᵤ t₂) +ᵤ t₃} (inj₂ y) ]⟫
st (inj₁ (inj₁ x)) (assocr₊ {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {t₁ +ᵤ t₂ +ᵤ t₃} (inj₁ x) ]⟫
st (inj₁ (inj₂ y)) (assocr₊ {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {t₁ +ᵤ t₂ +ᵤ t₃} (inj₂ (inj₁ y)) ]⟫
st (inj₂ y) (assocr₊ {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {t₁ +ᵤ t₂ +ᵤ t₃} (inj₂ (inj₂ y)) ]⟫
st (tt , y) unite⋆l = _ , id⟷ , ⟪ Enum _ [ Find' y ]⟫
st a uniti⋆l = _ , id⟷ , ⟪ Enum _ [ Find' (tt , a) ]⟫
st (x , tt) unite⋆r = _ , id⟷ , ⟪ Enum _ [ Find' x ]⟫
st a uniti⋆r = _ , id⟷ , ⟪ Enum _ [ Find' (a , tt) ]⟫
st (x , y) swap⋆ = _ , id⟷ , ⟪ Enum _ [ Find' (y , x) ]⟫
st (x , y , z) assocl⋆ = _ , id⟷ , ⟪ Enum _ [ Find' ((x , y) , z) ]⟫
st ((x , y) , z) assocr⋆ = _ , id⟷ , ⟪ Enum _ [ Find' (x , y , z) ]⟫
st (inj₁ x , y) (dist {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {t₁ ×ᵤ t₃ +ᵤ t₂ ×ᵤ t₃} (inj₁ (x , y)) ]⟫
st (inj₂ x , y) (dist {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {t₁ ×ᵤ t₃ +ᵤ t₂ ×ᵤ t₃} (inj₂ (x , y)) ]⟫
st (inj₁ (x , y)) (factor {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {(t₁ +ᵤ t₂) ×ᵤ t₃} (inj₁ x , y) ]⟫
st (inj₂ (y , z)) (factor {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {(t₁ +ᵤ t₂) ×ᵤ t₃} (inj₂ y , z) ]⟫
st (x , inj₁ y) (distl {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {(t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃)} (inj₁ (x , y)) ]⟫
st (x , inj₂ y) (distl {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {(t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃)} (inj₂ (x , y)) ]⟫
st (inj₁ (x , y)) (factorl {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {t₁ ×ᵤ (t₂ +ᵤ t₃)} (x , inj₁ y) ]⟫
st (inj₂ (x , z)) (factorl {t₁} {t₂} {t₃}) = _ , id⟷ , ⟪ Enum _ [ Find' {t₁ ×ᵤ (t₂ +ᵤ t₃)} (x , inj₂ z) ]⟫
st a id⟷ = _ , id⟷ , ⟪ Enum _ [ Find' a ]⟫
st a (id⟷ ⊚ c) = _ , c , ⟪ Enum _ [ Find' a ]⟫
st a (c₁ ⊚ c₂) = let _ , c , st' = st a c₁ in
_ , c ⊚ c₂ , st'
st (inj₁ x) (_⊕_ {t₁} {t₂} {_} {t₄} id⟷ c₂) = _ , id⟷ , ⟪ Enum _ [ Find' {_ +ᵤ t₄} (inj₁ x) ]⟫
st (inj₁ x) (_⊕_ {t₁} {t₂} c₁ c₂) = let _ , c , st' = st x c₁ in
_ , c ⊕ c₂ , ⟪ Enum _ [ Find' {_ +ᵤ t₂} (inj₁ $ resolve st') ]⟫
st (inj₂ y) (_⊕_ {t₁} {t₂} {t₃} {_} c₁ id⟷) = _ , id⟷ , ⟪ Enum _ [ Find' {t₃ +ᵤ _} (inj₂ y) ]⟫
st (inj₂ y) (_⊕_ {t₁} c₁ c₂) = let _ , c , st' = st y c₂ in
_ , c₁ ⊕ c , ⟪ Enum _ [ Find' {t₁ +ᵤ _} (inj₂ $ resolve st') ]⟫
st (x , y) (id⟷ ⊗ id⟷) = _ , id⟷ , ⟪ Enum _ [ Find' (x , y) ]⟫
st (x , y) (id⟷ ⊗ c₂) = let _ , c , st' = st y c₂ in
_ , id⟷ ⊗ c , ⟪ Enum _ [ Find' (x , resolve st') ]⟫
st (x , y) (c₁ ⊗ c₂) = let _ , c , st' = st x c₁ in
_ , c ⊗ c₂ , ⟪ Enum _ [ Find' (resolve st' , y) ]⟫
step : {A B : 𝕌} (c : A ⟷ B) → State A → Σ[ C ∈ 𝕌 ] (C ⟷ B × State C)
step c ⟪ v [ i ]⟫ = st (lookup v i) c
data State' : ℕ → Set where
⟪_∥_[_]⟫ : {A B : 𝕌} → A ⟷ B → Vec ⟦ A ⟧ ∣ A ∣ → Fin ∣ A ∣ → State' ∣ A ∣
step' : ∀ {n} → State' n → State' n
step' (⟪_∥_[_]⟫ {A} {B} c v i) with step c ⟪ v [ i ]⟫
... | A' , c' , ⟪ v' [ i' ]⟫ rewrite card= (c ⊚ ! c') = ⟪ c' ∥ v' [ i' ]⟫
run : (sz n : ℕ) → (st : State' sz) → Vec (State' sz) (suc n)
run sz 0 st = [ st ]
run sz (suc n) st with run sz n st
... | sts with last sts
... | ⟪_∥_[_]⟫ {A} {B} cx vx ix rewrite +-comm 1 (suc n) = sts ++ [ step' ⟪ cx ∥ vx [ ix ]⟫ ]
𝔹 : 𝕌
𝔹 = 𝟙 +ᵤ 𝟙
pattern 𝔽 = inj₁ tt
pattern 𝕋 = inj₂ tt
CNOT : 𝔹 ×ᵤ 𝔹 ⟷ 𝔹 ×ᵤ 𝔹
CNOT = dist ⊚ (id⟷ ⊕ (id⟷ ⊗ swap₊)) ⊚ factor
ex₁ : Vec (State' ∣ 𝔹 ×ᵤ 𝔹 ∣) 8
ex₁ = run ∣ 𝔹 ×ᵤ 𝔹 ∣ 7 ⟪ CNOT ∥ Enum (𝔹 ×ᵤ 𝔹) [ Fin.fromℕ 3 ]⟫
| 44.964567
| 117
| 0.435338
|
5e9d0d01f978a72e36610da8e2d7f93474598338
| 8,931
|
agda
|
Agda
|
src/Data/PropFormula/Theorems/Biimplication.agda
|
jonaprieto/agda-prop
|
a1730062a6aaced2bb74878c1071db06477044ae
|
[
"MIT"
] | 13
|
2017-05-01T16:45:41.000Z
|
2022-01-17T03:33:12.000Z
|
src/Data/PropFormula/Theorems/Biimplication.agda
|
jonaprieto/agda-prop
|
a1730062a6aaced2bb74878c1071db06477044ae
|
[
"MIT"
] | 18
|
2017-03-08T14:33:10.000Z
|
2017-12-18T16:34:21.000Z
|
src/Data/PropFormula/Theorems/Biimplication.agda
|
jonaprieto/agda-prop
|
a1730062a6aaced2bb74878c1071db06477044ae
|
[
"MIT"
] | 2
|
2017-03-30T16:41:56.000Z
|
2017-12-01T17:01:25.000Z
|
------------------------------------------------------------------------------
-- Agda-Prop Library.
-- Theorems of ⇔ connective.
------------------------------------------------------------------------------
open import Data.Nat using ( ℕ )
module Data.PropFormula.Theorems.Biimplication ( n : ℕ ) where
------------------------------------------------------------------------------
open import Data.PropFormula.Theorems.Classical n
open import Data.PropFormula.Theorems.Implication n
using ( ⊃-to-¬∨; ⊃⊃-to-∧⊃; ∧⊃-to-⊃⊃ )
open import Data.PropFormula.Theorems.Negation n
using ( ¬-equiv₁ ; ¬-equiv₂; ¬∨-to-⊃; ¬¬-equiv₁; ¬¬-equiv₂ )
open import Data.PropFormula.Syntax n
open import Function using ( _$_ )
------------------------------------------------------------------------------
-- Theorem.
⇔-equiv₁
: ∀ {Γ} {φ ψ}
→ Γ ⊢ φ ⇔ ψ
→ Γ ⊢ (φ ⊃ ψ) ∧ (ψ ⊃ φ)
-- Proof.
⇔-equiv₁ {Γ}{φ}{ψ} Γ⊢φ⇔ψ =
∧-intro
(⊃-intro
(⇔-elim₁
(assume φ)
(weaken φ Γ⊢φ⇔ψ)))
(⊃-intro
(⇔-elim₂
(assume ψ)
(weaken ψ Γ⊢φ⇔ψ)))
-------------------------------------------------------------------------- ∎
-- Theorem.
⇔-equiv₂
: ∀ {Γ} {φ ψ}
→ Γ ⊢ (φ ⊃ ψ) ∧ (ψ ⊃ φ)
→ Γ ⊢ φ ⇔ ψ
-- Proof.
⇔-equiv₂ {φ = φ}{ψ} Γ⊢⟪φ⊃ψ⟫∧⟪ψ⊃φ⟫ =
⇔-intro
(⊃-elim
(weaken φ (∧-proj₁ Γ⊢⟪φ⊃ψ⟫∧⟪ψ⊃φ⟫))
(assume φ))
(⊃-elim
(weaken ψ (∧-proj₂ Γ⊢⟪φ⊃ψ⟫∧⟪ψ⊃φ⟫))
(assume ψ))
-------------------------------------------------------------------------- ∎
-- Theorem.
⇔-equiv
: ∀ {Γ} {φ ψ}
→ Γ ⊢ (φ ⇔ ψ) ⇔ ((φ ⊃ ψ) ∧ (ψ ⊃ φ))
-- Proof.
⇔-equiv {Γ}{φ}{ψ} =
⇔-intro
(⇔-equiv₁
(assume (φ ⇔ ψ)))
(⇔-equiv₂
(assume ((φ ⊃ ψ) ∧ (ψ ⊃ φ))))
-------------------------------------------------------------------------- ∎
-- Theorem.
⇔-assoc₁
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ φ ⇔ (ψ ⇔ γ)
→ Γ ⊢ (φ ⇔ ψ) ⇔ γ
-- Proof.
⇔-assoc₁ {Γ}{φ = φ}{ψ}{γ} thm =
⇔-intro
(RAA
(¬-elim
(¬-intro
(¬-elim
(¬-intro
(¬-elim
(weaken φ $ weaken (ψ ⇔ γ) $ assume {Γ = Γ , φ ⇔ ψ} (¬ γ))
(⇔-elim₁
(⇔-elim₁
(assume {Γ = Γ , φ ⇔ ψ , ¬ γ , ψ ⇔ γ} φ)
(weaken φ $ weaken (ψ ⇔ γ)
(weaken (¬ γ) $ assume (φ ⇔ ψ))))
(⇔-elim₁
(assume {Γ = Γ , φ ⇔ ψ , ¬ γ , ψ ⇔ γ} φ)
(weaken φ $ weaken (ψ ⇔ γ) $ weaken (¬ γ) $
weaken (φ ⇔ ψ) thm)))))
(⇔-elim₂
(assume {Γ = Γ , φ ⇔ ψ , ¬ γ} (ψ ⇔ γ))
(weaken (ψ ⇔ γ) $ weaken (¬ γ) $ weaken (φ ⇔ ψ) thm))))
(⇔-intro
(⊥-elim γ
(¬-elim
(⊥-elim (¬ ψ)
(¬-elim
(¬-intro -- ¬ φ
(¬-elim
(weaken φ $ weaken ψ $ assume {Γ = Γ , φ ⇔ ψ} (¬ γ))
(⇔-elim₁
(⇔-elim₁
(assume {Γ = Γ , φ ⇔ ψ , ¬ γ , ψ} φ)
(weaken φ
(weaken ψ
(weaken (¬ γ)
(assume (φ ⇔ ψ))))))
(⇔-elim₁
(assume {Γ = Γ , φ ⇔ ψ , ¬ γ , ψ} φ)
(weaken φ $
weaken ψ $ weaken (¬ γ) $ weaken (φ ⇔ ψ) thm)))))
(⇔-elim₂ -- φ
(assume {Γ = Γ , φ ⇔ ψ , ¬ γ} ψ)
(weaken ψ (weaken (¬ γ) (assume (φ ⇔ ψ)))))))
(assume {Γ = Γ , φ ⇔ ψ , ¬ γ} ψ)))
(⊥-elim ψ
(¬-elim
(weaken γ $ assume {Γ = Γ , φ ⇔ ψ} (¬ γ))
(assume {Γ = Γ , φ ⇔ ψ , ¬ γ} γ))))))
(⇔-intro
(⇔-elim₂
(weaken φ $ assume γ)
(⇔-elim₁
(assume {Γ = Γ , γ} φ)
(weaken φ $ weaken γ thm)))
(⇔-elim₂
(⇔-intro
(weaken ψ $ weaken ψ $ assume γ)
(weaken γ $ assume {Γ = Γ , γ} ψ))
(weaken ψ $ weaken γ thm)))
-------------------------------------------------------------------------- ∎
-- Theorem.
⇔-assoc₂
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ (φ ⇔ ψ) ⇔ γ
→ Γ ⊢ φ ⇔ (ψ ⇔ γ)
-- Proof.
⇔-assoc₂ {Γ}{φ}{ψ}{γ} thm =
⇔-intro
(⇔-intro
(⇔-elim₁
(⇔-intro
(weaken φ (assume {Γ = Γ , φ} ψ))
(weaken ψ (weaken ψ (assume φ))))
(weaken ψ (weaken φ thm)))
(⇔-elim₁
(weaken γ (assume φ))
(⇔-elim₂
(assume {Γ = Γ , φ} γ)
(weaken γ (weaken φ thm)))))
(RAA
(¬-elim
(¬-intro
(¬-elim
(¬-intro
(¬-elim
(weaken γ $ weaken (φ ⇔ ψ) $ assume {Γ = Γ , ψ ⇔ γ} (¬ φ))
(⇔-elim₂
(⇔-elim₂
(assume {Γ = Γ , ψ ⇔ γ , ¬ φ , (φ ⇔ ψ)} γ)
(weaken γ $ weaken (φ ⇔ ψ) $ weaken (¬ φ) $
assume (ψ ⇔ γ)))
(⇔-elim₂
(assume {Γ = Γ , ψ ⇔ γ , ¬ φ , (φ ⇔ ψ)} γ)
(weaken γ $ weaken (φ ⇔ ψ) $ weaken (¬ φ) $
weaken (ψ ⇔ γ) thm)))))
(⇔-elim₁
(assume {Γ = Γ , ψ ⇔ γ , ¬ φ} (φ ⇔ ψ))
(weaken (φ ⇔ ψ) (weaken (¬ φ) (weaken (ψ ⇔ γ) thm))))))
(⇔-intro
(⊥-elim ψ
(¬-elim
(weaken φ $ assume {Γ = Γ , ψ ⇔ γ} (¬ φ))
(assume {Γ = Γ , ψ ⇔ γ , ¬ φ} φ)))
(⊥-elim φ
(¬-elim
(⊥-elim (¬ ψ)
(¬-elim
(¬-intro
(¬-elim
(weaken γ $ weaken ψ $ assume {Γ = Γ , ψ ⇔ γ} (¬ φ))
(⇔-elim₂
(weaken γ $ assume {Γ = Γ , ψ ⇔ γ , ¬ φ} ψ)
(⇔-elim₂
(assume {Γ = Γ , ψ ⇔ γ , ¬ φ , ψ} γ)
(weaken γ $ weaken ψ $ weaken (¬ φ) $
weaken (ψ ⇔ γ) thm)))))
(⇔-elim₁
(assume {Γ = Γ , ψ ⇔ γ , ¬ φ} ψ)
(weaken ψ (weaken (¬ φ) (assume (ψ ⇔ γ)))))))
(assume {Γ = Γ , ψ ⇔ γ , ¬ φ} ψ))))))
-------------------------------------------------------------------------- ∎
-- Theorem.
⇔-assoc
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ (φ ⇔ (ψ ⇔ γ)) ⇔ ((φ ⇔ ψ) ⇔ γ)
-- Proof.
⇔-assoc {φ = φ}{ψ}{γ} =
⇔-intro
(⇔-assoc₁ (assume (φ ⇔ ψ ⇔ γ)))
(⇔-assoc₂ (assume ((φ ⇔ ψ) ⇔ γ)))
-------------------------------------------------------------------------- ∎
-- Theorem.
⇔-comm
: ∀ {Γ} {φ ψ}
→ Γ ⊢ φ ⇔ ψ
→ Γ ⊢ ψ ⇔ φ
-- Proof.
⇔-comm {Γ}{φ}{ψ} Γ⊢φ⇔ψ =
⇔-intro
(⇔-elim₂ (assume ψ) (weaken ψ Γ⊢φ⇔ψ))
(⇔-elim₁ (assume φ) (weaken φ Γ⊢φ⇔ψ))
-------------------------------------------------------------------------- ∎
-- Theorem.
⊃-⇔-¬∨
: ∀ {Γ} {φ ψ}
→ Γ ⊢ (φ ⊃ ψ) ⇔ (¬ φ ∨ ψ)
-- Proof.
⊃-⇔-¬∨ {Γ}{φ}{ψ} =
⇔-intro
(⊃-to-¬∨ (assume (φ ⊃ ψ)))
(¬∨-to-⊃ (assume (¬ φ ∨ ψ)))
-------------------------------------------------------------------------- ∎
-- Theorem.
bicon₀-thm
: ∀ {Γ} {φ ψ}
→ Γ ⊢ φ ⇔ ψ → Γ ⊢ ¬ φ
→ Γ ⊢ ¬ ψ
⇔-¬-to-¬ = bicon₀-thm
-- Proof.
bicon₀-thm {Γ}{φ}{ψ} Γ⊢φ⇔ψ Γ⊢¬ψ =
¬-equiv₂
(⊃-intro
(¬-elim
(weaken ψ Γ⊢¬ψ)
(⇔-elim₂
(assume ψ)
(weaken ψ Γ⊢φ⇔ψ))))
-------------------------------------------------------------------------- ∎
-- Theorem.
bicon₁-thm
: ∀ {Γ} {φ ψ}
→ Γ ⊢ ¬ φ ⇔ ψ → Γ ⊢ φ
→ Γ ⊢ ¬ ψ
¬⇔-to-¬ = bicon₁-thm
-- Proof.
bicon₁-thm {Γ}{φ}{ψ} Γ⊢¬φ⇔ψ Γ⊢φ =
¬-equiv₂
(⊃-intro
(¬-elim
(⇔-elim₂
(assume ψ)
(weaken ψ Γ⊢¬φ⇔ψ))
(weaken ψ Γ⊢φ)))
-------------------------------------------------------------------------- ∎
-- Theorem.
¬-equiv
: ∀ {Γ} {φ}
→ Γ ⊢ ¬ φ ⇔ (φ ⊃ ⊥)
-- Proof.
¬-equiv {Γ}{φ} =
⇔-intro
(¬-equiv₁ (assume (¬ φ)))
(¬-equiv₂ (assume (φ ⊃ ⊥)))
-------------------------------------------------------------------------- ∎
-- Theorem.
¬¬-equiv
: ∀ {Γ} {φ}
→ Γ ⊢ ¬ (¬ φ) ⇔ φ
-- Proof.
¬¬-equiv {Γ}{φ} =
⇔-intro
(¬¬-equiv₁ (assume (¬ (¬ φ))))
(¬¬-equiv₂ (assume φ))
-------------------------------------------------------------------------- ∎
-- Theorem.
⊃⊃-⇔-∧⊃
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ (φ ⊃ (ψ ⊃ γ)) ⇔ ((φ ∧ ψ) ⊃ γ)
-- Proof.
⊃⊃-⇔-∧⊃ {φ = φ}{ψ}{γ} =
⇔-intro
(⊃⊃-to-∧⊃ (assume (φ ⊃ ψ ⊃ γ)))
(∧⊃-to-⊃⊃ (assume (φ ∧ ψ ⊃ γ)))
-------------------------------------------------------------------------- ∎
-- Theorem.
⇔-trans
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ γ ⇔ φ
→ Γ ⊢ φ ⇔ ψ
→ Γ ⊢ γ ⇔ ψ
subst⊢⇔₁ = ⇔-trans
-- Proof.
⇔-trans {φ = φ}{ψ}{γ} Γ⊢γ⇔φ Γ⊢φ⇔ψ =
⇔-intro
(⇔-elim₁
(⇔-elim₁
(assume γ)
(weaken γ Γ⊢γ⇔φ))
(weaken γ Γ⊢φ⇔ψ))
(⇔-elim₂
(⇔-elim₂
(assume ψ)
(weaken ψ Γ⊢φ⇔ψ))
(weaken ψ Γ⊢γ⇔φ))
-------------------------------------------------------------------------- ∎
| 26.580357
| 78
| 0.285074
|
2facd10a82fdc951a0525739f9b040747c529a68
| 12,831
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Container/Relation/Unary/Any/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Container/Relation/Unary/Any/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Container/Relation/Unary/Any/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Propertiers of any for containers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Container.Relation.Unary.Any.Properties where
open import Level
open import Algebra
open import Data.Product as Prod using (∃; _×_; ∃₂; _,_; proj₂)
open import Data.Product.Function.NonDependent.Propositional using (_×-cong_)
import Data.Product.Function.Dependent.Propositional as Σ
open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_])
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (equivalence)
open import Function.HalfAdjointEquivalence using (_≃_; ↔→≃)
open import Function.Inverse as Inv using (_↔_; inverse; module Inverse)
open import Function.Related as Related using (Related; SK-sym)
open import Function.Related.TypeIsomorphisms
open import Relation.Unary using (Pred ; _∪_ ; _∩_)
open import Relation.Binary using (REL)
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≗_; refl)
open Related.EquationalReasoning hiding (_≡⟨_⟩_)
private
module ×⊎ {k ℓ} = CommutativeSemiring (×-⊎-commutativeSemiring k ℓ)
open import Data.Container.Core
import Data.Container.Combinator as C
open import Data.Container.Combinator.Properties
open import Data.Container.Related
open import Data.Container.Relation.Unary.Any as Any using (◇; any)
open import Data.Container.Membership
module _ {s p} (C : Container s p) {x} {X : Set x} {ℓ} {P : Pred X ℓ} where
-- ◇ can be unwrapped to reveal the Σ type
↔Σ : ∀ {xs : ⟦ C ⟧ X} → ◇ C P xs ↔ ∃ λ p → P (proj₂ xs p)
↔Σ {xs} = inverse ◇.proof any (λ _ → P.refl) (λ _ → P.refl)
-- ◇ can be expressed using _∈_.
↔∈ : ∀ {xs : ⟦ C ⟧ X} → ◇ C P xs ↔ (∃ λ x → x ∈ xs × P x)
↔∈ {xs} = inverse to from (λ _ → P.refl) (to∘from) where
to : ◇ C P xs → ∃ λ x → x ∈ xs × P x
to (any (p , Px)) = (proj₂ xs p , (any (p , P.refl)) , Px)
from : (∃ λ x → x ∈ xs × P x) → ◇ C P xs
from (.(proj₂ xs p) , (any (p , refl)) , Px) = any (p , Px)
to∘from : to ∘ from ≗ id
to∘from (.(proj₂ xs p) , any (p , refl) , Px) = P.refl
module _ {s p} {C : Container s p} {x} {X : Set x}
{ℓ₁ ℓ₂} {P₁ : Pred X ℓ₁} {P₂ : Pred X ℓ₂} where
-- ◇ is a congruence for bag and set equality and related preorders.
cong : ∀ {k} {xs₁ xs₂ : ⟦ C ⟧ X} →
(∀ x → Related k (P₁ x) (P₂ x)) → xs₁ ∼[ k ] xs₂ →
Related k (◇ C P₁ xs₁) (◇ C P₂ xs₂)
cong {k} {xs₁} {xs₂} P₁↔P₂ xs₁≈xs₂ =
◇ C P₁ xs₁ ↔⟨ ↔∈ C ⟩
(∃ λ x → x ∈ xs₁ × P₁ x) ∼⟨ Σ.cong Inv.id (xs₁≈xs₂ ×-cong P₁↔P₂ _) ⟩
(∃ λ x → x ∈ xs₂ × P₂ x) ↔⟨ SK-sym (↔∈ C) ⟩
◇ C P₂ xs₂ ∎
-- Nested occurrences of ◇ can sometimes be swapped.
module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂}
{x y} {X : Set x} {Y : Set y} {r} {P : REL X Y r} where
swap : {xs : ⟦ C₁ ⟧ X} {ys : ⟦ C₂ ⟧ Y} →
let ◈ : ∀ {s p} {C : Container s p} {x} {X : Set x} {ℓ} → ⟦ C ⟧ X → Pred X ℓ → Set (p ⊔ ℓ)
◈ = λ {_} {_} → flip (◇ _) in
◈ xs (◈ ys ∘ P) ↔ ◈ ys (◈ xs ∘ flip P)
swap {xs} {ys} =
◇ _ (λ x → ◇ _ (P x) ys) xs ↔⟨ ↔∈ C₁ ⟩
(∃ λ x → x ∈ xs × ◇ _ (P x) ys) ↔⟨ Σ.cong Inv.id $ Σ.cong Inv.id $ ↔∈ C₂ ⟩
(∃ λ x → x ∈ xs × ∃ λ y → y ∈ ys × P x y) ↔⟨ Σ.cong Inv.id (λ {x} → ∃∃↔∃∃ (λ _ y → y ∈ ys × P x y)) ⟩
(∃₂ λ x y → x ∈ xs × y ∈ ys × P x y) ↔⟨ ∃∃↔∃∃ (λ x y → x ∈ xs × y ∈ ys × P x y) ⟩
(∃₂ λ y x → x ∈ xs × y ∈ ys × P x y) ↔⟨ Σ.cong Inv.id (λ {y} → Σ.cong Inv.id (λ {x} →
(x ∈ xs × y ∈ ys × P x y) ↔⟨ SK-sym Σ-assoc ⟩
((x ∈ xs × y ∈ ys) × P x y) ↔⟨ Σ.cong (×-comm _ _) Inv.id ⟩
((y ∈ ys × x ∈ xs) × P x y) ↔⟨ Σ-assoc ⟩
(y ∈ ys × x ∈ xs × P x y) ∎)) ⟩
(∃₂ λ y x → y ∈ ys × x ∈ xs × P x y) ↔⟨ Σ.cong Inv.id (λ {y} → ∃∃↔∃∃ {B = y ∈ ys} (λ x _ → x ∈ xs × P x y)) ⟩
(∃ λ y → y ∈ ys × ∃ λ x → x ∈ xs × P x y) ↔⟨ Σ.cong Inv.id (Σ.cong Inv.id (SK-sym (↔∈ C₁))) ⟩
(∃ λ y → y ∈ ys × ◇ _ (flip P y) xs) ↔⟨ SK-sym (↔∈ C₂) ⟩
◇ _ (λ y → ◇ _ (flip P y) xs) ys ∎
-- Nested occurrences of ◇ can sometimes be flattened.
module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂}
{x} {X : Set x} {ℓ} (P : Pred X ℓ) where
flatten : ∀ (xss : ⟦ C₁ ⟧ (⟦ C₂ ⟧ X)) →
◇ C₁ (◇ C₂ P) xss ↔
◇ (C₁ C.∘ C₂) P (Inverse.from (Composition.correct C₁ C₂) ⟨$⟩ xss)
flatten xss = inverse t f (λ _ → P.refl) (λ _ → P.refl) where
◇₁ = ◇ C₁; ◇₂ = ◇ C₂; ◇₁₂ = ◇ (C₁ C.∘ C₂)
open Inverse
t : ◇₁ (◇₂ P) xss → ◇₁₂ P (from (Composition.correct C₁ C₂) ⟨$⟩ xss)
t (any (p₁ , (any (p₂ , p)))) = any (any (p₁ , p₂) , p)
f : ◇₁₂ P (from (Composition.correct C₁ C₂) ⟨$⟩ xss) → ◇₁ (◇₂ P) xss
f (any (any (p₁ , p₂) , p)) = any (p₁ , any (p₂ , p))
-- Sums commute with ◇ (for a fixed instance of a given container).
module _ {s p} {C : Container s p} {x} {X : Set x}
{ℓ ℓ′} {P : Pred X ℓ} {Q : Pred X ℓ′} where
◇⊎↔⊎◇ : ∀ {xs : ⟦ C ⟧ X} → ◇ C (P ∪ Q) xs ↔ (◇ C P xs ⊎ ◇ C Q xs)
◇⊎↔⊎◇ {xs} = inverse to from from∘to to∘from
where
to : ◇ C (λ x → P x ⊎ Q x) xs → ◇ C P xs ⊎ ◇ C Q xs
to (any (pos , inj₁ p)) = inj₁ (any (pos , p))
to (any (pos , inj₂ q)) = inj₂ (any (pos , q))
from : ◇ C P xs ⊎ ◇ C Q xs → ◇ C (λ x → P x ⊎ Q x) xs
from = [ Any.map₂ inj₁ , Any.map₂ inj₂ ]
from∘to : from ∘ to ≗ id
from∘to (any (pos , inj₁ p)) = P.refl
from∘to (any (pos , inj₂ q)) = P.refl
to∘from : to ∘ from ≗ id
to∘from = [ (λ _ → P.refl) , (λ _ → P.refl) ]
-- Products "commute" with ◇.
module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂}
{x y} {X : Set x} {Y : Set y} {ℓ ℓ′} {P : Pred X ℓ} {Q : Pred Y ℓ′} where
×◇↔◇◇× : ∀ {xs : ⟦ C₁ ⟧ X} {ys : ⟦ C₂ ⟧ Y} →
◇ C₁ (λ x → ◇ C₂ (λ y → P x × Q y) ys) xs ↔ (◇ C₁ P xs × ◇ C₂ Q ys)
×◇↔◇◇× {xs} {ys} = inverse to from (λ _ → P.refl) (λ _ → P.refl)
where
◇₁ = ◇ C₁; ◇₂ = ◇ C₂
to : ◇₁ (λ x → ◇₂ (λ y → P x × Q y) ys) xs → ◇₁ P xs × ◇₂ Q ys
to (any (p₁ , any (p₂ , p , q))) = (any (p₁ , p) , any (p₂ , q))
from : ◇₁ P xs × ◇₂ Q ys → ◇₁ (λ x → ◇₂ (λ y → P x × Q y) ys) xs
from (any (p₁ , p) , any (p₂ , q)) = any (p₁ , any (p₂ , p , q))
-- map can be absorbed by the predicate.
module _ {s p} (C : Container s p) {x y} {X : Set x} {Y : Set y}
{ℓ} (P : Pred Y ℓ) where
map↔∘ : ∀ {xs : ⟦ C ⟧ X} (f : X → Y) → ◇ C P (map f xs) ↔ ◇ C (P ∘′ f) xs
map↔∘ {xs} f =
◇ C P (map f xs) ↔⟨ ↔Σ C ⟩
∃ (P ∘′ proj₂ (map f xs)) ↔⟨⟩
∃ (P ∘′ f ∘′ proj₂ xs) ↔⟨ SK-sym (↔Σ C) ⟩
◇ C (P ∘′ f) xs ∎
-- Membership in a mapped container can be expressed without reference
-- to map.
module _ {s p} (C : Container s p) {x y} {X : Set x} {Y : Set y}
{ℓ} (P : Pred Y ℓ) where
∈map↔∈×≡ : ∀ {f : X → Y} {xs : ⟦ C ⟧ X} {y} →
y ∈ map f xs ↔ (∃ λ x → x ∈ xs × y ≡ f x)
∈map↔∈×≡ {f = f} {xs} {y} =
y ∈ map f xs ↔⟨ map↔∘ C (y ≡_) f ⟩
◇ C (λ x → y ≡ f x) xs ↔⟨ ↔∈ C ⟩
∃ (λ x → x ∈ xs × y ≡ f x) ∎
-- map is a congruence for bag and set equality and related preorders.
module _ {s p} (C : Container s p) {x y} {X : Set x} {Y : Set y}
{ℓ} (P : Pred Y ℓ) where
map-cong : ∀ {k} {f₁ f₂ : X → Y} {xs₁ xs₂ : ⟦ C ⟧ X} →
f₁ ≗ f₂ → xs₁ ∼[ k ] xs₂ →
map f₁ xs₁ ∼[ k ] map f₂ xs₂
map-cong {f₁ = f₁} {f₂} {xs₁} {xs₂} f₁≗f₂ xs₁≈xs₂ {x} =
x ∈ map f₁ xs₁ ↔⟨ map↔∘ C (_≡_ x) f₁ ⟩
◇ C (λ y → x ≡ f₁ y) xs₁ ∼⟨ cong (Related.↔⇒ ∘ helper) xs₁≈xs₂ ⟩
◇ C (λ y → x ≡ f₂ y) xs₂ ↔⟨ SK-sym (map↔∘ C (_≡_ x) f₂) ⟩
x ∈ map f₂ xs₂ ∎
where
helper : ∀ y → (x ≡ f₁ y) ↔ (x ≡ f₂ y)
helper y rewrite f₁≗f₂ y = Inv.id
-- Uses of linear morphisms can be removed.
module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂}
{x} {X : Set x} {ℓ} (P : Pred X ℓ) where
remove-linear : ∀ {xs : ⟦ C₁ ⟧ X} (m : C₁ ⊸ C₂) → ◇ C₂ P (⟪ m ⟫⊸ xs) ↔ ◇ C₁ P xs
remove-linear {xs} m = Inv.inverse t f f∘t t∘f
where
open _≃_
open P.≡-Reasoning renaming (_∎ to _∎′)
position⊸m : ∀ {s} → Position C₂ (shape⊸ m s) ≃ Position C₁ s
position⊸m = ↔→≃ (position⊸ m)
◇₁ = ◇ C₁; ◇₂ = ◇ C₂
t : ◇₂ P (⟪ m ⟫⊸ xs) → ◇₁ P xs
t = Any.map₁ (_⊸_.morphism m)
f : ◇₁ P xs → ◇₂ P (⟪ m ⟫⊸ xs)
f (any (x , p)) =
any $ from position⊸m x
, P.subst (P ∘′ proj₂ xs) (P.sym (right-inverse-of position⊸m _)) p
f∘t : f ∘ t ≗ id
f∘t (any (p₂ , p)) = P.cong any $ Inverse.to Σ-≡,≡↔≡ ⟨$⟩
( left-inverse-of position⊸m p₂
, (P.subst (P ∘ proj₂ xs ∘ to position⊸m)
(left-inverse-of position⊸m p₂)
(P.subst (P ∘ proj₂ xs)
(P.sym (right-inverse-of position⊸m
(to position⊸m p₂)))
p) ≡⟨ P.subst-∘ (left-inverse-of position⊸m _) ⟩
P.subst (P ∘ proj₂ xs)
(P.cong (to position⊸m)
(left-inverse-of position⊸m p₂))
(P.subst (P ∘ proj₂ xs)
(P.sym (right-inverse-of position⊸m
(to position⊸m p₂)))
p) ≡⟨ P.cong (λ eq → P.subst (P ∘ proj₂ xs) eq
(P.subst (P ∘ proj₂ xs)
(P.sym (right-inverse-of position⊸m _)) _))
(_≃_.left-right position⊸m _) ⟩
P.subst (P ∘ proj₂ xs)
(right-inverse-of position⊸m
(to position⊸m p₂))
(P.subst (P ∘ proj₂ xs)
(P.sym (right-inverse-of position⊸m
(to position⊸m p₂)))
p) ≡⟨ P.subst-subst (P.sym (right-inverse-of position⊸m _)) ⟩
P.subst (P ∘ proj₂ xs)
(P.trans
(P.sym (right-inverse-of position⊸m
(to position⊸m p₂)))
(right-inverse-of position⊸m
(to position⊸m p₂)))
p ≡⟨ P.cong (λ eq → P.subst (P ∘ proj₂ xs) eq p)
(P.trans-symˡ (right-inverse-of position⊸m _)) ⟩
P.subst (P ∘ proj₂ xs) P.refl p ≡⟨⟩
p ∎′)
)
t∘f : t ∘ f ≗ id
t∘f (any (p₁ , p)) = P.cong any $ Inverse.to Σ-≡,≡↔≡ ⟨$⟩
( right-inverse-of position⊸m p₁
, (P.subst (P ∘ proj₂ xs)
(right-inverse-of position⊸m p₁)
(P.subst (P ∘ proj₂ xs)
(P.sym (right-inverse-of position⊸m p₁))
p) ≡⟨ P.subst-subst (P.sym (right-inverse-of position⊸m _)) ⟩
P.subst (P ∘ proj₂ xs)
(P.trans
(P.sym (right-inverse-of position⊸m p₁))
(right-inverse-of position⊸m p₁))
p ≡⟨ P.cong (λ eq → P.subst (P ∘ proj₂ xs) eq p)
(P.trans-symˡ (right-inverse-of position⊸m _)) ⟩
P.subst (P ∘ proj₂ xs) P.refl p ≡⟨⟩
p ∎′)
)
-- Linear endomorphisms are identity functions if bag equality is used.
module _ {s p} {C : Container s p} {x} {X : Set x} where
linear-identity : ∀ {xs : ⟦ C ⟧ X} (m : C ⊸ C) → ⟪ m ⟫⊸ xs ∼[ bag ] xs
linear-identity {xs} m {x} =
x ∈ ⟪ m ⟫⊸ xs ↔⟨ remove-linear (_≡_ x) m ⟩
x ∈ xs ∎
-- If join can be expressed using a linear morphism (in a certain
-- way), then it can be absorbed by the predicate.
module _ {s₁ s₂ s₃ p₁ p₂ p₃}
{C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂} {C₃ : Container s₃ p₃}
{x} {X : Set x} {ℓ} (P : Pred X ℓ) where
join↔◇ : (join′ : (C₁ C.∘ C₂) ⊸ C₃) (xss : ⟦ C₁ ⟧ (⟦ C₂ ⟧ X)) →
let join : ∀ {X} → ⟦ C₁ ⟧ (⟦ C₂ ⟧ X) → ⟦ C₃ ⟧ X
join = λ {_} → ⟪ join′ ⟫⊸ ∘
_⟨$⟩_ (Inverse.from (Composition.correct C₁ C₂)) in
◇ C₃ P (join xss) ↔ ◇ C₁ (◇ C₂ P) xss
join↔◇ join xss =
◇ C₃ P (⟪ join ⟫⊸ xss′) ↔⟨ remove-linear P join ⟩
◇ (C₁ C.∘ C₂) P xss′ ↔⟨ SK-sym $ flatten P xss ⟩
◇ C₁ (◇ C₂ P) xss ∎
where xss′ = Inverse.from (Composition.correct C₁ C₂) ⟨$⟩ xss
| 41.257235
| 130
| 0.446107
|
0d8fa65c284151ee79b0304ce020a846e37fa492
| 6,758
|
agda
|
Agda
|
main/NielsenSchreier.agda
|
awswan/nielsenschreier-hott
|
84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d
|
[
"MIT"
] | null | null | null |
main/NielsenSchreier.agda
|
awswan/nielsenschreier-hott
|
84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d
|
[
"MIT"
] | null | null | null |
main/NielsenSchreier.agda
|
awswan/nielsenschreier-hott
|
84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --exact-split --rewriting --overlapping-instances #-}
open import lib.Basics
open import lib.NConnected
open import lib.NType2
open import lib.types.Truncation
open import lib.types.Sigma
open import lib.Equivalence
open import lib.types.Fin
open import lib.types.Coproduct
open import Graphs.Definition
open import Graphs.Properties
open import Coequalizers.Definition
open import Coequalizers.Misc
open import Groups.Definition
open import Coequalizers.PullbackStability
open import Coequalizers.PreserveEquivalence
open import Coequalizers.EdgeCoproduct
open import Graphs.SpanningTreeFinite
open import Graphs.SubTrees
open import Util.Misc
open import Util.DecEq
module NielsenSchreier {i : ULevel} where
{- We build towards the proof of the finite index Nielsen-Schreier theorem in several steps. -}
{- We will first show that subgroups of free higher groups are free higher groupoids. That is, we will show that
for any family of types X over ⊤ / A, the total space Σ (⊤ / A) X is equivalent to the coequalizer of
a graph. Moveover, we can give an explicit description of the graph. -}
module SubgroupsOfFreeHigherGroups (A : Type i) (X : (⊤ / A) → Type i) where
instance
{- Whenever we need a pair of maps (A × X fhg-base) ⇉ (X fhg-base) we will use the definition below. This
applies in this module and wherever it is imported. -}
higher-subgp-gph : Graph (A × X fhg-base) (X fhg-base)
higher-subgp-gph = record { π₀ = snd ; π₁ = λ {(a , x) → transport X (quot a) x} }
to-free-higher-gpd : Σ (⊤ / A) X ≃ (X fhg-base) / (A × X fhg-base)
to-free-higher-gpd =
Σ (⊤ / A) X
≃⟨ pb-equiv ⁻¹ ⟩ -- coequalizers are stable under pullback
(Σ ⊤ (X ∘ c[_])) / (Σ A (X ∘ c[_] ∘ π₀))
≃⟨ Coeq-emap Σ₁-Unit (ide _) (λ _ → idp) (λ _ → idp) ⟩
(X fhg-base) / (A × X fhg-base)
≃∎
where
open PullbackStability A ⊤ X -- contains definition of (Σ ⊤ (X ∘ c[_])) / (Σ A (X ∘ c[_] ∘ π₀))
{- We now show that subgroups of free groups are free groupoids. This is a 1-truncated version of
the result above. -}
module SubGroupsOfFreeGroups (A : Type i) (X : ∥ ⊤ / A ∥₁ → Type i)
⦃ Xset : {z : ∥ ⊤ / A ∥₁} → is-set (X z) ⦄ where -- we now need to assume X is 0-truncated.
open SubgroupsOfFreeHigherGroups A (X ∘ [_]) public -- also defines instance for (X fhg-base) / (A × X fhg-base)
to-free-gpd : Σ ∥ ⊤ / A ∥₁ X ≃ ∥ X base / (A × X base) ∥₁
to-free-gpd =
Σ ∥ ⊤ / A ∥₁ X
≃⟨ Σ-emap-r (Trunc-elim λ z → ide _) ⟩
Σ ∥ ⊤ / A ∥₁ X'
≃⟨ TruncRecType.flattening-Trunc _ ⟩
∥ Σ (⊤ / A) (X ∘ [_]) ∥₁
≃⟨ Trunc-emap to-free-higher-gpd ⟩
∥ X base / (A × X base) ∥₁
≃∎
where
X'-set : ∥ ⊤ / A ∥₁ → hSet i
X'-set = Trunc-rec (λ z → ((X [ z ]) , Xset))
X' = fst ∘ X'-set
instance
X-≃-gpd : {z : ∥ ⊤ / A ∥₁} → is-gpd (X z ≃ X' z)
X-≃-gpd {z} = raise-level 0 (≃-level Xset (snd (X'-set z)))
{- A free groupoid with vertex set a definitionally finite set is merely equivalent
to a free group. -}
strict-fin-free-gpd-is-free-gp :
(n : ℕ) → (E : Type i) → (Edec : has-dec-eq E) →
⦃ gph : Graph E (Fin (S n)) ⦄ ⦃ conn : gph-is-connected gph ⦄ →
∥ Σ (Type i) (λ B → ∥ Coeq gph ∥₁ ≃ FreeGroup B) ∥
strict-fin-free-gpd-is-free-gp n E Edec =
Trunc-fmap from-spanning-tree-fin (spanning-tree E Edec n)
where
from-spanning-tree-fin : SpanningTree E (Fin (S n)) (Fin n) (Fin (S n)) →
Σ (Type i) (λ B → ∥ Fin (S n) / E ∥₁ ≃ FreeGroup B)
from-spanning-tree-fin st =
¬E' , Trunc-emap eq
where
open SpanningTree st
open ExtendSpanningTree E (Fin (S n)) (Fin n) (Fin (S n)) st
open CoeqCoprodEquiv (Fin (S n)) (Fin n) ¬E'
eq : Fin (S n) / E ≃ ⊤ / ¬E'
eq =
Fin (S n) / E
≃⟨ spantree-equiv ⟩
Fin (S n) / ((Fin n) ⊔ ¬E')
≃⟨ edge-coproduct-expand ⟩
(Fin (S n) / (Fin n)) / ¬E'
≃⟨ Coeq-emap (contr-equiv-Unit ⟨⟩) (ide _) (λ _ → idp) (λ _ → idp) ⟩
⊤ / ¬E'
≃∎
{- We generalise the above so that the vertex set only needs to be equivalent to a
definitionally finite set. -}
fin-free-gpd-is-free-gp : (n : ℕ) → (E : Type i) → (Edec : has-dec-eq E) →
(V : Type i) → (Vfin : V ≃ Fin (S n)) →
⦃ gph : Graph E V ⦄ ⦃ conn : gph-is-connected gph ⦄ →
∥ Σ (Type i) (λ B → ∥ Coeq gph ∥₁ ≃ FreeGroup B) ∥
fin-free-gpd-is-free-gp n E Edec V Vfin =
Trunc-fmap (λ {(B , e) → B , (e ∘e Trunc-emap coeq-equiv)}) (strict-fin-free-gpd-is-free-gp n E Edec)
where
instance
gph' : Graph E (Fin (S n))
gph' = record { π₀ = (–> Vfin) ∘ π₀ ; π₁ = (–> Vfin) ∘ π₁ }
coeq-equiv : (V / E) ≃ (Fin (S n) / E)
coeq-equiv = Coeq-emap Vfin (ide E) (λ _ → idp) λ _ → idp
instance
conn' : gph-is-connected gph'
conn' = equiv-preserves-level (Trunc-emap coeq-equiv )
{- We can now prove the finite index version of the Nielsen-Schreier theorem. -}
nielsen-schreier-finite-index :
(A : Type i) (Adec : has-dec-eq A) -- we are given a type A with decidable equality
(X : (FreeGroup A) → Type i) -- together with a covering space over the free group on A, that is a family of types X ...
⦃ conn : is-connected 0 (Σ (FreeGroup A) X) ⦄ -- such that the total space is connected
(n : ℕ) (Xfin : X (base) ≃ Fin (S n)) → -- here we do the finite index case
∥ Σ (Type i) (λ B → Σ (FreeGroup A) X ≃ FreeGroup B) ∥ -- then the total space is a free group
nielsen-schreier-finite-index A Adec X n Xfin =
Trunc-fmap (λ {(B , e) → B , e ∘e to-free-gpd}) -- we compose the two equivalences from earlier
(fin-free-gpd-is-free-gp n (A × X base) (×-has-dec-eq Adec (equiv-preserves-dec-eq Xfin Fin-has-dec-eq)) (X base) Xfin)
-- earlier we showed that free groupoids with finite vertex set are merely equivalent to free groups
where
open SubGroupsOfFreeGroups A X -- contains our proof that the subgroup is a free groupoid
instance -- we use that X is a set and the free groupoid is connected
Xset : {z : (FreeGroup A)} → is-set (X z)
Xset {z} = Trunc-elim {P = λ z → is-set (X z)}
(Coeq-elim (λ z → is-set (X [ z ]))
(λ {unit → equiv-preserves-level (Xfin ⁻¹) ⦃ Fin-is-set ⦄}) λ _ → prop-has-all-paths-↓) z
conn2 : is-connected 0 (X base / (A × X base))
conn2 = equiv-preserves-level e
where
e : ∥ Σ (FreeGroup A) X ∥₀ ≃ ∥ X base / (A × X base) ∥₀
e =
∥ Σ (FreeGroup A) X ∥₀
≃⟨ Trunc-emap (to-free-gpd ) ⟩
∥ ∥ X base / (A × X base) ∥₁ ∥₀
≃⟨ Trunc-fuse _ 0 1 ⟩
∥ X base / (A × X base) ∥₀
≃∎
| 41.207317
| 132
| 0.583605
|
21451e6ecf64d5e88603d75ecedd51f7ebc46eed
| 2,164
|
agda
|
Agda
|
test/epic/Prelude/IO.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | null | null | null |
test/epic/Prelude/IO.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | null | null | null |
test/epic/Prelude/IO.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
module Prelude.IO where
open import Prelude.Bool
open import Prelude.Char
open import Prelude.Nat
open import Prelude.String
open import Prelude.Unit
open import Prelude.Vec
open import Prelude.Float
postulate
IO : Set → Set
{-# COMPILED_TYPE IO IO #-}
infixl 1 _>>=_
postulate
return : ∀ {A} → A → IO A
_>>=_ : ∀ {A B} → IO A → (A → IO B) → IO B
numArgs : Nat
getArg : Nat -> String
args : Vec String numArgs
args = buildArgs numArgs
where
buildArgs : (n : Nat) -> Vec String n
buildArgs Z = []
buildArgs (S n) = snoc (buildArgs n) (getArg n)
{-# COMPILED_EPIC return (u1 : Unit, a : Any) -> Any = ioreturn(a) #-}
{-# COMPILED_EPIC _>>=_ (u1 : Unit, u2 : Unit, x : Any, f : Any) -> Any = iobind(x,f) #-}
{-# COMPILED_EPIC numArgs () -> BigInt = foreign BigInt "numArgsBig" () #-}
{-# COMPILED_EPIC getArg (n : BigInt) -> Any = foreign Any "getArgBig" (n : BigInt) #-}
postulate
natToString : Nat -> String
readNat : IO Nat
readStr : IO String
putStr : String -> IO Unit
printChar : Char -> IO Unit
putStrLn : String -> IO Unit
putStrLn s = putStr s >>= \_ -> putStr "\n"
printFloat : Float -> IO Unit
printFloat f = putStr (floatToString f)
printNat : Nat -> IO Unit
printNat n = putStr (natToString n)
printBool : Bool -> IO Unit
printBool true = putStr "true"
printBool false = putStr "false"
{-# COMPILED_EPIC natToString (n : Any) -> String = bigToStr(n) #-}
{-# COMPILED_EPIC readNat (u : Unit) -> Any = strToBig(readStr(u)) #-}
{-# COMPILED_EPIC putStr (a : String, u : Unit) -> Unit = foreign Int "wputStr" (a : String); primUnit #-}
-- {-# COMPILED_EPIC putStrLn (a : String, u : Unit) -> Unit = putStrLn (a) #-}
{-# COMPILED_EPIC readStr (u : Unit) -> Data = readStr(u) #-}
{-# COMPILED_EPIC printChar (c : Int, u : Unit) -> Unit = printChar(c) #-}
infixr 2 _<$>_
_<$>_ : {A B : Set}(f : A -> B)(m : IO A) -> IO B
f <$> x = x >>= λ y -> return (f y)
infixr 0 bind
bind : ∀ {A B} → IO A → (A → IO B) → IO B
bind m f = m >>= f
infixr 0 then
then : ∀ {A B} -> IO A -> IO B -> IO B
then m f = m >>= λ _ -> f
syntax bind e (\ x -> f) = x <- e , f
syntax then e f = e ,, f
| 27.392405
| 106
| 0.597505
|
301c2131654ace3b2c9bb83fea497455df3fbb01
| 1,647
|
agda
|
Agda
|
src/Categories/Diagram/Equalizer/Properties.agda
|
maxsnew/agda-categories
|
8f3c844d929508040dfa21f681fa260056214b73
|
[
"MIT"
] | null | null | null |
src/Categories/Diagram/Equalizer/Properties.agda
|
maxsnew/agda-categories
|
8f3c844d929508040dfa21f681fa260056214b73
|
[
"MIT"
] | null | null | null |
src/Categories/Diagram/Equalizer/Properties.agda
|
maxsnew/agda-categories
|
8f3c844d929508040dfa21f681fa260056214b73
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Diagram.Equalizer.Properties {o ℓ e} (C : Category o ℓ e) where
open import Categories.Diagram.Equalizer C
open import Categories.Morphism C
open import Categories.Morphism.Reasoning C
private
module C = Category C
open C
variable
X Y Z : Obj
f g : X ⇒ Y
module _ (equalizer : Equalizer f g) where
open Equalizer equalizer
open HomReasoning
equalizer-≈⇒≈ : ∀ {h} → arr ∘ h ≈ id → f ≈ g
equalizer-≈⇒≈ {h} eq = begin
f ≈⟨ introʳ eq ⟩
f ∘ arr ∘ h ≈⟨ pullˡ equality ⟩
(g ∘ arr) ∘ h ≈⟨ cancelʳ eq ⟩
g ∎
section-equalizer : ∀ {X Y} {f : Y ⇒ X} {g : X ⇒ Y} → f SectionOf g → IsEqualizer f (f ∘ g) id
section-equalizer {X = X} {Y = Y} {f = f} {g = g} g∘f≈id = record
{ equality = equality
; equalize = equalize
; universal = λ {_} {_} {eq} → universal {eq = eq}
; unique = unique
}
where
open HomReasoning
equality : (f ∘ g) ∘ f ≈ id ∘ f
equality = begin
(f ∘ g) ∘ f ≈⟨ pullʳ g∘f≈id ⟩
f ∘ id ≈⟨ id-comm ⟩
id ∘ f ∎
equalize : ∀ {Z} {h : Z ⇒ X} → (f ∘ g) ∘ h ≈ id ∘ h → Z ⇒ Y
equalize {h = h} _ = g ∘ h
universal : ∀ {Z} {h : Z ⇒ X} {eq : (f ∘ g) ∘ h ≈ id ∘ h} → h ≈ f ∘ g ∘ h
universal {h = h} {eq = eq} = begin
h ≈˘⟨ identityˡ ⟩
id ∘ h ≈˘⟨ eq ⟩
(f ∘ g) ∘ h ≈⟨ assoc ⟩
f ∘ g ∘ h ∎
unique : ∀ {Z} {h : Z ⇒ X} {i : Z ⇒ Y} → h ≈ f ∘ i → i ≈ g ∘ h
unique {h = h} {i = i} h≈g∘i = begin
i ≈⟨ introˡ g∘f≈id ⟩
(g ∘ f) ∘ i ≈⟨ pullʳ (⟺ h≈g∘i) ⟩
g ∘ h ∎
| 27
| 94
| 0.485124
|
0de069db55154cbb7b8037390226be58b124a29f
| 308
|
agda
|
Agda
|
Function.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Function.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Function.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Function where
import Lvl
open import Type
-- The domain type of a function.
domain : ∀{ℓ₁ ℓ₂} {A : Type{ℓ₁}}{B : Type{ℓ₂}} → (A → B) → Type{ℓ₁}
domain{A = A} _ = A
-- The codomain type of a function.
codomain : ∀{ℓ₁ ℓ₂} {A : Type{ℓ₁}}{B : Type{ℓ₂}} → (A → B) → Type{ℓ₂}
codomain{B = B} _ = B
| 23.692308
| 69
| 0.584416
|
376420dd166388c340d950976b5563351711c068
| 4,972
|
agda
|
Agda
|
Codata/Segments.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Codata/Segments.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Codata/Segments.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
open import Prelude
open import Algebra
open import Algebra.Monus
module Codata.Segments
{ℓ}
(mon : CTMAPOM ℓ)
where
open CTMAPOM mon
private variable i j : 𝑆
-- This is a type which contains some finite and some infinite lists.
-- The idea is that each entry contains a parameter (w) which says
-- how much coinductive "fuel" it uses.
-- The Colist′ A i type represents a colist which is defined down to depth
-- i; the Colist A type represents a "true" colist, i.e. a colist defined for
-- any given depth.
infixr 5 _◃_
data Colist′ {a} (A : Type a) (i : 𝑆) : Type (a ℓ⊔ ℓ) where
_◃_ : ∀ w → -- Segment size
( (w<i : w < i) → -- If there is enough fuel left (i is the fuel)
-- (also the _<_ type is a proposition)
A × Colist′ A (i ∸ w) -- Produce an element followed by the rest of
-- the list, with w taken out of the fuel.
) →
Colist′ A i
Colist : Type a → Type (a ℓ⊔ ℓ)
Colist A = ∀ {i} → Colist′ A i
-- The main interesting things tyhis type can do are the following:
-- * Infinite lists.
-- * The "fuel" parameter can be an arbitrary monoid, not just ℕ
-- * Finite lists can also be specified, and the way we say something is
-- finite is by taking no fuel.
-- * Everything seems to correspond correctly to the monus axioms.
--------------------------------------------------------------------------------
-- Finite colists
--------------------------------------------------------------------------------
-- By adding a finite prefix you don't have to use any of the fuel.
_∹_ : A → Colist A → Colist A
x ∹ xs = ε ◃ λ _ → x , xs
--------------------------------------------------------------------------------
-- Empty colists
--------------------------------------------------------------------------------
-- To terminate computation you use all the fuel, making an empty list.
-- (I'm not sure how principled this is: semantically I don't know if I like
-- that the size of a segment can depend on the supplied size parameter).
empty : Colist A
empty {i = i} = i ◃ λ i<i → ⊥-elim (irrefl i<i)
--------------------------------------------------------------------------------
-- Finite derived colists
--------------------------------------------------------------------------------
-- singleton
pure : A → Colist A
pure x = x ∹ empty
replicate : ℕ → A → Colist A
replicate zero x = empty
replicate (suc n) x = x ∹ replicate n x
--------------------------------------------------------------------------------
-- Infinite colists
--------------------------------------------------------------------------------
-- This unfold function produces an infinite list; it needs every size segment
-- be non empty so that each step uses some fuel. This is what provides the
-- termination argument.
module _
(B : 𝑆 → Type b) -- The seed type
(ϕ : ∀ {i} → -- At depth i
B i → -- With this seed
∃ w × -- Produce a segment of size w
(w ≢ ε) × -- w can't be ε, so that we use some of the fuel to prove
-- termination
((w<i : w < i) → A × B (i ∸ w)) -- And produce the cons constructor.
)
-- ^ The step function
where
unfold′ : Acc _<_ i → B i → Colist′ A i
unfold′ a = uncurry _◃_
∘ map₂
(λ { (w≢ε , xs′) w<i →
map₂ (case a of
λ { (acc wf) →
unfold′ (wf _ (∸‿<-< _ _ w<i w≢ε)) })
(xs′ w<i) })
∘ ϕ
unfold : (fdc : WellFounded _<_)
(B : 𝑆 → Type b)
(ϕ : ∀ {i} → B i → ∃ w × (w ≢ ε) × ((w<i : w < i) → A × B (i ∸ w))) →
(∀ {i} → B i) → Colist A
unfold fdc B ϕ xs {i} = unfold′ B ϕ (fdc i) xs
-- Here's a simple example using the unfold function: this produces infinitely
-- repeated values, with segment size s.
repeat : (fdc : WellFounded _<_) (s : 𝑆) (s≢ε : s ≢ ε) (x : A) → Colist A
repeat fdc s s≢ε x = unfold fdc (const ⊤) (λ _ → s , s≢ε , const (x , tt)) tt
--------------------------------------------------------------------------------
-- Manipulating colists
--------------------------------------------------------------------------------
-- One important thing to note about the Colist type: it is inductive!
-- Although it does technically represent "coinduction", the constructors and
-- type itself are inductive as far as Agda can see. For that reason functions
-- like map pass the termination checker with no extra ceremony.
map : (A → B) → Colist′ A i → Colist′ B i
map f (w ◃ xs) = w ◃ λ w<i → case xs w<i of λ { (y , ys) → f y , map f ys }
-- You can extract a finite prefix of the colist.
open import Data.List using (List; _∷_; [])
take′ : ∀ i → Colist′ A i → List A
take′ i (w ◃ xs) with w <? i
... | no _ = []
... | yes w<i with xs w<i
... | y , ys = y ∷ take′ _ ys
take : 𝑆 → Colist A → List A
take x xs = take′ x xs
| 37.383459
| 80
| 0.483709
|
a0fd7a74499065d427271b8dc4591c0d9d012b3e
| 5,078
|
agda
|
Agda
|
agda/book/Programming_Language_Foundations_in_Agda/x02-842Induction.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/book/Programming_Language_Foundations_in_Agda/x02-842Induction.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/book/Programming_Language_Foundations_in_Agda/x02-842Induction.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
module x02-842Induction where
-- Library
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_)
-- PLFA coverage of identity, associativity, commutativity, distributivity.
-- An example of the associative law for addition.
_ : (3 + 4) + 5 ≡ 3 + (4 + 5)
_ =
begin
(3 + 4) + 5
≡⟨⟩
7 + 5
≡⟨⟩
12
≡⟨⟩
3 + 9
≡⟨⟩
3 + (4 + 5)
∎
-- A theorem easy to prove.
+-identityᴸ : ∀ (m : ℕ) → zero + m ≡ m
+-identityᴸ m = {!!}
-- A first nontrivial theorem.
-- An equational proof is shown in PLFA.
-- It uses helpers cong and sym imported from the standard library,
-- and a form of equational reasoning that allows more elaborate justification.
-- Instead we will use 'rewrite'.
+-identityʳ : ∀ (m : ℕ) → m + zero ≡ m
+-identityʳ m = {!!}
-- Associativity of addition.
-- (Done first in PLFA.)
+-assoc : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc m n p = {!!}
-- A useful lemma about addition.
-- Equational proof shown in PLFA.
+-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
+-suc m n = {!!}
-- Commutativity of addition.
-- Equational proof shown in PLFA.
+-comm : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm m n = {!!}
-- 842 exercise: AddSwap (1 point)
-- Please do this without using induction/recursion.
+-swap : ∀ (m n p : ℕ) → (m + n) + p ≡ n + (m + p)
+-swap m n p = {!!}
-- 842 exercise: AddDistMult (2 points)
-- Show that addition distributes over multiplication.
*-+-rdistrib : ∀ (m n p : ℕ) → (m + n) * p ≡ m * p + n * p
*-+-rdistrib m n p = {!!}
-- 842 exercise: MultAssoc (2 points)
-- Show that multiplication is associative.
*-assoc : ∀ (m n p : ℕ) → (m * n) * p ≡ m * (n * p)
*-assoc m n p = {!!}
-- 842 exercise: MultComm (3 points)
-- Show that multiplication is commutative.
-- As with the addition proof above, helper lemmas will be needed.
*-comm : ∀ (m n : ℕ) → m * n ≡ n * m
*-comm m n = {!!}
-- 842 exercise: LeftMonusZero (1 point)
-- PLFA asks "Did your proof require induction?"
-- (which should give you an indication of the expected answer).
0∸n≡0 : ∀ (m : ℕ) → zero ∸ m ≡ zero
0∸n≡0 m = {!!}
-- 842 exercise: MonusAssocish (2 points)
-- Show a form of associativity for monus.
∸-+-assoc : ∀ (m n p : ℕ) → m ∸ n ∸ p ≡ m ∸ (n + p)
∸-+-assoc m n p = {!!}
-- 842 extended exercise: properties of binary representation.
-- This is based on the PLFA Bin-laws exercise.
-- Copied from 842Naturals.
data Bin-ℕ : Set where
bits : Bin-ℕ
_x0 : Bin-ℕ → Bin-ℕ
_x1 : Bin-ℕ → Bin-ℕ
dbl : ℕ → ℕ
dbl zero = zero
dbl (suc n) = suc (suc (dbl n))
-- Copy your versions of 'inc', 'to', 'from', 'bin-+' over from 842Naturals.
-- You may choose to change them here to make proofs easier.
-- But make sure to test them if you do!
inc : Bin-ℕ → Bin-ℕ
inc m = {!!}
tob : ℕ → Bin-ℕ
tob m = {!!}
fromb : Bin-ℕ → ℕ
fromb m = {!!}
_bin-+_ : Bin-ℕ → Bin-ℕ → Bin-ℕ
m bin-+ n = {!!}
-- 842 exercise: DoubleB (1 point)
-- Write the Bin-ℕ version of dbl, here called dblb.
-- As with the other Bin-ℕ operations, don't use tob/fromb.
dblb : Bin-ℕ → Bin-ℕ
dblb m = {!!}
-- Here are some properties of tob/fromb/inc suggested by PLFA Induction.
-- Please complete the proofs.
-- 842 exercise: FromInc (1 point)
from∘inc : ∀ (m : Bin-ℕ) → fromb (inc m) ≡ suc (fromb m)
from∘inc m = {!!}
-- 842 exercise: FromToB (1 point)
from∘tob : ∀ (m : ℕ) → fromb (tob m) ≡ m
from∘tob m = {!!}
-- 842 exercise: ToFromB (2 points)
-- The property ∀ (m : Bin-ℕ) → tob (fromb m) ≡ m cannot be proved.
-- Can you see why?
-- However, this restriction of it can be proved.
to/from-corr : ∀ (m : Bin-ℕ) (n : ℕ) → m ≡ tob n → fromb m ≡ n
to/from-corr m n m≡tn = {!!}
-- Here are a few more properties for you to prove.
-- 842 exercise: DblBInc (1 point)
dblb∘inc : ∀ (m : Bin-ℕ) → dblb (inc m) ≡ inc (inc (dblb m))
dblb∘inc m = {!!}
-- 842 exercise: ToDbl (1 point)
to∘dbl : ∀ (m : ℕ) → tob (dbl m) ≡ dblb (tob m)
to∘dbl m = {!!}
-- 842 exercise: FromDblB (1 point)
from∘dblb : ∀ (m : Bin-ℕ) → fromb (dblb m) ≡ dbl (fromb m)
from∘dblb m = {!!}
-- 842 exercise: BinPlusLInc (2 points)
-- This helper function translates the second case for unary addition
-- suc m + n = suc (m + n)
-- into the binary setting. It's useful in the next proof.
-- Hint: induction on both m and n is needed.
bin-+-linc : ∀ (m n : Bin-ℕ) → (inc m) bin-+ n ≡ inc (m bin-+ n)
bin-+-linc m n = {!!}
-- 842 exercise: PlusUnaryBinary (2 points)
-- This theorem relates unary and binary addition.
to∘+ : ∀ (m n : ℕ) → tob (m + n) ≡ tob m bin-+ tob n
to∘+ m n = {!!}
-- This ends the extended exercise.
-- The following theorems proved in PLFA can be found in the standard library.
-- import Data.Nat.Properties using (+-assoc; +-identityʳ; +-suc; +-comm)
-- Unicode used in this chapter:
{-
∀ U+2200 FOR ALL (\forall, \all)
ʳ U+02B3 MODIFIER LETTER SMALL R (\^r)
′ U+2032 PRIME (\')
″ U+2033 DOUBLE PRIME (\')
‴ U+2034 TRIPLE PRIME (\')
⁗ U+2057 QUADRUPLE PRIME (\')
-}
| 24.531401
| 79
| 0.596298
|
36ebcec936f5bc8501c9b996726730703d471900
| 866
|
agda
|
Agda
|
test/Succeed/Issue1783.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1783.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1783.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-01-19, issue raised by Twey
-- {-# OPTIONS -v 10 #-}
{-# OPTIONS --allow-unsolved-metas #-}
Rel : Set → Set₁
Rel A = A → A → Set
record Category : Set₁ where
field
Obj : Set
_⇒_ : Rel Obj -- unfolding the definition of Rel removes the error
record Product (C : Category) (A B : Category.Obj C) : Set where
field
A×B : Category.Obj C
postulate
anything : ∀{a}{A : Set a} → A
trivial : ∀ {C} → Category.Obj C → Set
trivial _ = anything
map-obj : ∀ {P : _} → trivial (Product.A×B P) -- Note: hole _ cannot be filled
map-obj = anything
{- Error thrown during printing open metas:
piApply
t = Rel _24 Def Issue1783.Rel [Apply []r(MetaV (MetaId 24) [])]}
args = @0 [[]r{Var 0 []}]
An internal error has occurred. Please report this as a bug.
Location of the error: src/full/Agda/TypeChecking/Substitute.hs:382
-}
| 25.470588
| 78
| 0.639723
|
34d5f2708262349bb2ec6938bd7ff357927f5f20
| 1,731
|
agda
|
Agda
|
Groups/Groups.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Groups/Groups.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Groups/Groups.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Groups.Definition
open import Sets.EquivalenceRelations
module Groups.Groups where
reflGroupWellDefined : {lvl : _} {A : Set lvl} {m n x y : A} {op : A → A → A} → m ≡ x → n ≡ y → (op m n) ≡ (op x y)
reflGroupWellDefined {lvl} {A} {m} {n} {.m} {.n} {op} refl refl = refl
fourWay+Associative : {a b : _} → {A : Set a} → {S : Setoid {a} {b} A} → {_·_ : A → A → A} → (G : Group S _·_) → {r s t u : A} → (Setoid._∼_ S) (r · ((s · t) · u)) ((r · s) · (t · u))
fourWay+Associative {S = S} {_·_} G {r} {s} {t} {u} = transitive p1 (transitive p2 p3)
where
open Group G renaming (inverse to _^-1)
open Setoid S
open Equivalence eq
p1 : r · ((s · t) · u) ∼ (r · (s · t)) · u
p2 : (r · (s · t)) · u ∼ ((r · s) · t) · u
p3 : ((r · s) · t) · u ∼ (r · s) · (t · u)
p1 = Group.+Associative G
p2 = Group.+WellDefined G (Group.+Associative G) reflexive
p3 = symmetric (Group.+Associative G)
fourWay+Associative' : {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_·_ : A → A → A} (G : Group S _·_) {a b c d : A} → (Setoid._∼_ S (((a · b) · c) · d) (a · ((b · c) · d)))
fourWay+Associative' {S = S} G = transitive (symmetric +Associative) (symmetric (fourWay+Associative G))
where
open Group G
open Setoid S
open Equivalence eq
fourWay+Associative'' : {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_·_ : A → A → A} (G : Group S _·_) {a b c d : A} → (Setoid._∼_ S (a · (b · (c · d))) (a · ((b · c) · d)))
fourWay+Associative'' {S = S} {_·_ = _·_} G = transitive +Associative (symmetric (fourWay+Associative G))
where
open Group G
open Setoid S
open Equivalence eq
| 45.552632
| 183
| 0.548816
|
21d3429bc17d0c0c77bc2b93c7b46847b1d513ba
| 5,432
|
agda
|
Agda
|
Categories/NaturalTransformation/Core.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 1
|
2018-12-29T21:51:57.000Z
|
2018-12-29T21:51:57.000Z
|
Categories/NaturalTransformation/Core.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | null | null | null |
Categories/NaturalTransformation/Core.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --universe-polymorphism #-}
module Categories.NaturalTransformation.Core where
open import Level
open import Relation.Binary using (Rel; IsEquivalence)
open import Categories.Support.Equivalence
open import Categories.Category
open import Categories.Functor.Core renaming (id to idF; _∘_ to _∘F_)
record NaturalTransformation {o ℓ e o′ ℓ′ e′}
{C : Category o ℓ e}
{D : Category o′ ℓ′ e′}
(F G : Functor C D) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
private module C = Category C
private module D = Category D
private module F = Functor F
private module G = Functor G
open F using (F₀; F₁)
open G using () renaming (F₀ to G₀; F₁ to G₁)
field
η : ∀ X → D [ F₀ X , G₀ X ]
.commute : ∀ {X Y} (f : C [ X , Y ]) → D.CommutativeSquare (F₁ f) (η X) (η Y) (G₁ f)
op : NaturalTransformation G.op F.op
op = record
{ η = η
; commute = λ f → D.Equiv.sym (commute f)
}
id : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {F : Functor C D} → NaturalTransformation F F
id {C = C} {D} {F} = record
{ η = λ _ → D.id
; commute = commute′
}
where
module C = Category C
module D = Category D
module F = Functor F
open F
.commute′ : ∀ {X Y} (f : C [ X , Y ]) → D [ D [ D.id ∘ F₁ f ] ≡ D [ F₁ f ∘ D.id ] ]
commute′ f = begin
D [ D.id ∘ F₁ f ]
↓⟨ D.identityˡ ⟩
F₁ f
↑⟨ D.identityʳ ⟩
D [ F₁ f ∘ D.id ]
∎
where
open D.HomReasoning
infixr 9 _∘₁_ _∘₀_
-- "Vertical composition"
_∘₁_ : ∀ {o₀ ℓ₀ e₀ o₁ ℓ₁ e₁}
{C : Category o₀ ℓ₀ e₀} {D : Category o₁ ℓ₁ e₁}
{F G H : Functor C D}
→ NaturalTransformation G H → NaturalTransformation F G → NaturalTransformation F H
_∘₁_ {C = C} {D} {F} {G} {H} X Y = record
{ η = λ q → D [ X.η q ∘ Y.η q ]
; commute = commute′
}
where
module C = Category C
module D = Category D
module F = Functor F
module G = Functor G
module H = Functor H
module X = NaturalTransformation X
module Y = NaturalTransformation Y
open F
open G renaming (F₀ to G₀; F₁ to G₁)
open H renaming (F₀ to H₀; F₁ to H₁)
.commute′ : ∀ {A B} (f : C [ A , B ]) → D [ D [ D [ X.η B ∘ Y.η B ] ∘ F₁ f ] ≡ D [ H₁ f ∘ D [ X.η A ∘ Y.η A ] ] ]
commute′ {A} {B} f =
begin
D [ D [ X.η B ∘ Y.η B ] ∘ F₁ f ]
↓⟨ D.assoc ⟩
D [ X.η B ∘ D [ Y.η B ∘ F₁ f ] ]
↓⟨ D.∘-resp-≡ʳ (Y.commute f) ⟩
D [ X.η B ∘ D [ G₁ f ∘ Y.η A ] ]
↑⟨ D.assoc ⟩
D [ D [ X.η B ∘ G₁ f ] ∘ Y.η A ]
↓⟨ D.∘-resp-≡ˡ (X.commute f) ⟩
D [ D [ H₁ f ∘ X.η A ] ∘ Y.η A ]
↓⟨ D.assoc ⟩
D [ H₁ f ∘ D [ X.η A ∘ Y.η A ] ]
∎
where
open D.HomReasoning
-- "Horizontal composition"
_∘₀_ : ∀ {o₀ ℓ₀ e₀ o₁ ℓ₁ e₁ o₂ ℓ₂ e₂}
{C : Category o₀ ℓ₀ e₀} {D : Category o₁ ℓ₁ e₁} {E : Category o₂ ℓ₂ e₂}
{F G : Functor C D} {H I : Functor D E}
→ NaturalTransformation H I → NaturalTransformation F G → NaturalTransformation (H ∘F F) (I ∘F G)
_∘₀_ {C = C} {D} {E} {F} {G} {H} {I} Y X = record
{ η = λ q → E [ I₁ (X.η q) ∘ Y.η (F₀ q) ]
; commute = commute′
}
where
module C = Category C
module D = Category D
module E = Category E
module F = Functor F
module G = Functor G
module H = Functor H
module I = Functor I
module X = NaturalTransformation X
module Y = NaturalTransformation Y
open F
open G renaming (F₀ to G₀; F₁ to G₁; F-resp-≡ to G-resp-≡)
open H renaming (F₀ to H₀; F₁ to H₁; F-resp-≡ to H-resp-≡)
open I renaming (F₀ to I₀; F₁ to I₁; F-resp-≡ to I-resp-≡)
.commute′ : ∀ {A B} (f : C [ A , B ]) → E [ E [ E [ I₁ (X.η B) ∘ Y.η (F₀ B) ] ∘ H₁ (F₁ f) ] ≡ E [ I₁ (G₁ f) ∘ E [ I₁ (X.η A) ∘ Y.η (F₀ A) ] ] ]
commute′ {A} {B} f =
begin
E [ E [ I₁ (X.η B) ∘ Y.η (F₀ B) ] ∘ H₁ (F₁ f) ]
↓⟨ E.assoc ⟩
E [ I₁ (X.η B) ∘ E [ Y.η (F₀ B) ∘ H₁ (F₁ f) ] ]
↓⟨ E.∘-resp-≡ʳ (Y.commute (F₁ f)) ⟩
E [ I₁ (X.η B) ∘ E [ I₁ (F₁ f) ∘ Y.η (F₀ A) ] ]
↑⟨ E.assoc ⟩
E [ E [ I₁ (X.η B) ∘ I₁ (F₁ f) ] ∘ Y.η (F₀ A) ]
↑⟨ E.∘-resp-≡ˡ I.homomorphism ⟩
E [ I₁ (D [ X.η B ∘ F₁ f ]) ∘ Y.η (F₀ A) ]
↓⟨ E.∘-resp-≡ˡ (I-resp-≡ (X.commute f)) ⟩
E [ I₁ (D [ G₁ f ∘ X.η A ]) ∘ Y.η (F₀ A) ]
↓⟨ E.∘-resp-≡ˡ I.homomorphism ⟩
E [ E [ I₁ (G₁ f) ∘ I₁ (X.η A) ] ∘ Y.η (F₀ A) ]
↓⟨ E.assoc ⟩
E [ I₁ (G₁ f) ∘ E [ I₁ (X.η A) ∘ Y.η (F₀ A) ] ]
∎
where
open E.HomReasoning
infix 4 _≡_
_≡_ : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {F G : Functor C D} → Rel (NaturalTransformation F G) (o ⊔ e′)
_≡_ {D = D} X Y = ∀ {x} → D [ NaturalTransformation.η X x ≡ NaturalTransformation.η Y x ]
.equiv : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {F G : Functor C D} → IsEquivalence (_≡_ {F = F} {G})
equiv {C = C} {D} {F} {G} = record
{ refl = refl
; sym = λ f → sym f
; trans = λ f g → trans f g
}
where
open Category.Equiv D
setoid : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {F G : Functor C D} → Setoid _ _
setoid {F = F} {G} = record
{ Carrier = NaturalTransformation F G
; _≈_ = _≡_
; isEquivalence = equiv {F = F}
}
| 33.325153
| 145
| 0.486561
|
34ad8d8792d936a15386732c37502f9d635be633
| 94
|
agda
|
Agda
|
test/Fail/Issue309b.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue309b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue309b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue309b where
data D : Set where
d : D → D
syntax d x = f
g : D → D
g (d x) = f
| 9.4
| 22
| 0.553191
|
038f7ece6286d4ccd4c5cfc0520c49c174ca684f
| 13,523
|
agda
|
Agda
|
Cubical/Homotopy/Connected.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Connected.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Homotopy/Connected.agda
|
jorge-jbs/cubical
|
ebbe824fda41ab6524b62a42959665be4e67b847
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Homotopy.Connected where
open import Cubical.Core.Everything
open import Cubical.Foundations.Everything
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Path
open import Cubical.Foundations.Univalence
open import Cubical.Functions.Fibration
open import Cubical.Data.Nat
open import Cubical.Data.Prod hiding (map)
open import Cubical.Data.Sigma hiding (_×_)
open import Cubical.HITs.Nullification
open import Cubical.HITs.Susp
open import Cubical.HITs.SmashProduct
open import Cubical.HITs.Truncation as Trunc renaming (rec to trRec)
open import Cubical.Homotopy.Loopspace
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn
open import Cubical.HITs.S1
open import Cubical.Data.Bool
open import Cubical.Data.Unit
-- Note that relative to most sources, this notation is off by +2
isConnected : ∀ {ℓ} (n : HLevel) (A : Type ℓ) → Type ℓ
isConnected n A = isContr (hLevelTrunc n A)
isConnectedFun : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ')
isConnectedFun n f = ∀ b → isConnected n (fiber f b)
isTruncatedFun : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ')
isTruncatedFun n f = ∀ b → isOfHLevel n (fiber f b)
isConnectedSubtr : ∀ {ℓ} {A : Type ℓ} (n m : HLevel)
→ isConnected (m + n) A
→ isConnected n A
isConnectedSubtr {A = A} n m iscon =
isOfHLevelRetractFromIso 0 (truncOfTruncIso n m) (helper n iscon)
where
helper : (n : ℕ) → isConnected (m + n) A → isContr (hLevelTrunc n (hLevelTrunc (m + n) A))
helper zero iscon = isContrUnit*
helper (suc n) iscon = ∣ iscon .fst ∣ , (Trunc.elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ a → cong ∣_∣ (iscon .snd a))
isConnectedFunSubtr : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (n m : HLevel) (f : A → B)
→ isConnectedFun (m + n) f
→ isConnectedFun n f
isConnectedFunSubtr n m f iscon b = isConnectedSubtr n m (iscon b)
private
typeToFiberIso : ∀ {ℓ} (A : Type ℓ) → Iso A (fiber (λ (x : A) → tt) tt)
Iso.fun (typeToFiberIso A) x = x , refl
Iso.inv (typeToFiberIso A) = fst
Iso.rightInv (typeToFiberIso A) b i = fst b , (isOfHLevelSuc 1 (isPropUnit) tt tt (snd b) refl) i
Iso.leftInv (typeToFiberIso A) a = refl
typeToFiber : ∀ {ℓ} (A : Type ℓ) → A ≡ fiber (λ (x : A) → tt) tt
typeToFiber A = isoToPath (typeToFiberIso A)
module elim {ℓ ℓ' : Level} {A : Type ℓ} {B : Type ℓ'} (f : A → B) where
private
inv : ∀ {ℓ'''} (n : HLevel) (P : B → TypeOfHLevel ℓ''' (suc n))
→ ((a : A) → P (f a) .fst)
→ (b : B)
→ hLevelTrunc (suc n) (fiber f b) → P b .fst
inv n P t b =
Trunc.rec
(P b .snd)
(λ {(a , p) → subst (fst ∘ P) p (t a)})
isIsoPrecompose : ∀ {ℓ'''} (n : ℕ) (P : B → TypeOfHLevel ℓ''' n)
→ isConnectedFun n f
→ Iso ((b : B) → P b .fst) ((a : A) → P (f a) .fst)
isIsoPrecompose zero P fConn = isContr→Iso (isOfHLevelΠ _ (λ b → P b .snd)) (isOfHLevelΠ _ λ a → P (f a) .snd)
Iso.fun (isIsoPrecompose (suc n) P fConn) = _∘ f
Iso.inv (isIsoPrecompose (suc n) P fConn) t b = inv n P t b (fConn b .fst)
Iso.rightInv (isIsoPrecompose (suc n) P fConn) t =
funExt λ a → cong (inv n P t (f a)) (fConn (f a) .snd ∣ a , refl ∣)
∙ substRefl {B = fst ∘ P} (t a)
Iso.leftInv (isIsoPrecompose (suc n) P fConn) s =
funExt λ b →
Trunc.elim
{B = λ d → inv n P (s ∘ f) b d ≡ s b}
(λ _ → isOfHLevelPath (suc n) (P b .snd) _ _)
(λ {(a , p) i → transp (λ j → P (p (j ∨ i)) .fst) i (s (p i))})
(fConn b .fst)
isEquivPrecompose : ∀ {ℓ'''} (n : ℕ) (P : B → TypeOfHLevel ℓ''' n)
→ isConnectedFun n f
→ isEquiv (λ(s : (b : B) → P b .fst) → s ∘ f)
isEquivPrecompose zero P fConn = isoToIsEquiv theIso
where
theIso : Iso ((b : B) → P b .fst) ((a : A) → P (f a) .fst)
Iso.fun theIso = λ(s : (b : B) → P b .fst) → s ∘ f
Iso.inv theIso = λ _ b → P b .snd .fst
Iso.rightInv theIso g = funExt λ x → P (f x) .snd .snd (g x)
Iso.leftInv theIso g = funExt λ x → P x .snd .snd (g x)
isEquivPrecompose (suc n) P fConn = isoToIsEquiv (isIsoPrecompose (suc n) P fConn)
isConnectedPrecompose : (n : ℕ) → ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') n)
→ hasSection (λ(s : (b : B) → P b .fst) → s ∘ f))
→ isConnectedFun n f
isConnectedPrecompose zero P→sect b = isContrUnit*
isConnectedPrecompose (suc n) P→sect b = c n P→sect b , λ y → sym (fun n P→sect b y)
where
P : (n : HLevel) → ((P : B → TypeOfHLevel ℓ (suc n))
→ hasSection (λ(s : (b : B) → P b .fst) → s ∘ f))
→ B → Type _
P n s b = hLevelTrunc (suc n) (fiber f b)
c : (n : HLevel) → ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') (suc n))
→ hasSection (λ(s : (b : B) → P b .fst) → s ∘ f)) → (b : B)
→ hLevelTrunc (suc n) (fiber f b)
c n s = (s λ b → (hLevelTrunc (suc n) (fiber f b) , isOfHLevelTrunc _)) .fst
λ a → ∣ a , refl ∣
fun : (n : HLevel) (P→sect : ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') (suc n))
→ hasSection λ(s : (b : B) → P b .fst) → s ∘ f))
→ (b : B) (w : (hLevelTrunc (suc n) (fiber f b)))
→ w ≡ c n P→sect b
fun n P→sect b = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _)
λ a → J (λ b p → ∣ (fst a) , p ∣ ≡ c n P→sect b)
(c* (fst a))
(snd a)
where
c* : ((a : A) → ∣ (a , refl {x = f a}) ∣ ≡ c n P→sect (f a))
c* a = sym (cong (λ x → x a) (P→sect (λ b → hLevelTrunc (suc n) (fiber f b) , isOfHLevelTrunc _) .snd λ a → ∣ a , refl ∣))
isOfHLevelPrecomposeConnected : ∀ {ℓ ℓ' ℓ''} (k : HLevel) (n : HLevel)
{A : Type ℓ} {B : Type ℓ'} (P : B → TypeOfHLevel ℓ'' (k + n)) (f : A → B)
→ isConnectedFun n f
→ isOfHLevelFun k (λ(s : (b : B) → P b .fst) → s ∘ f)
isOfHLevelPrecomposeConnected zero n P f fConn =
elim.isEquivPrecompose f n P fConn .equiv-proof
isOfHLevelPrecomposeConnected (suc k) n P f fConn t =
isOfHLevelPath'⁻ k
λ {(s₀ , p₀) (s₁ , p₁) →
isOfHLevelRetractFromIso k (invIso ΣPathIsoPathΣ)
(subst (isOfHLevel k)
(sym (fiberPath (s₀ , p₀) (s₁ , p₁)))
(isOfHLevelRetract k
(λ {(q , α) → (funExt⁻ q) , (cong funExt⁻ α)})
(λ {(h , β) → (funExt h) , (cong funExt β)})
(λ _ → refl)
(isOfHLevelPrecomposeConnected k n
(λ b → (s₀ b ≡ s₁ b) , isOfHLevelPath' (k + n) (P b .snd) _ _)
f fConn
(funExt⁻ (p₀ ∙∙ refl ∙∙ sym p₁)))))}
indMapEquiv→conType : ∀ {ℓ} {A : Type ℓ} (n : HLevel)
→ ((B : TypeOfHLevel ℓ n)
→ isEquiv (λ (b : (fst B)) → λ (a : A) → b))
→ isConnected n A
indMapEquiv→conType {A = A} zero BEq = isContrUnit*
indMapEquiv→conType {A = A} (suc n) BEq =
isOfHLevelRetractFromIso 0 (mapCompIso {n = (suc n)} (typeToFiberIso A))
(elim.isConnectedPrecompose (λ _ → tt) (suc n)
(λ P → ((λ a _ → a) ∘ invIsEq (BEq (P tt)))
, λ a → equiv-proof (BEq (P tt)) a .fst .snd)
tt)
isConnectedPath : ∀ {ℓ} (n : HLevel) {A : Type ℓ}
→ isConnected (suc n) A
→ (a₀ a₁ : A) → isConnected n (a₀ ≡ a₁)
isConnectedPath zero connA a₀ a₁ = isContrUnit*
isConnectedPath (suc n) connA a₀ a₁ =
isOfHLevelRetractFromIso 0
(invIso (PathIdTruncIso (suc n)))
(isContr→isContrPath connA _ _)
isConnectedRetract : ∀ {ℓ ℓ'} (n : HLevel)
{A : Type ℓ} {B : Type ℓ'}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isConnected n B → isConnected n A
isConnectedRetract zero _ _ _ _ = isContrUnit*
isConnectedRetract (suc n) f g h =
isContrRetract
(Trunc.map f)
(Trunc.map g)
(Trunc.elim
(λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(λ a → cong ∣_∣ (h a)))
isConnectedRetractFromIso : ∀ {ℓ ℓ'} (n : HLevel)
{A : Type ℓ} {B : Type ℓ'}
→ Iso A B
→ isConnected n B → isConnected n A
isConnectedRetractFromIso n e =
isConnectedRetract n
(Iso.fun e)
(Iso.inv e)
(Iso.leftInv e)
isConnectedPoint : ∀ {ℓ} (n : HLevel) {A : Type ℓ}
→ isConnected (suc n) A
→ (a : A) → isConnectedFun n (λ(_ : Unit) → a)
isConnectedPoint n connA a₀ a =
isConnectedRetract n
snd (_ ,_) (λ _ → refl)
(isConnectedPath n connA a₀ a)
isConnectedPoint2 : ∀ {ℓ} (n : HLevel) {A : Type ℓ} (a : A)
→ isConnectedFun n (λ(_ : Unit) → a)
→ isConnected (suc n) A
isConnectedPoint2 n {A = A} a connMap = indMapEquiv→conType _ λ B → isoToIsEquiv (theIso B)
where
module _ {ℓ' : Level} (B : TypeOfHLevel ℓ' (suc n))
where
helper : (f : A → fst B) → (a2 : A) → f a2 ≡ f a
helper f = equiv-proof (elim.isEquivPrecompose (λ _ → a) n (λ a2 → (f a2 ≡ f a) ,
isOfHLevelPath' n (snd B) (f a2) (f a)) connMap) (λ _ → refl) .fst .fst
theIso : Iso (fst B) (A → fst B)
Iso.fun theIso b a = b
Iso.inv theIso f = f a
Iso.rightInv theIso f = funExt λ y → sym (helper f y)
Iso.leftInv theIso _ = refl
connectedTruncIso : ∀ {ℓ} {A B : Type ℓ} (n : HLevel) (f : A → B)
→ isConnectedFun n f
→ Iso (hLevelTrunc n A) (hLevelTrunc n B)
connectedTruncIso {A = A} {B = B} zero f con = isContr→Iso isContrUnit* isContrUnit*
connectedTruncIso {A = A} {B = B} (suc n) f con = g
where
back : B → hLevelTrunc (suc n) A
back y = map fst ((con y) .fst)
backSection : (b : B) → Path (hLevelTrunc (suc n) B)
(Trunc.rec (isOfHLevelTrunc (suc n))
(λ a → ∣ f a ∣)
(Trunc.rec {n = n}
{B = hLevelTrunc (suc n) A} (isOfHLevelTrunc (suc n))
back ∣ b ∣))
∣ b ∣
backSection b = helper (λ p → map f p ≡ ∣ b ∣)
(λ x → (isOfHLevelSuc (suc n) (isOfHLevelTrunc (suc n)))
(map f (map fst x)) ∣ b ∣)
(λ a p → cong ∣_∣ p)
(fst (con b))
where
helper : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : A → Type ℓ'} (P : hLevelTrunc (suc n) A → Type ℓ'')
→ ((x : hLevelTrunc (suc n) (Σ A B)) → isOfHLevel (suc n) (P (map fst x)))
→ ((a : A) (b : B a) → P ∣ a ∣)
→ (p : hLevelTrunc (suc n) (Σ A B))
→ P (map fst p)
helper P hlev pf = Trunc.elim hlev λ pair → pf (fst pair) (snd pair)
g : Iso (hLevelTrunc (suc n) A) (hLevelTrunc (suc n) B)
Iso.fun g = map f
Iso.inv g = Trunc.rec (isOfHLevelTrunc _) back
Iso.leftInv g = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _)
λ a → cong (map fst) (con (f a) .snd ∣ a , refl ∣)
Iso.rightInv g = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _)
backSection
connectedTruncIso2 : ∀ {ℓ} {A B : Type ℓ} (n m : HLevel) (f : A → B)
→ Σ[ x ∈ ℕ ] x + n ≡ m
→ isConnectedFun m f
→ Iso (hLevelTrunc n A) (hLevelTrunc n B)
connectedTruncIso2 {A = A} {B = B} n m f (x , pf) con =
connectedTruncIso n f (isConnectedFunSubtr n x f (transport (λ i → isConnectedFun (pf (~ i)) f) con))
connectedTruncEquiv : ∀ {ℓ} {A B : Type ℓ} (n : HLevel) (f : A → B)
→ isConnectedFun n f
→ hLevelTrunc n A ≃ hLevelTrunc n B
connectedTruncEquiv {A = A} {B = B} n f con = isoToEquiv (connectedTruncIso n f con)
-- TODO : Reorganise the following proofs.
inrConnected : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} (n : HLevel)
→ (f : C → A) (g : C → B)
→ isConnectedFun n f
→ isConnectedFun n {A = B} {B = Pushout f g} inr
inrConnected {A = A} {B = B} {C = C} n f g iscon =
elim.isConnectedPrecompose inr n λ P → (k P) , λ b → refl
where
module _ {ℓ : Level} (P : (Pushout f g) → TypeOfHLevel ℓ n)
(h : (b : B) → typ (P (inr b)))
where
Q : A → TypeOfHLevel _ n
Q a = (P (inl a))
fun : (c : C) → typ (Q (f c))
fun c = transport (λ i → typ (P (push c (~ i)))) (h (g c))
k : (d : Pushout f g) → typ (P d)
k (inl x) = equiv-proof (elim.isEquivPrecompose f n Q iscon) fun .fst .fst x
k (inr x) = h x
k (push a i) =
hcomp (λ k → λ { (i = i0) → equiv-proof (elim.isEquivPrecompose f n Q iscon) fun .fst .snd i0 a
; (i = i1) → transportTransport⁻ (λ j → typ (P (push a j))) (h (g a)) k })
(transp (λ j → typ (P (push a (i ∧ j))))
(~ i)
(equiv-proof (elim.isEquivPrecompose f n Q iscon)
fun .fst .snd i a))
sphereConnected : (n : HLevel) → isConnected (suc n) (S₊ n)
sphereConnected n = ∣ ptSn n ∣ , (Trunc.elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(λ a → sym (spoke ∣_∣ (ptSn n)) ∙ spoke ∣_∣ a))
| 43.905844
| 145
| 0.527915
|
0d9bc13cb139754ba743eb6f29bf112982319402
| 207
|
agda
|
Agda
|
Cubical/HITs/Rationals/HITQ.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Rationals/HITQ.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/Rationals/HITQ.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Rationals.HITQ where
open import Cubical.HITs.Rationals.HITQ.Base public
-- open import Cubical.HITs.Rationals.HITQ.Properties public
| 29.571429
| 60
| 0.772947
|
211b68ce180683116c4e779d53f69678b1fb4452
| 2,744
|
agda
|
Agda
|
src/FOmegaInt/Undecidable.agda
|
sstucki/f-omega-int-agda
|
ae648c9520895a8428a7ad80f47bb55ecf4d50ea
|
[
"MIT"
] | 12
|
2017-06-13T16:05:35.000Z
|
2021-09-27T05:53:06.000Z
|
src/FOmegaInt/Undecidable.agda
|
sstucki/f-omega-int-agda
|
ae648c9520895a8428a7ad80f47bb55ecf4d50ea
|
[
"MIT"
] | 1
|
2021-05-14T08:09:40.000Z
|
2021-05-14T08:54:39.000Z
|
src/FOmegaInt/Undecidable.agda
|
sstucki/f-omega-int-agda
|
ae648c9520895a8428a7ad80f47bb55ecf4d50ea
|
[
"MIT"
] | 2
|
2021-05-13T22:29:48.000Z
|
2021-05-14T10:25:05.000Z
|
------------------------------------------------------------------------
-- Undecidability of subtyping in Fω with interval kinds
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module FOmegaInt.Undecidable where
open import Function.Equivalence using (_⇔_; equivalence)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import FOmegaInt.Syntax
open import FOmegaInt.Typing as Declarative
open import FOmegaInt.Kinding.Canonical as Canonical
open import FOmegaInt.Kinding.Canonical.Equivalence
open import FOmegaInt.Undecidable.SK
open import FOmegaInt.Undecidable.Encoding
open import FOmegaInt.Undecidable.Decoding
open Syntax
open ContextConversions using (⌞_⌟Ctx)
open Canonical.Kinding using (_⊢_<:_⇇_)
open Declarative.Typing using (_⊢_<:_∈_)
open Encoding
module T = TermCtx
module E = ElimCtx
------------------------------------------------------------------------
-- SK combinator term equality checking reduces to subtype checking in
-- Fω with interval kinds.
--
-- We do not proof undecidability of subtyping directly, but give a
-- reduction from undecidability of checking the equivalence of two SK
-- combinator terms, which is well-known to be undecidable. In other
-- words, if we could check subtyping, we could also check the
-- equality of two SK combinator terms, which we cannot.
--
-- The following types characterize the decision procedures involved.
SKEqualityCheck : Set
SKEqualityCheck = (s t : SKTerm) → Dec (s ≡SK t)
CanoncialSubtypeCheck : Set
CanoncialSubtypeCheck = ∀ {n} (Γ : E.Ctx n) a b k → Dec (Γ ⊢ a <: b ⇇ k)
DeclarativeSubtypeCheck : Set
DeclarativeSubtypeCheck = ∀ {n} (Γ : T.Ctx n) a b k → Dec (Γ ⊢ a <: b ∈ k)
-- The reduction from SK equality checking to canonical subtype checking.
canonicalEquivalence : ∀ s t → Γ-SK? ⊢ encode s <: encode t ⇇ ⌜*⌝ ⇔ s ≡SK t
canonicalEquivalence s t = equivalence decode-<:⇇-encode <:⇇-encode
canonicalReduction : CanoncialSubtypeCheck → SKEqualityCheck
canonicalReduction check-<:⇇ s t =
map (canonicalEquivalence s t) (check-<:⇇ Γ-SK? (encode s) (encode t) ⌜*⌝)
-- The reduction from SK equality checking to declarative subtype checking.
declarativeEquivalence :
∀ s t → ⌞Γ-SK?⌟ ⊢ ⌞ encode s ⌟ <: ⌞ encode t ⌟ ∈ * ⇔ s ≡SK t
declarativeEquivalence s t = equivalence
(λ es<:et∈* → decode-<:⇇-encode
(subst₂ (_ ⊢_<:_⇇ _) (nf-encode s) (nf-encode t) (complete-<: es<:et∈*)))
(λ s≡t → sound-<:⇇ (<:⇇-encode s≡t))
declarativeReduction : DeclarativeSubtypeCheck → SKEqualityCheck
declarativeReduction check-<:∈ s t =
map (declarativeEquivalence s t)
(check-<:∈ ⌞Γ-SK?⌟ ⌞ encode s ⌟ ⌞ encode t ⌟ *)
| 37.081081
| 79
| 0.672012
|
3640040682ba360de18c265bf3c8befd7fbc98f1
| 12,700
|
agda
|
Agda
|
Cubical/Homotopy/HopfInvariant/Base.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Homotopy/HopfInvariant/Base.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/HopfInvariant/Base.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.HopfInvariant.Base where
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.Group.Base
open import Cubical.Homotopy.Group.SuspensionMap
open import Cubical.Relation.Nullary
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.MayerVietorisUnreduced
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.Groups.Wedge
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.ZCohomology.RingStructure.CupProduct
open import Cubical.ZCohomology.RingStructure.GradedCommutativity
open import Cubical.ZCohomology.Gysin
open import Cubical.Foundations.Path
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Function
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
open import Cubical.Data.Int hiding (_+'_)
open import Cubical.Data.Nat renaming (_+_ to _+ℕ_ ; _·_ to _·ℕ_)
open import Cubical.Data.Unit
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.ZAction
open import Cubical.Algebra.Group.Exact
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Instances.Int
open import Cubical.Algebra.Group.Instances.Unit
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.HITs.Wedge
open import Cubical.HITs.Truncation
renaming (rec to trRec)
open import Cubical.HITs.SetTruncation
renaming (rec to sRec ; elim to sElim ; elim2 to sElim2 ; map to sMap)
open import Cubical.HITs.PropositionalTruncation
renaming (rec to pRec)
-- The pushout of the hopf invariant
HopfInvariantPush : (n : ℕ)
→ (f : S₊ (3 +ℕ n +ℕ n) → S₊ (2 +ℕ n))
→ Type _
HopfInvariantPush n f = Pushout (λ _ → tt) f
Hopfα : (n : ℕ)
→ (f : S₊∙ (3 +ℕ n +ℕ n) →∙ S₊∙ (2 +ℕ n))
→ coHom (2 +ℕ n) (HopfInvariantPush n (fst f))
Hopfα n f = ∣ (λ { (inl x) → 0ₖ _
; (inr x) → ∣ x ∣
; (push a i) → help a (~ i)}) ∣₂
where
help : (a : S₊ (3 +ℕ n +ℕ n)) → ∣ fst f a ∣ ≡ 0ₖ (2 +ℕ n)
help = sphereElim _ (λ _ → isOfHLevelPlus' {n = n} (3 +ℕ n)
(isOfHLevelPath' (3 +ℕ n) (isOfHLevelTrunc (4 +ℕ n)) _ _))
(cong ∣_∣ₕ (snd f))
Hopfβ : (n : ℕ)
→ (f : S₊∙ (3 +ℕ n +ℕ n) →∙ S₊∙ (2 +ℕ n))
→ coHom (4 +ℕ (n +ℕ n)) (HopfInvariantPush n (fst f))
Hopfβ n f = fst (MV.d _ _ _ (λ _ → tt) (fst f) (3 +ℕ n +ℕ n)) ∣ ∣_∣ ∣₂
-- To define the Hopf invariant, we need to establish the
-- non-trivial isos of Hⁿ(HopfInvariant).
module _ (n : ℕ) (f : S₊∙ (3 +ℕ n +ℕ n) →∙ S₊∙ (2 +ℕ n)) where
module M = MV _ _ _ (λ _ → tt) (fst f)
¬lemHopf : (n m : ℕ) → ¬ suc (suc (m +ℕ n)) ≡ suc n
¬lemHopf zero zero p = snotz (cong predℕ p)
¬lemHopf (suc n) zero p = ¬lemHopf n zero (cong predℕ p)
¬lemHopf zero (suc m) p = snotz (cong predℕ p)
¬lemHopf (suc n) (suc m) p =
¬lemHopf n (suc m) (cong (suc ∘ suc )
(sym (+-suc m n)) ∙ (cong predℕ p))
SphereHopfCohomIso :
GroupEquiv
(coHomGr (3 +ℕ n +ℕ n) (S₊ (3 +ℕ n +ℕ n)))
((coHomGr (suc (3 +ℕ n +ℕ n)) (HopfInvariantPush _ (fst f))))
fst (fst SphereHopfCohomIso) =
fst (MV.d _ _ _ (λ _ → tt) (fst f) (3 +ℕ n +ℕ n))
snd (fst SphereHopfCohomIso) = help
where
abstract
help : isEquiv (fst (MV.d _ _ _ (λ _ → tt) (fst f)
(3 +ℕ n +ℕ n)))
help =
SES→isEquiv
(isContr→≡UnitGroup
(isContrΣ (GroupIsoUnitGroup→isContr (invGroupIso (Hⁿ-Unit≅0 _)))
λ _ → GroupIsoUnitGroup→isContr
(invGroupIso (Hⁿ-Sᵐ≅0 _ _ (¬lemHopf n n)))))
(isContr→≡UnitGroup
(isContrΣ (GroupIsoUnitGroup→isContr
(invGroupIso (Hⁿ-Unit≅0 _)))
λ _ → GroupIsoUnitGroup→isContr
(invGroupIso (Hⁿ-Sᵐ≅0 _ _ (¬lemHopf n (suc n))))))
(M.Δ (3 +ℕ n +ℕ n))
(M.d (3 +ℕ n +ℕ n))
(M.i (4 +ℕ n +ℕ n))
(M.Ker-d⊂Im-Δ _)
(M.Ker-i⊂Im-d _)
snd SphereHopfCohomIso = d-inv
where
-- Currently, type checking is very slow without the abstract flag.
-- TODO : Remove abstract
abstract
d-inv : IsGroupHom (snd (coHomGr (3 +ℕ n +ℕ n) (S₊ (3 +ℕ n +ℕ n))))
(fst (MV.d _ _ _ (λ _ → tt) (fst f) (3 +ℕ n +ℕ n)))
(snd (coHomGr (suc (3 +ℕ n +ℕ n))
(Pushout (λ _ → tt) (fst f))))
d-inv = snd (MV.d _ _ _ (λ _ → tt) (fst f) (3 +ℕ n +ℕ n))
Hopfβ-Iso : GroupIso (coHomGr (suc (3 +ℕ n +ℕ n))
(HopfInvariantPush _ (fst f)))
ℤGroup
fst Hopfβ-Iso = compIso (invIso (equivToIso (fst SphereHopfCohomIso)))
(fst (Hⁿ-Sⁿ≅ℤ (suc (suc (n +ℕ n)))))
snd Hopfβ-Iso = grHom
where
abstract
grHom :
IsGroupHom (coHomGr (suc (3 +ℕ n +ℕ n))
(Pushout (λ _ → tt) (fst f)) .snd)
(λ x → Iso.fun (fst ((Hⁿ-Sⁿ≅ℤ (suc (suc (n +ℕ n))))))
(invEq (fst SphereHopfCohomIso) x))
(ℤGroup .snd)
grHom = snd (compGroupIso
(GroupEquiv→GroupIso (invGroupEquiv (SphereHopfCohomIso)))
(Hⁿ-Sⁿ≅ℤ (suc (suc (n +ℕ n)))))
Hⁿ-Sⁿ≅ℤ-nice-generator : (n : ℕ) → Iso.inv (fst (Hⁿ-Sⁿ≅ℤ (suc n))) 1 ≡ ∣ ∣_∣ ∣₂
Hⁿ-Sⁿ≅ℤ-nice-generator zero = Iso.leftInv (fst (Hⁿ-Sⁿ≅ℤ (suc zero))) _
Hⁿ-Sⁿ≅ℤ-nice-generator (suc n) =
(λ i → Iso.inv (fst (suspensionAx-Sn (suc n) (suc n)))
(Hⁿ-Sⁿ≅ℤ-nice-generator n i))
∙ cong ∣_∣₂
(funExt λ { north → refl
; south → cong ∣_∣ₕ (merid north)
; (merid a i) j → ∣ compPath-filler (merid a)
(sym (merid north)) (~ j) i ∣ₕ})
Hopfβ↦1 : (n : ℕ) (f : S₊∙ (3 +ℕ n +ℕ n) →∙ S₊∙ (2 +ℕ n))
→ Iso.fun (fst (Hopfβ-Iso n f)) (Hopfβ n f) ≡ 1
Hopfβ↦1 n f =
sym (cong (Iso.fun (fst (Hopfβ-Iso n f))) lem)
∙ Iso.rightInv (fst (Hopfβ-Iso n f)) (pos 1)
where
lem : Iso.inv (fst (Hopfβ-Iso n f)) (pos 1) ≡ Hopfβ n f
lem = (λ i → fst (MV.d _ _ _ (λ _ → tt) (fst f) (3 +ℕ n +ℕ n))
(Hⁿ-Sⁿ≅ℤ-nice-generator _ i))
∙ cong ∣_∣₂ (funExt (λ { (inl x) → refl
; (inr x) → refl
; (push a i) → refl}))
module _ (n : ℕ) (f : S₊∙ (3 +ℕ n +ℕ n) →∙ S₊∙ (2 +ℕ n)) where
private
2+n = 2 +ℕ n
H = HopfInvariantPush n (fst f)
H→Sphere : coHom 2+n H → coHom 2+n (S₊ (suc (suc n)))
H→Sphere = sMap (_∘ inr)
grHom : IsGroupHom (snd (coHomGr 2+n H))
H→Sphere (snd (coHomGr 2+n (S₊ (suc (suc n)))))
grHom =
makeIsGroupHom
(sElim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f g → refl)
preSphere→H : (g : (S₊ (suc (suc n)) → coHomK 2+n))
→ H → coHomK (2 +ℕ n)
preSphere→H g (inl x) = 0ₖ _
preSphere→H g (inr x) = g x -ₖ g north
preSphere→H g (push a i) = lem a i
where
lem : (a : S₊ (suc (suc (suc (n +ℕ n)))))
→ 0ₖ (suc (suc n)) ≡ g (fst f a) -ₖ g north
lem =
sphereElim _
(λ x → isOfHLevelPlus' {n = n} (3 +ℕ n)
(isOfHLevelTrunc (4 +ℕ n) _ _))
(sym (rCancelₖ _ (g north))
∙ cong (λ x → g x -ₖ g north) (sym (snd f)))
Sphere→H : coHom 2+n (S₊ (suc (suc n))) → coHom 2+n H
Sphere→H = sMap preSphere→H
conCohom2+n : (x : _) → ∥ x ≡ 0ₖ (suc (suc n)) ∥₁
conCohom2+n =
coHomK-elim _ (λ _ → isProp→isOfHLevelSuc (suc n) squash₁) ∣ refl ∣₁
HIPSphereCohomIso :
Iso (coHom (2 +ℕ n) (HopfInvariantPush n (fst f)))
(coHom (2 +ℕ n) (S₊ (2 +ℕ n)))
Iso.fun HIPSphereCohomIso = H→Sphere
Iso.inv HIPSphereCohomIso = Sphere→H
Iso.rightInv HIPSphereCohomIso =
sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ g → pRec (squash₂ _ _)
(λ p → cong ∣_∣₂ (funExt λ x → cong (g x +ₖ_) (cong (-ₖ_) p)
∙ rUnitₖ _ (g x)))
(conCohom2+n (g north))
Iso.leftInv HIPSphereCohomIso =
sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ g →
pRec (squash₂ _ _)
(pRec (isPropΠ (λ _ → squash₂ _ _))
(λ gn gtt →
trRec (isProp→isOfHLevelSuc n (squash₂ _ _))
(λ r → cong ∣_∣₂ (funExt λ {
(inl x) → sym gtt
; (inr x) → (λ i → g (inr x) -ₖ gn i)
∙ rUnitₖ _ (g (inr x))
; (push a i)
→ sphereElim _
{A = λ a →
PathP (λ i → preSphere→H (λ x → g (inr x))
(push a i)
≡ g (push a i))
(sym gtt)
((λ i → g (inr (fst f a)) -ₖ gn i)
∙ rUnitₖ _ (g (inr (fst f a))))}
(λ _ → isOfHLevelPathP' (suc (suc (suc (n +ℕ n))))
(isOfHLevelPath (suc (suc (suc (suc (n +ℕ n)))))
(isOfHLevelPlus' {n = n} (suc (suc (suc (suc n))))
(isOfHLevelTrunc (suc (suc (suc (suc n)))))) _ _) _ _)
r a i}))
(push-helper g gtt gn))
(conCohom2+n (g (inr north))))
(conCohom2+n (g (inl tt)))
where
push-helper : (g : HopfInvariantPush n (fst f) → coHomK (suc (suc n)))
→ (gtt : g (inl tt) ≡ 0ₖ (suc (suc n)))
→ (gn : g (inr north) ≡ 0ₖ (suc (suc n)))
→ hLevelTrunc (suc n)
(PathP (λ i → preSphere→H (λ x → g (inr x)) (push north i)
≡ g (push north i))
(sym gtt)
((λ i → g (inr (fst f north)) -ₖ gn i)
∙ rUnitₖ _ (g (inr (fst f north)))))
push-helper g gtt gn =
isConnectedPathP _ (isConnectedPath _ (isConnectedKn _) _ _) _ _ .fst
Hopfα-Iso : GroupIso (coHomGr (2 +ℕ n) (HopfInvariantPush n (fst f))) ℤGroup
Hopfα-Iso =
compGroupIso
(HIPSphereCohomIso , grHom)
(Hⁿ-Sⁿ≅ℤ (suc n))
Hopfα-Iso-α : (n : ℕ) (f : _)
→ Iso.fun (fst (Hopfα-Iso n f)) (Hopfα n f)
≡ 1
Hopfα-Iso-α n f =
sym (cong (Iso.fun (fst (Hⁿ-Sⁿ≅ℤ (suc n)))) (Hⁿ-Sⁿ≅ℤ-nice-generator n))
∙ Iso.rightInv (fst (Hⁿ-Sⁿ≅ℤ (suc n))) (pos 1)
where
hz : Iso.fun (HIPSphereCohomIso n f) (Hopfα n f) ≡ ∣ ∣_∣ ∣₂
hz = refl
⌣-α : (n : ℕ) → (f : S₊∙ (3 +ℕ (n +ℕ n)) →∙ S₊∙ (2 +ℕ n)) → _
⌣-α n f = Hopfα n f ⌣ Hopfα n f
HopfInvariant : (n : ℕ)
→ (f : S₊∙ (3 +ℕ (n +ℕ n)) →∙ S₊∙ (2 +ℕ n))
→ ℤ
HopfInvariant n f = Iso.fun (fst (Hopfβ-Iso n f))
(subst (λ x → coHom x (HopfInvariantPush n (fst f)))
(λ i → suc (suc (suc (+-suc n n i))))
(⌣-α n f))
HopfInvariant-π' : (n : ℕ) → π' (3 +ℕ (n +ℕ n)) (S₊∙ (2 +ℕ n)) → ℤ
HopfInvariant-π' n = sRec isSetℤ (HopfInvariant n)
HopfInvariant-π : (n : ℕ) → π (3 +ℕ (n +ℕ n)) (S₊∙ (2 +ℕ n)) → ℤ
HopfInvariant-π n = sRec isSetℤ λ x → HopfInvariant-π' n ∣ Ω→SphereMap _ x ∣₂
-- Elimination principle for the pushout defining the Hopf Invariant
HopfInvariantPushElim :
∀ {ℓ} n → (f : _)
→ {P : HopfInvariantPush n f → Type ℓ}
→ (isOfHLevel (suc (suc (suc (suc (n +ℕ n))))) (P (inl tt)))
→ (e : P (inl tt))
(g : (x : _) → P (inr x))
(r : PathP (λ i → P (push north i)) e (g (f north)))
→ (x : _) → P x
HopfInvariantPushElim n f {P = P} hlev e g r (inl x) = e
HopfInvariantPushElim n f {P = P} hlev e g r (inr x) = g x
HopfInvariantPushElim n f {P = P} hlev e g r (push a i₁) = help a i₁
where
help : (a : Susp (Susp (S₊ (suc (n +ℕ n)))))
→ PathP (λ i → P (push a i)) e (g (f a))
help =
sphereElim _
(sphereElim _
(λ _ → isProp→isOfHLevelSuc (suc (suc (n +ℕ n)))
(isPropIsOfHLevel _))
(isOfHLevelPathP' (suc (suc (suc (n +ℕ n))))
(subst (isOfHLevel (suc (suc (suc (suc (n +ℕ n))))))
(cong P (push north))
hlev) _ _)) r
| 40.063091
| 80
| 0.512913
|
368ad3e944d0dc42486f6757ac6dbfdfefc10190
| 8,591
|
agda
|
Agda
|
Cubical/Foundations/Equiv/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Equiv/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/Equiv/Properties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-
A couple of general facts about equivalences:
- if f is an equivalence then (cong f) is an equivalence ([equivCong])
- if f is an equivalence then pre- and postcomposition with f are equivalences ([preCompEquiv], [postCompEquiv])
- if f is an equivalence then (Σ[ g ] section f g) and (Σ[ g ] retract f g) are contractible ([isContr-section], [isContr-retract])
- isHAEquiv is a proposition [isPropIsHAEquiv]
(these are not in 'Equiv.agda' because they need Univalence.agda (which imports Equiv.agda))
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Equiv.Properties where
open import Cubical.Core.Everything
open import Cubical.Data.Sigma
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.HLevels
open import Cubical.Functions.FunExtEquiv
open import Cubical.Relation.Binary.Reasoning.Equality
private
variable
ℓ ℓ′ : Level
A B C : Type ℓ
isEquivCong : {x y : A} (e : A ≃ B) → isEquiv (λ (p : x ≡ y) → cong (e .fst) p)
isEquivCong e = isoToIsEquiv (congIso (equivToIso e))
congEquiv : {x y : A} (e : A ≃ B) → (x ≡ y) ≃ (e .fst x ≡ e .fst y)
congEquiv e = isoToEquiv (congIso (equivToIso e))
equivAdjointEquiv : (e : A ≃ B) → ∀ {a b} → (a ≡ invEq e b) ≃ (equivFun e a ≡ b)
equivAdjointEquiv e = compEquiv (congEquiv e) (compPathrEquiv (retEq e _))
invEq≡→equivFun≡ : (e : A ≃ B) → ∀ {a b} → invEq e b ≡ a → equivFun e a ≡ b
invEq≡→equivFun≡ e = equivAdjointEquiv e .fst ∘ sym
isEquivPreComp : {A B : Type ℓ} {C : Type ℓ′} (e : A ≃ B)
→ isEquiv (λ (φ : B → C) → φ ∘ e .fst)
isEquivPreComp {A = A} {B} {C} e = EquivJ
(λ (A : Type _) (e' : A ≃ B) → isEquiv (λ (φ : B → C) → φ ∘ e' .fst))
(idIsEquiv (B → C)) e
preCompEquiv : {A B : Type ℓ} {C : Type ℓ′} (e : A ≃ B)
→ (B → C) ≃ (A → C)
preCompEquiv e = (λ φ → φ ∘ fst e) , isEquivPreComp e
depPostCompEquiv : {A : C → Type ℓ} {B : C → Type ℓ′} (e : ∀ c → A c ≃ B c)
→ (∀ c → A c) ≃ (∀ c → B c)
depPostCompEquiv {A = A} {B} e = isoToEquiv pcIso where
eIso : ∀ c → Iso (A c) (B c)
eIso c = equivToIso (e c)
pcIso : Iso (∀ c → A c) (∀ c → B c)
Iso.fun pcIso f c = Iso.fun (eIso c) (f c)
Iso.inv pcIso g c = Iso.inv (eIso c) (g c)
Iso.rightInv pcIso f i c = Iso.rightInv (eIso c) (f c) i
Iso.leftInv pcIso g i c = Iso.leftInv (eIso c) (g c) i
isEquivPostComp :(e : A ≃ B) → isEquiv (λ (φ : C → A) → e .fst ∘ φ)
isEquivPostComp {A = A} {B} {C} e = snd (depPostCompEquiv (λ _ → e))
postCompEquiv : (e : A ≃ B) → (C → A) ≃ (C → B)
postCompEquiv e = _ , isEquivPostComp e
hasSection : (A → B) → Type _
hasSection {A = A} {B = B} f = Σ[ g ∈ (B → A) ] section f g
hasRetract : (A → B) → Type _
hasRetract {A = A} {B = B} f = Σ[ g ∈ (B → A) ] retract f g
isEquiv→isContrHasSection : {f : A → B} → isEquiv f → isContr (hasSection f)
fst (isEquiv→isContrHasSection isEq) = invIsEq isEq , secIsEq isEq
snd (isEquiv→isContrHasSection isEq) (f , ε) i = (λ b → fst (p b i)) , (λ b → snd (p b i))
where p : ∀ b → (invIsEq isEq b , secIsEq isEq b) ≡ (f b , ε b)
p b = isEq .equiv-proof b .snd (f b , ε b)
isEquiv→hasSection : {f : A → B} → isEquiv f → hasSection f
isEquiv→hasSection = fst ∘ isEquiv→isContrHasSection
isContr-hasSection : (e : A ≃ B) → isContr (hasSection (fst e))
isContr-hasSection e = isEquiv→isContrHasSection (snd e)
isEquiv→isContrHasRetract : {f : A → B} → isEquiv f → isContr (hasRetract f)
fst (isEquiv→isContrHasRetract isEq) = invIsEq isEq , retIsEq isEq
snd (isEquiv→isContrHasRetract {f = f} isEq) (g , η) =
λ i → (λ b → p b i) , (λ a → q a i)
where p : ∀ b → invIsEq isEq b ≡ g b
p b = sym (η (invIsEq isEq b)) ∙' cong g (secIsEq isEq b)
-- one square from the definition of invIsEq
ieSq : ∀ a → Square (cong g (secIsEq isEq (f a)))
refl
(cong (g ∘ f) (retIsEq isEq a))
refl
ieSq a k j = g (commSqIsEq isEq a k j)
-- one square from η
ηSq : ∀ a → Square (η (invIsEq isEq (f a)))
(η a)
(cong (g ∘ f) (retIsEq isEq a))
(retIsEq isEq a)
ηSq a i j = η (retIsEq isEq a i) j
-- and one last square from the definition of p
pSq : ∀ b → Square (η (invIsEq isEq b))
refl
(cong g (secIsEq isEq b))
(p b)
pSq b i j = compPath'-filler (sym (η (invIsEq isEq b))) (cong g (secIsEq isEq b)) j i
q : ∀ a → Square (retIsEq isEq a) (η a) (p (f a)) refl
q a i j = hcomp (λ k → λ { (i = i0) → ηSq a j k
; (i = i1) → η a (j ∧ k)
; (j = i0) → pSq (f a) i k
; (j = i1) → η a k
})
(ieSq a j i)
isEquiv→hasRetract : {f : A → B} → isEquiv f → hasRetract f
isEquiv→hasRetract = fst ∘ isEquiv→isContrHasRetract
isContr-hasRetract : (e : A ≃ B) → isContr (hasRetract (fst e))
isContr-hasRetract e = isEquiv→isContrHasRetract (snd e)
-- there is a (much slower) alternate proof that also works for retract
isContr-hasSection' : {A B : Type ℓ} (e : A ≃ B) → isContr (hasSection (fst e))
isContr-hasSection' {_} {A} {B} e = transport (λ i → ∃![ g ∈ (B → A) ] eq g i)
(equiv-proof (isEquivPostComp e) (idfun _))
where eq : ∀ (g : B → A) → ((fst e) ∘ g ≡ idfun _) ≡ (section (fst e) g)
eq g = sym (funExtPath {f = (fst e) ∘ g} {g = idfun _})
isContr-hasRetract' : {A B : Type ℓ} (e : A ≃ B) → isContr (hasRetract (fst e))
isContr-hasRetract' {_} {A} {B} e = transport (λ i → ∃![ g ∈ (B → A) ] eq g i)
(equiv-proof (isEquivPreComp e) (idfun _))
where eq : ∀ (g : B → A) → (g ∘ (fst e) ≡ idfun _) ≡ (retract (fst e) g)
eq g = sym (funExtPath {f = g ∘ (fst e)} {g = idfun _})
cong≃ : (F : Type ℓ → Type ℓ′) → (A ≃ B) → F A ≃ F B
cong≃ F e = pathToEquiv (cong F (ua e))
cong≃-char : (F : Type ℓ → Type ℓ′) {A B : Type ℓ} (e : A ≃ B) → ua (cong≃ F e) ≡ cong F (ua e)
cong≃-char F e = ua-pathToEquiv (cong F (ua e))
cong≃-idEquiv : (F : Type ℓ → Type ℓ′) (A : Type ℓ) → cong≃ F (idEquiv A) ≡ idEquiv (F A)
cong≃-idEquiv F A = cong≃ F (idEquiv A) ≡⟨ cong (λ p → pathToEquiv (cong F p)) uaIdEquiv ⟩
pathToEquiv refl ≡⟨ pathToEquivRefl ⟩
idEquiv (F A) ∎
isPropIsHAEquiv : {f : A → B} → isProp (isHAEquiv f)
isPropIsHAEquiv {f = f} ishaef = goal ishaef where
equivF : isEquiv f
equivF = isHAEquiv→isEquiv ishaef
rCoh1 : (sec : hasSection f) → Type _
rCoh1 (g , ε) = Σ[ η ∈ retract f g ] ∀ x → cong f (η x) ≡ ε (f x)
rCoh2 : (sec : hasSection f) → Type _
rCoh2 (g , ε) = Σ[ η ∈ retract f g ] ∀ x → Square (ε (f x)) refl (cong f (η x)) refl
rCoh3 : (sec : hasSection f) → Type _
rCoh3 (g , ε) = ∀ x → Σ[ ηx ∈ g (f x) ≡ x ] Square (ε (f x)) refl (cong f ηx) refl
rCoh4 : (sec : hasSection f) → Type _
rCoh4 (g , ε) = ∀ x → Path (fiber f (f x)) (g (f x) , ε (f x)) (x , refl)
characterization : isHAEquiv f ≃ Σ _ rCoh4
characterization =
isHAEquiv f
-- first convert between Σ and record
≃⟨ isoToEquiv (iso (λ e → (e .g , e .ret) , (e .sec , e .com))
(λ e → record { g = e .fst .fst ; ret = e .fst .snd
; sec = e .snd .fst ; com = e .snd .snd })
(λ _ → refl) (λ _ → refl)) ⟩
Σ _ rCoh1
-- secondly, convert the path into a dependent path for later convenience
≃⟨ Σ-cong-equiv-snd (λ s → Σ-cong-equiv-snd
λ η → depPostCompEquiv
λ x → compEquiv (flipSquareEquiv {a₀₀ = f x}) (invEquiv slideSquareEquiv)) ⟩
Σ _ rCoh2
≃⟨ Σ-cong-equiv-snd (λ s → invEquiv Σ-Π-≃) ⟩
Σ _ rCoh3
≃⟨ Σ-cong-equiv-snd (λ s → depPostCompEquiv λ x → ΣPath≃PathΣ) ⟩
Σ _ rCoh4
■
where open isHAEquiv
goal : isProp (isHAEquiv f)
goal = subst isProp (sym (ua characterization))
(isPropΣ (isContr→isProp (isEquiv→isContrHasSection equivF))
λ s → isPropΠ λ x → isProp→isSet (isContr→isProp (equivF .equiv-proof (f x))) _ _)
| 42.955
| 131
| 0.548481
|
1bb0c5782ae14689e56d95066bc438e717bdee4d
| 3,908
|
agda
|
Agda
|
Formalization/PredicateLogic/Syntax/Tree.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Formalization/PredicateLogic/Syntax/Tree.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Formalization/PredicateLogic/Syntax/Tree.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
open import Formalization.PredicateLogic.Signature
module Formalization.PredicateLogic.Syntax.Tree (𝔏 : Signature) where
open Signature(𝔏)
open import Data.DependentWidthTree as Tree hiding (height)
import Functional.Dependent
import Lvl
open import Formalization.PredicateLogic.Syntax(𝔏)
open import Formalization.PredicateLogic.Syntax.Substitution(𝔏)
open import Functional using (_∘_ ; _∘₂_ ; _∘₃_ ; _∘₄_ ; swap ; _←_ ; _on₂_)
open import Numeral.Finite
open import Numeral.Natural.Function.Proofs
open import Numeral.Natural.Inductions
open import Numeral.Natural.Relation.Order
open import Numeral.Natural.Relation.Order.Proofs
open import Numeral.Natural
open import Relator.Equals
open import Structure.Relator
open import Structure.Relator.Ordering
open import Structure.Relator.Ordering.Proofs
open import Type.Dependent
open import Type
private variable ℓ : Lvl.Level
private variable vars vars₁ vars₂ : ℕ
private variable φ ψ : Formula(vars)
tree : Formula(vars) → FiniteTreeStructure
tree (_ $ _) = Node 0 \()
tree ⊤ = Node 0 \()
tree ⊥ = Node 0 \()
tree (φ ∧ ψ) = Node 2 \{𝟎 → tree φ; (𝐒 𝟎) → tree ψ}
tree (φ ∨ ψ) = Node 2 \{𝟎 → tree φ; (𝐒 𝟎) → tree ψ}
tree (φ ⟶ ψ) = Node 2 \{𝟎 → tree φ; (𝐒 𝟎) → tree ψ}
tree (Ɐ φ) = Node 1 \{𝟎 → tree φ}
tree (∃ φ) = Node 1 \{𝟎 → tree φ}
height : Formula(vars) → ℕ
height = Tree.height ∘ tree
-- Ordering on formulas based on the height of their tree representation.
_<↑_ : (Σ ℕ Formula) → (Σ ℕ Formula) → Type
_<↑_ = (_<_) on₂ (height Functional.Dependent.∘ Σ.right)
substitute-height : ∀{t} → (height(substitute{vars₁ = vars₁}{vars₂ = vars₂} t φ) ≡ height φ)
substitute-height {φ = f $ x} = [≡]-intro
substitute-height {φ = ⊤} = [≡]-intro
substitute-height {φ = ⊥} = [≡]-intro
substitute-height {φ = φ ∧ ψ} {t} rewrite substitute-height {φ = φ}{t} rewrite substitute-height {φ = ψ}{t} = [≡]-intro
substitute-height {φ = φ ∨ ψ} {t} rewrite substitute-height {φ = φ}{t} rewrite substitute-height {φ = ψ}{t} = [≡]-intro
substitute-height {φ = φ ⟶ ψ} {t} rewrite substitute-height {φ = φ}{t} rewrite substitute-height {φ = ψ}{t} = [≡]-intro
substitute-height {φ = Ɐ φ} {t} rewrite substitute-height {φ = φ}{termMapper𝐒 t} = [≡]-intro
substitute-height {φ = ∃ φ} {t} rewrite substitute-height {φ = φ}{termMapper𝐒 t} = [≡]-intro
instance
[<↑]-wellfounded : Strict.Properties.WellFounded(_<↑_)
[<↑]-wellfounded = wellfounded-image-by-trans {f = height Functional.Dependent.∘ Σ.right}
induction-on-height : (P : ∀{vars} → Formula(vars) → Type{ℓ}) → (∀{vars}{φ : Formula(vars)} → (∀{vars}{ψ : Formula(vars)} → (height ψ < height φ) → P(ψ)) → P(φ)) → ∀{vars}{φ : Formula(vars)} → P(φ)
induction-on-height P step {vars}{φ} = Strict.Properties.wellfounded-induction(_<↑_) (\{ {intro vars φ} p → step{vars}{φ} \{vars}{ψ} ph → p{intro vars ψ} ⦃ ph ⦄}) {intro vars φ}
⊤-height-order : (height{vars} ⊤ ≤ height φ)
⊤-height-order = [≤]-minimum
⊥-height-order : (height{vars} ⊥ ≤ height φ)
⊥-height-order = [≤]-minimum
∧-height-orderₗ : (height φ < height(φ ∧ ψ))
∧-height-orderₗ = [≤]-with-[𝐒]
∧-height-orderᵣ : (height ψ < height(φ ∧ ψ))
∧-height-orderᵣ = [≤]-with-[𝐒]
∨-height-orderₗ : (height φ < height(φ ∨ ψ))
∨-height-orderₗ = [≤]-with-[𝐒]
∨-height-orderᵣ : (height ψ < height(φ ∨ ψ))
∨-height-orderᵣ = [≤]-with-[𝐒]
⟶-height-orderₗ : (height φ < height(φ ⟶ ψ))
⟶-height-orderₗ = [≤]-with-[𝐒]
⟶-height-orderᵣ : (height ψ < height(φ ⟶ ψ))
⟶-height-orderᵣ = [≤]-with-[𝐒]
Ɐ-height-order : (height φ < height(Ɐ φ))
Ɐ-height-order = [<]-of-[𝐒]
∃-height-order : (height φ < height(∃ φ))
∃-height-order = [<]-of-[𝐒]
-- induction-on-height : ∀{P : ∀{vars} → Formula(vars) → Type{ℓ}} → (∀{vars} → P{vars}(⊤)) → (∀{vars} → P{vars}(⊥)) → ((∀{vars}{ψ : Formula(vars)} → (height ψ < height φ) → P(ψ)) → P(φ)) → P(φ)
-- induction-on-height {φ = φ} base⊤ base⊥ step = step {!Strict.Properties.wellfounded-induction(_<↑_)!}
| 41.136842
| 197
| 0.649437
|
1164873c4326f6d5bd4b1f1b4bdafe9661eb6979
| 6,401
|
agda
|
Agda
|
src/Bisimilarity/Step.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Bisimilarity/Step.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
src/Bisimilarity/Step.agda
|
nad/up-to
|
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Step function, used to define strong and weak bisimilarity as
-- well as expansion
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude
open import Labelled-transition-system
module Bisimilarity.Step
{ℓ}
(lts : LTS ℓ)
(open LTS lts)
(_[_]↝₁_ _[_]↝₂_ : Proc → Label → Proc → Type ℓ)
where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Bijection equality-with-J using (_↔_)
import Equivalence equality-with-J as Eq
open import Function-universe equality-with-J as F hiding (_∘_)
open import H-level.Closure equality-with-J
import Similarity.Step lts as One-sided
open import Indexed-container hiding (⟨_⟩)
open import Indexed-container.Combinators hiding (_∘_)
open import Relation
private
module Temporarily-private where
-- If _[_]↝₁_ and _[_]↝₂_ are instantiated with _[_]⟶_, then this is
-- basically the function from Definition 6.3.1 in Pous and
-- Sangiorgi's "Enhancements of the bisimulation proof method",
-- except that clause (3) is omitted.
--
-- Similarly, if the relations are instantiated with _[_]⇒̂_, then
-- this is basically the function wb₁, again with the exception that
-- clause (3) is omitted.
--
-- Finally, if _[_]↝₁_ is instantiated with _[_]⟶̂_ and _[_]↝₂_ is
-- instantiated with _[_]⇒_, then we get the expansion relation's
-- "step" function.
record Step {r} (R : Rel₂ r Proc) (pq : Proc × Proc) :
Type (ℓ ⊔ r) where
constructor ⟨_,_⟩
private
p = proj₁ pq
q = proj₂ pq
field
left-to-right : ∀ {p′ μ} →
p [ μ ]⟶ p′ → ∃ λ q′ → q [ μ ]↝₁ q′ × R (p′ , q′)
right-to-left : ∀ {q′ μ} →
q [ μ ]⟶ q′ → ∃ λ p′ → p [ μ ]↝₂ p′ × R (p′ , q′)
open Temporarily-private using (Step)
-- The Step function, expressed as an indexed container.
StepC : Container (Proc × Proc) (Proc × Proc)
StepC = One-sided.StepC _[_]↝₁_ ⟷ One-sided.StepC _[_]↝₂_
-- The strong bisimilarity container presented in the paper,
-- generalised to use _[_]↝₁_ and _[_]↝₂_.
StepC′ : Container (Proc × Proc) (Proc × Proc)
StepC′ =
(λ { (p , q) → (∀ {p′ μ} → p [ μ ]⟶ p′ → ∃ λ q′ → q [ μ ]↝₁ q′) ×
(∀ {q′ μ} → q [ μ ]⟶ q′ → ∃ λ p′ → p [ μ ]↝₂ p′)
})
◁
(λ { {(p , q)} (lr , rl) (p′ , q′) →
(∃ λ μ → ∃ λ (p⟶p′ : p [ μ ]⟶ p′) → proj₁ (lr p⟶p′) ≡ q′) ⊎
(∃ λ μ → ∃ λ (q⟶q′ : q [ μ ]⟶ q′) → proj₁ (rl q⟶q′) ≡ p′)
})
-- The interpretations of the two containers above are pointwise
-- logically equivalent, and in the presence of extensionality they
-- are pointwise isomorphic.
StepC↔StepC′ :
∀ {k r} {R : Rel₂ r Proc} {pq} →
Extensionality? k ℓ (ℓ ⊔ r) →
⟦ StepC ⟧ R pq ↝[ k ] ⟦ StepC′ ⟧ R pq
StepC↔StepC′ {pq = p , q} =
inverse-ext? λ {k} ext →
Σ-cong (inverse $
drop-⊤-left-Σ (One-sided.Magic↔⊤ _)
×-cong
drop-⊤-left-Σ (One-sided.Magic↔⊤ _)) λ { (lr , rl) →
implicit-∀-cong ext λ { {p′ , q′} →
Π-cong (lower-extensionality? k lzero ℓ ext)
(F.id ⊎-cong (
(∃ λ μ → ∃ λ (q⟶q′ : q [ μ ]⟶ q′) →
proj₁ (rl q⟶q′) ≡ p′) ↝⟨ inverse $ drop-⊤-left-Σ (_⇔_.to contractible⇔↔⊤ (singleton-contractible _)) ⟩
(∃ λ (q′p′≡ : ∃ λ q′p′ → q′p′ ≡ (q′ , p′)) →
∃ λ μ → ∃ λ (q⟶q′ : q [ μ ]⟶ proj₁ (proj₁ q′p′≡)) →
proj₁ (rl q⟶q′) ≡ proj₂ (proj₁ q′p′≡)) ↝⟨ inverse Σ-assoc ⟩
(∃ λ q′p′ → q′p′ ≡ (q′ , p′) ×
∃ λ μ → ∃ λ (q⟶q′ : q [ μ ]⟶ proj₁ q′p′) →
proj₁ (rl q⟶q′) ≡ proj₂ q′p′) ↔⟨ (∃-cong λ _ → (inverse $ Eq.≃-≡ (Eq.↔⇒≃ ×-comm)) ×-cong F.id) ⟩□
(∃ λ q′p′ → swap q′p′ ≡ (p′ , q′) ×
∃ λ μ → ∃ λ (q⟶q′ : q [ μ ]⟶ proj₁ q′p′) →
proj₁ (rl q⟶q′) ≡ proj₂ q′p′) □))
(λ _ → F.id) }}
-- The definition of Step in terms of a container is pointwise
-- logically equivalent to the direct definition, and in the presence
-- of extensionality it is pointwise isomorphic to the direct
-- definition.
Step↔StepC :
∀ {k r} {R : Rel₂ r Proc} {pq} →
Extensionality? k ℓ (ℓ ⊔ r) →
Step R pq ↝[ k ] ⟦ StepC ⟧ R pq
Step↔StepC {R = R} {pq} ext =
Step R pq ↔⟨ lemma ⟩
One-sided.Step _[_]↝₁_ R pq
×
One-sided.Step _[_]↝₂_ (R ⁻¹) (swap pq) ↝⟨ One-sided.Step↔StepC _ ext ×-cong One-sided.Step↔StepC _ ext ⟩
⟦ One-sided.StepC _[_]↝₁_ ⟧ R pq
×
⟦ One-sided.StepC _[_]↝₂_ ⟧ (R ⁻¹) (swap pq) ↝⟨ inverse-ext? (λ ext → ⟦⟷⟧↔ ext (One-sided.StepC _[_]↝₁_) (One-sided.StepC _[_]↝₂_)) ext ⟩□
⟦ StepC ⟧ R pq □
where
lemma : _ ↔ _
lemma = record
{ surjection = record
{ logical-equivalence = record
{ to = λ s → One-sided.⟨ Step.left-to-right s ⟩
, One-sided.⟨ Step.right-to-left s ⟩
; from = λ { (lr , rl) →
Temporarily-private.⟨ One-sided.Step.challenge lr
, One-sided.Step.challenge rl
⟩
}
}
; right-inverse-of = λ _ → refl
}
; left-inverse-of = λ _ → refl
}
-- A variant of the previous lemma, stated for StepC′ instead of
-- StepC.
Step↔StepC′ :
∀ {k r} {R : Rel₂ r Proc} {pq} →
Extensionality? k ℓ (ℓ ⊔ r) →
Step R pq ↝[ k ] ⟦ StepC′ ⟧ R pq
Step↔StepC′ {R = R} {pq} ext =
Step R pq ↝⟨ Step↔StepC ext ⟩
⟦ StepC ⟧ R pq ↝⟨ StepC↔StepC′ ext ⟩□
⟦ StepC′ ⟧ R pq □
module StepC {r} {R : Rel₂ r Proc} {p q} where
-- A "constructor".
⟨_,_⟩ :
(∀ {p′ μ} → p [ μ ]⟶ p′ → ∃ λ q′ → q [ μ ]↝₁ q′ × R (p′ , q′)) →
(∀ {q′ μ} → q [ μ ]⟶ q′ → ∃ λ p′ → p [ μ ]↝₂ p′ × R (p′ , q′)) →
⟦ StepC ⟧ R (p , q)
⟨ lr , rl ⟩ = _⇔_.to (Step↔StepC _) Temporarily-private.⟨ lr , rl ⟩
-- Some "projections".
left-to-right :
⟦ StepC ⟧ R (p , q) →
∀ {p′ μ} → p [ μ ]⟶ p′ → ∃ λ q′ → q [ μ ]↝₁ q′ × R (p′ , q′)
left-to-right = Step.left-to-right ∘ _⇔_.from (Step↔StepC _)
right-to-left :
⟦ StepC ⟧ R (p , q) →
∀ {q′ μ} → q [ μ ]⟶ q′ → ∃ λ p′ → p [ μ ]↝₂ p′ × R (p′ , q′)
right-to-left = Step.right-to-left ∘ _⇔_.from (Step↔StepC _)
open Temporarily-private public
| 33.338542
| 141
| 0.499297
|
52ad02ddc85e80600e4f619e391d499ce986f5b7
| 1,053
|
agda
|
Agda
|
src/PathOperations.agda
|
vituscze/HoTT-lectures
|
7730385adfdbdda38ee8b124be3cdeebb7312c65
|
[
"BSD-3-Clause"
] | null | null | null |
src/PathOperations.agda
|
vituscze/HoTT-lectures
|
7730385adfdbdda38ee8b124be3cdeebb7312c65
|
[
"BSD-3-Clause"
] | null | null | null |
src/PathOperations.agda
|
vituscze/HoTT-lectures
|
7730385adfdbdda38ee8b124be3cdeebb7312c65
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K #-}
module PathOperations where
open import Types
infixr 4 _·_
infix 9 _⁻¹
_⁻¹ : ∀ {a} {A : Set a} {x y : A} →
x ≡ y → y ≡ x
_⁻¹ = J (λ x y _ → y ≡ x) (λ _ → refl) _ _
_·_ : ∀ {a} {A : Set a} {x y z : A} →
x ≡ y → y ≡ z → x ≡ z
_·_ {z = z} = J (λ x y _ → y ≡ z → x ≡ z) (λ _ p′ → p′) _ _
tr : ∀ {a p} {A : Set a} (P : A → Set p) {x y : A} (p : x ≡ y) →
P x → P y
tr P = J (λ x y _ → P x → P y) (λ _ x → x) _ _
ap : ∀ {a b} {A : Set a} {B : Set b} {x y : A} (f : A → B) →
x ≡ y → f x ≡ f y
ap f = J (λ x y _ → f x ≡ f y) (λ _ → refl) _ _
ap₂ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
{x x′ y y′} (f : A → B → C) (p : x ≡ x′) (q : y ≡ y′) →
f x y ≡ f x′ y′
ap₂ f p q = ap (λ _ → f _ _) p · ap (f _) q
apd : ∀ {a b} {A : Set a} {B : A → Set b} {x y : A}
(f : ∀ a → B a) (p : x ≡ y) →
tr B p (f x) ≡ f y
apd {B = B} f = J
(λ x y p → tr B p (f x) ≡ f y)
(λ _ → refl) _ _
happly : ∀ {a b} {A : Set a} {B : A → Set b} {f g : (x : A) → B x} →
f ≡ g → ∀ x → f x ≡ g x
happly p x = ap (λ f → f x) p
| 26.325
| 68
| 0.377968
|
219e51b894ccb1f1ff1f536302a42d526f729935
| 2,547
|
agda
|
Agda
|
test/SetQuotientTest.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | 3
|
2020-07-31T18:15:26.000Z
|
2022-02-19T12:15:21.000Z
|
test/SetQuotientTest.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
test/SetQuotientTest.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts #-}
module SetQuotientTest where
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Foundations.Logic renaming (inl to inlᵖ; inr to inrᵖ)
open import Cubical.Data.Empty renaming (elim to ⊥-elim; ⊥ to ⊥⊥)
open import Cubical.Relation.Nullary.Base renaming (¬_ to ¬ᵗ_)
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_)
open import Cubical.Data.NatPlusOne using (HasFromNat; 1+_; ℕ₊₁; ℕ₊₁→ℕ)
open import Cubical.HITs.Ints.QuoInt using (HasFromNat; signed) renaming
( abs to absᶻ
; pos to pos
; neg to neg
)
open import Cubical.HITs.Ints.QuoInt hiding (_+_; -_; +-assoc; +-comm)
open import Cubical.HITs.Rationals.QuoQ using
( ℚ
; onCommonDenom
; onCommonDenomSym
; eq/
; _//_
; _∼_
; isSetℚ
)
renaming
( [_] to [_]ᶠ
; ℕ₊₁→ℤ to [1+_ⁿ]ᶻ
)
open import Cubical.HITs.SetQuotients as SetQuotient using () renaming (_/_ to _//_)
postulate
_<ᶻ_ : ℤ → ℤ → hProp ℓ-zero
_<'_ : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → hProp ℓ-zero
(aᶻ , aⁿ) <' (bᶻ , bⁿ) =
let aⁿᶻ = [1+ aⁿ ⁿ]ᶻ
bⁿᶻ = [1+ bⁿ ⁿ]ᶻ
in (aᶻ * bⁿᶻ) <ᶻ (bᶻ * aⁿᶻ)
postulate
<'-respects-∼ˡ : ∀ a b x → a ∼ b → a <' x ≡ b <' x
<'-respects-∼ʳ : ∀ x a b → a ∼ b → x <' a ≡ x <' b
_<_ : ℚ → ℚ → hProp ℓ-zero
a < b = SetQuotient.rec2 {R = _∼_} {B = hProp ℓ-zero} isSetHProp _<'_ <'-respects-∼ˡ <'-respects-∼ʳ a b
isProp⊎ˡ : ∀{ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → isProp A → isProp B → (A → ¬ᵗ B) → isProp (A ⊎ B)
isProp⊎ˡ pA pB A⇒¬B (inl x) (inl y) = cong inl (pA x y)
isProp⊎ˡ pA pB A⇒¬B (inr x) (inr y) = cong inr (pB x y)
isProp⊎ˡ pA pB A⇒¬B (inl x) (inr y) = ⊥-elim (A⇒¬B x y)
isProp⊎ˡ pA pB A⇒¬B (inr x) (inl y) = ⊥-elim (A⇒¬B y x)
⊎ᵖ-syntax : ∀{ℓ ℓ'} (P : hProp ℓ) (Q : hProp ℓ') → {[ P ] → [ ¬ Q ]} → hProp _
⊎ᵖ-syntax P Q {P⇒¬Q} = ([ P ] ⊎ [ Q ]) , isProp⊎ˡ (isProp[] P) (isProp[] Q) P⇒¬Q
syntax ⊎ᵖ-syntax P Q {P⇒¬Q} = [ P⇒¬Q ] P ⊎ᵖ Q
postulate
<-asym : ∀ x y → [ x < y ] → [ ¬(y < x) ]
_#_ : ℚ → ℚ → hProp ℓ-zero
x # y = [ <-asym x y ] (x < y) ⊎ᵖ (y < x)
_⁻¹''' : (x : ℚ) → [ x # 0 ] → ℚ
_⁻¹''' = SetQuotient.elim {R = _∼_} {B = λ x → [ x # 0 ] → ℚ} φ _⁻¹'' ⁻¹''-respects-∼ where
φ : ∀ x → isSet ([ x # 0 ] → ℚ)
φ x = isSetΠ (λ _ → isSetℚ)
_⁻¹'' : (a : ℤ × ℕ₊₁) → [ [ a ]ᶠ # 0 ] → ℚ
x ⁻¹'' = {!!}
⁻¹''-respects-∼ : (a b : ℤ × ℕ₊₁) (r : a ∼ b)
→ PathP (λ i → [ eq/ a b r i # 0 ] → ℚ) (a ⁻¹'') (b ⁻¹'')
⁻¹''-respects-∼ a b r = {!!}
| 33.96
| 103
| 0.537888
|
14f7bb99556a4e68323b4b8a39a4382b135db707
| 71
|
agda
|
Agda
|
test/Fail/Polarity-pragma-in-safe-mode.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Polarity-pragma-in-safe-mode.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Polarity-pragma-in-safe-mode.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --safe #-}
postulate F : Set → Set
{-# POLARITY F ++ #-}
| 11.833333
| 23
| 0.507042
|
0dcafef2870545554ebb21e5efb1a4bc36e37798
| 1,896
|
agda
|
Agda
|
src/Control/Monad/KleisliTriple.agda
|
andreasabel/cubical
|
914f655c7c0417754c2ffe494d3f6ea7a357b1c3
|
[
"MIT"
] | null | null | null |
src/Control/Monad/KleisliTriple.agda
|
andreasabel/cubical
|
914f655c7c0417754c2ffe494d3f6ea7a357b1c3
|
[
"MIT"
] | null | null | null |
src/Control/Monad/KleisliTriple.agda
|
andreasabel/cubical
|
914f655c7c0417754c2ffe494d3f6ea7a357b1c3
|
[
"MIT"
] | null | null | null |
-- Non-indexed (plain) monads in form of Kleisli triple, presented in point-free style.
module Control.Monad.KleisliTriple where
open import Function using (id) renaming (_∘′_ to _∘_)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Axiom.FunctionExtensionality
open import Control.Functor
record IsKleisliTriple (M : Set → Set) : Set₁ where
-- Methods.
field
return : ∀ {A } → A → M A
bind′ : ∀ {A B} → (A → M B) → M A → M B
-- Laws.
field
bind′-β : ∀ {A B} {k : A → M B} →
bind′ k ∘ return ≡ k
bind′-η : ∀ {A} →
bind′ {A = A} return ≡ id
bind′-∘ : ∀ {A B C} {k : A → M B} {l : B → M C} →
bind′ (bind′ l ∘ k) ≡ bind′ l ∘ bind′ k
-- Notations for bind′.
-- Postfix category-theoretical notation.
_✶ = bind′
-- Infix Haskell notation.
infixl 6 _=<<_
_=<<_ = bind′
-- Kleisli composition.
infixl 6 _<=<_
_<=<_ : ∀ {A B C : Set} (l : B → M C) (k : A → M B) → (A → M C)
l <=< k = bind′ l ∘ k
-- Functoriality.
isFunctor : IsFunctor M
isFunctor = record
{ ops = record { map = map }
; laws = record { map-id = bind′-η ; map-∘ = sym (map-∘-sym _ _) }
}
where
map : ∀ {A B} → (A → B) → M A → M B
map f = bind′ (return ∘ f)
map-∘-sym : ∀ {A B C} (f : A → B) (g : B → C) → map g ∘ map f ≡ map (g ∘ f)
map-∘-sym f g = begin
map g ∘ map f ≡⟨⟩
bind′ (return ∘ g) ∘ bind′ (return ∘ f) ≡⟨ sym bind′-∘ ⟩
bind′ (bind′ (return ∘ g) ∘ return ∘ f) ≡⟨ cong (λ z → bind′ (z ∘ f)) bind′-β ⟩
bind′ (return ∘ g ∘ f) ≡⟨⟩
map (g ∘ f) ∎
open IsFunctor isFunctor public
-- Monads in Kleisli Triple presentation.
record KleisliTriple : Set₁ where
field
M : Set → Set
M! : IsKleisliTriple M
open IsKleisliTriple M! public
| 23.407407
| 88
| 0.511076
|
7cb04e2fc37d62f221199ba3358cf986151d6a93
| 11,288
|
agda
|
Agda
|
LibraBFT/Concrete/Properties/VotesOnce.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/Concrete/Properties/VotesOnce.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/Concrete/Properties/VotesOnce.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open import LibraBFT.Base.KVMap
open import LibraBFT.Base.PKCS
open import LibraBFT.Concrete.System
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochDep
open import LibraBFT.ImplShared.Util.Crypto
open import LibraBFT.Lemmas
open import LibraBFT.Prelude
open import LibraBFT.Yasm.Base
open import Optics.All
open EpochConfig
-- In this module, we define two "implementation obligations"
-- (ImplObligationᵢ for i ∈ {1 , 2}), which are predicates over
-- reachable states of a system defined by
-- 'LibraBFT.Concrete.System.Parameters'. These two properties relate
-- votes sent by the same sender, ensuring that if they are for the
-- same epoch and round, then they vote for the same blockID; the
-- first relates a vote output by the handler to a vote sent
-- previously, and the second relates two votes both sent by the
-- handler.
--
-- We then prove that, if an implementation satisfies these two
-- semantic obligations, along with a structural one about messages
-- sent by honest peers in the implementation, then the implemenation
-- satisfies the LibraBFT.Abstract.Properties.VotesOnce invariant.
-- It is not actually necessary to provide an EpochConfig to define
-- these implementation obligations, but it is needed below to state
-- the goal of the proof (voo). In contrast, the PreferredRound rule
-- requires and EpochConfig to state the obligations, because they
-- are defined in terms of abstract Records, which are defined for an
-- EpochConfig. We introduce the EpochConfig at the top of this
-- module for consistency with the PreferredRound rule so that the
-- order of parameters to invoke the respective proofs is consistent.
module LibraBFT.Concrete.Properties.VotesOnce (iiah : SystemInitAndHandlers ℓ-RoundManager ConcSysParms) (𝓔 : EpochConfig) where
open SystemTypeParameters ConcSysParms
open SystemInitAndHandlers iiah
open ParamsWithInitAndHandlers iiah
open import LibraBFT.ImplShared.Util.HashCollisions iiah
open import LibraBFT.Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms iiah PeerCanSignForPK PeerCanSignForPK-stable
open import LibraBFT.Concrete.Properties.Common iiah 𝓔
-- TODO-3: This may not be the best way to state the implementation obligation. Why not reduce
-- this as much as possible before giving the obligation to the implementation? For example, this
-- will still require the implementation to deal with hash collisons (v and v' could be different,
-- but yield the same bytestring and therefore same signature). Also, avoid the need for the
-- implementation to reason about messages sent by step-cheat, or give it something to make this
-- case easy to eliminate.
ImplObligation₂ : Set (ℓ+1 ℓ-RoundManager)
ImplObligation₂ =
∀{pid s' outs pk}{pre : SystemState}
→ ReachableSystemState pre
-- For any honest call to /handle/ or /init/,
→ (sps : StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s' , outs))
→ ∀{v m v' m'}
→ Meta-Honest-PK pk
-- For every vote v represented in a message output by the call
→ v ⊂Msg m → send m ∈ outs
→ (sig : WithVerSig pk v) → ¬ (∈BootstrapInfo bootstrapInfo (ver-signature sig))
→ ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool pre))
→ PeerCanSignForPK (StepPeer-post {pre = pre} (step-honest sps)) v pid pk
-- And if there exists another v' that is also new and valid
→ v' ⊂Msg m' → send m' ∈ outs
→ (sig' : WithVerSig pk v') → ¬ (∈BootstrapInfo bootstrapInfo (ver-signature sig'))
→ ¬ (MsgWithSig∈ pk (ver-signature sig') (msgPool pre))
→ PeerCanSignForPK (StepPeer-post {pre = pre} (step-honest sps)) v' pid pk
-- If v and v' share the same epoch and round
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ v ^∙ vRound ≡ v' ^∙ vRound
----------------------------------------------------------
-- Then, an honest implemenation promises v and v' vote for the same blockId.
→ v ^∙ vProposedId ≡ v' ^∙ vProposedId
-- Next, we prove that, given the necessary obligations,
module Proof
(sps-corr : StepPeerState-AllValidParts)
(Impl-bsvc : ImplObl-bootstrapVotesConsistent)
(Impl-bsvr : ImplObl-bootstrapVotesRound≡0)
(Impl-nvr≢0 : ImplObl-NewVoteRound≢0)
(Impl-∈BI? : (sig : Signature) → Dec (∈BootstrapInfo bootstrapInfo sig))
(Impl-IRO : IncreasingRoundObligation)
(Impl-VO2 : ImplObligation₂)
where
-- Any reachable state satisfies the VO rule for any epoch in the system.
module _ {st : SystemState}(r : ReachableSystemState st) where
open Structural sps-corr
-- Bring in intSystemState
open PerEpoch 𝓔
open PerState st
open PerReachableState r
open ConcreteCommonProperties st r sps-corr Impl-bsvr Impl-nvr≢0
open WithEC
open import LibraBFT.Concrete.Obligations.VotesOnce 𝓔 (ConcreteVoteEvidence 𝓔) as VO
-- The VO proof is done by induction on the execution trace leading to 'st'. In
-- Agda, this is 'r : RechableSystemState st' above.
private
-- From this point onwards, it might be easier to read this proof starting at 'voo'
-- at the end of the file. Next, we provide an overview the proof.
--
-- We wish to prove that, for any two votes v and v' cast by an honest α in the message
-- pool of a state st, if v and v' have equal rounds and epochs, then they vote for the
-- same block.
--
-- The base case and the case for a new epoch in the system are trivial. For the base case
-- we get to a contradiction because it's not possible to have any message in the msgpool.
--
-- Regarding the PeerStep case. The induction hypothesis tells us that the property holds
-- in the pre-state. Next, we reason about the post-state. We start by analyzing whether
-- v and v' have been sent as outputs of the PeerStep under scrutiny or were already in
-- the pool before.
--
-- There are four possibilities:
--
-- i) v and v' were aleady present in the msgPool before: use induction hypothesis.
-- ii) v and v' are both in the output produced by the PeerStep under scrutiny.
-- iii) v was present before, but v' is new.
-- iv) v' was present before, but v is new.
--
-- In order to obtain this four possiblities we invoke newMsg⊎msgSent4 lemma, which
-- receives proof that some vote is in a message that is in the msgPool of the post state
-- and returns evidence that either the vote is new or that some message with the same
-- signature was sent before.
--
-- Case (i) is trivial; cases (iii) and (iv) are symmetric and reduce to an implementation
-- obligation (Impl-VO1) and case (ii) reduces to a different implementation obligation
-- (Impl-VO2).
VotesOnceProof :
∀ {pk round epoch blockId₁ blockId₂} {st : SystemState}
→ ReachableSystemState st
→ Meta-Honest-PK pk
→ (m₁ : VoteForRound∈ pk round epoch blockId₁ (msgPool st))
→ (m₂ : VoteForRound∈ pk round epoch blockId₂ (msgPool st))
→ blockId₁ ≡ blockId₂
VotesOnceProof step-0 _ m₁ = ⊥-elim (¬Any[] (msg∈pool m₁))
VotesOnceProof step@(step-s r theStep) pkH m₁ m₂
with msgRound≡ m₁ | msgEpoch≡ m₁ | msgBId≡ m₁
| msgRound≡ m₂ | msgEpoch≡ m₂ | msgBId≡ m₂
...| refl | refl | refl | refl | refl | refl
with Impl-∈BI? (_vSignature (msgVote m₁)) | Impl-∈BI? (_vSignature (msgVote m₂))
...| yes init₁ | yes init₂ = Impl-bsvc (msgVote m₁) (msgVote m₂) init₁ init₂
...| yes init₁ | no ¬init₂ = ⊥-elim (NewVoteRound≢0 step pkH m₂ ¬init₂ (Impl-bsvr (msgSigned m₁) init₁))
...| no ¬init₁ | yes init₂ = ⊥-elim (NewVoteRound≢0 step pkH m₁ ¬init₁ (Impl-bsvr (msgSigned m₂) init₂))
...| no ¬init₁ | no ¬init₂
with theStep
...| step-peer cheat@(step-cheat c)
= let m₁sb4 = ¬cheatForgeNewSig r cheat unit pkH (msgSigned m₁) (msg⊆ m₁) (msg∈pool m₁) ¬init₁
m₂sb4 = ¬cheatForgeNewSig r cheat unit pkH (msgSigned m₂) (msg⊆ m₂) (msg∈pool m₂) ¬init₂
v₁sb4 = msgSentB4⇒VoteRound∈ (msgSigned m₁) m₁sb4
v₂sb4 = msgSentB4⇒VoteRound∈ (msgSigned m₂) m₂sb4
in VotesOnceProof r pkH (proj₁ v₁sb4) (proj₁ v₂sb4)
...| step-peer (step-honest stP)
with ⊎-map₂ (msgSentB4⇒VoteRound∈ (msgSigned m₁))
(newMsg⊎msgSentB4 r stP pkH (msgSigned m₁) ¬init₁ (msg⊆ m₁) (msg∈pool m₁))
| ⊎-map₂ (msgSentB4⇒VoteRound∈ (msgSigned m₂))
(newMsg⊎msgSentB4 r stP pkH (msgSigned m₂) ¬init₂ (msg⊆ m₂) (msg∈pool m₂))
...| inj₂ (v₁sb4 , refl) | inj₂ (v₂sb4 , refl)
= VotesOnceProof r pkH v₁sb4 v₂sb4
...| inj₁ (m₁∈outs , v₁pk , v₁New) | inj₁ (m₂∈outs , v₂pk , v₂New)
= Impl-VO2 r stP pkH (msg⊆ m₁) m₁∈outs (msgSigned m₁) ¬init₁ v₁New v₁pk
(msg⊆ m₂) m₂∈outs (msgSigned m₂) ¬init₂ v₂New v₂pk refl refl
...| inj₁ (m₁∈outs , v₁pk , v₁New) | inj₂ (v₂sb4 , refl)
= let round≡ = trans (msgRound≡ v₂sb4) (msgRound≡ m₂)
¬bootstrapV₂ = ¬Bootstrap∧Round≡⇒¬Bootstrap step pkH m₂ ¬init₂ (msgSigned v₂sb4) round≡
epoch≡ = sym (msgEpoch≡ v₂sb4)
in either (λ v₂<v₁ → ⊥-elim (<⇒≢ v₂<v₁ (msgRound≡ v₂sb4)))
(λ v₁sb4 → VotesOnceProof r pkH v₁sb4 v₂sb4)
(Impl-IRO r stP pkH (msg⊆ m₁) m₁∈outs (msgSigned m₁) ¬init₁ v₁New v₁pk
(msg⊆ v₂sb4) (msg∈pool v₂sb4) (msgSigned v₂sb4) ¬bootstrapV₂ epoch≡)
...| inj₂ (v₁sb4 , refl) | inj₁ (m₂∈outs , v₂pk , v₂New)
= let round≡ = trans (msgRound≡ v₁sb4) (msgRound≡ m₁)
¬bootstrapV₁ = ¬Bootstrap∧Round≡⇒¬Bootstrap step pkH m₁ ¬init₁ (msgSigned v₁sb4) round≡
in either (λ v₁<v₂ → ⊥-elim (<⇒≢ v₁<v₂ (msgRound≡ v₁sb4)))
(λ v₂sb4 → VotesOnceProof r pkH v₁sb4 v₂sb4)
(Impl-IRO r stP pkH (msg⊆ m₂) m₂∈outs (msgSigned m₂) ¬init₂ v₂New v₂pk
(msg⊆ v₁sb4) (msg∈pool v₁sb4) (msgSigned v₁sb4) ¬bootstrapV₁
(sym (msgEpoch≡ v₁sb4)))
voo : VO.Type intSystemState
voo hpk refl sv refl sv' refl
with vmsg≈v (vmFor sv) | vmsg≈v (vmFor sv')
...| refl | refl
with vmsgEpoch (vmFor sv) | vmsgEpoch (vmFor sv')
...| refl | refl
= let vfr = mkVoteForRound∈ (nm (vmFor sv)) (cv ((vmFor sv))) (cv∈nm (vmFor sv))
(vmSender sv) (nmSentByAuth sv) (vmsgSigned (vmFor sv))
(vmsgEpoch (vmFor sv)) refl refl
vfr' = mkVoteForRound∈ (nm (vmFor sv')) (cv (vmFor sv')) (cv∈nm (vmFor sv'))
(vmSender sv') (nmSentByAuth sv') (vmsgSigned (vmFor sv'))
(vmsgEpoch (vmFor sv')) refl refl
in VotesOnceProof r hpk vfr vfr'
| 52.502326
| 128
| 0.66203
|
1116444ee12c2092ee13cde6524f1ae55385e0ab
| 646
|
agda
|
Agda
|
agda-stdlib/src/Data/List/Relation/Subset/Propositional/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/List/Relation/Subset/Propositional/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/Relation/Subset/Propositional/Properties.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.List.Relation.Binary.Subset.Propositional.Properties directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Subset.Propositional.Properties where
open import Data.List.Relation.Binary.Subset.Propositional.Properties
public
{-# WARNING_ON_IMPORT
"Data.List.Relation.Subset.Propositional.Properties was deprecated in v1.0.
Use Data.List.Relation.Binary.Subset.Propositional.Properties instead."
#-}
| 34
| 75
| 0.611455
|
36d529693dc9ac6a423c03b8795149b789c17298
| 158
|
agda
|
Agda
|
Task/Reverse-a-string/Agda/reverse-a-string.agda
|
mullikine/RosettaCodeData
|
4f0027c6ce83daa36118ee8b67915a13cd23ab67
|
[
"Info-ZIP"
] | 1
|
2018-11-09T22:08:38.000Z
|
2018-11-09T22:08:38.000Z
|
Task/Reverse-a-string/Agda/reverse-a-string.agda
|
mullikine/RosettaCodeData
|
4f0027c6ce83daa36118ee8b67915a13cd23ab67
|
[
"Info-ZIP"
] | null | null | null |
Task/Reverse-a-string/Agda/reverse-a-string.agda
|
mullikine/RosettaCodeData
|
4f0027c6ce83daa36118ee8b67915a13cd23ab67
|
[
"Info-ZIP"
] | 1
|
2018-11-09T22:08:40.000Z
|
2018-11-09T22:08:40.000Z
|
module reverse_string where
open import Data.String
open import Data.List
reverse_string : String → String
reverse_string s = fromList (reverse (toList s))
| 19.75
| 48
| 0.797468
|
360da3588805192a112c0137c419b040f8961055
| 34
|
agda
|
Agda
|
test/Fail/NoSuchModule.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/NoSuchModule.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/NoSuchModule.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module NoSuchModule where
open X
| 8.5
| 25
| 0.823529
|
14079419f605046cefb0f8b7264c84130b3f04f2
| 4,484
|
agda
|
Agda
|
vendor/stdlib/src/Relation/Binary/Core.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Relation/Binary/Core.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Relation/Binary/Core.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- Properties of homogeneous binary relations
------------------------------------------------------------------------
-- This file contains some core definitions which are reexported by
-- Relation.Binary or Relation.Binary.PropositionalEquality.
module Relation.Binary.Core where
open import Data.Product
open import Data.Sum
open import Data.Function
open import Relation.Nullary.Core
------------------------------------------------------------------------
-- Homogeneous binary relations
Rel : Set → Set₁
Rel a = a → a → Set
------------------------------------------------------------------------
-- Simple properties of binary relations
infixr 4 _⇒_ _=[_]⇒_
-- Implication/containment. Could also be written ⊆.
_⇒_ : ∀ {a} → Rel a → Rel a → Set
P ⇒ Q = ∀ {i j} → P i j → Q i j
-- Generalised implication. If P ≡ Q it can be read as "f preserves
-- P".
_=[_]⇒_ : ∀ {a b} → Rel a → (a → b) → Rel b → Set
P =[ f ]⇒ Q = P ⇒ (Q on₁ f)
-- A synonym, along with a binary variant.
_Preserves_⟶_ : ∀ {a₁ a₂} → (a₁ → a₂) → Rel a₁ → Rel a₂ → Set
f Preserves P ⟶ Q = P =[ f ]⇒ Q
_Preserves₂_⟶_⟶_ : ∀ {a₁ a₂ a₃} →
(a₁ → a₂ → a₃) → Rel a₁ → Rel a₂ → Rel a₃ → Set
_+_ Preserves₂ P ⟶ Q ⟶ R =
∀ {x y u v} → P x y → Q u v → R (x + u) (y + v)
-- Reflexivity of _∼_ can be expressed as _≈_ ⇒ _∼_, for some
-- underlying equality _≈_. However, the following variant is often
-- easier to use.
Reflexive : {a : Set} → (_∼_ : Rel a) → Set
Reflexive _∼_ = ∀ {x} → x ∼ x
-- Irreflexivity is defined using an underlying equality.
Irreflexive : {a : Set} → (_≈_ _<_ : Rel a) → Set
Irreflexive _≈_ _<_ = ∀ {x y} → x ≈ y → ¬ (x < y)
-- Generalised symmetry.
Sym : ∀ {a} → Rel a → Rel a → Set
Sym P Q = P ⇒ flip₁ Q
Symmetric : {a : Set} → Rel a → Set
Symmetric _∼_ = Sym _∼_ _∼_
-- Generalised transitivity.
Trans : ∀ {a} → Rel a → Rel a → Rel a → Set
Trans P Q R = ∀ {i j k} → P i j → Q j k → R i k
Transitive : {a : Set} → Rel a → Set
Transitive _∼_ = Trans _∼_ _∼_ _∼_
Antisymmetric : {a : Set} → (_≈_ _≤_ : Rel a) → Set
Antisymmetric _≈_ _≤_ = ∀ {x y} → x ≤ y → y ≤ x → x ≈ y
Asymmetric : {a : Set} → (_<_ : Rel a) → Set
Asymmetric _<_ = ∀ {x y} → x < y → ¬ (y < x)
_Respects_ : {a : Set} → (a → Set) → Rel a → Set
P Respects _∼_ = ∀ {x y} → x ∼ y → P x → P y
_Respects₂_ : {a : Set} → Rel a → Rel a → Set
P Respects₂ _∼_ =
(∀ {x} → P x Respects _∼_) ×
(∀ {y} → flip₁ P y Respects _∼_)
Substitutive : {a : Set} → Rel a → Set₁
Substitutive _∼_ = ∀ P → P Respects _∼_
Congruential : ({a : Set} → Rel a) → Set₁
Congruential ∼ = ∀ {a b} → (f : a → b) → f Preserves ∼ ⟶ ∼
Congruential₂ : ({a : Set} → Rel a) → Set₁
Congruential₂ ∼ =
∀ {a b c} → (f : a → b → c) → f Preserves₂ ∼ ⟶ ∼ ⟶ ∼
Decidable : {a : Set} → Rel a → Set
Decidable _∼_ = ∀ x y → Dec (x ∼ y)
Total : {a : Set} → Rel a → Set
Total _∼_ = ∀ x y → (x ∼ y) ⊎ (y ∼ x)
data Tri (A B C : Set) : Set where
tri< : ( a : A) (¬b : ¬ B) (¬c : ¬ C) → Tri A B C
tri≈ : (¬a : ¬ A) ( b : B) (¬c : ¬ C) → Tri A B C
tri> : (¬a : ¬ A) (¬b : ¬ B) ( c : C) → Tri A B C
Trichotomous : {a : Set} → Rel a → Rel a → Set
Trichotomous _≈_ _<_ = ∀ x y → Tri (x < y) (x ≈ y) (x > y)
where _>_ = flip₁ _<_
record NonEmpty {I : Set} (T : Rel I) : Set where
field
i : I
j : I
proof : T i j
nonEmpty : ∀ {I} {T : Rel I} {i j} → T i j → NonEmpty T
nonEmpty p = record { i = _; j = _; proof = p }
------------------------------------------------------------------------
-- Propositional equality
-- This dummy module is used to avoid shadowing of the field named
-- refl defined in IsEquivalence below. The module is opened publicly
-- at the end of this file.
private
module Dummy where
infix 4 _≡_ _≢_
data _≡_ {a : Set} (x : a) : a → Set where
refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
{-# BUILTIN REFL refl #-}
-- Nonequality.
_≢_ : {a : Set} → a → a → Set
x ≢ y = ¬ x ≡ y
------------------------------------------------------------------------
-- Equivalence relations
-- The preorders of this library are defined in terms of an underlying
-- equivalence relation, and hence equivalence relations are not
-- defined in terms of preorders.
record IsEquivalence {a : Set} (_≈_ : Rel a) : Set where
field
refl : Reflexive _≈_
sym : Symmetric _≈_
trans : Transitive _≈_
reflexive : Dummy._≡_ ⇒ _≈_
reflexive Dummy.refl = refl
open Dummy public
| 27.509202
| 72
| 0.513381
|
388c63ee516ccecf4a778dd77eb11fceaefdddee
| 850
|
agda
|
Agda
|
examples/simple-lib/Lib/Bool.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/simple-lib/Lib/Bool.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/simple-lib/Lib/Bool.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Lib.Bool where
open import Lib.Logic
data Bool : Set where
true : Bool
false : Bool
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
isTrue : Bool -> Set
isTrue true = True
isTrue false = False
isFalse : Bool -> Set
isFalse true = False
isFalse false = True
data Inspect (b : Bool) : Set where
itsTrue : .(isTrue b) -> Inspect b
itsFalse : .(isFalse b) -> Inspect b
inspect : (b : Bool) -> Inspect b
inspect true = itsTrue _
inspect false = itsFalse _
infix 5 if_then_else_
if_then_else_ : {A : Set} -> Bool -> A -> A -> A
if true then x else y = x
if false then x else y = y
not : Bool -> Bool
not true = false
not false = true
infixr 25 _&&_
infixr 22 _||_
_&&_ : Bool -> Bool -> Bool
false && y = false
true && y = y
_||_ : Bool -> Bool -> Bool
false || y = y
true || y = true
| 17
| 48
| 0.622353
|
3f83f2e55d1cc66a568fe980c25220ae53a88255
| 16,008
|
agda
|
Agda
|
Cubical/Functions/Embedding.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Functions/Embedding.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Functions/Embedding.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Functions.Embedding where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence using (ua; univalence)
open import Cubical.Functions.Fibration
open import Cubical.Data.Sigma
open import Cubical.Functions.Fibration
open import Cubical.Functions.FunExtEquiv
open import Cubical.Relation.Nullary using (Discrete; yes; no)
open import Cubical.Structures.Axioms
open import Cubical.Reflection.StrictEquiv
open import Cubical.Data.Nat using (ℕ; zero; suc)
open import Cubical.Data.Sigma
private
variable
ℓ ℓ₁ ℓ₂ : Level
A B : Type ℓ
f h : A → B
w x : A
y z : B
-- Embeddings are generalizations of injections. The usual
-- definition of injection as:
--
-- f x ≡ f y → x ≡ y
--
-- is not well-behaved with higher h-levels, while embeddings
-- are.
isEmbedding : (A → B) → Type _
isEmbedding f = ∀ w x → isEquiv {A = w ≡ x} (cong f)
isPropIsEmbedding : isProp (isEmbedding f)
isPropIsEmbedding {f = f} = isPropΠ2 λ _ _ → isPropIsEquiv (cong f)
-- If A and B are h-sets, then injective functions between
-- them are embeddings.
--
-- Note: It doesn't appear to be possible to omit either of
-- the `isSet` hypotheses.
injEmbedding
: {f : A → B}
→ isSet A → isSet B
→ (∀{w x} → f w ≡ f x → w ≡ x)
→ isEmbedding f
injEmbedding {f = f} iSA iSB inj w x
= isoToIsEquiv (iso (cong f) inj sect retr)
where
sect : section (cong f) inj
sect p = iSB (f w) (f x) _ p
retr : retract (cong f) inj
retr p = iSA w x _ p
-- If `f` is an embedding, we'd expect the fibers of `f` to be
-- propositions, like an injective function.
hasPropFibers : (A → B) → Type _
hasPropFibers f = ∀ y → isProp (fiber f y)
-- This can be relaxed to having all prop fibers over the image, see [hasPropFibersOfImage→isEmbedding]
hasPropFibersOfImage : (A → B) → Type _
hasPropFibersOfImage f = ∀ x → isProp (fiber f (f x))
-- some notation
_↪_ : Type ℓ₁ → Type ℓ₂ → Type (ℓ-max ℓ₁ ℓ₂)
A ↪ B = Σ[ f ∈ (A → B) ] isEmbedding f
hasPropFibersIsProp : isProp (hasPropFibers f)
hasPropFibersIsProp = isPropΠ (λ _ → isPropIsProp)
private
lemma₀ : (p : y ≡ z) → fiber f y ≡ fiber f z
lemma₀ {f = f} p = λ i → fiber f (p i)
lemma₁ : isEmbedding f → ∀ x → isContr (fiber f (f x))
lemma₁ {f = f} iE x = value , path
where
value : fiber f (f x)
value = (x , refl)
path : ∀(fi : fiber f (f x)) → value ≡ fi
path (w , p) i
= case equiv-proof (iE w x) p of λ
{ ((q , sq) , _)
→ hfill (λ j → λ { (i = i0) → (x , refl)
; (i = i1) → (w , sq j)
})
(inS (q (~ i) , λ j → f (q (~ i ∨ j))))
i1
}
isEmbedding→hasPropFibers : isEmbedding f → hasPropFibers f
isEmbedding→hasPropFibers iE y (x , p)
= subst (λ f → isProp f) (lemma₀ p) (isContr→isProp (lemma₁ iE x)) (x , p)
private
fibCong→PathP
: {f : A → B}
→ (p : f w ≡ f x)
→ (fi : fiber (cong f) p)
→ PathP (λ i → fiber f (p i)) (w , refl) (x , refl)
fibCong→PathP p (q , r) i = q i , λ j → r j i
PathP→fibCong
: {f : A → B}
→ (p : f w ≡ f x)
→ (pp : PathP (λ i → fiber f (p i)) (w , refl) (x , refl))
→ fiber (cong f) p
PathP→fibCong p pp = (λ i → fst (pp i)) , (λ j i → snd (pp i) j)
PathP≡fibCong
: {f : A → B}
→ (p : f w ≡ f x)
→ PathP (λ i → fiber f (p i)) (w , refl) (x , refl) ≡ fiber (cong f) p
PathP≡fibCong p
= isoToPath (iso (PathP→fibCong p) (fibCong→PathP p) (λ _ → refl) (λ _ → refl))
hasPropFibers→isEmbedding : hasPropFibers f → isEmbedding f
hasPropFibers→isEmbedding {f = f} iP w x .equiv-proof p
= subst isContr (PathP≡fibCong p) (isProp→isContrPathP (λ i → iP (p i)) fw fx)
where
fw : fiber f (f w)
fw = (w , refl)
fx : fiber f (f x)
fx = (x , refl)
hasPropFibersOfImage→hasPropFibers : hasPropFibersOfImage f → hasPropFibers f
hasPropFibersOfImage→hasPropFibers {f = f} fibImg y a b =
subst (λ y → isProp (fiber f y)) (snd a) (fibImg (fst a)) a b
hasPropFibersOfImage→isEmbedding : hasPropFibersOfImage f → isEmbedding f
hasPropFibersOfImage→isEmbedding = hasPropFibers→isEmbedding ∘ hasPropFibersOfImage→hasPropFibers
isEmbedding≡hasPropFibers : isEmbedding f ≡ hasPropFibers f
isEmbedding≡hasPropFibers
= isoToPath
(iso isEmbedding→hasPropFibers
hasPropFibers→isEmbedding
(λ _ → hasPropFibersIsProp _ _)
(λ _ → isPropIsEmbedding _ _))
isEquiv→hasPropFibers : isEquiv f → hasPropFibers f
isEquiv→hasPropFibers e b = isContr→isProp (equiv-proof e b)
isEquiv→isEmbedding : isEquiv f → isEmbedding f
isEquiv→isEmbedding e = λ _ _ → congEquiv (_ , e) .snd
Equiv→Embedding : A ≃ B → A ↪ B
Equiv→Embedding (f , isEquivF) = (f , isEquiv→isEmbedding isEquivF)
iso→isEmbedding : ∀ {ℓ} {A B : Type ℓ}
→ (isom : Iso A B)
-------------------------------
→ isEmbedding (Iso.fun isom)
iso→isEmbedding {A = A} {B} isom = (isEquiv→isEmbedding (equivIsEquiv (isoToEquiv isom)))
isEmbedding→Injection :
∀ {ℓ} {A B C : Type ℓ}
→ (a : A → B)
→ (e : isEmbedding a)
----------------------
→ ∀ {f g : C → A} →
∀ x → (a (f x) ≡ a (g x)) ≡ (f x ≡ g x)
isEmbedding→Injection a e {f = f} {g} x = sym (ua (cong a , e (f x) (g x)))
-- if `f` has a retract, then `cong f` has, as well. If `B` is a set, then `cong f`
-- further has a section, making `f` an embedding.
module _ {f : A → B} (retf : hasRetract f) where
open Σ retf renaming (fst to g ; snd to ϕ)
congRetract : f w ≡ f x → w ≡ x
congRetract {w = w} {x = x} p = sym (ϕ w) ∙∙ cong g p ∙∙ ϕ x
isRetractCongRetract : retract (cong {x = w} {y = x} f) congRetract
isRetractCongRetract p = transport (PathP≡doubleCompPathˡ _ _ _ _) (λ i j → ϕ (p j) i)
hasRetract→hasRetractCong : hasRetract (cong {x = w} {y = x} f)
hasRetract→hasRetractCong = congRetract , isRetractCongRetract
retractableIntoSet→isEmbedding : isSet B → isEmbedding f
retractableIntoSet→isEmbedding setB w x =
isoToIsEquiv (iso (cong f) congRetract (λ _ → setB _ _ _ _) (hasRetract→hasRetractCong .snd))
Embedding-into-Discrete→Discrete : A ↪ B → Discrete B → Discrete A
Embedding-into-Discrete→Discrete (f , isEmbeddingF) _≟_ x y with f x ≟ f y
... | yes p = yes (invIsEq (isEmbeddingF x y) p)
... | no ¬p = no (¬p ∘ cong f)
Embedding-into-isProp→isProp : A ↪ B → isProp B → isProp A
Embedding-into-isProp→isProp (f , isEmbeddingF) isProp-B x y
= invIsEq (isEmbeddingF x y) (isProp-B (f x) (f y))
Embedding-into-isSet→isSet : A ↪ B → isSet B → isSet A
Embedding-into-isSet→isSet (f , isEmbeddingF) isSet-B x y p q =
p ≡⟨ sym (retIsEq isEquiv-cong-f p) ⟩
cong-f⁻¹ (cong f p) ≡⟨ cong cong-f⁻¹ cong-f-p≡cong-f-q ⟩
cong-f⁻¹ (cong f q) ≡⟨ retIsEq isEquiv-cong-f q ⟩
q ∎
where
cong-f-p≡cong-f-q = isSet-B (f x) (f y) (cong f p) (cong f q)
isEquiv-cong-f = isEmbeddingF x y
cong-f⁻¹ = invIsEq isEquiv-cong-f
Embedding-into-hLevel→hLevel
: ∀ n → A ↪ B → isOfHLevel (suc n) B → isOfHLevel (suc n) A
Embedding-into-hLevel→hLevel zero = Embedding-into-isProp→isProp
Embedding-into-hLevel→hLevel (suc n) (f , isEmbeddingF) Blvl x y
= isOfHLevelRespectEquiv (suc n) (invEquiv equiv) subLvl
where
equiv : (x ≡ y) ≃ (f x ≡ f y)
equiv .fst = cong f
equiv .snd = isEmbeddingF x y
subLvl : isOfHLevel (suc n) (f x ≡ f y)
subLvl = Blvl (f x) (f y)
-- We now show that the powerset is the subtype classifier
-- i.e. ℙ X ≃ Σ[A ∈ Type ℓ] (A ↪ X)
Embedding→Subset : {X : Type ℓ} → Σ[ A ∈ Type ℓ ] (A ↪ X) → ℙ X
Embedding→Subset (_ , f , isEmbeddingF) x = fiber f x , isEmbedding→hasPropFibers isEmbeddingF x
Subset→Embedding : {X : Type ℓ} → ℙ X → Σ[ A ∈ Type ℓ ] (A ↪ X)
Subset→Embedding {X = X} A = D , fst , Ψ
where
D = Σ[ x ∈ X ] x ∈ A
Ψ : isEmbedding fst
Ψ w x = isEmbeddingFstΣProp (∈-isProp A)
Subset→Embedding→Subset : {X : Type ℓ} → section (Embedding→Subset {ℓ} {X}) (Subset→Embedding {ℓ} {X})
Subset→Embedding→Subset _ = funExt λ x → Σ≡Prop (λ _ → isPropIsProp) (ua (FiberIso.fiberEquiv _ x))
Embedding→Subset→Embedding : {X : Type ℓ} → retract (Embedding→Subset {ℓ} {X}) (Subset→Embedding {ℓ} {X})
Embedding→Subset→Embedding {ℓ = ℓ} {X = X} (A , f , ψ) =
cong (equivFun Σ-assoc-≃) (Σ≡Prop (λ _ → isPropIsEmbedding) (retEq (fibrationEquiv X ℓ) (A , f)))
Subset≃Embedding : {X : Type ℓ} → ℙ X ≃ (Σ[ A ∈ Type ℓ ] (A ↪ X))
Subset≃Embedding = isoToEquiv (iso Subset→Embedding Embedding→Subset
Embedding→Subset→Embedding Subset→Embedding→Subset)
Subset≡Embedding : {X : Type ℓ} → ℙ X ≡ (Σ[ A ∈ Type ℓ ] (A ↪ X))
Subset≡Embedding = ua Subset≃Embedding
isEmbedding-∘ : isEmbedding f → isEmbedding h → isEmbedding (f ∘ h)
isEmbedding-∘ {f = f} {h = h} Embf Embh w x
= compEquiv (cong h , Embh w x) (cong f , Embf (h w) (h x)) .snd
isEmbedding→embedsFibersIntoSingl
: isEmbedding f
→ ∀ z → fiber f z ↪ singl z
isEmbedding→embedsFibersIntoSingl {f = f} isE z = e , isEmbE where
e : fiber f z → singl z
e x = f (fst x) , sym (snd x)
isEmbE : isEmbedding e
isEmbE u v = goal where
-- "adjust" ΣeqCf by trivial equivalences that hold judgementally, which should save compositions
Dom′ : ∀ u v → Type _
Dom′ u v = Σ[ p ∈ fst u ≡ fst v ] PathP (λ i → f (p i) ≡ z) (snd u) (snd v)
Cod′ : ∀ u v → Type _
Cod′ u v = Σ[ p ∈ f (fst u) ≡ f (fst v) ] PathP (λ i → p i ≡ z) (snd u) (snd v)
ΣeqCf : Dom′ u v ≃ Cod′ u v
ΣeqCf = Σ-cong-equiv-fst (_ , isE _ _)
dom→ : u ≡ v → Dom′ u v
dom→ p = cong fst p , cong snd p
dom← : Dom′ u v → u ≡ v
dom← p i = p .fst i , p .snd i
cod→ : e u ≡ e v → Cod′ u v
cod→ p = cong fst p , cong (sym ∘ snd) p
cod← : Cod′ u v → e u ≡ e v
cod← p i = p .fst i , sym (p .snd i)
goal : isEquiv (cong e)
goal .equiv-proof x .fst .fst =
dom← (equivCtr ΣeqCf (cod→ x) .fst)
goal .equiv-proof x .fst .snd j =
cod← (equivCtr ΣeqCf (cod→ x) .snd j)
goal .equiv-proof x .snd (g , p) i .fst =
dom← (equivCtrPath ΣeqCf (cod→ x) (dom→ g , cong cod→ p) i .fst)
goal .equiv-proof x .snd (g , p) i .snd j =
cod← (equivCtrPath ΣeqCf (cod→ x) (dom→ g , cong cod→ p) i .snd j)
isEmbedding→hasPropFibers′ : isEmbedding f → hasPropFibers f
isEmbedding→hasPropFibers′ {f = f} iE z =
Embedding-into-isProp→isProp (isEmbedding→embedsFibersIntoSingl iE z) isPropSingl
universeEmbedding :
∀ {ℓ ℓ₁ : Level}
→ (F : Type ℓ → Type ℓ₁)
→ (∀ X → F X ≃ X)
→ isEmbedding F
universeEmbedding F liftingEquiv = hasPropFibersOfImage→isEmbedding propFibersF where
lemma : ∀ A B → (F A ≡ F B) ≃ (B ≡ A)
lemma A B = (F A ≡ F B) ≃⟨ univalence ⟩
(F A ≃ F B) ≃⟨ equivComp (liftingEquiv A) (liftingEquiv B) ⟩
(A ≃ B) ≃⟨ invEquivEquiv ⟩
(B ≃ A) ≃⟨ invEquiv univalence ⟩
(B ≡ A) ■
fiberSingl : ∀ X → fiber F (F X) ≃ singl X
fiberSingl X = Σ-cong-equiv-snd (λ _ → lemma _ _)
propFibersF : hasPropFibersOfImage F
propFibersF X = Embedding-into-isProp→isProp (Equiv→Embedding (fiberSingl X)) isPropSingl
liftEmbedding : (ℓ ℓ₁ : Level)
→ isEmbedding (Lift {i = ℓ} {j = ℓ₁})
liftEmbedding ℓ ℓ₁ = universeEmbedding (Lift {j = ℓ₁}) (λ _ → invEquiv LiftEquiv)
module FibrationIdentityPrinciple {B : Type ℓ} {ℓ₁} where
-- note that fibrationEquiv (for good reason) uses ℓ₁ = ℓ-max ℓ ℓ₁, so we have to work
-- some universe magic to achieve good universe polymorphism
-- First, prove it for the case that's dealt with in fibrationEquiv
Fibration′ = Fibration B (ℓ-max ℓ ℓ₁)
module Lifted (f g : Fibration′) where
f≃g′ : Type (ℓ-max ℓ ℓ₁)
f≃g′ = ∀ b → fiber (f .snd) b ≃ fiber (g .snd) b
Fibration′IP : f≃g′ ≃ (f ≡ g)
Fibration′IP =
f≃g′
≃⟨ equivΠCod (λ _ → invEquiv univalence) ⟩
(∀ b → fiber (f .snd) b ≡ fiber (g .snd) b)
≃⟨ funExtEquiv ⟩
fiber (f .snd) ≡ fiber (g .snd)
≃⟨ invEquiv (congEquiv (fibrationEquiv B ℓ₁)) ⟩
f ≡ g
■
-- Then embed into the above case by lifting the type
L : Type _ → Type _ -- local synonym fixing the levels of Lift
L = Lift {i = ℓ₁} {j = ℓ}
liftFibration : Fibration B ℓ₁ → Fibration′
liftFibration (A , f) = L A , f ∘ lower
hasPropFibersLiftFibration : hasPropFibers liftFibration
hasPropFibersLiftFibration (A , f) =
Embedding-into-isProp→isProp (Equiv→Embedding fiberChar)
(isPropΣ (isEmbedding→hasPropFibers (liftEmbedding _ _) A)
λ _ → isEquiv→hasPropFibers (snd (invEquiv (preCompEquiv LiftEquiv))) _)
where
fiberChar : fiber liftFibration (A , f)
≃ (Σ[ (E , eq) ∈ fiber L A ] fiber (_∘ lower) (transport⁻ (λ i → eq i → B) f))
fiberChar =
fiber liftFibration (A , f)
≃⟨ Σ-cong-equiv-snd (λ _ → invEquiv ΣPath≃PathΣ) ⟩
(Σ[ (E , g) ∈ Fibration B ℓ₁ ] Σ[ eq ∈ (L E ≡ A) ] PathP (λ i → eq i → B) (g ∘ lower) f)
≃⟨ boringSwap ⟩
(Σ[ (E , eq) ∈ fiber L A ] Σ[ g ∈ (E → B) ] PathP (λ i → eq i → B) (g ∘ lower) f)
≃⟨ Σ-cong-equiv-snd (λ _ → Σ-cong-equiv-snd λ _ → transportEquiv (PathP≡Path⁻ _ _ _)) ⟩
(Σ[ (E , eq) ∈ fiber L A ] fiber (_∘ lower) (transport⁻ (λ i → eq i → B) f))
■ where
unquoteDecl boringSwap =
declStrictEquiv boringSwap
(λ ((E , g) , (eq , p)) → ((E , eq) , (g , p)))
(λ ((E , g) , (eq , p)) → ((E , eq) , (g , p)))
isEmbeddingLiftFibration : isEmbedding liftFibration
isEmbeddingLiftFibration = hasPropFibers→isEmbedding hasPropFibersLiftFibration
-- and finish off
module _ (f g : Fibration B ℓ₁) where
open Lifted (liftFibration f) (liftFibration g)
f≃g : Type (ℓ-max ℓ ℓ₁)
f≃g = ∀ b → fiber (f .snd) b ≃ fiber (g .snd) b
FibrationIP : f≃g ≃ (f ≡ g)
FibrationIP =
f≃g ≃⟨ equivΠCod (λ b → equivComp (Σ-cong-equiv-fst LiftEquiv)
(Σ-cong-equiv-fst LiftEquiv)) ⟩
f≃g′ ≃⟨ Fibration′IP ⟩
(liftFibration f ≡ liftFibration g) ≃⟨ invEquiv (_ , isEmbeddingLiftFibration _ _) ⟩
(f ≡ g) ■
open FibrationIdentityPrinciple renaming (f≃g to _≃Fib_) using (FibrationIP) public
Embedding : (B : Type ℓ₁) → (ℓ : Level) → Type (ℓ-max ℓ₁ (ℓ-suc ℓ))
Embedding B ℓ = Σ[ A ∈ Type ℓ ] A ↪ B
module EmbeddingIdentityPrinciple {B : Type ℓ} {ℓ₁} (f g : Embedding B ℓ₁) where
module _ where
open Σ f renaming (fst to F) public
open Σ g renaming (fst to G) public
open Σ (f .snd) renaming (fst to ffun; snd to isEmbF) public
open Σ (g .snd) renaming (fst to gfun; snd to isEmbG) public
f≃g : Type _
f≃g = (∀ b → fiber ffun b → fiber gfun b) ×
(∀ b → fiber gfun b → fiber ffun b)
toFibr : Embedding B ℓ₁ → Fibration B ℓ₁
toFibr (A , (f , _)) = (A , f)
isEmbeddingToFibr : isEmbedding toFibr
isEmbeddingToFibr w x = fullEquiv .snd where
-- carefully managed such that (cong toFibr) is the equivalence
fullEquiv : (w ≡ x) ≃ (toFibr w ≡ toFibr x)
fullEquiv = compEquiv (congEquiv (invEquiv Σ-assoc-≃)) (invEquiv (Σ≡PropEquiv (λ _ → isPropIsEmbedding)))
EmbeddingIP : f≃g ≃ (f ≡ g)
EmbeddingIP =
f≃g
≃⟨ strictIsoToEquiv (invIso toProdIso) ⟩
(∀ b → (fiber ffun b → fiber gfun b) × (fiber gfun b → fiber ffun b))
≃⟨ equivΠCod (λ _ → isEquivPropBiimpl→Equiv (isEmbedding→hasPropFibers isEmbF _)
(isEmbedding→hasPropFibers isEmbG _)) ⟩
(∀ b → (fiber (f .snd .fst) b) ≃ (fiber (g .snd .fst) b))
≃⟨ FibrationIP (toFibr f) (toFibr g) ⟩
(toFibr f ≡ toFibr g)
≃⟨ invEquiv (_ , isEmbeddingToFibr _ _) ⟩
f ≡ g
■
open EmbeddingIdentityPrinciple renaming (f≃g to _≃Emb_) using (EmbeddingIP) public
| 37.401869
| 109
| 0.61488
|
380b21d657fefc305b5b999bf062a89221a4c0dd
| 7,300
|
agda
|
Agda
|
Cubical/Papers/Synthetic.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Papers/Synthetic.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Papers/Synthetic.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Papers.Synthetic where
-- Cubical synthetic homotopy theory
-- Mörtberg and Pujet, „Cubical synthetic homotopy theory“.
-- https://dl.acm.org/doi/abs/10.1145/3372885.3373825
-- 2.1
import Agda.Builtin.Cubical.Path as Path
import Cubical.Foundations.Prelude as Prelude
-- 2.2
import Agda.Primitive.Cubical as PrimitiveCubical
import Cubical.Data.Bool as Bool
import Cubical.Core.Primitives as CorePrimitives
-- 2.3
import Cubical.HITs.S1 as S1
-- 2.4
import Cubical.Foundations.Equiv as Equiv
import Cubical.Core.Glue as CoreGlue
import Cubical.Foundations.Univalence as Univalence
-- 3.
import Cubical.HITs.Torus as T2
-- 3.1
import Cubical.Data.Int as Int
import Cubical.Data.Int.Properties as IntProp
import Cubical.Foundations.Isomorphism as Isomorphism
-- 4.1
import Cubical.HITs.Susp as Suspension
import Cubical.HITs.Sn as Sn
import Agda.Builtin.Nat as BNat
import Agda.Builtin.Bool as BBool
import Cubical.Foundations.GroupoidLaws as GroupoidLaws
import Cubical.HITs.S2 as S2
import Cubical.HITs.S3 as S3
-- 4.2
import Cubical.HITs.Pushout as Push
import Cubical.HITs.Pushout.Properties as PushProp
-- 4.3
import Cubical.HITs.Join as Join
import Cubical.HITs.Join.Properties as JoinProp
-- 5.
import Cubical.HITs.Hopf as Hopf
--------------------------------------------------------------------------------
-- 2. Cubical Agda
-- 2.1 The Interval and Path Types
-- 2.2 Transport and Composition
-- 2.3 Higher Inductive Types
-- 2.4 Glue Types and Univalence
--------------------------------------------------------------------------------
-- 2.1 The Interval and Path Types
open Path using (PathP) public
open Prelude using (_≡_ ; refl ; funExt) public
open Prelude renaming (sym to _⁻¹) public
-- 2.2 Transport and Composition
open Prelude using (transport ; subst ; J ; JRefl) public
open PrimitiveCubical using (Partial) public
open Bool using (Bool ; true ; false) public
partialBool : ∀ i → Partial (i ∨ ~ i) Bool
partialBool i = λ {(i = i1) → true
; (i = i0) → false}
open CorePrimitives using (inS ; outS ; hcomp) public
open Prelude using (_∙_) public
-- 2.3 Higher Inductive Types
open S1 using (S¹ ; base ; loop) public
double : S¹ → S¹
double base = base
double (loop i) = (loop ∙ loop) i
-- 2.4 Glue Types and Univalence
open Equiv using (idEquiv) public
open CoreGlue using (Glue) public
open Univalence using (ua) public
--------------------------------------------------------------------------------
-- 3. The Circle and Torus
-- 3.1 The Loop Spaces of the Circle and Torus
--------------------------------------------------------------------------------
open T2 using ( Torus ; point ; line1 ; line2 ; square
; t2c ; c2t ; c2t-t2c ; t2c-c2t ; Torus≡S¹×S¹)
-- 3.1 The Loop Spaces of the Circle and Torus
open S1 using (ΩS¹) public
open T2 using (ΩTorus) public
open Int using (Int ; pos ; negsuc) public
open IntProp using (sucPathInt) public
open S1 using (helix ; winding) public
-- Examples computing the winding numbers of the circle
_ : winding (loop ∙ loop ∙ loop) ≡ pos 3
_ = refl
_ : winding ((loop ⁻¹) ∙ loop ∙ (loop ⁻¹)) ≡ negsuc 0
_ = refl
open S1 renaming (intLoop to loopn) public
open S1 renaming (windingIntLoop to winding-loopn) public
open S1 using (encode ; decode ; decodeEncode ; ΩS¹≡Int) public
open Isomorphism using (isoToPath ; iso) public
-- Notation of the paper, current notation under ΩS¹≡Int
ΩS¹≡Int' : ΩS¹ ≡ Int
ΩS¹≡Int' = isoToPath (iso winding loopn
winding-loopn (decodeEncode base))
open T2 using (ΩTorus≡Int×Int ; windingTorus) public
-- Examples at the end of section 3.
_ : windingTorus (line1 ∙ line2) ≡ (pos 1 , pos 1)
_ = refl
_ : windingTorus ((line1 ⁻¹) ∙ line2 ∙ line1) ≡ (pos 0 , pos 1)
_ = refl
--------------------------------------------------------------------------------
-- 4. Suspension, Spheres and Pushouts
-- 4.1 Suspension
-- 4.2 Pushouts and the 3 × 3 Lemma
-- 4.3 The Join and S³
--------------------------------------------------------------------------------
-- 4.1 Suspension
open Suspension using (Susp ; north ; south ; merid) public
open Sn using (S₊) public
open Suspension using ( SuspBool→S¹ ; S¹→SuspBool
; SuspBool→S¹→SuspBool
; S¹→SuspBool→S¹) public
-- Deprecated version of S₊
open BNat renaming (Nat to ℕ) hiding (_*_) public
open CorePrimitives renaming (Type to Set) public
open BBool using (Bool) public
-- At the time the paper was published, Set was used instead of Type
_-sphere : ℕ → Set
0 -sphere = Bool
(suc n) -sphere = Susp (n -sphere)
-- Lemma 4.1. The (1)-sphere is equal to the circle S1.
open BBool using (true ; false) public
-- Deprecated version of SuspBool→S¹
s2c : 1 -sphere → S¹
s2c north = base
s2c south = base
s2c (merid true i) = loop i
s2c (merid false i) = base -- (loop ⁻¹) i
-- Deprecated version of S¹→SuspBool
c2s : S¹ → 1 -sphere
c2s base = north
c2s (loop i) = (merid true ∙ (merid false ⁻¹)) i
open GroupoidLaws using (rUnit) public
-- Deprecated version of SuspBool→S¹→SuspBool
s2c-c2s : ∀ (p : S¹) → s2c (c2s p) ≡ p
s2c-c2s base = refl
s2c-c2s (loop i) j = rUnit loop (~ j) i
h1 : I → I → 1 -sphere
h1 i j = merid false (i ∧ j)
h2 : I → I → 1 -sphere
h2 i j = hcomp (λ k → λ { (i = i0) → north
; (i = i1) → merid false (j ∨ ~ k)
; (j = i1) → merid true i })
(merid true i)
-- Deprecated version of S¹→SuspBool→S¹
c2s-s2c : ∀ (t : 1 -sphere) → c2s (s2c t) ≡ t
c2s-s2c north j = north
c2s-s2c south j = merid false j
c2s-s2c (merid true i) j = h2 i j
c2s-s2c (merid false i) j = merid false (i ∧ j)
-- Notation of the paper, current notation under S¹≡SuspBool
-- Proof of Lemma 4.1
1-sphere≡S¹ : 1 -sphere ≡ S¹
1-sphere≡S¹ = isoToPath (iso s2c c2s s2c-c2s c2s-s2c)
-- Definitions of S2 and S3
open S2 using (S²) public
open S3 using (S³) public
-- 4.2 Pushouts and the 3 × 3 Lemma
open Push using (Pushout) public
-- 3x3-span is implemented as a record
open PushProp using (3x3-span) public
open 3x3-span using (f□1) public
-- The rest of the definitions inside the 3x3-lemma
-- A□0-A○□ , A□○-A○□ ...
open 3x3-span using (3x3-lemma) public
-- 4.3 The Join and S³
open Join renaming (join to Join) using (S³≡joinS¹S¹) public
open JoinProp using (join-assoc) public
--------------------------------------------------------------------------------
-- 5. The Hopf Fibration
--------------------------------------------------------------------------------
-- rot (denoted by _·_ here) in the paper is substituted by a rot and rotLoop in S1
open S1 using (_·_ ; rotLoop) public
open Hopf renaming ( HopfSuspS¹ to Hopf
; JoinS¹S¹→TotalHopf to j2h
; TotalHopf→JoinS¹S¹ to h2j)
using (HopfS²) public
open S1 renaming (rotInv-1 to lem-rot-inv) public
| 33.953488
| 83
| 0.589178
|
1417e8e6f3e4e16788183d379aaf4fdd597bde54
| 4,816
|
agda
|
Agda
|
examples/outdated-and-incorrect/tait/Subst.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/outdated-and-incorrect/tait/Subst.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/outdated-and-incorrect/tait/Subst.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Subst where
open import Prelude
open import Lambda
infix 100 _[_] _[_:=_] _↑
infixl 100 _↑_ _↑ˢ_ _↑ˣ_ _↓ˣ_
infixl 60 _-_
{-
_-_ : {τ : Type}(Γ : Ctx) -> Var Γ τ -> Ctx
ε - ()
Γ , τ - vz = Γ
Γ , τ - vs x = (Γ - x) , τ
wkˣ : {Γ : Ctx}{σ τ : Type}
(x : Var Γ σ) -> Var (Γ - x) τ -> Var Γ τ
wkˣ vz y = vs y
wkˣ (vs x) vz = vz
wkˣ (vs x) (vs y) = vs (wkˣ x y)
wk : {Γ : Ctx}{σ τ : Type}
(x : Var Γ σ) -> Term (Γ - x) τ -> Term Γ τ
wk x (var y) = var (wkˣ x y)
wk x (s • t) = wk x s • wk x t
wk x (ƛ t) = ƛ wk (vs x) t
_↑ : {Γ : Ctx}{σ τ : Type} -> Term Γ τ -> Term (Γ , σ) τ
t ↑ = wk vz t
_↑_ : {Γ : Ctx}{τ : Type} -> Term Γ τ -> (Δ : Ctx) -> Term (Γ ++ Δ) τ
t ↑ ε = t
t ↑ (Δ , σ) = (t ↑ Δ) ↑
data Cmpˣ {Γ : Ctx}{τ : Type}(x : Var Γ τ) :
{σ : Type} -> Var Γ σ -> Set where
same : Cmpˣ x x
diff : {σ : Type}(y : Var (Γ - x) σ) -> Cmpˣ x (wkˣ x y)
_≟_ : {Γ : Ctx}{σ τ : Type}(x : Var Γ σ)(y : Var Γ τ) -> Cmpˣ x y
vz ≟ vz = same
vz ≟ vs y = diff y
vs x ≟ vz = diff vz
vs x ≟ vs y with x ≟ y
vs x ≟ vs .x | same = same
vs x ≟ vs .(wkˣ x y) | diff y = diff (vs y)
_[_:=_] : {Γ : Ctx}{σ τ : Type} ->
Term Γ σ -> (x : Var Γ τ) -> Term (Γ - x) τ ->
Term (Γ - x) σ
var y [ x := u ] with x ≟ y
var .x [ x := u ] | same = u
var .(wkˣ x y) [ x := u ] | diff y = var y
(s • t) [ x := u ] = s [ x := u ] • t [ x := u ]
(ƛ t) [ x := u ] = ƛ t [ vs x := u ↑ ]
-}
infix 30 _─⟶_
infixl 90 _/_
_─⟶_ : Ctx -> Ctx -> Set
Γ ─⟶ Δ = Terms Γ Δ
idS : forall {Γ} -> Γ ─⟶ Γ
idS = tabulate var
infixr 80 _∘ˢ_
[_] : forall {Γ σ } -> Term Γ σ -> Γ ─⟶ Γ , σ
[ t ] = idS ◄ t
wkS : forall {Γ Δ τ} -> Γ ─⟶ Δ -> Γ , τ ─⟶ Δ
wkS ∅ = ∅
wkS (θ ◄ t) = wkS θ ◄ wk t
_↑ : forall {Γ Δ τ} -> (Γ ─⟶ Δ) -> Γ , τ ─⟶ Δ , τ
θ ↑ = wkS θ ◄ vz
_/_ : forall {Γ Δ τ} -> Term Δ τ -> Γ ─⟶ Δ -> Term Γ τ
vz / (θ ◄ u) = u
wk t / (θ ◄ u) = t / θ
(s • t) / θ = s / θ • t / θ
(ƛ t) / θ = ƛ t / θ ↑
_∘ˢ_ : forall {Γ Δ Θ} -> Δ ─⟶ Θ -> Γ ─⟶ Δ -> Γ ─⟶ Θ
∅ ∘ˢ θ = ∅
(δ ◄ t) ∘ˢ θ = δ ∘ˢ θ ◄ t / θ
inj : forall {Γ Δ τ} Θ -> Term Γ τ -> Γ ─⟶ Δ ++ Θ -> Γ ─⟶ Δ , τ ++ Θ
inj ε t θ = θ ◄ t
inj (Θ , σ) t (θ ◄ u) = inj Θ t θ ◄ u
[_⟵_] : forall {Γ τ} Δ -> Term (Γ ++ Δ) τ -> Γ ++ Δ ─⟶ Γ , τ ++ Δ
[ Δ ⟵ t ] = inj Δ t idS
_↑_ : forall {Γ σ} -> Term Γ σ -> (Δ : Ctx) -> Term (Γ ++ Δ) σ
t ↑ ε = t
t ↑ (Δ , τ) = wk (t ↑ Δ)
_↑ˢ_ : forall {Γ Δ} -> Terms Γ Δ -> (Θ : Ctx) -> Terms (Γ ++ Θ) Δ
∅ ↑ˢ Θ = ∅
(ts ◄ t) ↑ˢ Θ = ts ↑ˢ Θ ◄ t ↑ Θ
_↑ˣ_ : forall {Γ τ} -> Var Γ τ -> (Δ : Ctx) -> Var (Γ ++ Δ) τ
x ↑ˣ ε = x
x ↑ˣ (Δ , σ) = vsuc (x ↑ˣ Δ)
lem-var-↑ˣ : forall {Γ τ}(x : Var Γ τ)(Δ : Ctx) ->
var (x ↑ˣ Δ) ≡ var x ↑ Δ
lem-var-↑ˣ x ε = refl
lem-var-↑ˣ x (Δ , σ) = cong wk (lem-var-↑ˣ x Δ)
{- Not true!
lem-•-↑ : forall {Γ σ τ}(t : Term Γ (σ ⟶ τ))(u : Term Γ σ) Δ ->
(t ↑ Δ) • (u ↑ Δ) ≡ (t • u) ↑ Δ
lem-•-↑ t u ε = refl
lem-•-↑ t u (Δ , δ) = {! !}
lem-•ˢ-↑ : forall {Γ Θ τ}(t : Term Γ (Θ ⇒ τ))(ts : Terms Γ Θ) Δ ->
(t ↑ Δ) •ˢ (ts ↑ˢ Δ) ≡ (t •ˢ ts) ↑ Δ
lem-•ˢ-↑ t ∅ Δ = refl
lem-•ˢ-↑ t (u ◄ us) Δ = {! !}
-}
{-
_[_] : {Γ : Ctx}{σ τ : Type} ->
Term (Γ , τ) σ -> Term Γ τ -> Term Γ σ
t [ u ] = t / [ u ]
-}
{-
vz [ u ] = u
wk t [ u ] = {! !}
(s • t) [ u ] = {! !}
(ƛ_ {τ = ρ} t) [ u ] = ƛ {! !}
-}
{-
_↓ˣ_ : {Γ : Ctx}{σ τ : Type}
(y : Var Γ σ)(x : Var (Γ - y) τ) -> Var (Γ - wkˣ y x) σ
vz ↓ˣ x = vz
vs y ↓ˣ vz = y
vs y ↓ˣ vs x = vs (y ↓ˣ x)
lem-commute-minus :
{Γ : Ctx}{σ τ : Type}(y : Var Γ σ)(x : Var (Γ - y) τ) ->
Γ - y - x ≡ Γ - wkˣ y x - (y ↓ˣ x)
lem-commute-minus vz x = refl
lem-commute-minus (vs y) vz = refl
lem-commute-minus (vs {Γ} y) (vs x) with Γ - y - x | lem-commute-minus y x
... | ._ | refl = refl
Lem-wk-[] :
{Γ : Ctx}{τ σ ρ : Type}
(y : Var Γ τ)
(x : Var (Γ - y) σ)
(t : Term (Γ - wkˣ y x) ρ)
(u : Term (Γ - y - x) τ) -> Set
Lem-wk-[] {Γ}{τ}{σ}{ρ} y x t u =
wk (wkˣ y x) t [ y := wk x u ]
≡ wk x t[u']'
where
u' : Term (Γ - wkˣ y x - y ↓ˣ x) τ
u' = subst (\Δ -> Term Δ τ) (sym (lem-commute-minus y x)) u
t[u']' : Term (Γ - y - x) ρ
t[u']' = subst (\Δ -> Term Δ ρ) (lem-commute-minus y x)
(t [ y ↓ˣ x := u' ])
postulate
lem-wk-[] : {Γ : Ctx}{σ τ ρ : Type}
(y : Var Γ τ)(x : Var (Γ - y) σ)
(t : Term (Γ - wkˣ y x) ρ){u : Term (Γ - y - x) τ} ->
Lem-wk-[] y x t u
{-
lem-wk-[] y x (var z) = {! !}
lem-wk-[] y x (t • u) = {! !}
lem-wk-[] y x (ƛ t) = {! !}
-}
lem-wk-[]' : {Γ : Ctx}{σ τ ρ : Type}
(x : Var Γ σ)(t : Term (Γ - x , ρ) τ){u : Term (Γ - x) ρ} ->
wk x (t [ vz := u ]) ≡ wk (vs x) t [ vz := wk x u ]
lem-wk-[]' x t = sym (lem-wk-[] vz x t)
-}
| 25.481481
| 74
| 0.387666
|
117337f24827294f582c8be9cf555968abf3ad9f
| 90
|
agda
|
Agda
|
test/fail/Negative3.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/fail/Negative3.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/Negative3.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module Negative3 where
data Mu (F : Set -> Set) : Set where
inn : F (Mu F) -> Mu F
| 12.857143
| 36
| 0.566667
|
1e83559beba85c7dcd839d11e1c84127d2140792
| 4,599
|
agda
|
Agda
|
Functions/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Functions/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Functions/Lemmas.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Functions.Definition
module Functions.Lemmas where
invertibleImpliesBijection : {a b : _} {A : Set a} {B : Set b} {f : A → B} → Invertible f → Bijection f
Bijection.inj (invertibleImpliesBijection {a} {b} {A} {B} {f} record { inverse = inverse ; isLeft = isLeft ; isRight = isRight }) {x} {y} fx=fy = ans
where
bl : inverse (f x) ≡ inverse (f y)
bl = applyEquality inverse fx=fy
ans : x ≡ y
ans rewrite equalityCommutative (isRight x) | equalityCommutative (isRight y) = bl
Bijection.surj (invertibleImpliesBijection {a} {b} {A} {B} {f} record { inverse = inverse ; isLeft = isLeft ; isRight = isRight }) y = (inverse y , isLeft y)
bijectionImpliesInvertible : {a b : _} {A : Set a} {B : Set b} {f : A → B} → Bijection f → Invertible f
Invertible.inverse (bijectionImpliesInvertible record { inj = inj ; surj = surj }) b = underlying (surj b)
Invertible.isLeft (bijectionImpliesInvertible {f = f} record { inj = inj ; surj = surj }) b with surj b
Invertible.isLeft (bijectionImpliesInvertible {f = f} record { inj = inj ; surj = surj }) b | a , prop = prop
Invertible.isRight (bijectionImpliesInvertible {f = f} record { inj = inj ; surj = surj }) a with surj (f a)
Invertible.isRight (bijectionImpliesInvertible {f = f} record { inj = property ; surj = surj }) a | a₁ , b = property b
injComp : {a b c : _} {A : Set a} {B : Set b} {C : Set c} {f : A → B} {g : B → C} → Injection f → Injection g → Injection (g ∘ f)
injComp {f = f} {g} propF propG pr = propF (propG pr)
surjComp : {a b c : _} {A : Set a} {B : Set b} {C : Set c} {f : A → B} {g : B → C} → Surjection f → Surjection g → Surjection (g ∘ f)
surjComp {f = f} {g} propF propG c with propG c
surjComp {f = f} {g} propF propG c | b , pr with propF b
surjComp {f = f} {g} propF propG c | b , pr | a , pr2 = a , pr'
where
pr' : g (f a) ≡ c
pr' rewrite pr2 = pr
bijectionComp : {a b c : _} {A : Set a} {B : Set b} {C : Set c} {f : A → B} {g : B → C} → Bijection f → Bijection g → Bijection (g ∘ f)
Bijection.inj (bijectionComp bijF bijG) = injComp (Bijection.inj bijF) (Bijection.inj bijG)
Bijection.surj (bijectionComp bijF bijG) = surjComp (Bijection.surj bijF) (Bijection.surj bijG)
compInjRightInj : {a b c : _} {A : Set a} {B : Set b} {C : Set c} {f : A → B} {g : B → C} → Injection (g ∘ f) → Injection f
compInjRightInj {f = f} {g} property {x} {y} fx=fy = property (applyEquality g fx=fy)
compSurjLeftSurj : {a b c : _} {A : Set a} {B : Set b} {C : Set c} {f : A → B} {g : B → C} → Surjection (g ∘ f) → Surjection g
compSurjLeftSurj {f = f} {g} property b with property b
compSurjLeftSurj {f = f} {g} property b | a , b1 = f a , b1
injectionPreservedUnderExtensionalEq : {a b : _} {A : Set a} {B : Set b} {f g : A → B} → Injection f → ({x : A} → f x ≡ g x) → Injection g
injectionPreservedUnderExtensionalEq {A = A} {B} {f} {g} property prop {x} {y} gx=gy = property (transitivity (prop {x}) (transitivity gx=gy (equalityCommutative (prop {y}))))
surjectionPreservedUnderExtensionalEq : {a b : _} {A : Set a} {B : Set b} {f g : A → B} → Surjection f → ({x : A} → f x ≡ g x) → Surjection g
surjectionPreservedUnderExtensionalEq {f = f} {g} surj ext b with surj b
surjectionPreservedUnderExtensionalEq {f = f} {g} surj ext b | a , pr = a , transitivity (equalityCommutative ext) pr
bijectionPreservedUnderExtensionalEq : {a b : _} {A : Set a} {B : Set b} {f g : A → B} → Bijection f → ({x : A} → f x ≡ g x) → Bijection g
Bijection.inj (bijectionPreservedUnderExtensionalEq record { inj = inj ; surj = surj } ext) = injectionPreservedUnderExtensionalEq inj ext
Bijection.surj (bijectionPreservedUnderExtensionalEq record { inj = inj ; surj = surj } ext) = surjectionPreservedUnderExtensionalEq surj ext
inverseIsInvertible : {a b : _} {A : Set a} {B : Set b} {f : A → B} → (inv : Invertible f) → Invertible (Invertible.inverse inv)
Invertible.inverse (inverseIsInvertible {f = f} inv) = f
Invertible.isLeft (inverseIsInvertible {f = f} inv) b = Invertible.isRight inv b
Invertible.isRight (inverseIsInvertible {f = f} inv) a = Invertible.isLeft inv a
idIsBijective : {a : _} {A : Set a} → Bijection (id {a} {A})
Bijection.inj idIsBijective pr = pr
Bijection.surj idIsBijective b = b , refl
functionCompositionExtensionallyAssociative : {a b c d : _} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → (f : A → B) → (g : B → C) → (h : C → D) → (x : A) → (h ∘ (g ∘ f)) x ≡ ((h ∘ g) ∘ f) x
functionCompositionExtensionallyAssociative f g h x = refl
| 65.7
| 195
| 0.646227
|
1b54de3c75a99b560f2685b2469e75acf8c92b87
| 2,587
|
agda
|
Agda
|
src/agda/FRP/JS/Float.agda
|
agda/agda-frp-js
|
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
|
[
"MIT",
"BSD-3-Clause"
] | 63
|
2015-04-20T21:47:00.000Z
|
2022-02-28T09:46:14.000Z
|
src/agda/FRP/JS/Float.agda
|
agda/agda-frp-js
|
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
|
[
"MIT",
"BSD-3-Clause"
] | null | null | null |
src/agda/FRP/JS/Float.agda
|
agda/agda-frp-js
|
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
|
[
"MIT",
"BSD-3-Clause"
] | 7
|
2016-11-07T21:50:58.000Z
|
2022-03-12T11:39:38.000Z
|
open import FRP.JS.Bool using ( Bool ; true ; false ; not ; _∨_ )
open import FRP.JS.True using ( True )
open import FRP.JS.Maybe using ( Maybe ; just ; nothing )
open import FRP.JS.Primitive using ( ℤ ; String )
module FRP.JS.Float where
infixr 4 _≤_ _<_ _≟_ _≠_
infixl 6 _+_ _-_
infixl 7 _*_ _/_ _/?_
open import FRP.JS.Primitive public using ( ℝ )
primitive
primFloatPlus : ℝ -> ℝ -> ℝ
primFloatMinus : ℝ -> ℝ -> ℝ
primFloatTimes : ℝ -> ℝ -> ℝ
primFloatDiv : ℝ -> ℝ -> ℝ
primFloatLess : ℝ -> ℝ -> Bool
primFloor : ℝ -> ℤ
primCeiling : ℝ -> ℤ
primExp : ℝ -> ℝ
primLog : ℝ -> ℝ
primSin : ℝ -> ℝ
primShowFloat : ℝ -> String
primShowInteger : ℤ → String
primIntegerToFloat : ℤ → ℝ
_+_ = primFloatPlus
_-_ = primFloatMinus
_*_ = primFloatTimes
_<_ = primFloatLess
⌊_⌋ = primFloor
⌈_⌉ = primCeiling
exp = primExp
log = primLog
sin = primSin
{-# COMPILED_JS _+_ function(x) { return function(y) { return x + y; }; } #-}
{-# COMPILED_JS _-_ function(x) { return function(y) { return x - y; }; } #-}
{-# COMPILED_JS _*_ function(x) { return function(y) { return x * y; }; } #-}
{-# COMPILED_JS _<_ function(x) { return function(y) { return x < y; }; } #-}
{-# COMPILED_JS ⌊_⌋ Math.floor #-}
{-# COMPILED_JS ⌈_⌉ Math.ceil #-}
{-# COMPILED_JS exp Math.exp #-}
{-# COMPILED_JS log Math.log #-}
{-# COMPILED_JS sin Math.sin #-}
-_ : ℝ → ℝ
- x = 0.0 - x
_≠_ : ℝ → ℝ → Bool
(x ≠ y) = (x < y) ∨ (y < x)
_≟_ : ℝ → ℝ → Bool
(x ≟ y) = not (x ≠ y)
_≤_ : ℝ → ℝ → Bool
(x ≤ y) = not (y < x)
-- Some hoop-jumping to avoid division by zero, so we don't end up with
-- Infinity, -Infinity or NaN.
_/_ : (x y : ℝ) → {y≠0 : True (y ≠ 0.0)} → ℝ
x / y = primFloatDiv x y
_/?_ : ℝ → ℝ → Maybe ℝ
x /? 0.0 = nothing
x /? y = just (primFloatDiv x y)
show : ℝ → String
show x
with (x ≟ primIntegerToFloat ⌊ x ⌋)
... | true = primShowInteger ⌊ x ⌋
... | false = primShowFloat x
{-# COMPILED_JS -_ function(x) { return -x; } #-}
{-# COMPILED_JS _≠_ function(x) { return function(y) { return x !== y; }; } #-}
{-# COMPILED_JS _≟_ function(x) { return function(y) { return x === y; }; } #-}
{-# COMPILED_JS _≤_ function(x) { return function(y) { return x <= y; }; } #-}
{-# COMPILED_JS _/_ function(x) { return function(y) { return function() { return x / y; }; }; } #-}
{-# COMPILED_JS _/?_ function(x) { return function(y) { if (y === 0) { return null; } else { return x / y; } }; } #-}
{-# COMPILED_JS show function(x) { return x.toString(); } #-}
| 30.081395
| 118
| 0.558949
|
14e2c120f0897cfc11a061ca54bc649c9014b5a8
| 17,002
|
agda
|
Agda
|
Cubical/Data/Int/Properties.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Data/Int/Properties.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Data/Int/Properties.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Data.Int.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Transport
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Empty
open import Cubical.Data.Nat
hiding (+-assoc ; +-comm ; ·-comm)
renaming (_·_ to _·ℕ_; _+_ to _+ℕ_ ; ·-assoc to ·ℕ-assoc)
open import Cubical.Data.Bool
open import Cubical.Data.Sum
open import Cubical.Data.Int.Base
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
sucPred : ∀ i → sucℤ (predℤ i) ≡ i
sucPred (pos zero) = refl
sucPred (pos (suc n)) = refl
sucPred (negsuc n) = refl
predSuc : ∀ i → predℤ (sucℤ i) ≡ i
predSuc (pos n) = refl
predSuc (negsuc zero) = refl
predSuc (negsuc (suc n)) = refl
injPos : ∀ {a b : ℕ} → pos a ≡ pos b → a ≡ b
injPos {a} h = subst T h refl
where
T : ℤ → Type₀
T (pos x) = a ≡ x
T (negsuc _) = ⊥
injNegsuc : ∀ {a b : ℕ} → negsuc a ≡ negsuc b → a ≡ b
injNegsuc {a} h = subst T h refl
where
T : ℤ → Type₀
T (pos _) = ⊥
T (negsuc x) = a ≡ x
posNotnegsuc : ∀ (a b : ℕ) → ¬ (pos a ≡ negsuc b)
posNotnegsuc a b h = subst T h 0
where
T : ℤ → Type₀
T (pos _) = ℕ
T (negsuc _) = ⊥
negsucNotpos : ∀ (a b : ℕ) → ¬ (negsuc a ≡ pos b)
negsucNotpos a b h = subst T h 0
where
T : ℤ → Type₀
T (pos _) = ⊥
T (negsuc _) = ℕ
discreteℤ : Discrete ℤ
discreteℤ (pos n) (pos m) with discreteℕ n m
... | yes p = yes (cong pos p)
... | no p = no (λ x → p (injPos x))
discreteℤ (pos n) (negsuc m) = no (posNotnegsuc n m)
discreteℤ (negsuc n) (pos m) = no (negsucNotpos n m)
discreteℤ (negsuc n) (negsuc m) with discreteℕ n m
... | yes p = yes (cong negsuc p)
... | no p = no (λ x → p (injNegsuc x))
isSetℤ : isSet ℤ
isSetℤ = Discrete→isSet discreteℤ
-pos : ∀ n → - (pos n) ≡ neg n
-pos zero = refl
-pos (suc n) = refl
-neg : ∀ n → - (neg n) ≡ pos n
-neg zero = refl
-neg (suc n) = refl
-Involutive : ∀ z → - (- z) ≡ z
-Involutive (pos n) = cong -_ (-pos n) ∙ -neg n
-Involutive (negsuc n) = refl
sucℤ+pos : ∀ n m → sucℤ (m +pos n) ≡ (sucℤ m) +pos n
sucℤ+pos zero m = refl
sucℤ+pos (suc n) m = cong sucℤ (sucℤ+pos n m)
predℤ+negsuc : ∀ n m → predℤ (m +negsuc n) ≡ (predℤ m) +negsuc n
predℤ+negsuc zero m = refl
predℤ+negsuc (suc n) m = cong predℤ (predℤ+negsuc n m)
sucℤ+negsuc : ∀ n m → sucℤ (m +negsuc n) ≡ (sucℤ m) +negsuc n
sucℤ+negsuc zero m = (sucPred _) ∙ (sym (predSuc _))
sucℤ+negsuc (suc n) m = _ ≡⟨ sucPred _ ⟩
m +negsuc n ≡[ i ]⟨ predSuc m (~ i) +negsuc n ⟩
(predℤ (sucℤ m)) +negsuc n ≡⟨ sym (predℤ+negsuc n (sucℤ m)) ⟩
predℤ (sucℤ m +negsuc n) ∎
predℤ+pos : ∀ n m → predℤ (m +pos n) ≡ (predℤ m) +pos n
predℤ+pos zero m = refl
predℤ+pos (suc n) m = _ ≡⟨ predSuc _ ⟩
m +pos n ≡[ i ]⟨ sucPred m (~ i) + pos n ⟩
(sucℤ (predℤ m)) +pos n ≡⟨ sym (sucℤ+pos n (predℤ m))⟩
(predℤ m) +pos (suc n) ∎
predℤ-pos : ∀ n → predℤ(- (pos n)) ≡ negsuc n
predℤ-pos zero = refl
predℤ-pos (suc n) = refl
predℤ+ : ∀ m n → predℤ (m + n) ≡ (predℤ m) + n
predℤ+ m (pos n) = predℤ+pos n m
predℤ+ m (negsuc n) = predℤ+negsuc n m
+predℤ : ∀ m n → predℤ (m + n) ≡ m + (predℤ n)
+predℤ m (pos zero) = refl
+predℤ m (pos (suc n)) = (predSuc (m + pos n)) ∙ (cong (_+_ m) (sym (predSuc (pos n))))
+predℤ m (negsuc n) = refl
sucℤ+ : ∀ m n → sucℤ (m + n) ≡ (sucℤ m) + n
sucℤ+ m (pos n) = sucℤ+pos n m
sucℤ+ m (negsuc n) = sucℤ+negsuc n m
+sucℤ : ∀ m n → sucℤ (m + n) ≡ m + (sucℤ n)
+sucℤ m (pos n) = refl
+sucℤ m (negsuc zero) = sucPred _
+sucℤ m (negsuc (suc n)) = (sucPred (m +negsuc n)) ∙ (cong (_+_ m) (sym (sucPred (negsuc n))))
pos0+ : ∀ z → z ≡ pos 0 + z
pos0+ (pos zero) = refl
pos0+ (pos (suc n)) = cong sucℤ (pos0+ (pos n))
pos0+ (negsuc zero) = refl
pos0+ (negsuc (suc n)) = cong predℤ (pos0+ (negsuc n))
negsuc0+ : ∀ z → predℤ z ≡ negsuc 0 + z
negsuc0+ (pos zero) = refl
negsuc0+ (pos (suc n)) = (sym (sucPred (pos n))) ∙ (cong sucℤ (negsuc0+ _))
negsuc0+ (negsuc zero) = refl
negsuc0+ (negsuc (suc n)) = cong predℤ (negsuc0+ (negsuc n))
ind-comm : {A : Type₀} (_∙_ : A → A → A) (f : ℕ → A) (g : A → A)
(p : ∀ {n} → f (suc n) ≡ g (f n))
(g∙ : ∀ a b → g (a ∙ b) ≡ g a ∙ b)
(∙g : ∀ a b → g (a ∙ b) ≡ a ∙ g b)
(base : ∀ z → z ∙ f 0 ≡ f 0 ∙ z)
→ ∀ z n → z ∙ f n ≡ f n ∙ z
ind-comm _∙_ f g p g∙ ∙g base z 0 = base z
ind-comm _∙_ f g p g∙ ∙g base z (suc n) =
z ∙ f (suc n) ≡[ i ]⟨ z ∙ p {n} i ⟩
z ∙ g (f n) ≡⟨ sym ( ∙g z (f n)) ⟩
g (z ∙ f n) ≡⟨ cong g IH ⟩
g (f n ∙ z) ≡⟨ g∙ (f n) z ⟩
g (f n) ∙ z ≡[ i ]⟨ p {n} (~ i) ∙ z ⟩
f (suc n) ∙ z ∎
where
IH = ind-comm _∙_ f g p g∙ ∙g base z n
ind-assoc : {A : Type₀} (_·_ : A → A → A) (f : ℕ → A)
(g : A → A) (p : ∀ a b → g (a · b) ≡ a · (g b))
(q : ∀ {c} → f (suc c) ≡ g (f c))
(base : ∀ m n → (m · n) · (f 0) ≡ m · (n · (f 0)))
(m n : A) (o : ℕ)
→ m · (n · (f o)) ≡ (m · n) · (f o)
ind-assoc _·_ f g p q base m n 0 = sym (base m n)
ind-assoc _·_ f g p q base m n (suc o) =
m · (n · (f (suc o))) ≡[ i ]⟨ m · (n · q {o} i) ⟩
m · (n · (g (f o))) ≡[ i ]⟨ m · (p n (f o) (~ i)) ⟩
m · (g (n · (f o))) ≡⟨ sym (p m (n · (f o)))⟩
g (m · (n · (f o))) ≡⟨ cong g IH ⟩
g ((m · n) · (f o)) ≡⟨ p (m · n) (f o) ⟩
(m · n) · (g (f o)) ≡[ i ]⟨ (m · n) · q {o} (~ i) ⟩
(m · n) · (f (suc o)) ∎
where
IH = ind-assoc _·_ f g p q base m n o
+Comm : ∀ m n → m + n ≡ n + m
+Comm m (pos n) = ind-comm _+_ pos sucℤ refl sucℤ+ +sucℤ pos0+ m n
+Comm m (negsuc n) = ind-comm _+_ negsuc predℤ refl predℤ+ +predℤ negsuc0+ m n
+Assoc : ∀ m n o → m + (n + o) ≡ (m + n) + o
+Assoc m n (pos o) = ind-assoc _+_ pos sucℤ +sucℤ refl (λ _ _ → refl) m n o
+Assoc m n (negsuc o) = ind-assoc _+_ negsuc predℤ +predℤ refl +predℤ m n o
-- Compose sucPathℤ with itself n times. Transporting along this
-- will be addition, transporting with it backwards will be subtraction.
-- Use this to define _+'_ for which is easier to prove
-- isEquiv (λ n → n +' m) since _+'_ is defined by transport
sucPathℤ : ℤ ≡ ℤ
sucPathℤ = ua (sucℤ , isoToIsEquiv (iso sucℤ predℤ sucPred predSuc))
addEq : ℕ → ℤ ≡ ℤ
addEq zero = refl
addEq (suc n) = (addEq n) ∙ sucPathℤ
predPathℤ : ℤ ≡ ℤ
predPathℤ = ua (predℤ , isoToIsEquiv (iso predℤ sucℤ predSuc sucPred))
subEq : ℕ → ℤ ≡ ℤ
subEq zero = refl
subEq (suc n) = (subEq n) ∙ predPathℤ
_+'_ : ℤ → ℤ → ℤ
m +' pos n = transport (addEq n) m
m +' negsuc n = transport (subEq (suc n)) m
+'≡+ : _+'_ ≡ _+_
+'≡+ i m (pos zero) = m
+'≡+ i m (pos (suc n)) = sucℤ (+'≡+ i m (pos n))
+'≡+ i m (negsuc zero) = predℤ m
+'≡+ i m (negsuc (suc n)) = predℤ (+'≡+ i m (negsuc n)) --
-- compPath (λ i → (+'≡+ i (predℤ m) (negsuc n))) (sym (predℤ+negsuc n m)) i
isEquivAddℤ' : (m : ℤ) → isEquiv (λ n → n +' m)
isEquivAddℤ' (pos n) = isEquivTransport (addEq n)
isEquivAddℤ' (negsuc n) = isEquivTransport (subEq (suc n))
isEquivAddℤ : (m : ℤ) → isEquiv (λ n → n + m)
isEquivAddℤ = subst (λ add → (m : ℤ) → isEquiv (λ n → add n m)) +'≡+ isEquivAddℤ'
-- below is an alternate proof of isEquivAddℤ for comparison
-- We also have two useful lemma here.
minusPlus : ∀ m n → (n - m) + m ≡ n
minusPlus (pos zero) n = refl
minusPlus (pos 1) = sucPred
minusPlus (pos (suc (suc m))) n =
sucℤ ((n +negsuc (suc m)) +pos (suc m)) ≡⟨ sucℤ+pos (suc m) _ ⟩
sucℤ (n +negsuc (suc m)) +pos (suc m) ≡[ i ]⟨ sucPred (n +negsuc m) i +pos (suc m) ⟩
(n - pos (suc m)) +pos (suc m) ≡⟨ minusPlus (pos (suc m)) n ⟩
n ∎
minusPlus (negsuc zero) = predSuc
minusPlus (negsuc (suc m)) n =
predℤ (sucℤ (sucℤ (n +pos m)) +negsuc m) ≡⟨ predℤ+negsuc m _ ⟩
predℤ (sucℤ (sucℤ (n +pos m))) +negsuc m ≡[ i ]⟨ predSuc (sucℤ (n +pos m)) i +negsuc m ⟩
sucℤ (n +pos m) +negsuc m ≡⟨ minusPlus (negsuc m) n ⟩
n ∎
plusMinus : ∀ m n → (n + m) - m ≡ n
plusMinus (pos zero) n = refl
plusMinus (pos (suc m)) = minusPlus (negsuc m)
plusMinus (negsuc m) = minusPlus (pos (suc m))
private
alternateProof : (m : ℤ) → isEquiv (λ n → n + m)
alternateProof m = isoToIsEquiv (iso (λ n → n + m)
(λ n → n - m)
(minusPlus m)
(plusMinus m))
-Cancel : ∀ z → z - z ≡ 0
-Cancel z = cong (_- z) (pos0+ z) ∙ plusMinus z (pos zero)
pos+ : ∀ m n → pos (m +ℕ n) ≡ pos m + pos n
pos+ zero zero = refl
pos+ zero (suc n) =
pos (zero +ℕ suc n) ≡⟨ +Comm (pos (suc n)) (pos zero) ⟩
pos zero + pos (suc n) ∎
pos+ (suc m) zero =
pos (suc (m +ℕ zero)) ≡⟨ cong pos (cong suc (+-zero m)) ⟩
pos (suc m) + pos zero ∎
pos+ (suc m) (suc n) =
pos (suc m +ℕ suc n) ≡⟨ cong pos (cong suc (+-suc m n)) ⟩
sucℤ (pos (suc (m +ℕ n))) ≡⟨ cong sucℤ (cong sucℤ (pos+ m n)) ⟩
sucℤ (sucℤ (pos m + pos n)) ≡⟨ sucℤ+ (pos m) (sucℤ (pos n)) ⟩
pos (suc m) + pos (suc n) ∎
negsuc+ : ∀ m n → negsuc (m +ℕ n) ≡ negsuc m - pos n
negsuc+ zero zero = refl
negsuc+ zero (suc n) =
negsuc (zero +ℕ suc n) ≡⟨ negsuc0+ (negsuc n) ⟩
negsuc zero + negsuc n ≡⟨ cong (negsuc zero +_) (-pos (suc n)) ⟩
negsuc zero - pos (suc n) ∎
negsuc+ (suc m) zero =
negsuc (suc m +ℕ zero) ≡⟨ cong negsuc (cong suc (+-zero m)) ⟩
negsuc (suc m) - pos zero ∎
negsuc+ (suc m) (suc n) =
negsuc (suc m +ℕ suc n) ≡⟨ cong negsuc (sym (+-suc m (suc n))) ⟩
negsuc (m +ℕ suc (suc n)) ≡⟨ negsuc+ m (suc (suc n)) ⟩
negsuc m - pos (suc (suc n)) ≡⟨ sym (+predℤ (negsuc m) (negsuc n)) ⟩
predℤ (negsuc m + negsuc n ) ≡⟨ predℤ+ (negsuc m) (negsuc n) ⟩
negsuc (suc m) - pos (suc n) ∎
neg+ : ∀ m n → neg (m +ℕ n) ≡ neg m + neg n
neg+ zero zero = refl
neg+ zero (suc n) = neg (zero +ℕ suc n) ≡⟨ +Comm (neg (suc n)) (pos zero) ⟩
neg zero + neg (suc n) ∎
neg+ (suc m) zero = neg (suc (m +ℕ zero)) ≡⟨ cong neg (cong suc (+-zero m)) ⟩
neg (suc m) + neg zero ∎
neg+ (suc m) (suc n) = neg (suc m +ℕ suc n) ≡⟨ negsuc+ m (suc n) ⟩
neg (suc m) + neg (suc n) ∎
ℕ-AntiComm : ∀ m n → m ℕ- n ≡ - (n ℕ- m)
ℕ-AntiComm zero zero = refl
ℕ-AntiComm zero (suc n) = refl
ℕ-AntiComm (suc m) zero = refl
ℕ-AntiComm (suc m) (suc n) = suc m ℕ- suc n ≡⟨ ℕ-AntiComm m n ⟩
- (suc n ℕ- suc m) ∎
pos- : ∀ m n → m ℕ- n ≡ pos m - pos n
pos- zero zero = refl
pos- zero (suc n) = zero ℕ- suc n ≡⟨ +Comm (negsuc n) (pos zero) ⟩
pos zero - pos (suc n) ∎
pos- (suc m) zero = refl
pos- (suc m) (suc n) =
suc m ℕ- suc n ≡⟨ pos- m n ⟩
pos m - pos n ≡⟨ sym (sucPred (pos m - pos n)) ⟩
sucℤ (predℤ (pos m - pos n)) ≡⟨ cong sucℤ (+predℤ (pos m) (- pos n)) ⟩
sucℤ (pos m + predℤ (- (pos n))) ≡⟨ cong sucℤ (cong (pos m +_) (predℤ-pos n)) ⟩
sucℤ (pos m + negsuc n) ≡⟨ sucℤ+negsuc n (pos m) ⟩
pos (suc m) - pos (suc n) ∎
-AntiComm : ∀ m n → m - n ≡ - (n - m)
-AntiComm (pos n) (pos m) = pos n - pos m ≡⟨ sym (pos- n m) ⟩
n ℕ- m ≡⟨ ℕ-AntiComm n m ⟩
- (m ℕ- n) ≡⟨ cong -_ (pos- m n) ⟩
- (pos m - pos n) ∎
-AntiComm (pos n) (negsuc m) =
pos n - negsuc m ≡⟨ +Comm (pos n) (pos (suc m)) ⟩
pos (suc m) + pos n ≡⟨ sym (pos+ (suc m) n) ⟩
pos (suc m +ℕ n) ≡⟨ sym (-neg (suc m +ℕ n)) ⟩
- neg (suc m +ℕ n) ≡⟨ cong -_ (neg+ (suc m) n) ⟩
- (neg (suc m) + neg n) ≡⟨ cong -_ (cong (negsuc m +_) (sym (-pos n))) ⟩
- (negsuc m - pos n) ∎
-AntiComm (negsuc n) (pos m) =
negsuc n - pos m ≡⟨ sym (negsuc+ n m) ⟩
negsuc (n +ℕ m) ≡⟨ cong -_ (pos+ (suc n) m) ⟩
- (pos (suc n) + pos m) ≡⟨ cong -_ (+Comm (pos (suc n)) (pos m)) ⟩
- (pos m - negsuc n) ∎
-AntiComm (negsuc n) (negsuc m) =
negsuc n - negsuc m ≡⟨ +Comm (negsuc n) (pos (suc m)) ⟩
pos (suc m) + negsuc n ≡⟨ sym (pos- (suc m) (suc n)) ⟩
suc m ℕ- suc n ≡⟨ ℕ-AntiComm (suc m) (suc n) ⟩
- (suc n ℕ- suc m) ≡⟨ cong -_ (pos- (suc n) (suc m)) ⟩
- (pos (suc n) - pos (suc m)) ≡⟨ cong -_ (+Comm (pos (suc n)) (negsuc m)) ⟩
- (negsuc m - negsuc n) ∎
-Dist+ : ∀ m n → - (m + n) ≡ (- m) + (- n)
-Dist+ (pos n) (pos m) =
- (pos n + pos m) ≡⟨ cong -_ (sym (pos+ n m)) ⟩
- pos (n +ℕ m) ≡⟨ -pos (n +ℕ m) ⟩
neg (n +ℕ m) ≡⟨ neg+ n m ⟩
neg n + neg m ≡⟨ cong (neg n +_) (sym (-pos m)) ⟩
neg n + (- pos m) ≡⟨ cong (_+ (- pos m)) (sym (-pos n)) ⟩
(- pos n) + (- pos m) ∎
-Dist+ (pos n) (negsuc m) =
- (pos n + negsuc m) ≡⟨ sym (-AntiComm (pos (suc m)) (pos n)) ⟩
pos (suc m) - pos n ≡⟨ +Comm (pos (suc m)) (- pos n) ⟩
(- pos n) + (- negsuc m) ∎
-Dist+ (negsuc n) (pos m) =
- (negsuc n + pos m) ≡⟨ cong -_ (+Comm (negsuc n) (pos m)) ⟩
- (pos m + negsuc n) ≡⟨ sym (-AntiComm (- negsuc n) (pos m)) ⟩
(- negsuc n) + (- pos m) ∎
-Dist+ (negsuc n) (negsuc m) =
- (negsuc n + negsuc m) ≡⟨ cong -_ (sym (neg+ (suc n) (suc m))) ⟩
- neg (suc n +ℕ suc m) ≡⟨ pos+ (suc n) (suc m) ⟩
(- negsuc n) + (- negsuc m) ∎
-- multiplication
pos·negsuc : (n m : ℕ) → pos n · negsuc m ≡ - (pos n · pos (suc m))
pos·negsuc zero m = refl
pos·negsuc (suc n) m =
(λ i → negsuc m + (pos·negsuc n m i))
∙ sym (-Dist+ (pos (suc m)) (pos n · pos (suc m)))
negsuc·pos : (n m : ℕ) → negsuc n · pos m ≡ - (pos (suc n) · pos m)
negsuc·pos zero m = refl
negsuc·pos (suc n) m =
cong ((- pos m) +_) (negsuc·pos n m)
∙ sym (-Dist+ (pos m) (pos m + (pos n · pos m)))
negsuc·negsuc : (n m : ℕ) → negsuc n · negsuc m ≡ pos (suc n) · pos (suc m)
negsuc·negsuc zero m = refl
negsuc·negsuc (suc n) m = cong (pos (suc m) +_) (negsuc·negsuc n m)
·Comm : (x y : ℤ) → x · y ≡ y · x
·Comm (pos n) (pos m) = lem n m
where
lem : (n m : ℕ) → (pos n · pos m) ≡ (pos m · pos n)
lem zero zero = refl
lem zero (suc m) i = +Comm (lem zero m i) (pos zero) i
lem (suc n) zero i = +Comm (pos zero) (lem n zero i) i
lem (suc n) (suc m) =
(λ i → pos (suc m) + (lem n (suc m) i))
∙∙ +Assoc (pos (suc m)) (pos n) (pos m · pos n)
∙∙ (λ i → sucℤ+ (pos m) (pos n) (~ i) + (pos m · pos n))
∙∙ (λ i → +Comm (pos m) (pos (suc n)) i + (pos m · pos n))
∙∙ sym (+Assoc (pos (suc n)) (pos m) (pos m · pos n))
∙∙ (λ i → pos (suc n) + (pos m + (lem n m (~ i))))
∙∙ λ i → pos (suc n) + (lem (suc n) m i)
·Comm (pos n) (negsuc m) =
pos·negsuc n m
∙∙ cong -_ (·Comm (pos n) (pos (suc m)))
∙∙ sym (negsuc·pos m n)
·Comm (negsuc n) (pos m) =
sym (pos·negsuc m n
∙∙ cong -_ (·Comm (pos m) (pos (suc n)))
∙∙ sym (negsuc·pos n m))
·Comm (negsuc n) (negsuc m) =
negsuc·negsuc n m ∙∙ ·Comm (pos (suc n)) (pos (suc m)) ∙∙ sym (negsuc·negsuc m n)
·Rid : (x : ℤ) → x · 1 ≡ x
·Rid x = ·Comm x 1
private
distrHelper : (x y z w : ℤ) → (x + y) + (z + w) ≡ ((x + z) + (y + w))
distrHelper x y z w =
+Assoc (x + y) z w
∙∙ cong (_+ w) (sym (+Assoc x y z) ∙∙ cong (x +_) (+Comm y z) ∙∙ +Assoc x z y)
∙∙ sym (+Assoc (x + z) y w)
·DistR+ : (x y z : ℤ) → x · (y + z) ≡ x · y + x · z
·DistR+ (pos zero) y z = refl
·DistR+ (pos (suc n)) y z =
cong ((y + z) +_) (·DistR+ (pos n) y z)
∙ distrHelper y z (pos n · y) (pos n · z)
·DistR+ (negsuc zero) y z = -Dist+ y z
·DistR+ (negsuc (suc n)) y z =
cong₂ _+_ (-Dist+ y z) (·DistR+ (negsuc n) y z)
∙ distrHelper (- y) (- z) (negsuc n · y) (negsuc n · z)
·DistL+ : (x y z : ℤ) → (x + y) · z ≡ x · z + y · z
·DistL+ x y z = ·Comm (x + y) z ∙∙ ·DistR+ z x y ∙∙ cong₂ _+_ (·Comm z x) (·Comm z y)
-DistL· : (b c : ℤ) → - (b · c) ≡ - b · c
-DistL· (pos zero) c = refl
-DistL· (pos (suc n)) (pos m) = sym (negsuc·pos n m)
-DistL· (pos (suc zero)) (negsuc m) =
-Dist+ (negsuc m) (pos zero · negsuc m)
∙ cong (pos (suc m) +_) (-DistL· (pos zero) (negsuc m))
-DistL· (pos (suc (suc n))) (negsuc m) =
-Dist+ (negsuc m) (pos (suc n) · negsuc m)
∙ cong (pos (suc m) +_) (-DistL· (pos (suc n)) (negsuc m))
-DistL· (negsuc zero) c = -Involutive c
-DistL· (negsuc (suc n)) c =
-Dist+ (- c) (negsuc n · c)
∙∙ cong (_+ (- (negsuc n · c))) (-Involutive c)
∙∙ cong (c +_) (-DistL· (negsuc n) c)
-DistR· : (b c : ℤ) → - (b · c) ≡ b · - c
-DistR· b c = cong (-_) (·Comm b c) ∙∙ -DistL· c b ∙∙ ·Comm (- c) b
·Assoc : (a b c : ℤ) → (a · (b · c)) ≡ ((a · b) · c)
·Assoc (pos zero) b c = refl
·Assoc (pos (suc n)) b c =
cong ((b · c) +_) (·Assoc (pos n) b c)
∙∙ cong₂ _+_ (·Comm b c) (·Comm (pos n · b) c)
∙∙ sym (·DistR+ c b (pos n · b))
∙ sym (·Comm _ c)
·Assoc (negsuc zero) = -DistL·
·Assoc (negsuc (suc n)) b c =
cong ((- (b · c)) +_) (·Assoc (negsuc n) b c)
∙∙ cong (_+ ((negsuc n · b) · c)) (-DistL· b c)
∙∙ sym (·DistL+ (- b) (negsuc n · b) c)
| 37.041394
| 94
| 0.499882
|
0dcabe57d0c2204d4b90565a9220a916955eebeb
| 5,877
|
agda
|
Agda
|
Cubical/Algebra/Semigroup/Construct/Free.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Semigroup/Construct/Free.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Semigroup/Construct/Free.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Foundations.HLevels
module Cubical.Algebra.Semigroup.Construct.Free {ℓ} (Aˢ : hSet ℓ) where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Path
open import Cubical.Algebra.Semigroup
open import Cubical.Data.Empty.Polymorphic
open import Cubical.Data.Prod
open import Cubical.Relation.Binary.Reasoning.Equality
A = ⟨ Aˢ ⟩
isSetA = Aˢ .snd
------------------------------------------------------------------------
-- The direct free semigroup type
data FreeS′ : Type ℓ where
inj : A → FreeS′
_•_ : Op₂ FreeS′
•-assoc : Associative _•_
squash : isSet FreeS′
elim : ∀ {ℓ′} {B : FreeS′ → Type ℓ′} →
(∀ x → isSet (B x)) →
(∀ x → B (inj x)) →
(op : ∀ x y → B x → B y → B (x • y)) →
(∀ x y z (a : B x) (b : B y) (c : B z) → PathP (λ i → B (•-assoc x y z i)) (op _ _ (op _ _ a b) c) (op _ _ a (op _ _ b c))) →
(x : FreeS′) → B x
elim isSetB f op assc (inj x) = f x
elim isSetB f op assc (x • y) = op x y (elim isSetB f op assc x) (elim isSetB f op assc y)
elim isSetB f op assc (•-assoc x y z i) = assc x y z (elim isSetB f op assc x) (elim isSetB f op assc y) (elim isSetB f op assc z) i
elim isSetB f op assc (squash x y p q i j) =
isOfHLevel→isOfHLevelDep 2 isSetB
(elim isSetB f op assc x) (elim isSetB f op assc y)
(cong (elim isSetB f op assc) p) (cong (elim isSetB f op assc) q) (squash x y p q) i j
------------------------------------------------------------------------
-- The simplified free semigroup type
infixl 5 _□
infixr 4 _∶_
data FreeS : Type ℓ where
_□ : A → FreeS
_∶_ : A → FreeS → FreeS
module FreeSPath where
Cover : FreeS → FreeS → Type ℓ
Cover (x □) (y □) = x ≡ y
Cover (x □) (y ∶ ys) = ⊥
Cover (x ∶ xs) (y □) = ⊥
Cover (x ∶ xs) (y ∶ ys) = (x ≡ y) × Cover xs ys
isPropCover : ∀ xs ys → isProp (Cover xs ys)
isPropCover (x □) (y □) = isSetA x y
isPropCover (x □) (y ∶ ys) = isProp⊥
isPropCover (x ∶ xs) (y □) = isProp⊥
isPropCover (x ∶ xs) (y ∶ ys) = isPropProd (isSetA x y) (isPropCover xs ys)
reflCover : ∀ xs → Cover xs xs
reflCover (x □) = refl
reflCover (x ∶ xs) = refl , reflCover xs
encode : ∀ xs ys → xs ≡ ys → Cover xs ys
encode xs _ = J (λ ys _ → Cover xs ys) (reflCover xs)
encodeRefl : ∀ xs → encode xs xs refl ≡ reflCover xs
encodeRefl xs = JRefl (λ ys _ → Cover xs ys) (reflCover xs)
decode : ∀ xs ys → Cover xs ys → xs ≡ ys
decode (x □) (y □) p = cong _□ p
decode (x □) (y ∶ ys) ()
decode (x ∶ xs) (y □) ()
decode (x ∶ xs) (y ∶ ys) (p , q) = cong₂ _∶_ p (decode xs ys q)
decodeRefl : ∀ xs → decode xs xs (reflCover xs) ≡ refl
decodeRefl (x □) = refl
decodeRefl (x ∶ xs) = cong (cong₂ _∶_ refl) (decodeRefl xs)
decodeEncode : ∀ xs ys → (p : xs ≡ ys) → decode xs ys (encode xs ys p) ≡ p
decodeEncode xs _ =
J (λ ys p → decode xs ys (encode xs ys p) ≡ p)
(cong (decode xs xs) (encodeRefl xs) ∙ decodeRefl xs)
isSetFreeS : isSet FreeS
isSetFreeS x y =
isOfHLevelRetract 1
(FreeSPath.encode x y)
(FreeSPath.decode x y)
(FreeSPath.decodeEncode x y)
(FreeSPath.isPropCover x y)
_++_ : Op₂ FreeS
(x □) ++ ys = x ∶ ys
(x ∶ xs) ++ ys = x ∶ xs ++ ys
++-assoc : Associative _++_
++-assoc (x □) ys zs = refl
++-assoc (x ∶ xs) ys zs = cong (x ∶_) (++-assoc xs ys zs)
------------------------------------------------------------------------
-- Proving the two types are equivalent
FreeS→FreeS′ : FreeS → FreeS′
FreeS→FreeS′ (x □) = inj x
FreeS→FreeS′ (x ∶ xs) = inj x • FreeS→FreeS′ xs
FreeS′→FreeS : FreeS′ → FreeS
FreeS′→FreeS = elim (λ _ → isSetFreeS) _□ (λ _ _ → _++_) (λ _ _ _ → ++-assoc)
FreeS→FreeS′→FreeS : retract FreeS→FreeS′ FreeS′→FreeS
FreeS→FreeS′→FreeS (x □) = refl
FreeS→FreeS′→FreeS (x ∶ xs) = cong (x ∶_) (FreeS→FreeS′→FreeS xs)
++-hom : Homomorphic₂ FreeS→FreeS′ _++_ _•_
++-hom (x □) ys = refl
++-hom (x ∶ xs) ys = cong (inj x •_) (++-hom xs ys) ∙ sym (•-assoc (inj x) (FreeS→FreeS′ xs) (FreeS→FreeS′ ys))
FreeS′→FreeS→FreeS′ : section FreeS→FreeS′ FreeS′→FreeS
FreeS′→FreeS→FreeS′ = elim (λ _ → isSet→isGroupoid squash _ _) (λ _ → refl) sectionOp (λ _ _ _ _ _ _ → isOfHLevelPathP' 0 (squash _ _) _ _ .fst)
where
sectionOp : ∀ x y → FreeS→FreeS′ (FreeS′→FreeS x) ≡ x →
FreeS→FreeS′ (FreeS′→FreeS y) ≡ y →
FreeS→FreeS′ (FreeS′→FreeS (x • y)) ≡ (x • y)
sectionOp x y p q =
FreeS→FreeS′ (FreeS′→FreeS (x • y)) ≡⟨⟩
FreeS→FreeS′ (FreeS′→FreeS x ++ FreeS′→FreeS y) ≡⟨ ++-hom (FreeS′→FreeS x) (FreeS′→FreeS y) ⟩
FreeS→FreeS′ (FreeS′→FreeS x) • FreeS→FreeS′ (FreeS′→FreeS y) ≡⟨ cong₂ _•_ p q ⟩
x • y ∎
FreeS≃FreeS′ : FreeS ≃ FreeS′
FreeS≃FreeS′ = isoToEquiv (iso FreeS→FreeS′ FreeS′→FreeS FreeS′→FreeS→FreeS′ FreeS→FreeS′→FreeS)
FreeS≡FreeS′ : FreeS ≡ FreeS′
FreeS≡FreeS′ = ua FreeS≃FreeS′
------------------------------------------------------------------------
-- Semigroup Algebra
FreeS′-isSemigroup : IsSemigroup FreeS′ _•_
FreeS′-isSemigroup = record
{ isMagma = record { is-set = squash }
; assoc = •-assoc
}
FreeS-isSemigroup : IsSemigroup FreeS _++_
FreeS-isSemigroup = record
{ isMagma = record { is-set = isSetFreeS }
; assoc = ++-assoc
}
FreeSemigroup′ : Semigroup ℓ
FreeSemigroup′ = record { isSemigroup = FreeS′-isSemigroup }
FreeSemigroup : Semigroup ℓ
FreeSemigroup = record { isSemigroup = FreeS-isSemigroup }
EquivFreeS : SemigroupEquiv FreeSemigroup FreeSemigroup′
EquivFreeS = record
{ eq = FreeS≃FreeS′
; isHom = ++-hom
}
FreeSemigroup≡ : FreeSemigroup ≡ FreeSemigroup′
FreeSemigroup≡ = uaSemigroup EquivFreeS
| 31.940217
| 144
| 0.572401
|
412db4c2ac19d31f1b8450c5a382ea28282f8149
| 2,690
|
agda
|
Agda
|
Cubical/Data/Nat/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Data/Nat/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Data/Nat/Properties.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-exact-split --safe #-}
module Cubical.Data.Nat.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat.Base
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Prod.Base
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
+-zero : ∀ m → m + 0 ≡ m
+-zero zero = refl
+-zero (suc m) = cong suc (+-zero m)
+-suc : ∀ m n → m + suc n ≡ suc (m + n)
+-suc zero n = refl
+-suc (suc m) n = cong suc (+-suc m n)
+-comm : ∀ m n → m + n ≡ n + m
+-comm m zero = +-zero m
+-comm m (suc n) = (+-suc m n) ∙ (cong suc (+-comm m n))
-- Addition is associative
+-assoc : ∀ m n o → m + (n + o) ≡ (m + n) + o
+-assoc zero _ _ = refl
+-assoc (suc m) n o = cong suc (+-assoc m n o)
private
variable
l m n : ℕ
znots : ¬ (0 ≡ suc n)
znots eq = subst (caseNat ℕ ⊥) eq 0
snotz : ¬ (suc n ≡ 0)
snotz eq = subst (caseNat ⊥ ℕ) eq 0
injSuc : suc m ≡ suc n → m ≡ n
injSuc p = cong predℕ p
inj-m+ : m + l ≡ m + n → l ≡ n
inj-m+ {zero} p = p
inj-m+ {suc m} p = inj-m+ (injSuc p)
inj-+m : l + m ≡ n + m → l ≡ n
inj-+m {l} {m} {n} p = inj-m+ ((+-comm m l) ∙ (p ∙ (+-comm n m)))
m+n≡n→m≡0 : m + n ≡ n → m ≡ 0
m+n≡n→m≡0 {n = zero} = λ p → (sym (+-zero _)) ∙ p
m+n≡n→m≡0 {n = suc n} p = m+n≡n→m≡0 (injSuc ((sym (+-suc _ n)) ∙ p))
m+n≡0→m≡0×n≡0 : m + n ≡ 0 → (m ≡ 0) × (n ≡ 0)
m+n≡0→m≡0×n≡0 {zero} = refl ,_
m+n≡0→m≡0×n≡0 {suc m} p = ⊥.rec (snotz p)
discreteℕ : Discrete ℕ
discreteℕ zero zero = yes refl
discreteℕ zero (suc n) = no znots
discreteℕ (suc m) zero = no snotz
discreteℕ (suc m) (suc n) with discreteℕ m n
... | yes p = yes (cong suc p)
... | no p = no (λ x → p (injSuc x))
isSetℕ : isSet ℕ
isSetℕ = Discrete→isSet discreteℕ
0≡m*0 : ∀ m → 0 ≡ m * 0
0≡m*0 zero = refl
0≡m*0 (suc m) = 0≡m*0 m
*-suc : ∀ m n → m * suc n ≡ m + m * n
*-suc zero n = refl
*-suc (suc m) n
= cong suc
( n + m * suc n ≡⟨ cong (n +_) (*-suc m n) ⟩
n + (m + m * n) ≡⟨ +-assoc n m (m * n) ⟩
(n + m) + m * n ≡⟨ cong (_+ m * n) (+-comm n m) ⟩
(m + n) + m * n ≡⟨ sym (+-assoc m n (m * n)) ⟩
m + (n + m * n) ∎
)
*-comm : ∀ m n → m * n ≡ n * m
*-comm zero n = 0≡m*0 n
*-comm (suc m) n = cong (n +_) (*-comm m n) ∙ sym (*-suc n m)
0≡n*sm→0≡n : 0 ≡ n * suc m → 0 ≡ n
0≡n*sm→0≡n {n = zero} p = refl
0≡n*sm→0≡n {n = suc n} p = ⊥.rec (znots p)
inj-*sm : l * suc m ≡ n * suc m → l ≡ n
inj-*sm {zero} {m} {n} p = 0≡n*sm→0≡n p
inj-*sm {l} {m} {zero} p = sym (0≡n*sm→0≡n (sym p))
inj-*sm {suc l} {m} {suc n} p = cong suc (inj-*sm (inj-m+ {m = suc m} p))
inj-sm* : suc m * l ≡ suc m * n → l ≡ n
inj-sm* {m} {l} {n} p = inj-*sm (*-comm l (suc m) ∙ p ∙ *-comm (suc m) n)
| 26.633663
| 73
| 0.516729
|
4eaf4fe677865067372b7e04e61dcee1a5d572e1
| 3,104
|
agda
|
Agda
|
src/Categories/Category/Equivalence.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/Equivalence.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/Equivalence.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Equivalence where
-- Strong equivalence of categories. Same as ordinary equivalence in Cat.
-- May not include everything we'd like to think of as equivalences, namely
-- the full, faithful functors that are essentially surjective on objects.
open import Level
open import Relation.Binary using (IsEquivalence; Setoid)
open import Categories.Category.Core using (Category)
open import Categories.Functor renaming (id to idF)
open import Categories.NaturalTransformation.NaturalIsomorphism as ≃
using (NaturalIsomorphism ; unitorˡ; unitorʳ; associator; _ⓘᵥ_; _ⓘˡ_; _ⓘʳ_)
private
variable
o ℓ e : Level
C D E : Category o ℓ e
record WeakInverse (F : Functor C D) (G : Functor D C) : Set (levelOfTerm F ⊔ levelOfTerm G) where
field
F∘G≈id : NaturalIsomorphism (F ∘F G) idF
G∘F≈id : NaturalIsomorphism (G ∘F F) idF
module F∘G≈id = NaturalIsomorphism F∘G≈id
module G∘F≈id = NaturalIsomorphism G∘F≈id
record StrongEquivalence {o ℓ e o′ ℓ′ e′} (C : Category o ℓ e) (D : Category o′ ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
F : Functor C D
G : Functor D C
weak-inverse : WeakInverse F G
open WeakInverse weak-inverse public
op : StrongEquivalence (Category.op C) (Category.op D)
op = record
{ F = Functor.op F
; G = Functor.op G
; weak-inverse = record
{ F∘G≈id = NaturalIsomorphism.op′ F∘G≈id
; G∘F≈id = NaturalIsomorphism.op′ G∘F≈id
}
}
refl : StrongEquivalence C C
refl = record
{ F = idF
; G = idF
; weak-inverse = record
{ F∘G≈id = unitorˡ
; G∘F≈id = unitorˡ
}
}
sym : StrongEquivalence C D → StrongEquivalence D C
sym e = record
{ F = G
; G = F
; weak-inverse = record
{ F∘G≈id = G∘F≈id
; G∘F≈id = F∘G≈id
}
}
where open StrongEquivalence e
trans : StrongEquivalence C D → StrongEquivalence D E → StrongEquivalence C E
trans {C = C} {D = D} {E = E} e e′ = record
{ F = e′.F ∘F e.F
; G = e.G ∘F e′.G
; weak-inverse = record
{ F∘G≈id = let module S = Setoid (≃.Functor-NI-setoid E E)
in S.trans (S.trans (associator (e.G ∘F e′.G) e.F e′.F)
(e′.F ⓘˡ (unitorˡ ⓘᵥ (e.F∘G≈id ⓘʳ e′.G) ⓘᵥ ≃.sym (associator e′.G e.G e.F))))
e′.F∘G≈id
; G∘F≈id = let module S = Setoid (≃.Functor-NI-setoid C C)
in S.trans (S.trans (associator (e′.F ∘F e.F) e′.G e.G)
(e.G ⓘˡ (unitorˡ ⓘᵥ (e′.G∘F≈id ⓘʳ e.F) ⓘᵥ ≃.sym (associator e.F e′.F e′.G))))
e.G∘F≈id
}
}
where module e = StrongEquivalence e
module e′ = StrongEquivalence e′
isEquivalence : ∀ {o ℓ e} → IsEquivalence (StrongEquivalence {o} {ℓ} {e})
isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
setoid : ∀ o ℓ e → Setoid _ _
setoid o ℓ e = record
{ Carrier = Category o ℓ e
; _≈_ = StrongEquivalence
; isEquivalence = isEquivalence
}
| 31.04
| 125
| 0.580541
|
Subsets and Splits
HTML Code Excluding Scripts
The query retrieves a limited set of HTML content entries that are longer than 8 characters and do not contain script tags, offering only basic filtering with minimal analytical value.