Search is not available for this dataset
text
string | meta
dict |
---|---|
open import Agda.Primitive using (_⊔_; lsuc; lzero)
import Categories.Category as Category
import Categories.Category.Cartesian as Cartesian
import MultiSorted.Model as Model
import MultiSorted.Interpretation as Interpretation
import MultiSorted.UniversalModel as UniversalModel
import MultiSorted.SyntacticCategory as SyntacticCategory
import MultiSorted.UniversalModel as UniversalModel
open import MultiSorted.AlgebraicTheory
module MultiSorted.Completeness
{ℓt}
{𝓈 ℴ}
{Σ : Signature {𝓈} {ℴ}}
(T : Theory ℓt Σ) where
open Theory T
open UniversalModel T
-- An equation is semantically valid when it holds in all models
valid : ∀ (ε : Equation Σ) → Set (lsuc (lsuc ℓt ⊔ lsuc 𝓈 ⊔ lsuc ℴ))
valid ε = ∀ {𝒞 : Category.Category 𝓈 (lsuc ℴ) (lsuc (ℓt ⊔ 𝓈 ⊔ ℴ))}
{cartesian-𝒞 : Cartesian.Cartesian 𝒞}
{I : Interpretation.Interpretation Σ cartesian-𝒞}
(M : Model.Model T I) → Interpretation.Interpretation.⊨_ I ε
-- Completeness: semantic validity implies provability
valid-⊢ : ∀ (ε : Equation Σ) → valid ε → ⊢ ε
valid-⊢ ε v = universality ε (v 𝒰)
|
{
"alphanum_fraction": 0.6967572305,
"avg_line_length": 34.5757575758,
"ext": "agda",
"hexsha": "bb4d18e8541bb90996345fe677ad849050afa4eb",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z",
"max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/formaltt",
"max_forks_repo_path": "src/MultiSorted/Completeness.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejbauer/formaltt",
"max_issues_repo_path": "src/MultiSorted/Completeness.agda",
"max_line_length": 74,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cilinder/formaltt",
"max_stars_repo_path": "src/MultiSorted/Completeness.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z",
"num_tokens": 349,
"size": 1141
}
|
------------------------------------------------------------------------------
-- Totality properties respect to Bool
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.SortList.Properties.Totality.BoolATP where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Bool.PropertiesATP
open import FOTC.Data.Bool.Type
open import FOTC.Data.Nat.List.Type
open import FOTC.Data.Nat.Type
open import FOTC.Program.SortList.SortList
------------------------------------------------------------------------------
le-ItemList-Bool : ∀ {item is} → N item → ListN is → Bool (le-ItemList item is)
le-ItemList-Bool {item} Nitem lnnil = prf
where postulate prf : Bool (le-ItemList item [])
{-# ATP prove prf #-}
le-ItemList-Bool {item} Nitem (lncons {i} {is} Ni Lis) =
prf (le-ItemList-Bool Nitem Lis)
where postulate prf : Bool (le-ItemList item is) →
Bool (le-ItemList item (i ∷ is))
{-# ATP prove prf &&-Bool le-Bool #-}
le-Lists-Bool : ∀ {is js} → ListN is → ListN js → Bool (le-Lists is js)
le-Lists-Bool {js = js} lnnil LNjs = prf
where postulate prf : Bool (le-Lists [] js)
{-# ATP prove prf #-}
le-Lists-Bool {js = js} (lncons {i} {is} Ni LNis) LNjs =
prf (le-Lists-Bool LNis LNjs)
where postulate prf : Bool (le-Lists is js) → Bool (le-Lists (i ∷ is) js)
{-# ATP prove prf &&-Bool le-ItemList-Bool #-}
ordList-Bool : ∀ {is} → ListN is → Bool (ordList is)
ordList-Bool lnnil = prf
where postulate prf : Bool (ordList [])
{-# ATP prove prf #-}
ordList-Bool (lncons {i} {is} Ni LNis) = prf (ordList-Bool LNis)
where postulate prf : Bool (ordList is) → Bool (ordList (i ∷ is))
{-# ATP prove prf &&-Bool le-ItemList-Bool #-}
le-ItemTree-Bool : ∀ {item t} → N item → Tree t → Bool (le-ItemTree item t)
le-ItemTree-Bool {item} Nt tnil = prf
where postulate prf : Bool (le-ItemTree item nil)
{-# ATP prove prf #-}
le-ItemTree-Bool {item} Nitem (ttip {i} Ni) = prf
where postulate prf : Bool (le-ItemTree item (tip i))
{-# ATP prove prf le-Bool #-}
le-ItemTree-Bool {item} Nitem (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) =
prf (le-ItemTree-Bool Nitem Tt₁) (le-ItemTree-Bool Nitem Tt₂)
where postulate prf : Bool (le-ItemTree item t₁) →
Bool (le-ItemTree item t₂) →
Bool (le-ItemTree item (node t₁ i t₂))
{-# ATP prove prf &&-Bool #-}
le-TreeItem-Bool : ∀ {t item} → Tree t → N item → Bool (le-TreeItem t item)
le-TreeItem-Bool {item = item } tnil Nt = prf
where postulate prf : Bool (le-TreeItem nil item)
{-# ATP prove prf #-}
le-TreeItem-Bool {item = item} (ttip {i} Ni) Nitem = prf
where postulate prf : Bool (le-TreeItem (tip i) item)
{-# ATP prove prf le-Bool #-}
le-TreeItem-Bool {item = item} (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) Nitem =
prf (le-TreeItem-Bool Tt₁ Nitem) (le-TreeItem-Bool Tt₂ Nitem)
where postulate prf : Bool (le-TreeItem t₁ item) →
Bool (le-TreeItem t₂ item) →
Bool (le-TreeItem (node t₁ i t₂) item)
{-# ATP prove prf &&-Bool #-}
ordTree-Bool : ∀ {t} → Tree t → Bool (ordTree t)
ordTree-Bool tnil = prf
where postulate prf : Bool (ordTree nil)
{-# ATP prove prf #-}
ordTree-Bool (ttip {i} Ni) = prf
where postulate prf : Bool (ordTree (tip i))
{-# ATP prove prf #-}
ordTree-Bool (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) =
prf (ordTree-Bool Tt₁) (ordTree-Bool Tt₂)
where postulate prf : Bool (ordTree t₁) →
Bool (ordTree t₂) →
Bool (ordTree (node t₁ i t₂))
{-# ATP prove prf &&-Bool le-TreeItem-Bool le-ItemTree-Bool #-}
|
{
"alphanum_fraction": 0.5683453237,
"avg_line_length": 41.4042553191,
"ext": "agda",
"hexsha": "876398af3ba56f75d2029e82de63fc0fcce0fe39",
"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/SortList/Properties/Totality/BoolATP.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/SortList/Properties/Totality/BoolATP.agda",
"max_line_length": 79,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/SortList/Properties/Totality/BoolATP.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": 1242,
"size": 3892
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Universes
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Universe where
open import Data.Product
open import Function
open import Level
-- Universes.
record Universe u e : Set (suc (u ⊔ e)) where
field
-- Codes.
U : Set u
-- Decoding function.
El : U → Set e
-- Indexed universes.
record Indexed-universe i u e : Set (suc (i ⊔ u ⊔ e)) where
field
-- Index set.
I : Set i
-- Codes.
U : I → Set u
-- Decoding function.
El : ∀ {i} → U i → Set e
-- An indexed universe can be turned into an unindexed one.
unindexed-universe : Universe (i ⊔ u) e
unindexed-universe = record
{ U = ∃ λ i → U i
; El = El ∘ proj₂
}
|
{
"alphanum_fraction": 0.4866123399,
"avg_line_length": 19.0888888889,
"ext": "agda",
"hexsha": "641407090d5c1fabfc787b3a3e6296bdcd141255",
"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/Universe.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/Universe.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/Universe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 225,
"size": 859
}
|
{-# OPTIONS --cubical --safe #-}
module Relation.Nullary.Stable.Base where
open import Data.Empty
open import Level
Stable : Type a → Type a
Stable A = ¬ ¬ A → A
|
{
"alphanum_fraction": 0.6848484848,
"avg_line_length": 16.5,
"ext": "agda",
"hexsha": "5d70eefd1c63a589bcfd21a1729e8c178b11caf4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Relation/Nullary/Stable/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Relation/Nullary/Stable/Base.agda",
"max_line_length": 41,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Relation/Nullary/Stable/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z",
"num_tokens": 46,
"size": 165
}
|
module Common.Reflection where
open import Agda.Builtin.Reflection public renaming
( arg-info to argInfo
; function to funDef
; data-type to dataDef
; record-type to recordDef
; agda-sort to sort
; name to qname
; absurd-clause to absurdClause
; pat-lam to extLam
; proj to projP
; instance′ to inst
; Visibility to Hiding
; Name to QName)
open import Common.Level
open import Common.Prelude hiding (_>>=_)
pattern vArg x = arg (argInfo visible relevant) x
pattern hArg x = arg (argInfo hidden relevant) x
pattern iArg x = arg (argInfo inst relevant) x
Args = List (Arg Term)
data FunDef : Set where
funDef : Type → List Clause → FunDef
Tactic = Term → TC ⊤
give : Term → Tactic
give v = λ hole → unify hole v
define : Arg QName → FunDef → TC ⊤
define (arg i f) (funDef a cs) =
bindTC (declareDef (arg i f) a) λ _ →
defineFun f cs
newMeta : Type → TC Term
newMeta a = checkType unknown a
numberOfParameters : QName → TC Nat
numberOfParameters d =
bindTC (getDefinition d) λ
{ (dataDef n _) → returnTC n
; _ → typeError (strErr "Cannot get parameters of non-data type" ∷ nameErr d ∷ [])
}
getConstructors : QName → TC (List QName)
getConstructors d =
bindTC (getDefinition d) λ
{ (dataDef _ cs) → returnTC cs
; (recordDef c _) → returnTC (c ∷ [])
; _ → typeError (strErr "Cannot get constructors of non-data or record type" ∷ nameErr d ∷ [])
}
infixl 1 _>>=_
_>>=_ = bindTC
|
{
"alphanum_fraction": 0.6544362909,
"avg_line_length": 25.406779661,
"ext": "agda",
"hexsha": "9777f54a9159d2a3800aa72b4586000297e6fbab",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Common/Reflection.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Common/Reflection.agda",
"max_line_length": 96,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Common/Reflection.agda",
"max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z",
"num_tokens": 458,
"size": 1499
}
|
module gugugu where
open import Relation.Binary.PropositionalEquality
open import Data.List
open import Data.List.Properties
open import Agda.Builtin.Sigma
-- you can import other functions from the stdlib here
++-injectiveʳ : ∀ {ℓ} {A : Set ℓ} (a b c : List A) → a ++ b ≡ a ++ c → b ≡ c
++-injectiveʳ [] b c p = p
++-injectiveʳ (x ∷ a) b c p = ++-injectiveʳ a b c (snd (∷-injective p))
lemma : ∀ {ℓ} {A : Set ℓ} (x : A) (xs ys : List A) → xs ++ x ∷ ys ≡ (xs ++ x ∷ []) ++ ys
lemma x [] ys = refl
lemma x (x₁ ∷ xs) ys = cong (_∷_ x₁) (lemma x xs ys)
col : ∀ {ℓ} {A : Set ℓ} (x : A) (xs : List A) → xs ++ x ∷ [] ≡ (xs ∷ʳ x)
col x [] = refl
col x (x₁ ∷ xs) = refl
silly' : ∀ {ℓ} {A : Set ℓ} (x : A) (xs ys : List A) → xs ++ x ∷ [] ≡ ys ++ x ∷ [] → xs ∷ʳ x ≡ ys ∷ʳ x
silly' x xs ys = λ z → z
silly : ∀ {ℓ} {A : Set ℓ} (x : A) (xs ys : List A) → xs ++ x ∷ [] ≡ ys ++ x ∷ [] → xs ≡ ys
silly x xs ys p rewrite col x xs | col x ys = fst (∷ʳ-injective xs ys (silly' x xs ys p))
-- inductive can do this job too.
++-injectiveˡ : ∀ {ℓ} {A : Set ℓ} (a b c : List A) → a ++ c ≡ b ++ c → a ≡ b
++-injectiveˡ a b [] p rewrite ++-identityʳ a | ++-identityʳ b = p
++-injectiveˡ a b (x ∷ c) p rewrite lemma x a c | lemma x b c = silly x a b (++-injectiveˡ (a ++ x ∷ []) (b ++ x ∷ []) c p)
|
{
"alphanum_fraction": 0.5293197811,
"avg_line_length": 41.2580645161,
"ext": "agda",
"hexsha": "e3469d969cb983ea7510ed6f9d87fe870baad449",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-13T04:50:46.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-13T04:50:46.000Z",
"max_forks_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Brethland/LEARNING-STUFF",
"max_forks_repo_path": "Agda/gugugu.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"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": "Brethland/LEARNING-STUFF",
"max_issues_repo_path": "Agda/gugugu.agda",
"max_line_length": 123,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Brethland/LEARNING-STUFF",
"max_stars_repo_path": "Agda/gugugu.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-11T10:35:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-03T05:05:52.000Z",
"num_tokens": 556,
"size": 1279
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Bool
open import lib.types.Empty
open import lib.types.Paths
open import lib.types.Pi
open import lib.types.Sigma
{-
This file contains various lemmas that rely on lib.types.Paths or
functional extensionality for pointed maps.
-}
module lib.types.Pointed where
{- Pointed maps -}
⊙app= : ∀ {i j} {X : Ptd i} {Y : Ptd j} {f g : X ⊙→ Y}
→ f == g → f ⊙∼ g
⊙app= {X = X} {Y = Y} p =
app= (fst= p) , ↓-ap-in (_== pt Y) (λ u → u (pt X)) (snd= p)
-- function extensionality for pointed maps
⊙λ= : ∀ {i j} {X : Ptd i} {Y : Ptd j} {f g : X ⊙→ Y}
→ f ⊙∼ g → f == g
⊙λ= {g = g} (p , α) = pair= (λ= p)
(↓-app=cst-in (↓-idf=cst-out α ∙ ap (_∙ snd g) (! (app=-β p _))))
⊙λ=' : ∀ {i j} {X : Ptd i} {Y : Ptd j} {f g : X ⊙→ Y}
(p : fst f ∼ fst g)
(α : snd f == snd g [ (λ y → y == pt Y) ↓ p (pt X) ])
→ f == g
⊙λ=' {g = g} = curry ⊙λ=
-- associativity of pointed maps
⊙∘-assoc-pt : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}
{a₁ a₂ : A} (f : A → B) {b : B} (g : B → C) {c : C}
(p : a₁ == a₂) (q : f a₂ == b) (r : g b == c)
→ ⊙∘-pt (g ∘ f) p (⊙∘-pt g q r) == ⊙∘-pt g (⊙∘-pt f p q) r
⊙∘-assoc-pt _ _ idp _ _ = idp
⊙∘-assoc : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}
(h : Z ⊙→ W) (g : Y ⊙→ Z) (f : X ⊙→ Y)
→ ((h ⊙∘ g) ⊙∘ f) ⊙∼ (h ⊙∘ (g ⊙∘ f))
⊙∘-assoc (h , hpt) (g , gpt) (f , fpt) = (λ _ → idp) , ⊙∘-assoc-pt g h fpt gpt hpt
⊙∘-cst-l : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
→ (f : X ⊙→ Y) → (⊙cst :> (Y ⊙→ Z)) ⊙∘ f ⊙∼ ⊙cst
⊙∘-cst-l {Z = Z} f = (λ _ → idp) , ap (_∙ idp) (ap-cst (pt Z) (snd f))
⊙∘-cst-r : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
→ (f : Y ⊙→ Z) → f ⊙∘ (⊙cst :> (X ⊙→ Y)) ⊙∼ ⊙cst
⊙∘-cst-r {X = X} f = (λ _ → snd f) , ↓-idf=cst-in' idp
{- Pointed equivalences -}
-- Extracting data from an pointed equivalence
module _ {i j} {X : Ptd i} {Y : Ptd j} (⊙e : X ⊙≃ Y) where
⊙≃-to-≃ : de⊙ X ≃ de⊙ Y
⊙≃-to-≃ = fst (fst ⊙e) , snd ⊙e
⊙–> : X ⊙→ Y
⊙–> = fst ⊙e
⊙–>-pt = snd ⊙–>
⊙<– : Y ⊙→ X
⊙<– = is-equiv.g (snd ⊙e) , lemma ⊙e where
lemma : {Y : Ptd j} (⊙e : X ⊙≃ Y) → is-equiv.g (snd ⊙e) (pt Y) == pt X
lemma ((f , idp) , f-ise) = is-equiv.g-f f-ise (pt X)
⊙<–-pt = snd ⊙<–
infix 120 _⊙⁻¹
_⊙⁻¹ : Y ⊙≃ X
_⊙⁻¹ = ⊙<– , is-equiv-inverse (snd ⊙e)
module _ {i j} {X : Ptd i} {Y : Ptd j} where
⊙<–-inv-l : (⊙e : X ⊙≃ Y) → ⊙<– ⊙e ⊙∘ ⊙–> ⊙e ⊙∼ ⊙idf _
⊙<–-inv-l ⊙e = <–-inv-l (⊙≃-to-≃ ⊙e) , ↓-idf=cst-in' (lemma ⊙e) where
lemma : {Y : Ptd j} (⊙e : X ⊙≃ Y)
→ snd (⊙<– ⊙e ⊙∘ ⊙–> ⊙e) == is-equiv.g-f (snd ⊙e) (pt X)
lemma ((f , idp) , f-ise) = idp
⊙<–-inv-r : (⊙e : X ⊙≃ Y) → ⊙–> ⊙e ⊙∘ ⊙<– ⊙e ⊙∼ ⊙idf _
⊙<–-inv-r ⊙e = <–-inv-r (⊙≃-to-≃ ⊙e) , ↓-idf=cst-in' (lemma ⊙e) where
lemma : {Y : Ptd j} (⊙e : X ⊙≃ Y)
→ snd (⊙–> ⊙e ⊙∘ ⊙<– ⊙e) == is-equiv.f-g (snd ⊙e) (pt Y)
lemma ((f , idp) , f-ise) = ∙-unit-r _ ∙ is-equiv.adj f-ise (pt X)
module _ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} (⊙e : X ⊙≃ Y) where
post⊙∘-is-equiv : is-equiv (λ (k : Z ⊙→ X) → ⊙–> ⊙e ⊙∘ k)
post⊙∘-is-equiv = is-eq (⊙–> ⊙e ⊙∘_) (⊙<– ⊙e ⊙∘_) (to-from ⊙e) (from-to ⊙e) where
abstract
to-from : ∀ {Y} (⊙e : X ⊙≃ Y) (k : Z ⊙→ Y) → ⊙–> ⊙e ⊙∘ (⊙<– ⊙e ⊙∘ k) == k
to-from ((f , idp) , f-ise) (k , k-pt) = ⊙λ=' (f.f-g ∘ k) (↓-idf=cst-in' $ lemma k-pt)
where
module f = is-equiv f-ise
lemma : ∀ {y₀} (k-pt : y₀ == f (pt X))
→ ⊙∘-pt f (⊙∘-pt f.g k-pt (f.g-f _)) idp == f.f-g y₀ ∙' k-pt
lemma idp = ∙-unit-r _ ∙ f.adj _
from-to : ∀ {Y} (⊙e : X ⊙≃ Y) (k : Z ⊙→ X) → ⊙<– ⊙e ⊙∘ (⊙–> ⊙e ⊙∘ k) == k
from-to ((f , idp) , f-ise) (k , idp) = ⊙λ=' (f.g-f ∘ k) $ ↓-idf=cst-in' idp
where module f = is-equiv f-ise
post⊙∘-equiv : (Z ⊙→ X) ≃ (Z ⊙→ Y)
post⊙∘-equiv = _ , post⊙∘-is-equiv
pre⊙∘-is-equiv : is-equiv (λ (k : Y ⊙→ Z) → k ⊙∘ ⊙–> ⊙e)
pre⊙∘-is-equiv = is-eq (_⊙∘ ⊙–> ⊙e) (_⊙∘ ⊙<– ⊙e) (to-from ⊙e) (from-to ⊙e) where
abstract
to-from : ∀ {Z} (⊙e : X ⊙≃ Y) (k : X ⊙→ Z) → (k ⊙∘ ⊙<– ⊙e) ⊙∘ ⊙–> ⊙e == k
to-from ((f , idp) , f-ise) (k , idp) = ⊙λ=' (ap k ∘ f.g-f) $ ↓-idf=cst-in' $ ∙-unit-r _
where module f = is-equiv f-ise
from-to : ∀ {Z} (⊙e : X ⊙≃ Y) (k : Y ⊙→ Z) → (k ⊙∘ ⊙–> ⊙e) ⊙∘ ⊙<– ⊙e == k
from-to ((f , idp) , f-ise) (k , idp) = ⊙λ=' (ap k ∘ f.f-g) $ ↓-idf=cst-in' $
∙-unit-r _ ∙ ap-∘ k f (f.g-f (pt X)) ∙ ap (ap k) (f.adj (pt X))
where module f = is-equiv f-ise
pre⊙∘-equiv : (Y ⊙→ Z) ≃ (X ⊙→ Z)
pre⊙∘-equiv = _ , pre⊙∘-is-equiv
{- Pointed maps out of bool -}
-- intuition : [f true] is fixed and the only changable part is [f false].
⊙Bool→-to-idf : ∀ {i} {X : Ptd i}
→ ⊙Bool ⊙→ X → de⊙ X
⊙Bool→-to-idf (h , _) = h false
⊙Bool→-equiv-idf : ∀ {i} (X : Ptd i)
→ (⊙Bool ⊙→ X) ≃ de⊙ X
⊙Bool→-equiv-idf {i} X = equiv ⊙Bool→-to-idf g f-g g-f
where
g : de⊙ X → ⊙Bool ⊙→ X
g x = Bool-rec (pt X) x , idp
abstract
f-g : ∀ x → ⊙Bool→-to-idf (g x) == x
f-g x = idp
g-f : ∀ H → g (⊙Bool→-to-idf H) == H
g-f (h , hpt) = pair=
(λ= lemma)
(↓-app=cst-in $
idp
=⟨ ! (!-inv-l hpt) ⟩
! hpt ∙ hpt
=⟨ ! (app=-β lemma true) |in-ctx (λ w → w ∙ hpt) ⟩
app= (λ= lemma) true ∙ hpt
=∎)
where lemma : ∀ b → fst (g (h false)) b == h b
lemma true = ! hpt
lemma false = idp
⊙Bool→-equiv-idf-nat : ∀ {i j} {X : Ptd i} {Y : Ptd j} (F : X ⊙→ Y)
→ CommSquareEquiv
(F ⊙∘_)
(fst F)
⊙Bool→-to-idf
⊙Bool→-to-idf
⊙Bool→-equiv-idf-nat F = (comm-sqr λ _ → idp) ,
snd (⊙Bool→-equiv-idf _) , snd (⊙Bool→-equiv-idf _)
|
{
"alphanum_fraction": 0.4291739895,
"avg_line_length": 33.2748538012,
"ext": "agda",
"hexsha": "7f9bfd8ecd973b3751478370dc2fe272caed26f7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/Pointed.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Pointed.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/Pointed.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3066,
"size": 5690
}
|
------------------------------------------------------------------------
-- Some results/examples related to CCS, implemented using the
-- classical definition of bisimilarity
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude
module Bisimilarity.CCS.Examples.Classical {ℓ} {Name : Type ℓ} where
open import Equality.Propositional
open import Prelude.Size
open import Bisimilarity.CCS.Classical
import Bisimilarity.Classical.Equational-reasoning-instances
open import Equational-reasoning
open import Labelled-transition-system.CCS Name
open import Relation
open import Bisimilarity.Classical CCS
------------------------------------------------------------------------
-- Exercise 6.2.4 from "Enhancements of the bisimulation proof method"
-- by Pous and Sangiorgi
6-2-4 : ∀ {a} → ! ! a ∙ ∼ ! a ∙
6-2-4 {a} = bisimulation-up-to-∼⊆∼ R-is base
where
data R : Rel₂ ℓ (Proc ∞) where
base : R (! ! a ∙ , ! a ∙)
impossible : ∀ {μ P q} {Q : Type q} →
! ! a ∙ [ μ ]⟶ P → μ ≡ τ → Q
impossible {μ} !!a⟶P μ≡τ = ⊥-elim $ name≢τ
(name a ≡⟨ !-only (!-only ·-only) !!a⟶P ⟩
μ ≡⟨ μ≡τ ⟩∎
τ ∎)
R-is : Bisimulation-up-to-bisimilarity R
R-is = ⟪ lr , rl ⟫
where
lemma = λ {P : Proc ∞} P∼!a∣∅ →
! ! a ∙ ∣ P ∼⟨ reflexive ∣-cong P∼!a∣∅ ⟩
! ! a ∙ ∣ (! a ∙ ∣ ∅) ∼⟨ reflexive ∣-cong ∣-right-identity ⟩
! ! a ∙ ∣ ! a ∙ ∼⟨ 6-1-2 ⟩■
! ! a ∙
lr : ∀ {P P′ Q μ} →
R (P , Q) → P [ μ ]⟶ P′ →
∃ λ Q′ → Q [ μ ]⟶ Q′ ×
(Bisimilarity ⊙ R ⊙ Bisimilarity) (P′ , Q′)
lr {P′ = P′} base !!a⟶P′ = case 6-1-3-2 !!a⟶P′ of λ where
(inj₂ (μ≡τ , _)) → impossible !!a⟶P′ μ≡τ
(inj₁ (P″ , !a⟶P″ , P′∼!!a∣P″)) → case 6-1-3-2 !a⟶P″ of λ where
(inj₂ (μ≡τ , _)) → impossible !!a⟶P′ μ≡τ
(inj₁ (.∅ , action , P″∼!a∣∅)) →
_
, (! a ∙ [ name a ]⟶⟨ replication (par-right action) ⟩
! a ∙ ∣ ∅)
, _
, (P′ ∼⟨ P′∼!!a∣P″ ⟩
! ! a ∙ ∣ P″ ∼⟨ ∼: lemma P″∼!a∣∅ ⟩■
! ! a ∙)
, _
, base
, (! a ∙ ∼⟨ symmetric ∣-right-identity ⟩■
! a ∙ ∣ ∅)
rl : ∀ {P Q Q′ μ} →
R (P , Q) → Q [ μ ]⟶ Q′ →
∃ λ P′ → P [ μ ]⟶ P′ ×
(Bisimilarity ⊙ R ⊙ Bisimilarity) (P′ , Q′)
rl {Q′ = Q′} base !a⟶Q′ = case 6-1-3-2 !a⟶Q′ of λ where
(inj₂ (refl , .∅ , Q″ , .a , action , a⟶Q″ , _)) →
⊥-elim (names-are-not-inverted a⟶Q″)
(inj₁ (.∅ , action , Q′∼!a∣∅)) →
_
, (! ! a ∙ [ name a ]⟶⟨ replication (par-right !a⟶Q′) ⟩
! ! a ∙ ∣ Q′)
, _
, (! ! a ∙ ∣ Q′ ∼⟨ lemma Q′∼!a∣∅ ⟩■
! ! a ∙)
, _
, base
, (! a ∙ ∼⟨ symmetric ∣-right-identity ⟩
! a ∙ ∣ ∅ ∼⟨ symmetric Q′∼!a∣∅ ⟩■
Q′)
------------------------------------------------------------------------
-- A result mentioned in "Enhancements of the bisimulation proof
-- method" by Pous and Sangiorgi
∙∣∙∼∙∙ : ∀ {a} → a ∙ ∣ a ∙ ∼ name a ∙ (a ∙)
∙∣∙∼∙∙ {a} = bisimulation-up-to-∪⊆∼ R-is base
where
data R : Rel₂ ℓ (Proc ∞) where
base : R (a ∙ ∣ a ∙ , name a ∙ (a ∙))
R-is : Bisimulation-up-to-∪ R
R-is = ⟪ lr , rl ⟫
where
lr : ∀ {P P′ Q μ} →
R (P , Q) → P [ μ ]⟶ P′ →
∃ λ Q′ → Q [ μ ]⟶ Q′ × (R ∪ Bisimilarity) (P′ , Q′)
lr base (par-left action) =
_
, (name a ∙ (a ∙) [ name a ]⟶⟨ action ⟩
a ∙)
, inj₂ (∅ ∣ a ∙ ∼⟨ ∣-left-identity ⟩■
a ∙)
lr base (par-right action) =
_
, (name a ∙ (a ∙) [ name a ]⟶⟨ action ⟩
a ∙)
, inj₂ (a ∙ ∣ ∅ ∼⟨ ∣-right-identity ⟩■
a ∙)
lr base (par-τ action tr) = ⊥-elim (names-are-not-inverted tr)
rl : ∀ {P Q Q′ μ} →
R (P , Q) → Q [ μ ]⟶ Q′ →
∃ λ P′ → P [ μ ]⟶ P′ × (R ∪ Bisimilarity) (P′ , Q′)
rl base action =
_
, (a ∙ ∣ a ∙ [ name a ]⟶⟨ par-right action ⟩
a ∙ ∣ ∅)
, inj₂ (a ∙ ∣ ∅ ∼⟨ ∣-right-identity ⟩■
a ∙)
|
{
"alphanum_fraction": 0.3935839119,
"avg_line_length": 31.8854961832,
"ext": "agda",
"hexsha": "3c0384b24f09e21232821e5f076892e39cccde3c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Bisimilarity/CCS/Examples/Classical.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/up-to",
"max_issues_repo_path": "src/Bisimilarity/CCS/Examples/Classical.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Bisimilarity/CCS/Examples/Classical.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1732,
"size": 4177
}
|
{-# OPTIONS --without-K --safe #-}
-- Bundled version of a Cocartesian Category
module Categories.Category.Cocartesian.Bundle where
open import Level
open import Categories.Category.Core using (Category)
open import Categories.Category.Cocartesian using (Cocartesian)
-- open import Categories.Category.Cartesian.Monoidal using (module CartesianMonoidal)
-- open import Categories.Category.Monoidal using (MonoidalCategory)
record CocartesianCategory o ℓ e : Set (suc (o ⊔ ℓ ⊔ e)) where
field
U : Category o ℓ e -- U for underlying
cocartesian : Cocartesian U
open Category U public
open Cocartesian cocartesian public
{-
monoidalCategory : MonoidalCategory o ℓ e
monoidalCategory = record
{ U = U
; monoidal = CocartesianMonoidal.monoidal cocartesian
}
-}
|
{
"alphanum_fraction": 0.7382716049,
"avg_line_length": 30,
"ext": "agda",
"hexsha": "0fca3aed0f279d259a3445a043b573dd4c11e7f6",
"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": "602ed2ae05dd449d77fc299c07a1cdd02ee5b823",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sstucki/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Cocartesian/Bundle.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "602ed2ae05dd449d77fc299c07a1cdd02ee5b823",
"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": "sstucki/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Cocartesian/Bundle.agda",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "602ed2ae05dd449d77fc299c07a1cdd02ee5b823",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "sstucki/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Cocartesian/Bundle.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 205,
"size": 810
}
|
module integer7 where
import Relation.Binary.PropositionalEquality as PropEq
open PropEq using (_≡_; refl; cong; sym)
open import Data.Nat
-- Int
data Int : Set where
O : Int
I : ℕ → ℕ → Int
postulate
zeroZ : (x : ℕ) → I x x ≡ O
-- plusInt
_++_ : Int → Int → Int
O ++ O = O
O ++ X = X
X ++ O = X
I x y ++ I z w = I (x + z) (y + w)
postulate
++Assoc : (X Y Z : Int) → (X ++ Y) ++ Z ≡ X ++ (Y ++ Z)
++Comm : (X Y : Int) → X ++ Y ≡ Y ++ X
-- productInt
_**_ : Int → Int → Int
O ** O = O
O ** _ = O
_ ** O = O
I x y ** I z w = I (x * z + y * w) (x * w + y * z)
postulate
**Assoc : (X Y Z : Int) → (X ** Y) ** Z ≡ X ** (Y ** Z)
**Dist : (X Y Z : Int) → X ** (Y ++ Z) ≡ (X ** Y) ++ (X ** Z)
-- (-1) ** (-1) = 1
minus1 : I 0 1 ** I 0 1 ≡ I 1 0
minus1 = refl
-1+1 : I 0 1 ++ I 1 0 ≡ I 1 1
-1+1 = refl
-1*1 : I 0 1 ** I 1 0 ≡ I 0 1
-1*1 = refl
minus2 : I 0 1 ** I 0 1 ≡ I 1 0
minus2 = begin
I 0 1 ** I 0 1
≡⟨ refl ⟩
(I 0 1 ** I 0 1) ++ O
≡⟨ sym (cong (\ x → (I 0 1 ** I 0 1) ++ x) (zeroZ 1)) ⟩
(I 0 1 ** I 0 1) ++ (I 1 1)
≡⟨ sym (cong (\ x → (I 0 1 ** I 0 1) ++ x) -1+1) ⟩
(I 0 1 ** I 0 1) ++ (I 0 1 ++ I 1 0)
≡⟨ sym (++Assoc O O (I (suc (suc zero)) (suc zero))) ⟩
((I 0 1 ** I 0 1) ++ I 0 1) ++ I 1 0
≡⟨ sym (cong (\ x → ((I 0 1 ** I 0 1) ++ x) ++ I 1 0) -1*1) ⟩
((I 0 1 ** I 0 1) ++ (I 0 1 ** I 1 0)) ++ I 1 0
≡⟨ sym (cong (\ x → x ++ I 1 0) (**Dist (I 0 1) (I 0 1) (I 1 0))) ⟩
(I 0 1 ** (I 0 1 ++ I 1 0)) ++ I 1 0
≡⟨ refl ⟩
(I 0 1 ** I 1 1) ++ I 1 0
≡⟨ cong (\ x → ((I 0 1 ** x) ++ I 1 0)) (zeroZ 1) ⟩
(I 0 1 ** O) ++ I 1 0
≡⟨ refl ⟩
O ++ I 1 0
≡⟨ refl ⟩
I 1 0
∎
where open PropEq.≡-Reasoning
|
{
"alphanum_fraction": 0.4061004785,
"avg_line_length": 26.125,
"ext": "agda",
"hexsha": "d9062048bb80eec1ece7ca624a99ea053ecac0db",
"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": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "righ1113/Agda",
"max_forks_repo_path": "integer7.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84",
"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": "righ1113/Agda",
"max_issues_repo_path": "integer7.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9117b6bec9880d8c0a5d6ee4399fd841c3544d84",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "righ1113/Agda",
"max_stars_repo_path": "integer7.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 932,
"size": 1672
}
|
{-# OPTIONS --rewriting --without-K #-}
open import Agda.Primitive
open import Prelude
import GSeTT.Syntax
import GSeTT.Rules
open import GSeTT.Typed-Syntax
import Globular-TT.Syntax
module Globular-TT.Rules {l} (index : Set l) (rule : index → GSeTT.Typed-Syntax.Ctx × (Globular-TT.Syntax.Pre-Ty index)) where
open import Globular-TT.Syntax index
{- Notational shortcuts : the context corresponding to an index -}
Ci : index → Pre-Ctx
Ci i = GPre-Ctx (fst (fst (rule i)))
Ti : index → Pre-Ty
Ti i = snd (rule i)
data _⊢C : Pre-Ctx → Set (lsuc l)
data _⊢T_ : Pre-Ctx → Pre-Ty → Set (lsuc l)
data _⊢t_#_ : Pre-Ctx → Pre-Tm → Pre-Ty → Set (lsuc l)
data _⊢S_>_ : Pre-Ctx → Pre-Sub → Pre-Ctx → Set (lsuc l)
data _⊢C where
ec : ⊘ ⊢C
cc : ∀ {Γ A x} → Γ ⊢C → Γ ⊢T A → x == C-length Γ → (Γ ∙ x # A) ⊢C
data _⊢T_ where
ob : ∀ {Γ} → Γ ⊢C → Γ ⊢T ∗
ar : ∀ {Γ A t u} → Γ ⊢T A → Γ ⊢t t # A → Γ ⊢t u # A → Γ ⊢T ⇒ A t u
data _⊢t_#_ where
var : ∀ {Γ x A} → Γ ⊢C → x # A ∈ Γ → Γ ⊢t (Var x) # A
tm : ∀ {Δ γ A i} → Ci i ⊢T Ti i → Δ ⊢S γ > Ci i → (A == (Ti i [ γ ]Pre-Ty)) → Δ ⊢t Tm-constructor i γ # A
data _⊢S_>_ where
es : ∀ {Δ} → Δ ⊢C → Δ ⊢S <> > ⊘
sc : ∀ {Δ Γ γ x y A t} → Δ ⊢S γ > Γ → (Γ ∙ x # A) ⊢C → (Δ ⊢t t # (A [ γ ]Pre-Ty)) → x == y → Δ ⊢S < γ , y ↦ t > > (Γ ∙ x # A)
{- Derivability is preserved by the translation from GSeTT to our TT -}
x∈GCtx : ∀ {x A Γ} → x GSeTT.Syntax.# A ∈ Γ → x # GPre-Ty A ∈ GPre-Ctx Γ
x∈GCtx {Γ = Γ :: a} (inl x∈Γ) = inl (x∈GCtx x∈Γ)
x∈GCtx {Γ = Γ :: (x,A)} (inr (idp , idp)) = inr (idp , idp)
G-length : ∀ Γ → length Γ == C-length (GPre-Ctx Γ)
G-length nil = idp
G-length (Γ :: _) = S= (G-length Γ)
GCtx : ∀ (Γ : GSeTT.Syntax.Pre-Ctx) → Γ GSeTT.Rules.⊢C → (GPre-Ctx Γ) ⊢C
GTy : ∀ (Γ : GSeTT.Syntax.Pre-Ctx) (A : GSeTT.Syntax.Pre-Ty) → Γ GSeTT.Rules.⊢T A → (GPre-Ctx Γ) ⊢T (GPre-Ty A)
GTm : ∀ (Γ : GSeTT.Syntax.Pre-Ctx) (A : GSeTT.Syntax.Pre-Ty) (t : GSeTT.Syntax.Pre-Tm) → Γ GSeTT.Rules.⊢t t # A → (GPre-Ctx Γ) ⊢t (GPre-Tm t) # (GPre-Ty A)
GCtx .nil GSeTT.Rules.ec = ec
GCtx (Γ :: (.(length Γ) , A)) (GSeTT.Rules.cc Γ⊢ Γ⊢A idp) = coe (ap (λ n → (GPre-Ctx (Γ :: (n , A)) ⊢C)) (G-length Γ) ^) (cc (GCtx Γ Γ⊢) (GTy Γ A Γ⊢A) idp)
GTy Γ .GSeTT.Syntax.∗ (GSeTT.Rules.ob Γ⊢) = ob (GCtx Γ Γ⊢)
GTy Γ (GSeTT.Syntax.⇒ A t u) (GSeTT.Rules.ar Γ⊢t:A Γ⊢u:A) = ar (GTy Γ A (GSeTT.Rules.Γ⊢t:A→Γ⊢A Γ⊢t:A)) (GTm Γ A t Γ⊢t:A) (GTm Γ A u Γ⊢u:A)
GTm Γ A (GSeTT.Syntax.Var x) (GSeTT.Rules.var Γ⊢ x∈Γ) = var (GCtx Γ Γ⊢) (x∈GCtx x∈Γ)
{- Properties of the type theory -}
{- weakening admissibility -}
wkT : ∀ {Γ A y B} → Γ ⊢T A → (Γ ∙ y # B) ⊢C → (Γ ∙ y # B) ⊢T A
wkt : ∀ {Γ A t y B} → Γ ⊢t t # A → (Γ ∙ y # B) ⊢C → (Γ ∙ y # B) ⊢t t # A
wkS : ∀ {Δ Γ γ y B} → Δ ⊢S γ > Γ → (Δ ∙ y # B) ⊢C → (Δ ∙ y # B) ⊢S γ > Γ
wkT (ob _) Γ,y:B⊢ = ob Γ,y:B⊢
wkT (ar Γ⊢A Γ⊢t:A Γ⊢u:A) Γ,y:B⊢ = ar (wkT Γ⊢A Γ,y:B⊢) (wkt Γ⊢t:A Γ,y:B⊢) (wkt Γ⊢u:A Γ,y:B⊢)
wkt (var Γ⊢C x∈Γ) Γ,y:B⊢ = var Γ,y:B⊢ (inl x∈Γ)
wkt (tm Ci⊢Ti Γ⊢γ:Δ idp) Γ,y:B⊢ = tm Ci⊢Ti (wkS Γ⊢γ:Δ Γ,y:B⊢) idp
wkS (es _) Δ,y:B⊢ = es Δ,y:B⊢
wkS (sc Δ⊢γ:Γ Γ,x:A⊢ Δ⊢t:A[γ] idp) Δ,y:B⊢ = sc (wkS Δ⊢γ:Γ Δ,y:B⊢) Γ,x:A⊢ (wkt Δ⊢t:A[γ] Δ,y:B⊢) idp
{- Consistency : all objects appearing in derivable judgments are derivable -}
Γ⊢A→Γ⊢ : ∀ {Γ A} → Γ ⊢T A → Γ ⊢C
Γ⊢t:A→Γ⊢ : ∀ {Γ A t} → Γ ⊢t t # A → Γ ⊢C
Δ⊢γ:Γ→Δ⊢ : ∀ {Δ Γ γ} → Δ ⊢S γ > Γ → Δ ⊢C
Γ⊢A→Γ⊢ (ob Γ⊢) = Γ⊢
Γ⊢A→Γ⊢ (ar Γ⊢A Γ⊢t:A Γ⊢u:A) = Γ⊢t:A→Γ⊢ Γ⊢t:A
Γ⊢t:A→Γ⊢ (var Γ⊢ _) = Γ⊢
Γ⊢t:A→Γ⊢ (tm _ Γ⊢γ:Δ idp) = Δ⊢γ:Γ→Δ⊢ Γ⊢γ:Δ
Δ⊢γ:Γ→Δ⊢ (es Δ⊢) = Δ⊢
Δ⊢γ:Γ→Δ⊢ (sc Δ⊢γ:Γ Γ,x:A⊢ Δ⊢t:A[γ] idp) = Δ⊢γ:Γ→Δ⊢ Δ⊢γ:Γ
Δ⊢γ:Γ→Γ⊢ : ∀ {Δ Γ γ} → Δ ⊢S γ > Γ → Γ ⊢C
Δ⊢γ:Γ→Γ⊢ (es Δ⊢) = ec
Δ⊢γ:Γ→Γ⊢ (sc Δ⊢γ:Γ Γ,x:A⊢ Δ⊢t:A[γ] idp) = Γ,x:A⊢
Γ,x:A⊢→Γ,x:A⊢A : ∀ {Γ x A} → (Γ ∙ x # A) ⊢C → (Γ ∙ x # A) ⊢T A
Γ,x:A⊢→Γ,x:A⊢A Γ,x:A⊢@(cc Γ⊢ Γ⊢A idp) = wkT Γ⊢A Γ,x:A⊢
Γ,x:A⊢→Γ,x:A⊢x:A : ∀ {Γ x A} → (Γ ∙ x # A) ⊢C → (Γ ∙ x # A) ⊢t (Var x) # A
Γ,x:A⊢→Γ,x:A⊢x:A Γ,x:A⊢ = var Γ,x:A⊢ (inr (idp , idp))
Γ⊢src : ∀ {Γ A t u} → Γ ⊢T ⇒ A t u → Γ ⊢t t # A
Γ⊢src (ar Γ⊢ Γ⊢t Γ⊢u) = Γ⊢t
Γ⊢tgt : ∀ {Γ A t u} → Γ ⊢T ⇒ A t u → Γ ⊢t u # A
Γ⊢tgt (ar Γ⊢ Γ⊢t Γ⊢u) = Γ⊢u
-- The proposition Γ⊢t:A→Γ⊢A is slightly harder and is moved in CwF-Struture since it depends on lemmas there
-- Type epressing that the rules are well-founded (useful to show that judgments are decidable)
well-founded : Set (lsuc l)
well-founded = ∀ (i : index) → Ci i ⊢T Ti i → dimC (Ci i) ≤ dim (Ti i)
-- Derivation of a term constructed by a term constructor
Γ⊢tm→Ci⊢Ti : ∀ {i Γ γ A} → Γ ⊢t (Tm-constructor i γ) # A → Ci i ⊢T Ti i
Γ⊢tm→Ci⊢Ti (tm Ci⊢Ti _ idp) = Ci⊢Ti
Γ⊢tm→Γ⊢γ : ∀ {i Γ γ A} → Γ ⊢t (Tm-constructor i γ) # A → Γ ⊢S γ > Ci i
Γ⊢tm→Γ⊢γ (tm _ Γ⊢γ idp) = Γ⊢γ
|
{
"alphanum_fraction": 0.5072494221,
"avg_line_length": 41.025862069,
"ext": "agda",
"hexsha": "383f4eb718416562569bdb889e7a44c9ce0c1dc6",
"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/Rules.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/Rules.agda",
"max_line_length": 158,
"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/Rules.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2794,
"size": 4759
}
|
import Lvl
open import Structure.Operator.Ring
open import Structure.Setoid
open import Type
module Structure.Operator.Ring.Characteristic {ℓ ℓₑ} {T : Type{ℓ}} ⦃ equiv : Equiv{ℓₑ}(T) ⦄ (_+_ _⋅_ : T → T → T) ⦃ ring : Ring(_+_)(_⋅_) ⦄ where
open Ring(ring)
open import Function.Iteration
open import Numeral.Natural as ℕ using (ℕ)
import Numeral.Natural.Relation.Order as ℕ
open import Relator.Equals using () renaming (_≡_ to _≡ₑ_)
CharacteristicMultiple : ℕ → Type
CharacteristicMultiple(n) = ∀{a} → (repeatᵣ(n)(_+_) a 𝟎 ≡ 𝟎)
data Characteristic : ℕ → Type{ℓ Lvl.⊔ ℓₑ} where
none : (∀{n} → CharacteristicMultiple(n) → (n ≡ₑ ℕ.𝟎)) → Characteristic(ℕ.𝟎)
pos : ∀{n} → CharacteristicMultiple(ℕ.𝐒(n)) → (∀{m} → CharacteristicMultiple(ℕ.𝐒(m)) → (ℕ.𝐒(m) ℕ.≥ ℕ.𝐒(n))) → Characteristic(ℕ.𝐒(n))
|
{
"alphanum_fraction": 0.6732919255,
"avg_line_length": 40.25,
"ext": "agda",
"hexsha": "072985e6dc376f080baa793ba9b12e284c63c02b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Operator/Ring/Characteristic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Operator/Ring/Characteristic.agda",
"max_line_length": 146,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Operator/Ring/Characteristic.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": 324,
"size": 805
}
|
------------------------------------------------------------------------
-- The syntax of, and a type system for, the untyped λ-calculus with
-- constants
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Lambda.Syntax where
open import Equality.Propositional
open import Prelude
open import Prelude.Size
open import Maybe equality-with-J
open import Vec.Function equality-with-J
------------------------------------------------------------------------
-- Terms
-- Variables are represented using de Bruijn indices.
infixl 9 _·_
data Tm (n : ℕ) : Type where
con : (i : ℕ) → Tm n
var : (x : Fin n) → Tm n
ƛ : Tm (suc n) → Tm n
_·_ : Tm n → Tm n → Tm n
------------------------------------------------------------------------
-- Closure-based definition of values
-- Environments and values. Defined in a module parametrised by the
-- type of terms.
module Closure (Tm : ℕ → Type) where
mutual
-- Environments.
Env : ℕ → Type
Env n = Vec Value n
-- Values. Lambdas are represented using closures, so values do
-- not contain any free variables.
data Value : Type where
con : (i : ℕ) → Value
ƛ : ∀ {n} (t : Tm (suc n)) (ρ : Env n) → Value
------------------------------------------------------------------------
-- Type system
-- Recursive, simple types, defined coinductively.
infixr 8 _⇾_
mutual
data Ty (i : Size) : Type where
nat : Ty i
_⇾_ : (σ τ : ∞Ty i) → Ty i
record ∞Ty (i : Size) : Type where
coinductive
field
force : {j : Size< i} → Ty j
open ∞Ty public
-- A conversion function.
[_] : Ty ∞ → ∞Ty ∞
[ σ ] .force = σ
-- Contexts.
Ctxt : ℕ → Type
Ctxt n = Vec (Ty ∞) n
-- Type system.
infix 4 _⊢_∈_
data _⊢_∈_ {n} (Γ : Ctxt n) : Tm n → Ty ∞ → Type where
con : ∀ {i} → Γ ⊢ con i ∈ nat
var : ∀ {x} → Γ ⊢ var x ∈ Γ x
ƛ : ∀ {t σ τ} →
cons (force σ) Γ ⊢ t ∈ force τ → Γ ⊢ ƛ t ∈ σ ⇾ τ
_·_ : ∀ {t₁ t₂ σ τ} →
Γ ⊢ t₁ ∈ σ ⇾ τ → Γ ⊢ t₂ ∈ force σ →
Γ ⊢ t₁ · t₂ ∈ force τ
------------------------------------------------------------------------
-- Some definitions used in several type soundness proofs
open Closure Tm
-- WF-Value, WF-Env and WF-MV specify when a
-- value/environment/potential value is well-formed with respect to a
-- given context (and type).
mutual
data WF-Value : Ty ∞ → Value → Type where
con : ∀ {i} → WF-Value nat (con i)
ƛ : ∀ {n Γ σ τ} {t : Tm (1 + n)} {ρ} →
cons (force σ) Γ ⊢ t ∈ force τ →
WF-Env Γ ρ →
WF-Value (σ ⇾ τ) (ƛ t ρ)
WF-Env : ∀ {n} → Ctxt n → Env n → Type
WF-Env Γ ρ = ∀ x → WF-Value (Γ x) (ρ x)
WF-MV : Ty ∞ → Maybe Value → Type
WF-MV σ v = maybe (WF-Value σ) Prelude.⊥ v
-- Some "constructors" for WF-Env.
nil-wf : WF-Env nil nil
nil-wf ()
cons-wf : ∀ {n} {Γ : Ctxt n} {ρ σ v} →
WF-Value σ v → WF-Env Γ ρ → WF-Env (cons σ Γ) (cons v ρ)
cons-wf v-wf ρ-wf fzero = v-wf
cons-wf v-wf ρ-wf (fsuc x) = ρ-wf x
------------------------------------------------------------------------
-- Examples
-- A non-terminating term.
ω : Tm 0
ω = ƛ (var fzero · var fzero)
Ω : Tm 0
Ω = ω · ω
-- Ω is well-typed.
Ω-well-typed : (τ : Ty ∞) → nil ⊢ Ω ∈ τ
Ω-well-typed τ =
_·_ {σ = σ} {τ = [ τ ]} (ƛ (var · var)) (ƛ (var · var))
where
σ : ∀ {i} → ∞Ty i
σ .force = σ ⇾ [ τ ]
-- A call-by-value fixpoint combinator.
Z : Tm 0
Z = ƛ (t · t)
where
t = ƛ (var (fsuc fzero) ·
ƛ (var (fsuc fzero) · var (fsuc fzero) · var fzero))
-- This combinator is also well-typed.
Z-well-typed :
∀ {σ τ} →
nil ⊢ Z ∈ [ [ [ σ ] ⇾ [ τ ] ] ⇾ [ [ σ ] ⇾ [ τ ] ] ] ⇾
[ [ σ ] ⇾ [ τ ] ]
Z-well-typed {σ = σ} {τ = τ} =
ƛ (_·_ {σ = υ} {τ = [ _ ]}
(ƛ (var · ƛ (var · var · var)))
(ƛ (var · ƛ (var · var · var))))
where
υ : ∀ {i} → ∞Ty i
force υ = υ ⇾ [ [ σ ] ⇾ [ τ ] ]
|
{
"alphanum_fraction": 0.4650565262,
"avg_line_length": 22.8941176471,
"ext": "agda",
"hexsha": "ee986ecff93929dbbb4e17d5e1284fa85bfd1545",
"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": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Lambda/Syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"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/partiality-monad",
"max_issues_repo_path": "src/Lambda/Syntax.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Lambda/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 1379,
"size": 3892
}
|
module Plylet where
open import Data.String.Base
open import Data.Char.Base
open import Data.List.Base
data Type : Set where
-- The type of the unit value
TUnit : Type
-- The type constructor for functions →
TFunc : Type -> Type -> Type
-- A type loaded from the prelude
TBuiltin : String -> Type
data Term : Set where
-- The value of unit
VUnit : Term
-- An well-typed application is a valid term
VApp : Term → Term → Term
-- A well-formed let expression is a valid term
VLet : Char -> Term -> Term -> Term
-- A function from the prelude
VFunc : String -> Term
data Judgment : Set where
-- A typing judgment
TypeJ : Term → Type → Judgment
-- A coercion validity judgment
CoerceJ : Type → Type → Judgment
Gamma : Set
Gamma = List Judgment
baseEnv : Gamma
baseEnv =
TypeJ VUnit TUnit
∷ []
|
{
"alphanum_fraction": 0.6509758898,
"avg_line_length": 22.9210526316,
"ext": "agda",
"hexsha": "7a9726f09d71214cadb19b8a59c8ef8a6bdf15d1",
"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": "0fd0c9d0ff00529b48f65b638fe288172916bf71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Kazark/plylet",
"max_forks_repo_path": "Plylet.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0fd0c9d0ff00529b48f65b638fe288172916bf71",
"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": "Kazark/plylet",
"max_issues_repo_path": "Plylet.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0fd0c9d0ff00529b48f65b638fe288172916bf71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Kazark/plylet",
"max_stars_repo_path": "Plylet.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 232,
"size": 871
}
|
------------------------------------------------------------------------------
-- Properties related with lists (using induction on the FOTC lists type)
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.List.PropertiesByInductionATP where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.List
open import FOTC.Data.Nat.Type
------------------------------------------------------------------------------
-- Totality properties
-- See Issue https://github.com/asr/apia/issues/81 .
lengthList-NA : D → Set
lengthList-NA ds = N (length ds)
{-# ATP definition lengthList-NA #-}
lengthList-N : ∀ {xs} → List xs → N (length xs)
lengthList-N = List-ind lengthList-NA A[] h
where
postulate A[] : lengthList-NA []
{-# ATP prove A[] #-}
postulate h : ∀ a {as} → lengthList-NA as → lengthList-NA (a ∷ as)
{-# ATP prove h #-}
------------------------------------------------------------------------------
-- See Issue https://github.com/asr/apia/issues/81 .
++-assocA : D → D → D → Set
++-assocA ys zs as = (as ++ ys) ++ zs ≡ as ++ ys ++ zs
{-# ATP definition ++-assocA #-}
++-assoc : ∀ {xs} → List xs → ∀ ys zs → (xs ++ ys) ++ zs ≡ xs ++ ys ++ zs
++-assoc Lxs ys zs = List-ind (++-assocA ys zs) A[] h Lxs
where
postulate A[] : ++-assocA ys zs []
{-# ATP prove A[] #-}
postulate h : ∀ a {as} → ++-assocA ys zs as → ++-assocA ys zs (a ∷ as)
{-# ATP prove h #-}
|
{
"alphanum_fraction": 0.4780728845,
"avg_line_length": 33.0408163265,
"ext": "agda",
"hexsha": "8683f7b7152ed55ccd9d79ed087a7418615ab169",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Data/List/PropertiesByInductionATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Data/List/PropertiesByInductionATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Data/List/PropertiesByInductionATP.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": 414,
"size": 1619
}
|
module Implicits.Resolution.Infinite.NormalFormEquiv where
open import Prelude
open import Implicits.Syntax
open import Implicits.Resolution.Infinite.Resolution
open import Implicits.Resolution.Embedding
open import Implicits.Resolution.Embedding.Lemmas
open import SystemF.Everything as F using ()
open import SystemF.NormalForm
open import Data.Vec hiding ([_])
open import Relation.Binary.HeterogeneousEquality as H using ()
open import Data.List.Any
open import Data.List.Properties
open import Data.Vec.Properties as VP using ()
open import Extensions.Vec
open import Function.Equivalence using (_⇔_; equivalence)
mutual
from-⇓ : ∀ {ν n t a τ} {Γ : F.Ctx ν n} → Γ ⊢ t ⇓ a → ⟦ Γ ⟧ctx← ⊢ ⟦ a ⟧tp← ↓ τ →
∃ λ i → ⟦ Γ ⟧ctx← ⊢ ⟦ lookup i Γ ⟧tp← ↓ τ
from-⇓ {Γ = Γ} (nvar i) ↓τ = i , ↓τ
from-⇓ (napp p x) ↓τ = from-⇓ p (i-iabs (from-⇑ x) ↓τ)
from-⇓ {Γ = Γ} (ntapp {a = a} b p) ↓τ = from-⇓ p
(i-tabs ⟦ b ⟧tp← (subst (λ z → ⟦ Γ ⟧ctx← ⊢ z ↓ _) (⟦a/sub⟧tp← a b) ↓τ))
from-⇑ : ∀ {ν n t a} {Γ : F.Ctx ν n} → Γ ⊢ t ⇑ a → ⟦ Γ ⟧ctx← ⊢ᵣ ⟦ a ⟧tp←
from-⇑ (nbase b x) with ⟦base⟧tp← b
from-⇑ (nbase b x) | τ , eq with from-⇓ x (subst (λ z → _ ⊢ z ↓ τ) (sym $ eq) (i-simp τ))
from-⇑ (nbase b x) | τ , eq | i , lookup-i↓tc =
subst (λ z → _ ⊢ᵣ z) (sym $ eq) (r-simp (lookup-∈ i _) lookup-i↓tc)
from-⇑ (nabs p) = r-iabs (from-⇑ p)
from-⇑ (ntabs p) = r-tabs (subst (λ z → z ⊢ᵣ _) (⟦weaken⟧ctx← _) (from-⇑ p))
to-⇓ : ∀ {ν} {Δ : ICtx ν} {a τ t₁} → Δ ⊢ a ↓ τ → ⟦ Δ ⟧ctx→ ⊢ t₁ ⇓ ⟦ a ⟧tp→ →
∃ λ t₂ → ⟦ Δ ⟧ctx→ ⊢ t₂ ⇓ ⟦ simpl τ ⟧tp→
to-⇓ (i-simp a) q = , q
to-⇓ (i-iabs x p) q = to-⇓ p (napp q (proj₂ $ to-⇑ x))
to-⇓ {Δ = Δ} (i-tabs {ρ = a} b p) q =
to-⇓ p (subst (λ z → ⟦ Δ ⟧ctx→ ⊢ _ ⇓ z) (sym $ ⟦a/sub⟧tp→ a b) (ntapp ⟦ b ⟧tp→ q))
to-⇑ : ∀ {ν} {Δ : ICtx ν} {a} → Δ ⊢ᵣ a → ∃ λ t → ⟦ Δ ⟧ctx→ ⊢ t ⇑ ⟦ a ⟧tp→
to-⇑ {Δ = Δ} (r-simp {r = a} r r↓τ) = , nbase (⟦simpl⟧tp→ _) (proj₂ $ to-⇓ r↓τ var⇓a)
where
var⇓a : ⟦ Δ ⟧ctx→ ⊢ _ ⇓ ⟦ a ⟧tp→
var⇓a = let (i , eq) = ∈⟶index (VP.List-∈⇒∈ r) in
let i' = (subst Fin (sym $ length-map _ Δ) i) in
subst (λ z → ⟦ Δ ⟧ctx→ ⊢ (F.var i') ⇓ z) (lookup⟦⟧ Δ i eq) (nvar i')
to-⇑ (r-iabs p) =
, nabs (proj₂ $ to-⇑ p)
to-⇑ {Δ = Δ} (r-tabs {ρ = a} p) =
, ntabs (⇑-subst-n (length-weaken-Δ Δ) (H.sym $ ⟦weaken⟧ctx→ Δ) (proj₂ (to-⇑ p)))
-- System F η-long-β-normal forms are isomorphic to infinite resolution derivations
equivalent : ∀ {ν} (Δ : ICtx ν) r → Δ ⊢ᵣ r ⇔ (∃ λ t → ⟦ Δ ⟧ctx→ ⊢ t ⇑ ⟦ r ⟧tp→)
equivalent Δ r = equivalence
(λ x → to-⇑ x)
(λ x → subst₂ (λ Δ' r' → Δ' ⊢ᵣ r') (ctx→← _) (tp→← r) (from-⇑ (proj₂ x)))
{-}
open import Function.Inverse
open import Function.Equality
-- from-⇑ : ∀ {ν n t a} {Γ : F.Ctx ν n} → Γ ⊢ t ⇑ a → ⟦ Γ ⟧ctx← ⊢ᵣ ⟦ a ⟧tp←
from-⇑' : ∀ {ν a} {Δ : ICtx ν} → (∃ λ t → ⟦ Δ ⟧ctx→ ⊢ t ⇑ ⟦ a ⟧tp→) → Δ ⊢ᵣ a
from-⇑' (_ , p) = subst₂ (λ Δ a → Δ ⊢ᵣ a) (ctx→← _) (tp→← _) (from-⇑ p)
-- from-⇓' : ∀ {ν a} {Δ : ICtx ν} {τ} → (∃ λ t → ⟦ Δ ⟧ctx→ ⊢ t ⇓ ⟦ a ⟧tp→) → Δ ⊢ Δ ⊢ a ↓ τ
-- from-⇓' {τ = τ} (_ , p) = subst₂ (λ Δ a → Δ ⊢ a ↓ τ) (ctx→← _) (tp→← _) (from-⇓ p)
-- from-to-⇓ : ∀ {ν a} {Δ : ICtx ν} {τ} → (p : Δ ⊢ a ↓ τ) → from-⇓' (to-⇓ p) ≡ p
-- from-to-⇓ p = ?
from-to-⇑ : ∀ {ν a} {Δ : ICtx ν} → (p : Δ ⊢ᵣ a) → from-⇑' (to-⇑ p) ≡ p
from-to-⇑ (r-simp x x₁) = {!!}
from-to-⇑ (r-iabs p) = begin
from-⇑' (, (nabs (proj₂ (to-⇑ p))))
≡⟨ refl ⟩
subst₂ (λ Δ a → Δ ⊢ᵣ a) (ctx→← _) (tp→← _) (from-⇑ (nabs (proj₂ (to-⇑ p))))
≡⟨ refl ⟩
subst₂ (λ Δ a → Δ ⊢ᵣ a) (ctx→← _) (tp→← _) (r-iabs (from-⇑ (proj₂ (to-⇑ p))))
≡⟨ {!!} ⟩
r-iabs (subst₂ (λ Δ a → Δ ⊢ᵣ a) (ctx→← _) (tp→← _) (from-⇑ (proj₂ (to-⇑ p))))
≡⟨ refl ⟩
r-iabs (from-⇑' (to-⇑ p))
≡⟨ Prelude.cong r-iabs (from-to-⇑ p) ⟩
r-iabs p ∎
from-to-⇑ (r-tabs p) with from-to-⇑ p
from-to-⇑ (r-tabs p) | x = {!x!}
where
lem : ∀ {ν a} {Δ : ICtx ν} →
to-from-⇑ : ∀ {ν a} {Δ : ICtx ν} → (p : ∃ λ t → ⟦ Δ ⟧ctx→ ⊢ t ⇑ ⟦ a ⟧tp→) → to-⇑ (from-⇑' p) ≡ p
to-from-⇑ p = {!!}
iso' : ∀ {ν a} {Δ : ICtx ν} → (→-to-⟶ (to-⇑ {Δ = Δ} {a = a})) InverseOf (→-to-⟶ from-⇑')
iso' = record { left-inverse-of = to-from-⇑; right-inverse-of = from-to-⇑ }
-}
|
{
"alphanum_fraction": 0.4901252408,
"avg_line_length": 40.3106796117,
"ext": "agda",
"hexsha": "fbbbc290bcf2c0b902ace760a56af51164378f1c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Infinite/NormalFormEquiv.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Infinite/NormalFormEquiv.agda",
"max_line_length": 96,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Infinite/NormalFormEquiv.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 2188,
"size": 4152
}
|
-- Solver for cartesian category
-- Normalisation is based on https://arxiv.org/abs/math/9911059
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Category.Cartesian
module Experiment.Categories.Solver.Category.Cartesian
{o ℓ e} {𝒞 : Category o ℓ e} (cartesian : Cartesian 𝒞) where
open import Level
open import Relation.Binary using (Rel; REL)
import Categories.Morphism.Reasoning as MR
open Category 𝒞
open Cartesian cartesian
open HomReasoning
open MR 𝒞
private
variable
A B C D E F : Obj
infixr 9 _:∘_
infixr 7 _:×_
infix 11 :⟨_,_⟩
data Sig : Set o where
∥_∥ : Obj → Sig
:⊤ : Sig
_:×_ : Sig → Sig → Sig
⟦_⟧Sig : Sig → Obj
⟦ ∥ A ∥ ⟧Sig = A
⟦ :⊤ ⟧Sig = ⊤
⟦ S₁ :× S₂ ⟧Sig = ⟦ S₁ ⟧Sig × ⟦ S₂ ⟧Sig
private
variable
S T U V : Sig
-- Expression for cartesian category
data Expr : Rel Sig (o ⊔ ℓ) where
:id : Expr S S
_:∘_ : Expr T U → Expr S T → Expr S U
:π₁ : Expr (S :× T) S
:π₂ : Expr (S :× T) T
:⟨_,_⟩ : Expr U S → Expr U T → Expr U (S :× T)
∥_∥ : A ⇒ B → Expr ∥ A ∥ ∥ B ∥
∥_!∥ : A ⇒ ⊤ → Expr ∥ A ∥ :⊤
-- Atomised expression
data AExpr : REL Sig Obj (o ⊔ ℓ) where
:π₁ : AExpr (∥ A ∥ :× T) A
:π₂ : AExpr (S :× ∥ B ∥) B
_:∘π₁ : AExpr S A → AExpr (S :× T) A
_:∘π₂ : AExpr T A → AExpr (S :× T) A
-- Normalised expression
data NExpr : Rel Sig (o ⊔ ℓ) where
:id : NExpr ∥ A ∥ ∥ A ∥
:!N : NExpr S :⊤
⟪_⟫ : AExpr S A → NExpr S ∥ A ∥
:⟨_,_⟩ : NExpr U S → NExpr U T → NExpr U (S :× T)
∥_∥∘_ : B ⇒ C → NExpr S ∥ B ∥ → NExpr S ∥ C ∥
-- Semantics
⟦_⟧ : Expr S T → ⟦ S ⟧Sig ⇒ ⟦ T ⟧Sig
⟦ :id ⟧ = id
⟦ e₁ :∘ e₂ ⟧ = ⟦ e₁ ⟧ ∘ ⟦ e₂ ⟧
⟦ :π₁ ⟧ = π₁
⟦ :π₂ ⟧ = π₂
⟦ :⟨ e₁ , e₂ ⟩ ⟧ = ⟨ ⟦ e₁ ⟧ , ⟦ e₂ ⟧ ⟩
⟦ ∥ f ∥ ⟧ = f
⟦ ∥ g !∥ ⟧ = g
⟦_⟧A : AExpr S B → ⟦ S ⟧Sig ⇒ B
⟦ :π₁ ⟧A = π₁
⟦ :π₂ ⟧A = π₂
⟦ e :∘π₁ ⟧A = ⟦ e ⟧A ∘ π₁
⟦ e :∘π₂ ⟧A = ⟦ e ⟧A ∘ π₂
⟦_⟧N : NExpr S T → ⟦ S ⟧Sig ⇒ ⟦ T ⟧Sig
⟦ :id ⟧N = id
⟦ :!N ⟧N = !
⟦ ⟪ e ⟫ ⟧N = ⟦ e ⟧A
⟦ :⟨ e₁ , e₂ ⟩ ⟧N = ⟨ ⟦ e₁ ⟧N , ⟦ e₂ ⟧N ⟩
⟦ ∥ f ∥∘ e ⟧N = f ∘ ⟦ e ⟧N
_∘AN_ : AExpr T A → NExpr S T → NExpr S ∥ A ∥
:π₁ ∘AN :⟨ e₂ , e₃ ⟩ = e₂
:π₂ ∘AN :⟨ e₂ , e₃ ⟩ = e₃
(e₁ :∘π₁) ∘AN :⟨ e₂ , e₃ ⟩ = e₁ ∘AN e₂
(e₁ :∘π₂) ∘AN :⟨ e₂ , e₃ ⟩ = e₁ ∘AN e₃
_∘π₁N : NExpr S U → NExpr (S :× T) U
:id ∘π₁N = ⟪ :π₁ ⟫
:!N ∘π₁N = :!N
⟪ e ⟫ ∘π₁N = ⟪ e :∘π₁ ⟫
:⟨ e₁ , e₂ ⟩ ∘π₁N = :⟨ e₁ ∘π₁N , e₂ ∘π₁N ⟩
(∥ f ∥∘ e) ∘π₁N = ∥ f ∥∘ (e ∘π₁N)
_∘π₂N : NExpr T U → NExpr (S :× T) U
:id ∘π₂N = ⟪ :π₂ ⟫
:!N ∘π₂N = :!N
⟪ e ⟫ ∘π₂N = ⟪ e :∘π₂ ⟫
:⟨ e₁ , e₂ ⟩ ∘π₂N = :⟨ e₁ ∘π₂N , e₂ ∘π₂N ⟩
(∥ f ∥∘ e) ∘π₂N = ∥ f ∥∘ (e ∘π₂N)
_∘N_ : NExpr T U → NExpr S T → NExpr S U
:id ∘N e₂ = e₂
:!N ∘N e₂ = :!N
⟪ e₁ ⟫ ∘N e₂ = e₁ ∘AN e₂
:⟨ e₁ , e₂ ⟩ ∘N e₃ = :⟨ e₁ ∘N e₃ , e₂ ∘N e₃ ⟩
(∥ f ∥∘ e₁) ∘N e₂ = ∥ f ∥∘ (e₁ ∘N e₂)
π₁N : ∀ S T → NExpr (S :× T) S
π₂N : ∀ S T → NExpr (S :× T) T
π₁N ∥ _ ∥ T = ⟪ :π₁ ⟫
π₁N :⊤ T = :!N
π₁N (S₁ :× S₂) T = :⟨ (π₁N S₁ S₂) ∘π₁N , (π₂N S₁ S₂) ∘π₁N ⟩
π₂N S ∥ _ ∥ = ⟪ :π₂ ⟫
π₂N S :⊤ = :!N
π₂N S (T₁ :× T₂) = :⟨ (π₁N T₁ T₂) ∘π₂N , (π₂N T₁ T₂) ∘π₂N ⟩
idN : ∀ S → NExpr S S
idN ∥ _ ∥ = :id
idN :⊤ = :!N
idN (S :× T) = :⟨ π₁N S T , π₂N S T ⟩
-- expand id, π₁ and π₂
normalise : Expr S T → NExpr S T
normalise :id = idN _
normalise (e₁ :∘ e₂) = normalise e₁ ∘N normalise e₂
normalise :π₁ = π₁N _ _
normalise :π₂ = π₂N _ _
normalise :⟨ e₁ , e₂ ⟩ = :⟨ normalise e₁ , normalise e₂ ⟩
normalise ∥ f ∥ = ∥ f ∥∘ :id
normalise ∥ g !∥ = :!N
∘AN-homo : (e₁ : AExpr T A) (e₂ : NExpr S T) → ⟦ e₁ ∘AN e₂ ⟧N ≈ ⟦ e₁ ⟧A ∘ ⟦ e₂ ⟧N
∘AN-homo :π₁ :⟨ e₂ , e₃ ⟩ = ⟺ project₁
∘AN-homo :π₂ :⟨ e₂ , e₃ ⟩ = ⟺ project₂
∘AN-homo (e₁ :∘π₁) :⟨ e₂ , e₃ ⟩ = ∘AN-homo e₁ e₂ ○ pushʳ (⟺ project₁)
∘AN-homo (e₁ :∘π₂) :⟨ e₂ , e₃ ⟩ = ∘AN-homo e₁ e₃ ○ pushʳ (⟺ project₂)
∘N-homo : (e₁ : NExpr T U) (e₂ : NExpr S T) → ⟦ e₁ ∘N e₂ ⟧N ≈ ⟦ e₁ ⟧N ∘ ⟦ e₂ ⟧N
∘N-homo :id e₂ = ⟺ identityˡ
∘N-homo :!N e₂ = !-unique _
∘N-homo ⟪ e₁ ⟫ e₂ = ∘AN-homo e₁ e₂
∘N-homo :⟨ e₁ , e₂ ⟩ e₃ = ⟨⟩-cong₂ (∘N-homo e₁ e₃) (∘N-homo e₂ e₃) ○ ⟺ ⟨⟩∘
∘N-homo (∥ f ∥∘ e₁) e₂ = pushʳ (∘N-homo e₁ e₂)
∘π₁N-homo : ∀ (e : NExpr S U) → ⟦ (_∘π₁N {T = T}) e ⟧N ≈ ⟦ e ⟧N ∘ π₁
∘π₁N-homo :id = ⟺ identityˡ
∘π₁N-homo :!N = !-unique _
∘π₁N-homo ⟪ e ⟫ = refl
∘π₁N-homo :⟨ e₁ , e₂ ⟩ = ⟨⟩-cong₂ (∘π₁N-homo e₁) (∘π₁N-homo e₂) ○ ⟺ ⟨⟩∘
∘π₁N-homo (∥ f ∥∘ e) = pushʳ (∘π₁N-homo e)
∘π₂N-homo : ∀ (e : NExpr T U) → ⟦ (_∘π₂N {S = S}) e ⟧N ≈ ⟦ e ⟧N ∘ π₂
∘π₂N-homo :id = ⟺ identityˡ
∘π₂N-homo :!N = !-unique _
∘π₂N-homo ⟪ e ⟫ = refl
∘π₂N-homo :⟨ e₁ , e₂ ⟩ = ⟨⟩-cong₂ (∘π₂N-homo e₁) (∘π₂N-homo e₂) ○ ⟺ ⟨⟩∘
∘π₂N-homo (∥ f ∥∘ e) = pushʳ (∘π₂N-homo e)
private
∘π₁N′ : ∀ S T → NExpr S U → NExpr (S :× T) U
∘π₁N′ _ _ = _∘π₁N
∘π₂N′ : ∀ S T → NExpr T U → NExpr (S :× T) U
∘π₂N′ _ _ = _∘π₂N
π₁N-homo : ∀ S T → ⟦ π₁N S T ⟧N ≈ π₁
π₂N-homo : ∀ S T → ⟦ π₂N S T ⟧N ≈ π₂
π₁N-homo ∥ A ∥ T = refl
π₁N-homo :⊤ T = !-unique _
π₁N-homo (S₁ :× S₂) T = begin
⟨ ⟦ ∘π₁N′ (S₁ :× S₂) T (π₁N S₁ S₂) ⟧N , ⟦ ∘π₁N′ (S₁ :× S₂) T (π₂N S₁ S₂) ⟧N ⟩
≈⟨ ⟨⟩-cong₂ (∘π₁N-homo (π₁N S₁ S₂)) (∘π₁N-homo (π₂N S₁ S₂)) ⟩
⟨ ⟦ π₁N S₁ S₂ ⟧N ∘ π₁ , ⟦ π₂N S₁ S₂ ⟧N ∘ π₁ ⟩
≈˘⟨ ⟨⟩∘ ⟩
⟨ ⟦ π₁N S₁ S₂ ⟧N , ⟦ π₂N S₁ S₂ ⟧N ⟩ ∘ π₁
≈⟨ ⟨⟩-cong₂ (π₁N-homo S₁ S₂) (π₂N-homo S₁ S₂) ⟩∘⟨refl ⟩
⟨ π₁ , π₂ ⟩ ∘ π₁
≈⟨ elimˡ η ⟩
π₁
∎
π₂N-homo S ∥ A ∥ = refl
π₂N-homo S :⊤ = !-unique _
π₂N-homo S (T₁ :× T₂) = begin
⟨ ⟦ ∘π₂N′ S (T₁ :× T₂) (π₁N T₁ T₂) ⟧N , ⟦ ∘π₂N′ S (T₁ :× T₂) (π₂N T₁ T₂) ⟧N ⟩
≈⟨ ⟨⟩-cong₂ (∘π₂N-homo (π₁N T₁ T₂)) (∘π₂N-homo (π₂N T₁ T₂)) ⟩
⟨ ⟦ π₁N T₁ T₂ ⟧N ∘ π₂ , ⟦ π₂N T₁ T₂ ⟧N ∘ π₂ ⟩
≈˘⟨ ⟨⟩∘ ⟩
⟨ ⟦ π₁N T₁ T₂ ⟧N , ⟦ π₂N T₁ T₂ ⟧N ⟩ ∘ π₂
≈⟨ ⟨⟩-cong₂ (π₁N-homo T₁ T₂) (π₂N-homo T₁ T₂) ⟩∘⟨refl ⟩
⟨ π₁ , π₂ ⟩ ∘ π₂
≈⟨ elimˡ η ⟩
π₂
∎
idN-homo : ∀ S → ⟦ idN S ⟧N ≈ id
idN-homo ∥ _ ∥ = refl
idN-homo :⊤ = !-unique id
idN-homo (S₁ :× S₂) = ⟨⟩-cong₂ (π₁N-homo S₁ S₂) (π₂N-homo S₁ S₂) ○ η
correct : ∀ (e : Expr S T) → ⟦ normalise e ⟧N ≈ ⟦ e ⟧
correct {S} :id = idN-homo S
correct (e₁ :∘ e₂) = begin
⟦ normalise e₁ ∘N normalise e₂ ⟧N ≈⟨ ∘N-homo (normalise e₁) (normalise e₂) ⟩
⟦ normalise e₁ ⟧N ∘ ⟦ normalise e₂ ⟧N ≈⟨ correct e₁ ⟩∘⟨ correct e₂ ⟩
⟦ e₁ ⟧ ∘ ⟦ e₂ ⟧ ∎
correct {S :× T} {S} :π₁ = π₁N-homo S T
correct {S :× T} {T} :π₂ = π₂N-homo S T
correct :⟨ e₁ , e₂ ⟩ = ⟨⟩-cong₂ (correct e₁) (correct e₂)
correct ∥ f ∥ = identityʳ
correct ∥ g !∥ = !-unique g
solve : (e₁ e₂ : Expr S T) →
⟦ normalise e₁ ⟧N ≈ ⟦ normalise e₂ ⟧N → ⟦ e₁ ⟧ ≈ ⟦ e₂ ⟧
solve e₁ e₂ eq = begin
⟦ e₁ ⟧ ≈˘⟨ correct e₁ ⟩
⟦ normalise e₁ ⟧N ≈⟨ eq ⟩
⟦ normalise e₂ ⟧N ≈⟨ correct e₂ ⟩
⟦ e₂ ⟧ ∎
-- Combinators
∥-∥ : ∀ {f : A ⇒ B} → Expr ∥ A ∥ ∥ B ∥
∥-∥ {f = f} = ∥ f ∥
:! : Expr ∥ A ∥ :⊤
:! = ∥ ! !∥
:swap : Expr (S :× T) (T :× S)
:swap = :⟨ :π₂ , :π₁ ⟩
:assocˡ : Expr ((S :× T) :× U) (S :× T :× U)
:assocˡ = :⟨ :π₁ :∘ :π₁ , :⟨ :π₂ :∘ :π₁ , :π₂ ⟩ ⟩
:assocʳ : Expr (S :× T :× U) ((S :× T) :× U)
:assocʳ = :⟨ :⟨ :π₁ , :π₁ :∘ :π₂ ⟩ , :π₂ :∘ :π₂ ⟩
infixr 8 _:⁂_
_:⁂_ : Expr S T → Expr U V → Expr (S :× U) (T :× V)
e₁ :⁂ e₂ = :⟨ e₁ :∘ :π₁ , e₂ :∘ :π₂ ⟩
:first : Expr S T → Expr (S :× U) (T :× U)
:first e = e :⁂ :id
:second : Expr T U → Expr (S :× T) (S :× U)
:second e = :id :⁂ e
|
{
"alphanum_fraction": 0.4447558046,
"avg_line_length": 29.1595330739,
"ext": "agda",
"hexsha": "05c33a713222f8574a31b49fe54a123cab297b91",
"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/Categories/Solver/Category/Cartesian.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/Categories/Solver/Category/Cartesian.agda",
"max_line_length": 82,
"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/Categories/Solver/Category/Cartesian.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": 4406,
"size": 7494
}
|
open import Oscar.Prelude
module Oscar.Class.[ExtensibleType] where
record [ExtensibleType]
{𝔵} {𝔛 : Ø 𝔵}
{𝔟} {𝔒₂ : 𝔛 → Ø 𝔟}
{ℓ̇} (_↦_ : ∀ {x} → 𝔒₂ x → 𝔒₂ x → Ø ℓ̇)
: Ø₀ where
constructor ∁
no-eta-equality
|
{
"alphanum_fraction": 0.5676855895,
"avg_line_length": 17.6153846154,
"ext": "agda",
"hexsha": "eb3034c525299c3fc5586f9c74b688421ab62c0b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Class/[ExtensibleType].agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Class/[ExtensibleType].agda",
"max_line_length": 43,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Class/[ExtensibleType].agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 113,
"size": 229
}
|
open import Relation.Binary.Core
module TreeSort.Impl1.Correctness.Permutation {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import BTree {A}
open import Data.List
open import Data.Sum
open import List.Permutation.Base A
open import List.Permutation.Base.Concatenation A
open import List.Permutation.Base.Equivalence A
open import TreeSort.Impl1 _≤_ tot≤
lemma-++∼ : {x : A}{xs ys : List A} → (x ∷ (xs ++ ys)) ∼ (xs ++ (x ∷ ys))
lemma-++∼ {xs = xs} = ∼x /head (lemma++/l {xs = xs} /head) refl∼
lemma-flatten∼ : (x : A) → (t : BTree) → (x ∷ flatten t) ∼ flatten (insert x t)
lemma-flatten∼ x leaf = ∼x /head /head ∼[]
lemma-flatten∼ x (node y l r)
with tot≤ x y
... | inj₁ x≤y = lemma++∼r (lemma-flatten∼ x l)
... | inj₂ y≤x = trans∼ (lemma-++∼ {xs = flatten l}) (lemma++∼l {xs = flatten l} (∼x (/tail /head) /head (lemma-flatten∼ x r)))
theorem-treeSort∼ : (xs : List A) → xs ∼ (flatten (treeSort xs))
theorem-treeSort∼ [] = ∼[]
theorem-treeSort∼ (x ∷ xs) = trans∼ (∼x /head /head (theorem-treeSort∼ xs)) (lemma-flatten∼ x (treeSort xs))
|
{
"alphanum_fraction": 0.6045248869,
"avg_line_length": 34.53125,
"ext": "agda",
"hexsha": "f37837655194338e96ced6a0c43fecb1011e1333",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/TreeSort/Impl1/Correctness/Permutation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/TreeSort/Impl1/Correctness/Permutation.agda",
"max_line_length": 127,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/TreeSort/Impl1/Correctness/Permutation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 413,
"size": 1105
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Basic lemmas showing that various types are related (isomorphic or
-- equivalent or…)
------------------------------------------------------------------------
module Function.Related.TypeIsomorphisms where
open import Algebra
import Algebra.FunctionProperties as FP
import Algebra.Operations
import Algebra.RingSolver.Natural-coefficients
open import Algebra.Structures
open import Data.Empty
open import Data.Nat as Nat using (zero; suc)
open import Data.Product as Prod hiding (swap)
open import Data.Sum as Sum
open import Data.Unit
open import Level hiding (zero; suc)
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence as Eq using (_⇔_; module Equivalence)
open import Function.Inverse as Inv using (_↔_; module Inverse)
open import Function.Related as Related
open import Relation.Binary
open import Relation.Binary.Product.Pointwise
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≗_)
open import Relation.Binary.Sum
open import Relation.Nullary
open import Relation.Nullary.Decidable as Dec using (True)
------------------------------------------------------------------------
-- Σ is "associative"
Σ-assoc : ∀ {a b c}
{A : Set a} {B : A → Set b} {C : (a : A) → B a → Set c} →
Σ (Σ A B) (uncurry C) ↔ Σ A (λ a → Σ (B a) (C a))
Σ-assoc = record
{ to = P.→-to-⟶ λ p →
proj₁ (proj₁ p) , (proj₂ (proj₁ p) , proj₂ p)
; from = P.→-to-⟶ _
; inverse-of = record
{ left-inverse-of = λ _ → P.refl
; right-inverse-of = λ _ → P.refl
}
}
------------------------------------------------------------------------
-- ⊥, ⊤, _×_ and _⊎_ form a commutative semiring
×-CommutativeMonoid : Symmetric-kind → (ℓ : Level) →
CommutativeMonoid _ _
×-CommutativeMonoid k ℓ = record
{ Carrier = Set ℓ
; _≈_ = Related ⌊ k ⌋
; _∙_ = _×_
; ε = Lift ⊤
; isCommutativeMonoid = record
{ isSemigroup = record
{ isEquivalence = Setoid.isEquivalence $ Related.setoid k ℓ
; assoc = λ _ _ _ → ↔⇒ Σ-assoc
; ∙-cong = _×-cong_
}
; identityˡ = λ A → ↔⇒ $ left-identity A
; comm = λ A B → ↔⇒ $ comm A B
}
}
where
open FP _↔_
left-identity : LeftIdentity (Lift {ℓ = ℓ} ⊤) _×_
left-identity _ = record
{ to = P.→-to-⟶ proj₂
; from = P.→-to-⟶ λ y → _ , y
; inverse-of = record
{ left-inverse-of = λ _ → P.refl
; right-inverse-of = λ _ → P.refl
}
}
comm : Commutative _×_
comm _ _ = record
{ to = P.→-to-⟶ Prod.swap
; from = P.→-to-⟶ Prod.swap
; inverse-of = record
{ left-inverse-of = λ _ → P.refl
; right-inverse-of = λ _ → P.refl
}
}
⊎-CommutativeMonoid : Symmetric-kind → (ℓ : Level) →
CommutativeMonoid _ _
⊎-CommutativeMonoid k ℓ = record
{ Carrier = Set ℓ
; _≈_ = Related ⌊ k ⌋
; _∙_ = _⊎_
; ε = Lift ⊥
; isCommutativeMonoid = record
{ isSemigroup = record
{ isEquivalence = Setoid.isEquivalence $ Related.setoid k ℓ
; assoc = λ A B C → ↔⇒ $ assoc A B C
; ∙-cong = _⊎-cong_
}
; identityˡ = λ A → ↔⇒ $ left-identity A
; comm = λ A B → ↔⇒ $ comm A B
}
}
where
open FP _↔_
left-identity : LeftIdentity (Lift ⊥) (_⊎_ {a = ℓ} {b = ℓ})
left-identity A = record
{ to = P.→-to-⟶ [ (λ ()) ∘′ lower , id ]
; from = P.→-to-⟶ inj₂
; inverse-of = record
{ right-inverse-of = λ _ → P.refl
; left-inverse-of = [ ⊥-elim ∘ lower , (λ _ → P.refl) ]
}
}
assoc : Associative _⊎_
assoc A B C = record
{ to = P.→-to-⟶ [ [ inj₁ , inj₂ ∘ inj₁ ] , inj₂ ∘ inj₂ ]
; from = P.→-to-⟶ [ inj₁ ∘ inj₁ , [ inj₁ ∘ inj₂ , inj₂ ] ]
; inverse-of = record
{ left-inverse-of = [ [ (λ _ → P.refl) , (λ _ → P.refl) ] , (λ _ → P.refl) ]
; right-inverse-of = [ (λ _ → P.refl) , [ (λ _ → P.refl) , (λ _ → P.refl) ] ]
}
}
comm : Commutative _⊎_
comm _ _ = record
{ to = P.→-to-⟶ swap
; from = P.→-to-⟶ swap
; inverse-of = record
{ left-inverse-of = inv
; right-inverse-of = inv
}
}
where
swap : {A B : Set ℓ} → A ⊎ B → B ⊎ A
swap = [ inj₂ , inj₁ ]
inv : ∀ {A B} → swap ∘ swap {A} {B} ≗ id
inv = [ (λ _ → P.refl) , (λ _ → P.refl) ]
×⊎-CommutativeSemiring : Symmetric-kind → (ℓ : Level) →
CommutativeSemiring (Level.suc ℓ) ℓ
×⊎-CommutativeSemiring k ℓ = record
{ Carrier = Set ℓ
; _≈_ = Related ⌊ k ⌋
; _+_ = _⊎_
; _*_ = _×_
; 0# = Lift ⊥
; 1# = Lift ⊤
; isCommutativeSemiring = isCommutativeSemiring
}
where
open CommutativeMonoid
open FP _↔_
left-zero : LeftZero (Lift ⊥) (_×_ {a = ℓ} {b = ℓ})
left-zero A = record
{ to = P.→-to-⟶ proj₁
; from = P.→-to-⟶ (⊥-elim ∘′ lower)
; inverse-of = record
{ left-inverse-of = λ p → ⊥-elim (lower $ proj₁ p)
; right-inverse-of = λ x → ⊥-elim (lower x)
}
}
right-distrib : _×_ DistributesOverʳ _⊎_
right-distrib A B C = record
{ to = P.→-to-⟶ $ uncurry [ curry inj₁ , curry inj₂ ]
; from = P.→-to-⟶ from
; inverse-of = record
{ right-inverse-of = [ (λ _ → P.refl) , (λ _ → P.refl) ]
; left-inverse-of =
uncurry [ (λ _ _ → P.refl) , (λ _ _ → P.refl) ]
}
}
where
from : B × A ⊎ C × A → (B ⊎ C) × A
from = [ Prod.map inj₁ id , Prod.map inj₂ id ]
abstract
-- If isCommutativeSemiring is made concrete, then it takes much
-- more time to type-check coefficient-dec (at the time of
-- writing, on a given system, using certain Agda options).
isCommutativeSemiring :
IsCommutativeSemiring
{ℓ = ℓ} (Related ⌊ k ⌋) _⊎_ _×_ (Lift ⊥) (Lift ⊤)
isCommutativeSemiring = record
{ +-isCommutativeMonoid = isCommutativeMonoid $
⊎-CommutativeMonoid k ℓ
; *-isCommutativeMonoid = isCommutativeMonoid $
×-CommutativeMonoid k ℓ
; distribʳ = λ A B C → ↔⇒ $ right-distrib A B C
; zeroˡ = λ A → ↔⇒ $ left-zero A
}
private
-- A decision procedure used by the solver below.
coefficient-dec :
∀ s ℓ →
let open CommutativeSemiring (×⊎-CommutativeSemiring s ℓ)
open Algebra.Operations semiring renaming (_×_ to Times)
in
∀ m n → Dec (Times m 1# ∼[ ⌊ s ⌋ ] Times n 1#)
coefficient-dec equivalence ℓ m n with m | n
... | zero | zero = yes (Eq.equivalence id id)
... | zero | suc _ = no (λ eq → lower (Equivalence.from eq ⟨$⟩ inj₁ _))
... | suc _ | zero = no (λ eq → lower (Equivalence.to eq ⟨$⟩ inj₁ _))
... | suc _ | suc _ = yes (Eq.equivalence (λ _ → inj₁ _) (λ _ → inj₁ _))
coefficient-dec bijection ℓ m n = Dec.map′ to (from m n) (Nat._≟_ m n)
where
open CommutativeSemiring (×⊎-CommutativeSemiring bijection ℓ)
using (1#; semiring)
open Algebra.Operations semiring renaming (_×_ to Times)
to : ∀ {m n} → m ≡ n → Times m 1# ↔ Times n 1#
to {m} P.refl = Times m 1# ∎
where open Related.EquationalReasoning
from : ∀ m n → Times m 1# ↔ Times n 1# → m ≡ n
from zero zero _ = P.refl
from zero (suc n) 0↔+ = ⊥-elim $ lower $ Inverse.from 0↔+ ⟨$⟩ inj₁ _
from (suc m) zero +↔0 = ⊥-elim $ lower $ Inverse.to +↔0 ⟨$⟩ inj₁ _
from (suc m) (suc n) +↔+ = P.cong suc $ from m n (pred↔pred +↔+)
where
open P.≡-Reasoning
↑⊤ : Set ℓ
↑⊤ = Lift ⊤
inj₁≢inj₂ : ∀ {A : Set ℓ} {x : ↑⊤ ⊎ A} {y} →
x ≡ inj₂ y → x ≡ inj₁ _ → ⊥
inj₁≢inj₂ {x = x} {y} eq₁ eq₂ =
P.subst [ const ⊥ , const ⊤ ] (begin
inj₂ y ≡⟨ P.sym eq₁ ⟩
x ≡⟨ eq₂ ⟩
inj₁ _ ∎)
_
g′ : {A B : Set ℓ}
(f : (↑⊤ ⊎ A) ↔ (↑⊤ ⊎ B)) (x : A) (y z : ↑⊤ ⊎ B) →
Inverse.to f ⟨$⟩ inj₂ x ≡ y →
Inverse.to f ⟨$⟩ inj₁ _ ≡ z →
B
g′ _ _ (inj₂ y) _ _ _ = y
g′ _ _ (inj₁ _) (inj₂ z) _ _ = z
g′ f _ (inj₁ _) (inj₁ _) eq₁ eq₂ = ⊥-elim $
inj₁≢inj₂ (Inverse.to-from f eq₁) (Inverse.to-from f eq₂)
g : {A B : Set ℓ} → (↑⊤ ⊎ A) ↔ (↑⊤ ⊎ B) → A → B
g f x = g′ f x _ _ P.refl P.refl
g′∘g′ : ∀ {A B} (f : (↑⊤ ⊎ A) ↔ (↑⊤ ⊎ B))
x y₁ z₁ y₂ z₂ eq₁₁ eq₂₁ eq₁₂ eq₂₂ →
g′ (reverse f) (g′ f x y₁ z₁ eq₁₁ eq₂₁) y₂ z₂ eq₁₂ eq₂₂ ≡
x
g′∘g′ f x (inj₂ y₁) _ (inj₂ y₂) _ eq₁₁ _ eq₁₂ _ =
P.cong [ const y₂ , id ] (begin
inj₂ y₂ ≡⟨ P.sym eq₁₂ ⟩
Inverse.from f ⟨$⟩ inj₂ y₁ ≡⟨ Inverse.to-from f eq₁₁ ⟩
inj₂ x ∎)
g′∘g′ f x (inj₁ _) (inj₂ _) (inj₁ _) (inj₂ z₂) eq₁₁ _ _ eq₂₂ =
P.cong [ const z₂ , id ] (begin
inj₂ z₂ ≡⟨ P.sym eq₂₂ ⟩
Inverse.from f ⟨$⟩ inj₁ _ ≡⟨ Inverse.to-from f eq₁₁ ⟩
inj₂ x ∎)
g′∘g′ f _ (inj₂ y₁) _ (inj₁ _) _ eq₁₁ _ eq₁₂ _ =
⊥-elim $ inj₁≢inj₂ (Inverse.to-from f eq₁₁) eq₁₂
g′∘g′ f _ (inj₁ _) (inj₂ z₁) (inj₂ y₂) _ _ eq₂₁ eq₁₂ _ =
⊥-elim $ inj₁≢inj₂ eq₁₂ (Inverse.to-from f eq₂₁)
g′∘g′ f _ (inj₁ _) (inj₂ _) (inj₁ _) (inj₁ _) eq₁₁ _ _ eq₂₂ =
⊥-elim $ inj₁≢inj₂ (Inverse.to-from f eq₁₁) eq₂₂
g′∘g′ f _ (inj₁ _) (inj₁ _) _ _ eq₁₁ eq₂₁ _ _ =
⊥-elim $ inj₁≢inj₂ (Inverse.to-from f eq₁₁)
(Inverse.to-from f eq₂₁)
g∘g : ∀ {A B} (f : (↑⊤ ⊎ A) ↔ (↑⊤ ⊎ B)) x →
g (reverse f) (g f x) ≡ x
g∘g f x = g′∘g′ f x _ _ _ _ P.refl P.refl P.refl P.refl
pred↔pred : {A B : Set ℓ} → (↑⊤ ⊎ A) ↔ (↑⊤ ⊎ B) → A ↔ B
pred↔pred X⊎↔X⊎ = record
{ to = P.→-to-⟶ $ g X⊎↔X⊎
; from = P.→-to-⟶ $ g (reverse X⊎↔X⊎)
; inverse-of = record
{ left-inverse-of = g∘g X⊎↔X⊎
; right-inverse-of = g∘g (reverse X⊎↔X⊎)
}
}
module Solver s {ℓ} =
Algebra.RingSolver.Natural-coefficients
(×⊎-CommutativeSemiring s ℓ)
(coefficient-dec s ℓ)
private
-- A test of the solver above.
test : (A B C : Set) →
(Lift ⊤ × A × (B ⊎ C)) ↔ (A × B ⊎ C × (Lift ⊥ ⊎ A))
test = solve 3 (λ A B C → con 1 :* (A :* (B :+ C)) :=
A :* B :+ C :* (con 0 :+ A))
Inv.id
where open Solver bijection
------------------------------------------------------------------------
-- Some reordering lemmas
ΠΠ↔ΠΠ : ∀ {a b p} {A : Set a} {B : Set b} (P : A → B → Set p) →
((x : A) (y : B) → P x y) ↔ ((y : B) (x : A) → P x y)
ΠΠ↔ΠΠ _ = record
{ to = P.→-to-⟶ λ f x y → f y x
; from = P.→-to-⟶ λ f y x → f x y
; inverse-of = record
{ left-inverse-of = λ _ → P.refl
; right-inverse-of = λ _ → P.refl
}
}
∃∃↔∃∃ : ∀ {a b p} {A : Set a} {B : Set b} (P : A → B → Set p) →
(∃₂ λ x y → P x y) ↔ (∃₂ λ y x → P x y)
∃∃↔∃∃ {a} {b} {p} _ = record
{ to = P.→-to-⟶ λ p → (proj₁ (proj₂ p) , proj₁ p , proj₂ (proj₂ p))
; from = P.→-to-⟶ λ p → (proj₁ (proj₂ p) , proj₁ p , proj₂ (proj₂ p))
; inverse-of = record
{ left-inverse-of = λ _ → P.refl
; right-inverse-of = λ _ → P.refl
}
}
------------------------------------------------------------------------
-- Implicit and explicit function spaces are isomorphic
Π↔Π : ∀ {a b} {A : Set a} {B : A → Set b} →
((x : A) → B x) ↔ ({x : A} → B x)
Π↔Π = record
{ to = P.→-to-⟶ λ f {x} → f x
; from = P.→-to-⟶ λ f x → f {x}
; inverse-of = record
{ left-inverse-of = λ _ → P.refl
; right-inverse-of = λ _ → P.refl
}
}
------------------------------------------------------------------------
-- _→_ preserves the symmetric relations
_→-cong-⇔_ :
∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
A ⇔ B → C ⇔ D → (A → C) ⇔ (B → D)
A⇔B →-cong-⇔ C⇔D = record
{ to = P.→-to-⟶ λ f x →
Equivalence.to C⇔D ⟨$⟩ f (Equivalence.from A⇔B ⟨$⟩ x)
; from = P.→-to-⟶ λ f x →
Equivalence.from C⇔D ⟨$⟩ f (Equivalence.to A⇔B ⟨$⟩ x)
}
→-cong :
∀ {a b c d} →
P.Extensionality a c → P.Extensionality b d →
∀ {k} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
A ∼[ ⌊ k ⌋ ] B → C ∼[ ⌊ k ⌋ ] D → (A → C) ∼[ ⌊ k ⌋ ] (B → D)
→-cong extAC extBD {equivalence} A⇔B C⇔D = A⇔B →-cong-⇔ C⇔D
→-cong extAC extBD {bijection} A↔B C↔D = record
{ to = Equivalence.to A→C⇔B→D
; from = Equivalence.from A→C⇔B→D
; inverse-of = record
{ left-inverse-of = λ f → extAC λ x → begin
Inverse.from C↔D ⟨$⟩ (Inverse.to C↔D ⟨$⟩
f (Inverse.from A↔B ⟨$⟩ (Inverse.to A↔B ⟨$⟩ x))) ≡⟨ Inverse.left-inverse-of C↔D _ ⟩
f (Inverse.from A↔B ⟨$⟩ (Inverse.to A↔B ⟨$⟩ x)) ≡⟨ P.cong f $ Inverse.left-inverse-of A↔B x ⟩
f x ∎
; right-inverse-of = λ f → extBD λ x → begin
Inverse.to C↔D ⟨$⟩ (Inverse.from C↔D ⟨$⟩
f (Inverse.to A↔B ⟨$⟩ (Inverse.from A↔B ⟨$⟩ x))) ≡⟨ Inverse.right-inverse-of C↔D _ ⟩
f (Inverse.to A↔B ⟨$⟩ (Inverse.from A↔B ⟨$⟩ x)) ≡⟨ P.cong f $ Inverse.right-inverse-of A↔B x ⟩
f x ∎
}
}
where
open P.≡-Reasoning
A→C⇔B→D = ↔⇒ A↔B →-cong-⇔ ↔⇒ C↔D
------------------------------------------------------------------------
-- ¬_ preserves the symmetric relations
¬-cong-⇔ : ∀ {a b} {A : Set a} {B : Set b} →
A ⇔ B → (¬ A) ⇔ (¬ B)
¬-cong-⇔ A⇔B = A⇔B →-cong-⇔ (⊥ ∎)
where open Related.EquationalReasoning
¬-cong : ∀ {a b} →
P.Extensionality a Level.zero →
P.Extensionality b Level.zero →
∀ {k} {A : Set a} {B : Set b} →
A ∼[ ⌊ k ⌋ ] B → (¬ A) ∼[ ⌊ k ⌋ ] (¬ B)
¬-cong extA extB A≈B = →-cong extA extB A≈B (⊥ ∎)
where open Related.EquationalReasoning
------------------------------------------------------------------------
-- _⇔_ preserves _⇔_
-- The type of the following proof is a bit more general.
Related-cong :
∀ {k a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
A ∼[ ⌊ k ⌋ ] B → C ∼[ ⌊ k ⌋ ] D → (A ∼[ ⌊ k ⌋ ] C) ⇔ (B ∼[ ⌊ k ⌋ ] D)
Related-cong {A = A} {B} {C} {D} A≈B C≈D =
Eq.equivalence (λ A≈C → B ∼⟨ sym A≈B ⟩
A ∼⟨ A≈C ⟩
C ∼⟨ C≈D ⟩
D ∎)
(λ B≈D → A ∼⟨ A≈B ⟩
B ∼⟨ B≈D ⟩
D ∼⟨ sym C≈D ⟩
C ∎)
where open Related.EquationalReasoning
------------------------------------------------------------------------
-- A lemma relating True dec and P, where dec : Dec P
True↔ : ∀ {p} {P : Set p}
(dec : Dec P) → ((p₁ p₂ : P) → p₁ ≡ p₂) → True dec ↔ P
True↔ (yes p) irr = record
{ to = P.→-to-⟶ (λ _ → p)
; from = P.→-to-⟶ (λ _ → _)
; inverse-of = record
{ left-inverse-of = λ _ → P.refl
; right-inverse-of = irr p
}
}
True↔ (no ¬p) _ = record
{ to = P.→-to-⟶ (λ ())
; from = P.→-to-⟶ (λ p → ¬p p)
; inverse-of = record
{ left-inverse-of = λ ()
; right-inverse-of = λ p → ⊥-elim (¬p p)
}
}
------------------------------------------------------------------------
-- Equality between pairs can be expressed as a pair of equalities
Σ-≡,≡↔≡ : ∀ {a b} {A : Set a} {B : A → Set b} {p₁ p₂ : Σ A B} →
(∃ λ (p : proj₁ p₁ ≡ proj₁ p₂) →
P.subst B p (proj₂ p₁) ≡ proj₂ p₂) ↔
(p₁ ≡ p₂)
Σ-≡,≡↔≡ {A = A} {B} = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ from
; inverse-of = record
{ left-inverse-of = left-inverse-of
; right-inverse-of = right-inverse-of
}
}
where
to : {p₁ p₂ : Σ A B} →
Σ (proj₁ p₁ ≡ proj₁ p₂)
(λ p → P.subst B p (proj₂ p₁) ≡ proj₂ p₂) →
p₁ ≡ p₂
to (P.refl , P.refl) = P.refl
from : {p₁ p₂ : Σ A B} →
p₁ ≡ p₂ →
Σ (proj₁ p₁ ≡ proj₁ p₂)
(λ p → P.subst B p (proj₂ p₁) ≡ proj₂ p₂)
from P.refl = P.refl , P.refl
left-inverse-of : {p₁ p₂ : Σ A B}
(p : Σ (proj₁ p₁ ≡ proj₁ p₂)
(λ x → P.subst B x (proj₂ p₁) ≡ proj₂ p₂)) →
from (to p) ≡ p
left-inverse-of (P.refl , P.refl) = P.refl
right-inverse-of : {p₁ p₂ : Σ A B} (p : p₁ ≡ p₂) → to (from p) ≡ p
right-inverse-of P.refl = P.refl
×-≡,≡↔≡ : ∀ {a b} {A : Set a} {B : Set b} {p₁ p₂ : A × B} →
(proj₁ p₁ ≡ proj₁ p₂ × proj₂ p₁ ≡ proj₂ p₂) ↔
p₁ ≡ p₂
×-≡,≡↔≡ {A = A} {B} = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ from
; inverse-of = record
{ left-inverse-of = left-inverse-of
; right-inverse-of = right-inverse-of
}
}
where
to : {p₁ p₂ : A × B} →
(proj₁ p₁ ≡ proj₁ p₂) × (proj₂ p₁ ≡ proj₂ p₂) → p₁ ≡ p₂
to (P.refl , P.refl) = P.refl
from : {p₁ p₂ : A × B} → p₁ ≡ p₂ →
(proj₁ p₁ ≡ proj₁ p₂) × (proj₂ p₁ ≡ proj₂ p₂)
from P.refl = P.refl , P.refl
left-inverse-of : {p₁ p₂ : A × B} →
(p : (proj₁ p₁ ≡ proj₁ p₂) × (proj₂ p₁ ≡ proj₂ p₂)) →
from (to p) ≡ p
left-inverse-of (P.refl , P.refl) = P.refl
right-inverse-of : {p₁ p₂ : A × B} (p : p₁ ≡ p₂) → to (from p) ≡ p
right-inverse-of P.refl = P.refl
|
{
"alphanum_fraction": 0.4523446758,
"avg_line_length": 34.2104247104,
"ext": "agda",
"hexsha": "c4e3b652d4bc17a93c3af88b2ccac627cfb4ea0d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Function/Related/TypeIsomorphisms.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Function/Related/TypeIsomorphisms.agda",
"max_line_length": 106,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Function/Related/TypeIsomorphisms.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 6948,
"size": 17721
}
|
-- Andreas, 2013-10-24 Bug reported to me by Christoph-Simon Senjak
module Issue924 where
open import Level
open import Data.Empty
open import Data.Product
open import Data.Sum
open import Data.Bool
open import Data.Maybe.Base
import Data.Nat as ℕ
open import Data.Nat using (ℕ)
import Data.Nat.Divisibility as ℕ
import Data.Nat.Properties as ℕ
open import Data.Nat.DivMod
import Data.Fin as F
open import Data.Fin using (Fin)
import Data.Fin.Properties as F
import Data.List as L
open import Data.List using (List)
open import Data.Vec
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Algebra
open import Algebra.Structures
Byte : Set
Byte = Fin 256
infixr 8 _^_
_^_ : ℕ → ℕ → ℕ
_ ^ 0 = 1
n ^ (ℕ.suc m) = n ℕ.* (n ^ m)
BitVecToNat : {n : ℕ} → Vec Bool n → ℕ
BitVecToNat [] = 0
BitVecToNat (true ∷ r) = ℕ.suc (2 ℕ.* (BitVecToNat r))
BitVecToNat (false ∷ r) = (2 ℕ.* (BitVecToNat r))
postulate ≤lem₁ : {a b : ℕ} → (a ℕ.< b) → (2 ℕ.* a) ℕ.< (2 ℕ.* b)
postulate ≤lem₂ : {a b : ℕ} → (a ℕ.< (ℕ.suc b)) → (ℕ.suc (2 ℕ.* a)) ℕ.< (2 ℕ.* (ℕ.suc b))
postulate ≤lem₃ : {a b c : ℕ} → (c ℕ.+ (a ℕ.* 2) ℕ.< (2 ℕ.* b)) → a ℕ.< b
¬0<b∧0≡b : {b : ℕ} → 0 ℕ.< b → 0 ≡ b → ⊥
¬0<b∧0≡b {0} () 0≡b
¬0<b∧0≡b {ℕ.suc n} 0<b ()
0<a∧0<b→0<ab : (a b : ℕ) → (0 ℕ.< a) → (0 ℕ.< b) → (0 ℕ.< (a ℕ.* b))
0<a∧0<b→0<ab a b 0<a 0<b with 1 ℕ.≤? (a ℕ.* b)
... | yes y = y
... | no n with (a ℕ.* b) | inspect (λ x → a ℕ.* x) b
... | ℕ.suc ns | _ = ⊥-elim (n (ℕ.s≤s (ℕ.z≤n {ns})))
... | 0 | [ eq ] with ℕ.m*n≡0⇒m≡0∨n≡0 a {b} eq
... | inj₁ a≡0 = ⊥-elim (¬0<b∧0≡b 0<a (sym a≡0))
... | inj₂ b≡0 = ⊥-elim (¬0<b∧0≡b 0<b (sym b≡0))
0<s^b : {a b : ℕ} → (0 ℕ.< ((ℕ.suc a) ^ b))
0<s^b {_} {0} = ℕ.s≤s ℕ.z≤n
0<s^b {m} {ℕ.suc n} = 0<a∧0<b→0<ab (ℕ.suc m) ((ℕ.suc m) ^ n) (ℕ.s≤s ℕ.z≤n) (0<s^b {m} {n})
<-lemma : (b : ℕ) → (0 ℕ.< b) → ∃ λ a → ℕ.suc a ≡ b
<-lemma (ℕ.suc b) (ℕ.s≤s (ℕ.z≤n {.b})) = ( b , refl )
2^lem₁ : (a : ℕ) → ∃ λ b → (ℕ.suc b) ≡ (2 ^ a)
2^lem₁ a = <-lemma (2 ^ a) (0<s^b {1} {a})
BitVecToNatLemma : {n : ℕ} → (s : Vec Bool n) → ((BitVecToNat s) ℕ.< (2 ^ n))
BitVecToNatLemma {0} [] = ℕ.s≤s ℕ.z≤n
BitVecToNatLemma {ℕ.suc n} (false ∷ r) = ≤lem₁ (BitVecToNatLemma r)
BitVecToNatLemma {ℕ.suc n} (true ∷ r) = ret₃ where
q = 2^lem₁ n
t = proj₁ q
s : (ℕ.suc t) ≡ 2 ^ n
s = proj₂ q
ret₁ : (BitVecToNat r) ℕ.< (ℕ.suc t)
ret₁ = subst (λ u → (BitVecToNat r) ℕ.< u) (sym s) (BitVecToNatLemma r)
ret₂ : (ℕ.suc (2 ℕ.* (BitVecToNat r))) ℕ.< (2 ℕ.* (ℕ.suc t))
ret₂ = ≤lem₂ ret₁
ret₃ : (ℕ.suc (2 ℕ.* (BitVecToNat r))) ℕ.< (2 ^ (ℕ.suc n))
ret₃ = subst (λ u → (ℕ.suc (2 ℕ.* (BitVecToNat r))) ℕ.< (2 ℕ.* u)) s ret₂
BitVecToFin : {n : ℕ} → Vec Bool n → Fin (2 ^ n)
BitVecToFin s = F.fromℕ< (BitVecToNatLemma s)
FinToBitVec : {n : ℕ} → (m : Fin (2 ^ n)) → ∃ λ (s : Vec Bool n) → (BitVecToFin s ≡ m)
FinToBitVec {0} F.zero = ( [] , refl )
FinToBitVec {0} (F.suc ())
FinToBitVec {ℕ.suc n} k = ( ret₁ , lem₇ ) where
open CommutativeSemiring ℕ.+-*-commutativeSemiring using (*-comm)
kn = F.toℕ k
p2^n' = 2^lem₁ (ℕ.suc n)
p2^n = proj₁ p2^n'
p2^nl : ℕ.suc p2^n ≡ 2 ^ (ℕ.suc n)
p2^nl = proj₂ p2^n'
kn<2^n : kn ℕ.< 2 ^ (ℕ.suc n)
kn<2^n = subst (λ d → kn ℕ.< d) p2^nl (subst (λ d → kn ℕ.< ℕ.suc (ℕ.pred d)) (sym p2^nl) (ℕ.s≤s (F.toℕ≤pred[n] k)))
dm = kn divMod 2
quot = DivMod.quotient dm
rem = F.toℕ (DivMod.remainder dm)
Fin2toBool : Fin 2 → Bool
Fin2toBool F.zero = false
Fin2toBool (F.suc F.zero) = true
Fin2toBool (F.suc (F.suc ()))
zl = 2^lem₁ n
lem₀ : rem ℕ.+ quot ℕ.* 2 ℕ.< (2 ^ (ℕ.suc n))
lem₀ = subst (λ d → d ℕ.< (2 ^ (ℕ.suc n))) (DivMod.property dm) kn<2^n
lem₁ : (DivMod.quotient dm) ℕ.< (2 ^ n)
lem₁ = ≤lem₃ {a = quot} {b = 2 ^ n} {c = rem} lem₀
fQuot : Fin (2 ^ n)
fQuot = F.fromℕ< lem₁
-- the recursive call
prevRet : ∃ λ (s : Vec Bool n) → (BitVecToFin s ≡ fQuot)
prevRet = FinToBitVec (F.fromℕ< lem₁)
prevRetEq : (BitVecToFin (proj₁ prevRet) ≡ fQuot)
prevRetEq = proj₂ prevRet
lem₉ : {n : ℕ} → (r : Vec Bool n) → F.toℕ (BitVecToFin r) ≡ (BitVecToNat r)
lem₉ r = trans (cong F.toℕ refl) (F.toℕ-fromℕ< (BitVecToNatLemma r))
prevRetEqℕ : quot ≡ BitVecToNat (proj₁ prevRet)
prevRetEqℕ = trans (trans (sym (F.toℕ-fromℕ< lem₁)) (cong F.toℕ (sym prevRetEq))) (lem₉ (proj₁ prevRet))
ret₁ = (Fin2toBool (DivMod.remainder dm)) ∷ (proj₁ prevRet)
lem₃ : (r : Fin 2) → (BitVecToNat ((Fin2toBool r) ∷ (proj₁ prevRet))) ≡ (F.toℕ r) ℕ.+ (2 ℕ.* (BitVecToNat (proj₁ prevRet)))
lem₃ F.zero = refl
lem₃ (F.suc F.zero) = refl
lem₃ (F.suc (F.suc ()))
lem₅ : rem ℕ.+ (2 ℕ.* (BitVecToNat (proj₁ prevRet))) ≡ kn
lem₅ = subst (λ d → rem ℕ.+ d ≡ kn) (*-comm (BitVecToNat (proj₁ prevRet)) 2)
(subst (λ d → rem ℕ.+ d ℕ.* 2 ≡ kn) prevRetEqℕ (sym (DivMod.property dm)))
lem₆ : (BitVecToNat ret₁) ≡ kn
lem₆ =
begin
BitVecToNat ret₁
≡⟨ lem₃ (DivMod.remainder dm) ⟩
rem ℕ.+ (2 ℕ.* (BitVecToNat (proj₁ prevRet)))
≡⟨ lem₅ ⟩
kn
∎
-- lem₆ = trans lem₄ lem₅
lem₈ : kn ≡ F.toℕ (F.fromℕ< kn<2^n)
lem₈ = sym (cong F.toℕ (F.fromℕ<-toℕ k kn<2^n))
lem₇ : (BitVecToFin ret₁) ≡ k
lem₇ = trans (F.toℕ-injective (trans (lem₉ ret₁) (trans lem₆ lem₈))) (F.fromℕ<-toℕ k kn<2^n)
record ByteStream : Set where
constructor bs
field
cBit : Maybe (∃ λ (c : Fin 8) → Vec Bool (ℕ.suc (F.toℕ c)))
str : List Byte
property : (cBit ≡ nothing) → (str ≡ L.[])
byteStreamFromList : List Byte → ByteStream
byteStreamFromList L.[] = bs nothing
L.[]
(λ _ → refl)
byteStreamFromList (a L.∷ x) = bs (just ((F.fromℕ 7) , (proj₁ (FinToBitVec a))))
x
(λ ())
-- Problem WAS:
-- Normalization in unifyConArgs went berserk when checking this
-- absurd lambda. Fixed by more cautious normalization in unifier.
|
{
"alphanum_fraction": 0.5411283729,
"avg_line_length": 31.0406091371,
"ext": "agda",
"hexsha": "4783bec8f89864f8d32c69b2254dcae770bafff0",
"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/LibSucceed/Issue924.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/LibSucceed/Issue924.agda",
"max_line_length": 125,
"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/LibSucceed/Issue924.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2649,
"size": 6115
}
|
module Cats.Category.Constructions.Exponential where
open import Level
open import Cats.Category.Base
open import Cats.Category.Constructions.Product as Product using
(HasBinaryProducts)
open import Cats.Util.Conv
import Cats.Category.Constructions.Unique as Unique
module Build {lo la l≈}
(Cat : Category lo la l≈)
{{hasBinaryProducts : HasBinaryProducts Cat}}
where
open Category Cat
open ≈-Reasoning
open Unique.Build Cat
open HasBinaryProducts hasBinaryProducts
record Exp (B C : Obj) : Set (lo ⊔ la ⊔ l≈) where
field
Cᴮ : Obj
eval : Cᴮ × B ⇒ C
curry′ : ∀ {A} (f : A × B ⇒ C)
→ ∃![ f̃ ∈ A ⇒ Cᴮ ] (eval ∘ ⟨ f̃ × id ⟩ ≈ f)
curry : ∀ {A} → A × B ⇒ C → A ⇒ Cᴮ
curry f = curry′ f ⃗
eval-curry : ∀ {A} {f : A × B ⇒ C}
→ eval ∘ ⟨ curry f × id ⟩ ≈ f
eval-curry {f = f} = ∃!′.prop (curry′ f)
curry-unique : ∀ {A} {f : A × B ⇒ C} {g}
→ eval ∘ ⟨ g × id ⟩ ≈ f
→ curry f ≈ g
curry-unique {f = f} = ∃!′.unique (curry′ f)
uncurry : ∀ {A} → A ⇒ Cᴮ → A × B ⇒ C
uncurry f = eval ∘ ⟨ f × id ⟩
curry∘uncurry : ∀ {A} {f : A ⇒ Cᴮ}
→ curry (uncurry f) ≈ f
curry∘uncurry = curry-unique ≈.refl
uncurry∘curry : ∀ {A} {f : A × B ⇒ C}
→ uncurry (curry f) ≈ f
uncurry∘curry = eval-curry
instance HasObj-Exp : ∀ {B C} → HasObj (Exp B C) lo la l≈
HasObj-Exp = record { Cat = Cat ; _ᴼ = Exp.Cᴮ }
open Exp public
curry∘curry : ∀ {A B C Y Z} (Cᴮ : Exp B C) (Yᶻ : Exp Y Z)
→ {f : Cᴮ ᴼ × Y ⇒ Z} {g : A × B ⇒ C}
→ curry Yᶻ f ∘ curry Cᴮ g ≈ curry Yᶻ (f ∘ ⟨ curry Cᴮ g × id ⟩)
curry∘curry Cᴮ Yᶻ {f} {g} = ≈.sym (curry-unique Yᶻ (
begin
eval Yᶻ ∘ ⟨ curry Yᶻ f ∘ curry Cᴮ g × id ⟩
≈⟨ ∘-resp-r (⟨×⟩-resp ≈.refl (≈.sym id-l)) ⟩
eval Yᶻ ∘ ⟨ curry Yᶻ f ∘ curry Cᴮ g × id ∘ id ⟩
≈⟨ ∘-resp-r (≈.sym ⟨×⟩-∘) ⟩
eval Yᶻ ∘ ⟨ curry Yᶻ f × id ⟩ ∘ ⟨ curry Cᴮ g × id ⟩
≈⟨ unassoc ⟩
(eval Yᶻ ∘ ⟨ curry Yᶻ f × id ⟩) ∘ ⟨ curry Cᴮ g × id ⟩
≈⟨ ∘-resp-l (eval-curry Yᶻ) ⟩
f ∘ ⟨ curry Cᴮ g × id ⟩
∎
))
record HasExponentials {lo la l≈}
(Cat : Category lo la l≈)
: Set (lo ⊔ la ⊔ l≈)
where
private open module Bld = Build Cat using (Exp)
open Category Cat
open Unique.Build Cat
infixr 1 _↝′_ _↝_
field
{{hasBinaryProducts}} : HasBinaryProducts Cat
_↝′_ : ∀ B C → Exp B C
open HasBinaryProducts hasBinaryProducts
_↝_ : Obj → Obj → Obj
B ↝ C = (B ↝′ C) ᴼ
eval : ∀ {B C} → (B ↝ C) × B ⇒ C
eval {B} {C} = Bld.eval (B ↝′ C)
curry : ∀ {A B C} → A × B ⇒ C → A ⇒ B ↝ C
curry {B = B} {C} f = Bld.curry (B ↝′ C) f
uncurry : ∀ {A B C} → A ⇒ B ↝ C → A × B ⇒ C
uncurry {B = B} {C} = Bld.uncurry (B ↝′ C)
eval-curry : ∀ {A B C} {f : A × B ⇒ C}
→ eval ∘ ⟨ curry f × id ⟩ ≈ f
eval-curry {B = B} {C} = Bld.eval-curry (B ↝′ C)
curry∘uncurry : ∀ {A B C} {f : A ⇒ B ↝ C}
→ curry (uncurry f) ≈ f
curry∘uncurry {B = B} {C} = Bld.curry∘uncurry (B ↝′ C)
uncurry∘curry : ∀ {A B C} {f : A × B ⇒ C}
→ uncurry (curry f) ≈ f
uncurry∘curry {B = B} {C} = Bld.uncurry∘curry (B ↝′ C)
curry∘curry : ∀ {A B C Y Z}
→ {f : (B ↝ C) × Y ⇒ Z} {g : A × B ⇒ C}
→ curry f ∘ curry g ≈ curry (f ∘ ⟨ curry g × id ⟩)
curry∘curry {B = B} {C} {Y} {Z} = Bld.curry∘curry (B ↝′ C) (Y ↝′ Z)
|
{
"alphanum_fraction": 0.5031559964,
"avg_line_length": 24.1086956522,
"ext": "agda",
"hexsha": "f72014abd17dcbdc16ea0adcd257c5f4efffd442",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Category/Constructions/Exponential.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Category/Constructions/Exponential.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Category/Constructions/Exponential.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1518,
"size": 3327
}
|
open import Prelude
module Implicits.Resolution.Termination.SizeMeasures where
open import Induction.WellFounded
open import Induction.Nat
open import Data.Product hiding (map)
open import Data.Nat.Base using (_<′_)
open import Data.Fin hiding (_+_; _≤_; _<_; _≤?_)
open import Data.List hiding (map)
open import Data.List.All
open import Implicits.Syntax
open import Implicits.Syntax.Type.Unification
open import Data.Nat hiding (_<_)
open import Data.Nat.Properties
-- a strict sizemeasure for types
||_|| : ∀ {ν} → Type ν → ℕ
|| simpl (tc x) || = 1
|| simpl (tvar n) || = 1
|| simpl (a →' b) || = 1 + || a || + || b ||
|| a ⇒ b || = 1 + || a || + || b ||
|| ∀' a || = 1 + || a ||
-- size of the head of a type
h||_|| : ∀ {ν} → Type ν → ℕ
h|| a || = || proj₂ (a ◁) ||
-- type measure on metatypes
m||_|| : ∀ {m ν} → MetaType m ν → ℕ
m|| simpl (tc x) || = 1
m|| simpl (tvar n) || = 1
m|| simpl (mvar n) || = 1
m|| simpl (a →' b) || = suc (m|| a || + m|| b ||)
m|| a ⇒ b || = 1 + (m|| a || + m|| b ||)
m|| ∀' a || = 1 + m|| a ||
-- We package Type with it's deBruijn counter because
-- we need to express orderings such as a sρ< ∀' a
-- where the number of free variables varies.
-- We could express that as ∀ {ν μ} → Type ν → Type μ → Set,
-- but Well-founded _sρ<_ unifies ν and μ,
-- such that the well-founded proof would be too narrow
_hρ≤_ : (a b : ∃ Type) → Set
(_ , a) hρ≤ (_ , b) = h|| a || ≤ h|| b ||
_hρ<_ : (a b : ∃ Type) → Set
(_ , a) hρ< (_ , b) = h|| a || < h|| b ||
_hρ<?_ : ∀ {ν μ} → (a : Type ν) → (b : Type μ) → Dec ((ν , a) hρ< (μ , b))
a hρ<? b with h|| a || | h|| b ||
a hρ<? b | y | z = (suc y) ≤? z
_ρ<_ : ∃ Type → ∃ Type → Set
(_ , a) ρ< (_ , b) = || a || < || b ||
_ρ<?_ : (a b : ∃ Type) → Dec (a ρ< b)
(_ , a) ρ<? (_ , b) with || a || | || b ||
(_ , a) ρ<? (_ , b) | y | z = (suc y) ≤? z
_m<_ : ∃₂ MetaType → ∃₂ MetaType → Set
(_ , _ , a) m< (_ , _ , b) = m|| a || < m|| b ||
_occ[_]<_ : ∀ {ν μ} (a : Type ν) (x : ℕ) (b : Type μ) → Set
a occ[ x ]< b = (occ x (proj₂ (a ◁))) ≤ (occ x (proj₂ (b ◁)))
-- oliveira's termination condition on types
data ⊢term {ν} : (Type ν) → Set where
term-simp : ∀ {τ} → ⊢term (simpl τ)
term-tabs : ∀ {a} → ⊢term a → ⊢term (∀' a)
term-iabs : ∀ {a b} → ⊢term a → ⊢term b → (, a) hρ< (, b) →
All (λ x → a occ[ toℕ x ]< b) (fvars a ++ fvars b) →
⊢term (a ⇒ b)
|
{
"alphanum_fraction": 0.5065650148,
"avg_line_length": 31.9054054054,
"ext": "agda",
"hexsha": "e5d2fd28e7c261b9f3becb69a64d5f74db3069f7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Termination/SizeMeasures.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Termination/SizeMeasures.agda",
"max_line_length": 74,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Termination/SizeMeasures.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 951,
"size": 2361
}
|
{-
This file contains:
- Properties of set truncations
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.SetTruncation.Properties where
open import Cubical.HITs.SetTruncation.Base
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
private
variable
ℓ : Level
A B C D : Type ℓ
rec : isSet B → (A → B) → ∥ A ∥₂ → B
rec Bset f ∣ x ∣₂ = f x
rec Bset f (squash₂ x y p q i j) =
Bset _ _ (cong (rec Bset f) p) (cong (rec Bset f) q) i j
-- lemma 6.9.1 in HoTT book
elim : {B : ∥ A ∥₂ → Type ℓ}
(Bset : (x : ∥ A ∥₂) → isSet (B x))
(g : (a : A) → B (∣ a ∣₂))
(x : ∥ A ∥₂) → B x
elim Bset g ∣ a ∣₂ = g a
elim Bset g (squash₂ x y p q i j) =
isOfHLevel→isOfHLevelDep 2 Bset _ _
(cong (elim Bset g) p) (cong (elim Bset g) q) (squash₂ x y p q) i j
setTruncUniversal : isSet B → (∥ A ∥₂ → B) ≃ (A → B)
setTruncUniversal {B = B} Bset =
isoToEquiv (iso (λ h x → h ∣ x ∣₂) (rec Bset) (λ _ → refl) rinv)
where
rinv : (f : ∥ A ∥₂ → B) → rec Bset (λ x → f ∣ x ∣₂) ≡ f
rinv f i x =
elim (λ x → isProp→isSet (Bset (rec Bset (λ x → f ∣ x ∣₂) x) (f x)))
(λ _ → refl) x i
elim2 : {B : ∥ A ∥₂ → ∥ A ∥₂ → Type ℓ}
(Bset : ((x y : ∥ A ∥₂) → isSet (B x y)))
(g : (a b : A) → B ∣ a ∣₂ ∣ b ∣₂)
(x y : ∥ A ∥₂) → B x y
elim2 Bset g = elim (λ _ → isSetΠ (λ _ → Bset _ _))
(λ a → elim (λ _ → Bset _ _) (g a))
elim3 : {B : (x y z : ∥ A ∥₂) → Type ℓ}
(Bset : ((x y z : ∥ A ∥₂) → isSet (B x y z)))
(g : (a b c : A) → B ∣ a ∣₂ ∣ b ∣₂ ∣ c ∣₂)
(x y z : ∥ A ∥₂) → B x y z
elim3 Bset g = elim2 (λ _ _ → isSetΠ (λ _ → Bset _ _ _))
(λ a b → elim (λ _ → Bset _ _ _) (g a b))
setTruncIsSet : isSet ∥ A ∥₂
setTruncIsSet a b p q = squash₂ a b p q
setTruncIdempotent≃ : isSet A → ∥ A ∥₂ ≃ A
setTruncIdempotent≃ {A = A} hA = isoToEquiv f
where
f : Iso ∥ A ∥₂ A
Iso.fun f = rec hA (idfun A)
Iso.inv f x = ∣ x ∣₂
Iso.rightInv f _ = refl
Iso.leftInv f = elim (λ _ → isSet→isGroupoid setTruncIsSet _ _) (λ _ → refl)
setTruncIdempotent : isSet A → ∥ A ∥₂ ≡ A
setTruncIdempotent hA = ua (setTruncIdempotent≃ hA)
isContr→isContrSetTrunc : isContr A → isContr (∥ A ∥₂)
isContr→isContrSetTrunc contr = ∣ fst contr ∣₂
, elim (λ _ → isOfHLevelPath 2 (setTruncIsSet) _ _)
λ a → cong ∣_∣₂ (snd contr a)
setTruncIso : Iso A B → Iso ∥ A ∥₂ ∥ B ∥₂
Iso.fun (setTruncIso is) = rec setTruncIsSet (λ x → ∣ Iso.fun is x ∣₂)
Iso.inv (setTruncIso is) = rec setTruncIsSet (λ x → ∣ Iso.inv is x ∣₂)
Iso.rightInv (setTruncIso is) =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ a → cong ∣_∣₂ (Iso.rightInv is a)
Iso.leftInv (setTruncIso is) =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ a → cong ∣_∣₂ (Iso.leftInv is a)
setSigmaIso : ∀ {ℓ} {B : A → Type ℓ} → Iso ∥ Σ A B ∥₂ ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂
setSigmaIso {A = A} {B = B} = iso fun funinv sect retr
where
{- writing it out explicitly to avoid yellow highlighting -}
fun : ∥ Σ A B ∥₂ → ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂
fun = rec setTruncIsSet λ {(a , p) → ∣ a , ∣ p ∣₂ ∣₂}
funinv : ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ → ∥ Σ A B ∥₂
funinv = rec setTruncIsSet (λ {(a , p) → rec setTruncIsSet (λ p → ∣ a , p ∣₂) p})
sect : section fun funinv
sect = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ { (a , p) → elim {B = λ p → fun (funinv ∣ a , p ∣₂) ≡ ∣ a , p ∣₂}
(λ p → isOfHLevelPath 2 setTruncIsSet _ _) (λ _ → refl) p }
retr : retract fun funinv
retr = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ { _ → refl }
sigmaElim : ∀ {ℓ ℓ'} {B : ∥ A ∥₂ → Type ℓ} {C : Σ ∥ A ∥₂ B → Type ℓ'}
(Bset : (x : Σ ∥ A ∥₂ B) → isSet (C x))
(g : (a : A) (b : B ∣ a ∣₂) → C (∣ a ∣₂ , b))
(x : Σ ∥ A ∥₂ B) → C x
sigmaElim {B = B} {C = C} set g (x , y) = elim {B = λ x → (y : B x) → C (x , y)}
(λ _ → isOfHLevelΠ 2 λ _ → set (_ , _))
g x y
sigmaProdElim : ∀ {ℓ ℓ'} {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ} {D : Σ (∥ A ∥₂ × ∥ B ∥₂) C → Type ℓ'}
(Bset : (x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → isSet (D x))
(g : (a : A) (b : B) (c : C (∣ a ∣₂ , ∣ b ∣₂)) → D ((∣ a ∣₂ , ∣ b ∣₂) , c))
(x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → D x
sigmaProdElim {B = B} {C = C} {D = D} set g ((x , y) , c) =
elim {B = λ x → (y : ∥ B ∥₂) (c : C (x , y)) → D ((x , y) , c)}
(λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelΠ 2 λ _ → set _)
(λ x → elim (λ _ → isOfHLevelΠ 2 λ _ → set _)
λ y c → g x y c)
x y c
prodElim : ∀ {ℓ} {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ}
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) → isOfHLevel 2 (C x))
→ ((a : A) (b : B) → C (∣ a ∣₂ , ∣ b ∣₂))
→ (x : ∥ A ∥₂ × ∥ B ∥₂) → C x
prodElim {A = A} {B = B} {C = C} hlevel ind (a , b) = schonf a b
where
schonf : (a : ∥ A ∥₂) (b : ∥ B ∥₂) → C (a , b)
schonf = elim (λ x → isOfHLevelΠ 2 λ y → hlevel (_ , _)) λ a → elim (λ x → hlevel (_ , _))
λ b → ind a b
prodElim2 : ∀ {ℓ} {E : (∥ A ∥₂ × ∥ B ∥₂) → (∥ C ∥₂ × ∥ D ∥₂) → Type ℓ}
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → isOfHLevel 2 (E x y))
→ ((a : A) (b : B) (c : C) (d : D) → E (∣ a ∣₂ , ∣ b ∣₂) (∣ c ∣₂ , ∣ d ∣₂))
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → (E x y))
prodElim2 isset f = prodElim (λ _ → isOfHLevelΠ 2 λ _ → isset _ _)
λ a b → prodElim (λ _ → isset _ _)
λ c d → f a b c d
setTruncOfProdIso : Iso ∥ A × B ∥₂ (∥ A ∥₂ × ∥ B ∥₂)
Iso.fun setTruncOfProdIso = rec (isOfHLevelΣ 2 setTruncIsSet (λ _ → setTruncIsSet)) λ { (a , b) → ∣ a ∣₂ , ∣ b ∣₂ }
Iso.inv setTruncOfProdIso = prodElim (λ _ → setTruncIsSet) λ a b → ∣ a , b ∣₂
Iso.rightInv setTruncOfProdIso =
prodElim (λ _ → isOfHLevelPath 2 (isOfHLevelΣ 2 setTruncIsSet (λ _ → setTruncIsSet)) _ _)
λ _ _ → refl
Iso.leftInv setTruncOfProdIso =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ {(a , b) → refl}
|
{
"alphanum_fraction": 0.4895701643,
"avg_line_length": 39.7987421384,
"ext": "agda",
"hexsha": "746652321c7c440d54cccf392ffba6b013b3b787",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "knrafto/cubical",
"max_forks_repo_path": "Cubical/HITs/SetTruncation/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "knrafto/cubical",
"max_issues_repo_path": "Cubical/HITs/SetTruncation/Properties.agda",
"max_line_length": 115,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "knrafto/cubical",
"max_stars_repo_path": "Cubical/HITs/SetTruncation/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2827,
"size": 6328
}
|
{-# OPTIONS --cubical --safe --no-import-sorts #-}
module Cubical.HITs.Delooping.Two.Properties where
open import Cubical.Functions.Involution
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.Data.Bool
open import Cubical.Data.Empty
open import Cubical.Data.Unit
open import Cubical.HITs.Delooping.Two.Base
open import Cubical.HITs.PropositionalTruncation
private
variable
ℓ : Level
module Embed where
isSetIsPropDep : isOfHLevelDep {ℓ' = ℓ} 1 isSet
isSetIsPropDep = isOfHLevel→isOfHLevelDep 1 (λ _ → isPropIsSet)
notSet : PathP (λ i → isSet (notEq i)) isSetBool isSetBool
notSet = isSetIsPropDep isSetBool isSetBool notEq
notNot² : Square notEq refl refl notEq
notNot² = involPath² notnot
notNotSet
: SquareP (λ i j → isSet (notNot² i j)) notSet refl refl notSet
notNotSet = isPropDep→isSetDep'
isSetIsPropDep
(involPath² notnot)
notSet refl refl notSet
Code : Bℤ₂ → hSet ℓ-zero
Code = Elim.rec
(Bool , isSetBool)
(λ i → notEq i , notSet i)
(λ i j → λ where
.fst → notNot² i j
.snd → notNotSet i j)
(isOfHLevelTypeOfHLevel 2)
El : Bℤ₂ → Type₀
El b = Code b .fst
module BINARY where
open import Cubical.Data.FinSet.Binary.Large
sem : Bℤ₂ → Binary _
sem = Elim.rec Base Loop Loop² isGroupoidBinary
loop? : Bool → base ≡ base
loop? false = refl
loop? true = loop
Loop²-coh : (a b c : Bool) → Type₀
Loop²-coh false false false = Unit
Loop²-coh false true true = Unit
Loop²-coh true false true = Unit
Loop²-coh true true false = Unit
Loop²-coh _ _ _ = ⊥
rf : Bool ≡ Bool → Bool
rf P = transport P false
Loop²-coh-lemma₀
: ∀(p q r : Bool)
→ r ⊕ p ≡ q
→ Loop²-coh p q r
Loop²-coh-lemma₀ false false false sq = _
Loop²-coh-lemma₀ false true true sq = _
Loop²-coh-lemma₀ true false true sq = _
Loop²-coh-lemma₀ true true false sq = _
Loop²-coh-lemma₀ false true false = false≢true
Loop²-coh-lemma₀ false false true = true≢false
Loop²-coh-lemma₀ true false false = true≢false
Loop²-coh-lemma₀ true true true = false≢true
Loop²-coh-lemma
: ∀(P Q R : Bool ≡ Bool)
→ Square P Q refl R
→ Loop²-coh (rf P) (rf Q) (rf R)
Loop²-coh-lemma P Q R sq = Loop²-coh-lemma₀ p q r eqn
where
p = rf P
q = rf Q
r = rf R
open BoolReflection
cmp : P ∙ R ≡ Q
cmp i j
= hcomp (λ k → λ where
(i = i0) → compPath-filler P R k j
(i = i1) → Q j
(j = i0) → Bool
(j = i1) → R (i ∨ k))
(sq i j)
rcmp : ⊕-Path (r ⊕ p) ≡ ⊕-Path q
rcmp = ⊕-Path (r ⊕ p)
≡[ i ]⟨ ⊕-comp p r (~ i) ⟩
⊕-Path p ∙ ⊕-Path r
≡[ i ]⟨ ⊕-complete P (~ i) ∙ ⊕-complete R (~ i) ⟩
P ∙ R
≡⟨ cmp ⟩
Q
≡⟨ ⊕-complete Q ⟩
⊕-Path q ∎
open Iso
eqn : r ⊕ p ≡ q
eqn = transport (λ i →
reflectIso .leftInv (r ⊕ p) i ≡ reflectIso .leftInv q i)
(cong (reflectIso .inv) rcmp)
loop²?
: ∀ p q r → Loop²-coh p q r
→ Square (loop? p) (loop? q) refl (loop? r)
loop²? false false false _ = refl
loop²? false true true _ = λ i j → loop (i ∧ j)
loop²? true false true _ = loop²
loop²? true true false _ = refl
module _ (B : Type₀) where
based : (P : Bool ≃ B) → Bℤ₂
based _ = base
pull₀ : (P Q : Bool ≃ B) → Bool ≡ Bool
pull₀ P Q i
= hcomp (λ k → λ where
(i = i0) → ua P (~ k)
(i = i1) → ua Q (~ k))
B
pull₁ : (P Q : Bool ≃ B) → Square (ua P) (ua Q) (pull₀ P Q) refl
pull₁ P Q i j
= hcomp (λ k → λ where
(i = i0) → ua P (~ k ∨ j)
(i = i1) → ua Q (~ k ∨ j)
(j = i1) → B)
B
pull₂
: (P Q R : Bool ≃ B)
→ Square (pull₀ P Q) (pull₀ P R) refl (pull₀ Q R)
pull₂ P Q R i j
= hcomp (λ k → λ where
(j = i0) → ua P (~ k)
(i = i0) (j = i1) → ua Q (~ k)
(i = i1) (j = i1) → ua R (~ k))
B
pull₃
: (P Q R : Bool ≃ B)
→ Cube (pull₁ P Q) (pull₁ P R)
(λ _ → ua P) (pull₁ Q R)
(pull₂ P Q R) (λ _ _ → B)
pull₃ P Q R i j k
= hcomp (λ τ → λ where
(j = i0) → ua P (~ τ ∨ k)
(i = i0) (j = i1) → ua Q (~ τ ∨ k)
(i = i1) (j = i1) → ua R (~ τ ∨ k)
(k = i1) → B)
B
looped : (P Q : Bool ≃ B) → based P ≡ based Q
looped P Q = loop? b
where
b : Bool
b = rf (pull₀ P Q)
looped²
: (P Q R : Bool ≃ B)
→ Square (looped P Q) (looped P R) refl (looped Q R)
looped² P Q R = loop²? pq pr qr pqr
where
pq = rf (pull₀ P Q)
pr = rf (pull₀ P R)
qr = rf (pull₀ Q R)
pqr : Loop²-coh pq pr qr
pqr = Loop²-coh-lemma (pull₀ P Q) (pull₀ P R) (pull₀ Q R) (pull₂ P Q R)
syn : Binary _ → Bℤ₂
syn (B , tP) = rec→Gpd trunc (based B) 3k tP
where
open 3-Constant
3k : 3-Constant (based B)
3k .link = looped B
3k .coh₁ = looped² B
|
{
"alphanum_fraction": 0.5374034294,
"avg_line_length": 26.6683417085,
"ext": "agda",
"hexsha": "4cfe24f5c55b060949fba0c82238ec6b9109476e",
"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": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/HITs/Delooping/Two/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"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": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/HITs/Delooping/Two/Properties.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/HITs/Delooping/Two/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2005,
"size": 5307
}
|
----------------------------------------------------------------------
-- A monad with partiality and failure
----------------------------------------------------------------------
module PartialityAndFailure where
open import Category.Monad
open import Codata.Musical.Notation
open import Category.Monad.Partiality as Partiality using (_⊥)
open import Data.Maybe as Maybe using (Maybe; just; nothing; maybe)
open import Data.Maybe.Categorical as MaybeC using ()
open import Level using (_⊔_)
open import Function
open import Relation.Binary as B hiding (Rel)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
------------------------------------------------------------------------
-- Danielsson's partiality-and-failure monad.
-- The definitions below are slightly modified versions of those given
-- in the code accompanying Danielsson's ICFP'12 paper "Operational
-- Semantics Using the Partiality Monad". The original version along
-- with additional explanations can be found at
--
-- http://www.cse.chalmers.se/~nad/publications/danielsson-semantics-partiality-monad.html
_?⊥ : ∀ {a} → Set a → Set a
A ?⊥ = Maybe A ⊥
monad : ∀ {f} → RawMonad {f = f} (_⊥ ∘ Maybe)
monad = MaybeC.monadT Partiality.monad
private module M {f} = RawMonad (monad {f})
-- Re-export constructors and kinds of relations.
open Partiality public
using (now; later; Kind; OtherKind; geq; weak; strong; other)
-- Failure.
private
-- This module encapsulates fail so we can define/overload it as a
-- constructor of _?⊥P and RelP in the Workaround and
-- AlternativeEquality modules below. Its definitions will be
-- re-exported at the global scope later.
module Failure {a} where
fail : ∀ {A : Set a} → A ?⊥
fail = now nothing
infix 7 _or-fail
_or-fail : ∀ {A B : Set a} → (A → B ?⊥) → Maybe A → B ?⊥
f or-fail = maybe f fail
------------------------------------------------------------------------
-- Equality/ordering
-- The default equality for the partiality monad (bisimilarity)
-- specialized to include failure and with the underlying equality
-- fixed to "syntactic" equality (_≡_).
module Equality {a} {A : Set a} where
open M using (_>>=_)
private module E = Partiality.Equality (_≡_ {A = Maybe A})
open E public using (now; later; laterʳ; laterˡ)
infix 4 _≅_ _≳_ _≲_ _≈_
-- The three relations specialized to include failure and with the
-- underlying equality fixed to "syntactic" equality (_≡_).
Rel : Kind → A ?⊥ → A ?⊥ → Set _
Rel k x y = E.Rel k x y
_≅_ = Rel strong
_≳_ = Rel (other geq)
_≲_ = flip _≳_
_≈_ = Rel (other weak)
fail : ∀ {k} → Rel k (Failure.fail) (Failure.fail)
fail = now P.refl
------------------------------------------------------------------------
-- The (specialized) relations are equivalences or partial orders
-- for the chosen underlying "syntactic" equality (_≡_)
module Equivalence {a} {A : Set a} where
open Partiality.Equivalence {A = Maybe A} {_∼_ = _≡_} public
-- Equational reasoning with the underlying equality fixed to
-- "syntactic" equality (_≡_).
module Reasoning {a} {A : Set a} where
open Partiality.Reasoning (P.isEquivalence {A = Maybe A}) public
------------------------------------------------------------------------
-- Laws related to bind
module _ {a} {A B : Set a} where
open Failure
open Equality
open M using (_>>=_)
infixl 1 _>>=-cong_
-- Bind preserves all the relations.
_>>=-cong_ : ∀ {k} {x₁ x₂} {f₁ f₂ : A → B ?⊥} →
Rel k x₁ x₂ → (∀ x → Rel k (f₁ x) (f₂ x)) →
Rel k (x₁ >>= f₁) (x₂ >>= f₂)
_>>=-cong_ {k} {f₁ = f₁} {f₂} x₁≈x₂ f₁≈f₂ =
x₁≈x₂ Partiality.>>=-cong helper
where
helper : ∀ {x y} → x ≡ y → Rel k ((f₁ or-fail) x) ((f₂ or-fail) y)
helper {x = nothing} P.refl = now P.refl
helper {x = just x} P.refl = f₁≈f₂ x
------------------------------------------------------------------------
-- Productivity checker workaround
-- Just like the partiality monad, the partiality-and-fail monad
-- suffers from the limitations of guarded coinduction. Luckily there
-- is a (limited) workaround for this problem, namely to extend the
-- datatype _?⊥ with a _>>=_ constructor, yielding an embedded
-- language _?⊥P (of _?⊥ "programs") which internalizes the monadic
-- bind operation. When writing corecursive functions in _?⊥P, one
-- may use _>>=_ without guarding it with other constructors. By
-- interpreting the resulting programs in _?⊥, one recovers the
-- desired corecursive function. For details, see e.g. Danielsson's
-- PAR'10 paper "Beating the Productivity Checker Using Embedded
-- Languages".
module Workaround {a} where
private module W = Partiality.Workaround {a}
infixl 1 _>>=_
-- The language of _?⊥ "programs" internalizing _>>=_.
data _?⊥P : Set a → Set (Level.suc a) where
return : ∀ {A} (x : A) → A ?⊥P
later : ∀ {A} (x : ∞ (A ?⊥P)) → A ?⊥P
fail : ∀ {A} → A ?⊥P
_>>=_ : ∀ {A B} (x : A ?⊥P) (f : A → B ?⊥P) → B ?⊥P
private
mutual
-- Translation of _?⊥ programs to _⊥ programs.
⟦_⟧P′ : ∀ {A} → A ?⊥P → (Maybe A) W.⊥P
⟦ return x ⟧P′ = W.now (just x)
⟦ later x ⟧P′ = W.later (♯ ⟦ (♭ x) ⟧P′)
⟦ fail ⟧P′ = W.now nothing
⟦ _>>=_ {A} {B} x f ⟧P′ = ⟦ x ⟧P′ W.>>= ⟦>>=⟧-helper f
⟦>>=⟧-helper : ∀ {A B : Set a} → (A → B ?⊥P) → Maybe A → (Maybe B) W.⊥P
⟦>>=⟧-helper f (just y) = ⟦ f y ⟧P′
⟦>>=⟧-helper _ nothing = W.now nothing
-- Interpretation of _?⊥ programs in _?⊥.
⟦_⟧P : ∀ {A} → A ?⊥P → A ?⊥
⟦_⟧P = W.⟦_⟧P ∘ ⟦_⟧P′
-- The definitions above make sense. ⟦_⟧P is homomorphic with
-- respect to now, later, fail and _>>=_.
module Correct where
open Equality {a} hiding (fail)
open Reasoning {a}
private
module F = Failure {a}
module PM {f} = RawMonad (Partiality.monad {f})
return-hom : ∀ {A} (x : A) → ⟦ return x ⟧P ≅ M.return x
return-hom x = M.return x ∎
later-hom : ∀ {A} (x : ∞ (A ?⊥P)) → ⟦ later x ⟧P ≅ later (♯ ⟦ ♭ x ⟧P)
later-hom x = later (♯ (⟦ ♭ x ⟧P ∎) )
fail-hom : ∀ {A} → ⟦ fail {A} ⟧P ≅ F.fail {A}
fail-hom {A} = F.fail {A} ∎
>>=-hom : ∀ {A B} (x : A ?⊥P) (f : A → B ?⊥P) →
⟦ x >>= f ⟧P ≅ (⟦ x ⟧P M.>>= λ y → ⟦ f y ⟧P)
>>=-hom {A} {B} x f =
W.⟦ ⟦ x ⟧P′ W.>>= (⟦>>=⟧-helper f) ⟧P
≅⟨ W.Correct.>>=-hom ⟦ x ⟧P′ _ ⟩
(⟦ x ⟧P PM.>>= λ y → W.⟦ ⟦>>=⟧-helper f y ⟧P)
≅⟨ (⟦ x ⟧P ∎) Partiality.≡->>=-cong helper ⟩
(⟦ x ⟧P PM.>>= maybe (⟦_⟧P ∘ f) F.fail)
∎
where
helper : ∀ y → W.⟦ ⟦>>=⟧-helper f y ⟧P ≅ maybe (⟦_⟧P ∘ f) F.fail y
helper (just y) = ⟦ f y ⟧P ∎
helper nothing = F.fail ∎
------------------------------------------------------------------------
-- An alternative, but equivalent, formulation of equality/ordering
-- This version of equality works around some limitations of guarded
-- corecursion and is therefore easier to use in corecursive proofs.
-- However, it does not admit unrestricted use of transitivity. For a
-- discussion of the technique and the related issues, see e.g.
--
-- * "Operational Semantics Using the Partiality Monad", Danielsson,
-- ICFP'12
--
-- * "Beating the Productivity Checker Using Embedded Languages",
-- Danielsson, PAR'10
--
-- * "Subtyping, Declaratively -- An Exercise in Mixed Induction and
-- Coinduction", Danielsson and Altenkirch, MPC'10
--
-- All of the above can be found at
-- http://www.cse.chalmers.se/~nad/publications/
module AlternativeEquality {a} where
open Equality {a} hiding (fail)
private
open module F = Failure {a} hiding (fail)
module AE = Partiality.AlternativeEquality {a}
mutual
-- Proof "programs" with the underlying equality fixed to
-- "syntactic" equality (_≡_) and extended to include failure.
infix 4 _≅P_ _≳P_ _≈P_
infix 3 _∎
infixr 2 _≡⟨_⟩_ _≅⟨_⟩_ _≳⟨_⟩_ _≳⟨_⟩≅_ _≳⟨_⟩≈_ _≈⟨_⟩≅_ _≈⟨_⟩≲_
infixl 1 _>>=_
_≅P_ : ∀ {A} → B.Rel (A ?⊥) _
_≅P_ = RelP strong
_≳P_ : ∀ {A} → B.Rel (A ?⊥) _
_≳P_ = RelP (other geq)
_≈P_ : ∀ {A} → B.Rel (A ?⊥) _
_≈P_ = RelP (other weak)
data RelP {A : Set a} : Kind → B.Rel (A ?⊥) (Level.suc a) where
-- Congruences.
return : ∀ {k x y} (x≡y : x ≡ y) →
RelP k (M.return x) (M.return y)
later : ∀ {k x y} (x∼y : ∞ (RelP k (♭ x) (♭ y))) →
RelP k (later x) (later y)
fail : ∀ {k} → RelP k (F.fail) (F.fail)
_>>=_ : ∀ {B : Set a} {k x₁ x₂} {f₁ f₂ : B → A ?⊥} →
let open M in
(x₁≡x₂ : RelP k x₁ x₂)
(f₁∼f₂ : ∀ x → RelP k (f₁ x) (f₂ x)) →
RelP k (x₁ >>= f₁) (x₂ >>= f₂)
-- Ordering/weak equality.
laterʳ : ∀ {x y} (x≈y : RelP (other weak) x (♭ y)) →
RelP (other weak) x (later y)
laterˡ : ∀ {k x y} (x∼y : RelP (other k) (♭ x) y) →
RelP (other k) (later x) y
-- Equational reasoning. Note that including full transitivity
-- for weak equality would make _≈P_ trivial; a similar problem
-- applies to _≳P_ (never ≳P return x would be
-- provable). Instead the definition of RelP includes limited
-- notions of transitivity, similar to weak bisimulation up-to
-- various things.
_∎ : ∀ {k} x → RelP k x x
sym : ∀ {k x y} {eq : Partiality.Equality k} (x∼y : RelP k x y) →
RelP k y x
_≡⟨_⟩_ : ∀ {k} x {y z} (x≡y : x ≡ y) (y∼z : RelP k y z) → RelP k x z
_≅⟨_⟩_ : ∀ {k} x {y z} (x≅y : x ≅P y) (y∼z : RelP k y z) → RelP k x z
_≳⟨_⟩_ : ∀ x {y z} (x≳y : x ≳ y) (y≳z : y ≳P z) → x ≳P z
_≳⟨_⟩≅_ : ∀ x {y z} (x≳y : x ≳P y) (y≅z : y ≅P z) → x ≳P z
_≳⟨_⟩≈_ : ∀ x {y z} (x≳y : x ≳P y) (y≈z : y ≈P z) → x ≈P z
_≈⟨_⟩≅_ : ∀ x {y z} (x≈y : x ≈P y) (y≅z : y ≅P z) → x ≈P z
_≈⟨_⟩≲_ : ∀ x {y z} (x≈y : x ≈P y) (y≲z : z ≳P y) → x ≈P z
-- If any of the following transitivity-like rules were added to
-- RelP, then RelP and Rel would no longer be equivalent:
--
-- x ≳P y → y ≳P z → x ≳P z
-- x ≳P y → y ≳ z → x ≳P z
-- x ≲P y → y ≈P z → x ≈P z
-- x ≈P y → y ≳P z → x ≈P z
-- x ≲ y → y ≈P z → x ≈P z
-- x ≈P y → y ≳ z → x ≈P z
-- x ≈P y → y ≈P z → x ≈P z
-- x ≈P y → y ≈ z → x ≈P z
-- x ≈ y → y ≈P z → x ≈P z
--
-- The reason is that any of these rules would make it possible
-- to derive that never and now x are related.
-- RelP is complete with respect to Rel.
complete : ∀ {A k} {x y : A ?⊥} → Rel k x y → RelP k x y
complete {x = now (just x)} {now (just .x)} (now P.refl) = return P.refl
complete {x = now (just x)} {now nothing} (now ())
complete {x = now nothing} {now (just _)} (now ())
complete {x = now nothing} {now nothing} (now P.refl) = fail
complete (later x∼y) = later (♯ complete (♭ x∼y))
complete (laterʳ x≈y) = laterʳ (complete x≈y)
complete (laterˡ x∼y) = laterˡ (complete x∼y)
private
AE-RelP : ∀ {A : Set a} → Kind → B.Rel (A ?⊥) _
AE-RelP {A} = AE.RelP (P.setoid (Maybe A))
-- RelP is sound with respect to the alternative equality of the
-- partiality monad.
sound′ : ∀ {A k} {x y : A ?⊥} → RelP k x y → AE-RelP k x y
sound′ (return x≡y) = AE.now (P.cong just x≡y)
sound′ (later x∼y) = AE.later (♯ sound′ (♭ x∼y))
sound′ fail = AE.now P.refl
sound′ {A} {k} (_>>=_ {B} {f₁ = f₁} {f₂} x f₁∼f₂) =
sound′ x AE.>>= helper
where
helper : ∀ {x y} → x ≡ y → AE-RelP k ((f₁ or-fail) x) ((f₂ or-fail) y)
helper {x = nothing} P.refl = AE.now P.refl
helper {x = just x} P.refl = sound′ (f₁∼f₂ x)
sound′ (laterʳ x) = AE.laterʳ (sound′ x)
sound′ (laterˡ x) = AE.laterˡ (sound′ x)
sound′ (x ∎) = x AE.∎
sound′ (sym {eq = eq} x) = AE.sym {eq = eq} (sound′ x)
sound′ (x ≡⟨ x≡y ⟩ y≡z) = AE._≡⟨_⟩_ x x≡y (sound′ y≡z)
sound′ (x ≅⟨ x≅y ⟩ y≅z) = AE._≅⟨_⟩_ x (sound′ x≅y) (sound′ y≅z)
sound′ (x ≳⟨ x≳y ⟩ y≳z) = AE._≳⟨_⟩_ x x≳y (sound′ y≳z)
sound′ (x ≳⟨ x≳y ⟩≅ y≅z) = AE._≳⟨_⟩≅_ x (sound′ x≳y) (sound′ y≅z)
sound′ (x ≳⟨ x≳y ⟩≈ y≈z) = AE._≳⟨_⟩≈_ x (sound′ x≳y) (sound′ y≈z)
sound′ (x ≈⟨ x≈y ⟩≅ y≅z) = AE._≈⟨_⟩≅_ x (sound′ x≈y) (sound′ y≅z)
sound′ (x ≈⟨ x≈y ⟩≲ y≲z) = AE._≈⟨_⟩≲_ x (sound′ x≈y) (sound′ y≲z)
-- RelP is sound with respect to Rel.
sound : ∀ {A k} {x y : A ?⊥} → RelP k x y → Rel k x y
sound = AE.sound ∘ sound′
open Failure public
|
{
"alphanum_fraction": 0.5231908024,
"avg_line_length": 37.1315789474,
"ext": "agda",
"hexsha": "5fb75ce6ac6d538e01717d0967c9c89241d3ea12",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-07-06T23:12:48.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-29T12:24:46.000Z",
"max_forks_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sstucki/system-f-agda",
"max_forks_repo_path": "src/PartialityAndFailure.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T19:23:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-05-30T06:43:04.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "sstucki/system-f-agda",
"max_issues_repo_path": "src/PartialityAndFailure.agda",
"max_line_length": 92,
"max_stars_count": 68,
"max_stars_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "sstucki/system-f-agda",
"max_stars_repo_path": "src/PartialityAndFailure.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-01T01:25:16.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-26T13:12:56.000Z",
"num_tokens": 4876,
"size": 12699
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Reflexive closures
------------------------------------------------------------------------
module Data.ReflexiveClosure where
open import Data.Unit
open import Level
open import Relation.Binary
open import Relation.Binary.Simple
------------------------------------------------------------------------
-- Reflexive closure
data Refl {a ℓ} {A : Set a} (_∼_ : Rel A ℓ) : Rel A (a ⊔ ℓ) where
[_] : ∀ {x y} (x∼y : x ∼ y) → Refl _∼_ x y
refl : Reflexive (Refl _∼_)
-- Map.
map : ∀ {a a′ ℓ ℓ′} {A : Set a} {A′ : Set a′}
{_R_ : Rel A ℓ} {_R′_ : Rel A′ ℓ′} {f : A → A′} →
_R_ =[ f ]⇒ _R′_ → Refl _R_ =[ f ]⇒ Refl _R′_
map R⇒R′ [ xRy ] = [ R⇒R′ xRy ]
map R⇒R′ refl = refl
-- The reflexive closure has no effect on reflexive relations.
drop-refl : ∀ {a ℓ} {A : Set a} {_R_ : Rel A ℓ} →
Reflexive _R_ → Refl _R_ ⇒ _R_
drop-refl rfl [ x∼y ] = x∼y
drop-refl rfl refl = rfl
------------------------------------------------------------------------
-- Example: Maybe
module Maybe where
Maybe : ∀ {ℓ} → Set ℓ → Set ℓ
Maybe A = Refl (Const A) tt tt
nothing : ∀ {a} {A : Set a} → Maybe A
nothing = refl
just : ∀ {a} {A : Set a} → A → Maybe A
just = [_]
|
{
"alphanum_fraction": 0.4360153257,
"avg_line_length": 26.6326530612,
"ext": "agda",
"hexsha": "cf121753fec7977155f9c7881f31a6f36cbc3a29",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/ReflexiveClosure.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/ReflexiveClosure.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/ReflexiveClosure.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 430,
"size": 1305
}
|
{-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-}
{-
Kan extension of a functor C → D to a functor PreShv C ℓ → PreShv D ℓ left or right adjoint to
precomposition.
-}
module Cubical.Categories.Presheaf.KanExtension where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Functions.FunExtEquiv
open import Cubical.HITs.SetQuotients
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.NaturalTransformation
open import Cubical.Categories.Adjoint
open import Cubical.Categories.Presheaf.Base
open import Cubical.Categories.Instances.Functors
open import Cubical.Categories.Instances.Sets
{-
Left Kan extension of a functor C → D to a functor PreShv C ℓ → PreShv D ℓ left adjoint to precomposition.
-}
module Lan {ℓC ℓC' ℓD ℓD'} ℓS
{C : Precategory ℓC ℓC'} {D : Precategory ℓD ℓD'}
(F : Functor C D)
where
open Functor
open NatTrans
private
module C = Precategory C
module D = Precategory D
{-
We want the category SET ℓ we're mapping into to be large enough that the coend will take presheaves
Cᵒᵖ → Set ℓ to presheaves Dᵒᵖ → Set ℓ, otherwise we get no adjunction with precomposition.
So we must have ℓC,ℓC',ℓD' ≤ ℓ; the parameter ℓS allows ℓ to be larger than their maximum.
-}
ℓ = ℓ-max (ℓ-max (ℓ-max ℓC ℓC') ℓD') ℓS
module _ (G : Functor (C ^op) (SET ℓ)) where
-- Definition of the coend
module _ (d : D.ob) where
Raw : Type ℓ
Raw = Σ[ c ∈ C.ob ] Σ[ g ∈ D.Hom[ d , F ⟅ c ⟆ ] ] G .F-ob c .fst
data _≈_ : (u v : Raw) → Type ℓ where
shift : {c c' : C.ob} (g : D.Hom[ d , F ⟅ c ⟆ ]) (f : C.Hom[ c , c' ]) (a : (G ⟅ c' ⟆) .fst)
→ (c' , (g D.⋆ F ⟪ f ⟫) , a) ≈ (c , g , (G ⟪ f ⟫) a)
Quo = Raw / _≈_
pattern shift/ g f a i = eq/ _ _ (shift g f a) i
-- Action of Quo on arrows in D
mapR : {d d' : D.ob} (h : D.Hom[ d' , d ]) → Quo d → Quo d'
mapR h [ c , g , a ] = [ c , h D.⋆ g , a ]
mapR h (shift/ g f a i) =
hcomp
(λ j → λ
{ (i = i0) → [ _ , D.⋆Assoc h g (F ⟪ f ⟫) j , a ]
; (i = i1) → [ _ , h D.⋆ g , (G ⟪ f ⟫) a ]
})
(shift/ (h D.⋆ g) f a i)
mapR h (squash/ t u p q i j) =
squash/ (mapR h t) (mapR h u) (cong (mapR h) p) (cong (mapR h) q) i j
mapRId : (d : D.ob) → mapR (D.id d) ≡ (idfun _)
mapRId d =
funExt (elimProp (λ _ → squash/ _ _) (λ (c , g , a) i → [ c , D.⋆IdL g i , a ]))
mapR∘ : {d d' d'' : D.ob}
(h' : D.Hom[ d'' , d' ]) (h : D.Hom[ d' , d ])
→ mapR (h' D.⋆ h) ≡ mapR h' ∘ mapR h
mapR∘ h' h =
funExt (elimProp (λ _ → squash/ _ _) (λ (c , g , a) i → [ c , D.⋆Assoc h' h g i , a ]))
LanOb : Functor (C ^op) (SET ℓ) → Functor (D ^op) (SET _)
LanOb G .F-ob d .fst = Quo G d
LanOb G .F-ob d .snd = squash/
LanOb G .F-hom = mapR G
LanOb G .F-id {d} = mapRId G d
LanOb G .F-seq h h' = mapR∘ G h' h
-- Action of Quo on arrows in Cᵒᵖ → Set
module _ {G G' : Functor (C ^op) (SET ℓ)} (α : NatTrans G G') where
mapL : (d : D.ob) → Quo G d → Quo G' d
mapL d [ c , g , a ] = [ c , g , α .N-ob c a ]
mapL d (shift/ g f a i) =
hcomp
(λ j → λ
{ (i = i0) → [ _ , (g D.⋆ F ⟪ f ⟫) , α .N-ob _ a ]
; (i = i1) → [ _ , g , funExt⁻ (α .N-hom f) a (~ j) ]
})
(shift/ g f ((α ⟦ _ ⟧) a) i)
mapL d (squash/ t u p q i j) =
squash/ (mapL d t) (mapL d u) (cong (mapL d) p) (cong (mapL d) q) i j
mapLR : {d d' : D.ob} (h : D.Hom[ d' , d ])
→ mapL d' ∘ mapR G h ≡ mapR G' h ∘ mapL d
mapLR h = funExt (elimProp (λ _ → squash/ _ _) (λ _ → refl))
mapLId : (G : Functor (C ^op) (SET ℓ))
(d : D.ob) → mapL (idTrans G) d ≡ idfun (Quo G d)
mapLId G d = funExt (elimProp (λ _ → squash/ _ _) (λ _ → refl))
mapL∘ : {G G' G'' : Functor (C ^op) (SET ℓ)}
(β : NatTrans G' G'') (α : NatTrans G G')
(d : D.ob) → mapL (seqTrans α β) d ≡ mapL β d ∘ mapL α d
mapL∘ β α d = funExt (elimProp (λ _ → squash/ _ _) (λ _ → refl))
LanHom : {G G' : Functor (C ^op) (SET ℓ)}
→ NatTrans G G' → NatTrans (LanOb G) (LanOb G')
LanHom α .N-ob = mapL α
LanHom α .N-hom = mapLR α
-- Definition of the left Kan extension functor
Lan : Functor (FUNCTOR (C ^op) (SET ℓ)) (FUNCTOR (D ^op) (SET ℓ))
Lan .F-ob = LanOb
Lan .F-hom = LanHom
Lan .F-id {G} = makeNatTransPath (funExt (mapLId G))
Lan .F-seq α β = makeNatTransPath (funExt (mapL∘ β α))
-- Adjunction between the left Kan extension and precomposition
private
F* = precomposeF (SET ℓ) (F ^opF)
open UnitCounit
η : 𝟙⟨ FUNCTOR (C ^op) (SET ℓ) ⟩ ⇒ funcComp F* Lan
η .N-ob G .N-ob c a = [ c , D.id _ , a ]
η .N-ob G .N-hom {c'} {c} f =
funExt λ a →
[ c , D.id _ , (G ⟪ f ⟫) a ]
≡⟨ sym (shift/ (D.id _) f a) ⟩
[ c' , ((D.id _) D.⋆ F ⟪ f ⟫) , a ]
≡[ i ]⟨ [ c' , lem i , a ] ⟩
[ c' , (F ⟪ f ⟫ D.⋆ (D.id _)) , a ]
∎
where
lem : (D.id _) D.⋆ F ⟪ f ⟫ ≡ F ⟪ f ⟫ D.⋆ (D.id _)
lem = D.⋆IdL (F ⟪ f ⟫) ∙ sym (D.⋆IdR (F ⟪ f ⟫))
η .N-hom f = makeNatTransPath refl
ε : funcComp Lan F* ⇒ 𝟙⟨ FUNCTOR (D ^op) (SET ℓ) ⟩
ε .N-ob H .N-ob d =
elim
(λ _ → (H ⟅ d ⟆) .snd)
(λ (c , g , a) → (H ⟪ g ⟫) a)
(λ {_ _ (shift g f a) i → H .F-seq (F ⟪ f ⟫) g i a})
ε .N-ob H .N-hom g' =
funExt (elimProp (λ _ → (H ⟅ _ ⟆) .snd _ _) (λ (c , g , a) → funExt⁻ (H .F-seq g g') a))
ε .N-hom {H} {H'} α =
makeNatTransPath
(funExt₂ λ d →
elimProp (λ _ → (H' ⟅ _ ⟆) .snd _ _)
(λ (c , g , a) → sym (funExt⁻ (α .N-hom g) a)))
Δ₁ : ∀ G → seqTrans (Lan ⟪ η ⟦ G ⟧ ⟫) (ε ⟦ Lan ⟅ G ⟆ ⟧) ≡ idTrans _
Δ₁ G =
makeNatTransPath
(funExt₂ λ d →
elimProp (λ _ → squash/ _ _)
(λ (c , g , a) →
[ c , g D.⋆ D.id _ , a ]
≡[ i ]⟨ [ c , (g D.⋆ F .F-id (~ i)) , a ] ⟩
[ c , g D.⋆ (F ⟪ C.id _ ⟫) , a ]
≡⟨ shift/ g (C.id _) a ⟩
[ c , g , (G ⟪ C.id _ ⟫) a ]
≡[ i ]⟨ [ c , g , G .F-id i a ] ⟩
[ c , g , a ]
∎))
Δ₂ : ∀ H → seqTrans (η ⟦ F* ⟅ H ⟆ ⟧) (F* ⟪ ε ⟦ H ⟧ ⟫) ≡ idTrans _
Δ₂ H = makeNatTransPath (funExt λ c → H .F-id)
adj : Lan ⊣ F*
adj = make⊣ η ε Δ₁ Δ₂
{-
Right Kan extension of a functor C → D to a functor PreShv C ℓ → PreShv D ℓ right adjoint to precomposition.
-}
module Ran {ℓC ℓC' ℓD ℓD'} ℓS
{C : Precategory ℓC ℓC'} {D : Precategory ℓD ℓD'}
(F : Functor C D)
where
open Functor
open NatTrans
private
module C = Precategory C
module D = Precategory D
{-
We want the category SET ℓ we're mapping into to be large enough that the coend will take presheaves
Cᵒᵖ → Set ℓ to presheaves Dᵒᵖ → Set ℓ, otherwise we get no adjunction with precomposition.
So we must have ℓC,ℓC',ℓD' ≤ ℓ; the parameter ℓS allows ℓ to be larger than their maximum.
-}
ℓ = ℓ-max (ℓ-max (ℓ-max ℓC ℓC') ℓD') ℓS
module _ (G : Functor (C ^op) (SET ℓ)) where
-- Definition of the end
record End (d : D.ob) : Type ℓ where
field
fun : (c : C.ob) (g : D.Hom[ F ⟅ c ⟆ , d ]) → G .F-ob c .fst
coh : {c c' : C.ob} (f : C.Hom[ c , c' ]) (g : D.Hom[ F ⟅ c' ⟆ , d ])
→ fun c (F ⟪ f ⟫ ⋆⟨ D ⟩ g) ≡ (G ⟪ f ⟫) (fun c' g)
open End
end≡ : {d : D.ob} {x x' : End d} → (∀ c g → x .fun c g ≡ x' .fun c g) → x ≡ x'
end≡ h i .fun c g = h c g i
end≡ {_} {x} {x'} h i .coh f g =
isSet→isSet' (G .F-ob _ .snd)
(x .coh f g)
(x' .coh f g)
(h _ (F ⟪ f ⟫ ⋆⟨ D ⟩ g))
(cong (G ⟪ f ⟫) (h _ g))
i
-- Action of End on arrows in D
mapR : {d d' : D.ob} (h : D.Hom[ d' , d ]) → End d → End d'
mapR h x .fun c g = x .fun c (g ⋆⟨ D ⟩ h)
mapR h x .coh f g = cong (x .fun _) (D.⋆Assoc (F ⟪ f ⟫) g h) ∙ x .coh f (g ⋆⟨ D ⟩ h)
mapRId : (d : D.ob) → mapR (D.id d) ≡ (idfun _)
mapRId h = funExt λ x → end≡ λ c g → cong (x .fun c) (D.⋆IdR g)
mapR∘ : {d d' d'' : D.ob}
(h' : D.Hom[ d'' , d' ]) (h : D.Hom[ d' , d ])
→ mapR (h' D.⋆ h) ≡ mapR h' ∘ mapR h
mapR∘ h' h = funExt λ x → end≡ λ c g → cong (x .fun c) (sym (D.⋆Assoc g h' h))
open End
RanOb : Functor (C ^op) (SET ℓ) → Functor (D ^op) (SET _)
RanOb G .F-ob d .fst = End G d
RanOb G .F-ob d .snd =
-- We use that End is equivalent to a Σ-type to prove its HLevel more easily
isOfHLevelRetract 2
{B =
Σ[ z ∈ ((c : C.ob) (g : D.Hom[ F ⟅ c ⟆ , d ]) → G .F-ob c .fst) ]
({c c' : C.ob} (f : C.Hom[ c , c' ]) (g : D.Hom[ F ⟅ c' ⟆ , d ])
→ z c (F ⟪ f ⟫ ⋆⟨ D ⟩ g) ≡ (G ⟪ f ⟫) (z c' g))
}
(λ x → λ where .fst → x .fun; .snd → x .coh)
(λ σ → λ where .fun → σ .fst; .coh → σ .snd)
(λ _ → refl)
(isSetΣ
(isSetΠ2 λ _ _ → G .F-ob _ .snd)
(λ _ → isProp→isSet
(isPropImplicitΠ λ _ → isPropImplicitΠ λ _ → isPropΠ2 λ _ _ → G .F-ob _ .snd _ _)))
RanOb G .F-hom = mapR G
RanOb G .F-id {d} = mapRId G d
RanOb G .F-seq h h' = mapR∘ G h' h
-- Action of End on arrows in Cᵒᵖ → Set
module _ {G G' : Functor (C ^op) (SET ℓ)} (α : NatTrans G G') where
mapL : (d : D.ob) → End G d → End G' d
mapL d x .fun c g = (α ⟦ c ⟧) (x .fun c g)
mapL d x .coh f g =
cong (α ⟦ _ ⟧) (x .coh f g)
∙ funExt⁻ (α .N-hom f) (x .fun _ g)
mapLR : {d d' : D.ob} (h : D.Hom[ d' , d ])
→ mapL d' ∘ mapR G h ≡ mapR G' h ∘ mapL d
mapLR h = funExt λ _ → end≡ _ λ _ _ → refl
mapLId : (G : Functor (C ^op) (SET ℓ))
(d : D.ob) → mapL (idTrans G) d ≡ idfun (End G d)
mapLId G d = funExt λ _ → end≡ _ λ _ _ → refl
mapL∘ : {G G' G'' : Functor (C ^op) (SET ℓ)}
(β : NatTrans G' G'') (α : NatTrans G G')
(d : D.ob) → mapL (seqTrans α β) d ≡ mapL β d ∘ mapL α d
mapL∘ β α d = funExt λ _ → end≡ _ λ _ _ → refl
RanHom : {G G' : Functor (C ^op) (SET ℓ)}
→ NatTrans G G' → NatTrans (RanOb G) (RanOb G')
RanHom α .N-ob = mapL α
RanHom α .N-hom = mapLR α
-- Definition of the right Kan extension functor
Ran : Functor (FUNCTOR (C ^op) (SET ℓ)) (FUNCTOR (D ^op) (SET ℓ))
Ran .F-ob = RanOb
Ran .F-hom = RanHom
Ran .F-id {G} = makeNatTransPath (funExt (mapLId G))
Ran .F-seq α β = makeNatTransPath (funExt (mapL∘ β α))
-- Adjunction between precomposition and right Kan extension
private
F* = precomposeF (SET ℓ) (F ^opF)
open UnitCounit
η : 𝟙⟨ FUNCTOR (D ^op) (SET ℓ) ⟩ ⇒ (funcComp Ran F*)
η .N-ob G .N-ob d a .fun c g = (G ⟪ g ⟫) a
η .N-ob G .N-ob d a .coh f g = funExt⁻ (G .F-seq g (F ⟪ f ⟫)) a
η .N-ob G .N-hom h = funExt λ a → end≡ _ λ c g → sym (funExt⁻ (G .F-seq h g) a)
η .N-hom {G} {G'} α =
makeNatTransPath (funExt₂ λ d a → end≡ _ λ c g → sym (funExt⁻ (α .N-hom g) a))
ε : funcComp F* Ran ⇒ 𝟙⟨ FUNCTOR (C ^op) (SET ℓ) ⟩
ε .N-ob H .N-ob c x = x .fun c (D.id _)
ε .N-ob H .N-hom {c} {c'} g =
funExt λ x →
cong (x .fun c') (D.⋆IdL _ ∙ sym (D.⋆IdR _)) ∙ x .coh g (D.id _)
ε .N-hom {H} {H'} α = makeNatTransPath refl
Δ₁ : ∀ G → seqTrans (F* ⟪ η ⟦ G ⟧ ⟫) (ε ⟦ F* ⟅ G ⟆ ⟧) ≡ idTrans _
Δ₁ G = makeNatTransPath (funExt₂ λ c a → funExt⁻ (G .F-id) a)
Δ₂ : ∀ H → seqTrans (η ⟦ Ran ⟅ H ⟆ ⟧) (Ran ⟪ ε ⟦ H ⟧ ⟫) ≡ idTrans _
Δ₂ H = makeNatTransPath (funExt₂ λ c x → end≡ _ λ c' g → cong (x .fun c') (D.⋆IdL g))
adj : F* ⊣ Ran
adj = make⊣ η ε Δ₁ Δ₂
|
{
"alphanum_fraction": 0.4999124803,
"avg_line_length": 33.4093567251,
"ext": "agda",
"hexsha": "a9835d3da6a8e2da29dee80929884cf8240ea260",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/Categories/Presheaf/KanExtension.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/Categories/Presheaf/KanExtension.agda",
"max_line_length": 110,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/Categories/Presheaf/KanExtension.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5093,
"size": 11426
}
|
{-
Problem #758
same as problem 757 but rewritten with only expressions of first-order logic
Given premises:
(all A)(all B)((subset A B) <-> (all x)((mem x A) -> (mem x B))) justification = 1.0
(all A)(all B)(some intAB)(IsInt A B intAB) justification = 1.0
(all A)(all B)(all intAB)((IsInt A B intAB) <-> (all x)((mem x intAB) <-> ((mem x A) & (mem x B)))) justification = 1.0
(all A)(all B)((mapsF A B) <-> ((all x)((mem x A) -> (some y)((mem y B) & (F x y))) & (all x)(all y)(all z)(((mem x A) & ((mem y A) & (mem z A))) -> (((F x y) & (F x z)) -> (same y z))))) justification = 1.0
(all A)(all x)(all y)((same x y) -> ((mem x A) -> (mem y A))) justification = 1.0
(all x)(same x x) justification = 1.0
(all x)(all y)((same x y) <-> (same y x)) justification = 1.0
(all x)(all y)(all z)(((same x y) & (same y z)) -> (same x z)) justification = 1.0
(all A)(all B)((equal A B) <-> ((subset A B) & (subset B A))) justification = 1.0
(all A)(all B)(some invFBA)(IsInvF B A invFBA) justification = 1.0
(all A)(all B)(all invFBA)((IsInvF B A invFBA) <-> (all x)((mem x invFBA) <-> ((mem x A) & (some y)((mem y B) & (F x y))))) justification = 1.0
Ultimate epistemic interests:
(all A)(all B)(all X)(all Y)(((mapsF A B) & ((subset X B) & (subset Y B))) -> (some intXY)((IsInt X Y intXY) & (some invFIntXYA)((IsInvF intXY A invFIntXYA) & (some invFXA)((IsInvF X A invFXA) & (some invFYA)((IsInvF Y A invFYA) & (some intInvFXAInvFYA)((IsInt invFXA invFYA intInvFXAInvFYA) & (equal invFIntXYA intInvFXAInvFYA))))))) interest = 1.0
-}
_↔_ : Set → Set → Set
p ↔ q = p → q
postulate
U : Set
subset : U → U → Set
-- subsetMembership : ∀ {A} {B} →
|
{
"alphanum_fraction": 0.5577918344,
"avg_line_length": 64.4074074074,
"ext": "agda",
"hexsha": "d3f8007c82f35e4d6ae14c7babf047bb9ebcb797",
"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/lisp-revised/758.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/lisp-revised/758.agda",
"max_line_length": 357,
"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/lisp-revised/758.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 672,
"size": 1739
}
|
{-
Set quotients:
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.SetQuotients.Properties where
open import Cubical.HITs.SetQuotients.Base
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Univalence
open import Cubical.Functions.FunExtEquiv
open import Cubical.Data.Sigma
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary.Base
open import Cubical.HITs.TypeQuotients as TypeQuot using (_/ₜ_ ; [_] ; eq/)
open import Cubical.HITs.PropositionalTruncation as PropTrunc using (∥_∥ ; ∣_∣ ; squash)
open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂ ; ∣_∣₂ ; squash₂
; setTruncIsSet)
private
variable
ℓ ℓ' ℓ'' : Level
A : Type ℓ
R : A → A → Type ℓ
B : A / R → Type ℓ
C : A / R → A / R → Type ℓ
D : A / R → A / R → A / R → Type ℓ
elimEq/ : (Bprop : (x : A / R ) → isProp (B x))
{x y : A / R}
(eq : x ≡ y)
(bx : B x)
(by : B y) →
PathP (λ i → B (eq i)) bx by
elimEq/ {B = B} Bprop {x = x} =
J (λ y eq → ∀ bx by → PathP (λ i → B (eq i)) bx by) (λ bx by → Bprop x bx by)
elimProp : ((x : A / R ) → isProp (B x))
→ ((a : A) → B ( [ a ]))
→ (x : A / R)
→ B x
elimProp Bprop f [ x ] = f x
elimProp Bprop f (squash/ x y p q i j) =
isOfHLevel→isOfHLevelDep 2 (λ x → isProp→isSet (Bprop x))
(g x) (g y) (cong g p) (cong g q) (squash/ x y p q) i j
where
g = elimProp Bprop f
elimProp Bprop f (eq/ a b r i) = elimEq/ Bprop (eq/ a b r) (f a) (f b) i
elimProp2 : ((x y : A / R ) → isProp (C x y))
→ ((a b : A) → C [ a ] [ b ])
→ (x y : A / R)
→ C x y
elimProp2 Cprop f = elimProp (λ x → isPropΠ (λ y → Cprop x y))
(λ x → elimProp (λ y → Cprop [ x ] y) (f x))
elimProp3 : ((x y z : A / R ) → isProp (D x y z))
→ ((a b c : A) → D [ a ] [ b ] [ c ])
→ (x y z : A / R)
→ D x y z
elimProp3 Dprop f = elimProp (λ x → isPropΠ2 (λ y z → Dprop x y z))
(λ x → elimProp2 (λ y z → Dprop [ x ] y z) (f x))
-- lemma 6.10.2 in hott book
[]surjective : (x : A / R) → ∃[ a ∈ A ] [ a ] ≡ x
[]surjective = elimProp (λ x → squash) (λ a → ∣ a , refl ∣)
elim : {B : A / R → Type ℓ}
→ ((x : A / R) → isSet (B x))
→ (f : (a : A) → (B [ a ]))
→ ((a b : A) (r : R a b) → PathP (λ i → B (eq/ a b r i)) (f a) (f b))
→ (x : A / R)
→ B x
elim Bset f feq [ a ] = f a
elim Bset f feq (eq/ a b r i) = feq a b r i
elim Bset f feq (squash/ x y p q i j) =
isOfHLevel→isOfHLevelDep 2 Bset
(g x) (g y) (cong g p) (cong g q) (squash/ x y p q) i j
where
g = elim Bset f feq
rec : {B : Type ℓ}
(Bset : isSet B)
(f : A → B)
(feq : (a b : A) (r : R a b) → f a ≡ f b)
→ A / R → B
rec Bset f feq [ a ] = f a
rec Bset f feq (eq/ a b r i) = feq a b r i
rec Bset f feq (squash/ x y p q i j) = Bset (g x) (g y) (cong g p) (cong g q) i j
where
g = rec Bset f feq
rec2 : {B : Type ℓ} (Bset : isSet B)
(f : A → A → B) (feql : (a b c : A) (r : R a b) → f a c ≡ f b c)
(feqr : (a b c : A) (r : R b c) → f a b ≡ f a c)
→ A / R → A / R → B
rec2 Bset f feql feqr = rec (isSetΠ (λ _ → Bset))
(λ a → rec Bset (f a) (feqr a))
(λ a b r → funExt (elimProp (λ _ → Bset _ _)
(λ c → feql a b c r)))
-- the recursor for maps into groupoids:
-- i.e. for any type A with a binary relation R and groupoid B,
-- we can construct a map A / R → B from a map A → B satisfying the conditions
-- (i) ∀ (a b : A) → R a b → f a ≡ f b
-- (ii) ∀ (a b : A) → isProp (f a ≡ f b)
-- We start by proving that we can recover the set-quotient
-- by set-truncating the (non-truncated type quotient)
typeQuotSetTruncIso : Iso (A / R) ∥ A /ₜ R ∥₂
Iso.fun typeQuotSetTruncIso = rec setTruncIsSet (λ a → ∣ [ a ] ∣₂)
λ a b r → cong ∣_∣₂ (eq/ a b r)
Iso.inv typeQuotSetTruncIso = SetTrunc.rec squash/ (TypeQuot.rec [_] eq/)
Iso.rightInv typeQuotSetTruncIso = SetTrunc.elim (λ _ → isProp→isSet (squash₂ _ _))
(TypeQuot.elimProp (λ _ → squash₂ _ _) λ _ → refl)
Iso.leftInv typeQuotSetTruncIso = elimProp (λ _ → squash/ _ _) λ _ → refl
module rec→Gpd {A : Type ℓ} {R : A → A → Type ℓ'} {B : Type ℓ''} (Bgpd : isGroupoid B)
(f : A → B)
(feq : ∀ (a b : A) → R a b → f a ≡ f b)
(fprop : ∀ (a b : A) → isProp (f a ≡ f b)) where
fun : A / R → B
fun = f₁ ∘ f₂
where
f₁ : ∥ A /ₜ R ∥₂ → B
f₁ = SetTrunc.rec→Gpd.fun Bgpd f/ congF/Const
where
f/ : A /ₜ R → B
f/ = TypeQuot.rec f feq
congF/Const : (a b : A /ₜ R) (p q : a ≡ b) → cong f/ p ≡ cong f/ q
congF/Const = TypeQuot.elimProp2 (λ _ _ → isPropΠ2 λ _ _ → Bgpd _ _ _ _)
λ a b p q → fprop a b (cong f/ p) (cong f/ q)
f₂ : A / R → ∥ A /ₜ R ∥₂
f₂ = Iso.fun typeQuotSetTruncIso
setQuotUniversalIso : {B : Type ℓ} (Bset : isSet B)
→ Iso (A / R → B) (Σ[ f ∈ (A → B) ] ((a b : A) → R a b → f a ≡ f b))
Iso.fun (setQuotUniversalIso Bset) g = (λ a → g [ a ]) , λ a b r i → g (eq/ a b r i)
Iso.inv (setQuotUniversalIso Bset) h = elim (λ x → Bset) (fst h) (snd h)
Iso.rightInv (setQuotUniversalIso Bset) h = refl
Iso.leftInv (setQuotUniversalIso Bset) g =
funExt (λ x → PropTrunc.elim (λ sur → Bset (out (intro g) x) (g x))
(λ sur → cong (out (intro g)) (sym (snd sur)) ∙ (cong g (snd sur))) ([]surjective x))
where
intro = Iso.fun (setQuotUniversalIso Bset)
out = Iso.inv (setQuotUniversalIso Bset)
setQuotUniversal : {B : Type ℓ} (Bset : isSet B) →
(A / R → B) ≃ (Σ[ f ∈ (A → B) ] ((a b : A) → R a b → f a ≡ f b))
setQuotUniversal Bset = isoToEquiv (setQuotUniversalIso Bset)
open BinaryRelation
-- characterisation of binary functions/operations on set-quotients
setQuotUniversal2Iso : {B : Type ℓ} (Bset : isSet B) → isRefl R
→ Iso (A / R → A / R → B)
(Σ[ _∗_ ∈ (A → A → B) ] ((a a' b b' : A) → R a a' → R b b' → a ∗ b ≡ a' ∗ b'))
Iso.fun (setQuotUniversal2Iso {A = A} {R = R} {B = B} Bset isReflR) _∗/_ = _∗_ , h
where
_∗_ = λ a b → [ a ] ∗/ [ b ]
h : (a a' b b' : A) → R a a' → R b b' → a ∗ b ≡ a' ∗ b'
h a a' b b' ra rb = cong (_∗/ [ b ]) (eq/ _ _ ra) ∙ cong ([ a' ] ∗/_) (eq/ _ _ rb)
Iso.inv (setQuotUniversal2Iso {A = A} {R = R} {B = B} Bset isReflR) (_∗_ , h) =
rec2 Bset _∗_ hleft hright
where
hleft : ∀ a b c → R a b → (a ∗ c) ≡ (b ∗ c)
hleft _ _ c r = h _ _ _ _ r (isReflR c)
hright : ∀ a b c → R b c → (a ∗ b) ≡ (a ∗ c)
hright a _ _ r = h _ _ _ _ (isReflR a) r
Iso.rightInv (setQuotUniversal2Iso {A = A} {R = R} {B = B} Bset isReflR) (_∗_ , h) =
Σ≡Prop (λ _ → isPropΠ4 λ _ _ _ _ → isPropΠ2 λ _ _ → Bset _ _) refl
Iso.leftInv (setQuotUniversal2Iso {A = A} {R = R} {B = B} Bset isReflR) _∗/_ =
funExt₂ (elimProp2 (λ _ _ → Bset _ _) λ _ _ → refl)
setQuotUniversal2 : {B : Type ℓ} (Bset : isSet B) → isRefl R
→ (A / R → A / R → B)
≃ (Σ[ _∗_ ∈ (A → A → B) ] ((a a' b b' : A) → R a a' → R b b' → a ∗ b ≡ a' ∗ b'))
setQuotUniversal2 Bset isReflR = isoToEquiv (setQuotUniversal2Iso Bset isReflR)
-- corollary for binary operations
-- TODO: prove truncated inverse for effective relations
setQuotBinOp : isRefl R
→ (_∗_ : A → A → A)
→ (∀ a a' b b' → R a a' → R b b' → R (a ∗ b) (a' ∗ b'))
→ (A / R → A / R → A / R)
setQuotBinOp isReflR _∗_ h = Iso.inv (setQuotUniversal2Iso squash/ isReflR)
((λ a b → [ a ∗ b ]) , λ _ _ _ _ ra rb → eq/ _ _ (h _ _ _ _ ra rb))
setQuotSymmBinOp : isRefl R → isTrans R
→ (_∗_ : A → A → A)
→ (∀ a b → a ∗ b ≡ b ∗ a)
→ (∀ a a' b → R a a' → R (a ∗ b) (a' ∗ b))
→ (A / R → A / R → A / R)
setQuotSymmBinOp {A = A} {R = R} isReflR isTransR _∗_ ∗-symm h = setQuotBinOp isReflR _∗_ h'
where
h' : ∀ a a' b b' → R a a' → R b b' → R (a ∗ b) (a' ∗ b')
h' a a' b b' ra rb = isTransR _ _ _ (h a a' b ra)
(transport (λ i → R (∗-symm b a' i) (∗-symm b' a' i)) (h b b' a' rb))
effective : (Rprop : isPropValued R) (Requiv : isEquivRel R) (a b : A) → [ a ] ≡ [ b ] → R a b
effective {A = A} {R = R} Rprop (equivRel R/refl R/sym R/trans) a b p = transport aa≡ab (R/refl _)
where
helper : A / R → hProp _
helper =
rec isSetHProp (λ c → (R a c , Rprop a c))
(λ c d cd → Σ≡Prop (λ _ → isPropIsProp)
(hPropExt (Rprop a c) (Rprop a d)
(λ ac → R/trans _ _ _ ac cd) (λ ad → R/trans _ _ _ ad (R/sym _ _ cd))))
aa≡ab : R a a ≡ R a b
aa≡ab i = helper (p i) .fst
isEquivRel→effectiveIso : isPropValued R → isEquivRel R → (a b : A) → Iso ([ a ] ≡ [ b ]) (R a b)
Iso.fun (isEquivRel→effectiveIso {R = R} Rprop Req a b) = effective Rprop Req a b
Iso.inv (isEquivRel→effectiveIso {R = R} Rprop Req a b) = eq/ a b
Iso.rightInv (isEquivRel→effectiveIso {R = R} Rprop Req a b) _ = Rprop a b _ _
Iso.leftInv (isEquivRel→effectiveIso {R = R} Rprop Req a b) _ = squash/ _ _ _ _
isEquivRel→isEffective : isPropValued R → isEquivRel R → isEffective R
isEquivRel→isEffective Rprop Req a b = isoToIsEquiv (invIso (isEquivRel→effectiveIso Rprop Req a b))
discreteSetQuotients : Discrete A → isPropValued R → isEquivRel R → (∀ a₀ a₁ → Dec (R a₀ a₁)) → Discrete (A / R)
discreteSetQuotients {A = A} {R = R} Adis Rprop Req Rdec =
elim (λ a₀ → isSetΠ (λ a₁ → isProp→isSet (isPropDec (squash/ a₀ a₁))))
discreteSetQuotients' discreteSetQuotients'-eq
where
discreteSetQuotients' : (a : A) (y : A / R) → Dec ([ a ] ≡ y)
discreteSetQuotients' a₀ = elim (λ a₁ → isProp→isSet (isPropDec (squash/ [ a₀ ] a₁))) dis dis-eq
where
dis : (a₁ : A) → Dec ([ a₀ ] ≡ [ a₁ ])
dis a₁ with Rdec a₀ a₁
... | (yes p) = yes (eq/ a₀ a₁ p)
... | (no ¬p) = no λ eq → ¬p (effective Rprop Req a₀ a₁ eq )
dis-eq : (a b : A) (r : R a b) →
PathP (λ i → Dec ([ a₀ ] ≡ eq/ a b r i)) (dis a) (dis b)
dis-eq a b ab = J (λ b ab → ∀ k → PathP (λ i → Dec ([ a₀ ] ≡ ab i)) (dis a) k)
(λ k → isPropDec (squash/ _ _) _ _) (eq/ a b ab) (dis b)
discreteSetQuotients'-eq : (a b : A) (r : R a b) →
PathP (λ i → (y : A / R) → Dec (eq/ a b r i ≡ y))
(discreteSetQuotients' a) (discreteSetQuotients' b)
discreteSetQuotients'-eq a b ab =
J (λ b ab → ∀ k → PathP (λ i → (y : A / R) → Dec (ab i ≡ y))
(discreteSetQuotients' a) k)
(λ k → funExt (λ x → isPropDec (squash/ _ _) _ _)) (eq/ a b ab) (discreteSetQuotients' b)
-- Quotienting by the truncated relation is equivalent to quotienting by untruncated relation
truncRelIso : Iso (A / R) (A / (λ a b → ∥ R a b ∥))
Iso.fun truncRelIso = rec squash/ [_] λ _ _ r → eq/ _ _ ∣ r ∣
Iso.inv truncRelIso = rec squash/ [_] λ _ _ → PropTrunc.rec (squash/ _ _) λ r → eq/ _ _ r
Iso.rightInv truncRelIso = elimProp (λ _ → squash/ _ _) λ _ → refl
Iso.leftInv truncRelIso = elimProp (λ _ → squash/ _ _) λ _ → refl
truncRelEquiv : A / R ≃ A / (λ a b → ∥ R a b ∥)
truncRelEquiv = isoToEquiv truncRelIso
-- Using this we can obtain a useful characterization of
-- path-types for equivalence relations (not prop-valued)
-- and their quotients
isEquivRel→TruncIso : isEquivRel R → (a b : A) → Iso ([ a ] ≡ [ b ]) ∥ R a b ∥
isEquivRel→TruncIso {A = A} {R = R} Req a b = compIso (isProp→Iso (squash/ _ _) (squash/ _ _)
(cong (Iso.fun truncRelIso)) (cong (Iso.inv truncRelIso)))
(isEquivRel→effectiveIso (λ _ _ → PropTrunc.propTruncIsProp) ∥R∥eq a b)
where
open isEquivRel
∥R∥eq : isEquivRel λ a b → ∥ R a b ∥
reflexive ∥R∥eq a = ∣ reflexive Req a ∣
symmetric ∥R∥eq a b = PropTrunc.map (symmetric Req a b)
transitive ∥R∥eq a b c = PropTrunc.map2 (transitive Req a b c)
|
{
"alphanum_fraction": 0.5217008328,
"avg_line_length": 42.6211604096,
"ext": "agda",
"hexsha": "721d74ea6a633396368266a1be9ca03841d84b7d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/HITs/SetQuotients/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/HITs/SetQuotients/Properties.agda",
"max_line_length": 121,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/HITs/SetQuotients/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4925,
"size": 12488
}
|
module bool-thms2 where
open import bool
open import eq
open import product
open import sum
ff-imp : ∀ (b : 𝔹) → (ff imp b) ≡ tt
ff-imp ff = refl
ff-imp tt = refl
imp-tt : ∀ (b : 𝔹) → (b imp tt) ≡ tt
imp-tt ff = refl
imp-tt tt = refl
imp-ff : ∀ (b : 𝔹) → (b imp ff) ≡ ~ b
imp-ff tt = refl
imp-ff ff = refl
tt-imp : ∀ (b : 𝔹) → (tt imp b) ≡ b
tt-imp tt = refl
tt-imp ff = refl
&&-tt : ∀ (b : 𝔹) → b && tt ≡ b
&&-tt tt = refl
&&-tt ff = refl
||-ff : ∀ (b : 𝔹) → b || ff ≡ b
||-ff tt = refl
||-ff ff = refl
&&-contra : ∀ (b : 𝔹) → b && ~ b ≡ ff
&&-contra ff = refl
&&-contra tt = refl
&&-comm : ∀ (b1 b2 : 𝔹) → b1 && b2 ≡ b2 && b1
&&-comm ff ff = refl
&&-comm ff tt = refl
&&-comm tt ff = refl
&&-comm tt tt = refl
||-comm : ∀ (b1 b2 : 𝔹) → b1 || b2 ≡ b2 || b1
||-comm ff ff = refl
||-comm ff tt = refl
||-comm tt ff = refl
||-comm tt tt = refl
&&-assoc : ∀ (b1 b2 b3 : 𝔹) → b1 && (b2 && b3) ≡ (b1 && b2) && b3
&&-assoc ff _ _ = refl
&&-assoc tt _ _ = refl
||-assoc : ∀ (b1 b2 b3 : 𝔹) → b1 || (b2 || b3) ≡ (b1 || b2) || b3
||-assoc tt _ _ = refl
||-assoc ff _ _ = refl
~-over-&& : ∀ (b1 b2 : 𝔹) → ~ ( b1 && b2 ) ≡ (~ b1 || ~ b2)
~-over-&& tt _ = refl
~-over-&& ff _ = refl
~-over-|| : ∀ (b1 b2 : 𝔹) → ~ ( b1 || b2 ) ≡ (~ b1 && ~ b2)
~-over-|| tt _ = refl
~-over-|| ff _ = refl
&&-over-||-l : ∀ (a b c : 𝔹) → a && (b || c) ≡ (a && b) || (a && c)
&&-over-||-l tt _ _ = refl
&&-over-||-l ff _ _ = refl
&&-over-||-r : ∀ (a b c : 𝔹) → (a || b) && c ≡ (a && c) || (b && c)
&&-over-||-r tt tt tt = refl
&&-over-||-r tt tt ff = refl
&&-over-||-r tt ff tt = refl
&&-over-||-r tt ff ff = refl
&&-over-||-r ff tt tt = refl
&&-over-||-r ff tt ff = refl
&&-over-||-r ff ff tt = refl
&&-over-||-r ff ff ff = refl
||-over-&&-l : ∀ (a b c : 𝔹) → a || (b && c) ≡ (a || b) && (a || c)
||-over-&&-l tt _ _ = refl
||-over-&&-l ff _ _ = refl
||-over-&&-r : ∀ (a b c : 𝔹) → (a && b) || c ≡ (a || c) && (b || c)
||-over-&&-r tt _ _ = refl
||-over-&&-r ff _ ff = refl
||-over-&&-r ff tt tt = refl
||-over-&&-r ff ff tt = refl
&&-cong₁ : ∀ {b1 b1' b2 : 𝔹} → b1 ≡ b1' → b1 && b2 ≡ b1' && b2
&&-cong₁ refl = refl
&&-cong₂ : ∀ {b1 b2 b2' : 𝔹} → b2 ≡ b2' → b1 && b2 ≡ b1 && b2'
&&-cong₂ refl = refl
&&-intro : ∀ {b1 b2 : 𝔹} → b1 ≡ tt → b2 ≡ tt → b1 && b2 ≡ tt
&&-intro{tt}{tt} _ _ = refl
&&-intro{tt}{ff} _ ()
&&-intro{ff}{tt} () _
&&-intro{ff}{ff} () _
||-intro1 : ∀ {b1 b2 : 𝔹} → b1 ≡ tt → b1 || b2 ≡ tt
||-intro1 {tt} p = refl
||-intro1 {ff} ()
&&-elim : ∀ {b1 b2 : 𝔹} → b1 && b2 ≡ tt → b1 ≡ tt ∧ b2 ≡ tt
&&-elim{tt}{tt} _ = refl , refl
&&-elim{ff}{_} ()
&&-elim{tt}{ff} ()
&&-elim1 : ∀ {b1 b2 : 𝔹} → b1 && b2 ≡ tt → b1 ≡ tt
&&-elim1 p with &&-elim p
&&-elim1 _ | p , _ = p
&&-elim2 : ∀ {b1 b2 : 𝔹} → b1 && b2 ≡ tt → b2 ≡ tt
&&-elim2{b1} p with &&-elim{b1} p
&&-elim2 _ | _ , p = p
||-elim : ∀ {b1 b2 : 𝔹} → b1 || b2 ≡ tt → b1 ≡ tt ∨ b2 ≡ tt
||-elim {tt} refl = inj₁ refl
||-elim {ff} refl = inj₂ refl
~-cong : ∀ {b b' : 𝔹} → b ≡ b' → ~ b ≡ ~ b'
~-cong refl = refl
ite-cong₁ : ∀{ℓ}{A : Set ℓ} {b b' : 𝔹}(x y : A) → b ≡ b' → (if b then x else y) ≡ (if b' then x else y)
ite-cong₁ x y refl = refl
ite-cong₂ : ∀{ℓ}{A : Set ℓ} (b : 𝔹){x x' : A}(y : A) → x ≡ x' → (if b then x else y) ≡ (if b then x' else y)
ite-cong₂ b y refl = refl
ite-cong₃ : ∀{ℓ}{A : Set ℓ} (b : 𝔹)(x : A){y y' : A} → y ≡ y' → (if b then x else y) ≡ (if b then x else y')
ite-cong₃ b x refl = refl
&&-split : ∀ {b b' : 𝔹} → b || b' ≡ ff → b ≡ ff ⊎ b' ≡ ff
&&-split {tt} ()
&&-split {ff}{tt} ()
&&-split {ff}{ff} p = inj₁ refl
-----------------------------------
-- Theorems about imp
-----------------------------------
imp-same : ∀ (b : 𝔹) → (b imp b) ≡ tt
imp-same ff = refl
imp-same tt = refl
imp-to-|| : ∀ (b1 b2 : 𝔹) → (b1 imp b2) ≡ (~ b1 || b2)
imp-to-|| ff _ = refl
imp-to-|| tt _ = refl
imp-mp : ∀ {b b' : 𝔹} → (b imp b') ≡ tt → b ≡ tt → b' ≡ tt
imp-mp {tt} {tt} p refl = refl
imp-mp {ff} {ff} p q = q
imp-mp {tt} {ff} p q = p
imp-mp {ff} {tt} p q = refl
imp-antisymm : ∀ {b1 b2 : 𝔹} → (b1 imp b2) ≡ tt → (b2 imp b1) ≡ tt → b1 ≡ b2
imp-antisymm{tt}{tt} p q = refl
imp-antisymm{tt}{ff} () q
imp-antisymm{ff}{tt} p ()
imp-antisymm{ff}{ff} p q = refl
-----------------------------------
-- Theorems about xor
-----------------------------------
ff-xor : ∀ (b : 𝔹) → ff xor b ≡ b
ff-xor tt = refl
ff-xor ff = refl
tt-xor : ∀ (b : 𝔹) → tt xor b ≡ ~ b
tt-xor tt = refl
tt-xor ff = refl
~-xor-distrb : ∀ (a b : 𝔹) → ~ (a xor b) ≡ ~ a xor b
~-xor-distrb tt tt = refl
~-xor-distrb tt ff = refl
~-xor-distrb ff tt = refl
~-xor-distrb ff ff = refl
xor-distrib-&& : ∀ (x y : 𝔹) → x xor (y && x) ≡ ~ y && x
xor-distrib-&& tt tt = refl
xor-distrib-&& tt ff = refl
xor-distrib-&& ff tt = refl
xor-distrib-&& ff ff = refl
xor~hop : ∀ (a b : 𝔹) → ~ a xor b ≡ a xor ~ b
xor~hop tt tt = refl
xor~hop tt ff = refl
xor~hop ff tt = refl
xor~hop ff ff = refl
xor-comm : ∀ (b1 b2 : 𝔹) → b1 xor b2 ≡ b2 xor b1
xor-comm tt tt = refl
xor-comm tt ff = refl
xor-comm ff tt = refl
xor-comm ff ff = refl
xor-assoc : (b1 b2 b3 : 𝔹) → b1 xor (b2 xor b3) ≡ (b1 xor b2) xor b3
xor-assoc tt tt tt = refl
xor-assoc tt tt ff = refl
xor-assoc tt ff tt = refl
xor-assoc tt ff ff = refl
xor-assoc ff tt tt = refl
xor-assoc ff tt ff = refl
xor-assoc ff ff tt = refl
xor-assoc ff ff ff = refl
xor-anti-idem : (b : 𝔹) → b xor b ≡ ff
xor-anti-idem tt = refl
xor-anti-idem ff = refl
xor-≡ : {b1 b2 : 𝔹} → b1 xor b2 ≡ ff → b1 ≡ b2
xor-≡ {tt} {tt} p = refl
xor-≡ {tt} {ff} ()
xor-≡ {ff} {tt} ()
xor-≡ {ff} {ff} p = refl
-----------------------------------
-- Theorems about nor, nand
-----------------------------------
nor-not : ∀ (b : 𝔹) → b nor b ≡ ~ b
nor-not tt = refl
nor-not ff = refl
nor-or : ∀ (b1 b2 : 𝔹) → (b1 nor b2) nor (b1 nor b2) ≡ b1 || b2
nor-or tt b2 = refl
nor-or ff tt = refl
nor-or ff ff = refl
nor-and : ∀ (b1 b2 : 𝔹) → (b1 nor b1) nor (b2 nor b2) ≡ b1 && b2
nor-and tt tt = refl
nor-and tt ff = refl
nor-and ff b2 = refl
nor-comm : ∀ (b1 b2 : 𝔹) → b1 nor b2 ≡ b2 nor b1
nor-comm tt tt = refl
nor-comm tt ff = refl
nor-comm ff tt = refl
nor-comm ff ff = refl
nand-comm : ∀ (b1 b2 : 𝔹) → b1 nand b2 ≡ b2 nand b1
nand-comm tt tt = refl
nand-comm tt ff = refl
nand-comm ff tt = refl
nand-comm ff ff = refl
|
{
"alphanum_fraction": 0.4813915858,
"avg_line_length": 25.1219512195,
"ext": "agda",
"hexsha": "56a1c69efe314da0a724848c7b13a671721ab9ce",
"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": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "bool-thms2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"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": "heades/AUGL",
"max_issues_repo_path": "bool-thms2.agda",
"max_line_length": 108,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "bool-thms2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2905,
"size": 6180
}
|
open import Prelude
open import Data.Nat using (_≤?_)
open import Data.Maybe using (Maybe; just; nothing)
open import Data.Vec using (Vec; _∷_; [])
open import RW.Language.RTerm
open import RW.Language.FinTerm
open import RW.Language.RTermUtils
open import RW.Utils.Monads
module RW.Language.GoalGuesser (maxH : ℕ) where
open Monad {{...}}
----------------
-- Housekeeping
private
cast-RBinApp : {A B : Set} → (A → B) → RBinApp A → RBinApp B
cast-RBinApp f (n , a , b) = n , replace-A (ovar ∘ f) a , replace-A (ovar ∘ f) b
RBinApp02⊥ : RBinApp (Fin zero) → RBinApp ⊥
RBinApp02⊥ = cast-RBinApp (λ ())
symmetric : {A : Set} → RBinApp A → RBinApp A
symmetric (n , a , b) = n , b , a
-----------------
-- Term subsitution
-- Given a RBinApp representing a type (t₁ ▵ t₂), will return a
-- non-deterministic substitution of t₂ for t₁ in a given goal g.
-- If no substitution could be performed, the empty list will be returned.
_[_] : {A : Set}{{eqA : Eq A}} → RTerm A → RTerm A × RTerm A → NonDet (RTerm A)
g [ ty1 , ty2 ] = map p2 (filter p1 (substRTermAux g ty1 ty2))
where
-- Non-deterministic term substitution. Possibly empty substitution.
-- Since we're only interested in the situations where a single substitution is performed,
-- we also return a boolean flag indicating whether or not we already had a substitution.
substRTermAux : {A : Set}{{ eqA : Eq A }} → RTerm A → RTerm A → RTerm A → NonDet (Bool × RTerm A)
substRTermAux {A} {{eqA}} t m n with t ≟-RTerm m
...| yes _ = return (true , n)
...| no _ = substStep t m n
where
mutual
substStep : RTerm A → RTerm A → RTerm A → NonDet (Bool × RTerm A)
substStep (ovar x) _ _ = return (false , ovar x)
substStep (ivar n) _ _ = return (false , ivar n)
substStep (rlit l) _ _ = return (false , rlit l)
substStep (rlam t) m n = substRTermAux t m n >>= return ∘ (λ p → p1 p , rlam (p2 p))
substStep (rapp a as) m n = substStep* as m n >>= return ∘ (λ p → p1 p , rapp a (p2 p))
-- For the list scenario, in the inductive step, we need to substitute m for n in x,
-- and return either the result of such substitution or the result of substituting
-- m for n recursively in la. Do not forget that _++_ is mplus for the list monad.
substStep* : List (RTerm A) → RTerm A → RTerm A → NonDet (Bool × List (RTerm A))
substStep* [] _ _ = return (false , [])
substStep* (x ∷ la) m n
= substRTermAux x m n >>= λ x' → return (p1 x' , (p2 x' ∷ la))
++ (substStep* la m n >>= return ∘ (λ p → p1 p , x ∷ p2 p))
-- Given a term and a type ty with n variables, will search for n subterms of t
-- in a non-deterministic fashion, and will instantiate them as parameters to ty.
{-# TERMINATING #-}
apply : {n : ℕ} → RTerm ⊥ → RBinApp (Fin n) → NonDet (RTerm ⊥)
-- If we have no more variables to instantiate on our type,
-- we can proceed to substitute.
apply {n = zero} g (_ , ty1 , ty2)
= g [ Fin2RTerm⊥ ty1 , Fin2RTerm⊥ ty2 ]
-- If not, we simply call with a recursively smaller n
apply {n = suc n} g t = inst g t >>= apply g
where
-- Easy way of discarding the last variable of a Fin n.
-- Mainly, we map Fin (1 + n) to 1 + Fin n.
thin : {n : ℕ} → Fin (suc n) → Maybe (Fin n)
thin {zero} _ = nothing
thin {suc n} fz = just fz
thin {suc n} (fs x) with thin x
...| nothing = nothing
...| just x' = just (fs x')
-- Given a closed term t, returns a substitution σ defined
-- by σ(n+1) = t, σ(k, k ≤ n) = var k.
▵_ : {n : ℕ} → RTerm ⊥ → Fin (suc n) → RTerm (Fin n)
▵_ {n} t x with thin x
...| nothing = replace-A (λ ()) t
...| just x' = ovar x'
{-# TERMINATING #-}
mk-inst-f : {n : ℕ} → RTerm ⊥ → NonDet (Fin (suc n) → RTerm (Fin n))
mk-inst-f (ovar ())
mk-inst-f (ivar n) = return (▵ (ivar n))
mk-inst-f (rlit l) = return (▵ (rlit l))
mk-inst-f (rlam t) with height (rlam t) ≤? maxH
...| yes _ = return (▵ (rlam t)) ++ mk-inst-f t
...| no _ = mk-inst-f t
mk-inst-f (rapp n ts) with height (rapp n ts) ≤? maxH
...| yes _ = return (▵ (rapp n ts)) ++ concat (mapM mk-inst-f ts)
...| no _ = concat (mapM mk-inst-f ts)
-- Given a term t and a type with (n+1) variables, instantiate the last variable
-- from the type with a non-deterministic subterm of t, returns the resulting type.
inst : {n : ℕ} → RTerm ⊥ → RBinApp (Fin (suc n)) → NonDet (RBinApp (Fin n))
inst {n} t (r , ty1 , ty2) = mk-inst-f {n} t >>= λ f → return (r , replace-A f ty1 , replace-A f ty2)
-- TODO: Use vectors instead of lists...
-- Given a goal (a ▵ b) and a list of types L, try to find intermediate goals g₁⋯gₙ such
-- that ∀n . tyₙ ∈ L ⇒ tyₙ : gₙ₋₁ → gₙ , where g₀ = a and gₖ = b.
divideGoal : RBinApp ⊥ → List (Σ ℕ (RBinApp ∘ Fin)) → Maybe (List (RTerm ⊥))
divideGoal (gh , g1 , g2) l = sfHead (filter chainIsValid (stepGoals g1 l))
where
chainIsValid : List (RTerm ⊥) → Bool
chainIsValid [] = false
chainIsValid (x ∷ []) with x ≟-RTerm g2
...| yes _ = true
...| no _ = false
chainIsValid (x ∷ l) = chainIsValid l
sfHead : {A : Set} → List A → Maybe A
sfHead [] = nothing
sfHead (x ∷ _) = just x
-- Given a list of types, will return a possible list of goals that
-- could be discharged by those types.
stepGoals : RTerm ⊥ → List (Σ ℕ (RBinApp ∘ Fin)) → NonDet (List (RTerm ⊥))
stepGoals g [] = return (g ∷ [])
stepGoals g ((nₜ , t) ∷ ts) = apply g t ++ apply g (symmetric t)
>>= (λ g' → stepGoals g' ts
>>= return ∘ (_∷_ g))
module Test where
goal : RTerm ⊥
goal = rapp (rdef (quote _≡_))
(rapp (rdef (quote _+_)) (ivar 0 ∷ ivar 1 ∷ []) ∷
rapp (rdef (quote _+_))
(ivar 0 ∷
rapp (rdef (quote _+_)) (ivar 1 ∷ rapp (rcon (quote zero)) [] ∷ [])
∷ [])
∷ [])
binGoal : RBinApp ⊥
binGoal = rdef (quote _≡_)
, rapp (rdef (quote _+_)) (ivar 0 ∷ ivar 1 ∷ [])
, rapp (rdef (quote _+_)) (ivar 0 ∷ (rapp (rdef (quote _+_)) (ivar 1 ∷ (rapp (rcon (quote zero)) []) ∷ []) ∷ []))
+-ri : RBinApp (Fin 1)
+-ri = rdef (quote _≡_)
, rapp (rdef (quote _+_)) (ovar fz ∷ rapp (rcon (quote zero)) [] ∷ [])
, ovar fz
+-a : RBinApp (Fin 3)
+-a = rdef (quote _≡_)
, rapp (rdef (quote _+_)) (rapp (rdef (quote _+_)) (ovar (fs $ fs fz) ∷ ovar (fs fz) ∷ []) ∷ ovar fz ∷ [])
, rapp (rdef (quote _+_)) (ovar (fs $ fs fz) ∷ rapp (rdef (quote _+_)) (ovar (fs fz) ∷ ovar fz ∷ []) ∷ [])
tylist : List (Σ ℕ (RBinApp ∘ Fin))
tylist = (1 , +-ri) ∷ (3 , +-a) ∷ []
|
{
"alphanum_fraction": 0.5409531963,
"avg_line_length": 42.9938650307,
"ext": "agda",
"hexsha": "c8360c99ccab2537fa801087410a5dbc63544dd7",
"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": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "VictorCMiraldo/agda-rw",
"max_forks_repo_path": "RW/Language/GoalGuesser.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_issues_repo_issues_event_max_datetime": "2015-05-28T14:48:03.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-06T15:03:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "VictorCMiraldo/agda-rw",
"max_issues_repo_path": "RW/Language/GoalGuesser.agda",
"max_line_length": 125,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "VictorCMiraldo/agda-rw",
"max_stars_repo_path": "RW/Language/GoalGuesser.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-24T17:38:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-02-09T15:43:38.000Z",
"num_tokens": 2368,
"size": 7008
}
|
{-# OPTIONS --prop --rewriting #-}
module Examples.Sorting.Sequential where
open import Examples.Sorting.Sequential.Comparable
open import Calf costMonoid
open import Calf.Types.Nat
open import Calf.Types.List
open import Relation.Binary.PropositionalEquality as Eq using (_≡_)
open import Data.Product using (_,_)
test/forward = 1 ∷ 2 ∷ 3 ∷ 4 ∷ 5 ∷ 6 ∷ 7 ∷ 8 ∷ 9 ∷ 10 ∷ 11 ∷ 12 ∷ 13 ∷ 14 ∷ 15 ∷ 16 ∷ []
test/backward = 16 ∷ 15 ∷ 14 ∷ 13 ∷ 12 ∷ 11 ∷ 10 ∷ 9 ∷ 8 ∷ 7 ∷ 6 ∷ 5 ∷ 4 ∷ 3 ∷ 2 ∷ 1 ∷ []
test/shuffled = 4 ∷ 8 ∷ 12 ∷ 16 ∷ 13 ∷ 3 ∷ 5 ∷ 14 ∷ 9 ∷ 6 ∷ 7 ∷ 10 ∷ 11 ∷ 1 ∷ 2 ∷ 15 ∷ []
module Ex/InsertionSort where
import Examples.Sorting.Sequential.InsertionSort NatComparable as Sort
list' = list nat
ex/insert : cmp (F list')
ex/insert = Sort.insert 3 (1 ∷ 2 ∷ 4 ∷ [])
ex/sort : cmp (F list')
ex/sort = Sort.sort (1 ∷ 5 ∷ 3 ∷ 1 ∷ 2 ∷ [])
ex/sort/forward : cmp (F list')
ex/sort/forward = Sort.sort test/forward -- cost: 15
ex/sort/backward : cmp (F list')
ex/sort/backward = Sort.sort test/backward -- cost: 120
ex/sort/shuffled : cmp (F list')
ex/sort/shuffled = Sort.sort test/shuffled -- cost: 76
module Ex/MergeSort where
import Examples.Sorting.Sequential.MergeSort NatComparable as Sort
list' = list nat
ex/split : cmp (F Sort.pair)
ex/split = Sort.split (6 ∷ 2 ∷ 8 ∷ 3 ∷ 1 ∷ 8 ∷ 5 ∷ [])
ex/merge : cmp (F list')
ex/merge = Sort.merge (2 ∷ 3 ∷ 6 ∷ 8 ∷ [] , 1 ∷ 5 ∷ 8 ∷ [])
ex/sort : cmp (F list')
ex/sort = Sort.sort (1 ∷ 5 ∷ 3 ∷ 1 ∷ 2 ∷ [])
ex/sort/forward : cmp (F list')
ex/sort/forward = Sort.sort test/forward -- cost: 32
ex/sort/backward : cmp (F list')
ex/sort/backward = Sort.sort test/backward -- cost: 32
ex/sort/shuffled : cmp (F list')
ex/sort/shuffled = Sort.sort test/shuffled -- cost: 47
module SortEquivalence (M : Comparable) where
open Comparable M
open import Examples.Sorting.Sequential.Core M
import Examples.Sorting.Sequential.InsertionSort M as ISort
import Examples.Sorting.Sequential.MergeSort M as MSort
isort≡msort : ◯ (ISort.sort ≡ MSort.sort)
isort≡msort = IsSort⇒≡ ISort.sort ISort.sort/correct MSort.sort MSort.sort/correct
|
{
"alphanum_fraction": 0.641832485,
"avg_line_length": 30.8714285714,
"ext": "agda",
"hexsha": "35027676887662ece77f97925ddd22452d8f2bef",
"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/Sorting/Sequential.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/Sorting/Sequential.agda",
"max_line_length": 89,
"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/Sorting/Sequential.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": 829,
"size": 2161
}
|
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- From: On the Bright Side of Type Classes: Instances Arguments in
-- Agda (ICFP'11).
module InstanceArguments where
open import Data.Bool.Base
open import Data.Nat hiding ( equal ) renaming ( suc to succ )
-- Note: Agda doesn't have a primitive function primBoolEquality.
boolEq : Bool → Bool → Bool
boolEq true true = true
boolEq false false = true
{-# CATCHALL #-}
boolEq _ _ = false
natEq : ℕ → ℕ → Bool
natEq zero zero = true
natEq (succ m) (succ n) = natEq m n
{-# CATCHALL #-}
natEq _ _ = false
record Eq (t : Set) : Set where
field equal : t → t → Bool
instance
eqInstanceBool : Eq Bool
eqInstanceBool = record { equal = boolEq }
eqInstanceℕ : Eq ℕ
eqInstanceℕ = record { equal = natEq }
equal : {t : Set} → {{eqT : Eq t}} → t → t → Bool
equal {{eqT}} = Eq.equal eqT
test : Bool
test = equal 5 3 ∨ equal true false
|
{
"alphanum_fraction": 0.6127497621,
"avg_line_length": 25.0238095238,
"ext": "agda",
"hexsha": "3754ae6f225756fb82bbf05e677c7971a81e7c81",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/type-classes/InstanceArguments.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/type-classes/InstanceArguments.agda",
"max_line_length": 67,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/type-classes/InstanceArguments.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": 300,
"size": 1051
}
|
-- WARNING: This file was generated automatically by Vehicle
-- and should not be modified manually!
-- Metadata
-- - Agda version: 2.6.2
-- - AISEC version: 0.1.0.1
-- - Time generated: ???
open import AISEC.Utils
open import Data.Real as ℝ using (ℝ)
open import Data.List
module MyTestModule where
f : Tensor ℝ (1 ∷ []) → Tensor ℝ (1 ∷ [])
f = evaluate record
{ databasePath = DATABASE_PATH
; networkUUID = NETWORK_UUID
}
increasing : ∀ (x : Tensor ℝ (1 ∷ [])) → let y = f (x) in x 0 ℝ.≤ y 0
increasing = checkProperty record
{ databasePath = DATABASE_PATH
; propertyUUID = ????
}
|
{
"alphanum_fraction": 0.657807309,
"avg_line_length": 25.0833333333,
"ext": "agda",
"hexsha": "7a8730e1e7db2bccee00d2f59b12939de15b96f9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Yiergot/vehicle",
"max_forks_repo_path": "examples/network/increasing/increasing-output.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "Yiergot/vehicle",
"max_issues_repo_path": "examples/network/increasing/increasing-output.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "Yiergot/vehicle",
"max_stars_repo_path": "examples/network/increasing/increasing-output.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 190,
"size": 602
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some specialised instances of the ring solver
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Tactic.RingSolver.Core.Polynomial.Parameters
-- Here, we provide proofs of homomorphism between the operations
-- defined on polynomials and those on the underlying ring.
module Tactic.RingSolver.Core.Polynomial.Homomorphism
{r₁ r₂ r₃ r₄}
(homo : Homomorphism r₁ r₂ r₃ r₄)
where
-- The lemmas are the general-purpose proofs we reuse in each other section
open import Tactic.RingSolver.Core.Polynomial.Homomorphism.Lemmas homo using (pow-cong) public
-- Proofs for each component of the polynomial
open import Tactic.RingSolver.Core.Polynomial.Homomorphism.Addition homo using (⊞-hom) public
open import Tactic.RingSolver.Core.Polynomial.Homomorphism.Multiplication homo using (⊠-hom) public
open import Tactic.RingSolver.Core.Polynomial.Homomorphism.Negation homo using (⊟-hom) public
open import Tactic.RingSolver.Core.Polynomial.Homomorphism.Exponentiation homo using (⊡-hom) public
open import Tactic.RingSolver.Core.Polynomial.Homomorphism.Constants homo using (κ-hom) public
open import Tactic.RingSolver.Core.Polynomial.Homomorphism.Variables homo using (ι-hom) public
|
{
"alphanum_fraction": 0.7016534867,
"avg_line_length": 47.9655172414,
"ext": "agda",
"hexsha": "c900ca53f600ad94ad426270c0b389fe8a98147e",
"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/Tactic/RingSolver/Core/Polynomial/Homomorphism.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/Tactic/RingSolver/Core/Polynomial/Homomorphism.agda",
"max_line_length": 102,
"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/Tactic/RingSolver/Core/Polynomial/Homomorphism.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": 333,
"size": 1391
}
|
{-
This module contains
- the type of vertical composition operations
that can be defined on a reflexive graph
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.DStructures.Structures.VertComp 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
open import Cubical.DStructures.Structures.Group
open import Cubical.DStructures.Structures.ReflGraph
open MorphismLemmas
open GroupLemmas
private
variable
ℓ ℓ' : Level
{-
-- The type of vertical composition operations
-- that can be defined over a reflexive graph 𝒢
--
-- we use the property isComposable instead of defining
-- a type of composable morphisms of G₁, because
-- otherwise it would be difficult to formulate
-- properties involving an odd number of composable morphisms
-- in a uniform and clean way.
-}
record VertComp (𝒢 : ReflGraph ℓ ℓ') : Type (ℓ-max ℓ ℓ') where
no-eta-equality
constructor vertcomp
open ReflGraphNotation 𝒢
open ReflGraphLemmas 𝒢
-- the vertical composition operation with convenient syntax
field
vcomp : (g f : ⟨ G₁ ⟩) → isComposable g f → ⟨ G₁ ⟩
syntax vcomp g f p = g ∘⟨ p ⟩ f
field
-- vcomp preserves source and target
σ-∘ : (g f : ⟨ G₁ ⟩) (c : isComposable g f) → s (g ∘⟨ c ⟩ f) ≡ s f
τ-∘ : (g f : ⟨ G₁ ⟩) (c : isComposable g f) → t (g ∘⟨ c ⟩ f) ≡ t g
-- vcomp is a homomorphism, also known as interchange law
isHom-∘ : (g f : ⟨ G₁ ⟩) (c : isComposable g f)
(g' f' : ⟨ G₁ ⟩) (c' : isComposable g' f')
(c'' : isComposable (g +₁ g') (f +₁ f'))
→ (g +₁ g') ∘⟨ c'' ⟩ (f +₁ f') ≡ (g ∘⟨ c ⟩ f) +₁ (g' ∘⟨ c' ⟩ f')
-- vcomp is associative
assoc-∘ : (h g f : ⟨ G₁ ⟩)
(c-hg : isComposable h g)
(c-gf : isComposable g f)
(c-h-gf : isComposable h (g ∘⟨ c-gf ⟩ f))
(c-hg-f : isComposable (h ∘⟨ c-hg ⟩ g) f)
→ h ∘⟨ c-h-gf ⟩ (g ∘⟨ c-gf ⟩ f) ≡ (h ∘⟨ c-hg ⟩ g) ∘⟨ c-hg-f ⟩ f
-- composing with identity arrows does nothing
lid-∘ : (f : ⟨ G₁ ⟩) (c : isComposable (𝒾 (t f)) f)
→ 𝒾 (t f) ∘⟨ c ⟩ f ≡ f
rid-∘ : (g : ⟨ G₁ ⟩) (c : isComposable g (𝒾 (s g))) → g ∘⟨ c ⟩ 𝒾 (s g) ≡ g
-- alternative lid/rid definition, but taking paramter c is more flexible
-- lid-∘ : (f : ⟨ G₁ ⟩) → 𝒾 (t f) ∘⟨ σι-≡-fun (t f) ⟩ f ≡ f
-- assoc-∘ : (h g f : ⟨ G₁ ⟩) (c : isComposable h g) (c' : isComposable g f)
-- → h ∘⟨ c ∙ sym (τ-∘ g f c') ⟩ (g ∘⟨ c' ⟩ f) ≡ (h ∘⟨ c ⟩ g) ∘⟨ σ-∘ h g c ∙ c' ⟩ f
-- → h ∘⟨ c-hg ∙ sym (τ-∘ g f c-gf) ⟩ (g ∘⟨ c-gf ⟩ f)
-- ≡ (h ∘⟨ c-hg ⟩ g) ∘⟨ σ-∘ h g c-hg ∙ c-gf ⟩ f
module _ {𝒢 : ReflGraph ℓ ℓ'} where
open ReflGraphNotation 𝒢
open ReflGraphLemmas 𝒢
-- lemmas about a given vertical composition
module _ (𝒞 : VertComp 𝒢) where
open VertComp 𝒞
-- These are all propositions, so we use abstract.
-- Most of these lemmas are nontrivial, because we need to keep a
-- proof of composability at hand.
abstract
-- if (g, f), and (g', f') are composable,
-- then so is (g + g', f + f')
+-c : (g f : ⟨ G₁ ⟩) (c : isComposable g f)
(g' f' : ⟨ G₁ ⟩) (c' : isComposable g' f')
→ isComposable (g +₁ g') (f +₁ f')
+-c g f c g' f' c' = σ .isHom g g'
∙∙ cong (_+₀ s g') c
∙∙ cong (t f +₀_) c'
∙ sym (τ .isHom f f')
-- if (g, f) is composable, and g ≡ g',
-- then (g', f) is composable
∘-cong-l-c : {g f : ⟨ G₁ ⟩} (c : isComposable g f)
{g' : ⟨ G₁ ⟩} (p : g ≡ g')
→ isComposable g' f
∘-cong-l-c c p = cong s (sym p) ∙ c
-- if (g, f) is composable, and f ≡ f',
-- then (g, f') is composable
∘-cong-r-c : {g f : ⟨ G₁ ⟩} (c : isComposable g f)
{f' : ⟨ G₁ ⟩} (p : f ≡ f')
→ isComposable g f'
∘-cong-r-c c p = c ∙ cong t p
-- if (g, f) are composable, and (g, f) ≡ (g', f'),
-- then (g', f') is composable
-- by combining the two lemmas above
∘-cong-c : {g f : ⟨ G₁ ⟩} (c : isComposable g f)
{g' f' : ⟨ G₁ ⟩} (p : g ≡ g') (q : f ≡ f')
→ isComposable g' f'
∘-cong-c c p q = ∘-cong-l-c c p ∙ cong t q
-- if (g, f) is composable, and g ≡ g',
-- then g ∘ f ≡ g' ∘ f
∘-cong-l : {g f : ⟨ G₁ ⟩} (c : isComposable g f)
{g' : ⟨ G₁ ⟩} (p : g ≡ g')
→ g ∘⟨ c ⟩ f ≡ g' ∘⟨ ∘-cong-l-c c p ⟩ f
∘-cong-l {g = g} {f = f} c {g'} p = cong₂ (λ h d → h ∘⟨ d ⟩ f)
p
(toPathP (isPropIsComposable g'
f
(transp (λ i → isComposable (p i) f) i0 c)
(∘-cong-l-c c p)))
-- if (g, f) is composable, and f ≡ f',
-- then g ∘ f ≡ g ∘ f'
∘-cong-r : {g f : ⟨ G₁ ⟩} (c : isComposable g f)
{f' : ⟨ G₁ ⟩} (p : f ≡ f')
→ g ∘⟨ c ⟩ f ≡ g ∘⟨ ∘-cong-r-c c p ⟩ f'
∘-cong-r {g = g} c {f'} p = cong₂ (λ h d → g ∘⟨ d ⟩ h)
p
(toPathP (isPropIsComposable g
f'
(transp (λ i → isComposable g (p i)) i0 c)
(∘-cong-r-c c p)))
-- if (g, f) are composable, and (g, f) ≡ (g', f'),
-- then g ∘ f ≡ g' ∘ f'
∘-cong : {g f : ⟨ G₁ ⟩} (c : isComposable g f)
{g' f' : ⟨ G₁ ⟩} (p : g ≡ g') (q : f ≡ f')
→ g ∘⟨ c ⟩ f ≡ g' ∘⟨ ∘-cong-c c p q ⟩ f'
∘-cong c p q = ∘-cong-l c p
∙ ∘-cong-r (∘-cong-l-c c p) q
-- an alternate version of lid-∘
-- where a composable g is assumed and ι (σ g)
-- instead of ι (τ f) is used
∘-lid' : {g f : ⟨ G₁ ⟩} (c : isComposable g f)
(c' : isComposable (𝒾s g) f)
→ (𝒾s g) ∘⟨ c' ⟩ f ≡ f
∘-lid' {g} {f} c c' = (𝒾s g) ∘⟨ c' ⟩ f
≡⟨ ∘-cong-l c' (cong 𝒾 c) ⟩
𝒾t f ∘⟨ ∘-cong-l-c c' (cong 𝒾 c) ⟩ f
≡⟨ lid-∘ f (∘-cong-l-c c' (cong 𝒾 c)) ⟩
f ∎
-- Fundamental theorem:
-- Any vertical composition is necessarily of the form
-- g ∘⟨ _ ⟩ f ≡ g - ι (σ g) + f
-- This implies contractibility of VertComp 𝒢
VertComp→+₁ : (g f : ⟨ G₁ ⟩) (c : isComposable g f)
→ g ∘⟨ c ⟩ f ≡ (g -₁ 𝒾s g) +₁ f
VertComp→+₁ g f c = g ∘⟨ c ⟩ f
≡⟨ ∘-cong c
(sym (rId₁ g) ∙ cong (g +₁_) (sym (lCancel₁ isg)))
(sym (lId₁ f) ∙ cong (_+₁ f) (sym (rCancel₁ isg))) ⟩
(g +₁ (-isg +₁ isg)) ∘⟨ c₁ ⟩ ((isg -₁ isg) +₁ f)
≡⟨ ∘-cong-l c₁ (assoc₁ g -isg isg) ⟩
((g -₁ isg) +₁ isg) ∘⟨ c₂ ⟩ ((isg -₁ isg) +₁ f)
≡⟨ isHom-∘ (g -₁ isg) (isg -₁ isg) c₄
isg f c₃
c₂ ⟩
((g +₁ -isg) ∘⟨ c₄ ⟩ (isg +₁ -isg)) +₁ (isg ∘⟨ c₃ ⟩ f)
≡⟨ cong (_+₁ (isg ∘⟨ c₃ ⟩ f))
(isHom-∘ g isg c₅ -isg -isg c₆ c₄) ⟩
((g ∘⟨ c₅ ⟩ isg) +₁ (-isg ∘⟨ c₆ ⟩ -isg)) +₁ (isg ∘⟨ c₃ ⟩ f)
≡⟨ cong (λ z → (z +₁ (-isg ∘⟨ c₆ ⟩ -isg)) +₁ (isg ∘⟨ c₃ ⟩ f))
(rid-∘ g (isComp-g-isg g)) ⟩
(g +₁ (-isg ∘⟨ c₆ ⟩ -isg)) +₁ (isg ∘⟨ c₃ ⟩ f)
≡⟨ cong ((g +₁ (-isg ∘⟨ c₆ ⟩ -isg)) +₁_)
(∘-lid' c c₃) ⟩
(g +₁ (-isg ∘⟨ c₆ ⟩ -isg)) +₁ f
≡⟨ cong (λ z → (g +₁ z) +₁ f)
(-isg ∘⟨ c₆ ⟩ -isg
≡⟨ ∘-cong-r c₆
-- prove that is(-isg)≡-isg
(sym (cong 𝒾s (sym (mapInv ι (s g)))
∙∙ cong 𝒾 (σι-≡-fun (-₀ s g))
∙∙ mapInv ι (s g))) ⟩
-isg ∘⟨ c₈ ⟩ (𝒾s -isg)
≡⟨ rid-∘ -isg c₈ ⟩
-isg ∎) ⟩
(g -₁ isg) +₁ f ∎
where
-- abbreviations to reduce the amount of parentheses
isg = 𝒾s g
-isg = -₁ isg
itf = 𝒾t f
-- composability proofs,
-- none of which are really interesting.
c₁ : isComposable (g +₁ (-isg +₁ isg)) ((isg -₁ isg) +₁ f)
c₁ = ∘-cong-c c
(sym (rId₁ g) ∙ cong (g +₁_) (sym (lCancel₁ isg)))
(sym (lId₁ f) ∙ cong (_+₁ f) (sym (rCancel₁ isg)))
c₂ : isComposable ((g -₁ isg) +₁ isg) ((isg -₁ isg) +₁ f)
c₂ = ∘-cong-l-c c₁ (assoc₁ g -isg isg)
c₃ : isComposable isg f
c₃ = σι-≡-fun (s g) ∙ c
c₄ : isComposable (g -₁ isg) (isg -₁ isg)
c₄ = s (g -₁ isg)
≡⟨ σ-g--isg g ⟩
0₀
≡⟨ sym (cong t (rCancel₁ isg) ∙ mapId τ) ⟩
t (isg -₁ isg) ∎
c₅ : isComposable g isg
c₅ = isComp-g-isg g
c₆ : isComposable -isg -isg
c₆ = s -isg
≡⟨ mapInv σ isg ⟩
-₀ (s isg)
≡⟨ cong -₀_ (σι-≡-fun (s g)) ⟩
-₀ (s g)
≡⟨ cong -₀_ (sym (τι-≡-fun (s g))) ⟩
-₀ (t isg)
≡⟨ sym (mapInv τ isg) ⟩
t -isg ∎
c₈ : isComposable -isg (𝒾s -isg)
c₈ = ∘-cong-r-c c₆
(sym (cong 𝒾s (sym (mapInv ι (s g)))
∙∙ cong 𝒾 (σι-≡-fun (-₀ s g))
∙∙ mapInv ι (s g)))
-- properties of the interchange law
IC2 : (g g' f : ⟨ G₁ ⟩) (c-gf : isComposable g f)
→ (g' +₁ (-is g' -₁ is g)) +₁ f ≡ (-is g +₁ f) +₁ (g' -₁ is g')
IC2 g g' f c-gf =
(g' +₁ (-isg' +₁ -isg)) +₁ f
≡⟨ cong ((g' +₁ (-isg' +₁ -isg)) +₁_)
(sym (rCancel-rId G₁ f f') ∙ assoc₁ f f' -f') ⟩
(g' +₁ (-isg' +₁ -isg)) +₁ ((f +₁ f') -₁ f')
≡⟨ assoc₁ (g' +₁ (-isg' +₁ -isg)) (f +₁ f') (-₁ f') ⟩
((g' +₁ (-isg' +₁ -isg)) +₁ (f +₁ f')) -₁ f'
≡⟨ cong (_-₁ f')
(sym (lCancel-lId G₁ g _)) ⟩
((-g +₁ g) +₁ ((g' +₁ (-isg' +₁ -isg)) +₁ (f +₁ f'))) -₁ f'
≡⟨ cong (_-₁ f')
(sym (assoc₁ -g g _)) ⟩
(-g +₁ (g +₁ ((g' +₁ (-isg' +₁ -isg)) +₁ (f +₁ f')))) -₁ f'
≡⟨ cong (λ z → (-g +₁ z) -₁ f')
(assoc₁ g _ (f +₁ f')) ⟩
(-g +₁ ((g +₁ (g' +₁ (-isg' +₁ -isg))) +₁ (f +₁ f'))) -₁ f'
≡⟨ cong (λ z → (-g +₁ (z +₁ (f +₁ f'))) -₁ f')
(assoc₁ g g' (-isg' -₁ isg)) ⟩
(-g +₁ (((g +₁ g') +₁ (-isg' +₁ -isg)) +₁ (f +₁ f'))) -₁ f'
≡⟨ cong (λ z → (-g +₁ z) -₁ f')
(sym q) ⟩
(-g +₁ ((g +₁ g') ∘⟨ c-gf'+ ⟩ (f +₁ f'))) -₁ f'
≡⟨ cong (λ z → (-g +₁ z) -₁ f')
(isHom-∘ g f c-gf
g' f' c-gf'
c-gf'+) ⟩
(-g +₁ ((g ∘⟨ c-gf ⟩ f) +₁ (g' ∘⟨ c-gf' ⟩ f'))) -₁ f'
≡⟨ cong (λ z → (-g +₁ ((g ∘⟨ c-gf ⟩ f) +₁ z)) -₁ f')
(VertComp→+₁ g' f' c-gf') ⟩
(-g +₁ ((g ∘⟨ c-gf ⟩ f) +₁ ((g' -₁ isg') +₁ f'))) -₁ f'
≡⟨ cong (λ z → (-g +₁ (z +₁ ((g' -₁ isg') +₁ f'))) -₁ f')
(VertComp→+₁ g f c-gf) ⟩
(-g +₁ (((g -₁ isg) +₁ f) +₁ ((g' -₁ isg') +₁ f'))) -₁ f'
≡⟨ cong (λ z → (-g +₁ (z +₁ ((g' -₁ isg') +₁ f'))) -₁ f')
(sym (assoc₁ g -isg f)) ⟩
(-g +₁ ((g +₁ (-isg +₁ f)) +₁ ((g' -₁ isg') +₁ f'))) -₁ f'
≡⟨ cong (λ z → (-g +₁ z) -₁ f')
(sym (assoc₁ g (-isg +₁ f) _)) ⟩
(-g +₁ (g +₁ ((-isg +₁ f) +₁ ((g' -₁ isg') +₁ f')))) -₁ f'
≡⟨ cong (_-₁ f')
(assoc₁ -g g _) ⟩
((-g +₁ g) +₁ ((-isg +₁ f) +₁ ((g' -₁ isg') +₁ f'))) -₁ f'
≡⟨ cong (_-₁ f')
(lCancel-lId G₁ g _) ⟩
((-isg +₁ f) +₁ ((g' -₁ isg') +₁ f')) -₁ f'
≡⟨ sym (assoc₁ (-isg +₁ f) _ -f') ⟩
(-isg +₁ f) +₁ (((g' -₁ isg') +₁ f') -₁ f')
≡⟨ cong ((-isg +₁ f) +₁_)
(sym (assoc₁ (g' -₁ isg') f' -f')) ⟩
(-isg +₁ f) +₁ ((g' -₁ isg') +₁ (f' -₁ f'))
≡⟨ cong ((-isg +₁ f) +₁_ )
(rCancel-rId G₁ (g' -₁ isg') f') ⟩
(-isg +₁ f) +₁ (g' -₁ isg') ∎
where
-- abbreviations to reduce the number of parentheses
-g = -₁ g
isg = 𝒾s g
isg' = 𝒾s g'
-isg = -₁ isg
-isg' = -₁ isg'
f' = isg'
-f' = -₁ f'
-- composability proofs
c-gf' = isComp-g-isg g'
c-gf'+ = +-c g f c-gf g' f' c-gf'
--
q = (g +₁ g') ∘⟨ c-gf'+ ⟩ (f +₁ f')
≡⟨ VertComp→+₁ (g +₁ g') (f +₁ f') c-gf'+ ⟩
((g +₁ g') -₁ (𝒾s (g +₁ g'))) +₁ (f +₁ f')
≡⟨ cong (λ z → ((g +₁ g') -₁ z) +₁ (f +₁ f'))
(ι∘σ .isHom g g') ⟩
((g +₁ g') -₁ (isg +₁ isg')) +₁ (f +₁ f')
≡⟨ cong (λ z → ((g +₁ g') +₁ z) +₁ (f +₁ f'))
(invDistr G₁ isg isg') ⟩
((g +₁ g') +₁ (-isg' +₁ -isg)) +₁ (f +₁ f') ∎
IC3 : (g g' f : ⟨ G₁ ⟩) (c-gf : isComposable g f)
→ (-₁ f) +₁ ((is g +₁ is g') -₁ g') ≡ (is g' -₁ g') +₁ ((-₁ f) +₁ is g)
IC3 g g' f c-gf =
-f +₁ ((isg +₁ isg') -₁ g')
≡⟨ cong (λ z → -f +₁ ((isg +₁ z) -₁ g'))
(sym (invInvo G₁ isg')) ⟩
-f +₁ ((isg -₁ -isg') -₁ g')
≡⟨ cong (λ z → -f +₁ ((z -₁ -isg') -₁ g'))
(sym (invInvo G₁ isg)) ⟩
-f +₁ (((-₁ -isg) -₁ -isg') -₁ g')
≡⟨ cong (λ z → -f +₁ (z -₁ g'))
(sym (invDistr G₁ -isg' -isg)) ⟩
-f +₁ ((-₁ (-isg' +₁ -isg)) -₁ g')
≡⟨ cong (λ z → -f +₁ z)
(sym (invDistr G₁ g' (-isg' +₁ -isg))) ⟩
-f -₁ (g' +₁ (-isg' +₁ -isg))
≡⟨ sym (invDistr G₁ _ f) ⟩
-₁ ((g' +₁ (-isg' +₁ -isg)) +₁ f)
≡⟨ cong -₁_
(IC2 g g' f c-gf) ⟩
-₁ ((-isg +₁ f) +₁ (g' -₁ isg'))
≡⟨ invDistr G₁ (-isg +₁ f) (g' -₁ isg') ⟩
(-₁ (g' -₁ isg')) +₁ (-₁ (-isg +₁ f))
≡⟨ cong ((-₁ (g' -₁ isg')) +₁_)
(invDistr G₁ -isg f) ⟩
(-₁ (g' -₁ isg')) +₁ (-f -₁ -isg)
≡⟨ cong (_+₁ (-f -₁ -isg))
(invDistr G₁ g' -isg') ⟩
((-₁ -isg') -₁ g') +₁ (-f -₁ -isg)
≡⟨ cong (λ z → (z -₁ g') +₁ (-f -₁ -isg))
(invInvo G₁ isg') ⟩
(isg' -₁ g') +₁ (-f -₁ -isg)
≡⟨ cong (λ z → (isg' -₁ g') +₁ (-f +₁ z))
(invInvo G₁ isg) ⟩
(isg' -₁ g') +₁ (-f +₁ isg) ∎
where
-f = -₁ f
-g = -₁ g
isg = 𝒾s g
isg' = 𝒾s g'
-isg = -₁ isg
-isg' = -₁ isg'
IC4 : (g g' f : ⟨ G₁ ⟩) (c-gf : isComposable g f)
→ f +₁ (((-is g) -₁ (is g')) +₁ g') ≡ ((-is g') +₁ g') +₁ (f -₁ (is g))
IC4 g g' f c-gf =
f +₁ ((-isg -₁ isg') +₁ g')
≡⟨ cong (λ z → f +₁ ((-isg -₁ isg') +₁ z))
(sym (invInvo G₁ g')) ⟩
(f +₁ ((-isg -₁ isg') -₁ -g'))
≡⟨ cong (λ z → f +₁ ((-isg +₁ z) -₁ -g'))
(sym (mapInv ι∘σ g')) ⟩
f +₁ ((-isg +₁ (is- g')) -₁ -g')
≡⟨ cong (λ z → f +₁ ((z +₁ (is- g')) -₁ -g'))
(sym (mapInv ι∘σ g)) ⟩
f +₁ (((is- g) +₁ (is- g')) -₁ -g')
≡⟨ cong (_+₁ ((is- g +₁ is- g') -₁ -g'))
(sym (invInvo G₁ f)) ⟩
(-₁ -f) +₁ (((is- g) +₁ (is- g')) -₁ -g')
≡⟨ IC3 -g -g' -f c--gf ⟩
((is- g') -₁ -g') +₁ ((-₁ -f) +₁ (is- g))
≡⟨ cong (λ z → (z -₁ -g') +₁ ((-₁ -f) +₁ (is- g)))
(mapInv ι∘σ g') ⟩
(-isg' -₁ -g') +₁ ((-₁ -f) +₁ (is- g))
≡⟨ cong (λ z → (-isg' +₁ z) +₁ ((-₁ -f) +₁ (is- g)))
(invInvo G₁ g') ⟩
(-isg' +₁ g') +₁ ((-₁ -f) +₁ (is- g))
≡⟨ cong (λ z → (-isg' +₁ g') +₁ (z +₁ (is- g)))
(invInvo G₁ f) ⟩
(-isg' +₁ g') +₁ (f +₁ (is- g))
≡⟨ cong (λ z → (-isg' +₁ g') +₁ (f +₁ z))
(mapInv ι∘σ g) ⟩
(-isg' +₁ g') +₁ (f -₁ isg) ∎
where
-f = -₁ f
-g = -₁ g
-g' = -₁ g'
isg = 𝒾s g
isg' = 𝒾s g'
-isg = -₁ isg
-isg' = -₁ isg'
c--gf = s -g
≡⟨ mapInv σ g ⟩
-₀ (s g)
≡⟨ cong -₀_ c-gf ⟩
-₀ (t f)
≡⟨ sym (mapInv τ f) ⟩
t -f ∎
-- g = itf
IC5 : (g' f : ⟨ G₁ ⟩)
→ f +₁ (((-it f) -₁ (is g')) +₁ g') ≡ ((-is g') +₁ g') +₁ (f -₁ (it f))
IC5 g' f =
f +₁ ((-itf -₁ isg') +₁ g')
≡⟨ cong (λ z → f +₁ (((-₁ (𝒾 z)) -₁ isg') +₁ g'))
(sym c-gf) ⟩
f +₁ ((-isg -₁ isg') +₁ g')
≡⟨ IC4 g g' f c-gf ⟩
(-isg' +₁ g') +₁ (f -₁ isg)
≡⟨ cong (λ z → (-isg' +₁ g') +₁ (f -₁ (𝒾 z)))
c-gf ⟩
(-isg' +₁ g') +₁ (f -₁ itf) ∎
where
-f = -₁ f
-itf = -it f
itf = it f
g = it f
-g = -₁ g
-g' = -₁ g'
isg = 𝒾s g
isg' = 𝒾s g'
-isg = -₁ isg
-isg' = -₁ isg'
c-gf : isComposable g f
c-gf = isComp-itf-f f
open VertComp
-- the record VertComp has no eta equality, so this can be used to
-- construct paths between vertical compositions
η-VertComp : (𝒱 : VertComp 𝒢) → vertcomp (vcomp 𝒱) (σ-∘ 𝒱) (τ-∘ 𝒱) (isHom-∘ 𝒱) (assoc-∘ 𝒱) (lid-∘ 𝒱) (rid-∘ 𝒱) ≡ 𝒱
vcomp (η-VertComp 𝒱 i) = vcomp 𝒱
σ-∘ (η-VertComp 𝒱 i) = σ-∘ 𝒱
τ-∘ (η-VertComp 𝒱 i) = τ-∘ 𝒱
isHom-∘ (η-VertComp 𝒱 i) = isHom-∘ 𝒱
assoc-∘ (η-VertComp 𝒱 i) = assoc-∘ 𝒱
lid-∘(η-VertComp 𝒱 i) = lid-∘ 𝒱
rid-∘ (η-VertComp 𝒱 i) = rid-∘ 𝒱
-- this is just a helper for the module below
module _ (𝒞 𝒞' : VertComp 𝒢) where
p∘ : vcomp 𝒞 ≡ vcomp 𝒞'
p∘ = funExt₃ (λ g f c → VertComp→+₁ 𝒞 g f c ∙ sym (VertComp→+₁ 𝒞' g f c))
pσ : PathP (λ j → (g f : ⟨ G₁ ⟩) (c : isComposable g f) → s (p∘ j g f c) ≡ s f) (σ-∘ 𝒞) (σ-∘ 𝒞')
pσ = isProp→PathP (λ i → isPropΠ3 (λ g f c → set₀ (s (p∘ i g f c)) (s f))) (σ-∘ 𝒞) (σ-∘ 𝒞')
passoc : PathP (λ i → (h g f : ⟨ G₁ ⟩)
(c-hg : isComposable h g)
(c-gf : isComposable g f)
(c-h-gf : isComposable h (p∘ i g f c-gf))
(c-hg-f : isComposable (p∘ i h g c-hg) f) →
p∘ i h (p∘ i g f c-gf) c-h-gf ≡ p∘ i (p∘ i h g c-hg) f c-hg-f) (assoc-∘ 𝒞) (assoc-∘ 𝒞')
passoc = isProp→PathP (λ j → isPropΠ4 (λ h g f c-hg → isPropΠ3 (λ c-gf c-h-gf c-hg-f → set₁ (p∘ j h (p∘ j g f c-gf) c-h-gf) (p∘ j (p∘ j h g c-hg) f c-hg-f)))) (assoc-∘ 𝒞) (assoc-∘ 𝒞')
-- (p∘ j h (p∘ j g f c-gf) c-h-gf ≡ p∘ j (p∘ j h g c-hg) f c-hg-f)
-- proof that there is at most one vertical composition on a reflexive graph
module _ (𝒢 : ReflGraph ℓ ℓ') where
open ReflGraphNotation 𝒢
open ReflGraphLemmas 𝒢
open VertComp
isPropVertComp : isProp (VertComp 𝒢)
vcomp (isPropVertComp 𝒞 𝒞' i) = funExt₃ (λ g f c → VertComp→+₁ 𝒞 g f c ∙ sym (VertComp→+₁ 𝒞' g f c)) i
-- σ-∘ (isPropVertComp 𝒞 𝒞' i) = funExt₃ P i
σ-∘ (isPropVertComp 𝒞 𝒞' i) = pσ 𝒞 𝒞' i
where
P : (g f : ⟨ G₁ ⟩) (c : isComposable g f)
→ PathP (λ j → s (vcomp (isPropVertComp 𝒞 𝒞' j) g f c) ≡ s f)
(σ-∘ 𝒞 g f c)
(σ-∘ 𝒞' g f c)
P g f c = isProp→PathP (λ j → set₀ (s (vcomp (isPropVertComp 𝒞 𝒞' j) g f c)) (s f)) (σ-∘ 𝒞 g f c) (σ-∘ 𝒞' g f c)
τ-∘ (isPropVertComp 𝒞 𝒞' i) = funExt₃ P i
where
P : (g f : ⟨ G₁ ⟩) (c : isComposable g f) → PathP (λ j → t (vcomp (isPropVertComp 𝒞 𝒞' j) g f c) ≡ t g) (τ-∘ 𝒞 g f c) (τ-∘ 𝒞' g f c)
P g f c = isProp→PathP (λ j → set₀ (t (vcomp (isPropVertComp 𝒞 𝒞' j) g f c)) (t g)) (τ-∘ 𝒞 g f c) (τ-∘ 𝒞' g f c)
isHom-∘ (isPropVertComp 𝒞 𝒞' i) = funExt₃ (λ g f c → funExt₃ (λ g' f' c' → funExt (λ c+ → P g f c g' f' c' c+))) i
where
P : (g f : ⟨ G₁ ⟩) (c : isComposable g f)
(g' f' : ⟨ G₁ ⟩) (c' : isComposable g' f')
(c+ : isComposable (g +₁ g') (f +₁ f'))
→ PathP (λ j → vcomp (isPropVertComp 𝒞 𝒞' j) (g +₁ g') (f +₁ f') c+
≡ (vcomp (isPropVertComp 𝒞 𝒞' j) g f c) +₁ (vcomp (isPropVertComp 𝒞 𝒞' j) g' f' c'))
(isHom-∘ 𝒞 g f c g' f' c' c+)
(isHom-∘ 𝒞' g f c g' f' c' c+)
P g f c g' f' c' c+ = isProp→PathP (λ j → set₁ (vcomp (isPropVertComp 𝒞 𝒞' j) (g +₁ g') (f +₁ f') c+)
((vcomp (isPropVertComp 𝒞 𝒞' j) g f c) +₁ (vcomp (isPropVertComp 𝒞 𝒞' j) g' f' c')))
(isHom-∘ 𝒞 g f c g' f' c' c+)
(isHom-∘ 𝒞' g f c g' f' c' c+)
assoc-∘ (isPropVertComp 𝒞 𝒞' i) = passoc 𝒞 𝒞' i
lid-∘ (isPropVertComp 𝒞 𝒞' i) = funExt₂ P i
where
P : (f : ⟨ G₁ ⟩) (c : isComposable (𝒾 (t f)) f)
→ PathP (λ j → vcomp (isPropVertComp 𝒞 𝒞' j) (𝒾 (t f)) f c ≡ f) (lid-∘ 𝒞 f c) (lid-∘ 𝒞' f c)
P f c = isProp→PathP (λ j → set₁ (vcomp (isPropVertComp 𝒞 𝒞' j) (𝒾 (t f)) f c) f) (lid-∘ 𝒞 f c) (lid-∘ 𝒞' f c)
rid-∘ (isPropVertComp 𝒞 𝒞' i) = funExt₂ P i
where
P : (g : ⟨ G₁ ⟩) (c : isComposable g (𝒾 (s g)))
→ PathP (λ j → vcomp (isPropVertComp 𝒞 𝒞' j) g (𝒾 (s g)) c ≡ g) (rid-∘ 𝒞 g c) (rid-∘ 𝒞' g c)
P g c = isProp→PathP (λ j → set₁ (vcomp (isPropVertComp 𝒞 𝒞' j) g (𝒾 (s g)) c) g) (rid-∘ 𝒞 g c) (rid-∘ 𝒞' g c)
|
{
"alphanum_fraction": 0.3701865988,
"avg_line_length": 44.6590909091,
"ext": "agda",
"hexsha": "267d900ffe18b4f133967ad24bef83a382de88f2",
"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/VertComp.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/VertComp.agda",
"max_line_length": 187,
"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/VertComp.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9739,
"size": 23580
}
|
module FFI.Data.String where
import Agda.Builtin.String
String = Agda.Builtin.String.String
infixr 5 _++_
_++_ = Agda.Builtin.String.primStringAppend
|
{
"alphanum_fraction": 0.7843137255,
"avg_line_length": 17,
"ext": "agda",
"hexsha": "5bb315cf3ed1d0afa4d89b84936d1a952ef368a5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "XanderYZZ/luau",
"max_forks_repo_path": "prototyping/FFI/Data/String.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "XanderYZZ/luau",
"max_issues_repo_path": "prototyping/FFI/Data/String.agda",
"max_line_length": 43,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "TheGreatSageEqualToHeaven/luau",
"max_stars_repo_path": "prototyping/FFI/Data/String.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z",
"num_tokens": 45,
"size": 153
}
|
-- Dummy file.
|
{
"alphanum_fraction": 0.6,
"avg_line_length": 7.5,
"ext": "agda",
"hexsha": "341c03aad60d00bd990be17132ba927fc576c7b1",
"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/Issue4835.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/Issue4835.agda",
"max_line_length": 14,
"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/Issue4835.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": 4,
"size": 15
}
|
module Numeral.Natural.Prime.Proofs.Product where
import Lvl
open import Data.Either as Either using ()
open import Functional
open import Lang.Instance
open import Logic.Propositional
open import Numeral.Natural
open import Numeral.Natural.Relation.Divisibility.Proofs
open import Numeral.Natural.Oper
open import Numeral.Natural.Prime
open import Numeral.Natural.Relation.Divisibility.Proofs.Product
open import Sets.PredicateSet renaming (_≡_ to _≡ₛ_)
open import Type
private variable a b : ℕ
-- The prime factors of a product is the prime factors of its factors.
product-primeFactors : PrimeFactor(a ⋅ b) ≡ₛ (PrimeFactor(a) ∪ PrimeFactor(b))
product-primeFactors = [↔]-intro l r where
l : PrimeFactor(a ⋅ b) ⊇ (PrimeFactor(a) ∪ PrimeFactor(b))
l{a}{b}{x} (Either.Left intro) = intro ⦃ factor = divides-with-[⋅] {x}{a}{b} ([∨]-introₗ infer) ⦄
l{a}{b}{x} (Either.Right intro) = intro ⦃ factor = divides-with-[⋅] {x}{a}{b} ([∨]-introᵣ infer) ⦄
r : PrimeFactor(a ⋅ b) ⊆ (PrimeFactor(a) ∪ PrimeFactor(b))
r{a}{b}{x} intro = Either.map (p ↦ intro ⦃ factor = p ⦄) (p ↦ intro ⦃ factor = p ⦄) (prime-divides-of-[⋅] {x}{a}{b} infer infer)
|
{
"alphanum_fraction": 0.7071057192,
"avg_line_length": 42.7407407407,
"ext": "agda",
"hexsha": "12c7332d8fd455de1bc8129caf32d7f2ed7905cc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Natural/Prime/Proofs/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Prime/Proofs/Product.agda",
"max_line_length": 130,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Natural/Prime/Proofs/Product.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": 390,
"size": 1154
}
|
open import Nat
open import Prelude
open import core
open import contexts
module typ-dec where
lemma-arr-l : ∀{t1 t2 t4} → t1 ==> t2 == t1 ==> t4 → t2 == t4
lemma-arr-l refl = refl
lemma-arr-r : ∀{t1 t2 t3} → t1 ==> t2 == t3 ==> t2 → t1 == t3
lemma-arr-r refl = refl
lemma-arr-b : ∀{t1 t2 t3 t4} → t1 ==> t2 == t3 ==> t4 → t1 == t3
lemma-arr-b refl = refl
lemma-prod-l : ∀{t1 t2 t4} → t1 ⊗ t2 == t1 ⊗ t4 → t2 == t4
lemma-prod-l refl = refl
lemma-prod-r : ∀{t1 t2 t3} → t1 ⊗ t2 == t3 ⊗ t2 → t1 == t3
lemma-prod-r refl = refl
lemma-prod-b : ∀{t1 t2 t3 t4} → t1 ⊗ t2 == t3 ⊗ t4 → t1 == t3
lemma-prod-b refl = refl
-- types are decidable
typ-dec : dec typ
typ-dec b b = Inl refl
typ-dec b ⦇·⦈ = Inr (λ ())
typ-dec b (t2 ==> t3) = Inr (λ ())
typ-dec ⦇·⦈ b = Inr (λ ())
typ-dec ⦇·⦈ ⦇·⦈ = Inl refl
typ-dec ⦇·⦈ (t2 ==> t3) = Inr (λ ())
typ-dec (t1 ==> t2) b = Inr (λ ())
typ-dec (t1 ==> t2) ⦇·⦈ = Inr (λ ())
typ-dec (t1 ==> t2) (t3 ==> t4) with typ-dec t1 t3 | typ-dec t2 t4
typ-dec (t1 ==> t2) (.t1 ==> .t2) | Inl refl | Inl refl = Inl refl
typ-dec (t1 ==> t2) (.t1 ==> t4) | Inl refl | Inr x₁ = Inr (λ x → x₁ (lemma-arr-l x))
typ-dec (t1 ==> t2) (t3 ==> .t2) | Inr x | Inl refl = Inr (λ x₁ → x (lemma-arr-r x₁))
typ-dec (t1 ==> t2) (t3 ==> t4) | Inr x | Inr x₁ = Inr (λ x₂ → x (lemma-arr-b x₂))
typ-dec b (t2 ⊗ t3) = Inr (λ ())
typ-dec ⦇·⦈ (t2 ⊗ t3) = Inr (λ ())
typ-dec (t1 ==> t2) (t3 ⊗ t4) = Inr (λ ())
typ-dec (t1 ⊗ t2) b = Inr (λ ())
typ-dec (t1 ⊗ t2) ⦇·⦈ = Inr (λ ())
typ-dec (t1 ⊗ t2) (t3 ==> t4) = Inr (λ ())
typ-dec (t1 ⊗ t2) (t3 ⊗ t4) with typ-dec t1 t3 | typ-dec t2 t4
typ-dec (t1 ⊗ t2) (.t1 ⊗ .t2) | Inl refl | Inl refl = Inl refl
typ-dec (t1 ⊗ t2) (.t1 ⊗ t4) | Inl refl | Inr x₁ = Inr (λ x → x₁ (lemma-prod-l x))
typ-dec (t1 ⊗ t2) (t3 ⊗ .t2) | Inr x | Inl refl = Inr (λ x' → x (lemma-prod-r x'))
typ-dec (t1 ⊗ t2) (t3 ⊗ t4) | Inr x | Inr x₁ = Inr (λ x' → x (lemma-prod-b x'))
-- if an arrow is disequal, it disagrees in the first or second argument
ne-factor : ∀{τ1 τ2 τ3 τ4} → (τ1 ==> τ2) ≠ (τ3 ==> τ4) → (τ1 ≠ τ3) + (τ2 ≠ τ4)
ne-factor {τ1} {τ2} {τ3} {τ4} ne with typ-dec τ1 τ3 | typ-dec τ2 τ4
ne-factor ne | Inl refl | Inl refl = Inl (λ x → ne refl)
ne-factor ne | Inl x | Inr x₁ = Inr x₁
ne-factor ne | Inr x | Inl x₁ = Inl x
ne-factor ne | Inr x | Inr x₁ = Inl x
|
{
"alphanum_fraction": 0.5072886297,
"avg_line_length": 40.6949152542,
"ext": "agda",
"hexsha": "34eb6a106e7753e3a36699c5f76784f7c9beed78",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-livelits-agda",
"max_forks_repo_path": "typ-dec.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_issues_repo_issues_event_max_datetime": "2020-10-20T20:44:13.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-30T20:27:56.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazel-palette-agda",
"max_issues_repo_path": "typ-dec.agda",
"max_line_length": 91,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazel-palette-agda",
"max_stars_repo_path": "typ-dec.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T15:38:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-04T06:45:06.000Z",
"num_tokens": 1194,
"size": 2401
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Functions.Fibration where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Data.Sigma
private
variable
ℓ ℓb : Level
B : Type ℓb
module FiberIso {ℓ} (p⁻¹ : B → Type ℓ) (x : B) where
p : Σ B p⁻¹ → B
p = fst
fwd : fiber p x → p⁻¹ x
fwd ((x' , y) , q) = subst (λ z → p⁻¹ z) q y
bwd : p⁻¹ x → fiber p x
bwd y = (x , y) , refl
fwd-bwd : ∀ x → fwd (bwd x) ≡ x
fwd-bwd y = transportRefl y
bwd-fwd : ∀ x → bwd (fwd x) ≡ x
bwd-fwd ((x' , y) , q) i = h (r i)
where h : Σ[ s ∈ singl x ] p⁻¹ (s .fst) → fiber p x
h ((x , p) , y) = (x , y) , sym p
r : Path (Σ[ s ∈ singl x ] p⁻¹ (s .fst))
((x , refl ) , subst p⁻¹ q y)
((x' , sym q) , y )
r = ΣPathP (isContrSingl x .snd (x' , sym q)
, toPathP (transport⁻Transport (λ i → p⁻¹ (q i)) y))
-- HoTT Lemma 4.8.1
fiberEquiv : fiber p x ≃ p⁻¹ x
fiberEquiv = isoToEquiv (iso fwd bwd fwd-bwd bwd-fwd)
open FiberIso using (fiberEquiv) public
module _ {ℓ} {E : Type ℓ} (p : E → B) where
-- HoTT Lemma 4.8.2
totalEquiv : E ≃ Σ B (fiber p)
totalEquiv = isoToEquiv isom
where isom : Iso E (Σ B (fiber p))
Iso.fun isom x = p x , x , refl
Iso.inv isom (b , x , q) = x
Iso.leftInv isom x i = x
Iso.rightInv isom (b , x , q) i = q i , x , λ j → q (i ∧ j)
module _ (B : Type ℓb) (ℓ : Level) where
private
ℓ' = ℓ-max ℓb ℓ
-- HoTT Theorem 4.8.3
fibrationEquiv : (Σ[ E ∈ Type ℓ' ] (E → B)) ≃ (B → Type ℓ')
fibrationEquiv = isoToEquiv isom
where isom : Iso (Σ[ E ∈ Type ℓ' ] (E → B)) (B → Type ℓ')
Iso.fun isom (E , p) = fiber p
Iso.inv isom p⁻¹ = Σ B p⁻¹ , fst
Iso.rightInv isom p⁻¹ i x = ua (fiberEquiv p⁻¹ x) i
Iso.leftInv isom (E , p) i = ua e (~ i) , fst ∘ ua-unglue e (~ i)
where e = totalEquiv p
-- The path type in a fiber of f is equivalent to a fiber of (cong f)
open import Cubical.Foundations.Function
fiberPath : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} {f : A → B} {b : B} (h h' : fiber f b) →
(Σ[ p ∈ (fst h ≡ fst h') ] (PathP (λ i → f (p i) ≡ b) (snd h) (snd h')))
≡ fiber (cong f) (h .snd ∙∙ refl ∙∙ sym (h' .snd))
fiberPath h h' = cong (Σ (h .fst ≡ h' .fst)) (funExt λ p → flipSquarePath ∙ PathP≡doubleCompPathʳ _ _ _ _)
fiber≡ : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} {f : A → B} {b : B} (h h' : fiber f b)
→ (h ≡ h') ≡ fiber (cong f) (h .snd ∙∙ refl ∙∙ sym (h' .snd))
fiber≡ {f = f} {b = b} h h' =
ΣPath≡PathΣ ⁻¹ ∙
fiberPath h h'
FibrationStr : (B : Type ℓb) → Type ℓ → Type (ℓ-max ℓ ℓb)
FibrationStr B A = A → B
Fibration : (B : Type ℓb) → (ℓ : Level) → Type (ℓ-max ℓb (ℓ-suc ℓ))
Fibration {ℓb = ℓb} B ℓ = Σ[ A ∈ Type ℓ ] FibrationStr B A
|
{
"alphanum_fraction": 0.5428659858,
"avg_line_length": 34.3723404255,
"ext": "agda",
"hexsha": "04411c75f3a7191d6d367cc0746c6dc6200d7230",
"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": "3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "apabepa10/cubical",
"max_forks_repo_path": "Cubical/Functions/Fibration.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "apabepa10/cubical",
"max_issues_repo_path": "Cubical/Functions/Fibration.agda",
"max_line_length": 106,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3a9bb56260c25a6f2e9c20af8d278de0fe8d9e05",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "apabepa10/cubical",
"max_stars_repo_path": "Cubical/Functions/Fibration.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1314,
"size": 3231
}
|
module Numeral.Natural.Relation.ModuloCongruence where
open import Data.Boolean.Stmt
open import Functional
open import Numeral.Natural
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.Modulo
open import Relator.Equals
open import Type
private variable m n x y : ℕ
_≡_[mod_] : ℕ → ℕ → (m : ℕ) → .⦃ pos : IsTrue(positive? m) ⦄ → Type
a ≡ b [mod m ] = ((_≡_) on₂ (_mod m)) a b
open import Relator.Equals.Proofs.Equiv
open import Structure.Relator.Equivalence
open import Structure.Relator.Equivalence.Proofs
open import Structure.Setoid using (Equiv ; intro)
instance
mod-congruence-equivalence : ⦃ pos : IsTrue(positive? m) ⦄ → Equivalence(_≡_[mod m ])
mod-congruence-equivalence {m} = on₂-equivalence {f = _mod m} ⦃ [≡]-equivalence ⦄
mod-congruence-equiv : (m : ℕ) → ⦃ pos : IsTrue(positive? m) ⦄ → Equiv(ℕ)
mod-congruence-equiv m = intro(_≡_[mod m ]) ⦃ mod-congruence-equivalence {m} ⦄
open import Lang.Instance
open import Logic.Propositional
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Modulo.Proofs
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Relation.Divisibility
open import Numeral.Natural.Relation.Order
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Function.Proofs
open import Structure.Operator
open import Structure.Operator.Proofs.Util
open import Structure.Operator.Properties
open import Structure.Relator.Properties
open import Syntax.Implication
open import Syntax.Transitivity
mod-congruence-loose-linear-map : ∀{f g₁ g₂ h : ℕ → ℕ} (add : ∀{a b} → (f(a + b) ≡ g₁(a) + g₂(b))) → (mul : ∀{a b} → (g₂(a ⋅ b) ≡ a ⋅ h(b))) → ∀{m} ⦃ pos : IsTrue(positive? m) ⦄ → Function ⦃ mod-congruence-equiv m ⦄ ⦃ mod-congruence-equiv m ⦄ f
Function.congruence (mod-congruence-loose-linear-map {f}{g₁}{g₂}{h} add mul {𝐒 m}) {a}{b} = mod-intro₂(\{a}{b} am bm → (am ≡ bm) → (f(a) mod 𝐒(m) ≡ f(b) mod 𝐒(m))) {𝐒 m} (\{a}{b}{n₁}{n₂} → p{a}{b}{n₁}{n₂}) {a}{b} where
p : ∀{a b n₁ n₂} → (a < 𝐒(m)) → (b < 𝐒(m)) → (a ≡ b) → (f(a + (n₁ ⋅ 𝐒(m))) mod 𝐒(m)) ≡ (f(b + (n₂ ⋅ 𝐒(m))) mod 𝐒(m))
p {a}{b}{n₁}{n₂} am bm ab =
f(a + (n₁ ⋅ 𝐒(m))) mod 𝐒(m) 🝖[ _≡_ ]-[ congruence₁(_mod 𝐒(m)) (add{a}{n₁ ⋅ 𝐒(m)}) ]
(g₁(a) + g₂(n₁ ⋅ 𝐒(m))) mod 𝐒(m) 🝖[ _≡_ ]-[ congruence₁(_mod 𝐒(m)) (congruence₂ᵣ(_+_)(g₁(a)) (congruence₁(g₂) (commutativity(_⋅_) {n₁}{𝐒 m}))) ]
(g₁(a) + g₂(𝐒(m) ⋅ n₁)) mod 𝐒(m) 🝖[ _≡_ ]-[ congruence₁(_mod 𝐒(m)) (congruence₂ᵣ(_+_)(g₁(a)) (mul{𝐒(m)}{n₁})) ]
(g₁(a) + (𝐒(m) ⋅ h(n₁))) mod 𝐒(m) 🝖[ _≡_ ]-[ mod-of-modulus-sum-multiple{g₁(a)}{𝐒 m}{h(n₁)} ]
g₁(a) mod 𝐒(m) 🝖[ _≡_ ]-[ congruence₁(_mod 𝐒(m)) (congruence₁(g₁) ab) ]
g₁(b) mod 𝐒(m) 🝖[ _≡_ ]-[ mod-of-modulus-sum-multiple{g₁(b)}{𝐒 m}{h(n₂)} ]-sym
(g₁(b) + (𝐒(m) ⋅ h(n₂))) mod 𝐒(m) 🝖[ _≡_ ]-[ congruence₁(_mod 𝐒(m)) (congruence₂ᵣ(_+_)(g₁(b)) (mul{𝐒(m)}{n₂})) ]-sym
(g₁(b) + g₂(𝐒(m) ⋅ n₂)) mod 𝐒(m) 🝖[ _≡_ ]-[ congruence₁(_mod 𝐒(m)) (congruence₂ᵣ(_+_)(g₁(b)) (congruence₁(g₂) (commutativity(_⋅_) {n₂}{𝐒 m}))) ]-sym
(g₁(b) + g₂(n₂ ⋅ 𝐒(m))) mod 𝐒(m) 🝖[ _≡_ ]-[ congruence₁(_mod 𝐒(m)) (add{b}{n₂ ⋅ 𝐒(m)}) ]-sym
f(b + (n₂ ⋅ 𝐒(m))) mod 𝐒(m) 🝖-end
module _ {m} ⦃ pos : IsTrue(positive?(m)) ⦄ where
instance
mod-congruence-𝐒-function : Function ⦃ mod-congruence-equiv m ⦄ ⦃ mod-congruence-equiv m ⦄ 𝐒
mod-congruence-𝐒-function = mod-congruence-loose-linear-map {𝐒}{𝐒}{id}{id} (reflexivity(_≡_)) (reflexivity(_≡_)) {m}
instance
mod-congruence-[+]-operator : BinaryOperator ⦃ mod-congruence-equiv m ⦄ ⦃ mod-congruence-equiv m ⦄ ⦃ mod-congruence-equiv m ⦄ (_+_)
mod-congruence-[+]-operator = binaryOperator-from-function ⦃ _ ⦄ ⦃ _ ⦄ ⦃ _ ⦄ {_▫_ = _+_}
⦃ \{x} → functionₗ-from-commutative-functionᵣ ⦃ _ ⦄ ⦃ _ ⦄ {_+_} ⦃ r ⦄ ⦃ intro (\{x} → congruence₁(_mod m) (commutativity(_+_) {x})) ⦄ {x} ⦄
⦃ r ⦄
where
r : ∀{c} → Function ⦃ mod-congruence-equiv m ⦄ ⦃ mod-congruence-equiv m ⦄ (_+ c)
r{c} = mod-congruence-loose-linear-map {_+ c}{_+ c}{id}{id} (\{a}{b} → One.commuteᵣ-assocₗ{_▫_ = _+_} {a}{b}{c}) (reflexivity(_≡_)) {m}
-- r {_}{_}{𝟎} {_} p = p
-- r {a}{b}{𝐒 c}{m} p = mod-congruence-with-𝐒 {a + c}{b + c}{m} (r {a}{b}{c}{m} p)
instance
mod-congruence-[⋅]-operator : BinaryOperator ⦃ mod-congruence-equiv m ⦄ ⦃ mod-congruence-equiv m ⦄ ⦃ mod-congruence-equiv m ⦄ (_⋅_)
mod-congruence-[⋅]-operator = binaryOperator-from-function ⦃ _ ⦄ ⦃ _ ⦄ ⦃ _ ⦄ {_▫_ = _⋅_}
⦃ \{x} → functionₗ-from-commutative-functionᵣ ⦃ _ ⦄ ⦃ _ ⦄ {_⋅_} ⦃ \{c} → r{c} ⦄ ⦃ intro (\{x}{y} → congruence₁(_mod m) (commutativity(_⋅_) {x}{y})) ⦄ {x} ⦄
⦃ \{c} → r{c} ⦄
where
r : ∀{c} → Function ⦃ mod-congruence-equiv m ⦄ ⦃ mod-congruence-equiv m ⦄ (_⋅ c)
r{c} = mod-congruence-loose-linear-map {_⋅ c}{_⋅ c}{_⋅ c}{_⋅ c} (\{a}{b} → distributivityᵣ(_⋅_)(_+_) {a}{b}{c}) (\{a}{b} → associativity(_⋅_) {a}{b}{c}) {m}
mod-congruence-[^]ₗ-function : ∀{n} → Function ⦃ mod-congruence-equiv m ⦄ ⦃ mod-congruence-equiv m ⦄ (_^ n)
Function.congruence (mod-congruence-[^]ₗ-function {𝟎}) _ = reflexivity(_≡_)
Function.congruence (mod-congruence-[^]ₗ-function {𝐒 n}) {a} {b} p = BinaryOperator.congruence ⦃ _ ⦄ ⦃ _ ⦄ ⦃ _ ⦄ mod-congruence-[⋅]-operator {a}{b}{a ^ n}{b ^ n} p (Function.congruence ⦃ _ ⦄ ⦃ _ ⦄ (mod-congruence-[^]ₗ-function {n}) p)
instance
mod-congruence-𝐒-injective : ⦃ pos : IsTrue(positive?(m)) ⦄ → Injective ⦃ mod-congruence-equiv m ⦄ ⦃ mod-congruence-equiv m ⦄ 𝐒
Injective.proof (mod-congruence-𝐒-injective {𝐒 m}) {a}{b} =
𝐒(a) mod 𝐒(m) ≡ 𝐒(b) mod 𝐒(m) ⇒-[ swap (BinaryOperator.congruence ⦃ _ ⦄ ⦃ _ ⦄ ⦃ _ ⦄ (mod-congruence-[+]-operator {𝐒 m}) {𝐒 a}{𝐒 b}{m}{m}) (reflexivity(_≡_)) ]
(𝐒(a) + m) mod 𝐒(m) ≡ (𝐒(b) + m) mod 𝐒(m) ⇒-[]
(a + 𝐒(m)) mod 𝐒(m) ≡ (b + 𝐒(m)) mod 𝐒(m) ⇒-[ (p ↦ symmetry(_≡_) (mod-of-modulus-addᵣ{a}{m}) 🝖 p 🝖 mod-of-modulus-addᵣ{b}{m}) ]
a mod 𝐒(m) ≡ b mod 𝐒(m) ⇒-end
mod-congruence-[𝄩] : ∀{a b m} → ⦃ pos : IsTrue(positive?(m)) ⦄ → (a ≡ b [mod m ]) ↔ (m ∣ (a 𝄩 b))
mod-congruence-[𝄩] {a} {b} {𝐒 m} = [↔]-intro (l{a}{b}) (r{a}{b}) where
l : ∀{a b} → (a mod 𝐒(m) ≡ b mod 𝐒(m)) ← (𝐒(m) ∣ (a 𝄩 b))
l {𝟎} {𝟎} div = [≡]-intro
l {𝟎} {𝐒 b} div = symmetry(_≡_) ([↔]-to-[←] mod-divisibility div)
l {𝐒 a} {𝟎} div = [↔]-to-[←] mod-divisibility div
l {𝐒 a} {𝐒 b} div = congruence₁ ⦃ mod-congruence-equiv _ ⦄ ⦃ mod-congruence-equiv _ ⦄ (𝐒) {a}{b} (l{a}{b} div)
r : ∀{a b} → (a mod 𝐒(m) ≡ b mod 𝐒(m)) → (𝐒(m) ∣ (a 𝄩 b))
r {𝟎} {𝟎} eq = Div𝟎
r {𝟎} {𝐒 b} eq = [↔]-to-[→] mod-divisibility (symmetry(_≡_) eq)
r {𝐒 a} {𝟎} eq = [↔]-to-[→] mod-divisibility eq
r {𝐒 a} {𝐒 b} eq = r{a}{b} (injective ⦃ mod-congruence-equiv _ ⦄ ⦃ mod-congruence-equiv _ ⦄ (𝐒) {a}{b} eq)
open import Logic.Propositional.Theorems
open import Numeral.Natural.Function.GreatestCommonDivisor
open import Numeral.Natural.Function.GreatestCommonDivisor.Proofs
open import Numeral.Natural.Oper.FlooredDivision
open import Numeral.Natural.Oper.FlooredDivision.Proofs
open import Numeral.Natural.Oper.FlooredDivision.Proofs.Inverse
open import Numeral.Natural.Coprime
open import Numeral.Natural.Coprime.Proofs
open import Numeral.Natural.Relation
open import Numeral.Natural.Relation.Divisibility.Proofs
open import Numeral.Natural.Relation.Divisibility.Proofs.Product
open import Structure.Relator
-- TODO: Move the postulates below
postulate divides-[⌊/⌋] : ∀{a b c} ⦃ pos : Positive(c) ⦄ → (c ∣ a) → (a ∣ b) → ((a ⌊/⌋ c) ∣ (b ⌊/⌋ c))
postulate [⋅]-positive : ∀{a b} → ⦃ Positive(a) ⦄ → ⦃ Positive(b) ⦄ → Positive(a ⋅ b)
postulate [⌊/⌋][⋅]ₗ-compatibility : ∀{a b c} ⦃ pos : Positive(c) ⦄ → (c ∣ a) → (((a ⋅ b) ⌊/⌋ c) ≡ (a ⌊/⌋ c) ⋅ b)
postulate [⌊/⌋][⋅]ᵣ-compatibility : ∀{a b c} ⦃ pos : Positive(c) ⦄ → (c ∣ a) → (((a ⋅ b) ⌊/⌋ c) ≡ a ⋅ (b ⌊/⌋ c))
mod-congruence-scale-modulus : ∀{m} → ⦃ pos : Positive(m) ⦄ → ∀{a b c} → (c ⋅ a ≡ c ⋅ b [mod m ]) ↔ (a ≡ b [mod((m ⌊/⌋ gcd c m) ⦃ _ ⦄)]) ⦃ _ ⦄
mod-congruence-scale-modulus {m} ⦃ pos ⦄ {a}{b}{c} = [↔]-transitivity ([↔]-transitivity mod-congruence-[𝄩] ([↔]-intro l r)) ([↔]-symmetry (mod-congruence-[𝄩] ⦃ [⌊/⌋]-positive ⦃ pos ⦄ ⦃ pgcd ⦄ ⦄)) where
instance
pgcd : Positive(gcd c m)
pgcd = [↔]-to-[→] gcd-positive ([∨]-introᵣ pos)
l : (m ∣ ((c ⋅ a) 𝄩 (c ⋅ b))) ← ((m ⌊/⌋ gcd c m) ⦃ _ ⦄ ∣ (a 𝄩 b))
l =
(m ⌊/⌋ gcd c m) ∣ (a 𝄩 b) ⇒-[ divides-with-[⋅]ᵣ-both {z = gcd c m} ]
((m ⌊/⌋ gcd c m) ⋅ gcd c m) ∣ ((a 𝄩 b) ⋅ gcd c m) ⇒-[ substitute₂ₗ(_∣_) ([⋅][⌊/⌋]-inverseOperatorᵣ (Gcd.divisorᵣ Gcd-gcd)) ]
m ∣ ((a 𝄩 b) ⋅ gcd c m) ⇒-[ divides-with-[⋅] {c = (c ⌊/⌋ gcd c m) ⦃ _ ⦄} ∘ [∨]-introₗ ]
m ∣ ((a 𝄩 b) ⋅ gcd c m) ⋅ (c ⌊/⌋ gcd c m) ⇒-[ substitute₂ᵣ(_∣_) (associativity(_⋅_) {a 𝄩 b}{gcd c m}{(c ⌊/⌋ gcd c m) ⦃ _ ⦄}) ]
m ∣ (a 𝄩 b) ⋅ (gcd c m ⋅ (c ⌊/⌋ gcd c m)) ⇒-[ substitute₂ᵣ(_∣_) (congruence₂ᵣ(_⋅_)(a 𝄩 b) (symmetry(_≡_) ([⌊/⌋][⋅]ᵣ-compatibility {gcd c m}{c}{gcd c m} (reflexivity(_∣_))))) ]
m ∣ (a 𝄩 b) ⋅ ((gcd c m ⋅ c) ⌊/⌋ gcd c m) ⇒-[ substitute₂ᵣ(_∣_) (congruence₂ᵣ(_⋅_)(a 𝄩 b) ([⌊/⌋][swap⋅]-inverseOperatorᵣ {gcd c m}{c})) ]
m ∣ (a 𝄩 b) ⋅ c ⇒-[ substitute₂ᵣ(_∣_) (commutativity(_⋅_) {a 𝄩 b}{c}) ]
m ∣ c ⋅ (a 𝄩 b) ⇒-[ substitute₂ᵣ(_∣_) (distributivityₗ(_⋅_)(_𝄩_) {c}{a}{b}) ]
m ∣ ((c ⋅ a) 𝄩 (c ⋅ b)) ⇒-end
r : (m ∣ ((c ⋅ a) 𝄩 (c ⋅ b))) → ((m ⌊/⌋ gcd c m) ⦃ _ ⦄ ∣ (a 𝄩 b))
r =
(m ∣ (c ⋅ a 𝄩 c ⋅ b)) ⇒-[ substitute₂ᵣ(_∣_) (symmetry(_≡_) (distributivityₗ(_⋅_)(_𝄩_) {c}{a}{b})) ]
(m ∣ c ⋅ (a 𝄩 b)) ⇒-[ divides-[⌊/⌋] {m}{c ⋅ (a 𝄩 b)}{gcd c m} (Gcd.divisorᵣ Gcd-gcd) ]
(m ⌊/⌋ gcd c m) ⦃ _ ⦄ ∣ ((c ⋅ (a 𝄩 b)) ⌊/⌋ gcd c m) ⦃ _ ⦄ ⇒-[ substitute₂ᵣ(_∣_) ([⌊/⌋][⋅]ₗ-compatibility {c}{a 𝄩 b}{gcd c m} ⦃ pgcd ⦄ (Gcd.divisorₗ {c}{m} Gcd-gcd)) ]
(m ⌊/⌋ gcd c m) ⦃ _ ⦄ ∣ ((c ⌊/⌋ gcd c m) ⦃ pgcd ⦄ ⋅ (a 𝄩 b)) ⇒-[ swap(coprime-divides-of-[⋅] {(m ⌊/⌋ gcd c m) ⦃ _ ⦄}{(c ⌊/⌋ gcd c m) ⦃ _ ⦄}{a 𝄩 b}) (symmetry(Coprime) ([⌊/⌋]-gcd-coprime{c}{m} ([∨]-introᵣ pos))) ]
((m ⌊/⌋ gcd c m) ⦃ _ ⦄ ∣ (a 𝄩 b)) ⇒-end
postulate mod-congruence-scale : ∀{m} ⦃ pos-m : Positive(m) ⦄ {c} ⦃ pos-c : Positive(c) ⦄ → ∀{a b} → (a ≡ b [mod m ]) → (c ⋅ a ≡ c ⋅ b [mod(c ⋅ m)]) ⦃ [⋅]-positive {c}{m} ⦄
postulate mod-congruence-divide : ∀{m} ⦃ pos-m : Positive(m) ⦄ {c} ⦃ pos-c : Positive(c) ⦄ → (c ∣ m) → ∀{a b} → (c ∣ a) → (c ∣ b) → (a ≡ b [mod m ]) → (a ⌊/⌋ c ≡ b ⌊/⌋ c [mod(m ⌊/⌋ c)]) ⦃ [⌊/⌋]-positive {m}{c} ⦄
postulate mod-congruence-smaller-modulus : ∀{m₁} ⦃ pos-m₁ : Positive(m₁) ⦄ {m₂} ⦃ pos-m₂ : Positive(m₂) ⦄ → (m₂ ∣ m₁) → ∀{a b} → (a ≡ b [mod m₁ ]) → (a ≡ b [mod m₂ ])
postulate mod-congruence-to-gcd-equality : ∀{m} ⦃ pos-m : Positive(m) ⦄ → ∀{a b} → (a ≡ b [mod m ]) → (gcd a m ≡ gcd b m)
postulate mod-congruence-[−₀]-operator : ∀{m} ⦃ pos-m : Positive(m) ⦄ → ∀{a₁ a₂ b₁ b₂} → (a₁ ≥ b₁) → (a₂ ≥ b₂) → (a₁ ≡ a₂ [mod m ]) → (b₁ ≡ b₂ [mod m ]) → (a₁ −₀ b₁ ≡ a₂ −₀ b₂ [mod m ])
postulate mod-congruence-[⌊/⌋]-operator : ∀{m} ⦃ pos-m : Positive(m) ⦄ → ∀{a₁ a₂ b₁ b₂} ⦃ pos-b₁ : Positive(b₁) ⦄ ⦃ pos-b₂ : Positive(b₂) ⦄ → (a₁ ∣ b₁) → (a₂ ∣ b₂) → (a₁ ≡ a₂ [mod m ]) → (b₁ ≡ b₂ [mod m ]) → (a₁ ⌊/⌋ b₁ ≡ a₂ ⌊/⌋ b₂ [mod m ])
|
{
"alphanum_fraction": 0.5414001577,
"avg_line_length": 67.9345238095,
"ext": "agda",
"hexsha": "9eb5603ddb2bd90910fb0751aa6720717e7c5d79",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Natural/Relation/ModuloCongruence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Relation/ModuloCongruence.agda",
"max_line_length": 244,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Natural/Relation/ModuloCongruence.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": 5735,
"size": 11413
}
|
{-# OPTIONS --cubical #-}
module Cubical.Codata.Conat where
open import Cubical.Codata.Conat.Base public
open import Cubical.Codata.Conat.Properties public
|
{
"alphanum_fraction": 0.7911392405,
"avg_line_length": 22.5714285714,
"ext": "agda",
"hexsha": "b8fb936b8c20fa09ca46aa9bc26df23da7dc7b7d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Codata/Conat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Codata/Conat.agda",
"max_line_length": 50,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Codata/Conat.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-23T23:52:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-03-23T23:52:11.000Z",
"num_tokens": 38,
"size": 158
}
|
{-# OPTIONS --safe --without-K #-}
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl; sym; cong; cong₂; subst; trans)
open import Relation.Nullary.Decidable using (True; from-yes)
open import Relation.Nullary.Negation using (¬?; contradiction)
open Relation.Binary.PropositionalEquality.≡-Reasoning
open import Function using (_∘_)
open import Relation.Nullary using (yes; no)
open import Data.Empty using (⊥)
open import Data.Product using (_×_; _,_; Σ-syntax; proj₁; proj₂)
open import Data.Fin.Base as Fin using (Fin; zero; suc)
open import Data.Unit using (⊤; tt)
open import Data.List.Base as List using (List; []; _∷_; [_])
import Data.List.Properties as Listₚ
import Data.Char.Properties as Charₚ
import Data.Digit as Digit
import Data.List.Membership.Propositional as ∈ₗ
import Data.List.Membership.Propositional.Properties as ∈ₗₚ
open import Data.Nat.Base as ℕ using (ℕ; zero; suc)
import Data.Nat.Properties as ℕₚ
import Data.Nat.Show as ℕₛ
import Data.Nat.Show.Properties as ℕₛₚ
open import Data.String.Base as String using (String)
import Data.Product.Properties as Productₚ
open import Data.Vec.Base as Vec using ([]; _∷_; Vec)
import Data.Vec.Properties as Vecₚ
open import Data.Vec.Relation.Unary.Any as Any using (here; there)
import Data.Vec.Membership.Propositional as ∈ᵥ
import Data.Vec.Membership.Propositional.Properties as ∈ᵥₚ
open import PiCalculus.Syntax
open Raw
open Scoped
open Conversion
open import PiCalculus.Utils
module PiCalculus.Syntax.Properties where
module _ where
private
variable
n : ℕ
P Q R S : Scoped n
x y : Fin n
namex namey : Name
fromName∘toName : (i : Fin n) (ctx : Ctx n) → ∈toFin (∈ᵥₚ.∈-lookup i ctx) ≡ i
fromName∘toName zero (x ∷ ctx) = refl
fromName∘toName (suc i) (x ∷ ctx) rewrite fromName∘toName i ctx = refl
toName∘fromName : ∀ {x} {ctx : Ctx n} (x∈ctx : x ∈ᵥ.∈ ctx) → Vec.lookup ctx (∈toFin x∈ctx) ≡ x
toName∘fromName (here px) = sym px
toName∘fromName (there x∈ctx) = toName∘fromName x∈ctx
-- The circum (^) is not a decimal character
^∉DECIMALS : '^' ∈ᵥ.∉ Digit.digitChars
^∉DECIMALS = from-yes (¬? (Any.any? ('^' Charₚ.≟_) Digit.digitChars))
module _ (base : ℕ) {2≤base : True (2 ℕₚ.≤? base)} {base≤16 : True (base ℕₚ.≤? 16)} where
charsInBase∈digitChars : ∀ n c → c ∈ₗ.∈ ℕₛ.charsInBase base {2≤base} {base≤16} n → c ∈ᵥ.∈ Digit.digitChars
charsInBase∈digitChars n c i with ∈ₗₚ.∈-map⁻ Digit.showDigit i
charsInBase∈digitChars n c i | d , _ , refl = ∈ᵥₚ.∈-lookup (Fin.inject≤ d _) Digit.digitChars
-- In <name>^<natural> the <natural> does not contain ^, therefore toChars is injective
toChars-injective : (x y : Name × ℕ) → toChars x ≡ toChars y → x ≡ y
toChars-injective (nx , cx) (ny , cy) eq = cong₂ _,_ cancel-names (ℕₛₚ.charsInBase-injective 10 cx cy count-repr)
where
count-repr = ListInv.inv-++ʳ nx ny '^'
(^∉DECIMALS ∘ charsInBase∈digitChars 10 cx '^')
(^∉DECIMALS ∘ charsInBase∈digitChars 10 cy '^')
eq
cancel-names = Listₚ.++-cancelʳ nx ny
(subst (λ ● → nx List.++ ('^' ∷ ●) ≡ _)
count-repr eq)
-- A fresh variable name created from inspecting a context cannot be in that context
fresh-∉' : ∀ m name (xs : Ctx n) → toChars (name , m ℕ.+ (count name xs)) ∈ᵥ.∉ apply xs
fresh-∉' m name (x ∷ xs) (here seq) with Listₚ.≡-dec Charₚ._≟_ name x
fresh-∉' m name (x ∷ xs) (here seq) | yes refl = ℕₚ.m≢1+n+m _ (begin
count name xs
≡˘⟨ Productₚ.,-injectiveʳ (toChars-injective (name , m ℕ.+ suc (count name xs)) (name , count name xs) seq) ⟩
m ℕ.+ suc (count name xs)
≡⟨ ℕₚ.+-suc m _ ⟩
suc m ℕ.+ count name xs
∎)
fresh-∉' m name (x ∷ xs) (here seq) | no ¬q = contradiction
(Productₚ.,-injectiveˡ (toChars-injective (name , m ℕ.+ count name xs) (x , count x xs) seq)) ¬q
fresh-∉' m name (x ∷ xs) (there ∈ps) with Listₚ.≡-dec Charₚ._≟_ name x
fresh-∉' m name (x ∷ xs) (there ∈ps) | yes refl rewrite ℕₚ.+-suc m (count name xs) = fresh-∉' (suc m) name _ ∈ps
fresh-∉' m name (x ∷ xs) (there ∈ps) | no ¬q = fresh-∉' m name _ ∈ps
fresh-∉ : ∀ name (xs : Ctx n) → toChars (name , count name xs) ∈ᵥ.∉ apply xs
fresh-∉ name xs = fresh-∉' zero name xs
-- Translating from de Bruijn to names results in a well-scoped process
toRaw-WellScoped : (ctx : Ctx n) (P : Scoped n) → WellScoped (apply ctx) (toRaw ctx P)
toRaw-WellScoped ctx 𝟘 = tt
toRaw-WellScoped ctx (ν P ⦃ name ⦄) = toRaw-WellScoped (name ∷ ctx) P
toRaw-WellScoped ctx (P ∥ Q) = toRaw-WellScoped ctx P , toRaw-WellScoped ctx Q
toRaw-WellScoped ctx ((x ⦅⦆ P) ⦃ name ⦄) = ∈ᵥₚ.∈-lookup _ _ , toRaw-WellScoped (name ∷ ctx) P
toRaw-WellScoped ctx (x ⟨ y ⟩ P) = ∈ᵥₚ.∈-lookup _ _ , ∈ᵥₚ.∈-lookup _ _ , toRaw-WellScoped ctx P
-- Translating from de Bruijn to names results in no shadowed variables
toRaw-NotShadowed : (ctx : Ctx n) (P : Scoped n) → NotShadowed (apply ctx) (toRaw ctx P)
toRaw-NotShadowed ctx 𝟘 = tt
toRaw-NotShadowed ctx (ν P ⦃ name ⦄) = fresh-∉ name ctx , (toRaw-NotShadowed (_ ∷ ctx) P)
toRaw-NotShadowed ctx (P ∥ Q) = toRaw-NotShadowed ctx P , toRaw-NotShadowed ctx Q
toRaw-NotShadowed ctx ((x ⦅⦆ P) ⦃ name ⦄) = fresh-∉ name ctx , toRaw-NotShadowed (name ∷ ctx) P
toRaw-NotShadowed ctx (x ⟨ y ⟩ P) = toRaw-NotShadowed ctx P
-- Translating from de Bruijn to names and back results in the same process modulo name hints
data _α-≡_ {n} : Scoped n → Scoped n → Set where
inaction : 𝟘 α-≡ 𝟘
scope : P α-≡ Q → ν P ⦃ namex ⦄ α-≡ ν Q ⦃ namey ⦄
comp : P α-≡ Q → R α-≡ S → (P ∥ R) α-≡ (Q ∥ S)
input : P α-≡ Q → (x ⦅⦆ P) ⦃ namex ⦄ α-≡ (x ⦅⦆ Q) ⦃ namey ⦄
output : P α-≡ Q → (x ⟨ y ⟩ P) α-≡ (x ⟨ y ⟩ Q)
fromRaw∘toRaw : (ctx : Ctx n) (P : Scoped n)
→ fromRaw' (apply ctx) (toRaw ctx P) (toRaw-WellScoped ctx P) α-≡ P
fromRaw∘toRaw ctx 𝟘 = inaction
fromRaw∘toRaw ctx (ν P ⦃ name ⦄) =
scope (fromRaw∘toRaw (name ∷ ctx) P)
fromRaw∘toRaw ctx (P ∥ Q) =
comp (fromRaw∘toRaw ctx P) (fromRaw∘toRaw ctx Q)
fromRaw∘toRaw ctx ((x ⦅⦆ P) ⦃ name ⦄)
rewrite fromName∘toName x (apply ctx) =
input (fromRaw∘toRaw (name ∷ ctx) P)
fromRaw∘toRaw ctx (x ⟨ y ⟩ P)
rewrite fromName∘toName x (apply ctx) | fromName∘toName y (apply ctx) =
output (fromRaw∘toRaw ctx P)
module _ where
private
variable
n : ℕ
P Q R S : Raw
x y w z : Name
ks vs : Ctx n
_∈²_ : ∀ {n} → (Name × Name) → (Ctx n × Ctx n) → Set
(x , y ) ∈² (xs , ys) = Σ[ i ∈ Fin _ ] (Vec.lookup xs i ≡ x × Vec.lookup ys i ≡ y)
infix 5 _α[_↦_]≡_
data _α[_↦_]≡_ : Raw → ∀ {n} → Ctx n → Ctx n → Raw → Set where
inaction : 𝟘 α[ ks ↦ vs ]≡ 𝟘
scope : P α[ x ∷ ks ↦ y ∷ vs ]≡ Q
→ ⦅ν x ⦆ P α[ ks ↦ vs ]≡ ⦅ν y ⦆ Q
comp : P α[ ks ↦ vs ]≡ Q
→ R α[ ks ↦ vs ]≡ S
→ P ∥ R α[ ks ↦ vs ]≡ Q ∥ S
input : (x , y) ∈² (ks , vs)
→ P α[ w ∷ ks ↦ z ∷ vs ]≡ Q
→ x ⦅ w ⦆ P α[ ks ↦ vs ]≡ y ⦅ z ⦆ Q
output : (x , y) ∈² (ks , vs)
→ (w , z) ∈² (ks , vs)
→ P α[ ks ↦ vs ]≡ Q
→ x ⟨ w ⟩ P α[ ks ↦ vs ]≡ (y ⟨ z ⟩ Q)
-- Translating a well-scoped process to de Bruijn and back results in the same process
-- modulo alpha renaming, where the new names in `apply isf` map to the old in `ctx`
toRaw∘fromRaw : (ctx : Ctx n) (P : Raw) (wsP : WellScoped ctx P)
→ toRaw ctx (fromRaw' ctx P wsP) α[ apply ctx ↦ ctx ]≡ P
toRaw∘fromRaw ctx 𝟘 wsP = inaction
toRaw∘fromRaw ctx (⦅ν x ⦆ P) wsP
= scope (toRaw∘fromRaw (x ∷ ctx) P wsP)
toRaw∘fromRaw ctx (P ∥ Q) (wsP , wsQ)
= comp (toRaw∘fromRaw ctx P wsP)
(toRaw∘fromRaw ctx Q wsQ)
toRaw∘fromRaw ctx (x ⦅ y ⦆ P) (x∈ctx , wsP)
= input (_ , refl , toName∘fromName x∈ctx)
(toRaw∘fromRaw (y ∷ ctx) P wsP)
toRaw∘fromRaw ctx (x ⟨ y ⟩ P) (x∈ctx , y∈ctx , wsP)
= output (_ , refl , toName∘fromName x∈ctx)
(_ , refl , toName∘fromName y∈ctx)
(toRaw∘fromRaw ctx P wsP)
|
{
"alphanum_fraction": 0.5975714461,
"avg_line_length": 44.0702702703,
"ext": "agda",
"hexsha": "8d02010b072e1d6dbae8195dcba15e29d6a7c389",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T16:24:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-25T13:57:13.000Z",
"max_forks_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/typing-linear-pi",
"max_forks_repo_path": "src/PiCalculus/Syntax/Properties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_issues_repo_issues_event_max_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guilhermehas/typing-linear-pi",
"max_issues_repo_path": "src/PiCalculus/Syntax/Properties.agda",
"max_line_length": 115,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/typing-linear-pi",
"max_stars_repo_path": "src/PiCalculus/Syntax/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-14T15:18:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-02T23:32:11.000Z",
"num_tokens": 3218,
"size": 8153
}
|
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Definition
open import Numbers.Naturals.Naturals
open import Numbers.Naturals.Order
open import Numbers.Naturals.Order.Lemmas
open import Numbers.Naturals.Order.WellFounded
open import Orders.WellFounded.Induction
open import Orders.Total.Definition
open import Semirings.Definition
module Numbers.Naturals.EuclideanAlgorithm where
open TotalOrder ℕTotalOrder
open Semiring ℕSemiring
open import Decidable.Lemmas ℕDecideEquality
record divisionAlgResult (a : ℕ) (b : ℕ) : Set where
field
quot : ℕ
rem : ℕ
pr : a *N quot +N rem ≡ b
remIsSmall : (rem <N a) || (a ≡ 0)
quotSmall : (0 <N a) || ((0 ≡ a) && (quot ≡ 0))
record divisionAlgResult' (a : ℕ) (b : ℕ) : Set where
field
quot : ℕ
rem : ℕ
.pr : a *N quot +N rem ≡ b
remIsSmall : (rem <N' a) || (a =N' 0)
quotSmall : (0 <N' a) || ((0 =N' a) && (quot =N' 0))
collapseDivAlgResult : {a b : ℕ} → (divisionAlgResult a b) → divisionAlgResult' a b
collapseDivAlgResult record { quot = q ; rem = r ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl y) } = record { quot = q ; rem = r ; pr = pr ; remIsSmall = inl (<NTo<N' x) ; quotSmall = inl (<NTo<N' y) }
collapseDivAlgResult record { quot = q ; rem = r ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr y) } = record { quot = q ; rem = r ; pr = pr ; remIsSmall = inl (<NTo<N' x) ; quotSmall = inr (collapseN (_&&_.fst y) ,, collapseN (_&&_.snd y)) }
collapseDivAlgResult record { quot = q ; rem = r ; pr = pr ; remIsSmall = (inr x) ; quotSmall = inl y } = record { quot = q ; rem = r ; pr = pr ; remIsSmall = inr (collapseN x) ; quotSmall = inl (<NTo<N' y) }
collapseDivAlgResult record { quot = q ; rem = r ; pr = pr ; remIsSmall = (inr x) ; quotSmall = inr y } = record { quot = q ; rem = r ; pr = pr ; remIsSmall = inr (collapseN x) ; quotSmall = inr (collapseN (_&&_.fst y) ,, collapseN (_&&_.snd y)) }
squashDivAlgResult : {a b : ℕ} → divisionAlgResult' a b → divisionAlgResult a b
squashDivAlgResult record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl y) } = record { quot = quot ; rem = rem ; pr = squash pr ; remIsSmall = inl (<N'To<N x) ; quotSmall = inl (<N'To<N y) }
squashDivAlgResult record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr y) } = record { quot = quot ; rem = rem ; pr = squash pr ; remIsSmall = inl (<N'To<N x) ; quotSmall = inr (squashN (_&&_.fst y) ,, squashN (_&&_.snd y)) }
squashDivAlgResult record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inl y) } = record { quot = quot ; rem = rem ; pr = squash pr ; remIsSmall = inr (squashN x) ; quotSmall = inl (<N'To<N y) }
squashDivAlgResult record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inr y) } = record { quot = quot ; rem = rem ; pr = squash pr ; remIsSmall = inr (squashN x) ; quotSmall = inr (squashN (_&&_.fst y) ,, squashN (_&&_.snd y)) }
squashPreservesRem : {a b : ℕ} → (p : divisionAlgResult' a b) → divisionAlgResult.rem (squashDivAlgResult p) ≡ divisionAlgResult'.rem p
squashPreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl x₁) } = refl
squashPreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr x₁) } = refl
squashPreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inl x₁) } = refl
squashPreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inr x₁) } = refl
squashPreservesQuot : {a b : ℕ} → (p : divisionAlgResult' a b) → divisionAlgResult.quot (squashDivAlgResult p) ≡ divisionAlgResult'.quot p
squashPreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl x₁) } = refl
squashPreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr x₁) } = refl
squashPreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inl x₁) } = refl
squashPreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inr x₁) } = refl
collapsePreservesRem : {a b : ℕ} → (p : divisionAlgResult a b) → divisionAlgResult'.rem (collapseDivAlgResult p) ≡ divisionAlgResult.rem p
collapsePreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl x₁) } = refl
collapsePreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr x₁) } = refl
collapsePreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inl x₁) } = refl
collapsePreservesRem record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inr x₁) } = refl
collapsePreservesQuot : {a b : ℕ} → (p : divisionAlgResult a b) → divisionAlgResult'.quot (collapseDivAlgResult p) ≡ divisionAlgResult.quot p
collapsePreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inl x₁) } = refl
collapsePreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) ; quotSmall = (inr x₁) } = refl
collapsePreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inl x₁) } = refl
collapsePreservesQuot record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr x) ; quotSmall = (inr x₁) } = refl
divAlgLessLemma : (a b : ℕ) → (0 <N a) → (r : divisionAlgResult a b) → (divisionAlgResult.quot r ≡ 0) || (divisionAlgResult.rem r <N b)
divAlgLessLemma zero b pr _ = exFalso (TotalOrder.irreflexive ℕTotalOrder pr)
divAlgLessLemma (succ a) b _ record { quot = zero ; rem = a%b ; pr = pr ; remIsSmall = remIsSmall } = inl refl
divAlgLessLemma (succ a) b _ record { quot = (succ a/b) ; rem = a%b ; pr = pr ; remIsSmall = remIsSmall } = inr record { x = a/b +N a *N succ (a/b) ; proof = pr }
modUniqueLemma : {rem1 rem2 a : ℕ} → (quot1 quot2 : ℕ) → rem1 <N a → rem2 <N a → a *N quot1 +N rem1 ≡ a *N quot2 +N rem2 → rem1 ≡ rem2
modUniqueLemma {rem1} {rem2} {a} zero zero rem1<a rem2<a pr rewrite Semiring.productZeroRight ℕSemiring a = pr
modUniqueLemma {rem1} {rem2} {a} zero (succ quot2) rem1<a rem2<a pr rewrite Semiring.productZeroRight ℕSemiring a | pr | multiplicationNIsCommutative a (succ quot2) | equalityCommutative (Semiring.+Associative ℕSemiring a (quot2 *N a) rem2) = exFalso (cannotAddAndEnlarge' {a} {quot2 *N a +N rem2} rem1<a)
modUniqueLemma {rem1} {rem2} {a} (succ quot1) zero rem1<a rem2<a pr rewrite Semiring.productZeroRight ℕSemiring a | equalityCommutative pr | multiplicationNIsCommutative a (succ quot1) | equalityCommutative (Semiring.+Associative ℕSemiring a (quot1 *N a) rem1) = exFalso (cannotAddAndEnlarge' {a} {quot1 *N a +N rem1} rem2<a)
modUniqueLemma {rem1} {rem2} {a} (succ quot1) (succ quot2) rem1<a rem2<a pr rewrite multiplicationNIsCommutative a (succ quot1) | multiplicationNIsCommutative a (succ quot2) | equalityCommutative (Semiring.+Associative ℕSemiring a (quot1 *N a) rem1) | equalityCommutative (Semiring.+Associative ℕSemiring a (quot2 *N a) rem2) = modUniqueLemma {rem1} {rem2} {a} quot1 quot2 rem1<a rem2<a (go {a}{quot1}{rem1}{quot2}{rem2} pr)
where
go : {a quot1 rem1 quot2 rem2 : ℕ} → (a +N (quot1 *N a +N rem1) ≡ a +N (quot2 *N a +N rem2)) → a *N quot1 +N rem1 ≡ a *N quot2 +N rem2
go {a} {quot1} {rem1} {quot2} {rem2} pr rewrite multiplicationNIsCommutative quot1 a | multiplicationNIsCommutative quot2 a = canSubtractFromEqualityLeft {a} pr
modIsUnique : {a b : ℕ} → (div1 div2 : divisionAlgResult a b) → divisionAlgResult.rem div1 ≡ divisionAlgResult.rem div2
modIsUnique {zero} {b} record { quot = quot1 ; rem = rem1 ; pr = pr1 ; remIsSmall = remIsSmall1 } record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = remIsSmall } = transitivity pr1 (equalityCommutative pr)
modIsUnique {succ a} {b} record { quot = quot1 ; rem = rem1 ; pr = pr1 ; remIsSmall = (inl y) } record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) } = modUniqueLemma {rem1} {rem} {succ a} quot1 quot y x (transitivity pr1 (equalityCommutative pr))
modIsUnique {succ a} {b} record { quot = quot1 ; rem = rem1 ; pr = pr1 ; remIsSmall = (inr ()) } record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inl x) }
modIsUnique {succ a} {b} record { quot = quot1 ; rem = rem1 ; pr = pr1 ; remIsSmall = remIsSmall1 } record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = (inr ()) }
transferAddition : (a b c : ℕ) → (a +N b) +N c ≡ (a +N c) +N b
transferAddition a b c rewrite equalityCommutative (Semiring.+Associative ℕSemiring a b c) = p a b c
where
p : (a b c : ℕ) → a +N (b +N c) ≡ (a +N c) +N b
p a b c = transitivity (applyEquality (a +N_) (Semiring.commutative ℕSemiring b c)) (Semiring.+Associative ℕSemiring a c b)
divisionAlgLemma : (x b : ℕ) → x *N zero +N b ≡ b
divisionAlgLemma x b rewrite (Semiring.productZeroRight ℕSemiring x) = refl
divisionAlgLemma2 : (x b : ℕ) → (x ≡ b) → x *N succ zero +N zero ≡ b
divisionAlgLemma2 x b pr rewrite (Semiring.productOneRight ℕSemiring x) = equalityCommutative (transitivity (equalityCommutative pr) (equalityCommutative (Semiring.sumZeroRight ℕSemiring x)))
divisionAlgLemma3 : {a x : ℕ} → (p : succ a <N succ x) → (subtractionNResult.result (-N (inl p))) <N (succ x)
divisionAlgLemma3 {a} {x} p = -NIsDecreasing {a} {succ x} p
divisionAlgLemma4 : (p a q : ℕ) → ((p +N a *N p) +N q) +N succ a ≡ succ ((p +N a *N succ p) +N q)
divisionAlgLemma4 p a q = ans
where
r : ((p +N a *N p) +N q) +N succ a ≡ succ (((p +N a *N p) +N q) +N a)
ans : ((p +N a *N p) +N q) +N succ a ≡ succ ((p +N a *N succ p) +N q)
s : ((p +N a *N p) +N q) +N a ≡ (p +N a *N succ p) +N q
t : (p +N a *N p) +N a ≡ p +N a *N succ p
s = transitivity (transferAddition (p +N a *N p) q a) (applyEquality (λ i → i +N q) t)
ans = identityOfIndiscernablesRight _≡_ r (applyEquality succ s)
r = succExtracts ((p +N a *N p) +N q) a
t = transitivity (equalityCommutative (Semiring.+Associative ℕSemiring p (a *N p) a)) (applyEquality (λ n → p +N n) (equalityCommutative (transitivity (multiplicationNIsCommutative a (succ p)) (transitivity (Semiring.commutative ℕSemiring a _) (applyEquality (_+N a) (multiplicationNIsCommutative p _))))))
divisionAlg : (a : ℕ) → (b : ℕ) → divisionAlgResult a b
divisionAlg zero = λ b → record { quot = zero ; rem = b ; pr = refl ; remIsSmall = inr refl ; quotSmall = inr (record { fst = refl ; snd = refl }) }
divisionAlg (succ a) = rec <NWellfounded (λ n → divisionAlgResult (succ a) n) go
where
go : (x : ℕ) (indHyp : (y : ℕ) (y<x : y <N x) → divisionAlgResult (succ a) y) →
divisionAlgResult (succ a) x
go zero prop = record { quot = zero ; rem = zero ; pr = divisionAlgLemma (succ a) zero ; remIsSmall = inl (succIsPositive a) ; quotSmall = inl (succIsPositive a) }
go (succ x) indHyp with totality (succ a) (succ x)
go (succ x) indHyp | inl (inl sa<sx) with indHyp (subtractionNResult.result (-N (inl sa<sx))) (divisionAlgLemma3 sa<sx)
... | record { quot = prevQuot ; rem = prevRem ; pr = prevPr ; remIsSmall = smallRem } = p
where
p : divisionAlgResult (succ a) (succ x)
addedA : (succ a *N prevQuot +N prevRem) +N (succ a) ≡ subtractionNResult.result (-N (inl sa<sx)) +N (succ a)
addedA' : (succ a *N prevQuot +N prevRem) +N succ a ≡ succ x
addedA'' : (succ a *N succ prevQuot) +N prevRem ≡ succ x
addedA''' : succ ((prevQuot +N a *N succ prevQuot) +N prevRem) ≡ succ x
addedA''' = identityOfIndiscernablesLeft _≡_ addedA'' refl
p = record { quot = succ prevQuot ; rem = prevRem ; pr = addedA''' ; remIsSmall = smallRem ; quotSmall = inl (succIsPositive a) }
addedA = applyEquality (λ n → n +N succ a) prevPr
addedA' = identityOfIndiscernablesRight _≡_ addedA (addMinus {succ a} {succ x} (inl sa<sx))
addedA'' = identityOfIndiscernablesLeft _≡_ addedA' (divisionAlgLemma4 prevQuot a prevRem)
go (succ x) indHyp | inr (sa=sx) = record { quot = succ zero ; rem = zero ; pr = divisionAlgLemma2 (succ a) (succ x) sa=sx ; remIsSmall = inl (succIsPositive a) ; quotSmall = inl (succIsPositive a) }
go (succ x) indHyp | inl (inr (sx<sa)) = record { quot = zero ; rem = succ x ; pr = divisionAlgLemma (succ a) (succ x) ; remIsSmall = inl sx<sa ; quotSmall = inl (succIsPositive a) }
data _∣_ : ℕ → ℕ → Set where
divides : {a b : ℕ} → (res : divisionAlgResult a b) → divisionAlgResult.rem res ≡ zero → a ∣ b
data _∣'_ : ℕ → ℕ → Set where
divides' : {a b : ℕ} → (res : divisionAlgResult' a b) → .(divisionAlgResult'.rem res ≡ zero) → a ∣' b
divToDiv' : {a b : ℕ} → a ∣ b → a ∣' b
divToDiv' (divides res x) = divides' (collapseDivAlgResult res) (transitivity (collapsePreservesRem res) x)
div'ToDiv : {a b : ℕ} → a ∣' b → a ∣ b
div'ToDiv (divides' res x) = divides (squashDivAlgResult res) (transitivity (squashPreservesRem res) (squashN record { eq = x }))
zeroDividesNothing : (a : ℕ) → zero ∣ succ a → False
zeroDividesNothing a (divides record { quot = quot ; rem = rem ; pr = pr } x) = naughtE p
where
p : zero ≡ succ a
p = transitivity (equalityCommutative x) pr
record hcfData (a b : ℕ) : Set where
field
c : ℕ
c|a : c ∣ a
c|b : c ∣ b
hcf : ∀ x → x ∣ a → x ∣ b → x ∣ c
positiveTimes : {a b : ℕ} → (succ a *N succ b <N succ a) → False
positiveTimes {a} {b} pr = zeroNeverGreater f'
where
g : succ a *N succ b <N succ a *N succ 0
g rewrite multiplicationNIsCommutative a 1 | Semiring.commutative ℕSemiring a 0 = pr
f : succ b <N succ 0
f = cancelInequalityLeft {succ a} {succ b} g
f' : b <N 0
f' = canRemoveSuccFrom<N f
biggerThanCantDivideLemma : {a b : ℕ} → (a <N b) → (b ∣ a) → a ≡ 0
biggerThanCantDivideLemma {zero} {b} a<b b|a = refl
biggerThanCantDivideLemma {succ a} {zero} a<b (divides record { quot = quot ; rem = .0 ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = (inl (le x ())) } refl)
biggerThanCantDivideLemma {succ a} {zero} a<b (divides record { quot = quot ; rem = .0 ; pr = () ; remIsSmall = remIsSmall ; quotSmall = (inr x) } refl)
biggerThanCantDivideLemma {succ a} {succ b} a<b (divides record { quot = zero ; rem = .0 ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } refl) rewrite Semiring.commutative ℕSemiring (b *N zero) 0 | multiplicationNIsCommutative b 0 = exFalso (naughtE pr)
biggerThanCantDivideLemma {succ a} {succ b} a<b (divides record { quot = (succ quot) ; rem = .0 ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } refl) rewrite Semiring.commutative ℕSemiring (quot +N b *N succ quot) 0 | equalityCommutative pr = exFalso (positiveTimes {b} {quot} a<b)
biggerThanCantDivide : {a b : ℕ} → (x : ℕ) → (TotalOrder.max ℕTotalOrder a b) <N x → (x ∣ a) → (x ∣ b) → (a ≡ 0) && (b ≡ 0)
biggerThanCantDivide {a} {b} x pr x|a x|b with totality a b
biggerThanCantDivide {a} {b} x pr x|a x|b | inl (inl a<b) = exFalso (zeroNeverGreater f')
where
f : b ≡ 0
f = biggerThanCantDivideLemma pr x|b
f' : a <N 0
f' rewrite equalityCommutative f = a<b
biggerThanCantDivide {a} {b} x pr x|a x|b | inl (inr b<a) = exFalso (zeroNeverGreater f')
where
f : a ≡ 0
f = biggerThanCantDivideLemma pr x|a
f' : b <N 0
f' rewrite equalityCommutative f = b<a
biggerThanCantDivide {a} {b} x pr x|a x|b | inr a=b = (transitivity a=b f ,, f)
where
f : b ≡ 0
f = biggerThanCantDivideLemma pr x|b
aDivA : (a : ℕ) → a ∣ a
aDivA zero = divides (record { quot = 0 ; rem = 0 ; pr = equalityCommutative (oneTimesPlusZero zero) ; remIsSmall = inr refl ; quotSmall = inr (refl ,, refl) }) refl
aDivA (succ a) = divides (record { quot = 1 ; rem = 0 ; pr = equalityCommutative (oneTimesPlusZero (succ a)) ; remIsSmall = inl (succIsPositive a) ; quotSmall = inl (succIsPositive a) }) refl
aDivZero : (a : ℕ) → a ∣ zero
aDivZero zero = aDivA zero
aDivZero (succ a) = divides (record { quot = zero ; rem = zero ; pr = lemma (succ a) ; remIsSmall = inl (succIsPositive a) ; quotSmall = inl (succIsPositive a) }) refl
where
lemma : (b : ℕ) → b *N zero +N zero ≡ zero
lemma b rewrite (Semiring.sumZeroRight ℕSemiring (b *N zero)) = Semiring.productZeroRight ℕSemiring b
record extendedHcf (a b : ℕ) : Set where
field
hcf : hcfData a b
c : ℕ
c = hcfData.c hcf
field
extended1 : ℕ
extended2 : ℕ
extendedProof : (a *N extended1 ≡ b *N extended2 +N c) || (a *N extended1 +N c ≡ b *N extended2)
divEqualityLemma1 : {a b c : ℕ} → b ≡ zero → b *N c +N 0 ≡ a → a ≡ b
divEqualityLemma1 {a} {.0} {c} refl pr = equalityCommutative pr
divEquality : {a b : ℕ} → a ∣ b → b ∣ a → a ≡ b
divEquality {a} {b} (divides record { quot = quotAB ; rem = .0 ; pr = prAB ; remIsSmall = _ ; quotSmall = quotSmallAB } refl) (divides record { quot = quot ; rem = .0 ; pr = pr ; remIsSmall = _ ; quotSmall = (inl x) } refl) rewrite Semiring.commutative ℕSemiring (b *N quot) 0 | Semiring.commutative ℕSemiring (a *N quotAB) 0 | equalityCommutative pr | equalityCommutative (Semiring.*Associative ℕSemiring b quot quotAB) = res
where
lem : {b r : ℕ} → b *N r ≡ b → (0 <N b) → r ≡ 1
lem {zero} {r} pr ()
lem {succ b} {zero} pr _ rewrite multiplicationNIsCommutative b 0 = exFalso (naughtE pr)
lem {succ b} {succ zero} pr _ = refl
lem {succ b} {succ (succ r)} pr _ rewrite multiplicationNIsCommutative b (succ (succ r)) | Semiring.commutative ℕSemiring (succ r) (b +N (b +N r *N b)) | equalityCommutative (Semiring.+Associative ℕSemiring b (b +N r *N b) (succ r)) | Semiring.commutative ℕSemiring (b +N r *N b) (succ r) = exFalso (cannotAddAndEnlarge'' {succ b} pr)
p : quot *N quotAB ≡ 1
p = lem prAB x
q : quot ≡ 1
q = _&&_.fst (productOneImpliesOperandsOne p)
res : b *N quot ≡ b
res rewrite q | multiplicationNIsCommutative b 1 | Semiring.commutative ℕSemiring b 0 = refl
divEquality {.0} {.0} (divides record { quot = quotAB ; rem = .0 ; pr = prAB ; remIsSmall = _ ; quotSmall = quotSmallAB } refl) (divides record { quot = quot ; rem = .0 ; pr = refl ; remIsSmall = _ ; quotSmall = (inr (refl ,, snd)) } refl) = refl
hcfWelldefined : {a b : ℕ} → (ab : hcfData a b) → (ab' : hcfData a b) → (hcfData.c ab ≡ hcfData.c ab')
hcfWelldefined {a} {b} record { c = c ; c|a = c|a ; c|b = c|b ; hcf = hcf } record { c = c' ; c|a = c|a' ; c|b = c|b' ; hcf = hcf' } with hcf c' c|a' c|b'
... | c'DivC with hcf' c c|a c|b
... | cDivC' = divEquality cDivC' c'DivC
reverseHCF : {a b : ℕ} → (ab : extendedHcf a b) → extendedHcf b a
reverseHCF {a} {b} record { hcf = record { c = c ; c|a = c|a ; c|b = c|b ; hcf = hcf } ; extended1 = extended1 ; extended2 = extended2 ; extendedProof = (inl x) } = record { hcf = record { c = c ; c|a = c|b ; c|b = c|a ; hcf = λ x z z₁ → hcf x z₁ z } ; extended1 = extended2 ; extended2 = extended1 ; extendedProof = inr (equalityCommutative x) }
reverseHCF {a} {b} record { hcf = record { c = c ; c|a = c|a ; c|b = c|b ; hcf = hcf } ; extended1 = extended1 ; extended2 = extended2 ; extendedProof = (inr x) } = record { hcf = record { c = c ; c|a = c|b ; c|b = c|a ; hcf = λ x z z₁ → hcf x z₁ z } ; extended1 = extended2 ; extended2 = extended1 ; extendedProof = inl (equalityCommutative x) }
oneDivN : (a : ℕ) → 1 ∣ a
oneDivN a = divides (record { quot = a ; rem = zero ; pr = pr ; remIsSmall = inl (succIsPositive zero) ; quotSmall = inl (le zero refl) }) refl
where
pr : (a +N zero) +N zero ≡ a
pr rewrite Semiring.sumZeroRight ℕSemiring (a +N zero) = Semiring.sumZeroRight ℕSemiring a
hcfZero : (a : ℕ) → extendedHcf zero a
hcfZero a = record { hcf = record { c = a ; c|a = aDivZero a ; c|b = aDivA a ; hcf = λ _ _ p → p } ; extended1 = 0 ; extended2 = 1 ; extendedProof = inr (equalityCommutative (Semiring.productOneRight ℕSemiring a))}
hcfOne : (a : ℕ) → extendedHcf 1 a
hcfOne a = record { hcf = record { c = 1 ; c|a = aDivA 1 ; c|b = oneDivN a ; hcf = λ _ z _ → z } ; extended1 = 1 ; extended2 = 0 ; extendedProof = inl g }
where
g : 1 ≡ a *N 0 +N 1
g rewrite multiplicationNIsCommutative a 0 = refl
zeroIsValidRem : (a : ℕ) → (0 <N a) || (a ≡ 0)
zeroIsValidRem zero = inr refl
zeroIsValidRem (succ a) = inl (succIsPositive a)
dividesBothImpliesDividesSum : {a x y : ℕ} → a ∣ x → a ∣ y → a ∣ (x +N y)
dividesBothImpliesDividesSum {a} {x} {y} (divides record { quot = xDivA ; rem = .0 ; pr = prA ; quotSmall = qsm1 } refl) (divides record { quot = quot ; rem = .0 ; pr = pr ; quotSmall = qsm2 } refl) = divides (record { quot = xDivA +N quot ; rem = 0 ; pr = go {a} {x} {y} {xDivA} {quot} pr prA ; remIsSmall = zeroIsValidRem a ; quotSmall = (quotSmall qsm1 qsm2) }) refl
where
go : {a x y quot quot2 : ℕ} → (a *N quot2 +N zero ≡ y) → (a *N quot +N zero ≡ x) → a *N (quot +N quot2) +N zero ≡ x +N y
go {a} {x} {y} {quot} {quot2} pr1 pr2 rewrite Semiring.sumZeroRight ℕSemiring (a *N quot) = identityOfIndiscernablesLeft _≡_ t (equalityCommutative (Semiring.sumZeroRight ℕSemiring (a *N (quot +N quot2))))
where
t : a *N (quot +N quot2) ≡ x +N y
t rewrite Semiring.sumZeroRight ℕSemiring (a *N quot2) = transitivity (Semiring.+DistributesOver* ℕSemiring a quot quot2) p
where
s : a *N quot +N a *N quot2 ≡ x +N a *N quot2
s = applyEquality (λ n → n +N a *N quot2) pr2
r : x +N a *N quot2 ≡ x +N y
r = applyEquality (λ n → x +N n) pr1
p : a *N quot +N a *N quot2 ≡ x +N y
p = transitivity s r
quotSmall : ((0 <N a) || ((0 ≡ a) && (xDivA ≡ 0))) → ((0 <N a) || ((0 ≡ a) && (quot ≡ 0))) → (0 <N a) || ((0 ≡ a) && (xDivA +N quot ≡ 0))
quotSmall (inl x1) (inl x2) = inl x1
quotSmall (inl x1) (inr x2) = inl x1
quotSmall (inr x1) (inl x2) = inl x2
quotSmall (inr (a=0 ,, bl)) (inr (_ ,, bl2)) = inr (a=0 ,, ans)
where
ans : xDivA +N quot ≡ 0
ans rewrite bl | bl2 = refl
dividesBothImpliesDividesDifference : {a b c : ℕ} → a ∣ b → a ∣ c → (c<b : c <N b) → a ∣ (subtractionNResult.result (-N (inl c<b)))
dividesBothImpliesDividesDifference {zero} {b} {.0} prab (divides record { quot = quot ; rem = .0 ; pr = refl } refl) c<b = prab
dividesBothImpliesDividesDifference {succ a} {b} {c} (divides record { quot = bDivSA ; rem = .0 ; pr = pr } refl) (divides record { quot = cDivSA ; rem = .0 ; pr = pr2 } refl) c<b rewrite (Semiring.sumZeroRight ℕSemiring (succ a *N cDivSA)) | (Semiring.sumZeroRight ℕSemiring (succ a *N bDivSA)) = divides (record { quot = subtractionNResult.result bDivSA-cDivSA ; rem = 0 ; pr = identityOfIndiscernablesLeft _≡_ (identityOfIndiscernablesLeft _≡_ s (equalityCommutative q)) (equalityCommutative (Semiring.sumZeroRight ℕSemiring _)) ; remIsSmall = inl (succIsPositive a) ; quotSmall = inl (succIsPositive a) }) refl
where
p : cDivSA <N bDivSA
p rewrite (equalityCommutative pr2) | (equalityCommutative pr) = cancelInequalityLeft {succ a} {cDivSA} {bDivSA} c<b
bDivSA-cDivSA : subtractionNResult cDivSA bDivSA (inl p)
bDivSA-cDivSA = -N {cDivSA} {bDivSA} (inl p)
la-ka = subtractionNResult.result (-N {succ a *N cDivSA} {succ a *N bDivSA} (inl (lessRespectsMultiplicationLeft cDivSA bDivSA (succ a) p (succIsPositive a))))
q : (succ a *N (subtractionNResult.result bDivSA-cDivSA)) ≡ la-ka
q = subtractProduct {succ a} {cDivSA} {bDivSA} (succIsPositive a) p
s : la-ka ≡ subtractionNResult.result (-N {c} {b} (inl c<b))
s = equivalentSubtraction (succ a *N cDivSA) b (succ a *N bDivSA) c (lessRespectsMultiplicationLeft cDivSA bDivSA (succ a) p (succIsPositive a)) c<b g
where
g : (succ a *N cDivSA) +N b ≡ (succ a *N bDivSA) +N c
g rewrite equalityCommutative pr2 | equalityCommutative pr = Semiring.commutative ℕSemiring (cDivSA +N a *N cDivSA) (bDivSA +N a *N bDivSA)
euclidLemma1 : {a b : ℕ} → (a<b : a <N b) → (t : ℕ) → a +N b <N t → a +N (subtractionNResult.result (-N (inl a<b))) <N t
euclidLemma1 {zero} {b} zero<b t b<t = b<t
euclidLemma1 {succ a} {b} sa<b t sa+b<t = identityOfIndiscernablesLeft _<N_ q (Semiring.commutative ℕSemiring (subtractionNResult.result (-N (inl sa<b))) (succ a))
where
p : b <N t
p = TotalOrder.<Transitive ℕTotalOrder (le a refl) sa+b<t
q : (subtractionNResult.result (-N (inl sa<b))) +N succ a <N t
q = identityOfIndiscernablesLeft _<N_ p (equalityCommutative (addMinus (inl sa<b)))
euclidLemma2 : {a b max : ℕ} → (succ (a +N b) <N max) → b <N max
euclidLemma2 {a} {b} {max} pr = lessTransitive {b} {succ (a +N b)} {max} (lemma a b) pr
where
lemma : (a b : ℕ) → b <N succ (a +N b)
lemma a b rewrite Semiring.commutative ℕSemiring (succ a) b = addingIncreases b a
euclidLemma3 : {a b max : ℕ} → (succ (succ (a +N b)) <N max) → succ b <N max
euclidLemma3 {a} {b} {max} pr = euclidLemma2 {a} {succ b} {max} (identityOfIndiscernablesLeft _<N_ pr (applyEquality succ (equalityCommutative (succExtracts a b))))
euclidLemma4 : (a b c d h : ℕ) → (sa<b : (succ a) <N b) → (pr : subtractionNResult.result (-N (inl sa<b)) *N c ≡ (succ a) *N d +N h) → b *N c ≡ (succ a) *N (d +N c) +N h
euclidLemma4 a b zero d h sa<b pr rewrite Semiring.sumZeroRight ℕSemiring d | Semiring.productZeroRight ℕSemiring b | Semiring.productZeroRight ℕSemiring (subtractionNResult.result (-N (inl sa<b))) = pr
euclidLemma4 a b (succ c) d h sa<b pr rewrite subtractProduct' (succIsPositive c) sa<b = transitivity q' r'
where
q : (succ c) *N b ≡ succ (a +N c *N succ a) +N ((succ a) *N d +N h)
q = moveOneSubtraction {succ (a +N c *N succ a)} {b +N c *N b} {(succ a) *N d +N h} {inl _} pr
q' : b *N succ c ≡ succ (a +N c *N succ a) +N ((succ a) *N d +N h)
q' rewrite multiplicationNIsCommutative b (succ c) = q
r' : ((succ c) *N succ a) +N (((succ a) *N d) +N h) ≡ ((succ a) *N (d +N succ c)) +N h
r' rewrite Semiring.+Associative ℕSemiring ((succ c) *N succ a) ((succ a) *N d) h = applyEquality (λ t → t +N h) {((succ c) *N succ a) +N ((succ a) *N d)} {(succ a) *N (d +N succ c)} (go (succ c) (succ a) d)
where
go' : (a b c : ℕ) → b *N a +N b *N c ≡ b *N (c +N a)
go : (a b c : ℕ) → a *N b +N b *N c ≡ b *N (c +N a)
go a b c rewrite multiplicationNIsCommutative a b = go' a b c
go' a b c rewrite Semiring.commutative ℕSemiring (b *N a) (b *N c) = equalityCommutative (Semiring.+DistributesOver* ℕSemiring b c a)
euclidLemma5 : (a b c d h : ℕ) → (sa<b : (succ a) <N b) → (pr : subtractionNResult.result (-N (inl sa<b)) *N c +N h ≡ (succ a) *N d) → (succ a) *N (d +N c) ≡ b *N c +N h
euclidLemma5 a b c d h sa<b pr with (-N (inl sa<b))
euclidLemma5 a b zero d h sa<b pr | record { result = result ; pr = sub } rewrite Semiring.sumZeroRight ℕSemiring d | Semiring.productZeroRight ℕSemiring b | Semiring.productZeroRight ℕSemiring result = equalityCommutative pr
euclidLemma5 a b (succ c) d h sa<b pr | record { result = result ; pr = sub } rewrite subtractProduct' (succIsPositive c) sa<b | equalityCommutative sub = pv''
where
p : succ a *N d ≡ result *N succ c +N h
p = equalityCommutative pr
p' : a *N succ c +N succ a *N d ≡ (a *N succ c) +N ((result *N succ c) +N h)
p' = applyEquality (λ t → a *N succ c +N t) p
p'' : a *N succ c +N succ a *N d ≡ (a *N succ c +N result *N succ c) +N h
p'' rewrite equalityCommutative (Semiring.+Associative ℕSemiring (a *N succ c) (result *N succ c) h) = p'
p''' : a *N succ c +N succ a *N d ≡ (a +N result) *N succ c +N h
p''' rewrite multiplicationNIsCommutative (a +N result) (succ c) | Semiring.+DistributesOver* ℕSemiring (succ c) a result | multiplicationNIsCommutative (succ c) a | multiplicationNIsCommutative (succ c) result = p''
pv : c +N (a *N succ c +N succ a *N d) ≡ (c +N (a +N result) *N succ c) +N h
pv rewrite equalityCommutative (Semiring.+Associative ℕSemiring c ((a +N result) *N succ c) h) = applyEquality (λ t → c +N t) p'''
pv' : (succ c) +N (a *N succ c +N succ a *N d) ≡ succ ((c +N (a +N result) *N succ c) +N h)
pv' = applyEquality succ pv
pv'' : (succ a) *N (d +N succ c) ≡ succ ((c +N (a +N result) *N succ c) +N h)
pv'' = identityOfIndiscernablesLeft _≡_ pv' (go a c d)
where
go : (a c d : ℕ) → (succ c) +N (a *N succ c +N ((succ a) *N d)) ≡ (succ a) *N (d +N succ c)
go a c d rewrite Semiring.+Associative ℕSemiring (succ c) (a *N succ c) ((succ a) *N d) = go'
where
go' : (succ a) *N (succ c) +N (succ a) *N d ≡ (succ a) *N (d +N succ c)
go' rewrite Semiring.commutative ℕSemiring d (succ c) = equalityCommutative (Semiring.+DistributesOver* ℕSemiring (succ a) (succ c) d)
euclid : (a b : ℕ) → extendedHcf a b
euclid a b = inducted (succ a +N b) a b (a<SuccA (a +N b))
where
P : ℕ → Set
P sum = ∀ (a b : ℕ) → a +N b <N sum → extendedHcf a b
go'' : {a b : ℕ} → (maxsum : ℕ) → (a <N b) → (a +N b <N maxsum) → (∀ y → y <N maxsum → P y) → extendedHcf a b
go'' {zero} {b} maxSum zero<b b<maxsum indHyp = hcfZero b
go'' {1} {b} maxSum 1<b b<maxsum indHyp = hcfOne b
go'' {succ (succ a)} {b} maxSum ssa<b ssa+b<maxsum indHyp with (indHyp (succ b) (euclidLemma3 {a} {b} {maxSum} ssa+b<maxsum)) (subtractionNResult.result (-N (inl ssa<b))) (succ (succ a)) (identityOfIndiscernablesLeft _<N_ (a<SuccA b) (equalityCommutative (addMinus (inl ssa<b))))
go'' {succ (succ a)} {b} maxSum ssa<b ssa+b<maxsum indHyp | record { hcf = record { c = c ; c|a = c|a ; c|b = c|b ; hcf = hcf } ; extended1 = extended1 ; extended2 = extended2 ; extendedProof = inl extendedProof } = record { hcf = record { c = c ; c|a = c|b ; c|b = hcfDivB'' ; hcf = λ div prDivSSA prDivB → hcf div (dividesBothImpliesDividesDifference prDivB prDivSSA ssa<b) prDivSSA } ; extended2 = extended1; extended1 = extended2 +N extended1 ; extendedProof = inr (equalityCommutative (euclidLemma4 (succ a) b extended1 extended2 c ssa<b extendedProof)) }
where
hcfDivB : c ∣ ((succ (succ a)) +N (subtractionNResult.result (-N (inl ssa<b))))
hcfDivB = dividesBothImpliesDividesSum {c} {succ (succ a)} { subtractionNResult.result (-N (inl ssa<b))} c|b c|a
hcfDivB' : c ∣ ((subtractionNResult.result (-N (inl ssa<b))) +N (succ (succ a)))
hcfDivB' = identityOfIndiscernablesRight _∣_ hcfDivB (Semiring.commutative ℕSemiring (succ (succ a)) ( subtractionNResult.result (-N (inl ssa<b))))
hcfDivB'' : c ∣ b
hcfDivB'' = identityOfIndiscernablesRight _∣_ hcfDivB' (addMinus (inl ssa<b))
go'' {succ (succ a)} {b} maxSum ssa<b ssa+b<maxsum indHyp | record { hcf = record { c = c ; c|a = c|a ; c|b = c|b ; hcf = hcf } ; extended1 = extended1 ; extended2 = extended2 ; extendedProof = inr extendedProof } = record { hcf = record { c = c ; c|a = c|b ; c|b = hcfDivB'' ; hcf = λ div prDivSSA prDivB → hcf div (dividesBothImpliesDividesDifference prDivB prDivSSA ssa<b) prDivSSA } ; extended2 = extended1; extended1 = extended2 +N extended1 ; extendedProof = inl (euclidLemma5 (succ a) b extended1 extended2 c ssa<b extendedProof) }
where
hcfDivB : c ∣ ((succ (succ a)) +N (subtractionNResult.result (-N (inl ssa<b))))
hcfDivB = dividesBothImpliesDividesSum {c} {succ (succ a)} { subtractionNResult.result (-N (inl ssa<b))} c|b c|a
hcfDivB' : c ∣ ((subtractionNResult.result (-N (inl ssa<b))) +N (succ (succ a)))
hcfDivB' = identityOfIndiscernablesRight _∣_ hcfDivB (Semiring.commutative ℕSemiring (succ (succ a)) (subtractionNResult.result (-N (inl ssa<b))))
hcfDivB'' : c ∣ b
hcfDivB'' = identityOfIndiscernablesRight _∣_ hcfDivB' (addMinus (inl ssa<b))
go' : (maxSum a b : ℕ) → (a +N b <N maxSum) → (∀ y → y <N maxSum → P y) → extendedHcf a b
go' maxSum a b a+b<maxsum indHyp with totality a b
go' maxSum a b a+b<maxsum indHyp | inl (inl a<b) = go'' maxSum a<b a+b<maxsum indHyp
go' maxSum a b a+b<maxsum indHyp | inl (inr b<a) = reverseHCF (go'' maxSum b<a (identityOfIndiscernablesLeft _<N_ a+b<maxsum (Semiring.commutative ℕSemiring a b)) indHyp)
go' maxSum a .a _ indHyp | inr refl = record { hcf = record { c = a ; c|a = aDivA a ; c|b = aDivA a ; hcf = λ _ _ z → z } ; extended1 = 0 ; extended2 = 1 ; extendedProof = inr s}
where
s : a *N zero +N a ≡ a *N 1
s rewrite multiplicationNIsCommutative a zero | Semiring.productOneRight ℕSemiring a = refl
go : ∀ x → (∀ y → y <N x → P y) → P x
go maxSum indHyp = λ a b a+b<maxSum → go' maxSum a b a+b<maxSum indHyp
inducted : ∀ x → P x
inducted = rec <NWellfounded P go
divOneImpliesOne : {a : ℕ} → a ∣ 1 → a ≡ 1
divOneImpliesOne {zero} a|1 = exFalso (zeroDividesNothing _ a|1)
divOneImpliesOne {succ zero} a|1 = refl
divOneImpliesOne {succ (succ a)} (divides record { quot = zero ; rem = .0 ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } refl) rewrite Semiring.sumZeroRight ℕSemiring (a *N zero) | multiplicationNIsCommutative a 0 = exFalso (naughtE pr)
divOneImpliesOne {succ (succ a)} (divides record { quot = (succ quot) ; rem = .0 ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } refl) rewrite Semiring.commutative ℕSemiring quot (succ (quot +N a *N succ quot)) = exFalso (naughtE (equalityCommutative (succInjective pr)))
|
{
"alphanum_fraction": 0.6359801115,
"avg_line_length": 79.7716346154,
"ext": "agda",
"hexsha": "397765a9f3b9bcde1a92a3afe4050b3502b87587",
"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": "Numbers/Naturals/EuclideanAlgorithm.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": "Numbers/Naturals/EuclideanAlgorithm.agda",
"max_line_length": 614,
"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": "Numbers/Naturals/EuclideanAlgorithm.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": 12349,
"size": 33185
}
|
{-# OPTIONS --cubical #-}
open import Agda.Builtin.Cubical.Path
data I : Set where
zero one : I
zero≡one : zero ≡ one
|
{
"alphanum_fraction": 0.6532258065,
"avg_line_length": 15.5,
"ext": "agda",
"hexsha": "28b85ec3607c56b7725f468bc9df0c15c1572303",
"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/Higher-inductive-types-are-not-supported.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/Higher-inductive-types-are-not-supported.agda",
"max_line_length": 37,
"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/Higher-inductive-types-are-not-supported.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": 41,
"size": 124
}
|
------------------------------------------------------------------------------
-- Theory T from the paper
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module T where
infixl 9 _·_ -- The symbol is '\cdot'.
infix 7 _≡_
------------------------------------------------------------------------------
postulate
T : Set
zero K S : T
succ : T → T
_·_ : T → T → T
-- The identity type on the universe of discourse.
data _≡_ (x : T) : T → Set where
refl : x ≡ x
-- Conversion rules
postulate
cK : ∀ x y → K · x · y ≡ x
cS : ∀ x y z → S · x · y · z ≡ x · z · (y · z)
|
{
"alphanum_fraction": 0.3447852761,
"avg_line_length": 26.2903225806,
"ext": "agda",
"hexsha": "b1dea2c4c7a7f4bfaf6ee1fe6ee411ba17153759",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/papers/paper-2011/T.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/papers/paper-2011/T.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/papers/paper-2011/T.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": 201,
"size": 815
}
|
{-# OPTIONS --rewriting #-}
module Properties.Subtyping where
open import Agda.Builtin.Equality using (_≡_; refl)
open import FFI.Data.Either using (Either; Left; Right; mapLR; swapLR; cond)
open import Luau.Subtyping using (_<:_; _≮:_; Tree; Language; ¬Language; witness; unknown; never; scalar; function; scalar-function; scalar-function-ok; scalar-function-err; scalar-scalar; function-scalar; function-ok; function-err; left; right; _,_)
open import Luau.Type using (Type; Scalar; nil; number; string; boolean; never; unknown; _⇒_; _∪_; _∩_; src; tgt)
open import Properties.Contradiction using (CONTRADICTION; ¬)
open import Properties.Equality using (_≢_)
open import Properties.Functions using (_∘_)
open import Properties.Product using (_×_; _,_)
-- Language membership is decidable
dec-language : ∀ T t → Either (¬Language T t) (Language T t)
dec-language nil (scalar number) = Left (scalar-scalar number nil (λ ()))
dec-language nil (scalar boolean) = Left (scalar-scalar boolean nil (λ ()))
dec-language nil (scalar string) = Left (scalar-scalar string nil (λ ()))
dec-language nil (scalar nil) = Right (scalar nil)
dec-language nil function = Left (scalar-function nil)
dec-language nil (function-ok t) = Left (scalar-function-ok nil)
dec-language nil (function-err t) = Right (scalar-function-err nil)
dec-language boolean (scalar number) = Left (scalar-scalar number boolean (λ ()))
dec-language boolean (scalar boolean) = Right (scalar boolean)
dec-language boolean (scalar string) = Left (scalar-scalar string boolean (λ ()))
dec-language boolean (scalar nil) = Left (scalar-scalar nil boolean (λ ()))
dec-language boolean function = Left (scalar-function boolean)
dec-language boolean (function-ok t) = Left (scalar-function-ok boolean)
dec-language boolean (function-err t) = Right (scalar-function-err boolean)
dec-language number (scalar number) = Right (scalar number)
dec-language number (scalar boolean) = Left (scalar-scalar boolean number (λ ()))
dec-language number (scalar string) = Left (scalar-scalar string number (λ ()))
dec-language number (scalar nil) = Left (scalar-scalar nil number (λ ()))
dec-language number function = Left (scalar-function number)
dec-language number (function-ok t) = Left (scalar-function-ok number)
dec-language number (function-err t) = Right (scalar-function-err number)
dec-language string (scalar number) = Left (scalar-scalar number string (λ ()))
dec-language string (scalar boolean) = Left (scalar-scalar boolean string (λ ()))
dec-language string (scalar string) = Right (scalar string)
dec-language string (scalar nil) = Left (scalar-scalar nil string (λ ()))
dec-language string function = Left (scalar-function string)
dec-language string (function-ok t) = Left (scalar-function-ok string)
dec-language string (function-err t) = Right (scalar-function-err string)
dec-language (T₁ ⇒ T₂) (scalar s) = Left (function-scalar s)
dec-language (T₁ ⇒ T₂) function = Right function
dec-language (T₁ ⇒ T₂) (function-ok t) = mapLR function-ok function-ok (dec-language T₂ t)
dec-language (T₁ ⇒ T₂) (function-err t) = mapLR function-err function-err (swapLR (dec-language T₁ t))
dec-language never t = Left never
dec-language unknown t = Right unknown
dec-language (T₁ ∪ T₂) t = cond (λ p → cond (Left ∘ _,_ p) (Right ∘ right) (dec-language T₂ t)) (Right ∘ left) (dec-language T₁ t)
dec-language (T₁ ∩ T₂) t = cond (Left ∘ left) (λ p → cond (Left ∘ right) (Right ∘ _,_ p) (dec-language T₂ t)) (dec-language T₁ t)
-- ¬Language T is the complement of Language T
language-comp : ∀ {T} t → ¬Language T t → ¬(Language T t)
language-comp t (p₁ , p₂) (left q) = language-comp t p₁ q
language-comp t (p₁ , p₂) (right q) = language-comp t p₂ q
language-comp t (left p) (q₁ , q₂) = language-comp t p q₁
language-comp t (right p) (q₁ , q₂) = language-comp t p q₂
language-comp (scalar s) (scalar-scalar s p₁ p₂) (scalar s) = p₂ refl
language-comp (scalar s) (function-scalar s) (scalar s) = language-comp function (scalar-function s) function
language-comp (scalar s) never (scalar ())
language-comp function (scalar-function ()) function
language-comp (function-ok t) (scalar-function-ok ()) (function-ok q)
language-comp (function-ok t) (function-ok p) (function-ok q) = language-comp t p q
language-comp (function-err t) (function-err p) (function-err q) = language-comp t q p
-- ≮: is the complement of <:
¬≮:-impl-<: : ∀ {T U} → ¬(T ≮: U) → (T <: U)
¬≮:-impl-<: {T} {U} p t q with dec-language U t
¬≮:-impl-<: {T} {U} p t q | Left r = CONTRADICTION (p (witness t q r))
¬≮:-impl-<: {T} {U} p t q | Right r = r
<:-impl-¬≮: : ∀ {T U} → (T <: U) → ¬(T ≮: U)
<:-impl-¬≮: p (witness t q r) = language-comp t r (p t q)
-- reflexivity
≮:-refl : ∀ {T} → ¬(T ≮: T)
≮:-refl (witness t p q) = language-comp t q p
<:-refl : ∀ {T} → (T <: T)
<:-refl = ¬≮:-impl-<: ≮:-refl
-- transititivity
≮:-trans-≡ : ∀ {S T U} → (S ≮: T) → (T ≡ U) → (S ≮: U)
≮:-trans-≡ p refl = p
≡-trans-≮: : ∀ {S T U} → (S ≡ T) → (T ≮: U) → (S ≮: U)
≡-trans-≮: refl p = p
≮:-trans : ∀ {S T U} → (S ≮: U) → Either (S ≮: T) (T ≮: U)
≮:-trans {T = T} (witness t p q) = mapLR (witness t p) (λ z → witness t z q) (dec-language T t)
<:-trans : ∀ {S T U} → (S <: T) → (T <: U) → (S <: U)
<:-trans p q = ¬≮:-impl-<: (cond (<:-impl-¬≮: p) (<:-impl-¬≮: q) ∘ ≮:-trans)
-- Properties of scalars
skalar = number ∪ (string ∪ (nil ∪ boolean))
function-≮:-scalar : ∀ {S T U} → (Scalar U) → ((S ⇒ T) ≮: U)
function-≮:-scalar s = witness function function (scalar-function s)
scalar-≮:-function : ∀ {S T U} → (Scalar U) → (U ≮: (S ⇒ T))
scalar-≮:-function s = witness (scalar s) (scalar s) (function-scalar s)
unknown-≮:-scalar : ∀ {U} → (Scalar U) → (unknown ≮: U)
unknown-≮:-scalar s = witness (function-ok (scalar s)) unknown (scalar-function-ok s)
scalar-≮:-never : ∀ {U} → (Scalar U) → (U ≮: never)
scalar-≮:-never s = witness (scalar s) (scalar s) never
scalar-≢-impl-≮: : ∀ {T U} → (Scalar T) → (Scalar U) → (T ≢ U) → (T ≮: U)
scalar-≢-impl-≮: s₁ s₂ p = witness (scalar s₁) (scalar s₁) (scalar-scalar s₁ s₂ p)
-- Properties of tgt
tgt-function-ok : ∀ {T t} → (Language (tgt T) t) → Language T (function-ok t)
tgt-function-ok {T = nil} (scalar ())
tgt-function-ok {T = T₁ ⇒ T₂} p = function-ok p
tgt-function-ok {T = never} (scalar ())
tgt-function-ok {T = unknown} p = unknown
tgt-function-ok {T = boolean} (scalar ())
tgt-function-ok {T = number} (scalar ())
tgt-function-ok {T = string} (scalar ())
tgt-function-ok {T = T₁ ∪ T₂} (left p) = left (tgt-function-ok p)
tgt-function-ok {T = T₁ ∪ T₂} (right p) = right (tgt-function-ok p)
tgt-function-ok {T = T₁ ∩ T₂} (p₁ , p₂) = (tgt-function-ok p₁ , tgt-function-ok p₂)
function-ok-tgt : ∀ {T t} → Language T (function-ok t) → (Language (tgt T) t)
function-ok-tgt (function-ok p) = p
function-ok-tgt (left p) = left (function-ok-tgt p)
function-ok-tgt (right p) = right (function-ok-tgt p)
function-ok-tgt (p₁ , p₂) = (function-ok-tgt p₁ , function-ok-tgt p₂)
function-ok-tgt unknown = unknown
skalar-function-ok : ∀ {t} → (¬Language skalar (function-ok t))
skalar-function-ok = (scalar-function-ok number , (scalar-function-ok string , (scalar-function-ok nil , scalar-function-ok boolean)))
skalar-scalar : ∀ {T} (s : Scalar T) → (Language skalar (scalar s))
skalar-scalar number = left (scalar number)
skalar-scalar boolean = right (right (right (scalar boolean)))
skalar-scalar string = right (left (scalar string))
skalar-scalar nil = right (right (left (scalar nil)))
tgt-never-≮: : ∀ {T U} → (tgt T ≮: U) → (T ≮: (skalar ∪ (never ⇒ U)))
tgt-never-≮: (witness t p q) = witness (function-ok t) (tgt-function-ok p) (skalar-function-ok , function-ok q)
never-tgt-≮: : ∀ {T U} → (T ≮: (skalar ∪ (never ⇒ U))) → (tgt T ≮: U)
never-tgt-≮: (witness (scalar s) p (q₁ , q₂)) = CONTRADICTION (≮:-refl (witness (scalar s) (skalar-scalar s) q₁))
never-tgt-≮: (witness function p (q₁ , scalar-function ()))
never-tgt-≮: (witness (function-ok t) p (q₁ , function-ok q₂)) = witness t (function-ok-tgt p) q₂
never-tgt-≮: (witness (function-err (scalar s)) p (q₁ , function-err (scalar ())))
-- Properties of src
function-err-src : ∀ {T t} → (¬Language (src T) t) → Language T (function-err t)
function-err-src {T = nil} never = scalar-function-err nil
function-err-src {T = T₁ ⇒ T₂} p = function-err p
function-err-src {T = never} (scalar-scalar number () p)
function-err-src {T = never} (scalar-function-ok ())
function-err-src {T = unknown} never = unknown
function-err-src {T = boolean} p = scalar-function-err boolean
function-err-src {T = number} p = scalar-function-err number
function-err-src {T = string} p = scalar-function-err string
function-err-src {T = T₁ ∪ T₂} (left p) = left (function-err-src p)
function-err-src {T = T₁ ∪ T₂} (right p) = right (function-err-src p)
function-err-src {T = T₁ ∩ T₂} (p₁ , p₂) = function-err-src p₁ , function-err-src p₂
¬function-err-src : ∀ {T t} → (Language (src T) t) → ¬Language T (function-err t)
¬function-err-src {T = nil} (scalar ())
¬function-err-src {T = T₁ ⇒ T₂} p = function-err p
¬function-err-src {T = never} unknown = never
¬function-err-src {T = unknown} (scalar ())
¬function-err-src {T = boolean} (scalar ())
¬function-err-src {T = number} (scalar ())
¬function-err-src {T = string} (scalar ())
¬function-err-src {T = T₁ ∪ T₂} (p₁ , p₂) = (¬function-err-src p₁ , ¬function-err-src p₂)
¬function-err-src {T = T₁ ∩ T₂} (left p) = left (¬function-err-src p)
¬function-err-src {T = T₁ ∩ T₂} (right p) = right (¬function-err-src p)
src-¬function-err : ∀ {T t} → Language T (function-err t) → (¬Language (src T) t)
src-¬function-err {T = nil} p = never
src-¬function-err {T = T₁ ⇒ T₂} (function-err p) = p
src-¬function-err {T = never} (scalar-function-err ())
src-¬function-err {T = unknown} p = never
src-¬function-err {T = boolean} p = never
src-¬function-err {T = number} p = never
src-¬function-err {T = string} p = never
src-¬function-err {T = T₁ ∪ T₂} (left p) = left (src-¬function-err p)
src-¬function-err {T = T₁ ∪ T₂} (right p) = right (src-¬function-err p)
src-¬function-err {T = T₁ ∩ T₂} (p₁ , p₂) = (src-¬function-err p₁ , src-¬function-err p₂)
src-¬scalar : ∀ {S T t} (s : Scalar S) → Language T (scalar s) → (¬Language (src T) t)
src-¬scalar number (scalar number) = never
src-¬scalar boolean (scalar boolean) = never
src-¬scalar string (scalar string) = never
src-¬scalar nil (scalar nil) = never
src-¬scalar s (left p) = left (src-¬scalar s p)
src-¬scalar s (right p) = right (src-¬scalar s p)
src-¬scalar s (p₁ , p₂) = (src-¬scalar s p₁ , src-¬scalar s p₂)
src-¬scalar s unknown = never
src-unknown-≮: : ∀ {T U} → (T ≮: src U) → (U ≮: (T ⇒ unknown))
src-unknown-≮: (witness t p q) = witness (function-err t) (function-err-src q) (¬function-err-src p)
unknown-src-≮: : ∀ {S T U} → (U ≮: S) → (T ≮: (U ⇒ unknown)) → (U ≮: src T)
unknown-src-≮: (witness t x x₁) (witness (scalar s) p (function-scalar s)) = witness t x (src-¬scalar s p)
unknown-src-≮: r (witness (function-ok (scalar s)) p (function-ok (scalar-scalar s () q)))
unknown-src-≮: r (witness (function-ok (function-ok _)) p (function-ok (scalar-function-ok ())))
unknown-src-≮: r (witness (function-err t) p (function-err q)) = witness t q (src-¬function-err p)
-- Properties of unknown and never
unknown-≮: : ∀ {T U} → (T ≮: U) → (unknown ≮: U)
unknown-≮: (witness t p q) = witness t unknown q
never-≮: : ∀ {T U} → (T ≮: U) → (T ≮: never)
never-≮: (witness t p q) = witness t p never
unknown-≮:-never : (unknown ≮: never)
unknown-≮:-never = witness (scalar nil) unknown never
function-≮:-never : ∀ {T U} → ((T ⇒ U) ≮: never)
function-≮:-never = witness function function never
-- A Gentle Introduction To Semantic Subtyping (https://www.cduce.org/papers/gentle.pdf)
-- defines a "set-theoretic" model (sec 2.5)
-- Unfortunately we don't quite have this property, due to uninhabited types,
-- for example (never -> T) is equivalent to (never -> U)
-- when types are interpreted as sets of syntactic values.
_⊆_ : ∀ {A : Set} → (A → Set) → (A → Set) → Set
(P ⊆ Q) = ∀ a → (P a) → (Q a)
_⊗_ : ∀ {A B : Set} → (A → Set) → (B → Set) → ((A × B) → Set)
(P ⊗ Q) (a , b) = (P a) × (Q b)
Comp : ∀ {A : Set} → (A → Set) → (A → Set)
Comp P a = ¬(P a)
set-theoretic-if : ∀ {S₁ T₁ S₂ T₂} →
-- This is the "if" part of being a set-theoretic model
(Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂)) →
(∀ Q → Q ⊆ Comp((Language S₁) ⊗ Comp(Language T₁)) → Q ⊆ Comp((Language S₂) ⊗ Comp(Language T₂)))
set-theoretic-if {S₁} {T₁} {S₂} {T₂} p Q q (t , u) Qtu (S₂t , ¬T₂u) = q (t , u) Qtu (S₁t , ¬T₁u) where
S₁t : Language S₁ t
S₁t with dec-language S₁ t
S₁t | Left ¬S₁t with p (function-err t) (function-err ¬S₁t)
S₁t | Left ¬S₁t | function-err ¬S₂t = CONTRADICTION (language-comp t ¬S₂t S₂t)
S₁t | Right r = r
¬T₁u : ¬(Language T₁ u)
¬T₁u T₁u with p (function-ok u) (function-ok T₁u)
¬T₁u T₁u | function-ok T₂u = ¬T₂u T₂u
not-quite-set-theoretic-only-if : ∀ {S₁ T₁ S₂ T₂} →
-- We don't quite have that this is a set-theoretic model
-- it's only true when Language T₁ and ¬Language T₂ t₂ are inhabited
-- in particular it's not true when T₁ is never, or T₂ is unknown.
∀ s₂ t₂ → Language S₂ s₂ → ¬Language T₂ t₂ →
-- This is the "only if" part of being a set-theoretic model
(∀ Q → Q ⊆ Comp((Language S₁) ⊗ Comp(Language T₁)) → Q ⊆ Comp((Language S₂) ⊗ Comp(Language T₂))) →
(Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂))
not-quite-set-theoretic-only-if {S₁} {T₁} {S₂} {T₂} s₂ t₂ S₂s₂ ¬T₂t₂ p = r where
Q : (Tree × Tree) → Set
Q (t , u) = Either (¬Language S₁ t) (Language T₁ u)
q : Q ⊆ Comp((Language S₁) ⊗ Comp(Language T₁))
q (t , u) (Left ¬S₁t) (S₁t , ¬T₁u) = language-comp t ¬S₁t S₁t
q (t , u) (Right T₂u) (S₁t , ¬T₁u) = ¬T₁u T₂u
r : Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂)
r function function = function
r (function-err t) (function-err ¬S₁t) with dec-language S₂ t
r (function-err t) (function-err ¬S₁t) | Left ¬S₂t = function-err ¬S₂t
r (function-err t) (function-err ¬S₁t) | Right S₂t = CONTRADICTION (p Q q (t , t₂) (Left ¬S₁t) (S₂t , language-comp t₂ ¬T₂t₂))
r (function-ok t) (function-ok T₁t) with dec-language T₂ t
r (function-ok t) (function-ok T₁t) | Left ¬T₂t = CONTRADICTION (p Q q (s₂ , t) (Right T₁t) (S₂s₂ , language-comp t ¬T₂t))
r (function-ok t) (function-ok T₁t) | Right T₂t = function-ok T₂t
-- A counterexample when the argument type is empty.
set-theoretic-counterexample-one : (∀ Q → Q ⊆ Comp((Language never) ⊗ Comp(Language number)) → Q ⊆ Comp((Language never) ⊗ Comp(Language string)))
set-theoretic-counterexample-one Q q ((scalar s) , u) Qtu (scalar () , p)
set-theoretic-counterexample-one Q q ((function-err t) , u) Qtu (scalar-function-err () , p)
set-theoretic-counterexample-two : (never ⇒ number) ≮: (never ⇒ string)
set-theoretic-counterexample-two = witness
(function-ok (scalar number)) (function-ok (scalar number))
(function-ok (scalar-scalar number string (λ ())))
-- At some point we may deal with overloaded function resolution, which should fix this problem...
-- The reason why this is connected to overloaded functions is that currently we have that the type of
-- f(x) is (tgt T) where f:T. Really we should have the type depend on the type of x, that is use (tgt T U),
-- where U is the type of x. In particular (tgt (S => T) (U & V)) should be the same as (tgt ((S&U) => T) V)
-- and tgt(never => T) should be unknown. For example
--
-- tgt((number => string) & (string => bool))(number)
-- is tgt(number => string)(number) & tgt(string => bool)(number)
-- is tgt(number => string)(number) & tgt(string => bool)(number&unknown)
-- is tgt(number => string)(number) & tgt(string&number => bool)(unknown)
-- is tgt(number => string)(number) & tgt(never => bool)(unknown)
-- is string & unknown
-- is string
--
-- there's some discussion of this in the Gentle Introduction paper.
|
{
"alphanum_fraction": 0.6483252074,
"avg_line_length": 50.9451612903,
"ext": "agda",
"hexsha": "b713eaf7db1520b08cd6061203a073e0092d52ce",
"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": "5bb9f379b07e378db0a170e7c4030e3a943b2f14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MeltzDev/luau",
"max_forks_repo_path": "prototyping/Properties/Subtyping.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5bb9f379b07e378db0a170e7c4030e3a943b2f14",
"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": "MeltzDev/luau",
"max_issues_repo_path": "prototyping/Properties/Subtyping.agda",
"max_line_length": 250,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5bb9f379b07e378db0a170e7c4030e3a943b2f14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MeltzDev/luau",
"max_stars_repo_path": "prototyping/Properties/Subtyping.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5442,
"size": 15793
}
|
------------------------------------------------------------------------------
-- The first-order theory of combinators (FOTC) base
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
{-
FOTC The logical framework (Agda)
* Logical constants * Curry-Howard isomorphism
* Equality * Identity type
* Term language and conversion rules * Postulates
* Inductively defined predicates * Inductive families
* Co-inductively defined predicates * Greatest fixed-points
-}
module FOTC.Base where
-- First-order logic with equality.
open import Common.FOL.FOL-Eq public
-- Common definitions.
open import Common.DefinitionsATP public
infixl 7 _·_
infix 0 if_then_else_
------------------------------------------------------------------------------
-- The term language of FOTC
-- t ::= x | t · t |
-- | true | false | if
-- | 0 | succ | pred | iszero
postulate
_·_ : D → D → D -- FOTC application.
true false if : D -- FOTC partial Booleans.
zero succ pred iszero : D -- FOTC partial natural numbers.
------------------------------------------------------------------------------
-- Definitions
-- We define some function symbols for convenience in writing and
-- looking for an optimization for the ATPs.
-- 2012-03-20. The definitions are inside an abstract block because
-- the conversion rules (see below) are based on them, so we want to
-- avoid their expansion.
abstract
if_then_else_ : D → D → D → D
if b then t else t' = if · b · t · t'
-- {-# ATP definition if_then_else_ #-}
succ₁ : D → D
succ₁ n = succ · n
-- {-# ATP definition succ₁ #-}
pred₁ : D → D
pred₁ n = pred · n
-- {-# ATP definition pred₁ #-}
iszero₁ : D → D
iszero₁ n = iszero · n
-- {-# ATP definition iszero₁ #-}
------------------------------------------------------------------------------
-- Conversion rules
-- The conversion relation _conv_ satifies (Aczel 1977, p. 8)
--
-- x conv y <=> FOTC ⊢ x ≡ y,
--
-- therefore, we introduce the conversion rules as non-logical axioms.
-- N.B. Looking for an optimization for the ATPs, we write the
-- conversion rules on the defined function symbols instead of on the
-- term constants.
-- Conversion rules for Booleans.
-- if-true : ∀ t {t'} → if · true · t · t' ≡ t
-- if-false : ∀ {t} t' → if · false · t · t' ≡ t'
postulate
if-true : ∀ t {t'} → (if true then t else t') ≡ t
if-false : ∀ {t} t' → (if false then t else t') ≡ t'
{-# ATP axioms if-true if-false #-}
-- Conversion rules for pred.
-- pred-0 : pred · zero ≡ zero
-- pred-S : ∀ n → pred · (succ · n) ≡ n
postulate
pred-0 : pred₁ zero ≡ zero
pred-S : ∀ n → pred₁ (succ₁ n) ≡ n
{-# ATP axioms pred-0 pred-S #-}
-- Conversion rules for iszero.
-- iszero-0 : iszero · zero ≡ true
-- iszero-S : ∀ n → iszero · (succ · n) ≡ false
postulate
iszero-0 : iszero₁ zero ≡ true
iszero-S : ∀ n → iszero₁ (succ₁ n) ≡ false
{-# ATP axioms iszero-0 iszero-S #-}
------------------------------------------------------------------------------
-- Discrimination rules
-- 0≢S : ∀ {n} → zero ≢ succ · n
postulate
t≢f : true ≢ false
0≢S : ∀ {n} → zero ≢ succ₁ n
{-# ATP axioms t≢f 0≢S #-}
------------------------------------------------------------------------------
-- References
--
-- Aczel, Peter (1977). The Strength of MartinLöf’s Intuitionistic
-- Type Theory with One Universe. In: Proc. of the Symposium on
-- Mathematical Logic (Oulu, 1974). Ed. by Miettinen, S. and Väänanen,
-- J. Report No. 2, Department of Philosophy, University of Helsinki,
-- Helsinki, pp. 1–32.
|
{
"alphanum_fraction": 0.515625,
"avg_line_length": 31.4838709677,
"ext": "agda",
"hexsha": "94520c4dcad0983bf10bbee692a4788f6ec0926c",
"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/Base.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/Base.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Base.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": 1030,
"size": 3904
}
|
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Escape {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Properties
open import Tools.Product
-- Valid types are well-formed.
escapeᵛ : ∀ {A l Γ} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ l ⟩ A / [Γ] → Γ ⊢ A
escapeᵛ [Γ] [A] =
let ⊢Γ = soundContext [Γ]
idSubst = idSubstS [Γ]
in escape (irrelevance′ (subst-id _) (proj₁ ([A] ⊢Γ idSubst)))
-- Valid type equality respects the equality relation.
escapeEqᵛ : ∀ {A B l Γ} ([Γ] : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
→ Γ ⊩ᵛ⟨ l ⟩ A ≡ B / [Γ] / [A] → Γ ⊢ A ≅ B
escapeEqᵛ [Γ] [A] [A≡B] =
let ⊢Γ = soundContext [Γ]
idSubst = idSubstS [Γ]
[idA] = proj₁ ([A] ⊢Γ idSubst)
[idA]′ = irrelevance′ (subst-id _) [idA]
in escapeEq [idA]′ (irrelevanceEq″ (subst-id _) (subst-id _)
[idA] [idA]′ ([A≡B] ⊢Γ idSubst))
-- Valid terms are well-formed.
escapeTermᵛ : ∀ {t A l Γ} ([Γ] : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
→ Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A] → Γ ⊢ t ∷ A
escapeTermᵛ [Γ] [A] [t] =
let ⊢Γ = soundContext [Γ]
idSubst = idSubstS [Γ]
[idA] = proj₁ ([A] ⊢Γ idSubst)
[idA]′ = irrelevance′ (subst-id _) (proj₁ ([A] ⊢Γ idSubst))
in escapeTerm [idA]′
(irrelevanceTerm″ (subst-id _) (subst-id _)
[idA] [idA]′ (proj₁ ([t] ⊢Γ idSubst)))
-- Valid term equality respects the equality relation.
escapeEqTermᵛ : ∀ {t u A l Γ} ([Γ] : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
→ Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A] → Γ ⊢ t ≅ u ∷ A
escapeEqTermᵛ [Γ] [A] [t≡u] =
let ⊢Γ = soundContext [Γ]
idSubst = idSubstS [Γ]
[idA] = proj₁ ([A] ⊢Γ idSubst)
[idA]′ = irrelevance′ (subst-id _) (proj₁ ([A] ⊢Γ idSubst))
in escapeTermEq [idA]′
(irrelevanceEqTerm″ (subst-id _) (subst-id _)
(subst-id _)
[idA] [idA]′ ([t≡u] ⊢Γ idSubst))
|
{
"alphanum_fraction": 0.5439834025,
"avg_line_length": 37.65625,
"ext": "agda",
"hexsha": "bf181a3c1c6350a6fa6c6d4a01cfb720b7cd5f7e",
"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": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Vtec234/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Substitution/Escape.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"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": "Vtec234/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Substitution/Escape.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Vtec234/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Substitution/Escape.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 932,
"size": 2410
}
|
{-# OPTIONS --safe #-}
module Cubical.HITs.SetQuotients.EqClass where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.HITs.PropositionalTruncation as Prop
open import Cubical.HITs.SetQuotients as SetQuot
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Functions.Embedding
open import Cubical.Functions.Surjection
private
variable
ℓ ℓ' ℓ'' : Level
-- another definition using equivalence classes
open BinaryRelation
open isEquivRel
open Iso
module _
{ℓ ℓ' : Level}
(X : Type ℓ) where
ℙ : Type (ℓ-max ℓ (ℓ-suc ℓ'))
ℙ = X → hProp ℓ'
ℙDec : Type (ℓ-max ℓ (ℓ-suc ℓ'))
ℙDec = Σ[ P ∈ ℙ ] ((x : X) → Dec (P x .fst))
isSetℙ : isSet ℙ
isSetℙ = isSetΠ λ x → isSetHProp
isSetℙDec : isSet ℙDec
isSetℙDec = isOfHLevelΣ 2 isSetℙ (λ P → isSetΠ (λ x → isProp→isSet (isPropDec (P x .snd))))
module _
(R : X → X → Type ℓ'') where
isEqClass : ℙ → Type (ℓ-max (ℓ-max ℓ ℓ') ℓ'')
isEqClass P = ∥ Σ[ x ∈ X ] ((a : X) → P a .fst ≃ ∥ R a x ∥) ∥
isPropIsEqClass : (P : ℙ) → isProp (isEqClass P)
isPropIsEqClass P = isPropPropTrunc
_∥_ : Type (ℓ-max (ℓ-max ℓ (ℓ-suc ℓ')) ℓ'')
_∥_ = Σ[ P ∈ ℙ ] isEqClass P
isSet∥ : isSet _∥_
isSet∥ = isOfHLevelΣ 2 isSetℙ (λ _ → isProp→isSet isPropPropTrunc)
module _
(dec : (x x' : X) → Dec (R x x')) where
_∥Dec_ : Type (ℓ-max (ℓ-max ℓ (ℓ-suc ℓ')) ℓ'')
_∥Dec_ = Σ[ P ∈ ℙDec ] isEqClass (P .fst)
isDecEqClass : (P : _∥_) → (x : X) → Dec (P .fst x .fst)
isDecEqClass (P , h) a =
Prop.rec (isPropDec (P a .snd)) (λ (x , p) → EquivPresDec (invEquiv (p a)) (Dec∥∥ (dec a x))) h
Iso-∥Dec-∥ : Iso _∥Dec_ _∥_
Iso-∥Dec-∥ .fun P = P .fst .fst , P .snd
Iso-∥Dec-∥ .inv P = (P .fst , isDecEqClass P) , P .snd
Iso-∥Dec-∥ .rightInv P = refl
Iso-∥Dec-∥ .leftInv P i .fst .fst = P .fst .fst
Iso-∥Dec-∥ .leftInv P i .fst .snd x =
isProp→PathP {B = λ i → Dec (P .fst .fst x .fst)}
(λ i → isPropDec (P .fst .fst x .snd))
(isDecEqClass (Iso-∥Dec-∥ .fun P) x) (P .fst .snd x) i
Iso-∥Dec-∥ .leftInv P i .snd = P .snd
∥Dec≃∥ : _∥Dec_ ≃ _∥_
∥Dec≃∥ = isoToEquiv Iso-∥Dec-∥
module _
{ℓ ℓ' ℓ'' : Level}
(X : Type ℓ)
(R : X → X → Type ℓ'')
(h : isEquivRel R) where
∥Rx∥Iso : (x x' : X)(r : R x x') → (a : X) → Iso ∥ R a x ∥ ∥ R a x' ∥
∥Rx∥Iso x x' r a .fun = Prop.rec isPropPropTrunc (λ r' → ∣ h .transitive _ _ _ r' r ∣)
∥Rx∥Iso x x' r a .inv = Prop.rec isPropPropTrunc (λ r' → ∣ h .transitive _ _ _ r' (h .symmetric _ _ r) ∣)
∥Rx∥Iso x x' r a .leftInv _ = isPropPropTrunc _ _
∥Rx∥Iso x x' r a .rightInv _ = isPropPropTrunc _ _
isEqClass∥Rx∥ : (x : X) → isEqClass X R (λ a → ∥ R a x ∥ , isPropPropTrunc)
isEqClass∥Rx∥ x = ∣ x , (λ _ → idEquiv _) ∣
∥R∥ : (x : X) → X ∥ R
∥R∥ x = (λ a → ∥ R a x ∥ , isPropPropTrunc) , isEqClass∥Rx∥ x
∥Rx∥Path : (x x' : X)(r : R x x') → ∥R∥ x ≡ ∥R∥ x'
∥Rx∥Path x x' r i .fst a .fst = ua (isoToEquiv (∥Rx∥Iso x x' r a)) i
∥Rx∥Path x x' r i .fst a .snd =
isProp→PathP {B = λ i → isProp (∥Rx∥Path x x' r i .fst a .fst)}
(λ i → isPropIsProp) isPropPropTrunc isPropPropTrunc i
∥Rx∥Path x x' r i .snd =
isProp→PathP {B = λ i → isEqClass X R (∥Rx∥Path x x' r i .fst)}
(λ i → isPropIsEqClass X R (∥Rx∥Path x x' r i .fst))
(isEqClass∥Rx∥ x) (isEqClass∥Rx∥ x') i
/→∥ : X / R → X ∥ R
/→∥ = SetQuot.rec (isSet∥ X R) ∥R∥ (λ x x' r → ∥Rx∥Path x x' r)
inj/→∥' : (x x' : X) → ∥R∥ x ≡ ∥R∥ x' → ∥ R x x' ∥
inj/→∥' x x' p = transport (λ i → p i .fst x .fst) ∣ h .reflexive x ∣
inj/→∥ : (x y : X / R) → /→∥ x ≡ /→∥ y → x ≡ y
inj/→∥ =
SetQuot.elimProp2 {P = λ x y → /→∥ x ≡ /→∥ y → x ≡ y}
(λ _ _ → isPropΠ (λ _ → squash/ _ _))
(λ x y q → Prop.rec (squash/ _ _) (λ r → eq/ _ _ r) (inj/→∥' x y q))
isEmbedding/→∥ : isEmbedding /→∥
isEmbedding/→∥ = injEmbedding squash/ (isSet∥ X R) (λ {x} {y} → inj/→∥ x y)
surj/→∥ : (P : X ∥ R) → ((x , _) : Σ[ x ∈ X ] ((a : X) → P .fst a .fst ≃ ∥ R a x ∥)) → ∥R∥ x ≡ P
surj/→∥ P (x , p) i .fst a .fst = ua (p a) (~ i)
surj/→∥ P (x , p) i .fst a .snd =
isProp→PathP {B = λ i → isProp (surj/→∥ P (x , p) i .fst a .fst)}
(λ i → isPropIsProp) isPropPropTrunc (P .fst a .snd) i
surj/→∥ P (x , p) i .snd =
isProp→PathP {B = λ i → isEqClass X R (surj/→∥ P (x , p) i .fst)}
(λ i → isPropIsEqClass X R (surj/→∥ P (x , p) i .fst))
(isEqClass∥Rx∥ x) (P .snd) i
isSurjection/→∥ : isSurjection /→∥
isSurjection/→∥ P = Prop.rec isPropPropTrunc (λ p → ∣ [ p .fst ] , surj/→∥ P p ∣) (P .snd)
-- both definitions are equivalent
equivQuot : X / R ≃ X ∥ R
equivQuot = /→∥ , isEmbedding×isSurjection→isEquiv (isEmbedding/→∥ , isSurjection/→∥)
|
{
"alphanum_fraction": 0.5411576207,
"avg_line_length": 34.4344827586,
"ext": "agda",
"hexsha": "917cadff1caa64d60bd86f50ae442829a3521094",
"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": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/HITs/SetQuotients/EqClass.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"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": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/HITs/SetQuotients/EqClass.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/HITs/SetQuotients/EqClass.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2310,
"size": 4993
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module constructs the unit of the monoidal structure on
-- R-modules, and similar for weaker module-like structures.
-- The intended universal property is that the maps out of the tensor
-- unit into M are isomorphic to the elements of M.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Algebra.Module.Construct.TensorUnit where
open import Algebra.Bundles
open import Algebra.Module.Bundles
open import Level
private
variable
c ℓ : Level
leftSemimodule : {R : Semiring c ℓ} → LeftSemimodule R c ℓ
leftSemimodule {R = semiring} = record
{ Carrierᴹ = Carrier
; _≈ᴹ_ = _≈_
; _+ᴹ_ = _+_
; _*ₗ_ = _*_
; 0ᴹ = 0#
; isLeftSemimodule = record
{ +ᴹ-isCommutativeMonoid = +-isCommutativeMonoid
; isPreleftSemimodule = record
{ *ₗ-cong = *-cong
; *ₗ-zeroˡ = zeroˡ
; *ₗ-distribʳ = distribʳ
; *ₗ-identityˡ = *-identityˡ
; *ₗ-assoc = *-assoc
; *ₗ-zeroʳ = zeroʳ
; *ₗ-distribˡ = distribˡ
}
}
} where open Semiring semiring
rightSemimodule : {R : Semiring c ℓ} → RightSemimodule R c ℓ
rightSemimodule {R = semiring} = record
{ Carrierᴹ = Carrier
; _≈ᴹ_ = _≈_
; _+ᴹ_ = _+_
; _*ᵣ_ = _*_
; 0ᴹ = 0#
; isRightSemimodule = record
{ +ᴹ-isCommutativeMonoid = +-isCommutativeMonoid
; isPrerightSemimodule = record
{ *ᵣ-cong = *-cong
; *ᵣ-zeroʳ = zeroʳ
; *ᵣ-distribˡ = distribˡ
; *ᵣ-identityʳ = *-identityʳ
; *ᵣ-assoc = *-assoc
; *ᵣ-zeroˡ = zeroˡ
; *ᵣ-distribʳ = distribʳ
}
}
} where open Semiring semiring
bisemimodule : {R : Semiring c ℓ} → Bisemimodule R R c ℓ
bisemimodule {R = semiring} = record
{ isBisemimodule = record
{ +ᴹ-isCommutativeMonoid = +-isCommutativeMonoid
; isPreleftSemimodule =
LeftSemimodule.isPreleftSemimodule leftSemimodule
; isPrerightSemimodule =
RightSemimodule.isPrerightSemimodule rightSemimodule
; *ₗ-*ᵣ-assoc = *-assoc
}
} where open Semiring semiring
semimodule : {R : CommutativeSemiring c ℓ} → Semimodule R c ℓ
semimodule {R = commutativeSemiring} = record
{ isSemimodule = record
{ isBisemimodule = Bisemimodule.isBisemimodule bisemimodule
}
} where open CommutativeSemiring commutativeSemiring
leftModule : {R : Ring c ℓ} → LeftModule R c ℓ
leftModule {R = ring} = record
{ -ᴹ_ = -_
; isLeftModule = record
{ isLeftSemimodule = LeftSemimodule.isLeftSemimodule leftSemimodule
; -ᴹ‿cong = -‿cong
; -ᴹ‿inverse = -‿inverse
}
} where open Ring ring
rightModule : {R : Ring c ℓ} → RightModule R c ℓ
rightModule {R = ring} = record
{ -ᴹ_ = -_
; isRightModule = record
{ isRightSemimodule = RightSemimodule.isRightSemimodule rightSemimodule
; -ᴹ‿cong = -‿cong
; -ᴹ‿inverse = -‿inverse
}
} where open Ring ring
bimodule : {R : Ring c ℓ} → Bimodule R R c ℓ
bimodule {R = ring} = record
{ isBimodule = record
{ isBisemimodule = Bisemimodule.isBisemimodule bisemimodule
; -ᴹ‿cong = -‿cong
; -ᴹ‿inverse = -‿inverse
}
} where open Ring ring
⟨module⟩ : {R : CommutativeRing c ℓ} → Module R c ℓ
⟨module⟩ {R = commutativeRing} = record
{ isModule = record
{ isBimodule = Bimodule.isBimodule bimodule
}
} where open CommutativeRing commutativeRing
|
{
"alphanum_fraction": 0.6291410144,
"avg_line_length": 28.906779661,
"ext": "agda",
"hexsha": "2dbdda06cb5eb8e11b2d9dfd3e12d04464b20c84",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Algebra/Module/Construct/TensorUnit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Algebra/Module/Construct/TensorUnit.agda",
"max_line_length": 75,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/Module/Construct/TensorUnit.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": 1251,
"size": 3411
}
|
-- Andreas, 2019-06-26, issue #3855
-- Mark erased hypotheses as such in a non-erased goal.
-- Same for irrelevance.
Goal :
( A : Set)
(@0 B : Set)
(@irr C : Set)
(@0 @irr D : Set)
( A : Set)
(@0 B : Set)
(@irr C : Set)
(@0 @irr D : Set)
→ Set
Goal A B C D = λ A B C D → {!!}
-- Goal: Set
-- ————————————————————————————————————————————————————————————
-- D : Set (erased, irrelevant)
-- C : Set (irrelevant)
-- B : Set (erased)
-- A : Set
-- D = D₁ : Set (not in scope, erased, irrelevant)
-- C = C₁ : Set (not in scope, irrelevant)
-- B = B₁ : Set (not in scope, erased)
-- A = A₁ : Set (not in scope)
-- Don't show erasure in erased goal!
@0 ErasedGoal :
( A : Set)
(@0 B : Set)
(@irr C : Set)
(@0 @irr D : Set)
( A : Set)
(@0 B : Set)
(@irr C : Set)
(@0 @irr D : Set)
→ Set
ErasedGoal A B C D = λ A B C D → {!!}
-- Goal: Set
-- ————————————————————————————————————————————————————————————
-- D : Set (irrelevant)
-- C : Set (irrelevant)
-- B : Set
-- A : Set
-- D = D₁ : Set (not in scope, irrelevant)
-- C = C₁ : Set (not in scope, irrelevant)
-- B = B₁ : Set (not in scope)
-- A = A₁ : Set (not in scope)
-- Don't show irrelevance in irrelevant goal!
@irr IrrGoal :
( A : Set)
(@0 B : Set)
(@irr C : Set)
(@0 @irr D : Set)
( A : Set)
(@0 B : Set)
(@irr C : Set)
(@0 @irr D : Set)
→ Set
IrrGoal A B C D = λ A B C D → {!!}
-- Goal: Set
-- ————————————————————————————————————————————————————————————
-- D : Set (erased)
-- C : Set
-- B : Set (erased)
-- A : Set
-- D = D₁ : Set (not in scope, erased)
-- C = C₁ : Set (not in scope)
-- B = B₁ : Set (not in scope, erased)
-- A = A₁ : Set (not in scope)
|
{
"alphanum_fraction": 0.4138118543,
"avg_line_length": 23.2784810127,
"ext": "agda",
"hexsha": "27d6aac709959a13a34effbdb827221dc142969a",
"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/Issue3855-8.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/Issue3855-8.agda",
"max_line_length": 63,
"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/Issue3855-8.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": 648,
"size": 1839
}
|
{-# OPTIONS --without-K --cubical #-}
module combinatorial-objects where
import 14-univalence
open 14-univalence public
{- The type ℍ of hereditarily finite types is introduces as an inductive type.
Note that this is the type of 'planar' combinatorial objects, because Fin n
is a linearly ordered finite set with n elements.
For a non-planar type of hereditarily finite types, we need to use the type
𝔽, which is the image of (Fin : ℕ → UU lzero). This latter type probably has
the correct identity type, and is more interesting from the perspective of
homotopy type theory.
Planar hereditarily finite types are easier to handle though, so we study
them first.
-}
data ℍ : UU lzero where
join-ℍ : (n : ℕ) → (Fin n → ℍ) → ℍ
width-ℍ : ℍ → ℕ
width-ℍ (join-ℍ n x) = n
branch-ℍ : (x : ℍ) → (Fin (width-ℍ x) → ℍ)
branch-ℍ (join-ℍ n x) = x
empty-ℍ : ℍ
empty-ℍ = join-ℍ zero-ℕ ind-empty
Fin-ℍ : ℕ → ℍ
Fin-ℍ n = join-ℍ n (const (Fin n) ℍ empty-ℍ)
unit-ℍ : ℍ
unit-ℍ = Fin-ℍ one-ℕ
{- Logical morphisms of hereditarily finite types. -}
hom-ℍ : ℍ → ℍ → UU lzero
hom-ℍ (join-ℍ m x) (join-ℍ n y) =
Σ (Fin m → Fin n) (λ h → (i : Fin m) → hom-ℍ (x i) (y (h i)))
map-base-hom-ℍ : (x y : ℍ) (f : hom-ℍ x y) →
Fin (width-ℍ x) → Fin (width-ℍ y)
map-base-hom-ℍ (join-ℍ m x) (join-ℍ n y) = pr1
hom-branch-hom-ℍ : (x y : ℍ) (f : hom-ℍ x y) (i : Fin (width-ℍ x)) →
hom-ℍ (branch-ℍ x i) (branch-ℍ y (map-base-hom-ℍ x y f i))
hom-branch-hom-ℍ (join-ℍ m x) (join-ℍ n y) = pr2
htpy-hom-ℍ : {x y : ℍ} (f g : hom-ℍ x y) → UU lzero
htpy-hom-ℍ {join-ℍ m x} {join-ℍ n y} (pair f F) g =
Σ ( f ~ (map-base-hom-ℍ (join-ℍ m x) (join-ℍ n y) g))
( λ H →
( i : Fin m) →
htpy-hom-ℍ
( tr (λ t → hom-ℍ (x i) (y t)) (H i) (F i))
( hom-branch-hom-ℍ (join-ℍ m x) (join-ℍ n y) g i))
refl-htpy-hom-ℍ : {x y : ℍ} {f : hom-ℍ x y} → htpy-hom-ℍ f f
refl-htpy-hom-ℍ {join-ℍ m x} {join-ℍ n y} {pair f F} =
pair refl-htpy (λ i → refl-htpy-hom-ℍ)
htpy-hom-ℍ-eq : {x y : ℍ} {f g : hom-ℍ x y} → (Id f g) → htpy-hom-ℍ f g
htpy-hom-ℍ-eq refl = refl-htpy-hom-ℍ
is-contr-total-htpy-hom-ℍ : {x y : ℍ} (f : hom-ℍ x y) →
is-contr (Σ (hom-ℍ x y) (htpy-hom-ℍ f))
is-contr-total-htpy-hom-ℍ {join-ℍ m x} {join-ℍ n y} (pair f F) =
is-contr-total-Eq-structure
( λ g G (H : f ~ g) →
( i : Fin m) →
htpy-hom-ℍ
( tr (λ t → hom-ℍ (x i) (y t)) (H i) (F i))
( G i))
( is-contr-total-htpy f)
( pair f refl-htpy)
( is-contr-total-Eq-Π
( λ i G → htpy-hom-ℍ (F i) G)
( λ i → is-contr-total-htpy-hom-ℍ (F i))
( λ i → F i))
is-equiv-htpy-hom-ℍ-eq : {x y : ℍ} (f g : hom-ℍ x y) →
is-equiv (htpy-hom-ℍ-eq {x} {y} {f} {g})
is-equiv-htpy-hom-ℍ-eq f =
fundamental-theorem-id f
( refl-htpy-hom-ℍ)
( is-contr-total-htpy-hom-ℍ f)
( λ g → htpy-hom-ℍ-eq)
eq-htpy-hom-ℍ : {x y : ℍ} {f g : hom-ℍ x y} → htpy-hom-ℍ f g → Id f g
eq-htpy-hom-ℍ {x} {y} {f} {g} =
inv-is-equiv (is-equiv-htpy-hom-ℍ-eq f g)
id-ℍ : {x : ℍ} → hom-ℍ x x
id-ℍ {join-ℍ n x} = pair id (λ i → id-ℍ)
comp-ℍ :
{x y z : ℍ} (g : hom-ℍ y z) (f : hom-ℍ x y) → hom-ℍ x z
comp-ℍ {join-ℍ m x} {join-ℍ n y} {join-ℍ k z} (pair g G) (pair f F) =
pair (g ∘ f) (λ i → comp-ℍ (G (f i)) (F i))
left-unit-law-htpy-hom-ℍ :
{x y : ℍ} (f : hom-ℍ x y) → htpy-hom-ℍ (comp-ℍ id-ℍ f) f
left-unit-law-htpy-hom-ℍ {join-ℍ m x} {join-ℍ n y} (pair f F) =
pair refl-htpy (λ i → left-unit-law-htpy-hom-ℍ (F i))
left-unit-law-hom-ℍ :
{x y : ℍ} (f : hom-ℍ x y) → Id (comp-ℍ id-ℍ f) f
left-unit-law-hom-ℍ f = eq-htpy-hom-ℍ (left-unit-law-htpy-hom-ℍ f)
right-unit-law-htpy-hom-ℍ :
{x y : ℍ} (g : hom-ℍ x y) → htpy-hom-ℍ (comp-ℍ g id-ℍ) g
right-unit-law-htpy-hom-ℍ {join-ℍ m x} {join-ℍ n y} (pair g G) =
pair refl-htpy (λ i → right-unit-law-htpy-hom-ℍ (G i))
right-unit-law-hom-ℍ :
{x y : ℍ} (g : hom-ℍ x y) → Id (comp-ℍ g id-ℍ) g
right-unit-law-hom-ℍ g = eq-htpy-hom-ℍ (right-unit-law-htpy-hom-ℍ g)
associative-htpy-comp-ℍ :
{x y z w : ℍ} (h : hom-ℍ z w) (g : hom-ℍ y z) (f : hom-ℍ x y) →
htpy-hom-ℍ (comp-ℍ (comp-ℍ h g) f) (comp-ℍ h (comp-ℍ g f))
associative-htpy-comp-ℍ
{join-ℍ n1 x1} {join-ℍ n2 x2} {join-ℍ n3 x3} {join-ℍ n4 x4} (pair h H) (pair g G) (pair f F) =
pair refl-htpy (λ i → associative-htpy-comp-ℍ (H (g (f i))) (G (f i)) (F i))
associative-comp-ℍ :
{x y z w : ℍ} (h : hom-ℍ z w) (g : hom-ℍ y z) (f : hom-ℍ x y) →
Id (comp-ℍ (comp-ℍ h g) f) (comp-ℍ h (comp-ℍ g f))
associative-comp-ℍ h g f = eq-htpy-hom-ℍ (associative-htpy-comp-ℍ h g f)
{-
{- Union of planar hereditarily finite sets -}
{-
map-add-Fin : {m n : ℕ} → Fin (add-ℕ m n) → coprod (Fin m) (Fin n)
map-add-Fin {zero-ℕ} {n} x = inr x
map-add-Fin {succ-ℕ m} {n} (inl x) = {!!}
map-add-Fin {succ-ℕ m} {n} (inr star) = ?
-}
{-
union-ℍ : ℍ → ℍ → ℍ
union-ℍ (join-ℍ n f) (join-ℍ m g) = join-ℍ (add-ℕ n m) ((ind-coprod (λ x → ℍ) f g) ∘ map-add-Fin)
-}
{- We define the Rado graph to be the graph with set of vertices ℍ, and for each (f : Fin n → ℍ) and each (i : Fin n), an edge from (join-ℍ n f) to (f i).
Note that in this definition of the Rado graph, there can be multiple edges
from x to y. -}
data Rado-ℍ : ℍ → ℍ → UU lzero where
edge-Rado-ℍ : (n : ℕ) (f : Fin n → ℍ) (i : Fin n) → Rado-ℍ (join-ℍ n f) (f i)
{- Next, we define the Ackermann bijection from ℍ to ℕ. -}
finite-sum-ℕ : (n : ℕ) → (f : Fin n → ℕ) → ℕ
finite-sum-ℕ zero-ℕ f = zero-ℕ
finite-sum-ℕ (succ-ℕ n) f = add-ℕ (f (inr star)) (finite-sum-ℕ n (f ∘ inl))
map-Ackermann-ℍ : ℍ → ℕ
map-Ackermann-ℍ (join-ℍ n f) =
finite-sum-ℕ n (λ i → pow-ℕ (succ-ℕ (succ-ℕ zero-ℕ)) (map-Ackermann-ℍ (f i)))
{- In order to construct the inverse of the Ackermann map, we need to show
first that every natural number can be uniquely represented as a list of
booleans. -}
ℕ-list-bool : list bool → ℕ
ℕ-list-bool nil = zero-ℕ
ℕ-list-bool (cons false l) = pow-ℕ (succ-ℕ (succ-ℕ zero-ℕ)) (ℕ-list-bool l)
ℕ-list-bool (cons true l) = succ-ℕ (pow-ℕ (succ-ℕ (succ-ℕ zero-ℕ)) (ℕ-list-bool l))
list-bool-ℕ : ℕ → list bool
list-bool-ℕ zero-ℕ = nil
list-bool-ℕ (succ-ℕ n) = {!!}
inv-Ackermann-ℍ : ℕ → ℍ
inv-Ackermann-ℍ n = {!!}
-}
|
{
"alphanum_fraction": 0.5734072022,
"avg_line_length": 33.172972973,
"ext": "agda",
"hexsha": "3e46a9a22fafd1ede6852abbef25d1cfb2d8a5a6",
"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": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "tmoux/HoTT-Intro",
"max_forks_repo_path": "Agda/combinatorial-objects.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "tmoux/HoTT-Intro",
"max_issues_repo_path": "Agda/combinatorial-objects.agda",
"max_line_length": 156,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "tmoux/HoTT-Intro",
"max_stars_repo_path": "Agda/combinatorial-objects.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2938,
"size": 6137
}
|
-- The default include path should contain Agda.Primitive
module TestDefaultIncludePath where
import Agda.Primitive
-- That's it.
|
{
"alphanum_fraction": 0.7851851852,
"avg_line_length": 13.5,
"ext": "agda",
"hexsha": "71a9a80da23b482238153297244a233525c95ee3",
"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/succeed/TestDefaultIncludePath.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/TestDefaultIncludePath.agda",
"max_line_length": 57,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "masondesu/agda",
"max_stars_repo_path": "test/succeed/TestDefaultIncludePath.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": 30,
"size": 135
}
|
record Pointed (A : Set) : Set where
field
point : A
point : {A : Set} ⦃ p : Pointed A ⦄ → A
point ⦃ p = p ⦄ = Pointed.point p
record R : Set₁ where
field
A : Set
instance
is-pointed : Pointed A
postulate
r : R
open R r
x : R.A r
x = point
|
{
"alphanum_fraction": 0.562962963,
"avg_line_length": 12.2727272727,
"ext": "agda",
"hexsha": "4f06ffb6a3af6dd47c5c5c09831f51b02e3ae5b2",
"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/Issue1915.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/Issue1915.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/Succeed/Issue1915.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": 107,
"size": 270
}
|
module Generic.Test.Data.Product where
open import Generic.Main as Main hiding (Σ; proj₁; proj₂; _,′_) renaming (_,_ to _,′_)
infixr 4 _,_
Σ : ∀ {α β} -> (A : Set α) -> (A -> Set β) -> Set (α ⊔ β)
Σ = readData Main.Σ
pattern _,_ x y = !#₀ (relv x ,′ relv y ,′ lrefl)
proj₁ : ∀ {α β} {A : Set α} {B : A -> Set β} -> Σ A B -> A
proj₁ (x , y) = x
proj₂ : ∀ {α β} {A : Set α} {B : A -> Set β} -> (p : Σ A B) -> B (proj₁ {B = B} p)
proj₂ (x , y) = y
ηo : ∀ {α β} {A : Set α} {B : A -> Set β} -> (p : Σ A B) -> p ≡ proj₁ {B = B} p , proj₂ {B = B} p
ηo (x , y) = refl
|
{
"alphanum_fraction": 0.4823943662,
"avg_line_length": 28.4,
"ext": "agda",
"hexsha": "2390016b7f8598620612b6776b01138ddcdad131",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z",
"max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Test/Data/Product.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "turion/Generic",
"max_issues_repo_path": "src/Generic/Test/Data/Product.agda",
"max_line_length": 97,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Test/Data/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z",
"num_tokens": 262,
"size": 568
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.Equivalence2
open import lib.NConnected
open import lib.types.TLevel
open import lib.types.Truncation
open import lib.types.Group
open import lib.groups.LoopSpace
open import lib.groups.Homomorphism
module lib.types.EilenbergMacLane1 {i} where
module _ (G : Group i) where
postulate -- HIT
EM₁ : Type i
embase' : EM₁
emloop' : Group.El G → embase' == embase'
emloop-comp' : ∀ g₁ g₂ → emloop' (Group.comp G g₁ g₂) == emloop' g₁ ∙ emloop' g₂
EM₁-level' : has-level ⟨ 1 ⟩ EM₁
⊙EM₁ : Ptd i
⊙EM₁ = ⊙[ EM₁ , embase' ]
module _ {G : Group i} where
private
module G = Group G
embase = embase' G
emloop = emloop' G
emloop-comp = emloop-comp' G
instance
EM₁-level : {n : ℕ₋₂} → has-level (S (S (S n))) (EM₁ G)
EM₁-level {⟨-2⟩} = EM₁-level' G
EM₁-level {S n} = raise-level _ EM₁-level
abstract
-- This was in the original paper, but is actually derivable.
emloop-ident : emloop G.ident == idp
emloop-ident = ! $ anti-whisker-right (emloop G.ident) $
ap emloop (! $ G.unit-r G.ident) ∙ emloop-comp G.ident G.ident
module EM₁Elim {j} {P : EM₁ G → Type j}
{{_ : (x : EM₁ G) → has-level ⟨ 1 ⟩ (P x)}}
(embase* : P embase)
(emloop* : (g : G.El) → embase* == embase* [ P ↓ emloop g ])
(emloop-comp* : (g₁ g₂ : G.El) →
emloop* (G.comp g₁ g₂) == emloop* g₁ ∙ᵈ emloop* g₂
[ (λ p → embase* == embase* [ P ↓ p ]) ↓ emloop-comp g₁ g₂ ])
where
postulate -- HIT
f : Π (EM₁ G) P
embase-β : f embase ↦ embase*
{-# REWRITE embase-β #-}
postulate -- HIT
emloop-β : (g : G.El) → apd f (emloop g) == emloop* g
open EM₁Elim public using () renaming (f to EM₁-elim)
module EM₁Rec {j} {C : Type j}
{{_ : has-level ⟨ 1 ⟩ C}} (embase* : C)
(hom* : G →ᴳ (Ω^S-group 0 ⊙[ C , embase* ])) where
private
module M = EM₁Elim {P = λ _ → C}
embase* (λ g → ↓-cst-in (GroupHom.f hom* g))
(λ g₁ g₂ → ↓-cst-in2 (GroupHom.pres-comp hom* g₁ g₂)
∙'ᵈ ↓-cst-in-∙ (emloop g₁) (emloop g₂)
(GroupHom.f hom* g₁) (GroupHom.f hom* g₂))
f = M.f
emloop-β : (g : G.El) → ap f (emloop g) == GroupHom.f hom* g
emloop-β g = apd=cst-in {f = f} (M.emloop-β g)
open EM₁Rec public using () renaming (f to EM₁-rec)
-- basic lemmas about [EM₁]
module _ {G : Group i} where
private
module G = Group G
abstract
emloop-inv : ∀ g → emloop' G (G.inv g) == ! (emloop g)
emloop-inv g = cancels-inverse _ _ lemma
where
cancels-inverse : ∀ {i} {A : Type i} {x y : A}
(p : x == y) (q : y == x) → p ∙ q == idp → p == ! q
cancels-inverse p idp r = ! (∙-unit-r p) ∙ r
lemma : emloop' G (G.inv g) ∙ emloop g == idp
lemma = ! (emloop-comp (G.inv g) g) ∙ ap emloop (G.inv-l g) ∙ emloop-ident
{- EM₁ is 0-connected -}
instance
EM₁-conn : is-connected 0 (EM₁ G)
EM₁-conn = has-level-in ([ embase ] , Trunc-elim
(EM₁-elim
{P = λ x → [ embase ] == [ x ]}
{{λ _ → raise-level _ (=-preserves-level Trunc-level)}}
idp
(λ _ → prop-has-all-paths-↓)
(λ _ _ → set-↓-has-all-paths-↓)))
|
{
"alphanum_fraction": 0.5509583207,
"avg_line_length": 29.6126126126,
"ext": "agda",
"hexsha": "e670106929b3a3547e3112a9b074071cfda6bb24",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/EilenbergMacLane1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/EilenbergMacLane1.agda",
"max_line_length": 84,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/EilenbergMacLane1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1224,
"size": 3287
}
|
{-# OPTIONS --prop --show-irrelevant #-}
open import Agda.Builtin.Equality
postulate
A : Set
P : Prop
f : P → A
g : A → P
{-# TERMINATING #-}
loop : A → A
loop y = loop y
mutual
X : A
X = _
test : ∀ y → X ≡ f (g (loop y))
test y = refl
-- The occurs check should not try to normalize the argument `loop y`
-- because it only appears in an irrelevant context.
|
{
"alphanum_fraction": 0.6062992126,
"avg_line_length": 15.875,
"ext": "agda",
"hexsha": "9adfb361a2d0f41b8159365b6c35bdeabac1f5f0",
"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/Issue4120-loop.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/Issue4120-loop.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/Issue4120-loop.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": 121,
"size": 381
}
|
open import Type
module Relator.Congruence {ℓ₁}{ℓ₂} {X : Type{ℓ₁}}{Y : Type{ℓ₂}} where
import Lvl
open import Functional
open import Logic
open import Logic.Propositional
open import Relator.Equals
-- The congruence relation with respect to a relation
infixl 15 _≅_of_
data _≅_of_ (x₁ : X) (x₂ : X) (f : X → Y) : Stmt{ℓ₂} where
[≅]-intro : (f(x₁) ≡ f(x₂)) → (x₁ ≅ x₂ of f)
[≅]-elim : ∀{x₁ x₂ : X}{f : X → Y} → (x₁ ≅ x₂ of f) → (f(x₁) ≡ f(x₂))
[≅]-elim ([≅]-intro eq) = eq
|
{
"alphanum_fraction": 0.6128364389,
"avg_line_length": 26.8333333333,
"ext": "agda",
"hexsha": "225634cdec11e75b259a960e5712d51288b6aafb",
"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": "Relator/Congruence.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": "Relator/Congruence.agda",
"max_line_length": 69,
"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": "Relator/Congruence.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": 212,
"size": 483
}
|
{-# OPTIONS --without-K #-}
module PointedPi where
open import Level using (_⊔_) renaming (zero to l0; suc to lsuc)
open import Universe using (Universe)
open import Categories.Category using (Category)
open import Categories.Groupoid using (Groupoid)
open import Categories.Functor using (Functor)
open import Data.Empty using (⊥)
open import Data.Unit using (⊤; tt)
open import Data.Sum hiding ([_,_])
open import Data.Product
open import Relation.Binary.PropositionalEquality as P
open import Function using (flip)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Nat.Properties.Simple using (+-right-identity)
open import Data.Integer using (ℤ;+_;-[1+_]) renaming (suc to ℤsuc; -_ to ℤ-; _+_ to _ℤ+_)
open import Data.List using (List; foldr; replicate; _++_) renaming (map to Lmap; [] to nil; _∷_ to _∷:_)
open import Data.List.Any using (module Membership-≡; here; there)
open Membership-≡
open import Data.List.Properties using ()
open import Categories.Groupoid.Sum using () renaming (Sum to GSum)
open import Categories.Groupoid.Product using () renaming (Product to GProduct)
open import PiU using (U; ZERO; ONE; PLUS; TIMES; toℕ)
open import PiLevel0
open import PiLevel1
open import PiEquiv renaming (eval to ap; evalB to apB)
open import Equiv
open import PiIter
data Pointed (t : U) : Set where
∙ : ⟦ t ⟧ → Pointed t
-- yes, re-use name eval on purpose here
eval : {t₁ t₂ : U} → (t₁ ⟷ t₂) → Pointed t₁ → Pointed t₂
eval c (∙ x) = ∙ (ap c x)
-- all our values will be 'subtypes' of this:
record V (t : U) : Set where
constructor v
field
pt : ⟦ t ⟧
auto : t ⟷ t
evalV : {t₁ t₂ : U} → (t₁ ⟷ t₂) → V t₁ → V t₂
evalV c (v pt auto) = v (ap c pt) (! c ◎ auto ◎ c)
-- V equivalence
record _≈_ {t : U} (a : V t) (b : V t) : Set where
constructor veq
field
pt-eq : V.pt a P.≡ V.pt b
auto-eq : V.auto a ⇔ V.auto b
-- and in general, all our morphisms will be 'subtypes' of
record H {s t : U} (a : V s) (b : V t) : Set where
constructor mor
field
transp : s ⟷ t
t-eq : evalV transp a ≈ b
--- Generating sets: lists of combinators over a type
GenSet : U → Set
GenSet t = List (t ⟷ t)
-- We will need to use a choice between 3 things. Don't want
-- to abuse ⊎. The 3 things can be understood as
-- Forward, Backward and Neutral. So we name it ⇕.
infix 30 _⇕_
data _⇕_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where
Fwd : (x : A) → A ⇕ B
Bwd : (y : B) → A ⇕ B
Neu : A ⇕ B
-- note that this uses ≡ (inside ∈), not ⇔. On purpose.
inGS : {t : U} → GenSet t → Set
inGS {t} S = Σ (t ⟷ t) (λ p → (p ∈ S) ⇕ (p ∈ S))
-- flip a ⇕
flip⇕ : ∀ {a b} {A : Set a} {B : Set b} → A ⇕ B → B ⇕ A
flip⇕ (Fwd x) = Bwd x
flip⇕ (Bwd y) = Fwd y
flip⇕ Neu = Neu
-- type of sequences of applications from GenSet
CombS : {t : U} → GenSet t → Set
CombS {t} S = List ( inGS S )
extract : {t : U} {S : GenSet t} → inGS S → (t ⟷ t)
extract (p , Fwd x) = p
extract (p , Bwd y) = ! p
extract (p , Neu ) = id⟷
interp : {t : U} {S : GenSet t} → CombS S → (t ⟷ t)
interp l = foldr _◎_ id⟷ (Lmap extract l)
-- the combinator (CombS S) acts as a sort of reference point
data U↑ : Set where
↑ : U → U↑
# : {τ : U} → (S : GenSet τ) → CombS S → U↑
1/ : {τ : U} → (S : GenSet τ) → CombS S → U↑
_⊞_ : U↑ → U↑ → U↑
_⊠_ : U↑ → U↑ → U↑
infix 40 _⇿_
data _⇿_ : U↑ → U↑ → Set where
↑ : {t₁ t₂ : U} → t₁ ⟷ t₂ → ↑ t₁ ⇿ ↑ t₂
ev : {t₁ : U} {S : GenSet t₁} → (q : CombS S) → ((# S q) ⊠ (1/ S q)) ⇿ ↑ ONE
coev : {t₁ : U} {S : GenSet t₁} → (q : CombS S) → ↑ ONE ⇿ ((# S q) ⊠ (1/ S q))
id⇿ : {t₁ : U↑} → t₁ ⇿ t₁ -- needed for coev of ⊠
UG : Universe l0 (lsuc l0)
UG = record {
U = U↑
; El = λ T → Σ[ ℂ ∈ Category l0 l0 l0 ] (Groupoid ℂ)
}
-- for convenience, create some types which are embedable into V
D : U → Set
D t = ⟦ t ⟧
embedD : {t : U} → D t → V t
embedD w = v w id⟷
-- and D equality lifts to ≈
embedDeq : {τ : U} → (s t : D τ) → s ≡ t → embedD s ≈ embedD t
embedDeq s .s P.refl = veq P.refl id⇔
-- even more to the point, it lifts to describing Hom sets
-- note how we can't use embedDeq directly!
embedDHom : {τ : U} → (s t : D τ) → s ≡ t → H (embedD s) (embedD t)
embedDHom s .s P.refl = mor id⟷ (veq P.refl (trans⇔ idl◎l idl◎l))
-- this is the same as in 2DTypes/groupoid
discreteC : U → Category _ _ _
discreteC t = record {
Obj = D t
; _⇒_ = λ s₁ s₂ → s₁ P.≡ s₂ -- see embedDHom
; _≡_ = λ _ _ → ⊤ -- hard-code proof-irrelevance
; id = P.refl
; _∘_ = flip P.trans
; assoc = tt
; identityˡ = tt
; identityʳ = tt
; equiv = record { refl = tt ; sym = λ _ → tt ; trans = λ _ _ → tt }
; ∘-resp-≡ = λ _ _ → tt
}
-- ditto
discreteG : (t : U) → Groupoid (discreteC t)
discreteG S = record
{ _⁻¹ = λ { {A} {.A} refl → P.refl }
; iso = record { isoˡ = tt; isoʳ = tt }
}
-----------
--- Structure theorems for ⇕
extract-GS[]≡id⟷ : ∀ {t : U} → (gs : GenSet t) → gs ≡ nil →
(∀ (y : inGS gs) → extract y ≡ id⟷)
extract-GS[]≡id⟷ .nil refl (p , Fwd ())
extract-GS[]≡id⟷ .nil refl (p , Bwd ())
extract-GS[]≡id⟷ .nil refl (p , Neu) = refl
private
Iter→CombS : ∀ {τ : U} (c : τ ⟷ τ) → Iter c → CombS (c ∷: nil)
Iter→CombS p (iter (+_ n) _ _) = replicate n (p , Fwd (here refl))
Iter→CombS p (iter (-[1+_] n) _ _) = replicate (suc n) (p , Bwd (here refl))
CombS→Iter : ∀ {τ : U} (c : τ ⟷ τ) → CombS (c ∷: nil) → Iter c
CombS→Iter p nil = iter (+ 0) id⟷ id⇔
CombS→Iter p (x ∷: xs) with CombS→Iter p xs
CombS→Iter p ((.p , Fwd (here refl)) ∷: xs) | iter i q pf =
iter (ℤsuc i) (p ◎ q) (trans⇔ (id⇔ ⊡ pf)
(trans⇔ (idr◎r ⊡ id⇔) (2! (lower (+ 1) i))))
CombS→Iter p ((p' , Fwd (there ())) ∷: xs) | iter i q pf
CombS→Iter p ((.p , Bwd (here refl)) ∷: xs) | iter i q pf =
iter (i ℤ+ -[1+ 0 ]) (q ◎ (! p))
(trans⇔ (pf ⊡ id⇔) (2! (lower i -[1+ 0 ])))
CombS→Iter p ((p' , Bwd (there ())) ∷: xs) | iter i q pf
CombS→Iter p ((p' , Neu) ∷: xs) | iter i q pf = iter i q pf
-- split Fwd case from Bwd
preserve-iter : ∀ {τ : U} (c : τ ⟷ τ) → (n : ℕ) →
let p = CombS→Iter c (replicate n (c , Fwd (here refl))) in
Iter.i p ≡ + n
preserve-iter c zero = refl
preserve-iter c (suc n) = cong ℤsuc (preserve-iter c n)
preserve-iterB : ∀ {τ : U} (c : τ ⟷ τ) → (n : ℕ) →
let p = CombS→Iter c (replicate (suc n) (c , Bwd (here refl))) in
Iter.i p ≡ -[1+ n ]
preserve-iterB c zero = refl
preserve-iterB c (suc i) = P.trans
(cong (λ z → z ℤ+ -[1+ 0 ]) (preserve-iterB c i))
(cong (λ z → -[1+ (suc z) ]) (+-right-identity i))
P2C2P : ∀ {τ : U} (c : τ ⟷ τ) → (p : Iter c) → (CombS→Iter c (Iter→CombS c p)) ≡c p
P2C2P c (iter (+_ zero) p' p'⇔p^i) = eqc refl (2! p'⇔p^i)
P2C2P c (iter (+_ (suc n)) p' p'⇔p^i) with CombS→Iter c (replicate n (c , Fwd (here refl))) | P.inspect (λ nn → CombS→Iter c (replicate nn (c , Fwd (here refl)))) n
... | iter i q pf | [ eq ] =
let i=n = (P.trans (cong Iter.i (P.sym eq)) (preserve-iter c n)) in
eqc (cong ℤsuc i=n) (trans⇔ (id⇔ {c = c} ⊡ pf)
(trans⇔ (id⇔ ⊡ P.subst (λ j → c ^ i ⇔ c ^ j) i=n (id⇔ {c = c ^ i})) (2! p'⇔p^i)))
P2C2P c (iter (-[1+_] n) p' p'⇔p^i) with CombS→Iter c (replicate (suc n) (c , Bwd (here refl))) | P.inspect (λ nn → CombS→Iter c (replicate (suc nn) (c , Bwd (here refl)))) n
... | iter i q pf | [ eq ] =
let i=n = P.trans (cong Iter.i (P.sym eq)) (preserve-iterB c n) in
eqc i=n (trans⇔ (P.subst (λ j → q ⇔ c ^ j) i=n pf) (2! p'⇔p^i))
C2P2C : ∀ {τ : U} (c : τ ⟷ τ) → (q : CombS (c ∷: nil)) →
interp (Iter→CombS c (CombS→Iter c q)) ⇔ interp q
C2P2C c nil = id⇔
C2P2C c (x ∷: q) with CombS→Iter c q | (C2P2C c) q
C2P2C c ((.c , Fwd (here refl)) ∷: q) | iter (+_ n) p' pf | pf2 = id⇔ ⊡ pf2
C2P2C c ((.c , Fwd (here refl)) ∷: q) | iter (-[1+_] zero) p' pf | pf2 =
trans⇔ (linv◎r {c = c}) (id⇔ ⊡ trans⇔ idr◎r pf2)
C2P2C c ((.c , Fwd (here refl)) ∷: q) | iter (-[1+_] (suc n)) p' pf | pf2 =
trans⇔ (trans⇔ idl◎r (linv◎r ⊡ id⇔)) (trans⇔ assoc◎r (id⇔ ⊡ pf2))
C2P2C c ((comb , Fwd (there ())) ∷: q) | iter i p' pf | pf2
C2P2C c ((.c , Bwd (here refl)) ∷: q) | iter (+_ zero) p' pf | pf2 = id⇔ ⊡ pf2
C2P2C c ((.c , Bwd (here refl)) ∷: q) | iter (+_ (suc n)) p' pf | pf2 =
trans⇔ (trans⇔ idl◎r (rinv◎r ⊡ id⇔)) (trans⇔ assoc◎r (id⇔ ⊡ pf2))
C2P2C c ((.c , Bwd (here refl)) ∷: q) | iter (-[1+_] n) p' pf | pf2 =
id⇔ {c = ! c} ⊡ (P.subst (λ j → ! c ◎ foldr _◎_ id⟷ (Lmap extract (replicate j (c , Bwd (here refl)))) ⇔ foldr _◎_ id⟷ (Lmap extract q)) (P.sym (+-right-identity n)) pf2)
C2P2C c ((comb , Bwd (there ())) ∷: q) | iter i p' pf | pf2
C2P2C c ((comb , Neu) ∷: q) | iter i p' pf | pf2 = trans⇔ pf2 idl◎r
-- we would like to say:
-- Iter[p]≃CombS[p] : ∀ {τ : U} (p : τ ⟷ τ) → Iter p ≃ CombS (p ∷: nil)
-- but the homotopies have the wrong type (≡ rather than ≡c and ⇔).
-----------
-- Generalization of # p to # S.
orderC : {τ : U} → (S : GenSet τ) → Category _ _ _
orderC {τ} S = record {
Obj = CombS S
; _⇒_ = λ q₁ q₂ → interp q₁ ⇔ interp q₂
; _≡_ = λ _ _ → ⊤
; id = id⇔
; _∘_ = flip trans⇔
; assoc = tt
; identityˡ = tt
; identityʳ = tt
; equiv = record { refl = tt; sym = λ _ → tt; trans = λ _ _ → tt }
; ∘-resp-≡ = λ _ _ → tt
}
orderG : {τ : U} → (S : GenSet τ) → Groupoid (orderC S)
orderG {τ} S = record {
_⁻¹ = 2!
; iso = record {
isoˡ = tt
; isoʳ = tt
}
}
commute-interp-++ : ∀ {τ : U} {S : GenSet τ} (f g : CombS S) →
interp (f ++ g) ⇔ interp f ◎ interp g
commute-interp-++ nil g = idl◎r
commute-interp-++ (x ∷: f) g = trans⇔ (id⇔ ⊡ commute-interp-++ f g) assoc◎l
1/orderC : {τ : U} → (S : GenSet τ) → Category _ _ _
1/orderC S = record {
Obj = ⊤
; _⇒_ = λ _ _ → CombS S
; _≡_ = λ p q → interp p ⇔ interp q
; id = nil
; _∘_ = _++_
; assoc = λ { {f = f} {g} {h} → trans⇔ (commute-interp-++ (h ++ g) f) (
trans⇔ (commute-interp-++ h g ⊡ id⇔) (
trans⇔ assoc◎r (
trans⇔ (id⇔ ⊡ (2! (commute-interp-++ g f))) (
2! (commute-interp-++ h (g ++ f)))))) }
; identityˡ = id⇔ -- could also use idl◎l like below
; identityʳ = λ { {f = f} → trans⇔ (commute-interp-++ f nil) idr◎l }
; equiv = record { refl = id⇔ ; sym = 2! ; trans = trans⇔ }
; ∘-resp-≡ = λ { {f = f} {h} {g} {i} f⇔h g⇔i →
trans⇔ (commute-interp-++ f g) (trans⇔ (f⇔h ⊡ g⇔i) (2! (commute-interp-++ h i))) }
}
flipGS : {τ : U} {S : GenSet τ} → inGS S → inGS S
flipGS (c , pf) = c , flip⇕ pf
invert-CombS : {τ : U} {S : GenSet τ} → CombS S → CombS S
invert-CombS pl = Data.List.map flipGS (Data.List.reverse pl)
-- sometimes we need to do some list manipulations under interp
lift-≡ : {t₁ t₂ : U} {p q : t₁ ⟷ t₂} → p ≡ q → p ⇔ q
lift-≡ refl = id⇔
interp-invert : {τ : U} {S : GenSet τ} → (x : inGS S) → (f : CombS S) →
interp (invert-CombS (x ∷: f)) ⇔ interp (invert-CombS f) ◎ extract (flipGS x)
interp-invert (c , Fwd x) f = {!!}
interp-invert (c , Bwd y) f = {!!}
interp-invert (c , Neu) f = {!!}
extract-flipGS : {τ : U} {S : GenSet τ} → (x : inGS S) → extract (flipGS x) ⇔ ! (extract x)
extract-flipGS (proj₁ , Fwd x) = id⇔
extract-flipGS (proj₁ , Bwd y) = 2! !!⇔id
extract-flipGS (proj₁ , Neu) = id⇔
private
left-invCS : {τ : U} {S : GenSet τ} (f : CombS S) → interp (invert-CombS f ++ f) ⇔ id⟷
left-invCS nil = id⇔
left-invCS (x ∷: f) = trans⇔
(commute-interp-++ (invert-CombS (x ∷: f)) (x ∷: f)) (trans⇔
(interp-invert x f ⊡ id⇔) (trans⇔
assoc◎r (trans⇔
(id⇔ ⊡ assoc◎l) (trans⇔
(id⇔ ⊡ trans⇔ (trans⇔ (extract-flipGS x ⊡ id⇔) rinv◎l ⊡ id⇔) idl◎l) (trans⇔
(2! (commute-interp-++ (invert-CombS f) f)) (left-invCS f))))))
right-invCS : {τ : U} {S : GenSet τ} (f : CombS S) → interp (f ++ invert-CombS f) ⇔ id⟷
right-invCS l = {!!}
1/orderG : {τ : U} → (S : GenSet τ) → Groupoid (1/orderC S)
1/orderG s = record {
_⁻¹ = invert-CombS
; iso = λ {_} {_} {f} → record {
isoˡ = left-invCS f
; isoʳ = right-invCS f
}
}
-----------
--- Our semantics into groupoids
⟦_⟧↑ : (T : U↑) → Universe.El UG T
⟦ ↑ S ⟧↑ = , discreteG S
⟦ # S q ⟧↑ = , orderG S -- the base point doesn't matter here?
⟦ 1/ S q ⟧↑ = , 1/orderG S -- ditto?
⟦ x ⊞ y ⟧↑ with ⟦ x ⟧↑ | ⟦ y ⟧↑
... | (_ , G₁) | (_ , G₂) = , GSum G₁ G₂
⟦ x ⊠ y ⟧↑ with ⟦ x ⟧↑ | ⟦ y ⟧↑
... | (_ , G₁) | (_ , G₂) = , GProduct G₁ G₂
record W (t : U↑) : Set where
constructor w
field
pt : Category.Obj (proj₁ ⟦ t ⟧↑)
auto : Category._⇒_ (proj₁ ⟦ t ⟧↑) pt pt
evalW : {s t : U↑} → s ⇿ t → W s → W t
evalW (↑ x) (w pt auto) = w (ap x pt) refl
evalW (ev q) (w (cc , tt) (cc⇔cc-pf , cc')) = w tt refl -- this is cheating, cc <=> cc' ??
evalW (coev q) (w tt refl) = w (q , tt) (id⇔ , q) -- but this isn't.
evalW id⇿ (w pt auto) = w pt auto
-- This should actually be Hom-set inhabitation, aka categorical equivalence
-- (as we are in a groupoid setting).
ObjEq : (t : U↑) → Category.Obj (proj₁ ⟦ t ⟧↑) → Category.Obj (proj₁ ⟦ t ⟧↑) → Set
ObjEq (↑ x) a b = a P.≡ b
ObjEq (# S x) a b = interp a ⇔ interp b
ObjEq (1/ S x) a b = ⊤
ObjEq (s ⊞ t) (inj₁ x) (inj₁ y) = ObjEq s x y
ObjEq (s ⊞ t) (inj₁ x) (inj₂ y) = ⊥
ObjEq (s ⊞ t) (inj₂ y) (inj₁ x) = ⊥
ObjEq (s ⊞ t) (inj₂ x) (inj₂ y) = ObjEq t x y
ObjEq (s ⊠ t) (a , b) (c , d) = ObjEq s a c × ObjEq t b d
HomEq : (t : U↑) → (a b : Category.Obj (proj₁ ⟦ t ⟧↑)) →
Category._⇒_ (proj₁ ⟦ t ⟧↑) a b → Category._⇒_ (proj₁ ⟦ t ⟧↑) a b → Set
HomEq (↑ x) a b h1 h2 = ⊤ -- this is basically proof-irrelevance h1 h2
HomEq (# S x) a b h1 h2 = ⊤ -- because h1 and h2 are the exact same ⇔
HomEq (1/ S x) tt tt h1 h2 = interp h1 ⇔ interp h2 -- here!
HomEq (s ⊞ t) (inj₁ x) (inj₁ x₁) h1 h2 = HomEq s x x₁ h1 h2
HomEq (s ⊞ t) (inj₁ x) (inj₂ y) (Level.lift ()) h2
HomEq (s ⊞ t) (inj₂ y) (inj₁ x) (Level.lift ()) h2
HomEq (s ⊞ t) (inj₂ y) (inj₂ y₁) h1 h2 = HomEq t y y₁ h1 h2
HomEq (s ⊠ t) (a , b) (c , d) (a⇒c , b⇒d) (a⇒c' , b⇒d') =
HomEq s a c a⇒c a⇒c' × HomEq t b d b⇒d b⇒d'
-- W equivalence; note that transp is restricted to be the Homs of cat
-- we might want to restrict that more.
record _≈W_ {t : U↑} (a : W t) (b : W t) : Set where
constructor weq
cat = proj₁ ⟦ t ⟧↑
gpd = proj₂ ⟦ t ⟧↑
_∘_ = Category._∘_ cat
field
pt-eq : ObjEq t (W.pt a) (W.pt b)
transp : Category._⇒_ cat (W.pt a) (W.pt b)
auto-eq : HomEq t (W.pt a) (W.pt b) (W.auto b ∘ (transp ∘ (W.auto a))) transp
|
{
"alphanum_fraction": 0.5391669583,
"avg_line_length": 36.4413265306,
"ext": "agda",
"hexsha": "384153d0994d6905e18597d967092ab4b65bbab6",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/PointedPi.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/PointedPi.agda",
"max_line_length": 176,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/PointedPi.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 6419,
"size": 14285
}
|
{-# OPTIONS --cubical --safe #-}
module AssocList where
open import Cubical.Core.Everything using (Type)
open import Data.Bool using (Bool; false; true; _∨_; _∧_)
open import Data.List using (List; []; _∷_; foldr)
open import Data.Product using (_×_; _,_; proj₂)
open import Function using (_∘_)
AList : (A B : Type) → Type
AList A B = List (A × List B)
-- Does not deduplicate in list of B.
insert : {A B : Type} → (A → A → Bool) → A × B → AList A B → AList A B
insert eq (a , b) [] = (a , b ∷ []) ∷ []
insert eq (a , b) ((a' , bs) ∷ xs) with eq a a'
... | false = (a' , bs) ∷ insert eq (a , b) xs
... | true = (a' , b ∷ bs) ∷ xs
lookup : {A B : Type} → (A → A → Bool) → A → AList A B → List B
lookup eq _ [] = []
lookup eq a ((a' , bs) ∷ xs) with eq a a'
... | false = lookup eq a xs
... | true = bs
|
{
"alphanum_fraction": 0.5291375291,
"avg_line_length": 30.6428571429,
"ext": "agda",
"hexsha": "8782e961157fed5c6917a579555afe3521a021ff",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "agda/AssocList.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "agda/AssocList.agda",
"max_line_length": 70,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "agda/AssocList.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 304,
"size": 858
}
|
-- Empty, unit and equality.
⊥ = (X : Set) → X
⊤ = (X : Set) → X → X
data _≡_ {l}{A : Set l}(x : A) : A → Set l where
<> : x ≡ x
-- The fixpoint of the identity functor as a data definition.
module Data where
data μId : Set where
In : μId → μId
-- μId can be proved empty. Here are both a direct proof and one that
-- relies on the eliminator for μId.
¬μId : μId → ⊥
¬μId (In x) = ¬μId x
μId-elim : ∀ {l}(P : μId → Set l) → (∀ x → P x → P (In x)) → ∀ x → P x
μId-elim P m (In x) = m x (μId-elim P m x)
¬Id' : μId → ⊥
¬Id' = μId-elim (λ _ → ⊥) (λ _ p → p)
-- To prove ∀ x → ¬ (x ≡ In x) it is enough to call ¬μId (or ¬μId'): the
-- equality proof is not inspected.
¬id≡In-empty : ∀ {x} → x ≡ In x → ⊥
¬id≡In-empty {x} _ = ¬μId x -- or ¬Id' x
-- Alternatively, one could use an absurd pattern which relies on the
-- presence of a cycle.
¬id≡In-pm : ∀ {x} → x ≡ In x → ⊥
¬id≡In-pm ()
-- The case of inductive records is a bit different. Here is the fixpoint
-- of the identity functor as an inductive record definition.
module Record where
record μId : Set where
inductive
constructor In
field Out : μId
open μId
-- It does not seem possible to prove Record.μId empty, as Agda does not
-- consider the following definitions as terminating.
{-# NON_TERMINATING #-}
¬μId : μId → ⊥
¬μId (In x) = ¬μId x
{-# NON_TERMINATING #-}
μId-elim : ∀ {l}(P : μId → Set l) → (∀ x → P x → P (In x)) → ∀ x → P x
μId-elim P m (In x) = m x (μId-elim P m x)
¬Id' : μId → ⊥
¬Id' = μId-elim (λ _ → ⊥) (λ _ p → p)
¬id≡In-empty : ∀ {x} → x ≡ In x → ⊥
¬id≡In-empty {x} _ = ¬μId x -- or ¬Id' x
-- However, we can still use an absurd pattern as in Data.¬id≡In-pm.
¬id≡In-pm : ∀ {x} → x ≡ In x → ⊥
¬id≡In-pm ()
-- This should not be possible.
|
{
"alphanum_fraction": 0.559911651,
"avg_line_length": 24.1466666667,
"ext": "agda",
"hexsha": "41195b61c8fe11ca3c23c4d1fa7381274c80826e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/Fail/Issue1271a.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"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": "hborum/agda",
"max_issues_repo_path": "test/Fail/Issue1271a.agda",
"max_line_length": 73,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Fail/Issue1271a.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 713,
"size": 1811
}
|
------------------------------------------------------------------------
-- Vectors, defined using an inductive family
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Vec.Data
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Prelude
open import Bijection eq using (_↔_)
open Derived-definitions-and-properties eq
open import Function-universe eq hiding (_∘_)
open import List eq using (length)
open import Surjection eq using (_↠_; ↠-≡)
------------------------------------------------------------------------
-- The type
-- Vectors.
infixr 5 _∷_
data Vec {a} (A : Type a) : ℕ → Type a where
[] : Vec A zero
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)
------------------------------------------------------------------------
-- Some simple functions
-- Finds the element at the given position.
index : ∀ {n} {a} {A : Type a} → Vec A n → Fin n → A
index (x ∷ _) fzero = x
index (_ ∷ xs) (fsuc i) = index xs i
-- Updates the element at the given position.
infix 3 _[_≔_]
_[_≔_] : ∀ {n} {a} {A : Type a} → Vec A n → Fin n → A → Vec A n
_[_≔_] [] () _
_[_≔_] (x ∷ xs) fzero y = y ∷ xs
_[_≔_] (x ∷ xs) (fsuc i) y = x ∷ (xs [ i ≔ y ])
-- Applies the function to every element in the vector.
map : ∀ {n a b} {A : Type a} {B : Type b} → (A → B) → Vec A n → Vec B n
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
-- Constructs a vector containing a certain number of copies of the
-- given element.
replicate : ∀ {n a} {A : Type a} → A → Vec A n
replicate {zero} _ = []
replicate {suc _} x = x ∷ replicate x
-- The head of the vector.
head : ∀ {n a} {A : Type a} → Vec A (suc n) → A
head (x ∷ _) = x
-- The tail of the vector.
tail : ∀ {n a} {A : Type a} → Vec A (suc n) → Vec A n
tail (_ ∷ xs) = xs
------------------------------------------------------------------------
-- Conversions to and from lists
-- Vectors can be converted to lists.
to-list : ∀ {n} {a} {A : Type a} → Vec A n → List A
to-list [] = []
to-list (x ∷ xs) = x ∷ to-list xs
-- Lists can be converted to vectors.
from-list : ∀ {a} {A : Type a} (xs : List A) → Vec A (length xs)
from-list [] = []
from-list (x ∷ xs) = x ∷ from-list xs
-- ∃ (Vec A) is isomorphic to List A.
∃Vec↔List : ∀ {a} {A : Type a} → ∃ (Vec A) ↔ List A
∃Vec↔List {A = A} = record
{ surjection = record
{ logical-equivalence = record
{ to = to-list ∘ proj₂
; from = λ xs → length xs , from-list xs
}
; right-inverse-of = to∘from
}
; left-inverse-of = uncurry from∘to
}
where
to∘from : (xs : List A) → to-list (from-list xs) ≡ xs
to∘from [] = refl _
to∘from (x ∷ xs) = cong (x ∷_) (to∘from xs)
tail′ : A → ∃ (Vec A) ↠ ∃ (Vec A)
tail′ y = record
{ logical-equivalence = record
{ to = λ where
(suc n , _ ∷ xs) → n , xs
xs@(zero , _) → xs
; from = Σ-map suc (y ∷_)
}
; right-inverse-of = refl
}
from∘to :
∀ n (xs : Vec A n) →
(length (to-list xs) , from-list (to-list xs)) ≡ (n , xs)
from∘to zero [] = refl _
from∘to (suc n) (x ∷ xs) = $⟨ from∘to n xs ⟩
(length (to-list xs) , from-list (to-list xs)) ≡ (n , xs) ↝⟨ _↠_.from $ ↠-≡ (tail′ x) ⟩□
(length (to-list (x ∷ xs)) , from-list (to-list (x ∷ xs)))
≡
(suc n , x ∷ xs) □
|
{
"alphanum_fraction": 0.4667621777,
"avg_line_length": 27.6984126984,
"ext": "agda",
"hexsha": "5ae1a4dd825143e3e790d93ea9d792aaa6960ae3",
"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/Vec/Data.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/Vec/Data.agda",
"max_line_length": 94,
"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/Vec/Data.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": 1160,
"size": 3490
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Object.Zero
-- Kernels of morphisms.
-- https://ncatlab.org/nlab/show/kernel
module Categories.Object.Kernel {o ℓ e} {𝒞 : Category o ℓ e} (zero : Zero 𝒞) where
open import Level using (_⊔_)
open import Categories.Morphism 𝒞
open import Categories.Morphism.Reasoning 𝒞
hiding (glue)
open Category 𝒞
open Zero zero
open HomReasoning
private
variable
A B X : Obj
f h i j k : A ⇒ B
-- Note: We could define Kernels directly as equalizers or as pullbacks, but it seems somewhat
-- cleaner to just define them "as is" to avoid mucking about with extra morphisms that can
-- get in the way. For example, if we defined them as 'Pullback f !' then our 'p₂' projection
-- would _always_ be trivially equal to '¡ : K ⇒ zero'.
record IsKernel {A B K} (k : K ⇒ A) (f : A ⇒ B) : Set (o ⊔ ℓ ⊔ e) where
field
commute : f ∘ k ≈ zero⇒
universal : ∀ {X} {h : X ⇒ A} → f ∘ h ≈ zero⇒ → X ⇒ K
factors : ∀ {eq : f ∘ h ≈ zero⇒} → h ≈ k ∘ universal eq
unique : ∀ {eq : f ∘ h ≈ zero⇒} → h ≈ k ∘ i → i ≈ universal eq
universal-resp-≈ : ∀ {eq : f ∘ h ≈ zero⇒} {eq′ : f ∘ i ≈ zero⇒} →
h ≈ i → universal eq ≈ universal eq′
universal-resp-≈ h≈i = unique (⟺ h≈i ○ factors)
universal-∘ : f ∘ k ∘ h ≈ zero⇒
universal-∘ {h = h} = begin
f ∘ k ∘ h ≈⟨ pullˡ commute ⟩
zero⇒ ∘ h ≈⟨ pullʳ (⟺ (¡-unique (¡ ∘ h))) ⟩
zero⇒ ∎
record Kernel {A B} (f : A ⇒ B) : Set (o ⊔ ℓ ⊔ e) where
field
{kernel} : Obj
kernel⇒ : kernel ⇒ A
isKernel : IsKernel kernel⇒ f
open IsKernel isKernel public
IsKernel⇒Kernel : IsKernel k f → Kernel f
IsKernel⇒Kernel {k = k} isKernel = record
{ kernel⇒ = k
; isKernel = isKernel
}
|
{
"alphanum_fraction": 0.6101888952,
"avg_line_length": 28.6393442623,
"ext": "agda",
"hexsha": "7e49fddc64601acd397461d399f753c9a3338ce1",
"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": "3ef03f73bce18f1efba2890df9ddf3d76ed2de32",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "FintanH/agda-categories",
"max_forks_repo_path": "src/Categories/Object/Kernel.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3ef03f73bce18f1efba2890df9ddf3d76ed2de32",
"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": "FintanH/agda-categories",
"max_issues_repo_path": "src/Categories/Object/Kernel.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3ef03f73bce18f1efba2890df9ddf3d76ed2de32",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FintanH/agda-categories",
"max_stars_repo_path": "src/Categories/Object/Kernel.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 664,
"size": 1747
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Pointwise table equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Table.Relation.Binary.Equality where
open import Relation.Binary using (Setoid)
open import Data.Table.Base
open import Data.Nat using (ℕ)
open import Function using (_∘_)
open import Relation.Binary.PropositionalEquality
as P using (_≡_; _→-setoid_)
setoid : ∀ {c p} → Setoid c p → ℕ → Setoid _ _
setoid S n = record
{ Carrier = Table Carrier n
; _≈_ = λ t t′ → ∀ i → lookup t i ≈ lookup t′ i
; isEquivalence = record
{ refl = λ i → refl
; sym = λ p → sym ∘ p
; trans = λ p q i → trans (p i) (q i)
}
}
where open Setoid S
≡-setoid : ∀ {a} → Set a → ℕ → Setoid _ _
≡-setoid A = setoid (P.setoid A)
module _ {a} {A : Set a} {n} where
open Setoid (≡-setoid A n) public
using () renaming (_≈_ to _≗_)
|
{
"alphanum_fraction": 0.5331991952,
"avg_line_length": 27.6111111111,
"ext": "agda",
"hexsha": "3f162ffdc2a81b89598f01c88a059eab5a64870f",
"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/Table/Relation/Binary/Equality.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/Table/Relation/Binary/Equality.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/Data/Table/Relation/Binary/Equality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 292,
"size": 994
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Instantiates the ring solver with two copies of the same ring with
-- decidable equality
------------------------------------------------------------------------
open import Algebra.RingSolver.AlmostCommutativeRing
open import Relation.Binary
module Algebra.RingSolver.Simple
{r₁ r₂} (R : AlmostCommutativeRing r₁ r₂)
(_≟_ : Decidable (AlmostCommutativeRing._≈_ R))
where
open AlmostCommutativeRing R
import Algebra.RingSolver as RS
open RS rawRing R (-raw-almostCommutative⟶ R) _≟_ public
|
{
"alphanum_fraction": 0.5748407643,
"avg_line_length": 33.0526315789,
"ext": "agda",
"hexsha": "17c5036906ceec0a2b35f2051f325deb098e3bd5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Algebra/RingSolver/Simple.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Algebra/RingSolver/Simple.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Algebra/RingSolver/Simple.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 138,
"size": 628
}
|
module Extensions.All where
open import Data.List.All
|
{
"alphanum_fraction": 0.8181818182,
"avg_line_length": 13.75,
"ext": "agda",
"hexsha": "0007e736046483125f6fa81ba8edadf01b1687de",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Extensions/All.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Extensions/All.agda",
"max_line_length": 27,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Extensions/All.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 11,
"size": 55
}
|
{-# OPTIONS --cubical #-}
open import Agda.Primitive.Cubical
postulate
A : Set
B : Set
b : B
postulate
PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ
{-# BUILTIN PATHP PathP #-}
infix 4 _≡_
_≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
_≡_ {A = A} = PathP (λ _ → A)
f : (\ {a : A} (x : B) → b) ≡ (\ _ → b)
f i x = b
|
{
"alphanum_fraction": 0.4617647059,
"avg_line_length": 16.1904761905,
"ext": "agda",
"hexsha": "e36f393213c9b6bb8c8f0efb69c59123c31940d5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue2722.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue2722.agda",
"max_line_length": 53,
"max_stars_count": 2,
"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/Issue2722.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": 160,
"size": 340
}
|
{-# OPTIONS --without-K #-}
open import lib.Base
module test.fail.Test2 where
module _ where
private
data #I : Type₀ where
#zero : #I
#one : #I
I : Type₀
I = #I
zero : I
zero = #zero
one : I
one = #one
postulate
seg : zero == one
I-elim : ∀ {i} {P : I → Type i} (zero* : P zero) (one* : P one)
(seg* : zero* == one* [ P ↓ seg ]) → Π I P
I-elim {i} {P} zero* one* seg* = I-elim-aux phantom where
I-elim-aux : Phantom seg* → Π I P
I-elim-aux phantom #zero = zero*
I-elim-aux phantom #one = one*
postulate
P : I → Type₀
z : P zero
o : P one
s s' : z == o [ P ↓ seg ]
absurd : I-elim z o s == I-elim z o s'
absurd = idp
|
{
"alphanum_fraction": 0.5185714286,
"avg_line_length": 16.6666666667,
"ext": "agda",
"hexsha": "0ed9f8f71aa031d23e01cf143fe8f6c055fa21d0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "test/fail/Test2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "test/fail/Test2.agda",
"max_line_length": 65,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "test/fail/Test2.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 270,
"size": 700
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of operations on containers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Container.Properties where
import Function as F
open import Relation.Binary
open import Data.Container.Core
open import Data.Container.Relation.Binary.Equality.Setoid
module _ {s p} {C : Container s p} where
map-identity : ∀ {x e} (X : Setoid x e) xs →
Eq X C (map F.id xs) xs
map-identity X xs = refl X C
map-compose : ∀ {x y z e} {X : Set x} {Y : Set y} (Z : Setoid z e) g (f : X → Y) xs →
Eq Z C (map g (map f xs)) (map (g F.∘′ f) xs)
map-compose Z g f xs = refl Z C
|
{
"alphanum_fraction": 0.501910828,
"avg_line_length": 30.1923076923,
"ext": "agda",
"hexsha": "c20c6b144e0724153009c2cbbfaa6187fac13082",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Properties.agda",
"max_line_length": 87,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Properties.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": 199,
"size": 785
}
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRingSolver.HornerForms where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.Int hiding (_+_ ; _·_ ; -_)
open import Cubical.Data.FinData
open import Cubical.Data.Vec
open import Cubical.Data.Bool
open import Cubical.Relation.Nullary.Base using (yes; no)
open import Cubical.Algebra.CommRingSolver.Utility
open import Cubical.Algebra.CommRingSolver.RawRing
open import Cubical.Algebra.CommRingSolver.IntAsRawRing
open import Cubical.Algebra.CommRingSolver.RawAlgebra renaming (⟨_⟩ to ⟨_⟩ₐ)
open import Cubical.Algebra.CommRingSolver.AlgebraExpression public
private
variable
ℓ ℓ' : Level
{-
This defines the type of multivariate Polynomials over the RawRing R.
The construction is based on the algebraic fact
R[X₀][X₁]⋯[Xₙ] ≅ R[X₀,⋯,Xₙ]
BUT: Contrary to algebraic convetions, we will give 'Xₙ' the lowest index
in the definition of 'Variable' below. So if 'Variable n R k' is identified
with 'Xₖ', then the RawRing we construct should rather be denoted with
R[Xₙ][Xₙ₋₁]⋯[X₀]
or, to be precise about the evaluation order:
(⋯((R[Xₙ])[Xₙ₋₁])⋯)[X₀]
-}
data IteratedHornerForms (A : RawAlgebra ℤAsRawRing ℓ) : ℕ → Type ℓ where
const : ℤ → IteratedHornerForms A ℕ.zero
0H : {n : ℕ} → IteratedHornerForms A (ℕ.suc n)
_·X+_ : {n : ℕ} → IteratedHornerForms A (ℕ.suc n) → IteratedHornerForms A n
→ IteratedHornerForms A (ℕ.suc n)
{-
The following function returns true, if there is some
obvious reason that the Horner-Expression should be zero.
Since Equality is undecidable in a general RawAlgebra, we cannot
have a function that fully lives up to the name 'isZero'.
-}
module _ (A : RawAlgebra ℤAsRawRing ℓ) where
open RawRing ℤAsRawRing
isZero : {n : ℕ} → IteratedHornerForms A n
→ Bool
isZero (const (pos ℕ.zero)) = true
isZero (const (pos (ℕ.suc _))) = false
isZero (const (negsuc _)) = false
isZero 0H = true
isZero (P ·X+ Q) = (isZero P) and (isZero Q)
leftIsZero : {n : ℕ}
(P : IteratedHornerForms A (ℕ.suc n))
(Q : IteratedHornerForms A n)
→ isZero (P ·X+ Q) ≡ true
→ isZero P ≡ true
leftIsZero P Q isZeroSum with isZero P
... | true = refl
... | false = byBoolAbsurdity (fst (extractFromAnd _ _ isZeroSum))
rightIsZero : {n : ℕ}
(P : IteratedHornerForms A (ℕ.suc n))
(Q : IteratedHornerForms A n)
→ isZero (P ·X+ Q) ≡ true
→ isZero Q ≡ true
rightIsZero P Q isZeroSum with isZero Q
... | true = refl
... | false = byBoolAbsurdity (snd (extractFromAnd _ _ isZeroSum))
module IteratedHornerOperations (A : RawAlgebra ℤAsRawRing ℓ) where
open RawRing ℤAsRawRing
private
1H' : (n : ℕ) → IteratedHornerForms A n
1H' ℕ.zero = const 1r
1H' (ℕ.suc n) = 0H ·X+ 1H' n
0H' : (n : ℕ) → IteratedHornerForms A n
0H' ℕ.zero = const 0r
0H' (ℕ.suc n) = 0H
1ₕ : {n : ℕ} → IteratedHornerForms A n
1ₕ {n = n} = 1H' n
0ₕ : {n : ℕ} → IteratedHornerForms A n
0ₕ {n = n} = 0H' n
X : (n : ℕ) (k : Fin n) → IteratedHornerForms A n
X (ℕ.suc m) zero = 1ₕ ·X+ 0ₕ
X (ℕ.suc m) (suc k) = 0ₕ ·X+ X m k
_+ₕ_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
→ IteratedHornerForms A n
(const r) +ₕ (const s) = const (r + s)
0H +ₕ Q = Q
(P ·X+ r) +ₕ 0H = P ·X+ r
(P ·X+ r) +ₕ (Q ·X+ s) =
let left = (P +ₕ Q)
right = (r +ₕ s)
in if ((isZero A left) and (isZero A right))
then 0ₕ
else left ·X+ right
-ₕ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
-ₕ (const x) = const (- x)
-ₕ 0H = 0H
-ₕ (P ·X+ Q) = (-ₕ P) ·X+ (-ₕ Q)
_⋆_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A (ℕ.suc n)
→ IteratedHornerForms A (ℕ.suc n)
_·ₕ_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
→ IteratedHornerForms A n
r ⋆ 0H = 0H
r ⋆ (P ·X+ Q) =
if (isZero A r)
then 0ₕ
else (r ⋆ P) ·X+ (r ·ₕ Q)
const x ·ₕ const y = const (x · y)
0H ·ₕ Q = 0H
(P ·X+ Q) ·ₕ S =
let
z = (P ·ₕ S)
in if (isZero A z)
then (Q ⋆ S)
else (z ·X+ 0ₕ) +ₕ (Q ⋆ S)
isZeroPresLeft⋆ :
{n : ℕ}
(r : IteratedHornerForms A n)
(P : IteratedHornerForms A (ℕ.suc n))
→ isZero A r ≡ true
→ isZero A (r ⋆ P) ≡ true
isZeroPresLeft⋆ r 0H isZero-r = refl
isZeroPresLeft⋆ r (P ·X+ Q) isZero-r with isZero A r
... | true = refl
... | false = byBoolAbsurdity isZero-r
isZeroPresLeft·ₕ :
{n : ℕ} (P Q : IteratedHornerForms A n)
→ isZero A P ≡ true
→ isZero A (P ·ₕ Q) ≡ true
isZeroPresLeft·ₕ (const (pos ℕ.zero)) (const _) isZeroP = refl
isZeroPresLeft·ₕ (const (pos (ℕ.suc n))) (const _) isZeroP = byBoolAbsurdity isZeroP
isZeroPresLeft·ₕ (const (negsuc n)) (const _) isZeroP = byBoolAbsurdity isZeroP
isZeroPresLeft·ₕ 0H Q isZeroP = refl
isZeroPresLeft·ₕ (P ·X+ Q) S isZeroSum with isZero A (P ·ₕ S) ≟ true
... | no p = byBoolAbsurdity (sym notZeroProd ∙ isZeroProd)
where notZeroProd = ¬true→false _ p
isZeroP = extractFromAndLeft isZeroSum
isZeroProd = isZeroPresLeft·ₕ P S isZeroP
... | yes p with isZero A (P ·ₕ S)
... | true = isZeroPresLeft⋆ Q S isZeroQ
where isZeroQ = extractFromAndRight isZeroSum
... | false = byBoolAbsurdity p
asRawRing : (n : ℕ) → RawRing ℓ
RawRing.Carrier (asRawRing n) = IteratedHornerForms A n
RawRing.0r (asRawRing n) = 0ₕ
RawRing.1r (asRawRing n) = 1ₕ
RawRing._+_ (asRawRing n) = _+ₕ_
RawRing._·_ (asRawRing n) = _·ₕ_
RawRing.- (asRawRing n) = -ₕ
Variable : (n : ℕ) (R : RawAlgebra ℤAsRawRing ℓ') (k : Fin n) → IteratedHornerForms R n
Variable n R k = IteratedHornerOperations.X R n k
Constant : (n : ℕ) (R : RawAlgebra ℤAsRawRing ℓ') (r : ℤ) → IteratedHornerForms R n
Constant ℕ.zero R r = const r
Constant (ℕ.suc n) R r = IteratedHornerOperations.0ₕ R ·X+ Constant n R r
|
{
"alphanum_fraction": 0.6178835111,
"avg_line_length": 32.9459459459,
"ext": "agda",
"hexsha": "f7ff797f7cc3fafd1ba57a24ac8ee86c4234185c",
"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/CommRingSolver/HornerForms.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/CommRingSolver/HornerForms.agda",
"max_line_length": 87,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRingSolver/HornerForms.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 2359,
"size": 6095
}
|
open import Data.Fin using (Fin)
open import Data.Nat using (ℕ; _+_)
open import Data.Vec using (Vec; []; _∷_; _++_)
open import Dipsy.Polarity
module Dipsy.Base
(FOp : {n : ℕ} (as : Vec Polarity n) (b : Polarity) → Set)
(SOp : {n : ℕ} (as : Vec Polarity n) (b : Polarity) → Set)
where
open import Dipsy.Form FOp public
open import Dipsy.Struct FOp SOp public
Res : Set
Res = {n₁ n₂ : ℕ}
→ {as₁ : Vec Polarity n₁}
→ {as₂ : Vec Polarity n₂}
→ {b : Polarity}
→ SOp (as₁ ++ flip b ∷ as₂) b
→ Context (flip b) b
-- we need contexts with n holes if we want to encode structuralisation properly..
-- those are functions...
|
{
"alphanum_fraction": 0.6327160494,
"avg_line_length": 25.92,
"ext": "agda",
"hexsha": "d21f1c52f76e84c5d1239c470394efbc067357c0",
"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": "06eec3f3325c71c81809ff19dfaf4fd43ba958ed",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wenkokke/dipsy",
"max_forks_repo_path": "src/Dipsy/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "06eec3f3325c71c81809ff19dfaf4fd43ba958ed",
"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": "wenkokke/dipsy",
"max_issues_repo_path": "src/Dipsy/Base.agda",
"max_line_length": 82,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "06eec3f3325c71c81809ff19dfaf4fd43ba958ed",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/Dipsy",
"max_stars_repo_path": "src/Dipsy/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-10T13:43:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-10T13:43:29.000Z",
"num_tokens": 225,
"size": 648
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Right-biased universe-sensitive functor and monad instances for the
-- Product type.
--
-- To minimize the universe level of the RawFunctor, we require that
-- elements of B are "lifted" to a copy of B at a higher universe level
-- (a ⊔ b). See the Data.Product.Categorical.Examples for how this is
-- done.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
open import Level
module Data.Product.Categorical.Right
(a : Level) {b e} (B : RawMonoid b e) where
open import Data.Product
import Data.Product.Categorical.Right.Base as Base
open import Category.Applicative using (RawApplicative)
open import Category.Monad using (RawMonad; RawMonadT)
open import Function using (id; flip; _∘_; _∘′_)
import Function.Identity.Categorical as Id
open RawMonoid B
------------------------------------------------------------------------
-- Re-export the base contents publically
open Base Carrier a public
------------------------------------------------------------------------
-- Basic records
applicative : RawApplicative Productᵣ
applicative = record
{ pure = _, ε
; _⊛_ = zip id _∙_
}
monadT : RawMonadT (_∘′ Productᵣ)
monadT M = record
{ return = pure ∘′ (_, ε)
; _>>=_ = λ ma f → ma >>= uncurry λ x b → map₂ (b ∙_) <$> f x
} where open RawMonad M
monad : RawMonad Productᵣ
monad = monadT Id.monad
------------------------------------------------------------------------
-- Get access to other monadic functions
module _ {F} (App : RawApplicative {a ⊔ b} F) where
open RawApplicative App
sequenceA : ∀ {A} → Productᵣ (F A) → F (Productᵣ A)
sequenceA (fa , y) = (_, y) <$> fa
mapA : ∀ {A B} → (A → F B) → Productᵣ A → F (Productᵣ B)
mapA f = sequenceA ∘ map₁ f
forA : ∀ {A B} → Productᵣ A → (A → F B) → F (Productᵣ B)
forA = flip mapA
module _ {M} (Mon : RawMonad {a ⊔ b} M) where
private App = RawMonad.rawIApplicative Mon
sequenceM : ∀ {A} → Productᵣ (M A) → M (Productᵣ A)
sequenceM = sequenceA App
mapM : ∀ {A B} → (A → M B) → Productᵣ A → M (Productᵣ B)
mapM = mapA App
forM : ∀ {A B} → Productᵣ A → (A → M B) → M (Productᵣ B)
forM = forA App
|
{
"alphanum_fraction": 0.5559912854,
"avg_line_length": 28.3333333333,
"ext": "agda",
"hexsha": "0e7129441a89d792baf8d2cf3bf1d1449501c188",
"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/Categorical/Right.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/Categorical/Right.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/Data/Product/Categorical/Right.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 669,
"size": 2295
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
module Rings.IntegralDomains.Examples where
|
{
"alphanum_fraction": 0.7142857143,
"avg_line_length": 16.3333333333,
"ext": "agda",
"hexsha": "1a962aa0dd5b58b17a9b8344d66292baeb8ca3e7",
"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/IntegralDomains/Examples.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/IntegralDomains/Examples.agda",
"max_line_length": 50,
"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/IntegralDomains/Examples.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": 22,
"size": 98
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Algebra.FunctionProperties.Consequences.Propositional
{a} {A : Set a} where
{-# WARNING_ON_IMPORT
"Algebra.FunctionProperties.Consequences.Propositional was deprecated in v1.3.
Use Algebra.Consequences.Propositional instead."
#-}
open import Algebra.Consequences.Propositional {A = A} public
|
{
"alphanum_fraction": 0.5602189781,
"avg_line_length": 30.4444444444,
"ext": "agda",
"hexsha": "8d68750adf63348424f3a623ce2804a2d4d883d8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Algebra/FunctionProperties/Consequences/Propositional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Algebra/FunctionProperties/Consequences/Propositional.agda",
"max_line_length": 78,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/FunctionProperties/Consequences/Propositional.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 99,
"size": 548
}
|
----------------------------------------------------------------------
-- Copyright: 2013, Jan Stolarek, Lodz University of Technology --
-- --
-- License: See LICENSE file in root of the repo --
-- Repo address: https://github.com/jstolarek/dep-typed-wbl-heaps --
-- --
-- Basic implementation of weight-biased leftist heap. No proofs --
-- and no dependent types. Uses a two-pass merging algorithm. --
----------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module TwoPassMerge.NoProofs where
open import Basics.Nat
open import Basics hiding (_≥_)
open import Sized
-- Weight biased leftist heap is implemented using a binary tree. I
-- will interchangeably refer to children of a node as "subtrees" or
-- "subheaps".
--
-- A Heap usually stores elements of some type (Set) A with an
-- assigned priority. However to keep code easier to read each node
-- will only store Priority (a natural number). This will not affect
-- in any way proofs that we are conducting.
-- We begin with a simple implementation that uses no dependent
-- types. Note the we explicitly store rank in node constructor
-- (recall that rank is defined as number of elements in a
-- tree). Theoretically this information is redundant - we could
-- compute the size of a tree whenever we need it. The reason I choose
-- to store it in a node is that later, when we come to proving the
-- rank invariant, it will be instructive to show how information
-- stored inside a constructor is turned into an inductive family
-- index.
-- One more thing to note is that we will define most of our Heaps to
-- be sized types, ie. to use an implict index that defines how a
-- constructor affects the inductive size of the data structure. This
-- information is used to guide the termination checker in the
-- definitions of merge.
data Heap : {i : Size} → Set where
empty : {i : Size} → Heap {↑ i}
node : {i : Size} → Priority → Rank → Heap {i} → Heap {i} → Heap {↑ i}
-- Returns rank of node.
rank : Heap → Nat
rank empty = zero
rank (node _ r _ _) = r
-- Creates heap containing a single element with a given Priority
singleton : Priority → Heap
singleton p = node p one empty empty
-- Note [Two-pass merging algorithm]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- We use a two-pass implementation of merging algorithm. One pass,
-- implemented by merge, performs merging in a top-down manner. Second
-- one, implemented by makeT, ensures that rank invariant of weight
-- biased leftist tree is not violated after merging.
--
-- Notation:
--
-- h1, h2 - heaps being merged
-- p1, p2 - priority of root element in h1 and h2
-- l1 - left subtree in the first heap
-- r1 - right subtree in the first heap
-- l2 - left subtree in the second heap
-- r2 - right subtree in the second heap
--
-- Merge function analyzes four cases. Two of them are base cases:
--
-- a) h1 is empty - return h2
--
-- b) h2 is empty - return h1
--
-- The other two form the inductive definition of merge:
--
-- c) priority p1 is higher than p2 - p1 becomes new root, l1
-- becomes its one child and result of merging r1 with h2
-- becomes the other child:
--
-- p1
-- / \
-- / \
-- l1 r1+h2 -- here "+" denotes merging
--
-- d) priority p2 is higher than p2 - p2 becomes new root, l2
-- becomes its one child and result of merging r2 with h1
-- becomes the other child.
--
-- p2
-- / \
-- / \
-- l2 r2+h1
--
-- Note that there is no guarantee that rank of r1+h2 (or r2+h1) will
-- be smaller than rank of l1 (or l2). To ensure that merged heap
-- maintains the rank invariant we pass both childred - ie. either l1
-- and r1+h2 or l2 and r2+h1 - to makeT, which creates a new node by
-- inspecting sizes of children and swapping them if necessary.
-- makeT takes an element (priority) and two heaps (trees). It
-- constructs a new heap with element at the root and two heaps as
-- children. makeT ensures that WBL heap rank invariant is maintained
-- in the newly created tree by reversing left and right subtrees when
-- necessary (note the inversed r and l in the last case of makeT).
makeT : Priority → Heap → Heap → Heap
makeT p l r with rank l ≥ rank r
makeT p l r | true = node p (suc (rank l + rank r)) l r
makeT p l r | false = node p (suc (rank l + rank r)) r l
-- merge combines two heaps into one. There are two base cases and two
-- recursive cases - see [Two-pass Merging algorithm]. Recursive cases
-- call makeT to ensure that rank invariant is maintained after
-- merging.
merge : {i j : Size} → Heap {i} → Heap {j} → Heap
merge empty h2 = h2
merge h1 empty = h1
merge (node p1 h1-r l1 r1) (node p2 h2-r l2 r2)
with p1 < p2
merge (node p1 h1-r l1 r1) (node p2 h2-r l2 r2)
| true = makeT p1 l1 (merge r1 (node p2 h2-r l2 r2))
merge (node p1 h1-r l1 r1) (node p2 h2-r l2 r2)
| false = makeT p2 l2 (merge (node p1 h1-r l1 r1) r2)
-- Inserting into a heap is performed by merging that heap with newly
-- created singleton heap.
insert : Priority → Heap → Heap
insert p h = merge (singleton p) h
-- findMin returns element with highest priority, ie. root
-- element. Here we encounter first serious problem: we can't return
-- anything for empty node. If this was Haskell we could throw an
-- error, but Agda is a total language. This means that every program
-- written in Agda eventually terminates and produces a
-- result. Throwing errors is not allowed.
findMin : Heap → Priority
findMin empty = {!!} -- does it make sense to assume default
-- priority for empty heap?
findMin (node p _ _ _) = p
data Maybe (A : Set) : Set where
nothing : Maybe A
just : A → Maybe A
findMinM : Heap → Maybe Priority
findMinM empty = nothing
findMinM (node p _ _ _) = just p
-- deleteMin removes the element with the highest priority by merging
-- subtrees of a root element. Again the case of empty heap is
-- problematic. We could give it semantics by returning empty, but
-- this just doesn't feel right. Why should we be able to remove
-- elements from the empty heap?
deleteMin : Heap → Heap
deleteMin empty = {!!} -- should we insert empty?
deleteMin (node _ _ l r) = merge l r
-- As a quick sanity check let's construct some examples. Here's a
-- heap constructed by inserting following priorities into an empty
-- heap: 3, 0, 1, 2.
heap : Heap
heap = insert (suc (suc zero))
(insert (suc zero)
(insert zero
(insert (suc (suc (suc zero))) empty)))
-- Example usage of findMin
findMinInHeap : Priority
findMinInHeap = findMin heap
-- Example usage of deleteMin
deleteMinFromHeap : Heap
deleteMinFromHeap = deleteMin heap
|
{
"alphanum_fraction": 0.6491102181,
"avg_line_length": 39.1460674157,
"ext": "agda",
"hexsha": "cebb5c22f791935699f1e664bd7926a6ade0dbe4",
"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": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_forks_repo_path": "src/TwoPassMerge/NoProofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"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": "jstolarek/dep-typed-wbl-heaps",
"max_issues_repo_path": "src/TwoPassMerge/NoProofs.agda",
"max_line_length": 73,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_stars_repo_path": "src/TwoPassMerge/NoProofs.agda",
"max_stars_repo_stars_event_max_datetime": "2018-05-02T21:48:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-02T21:48:43.000Z",
"num_tokens": 1799,
"size": 6968
}
|
module Syntax where
import Level
open import Data.Unit as Unit renaming (tt to ∗)
open import Data.List as List
open import Data.Product
open import Categories.Category using (Category)
open import Function
open import Relation.Binary.PropositionalEquality as PE hiding ([_]; subst)
open import Relation.Binary using (module IsEquivalence; Setoid; module Setoid)
open ≡-Reasoning
open import Common.Context as Context
Univ = ⊤
data FP : Set where
μ : FP
ν : FP
mutual
TypeCtx : Set
TypeCtx = Ctx (TermCtx × Univ)
data Type : TypeCtx → TermCtx → TermCtx → Univ → Set
data TermCtx : Set where
Ø : TermCtx
_∷'_ : {i : Univ} → (Γ : TermCtx) → Type [] Γ Ø i → TermCtx
data Term (Γ Γ' : TermCtx) {i : Univ} :
Type [] Γ Γ' i → Type [] Γ Γ' i → Set
TypeVar : TypeCtx → TermCtx → Univ → Set
TypeVar Δ Γ i = Var Δ (Γ , i)
data CtxMor (Γ : TermCtx) : TermCtx → Set where
⟨⟩ : CtxMor Γ Ø
_⋉_ : {i : Univ} {Γ' : TermCtx} {A : Type [] Γ' Ø i}
(f : CtxMor Γ Γ') → Term Γ (subst A f) → CtxMor Γ (Γ ∷' A)
reidx : {Δ : TypeCtx} {Γ Γ' : TermCtx} {i : Univ} →
CtxMor Γ' Γ → Type Δ Γ Ø i → Type Δ Γ' Ø i
reidx = ?
data Term (Γ Γ' : TermCtx) {i : Univ} :
Type [] Γ Γ' i → Type [] Γ Γ' i → Set where
in₁ : {i : Univ} {X : TypeVar [(Γ , i)] Γ i}
{Γ₁ : TermCtx} (A₁ : Type [(Γ , i)] Γ₁ Ø i) (f₁ : Γ₁ ▹ Γ) →
Term Γ Γ' i (tySubst (fp A₁ f₁ μ) A₁ X) (reidx f₁ (fp A₁ f₁ μ))
{-
_++'_ : TermCtx → TermCtx → TermCtx
Γ₁ ++' Ø = Γ₁
Γ₁ ++' (Γ₂ ∷' A) =
-}
data Type : TypeCtx → TermCtx → TermCtx → Univ → Set where
tyVar : (Δ : TypeCtx) → (Γ : TermCtx) → (i : Univ) → Type Δ Ø Γ i
-- app :
fp : {Δ : TypeCtx} {Γ : TermCtx} {i : Univ} {X : TypeVar Δ Γ i}
{Γ₁ : TermCtx} (A₁ : Type Δ Γ₁ Ø i)
(f₁ : Γ₁ ▹ Γ)
(ρ : FP) →
Type Δ Ø Γ i
{- fp : {Δ : TypeCtx} {X : TypeVar} {Γ Γ' Γ₁ : TermCtx} {i : Univ}
(A₁ : Type Δ (Γ' ++' Γ₁)
-}
|
{
"alphanum_fraction": 0.5397698849,
"avg_line_length": 28.9710144928,
"ext": "agda",
"hexsha": "b515caf7fc4326886c65fea2d64f77ad9c39d6f2",
"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": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "TypeTheory/FibDataTypes/Syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"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": "hbasold/Sandbox",
"max_issues_repo_path": "TypeTheory/FibDataTypes/Syntax.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "TypeTheory/FibDataTypes/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 761,
"size": 1999
}
|
------------------------------------------------------------------------
-- Functional semantics for an untyped λ-calculus with constants
------------------------------------------------------------------------
module Lambda.Closure.Functional where
open import Category.Monad
open import Category.Monad.Partiality as Partiality
using (_⊥; never; OtherKind; other; steps)
open import Codata.Musical.Notation
open import Data.Empty using (⊥-elim)
open import Data.List hiding (lookup)
open import Data.Maybe hiding (_>>=_)
import Data.Maybe.Categorical as Maybe
open import Data.Nat
open import Data.Product
open import Data.Sum
open import Data.Vec using (Vec; []; _∷_; lookup)
open import Function
import Level
open import Relation.Binary using (module Preorder)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary
open import Relation.Nullary.Negation
open Partiality._⊥
private
open module E {A : Set} = Partiality.Equality (_≡_ {A = A})
open module R {A : Set} =
Partiality.Reasoning (P.isEquivalence {A = A})
open import Lambda.Syntax
open Closure Tm
open import Lambda.VirtualMachine
open Functional
private
module VM = Closure Code
------------------------------------------------------------------------
-- A monad with partiality and failure
PF : RawMonad {f = Level.zero} (_⊥ ∘ Maybe)
PF = Maybe.monadT Partiality.monad
module PF where
open RawMonad PF public
fail : {A : Set} → Maybe A ⊥
fail = now nothing
_>>=-cong_ :
∀ {k} {A B : Set} {x₁ x₂ : Maybe A ⊥} {f₁ f₂ : A → Maybe B ⊥} →
Rel k x₁ x₂ → (∀ x → Rel k (f₁ x) (f₂ x)) →
Rel k (x₁ >>= f₁) (x₂ >>= f₂)
_>>=-cong_ {k} {f₁ = f₁} {f₂} x₁≈x₂ f₁≈f₂ =
Partiality._>>=-cong_ x₁≈x₂ helper
where
helper : ∀ {x y} → x ≡ y →
Rel k (maybe f₁ fail x) (maybe f₂ fail y)
helper {x = nothing} P.refl = fail ∎
helper {x = just x} P.refl = f₁≈f₂ x
associative :
{A B C : Set}
(x : Maybe A ⊥) (f : A → Maybe B ⊥) (g : B → Maybe C ⊥) →
(x >>= f >>= g) ≅ (x >>= λ y → f y >>= g)
associative x f g =
(x >>= f >>= g) ≅⟨ Partiality.associative P.refl x _ _ ⟩
(x >>=′ λ y → maybe f fail y >>= g) ≅⟨ Partiality._>>=-cong_ (x ∎) helper ⟩
(x >>= λ y → f y >>= g) ∎
where
open RawMonad Partiality.monad renaming (_>>=_ to _>>=′_)
helper : ∀ {y₁ y₂} → y₁ ≡ y₂ →
(maybe f fail y₁ >>= g) ≅ maybe (λ z → f z >>= g) fail y₂
helper {y₁ = nothing} P.refl = fail ∎
helper {y₁ = just y} P.refl = (f y >>= g) ∎
>>=-inversion-⇓ :
∀ {k} {A B : Set} x {f : A → Maybe B ⊥} {y} →
(x>>=f⇓ : (x >>= f) ⇓[ k ] just y) →
∃ λ z → ∃₂ λ (x⇓ : x ⇓[ k ] just z)
(fz⇓ : f z ⇓[ k ] just y) →
steps x⇓ + steps fz⇓ ≡ steps x>>=f⇓
>>=-inversion-⇓ x {f} x>>=f⇓
with Partiality.>>=-inversion-⇓ {_∼A_ = _≡_} P.refl x x>>=f⇓
... | (nothing , x↯ , now () , _)
... | (just z , x⇓ , fz⇓ , eq) = (z , x⇓ , fz⇓ , eq)
>>=-inversion-⇑ :
∀ {k} {A B : Set} x {f : A → Maybe B ⊥} →
(x >>= f) ⇑[ other k ] →
¬ ¬ (x ⇑[ other k ] ⊎
∃ λ y → x ⇓[ other k ] just y × f y ⇑[ other k ])
>>=-inversion-⇑ {k} x {f} x>>=f⇑ =
helper ⟨$⟩ Partiality.>>=-inversion-⇑ P.isEquivalence x x>>=f⇑
where
open RawMonad ¬¬-Monad renaming (_<$>_ to _⟨$⟩_)
helper : (_ ⊎ ∃ λ (y : Maybe _) → _) → _
helper (inj₁ x⇑ ) = inj₁ x⇑
helper (inj₂ (just y , x⇓,fy⇑) ) = inj₂ (y , x⇓,fy⇑)
helper (inj₂ (nothing , x↯,now∼never)) =
⊥-elim (Partiality.now≉never (proj₂ x↯,now∼never))
------------------------------------------------------------------------
-- A workaround for the limitations of guardedness
module Workaround where
data Maybe_⊥P : Set → Set₁ where
fail : ∀ {A} → Maybe A ⊥P
return : ∀ {A} (x : A) → Maybe A ⊥P
later : ∀ {A} (x : ∞ (Maybe A ⊥P)) → Maybe A ⊥P
_>>=_ : ∀ {A B} (x : Maybe A ⊥P) (f : A → Maybe B ⊥P) → Maybe B ⊥P
private
data Maybe_⊥W : Set → Set₁ where
fail : ∀ {A} → Maybe A ⊥W
return : ∀ {A} (x : A) → Maybe A ⊥W
later : ∀ {A} (x : Maybe A ⊥P) → Maybe A ⊥W
mutual
_>>=W_ : ∀ {A B} → Maybe A ⊥W → (A → Maybe B ⊥P) → Maybe B ⊥W
fail >>=W f = fail
return x >>=W f = whnf (f x)
later x >>=W f = later (x >>= f)
whnf : ∀ {A} → Maybe A ⊥P → Maybe A ⊥W
whnf fail = fail
whnf (return x) = return x
whnf (later x) = later (♭ x)
whnf (x >>= f) = whnf x >>=W f
mutual
private
⟪_⟫W : ∀ {A} → Maybe A ⊥W → Maybe A ⊥
⟪ fail ⟫W = PF.fail
⟪ return x ⟫W = PF.return x
⟪ later x ⟫W = later (♯ ⟪ x ⟫P)
⟪_⟫P : ∀ {A} → Maybe A ⊥P → Maybe A ⊥
⟪ p ⟫P = ⟪ whnf p ⟫W
-- The definitions above make sense. ⟪_⟫P is homomorphic with respect
-- to fail, return, later and _>>=_.
fail-hom : ∀ {A} → ⟪ fail {A = A} ⟫P ≅ PF.fail
fail-hom = PF.fail ∎
return-hom : ∀ {A} (x : A) → ⟪ return x ⟫P ≅ PF.return x
return-hom x = PF.return x ∎
later-hom : ∀ {A} (x : ∞ Maybe A ⊥P) →
⟪ later x ⟫P ≅ later (♯ ⟪ ♭ x ⟫P)
later-hom x = later (♯ (⟪ ♭ x ⟫P ∎))
mutual
private
>>=-homW : ∀ {A B} (x : Maybe A ⊥W) (f : A → Maybe B ⊥P) →
⟪ x >>=W f ⟫W ≅ PF._>>=_ ⟪ x ⟫W (λ y → ⟪ f y ⟫P)
>>=-homW fail f = PF.fail ∎
>>=-homW (return x) f = ⟪ f x ⟫P ∎
>>=-homW (later x) f = later (♯ >>=-hom x f)
>>=-hom : ∀ {A B} (x : Maybe A ⊥P) (f : A → Maybe B ⊥P) →
⟪ x >>= f ⟫P ≅ PF._>>=_ ⟪ x ⟫P (λ y → ⟪ f y ⟫P)
>>=-hom x f = >>=-homW (whnf x) f
open Workaround hiding (_>>=_)
------------------------------------------------------------------------
-- Semantics
infix 5 _∙_
-- Note that this definition gives us determinism "for free".
mutual
⟦_⟧′ : ∀ {n} → Tm n → Env n → Maybe Value ⊥P
⟦ con i ⟧′ ρ = return (con i)
⟦ var x ⟧′ ρ = return (lookup ρ x)
⟦ ƛ t ⟧′ ρ = return (ƛ t ρ)
⟦ t₁ · t₂ ⟧′ ρ = ⟦ t₁ ⟧′ ρ >>= λ v₁ →
⟦ t₂ ⟧′ ρ >>= λ v₂ →
v₁ ∙ v₂
where open Workaround
_∙_ : Value → Value → Maybe Value ⊥P
con i ∙ v₂ = fail
ƛ t₁ ρ ∙ v₂ = later (♯ (⟦ t₁ ⟧′ (v₂ ∷ ρ)))
⟦_⟧ : ∀ {n} → Tm n → Env n → Maybe Value ⊥
⟦ t ⟧ ρ = ⟪ ⟦ t ⟧′ ρ ⟫P
------------------------------------------------------------------------
-- Example
Ω-loops : ⟦ Ω ⟧ [] ≈ never
Ω-loops = later (♯ Ω-loops)
------------------------------------------------------------------------
-- Some lemmas
open PF hiding (_>>=_)
-- An abbreviation.
infix 5 _⟦·⟧_
_⟦·⟧_ : Maybe Value ⊥ → Maybe Value ⊥ → Maybe Value ⊥
v₁ ⟦·⟧ v₂ = v₁ >>= λ v₁ → v₂ >>= λ v₂ → ⟪ v₁ ∙ v₂ ⟫P
where open PF
-- _⟦·⟧_ preserves equality.
_⟦·⟧-cong_ : ∀ {k v₁₁ v₁₂ v₂₁ v₂₂} →
Rel k v₁₁ v₂₁ → Rel k v₁₂ v₂₂ →
Rel k (v₁₁ ⟦·⟧ v₁₂) (v₂₁ ⟦·⟧ v₂₂)
v₁₁≈v₂₁ ⟦·⟧-cong v₁₂≈v₂₂ =
v₁₁≈v₂₁ >>=-cong λ v₁ →
v₁₂≈v₂₂ >>=-cong λ v₂ →
⟪ v₁ ∙ v₂ ⟫P ∎
-- The semantics of application is compositional (with respect to the
-- syntactic equality which is used).
·-comp : ∀ {n} (t₁ t₂ : Tm n) {ρ} →
⟦ t₁ · t₂ ⟧ ρ ≅ ⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ
·-comp t₁ t₂ {ρ} =
⟦ t₁ · t₂ ⟧ ρ ≅⟨ >>=-hom (⟦ t₁ ⟧′ ρ) _ ⟩
PF._>>=_ (⟦ t₁ ⟧ ρ) (λ v₁ →
⟪ Workaround._>>=_ (⟦ t₂ ⟧′ ρ) (λ v₂ →
v₁ ∙ v₂) ⟫P) ≅⟨ ((⟦ t₁ ⟧ ρ ∎) >>=-cong λ _ →
>>=-hom (⟦ t₂ ⟧′ ρ) _) ⟩
⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ∎
open PF
------------------------------------------------------------------------
-- Compiler correctness
module Correctness {k : OtherKind} where
infix 4 _≈P_ _≈W_
infixr 2 _≡⟨_⟩W_ _≈⟨_⟩P_ _≈⟨_⟩W_
mutual
data _≈P_ : Maybe VM.Value ⊥ → Maybe VM.Value ⊥ → Set where
_≈⟨_⟩P_ : ∀ x {y z} (x≈y : x ≈P y) (y≅z : y ≅ z) → x ≈P z
correct :
∀ {n} t {ρ : Env n} {c s} {k : Value → Maybe VM.Value ⊥} →
(hyp : ∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩
≈W k v) →
exec ⟨ comp t c , s , comp-env ρ ⟩ ≈P (⟦ t ⟧ ρ >>= k)
data _≈W_ : Maybe VM.Value ⊥ → Maybe VM.Value ⊥ → Set where
⌈_⌉ : ∀ {x y} (x≈y : Rel (other k) x y) → x ≈W y
later : ∀ {x y} (x≈y : ♭ x ≈P ♭ y) → later x ≈W later y
laterˡ : ∀ {x y} (x≈y : ♭ x ≈W y) → later x ≈W y
_≡⟨_⟩W_ : ∀ x {y z} → x ≡ y → y ≈W z → x ≈W z
_ ≡⟨ P.refl ⟩W y≈z = y≈z
_≈⟨_⟩W_ : ∀ x {y z} → x ≈W y → y ≅ z → x ≈W z
._ ≈⟨ later x≈y ⟩W later y≅z = later (_ ≈⟨ x≈y ⟩P ♭ y≅z)
._ ≈⟨ laterˡ x≈y ⟩W y≅z = laterˡ (_ ≈⟨ x≈y ⟩W y≅z)
_ ≈⟨ ⌈ x≈y ⌉ ⟩W y≅z = ⌈ trans x≈y (Partiality.≅⇒ y≅z) ⌉
where trans = Preorder.trans (Partiality.preorder P.isPreorder _)
-- The relation _≈_ does not admit unrestricted use of transitivity
-- in corecursive proofs, so I have formulated the correctness proof
-- using a continuation. Note that the proof would perhaps be easier
-- if the semantics was also formulated in continuation-passing
-- style.
mutual
correctW :
∀ {n} t {ρ : Env n} {c s} {k : Value → Maybe VM.Value ⊥} →
(∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≈W k v) →
exec ⟨ comp t c , s , comp-env ρ ⟩ ≈W (⟦ t ⟧ ρ >>= k)
correctW (con i) {ρ} {c} {s} {k} hyp = laterˡ (
exec ⟨ c , val (Lambda.Syntax.Closure.con i) ∷ s , comp-env ρ ⟩ ≈⟨ hyp (con i) ⟩W
k (con i) ∎)
correctW (var x) {ρ} {c} {s} {k} hyp = laterˡ (
exec ⟨ c , val (lookup (comp-env ρ) x) ∷ s , comp-env ρ ⟩ ≡⟨ P.cong (λ v → exec ⟨ c , val v ∷ s , comp-env ρ ⟩) $ lookup-hom x ρ ⟩W
exec ⟨ c , val (comp-val (lookup ρ x)) ∷ s , comp-env ρ ⟩ ≈⟨ hyp (lookup ρ x) ⟩W
k (lookup ρ x) ∎)
correctW (ƛ t) {ρ} {c} {s} {k} hyp = laterˡ (
exec ⟨ c , val (comp-val (ƛ t ρ)) ∷ s , comp-env ρ ⟩ ≈⟨ hyp (ƛ t ρ) ⟩W
k (ƛ t ρ) ∎)
correctW (t₁ · t₂) {ρ} {c} {s} {k} hyp =
exec ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ≈⟨ correctW t₁ (λ v₁ → correctW t₂ (λ v₂ → ∙-correctW v₁ v₂ hyp)) ⟩W
(⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦ t₂ ⟧ ρ >>= λ v₂ → ⟪ v₁ ∙ v₂ ⟫P >>= k) ≅⟨ ((⟦ t₁ ⟧ ρ ∎) >>=-cong λ _ → sym $ associative (⟦ t₂ ⟧ ρ) _ _) ⟩
(⟦ t₁ ⟧ ρ >>= λ v₁ → (⟦ t₂ ⟧ ρ >>= λ v₂ → ⟪ v₁ ∙ v₂ ⟫P) >>= k) ≅⟨ sym $ associative (⟦ t₁ ⟧ ρ) _ _ ⟩
(⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ >>= k) ≅⟨ sym (·-comp t₁ t₂ >>=-cong λ v → k v ∎) ⟩
(⟦ t₁ · t₂ ⟧ ρ >>= k) ∎
∙-correctW :
∀ {n} v₁ v₂ {ρ : Env n} {c s} {k : Value → Maybe VM.Value ⊥} →
(∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≈W k v) →
exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val v₁) ∷ s , comp-env ρ ⟩ ≈W
(⟪ v₁ ∙ v₂ ⟫P >>= k)
∙-correctW (con i) v₂ _ = ⌈ PF.fail ∎ ⌉
∙-correctW (ƛ t₁ ρ₁) v₂ {ρ} {c} {s} {k} hyp =
exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val (ƛ t₁ ρ₁)) ∷ s , comp-env ρ ⟩ ≈⟨ later (
exec ⟨ comp t₁ [ ret ] , ret c (comp-env ρ) ∷ s , comp-env (v₂ ∷ ρ₁) ⟩ ≈⟨ correct t₁ (λ v → laterˡ (hyp v)) ⟩P
(⟦ t₁ ⟧ (v₂ ∷ ρ₁) >>= k) ∎) ⟩W
(⟪ ƛ t₁ ρ₁ ∙ v₂ ⟫P >>= k) ∎
whnf : ∀ {x y} → x ≈P y → x ≈W y
whnf (x ≈⟨ x≈y ⟩P y≅z) = x ≈⟨ whnf x≈y ⟩W y≅z
whnf (correct t hyp) = correctW t hyp
mutual
soundW : ∀ {x y} → x ≈W y → Rel (other k) x y
soundW ⌈ x≈y ⌉ = x≈y
soundW (later x≈y) = later (♯ soundP x≈y)
soundW (laterˡ x≈y) = laterˡ (soundW x≈y)
soundP : ∀ {x y} → x ≈P y → Rel (other k) x y
soundP x≈y = soundW (whnf x≈y)
-- Note that the equality that is used here is syntactic.
correct : ∀ t →
exec ⟨ comp t [] , [] , [] ⟩ ≈
(⟦ t ⟧ [] >>= λ v → PF.return (comp-val v))
correct t =
soundP $ Correctness.correct t (λ v → ⌈ PF.return (comp-val v) ∎ ⌉)
where open Correctness
|
{
"alphanum_fraction": 0.4428430242,
"avg_line_length": 35.1942028986,
"ext": "agda",
"hexsha": "a76283767f6e768947923ca731c89c487e07d64a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "Lambda/Closure/Functional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "Lambda/Closure/Functional.agda",
"max_line_length": 138,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "Lambda/Closure/Functional.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 5060,
"size": 12142
}
|
------------------------------------------------------------------------------
-- Example using distributive laws on a binary operation via Agsy
------------------------------------------------------------------------------
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- Tested with the development version of the Agda standard library on
-- 02 February 2012.
module Agsy.DistributiveLaws.TaskB where
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
infixl 7 _·_
------------------------------------------------------------------------------
-- Distributive laws axioms
postulate
D : Set -- The universe
_·_ : D → D → D -- The binary operation.
leftDistributive : ∀ x y z → x · (y · z) ≡ (x · y) · (x · z)
rightDistributive : ∀ x y z → (x · y) · z ≡ (x · z) · (y · z)
-- Properties
taskB : ∀ u x y z →
(x · y · (z · u)) · ((x · y · ( z · u)) · (x · z · (y · u))) ≡
x · z · (y · u)
taskB u x y z = {!-t 20 -m!} -- Agsy fails
|
{
"alphanum_fraction": 0.4401378122,
"avg_line_length": 31.3783783784,
"ext": "agda",
"hexsha": "2eeb0d89fe4b149af2a4427b4baa901f6101d5ef",
"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/Agsy/DistributiveLaws/TaskB.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/Agsy/DistributiveLaws/TaskB.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/Agsy/DistributiveLaws/TaskB.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": 301,
"size": 1161
}
|
module Syntax.Type where
open import Type
-- Assures that a value has a certain type
type-ascript : ∀{ℓ} → (T : Type{ℓ}) → T → T
type-ascript T x = x
{-# INLINE type-ascript #-}
_:-[_] = type-ascript
infixr 0.98 _:-[_]
{-# INLINE _:-[_] #-}
infixl 10 type-ascript
syntax type-ascript T x = x :of: T
|
{
"alphanum_fraction": 0.6336633663,
"avg_line_length": 18.9375,
"ext": "agda",
"hexsha": "ccbf2eb7d86a098b6f9810fa140f27acbf92be38",
"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": "Syntax/Type.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": "Syntax/Type.agda",
"max_line_length": 43,
"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": "Syntax/Type.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": 106,
"size": 303
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Inverses
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Function.Inverse where
open import Level
open import Function using (flip)
open import Function.Bijection hiding (id; _∘_; bijection)
open import Function.Equality as F
using (_⟶_) renaming (_∘_ to _⟪∘⟫_)
open import Function.LeftInverse as Left hiding (id; _∘_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≗_; _≡_)
open import Relation.Unary using (Pred)
------------------------------------------------------------------------
-- Inverses
record _InverseOf_ {f₁ f₂ t₁ t₂}
{From : Setoid f₁ f₂} {To : Setoid t₁ t₂}
(from : To ⟶ From) (to : From ⟶ To) :
Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where
field
left-inverse-of : from LeftInverseOf to
right-inverse-of : from RightInverseOf to
------------------------------------------------------------------------
-- The set of all inverses between two setoids
record Inverse {f₁ f₂ t₁ t₂}
(From : Setoid f₁ f₂) (To : Setoid t₁ t₂) :
Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where
field
to : From ⟶ To
from : To ⟶ From
inverse-of : from InverseOf to
open _InverseOf_ inverse-of public
left-inverse : LeftInverse From To
left-inverse = record
{ to = to
; from = from
; left-inverse-of = left-inverse-of
}
open LeftInverse left-inverse public
using (injective; injection)
bijection : Bijection From To
bijection = record
{ to = to
; bijective = record
{ injective = injective
; surjective = record
{ from = from
; right-inverse-of = right-inverse-of
}
}
}
open Bijection bijection public
using (equivalence; surjective; surjection; right-inverse;
to-from; from-to)
------------------------------------------------------------------------
-- The set of all inverses between two sets (i.e. inverses with
-- propositional equality)
infix 3 _↔_ _↔̇_
_↔_ : ∀ {f t} → Set f → Set t → Set _
From ↔ To = Inverse (P.setoid From) (P.setoid To)
_↔̇_ : ∀ {i f t} {I : Set i} → Pred I f → Pred I t → Set _
From ↔̇ To = ∀ {i} → From i ↔ To i
inverse : ∀ {f t} {From : Set f} {To : Set t} →
(to : From → To) (from : To → From) →
(∀ x → from (to x) ≡ x) →
(∀ x → to (from x) ≡ x) →
From ↔ To
inverse to from from∘to to∘from = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ from
; inverse-of = record
{ left-inverse-of = from∘to
; right-inverse-of = to∘from
}
}
------------------------------------------------------------------------
-- If two setoids are in bijective correspondence, then there is an
-- inverse between them
fromBijection :
∀ {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂} →
Bijection From To → Inverse From To
fromBijection b = record
{ to = Bijection.to b
; from = Bijection.from b
; inverse-of = record
{ left-inverse-of = Bijection.left-inverse-of b
; right-inverse-of = Bijection.right-inverse-of b
}
}
------------------------------------------------------------------------
-- Inverse is an equivalence relation
-- Reflexivity
id : ∀ {s₁ s₂} → Reflexive (Inverse {s₁} {s₂})
id {x = S} = record
{ to = F.id
; from = F.id
; inverse-of = record
{ left-inverse-of = LeftInverse.left-inverse-of id′
; right-inverse-of = LeftInverse.left-inverse-of id′
}
} where id′ = Left.id {S = S}
-- Transitivity
infixr 9 _∘_
_∘_ : ∀ {f₁ f₂ m₁ m₂ t₁ t₂} →
TransFlip (Inverse {f₁} {f₂} {m₁} {m₂})
(Inverse {m₁} {m₂} {t₁} {t₂})
(Inverse {f₁} {f₂} {t₁} {t₂})
f ∘ g = record
{ to = to f ⟪∘⟫ to g
; from = from g ⟪∘⟫ from f
; inverse-of = record
{ left-inverse-of = LeftInverse.left-inverse-of (Left._∘_ (left-inverse f) (left-inverse g))
; right-inverse-of = LeftInverse.left-inverse-of (Left._∘_ (right-inverse g) (right-inverse f))
}
} where open Inverse
-- Symmetry.
sym : ∀ {f₁ f₂ t₁ t₂} →
Sym (Inverse {f₁} {f₂} {t₁} {t₂}) (Inverse {t₁} {t₂} {f₁} {f₂})
sym inv = record
{ from = to
; to = from
; inverse-of = record
{ left-inverse-of = right-inverse-of
; right-inverse-of = left-inverse-of
}
} where open Inverse inv
------------------------------------------------------------------------
-- Transformations
map : ∀ {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂}
{f₁′ f₂′ t₁′ t₂′}
{From′ : Setoid f₁′ f₂′} {To′ : Setoid t₁′ t₂′} →
(t : (From ⟶ To) → (From′ ⟶ To′)) →
(f : (To ⟶ From) → (To′ ⟶ From′)) →
(∀ {to from} → from InverseOf to → f from InverseOf t to) →
Inverse From To → Inverse From′ To′
map t f pres eq = record
{ to = t to
; from = f from
; inverse-of = pres inverse-of
} where open Inverse eq
zip : ∀ {f₁₁ f₂₁ t₁₁ t₂₁}
{From₁ : Setoid f₁₁ f₂₁} {To₁ : Setoid t₁₁ t₂₁}
{f₁₂ f₂₂ t₁₂ t₂₂}
{From₂ : Setoid f₁₂ f₂₂} {To₂ : Setoid t₁₂ t₂₂}
{f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂} →
(t : (From₁ ⟶ To₁) → (From₂ ⟶ To₂) → (From ⟶ To)) →
(f : (To₁ ⟶ From₁) → (To₂ ⟶ From₂) → (To ⟶ From)) →
(∀ {to₁ from₁ to₂ from₂} →
from₁ InverseOf to₁ → from₂ InverseOf to₂ →
f from₁ from₂ InverseOf t to₁ to₂) →
Inverse From₁ To₁ → Inverse From₂ To₂ → Inverse From To
zip t f pres eq₁ eq₂ = record
{ to = t (to eq₁) (to eq₂)
; from = f (from eq₁) (from eq₂)
; inverse-of = pres (inverse-of eq₁) (inverse-of eq₂)
} where open Inverse
|
{
"alphanum_fraction": 0.5085295121,
"avg_line_length": 30.8526315789,
"ext": "agda",
"hexsha": "8883e0a3ca31293fdf94f06a8135d9241fc95683",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Function/Inverse.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Function/Inverse.agda",
"max_line_length": 99,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Function/Inverse.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1878,
"size": 5862
}
|
-- Non-indexed (plain) monads in form of Kleisli triple, presented in point-free style.
module Control.Comonad where
open import Function using (id) renaming (_∘′_ to _∘_)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Axiom.FunctionExtensionality
open import Control.Functor
record IsComonad (W : Set → Set) : Set₁ where
-- Methods.
field
extract : ∀ {A } → W A → A
extend : ∀ {A B} → (W A → B) → W A → W B
-- Laws.
field
extend-β : ∀ {A B} {k : W A → B} →
extract ∘ extend k ≡ k
extend-η : ∀ {A} →
extend {A = A} extract ≡ id
extend-∘ : ∀ {A B C} {k : W A → B} {l : W B → C} →
extend (l ∘ extend k) ≡ extend l ∘ extend k
-- Comonadic composition.
comComp : ∀ {A B C : Set} (l : W B → C) (k : W A → B) → (W A → C)
comComp l k = l ∘ extend k
-- Functoriality.
isFunctor : IsFunctor W
isFunctor = record
{ ops = record { map = map }
; laws = record { map-id = extend-η ; map-∘ = λ {A B C f g} → sym (map-∘-sym f g) }
}
where
map : ∀ {A B} → (A → B) → W A → W B
map f = extend (f ∘ extract)
map-∘-sym : ∀ {A B C} (f : A → B) (g : B → C) → map g ∘ map f ≡ map (g ∘ f)
map-∘-sym f g = begin
map g ∘ map f ≡⟨⟩
extend (g ∘ extract) ∘ extend (f ∘ extract) ≡⟨ sym extend-∘ ⟩
extend (g ∘ extract ∘ extend (f ∘ extract)) ≡⟨ cong (λ z → extend (g ∘ z)) extend-β ⟩
extend (g ∘ f ∘ extract) ≡⟨⟩
map (g ∘ f) ∎
open IsFunctor isFunctor public
-- Monads in Kleisli Triple presentation.
record Comonad : Set₁ where
constructor comonad
field
W : Set → Set
W! : IsComonad W
open IsComonad W! public
-- Casting a Comonad to a Functor
FunctorOfComonad : Comonad → Functor
FunctorOfComonad WW = functor W isFunctor
where open Comonad WW
|
{
"alphanum_fraction": 0.5377800938,
"avg_line_length": 24.9220779221,
"ext": "agda",
"hexsha": "22a2e80c8608329a491c4aa3146cb5202e862d73",
"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": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andreasabel/cubical",
"max_forks_repo_path": "src/Control/Comonad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"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": "andreasabel/cubical",
"max_issues_repo_path": "src/Control/Comonad.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andreasabel/cubical",
"max_stars_repo_path": "src/Control/Comonad.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 691,
"size": 1919
}
|
-- Andreas, 2016-01-21, issue 1791
-- With-clause stripping for copatterns with "polymorphic" field.
-- {-# OPTIONS -v tc.with.strip:60 #-}
postulate anything : ∀{A : Set} → A
record Wrap (A : Set) : Set where
field unwrap : A
record Pointed (M : Set → Set) : Set₁ where
field point : ∀{A} → M A -- field type starts with hidden quantifier!
test : Pointed Wrap
Wrap.unwrap (Pointed.point test) with Set₂
... | _ = anything
-- should succeed
|
{
"alphanum_fraction": 0.6659292035,
"avg_line_length": 23.7894736842,
"ext": "agda",
"hexsha": "c5e69fcd18d870b66c4ac5b9826aa86745db1b5f",
"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/Issue1791.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/Issue1791.agda",
"max_line_length": 72,
"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/Issue1791.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": 139,
"size": 452
}
|
module Generic.Property.Eq where
open import Generic.Core
SemEq : ∀ {i β} {I : Set i} -> Desc I β -> Set
SemEq (var i) = ⊤
SemEq (π i q C) = ⊥
SemEq (D ⊛ E) = SemEq D × SemEq E
mutual
ExtendEq : ∀ {i β} {I : Set i} -> Desc I β -> Set β
ExtendEq (var i) = ⊤
ExtendEq (π i q C) = ExtendEqᵇ i C q
ExtendEq (D ⊛ E) = SemEq D × ExtendEq E
ExtendEqᵇ : ∀ {ι α β γ q} {I : Set ι} i -> Binder α β γ i q I -> α ≤ℓ β -> Set β
ExtendEqᵇ (arg-info v r) (coerce (A , D)) q = Coerce′ q $ RelEq r A × ∀ {x} -> ExtendEq (D x)
instance
{-# TERMINATING #-} -- Why?
DataEq : ∀ {i β} {I : Set i} {D : Data (Desc I β)} {j}
{{eqD : All ExtendEq (consTypes D)}} -> Eq (μ D j)
DataEq {ι} {β} {I} {D₀} = record { _≟_ = decMu } where
mutual
decSem : ∀ D {{eqD : SemEq D}} -> IsSet (⟦ D ⟧ (μ D₀))
decSem (var i) d₁ d₂ = decMu d₁ d₂
decSem (π i q C) {{()}}
decSem (D ⊛ E) {{eqD , eqE}} p₁ p₂ =
decProd (decSem D {{eqD}}) (decSem E {{eqE}}) p₁ p₂
decExtend : ∀ {j} D {{eqD : ExtendEq D}} -> IsSet (Extend D (μ D₀) j)
decExtend (var i) lrefl lrefl = yes refl
decExtend (π i q C) p₁ p₂ = decExtendᵇ i C q p₁ p₂
decExtend (D ⊛ E) {{eqD , eqE}} p₁ p₂ =
decProd (decSem D {{eqD}}) (decExtend E {{eqE}}) p₁ p₂
decExtendᵇ : ∀ {α γ q j} i (C : Binder α β γ i q I) q {{eqC : ExtendEqᵇ i C q}}
-> IsSet (Extendᵇ i C q (μ D₀) j)
decExtendᵇ (arg-info v r) (coerce (A , D)) q {{eqC}} p₁ p₂ =
split q eqC λ eqA eqD ->
decCoerce′ q (decProd (_≟_ {{EqRelValue {{eqA}}}}) (decExtend (D _) {{eqD}})) p₁ p₂
decAny : ∀ {j} (Ds : List (Desc I β)) {{eqD : All ExtendEq Ds}}
-> ∀ d a b ns -> IsSet (Node D₀ (packData d a b Ds ns) j)
decAny [] d a b tt () ()
decAny (D ∷ []) {{eqD , _}} d a b (_ , ns) e₁ e₂ = decExtend D {{eqD}} e₁ e₂
decAny (D ∷ E ∷ Ds) {{eqD , eqDs}} d a b (_ , ns) s₁ s₂ =
decSum (decExtend D {{eqD}}) (decAny (E ∷ Ds) {{eqDs}} d a b ns) s₁ s₂
decMu : ∀ {j} -> IsSet (μ D₀ j)
decMu (node e₁) (node e₂) = dcong node node-inj $ decAny (consTypes D₀)
(dataName D₀)
(parsTele D₀)
(indsTele D₀)
(consNames D₀)
e₁
e₂
|
{
"alphanum_fraction": 0.4192465498,
"avg_line_length": 46.224137931,
"ext": "agda",
"hexsha": "c5a11a07833c6e96f2bc423c7d62f0a7b8a25a65",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z",
"max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Property/Eq.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "turion/Generic",
"max_issues_repo_path": "src/Generic/Property/Eq.agda",
"max_line_length": 95,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Property/Eq.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z",
"num_tokens": 960,
"size": 2681
}
|
module prelude where
Subset : Set → Set₁
Subset(X) = X → Set
_∈_ : ∀ {X} → X → Subset(X) → Set
(x ∈ A) = A(x)
_⊆_ : ∀ {X} → Subset(X) → Subset(X) → Set
(A ⊆ B) = ∀ x → (x ∈ A) → (x ∈ B)
record Inhabited {X} (S : Subset(X)) : Set where
constructor _,_
field witness : X
field witness-in : (witness ∈ S)
Rel : Set → Set₁
Rel(X) = X → X → Set
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
data ℤ : Set where
succ : ℕ → ℤ
-ve : ℕ → ℤ
+ve : ℕ → ℤ
+ve zero = -ve zero
+ve (succ n) = (succ n)
sucz : ℤ → ℤ
sucz (succ x) = succ (succ x)
sucz (-ve zero) = succ zero
sucz (-ve (succ x)) = -ve x
pred : ℤ → ℤ
pred (succ zero) = -ve zero
pred (succ (succ x)) = succ x
pred (-ve x) = -ve (succ x)
_+_ : ℤ → ℤ → ℤ
succ zero + y = sucz y
succ (succ x) + y = sucz (succ x + y)
-ve zero + y = y
-ve (succ x) + y = pred (-ve x + y)
data _^_ (X : Set) : ℕ → Set where
nil : (X ^ zero)
_∷_ : ∀ {n} → X → (X ^ n) → (X ^ succ(n))
data _≡_ {D : Set} (d : D) : D → Set where
refl : (d ≡ d)
sym : ∀ {D} {d e : D} → (d ≡ e) → (e ≡ d)
sym refl = refl
trans : ∀ {D} {d e f : D} → (d ≡ e) → (e ≡ f) → (d ≡ f)
trans refl refl = refl
subst : ∀ {X L R} (P : X → Set) → (L ≡ R) → (P R) → (P L)
subst P refl p = p
data _≣_ {X : Set₁} (x : X) : X → Set₁ where
REFL : (x ≣ x)
SYM : ∀ {D} {d e : D} → (d ≣ e) → (e ≣ d)
SYM REFL = REFL
TRANS : ∀ {D} {d e f : D} → (d ≣ e) → (e ≣ f) → (d ≣ f)
TRANS REFL REFL = REFL
SUBST : ∀ {X L R} (P : X → Set) →
(L ≣ R) →
(P R) →
(P L)
SUBST P REFL p = p
succ-dist-+ : ∀ m n → ((succ m + n) ≡ sucz (+ve m + n))
succ-dist-+ zero n = refl
succ-dist-+ (succ m) n = refl
record ⊤ : Set where
constructor tt
data ⊥ : Set where
¬ : Set → Set
¬(X) = (X → ⊥)
contradiction : ∀ {X : Set} → ⊥ → X
contradiction ()
data _∨_ (X Y : Set) : Set where
in₁ : X → (X ∨ Y)
in₂ : Y → (X ∨ Y)
_∪_ : ∀ {X} → Subset(X) → Subset(X) → Subset(X)
(A ∪ B) x = (x ∈ A) ∨ (x ∈ B)
record _∧_ (X Y : Set) : Set where
constructor _,_
field proj₁ : X
field proj₂ : Y
_∩_ : ∀ {X} → Subset(X) → Subset(X) → Subset(X)
(A ∩ B) x = (x ∈ A) ∧ (x ∈ B)
All : ∀ {X n} → Subset(X) → Subset(X ^ n)
All(S) nil = ⊤
All(S) (x ∷ xs) = (x ∈ S) ∧ (xs ∈ All(S))
All-resp-⊆ : ∀ {X} {A B : Subset(X)} {n} → (A ⊆ B) → (All {n = n} (A) ⊆ All(B))
All-resp-⊆ A⊆B nil tt = tt
All-resp-⊆ A⊆B (x ∷ xs) (x∈A , xs∈A) = (A⊆B x x∈A , All-resp-⊆ A⊆B xs xs∈A)
All-resp-∩ : ∀ {X} {A B : Subset(X)} {n} → ((All {n = n} (A) ∩ All(B)) ⊆ All(A ∩ B))
All-resp-∩ nil (tt , tt) = tt
All-resp-∩ (d ∷ ds) ((d∈A , ds∈A) , (d∈B , ds∈B)) = ((d∈A , d∈B) , (All-resp-∩ ds (ds∈A , ds∈B)))
record DirectedGraph(D : Set) : Set₁ where
field _⇒_ : Rel(D)
data _⇒+_ (d e : D) : Set where
⇒-impl-⇒+ : (d ⇒ e) → (d ⇒+ e)
⇒⇒+-impl-⇒+ : ∀ {f} → (d ⇒ f) → (f ⇒+ e) → (d ⇒+ e)
record Forest(D : Set) : Set₁ where
field DG : DirectedGraph(D)
open DirectedGraph DG public
field ⇒-parent-uniq : ∀ {d e f} → (d ⇒ f) → (e ⇒ f) → (d ≡ e)
field ⇒-acyclic : ∀ {d} → (d ⇒+ d) → ⊥
record PartialOrder(D : Set) : Set₁ where
field _≤_ : Rel(D)
field ≤-refl : ∀ {d} → (d ≤ d)
field ≤-trans : ∀ {d e f} → (d ≤ e) → (e ≤ f) → (d ≤ f)
field ≤-asym : ∀ {d e} → (d ≤ e) → (e ≤ d) → (d ≡ e)
field _≤?_ : ∀ d e → ((d ≤ e) ∨ ¬(d ≤ e))
_<_ : Rel(D)
d < e = (d ≤ e) ∧ ¬(d ≡ e)
≡-impl-≤ : ∀ {d e} → (d ≡ e) → (d ≤ e)
≡-impl-≤ refl = ≤-refl
<-trans-≤ : ∀ {d e f} → (d < e) → (e ≤ f) → (d < f)
<-trans-≤ (d≤e , d≠e) e≤f = (≤-trans d≤e e≤f , (λ d≡f → d≠e (trans d≡f (≤-asym (≤-trans (≡-impl-≤ (sym d≡f)) d≤e) e≤f))))
≤-trans-< : ∀ {d e f} → (d ≤ e) → (e < f) → (d < f)
≤-trans-< d≤e (e≤f , e≠f) = (≤-trans d≤e e≤f , (λ d≡f → e≠f (trans (≤-asym (≤-trans e≤f (≡-impl-≤ (sym d≡f))) d≤e) d≡f)))
<-trans : ∀ {d e f} → (d < e) → (e < f) → (d < f)
<-trans d<e (e≤f , e≠f) = <-trans-≤ d<e e≤f
<-impl-≤ : ∀ {d e} → (d < e) → (d ≤ e)
<-impl-≤ (d≤e , d≠e) = d≤e
<-impl-≱ : ∀ {d e} → (d < e) → ¬(e ≤ d)
<-impl-≱ (d≤e , d≠e) e≤d = d≠e (≤-asym d≤e e≤d)
Past : D → Subset(D)
Past(d) e = (e < d)
Future : D → Subset(D)
Future(d) e = (d < e)
Decreasing : ∀ {n} → Subset(D ^ n)
Decreasing nil = ⊤
Decreasing (d ∷ ds) = (ds ∈ (All(Past(d)) ∩ Decreasing))
Increasing : ∀ {n} → Subset(D ^ n)
Increasing nil = ⊤
Increasing (d ∷ ds) = (ds ∈ (All(Future(d)) ∩ Increasing))
_≤*_ : ∀ {n} → Rel(D ^ n)
nil ≤* nil = ⊤
(d ∷ ds) ≤* (e ∷ es) = (d ≤ e) ∧ (ds ≤* es)
Min : Subset(D) → Subset(D)
Min(S) d = (d ∈ S) ∧ (∀ e → (e ∈ S) → (d ≤ e))
Max : Subset(D) → Subset(D)
Max(S) d = (d ∈ S) ∧ (∀ e → (e ∈ S) → (e ≤ d))
Min* : ∀ {n} → Subset(D ^ n) → Subset(D ^ n)
Min*(S) ds = (ds ∈ S) ∧ (∀ es → (es ∈ S) → (ds ≤* es))
Max* : ∀ {n} → Subset(D ^ n) → Subset(D ^ n)
Max*(S) ds = (ds ∈ S) ∧ (∀ es → (es ∈ S) → (es ≤* ds))
record FiniteTotalOrder(D : Set) : Set₁ where
field PO : PartialOrder(D)
open PartialOrder PO public
field min_∵_ : ∀ (S : Subset(D)) → Inhabited(S) → Inhabited(Min(S))
field max_∵_ : ∀ (S : Subset(D)) → Inhabited(S) → Inhabited(Max(S))
≤-total : ∀ d e → (d ≤ e) ∨ (e < d)
≤-total d e with d ≤? e
≤-total d e | in₁ d≤e = in₁ d≤e
≤-total d e | in₂ d≰e with max (λ f → (d ≡ f) ∨ (e ≡ f)) ∵ (d , in₁ refl)
≤-total d e | in₂ d≰e | .d , (in₁ refl , d-max) = in₂ (e≤d , e≠d) where
e≤d = d-max e (in₂ refl)
e≠d = λ e=d → d≰e (≡-impl-≤ (sym e=d))
≤-total d e | in₂ d≰e | .e , (in₂ refl , e-max) = contradiction (d≰e (e-max d (in₁ refl)))
Max-hd : ∀ S {n} d (ds : D ^ n) →
((d ∷ ds) ∈ Max*(Decreasing ∩ All(S))) →
(d ∈ Max(S))
Max-hd S d ds (((d>ds , ds↓) , (d∈S , ds∈S)) , d∷ds-max) = (d∈S , d-max) where
d-max : ∀ e → (e ∈ S) → (e ≤ d)
d-max e e∈S with ≤-total e d
d-max e e∈S | in₁ e≤d = e≤d
d-max e e∈S | in₂ d<e with d∷ds-max (e ∷ ds) ((All-resp-⊆ (λ f d<f → <-trans d<f d<e) ds d>ds , ds↓) , (e∈S , ds∈S))
d-max e e∈S | in₂ d<e | (e≤d , ds≤ds) = e≤d
Max-tl : ∀ S {n} d (ds : D ^ n) →
((d ∷ ds) ∈ Max*(Decreasing ∩ All(S))) →
(ds ∈ Max*(All(Past(d)) ∩ (Decreasing ∩ All(S))))
Max-tl S d ds (((d>ds , ds↓) , (d∈S , ds∈S)) , d∷ds-max) = ((d>ds , (ds↓ , ds∈S)) , ds-max) where
ds-max : ∀ es → (es ∈ (All(Past(d)) ∩ (Decreasing ∩ All(S)))) → (es ≤* ds)
ds-max es (d>es , (es↓ , es∈S)) with d∷ds-max (d ∷ es) ((d>es , es↓) , (d∈S , es∈S))
ds-max es (d>es , (es↓ , es∈S)) | (d≤d , es≤ds) = es≤ds
record Equivalence(D : Set) : Set₁ where
field _~_ : Rel(D)
field ~-refl : ∀ {d} → (d ~ d)
field ~-trans : ∀ {d e f} → (d ~ e) → (e ~ f) → (d ~ f)
field ~-sym : ∀ {d e} → (d ~ e) → (e ~ d)
field _~?_ : ∀ d e → ((d ~ e) ∨ ¬(d ~ e))
≡-impl-~ : ∀ {d e} → (d ≡ e) → (d ~ e)
≡-impl-~ refl = ~-refl
|
{
"alphanum_fraction": 0.4416304511,
"avg_line_length": 27.016194332,
"ext": "agda",
"hexsha": "a47add97c64e66d072067b7b4afc85cd8f4c2d93",
"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": "cea700aea1488df1d27092c8f3d79d5d99f7e09a",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "cbrewster/ServoNavigation",
"max_forks_repo_path": "notes/prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cea700aea1488df1d27092c8f3d79d5d99f7e09a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "cbrewster/ServoNavigation",
"max_issues_repo_path": "notes/prelude.agda",
"max_line_length": 123,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "cea700aea1488df1d27092c8f3d79d5d99f7e09a",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "cbrewster/ServoNavigation",
"max_stars_repo_path": "notes/prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2017-04-22T01:51:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-22T01:51:07.000Z",
"num_tokens": 3335,
"size": 6673
}
|
{-# OPTIONS --cubical --safe #-}
module Codata.Stream where
open import Prelude
open import Data.List using (List; _∷_; [])
open import Data.List.Kleene
import Data.List.Kleene.Membership as Kleene
open import Data.Fin
Stream : Type a → Type a
Stream A = ℕ → A
infixr 5 _∈_
_∈_ : A → Stream A → Type _
x ∈ xs = fiber xs x
toList : ℕ → Stream A → List A
toList zero xs = []
toList (suc n) xs = xs zero ∷ toList n (xs ∘ suc)
mutual
concat⋆ : A ⋆ → Stream (A ⁺) → Stream A
concat⋆ [] xs = concat⁺ (xs zero) (xs ∘ suc)
concat⋆ (∹ x) xs = concat⁺ x xs
concat⁺ : A ⁺ → Stream (A ⁺) → Stream A
concat⁺ x xs zero = x .head
concat⁺ x xs (suc n) = concat⋆ (x .tail) xs n
concat : Stream (A ⁺) → Stream A
concat xs = concat⁺ (xs zero) (xs ∘ suc)
infixr 5 _∈²_
_∈²_ : A → Stream (A ⁺) → Type _
x ∈² xs = ∃[ n ] x Kleene.∈⁺ xs n
mutual
◇++⋆ : ∀ (x : A) y ys → x Kleene.∈⋆ y → x ∈ concat⋆ y ys
◇++⋆ x (∹ y) ys x∈y = ◇++⁺ x y ys x∈y
◇++⁺ : ∀ (x : A) y ys → x Kleene.∈⁺ y → x ∈ concat⁺ y ys
◇++⁺ x y ys (f0 , x∈y) = zero , x∈y
◇++⁺ x y ys (fs n , x∈y) = let m , p = ◇++⋆ x (y .tail) ys (n , x∈y) in suc m , p
mutual
++◇⋆ : ∀ (x : A) y ys → x ∈ concat ys → x ∈ concat⋆ y ys
++◇⋆ x [] ys x∈ys = x∈ys
++◇⋆ x (∹ y) ys x∈ys = ++◇⁺ x y ys x∈ys
++◇⁺ : ∀ (x : A) y ys → x ∈ concat ys → x ∈ concat⁺ y ys
++◇⁺ x y ys x∈ys = let n , p = ++◇⋆ x (y .tail) ys x∈ys in suc n , p
concat-∈ : ∀ (x : A) xs → x ∈² xs → x ∈ concat xs
concat-∈ x xs (zero , x∈xs) = ◇++⁺ x (xs zero) (xs ∘ suc) x∈xs
concat-∈ x xs (suc n , x∈xs) = ++◇⁺ x (xs zero) (xs ∘ suc) (concat-∈ x (xs ∘ suc) (n , x∈xs))
|
{
"alphanum_fraction": 0.5124378109,
"avg_line_length": 28.2105263158,
"ext": "agda",
"hexsha": "6b6c9c85220180cce1702ab51075c0975a1d448e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Codata/Stream.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Codata/Stream.agda",
"max_line_length": 93,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Codata/Stream.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 784,
"size": 1608
}
|
module Issue472 where
postulate
I : Set
P : I → Set
record ∃ (P : I → Set) : Set where
constructor _,_
field
fst : I
snd : P fst
open ∃
data S : ∃ P → Set where
s : (i : I) (x : P i) → S (i , x)
Foo : (p : ∃ P) → S p → Set
Foo p (s .(fst p) .(snd p)) = I
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Substitute.hs:47
|
{
"alphanum_fraction": 0.5872235872,
"avg_line_length": 16.9583333333,
"ext": "agda",
"hexsha": "e1884082a4088714878654c8e3aef40a24fdcfdb",
"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/Issue472.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/Issue472.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/Succeed/Issue472.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": 149,
"size": 407
}
|
import cedille-options
open import general-util
module classify (options : cedille-options.options)
{mF : Set → Set} ⦃ mFm : monad mF ⦄ (write-to-log : string → mF ⊤) where
open import cedille-types
open import constants
open import conversion
open import ctxt
open import datatype-util
open import elab-util options
open import free-vars
open import meta-vars options {mF} ⦃ mFm ⦄
open import rename
open import resugar
open import rewriting
open import spans options {mF} ⦃ mFm ⦄
open import subst
open import syntax-util
open import type-util
open import to-string options
open import untyped-spans options {mF} ⦃ mFm ⦄
span-error-t : Set
span-error-t = (string × 𝕃 tagged-val)
{-# TERMINATING #-}
check-term : ctxt → ex-tm → (T? : maybe type) → spanM (check-ret T? term)
check-type : ctxt → ex-tp → (k? : maybe kind) → spanM (check-ret k? type)
check-kind : ctxt → ex-kd → spanM kind
check-tpkd : ctxt → ex-tk → spanM tpkd
check-args : ctxt → ex-args → params → spanM args
check-let : ctxt → ex-def → erased? → posinfo → posinfo → spanM (ctxt × var × tagged-val × (∀ {ed : exprd} → ⟦ ed ⟧ → ⟦ ed ⟧) × (term → term))
check-mu : ctxt → posinfo → posinfo → var → ex-tm → maybe ex-tp → posinfo → ex-cases → posinfo → (T? : maybe type) → spanM (check-ret T? term)
check-sigma : ctxt → posinfo → maybe ex-tm → ex-tm → maybe ex-tp → posinfo → ex-cases → posinfo → (T? : maybe type) → spanM (check-ret T? term)
get-datatype-info-from-head-type : ctxt → var → 𝕃 tmtp → spanM (span-error-t ⊎ datatype-info)
check-sigma-evidence : ctxt → maybe ex-tm → var → 𝕃 tmtp → spanM (span-error-t ⊎ (term × (term → term) × datatype-info))
check-cases : ctxt → ex-cases → (Dₓ : var) → (ctrs : trie type) → renamectxt → (ctr-ps : args) → (drop-as : ℕ) → type → (ctxt → term → type → term) → (ctxt → type → kind → type) → spanM (cases × err-m)
check-case : ctxt → ex-case → (earlier : stringset) → (Dₓ : var) → (ctrs : trie (type × params × 𝕃 tmtp)) → renamectxt → (ctr-ps : args) → (drop-as : ℕ) → type → (ctxt → term → type → term) → (ctxt → type → kind → type) → spanM (case × trie (type × params × 𝕃 tmtp))
check-refinement : ctxt → type → kind → spanM (type × 𝕃 tagged-val × err-m)
synth-tmtp' : ∀ {b X} → ctxt → if b then ex-tm else ex-tp → (if b then term else type → if b then type else kind → spanM X) → spanM X
synth-tmtp' {tt} Γ t f = check-term Γ t nothing >>= uncurry f
synth-tmtp' {ff} Γ T f = check-type Γ T nothing >>= uncurry f
check-tmtp' : ∀ {b X} → ctxt → if b then ex-tm else ex-tp → if b then type else kind → (if b then term else type → spanM X) → spanM X
check-tmtp' {tt} Γ t T f = check-term Γ t (just T) >>= f
check-tmtp' {ff} Γ T k f = check-type Γ T (just k) >>= f
check-tpkd' : ∀ {b X} → ctxt → if b then ex-kd else ex-tk → (if b then kind else tpkd → spanM X) → spanM X
check-tpkd' {tt} Γ k f = check-kind Γ k >>= f
check-tpkd' {ff} Γ k f = check-tpkd Γ k >>= f
lambda-bound-conv? : ctxt → var → tpkd → tpkd → 𝕃 tagged-val → 𝕃 tagged-val × err-m
lambda-bound-conv? Γ x tk tk' ts with conv-tpkd Γ tk tk'
...| tt = ts , nothing
...| ff =
(to-string-tag-tk "declared classifier" Γ tk' ::
to-string-tag-tk "expected classifier" Γ tk :: ts) ,
just "The classifier given for a λ-bound variable is not the one we expected"
id' = id
hnf-of : ∀ {X : Set} {ed} → ctxt → ⟦ ed ⟧ → (⟦ ed ⟧ → X) → X
hnf-of Γ t f = f (hnf Γ unfold-head-elab t)
-- "⊢" = "\vdash" or "\|-"
-- "⇒" = "\r="
-- "⇐" = "\l="
infixr 2 hnf-of id' check-tpkd' check-tmtp' synth-tmtp'
syntax synth-tmtp' Γ t (λ t~ → f) = Γ ⊢ t ↝ t~ ⇒ f
syntax check-tmtp' Γ t T f = Γ ⊢ t ⇐ T ↝ f
syntax check-tpkd' Γ k f = Γ ⊢ k ↝ f
syntax id' (λ x → f) = x / f -- Supposed to look like a horizontal bar (as in typing rules)
syntax hnf-of Γ t f = Γ ⊢ t =β= f
-- t [-]t'
check-term Γ (ExApp t e t') Tₑ? =
check-term-spine Γ (ExApp t e t') (proto-maybe Tₑ?) tt
on-fail return-when (Hole (term-start-pos t)) (TpHole (term-start-pos t))
>>=m (uncurry return-when ∘ check-term-spine-elim Γ)
where open import type-inf options {mF} check-term check-type
-- t ·T
check-term Γ (ExAppTp tₕ Tₐ) Tₑ? =
-- "Γ ⊢ tₕ ↝ tₕ~ ⇒ Tₕ~ /" desugars to "synth-tmtp' Γ tₕ λ tₕ~ Tₕ~ →"
Γ ⊢ tₕ ↝ tₕ~ ⇒ Tₕ~ /
Γ ⊢ Tₕ~ =β= λ where
(TpAbs tt x (Tkk kₐ) Tᵣ) →
Γ ⊢ Tₐ ⇐ kₐ ↝ Tₐ~ /
let Tᵣ = [ Γ - Tₐ~ / x ] Tᵣ in
[- AppTp-span tt (term-start-pos tₕ) (type-end-pos Tₐ) (maybe-to-checking Tₑ?)
(head-type Γ Tₕ~ :: type-data Γ Tᵣ :: expected-type-if Γ Tₑ?)
(check-for-type-mismatch-if Γ "synthesized" Tₑ? Tᵣ) -]
return-when (AppTp tₕ~ Tₐ~) Tᵣ
Tₕ'~ →
untyped-type Γ Tₐ >>= λ Tₐ~ →
[- AppTp-span tt (term-start-pos tₕ) (type-end-pos Tₐ) (maybe-to-checking Tₑ?)
(head-type Γ Tₕ'~ :: arg-type Γ Tₐ~ :: expected-type-if Γ Tₑ?)
(unless (is-hole Tₕ'~)
("The type synthesized from the head does not allow it to be applied" ^
" to a type argument")) -]
return-when (AppTp tₕ~ Tₐ~) (TpHole (term-start-pos tₕ))
-- β[<t?>][{t?'}]
check-term Γ (ExBeta pi t? t?') Tₑ? =
maybe-map (λ {(PosTm t _) → untyped-term Γ t}) t? >>=? λ t?~ →
maybe-map (λ {(PosTm t _) → untyped-term Γ t}) t?' >>=? λ t?'~ →
let t'~ = maybe-else' t?'~ id-term id
e-t~ = maybe-else' Tₑ?
(maybe-else' t?~
(inj₁ ([] , "When synthesizing, specify what equality to prove with β<...>"))
(λ t → inj₂ (t , nothing)))
λ Tₑ → Γ ⊢ Tₑ =β= λ where
(TpEq t₁ t₂) →
if conv-term Γ t₁ t₂
then maybe-else' (t?~ >>= λ t~ → check-for-type-mismatch Γ "computed"
(TpEq t~ t~) (TpEq t₁ t₂) >>= λ e → just (e , t~))
(inj₂ (t₁ , just t₂))
(uncurry λ e t~ → inj₁ ([ type-data Γ (TpEq t~ t~) ] , e))
else inj₁ ([] , "The two terms in the equation are not β-equal")
Tₕ → inj₁ ([] , "The expected type is not an equation")
e? = either-else' e-t~ (map-snd just) λ _ → [] , nothing
fₓ = fresh-var Γ "x"
t~T~ = either-else' e-t~ (λ _ → Hole pi , TpEq (Hole pi) (Hole pi))
$ uncurry λ t₁ → maybe-else (Beta t₁ t'~ , TpEq t₁ t₁)
λ t₂ → (Beta t₁ t'~) , TpEq t₁ t₂ in
[- uncurry (λ tvs → Beta-span pi (term-end-pos (ExBeta pi t? t?')) (maybe-to-checking Tₑ?)
(expected-type-if Γ Tₑ? ++ tvs)) e? -]
uncurry return-when t~T~
-- χ [T?] - t
check-term Γ (ExChi pi T? t) Tₑ? =
(maybe-else' T?
(check-term Γ t nothing)
λ T → Γ ⊢ T ⇐ KdStar ↝ T~ /
Γ ⊢ t ⇐ T~ ↝ t~ /
return2 t~ T~
) >>= uncurry λ t~ T~ →
[- Chi-span Γ pi (just T~) t (maybe-to-checking Tₑ?)
(type-data Γ T~ :: expected-type-if Γ Tₑ?)
(check-for-type-mismatch-if Γ
(maybe-else' T? "synthesized" (const "computed")) Tₑ? T~) -]
return-when t~ T~
-- δ [T?] - t
check-term Γ (ExDelta pi T? t) Tₑ? =
Γ ⊢ t ↝ t~ ⇒ Tcontra /
maybe-else' T?
(return (maybe-else' Tₑ? (TpAbs Erased "X" (Tkk KdStar) (TpVar "X")) id))
(λ T → Γ ⊢ T ⇐ KdStar ↝ return) >>= λ T~' →
let b = Γ ⊢ Tcontra =β= λ {(TpEq t₁ t₂) → when (inconv Γ t₁ t₂) (t₁ , t₂); _ → nothing}
b? = unless (conv-type Γ Tcontra (TpEq tt-term ff-term)) triv >> b in
[- Delta-span pi t (maybe-to-checking Tₑ?)
(to-string-tag "the contradiction" Γ Tcontra ::
type-data Γ T~' :: expected-type-if Γ Tₑ?)
(maybe-not b >> just
"We could not find a contradiction in the synthesized type of the subterm") -]
return-when (Delta b? T~' t~) T~'
-- ε[lr][-?] t
check-term Γ (ExEpsilon pi lr -? t) Tₑ? =
let hnf-from = if -? then hanf Γ tt else hnf Γ unfold-head
update-eq : term → term → type
update-eq = λ t₁ t₂ → uncurry TpEq $ maybe-else' lr (hnf-from t₁ , hnf-from t₂) λ lr →
if lr then (t₁ , hnf-from t₂) else (hnf-from t₁ , t₂) in
case-ret {m = Tₑ?}
(Γ ⊢ t ↝ t~ ⇒ T~ /
Γ ⊢ T~ =β= λ where
(TpEq t₁ t₂) →
let Tᵣ = update-eq t₁ t₂ in
[- Epsilon-span pi lr -? t (maybe-to-checking Tₑ?) [ type-data Γ Tᵣ ] nothing -]
return2 t~ Tᵣ
Tₕ →
[- Epsilon-span pi lr -? t (maybe-to-checking Tₑ?)
[ to-string-tag "synthesized type" Γ Tₕ ]
(unless (is-hole Tₕ)
"The synthesized type of the body is not an equation") -]
return2 t~ Tₕ)
λ Tₑ → Γ ⊢ Tₑ =β= λ where
(TpEq t₁ t₂) →
[- Epsilon-span pi lr -? t (maybe-to-checking Tₑ?)
[ expected-type Γ (TpEq t₁ t₂) ] nothing -]
Γ ⊢ t ⇐ update-eq t₁ t₂ ↝ return
Tₕ →
[- Epsilon-span pi lr -? t (maybe-to-checking Tₑ?) [ expected-type Γ Tₕ ]
(unless (is-hole Tₕ) "The expected type is not an equation") -]
untyped-term Γ t
-- ●
check-term Γ (ExHole pi) Tₑ? =
[- hole-span Γ pi Tₑ? (maybe-to-checking Tₑ?) [] -]
return-when (Hole pi) (TpHole pi)
-- [ t₁ , t₂ [@ Tₘ,?] ]
check-term Γ (ExIotaPair pi t₁ t₂ Tₘ? pi') Tₑ? =
maybe-else' {B = spanM (err-m × 𝕃 tagged-val × term × term × term × type)} Tₑ?
(maybe-else' Tₘ?
(untyped-term Γ t₁ >>= λ t₁~ →
untyped-term Γ t₂ >>= λ t₂~ →
return (just "Iota pairs require a specified type when synthesizing" , [] ,
t₁~ , t₁~ , t₂~ , TpHole pi))
λ {(ExGuide pi'' x T₂) →
Γ ⊢ t₁ ↝ t₁~ ⇒ T₁~ /
(Γ , pi'' - x :` Tkt T₁~) ⊢ T₂ ⇐ KdStar ↝ T₂~ /
Γ ⊢ t₂ ⇐ [ Γ - t₁~ / (pi'' % x) ] T₂~ ↝ t₂~ /
let T₂~ = [ Γ - Var x / (pi'' % x) ] T₂~
bd = binder-data Γ pi'' x (Tkt T₁~) ff nothing
(type-start-pos T₂) (type-end-pos T₂) in
[- Var-span Γ pi'' x checking [ type-data Γ T₁~ ] nothing -]
return (nothing , (type-data Γ (TpIota x T₁~ T₂~) :: [ bd ]) ,
IotaPair t₁~ t₂~ x T₂~ , t₁~ , t₂~ , TpIota x T₁~ T₂~)})
(λ Tₑ → Γ ⊢ Tₑ =β= λ where
(TpIota x T₁ T₂) →
Γ ⊢ t₁ ⇐ T₁ ↝ t₁~ /
maybe-else' Tₘ?
(Γ ⊢ t₂ ⇐ [ Γ - t₁~ / x ] T₂ ↝ t₂~ /
return (nothing , (type-data Γ (TpIota x T₁ T₂) :: [ expected-type Γ Tₑ ]) ,
IotaPair t₁~ t₂~ x T₂ , t₁~ , t₂~ , TpIota x T₁ T₂))
λ {(ExGuide pi'' x' Tₘ) →
(Γ , pi'' - x' :` Tkt T₁) ⊢ Tₘ ⇐ KdStar ↝ Tₘ~ /
let Tₘ~ = [ Γ - Var x' / (pi'' % x') ] Tₘ~
T₂ = [ Γ - Var x' / x ] T₂
Tₛ = TpIota x' T₁ Tₘ~ in
Γ ⊢ t₂ ⇐ [ Γ - t₁~ / x' ] Tₘ~ ↝ t₂~ /
[- Var-span Γ pi'' x checking [ type-data Γ T₁ ] nothing -]
return (check-for-type-mismatch Γ "computed" Tₘ~ T₂ ,
(type-data Γ Tₛ :: expected-type Γ (TpIota x' T₁ T₂) ::
[ binder-data Γ pi'' x' (Tkt T₁) ff nothing
(type-start-pos Tₘ) (type-end-pos Tₘ) ]) ,
IotaPair t₁~ t₂~ x' Tₘ~ , t₁~ , t₂~ , Tₛ)}
Tₕ →
untyped-term Γ t₁ >>= λ t₁~ →
untyped-term Γ t₂ >>= λ t₂~ →
return (unless (is-hole Tₕ) "The expected type is not an iota-type" ,
[ expected-type Γ Tₕ ] , t₁~ , t₁~ , t₂~ , Tₕ)) >>= λ where
(err? , tvs , t~ , t₁~ , t₂~ , T~) →
let conv-e = "The two components of the iota-pair are not convertible (as required)"
conv-e? = unless (conv-term Γ t₁~ t₂~) conv-e
conv-tvs = maybe-else' conv-e? [] λ _ →
to-string-tag "hnf of the first component" Γ (hnf Γ unfold-head t₁~) ::
[ to-string-tag "hnf of the second component" Γ (hnf Γ unfold-head t₂~) ] in
[- IotaPair-span pi pi' (maybe-to-checking Tₑ?) (conv-tvs ++ tvs)
(conv-e? ||-maybe err?) -]
return-when t~ T~
-- t.(1 / 2)
check-term Γ (ExIotaProj t n pi) Tₑ? =
Γ ⊢ t ↝ t~ ⇒ T~ /
let n? = case n of λ {"1" → just ι1; "2" → just ι2; _ → nothing} in
maybe-else' n?
([- IotaProj-span t pi (maybe-to-checking Tₑ?) (expected-type-if Γ Tₑ?)
(just "Iota-projections must use .1 or .2 only") -]
return-when t~ (TpHole pi)) λ n →
Γ ⊢ T~ =β= λ where
(TpIota x T₁ T₂) →
let Tᵣ = if n iff ι1 then T₁ else ([ Γ - t~ / x ] T₂) in
[- IotaProj-span t pi (maybe-to-checking Tₑ?)
(type-data Γ Tᵣ :: expected-type-if Γ Tₑ?)
(check-for-type-mismatch-if Γ "synthesized" Tₑ? Tᵣ) -]
return-when (IotaProj t~ n) Tᵣ
Tₕ~ →
[- IotaProj-span t pi (maybe-to-checking Tₑ?)
(head-type Γ Tₕ~ :: expected-type-if Γ Tₑ?)
(unless (is-hole Tₕ~)
"The synthesized type of the head is not an iota-type") -]
return-when (IotaProj t~ n) (TpHole pi)
-- λ/Λ x [: T?]. t
check-term Γ (ExLam pi e pi' x tk? t) Tₑ? =
[- punctuation-span "Lambda" pi (posinfo-plus pi 1) -]
let erase-err : (exp act : erased?) → tpkd → term → err-m × 𝕃 tagged-val
erase-err = λ where
Erased NotErased tk t →
just ("The expected type is a ∀-abstraction (implicit input), " ^
"but the term is a λ-abstraction (explicit input)") , []
NotErased Erased tk t →
just ("The expected type is a Π-abstraction (explicit input), " ^
"but the term is a Λ-abstraction (implicit input)") , []
Erased Erased tk t →
maybe-else (nothing , []) (λ e-tv → just (fst e-tv) , [ snd e-tv ])
(trie-lookup (free-vars (erase t)) x >>
just ("The Λ-bound variable occurs free in the erasure of the body" ,
erasure Γ t))
NotErased NotErased (Tkk _) t →
just "λ-terms must bind a term, not a type (use Λ instead)" , []
NotErased NotErased (Tkt _) t →
nothing , [] in
case-ret {m = Tₑ?}
(maybe-else' tk?
(untyped-term (Γ , pi' - x :` Tkt (TpHole pi')) t >>= λ t~ →
[- Lam-span Γ synthesizing pi pi' e x (Tkt (TpHole pi')) t []
(just ("We are not checking this abstraction against a type, " ^
"so a classifier must be given for the bound variable " ^ x)) -]
return2 (Lam e x nothing (rename-var Γ (pi' % x) x t~)) (TpHole pi'))
λ tk →
Γ ⊢ tk ↝ tk~ /
(Γ , pi' - x :` tk~) ⊢ t ↝ t~ ⇒ T~ /
let T~ = rename-var Γ (pi' % x) x T~
t~ = rename-var Γ (pi' % x) x t~
Tᵣ = TpAbs e x tk~ T~ in
[- var-span e (Γ , pi' - x :` tk~) pi' x checking tk~ nothing -]
[- uncurry (λ tvs → Lam-span Γ synthesizing pi pi' e x tk~ t
(type-data Γ Tᵣ :: tvs)) (twist-× (erase-err e e tk~ t~)) -]
return2 (Lam e x (just tk~) t~) Tᵣ)
λ Tₑ → Γ ⊢ Tₑ =β= λ where
(TpAbs e' x' tk T) →
maybe-map (check-tpkd Γ) tk? >>=? tk~? /
let tk~ = maybe-else' tk~? tk id in
--maybe-else' tk? (return tk) (λ tk → Γ ⊢ tk ↝ return) >>= tk~ /
(Γ , pi' - x :` tk~) ⊢ t ⇐ rename-var Γ x' (pi' % x) T ↝ t~ /
let xₙ = if x =string ignored-var && is-free-in x' T then x' else x
t~ = rename-var Γ (pi' % x) xₙ t~
T = rename-var Γ x' xₙ T
Tₛ = TpAbs e xₙ tk~ T
Tₑ = TpAbs e' xₙ tk T
vₑ = check-for-tpkd-mismatch-if Γ "computed" tk~? tk in
[- var-span e (Γ , pi' - x :` tk~) pi' x (maybe-to-checking tk?) tk~ nothing -]
[- uncurry (λ err tvs → Lam-span Γ checking pi pi' e x tk~ t
(type-data Γ Tₛ :: expected-type Γ Tₑ :: tvs) (err ||-maybe vₑ))
(erase-err e' e tk~ t~) -]
return (Lam e xₙ (just tk~) t~)
Tₕ →
maybe-else' tk? (return (Tkt (TpHole pi'))) (check-tpkd Γ) >>= tk~ /
untyped-term (Γ , pi' - x :` tk~) t >>= t~ /
[- Lam-span Γ checking pi pi' e x (Tkt (TpHole pi')) t
[ expected-type Γ Tₕ ] (just "The expected type is not a ∀- or a Π-type") -]
return (Lam e x (unless (is-hole -tk' tk~) tk~)
(rename-var Γ (pi' % x) x t~))
-- [d] - t
check-term Γ (ExLet pi e? d t) Tₑ? =
check-let Γ d e? (term-start-pos t) (term-end-pos t) >>= λ where
(Γ' , x , tv , σ , f) →
case-ret-body {m = Tₑ?} (check-term Γ' t Tₑ?) λ t~ T~ →
[- punctuation-span "Parens (let)" pi (term-end-pos t) -]
[- Let-span e? pi (term-end-pos t) (maybe-to-checking Tₑ?)
(maybe-else' Tₑ? (type-data Γ T~) (expected-type Γ) :: [ tv ])
(when (e? && is-free-in x (erase t~))
(unqual-local x ^ "occurs free in the body of the term")) -]
return-when (f t~) (σ T~)
-- open/close x - t
check-term Γ (ExOpen pi o pi' x t) Tₑ? =
let Γ? = ctxt-clarify-def Γ o x
e? = maybe-not Γ? >> just (x ^ " does not have a definition that can be " ^
(if o then "opened" else "closed")) in
[- Var-span Γ pi' x (maybe-to-checking Tₑ?) [ not-for-navigation ] nothing -]
[- Open-span o pi x t (maybe-to-checking Tₑ?) (expected-type-if Γ Tₑ?) e? -]
check-term (maybe-else' Γ? Γ id) t Tₑ?
-- (t)
check-term Γ (ExParens pi t pi') Tₑ? =
[- punctuation-span "Parens (term)" pi pi' -]
check-term Γ t Tₑ?
-- φ t₌ - t₁ {t₂}
check-term Γ (ExPhi pi t₌ t₁ t₂ pi') Tₑ? =
case-ret-body {m = Tₑ?} (check-term Γ t₁ Tₑ?) λ t₁~ T~ →
untyped-term Γ t₂ >>= λ t₂~ →
Γ ⊢ t₌ ⇐ TpEq t₁~ t₂~ ↝ t₌~ /
[- Phi-span pi pi' (maybe-to-checking Tₑ?)
[ maybe-else' Tₑ? (type-data Γ T~) (expected-type Γ)] nothing -]
return-when (Phi t₌~ t₁~ t₂~) T~
-- ρ[+]<ns> t₌ [@ Tₘ?] - t
check-term Γ (ExRho pi ρ+ <ns> t₌ Tₘ? t) Tₑ? =
Γ ⊢ t₌ ↝ t₌~ ⇒ T₌ /
Γ ⊢ T₌ =β= λ where
(TpEq t₁ t₂) →
let tₗ = if isJust Tₑ? then t₁ else t₂
tᵣ = if isJust Tₑ? then t₂ else t₁
tvs = λ T~ Tᵣ → to-string-tag "equation" Γ (TpEq t₁ t₂) ::
maybe-else' Tₑ?
(to-string-tag "type of second subterm" Γ T~)
(expected-type Γ) ::
[ to-string-tag "rewritten type" Γ Tᵣ ] in
maybe-else' Tₘ?
(elim-pair (optNums-to-stringset <ns>) λ ns ns-e? →
let x = fresh-var Γ "x"
Γ' = ctxt-var-decl x Γ
T-f = λ T → rewrite-type T Γ' ρ+ ns (just t₌~) tₗ x 0
Tᵣ-f = fst ∘ T-f
nn-f = snd ∘ T-f
Tₚ-f = map-fst (post-rewrite Γ' x t₌~ tᵣ) ∘ T-f in
maybe-else' Tₑ?
(Γ ⊢ t ↝ t~ ⇒ T~ /
return2 t~ T~)
(λ Tₑ → Γ ⊢ t ⇐ fst (Tₚ-f Tₑ) ↝ t~ /
return2 t~ Tₑ) >>=c λ t~ T~ →
elim-pair (Tₚ-f T~) λ Tₚ nn →
[- Rho-span pi t₌ t (maybe-to-checking Tₑ?) ρ+
(inj₁ (fst nn)) (tvs T~ Tₚ) (ns-e? (snd nn)) -]
return-when (Rho t₌~ x (erase (Tᵣ-f T~)) t~) Tₚ)
λ where
(ExGuide pi' x Tₘ) →
[- Var-span Γ pi' x untyped [] nothing -]
let Γ' = Γ , pi' - x :` Tkt (TpHole pi') in
untyped-type Γ' Tₘ >>= λ Tₘ~ →
let Tₘ~ = [ Γ' - Var x / (pi' % x) ] Tₘ~
T' = [ Γ' - tₗ / x ] Tₘ~
T'' = post-rewrite Γ' x t₌~ tᵣ (rewrite-at Γ' x (just t₌~) tt T' Tₘ~)
check-str = if isJust Tₑ? then "computed" else "synthesized" in
maybe-else' Tₑ?
(check-term Γ t nothing)
(λ Tₑ → Γ ⊢ t ⇐ T'' ↝ t~ /
return2 t~ Tₑ) >>=c λ t~ T~ →
[- Rho-span pi t₌ t (maybe-to-checking Tₑ?) ρ+ (inj₂ x) (tvs T~ T'')
(check-for-type-mismatch Γ check-str T' T~) -]
return-when (Rho t₌~ x Tₘ~ t~) T''
Tₕ →
Γ ⊢ t ↝ t~ ⇒ λ T~ →
[- Rho-span pi t₌ t (maybe-to-checking Tₑ?) ρ+ (inj₁ 1)
(to-string-tag "type of first subterm" Γ Tₕ ::
[ to-string-tag "type of second subterm" Γ T~ ])
(unless (is-hole Tₕ)
"We could not synthesize an equation from the first subterm") -]
return-when t~ T~
-- ς t
check-term Γ (ExVarSigma pi t) Tₑ? =
case-ret
(Γ ⊢ t ↝ t~ ⇒ T /
Γ ⊢ T =β= λ where
(TpEq t₁ t₂) →
[- VarSigma-span pi t synthesizing [ type-data Γ (TpEq t₂ t₁) ] nothing -]
return2 (VarSigma t~) (TpEq t₂ t₁)
Tₕ →
[- VarSigma-span pi t synthesizing [ type-data Γ Tₕ ]
(unless (is-hole Tₕ)
"The synthesized type of the body is not an equation") -]
return2 (VarSigma t~) Tₕ)
λ Tₑ →
Γ ⊢ Tₑ =β= λ where
(TpEq t₁ t₂) →
Γ ⊢ t ⇐ TpEq t₂ t₁ ↝ t~ /
[- VarSigma-span pi t checking [ expected-type Γ (TpEq t₁ t₂) ] nothing -]
return (VarSigma t~)
Tₕ →
[- VarSigma-span pi t checking [ expected-type Γ Tₕ ]
(unless (is-hole Tₕ)
"The expected type is not an equation") -]
untyped-term Γ t
-- θ t ts
check-term Γ (ExTheta pi θ t ts) Tₑ? =
case-ret {m = Tₑ?}
([- Theta-span Γ pi θ t ts synthesizing [] (just
"Theta-terms can only be used when checking (and we are synthesizing here)") -]
return2 (Hole pi) (TpHole pi))
λ Tₑ →
Γ ⊢ t ↝ t~ ⇒ T /
let x = case hnf Γ unfold-head t~ of λ {(Var x) → x; _ → "x"}
x' = fresh-var Γ x in
Γ ⊢ T =β= λ where
(TpAbs me x (Tkk kd) tp) →
(case θ of λ where
(AbstractVars vs) → either-else' (wrap-vars vs Tₑ) (return2 (TpHole pi) ∘ just) λ Tₘ → return2 Tₘ nothing
Abstract → return2 (TpLam x' (Tkt T) (rename-var Γ x x' Tₑ)) nothing
AbstractEq → return2 (TpLam x' (Tkt T) (TpAbs Erased ignored-var (Tkt (TpEq t~ (Var x'))) (rename-var Γ x x' Tₑ))) nothing) >>=c λ Tₘ e₁ →
check-refinement Γ Tₘ kd >>=c λ Tₘ → uncurry λ tvs e₂ →
let tp' = [ Γ - Tₘ / x ] tp in
check-lterms ts (AppTp t~ Tₘ) tp' >>=c λ t~ T~ →
let e₃ = check-for-type-mismatch Γ "synthesized" T~ Tₑ
t~ = case θ of λ {AbstractEq → AppEr t~ (Beta (erase t~) id-term); _ → t~} in
[- Theta-span Γ pi θ t ts checking
(type-data Γ T~ :: expected-type Γ Tₑ :: tvs)
(e₁ ||-maybe (e₂ ||-maybe e₃)) -]
return t~
Tₕ →
[- Theta-span Γ pi θ t ts checking (head-type Γ Tₕ :: expected-type Γ Tₑ :: [])
(unless (is-hole Tₕ) "The synthesized type of the head is not a type-forall") -]
return (Hole pi)
where
check-lterms : 𝕃 lterm → term → type → spanM (term × type)
check-lterms [] tm tp = return2 tm tp
check-lterms (Lterm me t :: ts) tm tp =
Γ ⊢ tp =β= λ where
(TpAbs me' x (Tkt T) T') →
Γ ⊢ t ⇐ T ↝ t~ /
(if me iff me' then return triv else spanM-add
(Theta-span Γ pi θ t [] checking [] (just "Mismatched erasure of theta arg"))) >>
check-lterms ts (if me then AppEr tm t~ else App tm t~) ([ Γ - t~ / x ] T')
Tₕ →
(if is-hole Tₕ then id
else [- Theta-span Γ pi θ t [] checking [ expected-type Γ Tₕ ]
(just "The expected type is not an arrow type") -]_)
(untyped-term Γ t >>= λ t~ → check-lterms ts (if me then AppEr tm t~ else App tm t~) Tₕ)
var-not-in-scope : var → string
var-not-in-scope x =
"We could not compute a motive from the given term because " ^
"the abstracted variable " ^ x ^ " is not in scope"
wrap-var : var → type → string ⊎ type
wrap-var x T =
let x' = fresh-var Γ x in
maybe-else' (ctxt-lookup-tpkd-var Γ x)
(inj₁ (var-not-in-scope x))
λ {(qx , as , tk) → inj₂ (TpLam x' tk (rename-var Γ qx x' T))}
wrap-vars : 𝕃 var → type → var ⊎ type
wrap-vars [] T = inj₂ T
wrap-vars (x :: xs) T = wrap-vars xs T >>= wrap-var x
motive : var → var → type → type → theta → term → type
motive x x' T T' Abstract t = TpLam x' (Tkt T') (rename-var Γ x x' T)
motive x x' T T' AbstractEq t = TpLam x' (Tkt T') (TpAbs Erased ignored-var (Tkt (TpEq t (Var x'))) (rename-var Γ x x' T))
motive x x' T T' (AbstractVars vs) t = T -- Shouldn't happen
-- μ(' / rec.) t [@ Tₘ?] {ms...}
check-term Γ (ExMu pi1 pi2 x t Tₘ? pi' ms pi'') Tₑ? =
check-mu Γ pi1 pi2 x t Tₘ? pi' ms pi'' Tₑ?
check-term Γ (ExSigma pi t? t Tₘ? pi' ms pi'') Tₑ? =
check-sigma Γ pi t? t Tₘ? pi' ms pi'' Tₑ?
-- x
check-term Γ (ExVar pi x) Tₑ? =
maybe-else' (ctxt-lookup-term-var Γ x)
([- Var-span Γ pi x (maybe-to-checking Tₑ?)
(expected-type-if Γ Tₑ?)
(just "Missing a type for a term variable") -]
return-when (Var x) (TpHole pi))
λ {(qx , as , T) →
[- Var-span Γ pi x (maybe-to-checking Tₑ?)
(type-data Γ T :: expected-type-if Γ Tₑ?)
(check-for-type-mismatch-if Γ "computed" Tₑ? T) -]
return-when (apps-term (Var qx) as) T}
-- ∀/Π x : tk. T
check-type Γ (ExTpAbs pi e pi' x tk T) kₑ? =
Γ ⊢ tk ↝ tk~ /
(Γ , pi' - x :` tk~) ⊢ T ⇐ KdStar ↝ T~ /
let T~ = rename-var Γ (pi' % x) x T~ in
[- punctuation-span "Forall" pi (posinfo-plus pi 1) -]
[- var-span ff (Γ , pi' - x :` tk~) pi' x checking tk~ nothing -]
[- TpQuant-span Γ e pi pi' x tk~ T (maybe-to-checking kₑ?)
(kind-data Γ KdStar :: expected-kind-if Γ kₑ?)
(check-for-kind-mismatch-if Γ "computed" kₑ? KdStar) -]
return-when (TpAbs e x tk~ T~) KdStar
-- ι x : T₁. T₂
check-type Γ (ExTpIota pi pi' x T₁ T₂) kₑ? =
Γ ⊢ T₁ ⇐ KdStar ↝ T₁~ /
(Γ , pi' - x :` Tkt T₁~) ⊢ T₂ ⇐ KdStar ↝ T₂~ /
let T₂~ = rename-var Γ (pi' % x) x T₂~ in
[- punctuation-span "Iota" pi (posinfo-plus pi 1) -]
[- Var-span (Γ , pi' - x :` Tkt T₁~) pi' x checking [ type-data Γ T₁~ ] nothing -]
[- Iota-span Γ pi pi' x T₁~ T₂ (maybe-to-checking kₑ?)
(kind-data Γ KdStar :: expected-kind-if Γ kₑ?)
(check-for-kind-mismatch-if Γ "computed" kₑ? KdStar) -]
return-when (TpIota x T₁~ T₂~) KdStar
-- {^ T ^} (generated by theta)
check-type Γ (ExTpNoSpans T pi) kₑ? = check-type Γ T kₑ? >>=spand return
-- [d] - T
check-type Γ (ExTpLet pi d T) kₑ? =
check-let Γ d ff (type-start-pos T) (type-end-pos T) >>= λ where
(Γ' , x , tv , σ , f) →
case-ret-body {m = kₑ?} (check-type Γ' T kₑ?) λ T~ k~ →
[- punctuation-span "Parens (let)" pi (type-end-pos T) -]
[- TpLet-span pi (type-end-pos T) (maybe-to-checking kₑ?)
(maybe-else' kₑ? (kind-data Γ k~) (expected-kind Γ) :: [ tv ]) -]
return-when (σ T~) (σ k~)
-- T · T'
check-type Γ (ExTpApp T T') kₑ? =
Γ ⊢ T ↝ T~ ⇒ kₕ /
Γ ⊢ kₕ =β= λ where
(KdAbs x (Tkk dom) cod) →
Γ ⊢ T' ⇐ dom ↝ T'~ /
let cod' = [ Γ - T'~ / x ] cod in
[- TpApp-span (type-start-pos T) (type-end-pos T') (maybe-to-checking kₑ?)
(kind-data Γ cod' :: expected-kind-if Γ kₑ?)
(check-for-kind-mismatch-if Γ "synthesized" kₑ? cod') -]
return-when (TpAppTp T~ T'~) cod'
kₕ' →
untyped-type Γ T' >>= T'~ /
[- TpApp-span (type-start-pos T) (type-end-pos T') (maybe-to-checking kₑ?)
(head-kind Γ kₕ' :: expected-kind-if Γ kₑ?)
(unless (is-hole kₕ') $
"The synthesized kind of the head does not allow it to be applied" ^
" to a type argument") -]
return-when (TpAppTp T~ T'~) (KdHole (type-start-pos T))
-- T t
check-type Γ (ExTpAppt T t) kₑ? =
Γ ⊢ T ↝ T~ ⇒ kₕ /
Γ ⊢ kₕ =β= λ where
(KdAbs x (Tkt dom) cod) →
Γ ⊢ t ⇐ dom ↝ t~ /
let cod' = [ Γ - t~ / x ] cod in
[- TpAppt-span (type-start-pos T) (term-end-pos t) (maybe-to-checking kₑ?)
(kind-data Γ cod' :: expected-kind-if Γ kₑ?)
(check-for-kind-mismatch-if Γ "synthesized" kₑ? cod') -]
return-when (TpAppTm T~ t~) cod'
kₕ' →
untyped-term Γ t >>= t~ /
[- TpAppt-span (type-start-pos T) (term-end-pos t) (maybe-to-checking kₑ?)
(head-kind Γ kₕ' :: expected-kind-if Γ kₑ?)
(unless (is-hole kₕ') $
"The synthesized kind of the head does not allow it to be applied" ^
" to a term argument") -]
return-when (TpAppTm T~ t~) (KdHole (type-start-pos T))
-- T ➔/➾ T'
check-type Γ (ExTpArrow T e T') kₑ? =
Γ ⊢ T ⇐ KdStar ↝ T~ /
Γ ⊢ T' ⇐ KdStar ↝ T'~ /
[- TpArrow-span T T' (maybe-to-checking kₑ?)
(kind-data Γ KdStar :: expected-kind-if Γ kₑ?)
(check-for-kind-mismatch-if Γ "computed" kₑ? KdStar) -]
return-when (TpAbs e ignored-var (Tkt T~) T'~) KdStar
-- { t₁ ≃ t₂ }
check-type Γ (ExTpEq pi t₁ t₂ pi') kₑ? =
untyped-term Γ t₁ >>= t₁~ /
untyped-term Γ t₂ >>= t₂~ /
[- punctuation-span "Parens (equation)" pi pi' -]
[- TpEq-span pi pi' (maybe-to-checking kₑ?)
(kind-data Γ KdStar :: expected-kind-if Γ kₑ?)
(check-for-kind-mismatch-if Γ "computed" kₑ? KdStar) -]
return-when (TpEq t₁~ t₂~) KdStar
-- ●
check-type Γ (ExTpHole pi) kₑ? =
[- tp-hole-span Γ pi kₑ? (maybe-to-checking kₑ?) [] -]
return-when (TpHole pi) (KdHole pi)
-- λ x : tk. T
check-type Γ (ExTpLam pi pi' x tk T) kₑ? =
[- punctuation-span "Lambda (type)" pi (posinfo-plus pi 1) -]
Γ ⊢ tk ↝ tk~ /
case-ret
((Γ , pi' - x :` tk~) ⊢ T ↝ T~ ⇒ k /
let kₛ = KdAbs x tk~ (rename-var Γ (pi' % x) x k) in
[- var-span ff (Γ , pi' - x :` tk~) pi' x checking tk~ nothing -]
[- TpLambda-span Γ pi pi' x tk~ T synthesizing [ kind-data Γ kₛ ] nothing -]
return2 (TpLam x tk~ (rename-var Γ (pi' % x) x T~)) kₛ)
λ kₑ →
(Γ ⊢ kₑ =β= λ where
(KdAbs x' tk' k) →
(Γ , pi' - x :` tk~) ⊢ T ⇐ (rename-var Γ x' (pi' % x) k) ↝ T~ /
let xₙ = if x =string ignored-var && is-free-in x' k then x' else x in
return (xₙ , rename-var Γ (pi' % x) xₙ T~ , lambda-bound-conv? Γ x tk' tk~ [])
kₕ →
(Γ , pi' - x :` tk~) ⊢ T ↝ T~ ⇒ _ /
return (x , rename-var Γ (pi' % x) x T~ , [] , unless (is-hole kₕ)
"The expected kind is not an arrow- or Pi-kind")
) >>= λ where
(xₙ , T~ , tvs , e?) →
[- var-span ff (Γ , pi' - x :` tk~) pi' x checking tk~ nothing -]
[- TpLambda-span Γ pi pi' x tk~ T checking (expected-kind Γ kₑ :: tvs) e? -]
return (TpLam xₙ tk~ T~)
-- (T)
check-type Γ (ExTpParens pi T pi') kₑ? =
[- punctuation-span "Parens (type)" pi pi' -]
check-type Γ T kₑ?
-- x
check-type Γ (ExTpVar pi x) kₑ? =
maybe-else' (ctxt-lookup-type-var Γ x)
([- TpVar-span Γ pi x (maybe-to-checking kₑ?) (expected-kind-if Γ kₑ?)
(just "Undefined type variable") -]
return-when (TpVar x) (KdHole pi)) λ where
(qx , as , k) →
[- TpVar-span Γ pi x (maybe-to-checking kₑ?)
(expected-kind-if Γ kₑ? ++ [ kind-data Γ k ])
(check-for-kind-mismatch-if Γ "computed" kₑ? k) -]
return-when (apps-type (TpVar qx) as) k
-- Π x : tk. k
check-kind Γ (ExKdAbs pi pi' x tk k) =
Γ ⊢ tk ↝ tk~ /
Γ , pi' - x :` tk~ ⊢ k ↝ k~ /
[- KdAbs-span Γ pi pi' x tk~ k checking nothing -]
[- var-span ff Γ pi' x checking tk~ nothing -]
[- punctuation-span "Pi (kind)" pi (posinfo-plus pi 1) -]
return (KdAbs x tk~ (rename-var Γ (pi' % x) x k~))
-- tk ➔ k
check-kind Γ (ExKdArrow tk k) =
Γ ⊢ tk ↝ tk~ /
Γ ⊢ k ↝ k~ /
[- KdArrow-span tk k checking nothing -]
return (KdAbs ignored-var tk~ k~)
-- ●
check-kind Γ (ExKdHole pi) =
[- kd-hole-span pi checking -]
return (KdHole pi)
-- (k)
check-kind Γ (ExKdParens pi k pi') =
[- punctuation-span "Parens (kind)" pi pi' -]
check-kind Γ k
-- ★
check-kind Γ (ExKdStar pi) =
[- Star-span pi checking nothing -]
return KdStar
-- κ as...
check-kind Γ (ExKdVar pi κ as) =
case ctxt-lookup-kind-var-def Γ κ of λ where
nothing →
[- KdVar-span Γ (pi , κ) (args-end-pos (posinfo-plus-str pi κ) as)
[] checking [] (just "Undefined kind variable") -]
return (KdHole pi)
(just (ps , k)) →
check-args Γ as ps >>= λ as~ →
[- KdVar-span Γ (pi , κ) (args-end-pos (posinfo-plus-str pi κ) as)
ps checking (params-data Γ ps)
(when (length as < length ps)
("Needed " ^ ℕ-to-string (length ps ∸ length as)
^ " further argument(s)")) -]
return (fst (subst-params-args' Γ ps as~ k))
check-tpkd Γ (ExTkt T) = Tkt <$> check-type Γ T (just KdStar)
check-tpkd Γ (ExTkk k) = Tkk <$> check-kind Γ k
check-args Γ (ExTmArg me t :: as) (Param me' x (Tkt T) :: ps) =
Γ ⊢ t ⇐ T ↝ t~ /
let e-s = mk-span "Argument" (term-start-pos t) (term-end-pos t)
[ expected-type Γ T ] (just "Mismatched argument erasure")
e-m = λ r → if me iff me' then return {F = spanM} r else ([- e-s -] return {F = spanM} r) in
check-args Γ as (subst-params Γ t~ x ps) >>= λ as~ →
e-m ((if me then inj₂ (inj₁ t~) else inj₁ t~) :: as~)
check-args Γ (ExTpArg T :: as) (Param _ x (Tkk k) :: ps) =
Γ ⊢ T ⇐ k ↝ T~ /
check-args Γ as (subst-params Γ T~ x ps) >>= λ as~ →
return (inj₂ (inj₂ T~) :: as~)
check-args Γ (ExTmArg me t :: as) (Param _ x (Tkk k) :: ps) =
[- mk-span "Argument" (term-start-pos t) (term-end-pos t) [ expected-kind Γ k ]
(just "Expected a type argument") -]
return []
check-args Γ (ExTpArg T :: as) (Param me x (Tkt T') :: ps) =
[- mk-span "Argument" (type-start-pos T) (type-end-pos T) [ expected-type Γ T' ]
(just ("Expected a" ^ (if me then "n erased" else "") ^ " term argument")) -]
return []
check-args Γ (a :: as) [] =
let range = case a of λ {(ExTmArg me t) → term-start-pos t , term-end-pos t;
(ExTpArg T) → type-start-pos T , type-end-pos T} in
check-args Γ as [] >>= λ as~ →
[- mk-span "Argument" (fst range) (snd range) [] (just "Too many arguments given") -]
return []
check-args Γ [] _ = return []
check-erased-margs : ctxt → posinfo → posinfo → term → maybe type → spanM ⊤
check-erased-margs Γ pi pi' t T? =
let psₑ = foldr (λ {(Param me x tk) psₑ → if me then x :: psₑ else psₑ}) [] (ctxt.ps Γ)
fvs = free-vars (erase t)
e = list-any (stringset-contains fvs) psₑ in
if e then spanM-add (erased-marg-span Γ pi pi' T?) else spanMok
check-let Γ (ExDefTerm pi x (just Tₑ) t) e? fm to =
Γ ⊢ Tₑ ⇐ KdStar ↝ Tₑ~ /
Γ ⊢ t ⇐ Tₑ~ ↝ t~ /
elim-pair (compileFail-in Γ t~) λ tvs e →
[- Var-span (Γ , pi - x :` Tkt Tₑ~) pi x checking (type-data Γ Tₑ~ :: tvs) e -]
return
(ctxt-term-def pi localScope opacity-open x (just t~) Tₑ~ Γ ,
pi % x ,
binder-data Γ pi x (Tkt Tₑ~) e? (just t~) fm to ,
(λ {ed} T' → [ Γ - t~ / (pi % x) ] T') ,
(λ t' → LetTm (e? || ~ is-free-in (pi % x) (erase t')) x nothing t~
([ Γ - Var x / (pi % x) ] t')))
check-let Γ (ExDefTerm pi x nothing t) e? fm to =
Γ ⊢ t ↝ t~ ⇒ Tₛ~ /
elim-pair (compileFail-in Γ t~) λ tvs e →
let Γ' = ctxt-term-def pi localScope opacity-open x (just t~) Tₛ~ Γ in
[- Var-span Γ' pi x synthesizing (type-data Γ Tₛ~ :: tvs) e -]
return
(Γ' ,
pi % x ,
binder-data Γ pi x (Tkt Tₛ~) e? (just t~) fm to ,
(λ {ed} T' → [ Γ - t~ / (pi % x) ] T') ,
(λ t' → LetTm (e? || ~ is-free-in (pi % x) (erase t')) x nothing t~
([ Γ - Var x / (pi % x) ] t')))
check-let Γ (ExDefType pi x k T) e? fm to =
Γ ⊢ k ↝ k~ /
Γ ⊢ T ⇐ k~ ↝ T~ /
[- TpVar-span (Γ , pi - x :` Tkk k~) pi x checking [ kind-data Γ k~ ] nothing -]
return
(ctxt-type-def pi localScope opacity-open x (just T~) k~ Γ ,
pi % x ,
binder-data Γ pi x (Tkk k~) e? (just T~) fm to ,
(λ {ed} T' → [ Γ - T~ / (pi % x) ] T') ,
(λ t' → LetTp x k~ T~ ([ Γ - TpVar x / (pi % x) ] t')))
check-case Γ (ExCase pi x cas t) es Dₓ cs ρₒ as dps Tₘ cast-tm cast-tp =
[- pattern-span pi x cas -]
maybe-else'
(trie-lookup (ctxt.qual Γ) x >>= uncurry λ x' _ →
trie-lookup cs x' >>= λ T →
just (x' , T))
(let e = maybe-else' (trie-lookup es x)
("This is not a constructor of " ^
unqual-local (unqual-all (ctxt.qual Γ) Dₓ))
λ _ → "This case is unreachable" in
[- pattern-ctr-span Γ pi x [] [] (just e) -]
return2 (Case x [] (Hole pi) []) cs)
λ where
(x' , Tₕ , ps , is) →
decl-args Γ cas ps empty-trie ρₒ [] (const spanMok) >>= λ where
(Γ' , cas' , e , σ , ρ , tvs , sm) →
let rs = tmtps-to-args' Γ' σ (drop dps is)
Tₘ' = TpAppTm (apps-type Tₘ rs)
(app-caseArgs (cast-tm Γ') (cast-tp Γ') (recompose-apps as (Var x')) (zip cas cas'))
Tₘ' = hnf Γ' unfold-no-defs Tₘ' in
Γ' ⊢ t ⇐ Tₘ' ↝ t~ /
sm t~ >>
[- pattern-clause-span pi t (reverse tvs) -]
[- pattern-ctr-span Γ' pi x cas' [] e -]
return2 (Case x'
(subst-case-args cas' Γ ρₒ)
(subst-renamectxt Γ ρ t~)
(args-to-tmtps (as ++ (subst-renamectxt Γ ρ -arg_ <$> rs))))
(trie-remove cs x')
where
subst-case-args : case-args → ctxt → renamectxt → case-args
subst-case-args [] Γ ρ = []
subst-case-args (CaseArg e x tk? :: cs) Γ ρ =
CaseArg e x (subst-renamectxt Γ ρ -tk_ <$> tk?) ::
subst-case-args cs (ctxt-var-decl x Γ) (renamectxt-insert ρ x x)
free-in-term : var → term → err-m
free-in-term x t = when (is-free-in x (erase t))
"Erased argument occurs free in the body of the term"
tmtp-to-arg' : ctxt → trie (Σi exprd ⟦_⟧) → tmtp → arg
tmtp-to-arg' = λ Γ σ → either-else (Arg ∘ substs Γ σ) (ArgTp ∘ substs Γ σ)
tmtps-to-args' : ctxt → trie (Σi exprd ⟦_⟧) → 𝕃 tmtp → args
tmtps-to-args' = λ Γ σ → tmtp-to-arg' Γ σ <$>_
app-caseArgs : (term → type → term) → (type → kind → type) → term → 𝕃 (ex-case-arg × case-arg) → term
app-caseArgs tf Tf = foldl λ where
(ExCaseArg _ pi x , CaseArg me _ tk?) t → elim-pair (me , tk?) λ where
tt (just (Tkt T)) → AppEr t (tf (Var (pi % x)) T)
tt (just (Tkk k)) → AppTp t (Tf (TpVar (pi % x)) k)
ff (just (Tkt T)) → App t (tf (Var (pi % x)) T)
_ _ → t
spos = term-start-pos t
epos = term-end-pos t
add-case-arg : ∀ {X Y} → ctxt → var → var → case-arg → spanM (X × case-args × Y) → spanM (X × case-args × Y)
add-case-arg Γ x xₙ ca m = m >>=c λ X → return2 X ∘ map-fst λ cas → ca :: subst-case-args cas Γ (renamectxt-single x xₙ)
decl-args : ctxt → ex-case-args → params → trie (Σi exprd ⟦_⟧) →
renamectxt → 𝕃 tagged-val → (term → spanM ⊤) →
spanM (ctxt × case-args × err-m × trie (Σi exprd ⟦_⟧) ×
renamectxt × 𝕃 tagged-val × (term → spanM ⊤))
decl-args Γ (ExCaseArg ExCaseArgTp pi x :: as) (Param me x' (Tkt T) :: ps) σ ρ xs sm =
let T' = substs Γ σ T
Γ' = ctxt-var-decl-loc pi x Γ
xₙ = if x =string ignored-var then x' else x in
add-case-arg Γ' (pi % x) xₙ (CaseArg tt xₙ (just (Tkt T'))) $
decl-args Γ' as ps
(trie-insert σ x' (, TpVar (pi % x)))
(renamectxt-insert ρ (pi % x) xₙ)
(binder-data Γ' pi x (Tkt T') Erased nothing spos epos :: xs)
λ t → [- TpVar-span Γ' pi x checking [ expected-type Γ T' ]
(just ("This type argument should be a" ^
(if me then "n erased term" else " term"))) -] sm t
decl-args Γ (ExCaseArg ExCaseArgTp pi x :: as) (Param _ x' (Tkk k) :: ps) σ ρ xs sm =
let k' = substs Γ σ k
Γ' = ctxt-type-decl pi x k' Γ
xₙ = if x =string ignored-var then x' else x in
add-case-arg Γ' (pi % x) xₙ (CaseArg tt xₙ (just (Tkk k'))) $
decl-args Γ' as ps
(trie-insert σ x' (, TpVar (pi % x)))
(renamectxt-insert ρ (pi % x) xₙ)
(binder-data Γ' pi x (Tkk k') Erased nothing spos epos :: xs)
λ t → [- TpVar-span Γ' pi x checking [ kind-data Γ k' ] (free-in-term x t) -] sm t
decl-args Γ (ExCaseArg me pi x :: as) (Param me' x' (Tkt T) :: ps) σ ρ xs sm =
let T' = substs Γ σ T
e₁ = when (ex-case-arg-erased me xor me') "Mismatched erasure of term argument"
e₂ = λ t → ifMaybe (ex-case-arg-erased me) $ free-in-term x t
Γ' = Γ , pi - x :` (Tkt T')
xₙ = if x =string ignored-var then x' else x in
(add-case-arg Γ' (pi % x) xₙ (CaseArg me' xₙ (just (Tkt T'))) $
decl-args Γ' as ps
(trie-insert σ x' (, Var (pi % x)))
(renamectxt-insert ρ (pi % x) xₙ)
(binder-data Γ' pi x (Tkt T') (ex-case-arg-erased me) nothing spos epos :: xs)
λ t → [- Var-span Γ' pi x checking [ type-data Γ T' ] (e₁ ||-maybe e₂ t) -] sm t)
decl-args Γ (ExCaseArg me pi x :: as) (Param me' x' (Tkk k) :: ps) σ ρ xs sm =
let k' = substs Γ σ k
Γ' = ctxt-var-decl-loc pi x Γ
xₙ = if x =string ignored-var then x' else x in
add-case-arg Γ' (pi % x) xₙ (CaseArg tt xₙ (just (Tkk k'))) $
decl-args Γ' as ps
(trie-insert σ x' (, Var (pi % x)))
(renamectxt-insert ρ (pi % x) xₙ)
(binder-data Γ' pi x (Tkk k') (ex-case-arg-erased me) nothing spos epos :: xs)
λ t → [- Var-span Γ' pi x checking [ expected-kind Γ k' ]
(just "This term argument should be a type") -] sm t
decl-args Γ [] [] σ ρ xs sm =
return (Γ , [] , nothing , σ , ρ , xs , sm)
decl-args Γ as [] σ ρ xs sm =
return (Γ , [] , just (ℕ-to-string (length as) ^ " too many arguments supplied") ,
σ , ρ , xs , sm)
decl-args Γ [] ps σ ρ xs sm =
return (Γ , params-to-case-args (substs-params Γ σ ps) ,
just (ℕ-to-string (length ps) ^ " more arguments expected") , σ , ρ , xs , sm)
check-cases Γ ms Dₓ cs ρ as dps Tₘ cast-tm cast-tp =
foldr {B = stringset → trie (type × params × 𝕃 tmtp) →
spanM (cases × trie (type × params × 𝕃 tmtp))}
(λ m x es cs' →
check-case Γ m es Dₓ cs' ρ as dps Tₘ cast-tm cast-tp >>=c λ m~ cs →
x (stringset-insert es (ex-case-ctr m)) cs >>=c λ ms~ →
return2 (m~ :: ms~))
(λ es → return2 [])
ms
empty-stringset
(trie-map (decompose-ctr-type Γ) cs)
>>=c λ ms~ missing-cases →
let xs = map (map-snd snd) $ trie-mappings missing-cases
csf = uncurry₂ λ Tₕ ps as →
rope-to-string $ strRun Γ $
strVar (unqual-all (ctxt.qual Γ) Tₕ) >>str args-to-string (params-to-args ps)
e = "Missing patterns: " ^ 𝕃-to-string csf ", " xs in
return2 ms~ (unless (iszero (length xs)) e)
check-refinement Γ Tₘ kₘ s =
check-type (qualified-ctxt Γ) (resugar Tₘ) (just kₘ) empty-spans >>= uncurry λ Tₘ' s' →
return $ (λ x → x , s) $
Tₘ' ,
[ to-string-tag "computed motive" Γ Tₘ ] ,
(when (spans-have-error s') "We could not compute a well-kinded motive")
get-datatype-info-from-head-type Γ X as = return $ maybe-else' (data-lookup Γ X as)
(inj₁ $ "The head type of the subterm is not a datatype" , [ head-type Γ (TpVar X) ])
(λ μ → inj₂ μ)
check-sigma-evidence Γ tₑ? X as = maybe-else' tₑ?
(get-datatype-info-from-head-type Γ X as >>=s λ d → return $ inj₂ (sigma-build-evidence X d , id , d))
(λ tₑ →
Γ ⊢ tₑ ↝ tₑ~ ⇒ T /
let ev-err = inj₁ $
("The synthesized type of the evidence does not prove " ^
unqual-local (unqual-all (ctxt.qual Γ) X) ^ " is a datatype") ,
[ to-string-tag "evidence type" Γ T ] in
case decompose-tpapps (hnf Γ unfold-head-elab T) of λ where
(TpVar X' , as') → case reverse as' of λ where
(Ttp T :: as') → return $ if ~ conv-type Γ T (TpVar X)
then ev-err
else maybe-else
ev-err
(λ {d@(mk-data-info X Xₒ asₚ asᵢ mps kᵢ k cs csₚₛ eds gds) →
inj₂ (tₑ~ , (App $ recompose-apps (asₚ ++ tmtps-to-args Erased asᵢ) $
Var $ data-to/ X) , d)})
-- AS: it looks like we are reversing as' twice, so not reversing at all?
(data-lookup-mu Γ X X' $ reverse as' ++ as)
-- TODO: Make sure "X" isn't a _defined_ type, but a _declared_ one!
-- This way we avoid the possibility that "as" has arguments
-- to parameters in it, but only to indices.
-- Also TODO: Make sure that parameters are equal in above conversion check!
_ → return ev-err
_ → return ev-err
)
ctxt-mu-decls : ctxt → term → indices → type → datatype-info → posinfo → posinfo → posinfo → var → (cases → spanM ⊤) × ctxt × 𝕃 tagged-val × renamectxt × (ctxt → term → type → term) × (ctxt → type → kind → type)
ctxt-mu-decls Γ t is Tₘ (mk-data-info X Xₒ asₚ asᵢ ps kᵢ k cs csₚₛ eds gds) pi₁ pi₂ pi₃ x =
let X' = mu-Type/ x
xₘᵤ = mu-isType/ x
qXₘᵤ = data-Is/ X
qXₜₒ = data-to/ X
qX' = pi₁ % X'
qxₘᵤ = pi₁ % xₘᵤ
qx = pi₁ % x
Tₘᵤ = TpAppTp (flip apps-type asₚ $ TpVar qXₘᵤ) $ TpVar qX'
Γ' = ctxt-term-def pi₁ localScope opacity-open xₘᵤ nothing Tₘᵤ $
ctxt-datatype-decl X qx asₚ $
ctxt-type-decl pi₁ X' k Γ
freshₓ = fresh-var (add-indices-to-ctxt is Γ') (maybe-else "x" id (is-var (Ttm t)))
Tₓ = hnf Γ' unfold-no-defs (indices-to-alls is $ TpAbs ff freshₓ (Tkt $ indices-to-tpapps is $ TpVar qX') $ TpAppTm (indices-to-tpapps is Tₘ) $ Phi (Beta (Var freshₓ) (Var freshₓ)) (App (indices-to-apps is $ AppEr (AppTp (flip apps-term asₚ $ Var qXₜₒ) $ TpVar qX') $ Var qxₘᵤ) $ Var freshₓ) (Var freshₓ))
Γ'' = ctxt-term-decl pi₁ x Tₓ Γ'
e₂? = unless (X =string Xₒ) "Abstract datatypes can only be pattern matched by σ"
e₃ = λ x → just $ x ^ " occurs free in the erasure of the body (not allowed)"
cs-fvs = stringset-contains ∘' free-vars-cases ∘' erase-cases
e₃ₓ? = λ cs x → ifMaybe (cs-fvs cs x) $ e₃ x
e₃? = λ cs → e₃ₓ? cs (mu-isType/ x) ||-maybe e₃ₓ? cs (mu-Type/ x) in
(λ cs → [- var-span NotErased Γ'' pi₁ x checking (Tkt Tₓ) (e₂? ||-maybe e₃? cs) -] spanMok) ,
Γ'' ,
(binder-data Γ'' pi₁ X' (Tkk k) Erased nothing pi₂ pi₃ ::
binder-data Γ'' pi₁ xₘᵤ (Tkt Tₘᵤ) Erased nothing pi₂ pi₃ ::
binder-data Γ'' pi₁ x (Tkt Tₓ) NotErased nothing pi₂ pi₃ ::
to-string-tag X' Γ'' k ::
to-string-tag xₘᵤ Γ'' Tₘᵤ ::
to-string-tag x Γ'' Tₓ :: []) ,
renamectxt-insert* empty-renamectxt
((qX' , X') :: (qxₘᵤ , xₘᵤ) :: (qx , x) :: []) ,
let cg = qX' , recompose-tpapps (args-to-tmtps asₚ) (TpVar qx) , AppEr (AppTp (recompose-apps asₚ (Var qXₜₒ)) (TpVar qX')) (Var qxₘᵤ) in
flip (mk-ctr-fmap-η? ff ∘ ctxt-datatype-undef qX') cg ,
flip (mk-ctr-fmapₖ-η? ff ∘ ctxt-datatype-undef qX') cg
check-mu Γ pi pi' x t Tₘ? pi'' cs pi''' Tₑ? =
check-term Γ t nothing >>=c λ t~ T →
let no-motive-err = just "A motive is required when synthesizing"
no-motive = return (nothing , [] , no-motive-err) in
case decompose-tpapps (hnf Γ unfold-head-elab T) of λ where
(TpVar X , as) →
get-datatype-info-from-head-type Γ X as on-fail
(uncurry λ e tvs → spanM-add (Mu-span Γ pi pi''' nothing (maybe-to-checking Tₑ?)
(expected-type-if Γ Tₑ? ++ tvs) $ just e) >>
return-when {m = Tₑ?} (Hole pi) (TpHole pi))
>>=s λ where
(d @ (mk-data-info Xₒ _ asₚ asᵢ ps kᵢ k cs' csₚₛ eds gds)) →
let Rₓ = mu-Type/ x; qRₓ = pi' % Rₓ
Γₘ = data-highlight (ctxt-type-decl pi' Rₓ k Γ) qRₓ
ρₘ = subst Γₘ (recompose-tpapps (args-to-tmtps asₚ) (TpVar Xₒ)) qRₓ
ρₘ' = subst Γₘ (TpVar Rₓ) qRₓ
eₘ = λ Tₘ → when (negₒ (extract-pos (positivity.type+ qRₓ Γₘ (hnf-ctr Γₘ qRₓ Tₘ))))
(Rₓ ^ " occurs negatively in the motive")
in
maybe-map (λ Tₘ → check-type Γₘ Tₘ (just kᵢ)) Tₘ? >>=? λ Tₘ?' →
let is = kind-to-indices Γ kᵢ
eₘ = Tₘ?' >>= eₘ
ret-tp = λ ps as t → maybe-else' Tₘ?' Tₑ? (λ Tₘ → just $ hnf Γ unfold-head-elab (TpAppTm (apps-type (ρₘ Tₘ) $
tmtps-to-args NotErased (drop (length ps) as)) t)) in
(maybe-else' Tₘ?'
(return Tₑ? on-fail no-motive >>=m λ Tₑ →
let Tₘ = refine-motive Γ is (asᵢ ++ [ Ttm t~ ]) Tₑ in
check-refinement Γ Tₘ kᵢ >>=c λ Tₘ → return2 (just Tₘ))
λ Tₘ → return (just Tₘ , [] , nothing))
>>=c λ Tₘ → uncurry λ tvs₁ e₁ →
let Tₘ = maybe-else' Tₘ (TpHole pi) id
is = drop-last 1 is
reduce-cs = map λ {(Ctr x T) → Ctr x $ hnf Γ unfold-no-defs T}
fcs = λ y → inst-ctrs Γ ps asₚ (map-snd (rename-var {TYPE} Γ Xₒ y) <$> cs')
cs' = reduce-cs $ fcs (mu-Type/ (pi' % x)) in
case
(ctxt-mu-decls Γ t~ is Tₘ d pi' pi'' pi''' x) of λ where
(sm , Γ' , bds , ρ , cast-tm , cast-tp) →
let cs'' = foldl (λ {(Ctr x T) σ → trie-insert σ x T}) empty-trie cs'
drop-ps = 0
scrutinee = t~
Tᵣ = ret-tp ps (args-to-tmtps asₚ ++ asᵢ) scrutinee in
check-cases Γ' cs Xₒ cs'' ρ asₚ drop-ps Tₘ cast-tm cast-tp >>=c λ cs~ e₂ →
let e₃ = maybe-else' Tᵣ
(just "A motive is required when synthesizing")
(check-for-type-mismatch-if Γ "synthesized" Tₑ?) in
[- Mu-span Γ pi pi''' Tₘ?' (maybe-to-checking Tₑ?)
(expected-type-if Γ Tₑ? ++
maybe-else' Tᵣ [] (λ Tᵣ → [ type-data Γ Tᵣ ]) ++
tvs₁ ++
bds)
(e₁ ||-maybe (e₂ ||-maybe (e₃ ||-maybe eₘ))) -]
sm cs~ >>
return-when {m = Tₑ?}
(subst-renamectxt Γ ρ (Mu x t~ (just (ρₘ' Tₘ)) d cs~))
(maybe-else' Tᵣ (TpHole pi) id)
(Tₕ , as) →
[- Mu-span Γ pi pi''' nothing (maybe-to-checking Tₑ?)
[ head-type Γ Tₕ ] (just "The head type of the subterm is not a datatype") -]
return-when {m = Tₑ?} (Hole pi) (TpHole pi)
check-sigma Γ pi t? t Tₘ? pi'' cs pi''' Tₑ? =
check-term Γ t nothing >>=c λ t~ T →
let no-motive-err = just "A motive is required when synthesizing"
no-motive = return (nothing , [] , no-motive-err) in
case decompose-tpapps (hnf Γ unfold-head-elab T) of λ where
(TpVar X , as) →
check-sigma-evidence Γ t? X as on-fail
(uncurry λ e tvs → spanM-add (Sigma-span Γ pi pi''' nothing (maybe-to-checking Tₑ?)
(expected-type-if Γ Tₑ? ++ tvs) $ just e) >>
return-when {m = Tₑ?} (Hole pi) (TpHole pi))
>>=s λ where
(tₑ~ , cast , d @ (mk-data-info Xₒ _ asₚ asᵢ ps kᵢ k cs' csₚₛ eds gds)) →
maybe-map (λ Tₘ → check-type Γ Tₘ (just kᵢ)) Tₘ? >>=? λ Tₘ?' →
let is = kind-to-indices Γ kᵢ
ret-tp = λ ps as t → maybe-else' Tₘ?' Tₑ? (λ Tₘ → just $ hnf Γ unfold-head-elab (TpAppTm (apps-type Tₘ $
tmtps-to-args NotErased (drop (length ps) as)) t)) in
(maybe-else' Tₘ?'
(return Tₑ? on-fail no-motive >>=m λ Tₑ →
let Tₘ = refine-motive Γ is (asᵢ ++ [ Ttm t~ ]) Tₑ in
check-refinement Γ Tₘ kᵢ >>=c λ Tₘ → return2 (just Tₘ))
λ Tₘ → return (just Tₘ , [] , nothing))
>>=c λ Tₘ → uncurry λ tvs₁ e₁ →
let Tₘ = maybe-else' Tₘ (TpHole pi) id
reduce-cs = map λ {(Ctr x T) → Ctr x $ hnf Γ unfold-no-defs T}
fcs = λ y → inst-ctrs Γ ps asₚ (map-snd (rename-var {TYPE} Γ Xₒ y) <$> cs')
cs' = reduce-cs $ if Xₒ =string X then csₚₛ else fcs X in
let sm = const spanMok
ρ = empty-renamectxt
cast-tm = (λ Γ t T → t)
cast-tp = (λ Γ T k → T)
cs'' = foldl (λ {(Ctr x T) σ → trie-insert σ x T}) empty-trie cs'
drop-ps = maybe-else 0 length (when (Xₒ =string X) ps)
scrutinee = cast t~
Tᵣ = ret-tp ps (args-to-tmtps asₚ ++ asᵢ) scrutinee in
check-cases Γ cs Xₒ cs'' ρ asₚ drop-ps Tₘ cast-tm cast-tp >>=c λ cs~ e₂ →
let e₃ = maybe-else' Tᵣ
(just "A motive is required when synthesizing")
(check-for-type-mismatch-if Γ "synthesized" Tₑ?) in
[- Sigma-span Γ pi pi''' Tₘ?' (maybe-to-checking Tₑ?)
(expected-type-if Γ Tₑ? ++
maybe-else' Tᵣ [] (λ Tᵣ → [ type-data Γ Tᵣ ]) ++
tvs₁)
(e₁ ||-maybe (e₂ ||-maybe e₃)) -]
sm cs~ >>
return-when {m = Tₑ?}
(subst-renamectxt Γ ρ (Sigma (just tₑ~) t~ (just Tₘ) d cs~))
(maybe-else' Tᵣ (TpHole pi) id)
(Tₕ , as) →
[- Sigma-span Γ pi pi''' nothing (maybe-to-checking Tₑ?)
[ head-type Γ Tₕ ] (just "The head type of the subterm is not a datatype") -]
return-when {m = Tₑ?} (Hole pi) (TpHole pi)
|
{
"alphanum_fraction": 0.5208341276,
"avg_line_length": 46.9248658318,
"ext": "agda",
"hexsha": "6a9c02c43dcb960d3e658ba4926d7d74b7755793",
"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": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ice1k/cedille",
"max_forks_repo_path": "src/classify.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"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": "ice1k/cedille",
"max_issues_repo_path": "src/classify.agda",
"max_line_length": 311,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ice1k/cedille",
"max_stars_repo_path": "src/classify.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 19348,
"size": 52462
}
|
{-# OPTIONS --type-in-type #-}
module poly.core where
open import functors
open import prelude
_^ : Set → Set -- Presheaf
I ^ = I → Set
∫ : Set -- Arena
∫ = ∃ _^
_⦅_⦆ : ∫ → Set → Set -- Interpret as a polynomial functor
(A⁺ , A⁻) ⦅ y ⦆ = Σ[ a⁺ ∈ A⁺ ] (A⁻ a⁺ → y)
module _ (A@(A⁺ , A⁻) B@(B⁺ , B⁻) : ∫) where
∫[_,_] : Set
∫[_,_] = (a⁺ : A⁺) → Σ[ b⁺ ∈ B⁺ ] (B⁻ b⁺ → A⁻ a⁺)
module _ {A@(A⁺ , A⁻) B@(B⁺ , B⁻) : ∫} where
lens : (get : A⁺ → B⁺)
(set : (a⁺ : A⁺) → B⁻ (get a⁺) → A⁻ a⁺)
→ ∫[ A , B ]
lens g s = λ a⁺ → g a⁺ , s a⁺
get : (l : ∫[ A , B ]) → A⁺ → B⁺
get l = π₁ ∘ l
set : (A↝B : ∫[ A , B ]) → (a⁺ : A⁺) → B⁻ (get A↝B a⁺) → A⁻ a⁺
set l = π₂ ∘ l
instance
lens-cat : Category ∫[_,_]
lens-cat = 𝒾: (λ a⁺ → a⁺ , id)
▸: (λ l1 l2 a⁺ → let b⁺ , setb = l1 a⁺
c⁺ , setc = l2 b⁺
in c⁺ , setb ∘ setc)
𝒾▸: (λ _ → refl)
▸𝒾: (λ _ → refl)
|
{
"alphanum_fraction": 0.3661257606,
"avg_line_length": 27.3888888889,
"ext": "agda",
"hexsha": "ac32d3d28b562b32a2c5829a2d9bbcf78f4fb53d",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-30T11:45:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-07-10T17:19:37.000Z",
"max_forks_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dspivak/poly",
"max_forks_repo_path": "code-examples/agda/poly/core.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_issues_repo_issues_event_max_datetime": "2022-01-12T10:06:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-02T02:29:39.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dspivak/poly",
"max_issues_repo_path": "code-examples/agda/poly/core.agda",
"max_line_length": 64,
"max_stars_count": 53,
"max_stars_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mstone/poly",
"max_stars_repo_path": "code-examples/agda/poly/core.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T23:08:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-18T16:31:04.000Z",
"num_tokens": 502,
"size": 986
}
|
------------------------------------------------------------------------------
-- Bisimilarity relation on unbounded lists
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Relation.Binary.Bisimilarity.Type where
open import FOTC.Base
open import FOTC.Base.List
infix 4 _≈_ _≉_
------------------------------------------------------------------------------
-- The bisimilarity relation _≈_ on unbounded lists is the greatest
-- fixed-point (by ≈-out and ≈-coind) of the bisimulation functional
-- (FOTC.Relation.Binary.Bisimulation).
-- The bisimilarity relation on unbounded lists.
postulate _≈_ : D → D → Set
-- The bisimilarity relation _≈_ on unbounded lists is a post-fixed
-- point of the bisimulation functional (FOTC.Relation.Binary.Bisimulation).
postulate
≈-out : ∀ {xs ys} → xs ≈ ys →
∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ xs' ≈ ys'
{-# ATP axiom ≈-out #-}
-- The bisimilarity relation _≈_ on unbounded lists is the greatest
-- post-fixed point of the bisimulation functional (see
-- FOTC.Relation.Binary.Bisimulation).
--
-- N.B. This is an axiom schema. Because in the automatic proofs we
-- *must* use an instance, we do not add this postulate as an ATP
-- axiom.
postulate
≈-coind :
(B : D → D → Set) →
-- B is a post-fixed point of the bisimulation functional.
(∀ {xs ys} → B xs ys →
∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ B xs' ys') →
-- _≈_ is greater than B.
∀ {xs ys} → B xs ys → xs ≈ ys
------------------------------------------------------------------------------
-- Auxiliary definition.
_≉_ : D → D → Set
x ≉ y = ¬ x ≈ y
{-# ATP definition _≉_ #-}
|
{
"alphanum_fraction": 0.5138740662,
"avg_line_length": 35.358490566,
"ext": "agda",
"hexsha": "6a8f6d7a6b5286378de37e79121763e0ab3a5554",
"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/Relation/Binary/Bisimilarity/Type.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/Relation/Binary/Bisimilarity/Type.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Relation/Binary/Bisimilarity/Type.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": 515,
"size": 1874
}
|
-- Modified: Andreas, 2011-04-11 freezing metas
module Issue151 where
record A : Set₁ where
field
El : Set
data B (a : A) : Set₁ where
b : ∀ a′ → B a′ → B a
data C a : B a → B a → Set₁ where
c : ∀ a′ (p : B a′) → C a (b record{ El = A.El a′ } p) (b a′ p)
c′ : ∀ a′ (p : B a′) → C a (b a′ p) (b a′ p)
-- In order to type check the second clause the unifier
-- needs to eta contract the record in the target of the c
-- constructor.
foo : ∀ a (p : B a) (p′ : B a) → C a (b a p) p′ → Set₁
foo a p (b .a .p) (c′ .a .p) = Set
foo a p (b .a .p) (c .a .p) = Set
postulate
D : A → Set
d : (a : A) → D a
-- The following definition generates a constraint
-- α record{ El = A.El a } == D a
-- on the metavariable above. To solve this the constraint
-- solver has to eta contract the record to see that the
-- left hand side is a proper Miller pattern.
bar : (test : (a : A) -> _) -> (a : A) → D a
bar test a = test record{ El = A.El a }
|
{
"alphanum_fraction": 0.567539267,
"avg_line_length": 28.0882352941,
"ext": "agda",
"hexsha": "e1c103d5e99096dfa2c05030b1e8af813e123f6c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/succeed/Issue151.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "np/agda-git-experiment",
"max_issues_repo_path": "test/succeed/Issue151.agda",
"max_line_length": 66,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/Issue151.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": 360,
"size": 955
}
|
id : forall {k}{X : Set k} -> X -> X
id x = x
_o_ : forall {i j k}
{A : Set i}{B : A -> Set j}{C : (a : A) -> B a -> Set k} ->
(f : {a : A}(b : B a) -> C a b) ->
(g : (a : A) -> B a) ->
(a : A) -> C a (g a)
f o g = \ a -> f (g a)
data List (X : Set) : Set where
[] : List X
_,_ : X → List X → List X
data Nat : Set where
zero : Nat
suc : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
data Vec (X : Set) : Nat -> Set where
[] : Vec X 0
_,_ : { n : Nat } → X → Vec X n → Vec X (suc n)
vec : forall { n X } → X → Vec X n
vec {zero} a = []
vec {suc n} a = a , vec a
vapp : forall { n S T } → Vec (S → T) n → Vec S n → Vec T n
vapp [] [] = []
vapp (x , st) (x₁ , s) = x x₁ , vapp st s
record Applicative (F : Set → Set) : Set₁ where
infixl 2 _⊛_
field
pure : forall { X } → X → F X
_⊛_ : forall { S T } → F (S → T) → F S → F T
open Applicative {{...}} public
instance
applicativeVec : forall { n } → Applicative (λ X → Vec X n)
applicativeVec = record { pure = vec; _⊛_ = vapp }
instance
applicativeComp : forall {F G} {{_ : Applicative F}} {{_ : Applicative G}} → Applicative (F o G)
applicativeComp {{af}} {{ag}} =
record
{ pure = λ z → Applicative.pure af (Applicative.pure ag z)
; _⊛_ = λ z → {!!}
}
record Traversable (T : Set → Set) : Set1 where
field
traverse : forall { F A B } {{ AF : Applicative F }} → (A → F B) → T A → F (T B)
open Traversable {{...}} public
instance
traversableVec : forall {n} → Traversable (\X → Vec X n)
traversableVec = record { traverse = vtr } where
vtr : forall { n F A B } {{ AF : Applicative F }} → (A → F B) → Vec A n → F (Vec B n)
vtr {{AF}} f [] = Applicative.pure AF []
vtr {{AF}} f (x , v) =
Applicative._⊛_ AF (Applicative._⊛_ AF (Applicative.pure AF _,_) (f x)) (vtr f v)
|
{
"alphanum_fraction": 0.516075388,
"avg_line_length": 26.9253731343,
"ext": "agda",
"hexsha": "bb0da65225f51970fb3dabd76a89b0fcef70c69a",
"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/Issue2993.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/Issue2993.agda",
"max_line_length": 98,
"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/Issue2993.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": 699,
"size": 1804
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Relations between properties of functions, such as associativity and
-- commutativity (specialised to propositional equality)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Algebra.FunctionProperties.Consequences.Propositional
{a} {A : Set a} where
open import Data.Sum using (inj₁; inj₂)
open import Relation.Binary using (Rel; Setoid; Symmetric; Total)
open import Relation.Binary.PropositionalEquality
open import Relation.Unary using (Pred)
open import Algebra.FunctionProperties {A = A} _≡_
import Algebra.FunctionProperties.Consequences (setoid A) as FP⇒
------------------------------------------------------------------------
-- Re-export all proofs that don't require congruence or substitutivity
open FP⇒ public
hiding
( assoc+distribʳ+idʳ+invʳ⇒zeˡ
; assoc+distribˡ+idʳ+invʳ⇒zeʳ
; assoc+id+invʳ⇒invˡ-unique
; assoc+id+invˡ⇒invʳ-unique
; comm+distrˡ⇒distrʳ
; comm+distrʳ⇒distrˡ
; comm⇒sym[distribˡ]
; subst+comm⇒sym
; wlog
; sel⇒idem
)
------------------------------------------------------------------------
-- Group-like structures
module _ {_•_ _⁻¹ ε} where
assoc+id+invʳ⇒invˡ-unique : Associative _•_ → Identity ε _•_ →
RightInverse ε _⁻¹ _•_ →
∀ x y → (x • y) ≡ ε → x ≡ (y ⁻¹)
assoc+id+invʳ⇒invˡ-unique = FP⇒.assoc+id+invʳ⇒invˡ-unique (cong₂ _)
assoc+id+invˡ⇒invʳ-unique : Associative _•_ → Identity ε _•_ →
LeftInverse ε _⁻¹ _•_ →
∀ x y → (x • y) ≡ ε → y ≡ (x ⁻¹)
assoc+id+invˡ⇒invʳ-unique = FP⇒.assoc+id+invˡ⇒invʳ-unique (cong₂ _)
------------------------------------------------------------------------
-- Ring-like structures
module _ {_+_ _*_ -_ 0#} where
assoc+distribʳ+idʳ+invʳ⇒zeˡ : Associative _+_ → _*_ DistributesOverʳ _+_ →
RightIdentity 0# _+_ → RightInverse 0# -_ _+_ →
LeftZero 0# _*_
assoc+distribʳ+idʳ+invʳ⇒zeˡ =
FP⇒.assoc+distribʳ+idʳ+invʳ⇒zeˡ (cong₂ _+_) (cong₂ _*_)
assoc+distribˡ+idʳ+invʳ⇒zeʳ : Associative _+_ → _*_ DistributesOverˡ _+_ →
RightIdentity 0# _+_ → RightInverse 0# -_ _+_ →
RightZero 0# _*_
assoc+distribˡ+idʳ+invʳ⇒zeʳ =
FP⇒.assoc+distribˡ+idʳ+invʳ⇒zeʳ (cong₂ _+_) (cong₂ _*_)
------------------------------------------------------------------------
-- Bisemigroup-like structures
module _ {_•_ _◦_ : Op₂ A} (•-comm : Commutative _•_) where
comm+distrˡ⇒distrʳ : _•_ DistributesOverˡ _◦_ → _•_ DistributesOverʳ _◦_
comm+distrˡ⇒distrʳ = FP⇒.comm+distrˡ⇒distrʳ (cong₂ _) •-comm
comm+distrʳ⇒distrˡ : _•_ DistributesOverʳ _◦_ → _•_ DistributesOverˡ _◦_
comm+distrʳ⇒distrˡ = FP⇒.comm+distrʳ⇒distrˡ (cong₂ _) •-comm
comm⇒sym[distribˡ] : ∀ x → Symmetric (λ y z → (x ◦ (y • z)) ≡ ((x ◦ y) • (x ◦ z)))
comm⇒sym[distribˡ] = FP⇒.comm⇒sym[distribˡ] (cong₂ _◦_) •-comm
------------------------------------------------------------------------
-- Selectivity
module _ {_•_ : Op₂ A} where
sel⇒idem : Selective _•_ → Idempotent _•_
sel⇒idem = FP⇒.sel⇒idem _≡_
------------------------------------------------------------------------
-- Without Loss of Generality
module _ {p} {P : Pred A p} where
subst+comm⇒sym : ∀ {f} (f-comm : Commutative f) →
Symmetric (λ a b → P (f a b))
subst+comm⇒sym = FP⇒.subst+comm⇒sym {P = P} subst
wlog : ∀ {f} (f-comm : Commutative f) →
∀ {r} {_R_ : Rel _ r} → Total _R_ →
(∀ a b → a R b → P (f a b)) →
∀ a b → P (f a b)
wlog = FP⇒.wlog {P = P} subst
|
{
"alphanum_fraction": 0.5133350937,
"avg_line_length": 35.7264150943,
"ext": "agda",
"hexsha": "f36d2ba4d8c26172da97f897977518295247ba0e",
"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/Consequences/Propositional.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/Consequences/Propositional.agda",
"max_line_length": 84,
"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/Consequences/Propositional.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1348,
"size": 3787
}
|
------------------------------------------------------------------------
-- Application of substitutions to normal and neutral terms
------------------------------------------------------------------------
open import Level using (zero)
open import Data.Universe
module README.DependentlyTyped.NormalForm.Substitution
(Uni₀ : Universe zero zero) where
open import Data.Product as Prod renaming (curry to c; uncurry to uc)
open import deBruijn.Substitution.Data
open import Function.Base as F renaming (const to k)
import README.DependentlyTyped.NormalForm as NF; open NF Uni₀
import README.DependentlyTyped.Term.Substitution as S
open S Uni₀ using (module Apply)
import README.DependentlyTyped.Term as Term; open Term Uni₀
import Relation.Binary.PropositionalEquality as P
open P.≡-Reasoning
-- Code for applying substitutions containing terms which can be
-- transformed into /neutral/ terms.
module Apply-n {T : Term-like Level.zero} (T↦Ne : T ↦ Tm-n ne) where
open _↦_ T↦Ne hiding (var)
T↦Tm : T ↦ Tm
T↦Tm = record
{ trans = forget-n [∘] trans
; simple = simple
}
open Apply T↦Tm using (_/⊢_; _/⊢t_; app)
-- Applies a substitution to an atomic type.
infixl 8 _/⊢a_
_/⊢a_ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} →
Γ ⊢ σ atomic-type → (ρ : Sub T ρ̂) → Δ ⊢ σ / ρ atomic-type
⋆ /⊢a ρ = ⋆
el /⊢a ρ = el
mutual
-- Applies a renaming to a normal or neutral term.
infixl 8 _/⊢n_ _/⊢n-lemma_
_/⊢n_ : ∀ {Γ Δ σ k} {ρ̂ : Γ ⇨̂ Δ} →
Γ ⊢ σ ⟨ k ⟩ → (ρ : Sub T ρ̂) → Δ ⊢ σ / ρ ⟨ k ⟩
ne σ′ t /⊢n ρ = ne (σ′ /⊢a ρ) (t /⊢n ρ)
var x /⊢n ρ = trans ⊙ (x /∋ ρ)
ƛ t /⊢n ρ = ƛ (t /⊢n ρ ↑)
t₁ · t₂ /⊢n ρ = [ t₁ · t₂ ]/⊢n ρ
-- The body of the last case above. (At the time of writing the
-- termination checker complains if [ t₁ · t₂ ]/⊢n ρ is replaced
-- by t₁ · t₂ /⊢n ρ in the type signature of ·-/⊢n below.)
[_·_]/⊢n :
∀ {Γ Δ sp₁ sp₂ σ} {ρ̂ : Γ ⇨̂ Δ}
(t₁ : Γ ⊢ π sp₁ sp₂ , σ ⟨ ne ⟩) (t₂ : Γ ⊢ fst σ ⟨ no ⟩)
(ρ : Sub T ρ̂) →
Δ ⊢ snd σ /̂ ŝub ⟦ t₂ ⟧n /̂ ρ̂ ⟨ ne ⟩
[_·_]/⊢n {σ = σ} t₁ t₂ ρ =
P.subst (λ v → _ ⊢ snd σ /̂ ⟦ ρ ⟧⇨ ↑̂ /̂ ŝub v ⟨ ne ⟩)
(≅-Value-⇒-≡ $ P.sym (t₂ /⊢n-lemma ρ))
((t₁ /⊢n ρ) · (t₂ /⊢n ρ))
abstract
-- An unfolding lemma.
·-/⊢n :
∀ {Γ Δ sp₁ sp₂ σ} {ρ̂ : Γ ⇨̂ Δ}
(t₁ : Γ ⊢ π sp₁ sp₂ , σ ⟨ ne ⟩) (t₂ : Γ ⊢ fst σ ⟨ no ⟩)
(ρ : Sub T ρ̂) →
[ t₁ · t₂ ]/⊢n ρ ≅-⊢n (t₁ /⊢n ρ) · (t₂ /⊢n ρ)
·-/⊢n {σ = σ} t₁ t₂ ρ =
drop-subst-⊢n (λ v → snd σ /̂ ⟦ ρ ⟧⇨ ↑̂ /̂ ŝub v)
(≅-Value-⇒-≡ $ P.sym $ t₂ /⊢n-lemma ρ)
-- The application operation is well-behaved.
_/⊢n-lemma_ : ∀ {Γ Δ σ k} {ρ̂ : Γ ⇨̂ Δ}
(t : Γ ⊢ σ ⟨ k ⟩) (ρ : Sub T ρ̂) →
⟦ t ⟧n /Val ρ ≅-Value ⟦ t /⊢n ρ ⟧n
ne σ′ t /⊢n-lemma ρ = begin
[ ⟦ t ⟧n /Val ρ ] ≡⟨ t /⊢n-lemma ρ ⟩
[ ⟦ t /⊢n ρ ⟧n ] ∎
var x /⊢n-lemma ρ = /̂∋-⟦⟧⇨ x ρ
ƛ t /⊢n-lemma ρ = begin
[ c ⟦ t ⟧n /Val ρ ] ≡⟨ P.refl ⟩
[ c (⟦ t ⟧n /Val ρ ↑) ] ≡⟨ curry-cong (t /⊢n-lemma (ρ ↑)) ⟩
[ c ⟦ t /⊢n ρ ↑ ⟧n ] ∎
t₁ · t₂ /⊢n-lemma ρ = begin
[ ⟦ t₁ · t₂ ⟧n /Val ρ ] ≡⟨ P.refl ⟩
[ (⟦ t₁ ⟧n /Val ρ) ˢ (⟦ t₂ ⟧n /Val ρ) ] ≡⟨ ˢ-cong (t₁ /⊢n-lemma ρ) (t₂ /⊢n-lemma ρ) ⟩
[ ⟦ t₁ /⊢n ρ ⟧n ˢ ⟦ t₂ /⊢n ρ ⟧n ] ≡⟨ P.refl ⟩
[ ⟦ (t₁ /⊢n ρ) · (t₂ /⊢n ρ) ⟧n ] ≡⟨ ⟦⟧n-cong (P.sym $ ·-/⊢n t₁ t₂ ρ) ⟩
[ ⟦ t₁ · t₂ /⊢n ρ ⟧n ] ∎
app-n : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → [ Tm-n ne ⟶ Tm-n ne ] ρ̂
app-n ρ = record
{ function = λ _ t → t /⊢n ρ
; corresponds = λ _ t → t /⊢n-lemma ρ
}
substitution₁-n : Substitution₁ (Tm-n ne)
substitution₁-n = record
{ var = record { function = λ _ → var
; corresponds = λ _ _ → P.refl
}
; app′ = Apply-n.app-n
; app′-var = λ _ _ _ → P.refl
}
open Substitution₁ substitution₁-n public hiding (var)
-- Let us make _/⊢n_ and friends immediately available for use with
-- /renamings/.
open Apply-n (Translation-from.translation Var-↦) public
|
{
"alphanum_fraction": 0.4672520171,
"avg_line_length": 33.1811023622,
"ext": "agda",
"hexsha": "58f4864d9c4f1a1fe1d381472b104df5b9c5c7f0",
"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/NormalForm/Substitution.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/NormalForm/Substitution.agda",
"max_line_length": 94,
"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/NormalForm/Substitution.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": 1916,
"size": 4214
}
|
-- Andreas, 2015-02-07 Failed with-abstraction in rewrite-generated with.
-- {-# OPTIONS -v tc.rewrite.top:25 -v tc.with.top:25 -v tc.with.abstract:50 #-}
{-# OPTIONS --type-in-type #-}
module Issue1420 where
open import Common.Equality
postulate
▶ : Set → Set
▷ : ▶ Set → Set
next : ∀{A} → A → ▶ A
_∗_ : ∀{A B} → ▶(A → B) → ▶ A → ▶ B
▶-def : ∀ A → ▷ (next A) ≡ ▶ A
next∗ : ∀{A B : Set} (f : A → B) (a : A) →
(next f ∗ next a) ≡ next (f a)
Name : Set
data Tm : Set where
name : Name → Tm
data R : Tm → Set where
name : ∀{x : Name} → R (name x)
print : Tm → ▶ Tm
print (name x) = next (name x)
-- Manually expanded with
test : ∀ (t : Tm) → ▷ (next R ∗ (print t))
test (name x) with next R ∗ next (name x) | next∗ R (name x)
... | ._ | refl rewrite ▶-def (R (name x)) = next name
-- Original rewrite
fails : ∀ (t : Tm) → ▷ (next R ∗ (print t))
fails (name x) rewrite next∗ R (name x) | ▶-def (R (name x)) = next name
-- should succeed
|
{
"alphanum_fraction": 0.5386178862,
"avg_line_length": 23.4285714286,
"ext": "agda",
"hexsha": "5158f9a8eb99af1cf33de6cf707d08dc888ee76d",
"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/Issue1420.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/Issue1420.agda",
"max_line_length": 80,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1420.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": 390,
"size": 984
}
|
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness #-}
module Agda.Builtin.String where
open import Agda.Builtin.Bool
open import Agda.Builtin.List
open import Agda.Builtin.Char
open import Agda.Builtin.Equality
postulate String : Set
{-# BUILTIN STRING String #-}
primitive
primStringToList : String → List Char
primStringFromList : List Char → String
primStringAppend : String → String → String
primStringEquality : String → String → Bool
primShowChar : Char → String
primShowString : String → String
primStringToListInjective : ∀ a b → primStringToList a ≡ primStringToList b → a ≡ b
{-# COMPILE JS primStringToList = function(x) { return x.split(""); } #-}
{-# COMPILE JS primStringFromList = function(x) { return x.join(""); } #-}
{-# COMPILE JS primStringAppend = function(x) { return function(y) { return x+y; }; } #-}
{-# COMPILE JS primStringEquality = function(x) { return function(y) { return x===y; }; } #-}
{-# COMPILE JS primShowChar = function(x) { return JSON.stringify(x); } #-}
{-# COMPILE JS primShowString = function(x) { return JSON.stringify(x); } #-}
|
{
"alphanum_fraction": 0.6904549509,
"avg_line_length": 40.0357142857,
"ext": "agda",
"hexsha": "5653d86eba64cf5375200bc1e8c387979620b070",
"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": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "phadej/agda",
"max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/String.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"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": "phadej/agda",
"max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/String.agda",
"max_line_length": 93,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "phadej/agda",
"max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/String.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 288,
"size": 1121
}
|
{-# OPTIONS --safe --warning=error --without-K --guardedness #-}
open import Setoids.Setoids
open import Rings.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Orders.Total.Definition
open import Groups.Definition
open import Groups.Lemmas
open import Groups.Homomorphisms.Definition
open import Fields.Fields
open import Sets.EquivalenceRelations
open import Sequences
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Functions.Definition
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
module Fields.CauchyCompletion.Group {m n o : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {_<_ : Rel {m} {o} A} {pOrder : SetoidPartialOrder S _<_} {R : Ring S _+_ _*_} {pRing : PartiallyOrderedRing R pOrder} (order : TotallyOrderedRing pRing) (F : Field R) where
open Setoid S
open SetoidTotalOrder (TotallyOrderedRing.total order)
open SetoidPartialOrder pOrder
open Equivalence eq
open TotallyOrderedRing order
open Field F
open Group (Ring.additiveGroup R)
open Ring R
open import Rings.Orders.Total.Lemmas order
open import Rings.Orders.Total.AbsoluteValue order
open import Fields.CauchyCompletion.Definition order F
open import Fields.CauchyCompletion.Addition order F
open import Fields.CauchyCompletion.Setoid order F
abstract
+CCommutative : (a b : CauchyCompletion) → Setoid._∼_ cauchyCompletionSetoid (a +C b) (b +C a)
+CCommutative a b ε 0<e = 0 , ans
where
foo : {x y : A} → (x + y) + inverse (y + x) ∼ 0G
foo = Equivalence.transitive eq (+WellDefined (Equivalence.reflexive eq) (inverseWellDefined additiveGroup groupIsAbelian)) invRight
ans : {m : ℕ} → 0 <N m → abs (index (apply _+_ (CauchyCompletion.elts (a +C b)) (map inverse (CauchyCompletion.elts (b +C a)))) m) < ε
ans {m} 0<m rewrite indexAndApply (CauchyCompletion.elts (a +C b)) (map inverse (CauchyCompletion.elts (b +C a))) _+_ {m} | indexAndApply (CauchyCompletion.elts a) (CauchyCompletion.elts b) _+_ {m} | equalityCommutative (mapAndIndex (apply _+_ (CauchyCompletion.elts b) (CauchyCompletion.elts a)) inverse m) | indexAndApply (CauchyCompletion.elts b) (CauchyCompletion.elts a) _+_ {m} = <WellDefined (Equivalence.symmetric eq (Equivalence.transitive eq (absWellDefined _ _ foo) (identityOfIndiscernablesRight _∼_ (Equivalence.reflexive eq) absZero))) (Equivalence.reflexive eq) 0<e
private
abstract
additionWellDefinedLeft : (a b c : CauchyCompletion) → Setoid._∼_ cauchyCompletionSetoid a b → Setoid._∼_ cauchyCompletionSetoid (a +C c) (b +C c)
additionWellDefinedLeft record { elts = a ; converges = aConv } record { elts = b ; converges = bConv } record { elts = c ; converges = cConv } a=b ε 0<e with a=b ε 0<e
... | Na-b , prA-b = Na-b , ans
where
ans : {m : ℕ} → Na-b <N m → abs (index (apply _+_ (apply _+_ a c) (map inverse (apply _+_ b c))) m) < ε
ans {m} mBig with prA-b {m} mBig
... | bl rewrite indexAndApply (apply _+_ a c) (map inverse (apply _+_ b c)) _+_ {m} | indexAndApply a c _+_ {m} | equalityCommutative (mapAndIndex (apply _+_ b c) inverse m) | indexAndApply b c _+_ {m} = <WellDefined (absWellDefined _ _ t) (Equivalence.reflexive eq) bl
where
t : index (apply _+_ a (map inverse b)) m ∼ ((index a m + index c m) + inverse (index b m + index c m))
t rewrite indexAndApply a (map inverse b) _+_ {m} | equalityCommutative (mapAndIndex b inverse m) = Equivalence.transitive eq (+WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.symmetric eq identLeft) (+WellDefined (Equivalence.symmetric eq invRight) (Equivalence.reflexive eq))) (Equivalence.symmetric eq +Associative)) (+WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq (invContravariant additiveGroup))))) (+Associative {index a m})
additionPreservedLeft : {a b : A} {c : CauchyCompletion} → (a ∼ b) → Setoid._∼_ cauchyCompletionSetoid (injection a +C c) (injection b +C c)
additionPreservedLeft {a} {b} {c} a=b = additionWellDefinedLeft (injection a) (injection b) c (injectionPreservesSetoid a b a=b)
additionPreservedRight : {a b : A} {c : CauchyCompletion} → (a ∼ b) → Setoid._∼_ cauchyCompletionSetoid (c +C injection a) (c +C injection b)
additionPreservedRight {a} {b} {c} a=b = Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {c +C injection a} {injection a +C c} {c +C injection b} (+CCommutative c (injection a)) (Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {injection a +C c} {injection b +C c} {c +C injection b} (additionPreservedLeft {a} {b} {c} a=b) (+CCommutative (injection b) c))
additionPreserved : {a b c d : A} → (a ∼ b) → (c ∼ d) → Setoid._∼_ cauchyCompletionSetoid (injection a +C injection c) (injection b +C injection d)
additionPreserved {a} {b} {c} {d} a=b c=d = Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {injection a +C injection c} {injection a +C injection d} {injection b +C injection d} (additionPreservedRight {c} {d} {injection a} c=d) (additionPreservedLeft {a} {b} {injection d} a=b)
additionWellDefinedRight : (a b c : CauchyCompletion) → Setoid._∼_ cauchyCompletionSetoid b c → Setoid._∼_ cauchyCompletionSetoid (a +C b) (a +C c)
additionWellDefinedRight a b c b=c = Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {a +C b} {b +C a} {a +C c} (+CCommutative a b) (Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {b +C a} {c +C a} {a +C c} (additionWellDefinedLeft b c a b=c) (+CCommutative c a))
additionWellDefined : {a b c d : CauchyCompletion} → Setoid._∼_ cauchyCompletionSetoid a b → Setoid._∼_ cauchyCompletionSetoid c d → Setoid._∼_ cauchyCompletionSetoid (a +C c) (b +C d)
additionWellDefined {a} {b} {c} {d} a=b c=d = Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {a +C c} {a +C d} {b +C d} (additionWellDefinedRight a c d c=d) (additionWellDefinedLeft a b d a=b)
additionHom : (x y : A) → Setoid._∼_ cauchyCompletionSetoid (injection (x + y)) (injection x +C injection y)
additionHom x y ε 0<e = 0 , ans
where
ans : {m : ℕ} → 0 <N m → abs (index (apply _+_ (CauchyCompletion.elts (injection (x + y))) (map inverse (CauchyCompletion.elts (injection x +C injection y)))) m) < ε
ans {m} 0<m rewrite indexAndApply (CauchyCompletion.elts (injection (x + y))) (map inverse (CauchyCompletion.elts (injection x +C injection y))) _+_ {m} | equalityCommutative (mapAndIndex (apply _+_ (constSequence x) (constSequence y)) inverse m) | indexAndConst (x + y) m | indexAndApply (constSequence x) (constSequence y) _+_ {m} | indexAndConst x m | indexAndConst y m = <WellDefined (Equivalence.symmetric eq (Equivalence.transitive eq (absWellDefined _ _ invRight) (identityOfIndiscernablesRight _∼_ (Equivalence.reflexive eq) absZero))) (Equivalence.reflexive eq) 0<e
Cassoc : {a b c : CauchyCompletion} → Setoid._∼_ cauchyCompletionSetoid (a +C (b +C c)) ((a +C b) +C c)
Cassoc {a} {b} {c} ε 0<e = 0 , ans
where
ans : {m : ℕ} → 0 <N m → abs (index (CauchyCompletion.elts ((a +C (b +C c)) +C (-C ((a +C b) +C c)))) m) < ε
ans {m} 0<m rewrite indexAndApply (CauchyCompletion.elts (a +C (b +C c))) (map inverse (CauchyCompletion.elts ((a +C b) +C c))) _+_ {m} | indexAndApply (CauchyCompletion.elts a) (apply _+_ (CauchyCompletion.elts b) (CauchyCompletion.elts c)) _+_ {m} | equalityCommutative (mapAndIndex (apply _+_ (apply _+_ (CauchyCompletion.elts a) (CauchyCompletion.elts b)) (CauchyCompletion.elts c)) inverse m) | indexAndApply (CauchyCompletion.elts b) (CauchyCompletion.elts c) _+_ {m} | indexAndApply (apply _+_ (CauchyCompletion.elts a) (CauchyCompletion.elts b)) (CauchyCompletion.elts c) _+_ {m} | indexAndApply (CauchyCompletion.elts a) (CauchyCompletion.elts b) _+_ {m} = <WellDefined (Equivalence.symmetric eq (Equivalence.transitive eq (absWellDefined _ _ (transferToRight'' (Ring.additiveGroup R) +Associative)) (identityOfIndiscernablesRight _∼_ (Equivalence.reflexive eq) absZero))) (Equivalence.reflexive eq) 0<e
CidentRight : {a : CauchyCompletion} → Setoid._∼_ cauchyCompletionSetoid (a +C injection 0G) a
CidentRight {a} ε 0<e = 0 , ans
where
ans : {m : ℕ} → 0 <N m → abs (index (apply _+_ (CauchyCompletion.elts (a +C injection 0G)) (map inverse (CauchyCompletion.elts a))) m) < ε
ans {m} 0<m rewrite indexAndApply (CauchyCompletion.elts (a +C injection 0G)) (map inverse (CauchyCompletion.elts a)) _+_ {m} | indexAndApply (CauchyCompletion.elts a) (constSequence 0G) _+_ {m} | equalityCommutative (mapAndIndex (CauchyCompletion.elts a) inverse m) | indexAndConst 0G m = <WellDefined (Equivalence.symmetric eq (Equivalence.transitive eq (absWellDefined _ _ (Equivalence.transitive eq (+WellDefined (identRight) (Equivalence.reflexive eq)) (invRight))) (identityOfIndiscernablesRight _∼_ (Equivalence.reflexive eq) absZero))) (Equivalence.reflexive eq) 0<e
CidentLeft : {a : CauchyCompletion} → Setoid._∼_ cauchyCompletionSetoid (injection 0G +C a) a
CidentLeft {a} = Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {injection 0G +C a} {a +C injection 0G} {a} (+CCommutative (injection 0G) a) (CidentRight {a})
CinvRight : {a : CauchyCompletion} → Setoid._∼_ cauchyCompletionSetoid (a +C (-C a)) (injection 0G)
CinvRight {a} ε 0<e = 0 , ans
where
ans : {m : ℕ} → (0 <N m) → abs (index (apply _+_ (CauchyCompletion.elts (a +C (-C a))) (map inverse (CauchyCompletion.elts (injection 0G)))) m) < ε
ans {m} 0<m rewrite indexAndApply (CauchyCompletion.elts (a +C (-C a))) (map inverse (CauchyCompletion.elts (injection 0G))) _+_ {m} | indexAndApply (CauchyCompletion.elts a) (map inverse (CauchyCompletion.elts a)) _+_ {m} | equalityCommutative (mapAndIndex (CauchyCompletion.elts a) inverse m) | equalityCommutative (mapAndIndex (constSequence 0G) inverse m) | indexAndConst 0G m = <WellDefined (Equivalence.symmetric eq (Equivalence.transitive eq (absWellDefined _ _ (Equivalence.transitive eq (+WellDefined invRight (invIdent (Ring.additiveGroup R))) identRight)) (identityOfIndiscernablesRight _∼_ (Equivalence.reflexive eq) absZero))) (Equivalence.reflexive eq) 0<e
CGroup : Group cauchyCompletionSetoid _+C_
Group.+WellDefined CGroup {a} {b} {c} {d} x y = additionWellDefined {a} {c} {b} {d} x y
Group.0G CGroup = injection 0G
Group.inverse CGroup = -C_
Group.+Associative CGroup {a} {b} {c} = Cassoc {a} {b} {c}
Group.identRight CGroup {a} = CidentRight {a}
Group.identLeft CGroup {a} = CidentLeft {a}
Group.invLeft CGroup {a} = Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {(-C a) +C a} {a +C (-C a)} {injection 0G} (+CCommutative (-C a) a) (CinvRight {a})
Group.invRight CGroup {a} = CinvRight {a}
CInjectionGroupHom : GroupHom (Ring.additiveGroup R) CGroup injection
GroupHom.groupHom CInjectionGroupHom {x} {y} = additionHom x y
GroupHom.wellDefined CInjectionGroupHom {x} {y} x=y = SetoidInjection.wellDefined CInjection {x} {y} x=y
|
{
"alphanum_fraction": 0.7139251915,
"avg_line_length": 97.3245614035,
"ext": "agda",
"hexsha": "df4660256a50e711c9f5de5f729a1b3f5b5f956e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Fields/CauchyCompletion/Group.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Fields/CauchyCompletion/Group.agda",
"max_line_length": 920,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Fields/CauchyCompletion/Group.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": 3711,
"size": 11095
}
|
module vector-test where
open import bool
open import nat
open import list
open import vector
test-vector : 𝕍 𝔹 4
test-vector = ff :: tt :: ff :: ff :: []
test-vector2 : 𝕃 (𝕍 𝔹 2)
test-vector2 = (ff :: tt :: []) ::
(tt :: ff :: []) ::
(tt :: ff :: []) :: []
test-vector3 : 𝕍 (𝕍 𝔹 3) 2
test-vector3 = (tt :: tt :: tt :: []) ::
(ff :: ff :: ff :: []) :: []
test-vector-append : 𝕍 𝔹 8
test-vector-append = test-vector ++𝕍 test-vector
test-set-vector : 𝕍 Set 3
test-set-vector = ℕ :: 𝔹 :: (𝔹 → 𝔹) :: []
|
{
"alphanum_fraction": 0.502722323,
"avg_line_length": 22.9583333333,
"ext": "agda",
"hexsha": "42241ad1eaf1dde3d11dbc0124dd876ebf812685",
"lang": "Agda",
"max_forks_count": 17,
"max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z",
"max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rfindler/ial",
"max_forks_repo_path": "vector-test.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rfindler/ial",
"max_issues_repo_path": "vector-test.agda",
"max_line_length": 48,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rfindler/ial",
"max_stars_repo_path": "vector-test.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z",
"num_tokens": 194,
"size": 551
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.