Search is not available for this dataset
text
string | meta
dict |
---|---|
import Lvl
module Structure.Category.Category {ℓₒ ℓₘ ℓₑ : Lvl.Level} where
open import Structure.Category
open import Structure.Category.Functor.Equiv
open import Structure.Category.Functor
import Structure.Category.Functor.Functors as Functors
open import Structure.Category.Functor.Functors.Proofs
open CategoryObject
open Functors.Wrapped
categoryCategory : Category{Obj = CategoryObject{ℓₒ}{ℓₘ}{ℓₑ}} (_→ᶠᵘⁿᶜᵗᵒʳ_)
Category._∘_ categoryCategory = _∘ᶠᵘⁿᶜᵗᵒʳ_
Category.id categoryCategory = idᶠᵘⁿᶜᵗᵒʳ
Category.binaryOperator categoryCategory = [∘ᶠᵘⁿᶜᵗᵒʳ]-binaryOperator
Category.associativity categoryCategory = [∘ᶠᵘⁿᶜᵗᵒʳ]-associativity
Category.identity categoryCategory = [∘ᶠᵘⁿᶜᵗᵒʳ]-identity
|
{
"alphanum_fraction": 0.7872628726,
"avg_line_length": 36.9,
"ext": "agda",
"hexsha": "5fb81d7a4f53a994ac6ca400ea2049e1c9824520",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Category/Category.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Category/Category.agda",
"max_line_length": 74,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Category/Category.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 292,
"size": 738
}
|
{-# OPTIONS --without-K --safe #-}
-- verbatim dual of Categories.Category.Construction.Properties.Kleisli
module Categories.Category.Construction.Properties.CoKleisli where
open import Level
import Relation.Binary.PropositionalEquality as ≡
open import Categories.Adjoint
open import Categories.Adjoint.Properties
open import Categories.Category
open import Categories.Functor using (Functor; _∘F_)
open import Categories.Functor.Equivalence
open import Categories.Comonad
import Categories.Morphism.Reasoning as MR
open import Categories.Adjoint.Construction.CoKleisli
open import Categories.Category.Construction.CoKleisli
private
variable
o ℓ e : Level
𝒞 𝒟 : Category o ℓ e
module _ {F : Functor 𝒞 𝒟} {G : Functor 𝒟 𝒞} (F⊣G : Adjoint F G) where
private
T : Comonad 𝒟
T = adjoint⇒comonad F⊣G
𝒟ₜ : Category _ _ _
𝒟ₜ = CoKleisli T
module 𝒞 = Category 𝒞
module 𝒟 = Category 𝒟
module 𝒟ₜ = Category 𝒟ₜ
module T = Comonad T
module F = Functor F
module G = Functor G
open Adjoint F⊣G
-- Maclane's Comparison Functor
ComparisonF : Functor 𝒟ₜ 𝒞
ComparisonF = record
{ F₀ = λ X → G.F₀ X
; F₁ = λ {A} {B} f → 𝒞 [ (G.F₁ f) ∘ unit.η (G.F₀ A) ]
; identity = λ {A} → zag
; homomorphism = λ {X} {Y} {Z} {f} {g} → begin
G.F₁ (g 𝒟.∘ F.F₁ (G.F₁ f) 𝒟.∘ F.F₁ (unit.η (G.F₀ X))) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ pushˡ G.homomorphism ⟩
G.F₁ g 𝒞.∘ G.F₁ ((F.F₁ (G.F₁ f)) 𝒟.∘ F.F₁ (unit.η (G.F₀ X))) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ (refl⟩∘⟨ pushˡ G.homomorphism) ⟩
G.F₁ g 𝒞.∘ G.F₁ (F.F₁ (G.F₁ f)) 𝒞.∘ G.F₁ (F.F₁ (unit.η (G.F₀ X))) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ (refl⟩∘⟨ (refl⟩∘⟨ sym (unit.commute (unit.η (G.F₀ X))))) ⟩
G.F₁ g 𝒞.∘ G.F₁ (F.F₁ (G.F₁ f)) 𝒞.∘ unit.η (G.F₀ (F.F₀ (G.F₀ X))) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ (refl⟩∘⟨ pullˡ (sym (unit.commute (G.F₁ f)))) ⟩
G.F₁ g 𝒞.∘ (unit.η (G.F₀ Y) 𝒞.∘ G.F₁ f) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ MR.assoc²'' 𝒞 ⟩
(G.F₁ g 𝒞.∘ unit.η (G.F₀ Y)) 𝒞.∘ G.F₁ f 𝒞.∘ unit.η (G.F₀ X) ∎
; F-resp-≈ = λ eq → 𝒞.∘-resp-≈ (G.F-resp-≈ eq) (Category.Equiv.refl 𝒞)
}
where
open 𝒞.HomReasoning
open 𝒞.Equiv
open MR 𝒞
private
L = ComparisonF
module L = Functor L
module Gₜ = Functor (Forgetful T)
module Fₜ = Functor (Cofree T)
F∘L≡Forgetful : (F ∘F L) ≡F Forgetful T
F∘L≡Forgetful = record
{ eq₀ = λ X → ≡.refl
; eq₁ = eq-1
}
where
open 𝒟.HomReasoning
open MR 𝒟
eq-1 : {X Y : 𝒟.Obj} (f : F.F₀ (G.F₀ X) 𝒟.⇒ Y) → 𝒟.id 𝒟.∘ F.F₁ (G.F₁ f 𝒞.∘ unit.η (G.F₀ X)) 𝒟.≈ (F.F₁ (G.F₁ f) 𝒟.∘ F.F₁ (unit.η (G.F₀ X))) 𝒟.∘ 𝒟.id
eq-1 {X} {Y} f = begin
𝒟.id 𝒟.∘ F.F₁ (G.F₁ f 𝒞.∘ unit.η (G.F₀ X)) ≈⟨ id-comm-sym ⟩
F.F₁ (G.F₁ f 𝒞.∘ unit.η (G.F₀ X)) 𝒟.∘ 𝒟.id ≈⟨ (F.homomorphism ⟩∘⟨refl) ⟩
(F.F₁ (G.F₁ f) 𝒟.∘ F.F₁ (unit.η (G.F₀ X))) 𝒟.∘ 𝒟.id ∎
L∘Cofree≡G : (L ∘F Cofree T) ≡F G
L∘Cofree≡G = record
{ eq₀ = λ X → ≡.refl
; eq₁ = eq-1
}
where
open 𝒞.HomReasoning
open MR 𝒞
eq-1 : {X Y : 𝒟.Obj} (f : X 𝒟.⇒ Y) → 𝒞.id 𝒞.∘ G.F₁ (f 𝒟.∘ counit.η X) 𝒞.∘ unit.η (G.F₀ X) 𝒞.≈ G.F₁ f 𝒞.∘ 𝒞.id
eq-1 {X} {Y} f = begin
𝒞.id 𝒞.∘ G.F₁ (f 𝒟.∘ counit.η X) 𝒞.∘ unit.η (G.F₀ X) ≈⟨ id-comm-sym ⟩
(G.F₁ (f 𝒟.∘ counit.η X) 𝒞.∘ unit.η (G.F₀ X)) 𝒞.∘ 𝒞.id ≈⟨ (pushˡ G.homomorphism ⟩∘⟨refl) ⟩
(G.F₁ f 𝒞.∘ G.F₁ (counit.η X) 𝒞.∘ unit.η (G.F₀ X)) 𝒞.∘ 𝒞.id ≈⟨ (elimʳ zag ⟩∘⟨refl) ⟩
G.F₁ f 𝒞.∘ 𝒞.id ∎
|
{
"alphanum_fraction": 0.5467048711,
"avg_line_length": 36.3541666667,
"ext": "agda",
"hexsha": "9afb00d936d70c2231c411e20cf3dbe4da378f5a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Construction/Properties/CoKleisli.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Construction/Properties/CoKleisli.agda",
"max_line_length": 153,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Construction/Properties/CoKleisli.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-22T03:54:24.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-05-21T17:07:19.000Z",
"num_tokens": 1769,
"size": 3490
}
|
module PatternSynonymImports2 where
open import PatternSynonyms
open import PatternSynonymImports
myzero' = z
myzero'' = myzero
list2 : List _
list2 = 1 ∷ []
|
{
"alphanum_fraction": 0.775,
"avg_line_length": 16,
"ext": "agda",
"hexsha": "c792c7ef085894fcc34603160b1480b30e07a0fb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/succeed/PatternSynonymImports2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "np/agda-git-experiment",
"max_issues_repo_path": "test/succeed/PatternSynonymImports2.agda",
"max_line_length": 35,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/PatternSynonymImports2.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 47,
"size": 160
}
|
{-# OPTIONS --without-K #-}
{- This brief section introduces an alternative definition
of n-connectedness defined purely using propositional truncation,
in contrast to the standard one using n-truncations
(The below observation has resulted in Exercise 7.6 of
the HoTT book being modified accordingly).
In detail, a type A is usually called n-connected if Trunc n A
is contractible. Here, we show that n-connectedness of A can also
be defined recursively as follows:
* A is (-2)-connected,
* A is (n+1)-connected iff A is merely inhabited and for all a₀, a₁ : A,
the path space a₀ == a₁ is n-connected.
This module is independent from the other files in this directory,
using only the truncations with definitional computation from the library. -}
module Universe.Trunc.ConnectednessAlt where
open import lib.Basics
open import lib.NConnected
open import lib.NType2
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.TLevel
open import lib.types.Truncation
open import lib.types.Unit
open import Universe.Utility.General
open import Universe.Utility.TruncUniverse
-- Preliminary lemmata.
module _ where
{- The structural lemma for the below equivalence of connectedness notions:
Contractibility is equivalent to propositionality and mere inhabitation. -}
contr-decompose : ∀ {i} {A : Type i} → is-contr A ≃ (Trunc ⟨-1⟩ A × is-prop A)
contr-decompose {i} {A} = prop-equiv h k f g where
h = is-contr-is-prop
k = snd ((_ , Trunc-level) ×-≤ (_ , is-prop-is-prop))
f = λ c → ([ fst c ] , contr-is-prop c)
g = λ {(ta , s) → Trunc-rec h (flip inhab-prop-is-contr s) ta}
-- Everything here will happen in universe Type i.
module _ {i} where
module _ {n : ℕ₋₂} where
-- The dependent universal property over n-types.
Trunc-dup : (A : Type i) (B : (ta : Trunc n A) → n -Type i)
→ Π (Trunc n A) (⟦_⟧ ∘ B) ≃ Π A (⟦_⟧ ∘ B ∘ [_])
Trunc-dup A B = equiv
(λ f → f ∘ [_]) (Trunc-elim (snd ∘ B)) (λ _ → idp)
(λ f → λ= (Trunc-elim (snd ∘ (λ a → Path-≤ (B a) _ _)) (λ a → idp)))
{- The truncation functor is applicative (here only a special case).
Note the more elegant alternative of using the approach
from TypeConstructors.agda with unicity of truncations. -}
Trunc-×-equiv : {A B : Type i} → Trunc n (A × B) ≃ (Trunc n A × Trunc n B)
Trunc-×-equiv {A} {B} = equiv f g f-g g-f where
f = λ t → (Trunc-fmap fst t , Trunc-fmap snd t)
g = λ {(ta , tb) → Trunc-rec Trunc-level
(λ a → Trunc-rec Trunc-level
(λ b → [ (a , b) ]) tb) ta}
f-g = λ {(ta , tb) → Trunc-elim (λ ta → snd (T (ta , tb)))
(λ a → Trunc-elim (λ tb → snd (T ([ a ] , tb)))
(λ b → idp) tb) ta} where
T : Trunc n A × Trunc n B → n -Type i
T ts = Path-≤ ((_ , Trunc-level) ×-≤ (_ , Trunc-level)) (f (g ts)) ts
g-f = Trunc-elim (λ _ → snd (Path-≤ (_ , Trunc-level) _ _)) (λ a → idp)
{- The connectedness predicate from the library:
is-connected : ℕ₋₂ → Type i → Type i
is-connected n A = is-contr (Trunc n A) -}
-- Our connectedness predicate defined using only propositional truncation.
is-connected' : ℕ₋₂ → Type i → Type i
is-connected' ⟨-2⟩ A = Lift ⊤
is-connected' (S n) A = Trunc ⟨-1⟩ A × ((as : A × A) → is-connected' n (fst as == snd as))
-- Both notions coincide.
connected-equiv : (n : ℕ₋₂) (A : Type i) → is-connected n A ≃ is-connected' n A
connected-equiv ⟨-2⟩ A = lift-equiv ⁻¹
∘e contr-equiv-Unit (inhab-prop-is-contr Trunc-level is-contr-is-prop)
connected-equiv (S n) A = equiv-Σ (fuse-Trunc A _ _) (λ _ → e) ∘e contr-decompose where
e = is-prop (Trunc (S n) A)
≃⟨ curry-equiv ⁻¹ ⟩
Π (Trunc (S n) A × Trunc (S n) A) (is-contr ∘ uncurry _==_)
≃⟨ equiv-Π-l _ (snd Trunc-×-equiv) ⁻¹ ⟩
Π (Trunc (S n) (A × A)) (is-contr ∘ uncurry _==_ ∘ _)
≃⟨ Trunc-dup (A × A) (λ _ → (_ , raise-level-≤T (≤T-ap-S (-2≤T n)) is-contr-is-prop)) ⟩
((as : A × A) → is-contr ([ fst as ] == [ snd as ]))
≃⟨ equiv-Π-r (λ _ → equiv-level (Trunc=-equiv _ _)) ⟩
Π (A × A) (is-connected n ∘ uncurry _==_)
≃⟨ equiv-Π-r (λ _ → connected-equiv n _) ⟩
Π (A × A) (is-connected' n ∘ uncurry _==_)
≃∎
|
{
"alphanum_fraction": 0.5973278047,
"avg_line_length": 43.41,
"ext": "agda",
"hexsha": "b040b65a2b5b3ff507b30c1c06957417a091364a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sattlerc/HoTT-Agda",
"max_forks_repo_path": "Universe/Trunc/ConnectednessAlt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "sattlerc/HoTT-Agda",
"max_issues_repo_path": "Universe/Trunc/ConnectednessAlt.agda",
"max_line_length": 95,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "sattlerc/HoTT-Agda",
"max_stars_repo_path": "Universe/Trunc/ConnectednessAlt.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1444,
"size": 4341
}
|
module Nat.Binary where
open import Data.Bool hiding (_≤_; _<_; _<?_)
open import Data.Empty
open import Data.List
open import Data.List.Properties
open import Data.Maybe
open import Data.Product
open import Data.Sum
open import Function
open import Nat.Class
open import Nat.Unary
using (ℕ₁)
renaming
(zero to zero₁
; succ to succ₁
; _+_ to _+₁_
; rec to rec₁
; ind to ind₁
; rec-succ to rec₁-succ
)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open ≡-Reasoning
data ℕ₂ : Set where
zero : ℕ₂
pos : List Bool → ℕ₂
ind :
(P : ℕ₂ → Set) →
P zero →
P (pos []) →
(∀ {b bs} → P (pos bs) → P (pos (b ∷ bs))) →
∀ n →
P n
ind P z u d zero = z
ind P z u d (pos []) = u
ind P z u d (pos (b ∷ bs)) = d (ind P z u d (pos bs))
succ⁺ : List Bool → List Bool
succ⁺ [] = false ∷ []
succ⁺ (false ∷ bs) = true ∷ bs
succ⁺ (true ∷ bs) = false ∷ succ⁺ bs
succ : ℕ₂ → ℕ₂
succ zero = pos []
succ (pos bs) = pos (succ⁺ bs)
-- TODO: try to build a rec implementation that computes the
-- predecessor to do unary recursion on binary numbers! However, the
-- predecessor function must return a proof showing that its result is
-- less than its argument, otherwise Agda doesn't know if the
-- recursion will terminate
digitsFold : {B : Set} → (B → Bool → Bool → B) → B → ℕ₂ → ℕ₂ → B
digitsFold f z zero zero =
f z false false
digitsFold f z zero (pos []) =
f z false true
digitsFold f z zero (pos (b₂ ∷ bs₂)) =
digitsFold f (f z false b₂) zero (pos bs₂)
digitsFold f z (pos []) zero =
f z true false
digitsFold f z (pos []) (pos []) =
f z true true
digitsFold f z (pos []) (pos (b₂ ∷ bs₂)) =
digitsFold f (f z true b₂) zero (pos bs₂)
digitsFold f z (pos (b₁ ∷ bs₁)) zero =
digitsFold f (f z b₁ false) (pos bs₁) zero
digitsFold f z (pos (b₁ ∷ bs₁)) (pos []) =
digitsFold f (f z b₁ true) (pos bs₁) zero
digitsFold f z (pos (b₁ ∷ bs₁)) (pos (b₂ ∷ bs₂)) =
digitsFold f (f z b₁ b₂) (pos bs₁) (pos bs₂)
adder : List Bool × Bool → Bool → Bool → List Bool × Bool
adder (bs , c) a b = (c xor (a xor b)) ∷ bs , (c ∧ (a xor b)) ∨ (a ∧ b)
revNormalize : List Bool → ℕ₂ → ℕ₂
revNormalize [] acc = acc
revNormalize (b ∷ rxs) (pos acc) = revNormalize rxs (pos (b ∷ acc))
revNormalize (false ∷ rxs) zero = revNormalize rxs zero
revNormalize (true ∷ rxs) zero = revNormalize rxs (pos [])
_+_ : ℕ₂ → ℕ₂ → ℕ₂
m + n =
let rs , c = digitsFold adder ([] , false) m n
in revNormalize (c ∷ rs) zero
_ : zero + zero ≡ zero
_ =
begin
zero + zero
≡⟨⟩
let rs , c = digitsFold adder ([] , false) zero zero
in revNormalize (c ∷ rs) zero
≡⟨⟩
let rs , c = adder ([] , false) false false
in revNormalize (c ∷ rs) zero
≡⟨⟩
let rs = (false xor (false xor false)) ∷ []
c = (false ∧ (false xor false)) ∨ (false ∧ false)
in revNormalize (c ∷ rs) zero
≡⟨⟩
let rs = false ∷ []
c = false
in revNormalize (c ∷ rs) zero
≡⟨⟩
revNormalize (false ∷ false ∷ []) zero
≡⟨⟩
revNormalize (false ∷ []) zero
≡⟨⟩
revNormalize [] zero
≡⟨⟩
zero
∎
_ : zero + pos [] ≡ pos []
_ =
begin
zero + pos []
≡⟨⟩
let rs , c = digitsFold adder ([] , false) zero (pos [])
in revNormalize (c ∷ rs) zero
≡⟨⟩
let rs , c = adder ([] , false) false true
in revNormalize (c ∷ rs) zero
≡⟨⟩
let rs = (false xor (false xor true)) ∷ []
c = (false ∧ (false xor true)) ∨ (false ∧ true)
in revNormalize (c ∷ rs) zero
≡⟨⟩
let rs = true ∷ []
c = false
in revNormalize (c ∷ rs) zero
≡⟨⟩
revNormalize (false ∷ true ∷ []) zero
≡⟨⟩
revNormalize (true ∷ []) zero
≡⟨⟩
revNormalize [] (pos [])
≡⟨⟩
pos []
∎
_ : zero + pos (false ∷ []) ≡ pos (false ∷ [])
_ =
begin
zero + pos (false ∷ [])
≡⟨⟩
let rs , c = digitsFold adder ([] , false) zero (pos (false ∷ []))
in revNormalize (c ∷ rs) zero
≡⟨⟩
let rs , c = digitsFold adder (adder ([] , false) false false) zero (pos [])
in revNormalize (c ∷ rs) zero
≡⟨⟩
let bs′ = (false xor (false xor false)) ∷ []
c′ = (false ∧ (false xor false)) ∨ (false ∧ false)
rs , c = digitsFold adder (bs′ , c′) zero (pos [])
in revNormalize (c ∷ rs) zero
≡⟨⟩
let rs , c = digitsFold adder (false ∷ [] , false) zero (pos [])
in revNormalize (c ∷ rs) zero
≡⟨⟩
let rs , c = adder (false ∷ [] , false) false true
in revNormalize (c ∷ rs) zero
≡⟨⟩
let rs = (false xor (false xor true)) ∷ false ∷ []
c = (false ∧ (false xor true)) ∨ (false ∧ true)
in revNormalize (c ∷ rs) zero
≡⟨⟩
revNormalize (false ∷ true ∷ false ∷ []) zero
≡⟨⟩
revNormalize (true ∷ false ∷ []) zero
≡⟨⟩
revNormalize (false ∷ []) (pos [])
≡⟨⟩
revNormalize [] (pos (false ∷ []))
≡⟨⟩
pos (false ∷ [])
∎
-- TODO Expand more zero + n examples
reverse-∷ :
{A : Set} {x : A} {xs : List A} →
reverse (x ∷ xs) ≡ reverse xs ++ (x ∷ [])
reverse-∷ {A} {x} {xs} =
begin
reverse (x ∷ xs)
≡⟨⟩
foldl (flip _∷_) [] (x ∷ xs)
≡⟨⟩
foldl (flip _∷_) (flip _∷_ [] x) xs
≡⟨⟩
foldl (flip _∷_) (x ∷ []) xs
≡⟨ {!!} ⟩
foldl (flip _∷_) [] xs ++ (x ∷ [])
≡⟨⟩
reverse xs ++ (x ∷ [])
∎
reverse-∷-++ :
{A : Set} {x : A} {xs ys : List A} →
reverse (x ∷ xs) ++ ys ≡ reverse xs ++ x ∷ ys
reverse-∷-++ {A} {x} {[]} {ys} = refl
reverse-∷-++ {A} {x} {x′ ∷ xs′} {ys} =
begin
reverse (x ∷ x′ ∷ xs′) ++ ys
≡⟨ {!!} ⟩
reverse (x′ ∷ xs′) ++ x ∷ ys
∎
adder-ca-false : ∀ {b bs} → adder (bs , false) false b ≡ (b ∷ bs , false)
adder-ca-false = refl
digitsFold-adder-zeroˡ-carry :
∀ {bs n} → proj₂ (digitsFold adder (bs , false) zero n) ≡ false
digitsFold-adder-zeroˡ-carry {n = zero} = refl
digitsFold-adder-zeroˡ-carry {n = pos []} = refl
digitsFold-adder-zeroˡ-carry {n = pos (b ∷ bs₂)} =
digitsFold-adder-zeroˡ-carry {n = pos bs₂}
digitsFold-adder-zeroˡ-sum :
∀ {rs bs} →
proj₁ (digitsFold adder (rs , false) zero (pos bs)) ≡ true ∷ reverse bs ++ rs
digitsFold-adder-zeroˡ-sum {rs} {[]} = refl
digitsFold-adder-zeroˡ-sum {rs} {b ∷ bs} =
begin
proj₁ (digitsFold adder (rs , false) zero (pos (b ∷ bs)))
≡⟨⟩
proj₁ (digitsFold adder (b ∷ rs , false) zero (pos bs))
≡⟨ digitsFold-adder-zeroˡ-sum {b ∷ rs} {bs} ⟩
true ∷ reverse bs ++ b ∷ rs
≡⟨ {!!} ⟩
true ∷ reverse (b ∷ bs) ++ rs
∎
+-identityˡ : ∀ {n} → zero + n ≡ n
+-identityˡ {zero} = refl
+-identityˡ {pos []} = refl
+-identityˡ {pos (b ∷ bs)} =
begin
zero + pos (b ∷ bs)
≡⟨⟩
let rs , c = digitsFold adder ([] , false) zero (pos (b ∷ bs))
in revNormalize (c ∷ rs) zero
≡⟨⟩
let rs , c = digitsFold adder (adder ([] , false) false b) zero (pos bs)
in revNormalize (c ∷ rs) zero
≡⟨ {!!} ⟩
pos (b ∷ bs)
∎
fromℕ₁ : ℕ₁ → ℕ₂
fromℕ₁ = rec₁ zero succ
fromℕ₁-succ : ∀ n → fromℕ₁ (succ₁ n) ≡ succ (fromℕ₁ n)
fromℕ₁-succ zero₁ = refl
fromℕ₁-succ (succ₁ n) =
begin
fromℕ₁ (succ₁ (succ₁ n))
≡⟨⟩
rec₁ zero succ (succ₁ (succ₁ n))
≡⟨⟩
rec₁ (succ zero) succ (succ₁ n)
≡⟨ rec₁-succ zero succ (succ₁ n) ⟩
succ (rec₁ zero succ (succ₁ n))
≡⟨⟩
succ (fromℕ₁ (succ₁ n))
∎
-- TODO Prove this using algebraic laws!
fromℕ₁-comm-+ : ∀ {m n} → fromℕ₁ (m +₁ n) ≡ fromℕ₁ m + fromℕ₁ n
fromℕ₁-comm-+ {zero₁} {zero₁} = refl
fromℕ₁-comm-+ {zero₁} {succ₁ n} =
begin
fromℕ₁ (zero₁ +₁ succ₁ n)
≡⟨⟩
fromℕ₁ (succ₁ n)
≡⟨ fromℕ₁-succ n ⟩
succ (fromℕ₁ n)
≡⟨ {!!} ⟩
zero + succ (fromℕ₁ n)
≡⟨ cong (zero +_) (sym (fromℕ₁-succ n)) ⟩
fromℕ₁ zero₁ + fromℕ₁ (succ₁ n)
∎
fromℕ₁-comm-+ {succ₁ m} {n} = {!!}
toℕ₁⁺ : List Bool → ℕ₁
toℕ₁⁺ [] = succ₁ zero₁
toℕ₁⁺ (b ∷ bs) = (if b then succ₁ else id) (toℕ₁⁺ bs +₁ toℕ₁⁺ bs)
toℕ₁ : ℕ₂ → ℕ₁
toℕ₁ zero = zero₁
toℕ₁ (pos bs) = toℕ₁⁺ bs
toℕ₁⁺-succ : ∀ bs → toℕ₁⁺ (succ⁺ bs) ≡ succ₁ (toℕ₁⁺ bs)
toℕ₁⁺-succ [] = refl
toℕ₁⁺-succ (false ∷ bs) = refl
toℕ₁⁺-succ (true ∷ bs) =
begin
toℕ₁⁺ (succ⁺ (true ∷ bs))
≡⟨⟩
toℕ₁⁺ (false ∷ succ⁺ bs)
≡⟨⟩
toℕ₁⁺ (succ⁺ bs) +₁ toℕ₁⁺ (succ⁺ bs)
≡⟨ cong (λ x → x +₁ toℕ₁⁺ (succ⁺ bs)) (toℕ₁⁺-succ bs) ⟩
succ₁ (toℕ₁⁺ bs) +₁ toℕ₁⁺ (succ⁺ bs)
≡⟨ cong (λ x → succ₁ (toℕ₁⁺ bs) +₁ x) (toℕ₁⁺-succ bs) ⟩
succ₁ (toℕ₁⁺ bs) +₁ succ₁ (toℕ₁⁺ bs)
≡⟨ +-succˡ {m = toℕ₁⁺ bs} ⟩
succ₁ (toℕ₁⁺ bs +₁ succ₁ (toℕ₁⁺ bs))
≡⟨ cong succ₁ (+-succʳ {m = toℕ₁⁺ bs}) ⟩
succ₁ (succ₁ (toℕ₁⁺ bs +₁ toℕ₁⁺ bs))
≡⟨⟩
succ₁ (toℕ₁⁺ (true ∷ bs))
∎
toℕ₁-succ : ∀ n → toℕ₁ (succ n) ≡ succ₁ (toℕ₁ n)
toℕ₁-succ zero = refl
toℕ₁-succ (pos bs) = toℕ₁⁺-succ bs
fromToℕ₁ : ∀ n → toℕ₁ (fromℕ₁ n) ≡ n
fromToℕ₁ zero₁ = refl
fromToℕ₁ (succ₁ n) =
begin
toℕ₁ (fromℕ₁ (succ₁ n))
≡⟨ cong toℕ₁ (fromℕ₁-succ n) ⟩
toℕ₁ (succ (fromℕ₁ n))
≡⟨ toℕ₁-succ (fromℕ₁ n) ⟩
succ₁ (toℕ₁ (fromℕ₁ n))
≡⟨ cong succ₁ (fromToℕ₁ n) ⟩
succ₁ n
∎
toFromℕ₁⁺ : ∀ bs → fromℕ₁ (toℕ₁⁺ bs) ≡ pos bs
toFromℕ₁⁺ [] = refl
toFromℕ₁⁺ (false ∷ bs) =
begin
fromℕ₁ (toℕ₁⁺ (false ∷ bs))
≡⟨⟩
fromℕ₁ (toℕ₁⁺ bs +₁ toℕ₁⁺ bs)
-- TODO Fill in these holes!
≡⟨ {!!} ⟩
fromℕ₁ (toℕ₁⁺ bs) + fromℕ₁ (toℕ₁⁺ bs)
≡⟨ cong (λ x → x + fromℕ₁ (toℕ₁⁺ bs)) (toFromℕ₁⁺ bs) ⟩
pos bs + fromℕ₁ (toℕ₁⁺ bs)
≡⟨ cong (λ x → pos bs + x) (toFromℕ₁⁺ bs) ⟩
pos bs + pos bs
≡⟨ {!!} ⟩
pos (false ∷ bs)
∎
toFromℕ₁⁺ (true ∷ bs) = {!!}
toFromℕ₁ : ∀ n → fromℕ₁ (toℕ₁ n) ≡ n
toFromℕ₁ zero = refl
toFromℕ₁ (pos bs) = toFromℕ₁⁺ bs
instance
Nat-ℕ₂ : Nat ℕ₂
Nat-ℕ₂ = record
{ zero = zero
; succ = succ
; ind = {!!}
; _+_ = _+_
; +-zero = +-identityˡ
; +-succ = {!!}
}
|
{
"alphanum_fraction": 0.5487868921,
"avg_line_length": 25.8021680217,
"ext": "agda",
"hexsha": "9b4e27df7fed63f6627fa97b05d5b7f771cd70c2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-28T12:49:47.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-28T12:49:47.000Z",
"max_forks_repo_head_hexsha": "1b51e83acf193a556a61d44a4585a6467a383fa3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "iblech/agda-quotients",
"max_forks_repo_path": "src/Nat/Binary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b51e83acf193a556a61d44a4585a6467a383fa3",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "iblech/agda-quotients",
"max_issues_repo_path": "src/Nat/Binary.agda",
"max_line_length": 80,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b51e83acf193a556a61d44a4585a6467a383fa3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "iblech/agda-quotients",
"max_stars_repo_path": "src/Nat/Binary.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-29T13:10:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-29T13:10:27.000Z",
"num_tokens": 4158,
"size": 9521
}
|
{-# OPTIONS --without-K #-}
module F1b where
open import Data.Unit
open import Data.Sum hiding (map; [_,_])
open import Data.Product hiding (map; ,_)
open import Function using (flip)
open import Relation.Binary.Core using (IsEquivalence; Reflexive; Symmetric; Transitive)
open import Relation.Binary
open import Groupoid
infixr 90 _⊗_
infixr 80 _⊕_
infixr 60 _∘_
infix 30 _⟷_
---------------------------------------------------------------------------
-- Paths
-- Path relation should be an equivalence
data Path {A : Set} : A → A → Set where
_⇛_ : (x : A) → (y : A) → Path x y
data _≣⇛_ {A : Set} {a b : A} (x : Path a b) : Path a b → Set where
refl⇛ : x ≣⇛ x
id⇛ : {A : Set} → (a : A) → Path a a
id⇛ a = a ⇛ a
ap : {A B : Set} → (f : A → B) → {a a' : A} → Path a a' → Path (f a) (f a')
ap f (a ⇛ a') = (f a) ⇛ (f a')
_∙⇛_ : {A : Set} {a b c : A} → Path b c → Path a b → Path a c
(b ⇛ c) ∙⇛ (a ⇛ .b) = a ⇛ c
_⇚ : {A : Set} {a b : A} → Path a b → Path b a
(x ⇛ y) ⇚ = y ⇛ x
lid⇛ : {A : Set} {x y : A} (α : Path x y) → (id⇛ y ∙⇛ α) ≣⇛ α
lid⇛ (x ⇛ y) = refl⇛
rid⇛ : {A : Set} {x y : A} (α : Path x y) → (α ∙⇛ id⇛ x) ≣⇛ α
rid⇛ (x ⇛ y) = refl⇛
assoc⇛ : {A : Set} {w x y z : A} (α : Path y z) (β : Path x y) (δ : Path w x) → ((α ∙⇛ β) ∙⇛ δ) ≣⇛ (α ∙⇛ (β ∙⇛ δ))
assoc⇛ (y ⇛ z) (x ⇛ .y) (w ⇛ .x) = refl⇛
l⇚ : {A : Set} {x y : A} (α : Path x y) → ((α ⇚) ∙⇛ α) ≣⇛ id⇛ x
l⇚ (x ⇛ y) = refl⇛
r⇚ : {A : Set} {x y : A} (α : Path x y) → (α ∙⇛ (α ⇚)) ≣⇛ id⇛ y
r⇚ (x ⇛ y) = refl⇛
sym⇛ : {A : Set} {x y : A} {α β : Path x y} → α ≣⇛ β → β ≣⇛ α
sym⇛ refl⇛ = refl⇛
trans⇛ : {A : Set} {x y : A} {α β δ : Path x y} → α ≣⇛ β → β ≣⇛ δ → α ≣⇛ δ
trans⇛ refl⇛ refl⇛ = refl⇛
equiv≣⇛ : {A : Set} {x y : A} → IsEquivalence {_} {_} {Path x y} (_≣⇛_)
equiv≣⇛ = record { refl = refl⇛; sym = sym⇛; trans = trans⇛ }
resp≣⇛ : {A : Set} {x y z : A} {f h : Path y z} {g i : Path x y} →
f ≣⇛ h → g ≣⇛ i → (f ∙⇛ g) ≣⇛ (h ∙⇛ i)
resp≣⇛ refl⇛ refl⇛ = refl⇛
------------------------------------------------------------------------------
-- pi types with exactly one level of reciprocals
data B0 : Set where
ONE : B0
PLUS0 : B0 → B0 → B0
TIMES0 : B0 → B0 → B0
-- interpretation of B0 as discrete groupoids
record 0-type : Set₁ where
constructor G₀
field
∣_∣₀ : Set
open 0-type public
plus : 0-type → 0-type → 0-type
plus t₁ t₂ = G₀ (∣ t₁ ∣₀ ⊎ ∣ t₂ ∣₀)
times : 0-type → 0-type → 0-type
times t₁ t₂ = G₀ (∣ t₁ ∣₀ × ∣ t₂ ∣₀)
⟦_⟧₀ : B0 → 0-type
⟦ ONE ⟧₀ = G₀ ⊤
⟦ PLUS0 b₁ b₂ ⟧₀ = plus ⟦ b₁ ⟧₀ ⟦ b₂ ⟧₀
⟦ TIMES0 b₁ b₂ ⟧₀ = times ⟦ b₁ ⟧₀ ⟦ b₂ ⟧₀
ı₀ : B0 → Set
ı₀ b = ∣ ⟦ b ⟧₀ ∣₀
point : (b : B0) → ı₀ b
point ONE = tt
point (PLUS0 b _) = inj₁ (point b)
point (TIMES0 b₀ b₁) = point b₀ , point b₁
-- isos
data _⟷_ : B0 → B0 → Set where
-- +
swap₊ : { b₁ b₂ : B0 } → PLUS0 b₁ b₂ ⟷ PLUS0 b₂ b₁
assocl₊ : { b₁ b₂ b₃ : B0 } → PLUS0 b₁ (PLUS0 b₂ b₃) ⟷ PLUS0 (PLUS0 b₁ b₂) b₃
assocr₊ : { b₁ b₂ b₃ : B0 } → PLUS0 (PLUS0 b₁ b₂) b₃ ⟷ PLUS0 b₁ (PLUS0 b₂ b₃)
-- *
unite⋆ : { b : B0 } → TIMES0 ONE b ⟷ b
uniti⋆ : { b : B0 } → b ⟷ TIMES0 ONE b
swap⋆ : { b₁ b₂ : B0 } → TIMES0 b₁ b₂ ⟷ TIMES0 b₂ b₁
assocl⋆ : { b₁ b₂ b₃ : B0 } → TIMES0 b₁ (TIMES0 b₂ b₃) ⟷ TIMES0 (TIMES0 b₁ b₂) b₃
assocr⋆ : { b₁ b₂ b₃ : B0 } → TIMES0 (TIMES0 b₁ b₂) b₃ ⟷ TIMES0 b₁ (TIMES0 b₂ b₃)
-- * distributes over +
dist : { b₁ b₂ b₃ : B0 } →
TIMES0 (PLUS0 b₁ b₂) b₃ ⟷ PLUS0 (TIMES0 b₁ b₃) (TIMES0 b₂ b₃)
factor : { b₁ b₂ b₃ : B0 } →
PLUS0 (TIMES0 b₁ b₃) (TIMES0 b₂ b₃) ⟷ TIMES0 (PLUS0 b₁ b₂) b₃
-- congruence
id⟷ : { b : B0 } → b ⟷ b
sym : { b₁ b₂ : B0 } → (b₁ ⟷ b₂) → (b₂ ⟷ b₁)
_∘_ : { b₁ b₂ b₃ : B0 } → (b₁ ⟷ b₂) → (b₂ ⟷ b₃) → (b₁ ⟷ b₃)
_⊕_ : { b₁ b₂ b₃ b₄ : B0 } →
(b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (PLUS0 b₁ b₂ ⟷ PLUS0 b₃ b₄)
_⊗_ : { b₁ b₂ b₃ b₄ : B0 } →
(b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (TIMES0 b₁ b₂ ⟷ TIMES0 b₃ b₄)
{--
--}
-- interpret isos as paths
eval0 : {b₁ b₂ : B0} → (c : b₁ ⟷ b₂) → (x : ı₀ b₁) → ı₀ b₂
eval0 _ = {!!}
--comb0 : {b₁ b₂ : B0} → (c : b₁ ⟷ b₂) → (x : ı₀ b₁) → Path x (eval0 c x)
--comb0 _ = ?
------------------------------------------------------------------------------
-- interpretation of B1 types as 1-groupoids
data B1 : Set where
LIFT0 : B0 → B1
PLUS1 : B1 → B1 → B1
TIMES1 : B1 → B1 → B1
RECIP1 : B0 → B1
open 1Groupoid
allPaths : Set → 1Groupoid
allPaths a = record
{ set = a
; _↝_ = Path
; _≈_ = _≣⇛_
; id = λ {x} → id⇛ x
; _∘_ = _∙⇛_
; _⁻¹ = _⇚
; lneutr = lid⇛
; rneutr = rid⇛
; assoc = assoc⇛
; linv = l⇚
; rinv = r⇚
; equiv = equiv≣⇛
; ∘-resp-≈ = resp≣⇛}
⟦_⟧₁ : B1 → 1Groupoid
⟦ LIFT0 b0 ⟧₁ = discrete (ı₀ b0)
⟦ PLUS1 b₁ b₂ ⟧₁ = ⟦ b₁ ⟧₁ ⊎G ⟦ b₂ ⟧₁
⟦ TIMES1 b₁ b₂ ⟧₁ = ⟦ b₁ ⟧₁ ×G ⟦ b₂ ⟧₁
⟦ RECIP1 b0 ⟧₁ = allPaths (ı₀ b0)
ı₁ : B1 → Set
ı₁ b = set ⟦ b ⟧₁
test10 = ⟦ LIFT0 ONE ⟧₁
test11 = ⟦ LIFT0 (PLUS0 ONE ONE) ⟧₁
test12 = ⟦ RECIP1 (PLUS0 ONE ONE) ⟧₁
-- interpret isos as functors
data _⟷₁_ : B1 → B1 → Set where
-- +
swap₊ : { b₁ b₂ : B1 } → PLUS1 b₁ b₂ ⟷₁ PLUS1 b₂ b₁
{--
assocl₊ : { b₁ b₂ b₃ : B1 } → PLUS b₁ (PLUS b₂ b₃) ⟷₁ PLUS (PLUS b₁ b₂) b₃
assocr₊ : { b₁ b₂ b₃ : B1 } → PLUS (PLUS b₁ b₂) b₃ ⟷₁ PLUS b₁ (PLUS b₂ b₃)
-- *
--}
unite⋆ : { b : B1 } → TIMES1 (LIFT0 ONE) b ⟷₁ b
uniti⋆ : { b : B1 } → b ⟷₁ TIMES1 (LIFT0 ONE) b
{--
swap⋆ : { b₁ b₂ : B } → TIMES b₁ b₂ ⟷₁ TIMES b₂ b₁
assocl⋆ : { b₁ b₂ b₃ : B } → TIMES b₁ (TIMES b₂ b₃) ⟷₁ TIMES (TIMES b₁ b₂) b₃
assocr⋆ : { b₁ b₂ b₃ : B } → TIMES (TIMES b₁ b₂) b₃ ⟷₁ TIMES b₁ (TIMES b₂ b₃)
-- * distributes over +
dist : { b₁ b₂ b₃ : B } →
TIMES (PLUS b₁ b₂) b₃ ⟷₁ PLUS (TIMES b₁ b₃) (TIMES b₂ b₃)
factor : { b₁ b₂ b₃ : B } →
PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) ⟷₁ TIMES (PLUS b₁ b₂) b₃
-- congruence
id⟷₁ : { b : B } → b ⟷₁ b
sym : { b₁ b₂ : B } → (b₁ ⟷₁ b₂) → (b₂ ⟷₁ b₁)
_∘_ : { b₁ b₂ b₃ : B } → (b₁ ⟷₁ b₂) → (b₂ ⟷₁ b₃) → (b₁ ⟷₁ b₃)
_⊕_ : { b₁ b₂ b₃ b₄ : B } →
(b₁ ⟷₁ b₃) → (b₂ ⟷₁ b₄) → (PLUS b₁ b₂ ⟷₁ PLUS b₃ b₄)
_⊗_ : { b₁ b₂ b₃ b₄ : B } →
(b₁ ⟷₁ b₃) → (b₂ ⟷₁ b₄) → (TIMES b₁ b₂ ⟷₁ TIMES b₃ b₄)
η⋆ : (b : B0) → LIFT0 ONE ⟷₁ TIMES1 (LIFT0 b) (RECIP1 b)
ε⋆ : (b : B0) → TIMES1 (LIFT0 b) (RECIP1 b) ⟷₁ LIFT0 ONE
--}
record 1-functor (A B : 1Groupoid) : Set where
constructor 1F
private module A = 1Groupoid A
private module B = 1Groupoid B
field
F₀ : set A → set B
F₁ : ∀ {X Y : set A} → A [ X , Y ] → B [ F₀ X , F₀ Y ]
-- identity : ∀ {X} → B._≈_ (F₁ (A.id {X})) B.id
-- F-resp-≈ : ∀ {X Y} {F G : A [ X , Y ]} → A._≈_ F G → B._≈_ (F₁ F) (F₁ G)
open 1-functor public
ipath : (b : B1) → ı₁ b → ı₁ b → Set
ipath b x y = Path {ı₁ b} x y
swap⊎ : {A B : Set} → A ⊎ B → B ⊎ A
swap⊎ (inj₁ a) = inj₂ a
swap⊎ (inj₂ b) = inj₁ b
intro1⋆ : {b : B1} {x y : ı₁ b} → ipath b x y → ipath (TIMES1 (LIFT0 ONE) b) (tt , x) (tt , y)
intro1⋆ (y ⇛ z) = (tt , y) ⇛ (tt , z)
objη⋆ : (b : B0) → ı₁ (LIFT0 ONE) → ı₁ (TIMES1 (LIFT0 b) (RECIP1 b))
objη⋆ b tt = point b , point b
objε⋆ : (b : B0) → ı₁ (TIMES1 (LIFT0 b) (RECIP1 b)) → ı₁ (LIFT0 ONE)
objε⋆ b (x , y) = tt
elim1∣₁ : (b : B1) → ı₁ (TIMES1 (LIFT0 ONE) b) → ı₁ b
elim1∣₁ b (tt , x) = x
intro1∣₁ : (b : B1) → ı₁ b → ı₁ (TIMES1 (LIFT0 ONE) b)
intro1∣₁ b x = (tt , x)
swapF : {b₁ b₂ : B1} →
let G = ⟦ b₁ ⟧₁ ⊎G ⟦ b₂ ⟧₁
G' = ⟦ b₂ ⟧₁ ⊎G ⟦ b₁ ⟧₁ in
{X Y : set G} → G [ X , Y ] → G' [ swap⊎ X , swap⊎ Y ]
swapF {X = inj₁ _} {inj₁ _} f = f
swapF {X = inj₁ _} {inj₂ _} ()
swapF {X = inj₂ _} {inj₁ _} ()
swapF {X = inj₂ _} {inj₂ _} f = f
{-
eta : (b : B0) → List (ipath (LIFT0 ONE)) → List (ipath (TIMES1 (LIFT0 b) (RECIP1 b)))
-- note how the input list is not used at all!
eta b _ = prod (λ a a' → _↝_ (a , tt) (a' , tt)) (elems0 b) (elems0 b)
eps : (b : B0) → ipath (TIMES1 (LIFT0 b) (RECIP1 b)) → ipath (LIFT0 ONE)
eps b0 (a ⇛ b) = tt ⇛ tt
-}
Funite⋆ : {b₁ : B1} → ∀ {X Y : set (discrete (ı₀ ONE) ×G ⟦ b₁ ⟧₁)} → DPath (proj₁ X) (proj₁ Y) × (_↝_ ⟦ b₁ ⟧₁) (proj₂ X) (proj₂ Y) → _↝_ ⟦ b₁ ⟧₁ (proj₂ X) (proj₂ Y)
Funite⋆ {b₁} {tt , _} {tt , _} (reflD , y) = y
Funiti⋆ : {b₁ : B1} → ∀ {X Y : set (discrete (ı₀ ONE) ×G ⟦ b₁ ⟧₁)} → _↝_ ⟦ b₁ ⟧₁ (proj₂ X) (proj₂ Y) → DPath (proj₁ X) (proj₁ Y) × (_↝_ ⟦ b₁ ⟧₁) (proj₂ X) (proj₂ Y)
Funiti⋆ y = reflD , y
mutual
eval : {b₁ b₂ : B1} → (b₁ ⟷₁ b₂) → 1-functor ⟦ b₁ ⟧₁ ⟦ b₂ ⟧₁
eval (swap₊ {b₁} {b₂}) = 1F swap⊎ (λ {X Y} → swapF {b₁} {b₂} {X} {Y})
eval (unite⋆ {b}) = 1F (elim1∣₁ b) (Funite⋆ {b})
eval (uniti⋆ {b}) = 1F (intro1∣₁ b) (Funiti⋆ {b})
-- eval (η⋆ b) = F₁ (objη⋆ b) (eta b )
-- eval (ε⋆ b) = F₁ (objε⋆ b) (map (eps b))
evalB : {b₁ b₂ : B1} → (b₁ ⟷₁ b₂) → 1-functor ⟦ b₂ ⟧₁ ⟦ b₁ ⟧₁
evalB (swap₊ {b₁} {b₂}) = 1F swap⊎ ((λ {X Y} → swapF {b₂} {b₁} {X} {Y}))
evalB (unite⋆ {b}) = 1F (intro1∣₁ b) (Funiti⋆ {b})
evalB (uniti⋆ {b}) = 1F (elim1∣₁ b) (Funite⋆ {b})
-- evalB (η⋆ b) = F₁ (objε⋆ b) (map (eps b))
-- evalB (ε⋆ b) = F₁ (objη⋆ b) (eta b)
{- eval assocl₊ = ? -- : { b₁ b₂ b₃ : B } → PLUS b₁ (PLUS b₂ b₃) ⟷₁ PLUS (PLUS b₁ b₂) b₃
eval assocr₊ = ? -- : { b₁ b₂ b₃ : B } → PLUS (PLUS b₁ b₂) b₃ ⟷₁ PLUS b₁ (PLUS b₂ b₃)
eval uniti⋆ = ? -- : { b : B } → b ⟷₁ TIMES ONE b
eval swap⋆ = ? -- : { b₁ b₂ : B } → TIMES b₁ b₂ ⟷₁ TIMES b₂ b₁
eval assocl⋆ = ? -- : { b₁ b₂ b₃ : B } → TIMES b₁ (TIMES b₂ b₃) ⟷₁ TIMES (TIMES b₁ b₂) b₃
eval assocr⋆ = ? -- : { b₁ b₂ b₃ : B } → TIMES (TIMES b₁ b₂) b₃ ⟷₁ TIMES b₁ (TIMES b₂ b₃)
eval dist = ? -- : { b₁ b₂ b₃ : B } → TIMES (PLUS b₁ b₂) b₃ ⟷₁ PLUS (TIMES b₁ b₃) (TIMES b₂ b₃)
eval factor = ? -- : { b₁ b₂ b₃ : B } → PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) ⟷₁ TIMES (PLUS b₁ b₂) b₃
eval id⟷₁ = ? -- : { b : B } → b ⟷₁ b
eval (sym c) = ? -- : { b₁ b₂ : B } → (b₁ ⟷₁ b₂) → (b₂ ⟷₁ b₁)
eval (c₁ ∘ c₂) = ? -- : { b₁ b₂ b₃ : B } → (b₁ ⟷₁ b₂) → (b₂ ⟷₁ b₃) → (b₁ ⟷₁ b₃)
eval (c₁ ⊕ c₂) = ? -- : { b₁ b₂ b₃ b₄ : B } → (b₁ ⟷₁ b₃) → (b₂ ⟷₁ b₄) → (PLUS b₁ b₂ ⟷₁ PLUS b₃ b₄)
eval (c₁ ⊗ c₂) = ? -- : { b₁ b₂ b₃ b₄ : B } → (b₁ ⟷₁ b₃) → (b₂ ⟷₁ b₄) → (TIMES b₁ b₂ ⟷₁ TIMES b₃ b₄)
---------------------------------------------------------------------------
--}
|
{
"alphanum_fraction": 0.4762188462,
"avg_line_length": 33.0196721311,
"ext": "agda",
"hexsha": "059c2bc4e7654b4e491f812490b96dce2b712ec6",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "F1b.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "F1b.agda",
"max_line_length": 168,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "F1b.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 5461,
"size": 10071
}
|
module UnicodeEllipsis where
f : {A B : Set} → (A → B) → A → B
f g a with g a
… | x = x
|
{
"alphanum_fraction": 0.5222222222,
"avg_line_length": 12.8571428571,
"ext": "agda",
"hexsha": "c1dd6cface4204044348625770ee186e1885cc3f",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/UnicodeEllipsis.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/UnicodeEllipsis.agda",
"max_line_length": 33,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/UnicodeEllipsis.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 39,
"size": 90
}
|
module LineEndings.Unix where
postulate ThisWorks : Set
|
{
"alphanum_fraction": 0.8245614035,
"avg_line_length": 14.25,
"ext": "agda",
"hexsha": "7c3d41c54287b85768e669c14d4a122f3128fa03",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/LineEndings/Unix.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/LineEndings/Unix.agda",
"max_line_length": 29,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/LineEndings/Unix.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 15,
"size": 57
}
|
{-# OPTIONS --without-K --safe #-}
open import Level
open import Categories.Category.Core using (Category)
open import Categories.Category
open import Categories.Monad
module Categories.Adjoint.Construction.Adjunctions {o ℓ e} {C : Category o ℓ e} (M : Monad C) where
open Category C
open import Categories.Adjoint
open import Categories.Functor
open import Categories.Morphism
open import Categories.Functor.Properties
open import Categories.NaturalTransformation.Core
open import Categories.NaturalTransformation.NaturalIsomorphism -- using (_≃_; unitorʳ; unitorˡ)
open import Categories.Morphism.Reasoning as MR
open import Categories.Tactic.Category
-- three things:
-- 1. the category of adjunctions splitting a given Monad
-- 2. the proof that EM(M) is the terminal object here
-- 3. the proof that KL(M) is the initial object here
record SplitObj : Set (suc o ⊔ suc ℓ ⊔ suc e) where
field
D : Category o ℓ e
F : Functor C D
G : Functor D C
adj : F ⊣ G
eqM : G ∘F F ≃ Monad.F M
record Split⇒ (X Y : SplitObj) : Set (suc o ⊔ suc ℓ ⊔ suc e) where
constructor Splitc⇒
private
module X = SplitObj X
module Y = SplitObj Y
field
H : Functor X.D Y.D
HF≃F' : H ∘F X.F ≃ Y.F
G'H≃G : Y.G ∘F H ≃ X.G
Split : Monad C → Category _ _ _
Split M = record
{ Obj = SplitObj
; _⇒_ = Split⇒
; _≈_ = λ U V → Split⇒.H U ≃ Split⇒.H V
; id = split-id
; _∘_ = comp
; assoc = λ { {f = f} {g = g} {h = h} → associator (Split⇒.H f) (Split⇒.H g) (Split⇒.H h) }
; sym-assoc = λ { {f = f} {g = g} {h = h} → sym-associator (Split⇒.H f) (Split⇒.H g) (Split⇒.H h) }
; identityˡ = unitorˡ
; identityʳ = unitorʳ
; identity² = unitor²
; equiv = record { refl = refl ; sym = sym ; trans = trans }
; ∘-resp-≈ = _ⓘₕ_
}
where
open NaturalTransformation
split-id : {A : SplitObj} → Split⇒ A A
split-id = record
{ H = Categories.Functor.id
; HF≃F' = unitorˡ
; G'H≃G = unitorʳ
}
comp : {A B X : SplitObj} → Split⇒ B X → Split⇒ A B → Split⇒ A X
comp {A = A} {B = B} {X = X} (Splitc⇒ Hᵤ HF≃F'ᵤ G'H≃Gᵤ) (Splitc⇒ Hᵥ HF≃F'ᵥ G'H≃Gᵥ) = record
{ H = Hᵤ ∘F Hᵥ
; HF≃F' = HF≃F'ᵤ ⓘᵥ (Hᵤ ⓘˡ HF≃F'ᵥ) ⓘᵥ associator (SplitObj.F A) Hᵥ Hᵤ
; G'H≃G = G'H≃Gᵥ ⓘᵥ (G'H≃Gᵤ ⓘʳ Hᵥ) ⓘᵥ sym-associator Hᵥ Hᵤ (SplitObj.G X)
}
open import Categories.Object.Terminal (Split M)
open import Categories.Object.Initial (Split M)
open import Categories.Category.Construction.EilenbergMoore
open import Categories.Category.Construction.Kleisli
EM-object : SplitObj
EM-object = record { D = {! EilenbergMoore M !}
; F = {! !}
; G = {! !}
; adj = {! !}
; eqM = {! !}
}
EM-terminal : IsTerminal EM-object
EM-terminal = {! !}
|
{
"alphanum_fraction": 0.6146657081,
"avg_line_length": 31.2584269663,
"ext": "agda",
"hexsha": "1e1537136e6cb01decf8eafdd9e180ce0a5ed8ee",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "cfa6aefd3069d4db995191b458c886edcfba8294",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "tetrapharmakon/agda-categories",
"max_forks_repo_path": "src/Categories/Adjoint/Construction/Adjunctions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cfa6aefd3069d4db995191b458c886edcfba8294",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "tetrapharmakon/agda-categories",
"max_issues_repo_path": "src/Categories/Adjoint/Construction/Adjunctions.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cfa6aefd3069d4db995191b458c886edcfba8294",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "tetrapharmakon/agda-categories",
"max_stars_repo_path": "src/Categories/Adjoint/Construction/Adjunctions.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1053,
"size": 2782
}
|
module Dave.Structures.Definitions where
open import Dave.Equality public
op₁ : Set → Set
op₁ A = A → A
op₂ : Set → Set
op₂ A = A → A → A
associative : {A : Set} → op₂ A → Set
associative _·_ = ∀ m n p → (m · n) · p ≡ m · (n · p)
commutative : {A : Set} → op₂ A → Set
commutative _·_ = ∀ m n → m · n ≡ n · m
left-identity : {A : Set} → op₂ A → (e : A) → Set
left-identity _·_ e = ∀ m → e · m ≡ m
right-identity : {A : Set} → op₂ A → (e : A) → Set
right-identity _·_ e = ∀ m → m · e ≡ m
|
{
"alphanum_fraction": 0.4936014625,
"avg_line_length": 27.35,
"ext": "agda",
"hexsha": "af9e804f95385034508198bd150ed74f0496bccc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DavidStahl97/formal-proofs",
"max_forks_repo_path": "Dave/Structures/Definitions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DavidStahl97/formal-proofs",
"max_issues_repo_path": "Dave/Structures/Definitions.agda",
"max_line_length": 57,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DavidStahl97/formal-proofs",
"max_stars_repo_path": "Dave/Structures/Definitions.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 217,
"size": 547
}
|
open import MLib.Algebra.PropertyCode
open import MLib.Algebra.PropertyCode.Structures
using (bimonoidCode; BimonoidK; +; *; 0#; 1#)
module MLib.Algebra.Operations {c ℓ} (struct : Struct bimonoidCode c ℓ) where
open import MLib.Prelude
open import Data.Fin.Permutation as Perm using (Permutation; Permutation′; _⟨$⟩ʳ_; _⟨$⟩ˡ_)
import Data.Fin.Permutation.Components as PC
open Struct struct
open EqReasoning setoid
--------------------------------------------------------------------------------
-- Nicer names for operations
--------------------------------------------------------------------------------
infixl 5 _+′_
infixl 6 _*′_
_+′_ = ⟦ + ⟧
_*′_ = ⟦ * ⟧
0′ = ⟦ 0# ⟧
1′ = ⟦ 1# ⟧
--------------------------------------------------------------------------------
-- Table stuff
--------------------------------------------------------------------------------
module _ {n} where
open Setoid (Table.setoid setoid n) public
using ()
renaming (_≈_ to _≋_)
_≋′_ : ∀ {m n} → Table Carrier m → Table Carrier n → Set ℓ
_≋′_ = Table.Pointwise′ _≈_
open Table using (head; tail; rearrange; fromList; toList; _≗_; select)
--------------------------------------------------------------------------------
-- Operations
--------------------------------------------------------------------------------
sumₜ : ∀ {n} → Table Carrier n → Carrier
sumₜ = Table.foldr _+′_ 0′
sumₗ : List Carrier → Carrier
sumₗ = List.foldr _+′_ 0′
-- An alternative mathematical-style syntax for sumₜ
infixl 10 sumₜ-syntax
sumₜ-syntax : ∀ n → (Fin n → Carrier) → Carrier
sumₜ-syntax _ = sumₜ ∘ Table.tabulate
syntax sumₜ-syntax n (λ i → x) = ∑[ i < n ] x
--------------------------------------------------------------------------------
-- Properties
--------------------------------------------------------------------------------
-- When summing over a function from a finite set, we can pull out any value and move it to the front.
sumₜ-punchIn :
⦃ props : Has (associative on + ∷ commutative on + ∷ []) ⦄ →
∀ {n} t (i : Fin (suc n)) → sumₜ t ≈ lookup t i +′ sumₜ (Table.rearrange (Fin.punchIn i) t)
sumₜ-punchIn f zero = refl
sumₜ-punchIn {zero} t (suc ())
sumₜ-punchIn ⦃ props ⦄ {suc n} t (suc i) =
let x = head t
y = lookup t (suc i)
z = sumₜ (rearrange (Fin.punchIn i) (tail t))
in begin
x +′ sumₜ (tail t) ≈⟨ cong + refl (sumₜ-punchIn (tail t) i) ⟩
x +′ (y +′ z) ≈⟨ sym (from props (associative on +) _ _ _) ⟩
(x +′ y) +′ z ≈⟨ cong + (from props (commutative on +) _ _) refl ⟩
(y +′ x) +′ z ≈⟨ from props (associative on +) _ _ _ ⟩
y +′ (x +′ z) ∎
-- '_≈_' is a congruence over 'sumTable n'.
sumₜ-cong : ∀ {n} {t t′ : Table Carrier n} → t ≋ t′ → sumₜ t ≈ sumₜ t′
sumₜ-cong = Table.foldr-cong setoid (cong +)
-- A version of 'sumₜ-cong' with heterogeneous table sizes
sumₜ-cong′ : ∀ {m n} {t : Table Carrier m} {t′ : Table Carrier n} → t ≋′ t′ → sumₜ t ≈ sumₜ t′
sumₜ-cong′ {m} (≡.refl , q) = sumₜ-cong λ i → q i i ≅.refl
-- '_≡_' is a congruence over 'sum n'.
sumₜ-cong≡ : ∀ {n} {t t′ : Table Carrier n} → t ≗ t′ → sumₜ t ≡ sumₜ t′
sumₜ-cong≡ = Table.foldr-cong (≡.setoid Carrier) (≡.cong₂ _+′_)
-- The sum over the constantly zero function is zero.
sumₜ-zero :
⦃ props : Has₁ (0# is leftIdentity for +) ⦄ →
∀ n → sumₜ (Table.replicate {n} 0′) ≈ 0′
sumₜ-zero zero = refl
sumₜ-zero ⦃ props ⦄ (suc n) =
begin
0′ +′ sumₜ (Table.replicate {n} 0′) ≈⟨ from props (0# is leftIdentity for +) _ ⟩
sumₜ (Table.replicate {n} 0′) ≈⟨ sumₜ-zero n ⟩
0′ ∎
-- The '∑' operator distributes over addition.
∑-+′-hom :
⦃ props : Has (0# is leftIdentity for + ∷ associative on + ∷ commutative on + ∷ []) ⦄ →
∀ n (f g : Fin n → Carrier) → ∑[ i < n ] f i +′ ∑[ i < n ] g i ≈ ∑[ i < n ] (f i +′ g i)
∑-+′-hom ⦃ props ⦄ zero f g = from props (0# is leftIdentity for +) _
∑-+′-hom ⦃ props ⦄ (suc n) f g =
let fz = f zero
gz = g zero
∑f = ∑[ i < n ] f (suc i)
∑g = ∑[ i < n ] g (suc i)
∑fg = ∑[ i < n ] (f (suc i) +′ g (suc i))
in begin
(fz +′ ∑f) +′ (gz +′ ∑g) ≈⟨ from props (associative on +) _ _ _ ⟩
fz +′ (∑f +′ (gz +′ ∑g)) ≈⟨ cong + refl (sym (from props (associative on +) _ _ _)) ⟩
fz +′ ((∑f +′ gz) +′ ∑g) ≈⟨ cong + refl (cong + (from props (commutative on +) _ _) refl) ⟩
fz +′ ((gz +′ ∑f) +′ ∑g) ≈⟨ cong + refl (from props (associative on +) _ _ _) ⟩
fz +′ (gz +′ (∑f +′ ∑g)) ≈⟨ cong + refl (cong + refl (∑-+′-hom n _ _)) ⟩
fz +′ (gz +′ ∑fg) ≈⟨ sym (from props (associative on +) _ _ _) ⟩
fz +′ gz +′ ∑fg ∎
-- The '∑' operator commutes with itself.
∑-comm :
⦃ props : Has (0# is leftIdentity for + ∷ associative on + ∷ commutative on + ∷ []) ⦄ →
∀ n m (f : Fin n → Fin m → Carrier) → ∑[ i < n ] ∑[ j < m ] f i j ≈ ∑[ j < m ] ∑[ i < n ] f i j
∑-comm ⦃ props ⦄ zero m f = sym (sumₜ-zero ⦃ weaken props ⦄ m)
∑-comm (suc n) m f =
begin
∑[ j < m ] f zero j +′ ∑[ i < n ] ∑[ j < m ] f (suc i) j ≈⟨ cong + refl (∑-comm n m _) ⟩
∑[ j < m ] f zero j +′ ∑[ j < m ] ∑[ i < n ] f (suc i) j ≈⟨ ∑-+′-hom m _ _ ⟩
∑[ j < m ] (f zero j +′ ∑[ i < n ] f (suc i) j) ∎
module _ ⦃ props : Has (associative on + ∷ commutative on + ∷ []) ⦄ where
open Fin using (punchIn)
-- Any permutation of a table has the same sum as the original.
sumₜ-permute : ∀ {n} t (π : Permutation′ n) → sumₜ t ≈ sumₜ (rearrange (π ⟨$⟩ʳ_) t)
sumₜ-permute {zero} t π = refl
sumₜ-permute {suc n} t π =
let f = lookup t
in
begin
sumₜ t ≡⟨⟩
f 0i +′ sumₜ (rearrange (punchIn 0i) t) ≈⟨ cong + refl (sumₜ-permute _ (Perm.remove (π ⟨$⟩ˡ 0i) π)) ⟩
f 0i +′ sumₜ (rearrange (punchIn 0i ∘ (Perm.remove (π ⟨$⟩ˡ 0i) π ⟨$⟩ʳ_)) t) ≡⟨ ≡.cong₂ _+′_ ≡.refl (sumₜ-cong≡ (≡.cong f ∘ ≡.sym ∘ Perm.punchIn-permute′ π 0i)) ⟩
f 0i +′ sumₜ (rearrange ((π ⟨$⟩ʳ_) ∘ punchIn (π ⟨$⟩ˡ 0i)) t) ≡⟨ ≡.cong₂ _+′_ (≡.cong f (≡.sym (Perm.inverseʳ π))) ≡.refl ⟩
f _ +′ sumₜ (rearrange ((π ⟨$⟩ʳ_) ∘ punchIn (π ⟨$⟩ˡ 0i)) t) ≈⟨ sym (sumₜ-punchIn (rearrange (π ⟨$⟩ʳ_) t) (π ⟨$⟩ˡ 0i)) ⟩
sumₜ (rearrange (π ⟨$⟩ʳ_) t) ∎
where
0i = zero
ππ0 = π ⟨$⟩ʳ (π ⟨$⟩ˡ 0i)
-- A version of 'sumₜ-permute' allowing heterogeneous sum lengths.
sumₜ-permute′ : ∀ {m n} t (π : Permutation m n) → sumₜ t ≈ sumₜ (rearrange (π ⟨$⟩ʳ_) t)
sumₜ-permute′ t π with Perm.↔⇒≡ π
sumₜ-permute′ t π | ≡.refl = sumₜ-permute t π
∑-permute : ∀ {n} (f : Fin n → Carrier) (π : Permutation′ n) → ∑[ i < n ] f i ≈ ∑[ i < n ] f (π ⟨$⟩ʳ i)
∑-permute = sumₜ-permute ∘ tabulate
∑-permute′ : ∀ {m n} (f : Fin n → Carrier) (π : Permutation m n) → ∑[ i < n ] f i ≈ ∑[ i < m ] f (π ⟨$⟩ʳ i)
∑-permute′ = sumₜ-permute′ ∘ tabulate
private
⌊i≟i⌋ : ∀ {n} (i : Fin n) → (i Fin.≟ i) ≡ yes ≡.refl
⌊i≟i⌋ i with i Fin.≟ i
⌊i≟i⌋ i | yes ≡.refl = ≡.refl
⌊i≟i⌋ i | no ¬p = ⊥-elim (¬p ≡.refl)
-- If the function takes the same value at 'i' and 'j', then swapping 'i' and
-- 'j' then selecting 'j' is the same as selecting 'i'.
select-transpose : ∀ {n} t (i j : Fin n) → lookup t i ≈ lookup t j → ∀ k → (lookup (select 0′ j t) ∘ PC.transpose i j) k ≈ lookup (select 0′ i t) k
select-transpose _ i j e k with k Fin.≟ i
select-transpose _ i j e k | yes p rewrite ≡.≡-≟-identity Fin._≟_ {j} ≡.refl = sym e
select-transpose _ i j e k | no ¬p with k Fin.≟ j
select-transpose _ i j e k | no ¬p | yes q rewrite proj₂ (≡.≢-≟-identity Fin._≟_ (¬p ∘ ≡.trans q ∘ ≡.sym)) = refl
select-transpose _ i j e k | no ¬p | no ¬q rewrite proj₂ (≡.≢-≟-identity Fin._≟_ ¬q) = refl
-- Summing over a pulse gives you the single value picked out by the pulse.
select-sum :
⦃ props : Has (0# is leftIdentity for + ∷ 0# is rightIdentity for + ∷ associative on + ∷ commutative on + ∷ []) ⦄ →
∀ {n i} (t : Table Carrier n) → sumₜ (Table.select 0′ i t) ≈ lookup t i
select-sum {zero} {()} t
select-sum ⦃ props ⦄ {suc n} {i} t =
let f = lookup t
open Table using (select; rearrange; replicate)
open PC using (transpose)
in
begin
sumₜ (select 0′ i t) ≈⟨ sumₜ-permute ⦃ weaken props ⦄ (select 0′ i t) (Perm.transpose zero i) ⟩
sumₜ (rearrange (transpose zero i) (select 0′ i t)) ≡⟨ sumₜ-cong≡ (Table.select-const 0′ i t ∘ transpose zero i) ⟩
sumₜ (rearrange (transpose zero i) (select 0′ i (replicate (f i)))) ≈⟨ sumₜ-cong (select-transpose (replicate (f i)) zero i refl) ⟩
sumₜ (select 0′ zero (replicate {suc n} (f i))) ≡⟨⟩
f i +′ sumₜ (replicate {n} 0′) ≈⟨ cong + refl (sumₜ-zero ⦃ weaken props ⦄ n) ⟩
f i +′ 0′ ≈⟨ from props (0# is rightIdentity for +) _ ⟩
f i ∎
sumₜ-fromList : ∀ xs → sumₜ (Table.fromList xs) ≡ sumₗ xs
sumₜ-fromList [] = ≡.refl
sumₜ-fromList (x ∷ xs) = ≡.cong₂ _+′_ ≡.refl (sumₜ-fromList xs)
sumₜ-toList : ∀ {n} (t : Table Carrier n) → sumₜ t ≡ sumₗ (Table.toList t)
sumₜ-toList {zero} _ = ≡.refl
sumₜ-toList {suc n} _ = ≡.cong₂ _+′_ ≡.refl (sumₜ-toList {n} _)
sumDistribˡ :
⦃ props : Has (0# is rightZero for * ∷ * ⟨ distributesOverˡ ⟩ₚ + ∷ []) ⦄ →
∀ {n} x (t : Table Carrier n) → x *′ sumₜ t ≈ ∑[ i < n ] (x *′ lookup t i)
sumDistribˡ ⦃ props ⦄ {Nat.zero} x f = from props (0# is rightZero for *) x
sumDistribˡ ⦃ props ⦄ {Nat.suc n} x t =
begin
x *′ (head t +′ sumₜ (tail t)) ≈⟨ from props (* ⟨ distributesOverˡ ⟩ₚ +) _ _ _ ⟩
(x *′ head t) +′ (x *′ sumₜ (tail t)) ≈⟨ cong + refl (sumDistribˡ x (tail t)) ⟩
(x *′ head t) +′ sumₜ (tabulate (λ i → x *′ lookup (tail t) i)) ∎
sumDistribʳ :
⦃ props : Has (0# is leftZero for * ∷ * ⟨ distributesOverʳ ⟩ₚ + ∷ []) ⦄ →
∀ {n} x (t : Table Carrier n) → sumₜ t *′ x ≈ ∑[ i < n ] (lookup t i *′ x)
sumDistribʳ ⦃ props ⦄ {Nat.zero} x t = from props (0# is leftZero for *) x
sumDistribʳ ⦃ props ⦄ {Nat.suc n} x t =
begin
(head t +′ sumₜ (tail t)) *′ x ≈⟨ from props (* ⟨ distributesOverʳ ⟩ₚ +) _ _ _ ⟩
(head t *′ x) +′ (sumₜ (tail t) *′ x) ≈⟨ cong + refl (sumDistribʳ x (tail t)) ⟩
(head t *′ x) +′ sumₜ (tabulate (λ i → lookup (tail t) i *′ x)) ∎
|
{
"alphanum_fraction": 0.4880242355,
"avg_line_length": 46.1266375546,
"ext": "agda",
"hexsha": "24aeb3816721463db8885ae59673755495802eb6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-matrices",
"max_forks_repo_path": "src/MLib/Algebra/Operations.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bch29/agda-matrices",
"max_issues_repo_path": "src/MLib/Algebra/Operations.agda",
"max_line_length": 168,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-matrices",
"max_stars_repo_path": "src/MLib/Algebra/Operations.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4264,
"size": 10563
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Indexed binary relations
------------------------------------------------------------------------
-- The contents of this module should be accessed via
-- `Relation.Binary.Indexed.Heterogeneous`.
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.Indexed.Heterogeneous.Core
module Relation.Binary.Indexed.Heterogeneous.Structures
{i a ℓ} {I : Set i} (A : I → Set a) (_≈_ : IRel A ℓ)
where
open import Function.Base
open import Level using (suc; _⊔_)
open import Relation.Binary using (_⇒_)
open import Relation.Binary.PropositionalEquality.Core as P using (_≡_)
open import Relation.Binary.Indexed.Heterogeneous.Definitions
------------------------------------------------------------------------
-- Equivalences
record IsIndexedEquivalence : Set (i ⊔ a ⊔ ℓ) where
field
refl : Reflexive A _≈_
sym : Symmetric A _≈_
trans : Transitive A _≈_
reflexive : ∀ {i} → _≡_ ⟨ _⇒_ ⟩ _≈_ {i}
reflexive P.refl = refl
record IsIndexedPreorder {ℓ₂} (_∼_ : IRel A ℓ₂) : Set (i ⊔ a ⊔ ℓ ⊔ ℓ₂) where
field
isEquivalence : IsIndexedEquivalence
reflexive : ∀ {i j} → (_≈_ {i} {j}) ⟨ _⇒_ ⟩ _∼_
trans : Transitive A _∼_
module Eq = IsIndexedEquivalence isEquivalence
refl : Reflexive A _∼_
refl = reflexive Eq.refl
|
{
"alphanum_fraction": 0.5722543353,
"avg_line_length": 29.4468085106,
"ext": "agda",
"hexsha": "9993514eefac9b740c1534d36af9509df0602997",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Relation/Binary/Indexed/Heterogeneous/Structures.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Relation/Binary/Indexed/Heterogeneous/Structures.agda",
"max_line_length": 76,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Relation/Binary/Indexed/Heterogeneous/Structures.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 389,
"size": 1384
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
-- The Category of Elements
open import Cubical.Categories.Category
module Cubical.Categories.Constructions.Elements {ℓ ℓ'} {C : Precategory ℓ ℓ'} where
open import Cubical.Categories.Instances.Sets
open import Cubical.Categories.Functor
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
import Cubical.Categories.Morphism as Morphism
import Cubical.Categories.Constructions.Slice as Slice
-- some issues
-- * always need to specify objects during composition because can't infer isSet
open Precategory
open Functor
getIsSet : ∀ {ℓS} {C : Precategory ℓ ℓ'} (F : Functor C (SET ℓS)) → (c : C .ob) → isSet (fst (F ⟅ c ⟆))
getIsSet F c = snd (F ⟅ c ⟆)
infix 50 ∫_
∫_ : ∀ {ℓS} → Functor C (SET ℓS) → Precategory (ℓ-max ℓ ℓS) (ℓ-max ℓ' ℓS)
-- objects are (c , x) pairs where c ∈ C and x ∈ F c
(∫ F) .ob = Σ[ c ∈ C .ob ] fst (F ⟅ c ⟆)
-- morphisms are f : c → c' which take x to x'
(∫ F) .Hom[_,_] (c , x) (c' , x') = Σ[ f ∈ C [ c , c' ] ] x' ≡ (F ⟪ f ⟫) x
(∫ F) .id (c , x) = C .id c , sym (funExt⁻ (F .F-id) x ∙ refl)
(∫ F) ._⋆_ {c , x} {c₁ , x₁} {c₂ , x₂} (f , p) (g , q)
= (f ⋆⟨ C ⟩ g) , (x₂
≡⟨ q ⟩
(F ⟪ g ⟫) x₁ -- basically expanding out function composition
≡⟨ cong (F ⟪ g ⟫) p ⟩
(F ⟪ g ⟫) ((F ⟪ f ⟫) x)
≡⟨ funExt⁻ (sym (F .F-seq _ _)) _ ⟩
(F ⟪ f ⋆⟨ C ⟩ g ⟫) x
∎)
(∫ F) .⋆IdL o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdL i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS' x' ((F ⟪ a ⟫) x)) p' p cIdL i
where
isS = getIsSet F c
isS' = getIsSet F c'
cIdL = C .⋆IdL f
-- proof from composition with id
p' : x' ≡ (F ⟪ C .id c ⋆⟨ C ⟩ f ⟫) x
p' = snd ((∫ F) ._⋆_ ((∫ F) .id o) f')
(∫ F) .⋆IdR o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdR i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS' x' ((F ⟪ a ⟫) x)) p' p cIdR i
where
cIdR = C .⋆IdR f
isS' = getIsSet F c'
p' : x' ≡ (F ⟪ f ⋆⟨ C ⟩ C .id c' ⟫) x
p' = snd ((∫ F) ._⋆_ f' ((∫ F) .id o1))
(∫ F) .⋆Assoc o@{c , x} o1@{c₁ , x₁} o2@{c₂ , x₂} o3@{c₃ , x₃} f'@(f , p) g'@(g , q) h'@(h , r) i
= (cAssoc i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS₃ x₃ ((F ⟪ a ⟫) x)) p1 p2 cAssoc i
where
cAssoc = C .⋆Assoc f g h
isS₃ = getIsSet F c₃
p1 : x₃ ≡ (F ⟪ (f ⋆⟨ C ⟩ g) ⋆⟨ C ⟩ h ⟫) x
p1 = snd ((∫ F) ._⋆_ ((∫ F) ._⋆_ {o} {o1} {o2} f' g') h')
p2 : x₃ ≡ (F ⟪ f ⋆⟨ C ⟩ (g ⋆⟨ C ⟩ h) ⟫) x
p2 = snd ((∫ F) ._⋆_ f' ((∫ F) ._⋆_ {o1} {o2} {o3} g' h'))
-- same thing but for presheaves
∫ᴾ_ : ∀ {ℓS} → Functor (C ^op) (SET ℓS) → Precategory (ℓ-max ℓ ℓS) (ℓ-max ℓ' ℓS)
-- objects are (c , x) pairs where c ∈ C and x ∈ F c
(∫ᴾ F) .ob = Σ[ c ∈ C .ob ] fst (F ⟅ c ⟆)
-- morphisms are f : c → c' which take x to x'
(∫ᴾ F) .Hom[_,_] (c , x) (c' , x') = Σ[ f ∈ C [ c , c' ] ] x ≡ (F ⟪ f ⟫) x'
(∫ᴾ F) .id (c , x) = C .id c , sym (funExt⁻ (F .F-id) x ∙ refl)
(∫ᴾ F) ._⋆_ {c , x} {c₁ , x₁} {c₂ , x₂} (f , p) (g , q)
= (f ⋆⟨ C ⟩ g) , (x
≡⟨ p ⟩
(F ⟪ f ⟫) x₁ -- basically expanding out function composition
≡⟨ cong (F ⟪ f ⟫) q ⟩
(F ⟪ f ⟫) ((F ⟪ g ⟫) x₂)
≡⟨ funExt⁻ (sym (F .F-seq _ _)) _ ⟩
(F ⟪ f ⋆⟨ C ⟩ g ⟫) x₂
∎)
(∫ᴾ F) .⋆IdL o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdL i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS x ((F ⟪ a ⟫) x')) p' p cIdL i
where
isS = getIsSet F c
isS' = getIsSet F c'
cIdL = C .⋆IdL f
-- proof from composition with id
p' : x ≡ (F ⟪ C .id c ⋆⟨ C ⟩ f ⟫) x'
p' = snd ((∫ᴾ F) ._⋆_ ((∫ᴾ F) .id o) f')
(∫ᴾ F) .⋆IdR o@{c , x} o1@{c' , x'} f'@(f , p) i
= (cIdR i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS x ((F ⟪ a ⟫) x')) p' p cIdR i
where
cIdR = C .⋆IdR f
isS = getIsSet F c
p' : x ≡ (F ⟪ f ⋆⟨ C ⟩ C .id c' ⟫) x'
p' = snd ((∫ᴾ F) ._⋆_ f' ((∫ᴾ F) .id o1))
(∫ᴾ F) .⋆Assoc o@{c , x} o1@{c₁ , x₁} o2@{c₂ , x₂} o3@{c₃ , x₃} f'@(f , p) g'@(g , q) h'@(h , r) i
= (cAssoc i) , isOfHLevel→isOfHLevelDep 1 (λ a → isS x ((F ⟪ a ⟫) x₃)) p1 p2 cAssoc i
where
cAssoc = C .⋆Assoc f g h
isS = getIsSet F c
p1 : x ≡ (F ⟪ (f ⋆⟨ C ⟩ g) ⋆⟨ C ⟩ h ⟫) x₃
p1 = snd ((∫ᴾ F) ._⋆_ ((∫ᴾ F) ._⋆_ {o} {o1} {o2} f' g') h')
p2 : x ≡ (F ⟪ f ⋆⟨ C ⟩ (g ⋆⟨ C ⟩ h) ⟫) x₃
p2 = snd ((∫ᴾ F) ._⋆_ f' ((∫ᴾ F) ._⋆_ {o1} {o2} {o3} g' h'))
-- helpful results
module _ {ℓS} {F : Functor (C ^op) (SET ℓS)} where
-- morphisms are equal as long as the morphisms in C are equals
∫ᴾhomEq : ∀ {o1 o1' o2 o2'} (f : (∫ᴾ F) [ o1 , o2 ]) (g : (∫ᴾ F) [ o1' , o2' ])
→ (p : o1 ≡ o1') (q : o2 ≡ o2')
→ (eqInC : PathP (λ i → C [ fst (p i) , fst (q i) ]) (fst f) (fst g))
→ PathP (λ i → (∫ᴾ F) [ p i , q i ]) f g
∫ᴾhomEq (f , eqf) (g , eqg) p q eqInC
= ΣPathP (eqInC
, isOfHLevel→isOfHLevelDep 1 {A = Σ[ (o1 , o2) ∈ (∫ᴾ F) .ob × (∫ᴾ F) .ob ] (C [ fst o1 , fst o2 ])}
{B = λ ((o1 , o2) , f) → snd o1 ≡ (F ⟪ f ⟫) (snd o2)}
(λ ((o1 , o2) , f) → snd (F ⟅ (fst o1) ⟆) (snd o1) ((F ⟪ f ⟫) (snd o2)))
eqf
eqg
λ i → ((p i , q i) , eqInC i))
|
{
"alphanum_fraction": 0.4335419735,
"avg_line_length": 39.3623188406,
"ext": "agda",
"hexsha": "b9f76c21206943fe9dfae8cf8df6fe34f485d716",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/Categories/Constructions/Elements.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/Categories/Constructions/Elements.agda",
"max_line_length": 114,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/Categories/Constructions/Elements.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2715,
"size": 5432
}
|
module Data.QuadTree.FoldableProofs.FoldableFunctorProof where
open import Haskell.Prelude renaming (zero to Z; suc to S)
open import Data.Logic
open import Data.QuadTree.Implementation.Definition
open import Data.QuadTree.Implementation.ValidTypes
open import Data.QuadTree.Implementation.QuadrantLenses
open import Data.QuadTree.Implementation.SafeFunctions
open import Data.QuadTree.Implementation.PropDepthRelation
open import Data.QuadTree.Implementation.Foldable
open import Data.QuadTree.Implementation.Functors
open import Data.QuadTree.FoldableProofs.FoldableProof
open import Data.QuadTree.FunctorProofs.Valid-QuadrantFunctor
proof-foldfmap-list : {t s : Set} {{monT : Monoid t}} {{monS : Monoid s}} -> (l : List t )
-> (f : t -> s)
-> foldMap f l ≡ foldMap id (fmap f l)
proof-foldfmap-list [] f = refl
proof-foldfmap-list (x ∷ xs) f =
begin
f x <> foldMap f xs
=⟨ cong (_<>_ (f x)) (proof-foldfmap-list xs f) ⟩
f x <> foldMap id (fmap f xs)
end
fmap-replicate : {A B : Set} -> (f : A -> B) -> (v : A) -> (n : Nat)
-> fmap f (replicateₙ n v) ≡ replicateₙ n (f v)
fmap-replicate f v Z = refl
fmap-replicate f v (S n) = cong (λ z → f v ∷ z) (fmap-replicate f v n)
fmap-concat : {A B : Set} -> (f : A -> B) -> (l1 l2 : List A)
-> fmap f (l1 ++ l2) ≡ fmap f l1 ++ fmap f l2
fmap-concat f [] l2 = refl
fmap-concat f (x ∷ l1) l2 = cong (λ z → f x ∷ z) (fmap-concat f l1 l2)
fmap-concat4 : {A B : Set} -> (f : A -> B) -> (l1 l2 l3 l4 : List A)
-> fmap f (l1 ++ l2 ++ l3 ++ l4) ≡ fmap f l1 ++ fmap f l2 ++ fmap f l3 ++ fmap f l4
fmap-concat4 f l1 l2 l3 l4 =
begin
fmap f (l1 ++ l2 ++ l3 ++ l4)
=⟨ fmap-concat f l1 (l2 ++ l3 ++ l4) ⟩
fmap f l1 ++ fmap f (l2 ++ l3 ++ l4)
=⟨ cong (_++_ (map f l1)) (fmap-concat f l2 (l3 ++ l4)) ⟩
fmap f l1 ++ fmap f l2 ++ fmap f (l3 ++ l4)
=⟨ cong (λ z → map f l1 ++ map f l2 ++ z) (fmap-concat f l3 l4) ⟩
fmap f l1 ++ fmap f l2 ++ fmap f l3 ++ fmap f l4
end
fmap-expand : {A B : Set} {{eqA : Eq A}} {{eqB : Eq B}} -> (f : A -> B) -> (t : Tile A)
-> fmap f (expand t) ≡ expand (fmap f t)
fmap-expand f t@(TileC v (RegionC (x1 , y1) (x2 , y2))) = fmap-replicate f v (diff x2 x1 * diff y2 y1)
fmap-concat-expand : {A B : Set} {{eqA : Eq A}} {{eqB : Eq B}} -> (f : A -> B) -> (l : List (Tile A))
-> (fmap f $ concat $ map expand l) ≡ (concat $ map expand $ fmap (fmap f) l)
fmap-concat-expand f [] = refl
fmap-concat-expand f (x ∷ xs) =
begin
fmap f (expand x ++ concat (map expand xs))
=⟨ fmap-concat f (expand x) _ ⟩
fmap f (expand x) ++ fmap f (concat (map expand xs))
=⟨ cong (_++_ (fmap f (expand x))) (fmap-concat-expand f xs) ⟩
fmap f (expand x) ++ concat (map expand $ fmap (fmap f) xs)
=⟨ cong (λ q -> q ++ concat (map expand $ fmap (fmap f) xs)) (fmap-expand f x) ⟩
expand (fmap f x) ++ concat (map expand $ fmap (fmap f) xs)
end
replicate-concat : {t : Set} -> (a b : Nat) -> (v : t)
-> replicateₙ a v ++ replicateₙ b v ≡ replicateₙ (a + b) v
replicate-concat Z b v = refl
replicate-concat (S a) b v = cong (λ z → v ∷ z) (replicate-concat a b v)
replicate-concat4 : {t : Set} -> (a b c d : Nat) -> (v : t)
-> replicateₙ a v ++ replicateₙ b v ++ replicateₙ c v ++ replicateₙ d v ≡ replicateₙ (a + b + c + d) v
replicate-concat4 a b c d v =
begin
replicateₙ a v ++ replicateₙ b v ++ (replicateₙ c v ++ replicateₙ d v)
=⟨ cong (λ z → replicateₙ a v ++ replicateₙ b v ++ z) (replicate-concat c d v) ⟩
replicateₙ a v ++ replicateₙ b v ++ replicateₙ (c + d) v
=⟨ cong (_++_ (replicateₙ a v)) (replicate-concat b (c + d) v) ⟩
replicateₙ a v ++ replicateₙ (b + (c + d)) v
=⟨ replicate-concat a (b + (c + d)) v ⟩
replicateₙ (a + (b + (c + d))) v
=⟨ sym (cong (λ z → replicateₙ z v) (add-assoc a b (c + d))) ⟩
replicateₙ (a + b + (c + d)) v
=⟨ sym (cong (λ z → replicateₙ z v) (add-assoc (a + b) c d)) ⟩
replicateₙ (a + b + c + d) v
end
++-assoc : {t : Set} -> (l1 l2 l3 : List t)
-> (l1 ++ l2) ++ l3 ≡ l1 ++ (l2 ++ l3)
++-assoc [] l2 l3 = refl
++-assoc (x ∷ xs) l2 l3 = cong (λ z → x ∷ z) (++-assoc xs l2 l3)
concat-cme : {t : Set} -> (l1 l2 : List (Tile t))
-> concat (map expand (l1 ++ l2)) ≡ (concat $ map expand l1) ++ (concat $ map expand l2)
concat-cme [] l2 = refl
concat-cme l1@(x ∷ xs) l2 =
begin
expand x ++ concat (map expand (xs ++ l2))
=⟨ cong (_++_ (expand x)) (concat-cme xs l2) ⟩
expand x ++ ((concat $ map expand xs) ++ (concat $ map expand l2))
=⟨ sym $ ++-assoc (expand x) (concat $ map expand xs) (concat $ map expand l2) ⟩
(expand x ++ concat (map expand xs)) ++ concat (map expand l2)
end
concat-cme4 : {t : Set} -> (l1 l2 l3 l4 : List (Tile t))
-> concat (map expand (l1 ++ l2 ++ l3 ++ l4)) ≡ (concat (map expand l1)) ++ (concat (map expand l2)) ++ (concat (map expand l3)) ++ (concat (map expand l4))
concat-cme4 l1 l2 l3 l4 =
begin
concat (map expand (l1 ++ (l2 ++ (l3 ++ l4))))
=⟨ concat-cme l1 (l2 ++ (l3 ++ l4)) ⟩
concat (map expand l1) ++ concat (map expand (l2 ++ (l3 ++ l4)))
=⟨ cong (_++_ (concat (map expand l1))) (concat-cme l2 (l3 ++ l4)) ⟩
concat (map expand l1) ++ concat (map expand l2) ++ concat (map expand (l3 ++ l4))
=⟨ cong (λ q -> concat (map expand l1) ++ concat (map expand l2) ++ q) (concat-cme l3 l4) ⟩
concat (map expand l1) ++ concat (map expand l2) ++ concat (map expand l3) ++ concat (map expand l4)
end
tilesQd-concat : {A : Set} {{eqA : Eq A}} -> (deps : Nat) -> (a b c d : VQuadrant A {deps}) -> (x1 y1 x2 y2 : Nat)
-> IsTrue (x1 <= x2) -> IsTrue (y1 <= y2)
-> ({a b : A} -> IsTrue (a == b) -> a ≡ b)
-> (concat $ map expand $ (tilesQd deps a (RegionC (x1 , y1) (min x2 (pow 2 deps + x1) , min y2 (pow 2 deps + y1)))
++ tilesQd deps b (RegionC (min x2 (pow 2 deps + x1) , y1) (x2 , min y2 (pow 2 deps + y1)))
++ tilesQd deps c (RegionC (x1 , min y2 (pow 2 deps + y1)) (min x2 (pow 2 deps + x1) , y2) )
++ tilesQd deps d (RegionC (min x2 (pow 2 deps + x1) , min y2 (pow 2 deps + y1)) (x2 , y2) )))
≡ (concat $ map expand $ tilesQd (S deps) (combine a b c d) (RegionC (x1 , y1) (x2 , y2)))
tilesQd-concat {A} deps a@(CVQuadrant (Leaf va)) b@(CVQuadrant (Leaf vb)) c@(CVQuadrant (Leaf vc)) d@(CVQuadrant (Leaf vd)) x1 y1 x2 y2 xp yp peq =
ifc (va == vb && vb == vc && vc == vd)
then (λ {{pc}} ->
begin
(cme $ TileC va rA ∷ TileC vb rB ∷ TileC vc rC ∷ TileC vd rD ∷ [])
=⟨⟩
replicateₙ (area rA) va ++ replicateₙ (area rB) vb ++ replicateₙ (area rC) vc ++ replicateₙ (area rD) vd ++ []
=⟨ cong (λ q -> replicateₙ (area rA) va ++ replicateₙ (area rB) vb ++ replicateₙ (area rC) vc ++ q) (concat-nothing _) ⟩
replicateₙ (area rA) (va) ++ replicateₙ (area rB) (vb) ++ replicateₙ (area rC) (vc) ++ replicateₙ (area rD) vd
=⟨ cong (λ v -> replicateₙ (area rA) (va) ++ replicateₙ (area rB) (vb) ++ replicateₙ (area rC) (vc) ++ replicateₙ (area rD) v)
(sym $ peq $ andSnd {vb == vc} $ andSnd {va == vb} pc) ⟩
replicateₙ (area rA) (va) ++ replicateₙ (area rB) (vb) ++ replicateₙ (area rC) (vc) ++ replicateₙ (area rD) (vc)
=⟨ cong (λ v -> replicateₙ (area rA) (va) ++ replicateₙ (area rB) (vb) ++ replicateₙ (area rC) (v) ++ replicateₙ (area rD) (v))
(sym $ peq $ andFst {vb == vc} $ andSnd {va == vb} pc) ⟩
replicateₙ (area rA) (va) ++ replicateₙ (area rB) (vb) ++ replicateₙ (area rC) (vb) ++ replicateₙ (area rD) (vb)
=⟨ cong (λ v -> replicateₙ (area rA) (va) ++ replicateₙ (area rB) (v) ++ replicateₙ (area rC) (v) ++ replicateₙ (area rD) (v))
(sym $ peq $ andFst {va == vb} pc) ⟩
replicateₙ (area rA) (va) ++ replicateₙ (area rB) (va) ++ replicateₙ (area rC) (va) ++ replicateₙ (area rD) (va)
=⟨ replicate-concat4 (area rA) (area rB) (area rC) (area rD) (va) ⟩
replicateₙ (area rA + area rB + area rC + area rD) (va)
=⟨ cong (λ q -> replicateₙ q (va)) (square-split x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2
(min-rel-1 x1 mid x2 xp) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) (min-rel-2 y2 (mid + y1))) ⟩
replicateₙ (diff x2 x1 * diff y2 y1) (va)
=⟨ sym $ concat-nothing (replicateₙ (diff x2 x1 * diff y2 y1) (va)) ⟩
replicateₙ (diff x2 x1 * diff y2 y1) va ++ []
=⟨⟩
(cme $ TileC va (RegionC (x1 , y1) (x2 , y2)) ∷ [])
=⟨ cong (λ q -> cme $ tilesQd (S deps) q (RegionC (x1 , y1) (x2 , y2))) (sym $ ifcTrue (va == vb && vb == vc && vc == vd) pc) ⟩
(cme $ tilesQd (S deps) (ifc (va == vb && vb == vc && vc == vd) then CVQuadrant (Leaf va) else CVQuadrant (Node (Leaf va) (Leaf vb) (Leaf vc) (Leaf vd))) (RegionC (x1 , y1) (x2 , y2)))
end)
else (λ {{pc}} ->
begin
(concat $ map expand $ tilesQd (S deps) (CVQuadrant (Node (Leaf va) (Leaf vb) (Leaf vc) (Leaf vd)) {andCombine (zeroLteAny deps) (falseToNotTrue pc)}) (RegionC (x1 , y1) (x2 , y2)))
=⟨ cong {x = CVQuadrant (Node (Leaf va) (Leaf vb) (Leaf vc) (Leaf vd)) {andCombine (zeroLteAny deps) (falseToNotTrue pc)}} (λ q -> concat $ map expand $ tilesQd (S deps) q (RegionC (x1 , y1) (x2 , y2))) (sym $ ifcFalse (va == vb && vb == vc && vc == vd) pc) ⟩
(concat $ map expand $ tilesQd (S deps) (ifc (va == vb && vb == vc && vc == vd) then CVQuadrant (Leaf va) else CVQuadrant (Node (Leaf va) (Leaf vb) (Leaf vc) (Leaf vd))) (RegionC (x1 , y1) (x2 , y2)))
end) where
mid = pow 2 deps
rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))
rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))
rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )
rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )
cme : List (Tile A) -> List A
cme v = concat $ map expand $ v
area : Region -> Nat
area (RegionC (x1 , y1) (x2 , y2)) = diff x2 x1 * diff y2 y1
tilesQd-concat deps (CVQuadrant (Leaf x)) (CVQuadrant (Leaf x₁)) (CVQuadrant (Leaf x₂)) (CVQuadrant (Node d d₁ d₂ d₃)) x1 y1 x2 y2 xp yp peq = refl
tilesQd-concat deps (CVQuadrant (Leaf x)) (CVQuadrant (Leaf x₁)) (CVQuadrant (Node c c₁ c₂ c₃)) (CVQuadrant d) x1 y1 x2 y2 xp yp peq = refl
tilesQd-concat deps (CVQuadrant (Leaf x)) (CVQuadrant (Node b b₁ b₂ b₃)) (CVQuadrant c) (CVQuadrant d) x1 y1 x2 y2 xp yp peq = refl
tilesQd-concat deps (CVQuadrant (Node a a₁ a₂ a₃)) (CVQuadrant b) (CVQuadrant c) (CVQuadrant d) x1 y1 x2 y2 xp yp peq = refl
fmap-tilesQd : {A B : Set} {{eqA : Eq A}} {{eqB : Eq B}} -> (f : A -> B) -> (dep : Nat) -> (vqd : VQuadrant A {dep}) -> (x1 y1 x2 y2 : Nat)
-> IsTrue (x1 <= x2) -> IsTrue (y1 <= y2)
-> ({a b : A} -> IsTrue (a == b) -> a ≡ b)
-> ({a b : B} -> IsTrue (a == b) -> a ≡ b)
-> (concat $ map expand $ fmap (fmap f) $ tilesQd dep vqd (RegionC (x1 , y1) (x2 , y2))) ≡ (concat $ map expand $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) (RegionC (x1 , y1) (x2 , y2)))
fmap-tilesQd f dep (CVQuadrant (Leaf v) {p1}) x1 y1 x2 y2 px py peqA peqB = refl
fmap-tilesQd {A} {B} f dep@(S deps) vqd@(CVQuadrant (Node a@(Leaf va) b@(Leaf vb) c@(Leaf vc) d@(Leaf vd)) {p1}) x1 y1 x2 y2 xp yp peqA peqB =
ifc ((va == vb) && (vb == vc) && (vc == vd))
then (λ {{pc}} ->
(begin
(cme $ fmap (fmap f) $ tilesQd dep vqd reg)
=⟨⟩
(cme $ TileC (f va) rA ∷ TileC (f vb) rB ∷ TileC (f vc) rC ∷ TileC (f vd) rD ∷ [])
=⟨⟩
replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vc) ++ replicateₙ (area rD) (f vd) ++ []
=⟨ cong (λ q -> replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vc) ++ q) (concat-nothing _) ⟩
replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vc) ++ replicateₙ (area rD) (f vd)
=⟨ cong (λ v -> replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vc) ++ replicateₙ (area rD) (f v))
(sym $ peqA $ andSnd {vb == vc} $ andSnd {va == vb} pc) ⟩
replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vc) ++ replicateₙ (area rD) (f vc)
=⟨ cong (λ v -> replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f v) ++ replicateₙ (area rD) (f v))
(sym $ peqA $ andFst {vb == vc} $ andSnd {va == vb} pc) ⟩
replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vb) ++ replicateₙ (area rD) (f vb)
=⟨ cong (λ v -> replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f v) ++ replicateₙ (area rC) (f v) ++ replicateₙ (area rD) (f v))
(sym $ peqA $ andFst {va == vb} pc) ⟩
replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f va) ++ replicateₙ (area rC) (f va) ++ replicateₙ (area rD) (f va)
=⟨ replicate-concat4 (area rA) (area rB) (area rC) (area rD) (f va) ⟩
replicateₙ (area rA + area rB + area rC + area rD) (f va)
=⟨ cong (λ q -> replicateₙ q (f va)) (square-split x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2
(min-rel-1 x1 mid x2 xp) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) (min-rel-2 y2 (mid + y1))) ⟩
replicateₙ (diff x2 x1 * diff y2 y1) (f va)
=⟨ sym $ concat-nothing (replicateₙ (diff x2 x1 * diff y2 y1) (f va)) ⟩
replicateₙ (diff x2 x1 * diff y2 y1) (f va) ++ []
=⟨ cong (λ q -> cme $ tilesQd dep q reg)
(sym $ ifcTrue ((f va == f vb) && (f vb == f vc) && (f vc == f vd))
(useEq (cong3 (λ e1 e2 e3 -> e1 && e2 && e3) (eq-subst f va vb) (eq-subst f vb vc) (eq-subst f vc vd)) pc)) ⟩
(cme $ tilesQd dep (combine
(fmapₑ (quadrantFunctor deps) f sA)
(fmapₑ (quadrantFunctor deps) f sB)
(fmapₑ (quadrantFunctor deps) f sC)
(fmapₑ (quadrantFunctor deps) f sD)) reg)
=⟨⟩
(cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)
end))
else (λ {{pc}} ->
(begin
(cme $ fmap (fmap f) $ tilesQd dep vqd reg)
=⟨⟩
(cme $ TileC (f va) rA ∷ TileC (f vb) rB ∷ TileC (f vc) rC ∷ TileC (f vd) rD ∷ [])
=⟨⟩
(cme $ tilesQd dep (CVQuadrant (Node (Leaf (f va)) (Leaf (f vb)) (Leaf (f vc)) (Leaf (f vd)))
{andCombine (zeroLteAny deps) (falseToNotTrue $ useEqFalse (cong3 (λ e1 e2 e3 -> e1 && e2 && e3) (eq-subst f va vb) (eq-subst f vb vc) (eq-subst f vc vd)) pc)}) reg)
=⟨ cong {x = CVQuadrant (Node (Leaf (f va)) (Leaf (f vb)) (Leaf (f vc)) (Leaf (f vd)))
{andCombine (zeroLteAny deps) (falseToNotTrue $ useEqFalse (cong3 (λ e1 e2 e3 -> e1 && e2 && e3) (eq-subst f va vb) (eq-subst f vb vc) (eq-subst f vc vd)) pc)}}
(λ q -> cme $ tilesQd dep q reg) (sym $ ifcFalse ((f va == f vb) && (f vb == f vc) && (f vc == f vd))
(useEqFalse (cong3 (λ e1 e2 e3 -> e1 && e2 && e3) (eq-subst f va vb) (eq-subst f vb vc) (eq-subst f vc vd)) pc)) ⟩
(cme $ tilesQd dep (combine
(fmapₑ (quadrantFunctor deps) f sA)
(fmapₑ (quadrantFunctor deps) f sB)
(fmapₑ (quadrantFunctor deps) f sC)
(fmapₑ (quadrantFunctor deps) f sD)) reg)
=⟨⟩
(cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)
end))
where
mid = pow 2 deps
rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))
rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))
rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )
rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )
reg = (RegionC (x1 , y1) (x2 , y2))
sA = CVQuadrant {dep = deps} a {aSub {dep = deps} a b c d p1}
sB = CVQuadrant {dep = deps} b {bSub {dep = deps} a b c d p1}
sC = CVQuadrant {dep = deps} c {cSub {dep = deps} a b c d p1}
sD = CVQuadrant {dep = deps} d {dSub {dep = deps} a b c d p1}
cme : List (Tile B) -> List B
cme v = concat $ map expand $ v
area : Region -> Nat
area (RegionC (x1 , y1) (x2 , y2)) = diff x2 x1 * diff y2 y1
fmap-tilesQd {A} {B} f dep@(S deps) vqd@(CVQuadrant (Node a@(Leaf _) b@(Leaf _) c@(Leaf _) d@(Node _ _ _ _)) {p1}) x1 y1 x2 y2 xp yp peqA peqB =
begin
(cme $ fmap (fmap f) $ tilesQd dep vqd reg)
=⟨⟩
(cme $ fmap (fmap f) $ (
tilesQd deps sA rA ++ tilesQd deps sB rB ++ tilesQd deps sC rC ++ tilesQd deps sD rD
))
=⟨ cong cme $ fmap-concat4 (fmap f) (tilesQd deps sA rA) (tilesQd deps sB rB) (tilesQd deps sC rC) (tilesQd deps sD rD) ⟩
(cme (
fmap (fmap f) (tilesQd deps sA rA)
++ fmap (fmap f) (tilesQd deps sB rB)
++ fmap (fmap f) (tilesQd deps sC rC)
++ fmap (fmap f) (tilesQd deps sD rD)
))
=⟨ concat-cme4 (fmap (fmap f) (tilesQd deps sA rA)) (fmap (fmap f) (tilesQd deps sB rB)) (fmap (fmap f) (tilesQd deps sC rC)) (fmap (fmap f) (tilesQd deps sD rD)) ⟩
(cme $ fmap (fmap f) (tilesQd deps sA rA))
++ (cme $ fmap (fmap f) (tilesQd deps sB rB))
++ (cme $ fmap (fmap f) (tilesQd deps sC rC))
++ (cme $ fmap (fmap f) (tilesQd deps sD rD))
=⟨ cong4 (λ l1 l2 l3 l4 -> l1 ++ l2 ++ l3 ++ l4)
(fmap-tilesQd f deps sA x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) (min-rel-1 x1 mid x2 xp) (min-rel-1 y1 mid y2 yp) peqA peqB)
(fmap-tilesQd f deps sB (min x2 (mid + x1)) y1 x2 (min y2 (mid + y1)) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) peqA peqB)
(fmap-tilesQd f deps sC x1 (min y2 (mid + y1)) (min x2 (mid + x1)) y2 (min-rel-1 x1 mid x2 xp) (min-rel-2 y2 (mid + y1)) peqA peqB)
(fmap-tilesQd f deps sD (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 (min-rel-2 x2 (mid + x1)) (min-rel-2 y2 (mid + y1)) peqA peqB) ⟩
(cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD))
=⟨ sym $ concat-cme4 (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD) ⟩
(cme (
tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD
))
=⟨ tilesQd-concat deps (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD) x1 y1 x2 y2 xp yp peqB ⟩
(cme $ tilesQd dep
(combine (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD)) reg)
=⟨⟩
(cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)
end where
cme : List (Tile B) -> List B
cme v = concat $ map expand $ v
reg = (RegionC (x1 , y1) (x2 , y2))
mid = pow 2 deps
rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))
rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))
rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )
rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )
sA = CVQuadrant {dep = deps} a {aSub {dep = deps} a b c d p1}
sB = CVQuadrant {dep = deps} b {bSub {dep = deps} a b c d p1}
sC = CVQuadrant {dep = deps} c {cSub {dep = deps} a b c d p1}
sD = CVQuadrant {dep = deps} d {dSub {dep = deps} a b c d p1}
fmap-tilesQd {A} {B} f dep@(S deps) vqd@(CVQuadrant (Node a@(Leaf _) b@(Leaf _) c@(Node _ _ _ _) d) {p1}) x1 y1 x2 y2 xp yp peqA peqB =
begin
(cme $ fmap (fmap f) $ tilesQd dep vqd reg)
=⟨⟩
(cme $ fmap (fmap f) $ (
tilesQd deps sA rA ++ tilesQd deps sB rB ++ tilesQd deps sC rC ++ tilesQd deps sD rD
))
=⟨ cong cme $ fmap-concat4 (fmap f) (tilesQd deps sA rA) (tilesQd deps sB rB) (tilesQd deps sC rC) (tilesQd deps sD rD) ⟩
(cme (
fmap (fmap f) (tilesQd deps sA rA)
++ fmap (fmap f) (tilesQd deps sB rB)
++ fmap (fmap f) (tilesQd deps sC rC)
++ fmap (fmap f) (tilesQd deps sD rD)
))
=⟨ concat-cme4 (fmap (fmap f) (tilesQd deps sA rA)) (fmap (fmap f) (tilesQd deps sB rB)) (fmap (fmap f) (tilesQd deps sC rC)) _ ⟩
(cme $ fmap (fmap f) (tilesQd deps sA rA))
++ (cme $ fmap (fmap f) (tilesQd deps sB rB))
++ (cme $ fmap (fmap f) (tilesQd deps sC rC))
++ (cme $ fmap (fmap f) (tilesQd deps sD rD))
=⟨ cong4 (λ l1 l2 l3 l4 -> l1 ++ l2 ++ l3 ++ l4)
(fmap-tilesQd f deps sA x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) (min-rel-1 x1 mid x2 xp) (min-rel-1 y1 mid y2 yp) peqA peqB)
(fmap-tilesQd f deps sB (min x2 (mid + x1)) y1 x2 (min y2 (mid + y1)) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) peqA peqB)
(fmap-tilesQd f deps sC x1 (min y2 (mid + y1)) (min x2 (mid + x1)) y2 (min-rel-1 x1 mid x2 xp) (min-rel-2 y2 (mid + y1)) peqA peqB)
(fmap-tilesQd f deps sD (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 (min-rel-2 x2 (mid + x1)) (min-rel-2 y2 (mid + y1)) peqA peqB) ⟩
(cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD))
=⟨ sym $ concat-cme4 (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC) _ ⟩
(cme (
tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD
))
=⟨ tilesQd-concat deps (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD) x1 y1 x2 y2 xp yp peqB ⟩
(cme $ tilesQd dep
(combine (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD)) reg)
=⟨⟩
(cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)
end where
cme : List (Tile B) -> List B
cme v = concat $ map expand $ v
reg = (RegionC (x1 , y1) (x2 , y2))
mid = pow 2 deps
rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))
rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))
rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )
rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )
sA = CVQuadrant {dep = deps} a {aSub {dep = deps} a b c d p1}
sB = CVQuadrant {dep = deps} b {bSub {dep = deps} a b c d p1}
sC = CVQuadrant {dep = deps} c {cSub {dep = deps} a b c d p1}
sD = CVQuadrant {dep = deps} d {dSub {dep = deps} a b c d p1}
fmap-tilesQd {A} {B} f dep@(S deps) vqd@(CVQuadrant (Node a@(Leaf _) b@(Node _ _ _ _) c d) {p1}) x1 y1 x2 y2 xp yp peqA peqB =
begin
(cme $ fmap (fmap f) $ tilesQd dep vqd reg)
=⟨⟩
(cme $ fmap (fmap f) $ (
tilesQd deps sA rA ++ tilesQd deps sB rB ++ tilesQd deps sC rC ++ tilesQd deps sD rD
))
=⟨ cong cme $ fmap-concat4 (fmap f) (tilesQd deps sA rA) (tilesQd deps sB rB) (tilesQd deps sC rC) (tilesQd deps sD rD) ⟩
(cme (
fmap (fmap f) (tilesQd deps sA rA)
++ fmap (fmap f) (tilesQd deps sB rB)
++ fmap (fmap f) (tilesQd deps sC rC)
++ fmap (fmap f) (tilesQd deps sD rD)
))
=⟨ concat-cme4 (fmap (fmap f) (tilesQd deps sA rA)) (fmap (fmap f) (tilesQd deps sB rB)) (fmap (fmap f) (tilesQd deps sC rC)) _ ⟩
(cme $ fmap (fmap f) (tilesQd deps sA rA))
++ (cme $ fmap (fmap f) (tilesQd deps sB rB))
++ (cme $ fmap (fmap f) (tilesQd deps sC rC))
++ (cme $ fmap (fmap f) (tilesQd deps sD rD))
=⟨ cong4 (λ l1 l2 l3 l4 -> l1 ++ l2 ++ l3 ++ l4)
(fmap-tilesQd f deps sA x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) (min-rel-1 x1 mid x2 xp) (min-rel-1 y1 mid y2 yp) peqA peqB)
(fmap-tilesQd f deps sB (min x2 (mid + x1)) y1 x2 (min y2 (mid + y1)) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) peqA peqB)
(fmap-tilesQd f deps sC x1 (min y2 (mid + y1)) (min x2 (mid + x1)) y2 (min-rel-1 x1 mid x2 xp) (min-rel-2 y2 (mid + y1)) peqA peqB)
(fmap-tilesQd f deps sD (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 (min-rel-2 x2 (mid + x1)) (min-rel-2 y2 (mid + y1)) peqA peqB) ⟩
(cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD))
=⟨ sym $ concat-cme4 (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC) _ ⟩
(cme (
tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD
))
=⟨ tilesQd-concat deps (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD) x1 y1 x2 y2 xp yp peqB ⟩
(cme $ tilesQd dep
(combine (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD)) reg)
=⟨⟩
(cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)
end where
cme : List (Tile B) -> List B
cme v = concat $ map expand $ v
reg = (RegionC (x1 , y1) (x2 , y2))
mid = pow 2 deps
rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))
rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))
rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )
rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )
sA = CVQuadrant {dep = deps} a {aSub {dep = deps} a b c d p1}
sB = CVQuadrant {dep = deps} b {bSub {dep = deps} a b c d p1}
sC = CVQuadrant {dep = deps} c {cSub {dep = deps} a b c d p1}
sD = CVQuadrant {dep = deps} d {dSub {dep = deps} a b c d p1}
fmap-tilesQd {A} {B} f dep@(S deps) vqd@(CVQuadrant (Node a@(Node _ _ _ _) b c d) {p1}) x1 y1 x2 y2 xp yp peqA peqB =
begin
(cme $ fmap (fmap f) $ tilesQd dep vqd reg)
=⟨⟩
(cme $ fmap (fmap f) $ (
tilesQd deps sA rA ++ tilesQd deps sB rB ++ tilesQd deps sC rC ++ tilesQd deps sD rD
))
=⟨ cong cme $ fmap-concat4 (fmap f) (tilesQd deps sA rA) (tilesQd deps sB rB) (tilesQd deps sC rC) (tilesQd deps sD rD) ⟩
(cme (
fmap (fmap f) (tilesQd deps sA rA)
++ fmap (fmap f) (tilesQd deps sB rB)
++ fmap (fmap f) (tilesQd deps sC rC)
++ fmap (fmap f) (tilesQd deps sD rD)
))
=⟨ concat-cme4 (fmap (fmap f) (tilesQd deps sA rA)) (fmap (fmap f) (tilesQd deps sB rB)) (fmap (fmap f) (tilesQd deps sC rC)) _ ⟩
(cme $ fmap (fmap f) (tilesQd deps sA rA))
++ (cme $ fmap (fmap f) (tilesQd deps sB rB))
++ (cme $ fmap (fmap f) (tilesQd deps sC rC))
++ (cme $ fmap (fmap f) (tilesQd deps sD rD))
=⟨ cong4 (λ l1 l2 l3 l4 -> l1 ++ l2 ++ l3 ++ l4)
(fmap-tilesQd f deps sA x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) (min-rel-1 x1 mid x2 xp) (min-rel-1 y1 mid y2 yp) peqA peqB)
(fmap-tilesQd f deps sB (min x2 (mid + x1)) y1 x2 (min y2 (mid + y1)) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) peqA peqB)
(fmap-tilesQd f deps sC x1 (min y2 (mid + y1)) (min x2 (mid + x1)) y2 (min-rel-1 x1 mid x2 xp) (min-rel-2 y2 (mid + y1)) peqA peqB)
(fmap-tilesQd f deps sD (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 (min-rel-2 x2 (mid + x1)) (min-rel-2 y2 (mid + y1)) peqA peqB) ⟩
(cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC))
++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD))
=⟨ sym $ concat-cme4 (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC) _ ⟩
(cme (
tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC
++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD
))
=⟨ tilesQd-concat deps (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD) x1 y1 x2 y2 xp yp peqB ⟩
(cme $ tilesQd dep
(combine (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD)) reg)
=⟨⟩
(cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)
end where
cme : List (Tile B) -> List B
cme v = concat $ map expand $ v
reg = (RegionC (x1 , y1) (x2 , y2))
mid = pow 2 deps
rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))
rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))
rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )
rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )
sA = CVQuadrant {dep = deps} a {aSub {dep = deps} a b c d p1}
sB = CVQuadrant {dep = deps} b {bSub {dep = deps} a b c d p1}
sC = CVQuadrant {dep = deps} c {cSub {dep = deps} a b c d p1}
sD = CVQuadrant {dep = deps} d {dSub {dep = deps} a b c d p1}
qdToQt : {A : Set} {{eqA : Eq A}} -> (dep w h : Nat) -> (vqd : VQuadrant A {dep}) -> .(q : IsTrue (dep == log2up (if w < h then h else w)))
-> tilesQd dep vqd (RegionC (0 , 0) (w , h)) ≡ tilesQt dep (toQt dep w h q vqd)
qdToQt dep w h (CVQuadrant qd {p}) q = refl
fmap-tilesQt : {A B : Set} {{eqA : Eq A}} {{eqB : Eq B}} -> (f : A -> B) -> (dep : Nat) -> (vqt : VQuadTree A {dep})
-> ({a b : A} -> IsTrue (a == b) -> a ≡ b)
-> ({a b : B} -> IsTrue (a == b) -> a ≡ b)
-> (concat $ map expand $ fmap (fmap f) $ tilesQt dep vqt) ≡ (concat $ map expand $ tilesQt dep $ fmapₑ (quadtreeFunctor dep) f vqt)
fmap-tilesQt f dep (CVQuadTree (Wrapper (w , h) (Leaf v))) peqA peqB = refl
fmap-tilesQt {A} {B} f dep@(S deps) vqt@(CVQuadTree (Wrapper (w , h) qd@(Node a b c d)) {p1} {p2}) peqA peqB =
begin
(concat $ map expand $ fmap (fmap f) $ tilesQt dep vqt)
=⟨⟩
(concat $ map expand $ fmap (fmap f) $ tilesQd dep (CVQuadrant qd {p1}) (RegionC (0 , 0) (w , h)))
=⟨ fmap-tilesQd f dep (CVQuadrant qd {p1}) 0 0 w h (zeroLteAny w) (zeroLteAny h) peqA peqB ⟩
(concat $ map expand $ tilesQd dep (fmapₑ (quadrantFunctor dep) f (CVQuadrant qd {p1})) (RegionC (0 , 0) (w , h)))
=⟨ cong (λ l -> concat $ map expand l) (qdToQt dep w h (combine (fmapₑ (quadrantFunctor deps) f (CVQuadrant a)) _ _ _) p2) ⟩
(concat $ map expand $ tilesQt dep (fmapₑ (quadtreeFunctor dep) f vqt))
end
proof-foldfmap-qt : {t s : Set} {{eqT : Eq t}} {{eqS : Eq s}} {{monS : Monoid s}} {{monT : Monoid t}} (dep : Nat) -> (vqt : VQuadTree t {dep})
-> (f : t -> s)
-> ({a b : t} -> IsTrue (a == b) -> a ≡ b)
-> ({a b : s} -> IsTrue (a == b) -> a ≡ b)
-> foldMapₑ (quadtreeFoldable dep) f vqt ≡ foldMapₑ (quadtreeFoldable dep) id (fmapₑ (quadtreeFunctor dep) f vqt)
proof-foldfmap-qt {t} {s} dep vqt@(CVQuadTree (Wrapper (w , h) (Leaf v)) {p} {q}) f peqA peqB =
begin
foldMapₑ (quadtreeFoldable dep) f vqt
=⟨⟩
foldMap f (replicateₙ (w * h) v ++ [])
=⟨ cong (foldMap f) (concat-nothing (replicateₙ (w * h) v)) ⟩
foldMap f (replicateₙ (w * h) v)
=⟨ proof-foldfmap-list (replicateₙ (w * h) v) f ⟩
foldMap id (fmap f (replicateₙ (w * h) v))
=⟨ cong (foldMap id) (fmap-replicate f v (w * h)) ⟩
foldMap id (replicateₙ (w * h) (f v))
=⟨ cong (foldMap id) (sym $ concat-nothing (replicateₙ (w * h) (f v))) ⟩
foldMap id (replicateₙ (w * h) (f v) ++ [])
=⟨⟩
foldMapₑ (quadtreeFoldable dep) id (fmapₑ (quadtreeFunctor dep) f vqt)
end
proof-foldfmap-qt {t} {s} dep vqt@(CVQuadTree (Wrapper (w , h) (Node qd qd₁ qd₂ qd₃)) {p} {q}) f peqA peqB =
begin
foldMapₑ (quadtreeFoldable dep) f vqt
=⟨⟩
(foldMap f $ concat $ map expand $ tilesQt dep vqt)
=⟨ proof-foldfmap-list (concat $ map expand $ tilesQt dep vqt) f ⟩
(foldMap id $ fmap f $ concat $ map expand $ tilesQt dep vqt)
=⟨ cong (foldMap id) (fmap-concat-expand f (tilesQt dep vqt)) ⟩
(foldMap id $ concat $ map expand $ fmap (fmap f) $ tilesQt dep vqt)
=⟨ cong (foldMap id) (fmap-tilesQt f dep vqt peqA peqB) ⟩
(foldMap id $ concat $ map expand $ tilesQt dep $ fmapₑ (quadtreeFunctor dep) f vqt)
=⟨⟩
foldMapₑ (quadtreeFoldable dep) id (fmapₑ (quadtreeFunctor dep) f vqt)
end
|
{
"alphanum_fraction": 0.5498592857,
"avg_line_length": 65.1550094518,
"ext": "agda",
"hexsha": "027bdedf47b1d23803a3121c5c3407d405aa7509",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "JonathanBrouwer/research-project",
"max_forks_repo_path": "src/Data/QuadTree/FoldableProofs/FoldableFunctorProof.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "JonathanBrouwer/research-project",
"max_issues_repo_path": "src/Data/QuadTree/FoldableProofs/FoldableFunctorProof.agda",
"max_line_length": 268,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "JonathanBrouwer/research-project",
"max_stars_repo_path": "src/Data/QuadTree/FoldableProofs/FoldableFunctorProof.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z",
"num_tokens": 14364,
"size": 34467
}
|
------------------------------------------------------------------------------
-- Well-founded induction on the relation LTL
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.List.WF-Relation.LT-Length.Induction.Acc.WF-I where
open import FOTC.Base
open import FOTC.Data.List
open import FOTC.Data.List.PropertiesI
open import FOTC.Data.List.WF-Relation.LT-Length
open import FOTC.Data.List.WF-Relation.LT-Length.PropertiesI
import FOTC.Data.Nat.Induction.Acc.WF-I
open FOTC.Data.Nat.Induction.Acc.WF-I.<-WF
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Type
open import FOTC.Induction.WF
-- Parametrized modules
open module InvImg =
FOTC.Induction.WF.InverseImage {List} {N} {_<_} lengthList-N
------------------------------------------------------------------------------
-- The relation LTL is well-founded (using the inverse image combinator).
LTL-wf : WellFounded LTL
LTL-wf Lxs = wellFounded <-wf Lxs
-- Well-founded induction on the relation LTL.
LTL-wfind : (A : D → Set) →
(∀ {xs} → List xs → (∀ {ys} → List ys → LTL ys xs → A ys) → A xs) →
∀ {xs} → List xs → A xs
LTL-wfind A = WellFoundedInduction LTL-wf
------------------------------------------------------------------------------
-- The relation LTL is well-founded (a different proof).
-- Adapted from FOTC.Data.Nat.Induction.Acc.WellFoundedInduction.WF₁-LT.
module WF₁-LTL where
LTL-wf' : WellFounded LTL
LTL-wf' Lxs = acc (helper Lxs)
where
helper : ∀ {xs ys} → List xs → List ys → LTL ys xs → Acc List LTL ys
helper lnil Lys ys<[] = ⊥-elim (xs<[]→⊥ Lys ys<[])
helper (lcons x {xs} Lxs) lnil []<x∷xs =
acc (λ Lys ys<[] → ⊥-elim (xs<[]→⊥ Lys ys<[]))
helper (lcons x {xs} Lxs) (lcons y {ys} Lys) y∷ys<x∷xs =
acc (λ {zs} Lzs zs<y∷ys →
let ys<xs : LTL ys xs
ys<xs = x∷xs<y∷ys→xs<ys Lys Lxs y∷ys<x∷xs
zs<xs : LTL zs xs
zs<xs = case (λ zs<ys → <-trans Lzs Lys Lxs zs<ys ys<xs)
(λ h → lg-xs≡lg-ys→ys<zx→xs<zs h ys<xs)
(xs<y∷ys→xs<ys∨lg-xs≡lg-ys Lzs Lys zs<y∷ys)
in helper Lxs Lzs zs<xs
)
|
{
"alphanum_fraction": 0.5315922494,
"avg_line_length": 37.09375,
"ext": "agda",
"hexsha": "ebcfa6ab4d66615c084ee00251adc9a8a5824924",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Data/List/WF-Relation/LT-Length/Induction/Acc/WF-I.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Data/List/WF-Relation/LT-Length/Induction/Acc/WF-I.agda",
"max_line_length": 79,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Data/List/WF-Relation/LT-Length/Induction/Acc/WF-I.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 724,
"size": 2374
}
|
module UnknownImplicitInstance where
⟨⟩ : {A : Set} {{a : A}} → A
⟨⟩ {{a}} = a
postulate
B : Set
instance b : B
f : {A : Set₁} {{a : A}} → A
x : Set
x = f
|
{
"alphanum_fraction": 0.493902439,
"avg_line_length": 12.6153846154,
"ext": "agda",
"hexsha": "cc3891dd3329870ef6bc3d534ace5a802e3cf579",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/UnknownImplicitInstance.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/UnknownImplicitInstance.agda",
"max_line_length": 36,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/UnknownImplicitInstance.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 71,
"size": 164
}
|
module Numeral.Rational where
open import Data.Tuple
open import Logic
import Lvl
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Integer
open import Numeral.Integer.Oper
open import Relator.Equals
open import Type
open import Type.Quotient
-- Equivalence relation of quotient equality.
-- Essentially (if one would already work in the rationals):
-- (a₁ , a₂) quot-≡_ (b₁ , b₂)
-- ⇔ a₁ ⋅ b₂ ≡ a₂ ⋅ b₁
-- ⇔ a₁ / a₂ ≡ b₁ / b₂
_quot-≡_ : (ℤ ⨯ ℕ₊) → (ℤ ⨯ ℕ₊) → Stmt{Lvl.𝟎}
(a₁ , a₂) quot-≡ (b₁ , b₂) = (a₁ ⋅ b₂ ≡ a₂ ⋅ b₁)
ℤ : Type{Lvl.𝟎}
ℤ = (ℤ ⨯ ℕ₊) / (_quot-≡_)
|
{
"alphanum_fraction": 0.6578947368,
"avg_line_length": 25.3333333333,
"ext": "agda",
"hexsha": "7d4d1e54c96f17fe5863e9ad63bbf4b9ce12e071",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Mathematical/Numeral/Rational.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Mathematical/Numeral/Rational.agda",
"max_line_length": 60,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Mathematical/Numeral/Rational.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 255,
"size": 608
}
|
module Selective.Runtime where
open import Selective.Simulate
open import Selective.SimulationEnvironment
open import Prelude
open import Data.Nat.Show using (show)
open import Codata.Musical.Notation using ( ♯_ ; ♭)
import IO
open ∞Trace
record BlockedCount : Set₂ where
field
return-count : ℕ
receive-count : ℕ
selective-count : ℕ
count-blocked : (env : Env) → BlockedCount
count-blocked env = loop (Env.blocked-no-progress env)
where
open BlockedCount
loop : ∀ {store inbs bl} → All (IsBlocked store inbs) bl → BlockedCount
loop [] = record { return-count = 0 ; receive-count = 0 ; selective-count = 0 }
loop (BlockedReturn _ _ ∷ xs) =
let rec = loop xs
in record { return-count = suc (rec .return-count) ; receive-count = rec .receive-count ; selective-count = rec .selective-count }
loop (BlockedReceive _ _ _ ∷ xs) =
let rec = loop xs
in record { return-count = rec .return-count ; receive-count = suc (rec .receive-count) ; selective-count = rec .selective-count }
loop (BlockedSelective _ _ _ _ _ ∷ xs) =
let rec = loop xs
in record { return-count = rec .return-count ; receive-count = rec .receive-count ; selective-count = suc (rec .selective-count) }
show-env : Env → String
show-env env =
let count = count-blocked env
open BlockedCount
in "There are " || show (count .return-count) || " finished actors, " || show (count .receive-count) || " receiving actors, and " || show (count .selective-count) || " selecting actors"
show-final-step : ℕ → String
show-final-step n = "Done after " || (show n) || " steps."
-- run-env continously runs the simulation of an environment
-- and transforms the steps taken into output to the console.
run-env : Env → IO.IO ⊤
run-env env = loop 1 ((simulate env) .force)
where
loop : ℕ → Trace ∞ → IO.IO ⊤
loop n (TraceStop env _) = ♯ IO.putStrLn (show-final-step n) IO.>> ♯ IO.putStrLn (show-env env)
loop n (x ∷ xs) = ♯ IO.putStrLn ("Step " || show n ) IO.>> ♯ loop (suc n) (xs .force)
run-env-silent : Env → IO.IO ⊤
run-env-silent env = loop 1 ((simulate env) .force)
where
loop : ℕ → Trace ∞ → IO.IO ⊤
loop n (TraceStop env _) = IO.putStrLn (show-final-step n)
loop n (x ∷ xs) = ♯ IO.return tt IO.>> ♯ loop (suc n) (xs .force)
run-env-end : Env → IO.IO Env
run-env-end env = loop ((simulate env) .force)
where
loop : Trace ∞ → IO.IO Env
loop (TraceStop env _) = IO.return env
loop (x ∷ xs) = ♯ IO.return x IO.>> ♯ loop (xs .force)
|
{
"alphanum_fraction": 0.6500994036,
"avg_line_length": 39.296875,
"ext": "agda",
"hexsha": "2f7a98664ea4ac23a8a53670cdb0a494c05cf221",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/singly-typed-actors",
"max_forks_repo_path": "src/Selective/Runtime.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Zalastax/singly-typed-actors",
"max_issues_repo_path": "src/Selective/Runtime.agda",
"max_line_length": 187,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/thesis",
"max_stars_repo_path": "src/Selective/Runtime.agda",
"max_stars_repo_stars_event_max_datetime": "2018-02-02T16:44:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-02-02T16:44:43.000Z",
"num_tokens": 735,
"size": 2515
}
|
module TAlgebra where
open import Level
open import Data.Product
open import Relation.Binary
open Setoid
open import Basic
open import Category
import Functor
import Nat
import Adjoint
open import Monad
open Category.Category
open Functor.Functor
open Nat.Nat
open Nat.Export
open Adjoint.Export
open Monad.Monad
record TAlgebra {C₀ C₁ ℓ} {C : Category C₀ C₁ ℓ} (T : Monad C) : Set (C₀ ⊔ C₁ ⊔ ℓ) where
field
Tobj : Obj C
Tmap : Hom C (fobj (MFunctor T) Tobj) Tobj
field
join-fmap-alg : C [ C [ Tmap ∘ component (Mjoin T) Tobj ] ≈ C [ Tmap ∘ fmap (MFunctor T) Tmap ] ]
map-unit : C [ C [ Tmap ∘ component (Munit T) Tobj ] ≈ id C ]
open TAlgebra
record TAlgMap {C₀ C₁ ℓ} {C : Category C₀ C₁ ℓ} {T : Monad C} (a b : TAlgebra T) : Set (C₁ ⊔ ℓ) where
field
Thom : Hom C (Tobj a) (Tobj b)
field
hom-comm : C [ C [ Tmap b ∘ fmap (MFunctor T) Thom ] ≈ C [ Thom ∘ Tmap a ] ]
open TAlgMap
compose : ∀ {C₀ C₁ ℓ} {C : Category C₀ C₁ ℓ} {T : Monad C} {a b c : TAlgebra T} → TAlgMap b c → TAlgMap a b → TAlgMap a c
compose {C = C} {T} {a} {b} {c} f g = record {
Thom = C [ Thom f ∘ Thom g ] ;
hom-comm = begin⟨ C ⟩
C [ Tmap c ∘ fmap (MFunctor T) (C [ Thom f ∘ Thom g ]) ] ≈⟨ ≈-composite C (refl-hom C) (preserveComp (MFunctor T)) ⟩
C [ Tmap c ∘ C [ fmap (MFunctor T) (Thom f) ∘ fmap (MFunctor T) (Thom g) ] ] ≈⟨ sym-hom C (assoc C) ⟩
C [ C [ Tmap c ∘ fmap (MFunctor T) (Thom f) ] ∘ fmap (MFunctor T) (Thom g) ] ≈⟨ ≈-composite C (hom-comm f) (refl-hom C) ⟩
C [ C [ Thom f ∘ Tmap b ] ∘ fmap (MFunctor T) (Thom g) ] ≈⟨ assoc C ⟩
C [ Thom f ∘ C [ Tmap b ∘ fmap (MFunctor T) (Thom g) ] ] ≈⟨ ≈-composite C (refl-hom C) (hom-comm g) ⟩
C [ Thom f ∘ C [ Thom g ∘ Tmap a ] ] ≈⟨ sym-hom C (assoc C) ⟩
C [ C [ Thom f ∘ Thom g ] ∘ Tmap a ]
∎ }
identity : ∀ {C₀ C₁ ℓ} {C : Category C₀ C₁ ℓ} {T : Monad C} {a : TAlgebra T} → TAlgMap a a
identity {C = C} {T} {a} = record {
Thom = id C ;
hom-comm = begin⟨ C ⟩
C [ Tmap a ∘ fmap (MFunctor T) (id C) ] ≈⟨ ≈-composite C (refl-hom C) (preserveId (MFunctor T)) ⟩
C [ Tmap a ∘ id C ] ≈⟨ rightId C ⟩
Tmap a ≈⟨ sym-hom C (leftId C) ⟩
C [ id C ∘ Tmap a ]
∎ }
T-Algs : ∀ {C₀ C₁ ℓ} {C : Category C₀ C₁ ℓ} (T : Monad C) → Category _ _ _
T-Algs {C = C} T = record {
Obj = TAlgebra T;
Homsetoid = λ a b → record {
Carrier = TAlgMap a b ;
_≈_ = λ f g → C [ Thom f ≈ Thom g ] ;
isEquivalence = record { refl = refl-hom C ; sym = sym-hom C ; trans = trans-hom C } };
comp = compose;
id = identity;
leftId = leftId C;
rightId = rightId C;
assoc = assoc C;
≈-composite = ≈-composite C }
Free-TAlg : ∀ {C₀ C₁ ℓ} {C : Category C₀ C₁ ℓ} (T : Monad C) → Functor.Functor C (T-Algs T)
Free-TAlg {C = C} T = record {
fobj = λ x → record {
Tobj = fobj (MFunctor T) x ;
Tmap = component (Mjoin T) x ;
join-fmap-alg = join_join T ;
map-unit = unit_MFunctor T } ;
fmapsetoid = λ {a} {b} → record {
mapping = λ x → record {
Thom = fmap (MFunctor T) x ;
hom-comm = naturality (Mjoin T) } ;
preserveEq = Functor.preserveEq (MFunctor T) } ;
preserveId = preserveId (MFunctor T) ;
preserveComp = preserveComp (MFunctor T) }
Forgetful-TAlg : ∀ {C₀ C₁ ℓ} {C : Category C₀ C₁ ℓ} (T : Monad C) → Functor.Functor (T-Algs T) C
Forgetful-TAlg {C = C} T = record {
fobj = Tobj ;
fmapsetoid = record { mapping = Thom ; preserveEq = λ x≈y → x≈y } ;
preserveId = refl-hom C ;
preserveComp = refl-hom C }
Free⊣Forgetful-TAlg : ∀ {C₀ C₁ ℓ} {C : Category C₀ C₁ ℓ} (T : Monad C) → Free-TAlg T ⊣ Forgetful-TAlg T
Free⊣Forgetful-TAlg {C = C} T = Adjoint.unit-triangular-holds-adjoint {C = C} {D = T-Algs T} {FT} {GT} ηT εT triL (λ {a} → triR {a})
where
FT = Free-TAlg T
GT = Forgetful-TAlg T
ηT = record {
component = component (Munit T) ;
naturality = naturality (Munit T) }
εT = record {
component = λ X → record {
Thom = Tmap X ;
hom-comm = sym-hom C (join-fmap-alg X) } ;
naturality = λ {a} {b} {f} → hom-comm f }
triL : [ C , T-Algs T ] [ Nat.compose (Nat.compose Nat.leftIdNat→ (εT N∘F FT)) (Nat.compose (Nat.assocNat← {F = FT} {GT} {FT}) (Nat.compose (FT F∘N ηT) Nat.rightIdNat←)) ≈ id [ C , T-Algs T ] ]
triL = λ {a} → begin⟨ C ⟩
C [ C [ id C ∘ Thom (component εT (fobj FT a)) ] ∘ C [ id C ∘ C [ Thom (fmap FT (component ηT a)) ∘ id C ] ] ] ≈⟨ ≈-composite C (leftId C) (trans-hom C (leftId C) (rightId C)) ⟩
C [ component (Mjoin T) a ∘ fmap (MFunctor T) (component (Munit T) a) ] ≈⟨ MFunctor_unit T ⟩
id C
∎
triR : [ T-Algs T , C ] [ Nat.compose (Nat.compose Nat.rightIdNat→ (GT F∘N εT)) (Nat.compose (Nat.assocNat→ {F = GT} {FT} {GT}) (Nat.compose (ηT N∘F GT) Nat.leftIdNat←)) ≈ id [ T-Algs T , C ] ]
triR = λ {a} → begin⟨ C ⟩
C [ C [ id C ∘ fmap GT (component εT a) ] ∘ C [ id C ∘ C [ component ηT (fobj GT a) ∘ id C ] ] ] ≈⟨ ≈-composite C (leftId C) (trans-hom C (leftId C) (rightId C)) ⟩
C [ fmap GT (component εT a) ∘ component ηT (fobj GT a) ] ≈⟨ refl-hom C ⟩
C [ component (GT F∘N εT) a ∘ component (Munit T) (Tobj a) ] ≈⟨ map-unit a ⟩
id C
∎
|
{
"alphanum_fraction": 0.570789576,
"avg_line_length": 38.9545454545,
"ext": "agda",
"hexsha": "87fb923e0d1d243ac04fb5fe5ac35d5943159da5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "myuon/agda-cate",
"max_forks_repo_path": "src/TAlgebra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "myuon/agda-cate",
"max_issues_repo_path": "src/TAlgebra.agda",
"max_line_length": 197,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "myuon/agda-cate",
"max_stars_repo_path": "src/TAlgebra.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-02T07:30:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-28T04:59:31.000Z",
"num_tokens": 2114,
"size": 5142
}
|
open import Nat
open import Prelude
open import dynamics-core
open import contexts
open import lemmas-disjointness
open import exchange
-- this module contains all the proofs of different weakening structural
-- properties that we use for the hypothetical judgements
module weakening where
mutual
weaken-subst-Δ : ∀{Δ1 Δ2 Γ σ Γ'} →
Δ1 ## Δ2 →
Δ1 , Γ ⊢ σ :s: Γ' →
(Δ1 ∪ Δ2) , Γ ⊢ σ :s: Γ'
weaken-subst-Δ disj (STAId x) = STAId x
weaken-subst-Δ disj (STASubst subst x) = STASubst (weaken-subst-Δ disj subst) (weaken-ta-Δ1 disj x)
weaken-ta-Δ1 : ∀{Δ1 Δ2 Γ d τ} →
Δ1 ## Δ2 →
Δ1 , Γ ⊢ d :: τ →
(Δ1 ∪ Δ2) , Γ ⊢ d :: τ
weaken-ta-Δ1 disj TANum = TANum
weaken-ta-Δ1 disj (TAPlus wt wt₁) = TAPlus (weaken-ta-Δ1 disj wt) (weaken-ta-Δ1 disj wt₁)
weaken-ta-Δ1 disj (TAVar x₁) = TAVar x₁
weaken-ta-Δ1 disj (TALam x₁ wt) = TALam x₁ (weaken-ta-Δ1 disj wt)
weaken-ta-Δ1 disj (TAAp wt wt₁) = TAAp (weaken-ta-Δ1 disj wt) (weaken-ta-Δ1 disj wt₁)
weaken-ta-Δ1 disj (TAInl wt) = TAInl (weaken-ta-Δ1 disj wt)
weaken-ta-Δ1 disj (TAInr wt) = TAInr (weaken-ta-Δ1 disj wt)
weaken-ta-Δ1 disj (TACase wt x wt₁ x₁ wt₂) = TACase (weaken-ta-Δ1 disj wt) x (weaken-ta-Δ1 disj wt₁) x₁ (weaken-ta-Δ1 disj wt₂)
weaken-ta-Δ1 {Δ1} {Δ2} {Γ} disj (TAEHole {u = u} {Γ' = Γ'} x x₁) = TAEHole (x∈∪l Δ1 Δ2 u _ x ) (weaken-subst-Δ disj x₁)
weaken-ta-Δ1 {Δ1} {Δ2} {Γ} disj (TANEHole {Γ' = Γ'} {u = u} x wt x₁) = TANEHole (x∈∪l Δ1 Δ2 u _ x) (weaken-ta-Δ1 disj wt) (weaken-subst-Δ disj x₁)
weaken-ta-Δ1 disj (TACast wt x) = TACast (weaken-ta-Δ1 disj wt) x
weaken-ta-Δ1 disj (TAFailedCast wt x x₁ x₂) = TAFailedCast (weaken-ta-Δ1 disj wt) x x₁ x₂
weaken-ta-Δ1 disj (TAPair wt wt₁) = TAPair (weaken-ta-Δ1 disj wt) (weaken-ta-Δ1 disj wt₁)
weaken-ta-Δ1 disj (TAFst wt) = TAFst (weaken-ta-Δ1 disj wt)
weaken-ta-Δ1 disj (TASnd wt) = TASnd (weaken-ta-Δ1 disj wt)
-- this is a little bit of a time saver. since ∪ is commutative on
-- disjoint contexts, and we need that premise anyway in both positions,
-- there's no real reason to repeat the inductive argument above
weaken-ta-Δ2 : ∀{Δ1 Δ2 Γ d τ} →
Δ1 ## Δ2 →
Δ2 , Γ ⊢ d :: τ →
(Δ1 ∪ Δ2) , Γ ⊢ d :: τ
weaken-ta-Δ2 {Δ1} {Δ2} {Γ} {d} {τ} disj D = tr (λ q → q , Γ ⊢ d :: τ) (∪comm Δ2 Δ1 (##-comm disj)) (weaken-ta-Δ1 (##-comm disj) D)
-- note that these statements are somewhat stronger than usual. this is
-- because we don't have implcit α-conversion. this reifies the
-- often-silent on paper assumption that if you collide with a bound
-- variable you can just α-convert it away and not worry.
mutual
weaken-synth : ∀{x Γ e τ τ'} →
freshh x e →
Γ ⊢ e => τ →
(Γ ,, (x , τ')) ⊢ e => τ
weaken-synth FRHNum SNum = SNum
weaken-synth (FRHPlus frsh frsh₁) (SPlus x x₁) = SPlus (weaken-ana frsh x) (weaken-ana frsh₁ x₁)
weaken-synth (FRHAsc frsh) (SAsc x₁) = SAsc (weaken-ana frsh x₁)
weaken-synth {Γ = Γ} (FRHVar {x = x} x₁) (SVar {x = y} x₂) = SVar (x∈∪r (■ (x , _)) Γ y _ x₂ (apart-singleton (flip x₁)))
weaken-synth {Γ = Γ} (FRHLam2 x₁ frsh) (SLam x₂ wt) =
SLam (apart-extend1 Γ (flip x₁) x₂)
(exchange-synth {Γ = Γ} (flip x₁) ((weaken-synth frsh wt)))
weaken-synth FRHEHole SEHole = SEHole
weaken-synth (FRHNEHole frsh) (SNEHole wt) = SNEHole (weaken-synth frsh wt)
weaken-synth (FRHAp frsh frsh₁) (SAp wt x₂ x₃) = SAp (weaken-synth frsh wt) x₂ (weaken-ana frsh₁ x₃)
weaken-synth (FRHPair frsh frsh₁) (SPair wt wt₁) = SPair (weaken-synth frsh wt) (weaken-synth frsh₁ wt₁)
weaken-synth (FRHFst frsh) (SFst wt x) = SFst (weaken-synth frsh wt) x
weaken-synth (FRHSnd frsh) (SSnd wt x) = SSnd (weaken-synth frsh wt) x
weaken-ana : ∀{x Γ e τ τ'} →
freshh x e →
Γ ⊢ e <= τ →
(Γ ,, (x , τ')) ⊢ e <= τ
weaken-ana frsh (ASubsume x₁ x₂) = ASubsume (weaken-synth frsh x₁) x₂
weaken-ana {Γ = Γ} (FRHLam1 neq frsh) (ALam x₂ x₃ wt) =
ALam (apart-extend1 Γ (flip neq) x₂)
x₃
(exchange-ana {Γ = Γ} (flip neq) (weaken-ana frsh wt))
weaken-ana (FRHInl frsh) (AInl x x₁) = AInl x (weaken-ana frsh x₁)
weaken-ana (FRHInr frsh) (AInr x x₁) = AInr x (weaken-ana frsh x₁)
weaken-ana {Γ = Γ} (FRHCase frshd newx≠y frshd₁ newx≠z frshd₂)
(ACase {Γ = .Γ} y#Γ z#Γ msum syn ana₁ ana₂) =
ACase (apart-extend1 Γ (flip newx≠y) y#Γ)
(apart-extend1 Γ (flip newx≠z) z#Γ)
msum
(weaken-synth {Γ = Γ} frshd syn)
(exchange-ana {Γ = Γ} (flip newx≠y) (weaken-ana frshd₁ ana₁))
(exchange-ana {Γ = Γ} (flip newx≠z) (weaken-ana frshd₂ ana₂))
mutual
weaken-subst-Γ : ∀{x Γ Δ σ Γ' τ} →
envfresh x σ →
Δ , Γ ⊢ σ :s: Γ' →
Δ , (Γ ,, (x , τ)) ⊢ σ :s: Γ'
weaken-subst-Γ {Γ = Γ} {τ = τ₁} (EFId {x = x₃} x₁) (STAId {Γ' = Γ'} x₂) = STAId (λ x τ x∈Γ' → x∈∪r (■ (x₃ , τ₁)) Γ x τ (x₂ x τ x∈Γ') (apart-singleton λ{refl → somenotnone ((! x∈Γ') · x₁)}))
weaken-subst-Γ {x = x} {Γ = Γ} (EFSubst x₁ efrsh x₂) (STASubst {y = y} {τ = τ'} subst x₃) =
STASubst (exchange-subst-Γ {Γ = Γ} (flip x₂) (weaken-subst-Γ {Γ = Γ ,, (y , τ')} efrsh subst))
(weaken-ta x₁ x₃)
weaken-ta : ∀{x Γ Δ d τ τ'} →
fresh x d →
Δ , Γ ⊢ d :: τ →
Δ , Γ ,, (x , τ') ⊢ d :: τ
weaken-ta FNum TANum = TANum
weaken-ta (FPlus x₁ x₂) (TAPlus x x₃) = TAPlus (weaken-ta x₁ x) (weaken-ta x₂ x₃)
weaken-ta {x} {Γ} {_} {_} {τ} {τ'} (FVar x₂) (TAVar x₃) = TAVar (x∈∪r (■(x , _)) Γ _ _ x₃ (apart-singleton (flip x₂)))
weaken-ta {x = x} frsh (TALam {x = y} x₂ wt) with natEQ x y
weaken-ta (FLam x₁ x₂) (TALam x₃ wt) | Inl refl = abort (x₁ refl)
weaken-ta {Γ = Γ} {τ' = τ'} (FLam x₁ x₃) (TALam {x = y} x₄ wt) | Inr x₂ = TALam (apart-extend1 Γ (flip x₁) x₄) (exchange-ta-Γ {Γ = Γ} (flip x₁) (weaken-ta x₃ wt))
weaken-ta (FAp frsh frsh₁) (TAAp wt wt₁) = TAAp (weaken-ta frsh wt) (weaken-ta frsh₁ wt₁)
weaken-ta (FHole x₁) (TAEHole x₂ x₃) = TAEHole x₂ (weaken-subst-Γ x₁ x₃)
weaken-ta (FNEHole x₁ frsh) (TANEHole x₂ wt x₃) = TANEHole x₂ (weaken-ta frsh wt) (weaken-subst-Γ x₁ x₃)
weaken-ta (FCast frsh) (TACast wt x₁) = TACast (weaken-ta frsh wt) x₁
weaken-ta (FFailedCast frsh) (TAFailedCast wt x₁ x₂ x₃) = TAFailedCast (weaken-ta frsh wt) x₁ x₂ x₃
weaken-ta (FInl frsh) (TAInl wt) = TAInl (weaken-ta frsh wt)
weaken-ta (FInr frsh) (TAInr wt) = TAInr (weaken-ta frsh wt)
weaken-ta {Γ = Γ} (FCase frsh x frsh₁ x₁ frsh₂) (TACase wt x₂ wt₁ x₃ wt₂) =
TACase (weaken-ta frsh wt)
(apart-extend1 Γ (flip x) x₂)
(exchange-ta-Γ {Γ = Γ} (flip x) (weaken-ta frsh₁ wt₁))
(apart-extend1 Γ (flip x₁) x₃)
(exchange-ta-Γ {Γ = Γ} (flip x₁) (weaken-ta frsh₂ wt₂))
weaken-ta (FPair frsh frsh₁) (TAPair wt wt₁) = TAPair (weaken-ta frsh wt) (weaken-ta frsh₁ wt₁)
weaken-ta (FFst frsh) (TAFst wt) = TAFst (weaken-ta frsh wt)
weaken-ta (FSnd frsh) (TASnd wt) = TASnd (weaken-ta frsh wt)
|
{
"alphanum_fraction": 0.5655980603,
"avg_line_length": 58,
"ext": "agda",
"hexsha": "c6dc62f19d3a42f8bae7992edb32c002e42b18fc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "weakening.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "weakening.agda",
"max_line_length": 193,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "weakening.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3226,
"size": 7424
}
|
{-# OPTIONS --without-K #-}
module FiniteFunctions where
open import Data.Vec using (tabulate; _∷_)
open import Data.Fin using (Fin; zero; suc)
open import Data.Nat using (ℕ; suc)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; cong; module ≡-Reasoning)
open import Function using (_∘_)
------------------------------------------------------------------------------
-- Important: Extensionality for finite functions
finext : {n : ℕ} {A : Set} → {f g : Fin n → A} → ((i : Fin n) → f i ≡ g i) →
(tabulate f ≡ tabulate g)
finext {0} _ = refl
finext {suc n} {_} {f} {g} fi≡gi =
begin (tabulate {suc n} f
≡⟨ refl ⟩
f zero ∷ tabulate {n} (f ∘ suc)
≡⟨ cong (λ x → x ∷ tabulate {n} (f ∘ suc)) (fi≡gi zero) ⟩
g zero ∷ tabulate {n} (f ∘ suc)
≡⟨ cong (_∷_ (g zero))
(finext {f = f ∘ suc} {g ∘ suc} (fi≡gi ∘ suc)) ⟩
g zero ∷ tabulate {n} (g ∘ suc)
≡⟨ refl ⟩
tabulate g ∎)
where open ≡-Reasoning
------------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.4533450704,
"avg_line_length": 35.5,
"ext": "agda",
"hexsha": "d6822652953fa17cd2c4b9a7539dc667053110c5",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/FiniteFunctions.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/FiniteFunctions.agda",
"max_line_length": 79,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/FiniteFunctions.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 354,
"size": 1136
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use `Data.Universe` instead.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Universe where
{-# WARNING_ON_IMPORT
"Universe was deprecated in v1.1.
Use Data.Universe instead."
#-}
open import Data.Universe public
open import Data.Universe.Indexed public
renaming (IndexedUniverse to Indexed-universe)
|
{
"alphanum_fraction": 0.5387596899,
"avg_line_length": 27.1578947368,
"ext": "agda",
"hexsha": "97f2f41afd2df74be1e20ae04de15094cc40cd56",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Universe.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Universe.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Universe.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 92,
"size": 516
}
|
-- A cut-down example:
module Issue295 where
data ⊥ : Set where
data Arr : Set where
_⟶_ : ⊥ → ⊥ → Arr
_﹔_ : Arr → Arr → Arr
(a ⟶ b)﹔(c ⟶ d) with b
... | ()
data Fun : Arr → Set where
∙ : ∀ a b c d → Fun (a ⟶ b) → Fun (c ⟶ d) → Fun ((a ⟶ b)﹔(c ⟶ d))
f : ∀ a b c d e f → Fun (a ⟶ b) → Fun (c ⟶ d) → Fun (e ⟶ f)
f a b c d e f F G = ∙ a b c d F G
-- The problem does not appear to be restricted to the pretty-printer.
-- With -v10 I get the following output:
--
-- compareTerm (a ⟶ b) ﹔ (b ⟶ c) == a ⟶ c : Arr
-- { compareAtom
-- compareAtom (b ⟶ a) ﹔ (c ⟶ b) | b == a ⟶ c : Arr
-- /tmp/Bug.agda:16,15-28
-- (b ⟶ a) ﹔ (c ⟶ b) | b != a ⟶ c of type Arr
-- when checking that the expression ∙ a b b c F G has type
-- Fun (a ⟶ c)
|
{
"alphanum_fraction": 0.514324693,
"avg_line_length": 25.275862069,
"ext": "agda",
"hexsha": "a59db9185ba9e799bf9ce9b2b84341361511e5cd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "4383a3d20328a6c43689161496cee8eb479aca08",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dagit/agda",
"max_forks_repo_path": "test/fail/Issue295.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4383a3d20328a6c43689161496cee8eb479aca08",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dagit/agda",
"max_issues_repo_path": "test/fail/Issue295.agda",
"max_line_length": 70,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/Issue295.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T07:26:06.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T07:26:06.000Z",
"num_tokens": 324,
"size": 733
}
|
{-# OPTIONS --without-K --rewriting #-}
module lib.modalities.Modalities where
open import lib.modalities.Truncation public
|
{
"alphanum_fraction": 0.7698412698,
"avg_line_length": 21,
"ext": "agda",
"hexsha": "ec86f0e68eb52cc7146273b1d8119a597542fa14",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/modalities/Modalities.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/modalities/Modalities.agda",
"max_line_length": 44,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/modalities/Modalities.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 28,
"size": 126
}
|
module Cats.Category.Cat.Facts.Product where
open import Data.Bool using (true ; false)
open import Data.Product using (_,_)
open import Level using (_⊔_)
open import Cats.Category
open import Cats.Category.Cat as Cat using (Cat ; Functor ; _⇒_ ; _∘_ ; id ; _≈_)
open import Cats.Category.Product.Binary using (_×_)
open import Cats.Category.Product.Binary.Facts using (iso-intro)
open import Cats.Trans.Iso using (NatIso)
open import Cats.Util.Logic.Constructive using (_∧_ ; ∧-eliml ; ∧-elimr)
open Functor
module _ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈} {D : Category lo′ la′ l≈′}
where
private
module C = Category C
module D = Category D
proj₁ : (C × D) ⇒ C
proj₁ = record
{ fobj = ∧-eliml
; fmap = ∧-eliml
; fmap-resp = ∧-eliml
; fmap-id = C.≈.refl
; fmap-∘ = C.≈.refl
}
proj₂ : (C × D) ⇒ D
proj₂ = record
{ fobj = ∧-elimr
; fmap = ∧-elimr
; fmap-resp = ∧-elimr
; fmap-id = D.≈.refl
; fmap-∘ = D.≈.refl
}
module _ {lo″ la″ l≈″} {X : Category lo″ la″ l≈″} where
⟨_,_⟩ : X ⇒ C → X ⇒ D → X ⇒ (C × D)
⟨ F , G ⟩ = record
{ fobj = λ x → fobj F x , fobj G x
; fmap = λ f → fmap F f , fmap G f
; fmap-resp = λ eq → fmap-resp F eq , fmap-resp G eq
; fmap-id = fmap-id F , fmap-id G
; fmap-∘ = fmap-∘ F , fmap-∘ G
}
module _ {F : X ⇒ C} {G : X ⇒ D} where
⟨,⟩-proj₁ : proj₁ ∘ ⟨ F , G ⟩ ≈ F
⟨,⟩-proj₁ = record
{ iso = C.≅.refl
; forth-natural = C.≈.trans C.id-l (C.≈.sym C.id-r)
}
⟨,⟩-proj₂ : proj₂ ∘ ⟨ F , G ⟩ ≈ G
⟨,⟩-proj₂ = record
{ iso = D.≅.refl
; forth-natural = D.≈.trans D.id-l (D.≈.sym D.id-r)
}
⟨,⟩-unique : ∀ {H} → proj₁ ∘ H ≈ F → proj₂ ∘ H ≈ G → H ≈ ⟨ F , G ⟩
⟨,⟩-unique {H} eq₁ eq₂ = record
{ iso = iso-intro (iso eq₁) (iso eq₂)
; forth-natural = forth-natural eq₁ , forth-natural eq₂
}
where
open NatIso
instance
hasBinaryProducts : ∀ lo la l≈ → HasBinaryProducts (Cat lo la l≈)
hasBinaryProducts lo la l≈ .HasBinaryProducts._×′_ C D
= mkBinaryProduct proj₁ proj₂ isBinaryProduct
where
open module Catt = Category (Cat lo la l≈) using
(IsBinaryProduct ; mkBinaryProduct ; ∃!-intro)
module ≈ = Catt.≈
isBinaryProduct : ∀ {C D : Category lo la l≈}
→ IsBinaryProduct (C × D) proj₁ proj₂
isBinaryProduct {C} {D} {X} F G = ∃!-intro
⟨ F , G ⟩
(≈.sym (⟨,⟩-proj₁ {G = G}) , ≈.sym (⟨,⟩-proj₂ {F = F}))
λ { (eq₁ , eq₂) → ≈.sym (⟨,⟩-unique (≈.sym eq₁) (≈.sym eq₂)) }
-- We get the following functors 'for free' from the above definition of
-- products in Cat, but those must have their domain and codomain category at
-- the same levels. The definitions below lift this restriction.
⟨_×_⟩ : ∀ {lo₁ la₁ l≈₁ lo₂ la₂ l≈₂ lo₃ la₃ l≈₃ lo₄ la₄ l≈₄}
→ {C : Category lo₁ la₁ l≈₁} {C′ : Category lo₂ la₂ l≈₂}
→ {D : Category lo₃ la₃ l≈₃} {D′ : Category lo₄ la₄ l≈₄}
→ C ⇒ C′ → D ⇒ D′ → (C × D) ⇒ (C′ × D′)
⟨ F × G ⟩ = ⟨ F ∘ proj₁ , G ∘ proj₂ ⟩
First : ∀ {lo₁ la₁ l≈₁ lo₂ la₂ l≈₂ lo₃ la₃ l≈₃}
→ {C : Category lo₁ la₁ l≈₁} {C′ : Category lo₂ la₂ l≈₂}
→ {D : Category lo₃ la₃ l≈₃}
→ C ⇒ C′ → (C × D) ⇒ (C′ × D)
First F = ⟨ F × id ⟩
Second : ∀ {lo₁ la₁ l≈₁ lo₂ la₂ l≈₂ lo₃ la₃ l≈₃}
→ {C : Category lo₁ la₁ l≈₁} {D : Category lo₂ la₂ l≈₂}
→ {D′ : Category lo₃ la₃ l≈₃}
→ D ⇒ D′ → (C × D) ⇒ (C × D′)
Second F = ⟨ id × F ⟩
Swap : ∀ {lo₁ la₁ l≈₁ lo₂ la₂ l≈₂}
→ {C : Category lo₁ la₁ l≈₁} {D : Category lo₂ la₂ l≈₂}
→ (C × D) ⇒ (D × C)
Swap = ⟨ proj₂ , proj₁ ⟩
|
{
"alphanum_fraction": 0.5268583831,
"avg_line_length": 28.3538461538,
"ext": "agda",
"hexsha": "94b8e84f16735ae094e2122eb4ad88fde2265df7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Category/Cat/Facts/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Category/Cat/Facts/Product.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Category/Cat/Facts/Product.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1502,
"size": 3686
}
|
module datatype-functions where
open import lib
open import ctxt
open import syntax-util
open import general-util
open import cedille-types
open import subst
open import rename
open import is-free
data indx : Set where
Index : var → tk → indx
indices = 𝕃 indx
data datatype : Set where
Data : var → params → indices → ctrs → datatype
{-# TERMINATING #-}
decompose-arrows : ctxt → type → params × type
decompose-arrows Γ (Abs pi me pi' x atk T) =
let x' = fresh-var-new Γ x in
case decompose-arrows (ctxt-var-decl x' Γ) (rename-var Γ x x' T) of λ where
(ps , T') → Decl posinfo-gen posinfo-gen me x' atk posinfo-gen :: ps , T'
decompose-arrows Γ (TpArrow T me T') =
let x = fresh-var-new Γ "x" in
case decompose-arrows (ctxt-var-decl x Γ) T' of λ where
(ps , T'') → Decl posinfo-gen posinfo-gen me x (Tkt T) posinfo-gen :: ps , T''
decompose-arrows Γ (TpParens pi T pi') = decompose-arrows Γ T
decompose-arrows Γ T = [] , T
decompose-ctr-type : ctxt → type → type × params × 𝕃 tty
decompose-ctr-type Γ T with decompose-arrows Γ T
...| ps , Tᵣ with decompose-tpapps Tᵣ
...| Tₕ , as = Tₕ , ps , as
{-# TERMINATING #-}
kind-to-indices : ctxt → kind → indices
kind-to-indices Γ (KndArrow k k') =
let x' = fresh-var-new Γ "x" in
Index x' (Tkk k) :: kind-to-indices (ctxt-var-decl x' Γ) k'
kind-to-indices Γ (KndParens pi k pi') = kind-to-indices Γ k
kind-to-indices Γ (KndPi pi pi' x atk k) =
let x' = fresh-var-new Γ x in
Index x' atk :: kind-to-indices (ctxt-var-decl x' Γ) (rename-var Γ x x' k)
kind-to-indices Γ (KndTpArrow T k) =
let x' = fresh-var-new Γ "x" in
Index x' (Tkt T) :: kind-to-indices (ctxt-var-decl x' Γ) k
kind-to-indices Γ (KndVar pi x as) with ctxt-lookup-kind-var-def Γ x
...| nothing = []
...| just (ps , k) = kind-to-indices Γ $ fst $ subst-params-args Γ ps as k
kind-to-indices Γ (Star pi) = []
tk-erased : tk → maybeErased → maybeErased
tk-erased (Tkk _) me = Erased
tk-erased (Tkt _) me = me
params-set-erased : maybeErased → params → params
params-set-erased me = map λ where
(Decl pi pi' me' x atk pi'') → Decl pi pi' me x atk pi''
args-set-erased : maybeErased → args → args
args-set-erased = map ∘ arg-set-erased
indices-to-kind : indices → kind → kind
indices-to-kind = flip $ foldr λ {(Index x atk) → KndPi posinfo-gen posinfo-gen x atk}
params-to-kind : params → kind → kind
params-to-kind = flip $ foldr λ {(Decl pi pi' me x atk pi'') → KndPi pi pi' x atk}
indices-to-tplams : indices → (body : type) → type
indices-to-tplams = flip $ foldr λ where
(Index x atk) → TpLambda posinfo-gen posinfo-gen x atk
params-to-tplams : params → (body : type) → type
params-to-tplams = flip $ foldr λ where
(Decl pi pi' me x atk pi'') → TpLambda pi pi' x atk
indices-to-alls : indices → (body : type) → type
indices-to-alls = flip $ foldr λ where
(Index x atk) → Abs posinfo-gen Erased posinfo-gen x atk
params-to-alls : params → (body : type) → type
params-to-alls = flip $ foldr λ where
(Decl pi pi' me x atk pi'') → Abs pi (tk-erased atk me) pi' x atk
indices-to-lams : indices → (body : term) → term
indices-to-lams = flip $ foldr λ where
(Index x atk) → Lam posinfo-gen Erased posinfo-gen x (SomeClass atk)
indices-to-lams' : indices → (body : term) → term
indices-to-lams' = flip $ foldr λ where
(Index x atk) → Lam posinfo-gen Erased posinfo-gen x NoClass
params-to-lams : params → (body : term) → term
params-to-lams = flip $ foldr λ where
(Decl pi pi' me x atk pi'') → Lam pi (tk-erased atk me) pi' x (SomeClass atk)
params-to-lams' : params → (body : term) → term
params-to-lams' = flip $ foldr λ where
(Decl pi pi' me x atk pi'') → Lam pi (tk-erased atk me) pi' x NoClass
indices-to-apps : indices → (body : term) → term
indices-to-apps = flip $ foldl λ where
(Index x (Tkt T)) t → App t Erased (mvar x)
(Index x (Tkk k)) t → AppTp t (mtpvar x)
params-to-apps : params → (body : term) → term
params-to-apps = flip $ foldl λ where
(Decl pi pi' me x (Tkt T) pi'') t → App t me (mvar x)
(Decl pi pi' me x (Tkk k) pi'') t → AppTp t (mtpvar x)
indices-to-tpapps : indices → (body : type) → type
indices-to-tpapps = flip $ foldl λ where
(Index x (Tkt T)) T' → TpAppt T' (mvar x)
(Index x (Tkk k)) T → TpApp T (mtpvar x)
params-to-tpapps : params → (body : type) → type
params-to-tpapps = flip $ foldl λ where
(Decl pi pi' me x (Tkt T) pi'') T' → TpAppt T' (mvar x)
(Decl pi pi' me x (Tkk k) pi'') T → TpApp T (mtpvar x)
ctrs-to-lams' : ctrs → (body : term) → term
ctrs-to-lams' = flip $ foldr λ where
(Ctr _ x T) → Lam posinfo-gen NotErased posinfo-gen x NoClass
ctrs-to-lams : ctxt → var → params → ctrs → (body : term) → term
ctrs-to-lams Γ x ps cs t = foldr
(λ {(Ctr _ y T) f Γ → Lam posinfo-gen NotErased posinfo-gen y
(SomeClass $ Tkt $ subst Γ (params-to-tpapps ps $ mtpvar y) y T)
$ f $ ctxt-var-decl y Γ})
(λ Γ → t) cs Γ
add-indices-to-ctxt : indices → ctxt → ctxt
add-indices-to-ctxt = flip $ foldr λ {(Index x atk) → ctxt-var-decl x}
add-params-to-ctxt : params → ctxt → ctxt
add-params-to-ctxt = flip $ foldr λ {(Decl _ _ _ x'' _ _) → ctxt-var-decl x''}
add-caseArgs-to-ctxt : caseArgs → ctxt → ctxt
add-caseArgs-to-ctxt = flip $ foldr λ {(CaseTermArg _ _ x) → ctxt-var-decl x; (CaseTypeArg _ x) → ctxt-var-decl x}
add-ctrs-to-ctxt : ctrs → ctxt → ctxt
add-ctrs-to-ctxt = flip $ foldr λ {(Ctr _ x T) → ctxt-var-decl x}
positivity : Set
positivity = 𝔹 × 𝔹 -- occurs positively × occurs negatively
pattern occurs-nil = ff , ff
pattern occurs-pos = tt , ff
pattern occurs-neg = ff , tt
pattern occurs-all = tt , tt
--positivity-inc : positivity → positivity
--positivity-dec : positivity → positivity
positivity-neg : positivity → positivity
positivity-add : positivity → positivity → positivity
--positivity-inc = map-fst λ _ → tt
--positivity-dec = map-snd λ _ → tt
positivity-neg = uncurry $ flip _,_
positivity-add (+ₘ , -ₘ) (+ₙ , -ₙ) = (+ₘ || +ₙ) , (-ₘ || -ₙ)
-- just tt = negative occurrence; just ff = not in the return type; nothing = okay
{-# TERMINATING #-}
ctr-positive : ctxt → var → type → maybe 𝔹
ctr-positive Γ x = arrs+ Γ ∘ hnf' Γ where
open import conversion
not-free : ∀ {ed} → ⟦ ed ⟧ → maybe 𝔹
not-free = maybe-map (λ _ → tt) ∘' maybe-if ∘' is-free-in check-erased x
if-free : ∀ {ed} → ⟦ ed ⟧ → positivity
if-free t with is-free-in check-erased x t
...| f = f , f
hnf' : ctxt → type → type
hnf' Γ T = hnf Γ unfold-all T tt
mtt = maybe-else tt id
mff = maybe-else ff id
posₒ = fst
negₒ = snd
occurs : positivity → maybe 𝔹
occurs p = maybe-if (negₒ p) ≫maybe just tt
arrs+ : ctxt → type → maybe 𝔹
type+ : ctxt → type → positivity
kind+ : ctxt → kind → positivity
tk+ : ctxt → tk → positivity
arrs+ Γ (Abs _ _ _ x' atk T) =
let Γ' = ctxt-var-decl x' Γ in
occurs (tk+ Γ atk) maybe-or arrs+ Γ' (hnf' Γ' T)
arrs+ Γ (TpApp T T') = arrs+ Γ T maybe-or not-free T'
arrs+ Γ (TpAppt T t) = arrs+ Γ T maybe-or not-free t
arrs+ Γ (TpArrow T _ T') = occurs (type+ Γ (hnf' Γ T)) maybe-or arrs+ Γ (hnf' Γ T')
arrs+ Γ (TpLambda _ _ x' atk T) =
let Γ' = ctxt-var-decl x' Γ in
occurs (tk+ Γ atk) maybe-or arrs+ Γ' (hnf' Γ' T)
arrs+ Γ (TpVar _ x') = maybe-not (maybe-if (x =string x')) ≫maybe just ff
arrs+ Γ T = just ff
type+ Γ (Abs _ _ _ x' atk T) =
let Γ' = ctxt-var-decl x' Γ; atk+? = tk+ Γ atk in
positivity-add (positivity-neg $ tk+ Γ atk) (type+ Γ' $ hnf' Γ' T)
type+ Γ (Iota _ _ x' T T') =
let Γ' = ctxt-var-decl x' Γ; T? = type+ Γ T in
positivity-add (type+ Γ T) (type+ Γ' T')
type+ Γ (Lft _ _ x' t lT) = occurs-all
type+ Γ (NoSpans T _) = type+ Γ T
type+ Γ (TpLet _ (DefTerm _ x' T? t) T) = type+ Γ (hnf' Γ (subst Γ t x' T))
type+ Γ (TpLet _ (DefType _ x' k T) T') = type+ Γ (hnf' Γ (subst Γ T x' T'))
type+ Γ (TpApp T T') = positivity-add (type+ Γ T) (if-free T')
type+ Γ (TpAppt T t) = positivity-add (type+ Γ T) (if-free t)
type+ Γ (TpArrow T _ T') = positivity-add (positivity-neg $ type+ Γ T) (type+ Γ $ hnf' Γ T')
type+ Γ (TpEq _ tₗ tᵣ _) = occurs-nil
type+ Γ (TpHole _) = occurs-nil
type+ Γ (TpLambda _ _ x' atk T)=
let Γ' = ctxt-var-decl x' Γ in
positivity-add (positivity-neg $ tk+ Γ atk) (type+ Γ' (hnf' Γ' T))
type+ Γ (TpParens _ T _) = type+ Γ T
type+ Γ (TpVar _ x') = x =string x' , ff
kind+ Γ (KndArrow k k') = positivity-add (positivity-neg $ kind+ Γ k) (kind+ Γ k')
kind+ Γ (KndParens _ k _) = kind+ Γ k
kind+ Γ (KndPi _ _ x' atk k) =
let Γ' = ctxt-var-decl x' Γ in
positivity-add (positivity-neg $ tk+ Γ atk) (kind+ Γ' k)
kind+ Γ (KndTpArrow T k) = positivity-add (positivity-neg $ type+ Γ T) (kind+ Γ k)
kind+ Γ (KndVar _ κ as) =
maybe-else' (ctxt-lookup-kind-var-def Γ κ) occurs-nil $ uncurry λ ps k → kind+ Γ (fst (subst-params-args Γ ps as k))
kind+ Γ (Star _) = occurs-nil
tk+ Γ (Tkt T) = type+ Γ (hnf' Γ T)
tk+ Γ (Tkk k) = kind+ Γ k
|
{
"alphanum_fraction": 0.6272942236,
"avg_line_length": 36.6983471074,
"ext": "agda",
"hexsha": "6146140d6512f08206ffab2c3e2dee43853f9b60",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CarlOlson/cedille",
"max_forks_repo_path": "src/datatype-functions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CarlOlson/cedille",
"max_issues_repo_path": "src/datatype-functions.agda",
"max_line_length": 120,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CarlOlson/cedille",
"max_stars_repo_path": "src/datatype-functions.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3278,
"size": 8881
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Algebra where
-- Algebra for a Functor
open import Level
open import Function using (_$_)
open import Categories.Category using (Category)
open import Categories.Functor using (Functor; Endofunctor)
private
variable
o ℓ e : Level
module _ {C : Category o ℓ e} where
record F-Algebra (F : Endofunctor C) : Set (o ⊔ ℓ) where
open Category C
field
A : Obj
α : Functor.F₀ F A ⇒ A
open F-Algebra
-- Given an F-Algebra F, one can apply F to it to obtain an new 'iterated' F-Algebra
iterate : {F : Endofunctor C} → F-Algebra F → F-Algebra F
iterate {F} c = record { A = Functor.F₀ F $ A c ; α = Functor.F₁ F $ α c }
record F-Algebra-Morphism {F : Endofunctor C} (X Y : F-Algebra F) : Set (ℓ ⊔ e) where
open Category C
module X = F-Algebra X
module Y = F-Algebra Y
open Functor F
field
f : X.A ⇒ Y.A
commutes : f ∘ X.α ≈ Y.α ∘ F₁ f
|
{
"alphanum_fraction": 0.6358921162,
"avg_line_length": 25.3684210526,
"ext": "agda",
"hexsha": "4c45d60d5ade5b746d586710a79d05cb79fadf76",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Functor/Algebra.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Functor/Algebra.agda",
"max_line_length": 87,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Functor/Algebra.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 314,
"size": 964
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some derivable properties
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Algebra.Properties.BooleanAlgebra
{b₁ b₂} (B : BooleanAlgebra b₁ b₂)
where
open BooleanAlgebra B
import Algebra.Properties.DistributiveLattice
private
open module DL = Algebra.Properties.DistributiveLattice
distributiveLattice public
hiding (replace-equality)
open import Algebra.Structures _≈_
open import Algebra.FunctionProperties _≈_
open import Algebra.FunctionProperties.Consequences setoid
open import Relation.Binary.Reasoning.Setoid setoid
open import Relation.Binary
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (_⇔_; module Equivalence)
open import Data.Product using (_,_)
------------------------------------------------------------------------
-- Some simple generalisations
∨-complementˡ : LeftInverse ⊤ ¬_ _∨_
∨-complementˡ = comm+invʳ⇒invˡ ∨-comm ∨-complementʳ
∨-complement : Inverse ⊤ ¬_ _∨_
∨-complement = ∨-complementˡ , ∨-complementʳ
∧-complementˡ : LeftInverse ⊥ ¬_ _∧_
∧-complementˡ = comm+invʳ⇒invˡ ∧-comm ∧-complementʳ
∧-complement : Inverse ⊥ ¬_ _∧_
∧-complement = ∧-complementˡ , ∧-complementʳ
------------------------------------------------------------------------
-- The dual construction is also a boolean algebra
∧-∨-isBooleanAlgebra : IsBooleanAlgebra _∧_ _∨_ ¬_ ⊥ ⊤
∧-∨-isBooleanAlgebra = record
{ isDistributiveLattice = ∧-∨-isDistributiveLattice
; ∨-complementʳ = ∧-complementʳ
; ∧-complementʳ = ∨-complementʳ
; ¬-cong = ¬-cong
}
∧-∨-booleanAlgebra : BooleanAlgebra _ _
∧-∨-booleanAlgebra = record
{ _∧_ = _∨_
; _∨_ = _∧_
; ⊤ = ⊥
; ⊥ = ⊤
; isBooleanAlgebra = ∧-∨-isBooleanAlgebra
}
------------------------------------------------------------------------
-- (∨, ∧, ⊥, ⊤) and (∧, ∨, ⊤, ⊥) are commutative semirings
∧-identityʳ : RightIdentity ⊤ _∧_
∧-identityʳ x = begin
x ∧ ⊤ ≈⟨ ∧-congˡ (sym (∨-complementʳ _)) ⟩
x ∧ (x ∨ ¬ x) ≈⟨ ∧-absorbs-∨ _ _ ⟩
x ∎
∧-identityˡ : LeftIdentity ⊤ _∧_
∧-identityˡ = comm+idʳ⇒idˡ ∧-comm ∧-identityʳ
∧-identity : Identity ⊤ _∧_
∧-identity = ∧-identityˡ , ∧-identityʳ
∨-identityʳ : RightIdentity ⊥ _∨_
∨-identityʳ x = begin
x ∨ ⊥ ≈⟨ ∨-congˡ $ sym (∧-complementʳ _) ⟩
x ∨ x ∧ ¬ x ≈⟨ ∨-absorbs-∧ _ _ ⟩
x ∎
∨-identityˡ : LeftIdentity ⊥ _∨_
∨-identityˡ = comm+idʳ⇒idˡ ∨-comm ∨-identityʳ
∨-identity : Identity ⊥ _∨_
∨-identity = ∨-identityˡ , ∨-identityʳ
∧-zeroʳ : RightZero ⊥ _∧_
∧-zeroʳ x = begin
x ∧ ⊥ ≈⟨ ∧-congˡ $ sym (∧-complementʳ _) ⟩
x ∧ x ∧ ¬ x ≈˘⟨ ∧-assoc _ _ _ ⟩
(x ∧ x) ∧ ¬ x ≈⟨ ∧-congʳ $ ∧-idempotent _ ⟩
x ∧ ¬ x ≈⟨ ∧-complementʳ _ ⟩
⊥ ∎
∧-zeroˡ : LeftZero ⊥ _∧_
∧-zeroˡ = comm+zeʳ⇒zeˡ ∧-comm ∧-zeroʳ
∧-zero : Zero ⊥ _∧_
∧-zero = ∧-zeroˡ , ∧-zeroʳ
∨-zeroʳ : ∀ x → x ∨ ⊤ ≈ ⊤
∨-zeroʳ x = begin
x ∨ ⊤ ≈⟨ ∨-congˡ $ sym (∨-complementʳ _) ⟩
x ∨ x ∨ ¬ x ≈˘⟨ ∨-assoc _ _ _ ⟩
(x ∨ x) ∨ ¬ x ≈⟨ ∨-congʳ $ ∨-idempotent _ ⟩
x ∨ ¬ x ≈⟨ ∨-complementʳ _ ⟩
⊤ ∎
∨-zeroˡ : LeftZero ⊤ _∨_
∨-zeroˡ _ = ∨-comm _ _ ⟨ trans ⟩ ∨-zeroʳ _
∨-zero : Zero ⊤ _∨_
∨-zero = ∨-zeroˡ , ∨-zeroʳ
∨-isMagma : IsMagma _∨_
∨-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = ∨-cong
}
∧-isMagma : IsMagma _∧_
∧-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = ∧-cong
}
∨-isSemigroup : IsSemigroup _∨_
∨-isSemigroup = record
{ isMagma = ∨-isMagma
; assoc = ∨-assoc
}
∧-isSemigroup : IsSemigroup _∧_
∧-isSemigroup = record
{ isMagma = ∧-isMagma
; assoc = ∧-assoc
}
∨-⊥-isMonoid : IsMonoid _∨_ ⊥
∨-⊥-isMonoid = record
{ isSemigroup = ∨-isSemigroup
; identity = ∨-identity
}
∧-⊤-isMonoid : IsMonoid _∧_ ⊤
∧-⊤-isMonoid = record
{ isSemigroup = ∧-isSemigroup
; identity = ∧-identity
}
∨-⊥-isCommutativeMonoid : IsCommutativeMonoid _∨_ ⊥
∨-⊥-isCommutativeMonoid = record
{ isSemigroup = ∨-isSemigroup
; identityˡ = ∨-identityˡ
; comm = ∨-comm
}
∧-⊤-isCommutativeMonoid : IsCommutativeMonoid _∧_ ⊤
∧-⊤-isCommutativeMonoid = record
{ isSemigroup = ∧-isSemigroup
; identityˡ = ∧-identityˡ
; comm = ∧-comm
}
∨-∧-isCommutativeSemiring : IsCommutativeSemiring _∨_ _∧_ ⊥ ⊤
∨-∧-isCommutativeSemiring = record
{ +-isCommutativeMonoid = ∨-⊥-isCommutativeMonoid
; *-isCommutativeMonoid = ∧-⊤-isCommutativeMonoid
; distribʳ = ∧-∨-distribʳ
; zeroˡ = ∧-zeroˡ
}
∨-∧-commutativeSemiring : CommutativeSemiring _ _
∨-∧-commutativeSemiring = record
{ _+_ = _∨_
; _*_ = _∧_
; 0# = ⊥
; 1# = ⊤
; isCommutativeSemiring = ∨-∧-isCommutativeSemiring
}
∧-∨-isCommutativeSemiring : IsCommutativeSemiring _∧_ _∨_ ⊤ ⊥
∧-∨-isCommutativeSemiring = record
{ +-isCommutativeMonoid = ∧-⊤-isCommutativeMonoid
; *-isCommutativeMonoid = ∨-⊥-isCommutativeMonoid
; distribʳ = ∨-∧-distribʳ
; zeroˡ = ∨-zeroˡ
}
∧-∨-commutativeSemiring : CommutativeSemiring _ _
∧-∨-commutativeSemiring = record
{ _+_ = _∧_
; _*_ = _∨_
; 0# = ⊤
; 1# = ⊥
; isCommutativeSemiring = ∧-∨-isCommutativeSemiring
}
------------------------------------------------------------------------
-- Some other properties
-- I took the statement of this lemma (called Uniqueness of
-- Complements) from some course notes, "Boolean Algebra", written
-- by Gert Smolka.
private
lemma : ∀ x y → x ∧ y ≈ ⊥ → x ∨ y ≈ ⊤ → ¬ x ≈ y
lemma x y x∧y=⊥ x∨y=⊤ = begin
¬ x ≈˘⟨ ∧-identityʳ _ ⟩
¬ x ∧ ⊤ ≈˘⟨ ∧-congˡ x∨y=⊤ ⟩
¬ x ∧ (x ∨ y) ≈⟨ ∧-∨-distribˡ _ _ _ ⟩
¬ x ∧ x ∨ ¬ x ∧ y ≈⟨ ∨-congʳ $ ∧-complementˡ _ ⟩
⊥ ∨ ¬ x ∧ y ≈˘⟨ ∨-congʳ x∧y=⊥ ⟩
x ∧ y ∨ ¬ x ∧ y ≈˘⟨ ∧-∨-distribʳ _ _ _ ⟩
(x ∨ ¬ x) ∧ y ≈⟨ ∧-congʳ $ ∨-complementʳ _ ⟩
⊤ ∧ y ≈⟨ ∧-identityˡ _ ⟩
y ∎
¬⊥=⊤ : ¬ ⊥ ≈ ⊤
¬⊥=⊤ = lemma ⊥ ⊤ (∧-identityʳ _) (∨-zeroʳ _)
¬⊤=⊥ : ¬ ⊤ ≈ ⊥
¬⊤=⊥ = lemma ⊤ ⊥ (∧-zeroʳ _) (∨-identityʳ _)
¬-involutive : Involutive ¬_
¬-involutive x = lemma (¬ x) x (∧-complementˡ _) (∨-complementˡ _)
deMorgan₁ : ∀ x y → ¬ (x ∧ y) ≈ ¬ x ∨ ¬ y
deMorgan₁ x y = lemma (x ∧ y) (¬ x ∨ ¬ y) lem₁ lem₂
where
lem₁ = begin
(x ∧ y) ∧ (¬ x ∨ ¬ y) ≈⟨ ∧-∨-distribˡ _ _ _ ⟩
(x ∧ y) ∧ ¬ x ∨ (x ∧ y) ∧ ¬ y ≈⟨ ∨-congʳ $ ∧-congʳ $ ∧-comm _ _ ⟩
(y ∧ x) ∧ ¬ x ∨ (x ∧ y) ∧ ¬ y ≈⟨ ∧-assoc _ _ _ ⟨ ∨-cong ⟩ ∧-assoc _ _ _ ⟩
y ∧ (x ∧ ¬ x) ∨ x ∧ (y ∧ ¬ y) ≈⟨ (∧-congˡ $ ∧-complementʳ _) ⟨ ∨-cong ⟩
(∧-congˡ $ ∧-complementʳ _) ⟩
(y ∧ ⊥) ∨ (x ∧ ⊥) ≈⟨ ∧-zeroʳ _ ⟨ ∨-cong ⟩ ∧-zeroʳ _ ⟩
⊥ ∨ ⊥ ≈⟨ ∨-identityʳ _ ⟩
⊥ ∎
lem₃ = begin
(x ∧ y) ∨ ¬ x ≈⟨ ∨-∧-distribʳ _ _ _ ⟩
(x ∨ ¬ x) ∧ (y ∨ ¬ x) ≈⟨ ∧-congʳ $ ∨-complementʳ _ ⟩
⊤ ∧ (y ∨ ¬ x) ≈⟨ ∧-identityˡ _ ⟩
y ∨ ¬ x ≈⟨ ∨-comm _ _ ⟩
¬ x ∨ y ∎
lem₂ = begin
(x ∧ y) ∨ (¬ x ∨ ¬ y) ≈˘⟨ ∨-assoc _ _ _ ⟩
((x ∧ y) ∨ ¬ x) ∨ ¬ y ≈⟨ ∨-congʳ lem₃ ⟩
(¬ x ∨ y) ∨ ¬ y ≈⟨ ∨-assoc _ _ _ ⟩
¬ x ∨ (y ∨ ¬ y) ≈⟨ ∨-congˡ $ ∨-complementʳ _ ⟩
¬ x ∨ ⊤ ≈⟨ ∨-zeroʳ _ ⟩
⊤ ∎
deMorgan₂ : ∀ x y → ¬ (x ∨ y) ≈ ¬ x ∧ ¬ y
deMorgan₂ x y = begin
¬ (x ∨ y) ≈˘⟨ ¬-cong $ ((¬-involutive _) ⟨ ∨-cong ⟩ (¬-involutive _)) ⟩
¬ (¬ ¬ x ∨ ¬ ¬ y) ≈˘⟨ ¬-cong $ deMorgan₁ _ _ ⟩
¬ ¬ (¬ x ∧ ¬ y) ≈⟨ ¬-involutive _ ⟩
¬ x ∧ ¬ y ∎
-- One can replace the underlying equality with an equivalent one.
replace-equality :
{_≈′_ : Rel Carrier b₂} →
(∀ {x y} → x ≈ y ⇔ (x ≈′ y)) → BooleanAlgebra _ _
replace-equality {_≈′_} ≈⇔≈′ = record
{ _≈_ = _≈′_
; _∨_ = _∨_
; _∧_ = _∧_
; ¬_ = ¬_
; ⊤ = ⊤
; ⊥ = ⊥
; isBooleanAlgebra = record
{ isDistributiveLattice = DistributiveLattice.isDistributiveLattice
(DL.replace-equality ≈⇔≈′)
; ∨-complementʳ = λ x → to ⟨$⟩ ∨-complementʳ x
; ∧-complementʳ = λ x → to ⟨$⟩ ∧-complementʳ x
; ¬-cong = λ i≈j → to ⟨$⟩ ¬-cong (from ⟨$⟩ i≈j)
}
} where open module E {x y} = Equivalence (≈⇔≈′ {x} {y})
------------------------------------------------------------------------
-- (⊕, ∧, id, ⊥, ⊤) is a commutative ring
-- This construction is parameterised over the definition of xor.
module XorRing
(xor : Op₂ Carrier)
(⊕-def : ∀ x y → xor x y ≈ (x ∨ y) ∧ ¬ (x ∧ y))
where
private
infixl 6 _⊕_
_⊕_ : Op₂ Carrier
_⊕_ = xor
helper : ∀ {x y u v} → x ≈ y → u ≈ v → x ∧ ¬ u ≈ y ∧ ¬ v
helper x≈y u≈v = x≈y ⟨ ∧-cong ⟩ ¬-cong u≈v
⊕-cong : Congruent₂ _⊕_
⊕-cong {x} {y} {u} {v} x≈y u≈v = begin
x ⊕ u ≈⟨ ⊕-def _ _ ⟩
(x ∨ u) ∧ ¬ (x ∧ u) ≈⟨ helper (x≈y ⟨ ∨-cong ⟩ u≈v)
(x≈y ⟨ ∧-cong ⟩ u≈v) ⟩
(y ∨ v) ∧ ¬ (y ∧ v) ≈˘⟨ ⊕-def _ _ ⟩
y ⊕ v ∎
⊕-comm : Commutative _⊕_
⊕-comm x y = begin
x ⊕ y ≈⟨ ⊕-def _ _ ⟩
(x ∨ y) ∧ ¬ (x ∧ y) ≈⟨ helper (∨-comm _ _) (∧-comm _ _) ⟩
(y ∨ x) ∧ ¬ (y ∧ x) ≈˘⟨ ⊕-def _ _ ⟩
y ⊕ x ∎
⊕-¬-distribˡ : ∀ x y → ¬ (x ⊕ y) ≈ ¬ x ⊕ y
⊕-¬-distribˡ x y = begin
¬ (x ⊕ y) ≈⟨ ¬-cong $ ⊕-def _ _ ⟩
¬ ((x ∨ y) ∧ (¬ (x ∧ y))) ≈⟨ ¬-cong (∧-∨-distribʳ _ _ _) ⟩
¬ ((x ∧ ¬ (x ∧ y)) ∨ (y ∧ ¬ (x ∧ y))) ≈⟨ ¬-cong $ ∨-congˡ $ ∧-congˡ $ ¬-cong (∧-comm _ _) ⟩
¬ ((x ∧ ¬ (x ∧ y)) ∨ (y ∧ ¬ (y ∧ x))) ≈⟨ ¬-cong $ lem _ _ ⟨ ∨-cong ⟩ lem _ _ ⟩
¬ ((x ∧ ¬ y) ∨ (y ∧ ¬ x)) ≈⟨ deMorgan₂ _ _ ⟩
¬ (x ∧ ¬ y) ∧ ¬ (y ∧ ¬ x) ≈⟨ ∧-congʳ $ deMorgan₁ _ _ ⟩
(¬ x ∨ (¬ ¬ y)) ∧ ¬ (y ∧ ¬ x) ≈⟨ helper (∨-congˡ $ ¬-involutive _) (∧-comm _ _) ⟩
(¬ x ∨ y) ∧ ¬ (¬ x ∧ y) ≈˘⟨ ⊕-def _ _ ⟩
¬ x ⊕ y ∎
where
lem : ∀ x y → x ∧ ¬ (x ∧ y) ≈ x ∧ ¬ y
lem x y = begin
x ∧ ¬ (x ∧ y) ≈⟨ ∧-congˡ $ deMorgan₁ _ _ ⟩
x ∧ (¬ x ∨ ¬ y) ≈⟨ ∧-∨-distribˡ _ _ _ ⟩
(x ∧ ¬ x) ∨ (x ∧ ¬ y) ≈⟨ ∨-congʳ $ ∧-complementʳ _ ⟩
⊥ ∨ (x ∧ ¬ y) ≈⟨ ∨-identityˡ _ ⟩
x ∧ ¬ y ∎
⊕-¬-distribʳ : ∀ x y → ¬ (x ⊕ y) ≈ x ⊕ ¬ y
⊕-¬-distribʳ x y = begin
¬ (x ⊕ y) ≈⟨ ¬-cong $ ⊕-comm _ _ ⟩
¬ (y ⊕ x) ≈⟨ ⊕-¬-distribˡ _ _ ⟩
¬ y ⊕ x ≈⟨ ⊕-comm _ _ ⟩
x ⊕ ¬ y ∎
⊕-annihilates-¬ : ∀ x y → x ⊕ y ≈ ¬ x ⊕ ¬ y
⊕-annihilates-¬ x y = begin
x ⊕ y ≈˘⟨ ¬-involutive _ ⟩
¬ ¬ (x ⊕ y) ≈⟨ ¬-cong $ ⊕-¬-distribˡ _ _ ⟩
¬ (¬ x ⊕ y) ≈⟨ ⊕-¬-distribʳ _ _ ⟩
¬ x ⊕ ¬ y ∎
⊕-identityˡ : LeftIdentity ⊥ _⊕_
⊕-identityˡ x = begin
⊥ ⊕ x ≈⟨ ⊕-def _ _ ⟩
(⊥ ∨ x) ∧ ¬ (⊥ ∧ x) ≈⟨ helper (∨-identityˡ _) (∧-zeroˡ _) ⟩
x ∧ ¬ ⊥ ≈⟨ ∧-congˡ ¬⊥=⊤ ⟩
x ∧ ⊤ ≈⟨ ∧-identityʳ _ ⟩
x ∎
⊕-identityʳ : RightIdentity ⊥ _⊕_
⊕-identityʳ _ = ⊕-comm _ _ ⟨ trans ⟩ ⊕-identityˡ _
⊕-identity : Identity ⊥ _⊕_
⊕-identity = ⊕-identityˡ , ⊕-identityʳ
⊕-inverseˡ : LeftInverse ⊥ id _⊕_
⊕-inverseˡ x = begin
x ⊕ x ≈⟨ ⊕-def _ _ ⟩
(x ∨ x) ∧ ¬ (x ∧ x) ≈⟨ helper (∨-idempotent _) (∧-idempotent _) ⟩
x ∧ ¬ x ≈⟨ ∧-complementʳ _ ⟩
⊥ ∎
⊕-inverseʳ : RightInverse ⊥ id _⊕_
⊕-inverseʳ _ = ⊕-comm _ _ ⟨ trans ⟩ ⊕-inverseˡ _
⊕-inverse : Inverse ⊥ id _⊕_
⊕-inverse = ⊕-inverseˡ , ⊕-inverseʳ
∧-distribˡ-⊕ : _∧_ DistributesOverˡ _⊕_
∧-distribˡ-⊕ x y z = begin
x ∧ (y ⊕ z) ≈⟨ ∧-congˡ $ ⊕-def _ _ ⟩
x ∧ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈˘⟨ ∧-assoc _ _ _ ⟩
(x ∧ (y ∨ z)) ∧ ¬ (y ∧ z) ≈⟨ ∧-congˡ $ deMorgan₁ _ _ ⟩
(x ∧ (y ∨ z)) ∧
(¬ y ∨ ¬ z) ≈˘⟨ ∨-identityˡ _ ⟩
⊥ ∨
((x ∧ (y ∨ z)) ∧
(¬ y ∨ ¬ z)) ≈⟨ ∨-congʳ lem₃ ⟩
((x ∧ (y ∨ z)) ∧ ¬ x) ∨
((x ∧ (y ∨ z)) ∧
(¬ y ∨ ¬ z)) ≈˘⟨ ∧-∨-distribˡ _ _ _ ⟩
(x ∧ (y ∨ z)) ∧
(¬ x ∨ (¬ y ∨ ¬ z)) ≈˘⟨ ∧-congˡ $ ∨-congˡ (deMorgan₁ _ _) ⟩
(x ∧ (y ∨ z)) ∧
(¬ x ∨ ¬ (y ∧ z)) ≈˘⟨ ∧-congˡ (deMorgan₁ _ _) ⟩
(x ∧ (y ∨ z)) ∧
¬ (x ∧ (y ∧ z)) ≈⟨ helper refl lem₁ ⟩
(x ∧ (y ∨ z)) ∧
¬ ((x ∧ y) ∧ (x ∧ z)) ≈⟨ ∧-congʳ $ ∧-∨-distribˡ _ _ _ ⟩
((x ∧ y) ∨ (x ∧ z)) ∧
¬ ((x ∧ y) ∧ (x ∧ z)) ≈˘⟨ ⊕-def _ _ ⟩
(x ∧ y) ⊕ (x ∧ z) ∎
where
lem₂ = begin
x ∧ (y ∧ z) ≈˘⟨ ∧-assoc _ _ _ ⟩
(x ∧ y) ∧ z ≈⟨ ∧-congʳ $ ∧-comm _ _ ⟩
(y ∧ x) ∧ z ≈⟨ ∧-assoc _ _ _ ⟩
y ∧ (x ∧ z) ∎
lem₁ = begin
x ∧ (y ∧ z) ≈˘⟨ ∧-congʳ (∧-idempotent _) ⟩
(x ∧ x) ∧ (y ∧ z) ≈⟨ ∧-assoc _ _ _ ⟩
x ∧ (x ∧ (y ∧ z)) ≈⟨ ∧-congˡ lem₂ ⟩
x ∧ (y ∧ (x ∧ z)) ≈˘⟨ ∧-assoc _ _ _ ⟩
(x ∧ y) ∧ (x ∧ z) ∎
lem₃ = begin
⊥ ≈˘⟨ ∧-zeroʳ _ ⟩
(y ∨ z) ∧ ⊥ ≈˘⟨ ∧-congˡ (∧-complementʳ _) ⟩
(y ∨ z) ∧ (x ∧ ¬ x) ≈˘⟨ ∧-assoc _ _ _ ⟩
((y ∨ z) ∧ x) ∧ ¬ x ≈⟨ ∧-comm _ _ ⟨ ∧-cong ⟩ refl ⟩
(x ∧ (y ∨ z)) ∧ ¬ x ∎
∧-distribʳ-⊕ : _∧_ DistributesOverʳ _⊕_
∧-distribʳ-⊕ = comm+distrˡ⇒distrʳ ⊕-cong ∧-comm ∧-distribˡ-⊕
∧-distrib-⊕ : _∧_ DistributesOver _⊕_
∧-distrib-⊕ = ∧-distribˡ-⊕ , ∧-distribʳ-⊕
private
lemma₂ : ∀ x y u v →
(x ∧ y) ∨ (u ∧ v) ≈
((x ∨ u) ∧ (y ∨ u)) ∧
((x ∨ v) ∧ (y ∨ v))
lemma₂ x y u v = begin
(x ∧ y) ∨ (u ∧ v) ≈⟨ ∨-∧-distribˡ _ _ _ ⟩
((x ∧ y) ∨ u) ∧ ((x ∧ y) ∨ v) ≈⟨ ∨-∧-distribʳ _ _ _
⟨ ∧-cong ⟩
∨-∧-distribʳ _ _ _ ⟩
((x ∨ u) ∧ (y ∨ u)) ∧
((x ∨ v) ∧ (y ∨ v)) ∎
⊕-assoc : Associative _⊕_
⊕-assoc x y z = sym $ begin
x ⊕ (y ⊕ z) ≈⟨ refl ⟨ ⊕-cong ⟩ ⊕-def _ _ ⟩
x ⊕ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ ⊕-def _ _ ⟩
(x ∨ ((y ∨ z) ∧ ¬ (y ∧ z))) ∧
¬ (x ∧ ((y ∨ z) ∧ ¬ (y ∧ z))) ≈⟨ lem₃ ⟨ ∧-cong ⟩ lem₄ ⟩
(((x ∨ y) ∨ z) ∧ ((x ∨ ¬ y) ∨ ¬ z)) ∧
(((¬ x ∨ ¬ y) ∨ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ≈⟨ ∧-assoc _ _ _ ⟩
((x ∨ y) ∨ z) ∧
(((x ∨ ¬ y) ∨ ¬ z) ∧
(((¬ x ∨ ¬ y) ∨ z) ∧ ((¬ x ∨ y) ∨ ¬ z))) ≈⟨ ∧-congˡ lem₅ ⟩
((x ∨ y) ∨ z) ∧
(((¬ x ∨ ¬ y) ∨ z) ∧
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z))) ≈˘⟨ ∧-assoc _ _ _ ⟩
(((x ∨ y) ∨ z) ∧ ((¬ x ∨ ¬ y) ∨ z)) ∧
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ≈⟨ lem₁ ⟨ ∧-cong ⟩ lem₂ ⟩
(((x ∨ y) ∧ ¬ (x ∧ y)) ∨ z) ∧
¬ (((x ∨ y) ∧ ¬ (x ∧ y)) ∧ z) ≈˘⟨ ⊕-def _ _ ⟩
((x ∨ y) ∧ ¬ (x ∧ y)) ⊕ z ≈˘⟨ ⊕-def _ _ ⟨ ⊕-cong ⟩ refl ⟩
(x ⊕ y) ⊕ z ∎
where
lem₁ = begin
((x ∨ y) ∨ z) ∧ ((¬ x ∨ ¬ y) ∨ z) ≈˘⟨ ∨-∧-distribʳ _ _ _ ⟩
((x ∨ y) ∧ (¬ x ∨ ¬ y)) ∨ z ≈˘⟨ ∨-congʳ $ ∧-congˡ (deMorgan₁ _ _) ⟩
((x ∨ y) ∧ ¬ (x ∧ y)) ∨ z ∎
lem₂' = begin
(x ∨ ¬ y) ∧ (¬ x ∨ y) ≈˘⟨ ∧-identityˡ _ ⟨ ∧-cong ⟩ ∧-identityʳ _ ⟩
(⊤ ∧ (x ∨ ¬ y)) ∧ ((¬ x ∨ y) ∧ ⊤) ≈˘⟨ (∨-complementˡ _ ⟨ ∧-cong ⟩ ∨-comm _ _)
⟨ ∧-cong ⟩
(∧-congˡ $ ∨-complementˡ _) ⟩
((¬ x ∨ x) ∧ (¬ y ∨ x)) ∧
((¬ x ∨ y) ∧ (¬ y ∨ y)) ≈˘⟨ lemma₂ _ _ _ _ ⟩
(¬ x ∧ ¬ y) ∨ (x ∧ y) ≈˘⟨ deMorgan₂ _ _ ⟨ ∨-cong ⟩ ¬-involutive _ ⟩
¬ (x ∨ y) ∨ ¬ ¬ (x ∧ y) ≈˘⟨ deMorgan₁ _ _ ⟩
¬ ((x ∨ y) ∧ ¬ (x ∧ y)) ∎
lem₂ = begin
((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z) ≈˘⟨ ∨-∧-distribʳ _ _ _ ⟩
((x ∨ ¬ y) ∧ (¬ x ∨ y)) ∨ ¬ z ≈⟨ ∨-congʳ lem₂' ⟩
¬ ((x ∨ y) ∧ ¬ (x ∧ y)) ∨ ¬ z ≈˘⟨ deMorgan₁ _ _ ⟩
¬ (((x ∨ y) ∧ ¬ (x ∧ y)) ∧ z) ∎
lem₃ = begin
x ∨ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ ∨-congˡ $ ∧-congˡ $ deMorgan₁ _ _ ⟩
x ∨ ((y ∨ z) ∧ (¬ y ∨ ¬ z)) ≈⟨ ∨-∧-distribˡ _ _ _ ⟩
(x ∨ (y ∨ z)) ∧ (x ∨ (¬ y ∨ ¬ z)) ≈˘⟨ ∨-assoc _ _ _ ⟨ ∧-cong ⟩ ∨-assoc _ _ _ ⟩
((x ∨ y) ∨ z) ∧ ((x ∨ ¬ y) ∨ ¬ z) ∎
lem₄' = begin
¬ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ deMorgan₁ _ _ ⟩
¬ (y ∨ z) ∨ ¬ ¬ (y ∧ z) ≈⟨ deMorgan₂ _ _ ⟨ ∨-cong ⟩ ¬-involutive _ ⟩
(¬ y ∧ ¬ z) ∨ (y ∧ z) ≈⟨ lemma₂ _ _ _ _ ⟩
((¬ y ∨ y) ∧ (¬ z ∨ y)) ∧
((¬ y ∨ z) ∧ (¬ z ∨ z)) ≈⟨ (∨-complementˡ _ ⟨ ∧-cong ⟩ ∨-comm _ _)
⟨ ∧-cong ⟩
(∧-congˡ $ ∨-complementˡ _) ⟩
(⊤ ∧ (y ∨ ¬ z)) ∧
((¬ y ∨ z) ∧ ⊤) ≈⟨ ∧-identityˡ _ ⟨ ∧-cong ⟩ ∧-identityʳ _ ⟩
(y ∨ ¬ z) ∧ (¬ y ∨ z) ∎
lem₄ = begin
¬ (x ∧ ((y ∨ z) ∧ ¬ (y ∧ z))) ≈⟨ deMorgan₁ _ _ ⟩
¬ x ∨ ¬ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ ∨-congˡ lem₄' ⟩
¬ x ∨ ((y ∨ ¬ z) ∧ (¬ y ∨ z)) ≈⟨ ∨-∧-distribˡ _ _ _ ⟩
(¬ x ∨ (y ∨ ¬ z)) ∧
(¬ x ∨ (¬ y ∨ z)) ≈˘⟨ ∨-assoc _ _ _ ⟨ ∧-cong ⟩ ∨-assoc _ _ _ ⟩
((¬ x ∨ y) ∨ ¬ z) ∧
((¬ x ∨ ¬ y) ∨ z) ≈⟨ ∧-comm _ _ ⟩
((¬ x ∨ ¬ y) ∨ z) ∧
((¬ x ∨ y) ∨ ¬ z) ∎
lem₅ = begin
((x ∨ ¬ y) ∨ ¬ z) ∧
(((¬ x ∨ ¬ y) ∨ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ≈˘⟨ ∧-assoc _ _ _ ⟩
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ ¬ y) ∨ z)) ∧
((¬ x ∨ y) ∨ ¬ z) ≈⟨ ∧-congʳ $ ∧-comm _ _ ⟩
(((¬ x ∨ ¬ y) ∨ z) ∧ ((x ∨ ¬ y) ∨ ¬ z)) ∧
((¬ x ∨ y) ∨ ¬ z) ≈⟨ ∧-assoc _ _ _ ⟩
((¬ x ∨ ¬ y) ∨ z) ∧
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ∎
⊕-isMagma : IsMagma _⊕_
⊕-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = ⊕-cong
}
⊕-isSemigroup : IsSemigroup _⊕_
⊕-isSemigroup = record
{ isMagma = ⊕-isMagma
; assoc = ⊕-assoc
}
⊕-⊥-isMonoid : IsMonoid _⊕_ ⊥
⊕-⊥-isMonoid = record
{ isSemigroup = ⊕-isSemigroup
; identity = ⊕-identity
}
⊕-⊥-isGroup : IsGroup _⊕_ ⊥ id
⊕-⊥-isGroup = record
{ isMonoid = ⊕-⊥-isMonoid
; inverse = ⊕-inverse
; ⁻¹-cong = id
}
⊕-⊥-isAbelianGroup : IsAbelianGroup _⊕_ ⊥ id
⊕-⊥-isAbelianGroup = record
{ isGroup = ⊕-⊥-isGroup
; comm = ⊕-comm
}
⊕-∧-isRing : IsRing _⊕_ _∧_ id ⊥ ⊤
⊕-∧-isRing = record
{ +-isAbelianGroup = ⊕-⊥-isAbelianGroup
; *-isMonoid = ∧-⊤-isMonoid
; distrib = ∧-distrib-⊕
}
isCommutativeRing : IsCommutativeRing _⊕_ _∧_ id ⊥ ⊤
isCommutativeRing = record
{ isRing = ⊕-∧-isRing
; *-comm = ∧-comm
}
commutativeRing : CommutativeRing _ _
commutativeRing = record
{ _+_ = _⊕_
; _*_ = _∧_
; -_ = id
; 0# = ⊥
; 1# = ⊤
; isCommutativeRing = isCommutativeRing
}
infixl 6 _⊕_
_⊕_ : Op₂ Carrier
x ⊕ y = (x ∨ y) ∧ ¬ (x ∧ y)
module DefaultXorRing = XorRing _⊕_ (λ _ _ → refl)
|
{
"alphanum_fraction": 0.3878276093,
"avg_line_length": 32.8057432432,
"ext": "agda",
"hexsha": "d7ee92fbcebaac60dba1cf6a6a7fb194036874d0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Properties/BooleanAlgebra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Properties/BooleanAlgebra.agda",
"max_line_length": 96,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Properties/BooleanAlgebra.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9368,
"size": 19421
}
|
-- Andreas, 2017-08-13, issue #2684
-- Better error for abstract constructor.
abstract
data D : Set where
c : D
data E : Set where
c : E
test : D
test = c
-- Expected:
-- Constructor c is abstract, thus, not in scope here
-- when checking that the expression c has type D
|
{
"alphanum_fraction": 0.6631944444,
"avg_line_length": 16.9411764706,
"ext": "agda",
"hexsha": "4e972b4f0f2f4f4805fba32e53eeb9f3a05562cb",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue2684.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue2684.agda",
"max_line_length": 53,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2684.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 84,
"size": 288
}
|
-- Check that unquoted functions are termination checked.
module _ where
open import Common.Prelude hiding (_>>=_)
open import Common.Reflection
open import Common.Equality
`⊥ : Type
`⊥ = def (quote ⊥) []
⊥-elim : ∀ {a} {A : Set a} → ⊥ → A
⊥-elim ()
{-
Generate
cheat : ⊥
cheat = cheat
-}
makeLoop : TC Term
makeLoop =
freshName "cheat" >>= λ cheat →
declareDef (vArg cheat) `⊥ >>= λ _ →
defineFun cheat (clause [] (def cheat []) ∷ []) >>= λ _ →
returnTC (def cheat [])
macro
magic : Tactic
magic hole =
makeLoop >>= λ loop →
unify hole (def (quote ⊥-elim) (vArg loop ∷ []))
postulate
ComplexityClass : Set
P NP : ComplexityClass
thm : P ≡ NP → ⊥
thm = magic
|
{
"alphanum_fraction": 0.6123919308,
"avg_line_length": 18.2631578947,
"ext": "agda",
"hexsha": "d4bfd3285ca71012564a5e2aac50a45a1d55d962",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/TerminationCheckUnquote.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Fail/TerminationCheckUnquote.agda",
"max_line_length": 59,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Fail/TerminationCheckUnquote.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 235,
"size": 694
}
|
module Issue1290b where
open import Issue1290
data Eq (x : R) : R → Set where
refl : Eq x x
test : Eq x (exp x)
test = refl
|
{
"alphanum_fraction": 0.6511627907,
"avg_line_length": 12.9,
"ext": "agda",
"hexsha": "4d90a7a692963506af22fa06103b2736945af6b5",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue1290b.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue1290b.agda",
"max_line_length": 31,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1290b.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 45,
"size": 129
}
|
------------------------------------------------------------------------
-- Simple combinators working solely on and with functions
------------------------------------------------------------------------
module Data.Function where
infixr 9 _∘_ _∘′_ _∘₀_ _∘₁_
infixl 1 _on_ _on₁_
infixl 1 _⟨_⟩_ _⟨_⟩₁_
infixr 0 _-[_]₁-_ _-[_]-_ _$_
infix 0 _∶_ _∶₁_
------------------------------------------------------------------------
-- Types
-- Unary functions on a given set.
Fun₁ : Set → Set
Fun₁ a = a → a
-- Binary functions on a given set.
Fun₂ : Set → Set
Fun₂ a = a → a → a
------------------------------------------------------------------------
-- Functions
_∘_ : {A : Set} {B : A → Set} {C : {x : A} → B x → Set} →
(∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →
((x : A) → C (g x))
f ∘ g = λ x → f (g x)
_∘′_ : {A B C : Set} → (B → C) → (A → B) → (A → C)
f ∘′ g = _∘_ f g
_∘₀_ : {A : Set} {B : A → Set} {C : {x : A} → B x → Set₁} →
(∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →
((x : A) → C (g x))
f ∘₀ g = λ x → f (g x)
_∘₁_ : {A : Set₁} {B : A → Set₁} {C : {x : A} → B x → Set₁} →
(∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →
((x : A) → C (g x))
f ∘₁ g = λ x → f (g x)
id : {a : Set} → a → a
id x = x
id₁ : {a : Set₁} → a → a
id₁ x = x
const : {a b : Set} → a → b → a
const x = λ _ → x
const₁ : {a : Set₁} {b : Set} → a → b → a
const₁ x = λ _ → x
flip : {A B : Set} {C : A → B → Set} →
((x : A) (y : B) → C x y) → ((y : B) (x : A) → C x y)
flip f = λ x y → f y x
flip₁ : {A B : Set} {C : A → B → Set₁} →
((x : A) (y : B) → C x y) → ((y : B) (x : A) → C x y)
flip₁ f = λ x y → f y x
-- Note that _$_ is right associative, like in Haskell. If you want a
-- left associative infix application operator, use
-- Category.Functor._<$>_, available from
-- Category.Monad.Identity.IdentityMonad.
_$_ : {a : Set} {b : a → Set} → ((x : a) → b x) → ((x : a) → b x)
f $ x = f x
_⟨_⟩_ : {a b c : Set} → a → (a → b → c) → b → c
x ⟨ f ⟩ y = f x y
_⟨_⟩₁_ : {a b : Set} → a → (a → b → Set) → b → Set
x ⟨ f ⟩₁ y = f x y
_on_ : {a b c : Set} → (b → b → c) → (a → b) → (a → a → c)
_*_ on f = λ x y → f x * f y
_on₁_ : {a b : Set} {c : Set₁} → (b → b → c) → (a → b) → (a → a → c)
_*_ on₁ f = λ x y → f x * f y
_-[_]-_ : {a b c d e : Set} →
(a → b → c) → (c → d → e) → (a → b → d) → (a → b → e)
f -[ _*_ ]- g = λ x y → f x y * g x y
_-[_]₁-_ : {a b : Set} →
(a → b → Set) → (Set → Set → Set) → (a → b → Set) →
(a → b → Set)
f -[ _*_ ]₁- g = λ x y → f x y * g x y
-- In Agda you cannot annotate every subexpression with a type
-- signature. This function can be used instead.
--
-- You should think of the colon as being mirrored around its vertical
-- axis; the type comes first.
_∶_ : (A : Set) → A → A
_ ∶ x = x
_∶₁_ : (A : Set₁) → A → A
_ ∶₁ x = x
|
{
"alphanum_fraction": 0.3939712583,
"avg_line_length": 26.6635514019,
"ext": "agda",
"hexsha": "9534cde627c98121393406434fba850d1b211d59",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/Function.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/Function.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/Function.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 1203,
"size": 2853
}
|
{-# OPTIONS --safe #-}
module Definition.Typed.Consequences.Injectivity where
open import Definition.Untyped hiding (wk)
import Definition.Untyped as U
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Weakening
open import Definition.Typed.Properties
open import Definition.Typed.EqRelInstance
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Fundamental.Reducibility
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Helper function of injectivity for specific reducible Π-types
injectivity′ : ∀ {F G H E rF lF rH lH rΠ lG lE Γ lΠ l}
([ΠFG] : Γ ⊩⟨ l ⟩Π Π F ^ rF ° lF ▹ G ° lG ° lΠ ^[ rΠ , lΠ ] )
→ Γ ⊩⟨ l ⟩ Π F ^ rF ° lF ▹ G ° lG ° lΠ ≡ Π H ^ rH ° lH ▹ E ° lE ° lΠ ^ [ rΠ , ι lΠ ] / Π-intr [ΠFG]
→ Γ ⊢ F ≡ H ^ [ rF , ι lF ]
× rF PE.≡ rH
× lF PE.≡ lH
× lG PE.≡ lE
× Γ ∙ F ^ [ rF , ι lF ] ⊢ G ≡ E ^ [ rΠ , ι lG ]
injectivity′ {F₁} {G₁} {H} {E} {lF = lF₁} {rΠ = rΠ} {Γ = Γ}
(noemb (Πᵣ ! lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
let F≡F₁ , rF≡rF₁ , lF≡lF₁ , G≡G₁ , lG≡lG₁ , _ = Π-PE-injectivity (whnfRed* (red D) Πₙ)
H≡F′ , rH≡rF′ , lH≡lF′ , E≡G′ , lE≡lG′ , _ = Π-PE-injectivity (whnfRed* D′ Πₙ)
⊢Γ = wf ⊢F
[F]₁ = [F] id ⊢Γ
[F]′ = irrelevance′ (PE.trans (wk-id _) (PE.sym F≡F₁)) [F]₁
[x∷F] = neuTerm ([F] (step id) (⊢Γ ∙ ⊢F)) (var 0) (var (⊢Γ ∙ ⊢F) here)
(refl (var (⊢Γ ∙ ⊢F) here))
[G]₁ = [G] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G]′ = PE.subst₂ (λ x y → _ ∙ y ^ _ ⊩⟨ _ ⟩ x ^ _)
(PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.sym F≡F₁) [G]₁
[F≡H]₁ = [F≡F′] id ⊢Γ
[F≡H]′ = irrelevanceEq″ (PE.trans (wk-id _) (PE.sym F≡F₁))
(PE.trans (wk-id _) (PE.sym H≡F′))
PE.refl PE.refl
[F]₁ [F]′ [F≡H]₁
[G≡E]₁ = [G≡G′] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G≡E]′ = irrelevanceEqLift″ (PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.trans (wkSingleSubstId _) (PE.sym E≡G′))
(PE.sym F≡F₁) [G]₁ [G]′ [G≡E]₁
in PE.subst (λ r → Γ ⊢ _ ≡ _ ^ [ r , ι lF₁ ] ) (PE.sym rF≡rF₁)
(PE.subst (λ l → Γ ⊢ F₁ ≡ H ^ [ ! , l ] ) (PE.cong ι (PE.sym lF≡lF₁))
(escapeEq [F]′ [F≡H]′)) ,
( PE.trans rF≡rF₁ (PE.sym rH≡rF′) ,
( PE.trans lF≡lF₁ (PE.sym lH≡lF′) ,
( PE.trans lG≡lG₁ (PE.sym lE≡lG′) ,
PE.subst (λ r → (_ ∙ _ ^ [ r , _ ] ) ⊢ _ ≡ _ ^ _) (PE.sym rF≡rF₁)
(PE.subst (λ l → (Γ ∙ F₁ ^ [ ! , ι lF₁ ] ) ⊢ G₁ ≡ E ^ [ rΠ , l ]) (PE.cong ι (PE.sym lG≡lG₁))
(PE.subst (λ l → (Γ ∙ F₁ ^ [ ! , l ] ) ⊢ G₁ ≡ E ^ [ rΠ , ι lG ]) (PE.cong ι (PE.sym lF≡lF₁))
(escapeEq [G]′ [G≡E]′))))))
injectivity′ {F₁} {G₁} {H} {E} {lF = lF₁} {rΠ = rΠ} {Γ = Γ}
(noemb (Πᵣ % lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
let F≡F₁ , rF≡rF₁ , lF≡lF₁ , G≡G₁ , lG≡lG₁ , _ = Π-PE-injectivity (whnfRed* (red D) Πₙ)
H≡F′ , rH≡rF′ , lH≡lF′ , E≡G′ , lE≡lG′ , _ = Π-PE-injectivity (whnfRed* D′ Πₙ)
⊢Γ = wf ⊢F
[F]₁ = [F] id ⊢Γ
[F]′ = irrelevance′ (PE.trans (wk-id _) (PE.sym F≡F₁)) [F]₁
[x∷F] = neuTerm ([F] (step id) (⊢Γ ∙ ⊢F)) (var 0) (var (⊢Γ ∙ ⊢F) here)
(proof-irrelevance (var (⊢Γ ∙ ⊢F) here) (var (⊢Γ ∙ ⊢F) here))
[G]₁ = [G] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G]′ = PE.subst₂ (λ x y → _ ∙ y ^ _ ⊩⟨ _ ⟩ x ^ _)
(PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.sym F≡F₁) [G]₁
[F≡H]₁ = [F≡F′] id ⊢Γ
[F≡H]₁ = [F≡F′] id ⊢Γ
[F≡H]′ = irrelevanceEq″ (PE.trans (wk-id _) (PE.sym F≡F₁))
(PE.trans (wk-id _) (PE.sym H≡F′))
PE.refl PE.refl
[F]₁ [F]′ [F≡H]₁
[G≡E]₁ = [G≡G′] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G≡E]′ = irrelevanceEqLift″ (PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.trans (wkSingleSubstId _) (PE.sym E≡G′))
(PE.sym F≡F₁) [G]₁ [G]′ [G≡E]₁
in PE.subst (λ r → Γ ⊢ _ ≡ _ ^ [ r , ι lF₁ ] ) (PE.sym rF≡rF₁)
(PE.subst (λ l → Γ ⊢ F₁ ≡ H ^ [ % , l ] ) (PE.cong ι (PE.sym lF≡lF₁))
(escapeEq [F]′ [F≡H]′)) ,
( PE.trans rF≡rF₁ (PE.sym rH≡rF′) ,
( PE.trans lF≡lF₁ (PE.sym lH≡lF′) ,
( PE.trans lG≡lG₁ (PE.sym lE≡lG′) ,
PE.subst (λ r → (_ ∙ _ ^ [ r , _ ] ) ⊢ _ ≡ _ ^ _) (PE.sym rF≡rF₁)
(PE.subst (λ l → (Γ ∙ F₁ ^ [ % , ι lF₁ ] ) ⊢ G₁ ≡ E ^ [ rΠ , l ]) (PE.cong ι (PE.sym lG≡lG₁))
(PE.subst (λ l → (Γ ∙ F₁ ^ [ % , l ] ) ⊢ G₁ ≡ E ^ [ rΠ , ι lG ]) (PE.cong ι (PE.sym lF≡lF₁))
(escapeEq [G]′ [G≡E]′))))))
injectivity′ (emb emb< x) [ΠFG≡ΠHE] = injectivity′ x [ΠFG≡ΠHE]
injectivity′ (emb ∞< x) [ΠFG≡ΠHE] = injectivity′ x [ΠFG≡ΠHE]
-- Injectivity of Π
injectivity : ∀ {Γ F G H E rF lF lH lG lE rH rΠ lΠ} →
Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ ≡ Π H ^ rH ° lH ▹ E ° lE ° lΠ ^ [ rΠ , ι lΠ ]
→ Γ ⊢ F ≡ H ^ [ rF , ι lF ]
× rF PE.≡ rH
× lF PE.≡ lH
× lG PE.≡ lE
× Γ ∙ F ^ [ rF , ι lF ] ⊢ G ≡ E ^ [ rΠ , ι lG ]
injectivity ⊢ΠFG≡ΠHE =
let [ΠFG] , _ , [ΠFG≡ΠHE] = reducibleEq ⊢ΠFG≡ΠHE
in injectivity′ (Π-elim [ΠFG])
(irrelevanceEq [ΠFG] (Π-intr (Π-elim [ΠFG])) [ΠFG≡ΠHE])
Uinjectivity′ : ∀ {Γ r₁ r₂ l₁ l₂ lU l}
([U] : Γ ⊩⟨ l ⟩U Univ r₁ l₁ ^ lU)
→ Γ ⊩⟨ l ⟩ Univ r₁ l₁ ≡ Univ r₂ l₂ ^ [ ! , lU ] / U-intr [U]
→ r₁ PE.≡ r₂ × l₁ PE.≡ l₂
Uinjectivity′ (noemb (Uᵣ r l′ l< eq d)) D =
let A , B = Univ-PE-injectivity (whnfRed* D Uₙ)
A' , B' = Univ-PE-injectivity (whnfRed* (red d) Uₙ)
in (PE.trans A' (PE.sym A)) , (PE.trans B' (PE.sym B))
Uinjectivity′ (emb emb< a) b = Uinjectivity′ a b
Uinjectivity′ (emb ∞< a) b = Uinjectivity′ a b
Uinjectivity : ∀ {Γ r₁ r₂ l₁ l₂ lU} →
Γ ⊢ Univ r₁ l₁ ≡ Univ r₂ l₂ ^ [ ! , lU ] →
r₁ PE.≡ r₂ × l₁ PE.≡ l₂
Uinjectivity ⊢U≡U =
let [U] , _ , [U≡U] = reducibleEq ⊢U≡U
in Uinjectivity′ (U-elim [U]) (irrelevanceEq [U] (U-intr (U-elim [U])) [U≡U])
-- injectivity of ∃
∃injectivity′ : ∀ {F G H E Γ l∃ l}
([∃FG] : Γ ⊩⟨ l ⟩∃ ∃ F ▹ G ^ l∃ )
→ Γ ⊩⟨ l ⟩ ∃ F ▹ G ≡ ∃ H ▹ E ^ [ % , ι l∃ ] / ∃-intr [∃FG]
→ Γ ⊢ F ≡ H ^ [ % , ι l∃ ]
× Γ ∙ F ^ [ % , ι l∃ ] ⊢ G ≡ E ^ [ % , ι l∃ ]
∃injectivity′ {F₁} {G₁} {H} {E} {Γ = Γ}
(noemb (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext))
(∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
let F≡F₁ , G≡G₁ = ∃-PE-injectivity (whnfRed* (red D) ∃ₙ)
H≡F′ , E≡G′ = ∃-PE-injectivity (whnfRed* D′ ∃ₙ)
⊢Γ = wf ⊢F
[F]₁ = [F] id ⊢Γ
[F]′ = irrelevance′ (PE.trans (wk-id _) (PE.sym F≡F₁)) [F]₁
[x∷F] = neuTerm ([F] (step id) (⊢Γ ∙ ⊢F)) (var 0) (var (⊢Γ ∙ ⊢F) here) (proof-irrelevance (var (⊢Γ ∙ ⊢F) here) (var (⊢Γ ∙ ⊢F) here))
[G]₁ = [G] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G]′ = PE.subst₂ (λ x y → _ ∙ y ^ _ ⊩⟨ _ ⟩ x ^ _)
(PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.sym F≡F₁) [G]₁
[F≡H]₁ = [F≡F′] id ⊢Γ
[F≡H]′ = irrelevanceEq″ (PE.trans (wk-id _) (PE.sym F≡F₁))
(PE.trans (wk-id _) (PE.sym H≡F′))
PE.refl PE.refl
[F]₁ [F]′ [F≡H]₁
[G≡E]₁ = [G≡G′] (step id) (⊢Γ ∙ ⊢F) [x∷F]
[G≡E]′ = irrelevanceEqLift″ (PE.trans (wkSingleSubstId _) (PE.sym G≡G₁))
(PE.trans (wkSingleSubstId _) (PE.sym E≡G′))
(PE.sym F≡F₁) [G]₁ [G]′ [G≡E]₁
in escapeEq [F]′ [F≡H]′ , escapeEq [G]′ [G≡E]′
∃injectivity′ (emb emb< x) [∃FG≡∃HE] = ∃injectivity′ x [∃FG≡∃HE]
∃injectivity′ (emb ∞< x) [∃FG≡∃HE] = ∃injectivity′ x [∃FG≡∃HE]
-- Injectivity of ∃
∃injectivity : ∀ {Γ F G H E l∃} →
Γ ⊢ ∃ F ▹ G ≡ ∃ H ▹ E ^ [ % , ι l∃ ]
→ Γ ⊢ F ≡ H ^ [ % , ι l∃ ]
× Γ ∙ F ^ [ % , ι l∃ ] ⊢ G ≡ E ^ [ % , ι l∃ ]
∃injectivity ⊢∃FG≡∃HE =
let [∃FG] , _ , [∃FG≡∃HE] = reducibleEq ⊢∃FG≡∃HE
in ∃injectivity′ (∃-elim [∃FG])
(irrelevanceEq [∃FG] (∃-intr (∃-elim [∃FG])) [∃FG≡∃HE])
|
{
"alphanum_fraction": 0.4373840445,
"avg_line_length": 47.3846153846,
"ext": "agda",
"hexsha": "4b92e09ab3002be8c0dbddfc84e45374cf49fefc",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/Typed/Consequences/Injectivity.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/Typed/Consequences/Injectivity.agda",
"max_line_length": 140,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/Typed/Consequences/Injectivity.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 4242,
"size": 8624
}
|
module _ where
import Issue4373.A as A hiding (t)
postulate
search : ⦃ x : A.T ⦄ → Set
fail : Set
fail = search
|
{
"alphanum_fraction": 0.6440677966,
"avg_line_length": 10.7272727273,
"ext": "agda",
"hexsha": "77a7be2437289d1eadef3a4b16c7e502df93943b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue4373.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue4373.agda",
"max_line_length": 34,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue4373.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 43,
"size": 118
}
|
module Function.Domains.Proofs where
|
{
"alphanum_fraction": 0.8648648649,
"avg_line_length": 18.5,
"ext": "agda",
"hexsha": "6d87e9c19fc7dcc90ee0a9a4817075b5663144b8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Function/Domains/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Function/Domains/Proofs.agda",
"max_line_length": 36,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Function/Domains/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 8,
"size": 37
}
|
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Implementation.Standard.Relation.Decidable where
open import Light.Variable.Sets
import Light.Implementation.Standard.Data.Empty
import Light.Implementation.Standard.Data.Unit
open import Light.Library.Data.Empty as Empty using (Empty)
open import Light.Library.Data.Unit as Unit using (Unit ; unit)
open import Light.Library.Relation.Decidable using (Library ; Dependencies)
instance dependencies : Dependencies
dependencies = record {}
instance library : Library dependencies
library = record
{
Implementation ;
to‐witness = λ ⦃ a ⦄ → Implementation.to‐witness a ;
to‐false‐witness = λ ⦃ a ⦄ → Implementation.to‐false‐witness a ;
from‐witness = λ ⦃ a ⦄ → Implementation.from‐witness a ;
from‐false‐witness = λ ⦃ a ⦄ → Implementation.from‐false‐witness a
}
where
module Implementation where
open import Relation.Nullary using (yes ; no) renaming (Dec to Decidable) public
open Relation.Nullary using (does)
open import Function using (_∘_)
import Data.Bool as Boolean
open import Function using (id)
open import Relation.Nullary.Decidable
renaming (
toWitness to to‐witness ;
fromWitness to from‐witness ;
toWitnessFalse to to‐false‐witness ;
fromWitnessFalse to from‐false‐witness
)
public
open import Light.Implementation.Standard.Relation.Sets using (base) public
ℓf = id
if′_then_else_ : Decidable 𝕒 → 𝕓 → 𝕓 → 𝕓
if′_then_else_ = Boolean.if_then_else_ ∘ does
if_then_else_ :
∀ (a : Decidable 𝕒)
→ (∀ ⦃ witness : 𝕒 ⦄ → 𝕓)
→ (∀ ⦃ witness : 𝕒 → Empty ⦄ → 𝕓)
→ 𝕓
if yes w then a else _ = a ⦃ witness = w ⦄
if no w then _ else a = a ⦃ witness = w ⦄
module Style where
open import Relation.Nullary.Decidable using (True ; False) public
open import Relation.Nullary.Negation using () renaming (¬? to ¬_) public
open import Relation.Nullary.Product using () renaming (_×-dec_ to _∧_) public
open import Relation.Nullary.Sum using () renaming (_⊎-dec_ to _∨_) public
open import Relation.Nullary.Implication using () renaming (_→-dec_ to _⇢_) public
true : Decidable Unit
true = yes unit
false : Decidable Empty
false = no λ ()
style = record { Style }
|
{
"alphanum_fraction": 0.5576657459,
"avg_line_length": 42.5882352941,
"ext": "agda",
"hexsha": "300b2523404c7481b8725c0b1be6c28a85692bd8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "bindings/stdlib/Light/Implementation/Standard/Relation/Decidable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "bindings/stdlib/Light/Implementation/Standard/Relation/Decidable.agda",
"max_line_length": 100,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "bindings/stdlib/Light/Implementation/Standard/Relation/Decidable.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 655,
"size": 2896
}
|
module _ where
open import Agda.Primitive
open import Agda.Builtin.Equality
data Wrap {a} (A : Set a) : Set a where
wrap : A → Wrap A
data Unit (A : Set) : Set where
unit : Unit A
cast : ∀ {A B} → Unit A → Unit B
cast unit = unit
data Functor {a b} (F : Set a → Set b) : Set (lsuc (a ⊔ b)) where
mkFunctor : (∀ {A B} → (A → B) → F A → F B) → Functor F
fmap : ∀ {a b} {A B : Set a} {F : Set a → Set b} →
Functor F → (A → B) → F A → F B
fmap (mkFunctor m) = m
FunUnit : Functor Unit
FunUnit = mkFunctor λ _ → cast
postulate
P : ∀ {a} {A : Set a} → A → Set a
A : Set
fmapType : ∀ {b} {B : Set} {F : Set → Set b} {x : F A} →
Functor F → (A → B) → P x → Set _
fmapType {x = x} Fun f _ = P (fmap Fun f x)
postulate
wrapP : ∀ {a} {A : Set a} (x : A) → P (wrap x)
mutual-block : Set₁
a : Level
a = _
X : Set → Set a
X = _
FunX : Functor X
FunX = mkFunctor _
-- Adds constraint:
-- fmapType FunX wrap (wrapP x) == P (wrap (wrap x))
-- P (fmap FunX wrap (wrap x) == P (wrap (wrap x))
-- fmap FunX wrap (wrap x) == wrap (wrap x)
-- ?0 wrap (wrap x) == wrap (wrap x)
constr₁ : (x : _) → fmapType {x = _} FunX wrap (wrapP x) → P (wrap (wrap x))
constr₁ x p = p
constr₂ : P FunX → P FunUnit
constr₂ p = p
mutual-block = Set
|
{
"alphanum_fraction": 0.5394736842,
"avg_line_length": 21.5333333333,
"ext": "agda",
"hexsha": "f162229328829a83a3e1fa9dfb493813aad201bf",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-06-14T11:07:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-14T11:07:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Bugs/Issue3870.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Bugs/Issue3870.agda",
"max_line_length": 76,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Bugs/Issue3870.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 507,
"size": 1292
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.Bouquet
open import homotopy.FinWedge
open import homotopy.SphereEndomorphism
open import groups.SphereEndomorphism
open import cw.CW
open import cw.FinCW
open import cw.WedgeOfCells
open import cw.DegreeByProjection {lzero}
open import cohomology.Theory
{- This file should be part of RephraseHigherFinCoboundary,
but putting these in a separate file seems more effective
in speeding up type-checking. Could be an Agda bug. -}
module cw.cohomology.cochainequiv.HigherCoboundaryAbstractDefs (OT : OrdinaryTheory lzero)
{n} (⊙fin-skel : ⊙FinSkeleton (S (S n))) where
open OrdinaryTheory OT
open import cohomology.Bouquet OT
private
⊙skel = ⊙FinSkeleton-realize ⊙fin-skel
fin-skel = ⊙FinSkeleton.skel ⊙fin-skel
I = AttachedFinSkeleton.numCells fin-skel
skel = ⊙Skeleton.skel ⊙skel
dec = ⊙FinSkeleton-has-cells-with-dec-eq ⊙fin-skel
⊙fin-skel₋₁ = ⊙fcw-init ⊙fin-skel
⊙skel₋₁ = ⊙FinSkeleton-realize ⊙fin-skel₋₁
fin-skel₋₁ = ⊙FinSkeleton.skel ⊙fin-skel₋₁
I₋₁ = AttachedFinSkeleton.numCells fin-skel₋₁
skel₋₁ = ⊙Skeleton.skel ⊙skel₋₁
dec₋₁ = ⊙FinSkeleton-has-cells-with-dec-eq ⊙fin-skel₋₁
open import cw.cohomology.WedgeOfCells OT
open import cw.cohomology.reconstructed.HigherCoboundary OT ⊙skel
⊙function₀ : ⊙FinBouquet I (S (S n)) ⊙→ ⊙Susp (⊙FinBouquet I₋₁ (S n))
⊙function₀ = ⊙Susp-fmap (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ skel₋₁))
⊙∘ ⊙cw-∂-before-Susp
⊙∘ ⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ skel)
function₁ : Fin I → Fin I₋₁ → Sphere-endo (S n)
function₁ <I <I₋₁ = bwproj Fin-has-dec-eq <I₋₁
∘ <– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁)
∘ cfcod
∘ attaching-last skel <I
abstract
⊙function₀' : ⊙FinBouquet I (S (S n)) ⊙→ ⊙Susp (⊙FinBouquet I₋₁ (S n))
⊙function₀' = ⊙function₀
⊙function₀'-β : ⊙function₀' == ⊙function₀
⊙function₀'-β = idp
function₁' : Fin I → Fin I₋₁ → Sphere-endo (S n)
function₁' = function₁
function₁'-β : ∀ <I <I₋₁ → function₁' <I <I₋₁ == function₁ <I <I₋₁
function₁'-β _ _ = idp
mega-reduction : ∀ <I <I₋₁ →
Susp-fmap (fwproj <I₋₁) ∘ fst ⊙function₀' ∘ fwin <I
∼ Susp-fmap (function₁' <I <I₋₁)
mega-reduction <I <I₋₁ = Susp-elim idp idp λ x → ↓-='-in' $ ! $
ap (Susp-fmap (fwproj <I₋₁) ∘ fst ⊙function₀ ∘ fwin <I) (merid x)
=⟨ ap-∘
( Susp-fmap (fwproj <I₋₁)
∘ Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁))
∘ cw-∂-before-Susp)
(Bouquet-to-Xₙ/Xₙ₋₁ skel ∘ fwin <I)
(merid x) ⟩
ap ( Susp-fmap (fwproj <I₋₁)
∘ Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁))
∘ cw-∂-before-Susp)
(ap (Bouquet-to-Xₙ/Xₙ₋₁ skel ∘ fwin <I) (merid x))
=⟨ ap (ap ( Susp-fmap (fwproj <I₋₁)
∘ Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁))
∘ cw-∂-before-Susp))
(Bouquet-to-Xₙ/Xₙ₋₁-in-merid-β skel <I x) ⟩
ap ( Susp-fmap (fwproj <I₋₁)
∘ Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁))
∘ cw-∂-before-Susp)
(cfglue (attaching-last skel <I x) ∙' ap cfcod (spoke <I x))
=⟨ ap-∘
( Susp-fmap (fwproj <I₋₁)
∘ Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁)))
cw-∂-before-Susp
(cfglue (attaching-last skel <I x) ∙' ap cfcod (spoke <I x)) ⟩
ap ( Susp-fmap (fwproj <I₋₁)
∘ Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁)))
(ap cw-∂-before-Susp
(cfglue (attaching-last skel <I x) ∙' ap cfcod (spoke <I x)))
=⟨ ap (ap ( Susp-fmap (fwproj <I₋₁)
∘ Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁))))
( ap-∙' cw-∂-before-Susp (cfglue (attaching-last skel <I x)) (ap cfcod (spoke <I x))
∙ ap2 _∙'_
(cw-∂-before-Susp-glue-β (attaching-last skel <I x))
( ∘-ap cw-∂-before-Susp cfcod (spoke <I x)
∙ ap-cst south (spoke <I x))) ⟩
ap ( Susp-fmap (fwproj <I₋₁)
∘ Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁)))
(merid (cfcod (attaching-last skel <I x)))
=⟨ ap-∘
(Susp-fmap (fwproj <I₋₁))
(Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁)))
(merid (cfcod (attaching-last skel <I x))) ⟩
ap (Susp-fmap (fwproj <I₋₁))
(ap (Susp-fmap (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁)))
(merid (cfcod (attaching-last skel <I x))))
=⟨ ap
(ap (Susp-fmap (fwproj <I₋₁)))
(SuspFmap.merid-β
(<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁))
(cfcod (attaching-last skel <I x))) ⟩
ap (Susp-fmap (fwproj <I₋₁))
(merid (<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁) (cfcod (attaching-last skel <I x))))
=⟨ SuspFmap.merid-β (fwproj <I₋₁)
(<– (Bouquet-equiv-Xₙ/Xₙ₋₁ skel₋₁) (cfcod (attaching-last skel <I x))) ⟩
merid (function₁ <I <I₋₁ x)
=⟨ ! $ SuspFmap.merid-β (function₁ <I <I₋₁) x ⟩
ap (Susp-fmap (function₁ <I <I₋₁)) (merid x)
=∎
|
{
"alphanum_fraction": 0.5790008123,
"avg_line_length": 38.7716535433,
"ext": "agda",
"hexsha": "c6c02d372b07c2335c14264c46611f96aab231ad",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/cochainequiv/HigherCoboundaryAbstractDefs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/cochainequiv/HigherCoboundaryAbstractDefs.agda",
"max_line_length": 96,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/cochainequiv/HigherCoboundaryAbstractDefs.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2104,
"size": 4924
}
|
module Bin-embedding where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym; cong)
open Eq.≡-Reasoning
open import Data.Nat using (ℕ; zero; suc; _+_; _*_)
open import Data.Nat.Properties using (+-identityʳ; +-suc; +-comm; +-assoc)
open import Isomorphism using (_≲_)
-- 2進数の表現
data Bin : Set where
⟨⟩ : Bin
_O : Bin → Bin
_I : Bin → Bin
-- 2進数のインクリメント
inc : Bin → Bin
inc ⟨⟩ = ⟨⟩ I
inc (b O) = b I
inc (b I) = inc b O
-- 自然数から2進数への変換
to : ℕ → Bin
to zero = ⟨⟩ O
to (suc n) = inc (to n)
-- 2進数から自然数への変換
from : Bin → ℕ
from ⟨⟩ = zero
from (b O) = 2 * (from b)
from (b I) = 2 * (from b) + 1
2*n≡n+n : ∀ (n : ℕ) → 2 * n ≡ n + n
2*n≡n+n n rewrite +-identityʳ n = refl
+-suc-suc : ∀ (m n : ℕ) → (suc m) + (suc n) ≡ suc (suc (m + n))
+-suc-suc m n rewrite +-suc (suc m) n | +-assoc 1 m n = refl
from∘inc≡suc∘from : ∀ (b : Bin) → from (inc b) ≡ suc (from b)
from∘inc≡suc∘from ⟨⟩ = refl
from∘inc≡suc∘from (b O) rewrite +-suc (from (b O)) zero = cong suc (+-identityʳ (from (b O)))
from∘inc≡suc∘from (b I) rewrite from∘inc≡suc∘from b | 2*n≡n+n (suc (from b)) | +-suc-suc (from b) (from b) | sym (2*n≡n+n (from b)) | +-comm 1 (2 * (from b)) = refl
from∘to : ∀ (n : ℕ) → from (to n) ≡ n
from∘to zero = refl
from∘to (suc n) rewrite from∘inc≡suc∘from (to n) = cong suc (from∘to n)
Bin-embedding : ℕ ≲ Bin
Bin-embedding =
record
{ to = to
; from = from
; from∘to = from∘to
}
|
{
"alphanum_fraction": 0.5734072022,
"avg_line_length": 25.7857142857,
"ext": "agda",
"hexsha": "e5195f878bbe794f7eb5c069f95b0ddc63684adf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/isomorphism/Bin-embedding.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/isomorphism/Bin-embedding.agda",
"max_line_length": 164,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/isomorphism/Bin-embedding.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 664,
"size": 1444
}
|
{-# OPTIONS --cubical-compatible --rewriting --confluence-check #-}
postulate
_↦_ : ∀ {i} {A : Set i} → A → A → Set i
idr : ∀ {i} {A : Set i} {a : A} → a ↦ a
{-# BUILTIN REWRITE _↦_ #-}
data _==_ {i} {A : Set i} (a : A) : A → Set i where
idp : a == a
PathOver : ∀ {i j} {A : Set i} (B : A → Set j)
{x y : A} (p : x == y) (u : B x) (v : B y) → Set j
PathOver B idp u v = (u == v)
syntax PathOver B p u v =
u == v [ B ↓ p ]
postulate
PathOver-rewr : ∀ {i j} {A : Set i} {B : Set j} {x y : A} (p : x == y) (u v : B) →
(PathOver (λ _ → B) p u v) ↦ (u == v)
{-# REWRITE PathOver-rewr #-}
ap : ∀ {i j} {A : Set i} {B : A → Set j} (f : (a : A) → B a) {x y : A}
→ (p : x == y) → PathOver B p (f x) (f y)
ap f idp = idp
postulate
Circle : Set
base : Circle
loop : base == base
module _ {i} {P : Circle → Set i} (base* : P base) (loop* : base* == base* [ P ↓ loop ])
where
postulate
Circle-elim : (x : Circle) → P x
Circle-base-β : Circle-elim base ↦ base*
{-# REWRITE Circle-base-β #-}
Circle-loop-β : ap Circle-elim loop ↦ loop*
{-# REWRITE Circle-loop-β #-}
idCircle : Circle → Circle
idCircle = Circle-elim base loop
|
{
"alphanum_fraction": 0.5042735043,
"avg_line_length": 26.5909090909,
"ext": "agda",
"hexsha": "127157f5a25a76e5b32f805b644a32aada01ef20",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue1663.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue1663.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue1663.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 480,
"size": 1170
}
|
kk : ∀ {ℓ} → Set ℓ
kk = {!∀ B → B!}
|
{
"alphanum_fraction": 0.3055555556,
"avg_line_length": 12,
"ext": "agda",
"hexsha": "43460983d822c3bf8c912e334980fc67cad77b60",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue3428.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue3428.agda",
"max_line_length": 18,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue3428.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 22,
"size": 36
}
|
module plfa.part1.Connectives where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning
open import Data.Nat using (ℕ)
open import Function using (_∘_)
open import plfa.part1.Isomorphism using (_≃_; _≲_; extensionality)
open plfa.part1.Isomorphism.≃-Reasoning
data _×_ (A B : Set) : Set where
⟨_,_⟩ :
A
→ B
-----
→ A × B
proj₁ : ∀ {A B : Set}
→ A × B
-----
→ A
proj₁ ⟨ x , y ⟩ = x
proj₂ : ∀ {A B : Set}
→ A × B
-----
→ B
proj₂ ⟨ x , y ⟩ = y
η-× : ∀ {A B : Set} (w : A × B) → ⟨ proj₁ w , proj₂ w ⟩ ≡ w
η-× ⟨ x , y ⟩ = refl
infixr 2 _×_
record _×′_ (A B : Set) : Set where
constructor ⟨_,_⟩′
field
proj₁′ : A
proj₂′ : B
open _×′_
η-×′ : ∀ {A B : Set} (w : A ×′ B) → ⟨ proj₁′ w , proj₂′ w ⟩′ ≡ w
η-×′ w = refl
data Bool : Set where
true : Bool
false : Bool
data Tri : Set where
aa : Tri
bb : Tri
cc : Tri
×-comm : ∀ {A B : Set} → A × B ≃ B × A
×-comm =
record
{ to = λ{ ⟨ x , y ⟩ → ⟨ y , x ⟩ }
; from = λ{ ⟨ y , x ⟩ → ⟨ x , y ⟩ }
; from∘to = λ{ ⟨ x , y ⟩ → refl }
; to∘from = λ{ ⟨ y , x ⟩ → refl }
}
×-assoc : ∀ {A B C : Set} → (A × B) × C ≃ A × (B × C)
×-assoc =
record
{ to = λ{ ⟨ ⟨ x , y ⟩ , z ⟩ → ⟨ x , ⟨ y , z ⟩ ⟩ }
; from = λ{ ⟨ x , ⟨ y , z ⟩ ⟩ → ⟨ ⟨ x , y ⟩ , z ⟩ }
; from∘to = λ{ ⟨ ⟨ x , y ⟩ , z ⟩ → refl }
; to∘from = λ{ ⟨ x , ⟨ y , z ⟩ ⟩ → refl }
}
data ⊤ : Set where
tt :
--
⊤
η-⊤ : ∀ (w : ⊤) → tt ≡ w
η-⊤ tt = refl
record ⊤′ : Set where
constructor tt′
η-⊤′ : ∀ (w : ⊤′) → tt′ ≡ w
η-⊤′ w = refl
truth′ : ⊤′
truth′ = _
⊤-identityˡ : ∀ {A : Set} → ⊤ × A ≃ A
⊤-identityˡ =
record
{ to = λ{ ⟨ tt , x ⟩ → x }
; from = λ{ x → ⟨ tt , x ⟩ }
; from∘to = λ{ ⟨ tt , x ⟩ → refl }
; to∘from = λ{ x → refl }
}
⊤-identityʳ : ∀ {A : Set} → (A × ⊤) ≃ A
⊤-identityʳ {A} =
≃-begin
(A × ⊤)
≃⟨ ×-comm ⟩
(⊤ × A)
≃⟨ ⊤-identityˡ ⟩
A
≃-∎
data _⊎_ (A B : Set) : Set where
inj₁ :
A
-----
→ A ⊎ B
inj₂ :
B
-----
→ A ⊎ B
case-⊎ : ∀ {A B C : Set}
→ (A → C)
→ (B → C)
→ A ⊎ B
-----------
→ C
case-⊎ f g (inj₁ x) = f x
case-⊎ f g (inj₂ y) = g y
η-⊎ : ∀ {A B : Set} (w : A ⊎ B) → case-⊎ inj₁ inj₂ w ≡ w
η-⊎ (inj₁ x) = refl
η-⊎ (inj₂ y) = refl
uniq-⊎ : ∀ {A B C : Set} (h : A ⊎ B → C) (w : A ⊎ B) →
case-⊎ (h ∘ inj₁) (h ∘ inj₂) w ≡ h w
uniq-⊎ h (inj₁ x) = refl
uniq-⊎ h (inj₂ y) = refl
infixr 1 _⊎_
⊎-comm : ∀ {A B : Set} → A ⊎ B ≃ B ⊎ A
⊎-comm = record {
to = λ { (inj₁ x) → inj₂ x ; (inj₂ x) → inj₁ x };
from = λ { (inj₁ x) → inj₂ x ; (inj₂ x) → inj₁ x};
from∘to = λ { (inj₁ x) → refl ; (inj₂ x) → refl} ;
to∘from = λ { (inj₁ x) → refl ; (inj₂ x) → refl} }
⊎-assoc : ∀ {A B C : Set} → (A ⊎ B) ⊎ C ≃ A ⊎ (B ⊎ C)
⊎-assoc = record {
to = λ { (inj₁ (inj₁ x)) → inj₁ x ;
(inj₁ (inj₂ x)) → inj₂ (inj₁ x) ;
(inj₂ x) → inj₂ (inj₂ x)} ;
from = λ { (inj₁ x) → inj₁ (inj₁ x) ;
(inj₂ (inj₁ x)) → inj₁ (inj₂ x) ;
(inj₂ (inj₂ x)) → inj₂ x} ;
from∘to = λ { (inj₁ (inj₁ x)) → refl ;
(inj₁ (inj₂ x)) → refl ;
(inj₂ x) → refl} ;
to∘from = λ { (inj₁ x) → refl ;
(inj₂ (inj₁ x)) → refl;
(inj₂ (inj₂ x)) → refl}
}
data ⊥ : Set where
⊥-elim : ∀ {A : Set}
→ ⊥
--
→ A
⊥-elim ()
uniq-⊥ : ∀ {C : Set} (h : ⊥ → C) (w : ⊥) → ⊥-elim w ≡ h w
uniq-⊥ h ()
⊥-count : ⊥ → ℕ
⊥-count ()
→-elim : ∀ {A B : Set}
→ (A → B)
→ A
-------
→ B
→-elim L M = L M
η-→ : ∀ {A B : Set} (f : A → B) → (λ (x : A) → f x) ≡ f
η-→ f = refl
currying : ∀ {A B C : Set} → (A → B → C) ≃ (A × B → C)
currying =
record
{ to = λ{ f → λ{ ⟨ x , y ⟩ → f x y }}
; from = λ{ g → λ{ x → λ{ y → g ⟨ x , y ⟩ }}}
; from∘to = λ{ f → refl }
; to∘from = λ{ g → extensionality λ{ ⟨ x , y ⟩ → refl }}
}
→-distrib-⊎ : ∀ {A B C : Set} → (A ⊎ B → C) ≃ ((A → C) × (B → C))
→-distrib-⊎ =
record
{ to = λ{ f → ⟨ f ∘ inj₁ , f ∘ inj₂ ⟩ }
; from = λ{ ⟨ g , h ⟩ → λ{ (inj₁ x) → g x ; (inj₂ y) → h y } }
; from∘to = λ{ f → extensionality λ{ (inj₁ x) → refl ; (inj₂ y) → refl } }
; to∘from = λ{ ⟨ g , h ⟩ → refl }
}
→-distrib-× : ∀ {A B C : Set} → (A → B × C) ≃ (A → B) × (A → C)
→-distrib-× =
record
{ to = λ{ f → ⟨ proj₁ ∘ f , proj₂ ∘ f ⟩ }
; from = λ{ ⟨ g , h ⟩ → λ x → ⟨ g x , h x ⟩ }
; from∘to = λ{ f → extensionality λ{ x → η-× (f x) } }
; to∘from = λ{ ⟨ g , h ⟩ → refl }
}
×-distrib-⊎ : ∀ {A B C : Set} → (A ⊎ B) × C ≃ (A × C) ⊎ (B × C)
×-distrib-⊎ =
record
{ to = λ{ ⟨ inj₁ x , z ⟩ → (inj₁ ⟨ x , z ⟩)
; ⟨ inj₂ y , z ⟩ → (inj₂ ⟨ y , z ⟩)
}
; from = λ{ (inj₁ ⟨ x , z ⟩) → ⟨ inj₁ x , z ⟩
; (inj₂ ⟨ y , z ⟩) → ⟨ inj₂ y , z ⟩
}
; from∘to = λ{ ⟨ inj₁ x , z ⟩ → refl
; ⟨ inj₂ y , z ⟩ → refl
}
; to∘from = λ{ (inj₁ ⟨ x , z ⟩) → refl
; (inj₂ ⟨ y , z ⟩) → refl
}
}
⊎-distrib-× : ∀ {A B C : Set} → (A × B) ⊎ C ≲ (A ⊎ C) × (B ⊎ C)
⊎-distrib-× =
record
{ to = λ{ (inj₁ ⟨ x , y ⟩) → ⟨ inj₁ x , inj₁ y ⟩
; (inj₂ z) → ⟨ inj₂ z , inj₂ z ⟩
}
; from = λ{ ⟨ inj₁ x , inj₁ y ⟩ → (inj₁ ⟨ x , y ⟩)
; ⟨ inj₁ x , inj₂ z ⟩ → (inj₂ z)
; ⟨ inj₂ z , _ ⟩ → (inj₂ z)
}
; from∘to = λ{ (inj₁ ⟨ x , y ⟩) → refl
; (inj₂ z) → refl
}
}
⊎-weak-× : ∀ {A B C : Set} → (A ⊎ B) × C → A ⊎ (B × C)
⊎-weak-× ⟨ inj₁ x , y ⟩ = inj₁ x
⊎-weak-× ⟨ inj₂ x , y ⟩ = inj₂ ⟨ x , y ⟩
⊎×-implies-×⊎ : ∀ {A B C D : Set} → (A × B) ⊎ (C × D) → (A ⊎ C) × (B ⊎ D)
⊎×-implies-×⊎ (inj₁ ⟨ x , y ⟩) = ⟨ inj₁ x , inj₁ y ⟩
⊎×-implies-×⊎ (inj₂ ⟨ x , y ⟩) = ⟨ (inj₂ x) , (inj₂ y) ⟩
|
{
"alphanum_fraction": 0.3557519228,
"avg_line_length": 23.7782101167,
"ext": "agda",
"hexsha": "8f6929428e14d0edb8319c703851a14bcb95c854",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "275ecc582b3a6a1da1af387251c6b4d74d9a5203",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sym-cereal/proofs",
"max_forks_repo_path": "plfa/part1/Connectives.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "275ecc582b3a6a1da1af387251c6b4d74d9a5203",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "sym-cereal/proofs",
"max_issues_repo_path": "plfa/part1/Connectives.agda",
"max_line_length": 78,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "275ecc582b3a6a1da1af387251c6b4d74d9a5203",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UnsoundWitch/proofs",
"max_stars_repo_path": "plfa/part1/Connectives.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-18T10:58:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-03T03:29:40.000Z",
"num_tokens": 2869,
"size": 6111
}
|
module _ where
open import Agda.Builtin.List
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
variable
a b : Set
{-# FOREIGN AGDA2HS
import Prelude hiding (map, sum)
#-}
data Exp (v : Set) : Set where
Plus : Exp v → Exp v → Exp v
Int : Nat → Exp v
Var : v → Exp v
{-# COMPILE AGDA2HS Exp #-}
eval : (a → Nat) → Exp a → Nat
eval env (Plus a b) = eval env a + eval env b
eval env (Int n) = n
eval env (Var x) = env x
{-# COMPILE AGDA2HS eval #-}
sum : List Nat → Nat
sum [] = 0
sum (x ∷ xs) = x + sum xs
{-# COMPILE AGDA2HS sum #-}
{-# FOREIGN AGDA2HS -- comment #-}
append : List a → List a → List a
append [] ys = ys
append (x ∷ xs) ys = x ∷ append xs ys
{-# COMPILE AGDA2HS append #-}
map : (a → b) → List a → List b
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
{-# COMPILE AGDA2HS map #-}
assoc : (a b c : Nat) → a + (b + c) ≡ (a + b) + c
assoc zero b c = refl
assoc (suc a) b c rewrite assoc a b c = refl
thm : ∀ xs ys → sum (append xs ys) ≡ sum xs + sum ys
thm [] ys = refl
thm (x ∷ xs) ys rewrite thm xs ys | assoc x (sum xs) (sum ys) = refl
|
{
"alphanum_fraction": 0.5710431655,
"avg_line_length": 19.5087719298,
"ext": "agda",
"hexsha": "57d613fced6e5a76a86bb1cdd06767a73fc30c42",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0f8b0b8a17ecad9e9be7ef5cae564187787df31d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/agda2hs",
"max_forks_repo_path": "Test.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0f8b0b8a17ecad9e9be7ef5cae564187787df31d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/agda2hs",
"max_issues_repo_path": "Test.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0f8b0b8a17ecad9e9be7ef5cae564187787df31d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/agda2hs",
"max_stars_repo_path": "Test.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 402,
"size": 1112
}
|
module Functors.Fin where
open import Library
open import Categories.Sets
open import Categories.Setoids
open import Categories
open import Categories.Initial
open import Categories.CoProducts
open import Functors
open import Isomorphism
open import Functors.FullyFaithful
open Cat
open Fun
open Iso
Nats : Cat {lzero}{lzero}
Nats = record{
Obj = ℕ;
Hom = λ m n → Fin m → Fin n;
iden = id;
comp = λ f g → f ∘ g;
idl = refl;
idr = refl;
ass = refl}
-- initial object
initN : Init Nats zero
initN = record {
i = λ ();
law = ext λ ()}
-- coproducts
extend : ∀ {m n} -> Fin m -> Fin (m + n)
extend zero = zero
extend (suc i) = suc (extend i)
lift : ∀ m {n} -> Fin n -> Fin (m + n)
lift zero i = i
lift (suc m) i = suc (lift m i)
case : ∀ (m : ℕ){n : ℕ}{X : Set} →
(Fin m → X) → (Fin n → X) → Fin (m + n) → X
case zero f g i = g i
case (suc m) f g zero = f zero
case (suc m) f g (suc i) = case m (f ∘ suc) g i
lem1 : ∀ A {B C}(f : Fin A → C) (g : Fin B → C)(i : Fin A) →
case A f g (extend i) ≅ f i
lem1 zero f g ()
lem1 (suc A) f g zero = refl
lem1 (suc A) f g (suc i) = lem1 A (f ∘ suc) g i
lem2 : ∀ A {B C} (f : Fin A → C) (g : Fin B → C)(i : Fin B) →
case A f g (lift A i) ≅ g i
lem2 zero f g zero = refl
lem2 zero f g (suc i) = refl
lem2 (suc A) f g i = lem2 A (f ∘ suc) g i
lem3 : ∀ A {B C}(f : Fin A → C) (g : Fin B → C)
(h : Fin (A + B) → C) →
(λ x → h (extend {A} x)) ≅ f →
(λ x → h (lift A x)) ≅ g → ∀ i → h i ≅ case A f g i
lem3 zero f g h p q i = fcong i q
lem3 (suc A) f g h p q zero = fcong zero p
lem3 (suc A) f g h p q (suc i) =
lem3 A (f ∘ suc) g (h ∘ suc) (ext (λ i → fcong (suc i) p)) q i
coprod : CoProd Nats
coprod = record
{ _+_ = _+_
; inl = extend
; inr = λ{m} → lift m
; [_,_] = λ{m} → case m
; law1 = λ{m} f g → ext (lem1 m f g)
; law2 = λ{m} f g → ext (lem2 m f g)
; law3 = λ{m} f g h p q → ext (lem3 m f g h p q)
}
--
FinF : Fun Nats Sets
FinF = record {
OMap = Fin;
HMap = id;
fid = refl;
fcomp = refl}
FinFoid : Fun Nats Setoids
FinFoid = record {
OMap = λ n → record {
set = Fin n ;
eq = λ i j → i ≅ j;
ref = refl;
sym' = sym;
trn = trans};
HMap = λ f → record {
fun = f; feq = cong f};
fid = SetoidFunEq refl (iext λ _ → iext λ _ → ext congid);
fcomp = λ{_ _ _ f g} →
SetoidFunEq refl (iext λ _ → iext λ _ → ext (congcomp f g))}
FinFF : FullyFaithful FinF
FinFF X Y = record {
fun = id;
inv = id;
law1 = λ _ → refl;
law2 = λ _ → refl}
open import Data.Bool
feq : forall {n} -> Fin n -> Fin n -> Bool
feq zero zero = true
feq zero (suc j) = false
feq (suc i) zero = false
feq (suc i) (suc j) = true
|
{
"alphanum_fraction": 0.5338455909,
"avg_line_length": 22.9663865546,
"ext": "agda",
"hexsha": "61aa801d4ff3cf17d681598be1fec5c829dae44a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "Functors/Fin.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "Functors/Fin.agda",
"max_line_length": 66,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "Functors/Fin.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 1144,
"size": 2733
}
|
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.SumFin where
open import Cubical.Data.SumFin.Base public
|
{
"alphanum_fraction": 0.7477477477,
"avg_line_length": 22.2,
"ext": "agda",
"hexsha": "bc4dba925cd21844e4da8779c556bed1091163be",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Data/SumFin.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Data/SumFin.agda",
"max_line_length": 43,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Data/SumFin.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 27,
"size": 111
}
|
-- Andreas, 2016-10-14, issue #2260 testcase by Nisse
-- {-# OPTIONS -v tc.meta:40 #-}
data D : Set → Set₁ where
d : (A : Set) → D A
postulate
A : Set
f : (A : Set) → D A → D A
B : Set₁
B = Set
where
abstract
A′ : Set
A′ = A
x : D A′
x = f _ (d A′)
-- WAS: internal error
-- should check
|
{
"alphanum_fraction": 0.5173501577,
"avg_line_length": 12.68,
"ext": "agda",
"hexsha": "789b4fe2f594064737d3fecb7440809ae20f4d9e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2260.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2260.agda",
"max_line_length": 53,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2260.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 129,
"size": 317
}
|
------------------------------------------------------------------------
-- A comparison of the two definitions of bisimilarity
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Bisimilarity.Comparison where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (Unit)
open import Bijection equality-with-J as Bijection using (_↔_)
open import Equality.Decision-procedures equality-with-J
open import Fin equality-with-J
open import Function-universe equality-with-J hiding (_∘_; id)
open import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import Nat equality-with-J as Nat
open import Surjection equality-with-J using (_↠_)
import Bisimilarity
import Bisimilarity.Classical
import Bisimilarity.Classical.Equational-reasoning-instances
import Bisimilarity.Equational-reasoning-instances
open import Equational-reasoning
import Indexed-container as IC
open import Labelled-transition-system
open import Relation
module _ {ℓ} {lts : LTS ℓ} where
open LTS lts
private
module Cl = Bisimilarity.Classical lts
module Co = Bisimilarity lts
-- Classically bisimilar processes are coinductively bisimilar.
cl⇒co : ∀ {i p q} → p Cl.∼ q → Co.[ i ] p ∼ q
cl⇒co = IC.gfp⊆ν ℓ
-- Coinductively bisimilar processes are classically bisimilar.
co⇒cl : ∀ {p q} → p Co.∼ q → p Cl.∼ q
co⇒cl = IC.ν⊆gfp ℓ
-- The function cl⇒co is a left inverse of co⇒cl (up to pointwise
-- bisimilarity).
cl⇒co∘co⇒cl : ∀ {i p q}
(p∼q : p Co.∼ q) →
Co.[ i ] cl⇒co (co⇒cl p∼q) ≡ p∼q
cl⇒co∘co⇒cl p∼q = IC.gfp⊆ν∘ν⊆gfp ℓ p∼q
-- If there are two processes that are not equal, but bisimilar,
-- then co⇒cl is not a left inverse of cl⇒co.
co⇒cl∘cl⇒co : ∀ {p q} →
p ≢ q → p Co.∼ q →
∃ λ (p∼p : p Cl.∼ p) → co⇒cl (cl⇒co p∼p) ≢ p∼p
co⇒cl∘cl⇒co {p} {q} p≢q p∼q =
reflexive
, (co⇒cl (cl⇒co reflexive) ≡ reflexive ↝⟨ cong (λ R → proj₁ R (p , q)) ⟩
↑ _ (p Co.∼ q) ≡ ↑ _ (p ≡ q) ↝⟨ (λ eq → ≡⇒↝ _ eq $ lift p∼q) ⟩
↑ _ (p ≡ q) ↔⟨ Bijection.↑↔ ⟩
p ≡ q ↝⟨ p≢q ⟩□
⊥ □)
-- The two definitions of bisimilarity are logically equivalent.
classical⇔coinductive : ∀ {p q} → p Cl.∼ q ⇔ p Co.∼ q
classical⇔coinductive = IC.gfp⇔ν ℓ
-- There is a split surjection from the classical definition of
-- bisimilarity to the coinductive one (assuming two kinds of
-- extensionality).
classical↠coinductive :
Extensionality ℓ ℓ →
Co.Extensionality →
∀ {p q} → p Cl.∼ q ↠ p Co.∼ q
classical↠coinductive ext co-ext = IC.gfp↠ν ext ℓ co-ext
-- There is at least one LTS for which there is a split surjection
-- from the coinductive definition of bisimilarity to the classical
-- one.
coinductive↠classical :
∀ {p q} →
Bisimilarity._∼_ empty p q ↠
Bisimilarity.Classical._∼_ empty p q
coinductive↠classical {p = ()}
-- There is an LTS for which coinductive bisimilarity is pointwise
-- propositional (assuming two kinds of extensionality).
coinductive-bisimilarity-is-sometimes-propositional :
Extensionality lzero lzero →
let module Co = Bisimilarity one-loop in
Co.Extensionality → Is-proposition (tt Co.∼ tt)
coinductive-bisimilarity-is-sometimes-propositional ext co-ext ∼₁ ∼₂ =
extensionality ext co-ext (irr ∼₁ ∼₂)
where
open Bisimilarity one-loop
irr : ∀ {i} ∼₁ ∼₂ → [ i ] ∼₁ ≡ ∼₂
irr ∼₁ ∼₂ =
Bisimilarity-of-∼.⟨ ext
, ∼₁
, ∼₂
, (λ _ → refl , refl , irr′ (proj₂ ∼₁ _)
(proj₂ ∼₂ _))
, (λ _ → refl , refl , irr′ (proj₂ ∼₁ _)
(proj₂ ∼₂ _))
⟩
where
irr′ : ∀ {i} ∼₁ ∼₂ → [ i ] ∼₁ ≡′ ∼₂
force (irr′ ∼₁ ∼₂) = irr (force ∼₁) (force ∼₂)
-- However, classical bisimilarity (of any size) is, for the same LTS,
-- not pointwise propositional.
classical-bisimilarity-is-not-propositional :
let module Cl = Bisimilarity.Classical one-loop in
∀ {ℓ} → ¬ Is-proposition (Cl.Bisimilarity′ ℓ (tt , tt))
classical-bisimilarity-is-not-propositional {ℓ} =
Is-proposition (Bisimilarity′ ℓ (tt , tt)) ↝⟨ (λ f → f tt∼tt₁ tt∼tt₂) ⟩
tt∼tt₁ ≡ tt∼tt₂ ↝⟨ cong (λ R → proj₁ R (tt , tt)) ⟩
Unit ≡ (Unit ⊎ Unit) ↝⟨ (λ eq → Fin 1 ↝⟨ inverse Unit↔Fin1 ⟩
Unit ↝⟨ ≡⇒↝ _ eq ⟩
Unit ⊎ Unit ↝⟨ Unit↔Fin1 ⊎-cong Unit↔Fin1 ⟩
Fin 1 ⊎ Fin 1 ↝⟨ Fin⊎Fin↔Fin+ 1 1 ⟩□
Fin 2 □) ⟩
Fin 1 ↔ Fin 2 ↝⟨ _⇔_.to isomorphic-same-size ⟩
1 ≡ 2 ↝⟨ from-⊎ (1 Nat.≟ 2) ⟩□
⊥ □
where
open Bisimilarity.Classical one-loop
tt∼tt₁ : Bisimilarity′ ℓ (tt , tt)
tt∼tt₁ = reflexive-∼′ _
tt∼tt₂ : Bisimilarity′ ℓ (tt , tt)
tt∼tt₂ =
let R , R-is-a-bisimulation , ttRtt =
_⇔_.to (Bisimilarity′↔ _ _) tt∼tt₁ in
_⇔_.from (Bisimilarity′↔ _ _)
( (R ∪ R)
, ×2-preserves-bisimulations R-is-a-bisimulation
, inj₁ ttRtt
)
Unit = ↑ ℓ (tt ≡ tt)
Unit↔Fin1 =
Unit ↔⟨ Bijection.↑↔ ⟩
tt ≡ tt ↝⟨ _⇔_.to contractible⇔↔⊤ (+⇒≡ $ mono₁ 0 ⊤-contractible) ⟩
⊤ ↝⟨ inverse ⊎-right-identity ⟩□
Fin 1 □
-- Thus, assuming two kinds of extensionality, there is in general no
-- split surjection from the coinductive definition of bisimilarity to
-- the classical one (of any size).
¬coinductive↠classical :
Extensionality lzero lzero →
Bisimilarity.Extensionality one-loop →
∀ {ℓ} →
¬ (∀ {p q} → Bisimilarity._∼_ one-loop p q ↠
Bisimilarity.Classical.Bisimilarity′ one-loop ℓ (p , q))
¬coinductive↠classical ext co-ext {ℓ} =
(∀ {p q} → p Co.∼ q ↠ Cl.Bisimilarity′ ℓ (p , q)) ↝⟨ (λ co↠cl → co↠cl {q = _}) ⟩
tt Co.∼ tt ↠ Cl.Bisimilarity′ ℓ (tt , tt) ↝⟨ (λ co↠cl → H-level.respects-surjection co↠cl 1) ⟩
(Is-proposition (tt Co.∼ tt) →
Is-proposition (Cl.Bisimilarity′ ℓ (tt , tt))) ↝⟨ (_$ coinductive-bisimilarity-is-sometimes-propositional ext co-ext) ⟩
Is-proposition (Cl.Bisimilarity′ ℓ (tt , tt)) ↝⟨ classical-bisimilarity-is-not-propositional ⟩□
⊥ □
where
module Cl = Bisimilarity.Classical one-loop
module Co = Bisimilarity one-loop
-- Note also that coinductive bisimilarity is not always
-- propositional.
coinductive-bisimilarity-is-not-propositional :
let open Bisimilarity two-bisimilar-processes in
¬ (∀ {p q} → Is-proposition (p ∼ q))
coinductive-bisimilarity-is-not-propositional =
(∀ {p q} → Is-proposition (p ∼ q)) ↝⟨ (λ is-prop → is-prop {p = true} {q = true}) ⟩
Is-proposition (true ∼ true) ↝⟨ (λ irr → irr _ _) ⟩
proof true true true ≡ proof false true true ↝⟨ cong (λ p → proj₁ (left-to-right {p = true} {q = true} p {p′ = true} _)) ⟩
true ≡ false ↝⟨ Bool.true≢false ⟩□
⊥ □
where
open Bisimilarity two-bisimilar-processes
open import Indexed-container
mutual
proof : Bool → ∀ b₁ b₂ {i} → [ i ] b₁ ∼ b₂
proof b b₁ b₂ =
⟨_,_⟩ {p = b₁} {q = b₂}
(λ _ → b , _ , proof′ b _ _)
(λ _ → b , _ , proof′ b _ _)
proof′ : Bool → ∀ b₁ b₂ {i} → [ i ] b₁ ∼′ b₂
force (proof′ b b₁ b₂) = proof b b₁ b₂
-- In fact, for every type A there is a pointwise split surjection
-- from a certain instance of bisimilarity (of any size) to equality
-- on A.
bisimilarity↠equality :
∀ {a} {A : Type a} →
let open Bisimilarity (bisimilarity⇔equality A) in
∀ {i} {p q : A} → ([ i ] p ∼ q) ↠ p ≡ q
bisimilarity↠equality {A = A} {i} = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
where
open Bisimilarity (bisimilarity⇔equality A)
to : ∀ {p q} → [ i ] p ∼ q → p ≡ q
to p∼q with left-to-right p∼q (refl , refl)
... | _ , (refl , _) , _ = refl
from : ∀ {p q} → p ≡ q → [ i ] p ∼ q
from refl = reflexive
to∘from : ∀ {p q} (p≡q : p ≡ q) → to (from p≡q) ≡ p≡q
to∘from refl = refl
|
{
"alphanum_fraction": 0.5435986159,
"avg_line_length": 35.6790123457,
"ext": "agda",
"hexsha": "935a6eaac36f55cb6918de3b4cacfbe05b1a9703",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Bisimilarity/Comparison.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/up-to",
"max_issues_repo_path": "src/Bisimilarity/Comparison.agda",
"max_line_length": 125,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Bisimilarity/Comparison.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3042,
"size": 8670
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- Skew closed structure on a category
module SOAS.Construction.Skew.SkewClosed {o ℓ e} (C : Category o ℓ e) where
private
module C = Category C
open C
variable
A B X X′ Y Y′ Z Z′ U ℐ : Obj
f g : A ⇒ B
open Commutation C
open import Level
open import Data.Product using (Σ; _,_)
open import Function.Equality using (_⟶_)
open import Function.Inverse using (_InverseOf_; Inverse)
open import Categories.Category.Product
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Bifunctor
open import Categories.Functor.Construction.Constant
open import Categories.NaturalTransformation
open import Categories.NaturalTransformation.NaturalIsomorphism
open import Categories.NaturalTransformation.Dinatural
record SkewClosed : Set (levelOfTerm C) where
field
-- internal hom
[-,-] : Bifunctor C.op C C
unit : Obj
[_,-] : Obj → Functor C C
[_,-] = appˡ [-,-]
[-,_] : Obj → Functor C.op C
[-,_] = appʳ [-,-]
module [-,-] = Functor [-,-]
[_,_]₀ : Obj → Obj → Obj
[ X , Y ]₀ = [-,-].F₀ (X , Y)
[_,_]₁ : A ⇒ B → X ⇒ Y → [ B , X ]₀ ⇒ [ A , Y ]₀
[ f , g ]₁ = [-,-].F₁ (f , g)
field
-- i
identity : NaturalTransformation [ unit ,-] idF
-- j
diagonal : Extranaturalʳ unit [-,-]
module identity = NaturalTransformation identity
module diagonal = DinaturalTransformation diagonal
[[X,-],[X,-]] : Obj → Bifunctor C.op C C
[[X,-],[X,-]] X = [-,-] ∘F (Functor.op [ X ,-] ⁂ [ X ,-])
[[-,Y],[-,Z]] : Obj → Obj → Bifunctor C C.op C
[[-,Y],[-,Z]] Y Z = [-,-] ∘F ((Functor.op [-, Y ]) ⁂ [-, Z ])
-- L needs to be natural in Y and Z.
-- it is better to spell out the conditions and then prove that indeed
-- the naturality conditions hold.
field
L : ∀ X Y Z → [ Y , Z ]₀ ⇒ [ [ X , Y ]₀ , [ X , Z ]₀ ]₀
L-commute : [ [ Y , Z ]₀ ⇒ [ [ X , Y′ ]₀ , [ X , Z′ ]₀ ]₀ ]⟨
[ f , g ]₁ ⇒⟨ [ Y′ , Z′ ]₀ ⟩
L X Y′ Z′
≈ L X Y Z ⇒⟨ [ [ X , Y ]₀ , [ X , Z ]₀ ]₀ ⟩
[ [ C.id , f ]₁ , [ C.id , g ]₁ ]₁
⟩
L-natural : NaturalTransformation [-,-] ([[X,-],[X,-]] X)
L-natural {X} = ntHelper record
{ η = λ where
(Y , Z) → L X Y Z
; commute = λ _ → L-commute
}
module L-natural {X} = NaturalTransformation (L-natural {X})
-- other required diagrams
field
Lj≈j : [ unit ⇒ [ [ X , Y ]₀ , [ X , Y ]₀ ]₀ ]⟨
diagonal.α Y ⇒⟨ [ Y , Y ]₀ ⟩
L X Y Y
≈ diagonal.α [ X , Y ]₀
⟩
ijL≈id : [ [ X , Y ]₀ ⇒ [ X , Y ]₀ ]⟨
L X X Y ⇒⟨ [ [ X , X ]₀ , [ X , Y ]₀ ]₀ ⟩
[ diagonal.α X , C.id ]₁ ⇒⟨ [ unit , [ X , Y ]₀ ]₀ ⟩
identity.η [ X , Y ]₀
≈ C.id
⟩
iL≈i : [ [ Y , Z ]₀ ⇒ [ [ unit , Y ]₀ , Z ]₀ ]⟨
L unit Y Z ⇒⟨ [ [ unit , Y ]₀ , [ unit , Z ]₀ ]₀ ⟩
[ C.id , identity.η Z ]₁
≈ [ identity.η Y , C.id ]₁
⟩
ij≈id : [ unit ⇒ unit ]⟨
diagonal.α unit ⇒⟨ [ unit , unit ]₀ ⟩
identity.η unit
≈ C.id
⟩
pentagon : [ [ U , ℐ ]₀ ⇒ [ [ Y , U ]₀ , [ [ X , Y ]₀ , [ X , ℐ ]₀ ]₀ ]₀ ]⟨
L X U ℐ ⇒⟨ [ [ X , U ]₀ , [ X , ℐ ]₀ ]₀ ⟩
L [ X , Y ]₀ [ X , U ]₀ [ X , ℐ ]₀ ⇒⟨ [ [ [ X , Y ]₀ , [ X , U ]₀ ]₀ , [ [ X , Y ]₀ , [ X , ℐ ]₀ ]₀ ]₀ ⟩
[ L X Y U , C.id ]₁
≈ L Y U ℐ ⇒⟨ [ [ Y , U ]₀ , [ Y , ℐ ]₀ ]₀ ⟩
[ C.id , L X Y ℐ ]₁
⟩
|
{
"alphanum_fraction": 0.4421333333,
"avg_line_length": 31.7796610169,
"ext": "agda",
"hexsha": "2a610c163a6db9558df5fec79450987fb58fedd4",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "SOAS/Construction/Skew/SkewClosed.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "SOAS/Construction/Skew/SkewClosed.agda",
"max_line_length": 121,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "SOAS/Construction/Skew/SkewClosed.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 1328,
"size": 3750
}
|
module Categories.Setoids where
open import Library
open import Categories
record Setoid {a b} : Set (lsuc (a ⊔ b)) where
field set : Set a
eq : set → set → Set b
ref : {s : set} → eq s s
sym' : {s s' : set} → eq s s' → eq s' s
trn : {s s' s'' : set} →
eq s s' → eq s' s'' → eq s s''
open Setoid
record SetoidFun (S S' : Setoid) : Set where
constructor setoidfun
field fun : set S → set S'
feq : {s s' : set S} →
eq S s s' → eq S' (fun s) (fun s')
open SetoidFun
SetoidFunEq : {S S' : Setoid}{f g : SetoidFun S S'} →
fun f ≅ fun g →
(λ{s}{s'}(p : eq S s s') → feq f p)
≅
(λ{s}{s'}(p : eq S s s') → feq g p) →
f ≅ g
SetoidFunEq {f = setoidfun fun feq} {setoidfun .fun .feq} refl refl = refl
idFun : {S : Setoid} → SetoidFun S S
idFun = record {fun = id; feq = id}
compFun : {S S' S'' : Setoid} →
SetoidFun S' S'' → SetoidFun S S' → SetoidFun S S''
compFun f g = record {fun = fun f ∘ fun g; feq = feq f ∘ feq g}
idl : {X Y : Setoid} {f : SetoidFun X Y} → compFun idFun f ≅ f
idl {f = setoidfun _ _} = refl
idr : {X Y : Setoid} {f : SetoidFun X Y} → compFun f idFun ≅ f
idr {f = setoidfun _ _} = refl
Setoids : Cat
Setoids = record{
Obj = Setoid;
Hom = SetoidFun;
iden = idFun;
comp = compFun;
idl = idl;
idr = idr;
ass = refl}
-- -}
|
{
"alphanum_fraction": 0.5122979621,
"avg_line_length": 26.3518518519,
"ext": "agda",
"hexsha": "c86564888b1028b7777c0c954e328cf7c208e5cf",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "Categories/Setoids.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "Categories/Setoids.agda",
"max_line_length": 74,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "Categories/Setoids.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 553,
"size": 1423
}
|
------------------------------------------------------------------------
-- Divisibility and coprimality
------------------------------------------------------------------------
module Data.Integer.Divisibility where
open import Data.Function
open import Data.Integer
open import Data.Integer.Properties
import Data.Nat.Divisibility as ℕ
import Data.Nat.Coprimality as ℕ
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
-- Divisibility.
infix 4 _∣_
_∣_ : Rel ℤ
_∣_ = ℕ._∣_ on₁ ∣_∣
-- Coprimality.
Coprime : Rel ℤ
Coprime = ℕ.Coprime on₁ ∣_∣
-- If i divides jk and is coprime to j, then it divides k.
coprime-divisor : ∀ i j k → Coprime i j → i ∣ j * k → i ∣ k
coprime-divisor i j k c eq =
ℕ.coprime-divisor c (subst (ℕ._∣_ ∣ i ∣) (abs-*-commute j k) eq)
|
{
"alphanum_fraction": 0.5856423174,
"avg_line_length": 24.8125,
"ext": "agda",
"hexsha": "b3e45755b2277a50bfdaddb57e55e116fc88a464",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/Integer/Divisibility.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/Integer/Divisibility.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/Integer/Divisibility.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 233,
"size": 794
}
|
module Issue18 where
postulate
D : Set
data ∃ (A : D → Set) : Set where
_,_ : (witness : D) → A witness → ∃ A
|
{
"alphanum_fraction": 0.5775862069,
"avg_line_length": 14.5,
"ext": "agda",
"hexsha": "73156c200f3ac8096d127870954d8d132fe0793d",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/NonConjectures/Issue18.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/NonConjectures/Issue18.agda",
"max_line_length": 39,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/NonConjectures/Issue18.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 45,
"size": 116
}
|
{-# OPTIONS --cubical #-}
module Cubical.README where
------------------------------------------------------------------------
-- An experimental library for Cubical Agda
-----------------------------------------------------------------------
-- The library comes with a .agda-lib file, for use with the library
-- management system.
------------------------------------------------------------------------
-- Module hierarchy
------------------------------------------------------------------------
-- The core library for Cubical Agda.
-- It contains basic primitives, equivalences, glue types.
import Cubical.Core.Everything
-- The foundations for Cubical Agda.
-- The Prelude module is self-explanatory.
import Cubical.Foundations.Prelude
import Cubical.Foundations.Everything
-- Data types and properties
import Cubical.Data.Everything
-- Properties and proofs about relations
import Cubical.Relation.Everything
-- Higher-inductive types
import Cubical.HITs.Everything
-- Coinductive data types and properties
import Cubical.Codata.Everything
-- Various experiments using Cubical Agda
import Cubical.Experiments.Everything
|
{
"alphanum_fraction": 0.5905096661,
"avg_line_length": 29.9473684211,
"ext": "agda",
"hexsha": "4f45ff381f46d65ad8b161efecddd2f107dc0a8e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/README.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/README.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/README.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 208,
"size": 1138
}
|
module Lang.Function where
import Lvl
open import Data.Boolean
open import Data.List as List using (List)
open import Data.List.Functions.Positional as List
open import Data.Option
open import Data
open import Lang.Reflection
open import Syntax.Do
open import Type
-- A default value tactic for implicit arguments.
-- This implements a "default arguments" language feature.
-- It works by always unifying the hole with the specified value.
-- Essentially a constant function for holes.
-- Example:
-- test : ∀{@(tactic default 𝑇) x : Bool} → Bool
-- test{x} = x
-- Now, `test = 𝑇`, `test{𝑇} = 𝑇`, `test{𝐹} = 𝐹`.
default : ∀{ℓ}{T : Type{ℓ}} → T → Term → TC(Unit{Lvl.𝟎})
default x hole = quoteTC x >>= unify hole
-- A no inferrance tactic for implicit arguments.
-- This makes implicit arguments work like explicit arguments by throwing an error when the hole does not match perfectly while still maintaining its implicit visibility status.
-- It works by always selecting the last argument in the hole, and the last argument is the one closest to the value, which is the argument one expects it to choose.
-- Examples:
-- idᵢwith : ∀{T : TYPE} → {@(tactic no-infer) x : T} → T
-- idᵢwith {x = x} = x
--
-- idᵢwithout : ∀{T : TYPE} → {x : T} → T
-- idᵢwithout {x = x} = x
--
-- postulate test : ({_ : Bool} → Bool) → Bool
--
-- test1 : Bool
-- test1 = test idᵢwith
--
-- test2 : (Bool → Bool) → Bool
-- test2 _ = test idᵢwith
--
-- test3 : ∀{T : TYPE} → {_ : T} → T
-- test3 = idᵢwith
--
-- It is useful in these kinds of scenarios because idᵢwithout would require writing the implicit argument explicitly, while idᵢwith always uses the given argument in order like how explicit arguments work.
no-infer : Term → TC(Unit{Lvl.𝟎})
no-infer hole@(meta _ args) with List.last(args)
... | None = typeError (List.singleton (strErr "Expected a parameter with \"hidden\" visibility when using \"no-infer\", found none."))
... | Some (arg (arg-info hidden _) term) = unify hole term
{-# CATCHALL #-}
... | Some (arg (arg-info _ _) term) = typeError (List.singleton (strErr "Wrong visibility of argument. Expected \"hidden\" when using \"no-infer\"."))
{-# CATCHALL #-}
no-infer _ = typeError (List.singleton (strErr "TODO: In what situations is this error occurring?"))
-- TODO: Implement idᵢwith, rename it to idᵢ, and put it in Functional. Also, try to refactor Data.Boolean, Data.List and Data.Option so that they only contain the type definition and its constructors. This minimizes the amount of dependencies this module requires (which should help in case of circular dependencies when importing this module).
|
{
"alphanum_fraction": 0.6859903382,
"avg_line_length": 48.0535714286,
"ext": "agda",
"hexsha": "bf2d7c477a6d59fe7bd1ee9ecc4ba09647c8a2c9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Lang/Function.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Lang/Function.agda",
"max_line_length": 345,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Lang/Function.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 741,
"size": 2691
}
|
postulate
T C D : Set
instance I : {{_ : C}} → D
d : {{_ : D}} → T
t : T
t = d
|
{
"alphanum_fraction": 0.4022988506,
"avg_line_length": 9.6666666667,
"ext": "agda",
"hexsha": "14d01561fa0bb443a5dba7624414bd5c6725ff31",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue2044.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue2044.agda",
"max_line_length": 28,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2044.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 42,
"size": 87
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Diagram.Cone.Properties where
open import Level
open import Categories.Category
open import Categories.Functor
open import Categories.Functor.Properties
open import Categories.NaturalTransformation
import Categories.Diagram.Cone as Con
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e : Level
C D J J′ : Category o ℓ e
module _ {F : Functor J C} (G : Functor C D) where
private
module C = Category C
module D = Category D
module F = Functor F
module G = Functor G
module CF = Con F
GF = G ∘F F
module CGF = Con GF
F-map-Coneˡ : CF.Cone → CGF.Cone
F-map-Coneˡ K = record
{ apex = record
{ ψ = λ X → G.F₁ (ψ X)
; commute = λ f → [ G ]-resp-∘ (commute f)
}
}
where open CF.Cone K
F-map-Cone⇒ˡ : ∀ {K K′} (f : CF.Cone⇒ K K′) → CGF.Cone⇒ (F-map-Coneˡ K) (F-map-Coneˡ K′)
F-map-Cone⇒ˡ f = record
{ arr = G.F₁ arr
; commute = [ G ]-resp-∘ commute
}
where open CF.Cone⇒ f
module _ {F : Functor J C} (G : Functor J′ J) where
private
module C = Category C
module J′ = Category J′
module F = Functor F
module G = Functor G
module CF = Con F
FG = F ∘F G
module CFG = Con FG
F-map-Coneʳ : CF.Cone → CFG.Cone
F-map-Coneʳ K = record
{ apex = record
{ ψ = λ j → ψ (G.F₀ j)
; commute = λ f → commute (G.F₁ f)
}
}
where open CF.Cone K
F-map-Cone⇒ʳ : ∀ {K K′} (f : CF.Cone⇒ K K′) → CFG.Cone⇒ (F-map-Coneʳ K) (F-map-Coneʳ K′)
F-map-Cone⇒ʳ f = record
{ arr = arr
; commute = commute
}
where open CF.Cone⇒ f
module _ {F G : Functor J C} (α : NaturalTransformation F G) where
private
module C = Category C
module J = Category J
module F = Functor F
module G = Functor G
module α = NaturalTransformation α
module CF = Con F
module CG = Con G
open C
open HomReasoning
open MR C
nat-map-Cone : CF.Cone → CG.Cone
nat-map-Cone K = record
{ apex = record
{ ψ = λ j → α.η j C.∘ ψ j
; commute = λ {X Y} f → begin
G.F₁ f ∘ α.η X ∘ ψ X ≈˘⟨ pushˡ (α.commute f) ⟩
(α.η Y ∘ F.F₁ f) ∘ ψ X ≈⟨ pullʳ (commute f) ⟩
α.η Y ∘ ψ Y ∎
}
}
where open CF.Cone K
nat-map-Cone⇒ : ∀ {K K′} (f : CF.Cone⇒ K K′) → CG.Cone⇒ (nat-map-Cone K) (nat-map-Cone K′)
nat-map-Cone⇒ {K} {K′} f = record
{ arr = arr
; commute = pullʳ commute
}
where open CF.Cone⇒ f
|
{
"alphanum_fraction": 0.5615841584,
"avg_line_length": 24.7549019608,
"ext": "agda",
"hexsha": "34891b35099daf0f42b9fb5248b3e7e80db2498b",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Diagram/Cone/Properties.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Diagram/Cone/Properties.agda",
"max_line_length": 92,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Diagram/Cone/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 955,
"size": 2525
}
|
{-# OPTIONS --safe #-}
module Definition.Conversion.HelperDecidable where
open import Definition.Untyped
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Conversion
open import Definition.Conversion.Whnf
open import Definition.Conversion.Soundness
open import Definition.Conversion.Symmetry
open import Definition.Conversion.Stability
open import Definition.Conversion.Conversion
open import Definition.Conversion.Lift
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.Substitution
open import Definition.Typed.Consequences.Injectivity
open import Definition.Typed.Consequences.Reduction
open import Definition.Typed.Consequences.Equality
open import Definition.Typed.Consequences.Inequality as IE
open import Definition.Typed.Consequences.NeTypeEq
open import Definition.Typed.Consequences.SucCong
open import Tools.Nat
open import Tools.Product
open import Tools.Empty
open import Tools.Nullary
import Tools.PropositionalEquality as PE
dec-relevance : ∀ (r r′ : Relevance) → Dec (r PE.≡ r′)
dec-relevance ! ! = yes PE.refl
dec-relevance ! % = no (λ ())
dec-relevance % ! = no (λ ())
dec-relevance % % = yes PE.refl
dec-level : ∀ (l l′ : Level) → Dec (l PE.≡ l′)
dec-level ⁰ ⁰ = yes PE.refl
dec-level ⁰ ¹ = no (λ ())
dec-level ¹ ⁰ = no (λ ())
dec-level ¹ ¹ = yes PE.refl
-- Algorithmic equality of variables infers propositional equality.
strongVarEq : ∀ {m n A Γ l} → Γ ⊢ var n ~ var m ↑! A ^ l → n PE.≡ m
strongVarEq (var-refl x x≡y) = x≡y
-- Helper function for decidability of applications.
dec~↑!-app : ∀ {k k₁ l l₁ F F₁ G G₁ rF B Γ Δ lF lG lΠ lK}
→ ⊢ Γ ≡ Δ
→ Γ ⊢ k ∷ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ ! , ι lΠ ]
→ Δ ⊢ k₁ ∷ Π F₁ ^ rF ° lF ▹ G₁ ° lG ° lΠ ^ [ ! , ι lΠ ]
→ Γ ⊢ k ~ k₁ ↓! B ^ lK
→ Dec (Γ ⊢ l [genconv↑] l₁ ∷ F ^ [ rF , ι lF ])
→ Dec (∃ λ A → ∃ λ lA → Γ ⊢ k ∘ l ^ lΠ ~ k₁ ∘ l₁ ^ lΠ ↑! A ^ lA)
dec~↑!-app Γ≡Δ k k₁ k~k₁ (yes p) =
let
whnfA , neK , neL = ne~↓! k~k₁
⊢A , ⊢k , ⊢l = syntacticEqTerm (soundness~↓! k~k₁)
l≡l , ΠFG₁≡A = neTypeEq neK k ⊢k
H , E , A≡ΠHE = Π≡A ΠFG₁≡A whnfA
F≡H , rF≡rH , lF≡lH , lG≡lE , G₁≡E = injectivity (PE.subst (λ x → _ ⊢ _ ≡ x ^ _) A≡ΠHE ΠFG₁≡A)
in yes (E [ _ ] , _ , app-cong (PE.subst₂ (λ x y → _ ⊢ _ ~ _ ↓! x ^ y) A≡ΠHE (PE.sym l≡l) k~k₁) (convConvTerm%! p F≡H))
dec~↑!-app Γ≡Δ k k₁ k~k₁ (no ¬p) = no (λ { (_ , _ , app-cong k~k₁′ p) →
let
whnfA , neK , neL = ne~↓! k~k₁′
⊢A , ⊢k , ⊢l = syntacticEqTerm (soundness~↓! k~k₁′)
l≡l , Π≡Π = neTypeEq neK k ⊢k
F≡F , rF≡rF , lF≡lF , lG≡lG , G≡G = injectivity Π≡Π
in ¬p (convConvTerm%! (PE.subst₂ (λ x y → _ ⊢ _ [genconv↑] _ ∷ _ ^ [ x , ι y ]) (PE.sym rF≡rF) (PE.sym lF≡lF) p) (sym F≡F)) })
nonNeutralℕ : Neutral ℕ → ⊥
nonNeutralℕ ()
nonNeutralU : ∀ {r l} → Neutral (Univ r l) → ⊥
nonNeutralU ()
Idℕ-elim : ∀ {Γ l A B t u t' u'} → Neutral A → Γ ⊢ Id A t u ~ Id ℕ t' u' ↑! B ^ l → ⊥
Idℕ-elim neA (Id-cong x x₁ x₂) = let _ , _ , neℕ = ne~↓! x in ⊥-elim (nonNeutralℕ neℕ)
Idℕ-elim neA (Id-ℕ x x₁) = ⊥-elim (nonNeutralℕ neA)
Idℕ-elim neA (Id-ℕ0 x) = ⊥-elim (nonNeutralℕ neA)
Idℕ-elim neA (Id-ℕS x x₁) = ⊥-elim (nonNeutralℕ neA)
Idℕ-elim' : ∀ {Γ l A B t u t' u'} → Neutral A → Γ ⊢ Id ℕ t u ~ Id A t' u' ↑! B ^ l → ⊥
Idℕ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in Idℕ-elim neA e'
conv↑-inversion : ∀ {Γ l A t u} → Whnf A → Whnf t → Whnf u → Γ ⊢ t [conv↑] u ∷ A ^ l → Γ ⊢ t [conv↓] u ∷ A ^ l
conv↑-inversion whnfA whnft whnfu ([↑]ₜ B t′ u′ D d d′ whnfB whnft′ whnfu′ t<>u) =
let et = whnfRed*Term d whnft
eu = whnfRed*Term d′ whnfu
eA = whnfRed* D whnfA
in PE.subst₃ (λ A X Y → _ ⊢ X [conv↓] Y ∷ A ^ _) (PE.sym eA) (PE.sym et) (PE.sym eu) t<>u
Idℕ0-elim- : ∀ {Γ l t} → Neutral t → Γ ⊢ t [conv↓] zero ∷ ℕ ^ l → ⊥
Idℕ0-elim- net (ℕ-ins ())
Idℕ0-elim- net (ne-ins x x₁ x₂ ())
Idℕ0-elim- () (zero-refl x)
Idℕ0-elim : ∀ {Γ l A t u u'} → Neutral t → Γ ⊢ Id ℕ t u ~ Id ℕ zero u' ↑! A ^ l → ⊥
Idℕ0-elim net (Id-cong x y x₂) =
let e = conv↑-inversion ℕₙ (ne net) zeroₙ y in Idℕ0-elim- net e
Idℕ0-elim net (Id-ℕ () x₁)
Idℕ0-elim () (Id-ℕ0 x)
Idℕ0-elim' : ∀ {Γ l A t u u'} → Neutral t → Γ ⊢ Id ℕ zero u ~ Id ℕ t u' ↑! A ^ l → ⊥
Idℕ0-elim' net e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in Idℕ0-elim net e'
IdℕS-elim- : ∀ {Γ l t n} → Neutral t → Γ ⊢ t [conv↓] suc n ∷ ℕ ^ l → ⊥
IdℕS-elim- net (ℕ-ins ())
IdℕS-elim- net (ne-ins x x₁ x₂ ())
IdℕS-elim- () (suc-cong x)
IdℕS-elim : ∀ {Γ l A t u n u'} → Neutral t → Γ ⊢ Id ℕ t u ~ Id ℕ (suc n) u' ↑! A ^ l → ⊥
IdℕS-elim net (Id-cong x y x₂) =
let e = conv↑-inversion ℕₙ (ne net) sucₙ y in IdℕS-elim- net e
IdℕS-elim net (Id-ℕ () x₁)
IdℕS-elim () (Id-ℕS x _)
IdℕS-elim' : ∀ {Γ l A t u n u'} → Neutral t → Γ ⊢ Id ℕ (suc n) u ~ Id ℕ t u' ↑! A ^ l → ⊥
IdℕS-elim' net e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in IdℕS-elim net e'
Idℕ0S-elim- : ∀ {Γ l n} → Γ ⊢ zero [conv↓] suc n ∷ ℕ ^ l → ⊥
Idℕ0S-elim- (ℕ-ins ())
Idℕ0S-elim- (ne-ins x x₁ x₂ ())
Idℕ0S-elim : ∀ {Γ l A u u' n} → Γ ⊢ Id ℕ zero u ~ Id ℕ (suc n) u' ↑! A ^ l → ⊥
Idℕ0S-elim (Id-cong x y x₂) =
let e = conv↑-inversion ℕₙ zeroₙ sucₙ y in Idℕ0S-elim- e
Idℕ0S-elim (Id-ℕ () _)
Idℕ0S-elim' : ∀ {Γ l A u u' n} → Γ ⊢ Id ℕ (suc n) u ~ Id ℕ zero u' ↑! A ^ l → ⊥
Idℕ0S-elim' e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in Idℕ0S-elim e'
IdU-elim : ∀ {Γ l A B t u t' u' rU lU} → Neutral A → Γ ⊢ Id A t u ~ Id (Univ rU lU) t' u' ↑! B ^ l → ⊥
IdU-elim neA (Id-cong x x₁ x₂) = let _ , _ , neU = ne~↓! x in ⊥-elim (nonNeutralU neU)
IdU-elim neA (Id-U x x₁) = ⊥-elim (nonNeutralU neA)
IdU-elim neA (Id-Uℕ x) = ⊥-elim (nonNeutralU neA)
IdU-elim neA (Id-UΠ x x₁) = ⊥-elim (nonNeutralU neA)
IdU-elim' : ∀ {Γ l A B t u t' u' rU lU} → Neutral A → Γ ⊢ Id (Univ rU lU) t u ~ Id A t' u' ↑! B ^ l → ⊥
IdU-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in IdU-elim neA e'
IdUℕ-elim : ∀ {Γ l A t u t' u' rU lU} → Γ ⊢ Id (Univ rU lU) t u ~ Id ℕ t' u' ↑! A ^ l → ⊥
IdUℕ-elim (Id-cong () x₁ x₂)
IdℕU-elim : ∀ {Γ l A t u t' u' rU lU} → Γ ⊢ Id ℕ t u ~ Id (Univ rU lU) t' u' ↑! A ^ l → ⊥
IdℕU-elim (Id-cong () x₁ x₂)
IdUUℕ-elim : ∀ {Γ l A t u u'} → Neutral t → Γ ⊢ Id (U ⁰) t u ~ Id (U ⁰) ℕ u' ↑! A ^ l → ⊥
IdUUℕ-elim () (Id-Uℕ x)
IdUUℕ-elim' : ∀ {Γ l A t u u'} → Neutral t → Γ ⊢ Id (U ⁰) ℕ u ~ Id (U ⁰) t u' ↑! A ^ l → ⊥
IdUUℕ-elim' () (Id-Uℕ x)
IdUUΠ-elim- : ∀ {Γ l A rA B X t} → Neutral t → Γ ⊢ t [conv↓] Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰ ∷ X ^ l → ⊥
IdUUΠ-elim- net (η-eq x x₁ x₂ x₃ x₄ x₅ (ne ()) x₇)
IdUUΠ-elim : ∀ {Γ l A rA B X t u u'} → Neutral t → Γ ⊢ Id (U ⁰) t u ~ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) u' ↑! X ^ l → ⊥
IdUUΠ-elim net (Id-cong x y x₂) = let e = conv↑-inversion Uₙ (ne net) Πₙ y in IdUUΠ-elim- net e
IdUUΠ-elim net (Id-U () x₁)
IdUUΠ-elim () (Id-UΠ x x₁)
IdUUΠ-elim' : ∀ {Γ l A rA B X t u u'} → Neutral t → Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) u ~ Id (U ⁰) t u' ↑! X ^ l → ⊥
IdUUΠ-elim' net e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in IdUUΠ-elim net e'
IdUUΠℕ-elim- : ∀ {Γ l A rA B X} → Γ ⊢ Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰ [conv↓] ℕ ∷ X ^ l → ⊥
IdUUΠℕ-elim- (η-eq x x₁ x₂ x₃ x₄ x₅ (ne ()) x₇)
IdUUΠℕ-elim : ∀ {Γ l A rA B X u u'} → Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) u ~ Id (U ⁰) ℕ u' ↑! X ^ l → ⊥
IdUUΠℕ-elim (Id-cong x y x₂) = let e = conv↑-inversion Uₙ Πₙ ℕₙ y in IdUUΠℕ-elim- e
IdUUΠℕ-elim (Id-U () x₁)
IdUUΠℕ-elim' : ∀ {Γ l A rA B X u u'} → Γ ⊢ Id (U ⁰) ℕ u ~ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) u' ↑! X ^ l → ⊥
IdUUΠℕ-elim' e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in IdUUΠℕ-elim e'
castℕ-elim : ∀ {Γ l A B B' X t e t' e'} → Neutral A → Γ ⊢ cast ⁰ A B e t ~ cast ⁰ ℕ B' e' t' ↑! X ^ l → ⊥
castℕ-elim neA (cast-cong () x₁ x₂ x₃ x₄)
castℕ-elim () (cast-ℕ x x₁ x₂ x₃)
castℕ-elim () (cast-ℕℕ x x₁ x₂)
castℕ-elim () (cast-ℕΠ x x₁ x₂ x₃)
castℕ-elim' : ∀ {Γ l A B B' X t e t' e'} → Neutral A → Γ ⊢ cast ⁰ ℕ B e t ~ cast ⁰ A B' e' t' ↑! X ^ l → ⊥
castℕ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castℕ-elim neA e'
castΠ-elim : ∀ {Γ l A B B' X t e t' e' r P Q} → Neutral A → Γ ⊢ cast ⁰ A B e t ~ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) B' e' t' ↑! X ^ l → ⊥
castΠ-elim neA (cast-cong () x₁ x₂ x₃ x₄)
castΠ-elim () (cast-Π x x₁ x₂ x₃ x₄)
castΠ-elim () (cast-Πℕ x x₁ x₂ x₃)
castΠ-elim () (cast-ΠΠ%! x x₁ x₂ x₃ x₄)
castΠ-elim () (cast-ΠΠ!% x x₁ x₂ x₃ x₄)
castΠ-elim' : ∀ {Γ l A B B' X t e t' e' r P Q} → Neutral A → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) B e t ~ cast ⁰ A B' e' t' ↑! X ^ l → ⊥
castΠ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castΠ-elim neA e'
castℕℕ-elim : ∀ {Γ l A X t e t' e'} → Neutral A → Γ ⊢ cast ⁰ ℕ A e t ~ cast ⁰ ℕ ℕ e' t' ↑! X ^ l → ⊥
castℕℕ-elim neA (cast-cong () x₁ x₂ x₃ x₄)
castℕℕ-elim (var n) (cast-ℕ () x₁ x₂ x₃)
castℕℕ-elim () (cast-ℕℕ x x₁ x₂)
castℕℕ-elim' : ∀ {Γ l A X t e t' e'} → Neutral A → Γ ⊢ cast ⁰ ℕ ℕ e t ~ cast ⁰ ℕ A e' t' ↑! X ^ l → ⊥
castℕℕ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castℕℕ-elim neA e'
castℕΠ-elim : ∀ {Γ l A A' X t e t' e' r P Q} → Γ ⊢ cast ⁰ ℕ A e t ~ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) A' e' t' ↑! X ^ l → ⊥
castℕΠ-elim (cast-cong () x₁ x₂ x₃ x₄)
castℕΠ-elim' : ∀ {Γ l A A' X t e t' e' r P Q} → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) A e t ~ cast ⁰ ℕ A' e' t' ↑! X ^ l → ⊥
castℕΠ-elim' (cast-cong () x₁ x₂ x₃ x₄)
castℕneΠ-elim : ∀ {Γ l A X t e t' e' r P Q} → Neutral A → Γ ⊢ cast ⁰ ℕ A e t ~ cast ⁰ ℕ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) e' t' ↑! X ^ l → ⊥
castℕneΠ-elim neA (cast-cong () x₁ x₂ x₃ x₄)
castℕneΠ-elim neA (cast-ℕ () x₁ x₂ x₃)
castℕneΠ-elim () (cast-ℕΠ x x₁ x₂ x₃)
castℕneΠ-elim' : ∀ {Γ l A X t e t' e' r P Q} → Neutral A → Γ ⊢ cast ⁰ ℕ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~ cast ⁰ ℕ A e' t' ↑! X ^ l → ⊥
castℕneΠ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castℕneΠ-elim neA e'
castℕℕΠ-elim : ∀ {Γ l X t e t' e' r P Q} → Γ ⊢ cast ⁰ ℕ ℕ e t ~ cast ⁰ ℕ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) e' t' ↑! X ^ l → ⊥
castℕℕΠ-elim (cast-cong () x₁ x₂ x₃ x₄)
castℕℕΠ-elim (cast-ℕ () x₁ x₂ x₃)
castℕℕΠ-elim' : ∀ {Γ l X t e t' e' r P Q} → Γ ⊢ cast ⁰ ℕ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~ cast ⁰ ℕ ℕ e' t' ↑! X ^ l → ⊥
castℕℕΠ-elim' e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castℕℕΠ-elim e'
castΠneℕ-elim : ∀ {Γ l A X t e t' e' r P Q r' P' Q'} → Neutral A → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) A e t ~
cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) ℕ e' t' ↑! X ^ l → ⊥
castΠneℕ-elim neA (cast-cong () x₁ x₂ x₃ x₄)
castΠneℕ-elim neA (cast-Π x () x₂ x₃ x₄)
castΠneℕ-elim () (cast-Πℕ x x₁ x₂ x₃)
castΠneℕ-elim' : ∀ {Γ l A X t e t' e' r P Q r' P' Q'} → Neutral A → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) ℕ e t ~
cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) A e' t' ↑! X ^ l → ⊥
castΠneℕ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castΠneℕ-elim neA e'
castΠneΠ-elim : ∀ {Γ l A X t e t' e' r P Q r' P' Q' r'' P'' Q''} → Neutral A →
Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) A e t ~ cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) (Π P'' ^ r'' ° ⁰ ▹ Q'' ° ⁰ ° ⁰) e' t' ↑! X ^ l → ⊥
castΠneΠ-elim neA (cast-cong () x₁ x₂ x₃ x₄)
castΠneΠ-elim neA (cast-Π x () x₂ x₃ x₄)
castΠneΠ-elim () (cast-ΠΠ%! x x₁ x₂ x₃ x₄)
castΠneΠ-elim () (cast-ΠΠ!% x x₁ x₂ x₃ x₄)
castΠneΠ-elim' : ∀ {Γ l A X t e t' e' r P Q r' P' Q' r'' P'' Q''} → Neutral A →
Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) (Π P'' ^ r'' ° ⁰ ▹ Q'' ° ⁰ ° ⁰) e t ~ cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) A e' t' ↑! X ^ l → ⊥
castΠneΠ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castΠneΠ-elim neA e'
castΠΠℕ-elim : ∀ {Γ l X t e t' e' r P Q r' P' Q' r'' P'' Q''} →
Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) ℕ e t ~ cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) (Π P'' ^ r'' ° ⁰ ▹ Q'' ° ⁰ ° ⁰) e' t' ↑! X ^ l → ⊥
castΠΠℕ-elim (cast-cong () x₁ x₂ x₃ x₄)
castΠΠℕ-elim (cast-Π x () x₂ x₃ x₄)
castΠΠℕ-elim' : ∀ {Γ l X t e t' e' r P Q r' P' Q' r'' P'' Q''} →
Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) (Π P'' ^ r'' ° ⁰ ▹ Q'' ° ⁰ ° ⁰) e t ~ cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) ℕ e' t' ↑! X ^ l → ⊥
castΠΠℕ-elim' e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castΠΠℕ-elim e'
castΠΠ!%-elim : ∀ {Γ l A A' X t e t' e' P Q P' Q'} → Γ ⊢ cast ⁰ (Π P ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰) A e t ~
cast ⁰ (Π P' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰) A' e' t' ↑! X ^ l → ⊥
castΠΠ!%-elim (cast-cong () x₁ x₂ x₃ x₄)
castΠΠ%!-elim : ∀ {Γ l A A' X t e t' e' P Q P' Q'} → Γ ⊢ cast ⁰ (Π P ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰) A e t ~
cast ⁰ (Π P' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰) A' e' t' ↑! X ^ l → ⊥
castΠΠ%!-elim (cast-cong () x₁ x₂ x₃ x₄)
-- Helper functions for decidability for neutrals
decConv↓Term-ℕ-ins : ∀ {t u Γ l}
→ Γ ⊢ t [conv↓] u ∷ ℕ ^ l
→ Γ ⊢ t ~ t ↓! ℕ ^ l
→ Γ ⊢ t ~ u ↓! ℕ ^ l
decConv↓Term-ℕ-ins (ℕ-ins x) t~t = x
decConv↓Term-ℕ-ins (ne-ins x x₁ () x₃) t~t
decConv↓Term-ℕ-ins (zero-refl x) ([~] A D whnfB ())
decConv↓Term-ℕ-ins (suc-cong x) ([~] A D whnfB ())
decConv↓Term-U-ins : ∀ {t u Γ r lU l}
→ Γ ⊢ t [conv↓] u ∷ Univ r lU ^ l
→ Γ ⊢ t ~ t ↓! Univ r lU ^ l
→ Γ ⊢ t ~ u ↓! Univ r lU ^ l
decConv↓Term-U-ins (ne x) t~r = x
decConv↓Term-ne-ins : ∀ {t u A Γ l}
→ Neutral A
→ Γ ⊢ t [conv↓] u ∷ A ^ l
→ ∃ λ B → ∃ λ lB → Γ ⊢ t ~ u ↓! B ^ lB
decConv↓Term-ne-ins neA (ne-ins x x₁ x₂ x₃) = _ , _ , x₃
-- Helper function for decidability for impossibility of terms not being equal
-- as neutrals when they are equal as terms and the first is a neutral.
decConv↓Term-ℕ : ∀ {t u Γ l}
→ Γ ⊢ t [conv↓] u ∷ ℕ ^ l
→ Γ ⊢ t ~ t ↓! ℕ ^ l
→ ¬ (Γ ⊢ t ~ u ↓! ℕ ^ l)
→ ⊥
decConv↓Term-ℕ (ℕ-ins x) t~t ¬u~u = ¬u~u x
decConv↓Term-ℕ (ne-ins x x₁ () x₃) t~t ¬u~u
decConv↓Term-ℕ (zero-refl x) ([~] A D whnfB ()) ¬u~u
decConv↓Term-ℕ (suc-cong x) ([~] A D whnfB ()) ¬u~u
decConv↓Term-U : ∀ {t u Γ r lU l}
→ Γ ⊢ t [conv↓] u ∷ Univ r lU ^ l
→ Γ ⊢ t ~ t ↓! Univ r lU ^ l
→ ¬ (Γ ⊢ t ~ u ↓! Univ r lU ^ l)
→ ⊥
decConv↓Term-U (ne x) t~t ¬u~u = ¬u~u x
|
{
"alphanum_fraction": 0.5228789986,
"avg_line_length": 47.4587458746,
"ext": "agda",
"hexsha": "97c8a2c2c56df053317bdcf7f1f28f0ccaa0cbcb",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/Conversion/HelperDecidable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/Conversion/HelperDecidable.agda",
"max_line_length": 149,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/Conversion/HelperDecidable.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 7526,
"size": 14380
}
|
record R (X : Set) : Set₁ where
field
P : X → Set
f : ∀ {x : X} → P x → P x
open R {{…}}
test : ∀ {X} {{r : R X}} {x : X} → P x → P x
test p = f p
-- WAS: instance search fails with several candidates left
-- SHOULD: succeed
|
{
"alphanum_fraction": 0.5168067227,
"avg_line_length": 18.3076923077,
"ext": "agda",
"hexsha": "40f43aeb5db9b2f7f8b9b0cd4444152bd947f0c7",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2760.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2760.agda",
"max_line_length": 58,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2760.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 89,
"size": 238
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Heterogeneous equality
------------------------------------------------------------------------
{-# OPTIONS --with-K --safe #-}
module Relation.Binary.HeterogeneousEquality where
import Axiom.Extensionality.Heterogeneous as Ext
open import Data.Product
open import Data.Unit.NonEta
open import Function
open import Function.Inverse using (Inverse)
open import Level
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.Consequences
open import Relation.Binary.Indexed.Heterogeneous
using (IndexedSetoid)
open import Relation.Binary.Indexed.Heterogeneous.Construct.At
using (_atₛ_)
open import Relation.Binary.PropositionalEquality as P using (_≡_; refl)
import Relation.Binary.HeterogeneousEquality.Core as Core
------------------------------------------------------------------------
-- Heterogeneous equality
infix 4 _≇_
open Core public using (_≅_; refl)
-- Nonequality.
_≇_ : ∀ {ℓ} {A : Set ℓ} → A → {B : Set ℓ} → B → Set ℓ
x ≇ y = ¬ x ≅ y
------------------------------------------------------------------------
-- Conversion
open Core public using (≅-to-≡; ≡-to-≅)
≅-to-type-≡ : ∀ {a} {A B : Set a} {x : A} {y : B} →
x ≅ y → A ≡ B
≅-to-type-≡ refl = refl
≅-to-subst-≡ : ∀ {a} {A B : Set a} {x : A} {y : B} → (p : x ≅ y) →
P.subst (λ x → x) (≅-to-type-≡ p) x ≡ y
≅-to-subst-≡ refl = refl
------------------------------------------------------------------------
-- Some properties
reflexive : ∀ {a} {A : Set a} → _⇒_ {A = A} _≡_ (λ x y → x ≅ y)
reflexive refl = refl
sym : ∀ {ℓ} {A B : Set ℓ} {x : A} {y : B} → x ≅ y → y ≅ x
sym refl = refl
trans : ∀ {ℓ} {A B C : Set ℓ} {x : A} {y : B} {z : C} →
x ≅ y → y ≅ z → x ≅ z
trans refl eq = eq
subst : ∀ {a} {A : Set a} {p} → Substitutive {A = A} (λ x y → x ≅ y) p
subst P refl p = p
subst₂ : ∀ {a b p} {A : Set a} {B : Set b} (P : A → B → Set p) →
∀ {x₁ x₂ y₁ y₂} → x₁ ≅ x₂ → y₁ ≅ y₂ → P x₁ y₁ → P x₂ y₂
subst₂ P refl refl p = p
subst-removable : ∀ {a p} {A : Set a}
(P : A → Set p) {x y} (eq : x ≅ y) z →
subst P eq z ≅ z
subst-removable P refl z = refl
≡-subst-removable : ∀ {a p} {A : Set a}
(P : A → Set p) {x y} (eq : x ≡ y) z →
P.subst P eq z ≅ z
≡-subst-removable P refl z = refl
cong : ∀ {a b} {A : Set a} {B : A → Set b} {x y}
(f : (x : A) → B x) → x ≅ y → f x ≅ f y
cong f refl = refl
cong-app : ∀ {a b} {A : Set a} {B : A → Set b} {f g : (x : A) → B x} →
f ≅ g → (x : A) → f x ≅ g x
cong-app refl x = refl
cong₂ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : ∀ x → B x → Set c}
{x y u v}
(f : (x : A) (y : B x) → C x y) → x ≅ y → u ≅ v → f x u ≅ f y v
cong₂ f refl refl = refl
resp₂ : ∀ {a ℓ} {A : Set a} (∼ : Rel A ℓ) → ∼ Respects₂ (λ x y → x ≅ y)
resp₂ _∼_ = subst⟶resp₂ _∼_ subst
icong : ∀ {a b ℓ} {I : Set ℓ}
(A : I → Set a) {B : {k : I} → A k → Set b}
{i j : I} {x : A i} {y : A j} →
i ≡ j →
(f : {k : I} → (z : A k) → B z) →
x ≅ y →
f x ≅ f y
icong _ refl _ refl = refl
icong₂ : ∀ {a b c ℓ} {I : Set ℓ}
(A : I → Set a)
{B : {k : I} → A k → Set b}
{C : {k : I} → (a : A k) → B a → Set c}
{i j : I} {x : A i} {y : A j} {u : B x} {v : B y} →
i ≡ j →
(f : {k : I} → (z : A k) → (w : B z) → C z w) →
x ≅ y → u ≅ v →
f x u ≅ f y v
icong₂ _ refl _ refl refl = refl
icong-subst-removable : ∀ {a b ℓ}
{I : Set ℓ}
(A : I → Set a) {B : {k : I} → A k → Set b}
{i j : I} (eq : i ≅ j)
(f : {k : I} → (z : A k) → B z)
(x : A i) →
f (subst A eq x) ≅ f x
icong-subst-removable _ refl _ _ = refl
icong-≡-subst-removable : ∀ {a b ℓ}
{I : Set ℓ}
(A : I → Set a) {B : {k : I} → A k → Set b}
{i j : I} (eq : i ≡ j)
(f : {k : I} → (z : A k) → B z)
(x : A i) →
f (P.subst A eq x) ≅ f x
icong-≡-subst-removable _ refl _ _ = refl
------------------------------------------------------------------------
--Proof irrelevance
≅-irrelevant : ∀ {ℓ} {A B : Set ℓ} → Irrelevant ((A → B → Set ℓ) ∋ λ a → a ≅_)
≅-irrelevant refl refl = refl
module _ {ℓ} {A₁ A₂ A₃ A₄ : Set ℓ} {a₁ : A₁} {a₂ : A₂} {a₃ : A₃} {a₄ : A₄} where
≅-heterogeneous-irrelevant : (p : a₁ ≅ a₂) (q : a₃ ≅ a₄) → a₂ ≅ a₃ → p ≅ q
≅-heterogeneous-irrelevant refl refl refl = refl
≅-heterogeneous-irrelevantˡ : (p : a₁ ≅ a₂) (q : a₃ ≅ a₄) → a₁ ≅ a₃ → p ≅ q
≅-heterogeneous-irrelevantˡ refl refl refl = refl
≅-heterogeneous-irrelevantʳ : (p : a₁ ≅ a₂) (q : a₃ ≅ a₄) → a₂ ≅ a₄ → p ≅ q
≅-heterogeneous-irrelevantʳ refl refl refl = refl
------------------------------------------------------------------------
-- Structures
isEquivalence : ∀ {a} {A : Set a} →
IsEquivalence {A = A} (λ x y → x ≅ y)
isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
setoid : ∀ {a} → Set a → Setoid _ _
setoid A = record
{ Carrier = A
; _≈_ = λ x y → x ≅ y
; isEquivalence = isEquivalence
}
indexedSetoid : ∀ {a b} {A : Set a} → (A → Set b) → IndexedSetoid A _ _
indexedSetoid B = record
{ Carrier = B
; _≈_ = λ x y → x ≅ y
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
}
≡↔≅ : ∀ {a b} {A : Set a} (B : A → Set b) {x : A} →
Inverse (P.setoid (B x)) ((indexedSetoid B) atₛ x)
≡↔≅ B = record
{ to = record { _⟨$⟩_ = id; cong = ≡-to-≅ }
; from = record { _⟨$⟩_ = id; cong = ≅-to-≡ }
; inverse-of = record
{ left-inverse-of = λ _ → refl
; right-inverse-of = λ _ → refl
}
}
decSetoid : ∀ {a} {A : Set a} →
Decidable {A = A} {B = A} (λ x y → x ≅ y) →
DecSetoid _ _
decSetoid dec = record
{ _≈_ = λ x y → x ≅ y
; isDecEquivalence = record
{ isEquivalence = isEquivalence
; _≟_ = dec
}
}
isPreorder : ∀ {a} {A : Set a} →
IsPreorder {A = A} (λ x y → x ≅ y) (λ x y → x ≅ y)
isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = id
; trans = trans
}
isPreorder-≡ : ∀ {a} {A : Set a} →
IsPreorder {A = A} _≡_ (λ x y → x ≅ y)
isPreorder-≡ = record
{ isEquivalence = P.isEquivalence
; reflexive = reflexive
; trans = trans
}
preorder : ∀ {a} → Set a → Preorder _ _ _
preorder A = record
{ Carrier = A
; _≈_ = _≡_
; _∼_ = λ x y → x ≅ y
; isPreorder = isPreorder-≡
}
------------------------------------------------------------------------
-- Convenient syntax for equational reasoning
module ≅-Reasoning where
-- The code in `Relation.Binary.Reasoning.Setoid` cannot handle
-- heterogeneous equalities, hence the code duplication here.
infix 4 _IsRelatedTo_
infix 3 _∎
infixr 2 _≅⟨_⟩_ _≅˘⟨_⟩_ _≡⟨_⟩_ _≡˘⟨_⟩_ _≡⟨⟩_
infix 1 begin_
data _IsRelatedTo_ {ℓ} {A : Set ℓ} (x : A) {B : Set ℓ} (y : B) :
Set ℓ where
relTo : (x≅y : x ≅ y) → x IsRelatedTo y
begin_ : ∀ {ℓ} {A : Set ℓ} {x : A} {B} {y : B} →
x IsRelatedTo y → x ≅ y
begin relTo x≅y = x≅y
_≅⟨_⟩_ : ∀ {ℓ} {A : Set ℓ} (x : A) {B} {y : B} {C} {z : C} →
x ≅ y → y IsRelatedTo z → x IsRelatedTo z
_ ≅⟨ x≅y ⟩ relTo y≅z = relTo (trans x≅y y≅z)
_≅˘⟨_⟩_ : ∀ {ℓ} {A : Set ℓ} (x : A) {B} {y : B} {C} {z : C} →
y ≅ x → y IsRelatedTo z → x IsRelatedTo z
_ ≅˘⟨ y≅x ⟩ relTo y≅z = relTo (trans (sym y≅x) y≅z)
_≡⟨_⟩_ : ∀ {ℓ} {A : Set ℓ} (x : A) {y C} {z : C} →
x ≡ y → y IsRelatedTo z → x IsRelatedTo z
_ ≡⟨ x≡y ⟩ relTo y≅z = relTo (trans (reflexive x≡y) y≅z)
_≡˘⟨_⟩_ : ∀ {ℓ} {A : Set ℓ} (x : A) {y C} {z : C} →
y ≡ x → y IsRelatedTo z → x IsRelatedTo z
_ ≡˘⟨ y≡x ⟩ relTo y≅z = relTo (trans (sym (reflexive y≡x)) y≅z)
_≡⟨⟩_ : ∀ {ℓ} {A : Set ℓ} (x : A) {B} {y : B} →
x IsRelatedTo y → x IsRelatedTo y
_ ≡⟨⟩ x≅y = x≅y
_∎ : ∀ {a} {A : Set a} (x : A) → x IsRelatedTo x
_∎ _ = relTo refl
------------------------------------------------------------------------
-- Inspect
-- Inspect can be used when you want to pattern match on the result r
-- of some expression e, and you also need to "remember" that r ≡ e.
record Reveal_·_is_ {a b} {A : Set a} {B : A → Set b}
(f : (x : A) → B x) (x : A) (y : B x) :
Set (a ⊔ b) where
constructor [_]
field eq : f x ≅ y
inspect : ∀ {a b} {A : Set a} {B : A → Set b}
(f : (x : A) → B x) (x : A) → Reveal f · x is f x
inspect f x = [ refl ]
-- Example usage:
-- f x y with g x | inspect g x
-- f x y | c z | [ eq ] = ...
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.15
proof-irrelevance = ≅-irrelevant
{-# WARNING_ON_USAGE proof-irrelevance
"Warning: proof-irrelevance was deprecated in v0.15.
Please use ≅-irrelevant instead."
#-}
-- Version 1.0
≅-irrelevance = ≅-irrelevant
{-# WARNING_ON_USAGE ≅-irrelevance
"Warning: ≅-irrelevance was deprecated in v1.0.
Please use ≅-irrelevant instead."
#-}
≅-heterogeneous-irrelevance = ≅-heterogeneous-irrelevant
{-# WARNING_ON_USAGE ≅-heterogeneous-irrelevance
"Warning: ≅-heterogeneous-irrelevance was deprecated in v1.0.
Please use ≅-heterogeneous-irrelevant instead."
#-}
≅-heterogeneous-irrelevanceˡ = ≅-heterogeneous-irrelevantˡ
{-# WARNING_ON_USAGE ≅-heterogeneous-irrelevanceˡ
"Warning: ≅-heterogeneous-irrelevanceˡ was deprecated in v1.0.
Please use ≅-heterogeneous-irrelevantˡ instead."
#-}
≅-heterogeneous-irrelevanceʳ = ≅-heterogeneous-irrelevantʳ
{-# WARNING_ON_USAGE ≅-heterogeneous-irrelevanceʳ
"Warning: ≅-heterogeneous-irrelevanceʳ was deprecated in v1.0.
Please use ≅-heterogeneous-irrelevantʳ instead."
#-}
Extensionality = Ext.Extensionality
{-# WARNING_ON_USAGE Extensionality
"Warning: Extensionality was deprecated in v1.0.
Please use Extensionality from `Axiom.Extensionality.Heterogeneous` instead."
#-}
≡-ext-to-≅-ext = Ext.≡-ext⇒≅-ext
{-# WARNING_ON_USAGE ≡-ext-to-≅-ext
"Warning: ≡-ext-to-≅-ext was deprecated in v1.0.
Please use ≡-ext⇒≅-ext from `Axiom.Extensionality.Heterogeneous` instead."
#-}
|
{
"alphanum_fraction": 0.4783710237,
"avg_line_length": 31.2521994135,
"ext": "agda",
"hexsha": "da7a6fbdcade2738840899bacf564f6e47d9d395",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/HeterogeneousEquality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/HeterogeneousEquality.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/HeterogeneousEquality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4062,
"size": 10657
}
|
{-# OPTIONS --without-K #-}
module Data.Word8.Primitive where
open import Agda.Builtin.Bool using (Bool)
open import Agda.Builtin.Nat using (Nat)
{-# FOREIGN GHC import qualified Data.Word #-}
{-# FOREIGN GHC import qualified Data.Bits #-}
postulate
Word8 : Set
_==_ : Word8 → Word8 → Bool
_/=_ : Word8 → Word8 → Bool
_xor_ : Word8 → Word8 → Word8
_and_ : Word8 → Word8 → Word8
_or_ : Word8 → Word8 → Word8
{-# COMPILE GHC Word8 = type Data.Word.Word8 #-}
{-# COMPILE GHC _==_ = (Prelude.==) #-}
{-# COMPILE GHC _/=_ = (Prelude./=) #-}
{-# COMPILE GHC _xor_ = (Data.Bits.xor) #-}
{-# COMPILE GHC _and_ = (Data.Bits..&.) #-}
{-# COMPILE GHC _or_ = (Data.Bits..|.) #-}
postulate
primWord8fromNat : Nat → Word8
primWord8toNat : Word8 → Nat
{-# COMPILE GHC primWord8fromNat = (\n -> Prelude.fromIntegral n) #-}
{-# COMPILE GHC primWord8toNat = (\w -> Prelude.fromIntegral w) #-}
|
{
"alphanum_fraction": 0.6376811594,
"avg_line_length": 28.935483871,
"ext": "agda",
"hexsha": "6902a87b1b73f6028849eb4d6d84b64cfa86ce2b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98a53f35fca27e3379cf851a9a6bdfe5bd8c9626",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "semenov-vladyslav/bytes-agda",
"max_forks_repo_path": "src/Data/Word8/Primitive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98a53f35fca27e3379cf851a9a6bdfe5bd8c9626",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "semenov-vladyslav/bytes-agda",
"max_issues_repo_path": "src/Data/Word8/Primitive.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98a53f35fca27e3379cf851a9a6bdfe5bd8c9626",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "semenov-vladyslav/bytes-agda",
"max_stars_repo_path": "src/Data/Word8/Primitive.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 288,
"size": 897
}
|
------------------------------------------------------------------------------
-- Testing the --schematic-propositional-symbols option
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- Fails because requires the above option.
module RequiredOption.SchematicPropositionalSymbols where
postulate D : Set
postulate id : (P : Set) → P → P
{-# ATP prove id #-}
|
{
"alphanum_fraction": 0.4477876106,
"avg_line_length": 31.3888888889,
"ext": "agda",
"hexsha": "0519d7b71971932d200a8182f016210499747783",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Fail/Errors/RequiredOption/SchematicPropositionalSymbols.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Fail/Errors/RequiredOption/SchematicPropositionalSymbols.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Fail/Errors/RequiredOption/SchematicPropositionalSymbols.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 94,
"size": 565
}
|
module Formalization.ClassicalPropositionalLogic.NaturalDeduction.Consistency where
import Lvl
open import Formalization.ClassicalPropositionalLogic.NaturalDeduction
open import Formalization.ClassicalPropositionalLogic.NaturalDeduction.Proofs
open import Formalization.ClassicalPropositionalLogic.Syntax
open import Functional
open import Logic.Propositional as Logic using (_←_)
open import Logic.Propositional.Theorems as Logic using ()
open import Relator.Equals.Proofs.Equiv
open import Sets.PredicateSet using (PredSet ; _∈_ ; _∉_ ; _∪_ ; _∪•_ ; _∖_ ; _⊆_ ; _⊇_ ; ∅ ; [≡]-to-[⊆] ; [≡]-to-[⊇]) renaming (•_ to singleton ; _≡_ to _≡ₛ_)
open import Type
private variable ℓₚ ℓ ℓ₁ ℓ₂ : Lvl.Level
private variable P : Type{ℓₚ}
private variable Γ Γ₁ Γ₂ : Formulas(P){ℓ}
private variable φ ψ : Formula(P)
Inconsistent : Formulas(P){ℓ} → Type
Inconsistent(Γ) = Γ ⊢ ⊥
Consistent : Formulas(P){ℓ} → Type
Consistent(Γ) = Γ ⊬ ⊥
consistency-of-[∪]ₗ : Consistent(Γ₁ ∪ Γ₂) → Consistent(Γ₁)
consistency-of-[∪]ₗ con z = con (weaken-union z)
[⊢]-derivability-inconsistency : (Γ ⊢ φ) Logic.↔ Inconsistent(Γ ∪ singleton(¬ φ))
[⊢]-derivability-inconsistency = Logic.[↔]-intro [¬]-elim ([¬]-intro-converse ∘ [¬¬]-intro)
[⊢]-derivability-consistencyᵣ : Consistent(Γ) → ((Γ ⊢ φ) → Consistent(Γ ∪ singleton(φ)))
[⊢]-derivability-consistencyᵣ con Γφ Γφ⊥ = con([⊥]-intro Γφ ([¬]-intro Γφ⊥))
[⊢]-explosion-inconsistency : (∀{φ} → (Γ ⊢ φ)) Logic.↔ Inconsistent(Γ)
[⊢]-explosion-inconsistency {Γ} = Logic.[↔]-intro (λ z → [⊥]-elim z) (λ z → z)
[⊢]-compose-inconsistency : (Γ ⊢ φ) → Inconsistent(Γ ∪ singleton(φ)) → Inconsistent(Γ)
[⊢]-compose-inconsistency Γφ Γφ⊥ = [⊥]-intro Γφ ([¬]-intro Γφ⊥)
[⊢]-compose-consistency : (Γ ⊢ φ) → Consistent(Γ) → Consistent(Γ ∪ singleton(φ))
[⊢]-compose-consistency Γφ = Logic.contrapositiveᵣ ([⊢]-compose-inconsistency Γφ)
[⊢]-subset-consistency : (Γ₁ ⊆ Γ₂) → (Consistent(Γ₂) → Consistent(Γ₁))
[⊢]-subset-consistency sub con = con ∘ weaken sub
[⊢]-subset-inconsistency : (Γ₁ ⊆ Γ₂) → (Inconsistent(Γ₁) → Inconsistent(Γ₂))
[⊢]-subset-inconsistency sub = weaken sub
[⊬]-negation-consistency : (Γ ⊬ (¬ φ)) → Consistent(Γ ∪ singleton(φ))
[⊬]-negation-consistency = _∘ [¬]-intro
[⊢]-consistent-noncontradicting-membership : Consistent(Γ) → ((¬ φ) ∈ Γ) → (φ ∈ Γ) → Logic.⊥
[⊢]-consistent-noncontradicting-membership con Γ¬φ Γφ = con([⊥]-intro (direct Γφ) (direct Γ¬φ))
|
{
"alphanum_fraction": 0.686716792,
"avg_line_length": 42.75,
"ext": "agda",
"hexsha": "9fd97605471214fc8cd6ff6cdc01cc0ddcc120ea",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Formalization/ClassicalPropositionalLogic/NaturalDeduction/Consistency.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Formalization/ClassicalPropositionalLogic/NaturalDeduction/Consistency.agda",
"max_line_length": 159,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Formalization/ClassicalPropositionalLogic/NaturalDeduction/Consistency.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 945,
"size": 2394
}
|
open import Structure.Operator.Field
open import Structure.Setoid
open import Type
-- Operators for matrices over a field.
module Numeral.Matrix.OverField {ℓ ℓₑ}{T : Type{ℓ}} ⦃ equiv : Equiv{ℓₑ}(T) ⦄ {_+ₛ_ _⋅ₛ_ : T → T → T} ⦃ field-structure : Field(_+ₛ_)(_⋅ₛ_) ⦄ where
open Field(field-structure) renaming (_−_ to _−ₛ_ ; −_ to −ₛ_ ; 𝟎 to 𝟎ₛ ; 𝟏 to 𝟏ₛ)
open import Data.Tuple as Tuple using (_,_)
open import Logic.Predicate
open import Numeral.Matrix
open import Numeral.Matrix.Proofs
open import Structure.Operator.Properties
𝟎 : ∀{s} → Matrix(s)(T)
𝟎 = fill(𝟎ₛ)
𝟏 : ∀{n} → Matrix(n , n)(T)
𝟏 = SquareMatrix.scalarMat(𝟎ₛ)(𝟏ₛ)
_+_ : ∀{s} → Matrix(s)(T) → Matrix(s)(T) → Matrix(s)(T)
_+_ = map₂(_+ₛ_)
infixr 1000 _+_
_−_ : ∀{s} → Matrix(s)(T) → Matrix(s)(T) → Matrix(s)(T)
_−_ = map₂(_−ₛ_)
infixr 1000 _−_
−_ : ∀{s} → Matrix(s)(T) → Matrix(s)(T)
−_ = map(−ₛ_)
infixr 1000 −_
_⨯_ : ∀{x y z} → Matrix(y , z)(T) → Matrix(x , y)(T) → Matrix(x , z)(T)
_⨯_ = multPattern(_+ₛ_)(_⋅ₛ_)(𝟎ₛ)
infixr 1000 _⨯_
_⁻¹ : ∀{n} → (M : Matrix(n , n)(T)) ⦃ inver : InvertibleElement(_⨯_) ⦃ [∃]-intro 𝟏 ⦃ {!matrix-multPattern-identity!} ⦄ ⦄ (M) ⦄ → Matrix(n , n)(T)
_⁻¹ _ ⦃ inver ⦄ = [∃]-witness inver
|
{
"alphanum_fraction": 0.6203703704,
"avg_line_length": 30.4615384615,
"ext": "agda",
"hexsha": "099d7c88e0a725599585edbff75ab2635112622f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Matrix/OverField.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Matrix/OverField.agda",
"max_line_length": 146,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Matrix/OverField.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 557,
"size": 1188
}
|
module Five where
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
import Data.Nat as ℕ
import Data.Nat.Properties as ℕₚ
import Data.List as List
import Data.List.Properties as Listₚ
import Data.Product as Product
open List using (List; []; _∷_; _++_)
open ℕ using (ℕ; zero; suc; _+_)
open Product using (Σ; _,_)
-- Our language consists of constants and addition
data Expr : Set where
const : ℕ → Expr
plus : Expr → Expr → Expr
-- Straightforward semantics
eval-expr : Expr → ℕ
eval-expr (const n) = n
eval-expr (plus e1 e2) = eval-expr e1 + eval-expr e2
data Instr : Set where
push : ℕ → Instr
add : Instr
Prog = List Instr
Stack = List ℕ
run : Prog → Stack → Stack
run [] s = s
run (push n ∷ p) s = run p (n ∷ s)
run (add ∷ p) (a1 ∷ a2 ∷ s) = run p (a1 + a2 ∷ s)
run (add ∷ p) s = run p s
compile : Expr → Prog
compile (const n) = push n ∷ []
compile (plus e1 e2) = compile e1 ++ compile e2 ++ add ∷ []
-- Task 2. Prove that you get the expected result when you compile and run the program.
compile-correct-split : ∀ p q s → run (p ++ q) s ≡ run q (run p s)
compile-correct-split = {!!}
compile-correct-exist : ∀ e s → Σ ℕ (λ m → run (compile e) s ≡ m ∷ s)
compile-correct-exist = {!!}
compile-correct-gen : ∀ e s → run (compile e) s ≡ run (compile e) [] ++ s
compile-correct-gen = {!!}
compile-correct : ∀ e → run (compile e) [] ≡ eval-expr e ∷ []
compile-correct = {!!}
|
{
"alphanum_fraction": 0.645229682,
"avg_line_length": 25.2678571429,
"ext": "agda",
"hexsha": "937d45853f6745a2d3aaf2ff82ede941a73dbf64",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d9359c5bfd0eaf69efe1113945d7f3145f6b2dff",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "UoG-Agda/Agda101",
"max_forks_repo_path": "Lectures/Six.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9359c5bfd0eaf69efe1113945d7f3145f6b2dff",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "UoG-Agda/Agda101",
"max_issues_repo_path": "Lectures/Six.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d9359c5bfd0eaf69efe1113945d7f3145f6b2dff",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UoG-Agda/Agda101",
"max_stars_repo_path": "Lectures/Six.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 474,
"size": 1415
}
|
open import Prelude renaming (lift to finlift) hiding (id; subst)
module Implicits.Substitutions.Lemmas.LNMetaType where
open import Implicits.Syntax.LNMetaType
open import Implicits.Substitutions.LNMetaType
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
open import Data.Vec.Properties
open import Data.Star using (Star; ε; _◅_)
open import Data.Nat.Properties
open import Data.Nat as Nat
open import Extensions.Substitution
open import Relation.Binary using (module DecTotalOrder)
open DecTotalOrder decTotalOrder using () renaming (refl to ≤-refl; trans to ≤-trans)
open import Relation.Binary.HeterogeneousEquality as H using ()
module HR = H.≅-Reasoning
typeLemmas : TermLemmas MetaType
typeLemmas = record { termSubst = typeSubst; app-var = refl ; /✶-↑✶ = Lemma./✶-↑✶ }
where
module Lemma {T₁ T₂} {lift₁ : Lift T₁ MetaType} {lift₂ : Lift T₂ MetaType} where
open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_)
open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_)
/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →
(∀ k x → (simpl (mvar x)) /✶₁ σs₁ ↑✶₁ k ≡ (simpl (mvar x)) /✶₂ σs₂ ↑✶₂ k) →
∀ k t → t /✶₁ σs₁ ↑✶₁ k ≡ t /✶₂ σs₂ ↑✶₂ k
/✶-↑✶ ρs₁ ρs₂ hyp k (simpl (mvar x)) = hyp k x
/✶-↑✶ ρs₁ ρs₂ hyp k (simpl (tvar x)) = begin
simpl (tvar x) /✶₁ ρs₁ ↑✶₁ k
≡⟨ MetaTypeApp.tvar-/✶-↑✶ _ k ρs₁ ⟩
simpl (tvar x)
≡⟨ sym $ MetaTypeApp.tvar-/✶-↑✶ _ k ρs₂ ⟩
simpl (tvar x) /✶₂ ρs₂ ↑✶₂ k ∎
/✶-↑✶ ρs₁ ρs₂ hyp k (simpl (tc c)) = begin
(simpl (tc c)) /✶₁ ρs₁ ↑✶₁ k
≡⟨ MetaTypeApp.tc-/✶-↑✶ _ k ρs₁ ⟩
(simpl (tc c))
≡⟨ sym $ MetaTypeApp.tc-/✶-↑✶ _ k ρs₂ ⟩
(simpl (tc c)) /✶₂ ρs₂ ↑✶₂ k ∎
/✶-↑✶ ρs₁ ρs₂ hyp k (simpl (a →' b)) = begin
(simpl (a →' b)) /✶₁ ρs₁ ↑✶₁ k
≡⟨ MetaTypeApp.→'-/✶-↑✶ _ k ρs₁ ⟩
simpl ((a /✶₁ ρs₁ ↑✶₁ k) →' (b /✶₁ ρs₁ ↑✶₁ k))
≡⟨ cong₂ (λ a b → simpl (a →' b)) (/✶-↑✶ ρs₁ ρs₂ hyp k a) (/✶-↑✶ ρs₁ ρs₂ hyp k b) ⟩
simpl ((a /✶₂ ρs₂ ↑✶₂ k) →' (b /✶₂ ρs₂ ↑✶₂ k))
≡⟨ sym (MetaTypeApp.→'-/✶-↑✶ _ k ρs₂) ⟩
(simpl (a →' b)) /✶₂ ρs₂ ↑✶₂ k
∎
/✶-↑✶ ρs₁ ρs₂ hyp k (a ⇒ b) = begin
(a ⇒ b) /✶₁ ρs₁ ↑✶₁ k
≡⟨ MetaTypeApp.⇒-/✶-↑✶ _ k ρs₁ ⟩ --
(a /✶₁ ρs₁ ↑✶₁ k) ⇒ (b /✶₁ ρs₁ ↑✶₁ k)
≡⟨ cong₂ _⇒_ (/✶-↑✶ ρs₁ ρs₂ hyp k a) (/✶-↑✶ ρs₁ ρs₂ hyp k b) ⟩
(a /✶₂ ρs₂ ↑✶₂ k) ⇒ (b /✶₂ ρs₂ ↑✶₂ k)
≡⟨ sym (MetaTypeApp.⇒-/✶-↑✶ _ k ρs₂) ⟩
(a ⇒ b) /✶₂ ρs₂ ↑✶₂ k
∎
/✶-↑✶ ρs₁ ρs₂ hyp k (∀' a) = begin
(∀' a) /✶₁ ρs₁ ↑✶₁ k
≡⟨ MetaTypeApp.∀'-/✶-↑✶ _ k ρs₁ ⟩
∀' (a /✶₁ ρs₁ ↑✶₁ k)
≡⟨ cong ∀' (/✶-↑✶ ρs₁ ρs₂ hyp k a) ⟩
∀' (a /✶₂ ρs₂ ↑✶₂ k)
≡⟨ sym (MetaTypeApp.∀'-/✶-↑✶ _ k ρs₂) ⟩
(∀' a) /✶₂ ρs₂ ↑✶₂ k
∎
open TermLemmas typeLemmas public hiding (var; id; _/_; _↑⋆_; wk; weaken; sub)
open AdditionalLemmas typeLemmas public
-- The above lemma /✶-↑✶ specialized to single substitutions
/-↑⋆ : ∀ {T₁ T₂} {lift₁ : Lift T₁ MetaType} {lift₂ : Lift T₂ MetaType} →
let open Lifted lift₁ using () renaming (_↑⋆_ to _↑⋆₁_; _/_ to _/₁_)
open Lifted lift₂ using () renaming (_↑⋆_ to _↑⋆₂_; _/_ to _/₂_)
in
∀ {n k} (ρ₁ : Sub T₁ n k) (ρ₂ : Sub T₂ n k) →
(∀ i x → (simpl (mvar x)) /₁ ρ₁ ↑⋆₁ i ≡ (simpl (mvar x)) /₂ ρ₂ ↑⋆₂ i) →
∀ i a → a /₁ ρ₁ ↑⋆₁ i ≡ a /₂ ρ₂ ↑⋆₂ i
/-↑⋆ ρ₁ ρ₂ hyp i a = /✶-↑✶ (ρ₁ ◅ ε) (ρ₂ ◅ ε) hyp i a
-- weakening a simple type gives a simple type
simpl-wk : ∀ {ν} k (τ : MetaSType (k N+ ν)) → ∃ λ τ' → (simpl τ) / wk ↑⋆ k ≡ simpl τ'
simpl-wk k (tc x) = , refl
simpl-wk k (mvar n) = , var-/-wk-↑⋆ k n
simpl-wk k (tvar n) = , refl
simpl-wk k (x →' x₁) = , refl
tclosed-wk : ∀ {ν m} {a : MetaType m} → TClosed ν a → TClosed (suc ν) a
tclosed-wk (a ⇒ b) = tclosed-wk a ⇒ tclosed-wk b
tclosed-wk (∀' x) = ∀' (tclosed-wk x)
tclosed-wk (simpl x) = simpl $ tclosed-wks x
where
tclosed-wks : ∀ {ν m} {τ : MetaSType m} → TClosedS ν τ → TClosedS (suc ν) τ
tclosed-wks (tvar p) = tvar (≤-steps 1 p)
tclosed-wks mvar = mvar
tclosed-wks (a →' b) = (tclosed-wk a) →' (tclosed-wk b)
tclosed-wks tc = tc
-- proper substitution doesn't affect the number of tvars
tclosed-/ : ∀ {m m' n} (a : MetaType m) {σ : Sub MetaType m m'} → TClosed n a →
(∀ i → TClosed n (lookup i σ)) → TClosed n (a / σ)
tclosed-/ (a ⇒ b) (ca ⇒ cb) f = tclosed-/ a ca f ⇒ tclosed-/ b cb f
tclosed-/ (∀' a) (∀' x) f = ∀' (tclosed-/ a x (λ p → tclosed-wk (f p)))
tclosed-/ (simpl x) (simpl y) f = tclosed-/s x y f
where
tclosed-/s : ∀ {m m' n} (a : MetaSType m) {σ : Sub MetaType m m'} → TClosedS n a →
(∀ i → TClosed n (lookup i σ)) → TClosed n (a simple/ σ)
tclosed-/s (tvar _) (tvar p) f = simpl (tvar p)
tclosed-/s (mvar i) _ f = f i
tclosed-/s (a →' b) (ca →' cb) f = simpl (tclosed-/ a ca f →' tclosed-/ b cb f)
tclosed-/s (tc c) _ _ = simpl tc
-- opening any free tvar will reduce the number of free tvars
tclosed-open : ∀ {m ν} {a : MetaType m} k → k N< (suc ν) → TClosed (suc ν) a →
TClosed ν (open-meta k a)
tclosed-open k k<ν (a ⇒ b) = (tclosed-open k k<ν a) ⇒ (tclosed-open k k<ν b)
tclosed-open k k<ν (∀' a) = ∀' (tclosed-open (suc k) (s≤s k<ν) a)
tclosed-open k k<ν (simpl (tvar {x = x} p)) with Nat.compare x k
tclosed-open .(suc (k' N+ k)) (s≤s k<ν) (simpl (tvar p)) | less k' k =
simpl (tvar (≤-trans (m≤m+n (suc k') k) k<ν))
tclosed-open x k<ν (simpl (tvar x₁)) | equal .x = simpl mvar
tclosed-open m k<ν (simpl (tvar (s≤s p))) | greater .m k = simpl (tvar p)
tclosed-open k k<ν (simpl mvar) = simpl mvar
tclosed-open k k<ν (simpl (x →' x₁)) = simpl (tclosed-open k k<ν x →' tclosed-open k k<ν x₁)
tclosed-open k k<ν (simpl tc) = simpl tc
open-meta-◁m₁ : ∀ {m k} (a : MetaType m) → (open-meta k a) ◁m₁ ≡ a ◁m₁
open-meta-◁m₁ (a ⇒ b) = open-meta-◁m₁ b
open-meta-◁m₁ (∀' a) = cong suc (open-meta-◁m₁ a)
open-meta-◁m₁ (simpl x) = refl
lem : ∀ {m} n k (a : MetaType m) → open-meta n (open-meta (n N+ suc k) a) H.≅
open-meta (n N+ k) (open-meta n a)
lem n k (a ⇒ b) = H.cong₂ _⇒_ (lem n k a) (lem n k b)
lem n k (∀' a) = H.cong ∀' (lem _ _ a)
lem n k (simpl (tvar x)) with Nat.compare x (n N+ (suc k))
lem n k (simpl (tvar x)) | z = {!z!}
lem n k (simpl (mvar x)) = H.refl
lem n k (simpl (a →' b)) = H.cong₂ (λ u v → simpl (u →' v)) (lem n k a) (lem n k b)
lem n k (simpl (tc x)) = H.refl
open-meta-◁m : ∀ {m} k (a : MetaType m) →
((open-meta k a) ◁m) H.≅ open-meta k (a ◁m)
open-meta-◁m k (a ⇒ b) = open-meta-◁m k b
open-meta-◁m k (∀' a) = HR.begin
open-meta zero ((open-meta (suc k)) a ◁m)
HR.≅⟨ {!!} ⟩
open-meta zero (open-meta (suc k) (a ◁m))
HR.≅⟨ lem zero k (a ◁m) ⟩
open-meta k (open-meta zero (a ◁m)) HR.∎
open-meta-◁m k (simpl x) = H.refl
open import Implicits.Syntax.Type
open import Implicits.Substitutions.Type as TS using ()
lem₁ : ∀ {ν} k (a : Type (k N+ suc ν)) (b : Type ν) →
(to-meta (a TS./ (TS.sub b) TS.↑⋆ k)) ≡
(open-meta k (to-meta a) / sub (to-meta b))
lem₁ k (simpl (tc x)) b = refl
lem₁ k (simpl (tvar n)) b with Nat.compare (toℕ n) k
lem₁ k (simpl (tvar n)) b | z = {!!}
lem₁ k (simpl (a →' b)) c = cong₂ (λ u v → simpl (u →' v)) (lem₁ k a c) (lem₁ k b c)
lem₁ k (a ⇒ b) c = cong₂ _⇒_ (lem₁ k a c) (lem₁ k b c)
lem₁ k (∀' a) b = cong ∀' (lem₁ (suc k) a b)
|
{
"alphanum_fraction": 0.5258985201,
"avg_line_length": 44.7810650888,
"ext": "agda",
"hexsha": "e436cd0cae78206517b89c379371384b889dc6f2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Substitutions/Lemmas/LNMetaType.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Substitutions/Lemmas/LNMetaType.agda",
"max_line_length": 102,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Substitutions/Lemmas/LNMetaType.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 3498,
"size": 7568
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Category.CartesianClosed.Locally {o ℓ e} (C : Category o ℓ e) where
open import Level using (levelOfTerm)
open import Categories.Category.CartesianClosed
open import Categories.Category.Cartesian
open import Categories.Category.Cartesian.Properties C
open import Categories.Category.Complete.Finitely C
open import Categories.Category.Slice C
open import Categories.Category.Slice.Properties C
open import Categories.Object.Product
open import Categories.Object.Exponential
open import Categories.Object.Terminal C
import Categories.Diagram.Pullback as P
import Categories.Diagram.Pullback.Properties C as Pₚ
import Categories.Morphism.Reasoning as MR
open Category C
record Locally : Set (levelOfTerm C) where
field
sliceCCC : ∀ A → CartesianClosed (Slice A)
module sliceCCC A = CartesianClosed (sliceCCC A)
pullbacks : ∀ {X A B} (f : A ⇒ X) (g : B ⇒ X) → P.Pullback C f g
pullbacks {X} f g = product⇒pullback product
where C/X = sliceCCC X
open CartesianClosed C/X using (product)
-- the slice categories also have pullbacks, because slice of slice is slice.
slice-pullbacks : ∀ {A} {B X Y : SliceObj A} (f : Slice⇒ X B) (g : Slice⇒ Y B) → P.Pullback (Slice A) f g
slice-pullbacks {A} {B} {X} {Y} f g = record
{ P = sliceobj (X.arr ∘ p.p₁)
; p₁ = slicearr refl
; p₂ = slicearr comm
; commute = p.commute
; universal = λ {Z} {h i} eq → slicearr {h = p.universal eq} (pullʳ p.p₁∘universal≈h₁ ○ Slice⇒.△ h)
; unique = λ eq₁ eq₂ → p.unique eq₁ eq₂
; p₁∘universal≈h₁ = p.p₁∘universal≈h₁
; p₂∘universal≈h₂ = p.p₂∘universal≈h₂
}
where open HomReasoning
module X = SliceObj X
module Y = SliceObj Y
module B = SliceObj B
module f = Slice⇒ f
module g = Slice⇒ g
module p = P.Pullback (pullbacks f.h g.h)
open MR C
comm : Y.arr ∘ p.p₂ ≈ X.arr ∘ p.p₁
comm = begin
Y.arr ∘ p.p₂ ≈˘⟨ g.△ ⟩∘⟨refl ⟩
(B.arr ∘ g.h) ∘ p.p₂ ≈˘⟨ pushʳ p.commute ⟩
B.arr ∘ f.h ∘ p.p₁ ≈⟨ pullˡ f.△ ⟩
X.arr ∘ p.p₁ ∎
module _ (LCCC : Locally) (t : Terminal) where
open Locally LCCC
open Terminal t
open HomReasoning
cartesian : Cartesian C
cartesian = record
{ terminal = t
; products = record
{ product = λ {A B} → Pₚ.pullback-⊤⇒product t (product⇒pullback product)
}
}
where open sliceCCC ⊤ using (product)
private
module cartesian = Cartesian cartesian
cartesianClosed : CartesianClosed C
cartesianClosed = record
{ cartesian = cartesian
; exp = λ {A B} →
let open Exponential (exp {sliceobj (! {A})} {sliceobj (! {B})})
in record
{ B^A = Y B^A
; product =
-- this is tricky. how product is implemented requires special care. for example, the following
-- code also gives a product that type checks, but it is impossible to work with.
-- Pₚ.pullback-⊤⇒product t (Pₚ.pullback-resp-≈ (product⇒pullback product) !-unique₂ refl)
--
-- another quirk of proof relevance.
let open Product (Slice ⊤) (exp.product {sliceobj (! {A})} {sliceobj (! {B})})
in record
{ A×B = Y A×B
; π₁ = h π₁
; π₂ = h π₂
; ⟨_,_⟩ = λ f g → h ⟨ slicearr {h = f} (⟺ (!-unique _)) , slicearr {h = g} (⟺ (!-unique _)) ⟩
; project₁ = project₁
; project₂ = project₂
; unique = λ eq eq′ → unique {h = slicearr (⟺ (!-unique _))} eq eq′
}
; eval = h eval
; λg = λ {X} p f → h (λg (pullback⇒product′ t (Pₚ.product⇒pullback-⊤ t p)) (lift t f))
; β = λ p → ∘-resp-≈ʳ (exp.product.⟨⟩-cong₂ refl refl) ○ β (pullback⇒product′ t (Pₚ.product⇒pullback-⊤ t p))
; λ-unique = λ p eq → λ-unique (pullback⇒product′ t (Pₚ.product⇒pullback-⊤ t p))
{h = slicearr (⟺ (!-unique _))}
(∘-resp-≈ʳ (exp.product.⟨⟩-cong₂ refl refl) ○ eq)
}
}
where open sliceCCC ⊤ using (exp)
open SliceObj
open Slice⇒
finitelyComplete : FinitelyComplete
finitelyComplete = record
{ cartesian = cartesian
; equalizer = λ f g → prods×pullbacks⇒equalizers cartesian.products
(λ {_ _ X} h i → product⇒pullback (sliceCCC.product X))
}
|
{
"alphanum_fraction": 0.5761343805,
"avg_line_length": 37.5737704918,
"ext": "agda",
"hexsha": "ec1bd4f06f72c32378e0b8e1a6b167f47e3753ec",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Category/CartesianClosed/Locally.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Category/CartesianClosed/Locally.agda",
"max_line_length": 121,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Category/CartesianClosed/Locally.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1451,
"size": 4584
}
|
{-# OPTIONS --safe #-} --without-K #-}
open import Relation.Binary.PropositionalEquality using (_≡_; refl; trans; sym; subst)
open import Function.Reasoning
import Data.Empty as Empty
import Data.Maybe as Maybe
import Data.Nat as Nat
import Data.Bool as Bool
import Data.Fin as Fin
import Data.Product as Product
import Data.Vec as Vec
import Data.Vec.Relation.Unary.All as All
import Data.Fin.Properties as Finₚ
open Empty using (⊥; ⊥-elim)
open Nat using (ℕ; zero; suc)
open Fin using (Fin ; zero ; suc)
open Vec using (Vec; []; _∷_)
open All using (All; []; _∷_)
open Product using (_×_; Σ-syntax; ∃-syntax; _,_; proj₁; proj₂)
open import PiCalculus.Syntax
open Scoped
open import PiCalculus.Semantics
open import PiCalculus.Semantics.Properties
open import PiCalculus.LinearTypeSystem.Algebras
module PiCalculus.LinearTypeSystem.SubjectReduction (Ω : Algebras) where
open Algebras Ω
open import PiCalculus.LinearTypeSystem Ω
open import PiCalculus.LinearTypeSystem.ContextLemmas Ω
open import PiCalculus.LinearTypeSystem.Framing Ω
open import PiCalculus.LinearTypeSystem.Weakening Ω
open import PiCalculus.LinearTypeSystem.Strengthening Ω
open import PiCalculus.LinearTypeSystem.Substitution Ω
open import PiCalculus.LinearTypeSystem.SubjectCongruence Ω
SubjectReduction : Set
SubjectReduction = {n : ℕ} {γ : PreCtx n} {idxs : Idxs n} {idx : Idx} {Γ Γ' Ξ : Ctx idxs}
{c : Channel n} {P Q : Scoped n}
→ maybe (Γ' ≡ Γ) (λ i → Γ' ∋[ i ] ℓ# {idx} ▹ Γ) c
→ P =[ c ]⇒ Q
→ γ ; Γ' ⊢ P ▹ Ξ
→ γ ; Γ ⊢ Q ▹ Ξ
private
variable
n : ℕ
i j : Fin n
idxs : Idxs n
P Q : Scoped n
extract-ℓ# : {Γ Ξ Δ Ψ Θ : Ctx idxs} {idx idx' : Idx}
→ Γ ∋[ i ] ℓᵢ {idx} ▹ Ξ
→ Ψ ∋[ i ] ℓₒ {idx'} ▹ Θ
→ Ξ ≔ Δ ⊗ Ψ
→ ∃[ z ] (All.lookup i Γ ≔ ℓ# ∙² z)
extract-ℓ# (zero x) (zero y) (_ , s) =
let
⁇ , Ξ≔ℓₒ∙⁇ , _ = ∙²-assoc (∙²-comm s) y
_ , Γ≔[ℓᵢℓₒ]∙⁇ , [ℓᵢℓₒ]≔ℓᵢ∙ℓₒ = ∙²-assoc⁻¹ x Ξ≔ℓₒ∙⁇
ℓ#≡ℓᵢℓₒ = ∙²-unique [ℓᵢℓₒ]≔ℓᵢ∙ℓₒ (∙-idʳ , ∙-idˡ)
in _ , subst (λ ● → _ ≔ ● ∙² ⁇) ℓ#≡ℓᵢℓₒ Γ≔[ℓᵢℓₒ]∙⁇
extract-ℓ# (suc i) (suc o) (s , _) = extract-ℓ# i o s
-- What we have: Γ' ---ℓᵢ--> Θ ---P--> Ξ ---ℓₒ--> Ψ
-- What we need: Γ' ---ℓ#--> Γ ---P--> Ψ
align : ∀ {i : Fin n} {γ : PreCtx n} {idxs : Idxs n} {Γ' Γ Ξ Θ Ψ : Ctx idxs} {idx' idx'' idx'''}
→ Γ' ∋[ i ] ℓᵢ {idx'} ▹ Θ
→ Ξ ∋[ i ] ℓₒ {idx''} ▹ Ψ
→ Γ' ∋[ i ] ℓ# {idx'''} ▹ Γ
→ γ ; Θ ⊢ P ▹ Ξ
→ γ ; Γ ⊢ P ▹ Ψ
align i o io ⊢P with ∋-≡Idx io | ∋-≡Idx i | ∋-≡Idx o
align i o io ⊢P | refl | refl | refl =
let
Δi , Γ'≔Δi∙Θ , Δi≔ℓᵢ = ∋-⊗ i
Δo , Ξ≔Δo∙Ψ , Δo≔ℓₒ = ∋-⊗ o
Δio , Γ'≔Δio∙Γ , Δio≔ℓ# = ∋-⊗ io
Δ⊢P , Θ≔Δ⊢P∙Ξ = ⊢-⊗ ⊢P
ΨΔ⊢P , Θ≔Δo∙[ΨΔ⊢P] , ΨΔ⊢P≔Ψ∙Δ⊢P = ⊗-assoc (⊗-comm Θ≔Δ⊢P∙Ξ) Ξ≔Δo∙Ψ
ΔiΔo , Γ'≔[ΔiΔo]∙[ΨΔ⊢P] , ΔiΔo≔ℓᵢℓₒ = ⊗-assoc⁻¹ Γ'≔Δi∙Θ Θ≔Δo∙[ΨΔ⊢P]
Δio≔Δi∙Δo = ∙²-⊗ Δio≔ℓ# Δi≔ℓᵢ Δo≔ℓₒ (∙-idʳ , ∙-idˡ)
ΔiΔo≡Δio = ⊗-unique ΔiΔo≔ℓᵢℓₒ Δio≔Δi∙Δo
Γ'≔Δio∙[ΨΔ⊢P] = subst (λ ● → _ ≔ ● ⊗ _) ΔiΔo≡Δio Γ'≔[ΔiΔo]∙[ΨΔ⊢P]
ΨΔ⊢P≡Γ = ⊗-uniqueˡ (⊗-comm Γ'≔Δio∙[ΨΔ⊢P]) (⊗-comm Γ'≔Δio∙Γ)
Γ≔Ψ∙Δ⊢P = subst (λ ● → ● ≔ _ ⊗ _) ΨΔ⊢P≡Γ ΨΔ⊢P≔Ψ∙Δ⊢P
in ⊢-frame Θ≔Δ⊢P∙Ξ (⊗-comm Γ≔Ψ∙Δ⊢P) ⊢P
comm-≥ℓ# : {γ : PreCtx n} {Γ Δ : Ctx idxs} {c : Channel n}
→ P =[ c ]⇒ Q → γ ; Γ ⊢ P ▹ Δ → c ≡ external i → ∃[ y ] (All.lookup i Γ ≔ ℓ# ∙² y)
comm-≥ℓ# {i = i} comm (((_ , x) ⦅⦆ ⊢P) ∥ ((_ , x') ⟨ _ ⟩ ⊢Q)) refl with ⊢-⊗ ⊢P
comm-≥ℓ# {i = i} comm (((_ , x) ⦅⦆ ⊢P) ∥ ((_ , x') ⟨ _ ⟩ ⊢Q)) refl | (_ -, _) , (Ξ≔ , _) = extract-ℓ# x x' Ξ≔
comm-≥ℓ# (par P→P') (⊢P ∥ ⊢Q) refl = comm-≥ℓ# P→P' ⊢P refl
comm-≥ℓ# (res_ {c = internal} P→Q) (ν t m μ ⊢P) ()
comm-≥ℓ# (res_ {c = external zero} P→Q) (ν t m μ ⊢P) ()
comm-≥ℓ# (res_ {c = external (suc i)} P→Q) (ν t m μ ⊢P) refl = comm-≥ℓ# P→Q ⊢P refl
comm-≥ℓ# (struct P≅P' P'→Q' P'≅Q ) ⊢P refl = comm-≥ℓ# P'→Q' (subject-cong P≅P' ⊢P) refl
subject-reduction : SubjectReduction
subject-reduction Γ'⇒Γ comm (((_⦅⦆_ {P = P} (tx , x) ⊢P)) ∥ ((tx' , x') ⟨ y ⟩ ⊢Q)) with trans (sym (∋-≡Type tx)) (∋-≡Type tx')
subject-reduction Γ'⇒Γ comm (((_⦅⦆_ {P = P} (tx , x) ⊢P)) ∥ ((tx' , x') ⟨ y ⟩ ⊢Q)) | refl = ⊢P' ∥ ⊢Q
where ⊢P' = ⊢P
|> align (suc x) (suc x') (suc Γ'⇒Γ)
|> ⊢-subst y
|> ⊢-strengthen zero (subst-unused (λ ()) P)
subject-reduction Γ'⇒Γ (par P→P') (⊢P ∥ ⊢Q) = subject-reduction Γ'⇒Γ P→P' ⊢P ∥ ⊢Q
subject-reduction {idx = idx} refl (res_ {c = internal} P→Q) (ν t m μ ⊢P)
= ν t m μ (subject-reduction {idx = idx} refl P→Q ⊢P)
subject-reduction refl (res_ {c = external zero} P→Q) (ν t m μ ⊢P)
= let (lμ' , rμ') , (ls , rs) = comm-≥ℓ# P→Q ⊢P refl
rs' = subst (λ ● → _ ≔ _ ∙ ●) (∙-uniqueˡ (∙-comm rs) (∙-comm ls)) rs
in ν t m lμ' (subject-reduction (zero (ls , rs')) P→Q ⊢P)
subject-reduction Γ'⇒Γ (res_ {c = external (suc i)} P→Q) (ν t m μ ⊢P)
= ν t m μ (subject-reduction (suc Γ'⇒Γ) P→Q ⊢P)
subject-reduction Γ'⇒Γ (struct P≅P' P'→Q' Q'≅Q) ⊢P
= subject-cong Q'≅Q (subject-reduction Γ'⇒Γ P'→Q' (subject-cong P≅P' ⊢P))
|
{
"alphanum_fraction": 0.5413579011,
"avg_line_length": 41.9579831933,
"ext": "agda",
"hexsha": "2a9eac464a745bcd955d6e9720af3201dae296b4",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T16:24:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-25T13:57:13.000Z",
"max_forks_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/typing-linear-pi",
"max_forks_repo_path": "src/PiCalculus/LinearTypeSystem/SubjectReduction.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_issues_repo_issues_event_max_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guilhermehas/typing-linear-pi",
"max_issues_repo_path": "src/PiCalculus/LinearTypeSystem/SubjectReduction.agda",
"max_line_length": 126,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/typing-linear-pi",
"max_stars_repo_path": "src/PiCalculus/LinearTypeSystem/SubjectReduction.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-14T15:18:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-02T23:32:11.000Z",
"num_tokens": 2740,
"size": 4993
}
|
{-# OPTIONS --cubical --no-import-sorts --safe --postfix-projections #-}
open import Cubical.Foundations.Everything renaming (uncurry to λ⟨,⟩_)
open import Cubical.Data.Sigma.Properties
open import Cubical.Foundations.CartesianKanOps
module Cubical.Modalities.Lex
(◯ : ∀ {ℓ} → Type ℓ → Type ℓ)
(η : ∀ {ℓ} {A : Type ℓ} → A → ◯ A)
(isModal : ∀ {ℓ} → Type ℓ → Type ℓ)
(let isModalFam = λ {ℓ ℓ′ : Level} {A : Type ℓ} (B : A → Type ℓ′) → (x : A) → isModal (B x))
(idemp : ∀ {ℓ} {A : Type ℓ} → isModal (◯ A))
(≡-modal : ∀ {ℓ} {A : Type ℓ} {x y : A} (A-mod : isModal A) → isModal (x ≡ y))
(◯-ind : ∀ {ℓ ℓ′} {A : Type ℓ} {B : ◯ A → Type ℓ′} (B-mod : isModalFam B) (f : (x : A) → B (η x)) → ([x] : ◯ A) → B [x])
(◯-ind-β : ∀ {ℓ ℓ′} {A : Type ℓ} {B : ◯ A → Type ℓ′} (B-mod : isModalFam B) (f : (x : A) → B (η x)) (x : A) → ◯-ind B-mod f (η x) ≡ f x)
(let Type◯ = λ (ℓ : Level) → Σ (Type ℓ) isModal)
(◯-lex : ∀ {ℓ} → isModal (Type◯ ℓ))
where
private
variable
ℓ ℓ′ : Level
η-at : (A : Type ℓ) → A → ◯ A
η-at _ = η
module _ where
private
variable
A : Type ℓ
B : Type ℓ′
module ◯-rec (B-mod : isModal B) (f : A → B) where
abstract
◯-rec : ◯ A → B
◯-rec = ◯-ind (λ _ → B-mod) f
◯-rec-β : (x : A) → ◯-rec (η x) ≡ f x
◯-rec-β = ◯-ind-β (λ _ → B-mod) f
open ◯-rec
module ◯-map (f : A → B) where
abstract
◯-map : ◯ A → ◯ B
◯-map = ◯-rec idemp λ x → η (f x)
◯-map-β : (x : A) → ◯-map (η x) ≡ η (f x)
◯-map-β x = ◯-rec-β idemp _ x
open ◯-rec
open ◯-map
module IsModalToUnitIsEquiv (A : Type ℓ) (A-mod : isModal A) where
abstract
inv : ◯ A → A
inv = ◯-rec A-mod λ x → x
η-retract : retract η inv
η-retract = ◯-rec-β _ _
η-section : section η inv
η-section = ◯-ind (λ _ → ≡-modal idemp) λ x i → η (η-retract x i)
η-iso : Iso A (◯ A)
Iso.fun η-iso = η
Iso.inv η-iso = inv
Iso.rightInv η-iso = η-section
Iso.leftInv η-iso = η-retract
η-is-equiv : isEquiv (η-at A)
η-is-equiv = isoToIsEquiv η-iso
abstract
unit-is-equiv-to-is-modal : {A : Type ℓ} → isEquiv (η-at A) → isModal A
unit-is-equiv-to-is-modal p = transport (cong isModal (sym (ua (η , p)))) idemp
retract-is-modal
: {A : Type ℓ} {B : Type ℓ′}
→ (A-mod : isModal A) (f : A → B) (g : B → A) (r : retract g f)
→ isModal B
retract-is-modal {A = A} {B = B} A-mod f g r =
unit-is-equiv-to-is-modal (isoToIsEquiv (iso η η-inv η-section η-retract))
where
η-inv : ◯ B → B
η-inv = f ∘ ◯-rec A-mod g
η-retract : retract η η-inv
η-retract b = cong f (◯-rec-β A-mod g b) ∙ r b
η-section : section η η-inv
η-section = ◯-ind (λ _ → ≡-modal idemp) (cong η ∘ η-retract)
module LiftFam {A : Type ℓ} (B : A → Type ℓ′) where
module M = IsModalToUnitIsEquiv (Type◯ ℓ′) ◯-lex
abstract
◯-lift-fam : ◯ A → Type◯ ℓ′
◯-lift-fam = M.inv ∘ ◯-map (λ a → ◯ (B a) , idemp)
⟨◯⟩ : ◯ A → Type ℓ′
⟨◯⟩ [a] = ◯-lift-fam [a] .fst
⟨◯⟩-modal : isModalFam ⟨◯⟩
⟨◯⟩-modal [a] = ◯-lift-fam [a] .snd
⟨◯⟩-compute : (x : A) → ⟨◯⟩ (η x) ≡ ◯ (B x)
⟨◯⟩-compute x =
⟨◯⟩ (η x)
≡⟨ cong (fst ∘ M.inv) (◯-map-β _ _) ⟩
M.inv (η (◯ (B x) , idemp)) .fst
≡⟨ cong fst (M.η-retract _) ⟩
◯ (B x) ∎
open LiftFam using (⟨◯⟩; ⟨◯⟩-modal; ⟨◯⟩-compute)
module LiftFamExtra {A : Type ℓ} {B : A → Type ℓ′} where
⟨◯⟩←◯ : ∀ {a} → ◯ (B a) → ⟨◯⟩ B (η a)
⟨◯⟩←◯ = transport (sym (⟨◯⟩-compute B _))
⟨◯⟩→◯ : ∀ {a} → ⟨◯⟩ B (η a) → ◯ (B a)
⟨◯⟩→◯ = transport (⟨◯⟩-compute B _)
⟨η⟩ : ∀ {a} → B a → ⟨◯⟩ B (η a)
⟨η⟩ = ⟨◯⟩←◯ ∘ η
abstract
⟨◯⟩→◯-section : ∀ {a} → section (⟨◯⟩→◯ {a}) ⟨◯⟩←◯
⟨◯⟩→◯-section = transport⁻Transport (sym (⟨◯⟩-compute _ _))
module Combinators where
private
variable
ℓ′′ : Level
A A′ : Type ℓ
B : A → Type ℓ′
C : Σ A B → Type ℓ′′
λ/coe⟨_⟩_ : (p : A ≡ A′) → ((x : A′) → B (coe1→0 (λ i → p i) x)) → ((x : A) → B x)
λ/coe⟨_⟩_ {B = B} p f = coe1→0 (λ i → (x : p i) → B (coei→0 (λ j → p j) i x)) f
open Combinators
module _ {A : Type ℓ} {B : A → Type ℓ′} where
abstract
Π-modal : isModalFam B → isModal ((x : A) → B x)
Π-modal B-mod = retract-is-modal idemp η-inv η retr
where
η-inv : ◯ ((x : A) → B x) → (x : A) → B x
η-inv [f] x = ◯-rec (B-mod x) (λ f → f x) [f]
retr : retract η η-inv
retr f = funExt λ x → ◯-rec-β (B-mod x) _ f
Σ-modal : isModal A → isModalFam B → isModal (Σ A B)
Σ-modal A-mod B-mod = retract-is-modal idemp η-inv η retr
where
h : ◯ (Σ A B) → A
h = ◯-rec A-mod fst
h-β : (x : Σ A B) → h (η x) ≡ fst x
h-β = ◯-rec-β A-mod fst
f : (i : I) (x : Σ A B) → B (h-β x i)
f i x = coe1→i (λ j → B (h-β x j)) i (snd x)
η-inv : ◯ (Σ A B) → Σ A B
η-inv y = h y , ◯-ind (B-mod ∘ h) (f i0) y
retr : (p : Σ A B) → η-inv (η p) ≡ p
retr p =
η-inv (η p)
≡⟨ ΣPathP (refl , ◯-ind-β _ _ _) ⟩
h (η p) , f i0 p
≡⟨ ΣPathP (h-β _ , λ i → f i p) ⟩
p ∎
module Σ-commute {A : Type ℓ} (B : A → Type ℓ′) where
open LiftFamExtra
◯Σ = ◯ (Σ A B)
module Σ◯ where
Σ◯ = Σ (◯ A) (⟨◯⟩ B)
abstract
Σ◯-modal : isModal Σ◯
Σ◯-modal = Σ-modal idemp (⟨◯⟩-modal _)
open Σ◯
η-Σ◯ : Σ A B → Σ◯
η-Σ◯ (x , y) = η x , ⟨η⟩ y
module Push where
abstract
fun : ◯Σ → Σ◯
fun = ◯-rec Σ◯-modal η-Σ◯
compute : fun ∘ η ≡ η-Σ◯
compute = funExt (◯-rec-β _ _)
module Unpush where
abstract
fun : Σ◯ → ◯Σ
fun =
λ⟨,⟩ ◯-ind (λ _ → Π-modal λ _ → idemp) λ x →
λ/coe⟨ ⟨◯⟩-compute B x ⟩ ◯-map (x ,_)
compute : fun ∘ η-Σ◯ ≡ η
compute =
funExt λ p →
fun (η-Σ◯ p)
≡⟨ funExt⁻ (◯-ind-β _ _ _) _ ⟩
transport refl (◯-map _ _)
≡⟨ transportRefl _ ⟩
◯-map _ (⟨◯⟩→◯ (⟨η⟩ _))
≡⟨ cong (◯-map _) (⟨◯⟩→◯-section _) ⟩
◯-map _ (η _)
≡⟨ ◯-map-β _ _ ⟩
η p ∎
push-unpush-compute : Push.fun ∘ Unpush.fun ∘ η-Σ◯ ≡ η-Σ◯
push-unpush-compute =
Push.fun ∘ Unpush.fun ∘ η-Σ◯
≡⟨ cong (Push.fun ∘_) Unpush.compute ⟩
Push.fun ∘ η
≡⟨ Push.compute ⟩
η-Σ◯ ∎
unpush-push-compute : Unpush.fun ∘ Push.fun ∘ η ≡ η
unpush-push-compute =
Unpush.fun ∘ Push.fun ∘ η
≡⟨ cong (Unpush.fun ∘_) Push.compute ⟩
Unpush.fun ∘ η-Σ◯
≡⟨ Unpush.compute ⟩
η ∎
is-section : section Unpush.fun Push.fun
is-section = ◯-ind (λ x → ≡-modal idemp) λ x i → unpush-push-compute i x
is-retract : retract Unpush.fun Push.fun
is-retract =
λ⟨,⟩ ◯-ind (λ _ → Π-modal λ _ → ≡-modal Σ◯-modal) λ x →
λ/coe⟨ ⟨◯⟩-compute B x ⟩
◯-ind
(λ _ → ≡-modal Σ◯-modal)
(λ y i → push-unpush-compute i (x , y))
push-sg-is-equiv : isEquiv Push.fun
push-sg-is-equiv = isoToIsEquiv (iso Push.fun Unpush.fun is-retract is-section)
isConnected : Type ℓ → Type ℓ
isConnected A = isContr (◯ A)
module FormalDiskBundle {A : Type ℓ} where
𝔻 : A → Type ℓ
𝔻 a = Σ[ x ∈ A ] η a ≡ η x
|
{
"alphanum_fraction": 0.4784319236,
"avg_line_length": 26.1654411765,
"ext": "agda",
"hexsha": "cd61ed55d6b8f4df80c0e6407311afdcb96fc8a1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Modalities/Lex.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Modalities/Lex.agda",
"max_line_length": 138,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Modalities/Lex.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3350,
"size": 7117
}
|
------------------------------------------------------------------------
-- Higher lenses, defined using the requirement that the remainder
-- function should be surjective
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
import Equality.Path as P
module Lens.Non-dependent.Higher.Surjective-remainder
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J using (_↔_)
open import Equality.Path.Isomorphisms eq hiding (univ)
open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence)
open import Function-universe equality-with-J as F
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq
open import Lens.Non-dependent eq
import Lens.Non-dependent.Higher eq as Higher
private
variable
a b : Level
A B : Set a
-- A variant of the lenses defined in Lens.Non-dependent.Higher. In
-- this definition the function called inhabited is replaced by a
-- requirement that the remainder function should be surjective.
Lens : Set a → Set b → Set (lsuc (a ⊔ b))
Lens {a = a} {b = b} A B =
∃ λ (get : A → B) →
∃ λ (R : Set (a ⊔ b)) →
∃ λ (remainder : A → R) →
Is-equivalence (λ a → remainder a , get a) ×
Surjective remainder
instance
-- The lenses defined above have getters and setters.
has-getter-and-setter :
Has-getter-and-setter (Lens {a = a} {b = b})
has-getter-and-setter = record
{ get = λ (get , _) → get
; set = λ (_ , _ , rem , equiv , _) a b →
_≃_.from Eq.⟨ _ , equiv ⟩ (rem a , b)
}
-- Higher.Lens A B is isomorphic to Lens A B.
Higher-lens↔Lens : Higher.Lens A B ↔ Lens A B
Higher-lens↔Lens {A = A} {B = B} =
Higher.Lens A B ↝⟨ Higher.Lens-as-Σ ⟩
(∃ λ (R : Set _) →
(A ≃ (R × B)) ×
(R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → Eq.≃-as-Σ ×-cong F.id) ⟩
(∃ λ (R : Set _) →
(∃ λ (f : A → R × B) → Eq.Is-equivalence f) ×
(R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → inverse Σ-assoc) ⟩
(∃ λ (R : Set _) →
∃ λ (f : A → R × B) →
Eq.Is-equivalence f ×
(R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → Σ-cong ΠΣ-comm λ _ → F.id) ⟩
(∃ λ (R : Set _) →
∃ λ (rg : (A → R) × (A → B)) →
Eq.Is-equivalence (λ a → proj₁ rg a , proj₂ rg a) ×
(R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → inverse Σ-assoc) ⟩
(∃ λ (R : Set _) →
∃ λ (remainder : A → R) →
∃ λ (get : A → B) →
Eq.Is-equivalence (λ a → remainder a , get a) ×
(R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → ∃-comm) ⟩
(∃ λ (R : Set _) →
∃ λ (get : A → B) →
∃ λ (remainder : A → R) →
Eq.Is-equivalence (λ a → remainder a , get a) ×
(R → ∥ B ∥)) ↝⟨ ∃-comm ⟩
(∃ λ (get : A → B) →
∃ λ (R : Set _) →
∃ λ (remainder : A → R) →
Eq.Is-equivalence (λ a → remainder a , get a) ×
(R → ∥ B ∥)) ↝⟨ (∃-cong λ get → ∃-cong λ R → ∃-cong λ rem → ∃-cong λ eq →
∀-cong ext λ _ → ∥∥-cong $
lemma get R rem eq _) ⟩□
(∃ λ (get : A → B) →
∃ λ (R : Set _) →
∃ λ (remainder : A → R) →
Eq.Is-equivalence (λ a → remainder a , get a) ×
Surjective remainder) □
where
lemma : ∀ _ _ _ _ _ → _
lemma = λ _ _ remainder eq r →
B ↝⟨ (inverse $ drop-⊤-right λ _ →
_⇔_.to contractible⇔↔⊤ $
singleton-contractible _) ⟩
B × Singleton r ↝⟨ Σ-assoc ⟩
(∃ λ { (_ , r′) → r′ ≡ r }) ↝⟨ (Σ-cong ×-comm λ _ → F.id) ⟩
(∃ λ { (r′ , _) → r′ ≡ r }) ↝⟨ (inverse $ Σ-cong Eq.⟨ _ , eq ⟩ λ _ → F.id) ⟩□
(∃ λ a → remainder a ≡ r) □
-- The isomorphism preserves getters and setters.
Higher-lens↔Lens-preserves-getters-and-setters :
Preserves-getters-and-setters-⇔ A B
(_↔_.logical-equivalence Higher-lens↔Lens)
Higher-lens↔Lens-preserves-getters-and-setters =
Preserves-getters-and-setters-→-↠-⇔
(_↔_.surjection Higher-lens↔Lens)
(λ _ → refl _ , refl _)
|
{
"alphanum_fraction": 0.4658072974,
"avg_line_length": 35.7578125,
"ext": "agda",
"hexsha": "42c44aa88b7df37468b66762e1e9ec648b84f68f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Saizan/dependent-lenses",
"max_forks_repo_path": "src/Lens/Non-dependent/Higher/Surjective-remainder.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Saizan/dependent-lenses",
"max_issues_repo_path": "src/Lens/Non-dependent/Higher/Surjective-remainder.agda",
"max_line_length": 118,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Saizan/dependent-lenses",
"max_stars_repo_path": "src/Lens/Non-dependent/Higher/Surjective-remainder.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1495,
"size": 4577
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Monoid where
open import Cubical.Algebra.Base public
open import Cubical.Algebra.Definitions public
open import Cubical.Algebra.Structures public using (IsMonoid; ismonoid)
open import Cubical.Algebra.Bundles public using (Monoid; mkmonoid; MonoidCarrier)
open import Cubical.Structures.Carrier public
open import Cubical.Algebra.Monoid.Properties public
open import Cubical.Algebra.Monoid.Morphism public
open import Cubical.Algebra.Monoid.MorphismProperties public hiding (isPropIsMonoid)
|
{
"alphanum_fraction": 0.8292253521,
"avg_line_length": 40.5714285714,
"ext": "agda",
"hexsha": "69014f9858e657388791406ea90b146817d2d789",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Algebra/Monoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Algebra/Monoid.agda",
"max_line_length": 84,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Algebra/Monoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 137,
"size": 568
}
|
open import Type
open import Structure.Setoid renaming (_≡_ to _≡ₑ_)
-- Finite sets represented by lists
module Data.List.Relation.Membership {ℓ ℓₑ} {T : Type{ℓ}} ⦃ equiv : Equiv{ℓₑ}(T)⦄ where
open import Data.List
open import Data.List.Relation.Quantification using (ExistsElement ; ExistsUniqueElement)
open import Functional
open import Logic
_∈_ : T → List(T) → Stmt
_∈_ = ExistsElement ∘ (_≡ₑ_)
module _∈_ where
pattern use {x}{l} px = ExistsElement.•_ {x = x}{l = l} px
pattern skip {x}{l} el = ExistsElement.⊰_ {l = l}{x = x} el
open _∈_ public
open import Relator.Sets(_∈_) public
_∈!_ : T → List(T) → Stmt
_∈!_ = ExistsUniqueElement ∘ (_≡ₑ_)
|
{
"alphanum_fraction": 0.6959152799,
"avg_line_length": 28.7391304348,
"ext": "agda",
"hexsha": "740fb0ca0aa505c04082897a14147097b080a5e5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data/List/Relation/Membership.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/List/Relation/Membership.agda",
"max_line_length": 89,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data/List/Relation/Membership.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 242,
"size": 661
}
|
module CS410-Nat where
open import CS410-Prelude
open import CS410-Monoid
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
{-# COMPILED_DATA Nat HaskellSetup.Nat HaskellSetup.Zero HaskellSetup.Suc #-}
_+N_ : Nat -> Nat -> Nat
zero +N n = n
suc m +N n = suc (m +N n)
infixr 3 _+N_
+Mon : Monoid Nat
+Mon = record
{ e = 0
; op = _+N_
; lunit = \ m -> refl
; runit = ruHelp
; assoc = asHelp
} where
ruHelp : (m : Nat) -> m +N 0 == m
ruHelp zero = refl
ruHelp (suc m) rewrite ruHelp m = refl
asHelp : (m m' m'' : Nat) -> m +N (m' +N m'') == (m +N m') +N m''
asHelp zero m' m'' = refl
asHelp (suc m) m' m'' rewrite asHelp m m' m'' = refl
_*N_ : Nat -> Nat -> Nat
zero *N n = zero
suc m *N n = m *N n +N n
infixr 4 _*N_
_N>=_ : Nat -> Nat -> Set
m N>= zero = One
zero N>= suc n = Zero
suc m N>= suc n = m N>= n
N>=Unique : (m n : Nat)(p q : m N>= n) -> p == q
N>=Unique m zero p q = refl
N>=Unique zero (suc n) () q
N>=Unique (suc m) (suc n) p q = N>=Unique m n p q
plusSucFact : (m n : Nat) -> m +N suc n == suc m +N n
plusSucFact zero n = refl
plusSucFact (suc m) n rewrite plusSucFact m n = refl
plusCommFact : (m n : Nat) -> m +N n == n +N m
plusCommFact m zero = Monoid.runit +Mon m
plusCommFact m (suc n) rewrite plusSucFact m n | plusCommFact m n = refl
|
{
"alphanum_fraction": 0.5684830633,
"avg_line_length": 25.1481481481,
"ext": "agda",
"hexsha": "914e92a34b433f371701578b414ce1113ff951e6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "clarkdm/CS410",
"max_forks_repo_path": "CS410-Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "clarkdm/CS410",
"max_issues_repo_path": "CS410-Nat.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "clarkdm/CS410",
"max_stars_repo_path": "CS410-Nat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 545,
"size": 1358
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Data.List.Any.Membership instantiated with propositional equality,
-- along with some additional definitions.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Membership.Propositional {a} {A : Set a} where
open import Data.List.Relation.Unary.Any using (Any)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; setoid; subst)
import Data.List.Membership.Setoid as SetoidMembership
------------------------------------------------------------------------
-- Re-export contents of setoid membership
open SetoidMembership (setoid A) public hiding (lose)
------------------------------------------------------------------------
-- Different members
_≢∈_ : ∀ {x y : A} {xs} → x ∈ xs → y ∈ xs → Set _
_≢∈_ x∈xs y∈xs = ∀ x≡y → subst (_∈ _) x≡y x∈xs ≢ y∈xs
------------------------------------------------------------------------
-- Other operations
lose : ∀ {p} {P : A → Set p} {x xs} → x ∈ xs → P x → Any P xs
lose = SetoidMembership.lose (setoid A) (subst _)
|
{
"alphanum_fraction": 0.4711951849,
"avg_line_length": 35.2424242424,
"ext": "agda",
"hexsha": "8ede0ee5e11818bca37375d3bca9b8bd7ff90fd7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Membership/Propositional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Membership/Propositional.agda",
"max_line_length": 81,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Membership/Propositional.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 257,
"size": 1163
}
|
{-
This is the Agda formalization of
NOTIONS OF ANONYMOUS EXISTENCE IN MARTIN-LOF TYPE THEORY
by
Nicolai Kraus, Martin Escardo, Thierry Coquand, Thorsten Altenkirch
This file stays very close to the article. Because of this, not all
proofs are given in the way that is most elegant for a formalization.
In fact, often re-ordering statements would lead to a shorter
presentation. The order that we have chosen in the article makes our
results, as we hope, understandable and gives sufficient motivation.
This file type check with Agda 2.4.2.5.
-}
module INDEX_NotionsOfAnonymousExistence where
-- We use the following library files:
open import library.Basics hiding (Type ; Σ)
open import library.types.Sigma
open import library.types.Pi
open import library.types.Bool
open import library.NType2
open import library.types.Paths
-- OUR FORMALIZATION
-- Section 1: Introduction
-- (no formalization)
-- Section 2: Preliminaries
open import Sec2preliminaries
-- Section 3: Hedberg's Theorem
open import Sec3hedberg
-- Section 4: Collapsibility implies H-Stability
open import Sec4hasConstToSplit
-- Section 5: Factorizing Weakly Constant Functions
open import Sec5factorConst
-- Section 6: Populatedness
open import Sec6populatedness
-- Section 7: Taboos and Counter-Models
open import Sec7taboos
-- Section 8: Propositional Truncation with Judgmental Computation Rule
open import Sec8judgmentalBeta
-- Section 9: Conclusion and Open Problems
-- (no formalization)
|
{
"alphanum_fraction": 0.776609724,
"avg_line_length": 25.7966101695,
"ext": "agda",
"hexsha": "6dfeaca766b9135ad6928ef22f401ee03681341c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "nicolai/anonymousExistence/INDEX_NotionsOfAnonymousExistence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "nicolai/anonymousExistence/INDEX_NotionsOfAnonymousExistence.agda",
"max_line_length": 71,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nicolaikraus/HoTT-Agda",
"max_stars_repo_path": "nicolai/anonymousExistence/INDEX_NotionsOfAnonymousExistence.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 387,
"size": 1522
}
|
{-# OPTIONS --safe --no-qualified-instances #-}
module CF.Transform.Compile.Statements where
open import Function using (_∘_)
open import Data.Unit using (⊤; tt)
open import Data.Product
open import Data.List hiding (null; [_])
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Relation.Unary
open import Relation.Unary.PredicateTransformer using (Pt)
open import Relation.Ternary.Core
open import Relation.Ternary.Structures
open import Relation.Ternary.Structures.Syntax
open import Relation.Ternary.Monad
open import CF.Syntax.DeBruijn
open import CF.Transform.Compile.Expressions
open import CF.Types
open import CF.Transform.Compile.ToJVM
open import JVM.Types
open import JVM.Compiler
open import JVM.Contexts
open import JVM.Model StackTy
open import JVM.Syntax.Values
open import JVM.Syntax.Instructions
mutual
{- Compiling statements -}
compileₛ : ∀ {ψ : StackTy} {Γ r} → Stmt r Γ → ε[ Compiler ⟦ Γ ⟧ ψ ψ Emp ]
compileₛ (asgn x e) = do
compileₑ e
code (store ⟦ x ⟧)
compileₛ (run e) = do
compileₑ e
code pop
compileₛ (block x) = do
compiler _ x
compileₛ (while e body) = do
-- condition
lcond⁺ ∙⟨ σ ⟩ lcond⁻ ← freshLabel
refl ∙⟨ σ ⟩ lcond⁻ ← attachTo lcond⁺ ⟨ ∙-idʳ ⟩ compileₑ e ⟨ Down _ # σ ⟩& lcond⁻
(↓ lend⁻) ∙⟨ σ ⟩ labels ← (✴-rotateₗ ∘ ✴-assocᵣ) ⟨$⟩ (freshLabel ⟨ Down _ # σ ⟩& lcond⁻)
(↓ lcond⁻) ∙⟨ σ ⟩ lend⁺ ← ✴-id⁻ˡ ⟨$⟩ (code (if eq lend⁻) ⟨ _ ✴ _ # σ ⟩& labels)
-- body
compileₛ body
lend⁺ ← ✴-id⁻ˡ ⟨$⟩ (code (goto lcond⁻) ⟨ Up _ # σ ⟩& lend⁺)
attach lend⁺
compileₛ (ifthenelse c e₁ e₂) = do
-- condition
compileₑ c
lthen+ ∙⟨ σ ⟩ ↓ lthen- ← freshLabel
lthen+ ← ✴-id⁻ˡ ⟨$⟩ (code (if ne lthen-) ⟨ Up _ # ∙-comm σ ⟩& lthen+)
-- else
compileₛ e₂
↓ lend- ∙⟨ σ ⟩ labels ← (✴-rotateₗ ∘ ✴-assocᵣ) ⟨$⟩ (freshLabel ⟨ Up _ # ∙-idˡ ⟩& lthen+)
-- then
lthen+ ∙⟨ σ ⟩ lend+ ← ✴-id⁻ˡ ⟨$⟩ (code (goto lend-) ⟨ _ ✴ _ # σ ⟩& labels)
lend+ ← ✴-id⁻ˡ ⟨$⟩ (attach lthen+ ⟨ Up _ # σ ⟩& lend+)
compileₛ e₁
-- label the end
attach lend+
{- Compiling blocks -}
compiler : ∀ (ψ : StackTy) {Γ r} → Block r Γ → ε[ Compiler ⟦ Γ ⟧ ψ ψ Emp ]
compiler ψ (nil) = do
return refl
compiler ψ (s ⍮⍮ b) = do
compileₛ s
compiler _ b
|
{
"alphanum_fraction": 0.6003351487,
"avg_line_length": 29.1097560976,
"ext": "agda",
"hexsha": "30c3e330b1f3272496af02f520e18a29f05f1144",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ajrouvoet/jvm.agda",
"max_forks_repo_path": "src/CF/Transform/Compile/Statements.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ajrouvoet/jvm.agda",
"max_issues_repo_path": "src/CF/Transform/Compile/Statements.agda",
"max_line_length": 102,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ajrouvoet/jvm.agda",
"max_stars_repo_path": "src/CF/Transform/Compile/Statements.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-28T21:49:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T14:07:17.000Z",
"num_tokens": 882,
"size": 2387
}
|
{- 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 Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Hash
open import LibraBFT.Base.ByteString
open import LibraBFT.Base.Encode
open import LibraBFT.Base.KVMap as KVMap
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
open import LibraBFT.Impl.Base.Types
open import Data.String using (String)
-- Defines the types that /DO NOT/ depend on an epoch config.
-- TODO-3: update types to reflect more recent version of LibraBFT. This is
-- a substantial undertaking that should probably be led by someone who can
-- access our internal implementation.
module LibraBFT.Impl.Consensus.Types.EpochIndep where
-- Below here is incremental progress towards something
-- that will eventually mirror the types in LBFT.Consensus.Types
-- that /DO NOT/ depend on the set of active authors
-- or safety rules, which we call the /EpochConfig/.
Author : Set
Author = NodeId
AccountAddress : Set
AccountAddress = Author
HashValue : Set
HashValue = Hash
TX : Set
TX = ByteString
Instant : Set
Instant = ℕ -- TODO-2: should eventually be a time stamp
-----------------
-- Information --
-----------------
record BlockInfo : Set where
constructor BlockInfo∙new
field
₋biEpoch : Epoch
₋biRound : Round
₋biId : HashValue
-- This has more fields...
open BlockInfo public
unquoteDecl biEpoch biRound biId = mkLens (quote BlockInfo)
(biEpoch ∷ biRound ∷ biId ∷ [])
postulate instance enc-BlockInfo : Encoder BlockInfo
BlockInfo-η : ∀{e1 e2 r1 r2 i1 i2} → e1 ≡ e2 → r1 ≡ r2 → i1 ≡ i2
→ BlockInfo∙new e1 r1 i1 ≡ BlockInfo∙new e2 r2 i2
BlockInfo-η refl refl refl = refl
record LedgerInfo : Set where
constructor LedgerInfo∙new
field
₋liCommitInfo : BlockInfo
₋liConsensusDataHash : HashValue
open LedgerInfo public
unquoteDecl liCommitInfo liConsensusDataHash = mkLens (quote LedgerInfo)
(liCommitInfo ∷ liConsensusDataHash ∷ [])
postulate instance enc-LedgerInfo : Encoder LedgerInfo
LedgerInfo-η : ∀ {ci1 ci2 : BlockInfo} {cdh1 cdh2 : Hash}
→ ci1 ≡ ci2
→ cdh1 ≡ cdh2
→ (LedgerInfo∙new ci1 cdh1) ≡ (LedgerInfo∙new ci2 cdh2)
LedgerInfo-η refl refl = refl
record LedgerInfoWithSignatures : Set where
constructor LedgerInfoWithSignatures∙new
field
₋liwsLedgerInfo : LedgerInfo
₋liwsSignatures : KVMap Author Signature
open LedgerInfoWithSignatures public
unquoteDecl liwsLedgerInfo liwsSignatures = mkLens (quote LedgerInfoWithSignatures)
(liwsLedgerInfo ∷ liwsSignatures ∷ [])
postulate instance enc-LedgerInfoWithSignatures : Encoder LedgerInfoWithSignatures
-------------------
-- Votes and QCs --
-------------------
record VoteData : Set where
constructor VoteData∙new
field
₋vdProposed : BlockInfo
₋vdParent : BlockInfo
open VoteData public
unquoteDecl vdProposed vdParent = mkLens (quote VoteData)
(vdProposed ∷ vdParent ∷ [])
postulate instance enc-VoteData : Encoder VoteData
VoteData-η : ∀ {pr1 par1 pr2 par2 : BlockInfo} → pr1 ≡ pr2 → par1 ≡ par2
→ (VoteData∙new pr1 par1) ≡ (VoteData∙new pr2 par2)
VoteData-η refl refl = refl
-- DESIGN NOTE: The ₋vAuthor field is included only to facilitate lookup of the public key against
-- which to verify the signature. An alternative would be to use an index into the members of the
-- epoch config, which would save message space and therefore bandwidth.
record Vote : Set where
constructor Vote∙new
field
₋vVoteData : VoteData
₋vAuthor : Author
₋vLedgerInfo : LedgerInfo
₋vSignature : Signature
₋vTimeoutSignature : Maybe Signature
open Vote public
unquoteDecl vVoteData vAuthor vLedgerInfo vSignature vTimeoutSignature = mkLens (quote Vote)
(vVoteData ∷ vAuthor ∷ vLedgerInfo ∷ vSignature ∷ vTimeoutSignature ∷ [])
postulate instance enc-Vote : Encoder Vote
vParent : Lens Vote BlockInfo
vParent = vVoteData ∙ vdParent
vProposed : Lens Vote BlockInfo
vProposed = vVoteData ∙ vdProposed
vParentId : Lens Vote Hash
vParentId = vVoteData ∙ vdParent ∙ biId
vParentRound : Lens Vote Round
vParentRound = vVoteData ∙ vdParent ∙ biRound
vProposedId : Lens Vote Hash
vProposedId = vVoteData ∙ vdProposed ∙ biId
vEpoch : Lens Vote Epoch
vEpoch = vVoteData ∙ vdProposed ∙ biEpoch
vdRound : Lens VoteData Round
vdRound = vdProposed ∙ biRound
vRound : Lens Vote Round
vRound = vVoteData ∙ vdRound
record QuorumCert : Set where
constructor QuorumCert∙new
field
₋qcVoteData : VoteData
₋qcSignedLedgerInfo : LedgerInfoWithSignatures
open QuorumCert public
unquoteDecl qcVoteData qcSignedLedgerInfo = mkLens (quote QuorumCert)
(qcVoteData ∷ qcSignedLedgerInfo ∷ [])
postulate instance enc-QuorumCert : Encoder QuorumCert
-- Because QuorumCert has an injective encoding (postulated, for now),
-- we can use it to determine equality of QuorumCerts.
_≟QC_ : (q1 q2 : QuorumCert) → Dec (q1 ≡ q2)
_≟QC_ = ≡-Encoder enc-QuorumCert
_QCBoolEq_ : QuorumCert → QuorumCert → Bool
_QCBoolEq_ q1 q2 = does (q1 ≟QC q2)
qcCertifiedBlock : Lens QuorumCert BlockInfo
qcCertifiedBlock = qcVoteData ∙ vdProposed
-- Constructs a 'vote' that was gathered in a QC.
rebuildVote : QuorumCert → Author × Signature → Vote
rebuildVote qc (α , sig)
= record { ₋vVoteData = ₋qcVoteData qc
; ₋vAuthor = α
; ₋vLedgerInfo = qc ^∙ (qcSignedLedgerInfo ∙ liwsLedgerInfo)
; ₋vSignature = sig
; ₋vTimeoutSignature = nothing -- Is this correct? The original vote may have had a
-- timeout signature, but we don't know. Does it
-- matter?
}
-- Two votes are equivalent if they are identical except they may differ on timeout signature
_≈Vote_ : (v1 v2 : Vote) → Set
v1 ≈Vote v2 = v2 ≡ record v1 { ₋vTimeoutSignature = ₋vTimeoutSignature v2 }
qcVotesKV : QuorumCert → KVMap Author Signature
qcVotesKV = ₋liwsSignatures ∘ ₋qcSignedLedgerInfo
qcVotes : QuorumCert → List (Author × Signature)
qcVotes qc = kvm-toList (qcVotesKV qc)
qcCertifies : Lens QuorumCert Hash
qcCertifies = qcVoteData ∙ vdProposed ∙ biId
qcRound : Lens QuorumCert Round
qcRound = qcVoteData ∙ vdProposed ∙ biRound
₋qcCertifies : QuorumCert → Hash
₋qcCertifies q = q ^∙ qcCertifies
₋qcRound : QuorumCert → Round
₋qcRound q = q ^∙ qcRound
------------
-- Blocks --
------------
data BlockType : Set where
Proposal : TX → Author → BlockType
NilBlock : BlockType
Genesis : BlockType
postulate instance enc-BlockType : Encoder BlockType
record BlockData : Set where
constructor BlockData∙new
field
₋bdEpoch : Epoch
₋bdRound : Round
-- QUESTION: How do we represent a block that extends the
-- genesis block, which doesn't come with a QC. Maybe the
-- genesis block has an associated QC established for the epoch?
₋bdQuorumCert : QuorumCert
₋bdBlockType : BlockType
open BlockData public
unquoteDecl bdEpoch bdRound bdQuorumCert bdBlockType = mkLens (quote BlockData)
(bdEpoch ∷ bdRound ∷ bdQuorumCert ∷ bdBlockType ∷ [])
postulate instance enc-BlockData : Encoder BlockData
bdParentId : Lens BlockData Hash
bdParentId = bdQuorumCert ∙ qcVoteData ∙ vdParent ∙ biId
-- This is the id of a block
bdBlockId : Lens BlockData Hash
bdBlockId = bdQuorumCert ∙ qcVoteData ∙ vdProposed ∙ biId
-- The signature is a Maybe to allow us to use 'nothing' as the
-- 'bSignature' when constructing a block to sign later. Also,
-- "nil" blocks are not signed because they are produced
-- independently by different validators. This is to enable
-- committing after an epoch-changing command is processed: we
-- cannot add more commands, but we need to add some quorum
-- certificates in order to commit the epoch-changing command.
record Block : Set where
constructor Block∙new
field
₋bId : HashValue
₋bBlockData : BlockData
₋bSignature : Maybe Signature
open Block public
unquoteDecl bId bBlockData bSignature = mkLens (quote Block)
(bId ∷ bBlockData ∷ bSignature ∷ [])
postulate instance enc : Encoder Block
bQuorumCert : Lens Block QuorumCert
bQuorumCert = bBlockData ∙ bdQuorumCert
bRound : Lens Block Round
bRound = bBlockData ∙ bdRound
record SyncInfo : Set where
constructor mkSyncInfo -- Bare constructor to enable pattern matching against SyncInfo; "smart"
-- constructor SyncInfo∙new is below
field
₋siHighestQuorumCert : QuorumCert
₋siHighestCommitCert : Maybe QuorumCert
-- ₋siHighestTimeoutCert : Mabe TimeoutCert -- Not used yet.
open SyncInfo public
-- Note that we do not automatically derive a lens for siHighestCommitCert;
-- it is defined manually below.
unquoteDecl siHighestQuorumCert = mkLens (quote SyncInfo)
(siHighestQuorumCert ∷ [])
postulate instance enc-SyncInfo : Encoder SyncInfo
SyncInfo∙new : QuorumCert → QuorumCert → SyncInfo
SyncInfo∙new highestQuorumCert highestCommitCert =
record { ₋siHighestQuorumCert = highestQuorumCert
; ₋siHighestCommitCert = if highestQuorumCert QCBoolEq highestCommitCert
then nothing else (just highestCommitCert) }
siHighestCommitCert : Lens SyncInfo QuorumCert
siHighestCommitCert = mkLens' (λ x → fromMaybe (x ^∙ siHighestQuorumCert) (₋siHighestCommitCert x))
(λ x si → record x { ₋siHighestCommitCert = just si })
----------------------
-- Network Messages --
----------------------
record ProposalMsg : Set where
constructor ProposalMsg∙new
field
₋pmProposal : Block
₋pmSyncInfo : SyncInfo
open ProposalMsg public
unquoteDecl pmProposal pmSyncInfo = mkLens (quote ProposalMsg)
(pmProposal ∷ pmSyncInfo ∷ [])
postulate instance enc-ProposalMsg : Encoder ProposalMsg
record VoteMsg : Set where
constructor VoteMsg∙new
field
₋vmVote : Vote
₋vmSyncInfo : SyncInfo
open VoteMsg public
unquoteDecl vmVote vmSyncInfo = mkLens (quote VoteMsg)
(vmVote ∷ vmSyncInfo ∷ [])
postulate instance enc-VoteMsg : Encoder VoteMsg
vmProposed : Lens VoteMsg BlockInfo
vmProposed = vmVote ∙ vVoteData ∙ vdProposed
vmParent : Lens VoteMsg BlockInfo
vmParent = vmVote ∙ vVoteData ∙ vdParent
-- This is a notification of a commit. It may not be explicitly included in an implementation,
-- but we need something to be able to express correctness conditions. It will
-- probably have something different in it, but will serve the purpose for now.
record CommitMsg : Set where
constructor CommitMsg∙new
field
₋cmEpoch : Epoch
₋cmAuthor : NodeId
₋cmRound : Round
₋cmCert : QuorumCert -- We assume for now that a CommitMsg contains the QuorumCert of the head of the 3-chain
₋cmSigMB : Maybe Signature
open CommitMsg public
unquoteDecl cmEpoch cmAuthor cmRound cmCert cmSigMB = mkLens (quote CommitMsg)
(cmEpoch ∷ cmAuthor ∷ cmRound ∷ cmCert ∷ cmSigMB ∷ [])
postulate instance enc-CommitMsg : Encoder CommitMsg
record LastVoteInfo : Set where
constructor LastVoteInfo∙new
field
₋lviLiDigest : HashValue
₋lviRound : Round
₋lviIsTimeout : Bool
open LastVoteInfo public
record PendingVotes : Set where
constructor PendingVotes∙new
field
₋pvLiDigestToVotes : KVMap HashValue LedgerInfoWithSignatures
-- -pvMaybePartialTC : Maybe TimeoutCertificate
₋pvAuthorToVote : KVMap Author Vote
open PendingVotes public
-- Note: this is a placeholder.
-- We are not concerned for now with executing transactions, just ordering/committing them.
-- This is outdated (see comment at top).
data StateComputeResult : Set where
stateComputeResult : StateComputeResult
record ExecutedBlock : Set where
constructor ExecutedBlock∙new
field
₋ebBlock : Block
₋ebOutput : StateComputeResult
open ExecutedBlock public
unquoteDecl ebBlock ebOutput = mkLens (quote ExecutedBlock)
(ebBlock ∷ ebOutput ∷ [])
ebId : Lens ExecutedBlock HashValue
ebId = ebBlock ∙ bId
ebQuorumCert : Lens ExecutedBlock QuorumCert
ebQuorumCert = ebBlock ∙ bQuorumCert
ebParentId : Lens ExecutedBlock HashValue
ebParentId = ebQuorumCert ∙ qcCertifiedBlock ∙ biId
ebRound : Lens ExecutedBlock Round
ebRound = ebBlock ∙ bRound
-- ------------------------------------------------------------------------------
record LinkableBlock : Set where
constructor LinkableBlock₋new
field
₋lbExecutedBlock : ExecutedBlock
-- ₋lbChildren : Set HashValue
open LinkableBlock public
unquoteDecl lbExecutedBlock = mkLens (quote LinkableBlock)
(lbExecutedBlock ∷ [])
lbId : Lens LinkableBlock HashValue
lbId = lbExecutedBlock ∙ ebId
-- ------------------------------------------------------------------------------
-- Note BlockTree and BlockStore are defined in EpochDep.agda as they depend on an EpochConfig
record SafetyData : Set where
constructor SafetyData∙new
field
:sdEpoch : Epoch
:sdLastVotedRound : Round
:sdPreferredRound : Round
:sdLastVote : Maybe Vote
open SafetyData public
unquoteDecl sdEpoch sdLastVotedRound sdPreferredRound sdLastVote =
mkLens (quote SafetyData)
(sdEpoch ∷ sdLastVotedRound ∷ sdPreferredRound ∷ sdLastVote ∷ [])
record PersistentSafetyStorage : Set where
constructor PersistentSafetyStorage∙new
field
:pssSafetyData : SafetyData
:pssAuthor : Author
-- :pssWaypoint : Waypoint
open PersistentSafetyStorage public
unquoteDecl pssSafetyData pssAuthor = mkLens (quote PersistentSafetyStorage)
(pssSafetyData ∷ pssAuthor ∷ [])
record ValidatorSigner : Set where
constructor ValidatorSigner∙new
field
:vsAuthor : AccountAddress
-- :vsPrivateKey : SK -- Note that the SystemModel doesn't
-- allow one node to examine another's
-- state, so we don't model someone being
-- able to impersonate someone else unless
-- PK is "dishonest", which models the
-- possibility that the corresponding secret
-- key may have been leaked.
open ValidatorSigner public
record ValidatorConfig : Set where
constructor ValidatorConfig∙new
field
:vcConsensusPublicKey : PK
open ValidatorConfig public
unquoteDecl vcConsensusPublicKey = mkLens (quote ValidatorConfig)
(vcConsensusPublicKey ∷ [])
record ValidatorInfo : Set where
constructor ValidatorInfo∙new
field
-- :viAccountAddress : AccountAddress
-- :viConsensusVotingPower : Int -- TODO-2: Each validator has one vote. Generalize later.
:viConfig : ValidatorConfig
open ValidatorInfo public
record ValidatorConsensusInfo : Set where
constructor ValidatorConsensusInfo∙new
field
:vciPublicKey : PK
--:vciVotingPower : U64
open ValidatorConsensusInfo public
record ValidatorVerifier : Set where
constructor ValidatorVerifier∙new
field
:vvAddressToValidatorInfo : (KVMap AccountAddress ValidatorConsensusInfo)
:vvQuorumVotingPower : ℕ -- TODO-2: see above; for now, this is QuorumSize
-- :vvTotalVotingPower : ℕ -- TODO-2: see above; for now, this is number of peers in EpochConfig
open ValidatorVerifier public
unquoteDecl vvAddressToValidatorInfo vvQuorumVotingPower = mkLens
(quote ValidatorVerifier)
(vvAddressToValidatorInfo ∷ vvQuorumVotingPower ∷ [])
record SafetyRules : Set where
constructor SafetyRules∙new
field
:srPersistentStorage : PersistentSafetyStorage
-- :srValidatorSigner : Maybe ValidatorSigner
open SafetyRules public
unquoteDecl srPersistentStorage = mkLens (quote SafetyRules)
(srPersistentStorage ∷ [])
data Output : Set where
BroadcastProposal : ProposalMsg → Output
LogErr : String → Output
-- LogInfo : InfoLog a → Output
SendVote : VoteMsg → List Author → Output
open Output public
SendVote-inj-v : ∀ {x1 x2 y1 y2} → SendVote x1 y1 ≡ SendVote x2 y2 → x1 ≡ x2
SendVote-inj-v refl = refl
SendVote-inj-si : ∀ {x1 x2 y1 y2} → SendVote x1 y1 ≡ SendVote x2 y2 → y1 ≡ y2
SendVote-inj-si refl = refl
|
{
"alphanum_fraction": 0.6748387846,
"avg_line_length": 35.7858627859,
"ext": "agda",
"hexsha": "7983b5e36a483cf62e1737cddd8e48216c0a9756",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Impl/Consensus/Types/EpochIndep.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Impl/Consensus/Types/EpochIndep.agda",
"max_line_length": 119,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Impl/Consensus/Types/EpochIndep.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4818,
"size": 17213
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some algebraic structures (not packed up with sets, operations,
-- etc.)
------------------------------------------------------------------------
-- The contents of this module should be accessed via `Algebra`, unless
-- you want to parameterise it via the equality relation.
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Rel; Setoid; IsEquivalence)
module Algebra.Structures
{a ℓ} {A : Set a} -- The underlying set
(_≈_ : Rel A ℓ) -- The underlying equality relation
where
-- The file is divided into sections depending on the arities of the
-- components of the algebraic structure.
open import Algebra.Core
open import Algebra.Definitions _≈_
import Algebra.Consequences.Setoid as Consequences
open import Data.Product using (_,_; proj₁; proj₂)
open import Level using (_⊔_)
------------------------------------------------------------------------
-- Structures with 1 binary operation
------------------------------------------------------------------------
record IsMagma (∙ : Op₂ A) : Set (a ⊔ ℓ) where
field
isEquivalence : IsEquivalence _≈_
∙-cong : Congruent₂ ∙
open IsEquivalence isEquivalence public
setoid : Setoid a ℓ
setoid = record { isEquivalence = isEquivalence }
∙-congˡ : LeftCongruent ∙
∙-congˡ y≈z = ∙-cong refl y≈z
∙-congʳ : RightCongruent ∙
∙-congʳ y≈z = ∙-cong y≈z refl
record IsSemigroup (∙ : Op₂ A) : Set (a ⊔ ℓ) where
field
isMagma : IsMagma ∙
assoc : Associative ∙
open IsMagma isMagma public
record IsBand (∙ : Op₂ A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
idem : Idempotent ∙
open IsSemigroup isSemigroup public
record IsCommutativeSemigroup (∙ : Op₂ A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
comm : Commutative ∙
open IsSemigroup isSemigroup public
record IsSemilattice (∧ : Op₂ A) : Set (a ⊔ ℓ) where
field
isBand : IsBand ∧
comm : Commutative ∧
open IsBand isBand public
renaming (∙-cong to ∧-cong; ∙-congˡ to ∧-congˡ; ∙-congʳ to ∧-congʳ)
record IsSelectiveMagma (∙ : Op₂ A) : Set (a ⊔ ℓ) where
field
isMagma : IsMagma ∙
sel : Selective ∙
open IsMagma isMagma public
------------------------------------------------------------------------
-- Structures with 1 binary operation & 1 element
------------------------------------------------------------------------
record IsMonoid (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
identity : Identity ε ∙
open IsSemigroup isSemigroup public
identityˡ : LeftIdentity ε ∙
identityˡ = proj₁ identity
identityʳ : RightIdentity ε ∙
identityʳ = proj₂ identity
record IsCommutativeMonoid (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where
field
isMonoid : IsMonoid ∙ ε
comm : Commutative ∙
open IsMonoid isMonoid public
isCommutativeSemigroup : IsCommutativeSemigroup ∙
isCommutativeSemigroup = record
{ isSemigroup = isSemigroup
; comm = comm
}
record IsIdempotentCommutativeMonoid (∙ : Op₂ A)
(ε : A) : Set (a ⊔ ℓ) where
field
isCommutativeMonoid : IsCommutativeMonoid ∙ ε
idem : Idempotent ∙
open IsCommutativeMonoid isCommutativeMonoid public
-- Idempotent commutative monoids are also known as bounded lattices.
-- Note that the BoundedLattice necessarily uses the notation inherited
-- from monoids rather than lattices.
IsBoundedLattice = IsIdempotentCommutativeMonoid
module IsBoundedLattice {∙ : Op₂ A}
{ε : A}
(isIdemCommMonoid : IsIdempotentCommutativeMonoid ∙ ε) =
IsIdempotentCommutativeMonoid isIdemCommMonoid
------------------------------------------------------------------------
-- Structures with 1 binary operation, 1 unary operation & 1 element
------------------------------------------------------------------------
record IsGroup (_∙_ : Op₂ A) (ε : A) (_⁻¹ : Op₁ A) : Set (a ⊔ ℓ) where
field
isMonoid : IsMonoid _∙_ ε
inverse : Inverse ε _⁻¹ _∙_
⁻¹-cong : Congruent₁ _⁻¹
open IsMonoid isMonoid public
infixl 6 _-_
_-_ : Op₂ A
x - y = x ∙ (y ⁻¹)
inverseˡ : LeftInverse ε _⁻¹ _∙_
inverseˡ = proj₁ inverse
inverseʳ : RightInverse ε _⁻¹ _∙_
inverseʳ = proj₂ inverse
uniqueˡ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → x ≈ (y ⁻¹)
uniqueˡ-⁻¹ = Consequences.assoc+id+invʳ⇒invˡ-unique
setoid ∙-cong assoc identity inverseʳ
uniqueʳ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → y ≈ (x ⁻¹)
uniqueʳ-⁻¹ = Consequences.assoc+id+invˡ⇒invʳ-unique
setoid ∙-cong assoc identity inverseˡ
record IsAbelianGroup (∙ : Op₂ A)
(ε : A) (⁻¹ : Op₁ A) : Set (a ⊔ ℓ) where
field
isGroup : IsGroup ∙ ε ⁻¹
comm : Commutative ∙
open IsGroup isGroup public
isCommutativeMonoid : IsCommutativeMonoid ∙ ε
isCommutativeMonoid = record
{ isMonoid = isMonoid
; comm = comm
}
open IsCommutativeMonoid isCommutativeMonoid public
using (isCommutativeSemigroup)
------------------------------------------------------------------------
-- Structures with 2 binary operations
------------------------------------------------------------------------
-- Note that `IsLattice` is not defined in terms of `IsSemilattice`
-- because the idempotence laws of ∨ and ∧ can be derived from the
-- absorption laws, which makes the corresponding "idem" fields
-- redundant. The derived idempotence laws are stated and proved in
-- `Algebra.Properties.Lattice` along with the fact that every lattice
-- consists of two semilattices.
record IsLattice (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where
field
isEquivalence : IsEquivalence _≈_
∨-comm : Commutative ∨
∨-assoc : Associative ∨
∨-cong : Congruent₂ ∨
∧-comm : Commutative ∧
∧-assoc : Associative ∧
∧-cong : Congruent₂ ∧
absorptive : Absorptive ∨ ∧
open IsEquivalence isEquivalence public
∨-absorbs-∧ : ∨ Absorbs ∧
∨-absorbs-∧ = proj₁ absorptive
∧-absorbs-∨ : ∧ Absorbs ∨
∧-absorbs-∨ = proj₂ absorptive
∧-congˡ : LeftCongruent ∧
∧-congˡ y≈z = ∧-cong refl y≈z
∧-congʳ : RightCongruent ∧
∧-congʳ y≈z = ∧-cong y≈z refl
∨-congˡ : LeftCongruent ∨
∨-congˡ y≈z = ∨-cong refl y≈z
∨-congʳ : RightCongruent ∨
∨-congʳ y≈z = ∨-cong y≈z refl
record IsDistributiveLattice (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where
field
isLattice : IsLattice ∨ ∧
∨-distribʳ-∧ : ∨ DistributesOverʳ ∧
open IsLattice isLattice public
∨-∧-distribʳ = ∨-distribʳ-∧
{-# WARNING_ON_USAGE ∨-∧-distribʳ
"Warning: ∨-∧-distribʳ was deprecated in v1.1.
Please use ∨-distribʳ-∧ instead."
#-}
------------------------------------------------------------------------
-- Structures with 2 binary operations & 1 element
------------------------------------------------------------------------
record IsNearSemiring (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where
field
+-isMonoid : IsMonoid + 0#
*-isSemigroup : IsSemigroup *
distribʳ : * DistributesOverʳ +
zeroˡ : LeftZero 0# *
open IsMonoid +-isMonoid public
renaming
( assoc to +-assoc
; ∙-cong to +-cong
; ∙-congˡ to +-congˡ
; ∙-congʳ to +-congʳ
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
)
open IsSemigroup *-isSemigroup public
using ()
renaming
( assoc to *-assoc
; ∙-cong to *-cong
; ∙-congˡ to *-congˡ
; ∙-congʳ to *-congʳ
; isMagma to *-isMagma
)
record IsSemiringWithoutOne (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where
field
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isSemigroup : IsSemigroup *
distrib : * DistributesOver +
zero : Zero 0# *
open IsCommutativeMonoid +-isCommutativeMonoid public
using ()
renaming
( comm to +-comm
; isMonoid to +-isMonoid
; isCommutativeSemigroup to +-isCommutativeSemigroup
)
zeroˡ : LeftZero 0# *
zeroˡ = proj₁ zero
zeroʳ : RightZero 0# *
zeroʳ = proj₂ zero
isNearSemiring : IsNearSemiring + * 0#
isNearSemiring = record
{ +-isMonoid = +-isMonoid
; *-isSemigroup = *-isSemigroup
; distribʳ = proj₂ distrib
; zeroˡ = zeroˡ
}
open IsNearSemiring isNearSemiring public
hiding (+-isMonoid; zeroˡ)
record IsCommutativeSemiringWithoutOne
(+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where
field
isSemiringWithoutOne : IsSemiringWithoutOne + * 0#
*-comm : Commutative *
open IsSemiringWithoutOne isSemiringWithoutOne public
------------------------------------------------------------------------
-- Structures with 2 binary operations & 2 elements
------------------------------------------------------------------------
record IsSemiringWithoutAnnihilatingZero (+ * : Op₂ A)
(0# 1# : A) : Set (a ⊔ ℓ) where
field
-- Note that these structures do have an additive unit, but this
-- unit does not necessarily annihilate multiplication.
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isMonoid : IsMonoid * 1#
distrib : * DistributesOver +
distribˡ : * DistributesOverˡ +
distribˡ = proj₁ distrib
distribʳ : * DistributesOverʳ +
distribʳ = proj₂ distrib
open IsCommutativeMonoid +-isCommutativeMonoid public
renaming
( assoc to +-assoc
; ∙-cong to +-cong
; ∙-congˡ to +-congˡ
; ∙-congʳ to +-congʳ
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; comm to +-comm
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
; isMonoid to +-isMonoid
; isCommutativeSemigroup to +-isCommutativeSemigroup
)
open IsMonoid *-isMonoid public
using ()
renaming
( assoc to *-assoc
; ∙-cong to *-cong
; ∙-congˡ to *-congˡ
; ∙-congʳ to *-congʳ
; identity to *-identity
; identityˡ to *-identityˡ
; identityʳ to *-identityʳ
; isMagma to *-isMagma
; isSemigroup to *-isSemigroup
)
record IsSemiring (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
isSemiringWithoutAnnihilatingZero :
IsSemiringWithoutAnnihilatingZero + * 0# 1#
zero : Zero 0# *
open IsSemiringWithoutAnnihilatingZero
isSemiringWithoutAnnihilatingZero public
isSemiringWithoutOne : IsSemiringWithoutOne + * 0#
isSemiringWithoutOne = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isSemigroup = *-isSemigroup
; distrib = distrib
; zero = zero
}
open IsSemiringWithoutOne isSemiringWithoutOne public
using
( isNearSemiring
; zeroˡ
; zeroʳ
)
record IsCommutativeSemiring (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
isSemiring : IsSemiring + * 0# 1#
*-comm : Commutative *
open IsSemiring isSemiring public
isCommutativeSemiringWithoutOne :
IsCommutativeSemiringWithoutOne + * 0#
isCommutativeSemiringWithoutOne = record
{ isSemiringWithoutOne = isSemiringWithoutOne
; *-comm = *-comm
}
*-isCommutativeSemigroup : IsCommutativeSemigroup *
*-isCommutativeSemigroup = record
{ isSemigroup = *-isSemigroup
; comm = *-comm
}
*-isCommutativeMonoid : IsCommutativeMonoid * 1#
*-isCommutativeMonoid = record
{ isMonoid = *-isMonoid
; comm = *-comm
}
------------------------------------------------------------------------
-- Structures with 2 binary operations, 1 unary operation & 2 elements
------------------------------------------------------------------------
record IsRing (+ * : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
+-isAbelianGroup : IsAbelianGroup + 0# -_
*-isMonoid : IsMonoid * 1#
distrib : * DistributesOver +
zero : Zero 0# *
open IsAbelianGroup +-isAbelianGroup public
renaming
( assoc to +-assoc
; ∙-cong to +-cong
; ∙-congˡ to +-congˡ
; ∙-congʳ to +-congʳ
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; inverse to -‿inverse
; inverseˡ to -‿inverseˡ
; inverseʳ to -‿inverseʳ
; ⁻¹-cong to -‿cong
; comm to +-comm
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
; isMonoid to +-isMonoid
; isCommutativeMonoid to +-isCommutativeMonoid
; isCommutativeSemigroup to +-isCommutativeSemigroup
; isGroup to +-isGroup
)
open IsMonoid *-isMonoid public
using ()
renaming
( assoc to *-assoc
; ∙-cong to *-cong
; ∙-congˡ to *-congˡ
; ∙-congʳ to *-congʳ
; identity to *-identity
; identityˡ to *-identityˡ
; identityʳ to *-identityʳ
; isMagma to *-isMagma
; isSemigroup to *-isSemigroup
)
zeroˡ : LeftZero 0# *
zeroˡ = proj₁ zero
zeroʳ : RightZero 0# *
zeroʳ = proj₂ zero
isSemiringWithoutAnnihilatingZero
: IsSemiringWithoutAnnihilatingZero + * 0# 1#
isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isMonoid = *-isMonoid
; distrib = distrib
}
isSemiring : IsSemiring + * 0# 1#
isSemiring = record
{ isSemiringWithoutAnnihilatingZero =
isSemiringWithoutAnnihilatingZero
; zero = zero
}
open IsSemiring isSemiring public
using (distribˡ; distribʳ; isNearSemiring; isSemiringWithoutOne)
record IsCommutativeRing
(+ * : Op₂ A) (- : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
isRing : IsRing + * - 0# 1#
*-comm : Commutative *
open IsRing isRing public
*-isCommutativeMonoid : IsCommutativeMonoid * 1#
*-isCommutativeMonoid = record
{ isMonoid = *-isMonoid
; comm = *-comm
}
isCommutativeSemiring : IsCommutativeSemiring + * 0# 1#
isCommutativeSemiring = record
{ isSemiring = isSemiring
; *-comm = *-comm
}
open IsCommutativeSemiring isCommutativeSemiring public
using ( isCommutativeSemiringWithoutOne )
record IsBooleanAlgebra
(∨ ∧ : Op₂ A) (¬ : Op₁ A) (⊤ ⊥ : A) : Set (a ⊔ ℓ) where
field
isDistributiveLattice : IsDistributiveLattice ∨ ∧
∨-complementʳ : RightInverse ⊤ ¬ ∨
∧-complementʳ : RightInverse ⊥ ¬ ∧
¬-cong : Congruent₁ ¬
open IsDistributiveLattice isDistributiveLattice public
|
{
"alphanum_fraction": 0.5615206612,
"avg_line_length": 28.3771106942,
"ext": "agda",
"hexsha": "11341ab0bffb1cc5431e8933d5ddfc3cb330550e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Algebra/Structures.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Algebra/Structures.agda",
"max_line_length": 80,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/Structures.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 4863,
"size": 15125
}
|
------------------------------------------------------------------------
-- A variant of weak bisimilarity that can be used to relate the
-- number of steps in two computations
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude hiding (_+_; _*_)
module Delay-monad.Quantitative-weak-bisimilarity {a} {A : Type a} where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude.Size
open import Conat equality-with-J as Conat
using (Conat; zero; suc; force; ⌜_⌝; _+_; _*_;
[_]_≤_; step-≤; step-∼≤; _∎≤; step-∼; _∎∼)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import Delay-monad
open import Delay-monad.Bisimilarity as B
using (now; later; laterˡ; laterʳ; force)
------------------------------------------------------------------------
-- The relation
mutual
-- Quantitative weak bisimilarity. [ ∞ ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y
-- is a variant of x B.≈ y for which the number of later
-- constructors in x is bounded by nˡ plus 1 + mˡ times the number
-- of later constructors in y, and the number of later constructors
-- in y is bounded by nʳ plus 1 + mʳ times the number of later
-- constructors in x (see ≈⇔≈×steps≤steps² below).
infix 4 [_∣_∣_∣_∣_]_≈_ [_∣_∣_∣_∣_]_≈′_
data [_∣_∣_∣_∣_]_≈_
(i : Size) (mˡ mʳ : Conat ∞) :
Conat ∞ → Conat ∞ → Delay A ∞ → Delay A ∞ → Type a where
now : ∀ {x nˡ nʳ} → [ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] now x ≈ now x
later : ∀ {x y nˡ nʳ} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ + mˡ ∣ nʳ + mʳ ] x .force ≈′ y .force →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] later x ≈ later y
laterˡ : ∀ {x y nˡ nʳ} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ .force ∣ nʳ ] x .force ≈ y →
[ i ∣ mˡ ∣ mʳ ∣ suc nˡ ∣ nʳ ] later x ≈ y
laterʳ : ∀ {x y nˡ nʳ} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ .force ] x ≈ y .force →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ suc nʳ ] x ≈ later y
record [_∣_∣_∣_∣_]_≈′_
(i : Size) (mˡ mʳ nˡ nʳ : Conat ∞)
(x y : Delay A ∞) : Type a where
coinductive
field
force : {j : Size< i} → [ j ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y
open [_∣_∣_∣_∣_]_≈′_ public
-- Specialised variants of [_∣_∣_∣_∣_]_≈_ and [_∣_∣_∣_∣_]_≈′_.
infix 4 [_∣_∣_]_≈_ [_∣_∣_]_≈′_
[_∣_∣_]_≈_ : Size → Conat ∞ → Conat ∞ → Delay A ∞ → Delay A ∞ → Type a
[ i ∣ mˡ ∣ mʳ ] x ≈ y = [ i ∣ mˡ ∣ mʳ ∣ zero ∣ zero ] x ≈ y
[_∣_∣_]_≈′_ : Size → Conat ∞ → Conat ∞ → Delay A ∞ → Delay A ∞ → Type a
[ i ∣ mˡ ∣ mʳ ] x ≈′ y = [ i ∣ mˡ ∣ mʳ ∣ zero ∣ zero ] x ≈′ y
-- Quantitative expansion.
infix 4 [_∣_∣_]_≳_ [_∣_∣_]_≳′_ [_∣_]_≳_ [_∣_]_≳′_
[_∣_∣_]_≳_ : Size → Conat ∞ → Conat ∞ → Delay A ∞ → Delay A ∞ → Type a
[ i ∣ m ∣ n ] x ≳ y = [ i ∣ m ∣ zero ∣ n ∣ zero ] x ≈ y
[_∣_∣_]_≳′_ : Size → Conat ∞ → Conat ∞ → Delay A ∞ → Delay A ∞ → Type a
[ i ∣ m ∣ n ] x ≳′ y = [ i ∣ m ∣ zero ∣ n ∣ zero ] x ≈′ y
[_∣_]_≳_ : Size → Conat ∞ → Delay A ∞ → Delay A ∞ → Type a
[ i ∣ m ] x ≳ y = [ i ∣ m ∣ zero ] x ≳ y
[_∣_]_≳′_ : Size → Conat ∞ → Delay A ∞ → Delay A ∞ → Type a
[ i ∣ m ] x ≳′ y = [ i ∣ m ∣ zero ] x ≳′ y
-- The converse of quantitative expansion.
infix 4 [_∣_∣_]_≲_ [_∣_∣_]_≲′_ [_∣_]_≲_ [_∣_]_≲′_
[_∣_∣_]_≲_ : Size → Conat ∞ → Conat ∞ → Delay A ∞ → Delay A ∞ → Type a
[ i ∣ m ∣ n ] x ≲ y = [ i ∣ m ∣ n ] y ≳ x
[_∣_∣_]_≲′_ : Size → Conat ∞ → Conat ∞ → Delay A ∞ → Delay A ∞ → Type a
[ i ∣ m ∣ n ] x ≲′ y = [ i ∣ m ∣ n ] y ≳′ x
[_∣_]_≲_ : Size → Conat ∞ → Delay A ∞ → Delay A ∞ → Type a
[ i ∣ m ] x ≲ y = [ i ∣ m ] y ≳ x
[_∣_]_≲′_ : Size → Conat ∞ → Delay A ∞ → Delay A ∞ → Type a
[ i ∣ m ] x ≲′ y = [ i ∣ m ] y ≳′ x
------------------------------------------------------------------------
-- Conversions
-- Weakening.
weaken :
∀ {i mˡ mˡ′ mʳ mʳ′ nˡ nˡ′ nʳ nʳ′ x y} →
[ ∞ ] mˡ ≤ mˡ′ → [ ∞ ] mʳ ≤ mʳ′ →
[ ∞ ] nˡ ≤ nˡ′ → [ ∞ ] nʳ ≤ nʳ′ →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y →
[ i ∣ mˡ′ ∣ mʳ′ ∣ nˡ′ ∣ nʳ′ ] x ≈ y
weaken pˡ pʳ = λ where
qˡ qʳ now → now
(suc qˡ) qʳ (laterˡ r) → laterˡ (weaken pˡ pʳ (qˡ .force) qʳ r)
qˡ (suc qʳ) (laterʳ r) → laterʳ (weaken pˡ pʳ qˡ (qʳ .force) r)
qˡ qʳ (later r) → later λ { .force →
weaken pˡ pʳ
(qˡ Conat.+-mono pˡ)
(qʳ Conat.+-mono pʳ)
(r .force) }
weakenˡʳ :
∀ {i mˡ mʳ nˡ nˡ′ nʳ nʳ′ x y} →
[ ∞ ] nˡ ≤ nˡ′ → [ ∞ ] nʳ ≤ nʳ′ →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y →
[ i ∣ mˡ ∣ mʳ ∣ nˡ′ ∣ nʳ′ ] x ≈ y
weakenˡʳ = weaken (_ ∎≤) (_ ∎≤)
weakenˡ :
∀ {i mˡ mʳ nˡ nˡ′ nʳ x y} →
[ ∞ ] nˡ ≤ nˡ′ →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y →
[ i ∣ mˡ ∣ mʳ ∣ nˡ′ ∣ nʳ ] x ≈ y
weakenˡ p = weakenˡʳ p (_ ∎≤)
weakenʳ :
∀ {i mˡ mʳ nˡ nʳ nʳ′ x y} →
[ ∞ ] nʳ ≤ nʳ′ →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ′ ] x ≈ y
weakenʳ p = weakenˡʳ (_ ∎≤) p
-- Strong bisimilarity is contained in quantitative weak bisimilarity.
∼→≈ : ∀ {i mˡ mʳ nˡ nʳ x y} →
B.[ i ] x ∼ y → [ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y
∼→≈ now = now
∼→≈ (later p) = later λ { .force → ∼→≈ (p .force) }
-- Quantitative expansion is contained in expansion.
≳→≳ : ∀ {i m n x y} →
[ i ∣ m ∣ n ] x ≳ y → B.[ i ] x ≳ y
≳→≳ now = now
≳→≳ (later p) = later λ { .force → ≳→≳ (p .force) }
≳→≳ (laterˡ p) = laterˡ (≳→≳ p)
-- Quantitative weak bisimilarity is contained in weak bisimilarity.
≈→≈ : ∀ {i mˡ mʳ nˡ nʳ x y} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y → B.[ i ] x ≈ y
≈→≈ now = now
≈→≈ (later p) = later λ { .force → ≈→≈ (p .force) }
≈→≈ (laterˡ p) = laterˡ (≈→≈ p)
≈→≈ (laterʳ p) = laterʳ (≈→≈ p)
-- In some cases expansion is contained in quantitative expansion.
≳→≳-steps :
∀ {m x y i} → B.[ i ] x ≳ y → [ i ∣ m ∣ steps x ] x ≳ y
≳→≳-steps now = now
≳→≳-steps (laterˡ p) = laterˡ (≳→≳-steps p)
≳→≳-steps {m} (later {x = x} p) = later λ { .force →
weakenˡ lemma (≳→≳-steps (p .force)) }
where
lemma =
steps (x .force) ≤⟨ Conat.≤suc ⟩
steps (later x) ≤⟨ Conat.m≤m+n ⟩
steps (later x) + m ∎≤
-- In some cases weak bisimilarity is contained in quantitative weak
-- bisimilarity.
≈→≈-steps :
∀ {mˡ mʳ x y i} →
B.[ i ] x ≈ y → [ i ∣ mˡ ∣ mʳ ∣ steps x ∣ steps y ] x ≈ y
≈→≈-steps now = now
≈→≈-steps (laterˡ p) = laterˡ (≈→≈-steps p)
≈→≈-steps (laterʳ p) = laterʳ (≈→≈-steps p)
≈→≈-steps {mˡ} {mʳ} (later {x = x} {y = y} p) = later λ { .force →
weakenˡʳ x-lemma y-lemma (≈→≈-steps (p .force)) }
where
x-lemma =
steps (x .force) ≤⟨ Conat.≤suc ⟩
steps (later x) ≤⟨ Conat.m≤m+n ⟩
steps (later x) + mˡ ∎≤
y-lemma =
steps (y .force) ≤⟨ Conat.≤suc ⟩
steps (later y) ≤⟨ Conat.m≤m+n ⟩
steps (later y) + mʳ ∎≤
-- In some cases quantitative weak bisimilarity is contained in strong
-- bisimilarity.
never≈→∼ :
∀ {i mˡ mʳ nˡ nʳ x} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] never ≈ x → B.[ i ] never ∼ x
never≈→∼ (later p) = later λ { .force → never≈→∼ (p .force) }
never≈→∼ (laterˡ p) = never≈→∼ p
never≈→∼ (laterʳ p) = later λ { .force → never≈→∼ p }
≈never→∼ :
∀ {i mˡ mʳ nˡ nʳ x} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ never → B.[ i ] x ∼ never
≈never→∼ (later p) = later λ { .force → ≈never→∼ (p .force) }
≈never→∼ (laterˡ p) = later λ { .force → ≈never→∼ p }
≈never→∼ (laterʳ p) = ≈never→∼ p
≈→∼ : ∀ {i x y} → [ i ∣ zero ∣ zero ] x ≈ y → B.[ i ] x ∼ y
≈→∼ now = now
≈→∼ (later p) = later λ { .force → ≈→∼ (p .force) }
------------------------------------------------------------------------
-- Reflexivity, symmetry/antisymmetry, transitivity
-- Quantitative weak bisimilarity is reflexive.
reflexive-≈ : ∀ {i mˡ mʳ nˡ nʳ} x → [ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ x
reflexive-≈ (now _) = now
reflexive-≈ (later x) = later λ { .force → reflexive-≈ (x .force) }
-- Quantitative weak bisimilarity is symmetric (in a certain sense).
symmetric-≈ :
∀ {i mˡ mʳ nˡ nʳ x y} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y →
[ i ∣ mʳ ∣ mˡ ∣ nʳ ∣ nˡ ] y ≈ x
symmetric-≈ now = now
symmetric-≈ (later p) = later λ { .force → symmetric-≈ (p .force) }
symmetric-≈ (laterˡ p) = laterʳ (symmetric-≈ p)
symmetric-≈ (laterʳ p) = laterˡ (symmetric-≈ p)
-- Four variants of transitivity.
transitive-≳∼ :
∀ {i m n x y z} →
[ i ∣ m ∣ n ] x ≳ y → B.[ i ] y ∼ z → [ i ∣ m ∣ n ] x ≳ z
transitive-≳∼ = λ where
now now → now
(laterˡ p) q → laterˡ (transitive-≳∼ p q)
(later p) (later q) → later λ { .force →
transitive-≳∼ (p .force) (q .force) }
transitive-∼≲ :
∀ {i m n x y z} →
B.[ i ] x ∼ y → [ i ∣ m ∣ n ] y ≲ z → [ i ∣ m ∣ n ] x ≲ z
transitive-∼≲ p q = transitive-≳∼ q (B.symmetric p)
transitive-≈∼ :
∀ {i mˡ mʳ nˡ nʳ x y z} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y → y B.∼ z →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ z
transitive-≈∼ = λ where
now now → now
(later p) (later q) → later λ { .force →
transitive-≈∼ (p .force) (q .force) }
(laterˡ p) q → laterˡ (transitive-≈∼ p q)
(laterʳ p) (later q) → laterʳ (transitive-≈∼ p (q .force))
transitive-∼≈ :
∀ {i mˡ mʳ nˡ nʳ x y z} →
x B.∼ y → [ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] y ≈ z →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ z
transitive-∼≈ = λ where
now now → now
(later p) (later q) → later λ { .force →
transitive-∼≈ (p .force) (q .force) }
(later p) (laterˡ q) → laterˡ (transitive-∼≈ (p .force) q)
p (laterʳ q) → laterʳ (transitive-∼≈ p q)
-- Equational reasoning combinators.
infix -1 _∎ˢ
infixr -2 step-∼≈ˢ step-≳∼ˢ step-≈∼ˢ _≳⟨⟩ˢ_ step-≡≈ˢ _∼⟨⟩ˢ_
_∎ˢ : ∀ {i mˡ mʳ nˡ nʳ} x → [ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ x
_∎ˢ = reflexive-≈
step-∼≈ˢ : ∀ {i mˡ mʳ nˡ nʳ} x {y z} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] y ≈ z → x B.∼ y →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ z
step-∼≈ˢ _ y≈z x∼y = transitive-∼≈ x∼y y≈z
syntax step-∼≈ˢ x y≈z x∼y = x ∼⟨ x∼y ⟩ˢ y≈z
step-≳∼ˢ : ∀ {i m n} x {y z} →
B.[ i ] y ∼ z → [ i ∣ m ∣ n ] x ≳ y →
[ i ∣ m ∣ n ] x ≳ z
step-≳∼ˢ _ y∼z x≳y = transitive-≳∼ x≳y y∼z
syntax step-≳∼ˢ x y∼z x≳y = x ≳⟨ x≳y ⟩ˢ y∼z
step-≈∼ˢ : ∀ {i mˡ mʳ nˡ nʳ} x {y z} →
y B.∼ z → [ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ z
step-≈∼ˢ _ y∼z x≈y = transitive-≈∼ x≈y y∼z
syntax step-≈∼ˢ x y∼z x≈y = x ≈⟨ x≈y ⟩ˢ y∼z
_≳⟨⟩ˢ_ : ∀ {i mˡ mʳ nˡ nʳ} x {y} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] drop-later x ≈ y →
[ i ∣ mˡ ∣ mʳ ∣ ⌜ 1 ⌝ + nˡ ∣ nʳ ] x ≈ y
now _ ≳⟨⟩ˢ p = weakenˡ Conat.≤suc p
later _ ≳⟨⟩ˢ p = laterˡ p
step-≡≈ˢ : ∀ {i mˡ mʳ nˡ nʳ} x {y z} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] y ≈ z → x ≡ y →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ z
step-≡≈ˢ _ y≈z refl = y≈z
syntax step-≡≈ˢ x y≈z x≡y = x ≡⟨ x≡y ⟩ˢ y≈z
_∼⟨⟩ˢ_ : ∀ {i mˡ mʳ nˡ nʳ} x {y} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y
_ ∼⟨⟩ˢ x≈y = x≈y
------------------------------------------------------------------------
-- Some results related to the steps function
-- If y is a quantitative expansion of x, then it contains at least as
-- many later constructors as x.
steps-mono :
∀ {i m n x y} → [ i ∣ m ∣ n ] x ≲ y → [ i ] steps x ≤ steps y
steps-mono = B.steps-mono ∘ ≳→≳
-- If [ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y holds, then the number of later
-- constructors in x is bounded by nˡ plus 1 + mˡ times the number of
-- later constructors in y.
steps-+-*ʳ :
∀ {mˡ mʳ nˡ nʳ i x y} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y →
[ i ] steps x ≤ nˡ + (⌜ 1 ⌝ + mˡ) * steps y
steps-+-*ʳ {mˡ} {mʳ} {nˡ} {nʳ} = λ where
now → zero
(later {x = x} {y = y} p) →
steps (later x) ∼⟨ suc (λ { .force → _ ∎∼ }) ⟩≤
suc (λ { .force → steps (x .force) }) ≤⟨ suc (λ { .force → steps-+-*ʳ (p .force) }) ⟩
suc (λ { .force → nˡ + mˡ + (⌜ 1 ⌝ + mˡ) * steps (y .force) }) ∼⟨ suc (λ { .force → Conat.symmetric-∼ (Conat.+-assoc nˡ) }) ⟩≤
⌜ 1 ⌝ + nˡ + (mˡ + (⌜ 1 ⌝ + mˡ) * steps (y .force)) ∼⟨ Conat.suc+∼+suc ⟩≤
nˡ + ((⌜ 1 ⌝ + mˡ) + (⌜ 1 ⌝ + mˡ) * steps (y .force)) ∼⟨ (nˡ ∎∼) Conat.+-cong Conat.symmetric-∼ Conat.*suc∼+* ⟩≤
nˡ + (⌜ 1 ⌝ + mˡ) * steps (later y) ∎≤
(laterˡ {x = x} {y = y} {nˡ = nˡ} p) →
steps (later x) ∼⟨ suc (λ { .force → _ ∎∼ }) ⟩≤
⌜ 1 ⌝ + steps (x .force) ≤⟨ (_ Conat.∎≤) Conat.+-mono steps-+-*ʳ p ⟩
⌜ 1 ⌝ + (nˡ .force + (⌜ 1 ⌝ + mˡ) * steps y) ∼⟨ suc (λ { .force → _ ∎∼ }) ⟩≤
suc nˡ + (⌜ 1 ⌝ + mˡ) * steps y ∎≤
(laterʳ {x = x} {y = y} {nʳ = nʳ} p) →
steps x ≤⟨ steps-+-*ʳ p ⟩
nˡ + (⌜ 1 ⌝ + mˡ) * steps (y .force) ≤⟨ (nˡ ∎≤) Conat.+-mono Conat.m≤n+m ⟩
nˡ + ((⌜ 1 ⌝ + mˡ) + (⌜ 1 ⌝ + mˡ) * steps (y .force)) ∼⟨ (nˡ ∎∼) Conat.+-cong Conat.symmetric-∼ Conat.*suc∼+* ⟩≤
nˡ + (⌜ 1 ⌝ + mˡ) * steps (later y) ∎≤
-- If [ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y holds, then the number of later
-- constructors in y is bounded by nʳ plus 1 + mʳ times the number of
-- later constructors in x.
steps-+-*ˡ :
∀ {mˡ mʳ nˡ nʳ i x y} →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y →
[ i ] steps y ≤ nʳ + (⌜ 1 ⌝ + mʳ) * steps x
steps-+-*ˡ = steps-+-*ʳ ∘ symmetric-≈
-- [ ∞ ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y holds iff x and y are weakly
-- bisimilar and the number of later constructors in x and y are
-- related in a certain way.
≈⇔≈×steps≤steps² :
∀ {mˡ mʳ nˡ nʳ x y} →
[ ∞ ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y ⇔
x B.≈ y ×
[ ∞ ] steps x ≤ nˡ + (⌜ 1 ⌝ + mˡ) * steps y ×
[ ∞ ] steps y ≤ nʳ + (⌜ 1 ⌝ + mʳ) * steps x
≈⇔≈×steps≤steps² {mˡ} {mʳ} {x = x} {y} = record
{ to = λ p → ≈→≈ p , steps-+-*ʳ p , steps-+-*ˡ p
; from = λ { (p , q , r) → from p q r }
}
where
from-lemma :
∀ {m n} {x y : Delay′ A ∞} {i} {j : Size< i} →
[ i ] steps (later x) ≤ n + (⌜ 1 ⌝ + m) * steps (later y) →
[ j ] steps (x .force) ≤ n + m + (⌜ 1 ⌝ + m) * steps (y .force)
from-lemma {m} {n} {x} {y} hyp = Conat.cancel-suc-≤ lemma .force
where
lemma =
⌜ 1 ⌝ + steps (x .force) ∼⟨ suc (λ { .force → _ ∎∼ }) ⟩≤
steps (later x) ≤⟨ hyp ⟩
n + (⌜ 1 ⌝ + m) * steps (later y) ∼⟨ (n ∎∼) Conat.+-cong Conat.*suc∼+* ⟩≤
n + ((⌜ 1 ⌝ + m) + (⌜ 1 ⌝ + m) * steps (y .force)) ∼⟨ Conat.symmetric-∼ Conat.suc+∼+suc ⟩≤
⌜ 1 ⌝ + n + (m + (⌜ 1 ⌝ + m) * steps (y .force)) ∼⟨ suc (λ { .force → _ ∎∼ }) ⟩≤
⌜ 1 ⌝ + (n + (m + (⌜ 1 ⌝ + m) * steps (y .force))) ∼⟨ suc (λ { .force → Conat.+-assoc n }) ⟩≤
⌜ 1 ⌝ + (n + m + (⌜ 1 ⌝ + m) * steps (y .force)) ∎≤
from :
∀ {nˡ nʳ i x y} →
B.[ i ] x ≈ y →
[ ∞ ] steps x ≤ nˡ + (⌜ 1 ⌝ + mˡ) * steps y →
[ ∞ ] steps y ≤ nʳ + (⌜ 1 ⌝ + mʳ) * steps x →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y
from now _ _ = now
from (later p) q r = later λ { .force →
from (p .force) (from-lemma q) (from-lemma r) }
from (laterˡ {y = later _} p) q r = later λ { .force →
from (B.laterʳ⁻¹ p) (from-lemma q) (from-lemma r) }
from (laterʳ {x = later _} p) q r = later λ { .force →
from (B.laterˡ⁻¹ p) (from-lemma q) (from-lemma r) }
from {nˡ = zero} (laterˡ {y = now _} p) ()
from {nˡ = suc _} (laterˡ {y = now _} p) (suc q) _ =
laterˡ (from p (q .force) zero)
from {nʳ = zero} (laterʳ {x = now _} p) _ ()
from {nʳ = suc _} (laterʳ {x = now _} p) _ (suc r) =
laterʳ (from p zero (r .force))
-- [ ∞ ∣ m ∣ n ] x ≳ y holds iff x is an expansion of y and the number
-- of later constructors in x and y are related in a certain way.
≳⇔≳×steps≤steps :
∀ {m n x y} →
[ ∞ ∣ m ∣ n ] x ≳ y ⇔
x B.≳ y × [ ∞ ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y
≳⇔≳×steps≤steps {m} {n} {x} {y} =
[ ∞ ∣ m ∣ n ] x ≳ y ↝⟨ ≈⇔≈×steps≤steps² ⟩
x B.≈ y ×
[ ∞ ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y ×
[ ∞ ] steps y ≤ (⌜ 1 ⌝ + ⌜ 0 ⌝) * steps x ↝⟨ F.id ×-cong F.id ×-cong (_ ∎∼) Conat.≤-cong-∼ lemma ⟩
x B.≈ y ×
[ ∞ ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y ×
[ ∞ ] steps y ≤ steps x ↝⟨ record { to = B.symmetric; from = B.symmetric } ×-cong from-isomorphism ×-comm ⟩
y B.≈ x ×
[ ∞ ] steps y ≤ steps x ×
[ ∞ ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y ↔⟨ ×-assoc ⟩
(y B.≈ x ×
[ ∞ ] steps y ≤ steps x) ×
[ ∞ ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y ↝⟨ inverse B.≲⇔≈×steps≤steps ×-cong F.id ⟩□
x B.≳ y × [ ∞ ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y □
where
lemma =
(⌜ 1 ⌝ + ⌜ 0 ⌝) * steps x ∼⟨ suc (λ { .force → _ ∎∼ }) Conat.*-cong (_ ∎∼) ⟩
⌜ 1 ⌝ * steps x ∼⟨ Conat.*-left-identity _ ⟩
steps x ∎∼
-- [ ∞ ∣ m ∣ n ] x ≳ y holds iff x is weakly bisimilar to y and the
-- number of later constructors in x and y are related in a certain
-- way.
≳⇔≈×steps≤steps² :
∀ {m n x y} →
[ ∞ ∣ m ∣ n ] x ≳ y ⇔
x B.≈ y ×
[ ∞ ] steps y ≤ steps x ×
[ ∞ ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y
≳⇔≈×steps≤steps² {m} {n} {x} {y} =
[ ∞ ∣ m ∣ n ] x ≳ y ↝⟨ ≳⇔≳×steps≤steps ⟩
x B.≳ y ×
[ ∞ ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y ↝⟨ B.≲⇔≈×steps≤steps ×-cong F.id ⟩
(y B.≈ x ×
[ ∞ ] steps y ≤ steps x) ×
[ ∞ ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y ↔⟨ inverse ×-assoc ⟩
y B.≈ x ×
[ ∞ ] steps y ≤ steps x ×
[ ∞ ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y ↝⟨ record { to = B.symmetric; from = B.symmetric } ×-cong F.id ⟩□
x B.≈ y ×
[ ∞ ] steps y ≤ steps x ×
[ ∞ ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y □
-- The left-to-right direction of ≳⇔≳×steps≤steps can be made
-- size-preserving.
≳→≳×steps≤steps :
∀ {i m n x y} →
[ i ∣ m ∣ n ] x ≳ y →
B.[ i ] x ≳ y × [ i ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y
≳→≳×steps≤steps x≳y = ≳→≳ x≳y , steps-+-*ʳ x≳y
-- The right-to-left direction of ≳⇔≳×steps≤steps can be made
-- size-preserving iff A is uninhabited.
≳×steps≤steps→≳⇔uninhabited :
(∀ {i m n x y} →
B.[ i ] x ≳ y ×
[ i ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y →
[ i ∣ m ∣ n ] x ≳ y)
⇔
¬ A
≳×steps≤steps→≳⇔uninhabited = record
{ to = flip to
; from =
¬ A ↝⟨ (λ ¬A {_ _ _ _ _} → ∼→≈ (B.uninhabited→trivial ¬A _ _)) ⟩
(∀ {i m n x y} → [ i ∣ m ∣ n ] x ≳ y) ↝⟨ (λ hyp {_ _ _ _ _} _ → hyp {_}) ⟩□
(∀ {i m n x y} →
B.[ i ] x ≳ y ×
[ i ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y →
[ i ∣ m ∣ n ] x ≳ y) □
}
where
strengthen-≳now :
∀ {i m n x y} →
[ i ∣ m ∣ n ] x ≳ now y →
[ ∞ ∣ m ∣ n ] x ≳ now y
strengthen-≳now now = now
strengthen-≳now (laterˡ p) = laterˡ (strengthen-≳now p)
to :
A →
¬ (∀ {i m n x y} →
B.[ i ] x ≳ y ×
[ i ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y →
[ i ∣ m ∣ n ] x ≳ y)
to x =
(∀ {i m n x y} →
B.[ i ] x ≳ y ×
[ i ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y →
[ i ∣ m ∣ n ] x ≳ y) ↝⟨ (λ hyp → curry hyp) ⟩
(∀ {i m n} →
B.[ i ] f m ≳ now x →
[ i ] steps (f m) ≤ n + zero →
[ i ∣ zero ∣ n ] f m ≳ now x) ↝⟨ (λ hyp {_ _ _} p → hyp (≳now _) (complicate p)) ⟩
(∀ {i m n} → [ i ] ⌜ m ⌝ ≤ n → [ i ∣ zero ∣ n ] f m ≳ now x) ↝⟨ strengthen-≳now ∘_ ⟩
(∀ {i m n} → [ i ] ⌜ m ⌝ ≤ n → [ ∞ ∣ zero ∣ n ] f m ≳ now x) ↝⟨ (λ hyp {_ _ _} p → steps-+-*ʳ (hyp p)) ⟩
(∀ {i m n} → [ i ] ⌜ m ⌝ ≤ n → [ ∞ ] steps (f m) ≤ n + zero) ↝⟨ (λ hyp {_ _ _} p → simplify (hyp p)) ⟩
(∀ {i m n} → [ i ] ⌜ m ⌝ ≤ n → [ ∞ ] ⌜ m ⌝ ≤ n) ↝⟨ (λ hyp → hyp) ⟩
(∀ {i} → [ i ] ⌜ 2 ⌝ ≤ ⌜ 1 ⌝ → [ ∞ ] ⌜ 2 ⌝ ≤ ⌜ 1 ⌝) ↝⟨ Conat.no-strengthening-≤-21 ⟩□
⊥ □
where
f : ∀ {i} → ℕ → Delay A i
f zero = now x
f (suc n) = later λ { .force → f n }
≳now : ∀ {i} n → B.[ i ] f n ≳ now x
≳now zero = now
≳now (suc n) = laterˡ (≳now n)
∼steps : ∀ {i} n → Conat.[ i ] ⌜ n ⌝ ∼ steps (f n)
∼steps zero = zero
∼steps (suc n) = suc λ { .force → ∼steps n }
complicate :
∀ {m n i} → [ i ] ⌜ m ⌝ ≤ n → [ i ] steps (f m) ≤ n + zero
complicate {m} {n} p =
steps (f m) ∼⟨ Conat.symmetric-∼ (∼steps m) ⟩≤
⌜ m ⌝ ≤⟨ p ⟩
n ∼⟨ Conat.symmetric-∼ (Conat.+-right-identity _) ⟩≤
n + zero ∎≤
simplify :
∀ {m n i} → [ i ] steps (f m) ≤ n + zero → [ i ] ⌜ m ⌝ ≤ n
simplify {m} {n} p =
⌜ m ⌝ ∼⟨ ∼steps m ⟩≤
steps (f m) ≤⟨ p ⟩
n + zero ∼⟨ Conat.+-right-identity _ ⟩≤
n ∎≤
-- The left-to-right direction of ≈⇔≈×steps≤steps² can be made
-- size-preserving.
≈→≈×steps≤steps² :
∀ {i mˡ mʳ nˡ nʳ x y} →
[ ∞ ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y →
B.[ i ] x ≈ y ×
[ i ] steps x ≤ nˡ + (⌜ 1 ⌝ + mˡ) * steps y ×
[ i ] steps y ≤ nʳ + (⌜ 1 ⌝ + mʳ) * steps x
≈→≈×steps≤steps² x≈y = ≈→≈ x≈y , steps-+-*ʳ x≈y , steps-+-*ˡ x≈y
-- The right-to-left direction of ≈⇔≈×steps≤steps² can be made
-- size-preserving iff A is uninhabited.
≈×steps≤steps²→≈⇔uninhabited :
(∀ {i mˡ mʳ nˡ nʳ x y} →
B.[ i ] x ≈ y ×
[ i ] steps x ≤ nˡ + (⌜ 1 ⌝ + mˡ) * steps y ×
[ i ] steps y ≤ nʳ + (⌜ 1 ⌝ + mʳ) * steps x →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y)
⇔
¬ A
≈×steps≤steps²→≈⇔uninhabited = record
{ to =
(∀ {i mˡ mʳ nˡ nʳ x y} →
B.[ i ] x ≈ y ×
[ i ] steps x ≤ nˡ + (⌜ 1 ⌝ + mˡ) * steps y ×
[ i ] steps y ≤ nʳ + (⌜ 1 ⌝ + mʳ) * steps x →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y) ↝⟨ (λ { hyp (p , q) → hyp (B.≳→ p , q , lemma (B.steps-mono p)) }) ⟩
(∀ {i m n x y} →
B.[ i ] x ≳ y ×
[ i ] steps x ≤ n + (⌜ 1 ⌝ + m) * steps y →
[ i ∣ m ∣ n ] x ≳ y) ↝⟨ _⇔_.to ≳×steps≤steps→≳⇔uninhabited ⟩□
¬ A □
; from =
¬ A ↝⟨ (λ ¬A {_ _ _ _ _} → ∼→≈ (B.uninhabited→trivial ¬A _ _)) ⟩
(∀ {i mˡ mʳ nˡ nʳ x y} → [ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y) ↝⟨ (λ hyp {_ _ _ _ _ _ _} _ → hyp {_}) ⟩□
(∀ {i mˡ mʳ nˡ nʳ x y} →
B.[ i ] x ≈ y ×
[ i ] steps x ≤ nˡ + (⌜ 1 ⌝ + mˡ) * steps y ×
[ i ] steps y ≤ nʳ + (⌜ 1 ⌝ + mʳ) * steps x →
[ i ∣ mˡ ∣ mʳ ∣ nˡ ∣ nʳ ] x ≈ y) □
}
where
lemma :
∀ {m n i} →
[ i ] m ≤ n →
[ i ] m ≤ (⌜ 1 ⌝ + ⌜ 0 ⌝) * n
lemma {m} {n} p =
m ≤⟨ p ⟩
n ∼⟨ Conat.symmetric-∼ (Conat.*-left-identity _) ⟩≤
⌜ 1 ⌝ * n ∼⟨ Conat.symmetric-∼ (Conat.+-right-identity _) Conat.*-cong (_ ∎∼) ⟩≤
(⌜ 1 ⌝ + ⌜ 0 ⌝) * n ∎≤
|
{
"alphanum_fraction": 0.4198212408,
"avg_line_length": 35.0061349693,
"ext": "agda",
"hexsha": "bcf8ff43241d79983f8c1d4dc62013c3272e2112",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/delay-monad",
"max_forks_repo_path": "src/Delay-monad/Quantitative-weak-bisimilarity.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/delay-monad",
"max_issues_repo_path": "src/Delay-monad/Quantitative-weak-bisimilarity.agda",
"max_line_length": 138,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/delay-monad",
"max_stars_repo_path": "src/Delay-monad/Quantitative-weak-bisimilarity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 11812,
"size": 22824
}
|
module trichotomy where
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Data.Nat using (ℕ; zero; suc)
open import Relations using (_<_; z<s; s<s)
-- 三分法
data Trichotomy (m n : ℕ) : Set where
m<n : m < n → Trichotomy m n
m≡n : m ≡ n → Trichotomy m n
n<m : n < m → Trichotomy m n
trichotomy : ∀ (m n : ℕ) → Trichotomy m n
trichotomy zero zero = m≡n refl
trichotomy (suc m) zero = n<m z<s
trichotomy zero (suc n) = m<n z<s
trichotomy (suc m) (suc n) with trichotomy m n
... | m<n m′<n′ = m<n (s<s m′<n′)
... | m≡n refl = m≡n refl
... | n<m n′<m′ = n<m (s<s n′<m′)
|
{
"alphanum_fraction": 0.4837451235,
"avg_line_length": 34.9545454545,
"ext": "agda",
"hexsha": "79edb12e37d4b025d00ecee905273c241ad7d8db",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/relations/trichotomy.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/relations/trichotomy.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/relations/trichotomy.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 260,
"size": 769
}
|
{-# OPTIONS --universe-polymorphism #-}
open import Categories.Category
module Categories.Object.Terminal {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Relation.Binary using (IsEquivalence; Setoid)
open import Categories.Support.PropositionalEquality
open Category C
record Terminal : Set (o ⊔ ℓ ⊔ e) where
field
⊤ : Obj
! : ∀ {A} → (A ⇒ ⊤)
.!-unique : ∀ {A} → (f : A ⇒ ⊤) → ! ≡ f
.!-unique₂ : ∀ {A} → (f g : A ⇒ ⊤) → f ≡ g
!-unique₂ f g =
begin
f
↑⟨ !-unique f ⟩
!
↓⟨ !-unique g ⟩
g
∎
where open HomReasoning
.⊤-id : (f : ⊤ ⇒ ⊤) → f ≡ id
⊤-id f = !-unique₂ f id
open Heterogeneous C
!-unique∼ : ∀ {A A′} → (f : A′ ⇒ ⊤) → (A ≣ A′) → ! {A} ∼ f
!-unique∼ f ≣-refl = Heterogeneous.≡⇒∼ (!-unique f)
import Categories.Morphisms
open Categories.Morphisms C
open import Categories.Square
open GlueSquares C
open Terminal
open Heterogeneous C
!-is-propertylike : ∀ t₁ t₂ → ⊤ t₁ ≣ ⊤ t₂ → ∀ {A} → ! t₁ {A} ∼ ! t₂ {A}
!-is-propertylike t₁ t₂ eq = helper t₁ eq (! t₂)
where
helper : ∀ t {T} → (⊤ t ≣ T) → ∀ {A} (f : A ⇒ T) → ! t {A} ∼ f
helper t ≣-refl f = ≡⇒∼ (!-unique t f)
up-to-iso : (t₁ t₂ : Terminal) → ⊤ t₁ ≅ ⊤ t₂
up-to-iso t₁ t₂ = record
{ f = ! t₂
; g = ! t₁
; iso = record { isoˡ = ⊤-id t₁ _; isoʳ = ⊤-id t₂ _ }
}
up-to-iso-cong₂ : {t₁ t₁′ t₂ t₂′ : Terminal} → ⊤ t₁ ≣ ⊤ t₁′ → ⊤ t₂ ≣ ⊤ t₂′ → up-to-iso t₁ t₂ ∼ⁱ up-to-iso t₁′ t₂′
up-to-iso-cong₂ {t₁} {t₁′} {t₂} {t₂′} eq₁ eq₂ = heqⁱ (up-to-iso t₁ t₂) (up-to-iso t₁′ t₂′) (helper t₂ t₂′ eq₂ eq₁) (helper t₁ t₁′ eq₁ eq₂)
where
helper : ∀ t t′ → (⊤ t ≣ ⊤ t′) → ∀ {A A′} → A ≣ A′ → ! t {A} ∼ ! t′ {A′}
helper t t′ eq-t ≣-refl = !-is-propertylike t t′ eq-t
transport-by-iso : (t : Terminal) → ∀ {X} → ⊤ t ≅ X → Terminal
transport-by-iso t {X} t≅X = record
{ ⊤ = X
; ! = f ∘ ! t
; !-unique = λ h → let open HomReasoning in
begin
f ∘ ! t
↓⟨ ∘-resp-≡ʳ (!-unique t (g ∘ h)) ⟩
f ∘ (g ∘ h)
↓⟨ cancelLeft isoʳ ⟩
h
∎
}
where open _≅_ t≅X
transport-by-iso-cong₂ : ∀ {t t′} → (⊤ t ≣ ⊤ t′) → ∀ {X} {i : ⊤ t ≅ X} {X′} {i′ : ⊤ t′ ≅ X′} → (i ∼ⁱ i′) → ⊤ (transport-by-iso t i) ≣ ⊤ (transport-by-iso t′ i′)
transport-by-iso-cong₂ eq-t eq-i = codomain-≣ⁱ eq-i
.up-to-iso-unique : ∀ t t′ → (i : ⊤ t ≅ ⊤ t′) → up-to-iso t t′ ≡ⁱ i
up-to-iso-unique t t′ i = record { f-≡ = !-unique t′ _; g-≡ = !-unique t _ }
.up-to-iso-invˡ : ∀ {t X} {i : ⊤ t ≅ X} → up-to-iso t (transport-by-iso t i) ≡ⁱ i
up-to-iso-invˡ {t} {i = i} = up-to-iso-unique t (transport-by-iso t i) i
up-to-iso-invʳ : ∀ {t t′} → ⊤ (transport-by-iso t (up-to-iso t t′)) ≣ ⊤ t′
up-to-iso-invʳ {t} {t′} = ≣-refl
|
{
"alphanum_fraction": 0.513271028,
"avg_line_length": 29.7222222222,
"ext": "agda",
"hexsha": "b216bcecd64a8186fe8dbb91e82c7d9f079c3307",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Object/Terminal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Object/Terminal.agda",
"max_line_length": 160,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "p-pavel/categories",
"max_stars_repo_path": "Categories/Object/Terminal.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-29T21:51:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-12-29T21:51:57.000Z",
"num_tokens": 1272,
"size": 2675
}
|
------------------------------------------------------------------------
-- Concrete syntax used by the mixfix operator parser
------------------------------------------------------------------------
module RecursiveDescent.Hybrid.Mixfix.Expr where
open import Data.Nat hiding (_≟_)
open import Data.Vec
open import Data.List using (List)
open import Data.Product
open import Data.Maybe
open import Data.String using (String)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import RecursiveDescent.Hybrid.Mixfix.Fixity
-- Name parts.
NamePart : Set
NamePart = String
-- Operators. arity is the internal arity of the operator, i.e. the
-- number of arguments taken between the first and last name parts.
data Operator (fix : Fixity) (arity : ℕ) : Set where
operator : (nameParts : Vec NamePart (1 + arity)) ->
Operator fix arity
-- Predicate filtering out operators of the given fixity and
-- associativity.
hasFixity : forall fix -> ∃₂ Operator -> Maybe (∃ (Operator fix))
hasFixity fix (fix' , op) with fix ≟ fix'
hasFixity fix (.fix , op) | yes refl = just op
hasFixity fix (fix' , op) | _ = nothing
-- Precedence graphs are represented by their unfoldings as forests
-- (one tree for every node in the graph). This does not take into
-- account the sharing of the precedence graphs, but this program is
-- not aimed at efficiency.
mutual
PrecedenceGraph : Set
PrecedenceGraph = List PrecedenceTree
data PrecedenceTree : Set where
precedence : (ops : (fix : Fixity) -> List (∃ (Operator fix)))
(successors : PrecedenceGraph) ->
PrecedenceTree
-- Concrete syntax. TODO: Ensure that expressions are precedence
-- correct by parameterising the expression type on a precedence graph
-- and indexing on precedences.
mutual
infixl 4 _⟨_⟩_ _∙_
infix 4 _⟨_⟫ ⟪_⟩_
data Expr : Set where
_⟨_⟩_ : forall {assoc}
(l : Expr) (op : Internal (infx assoc)) (r : Expr) -> Expr
_⟨_⟫ : (l : Expr) (op : Internal postfx) -> Expr
⟪_⟩_ : (op : Internal prefx) (r : Expr) -> Expr
⟪_⟫ : (op : Internal closed) -> Expr
-- Application of an operator to all its internal arguments.
data Internal (fix : Fixity) : Set where
_∙_ : forall {arity}
(op : Operator fix arity) (args : Vec Expr arity) ->
Internal fix
|
{
"alphanum_fraction": 0.6242299795,
"avg_line_length": 32.4666666667,
"ext": "agda",
"hexsha": "49968d53a12221cea844cff0e1fb1d6c6cd1eb93",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "misc/RecursiveDescent/Hybrid/Mixfix/Expr.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "misc/RecursiveDescent/Hybrid/Mixfix/Expr.agda",
"max_line_length": 72,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "misc/RecursiveDescent/Hybrid/Mixfix/Expr.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 616,
"size": 2435
}
|
{-# OPTIONS --type-in-type #-}
open import Data.Empty
open import Data.Unit
open import Data.Bool
open import Data.Product hiding ( curry ; uncurry )
open import Data.Nat
open import Data.String
open import Relation.Binary.PropositionalEquality using ( refl ; _≢_ ; _≡_ )
open import Function
module ClosedTheory where
noteq = _≢_
----------------------------------------------------------------------
data Desc (I : Set) : Set₁ where
End : (i : I) → Desc I
Rec : (i : I) (D : Desc I) → Desc I
Arg : (A : Set) (B : A → Desc I) → Desc I
ISet : Set → Set₁
ISet I = I → Set
El : {I : Set} (D : Desc I) → ISet I → ISet I
El (End j) X i = j ≡ i
El (Rec j D) X i = X j × El D X i
El (Arg A B) X i = Σ A (λ a → El (B a) X i)
----------------------------------------------------------------------
UncurriedEl : {I : Set} (D : Desc I) (X : ISet I) → Set
UncurriedEl D X = ∀{i} → El D X i → X i
CurriedEl : {I : Set} (D : Desc I) (X : ISet I) → Set
CurriedEl (End i) X = X i
CurriedEl (Rec i D) X = (x : X i) → CurriedEl D X
CurriedEl (Arg A B) X = (a : A) → CurriedEl (B a) X
CurriedEl' : {I : Set} (D : Desc I) (X : ISet I) (i : I) → Set
CurriedEl' (End j) X i = j ≡ i → X i
CurriedEl' (Rec j D) X i = (x : X j) → CurriedEl' D X i
CurriedEl' (Arg A B) X i = (a : A) → CurriedEl' (B a) X i
curryEl : {I : Set} (D : Desc I) (X : ISet I)
→ UncurriedEl D X → CurriedEl D X
curryEl (End i) X cn = cn refl
curryEl (Rec i D) X cn = λ x → curryEl D X (λ xs → cn (x , xs))
curryEl (Arg A B) X cn = λ a → curryEl (B a) X (λ xs → cn (a , xs))
uncurryEl : {I : Set} (D : Desc I) (X : ISet I)
→ CurriedEl D X → UncurriedEl D X
uncurryEl (End i) X cn refl = cn
uncurryEl (Rec i D) X cn (x , xs) = uncurryEl D X (cn x) xs
uncurryEl (Arg A B) X cn (a , xs) = uncurryEl (B a) X (cn a) xs
----------------------------------------------------------------------
data μ {I : Set} (D : Desc I) (i : I) : Set where
init : El D (μ D) i → μ D i
Inj : {I : Set} (D : Desc I) → Set
Inj D = CurriedEl D (μ D)
inj : {I : Set} (D : Desc I) → Inj D
inj D = curryEl D (μ D) init
----------------------------------------------------------------------
data VecT : Set where
nilT consT : VecT
VecC : (A : Set) → VecT → Desc ℕ
VecC A nilT = End zero
VecC A consT = Arg ℕ (λ n → Arg A λ _ → Rec n (End (suc n)))
VecD : (A : Set) → Desc ℕ
VecD A = Arg VecT (VecC A)
Vec : (A : Set) → ℕ → Set
Vec A = μ (VecD A)
InjConsT : Set → ℕ → Set
InjConsT A m = El (VecC A consT) (Vec A) m → Vec A m
InjConsT' : Set → ℕ → Set
InjConsT' A m = Σ ℕ (λ n → A × Vec A n × suc n ≡ m) → Vec A m
test-InjConsT : (A : Set) (n : ℕ) → InjConsT A n ≡ InjConsT' A n
test-InjConsT A n = refl
nil : (A : Set) → Vec A zero
nil A = init (nilT , refl)
cons : (A : Set) (n : ℕ) (x : A) (xs : Vec A n) → Vec A (suc n)
cons A n x xs = init (consT , n , x , xs , refl)
nil2 : (A : Set) → Vec A zero
nil2 A = inj (VecD A) nilT
cons2 : (A : Set) (n : ℕ) (x : A) (xs : Vec A n) → Vec A (suc n)
cons2 A = inj (VecD A) consT
bit : Vec Bool (suc zero)
bit = cons Bool zero true (nil Bool)
bit2 : Vec Bool (suc zero)
bit2 = init (consT , zero , true , init (nilT , refl) , refl)
----------------------------------------------------------------------
data TreeT : Set where
leaf₁T leaf₂T branchT : TreeT
TreeC : (A B : Set) → TreeT → Desc (ℕ × ℕ)
TreeC A B leaf₁T = Arg A λ _ → End (suc zero , zero)
TreeC A B leaf₂T = Arg B λ _ → End (zero , suc zero)
TreeC A B branchT = Arg ℕ λ m → Arg ℕ λ n
→ Arg ℕ λ x → Arg ℕ λ y
→ Rec (m , n) $ Rec (x , y)
$ End (m + x , n + y)
TreeD : (A B : Set) → Desc (ℕ × ℕ)
TreeD A B = Arg TreeT (TreeC A B)
Tree : (A B : Set) (m n : ℕ) → Set
Tree A B m n = μ (TreeD A B) (m , n)
leaf₁ : (A B : Set) → A → Tree A B (suc zero) zero
leaf₁ A B a = init (leaf₁T , a , refl)
leaf₁2 : (A B : Set) → A → Tree A B (suc zero) zero
leaf₁2 A B = inj (TreeD A B) leaf₁T
----------------------------------------------------------------------
|
{
"alphanum_fraction": 0.4950992712,
"avg_line_length": 29.4740740741,
"ext": "agda",
"hexsha": "cd6991fc1c56cec434310ae712871e2cd745dfe9",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:31:22.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-02T08:56:15.000Z",
"max_forks_repo_head_hexsha": "832383d7adf37aa2364213fb0aeb67e9f61a248f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/generic-elim",
"max_forks_repo_path": "slides/ClosedTheory.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "832383d7adf37aa2364213fb0aeb67e9f61a248f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/generic-elim",
"max_issues_repo_path": "slides/ClosedTheory.agda",
"max_line_length": 76,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "832383d7adf37aa2364213fb0aeb67e9f61a248f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/generic-elim",
"max_stars_repo_path": "slides/ClosedTheory.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-09T08:46:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-02T14:05:20.000Z",
"num_tokens": 1511,
"size": 3979
}
|
module VaryingClauseArity where
-- see also thread https://lists.chalmers.se/pipermail/agda-dev/2015-January/000041.html
open import Common.IO
open import Common.Unit
open import Common.Nat
Sum : Nat → Set
Sum 0 = Nat
Sum (suc n) = Nat → Sum n
sum : (acc : Nat) (n : Nat) → Sum n
sum acc 0 = acc
sum acc (suc n) 0 = sum acc n
sum acc (suc n) m = sum (m + acc) n
-- expected:
-- 10
-- 20
-- 33
main : IO Unit
main = printNat (sum 10 0) ,,
putStr "\n" ,,
printNat (sum 20 1 0) ,,
putStr "\n" ,,
printNat (sum 30 1 3)
|
{
"alphanum_fraction": 0.6187845304,
"avg_line_length": 18.724137931,
"ext": "agda",
"hexsha": "009d6b4dc46f522149063631357749d6e88e2b7e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Compiler/simple/VaryingClauseArity.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Compiler/simple/VaryingClauseArity.agda",
"max_line_length": 88,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Compiler/simple/VaryingClauseArity.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 207,
"size": 543
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Vectors where all elements satisfy a given property
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Relation.Unary.All where
open import Data.Nat using (zero; suc)
open import Data.Fin using (Fin; zero; suc)
open import Data.Product as Prod using (_,_)
open import Data.Vec as Vec using (Vec; []; _∷_)
open import Function using (_∘_)
open import Level using (_⊔_)
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
open import Relation.Unary
open import Relation.Binary.PropositionalEquality as P using (subst)
------------------------------------------------------------------------
-- All P xs means that all elements in xs satisfy P.
infixr 5 _∷_
data All {a p} {A : Set a}
(P : A → Set p) : ∀ {k} → Vec A k → Set (p ⊔ a) where
[] : All P []
_∷_ : ∀ {k x} {xs : Vec A k} (px : P x) (pxs : All P xs) → All P (x ∷ xs)
------------------------------------------------------------------------
-- Operations on All
head : ∀ {a p} {A : Set a} {P : A → Set p} {k x} {xs : Vec A k} →
All P (x ∷ xs) → P x
head (px ∷ pxs) = px
tail : ∀ {a p} {A : Set a} {P : A → Set p} {k x} {xs : Vec A k} →
All P (x ∷ xs) → All P xs
tail (px ∷ pxs) = pxs
lookup : ∀ {a p} {A : Set a} {P : A → Set p} {k} {xs : Vec A k} →
(i : Fin k) → All P xs → P (Vec.lookup xs i)
lookup () []
lookup zero (px ∷ pxs) = px
lookup (suc i) (px ∷ pxs) = lookup i pxs
tabulate : ∀ {a p} {A : Set a} {P : A → Set p} {k xs} →
(∀ i → P (Vec.lookup xs i)) → All P {k} xs
tabulate {xs = []} pxs = []
tabulate {xs = _ ∷ _} pxs = pxs zero ∷ tabulate (pxs ∘ suc)
map : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} {k} →
P ⊆ Q → All P {k} ⊆ All Q {k}
map g [] = []
map g (px ∷ pxs) = g px ∷ map g pxs
zipWith : ∀ {a b c p q r} {A : Set a} {B : Set b} {C : Set c} {_⊕_ : A → B → C}
{P : A → Set p} {Q : B → Set q} {R : C → Set r} →
(∀ {x y} → P x → Q y → R (x ⊕ y)) →
∀ {k xs ys} → All P {k} xs → All Q {k} ys →
All R {k} (Vec.zipWith _⊕_ xs ys)
zipWith _⊕_ {xs = []} {[]} [] [] = []
zipWith _⊕_ {xs = x ∷ xs} {y ∷ ys} (px ∷ pxs) (qy ∷ qys) =
px ⊕ qy ∷ zipWith _⊕_ pxs qys
zip : ∀ {a p q k} {A : Set a} {P : A → Set p} {Q : A → Set q} →
All P ∩ All Q ⊆ All (P ∩ Q) {k}
zip ([] , []) = []
zip (px ∷ pxs , qx ∷ qxs) = (px , qx) ∷ zip (pxs , qxs)
unzip : ∀ {a p q k} {A : Set a} {P : A → Set p} {Q : A → Set q} →
All (P ∩ Q) {k} ⊆ All P ∩ All Q
unzip [] = [] , []
unzip (pqx ∷ pqxs) = Prod.zip _∷_ _∷_ pqx (unzip pqxs)
------------------------------------------------------------------------
-- Properties of predicates preserved by All
module _ {a p} {A : Set a} {P : A → Set p} where
all : ∀ {k} → Decidable P → Decidable (All P {k})
all P? [] = yes []
all P? (x ∷ xs) with P? x
... | yes px = Dec.map′ (px ∷_) tail (all P? xs)
... | no ¬px = no (¬px ∘ head)
universal : Universal P → ∀ {k} → Universal (All P {k})
universal u [] = []
universal u (x ∷ xs) = u x ∷ universal u xs
irrelevant : Irrelevant P → ∀ {k} → Irrelevant (All P {k})
irrelevant irr [] [] = P.refl
irrelevant irr (px₁ ∷ pxs₁) (px₂ ∷ pxs₂) =
P.cong₂ _∷_ (irr px₁ px₂) (irrelevant irr pxs₁ pxs₂)
satisfiable : Satisfiable P → ∀ {k} → Satisfiable (All P {k})
satisfiable (x , p) {zero} = [] , []
satisfiable (x , p) {suc k} = Prod.map (x ∷_) (p ∷_) (satisfiable (x , p))
|
{
"alphanum_fraction": 0.4517891287,
"avg_line_length": 36.2475247525,
"ext": "agda",
"hexsha": "d37d6c298e2af82b1ab43693528283047a7fb85e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Unary/All.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Unary/All.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Unary/All.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1337,
"size": 3661
}
|
{-# OPTIONS --without-K #-}
open import Type using (Type₀; Type₁; Type_)
open import Type.Identities
open import Function.NP using (Π; _∘_; const)
open import Function.Extensionality using (FunExt)
open import Data.Zero using (𝟘)
open import Data.One using (𝟙; 0₁)
open import Data.Two.Base using (𝟚; 0₂; 1₂)
open import Data.Product.NP using (Σ; _×_; _,_; fst; snd)
open import Data.Sum.NP using (_⊎_; inl; inr)
open import Data.Nat.Base using (ℕ; zero; suc)
open import Data.Fin using (Fin)
open import Relation.Nullary.NP using (Dec)
open import Relation.Binary.PropositionalEquality.NP using (_≡_; idp; ap; !_; _∙_; tr)
open import HoTT using (ua; UA; module Equivalences)
open Equivalences using (_≃_; ≃-!; ≃-refl; _≃-∙_)
open import Explore.Core
open import Explore.Properties
open import Explore.Zero
open import Explore.One
open import Explore.Two
open import Explore.Product
open Explore.Product.Operators
open import Explore.Sum
open import Explore.Explorable
open import Explore.Isomorphism
open import Explore.GuessingGameFlipping
import Explore.Universe.Type
import Explore.Universe.FromE
module Explore.Universe (X : Type₀) where
open Explore.Universe.Type {X}
module FromXᵉ = Explore.Universe.FromE X
open Adequacy _≡_
module FromKit
{Xᵉ : ∀ {ℓ} → Explore ℓ X}
(Xⁱ : ∀ {ℓ p} → ExploreInd p (Xᵉ {ℓ}))
(let module Xᴱ = FromExploreInd Xⁱ)
(Xˢ-ok : ∀{{_ : UA}}{{_ : FunExt}} → Adequate-sum Xᴱ.sum)
(Xˡ : ∀ {ℓ} → Lookup {ℓ} Xᵉ)
(Xᶠ : ∀ {ℓ} → Focus {ℓ} Xᵉ)
(ΣᵉX-ok : ∀{{_ : UA}}{{_ : FunExt}}{ℓ} → Adequate-Σ {ℓ} (Σᵉ Xᵉ))
(ΠᵉX-ok : ∀{{_ : UA}}{{_ : FunExt}}{ℓ} → Adequate-Π {ℓ} (Πᵉ Xᵉ))
(⟦Xᵉ⟧≡ : ∀ {ℓ₀ ℓ₁} ℓᵣ → ⟦Explore⟧ {ℓ₀} {ℓ₁} ℓᵣ _≡_ Xᵉ Xᵉ)
(ΠX : (X → U) → U)
(ΠX≃ : ∀{{_ : UA}}{{_ : FunExt}} v → El (ΠX v) ≃ Π X (El ∘ v))
(u : U)
where
private
module M where
open FromXᵉ Xᵉ public
open FromXⁱ Xⁱ public
open FromXˡ Xˡ public
open FromXᶠ Xᶠ public
open FromΠX ΠX public
module _ {{_ : FunExt}}{{_ : UA}} where
open FromΣᵉX-ok ΣᵉX-ok public
open FromΠᵉX-ok ΠᵉX-ok public
open From⟦Xᵉ⟧≡ ⟦Xᵉ⟧≡ public
open FromΠX≃ ΠX≃ public
explore : ∀ {ℓ} → Explore ℓ (El u)
explore = M.explore u
explore-ind : ∀ {ℓ p} → ExploreInd {ℓ} p explore
explore-ind = M.explore-ind u
open FromExploreInd explore-ind public hiding (⟦explore⟧)
-- TODO list what is exported here
lookup : ∀ {ℓ} → Lookup {ℓ} explore
lookup = M.lookup u
open FromLookup {explore = explore} lookup public
focus : ∀ {ℓ} → Focus {ℓ} explore
focus = M.focus u
Πᵁ : (v : El u → U) → U
Πᵁ = M.Πᵁ u
_→ᵁ_ : (v : U) → U
_→ᵁ_ = M._→ᵁ_ u
module _ {{_ : FunExt}}{{_ : UA}} where
Σᵉ-ok : ∀ {ℓ} → Adequate-Σ {ℓ} (Σᵉ explore)
Σᵉ-ok = M.Σᵉ-ok u
Πᵉ-ok : ∀ {ℓ} → Adequate-Π {ℓ} (Πᵉ explore)
Πᵉ-ok = M.Πᵉ-ok u
⟦explore⟧≡ : ∀ {ℓ₀ ℓ₁} ℓᵣ → ⟦Explore⟧ {ℓ₀} {ℓ₁} ℓᵣ _≡_ explore explore
⟦explore⟧≡ ℓᵣ = M.⟦explore⟧≡ ℓᵣ u
open From⟦Explore⟧ ⟦explore⟧≡ public
using ( sum⇒Σᵉ
; product⇒Πᵉ
; ✓all-Πᵉ
; ✓any→Σᵉ
; module FromAdequate-Σᵉ
; module FromAdequate-Πᵉ
)
open FromAdequate-Σᵉ Σᵉ-ok public
using ( sumStableUnder
; sumStableUnder′
; same-count→iso
; adequate-sum
; adequate-any
)
open FromAdequate-Πᵉ Πᵉ-ok public
using ( adequate-product
; adequate-all
; check!
)
Dec-Σ : ∀ {p}{P : El u → Type p} → Π (El u) (Dec ∘ P) → Dec (Σ (El u) P)
Dec-Σ = FromFocus.Dec-Σ focus
Πᵁ-Π : ∀ v → El (Πᵁ v) ≡ Π (El u) (El ∘ v)
Πᵁ-Π = M.Πᵁ-Π u
→ᵁ-→ : ∀ v → El (_→ᵁ_ v) ≡ (El u → El v)
→ᵁ-→ = M.→ᵁ-→ u
Πᵁ→Π : ∀ v → El (Πᵁ v) → Π (El u) (El ∘ v)
Πᵁ→Π = M.Πᵁ→Π u
Π→Πᵁ : ∀ v → Π (El u) (El ∘ v) → El (Πᵁ v)
Π→Πᵁ = M.Π→Πᵁ u
→ᵁ→→ : ∀ v → El (_→ᵁ_ v) → (El u → El v)
→ᵁ→→ = M.→ᵁ→→ u
→→→ᵁ : ∀ v → (El u → El v) → El (_→ᵁ_ v)
→→→ᵁ = M.→→→ᵁ u
guessing-game-flipping = Explore.GuessingGameFlipping.thm (El u) sum sum-ind
-- -}
-- -}
-- -}
-- -}
-- -}
|
{
"alphanum_fraction": 0.5693236715,
"avg_line_length": 27.417218543,
"ext": "agda",
"hexsha": "6ed873e16fbd62cae6d42984c66c003df0b4cbb7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/Universe.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/Universe.agda",
"max_line_length": 86,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/Universe.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 1873,
"size": 4140
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
open import LibraBFT.Impl.OBM.Logging.Logging
import LibraBFT.Impl.Types.Ledger2WaypointConverter as Ledger2WaypointConverter
open import LibraBFT.ImplShared.Consensus.Types
import LibraBFT.ImplShared.Util.Crypto as Crypto
open import Optics.All
open import Util.Hash
open import Util.Prelude
module LibraBFT.Impl.Types.Waypoint where
newAny : LedgerInfo → Waypoint
newAny ledgerInfo =
let converter = Ledger2WaypointConverter.new ledgerInfo
in Waypoint∙new (ledgerInfo ^∙ liVersion) (Crypto.hashL2WC converter)
newEpochBoundary : LedgerInfo → Either ErrLog Waypoint
newEpochBoundary ledgerInfo =
if ledgerInfo ^∙ liEndsEpoch
then pure (newAny ledgerInfo)
else Left fakeErr -- ["newEpochBoundary", "no validator set"]
verify : Waypoint → LedgerInfo → Either ErrLog Unit
verify self ledgerInfo = do
lcheck (self ^∙ wVersion == ledgerInfo ^∙ liVersion)
("Waypoint" ∷ "version mismatch" ∷ []) --show (self^.wVersion), show (ledgerInfo^.liVersion)]
let converter = Ledger2WaypointConverter.new ledgerInfo
lcheck (self ^∙ wValue == Crypto.hashL2WC converter)
("Waypoint" ∷ "value mismatch" ∷ []) --show (self^.wValue), show (Crypto.hashL2WC converter)]
pure unit
epochChangeVerificationRequired : Waypoint → Epoch → Bool
epochChangeVerificationRequired _self _epoch = true
isLedgerInfoStale : Waypoint → LedgerInfo → Bool
isLedgerInfoStale self ledgerInfo = ⌊ (ledgerInfo ^∙ liVersion) <?-Version (self ^∙ wVersion) ⌋
verifierVerify : Waypoint → LedgerInfoWithSignatures → Either ErrLog Unit
verifierVerify self liws = verify self (liws ^∙ liwsLedgerInfo)
|
{
"alphanum_fraction": 0.7622820919,
"avg_line_length": 41.152173913,
"ext": "agda",
"hexsha": "c76e5affcf60fed8769a67fdd93916d006348551",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Types/Waypoint.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Types/Waypoint.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Types/Waypoint.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 522,
"size": 1893
}
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.DinaturalTransformation where
open import Level
open import Data.Product
open import Categories.Category
import Categories.NaturalTransformation
private module NT = Categories.NaturalTransformation
open import Categories.Functor using (Functor) renaming (_∘_ to _∘F_)
open import Categories.Bifunctor using (Bifunctor; module Functor)
open import Categories.Product
open import Categories.Square
record DinaturalTransformation {o ℓ e o′ ℓ′ e′}
{C : Category o ℓ e}
{D : Category o′ ℓ′ e′}
(F G : Bifunctor (Category.op C) C D) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
private
module C = Category C
module D = Category D
open Functor F renaming (op to Fop)
open Functor G renaming (F₀ to G₀; F₁ to G₁; op to Gop)
open D hiding (op)
field
α : (c : C.Obj) → D [ F₀ (c , c) , G₀ (c , c) ]
.commute : ∀ {c c′} (f : C [ c , c′ ]) → G₁ (f , C.id) ∘ α c′ ∘ F₁ ( C.id , f ) ≡ G₁ ( C.id , f ) ∘ α c ∘ F₁ ( f , C.id )
op : DinaturalTransformation {C = C.op} {D = D.op} Gop Fop
op = record { α = α; commute = λ f → D.Equiv.trans assoc (D.Equiv.trans (D.Equiv.sym (commute f)) (D.Equiv.sym assoc)) }
_<∘_ : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {F G H : Bifunctor (Category.op C) C D}
→ NT.NaturalTransformation G H → DinaturalTransformation {C = C} F G → DinaturalTransformation {C = C} F H
_<∘_ {C = C} {D} {F} {G} {H} eta alpha = record { α = λ c → η (c , c) ∘ α c; commute = λ {c} {c′} f →
begin
H.F₁ (f , C.id) ∘ ((η (c′ , c′) ∘ α c′) ∘ F.F₁ (C.id , f))
↓⟨ ∘-resp-≡ʳ assoc ⟩
H.F₁ (f , C.id) ∘ (η (c′ , c′) ∘ (α c′ ∘ F.F₁ (C.id , f)))
↑⟨ assoc ⟩
(H.F₁ (f , C.id) ∘ η (c′ , c′)) ∘ (α c′ ∘ F.F₁ (C.id , f))
↑⟨ ∘-resp-≡ˡ (eta.commute (f , C.id)) ⟩
(η (c , c′) ∘ G.F₁ (f , C.id)) ∘ (α c′ ∘ F.F₁ (C.id , f))
↓⟨ pullʳ (commute f) ⟩
η (c , c′) ∘ G.F₁ (C.id , f) ∘ (α c ∘ F.F₁ (f , C.id))
↓⟨ pullˡ (eta.commute (C.id , f)) ⟩
(H.F₁ (C.id , f) ∘ η (c , c)) ∘ (α c ∘ F.F₁ (f , C.id))
↓⟨ assoc ⟩
H.F₁ (C.id , f) ∘ (η (c , c) ∘ (α c ∘ F.F₁ (f , C.id)))
↑⟨ ∘-resp-≡ʳ assoc ⟩
H.F₁ (C.id , f) ∘ ((η (c , c) ∘ α c) ∘ F.F₁ (f , C.id))
∎
{- This uses 'associative-unital reasoning, which is now broken. Above uses
direct reasoning, which is heavier, but works. JC.
begin
H.F₁ (f , C.id) ∙ ((η (c′ , c′) ∙ α c′) ∙ F.F₁ (C.id , f))
↑⟨ refl ⟩
(H.F₁ (f , C.id) ∙ η (c′ , c′)) ∙ (α c′ ∙ F.F₁ (C.id , f))
↑≡⟨ ∘-resp-≡ˡ (eta.commute (f , C.id)) ⟩
(η (c , c′) ∙ G.F₁ (f , C.id)) ∙ (α c′ ∙ F.F₁ (C.id , f))
↓≡⟨ pullʳ (commute f) ⟩
η (c , c′) ∙ G.F₁ (C.id , f) ∙ α c ∙ F.F₁ (f , C.id)
↓≡⟨ pullˡ (eta.commute (C.id , f)) ⟩
(H.F₁ (C.id , f) ∙ η (c , c)) ∙ α c ∙ F.F₁ (f , C.id)
↓⟨ refl ⟩
H.F₁ (C.id , f) ∙ (η (c , c) ∙ α c) ∙ F.F₁ (f , C.id)
∎ -} }
where
module C = Category C
module D = Category D
open D
open D.Equiv
module F = Functor F
module G = Functor G
module H = Functor H
module eta = NT.NaturalTransformation eta
open eta using (η)
open DinaturalTransformation alpha
-- open AUReasoning D
open HomReasoning
open GlueSquares D
_∘>_ : ∀ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {F G H : Bifunctor (Category.op C) C D}
→ DinaturalTransformation {C = C} G H → NT.NaturalTransformation F G → DinaturalTransformation {C = C} F H
alpha ∘> eta = DinaturalTransformation.op (eta.op <∘ alpha.op)
where
module eta = NT.NaturalTransformation eta
module alpha = DinaturalTransformation alpha
_∘ʳ_ : ∀ {o₀ ℓ₀ e₀ o₁ ℓ₁ e₁ o₂ ℓ₂ e₂}
→ {C : Category o₀ ℓ₀ e₀} {D : Category o₁ ℓ₁ e₁} {E : Category o₂ ℓ₂ e₂}
→ {F G : Bifunctor (Category.op C) C D}
→ (η : DinaturalTransformation {C = C} F G) → (K : Functor E C) → DinaturalTransformation {C = E} (F ∘F ((Functor.op K) ⁂ K)) (G ∘F ((Functor.op K) ⁂ K))
_∘ʳ_ {C = C} {D = D} {E} {F} {G} η K = record
{ α = λ c → DinaturalTransformation.α η (K.F₀ c)
; commute = λ {c} {c′} f → begin
G.F₁ (K.F₁ f , K.F₁ E.id) D.∘ η.α (K.F₀ c′) D.∘ F.F₁ (K.F₁ E.id , K.F₁ f)
↓⟨ G.F-resp-≡ (C.Equiv.refl , K.identity) ⟩∘⟨ D.Equiv.refl ⟩∘⟨ F.F-resp-≡ (K.identity , C.Equiv.refl) ⟩
G.F₁ (K.F₁ f , C.id) D.∘ η.α (K.F₀ c′) D.∘ F.F₁ (C.id , K.F₁ f)
↓⟨ DinaturalTransformation.commute η (K.F₁ f) ⟩
G.F₁ (C.id , K.F₁ f) D.∘ η.α (K.F₀ c) D.∘ F.F₁ (K.F₁ f , C.id)
↑⟨ G.F-resp-≡ (K.identity , C.Equiv.refl) ⟩∘⟨ D.Equiv.refl ⟩∘⟨ F.F-resp-≡ (C.Equiv.refl , K.identity) ⟩
G.F₁ (K.F₁ E.id , K.F₁ f) D.∘ η.α (K.F₀ c) D.∘ F.F₁ (K.F₁ f , K.F₁ E.id)
∎
}
where
module K = Functor K
module C = Category C
module D = Category D
module E = Category E
module F = Functor F
module G = Functor G
module η = DinaturalTransformation η
open D.HomReasoning
|
{
"alphanum_fraction": 0.5217131474,
"avg_line_length": 42.905982906,
"ext": "agda",
"hexsha": "226a5971297b7c8edd60d17d396d3b990280e88d",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/DinaturalTransformation.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/DinaturalTransformation.agda",
"max_line_length": 158,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/DinaturalTransformation.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 2136,
"size": 5020
}
|
------------------------------------------------------------------------------
-- Proving that two group theory formalisations are equivalents
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- We prove that group theory axioms based on the signature (G, ·, ε,)
-- (see for example [p. 39, 1]), i.e.
-- ∀ a b c. abc = a(bc)
-- ∀ a. εa = aε = a
-- ∀ a. ∃ a'. a'a = aa' = ε
-- are equivalents to the axioms based on the signature (G, ·, _⁻¹, ε,)
-- (see for example [2,3]), i.e.
-- ∀ a b c. abc = a(bc)
-- ∀ a. εa = aε = a
-- ∀ a. a⁻¹a = aa⁻¹ = ε
-- [1] C. C. Chang and H. J. Keisler. Model Theory, volume 73 of Studies
-- in Logic and the Foundations of Mathematics. North-Holland, 3rd
-- edition, 3rd impression 1992.
-- [2] Agda standard library_0.8.1 (see Algebra/Structures.agda)
-- [3] Coq implementation
-- (http://coq.inria.fr/pylons/contribs/files/GroupTheory/v8.3/GroupTheory.g1.html)
module FOT.GroupTheory.FormalisationsSL where
open import Data.Product
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------------
-- NB. We only write the proof for the left-inverse property.
infixl 10 _·_ -- The symbol is '\cdot'.
postulate
G : Set -- The universe
ε : G -- The identity element.
_·_ : G → G → G -- The binary operation.
-- Left-inverse property based on the signature (G, ·, ε,).
leftInverse₁ : Set
leftInverse₁ = ∀ a → Σ G (λ a' → a' · a ≡ ε)
-- Left-inverse property based on the signature (G, ·, _⁻¹, ε,).
infix 11 _⁻¹
postulate _⁻¹ : G → G -- The inverse function.
leftInverse₂ : Set
leftInverse₂ = ∀ a → a ⁻¹ · a ≡ ε
-- From the left-inverse property based on the signature (G, ·, _⁻¹, ε,)
-- to the one based on the signature (G, ·, ε,).
leftInverse₂₋₁ : leftInverse₂ → leftInverse₁
leftInverse₂₋₁ h a = (a ⁻¹) , (h a)
-- From the left-inverse property based on the signature (G, ·, ε,) to
-- the one based on the signature (G, ·, _⁻¹, ε,).
--
-- In this case we prove the existence of the inverse function.
leftInverse₁₋₂ : leftInverse₁ → Σ (G → G) (λ f → ∀ a → f a · a ≡ ε)
leftInverse₁₋₂ h = f , prf
where
f : G → G -- The inverse function.
f a = proj₁ (h a)
prf : ∀ a → f a · a ≡ ε
prf a = proj₂ (h a)
|
{
"alphanum_fraction": 0.5536654516,
"avg_line_length": 30.1097560976,
"ext": "agda",
"hexsha": "dc7766198371bc669abd46421c4534dd983e1836",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/GroupTheory/FormalisationsSL.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/GroupTheory/FormalisationsSL.agda",
"max_line_length": 87,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/GroupTheory/FormalisationsSL.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 754,
"size": 2469
}
|
-- Record constructors are not allowed in patterns.
module RecordConstructorPatternMatching where
record R : Set₁ where
constructor con
field
{A} : Set
f : A → A
{B C} D {E} : Set
g : B → C → E
id : R → R
id (con f D g) = con f D g
|
{
"alphanum_fraction": 0.5477031802,
"avg_line_length": 18.8666666667,
"ext": "agda",
"hexsha": "7051d8ff0c2ac8eb35844f381710833a88b1e01e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/RecordConstructorPatternMatching.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/RecordConstructorPatternMatching.agda",
"max_line_length": 51,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/RecordConstructorPatternMatching.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 87,
"size": 283
}
|
{-# OPTIONS --cubical-compatible #-}
mutual
data D : Set → Set₁ where
c : (@0 A : Set) → _ → D _
_ : (@0 A : Set) → A → D A
_ = c
|
{
"alphanum_fraction": 0.4685314685,
"avg_line_length": 14.3,
"ext": "agda",
"hexsha": "759619742864582fb1e48a9c71b94f72eb2219d4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Fail/Issue5434-3.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Fail/Issue5434-3.agda",
"max_line_length": 36,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Fail/Issue5434-3.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 55,
"size": 143
}
|
{- Name: Bowornmet (Ben) Hudson
-- new source language module. trying stuff out
-}
open import Preliminaries
open import Preorder-withmax
module Source2 where
data Tp : Set where
unit : Tp
nat : Tp
susp : Tp → Tp
_->s_ : Tp → Tp → Tp
_×s_ : Tp → Tp → Tp
list : Tp → Tp
bool : Tp
Ctx = List Tp
-- de Bruijn indices
data _∈_ : Tp → Ctx → Set where
i0 : ∀ {Γ τ} → τ ∈ τ :: Γ
iS : ∀ {Γ τ τ1} → τ ∈ Γ → τ ∈ τ1 :: Γ
data _|-_ : Ctx → Tp → Set where
unit : ∀ {Γ} → Γ |- unit
var : ∀ {Γ τ}
→ τ ∈ Γ
→ Γ |- τ
z : ∀ {Γ} → Γ |- nat
suc : ∀ {Γ}
→ (e : Γ |- nat)
→ Γ |- nat
rec : ∀ {Γ τ} → Γ |- nat → Γ |- τ → (nat :: (susp τ :: Γ)) |- τ
→ Γ |- τ
lam : ∀ {Γ τ ρ} → (ρ :: Γ) |- τ
→ Γ |- (ρ ->s τ)
app : ∀ {Γ τ1 τ2}
→ Γ |- (τ2 ->s τ1) → Γ |- τ2
→ Γ |- τ1
prod : ∀ {Γ τ1 τ2}
→ Γ |- τ1 → Γ |- τ2
→ Γ |- (τ1 ×s τ2)
delay : ∀ {Γ τ}
→ Γ |- τ
→ Γ |- susp τ
force : ∀ {Γ τ}
→ Γ |- susp τ
→ Γ |- τ
split : ∀ {Γ τ τ1 τ2}
→ Γ |- (τ1 ×s τ2) → (τ1 :: (τ2 :: Γ)) |- τ
→ Γ |- τ
nil : ∀ {Γ τ} → Γ |- list τ
_::s_ : ∀ {Γ τ} → Γ |- τ → Γ |- list τ → Γ |- list τ
listrec : ∀ {Γ τ τ'} → Γ |- list τ → Γ |- τ' → (τ :: (list τ :: (susp τ' :: Γ))) |- τ' → Γ |- τ'
true : ∀ {Γ} → Γ |- bool
false : ∀ {Γ} → Γ |- bool
module RenSubst where
-- renaming = variable for variable substitution
--functional view:
--avoids induction,
--some associativity/unit properties for free
module Ren where
-- read: you can rename Γ' as Γ
rctx : Ctx → Ctx → Set
rctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → τ ∈ Γ
rename-var : ∀ {Γ Γ' τ} → rctx Γ Γ' → τ ∈ Γ' → τ ∈ Γ
rename-var ρ a = ρ a
idr : ∀ {Γ} → rctx Γ Γ
idr x = x
-- weakening with renaming
p∙ : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) Γ'
p∙ ρ = λ x → iS (ρ x)
p : ∀ {Γ τ} → rctx (τ :: Γ) Γ
p = p∙ idr
_∙rr_ : ∀ {A B C} → rctx A B → rctx B C → rctx A C
ρ1 ∙rr ρ2 = ρ1 o ρ2
-- free stuff
rename-var-ident : ∀ {Γ τ} → (x : τ ∈ Γ) → rename-var idr x == x
rename-var-ident _ = Refl
rename-var-∙ : ∀ {A B C τ} → (r1 : rctx A B) (r2 : rctx B C) (x : τ ∈ C)
→ rename-var r1 (rename-var r2 x) == rename-var (r1 ∙rr r2) x
rename-var-∙ _ _ _ = Refl
∙rr-assoc : ∀ {A B C D} → (r1 : rctx A B) (r2 : rctx B C) (r3 : rctx C D) → _==_ {_} {rctx A D} (r1 ∙rr (r2 ∙rr r3)) ((r1 ∙rr r2) ∙rr r3)
∙rr-assoc r1 r2 r3 = Refl
r-extend : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ')
r-extend ρ i0 = i0
r-extend ρ (iS x) = iS (ρ x)
ren : ∀ {Γ Γ' τ} → Γ' |- τ → rctx Γ Γ' → Γ |- τ
ren unit ρ = unit
ren (var x) ρ = var (ρ x)
ren z ρ = z
ren (suc e) ρ = suc (ren e ρ)
ren (rec e e₁ e₂) ρ = rec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend ρ)))
ren (lam e) ρ = lam (ren e (r-extend ρ))
ren (app e e₁) ρ = app (ren e ρ) (ren e₁ ρ)
ren (prod e1 e2) ρ = prod (ren e1 ρ) (ren e2 ρ)
ren (delay e) ρ = delay (ren e ρ)
ren (force e) ρ = force (ren e ρ)
ren (split e e₁) ρ = split (ren e ρ) (ren e₁ (r-extend (r-extend ρ)))
-- list stuff
ren nil ρ = nil
ren (x ::s xs) ρ = ren x ρ ::s ren xs ρ
ren true ρ = true
ren false ρ = false
ren (listrec e e₁ e₂) ρ = listrec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend (r-extend ρ))))
extend-ren-comp-lemma : ∀ {Γ Γ' Γ'' τ τ'} → (x : τ ∈ τ' :: Γ'') (ρ1 : rctx Γ Γ') (ρ2 : rctx Γ' Γ'')
→ Id {_} {_} ((r-extend ρ1 ∙rr r-extend ρ2) x) (r-extend (ρ1 ∙rr ρ2) x)
extend-ren-comp-lemma i0 ρ1 ρ2 = Refl
extend-ren-comp-lemma (iS x) ρ1 ρ2 = Refl
extend-ren-comp : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'')
→ Id {_} {rctx (τ :: Γ) (τ :: Γ'')} (r-extend ρ1 ∙rr r-extend ρ2) (r-extend (ρ1 ∙rr ρ2))
extend-ren-comp ρ1 ρ2 = λ=i (λ τ → λ= (λ x → extend-ren-comp-lemma x ρ1 ρ2))
ren-comp : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'') → (e : Γ'' |- τ)
→ (ren (ren e ρ2) ρ1) == (ren e (ρ1 ∙rr ρ2))
ren-comp ρ1 ρ2 unit = Refl
ren-comp ρ1 ρ2 (var x) = ap var (rename-var-∙ ρ1 ρ2 x)
ren-comp ρ1 ρ2 z = Refl
ren-comp ρ1 ρ2 (suc e) = ap suc (ren-comp ρ1 ρ2 e)
ren-comp ρ1 ρ2 (rec e e₁ e₂) = ap3 rec (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
(ap (ren e₂) (ap r-extend (extend-ren-comp ρ1 ρ2) ∘
extend-ren-comp (r-extend ρ1) (r-extend ρ2)) ∘
ren-comp (r-extend (r-extend ρ1)) (r-extend (r-extend ρ2)) e₂)
ren-comp ρ1 ρ2 (lam e) = ap lam ((ap (ren e) (extend-ren-comp ρ1 ρ2)) ∘ ren-comp (r-extend ρ1) (r-extend ρ2) e)
ren-comp ρ1 ρ2 (app e e₁) = ap2 app (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
ren-comp ρ1 ρ2 (prod e e₁) = ap2 prod (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
ren-comp ρ1 ρ2 (delay e) = ap delay (ren-comp ρ1 ρ2 e)
ren-comp ρ1 ρ2 (force e) = ap force (ren-comp ρ1 ρ2 e)
ren-comp ρ1 ρ2 (split e e₁) = ap2 split (ren-comp ρ1 ρ2 e)
(ap (ren e₁) (ap r-extend (extend-ren-comp ρ1 ρ2) ∘
extend-ren-comp (r-extend ρ1) (r-extend ρ2)) ∘
ren-comp (r-extend (r-extend ρ1)) (r-extend (r-extend ρ2)) e₁)
ren-comp ρ1 ρ2 nil = Refl
ren-comp ρ1 ρ2 (e ::s e₁) = ap2 _::s_ (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
ren-comp ρ1 ρ2 (listrec e e₁ e₂) = ap3 listrec (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
(ap (ren e₂) (ap r-extend (ap r-extend (extend-ren-comp ρ1 ρ2)) ∘
(ap r-extend (extend-ren-comp (r-extend ρ1) (r-extend ρ2)) ∘
extend-ren-comp (r-extend (r-extend ρ1)) (r-extend (r-extend ρ2)))) ∘
ren-comp (r-extend (r-extend (r-extend ρ1)))
(r-extend (r-extend (r-extend ρ2))) e₂)
ren-comp ρ1 ρ2 true = Refl
ren-comp ρ1 ρ2 false = Refl
-- weakening a context
wkn : ∀ {Γ τ1 τ2} → Γ |- τ2 → (τ1 :: Γ) |- τ2
wkn e = ren e iS
open Ren
sctx : Ctx → Ctx → Set
sctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → Γ |- τ
--lem2 (addvar)
s-extend : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) (τ :: Γ')
s-extend Θ i0 = var i0
s-extend Θ (iS x) = wkn (Θ x)
ids : ∀ {Γ} → sctx Γ Γ
ids x = var x
-- weakening with substitution
q∙ : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) Γ'
q∙ Θ = λ x → wkn (Θ x)
lem3' : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ |- τ → sctx Γ (τ :: Γ')
lem3' Θ e i0 = e
lem3' Θ e (iS i) = Θ i
--lem3
q : ∀ {Γ τ} → Γ |- τ → sctx Γ (τ :: Γ)
q e = lem3' ids e
-- subst-var
svar : ∀ {Γ1 Γ2 τ} → sctx Γ1 Γ2 → τ ∈ Γ2 → Γ1 |- τ
svar Θ i = q (Θ i) i0
lem4' : ∀ {Γ Γ' τ1 τ2} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ'))
lem4' Θ a b = lem3' (lem3' Θ b) a
lem4 : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ))
lem4 e1 e2 = lem4' ids e1 e2
subst : ∀ {Γ Γ' τ} → Γ' |- τ → sctx Γ Γ' → Γ |- τ
subst unit Θ = unit
subst (var x) Θ = Θ x
subst z Θ = z
subst (suc e) Θ = suc (subst e Θ)
subst (rec e e₁ e₂) Θ = rec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend Θ)))
subst (lam e) Θ = lam (subst e (s-extend Θ))
subst (app e e₁) Θ = app (subst e Θ) (subst e₁ Θ)
subst (prod e1 e2) Θ = prod (subst e1 Θ) (subst e2 Θ)
subst (delay e) Θ = delay (subst e Θ)
subst (force e) Θ = force (subst e Θ)
subst (split e e₁) Θ = split (subst e Θ) (subst e₁ (s-extend (s-extend Θ)))
-- list stuff
subst nil Θ = nil
subst (x ::s xs) Θ = subst x Θ ::s subst xs Θ
subst true Θ = true
subst false Θ = false
subst (listrec e e₁ e₂) Θ = listrec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend (s-extend Θ))))
subst1 : ∀ {Γ τ τ1} → Γ |- τ1 → (τ1 :: Γ) |- τ → Γ |- τ
subst1 e e' = subst e' (q e)
_rs_ : ∀ {A B C} → rctx A B → sctx B C → sctx A C
_rs_ ρ Θ x = ren (subst (var x) Θ) ρ
_ss_ : ∀ {A B C} → sctx A B → sctx B C → sctx A C
_ss_ Θ1 Θ2 x = subst (subst (var x) Θ2) Θ1
_sr_ : ∀ {A B C} → sctx A B → rctx B C → sctx A C
_sr_ Θ ρ x = subst (ren (var x) ρ) Θ
--free stuff
svar-rs : ∀ {A B C τ} (ρ : rctx A B) (Θ : sctx B C) (x : τ ∈ C)
→ svar (ρ rs Θ) x == ren (svar Θ x) ρ
svar-rs = λ ρ Θ x → Refl
svar-ss : ∀ {A B C τ} (Θ1 : sctx A B) (Θ2 : sctx B C) (x : τ ∈ C)
→ svar (Θ1 ss Θ2) x == subst (svar Θ2 x) Θ1
svar-ss = λ Θ1 Θ2 x → Refl
svar-sr : ∀ {A B C τ} (Θ : sctx A B) (ρ : rctx B C) (x : τ ∈ C)
→ svar Θ (rename-var ρ x) == svar (Θ sr ρ) x
svar-sr = λ Θ ρ x → Refl
svar-id : ∀ {Γ τ} → (x : τ ∈ Γ) → var x == svar ids x
svar-id = λ x → Refl
rsr-assoc : ∀ {A B C D} → (ρ1 : rctx A B) (Θ : sctx B C) (ρ2 : rctx C D)
→ Id {_} {sctx A D} ((ρ1 rs Θ) sr ρ2) (ρ1 rs (Θ sr ρ2))
rsr-assoc = λ ρ1 Θ ρ2 → Refl
extend-id-once-lemma : ∀ {Γ τ τ'} → (x : τ ∈ τ' :: Γ) → _==_ {_} {τ' :: Γ |- τ}
(ids {τ' :: Γ} {τ} x) (s-extend {Γ} {Γ} {τ'} (ids {Γ}) {τ} x)
extend-id-once-lemma i0 = Refl
extend-id-once-lemma (iS x) = Refl
extend-id-once : ∀ {Γ τ} → Id {_} {sctx (τ :: Γ) (τ :: Γ)} (ids {τ :: Γ}) (s-extend ids)
extend-id-once = λ=i (λ τ → λ= (λ x → extend-id-once-lemma x))
extend-id-twice : ∀ {Γ τ1 τ2} → Id {_} {sctx (τ1 :: τ2 :: Γ) (τ1 :: τ2 :: Γ)} (ids {τ1 :: τ2 :: Γ}) (s-extend (s-extend ids))
extend-id-twice = ap s-extend extend-id-once ∘ extend-id-once
subst-id : ∀ {Γ τ} (e : Γ |- τ) → e == subst e ids
subst-id unit = Refl
subst-id (var x) = svar-id x
subst-id z = Refl
subst-id (suc e) = ap suc (subst-id e)
subst-id (rec e e₁ e₂) = ap3 rec (subst-id e) (subst-id e₁) (ap (subst e₂) extend-id-twice ∘ subst-id e₂)
subst-id (lam e) = ap lam (ap (subst e) extend-id-once ∘ subst-id e)
subst-id (app e e₁) = ap2 app (subst-id e) (subst-id e₁)
subst-id (prod e e₁) = ap2 prod (subst-id e) (subst-id e₁)
subst-id (delay e) = ap delay (subst-id e)
subst-id (force e) = ap force (subst-id e)
subst-id (split e e₁) = ap2 split (subst-id e) (ap (subst e₁) extend-id-twice ∘ subst-id e₁)
subst-id nil = Refl
subst-id (e ::s e₁) = ap2 _::s_ (subst-id e) (subst-id e₁)
subst-id true = Refl
subst-id false = Refl
subst-id (listrec e e₁ e₂) = ap3 listrec (subst-id e) (subst-id e₁) (ap (subst e₂) (ap s-extend (ap s-extend extend-id-once) ∘ extend-id-twice) ∘ subst-id e₂)
extend-rs-once-lemma : ∀ {A B C τ τ'} → (x : τ ∈ τ' :: B) (ρ : rctx C A) (Θ : sctx A B) → _==_ {_} {τ' :: C |- τ}
(_rs_ {τ' :: C} {τ' :: A} {τ' :: B} (r-extend {C} {A} {τ'} ρ)
(s-extend {A} {B} {τ'} Θ) {τ} x)
(s-extend {C} {B} {τ'} (_rs_ {C} {A} {B} ρ Θ) {τ} x)
extend-rs-once-lemma i0 ρ Θ = Refl
extend-rs-once-lemma (iS x) ρ Θ = ! (ren-comp iS ρ (Θ x)) ∘ ren-comp (r-extend ρ) iS (Θ x)
extend-rs-once : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B)
→ Id {_} {sctx (τ :: C) (τ :: B)} (r-extend ρ rs s-extend Θ) (s-extend (ρ rs Θ))
extend-rs-once ρ Θ = λ=i (λ τ → λ= (λ x → extend-rs-once-lemma x ρ Θ))
extend-rs-twice : ∀ {A B C τ τ'} → (ρ : rctx C A) (Θ : sctx A B)
→ Id {_} {sctx (τ :: τ' :: C) (τ :: τ' :: B)} ((r-extend (r-extend ρ)) rs (s-extend (s-extend Θ))) ((s-extend (s-extend (ρ rs Θ))))
extend-rs-twice ρ Θ = ap s-extend (extend-rs-once ρ Θ) ∘ extend-rs-once (r-extend ρ) (s-extend Θ)
subst-rs : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B) (e : B |- τ)
→ ren (subst e Θ) ρ == subst e (ρ rs Θ)
subst-rs ρ Θ unit = Refl
subst-rs ρ Θ (var x) = svar-rs ρ Θ x
subst-rs ρ Θ z = Refl
subst-rs ρ Θ (suc e) = ap suc (subst-rs ρ Θ e)
subst-rs ρ Θ (rec e e₁ e₂) = ap3 rec (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
(ap (subst e₂) (extend-rs-twice ρ Θ) ∘
subst-rs (r-extend (r-extend ρ)) (s-extend (s-extend Θ)) e₂)
subst-rs ρ Θ (lam e) = ap lam (ap (subst e) (extend-rs-once ρ Θ) ∘ subst-rs (r-extend ρ) (s-extend Θ) e)
subst-rs ρ Θ (app e e₁) = ap2 app (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
subst-rs ρ Θ (prod e e₁) = ap2 prod (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
subst-rs ρ Θ (delay e) = ap delay (subst-rs ρ Θ e)
subst-rs ρ Θ (force e) = ap force (subst-rs ρ Θ e)
subst-rs ρ Θ (split e e₁) = ap2 split (subst-rs ρ Θ e)
(ap (subst e₁) (extend-rs-twice ρ Θ) ∘
subst-rs (r-extend (r-extend ρ)) (s-extend (s-extend Θ)) e₁)
subst-rs ρ Θ nil = Refl
subst-rs ρ Θ (e ::s e₁) = ap2 _::s_ (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
subst-rs ρ Θ true = Refl
subst-rs ρ Θ false = Refl
subst-rs ρ Θ (listrec e e₁ e₂) = ap3 listrec (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
(ap (subst e₂) (ap s-extend (ap s-extend (extend-rs-once ρ Θ)) ∘
extend-rs-twice (r-extend ρ) (s-extend Θ)) ∘
subst-rs (r-extend (r-extend (r-extend ρ))) (s-extend (s-extend (s-extend Θ))) e₂)
rs-comp : ∀ {Γ Γ' Γ'' τ} → (ρ : rctx Γ Γ') → (Θ : sctx Γ' Γ'') → (e : Γ'' |- τ)
→ (ren (subst e Θ) ρ) == subst e (ρ rs Θ)
rs-comp ρ Θ unit = Refl
rs-comp ρ Θ (var x) = svar-rs ρ Θ x
rs-comp ρ Θ z = Refl
rs-comp ρ Θ (suc e) = ap suc (rs-comp ρ Θ e)
rs-comp ρ Θ (rec e e₁ e₂) = ap3 rec (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
(ap (subst e₂) (extend-rs-twice ρ Θ) ∘ rs-comp (r-extend (r-extend ρ)) (s-extend (s-extend Θ)) e₂)
rs-comp ρ Θ (lam e) = ap lam (ap (subst e) (extend-rs-once ρ Θ) ∘ rs-comp (r-extend ρ) (s-extend Θ) e)
rs-comp ρ Θ (app e e₁) = ap2 app (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
rs-comp ρ Θ (prod e e₁) = ap2 prod (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
rs-comp ρ Θ (delay e) = ap delay (rs-comp ρ Θ e)
rs-comp ρ Θ (force e) = ap force (rs-comp ρ Θ e)
rs-comp ρ Θ (split e e₁) = ap2 split (rs-comp ρ Θ e) (ap (subst e₁) (extend-rs-twice ρ Θ) ∘ rs-comp (r-extend (r-extend ρ)) (s-extend (s-extend Θ)) e₁)
rs-comp ρ Θ nil = Refl
rs-comp ρ Θ (e ::s e₁) = ap2 _::s_ (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
rs-comp ρ Θ (listrec e e₁ e₂) = ap3 listrec (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
(ap (subst e₂) (ap s-extend (ap s-extend (extend-rs-once ρ Θ)) ∘
extend-rs-twice (r-extend ρ) (s-extend Θ)) ∘
rs-comp (r-extend (r-extend (r-extend ρ)))
(s-extend (s-extend (s-extend Θ))) e₂)
rs-comp ρ Θ true = Refl
rs-comp ρ Θ false = Refl
extend-sr-once-lemma : ∀ {A B C τ τ'} → (Θ : sctx A B) (ρ : rctx B C) (x : τ ∈ τ' :: C)
→ _==_ {_} {τ' :: A |- τ} (s-extend (_sr_ Θ ρ) x) (_sr_ (s-extend Θ) (r-extend ρ) x)
extend-sr-once-lemma Θ ρ i0 = Refl
extend-sr-once-lemma Θ ρ (iS x) = Refl
extend-sr-once : ∀ {A B C τ} → (Θ : sctx A B) (ρ : rctx B C)
→ Id {_} {sctx (τ :: A) (τ :: C)} (s-extend Θ sr r-extend ρ) (s-extend (Θ sr ρ))
extend-sr-once Θ ρ = λ=i (λ τ → λ= (λ x → ! (extend-sr-once-lemma Θ ρ x)))
extend-sr-twice : ∀ {A B C τ τ'} → (Θ : sctx A B) (ρ : rctx B C)
→ Id {_} {sctx (τ' :: τ :: A) (τ' :: τ :: C)}
(s-extend (s-extend Θ) sr r-extend (r-extend ρ)) (s-extend (s-extend (Θ sr ρ)))
extend-sr-twice Θ ρ = ap s-extend (extend-sr-once Θ ρ) ∘ extend-sr-once (s-extend Θ) (r-extend ρ)
sr-comp : ∀ {Γ Γ' Γ'' τ} → (Θ : sctx Γ Γ') → (ρ : rctx Γ' Γ'') → (e : Γ'' |- τ)
→ (subst (ren e ρ) Θ) == subst e (Θ sr ρ)
sr-comp Θ ρ unit = Refl
sr-comp Θ ρ (var x) = svar-sr Θ ρ x
sr-comp Θ ρ z = Refl
sr-comp Θ ρ (suc e) = ap suc (sr-comp Θ ρ e)
sr-comp Θ ρ (rec e e₁ e₂) = ap3 rec (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
(ap (subst e₂) (ap s-extend (extend-sr-once Θ ρ) ∘
extend-sr-once (s-extend Θ) (r-extend ρ)) ∘
sr-comp (s-extend (s-extend Θ)) (r-extend (r-extend ρ)) e₂)
sr-comp Θ ρ (lam e) = ap lam (ap (subst e) (extend-sr-once Θ ρ) ∘ sr-comp (s-extend Θ) (r-extend ρ) e)
sr-comp Θ ρ (app e e₁) = ap2 app (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
sr-comp Θ ρ (prod e e₁) = ap2 prod (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
sr-comp Θ ρ (delay e) = ap delay (sr-comp Θ ρ e)
sr-comp Θ ρ (force e) = ap force (sr-comp Θ ρ e)
sr-comp Θ ρ (split e e₁) = ap2 split (sr-comp Θ ρ e) (ap (subst e₁) (ap s-extend (extend-sr-once Θ ρ) ∘
extend-sr-once (s-extend Θ) (r-extend ρ)) ∘
sr-comp (s-extend (s-extend Θ)) (r-extend (r-extend ρ)) e₁)
sr-comp Θ ρ nil = Refl
sr-comp Θ ρ (e ::s e₁) = ap2 _::s_ (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
sr-comp Θ ρ (listrec e e₁ e₂) = ap3 listrec (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
(ap (subst e₂) (ap s-extend (ap s-extend (extend-sr-once Θ ρ)) ∘
extend-sr-twice (s-extend Θ) (r-extend ρ)) ∘
sr-comp (s-extend (s-extend (s-extend Θ)))
(r-extend (r-extend (r-extend ρ))) e₂)
sr-comp Θ ρ true = Refl
sr-comp Θ ρ false = Refl
extend-ss-once-lemma : ∀ {A B C τ τ'} → (Θ1 : sctx A B) (Θ2 : sctx B C) (x : τ ∈ τ' :: C)
→ _==_ {_} {τ' :: A |- τ} (s-extend (_ss_ Θ1 Θ2) x) (_ss_ (s-extend Θ1) (s-extend Θ2) x)
extend-ss-once-lemma Θ1 Θ2 i0 = Refl
extend-ss-once-lemma Θ1 Θ2 (iS x) = ! (sr-comp (s-extend Θ1) iS (Θ2 x)) ∘ rs-comp iS Θ1 (Θ2 x)
extend-ss-once : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C)
→ _==_ {_} {sctx (τ :: A) (τ :: C)} (s-extend (Θ1 ss Θ2))
((s-extend Θ1) ss
(s-extend Θ2))
extend-ss-once Θ1 Θ2 = λ=i (λ τ → λ= (λ x → extend-ss-once-lemma Θ1 Θ2 x))
subst-ss : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C) (e : C |- τ)
→ subst e (Θ1 ss Θ2) == subst (subst e Θ2) Θ1
subst-ss Θ1 Θ2 unit = Refl
subst-ss Θ1 Θ2 (var x) = svar-ss Θ1 Θ2 x
subst-ss Θ1 Θ2 z = Refl
subst-ss Θ1 Θ2 (suc e) = ap suc (subst-ss Θ1 Θ2 e)
subst-ss Θ1 Θ2 (rec e e₁ e₂) = ap3 rec (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
(subst-ss (s-extend (s-extend Θ1)) (s-extend (s-extend Θ2)) e₂ ∘
ap (subst e₂) (extend-ss-once (s-extend Θ1) (s-extend Θ2) ∘
ap s-extend (extend-ss-once Θ1 Θ2)))
subst-ss Θ1 Θ2 (lam e) = ap lam (subst-ss (s-extend Θ1) (s-extend Θ2) e ∘ ap (subst e) (extend-ss-once Θ1 Θ2))
subst-ss Θ1 Θ2 (app e e₁) = ap2 app (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
subst-ss Θ1 Θ2 (prod e e₁) = ap2 prod (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
subst-ss Θ1 Θ2 (delay e) = ap delay (subst-ss Θ1 Θ2 e)
subst-ss Θ1 Θ2 (force e) = ap force (subst-ss Θ1 Θ2 e)
subst-ss Θ1 Θ2 (split e e₁) = ap2 split (subst-ss Θ1 Θ2 e)
(subst-ss (s-extend (s-extend Θ1)) (s-extend (s-extend Θ2)) e₁ ∘
ap (subst e₁) (extend-ss-once (s-extend Θ1) (s-extend Θ2) ∘
ap s-extend (extend-ss-once Θ1 Θ2)))
subst-ss Θ1 Θ2 nil = Refl
subst-ss Θ1 Θ2 (e ::s e₁) = ap2 _::s_ (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
subst-ss Θ1 Θ2 true = Refl
subst-ss Θ1 Θ2 false = Refl
subst-ss Θ1 Θ2 (listrec e e₁ e₂) = ap3 listrec (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
(subst-ss (s-extend (s-extend (s-extend Θ1))) (s-extend (s-extend (s-extend Θ2))) e₂ ∘
ap (subst e₂) (extend-ss-once (s-extend (s-extend Θ1)) (s-extend (s-extend Θ2)) ∘
ap s-extend (extend-ss-once (s-extend Θ1) (s-extend Θ2) ∘
ap s-extend (extend-ss-once Θ1 Θ2))))
throw : ∀ {Γ Γ' τ} → sctx Γ (τ :: Γ') → sctx Γ Γ'
throw Θ x = Θ (iS x)
fuse1 : ∀ {Γ Γ' τ τ'} (v : Γ |- τ') (Θ : sctx Γ Γ') (x : τ ∈ Γ') → (q v ss q∙ Θ) x == Θ x
fuse1 v Θ x = subst (ren (Θ x) iS) (q v) =⟨ sr-comp (q v) iS (Θ x) ⟩
subst (Θ x) (q v sr iS) =⟨ Refl ⟩
subst (Θ x) ids =⟨ ! (subst-id (Θ x)) ⟩
(Θ x ∎)
subst-compose-lemma-lemma : ∀ {Γ Γ' τ τ'} (v : Γ |- τ') (Θ : sctx Γ Γ') (x : τ ∈ τ' :: Γ')
→ _==_ {_} {Γ |- τ} (_ss_ (q v) (s-extend Θ) x) (lem3' Θ v x)
subst-compose-lemma-lemma v Θ i0 = Refl
subst-compose-lemma-lemma v Θ (iS x) = subst (wkn (subst (var x) Θ)) (lem3' ids v) =⟨ subst-ss (q v) (q∙ Θ) (var x) ⟩
subst (var x) (q v ss q∙ Θ) =⟨ fuse1 v Θ x ⟩
subst (var x) Θ =⟨ Refl ⟩
Θ x ∎
fuse2 : ∀ {Γ Γ' τ τ1 τ2} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (Θ : sctx Γ Γ') (x : τ ∈ τ2 :: Γ')
→ (lem4 v1 v2 ss throw (s-extend (s-extend Θ))) x == (lem3' Θ v2) x
fuse2 v1 v2 Θ x = subst (ren (s-extend Θ x) iS) (lem4 v1 v2) =⟨ sr-comp (lem4 v1 v2) iS (s-extend Θ x) ⟩
subst (s-extend Θ x) (lem4 v1 v2 sr iS) =⟨ Refl ⟩
subst (s-extend Θ x) (lem3' ids v2) =⟨ subst-compose-lemma-lemma v2 Θ x ⟩
(lem3' Θ v2 x ∎)
subst-compose-lemma : ∀ {Γ Γ' τ} (v : Γ |- τ) (Θ : sctx Γ Γ')
→ _==_ {_} {sctx Γ (τ :: Γ')} ((q v) ss (s-extend Θ)) (lem3' Θ v)
subst-compose-lemma v Θ = λ=i (λ τ → λ= (λ x → subst-compose-lemma-lemma v Θ x))
subst-compose : ∀ {Γ Γ' τ τ1} (Θ : sctx Γ Γ') (v : Γ |- τ) (e : (τ :: Γ' |- τ1) )
→ subst (subst e (s-extend Θ)) (q v) == subst e (lem3' Θ v)
subst-compose Θ v e = ap (subst e) (subst-compose-lemma v Θ) ∘ (! (subst-ss (q v) (s-extend Θ) e))
subst-compose2-lemma-lemma : ∀ {Γ Γ' τ τ1 τ2 τ'} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (e1 : τ1 :: τ2 :: Γ' |- τ) (Θ : sctx Γ Γ') (x : τ' ∈ τ1 :: τ2 :: Γ')
→ _==_ {_} {_} ((lem4 v1 v2 ss s-extend (s-extend Θ)) x) (lem4' Θ v1 v2 x)
subst-compose2-lemma-lemma v1 v2 e1 Θ i0 = Refl
subst-compose2-lemma-lemma v1 v2 e1 Θ (iS x) = subst (wkn (s-extend Θ x)) (lem4 v1 v2) =⟨ Refl ⟩
subst (var x) (lem4 v1 v2 ss throw (s-extend (s-extend Θ))) =⟨ fuse2 v1 v2 Θ x ⟩
subst (var x) (lem3' Θ v2) =⟨ Refl ⟩
(lem3' Θ v2 x ∎)
subst-compose2-lemma : ∀ {Γ Γ' τ τ1 τ2} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (e1 : τ1 :: τ2 :: Γ' |- τ) (Θ : sctx Γ Γ')
→ _==_ {_} {sctx Γ (τ1 :: τ2 :: Γ')} (lem4 v1 v2 ss s-extend (s-extend Θ)) (lem4' Θ v1 v2)
subst-compose2-lemma v1 v2 e1 Θ = λ=i (λ τ → λ= (λ x → subst-compose2-lemma-lemma v1 v2 e1 Θ x))
subst-compose2 : ∀ {Γ Γ' τ} (Θ : sctx Γ Γ') (n : Γ |- nat) (e1 : Γ' |- τ) (e2 : (nat :: (susp τ :: Γ')) |- τ)
→ subst (subst e2 (s-extend (s-extend Θ))) (lem4 n (delay (rec n (subst e1 Θ) (subst e2 (s-extend (s-extend Θ)))))) ==
subst e2 (lem4' Θ n (delay (rec n (subst e1 Θ) (subst e2 (s-extend (s-extend Θ))))))
subst-compose2 Θ n e1 e2 = ap (subst e2) (subst-compose2-lemma n (delay (rec n (subst e1 Θ) (subst e2 (s-extend (s-extend Θ))))) e2 Θ) ∘
! (subst-ss (lem4 n (delay (rec n (subst e1 Θ) (subst e2 (s-extend (s-extend Θ)))))) (s-extend (s-extend Θ)) e2)
subst-compose3 : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2)
→ subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2) == subst e1 (lem4' Θ v1 v2)
subst-compose3 Θ e1 v1 v2 = ap (subst e1) (subst-compose2-lemma v1 v2 e1 Θ) ∘
! (subst-ss (lem4 v1 v2) (s-extend (s-extend Θ)) e1)
subst-compose4 : ∀ {Γ Γ' τ} (Θ : sctx Γ Γ') (v' : Γ |- nat) (r : Γ |- susp τ) (e2 : (nat :: (susp τ :: Γ')) |- τ)
→ subst (subst e2 (s-extend (s-extend Θ))) (lem4 v' r) == subst e2 (lem4' Θ v' r)
subst-compose4 Θ v' r e2 = ap (subst e2) (subst-compose2-lemma v' r e2 Θ) ∘
! (subst-ss (lem4 v' r) (s-extend (s-extend Θ)) e2)
open RenSubst
--closed values of the source language
data val : ∀ {τ} → [] |- τ → Set where
z-isval : val z
suc-isval : (e : [] |- nat) → (val e)
→ val (suc e)
pair-isval : ∀ {τ1 τ2} (e1 : [] |- τ1) → (e2 : [] |- τ2)
→ val e1 → val e2
→ val (prod e1 e2)
lam-isval : ∀ {ρ τ} (e : (ρ :: []) |- τ)
→ val (lam e)
unit-isval : val unit
delay-isval : ∀ {τ} (e : [] |- τ) → val (delay e)
nil-isval : ∀ {τ} → val (nil {_} {τ})
cons-isval : ∀ {τ} (x : [] |- τ) → (xs : [] |- list τ)
→ val x → val xs
→ val (x ::s xs)
true-isval : val true
false-isval : val false
data Cost : Set where
0c : Cost
1c : Cost
_+c_ : Cost → Cost → Cost
data Equals0c : Cost → Set where
Eq0-0c : Equals0c 0c
Eq0-+c : ∀ {c c'} → Equals0c c → Equals0c c' → Equals0c (c +c c')
mutual
-- define evals (e : source exp) (v : value) (c : nat)
-- analogous to "e evaluates to v in c steps"
-- figure 2 from ICFP paper
data evals : {τ : Tp} → [] |- τ → [] |- τ → Cost → Set where
pair-evals : ∀ {n1 n2}
→ {τ1 τ2 : Tp} {e1 v1 : [] |- τ1} {e2 v2 : [] |- τ2}
→ evals e1 v1 n1
→ evals e2 v2 n2
→ evals (prod e1 e2) (prod v1 v2) (n1 +c n2)
lam-evals : ∀ {ρ τ} {e : (ρ :: []) |- τ}
→ evals (lam e) (lam e) 0c
app-evals : ∀ {n0 n1 n}
→ {τ1 τ2 : Tp} {e0 : [] |- (τ1 ->s τ2)} {e0' : (τ1 :: []) |- τ2} {e1 v1 : [] |- τ1} {v : [] |- τ2}
→ evals e0 (lam e0') n0
→ evals e1 v1 n1
→ evals (subst e0' (q v1)) v n
→ evals (app e0 e1) v ((n0 +c n1) +c n)
z-evals : evals z z 0c
s-evals : ∀ {n}
→ {e v : [] |- nat}
→ evals e v n
→ evals (suc e) (suc v) n
unit-evals : evals unit unit 0c
rec-evals : ∀ {n1 n2}
→ {τ : Tp} {e v : [] |- nat} {e0 v' : [] |- τ} {e1 : (nat :: (susp τ :: [])) |- τ}
→ evals e v n1
→ evals-rec-branch e0 e1 v v' n2
→ evals (rec e e0 e1) v' (n1 +c (1c +c n2))
delay-evals : {τ : Tp} {e : [] |- τ}
→ evals (delay e) (delay e) 0c
force-evals : ∀ {n1 n2}
→ {τ : Tp} {e' v : [] |- τ} {e : [] |- susp τ}
→ evals e (delay e') n1
→ evals e' v n2
→ evals (force e) v (n1 +c n2)
split-evals : ∀ {n1 n2}
→ {τ τ1 τ2 : Tp} {e0 : [] |- (τ1 ×s τ2)} {v1 : [] |- τ1} {v2 : [] |- τ2} {e1 : (τ1 :: (τ2 :: [])) |- τ} {v : [] |- τ}
→ evals e0 (prod v1 v2) n1
→ evals (subst e1 (lem4 v1 v2)) v n2
→ evals (split e0 e1) v (n1 +c n2)
nil-evals : ∀ {τ : Tp} → evals (nil {_} {τ}) (nil {_} {τ}) 0c
cons-evals : ∀ {n1 n2}
→ {τ : Tp} {x v : [] |- τ} {xs vs : [] |- list τ}
→ evals x v n1
→ evals xs vs n2
→ evals (x ::s xs) (v ::s vs) (n1 +c n2)
true-evals : evals true true 0c
false-evals : evals false false 0c
-- means evals (rec v e0 e1) v' n
-- but helpful to have a separate type for this
data evals-rec-branch {τ : Tp} (e0 : [] |- τ) (e1 : (nat :: (susp τ :: [])) |- τ) : (e : [] |- nat) (v : [] |- τ) → Cost → Set where
evals-rec-z : ∀ {v n} → evals e0 v n → evals-rec-branch e0 e1 z v n
evals-rec-s : ∀ {v v' n} → evals (subst e1 (lem4 v (delay (rec v e0 e1)))) v' n
→ evals-rec-branch e0 e1 (suc v) v' n
evals-val : {τ : Tp} {e : [] |- τ} {v : [] |- τ} {n : Cost} → evals e v n → val v
evals-val (pair-evals D D₁) = pair-isval _ _ (evals-val D) (evals-val D₁)
evals-val lam-evals = lam-isval _
evals-val (app-evals D D₁ D₂) = evals-val D₂
evals-val z-evals = z-isval
evals-val (s-evals D) = suc-isval _ (evals-val D)
evals-val unit-evals = unit-isval
evals-val (rec-evals x (evals-rec-z D)) = evals-val D
evals-val (rec-evals x (evals-rec-s D)) = evals-val D
evals-val delay-evals = delay-isval _
evals-val (force-evals D D₁) = evals-val D₁
evals-val (split-evals D D₁) = evals-val D₁
evals-val nil-evals = nil-isval
evals-val (cons-evals D D₁) = cons-isval _ _ (evals-val D) (evals-val D₁)
evals-val true-evals = true-isval
evals-val false-evals = false-isval
-- lemma 2 from ICFP paper
val-evals-inversion : {τ : Tp} {v v' : [] |- τ} {n : Cost} → val v → evals v v' n → (v == v') × Equals0c n
val-evals-inversion z-isval z-evals = Refl , Eq0-0c
val-evals-inversion (suc-isval e ve) (s-evals D) = (ap suc (fst IH)) , snd IH where
IH = val-evals-inversion ve D
val-evals-inversion (pair-isval e1 e2 ve1 ve2) (pair-evals D D₁) = ap2 prod (fst IH1) (fst IH2) , Eq0-+c (snd IH1) (snd IH2) where
IH1 = val-evals-inversion ve1 D
IH2 = val-evals-inversion ve2 D₁
val-evals-inversion (lam-isval e) lam-evals = Refl , Eq0-0c
val-evals-inversion unit-isval unit-evals = Refl , Eq0-0c
val-evals-inversion (delay-isval e) delay-evals = Refl , Eq0-0c
val-evals-inversion nil-isval nil-evals = Refl , Eq0-0c
val-evals-inversion (cons-isval x xs vx vxs) (cons-evals D D₁) = ap2 _::s_ (fst IH1) (fst IH2) , Eq0-+c (snd IH1) (snd IH2) where
IH1 = val-evals-inversion vx D
IH2 = val-evals-inversion vxs D₁
val-evals-inversion true-isval true-evals = Refl , Eq0-0c
val-evals-inversion false-isval false-evals = Refl , Eq0-0c
|
{
"alphanum_fraction": 0.4639547361,
"avg_line_length": 50.25,
"ext": "agda",
"hexsha": "f5260fc05114d1f7ac14e2ddb97b54adaff216aa",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "benhuds/Agda",
"max_forks_repo_path": "complexity-drafts/Source2.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_issues_repo_issues_event_max_datetime": "2020-05-12T00:32:45.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-23T08:39:04.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "benhuds/Agda",
"max_issues_repo_path": "complexity-drafts/Source2.agda",
"max_line_length": 162,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "benhuds/Agda",
"max_stars_repo_path": "complexity-drafts/Source2.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:27:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-26T20:22:22.000Z",
"num_tokens": 12835,
"size": 30753
}
|
------------------------------------------------------------------------------
-- All parameters are required in an ATP definition
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Issue11 where
postulate
D : Set
false true : D
data Bool : D → Set where
btrue : Bool true
bfalse : Bool false
OkBit : D → Set
OkBit b = Bool b
{-# ATP definition OkBit #-}
postulate foo : ∀ b → OkBit b → OkBit b
{-# ATP prove foo #-}
WrongBit : D → Set
WrongBit = Bool
{-# ATP definition WrongBit #-}
postulate bar : ∀ b → WrongBit b → WrongBit b
{-# ATP prove bar #-}
-- $ apia --check Issue11.agda
-- apia: tptp4X found an error in the file /tmp/Issue11/29-bar.tptp
|
{
"alphanum_fraction": 0.4976247031,
"avg_line_length": 24.0571428571,
"ext": "agda",
"hexsha": "5eb855cf4f285f5d8ac378759b683cb76d19bcb8",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "issues/Issue11.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "issues/Issue11.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "issues/Issue11.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 197,
"size": 842
}
|
------------------------------------------------------------------------
-- Parser monad
------------------------------------------------------------------------
-- This code may have bitrotted.
open import Relation.Binary
open import Relation.Binary.OrderMorphism
import Relation.Binary.PropositionalEquality as PropEq
open PropEq using (_≡_)
import Relation.Binary.Props.StrictTotalOrder as STOProps
open import Data.Product
module StructurallyRecursiveDescentParsing.Memoised.Monad
-- Input string positions.
{Position : Set} {_<P_ : Rel Position}
(posOrdered : IsStrictTotalOrder _≡_ _<P_)
-- Input strings.
(Input : Position → Set)
-- In order to be able to store results in a memo table (and avoid
-- having to lift the table code to Set1) the result types have to
-- come from the following universe:
{Result : Set} (⟦_⟧ : Result → Set)
-- Memoisation keys. These keys must uniquely identify the
-- computation that they are associated with, when paired up with
-- the current input string position.
{Key : let PosPoset = STOProps.poset
(record { carrier = _ ; _≈_ = _; _<_ = _
; isStrictTotalOrder = posOrdered })
MonoFun = PosPoset ⇒-Poset PosPoset in
MonoFun → Result → Set}
{_≈_ _<_ : Rel (∃₂ Key)}
(keyOrdered : IsStrictTotalOrder _≈_ _<_)
-- Furthermore the underlying equality needs to be strong enough.
(funsEqual : _≈_ =[ proj₁ ]⇒ _≡_)
(resultsEqual : _≈_ =[ (λ rfk → proj₁ (proj₂ rfk)) ]⇒ _≡_)
where
open _⇒-Poset_
open STOProps (record { carrier = _ ; _≈_ = _; _<_ = _
; isStrictTotalOrder = posOrdered })
import Data.AVL.IndexedMap as Map renaming (Map to MemoTable)
open import Category.Monad
open import Category.Monad.State
import Data.List as List; open List using (List)
open import Function using (_⟨_⟩_; _on_)
open import Data.Maybe using (Maybe; nothing; just)
open import Data.Unit using (⊤)
open import Relation.Binary.Product.StrictLex
open import Relation.Binary.Product.Pointwise
import Relation.Binary.On as On
------------------------------------------------------------------------
-- Monotone functions
MonoFun : Set
MonoFun = poset ⇒-Poset poset
------------------------------------------------------------------------
-- Memo table keys and values
-- Indices and keys used by the memo table.
Index : Set
Index = Position × MonoFun × Result
data MemoTableKey : Index → Set where
key : ∀ {f r} (key : Key f r) pos → MemoTableKey (pos , f , r)
-- Input strings of a certain maximum length.
record Input≤ (bnd : Position) : Set where
field
position : Position
bounded : position ≤ bnd
string : Input position
open Input≤ public
_isBounded∶_ : ∀ {bnd pos} → Input pos → pos ≤ bnd → Input≤ bnd
xs isBounded∶ le = record { position = _; bounded = le; string = xs }
-- Memo table values.
Value : Index → Set
Value (pos , f , r) = List (⟦ r ⟧ × Input≤ (fun f pos))
------------------------------------------------------------------------
-- Parser monad
-- The parser monad is instantiated with the memo table at the end of
-- the file in order to reduce the time required to type check it.
private
module Dummy
(MemoTable : Set)
(empty : MemoTable)
(insert : ∀ {i} → MemoTableKey i → Value i →
MemoTable → MemoTable)
(lookup : ∀ {i} → MemoTableKey i → MemoTable → Maybe (Value i))
where
-- The parser monad is built upon a list monad, for backtracking, and
-- two state monads. One of the state monads stores a memo table, and
-- is unaffected by backtracking. The other state monad, which /is/
-- affected by backtracking, stores the remaining input string.
-- The memo table state monad.
module MemoState = RawMonadState (StateMonadState MemoTable)
-- The list monad.
module List = RawMonadPlus List.monadPlus
-- The inner monad (memo table plus list).
module IM where
Inner : Set → Set
Inner R = State MemoTable (List R)
InnerMonadPlus : RawMonadPlus Inner
InnerMonadPlus = record
{ monadZero = record
{ monad = record
{ return = λ x → return (List.return x)
; _>>=_ = λ m f → List.concat <$> (List.mapM monad f =<< m)
}
; ∅ = return List.∅
}
; _∣_ = λ m₁ m₂ → List._∣_ <$> m₁ ⊛ m₂
}
where open MemoState
InnerMonadState : RawMonadState MemoTable Inner
InnerMonadState = record
{ monad = RawMonadPlus.monad InnerMonadPlus
; get = List.return <$> get
; put = λ s → List.return <$> put s
}
where open MemoState
open RawMonadPlus InnerMonadPlus public
open RawMonadState InnerMonadState public
using (get; put; modify)
-- The complete parser monad.
module PM where
infixr 5 _∣_
infixl 1 _>>=_ _>>_
infixr 1 _=<<_
-- Parameters:
-- • bnd: Upper bound of the length of the input.
-- • f: The actual length of the output is bounded by
-- f (actual length of the input).
-- • A: Result type.
data P (bnd : Position) (f : MonoFun) (A : Set) : Set where
pm : (im : (inp : Input≤ bnd) →
IM.Inner (A × Input≤ (fun f (position inp)))) →
P bnd f A
private
unPM : ∀ {bnd f A} → P bnd f A → (inp : Input≤ bnd) →
IM.Inner (A × Input≤ (fun f (position inp)))
unPM (pm m) = m
-- Memoises the computation, assuming that the key is sufficiently
-- unique.
memoise : ∀ {bnd f r} → Key f r → P bnd f ⟦ r ⟧ → P bnd f ⟦ r ⟧
memoise {bnd} {f} {r} k (pm p) = pm helper₁
where
helper₁ : (inp : Input≤ bnd) →
IM.Inner (⟦ r ⟧ × Input≤ (fun f (position inp)))
helper₁ xs = let open IM in
helper₂ =<< lookup k′ <$> get
where
i = (position xs , f , r)
k′ : MemoTableKey i
k′ = key k (position xs)
helper₂ : Maybe (Value i) → State MemoTable (Value i)
helper₂ (just v) = return v where open MemoState
helper₂ nothing = p xs >>= λ v →
modify (insert k′ v) >>
return v
where open MemoState
-- Other monadic operations.
return : ∀ {bnd A} → A → P bnd id A
return a =
pm λ xs → IM.return (a , string xs isBounded∶ refl)
_>>=_ : ∀ {bnd A B f g} →
P bnd f A → (A → P (fun f bnd) g B) → P bnd (g ∘ f) B
_>>=_ {f = f} {g} (pm m₁) m₂ = pm λ xs →
m₁ xs ⟨ IM._>>=_ ⟩ λ ays →
let a = proj₁ ays; ys = proj₂ ays in
fix (bounded ys) ⟨ IM._<$>_ ⟩
unPM (m₂ a) (string ys isBounded∶
lemma f (bounded xs) (bounded ys))
where
lemma : ∀ f {i j k} → j ≤ k → i ≤ fun f j → i ≤ fun f k
lemma f j≤k i≤gj = trans i≤gj (monotone f j≤k)
fix : ∀ {A i j} → i ≤ j →
A × Input≤ (fun g i) →
A × Input≤ (fun g j)
fix le (a , xs) =
(a , string xs isBounded∶ lemma g le (bounded xs))
_>>_ : ∀ {bnd A B f g} →
P bnd f A → P (fun f bnd) g B → P bnd (g ∘ f) B
m₁ >> m₂ = m₁ >>= λ _ → m₂
_=<<_ : ∀ {bnd A B f g} →
(A → P (fun f bnd) g B) → P bnd f A → P bnd (g ∘ f) B
m₂ =<< m₁ = m₁ >>= m₂
∅ : ∀ {bnd f A} → P bnd f A
∅ = pm (λ _ → IM.∅)
_∣_ : ∀ {bnd f A} → P bnd f A → P bnd f A → P bnd f A
pm m₁ ∣ pm m₂ = pm λ xs → IM._∣_ (m₁ xs) (m₂ xs)
get : ∀ {bnd} → P bnd id (Input≤ bnd)
get = pm λ xs → IM.return (xs , string xs isBounded∶ refl)
put : ∀ {bnd bnd′} → Input≤ bnd′ → P bnd (const bnd′) ⊤
put xs = pm λ _ → IM.return (_ , xs)
-- A generalised variant of modify.
gmodify : ∀ {bnd A} f →
((inp : Input≤ bnd) → A × Input≤ (fun f (position inp))) →
P bnd f A
gmodify f g = pm λ xs → IM.return (g xs)
modify : ∀ {bnd} f →
((inp : Input≤ bnd) → Input≤ (fun f (position inp))) →
P bnd f ⊤
modify f g = gmodify f (λ xs → (_ , g xs))
adjustBound : ∀ {bnd f g A} →
(∀ p → fun f p ≤ fun g p) → P bnd f A → P bnd g A
adjustBound hyp (pm m) =
pm λ xs →
let le = λ (ys : _) → trans (bounded ys) (hyp (position xs)) in
map (λ x → x) (λ ys → string ys isBounded∶ le ys)
⟨ IM._<$>_ ⟩
m xs
run : ∀ {A f pos} →
Input pos → P pos f A → List (A × Input≤ (fun f pos))
run xs (pm m) = proj₁ (m (xs isBounded∶ refl) empty)
------------------------------------------------------------------------
-- Memo tables
-- Shuffles the elements to simplify defining equality and order
-- relations for the keys.
shuffle : ∃ MemoTableKey → Position × ∃₂ Key
shuffle ((pos , f , r) , key k .pos) = (pos , f , r , k)
-- Equality and ordering.
Eq : Rel (∃ MemoTableKey)
Eq = _≡_ ×-Rel _≈_ on shuffle
Lt : Rel (∃ MemoTableKey)
Lt = ×-Lex _≡_ _<P_ _<_ on shuffle
isOrdered : IsStrictTotalOrder Eq Lt
isOrdered = On.isStrictTotalOrder shuffle
(posOrdered ×-isStrictTotalOrder keyOrdered)
indicesEqual′ : Eq =[ proj₁ ]⇒ _≡_
indicesEqual′ {((_ , _ , _) , key _ ._)}
{((_ , _ , _) , key _ ._)} (eq₁ , eq₂) =
PropEq.cong₂ _,_ eq₁
(PropEq.cong₂ _,_ (funsEqual eq₂) (resultsEqual eq₂))
open Map isOrdered (λ {k₁} {k₂} → indicesEqual′ {k₁} {k₂}) Value
-- Instantiation of the Dummy module above.
open Dummy MemoTable empty insert lookup public
|
{
"alphanum_fraction": 0.5452631579,
"avg_line_length": 30.7443365696,
"ext": "agda",
"hexsha": "1506ceea177432c8dcfccf3484c45fdf2157242a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "StructurallyRecursiveDescentParsing/Memoised/Monad.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "StructurallyRecursiveDescentParsing/Memoised/Monad.agda",
"max_line_length": 72,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "StructurallyRecursiveDescentParsing/Memoised/Monad.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 2900,
"size": 9500
}
|
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Empty.Base where
open import Cubical.Core.Everything
data ⊥ : Type₀ where
⊥-elim : ∀ {ℓ} {A : Type ℓ} → ⊥ → A
⊥-elim ()
|
{
"alphanum_fraction": 0.6214689266,
"avg_line_length": 16.0909090909,
"ext": "agda",
"hexsha": "d5823bd20fcc040544d7697e097275f22c7bf8a6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Data/Empty/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Data/Empty/Base.agda",
"max_line_length": 36,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Data/Empty/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 64,
"size": 177
}
|
module Luau.Addr.ToString where
open import Agda.Builtin.String using (String; primStringAppend)
open import Luau.Addr using (Addr)
open import Agda.Builtin.Int using (Int; primShowInteger; pos)
addrToString : Addr → String
addrToString a = primStringAppend "a" (primShowInteger (pos a))
|
{
"alphanum_fraction": 0.7896551724,
"avg_line_length": 32.2222222222,
"ext": "agda",
"hexsha": "2fc383355c263ede33aaea9002d08bcab97be395",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "XanderYZZ/luau",
"max_forks_repo_path": "prototyping/Luau/Addr/ToString.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "XanderYZZ/luau",
"max_issues_repo_path": "prototyping/Luau/Addr/ToString.agda",
"max_line_length": 64,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "TheGreatSageEqualToHeaven/luau",
"max_stars_repo_path": "prototyping/Luau/Addr/ToString.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z",
"num_tokens": 73,
"size": 290
}
|
open import Agda.Primitive
module ManySortedAlgebra where
-- a many sorted signature
record Signature {l : Level} : Set (lsuc l) where
field
sort : Set l -- sorts
op : Set l -- operations
arg : op → Set l
op-sort : op → sort -- the sort of the operation
arg-sort : ∀ {f} → arg f → sort -- the sorts of arguments
open Signature
-- we allow general contexts in which there are arbitrarily many variables,
-- which makes things easier
record Context {l : Level} (Σ : Signature {l}) : Set (lsuc l) where
field
var : Set l
var-sort : var → sort Σ
open Context
-- terms over a signature in a context of a given sort
data Term {l : Level} {Σ : Signature {l}} (Γ : Context Σ) : sort Σ → Set l where
tm-var : ∀ (x : var Γ) → Term Γ (var-sort Γ x)
tm-op : ∀ (f : op Σ) → (∀ (i : arg Σ f) → Term Γ (arg-sort Σ i)) → Term Γ (op-sort Σ f)
substitution : ∀ {l : Level} {Σ : Signature {l}} (Γ Δ : Context Σ) → Set l
substitution Γ Δ = ∀ (x : var Γ) → Term Δ (var-sort Γ x)
-- the action of a substitution on a term
_·_ : ∀ {l : Level} {Σ : Signature {l}} {Γ Δ : Context Σ} → substitution Γ Δ → ∀ {A} → Term Γ A → Term Δ A
σ · (tm-var x) = σ x
σ · (tm-op f x) = tm-op f (λ i → σ · x i)
infixr 6 _·_
-- composition of substitutions
_○_ : ∀ {l : Level} {Σ : Signature {l}} {Γ Δ Θ : Context Σ} → substitution Δ Θ → substitution Γ Δ → substitution Γ Θ
(σ ○ τ) x = σ · τ x
infixl 7 _○_
-- an equational theory is a family of equations over a given sort
record EquationalTheory {l : Level} (Σ : Signature {l}) : Set (lsuc l) where
field
eq : Set l
eq-ctx : ∀ (ε : eq) → Context {l} Σ
eq-sort : ∀ (ε : eq) → sort Σ
eq-lhs : ∀ (ε : eq) → Term (eq-ctx ε) (eq-sort ε)
eq-rhs : ∀ (ε : eq) → Term (eq-ctx ε) (eq-sort ε)
open EquationalTheory
infix 4 _≡_
-- the remaining judgement form is equality
data _≡_ {l : Level} {Σ : Signature {l}} {T : EquationalTheory {l} Σ } : {Γ : Context Σ} → {S : sort Σ} → Term Γ S → Term Γ S → Set (lsuc l) where
-- general rules
eq-refl : ∀ {Γ} {S : sort Σ} {t : Term Γ S} → t ≡ t
eq-symm : ∀ {Γ} {S : sort Σ} {s t : Term {l} {Σ} Γ S} → _≡_ {T = T} s t → t ≡ s
eq-tran : ∀ {Γ} {S : sort Σ} {s t u : Term Γ S} → _≡_ {T = T} s t → _≡_ {T = T} t u → s ≡ u
-- congruence rule
eq-congr : ∀ {Γ} {f : op Σ} (x y : ∀ (i : arg Σ f) → Term Γ (arg-sort Σ i)) →
(∀ i → _≡_ {_} {_} {T} (x i) (y i)) → tm-op f x ≡ tm-op f y
-- equational axiom
eq-axiom : ∀ (ε : eq T) {Δ : Context Σ} (σ : substitution (eq-ctx T ε) Δ) →
σ · eq-lhs T ε ≡ σ · eq-rhs T ε
-- composition is functorial
subst-○ : ∀ {l : Level} {Σ : Signature {l}} {T : EquationalTheory Σ} {Γ Δ Θ : Context Σ}
(σ : substitution Δ Θ) (τ : substitution Γ Δ) →
∀ {A} (t : Term Γ A) → _≡_ {T = T} (σ · τ · t) (σ ○ τ · t)
subst-○ σ τ (tm-var x) = eq-refl
subst-○ σ τ (tm-op f x) = eq-congr (λ i → σ · τ · x i) (λ i → σ ○ τ · x i) λ i → subst-○ σ τ (x i)
-- substitution preserves equality
eq-subst : ∀ {l : Level} {Σ : Signature {l}} {T : EquationalTheory Σ} {Γ Δ : Context Σ} {S : sort Σ} (σ : substitution Γ Δ)
{s t : Term Γ S} → _≡_ {T = T} s t → _≡_ {T = T} (σ · s) (σ · t)
eq-subst σ eq-refl = eq-refl
eq-subst σ (eq-symm ξ) = eq-symm (eq-subst σ ξ)
eq-subst σ (eq-tran ζ ξ) = eq-tran (eq-subst σ ζ) (eq-subst σ ξ)
eq-subst σ (eq-congr x y ξ) = eq-congr (λ i → σ · x i) (λ i → σ · y i) λ i → eq-subst σ (ξ i)
eq-subst {T = T} σ (eq-axiom ε τ) =
eq-tran (subst-○ σ τ (eq-lhs T ε))
(eq-tran (eq-axiom ε (σ ○ τ)) (eq-symm (subst-○ σ τ (eq-rhs T ε))))
|
{
"alphanum_fraction": 0.5295546559,
"avg_line_length": 41.6292134831,
"ext": "agda",
"hexsha": "bf90e76ed790ddf7d822e0f118d35cac5f8784fd",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z",
"max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/formaltt",
"max_forks_repo_path": "src/Experimental/ManySortedAlgebra.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejbauer/formaltt",
"max_issues_repo_path": "src/Experimental/ManySortedAlgebra.agda",
"max_line_length": 148,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cilinder/formaltt",
"max_stars_repo_path": "src/Experimental/ManySortedAlgebra.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z",
"num_tokens": 1477,
"size": 3705
}
|
module With where
open import Reflection
open import Function using (_∘_ ; _$_ ; _∋_ ; id ; const)
open import Data.List
open import Data.Nat hiding (_+_)
open import Relation.Binary using (Setoid ; Decidable)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality hiding ( [_] ; subst )
open import Helper.CodeGeneration
{-# TERMINATING #-}
mutual
s_arg : (n : ℕ) -> (ℕ -> Term -> Term) -> Arg Term -> Arg Term
s_arg n f (arg i x) = arg i (s_term' n f x)
s_type : (n : ℕ) -> (ℕ -> Term -> Term) -> Type -> Type
s_type n f (el s t) = el s (s_term' n f t)
s_term : (n : ℕ) -> (ℕ -> Term -> Term) -> Term -> Term
s_term n f (var x args) = var x (map (s_arg n f) args)
s_term n f (con c args) = con c (map (s_arg n f) args)
s_term n f (def f₁ args) = def f₁ (map (s_arg n f) args)
s_term n f (lam v (abs s x)) = lam v (abs s (s_term' n f x))
s_term n f (pat-lam cs args) = pat-lam cs (map (s n arg f) args)
s_term n f (pi (arg i x) (abs s x₁)) = pi (arg i (s_type n f x)) (abs s (s_type n f x₁))
s_term n f t = t
s_term' : (n : ℕ) -> (ℕ -> Term -> Term) -> Term -> Term
s_term' n f t = f n (s_term n f t)
inc_debruijn_indices : Term -> Term
inc_debruijn_indices t = s_term' zero alg t
where
alg : ℕ -> Term -> Term
alg n (var x args) = var (suc x) args
alg n t2 = t2
subst : Term -> Term -> Term -> Term
subst t ti to = s_term' zero alg t
where
alg : ℕ -> Term -> Term
alg n ti1 with ti Reflection.≟ ti1
alg n ti1 | yes p = to
alg n ti1 | no ¬p = ti1
getType : {T : Set} -> (t : T) -> Term
getType {T} t = quoteTerm T
with' : Term -> Term -> Term
with' w l = quote-goal (abs "g" lam_body)
where
sub_term = def (quote subst) ( (a $ var 1 []) ∷ (a $ w) ∷ (a $ quote-term $ var 0 []) ∷ [] )
lam_type_q = unquote-term sub_term []
lam_type = pi (a $ t0 unknown) (abs "i" $ t0 $ lam_type_q)
lam_body = def (quote _$_) ((a $ lam_type ∋-t l) ∷ (a $ inc_debruijn_indices $ unquote-term w []) ∷ [])
postulate
A : Set
_+_ : A → A → A
T : A → Set
mkT : ∀ x → T x
P : ∀ x → T x → Set
-- the type A of the with argument has no free variables, so the with
-- argument will come first
f₁ : (x y : A) (t : T (x + y)) → T (x + y)
f₁ x y t with x + y
f₁ x y t | w = mkT w
f₂ : (x y : A) → T (x + y)
f₂ x y = unquote (with' (quoteTerm (quoteTerm (x + y))) (quoteTerm (\w -> mkT w)))
-- def (quote inc_var_indices) [ a $ var 1 [] ] --
-- sub_term = def (quote subst) ( (a $ var 1 []) ∷ (a $ w) ∷ (a $ (quote-term (var 0 []))) ∷ [] )
-- lam_type = pi (a $ t0 $ (def (quote _≡_) ((a $ var 3 []) ∷ (a $ var 2 []) ∷ []))) (abs "i" $ t0 $ lam_type_q)
|
{
"alphanum_fraction": 0.5544848036,
"avg_line_length": 33.3086419753,
"ext": "agda",
"hexsha": "ed4ae29761536aeb5d264f36105f77c6be88ef25",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mathijsb/generic-in-agda",
"max_forks_repo_path": "With.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mathijsb/generic-in-agda",
"max_issues_repo_path": "With.agda",
"max_line_length": 116,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mathijsb/generic-in-agda",
"max_stars_repo_path": "With.agda",
"max_stars_repo_stars_event_max_datetime": "2016-08-04T16:05:24.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-09T09:59:27.000Z",
"num_tokens": 1008,
"size": 2698
}
|
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Graph.Examples where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Empty
open import Cubical.Data.Unit renaming (Unit to ⊤)
open import Cubical.Data.Nat
open import Cubical.Data.SumFin
open import Cubical.Relation.Nullary
open import Cubical.Data.Sum
open import Cubical.Data.Prod
open import Cubical.Data.Graph.Base
-- Some small graphs of common shape
⇒⇐ : Graph ℓ-zero ℓ-zero
Obj ⇒⇐ = Fin 3
Hom ⇒⇐ fzero (fsuc fzero) = ⊤
Hom ⇒⇐ (fsuc (fsuc fzero)) (fsuc fzero) = ⊤
Hom ⇒⇐ _ _ = ⊥
⇐⇒ : Graph ℓ-zero ℓ-zero
Obj ⇐⇒ = Fin 3
Hom ⇐⇒ (fsuc fzero) fzero = ⊤
Hom ⇐⇒ (fsuc fzero) (fsuc (fsuc fzero)) = ⊤
Hom ⇐⇒ _ _ = ⊥
-- paralell pair graph
⇉ : Graph ℓ-zero ℓ-zero
Obj ⇉ = Fin 2
Hom ⇉ fzero (fsuc fzero) = Fin 2
Hom ⇉ _ _ = ⊥
-- The graph ω = 0 → 1 → 2 → ···
data Adj : ℕ → ℕ → Type₀ where
adj : ∀ n → Adj n (suc n)
areAdj : ∀ m n → Dec (Adj m n)
areAdj zero zero = no λ ()
areAdj zero (suc zero) = yes (adj zero)
areAdj zero (suc (suc n)) = no λ ()
areAdj (suc m) zero = no λ ()
areAdj (suc m) (suc n) = mapDec (λ { (adj .m) → adj (suc m) })
(λ { ¬a (adj .(suc m)) → ¬a (adj m) })
(areAdj m n)
ωGr : Graph ℓ-zero ℓ-zero
Obj ωGr = ℕ
Hom ωGr m n with areAdj m n
... | yes _ = ⊤ -- if n ≡ (suc m)
... | no _ = ⊥ -- otherwise
record ωDiag ℓ : Type (ℓ-suc ℓ) where
field
ωObj : ℕ → Type ℓ
ωHom : ∀ n → ωObj n → ωObj (suc n)
asDiag : Diag ℓ ωGr
asDiag $ n = ωObj n
_<$>_ asDiag {m} {n} f with areAdj m n
asDiag <$> tt | yes (adj m) = ωHom m
-- The finite connected subgraphs of ω: 𝟘,𝟙,𝟚,𝟛,...
data AdjFin : ∀ {k} → Fin k → Fin k → Type₀ where
adj : ∀ {k} (n : Fin k) → AdjFin (finj n) (fsuc n)
adj-fsuc : ∀ {k} {m n : Fin k} → AdjFin (fsuc m) (fsuc n) → AdjFin m n
adj-fsuc {suc k} {.(finj n)} {fsuc n} (adj .(fsuc n)) = adj n
areAdjFin : ∀ {k} (m n : Fin k) → Dec (AdjFin m n)
areAdjFin {suc k} fzero fzero = no λ ()
areAdjFin {suc (suc k)} fzero (fsuc fzero) = yes (adj fzero)
areAdjFin {suc (suc k)} fzero (fsuc (fsuc n)) = no λ ()
areAdjFin {suc k} (fsuc m) fzero = no λ ()
areAdjFin {suc k} (fsuc m) (fsuc n) = mapDec (λ { (adj m) → adj (fsuc m) })
(λ { ¬a a → ¬a (adj-fsuc a) })
(areAdjFin {k} m n)
[_]Gr : ℕ → Graph ℓ-zero ℓ-zero
Obj [ k ]Gr = Fin k
Hom [ k ]Gr m n with areAdjFin m n
... | yes _ = ⊤ -- if n ≡ (suc m)
... | no _ = ⊥ -- otherwise
𝟘Gr 𝟙Gr 𝟚Gr 𝟛Gr : Graph ℓ-zero ℓ-zero
𝟘Gr = [ 0 ]Gr; 𝟙Gr = [ 1 ]Gr; 𝟚Gr = [ 2 ]Gr; 𝟛Gr = [ 3 ]Gr
record [_]Diag ℓ (k : ℕ) : Type (ℓ-suc ℓ) where
field
[]Obj : Fin (suc k) → Type ℓ
[]Hom : ∀ (n : Fin k) → []Obj (finj n) → []Obj (fsuc n)
asDiag : Diag ℓ [ suc k ]Gr
asDiag $ n = []Obj n
_<$>_ asDiag {m} {n} f with areAdjFin m n
_<$>_ asDiag {.(finj n)} {fsuc n} f | yes (adj .n) = []Hom n
-- Disjoint union of graphs
module _ {ℓv ℓe ℓv' ℓe'} where
_⊎Gr_ : ∀ (G : Graph ℓv ℓe) (G' : Graph ℓv' ℓe') → Graph (ℓ-max ℓv ℓv') (ℓ-max ℓe ℓe')
Obj (G ⊎Gr G') = Obj G ⊎ Obj G'
Hom (G ⊎Gr G') (inl x) (inl y) = Lift {j = ℓe'} (Hom G x y)
Hom (G ⊎Gr G') (inr x) (inr y) = Lift {j = ℓe } (Hom G' x y)
Hom (G ⊎Gr G') _ _ = Lift ⊥
record ⊎Diag ℓ (G : Graph ℓv ℓe) (G' : Graph ℓv' ℓe')
: Type (ℓ-max (ℓ-suc ℓ) (ℓ-max (ℓ-max ℓv ℓv') (ℓ-max ℓe ℓe'))) where
field
⊎Obj : Obj G ⊎ Obj G' → Type ℓ
⊎Homl : ∀ {x y} → Hom G x y → ⊎Obj (inl x) → ⊎Obj (inl y)
⊎Homr : ∀ {x y} → Hom G' x y → ⊎Obj (inr x) → ⊎Obj (inr y)
asDiag : Diag ℓ (G ⊎Gr G')
asDiag $ x = ⊎Obj x
_<$>_ asDiag {inl x} {inl y} f = ⊎Homl (lower f)
_<$>_ asDiag {inr x} {inr y} f = ⊎Homr (lower f)
-- Cartesian product of graphs
module _ {ℓv ℓe ℓv' ℓe'} where
-- We need decidable equality in order to define the cartesian product
DecGraph : ∀ ℓv ℓe → Type (ℓ-suc (ℓ-max ℓv ℓe))
DecGraph ℓv ℓe = Σ[ G ∈ Graph ℓv ℓe ] Discrete (Obj G)
_×Gr_ : (G : DecGraph ℓv ℓe) (G' : DecGraph ℓv' ℓe') → Graph (ℓ-max ℓv ℓv') (ℓ-max ℓe ℓe')
Obj (G ×Gr G') = Obj (fst G) × Obj (fst G')
Hom (G ×Gr G') (x , x') (y , y') with snd G x y | snd G' x' y'
... | yes _ | yes _ = Hom (fst G) x y ⊎ Hom (fst G') x' y'
... | yes _ | no _ = Lift {j = ℓe } (Hom (fst G') x' y')
... | no _ | yes _ = Lift {j = ℓe'} (Hom (fst G) x y)
... | no _ | no _ = Lift ⊥
record ×Diag ℓ (G : DecGraph ℓv ℓe) (G' : DecGraph ℓv' ℓe')
: Type (ℓ-max (ℓ-suc ℓ) (ℓ-max (ℓ-max ℓv ℓv') (ℓ-max ℓe ℓe'))) where
field
×Obj : Obj (fst G) × Obj (fst G') → Type ℓ
×Hom₁ : ∀ {x y} (f : Hom (fst G) x y) (x' : Obj (fst G')) → ×Obj (x , x') → ×Obj (y , x')
×Hom₂ : ∀ (x : Obj (fst G)) {x' y'} (f : Hom (fst G') x' y') → ×Obj (x , x') → ×Obj (x , y')
asDiag : Diag ℓ (G ×Gr G')
asDiag $ x = ×Obj x
_<$>_ asDiag {x , x'} {y , y'} f with snd G x y | snd G' x' y'
_<$>_ asDiag {x , x'} {y , y'} (inl f) | yes _ | yes p' = subst _ p' (×Hom₁ f x')
_<$>_ asDiag {x , x'} {y , y'} (inr f) | yes p | yes _ = subst _ p (×Hom₂ x f )
_<$>_ asDiag {x , x'} {y , y'} f | yes p | no _ = subst _ p (×Hom₂ x (lower f) )
_<$>_ asDiag {x , x'} {y , y'} f | no _ | yes p' = subst _ p' (×Hom₁ (lower f) x')
|
{
"alphanum_fraction": 0.5075688492,
"avg_line_length": 33.6380368098,
"ext": "agda",
"hexsha": "9b36bb10d9212bd1ba14fd1dfbae39b2432cc25b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Data/Graph/Examples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Data/Graph/Examples.agda",
"max_line_length": 98,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Data/Graph/Examples.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2434,
"size": 5483
}
|
open import bool
module list-merge-sort (A : Set) (_<A_ : A → A → 𝔹) where
open import braun-tree A _<A_
open import eq
open import list
open import nat
open import nat-thms
merge : (l1 l2 : 𝕃 A) → 𝕃 A
merge [] ys = ys
merge xs [] = xs
merge (x :: xs) (y :: ys) with x <A y
merge (x :: xs) (y :: ys) | tt = x :: (merge xs (y :: ys))
merge (x :: xs) (y :: ys) | ff = y :: (merge (x :: xs) ys)
merge-sort-h : ∀{n : ℕ} → braun-tree' n → 𝕃 A
merge-sort-h (bt'-leaf a) = [ a ]
merge-sort-h (bt'-node l r p) = merge (merge-sort-h l) (merge-sort-h r)
merge-sort : 𝕃 A → 𝕃 A
merge-sort [] = []
merge-sort (a :: as) with 𝕃-to-braun-tree' a as
merge-sort (a :: as) | t = merge-sort-h t
|
{
"alphanum_fraction": 0.5712187959,
"avg_line_length": 26.1923076923,
"ext": "agda",
"hexsha": "dd69d6fb6a9c580754e01bbd8773812be12999c4",
"lang": "Agda",
"max_forks_count": 17,
"max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z",
"max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rfindler/ial",
"max_forks_repo_path": "list-merge-sort.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rfindler/ial",
"max_issues_repo_path": "list-merge-sort.agda",
"max_line_length": 71,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rfindler/ial",
"max_stars_repo_path": "list-merge-sort.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z",
"num_tokens": 267,
"size": 681
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Indexed monads
------------------------------------------------------------------------
-- Note that currently the monad laws are not included here.
module Category.Monad.Indexed where
open import Category.Applicative.Indexed
open import Function
open import Level
record RawIMonad {i f} {I : Set i} (M : IFun I f) :
Set (i ⊔ suc f) where
infixl 1 _>>=_ _>>_ _>=>_
infixr 1 _=<<_ _<=<_
field
return : ∀ {i A} → A → M i i A
_>>=_ : ∀ {i j k A B} → M i j A → (A → M j k B) → M i k B
_>>_ : ∀ {i j k A B} → M i j A → M j k B → M i k B
m₁ >> m₂ = m₁ >>= λ _ → m₂
_=<<_ : ∀ {i j k A B} → (A → M j k B) → M i j A → M i k B
f =<< c = c >>= f
_>=>_ : ∀ {i j k a} {A : Set a} {B C} →
(A → M i j B) → (B → M j k C) → (A → M i k C)
f >=> g = _=<<_ g ∘ f
_<=<_ : ∀ {i j k B C a} {A : Set a} →
(B → M j k C) → (A → M i j B) → (A → M i k C)
g <=< f = f >=> g
join : ∀ {i j k A} → M i j (M j k A) → M i k A
join m = m >>= id
rawIApplicative : RawIApplicative M
rawIApplicative = record
{ pure = return
; _⊛_ = λ f x → f >>= λ f' → x >>= λ x' → return (f' x')
}
open RawIApplicative rawIApplicative public
record RawIMonadZero {i f} {I : Set i} (M : IFun I f) :
Set (i ⊔ suc f) where
field
monad : RawIMonad M
∅ : ∀ {i j A} → M i j A
open RawIMonad monad public
record RawIMonadPlus {i f} {I : Set i} (M : IFun I f) :
Set (i ⊔ suc f) where
infixr 3 _∣_
field
monadZero : RawIMonadZero M
_∣_ : ∀ {i j A} → M i j A → M i j A → M i j A
open RawIMonadZero monadZero public
|
{
"alphanum_fraction": 0.4478808706,
"avg_line_length": 26.8615384615,
"ext": "agda",
"hexsha": "1619d9c5c2d72670bcab1dfd201600f48c614644",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Category/Monad/Indexed.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Category/Monad/Indexed.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Category/Monad/Indexed.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 667,
"size": 1746
}
|
------------------------------------------------------------------------
-- Raw monads
------------------------------------------------------------------------
-- Note that this module is not parametrised by an axiomatisation of
-- equality. This module is reexported from Monad.
{-# OPTIONS --without-K --safe #-}
module Monad.Raw where
open import Prelude
-- Raw monads.
record Raw-monad {d c} (M : Type d → Type c) : Type (lsuc d ⊔ c) where
constructor mk
infixl 6 _⟨$⟩_ _⊛_
infixl 5 _>>=_ _>>_
infixr 5 _=<<_
field
return : ∀ {A} → A → M A
_>>=_ : ∀ {A B} → M A → (A → M B) → M B
-- Variants of _>>=_.
_>>_ : ∀ {A B} → M A → M B → M B
x >> y = x >>= const y
_=<<_ : ∀ {A B} → (A → M B) → M A → M B
_=<<_ = flip _>>=_
-- A map function.
map : ∀ {A B} → (A → B) → M A → M B
map f x = x >>= return ∘ f
-- A synonym.
_⟨$⟩_ : ∀ {A B} → (A → B) → M A → M B
_⟨$⟩_ = map
-- Applicative functor application.
_⊛_ : ∀ {A B} → M (A → B) → M A → M B
f ⊛ x = f >>= λ f → x >>= λ x → return (f x)
-- The sequence function (for lists).
sequence : ∀ {A} → List (M A) → M (List A)
sequence [] = return []
sequence (x ∷ xs) = _∷_ ⟨$⟩ x ⊛ sequence xs
open Raw-monad ⦃ … ⦄ public
-- Raw monad transformers.
record Raw-monad-transformer
{d c₁ c₂} (F : (Type d → Type c₁) → (Type d → Type c₂)) :
Type (lsuc (c₁ ⊔ d) ⊔ c₂) where
constructor mk
field
transform : ∀ {M} ⦃ is-raw-monad : Raw-monad M ⦄ → Raw-monad (F M)
liftʳ : ∀ {M A} ⦃ is-raw-monad : Raw-monad M ⦄ → M A → F M A
open Raw-monad-transformer ⦃ … ⦄ public using (liftʳ)
|
{
"alphanum_fraction": 0.4699386503,
"avg_line_length": 24.328358209,
"ext": "agda",
"hexsha": "626cf0815b59e72c8cd4e2165e029351a161e87a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Monad/Raw.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Monad/Raw.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Monad/Raw.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 603,
"size": 1630
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.