Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Comonad
-- verbatim dual of Categories.Category.Construction.EilenbergMoore
module Categories.Category.Construction.CoEilenbergMoore {o ℓ e} {C : Category o ℓ e} (M : Comonad C) where
open import Level
open import Categories.Morphism.Reasoning C
private
module C = Category C
module M = Comonad M
open C
open M.F
open HomReasoning
open Equiv
record Comodule : Set (o ⊔ ℓ ⊔ e) where
field
A : Obj
coaction : A ⇒ F₀ A
commute : F₁ coaction ∘ coaction ≈ M.δ.η A ∘ coaction
identity : M.ε.η A ∘ coaction ≈ C.id
record Comodule⇒ (X Y : Comodule) : Set (ℓ ⊔ e) where
private
module X = Comodule X
module Y = Comodule Y
field
arr : X.A ⇒ Y.A
commute : Y.coaction ∘ arr ≈ F₁ arr ∘ X.coaction
CoEilenbergMoore : Category (o ⊔ ℓ ⊔ e) (ℓ ⊔ e) e
CoEilenbergMoore =
record
{ Obj = Comodule
; _⇒_ = Comodule⇒
; _≈_ = λ f g → Comodule⇒.arr f ≈ Comodule⇒.arr g
; id = record { arr = C.id ; commute = identityʳ ○ introˡ identity }
; _∘_ = compose
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = record { refl = refl ; sym = sym ; trans = trans }
; ∘-resp-≈ = ∘-resp-≈
}
where
open Equiv
compose : ∀ {X Y Z} → Comodule⇒ Y Z → Comodule⇒ X Y → Comodule⇒ X Z
compose {X} {Y} {Z} f g = record
{ arr = f.arr ∘ g.arr
; commute = begin
Comodule.coaction Z ∘ f.arr ∘ g.arr ≈⟨ pullˡ f.commute ⟩
(F₁ f.arr ∘ Comodule.coaction Y) ∘ g.arr ≈⟨ pullʳ g.commute ⟩
F₁ f.arr ∘ F₁ g.arr ∘ Comodule.coaction X ≈⟨ pullˡ (sym homomorphism) ⟩
F₁ (f.arr ∘ g.arr) ∘ Comodule.coaction X ∎
}
where module f = Comodule⇒ f
module g = Comodule⇒ g
|
{
"alphanum_fraction": 0.6133768352,
"avg_line_length": 28.2923076923,
"ext": "agda",
"hexsha": "b49a5188dd1f9afa46875710550a368cf835da51",
"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/CoEilenbergMoore.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/CoEilenbergMoore.agda",
"max_line_length": 107,
"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/CoEilenbergMoore.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": 697,
"size": 1839
}
|
module CategoryTheory.Linear where
open import CategoryTheory.Categories
open import CategoryTheory.Functor
open import CategoryTheory.BCCCs
open import CategoryTheory.Monad
open import CategoryTheory.Instances.Kleisli
module L {n} {ℂ : Category n} (ℂ-BCCC : BicartesianClosed ℂ) (Mo : Monad ℂ) where
open Category ℂ
open BicartesianClosed ℂ-BCCC
open Monad Mo
open Functor T renaming (omap to M ; fmap to M-f)
Kl : Category n
Kl = Kleisli ℂ Mo
-- Linear product of two objects
_⊛_ : (A B : obj) -> obj
A ⊛ B = (A ⊗ M B) ⊕ (M A ⊗ B) ⊕ (A ⊗ B)
-- First projection from linear product
*π₁ : ∀{A B} -> A ⊛ B ~> M A
*π₁ {A}{B} = [ η.at A ∘ π₁ ⁏ π₁ ⁏ η.at A ∘ π₁ ]
-- Second projection from linear product
*π₂ : ∀{A B} -> A ⊛ B ~> M B
*π₂ {A}{B} = [ π₂ ⁏ η.at B ∘ π₂ ⁏ η.at B ∘ π₂ ]
-- Type class for linear products of type A ⊛ B. Need to provide
-- linear product of morphisms and product laws in order to establish
-- that the linear product is a product in the Kleisli category of the monad.
record LinearProduct (A B : obj) : Set (lsuc n) where
infix 10 ⟪_,_⟫
field
-- | Data
-- Linear product
⟪_,_⟫ : ∀{L} -> (L ~> M A) -> (L ~> M B) -> (L ~> M (A ⊛ B))
-- | Laws
*π₁-comm : ∀{L} -> {l₁ : L ~> M A} {l₂ : L ~> M B}
-> (μ.at A ∘ M-f *π₁) ∘ ⟪ l₁ , l₂ ⟫ ≈ l₁
*π₂-comm : ∀{L} -> {l₁ : L ~> M A} {l₂ : L ~> M B}
-> (μ.at B ∘ M-f *π₂) ∘ ⟪ l₁ , l₂ ⟫ ≈ l₂
⊛-unique : ∀{P} {p₁ : P ~> M A} {p₂ : P ~> M B} {m : P ~> M A⊕B}
-> (μ.at A ∘ M-f *π₁) ∘ m ≈ p₁ -> (μ.at B ∘ M-f *π₂) ∘ m ≈ p₂
-> ⟪ p₁ , p₂ ⟫ ≈ m
Kl-⊛ : Product Kl A B
Kl-⊛ = record
{ A⊗B = A ⊛ B
; π₁ = *π₁
; π₂ = *π₂
; ⟨_,_⟩ = ⟪_,_⟫
; π₁-comm = *π₁-comm
; π₂-comm = *π₂-comm
; ⊗-unique = ⊛-unique
}
-- Type class for linear categories
record Linear {n} {ℂ : Category n}
(ℂ-BCCC : BicartesianClosed ℂ) (Mo : Monad ℂ) : Set (lsuc n) where
open Category ℂ
open L ℂ-BCCC Mo
field
linprod : ∀(A B : obj) -> LinearProduct A B
open module Li {A} {B} = LinearProduct (linprod A B) public
|
{
"alphanum_fraction": 0.4874307627,
"avg_line_length": 33.0563380282,
"ext": "agda",
"hexsha": "032a80c0de4f5d88c1e768ef05324a4e1f09703d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DimaSamoz/temporal-type-systems",
"max_forks_repo_path": "src/CategoryTheory/Linear.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DimaSamoz/temporal-type-systems",
"max_issues_repo_path": "src/CategoryTheory/Linear.agda",
"max_line_length": 81,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DimaSamoz/temporal-type-systems",
"max_stars_repo_path": "src/CategoryTheory/Linear.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z",
"num_tokens": 872,
"size": 2347
}
|
-- {-# OPTIONS --cubical -vtc.lhs.split.partial:20 #-}
{-# OPTIONS --cubical #-}
module _ where
open import Agda.Primitive.Cubical
open import Agda.Builtin.Equality
postulate
X : Set
P : I → Set
p : P i1
module Test (A : Set) (i : I) (B : Set) where
j = i
R = P j
module Z (r s : A) where
a0 : I → Partial j R
a0 k with k
... | _ = \ { (j = i1) → p }
a : Partial j R
a (j = i1) = p
refining : ∀ (x y : A) → x ≡ y → A → Partial j R
refining x y refl = \ { _ (j = i1) → p }
refining-dot : ∀ (x y : A) → x ≡ y → A → Partial j R
refining-dot x .x refl = \ { _ (j = i1) → p }
refining-dot2 : ∀ (x y : A) → x ≡ y → A → Partial j R
refining-dot2 x .x refl z = \ { (i = i1) → p }
refining-cxt : A ≡ X → Partial j R
refining-cxt refl = \ { (j = i1) → p }
refining-cxt2 : B ≡ X → Partial j R
refining-cxt2 refl = \ { (j = i1) → p }
|
{
"alphanum_fraction": 0.5119453925,
"avg_line_length": 23.1315789474,
"ext": "agda",
"hexsha": "5c896fb6113dac7b11ed7f49e1bc5f73d850432c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue3547.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Succeed/Issue3547.agda",
"max_line_length": 55,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Succeed/Issue3547.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": 354,
"size": 879
}
|
{-# OPTIONS --without-K --safe #-}
module Experiment.ListRelationProperties where
open import Level
open import Data.Bool hiding (_≤_; _≤?_; _<_)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.List
import Data.List.Properties as Listₚ
import Data.Nat as ℕ
import Data.Nat.Properties as ℕₚ
open import Data.Product hiding (swap)
import Data.List.Relation.Binary.Equality.Setoid as ListSetoidEquality
import Data.List.Relation.Binary.Permutation.Setoid as PermutationSetoid
import Data.List.Relation.Binary.Permutation.Setoid.Properties
as PermutationSetoidProperties
open import Data.List.Relation.Unary.All as All
import Data.List.Relation.Unary.All.Properties as Allₚ
open import Data.List.Relation.Unary.Any as Any
open import Data.List.Relation.Unary.Linked
import Data.List.Relation.Unary.Linked.Properties as Linkedₚ
open import Data.List.Relation.Unary.AllPairs as AllPairs
import Data.List.Relation.Unary.AllPairs.Properties as AllPairsₚ
open import Data.List.Membership.Propositional
open import Function.Base using (_∘_; _$_; flip)
open import Relation.Binary as B
import Relation.Binary.Properties.DecTotalOrder as DecTotalOrderProperties
open import Relation.Binary.PropositionalEquality using (_≡_)
import Relation.Binary.PropositionalEquality as ≡ hiding ([_])
import Relation.Binary.Reasoning.Setoid as SetoidReasoning
open import Relation.Nullary
open import Relation.Unary as U hiding (_∈_)
-- stdlib
foldr-preservesʳ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p} {f : A → B → B}
→ (∀ x {y} → P y → P (f x y))
→ ∀ {e} → P e → ∀ xs → P (foldr f e xs)
foldr-preservesʳ pres Pe [] = Pe
foldr-preservesʳ pres Pe (x ∷ xs) = pres _ (foldr-preservesʳ pres Pe xs)
-- stdlib
module _ {a p q} {A : Set a} {P : U.Pred A p} {Q : U.Pred A q} where
All-mapWith∈ : ∀ {xs : List A} → (∀ {x} → x ∈ xs → P x → Q x) → All P xs → All Q xs
All-mapWith∈ f [] = []
All-mapWith∈ {x ∷ xs} f (px ∷ pxs) =
f (here ≡.refl) px ∷ All-mapWith∈ (λ x∈xs Px → f (there x∈xs) Px) pxs
module _ {a p} {A : Set a} {P : U.Pred A p} where
All-singleton⁺ : ∀ {x} → P x → All P [ x ]
All-singleton⁺ px = px ∷ []
All-reverse⁺ : ∀ {xs} → All P xs → All P (reverse xs)
All-reverse⁺ {[]} [] = []
All-reverse⁺ {x ∷ xs} (px ∷ pxs) =
≡.subst (All P) (≡.sym $ Listₚ.unfold-reverse x xs)
(Allₚ.++⁺ (All-reverse⁺ pxs) (All-singleton⁺ px))
module _ {a r} {A : Set a} {R : Rel A r} where
-- AllPairs-map⁻
-- AllPairs-mapMaybe⁺ : (∀ x y → R x y → R (f x) (f y)) → AllPairs R xs → AllPairs R (mapMaybe f xs)
-- AllPairs mapMaybe⁻
AllPairs-singleton⁺ : ∀ x → AllPairs R [ x ]
AllPairs-singleton⁺ x = [] ∷ []
AllPairs-pair : ∀ {x y} → R x y → AllPairs R (x ∷ y ∷ [])
AllPairs-pair Rxy = All-singleton⁺ Rxy ∷ AllPairs-singleton⁺ _
AllPairs-++⁻ʳ : ∀ xs {ys} → AllPairs R (xs ++ ys) → AllPairs R ys
AllPairs-++⁻ʳ [] rxs = rxs
AllPairs-++⁻ʳ (x ∷ xs) (rx ∷ rxs) = AllPairs-++⁻ʳ xs rxs
AllPairs-++⁻ˡ : ∀ xs {ys} → AllPairs R (xs ++ ys) → AllPairs R xs
AllPairs-++⁻ˡ [] rxs = []
AllPairs-++⁻ˡ (x ∷ xs) (rx ∷ rxs) = Allₚ.++⁻ˡ xs rx ∷ AllPairs-++⁻ˡ xs rxs
AllPairs-++⁻-AllAll : ∀ xs {ys} →
AllPairs R (xs ++ ys) → All (λ x → All (R x) ys) xs
AllPairs-++⁻-AllAll [] rxs = []
AllPairs-++⁻-AllAll (x ∷ xs) (rx ∷ rxs) = Allₚ.++⁻ʳ _ rx ∷ AllPairs-++⁻-AllAll xs rxs
AllPairs-++⁻ : ∀ xs {ys} → AllPairs R (xs ++ ys) →
AllPairs R xs × AllPairs R ys × All (λ x → All (R x) ys) xs
AllPairs-++⁻ xs rxs = AllPairs-++⁻ˡ xs rxs , AllPairs-++⁻ʳ xs rxs , AllPairs-++⁻-AllAll xs rxs
AllPairs-∷ʳ⁺ : ∀ {x xs} → AllPairs R xs → All (flip R x) xs → AllPairs R (xs ∷ʳ x)
AllPairs-∷ʳ⁺ {x} {xs} rxs px =
AllPairsₚ.++⁺ rxs (AllPairs-singleton⁺ x) (All.map All-singleton⁺ px)
AllPairs-∷ʳ⁻ : ∀ {x xs} → AllPairs R (xs ∷ʳ x) → AllPairs R xs × All (flip R x) xs
AllPairs-∷ʳ⁻ {x} {xs} rxs with AllPairs-++⁻ xs rxs
... | rxs′ , _ , pxs = rxs′ , All.map Allₚ.singleton⁻ pxs
AllPairs-reverse⁺ : ∀ {xs} → AllPairs (flip R) xs → AllPairs R (reverse xs)
AllPairs-reverse⁺ {[]} [] = []
AllPairs-reverse⁺ {x ∷ xs} (rx ∷ rxs) =
≡.subst (AllPairs R) (≡.sym $ Listₚ.unfold-reverse x xs)
(AllPairs-∷ʳ⁺ (AllPairs-reverse⁺ rxs) (All-reverse⁺ rx))
module _ {a r} {A : Set a} {R : Rel A r} where
AllPairs-sym-reverse⁺ : Symmetric R → ∀ {xs} → AllPairs R xs → AllPairs R (reverse xs)
AllPairs-sym-reverse⁺ sym = AllPairs.map sym ∘ AllPairs-reverse⁺
AllAll : ∀ {a b r} {A : Set a} {B : Set b} → REL A B r → List A → List B → Set _
AllAll R xs ys = All (λ x → All (R x) ys) xs
module _ {a r} {A : Set a} {R : Rel A r} where
AllPairs-reverse⁻ : ∀ {xs} → AllPairs R (reverse xs) → AllPairs (flip R) xs
AllPairs-reverse⁻ {xs} rxs =
≡.subst (AllPairs (flip R)) (Listₚ.reverse-involutive xs)
(AllPairs-reverse⁺ rxs)
-- concat⁻
{-
AllPairs-concat⁺ : ∀ {xss} → AllAll (AllAll R) xss xss →
All (AllPairs R) xss → AllPairs R (concat xss)
AllPairs-concat⁺ {[]} rxss pxss = []
AllPairs-concat⁺ {xs ∷ xss} (rxs ∷ rxss) (pxs ∷ pxss) =
AllPairsₚ.++⁺ {xs = xs} pxs (AllPairs-concat⁺ {! proj₂ (unconsʳ rxs) !} pxss) {! !}
-}
AllPairs-universal : B.Universal R → U.Universal (AllPairs R)
AllPairs-universal u [] = []
AllPairs-universal u (x ∷ xs) = All.universal (u _) _ ∷ AllPairs-universal u xs
AllPairs-replicate⁺ : ∀ n {x} → R x x → AllPairs R (replicate n x)
AllPairs-replicate⁺ ℕ.zero Rxx = []
AllPairs-replicate⁺ (ℕ.suc n) Rxx = Allₚ.replicate⁺ n Rxx ∷ AllPairs-replicate⁺ n Rxx
AllPairs-replicate⁻ : ∀ {n x} → AllPairs R (replicate (ℕ.suc (ℕ.suc n)) x) → R x x
AllPairs-replicate⁻ (pxs ∷ rxs) = Allₚ.replicate⁻ pxs
-- AllPairs-drop⁺
-- AllPairs-zipWith⁺ :
module _ {c e} (S : Setoid c e) where
open Setoid S
open ListSetoidEquality S
Linked-resp-≋ : ∀ {r} {R : Rel Carrier r} →
R Respects₂ _≈_ → (Linked R) Respects _≋_
Linked-resp-≋ resp [] [] = []
Linked-resp-≋ resp (_ ∷ []) [-] = [-]
Linked-resp-≋ resp (e₁ ∷ e₂ ∷ xs≋ys) (x ∷ l) =
(proj₂ resp e₁ $ proj₁ resp e₂ x) ∷ Linked-resp-≋ resp (e₂ ∷ xs≋ys) l
module _ {a r} {A : Set a} {R : Rel A r} where
-- Linked-pair : R x y →
Linked-++⁻ʳ : ∀ xs {ys} → Linked R (xs ++ ys) → Linked R ys
Linked-++⁻ʳ [] rxs = rxs
Linked-++⁻ʳ (x ∷ []) {[]} rxs = []
Linked-++⁻ʳ (x ∷ []) {_ ∷ _} (y ∷ rxs) = rxs
Linked-++⁻ʳ (x ∷ y ∷ xs) (_ ∷ rxs) = Linked-++⁻ʳ (y ∷ xs) rxs
Linked-++⁻ˡ : ∀ xs {ys} → Linked R (xs ++ ys) → Linked R xs
Linked-++⁻ˡ [] rxs = []
Linked-++⁻ˡ (x ∷ []) rxs = [-]
Linked-++⁻ˡ (x ∷ y ∷ xs) (rx ∷ rxs) = rx ∷ Linked-++⁻ˡ (y ∷ xs) rxs
Linked-∷⁻ʳ : ∀ {x xs} → Linked R (x ∷ xs) → Linked R xs
Linked-∷⁻ʳ {x = x} = Linked-++⁻ʳ [ x ]
Linked-∷ʳ⁻ˡ : ∀ {xs x} → Linked R (xs ∷ʳ x) → Linked R xs
Linked-∷ʳ⁻ˡ {xs = xs} = Linked-++⁻ˡ xs
{-
Linked-∷ʳ₂⁺ : ∀ {xs x y} → Linked R (xs ∷ʳ x) → R x y → Linked R (xs ∷ʳ x ∷ʳ y)
Linked-∷ʳ₂⁺ {[]} {x} {y} [-] Rxy = Rxy ∷ [-]
Linked-∷ʳ₂⁺ {x′ ∷ xs} {x} {y} l Rxy = {! !}
Linked-reverse⁺ : ∀ {xs} → Linked (flip R) xs → Linked R (reverse xs)
Linked-reverse⁺ {[]} l = []
Linked-reverse⁺ {x ∷ []} l = [-]
Linked-reverse⁺ {x ∷ y ∷ xs} (Rxy ∷ l) = {! Rxy ∷ !}
-}
-- Linked-inits⁺
-- respects
-- Linked-++⁻-middle : ∀ xs {ys} → Linked R (xs ++ ys) → Last (λ x → First (R x) ys) xs
Linked-universal : B.Universal R → U.Universal (Linked R)
Linked-universal u [] = []
Linked-universal u (x ∷ []) = [-]
Linked-universal u (x ∷ x₁ ∷ xs) = u x x₁ ∷ Linked-universal u (x₁ ∷ xs)
module _ (R-trans : Transitive R) where
private
L⇒A : ∀ {xs} → Linked R xs → AllPairs R xs
L⇒A = Linkedₚ.Linked⇒AllPairs R-trans
Linked-trans-∷ : ∀ {x xs} → All (R x) xs → Linked R xs → Linked R (x ∷ xs)
Linked-trans-∷ a l = Linkedₚ.AllPairs⇒Linked (a ∷ L⇒A l)
Linked-trans-head : ∀ {x xs} → Linked R (x ∷ xs) → All (R x) xs
Linked-trans-head = AllPairs.head ∘ L⇒A
{-
Linked-++⁺ : Linked R xs → Linked R ys → Frist (λ x → Last (λ y → R xy) ys) xs → Linked R (xs ++ ys)
-}
-- stdlib?
AllPairs-trans-∷₂ : ∀ {a r} {A : Set a} {R : Rel A r} {x y ys} →
Transitive R →
R x y → AllPairs R (y ∷ ys) → AllPairs R (x ∷ y ∷ ys)
AllPairs-trans-∷₂ R-trans Rxy rxs@(px ∷ _) =
(Rxy ∷ All.map (λ {z} Ryz → R-trans Rxy Ryz) px) ∷ rxs
-- Transitive R → AllPairs R (xs ∷ʳ v) → AllPairs R (v ∷ ys)
-- AllPairs R (xs ++ [ v ] ++ ys)
-- Transitive R → length ys ≥ 1 → AllPairs R (xs ++ ys) → AllPairs R (ys ++ zs) →
-- AllPairs (xs ++ ys ++ zs)
|
{
"alphanum_fraction": 0.5729070837,
"avg_line_length": 39.8899082569,
"ext": "agda",
"hexsha": "a514d687ac2cf27c4203a2adfef40d824e04419e",
"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": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Experiment/ListRelationProperties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"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": "rei1024/agda-misc",
"max_issues_repo_path": "Experiment/ListRelationProperties.agda",
"max_line_length": 102,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Experiment/ListRelationProperties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 3507,
"size": 8696
}
|
module ExtractFunction where
open import Data.List
open import ParseTree
open import Data.Nat
open import Data.String hiding (_++_)
open import ScopeState using (ScopeState ; ScopeEnv ; replaceID ; liftIO ; getUniqueIdentifier)
open import ScopeParseTree
open import AgdaHelperFunctions
open import Typing
open import Data.Bool
open import MatchUpNames
open import Category.Monad.State
open import Data.Product
open import Data.Maybe
open import Relation.Nullary
open import Data.Unit using (⊤ ; tt)
open import Data.Nat.Show
open import ParseTreeOperations
--TODO: actually, it is okay if the module has no name - in this case we do not need to rename it.
getIDForModule : List ParseTree -> ScopeState Identifier
getIDForModule [] = ScopeState.fail "This module seems to have no name"
getIDForModule (moduleName id range₁ ∷ p) = ScopeState.return id
getIDForModule (x ∷ xs) = getIDForModule xs
record ExtractionEnv : Set where
constructor extEnv
field
stuffBeforeFunc : List ParseTree
stuffAfterFunc : List ParseTree
rightHandSideBuilder : Maybe (Expr -> Expr)
extractedExpr : Maybe Expr
holesPassed : ℕ
functionRebuilder : Maybe (Expr -> ParseTree)
oldFunctionName : Maybe Identifier
ExtractionState : Set -> Set
ExtractionState = StateT ExtractionEnv ScopeState
runExtractionState :
{a : Set} -> ExtractionState a -> ExtractionEnv -> ScopeState a
runExtractionState eMonad e = do
(result , newState) <- eMonad e
return result
where open RawMonadState (StateTMonadState ScopeEnv (SumMonadT IOMonad String))
liftScopeState : {a : Set} -> ScopeState a -> ExtractionState a
liftScopeState action ee = do
a <- action
return (a , ee)
where open RawMonadState (StateTMonadState ScopeEnv (SumMonadT IOMonad String))
open RawMonadState (StateTMonadState ExtractionEnv (StateTMonad ScopeEnv (SumMonadT IOMonad String)))
fail : {a : Set} -> String -> ExtractionState a
fail s = liftScopeState $ ScopeState.fail s
--assuming that start < end
isInside : Range -> ℕ -> ℕ -> Bool
isInside (range lastUnaffected lastAffected) start end
with end ≤? lastUnaffected | lastAffected ≤? suc start
... | no p | no q = true
... | p | q = false
isInIdent : Identifier -> ℕ -> ℕ -> Bool
isInIdent (identifier name isInRange scope declaration {b}{c} {c2}) start end
with isInRange start | isInRange end
... | after | _ = false
... | _ | before = false
... | _ | _ = true
findPartInExpr : Expr -> ℕ -> ℕ -> ExtractionState Bool
findPartInExpr (numLit {value}
{r} {c} {c2}) start end
with isInside r start end
... | true = do
extEnv x y f expr h g n <- get
put $ extEnv x y (just(λ a -> a)) (just $ numLit {value} {r} {c} {c2}) h g n
return true
... | false = return false
findPartInExpr (ident id) start end
with isInIdent id start end
... | false = return false
... | true = do
extEnv x y f expr h g n <- get
put $ extEnv x y (just(λ a -> a)) (just $ ident id) h g n
return true
findPartInExpr (hole {t} {p} {c} {c2}) start end
with isInside p start end
... | true = do
extEnv x y f expr h g n <- get
put $ extEnv x y (just(λ a -> a)) (just $ hole {t} {p} {c} {c2}) h g n
return true
... | false = return false
findPartInExpr (functionApp e e₁ {false} ) start end = do
true <- findPartInExpr e₁ start end
where false -> do
true <- findPartInExpr e start end
where false -> return false
-- here we want to extract some subexpression of e
-- so we rebuild it with rebuilder f and put it in the functionApp
extEnv x y (just f) expr h g n <- get
where _ -> fail "Got no function despite extraction"
put $ extEnv x y (just(λ x -> functionApp (f x) e₁ {false})) expr h g n
return true
extEnv x y (just f) expr h g n <- get
where _ -> fail "Got no function despite extraction"
true <- findPartInExpr e start end
where false -> do -- extract only (part of) e₁
put $ extEnv x y (just (λ a -> functionApp e (f a) {false})) expr h g n
return true
-- at this point we realize we want to extract the entire
-- functionApp
-- Therefore, we need to extract entire e and e₁ regardless of
-- how far into it the selection extends.
--extEnv x y f expr h g n <- get
put $ extEnv x y (just (λ x -> x)) (just $ functionApp e e₁ {false} ) h g n
return true
findPartInExpr (functionApp e e₁ {true} ) start end = do
true <- findPartInExpr e start end
where false -> do
true <- findPartInExpr e₁ start end
where false -> return false
extEnv x y (just f) expr h g n <- get
where _ -> fail "Got no function despite extraction"
put $ extEnv x y (just(λ x -> functionApp e (f x) {true} )) expr h g n
return true
extEnv x y (just f) expr h g n <- get
where _ -> fail "Got no function despite extraction"
namedArgument sign <- return e
where _ -> do
-- e is not a named argument so can be extracted by itself
true <- findPartInExpr e₁ start end
where false -> do
put $ extEnv x y (just (λ a -> functionApp (f e) e₁ {true})) expr h g n
return true
put $ extEnv x y (just (λ x -> x)) (just $ functionApp e e₁ {true}) h g n
return true
put $ extEnv x y (just $ λ x -> x) (just $ functionApp e e₁ {true}) h g n
return true
findPartInExpr (implicit x) start end = do
true <- findPartInExpr x start end
where false -> return false
extEnv x y (just f) expr h g n <- get
where _ -> fail "Extraction failed"
put $ extEnv x y (just(λ a -> implicit $ f a)) expr h g n
return true
findPartInExpr (underscore {p} {c1} {c2}) start end with isInside p start end
... | true = do
extEnv x y f expr h g n <- get
put $ extEnv x y (just(λ a -> a)) (just $ underscore {p} {c1} {c2}) h g n
return true
... | false = return false
findPartInExpr (namedArgument (typeSignature funcName funcType) {b} {bef} {aft}) start end
with isInIdent funcName start end
-- can't extract just the name of a variable
... | true = do
extEnv x y f expr h g n <- get
put $ extEnv x y (just $ λ x -> x)
(just $ namedArgument (typeSignature funcName funcType) {b} {bef} {aft}) h g n
return true
... | false = do
true <- findPartInExpr funcType start end
where false -> return false
extEnv x y (just f) expr h g n <- get
where _ -> fail "No function in state"
put $ extEnv x y (just $ λ x -> namedArgument (typeSignature funcName $ f x) {b} {bef} {aft}) expr h g n
return true
sameNameAndStatus : Identifier -> Identifier -> Bool
sameNameAndStatus (identifier name isInRange scope declaration {inScope1}) (identifier name₁ isInRange₁ scope₁ declaration₁ {inScope2}) = (name == name₁) ∧ (not $ inScope1 xor inScope2)
isIdInExpr : (whatToSearchFor : Identifier) -> (whereToSearch : Expr) -> Bool
isIdInExpr i (ident identifier₁) = sameNameAndStatus i identifier₁
isIdInExpr i (functionApp x x₁) = isIdInExpr i x ∨ isIdInExpr i x₁
isIdInExpr _ _ = false
countHole : ExtractionState ⊤
countHole = do
extEnv b a func exp h g n <- get
put $ extEnv b a func exp (suc h) g n
return tt
mapState : {A B : Set} -> (A -> ExtractionState B) -> List A -> ExtractionState (List B)
mapState f [] = return []
mapState f (x ∷ list) = do
x1 <- f x
xs <- mapState f list
return (x1 ∷ xs)
countHolesInSignature : TypeSignature -> ExtractionState ⊤
countHolesInExpr : Expr -> ExtractionState ⊤
countHolesInExpr hole = countHole
countHolesInExpr (functionApp e e₁) = do
countHolesInExpr e
countHolesInExpr e₁
countHolesInExpr (namedArgument arg) = countHolesInSignature arg
countHolesInExpr _ = return tt
countHolesInSignature (typeSignature funcName funcType) =
countHolesInExpr funcType
countHolesInTree : ParseTree -> ExtractionState ⊤
countHolesInTree (signature signature₁ range₁) = countHolesInSignature signature₁
countHolesInTree (functionDefinition definitionOf params body range₁) = countHolesInExpr body
countHolesInTree (dataStructure dataName parameters indexInfo constructors range₁) = do
mapState countHolesInSignature parameters
mapState countHolesInSignature constructors
countHolesInExpr indexInfo
countHolesInTree _ = return tt
findPartToExtract : List ParseTree -> ℕ -> ℕ -> ExtractionState ⊤
findPartToExtract [] start end = fail "Found nothing that can be extracted"
findPartToExtract (functionDefinition definitionOf params body (range a z) ∷ e)
start end with (suc a) ≤? start | end ≤? z
... | yes p | yes q = do
true <- findPartInExpr body start end
where false -> fail "Command start and end must be in the function body"
extEnv bef aft func exp h g n <- get
put $ extEnv bef e func exp h (just (λ x -> functionDefinition definitionOf params x (range a z))) $ just definitionOf
just ex <- return exp
where nothing -> fail "Didn't get an expression to extract"
mapState countHolesInTree bef
return tt
findPartToExtract (p ∷ ps) start end | yes a | no b = do
extEnv b a func exp h g n <- get
put $ extEnv (b ∷ʳ p) a func exp h g n
findPartToExtract ps start end
... | p | q = fail "Command start and end not fully inside any function"
findPartToExtract (p ∷ ps) start end = do
extEnv b a func exp h g n <- get
put $ extEnv (b ∷ʳ p) a func exp h g n
findPartToExtract ps start end
makeTypeFromTypes : List Expr -> ExtractionState Expr
makeTypeFromTypes [] = fail "Can't make type from nothing"
makeTypeFromTypes (x ∷ []) = return x
makeTypeFromTypes (x ∷ xs) = do
y <- makeTypeFromTypes xs
return $ functionApp x y {true}
makeExprFromExprs : List Expr -> ExtractionState Expr
makeExprFromExprs [] = fail "Can't make expr from nothing"
makeExprFromExprs (x ∷ []) = return x
makeExprFromExprs (x ∷ l) = do
y <- makeExprFromExprs l
return $ functionApp y x {false}
-- List of type signatures is environment. Contains all variables,
-- including not-in-scope. Return list is the new function's environment.
filterEnvironment : Expr -> List TypeSignature -> (extractedExp : Expr) -> ExtractionState (List TypeSignature)
filterEnvironment resultType [] varsUsed = return []
filterEnvironment resultType (typeSignature funcName funcType ∷ environment) extractedExpr = do
filteredEnv <- filterEnvironment resultType environment extractedExpr
let isInExtractedExpr = isIdInExpr funcName extractedExpr
let typesToCheck = Data.List.map (λ { (typeSignature n t) -> t}) filteredEnv
isInTypes <- mapState (findInType funcName) typesToCheck
let isIn = or isInTypes
if isIn ∨ isInExtractedExpr
then return $ (typeSignature funcName funcType) ∷ filteredEnv
else return filteredEnv
where
findInType : Identifier -> Expr -> ExtractionState Bool
findInType id (namedArgument (typeSignature funcName funcType)) = findInType id funcType
findInType id (functionApp t t₁ {true}) = do
one <- findInType id t
two <- findInType id t₁
return $ one ∨ two
findInType id expression = return $ isIdInExpr id expression
bringIdInScope : Identifier -> Identifier
bringIdInScope (identifier name isInRange scope declaration {inScope} {a} {b}) = identifier name isInRange scope declaration {true} {a}{b}
containsIdInSign : TypeSignature -> Identifier -> Bool
containsInType : Expr -> Identifier -> Bool
containsInType (namedArgument arg) i = containsIdInSign arg i
containsInType (functionApp t t₁ {true}) i = containsInType t i ∨ containsInType t₁ i
containsInType expression i = isIdInExpr i expression
containsIdInSign (typeSignature name funcType) id = sameNameAndStatus name id ∨ containsInType funcType id
isInScope : Identifier -> Bool
isInScope (identifier _ _ _ _ {isInScope}) = isInScope
bringExprInScope : Expr -> Expr
bringExprInScope (ident id) = ident $ bringIdInScope id
bringExprInScope (functionApp e e₁ {b} ) = functionApp (bringExprInScope e) (bringExprInScope e₁) {b}
bringExprInScope (implicit e) = implicit $ bringExprInScope e
bringExprInScope x = x
bringInScope : Expr -> Expr
bringSignatureInScope : TypeSignature -> TypeSignature
bringSignatureInScope (typeSignature funcName funcType) =
typeSignature (bringIdInScope funcName) $ bringInScope funcType
bringInScope (namedArgument arg {b} {bef} {aft}) = namedArgument (bringSignatureInScope arg) {b} {bef} {aft}
bringInScope (functionApp t t₁ {true} ) = functionApp (bringInScope t) (bringInScope t₁) {true}
bringInScope expression = bringExprInScope expression
renameNotInScopeExpr : Identifier -> Identifier -> Expr -> Expr
renameNotInScopeExpr (identifier name₁ isInRange₁ scope₁ declaration₁) to (ident (identifier name isInRange scope declaration {false} {b} {a})) with name == name₁
renameNotInScopeExpr (identifier name₁ isInRange₁ scope₁ declaration₁) (identifier name₂ isInRange₂ scope₂ declaration₂) (ident (identifier name isInRange scope declaration {false} {b} {a})) | true = ident $ identifier name₂ isInRange₂ scope₂ declaration₂ {false}{b} {a}
... | false = ident $ identifier name isInRange scope declaration {false} {b} {a}
renameNotInScopeExpr from to (functionApp e e₁ {b} ) =
functionApp (renameNotInScopeExpr from to e) (renameNotInScopeExpr from to e₁) {b}
renameNotInScopeExpr from to (implicit e) = implicit $ renameNotInScopeExpr from to e
renameNotInScopeExpr _ _ x = x
renameNotInScopeOfName : Identifier -> Identifier -> Expr -> Expr
renameNotInScopeSign : Identifier -> Identifier -> TypeSignature -> TypeSignature
renameNotInScopeSign from to (typeSignature funcName funcType) =
typeSignature funcName $ renameNotInScopeOfName from to funcType
renameNotInScopeOfName from to (namedArgument arg {b} {bef} {aft}) = namedArgument (renameNotInScopeSign from to arg) {b} {bef} {aft}
renameNotInScopeOfName from to (functionApp signs signs₁ {true} ) =
functionApp (renameNotInScopeOfName from to signs) (renameNotInScopeOfName from to signs₁) {true}
renameNotInScopeOfName from to expression = renameNotInScopeExpr from to expression
-- returns list of types, which are explicit or implicit named arguments
-- and a list of expressions which is the left-hand side of the new function, i.e. idents.
signatureToType : Expr -> List TypeSignature -> ExtractionState (List Expr × List Expr)
signatureToType result [] = return $ (result ∷ []) , []
signatureToType result (typeSignature funcName funcType ∷ laterSigns) = do
let inScopeType = bringInScope funcType
(restOfSigns , exprs) <- signatureToType result laterSigns
false <- return $ isInScope funcName
where true -> do -- in this case, we plainly don't want to rename anything
let newSign = namedArgument (typeSignature funcName funcType) {true} {[]}{[]}
return $ newSign ∷ restOfSigns , ident funcName ∷ exprs
-- Do we need to rename the current variable?
true <- return $ or $ Data.List.map (λ x -> containsIdInSign x $ bringIdInScope funcName) laterSigns
where false -> do
let newSign = namedArgument (typeSignature funcName funcType) {false} {[]}{[]}
return $ newSign ∷ restOfSigns , exprs
liftScopeState $ liftIO $ output "Need to rename a variable"
newName <- liftScopeState getUniqueIdentifier
let renamedSigns = Data.List.map (renameNotInScopeOfName funcName newName) restOfSigns
return $ namedArgument (typeSignature newName inScopeType) {false} {[]}{[]} ∷ renamedSigns , exprs
placeInRightPlace : Identifier -> (placeOverTypeSignature : Bool) -> ParseTree -> ParseTree -> List ParseTree -> List ParseTree
placeInRightPlace oldFunctionName _ newsign newdef [] = newsign ∷ newdef ∷ []
placeInRightPlace oldFunctionName false newsign newdef (functionDefinition definitionOf params body range₁ ∷ program) with sameId oldFunctionName definitionOf
...| false = functionDefinition definitionOf params body range₁ ∷ placeInRightPlace oldFunctionName false newsign newdef program
... | true = newsign ∷ newdef ∷ functionDefinition definitionOf params body range₁ ∷ program
placeInRightPlace oldFunctionName true newsign newdef (signature (typeSignature funcName funcType) range₁ ∷ program) with sameId oldFunctionName funcName
... | false = signature (typeSignature funcName funcType) range₁ ∷ placeInRightPlace oldFunctionName true newsign newdef program
... | true = newsign ∷ newdef ∷ signature (typeSignature funcName funcType) range₁ ∷ program
placeInRightPlace x y z a (p ∷ program) = p ∷ placeInRightPlace x y z a program
doExtraction : List ParseTree -> ℕ -> ℕ -> String -> ExtractionState (List ParseTree)
doExtraction program startPoint endPoint filename = do
scoped <- liftScopeState $ scopeParseTreeList program
-- TODO: Assuming that the module only has a simple name.
-- Otherwise, need to calculate the right name.
identifier name _ _ declaration <- liftScopeState $ getIDForModule scoped
liftScopeState $ replaceID declaration "RefactorAgdaTemporaryFile"
renamedInputProgram <- liftScopeState $ matchUpNames scoped
findPartToExtract renamedInputProgram startPoint endPoint
extEnv b a (just expBuilder) (just extractedExp) h (just functionBuilder) (just oldFunctionName) <- get
where _ -> fail "An error in doExtraction"
let programWithNewHole = b ++
((functionBuilder $ expBuilder $ hole {""} {range 0 0} {[]} {[]})∷ a)
(resultTypeNewFunc ∷ []) <- liftScopeState $ liftIO $ getTypes
programWithNewHole h
(extractedExp ∷ []) filename
where _ -> fail "Something happened in InteractWithAgda"
environment <- liftScopeState $ liftIO $ getEnvironment programWithNewHole h filename
newFuncName <- liftScopeState $ getUniqueIdentifier
newFuncEnv <- filterEnvironment resultTypeNewFunc environment extractedExp
(newFuncSignParts , newFuncArgNames) <- signatureToType resultTypeNewFunc newFuncEnv
newFuncType <- makeTypeFromTypes $ newFuncSignParts
let newFuncSignature = signature (typeSignature newFuncName newFuncType) (range 0 0)
let newFuncDefinition = functionDefinition newFuncName newFuncArgNames extractedExp (range 0 0)
replacingExpr <- makeExprFromExprs $ reverse $ ident newFuncName ∷ newFuncArgNames
let oldFunction = functionBuilder $ expBuilder $ replacingExpr
let placeBelowTypeSignature = isIdInExpr oldFunctionName extractedExp
let completeCode = placeInRightPlace oldFunctionName (not placeBelowTypeSignature) newFuncSignature newFuncDefinition b ++
(oldFunction ∷ a)
scopeCompleted <- liftScopeState $ scopeParseTreeList completeCode
identifier _ _ _ d <- liftScopeState $ getIDForModule scopeCompleted
liftScopeState $ replaceID d name
liftScopeState $ matchUpNames scopeCompleted
extract : List ParseTree -> ℕ -> ℕ -> String -> ScopeState (List ParseTree)
extract p s e f = runExtractionState (doExtraction p s e f) $ extEnv [] [] nothing nothing 0 nothing nothing
|
{
"alphanum_fraction": 0.7151582162,
"avg_line_length": 47.7211055276,
"ext": "agda",
"hexsha": "0a7664ab09af04b15ac0f93d00f80845e7ae3373",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "omega12345/RefactorAgda",
"max_forks_repo_path": "RefactorAgdaEngine/ExtractFunction.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "omega12345/RefactorAgda",
"max_issues_repo_path": "RefactorAgdaEngine/ExtractFunction.agda",
"max_line_length": 270,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "omega12345/RefactorAgda",
"max_stars_repo_path": "RefactorAgdaEngine/ExtractFunction.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z",
"num_tokens": 5206,
"size": 18993
}
|
-- Andreas, James, 2011-11-24
-- trigger error message 'NeedOptionCopatterns'
module NeedOptionCopatterns where
record Bla : Set2 where
field
bla : Set1
open Bla
f : Bla
bla f = Set
-- should request option --copatterns
|
{
"alphanum_fraction": 0.7292576419,
"avg_line_length": 16.3571428571,
"ext": "agda",
"hexsha": "dbd67c3f56a7e20533ff136fc9236c9eba9e7fef",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/NeedOptionCopatterns.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/NeedOptionCopatterns.agda",
"max_line_length": 47,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/fail/NeedOptionCopatterns.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 72,
"size": 229
}
|
-- Copyright: (c) 2016 Ertugrul Söylemez
-- License: BSD3
-- Maintainer: Ertugrul Söylemez <[email protected]>
module Data.Int where
open import Algebra.Group
open import Classes
open import Core
open import Data.Int.Core
open import Data.Int.Core public
using (ℤ; ℤ-Negative; ℤ-Number; negsuc; pos)
ℤ,+ : Group
ℤ,+ =
record {
semigroup = record {
A = ℤ;
Eq = PropEq ℤ;
semigroupOver = record {
_⋄_ = _+_;
⋄-cong = cong2 _+_;
assoc = Props.+-assoc
}
};
isGroup = record {
isMonoid = record {
id = 0;
left-id = Props.+-left-id;
right-id = Props.+-right-id
};
iso = λ x → record {
inv = neg x;
left-inv = Props.+-left-inv x;
right-inv = Props.+-right-inv x
};
inv-cong = cong neg
}
}
ℤ,* : Monoid
ℤ,* =
record {
semigroup = record {
A = ℤ;
Eq = PropEq ℤ;
semigroupOver = record {
_⋄_ = _*_;
⋄-cong = cong2 _*_;
assoc = Props.*-assoc
}
};
isMonoid = record {
id = 1;
left-id = Props.*-left-id;
right-id = Props.*-right-id
}
}
|
{
"alphanum_fraction": 0.5141874463,
"avg_line_length": 19.0655737705,
"ext": "agda",
"hexsha": "446148e4acc244e9b8631a240647c68e9f69d182",
"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": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "esoeylemez/agda-simple",
"max_forks_repo_path": "Data/Int.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"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": "esoeylemez/agda-simple",
"max_issues_repo_path": "Data/Int.agda",
"max_line_length": 48,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "esoeylemez/agda-simple",
"max_stars_repo_path": "Data/Int.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-07T17:36:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-07T17:36:42.000Z",
"num_tokens": 379,
"size": 1163
}
|
module Luau.Syntax.ToString where
open import Agda.Builtin.Float using (primShowFloat)
open import Luau.Syntax using (Block; Stat; Expr; VarDec; FunDec; nil; var; var_∈_; addr; _$_; function_is_end; return; local_←_; _∙_; done; block_is_end; _⟨_⟩; _⟨_⟩∈_; number; BinaryOperator; +; -; *; /; binexp)
open import FFI.Data.String using (String; _++_)
open import Luau.Addr.ToString using (addrToString)
open import Luau.Type.ToString using (typeToString)
open import Luau.Var.ToString using (varToString)
varDecToString : ∀ {a} → VarDec a → String
varDecToString (var x) = varToString x
varDecToString (var x ∈ T) = varToString x ++ " : " ++ typeToString T
funDecToString : ∀ {a} → FunDec a → String
funDecToString ("" ⟨ x ⟩∈ T) = "function(" ++ varDecToString x ++ "): " ++ typeToString T
funDecToString ("" ⟨ x ⟩) = "function(" ++ varDecToString x ++ ")"
funDecToString (f ⟨ x ⟩∈ T) = "function " ++ varToString f ++ "(" ++ varDecToString x ++ "): " ++ typeToString T
funDecToString (f ⟨ x ⟩) = "function " ++ varToString f ++ "(" ++ varDecToString x ++ ")"
binOpToString : BinaryOperator → String
binOpToString + = "+"
binOpToString - = "-"
binOpToString * = "*"
binOpToString / = "/"
exprToString′ : ∀ {a} → String → Expr a → String
statToString′ : ∀ {a} → String → Stat a → String
blockToString′ : ∀ {a} → String → Block a → String
exprToString′ lb nil =
"nil"
exprToString′ lb (addr a) =
addrToString(a)
exprToString′ lb (var x) =
varToString(x)
exprToString′ lb (M $ N) =
(exprToString′ lb M) ++ "(" ++ (exprToString′ lb N) ++ ")"
exprToString′ lb (function F is B end) =
funDecToString F ++ lb ++
" " ++ (blockToString′ (lb ++ " ") B) ++ lb ++
"end"
exprToString′ lb (block b is B end) =
"(" ++ b ++ "()" ++ lb ++
" " ++ (blockToString′ (lb ++ " ") B) ++ lb ++
"end)()"
exprToString′ lb (number x) = primShowFloat x
exprToString′ lb (binexp x op y) = exprToString′ lb x ++ " " ++ binOpToString op ++ " " ++ exprToString′ lb y
statToString′ lb (function F is B end) =
"local " ++ funDecToString F ++ lb ++
" " ++ (blockToString′ (lb ++ " ") B) ++ lb ++
"end"
statToString′ lb (local x ← M) =
"local " ++ varDecToString x ++ " = " ++ (exprToString′ lb M)
statToString′ lb (return M) =
"return " ++ (exprToString′ lb M)
blockToString′ lb (S ∙ done) = statToString′ lb S
blockToString′ lb (S ∙ B) = statToString′ lb S ++ lb ++ blockToString′ lb B
blockToString′ lb (done) = ""
exprToString : ∀ {a} → Expr a → String
exprToString = exprToString′ "\n"
statToString : ∀ {a} → Stat a → String
statToString = statToString′ "\n"
blockToString : ∀ {a} → Block a → String
blockToString = blockToString′ "\n"
|
{
"alphanum_fraction": 0.6290566038,
"avg_line_length": 37.8571428571,
"ext": "agda",
"hexsha": "4a3061ba8d64e1a1795e270532392032405d5bf6",
"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": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Tr4shh/Roblox-Luau",
"max_forks_repo_path": "prototyping/Luau/Syntax/ToString.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734",
"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": "Tr4shh/Roblox-Luau",
"max_issues_repo_path": "prototyping/Luau/Syntax/ToString.agda",
"max_line_length": 212,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Tr4shh/Roblox-Luau",
"max_stars_repo_path": "prototyping/Luau/Syntax/ToString.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 841,
"size": 2650
}
|
module MJ.Examples.DynDispatch where
open import Prelude
import Data.Vec.All as Vec∀
open import Data.Star
open import Data.Bool
open import Data.List
open import Data.List.Any
open import Data.List.Membership.Propositional
open import Data.List.All hiding (lookup)
open import Data.Product hiding (Σ)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable
open import Data.String
open import MJ.Types
open import MJ.Classtable.Core 2
{-
// We test field inheritance and
// method call dispatching combining super calls and dynamic dispatch.
// The Agda test is equivalent to the following Java code
class Int {
int x;
public Int(int i) {
this.x = i;
return;
}
public int get() {
System.out.println("never");
return x;
}
public int set (Int y) {
x = y.x;
// in the test main this should dispatch to
// the implementation of the child Int2
return this.get();
}
}
class Int2 extends Int {
public Int2(int i) {
super(i);
}
public int get() {
return x + 1;
}
public int set (Int y) {
// test super dispatch
return super.set(new Int(y.x + 1));
}
}
class Main {
public static void main(String[] args) {
Int y = new Int(18);
Int2 x = new Int2(0);
// should print 20
// because we use the set(..) and get() of Int2
// which both increment with one
System.out.println(x.set(y));
}
}
-}
INT : Cid 2
INT = (cls (# 0))
INT+ : Cid 2
INT+ = (cls (# 1))
decls : (ns : NS) → List (String × typing ns)
decls METHOD =
("get" , ([] , int))
∷ ("set" , (ref INT ∷ [] , int))
∷ []
decls FIELD =
("x" , int)
∷ []
-- override methods; no extra fields
decls+ : (ns : NS) → List (String × typing ns)
decls+ METHOD =
("get" , ([] , int))
∷ ("set" , (ref INT ∷ [] , int))
∷ []
decls+ FIELD = []
IntegerSig = (class Object (int ∷ []) decls)
Integer+Sig = (class INT (int ∷ []) decls+)
-- class table signature
Σ : Classtable
Σ = record {
Σ = λ{
(cls zero) → IntegerSig ;
(cls (suc zero)) → Integer+Sig ;
(cls (suc (suc ()))) ;
Object → ObjectClass} ;
founded = refl ;
rooted = λ{
(cls zero) → super ◅ ε ;
(cls (suc zero)) → super ◅ super ◅ ε ;
(cls (suc (suc ()))) ;
Object → ε };
Σ-Object = refl }
open import MJ.Classtable.Code Σ
open import MJ.Syntax Σ
open import MJ.Syntax.Program Σ
-- Integer class body
IntegerImpl : Implementation INT
IntegerImpl = implementation
(body (body
(set
(var (here refl))
"x"
(var (there (here refl))) ◅ ε)
unit))
-- methods
(
-- get
body (body ε (get (var (here refl)) "x"))
-- set
∷ (body (body
(set
(var (here refl))
"x"
{int}
(get (var (there (here refl))) "x") ◅ ε)
(call (var (here refl)) "get" [])))
∷ []
)
-- Integer+ class body
Integer+Impl : Implementation INT+
Integer+Impl = implementation
(body (body
(
set (var (here refl)) "x" (var (there (here refl)))
◅ ε)
unit))
-- methods
(
-- override get
(body (body ε (iop (λ l r → l + r) (get (var (here refl)) "x") (num 1))))
-- set
∷ (super _ ⟨ new INT (iop (λ l r → l + r) (get (var (there (here refl))) "x") (num 1) ∷ []) ∷ [] ⟩then
body
ε
(var (here refl)))
∷ []
)
-- Implementation of the class table
Lib : Code
Lib (cls zero) = IntegerImpl
Lib (cls (suc zero)) = Integer+Impl
Lib (cls (suc (suc ())))
Lib Object = implementation (body (body ε unit)) []
open import MJ.Semantics Σ Lib
open import MJ.Semantics.Values Σ
-- a simple program
p₀ : Prog int
p₀ = Lib ,
let
x = (here refl)
y = (there (here refl))
in body
(
loc (ref INT) -- y
◅ loc (ref INT+) -- x
◅ asgn x (new INT+ ((num 0) ∷ []))
◅ asgn y (new INT ((num 18) ∷ []))
◅ ε
)
(call (var x) "set" (var y ∷ []))
test0 : p₀ ⇓⟨ 100 ⟩ (λ {W} (v : Val W int) → v ≡ num 20)
test0 = refl
|
{
"alphanum_fraction": 0.5316336166,
"avg_line_length": 20.8669950739,
"ext": "agda",
"hexsha": "7a1cac57dc4a7458b7dd391b4f91bb5cef56a8b7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJ/Examples/DynDispatch.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJ/Examples/DynDispatch.agda",
"max_line_length": 108,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJ/Examples/DynDispatch.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 1282,
"size": 4236
}
|
-- Andreas, 2017-09-09
-- Don't allow pattern synonyms where builtin constructor is expected
data Bool : Set where
true : Bool
false : Bool
pattern You = false
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE You #-} -- This should be rejected.
-- Expected error: ;-)
-- You must be a constructor in the binding to builtin FALSE
-- when checking the pragma BUILTIN FALSE You
|
{
"alphanum_fraction": 0.6870415648,
"avg_line_length": 24.0588235294,
"ext": "agda",
"hexsha": "9d837e5f09e34c6947aa0af79e52219e4455ba6b",
"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/BuiltinMustBeConstructorNotPatternSynonym.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/BuiltinMustBeConstructorNotPatternSynonym.agda",
"max_line_length": 69,
"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/BuiltinMustBeConstructorNotPatternSynonym.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": 103,
"size": 409
}
|
{-# OPTIONS --rewriting --without-K #-}
open import Agda.Primitive
open import Prelude
import GSeTT.Typed-Syntax
import Globular-TT.Syntax
{- Disk and Sphere contexts - properties -}
module Globular-TT.Disks {l} (index : Set l) (rule : index → GSeTT.Typed-Syntax.Ctx × (Globular-TT.Syntax.Pre-Ty index)) (eqdec-index : eqdec index) where
open import Globular-TT.Syntax index
open import Globular-TT.Rules index rule
open import Globular-TT.CwF-Structure index rule
open import Globular-TT.Uniqueness-Derivations index rule eqdec-index
open import Globular-TT.Typed-Syntax index rule eqdec-index
{- Definition of "universal source and target variables" -}
n-src : ℕ → ℕ
n-tgt : ℕ → ℕ
n⇒ : ℕ → Pre-Ty
n-src O = O
n-src (S n) = S (n-tgt n)
n-tgt n = S (n-src n)
n⇒ O = ∗
n⇒ (S n) = ⇒ (n⇒ n) (Var (n-src n)) (Var (n-tgt n))
dim⇒ : ∀ (n : ℕ) → dim (n⇒ n) == n
dim⇒ O = idp
dim⇒ (S n) = S= (dim⇒ n)
{- Syntactic definition of disks and spheres -}
Pre-𝕊 : ℕ → Pre-Ctx
Pre-𝔻 : ℕ → Pre-Ctx
Pre-𝕊 O = ⊘
Pre-𝕊 (S n) = (Pre-𝔻 n) ∙ C-length (Pre-𝔻 n) # n⇒ n
Pre-𝔻 n = (Pre-𝕊 n) ∙ C-length (Pre-𝕊 n) # n⇒ n
𝕊-length : ∀ n → C-length (Pre-𝕊 n) == n-src n
𝕊-length O = idp
𝕊-length (S n) = S= (S= (𝕊-length n))
{-# REWRITE 𝕊-length #-}
{- Disk and Sphere context are valid -}
𝕊⊢ : ∀ n → Pre-𝕊 n ⊢C
𝔻⊢ : ∀ n → Pre-𝔻 n ⊢C
𝕊⊢⇒ : ∀ n → Pre-𝕊 n ⊢T n⇒ n
𝕊⊢ O = ec
𝕊⊢ (S n) = cc (𝔻⊢ n) (wkT (𝕊⊢⇒ n) (𝔻⊢ n)) idp
𝔻⊢ n = cc (𝕊⊢ n) (𝕊⊢⇒ n) idp
𝕊⊢⇒ O = ob ec
𝕊⊢⇒ (S n) = ar (wkT (wkT (𝕊⊢⇒ n) (𝔻⊢ n)) (𝕊⊢ (S n))) (wkt (var (𝔻⊢ n) (inr (((𝕊-length n) ^) , idp))) (𝕊⊢ (S n))) (var (𝕊⊢ (S n)) (inr ((S= (𝕊-length n) ^) , idp)))
𝕊 : ℕ → Ctx
𝕊 n = Pre-𝕊 n , 𝕊⊢ n
𝔻 : ℕ → Ctx
𝔻 n = Pre-𝔻 n , 𝔻⊢ n
Ty-n : ∀ {Γ} → Σ ℕ (λ n → Sub Γ (𝕊 n)) → Ty Γ
Ty-n {Γ} (n , (γ , Γ⊢γ:Sn) ) = ((n⇒ n)[ γ ]Pre-Ty) , ([]T (𝕊⊢⇒ n) Γ⊢γ:Sn)
private
Pre-χ : Pre-Ty → Pre-Sub
Pre-χ ∗ = <>
Pre-χ (⇒ A t u) = < < Pre-χ A , n-src (dim A) ↦ t > , n-tgt (dim A) ↦ u >
χ_⊢ : ∀ {Γ A} → (Γ⊢A : Γ ⊢T A) → Γ ⊢S (Pre-χ A) > Pre-𝕊 (dim A)
⇒[χ_] : ∀ {Γ A} → (Γ⊢A : Γ ⊢T A) → A == ((n⇒ (dim A))[ Pre-χ A ]Pre-Ty)
χ ob Γ⊢ ⊢ = es Γ⊢
χ_⊢ {Γ} {⇒ A t u} (ar Γ⊢A Γ⊢t:A Γ⊢u:A) =
let Γ⊢χt = sc χ Γ⊢A ⊢ (𝔻⊢ (dim A)) (trT (⇒[χ Γ⊢A ]) Γ⊢t:A) idp in
sc Γ⊢χt (𝕊⊢ (S (dim A))) (trT (⇒[χ Γ⊢A ] >> (wk[]T (𝕊⊢⇒ (dim A)) Γ⊢χt ^)) Γ⊢u:A) idp
⇒[χ_] {Γ} {.∗} (ob _) = idp
⇒[χ_] {Γ} {(⇒ A t u)} (ar Γ⊢A Γ⊢t:A Γ⊢u:A) with eqdecℕ (n-src (dim A)) (n-tgt (dim A)) | eqdecℕ (n-src (dim A)) (n-src (dim A)) | eqdecℕ (S (n-src (dim A))) (S (n-src (dim A)))
... | inl contra | _ | _ = ⊥-elim (n≠Sn _ contra)
... | inr _ | inr n≠n | _ = ⊥-elim (n≠n idp)
... | inr _ | inl _ | inr n≠n = ⊥-elim (n≠n idp)
... | inr _ | inl _ | inl _ =
let Γ⊢χt = (sc χ Γ⊢A ⊢ (𝔻⊢(dim A)) (trT ⇒[χ Γ⊢A ] Γ⊢t:A) idp) in
let A=⇒[γt] = ⇒[χ Γ⊢A ] >> (wk[]T (𝕊⊢⇒ (dim A)) Γ⊢χt ^) in
⇒= (A=⇒[γt] >> (wk[]T (wkT (𝕊⊢⇒ (dim A)) (𝔻⊢ (dim A))) (sc Γ⊢χt (𝕊⊢ (S (dim A))) (trT A=⇒[γt] Γ⊢u:A) idp) ^)) idp idp
χ : ∀ {Γ} → Ty Γ → Σ ℕ λ n → Sub Γ (𝕊 n)
χ (A , Γ⊢A) = dim A , (Pre-χ A , χ Γ⊢A ⊢)
dim-Ty-n : ∀ {Γ} (n : ℕ) → (γ : Sub Γ (𝕊 n)) → dim (fst (Ty-n {Γ} (n , γ))) == n
dim-Ty-n n (γ , Γ⊢γ:Sn) = dim[] (n⇒ n) γ >> (dim⇒ n)
trS-sph : ∀ {Γ n m} → (p : n == m) → {γ : Sub Γ (𝕊 n)} → {δ : Sub Γ (𝕊 m)} → fst γ == fst δ → transport p γ == δ
trS-sph {Γ} {n} {m} idp {γ} {δ} x = eqS {Γ} {𝕊 m} γ δ x
lemma1 : ∀ t u γ n → (if n-src n ≡ S (n-src n) then u else (if n-src n ≡ n-src n then t else (Var (n-src n) [ γ ]Pre-Tm))) == t
lemma1 t u γ n with eqdecℕ (n-src n) (S (n-src n))
... | inl n=Sn = ⊥-elim (n≠Sn _ (n=Sn))
... | inr _ with eqdecℕ (n-src n) (n-src n)
... | inl _ = idp
... | inr n≠n = ⊥-elim (n≠n idp)
lemma2 : ∀ t u γ n → (if S (n-src n) ≡ S (n-src n) then u else (if S (n-src n) ≡ n-src n then t else (Var (S (n-src n)) [ γ ]Pre-Tm))) == u
lemma2 t u γ n with eqdecℕ (S (n-src n)) (S (n-src n))
... | inl _ = idp
... | inr n≠n = ⊥-elim (n≠n idp)
Pre-χTy-n : ∀ {Γ} (n : ℕ) → (γ : Sub Γ (𝕊 n)) → Pre-χ (fst (Ty-n {Γ} (n , γ))) == fst γ
Pre-χTy-n O (.<> , (es _)) = idp
Pre-χTy-n {Γ} (S n) (< < γ , _ ↦ t > , _ ↦ u > , (sc (sc Γ⊢γ:Sn _ Γ⊢t:A idp) _ Γ⊢u:A idp)) with eqdecℕ (n-src n) (S (n-src n)) | eqdecℕ (n-src n) (n-src n) | eqdecℕ (S (n-src n)) (S (n-src n))
... | inl contra | _ | _ = ⊥-elim (n≠Sn _ contra)
... | inr _ | inr n≠n | _ = ⊥-elim (n≠n idp)
... | inr _ | inl _ | inr n≠n = ⊥-elim (n≠n idp)
... | inr _ | inl _ | inl _ =
let χTm-n = (sc Γ⊢γ:Sn (𝔻⊢ n) Γ⊢t:A idp) in
<,>= (<,>= (ap Pre-χ (wk[]T (wkT (𝕊⊢⇒ n) (𝔻⊢ n)) (sc χTm-n (𝕊⊢ (S n)) Γ⊢u:A idp) >> wk[]T (𝕊⊢⇒ n) χTm-n) >> Pre-χTy-n {Γ} n (γ , Γ⊢γ:Sn))
(ap n-src (dim[] (n⇒ n) _ >> (dim⇒ n))) (lemma1 t u γ n))
(S= (ap n-src (dim[] (n⇒ n) _ >> (dim⇒ n))))
(lemma2 t u γ n)
χTy-n : ∀ {Γ} (n : ℕ) → (γ : Sub Γ (𝕊 n)) → χ {Γ} (Ty-n {Γ} (n , γ)) == (n , γ)
χTy-n {Γ} n γ = Σ= (dim-Ty-n {Γ} n γ) (trS-sph {Γ} (dim-Ty-n {Γ} n γ) {snd (χ {Γ} (Ty-n {Γ} (n , γ)))} {γ} (Pre-χTy-n {Γ} n γ))
Ty-classifier : ∀ Γ → is-equiv (Ty-n {Γ})
is-equiv.g (Ty-classifier Γ) (A , Γ⊢A) = χ {Γ} (A , Γ⊢A)
is-equiv.f-g (Ty-classifier Γ) (A , Γ⊢A) = Σ= (⇒[χ Γ⊢A ] ^) (has-all-paths-⊢T _ _)
is-equiv.g-f (Ty-classifier Γ) (n , γ) = χTy-n {Γ} n γ
is-equiv.adj (Ty-classifier Γ) (n , γ) = (is-prop-has-all-paths (is-set-Ty Γ _ _)) _ _
|
{
"alphanum_fraction": 0.437976438,
"avg_line_length": 42.7555555556,
"ext": "agda",
"hexsha": "21e86a57b65ec3e64990676d6c847b0568a64d94",
"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": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thibautbenjamin/catt-formalization",
"max_forks_repo_path": "Globular-TT/Disks.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"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": "thibautbenjamin/catt-formalization",
"max_issues_repo_path": "Globular-TT/Disks.agda",
"max_line_length": 196,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thibautbenjamin/catt-formalization",
"max_stars_repo_path": "Globular-TT/Disks.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3091,
"size": 5772
}
|
{-# OPTIONS --cubical --no-import-sorts #-}
module NumberSecondAttempt where
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
private
variable
ℓ ℓ' ℓ'' : Level
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Data.Unit.Base -- Unit
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
open import NumberPostulates
open import NumberStructures ℝℓ ℝℓ'
open import NumberBundles ℝℓ ℝℓ'
open import NumberInclusions ℝℓ ℝℓ'
module _ where
open ROrderedField ℝOF
data Number : Type (ℓ-max ℝℓ ℝℓ') where
ℕ[_] : (x : ℝCarrier) → Σ[ z ∈ ℕCarrier ] ℕ↪ℝ z ≡ x → Number
ℤ[_] : (x : ℝCarrier) → Σ[ z ∈ ℤCarrier ] ℤ↪ℝ z ≡ x → Number
ℚ[_] : (x : ℝCarrier) → Σ[ z ∈ ℚCarrier ] ℚ↪ℝ z ≡ x → Number
ℝ[_] : (x : ℝCarrier) → Unit → Number
ℚ₀⁺[_] : (x : ℝCarrier) → (0f ≤ x) × (Σ[ z ∈ ℚCarrier ] ℚ↪ℝ z ≡ x) → Number
ℚ⁺[_] : (x : ℝCarrier) → (0f < x) × (Σ[ z ∈ ℚCarrier ] ℚ↪ℝ z ≡ x) → Number
ℝ₀⁺[_] : (x : ℝCarrier) → 0f ≤ x → Number
ℝ⁺[_] : (x : ℝCarrier) → 0f < x → Number
num : Number → ℝCarrier
num (ℕ[ x ] _) = x
num (ℤ[ x ] _) = x
num (ℚ[ x ] _) = x
num (ℝ[ x ] _) = x
num (ℚ₀⁺[ x ] _) = x
num (ℚ⁺[ x ] _) = x
num (ℝ₀⁺[ x ] _) = x
num (ℝ⁺[ x ] _) = x
data NumberType : Type where
Tℕ : NumberType
Tℤ : NumberType
Tℚ : NumberType
Tℝ : NumberType
Tℚ₀⁺ : NumberType
Tℚ⁺ : NumberType
Tℝ₀⁺ : NumberType
Tℝ⁺ : NumberType
totype : NumberType → Type (ℓ-max ℝℓ ℝℓ')
totype Tℕ = (x : ℝCarrier) → Lift {ℝℓ} {ℓ-max ℝℓ ℝℓ'} (Σ[ z ∈ ℕCarrier ] ℕ↪ℝ z ≡ x)
totype Tℤ = (x : ℝCarrier) → Lift {ℝℓ} {ℓ-max ℝℓ ℝℓ'} (Σ[ z ∈ ℤCarrier ] ℤ↪ℝ z ≡ x)
totype Tℚ = (x : ℝCarrier) → Lift {ℝℓ} {ℓ-max ℝℓ ℝℓ'} (Σ[ z ∈ ℚCarrier ] ℚ↪ℝ z ≡ x)
totype Tℝ = (x : ℝCarrier) → Lift {ℓ-zero} {ℓ-max ℝℓ ℝℓ'} (Unit)
totype Tℚ₀⁺ = (x : ℝCarrier) → (0f ≤ x) × (Σ[ z ∈ ℚCarrier ] ℚ↪ℝ z ≡ x)
totype Tℚ⁺ = (x : ℝCarrier) → (0f < x) × (Σ[ z ∈ ℚCarrier ] ℚ↪ℝ z ≡ x)
totype Tℝ₀⁺ = (x : ℝCarrier) → 0f ≤ x
totype Tℝ⁺ = (x : ℝCarrier) → 0f < x
+-table : NumberType → NumberType → NumberType
+-table x y = y
module GenericOperations where
module ℕ' = ROrderedCommSemiring ℕOCSR
module ℝ' = ROrderedField ℝOF
module ℚ' = ROrderedField ℚOF
module _ where
open ℝ'
postulate
lemma1 : ∀ x y → 0f < x → 0f < y → 0f < (x + y)
lemma2 : ∀ x y → 0f ≤ x → 0f ≤ y → 0f ≤ (x + y)
_+_ : Number → Number → Number
-- IsROrderedCommSemiringInclusion.preserves-+ ℕ↪ℝinc
ℕ[ x ] (x₁ , p₁) + ℕ[ y ] (y₁ , q₁) = ℕ[ x ℝ'.+ y ]
(x₁ ℕ'.+ y₁ , transport (λ i → ℕ↪ℝ (x₁ ℕ'.+ y₁) ≡ (p₁ i ℝ'.+ q₁ i)) (IsROrderedCommSemiringInclusion.preserves-+ ℕ↪ℝinc x₁ y₁) )
ℚ⁺[ x ] (p₂ , x₁ , p₁) + ℚ⁺[ y ] (q₂ , y₁ , q₁) = ℚ⁺[ x ℝ'.+ y ]
(lemma1 x y p₂ q₂ , (x₁ ℚ'.+ y₁ , transport (λ i → ℚ↪ℝ (x₁ ℚ'.+ y₁) ≡ (p₁ i ℝ'.+ q₁ i)) (IsROrderedFieldInclusion.preserves-+ ℚ↪ℝinc x₁ y₁)))
ℚ₀⁺[ x ] (p₂ , x₁ , p₁) + ℚ₀⁺[ y ] (q₂ , y₁ , q₁) = ℚ₀⁺[ x ℝ'.+ y ]
(lemma2 x y p₂ q₂ , (x₁ ℚ'.+ y₁ , transport (λ i → ℚ↪ℝ (x₁ ℚ'.+ y₁) ≡ (p₁ i ℝ'.+ q₁ i)) (IsROrderedFieldInclusion.preserves-+ ℚ↪ℝinc x₁ y₁)))
-- TODO: more cases
-- default case
x + y = ℝ[ num x ℝ'.+ num y ] tt
instance
0<ℚ⁺ : ∀{x p} → ℝ'.0f ℝ'.< num (ℚ⁺[ x ] p)
0<ℚ⁺ {x} {0<x , p} = 0<x
|
{
"alphanum_fraction": 0.5444608567,
"avg_line_length": 36.7934782609,
"ext": "agda",
"hexsha": "f689cb1508c4aa43bac7c3878cf170b5324fc70e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "test/NumberSecondAttempt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/synthetic-reals",
"max_issues_repo_path": "test/NumberSecondAttempt.agda",
"max_line_length": 145,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "test/NumberSecondAttempt.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 1641,
"size": 3385
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Consequences of a monomorphism between orders
------------------------------------------------------------------------
-- See Data.Nat.Binary.Properties for examples of how this and similar
-- modules can be used to easily translate properties between types.
{-# OPTIONS --without-K --safe #-}
open import Function
open import Relation.Binary
open import Relation.Binary.Morphism
module Relation.Binary.Morphism.OrderMonomorphism
{a b ℓ₁ ℓ₂ ℓ₃ ℓ₄} {A : Set a} {B : Set b}
{_≈₁_ : Rel A ℓ₁} {_≈₂_ : Rel B ℓ₃}
{_∼₁_ : Rel A ℓ₂} {_∼₂_ : Rel B ℓ₄}
{⟦_⟧ : A → B}
(isOrderMonomorphism : IsOrderMonomorphism _≈₁_ _≈₂_ _∼₁_ _∼₂_ ⟦_⟧)
where
open import Data.Product using (map)
import Relation.Binary.Morphism.RelMonomorphism as RawRelation
open IsOrderMonomorphism isOrderMonomorphism
------------------------------------------------------------------------
-- Re-export equivalence proofs
module EqM = RawRelation Eq.isRelMonomorphism
open RawRelation isRelMonomorphism public
------------------------------------------------------------------------
-- Properties
reflexive : _≈₂_ ⇒ _∼₂_ → _≈₁_ ⇒ _∼₁_
reflexive refl x≈y = cancel (refl (cong x≈y))
irrefl : Irreflexive _≈₂_ _∼₂_ → Irreflexive _≈₁_ _∼₁_
irrefl irrefl x≈y x∼y = irrefl (cong x≈y) (mono x∼y)
antisym : Antisymmetric _≈₂_ _∼₂_ → Antisymmetric _≈₁_ _∼₁_
antisym antisym x∼y y∼x = injective (antisym (mono x∼y) (mono y∼x))
compare : Trichotomous _≈₂_ _∼₂_ → Trichotomous _≈₁_ _∼₁_
compare compare x y with compare ⟦ x ⟧ ⟦ y ⟧
... | tri< a ¬b ¬c = tri< (cancel a) (¬b ∘ cong) (¬c ∘ mono)
... | tri≈ ¬a b ¬c = tri≈ (¬a ∘ mono) (injective b) (¬c ∘ mono)
... | tri> ¬a ¬b c = tri> (¬a ∘ mono) (¬b ∘ cong) (cancel c)
respˡ : _∼₂_ Respectsˡ _≈₂_ → _∼₁_ Respectsˡ _≈₁_
respˡ resp x≈y x∼z = cancel (resp (cong x≈y) (mono x∼z))
respʳ : _∼₂_ Respectsʳ _≈₂_ → _∼₁_ Respectsʳ _≈₁_
respʳ resp x≈y y∼z = cancel (resp (cong x≈y) (mono y∼z))
resp : _∼₂_ Respects₂ _≈₂_ → _∼₁_ Respects₂ _≈₁_
resp = map respʳ respˡ
------------------------------------------------------------------------
-- Structures
isPreorder : IsPreorder _≈₂_ _∼₂_ → IsPreorder _≈₁_ _∼₁_
isPreorder O = record
{ isEquivalence = EqM.isEquivalence O.isEquivalence
; reflexive = reflexive O.reflexive
; trans = trans O.trans
} where module O = IsPreorder O
isPartialOrder : IsPartialOrder _≈₂_ _∼₂_ → IsPartialOrder _≈₁_ _∼₁_
isPartialOrder O = record
{ isPreorder = isPreorder O.isPreorder
; antisym = antisym O.antisym
} where module O = IsPartialOrder O
isTotalOrder : IsTotalOrder _≈₂_ _∼₂_ → IsTotalOrder _≈₁_ _∼₁_
isTotalOrder O = record
{ isPartialOrder = isPartialOrder O.isPartialOrder
; total = total O.total
} where module O = IsTotalOrder O
isDecTotalOrder : IsDecTotalOrder _≈₂_ _∼₂_ → IsDecTotalOrder _≈₁_ _∼₁_
isDecTotalOrder O = record
{ isTotalOrder = isTotalOrder O.isTotalOrder
; _≟_ = EqM.dec O._≟_
; _≤?_ = dec O._≤?_
} where module O = IsDecTotalOrder O
isStrictPartialOrder : IsStrictPartialOrder _≈₂_ _∼₂_ →
IsStrictPartialOrder _≈₁_ _∼₁_
isStrictPartialOrder O = record
{ isEquivalence = EqM.isEquivalence O.isEquivalence
; irrefl = irrefl O.irrefl
; trans = trans O.trans
; <-resp-≈ = resp O.<-resp-≈
} where module O = IsStrictPartialOrder O
isStrictTotalOrder : IsStrictTotalOrder _≈₂_ _∼₂_ →
IsStrictTotalOrder _≈₁_ _∼₁_
isStrictTotalOrder O = record
{ isEquivalence = EqM.isEquivalence O.isEquivalence
; trans = trans O.trans
; compare = compare O.compare
} where module O = IsStrictTotalOrder O
|
{
"alphanum_fraction": 0.614973262,
"avg_line_length": 34.6296296296,
"ext": "agda",
"hexsha": "683a529334ea2b7023ccbdc5e5ca1deb62c4effb",
"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/Morphism/OrderMonomorphism.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/Morphism/OrderMonomorphism.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/Relation/Binary/Morphism/OrderMonomorphism.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": 1320,
"size": 3740
}
|
{-# OPTIONS --without-K --safe #-}
module Definition.Typed.Consequences.Reduction where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.EqRelInstance
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Fundamental.Reducibility
open import Tools.Embedding
open import Tools.Product
-- Helper function where all reducible types can be reduced to WHNF.
whNorm′ : ∀ {A Γ l} ([A] : Γ ⊩⟨ l ⟩ A)
→ ∃ λ B → Whnf B × Γ ⊢ A :⇒*: B
whNorm′ (Uᵣ′ .⁰ 0<1 ⊢Γ) = U , Uₙ , idRed:*: (Uⱼ ⊢Γ)
whNorm′ (ℕᵣ D) = ℕ , ℕₙ , D
whNorm′ (ne′ K D neK K≡K) = K , ne neK , D
whNorm′ (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) = Π F ▹ G , Πₙ , D
whNorm′ (emb′ 0<1 [A]) = whNorm′ [A]
-- Well-formed types can all be reduced to WHNF.
whNorm : ∀ {A Γ} → Γ ⊢ A → ∃ λ B → Whnf B × Γ ⊢ A :⇒*: B
whNorm A = whNorm′ (reducible A)
-- Helper function where reducible all terms can be reduced to WHNF.
whNormTerm′ : ∀ {a A Γ l} ([A] : Γ ⊩⟨ l ⟩ A) → Γ ⊩⟨ l ⟩ a ∷ A / [A]
→ ∃ λ b → Whnf b × Γ ⊢ a :⇒*: b ∷ A
whNormTerm′ (Uᵣ′ a b c) (Uₜ A d typeA A≡A [t]) = A , typeWhnf typeA , d
whNormTerm′ (ℕᵣ x) (ιx (ℕₜ n d n≡n prop)) =
let natN = natural prop
in n , naturalWhnf natN , convRed:*: d (sym (subset* (red x)))
whNormTerm′ (ne′ K D neK K≡K) (ιx (neₜ k d (neNfₜ neK₁ ⊢k k≡k))) =
k , ne neK₁ , convRed:*: d (sym (subset* (red D)))
whNormTerm′ (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Πₜ f d funcF f≡f [f] [f]₁) =
f , functionWhnf funcF , convRed:*: d (sym (subset* (red D)))
whNormTerm′ (emb′ 0<1 [A]) (ιx [a]) = whNormTerm′ [A] [a]
-- Well-formed terms can all be reduced to WHNF.
whNormTerm : ∀ {a A Γ} → Γ ⊢ a ∷ A → ∃ λ b → Whnf b × Γ ⊢ a :⇒*: b ∷ A
whNormTerm {a} {A} ⊢a =
let [A] , [a] = reducibleTerm ⊢a
in whNormTerm′ [A] [a]
|
{
"alphanum_fraction": 0.5996818664,
"avg_line_length": 39.2916666667,
"ext": "agda",
"hexsha": "fd7ee97284ac039f15340129af2eb0c02061b4de",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/Typed/Consequences/Reduction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/Typed/Consequences/Reduction.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/Typed/Consequences/Reduction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 814,
"size": 1886
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Definition
open import Groups.Abelian.Definition
open import Setoids.Setoids
open import Rings.Definition
open import Modules.Definition
module Modules.DirectSum {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+R_ : A → A → A} {_*R_ : A → A → A} (R : Ring S _+R_ _*R_) {m n o p : _} {M : Set m} {T : Setoid {m} {n} M} {_+_ : M → M → M} {G' : Group T _+_} {G : AbelianGroup G'} {_·1_ : A → M → M} {N : Set o} {U : Setoid {o} {p} N} {_+'_ : N → N → N} {H' : Group U _+'_} {H : AbelianGroup H'} {_·2_ : A → N → N} (M1 : Module R G _·1_) (M2 : Module R H _·2_) where
open import Groups.Abelian.DirectSum G H
open import Setoids.Product T U
directSumModule : Module R directSumAbGroup λ r mn → ((r ·1 (_&&_.fst mn)) ,, (r ·2 (_&&_.snd mn)))
Module.dotWellDefined directSumModule r=s t=u = productLift (Module.dotWellDefined M1 r=s (_&&_.fst t=u)) (Module.dotWellDefined M2 r=s (_&&_.snd t=u))
Module.dotDistributesLeft directSumModule = productLift (Module.dotDistributesLeft M1) (Module.dotDistributesLeft M2)
Module.dotDistributesRight directSumModule = productLift (Module.dotDistributesRight M1) (Module.dotDistributesRight M2)
Module.dotAssociative directSumModule = productLift (Module.dotAssociative M1) (Module.dotAssociative M2)
Module.dotIdentity directSumModule = productLift (Module.dotIdentity M1) (Module.dotIdentity M2)
|
{
"alphanum_fraction": 0.6976256983,
"avg_line_length": 65.0909090909,
"ext": "agda",
"hexsha": "bc3d54dff95b58fde16a7efebc2a863eb5e00542",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Modules/DirectSum.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Modules/DirectSum.agda",
"max_line_length": 424,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Modules/DirectSum.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 478,
"size": 1432
}
|
------------------------------------------------------------------------
-- There is a term without a corresponding syntactic type (given some
-- assumptions)
------------------------------------------------------------------------
import Level
open import Data.Universe
module README.DependentlyTyped.Term-without-type
(Uni₀ : Universe Level.zero Level.zero)
where
import Axiom.Extensionality.Propositional as E
open import Data.Product
open import Function renaming (const to k)
import README.DependentlyTyped.NBE as NBE; open NBE Uni₀
import README.DependentlyTyped.NormalForm as NF; open NF Uni₀
import README.DependentlyTyped.Term as Term; open Term Uni₀
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_)
open import Relation.Nullary using (¬_)
abstract
-- There are no closed neutral terms.
no-closed-neutral : ∀ {σ} → ¬ (ε ⊢ σ ⟨ ne ⟩)
no-closed-neutral (var ())
no-closed-neutral (t₁ · t₂) = no-closed-neutral t₁
-- There are no closed normal forms of "atomic" type.
no-closed-atomic-normal :
∀ {σ} → ε ⊢ σ atomic-type → ¬ (ε ⊢ σ ⟨ no ⟩)
no-closed-atomic-normal ⋆ (ne ⋆ t) = no-closed-neutral t
no-closed-atomic-normal el (ne el t) = no-closed-neutral t
-- There are no closed terms of "atomic" type (assuming
-- extensionality).
no-closed-atomic :
E.Extensionality Level.zero Level.zero →
∀ {σ} → ε ⊢ σ atomic-type → ¬ (ε ⊢ σ)
no-closed-atomic ext atomic t =
no-closed-atomic-normal atomic (normalise ext t)
-- There are terms without syntactic types, assuming that U₀ is
-- inhabited (and also extensionality).
--
-- One could avoid this situation by annotating lambdas with the
-- (syntactic) type of their domain. I tried this, and found it to
-- be awkward. One case of the function
-- README.DependentlyTyped.NBE.Value.řeify returns a lambda, and I
-- didn't find a way to synthesise the annotation without supplying
-- syntactic types to V̌alue, řeify, řeflect, etc.
term-without-type :
E.Extensionality Level.zero Level.zero → U₀ →
∃₂ λ Γ σ → ∃ λ (t : Γ ⊢ σ) → ¬ (Γ ⊢ σ type)
term-without-type ext u = (ε , (-, σ) , ƛ (var zero) , proof)
where
σ : IType ε (π el el)
σ = k (U-π (U-el u) (k (U-el u)))
proof : ∀ {σ} → ¬ (ε ⊢ π el el , σ type)
proof (π (el t) (el t′)) = no-closed-atomic ext ⋆ t
|
{
"alphanum_fraction": 0.6341463415,
"avg_line_length": 35.4090909091,
"ext": "agda",
"hexsha": "85e5c166767484b3d2dae2cee1a1593124e1a459",
"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": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependently-typed-syntax",
"max_forks_repo_path": "README/DependentlyTyped/Term-without-type.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"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/dependently-typed-syntax",
"max_issues_repo_path": "README/DependentlyTyped/Term-without-type.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependently-typed-syntax",
"max_stars_repo_path": "README/DependentlyTyped/Term-without-type.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z",
"num_tokens": 681,
"size": 2337
}
|
module Scope where
{-
So this goes through (we don't actually check scope). But what could really
go wrong? This actually isn't captured by the main theorem, since we're type
checking multiple definitions. Maybe it should be strengthened.
Still nothing _bad_ happens here. Could we get some weird circular thing?
Probably not. The main reason to check scope is to be able to state soundness
in a reasonable way. So maybe we shouldn't make a big deal of scope.
-}
id : _ -> _
id x = x
data Nat : Set where
zero : Nat
suc : Nat -> Nat
z = id zero
|
{
"alphanum_fraction": 0.7162872154,
"avg_line_length": 22.84,
"ext": "agda",
"hexsha": "bec3e1f723017fba85e18cf16530986207399ca0",
"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": "notes/papers/implicit/examples/Scope.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": "notes/papers/implicit/examples/Scope.agda",
"max_line_length": 79,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "notes/papers/implicit/examples/Scope.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": 145,
"size": 571
}
|
{-# OPTIONS --without-K --exact-split --rewriting #-}
open import Coequalizers.Definition
open import lib.Basics
open import lib.types.Paths
open import Graphs.Definition
module Coequalizers.EdgeCoproduct where
module CoeqCoprodEquiv {i j k : ULevel} (V : Type i) (E₁ : Type j) (E₂ : Type k) ⦃ gph : Graph (E₁ ⊔ E₂) V ⦄ where
instance
gph1 : Graph E₁ V
gph1 = record { π₀ = (Graph.π₀ gph) ∘ inl ; π₁ = (Graph.π₁ gph) ∘ inl }
instance
gph2 : Graph E₂ (V / E₁)
gph2 = record { π₀ = c[_] ∘ (Graph.π₀ gph) ∘ inr ; π₁ = c[_] ∘ (Graph.π₁ gph) ∘ inr }
edge-coproduct-expand : (V / (E₁ ⊔ E₂)) ≃ ((V / E₁) / E₂)
edge-coproduct-expand = equiv f g f-g g-f
where
f : V / (E₁ ⊔ E₂) → (V / E₁) / E₂
f = Coeq-rec (c[_] ∘ c[_]) λ { (inl x) → ap c[_] (quot x) ; (inr x) → quot x}
g : (V / E₁) / E₂ → V / (E₁ ⊔ E₂)
g = Coeq-rec (Coeq-rec c[_] (λ e → quot (inl e))) (λ e → quot (inr e))
f-g : (x : (V / E₁) / E₂) → (f (g x) == x)
f-g = Coeq-elim (λ x' → f (g x') == x') (Coeq-elim (λ x' → f (g (c[ x' ])) == c[ x' ]) (λ v → idp) (λ e → ↓-='-in (lemma1 e))) λ e → ↓-app=idf-in $
idp ∙' quot e
=⟨ ∙'-unit-l _ ⟩
quot e
=⟨ ! (Coeq-rec-β= _ _ _) ⟩
ap f (quot (inr e))
=⟨ ap (ap f) (! (Coeq-rec-β= _ _ _)) ⟩
ap f (ap g (quot e))
=⟨ ! (ap-∘ f g (quot e)) ⟩
ap (f ∘ g) (quot e)
=⟨ ! (∙-unit-r _) ⟩
ap (f ∘ g) (quot e) ∙ idp
=∎
where
lemma1 : (e : E₁) → idp ∙' ap (λ z → c[ z ]) (quot e) ==
ap (λ z → f (g c[ z ])) (quot e) ∙ idp
lemma1 e =
idp ∙' ap c[_] (quot e)
=⟨ ∙'-unit-l _ ⟩
ap c[_] (quot e)
=⟨ ! (Coeq-rec-β= _ _ _) ⟩
ap f (quot (inl e))
=⟨ ap (ap f) (! (Coeq-rec-β= _ _ _)) ⟩
ap f (ap (Coeq-rec c[_] (λ e → quot (inl e))) (quot e))
=⟨ idp ⟩
ap f (ap (g ∘ c[_]) (quot e))
=⟨ ! (ap-∘ f (g ∘ c[_]) (quot e)) ⟩
ap (f ∘ g ∘ c[_]) (quot e)
=⟨ ! (∙-unit-r _) ⟩
ap (f ∘ g ∘ c[_]) (quot e) ∙ idp
=∎
g-f : (x : V / (E₁ ⊔ E₂)) → (g (f x) == x)
g-f = Coeq-elim (λ x → g (f x) == x) (λ v → idp) (λ { (inl e) → ↓-app=idf-in (! (lemma1 e)) ; (inr e) → ↓-app=idf-in (! (lemma2 e))})
where
lemma1 : (e : E₁) → ap (λ z → g (f z)) (quot (inl e)) ∙ idp == idp ∙' quot (inl e)
lemma1 e =
ap (g ∘ f) (quot (inl e)) ∙ idp
=⟨ ∙-unit-r _ ⟩
ap (g ∘ f) (quot (inl e))
=⟨ ap-∘ g f (quot (inl e)) ⟩
ap g (ap f (quot (inl e)))
=⟨ ap (ap g) (Coeq-rec-β= _ _ _) ⟩
ap g (ap c[_] (quot e))
=⟨ ! (ap-∘ g c[_] (quot e)) ⟩
ap (g ∘ c[_]) (quot e)
=⟨ idp ⟩
ap (Coeq-rec c[_] (λ e' → quot (inl e'))) (quot e)
=⟨ Coeq-rec-β= _ _ _ ⟩
quot (inl e)
=⟨ ! (∙'-unit-l _) ⟩
idp ∙' quot (inl e)
=∎
lemma2 : (e : E₂) → ap (λ z → g (f z)) (quot (inr e)) ∙ idp == idp ∙' quot (inr e)
lemma2 e =
ap (g ∘ f) (quot (inr e)) ∙ idp
=⟨ ∙-unit-r _ ⟩
ap (g ∘ f) (quot (inr e))
=⟨ ap-∘ g f (quot (inr e)) ⟩
ap g (ap f (quot (inr e)))
=⟨ ap (ap g) (Coeq-rec-β= _ _ _) ⟩
ap g (quot e)
=⟨ Coeq-rec-β= _ _ _ ⟩
quot (inr e)
=⟨ ! (∙'-unit-l _) ⟩
idp ∙' quot (inr e)
=∎
|
{
"alphanum_fraction": 0.373623348,
"avg_line_length": 35.6078431373,
"ext": "agda",
"hexsha": "b04b469364ca2672d447b01f638185f8d22d5125",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "awswan/nielsenschreier-hott",
"max_forks_repo_path": "main/Coequalizers/EdgeCoproduct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "awswan/nielsenschreier-hott",
"max_issues_repo_path": "main/Coequalizers/EdgeCoproduct.agda",
"max_line_length": 153,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "awswan/nielsenschreier-hott",
"max_stars_repo_path": "main/Coequalizers/EdgeCoproduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1541,
"size": 3632
}
|
module RMonads where
open import Library
open import Categories
open import Functors
record RMonad {a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}(J : Fun C D) :
Set (a ⊔ b ⊔ c ⊔ d) where
constructor rmonad
open Cat
open Fun
field T : Obj C → Obj D
η : ∀{X} → Hom D (OMap J X) (T X)
bind : ∀{X Y} → Hom D (OMap J X) (T Y) → Hom D (T X) (T Y)
law1 : ∀{X} → bind (η {X}) ≅ iden D {T X}
law2 : ∀{X Y}{f : Hom D (OMap J X) (T Y)} → comp D (bind f) η ≅ f
law3 : ∀{X Y Z}
{f : Hom D (OMap J X) (T Y)}{g : Hom D (OMap J Y) (T Z)} →
bind (comp D (bind g) f) ≅ comp D (bind g) (bind f)
open import Functors
TFun : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D} →
RMonad J → Fun C D
TFun {C = C}{D}{J} M = let open RMonad M; open Cat; open Fun in record {
OMap = T;
HMap = bind ∘ comp D η ∘ HMap J;
fid =
proof
bind (comp D η (HMap J (iden C)))
≅⟨ cong (bind ∘ comp D η) (fid J) ⟩
bind (comp D η (iden D))
≅⟨ cong bind (idr D) ⟩
bind η
≅⟨ law1 ⟩
iden D
∎;
fcomp = λ{_ _ _ f g} →
proof
bind (comp D η (HMap J (comp C f g)))
≅⟨ cong (bind ∘ comp D η) (fcomp J) ⟩
bind (comp D η (comp D (HMap J f) (HMap J g)))
≅⟨ cong bind (sym (ass D)) ⟩
bind (comp D (comp D η (HMap J f)) (HMap J g))
≅⟨ cong (λ f → bind (comp D f (HMap J g))) (sym law2) ⟩
bind (comp D (comp D (bind (comp D η (HMap J f))) η) (HMap J g))
≅⟨ cong bind (ass D) ⟩
bind (comp D (bind (comp D η (HMap J f))) (comp D η (HMap J g)))
≅⟨ law3 ⟩
comp D (bind (comp D η (HMap J f))) (bind (comp D η (HMap J g)))
∎}
-- any functor is a rel monad over itself
trivRM : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}(J : Fun C D) → RMonad J
trivRM {D = D} J = rmonad OMap (iden D) id refl (idr D) refl
where open Fun J; open Cat
|
{
"alphanum_fraction": 0.4957582185,
"avg_line_length": 32.5172413793,
"ext": "agda",
"hexsha": "a3bc2b55da5cf9bedb1eff932ec896a2525fbb01",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "RMonads.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "RMonads.agda",
"max_line_length": 75,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "RMonads.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": 826,
"size": 1886
}
|
{-# OPTIONS --safe --without-K #-}
module Data.Fin.Subset.Properties.Dec where
open import Data.Nat as ℕ
open import Data.Fin as Fin
open import Data.Empty using (⊥-elim)
open import Data.Fin.Subset
open import Data.Fin.Subset.Dec
open import Data.Fin.Subset.Properties using (⊆⊤; p⊆p∪q; q⊆p∪q ; p∩q⊆p ; p∩q⊆q ; ⊆-poset)
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Unary renaming (Decidable to Decidable₁) using ()
open import Data.Vec
open import Function using (_∘_)
open import Function.Equivalence using (_⇔_ ; equivalence)
open import Relation.Nullary.Negation using (¬?)
subset¬⊆∁subset : ∀ {n}{p} {P : Fin n → Set p}(P? : Decidable₁ P) → subset (¬? ∘ P?) ⊆ ∁ (subset P?)
subset¬⊆∁subset {zero} P? ()
subset¬⊆∁subset {suc n} P? x∈s with P? (# 0)
subset¬⊆∁subset {suc n} P? here | no ¬p0 = here
subset¬⊆∁subset {suc n} P? (there x∈s) | no ¬p0 = there (subset¬⊆∁subset (P? ∘ suc) x∈s)
subset¬⊆∁subset {suc n} P? (there x∈s) | yes p0 = there (subset¬⊆∁subset (P? ∘ suc) x∈s)
∁subset⊆subset¬ : ∀ {n}{p}{P : Fin n → Set p}(P? : Decidable₁ P) → ∁ (subset P?) ⊆ subset (¬? ∘ P?)
∁subset⊆subset¬ {zero} P? ()
∁subset⊆subset¬ {suc n} P? x∈s with P? (# 0)
∁subset⊆subset¬ {suc n} P? here | no ¬p0 = here
∁subset⊆subset¬ {suc n} P? (there x∈s) | yes p0 = there (∁subset⊆subset¬ (P? ∘ suc) x∈s)
∁subset⊆subset¬ {suc n} P? (there x∈s) | no ¬p0 = there (∁subset⊆subset¬ (P? ∘ suc) x∈s)
subset¬≡∁subset : ∀ {n}{p}{P : Fin n → Set p}(P? : Decidable₁ P) → subset (¬? ∘ P?) ≡ ∁ (subset P?)
subset¬≡∁subset {n} P? = ⊆-antisym (subset¬⊆∁subset P?) (∁subset⊆subset¬ P?)
where
open Poset (⊆-poset n) renaming (antisym to ⊆-antisym) using ()
∈subset⁺ : ∀ {n}{p}{P : Fin n → Set p}(P? : Decidable₁ P){x} → P x → x ∈ subset P?
∈subset⁺ {zero} P? {()} Px
∈subset⁺ {suc n} P? {x} Px with P? (# 0)
∈subset⁺ {suc n} P? {zero} Px | yes p0 = here
∈subset⁺ {suc n} P? {suc x} Px | yes p0 = there (∈subset⁺ (P? ∘ suc) Px)
∈subset⁺ {suc n} P? {zero} Px | no ¬p0 = ⊥-elim (¬p0 Px)
∈subset⁺ {suc n} P? {suc x} Px | no ¬p0 = there (∈subset⁺ (P? ∘ suc) Px)
∈subset⁻ : ∀ {n}{p} {P : Fin n → Set p}(P? : Decidable₁ P){x} → x ∈ subset P? → P x
∈subset⁻ {zero} P? {()} x∈s
∈subset⁻ {suc n} P? {x} x∈s with P? (# 0)
∈subset⁻ {suc n} P? {zero} here | yes p0 = p0
∈subset⁻ {suc n} P? {suc x} (there x∈s) | yes p0 = ∈subset⁻ (P? ∘ suc) x∈s
∈subset⁻ {suc n} P? {.(suc _)} (there x∈s) | no ¬p0 = ∈subset⁻ (P? ∘ suc) x∈s
⇔∈subset : ∀ {n}{p}{P : Fin n → Set p}(P? : Decidable₁ P) {x} → x ∈ subset P? ⇔ P x
⇔∈subset P? = equivalence (∈subset⁻ P?) (∈subset⁺ P?)
∈∁subset⁺ : ∀ {n}{p}{P : Fin n → Set p}(P? : Decidable₁ P){x} → ¬ P x → x ∈ ∁ (subset P?)
∈∁subset⁺ P? = subset¬⊆∁subset P? ∘ (∈subset⁺ (¬? ∘ P? ))
∈∁subset⁻ : ∀ {n}{p}{P : Fin n → Set p}(P? : Decidable₁ P){x} → x ∈ ∁ (subset P?) → ¬ P x
∈∁subset⁻ P? = ∈subset⁻ (¬? ∘ P?) ∘ ∁subset⊆subset¬ P?
⇔∈∁subset : ∀ {n}{p}{P : Fin n → Set p}(P? : Decidable₁ P) {x} → x ∈ ∁ (subset P?) ⇔ (¬ P x)
⇔∈∁subset P? = equivalence (∈∁subset⁻ P?) (∈∁subset⁺ P?)
|
{
"alphanum_fraction": 0.5700389105,
"avg_line_length": 48.1875,
"ext": "agda",
"hexsha": "850cebf57c5232164b4d5aec0b3a180d3d97a5ab",
"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": "abacd166f63582b7395d9cc10b6323c0f69649e5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "tizmd/agda-finitary",
"max_forks_repo_path": "src/Data/Fin/Subset/Properties/Dec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "abacd166f63582b7395d9cc10b6323c0f69649e5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "tizmd/agda-finitary",
"max_issues_repo_path": "src/Data/Fin/Subset/Properties/Dec.agda",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "abacd166f63582b7395d9cc10b6323c0f69649e5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "tizmd/agda-finitary",
"max_stars_repo_path": "src/Data/Fin/Subset/Properties/Dec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1460,
"size": 3084
}
|
{-# OPTIONS --safe --without-K #-}
module Generics.Prelude where
open import Function.Base public
open import Data.Product public hiding (map; uncurry; uncurry′; curry′)
open import Level public using (Setω; Level; _⊔_; Lift; lift)
renaming (zero to lzero; suc to lsuc)
open import Relation.Binary.PropositionalEquality public
hiding ([_]; Extensionality; ∀-extensionality)
open import Data.Nat.Base public using (ℕ; zero; suc; _+_)
renaming (_∸_ to _-_)
open import Data.Unit public using (⊤; tt)
open import Data.Empty public using (⊥)
open import Data.List public using (List; []; _∷_)
open import Data.Vec.Base public using (Vec; []; _∷_; map; lookup)
open import Data.Fin.Base as Fin public using (Fin; zero; suc)
open import Axiom.Extensionality.Propositional public
open import Data.String using (String)
open import Reflection public
hiding (var; return; _>>=_; _>>_; assocˡ; assocʳ; visibility; relevance; module Arg)
import Reflection.Argument
module Arg = Reflection.Argument
open import Reflection.Argument.Information public using (ArgInfo; arg-info; visibility)
renaming (modality to getModality)
open import Reflection.Argument.Modality public using (Modality; modality)
open import Reflection.Argument.Relevance public using (Relevance; relevant; irrelevant)
open import Reflection.Argument.Visibility public using (Visibility; visible; hidden; instance′)
private variable
m n : ℕ
k : Fin n
l l' : Level
A B : Set l
record Irr (A : Set l) : Set l where
constructor irrv
field
.unirr : A
open Irr public
<_>_ : Relevance → Set l → Set l
< relevant > A = A
< irrelevant > A = Irr A
relevance : ArgInfo → Relevance
relevance = Reflection.Argument.Modality.relevance ∘ getModality
-- withAI : ArgInfo → Term → Term
-- withAI i t with relevance i
-- ... | relevant = t
-- ... | irrelevant = con (quote irrv) (vArg t ∷ [])
-- macro
-- Π<> : ((n , i) : String × ArgInfo) → Term → Term → Term → TC ⊤
-- Π<> (n , ai) S′ (Term.var k []) =
-- unify (pi (arg ai S′) (abs n (Term.var (suc k) (vArg (withAI ai (Term.var 0 [])) ∷ []))))
-- Π<> (n , ai) S′ _ hole = typeError (strErr "" ∷ [])
-- TODO: do this with reflection, using names
-- TODO: deal with quantities
Π<_> : ((a , i) : String × ArgInfo) (A : Set l) → (< relevance i > A → Set l') → Set (l ⊔ l')
Π< _ , arg-info visible (modality relevant q) > A B = (x : A) → B x
Π< _ , arg-info visible (modality irrelevant q) > A B = .(x : A) → B (irrv x)
Π< _ , arg-info hidden (modality relevant q) > A B = {x : A} → B x
Π< _ , arg-info hidden (modality irrelevant q) > A B = .{x : A} → B (irrv x)
Π< _ , arg-info instance′ (modality relevant q) > A B = {{x : A}} → B x
Π< _ , arg-info instance′ (modality irrelevant q) > A B = .{{x : A}} → B (irrv x)
_→<_>_ : Set l → String × ArgInfo → Set l' → Set (l ⊔ l')
A →< i > B = Π< i > A λ _ → B
fun<_> : (ai@(a , i) : String × ArgInfo) {A : Set l} {B : < relevance i > A → Set l'}
→ (f : (x : < relevance i > A) → B x) → Π< ai > A B
fun< _ , arg-info visible (modality relevant q) > f x = f x
fun< _ , arg-info visible (modality irrelevant q) > f x = f (irrv x)
fun< _ , arg-info hidden (modality relevant q) > f {x} = f x
fun< _ , arg-info hidden (modality irrelevant q) > f {x} = f (irrv x)
fun< _ , arg-info instance′ (modality relevant q) > f {{x}} = f x
fun< _ , arg-info instance′ (modality irrelevant q) > f {{x}} = f (irrv x)
app<_> : (ai@(a , i) : String × ArgInfo) {A : Set l} {B : < relevance i > A → Set l'}
→ (f : Π< ai > A B) → (x : < relevance i > A) → B x
app< _ , arg-info visible (modality relevant q) > f x = f x
app< _ , arg-info visible (modality irrelevant q) > f (irrv x) = f x
app< _ , arg-info hidden (modality relevant q) > f x = f {x}
app< _ , arg-info hidden (modality irrelevant q) > f (irrv x) = f {x}
app< _ , arg-info instance′ (modality relevant q) > f x = f {{x}}
app< _ , arg-info instance′ (modality irrelevant q) > f (irrv x) = f {{x}}
-- Instead of the definitions from Function.Nary.NonDependent in the
-- standard library, we use a *functional* representation of vectors
-- of levels and types. This makes it much easier to work with
-- operations like lookup and tabulate, at the cost of losing certain
-- eta laws for nil and cons (see the comment for `uncurryₙ` below).
Levels : ℕ → Set
Levels n = Fin n → Level
private variable ls ls' : Levels n
[]l : Levels 0
[]l ()
_∷l_ : Level → Levels n → Levels (suc n)
(l ∷l ls) zero = l
(l ∷l ls) (suc k) = ls k
headl : Levels (suc n) → Level
headl ls = ls zero
taill : Levels (suc n) → Levels n
taill ls = ls ∘ suc
_++l_ : Levels m → Levels n → Levels (m + n)
_++l_ {zero} ls ls' = ls'
_++l_ {suc m} ls ls' zero = headl ls
_++l_ {suc m} ls ls' (suc x) = (taill ls ++l ls') x
⨆ : Levels n → Level
⨆ {zero} ls = lzero
⨆ {suc n} ls = ls zero ⊔ ⨆ (ls ∘ suc)
Sets : (ls : Levels n) → Setω
Sets {n} ls = (k : Fin n) → Set (ls k)
private variable As Bs : Sets ls
[]S : {ls : Levels 0} → Sets ls
[]S ()
_∷S_ : Set (headl ls) → Sets (taill ls) → Sets ls
(A ∷S As) zero = A
(A ∷S As) (suc k) = As k
headS : Sets ls → Set (headl ls)
headS As = As zero
tailS : Sets ls → Sets (taill ls)
tailS As k = As (suc k)
_++S_ : Sets ls → Sets ls' → Sets (ls ++l ls')
_++S_ {zero} As Bs = Bs
_++S_ {suc m} As Bs zero = headS As
_++S_ {suc m} As Bs (suc k) = (tailS As ++S Bs) k
Els : (As : Sets ls) → Setω
Els {n} As = (k : Fin n) → As k
private variable xs : Els As
[]El : {As : Sets {zero} ls} → Els As
[]El ()
_∷El_ : headS As → Els (tailS As) → Els As
(x ∷El xs) zero = x
(x ∷El xs) (suc k) = xs k
headEl : Els As → headS As
headEl xs = xs zero
tailEl : Els As → Els (tailS As)
tailEl xs k = xs (suc k)
_++El_ : Els As → Els Bs → Els (As ++S Bs)
_++El_ {zero} xs ys = ys
_++El_ {suc m} xs ys zero = headEl xs
_++El_ {suc m} xs ys (suc k) = (tailEl xs ++El ys) k
++El-proj₁ : Els (As ++S Bs) → Els As
++El-proj₁ xs zero = xs zero
++El-proj₁ xs (suc k) = ++El-proj₁ (tailEl xs) k
++El-proj₂ : Els (As ++S Bs) → Els Bs
++El-proj₂ {zero} xs k = xs k
++El-proj₂ {suc m} xs k = ++El-proj₂ (tailEl xs) k
Pis : (As : Sets ls) (B : Els As → Set l) → Set (⨆ ls ⊔ l)
Pis {zero} As B = B []El
Pis {suc n} As B = (x : As zero) → Pis (tailS As) (λ xs → B (x ∷El xs))
Arrows : (As : Sets ls) (B : Set l) → Set (⨆ ls ⊔ l)
Arrows As B = Pis As (λ _ → B)
curryₙ : {B : Els As → Set l} → ((xs : Els As) → B xs) → Pis As B
curryₙ {zero} f = f []El
curryₙ {suc n} f = λ x → curryₙ (λ xs → f (x ∷El xs))
-- It is not possible to define the dependent version of uncurryₙ, as
-- it requires the laws that `xs = []El` for all `xs : Els {zero} As`
-- and `xs = headEl xs ∷El tailEl xs` for all `xs : Els {suc n} As`,
-- which do not hold definitionally and require funExt to prove.
uncurryₙ : Arrows As B → Els As → B
uncurryₙ {zero} f _ = f
uncurryₙ {suc n} f xs = uncurryₙ (f (headEl xs)) (tailEl xs)
------------------------------------
-- Some utilities to work with Setω
-- TODO: move this somewhere else
-- TODO: consistent naming
record ⊤ω : Setω where
instance constructor tt
data ⊥ω : Setω where
⊥⇒⊥ω : ⊥ → ⊥ω
⊥⇒⊥ω ()
⊥ω-elimω : {A : Setω} → ⊥ω → A
⊥ω-elimω ()
ttω : ⊤ω
ttω = tt
record Liftω (A : Set l) : Setω where
constructor liftω
field lower : A
instance
liftω-inst : {A : Set l} → ⦃ A ⦄ → Liftω A
liftω-inst ⦃ x ⦄ = liftω x
record _×ω_ (A B : Setω) : Setω where
constructor _,_
field fst : A
snd : B
_ω,ω_ : {A B : Setω} → A → B → A ×ω B
_ω,ω_ = _,_
data _≡ω_ {A : Setω} (x : A) : A → Setω where
refl : x ≡ω x
congω : ∀ {A b} {B : Set b} (f : ∀ x → B)
→ ∀ {x y : A} → x ≡ω y → f x ≡ f y
congω f refl = refl
cong≡ω : {A : Set l} {B : Setω} (f : ∀ x → B)
→ ∀ {x y : A} → x ≡ y → f x ≡ω f y
cong≡ω f refl = refl
cong≡ωω : {A B : Setω} (f : ∀ x → B)
→ ∀ {x y : A} → x ≡ω y → f x ≡ω f y
cong≡ωω f refl = refl
reflω : {A : Setω} {x : A} → x ≡ω x
reflω = refl
transω : {A : Setω} {x y z : A}
→ x ≡ω y → y ≡ω z → x ≡ω z
transω refl refl = refl
symω : {A : Setω} {x y : A} → x ≡ω y → y ≡ω x
symω refl = refl
instance
×ω-inst : ∀ {A B} → ⦃ A ⦄ → ⦃ B ⦄ → A ×ω B
×ω-inst ⦃ x ⦄ ⦃ y ⦄ = x , y
record Σω {a} (A : Set a) (B : A → Setω) : Setω where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
data Decω (A : Setω) : Setω where
yesω : A → Decω A
noω : (A → ⊥) → Decω A
|
{
"alphanum_fraction": 0.5700057904,
"avg_line_length": 31.5145985401,
"ext": "agda",
"hexsha": "10160963e79f37b8040ecbdda7f4a159ef43ce3c",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z",
"max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/generics",
"max_forks_repo_path": "src/Generics/Prelude.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "flupe/generics",
"max_issues_repo_path": "src/Generics/Prelude.agda",
"max_line_length": 97,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/generics",
"max_stars_repo_path": "src/Generics/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z",
"num_tokens": 3248,
"size": 8635
}
|
open import Prelude
open import Nat
open import dynamics-core
module binders-disjoint-checks where
-- these are fairly mechanical lemmas that show that the
-- judgementally-defined binders-disjoint is really a type-directed
-- function
-- numbers
lem-bdσ-num : ∀{σ n} → binders-disjoint-σ σ (N n)
lem-bdσ-num {σ = Id Γ} = BDσId
lem-bdσ-num {σ = Subst d y σ} = BDσSubst BDNum lem-bdσ-num UBNum
lem-bd-num : ∀{d n} → binders-disjoint d (N n)
lem-bd-num {d = N x} = BDNum
lem-bd-num {d = d ·+ d₁} = BDPlus lem-bd-num lem-bd-num
lem-bd-num {d = X x} = BDVar
lem-bd-num {d = ·λ x ·[ x₁ ] d} = BDLam lem-bd-num UBNum
lem-bd-num {d = d ∘ d₁} = BDAp lem-bd-num lem-bd-num
lem-bd-num {d = inl x d} = BDInl lem-bd-num
lem-bd-num {d = inr x d} = BDInr lem-bd-num
lem-bd-num {d = case d x d₁ x₁ d₂} = BDCase lem-bd-num UBNum lem-bd-num UBNum lem-bd-num
lem-bd-num {d = ⟨ d , d₁ ⟩} = BDPair lem-bd-num lem-bd-num
lem-bd-num {d = fst d} = BDFst lem-bd-num
lem-bd-num {d = snd d} = BDSnd lem-bd-num
lem-bd-num {d = ⦇-⦈⟨ u , σ ⟩} = BDHole lem-bdσ-num
lem-bd-num {d = ⦇⌜ d ⌟⦈⟨ u , σ ⟩} = BDNEHole lem-bdσ-num lem-bd-num
lem-bd-num {d = d ⟨ x ⇒ x₁ ⟩} = BDCast lem-bd-num
lem-bd-num {d = d ⟨ x ⇒⦇-⦈⇏ x₁ ⟩} = BDFailedCast lem-bd-num
-- plus
lem-bdσ-into-plus : ∀{σ d1 d2} →
binders-disjoint-σ σ d1 →
binders-disjoint-σ σ d2 →
binders-disjoint-σ σ (d1 ·+ d2)
lem-bdσ-into-plus BDσId BDσId = BDσId
lem-bdσ-into-plus (BDσSubst x bd1 x₁) (BDσSubst x₂ bd2 x₃) =
BDσSubst (BDPlus x x₂) (lem-bdσ-into-plus bd1 bd2) (UBPlus x₁ x₃)
lem-bdσ-plus : ∀{σ d1 d2} →
binders-disjoint-σ σ (d1 ·+ d2) →
binders-disjoint-σ σ d1 × binders-disjoint-σ σ d2
lem-bdσ-plus BDσId = BDσId , BDσId
lem-bdσ-plus (BDσSubst (BDPlus x x₁) bd (UBPlus ub ub₁))
with lem-bdσ-plus bd
... | dis1 , dis2 = BDσSubst x dis1 ub , BDσSubst x₁ dis2 ub₁
lem-bd-plus : ∀{d d1 d2} →
binders-disjoint d (d1 ·+ d2) →
binders-disjoint d d1 × binders-disjoint d d2
lem-bd-plus BDNum = BDNum , BDNum
lem-bd-plus (BDPlus bd bd')
with lem-bd-plus bd | lem-bd-plus bd'
... | bd₁ , bd₂ | bd₁' , bd₂' = BDPlus bd₁ bd₁' , BDPlus bd₂ bd₂'
lem-bd-plus BDVar = BDVar , BDVar
lem-bd-plus (BDLam bd (UBPlus x x₁))
with lem-bd-plus bd
... | bd₁ , bd₂ = BDLam bd₁ x , BDLam bd₂ x₁
lem-bd-plus (BDAp bd bd')
with lem-bd-plus bd | lem-bd-plus bd'
... | bd₁ , bd₂ | bd₁' , bd₂' = BDAp bd₁ bd₁' , BDAp bd₂ bd₂'
lem-bd-plus (BDInl bd)
with lem-bd-plus bd
... | bd₁ , bd₂ = BDInl bd₁ , BDInl bd₂
lem-bd-plus (BDInr bd)
with lem-bd-plus bd
... | bd' , bdσ' = BDInr bd' , BDInr bdσ'
lem-bd-plus (BDCase bd (UBPlus x x₂) bd₁ (UBPlus x₁ x₃) bd₂)
with lem-bd-plus bd | lem-bd-plus bd₁ | lem-bd-plus bd₂
... | bd' , bd'' | bd₁' , bd₁'' | bd₂' , bd₂'' = BDCase bd' x bd₁' x₁ bd₂' , BDCase bd'' x₂ bd₁'' x₃ bd₂''
lem-bd-plus (BDPair bd bd₁)
with lem-bd-plus bd | lem-bd-plus bd₁
... | bd' , bd'' | bd₁' , bd₁'' = BDPair bd' bd₁' , BDPair bd'' bd₁''
lem-bd-plus (BDFst bd)
with lem-bd-plus bd
... | bd' , bdσ' = BDFst bd' , BDFst bdσ'
lem-bd-plus (BDSnd bd)
with lem-bd-plus bd
... | bd' , bdσ' = BDSnd bd' , BDSnd bdσ'
lem-bd-plus (BDHole x)
with lem-bdσ-plus x
... | bdσ₁ , bdσ₂ = BDHole bdσ₁ , BDHole bdσ₂
lem-bd-plus (BDNEHole x bd)
with lem-bdσ-plus x | lem-bd-plus bd
... | bdσ₁ , bdσ₂ | bd₁ , bd₂ = BDNEHole bdσ₁ bd₁ , BDNEHole bdσ₂ bd₂
lem-bd-plus (BDCast bd)
with lem-bd-plus bd
... | bd₁ , bd₂ = BDCast bd₁ , BDCast bd₂
lem-bd-plus (BDFailedCast bd)
with lem-bd-plus bd
... | bd₁ , bd₂ = BDFailedCast bd₁ , BDFailedCast bd₂
-- var
lem-bdσ-var : ∀{σ x} → binders-disjoint-σ σ (X x)
lem-bdσ-var {σ = Id Γ} = BDσId
lem-bdσ-var {σ = Subst d y σ} = BDσSubst BDVar lem-bdσ-var UBVar
lem-bd-var : ∀{d x} → binders-disjoint d (X x)
lem-bd-var {d = N x} = BDNum
lem-bd-var {d = d ·+ d₁} = BDPlus lem-bd-var lem-bd-var
lem-bd-var {d = X x} = BDVar
lem-bd-var {d = ·λ x ·[ x₁ ] d} = BDLam lem-bd-var UBVar
lem-bd-var {d = d ∘ d₁} = BDAp lem-bd-var lem-bd-var
lem-bd-var {d = inl x d} = BDInl lem-bd-var
lem-bd-var {d = inr x d} = BDInr lem-bd-var
lem-bd-var {d = case d x d₁ x₁ d₂} = BDCase lem-bd-var UBVar lem-bd-var UBVar lem-bd-var
lem-bd-var {d = ⟨ d , d₁ ⟩} = BDPair lem-bd-var lem-bd-var
lem-bd-var {d = fst d} = BDFst lem-bd-var
lem-bd-var {d = snd d} = BDSnd lem-bd-var
lem-bd-var {d = ⦇-⦈⟨ u , σ ⟩} = BDHole lem-bdσ-var
lem-bd-var {d = ⦇⌜ d ⌟⦈⟨ u , σ ⟩} = BDNEHole lem-bdσ-var lem-bd-var
lem-bd-var {d = d ⟨ x ⇒ x₁ ⟩} = BDCast lem-bd-var
lem-bd-var {d = d ⟨ x ⇒⦇-⦈⇏ x₁ ⟩} = BDFailedCast lem-bd-var
-- lambda
lem-bdσ-into-lam : ∀{x τ d σ} →
binders-disjoint-σ σ d →
unbound-in-σ x σ →
binders-disjoint-σ σ (·λ x ·[ τ ] d)
lem-bdσ-into-lam BDσId UBσId = BDσId
lem-bdσ-into-lam (BDσSubst x bd x₁) (UBσSubst x₂ ub x₃) =
BDσSubst (BDLam x x₂) (lem-bdσ-into-lam bd ub) (UBLam2 (flip x₃) x₁)
lem-bdσ-lam : ∀{σ x τ d} →
binders-disjoint-σ σ (·λ x ·[ τ ] d) →
binders-disjoint-σ σ d × unbound-in-σ x σ
lem-bdσ-lam BDσId = BDσId , UBσId
lem-bdσ-lam (BDσSubst (BDLam x₁ x) bd (UBLam2 x₂ ub))
with lem-bdσ-lam bd
... | bdσ , ub' = (BDσSubst x₁ bdσ ub) , (UBσSubst x ub' (flip x₂))
lem-bd-lam : ∀{d1 x τ1 d} →
binders-disjoint d1 (·λ x ·[ τ1 ] d) →
binders-disjoint d1 d × unbound-in x d1
lem-bd-lam BDNum = BDNum , UBNum
lem-bd-lam (BDPlus bd bd₁)
with lem-bd-lam bd | lem-bd-lam bd₁
... | bd' , ub | bd₁' , ub₁ = BDPlus bd' bd₁' , UBPlus ub ub₁
lem-bd-lam BDVar = BDVar , UBVar
lem-bd-lam (BDLam bd (UBLam2 x x₁))
with lem-bd-lam bd
... | bd' , ub = BDLam bd' x₁ , UBLam2 (flip x) ub
lem-bd-lam (BDAp bd bd₁)
with lem-bd-lam bd | lem-bd-lam bd₁
... | bd' , ub | bd₁' , ub₁ = BDAp bd' bd₁' , UBAp ub ub₁
lem-bd-lam (BDInl bd)
with lem-bd-lam bd
... | bd' , ub = BDInl bd' , UBInl ub
lem-bd-lam (BDInr bd)
with lem-bd-lam bd
... | bd' , ub = BDInr bd' , UBInr ub
lem-bd-lam (BDCase bd (UBLam2 x x₁) bd₁ (UBLam2 x₂ x₃) bd₂)
with lem-bd-lam bd | lem-bd-lam bd₁ | lem-bd-lam bd₂
... | bd' , ub | bd₁' , ub1 | bd₂' , ub2 = (BDCase bd' x₁ bd₁' x₃ bd₂') , (UBCase ub (flip x) ub1 (flip x₂) ub2)
lem-bd-lam (BDPair bd bd₁)
with lem-bd-lam bd | lem-bd-lam bd₁
... | bd' , ub | bd₁' , ub1 = BDPair bd' bd₁' , UBPair ub ub1
lem-bd-lam (BDFst bd)
with lem-bd-lam bd
... | bd' , ub = BDFst bd' , UBFst ub
lem-bd-lam (BDSnd bd)
with lem-bd-lam bd
... | bd' , ub = BDSnd bd' , UBSnd ub
lem-bd-lam (BDHole x)
with lem-bdσ-lam x
... | bdσ , ubσ = BDHole bdσ , UBHole ubσ
lem-bd-lam (BDNEHole x bd)
with lem-bd-lam bd | lem-bdσ-lam x
... | bd' , ub | bdσ , ubσ = BDNEHole bdσ bd' , UBNEHole ubσ ub
lem-bd-lam (BDCast bd)
with lem-bd-lam bd
... | bd' , ub = BDCast bd' , UBCast ub
lem-bd-lam (BDFailedCast bd)
with lem-bd-lam bd
... | bd' , ub = BDFailedCast bd' , UBFailedCast ub
-- application
lem-bdσ-into-ap : ∀{σ d1 d2} →
binders-disjoint-σ σ d1 →
binders-disjoint-σ σ d2 →
binders-disjoint-σ σ (d1 ∘ d2)
lem-bdσ-into-ap BDσId BDσId = BDσId
lem-bdσ-into-ap (BDσSubst x bd1 x₁) (BDσSubst x₂ bd2 x₃) =
BDσSubst (BDAp x x₂) (lem-bdσ-into-ap bd1 bd2) (UBAp x₁ x₃)
lem-bdσ-ap : ∀{σ d1 d2} →
binders-disjoint-σ σ (d1 ∘ d2) →
binders-disjoint-σ σ d1 × binders-disjoint-σ σ d2
lem-bdσ-ap BDσId = BDσId , BDσId
lem-bdσ-ap (BDσSubst (BDAp x x₁) bd (UBAp ub ub₁))
with lem-bdσ-ap bd
... | dis1 , dis2 = BDσSubst x dis1 ub , BDσSubst x₁ dis2 ub₁
lem-bd-ap : ∀{d d1 d2} →
binders-disjoint d (d1 ∘ d2) →
binders-disjoint d d1 × binders-disjoint d d2
lem-bd-ap BDNum = BDNum , BDNum
lem-bd-ap (BDPlus bd bd')
with lem-bd-ap bd | lem-bd-ap bd'
... | bd₁ , bd₂ | bd₁' , bd₂' = BDPlus bd₁ bd₁' , BDPlus bd₂ bd₂'
lem-bd-ap BDVar = BDVar , BDVar
lem-bd-ap (BDLam bd (UBAp x x₁))
with lem-bd-ap bd
... | bd₁ , bd₂ = BDLam bd₁ x , BDLam bd₂ x₁
lem-bd-ap (BDAp bd bd')
with lem-bd-ap bd | lem-bd-ap bd'
... | bd₁ , bd₂ | bd₁' , bd₂' = BDAp bd₁ bd₁' , BDAp bd₂ bd₂'
lem-bd-ap (BDInl bd)
with lem-bd-ap bd
... | bd₁ , bd₂ = BDInl bd₁ , BDInl bd₂
lem-bd-ap (BDInr bd)
with lem-bd-ap bd
... | bd' , bdσ' = BDInr bd' , BDInr bdσ'
lem-bd-ap (BDCase bd (UBAp x x₂) bd₁ (UBAp x₁ x₃) bd₂)
with lem-bd-ap bd | lem-bd-ap bd₁ | lem-bd-ap bd₂
... | bd' , bd'' | bd₁' , bd₁'' | bd₂' , bd₂'' = BDCase bd' x bd₁' x₁ bd₂' , BDCase bd'' x₂ bd₁'' x₃ bd₂''
lem-bd-ap (BDPair bd bd₁)
with lem-bd-ap bd | lem-bd-ap bd₁
... | bd' , bd'' | bd₁' , bd₁'' = BDPair bd' bd₁' , BDPair bd'' bd₁''
lem-bd-ap (BDFst bd)
with lem-bd-ap bd
... | bd' , bdσ' = BDFst bd' , BDFst bdσ'
lem-bd-ap (BDSnd bd)
with lem-bd-ap bd
... | bd' , bdσ' = BDSnd bd' , BDSnd bdσ'
lem-bd-ap (BDHole x)
with lem-bdσ-ap x
... | bdσ₁ , bdσ₂ = BDHole bdσ₁ , BDHole bdσ₂
lem-bd-ap (BDNEHole x bd)
with lem-bdσ-ap x | lem-bd-ap bd
... | bdσ₁ , bdσ₂ | bd₁ , bd₂ = BDNEHole bdσ₁ bd₁ , BDNEHole bdσ₂ bd₂
lem-bd-ap (BDCast bd)
with lem-bd-ap bd
... | bd₁ , bd₂ = BDCast bd₁ , BDCast bd₂
lem-bd-ap (BDFailedCast bd)
with lem-bd-ap bd
... | bd₁ , bd₂ = BDFailedCast bd₁ , BDFailedCast bd₂
-- inl
lem-bdσ-into-inl : ∀{σ d τ} →
binders-disjoint-σ σ d →
binders-disjoint-σ σ (inl τ d)
lem-bdσ-into-inl BDσId = BDσId
lem-bdσ-into-inl (BDσSubst x bd x₁) = BDσSubst (BDInl x) (lem-bdσ-into-inl bd) (UBInl x₁)
lem-bdσ-inl : ∀{σ τ d} →
binders-disjoint-σ σ (inl τ d) →
binders-disjoint-σ σ d
lem-bdσ-inl BDσId = BDσId
lem-bdσ-inl (BDσSubst (BDInl x) bd (UBInl ub)) = BDσSubst x (lem-bdσ-inl bd) ub
lem-bd-inl : ∀{d τ d1} →
binders-disjoint d (inl τ d1) →
binders-disjoint d d1
lem-bd-inl BDNum = BDNum
lem-bd-inl (BDPlus bd bd₁) = BDPlus (lem-bd-inl bd) (lem-bd-inl bd₁)
lem-bd-inl BDVar = BDVar
lem-bd-inl (BDLam bd (UBInl x)) = BDLam (lem-bd-inl bd) x
lem-bd-inl (BDAp bd bd₁) = BDAp (lem-bd-inl bd) (lem-bd-inl bd₁)
lem-bd-inl (BDInl bd) = BDInl (lem-bd-inl bd)
lem-bd-inl (BDInr bd) = BDInr (lem-bd-inl bd)
lem-bd-inl (BDCase bd (UBInl x) bd₁ (UBInl x₁) bd₂) = BDCase (lem-bd-inl bd) x (lem-bd-inl bd₁) x₁ (lem-bd-inl bd₂)
lem-bd-inl (BDPair bd bd₁) = BDPair (lem-bd-inl bd) (lem-bd-inl bd₁)
lem-bd-inl (BDFst bd) = BDFst (lem-bd-inl bd)
lem-bd-inl (BDSnd bd) = BDSnd (lem-bd-inl bd)
lem-bd-inl (BDHole x) = BDHole (lem-bdσ-inl x)
lem-bd-inl (BDNEHole x bd) = BDNEHole (lem-bdσ-inl x) (lem-bd-inl bd)
lem-bd-inl (BDCast bd) = BDCast (lem-bd-inl bd)
lem-bd-inl (BDFailedCast bd) = BDFailedCast (lem-bd-inl bd)
-- inr
lem-bdσ-into-inr : ∀{σ d τ} →
binders-disjoint-σ σ d →
binders-disjoint-σ σ (inr τ d)
lem-bdσ-into-inr BDσId = BDσId
lem-bdσ-into-inr (BDσSubst x bd x₁) = BDσSubst (BDInr x) (lem-bdσ-into-inr bd) (UBInr x₁)
lem-bdσ-inr : ∀{σ τ d} →
binders-disjoint-σ σ (inr τ d) →
binders-disjoint-σ σ d
lem-bdσ-inr BDσId = BDσId
lem-bdσ-inr (BDσSubst (BDInr x) bd (UBInr ub)) = BDσSubst x (lem-bdσ-inr bd) ub
lem-bd-inr : ∀{d τ d1} →
binders-disjoint d (inr τ d1) →
binders-disjoint d d1
lem-bd-inr BDNum = BDNum
lem-bd-inr (BDPlus bd bd₁) = BDPlus (lem-bd-inr bd) (lem-bd-inr bd₁)
lem-bd-inr BDVar = BDVar
lem-bd-inr (BDLam bd (UBInr x)) = BDLam (lem-bd-inr bd) x
lem-bd-inr (BDAp bd bd₁) = BDAp (lem-bd-inr bd) (lem-bd-inr bd₁)
lem-bd-inr (BDInl bd) = BDInl (lem-bd-inr bd)
lem-bd-inr (BDInr bd) = BDInr (lem-bd-inr bd)
lem-bd-inr (BDCase bd (UBInr x) bd₁ (UBInr x₁) bd₂) = BDCase (lem-bd-inr bd) x (lem-bd-inr bd₁) x₁ (lem-bd-inr bd₂)
lem-bd-inr (BDPair bd bd₁) = BDPair (lem-bd-inr bd) (lem-bd-inr bd₁)
lem-bd-inr (BDFst bd) = BDFst (lem-bd-inr bd)
lem-bd-inr (BDSnd bd) = BDSnd (lem-bd-inr bd)
lem-bd-inr (BDHole x) = BDHole (lem-bdσ-inr x)
lem-bd-inr (BDNEHole x bd) = BDNEHole (lem-bdσ-inr x) (lem-bd-inr bd)
lem-bd-inr (BDCast bd) = BDCast (lem-bd-inr bd)
lem-bd-inr (BDFailedCast bd) = BDFailedCast (lem-bd-inr bd)
-- case
lem-bdσ-into-case : ∀{σ d x d1 y d2} →
binders-disjoint-σ σ d →
unbound-in-σ x σ →
binders-disjoint-σ σ d1 →
unbound-in-σ y σ →
binders-disjoint-σ σ d2 →
binders-disjoint-σ σ (case d x d1 y d2)
lem-bdσ-into-case BDσId ubx bdσ1 uby bdσ2 = BDσId
lem-bdσ-into-case (BDσSubst x bdσ x₁) (UBσSubst x₂ ubx x₃) (BDσSubst x₆ bdσ1 x₇) (UBσSubst x₄ uby x₅) (BDσSubst x₈ bdσ2 x₉) =
BDσSubst (BDCase x x₂ x₆ x₄ x₈) (lem-bdσ-into-case bdσ ubx bdσ1 uby bdσ2) (UBCase x₁ (flip x₃) x₇ (flip x₅) x₉)
lem-bdσ-case : ∀{σ d x d1 y d2} →
binders-disjoint-σ σ (case d x d1 y d2) →
(binders-disjoint-σ σ d) ×
(unbound-in-σ x σ) ×
(binders-disjoint-σ σ d1) ×
(unbound-in-σ y σ) ×
(binders-disjoint-σ σ d2)
lem-bdσ-case BDσId = BDσId , UBσId , BDσId , UBσId , BDσId
lem-bdσ-case (BDσSubst (BDCase x x₁ x₂ x₃ x₄) bd (UBCase x₅ x₆ x₇ x₈ x₉))
with lem-bdσ-case bd
... | bdd , ubx , bdd1 , uby , bdd2 = BDσSubst x bdd x₅ , UBσSubst x₁ ubx (flip x₆) , BDσSubst x₂ bdd1 x₇ , UBσSubst x₃ uby (flip x₈) , BDσSubst x₄ bdd2 x₉
lem-bd-case : ∀{d x d1 y d2 d3} →
binders-disjoint d3 (case d x d1 y d2) →
(binders-disjoint d3 d) ×
(unbound-in x d3) ×
(binders-disjoint d3 d1) ×
(unbound-in y d3) ×
(binders-disjoint d3 d2)
lem-bd-case BDNum = BDNum , UBNum , BDNum , UBNum , BDNum
lem-bd-case (BDPlus bd bd₁)
with lem-bd-case bd | lem-bd-case bd₁
... | bdd , ubx , bdd1 , uby , bdd2 | bdd' , ubx' , bdd1' , uby' , bdd2' = BDPlus bdd bdd' , UBPlus ubx ubx' , BDPlus bdd1 bdd1' , UBPlus uby uby' , BDPlus bdd2 bdd2'
lem-bd-case BDVar = BDVar , UBVar , BDVar , UBVar , BDVar
lem-bd-case (BDLam bd (UBCase x x₁ x₂ x₃ x₄))
with lem-bd-case bd
... | bdd , ubx , bdd1 , uby , bdd2 = BDLam bdd x , UBLam2 (flip x₁) ubx , BDLam bdd1 x₂ , UBLam2 (flip x₃) uby , BDLam bdd2 x₄
lem-bd-case (BDAp bd bd₁)
with lem-bd-case bd | lem-bd-case bd₁
... | bdd , ubx , bdd1 , uby , bdd2 | bdd' , ubx' , bdd1' , uby' , bdd2' = BDAp bdd bdd' , UBAp ubx ubx' , BDAp bdd1 bdd1' , UBAp uby uby' , BDAp bdd2 bdd2'
lem-bd-case (BDInl bd)
with lem-bd-case bd
... | bdd , ubx , bdd1 , uby , bdd2 = BDInl bdd , UBInl ubx , BDInl bdd1 , UBInl uby , BDInl bdd2
lem-bd-case (BDInr bd)
with lem-bd-case bd
... | bdd , ubx , bdd1 , uby , bdd2 = BDInr bdd , UBInr ubx , BDInr bdd1 , UBInr uby , BDInr bdd2
lem-bd-case (BDCase bd (UBCase x x₁ x₂ x₃ x₄) bd₁ (UBCase x₅ x₆ x₇ x₈ x₉) bd₂)
with lem-bd-case bd | lem-bd-case bd₁ | lem-bd-case bd₂
... | bdd , ubx , bdd1 , uby , bdd2 | bdd' , ubx' , bdd1' , uby' , bdd2' | bdd'' , ubx'' , bdd1'' , uby'' , bdd2'' = BDCase bdd x bdd' x₅ bdd'' , UBCase ubx (flip x₁) ubx' (flip x₆) ubx'' , BDCase bdd1 x₂ bdd1' x₇ bdd1'' , UBCase uby (flip x₃) uby' (flip x₈) uby'' , BDCase bdd2 x₄ bdd2' x₉ bdd2''
lem-bd-case (BDPair bd bd₁)
with lem-bd-case bd | lem-bd-case bd₁
... | bdd , ubx , bdd1 , uby , bdd2 | bdd' , ubx' , bdd1' , uby' , bdd2' = BDPair bdd bdd' , UBPair ubx ubx' , BDPair bdd1 bdd1' , UBPair uby uby' , BDPair bdd2 bdd2'
lem-bd-case (BDFst bd)
with lem-bd-case bd
... | bdd , ubx , bdd1 , uby , bdd2 = BDFst bdd , UBFst ubx , BDFst bdd1 , UBFst uby , BDFst bdd2
lem-bd-case (BDSnd bd)
with lem-bd-case bd
... | bdd , ubx , bdd1 , uby , bdd2 = BDSnd bdd , UBSnd ubx , BDSnd bdd1 , UBSnd uby , BDSnd bdd2
lem-bd-case (BDHole x)
with lem-bdσ-case x
... | bdd , ubx , bdd1 , uby , bdd2 = BDHole bdd , UBHole ubx , BDHole bdd1 , UBHole uby , BDHole bdd2
lem-bd-case (BDNEHole x bd)
with lem-bd-case bd | lem-bdσ-case x
... | bdd , ubx , bdd1 , uby , bdd2 | bddσ , ubxσ , bdd1σ , ubyσ , bdd2σ = BDNEHole bddσ bdd , UBNEHole ubxσ ubx , BDNEHole bdd1σ bdd1 , UBNEHole ubyσ uby , BDNEHole bdd2σ bdd2
lem-bd-case (BDCast bd)
with lem-bd-case bd
... | bdd , ubx , bdd1 , uby , bdd2 = BDCast bdd , UBCast ubx , BDCast bdd1 , UBCast uby , BDCast bdd2
lem-bd-case (BDFailedCast bd)
with lem-bd-case bd
... | bdd , ubx , bdd1 , uby , bdd2 = BDFailedCast bdd , UBFailedCast ubx , BDFailedCast bdd1 , UBFailedCast uby , BDFailedCast bdd2
-- pairs
lem-bdσ-into-pair : ∀{σ d1 d2} →
binders-disjoint-σ σ d1 →
binders-disjoint-σ σ d2 →
binders-disjoint-σ σ ⟨ d1 , d2 ⟩
lem-bdσ-into-pair BDσId BDσId = BDσId
lem-bdσ-into-pair (BDσSubst x bdσ1 x₁) (BDσSubst x₂ bdσ2 x₃) = BDσSubst (BDPair x x₂) (lem-bdσ-into-pair bdσ1 bdσ2) (UBPair x₁ x₃)
lem-bdσ-pair : ∀{σ d1 d2} →
binders-disjoint-σ σ ⟨ d1 , d2 ⟩ →
(binders-disjoint-σ σ d1) × (binders-disjoint-σ σ d2)
lem-bdσ-pair BDσId = BDσId , BDσId
lem-bdσ-pair (BDσSubst (BDPair x x₁) bdσ (UBPair x₂ x₃))
with lem-bdσ-pair bdσ
... | bdσ1 , bdσ2 = BDσSubst x bdσ1 x₂ , BDσSubst x₁ bdσ2 x₃
lem-bd-pair : ∀{d d1 d2} →
binders-disjoint d ⟨ d1 , d2 ⟩ →
(binders-disjoint d d1) × (binders-disjoint d d2)
lem-bd-pair BDNum = BDNum , BDNum
lem-bd-pair (BDPlus bd bd₁)
with lem-bd-pair bd | lem-bd-pair bd₁
... | bd' , bd'' | bd₁' , bd₁'' = BDPlus bd' bd₁' , BDPlus bd'' bd₁''
lem-bd-pair BDVar = BDVar , BDVar
lem-bd-pair (BDLam bd (UBPair x x₁))
with lem-bd-pair bd
... | bd' , bd'' = BDLam bd' x , BDLam bd'' x₁
lem-bd-pair (BDAp bd bd₁)
with lem-bd-pair bd | lem-bd-pair bd₁
... | bd' , bd'' | bd₁' , bd₁'' = BDAp bd' bd₁' , BDAp bd'' bd₁''
lem-bd-pair (BDInl bd)
with lem-bd-pair bd
... | bd' , bd'' = BDInl bd' , BDInl bd''
lem-bd-pair (BDInr bd)
with lem-bd-pair bd
... | bd' , bd'' = BDInr bd' , BDInr bd''
lem-bd-pair (BDCase bd (UBPair x x₁) bd₁ (UBPair x₂ x₃) bd₂)
with lem-bd-pair bd | lem-bd-pair bd₁ | lem-bd-pair bd₂
... | bd' , bd'' | bd₁' , bd₁'' | bd₂' , bd₂'' = BDCase bd' x bd₁' x₂ bd₂' , BDCase bd'' x₁ bd₁'' x₃ bd₂''
lem-bd-pair (BDPair bd bd₁)
with lem-bd-pair bd | lem-bd-pair bd₁
... | bd' , bd'' | bd₁' , bd₁'' = BDPair bd' bd₁' , BDPair bd'' bd₁''
lem-bd-pair (BDFst bd)
with lem-bd-pair bd
... | bd' , bd'' = BDFst bd' , BDFst bd''
lem-bd-pair (BDSnd bd)
with lem-bd-pair bd
... | bd' , bd'' = BDSnd bd' , BDSnd bd''
lem-bd-pair (BDHole x)
with lem-bdσ-pair x
... | bdσ' , bdσ'' = BDHole bdσ' , BDHole bdσ''
lem-bd-pair (BDNEHole x bd)
with lem-bdσ-pair x | lem-bd-pair bd
... | bdσ' , bdσ'' | bd' , bd'' = BDNEHole bdσ' bd' , BDNEHole bdσ'' bd''
lem-bd-pair (BDCast bd)
with lem-bd-pair bd
... | bd' , bd'' = BDCast bd' , BDCast bd''
lem-bd-pair (BDFailedCast bd)
with lem-bd-pair bd
... | bd' , bd'' = BDFailedCast bd' , BDFailedCast bd''
-- fst
lem-bdσ-into-fst : ∀{σ d} →
binders-disjoint-σ σ d →
binders-disjoint-σ σ (fst d)
lem-bdσ-into-fst BDσId = BDσId
lem-bdσ-into-fst (BDσSubst x bdσ x₁) = BDσSubst (BDFst x) (lem-bdσ-into-fst bdσ) (UBFst x₁)
lem-bdσ-fst : ∀{σ d} →
binders-disjoint-σ σ (fst d) →
binders-disjoint-σ σ d
lem-bdσ-fst BDσId = BDσId
lem-bdσ-fst (BDσSubst (BDFst x) bdσ (UBFst x₁)) = BDσSubst x (lem-bdσ-fst bdσ) x₁
lem-bd-fst : ∀{d d1} →
binders-disjoint d (fst d1) →
binders-disjoint d d1
lem-bd-fst BDNum = BDNum
lem-bd-fst (BDPlus bd bd₁) = BDPlus (lem-bd-fst bd) (lem-bd-fst bd₁)
lem-bd-fst BDVar = BDVar
lem-bd-fst (BDLam bd (UBFst x)) = BDLam (lem-bd-fst bd) x
lem-bd-fst (BDAp bd bd₁) = BDAp (lem-bd-fst bd) (lem-bd-fst bd₁)
lem-bd-fst (BDInl bd) = BDInl (lem-bd-fst bd)
lem-bd-fst (BDInr bd) = BDInr (lem-bd-fst bd)
lem-bd-fst (BDCase bd (UBFst x) bd₁ (UBFst x₁) bd₂) = BDCase (lem-bd-fst bd) x (lem-bd-fst bd₁) x₁ (lem-bd-fst bd₂)
lem-bd-fst (BDPair bd bd₁) = BDPair (lem-bd-fst bd) (lem-bd-fst bd₁)
lem-bd-fst (BDFst bd) = BDFst (lem-bd-fst bd)
lem-bd-fst (BDSnd bd) = BDSnd (lem-bd-fst bd)
lem-bd-fst (BDHole x) = BDHole (lem-bdσ-fst x)
lem-bd-fst (BDNEHole x bd) = BDNEHole (lem-bdσ-fst x) (lem-bd-fst bd)
lem-bd-fst (BDCast bd) = BDCast (lem-bd-fst bd)
lem-bd-fst (BDFailedCast bd) = BDFailedCast (lem-bd-fst bd)
-- snd
lem-bdσ-into-snd : ∀{σ d} →
binders-disjoint-σ σ d →
binders-disjoint-σ σ (snd d)
lem-bdσ-into-snd BDσId = BDσId
lem-bdσ-into-snd (BDσSubst x bdσ x₁) = BDσSubst (BDSnd x) (lem-bdσ-into-snd bdσ) (UBSnd x₁)
lem-bdσ-snd : ∀{σ d} →
binders-disjoint-σ σ (snd d) →
binders-disjoint-σ σ d
lem-bdσ-snd BDσId = BDσId
lem-bdσ-snd (BDσSubst (BDSnd x) bdσ (UBSnd x₁)) = BDσSubst x (lem-bdσ-snd bdσ) x₁
lem-bd-snd : ∀{d d1} →
binders-disjoint d (snd d1) →
binders-disjoint d d1
lem-bd-snd BDNum = BDNum
lem-bd-snd (BDPlus bd bd₁) = BDPlus (lem-bd-snd bd) (lem-bd-snd bd₁)
lem-bd-snd BDVar = BDVar
lem-bd-snd (BDLam bd (UBSnd x)) = BDLam (lem-bd-snd bd) x
lem-bd-snd (BDAp bd bd₁) = BDAp (lem-bd-snd bd) (lem-bd-snd bd₁)
lem-bd-snd (BDInl bd) = BDInl (lem-bd-snd bd)
lem-bd-snd (BDInr bd) = BDInr (lem-bd-snd bd)
lem-bd-snd (BDCase bd (UBSnd x) bd₁ (UBSnd x₁) bd₂) = BDCase (lem-bd-snd bd) x (lem-bd-snd bd₁) x₁ (lem-bd-snd bd₂)
lem-bd-snd (BDPair bd bd₁) = BDPair (lem-bd-snd bd) (lem-bd-snd bd₁)
lem-bd-snd (BDFst bd) = BDFst (lem-bd-snd bd)
lem-bd-snd (BDSnd bd) = BDSnd (lem-bd-snd bd)
lem-bd-snd (BDHole x) = BDHole (lem-bdσ-snd x)
lem-bd-snd (BDNEHole x bd) = BDNEHole (lem-bdσ-snd x) (lem-bd-snd bd)
lem-bd-snd (BDCast bd) = BDCast (lem-bd-snd bd)
lem-bd-snd (BDFailedCast bd) = BDFailedCast (lem-bd-snd bd)
-- cast
lem-bdσ-into-cast : ∀{σ d τ1 τ2} →
binders-disjoint-σ σ d →
binders-disjoint-σ σ (d ⟨ τ1 ⇒ τ2 ⟩)
lem-bdσ-into-cast BDσId = BDσId
lem-bdσ-into-cast (BDσSubst x bd x₁) = BDσSubst (BDCast x) (lem-bdσ-into-cast bd) (UBCast x₁)
lem-bdσ-cast : ∀{σ d τ1 τ2} →
binders-disjoint-σ σ (d ⟨ τ1 ⇒ τ2 ⟩) →
binders-disjoint-σ σ d
lem-bdσ-cast BDσId = BDσId
lem-bdσ-cast (BDσSubst (BDCast x) bd (UBCast ub)) = BDσSubst x (lem-bdσ-cast bd) ub
lem-bd-cast : ∀{d1 d τ1 τ2} →
binders-disjoint d1 (d ⟨ τ1 ⇒ τ2 ⟩) →
binders-disjoint d1 d
lem-bd-cast BDNum = BDNum
lem-bd-cast (BDPlus bd bd₁) = BDPlus (lem-bd-cast bd) (lem-bd-cast bd₁)
lem-bd-cast BDVar = BDVar
lem-bd-cast (BDLam bd (UBCast x₁)) = BDLam (lem-bd-cast bd) x₁
lem-bd-cast (BDHole x) = BDHole (lem-bdσ-cast x)
lem-bd-cast (BDNEHole x bd) = BDNEHole (lem-bdσ-cast x) (lem-bd-cast bd)
lem-bd-cast (BDAp bd bd₁) = BDAp (lem-bd-cast bd) (lem-bd-cast bd₁)
lem-bd-cast (BDInl bd) = BDInl (lem-bd-cast bd)
lem-bd-cast (BDInr bd) = BDInr (lem-bd-cast bd)
lem-bd-cast (BDCase bd (UBCast x) bd₁ (UBCast x₁) bd₂) = BDCase (lem-bd-cast bd) x (lem-bd-cast bd₁) x₁ (lem-bd-cast bd₂)
lem-bd-cast (BDPair bd bd₁) = BDPair (lem-bd-cast bd) (lem-bd-cast bd₁)
lem-bd-cast (BDFst bd) = BDFst (lem-bd-cast bd)
lem-bd-cast (BDSnd bd) = BDSnd (lem-bd-cast bd)
lem-bd-cast (BDCast bd) = BDCast (lem-bd-cast bd)
lem-bd-cast (BDFailedCast bd) = BDFailedCast (lem-bd-cast bd)
-- failed cast
lem-bdσ-into-failedcast : ∀{σ d τ1 τ2} →
binders-disjoint-σ σ d →
binders-disjoint-σ σ (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩)
lem-bdσ-into-failedcast BDσId = BDσId
lem-bdσ-into-failedcast (BDσSubst x bd x₁) =
BDσSubst (BDFailedCast x) (lem-bdσ-into-failedcast bd) (UBFailedCast x₁)
lem-bdσ-failedcast : ∀{σ d τ1 τ2} →
binders-disjoint-σ σ (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) →
binders-disjoint-σ σ d
lem-bdσ-failedcast BDσId = BDσId
lem-bdσ-failedcast (BDσSubst (BDFailedCast x) bd (UBFailedCast ub)) = BDσSubst x (lem-bdσ-failedcast bd) ub
lem-bd-failedcast : ∀{d1 d τ1 τ2} → binders-disjoint d1 (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) → binders-disjoint d1 d
lem-bd-failedcast BDNum = BDNum
lem-bd-failedcast (BDPlus bd bd₁) = BDPlus (lem-bd-failedcast bd) (lem-bd-failedcast bd₁)
lem-bd-failedcast BDVar = BDVar
lem-bd-failedcast (BDLam bd (UBFailedCast x₁)) = BDLam (lem-bd-failedcast bd) x₁
lem-bd-failedcast (BDHole x) = BDHole (lem-bdσ-failedcast x)
lem-bd-failedcast (BDNEHole x bd) = BDNEHole (lem-bdσ-failedcast x) (lem-bd-failedcast bd)
lem-bd-failedcast (BDAp bd bd₁) = BDAp (lem-bd-failedcast bd) (lem-bd-failedcast bd₁)
lem-bd-failedcast (BDInl bd) = BDInl (lem-bd-failedcast bd)
lem-bd-failedcast (BDInr bd) = BDInr (lem-bd-failedcast bd)
lem-bd-failedcast (BDCase bd (UBFailedCast x) bd₁ (UBFailedCast x₁) bd₂) =
BDCase (lem-bd-failedcast bd) x (lem-bd-failedcast bd₁) x₁ (lem-bd-failedcast bd₂)
lem-bd-failedcast (BDPair bd bd₁) = BDPair (lem-bd-failedcast bd) (lem-bd-failedcast bd₁)
lem-bd-failedcast (BDFst bd) = BDFst (lem-bd-failedcast bd)
lem-bd-failedcast (BDSnd bd) = BDSnd (lem-bd-failedcast bd)
lem-bd-failedcast (BDCast bd) = BDCast (lem-bd-failedcast bd)
lem-bd-failedcast (BDFailedCast bd) = BDFailedCast (lem-bd-failedcast bd)
-- holes
mutual
-- For terms already holding an env, the equivalent lemms needs a judgement
-- that two envs are disjoint
data binders-disjoint-σs : env → env → Set where
BDσsId : ∀{Γ σ} → binders-disjoint-σs σ (Id Γ)
BDσsSubst : ∀{d1 σ' y σ} →
binders-disjoint-σ σ' d1 →
binders-disjoint-σs σ σ' →
unbound-in-σ y σ' →
binders-disjoint-σs σ' (Subst d1 y σ)
lem-bdσs-sym : ∀{σ σ'} →
binders-disjoint-σs σ σ' →
binders-disjoint-σs σ' σ
lem-bdσs-sym {σ = Id Γ} bd = BDσsId
lem-bdσs-sym {σ = Subst d y σ} BDσsId = BDσsSubst BDσId BDσsId UBσId
lem-bdσs-sym {σ = Subst d y σ} (BDσsSubst (BDσSubst x x₂ x₃) (BDσsSubst x₆ bd x₇) (UBσSubst x₁ x₄ x₅)) = BDσsSubst (BDσSubst (binders-disjoint-sym x) x₆ x₁) (BDσsSubst x₂ (lem-bdσs-sym bd) x₄) (UBσSubst x₃ x₇ (flip x₅))
lem-bdσ-into-hole : ∀{σ σ' u} →
binders-disjoint-σs σ σ' →
binders-disjoint-σ σ (⦇-⦈⟨ u , σ' ⟩)
lem-bdσ-into-hole {σ = Id Γ} bd = BDσId
lem-bdσ-into-hole {σ = Subst d y σ} BDσsId = BDσSubst (BDHole BDσId) (lem-bdσ-into-hole BDσsId) (UBHole UBσId)
lem-bdσ-into-hole {σ = Subst d y σ} (BDσsSubst (BDσSubst x x₁ x₂) (BDσsSubst x₆ bd x₇) (UBσSubst x₃ x₄ x₅)) = BDσSubst (BDHole (BDσSubst (binders-disjoint-sym x) x₆ x₃)) (lem-bdσ-into-hole (BDσsSubst x₁ (lem-bdσs-sym bd) x₄)) (UBHole (UBσSubst x₂ x₇ (flip x₅)))
lem-bdσ-hole : ∀{σ u σ'} →
binders-disjoint-σ σ (⦇-⦈⟨ u , σ' ⟩) →
binders-disjoint-σs σ σ'
lem-bdσ-hole {σ = Id Γ} bd = lem-bdσs-sym BDσsId
lem-bdσ-hole {σ = Subst d y σ} (BDσSubst (BDHole x) bd (UBHole x₁)) = lem-bdσs-sym (BDσsSubst x (lem-bdσ-hole bd) x₁)
lem-bd-hole : ∀{d u σ} →
binders-disjoint d (⦇-⦈⟨ u , σ ⟩) →
binders-disjoint-σ σ d
lem-bd-hole {σ = Id Γ} bd = BDσId
lem-bd-hole {σ = Subst d y σ} BDNum = BDσSubst BDNum lem-bdσ-num UBNum
lem-bd-hole {σ = Subst d y σ} (BDPlus bd bd₁)
with lem-bd-hole bd | lem-bd-hole bd₁
... | BDσSubst x bdσ ub | BDσSubst x₁ bdσ₁ ub₁ = BDσSubst (BDPlus x x₁) (lem-bdσ-into-plus bdσ bdσ₁) (UBPlus ub ub₁)
lem-bd-hole {σ = Subst d y σ} BDVar = BDσSubst BDVar lem-bdσ-var UBVar
lem-bd-hole {σ = Subst d y σ} (BDLam bd (UBHole (UBσSubst x x₁ x₂)))
with lem-bd-hole bd
... | BDσSubst x₃ bdσ x₄ = BDσSubst (BDLam x₃ x) (lem-bdσ-into-lam bdσ x₁) (UBLam2 (flip x₂) x₄)
lem-bd-hole {σ = Subst d y σ} (BDAp bd bd₁)
with lem-bd-hole bd | lem-bd-hole bd₁
... | BDσSubst x bdσ ub | BDσSubst x₁ bdσ₁ ub₁ = BDσSubst (BDAp x x₁) (lem-bdσ-into-ap bdσ bdσ₁) (UBAp ub ub₁)
lem-bd-hole {σ = Subst d y σ} (BDInl bd)
with lem-bd-hole bd
... | BDσSubst x bdσ ub = BDσSubst (BDInl x) (lem-bdσ-into-inl bdσ) (UBInl ub)
lem-bd-hole {σ = Subst d y σ} (BDInr bd)
with lem-bd-hole bd
... | BDσSubst x bdσ ub = BDσSubst (BDInr x) (lem-bdσ-into-inr bdσ) (UBInr ub)
lem-bd-hole {σ = Subst d y σ} (BDCase bd (UBHole (UBσSubst x x₁ x₂)) bd₁ (UBHole (UBσSubst x₃ x₄ x₅)) bd₂)
with lem-bd-hole bd | lem-bd-hole bd₁ | lem-bd-hole bd₂
... | BDσSubst y bdσ ub | BDσSubst y₁ bdσ₁ ub₁ | BDσSubst y₂ bdσ₂ ub₂ = BDσSubst (BDCase y x y₁ x₃ y₂) (lem-bdσ-into-case bdσ x₁ bdσ₁ x₄ bdσ₂) (UBCase ub (flip x₂) ub₁ (flip x₅) ub₂)
lem-bd-hole {σ = Subst d y σ} (BDPair bd bd₁)
with lem-bd-hole bd | lem-bd-hole bd₁
... | BDσSubst x bdσ ub | BDσSubst y₁ bdσ₁ ub₁ = BDσSubst (BDPair x y₁) (lem-bdσ-into-pair bdσ bdσ₁) (UBPair ub ub₁)
lem-bd-hole {σ = Subst d y σ} (BDFst bd)
with lem-bd-hole bd
... | BDσSubst x bdσ ub = BDσSubst (BDFst x) (lem-bdσ-into-fst bdσ) (UBFst ub)
lem-bd-hole {σ = Subst d y σ} (BDSnd bd)
with lem-bd-hole bd
... | BDσSubst x bdσ ub = BDσSubst (BDSnd x) (lem-bdσ-into-snd bdσ) (UBSnd ub)
lem-bd-hole {u = u} {σ = Subst d y σ} (BDHole {u = u₁} {σ = Id Γ} BDσId) =
BDσSubst (BDHole BDσId)
(lem-bdσ-into-hole BDσsId) (UBHole UBσId)
lem-bd-hole {u = u} {σ = Subst d y σ} (BDHole {u = u₁} {σ = Subst d₁ y₁ σ₁} (BDσSubst (BDHole (BDσSubst x x₂ x₃)) bd (UBHole (UBσSubst x₁ x₄ x₅))))
with lem-bdσ-hole bd
... | BDσsSubst x₆ q x₇ = BDσSubst (BDHole (BDσSubst (binders-disjoint-sym x) x₆ x₁)) (lem-bdσ-into-hole (BDσsSubst x₂ (lem-bdσs-sym q) x₄)) (UBHole (UBσSubst x₃ x₇ (flip x₅)))
lem-bd-hole {σ = Subst d y σ} (BDNEHole {σ = Id Γ} BDσId bd)
with lem-bd-hole bd
... | BDσSubst x bdσ x₁ = BDσSubst (BDNEHole BDσId x) (lem-bdσ-into-nehole BDσsId bdσ) (UBNEHole UBσId x₁)
lem-bd-hole {σ = Subst d y σ} (BDNEHole {σ = Subst d₁ y₁ σ'} (BDσSubst (BDHole (BDσSubst x x₃ x₄)) x₁ (UBHole (UBσSubst x₂ x₅ x₆))) bd)
with lem-bd-hole bd | lem-bdσ-hole x₁
... | BDσSubst x₇ bdσ x₈ | BDσsSubst x₉ bdσs x₁₀ = BDσSubst (BDNEHole (BDσSubst (binders-disjoint-sym x) x₉ x₂) x₇) (lem-bdσ-into-nehole (BDσsSubst x₃ (lem-bdσs-sym bdσs) x₅) bdσ) (UBNEHole (UBσSubst x₄ x₁₀ (flip x₆)) x₈)
lem-bd-hole {σ = Subst d y σ} (BDCast bd)
with lem-bd-hole bd
... | BDσSubst y bdσ ub = BDσSubst (BDCast y) (lem-bdσ-into-cast bdσ) (UBCast ub)
lem-bd-hole {σ = Subst d y σ} (BDFailedCast bd)
with lem-bd-hole bd
... | BDσSubst y bdσ ub = BDσSubst (BDFailedCast y) (lem-bdσ-into-failedcast bdσ) (UBFailedCast ub)
lem-bdσ-into-nehole : ∀{σ d u σ'} →
binders-disjoint-σs σ σ' →
binders-disjoint-σ σ d →
binders-disjoint-σ σ ⦇⌜ d ⌟⦈⟨ u , σ' ⟩
lem-bdσ-into-nehole BDσsId BDσId = BDσId
lem-bdσ-into-nehole BDσsId (BDσSubst x bd x₁) = BDσSubst (BDNEHole BDσId x) (lem-bdσ-into-nehole BDσsId bd) (UBNEHole UBσId x₁)
lem-bdσ-into-nehole (BDσsSubst x bds x₁) BDσId = BDσId
lem-bdσ-into-nehole (BDσsSubst (BDσSubst x x₈ x₉) (BDσsSubst x₄ bds x₅) (UBσSubst x₁ x₆ x₇)) (BDσSubst x₂ bd x₃) = BDσSubst (BDNEHole (BDσSubst (binders-disjoint-sym x) x₄ x₁) x₂) (lem-bdσ-into-nehole (BDσsSubst x₈ (lem-bdσs-sym bds) x₆) bd) (UBNEHole (UBσSubst x₉ x₅ (flip x₇)) x₃)
lem-bdσ-nehole : ∀{d u σ σ'} →
binders-disjoint-σ σ ⦇⌜ d ⌟⦈⟨ u , σ' ⟩ →
binders-disjoint-σs σ σ' × binders-disjoint-σ σ d
lem-bdσ-nehole BDσId = (lem-bdσs-sym BDσsId) , BDσId
lem-bdσ-nehole (BDσSubst (BDNEHole x x₁) bd (UBNEHole x₂ ub))
with lem-bdσ-nehole bd
... | bds' , bd' = (lem-bdσs-sym (BDσsSubst x bds' x₂)) , (BDσSubst x₁ bd' ub)
lem-bd-nehole : ∀{d1 d u σ} →
binders-disjoint d1 ⦇⌜ d ⌟⦈⟨ u , σ ⟩ →
binders-disjoint-σ σ d1 × binders-disjoint d1 d
lem-bd-nehole BDNum = lem-bdσ-num , BDNum
lem-bd-nehole (BDPlus bd bd₁)
with lem-bd-nehole bd | lem-bd-nehole bd₁
... | bdσ' , bd' | bd₁' , bdσ₁' = lem-bdσ-into-plus bdσ' bd₁' , BDPlus bd' bdσ₁'
lem-bd-nehole BDVar = lem-bdσ-var , BDVar
lem-bd-nehole (BDLam bd (UBNEHole x x₁))
with lem-bd-nehole bd
... | bdσ' , bd' = lem-bdσ-into-lam bdσ' x , BDLam bd' x₁
lem-bd-nehole (BDAp bd bd₁)
with lem-bd-nehole bd | lem-bd-nehole bd₁
... | bdσ' , bd' | bd₁' , bdσ₁' = lem-bdσ-into-ap bdσ' bd₁' , BDAp bd' bdσ₁'
lem-bd-nehole (BDInl bd)
with lem-bd-nehole bd
... | bdσ' , bd' = lem-bdσ-into-inl bdσ' , BDInl bd'
lem-bd-nehole (BDInr bd)
with lem-bd-nehole bd
... | bdσ' , bd' = lem-bdσ-into-inr bdσ' , BDInr bd'
lem-bd-nehole (BDCase bd (UBNEHole x x₁) bd₁ (UBNEHole x₂ x₃) bd₂)
with lem-bd-nehole bd | lem-bd-nehole bd₁ | lem-bd-nehole bd₂
... | bdσ' , bd' | bdσ₁' , bd₁' | bdσ₂' , bd₂' = lem-bdσ-into-case bdσ' x bdσ₁' x₂ bdσ₂' , BDCase bd' x₁ bd₁' x₃ bd₂'
lem-bd-nehole (BDPair bd bd₁)
with lem-bd-nehole bd | lem-bd-nehole bd₁
... | bdσ' , bd' | bdσ₁' , bd₁' = lem-bdσ-into-pair bdσ' bdσ₁' , BDPair bd' bd₁'
lem-bd-nehole (BDFst bd)
with lem-bd-nehole bd
... | bdσ' , bd' = lem-bdσ-into-fst bdσ' , BDFst bd'
lem-bd-nehole (BDSnd bd)
with lem-bd-nehole bd
... | bdσ' , bd' = lem-bdσ-into-snd bdσ' , BDSnd bd'
lem-bd-nehole (BDHole {u = u} {σ = Id Γ} BDσId) = lem-bdσ-into-hole BDσsId , BDHole BDσId
lem-bd-nehole (BDHole {u = u} {σ = Subst d y σ'} (BDσSubst (BDNEHole x x₃) x₁ (UBNEHole x₂ x₄)))
with lem-bdσ-nehole x₁
... | bdσ , bdσs = (lem-bdσ-into-hole (BDσsSubst x bdσ x₂)) , (BDHole (BDσSubst x₃ bdσs x₄))
lem-bd-nehole (BDNEHole {σ = Id Γ} BDσId bd)
with lem-bd-nehole bd
... | bdσ , bdσs = lem-bdσ-into-nehole BDσsId bdσ , BDNEHole BDσId bdσs
lem-bd-nehole (BDNEHole {σ = Subst d y σ'} (BDσSubst (BDNEHole x x₃) x₁ (UBNEHole x₂ x₄)) bd)
with lem-bd-nehole bd | lem-bdσ-nehole x₁
... | bdσ , bd' | bdσs , bdσ' = (lem-bdσ-into-nehole (BDσsSubst x bdσs x₂) bdσ) , BDNEHole (BDσSubst x₃ bdσ' x₄) bd'
lem-bd-nehole (BDCast bd)
with lem-bd-nehole bd
... | bdσ' , bd' = lem-bdσ-into-cast bdσ' , BDCast bd'
lem-bd-nehole (BDFailedCast bd)
with lem-bd-nehole bd
... | bdσ' , bd' = lem-bdσ-into-failedcast bdσ' , BDFailedCast bd'
binders-disjoint-sym : ∀{d1 d2} → binders-disjoint d1 d2 → binders-disjoint d2 d1
binders-disjoint-sym {d2 = N x} bd = BDNum
binders-disjoint-sym {d2 = d2 ·+ d3} bd
with lem-bd-plus bd
... | bd1 , bd2 = BDPlus (binders-disjoint-sym bd1) (binders-disjoint-sym bd2)
binders-disjoint-sym {d2 = X x} bd = BDVar
binders-disjoint-sym {d2 = ·λ x ·[ x₁ ] d2} bd
with lem-bd-lam bd
... | bd' , ub = BDLam (binders-disjoint-sym bd') ub
binders-disjoint-sym {d2 = d2 ∘ d3} bd
with lem-bd-ap bd
... | bd1 , bd2 = BDAp (binders-disjoint-sym bd1) (binders-disjoint-sym bd2)
binders-disjoint-sym {d2 = inl x d2} bd = BDInl (binders-disjoint-sym (lem-bd-inl bd))
binders-disjoint-sym {d2 = inr x d2} bd = BDInr (binders-disjoint-sym (lem-bd-inr bd))
binders-disjoint-sym {d2 = case d2 x d3 x₁ d4} bd
with lem-bd-case bd
... | bdd , ubx , bdd1 , uby , bdd2 = BDCase (binders-disjoint-sym bdd) ubx (binders-disjoint-sym bdd1) uby (binders-disjoint-sym bdd2)
binders-disjoint-sym {d2 = ⟨ d2 , d3 ⟩} bd
with lem-bd-pair bd
... | bd1 , bd2 = BDPair (binders-disjoint-sym bd1) (binders-disjoint-sym bd2)
binders-disjoint-sym {d2 = fst d2} bd = BDFst (binders-disjoint-sym (lem-bd-fst bd))
binders-disjoint-sym {d2 = snd d2} bd = BDSnd (binders-disjoint-sym (lem-bd-snd bd))
binders-disjoint-sym {d2 = ⦇-⦈⟨ u , σ ⟩} bd = BDHole (lem-bd-hole bd)
binders-disjoint-sym {d2 = ⦇⌜ d2 ⌟⦈⟨ u , σ ⟩} bd
with lem-bd-nehole bd
... | bdσ , bd' = BDNEHole bdσ (binders-disjoint-sym bd')
binders-disjoint-sym {d2 = d2 ⟨ x ⇒ x₁ ⟩} bd = BDCast (binders-disjoint-sym (lem-bd-cast bd))
binders-disjoint-sym {d2 = d2 ⟨ x ⇒⦇-⦈⇏ x₁ ⟩} bd = BDFailedCast (binders-disjoint-sym (lem-bd-failedcast bd))
|
{
"alphanum_fraction": 0.5834682642,
"avg_line_length": 49.408,
"ext": "agda",
"hexsha": "dd3b5b4ba6f6a5bf68b5bce21203cb462ffbf529",
"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": "binders-disjoint-checks.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": "binders-disjoint-checks.agda",
"max_line_length": 299,
"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": "binders-disjoint-checks.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 16463,
"size": 37056
}
|
{-
This file proves a variety of basic results about paths:
- refl, sym, cong and composition of paths. This is used to set up
equational reasoning.
- Transport, subst and functional extensionality
- J and its computation rule (up to a path)
- Σ-types and contractibility of singletons
- Converting PathP to and from a homogeneous path with transp
- Direct definitions of lower h-levels
- Export natural numbers
- Export universe lifting
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.Prelude where
open import Cubical.Core.Primitives public
infixr 30 _∙_
infix 3 _∎
infixr 2 _≡⟨_⟩_
-- Basic theory about paths. These proofs should typically be
-- inlined. This module also makes equational reasoning work with
-- (non-dependent) paths.
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : A → Type ℓ
x y z : A
refl : x ≡ x
refl {x = x} = λ _ → x
sym : x ≡ y → y ≡ x
sym p i = p (~ i)
symP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} →
(p : PathP A x y) → PathP (λ i → A (~ i)) y x
symP p j = p (~ j)
cong : ∀ (f : (a : A) → B a) (p : x ≡ y) →
PathP (λ i → B (p i)) (f x) (f y)
cong f p i = f (p i)
cong₂ : ∀ {C : (a : A) → (b : B a) → Type ℓ} →
(f : (a : A) → (b : B a) → C a b) →
(p : x ≡ y) →
{u : B x} {v : B y} (q : PathP (λ i → B (p i)) u v) →
PathP (λ i → C (p i) (q i)) (f x u) (f y v)
cong₂ f p q i = f (p i) (q i)
-- The filler of homogeneous path composition:
-- compPath-filler p q = PathP (λ i → x ≡ q i) p (p ∙ q)
compPath-filler : ∀ {x y z : A} → x ≡ y → y ≡ z → I → I → A
compPath-filler {x = x} p q j i =
hfill (λ j → λ { (i = i0) → x
; (i = i1) → q j }) (inS (p i)) j
_∙_ : x ≡ y → y ≡ z → x ≡ z
(p ∙ q) j = compPath-filler p q i1 j
-- The filler of heterogeneous path composition:
-- compPathP-filler p q = PathP (λ i → PathP (λ j → (compPath-filler (λ i → A i) B i j)) x (q i)) p (compPathP p q)
compPathP-filler : {A : I → Type ℓ} → {x : A i0} → {y : A i1} → {B_i1 : Type ℓ} {B : A i1 ≡ B_i1} → {z : B i1} →
(p : PathP A x y) → (q : PathP (λ i → B i) y z) → ∀ (i j : I) → compPath-filler (λ i → A i) B j i
compPathP-filler {A = A} {x = x} {B = B} p q i =
fill (λ j → compPath-filler (λ i → A i) B j i)
(λ j → λ { (i = i0) → x ;
(i = i1) → q j }) (inS (p i))
compPathP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} → {B_i1 : Type ℓ} {B : (A i1) ≡ B_i1} → {z : B i1} →
(p : PathP A x y) → (q : PathP (λ i → B i) y z) → PathP (λ j → ((λ i → A i) ∙ B) j) x z
compPathP p q j = compPathP-filler p q j i1
_≡⟨_⟩_ : (x : A) → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ x≡y ⟩ y≡z = x≡y ∙ y≡z
≡⟨⟩-syntax : (x : A) → x ≡ y → y ≡ z → x ≡ z
≡⟨⟩-syntax = _≡⟨_⟩_
infixr 2 ≡⟨⟩-syntax
syntax ≡⟨⟩-syntax x (λ i → B) y = x ≡[ i ]⟨ B ⟩ y
_∎ : (x : A) → x ≡ x
_ ∎ = refl
-- another definition of composition, useful for some proofs
compPath'-filler : ∀ {x y z : A} → x ≡ y → y ≡ z → I → I → A
compPath'-filler {z = z} p q j i =
hfill (λ j → λ { (i = i0) → p (~ j)
; (i = i1) → z }) (inS (q i)) j
_□_ : x ≡ y → y ≡ z → x ≡ z
(p □ q) j = compPath'-filler p q i1 j
□≡∙ : (p : x ≡ y) (q : y ≡ z) → p □ q ≡ p ∙ q
□≡∙ {x = x} {y = y} {z = z} p q i j = hcomp (λ k → \ { (i = i0) → compPath'-filler p q k j
; (i = i1) → compPath-filler p q k j
; (j = i0) → p ( ~ i ∧ ~ k)
; (j = i1) → q (k ∨ ~ i) }) (helper i j)
where
helper : PathP (λ i → p (~ i) ≡ q (~ i)) q p
helper i j = hcomp (λ k → \ { (i = i0) → q (k ∧ j)
; (i = i1) → p (~ k ∨ j)
; (j = i0) → p (~ i ∨ ~ k)
; (j = i1) → q (~ i ∧ k) })
y
-- Transport, subst and functional extensionality
-- transport is a special case of transp
transport : {A B : Type ℓ} → A ≡ B → A → B
transport p a = transp (λ i → p i) i0 a
-- Transporting in a constant family is the identity function (up to a
-- path). If we would have regularity this would be definitional.
transportRefl : (x : A) → transport refl x ≡ x
transportRefl {A = A} x i = transp (λ _ → A) i x
-- We want B to be explicit in subst
subst : (B : A → Type ℓ') (p : x ≡ y) → B x → B y
subst B p pa = transport (λ i → B (p i)) pa
substRefl : (px : B x) → subst B refl px ≡ px
substRefl px = transportRefl px
funExt : {f g : (x : A) → B x} → ((x : A) → f x ≡ g x) → f ≡ g
funExt p i x = p x i
-- J for paths and its computation rule
module _ (P : ∀ y → x ≡ y → Type ℓ') (d : P x refl) where
J : (p : x ≡ y) → P y p
J p = transport (λ i → P (p i) (λ j → p (i ∧ j))) d
JRefl : J refl ≡ d
JRefl = transportRefl d
-- Contractibility of singletons
singl : (a : A) → Type _
singl {A = A} a = Σ[ x ∈ A ] (a ≡ x)
contrSingl : (p : x ≡ y) → Path (singl x) (x , refl) (y , p)
contrSingl p i = (p i , λ j → p (i ∧ j))
-- Converting to and from a PathP
module _ {A : I → Type ℓ} {x : A i0} {y : A i1} where
toPathP : transp A i0 x ≡ y → PathP A x y
toPathP p i = hcomp (λ j → λ { (i = i0) → x
; (i = i1) → p j })
(transp (λ j → A (i ∧ j)) (~ i) x)
fromPathP : PathP A x y → transp A i0 x ≡ y
fromPathP p i = transp (λ j → A (i ∨ j)) i (p i)
-- Direct definitions of lower h-levels
isContr : Type ℓ → Type ℓ
isContr A = Σ[ x ∈ A ] (∀ y → x ≡ y)
isProp : Type ℓ → Type ℓ
isProp A = (x y : A) → x ≡ y
isSet : Type ℓ → Type ℓ
isSet A = (x y : A) → isProp (x ≡ y)
Square
: ∀{w x y z : A}
→ (p : w ≡ y) (q : w ≡ x) (r : y ≡ z) (s : x ≡ z)
→ Set _
Square p q r s = PathP (λ i → p i ≡ s i) q r
isSet' : Type ℓ → Type ℓ
isSet' A
= {x y z w : A}
→ (p : x ≡ y) (q : z ≡ w) (r : x ≡ z) (s : y ≡ w)
→ Square r p q s
isGroupoid : Type ℓ → Type ℓ
isGroupoid A = ∀ a b → isSet (Path A a b)
Cube
: ∀{w x y z w' x' y' z' : A}
→ {p : w ≡ y} {q : w ≡ x} {r : y ≡ z} {s : x ≡ z}
→ {p' : w' ≡ y'} {q' : w' ≡ x'} {r' : y' ≡ z'} {s' : x' ≡ z'}
→ {a : w ≡ w'} {b : x ≡ x'} {c : y ≡ y'} {d : z ≡ z'}
→ (ps : Square a p p' c) (qs : Square a q q' b)
→ (rs : Square c r r' d) (ss : Square b s s' d)
→ (f0 : Square p q r s) (f1 : Square p' q' r' s')
→ Set _
Cube ps qs rs ss f0 f1
= PathP (λ k → Square (ps k) (qs k) (rs k) (ss k)) f0 f1
isGroupoid' : Set ℓ → Set ℓ
isGroupoid' A
= ∀{w x y z w' x' y' z' : A}
→ {p : w ≡ y} {q : w ≡ x} {r : y ≡ z} {s : x ≡ z}
→ {p' : w' ≡ y'} {q' : w' ≡ x'} {r' : y' ≡ z'} {s' : x' ≡ z'}
→ {a : w ≡ w'} {b : x ≡ x'} {c : y ≡ y'} {d : z ≡ z'}
→ (fp : Square a p p' c) → (fq : Square a q q' b)
→ (fr : Square c r r' d) → (fs : Square b s s' d)
→ (f0 : Square p q r s) → (f1 : Square p' q' r' s')
→ Cube fp fq fr fs f0 f1
is2Groupoid : Type ℓ → Type ℓ
is2Groupoid A = ∀ a b → isGroupoid (Path A a b)
-- Essential consequences of isProp and isContr
isProp→PathP
: ((x : A) → isProp (B x)) → {a0 a1 : A}
→ (p : a0 ≡ a1) (b0 : B a0) (b1 : B a1)
→ PathP (λ i → B (p i)) b0 b1
isProp→PathP {B = B} P p b0 b1 = toPathP {A = λ i → B (p i)} {b0} {b1} (P _ _ _)
isPropIsContr : isProp (isContr A)
isPropIsContr z0 z1 j =
( z0 .snd (z1 .fst) j
, λ x i → hcomp (λ k → λ { (i = i0) → z0 .snd (z1 .fst) j
; (i = i1) → z0 .snd x (j ∨ k)
; (j = i0) → z0 .snd x (i ∧ k)
; (j = i1) → z1 .snd x i })
(z0 .snd (z1 .snd x i) j))
isContr→isProp : isContr A → isProp A
isContr→isProp (x , p) a b i =
hcomp (λ j → λ { (i = i0) → p a j
; (i = i1) → p b j }) x
isProp→isSet : isProp A → isSet A
isProp→isSet h a b p q j i =
hcomp (λ k → λ { (i = i0) → h a a k
; (i = i1) → h a b k
; (j = i0) → h a (p i) k
; (j = i1) → h a (q i) k }) a
-- Universe lifting
record Lift {i j} (A : Type i) : Type (ℓ-max i j) where
instance constructor lift
field
lower : A
open Lift public
|
{
"alphanum_fraction": 0.4653490118,
"avg_line_length": 30.5114503817,
"ext": "agda",
"hexsha": "e7ffb877208996e5e4600fa372acd7b7a350d81a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/Foundations/Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/Foundations/Prelude.agda",
"max_line_length": 115,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/Foundations/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3463,
"size": 7994
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.DStructures.Structures.Group where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Structure
open import Cubical.Functions.FunExtEquiv
open import Cubical.Homotopy.Base
open import Cubical.Data.Sigma
open import Cubical.Relation.Binary
open import Cubical.Algebra.Group
open import Cubical.Structures.LeftAction
open import Cubical.DStructures.Base
open import Cubical.DStructures.Meta.Properties
open import Cubical.DStructures.Structures.Constant
open import Cubical.DStructures.Structures.Type
private
variable
ℓ ℓ' : Level
open URGStr
-------------------------------------------
-- URG structure on the type of groups
-------------------------------------------
𝒮-group : (ℓ : Level) → URGStr (Group {ℓ}) ℓ
𝒮-group ℓ ._≅_ = GroupEquiv
𝒮-group ℓ .ρ = idGroupEquiv
𝒮-group ℓ .uni = isUnivalent'→isUnivalent GroupEquiv
idGroupEquiv
λ G H → invEquiv (GroupPath G H)
-------------------------------------------
-- 𝒮ᴰ-hierarchies on top of 𝒮-group
--
-- Notation:
--
-- G - group
-- G² - pair of groups
-- F - morphism forth
-- B - morphism back
--
-- F B (FB)
-- \ | /
-- G
-- |
-- G
-------------------------------------------
module _ (ℓ ℓ' : Level) where
---- Underlying types
-- pairs of groups
G² = Group {ℓ} × Group {ℓ'}
-- pairs of groups + a morphism forth
G²F = Σ[ (G , H) ∈ G² ] GroupHom G H
-- pairs of groups + a morphism back
G²B = Σ[ (G , H) ∈ G² ] GroupHom H G
-- pairs of groups + morphisms forth and back
G²FB = Σ[ (G , H) ∈ G² ] GroupHom G H × GroupHom H G
---- 𝒮 and 𝒮ᴰ-structures
-- Group morphisms displayed over pairs of groups
𝒮ᴰ-G²\F : URGStrᴰ (𝒮-group ℓ ×𝒮 𝒮-group ℓ')
(λ (G , H) → GroupHom G H)
(ℓ-max ℓ ℓ')
𝒮ᴰ-G²\F =
make-𝒮ᴰ (λ {(G , H)} {(G' , H')} f (eG , eH) f' → (g : ⟨ G ⟩) → GroupEquiv.eq eH .fst ((f .fun) g) ≡ (f' .fun) (GroupEquiv.eq eG .fst g))
(λ _ _ → refl)
λ (G , H) f → isContrRespectEquiv (Σ-cong-equiv-snd (λ f' → isoToEquiv (invIso (GroupMorphismExtIso f f'))))
(isContrSingl f)
where open GroupHom
-- URG structure on type of two groups with a group morphism
𝒮-G²F : URGStr G²F (ℓ-max ℓ ℓ')
𝒮-G²F = ∫⟨ 𝒮-group ℓ ×𝒮 𝒮-group ℓ' ⟩ 𝒮ᴰ-G²\F
-- Same as 𝒮-G²F but with the morphism going the other way
𝒮ᴰ-G²\B : URGStrᴰ (𝒮-group ℓ ×𝒮 𝒮-group ℓ')
(λ (G , H) → GroupHom H G)
(ℓ-max ℓ ℓ')
𝒮ᴰ-G²\B =
make-𝒮ᴰ (λ {(_ , H)} f (eG , eH) f' → (h : ⟨ H ⟩) → GroupEquiv.eq eG .fst (f .fun h) ≡ f' .fun (GroupEquiv.eq eH .fst h))
(λ _ _ → refl)
λ _ f → isContrRespectEquiv (Σ-cong-equiv-snd (λ f' → isoToEquiv (invIso (GroupMorphismExtIso f f')))) (isContrSingl f)
where open GroupHom
-- Type of two groups with a group morphism going back
𝒮-G²B : URGStr G²B (ℓ-max ℓ ℓ')
𝒮-G²B = ∫⟨ 𝒮-group ℓ ×𝒮 𝒮-group ℓ' ⟩ 𝒮ᴰ-G²\B
-- Morphisms going forth and back displayed over pairs of groups
𝒮ᴰ-G²\FB : URGStrᴰ (𝒮-group ℓ ×𝒮 𝒮-group ℓ')
(λ (G , H) → GroupHom G H × GroupHom H G)
(ℓ-max ℓ ℓ')
𝒮ᴰ-G²\FB = combine-𝒮ᴰ 𝒮ᴰ-G²\F 𝒮ᴰ-G²\B
-- URG structure on type of pairs of groups with morphisms going forth and back
𝒮-G²FB : URGStr G²FB (ℓ-max ℓ ℓ')
𝒮-G²FB = ∫⟨ 𝒮-group ℓ ×𝒮 𝒮-group ℓ' ⟩ 𝒮ᴰ-G²\FB
|
{
"alphanum_fraction": 0.5686865917,
"avg_line_length": 31.9912280702,
"ext": "agda",
"hexsha": "66e9903aacc9796cfac68f47959c47cf83636ed4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/DStructures/Structures/Group.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"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": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/DStructures/Structures/Group.agda",
"max_line_length": 141,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/DStructures/Structures/Group.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1344,
"size": 3647
}
|
-- Hilbert-style formalisation of closed syntax.
-- Nested terms.
module OldBasicILP.UntypedSyntax.ClosedHilbert where
open import OldBasicILP.UntypedSyntax.Common public
-- Closed, untyped representations.
data Rep : Set where
APP : Rep → Rep → Rep
CI : Rep
CK : Rep
CS : Rep
BOX : Rep → Rep
CDIST : Rep
CUP : Rep
CDOWN : Rep
CPAIR : Rep
CFST : Rep
CSND : Rep
UNIT : Rep
-- Anti-bug wrappers.
record Proof : Set where
constructor [_]
field
rep : Rep
open ClosedSyntax (Proof) public
-- Derivations using representations in types.
mutual
infix 3 ⊢_
data ⊢_ : Ty → Set where
app : ∀ {A B} → ⊢ A ▻ B → ⊢ A → ⊢ B
ci : ∀ {A} → ⊢ A ▻ A
ck : ∀ {A B} → ⊢ A ▻ B ▻ A
cs : ∀ {A B C} → ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
box : ∀ {A} → (d : ⊢ A)
→ ⊢ [ ᴿ⌊ d ⌋ ] ⦂ A
cdist : ∀ {A B} → {r₁ r₂ : Rep}
→ ⊢ [ r₁ ] ⦂ (A ▻ B) ▻ [ r₂ ] ⦂ A ▻ [ APP r₁ r₂ ] ⦂ B
cup : ∀ {A} → {r : Rep}
→ ⊢ [ r ] ⦂ A ▻ [ BOX r ] ⦂ [ r ] ⦂ A
cdown : ∀ {A} → {r : Rep}
→ ⊢ [ r ] ⦂ A ▻ A
cpair : ∀ {A B} → ⊢ A ▻ B ▻ A ∧ B
cfst : ∀ {A B} → ⊢ A ∧ B ▻ A
csnd : ∀ {A B} → ⊢ A ∧ B ▻ B
unit : ⊢ ⊤
-- Projection from derivations to representations.
ᴿ⌊_⌋ : ∀ {A} → ⊢ A → Rep
ᴿ⌊ app d₁ d₂ ⌋ = APP ᴿ⌊ d₁ ⌋ ᴿ⌊ d₂ ⌋
ᴿ⌊ ci ⌋ = CI
ᴿ⌊ ck ⌋ = CK
ᴿ⌊ cs ⌋ = CS
ᴿ⌊ box d ⌋ = BOX ᴿ⌊ d ⌋
ᴿ⌊ cdist ⌋ = CDIST
ᴿ⌊ cup ⌋ = CUP
ᴿ⌊ cdown ⌋ = CDOWN
ᴿ⌊ cpair ⌋ = CPAIR
ᴿ⌊ cfst ⌋ = CFST
ᴿ⌊ csnd ⌋ = CSND
ᴿ⌊ unit ⌋ = UNIT
infix 3 ⊢⋆_
⊢⋆_ : Cx Ty → Set
⊢⋆ ∅ = 𝟙
⊢⋆ Ξ , A = ⊢⋆ Ξ × ⊢ A
-- Cut and multicut.
cut : ∀ {A B} → ⊢ A → ⊢ A ▻ B → ⊢ B
cut d₁ d₂ = app d₂ d₁
multicut : ∀ {Ξ A} → ⊢⋆ Ξ → ⊢ Ξ ▻⋯▻ A → ⊢ A
multicut {∅} ∙ d₂ = d₂
multicut {Ξ , B} (ds , d₁) d₂ = app (multicut ds d₂) d₁
-- Contraction.
ccont : ∀ {A B} → ⊢ (A ▻ A ▻ B) ▻ A ▻ B
ccont = app (app cs cs) (app ck ci)
cont : ∀ {A B} → ⊢ A ▻ A ▻ B → ⊢ A ▻ B
cont d = app ccont d
-- Exchange, or Schönfinkel’s C combinator.
cexch : ∀ {A B C} → ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C
cexch = app (app cs (app (app cs (app ck cs))
(app (app cs (app ck ck)) cs)))
(app ck ck)
exch : ∀ {A B C} → ⊢ A ▻ B ▻ C → ⊢ B ▻ A ▻ C
exch d = app cexch d
-- Composition, or Schönfinkel’s B combinator.
ccomp : ∀ {A B C} → ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
ccomp = app (app cs (app ck cs)) ck
comp : ∀ {A B C} → ⊢ B ▻ C → ⊢ A ▻ B → ⊢ A ▻ C
comp d₁ d₂ = app (app ccomp d₁) d₂
-- Useful theorems in functional form.
dist : ∀ {A B r₁ r₂} → ⊢ [ r₁ ] ⦂ (A ▻ B) → ⊢ [ r₂ ] ⦂ A → ⊢ [ APP r₁ r₂ ] ⦂ B
dist d₁ d₂ = app (app cdist d₁) d₂
up : ∀ {A r} → ⊢ [ r ] ⦂ A → ⊢ [ BOX r ] ⦂ [ r ] ⦂ A
up d = app cup d
down : ∀ {A r} → ⊢ [ r ] ⦂ A → ⊢ A
down d = app cdown d
distup : ∀ {A B r₀ r₁} → ⊢ [ r₁ ] ⦂ ([ r₀ ] ⦂ A ▻ B) → ⊢ [ r₀ ] ⦂ A → ⊢ [ APP r₁ (BOX r₀) ] ⦂ B
distup d₁ d₂ = dist d₁ (up d₂)
pair : ∀ {A B} → ⊢ A → ⊢ B → ⊢ A ∧ B
pair d₁ d₂ = app (app cpair d₁) d₂
fst : ∀ {A B} → ⊢ A ∧ B → ⊢ A
fst d = app cfst d
snd : ∀ {A B} → ⊢ A ∧ B → ⊢ B
snd d = app csnd d
|
{
"alphanum_fraction": 0.4301710731,
"avg_line_length": 21.8707482993,
"ext": "agda",
"hexsha": "840efdeb39f552dcb01c2c7945415c25bc4f4a0a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "OldBasicILP/UntypedSyntax/ClosedHilbert.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "OldBasicILP/UntypedSyntax/ClosedHilbert.agda",
"max_line_length": 95,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "OldBasicILP/UntypedSyntax/ClosedHilbert.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 1593,
"size": 3215
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Pairs of lists that share no common elements (setoid equality)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Data.List.Relation.Binary.Disjoint.Setoid {c ℓ} (S : Setoid c ℓ) where
open import Level using (_⊔_)
open import Relation.Nullary using (¬_)
open import Function using (_∘_)
open import Data.List.Base using (List; []; [_]; _∷_)
open import Data.List.Relation.Unary.Any using (here; there)
open import Data.Product using (_×_; _,_)
open Setoid S renaming (Carrier to A)
open import Data.List.Membership.Setoid S using (_∈_; _∉_)
------------------------------------------------------------------------
-- Definition
Disjoint : Rel (List A) (ℓ ⊔ c)
Disjoint xs ys = ∀ {v} → ¬ (v ∈ xs × v ∈ ys)
------------------------------------------------------------------------
-- Operations
contractₗ : ∀ {x xs ys} → Disjoint (x ∷ xs) ys → Disjoint xs ys
contractₗ x∷xs∩ys=∅ (v∈xs , v∈ys) = x∷xs∩ys=∅ (there v∈xs , v∈ys)
contractᵣ : ∀ {xs y ys} → Disjoint xs (y ∷ ys) → Disjoint xs ys
contractᵣ xs#y∷ys (v∈xs , v∈ys) = xs#y∷ys (v∈xs , there v∈ys)
|
{
"alphanum_fraction": 0.511517077,
"avg_line_length": 34.027027027,
"ext": "agda",
"hexsha": "d9c12c294c52b57fa2b2f5983d49f3a95f47b3bb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Disjoint/Setoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Disjoint/Setoid.agda",
"max_line_length": 77,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Disjoint/Setoid.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 348,
"size": 1259
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Setoids.Setoids
open import Setoids.Subset
open import Setoids.Functions.Definition
open import Sets.EquivalenceRelations
module Setoids.Functions.Lemmas {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {f : A → B} (w : WellDefined S T f) where
inverseImagePred : {e : _} → {pred : B → Set e} → (sub : subset T pred) → A → Set (b ⊔ d ⊔ e)
inverseImagePred {pred = pred} subset a = Sg B (λ b → (pred b) && (Setoid._∼_ T (f a) b))
inverseImageWellDefined : {e : _} {pred : B → Set e} → (sub : subset T pred) → subset S (inverseImagePred sub)
inverseImageWellDefined sub {x} {y} x=y (b , (predB ,, fx=b)) = f x , (sub (symmetric fx=b) predB ,, symmetric (w x=y))
where
open Setoid T
open Equivalence eq
|
{
"alphanum_fraction": 0.6496106785,
"avg_line_length": 44.95,
"ext": "agda",
"hexsha": "2ff86ab0b2115c4e7d15e3a0c47f99fd3c51c488",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Setoids/Functions/Lemmas.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Setoids/Functions/Lemmas.agda",
"max_line_length": 157,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Setoids/Functions/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 312,
"size": 899
}
|
------------------------------------------------------------------------------
-- FOT (First-Order Theories)
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- Code accompanying the PhD thesis "Reasoning about Functional
-- Programs by Combining Interactive and Automatic Proofs" by Andrés
-- Sicard-Ramírez.
-- The code presented here does not match the thesis exactly.
module README where
------------------------------------------------------------------------------
-- Description
-- Examples of the formalization of first-order theories showing the
-- combination of interactive proofs with automatics proofs carried
-- out by first-order automatic theorem provers (ATPs).
------------------------------------------------------------------------------
-- For the thesis, prerequisites, tested versions of the ATPs and use,
-- see https://github.com/asr/fotc/.
------------------------------------------------------------------------------
-- Conventions
-- If the module's name ends in 'I' the module contains interactive
-- proofs, if it ends in 'ATP' the module contains combined proofs,
-- otherwise the module contains definitions and/or interactive proofs
-- that are used by the interactive and combined proofs.
------------------------------------------------------------------------------
-- First-order theories
------------------------------------------------------------------------------
-- • First-order logic with equality
-- First-order logic (FOL)
open import FOL.README
-- Propositional equality
open import Common.FOL.Relation.Binary.PropositionalEquality
-- Equality reasoning
open import Common.FOL.Relation.Binary.EqReasoning
-- • Group theory
open import GroupTheory.README
-- • Distributive laws on a binary operation (Stanovský example)
open import DistributiveLaws.README
-- • First-order Peano arithmetic (PA)
open import PA.README
-- • First-Order Theory of Combinators (FOTC)
open import FOTC.README
-- • Logical Theory of Constructions for PCF (LTC-PCF)
open import LTC-PCF.README
------------------------------------------------------------------------------
-- Agsy examples
------------------------------------------------------------------------------
-- We cannot import the Agsy examples because some modules contain
-- unsolved metas, therefore see examples/Agsy/README.txt
|
{
"alphanum_fraction": 0.5330188679,
"avg_line_length": 32.6153846154,
"ext": "agda",
"hexsha": "dc7d8982d7ba282219a9b44f6502362add1fa184",
"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/README.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/README.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/README.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": 437,
"size": 2544
}
|
open import Type
module Graph.Walk.Proofs {ℓ₁ ℓ₂} {V : Type{ℓ₁}} where
open import Lang.Instance
open import Logic
import Lvl
open import Graph{ℓ₁}{ℓ₂}(V)
open import Graph.Walk{ℓ₁}{ℓ₂}{V}
open import Relator.Equals.Proofs.Equiv
import Structure.Relator.Names as Names
open import Structure.Relator.Properties
open import Type.Properties.Singleton
private variable ℓ : Lvl.Level
private variable _⟶_ : Graph
private variable a b : V
private variable _▫_ : V → V → Type{ℓ}
-- There is a walk between two vertices when there is one edge between them.
instance
Walk-super : (_⟶_) ⊆₂ (Walk(_⟶_))
_⊆₂_.proof Walk-super p = prepend p at
-- Walk is a "smallest" reflexive-transitive closure
Walk-sub : ⦃ _ : Reflexivity(_▫_) ⦄ → ⦃ _ : Transitivity(_▫_) ⦄ → ⦃ _ : (_⟶_) ⊆₂ (_▫_) ⦄ → (Walk(_⟶_)) ⊆₂ (_▫_)
Walk-sub {_▫_ = _▫_}{_⟶_ = _⟶_} = intro proof where
proof : Names.Subrelation(Walk(_⟶_))(_▫_)
proof at = transitivity(_▫_) (reflexivity(_▫_)) (reflexivity(_▫_))
proof (prepend ab1 walkb1b) = transitivity(_▫_) (sub₂(_⟶_)(_▫_) ab1) (proof walkb1b)
Walk-transitivity-raw : Names.Transitivity(Walk(_⟶_))
Walk-transitivity-raw at xz = xz
Walk-transitivity-raw (prepend xb by) yz = prepend xb (Walk-transitivity-raw by yz)
instance
-- A walk can be joined/concatenated to form a new walk.
Walk-transitivity : Transitivity(Walk(_⟶_))
Transitivity.proof Walk-transitivity = Walk-transitivity-raw
instance
Walk-reflexivity : Reflexivity(Walk(_⟶_))
Walk-reflexivity = intro at
|
{
"alphanum_fraction": 0.6947162427,
"avg_line_length": 34.8409090909,
"ext": "agda",
"hexsha": "0dc5fe99b744a3a328a5be0f68b4bbc4fa60c381",
"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": "Graph/Walk/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": "Graph/Walk/Proofs.agda",
"max_line_length": 111,
"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": "Graph/Walk/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": 521,
"size": 1533
}
|
{-# OPTIONS --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Fundamental.Variable {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Fundamental theorem for variables.
fundamentalVar : ∀ {Γ A rA x}
→ x ∷ A ^ rA ∈ Γ
→ ([Γ] : ⊩ᵛ Γ)
→ ∃ λ ([A] : Γ ⊩ᵛ⟨ ∞ ⟩ A ^ rA / [Γ])
→ Γ ⊩ᵛ⟨ ∞ ⟩ var x ∷ A ^ rA / [Γ] / [A]
fundamentalVar here (_∙_ {A = A} {rA = rA} {l = l} [Γ] [A]) =
(λ ⊢Δ [σ] →
let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ]))
[σA′] = maybeEmb (irrelevance′ (PE.sym (subst-wk A)) [σA])
in [σA′]
, (λ [σ′] [σ≡σ′] →
irrelevanceEq″ (PE.sym (subst-wk A)) (PE.sym (subst-wk A)) PE.refl PE.refl
[σA] [σA′] (proj₂ ([A] ⊢Δ (proj₁ [σ]))
(proj₁ [σ′]) (proj₁ [σ≡σ′]))))
, (λ ⊢Δ [σ] →
let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ]))
[σA′] = maybeEmb (irrelevance′ (PE.sym (subst-wk A)) [σA])
in irrelevanceTerm′ (PE.sym (subst-wk A)) PE.refl PE.refl [σA] [σA′] (proj₂ [σ])
, (λ [σ′] [σ≡σ′] → irrelevanceEqTerm′ (PE.sym (subst-wk A)) PE.refl PE.refl
[σA] [σA′] (proj₂ [σ≡σ′])))
fundamentalVar (there {A = A} h) ([Γ] ∙ [B]) =
(λ ⊢Δ [σ] →
let [h] = proj₁ (fundamentalVar h [Γ]) ⊢Δ (proj₁ [σ])
[σA] = proj₁ [h]
[σA′] = irrelevance′ (PE.sym (subst-wk A)) [σA]
in [σA′]
, (λ [σ′] [σ≡σ′] →
irrelevanceEq″ (PE.sym (subst-wk A)) (PE.sym (subst-wk A)) PE.refl PE.refl
[σA] [σA′]
(proj₂ [h] (proj₁ [σ′]) (proj₁ [σ≡σ′]))))
, (λ ⊢Δ [σ] →
let [h] = (proj₁ (fundamentalVar h [Γ])) ⊢Δ (proj₁ [σ])
[σA] = proj₁ [h]
[σA′] = irrelevance′ (PE.sym (subst-wk A)) [σA]
[h′] = (proj₂ (fundamentalVar h [Γ])) ⊢Δ (proj₁ [σ])
in irrelevanceTerm′ (PE.sym (subst-wk A)) PE.refl PE.refl [σA] [σA′] (proj₁ [h′])
, (λ [σ′] [σ≡σ′] →
irrelevanceEqTerm′ (PE.sym (subst-wk A)) PE.refl PE.refl [σA] [σA′]
(proj₂ [h′] (proj₁ [σ′]) (proj₁ [σ≡σ′]))))
|
{
"alphanum_fraction": 0.4891141141,
"avg_line_length": 42.9677419355,
"ext": "agda",
"hexsha": "1b753f6172df47b3e7eac373c5ef818b2dd74c49",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Fundamental/Variable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Fundamental/Variable.agda",
"max_line_length": 91,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Fundamental/Variable.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": 978,
"size": 2664
}
|
------------------------------------------------------------------------
-- Unambiguity
------------------------------------------------------------------------
module TotalParserCombinators.Unambiguity where
open import Data.Product
open import Function using (_$_)
open import Function.Equivalence
open import Relation.Binary.PropositionalEquality
open import Relation.Binary.HeterogeneousEquality as H
renaming (_≅_ to _≅′_)
open import TotalParserCombinators.Parser
open import TotalParserCombinators.Semantics
-- A parser is unambiguous if every string can be parsed in at most
-- one way.
Unambiguous : ∀ {Tok R xs} → Parser Tok R xs → Set₁
Unambiguous p =
∀ {x₁ x₂ s} (x₁∈p : x₁ ∈ p · s) (x₂∈p : x₂ ∈ p · s) →
x₁ ≡ x₂ × x₁∈p ≅′ x₂∈p
-- Language and parser equivalence coincide for unambiguous parsers.
≈⇒≅ : ∀ {Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
Unambiguous p₁ → Unambiguous p₂ → p₁ ≈ p₂ → p₁ ≅ p₂
≈⇒≅ u₁ u₂ p₁≈p₂ = record
{ to = Equivalence.to p₁≈p₂
; from = Equivalence.from p₁≈p₂
; inverse-of = record
{ left-inverse-of = λ x∈p₁ → H.≅-to-≡ $ proj₂ $ u₁ _ x∈p₁
; right-inverse-of = λ x∈p₂ → H.≅-to-≡ $ proj₂ $ u₂ _ x∈p₂
}
}
|
{
"alphanum_fraction": 0.5810920945,
"avg_line_length": 32.2894736842,
"ext": "agda",
"hexsha": "d3d3ec243783cb02190337e062c3db0b83f32d4b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "TotalParserCombinators/Unambiguity.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": "TotalParserCombinators/Unambiguity.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": "TotalParserCombinators/Unambiguity.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": 406,
"size": 1227
}
|
module Data.Num.Standard where
-- Standard positional notations
open import Data.Nat
open ≤-Reasoning
renaming (begin_ to start_; _∎ to _□)
-- using (≰⇒>; +-∸-assoc; ∸-mono)
open import Data.Nat.Properties
open import Data.Fin using (Fin)
renaming (zero to Fzero; suc to Fsuc; toℕ to F→N; fromℕ≤ to N→F)
open import Data.Fin.Properties using (bounded)
open import Function
open import Relation.Nullary
-- open import Relation.Nullary.Decidable using (True; False; toWitness; toWitnessFalse; fromWitness; fromWitnessFalse)
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; cong; sym; trans; inspect)
open PropEq.≡-Reasoning
open import Relation.Binary
ℕ-isDecTotalOrder = DecTotalOrder.isDecTotalOrder decTotalOrder
ℕ-isTotalOrder = IsDecTotalOrder.isTotalOrder ℕ-isDecTotalOrder
ℕ-isPartialOrder = IsTotalOrder.isPartialOrder ℕ-isTotalOrder
ℕ-isPreorder = IsPartialOrder.isPreorder ℕ-isPartialOrder
≤-refl = IsPreorder.reflexive ℕ-isPreorder
≤-antisym = IsPartialOrder.antisym ℕ-isPartialOrder
≤-total = IsTotalOrder.total ℕ-isTotalOrder
data Digit : (base : ℕ) → Set where
D : ∀ {base} → Fin base → Digit base
infixl 6 _D+_
_D+_ : ∀ {b} → Digit b → Digit b → Digit b
D x D+ D {b} y with b ≤? (F→N x + F→N y)
D x D+ D {b} y | yes p = D $ N→F {F→N x + F→N y ∸ b} $
start
suc (F→N x + F→N y ∸ b)
≤⟨ ≤-refl (sym (+-∸-assoc 1 p)) ⟩
(suc (F→N x) + F→N y) ∸ b
≤⟨ ∸-mono {suc (F→N x) + F→N y} {b + b} {b} {b} (bounded x +-mono (
start
F→N y
≤⟨ n≤1+n (F→N y) ⟩
suc (F→N y)
≤⟨ bounded y ⟩
b
□
)) (≤-refl refl) ⟩
b + b ∸ b
≤⟨ ≤-refl (m+n∸n≡m b b) ⟩
b
□
D x D+ D {b} y | no ¬p = D $ N→F (≰⇒> ¬p)
-- start
-- {! !}
-- ≤⟨ {! !} ⟩
-- {! !}
-- ≤⟨ {! !} ⟩
-- {! !}
-- ≤⟨ {! !} ⟩
-- {! !}
-- ≤⟨ {! !} ⟩
-- {! !}
-- □
-- begin
-- {! !}
-- ≡⟨ {! !} ⟩
-- {! !}
-- ≡⟨ {! !} ⟩
-- {! !}
-- ≡⟨ {! !} ⟩
-- {! !}
-- ≡⟨ {! !} ⟩
-- {! !}
-- ∎
|
{
"alphanum_fraction": 0.5189340813,
"avg_line_length": 26.7375,
"ext": "agda",
"hexsha": "af7255a4e407aeb96bd20a3b0b95c5b9c3e69197",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Data/Num/Sandbox/_Standard.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "Data/Num/Sandbox/_Standard.agda",
"max_line_length": 119,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Data/Num/Sandbox/_Standard.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 836,
"size": 2139
}
|
open import Prelude
open import Nat
open import dynamics-core
open import contexts
open import lemmas-disjointness
module lemmas-freshness where
-- if x is fresh in an hexp, it's fresh in its expansion
mutual
fresh-elab-synth1 : ∀{x e τ d Γ Δ} →
x # Γ →
freshh x e →
Γ ⊢ e ⇒ τ ~> d ⊣ Δ →
fresh x d
fresh-elab-synth1 apt FHNum ESNum = FNum
fresh-elab-synth1 apt (FRHPlus x x₄) (ESPlus gapt x₁ x₂ x₃) =
FPlus (FCast (fresh-elab-ana1 apt x x₂))
(FCast (fresh-elab-ana1 apt x₄ x₃))
fresh-elab-synth1 apt (FRHAsc frsh) (ESAsc x₁) = FCast (fresh-elab-ana1 apt frsh x₁)
fresh-elab-synth1 _ (FRHVar x₂) (ESVar x₃) = FVar x₂
fresh-elab-synth1 {Γ = Γ} apt (FRHLam2 x₂ frsh) (ESLam x₃ exp) = FLam x₂ (fresh-elab-synth1 (apart-extend1 Γ x₂ apt) frsh exp)
fresh-elab-synth1 apt (FRHAp frsh frsh₁) (ESAp x₁ x₂ x₃ x₄ x₅ x₆) = FAp (FCast (fresh-elab-ana1 apt frsh x₅)) (FCast (fresh-elab-ana1 apt frsh₁ x₆))
fresh-elab-synth1 apt (FRHPair frsh frsh₁) (ESPair x x₁ x₂ x₃) = FPair (fresh-elab-synth1 apt frsh x₂) (fresh-elab-synth1 apt frsh₁ x₃)
fresh-elab-synth1 apt (FRHFst frsh) (ESFst x x₁ x₂) = FFst (FCast (fresh-elab-ana1 apt frsh x₂))
fresh-elab-synth1 apt (FRHSnd frsh) (ESSnd x x₁ x₂) = FSnd (FCast (fresh-elab-ana1 apt frsh x₂))
fresh-elab-synth1 apt FRHEHole ESEHole = FHole (EFId apt)
fresh-elab-synth1 apt (FRHNEHole frsh) (ESNEHole x₁ exp) = FNEHole (EFId apt) (fresh-elab-synth1 apt frsh exp)
fresh-elab-ana1 : ∀{x e τ d τ' Γ Δ} →
x # Γ →
freshh x e →
Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →
fresh x d
fresh-elab-ana1 {Γ = Γ} apt (FRHLam1 x₁ frsh) (EALam x₂ x₃ exp) = FLam x₁ (fresh-elab-ana1 (apart-extend1 Γ x₁ apt) frsh exp )
fresh-elab-ana1 apt frsh (EASubsume x₁ x₂ x₃ x₄) = fresh-elab-synth1 apt frsh x₃
fresh-elab-ana1 apt (FRHInl frsh) (EAInl x x₁) = FInl (fresh-elab-ana1 apt frsh x₁)
fresh-elab-ana1 apt (FRHInr frsh) (EAInr x x₁) = FInr (fresh-elab-ana1 apt frsh x₁)
fresh-elab-ana1 {Γ = Γ} apt (FRHCase frsh x₁ frsh₁ x₂ frsh₂) (EACase x x₃ x₄ x₅ x₆ x₇ x₈ x₉ x₁₀ x₁₁ x₁₂ x₁₃) = FCase (FCast (fresh-elab-synth1 apt frsh x₁₀)) x₁ (FCast (fresh-elab-ana1 (apart-extend1 Γ x₁ apt) frsh₁ x₁₂)) x₂ (FCast (fresh-elab-ana1 (apart-extend1 Γ x₂ apt) frsh₂ x₁₃))
fresh-elab-ana1 apt FRHEHole EAEHole = FHole (EFId apt)
fresh-elab-ana1 apt (FRHNEHole frsh) (EANEHole x₁ x₂) = FNEHole (EFId apt) (fresh-elab-synth1 apt frsh x₂)
-- if x is fresh in the expansion of an hexp, it's fresh in that hexp
mutual
fresh-elab-synth2 : ∀{x e τ d Γ Δ} →
fresh x d →
Γ ⊢ e ⇒ τ ~> d ⊣ Δ →
freshh x e
fresh-elab-synth2 FNum ESNum = FRHNum
fresh-elab-synth2 (FPlus (FCast x) (FCast x₄)) (ESPlus apt x₁ x₂ x₃) =
FRHPlus (fresh-elab-ana2 x x₂) (fresh-elab-ana2 x₄ x₃)
fresh-elab-synth2 (FVar x₂) (ESVar x₃) = FRHVar x₂
fresh-elab-synth2 (FLam x₂ frsh) (ESLam x₃ exp) = FRHLam2 x₂ (fresh-elab-synth2 frsh exp)
fresh-elab-synth2 (FAp (FCast frsh) (FCast frsh₁)) (ESAp x₁ x₂ x₃ x₄ x₅ x₆) = FRHAp (fresh-elab-ana2 frsh x₅) (fresh-elab-ana2 frsh₁ x₆)
fresh-elab-synth2 (FPair frsh frsh₁) (ESPair x x₁ x₂ x₃) = FRHPair (fresh-elab-synth2 frsh x₂) (fresh-elab-synth2 frsh₁ x₃)
fresh-elab-synth2 (FFst (FCast frsh)) (ESFst x x₁ x₂) = FRHFst (fresh-elab-ana2 frsh x₂)
fresh-elab-synth2 (FSnd (FCast frsh)) (ESSnd x x₁ x₂) = FRHSnd (fresh-elab-ana2 frsh x₂)
fresh-elab-synth2 (FHole x₁) ESEHole = FRHEHole
fresh-elab-synth2 (FNEHole x₁ frsh) (ESNEHole x₂ exp) = FRHNEHole (fresh-elab-synth2 frsh exp)
fresh-elab-synth2 (FCast frsh) (ESAsc x₁) = FRHAsc (fresh-elab-ana2 frsh x₁)
fresh-elab-ana2 : ∀{ x e τ d τ' Γ Δ} →
fresh x d →
Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →
freshh x e
fresh-elab-ana2 (FLam x₁ frsh) (EALam x₂ x₃ exp) = FRHLam1 x₁ (fresh-elab-ana2 frsh exp)
fresh-elab-ana2 frsh (EASubsume x₁ x₂ x₃ x₄) = fresh-elab-synth2 frsh x₃
fresh-elab-ana2 (FHole x₁) EAEHole = FRHEHole
fresh-elab-ana2 (FNEHole x₁ frsh) (EANEHole x₂ x₃) = FRHNEHole (fresh-elab-synth2 frsh x₃)
fresh-elab-ana2 (FInl frsh) (EAInl x x₁) = FRHInl (fresh-elab-ana2 frsh x₁)
fresh-elab-ana2 (FInr frsh) (EAInr x x₁) = FRHInr (fresh-elab-ana2 frsh x₁)
fresh-elab-ana2 (FCase (FCast frsh) x (FCast frsh₁) x₁ (FCast frsh₂)) (EACase x₂ x₃ x₄ x₅ x₆ x₇ x₈ x₉ x₁₀ x₁₁ x₁₂ x₁₃) = FRHCase (fresh-elab-synth2 frsh x₁₀) x (fresh-elab-ana2 frsh₁ x₁₂) x₁ (fresh-elab-ana2 frsh₂ x₁₃)
|
{
"alphanum_fraction": 0.6216726053,
"avg_line_length": 66.2638888889,
"ext": "agda",
"hexsha": "a6d73277e3427dae97fa746a3888c71efcc1bd84",
"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": "lemmas-freshness.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": "lemmas-freshness.agda",
"max_line_length": 289,
"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": "lemmas-freshness.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2020,
"size": 4771
}
|
module SN where
open import Relation.Unary using (_∈_; _⊆_)
open import Library
open import Terms
open import Substitution
open import TermShape public
-- Inductive definition of strong normalization.
infix 7 _⟨_⟩⇒_ _⇒ˢ_
mutual
-- Strongly normalizing evaluation contexts
SNhole : ∀ {i : Size} {Γ : Cxt} {a b : Ty} → Tm Γ b → ECxt Γ a b → Tm Γ a → Set
SNhole {i} = PCxt (SN {i})
-- Strongly neutral terms.
SNe : ∀ {i : Size} {Γ} {b} → Tm Γ b → Set
SNe {i} = PNe (SN {i})
-- Strongly normalizing terms.
data SN {i : Size}{Γ} : ∀ {a} → Tm Γ a → Set where
ne : ∀ {j : Size< i} {a t}
→ (𝒏 : SNe {j} t)
→ SN {a = a} t
abs : ∀ {j : Size< i} {a b}{t : Tm (a ∷ Γ) b}
→ (𝒕 : SN {j} t)
→ SN (abs t)
exp : ∀ {j₁ j₂ : Size< i} {a t t′}
→ (t⇒ : t ⟨ j₁ ⟩⇒ t′) (𝒕′ : SN {j₂} t′)
→ SN {a = a} t
_⟨_⟩⇒_ : ∀ {Γ a} → Tm Γ a → Size → Tm Γ a → Set
t ⟨ i ⟩⇒ t′ = SN {i} / t ⇒ t′
-- Strong head reduction
_⇒ˢ_ : ∀ {i : Size} {Γ} {a} → Tm Γ a → Tm Γ a → Set
_⇒ˢ_ {i} t t' = (SN {i}) / t ⇒ t'
-- -- Inductive definition of strong normalization.
-- mutual
-- -- Strongly normalizing evaluation contexts
-- data SNhole {i : Size} (n : ℕ) {Γ : Cxt} : {a b : Ty} → Tm Γ b → ECxt Γ a b → Tm Γ a → Set where
-- appl : ∀ {a b t u}
-- → (𝒖 : SN {i} n u)
-- → SNhole n (app t u) (appl u) (t ∶ (a →̂ b))
-- -- Strongly neutral terms.
-- data SNe {i : Size} (n : ℕ) {Γ} {b} : Tm Γ b → Set where
-- var : ∀ x → SNe n (var x)
-- elim : ∀ {a} {t : Tm Γ a} {E Et}
-- → (𝒏 : SNe {i} n t) (𝑬𝒕 : SNhole {i} n Et E t) → SNe n Et
-- -- elim : ∀ {j₁ j₂ : Size< i}{a} {t : Tm Γ a} {E Et}
-- -- → (𝒏 : SNe {j₁} n t) (𝑬𝒕 : SNhole {j₂} n Et E t) → SNe n Et
-- -- Strongly normalizing terms.
-- data SN {i : Size}{Γ} : ℕ → ∀ {a} → Tm Γ a → Set where
-- ne : ∀ {j : Size< i} {a n t}
-- → (𝒏 : SNe {j} n t)
-- → SN n {a} t
-- abs : ∀ {j : Size< i} {a b n}{t : Tm (a ∷ Γ) b}
-- → (𝒕 : SN {j} n t)
-- → SN n (abs t)
-- exp : ∀ {j₁ j₂ : Size< i} {a n t t′}
-- → (t⇒ : j₁ size t ⟨ n ⟩⇒ t′) (𝒕′ : SN {j₂} n t′)
-- → SN n {a} t
-- _size_⟨_⟩⇒_ : ∀ (i : Size) {Γ}{a} → Tm Γ a → ℕ → Tm Γ a → Set
-- i size t ⟨ n ⟩⇒ t′ = _⟨_⟩⇒_ {i} t n t′
-- -- Strong head reduction
-- data _⟨_⟩⇒_ {i : Size} {Γ} : ∀ {a} → Tm Γ a → ℕ → Tm Γ a → Set where
-- β : ∀ {a b}{t : Tm (a ∷ Γ) b}{u}
-- → (𝒖 : SN {i} n u)
-- → (app (abs t) u) ⟨ n ⟩⇒ subst0 u t
-- cong : ∀ {a b t t' Et Et'}{E : ECxt Γ a b}
-- → (𝑬𝒕 : Ehole Et E t)
-- → (𝑬𝒕' : Ehole Et' E t')
-- → (t⇒ : i size t ⟨ n ⟩⇒ t')
-- → Et ⟨ n ⟩⇒ Et'
-- β : ∀ {j : Size< i} {a b}{t : Tm (a ∷ Γ) b}{u}
-- → (𝒖 : SN {j} n u)
-- → (app (abs t) u) ⟨ n ⟩⇒ subst0 u t
-- cong : ∀ {j : Size< i} {a b t t' Et Et'}{E : ECxt Γ a b}
-- → (𝑬𝒕 : Ehole Et E t)
-- → (𝑬𝒕' : Ehole Et' E t')
-- → (t⇒ : j size t ⟨ n ⟩⇒ t')
-- → Et ⟨ n ⟩⇒ Et'
-- Strong head reduction is deterministic.
det⇒ : ∀ {a Γ} {t t₁ t₂ : Tm Γ a}
→ (t⇒₁ : t ⟨ _ ⟩⇒ t₁) (t⇒₂ : t ⟨ _ ⟩⇒ t₂) → t₁ ≡ t₂
det⇒ (β _) (β _) = ≡.refl
det⇒ (β _) (cong (appl u) (appl .u) (cong () _ _))
det⇒ (cong (appl u) (appl .u) (cong () _ _)) (β _)
det⇒ (cong (appl u) (appl .u) x) (cong (appl .u) (appl .u) y) = ≡.cong (λ t → app t u) (det⇒ x y)
-- Strongly neutrals are closed under application.
sneApp : ∀{Γ a b}{t : Tm Γ (a →̂ b)}{u : Tm Γ a} →
SNe t → SN u → SNe (app t u)
sneApp 𝒏 𝒖 = elim 𝒏 (appl 𝒖)
-- Substituting strongly neutral terms
record RenSubSNe {i} (vt : VarTm i) (Γ Δ : Cxt) : Set where
constructor _,_
field theSubst : RenSub vt Γ Δ
isSNe : ∀ {a} (x : Var Γ a) → SNe (vt2tm _ (theSubst x))
open RenSubSNe
RenSN = RenSubSNe `Var
SubstSNe = RenSubSNe `Tm
-- The singleton SNe substitution.
-- Replaces the first variable by another variable.
sgs-varSNe : ∀ {Γ a} → Var Γ a → SubstSNe (a ∷ Γ) Γ
theSubst (sgs-varSNe x) = sgs (var x)
isSNe (sgs-varSNe x) (zero) = (var x)
isSNe (sgs-varSNe x) (suc y) = var y
-- The SN-notions are closed under SNe substitution.
mutual
substSNh : ∀ {i vt Γ Δ a b} → (σ : RenSubSNe {i} vt Γ Δ) → ∀ {E : ECxt Γ a b}{Et t} → (SNh : SNhole Et E t)
→ SNhole (subst (theSubst σ) Et) (substEC (theSubst σ) E) (subst (theSubst σ) t)
substSNh σ (appl u) = appl (substSN σ u)
subst⇒ : ∀ {i vt Γ Δ a} (σ : RenSubSNe {i} vt Γ Δ) {t t' : Tm Γ a} → t ⟨ _ ⟩⇒ t' → subst (theSubst σ) t ⟨ _ ⟩⇒ subst (theSubst σ) t'
subst⇒ (σ , σ∈Ne) (β {t = t} {u = u} x) = ≡.subst (λ t' → app (abs (subst (lifts σ) t)) (subst σ u) ⟨ _ ⟩⇒ t')
(sgs-lifts-term {σ = σ} {u} {t})
(β {t = subst (lifts σ) t} (substSN (σ , σ∈Ne) x))
subst⇒ σ (cong Eh Eh' t→t') = cong (substEh (theSubst σ) Eh) (substEh (theSubst σ) Eh') (subst⇒ σ t→t')
-- Lifting a SNe substitution.
liftsSNe : ∀ {i vt Γ Δ a} → RenSubSNe {i} vt Γ Δ → RenSubSNe {i} vt (a ∷ Γ) (a ∷ Δ)
theSubst (liftsSNe σ) = lifts (theSubst σ)
isSNe (liftsSNe {vt = `Var} (σ , σ∈SNe)) (zero) = var (zero)
isSNe (liftsSNe {vt = `Var} (σ , σ∈SNe)) (suc y) = var (suc (σ y))
isSNe (liftsSNe {vt = `Tm } (σ , σ∈SNe)) (zero) = var (zero)
isSNe (liftsSNe {vt = `Tm } (σ , σ∈SNe)) (suc y) = substSNe {vt = `Var} (suc , (λ x → var (suc x))) (σ∈SNe y)
substSNe : ∀ {i vt Γ Δ τ} → (σ : RenSubSNe {i} vt Γ Δ) → ∀ {t : Tm Γ τ} → SNe t → SNe (subst (theSubst σ) t)
substSNe σ (var x) = isSNe σ x
substSNe σ (elim t∈SNe E∈SNh) = elim (substSNe σ t∈SNe) (substSNh σ E∈SNh)
substSN : ∀ {i vt Γ Δ τ} → (σ : RenSubSNe {i} vt Γ Δ) → ∀ {t : Tm Γ τ} → SN t → SN (subst (theSubst σ) t)
substSN σ (ne t∈SNe) = ne (substSNe σ t∈SNe)
substSN σ (abs t∈SN) = abs (substSN (liftsSNe σ) t∈SN)
substSN σ (exp t→t' t'∈SN) = exp (subst⇒ σ t→t') (substSN σ t'∈SN)
-- SN is closed under renaming.
renSN : ∀{Γ Δ} (ρ : Γ ≤ Δ) → RenSN Δ Γ
renSN ρ = (ρ , λ x → var (ρ x))
renameSNe : ∀{a Γ Δ} (ρ : Γ ≤ Δ) {t : Tm Δ a} →
SNe t → SNe (rename ρ t)
renameSNe ρ = substSNe (renSN ρ)
renameSN : ∀{a Γ Δ} (ρ : Γ ≤ Δ) {t : Tm Δ a} →
SN t → SN (rename ρ t)
renameSN ρ = substSN (renSN ρ)
-- Variables are SN.
varSN : ∀{Γ a x} → var x ∈ SN {Γ = Γ} {a}
varSN = ne (var _)
-- SN is closed under application to variables.
appVarSN : ∀{Γ a b}{t : Tm Γ (a →̂ b)}{x} → t ∈ SN → app t (var x) ∈ SN
appVarSN (ne t∈SNe) = ne (elim t∈SNe (appl varSN))
appVarSN (abs t∈SN) = exp (β varSN) (substSN (sgs-varSNe _) t∈SN)
appVarSN (exp t→t' t'∈SN) = exp (cong (appl (var _)) (appl (var _)) t→t') (appVarSN t'∈SN)
-- Subterm properties of SN
-- If app t u ∈ SN then u ∈ SN.
apprSN : ∀{i a b Γ}{t : Tm Γ (a →̂ b)}{u : Tm Γ a} → SN {i} (app t u) → SN {i} u
apprSN (ne (elim 𝒏 (appl 𝒖))) = 𝒖
apprSN (exp (β 𝒖) 𝒕) = 𝒖
apprSN (exp (cong (appl u) (appl .u) t⇒) 𝒕) = apprSN 𝒕
|
{
"alphanum_fraction": 0.4610113745,
"avg_line_length": 33.4724770642,
"ext": "agda",
"hexsha": "6cc6abff11b1c7cf168da5b3e2b24a7d35cd791c",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2018-02-23T18:22:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-11-10T16:44:52.000Z",
"max_forks_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "ryanakca/strong-normalization",
"max_forks_repo_path": "agda-aplas14/SN.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_issues_repo_issues_event_max_datetime": "2018-02-20T14:54:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-02-14T16:42:36.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "ryanakca/strong-normalization",
"max_issues_repo_path": "agda-aplas14/SN.agda",
"max_line_length": 134,
"max_stars_count": 32,
"max_stars_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "ryanakca/strong-normalization",
"max_stars_repo_path": "agda-aplas14/SN.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-05T12:12:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-22T14:33:27.000Z",
"num_tokens": 3309,
"size": 7297
}
|
-- This module is used to illustrate how to import a parameterised module.
module examples.syntax.ModuleB
(A : Set)
((==) : A -> A -> Prop)
(refl : (x : A) -> x == x)
where
infix 5 /\
module SubModule where
postulate dummy : A
data True : Prop where
tt : True
data False : Prop where
data (/\) (P, Q : Prop) : Prop where
andI : P -> Q -> P /\ Q
data List : Set where
nil : List
cons : A -> List -> List
eqList : List -> List -> Prop
eqList nil nil = True
eqList (cons x xs) nil = False
eqList nil (cons y ys) = False
eqList (cons x xs) (cons y ys) = x == y /\ eqList xs ys
reflEqList : (xs : List) -> eqList xs xs
reflEqList nil = tt
reflEqList (cons x xs) = andI (refl x) (reflEqList xs)
|
{
"alphanum_fraction": 0.5561160151,
"avg_line_length": 22.0277777778,
"ext": "agda",
"hexsha": "73af9221e18dc0c4eaedfcb0c5fb943a65db9e05",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/syntax/ModuleB.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/syntax/ModuleB.agda",
"max_line_length": 74,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/syntax/ModuleB.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": 269,
"size": 793
}
|
module NatEquality where
open import Definitions
_≟_ : (m n : ℕ) → Equal? m n
_≟_ = {!!}
equality-disjoint : (m n : ℕ) → m ≡ n → m ≢ n → ⊥
equality-disjoint = {!!}
|
{
"alphanum_fraction": 0.5714285714,
"avg_line_length": 15.2727272727,
"ext": "agda",
"hexsha": "558477a473d9465fd8e392fbd5d0a62fa1db15d6",
"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": "ece25bed081a24f02e9f85056d05933eae2afabf",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "danr/agder",
"max_forks_repo_path": "problems/NatEquality/NatEquality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ece25bed081a24f02e9f85056d05933eae2afabf",
"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": "danr/agder",
"max_issues_repo_path": "problems/NatEquality/NatEquality.agda",
"max_line_length": 49,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ece25bed081a24f02e9f85056d05933eae2afabf",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "danr/agder",
"max_stars_repo_path": "problems/NatEquality/NatEquality.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-17T12:07:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-17T12:07:03.000Z",
"num_tokens": 63,
"size": 168
}
|
------------------------------------------------------------------------
-- This module proves that the parser combinators correspond exactly
-- to functions of type List Tok → List R (if bag equality is used for
-- the lists of results)
------------------------------------------------------------------------
module TotalParserCombinators.ExpressiveStrength where
open import Codata.Musical.Notation
open import Data.Bool
open import Data.List as List
open import Data.List.Membership.Propositional
import Data.List.Properties as ListProp
open import Data.List.Relation.Binary.BagAndSetEquality
open import Data.List.Relation.Unary.Any
open import Data.List.Reverse
open import Data.Product
open import Function.Base
open import Function.Inverse using (_↔_)
import Function.Related as Related
open import Relation.Binary.PropositionalEquality as P
using (_≡_; refl)
open import Relation.Binary.HeterogeneousEquality
using (_≅_; _≇_; refl)
open import Relation.Nullary
open Related using (SK-sym)
open import TotalParserCombinators.Parser
open import TotalParserCombinators.Semantics as S
hiding (_≅_; _∼[_]_; token)
open import TotalParserCombinators.Lib
private
open module Tok = Token Bool _≟_ using (tok)
open import TotalParserCombinators.BreadthFirst as Backend
using (parse)
------------------------------------------------------------------------
-- Expressive strength
-- One direction of the correspondence has already been established:
-- For every parser there is an equivalent function.
parser⇒fun : ∀ {R xs} (p : Parser Bool R xs) {x s} →
x ∈ p · s ↔ x ∈ parse p s
parser⇒fun p = Backend.parse-correct
-- For every function there is a corresponding parser.
module Monadic where
-- The parser.
grammar : ∀ {Tok R} (f : List Tok → List R) → Parser Tok R (f [])
grammar f = token >>= (λ t → ♯ grammar (f ∘ _∷_ t))
∣ return⋆ (f [])
-- Correctness proof.
grammar-correct : ∀ {Tok R} (f : List Tok → List R) {x s} →
x ∈ grammar f · s ↔ x ∈ f s
grammar-correct f {s = s} = record
{ to = P.→-to-⟶ (sound f)
; from = P.→-to-⟶ (complete f s)
; inverse-of = record
{ left-inverse-of = complete∘sound f
; right-inverse-of = sound∘complete f s
}
}
where
sound : ∀ {Tok R x s} (f : List Tok → List R) →
x ∈ grammar f · s → x ∈ f s
sound f (∣-right ._ x∈) with Return⋆.sound (f []) x∈
... | (refl , x∈′) = x∈′
sound f (∣-left (S.token {t} >>= x∈)) = sound (f ∘ _∷_ t) x∈
complete : ∀ {Tok R x} (f : List Tok → List R) s →
x ∈ f s → x ∈ grammar f · s
complete f [] x∈ = ∣-right [] (Return⋆.complete x∈)
complete f (t ∷ s) x∈ =
∣-left ([ ○ - ◌ ] S.token >>= complete (f ∘ _∷_ t) s x∈)
complete∘sound : ∀ {Tok R x s} (f : List Tok → List R)
(x∈pf : x ∈ grammar f · s) →
complete f s (sound f x∈pf) ≡ x∈pf
complete∘sound f (∣-left (S.token {t} >>= x∈))
rewrite complete∘sound (f ∘ _∷_ t) x∈ = refl
complete∘sound f (∣-right .[] x∈)
with Return⋆.sound (f []) x∈ | Return⋆.complete∘sound (f []) x∈
complete∘sound f (∣-right .[] .(Return⋆.complete x∈f[]))
| (refl , x∈f[]) | refl = refl
sound∘complete : ∀ {Tok R x} (f : List Tok → List R) s
(x∈fs : x ∈ f s) →
sound f (complete f s x∈fs) ≡ x∈fs
sound∘complete f (t ∷ s) x∈ = sound∘complete (f ∘ _∷_ t) s x∈
sound∘complete {Tok} f [] x∈
with Return⋆.sound {Tok = Tok} (f []) (Return⋆.complete x∈)
| Return⋆.sound∘complete {Tok = Tok} x∈
... | (refl , .x∈) | refl = refl
-- A corollary.
maximally-expressive :
∀ {Tok R} (f : List Tok → List R) {s} →
parse (grammar f) s ∼[ bag ] f s
maximally-expressive f {s} {x} =
(x ∈ parse (grammar f) s) ↔⟨ SK-sym Backend.parse-correct ⟩
x ∈ grammar f · s ↔⟨ grammar-correct f ⟩
x ∈ f s ∎
where open Related.EquationalReasoning
-- If the token type is finite (in this case Bool), then the result
-- above can be established without the use of bind (_>>=_). (The
-- definition of tok uses bind, but if bind were removed it would be
-- reasonable to either add tok as a primitive combinator, or make it
-- possible to define tok using other combinators.)
module Applicative where
-- A helper function.
specialise : {A B : Set} → (List A → B) → A → (List A → B)
specialise f x = λ xs → f (xs ∷ʳ x)
-- The parser.
grammar : ∀ {R} (f : List Bool → List R) → Parser Bool R (f [])
grammar f =
♯ (const <$> grammar (specialise f true )) ⊛ tok true
∣ ♯ (const <$> grammar (specialise f false)) ⊛ tok false
∣ return⋆ (f [])
-- Correctness proof.
grammar-correct : ∀ {R} (f : List Bool → List R) {x s} →
x ∈ grammar f · s ↔ x ∈ f s
grammar-correct {R} f {s = s} = record
{ to = P.→-to-⟶ (sound f)
; from = P.→-to-⟶ (complete f (reverseView s))
; inverse-of = record
{ right-inverse-of = sound∘complete f (reverseView s)
; left-inverse-of = λ x∈ →
complete∘sound f (reverseView s) _ x∈ refl refl
}
}
where
sound : ∀ {x : R} {s} f → x ∈ grammar f · s → x ∈ f s
sound f (∣-right ._ x∈) with Return⋆.sound (f []) x∈
... | (refl , x∈′) = x∈′
sound f (∣-left (∣-left (<$> x∈ ⊛ t∈))) with Tok.sound true t∈
... | (refl , refl) = sound (specialise f true ) x∈
sound f (∣-left (∣-right ._ (<$> x∈ ⊛ t∈))) with Tok.sound false t∈
... | (refl , refl) = sound (specialise f false) x∈
complete : ∀ {x : R} {s} f → Reverse s →
x ∈ f s → x ∈ grammar f · s
complete f [] x∈ = ∣-right [] (Return⋆.complete x∈)
complete f (bs ∶ rs ∶ʳ true ) x∈ =
∣-left {xs₁ = []} (∣-left (
[ ◌ - ○ ] <$> complete (specialise f true ) rs x∈ ⊛ Tok.complete))
complete f (bs ∶ rs ∶ʳ false) x∈ =
∣-left (∣-right [] (
[ ◌ - ○ ] <$> complete (specialise f false) rs x∈ ⊛ Tok.complete))
sound∘complete : ∀ {x : R} {s} f (rs : Reverse s) (x∈fs : x ∈ f s) →
sound f (complete f rs x∈fs) ≡ x∈fs
sound∘complete f [] x∈
rewrite Return⋆.sound∘complete {Tok = Bool} x∈ = refl
sound∘complete f (bs ∶ rs ∶ʳ true) x∈ =
sound∘complete (specialise f true) rs x∈
sound∘complete f (bs ∶ rs ∶ʳ false) x∈ =
sound∘complete (specialise f false) rs x∈
complete∘sound : ∀ {x : R} {s s′ : List Bool}
f (rs : Reverse s) (rs′ : Reverse s′)
(x∈pf : x ∈ grammar f · s) → s ≡ s′ → rs ≅ rs′ →
complete f rs (sound f x∈pf) ≡ x∈pf
complete∘sound f rs rs′ (∣-right ._ x∈) s≡ rs≅
with Return⋆.sound (f []) x∈
| Return⋆.complete∘sound (f []) x∈
complete∘sound f ._ [] (∣-right ._ .(Return⋆.complete x∈′)) refl refl | (refl , x∈′) | refl = refl
complete∘sound f _ ([] ∶ _ ∶ʳ _) (∣-right ._ .(Return⋆.complete x∈′)) () _ | (refl , x∈′) | refl
complete∘sound f _ ((_ ∷ _) ∶ _ ∶ʳ _) (∣-right ._ .(Return⋆.complete x∈′)) () _ | (refl , x∈′) | refl
complete∘sound f rs rs′ (∣-left (∣-left (<$> x∈ ⊛ t∈))) s≡ rs≅ with Tok.sound true t∈
complete∘sound f rs (bs′ ∶ rs′ ∶ʳ true) (∣-left (∣-left (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl)
with proj₁ $ ListProp.∷ʳ-injective bs bs′ s≡
complete∘sound f rs (.bs ∶ rs′ ∶ʳ true) (∣-left (∣-left (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) | refl with s≡ | rs≅
complete∘sound f ._ (.bs ∶ rs′ ∶ʳ true) (∣-left (∣-left (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) | refl | refl | refl
rewrite complete∘sound (specialise f true) rs′ rs′ x∈ refl refl
| Tok.η t∈ = refl
complete∘sound f rs (bs′ ∶ rs′ ∶ʳ false) (∣-left (∣-left (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl)
with proj₂ $ ListProp.∷ʳ-injective bs bs′ s≡
... | ()
complete∘sound f rs [] (∣-left (∣-left (_⊛_ {s₁ = []} (<$> x∈) t∈))) () _ | (refl , refl)
complete∘sound f rs [] (∣-left (∣-left (_⊛_ {s₁ = _ ∷ _} (<$> x∈) t∈))) () _ | (refl , refl)
complete∘sound f rs rs′ (∣-left (∣-right ._ (<$> x∈ ⊛ t∈))) s≡ rs≅ with Tok.sound false t∈
complete∘sound f rs (bs′ ∶ rs′ ∶ʳ false) (∣-left (∣-right ._ (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl)
with proj₁ $ ListProp.∷ʳ-injective bs bs′ s≡
complete∘sound f rs (.bs ∶ rs′ ∶ʳ false) (∣-left (∣-right ._ (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) | refl with s≡ | rs≅
complete∘sound f ._ (.bs ∶ rs′ ∶ʳ false) (∣-left (∣-right ._ (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) | refl | refl | refl
rewrite complete∘sound (specialise f false) rs′ rs′ x∈ refl refl
| Tok.η t∈ = refl
complete∘sound f rs (bs′ ∶ rs′ ∶ʳ true) (∣-left (∣-right ._ (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl)
with proj₂ $ ListProp.∷ʳ-injective bs bs′ s≡
... | ()
complete∘sound f rs [] (∣-left (∣-right ._ (_⊛_ {s₁ = []} (<$> x∈) t∈))) () _ | (refl , refl)
complete∘sound f rs [] (∣-left (∣-right ._ (_⊛_ {s₁ = _ ∷ _} (<$> x∈) t∈))) () _ | (refl , refl)
-- A corollary.
maximally-expressive :
∀ {R} (f : List Bool → List R) {s} →
parse (grammar f) s ∼[ bag ] f s
maximally-expressive f {s} {x} =
(x ∈ parse (grammar f) s) ↔⟨ SK-sym Backend.parse-correct ⟩
x ∈ grammar f · s ↔⟨ grammar-correct f ⟩
x ∈ f s ∎
where open Related.EquationalReasoning
|
{
"alphanum_fraction": 0.5215181997,
"avg_line_length": 43.2421524664,
"ext": "agda",
"hexsha": "83244cca5b8935c4ec0ba128bc478b250d92b59a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "TotalParserCombinators/ExpressiveStrength.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "TotalParserCombinators/ExpressiveStrength.agda",
"max_line_length": 138,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "TotalParserCombinators/ExpressiveStrength.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 3558,
"size": 9643
}
|
module Everything where
import Records
import Basics
import Modules
import With
import Families
import Datatypes
import Bool
import Naturals
|
{
"alphanum_fraction": 0.8591549296,
"avg_line_length": 12.9090909091,
"ext": "agda",
"hexsha": "89a26925b516bdfa337f972afd573e2a59649291",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/AIM6/HelloAgda/Everything.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/AIM6/HelloAgda/Everything.agda",
"max_line_length": 23,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/AIM6/HelloAgda/Everything.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": 30,
"size": 142
}
|
------------------------------------------------------------------------
-- Definitional interpreters can model systems with bounded space
------------------------------------------------------------------------
-- In "Reasoning on Divergent Computations with Coaxioms" Ancona,
-- Dagnino and Zucca write the following:
--
-- "To assess the applicability and generality of our approach much
-- work is still needed. We are currently considering to apply
-- coaxioms to other kinds of semantics; in particular, trace
-- semantics seems particularly interesting for investigating
-- whether our approach is suitable for formalizing and proving
-- important safety properties of non terminating programs, as
-- ensuring that a server will never try to use infinite resources.
-- Other approaches based on definitional interpreters [Danielsson
-- 2012], and the adoption of step counters [Amin and Rompf 2017;
-- Ancona 2014; Ernst et al. 2006; Owens et al. 2016] seem to be
-- appealing for proving type soundness properties with big-step
-- semantics, and other results concerning program equivalence;
-- however, it is not clear whether these solutions work well for
-- other kinds of properties. For instance, if a program consists of
-- an infinite loop that allocates new heap space at each step
-- without releasing it, one would like to conclude that it will
-- eventually crash even though a definitional interpreter returns
-- timeout for all possible values of the step counter."
--
-- This is an attempt to show that definitional interpreters can
-- handle this situation.
module Bounded-space where
open import Equality.Propositional
open import Prelude
open import Tactic.By.Propositional
open import Prelude.Size
open import Colist equality-with-J
open import Nat equality-with-J
open import Delay-monad
open import Delay-monad.Bisimilarity as B
hiding (reflexive; symmetric)
open import Only-allocation
------------------------------------------------------------------------
-- Heaps
-- Bounded heaps. (Only a size, plus a proof showing that the size is
-- bounded.)
record Heap (limit : ℕ) : Type where
field
size : ℕ
bound : size ≤ limit
open Heap public
-- An empty heap.
empty : ∀ {l} → Heap l
empty = record { size = zero; bound = zero≤ _ }
-- A full heap.
full : ∀ l → Heap l
full l = record { size = l; bound = ≤-refl }
-- Reduces the heap's size by one. If the heap is empty, then it is
-- returned unchanged.
shrink : ∀ {l} → Heap l → Heap l
shrink {l} h = record
{ size = pred (h .size)
; bound = pred (h .size) ≤⟨ pred≤ _ ⟩
h .size ≤⟨ h .bound ⟩∎
l ∎≤
}
-- Increases the heap's size by one. If the heap already has the
-- maximum size, then nothing is returned.
grow : ∀ {l} → Heap l → Maybe (Heap l)
grow {l} h with l ≤⊎> h .size
... | inj₁ _ = nothing
... | inj₂ h<l = just (record { size = suc (h .size)
; bound = h<l
})
-- Lemmas related to grow.
grow-full :
∀ {l} (h : Heap l) → h .size ≡ l → grow h ≡ nothing
grow-full {l} h h≡l with l ≤⊎> h .size
... | inj₁ _ = refl
... | inj₂ h<l =
⊥-elim (+≮ 0 (
1 + h .size ≤⟨ h<l ⟩
l ≡⟨ sym h≡l ⟩≤
h .size ∎≤))
grow-not-full :
∀ {l} (h : Heap l) →
h .size < l → ∃ λ h′ → grow h ≡ just h′ × h′ .size ≡ 1 + h .size
grow-not-full {l} h h<l with l ≤⊎> h .size
... | inj₂ _ = _ , refl , refl
... | inj₁ l≤h =
⊥-elim (+≮ 0 (
1 + h .size ≤⟨ h<l ⟩
l ≤⟨ l≤h ⟩∎
h .size ∎≤))
------------------------------------------------------------------------
-- Definitional interpreter
-- One step of computation.
step : ∀ {l} → Stmt → Heap l → Maybe (Heap l)
step dealloc heap = just (shrink heap)
step alloc heap = grow heap
-- A crashing computation.
crash : ∀ {i l} → Delay (Maybe (Heap l)) i
crash = now nothing
-- A definitional interpreter.
⟦_⟧ : ∀ {i l} → Program i → Heap l → Delay (Maybe (Heap l)) i
⟦ [] ⟧ heap = now (just heap)
⟦ s ∷ p ⟧ heap with step s heap
... | nothing = crash
... | just new-heap = later λ { .force → ⟦ p .force ⟧ new-heap }
------------------------------------------------------------------------
-- A program equivalence
-- An equivalence relation that identifies programs that, given a
-- sufficient amount of memory, behave identically (up to weak
-- bisimilarity).
infix 4 [_]_≃_ [_]_≃′_
[_]_≃_ : Size → Program ∞ → Program ∞ → Type
[ i ] p ≃ q =
∃ λ c →
∀ l (h : Heap l) →
c + h .size ≤ l →
[ i ] ⟦ p ⟧ h ≈ ⟦ q ⟧ h
[_]_≃′_ : Size → Program ∞ → Program ∞ → Type
[ i ] p ≃′ q =
∃ λ c →
∀ l (h : Heap l) →
c + h .size ≤ l →
[ i ] ⟦ p ⟧ h ≈′ ⟦ q ⟧ h
-- The relation is an equivalence relation.
reflexive : ∀ {i} p → [ i ] p ≃ p
reflexive _ = 0 , λ _ _ _ → B.reflexive _
symmetric : ∀ {i p q} → [ i ] p ≃ q → [ i ] q ≃ p
symmetric = Σ-map id λ hyp l h c → B.symmetric (hyp l h c)
transitive : ∀ {i p q r} → [ ∞ ] p ≃ q → [ ∞ ] q ≃ r → [ i ] p ≃ r
transitive {p = p} {q} {r} (c₁ , p₁) (c₂ , p₂) =
max c₁ c₂ , λ l h c →
⟦ p ⟧ h ≈⟨ p₁ l h (lemma₁ l h c) ⟩
⟦ q ⟧ h ≈⟨ p₂ l h (lemma₂ l h c) ⟩∎
⟦ r ⟧ h ∎
where
lemma₁ = λ l h c →
c₁ + h .size ≤⟨ ˡ≤max c₁ _ +-mono ≤-refl ⟩
max c₁ c₂ + h .size ≤⟨ c ⟩∎
l ∎≤
lemma₂ = λ l h c →
c₂ + h .size ≤⟨ ʳ≤max c₁ _ +-mono ≤-refl ⟩
max c₁ c₂ + h .size ≤⟨ c ⟩∎
l ∎≤
-- The relation is compatible with respect to the program formers.
[]-cong : ∀ {i} → [ i ] [] ≃ []
[]-cong = reflexive []
∷-cong : ∀ {s p q i} → [ i ] p .force ≃′ q .force → [ i ] s ∷ p ≃ s ∷ q
∷-cong {dealloc} (c , p≈q) =
c , λ l h c≤ → later λ { .force → p≈q l (shrink h) (
c + shrink h .size ≤⟨ ≤-refl {n = c} +-mono pred≤ _ ⟩
c + h .size ≤⟨ c≤ ⟩
l ∎≤) .force }
∷-cong {alloc} {p} {q} {i} (c , p≈q) = 1 + c , lemma
where
lemma : ∀ l (h : Heap l) → 1 + c + h .size ≤ l →
[ i ] ⟦ alloc ∷ p ⟧ h ≈ ⟦ alloc ∷ q ⟧ h
lemma l h 1+c≤ with l ≤⊎> h .size
... | inj₁ _ = now
... | inj₂ h<l = later λ { .force → p≈q l _ (
c + (1 + h .size) ≡⟨ +-assoc c ⟩≤
c + 1 + h .size ≡⟨ by (+-comm c) ⟩≤
1 + c + h .size ≤⟨ 1+c≤ ⟩∎
l ∎≤) .force }
------------------------------------------------------------------------
-- Some examples
-- The program bounded crashes when the heap is full.
bounded-crash :
∀ {i l} (h : Heap l) →
h .size ≡ l →
[ i ] ⟦ bounded ⟧ h ≈ crash
bounded-crash h h≡l
rewrite grow-full h h≡l =
now
-- However, for smaller heaps the program loops.
bounded-loop :
∀ {i l} (h : Heap l) →
h .size < l →
[ i ] ⟦ bounded ⟧ h ≈ never
bounded-loop {l = l} h <l
with grow h | grow-not-full h <l
... | .(just h′) | h′ , refl , refl =
later λ { .force →
later λ { .force →
bounded-loop _ <l }}
-- The program bounded₂ loops when there are at least two empty slots
-- in the heap.
bounded₂-loop :
∀ {i l} (h : Heap l) →
2 + h .size ≤ l →
[ i ] ⟦ bounded₂ ⟧ h ≈ never
bounded₂-loop {i} {l} h 2+h≤l
with grow h | grow-not-full h (<→≤ 2+h≤l)
... | .(just h′) | h′ , refl , refl = later λ { .force → lemma }
where
lemma : [ i ] ⟦ force (tail bounded₂) ⟧ h′ ≈ never
lemma with grow h′ | grow-not-full h′ 2+h≤l
lemma | .(just h″) | h″ , refl , refl =
later λ { .force →
later λ { .force →
later λ { .force →
bounded₂-loop _ 2+h≤l }}}
-- The program unbounded crashes for all heaps.
unbounded-crash :
∀ {i l} (h : Heap l) → [ i ] ⟦ unbounded ⟧ h ≈ crash
unbounded-crash {l = l} h = helper h (≤→≤↑ (h .bound))
where
helper :
∀ {i} (h′ : Heap l) → size h′ ≤↑ l →
[ i ] ⟦ unbounded ⟧ h′ ≈ crash
helper h′ (≤↑-refl h′≡l)
rewrite grow-full h′ h′≡l =
now
helper h′ (≤↑-step 1+h′≤l)
with grow h′ | grow-not-full h′ (≤↑→≤ 1+h′≤l)
... | .(just h″) | h″ , refl , refl =
laterˡ (helper h″ 1+h′≤l)
-- The programs bounded and bounded₂ are ≃-equivalent.
bounded≃bounded₂ : [ ∞ ] bounded ≃ bounded₂
bounded≃bounded₂ =
2 , λ l h 2+h≤l →
⟦ bounded ⟧ h ≈⟨ bounded-loop _ (<→≤ 2+h≤l) ⟩
never ≈⟨ B.symmetric (bounded₂-loop _ 2+h≤l) ⟩∎
⟦ bounded₂ ⟧ h ∎
-- The programs bounded and unbounded are not ≃-equivalent.
¬bounded≃unbounded :
¬ [ ∞ ] bounded ≃ unbounded
¬bounded≃unbounded (c , c≈u) = now≉never (
crash ≈⟨ B.symmetric (unbounded-crash h) ⟩
⟦ unbounded ⟧ h ≈⟨ B.symmetric (c≈u _ h (≤-refl +-mono zero≤ _)) ⟩
⟦ bounded ⟧ h ≈⟨ bounded-loop h (m≤n+m _ _) ⟩∎
never ∎)
where
h : Heap (c + 1)
h = record
{ size = 0
; bound = zero≤ _
}
|
{
"alphanum_fraction": 0.524788668,
"avg_line_length": 29.9794520548,
"ext": "agda",
"hexsha": "6c6dae1aed09304fecaf708082e4ba0db9aeb8f9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/definitional-interpreters",
"max_forks_repo_path": "src/Bounded-space.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/definitional-interpreters",
"max_issues_repo_path": "src/Bounded-space.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/definitional-interpreters",
"max_stars_repo_path": "src/Bounded-space.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3077,
"size": 8754
}
|
open import Coinduction using ( ♯_ ; ♭ )
open import Data.Strict using ( Strict ; ! )
open import Data.Natural using ( Natural ; # ; _+_ )
open import Data.Bool using ( Bool ; true ; false )
open import System.IO.Transducers.Session using ( I ; Σ ; ⟨_⟩ ; * ; _&*_ ; ¿ )
open import System.IO.Transducers.Lazy using ( _⇒_ ; inp ; out ; done )
open import System.IO.Transducers.Strict using ( _⇛_ )
module System.IO.Transducers.List where
-- Length of a list
length' : ∀ {T S} → (Strict Natural) → (T &* S) ⇛ ⟨ Natural ⟩
length' {I} {S} (! n) true = inp (♯ length' {S} {S} (! (n + # 1)))
length' {I} {S} (! n) false = out n done
length' {Σ V G} {S} (! n) b = inp (♯ length' {♭ G b} {S} (! n))
length : ∀ {S} → (* S) ⇛ ⟨ Natural ⟩
length {S} = length' {I} {S} (! (# 0))
-- Flatten a list of lists
mutual
concat' : ∀ {T S} → ((T &* S) &* * S) ⇛ (T &* S)
concat' {I} {S} true = out true (inp (♯ concat' {S} {S}))
concat' {I} {S} false = inp (♯ concat {S})
concat' {Σ W G} {S} a = out a (inp (♯ concat' {♭ G a} {S}))
concat : ∀ {S} → (* (* S)) ⇛ (* S)
concat {S} true = inp (♯ concat' {I} {S})
concat {S} false = out false done
-- Some inclusions, which coerce traces from one session to another.
-- TODO: Add more inclusions.
-- TODO: Prove that these are monomorphisms.
-- TODO: It would be nice if inclusions like this could be handled by subtyping.
S⊆S&*T : ∀ {S T} → S ⇒ S &* T
S⊆S&*T {I} = out false done
S⊆S&*T {Σ V F} = inp (♯ λ a → out a S⊆S&*T)
S⊆*S : ∀ {S} → S ⇒ * S
S⊆*S = out true S⊆S&*T
¿S⊆*S : ∀ {S} → ¿ S ⇛ * S
¿S⊆*S {S} true = out true (S⊆S&*T {S} {S})
¿S⊆*S {S} false = out false done
|
{
"alphanum_fraction": 0.5394816154,
"avg_line_length": 32.5294117647,
"ext": "agda",
"hexsha": "f09f4a57dbe030f06471f03529e766a08fb1d95b",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z",
"max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ilya-fiveisky/agda-system-io",
"max_forks_repo_path": "src/System/IO/Transducers/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ilya-fiveisky/agda-system-io",
"max_issues_repo_path": "src/System/IO/Transducers/List.agda",
"max_line_length": 80,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ilya-fiveisky/agda-system-io",
"max_stars_repo_path": "src/System/IO/Transducers/List.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z",
"num_tokens": 673,
"size": 1659
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category using (Category)
open import Categories.Category.Monoidal using (Monoidal)
module Categories.Category.Monoidal.Reasoning {o ℓ e} {C : Category o ℓ e} (M : Monoidal C) where
open import Data.Product using (_,_)
open import Categories.Functor renaming (id to idF)
private
module C = Category C
open C hiding (id; identityˡ; identityʳ; assoc)
private
variable
X Y : Obj
f g h i : X ⇒ Y
open Monoidal M using (_⊗₁_; ⊗)
open Functor ⊗ using (F-resp-≈; homomorphism)
open HomReasoning public
infixr 6 _⟩⊗⟨_ refl⟩⊗⟨_
infixl 7 _⟩⊗⟨refl
⊗-resp-≈ : f ≈ h → g ≈ i → (f ⊗₁ g) ≈ (h ⊗₁ i)
⊗-resp-≈ p q = F-resp-≈ (p , q)
⊗-resp-≈ˡ : f ≈ h → (f ⊗₁ g) ≈ (h ⊗₁ g)
⊗-resp-≈ˡ p = ⊗-resp-≈ p Equiv.refl
⊗-resp-≈ʳ : g ≈ i → (f ⊗₁ g) ≈ (f ⊗₁ i)
⊗-resp-≈ʳ p = ⊗-resp-≈ Equiv.refl p
_⟩⊗⟨_ : f ≈ h → g ≈ i → (f ⊗₁ g) ≈ (h ⊗₁ i)
_⟩⊗⟨_ = ⊗-resp-≈
refl⟩⊗⟨_ : g ≈ i → (f ⊗₁ g) ≈ (f ⊗₁ i)
refl⟩⊗⟨_ = ⊗-resp-≈ʳ
_⟩⊗⟨refl : f ≈ h → (f ⊗₁ g) ≈ (h ⊗₁ g)
_⟩⊗⟨refl = ⊗-resp-≈ˡ
-- removing the {_} makes the whole thing not type check anymore for some reason
-- an issue was raised on the main agda GitHub repository about this
-- (https://github.com/agda/agda/issues/4140)
-- if this is fixed feel free to remove the {_}
⊗-distrib-over-∘ : ((f ∘ h) ⊗₁ (g ∘ i)) ≈ ((f ⊗₁ g) ∘ (h ⊗₁ i))
⊗-distrib-over-∘ {_} = homomorphism
-- This also corresponds with the graphical coherence property of diagrams modelling monoidal categories:
-- | | | |
-- [h] [i] [h] [i]
-- | | ≈ | |
-- [f] [g] | |
-- | | | |
-- [f] [g]
-- | |
-- Parallel-to-serial conversions
--
-- | | | | | |
-- | | | [g] [f] |
-- [f] [g] = | | = | |
-- | | [f] | | [g]
-- | | | | | |
serialize₁₂ : ∀ {X₁ Y₁ X₂ Y₂} {f : X₁ ⇒ Y₁} {g : X₂ ⇒ Y₂} →
f ⊗₁ g ≈ f ⊗₁ C.id ∘ C.id ⊗₁ g
serialize₁₂ {f = f} {g} = begin
f ⊗₁ g ≈˘⟨ C.identityʳ ⟩⊗⟨ C.identityˡ ⟩
(f ∘ C.id) ⊗₁ (C.id ∘ g) ≈⟨ ⊗-distrib-over-∘ ⟩
f ⊗₁ C.id ∘ C.id ⊗₁ g ∎
serialize₂₁ : ∀ {X₁ Y₁ X₂ Y₂} {f : X₁ ⇒ Y₁} {g : X₂ ⇒ Y₂} →
f ⊗₁ g ≈ C.id ⊗₁ g ∘ f ⊗₁ C.id
serialize₂₁ {f = f} {g} = begin
f ⊗₁ g ≈˘⟨ C.identityˡ ⟩⊗⟨ C.identityʳ ⟩
(C.id ∘ f) ⊗₁ (g ∘ C.id) ≈⟨ ⊗-distrib-over-∘ ⟩
C.id ⊗₁ g ∘ f ⊗₁ C.id ∎
-- Split a composite in the first component
--
-- | | | | | |
-- [g] | [g] | [g] [h]
-- | [h] = | | = | |
-- [f] | [f] [h] [f] |
-- | | | | | |
split₁ʳ : ∀ {X₁ Y₁ Z₁ X₂ Y₂} {f : Y₁ ⇒ Z₁} {g : X₁ ⇒ Y₁} {h : X₂ ⇒ Y₂} →
(f ∘ g) ⊗₁ h ≈ f ⊗₁ h ∘ g ⊗₁ C.id
split₁ʳ {f = f} {g} {h} = begin
(f ∘ g) ⊗₁ h ≈˘⟨ refl⟩⊗⟨ C.identityʳ ⟩
(f ∘ g) ⊗₁ (h ∘ C.id) ≈⟨ ⊗-distrib-over-∘ ⟩
f ⊗₁ h ∘ g ⊗₁ C.id ∎
split₁ˡ : ∀ {X₁ Y₁ Z₁ X₂ Y₂} {f : Y₁ ⇒ Z₁} {g : X₁ ⇒ Y₁} {h : X₂ ⇒ Y₂} →
(f ∘ g) ⊗₁ h ≈ f ⊗₁ C.id ∘ g ⊗₁ h
split₁ˡ {f = f} {g} {h} = begin
(f ∘ g) ⊗₁ h ≈˘⟨ refl⟩⊗⟨ C.identityˡ ⟩
(f ∘ g) ⊗₁ (C.id ∘ h) ≈⟨ ⊗-distrib-over-∘ ⟩
f ⊗₁ C.id ∘ g ⊗₁ h ∎
-- Split a composite in the second component
--
-- | | | | | |
-- | [h] | [h] [f] [h]
-- [f] | = | | = | |
-- | [g] [f] [g] | [g]
-- | | | | | |
split₂ʳ : ∀ {X₁ Y₁ X₂ Y₂ Z₂} {f : X₁ ⇒ Y₁} {g : Y₂ ⇒ Z₂} {h : X₂ ⇒ Y₂} →
f ⊗₁ (g ∘ h) ≈ f ⊗₁ g ∘ C.id ⊗₁ h
split₂ʳ {f = f} {g} {h} = begin
f ⊗₁ (g ∘ h) ≈˘⟨ C.identityʳ ⟩⊗⟨refl ⟩
(f ∘ C.id) ⊗₁ (g ∘ h) ≈⟨ ⊗-distrib-over-∘ ⟩
f ⊗₁ g ∘ C.id ⊗₁ h ∎
split₂ˡ : ∀ {X₁ Y₁ X₂ Y₂ Z₂} {f : X₁ ⇒ Y₁} {g : Y₂ ⇒ Z₂} {h : X₂ ⇒ Y₂} →
f ⊗₁ (g ∘ h) ≈ C.id ⊗₁ g ∘ f ⊗₁ h
split₂ˡ {f = f} {g} {h} = begin
f ⊗₁ (g ∘ h) ≈˘⟨ C.identityˡ ⟩⊗⟨refl ⟩
(C.id ∘ f) ⊗₁ (g ∘ h) ≈⟨ ⊗-distrib-over-∘ ⟩
C.id ⊗₁ g ∘ f ⊗₁ h ∎
|
{
"alphanum_fraction": 0.4146942801,
"avg_line_length": 31.937007874,
"ext": "agda",
"hexsha": "af88d075a52cafe2c093d019beb9b69e9538b5fe",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Monoidal/Reasoning.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Monoidal/Reasoning.agda",
"max_line_length": 107,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Monoidal/Reasoning.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": 2033,
"size": 4056
}
|
-- Export only the experiments that are expected to compile (without
-- any holes)
{-# OPTIONS --cubical #-}
module Cubical.Experiments.Everything where
open import Cubical.Experiments.Brunerie public
open import Cubical.Experiments.Generic public
open import Cubical.Experiments.Problem
open import Cubical.Experiments.FunExtFromUA public
|
{
"alphanum_fraction": 0.8211143695,
"avg_line_length": 34.1,
"ext": "agda",
"hexsha": "42a85a3e4e853d3ed3d5d056f5d8e65c5783c01d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/Experiments/Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/Experiments/Everything.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/Experiments/Everything.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 76,
"size": 341
}
|
-- Andreas, 2017-09-16, issue #2759
-- Allow empty declaration blocks in the parser.
open import Agda.Builtin.Nat
x0 = zero
mutual
x1 = suc x0
abstract
x2 = suc x1
private
x3 = suc x2
instance
x4 = suc x3
macro
x5 = suc x4
postulate
x6 = suc x5
-- Expected: 6 warnings about empty blocks
mutual
postulate
-- Empty postulate block.
abstract private instance macro
-- Empty macro block.
-- Empty blocks are also tolerated in lets and lambdas.
_ = λ (let abstract ) → let abstract in Set
_ = λ (let field ) → let field in Set
_ = λ (let instance ) → let instance in Set
_ = λ (let macro ) → let macro in Set
_ = λ (let mutual ) → let mutual in Set
_ = λ (let postulate) → let postulate in Set
_ = λ (let private ) → let private in Set
|
{
"alphanum_fraction": 0.6740547588,
"avg_line_length": 19.175,
"ext": "agda",
"hexsha": "776f64b86ce3f153b1c8fa8f72a168bc2b200729",
"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/Issue2759.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/Issue2759.agda",
"max_line_length": 55,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2759.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": 243,
"size": 767
}
|
module plfa-code.Reasoning-legacy where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; trans)
infixr 2 _≡⟨_⟩_
infix 3 _∎
_≡⟨_⟩_ : ∀ {A : Set} (x : A) {y z : A}
→ x ≡ y
→ y ≡ z
-------
→ x ≡ z
x ≡⟨ x≡y ⟩ y≡z = trans x≡y y≡z
_∎ : ∀ {A : Set} (x : A)
------
→ x ≡ x
x ∎ = refl
|
{
"alphanum_fraction": 0.5,
"avg_line_length": 16.4,
"ext": "agda",
"hexsha": "31938b3085d821d10682e974e9ce965293cc10a5",
"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": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "chirsz-ever/plfa-code",
"max_forks_repo_path": "src/plfa-code/Reasoning-legacy.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"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": "chirsz-ever/plfa-code",
"max_issues_repo_path": "src/plfa-code/Reasoning-legacy.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "chirsz-ever/plfa-code",
"max_stars_repo_path": "src/plfa-code/Reasoning-legacy.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 163,
"size": 328
}
|
module Oscar.Property.Symmetry where
open import Oscar.Level
record Symmetry {𝔬} {⋆ : Set 𝔬} {𝔮} (_≒_ : ⋆ → ⋆ → Set 𝔮) : Set (𝔬 ⊔ 𝔮) where
field
symmetry : ∀ {x y} → x ≒ y → y ≒ x
open Symmetry ⦃ … ⦄ public
|
{
"alphanum_fraction": 0.5760368664,
"avg_line_length": 19.7272727273,
"ext": "agda",
"hexsha": "4c2663e0732aba96d9bb19bf2f54e7a52a118747",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Property/Symmetry.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Property/Symmetry.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Property/Symmetry.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 103,
"size": 217
}
|
-- Reported by Christian Sattler on 2019-12-7
postulate
A B : Set
barb : Set
barb = (A → (_ : B) → _) _
-- WAS: unsolved constraints.
-- SHOULD: throw an error that A → ... is not a function.
|
{
"alphanum_fraction": 0.6294416244,
"avg_line_length": 17.9090909091,
"ext": "agda",
"hexsha": "6d90f58eb7301abafb34df22ba7e65e0bb34072a",
"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/Issue4268.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/Issue4268.agda",
"max_line_length": 57,
"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/Issue4268.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": 65,
"size": 197
}
|
{-# OPTIONS --type-in-type #-}
data IBool : Set where
itrue ifalse : IBool
Bool : Set; Bool
= (B : Set) → B → B → B
toIBool : Bool → IBool
toIBool b = b _ itrue ifalse
true : Bool; true
= λ B t f → t
and : Bool → Bool → Bool; and
= λ a b B t f → a B (b B t f) f
Nat : Set; Nat
= (n : Set) → (n → n) → n → n
add : Nat → Nat → Nat; add
= λ a b n s z → a n s (b n s z)
mul : Nat → Nat → Nat; mul
= λ a b n s → a n (b n s)
suc : Nat → Nat; suc
= λ a n s z → s (a n s z)
Eq : {A : Set} → A → A → Set
Eq {A} x y = (P : A → Set) → P x → P y
refl : {A : Set}{x : A} → Eq {A} x x; refl
= λ P px → px
n2 : Nat; n2 = λ N s z → s (s z)
n3 : Nat; n3 = λ N s z → s (s (s z))
n4 : Nat; n4 = λ N s z → s (s (s (s z)))
n5 : Nat; n5 = λ N s z → s (s (s (s (s z))))
n10 = mul n2 n5
n10b = mul n5 n2
n15 = add n10 n5
n15b = add n10b n5
n18 = add n15 n3
n18b = add n15b n3
n19 = add n15 n4
n19b = add n15b n4
n20 = mul n2 n10
n20b = mul n2 n10b
n21 = suc n20
n21b = suc n20b
n22 = suc n21
n22b = suc n21b
n23 = suc n22
n23b = suc n22b
n100 = mul n10 n10
n100b = mul n10b n10b
n10k = mul n100 n100
n10kb = mul n100b n100b
n100k = mul n10k n10
n100kb = mul n10kb n10b
n1M = mul n10k n100
n1Mb = mul n10kb n100b
n5M = mul n1M n5
n5Mb = mul n1Mb n5
n10M = mul n5M n2
n10Mb = mul n5Mb n2
Tree : Set; Tree = (T : Set) → (T → T → T) → T → T
leaf : Tree; leaf = λ T n l → l
node : Tree → Tree → Tree; node = λ t1 t2 T n l → n (t1 T n l) (t2 T n l)
fullTree : Nat → Tree; fullTree
= λ n → n Tree (λ t → node t t) leaf
-- full tree with given trees at bottom level
fullTreeWithLeaf : Tree → Nat → Tree; fullTreeWithLeaf
= λ bottom n → n Tree (λ t → node t t) bottom
forceTree : Tree → Bool; forceTree
= λ t → t Bool and true
t15 = fullTree n15
t15b = fullTree n15b
t18 = fullTree n18
t18b = fullTree n18b
t19 = fullTree n19
t19b = fullTree n19b
t20 = fullTree n20
t20b = fullTree n20b
t21 = fullTree n21
t21b = fullTree n21b
t22 = fullTree n22
t22b = fullTree n22b
t23 = fullTree n23
t23b = fullTree n23b
-- Nat conversion
--------------------------------------------------------------------------------
-- convn1M : Eq n1M n1Mb; convn1M = refl
-- convn5M : Eq n5M n5Mb; convn5M = refl
-- convn10M : Eq n10M n10Mb; convn10M = refl
-- Full tree conversion
--------------------------------------------------------------------------------
-- convt15 : Eq t15 t15b; convt15 = refl -- 16 ms
-- convt18 : Eq t18 t18b; convt18 = refl -- 20 ms
-- convt19 : Eq t19 t19b; convt19 = refl -- 30 ms
-- convt20 : Eq t20 t20b; convt20 = refl -- 1.7 s
-- convt21 : Eq t21 t21b; convt21 = refl -- 3.4 s
-- convt22 : Eq t22 t22b; convt22 = refl -- 6.6 s
-- convt23 : Eq t23 t23b; convt23 = refl -- 13.1 s
-- Full meta-containing tree conversion
--------------------------------------------------------------------------------
-- convmt15 : Eq t15b (fullTreeWithLeaf _ n15 ); convmt15 = refl --
-- convmt18 : Eq t18b (fullTreeWithLeaf _ n18 ); convmt18 = refl --
-- convmt19 : Eq t19b (fullTreeWithLeaf _ n19 ); convmt19 = refl --
-- convmt20 : Eq t20b (fullTreeWithLeaf _ n20 ); convmt20 = refl --
-- convmt21 : Eq t21b (fullTreeWithLeaf _ n21 ); convmt21 = refl
-- convmt22 : Eq t22b (fullTreeWithLeaf _ n22 ); convmt22 = refl
-- convmt23 : Eq t23b (fullTreeWithLeaf _ n23 ); convmt23 = refl
-- Full tree forcing
--------------------------------------------------------------------------------
-- forcet15 : Eq (toIBool (forceTree t15)) itrue; forcet15 = refl -- 50 ms
-- forcet18 : Eq (toIBool (forceTree t18)) itrue; forcet18 = refl -- 450 ms
-- forcet19 : Eq (toIBool (forceTree t19)) itrue; forcet19 = refl -- 900 ms
-- forcet20 : Eq (toIBool (forceTree t20)) itrue; forcet20 = refl -- 1.75 s
-- forcet21 : Eq (toIBool (forceTree t21)) itrue; forcet21 = refl -- 3.5 s
-- forcet22 : Eq (toIBool (forceTree t22)) itrue; forcet22 = refl -- 7.5 s
-- forcet23 : Eq (toIBool (forceTree t23)) itrue; forcet23 = refl -- 15 s
|
{
"alphanum_fraction": 0.5542857143,
"avg_line_length": 29.3795620438,
"ext": "agda",
"hexsha": "44e434184168326d20ef6e47cb8bda38e330ae19",
"lang": "Agda",
"max_forks_count": 19,
"max_forks_repo_forks_event_max_datetime": "2022-03-03T19:46:54.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-05T21:11:34.000Z",
"max_forks_repo_head_hexsha": "6a87f295148bd753d2519d50c2e1011b64c859ff",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "int-index/smalltt",
"max_forks_repo_path": "bench/conv_eval.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "6a87f295148bd753d2519d50c2e1011b64c859ff",
"max_issues_repo_issues_event_max_datetime": "2022-02-28T21:51:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-16T09:14:57.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "int-index/smalltt",
"max_issues_repo_path": "bench/conv_eval.agda",
"max_line_length": 80,
"max_stars_count": 377,
"max_stars_repo_head_hexsha": "6a87f295148bd753d2519d50c2e1011b64c859ff",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "int-index/smalltt",
"max_stars_repo_path": "bench/conv_eval.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T21:31:01.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-26T16:57:16.000Z",
"num_tokens": 1624,
"size": 4025
}
|
{-# OPTIONS --without-K --safe #-}
module Data.Binary.Proofs where
open import Data.Binary.Proofs.Multiplication using (*-homo)
open import Data.Binary.Proofs.Addition using (+-homo)
open import Data.Binary.Proofs.Unary using (inc-homo)
open import Data.Binary.Proofs.Bijection using (𝔹↔ℕ)
|
{
"alphanum_fraction": 0.7147435897,
"avg_line_length": 34.6666666667,
"ext": "agda",
"hexsha": "2f8a98ee76fefb80066a50ca9a9e97c7b69d0414",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-binary",
"max_forks_repo_path": "Data/Binary/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-binary",
"max_issues_repo_path": "Data/Binary/Proofs.agda",
"max_line_length": 62,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-binary",
"max_stars_repo_path": "Data/Binary/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-21T21:30:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-21T21:30:10.000Z",
"num_tokens": 80,
"size": 312
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Functions
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Numbers.Naturals.Semiring
open import Sets.FinSet
open import Groups.Groups
open import Groups.Definition
open import Sets.EquivalenceRelations
open import Setoids.Functions.Extension
open import Groups.SymmetricGroups.Definition
module Groups.SymmetricGroups.Finite.Definition where
snSet : (n : ℕ) → Set
snSet n = SymmetryGroupElements (reflSetoid (FinSet n))
snSetoid : (n : ℕ) → Setoid (snSet n)
snSetoid n = symmetricSetoid (reflSetoid (FinSet n))
SymmetricGroupN : (n : ℕ) → Group (snSetoid n) (symmetricGroupOp)
SymmetricGroupN n = symmetricGroup (reflSetoid (FinSet n))
record Cycles {n : ℕ} (s : snSet n) : Set where
field
cycles : {n : ℕ} → (s : snSet n) → Cycles s
cycles s = {!!}
|
{
"alphanum_fraction": 0.7461368653,
"avg_line_length": 28.3125,
"ext": "agda",
"hexsha": "d881a649932b0f9fe76cfa00e91fa3e4314da30c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/SymmetricGroups/Finite/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/SymmetricGroups/Finite/Definition.agda",
"max_line_length": 65,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/SymmetricGroups/Finite/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 267,
"size": 906
}
|
open import SOAS.Common
import SOAS.Families.Core
-- Families with syntactic structure
module SOAS.Metatheory.MetaAlgebra {T : Set}
(open SOAS.Families.Core {T})
(⅀F : Functor 𝔽amiliesₛ 𝔽amiliesₛ)
(𝔛 : Familyₛ) where
open import SOAS.Context {T}
open import SOAS.Variable {T}
open import SOAS.Construction.Structure as Structure
open import SOAS.Abstract.Hom {T}
import SOAS.Abstract.Coalgebra {T} as →□ ; open →□.Sorted
open import SOAS.Metatheory.Algebra ⅀F
private
variable
Γ Δ Π : Ctx
α : T
-- A family with support for variables, metavariables, and ⅀-algebra structure
record MetaAlg (𝒜 : Familyₛ) : Set where
field
𝑎𝑙𝑔 : ⅀ 𝒜 ⇾̣ 𝒜
𝑣𝑎𝑟 : ℐ ⇾̣ 𝒜
𝑚𝑣𝑎𝑟 : 𝔛 ⇾̣ 〖 𝒜 , 𝒜 〗
-- Congruence in metavariable arguments
𝑚≈₁ : {𝔪₁ 𝔪₂ : 𝔛 α Π}{σ : Π ~[ 𝒜 ]↝ Γ}
→ 𝔪₁ ≡ 𝔪₂
→ 𝑚𝑣𝑎𝑟 𝔪₁ σ ≡ 𝑚𝑣𝑎𝑟 𝔪₂ σ
𝑚≈₁ refl = refl
𝑚≈₂ : {𝔪 : 𝔛 α Π}{σ ς : Π ~[ 𝒜 ]↝ Γ}
→ ({τ : T}(v : ℐ τ Π) → σ v ≡ ς v)
→ 𝑚𝑣𝑎𝑟 𝔪 σ ≡ 𝑚𝑣𝑎𝑟 𝔪 ς
𝑚≈₂ {𝔪 = 𝔪} p = cong (𝑚𝑣𝑎𝑟 𝔪) (dext p)
-- Meta-algebra homomorphism
record MetaAlg⇒ {𝒜 ℬ : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜)(ℬᵃ : MetaAlg ℬ)
(f : 𝒜 ⇾̣ ℬ) : Set where
private module 𝒜 = MetaAlg 𝒜ᵃ
private module ℬ = MetaAlg ℬᵃ
field
⟨𝑎𝑙𝑔⟩ : {t : ⅀ 𝒜 α Γ} → f (𝒜.𝑎𝑙𝑔 t) ≡ ℬ.𝑎𝑙𝑔 (⅀₁ f t)
⟨𝑣𝑎𝑟⟩ : {v : ℐ α Γ} → f (𝒜.𝑣𝑎𝑟 v) ≡ ℬ.𝑣𝑎𝑟 v
⟨𝑚𝑣𝑎𝑟⟩ : {𝔪 : 𝔛 α Π}{ε : Π ~[ 𝒜 ]↝ Γ} → f (𝒜.𝑚𝑣𝑎𝑟 𝔪 ε) ≡ ℬ.𝑚𝑣𝑎𝑟 𝔪 (f ∘ ε)
-- Category of meta-algebras
module MetaAlgebraStructure = Structure 𝔽amiliesₛ MetaAlg
MetaAlgebraCatProps : MetaAlgebraStructure.CategoryProps
MetaAlgebraCatProps = record
{ IsHomomorphism = MetaAlg⇒
; id-hom = λ {𝒜}{𝒜ᵃ} → record
{ ⟨𝑎𝑙𝑔⟩ = cong (𝑎𝑙𝑔 𝒜ᵃ) (sym ⅀.identity)
; ⟨𝑣𝑎𝑟⟩ = refl
; ⟨𝑚𝑣𝑎𝑟⟩ = refl }
; comp-hom = λ{ {𝐶ˢ = 𝒜ᵃ}{ℬᵃ}{𝒞ᵃ} g f gᵃ⇒ fᵃ⇒ → record
{ ⟨𝑎𝑙𝑔⟩ = trans (cong g (⟨𝑎𝑙𝑔⟩ fᵃ⇒))
(trans (⟨𝑎𝑙𝑔⟩ gᵃ⇒)
(cong (𝑎𝑙𝑔 𝒞ᵃ) (sym ⅀.homomorphism)))
; ⟨𝑣𝑎𝑟⟩ = trans (cong g (⟨𝑣𝑎𝑟⟩ fᵃ⇒)) (⟨𝑣𝑎𝑟⟩ gᵃ⇒)
; ⟨𝑚𝑣𝑎𝑟⟩ = trans (cong g (⟨𝑚𝑣𝑎𝑟⟩ fᵃ⇒)) (⟨𝑚𝑣𝑎𝑟⟩ gᵃ⇒) }
}} where open MetaAlg ; open MetaAlg⇒
module MetaAlgProps = MetaAlgebraStructure.CategoryProps MetaAlgebraCatProps
𝕄etaAlgebras : Category 1ℓ 0ℓ 0ℓ
𝕄etaAlgebras = MetaAlgebraStructure.StructCat MetaAlgebraCatProps
module 𝕄etaAlg = Category 𝕄etaAlgebras
MetaAlgebra : Set₁
MetaAlgebra = 𝕄etaAlg.Obj
MetaAlgebra⇒ : MetaAlgebra → MetaAlgebra → Set
MetaAlgebra⇒ = 𝕄etaAlg._⇒_
-- Identity is a meta-algebra homomorphism
idᵃ : {𝒜 : Familyₛ} → (𝒜ᵃ : MetaAlg 𝒜) → MetaAlg⇒ 𝒜ᵃ 𝒜ᵃ id
idᵃ 𝒜ᵃ = record { ⟨𝑎𝑙𝑔⟩ = cong (MetaAlg.𝑎𝑙𝑔 𝒜ᵃ) (sym ⅀.identity)
; ⟨𝑣𝑎𝑟⟩ = refl ; ⟨𝑚𝑣𝑎𝑟⟩ = refl }
|
{
"alphanum_fraction": 0.6077684692,
"avg_line_length": 28.5434782609,
"ext": "agda",
"hexsha": "5f2c6b8111964f1af9bff0a288c5dd68606cb870",
"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/Metatheory/MetaAlgebra.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/Metatheory/MetaAlgebra.agda",
"max_line_length": 78,
"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/Metatheory/MetaAlgebra.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": 1587,
"size": 2626
}
|
{-# OPTIONS --without-K --safe #-}
module Definition.Typed.Weakening where
open import Definition.Untyped as U hiding (wk)
open import Definition.Untyped.Properties
open import Definition.Typed
import Tools.PropositionalEquality as PE
-- Weakening type
data _∷_⊆_ : Wk → Con Term → Con Term → Set where
id : ∀ {Γ} → id ∷ Γ ⊆ Γ
step : ∀ {Γ Δ A ρ} → ρ ∷ Δ ⊆ Γ → step ρ ∷ Δ ∙ A ⊆ Γ
lift : ∀ {Γ Δ A ρ} → ρ ∷ Δ ⊆ Γ → lift ρ ∷ Δ ∙ U.wk ρ A ⊆ Γ ∙ A
-- -- Weakening composition
_•ₜ_ : ∀ {ρ ρ′ Γ Δ Δ′} → ρ ∷ Γ ⊆ Δ → ρ′ ∷ Δ ⊆ Δ′ → ρ • ρ′ ∷ Γ ⊆ Δ′
id •ₜ η′ = η′
step η •ₜ η′ = step (η •ₜ η′)
lift η •ₜ id = lift η
lift η •ₜ step η′ = step (η •ₜ η′)
_•ₜ_ {lift ρ} {lift ρ′} {Δ′ = Δ′ ∙ A} (lift η) (lift η′) =
PE.subst (λ x → lift (ρ • ρ′) ∷ x ⊆ Δ′ ∙ A)
(PE.cong₂ _∙_ PE.refl (PE.sym (wk-comp ρ ρ′ A)))
(lift (η •ₜ η′))
-- Weakening of judgements
wkIndex : ∀ {Γ Δ n A ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρn = wkVar ρ n
in ⊢ Δ → n ∷ A ∈ Γ → ρn ∷ ρA ∈ Δ
wkIndex id ⊢Δ i = PE.subst (λ x → _ ∷ x ∈ _) (PE.sym (wk-id _)) i
wkIndex (step ρ) (⊢Δ ∙ A) i = PE.subst (λ x → _ ∷ x ∈ _)
(wk1-wk _ _)
(there (wkIndex ρ ⊢Δ i))
wkIndex (lift ρ) (⊢Δ ∙ A) (there i) = PE.subst (λ x → _ ∷ x ∈ _)
(wk1-wk≡lift-wk1 _ _)
(there (wkIndex ρ ⊢Δ i))
wkIndex (lift ρ) ⊢Δ here =
let G = _
n = _
in PE.subst (λ x → n ∷ x ∈ G)
(wk1-wk≡lift-wk1 _ _)
here
mutual
wk : ∀ {Γ Δ A ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
in ⊢ Δ → Γ ⊢ A → Δ ⊢ ρA
wk ρ ⊢Δ (ℕⱼ ⊢Γ) = ℕⱼ ⊢Δ
wk ρ ⊢Δ (Uⱼ ⊢Γ) = Uⱼ ⊢Δ
wk ρ ⊢Δ (Πⱼ F ▹ G) = let ρF = wk ρ ⊢Δ F
in Πⱼ ρF ▹ (wk (lift ρ) (⊢Δ ∙ ρF) G)
wk ρ ⊢Δ (univ A) = univ (wkTerm ρ ⊢Δ A)
wkTerm : ∀ {Γ Δ A t ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρt = U.wk ρ t
in ⊢ Δ → Γ ⊢ t ∷ A → Δ ⊢ ρt ∷ ρA
wkTerm ρ ⊢Δ (ℕⱼ ⊢Γ) = ℕⱼ ⊢Δ
wkTerm ρ ⊢Δ (Πⱼ F ▹ G) = let ρF = wkTerm ρ ⊢Δ F
in Πⱼ ρF ▹ (wkTerm (lift ρ) (⊢Δ ∙ univ ρF) G)
wkTerm ρ ⊢Δ (var ⊢Γ x) = var ⊢Δ (wkIndex ρ ⊢Δ x)
wkTerm ρ ⊢Δ (lamⱼ F t) = let ρF = wk ρ ⊢Δ F
in lamⱼ ρF (wkTerm (lift ρ) (⊢Δ ∙ ρF) t)
wkTerm ρ ⊢Δ (_∘ⱼ_ {G = G} g a) = PE.subst (λ x → _ ⊢ _ ∷ x)
(PE.sym (wk-β G))
(wkTerm ρ ⊢Δ g ∘ⱼ wkTerm ρ ⊢Δ a)
wkTerm ρ ⊢Δ (zeroⱼ ⊢Γ) = zeroⱼ ⊢Δ
wkTerm ρ ⊢Δ (sucⱼ n) = sucⱼ (wkTerm ρ ⊢Δ n)
wkTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrecⱼ {G = G} {s = s} ⊢G ⊢z ⊢s ⊢n) =
PE.subst (λ x → _ ⊢ natrec _ _ _ _ ∷ x) (PE.sym (wk-β G))
(natrecⱼ (wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢G)
(PE.subst (λ x → _ ⊢ _ ∷ x) (wk-β G) (wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec ρ G)
(wkTerm [ρ] ⊢Δ ⊢s))
(wkTerm [ρ] ⊢Δ ⊢n))
wkTerm ρ ⊢Δ (conv t A≡B) = conv (wkTerm ρ ⊢Δ t) (wkEq ρ ⊢Δ A≡B)
wkEq : ∀ {Γ Δ A B ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρB = U.wk ρ B
in ⊢ Δ → Γ ⊢ A ≡ B → Δ ⊢ ρA ≡ ρB
wkEq ρ ⊢Δ (univ A≡B) = univ (wkEqTerm ρ ⊢Δ A≡B)
wkEq ρ ⊢Δ (refl A) = refl (wk ρ ⊢Δ A)
wkEq ρ ⊢Δ (sym A≡B) = sym (wkEq ρ ⊢Δ A≡B)
wkEq ρ ⊢Δ (trans A≡B B≡C) = trans (wkEq ρ ⊢Δ A≡B) (wkEq ρ ⊢Δ B≡C)
wkEq ρ ⊢Δ (Π-cong F F≡H G≡E) = let ρF = wk ρ ⊢Δ F
in Π-cong ρF (wkEq ρ ⊢Δ F≡H)
(wkEq (lift ρ) (⊢Δ ∙ ρF) G≡E)
wkEqTerm : ∀ {Γ Δ A t u ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρt = U.wk ρ t
ρu = U.wk ρ u
in ⊢ Δ → Γ ⊢ t ≡ u ∷ A → Δ ⊢ ρt ≡ ρu ∷ ρA
wkEqTerm ρ ⊢Δ (refl t) = refl (wkTerm ρ ⊢Δ t)
wkEqTerm ρ ⊢Δ (sym t≡u) = sym (wkEqTerm ρ ⊢Δ t≡u)
wkEqTerm ρ ⊢Δ (trans t≡u u≡r) = trans (wkEqTerm ρ ⊢Δ t≡u) (wkEqTerm ρ ⊢Δ u≡r)
wkEqTerm ρ ⊢Δ (conv t≡u A≡B) = conv (wkEqTerm ρ ⊢Δ t≡u) (wkEq ρ ⊢Δ A≡B)
wkEqTerm ρ ⊢Δ (Π-cong F F≡H G≡E) =
let ρF = wk ρ ⊢Δ F
in Π-cong ρF (wkEqTerm ρ ⊢Δ F≡H)
(wkEqTerm (lift ρ) (⊢Δ ∙ ρF) G≡E)
wkEqTerm ρ ⊢Δ (app-cong {G = G} f≡g a≡b) =
PE.subst (λ x → _ ⊢ _ ≡ _ ∷ x)
(PE.sym (wk-β G))
(app-cong (wkEqTerm ρ ⊢Δ f≡g) (wkEqTerm ρ ⊢Δ a≡b))
wkEqTerm ρ ⊢Δ (β-red {a = a} {t = t} {G = G} F ⊢t ⊢a) =
let ρF = wk ρ ⊢Δ F
in PE.subst (λ x → _ ⊢ _ ≡ _ ∷ x)
(PE.sym (wk-β G))
(PE.subst (λ x → _ ⊢ U.wk _ ((lam t) ∘ a) ≡ x ∷ _)
(PE.sym (wk-β t))
(β-red ρF (wkTerm (lift ρ) (⊢Δ ∙ ρF) ⊢t)
(wkTerm ρ ⊢Δ ⊢a)))
wkEqTerm ρ ⊢Δ (η-eq F f g f0≡g0) =
let ρF = wk ρ ⊢Δ F
in η-eq ρF (wkTerm ρ ⊢Δ f)
(wkTerm ρ ⊢Δ g)
(PE.subst (λ t → _ ⊢ t ∘ _ ≡ _ ∷ _)
(PE.sym (wk1-wk≡lift-wk1 _ _))
(PE.subst (λ t → _ ⊢ _ ≡ t ∘ _ ∷ _)
(PE.sym (wk1-wk≡lift-wk1 _ _))
(wkEqTerm (lift ρ) (⊢Δ ∙ ρF) f0≡g0)))
wkEqTerm ρ ⊢Δ (suc-cong m≡n) = suc-cong (wkEqTerm ρ ⊢Δ m≡n)
wkEqTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-cong {s = s} {s′ = s′} {F = F}
F≡F′ z≡z′ s≡s′ n≡n′) =
PE.subst (λ x → Δ ⊢ natrec _ _ _ _ ≡ _ ∷ x) (PE.sym (wk-β F))
(natrec-cong (wkEq (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) F≡F′)
(PE.subst (λ x → Δ ⊢ _ ≡ _ ∷ x) (wk-β F)
(wkEqTerm [ρ] ⊢Δ z≡z′))
(PE.subst (λ x → Δ ⊢ U.wk ρ s
≡ U.wk ρ s′ ∷ x)
(wk-β-natrec _ F)
(wkEqTerm [ρ] ⊢Δ s≡s′))
(wkEqTerm [ρ] ⊢Δ n≡n′))
wkEqTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-zero {z} {s} {F} ⊢F ⊢z ⊢s) =
PE.subst (λ x → Δ ⊢ natrec (U.wk (lift _) F) _ _ _ ≡ _ ∷ x)
(PE.sym (wk-β F))
(natrec-zero (wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢F)
(PE.subst (λ x → Δ ⊢ U.wk ρ z ∷ x)
(wk-β F)
(wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec _ F)
(wkTerm [ρ] ⊢Δ ⊢s)))
wkEqTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-suc {n} {z} {s} {F} ⊢n ⊢F ⊢z ⊢s) =
PE.subst (λ x → Δ ⊢ natrec (U.wk (lift _) F) _ _ _
≡ _ ∘ (natrec _ _ _ _) ∷ x)
(PE.sym (wk-β F))
(natrec-suc (wkTerm [ρ] ⊢Δ ⊢n)
(wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢F)
(PE.subst (λ x → Δ ⊢ U.wk ρ z ∷ x)
(wk-β F)
(wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec _ F)
(wkTerm [ρ] ⊢Δ ⊢s)))
mutual
wkRed : ∀ {Γ Δ A B ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρB = U.wk ρ B
in ⊢ Δ → Γ ⊢ A ⇒ B → Δ ⊢ ρA ⇒ ρB
wkRed ρ ⊢Δ (univ A⇒B) = univ (wkRedTerm ρ ⊢Δ A⇒B)
wkRedTerm : ∀ {Γ Δ A t u ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρt = U.wk ρ t
ρu = U.wk ρ u
in ⊢ Δ → Γ ⊢ t ⇒ u ∷ A → Δ ⊢ ρt ⇒ ρu ∷ ρA
wkRedTerm ρ ⊢Δ (conv t⇒u A≡B) = conv (wkRedTerm ρ ⊢Δ t⇒u) (wkEq ρ ⊢Δ A≡B)
wkRedTerm ρ ⊢Δ (app-subst {B = B} t⇒u a) =
PE.subst (λ x → _ ⊢ _ ⇒ _ ∷ x) (PE.sym (wk-β B))
(app-subst (wkRedTerm ρ ⊢Δ t⇒u) (wkTerm ρ ⊢Δ a))
wkRedTerm ρ ⊢Δ (β-red {A} {B} {a} {t} ⊢A ⊢t ⊢a) =
let ⊢ρA = wk ρ ⊢Δ ⊢A
in PE.subst (λ x → _ ⊢ _ ⇒ _ ∷ x) (PE.sym (wk-β B))
(PE.subst (λ x → _ ⊢ U.wk _ ((lam t) ∘ a) ⇒ x ∷ _)
(PE.sym (wk-β t))
(β-red ⊢ρA (wkTerm (lift ρ) (⊢Δ ∙ ⊢ρA) ⊢t)
(wkTerm ρ ⊢Δ ⊢a)))
wkRedTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-subst {s = s} {F = F} ⊢F ⊢z ⊢s n⇒n′) =
PE.subst (λ x → _ ⊢ natrec _ _ _ _ ⇒ _ ∷ x) (PE.sym (wk-β F))
(natrec-subst (wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢F)
(PE.subst (λ x → _ ⊢ _ ∷ x) (wk-β F)
(wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec _ F)
(wkTerm [ρ] ⊢Δ ⊢s))
(wkRedTerm [ρ] ⊢Δ n⇒n′))
wkRedTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-zero {s = s} {F = F} ⊢F ⊢z ⊢s) =
PE.subst (λ x → _ ⊢ natrec (U.wk (lift ρ) F) _ _ _ ⇒ _ ∷ x)
(PE.sym (wk-β F))
(natrec-zero (wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢F)
(PE.subst (λ x → _ ⊢ _ ∷ x)
(wk-β F)
(wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec ρ F)
(wkTerm [ρ] ⊢Δ ⊢s)))
wkRedTerm {Δ = Δ} {ρ = ρ} [ρ] ⊢Δ (natrec-suc {s = s} {F = F} ⊢n ⊢F ⊢z ⊢s) =
PE.subst (λ x → _ ⊢ natrec _ _ _ _ ⇒ _ ∘ natrec _ _ _ _ ∷ x)
(PE.sym (wk-β F))
(natrec-suc (wkTerm [ρ] ⊢Δ ⊢n)
(wk (lift [ρ]) (⊢Δ ∙ ℕⱼ ⊢Δ) ⊢F)
(PE.subst (λ x → _ ⊢ _ ∷ x)
(wk-β F)
(wkTerm [ρ] ⊢Δ ⊢z))
(PE.subst (λ x → Δ ⊢ U.wk ρ s ∷ x)
(wk-β-natrec ρ F)
(wkTerm [ρ] ⊢Δ ⊢s)))
wkRed* : ∀ {Γ Δ A B ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρB = U.wk ρ B
in ⊢ Δ → Γ ⊢ A ⇒* B → Δ ⊢ ρA ⇒* ρB
wkRed* ρ ⊢Δ (id A) = id (wk ρ ⊢Δ A)
wkRed* ρ ⊢Δ (A⇒A′ ⇨ A′⇒*B) = wkRed ρ ⊢Δ A⇒A′ ⇨ wkRed* ρ ⊢Δ A′⇒*B
wkRed*Term : ∀ {Γ Δ A t u ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρt = U.wk ρ t
ρu = U.wk ρ u
in ⊢ Δ → Γ ⊢ t ⇒* u ∷ A → Δ ⊢ ρt ⇒* ρu ∷ ρA
wkRed*Term ρ ⊢Δ (id t) = id (wkTerm ρ ⊢Δ t)
wkRed*Term ρ ⊢Δ (t⇒t′ ⇨ t′⇒*u) = wkRedTerm ρ ⊢Δ t⇒t′ ⇨ wkRed*Term ρ ⊢Δ t′⇒*u
wkRed:*: : ∀ {Γ Δ A B ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρB = U.wk ρ B
in ⊢ Δ → Γ ⊢ A :⇒*: B → Δ ⊢ ρA :⇒*: ρB
wkRed:*: ρ ⊢Δ [ ⊢A , ⊢B , D ] = [ wk ρ ⊢Δ ⊢A , wk ρ ⊢Δ ⊢B , wkRed* ρ ⊢Δ D ]
wkRed:*:Term : ∀ {Γ Δ A t u ρ} → ρ ∷ Δ ⊆ Γ →
let ρA = U.wk ρ A
ρt = U.wk ρ t
ρu = U.wk ρ u
in ⊢ Δ → Γ ⊢ t :⇒*: u ∷ A → Δ ⊢ ρt :⇒*: ρu ∷ ρA
wkRed:*:Term ρ ⊢Δ [ ⊢t , ⊢u , d ] =
[ wkTerm ρ ⊢Δ ⊢t , wkTerm ρ ⊢Δ ⊢u , wkRed*Term ρ ⊢Δ d ]
|
{
"alphanum_fraction": 0.353000091,
"avg_line_length": 43.7569721116,
"ext": "agda",
"hexsha": "33a791f2018770259945384ab4bb677cdedb791e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/Typed/Weakening.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/Typed/Weakening.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/Typed/Weakening.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5296,
"size": 10983
}
|
module Pi-.Examples where
open import Data.Empty
open import Data.Unit
open import Data.Sum
open import Data.Product
open import Relation.Binary.Core
open import Relation.Binary
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Data.Nat
open import Data.Nat.Properties
open import Data.List as L
open import Function using (_∘_)
open import Pi-.Syntax
open import Pi-.Opsem
open import Pi-.Eval
-----------------------------------------------------------------------------
-- Patterns and data definitions
pattern 𝔹 = 𝟙 +ᵤ 𝟙
pattern 𝔽 = inj₁ tt
pattern 𝕋 = inj₂ tt
𝔹+ : ℕ → 𝕌
𝔹+ 0 = 𝟘
𝔹+ 1 = 𝔹
𝔹+ (suc (suc n)) = 𝔹 +ᵤ (𝔹+ (suc n))
𝔹^ : ℕ → 𝕌
𝔹^ 0 = 𝟙
𝔹^ 1 = 𝔹
𝔹^ (suc (suc n)) = 𝔹 ×ᵤ 𝔹^ (suc n)
𝔹* : ℕ → 𝕌
𝔹* n = 𝔹^ (1 + n)
𝔽^ : (n : ℕ) → ⟦ 𝔹^ n ⟧
𝔽^ 0 = tt
𝔽^ 1 = 𝔽
𝔽^ (suc (suc n)) = 𝔽 , 𝔽^ (suc n)
-----------------------------------------------------------------------------
-- Adaptors
[A+B]+C=[C+B]+A : ∀ {A B C} → (A +ᵤ B) +ᵤ C ↔ (C +ᵤ B) +ᵤ A
[A+B]+C=[C+B]+A = assocr₊ ⨾ (id↔ ⊕ swap₊) ⨾ swap₊
[A+B]+C=[A+C]+B : ∀ {A B C} → (A +ᵤ B) +ᵤ C ↔ (A +ᵤ C) +ᵤ B
[A+B]+C=[A+C]+B = assocr₊ ⨾ (id↔ ⊕ swap₊) ⨾ assocl₊
[A+B]+[C+D]=[A+C]+[B+D] : {A B C D : 𝕌} → (A +ᵤ B) +ᵤ (C +ᵤ D) ↔ (A +ᵤ C) +ᵤ (B +ᵤ D)
[A+B]+[C+D]=[A+C]+[B+D] = assocl₊ ⨾ (assocr₊ ⊕ id↔) ⨾ ((id↔ ⊕ swap₊) ⊕ id↔) ⨾ (assocl₊ ⊕ id↔) ⨾ assocr₊
A+[B+C]=B+[A+C] : ∀ {A B C} → A +ᵤ (B +ᵤ C) ↔ B +ᵤ (A +ᵤ C)
A+[B+C]=B+[A+C] = assocl₊ ⨾ swap₊ ⊕ id↔ ⨾ assocr₊
Ax[BxC]=Bx[AxC] : {A B C : 𝕌} → A ×ᵤ (B ×ᵤ C) ↔ B ×ᵤ (A ×ᵤ C)
Ax[BxC]=Bx[AxC] = assocl⋆ ⨾ (swap⋆ ⊗ id↔) ⨾ assocr⋆
[AxB]×C=[A×C]xB : ∀ {A B C} → (A ×ᵤ B) ×ᵤ C ↔ (A ×ᵤ C) ×ᵤ B
[AxB]×C=[A×C]xB = assocr⋆ ⨾ (id↔ ⊗ swap⋆) ⨾ assocl⋆
[A×B]×[C×D]=[A×C]×[B×D] : {A B C D : 𝕌} → (A ×ᵤ B) ×ᵤ (C ×ᵤ D) ↔ (A ×ᵤ C) ×ᵤ (B ×ᵤ D)
[A×B]×[C×D]=[A×C]×[B×D] = assocl⋆ ⨾ (assocr⋆ ⊗ id↔) ⨾ ((id↔ ⊗ swap⋆) ⊗ id↔) ⨾ (assocl⋆ ⊗ id↔) ⨾ assocr⋆
-- FST2LAST(b₁,b₂,…,bₙ) = (b₂,…,bₙ,b₁)
FST2LAST : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
FST2LAST {0} = id↔
FST2LAST {1} = id↔
FST2LAST {2} = swap⋆
FST2LAST {suc (suc (suc n))} = Ax[BxC]=Bx[AxC] ⨾ (id↔ ⊗ FST2LAST)
FST2LAST⁻¹ : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
FST2LAST⁻¹ = ! FST2LAST
-----------------------------------------------------------------------------
-- Reversible Conditionals
-- NOT(b) = ¬b
NOT : 𝔹 ↔ 𝔹
NOT = swap₊
-- CNOT(b₁,b₂) = (b₁,b₁ xor b₂)
CNOT : 𝔹 ×ᵤ 𝔹 ↔ 𝔹 ×ᵤ 𝔹
CNOT = dist ⨾ (id↔ ⊕ (id↔ ⊗ swap₊)) ⨾ factor
-- CIF(c₁,c₂)(𝔽,a) = (𝔽,c₁ a)
-- CIF(c₁,c₂)(𝕋,a) = (𝕋,c₂ a)
CIF : {A : 𝕌} → (c₁ c₂ : A ↔ A) → 𝔹 ×ᵤ A ↔ 𝔹 ×ᵤ A
CIF c₁ c₂ = dist ⨾ ((id↔ ⊗ c₁) ⊕ (id↔ ⊗ c₂)) ⨾ factor
CIF₁ CIF₂ : {A : 𝕌} → (c : A ↔ A) → 𝔹 ×ᵤ A ↔ 𝔹 ×ᵤ A
CIF₁ c = CIF c id↔
CIF₂ c = CIF id↔ c
-- TOFFOLI(b₁,…,bₙ,b) = (b₁,…,bₙ,b xor (b₁ ∧ … ∧ bₙ))
TOFFOLI : {n : ℕ} → 𝔹^ n ↔ 𝔹^ n
TOFFOLI {0} = id↔
TOFFOLI {1} = swap₊
TOFFOLI {suc (suc n)} = CIF₂ TOFFOLI
-- TOFFOLI(b₁,…,bₙ,b) = (b₁,…,bₙ,b xor (¬b₁ ∧ … ∧ ¬bₙ))
TOFFOLI' : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
TOFFOLI' {0} = id↔
TOFFOLI' {1} = swap₊
TOFFOLI' {suc (suc n)} = CIF₁ TOFFOLI'
-- RESET(b₁,…,bₙ) = (b₁ xor (b₁ ∨ … ∨ bₙ),…,bₙ)
RESET : ∀ {n} → 𝔹 ×ᵤ 𝔹^ n ↔ 𝔹 ×ᵤ 𝔹^ n
RESET {0} = id↔
RESET {1} = swap⋆ ⨾ CNOT ⨾ swap⋆
RESET {suc (suc n)} = Ax[BxC]=Bx[AxC] ⨾ CIF RESET (swap₊ ⊗ id↔) ⨾ Ax[BxC]=Bx[AxC]
-----------------------------------------------------------------------------
-- Reversible Copy
-- copy(𝔽,b₁,…,bₙ) = (b₁,b₁,…,bₙ)
COPY : ∀ {n} → 𝔹 ×ᵤ 𝔹^ n ↔ 𝔹 ×ᵤ 𝔹^ n
COPY {0} = id↔
COPY {1} = swap⋆ ⨾ CNOT ⨾ swap⋆
COPY {suc (suc n)} = assocl⋆ ⨾ (COPY {1} ⊗ id↔) ⨾ assocr⋆
-----------------------------------------------------------------------------
-- Arithmetic
-- INCR(b̅) = INCR(b̅ + 1)
INCR : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
INCR {0} = id↔
INCR {1} = swap₊
INCR {suc (suc n)} = (id↔ ⊗ INCR) ⨾ FST2LAST ⨾ TOFFOLI' ⨾ FST2LAST⁻¹
-----------------------------------------------------------------------------
-- Control flow
zigzag : 𝔹 ↔ 𝔹
zigzag = uniti₊l ⨾ (η₊ ⊕ id↔) ⨾ [A+B]+C=[C+B]+A ⨾ (ε₊ ⊕ id↔) ⨾ unite₊l
zigzagₜᵣ = evalₜᵣ zigzag 𝔽
-----------------------------------------------------------------------------
-- Iteration
trace₊ : ∀ {A B C} → A +ᵤ C ↔ B +ᵤ C → A ↔ B
trace₊ f = uniti₊r ⨾ (id↔ ⊕ η₊) ⨾ assocl₊ ⨾ (f ⊕ id↔) ⨾ assocr₊ ⨾ (id↔ ⊕ ε₊) ⨾ unite₊r
-- Given reversible F : 𝔹^n ↔ 𝔹^n, generate a circuit to find x̅ such that F(x̅) = (𝔽,…)
-- via running (LOOP F)(𝔽,𝔽̅).
-- (id↔ ⊗ F)((LOOP F)(𝔽,𝔽̅)) = (𝔽,𝔽,…)
LOOP : ∀ {n} → 𝔹^ n ↔ 𝔹^ n → 𝔹 ×ᵤ 𝔹^ n ↔ 𝔹 ×ᵤ 𝔹^ n
LOOP {0} F = id↔
LOOP {1} F = id↔ ⊗ F
LOOP {suc (suc n)} F = trace₊ ((dist ⊕ id↔) ⨾ [A+B]+C=[A+C]+B ⨾ (factor ⊕ id↔) ⨾
((RESET ⨾ (id↔ ⊗ F) ⨾ COPY ⨾ (id↔ ⊗ ! F)) ⊕ id↔) ⨾
(dist ⊕ id↔) ⨾ [A+B]+C=[A+C]+B ⨾ (factor ⊕ (id↔ ⊗ INCR)))
module loop_test where
-- Examples
-- AND(𝔽,a,b) = AND(a∧b,a,b)
AND : 𝔹^ 3 ↔ 𝔹^ 3
AND = FST2LAST ⨾ (dist ⨾ (id↔ ⊕ (id↔ ⊗ (dist ⨾ (id↔ ⊕ (id↔ ⊗ swap₊)) ⨾ factor))) ⨾ factor) ⨾ FST2LAST⁻¹
NAND : 𝔹^ 3 ↔ 𝔹^ 3
NAND = AND ⨾ (NOT ⊗ id↔)
-- OR(𝔽,a,b) = OR(a∨b,a,b)
OR : 𝔹^ 3 ↔ 𝔹^ 3
OR = FST2LAST ⨾ (dist ⨾ ((id↔ ⊗ (dist ⨾ (id↔ ⊕ (id↔ ⊗ swap₊)) ⨾ factor)) ⊕ (id↔ ⊗ (id↔ ⊗ swap₊))) ⨾ factor) ⨾ FST2LAST⁻¹
NOR : 𝔹^ 3 ↔ 𝔹^ 3
NOR = OR ⨾ (NOT ⊗ id↔)
-- XOR(a,b) = XOR(a xor b,b)
XOR : 𝔹^ 2 ↔ 𝔹^ 2
XOR = distl ⨾ (id↔ ⊕ (swap₊ ⊗ id↔)) ⨾ factorl
tests : List (∃[ n ] (𝔹^ n ↔ 𝔹^ n))
tests = (_ , LOOP AND) ∷ (_ , LOOP NAND) ∷ (_ , LOOP OR) ∷ (_ , LOOP NOR) ∷ (_ , LOOP XOR) ∷ []
results : List (Σ[ t ∈ 𝕌 ] ⟦ t ⟧)
results = L.map (λ {(_ , c) → proj₁ (eval' c (𝔽^ _))}) tests
-- (_ , 𝔽 , 𝔽 , 𝔽 , 𝔽) ∷
-- (_ , 𝔽 , 𝔽 , 𝕋 , 𝕋) ∷
-- (_ , 𝔽 , 𝔽 , 𝔽 , 𝔽) ∷
-- (_ , 𝔽 , 𝔽 , 𝔽 , 𝕋) ∷
-- (_ , 𝔽 , 𝔽 , 𝔽) ∷ []
-----------------------------------------------------------------------------
-- Data Structures Conversions
𝟙+ : ℕ → 𝕌
𝟙+ 0 = 𝟘
𝟙+ 1 = 𝟙
𝟙+ (suc (suc n)) = 𝟙 +ᵤ (𝟙+ (suc n))
convert : ∀ {n} → 𝟙+ (2 ^ n) ↔ 𝔹^ n
convert {0} = id↔
convert {1} = id↔
convert {suc (suc n)} =
split ⨾
(convert {suc n} ⊕ (coe {n} ⨾ convert {suc n})) ⨾
(uniti⋆l ⊕ uniti⋆l) ⨾
factor
where
coe : ∀ {n} → 𝟙+ ((2 ^ n) + ((2 ^ n) + 0) + 0) ↔ 𝟙+ (2 ^ (1 + n))
coe {n} rewrite +-identityʳ ((2 ^ n) + ((2 ^ n) + 0)) = id↔
split : ∀ {n m} → 𝟙+ (n + m) ↔ (𝟙+ n +ᵤ 𝟙+ m)
split {0} {m} = uniti₊l
split {1} {0} = uniti₊r
split {1} {1} = id↔
split {1} {suc (suc m)} = id↔
split {suc (suc n)} {m} = (id↔ ⊕ split) ⨾ assocl₊
2047→2¹¹-1 : 𝟙+ 2047 ↔ (- 𝟙 +ᵤ 𝔹^ 11)
2047→2¹¹-1 = uniti₊l ⨾
((η₊ ⨾ swap₊) ⊕ id↔) ⨾
assocr₊ ⨾
(id↔ ⊕ convert {11})
incr+ : ∀ {n} → 𝟙+ n ↔ 𝟙+ n
incr+ {0} = id↔
incr+ {1} = id↔
incr+ {2} = swap₊
incr+ {suc (suc (suc n))} = (id↔ ⊕ incr+) ⨾ A+[B+C]=B+[A+C]
incr+' : 𝟙+ 2047 ↔ 𝟙+ 2047
incr+' = 2047→2¹¹-1 ⨾ (id↔ ⊕ INCR) ⨾ ! 2047→2¹¹-1
v : (n : ℕ) → ¬ n ≡ 0 → ⟦ 𝟙+ n ⟧
v 0 0≠0 = 0≠0 refl
v 1 _ = tt
v (suc (suc n)) _ = inj₂ (v (suc n) (λ ()))
len1 = proj₂ (eval' (incr+ {2047}) (v 2047 (λ ()))) -- 32721
len2 = proj₂ (eval' incr+' (v 2047 (λ ()))) -- 20143
len3 = proj₂ (eval' 2047→2¹¹-1 (v 2047 (λ ()))) -- 12433
v' = (proj₂ ∘ proj₁) (eval' 2047→2¹¹-1 (v 2047 (λ ())))
len4 = proj₂ (eval' (id↔ ⊕ INCR) v') -- 3453
v'' = (proj₂ ∘ proj₁) (eval' (id↔ ⊕ INCR) v')
len5 = proj₂ (eval' (! 2047→2¹¹-1) v'') -- 249
-----------------------------------------------------------------------------
-- Higher-Order Combinators
hof- : {A B : 𝕌} → (A ↔ B) → (𝟘 ↔ - A +ᵤ B)
hof- c = η₊ ⨾ (c ⊕ id↔) ⨾ swap₊
comp- : {A B C : 𝕌} → (- A +ᵤ B) +ᵤ (- B +ᵤ C) ↔ (- A +ᵤ C)
comp- = assocl₊ ⨾ (assocr₊ ⊕ id↔) ⨾ ((id↔ ⊕ ε₊) ⊕ id↔) ⨾ (unite₊r ⊕ id↔)
app- : {A B : 𝕌} → (- A +ᵤ B) +ᵤ A ↔ B
app- = swap₊ ⨾ assocl₊ ⨾ (ε₊ ⊕ id↔) ⨾ unite₊l
-----------------------------------------------------------------------------
-- Algebraic Identities
inv- : {A : 𝕌} → A ↔ - (- A)
inv- = uniti₊r ⨾ (id↔ ⊕ η₊) ⨾ assocl₊ ⨾ (ε₊ ⊕ id↔) ⨾ unite₊l
dist- : {A B : 𝕌} → - (A +ᵤ B) ↔ - A +ᵤ - B
dist- = uniti₊l ⨾ (η₊ ⊕ id↔) ⨾ uniti₊l ⨾ (η₊ ⊕ id↔) ⨾ assocl₊ ⨾
([A+B]+[C+D]=[A+C]+[B+D] ⊕ id↔) ⨾
(swap₊ ⊕ id↔) ⨾ assocr₊ ⨾ (id↔ ⊕ ε₊) ⨾ unite₊r
neg- : {A B : 𝕌} → (A ↔ B) → (- A ↔ - B)
neg- c = uniti₊r ⨾ (id↔ ⊕ η₊) ⨾
(id↔ ⊕ ! c ⊕ id↔) ⨾ assocl₊ ⨾
((swap₊ ⨾ ε₊) ⊕ id↔) ⨾ unite₊l
|
{
"alphanum_fraction": 0.4100183262,
"avg_line_length": 30.5410447761,
"ext": "agda",
"hexsha": "f084db79f9cb4d3f255bfde9bbc95926c9f4b4a7",
"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": "Pi-/Examples.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": "Pi-/Examples.agda",
"max_line_length": 122,
"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": "Pi-/Examples.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": 4626,
"size": 8185
}
|
-- Agda program using the Iowa Agda library
open import bool
module PROOF-appendAddLengths
(Choice : Set)
(choose : Choice → 𝔹)
(lchoice : Choice → Choice)
(rchoice : Choice → Choice)
where
open import eq
open import nat
open import list
open import maybe
---------------------------------------------------------------------------
-- Translated Curry operations:
++ : {a : Set} → 𝕃 a → 𝕃 a → 𝕃 a
++ [] x = x
++ (y :: z) u = y :: (++ z u)
append : {a : Set} → 𝕃 a → 𝕃 a → 𝕃 a
append x y = ++ x y
---------------------------------------------------------------------------
appendAddLengths : {a : Set} → (x : 𝕃 a) → (y : 𝕃 a)
→ ((length x) + (length y)) ≡ (length (append x y))
appendAddLengths [] y = refl
appendAddLengths (x :: xs) y rewrite appendAddLengths xs y = refl
---------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.4389140271,
"avg_line_length": 25.2571428571,
"ext": "agda",
"hexsha": "5294fa52d2ede43be95445194e5d3a6b5420f42b",
"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": "7905bc4f625a94a725f9f6d8a2de1140bea5e471",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "phlummox/curry-tools",
"max_forks_repo_path": "currypp/.cpm/packages/currycheck/examples/withVerification/PROOF-appendAddLengths.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7905bc4f625a94a725f9f6d8a2de1140bea5e471",
"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": "phlummox/curry-tools",
"max_issues_repo_path": "currypp/.cpm/packages/currycheck/examples/withVerification/PROOF-appendAddLengths.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7905bc4f625a94a725f9f6d8a2de1140bea5e471",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "phlummox/curry-tools",
"max_stars_repo_path": "currypp/.cpm/packages/currycheck/examples/withVerification/PROOF-appendAddLengths.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 239,
"size": 884
}
|
{-# OPTIONS --without-K #-}
module algebra.group.core where
open import level
open import algebra.monoid.core
open import equality.core
open import function.isomorphism
open import sum
record IsGroup {i} (G : Set i) : Set i where
field instance mon : IsMonoid G
open IsMonoid mon public
field
inv : G → G
linv : (x : G) → inv x * x ≡ e
rinv : (x : G) → x * inv x ≡ e
Group : ∀ i → Set (lsuc i)
Group i = Σ (Set i) IsGroup
module _ {i} {G : Set i} ⦃ grp : IsGroup G ⦄ where
open IsGroup ⦃ ... ⦄
left-translation-iso : (g : G) → G ≅ G
left-translation-iso g = record
{ to = λ x → g * x
; from = λ x → inv g * x
; iso₁ = λ x → sym (assoc _ _ _)
· ap (λ u → u * x) (linv g)
· lunit x
; iso₂ = λ x → sym (assoc _ _ _)
· ap (λ u → u * x) (rinv g)
· lunit x }
right-translation-iso : (g : G) → G ≅ G
right-translation-iso g = record
{ to = λ x → x * g
; from = λ x → x * inv g
; iso₁ = λ x → assoc _ _ _
· ap (λ u → x * u) (rinv g)
· runit x
; iso₂ = λ x → assoc _ _ _
· ap (λ u → x * u) (linv g)
· runit x }
|
{
"alphanum_fraction": 0.5077720207,
"avg_line_length": 25.1739130435,
"ext": "agda",
"hexsha": "0602fac044275ce23571ccccf19bbc234b906970",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/algebra/group/core.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/algebra/group/core.agda",
"max_line_length": 50,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/algebra/group/core.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 424,
"size": 1158
}
|
-- Andreas, 2015-09-18, issue reported by Guillaume Brunerie
{-# OPTIONS --rewriting #-}
data _==_ {A : Set} (a : A) : A → Set where
idp : a == a
{-# BUILTIN REWRITE _==_ #-}
postulate
A : Set
a b : A
r : a == b
{-# REWRITE r #-}
r = idp
-- Should not work, as this behavior is confusing the users.
-- Instead, should give an error that rewrite rule
-- can only be added after function body.
|
{
"alphanum_fraction": 0.6253101737,
"avg_line_length": 20.15,
"ext": "agda",
"hexsha": "ea2957663540fd5fa034e293afb7c375dc6edc4c",
"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/Issue1651.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/Issue1651.agda",
"max_line_length": 60,
"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/Issue1651.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": 125,
"size": 403
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- A delimited continuation monad
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Category.Monad.Continuation where
open import Category.Applicative
open import Category.Applicative.Indexed
open import Category.Monad
open import Function.Identity.Categorical as Id using (Identity)
open import Category.Monad.Indexed
open import Function
open import Level
------------------------------------------------------------------------
-- Delimited continuation monads
DContT : ∀ {i f} {I : Set i} → (I → Set f) → (Set f → Set f) → IFun I f
DContT K M r₂ r₁ a = (a → M (K r₁)) → M (K r₂)
DCont : ∀ {i f} {I : Set i} → (I → Set f) → IFun I f
DCont K = DContT K Identity
DContTIMonad : ∀ {i f} {I : Set i} (K : I → Set f) {M} →
RawMonad M → RawIMonad (DContT K M)
DContTIMonad K Mon = record
{ return = λ a k → k a
; _>>=_ = λ c f k → c (flip f k)
}
where open RawMonad Mon
DContIMonad : ∀ {i f} {I : Set i} (K : I → Set f) → RawIMonad (DCont K)
DContIMonad K = DContTIMonad K Id.monad
------------------------------------------------------------------------
-- Delimited continuation operations
record RawIMonadDCont {i f} {I : Set i} (K : I → Set f)
(M : IFun I f) : Set (i ⊔ suc f) where
field
monad : RawIMonad M
reset : ∀ {r₁ r₂ r₃} → M r₁ r₂ (K r₂) → M r₃ r₃ (K r₁)
shift : ∀ {a r₁ r₂ r₃ r₄} →
((a → M r₁ r₁ (K r₂)) → M r₃ r₄ (K r₄)) → M r₃ r₂ a
open RawIMonad monad public
DContTIMonadDCont : ∀ {i f} {I : Set i} (K : I → Set f) {M} →
RawMonad M → RawIMonadDCont K (DContT K M)
DContTIMonadDCont K Mon = record
{ monad = DContTIMonad K Mon
; reset = λ e k → e return >>= k
; shift = λ e k → e (λ a k' → (k a) >>= k') return
}
where
open RawIMonad Mon
DContIMonadDCont : ∀ {i f} {I : Set i}
(K : I → Set f) → RawIMonadDCont K (DCont K)
DContIMonadDCont K = DContTIMonadDCont K Id.monad
|
{
"alphanum_fraction": 0.5140946011,
"avg_line_length": 32.2,
"ext": "agda",
"hexsha": "d20f67265b38f0a82038faec3d243030218a277a",
"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/Category/Monad/Continuation.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/Category/Monad/Continuation.agda",
"max_line_length": 72,
"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/Category/Monad/Continuation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 693,
"size": 2093
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Semigroup.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Reflection.StrictEquiv
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open import Cubical.Structures.Record
open Iso
private
variable
ℓ : Level
-- Semigroups as a record, inspired by the Agda standard library:
--
-- https://github.com/agda/agda-stdlib/blob/master/src/Algebra/Bundles.agda#L48
-- https://github.com/agda/agda-stdlib/blob/master/src/Algebra/Structures.agda#L50
--
-- Note that as we are using Path for all equations the IsMagma record
-- would only contain isSet A if we had it.
record IsSemigroup {A : Type ℓ} (_·_ : A → A → A) : Type ℓ where
constructor issemigroup
field
is-set : isSet A
assoc : (x y z : A) → x · (y · z) ≡ (x · y) · z
record SemigroupStr (A : Type ℓ) : Type (ℓ-suc ℓ) where
constructor semigroupstr
field
_·_ : A → A → A
isSemigroup : IsSemigroup _·_
infixl 7 _·_
open IsSemigroup isSemigroup public
Semigroup : Type (ℓ-suc ℓ)
Semigroup = TypeWithStr _ SemigroupStr
semigroup : (A : Type ℓ) (_·_ : A → A → A) (h : IsSemigroup _·_) → Semigroup
semigroup A _·_ h = A , semigroupstr _·_ h
record SemigroupEquiv (M N : Semigroup {ℓ}) (e : ⟨ M ⟩ ≃ ⟨ N ⟩) : Type ℓ where
constructor semigroupequiv
-- Shorter qualified names
private
module M = SemigroupStr (snd M)
module N = SemigroupStr (snd N)
field
isHom : (x y : ⟨ M ⟩) → equivFun e (x M.· y) ≡ equivFun e x N.· equivFun e y
open SemigroupStr
open IsSemigroup
open SemigroupEquiv
-- Develop some theory about Semigroups using various general results
-- that are stated using Σ-types. For this we define Semigroup as a
-- nested Σ-type, prove that it's equivalent to the above record
-- definition and then transport results along this equivalence.
module SemigroupΣTheory {ℓ} where
RawSemigroupStructure : Type ℓ → Type ℓ
RawSemigroupStructure X = X → X → X
RawSemigroupEquivStr = AutoEquivStr RawSemigroupStructure
rawSemigroupUnivalentStr : UnivalentStr _ RawSemigroupEquivStr
rawSemigroupUnivalentStr = autoUnivalentStr RawSemigroupStructure
SemigroupAxioms : (A : Type ℓ) → RawSemigroupStructure A → Type ℓ
SemigroupAxioms A _·_ = isSet A
× ((x y z : A) → x · (y · z) ≡ (x · y) · z)
SemigroupStructure : Type ℓ → Type ℓ
SemigroupStructure = AxiomsStructure RawSemigroupStructure SemigroupAxioms
SemigroupΣ : Type (ℓ-suc ℓ)
SemigroupΣ = TypeWithStr ℓ SemigroupStructure
isPropSemigroupAxioms : (A : Type ℓ) (_·_ : RawSemigroupStructure A)
→ isProp (SemigroupAxioms A _·_)
isPropSemigroupAxioms _ _ = isPropΣ isPropIsSet λ isSetA → isPropΠ3 λ _ _ _ → isSetA _ _
SemigroupEquivStr : StrEquiv SemigroupStructure ℓ
SemigroupEquivStr = AxiomsEquivStr RawSemigroupEquivStr SemigroupAxioms
SemigroupAxiomsIsoIsSemigroup : {A : Type ℓ} (_·_ : RawSemigroupStructure A)
→ Iso (SemigroupAxioms A _·_) (IsSemigroup _·_)
fun (SemigroupAxiomsIsoIsSemigroup s) (x , y) = issemigroup x y
inv (SemigroupAxiomsIsoIsSemigroup s) M = is-set M , assoc M
rightInv (SemigroupAxiomsIsoIsSemigroup s) _ = refl
leftInv (SemigroupAxiomsIsoIsSemigroup s) _ = refl
SemigroupAxioms≡IsSemigroup : {A : Type ℓ} (_·_ : RawSemigroupStructure A)
→ SemigroupAxioms _ _·_ ≡ IsSemigroup _·_
SemigroupAxioms≡IsSemigroup s = isoToPath (SemigroupAxiomsIsoIsSemigroup s)
Semigroup→SemigroupΣ : Semigroup → SemigroupΣ
Semigroup→SemigroupΣ (A , semigroupstr _·_ isSemigroup) =
A , _·_ , SemigroupAxiomsIsoIsSemigroup _ .inv isSemigroup
SemigroupΣ→Semigroup : SemigroupΣ → Semigroup
SemigroupΣ→Semigroup (A , _·_ , isSemigroupΣ) =
semigroup A _·_ (SemigroupAxiomsIsoIsSemigroup _ .fun isSemigroupΣ)
SemigroupIsoSemigroupΣ : Iso Semigroup SemigroupΣ
SemigroupIsoSemigroupΣ =
iso Semigroup→SemigroupΣ SemigroupΣ→Semigroup (λ _ → refl) (λ _ → refl)
semigroupUnivalentStr : UnivalentStr SemigroupStructure SemigroupEquivStr
semigroupUnivalentStr = axiomsUnivalentStr _ isPropSemigroupAxioms rawSemigroupUnivalentStr
SemigroupΣPath : (M N : SemigroupΣ) → (M ≃[ SemigroupEquivStr ] N) ≃ (M ≡ N)
SemigroupΣPath = SIP semigroupUnivalentStr
SemigroupEquivΣ : (M N : Semigroup) → Type ℓ
SemigroupEquivΣ M N = Semigroup→SemigroupΣ M ≃[ SemigroupEquivStr ] Semigroup→SemigroupΣ N
SemigroupIsoΣPath : {M N : Semigroup} → Iso (Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] SemigroupEquiv M N e) (SemigroupEquivΣ M N)
fun SemigroupIsoΣPath (e , x) = e , isHom x
inv SemigroupIsoΣPath (e , h) = e , semigroupequiv h
rightInv SemigroupIsoΣPath _ = refl
leftInv SemigroupIsoΣPath _ = refl
SemigroupPath : (M N : Semigroup) → (Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] SemigroupEquiv M N e) ≃ (M ≡ N)
SemigroupPath M N =
Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] SemigroupEquiv M N e ≃⟨ strictIsoToEquiv SemigroupIsoΣPath ⟩
SemigroupEquivΣ M N ≃⟨ SemigroupΣPath _ _ ⟩
Semigroup→SemigroupΣ M ≡ Semigroup→SemigroupΣ N ≃⟨ isoToEquiv (invIso (congIso SemigroupIsoSemigroupΣ)) ⟩
M ≡ N ■
-- We now extract the important results from the above module
isPropIsSemigroup : {A : Type ℓ} (_·_ : A → A → A) → isProp (IsSemigroup _·_)
isPropIsSemigroup _·_ =
subst isProp (SemigroupΣTheory.SemigroupAxioms≡IsSemigroup _·_)
(SemigroupΣTheory.isPropSemigroupAxioms _ _·_)
SemigroupPath : (M N : Semigroup {ℓ}) → (Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] SemigroupEquiv M N e) ≃ (M ≡ N)
SemigroupPath {ℓ = ℓ} =
SIP
(autoUnivalentRecord
(autoRecordSpec (SemigroupStr {ℓ}) SemigroupEquiv
(fields:
data[ _·_ ∣ isHom ]
prop[ isSemigroup ∣ (λ _ → isPropIsSemigroup _) ]))
_ _)
|
{
"alphanum_fraction": 0.7042643229,
"avg_line_length": 36.3550295858,
"ext": "agda",
"hexsha": "ef7ac7509d5d1b3c72560a571acd28384acfb708",
"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/Algebra/Semigroup/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/Algebra/Semigroup/Base.agda",
"max_line_length": 113,
"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/Algebra/Semigroup/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2080,
"size": 6144
}
|
module STLC1.Kovacs.Convertibility where
open import STLC1.Kovacs.Substitution public
--------------------------------------------------------------------------------
-- Convertibility (_~_ ; ~refl ; _~⁻¹ ; lam ; app ; β ; η)
infix 3 _∼_
data _∼_ : ∀ {Γ A} → Γ ⊢ A → Γ ⊢ A → Set
where
refl∼ : ∀ {Γ A} → {M : Γ ⊢ A}
→ M ∼ M
_⁻¹∼ : ∀ {Γ A} → {M₁ M₂ : Γ ⊢ A}
→ (p : M₁ ∼ M₂)
→ M₂ ∼ M₁
_⦙∼_ : ∀ {Γ A} → {M₁ M₂ M₃ : Γ ⊢ A}
→ (p : M₁ ∼ M₂) (q : M₂ ∼ M₃)
→ M₁ ∼ M₃
ƛ∼ : ∀ {Γ A B} → {M₁ M₂ : Γ , A ⊢ B}
→ (p : M₁ ∼ M₂)
→ ƛ M₁ ∼ ƛ M₂
_∙∼_ : ∀ {Γ A B} → {M₁ M₂ : Γ ⊢ A ⇒ B} {N₁ N₂ : Γ ⊢ A}
→ (p : M₁ ∼ M₂) (q : N₁ ∼ N₂)
→ M₁ ∙ N₁ ∼ M₂ ∙ N₂
_,∼_ : ∀ {Γ A B} → {M₁ M₂ : Γ ⊢ A} {N₁ N₂ : Γ ⊢ B}
→ (p : M₁ ∼ M₂) (q : N₁ ∼ N₂)
→ M₁ , N₁ ∼ M₂ , N₂
π₁∼ : ∀ {Γ A B} → {M₁ M₂ : Γ ⊢ A ⩕ B}
→ (p : M₁ ∼ M₂)
→ π₁ M₁ ∼ π₁ M₂
π₂∼ : ∀ {Γ A B} → {M₁ M₂ : Γ ⊢ A ⩕ B}
→ (p : M₁ ∼ M₂)
→ π₂ M₁ ∼ π₂ M₂
red⇒ : ∀ {Γ A B} → (M : Γ , A ⊢ B) (N : Γ ⊢ A)
→ (ƛ M) ∙ N ∼ cut N M
red⩕₁ : ∀ {Γ A B} → (M : Γ ⊢ A) (N : Γ ⊢ B)
→ π₁ (M , N) ∼ M
red⩕₂ : ∀ {Γ A B} → (M : Γ ⊢ A) (N : Γ ⊢ B)
→ π₂ (M , N) ∼ N
exp⇒ : ∀ {Γ A B} → (M : Γ ⊢ A ⇒ B)
→ M ∼ ƛ (wk M ∙ 0)
exp⩕ : ∀ {Γ A B} → (M : Γ ⊢ A ⩕ B)
→ M ∼ π₁ M , π₂ M
exp⫪ : ∀ {Γ} → (M : Γ ⊢ ⫪)
→ M ∼ τ
≡→∼ : ∀ {Γ A} → {M₁ M₂ : Γ ⊢ A}
→ M₁ ≡ M₂
→ M₁ ∼ M₂
≡→∼ refl = refl∼
instance
per∼ : ∀ {Γ A} → PER (Γ ⊢ A) _∼_
per∼ =
record
{ _⁻¹ = _⁻¹∼
; _⦙_ = _⦙∼_
}
--------------------------------------------------------------------------------
renwk : ∀ {Γ Γ′ A B} → (η : Γ′ ⊇ Γ) (M : Γ ⊢ A)
→ (wk {B} ∘ ren η) M ≡
(ren (liftₑ η) ∘ wk) M
renwk η M = ren○ (wkₑ idₑ) η M ⁻¹
⦙ (λ η′ → ren (wkₑ η′) M) & ( rid○ η
⦙ lid○ η ⁻¹
)
⦙ ren○ (liftₑ η) (wkₑ idₑ) M
rencut : ∀ {Γ Γ′ A B} → (η : Γ′ ⊇ Γ) (M : Γ ⊢ A) (N : Γ , A ⊢ B)
→ (cut (ren η M) ∘ ren (liftₑ η)) N ≡
(ren η ∘ cut M) N
rencut η M N = sub◑ (idₛ , ren η M) (liftₑ η) N ⁻¹
⦙ (λ σ → sub (σ , ren η M) N) & ( rid◑ η
⦙ lid◐ η ⁻¹
)
⦙ sub◐ η (idₛ , M) N
-- (~ₑ)
ren∼ : ∀ {Γ Γ′ A} → {M₁ M₂ : Γ ⊢ A}
→ (η : Γ′ ⊇ Γ) → M₁ ∼ M₂
→ ren η M₁ ∼ ren η M₂
ren∼ η refl∼ = refl∼
ren∼ η (p ⁻¹∼) = ren∼ η p ⁻¹
ren∼ η (p ⦙∼ q) = ren∼ η p ⦙ ren∼ η q
ren∼ η (ƛ∼ p) = ƛ∼ (ren∼ (liftₑ η) p)
ren∼ η (p ∙∼ q) = ren∼ η p ∙∼ ren∼ η q
ren∼ η (p ,∼ q) = ren∼ η p ,∼ ren∼ η q
ren∼ η (π₁∼ p) = π₁∼ (ren∼ η p)
ren∼ η (π₂∼ p) = π₂∼ (ren∼ η p)
ren∼ η (red⇒ M N) = coe (((ƛ (ren (liftₑ η) M) ∙ ren η N) ∼_)
& rencut η N M)
(red⇒ (ren (liftₑ η) M) (ren η N))
ren∼ η (red⩕₁ M N) = red⩕₁ (ren η M) (ren η N)
ren∼ η (red⩕₂ M N) = red⩕₂ (ren η M) (ren η N)
ren∼ η (exp⇒ M) = coe ((λ M′ → ren η M ∼ ƛ (M′ ∙ 0))
& renwk η M)
(exp⇒ (ren η M))
ren∼ η (exp⩕ M) = exp⩕ (ren η M)
ren∼ η (exp⫪ M) = exp⫪ (ren η M)
--------------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.266067178,
"avg_line_length": 30.0079365079,
"ext": "agda",
"hexsha": "a929e767bb2ffca97db693d4425678f7e30a54ef",
"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": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/coquand-kovacs",
"max_forks_repo_path": "src/STLC1/Kovacs/Convertibility.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/coquand-kovacs",
"max_issues_repo_path": "src/STLC1/Kovacs/Convertibility.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/coquand-kovacs",
"max_stars_repo_path": "src/STLC1/Kovacs/Convertibility.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1759,
"size": 3781
}
|
module Perm where
open import Basics
open import All
open import Splitting
data _~_ {X : Set} : List X -> List X -> Set where
[] : [] ~ []
_,-_ : forall {x xs ys zs} -> (x ,- []) <[ ys ]> zs -> xs ~ zs -> (x ,- xs) ~ ys
permute : {X : Set}{xs ys : List X} -> xs ~ ys ->
{P : X -> Set} -> All P xs -> All P ys
permute [] <> = <>
permute (i ,- is) (p , ps) = riffle i (p , <>) (permute is ps)
reflP : {X : Set}(xs : List X) -> xs ~ xs
reflP [] = []
reflP (x ,- xs) = sl (srs xs) ,- reflP xs
insP : forall {X : Set}{x : X}{xs xs' ys ys'} -> (x ,- []) <[ xs' ]> xs -> (x ,- []) <[ ys' ]> ys
-> xs ~ ys -> xs' ~ ys'
insP (sl i) j p with isSRS i
insP (sl .(srs _)) j p | mkSRS = j ,- p
insP (sr i) j (k ,- p) =
let _ , k' , j' = llswap (_ , j , k)
in k' ,- insP i j' p
l2r : forall {X : Set}{x : X}{xs xs' ys'}(i : (x ,- []) <[ xs' ]> xs)(p' : xs' ~ ys') ->
Sg (List X) \ ys -> Sg ((x ,- []) <[ ys' ]> ys) \ j -> xs ~ ys
l2r (sl i) (j ,- p) with isSRS i
l2r (sl .(srs _)) (j ,- p) | mkSRS = _ , j , p
l2r (sr i) (k' ,- p') with l2r i p'
... | _ , j' , p with llswap (_ , k' , j')
... | _ , j , k = _ , j , (k ,- p)
transP : {X : Set}{xs ys zs : List X} -> xs ~ ys -> ys ~ zs -> xs ~ zs
transP [] [] = []
transP (i ,- p) q' with l2r i q'
... | _ , j , q = j ,- transP p q
symP : {X : Set}{xs ys : List X} -> xs ~ ys -> ys ~ xs
symP [] = []
symP (i ,- p) = insP i (sl (srs _)) (symP p)
swapP : {X : Set}(xs ys : List X) -> (xs +L ys) ~ (ys +L xs)
swapP [] ys rewrite ys +L[] = reflP ys
swapP (x ,- xs) ys = insS ys x xs ,- swapP xs ys
catP : forall {X : Set}{as bs cs ds : List X} -> as ~ cs -> bs ~ ds -> (as +L bs) ~ (cs +L ds)
catP [] q = q
catP (x ,- p) q = catS x (srs _) ,- catP p q
permap : forall {X Y}(f : X -> Y){xs xs' : List X} -> xs ~ xs' -> list f xs ~ list f xs'
permap f [] = []
permap f (x ,- p) = splimap f x ,- permap f p
cartNil : forall {I}(is : List I){J} -> cart {J = J} is [] == []
cartNil [] = refl []
cartNil (i ,- is) = cartNil is
cartCons : forall {I J}(is : List I)(j : J)(js : List J) ->
cart is (j ,- js) ~ (list (_, j) is +L cart is js)
cartCons [] j js = []
cartCons (i ,- is) j js with catP (swapP (list (i ,_) js) (list (_, j) is)) (reflP (cart is js))
... | z rewrite assoc+L (list (i ,_) js) (list (_, j) is) (cart is js)
| assoc+L (list (_, j) is) (list (i ,_) js) (cart is js)
=
(sl (srs (list (_, j) is +L cart (i ,- is) js))) ,-
transP (catP (reflP (list (i ,_) js)) (cartCons is j js))
z
cartLemma : forall {I J}(is : List I)(js : List J) ->
cart is js ~ list swap (cart js is)
cartLemma {I}{J} [] js rewrite cartNil js {I} = []
cartLemma {I}{J} (i ,- is) js with catP (reflP (list (i ,_) js)) (cartLemma is js)
... | z rewrite sym (listlist swap (_, i) (i ,_) (\ j -> refl (i , j)) js)
| catNatural swap (list (_, i) js) (cart js is)
= transP
z
(symP (permap (\ ji -> snd ji , fst ji) (cartCons js i is)))
|
{
"alphanum_fraction": 0.4750254842,
"avg_line_length": 36.3333333333,
"ext": "agda",
"hexsha": "cb5a3be9fb4d595ad18327e46cb885b084cf6247",
"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": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pigworker/InteriorDesign",
"max_forks_repo_path": "Perm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"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": "pigworker/InteriorDesign",
"max_issues_repo_path": "Perm.agda",
"max_line_length": 97,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pigworker/InteriorDesign",
"max_stars_repo_path": "Perm.agda",
"max_stars_repo_stars_event_max_datetime": "2018-07-31T02:00:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-18T15:25:39.000Z",
"num_tokens": 1206,
"size": 2943
}
|
-- Andreas, 2012-09-19 propagate irrelevance info to dot patterns
{-# OPTIONS --experimental-irrelevance #-}
-- {-# OPTIONS -v tc.lhs:20 #-}
module ShapeIrrelevantIndex where
data Nat : Set where
Z : Nat
S : Nat → Nat
data Good : ..(_ : Nat) → Set where
goo : .(n : Nat) → Good (S n)
good : .(n : Nat) → Good n → Nat
good .(S n) (goo n) = Z
|
{
"alphanum_fraction": 0.6096866097,
"avg_line_length": 23.4,
"ext": "agda",
"hexsha": "f131cfff36264337b85f667208c298a855ccf51e",
"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/ShapeIrrelevantIndex.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/ShapeIrrelevantIndex.agda",
"max_line_length": 65,
"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/ShapeIrrelevantIndex.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": 119,
"size": 351
}
|
module Pi.Examples where
open import Data.Empty
open import Data.Unit
open import Data.Sum
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Data.Nat
open import Data.Vec as V hiding (map)
open import Pi.Syntax
open import Pi.Opsem
open import Pi.Eval
pattern 𝔹 = 𝟙 +ᵤ 𝟙
pattern 𝔽 = inj₁ tt
pattern 𝕋 = inj₂ tt
𝔹^ : ℕ → 𝕌
𝔹^ 0 = 𝟙
𝔹^ 1 = 𝔹
𝔹^ (suc (suc n)) = 𝔹 ×ᵤ 𝔹^ (suc n)
-----------------------------------------------------------------------------
-- Adaptors
[A+B]+C=[C+B]+A : ∀ {A B C} → (A +ᵤ B) +ᵤ C ↔ (C +ᵤ B) +ᵤ A
[A+B]+C=[C+B]+A = assocr₊ ⨾ (id↔ ⊕ swap₊) ⨾ swap₊
[A+B]+C=[A+C]+B : ∀ {A B C} → (A +ᵤ B) +ᵤ C ↔ (A +ᵤ C) +ᵤ B
[A+B]+C=[A+C]+B = assocr₊ ⨾ (id↔ ⊕ swap₊) ⨾ assocl₊
[A+B]+[C+D]=[A+C]+[B+D] : {A B C D : 𝕌} → (A +ᵤ B) +ᵤ (C +ᵤ D) ↔ (A +ᵤ C) +ᵤ (B +ᵤ D)
[A+B]+[C+D]=[A+C]+[B+D] = assocl₊ ⨾ (assocr₊ ⊕ id↔) ⨾ ((id↔ ⊕ swap₊) ⊕ id↔) ⨾ (assocl₊ ⊕ id↔) ⨾ assocr₊
Ax[BxC]=Bx[AxC] : {A B C : 𝕌} → A ×ᵤ (B ×ᵤ C) ↔ B ×ᵤ (A ×ᵤ C)
Ax[BxC]=Bx[AxC] = assocl⋆ ⨾ (swap⋆ ⊗ id↔) ⨾ assocr⋆
[AxB]×C=[A×C]xB : ∀ {A B C} → (A ×ᵤ B) ×ᵤ C ↔ (A ×ᵤ C) ×ᵤ B
[AxB]×C=[A×C]xB = assocr⋆ ⨾ (id↔ ⊗ swap⋆) ⨾ assocl⋆
[A×B]×[C×D]=[A×C]×[B×D] : {A B C D : 𝕌} → (A ×ᵤ B) ×ᵤ (C ×ᵤ D) ↔ (A ×ᵤ C) ×ᵤ (B ×ᵤ D)
[A×B]×[C×D]=[A×C]×[B×D] = assocl⋆ ⨾ (assocr⋆ ⊗ id↔) ⨾ ((id↔ ⊗ swap⋆) ⊗ id↔) ⨾ (assocl⋆ ⊗ id↔) ⨾ assocr⋆
-- FST2LAST(b₁,b₂,…,bₙ) = (b₂,…,bₙ,b₁)
FST2LAST : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
FST2LAST {0} = id↔
FST2LAST {1} = id↔
FST2LAST {2} = swap⋆
FST2LAST {suc (suc (suc n))} = Ax[BxC]=Bx[AxC] ⨾ (id↔ ⊗ FST2LAST)
FST2LAST⁻¹ : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
FST2LAST⁻¹ = ! FST2LAST
-- NOT(b) = ¬b
NOT : 𝔹 ↔ 𝔹
NOT = swap₊
-- CNOT(b₁,b₂) = (b₁,b₁ xor b₂)
CNOT : 𝔹 ×ᵤ 𝔹 ↔ 𝔹 ×ᵤ 𝔹
CNOT = dist ⨾ (id↔ ⊕ (id↔ ⊗ swap₊)) ⨾ factor
-- CIF(c₁,c₂)(𝔽,a) = (𝔽,c₁ a)
-- CIF(c₁,c₂)(𝕋,a) = (𝕋,c₂ a)
CIF : {A : 𝕌} → (c₁ c₂ : A ↔ A) → 𝔹 ×ᵤ A ↔ 𝔹 ×ᵤ A
CIF c₁ c₂ = dist ⨾ ((id↔ ⊗ c₁) ⊕ (id↔ ⊗ c₂)) ⨾ factor
CIF₁ CIF₂ : {A : 𝕌} → (c : A ↔ A) → 𝔹 ×ᵤ A ↔ 𝔹 ×ᵤ A
CIF₁ c = CIF c id↔
CIF₂ c = CIF id↔ c
-- TOFFOLI(b₁,…,bₙ,b) = (b₁,…,bₙ,b xor (b₁ ∧ … ∧ bₙ))
TOFFOLI : {n : ℕ} → 𝔹^ n ↔ 𝔹^ n
TOFFOLI {0} = id↔
TOFFOLI {1} = swap₊
TOFFOLI {suc (suc n)} = CIF₂ TOFFOLI
-- TOFFOLI(b₁,…,bₙ,b) = (b₁,…,bₙ,b xor (¬b₁ ∧ … ∧ ¬bₙ))
TOFFOLI' : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
TOFFOLI' {0} = id↔
TOFFOLI' {1} = swap₊
TOFFOLI' {suc (suc n)} = CIF₁ TOFFOLI'
-- RESET(b₁,…,bₙ) = (b₁ xor (b₁ ∨ … ∨ bₙ),…,bₙ)
RESET : ∀ {n} → 𝔹 ×ᵤ 𝔹^ n ↔ 𝔹 ×ᵤ 𝔹^ n
RESET {0} = id↔
RESET {1} = swap⋆ ⨾ CNOT ⨾ swap⋆
RESET {suc (suc n)} = Ax[BxC]=Bx[AxC] ⨾ CIF RESET (swap₊ ⊗ id↔) ⨾ Ax[BxC]=Bx[AxC]
-----------------------------------------------------------------------------
-- Reversible Copy
-- copy(𝔽,b₁,…,bₙ) = (b₁,b₁,…,bₙ)
COPY : ∀ {n} → 𝔹 ×ᵤ 𝔹^ n ↔ 𝔹 ×ᵤ 𝔹^ n
COPY {0} = id↔
COPY {1} = swap⋆ ⨾ CNOT ⨾ swap⋆
COPY {suc (suc n)} = assocl⋆ ⨾ (COPY {1} ⊗ id↔) ⨾ assocr⋆
-----------------------------------------------------------------------------
-- Arithmetic
-- INCR(b̅) = INCR(b̅ + 1)
INCR : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
INCR {0} = id↔
INCR {1} = swap₊
INCR {suc (suc n)} = (id↔ ⊗ INCR) ⨾ FST2LAST ⨾ TOFFOLI' ⨾ FST2LAST⁻¹
iterate : (n : ℕ) → (𝔹^ n ↔ 𝔹^ n) → Vec ⟦ 𝔹^ n ⟧ (2 ^ n)
iterate n f = go initial
where
initial : ∀ {m} → ⟦ 𝔹^ m ⟧
initial {zero} = tt
initial {suc zero} = 𝔽
initial {suc (suc m)} = 𝔽 , initial
go : ∀ {m} → ⟦ 𝔹^ n ⟧ → Vec ⟦ 𝔹^ n ⟧ m
go {0} v = []
go {suc m} v = let v' = eval f v
in v ∷ go v'
INCRₜₑₛₜ = iterate 4 INCR
|
{
"alphanum_fraction": 0.4550218341,
"avg_line_length": 29.1101694915,
"ext": "agda",
"hexsha": "b46100e3dc942b4ab3dbf83f603e12f79e120733",
"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": "Pi/Examples.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": "Pi/Examples.agda",
"max_line_length": 104,
"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": "Pi/Examples.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": 2022,
"size": 3435
}
|
------------------------------------------------------------------------
-- A correct implementation of tree sort
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
-- The algorithm and the treatment of ordering information is taken
-- from Conor McBride's talk "Pivotal pragmatism".
-- The module is parametrised by a total relation.
open import Equality
open import Prelude hiding (id; _∘_; lower)
module Tree-sort.Full
{c⁺}
(eq : ∀ {a p} → Equality-with-J a p c⁺)
{A : Type}
(le : A → A → Type)
(total : ∀ x y → le x y ⊎ le y x)
where
open Derived-definitions-and-properties eq
open import Bag-equivalence eq using () renaming (Any to AnyL)
open import Bijection eq using (_↔_)
open import Function-universe eq hiding (Kind; module Kind)
open import List eq
------------------------------------------------------------------------
-- Extending the order with new minimum and maximum elements
-- A extended with a new minimum and maximum.
data Extended : Type where
min max : Extended
[_] : (x : A) → Extended
infix 4 _≤_
_≤_ : Extended → Extended → Type
min ≤ y = ⊤
[ x ] ≤ [ y ] = le x y
x ≤ max = ⊤
_ ≤ _ = ⊥
-- A pair of ordering constraints (written as a record type to aid
-- type inference).
infix 4 _,_
record _≤[_]≤_ (l : Extended) (x : A) (u : Extended) : Type where
constructor _,_
field
lower : l ≤ [ x ]
upper : [ x ] ≤ u
------------------------------------------------------------------------
-- Ordered lists
data Ordered-list (l u : Extended) : Type where
nil : (l≤u : l ≤ u) → Ordered-list l u
cons : (x : A) (xs : Ordered-list [ x ] u) (l≤x : l ≤ [ x ]) →
Ordered-list l u
-- Conversion to ordinary lists.
to-list : ∀ {l u} → Ordered-list l u → List A
to-list (nil l≤u) = []
to-list (cons x xs l≤x) = x ∷ to-list xs
------------------------------------------------------------------------
-- Unbalanced binary search trees
infix 5 node
syntax node x lx xu = lx -[ x ]- xu
data Search-tree (l u : Extended) : Type where
leaf : (l≤u : l ≤ u) → Search-tree l u
node : (x : A) (lx : Search-tree l [ x ]) (xu : Search-tree [ x ] u) →
Search-tree l u
-- Any.
AnyT : ∀ {l u} → (A → Type) → Search-tree l u → Type
AnyT P (leaf _) = ⊥
AnyT P (node x l r) = AnyT P l ⊎ P x ⊎ AnyT P r
------------------------------------------------------------------------
-- An ad-hoc universe consisting of lists, ordered lists and search
-- trees
-- The purpose of this universe is to allow overloading of Any, _∈_
-- and _≈-bag_.
-- Codes.
data Kind : Type where
list ordered-list search-tree : Kind
-- Index type.
--
-- Note that Agda infers values of type ⊤ automatically.
Index : Kind → Type
Index list = ⊤
Index _ = Extended
-- Interpretation.
⟦_⟧ : (k : Kind) → (Index k → Index k → Type)
⟦ list ⟧ _ _ = List A
⟦ ordered-list ⟧ l u = Ordered-list l u
⟦ search-tree ⟧ l u = Search-tree l u
-- Any.
Any : ∀ {k l u} → (A → Type) → (⟦ k ⟧ l u → Type)
Any {list} = AnyL
Any {ordered-list} = λ P → AnyL P ∘ to-list
Any {search-tree} = AnyT
-- Membership.
infix 4 _∈_
_∈_ : ∀ {k l u} → A → ⟦ k ⟧ l u → Type
x ∈ xs = Any (λ y → x ≡ y) xs
-- Bag equivalence.
infix 4 _≈-bag_
_≈-bag_ : ∀ {k₁ k₂ l₁ u₁ l₂ u₂} → ⟦ k₁ ⟧ l₁ u₁ → ⟦ k₂ ⟧ l₂ u₂ → Type
xs ≈-bag ys = ∀ z → z ∈ xs ↔ z ∈ ys
------------------------------------------------------------------------
-- Singleton trees
singleton : ∀ {l u} (x : A) → l ≤[ x ]≤ u → Search-tree l u
singleton x (l≤x , x≤u) = leaf l≤x -[ x ]- leaf x≤u
-- Any lemma for singleton.
Any-singleton : ∀ (P : A → Type) {l u x} (l≤x≤u : l ≤[ x ]≤ u) →
Any P (singleton x l≤x≤u) ↔ P x
Any-singleton P {x = x} l≤x≤u =
Any P (singleton x l≤x≤u) ↔⟨⟩
⊥ ⊎ P x ⊎ ⊥ ↔⟨ ⊎-left-identity ⟩
P x ⊎ ⊥ ↔⟨ ⊎-right-identity ⟩
P x □
------------------------------------------------------------------------
-- Insertion into a search tree
insert : ∀ {l u} (x : A) → Search-tree l u → l ≤[ x ]≤ u →
Search-tree l u
insert x (leaf _) l≤x≤u = singleton x l≤x≤u
insert x (ly -[ y ]- yu) (l≤x , x≤u) with total x y
... | inj₁ x≤y = insert x ly (l≤x , x≤y) -[ y ]- yu
... | inj₂ y≤x = ly -[ y ]- insert x yu (y≤x , x≤u)
-- Any lemma for insert.
Any-insert : ∀ (P : A → Type) {l u} x t (l≤x≤u : l ≤[ x ]≤ u) →
Any P (insert x t l≤x≤u) ↔ P x ⊎ Any P t
Any-insert P {l} {u} x (leaf l≤u) l≤x≤u =
Any P (singleton x l≤x≤u) ↔⟨ Any-singleton P l≤x≤u ⟩
P x ↔⟨ inverse ⊎-right-identity ⟩
P x ⊎ ⊥ ↔⟨⟩
P x ⊎ Any P (leaf {l = l} {u = u} l≤u) □
Any-insert P x (ly -[ y ]- yu) (l≤x , x≤u) with total x y
... | inj₁ x≤y =
Any P (insert x ly (l≤x , x≤y)) ⊎ P y ⊎ Any P yu ↔⟨ Any-insert P x ly (l≤x , x≤y) ⊎-cong id ⟩
(P x ⊎ Any P ly) ⊎ P y ⊎ Any P yu ↔⟨ inverse ⊎-assoc ⟩
P x ⊎ Any P ly ⊎ P y ⊎ Any P yu □
... | inj₂ y≤x =
Any P ly ⊎ P y ⊎ Any P (insert x yu (y≤x , x≤u)) ↔⟨ id ⊎-cong id ⊎-cong Any-insert P x yu (y≤x , x≤u) ⟩
Any P ly ⊎ P y ⊎ P x ⊎ Any P yu ↔⟨ lemma _ _ _ _ ⟩
P x ⊎ Any P ly ⊎ P y ⊎ Any P yu □
where
-- The following lemma is easy to prove automatically (for
-- instance by using a ring solver).
lemma : (A B C D : Type) → A ⊎ B ⊎ C ⊎ D ↔ C ⊎ A ⊎ B ⊎ D
lemma A B C D =
A ⊎ B ⊎ C ⊎ D ↔⟨ id ⊎-cong ⊎-assoc ⟩
A ⊎ (B ⊎ C) ⊎ D ↔⟨ id ⊎-cong ⊎-comm ⊎-cong id ⟩
A ⊎ (C ⊎ B) ⊎ D ↔⟨ ⊎-assoc ⟩
(A ⊎ C ⊎ B) ⊎ D ↔⟨ ⊎-assoc ⊎-cong id ⟩
((A ⊎ C) ⊎ B) ⊎ D ↔⟨ (⊎-comm ⊎-cong id) ⊎-cong id ⟩
((C ⊎ A) ⊎ B) ⊎ D ↔⟨ inverse ⊎-assoc ⊎-cong id ⟩
(C ⊎ A ⊎ B) ⊎ D ↔⟨ inverse ⊎-assoc ⟩
C ⊎ (A ⊎ B) ⊎ D ↔⟨ id ⊎-cong inverse ⊎-assoc ⟩
C ⊎ A ⊎ B ⊎ D □
------------------------------------------------------------------------
-- Turning an unordered list into a search tree
to-search-tree : List A → Search-tree min max
to-search-tree = foldr (λ x t → insert x t _) (leaf _)
-- No elements are added or removed.
to-search-tree-lemma : ∀ xs → to-search-tree xs ≈-bag xs
to-search-tree-lemma [] = λ z →
z ∈ leaf {l = min} {u = max} _ ↔⟨⟩
z ∈ [] □
to-search-tree-lemma (x ∷ xs) = λ z →
z ∈ insert x (to-search-tree xs) _ ↔⟨ Any-insert (λ x → z ≡ x) _ _ _ ⟩
z ≡ x ⊎ z ∈ to-search-tree xs ↔⟨ id ⊎-cong to-search-tree-lemma xs z ⟩
z ∈ x ∷ xs □
------------------------------------------------------------------------
-- Appending two ordered lists with an extra element in between
infixr 5 append
syntax append x lx xu = lx -⁅ x ⁆- xu
append : ∀ {l u} (x : A) →
Ordered-list l [ x ] → Ordered-list [ x ] u → Ordered-list l u
nil l≤x -⁅ x ⁆- xu = cons x xu l≤x
cons y yx l≤y -⁅ x ⁆- xu = cons y (yx -⁅ x ⁆- xu) l≤y
-- Any lemma for append.
Any-append : ∀ (P : A → Type) {l u} x
(lx : Ordered-list l [ x ]) (xu : Ordered-list [ x ] u) →
Any P (lx -⁅ x ⁆- xu) ↔ Any P lx ⊎ P x ⊎ Any P xu
Any-append P x (nil l≤x) xu =
P x ⊎ Any P xu ↔⟨ inverse ⊎-left-identity ⟩
⊥ ⊎ P x ⊎ Any P xu □
Any-append P x (cons y yx l≤y) xu =
P y ⊎ Any P (append x yx xu) ↔⟨ id ⊎-cong Any-append P x yx xu ⟩
P y ⊎ Any P yx ⊎ P x ⊎ Any P xu ↔⟨ ⊎-assoc ⟩
(P y ⊎ Any P yx) ⊎ P x ⊎ Any P xu □
------------------------------------------------------------------------
-- Inorder flattening of a tree
flatten : ∀ {l u} → Search-tree l u → Ordered-list l u
flatten (leaf l≤u) = nil l≤u
flatten (l -[ x ]- r) = flatten l -⁅ x ⁆- flatten r
-- Flatten does not add or remove any elements.
flatten-lemma : ∀ {l u} (t : Search-tree l u) → flatten t ≈-bag t
flatten-lemma {l} {u} (leaf l≤u) = λ z →
z ∈ nil {l = l} {u = u} l≤u ↔⟨⟩
z ∈ leaf {l = l} {u = u} l≤u □
flatten-lemma (l -[ x ]- r) = λ z →
z ∈ flatten l -⁅ x ⁆- flatten r ↔⟨ Any-append (λ x → z ≡ x) _ _ _ ⟩
z ∈ flatten l ⊎ z ≡ x ⊎ z ∈ flatten r ↔⟨ flatten-lemma l z ⊎-cong id ⊎-cong flatten-lemma r z ⟩
z ∈ l ⊎ z ≡ x ⊎ z ∈ r ↔⟨⟩
z ∈ l -[ x ]- r □
------------------------------------------------------------------------
-- Sorting
-- Sorts a list.
tree-sort : List A → Ordered-list min max
tree-sort = flatten ∘ to-search-tree
-- The result is a permutation of the input.
tree-sort-permutes : ∀ xs → tree-sort xs ≈-bag xs
tree-sort-permutes xs = λ z →
z ∈ tree-sort xs ↔⟨⟩
z ∈ flatten (to-search-tree xs) ↔⟨ flatten-lemma (to-search-tree xs) _ ⟩
z ∈ to-search-tree xs ↔⟨ to-search-tree-lemma xs _ ⟩
z ∈ xs □
|
{
"alphanum_fraction": 0.4658441855,
"avg_line_length": 31.7173913043,
"ext": "agda",
"hexsha": "2282e1017923041a2ad2186e11e44a17efde8659",
"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/Tree-sort/Full.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/Tree-sort/Full.agda",
"max_line_length": 106,
"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/Tree-sort/Full.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": 3186,
"size": 8754
}
|
module Issue734a where
module M₁ (Z : Set₁) where
postulate
P : Set
Q : Set → Set
module M₂ (X Y : Set) where
module M₁′ = M₁ Set
open M₁′
p : P
p = {!!}
-- Previous and current agda2-goal-and-context:
-- Y : Set
-- X : Set
-- ---------
-- Goal: P
q : Q X
q = {!!}
-- Previous and current agda2-goal-and-context:
-- Y : Set
-- X : Set
-- -----------
-- Goal: Q X
postulate X : Set
pp : M₂.M₁′.P X X
pp = {!!}
-- Previous agda2-goal-and-context:
-- ----------------
-- Goal: M₁.P Set
-- Current agda2-goal-and-context:
-- --------------------
-- Goal: M₂.M₁′.P X X
|
{
"alphanum_fraction": 0.4747634069,
"avg_line_length": 13.2083333333,
"ext": "agda",
"hexsha": "dc6ef7a1c631933beed92000c1544c40d5843d14",
"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/interaction/Issue734a.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/interaction/Issue734a.agda",
"max_line_length": 49,
"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/interaction/Issue734a.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": 223,
"size": 634
}
|
{-# OPTIONS --prop --rewriting #-}
module Examples.Gcd where
open import Examples.Gcd.Euclid public
open import Examples.Gcd.Clocked public
open import Examples.Gcd.Spec public
open import Examples.Gcd.Refine public
|
{
"alphanum_fraction": 0.7935779817,
"avg_line_length": 24.2222222222,
"ext": "agda",
"hexsha": "07fd1a4fac9b44dc5614d380d54680ed6f3bc6e9",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Examples/Gcd.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Examples/Gcd.agda",
"max_line_length": 39,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Examples/Gcd.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 50,
"size": 218
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.GradedRing.Instances.Polynomials where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Data.Unit
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.Vec
open import Cubical.Data.Vec.OperationsNat
open import Cubical.Data.Sigma
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Monoid.Instances.NatVec
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.AbGroup.Instances.Unit
open import Cubical.Algebra.DirectSum.DirectSumHIT.Base
open import Cubical.Algebra.Ring
open import Cubical.Algebra.GradedRing.Base
open import Cubical.Algebra.GradedRing.DirectSumHIT
private variable
ℓ : Level
open Iso
open GradedRing-⊕HIT-index
open GradedRing-⊕HIT-⋆
module _
(ARing@(A , Astr) : Ring ℓ)
(n : ℕ)
where
open RingStr Astr
open RingTheory ARing
PolyGradedRing : GradedRing ℓ-zero ℓ
PolyGradedRing = makeGradedRingSelf
(NatVecMonoid n)
(λ _ → A)
(λ _ → snd (Ring→AbGroup ARing))
1r _·_ 0LeftAnnihilates 0RightAnnihilates
(λ a b c → ΣPathP ((+n-vec-assoc _ _ _) , (·Assoc _ _ _)))
(λ a → ΣPathP ((+n-vec-rid _) , (·IdR _)))
(λ a → ΣPathP ((+n-vec-lid _) , (·IdL _)))
·DistR+
·DistL+
|
{
"alphanum_fraction": 0.676132522,
"avg_line_length": 30.1836734694,
"ext": "agda",
"hexsha": "82f0f4b40b20b92c6a7d10d791fa11911e158d76",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/GradedRing/Instances/Polynomials.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/GradedRing/Instances/Polynomials.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/GradedRing/Instances/Polynomials.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 438,
"size": 1479
}
|
module std-lib where
open import IO using (IO; run; putStrLn; _>>_)
open import Data.Unit using (⊤)
open import Codata.Musical.Notation using (♯_)
import Agda.Builtin.IO using (IO)
open import Function using (_$_)
main1 : Agda.Builtin.IO.IO ⊤
main1 = run (♯ putStrLn "hallo" >> ♯ putStrLn "welt")
main2 : Agda.Builtin.IO.IO ⊤
main2 = run (do
♯ putStrLn "hallo"
♯ putStrLn "welt"
)
main3 : Agda.Builtin.IO.IO ⊤
main3 = run $ do
♯ putStrLn "hallo"
♯ putStrLn "welt"
main4 : Agda.Builtin.IO.IO ⊤
main4 = run $ do
♯ putStrLn "hallo"
♯ (do
♯ putStrLn "welt"
♯ putStrLn "!")
main : Agda.Builtin.IO.IO ⊤
main = main3
|
{
"alphanum_fraction": 0.6510172144,
"avg_line_length": 19.3636363636,
"ext": "agda",
"hexsha": "47a1cc56958cbb119cf1670967207f8d33585773",
"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": "112a706f266941d6ec8cb107d18476f9d7ffbbc6",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "neosimsim/merkdas",
"max_forks_repo_path": "agda-coinductive-io/std-lib.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "112a706f266941d6ec8cb107d18476f9d7ffbbc6",
"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": "neosimsim/merkdas",
"max_issues_repo_path": "agda-coinductive-io/std-lib.agda",
"max_line_length": 53,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "112a706f266941d6ec8cb107d18476f9d7ffbbc6",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "neosimsim/merkdas",
"max_stars_repo_path": "agda-coinductive-io/std-lib.agda",
"max_stars_repo_stars_event_max_datetime": "2020-05-26T08:08:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-26T08:08:13.000Z",
"num_tokens": 227,
"size": 639
}
|
module Sessions.Syntax.Values where
open import Prelude hiding (both)
open import Relation.Unary
open import Data.Maybe
open import Data.List.Properties using (++-isMonoid)
import Data.List as List
open import Sessions.Syntax.Types
open import Sessions.Syntax.Expr
open import Relation.Ternary.Separation.Morphisms
data Runtype : Set where
endp : SType → Runtype
chan : SType → SType → Runtype
flipped : Runtype → Runtype
flipped (endp x) = endp x
flipped (chan α β) = chan β α
data Ends : Runtype → Runtype → Runtype → Set where
lr : ∀ {a b} → Ends (endp a) (endp b) (chan a b)
rl : ∀ {a b} → Ends (endp b) (endp a) (chan a b)
instance
≺-raw-sep : RawSep Runtype
RawSep._⊎_≣_ ≺-raw-sep = Ends
≺-has-sep : IsSep ≺-raw-sep
IsSep.⊎-comm ≺-has-sep lr = rl
IsSep.⊎-comm ≺-has-sep rl = lr
IsSep.⊎-assoc ≺-has-sep lr ()
IsSep.⊎-assoc ≺-has-sep rl ()
RCtx = List Runtype
open import Relation.Ternary.Separation.Construct.ListOf Runtype public
End : SType → Runtype → Set
End α τ = [ endp α ] ≤ [ τ ]
ending : ∀ {ys} → Ends (endp γ) ys (chan α β) → End γ (chan α β)
ending lr = -, divide lr ⊎-idˡ
ending rl = -, divide rl ⊎-idˡ
mutual
Env = Allstar Val
data Closure : Type → Type → Pred RCtx 0ℓ where
clos : ∀ {a} → Exp b (a ∷ Γ) → ∀[ Env Γ ⇒ Closure a b ]
Endptr = Just ∘ endp
data Val : Type → Pred RCtx 0ℓ where
tt : ε[ Val unit ]
cref : ∀[ Endptr α ⇒ Val (cref α) ]
pairs : ∀[ Val a ✴ Val b ⇒ Val (prod a b) ]
clos : Exp b (a ∷ Γ) → ∀[ Env Γ ⇒ Val (a ⊸ b) ]
|
{
"alphanum_fraction": 0.629653821,
"avg_line_length": 25.9491525424,
"ext": "agda",
"hexsha": "8dab7e1e53e63b4912348c8a2d014baefb226878",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z",
"max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/linear.agda",
"max_forks_repo_path": "src/Sessions/Syntax/Values.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "laMudri/linear.agda",
"max_issues_repo_path": "src/Sessions/Syntax/Values.agda",
"max_line_length": 71,
"max_stars_count": 34,
"max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/linear.agda",
"max_stars_repo_path": "src/Sessions/Syntax/Values.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z",
"num_tokens": 570,
"size": 1531
}
|
-- Jesper, 2018-10-16: When solving constraints produces a term which
-- contains the same unsolved metavariable twice, only the first
-- occurrence should be turned into an interaction hole.
open import Agda.Builtin.Equality
postulate Id : (A : Set) → A → A → Set
allq : (∀ m n → Id _ m n) ≡ {!!}
allq = refl
|
{
"alphanum_fraction": 0.6996805112,
"avg_line_length": 28.4545454545,
"ext": "agda",
"hexsha": "32b3534ec60a23bbdf6923f125073cebe7dd92ee",
"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/Issue2273b.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/Issue2273b.agda",
"max_line_length": 69,
"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/Issue2273b.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": 91,
"size": 313
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Products
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Product where
open import Function
open import Level
open import Relation.Nullary
open import Agda.Builtin.Equality
infixr 4 _,′_
infix 4 -,_
infixr 2 _×_ _-×-_ _-,-_
------------------------------------------------------------------------
-- Definition
open import Agda.Builtin.Sigma hiding (module Σ) public renaming (fst to proj₁; snd to proj₂)
module Σ = Agda.Builtin.Sigma.Σ renaming (fst to proj₁; snd to proj₂)
-- The syntax declaration below is attached to Σ-syntax, to make it
-- easy to import Σ without the special syntax.
infix 2 Σ-syntax
Σ-syntax : ∀ {a b} (A : Set a) → (A → Set b) → Set (a ⊔ b)
Σ-syntax = Σ
syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B
∃ : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b)
∃ = Σ _
∃-syntax : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b)
∃-syntax = ∃
syntax ∃-syntax (λ x → B) = ∃[ x ] B
∄ : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b)
∄ P = ¬ ∃ P
∄-syntax : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b)
∄-syntax = ∄
syntax ∄-syntax (λ x → B) = ∄[ x ] B
∃₂ : ∀ {a b c} {A : Set a} {B : A → Set b}
(C : (x : A) → B x → Set c) → Set (a ⊔ b ⊔ c)
∃₂ C = ∃ λ a → ∃ λ b → C a b
_×_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a ⊔ b)
A × B = Σ[ x ∈ A ] B
_,′_ : ∀ {a b} {A : Set a} {B : Set b} → A → B → A × B
_,′_ = _,_
------------------------------------------------------------------------
-- Unique existence
-- Parametrised on the underlying equality.
∃! : ∀ {a b ℓ} {A : Set a} →
(A → A → Set ℓ) → (A → Set b) → Set (a ⊔ b ⊔ ℓ)
∃! _≈_ B = ∃ λ x → B x × (∀ {y} → B y → x ≈ y)
------------------------------------------------------------------------
-- Functions
-- Sometimes the first component can be inferred.
-,_ : ∀ {a b} {A : Set a} {B : A → Set b} {x} → B x → ∃ B
-, y = _ , y
<_,_> : ∀ {a b c} {A : Set a} {B : A → Set b} {C : ∀ {x} → B x → Set c}
(f : (x : A) → B x) → ((x : A) → C (f x)) →
((x : A) → Σ (B x) C)
< f , g > x = (f x , g x)
map : ∀ {a b p q}
{A : Set a} {B : Set b} {P : A → Set p} {Q : B → Set q} →
(f : A → B) → (∀ {x} → P x → Q (f x)) →
Σ A P → Σ B Q
map f g (x , y) = (f x , g y)
map₁ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
(A → B) → A × C → B × C
map₁ f = map f id
map₂ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : A → Set c} →
(∀ {x} → B x → C x) → Σ A B → Σ A C
map₂ f = map id f
zip : ∀ {a b c p q r}
{A : Set a} {B : Set b} {C : Set c}
{P : A → Set p} {Q : B → Set q} {R : C → Set r} →
(_∙_ : A → B → C) →
(∀ {x y} → P x → Q y → R (x ∙ y)) →
Σ A P → Σ B Q → Σ C R
zip _∙_ _∘_ (a , p) (b , q) = ((a ∙ b) , (p ∘ q))
swap : ∀ {a b} {A : Set a} {B : Set b} → A × B → B × A
swap (x , y) = (y , x)
_-×-_ : ∀ {a b i j} {A : Set a} {B : Set b} →
(A → B → Set i) → (A → B → Set j) → (A → B → Set _)
f -×- g = f -[ _×_ ]- g
_-,-_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
(A → B → C) → (A → B → D) → (A → B → C × D)
f -,- g = f -[ _,_ ]- g
curry : ∀ {a b c} {A : Set a} {B : A → Set b} {C : Σ A B → Set c} →
((p : Σ A B) → C p) →
((x : A) → (y : B x) → C (x , y))
curry f x y = f (x , y)
curry′ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
(A × B → C) → (A → B → C)
curry′ = curry
uncurry : ∀ {a b c} {A : Set a} {B : A → Set b} {C : Σ A B → Set c} →
((x : A) → (y : B x) → C (x , y)) →
((p : Σ A B) → C p)
uncurry f (x , y) = f x y
uncurry′ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
(A → B → C) → (A × B → C)
uncurry′ = uncurry
|
{
"alphanum_fraction": 0.3741748086,
"avg_line_length": 28.0518518519,
"ext": "agda",
"hexsha": "13a7711e4f124b1618b713d99240a893e9c3747c",
"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/Product.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/Product.agda",
"max_line_length": 93,
"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/Product.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1621,
"size": 3787
}
|
module New where
module _ where
open import Agda.Primitive
record IsBottom {ℓ-⊥} (⊥ : Set ℓ-⊥) ℓ-elim : Set (lsuc ℓ-elim ⊔ ℓ-⊥) where
field
⊥-elim : ⊥ → {A : Set ℓ-elim} → A
open IsBottom ⦃ … ⦄ public
record Bottom ℓ-⊥ ℓ-elim : Set (lsuc (ℓ-elim ⊔ ℓ-⊥)) where
field
⊥ : Set ℓ-⊥
instance ⦃ isBottom ⦄ : IsBottom ⊥ ℓ-elim
¬_ : ∀ {a} → Set a → Set (a ⊔ ℓ-⊥)
¬_ p = p → ⊥
open Bottom ⦃ … ⦄ public
record IsEquivalence {a} {A : Set a} {ℓ} (_≈_ : A → A → Set ℓ) : Set (a ⊔ ℓ) where
field
reflexivity : ∀ x → x ≈ x
symmetry : ∀ x y → x ≈ y → y ≈ x
transitivity : ∀ x y z → x ≈ y → y ≈ z → x ≈ z
open IsEquivalence ⦃ … ⦄ public
record Equivalence {a} (A : Set a) ℓ : Set (a ⊔ lsuc ℓ) where
infix 4 _≈_
field
_≈_ : A → A → Set ℓ
⦃ isEquivalence ⦄ : IsEquivalence _≈_
open Equivalence ⦃ … ⦄ public
{-# DISPLAY Equivalence._≈_ _ = _≈_ #-}
infix 4 _≉_
_≉_ : ∀ {a} {A : Set a} {ℓ} ⦃ _ : Equivalence A ℓ ⦄ {b} ⦃ _ : Bottom b ℓ ⦄ → A → A → Set (b ⊔ ℓ)
_≉_ {ℓ = ℓ} x y = ¬ (x ≈ y)
record _and_ {ℓ} (A : Set ℓ) (B : Set ℓ) : Set ℓ where
field
and₁ : A
and₂ : B
record _NOR_ {ℓ} (A : Set ℓ) (B : Set ℓ) : Set (lsuc ℓ) where
field
⦃ bottom ⦄ : Bottom ℓ ℓ
nor₁ : A → ⊥
nor₂ : B → ⊥
NOT : ∀ {ℓ} (A : Set ℓ) → Set (lsuc ℓ)
NOT A = A NOR A
_AND_ : ∀ {ℓ} (A B : Set ℓ) → Set (lsuc (lsuc ℓ))
_AND_ A B = (NOT A) NOR (NOT B)
_OR_ : ∀ {ℓ} (A B : Set ℓ) → Set (lsuc (lsuc ℓ))
_OR_ A B = NOT (A NOR B)
record Natlike {a} (A : Set a) ℓ b : Set (lsuc (b ⊔ a ⊔ ℓ)) where
field
zero : A
suc : A → A
⦃ equivalence ⦄ : Equivalence A ℓ
⦃ bottom ⦄ : Bottom b ℓ
suc-inj : ∀ {x} {y} → suc x ≈ suc y → x ≈ y
cong-suc : ∀ {x y} → x ≈ y → suc x ≈ suc y
zero≉one : zero ≉ suc zero
zero-is-bottommost : ∀ x → suc x ≉ zero
break-suc1 : suc zero ≉ suc (suc zero)
break-suc1 x = zero≉one (suc-inj x)
break-suc : ∀ x → suc x ≉ suc (suc x)
break-suc x x₁ = {!suc-inj x₁!}
record Isomorphic {a} (A : Set a) ℓᵃ ⦃ _ : Equivalence A ℓᵃ ⦄ {b} (B : Set b) ℓᵇ ⦃ _ : Equivalence B ℓᵇ ⦄ : Set (a ⊔ ℓᵃ ⊔ b ⊔ ℓᵇ) where
field
toB : A → B
toA : B → A
isoA : ∀ x → toA (toB x) ≈ x
isoB : ∀ x → toB (toA x) ≈ x
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
instance IsEquivalence≡ : ∀ {a} {A : Set a} → IsEquivalence {a} {A} _≡_
IsEquivalence.reflexivity IsEquivalence≡ x = refl
IsEquivalence.symmetry IsEquivalence≡ x .x refl = refl
IsEquivalence.transitivity IsEquivalence≡ x .x z refl x₂ = x₂
module _ where
open import Prelude using (it)
instance EquivalenceNat : Equivalence Nat lzero
Equivalence._≈_ EquivalenceNat = _≡_
record NatIso {a} (A : Set a) ℓ : Set (a ⊔ lsuc ℓ) where
field
⦃ equivalence ⦄ : Equivalence A ℓ
isoNat : Isomorphic A ℓ Nat lzero
record Op₂ {a} (A : Set a) : Set a where
infixl 6 _∙_
field
_∙_ : A → A → A
open Op₂ ⦃ … ⦄ public
record Op₀ {a} (A : Set a) : Set a where
field
ε : A
open Op₀ ⦃ … ⦄ public
record MonoidWithSuc {a} (A : Set a) : Set a where
field
instance op2 : Op₂ A
op0 : Op₀ A
¡ : A → A
open MonoidWithSuc ⦃ … ⦄ public
private
module ZC where
private
module ASD where
open import Prelude.Nat using ()
instance MonoidWithSucLevel : MonoidWithSuc Level
Op₂._∙_ (MonoidWithSuc.op2 MonoidWithSucLevel) = _⊔_
Op₀.ε (MonoidWithSuc.op0 MonoidWithSucLevel) = lzero
MonoidWithSuc.¡ MonoidWithSucLevel = lsuc
module _ where
open import Agda.Builtin.Nat
instance MonoidWithSucNat : MonoidWithSuc Nat
Op₂._∙_ (MonoidWithSuc.op2 MonoidWithSucNat) = _+_
Op₀.ε (MonoidWithSuc.op0 MonoidWithSucNat) = 0
MonoidWithSuc.¡ MonoidWithSucNat = suc
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
instance op0fromm : ∀ {a} {A : Set a} ⦃ _ : MonoidWithSuc A ⦄ → Op₀ A
op0fromm = op0
module _ where
private
foo : Nat → Set (¡ ε)
foo x = x ∙ x ≡ x → Set
bar : 4 ∙ 2 ≡ Nat.suc 5
bar = refl
module _ where
open import Agda.Primitive
infix -65536 ℞_
℞_ : ∀ ℓ → Set (lsuc ℓ)
℞_ ℓ = Set ℓ
module _ where
open import Agda.Primitive
|
{
"alphanum_fraction": 0.5646481178,
"avg_line_length": 24.7225433526,
"ext": "agda",
"hexsha": "977507fa9b787ee136b0357eb70cd9a4f8c784dd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/New.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/New.agda",
"max_line_length": 137,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/New.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1843,
"size": 4277
}
|
-- Andreas, 2022-06-10
-- A failed attempt to break Prop ≤ Set.
-- See https://github.com/agda/agda/issues/5761#issuecomment-1151336715
{-# OPTIONS --prop --cumulativity #-}
data ⊥ : Set where
record ⊤ : Set where
constructor tt
data Fool : Prop where
true false : Fool
Bool : Set
Bool = Fool
True : Bool → Set
True true = ⊤
True false = ⊥
X : Fool → Set
true≡false : X true → X false
true≡false x = x
X = True
-- Now we have True true → True false which looks dangerous...
-- But we cannot exploit it:
fails : ⊥
fails = true≡false tt
-- ERROR:
-- ⊤ !=< (True _)
-- when checking that the expression tt has type X _
|
{
"alphanum_fraction": 0.6525157233,
"avg_line_length": 17.1891891892,
"ext": "agda",
"hexsha": "5a435557ff2081efb12f45d6c5e778bb6b7ac13e",
"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/PropCumulative.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Fail/PropCumulative.agda",
"max_line_length": 71,
"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/PropCumulative.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 198,
"size": 636
}
|
{-# OPTIONS --without-K --safe #-}
-- | Exclusive option. Exactly one of the options holds at the same time.
module Dodo.Nullary.XOpt where
-- Stdlib imports
open import Level using (Level; _⊔_)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Relation.Nullary using (¬_; Dec; yes; no)
-- # XOpt₂
data XOpt₂ {a b : Level} (A : Set a) (B : Set b) : Set (a ⊔ b) where
xopt₁ : ( a : A) → (¬b : ¬ B) → XOpt₂ A B
xopt₂ : (¬a : ¬ A) → ( b : B) → XOpt₂ A B
xopt₂-apply : {a b c : Level} {A : Set a} {B : Set b} {C : Set c}
→ ( A → C )
→ ( B → C )
-----------------
→ ( XOpt₂ A B → C )
xopt₂-apply f g (xopt₁ a _) = f a
xopt₂-apply f g (xopt₂ _ b) = g b
xopt₂-dec₁ : {a b : Level} {A : Set a} {B : Set b} → XOpt₂ A B → Dec A
xopt₂-dec₁ (xopt₁ a ¬b) = yes a
xopt₂-dec₁ (xopt₂ ¬a b) = no ¬a
xopt₂-dec₂ : {a b : Level} {A : Set a} {B : Set b} → XOpt₂ A B → Dec B
xopt₂-dec₂ (xopt₁ a ¬b) = no ¬b
xopt₂-dec₂ (xopt₂ ¬a b) = yes b
xopt₂-elim₁ : {a b : Level} {A : Set a} {B : Set b} → ¬ A → XOpt₂ A B → B
xopt₂-elim₁ ¬a (xopt₁ a ¬b) = ⊥-elim (¬a a)
xopt₂-elim₁ _ (xopt₂ ¬a b) = b
xopt₂-elim₂ : {a b : Level} {A : Set a} {B : Set b} → ¬ B → XOpt₂ A B → A
xopt₂-elim₂ _ (xopt₁ a ¬b) = a
xopt₂-elim₂ ¬b (xopt₂ ¬a b) = ⊥-elim (¬b b)
xopt₂-select₁ : {a b : Level} {A : Set a} {B : Set b} → A → XOpt₂ A B → ¬ B
xopt₂-select₁ _ (xopt₁ _ ¬b) = ¬b
xopt₂-select₁ a (xopt₂ ¬a _) = ⊥-elim (¬a a)
xopt₂-select₂ : {a b : Level} {A : Set a} {B : Set b} → B → XOpt₂ A B → ¬ A
xopt₂-select₂ b (xopt₁ _ ¬b) = ⊥-elim (¬b b)
xopt₂-select₂ b (xopt₂ ¬a _) = ¬a
xopt₂-sum : {a b : Level} {A : Set a} {B : Set b} → XOpt₂ A B → A ⊎ B
xopt₂-sum (xopt₁ a _) = inj₁ a
xopt₂-sum (xopt₂ _ b) = inj₂ b
-- # XOpt₃
data XOpt₃ {a b c : Level} (A : Set a) (B : Set b) (C : Set c) : Set (a ⊔ b ⊔ c) where
xopt₁ : ( a : A) → (¬b : ¬ B) → (¬c : ¬ C) → XOpt₃ A B C
xopt₂ : (¬a : ¬ A) → ( b : B) → (¬c : ¬ C) → XOpt₃ A B C
xopt₃ : (¬a : ¬ A) → (¬b : ¬ B) → ( c : C) → XOpt₃ A B C
xopt₃-apply : {a b c d : Level} {A : Set a} {B : Set b} {C : Set c} {D : Set d}
→ ( A → D )
→ ( B → D )
→ ( C → D )
-------------------
→ ( XOpt₃ A B C → D )
xopt₃-apply f g h (xopt₁ a _ _) = f a
xopt₃-apply f g h (xopt₂ _ b _) = g b
xopt₃-apply f g h (xopt₃ _ _ c) = h c
xopt₃-dec₁ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → XOpt₃ A B C → Dec A
xopt₃-dec₁ (xopt₁ a _ _) = yes a
xopt₃-dec₁ (xopt₂ ¬a _ _) = no ¬a
xopt₃-dec₁ (xopt₃ ¬a _ _) = no ¬a
xopt₃-dec₂ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → XOpt₃ A B C → Dec B
xopt₃-dec₂ (xopt₁ _ ¬b _) = no ¬b
xopt₃-dec₂ (xopt₂ _ b _) = yes b
xopt₃-dec₂ (xopt₃ _ ¬b _) = no ¬b
xopt₃-dec₃ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → XOpt₃ A B C → Dec C
xopt₃-dec₃ (xopt₁ _ _ ¬c) = no ¬c
xopt₃-dec₃ (xopt₂ _ _ ¬c) = no ¬c
xopt₃-dec₃ (xopt₃ _ _ c) = yes c
xopt₃-elim₁ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → ¬ A → XOpt₃ A B C → XOpt₂ B C
xopt₃-elim₁ ¬a (xopt₁ a _ _) = ⊥-elim (¬a a)
xopt₃-elim₁ _ (xopt₂ _ b ¬c) = xopt₁ b ¬c
xopt₃-elim₁ _ (xopt₃ _ ¬b c) = xopt₂ ¬b c
xopt₃-elim₂ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → ¬ B → XOpt₃ A B C → XOpt₂ A C
xopt₃-elim₂ ¬b (xopt₁ a _ ¬c) = xopt₁ a ¬c
xopt₃-elim₂ ¬b (xopt₂ _ b _) = ⊥-elim (¬b b)
xopt₃-elim₂ ¬b (xopt₃ ¬a _ c) = xopt₂ ¬a c
xopt₃-elim₃ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → ¬ C → XOpt₃ A B C → XOpt₂ A B
xopt₃-elim₃ _ (xopt₁ a ¬b _) = xopt₁ a ¬b
xopt₃-elim₃ _ (xopt₂ ¬a b _) = xopt₂ ¬a b
xopt₃-elim₃ ¬c (xopt₃ _ _ c) = ⊥-elim (¬c c)
xopt₃-select₁ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → A → XOpt₃ A B C → ¬ B × ¬ C
xopt₃-select₁ a (xopt₁ _ ¬b ¬c) = ¬b , ¬c
xopt₃-select₁ a (xopt₂ ¬a _ _) = ⊥-elim (¬a a)
xopt₃-select₁ a (xopt₃ ¬a _ _) = ⊥-elim (¬a a)
xopt₃-select₂ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → B → XOpt₃ A B C → ¬ A × ¬ C
xopt₃-select₂ b (xopt₁ _ ¬b _) = ⊥-elim (¬b b)
xopt₃-select₂ b (xopt₂ ¬a _ ¬c) = ¬a , ¬c
xopt₃-select₂ b (xopt₃ _ ¬b _) = ⊥-elim (¬b b)
xopt₃-select₃ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → C → XOpt₃ A B C → ¬ A × ¬ B
xopt₃-select₃ c (xopt₁ _ _ ¬c) = ⊥-elim (¬c c)
xopt₃-select₃ c (xopt₂ _ _ ¬c) = ⊥-elim (¬c c)
xopt₃-select₃ c (xopt₃ ¬a ¬b _) = ¬a , ¬b
xopt₃-select₁₂ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → A → B → XOpt₃ A B C → ⊥
xopt₃-select₁₂ a b x = proj₁ (xopt₃-select₁ a x) b
xopt₃-select₂₃ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → B → C → XOpt₃ A B C → ⊥
xopt₃-select₂₃ b c x = proj₂ (xopt₃-select₂ b x) c
xopt₃-select₁₃ : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → A → C → XOpt₃ A B C → ⊥
xopt₃-select₁₃ a c x = proj₂ (xopt₃-select₁ a x) c
xopt₃-sum : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} → XOpt₃ A B C → A ⊎ B ⊎ C
xopt₃-sum (xopt₁ a _ _) = inj₁ a
xopt₃-sum (xopt₂ _ b _) = inj₂ (inj₁ b)
xopt₃-sum (xopt₃ _ _ c) = inj₂ (inj₂ c)
|
{
"alphanum_fraction": 0.526085225,
"avg_line_length": 37.7593984962,
"ext": "agda",
"hexsha": "0f311649946d7165812cb62c7a9c853d489aad31",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Nullary/XOpt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Nullary/XOpt.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Nullary/XOpt.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2597,
"size": 5022
}
|
module Issue2486.Haskell where
{-# FOREIGN GHC
data MyList a = Nil | Cons a (MyList a)
#-}
|
{
"alphanum_fraction": 0.670212766,
"avg_line_length": 11.75,
"ext": "agda",
"hexsha": "7a76489399b25bb9c233dd5ac94105ce93f706fe",
"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/Issue2486/Haskell.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/Issue2486/Haskell.agda",
"max_line_length": 39,
"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/Issue2486/Haskell.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": 29,
"size": 94
}
|
------------------------------------------------------------------------------
-- Property <→◁
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- The <→◁ property proves that the recursive calls of the McCarthy 91
-- function are on smaller arguments.
module FOTC.Program.McCarthy91.WF-Relation.LT2WF-RelationATP where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.PropertiesATP using ( S∸S )
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.EliminationPropertiesATP using ( x<0→⊥ )
open import FOTC.Data.Nat.Inequalities.PropertiesATP
using ( x<y→x≤y
; x≥y→y>0→x∸y<x
; x∸y<Sx
; x<y∨x≥y
; Sx≯y→x≯y
; x≯y→x≤y
; x≤y→x∸y≡0
; x<y→0<y∸x
)
open import FOTC.Data.Nat.UnaryNumbers
open import FOTC.Data.Nat.UnaryNumbers.TotalityATP
using ( 100-N
; 101-N
)
open import FOTC.Program.McCarthy91.WF-Relation
------------------------------------------------------------------------------
<→◁-helper : ∀ {n m k} → N n → N m → N k →
m < n → succ₁ n < k →
succ₁ m < k →
k ∸ n < k ∸ m →
k ∸ succ₁ n < k ∸ succ₁ m
<→◁-helper nzero Nm Nk p qn qm h = ⊥-elim (x<0→⊥ Nm p)
<→◁-helper (nsucc Nn) Nm nzero p qn qm h = ⊥-elim (x<0→⊥ (nsucc Nm) qm)
<→◁-helper (nsucc {n} Nn) nzero (nsucc {k} Nk) p qn qm h = prfS0S
where
postulate
k≥Sn : k ≥ succ₁ n
k∸Sn<k : k ∸ (succ₁ n) < k
prfS0S : succ₁ k ∸ succ₁ (succ₁ n) < succ₁ k ∸ succ₁ zero
{-# ATP prove k≥Sn x<y→x≤y #-}
{-# ATP prove k∸Sn<k k≥Sn x≥y→y>0→x∸y<x #-}
{-# ATP prove prfS0S k∸Sn<k S∸S #-}
<→◁-helper (nsucc {n} Nn) (nsucc {m} Nm) (nsucc {k} Nk) p qn qm h =
k∸Sn<k∸Sm→Sk∸SSn<Sk∸SSm (<→◁-helper Nn Nm Nk m<n Sn<k Sm<k k∸n<k∸m)
where
postulate
k∸Sn<k∸Sm→Sk∸SSn<Sk∸SSm : k ∸ succ₁ n < k ∸ succ₁ m →
succ₁ k ∸ succ₁ (succ₁ n) < succ₁ k ∸ succ₁ (succ₁ m)
{-# ATP prove k∸Sn<k∸Sm→Sk∸SSn<Sk∸SSm S∸S #-}
postulate
m<n : m < n
Sn<k : succ₁ n < k
Sm<k : succ₁ m < k
k∸n<k∸m : k ∸ n < k ∸ m
{-# ATP prove m<n #-}
{-# ATP prove Sn<k #-}
{-# ATP prove Sm<k #-}
{-# ATP prove k∸n<k∸m S∸S #-}
<→◁ : ∀ {n m} → N n → N m → m ≯ 100' → m < n → n ◁ m
<→◁ nzero Nm p h = ⊥-elim (x<0→⊥ Nm h)
<→◁ (nsucc {n} Nn) nzero p h = prfS0
where
postulate prfS0 : succ₁ n ◁ zero
{-# ATP prove prfS0 x∸y<Sx S∸S #-}
<→◁ (nsucc {n} Nn) (nsucc {m} Nm) p h with x<y∨x≥y Nn 100-N
... | inj₁ n<100 = <→◁-helper Nn Nm 101-N m<n Sn≤101 Sm≤101
(<→◁ Nn Nm m≯100 m<n)
where
postulate
m≯100 : m ≯ 100'
m<n : m < n
Sn≤101 : succ₁ n < 101'
Sm≤101 : succ₁ m < 101'
{-# ATP prove m≯100 Sx≯y→x≯y #-}
{-# ATP prove m<n #-}
{-# ATP prove Sn≤101 #-}
{-# ATP prove Sm≤101 x≯y→x≤y #-}
... | inj₂ n≥100 = prf-n≥100
where
postulate
0≡101∸Sn : zero ≡ 101' ∸ succ₁ n
0<101∸Sm : zero < 101' ∸ succ₁ m
{-# ATP prove 0≡101∸Sn x≤y→x∸y≡0 #-}
{-# ATP prove 0<101∸Sm x≯y→x≤y x<y→0<y∸x #-}
prf-n≥100 : succ₁ n ◁ succ₁ m
prf-n≥100 = subst (λ t → t < 101' ∸ succ₁ m) 0≡101∸Sn 0<101∸Sm
|
{
"alphanum_fraction": 0.4868813357,
"avg_line_length": 32.25,
"ext": "agda",
"hexsha": "dd6ff82009f9f73d757ec194dc919b3972ca5c3c",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/McCarthy91/WF-Relation/LT2WF-RelationATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/McCarthy91/WF-Relation/LT2WF-RelationATP.agda",
"max_line_length": 83,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/McCarthy91/WF-Relation/LT2WF-RelationATP.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": 1447,
"size": 3354
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.Group.EilenbergMacLane.GroupStructure where
open import Cubical.Algebra.Group.EilenbergMacLane.Base
open import Cubical.Algebra.Group.EilenbergMacLane.WedgeConnectivity
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Algebra.AbGroup.Base
open import Cubical.Data.Nat
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.GroupoidLaws renaming (assoc to ∙assoc)
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Path
open import Cubical.Homotopy.Loopspace
open import Cubical.HITs.EilenbergMacLane1
open import Cubical.HITs.Truncation
renaming (elim to trElim ; rec to trRec ; rec2 to trRec2)
open import Cubical.HITs.Susp
open import Cubical.Functions.Morphism
private
variable ℓ : Level
module _ {G : AbGroup ℓ} where
infixr 34 _+ₖ_
infixr 34 _-ₖ_
open AbGroupStr (snd G) renaming (_+_ to _+G_ ; -_ to -G_ ; +Assoc to +AssocG)
private
help : (n : ℕ) → n + (4 + n) ≡ (2 + n) + (2 + n)
help n = +-suc n (3 + n) ∙ cong suc (+-suc n (suc (suc n)))
hLevHelp : (n : ℕ) → isOfHLevel ((2 + n) + (2 + n)) (EM G (2 + n))
hLevHelp n =
transport (λ i → isOfHLevel (help n i) (EM G (2 + n)))
(isOfHLevelPlus {n = 4 + n} n (isOfHLevelTrunc (4 + n)))
helper : (g h : fst G)
→ PathP (λ i → Path (EM₁ (AbGroup→Group G))
(emloop h i) (emloop h i)) (emloop g) (emloop g)
helper g h =
comm→PathP
((sym (emloop-comp _ h g)
∙∙ cong emloop (+Comm h g)
∙∙ emloop-comp _ g h))
_+ₖ_ : {n : ℕ} → EM G n → EM G n → EM G n
_+ₖ_ {n = zero} = _+G_
_+ₖ_ {n = suc zero} =
rec _ (isGroupoidΠ (λ _ → emsquash))
(λ x → x)
(λ x → funExt (looper x))
λ g h i j x → el g h x i j
where
looper : fst G → (x : _) → x ≡ x
looper g = (elimSet _ (λ _ → emsquash _ _)
(emloop g)
(helper g))
el : (g h : fst G) (x : EM₁ (AbGroup→Group G))
→ Square (looper g x)
(looper (g +G h) x)
refl (looper h x)
el g h =
elimProp _ (λ _ → isOfHLevelPathP' 1 (emsquash _ _) _ _)
(emcomp g h)
_+ₖ_ {n = suc (suc n)} =
trRec2 (isOfHLevelTrunc (4 + n))
(wedgeConEM.fun G G (suc n) (suc n)
(λ _ _ → hLevHelp n)
∣_∣ ∣_∣ refl)
σ-EM : (n : ℕ) → EM-raw G (suc n) → Path (EM-raw G (2 + n)) ptEM-raw ptEM-raw
σ-EM n x = merid x ∙ sym (merid ptEM-raw)
-ₖ_ : {n : ℕ} → EM G n → EM G n
-ₖ_ {n = zero} x = -G x
-ₖ_ {n = suc zero} =
rec _ emsquash
embase
(λ g → sym (emloop g))
λ g h → sym (emloop-sym _ g)
◁ (flipSquare
(flipSquare (emcomp (-G g) (-G h))
▷ emloop-sym _ h)
▷ (cong emloop (+Comm (-G g) (-G h)
∙ sym (GroupTheory.invDistr (AbGroup→Group G) g h))
∙ emloop-sym _ (g +G h)))
-ₖ_ {n = suc (suc n)} =
map λ { north → north
; south → north
; (merid a i) → σ-EM n a (~ i)}
_-ₖ_ : {n : ℕ} → EM G n → EM G n → EM G n
_-ₖ_ {n = n} x y = _+ₖ_ {n = n} x (-ₖ_ {n = n} y)
+ₖ-syntax : (n : ℕ) → EM G n → EM G n → EM G n
+ₖ-syntax n = _+ₖ_ {n = n}
-ₖ-syntax : (n : ℕ) → EM G n → EM G n
-ₖ-syntax n = -ₖ_ {n = n}
-'ₖ-syntax : (n : ℕ) → EM G n → EM G n → EM G n
-'ₖ-syntax n = _-ₖ_ {n = n}
syntax +ₖ-syntax n x y = x +[ n ]ₖ y
syntax -ₖ-syntax n x = -[ n ]ₖ x
syntax -'ₖ-syntax n x y = x -[ n ]ₖ y
lUnitₖ : (n : ℕ) (x : EM G n) → 0ₖ n +[ n ]ₖ x ≡ x
lUnitₖ zero x = +IdL x
lUnitₖ (suc zero) _ = refl
lUnitₖ (suc (suc n)) =
trElim (λ _ → isOfHLevelTruncPath {n = 4 + n})
λ _ → refl
rUnitₖ : (n : ℕ) (x : EM G n) → x +[ n ]ₖ 0ₖ n ≡ x
rUnitₖ zero x = +IdR x
rUnitₖ (suc zero) =
elimSet _ (λ _ → emsquash _ _)
refl
λ _ _ → refl
rUnitₖ (suc (suc n)) =
trElim (λ _ → isOfHLevelTruncPath {n = 4 + n})
(wedgeConEM.right G G (suc n) (suc n)
(λ _ _ → hLevHelp n)
∣_∣ ∣_∣ refl)
commₖ : (n : ℕ) (x y : EM G n) → x +[ n ]ₖ y ≡ y +[ n ]ₖ x
commₖ zero = +Comm
commₖ (suc zero) =
wedgeConEM.fun G G 0 0 (λ _ _ → emsquash _ _)
(λ x → sym (rUnitₖ 1 x))
(rUnitₖ 1)
refl
commₖ (suc (suc n)) =
elim2 (λ _ _ → isOfHLevelTruncPath {n = 4 + n})
(wedgeConEM.fun G G _ _ (λ _ _ → isOfHLevelPath ((2 + n) + (2 + n)) (hLevHelp n) _ _)
(λ x → sym (rUnitₖ (2 + n) ∣ x ∣))
(λ x → rUnitₖ (2 + n) ∣ x ∣)
refl)
cong₂+₁ : (p q : typ (Ω (EM∙ G 1)))
→ cong₂ (λ x y → x +[ 1 ]ₖ y) p q ≡ p ∙ q
cong₂+₁ p q =
(cong₂Funct (λ x y → x +[ 1 ]ₖ y) p q)
∙ (λ i → (cong (λ x → rUnitₖ 1 x i) p) ∙ (cong (λ x → lUnitₖ 1 x i) q))
cong₂+₂ : (n : ℕ) (p q : typ (Ω (EM∙ G (suc (suc n)))))
→ cong₂ (λ x y → x +[ (2 + n) ]ₖ y) p q ≡ p ∙ q
cong₂+₂ n p q =
(cong₂Funct (λ x y → x +[ (2 + n) ]ₖ y) p q)
∙ (λ i → (cong (λ x → rUnitₖ (2 + n) x i) p) ∙ (cong (λ x → lUnitₖ (2 + n) x i) q))
isCommΩEM : (n : ℕ) (p q : typ (Ω (EM∙ G (suc n)))) → p ∙ q ≡ q ∙ p
isCommΩEM zero p q =
sym (cong₂+₁ p q)
∙∙ (λ i j → commₖ 1 (p j) (q j) i)
∙∙ cong₂+₁ q p
isCommΩEM (suc n) p q =
(sym (cong₂+₂ n p q)
∙∙ (λ i j → commₖ (suc (suc n)) (p j) (q j) i)
∙∙ cong₂+₂ n q p)
cong-₁ : (p : typ (Ω (EM∙ G 1))) → cong (λ x → -[ 1 ]ₖ x) p ≡ sym p
cong-₁ p = main embase p
where
decoder : (x : EM G 1) → embase ≡ x → x ≡ embase
decoder =
elimSet _
(λ _ → isSetΠ λ _ → emsquash _ _)
(λ p i → -[ 1 ]ₖ (p i))
λ g → toPathP
(funExt λ x →
(λ i → transport (λ i → Path (EM G 1) (emloop g i) embase)
(cong (-ₖ_ {n = 1})
(transp (λ j → Path (EM G 1) embase (emloop g (~ j ∧ ~ i))) i
(compPath-filler x (sym (emloop g)) i) )))
∙∙ (λ i → transp (λ j → Path (EM G 1) (emloop g (i ∨ j)) embase) i
(compPath-filler'
(sym (emloop g))
(cong-∙ (-ₖ_ {n = 1})
x (sym (emloop g)) i) i))
∙∙ (cong (sym (emloop g) ∙_) (isCommΩEM 0 (cong (-ₖ_ {n = 1}) x) (emloop g)))
∙∙ ∙assoc _ _ _
∙∙ cong (_∙ (cong (-ₖ_ {n = 1}) x)) (lCancel (emloop g))
∙ sym (lUnit _))
main : (x : EM G 1) (p : embase ≡ x) → decoder x p ≡ sym p
main x = J (λ x p → decoder x p ≡ sym p) refl
cong-₂ : (n : ℕ) (p : typ (Ω (EM∙ G (2 + n))))
→ cong (λ x → -[ 2 + n ]ₖ x) p ≡ sym p
cong-₂ n p = main _ p
where
pp : (a : _)
→ PathP (λ i → 0ₖ (suc (suc n)) ≡ ∣ merid a i ∣ₕ → ∣ merid a i ∣ₕ ≡ 0ₖ (2 + n))
(cong (λ x → -[ 2 + n ]ₖ x))
λ p → cong ∣_∣ₕ (sym (merid ptEM-raw)) ∙ cong (λ x → -[ 2 + n ]ₖ x) p
pp a =
toPathP
(funExt λ x →
(λ k → transp (λ i → Path (EM G (2 + n)) ∣ merid a (i ∨ k) ∣ ∣ ptEM-raw ∣) k
(compPath-filler' (cong ∣_∣ₕ (sym (merid a)))
(cong (-ₖ-syntax (suc (suc n)))
(transp (λ j → Path (EM G (2 + n)) ∣ ptEM-raw ∣ ∣ merid a (~ j ∧ ~ k) ∣) k
(compPath-filler x (sym (cong ∣_∣ₕ (merid a))) k))) k))
∙∙ cong (cong ∣_∣ₕ (sym (merid a)) ∙_)
(cong-∙ (λ x → -[ 2 + n ]ₖ x) x (sym (cong ∣_∣ₕ (merid a)))
∙ isCommΩEM (suc n) (cong (λ x → -[ 2 + n ]ₖ x) x) (cong ∣_∣ₕ (σ-EM n a)))
∙∙ (λ k → (λ i → ∣ merid a (~ i ∨ k) ∣)
∙ (λ i → ∣ compPath-filler' (merid a) (sym (merid ptEM-raw)) (~ k) i ∣)
∙ cong (λ x → -ₖ-syntax (suc (suc n)) x) x)
∙ sym (lUnit _))
decoder : (x : EM G (2 + n))
→ 0ₖ (2 + n) ≡ x → x ≡ 0ₖ (2 + n)
decoder =
trElim (λ _ → isOfHLevelΠ (4 + n) λ _ → isOfHLevelTruncPath {n = 4 + n})
λ { north → pp ptEM-raw i0
; south → pp ptEM-raw i1
; (merid a i) → pp a i}
main : (x : EM G (2 + n)) (p : 0ₖ (2 + n) ≡ x) → decoder x p ≡ sym p
main x = J (λ x p → decoder x p ≡ sym p) refl
rCancelₖ : (n : ℕ) (x : EM G n) → x +[ n ]ₖ (-[ n ]ₖ x) ≡ 0ₖ n
rCancelₖ zero x = +InvR x
rCancelₖ (suc zero) =
elimSet _ (λ _ → emsquash _ _)
refl
λ g → flipSquare (cong₂+₁ (emloop g) (λ i → -ₖ-syntax 1 (emloop g i))
∙ rCancel (emloop g))
rCancelₖ (suc (suc n)) =
trElim (λ _ → isOfHLevelTruncPath {n = 4 + n})
λ { north → refl
; south i → +ₖ-syntax (suc (suc n)) ∣ merid ptEM-raw (~ i) ∣
(-ₖ-syntax (suc (suc n)) ∣ merid ptEM-raw (~ i) ∣)
; (merid a i) j
→ hcomp (λ r → λ { (i = i0) → 0ₖ (2 + n)
; (i = i1) → ∣ merid ptEM-raw (~ j ∧ r) ∣ₕ -[ 2 + n ]ₖ ∣ merid ptEM-raw (~ j ∧ r) ∣
; (j = i0) → ∣ compPath-filler (merid a) (sym (merid ptEM-raw)) (~ r) i ∣
-[ 2 + n ]ₖ ∣ compPath-filler (merid a) (sym (merid ptEM-raw)) (~ r) i ∣
; (j = i1) → 0ₖ (2 + n)})
(help' a j i) }
where
help' : (a : _)
→ cong₂ (λ x y → ∣ x ∣ -[ suc (suc n) ]ₖ ∣ y ∣) (σ-EM n a) (σ-EM n a) ≡ refl
help' a =
cong₂+₂ n (cong ∣_∣ₕ (σ-EM n a)) (cong (λ x → -[ 2 + n ]ₖ ∣ x ∣) (σ-EM n a))
∙∙ cong (cong ∣_∣ₕ (σ-EM n a) ∙_) (cong-₂ n (cong ∣_∣ₕ (σ-EM n a)))
∙∙ rCancel _
lCancelₖ : (n : ℕ) (x : EM G n) → (-[ n ]ₖ x) +[ n ]ₖ x ≡ 0ₖ n
lCancelₖ n x = commₖ n (-[ n ]ₖ x) x ∙ rCancelₖ n x
assocₖ : (n : ℕ) (x y z : EM G n)
→ (x +[ n ]ₖ (y +[ n ]ₖ z) ≡ (x +[ n ]ₖ y) +[ n ]ₖ z)
assocₖ zero = +AssocG
assocₖ (suc zero) =
elimSet _ (λ _ → isSetΠ2 λ _ _ → emsquash _ _)
(λ _ _ → refl)
λ g i y z k → lem g y z k i
where
lem : (g : fst G) (y z : _)
→ cong (λ x → x +[ suc zero ]ₖ (y +[ suc zero ]ₖ z)) (emloop g)
≡ cong (λ x → (x +[ suc zero ]ₖ y) +[ suc zero ]ₖ z) (emloop g)
lem g =
elimProp _ (λ _ → isPropΠ λ _ → emsquash _ _ _ _)
(elimProp _ (λ _ → emsquash _ _ _ _)
refl)
assocₖ (suc (suc n)) =
elim2 (λ _ _ → isOfHLevelΠ (4 + n) λ _ → isOfHLevelTruncPath {n = 4 + n})
λ a b → trElim (λ _ → isOfHLevelTruncPath {n = 4 + n})
(λ c → main c a b)
where
lem : (c : _) (a b : _)
→ PathP (λ i → (∣ a ∣ₕ +[ suc (suc n) ]ₖ (∣ b ∣ₕ +[ suc (suc n) ]ₖ ∣ merid c i ∣ₕ)
≡ (∣ a ∣ₕ +[ suc (suc n) ]ₖ ∣ b ∣ₕ) +[ suc (suc n) ]ₖ ∣ merid c i ∣ₕ))
(cong (λ x → ∣ a ∣ₕ +[ suc (suc n) ]ₖ x) (rUnitₖ (suc (suc n)) ∣ b ∣)
∙ sym (rUnitₖ (suc (suc n)) (∣ a ∣ₕ +[ suc (suc n) ]ₖ ∣ b ∣ₕ)))
((λ i → ∣ a ∣ₕ +[ suc (suc n) ]ₖ (∣ b ∣ₕ +[ suc (suc n) ]ₖ ∣ merid ptEM-raw (~ i) ∣ₕ))
∙∙ cong (λ x → ∣ a ∣ₕ +[ suc (suc n) ]ₖ x) (rUnitₖ (suc (suc n)) ∣ b ∣)
∙ sym (rUnitₖ (suc (suc n)) (∣ a ∣ₕ +[ suc (suc n) ]ₖ ∣ b ∣ₕ))
∙∙ λ i → (∣ a ∣ₕ +[ suc (suc n) ]ₖ ∣ b ∣ₕ) +[ suc (suc n) ]ₖ ∣ merid ptEM-raw i ∣ₕ)
lem c =
raw-elim G (suc n)
(λ _ → isOfHLevelΠ (2 + n)
(λ _ → isOfHLevelPathP' (2 + n) (isOfHLevelTrunc (4 + n) _ _) _ _))
(raw-elim G (suc n)
(λ _ → isOfHLevelPathP' (2 + n) (isOfHLevelTrunc (4 + n) _ _) _ _)
((sym (rUnit refl)
◁ λ _ → refl)
▷ (sym (lCancel (cong ∣_∣ₕ (merid ptEM-raw)))
∙ λ i → (λ j → ∣ merid ptEM-raw (~ j ∨ ~ i) ∣ₕ)
∙∙ lUnit (λ j → ∣ merid ptEM-raw (~ j ∧ ~ i) ∣ₕ) i
∙∙ cong ∣_∣ₕ (merid ptEM-raw))))
main : (c a b : _)
→ (∣ a ∣ₕ +[ suc (suc n) ]ₖ (∣ b ∣ₕ +[ suc (suc n) ]ₖ ∣ c ∣ₕ)
≡ (∣ a ∣ₕ +[ suc (suc n) ]ₖ ∣ b ∣ₕ) +[ suc (suc n) ]ₖ ∣ c ∣ₕ)
main north a b = lem ptEM-raw a b i0
main south a b = lem ptEM-raw a b i1
main (merid c i) a b = lem c a b i
σ-EM' : (n : ℕ) (x : EM G (suc n))
→ Path (EM G (suc (suc n)))
(0ₖ (suc (suc n)))
(0ₖ (suc (suc n)))
σ-EM' zero x = cong ∣_∣ₕ (σ-EM zero x)
σ-EM' (suc n) =
trElim (λ _ → isOfHLevelTrunc (5 + n) _ _)
λ x → cong ∣_∣ₕ (σ-EM (suc n) x)
σ-EM'-0ₖ : (n : ℕ) → σ-EM' n (0ₖ (suc n)) ≡ refl
σ-EM'-0ₖ zero = cong (cong ∣_∣ₕ) (rCancel (merid ptEM-raw))
σ-EM'-0ₖ (suc n) = cong (cong ∣_∣ₕ) (rCancel (merid ptEM-raw))
private
lUnit-rUnit-coh : ∀ {ℓ} {A : Type ℓ} {x : A} (p : x ≡ x) (r : refl ≡ p)
→ lUnit p ∙ cong (_∙ p) r
≡ rUnit p ∙ cong (p ∙_) r
lUnit-rUnit-coh p =
J (λ p r → lUnit p ∙ cong (_∙ p) r ≡ rUnit p ∙ cong (p ∙_) r) refl
σ-EM'-hom : (n : ℕ) → (a b : _) → σ-EM' n (a +ₖ b) ≡ σ-EM' n a ∙ σ-EM' n b
σ-EM'-hom zero =
wedgeConEM.fun G G 0 0 (λ _ _ → isOfHLevelTrunc 4 _ _ _ _) l r p
where
l : _
l x = cong (σ-EM' zero) (lUnitₖ 1 x)
∙∙ lUnit (σ-EM' zero x)
∙∙ cong (_∙ σ-EM' zero x) (sym (σ-EM'-0ₖ zero))
r : _
r x =
cong (σ-EM' zero) (rUnitₖ 1 x)
∙∙ rUnit (σ-EM' zero x)
∙∙ cong (σ-EM' zero x ∙_) (sym (σ-EM'-0ₖ zero))
p : _
p = lUnit-rUnit-coh (σ-EM' zero embase) (sym (σ-EM'-0ₖ zero))
σ-EM'-hom (suc n) =
elim2 (λ _ _ → isOfHLevelPath (4 + n) (isOfHLevelTrunc (5 + n) _ _) _ _)
(wedgeConEM.fun G G _ _
(λ x y → transport (λ i → isOfHLevel (help n i)
((σ-EM' (suc n) (∣ x ∣ₕ +ₖ ∣ y ∣ₕ)
≡ σ-EM' (suc n) ∣ x ∣ₕ ∙ σ-EM' (suc n) ∣ y ∣ₕ)))
(isOfHLevelPlus {n = 4 + n} n
(isOfHLevelPath (4 + n)
(isOfHLevelTrunc (5 + n) _ _) _ _)))
(λ x → cong (σ-EM' (suc n)) (lUnitₖ (suc (suc n)) ∣ x ∣)
∙∙ lUnit (σ-EM' (suc n) ∣ x ∣)
∙∙ cong (_∙ σ-EM' (suc n) ∣ x ∣) (sym (σ-EM'-0ₖ (suc n))))
(λ x → cong (σ-EM' (suc n)) (rUnitₖ (2 + n) ∣ x ∣)
∙∙ rUnit (σ-EM' (suc n) ∣ x ∣)
∙∙ cong (σ-EM' (suc n) ∣ x ∣ ∙_) (sym (σ-EM'-0ₖ (suc n))))
(lUnit-rUnit-coh (σ-EM' (suc n) (0ₖ (2 + n))) (sym (σ-EM'-0ₖ (suc n)))))
σ-EM'-ₖ : (n : ℕ) → (a : _) → σ-EM' n (-ₖ a) ≡ sym (σ-EM' n a)
σ-EM'-ₖ n =
morphLemmas.distrMinus
(λ x y → x +[ suc n ]ₖ y) (_∙_)
(σ-EM' n) (σ-EM'-hom n)
(0ₖ (suc n)) refl
(λ x → -ₖ x) sym
(λ x → sym (lUnit x)) (λ x → sym (rUnit x))
(lCancelₖ (suc n)) rCancel
∙assoc (σ-EM'-0ₖ n)
-Dist : (n : ℕ) (x y : EM G n) → -[ n ]ₖ (x +[ n ]ₖ y) ≡ (-[ n ]ₖ x) +[ n ]ₖ (-[ n ]ₖ y)
-Dist zero x y = (GroupTheory.invDistr (AbGroup→Group G) x y) ∙ commₖ zero _ _
-Dist (suc zero) = k
where -- useless where clause. Needed for fast type checking for some reason.
l : _
l x = refl
r : _
r x = cong (λ z → -[ 1 ]ₖ z) (rUnitₖ 1 x) ∙ sym (rUnitₖ 1 (-[ 1 ]ₖ x))
p : r ptEM-raw ≡ l ptEM-raw
p = sym (rUnit refl)
k = wedgeConEM.fun G G 0 0 (λ _ _ → emsquash _ _) l r (sym p)
-Dist (suc (suc n)) =
elim2 (λ _ _ → isOfHLevelTruncPath {n = 4 + n})
(wedgeConEM.fun G G (suc n) (suc n)
(λ _ _ → isOfHLevelPath ((2 + n) + (2 + n)) (hLevHelp n) _ _)
(λ x → refl)
(λ x → cong (λ z → -[ (suc (suc n)) ]ₖ z)
(rUnitₖ (suc (suc n)) ∣ x ∣ₕ)
∙ sym (rUnitₖ (suc (suc n)) (-[ (suc (suc n)) ]ₖ ∣ x ∣ₕ)))
(rUnit refl))
addIso : (n : ℕ) (x : EM G n) → Iso (EM G n) (EM G n)
Iso.fun (addIso n x) y = y +[ n ]ₖ x
Iso.inv (addIso n x) y = y -[ n ]ₖ x
Iso.rightInv (addIso n x) y =
sym (assocₖ n y (-[ n ]ₖ x) x)
∙∙ cong (λ x → y +[ n ]ₖ x) (lCancelₖ n x)
∙∙ rUnitₖ n y
Iso.leftInv (addIso n x) y =
sym (assocₖ n y x (-[ n ]ₖ x))
∙∙ cong (λ x → y +[ n ]ₖ x) (rCancelₖ n x)
∙∙ rUnitₖ n y
|
{
"alphanum_fraction": 0.4499718416,
"avg_line_length": 38.4158653846,
"ext": "agda",
"hexsha": "888bde0c4a8bf7f896ac3faec36d26fede5339f1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/Group/EilenbergMacLane/GroupStructure.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/Group/EilenbergMacLane/GroupStructure.agda",
"max_line_length": 112,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/Group/EilenbergMacLane/GroupStructure.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7201,
"size": 15981
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of functions, such as associativity and commutativity
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Level
open import Relation.Binary
open import Data.Sum
-- The properties are parameterised by the following "equality" relation
module Algebra.FunctionProperties
{a ℓ} {A : Set a} (_≈_ : Rel A ℓ) where
open import Data.Product
------------------------------------------------------------------------
-- Unary and binary operations
open import Algebra.FunctionProperties.Core public
------------------------------------------------------------------------
-- Properties of operations
Associative : Op₂ A → Set _
Associative _∙_ = ∀ x y z → ((x ∙ y) ∙ z) ≈ (x ∙ (y ∙ z))
Commutative : Op₂ A → Set _
Commutative _∙_ = ∀ x y → (x ∙ y) ≈ (y ∙ x)
LeftIdentity : A → Op₂ A → Set _
LeftIdentity e _∙_ = ∀ x → (e ∙ x) ≈ x
RightIdentity : A → Op₂ A → Set _
RightIdentity e _∙_ = ∀ x → (x ∙ e) ≈ x
Identity : A → Op₂ A → Set _
Identity e ∙ = (LeftIdentity e ∙) × (RightIdentity e ∙)
LeftZero : A → Op₂ A → Set _
LeftZero z _∙_ = ∀ x → (z ∙ x) ≈ z
RightZero : A → Op₂ A → Set _
RightZero z _∙_ = ∀ x → (x ∙ z) ≈ z
Zero : A → Op₂ A → Set _
Zero z ∙ = (LeftZero z ∙) × (RightZero z ∙)
LeftInverse : A → Op₁ A → Op₂ A → Set _
LeftInverse e _⁻¹ _∙_ = ∀ x → ((x ⁻¹) ∙ x) ≈ e
RightInverse : A → Op₁ A → Op₂ A → Set _
RightInverse e _⁻¹ _∙_ = ∀ x → (x ∙ (x ⁻¹)) ≈ e
Inverse : A → Op₁ A → Op₂ A → Set _
Inverse e ⁻¹ ∙ = (LeftInverse e ⁻¹) ∙ × (RightInverse e ⁻¹ ∙)
LeftConical : A → Op₂ A → Set _
LeftConical e _∙_ = ∀ x y → (x ∙ y) ≈ e → x ≈ e
RightConical : A → Op₂ A → Set _
RightConical e _∙_ = ∀ x y → (x ∙ y) ≈ e → y ≈ e
Conical : A → Op₂ A → Set _
Conical e ∙ = (LeftConical e ∙) × (RightConical e ∙)
_DistributesOverˡ_ : Op₂ A → Op₂ A → Set _
_*_ DistributesOverˡ _+_ =
∀ x y z → (x * (y + z)) ≈ ((x * y) + (x * z))
_DistributesOverʳ_ : Op₂ A → Op₂ A → Set _
_*_ DistributesOverʳ _+_ =
∀ x y z → ((y + z) * x) ≈ ((y * x) + (z * x))
_DistributesOver_ : Op₂ A → Op₂ A → Set _
* DistributesOver + = (* DistributesOverˡ +) × (* DistributesOverʳ +)
_IdempotentOn_ : Op₂ A → A → Set _
_∙_ IdempotentOn x = (x ∙ x) ≈ x
Idempotent : Op₂ A → Set _
Idempotent ∙ = ∀ x → ∙ IdempotentOn x
IdempotentFun : Op₁ A → Set _
IdempotentFun f = ∀ x → f (f x) ≈ f x
Selective : Op₂ A → Set _
Selective _∙_ = ∀ x y → (x ∙ y) ≈ x ⊎ (x ∙ y) ≈ y
_Absorbs_ : Op₂ A → Op₂ A → Set _
_∙_ Absorbs _∘_ = ∀ x y → (x ∙ (x ∘ y)) ≈ x
Absorptive : Op₂ A → Op₂ A → Set _
Absorptive ∙ ∘ = (∙ Absorbs ∘) × (∘ Absorbs ∙)
Involutive : Op₁ A → Set _
Involutive f = ∀ x → f (f x) ≈ x
LeftCancellative : Op₂ A → Set _
LeftCancellative _•_ = ∀ x {y z} → (x • y) ≈ (x • z) → y ≈ z
RightCancellative : Op₂ A → Set _
RightCancellative _•_ = ∀ {x} y z → (y • x) ≈ (z • x) → y ≈ z
Cancellative : Op₂ A → Set _
Cancellative _•_ = (LeftCancellative _•_) × (RightCancellative _•_)
Congruent₁ : Op₁ A → Set _
Congruent₁ f = f Preserves _≈_ ⟶ _≈_
Congruent₂ : Op₂ A → Set _
Congruent₂ ∙ = ∙ Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_
LeftCongruent : Op₂ A → Set _
LeftCongruent _∙_ = ∀ {x} → (x ∙_) Preserves _≈_ ⟶ _≈_
RightCongruent : Op₂ A → Set _
RightCongruent _∙_ = ∀ {x} → (_∙ x) Preserves _≈_ ⟶ _≈_
|
{
"alphanum_fraction": 0.5397203213,
"avg_line_length": 27.5491803279,
"ext": "agda",
"hexsha": "84957b40c4a25a39e2458f4c62c9e0e86b2210f9",
"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/FunctionProperties.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/FunctionProperties.agda",
"max_line_length": 72,
"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/FunctionProperties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1299,
"size": 3361
}
|
module AbsToConDecl where
x where
data D (A : Set) : Set where
c : D A
|
{
"alphanum_fraction": 0.5975609756,
"avg_line_length": 13.6666666667,
"ext": "agda",
"hexsha": "bd6abb2f533785267cb3b1c1ea405c7ce6fe56cb",
"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/AbsToConDecl.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/AbsToConDecl.agda",
"max_line_length": 32,
"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/AbsToConDecl.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 28,
"size": 82
}
|
{-# OPTIONS --copatterns #-}
module Tree where
data Bool : Set where
true false : Bool
record Tree (A : Set) : Set where
field
label : A
child : Bool -> Tree A
open Tree
-- corecursive function defined by copattern matching
alternate : {A : Set}(a b : A) -> Tree A
-- deep copatterns:
label (child (alternate a b) false) = b
child (child (alternate a b) false) true = alternate a b
child (child (alternate a b) false) false = alternate a b
-- shallow copatterns
child {A = A} (alternate a b) true = alternate b a
label {A = A} (alternate a b) = a
{- Delivers an infinite tree
a
b b
a a a a
b b b b b b b b
...
-}
infixr 5 _::_
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
collect : List Bool -> {A : Set} -> Tree A -> List A
collect [] t = []
collect (b :: l) t = label t :: collect l (child t b)
test : List Bool
test = collect (true :: true :: true :: []) (alternate true false)
-- should give true :: false : true :: []
|
{
"alphanum_fraction": 0.5588507878,
"avg_line_length": 23.9777777778,
"ext": "agda",
"hexsha": "8f9620e68b5bcb82bde3f03e1ba4c7796a81e6e9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/features/Tree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/features/Tree.agda",
"max_line_length": 66,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "np/agda-git-experiment",
"max_stars_repo_path": "test/features/Tree.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": 321,
"size": 1079
}
|
{-# OPTIONS --copatterns #-}
module SizedPolyIO.Base where
open import Data.Maybe.Base
open import Data.Sum renaming (inj₁ to left; inj₂ to right; [_,_]′ to either)
open import Function
open import Level using (_⊔_) renaming (suc to lsuc)
open import Size
open import NativePolyIO
record IOInterface γ ρ : Set (lsuc (γ ⊔ ρ)) where
field
Command : Set γ
Response : (m : Command) → Set ρ
open IOInterface public
module _ {γ ρ} (I : IOInterface γ ρ) (let C = Command I) (let R = Response I) where
mutual
record IO (i : Size) {α} (A : Set α) : Set (α ⊔ γ ⊔ ρ) where
coinductive
constructor delay
field
force : {j : Size< i} → IO' j A
data IO' (i : Size) {α} (A : Set α) : Set (α ⊔ γ ⊔ ρ) where
do' : (c : C) (f : R c → IO i A) → IO' i A
return' : (a : A) → IO' i A
data IO+ (i : Size) {α} (A : Set α) : Set (α ⊔ ρ ⊔ γ) where
do' : (c : C) (f : R c → IO i A) → IO+ i A
open IO public
module _ {γ ρ} {I : IOInterface γ ρ} (let C = Command I) (let R = Response I) where
return : ∀{i α}{A : Set α} (a : A) → IO I i A
force (return a) = return' a
do : ∀{i α}{A : Set α} (c : C) (f : R c → IO I i A) → IO I i A
force (do c f) = do' c f
do1 : ∀{i} (c : C) → IO I i (R c)
do1 c = do c return
infixl 2 _>>=_ _>>='_ _>>_
mutual
_>>='_ : ∀{i α}{A B : Set α} (m : IO' I i A) (k : A → IO I (↑ i) B) → IO' I i B
do' c f >>=' k = do' c λ x → f x >>= k
return' a >>=' k = force (k a)
_>>=_ : ∀{i α}{A B : Set α} (m : IO I i A) (k : A → IO I i B) → IO I i B
force (m >>= k) = force m >>=' k
_>>_ : ∀{i α}{B : Set α} (m : IO I i Unit) (k : IO I i B) → IO I i B
m >> k = m >>= λ _ → k
{-# NON_TERMINATING #-}
translateIO : ∀{α}{A : Set α}
→ (translateLocal : (c : C) → NativeIO (R c))
→ IO I ∞ A
→ NativeIO A
translateIO translateLocal m = case (force m {_}) of
λ{ (do' c f) → (translateLocal c) native>>= λ r →
translateIO translateLocal (f r)
; (return' a) → nativeReturn a
}
-- Recursion
-- trampoline provides a generic form of loop (generalizing while/repeat).
-- Starting at state s : S, step function f is iterated until it returns
-- a result in A.
fromIO+' : ∀{i α}{A : Set α} → IO+ I i A → IO' I i A
fromIO+' (do' c f) = do' c f
fromIO+ : ∀{i α}{A : Set α} → IO+ I i A → IO I i A
force (fromIO+ (do' c f)) = do' c f
_>>=+'_ : ∀{i α}{A B : Set α} (m : IO+ I i A) (k : A → IO I i B) → IO' I i B
do' c f >>=+' k = do' c λ x → f x >>= k
_>>=+_ : ∀{i α}{A B : Set α} (m : IO+ I i A) (k : A → IO I i B) → IO I i B
force (m >>=+ k) = m >>=+' k
mutual
_>>+_ : ∀{i α}{A B : Set α} (m : IO I i (A ⊎ B)) (k : A → IO I i B) → IO I i B
force (m >>+ k) = force m >>+' k
_>>+'_ : ∀{j α}{A B : Set α} (m : IO' I j (A ⊎ B)) (k : A → IO I (↑ j) B) → IO' I j B
do' c f >>+' k = do' c λ x → f x >>+ k
return' (left a) >>+' k = force (k a)
return' (right b) >>+' k = return' b
-- loop
trampoline : ∀{i α}{A S : Set α} (f : S → IO+ I i (S ⊎ A)) (s : S) → IO I i A
force (trampoline f s) = case (f s) of
\{ (do' c k) → do' c λ r → k r >>+ trampoline f }
-- simple infinite loop
forever : ∀{i α}{A B : Set α} → IO+ I i A → IO I i B
force (forever (do' c f)) = do' c λ r → f r >>= λ _ → forever (do' c f)
whenJust : ∀{i α}{A : Set α} → Maybe A → (A → IO I i (Unit {α})) → IO I i Unit
whenJust nothing k = return _
whenJust (just a) k = k a
|
{
"alphanum_fraction": 0.4879587156,
"avg_line_length": 30.3304347826,
"ext": "agda",
"hexsha": "6b6ab465d6a0108e806c8ff3022aa010bf623bb2",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "src/SizedPolyIO/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "src/SizedPolyIO/Base.agda",
"max_line_length": 89,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "src/SizedPolyIO/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 1438,
"size": 3488
}
|
module Negative2 where
data Tree (A : Set) : Set where
leaf : Tree A
node : (A -> Tree A) -> Tree A
data Bad : Set where
bad : Tree Bad -> Bad
|
{
"alphanum_fraction": 0.582278481,
"avg_line_length": 15.8,
"ext": "agda",
"hexsha": "2915072e45a98bd53e78795cb3c043eab97e756b",
"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/Negative2.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/Negative2.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/Negative2.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": 49,
"size": 158
}
|
module Issue312 where
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
syntax Σ A (λ x → B) = Σ[ x ∶ A ] B
_×_ : Set → Set → Set
A × B = Σ[ _ ∶ A ] B
postulate
T : Set → Set → Set
equal : ∀ {A} → T A A
_and_are_ : (A B : Set) → T A B → Set
-- Check that it parses to the right thing
check : ∀ A B → (A × B) and Σ A (λ x → B) are equal
|
{
"alphanum_fraction": 0.5282555283,
"avg_line_length": 18.5,
"ext": "agda",
"hexsha": "a34d1c1d681ce91b29247154c47e48c02a59797e",
"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/Issue312.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/Issue312.agda",
"max_line_length": 53,
"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/Issue312.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": 170,
"size": 407
}
|
module sv20.class-exercise where
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _≤_; s≤s; z≤n)
-- Subset definition taken from: https://agda.readthedocs.io/en/v2.6.1/language/irrelevance.html
-- Notice that irrelevance is not the same as function dot-pattern: https://agda.readthedocs.io/en/v2.6.1/language/function-definitions.html#dot-patterns
postulate
.irrAx : ∀ {ℓ} {A : Set ℓ} -> .A -> A
record Subset (A : Set) (P : A -> Set) : Set where
constructor _#_
field
elem : A
.certificate : P elem
.certificate : {A : Set}{P : A -> Set} -> (x : Subset A P) -> P (Subset.elem x)
certificate (a # p) = irrAx p
_ : Subset ℕ (_≤ 3)
_ = 3 # s≤s (s≤s (s≤s z≤n))
--_ = 0 # z≤n
--_∈_ : ?
--(a # p) ∈ s = ?
|
{
"alphanum_fraction": 0.6092896175,
"avg_line_length": 28.1538461538,
"ext": "agda",
"hexsha": "a7d097e6ab081bb8d4b6c8cac7787adf3c4b0cc2",
"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": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "helq/old_code",
"max_forks_repo_path": "proglangs-learning/Agda/sv20/class-exercise.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z",
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "helq/old_code",
"max_issues_repo_path": "proglangs-learning/Agda/sv20/class-exercise.agda",
"max_line_length": 153,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "helq/old_code",
"max_stars_repo_path": "proglangs-learning/Agda/sv20/class-exercise.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 277,
"size": 732
}
|
{-# OPTIONS --without-K --safe #-}
module Data.List.Kleene.Properties where
open import Data.List.Kleene.Base
open import Relation.Binary
open import Relation.Unary
open import Function
module _ {a r} {A : Set a} {R : Rel A r} where
infix 4 _≈_
_≈_ = R
open import Algebra.FunctionProperties _≈_
foldr-universal : Transitive _≈_
→ ∀ {b} {B : Set b} (h : B ⋆ → A) f e
→ ∀[ f ⊢ Congruent₁ ]
→ (h [] ≈ e)
→ (∀ x xs → h (∹ x & xs) ≈ f x (h xs))
→ ∀ xs → h xs ≈ foldr⋆ f e xs
foldr-universal trans h f e cong-f base cons [] = base
foldr-universal trans h f e cong-f base cons (∹ x & xs) =
(cons x xs) ⟨ trans ⟩ cong-f (foldr-universal trans h f e cong-f base cons xs)
foldr-fusion : Transitive _≈_
→ Reflexive _≈_
→ ∀ {b c} {B : Set b} {C : Set c} (f : C → A) {_⊕_ : B → C → C} {_⊗_ : B → A → A} e
→ ∀[ _⊗_ ⊢ Congruent₁ ]
→ (∀ x y → f (x ⊕ y) ≈ x ⊗ f y)
→ ∀ xs → f (foldr⋆ _⊕_ e xs) ≈ foldr⋆ _⊗_ (f e) xs
foldr-fusion trans refl h {f} {g} e cong-g fuse =
foldr-universal trans (h ∘ foldr⋆ f e) g (h e) cong-g refl (λ x xs → fuse x (foldr⋆ f e xs))
|
{
"alphanum_fraction": 0.5008064516,
"avg_line_length": 34.4444444444,
"ext": "agda",
"hexsha": "b3279d0c8b668ed1d75122eb081dc31e9a8771aa",
"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": "a7e99bc288e12e83440c891dbd3e5077d9b1657e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-kleene-lists",
"max_forks_repo_path": "Data/List/Kleene/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a7e99bc288e12e83440c891dbd3e5077d9b1657e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-kleene-lists",
"max_issues_repo_path": "Data/List/Kleene/Properties.agda",
"max_line_length": 98,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a7e99bc288e12e83440c891dbd3e5077d9b1657e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-kleene-lists",
"max_stars_repo_path": "Data/List/Kleene/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 460,
"size": 1240
}
|
------------------------------------------------------------------------------
-- Unary naturales numbers
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Data.Nat.UnaryNumbers where
open import LTC-PCF.Base
------------------------------------------------------------------------------
[0] = zero
[1] = succ₁ [0]
[2] = succ₁ [1]
[3] = succ₁ [2]
[4] = succ₁ [3]
[5] = succ₁ [4]
[6] = succ₁ [5]
[7] = succ₁ [6]
[8] = succ₁ [7]
[9] = succ₁ [8]
|
{
"alphanum_fraction": 0.3338278932,
"avg_line_length": 25.9230769231,
"ext": "agda",
"hexsha": "03a19a4ba2ad136ff55d56bc0c1b9e9518b6a4af",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Data/Nat/UnaryNumbers.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Data/Nat/UnaryNumbers.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Data/Nat/UnaryNumbers.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": 162,
"size": 674
}
|
module Category.Profunctor.Joker where
open import Agda.Primitive using (Level; _⊔_; lsuc)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Category.Functor using (RawFunctor; module RawFunctor)
open import Category.Functor.Lawful
open import Category.Profunctor
open import Category.Choice
open import Relation.Binary.PropositionalEquality using (refl)
Joker : ∀ {l₁ l₂ l₃} (F : Set l₂ → Set l₃) (A : Set l₁) (B : Set l₂) → Set l₃
Joker F _ B = F B
jokerProfunctor : ∀ {l₁ l₂} {F : Set l₁ → Set l₂} → RawFunctor F → ProfunctorImp (Joker F)
jokerProfunctor f = record
{ dimap = λ _ h g → h <$> g
; lmap = λ _ g → g
; rmap = λ h g → h <$> g
} where open RawFunctor f
jokerLawfulProfunctor : ∀ {l₁ l₂} {F : Set l₁ → Set l₂} {FFunc : RawFunctor F} → LawfulFunctorImp FFunc → LawfulProfunctorImp (jokerProfunctor FFunc)
jokerLawfulProfunctor f = record
{ lmapId = refl
; rmapId = <$>-identity
; dimapLmapRmap = refl
} where open LawfulFunctor f
jokerChoice : ∀ {l₁ l₂} {F : Set l₁ → Set l₂} → RawFunctor F → ChoiceImp (Joker F)
jokerChoice f = record
{ isProfunctor = jokerProfunctor f
; left' = inj₁ <$>_
; right' = inj₂ <$>_
}
where open RawFunctor f
|
{
"alphanum_fraction": 0.6862416107,
"avg_line_length": 34.0571428571,
"ext": "agda",
"hexsha": "02987aace45904872fcc9537579c491270b4a5d5",
"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": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crisoagf/agda-optics",
"max_forks_repo_path": "src/Category/Profunctor/Joker.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"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": "crisoagf/agda-optics",
"max_issues_repo_path": "src/Category/Profunctor/Joker.agda",
"max_line_length": 149,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crisoagf/agda-optics",
"max_stars_repo_path": "src/Category/Profunctor/Joker.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 442,
"size": 1192
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- M-types (the dual of W-types)
------------------------------------------------------------------------
{-# OPTIONS --without-K --guardedness --sized-types #-}
module Codata.Musical.M where
open import Codata.Musical.Notation
open import Level
open import Data.Product hiding (map)
open import Data.Container.Core as C hiding (map)
-- The family of M-types.
data M {s p} (C : Container s p) : Set (s ⊔ p) where
inf : ⟦ C ⟧ (∞ (M C)) → M C
-- Projections.
module _ {s p} (C : Container s p) where
head : M C → Shape C
head (inf (x , _)) = x
tail : (x : M C) → Position C (head x) → M C
tail (inf (x , f)) b = ♭ (f b)
-- map
module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂}
(m : C₁ ⇒ C₂) where
map : M C₁ → M C₂
map (inf (x , f)) = inf (shape m x , λ p → ♯ map (♭ (f (position m p))))
-- unfold
module _ {s p ℓ} {C : Container s p} (open Container C)
{S : Set ℓ} (alg : S → ⟦ C ⟧ S) where
unfold : S → M C
unfold seed = let (x , f) = alg seed in
inf (x , λ p → ♯ unfold (f p))
------------------------------------------------------------------------
-- Legacy
import Codata.M as M
open import Codata.Thunk
import Size
module _ {s p} {C : Container s p} where
fromMusical : ∀ {i} → M C → M.M C i
fromMusical (inf t) = M.inf (C.map rec t) where
rec = λ x → λ where .force → fromMusical (♭ x)
toMusical : M.M C Size.∞ → M C
toMusical (M.inf (s , f)) = inf (s , λ p → ♯ toMusical (f p .force))
|
{
"alphanum_fraction": 0.490625,
"avg_line_length": 25,
"ext": "agda",
"hexsha": "632ea2c73248e648f35b6242717c1ef0179f8a94",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/M.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/M.agda",
"max_line_length": 74,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/M.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": 516,
"size": 1600
}
|
-- Andreas, 2013-03-15 issue reported by Nisse
-- {-# OPTIONS -v tc.proj:40 -v tc.conv.elim:40 #-}
-- {-# OPTIONS -v tc.inj.check:45 #-}
-- {-# OPTIONS -v tc.proj.like:45 #-}
module Issue821 where
import Common.Level
data D (A : Set) : Set where
c : D A → D A
-- f is projection like, but could also be injective!?
f : (A : Set) → D A → D A
f A (c x) = x
postulate
A : Set
P : D A → Set
x : D A
p : P x
Q : P (f A x) → Set
Foo : Set₁
Foo = Q p
-- WAS:
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Conversion.hs:466
-- Reason was that f is projection-like so the test x =?= f A x
-- actually becomes x =?= x .f with unequal spine shapes (empty vs. non-empty).
-- Agda thought this was impossible.
-- Expected error:
-- x != (f A x) of type (D A)
-- when checking that the expression p has type P (f A x)
-- Projection-likeness of f will turn this into:
-- x != (f _ x) of type (D A)
|
{
"alphanum_fraction": 0.6233367451,
"avg_line_length": 23.2619047619,
"ext": "agda",
"hexsha": "75d1d944f208583c4cb5ceef0dcd5c838d1dce8a",
"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/Issue821.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/Issue821.agda",
"max_line_length": 79,
"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/Issue821.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": 318,
"size": 977
}
|
module Examples where
-- The terms of AExp assign a binding time to each subterm. For
-- program specialization, we interpret terms with dynamic binding
-- time as the programs subject to specialization, and their subterms
-- with static binding time as statically known inputs. A partial
-- evaluation function (or specializer) then compiles the program into
-- a residual term for that is specialized for the static inputs. The
-- main complication when defining partial evaluation as a total,
-- primitively recursive function will be the treatment of the De
-- Bruijn variables of non-closed residual expressions.
-- Before diving into the precise definition, it is instructive to
-- investigate the expected result of partial evaluation on some
-- examples.
{-
module AExp-Examples where
open import Data.Product
-- (We pre-define some De Bruijn indices to improve
-- readability of the examples:)
x : ∀ {α Δ} → AExp (α ∷ Δ) α
x = Var hd
y : ∀ {α₁ α Δ} → AExp (α₁ ∷ α ∷ Δ) α
y = Var (tl hd)
z : ∀ {α₁ α₂ α Δ} → AExp (α₁ ∷ α₂ ∷ α ∷ Δ) α
z = Var (tl (tl hd))
-- A very simple case is the addition of three constants, where one
-- is dynamically bound and two are bound statically:
-- 5D +D (30S +S 7S)
-- ex1 : AExp [] (D Int)
-- ex1 = DAdd (DInt 5) (AAdd (AInt 30) (AInt 7))
-- ex1' : AExp [] (D Int)
-- ex1' = AApp (ALam (DAdd (DInt 5) x)) (AApp (ALam (DInt x) (AInt 30) (AInt 7)))
-- TODO: this example does not work due to the very restrictive type
-- off Add/DAdd. We could add a subsumption operator to AExp that
-- turns a static expression into a dynamic one and then build a
-- smart constructor for addition on top of that
-- Note:This case is omitted in the same way as we impose the restriction that
-- a dynamic function can only have components which are also dynamic.
-- Another simple case is the specialization for a static identity
-- function:
-- (Sλ x → x) (42D) ---specializes to--> 42D
ex1 : AExp [] (D Int)
ex1 = AApp (ALam (Var hd)) (DInt 42)
ex1-spec : Exp [] Int
ex1-spec = EInt 42
-- The above example can be rewritten as an open AExp term that
-- should be closed with a suitable environment. This representation
-- does not only corresponds more directly with the notion of
-- ``static inputs'', it also illustrates a typical situation when
-- specializing the body of a lambda abstraction:
-- The program ex1' takes an Int→Int function x as a static input.
--ex1' : AExp [ AFun (D Int) (D Int) ] (D Int)
--ex1' = AApp x (DInt 42)
---------------------
-- Some more examples
---------------------
------------------
-- Pairs
------------------
------------------
-- a. Static Pairs
------------------
ex2 : AExp [] (D Int)
ex2 = Snd (AInt 42 , DInt 42)
ex3 : AExp [] (D Int)
ex3 = AApp (ALam (Snd (Var hd))) (AInt 42 , DInt 42)
-- similar to ex1'
--ex3' : AExp [ AFun (AInt • (D Int)) (D Int) ] (D Int)
--ex3' = AApp x (AInt 42 , DInt 42)
-------------------
-- b. Dynamic Pairs
-------------------
ex4 : AExp [] (D Int)
ex4 = AApp (ALam (DSnd (Var hd))) ( DInt 43 ḋ DInt 42)
-- similar to ex1'
--ex4' : AExp [ AFun (D (Int • Int)) (D Int) ] (D Int)
--ex4' = AApp x (DInt 43 ḋ DInt 42)
---------------------
-- Sums
---------------------
-----------------
-- a. Static Sums
-----------------
ex5 : AExp [] AInt
ex5 = Case {α₂ = AInt} (Tl (AInt 0)) (Var hd) (Var hd)
ex6 : AExp [] AInt
ex6 = Case {α₁ = AInt} (Tr (AInt 0)) (Var hd) (AInt 10)
ex7 : AExp [] (AFun AInt AInt)
ex7 = Case {α₂ = AInt} (Tl (ALam (Var hd))) (Var hd) (ALam (Var hd))
------------------
-- b. Dynamic Sums
------------------
ex8 : AExp [] (D Int)
ex8 = DCase {σ₂ = Int} (DTl (DInt 0)) (Var hd) (Var hd)
ex9 : AExp [] (D Int)
ex9 = DCase {σ₁ = Int} (DTr (DInt 0)) (Var hd) (DInt 10)
ex10 : AExp [] (D (Fun Int Int))
ex10 = DCase {σ₂ = Int} (DTl (DLam (Var hd))) (Var hd) (DLam (Var hd))
-- The partial evaluation of ex1' requires an environment to look up
-- the static input. As a first approximation, a single input of
-- type α is just some annotated term of type type α:
Input : ∀ α → Set
Input α = (∃ λ Δ → AExp Δ α)
----------------------------
-- alternative specification
----------------------------
--record Sg (S : Set) (T : S → Set) : Set where
-- constructor _,_
-- field
-- ffst : S
-- ssnd : T ffst
--open Sg public
--Input' : ∀ α → Set
--Input' α = Sg ACtx \ x → AExp x α
-- Note that [input'] should be equivalent to [input]
-- (convenience constructor for Inputs)
inp : ∀ {α Δ} → AExp Δ α → Input α
inp {α} {Δ} e = Δ , e
-- An environment is simply a list of inputs that agrees with a
-- given typing context.
data AEnv : ACtx → Set where
[] : AEnv []
_∷_ : ∀ {α Δ} → Input α → AEnv Δ → AEnv (α ∷ Δ)
lookup : ∀ {α Δ} → AEnv Δ → α ∈ Δ → Input α
lookup [] ()
lookup (x ∷ env) hd = x
lookup (x ∷ env) (tl id) = lookup env id
-- Thus, an environment like ex1'-env should be able to close ex1'
-- and a partial evaluation of the closure should yield the same
-- result as in example ex1:
--ex1'-env : AEnv [ AFun (D Int) (D Int) ]
--ex1'-env = inp (ALam {[]} {D Int} (Var hd)) ∷ []
-- Similarly, an environment like ex3'-env should be able to close ex3'
-- and a partial evaluation of the closure should yield the same
-- result as in example ex3:
--ex3'-env : AEnv [ AFun (AInt • (D Int)) (D Int) ]
--ex3'-env = inp (ALam {[]} {AInt • (D Int)} (Snd (Var hd))) ∷ []
-- Also, an environment like ex4'-env should be able to close ex4'
-- and a partial evaluation of the closure should yield the same
-- result as in example ex4:
--ex4'-env : AEnv [ AFun (D (Int • Int)) (D Int) ]
--ex4'-env = inp (ALam {[]} {D (Int • Int)} (DSnd (Var hd))) ∷ []
-- TODO: unit test
ex1'-spec = ex1-spec
ex3'-spec = ex1-spec
ex4'-spec = ex1-spec
-- (some definitions for the example)
open import Data.Maybe
_=<<_ : ∀ {A B : Set} → (A → Maybe B) → Maybe A → Maybe B
f =<< mx = maybe′ f nothing mx
liftM2 : ∀ {A B C : Set} → (A → B → Maybe C) → Maybe A → Maybe B → Maybe C
liftM2 f mx my = (λ x → (λ y → f x y) =<< my) =<< mx
-- The partial function ex1'-pe demonstrates the desired calculation
-- for the specific case of ex1':
ex1'-pe : ∀ {Δ} → AEnv Δ → AExp Δ (D Int) → Maybe (Exp [] Int)
ex1'-pe {Δ} env (AApp ef ei)
= liftM2 fromApp
(fromInput =<< fromVar ef)
(fromInt ei)
where fromInput : ∀ {α} → Input α → Maybe (Exp [] Int → Exp [] Int)
fromInput (_ , ALam {D Int} (Var hd)) = just (λ x → x)
-- Sλ x/D → x
fromInput _ = nothing
fromVar : ∀ {α} → AExp Δ α → Maybe (Input α)
fromVar (Var x) = just (lookup env x)
fromVar _ = nothing
fromApp : (Exp [] Int → Exp [] Int) → Exp [] Int → Maybe (Exp [] Int)
fromApp f x = just (f x)
fromInt : ∀ {α} → AExp Δ α → Maybe (Exp [] Int)
fromInt (DInt i) = just (EInt {[]} i)
fromInt _ = nothing
ex1'-pe _ _ = nothing
open import Relation.Binary.PropositionalEquality
check-ex1'-pe : ex1'-pe ex1'-env ex1' ≡ just (ex1'-spec)
check-ex1'-pe = refl
-- Similarly the partial function ex3'-pe demonstrates the desired calculation
-- for the specific case of ex3':
ex3'-pe : ∀ {Δ} → AEnv Δ → AExp Δ (D Int) → Maybe (Exp [] Int)
ex3'-pe {Δ} env (AApp ef ei)
= liftM2 fromApp
(fromInput =<< fromVar ef)
(fromPair ei)
where fromInput : ∀ {α} → Input α → Maybe ((ℕ * (Exp [] Int)) → Exp [] Int)
fromInput (_ , ALam {AInt • (D Int)} (Snd (Var hd))) = just (λ x → (snd x))
-- Sλ x/(S*D) → (snd x)
fromInput _ = nothing
fromVar : ∀ {α} → AExp Δ α → Maybe (Input α)
fromVar (Var x) = just (lookup env x)
fromVar _ = nothing
fromApp : ((ℕ * (Exp [] Int)) → Exp [] Int) → (ℕ * (Exp [] Int)) → Maybe (Exp [] Int)
fromApp f x = just (f x)
fromPair : ∀ {α} → AExp Δ α → Maybe (ℕ * (Exp [] Int))
fromPair ((AInt j) , (DInt i)) = just (j , (EInt {[]} i))
fromPair _ = nothing
ex3'-pe _ _ = nothing
open import Relation.Binary.PropositionalEquality
check-ex3'-pe : ex3'-pe ex3'-env ex3' ≡ just (ex3'-spec)
check-ex3'-pe = refl
-- Similarly the partial function ex3'-pe demonstrates the desired calculation
-- for the specific case of ex3':
ex4'-pe : ∀ {Δ} → AEnv Δ → AExp Δ (D Int) → Maybe (Exp [] Int)
ex4'-pe {Δ} env (AApp ef ei)
= liftM2 fromApp
(fromInput =<< fromVar ef)
(fromDPair ei)
where fromInput : ∀ {α} → Input α → Maybe (((Exp [] Int) * (Exp [] Int)) → Exp [] Int)
fromInput (_ , ALam {D (Int • Int)} (DSnd (Var hd))) = just (λ x → (snd x))
-- Sλ x/(S*D) → (snd x)
fromInput _ = nothing
fromVar : ∀ {α} → AExp Δ α → Maybe (Input α)
fromVar (Var x) = just (lookup env x)
fromVar _ = nothing
fromApp : (((Exp [] Int) * (Exp [] Int)) → Exp [] Int) → ((Exp [] Int) * (Exp [] Int)) → Maybe (Exp [] Int)
fromApp f x = just (f x)
fromDPair : ∀ {α} → AExp Δ α → Maybe ((Exp [] Int) * (Exp [] Int))
fromDPair ((DInt j) ḋ (DInt i)) = just ((EInt {[]} j) , (EInt {[]} i))
fromDPair _ = nothing
ex4'-pe _ _ = nothing
open import Relation.Binary.PropositionalEquality
check-ex4'-pe : ex4'-pe ex4'-env ex4' ≡ just (ex4'-spec)
check-ex4'-pe = refl
-- The examples above show several problems for a total
-- generalization to arbitrary term with the current datastructures:
-- - the argument to fromApp is not primitive recursive
-- What?
-- - the result type of fromInput generates the context of the returned expression
-- ``out of thin air''
-- - Note "out of thin air" in a sense that the "typing context for the value" is only restricted by
-- the value v itself thus any Δ which types v will do. Also note there is no connection between
-- "typing context for the value" and the "typing context"
-- TODO: continue
-- Dλ y → let f = λ x → x D+ y in Dλ z → f z
term1 : AExp [] (D (Fun Int (Fun Int Int)))
term1 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
((ALam (DAdd x y))))
-- Dλ y → let f = λ x → (Dλ w → x D+ y) in Dλ z → f z
-- Dλ y → (λ f → Dλ z → f z) (λ x → (Dλ w → x D+ y))
-- wrong
term2 : AExp [] (D (Fun Int (Fun Int Int)))
term2 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
((ALam (DLam {σ₁ = Int} (DAdd y z)))))
-- ?
term3 : AExp [] (D (Fun Int (Fun Int Int)))
term3 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
(DInt 0))
-- correct!
term4 : AExp [] (D (Fun Int (Fun Int (Fun Int Int))))
term4 = DLam (AApp (ALam (DLam (AApp y x)))
((ALam (DLam {σ₁ = Int} (DAdd y z)))))
------------------
-- Some more terms
------------------
-}
{-
module CheckExamples where
open import Relation.Binary.PropositionalEquality
open SimpleAEnv
open AExp-Examples
check-ex1 : pe ex1 [] ≡ ex1-spec
check-ex1 = refl
-------------
-- Similarly
------------
check-ex3 : pe ex3 [] ≡ ex1-spec
check-ex3 = refl
-------
-- Also
-------
check-ex4 : pe {Γ = []} ex4 [] ≡ ESnd (EInt 43 , EInt 42)
check-ex4 = refl
module Examples where
open SimpleAEnv
open import Relation.Binary.PropositionalEquality
x : ∀ {α Δ} → AExp (α ∷ Δ) α
x = Var hd
y : ∀ {α₁ α Δ} → AExp (α₁ ∷ α ∷ Δ) α
y = Var (tl hd)
z : ∀ {α₁ α₂ α Δ} → AExp (α₁ ∷ α₂ ∷ α ∷ Δ) α
z = Var (tl (tl hd))
-- Dλ y → let f = λ x → x D+ y in Dλ z → f z
term1 : AExp [] (D (Fun Int (Fun Int Int)))
term1 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
((ALam (DAdd x y))))
-- Dλ y → let f = λ x → (Dλ w → x D+ y) in Dλ z → f z
-- Dλ y → (λ f → Dλ z → f z) (λ x → (Dλ w → x D+ y))
term2 : AExp [] (D (Fun Int (Fun Int Int)))
term2 = DLam (AApp (ALam (DLam (AApp (ALam y) x)))
((ALam (DLam {σ₁ = Int} (DAdd y z)))))
-- closed pe. In contrast to BTA5, it is now not clear what Γ is
-- given an expression. So perhaps AEnv has it's merrits after all?
pe[] : ∀ {α} → AExp [] α → Imp [] α
pe[] e = pe e []
ex-pe-term1 : pe[] term1 ≡ ELam (ELam (EVar hd))
ex-pe-term1 = refl
ex-pe-term2 : pe[] term2 ≡ ELam (ELam (EVar hd))
ex-pe-term2 = refl
--------------------------
-- Tests on pairs and sums
--------------------------
-}
|
{
"alphanum_fraction": 0.5486655579,
"avg_line_length": 33.2289473684,
"ext": "agda",
"hexsha": "c56259d3081466dece6b4dca258dda0683d95ef4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-10-15T09:01:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-10-15T09:01:37.000Z",
"max_forks_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "luminousfennell/polybta",
"max_forks_repo_path": "Examples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"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": "luminousfennell/polybta",
"max_issues_repo_path": "Examples.agda",
"max_line_length": 118,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "luminousfennell/polybta",
"max_stars_repo_path": "Examples.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-15T04:35:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-15T04:35:29.000Z",
"num_tokens": 4250,
"size": 12627
}
|
open import Numeral.Natural
open import Type
module Formalization.ClassicalPredicateLogic.Syntax {ℓₚ ℓᵥ ℓₒ} (Prop : ℕ → Type{ℓₚ}) (Var : Type{ℓᵥ}) (Obj : ℕ → Type{ℓₒ}) where
open import Data.ListSized
import Lvl
open import Functional using (_∘_ ; _∘₂_ ; swap)
open import Sets.PredicateSet using (PredSet)
private variable ℓ : Lvl.Level
private variable n : ℕ
data Term : Type{ℓᵥ Lvl.⊔ ℓₒ} where
var : Var → Term -- Variables
func : Obj(n) → List(Term)(n) → Term -- Constants/functions
-- Formulas.
-- Inductive definition of the grammatical elements of the language of predicate logic.
data Formula : Type{ℓₚ Lvl.⊔ ℓᵥ Lvl.⊔ ℓₒ} where
_$_ : Prop(n) → List(Term)(n) → Formula -- Relations
⊤ : Formula -- Tautology (Top / True)
⊥ : Formula -- Contradiction (Bottom / False)
_∧_ : Formula → Formula → Formula -- Conjunction (And)
_∨_ : Formula → Formula → Formula -- Disjunction (Or)
_⟶_ : Formula → Formula → Formula -- Implication
Ɐ : Var → Formula → Formula
∃ : Var → Formula → Formula
infix 1011 _$_
infixr 1005 _∧_
infixr 1004 _∨_
infixr 1000 _⟶_
-- Negation
¬_ : Formula → Formula
¬_ = _⟶ ⊥
-- Double negation
¬¬_ : Formula → Formula
¬¬_ = (¬_) ∘ (¬_)
-- Reverse implication
_⟵_ : Formula → Formula → Formula
_⟵_ = swap(_⟶_)
-- Equivalence
_⟷_ : Formula → Formula → Formula
p ⟷ q = (p ⟵ q) ∧ (p ⟶ q)
-- (Nor)
_⊽_ : Formula → Formula → Formula
_⊽_ = (¬_) ∘₂ (_∨_)
-- (Nand)
_⊼_ : Formula → Formula → Formula
_⊼_ = (¬_) ∘₂ (_∧_)
-- (Exclusive or / Xor)
_⊻_ : Formula → Formula → Formula
_⊻_ = (¬_) ∘₂ (_⟷_)
infix 1010 ¬_ ¬¬_
infixl 1000 _⟵_ _⟷_
|
{
"alphanum_fraction": 0.6347230865,
"avg_line_length": 23.6323529412,
"ext": "agda",
"hexsha": "cf4c5aff3c5a5c929fd468ed2fad143bc419458f",
"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/ClassicalPredicateLogic/Syntax.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/ClassicalPredicateLogic/Syntax.agda",
"max_line_length": 128,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Formalization/ClassicalPredicateLogic/Syntax.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": 621,
"size": 1607
}
|
-- Andreas, 2018-06-14, issue #2513, do not allow conflicting relevance info.
postulate
Foo : {A : Set} → ..(@irrelevant A) → A
-- Should fail. (Currently: parse error)
|
{
"alphanum_fraction": 0.6609195402,
"avg_line_length": 24.8571428571,
"ext": "agda",
"hexsha": "de408e4becd193e4428ff5ad39139b627aff3d2c",
"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/ConflictingRelevance2.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/ConflictingRelevance2.agda",
"max_line_length": 77,
"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/ConflictingRelevance2.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": 55,
"size": 174
}
|
{-
This second-order signature was created from the following second-order syntax description:
syntax Inception | IA
type
L : 0-ary
P : 0-ary
A : 0-ary
term
rec : L P -> A
inc : L.A P.A -> A
theory
(S) p : P a : P.A |> inc (l. rec (l, p[]), x. a[x]) = a[p[]]
(E) a : L.A |> k : L |- inc (l. a[l], x. rec(k, x)) = a[k]
(W) m : A a : P.A |> inc (l. m[], x. a[x]) = m[]
(A) p : (L,L).A a : (L,P).A b : P.A |> inc (l. inc (k. p[l, k], x. a[l,x]), y. b[y]) = inc (k. inc(l. p[l,k], y.b[y]), x. inc(l. a[l,x], y.b[y]))
-}
module Inception.Signature where
open import SOAS.Context
-- Type declaration
data IAT : Set where
L : IAT
P : IAT
A : IAT
open import SOAS.Syntax.Signature IAT public
open import SOAS.Syntax.Build IAT public
-- Operator symbols
data IAₒ : Set where
recₒ incₒ : IAₒ
-- Term signature
IA:Sig : Signature IAₒ
IA:Sig = sig λ
{ recₒ → (⊢₀ L) , (⊢₀ P) ⟼₂ A
; incₒ → (L ⊢₁ A) , (P ⊢₁ A) ⟼₂ A
}
open Signature IA:Sig public
|
{
"alphanum_fraction": 0.5332011893,
"avg_line_length": 20.5918367347,
"ext": "agda",
"hexsha": "6d84aad74b43a8375a565719099a39972ad95dee",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/Inception/Signature.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/Inception/Signature.agda",
"max_line_length": 163,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/Inception/Signature.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 424,
"size": 1009
}
|
module Oscar.Data.Equality where
open import Agda.Builtin.Equality public using (_≡_; refl) public
open import Relation.Binary.PropositionalEquality public using (_≢_) public
open import Relation.Binary.PropositionalEquality public using (cong; cong₂; cong-app; subst; subst₂; sym; trans) public
open import Oscar.Level
open import Oscar.Function
open import Oscar.Relation
infix 4 _≡̇_
_≡̇_ : ∀ {a} {A : Set a} {b} {B : A → Set b} → ((x : A) → B x) → ((x : A) → B x) → Set (a ⊔ b)
f ≡̇ g = ∀ x → f x ≡ g x
≡̇-refl : ∀ {a} {A : Set a} {b} {B : A → Set b} (f : (x : A) → B x) → f ≡̇ f
≡̇-refl _ _ = refl
≡̇-sym : ∀ {a} {A : Set a} {b} {B : A → Set b} {f g : (x : A) → B x} → f ≡̇ g → g ≡̇ f
≡̇-sym f≡̇g = sym ∘ f≡̇g
≡̇-trans : ∀ {a} {A : Set a} {b} {B : A → Set b} {f g : (x : A) → B x} → f ≡̇ g → {h : (x : A) → B x} → g ⟨ _≡̇ h ⟩→ f
≡̇-trans f≡̇g g≡̇h x = trans (f≡̇g x) (g≡̇h x)
open import Oscar.Category
≡-setoid : ∀ {a} (A : Set a) → Setoid A a
Setoid._≋_ (≡-setoid A) = _≡_
Setoid.≋-reflexivity (≡-setoid A) = refl
Setoid.≋-symmetry (≡-setoid A) = sym
Setoid.≋-transitivity (≡-setoid A) x≡y = trans x≡y
≡̇-setoid : ∀ {a} {A : Set a} {b} (B : A → Set b) → Setoid ((x : A) → B x) (a ⊔ b)
Setoid._≋_ (≡̇-setoid B) = _≡̇_
Setoid.≋-reflexivity (≡̇-setoid B) = ≡̇-refl _
Setoid.≋-symmetry (≡̇-setoid B) = ≡̇-sym
Setoid.≋-transitivity (≡̇-setoid B) = ≡̇-trans
|
{
"alphanum_fraction": 0.550036523,
"avg_line_length": 36.0263157895,
"ext": "agda",
"hexsha": "de6d2974d34ebb4066f32edc2b25a56748d80c1d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Data/Equality.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Data/Equality.agda",
"max_line_length": 120,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Data/Equality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 688,
"size": 1369
}
|
module Example where
open import Base
open import Nat
open import univ
-- Application
_#_ : {A : S}{F : El A -> S}{pF : Map _==_ _=S_ F} ->
El (pi A F pF) -> (x : El A) -> El (F x)
el < f , pf > # x = f x
-- Projection
π₀ : {A : S}{F : El A -> S}{pF : Map _==_ _=S_ F} ->
El (sigma A F pF) -> El A
π₀ (el < x , Fx >) = x
π₁ : {A : S}{F : El A -> S}{pF : Map _==_ _=S_ F} ->
(p : El (sigma A F pF)) -> El (F (π₀ p))
π₁ (el < x , Fx >) = Fx
|
{
"alphanum_fraction": 0.4600431965,
"avg_line_length": 19.2916666667,
"ext": "agda",
"hexsha": "0b6618e346c7bec43d51edbc4a7adfd510d21142",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/univ/Example.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/univ/Example.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": "examples/outdated-and-incorrect/univ/Example.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": 209,
"size": 463
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Definition
open import Setoids.Setoids
open import Functions.Definition
open import Sets.EquivalenceRelations
open import Rings.Definition
open import Lists.Lists
module Rings.Polynomial.Multiplication {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} (R : Ring S _+_ _*_) where
open Ring R
open Group additiveGroup
open import Groups.Polynomials.Definition additiveGroup
open import Groups.Polynomials.Group additiveGroup
open Setoid S
open Equivalence eq
_*P_ : NaivePoly → NaivePoly → NaivePoly
[] *P b = []
(x :: a) *P [] = []
(x :: a) *P (y :: b) = (x * y) :: (((map (x *_) b) +P (map (y *_) a)) +P (0R :: (a *P b)))
abstract
+PCommutative : {x y : NaivePoly} → polysEqual (x +P y) (y +P x)
+PCommutative {x} {y} = comm (record { commutative = groupIsAbelian }) {x} {y}
p*Commutative : {a b : NaivePoly} → polysEqual (a *P b) (b *P a)
p*Commutative {[]} {[]} = record {}
p*Commutative {[]} {x :: b} = record {}
p*Commutative {x :: a} {[]} = record {}
p*Commutative {x :: xs} {y :: ys} = *Commutative ,, +PwellDefined (+PCommutative {map (_*_ x) ys} {map (_*_ y) xs}) (reflexive ,, p*Commutative {xs} {ys})
zeroTimes1 : {a : NaivePoly} (c : A) → (c ∼ 0G) → polysEqual (map (_*_ c) a) []
zeroTimes1 {[]} c c=0 = record {}
zeroTimes1 {x :: a} c c=0 = transitive (transitive *Commutative (*WellDefined reflexive c=0)) (timesZero {x}) ,, zeroTimes1 {a} c c=0
zeroTimes2 : {a : NaivePoly} (c : A) → polysEqual a [] → polysEqual (map (_*_ c) a) []
zeroTimes2 {[]} c a=0 = record {}
zeroTimes2 {x :: a} c (fst ,, snd) = transitive (*WellDefined reflexive fst) (timesZero {c}) ,, zeroTimes2 {a} c snd
mapWellDefined : (a c : A) (bs : NaivePoly) → (a ∼ c) → polysEqual (map (_*_ a) bs) (map (_*_ c) bs)
mapWellDefined a c [] a=c = record {}
mapWellDefined a c (x :: bs) a=c = *WellDefined a=c reflexive ,, mapWellDefined a c bs a=c
mapWellDefined' : (a : A) (bs cs : NaivePoly) → polysEqual bs cs → polysEqual (map (_*_ a) bs) (map (_*_ a) cs)
mapWellDefined' a [] [] bs=cs = record {}
mapWellDefined' a [] (x :: cs) (fst ,, snd) = transitive (*WellDefined reflexive fst) (timesZero {a}) ,, Equivalence.symmetric (Setoid.eq naivePolySetoid) (zeroTimes2 {cs} a (Equivalence.symmetric (Setoid.eq naivePolySetoid) snd))
mapWellDefined' a (x :: bs) [] (fst ,, snd) = transitive (*WellDefined reflexive fst) (timesZero {a}) ,, zeroTimes2 {bs} a snd
mapWellDefined' a (b :: bs) (c :: cs) (fst ,, snd) = *WellDefined reflexive fst ,, mapWellDefined' a bs cs snd
*PwellDefinedL : {a b c : NaivePoly} → polysEqual a c → polysEqual (a *P b) (c *P b)
*PwellDefinedL {[]} {[]} {[]} a=c = record {}
*PwellDefinedL {[]} {[]} {x :: c} a=c = record {}
*PwellDefinedL {[]} {x :: b} {[]} a=c = record {}
*PwellDefinedL {[]} {b :: bs} {c :: cs} (fst ,, snd) = transitive (transitive *Commutative (*WellDefined reflexive fst)) (timesZero {b}) ,, Equivalence.transitive (Setoid.eq naivePolySetoid) (Equivalence.transitive (Setoid.eq naivePolySetoid) {_} {(map (_*_ c) bs) +P (0G :: (cs *P bs))} (Equivalence.transitive (Setoid.eq naivePolySetoid) {_} {[] +P (0G :: (cs *P bs))} (reflexive ,, ans) (+PwellDefined (Equivalence.symmetric (Setoid.eq naivePolySetoid) (zeroTimes1 {bs} c fst)) (Equivalence.reflexive (Setoid.eq naivePolySetoid) {0G :: (cs *P bs)}))) (+PwellDefined (Equivalence.symmetric (Setoid.eq naivePolySetoid) (Group.identRight polyGroup {map (_*_ c) bs})) (Equivalence.reflexive (Setoid.eq naivePolySetoid) {0G :: (cs *P bs)}))) (+PwellDefined {(map (_*_ c) bs +P [])} {0G :: (cs *P bs)} {(map (_*_ c) bs) +P map (_*_ b) cs} (+PwellDefined (Equivalence.reflexive (Setoid.eq naivePolySetoid) {map (_*_ c) bs}) (Equivalence.symmetric (Setoid.eq naivePolySetoid) (zeroTimes2 {cs} b (Equivalence.symmetric (Setoid.eq naivePolySetoid) snd)))) (Equivalence.reflexive (Setoid.eq naivePolySetoid) {0G :: (cs *P bs)}))
where
ans : polysEqual [] (map id (cs *P bs))
ans rewrite mapId (cs *P bs) = *PwellDefinedL snd
*PwellDefinedL {a :: as} {[]} {[]} a=c = record {}
*PwellDefinedL {a :: as} {[]} {x :: c} a=c = record {}
*PwellDefinedL {a :: as} {b :: bs} {[]} (fst ,, snd) = transitive (transitive *Commutative (*WellDefined reflexive fst)) (timesZero {b}) ,, Equivalence.transitive (Setoid.eq naivePolySetoid) (+PwellDefined {(map (_*_ a) bs +P map (_*_ b) as)} {0G :: (as *P bs)} {[] +P []} {[]} (+PwellDefined {map (_*_ a) bs} {map (_*_ b) as} {[]} {[]} (zeroTimes1 {bs} a fst) (zeroTimes2 {as} b snd)) (reflexive ,, *PwellDefinedL {as} {bs} {[]} snd)) (record {})
*PwellDefinedL {a :: as} {b :: bs} {c :: cs} (fst ,, snd) = *WellDefined fst reflexive ,, +PwellDefined {(map (_*_ a) bs) +P (map (_*_ b) as)} {0G :: (as *P bs)} {map (_*_ c) bs +P map (_*_ b) cs} {0G :: (cs *P bs)} (+PwellDefined {map (_*_ a) bs} {map (_*_ b) as} {map (_*_ c) bs} {map (_*_ b) cs} (mapWellDefined a c bs fst) (mapWellDefined' b as cs snd)) (reflexive ,, *PwellDefinedL {as} {bs} {cs} snd)
*PwellDefinedR : {a b c : NaivePoly} → polysEqual b c → polysEqual (a *P b) (a *P c)
*PwellDefinedR {a} {b} {c} b=c = Equivalence.transitive (Setoid.eq naivePolySetoid) (p*Commutative {a} {b}) (Equivalence.transitive (Setoid.eq naivePolySetoid) (*PwellDefinedL b=c) (p*Commutative {c} {a}))
*PwellDefined : {a b c d : NaivePoly} → polysEqual a c → polysEqual b d → polysEqual (a *P b) (c *P d)
*PwellDefined {a}{b}{c}{d} a=c b=d = Equivalence.transitive (Setoid.eq naivePolySetoid) (*PwellDefinedL a=c) (*PwellDefinedR b=d)
private
*1 : (a : NaivePoly) → polysEqual (map (_*_ 1R) a) a
*1 [] = record {}
*1 (x :: a) = Ring.identIsIdent R ,, *1 a
*Pident : {a : NaivePoly} → polysEqual ((1R :: []) *P a) a
*Pident {[]} = record {}
*Pident {x :: a} = Ring.identIsIdent R ,, Equivalence.transitive (Setoid.eq naivePolySetoid) (+PwellDefined {map (_*_ 1R) a +P []} {0G :: []} {map (_*_ 1R) a} {[]} (Group.identRight polyGroup) (reflexive ,, record {})) (Equivalence.transitive (Setoid.eq naivePolySetoid) (Group.identRight polyGroup {map (_*_ 1R) a}) (*1 a))
private
mapMap' : (f g : A → A) (xs : NaivePoly) → map f (map g xs) ≡ map (λ x → f (g x)) xs
mapMap' f g [] = refl
mapMap' f g (x :: xs) rewrite mapMap' f g xs = refl
mapMap'' : (f g : A → A) (xs : NaivePoly) → Setoid._∼_ naivePolySetoid (map f (map g xs)) (map (λ x → f (g x)) xs)
mapMap'' f g xs rewrite mapMap' f g xs = Equivalence.reflexive (Setoid.eq naivePolySetoid)
mapWd : (f g : A → A) (xs : NaivePoly) → ((x : A) → (f x) ∼ (g x)) → polysEqual (map f xs) (map g xs)
mapWd f g [] ext = record {}
mapWd f g (x :: xs) ext = ext x ,, mapWd f g xs ext
mapDist' : (b c : A) → (as : NaivePoly) → polysEqual (map (_*_ (b + c)) as) (map (_*_ c) as +P map (_*_ b) as)
mapDist' b c [] = record {}
mapDist' b c (x :: as) = transitive (Ring.*DistributesOver+' R {b} {c} {x}) groupIsAbelian ,, mapDist' b c as
mapTimes : (a b : NaivePoly) (c : A) → polysEqual (a *P (map (_*_ c) b)) (map (_*_ c) (a *P b))
mapTimes [] b c = record {}
mapTimes (a :: as) [] c = record {}
mapTimes (a :: as) (x :: b) c = transitive *Associative (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative)) ,, trans (+PwellDefined {(map (_*_ a) (map (_*_ c) b)) +P map (_*_ (c * x)) as} {0G :: (as *P map (_*_ c) b)} {map (_*_ c) (map (_*_ a) b +P map (_*_ x) as)} (trans (+PwellDefined {map (_*_ a) (map (_*_ c) b)} {map (_*_ (c * x)) as} {map (_*_ c) (map (_*_ a) b)} (trans (mapMap'' (_*_ a) (_*_ c) b) (trans (mapWd (λ x → a * (c * x)) (λ x → c * (a * x)) b (λ x → transitive *Associative (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative)))) (sym (mapMap'' (_*_ c) (_*_ a) b)))) (trans (mapWd (_*_ (c * x)) (λ y → c * (x * y)) as λ y → symmetric *Associative) (sym (mapMap'' (_*_ c) (_*_ x) as)))) (sym (mapDist (_*_ c) *DistributesOver+ (map (_*_ a) b) (map (_*_ x) as)))) (symmetric timesZero ,, mapTimes as b c)) (sym (mapDist (_*_ c) *DistributesOver+ (map (_*_ a) b +P map (_*_ x) as) (0G :: (as *P b))))
where
open Equivalence (Setoid.eq naivePolySetoid) renaming (transitive to trans ; symmetric to sym ; reflexive to ref)
mapTimes' : (a b : NaivePoly) (c : A) → polysEqual (map (_*_ c) (a *P b)) ((map (_*_ c) a) *P b)
mapTimes' a b c = trans (trans (mapWellDefined' c (a *P b) (b *P a) (p*Commutative {a} {b})) (sym (mapTimes b a c))) (p*Commutative {b} {map (_*_ c) a})
where
open Equivalence (Setoid.eq naivePolySetoid) renaming (transitive to trans ; symmetric to sym ; reflexive to ref)
bumpTimes' : (a bs : NaivePoly) (b : A) → polysEqual (a *P (b :: bs)) (map (_*_ b) a +P (0G :: (a *P bs)))
bumpTimes' [] bs b = reflexive ,, record {}
bumpTimes' (x :: a) bs b = transitive *Commutative (symmetric identRight) ,, trans (+PwellDefined {map (_*_ x) bs +P map (_*_ b) a} {0G :: (a *P bs)} {_} {0G :: (a *P bs)} (+PCommutative {map (_*_ x) bs} {map (_*_ b) a}) (ref {0G :: (a *P bs)})) (trans (sym (Group.+Associative polyGroup {map (_*_ b) a})) (+PwellDefined {map (_*_ b) a} {_} {map (_*_ b) a} {_} (ref {map (_*_ b) a}) (trans (trans (+PwellDefined {map (_*_ x) bs} {_} {map (_*_ x) bs} (ref {map (_*_ x) bs}) (reflexive ,, p*Commutative {a})) (sym (bumpTimes' bs a x))) (p*Commutative {bs}))))
where
open Equivalence (Setoid.eq naivePolySetoid) renaming (transitive to trans ; symmetric to sym ; reflexive to ref)
bumpTimes : {a b : NaivePoly} → polysEqual (a *P (0G :: b)) (0G :: (a *P b))
bumpTimes {[]} {b} = reflexive ,, record {}
bumpTimes {x :: a} {[]} = timesZero ,, trans (sym (Group.+Associative polyGroup {[]} {map (_*_ 0G) a})) ans
where
open Equivalence (Setoid.eq naivePolySetoid) renaming (transitive to trans ; symmetric to sym ; reflexive to ref)
ans : polysEqual (map id (map (_*_ 0G) a +P (0G :: (a *P [])))) []
ans rewrite mapId (map (_*_ 0G) a +P (0G :: (a *P []))) = (+PwellDefined {map (_*_ 0G) a} {0G :: (a *P [])} {[]} {[]} (zeroTimes1 0G reflexive) (reflexive ,, p*Commutative {a}))
bumpTimes {x :: a} {b :: bs} = timesZero ,, trans (+PwellDefined {((x * b) :: map (_*_ x) bs) +P map (_*_ 0G) a} {0G :: (a *P (b :: bs))} {(x * b) :: map (_*_ x) bs} {0G :: (a *P (b :: bs))} (trans (+PwellDefined {(x * b) :: map (_*_ x) bs} {map (_*_ 0G) a} {(x * b) :: map (_*_ x) bs} {[]} (ref {(x * b) :: map (_*_ x) bs}) (zeroTimes1 0G reflexive)) (Group.identRight polyGroup {(x * b) :: map (_*_ x) bs})) (ref {0G :: (a *P (b :: bs))})) (identRight ,, trans (+PwellDefined {map (_*_ x) bs} {_} {map (_*_ x) bs} ref (bumpTimes' a bs b)) (Group.+Associative polyGroup {map (_*_ x) bs} {map (_*_ b) a} {0G :: (a *P bs)}))
where
open Equivalence (Setoid.eq naivePolySetoid) renaming (transitive to trans ; symmetric to sym ; reflexive to ref)
*Pdistrib : {a b c : NaivePoly} → polysEqual (a *P (b +P c)) ((a *P b) +P (a *P c))
*Pdistrib {[]} {b} {c} = record {}
*Pdistrib {a :: as} {[]} {[]} = record {}
*Pdistrib {a :: as} {[]} {c :: cs} rewrite mapId cs | mapId ((map (_*_ a) cs +P map (_*_ c) as) +P (0G :: (as *P cs))) = reflexive ,, +PwellDefined {(map (_*_ a) cs) +P (map (_*_ c) as)} {_} {(map (_*_ a) cs) +P (map (_*_ c) as)} (Equivalence.reflexive (Setoid.eq naivePolySetoid)) (Equivalence.reflexive (Setoid.eq naivePolySetoid) {0G :: (as *P cs)})
*Pdistrib {a :: as} {b :: bs} {[]} rewrite mapId bs | mapId ((map (_*_ a) bs +P map (_*_ b) as) +P (0G :: (as *P bs))) = reflexive ,, +PwellDefined {(map (_*_ a) bs) +P (map (_*_ b) as)} {_} {(map (_*_ a) bs) +P (map (_*_ b) as)} (Equivalence.reflexive (Setoid.eq naivePolySetoid)) (Equivalence.reflexive (Setoid.eq naivePolySetoid) {0G :: (as *P bs)})
*Pdistrib {a :: as} {b :: bs} {c :: cs} = *DistributesOver+ ,, trans (+PwellDefined {(map (_*_ a) (bs +P cs)) +P (map (_*_ (b + c)) as)} {0G :: (as *P (bs +P cs))} {(map (_*_ a) bs +P map (_*_ b) as) +P ((map (_*_ a) cs) +P (map (_*_ c) as))} {0G :: ((as *P bs) +P (as *P cs))} (trans (+PwellDefined (mapDist (_*_ a) *DistributesOver+ bs cs) (mapDist' b c as)) (trans (sym (+Assoc {map (_*_ a) bs} {map (_*_ a) cs})) (trans (+PwellDefined (ref {map (_*_ a) bs}) (trans (trans (+Assoc {map (_*_ a) cs} {map (_*_ c) as}) ref) (+PCommutative {map (_*_ a) cs +P map (_*_ c) as} {map (_*_ b) as}))) (+Assoc {map (_*_ a) bs} {map (_*_ b) as})))) (reflexive ,, *Pdistrib {as} {bs} {cs})) (trans (sym (+Assoc {(map (_*_ a) bs +P map (_*_ b) as)} {(map (_*_ a) cs +P map (_*_ c) as)} {0G :: ((as *P bs) +P (as *P cs))})) (trans (+PwellDefined (ref {map (_*_ a) bs +P map (_*_ b) as}) (trans (trans (+PwellDefined (ref {map (_*_ a) cs +P map (_*_ c) as}) (symmetric identLeft ,, +PCommutative {as *P bs})) (+Assoc {map (_*_ a) cs +P (map (_*_ c) as)} {0G :: (as *P cs)} {0G :: (as *P bs)})) (+PCommutative {(map (_*_ a) cs +P map (_*_ c) as) +P (0G :: (as *P cs))} {0G :: (as *P bs)}))) (+Assoc {map (_*_ a) bs +P map (_*_ b) as} {0G :: (as *P bs)})))
where
open Equivalence (Setoid.eq naivePolySetoid) renaming (transitive to trans ; symmetric to sym ; reflexive to ref)
open Group polyGroup renaming (+Associative to +Assoc ; 0G to 0P) hiding (identLeft)
*Passoc : {a b c : NaivePoly} → polysEqual (a *P (b *P c)) ((a *P b) *P c)
*Passoc {[]} {b} {c} = record {}
*Passoc {a :: as} {[]} {c} = record {}
*Passoc {a :: as} {b :: bs} {[]} = record {}
*Passoc {a :: as} {b :: bs} {c :: cs} = *Associative ,, trans (+PwellDefined {(map (_*_ a) ((map (_*_ b) cs +P map (_*_ c) bs) +P (0G :: (bs *P cs))) +P map (_*_ (b * c)) as)} {0G :: (as *P ((map (_*_ b) cs +P map (_*_ c) bs) +P (0G :: (bs *P cs))))} {(((map (_*_ (a * b)) cs) +P (map (_*_ (a * c)) bs)) +P (map (_*_ a) (0G :: (bs *P cs)))) +P (map (_*_ (b * c)) as)} {0G :: (((map (_*_ b) (as *P cs)) +P (map (_*_ c) (as *P bs))) +P (as *P (0G :: (bs *P cs))))} (+PwellDefined {map (_*_ a) ((map (_*_ b) cs +P map (_*_ c) bs) +P (0G :: (bs *P cs)))} {map (_*_ (b * c)) as} {((map (_*_ (a * b)) cs +P map (_*_ (a * c)) bs) +P ((a * 0G) :: map (_*_ a) (bs *P cs)))} {map (_*_ (b * c)) as} (trans (mapDist (_*_ a) *DistributesOver+ (map (_*_ b) cs +P map (_*_ c) bs) (0G :: (bs *P cs))) (+PwellDefined {map (_*_ a) (map (_*_ b) cs +P map (_*_ c) bs)} {(a * 0G) :: map (_*_ a) (bs *P cs)} {map (_*_ (a * b)) cs +P map (_*_ (a * c)) bs} (trans (mapDist (_*_ a) *DistributesOver+ (map (_*_ b) cs) (map (_*_ c) bs)) (+PwellDefined {map (_*_ a) (map (_*_ b) cs)} {map (_*_ a) (map (_*_ c) bs)} {map (_*_ (a * b)) cs} (trans (mapMap'' (_*_ a) (_*_ b) cs) (mapWd (λ x → a * (b * x)) (_*_ (a * b)) cs (λ x → *Associative))) (trans (mapMap'' (_*_ a) (_*_ c) bs) (mapWd (λ x → a * (c * x)) (_*_ (a * c)) bs λ x → *Associative)))) (ref {(a * 0G) :: map (_*_ a) (bs *P cs)}))) (ref {map (_*_ (b * c)) as})) (reflexive ,, trans (*Pdistrib {as} {(map (_*_ b) cs +P map (_*_ c) bs)} {0G :: (bs *P cs)}) (+PwellDefined {(as *P (map (_*_ b) cs +P map (_*_ c) bs))} {as *P (0G :: (bs *P cs))} {(map (_*_ b) (as *P cs) +P map (_*_ c) (as *P bs))} (trans (*Pdistrib {as} {map (_*_ b) cs} {map (_*_ c) bs}) (+PwellDefined {as *P map (_*_ b) cs} {as *P map (_*_ c) bs} {map (_*_ b) (as *P cs)} (mapTimes as cs b) (mapTimes as bs c))) (ref {as *P (0G :: (bs *P cs))})))) (trans (trans (sym (Group.+Associative polyGroup {((map (_*_ (a * b)) cs) +P (map (_*_ (a * c)) bs)) +P ((a * 0G) :: map (_*_ a) (bs *P cs))})) (trans (sym (Group.+Associative polyGroup {(map (_*_ (a * b)) cs) +P (map (_*_ (a * c)) bs)})) (trans (sym (Group.+Associative polyGroup {map (_*_ (a * b)) cs})) (+PwellDefined {map (_*_ (a * b)) cs} (ref {map (_*_ (a * b)) cs}) (trans (trans ans (Group.+Associative polyGroup {map (_*_ c) (map (_*_ a) bs +P map (_*_ b) as)})) (+PwellDefined {_} {0G :: (((map (_*_ a) bs +P map (_*_ b) as) +P (0G :: (as *P bs))) *P cs)} {map (_*_ c) ((map (_*_ a) bs +P map (_*_ b) as) +P (0G :: (as *P bs)))} (sym (mapDist (_*_ c) *DistributesOver+ ((map (_*_ a) bs +P map (_*_ b) as)) (0G :: (as *P bs)))) (ref {0G :: (((map (_*_ a) bs +P map (_*_ b) as) +P (0G :: (as *P bs))) *P cs)}))))))) (Group.+Associative polyGroup {map (_*_ (a * b)) cs} {map (_*_ c) ((map (_*_ a) bs +P map (_*_ b) as) +P (0G :: (as *P bs)))}))
where
open Equivalence (Setoid.eq naivePolySetoid) renaming (transitive to trans ; symmetric to sym ; reflexive to ref)
open Group polyGroup renaming (+Associative to +Assoc ; 0G to 0P) hiding (identLeft ; identRight)
ans2 : polysEqual ((map (_*_ a) (bs *P cs) +P (map (_*_ b) (as *P cs) +P map (_*_ c) (as *P bs))) +P (as *P (0G :: (bs *P cs)))) (map (_*_ c) (as *P bs) +P (((map (_*_ a) bs +P map (_*_ b) as) +P (0G :: (as *P bs))) *P cs))
ans2 = trans (+PwellDefined {_} {as *P (0G :: (bs *P cs))} {_} {as *P (0G :: (bs *P cs))} (trans (+Assoc {map (_*_ a) (bs *P cs)} {map (_*_ b) (as *P cs)} {map (_*_ c) (as *P bs)}) (+PCommutative {map (_*_ a) (bs *P cs) +P map (_*_ b) (as *P cs)} {map (_*_ c) (as *P bs)})) ref) (trans (sym (+Assoc {map (_*_ c) (as *P bs)} {_} {as *P (0G :: (bs *P cs))}) ) (+PwellDefined {map (_*_ c) (as *P bs)} {_} {map (_*_ c) (as *P bs)} ref (trans (+PwellDefined {map (_*_ a) (bs *P cs) +P map (_*_ b) (as *P cs)} {as *P (0G :: (bs *P cs))} {((map (_*_ a) bs) *P cs) +P ((map (_*_ b) as) *P cs)} {0G :: (as *P (bs *P cs))} (+PwellDefined {map (_*_ a) (bs *P cs)} {map (_*_ b) (as *P cs)} {map (_*_ a) bs *P cs} {map (_*_ b) as *P cs} (mapTimes' bs cs a) (mapTimes' as cs b)) (bumpTimes {as} {bs *P cs})) (trans (trans (+PwellDefined {(map (_*_ a) bs *P cs) +P (map (_*_ b) as *P cs)} {0G :: (as *P (bs *P cs))} {cs *P (map (_*_ a) bs +P map (_*_ b) as)} {cs *P (0G :: (as *P bs))} (trans (+PwellDefined {map (_*_ a) bs *P cs} {map (_*_ b) as *P cs} {cs *P map (_*_ a) bs} {cs *P map (_*_ b) as} (p*Commutative {_} {cs}) (p*Commutative {_} {cs})) (sym (*Pdistrib {cs} {map (_*_ a) bs} {map (_*_ b) as}))) (trans (reflexive ,, trans (*Passoc {as} {bs} {cs}) (p*Commutative {_} {cs})) (sym (bumpTimes {cs} {as *P bs})))) (sym (*Pdistrib {cs} {(map (_*_ a) bs) +P (map (_*_ b) as)} {0G :: (as *P bs)}))) (p*Commutative {cs} {(map (_*_ a) bs +P map (_*_ b) as) +P (0G :: (as *P bs))})))))
ans :
polysEqual
((map (_*_ (a * c)) bs) +P (((a * 0G) :: map (_*_ a) (bs *P cs)) +P (map (_*_ (b * c)) as +P (0G :: ((map (_*_ b) (as *P cs) +P map (_*_ c) (as *P bs)) +P (as *P (0G :: (bs *P cs))))))))
((map (_*_ c) ((map (_*_ a) bs) +P (map (_*_ b) as))) +P (((c * 0G) :: map (_*_ c) (as *P bs)) +P (0G :: (((map (_*_ a) bs +P map (_*_ b) as) +P (0G :: (as *P bs))) *P cs))))
ans = trans (trans (+PwellDefined {map (_*_ (a * c)) bs} {_} {map (_*_ c) (map (_*_ a) bs)} (trans (mapWd (_*_ (a * c)) (λ x → c * (a * x)) bs (λ x → transitive (*WellDefined *Commutative reflexive) (symmetric *Associative))) (sym (mapMap'' (_*_ c) (_*_ a) bs))) (trans (+PCommutative {(a * 0G) :: map (_*_ a) (bs *P cs)} {map (_*_ (b * c)) as +P (0G :: ((map (_*_ b) (as *P cs) +P map (_*_ c) (as *P bs)) +P (as *P (0G :: bs *P cs))))}) (trans (sym (+Assoc {map (_*_ (b * c)) as})) (+PwellDefined {map (_*_ (b * c)) as} {_} {map (_*_ c) (map (_*_ b) as)} (trans (mapWd (_*_ (b * c)) (λ x → c * (b * x)) as λ x → transitive (*WellDefined *Commutative reflexive) (symmetric *Associative)) (sym (mapMap'' (_*_ c) (_*_ b) as))) (transitive identLeft (transitive (transitive timesZero (symmetric timesZero)) (symmetric identRight)) ,, trans (+PCommutative {(map (_*_ b) (as *P cs) +P map (_*_ c) (as *P bs)) +P (as *P (0G :: (bs *P cs)))} {map (_*_ a) (bs *P cs)}) (trans (+Assoc {map (_*_ a) (bs *P cs)} {(map (_*_ b) (as *P cs)) +P (map (_*_ c) (as *P bs))} {as *P (0G :: (bs *P cs))}) ans2)))))) (+Assoc {map (_*_ c) (map (_*_ a) bs)})) (+PwellDefined {(map (_*_ c) (map (_*_ a) bs)) +P (map (_*_ c) (map (_*_ b) as))} {(((c * 0G) :: map (_*_ c) (as *P bs)) +P (0G :: (((map (_*_ a) bs +P map (_*_ b) as) +P (0G :: (as *P bs))) *P cs)))} {map (_*_ c) ((map (_*_ a) bs) +P (map (_*_ b) as))} {(((c * 0G) :: map (_*_ c) (as *P bs)) +P (0G :: (((map (_*_ a) bs +P map (_*_ b) as) +P (0G :: (as *P bs))) *P cs)))} (sym (mapDist (_*_ c) (*DistributesOver+) (map (_*_ a) bs) (map (_*_ b) as))) (ref {(((c * 0G) :: map (_*_ c) (as *P bs)) +P (0G :: (((map (_*_ a) bs +P map (_*_ b) as) +P (0G :: (as *P bs))) *P cs)))}))
|
{
"alphanum_fraction": 0.5544491003,
"avg_line_length": 134.3377483444,
"ext": "agda",
"hexsha": "4890c735f9d9ab696f282952eeb34d20a05d4a4b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Rings/Polynomial/Multiplication.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/Polynomial/Multiplication.agda",
"max_line_length": 2797,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Rings/Polynomial/Multiplication.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 7997,
"size": 20285
}
|
module Relation.Binary.Lattice.Residuated where
open import Level
open import Algebra.FunctionProperties using (Op₂)
open import Algebra.Structures using (IsMonoid)
open import Algebra using (Monoid)
open import Relation.Binary
open import Relation.Binary.Core
open import Relation.Binary.Lattice using (Lattice; IsLattice)
open import Data.Product
LeftResidual : ∀ {c ℓ₂} {L : Set c}
→ (_≤_ : Rel L ℓ₂) -- The partial order.
→ (_∙_ : Op₂ L) -- The monoid operation.
→ (_◁_ : Op₂ L) -- The left residual.
→ Set (c ⊔ ℓ₂)
LeftResidual _≤_ _∙_ _◁_ = ∀ y z → (((z ◁ y) ∙ y) ≤ z) × (Maximum _≤_ (z ◁ y))
RightResidual : ∀ {c ℓ₂} {L : Set c}
→ (_≤_ : Rel L ℓ₂) -- The partial order.
→ (_∙_ : Op₂ L) -- The monoid operation.
→ (_▷_ : Op₂ L) -- The right residual.
→ Set (c ⊔ ℓ₂)
RightResidual _≤_ _∙_ _▷_ = ∀ x z → ((x ∙ (x ▷ z)) ≤ z) × (Maximum _≤_ (x ▷ z))
record IsResiduated {c ℓ₁ ℓ₂} {L : Set c}
(_≈_ : Rel L ℓ₁) -- The underlying equality.
(_≤_ : Rel L ℓ₂) -- The partial order.
(_∨_ : Op₂ L) -- The join operation.
(_∧_ : Op₂ L) -- The meet operation.
(_∙_ : Op₂ L) -- The monoid operation.
(ε : L) -- The identity element.
(_▷_ : Op₂ L) -- The right residual.
(_◁_ : Op₂ L) -- The left residual.
: Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
field
isLattice : IsLattice _≈_ _≤_ _∨_ _∧_
isMonoid : IsMonoid _≈_ _∙_ ε
isLeftResidual : LeftResidual _≤_ _∙_ _◁_
isRightResidual : RightResidual _≤_ _∙_ _▷_
∙-monotonic : _∙_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
-- ∀ x y x
-- y ≤ x ▷ z
-- ⇔ x ∙ y ≤ z
-- ⇔ x ≤ z ◁ y
module Pre = IsPreorder (IsPartialOrder.isPreorder (IsLattice.isPartialOrder isLattice))
-- theorems about the residuals, requires _∙_ to be monotonic
∙-at-left : ∀ x y z
→ y ≤ (x ▷ z)
→ (x ∙ y) ≤ z
∙-at-left x y z P = Pre.trans (∙-monotonic Pre.refl P) (proj₁ (isRightResidual x z))
∙-at-right : ∀ x y z
→ x ≤ (z ◁ y)
→ (x ∙ y) ≤ z
∙-at-right x y z P = Pre.trans (∙-monotonic P Pre.refl) (proj₁ (isLeftResidual y z))
apply-▷ : ∀ x y z
→ (x ∙ y) ≤ z
→ y ≤ (x ▷ z)
apply-▷ x y z P = proj₂ (isRightResidual x z) y
apply-◁ : ∀ x y z
→ (x ∙ y) ≤ z
→ x ≤ (z ◁ y)
apply-◁ x y z P = proj₂ (isLeftResidual y z) x
-- other modules
monoid : Monoid c ℓ₁
monoid = record { isMonoid = isMonoid }
lattice : Lattice c ℓ₁ ℓ₂
lattice = record { isLattice = isLattice }
record Residuated c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infix 4 _≈_ _≤_
infixr 6 _∨_
infixr 7 _∧_
infixr 5 _∙_
infixr 8 _▷_ _◁_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁ -- The underlying equality.
_≤_ : Rel Carrier ℓ₂ -- The partial order.
_∨_ : Op₂ Carrier -- The join operation.
_∧_ : Op₂ Carrier -- The meet operation.
_∙_ : Op₂ Carrier -- The monoid operation.
ε : Carrier -- The identity element.
_▷_ : Op₂ Carrier -- The right residual.
_◁_ : Op₂ Carrier -- The left residual.
isResiduated : IsResiduated _≈_ _≤_ _∨_ _∧_ _∙_ ε _▷_ _◁_
|
{
"alphanum_fraction": 0.4984537532,
"avg_line_length": 34.2019230769,
"ext": "agda",
"hexsha": "e937c2aa64ecece20e0ca45ec450bec989074ac7",
"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": "cf4b37b85b13aced9a36f3216d676ee5599059f6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/relalg",
"max_forks_repo_path": "src/Relation/Binary/Lattice/Residuated.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cf4b37b85b13aced9a36f3216d676ee5599059f6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/relalg",
"max_issues_repo_path": "src/Relation/Binary/Lattice/Residuated.agda",
"max_line_length": 92,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cf4b37b85b13aced9a36f3216d676ee5599059f6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/relalg",
"max_stars_repo_path": "src/Relation/Binary/Lattice/Residuated.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1267,
"size": 3557
}
|
{-
An induction principle for paths in a pushout, described in
Kraus and von Raumer, "Path Spaces of Higher Inductive Types in Homotopy Type Theory"
https://arxiv.org/abs/1901.06022
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Pushout.KrausVonRaumer where
open import Cubical.Foundations.Everything
open import Cubical.Data.Sigma
open import Cubical.HITs.Pushout.Base
private
interpolate : ∀ {ℓ} {A : Type ℓ} {x y z : A} (q : y ≡ z)
→ PathP (λ i → x ≡ q i → x ≡ z) (_∙ q) (idfun _)
interpolate q i p j =
hcomp
(λ k → λ
{ (j = i0) → p i0
; (j = i1) → q (i ∨ k)
; (i = i1) → p j
})
(p j)
interpolateCompPath : ∀ {ℓ} {A : Type ℓ} {x y : A} (p : x ≡ y) {z : A} (q : y ≡ z)
→ (λ i → interpolate q i (λ j → compPath-filler p q i j)) ≡ refl
interpolateCompPath p =
J (λ z q → (λ i → interpolate q i (λ j → compPath-filler p q i j)) ≡ refl)
(homotopySymInv (λ p i j → compPath-filler p refl (~ i) j) p)
module ElimL {ℓ ℓ' ℓ'' ℓ'''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''}
{f : A → B} {g : A → C} {b₀ : B}
(P : ∀ b → Path (Pushout f g) (inl b₀) (inl b) → Type ℓ''')
(Q : ∀ c → Path (Pushout f g) (inl b₀) (inr c) → Type ℓ''')
(r : P b₀ refl)
(e : (a : A) (q : inl b₀ ≡ inl (f a)) → P (f a) q ≃ Q (g a) (q ∙ push a))
where
Codes : (d : Pushout f g) (q : inl b₀ ≡ d) → Type ℓ'''
Codes (inl b) q = P b q
Codes (inr c) q = Q c q
Codes (push a i) q =
Glue
(Q (g a) (interpolate (push a) i q))
(λ
{ (i = i0) → _ , e a q
; (i = i1) → _ , idEquiv (Q (g a) q)
})
elimL : ∀ b q → P b q
elimL _ = J Codes r
elimR : ∀ c q → Q c q
elimR _ = J Codes r
refl-β : elimL b₀ refl ≡ r
refl-β = transportRefl _
push-β : (a : A) (q : inl b₀ ≡ inl (f a))
→ elimR (g a) (q ∙ push a) ≡ e a q .fst (elimL (f a) q)
push-β a q =
J-∙ Codes r q (push a)
∙ fromPathP
(subst
(λ α → PathP (λ i → Q (g a) (α i)) (e a q .fst (elimL (f a) q)) (e a q .fst (elimL (f a) q)))
(interpolateCompPath q (push a) ⁻¹)
refl)
module ElimR {ℓ ℓ' ℓ'' ℓ'''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''}
{f : A → B} {g : A → C} {c₀ : C}
(P : ∀ b → Path (Pushout f g) (inr c₀) (inl b) → Type ℓ''')
(Q : ∀ c → Path (Pushout f g) (inr c₀) (inr c) → Type ℓ''')
(r : Q c₀ refl)
(e : (a : A) (q : inr c₀ ≡ inl (f a)) → P (f a) q ≃ Q (g a) (q ∙ push a))
where
Codes : (d : Pushout f g) (q : inr c₀ ≡ d) → Type ℓ'''
Codes (inl b) q = P b q
Codes (inr c) q = Q c q
Codes (push a i) q =
Glue
(Q (g a) (interpolate (push a) i q))
(λ
{ (i = i0) → _ , e a q
; (i = i1) → _ , idEquiv (Q (g a) q)
})
elimL : ∀ b q → P b q
elimL _ = J Codes r
elimR : ∀ c q → Q c q
elimR _ = J Codes r
refl-β : elimR c₀ refl ≡ r
refl-β = transportRefl _
push-β : (a : A) (q : inr c₀ ≡ inl (f a))
→ elimR (g a) (q ∙ push a) ≡ e a q .fst (elimL (f a) q)
push-β a q =
J-∙ Codes r q (push a)
∙ fromPathP
(subst
(λ α → PathP (λ i → Q (g a) (α i)) (e a q .fst (elimL (f a) q)) (e a q .fst (elimL (f a) q)))
(interpolateCompPath q (push a) ⁻¹)
refl)
-- Example application: pushouts preserve embeddings
isEmbeddingInr : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''}
{f : A → B} (g : A → C)
→ isEmbedding f → isEmbedding (inr {f = f} {g = g})
isEmbeddingInr {f = f} g fEmb c₀ c₁ =
isoToIsEquiv (iso _ (fst ∘ bwd c₁) (snd ∘ bwd c₁) bwdCong)
where
Q : ∀ c → inr c₀ ≡ inr c → Type _
Q _ q = fiber (cong inr) q
P : ∀ b → inr c₀ ≡ inl b → Type _
P b p = Σ[ u ∈ fiber f b ] Q _ (p ∙ cong inl (u .snd ⁻¹) ∙ push (u .fst))
module Bwd = ElimR P Q
(refl , refl)
(λ a p →
subst
(P (f a) p ≃_)
(cong (λ w → fiber (cong inr) (p ∙ w)) (lUnit (push a) ⁻¹))
(Σ-contractFst (inhProp→isContr (a , refl) (isEmbedding→hasPropFibers fEmb (f a)))))
bwd : ∀ c → (t : inr c₀ ≡ inr c) → fiber (cong inr) t
bwd = Bwd.elimR
bwdCong : ∀ {c} → (r : c₀ ≡ c) → bwd c (cong inr r) .fst ≡ r
bwdCong = J (λ c r → bwd c (cong inr r) .fst ≡ r) (cong fst Bwd.refl-β)
|
{
"alphanum_fraction": 0.4949275362,
"avg_line_length": 30.2189781022,
"ext": "agda",
"hexsha": "9dd6434ade34dd2a51668d7caa492703377decff",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "borsiemir/cubical",
"max_forks_repo_path": "Cubical/HITs/Pushout/KrausVonRaumer.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "borsiemir/cubical",
"max_issues_repo_path": "Cubical/HITs/Pushout/KrausVonRaumer.agda",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "borsiemir/cubical",
"max_stars_repo_path": "Cubical/HITs/Pushout/KrausVonRaumer.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1864,
"size": 4140
}
|
record R₁ : Set₂ where
field
_≡_ : {A : Set₁} → A → A → Set
postulate
A B : Set
record R₂ (r₁ : R₁) : Set₂ where
open R₁ r₁
field
cong : (A : Set₁) (x y : A) (F : A → Set) → x ≡ y → F x ≡ F y
subst : (P : Set → Set₁) → A ≡ B → P A → P B
postulate
_≡_ : {A : Set₁} → A → A → Set
r₁ : R₁
r₁ .R₁._≡_ = _≡_
postulate
r₂ : ∀ r₁ → R₂ r₁
open R₂ (r₂ r₁)
record R₃ (@0 A : Set₁) : Set₁ where
constructor [_]
field
f : A
postulate
r₃ : R₃ Set
push-subst-[] :
(P : Set → Set₁) (p : P A) (eq : A ≡ B) →
subst (λ A → R₃ (P A)) eq [ p ] ≡ [ subst P eq p ]
_ :
(eq : A ≡ B) →
(subst (λ _ → R₃ Set) eq r₃ ≡ r₃) ≡
([ subst (λ _ → Set) eq (r₃ .R₃.f) ] ≡ r₃)
_ = λ eq → cong _ _ _ (_≡ _) (push-subst-[] _ _ _)
|
{
"alphanum_fraction": 0.4665792923,
"avg_line_length": 18.6097560976,
"ext": "agda",
"hexsha": "5985960f8bac16cbda93156720667d5ebe80b6b9",
"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/Issue5007.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/Issue5007.agda",
"max_line_length": 66,
"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/Issue5007.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": 377,
"size": 763
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Paths
module lib.types.Unit where
pattern tt = unit
⊙Unit : Ptd₀
⊙Unit = ⊙[ Unit , unit ]
abstract
-- Unit is contractible
Unit-is-contr : is-contr Unit
Unit-is-contr = (unit , λ y → idp)
Unit-is-prop : is-prop Unit
Unit-is-prop = raise-level -2 Unit-is-contr
Unit-is-set : is-set Unit
Unit-is-set = raise-level -1 Unit-is-prop
Unit-level = Unit-is-contr
⊤-is-contr = Unit-is-contr
⊤-level = Unit-is-contr
⊤-is-prop = Unit-is-prop
⊤-is-set = Unit-is-set
|
{
"alphanum_fraction": 0.6549912434,
"avg_line_length": 19.6896551724,
"ext": "agda",
"hexsha": "e21a8d038fe1cd6027c8b900ceabe93f2bab22cf",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"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": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Unit.agda",
"max_line_length": 45,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/Unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 188,
"size": 571
}
|
open import Syntax
module Categories.Category.Construction.Renaming {ℓ₁ ℓ₂} (Sg : Signature ℓ₁ ℓ₂) where
open import Relation.Binary using (Rel)
open import Data.List using (List; []; [_]; _∷_; length; _++_)
open import Level using (zero; _⊔_)
open import Categories.Category
open Signature Sg
data ren : Rel Context ℓ₁ where
id : forall {Γ} -> ren Γ Γ
_∙_ : forall {Γ₁ Γ₂ Γ₃} -> ren Γ₂ Γ₃ -> ren Γ₁ Γ₂ -> ren Γ₁ Γ₃
! : forall {Γ} -> ren Γ []
⟪_,_⟫ : forall {Γ Γ₁ Γ₂} -> ren Γ Γ₁ -> ren Γ Γ₂ -> ren Γ (Γ₂ ++ Γ₁)
p : forall {Γ Γ′} -> ren (Γ′ ++ Γ) Γ
q : forall {Γ Γ′} -> ren (Γ′ ++ Γ) Γ′
data _≐_ : forall {Γ Γ′} -> Rel (ren Γ Γ′) ℓ₁ where
refl : forall {Γ Γ′} {f : ren Γ Γ′} -> f ≐ f
sym : forall {Γ Γ′} {f g : ren Γ Γ′} -> f ≐ g -> g ≐ f
trans : forall {Γ Γ′} {f g h : ren Γ Γ′} -> f ≐ g -> g ≐ h -> f ≐ h
identityˡ : forall {Γ Γ′} {f : ren Γ Γ′} -> (id ∙ f) ≐ f
identityʳ : forall {Γ Γ′} {f : ren Γ Γ′} -> (f ∙ id) ≐ f
assoc : forall {Γ Γ′ Γ″ Γ‴} {h : ren Γ Γ′} {g : ren Γ′ Γ″} {f : ren Γ″ Γ‴}
-> ((f ∙ g) ∙ h) ≐ (f ∙ (g ∙ h))
!-unique : forall {Γ} {f : ren Γ []} -> ! ≐ f
β₁/⟪⟫ : forall {Γ Γ₁ Γ₂} {f : ren Γ Γ₁} {g : ren Γ Γ₂} -> (p ∙ ⟪ f , g ⟫) ≐ f
β₂/⟪⟫ : forall {Γ Γ₁ Γ₂} {f : ren Γ Γ₁} {g : ren Γ Γ₂} -> (q ∙ ⟪ f , g ⟫) ≐ g
η/⟪⟫ : forall {Γ Γ₁ Γ₂} {f : ren Γ (Γ₂ ++ Γ₁)} -> ⟪ p {Γ = Γ₁} ∙ f , q {Γ′ = Γ₂} ∙ f ⟫ ≐ f
cong/∙ : forall {Γ₁ Γ₂ Γ₃} {g i : ren Γ₁ Γ₂} {f h : ren Γ₂ Γ₃} -> f ≐ h -> g ≐ i -> (f ∙ g) ≐ (h ∙ i)
cong/⟪⟫ : forall {Γ Γ₁ Γ₂} {f h : ren Γ Γ₁} {g i : ren Γ Γ₂} -> f ≐ h -> g ≐ i -> ⟪ f , g ⟫ ≐ ⟪ h , i ⟫
Ren : Category ℓ₁ ℓ₁ ℓ₁
Ren = record
{ Obj = Context
; _⇒_ = ren
; _≈_ = _≐_
; id = id
; _∘_ = _∙_
; assoc = assoc
; sym-assoc = sym assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identityˡ
; equiv = record { refl = refl ; sym = sym ; trans = trans }
; ∘-resp-≈ = cong/∙
}
open import Categories.Category.Cartesian Ren
open import Categories.Category.BinaryProducts Ren
open import Categories.Object.Product Ren
open import Categories.Object.Terminal Ren
private
P : forall {Γ₁ Γ₂} -> Product Γ₁ Γ₂
P {Γ₁} {Γ₂} = record
{ A×B = Γ₂ ++ Γ₁
; π₁ = p
; π₂ = q
; ⟨_,_⟩ = ⟪_,_⟫
; project₁ = β₁/⟪⟫
; project₂ = β₂/⟪⟫
; unique = λ x x₁ →
begin
⟪ _ , _ ⟫
≈˘⟨ cong/⟪⟫ x x₁ ⟩
⟪ _ , _ ⟫
≈⟨ η/⟪⟫ ⟩
_
∎
}
where open Category.HomReasoning Ren
C : Cartesian
C = record { terminal = T ; products = record { product = P } }
where
T : Terminal
T = record { ⊤ = [] ; ⊤-is-terminal = record { ! = ! ; !-unique = λ f → !-unique {f = f} } }
|
{
"alphanum_fraction": 0.4717182497,
"avg_line_length": 32.6860465116,
"ext": "agda",
"hexsha": "d4720918301e228b54acce7fd50048dc5b59c566",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "elpinal/exsub-ccc",
"max_forks_repo_path": "Categories/Category/Construction/Renaming.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "elpinal/exsub-ccc",
"max_issues_repo_path": "Categories/Category/Construction/Renaming.agda",
"max_line_length": 105,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "elpinal/exsub-ccc",
"max_stars_repo_path": "Categories/Category/Construction/Renaming.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T13:30:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-05T06:16:32.000Z",
"num_tokens": 1221,
"size": 2811
}
|
{-# OPTIONS --without-K #-}
module NTypes.Unit where
open import Equivalence
open import NTypes
open import PathStructure.Unit
open import Types
1-isProp : isProp ⊤
1-isProp _ _ = merge-path _
1-isSet : isSet ⊤
1-isSet _ _ =
prop-eq (sym-equiv split-merge-eq) 1-isProp
|
{
"alphanum_fraction": 0.7262773723,
"avg_line_length": 18.2666666667,
"ext": "agda",
"hexsha": "cb70fc79c4e51cdc793b0f06c661782dafbfdc4d",
"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": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/NTypes/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"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": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/NTypes/Unit.agda",
"max_line_length": 45,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/NTypes/Unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 83,
"size": 274
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.