Search is not available for this dataset
text
string | meta
dict |
---|---|
module Generic.Lib.Reflection.Core where
open import Agda.Builtin.Reflection using (withNormalisation; Relevance; Visibility; clause) public
open import Reflection
renaming (visible to expl; hidden to impl; instance′ to inst;
relevant to rel; irrelevant to irr; pi to absPi; lam to absLam; def to appDef)
hiding (Arg-info; var; con; meta; visibility; relevance; _≟_; return; _>>=_; _>>_) public
open import Reflection.Argument.Information using (ArgInfo; visibility; relevance) public
import Reflection.Name
open Term using () renaming (var to appVar; con to appCon; meta to appMeta) public
open Pattern using () renaming (var to patVar; con to patCon) public
open Literal using () renaming (meta to litMeta) public
open Sort public
open import Generic.Lib.Intro
open import Generic.Lib.Equality.Propositional
open import Generic.Lib.Decidable
open import Generic.Lib.Category
open import Generic.Lib.Data.Nat
open import Generic.Lib.Data.String
open import Generic.Lib.Data.Maybe
open import Generic.Lib.Data.Product
open import Generic.Lib.Data.List
open import Data.Vec using (toList)
open import Data.Vec.N-ary using (N-ary; curryⁿ)
infixr 5 _‵→_
infixl 3 _·_
listCurryⁿ : ∀ {α β} {A : Set α} {B : Set β} n -> (List A -> B) -> N-ary n A B
listCurryⁿ n f = curryⁿ {n = n} (f ∘ toList)
named : String -> String
named s = if s == "_" then "x" else s
record Reify {α} (A : Set α) : Set α where
field reify : A -> Term
macro
reflect : A -> Term -> TC _
reflect = unify ∘ reify
open Reify {{...}} public
pattern pureVar n = appVar n []
pattern pureCon c = appCon c []
pattern pureDef f = appDef f []
pattern pureMeta m = appMeta m []
{-# DISPLAY appVar i [] = pureVar i #-}
{-# DISPLAY appCon c [] = pureCon c #-}
{-# DISPLAY appDef f [] = pureDef f #-}
{-# DISPLAY appMeta m [] = pureMeta m #-}
pattern explInfo r = arg-info expl r
pattern implInfo r = arg-info impl r
pattern instInfo r = arg-info inst r
{-# DISPLAY arg-info expl r = explInfo r #-}
{-# DISPLAY arg-info impl r = implInfo r #-}
{-# DISPLAY arg-info inst r = instInfo r #-}
pattern explRelInfo = explInfo rel
pattern explIrrInfo = explInfo irr
pattern implRelInfo = implInfo rel
pattern implIrrInfo = implInfo irr
pattern instRelInfo = instInfo rel
pattern instIrrInfo = instInfo irr
{-# DISPLAY explInfo rel = explRelInfo #-}
{-# DISPLAY explInfo irr = explIrrInfo #-}
{-# DISPLAY implInfo rel = implRelInfo #-}
{-# DISPLAY implInfo irr = implIrrInfo #-}
{-# DISPLAY instInfo rel = instRelInfo #-}
{-# DISPLAY instInfo irr = instIrrInfo #-}
pattern explArg r x = arg (explInfo r) x
pattern implArg r x = arg (implInfo r) x
pattern instArg r x = arg (instInfo r) x
{-# DISPLAY arg (explInfo r) = explArg r #-}
{-# DISPLAY arg (implInfo r) = implArg r #-}
{-# DISPLAY arg (instInfo r) = instArg r #-}
pattern explRelArg x = explArg rel x
pattern implRelArg x = implArg rel x
pattern instRelArg x = instArg rel x
{-# DISPLAY explArg rel x = explRelArg x #-}
{-# DISPLAY implArg rel x = implRelArg x #-}
{-# DISPLAY instArg rel x = instRelArg x #-}
pattern pi s a b = absPi a (abs s b)
{-# DISPLAY absPi a (abs s b) = pi s a b #-}
pattern explPi r s a b = pi s (explArg r a) b
pattern implPi r s a b = pi s (implArg r a) b
pattern instPi r s a b = pi s (instArg r a) b
{-# DISPLAY pi (explArg r a) s b = explPi r s a b #-}
{-# DISPLAY pi (implArg r a) s b = implPi r s a b #-}
{-# DISPLAY pi (instArg r a) s b = instPi r s a b #-}
pattern explRelPi s a b = explPi rel a s b
pattern explIrrPi s a b = explPi irr a s b
pattern implRelPi s a b = implPi rel a s b
pattern implIrrPi s a b = implPi irr a s b
pattern instRelPi s a b = instPi rel a s b
pattern instIrrPi s a b = instPi irr a s b
{-# DISPLAY explPi rel a s b = explRelPi s a b #-}
{-# DISPLAY explPi irr a s b = explIrrPi s a b #-}
{-# DISPLAY implPi rel a s b = implRelPi s a b #-}
{-# DISPLAY implPi irr a s b = implIrrPi s a b #-}
{-# DISPLAY instPi rel a s b = instRelPi s a b #-}
{-# DISPLAY instPi irr a s b = instIrrPi s a b #-}
pattern lam v s t = absLam v (abs s t)
{-# DISPLAY absLam v (abs s t) = lam v s t #-}
pattern explLam s t = lam expl s t
pattern implLam s t = lam impl s t
pattern instLam s t = lam inst s t
{-# DISPLAY lam expl s t = explLam s t #-}
{-# DISPLAY lam impl s t = implLam s t #-}
{-# DISPLAY lam inst s t = instLam s t #-}
pattern _‵→_ a b = pi "_" (explRelArg a) b
-- No longer parses for whatever reason.
-- {-# DISPLAY pi "_" (explRelArg a) b = a ‵→ b #-}
mutual
<_>_ : ∀ {α} -> Relevance -> Set α -> Set α
<_>_ = flip RelValue
data RelValue {α} (A : Set α) : Relevance -> Set α where
relv : A -> < rel > A
irrv : .A -> < irr > A
elimRelValue : ∀ {r α π} {A : Set α}
-> (P : ∀ {r} -> < r > A -> Set π)
-> (∀ x -> P (relv x))
-> (∀ .x -> P (irrv x))
-> (x : < r > A)
-> P x
elimRelValue P f g (relv x) = f x
elimRelValue P f g (irrv x) = g x
unrelv : ∀ {α} {A : Set α} -> < rel > A -> A
unrelv (relv x) = x
-- Is it possible to handle this in some other way that doesn't require a postulate?
-- See the `appRel` function below. Or is the postulate fine?
postulate
.unirrv : ∀ {α} {A : Set α} -> < irr > A -> A
<_>_~>_ : ∀ {α β} -> Relevance -> Set α -> Set β -> Set (α ⊔ β)
< rel > A ~> B = A -> B
< irr > A ~> B = .A -> B
lamRel : ∀ {r α β} {A : Set α} {B : Set β} -> (< r > A -> B) -> < r > A ~> B
lamRel {rel} f = λ x -> f (relv x)
lamRel {irr} f = λ x -> f (irrv x)
-- The laziness is intentional.
appRel : ∀ {r α β} {A : Set α} {B : Set β} -> (< r > A ~> B) -> < r > A -> B
appRel {rel} f rx = f (unrelv rx)
appRel {irr} f rx = f (unirrv rx)
Pi : ∀ {α β} i -> (A : Set α) -> (< relevance i > A -> Set β) -> Set (α ⊔ β)
Pi explRelInfo A B = (x : A) -> B (relv x)
Pi explIrrInfo A B = . (x : A) -> B (irrv x)
Pi implRelInfo A B = {x : A} -> B (relv x)
Pi implIrrInfo A B = . {x : A} -> B (irrv x)
Pi instRelInfo A B = {{x : A}} -> B (relv x)
Pi instIrrInfo A B = .{{x : A}} -> B (irrv x)
lamPi : ∀ {α β} {A : Set α} i {B : < relevance i > A -> Set β} -> (∀ x -> B x) -> Pi i A B
lamPi explRelInfo f = λ x -> f (relv x)
lamPi explIrrInfo f = λ x -> f (irrv x)
lamPi implRelInfo f = f _
lamPi implIrrInfo f = f _
lamPi instRelInfo f = f _
lamPi instIrrInfo f = f _
appPi : ∀ {α β} {A : Set α} i {B : < relevance i > A -> Set β} -> Pi i A B -> ∀ x -> B x
appPi explRelInfo f (relv x) = f x
appPi explIrrInfo f (irrv x) = f x
appPi implRelInfo y (relv x) = y
appPi implIrrInfo y (irrv x) = y
appPi instRelInfo y (relv x) = y {{x}}
appPi instIrrInfo y (irrv x) = y {{x}}
RelEq : ∀ {α} -> Relevance -> Set α -> Set α
RelEq rel A = Eq A
RelEq irr A = ⊤
vis : {A : Set} -> (A -> List (Arg Term) -> Term) -> A -> List Term -> Term
vis k x = k x ∘ map explRelArg
vis# : ∀ {A : Set} n -> (A -> List (Arg Term) -> Term) -> A -> N-ary n Term Term
vis# n k = listCurryⁿ n ∘ vis k
isRelevant : Relevance -> Bool
isRelevant rel = true
isRelevant irr = false
argInfo : ∀ {α} {A : Set α} -> Arg A -> _
argInfo (arg i x) = i
argVal : ∀ {α} {A : Set α} -> Arg A -> A
argVal (arg i x) = x
unExpl : ∀ {α} {A : Set α} -> Arg A -> Maybe A
unExpl (explArg r x) = just x
unExpl _ = nothing
absName : ∀ {α} {A : Set α} -> Abs A -> String
absName (abs s x) = s
absVal : ∀ {α} {A : Set α} -> Abs A -> A
absVal (abs s x) = x
patVars : List String -> List (Arg Pattern)
patVars = map (explRelArg ∘ patVar ∘ named)
record Data {α} (A : Set α) : Set α where
no-eta-equality
constructor packData
field
dataName : Name
parsTele : Type
indsTele : Type
consTypes : List A
consNames : All (const Name) consTypes
open Data public
instance
NameEq : Eq Name
NameEq = viaBase Reflection.Name._≟_
EqRelValue : ∀ {α r} {A : Set α} {{aEq : RelEq r A}} -> Eq (< r > A)
EqRelValue {A = A} {{aEq}} = record
{ _≟_ = go
} where
relv-inj : {x y : A} -> relv x ≡ relv y -> x ≡ y
relv-inj refl = refl
go : ∀ {r} {{aEq : RelEq r A}} -> IsSet (< r > A)
go (relv x) (relv y) = dcong relv relv-inj (x ≟ y)
go (irrv x) (irrv y) = yes refl
ArgFunctor : ∀ {α} -> RawFunctor {α} Arg
ArgFunctor = record
{ _<$>_ = λ{ f (arg i x) -> arg i (f x) }
}
AbsFunctor : ∀ {α} -> RawFunctor {α} Abs
AbsFunctor = record
{ _<$>_ = λ{ f (abs s x) -> abs s (f x) }
}
TCMonad : ∀ {α} -> RawMonad {α} TC
TCMonad = record
{ return = Reflection.return
; _>>=_ = Reflection._>>=_
}
TCApplicative : ∀ {α} -> RawApplicative {α} TC
TCApplicative = rawIApplicative
TCFunctor : ∀ {α} -> RawFunctor {α} TC
TCFunctor = rawFunctor
keep : (ℕ -> ℕ) -> ℕ -> ℕ
keep ι 0 = 0
keep ι (suc n) = suc (ι n)
{-# TERMINATING #-}
mutual
ren : (ℕ -> ℕ) -> Term -> Term
ren ι (appVar v xs) = appVar (ι v) (rens ι xs)
ren ι (appCon c xs) = appCon c (rens ι xs)
ren ι (appDef f xs) = appDef f (rens ι xs)
ren ι (lam v s t) = lam v s (ren (keep ι) t)
ren ι (pat-lam cs xs) = undefined where postulate undefined : _
ren ι (pi s a b) = pi s (ren ι <$> a) (ren (keep ι) b)
ren ι (agda-sort s) = agda-sort (renSort ι s)
ren ι (lit l) = lit l
ren ι (appMeta x xs) = appMeta x (rens ι xs)
ren ι unknown = unknown
rens : (ℕ -> ℕ) -> List (Arg Term) -> List (Arg Term)
rens ι = map (fmap (ren ι))
renSort : (ℕ -> ℕ) -> Sort -> Sort
renSort ι (set t) = set (ren ι t)
renSort ι (lit n) = lit n
renSort ι unknown = unknown
shiftBy : ℕ -> Term -> Term
shiftBy = ren ∘ _+_
shift : Term -> Term
shift = shiftBy 1
unshiftBy : ℕ -> Term -> Term
unshiftBy n = ren (_∸ n)
isSomeName : Name -> Term -> Bool
isSomeName n (appDef m _) = n == m
isSomeName n (appCon m _) = n == m
isSomeName n t = false
{-# TERMINATING #-}
mutual
mapName : (ℕ -> List (Arg Term) -> Term) -> Name -> Term -> Term
mapName f n (appVar v xs) = appVar v (mapNames f n xs)
mapName f n (appCon m xs) = (if n == m then f 0 else appCon m) (mapNames f n xs)
mapName f n (appDef m xs) = (if n == m then f 0 else appDef m) (mapNames f n xs)
mapName f n (lam v s t) = lam v s (mapName (f ∘ suc) n t)
mapName f n (pat-lam cs xs) = undefined where postulate undefined : _
mapName f n (pi s a b) = pi s (mapName f n <$> a) (mapName (f ∘ suc) n b)
mapName f n (agda-sort s) = agda-sort (mapNameSort f n s)
mapName f n (lit l) = lit l
mapName f n (appMeta x xs) = appMeta x (mapNames f n xs)
mapName f n unknown = unknown
mapNames : (ℕ -> List (Arg Term) -> Term) -> Name -> List (Arg Term) -> List (Arg Term)
mapNames f n = map (fmap (mapName f n))
mapNameSort : (ℕ -> List (Arg Term) -> Term) -> Name -> Sort -> Sort
mapNameSort f n (set t) = set (mapName f n t)
mapNameSort f n (lit l) = lit l
mapNameSort f n unknown = unknown
explsOnly : List (Arg Term) -> List Term
explsOnly = mapMaybe unExpl
initType : Type -> Type
initType (pi s a b) = pi s a (initType b)
initType b = unknown
lastType : Type -> Type
lastType (pi s a b) = lastType b
lastType b = b
-- These two should return just `Type` like everything else.
takePis : ℕ -> Type -> Maybe Type
takePis 0 a = just unknown
takePis (suc n) (pi s a b) = pi s a <$> takePis n b
takePis _ _ = nothing
dropPis : ℕ -> Type -> Maybe Type
dropPis 0 a = just a
dropPis (suc n) (pi s a b) = dropPis n b
dropPis _ _ = nothing
monoLastType : Type -> Type
monoLastType = go 0 where
go : ℕ -> Type -> Type
go n (pi s a b) = go (suc n) b
go n b = unshiftBy n b
appendType : Type -> Type -> Type
appendType (pi s a b) c = pi s a (appendType b c)
appendType b c = c
explLamsBy : Type -> Term -> Term
explLamsBy (explPi r s a b) t = explLam s (explLamsBy b t)
explLamsBy (pi s a b) t = explLamsBy b t
explLamsBy b t = t
implicitize : Type -> Type
implicitize (explPi r s a b) = implPi r s a (implicitize b)
implicitize (pi s a b) = pi s a (implicitize b)
implicitize b = b
leadImpls : Type -> List (Abs Term)
leadImpls (implPi r s a b) = abs s a ∷ leadImpls b
leadImpls b = []
pisToAbsArgTypes : Type -> List (Abs (Arg Type))
pisToAbsArgTypes (pi s a b) = abs s a ∷ pisToAbsArgTypes b
pisToAbsArgTypes b = []
explPisToAbsTypes : Type -> List (Abs Type)
explPisToAbsTypes (explPi r s a b) = abs s a ∷ explPisToAbsTypes b
explPisToAbsTypes (pi s a b) = explPisToAbsTypes b
explPisToAbsTypes b = []
explPisToNames : Type -> List String
explPisToNames = map absName ∘ explPisToAbsTypes
countPis : Type -> ℕ
countPis = length ∘ pisToAbsArgTypes
countExplPis : Type -> ℕ
countExplPis = length ∘ explPisToAbsTypes
pisToAbsArgVars : ℕ -> Type -> List (Abs (Arg Term))
pisToAbsArgVars (suc n) (pi s (arg i a) b) = abs s (arg i (pureVar n)) ∷ pisToAbsArgVars n b
pisToAbsArgVars n b = []
pisToArgVars : ℕ -> Type -> List (Arg Term)
pisToArgVars = map absVal % ∘ pisToAbsArgVars
explPisToAbsVars : ℕ -> Type -> List (Abs Term)
explPisToAbsVars (suc n) (explPi r s a b) = abs s (pureVar n) ∷ explPisToAbsVars n b
explPisToAbsVars (suc n) (pi s a b) = explPisToAbsVars n b
explPisToAbsVars n b = []
throw : ∀ {α} {A : Set α} -> String -> TC A
throw s = typeError (strErr s ∷ [])
panic : ∀ {α} {A : Set α} -> String -> TC A
panic s = throw $ "panic: " ++ˢ s
-- I'll merge these later.
macro
sate : Name -> Term -> TC _
sate f ?r =
getType f >>= λ a ->
let res = λ app -> quoteTC (vis# (countExplPis a) app f) >>= unify ?r in
getDefinition f >>= λ
{ (data-cons _) -> res appCon
; _ -> res appDef
}
sateMacro : Name -> Term -> TC _
sateMacro f ?r =
getType f >>= λ a ->
quoteTC (vis# (pred (countExplPis a)) appDef f) >>= unify ?r
_·_ : Term -> Term -> Term
_·_ = sate _$_
unshift′ : Term -> Term
unshift′ t = explLam "_" t · sate tt₀
-- A note for myself: `foldℕ (sate lsuc) (sate lzero) n` is not `reify n`:
-- it's damn `lsuc` -- not `suc`.
termLevelOf : Term -> Maybe Term
termLevelOf (agda-sort (set t)) = just t
termLevelOf (agda-sort (lit n)) = just (foldℕ (sate lsuc) (sate lzero) n)
termLevelOf (agda-sort unknown) = just unknown
termLevelOf _ = nothing
instance
TermReify : Reify Term
TermReify = record
{ reify = id
}
NameReify : Reify Name
NameReify = record
{ reify = lit ∘′ name
}
VisibilityReify : Reify Visibility
VisibilityReify = record
{ reify = λ
{ expl -> sate expl
; impl -> sate impl
; inst -> sate inst
}
}
RelevanceReify : Reify Relevance
RelevanceReify = record
{ reify = λ
{ rel -> sate rel
; irr -> sate irr
}
}
ArgInfoReify : Reify ArgInfo
ArgInfoReify = record
{ reify = λ{ (arg-info v r) -> sate arg-info (reify v) (reify r) }
}
ProdReify : ∀ {α β} {A : Set α} {B : A -> Set β}
{{aReify : Reify A}} {{bReify : ∀ {x} -> Reify (B x)}} -> Reify (Σ A B)
ProdReify = record
{ reify = uncurry λ x y -> sate _,_ (reify x) (reify y)
}
ℕReify : Reify ℕ
ℕReify = record
{ reify = foldℕ (sate suc) (sate zero)
}
ListReify : ∀ {α} {A : Set α} {{aReify : Reify A}} -> Reify (List A)
ListReify = record
{ reify = foldr (sate _∷_ ∘ reify) (sate [])
}
AllReify : ∀ {α β} {A : Set α} {B : A -> Set β} {xs} {{bReify : ∀ {x} -> Reify (B x)}}
-> Reify (All B xs)
AllReify {B = B} {{bReify}} = record
{ reify = go _
} where
go : ∀ xs -> All B xs -> Term
go [] tt = sate tt₀
go (x ∷ xs) (y , ys) = sate _,_ (reify {{bReify}} y) (go xs ys)
toTuple : List Term -> Term
toTuple = foldr₁ (sate _,_) (sate tt₀)
curryBy : Type -> Term -> Term
curryBy = go 0 where
go : ℕ -> Type -> Term -> Term
go n (pi s (arg (arg-info v r) a) b) t = lam v s $ go (suc n) b t
go n _ t = shiftBy n t · toTuple (map pureVar (downFrom n))
explUncurryBy : Type -> Term -> Term
explUncurryBy a f = explLam "x" $ appDef (quote id) (explArg rel (shift f) ∷ go a (pureVar 0)) where
go : Term -> Term -> List (Arg Term)
go (explPi r s a b@(pi _ _ _)) p = explArg r (sate proj₁ p) ∷ go b (sate proj₂ p)
go (pi s a b@(pi _ _ _)) p = go b (sate proj₂ p)
go (explPi r s a b) x = explArg r x ∷ []
go _ t = []
defineTerm : Name -> Term -> TC _
defineTerm n t =
getType n >>= λ a ->
defineFun n (clause (map (implRelArg ∘ patVar ∘ named ∘ absName) (leadImpls a)) t ∷ [])
-- Able to normalize a Setω.
normalize : Term -> TC Term
normalize (pi s (arg i a) b) =
pi s ∘ arg i <$> normalize a <*> extendContext (arg i a) (normalize b)
normalize t = normalise t
getNormType : Name -> TC Type
getNormType = getType >=> normalize
inferNormType : Term -> TC Type
inferNormType = inferType >=> normalize
getData : Name -> TC (Data Type)
getData d = getNormType d >>= λ ab -> getDefinition d >>= λ
{ (data-type p cs) ->
mapM (λ c -> _,_ c ∘ dropPis p <$> getNormType c) cs >>= λ mans ->
case takePis p ab ⊗ (dropPis p ab ⊗ (mapM (uncurry λ c ma -> flip _,_ c <$> ma) mans)) of λ
{ nothing -> panic "getData: data"
; (just (a , b , acs)) -> return ∘ uncurry (packData d a b) $ splitList acs
}
; (record-type c _) -> getNormType c >>= dropPis (countPis ab) >>> λ
{ nothing -> panic "getData: record"
; (just a′) -> return $ packData d (initType ab) (lastType ab) (a′ ∷ []) (c , tt)
}
; _ -> throw "not a data"
}
macro
TypeOf : Term -> Term -> TC _
TypeOf t ?r = inferNormType t >>= unify ?r
runTC : ∀ {α} {A : Set α} -> TC A -> Term -> TC _
runTC a ?r = bindTC a quoteTC >>= unify ?r
|
{
"alphanum_fraction": 0.5834500532,
"avg_line_length": 31.535335689,
"ext": "agda",
"hexsha": "30fea146a6d6e5903ddecb82df959621a9086c13",
"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/Lib/Reflection/Core.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/Lib/Reflection/Core.agda",
"max_line_length": 100,
"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/Lib/Reflection/Core.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": 6335,
"size": 17849
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.DiffInt where
open import Cubical.Data.DiffInt.Base public
open import Cubical.Data.DiffInt.Properties public
|
{
"alphanum_fraction": 0.7802197802,
"avg_line_length": 30.3333333333,
"ext": "agda",
"hexsha": "c889672851335f95e9851b5f2b0e10d410802359",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Data/DiffInt.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Data/DiffInt.agda",
"max_line_length": 50,
"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/Data/DiffInt.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 42,
"size": 182
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Instance.Globe where
open import Level using (Level; zero)
open import Relation.Binary using (IsEquivalence; module IsEquivalence)
open import Relation.Binary.PropositionalEquality using (isEquivalence)
open import Data.Nat using (ℕ; zero; suc; _<_; _≤_; z≤n; s≤s)
open import Categories.Category
data GlobeHom : (m n : ℕ) → Set where
I : ∀ {place : ℕ} → GlobeHom place place
σ : ∀ {n m : ℕ} → GlobeHom (suc n) m → GlobeHom n m
τ : ∀ {n m : ℕ} → GlobeHom (suc n) m → GlobeHom n m
data GlobeEq : {m n : ℕ} → GlobeHom m n → GlobeHom m n → Set where
both-I : ∀ {m} → GlobeEq {m} {m} I I
both-σ : ∀ {m n x y} → GlobeEq {m} {n} (σ x) (σ y)
both-τ : ∀ {m n x y} → GlobeEq {m} {n} (τ x) (τ y)
GlobeEquiv : ∀ {m n} → IsEquivalence (GlobeEq {m} {n})
GlobeEquiv = record { refl = refl; sym = sym; trans = trans }
where
refl : ∀ {m n} {x : GlobeHom m n} → GlobeEq x x
refl {x = I} = both-I
refl {x = σ y} = both-σ
refl {x = τ y} = both-τ
sym : ∀ {m n} {x y : GlobeHom m n} → GlobeEq x y → GlobeEq y x
sym both-I = both-I
sym both-σ = both-σ
sym both-τ = both-τ
trans : ∀ {m n} {x y z : GlobeHom m n} → GlobeEq x y → GlobeEq y z → GlobeEq x z
trans both-I y∼z = y∼z
trans both-σ both-σ = both-σ
trans both-τ both-τ = both-τ
infixl 7 _⊚_
_⊚_ : ∀ {l m n} → GlobeHom m n → GlobeHom l m → GlobeHom l n
x ⊚ I = x
x ⊚ σ y = σ (x ⊚ y)
x ⊚ τ y = τ (x ⊚ y)
Globe : Category Level.zero Level.zero Level.zero
Globe = record
{ Obj = ℕ
; _⇒_ = GlobeHom
; _≈_ = GlobeEq
; id = I
; _∘_ = _⊚_
; assoc = λ {_ _ _ _ f g h} → assoc {f = f} {g} {h}
; sym-assoc = λ {_ _ _ _ f g h} → GlobeEquiv.sym (assoc {f = f} {g} {h})
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = GlobeEquiv
; ∘-resp-≈ = ∘-resp-≡
}
where
module GlobeEquiv {m n} = IsEquivalence (GlobeEquiv {m} {n})
assoc : ∀ {A B C D} {f : GlobeHom A B} {g : GlobeHom B C} {h : GlobeHom C D} → GlobeEq ((h ⊚ g) ⊚ f) (h ⊚ (g ⊚ f))
assoc {f = I} = refl
where open IsEquivalence GlobeEquiv
assoc {f = σ y} = both-σ
assoc {f = τ y} = both-τ
identityˡ : ∀ {A B} {f : GlobeHom A B} → GlobeEq (I ⊚ f) f
identityˡ {f = I} = both-I
identityˡ {f = σ y} = both-σ
identityˡ {f = τ y} = both-τ
identityʳ : ∀ {A B} {f : GlobeHom A B} → GlobeEq (f ⊚ I) f
identityʳ = IsEquivalence.refl GlobeEquiv
identity² : {m : ℕ} → GlobeEq {m} (I ⊚ I) I
identity² = both-I
∘-resp-≡ : ∀ {A B C} {f h : GlobeHom B C} {g i : GlobeHom A B} → GlobeEq f h → GlobeEq g i → GlobeEq (f ⊚ g) (h ⊚ i)
∘-resp-≡ f∼h both-I = f∼h
∘-resp-≡ f∼h both-σ = both-σ
∘-resp-≡ f∼h both-τ = both-τ
|
{
"alphanum_fraction": 0.5663847003,
"avg_line_length": 34.858974359,
"ext": "agda",
"hexsha": "3b67a5a61a6807d195c41c89d27f56cb8a046044",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Instance/Globe.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Instance/Globe.agda",
"max_line_length": 118,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Instance/Globe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1154,
"size": 2719
}
|
{-# OPTIONS --prop --rewriting #-}
open import Examples.Sorting.Sequential.Comparable
module Examples.Sorting.Sequential.MergeSort.Split (M : Comparable) where
open Comparable M
open import Examples.Sorting.Sequential.Core M
open import Calf costMonoid
open import Calf.Types.Nat
open import Calf.Types.List
open import Calf.Types.Bounded costMonoid
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl)
open import Data.Product using (_×_; _,_; ∃; proj₁; proj₂)
open import Data.Nat as Nat using (ℕ; zero; suc; _+_; _*_; ⌊_/2⌋; ⌈_/2⌉)
open import Data.Nat.Properties as N using (module ≤-Reasoning)
pair = Σ++ (list A) λ _ → (list A)
split/clocked : cmp (Π nat λ _ → Π (list A) λ _ → F pair)
split/clocked zero l = ret ([] , l)
split/clocked (suc k) [] = ret ([] , [])
split/clocked (suc k) (x ∷ xs) = bind (F pair) (split/clocked k xs) λ (l₁ , l₂) → ret (x ∷ l₁ , l₂)
split/clocked/correct : ∀ k k' l → k + k' ≡ length l →
◯ (∃ λ l₁ → ∃ λ l₂ → split/clocked k l ≡ ret (l₁ , l₂) × length l₁ ≡ k × length l₂ ≡ k' × l ↭ (l₁ ++ l₂))
split/clocked/correct zero k' l refl u = [] , l , refl , refl , refl , refl
split/clocked/correct (suc k) k' (x ∷ xs) h u =
let (l₁ , l₂ , ≡ , h₁ , h₂ , ↭) = split/clocked/correct k k' xs (N.suc-injective h) u in
x ∷ l₁ , l₂ , Eq.cong (λ e → bind (F pair) e _) ≡ , Eq.cong suc h₁ , h₂ , prep x ↭
split/clocked/cost : cmp (Π nat λ _ → Π (list A) λ _ → cost)
split/clocked/cost _ _ = zero
split/clocked≤split/clocked/cost : ∀ k l → IsBounded pair (split/clocked k l) (split/clocked/cost k l)
split/clocked≤split/clocked/cost zero l = bound/ret
split/clocked≤split/clocked/cost (suc k) [] = bound/ret
split/clocked≤split/clocked/cost (suc k) (x ∷ xs) = bound/bind/const zero zero (split/clocked≤split/clocked/cost k xs) λ _ → bound/ret
split : cmp (Π (list A) λ _ → F pair)
split l = split/clocked ⌊ length l /2⌋ l
split/correct : ∀ l →
◯ (∃ λ l₁ → ∃ λ l₂ → split l ≡ ret (l₁ , l₂) × length l₁ ≡ ⌊ length l /2⌋ × length l₂ ≡ ⌈ length l /2⌉ × l ↭ (l₁ ++ l₂))
split/correct l = split/clocked/correct ⌊ length l /2⌋ ⌈ length l /2⌉ l (N.⌊n/2⌋+⌈n/2⌉≡n (length l))
split/cost : cmp (Π (list A) λ _ → cost)
split/cost l = split/clocked/cost ⌊ length l /2⌋ l
split≤split/cost : ∀ l → IsBounded pair (split l) (split/cost l)
split≤split/cost l = split/clocked≤split/clocked/cost ⌊ length l /2⌋ l
|
{
"alphanum_fraction": 0.6337910945,
"avg_line_length": 43.6909090909,
"ext": "agda",
"hexsha": "8f8211edb358827a462fca09be4ab70b8810c7a0",
"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/MergeSort/Split.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/MergeSort/Split.agda",
"max_line_length": 134,
"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/MergeSort/Split.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": 921,
"size": 2403
}
|
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Group where
open import Cubical.Data.Group.Base public
|
{
"alphanum_fraction": 0.7431192661,
"avg_line_length": 21.8,
"ext": "agda",
"hexsha": "97c1b5d00d43606c9b2e89a51ff7e9e5b3e3f90a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Data/Group.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Data/Group.agda",
"max_line_length": 42,
"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/Data/Group.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": 25,
"size": 109
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Group
open import lib.types.Pi
open import lib.NType2
open import lib.types.EilenbergMacLane1.Core
module lib.types.EilenbergMacLane1.DoubleElim where
private
emloop-emloop-helper : ∀ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k}
{a : A} (p : a == a)
{b₀ b₁ : B} (q : b₀ == b₁)
(f : (b : B) → C a b)
(g : (b : B) → C a b)
(r₀ : f b₀ == g b₀ [ (λ a → C a b₀) ↓ p ])
(r₁ : f b₁ == g b₁ [ (λ a → C a b₁) ↓ p ])
→ ↓-ap-in (λ Z → Z) (λ a → C a b₀) r₀ ∙'ᵈ ↓-ap-in (λ Z → Z) (C a) (apd g q) ==
↓-ap-in (λ Z → Z) (C a) (apd f q) ∙ᵈ ↓-ap-in (λ Z → Z) (λ a → C a b₁) r₁
[ (λ p → f b₀ == g b₁ [ (λ Z → Z) ↓ p ]) ↓ ap-comm' C p q ]
→ r₀ == r₁ [ (λ b → f b == g b [ (λ a → C a b) ↓ p ]) ↓ q ]
emloop-emloop-helper {C = C} p {b₀} idp f g r₀ r₁ s =
–>-is-inj (↓-ap-equiv (λ Z → Z) (λ a → C a b₀)) r₀ r₁ $
(! (▹idp (↓-ap-in (λ Z → Z) (λ a → C a b₀) r₀)) ∙
s ∙
idp◃ (↓-ap-in (λ Z → Z) (λ a → C a b₀) r₁))
module _ {i j} (G : Group i) (H : Group j) where
private
module G = Group G
module H = Group H
module EM₁Level₁DoubleElim {k} {P : EM₁ G → EM₁ H → Type k}
{{P-level : ∀ x y → has-level 1 (P x y)}}
(embase-embase* : P embase embase)
(embase-emloop* : ∀ h → embase-embase* == embase-embase* [ P embase ↓ emloop h ])
(emloop-embase* : ∀ g → embase-embase* == embase-embase* [ (λ x → P x embase) ↓ emloop g ])
(embase-emloop-comp* : ∀ h₁ h₂ →
embase-emloop* (H.comp h₁ h₂) == embase-emloop* h₁ ∙ᵈ embase-emloop* h₂
[ (λ p → embase-embase* == embase-embase* [ P embase ↓ p ]) ↓ emloop-comp h₁ h₂ ])
(emloop-comp-embase* : ∀ g₁ g₂ →
emloop-embase* (G.comp g₁ g₂) == emloop-embase* g₁ ∙ᵈ emloop-embase* g₂
[ (λ p → embase-embase* == embase-embase* [ (λ x → P x embase) ↓ p ]) ↓ emloop-comp g₁ g₂ ])
(emloop-emloop* : ∀ g h →
↓-ap-in (λ Z → Z) (λ a → P a embase) (emloop-embase* g) ∙'ᵈ
↓-ap-in (λ Z → Z) (P embase) (embase-emloop* h)
==
↓-ap-in (λ Z → Z) (P embase) (embase-emloop* h) ∙ᵈ
↓-ap-in (λ Z → Z) (λ a → P a embase) (emloop-embase* g)
[ (λ p → embase-embase* == embase-embase* [ (λ Z → Z) ↓ p ]) ↓ ap-comm' P (emloop g) (emloop h) ])
where
private
module Embase =
EM₁Level₁Elim {P = P embase}
{{P-level embase}}
embase-embase*
embase-emloop*
embase-emloop-comp*
P' : embase' G == embase → EM₁ H → Type k
P' p y = Embase.f y == Embase.f y [ (λ x → P x y) ↓ p ]
P'-level : ∀ p y → has-level 0 (P' p y)
P'-level _ y = ↓-level (P-level embase y)
emloop-emloop** : ∀ g h → emloop-embase* g == emloop-embase* g [ P' (emloop g) ↓ emloop h ]
emloop-emloop** g h =
emloop-emloop-helper
{C = P}
(emloop g) (emloop h)
Embase.f Embase.f
(emloop-embase* g) (emloop-embase* g)
(transport!
(λ u →
↓-ap-in (λ Z → Z) (λ a → P a embase) (emloop-embase* g) ∙'ᵈ
↓-ap-in (λ Z → Z) (P embase) u
==
↓-ap-in (λ Z → Z) (P embase) u ∙ᵈ
↓-ap-in (λ Z → Z) (λ a → P a embase) (emloop-embase* g)
[ (λ p → embase-embase* == embase-embase* [ (λ Z → Z) ↓ p ]) ↓ ap-comm' P (emloop g) (emloop h) ])
(Embase.emloop-β h)
(emloop-emloop* g h))
module Emloop (g : G.El) =
EM₁SetElim {P = P' (emloop g)}
{{P'-level (emloop g)}}
(emloop-embase* g)
(emloop-emloop** g)
module EmloopComp (g₁ g₂ : G.El) =
EM₁PropElim {P = λ y → Emloop.f (G.comp g₁ g₂) y ==
Emloop.f g₁ y ∙ᵈ Emloop.f g₂ y
[ (λ x → P' x y) ↓ emloop-comp g₁ g₂ ]}
{{λ y → ↓-level (P'-level _ y)}}
(emloop-comp-embase* g₁ g₂)
module DoubleElim (y : EM₁ H) =
EM₁Level₁Elim {P = λ x → P x y}
{{λ x → P-level x y}}
(Embase.f y)
(λ g → Emloop.f g y)
(λ g₁ g₂ → EmloopComp.f g₁ g₂ y)
abstract
f : ∀ x y → P x y
f x y = DoubleElim.f y x
embase-embase-β : f embase embase ↦ embase-embase*
embase-embase-β = Embase.embase-β
{-# REWRITE embase-embase-β #-}
embase-emloop-β : ∀ (h : H.El) → apd (λ y → f embase y) (emloop h) == embase-emloop* h
embase-emloop-β h = Embase.emloop-β h
emloop-embase-β : ∀ (g : G.El) → apd (λ x → f x embase) (emloop g) == emloop-embase* g
emloop-embase-β g = DoubleElim.emloop-β embase g
|
{
"alphanum_fraction": 0.4704897447,
"avg_line_length": 39.4876033058,
"ext": "agda",
"hexsha": "08055831f66c745d9f72bfc345ae8154ea6b752d",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/EilenbergMacLane1/DoubleElim.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/EilenbergMacLane1/DoubleElim.agda",
"max_line_length": 114,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/EilenbergMacLane1/DoubleElim.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 1832,
"size": 4778
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Results concerning double negation elimination.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Axiom.DoubleNegationElimination where
open import Axiom.ExcludedMiddle
open import Level
open import Relation.Nullary
open import Relation.Nullary.Negation
------------------------------------------------------------------------
-- Definition
-- The classical statement of double negation elimination says that
-- if a property is not not true then it is true.
DoubleNegationElimination : (ℓ : Level) → Set (suc ℓ)
DoubleNegationElimination ℓ = {P : Set ℓ} → ¬ ¬ P → P
------------------------------------------------------------------------
-- Properties
-- Double negation elimination is equivalent to excluded middle
em⇒dne : ∀ {ℓ} → ExcludedMiddle ℓ → DoubleNegationElimination ℓ
em⇒dne em = decidable-stable em
dne⇒em : ∀ {ℓ} → DoubleNegationElimination ℓ → ExcludedMiddle ℓ
dne⇒em dne = dne excluded-middle
|
{
"alphanum_fraction": 0.5521023766,
"avg_line_length": 31.2571428571,
"ext": "agda",
"hexsha": "3a3cf70fd12d551d3e4976cfd0041b595a5dd26f",
"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/Axiom/DoubleNegationElimination.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/Axiom/DoubleNegationElimination.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Axiom/DoubleNegationElimination.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": 237,
"size": 1094
}
|
------------------------------------------------------------------------------
-- Group theory base
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module GroupTheory.Base where
infix 8 _⁻¹
infixl 7 _·_
------------------------------------------------------------------------------
-- First-order logic with equality.
open import Common.FOL.FOL-Eq public renaming ( D to G )
-- Group theory axioms
postulate
ε : G -- The identity element.
_·_ : G → G → G -- The binary operation.
_⁻¹ : G → G -- The inverse function.
-- We choose a non-redundant set of axioms. See for example (Mac
-- Lane and Garret 1999, exercises 5-7, p. 50-51, or Hodges 1993,
-- p. 37).
assoc : ∀ a b c → a · b · c ≡ a · (b · c)
leftIdentity : ∀ a → ε · a ≡ a
leftInverse : ∀ a → a ⁻¹ · a ≡ ε
{-# ATP axioms assoc leftIdentity leftInverse #-}
------------------------------------------------------------------------------
-- References
--
-- Hodges, W. (1993). Model Theory. Vol. 42. Encyclopedia of
-- Mathematics and its Applications. Cambridge University Press.
--
-- Mac Lane, S. and Birkhof, G. (1999). Algebra. 3rd ed. AMS Chelsea
-- Publishing.
|
{
"alphanum_fraction": 0.456241033,
"avg_line_length": 34,
"ext": "agda",
"hexsha": "a4febf7d2c3ee1fc42971d5591d8c1863bac4aa6",
"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/GroupTheory/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/GroupTheory/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/GroupTheory/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": 335,
"size": 1394
}
|
module ProcessAlgebra where
open import Data.Nat
open import Data.Nat.Properties
open import Data.List
data Channel : Set where
ℂ_ : ℕ → Channel
data ℙ : Set₁ where
ν_[_] : List Channel → (Channel → ℙ) → ℙ
B_,_ : Channel → ℙ → ℙ
Send_[_],_ : ∀ {A : Set} → Channel → A → ℙ → ℙ
Recv_,_ : ∀ {A : Set} → Channel → (A → ℙ) → ℙ
_||_ : ℙ → ℙ → ℙ
Dup_ : ℙ → ℙ
Done : ℙ
data Message : Set₁ where
_,_of_ : Channel → (A : Set) → A → Message
data Action : Set₁ where
Out_ : Message → Action
In_ : Message → Action
data Label : Set₁ where
Silent : Label
Act_ : Action → Label
|
{
"alphanum_fraction": 0.6053511706,
"avg_line_length": 19.2903225806,
"ext": "agda",
"hexsha": "fb93ae84543a6186d71cd30fbc7433a6b6bbdb32",
"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/ProcessAlgebra.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/ProcessAlgebra.agda",
"max_line_length": 48,
"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/ProcessAlgebra.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": 226,
"size": 598
}
|
-- Andreas, 2018-06-10, issue #3124
-- Wrong context for error IrrelevantDatatype in the coverage checker.
data Squash (A : Set) : Prop where
squash : A → Squash A
test : ∀{A} → Squash (Squash A → A)
test = squash λ{ (squash y) → y }
-- WAS: de Bruijn index in error message
-- Expected error:
-- Cannot split on argument of irrelevant datatype (Squash .A)
-- when checking the definition of .extendedlambda0
|
{
"alphanum_fraction": 0.6987951807,
"avg_line_length": 27.6666666667,
"ext": "agda",
"hexsha": "1cb1faac6f3735b9c1f677b1fd7a0da507f1ec9f",
"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": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/Issue3124.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"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": "alhassy/agda",
"max_issues_repo_path": "test/Fail/Issue3124.agda",
"max_line_length": 70,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/Issue3124.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-07T10:49:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-07T10:49:57.000Z",
"num_tokens": 123,
"size": 415
}
|
module Categories.Topos where
|
{
"alphanum_fraction": 0.8666666667,
"avg_line_length": 15,
"ext": "agda",
"hexsha": "10f3954b1bca967aad685d54960e8cdfd9daeb1e",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Topos.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Topos.agda",
"max_line_length": 29,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Topos.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 6,
"size": 30
}
|
{-# OPTIONS --universe-polymorphism #-}
module NoBlockOnLevel where
open import Common.Level
infixr 0 _,_
record ∃ {a b} {A : Set a} (B : A → Set b) : Set (a ⊔ b) where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
open ∃
BSetoid : ∀ c → Set (lsuc c)
BSetoid c = Set c
infixr 0 _⟶_
postulate
_⟶_ : ∀ {f t} → BSetoid f → BSetoid t → Set (f ⊔ t)
→-to-⟶ : ∀ {a b} {A : Set a} {B : BSetoid b} →
(A → B) → A ⟶ B
postulate
a b p : Level
A : Set a
B : Set b
P : A → B → Set p
-- This will leave unsolved metas if we give up on an unsolved level constraint
-- when checking argument spines. Since we can't match on levels it's safe to keep
-- checking later constraints even if they depend on the unsolved levels.
f : (∃ λ x → ∃ λ y → P x y) ⟶ (∃ λ y → ∃ λ x → P x y)
f = →-to-⟶ λ p → proj₁ (proj₂ p) , proj₁ p , proj₂ (proj₂ p)
|
{
"alphanum_fraction": 0.5889145497,
"avg_line_length": 24.0555555556,
"ext": "agda",
"hexsha": "e85031af2dd7cc0661ad70648be310dcfdb4fe30",
"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/NoBlockOnLevel.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/NoBlockOnLevel.agda",
"max_line_length": 82,
"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/NoBlockOnLevel.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": 334,
"size": 866
}
|
-- Andreas, 2017-01-01, issue #2372, reported by m0davis
-- {-# OPTIONS -v tc.def.alias:100 -v tc.decl.instance:100 #-}
-- Expected error:
-- Terms marked as eligible for instance search should end with a name
-- when checking the definition of i
postulate
D : Set
instance
i = D -- NOW: Error given here (as expected).
record R : Set₁ where
field
r : Set
open R {{ ... }} public
f : r → Set₁ -- WAS: Here, confusingly, is where Agda registers its complaint.
f _ = Set
|
{
"alphanum_fraction": 0.6652977413,
"avg_line_length": 21.1739130435,
"ext": "agda",
"hexsha": "83aec6ab072c08c4865c146c5844d5217b69d9d1",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue2372.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue2372.agda",
"max_line_length": 78,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2372.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": 143,
"size": 487
}
|
-- {-# OPTIONS -v tc.conv:10 #-}
-- 2013-11-03 Reported by sanzhiyan
module Issue933 where
record RGraph : Set₁ where
field
O : Set
R : Set
refl : O -> R
module Families (Γ : RGraph) where
module Γ = RGraph Γ
record RG-Fam : Set₁ where
field
O : Γ.O -> Set
refl : ∀ {γo} -> (o : O γo) → O (Γ.refl γo)
-- "O (Γ.refl γo)" should be a type error.
-- Andreas: Fixed. SyntacticEquality wrongly just skipped projections.
|
{
"alphanum_fraction": 0.6111111111,
"avg_line_length": 18,
"ext": "agda",
"hexsha": "f94ce852bfd3905bc8754288e1e612a46bba79f7",
"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/Issue933.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/Issue933.agda",
"max_line_length": 71,
"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/Issue933.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": 155,
"size": 450
}
|
{-# OPTIONS --rewriting #-}
module Luau.StrictMode.ToString where
open import FFI.Data.String using (String; _++_)
open import Luau.StrictMode using (Warningᴱ; Warningᴮ; UnallocatedAddress; UnboundVariable; FunctionCallMismatch; FunctionDefnMismatch; BlockMismatch; app₁; app₂; BinOpMismatch₁; BinOpMismatch₂; bin₁; bin₂; block₁; return; LocalVarMismatch; local₁; local₂; function₁; function₂; heap; expr; block; addr)
open import Luau.Syntax using (Expr; val; yes; var; var_∈_; _⟨_⟩∈_; _$_; addr; number; binexp; nil; function_is_end; block_is_end; done; return; local_←_; _∙_; fun; arg; name)
open import Luau.Type using (strict)
open import Luau.TypeCheck(strict) using (_⊢ᴮ_∈_; _⊢ᴱ_∈_)
open import Luau.Addr.ToString using (addrToString)
open import Luau.Var.ToString using (varToString)
open import Luau.Type.ToString using (typeToString)
open import Luau.Syntax.ToString using (binOpToString)
warningToStringᴱ : ∀ {H Γ T} M → {D : Γ ⊢ᴱ M ∈ T} → Warningᴱ H D → String
warningToStringᴮ : ∀ {H Γ T} B → {D : Γ ⊢ᴮ B ∈ T} → Warningᴮ H D → String
warningToStringᴱ (var x) (UnboundVariable p) = "Unbound variable " ++ varToString x
warningToStringᴱ (val (addr a)) (UnallocatedAddress p) = "Unallocated adress " ++ addrToString a
warningToStringᴱ (M $ N) (FunctionCallMismatch {T = T} {U = U} p) = "Function has type " ++ typeToString T ++ " but argument has type " ++ typeToString U
warningToStringᴱ (M $ N) (app₁ W) = warningToStringᴱ M W
warningToStringᴱ (M $ N) (app₂ W) = warningToStringᴱ N W
warningToStringᴱ (function f ⟨ var x ∈ T ⟩∈ U is B end) (FunctionDefnMismatch {V = V} p) = "Function expresion " ++ varToString f ++ " has return type " ++ typeToString U ++ " but body returns " ++ typeToString V
warningToStringᴱ (function f ⟨ var x ∈ T ⟩∈ U is B end) (function₁ W) = warningToStringᴮ B W ++ "\n in function expression " ++ varToString f
warningToStringᴱ block var b ∈ T is B end (BlockMismatch {U = U} p) = "Block " ++ varToString b ++ " has type " ++ typeToString T ++ " but body returns " ++ typeToString U
warningToStringᴱ block var b ∈ T is B end (block₁ W) = warningToStringᴮ B W ++ "\n in block " ++ varToString b
warningToStringᴱ (binexp M op N) (BinOpMismatch₁ {T = T} p) = "Binary operator " ++ binOpToString op ++ " lhs has type " ++ typeToString T
warningToStringᴱ (binexp M op N) (BinOpMismatch₂ {U = U} p) = "Binary operator " ++ binOpToString op ++ " rhs has type " ++ typeToString U
warningToStringᴱ (binexp M op N) (bin₁ W) = warningToStringᴱ M W
warningToStringᴱ (binexp M op N) (bin₂ W) = warningToStringᴱ N W
warningToStringᴮ (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) (FunctionDefnMismatch {V = V} p) = "Function declaration " ++ varToString f ++ " has return type " ++ typeToString U ++ " but body returns " ++ typeToString V
warningToStringᴮ (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) (function₁ W) = warningToStringᴮ C W ++ "\n in function declaration " ++ varToString f
warningToStringᴮ (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) (function₂ W) = warningToStringᴮ B W
warningToStringᴮ (local var x ∈ T ← M ∙ B) (LocalVarMismatch {U = U} p) = "Local variable " ++ varToString x ++ " has type " ++ typeToString T ++ " but expression has type " ++ typeToString U
warningToStringᴮ (local var x ∈ T ← M ∙ B) (local₁ W) = warningToStringᴱ M W ++ "\n in local variable declaration " ++ varToString x
warningToStringᴮ (local var x ∈ T ← M ∙ B) (local₂ W) = warningToStringᴮ B W
warningToStringᴮ (return M ∙ B) (return W) = warningToStringᴱ M W ++ "\n in return statement"
|
{
"alphanum_fraction": 0.7024182077,
"avg_line_length": 87.875,
"ext": "agda",
"hexsha": "ca55888c62d2debb67b9f2880a32a8a7f8962d65",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "XanderYZZ/luau",
"max_forks_repo_path": "prototyping/Luau/StrictMode/ToString.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "XanderYZZ/luau",
"max_issues_repo_path": "prototyping/Luau/StrictMode/ToString.agda",
"max_line_length": 303,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "3f69d3a4f2b74dac8ecff2ef8ec851c8636324b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "gideros/luau",
"max_stars_repo_path": "prototyping/Luau/StrictMode/ToString.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-18T04:10:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-18T04:10:20.000Z",
"num_tokens": 1159,
"size": 3515
}
|
{-
This second-order term syntax was created from the following second-order syntax description:
syntax CommGroup | CG
type
* : 0-ary
term
unit : * | ε
add : * * -> * | _⊕_ l20
neg : * -> * | ⊖_ r40
theory
(εU⊕ᴸ) a |> add (unit, a) = a
(εU⊕ᴿ) a |> add (a, unit) = a
(⊕A) a b c |> add (add(a, b), c) = add (a, add(b, c))
(⊖N⊕ᴸ) a |> add (neg (a), a) = unit
(⊖N⊕ᴿ) a |> add (a, neg (a)) = unit
(⊕C) a b |> add(a, b) = add(b, a)
-}
module CommGroup.Syntax where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Construction.Structure
open import SOAS.ContextMaps.Inductive
open import SOAS.Metatheory.Syntax
open import CommGroup.Signature
private
variable
Γ Δ Π : Ctx
α : *T
𝔛 : Familyₛ
-- Inductive term declaration
module CG:Terms (𝔛 : Familyₛ) where
data CG : Familyₛ where
var : ℐ ⇾̣ CG
mvar : 𝔛 α Π → Sub CG Π Γ → CG α Γ
ε : CG * Γ
_⊕_ : CG * Γ → CG * Γ → CG * Γ
⊖_ : CG * Γ → CG * Γ
infixl 20 _⊕_
infixr 40 ⊖_
open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛
CGᵃ : MetaAlg CG
CGᵃ = record
{ 𝑎𝑙𝑔 = λ where
(unitₒ ⋮ _) → ε
(addₒ ⋮ a , b) → _⊕_ a b
(negₒ ⋮ a) → ⊖_ a
; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }
module CGᵃ = MetaAlg CGᵃ
module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where
open MetaAlg 𝒜ᵃ
𝕤𝕖𝕞 : CG ⇾̣ 𝒜
𝕊 : Sub CG Π Γ → Π ~[ 𝒜 ]↝ Γ
𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t
𝕊 (t ◂ σ) (old v) = 𝕊 σ v
𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)
𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v
𝕤𝕖𝕞 ε = 𝑎𝑙𝑔 (unitₒ ⋮ tt)
𝕤𝕖𝕞 (_⊕_ a b) = 𝑎𝑙𝑔 (addₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)
𝕤𝕖𝕞 (⊖_ a) = 𝑎𝑙𝑔 (negₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ CGᵃ 𝒜ᵃ 𝕤𝕖𝕞
𝕤𝕖𝕞ᵃ⇒ = record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }
; ⟨𝑣𝑎𝑟⟩ = refl
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }
where
open ≡-Reasoning
⟨𝑎𝑙𝑔⟩ : (t : ⅀ CG α Γ) → 𝕤𝕖𝕞 (CGᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)
⟨𝑎𝑙𝑔⟩ (unitₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (addₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (negₒ ⋮ _) = refl
𝕊-tab : (mε : Π ~[ CG ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)
𝕊-tab mε new = refl
𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v
module _ (g : CG ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ CGᵃ 𝒜ᵃ g) where
open MetaAlg⇒ gᵃ⇒
𝕤𝕖𝕞! : (t : CG α Γ) → 𝕤𝕖𝕞 t ≡ g t
𝕊-ix : (mε : Sub CG Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)
𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x
𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v
𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))
= trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))
𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩
𝕤𝕖𝕞! ε = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (_⊕_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (⊖_ a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
-- Syntax instance for the signature
CG:Syn : Syntax
CG:Syn = record
{ ⅀F = ⅀F
; ⅀:CS = ⅀:CompatStr
; mvarᵢ = CG:Terms.mvar
; 𝕋:Init = λ 𝔛 → let open CG:Terms 𝔛 in record
{ ⊥ = CG ⋉ CGᵃ
; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }
; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }
-- Instantiation of the syntax and metatheory
open Syntax CG:Syn public
open CG:Terms public
open import SOAS.Families.Build public
open import SOAS.Syntax.Shorthands CGᵃ public
open import SOAS.Metatheory CG:Syn public
|
{
"alphanum_fraction": 0.5246342192,
"avg_line_length": 24.9925373134,
"ext": "agda",
"hexsha": "7285ed6cd297357bba1a5d8d0a0fd30b3203332a",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/CommGroup/Syntax.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/CommGroup/Syntax.agda",
"max_line_length": 93,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/CommGroup/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 2106,
"size": 3349
}
|
module Categories.Normalise where
-- Experiments on using computation to simplify equalities
open import Level
open import Function renaming (id to idᶠ; _∘_ to _©_)
open import Data.Product
open import Categories.Support.PropositionalEquality
open import Categories.Category
import Categories.Morphisms as Mor
open import Relation.Binary hiding (_⇒_)
--open import Categories.Object.Coproduct
open import Categories.Object.BinaryCoproducts
open import Categories.Square
-- Normalizing with β and η rules for coproducts, through Yoneda
module +Reasoning {o ℓ e} (C : Category o ℓ e) (bincoprod : BinCoproducts C) where
private module C = Category C
open C using (Obj; _≡_; _⇒_; module Equiv)
open Equiv
open BinCoproducts C bincoprod
-- open BinaryCoproducts C (Bin→Binary C bincoprod) hiding ([_,_]; i₁; i₂; universal; commute₁; commute₂)
data Ty : Set o where
↑_ : Obj -> Ty
_⊎_ : Ty -> Ty -> Ty
T : Ty -> Obj
T (↑ x) = x
T (t ⊎ t₁) = T t + T t₁
data Term : Ty → Ty → Set (o ⊔ ℓ) where
#id : ∀ {A} → Term A A
#i₁ : ∀ {A B} → Term A (A ⊎ B)
#i₂ : ∀ {A B} → Term B (A ⊎ B)
#[_,_] : ∀ {A B C} → Term A C → Term B C → Term (A ⊎ B) C
_#∘_ : ∀ {A B C} → Term B C → Term A B → Term A C
`_` : ∀ {A B} → T A ⇒ T B → Term A B
↑↑ : ∀ {A B} -> A C.⇒ B -> Term (↑ A) (↑ B)
↑↑ {A} {B} f = `_` {↑ A} {↑ B} f
_#⧻_ : ∀ {A B C D} → (Term A B) → (Term C D) → (Term (A ⊎ C) (B ⊎ D))
f #⧻ g = #[ #i₁ #∘ f , #i₂ #∘ g ]
#left : ∀ {A B C} → (Term A B) → (Term (A ⊎ C) (B ⊎ C))
#left f = f #⧻ #id
#right : ∀ {A C D} → (Term C D) → (Term (A ⊎ C) (A ⊎ D))
#right g = #id #⧻ g
eval : ∀ {A B} → Term A B → T A ⇒ T B
eval #id = C.id
eval #i₁ = i₁
eval #i₂ = i₂
eval #[ t , t₁ ] = [ (eval t) , (eval t₁) ]
eval (t #∘ t₁) = eval t C.∘ eval t₁
eval ` x ` = x
module Internal where
_⇛_ : Ty → Ty → Set _
_⇛_ (↑ x) t = x ⇒ T t
_⇛_ (s ⊎ s₁) t = (s ⇛ t) × (s₁ ⇛ t)
⇛→⇒ : ∀ {A B} → A ⇛ B → T A ⇒ T B
⇛→⇒ {↑ O} f = f
⇛→⇒ {A ⊎ A₁} (f , g) = [ ⇛→⇒ {A} f , ⇛→⇒ {A₁} g ]
_<∘_ : ∀ {A B C} → T B ⇒ T C → A ⇛ B → A ⇛ C
_<∘_ {↑ x} f g = f C.∘ g
_<∘_ {A ⊎ A₁} f (g₁ , g₂) = (_<∘_ {A} f g₁) , (_<∘_ {A₁} f g₂)
.<∘-comm : ∀ {A B C} (f : T B ⇒ T C) (g : A ⇛ B) → f C.∘ (⇛→⇒ {A} g) C.≡ ⇛→⇒ {A} (_<∘_ {A} {B} {C} f g)
<∘-comm {↑ x} f g = refl
<∘-comm {A ⊎ A₁} f g = trans ∘[] ([]-cong₂ (<∘-comm f (proj₁ g)) (<∘-comm f (proj₂ g)))
mutual
j₁ : ∀ {A B} → A ⇛ (A ⊎ B)
j₁ {↑ x} = i₁
j₁ {A ⊎ A₁} = _<∘_ {A} i₁ (j₁ {A} {A₁}) , _<∘_ {A₁} i₁ (j₂ {A₁} {A})
j₂ : ∀ {B A} → B ⇛ (A ⊎ B)
j₂ {↑ x} = i₂
j₂ {B ⊎ B₁} = _<∘_ {B} i₂ (j₁ {B} {B₁}) , _<∘_ {B₁} i₂ (j₂ {B₁} {B})
id : ∀ {A} → A ⇛ A
id {↑ x} = C.id
id {A ⊎ A₁} = j₁ {A} {A₁} , j₂ {A₁} {A}
⇒→⇛ : ∀ {A B} → T A ⇒ T B → A ⇛ B
⇒→⇛ {↑ x} f = f
⇒→⇛ {A ⊎ A₁} f = _<∘_ {A} f (j₁ {A} {A₁}) , _<∘_ {A₁} f (j₂ {A₁} {A})
mutual
.j₁≡i₁ : ∀ {A B} → ⇛→⇒ {A} (j₁ {A} {B}) C.≡ i₁
j₁≡i₁ {↑ x} = refl
j₁≡i₁ {A ⊎ A₁} = universal (trans (C.∘-resp-≡ʳ (sym (j₁≡i₁ {A} {A₁}))) (<∘-comm {A} i₁ (j₁ {A} {A₁})))
(trans (C.∘-resp-≡ʳ (sym (j₂≡i₂ {A₁} {A}))) (<∘-comm {A₁} i₁ (j₂ {A₁} {A})))
.j₂≡i₂ : ∀ {B A} → ⇛→⇒ {B} (j₂ {B} {A}) C.≡ i₂
j₂≡i₂ {↑ x} = refl
j₂≡i₂ {A ⊎ A₁} = universal (trans (C.∘-resp-≡ʳ (sym (j₁≡i₁ {A} {A₁}))) (<∘-comm {A} i₂ (j₁ {A} {A₁})))
(trans (C.∘-resp-≡ʳ (sym (j₂≡i₂ {A₁} {A})))
(<∘-comm {A₁} i₂ (j₂ {A₁} {A})))
.iso₁-⇒⇛ : ∀ {A B} → (f : T A ⇒ T B) → ⇛→⇒ {A} {B} (⇒→⇛ {A} {B} f) ≡ f
iso₁-⇒⇛ {↑ x} f = refl
iso₁-⇒⇛ {A ⊎ A₁} {B} f = universal (trans (C.∘-resp-≡ʳ (sym j₁≡i₁)) (<∘-comm {A} {A ⊎ A₁} {B} f (j₁ {A})))
(trans (C.∘-resp-≡ʳ (sym j₂≡i₂)) (<∘-comm {A₁} {A ⊎ A₁} {B} f (j₂ {A₁})))
.id≡id : ∀ A → ⇛→⇒ {A} (id {A}) ≡ C.id
id≡id (↑ x) = refl
id≡id (A ⊎ A₁) = universal (trans C.identityˡ (sym j₁≡i₁)) (trans C.identityˡ (sym j₂≡i₂))
_∘_ : ∀ {A B C} → B ⇛ C → A ⇛ B → A ⇛ C
_∘_ {↑ x} {B} f g = ⇛→⇒ {B} f C.∘ g
_∘_ {A ⊎ A₁} f (g₁ , g₂) = (_∘_ {A} f g₁) , (_∘_ {A₁} f g₂)
.∘-comm : ∀ {A B C} (f : B ⇛ C) (g : A ⇛ B) → (⇛→⇒ {B} f) C.∘ (⇛→⇒ {A} g) C.≡ ⇛→⇒ {A} (_∘_ {A} {B} {C} f g)
∘-comm {↑ x} f g = refl
∘-comm {A ⊎ A₁} f g = trans ∘[] ([]-cong₂ (∘-comm f (proj₁ g)) (∘-comm f (proj₂ g)))
-- An η-expanded version of C
Cη : Category _ _ _
Cη = record
{ Obj = Ty
; _⇒_ = _⇛_
; _≡_ = λ {A} f g → ⇛→⇒ {A} f ≡ ⇛→⇒ {A} g
; _∘_ = λ {A} {B} {C} → _∘_ {A} {B} {C}
; id = λ {X} → id {X}
; assoc = λ {A} {B} {C} {D} {f} {g} {h} →
trans (sym (∘-comm {A} {B} {D} (h ∘ g) f))
(trans (C.∘-resp-≡ˡ (sym (∘-comm {B} {C} {D} h g)))
(trans C.assoc
(trans (C.∘-resp-≡ʳ (∘-comm {A} {B} {C} g f))
(∘-comm {A} {C} {D} h (g ∘ f)))))
; identityˡ = λ {A} {B} {f} → trans (sym (∘-comm {A} {B} {B} id f))
(trans (C.∘-resp-≡ˡ (id≡id B)) C.identityˡ)
; identityʳ = λ {A} {B} {f} →
trans (sym (∘-comm {A} {A} {B} f id))
(trans (C.∘-resp-≡ʳ (id≡id A)) C.identityʳ)
; equiv = record
{ refl = refl
; sym = sym
; trans = trans
}
; ∘-resp-≡ = λ {A} {B} {C} {f} {h} {g} {i} f≡h g≡i →
trans (sym (∘-comm {A} {B} {C} f g)) (trans (C.∘-resp-≡ f≡h g≡i) (∘-comm {A} {B} {C} h i))
}
module Cη = Category Cη
-- We need the opposite category for Yon because i₁ and i₂ simplify when precomposed.
-- Using Eda seems to undo the simplifications instead.
open Yon-Eda (Category.op Cη)
Yon-i₁ : ∀ {A B} → Yon (A ⊎ B) A
Yon-i₁ {A} {B} = record
{ arr = j₁ {A} {B}
; fun = proj₁
; ok = λ {W} f → trans (trans (sym commute₁) (C.∘-resp-≡ʳ (sym (j₁≡i₁ {A} {B})))) (∘-comm {A} {A ⊎ B} {W} f (j₁ {A} {B}))
}
Yon-i₂ : ∀ {A B} → Yon (A ⊎ B) B
Yon-i₂ {A} {B} = record
{ arr = j₂ {B} {A}
; fun = proj₂
; ok = λ {W} f →
trans (trans (sym commute₂) (C.∘-resp-≡ʳ (sym (j₂≡i₂ {B} {A}))))
(∘-comm {B} {A ⊎ B} {W} f (j₂ {B} {A}))
}
Yon-[_,_] : ∀ {A B C} → Yon C A → Yon C B → Yon C (A ⊎ B)
Yon-[_,_] f g = record
{ arr = (Yon.arr f) , (Yon.arr g)
; fun = λ f₁ → (Yon.fun f f₁) , (Yon.fun g f₁)
; ok = λ f₁ → []-cong₂ (Yon.ok f f₁) (Yon.ok g f₁)
}
eeval : ∀ {A B} → Term A B → Yon B A
eeval #id = Yon-id
eeval #i₁ = Yon-i₁
eeval #i₂ = Yon-i₂
eeval #[ t , t₁ ] = Yon-[ (eeval t) , (eeval t₁) ]
eeval (t #∘ t₁) = Yon-compose (eeval t₁) (eeval t)
eeval {A} ` f ` = Yon-inject (⇒→⇛ {A} f)
yeeval : ∀ {A B} → Term A B → T A ⇒ T B
yeeval {A} {B} t = ⇛→⇒ {A} (Yon.arr (eeval t))
.yeeval≡eval : ∀ {A B} → (f : Term A B) → yeeval f ≡ eval f
yeeval≡eval #id = id≡id _
yeeval≡eval {A} #i₁ = j₁≡i₁ {A}
yeeval≡eval {A} #i₂ = j₂≡i₂ {A}
yeeval≡eval ` x ` = iso₁-⇒⇛ x
yeeval≡eval #[ f , f₁ ] = []-cong₂ (yeeval≡eval f) (yeeval≡eval f₁)
yeeval≡eval (f #∘ f₁) = trans
(trans (Yon.ok (eeval f₁) (Yon.arr (eeval f)))
(sym (∘-comm (Yon.arr (eeval f)) (Yon.arr (eeval f₁)))))
(C.∘-resp-≡ (yeeval≡eval f) (yeeval≡eval f₁))
+reasoning : NormReasoning C o (ℓ ⊔ o)
+reasoning = record
{ U = Ty
; T = T
; _#⇒_ = Term
; eval = eval
; norm = yeeval
; norm≡eval = yeeval≡eval }
open NormReasoning Internal.+reasoning public hiding (T; eval)
|
{
"alphanum_fraction": 0.4049566295,
"avg_line_length": 36.6818181818,
"ext": "agda",
"hexsha": "28d735af0e3a68a63097ada1afb54241441e8680",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Normalise.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Normalise.agda",
"max_line_length": 142,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Normalise.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 3862,
"size": 8070
}
|
-- The bug appeared since I forgot to keep the constraint when trying to unify
-- a blocked term (I just didn't instantiate).
module LostConstraint where
infixr 10 _==>_ _=>_
data Setoid : Set1 where
setoid : Set -> Setoid
El : Setoid -> Set
El (setoid A) = A
eq : (A : Setoid) -> El A -> El A -> Set
eq (setoid A) = e
where
postulate e : (x, y : A) -> Set
data _=>_ (A,B : Setoid) : Set where
lam : (f : El A -> El B)
-> ((x : El A) -> eq A x x
-> eq B (f x) (f x)
)
-> A => B
app : {A,B : Setoid} -> (A => B) -> El A -> El B
app (lam f _) = f
postulate EqFun : {A,B : Setoid}(f, g : A => B) -> Set
lam2 : {A,B,C : Setoid} ->
(f : El A -> El B -> El C) ->
(x : El A) -> B => C
lam2 {A}{B}{C} f x = lam (f x) (lem _)
where
postulate
lem : (x : El A)(y : El B) -> eq B y y -> eq C (f x y) (f x y)
|
{
"alphanum_fraction": 0.4612903226,
"avg_line_length": 23.8461538462,
"ext": "agda",
"hexsha": "673356f5bff923e9b067bcd7a7bf7b860b4bdd3d",
"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": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/bugs/fixed/LostConstraint.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"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": "alhassy/agda",
"max_issues_repo_path": "test/bugs/fixed/LostConstraint.agda",
"max_line_length": 78,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/bugs/fixed/LostConstraint.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": 343,
"size": 930
}
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.Functor.Diagonal where
open import Data.Product
open import Categories.Category
open import Categories.Functor
open import Categories.Product
open import Categories.FunctorCategory
open import Categories.Functor.Constant
import Categories.Power as Power
Δ : ∀ {o ℓ e} → (C : Category o ℓ e) → Functor C (Product C C)
Δ C = record
{ F₀ = λ x → x , x
; F₁ = λ f → f , f
; identity = refl , refl
; homomorphism = refl , refl
; F-resp-≡ = λ x → x , x
}
where
open Category C
open Equiv
Δ′ : ∀ {o ℓ e} → (I : Set) → (C : Category o ℓ e) → Functor C (Power.Exp C I)
Δ′ I C = record
{ F₀ = λ x _ → x
; F₁ = λ f _ → f
; identity = λ _ → refl
; homomorphism = λ _ → refl
; F-resp-≡ = λ x _ → x
}
where
open Power C
open Category C
open Equiv
ΔF : ∀ {o ℓ e o₁ ℓ₁ e₁} {C : Category o ℓ e} (I : Category o₁ ℓ₁ e₁) → Functor C (Functors I C)
ΔF {C = C} I = record
{ F₀ = λ c → Constant c
; F₁ = λ f → record { η = λ X → f; commute = λ g → trans C.identityʳ (sym C.identityˡ) }
; identity = refl
; homomorphism = refl
; F-resp-≡ = λ x → x
}
where
module C = Category C
open C.Equiv
module I = Category I
|
{
"alphanum_fraction": 0.6080525883,
"avg_line_length": 23.862745098,
"ext": "agda",
"hexsha": "314adc4507da08e8aafe6fb0d8a935cd6346bc1e",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Functor/Diagonal.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Functor/Diagonal.agda",
"max_line_length": 95,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Functor/Diagonal.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 449,
"size": 1217
}
|
record R : Set₁ where
field
A : Set
B : Set
B = A
field
C : Set
D : Set
D = A → B → C
|
{
"alphanum_fraction": 0.4403669725,
"avg_line_length": 8.3846153846,
"ext": "agda",
"hexsha": "34f3cd1ff1b2773e762dab67b34728f6b2c50638",
"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/Issue3020.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/Issue3020.agda",
"max_line_length": 21,
"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/Issue3020.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": 47,
"size": 109
}
|
module Extended.FunRetRec where
open import Function
open import Data.Nat
open import Data.Nat.Properties.Simple
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Data.String
open import Data.Product
open import Data.Bool renaming (not to bnot) hiding (if_then_else_)
open import Relation.Nullary.Decidable
open import Relation.Nullary
open import Data.List hiding (and; or)
open import Data.List.Properties using (∷-injective)
open import Data.Empty
open import Data.Unit
import Level as L
open import Utils.Decidable
open import Utils.Monoid
open import Utils.NatOrdLemmas
{-
This module contains an extension of the While language and assorted semantics.
It incorporates some of the suggested extra features in the book.
The extra features in short:
- Function calls and recursive local function declarations
- Local variable declarations
- String-based bindings with name shadowing
- Return statements with the usual jump in control flow
-}
-- Data definitions
--------------------------------------------------
data Ty : Set where
bool nat : Ty
⟦_⟧ᵗ : Ty → Set
⟦ nat ⟧ᵗ = ℕ
⟦ bool ⟧ᵗ = Bool
data Exp : Ty → Set where
lit : ℕ → Exp nat
add mul sub : Exp nat → Exp nat → Exp nat
var : String → Exp nat
{-
Function calls. Note that we have calls as a proper *expression* that
evaluate to a value, if they terminate. This also implies that the evaluation
of expressions has a partial semantics just like statements.
We apply a function to a list of arguments. The number of args must be correct.
-}
_$:_ : String → List (Exp nat) → Exp nat
tt ff : Exp bool
eq lt lte : Exp nat → Exp nat → Exp bool
and : Exp bool → Exp bool → Exp bool
not : Exp bool → Exp bool
or : Exp bool → Exp bool → Exp bool
infixr 4 _,_
infixr 5 _:=_
data St : Set where
{- Function declarations. We specify the arguments as a list of bindings.
They are recursive. -}
fun : String → List String → St → St → St
{- variable declarations -}
decl : String → Exp nat → St → St
_:=_ : String → Exp nat → St
skip : St
_,_ : St → St → St
if_then_else_ : Exp bool → St → St → St
while_do_ : Exp bool → St → St
ret : Exp nat → St
{- The environment contains numbers and functions -}
data Entry : Set where
nat : ℕ → Entry
fun : List String → St → Entry
{- The environment is now keyed by strings (rather than de Bruijn indices) -}
Env : Set
Env = List (String × Entry)
_,ₙ_ : String → ℕ → (String × Entry)
v ,ₙ n = v , nat n
infixr 5 _,ₙ_
{-
A note on the return statement:
The book recommends two way for dealing with exceptions and jumps.
One way is to use small-step semantics. The other way is to introduce new program
states in big-step semantics. With more complicated derivation rules and many
types of non-local effects (and of course non-determinism), small-step semantics
seems to be more manageable.
But here we have just the return statement, so big-step semantics seems fine.
-}
data State : Set where
ok : Env → State
ret : ℕ → State
ret-inj : ∀ {a b} → (State ∋ ret a) ≡ ret b → a ≡ b
ret-inj refl = refl
ok-inj : ∀ {s s'} → ok s ≡ ok s' → s ≡ s'
ok-inj refl = refl
-- Well-scopedness
--------------------------------------------------
{-
Scoping rules are nontrivial, but we don't want to clutter our derivations
with explicit proofs for them.
A standard Agda solution for this is to use so-called irrelevant proofs. Such
types have at most a single value up to definitional equality, therefore they
cannot influence actual computation. Agda is willing to automatically fill in
the value for some of these types once it becomes apparent that the value exists.
The simplest example of a irrelevant type is the unit type.
record ⊤ : Set where constructor tt.
Agda has eta-extensionality for records, so Agda thinks that any value of
type ⊤ is definitionally equal to "tt".
The well-scopedness predicates below all compute to ⊤ or ⊥ (the unprovable type),
and both are irrelevant, so we get all the scoping proofs nicely inferred
and hidden.
We also augment our inference system with judicious use of instance arguments.
Agda tries to search for suitable values for these arguments from the current scope.
-}
------------------------------------------------------------
{-
A note on static semantics:
Arguably, well-scopedness should belong to static semantics. After all,
it can be checked without running the program, and in real compilers
scope checking also tends to be done statically.
Here, we don't *have* static semantics at all. The static semantic rules are baked into
the dynamic semantic rules. Adding proper static semantics would be one of the many potential
extensions and improvements to this library.
Ideally, we would have a completely raw AST, and an AST for code that is correct
with respect to static semantics (so it's annotated with proofs of static correctness).
We would also have a type checker function that would decide if a raw AST can be converted
to the correct AST. It would also nice to have a type erasure function that goes in the opposite
direction (erases proofs and returns a raw AST), and we could establish correctness of type
checking with respect to erasure, for example by proving that checking is the left inverse
of erasure.
It may be also the case, although I haven't tested it, that type checking would be faster
with a separate checked AST.
-}
-- variable is in scope
InScopeVar : String → Env → Set
InScopeVar v [] = ⊥
InScopeVar v ((_ , fun _ _) ∷ s) = InScopeVar v s
InScopeVar v ((v' , nat n) ∷ s) with v ≡⁇ v'
... | yes _ = ⊤
... | no _ = InScopeVar v s
-- function is in scope
InScopeFun : String → Env → Set
InScopeFun v [] = ⊥
InScopeFun v ((_ , nat _) ∷ s) = InScopeFun v s
InScopeFun v ((v' , fun _ _) ∷ s) with v ≡⁇ v'
... | yes _ = ⊤
... | no _ = InScopeFun v s
lookupVar : ∀ v s ⦃ _ : InScopeVar v s ⦄ → ℕ
lookupVar v [] ⦃ ⦄
lookupVar v ((_ , fun _ _) ∷ s) = lookupVar v s
lookupVar v ((v' , nat n) ∷ s) with v ≡⁇ v'
... | yes _ = n
... | no _ = lookupVar v s
lookupFun : ∀ f s ⦃ _ : InScopeFun f s ⦄ → List String × St
lookupFun v [] ⦃ ⦄
lookupFun v ((_ , nat _) ∷ s) = lookupFun v s
lookupFun v ((v' , fun args body) ∷ s) with v ≡⁇ v'
... | yes _ = args , body
... | no _ = lookupFun v s
-- perform a substitution on the environment at a name that is in scope
_[_]≔_ : ∀ s v ⦃ _ : InScopeVar v s ⦄ → ℕ → Env
_[_]≔_ [] _ ⦃ ⦄ _
_[_]≔_ ((v' , fun args body) ∷ s) v n = (v' , fun args body) ∷ (s [ v ]≔ n)
((v' , nat n) ∷ Γ) [ v ]≔ n' with v ≡⁇ v'
... | yes p = (v' , nat n') ∷ Γ
... | no ¬p = (v' , nat n ) ∷ Γ [ v ]≔ n'
-- Match the length of two lists
ArgLenMatch : List String → List ℕ → Set
ArgLenMatch [] [] = ⊤
ArgLenMatch [] (_ ∷ _) = ⊥
ArgLenMatch (_ ∷ names) [] = ⊥
ArgLenMatch (_ ∷ names) (_ ∷ vals) = ArgLenMatch names vals
-- Create a new environment with the function arguments pushed to the front
callWith : ∀ args vals ⦃ _ : ArgLenMatch args vals ⦄ → Env
callWith [] [] = []
callWith [] (_ ∷ _) ⦃ ⦄
callWith (_ ∷ _) [] ⦃ ⦄
callWith (n ∷ names) (v ∷ vals) = (n , nat v) ∷ callWith names vals
-- Semantics
--------------------------------------------------
mutual
-- Evaluation of argument lists
infixr 5 _∷_
data _⟨_⟩ᵃ⟱_ (s : Env) : List (Exp nat) → List ℕ → Set where
[] :
----------------
s ⟨ [] ⟩ᵃ⟱ []
_∷_ :
∀ {a args v vals} →
s ⟨ a ⟩ᵉ⟱ v → s ⟨ args ⟩ᵃ⟱ vals
→ ---------------------------------
s ⟨ a ∷ args ⟩ᵃ⟱ (v ∷ vals)
-- Shorthand for the evaluation of binary expressions
BinExp : ∀ {s t r} → (Exp t → Exp t → Exp r) → (⟦ t ⟧ᵗ → ⟦ t ⟧ᵗ → ⟦ r ⟧ᵗ) → Set
BinExp {s} cons op =
∀ {a b va vb} →
s ⟨ a ⟩ᵉ⟱ va → s ⟨ b ⟩ᵉ⟱ vb
-----------------------------
→ s ⟨ cons a b ⟩ᵉ⟱ (op va vb)
-- Evaluation of expressions
data _⟨_⟩ᵉ⟱_ (s : Env) : ∀ {t} → Exp t → ⟦ t ⟧ᵗ → Set where
add : BinExp add _+_
eq : BinExp eq (λ a b → ⌊ a ≡⁇ b ⌋)
lt : BinExp lt (λ a b → ⌊ suc a ≤⁇ b ⌋)
lte : BinExp lte (λ a b → ⌊ a ≤⁇ b ⌋)
and : BinExp and _∧_
or : BinExp or _∨_
mul : BinExp mul _*_
sub : BinExp sub _∸_
tt : s ⟨ tt ⟩ᵉ⟱ true
ff : s ⟨ ff ⟩ᵉ⟱ false
lit : ∀ {n} → s ⟨ lit n ⟩ᵉ⟱ n
not : ∀ {e b} → s ⟨ e ⟩ᵉ⟱ b → s ⟨ not e ⟩ᵉ⟱ bnot b
var :
∀ {v in-scope}
→ ----------------------------
s ⟨ var v ⟩ᵉ⟱ lookupVar v s
{- Evaluation of function calls -}
_$:_ :
{retVal : ℕ}
{argVals : List ℕ}
{f : String} -- if we have a function
{args : List (Exp nat)} -- and a list of arguments
⦃ in-scope-f : InScopeFun f s ⦄ -- and the function is in scope
→ let func = lookupFun f s
argNames = proj₁ func
body = proj₂ func in
s ⟨ args ⟩ᵃ⟱ argVals -- we can evaluate the arguments
→ ⦃ arg-len-match : ArgLenMatch argNames argVals ⦄ -- and the number of arguments is correct
-- note the recursive occurence in the call environement ⇓
→ let callEnv = callWith argNames argVals <> [ (f , fun argNames body) ] in
⟨ body , ok callEnv ⟩⟱ ret retVal
→ ----------------------------------- -- then a function call evaluates to the return value
s ⟨ f $: args ⟩ᵉ⟱ retVal -- of the function body evaluated in the call environment
-- Evaluation of statements
data ⟨_,_⟩⟱_ : St → State → State → Set where
fun :
∀ {x s s' S args body} →
⟨ S , ok ((x , fun args body) ∷ s) ⟩⟱ ok ((x , fun args body) ∷ s')
→ -------------------------------------------------------------------
⟨ fun x args body S , ok s ⟩⟱ ok s'
{-- This rule propagates ("rethrows") the return statement's effect if it happens inside the
scope of the function declaration --}
fun-ret :
∀ {x s r S args body} →
⟨ S , ok ((x , fun args body) ∷ s) ⟩⟱ ret r
→ --------------------------------------------
⟨ fun x args body S , ok s ⟩⟱ ret r
{- variable declarations -}
decl :
∀ {s s' S x e eVal e'} →
s ⟨ e ⟩ᵉ⟱ eVal →
⟨ S , ok ((x , nat eVal) ∷ s) ⟩⟱ (ok ((x , e') ∷ s'))
→ ----------------------------------------------------
⟨ decl x e S , ok s ⟩⟱ ok s'
{- variable declarations propagating the return statement -}
decl-ret :
∀ {r s S x e eVal} →
s ⟨ e ⟩ᵉ⟱ eVal →
⟨ S , ok ((x , nat eVal) ∷ s) ⟩⟱ ret r
→ ---------------------------------------
⟨ decl x e S , ok s ⟩⟱ ret r
ret :
∀ {e eVal s}
→ s ⟨ e ⟩ᵉ⟱ eVal
→ ---------------------------
⟨ ret e , ok s ⟩⟱ ret eVal
ass :
∀ {s e eVal x in-scope} →
s ⟨ e ⟩ᵉ⟱ eVal
→ --------------------------------------
⟨ x := e , ok s ⟩⟱ ok (s [ x ]≔ eVal)
skip :
∀ {s}
→ -----------------
⟨ skip , s ⟩⟱ s
_,_ :
∀ {s₁ s₂ s₃ S₁ S₂} →
⟨ S₁ , s₁ ⟩⟱ ok s₂ → ⟨ S₂ , ok s₂ ⟩⟱ s₃
→ --------------------------------------
⟨ (S₁ , S₂ ) , s₁ ⟩⟱ s₃
{-- If we return in the left statement of a composite statement,
then we ignore the right statement and just return -}
_ret,_ :
∀ {x s₁ s₂ S₁ S₂} →
⟨ S₁ , s₁ ⟩⟱ ret x → ⟨ S₂ , ret x ⟩⟱ s₂
→ ---------------------------------------
⟨ (S₁ , S₂ ) , s₁ ⟩⟱ ret x
if-true :
∀ {s s' S₁ S₂ b} →
s ⟨ b ⟩ᵉ⟱ true → ⟨ S₁ , ok s ⟩⟱ s'
→ ------------------------------------
⟨ if b then S₁ else S₂ , ok s ⟩⟱ s'
if-false :
∀ {s s' S₁ S₂ b} →
s ⟨ b ⟩ᵉ⟱ false → ⟨ S₂ , ok s ⟩⟱ s'
→ -------------------------------------
⟨ if b then S₁ else S₂ , ok s ⟩⟱ s'
while-true :
∀ {s s' s'' S b} →
s ⟨ b ⟩ᵉ⟱ true → ⟨ S , ok s ⟩⟱ s' → ⟨ while b do S , s' ⟩⟱ s''
→ ------------------------------------------------------------------
⟨ while b do S , ok s ⟩⟱ s''
while-false :
∀ {s S b} →
s ⟨ b ⟩ᵉ⟱ false
→ ------------------------------
⟨ while b do S , ok s ⟩⟱ ok s
substExp : ∀ {t s}{e : Exp t}{v v'} → v ≡ v' → s ⟨ e ⟩ᵉ⟱ v → s ⟨ e ⟩ᵉ⟱ v'
substExp refl p2 = p2
-- State transition is deterministic
--------------------------------------------------
deterministic : ∀ {S s s' s''} → ⟨ S , s ⟩⟱ s' → ⟨ S , s ⟩⟱ s'' → s' ≡ s''
deterministic = st where
mutual
args : ∀ {s as vs vs'} → s ⟨ as ⟩ᵃ⟱ vs → s ⟨ as ⟩ᵃ⟱ vs' → vs ≡ vs'
args [] [] = refl
args (x ∷ p1) (x₁ ∷ p2) rewrite exp x x₁ | args p1 p2 = refl
exp : ∀ {t s}{e : Exp t}{v v'} → s ⟨ e ⟩ᵉ⟱ v → s ⟨ e ⟩ᵉ⟱ v' → v ≡ v'
exp (add p1 p2) (add p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl
exp (sub p1 p2) (sub p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl
exp (eq p1 p2) (eq p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl
exp (lt p1 p2) (lt p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl
exp (lte p1 p2) (lte p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl
exp (and p1 p2) (and p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl
exp (or p1 p2) (or p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl
exp (mul p1 p2) (mul p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl
exp tt tt = refl
exp ff ff = refl
exp lit lit = refl
exp (not p1) (not p2) rewrite exp p1 p2 = refl
exp var var = refl
exp (_$:_ ae be) (_$:_ ae' be') rewrite args ae ae' = ret-inj (st be be')
st : ∀ {S s s' s''} → ⟨ S , s ⟩⟱ s' → ⟨ S , s ⟩⟱ s'' → s' ≡ s''
st (fun p1) (fun p2) = cong ok $ proj₂ $ ∷-injective $ ok-inj $ st p1 p2
st (fun p1) (fun-ret p2) with st p1 p2
... | ()
st (fun-ret p1) (fun p2) with st p1 p2
... | ()
st (fun-ret p1) (fun-ret p2) = st p1 p2
st (decl x₁ p1) (decl x₂ p2) rewrite
exp x₁ x₂ = cong ok $ proj₂ $ ∷-injective $ ok-inj $ st p1 p2
st (decl x₁ p1) (decl-ret x₂ p2) rewrite exp x₁ x₂ with st p1 p2
... | ()
st (decl-ret x₁ p1) (decl x₂ p2) rewrite exp x₁ x₂ with st p1 p2
... | ()
st (decl-ret x₁ p1) (decl-ret x₂ p2) rewrite exp x₁ x₂ = st p1 p2
st (ret x) (ret x₁) rewrite exp x x₁ = refl
st (ass x₁) (ass x₂) rewrite exp x₁ x₂ = refl
st skip skip = refl
st (p1 , p2) (p3 , p4) rewrite st p1 p3 = st p2 p4
st (p1 , p2) (p3 ret, p4) with st p1 p3
... | ()
st (p1 ret, p2) (p3 , p4) with st p1 p3
... | ()
st (p1 ret, p2) (p3 ret, p4) = st p1 p3
st (if-true x p1) (if-true x₁ p2) rewrite st p1 p2 = refl
st (if-true x p1) (if-false x₁ p2) with exp x₁ x
... | ()
st (if-false x p1) (if-true x₁ p2) with exp x x₁
... | ()
st (if-false x p1) (if-false x₁ p2) rewrite st p1 p2 = refl
st (while-true x p1 p2) (while-true x₁ p3 p4) rewrite st p1 p3 | st p2 p4 = refl
st (while-true x p1 p2) (while-false x₁) with exp x x₁
... | ()
st (while-false x) (while-true x₁ p2 p3) with exp x x₁
... | ()
st (while-false x) (while-false x₁) = refl
-- Divergence
--------------------------------------------------
_divergesOn_ : St → State → Set
prog divergesOn s = ∀ {s'} → ¬ ⟨ prog , s ⟩⟱ s'
Divergent : St → Set
Divergent prog = ∀ {s} → prog divergesOn s
private
inf-loop : Divergent (while tt do skip)
inf-loop (while-true tt p p₁) = inf-loop p₁
inf-loop (while-false ())
-- Semantic equivalence
--------------------------------------------------
_⇔_ : ∀ {a b} → Set a → Set b → Set (a L.⊔ b)
A ⇔ B = (A → B) × (B → A)
SemanticEq : St → St → Set
SemanticEq pa pb = ∀ {s s'} → ⟨ pa , s ⟩⟱ s' ⇔ ⟨ pb , s ⟩⟱ s'
Semantic⇒ : St → St → Set
Semantic⇒ pa pb = ∀ {s s'} → ⟨ pa , s ⟩⟱ s' → ⟨ pb , s ⟩⟱ s'
-- -- Correctness of factorial programs
-- --------------------------------------------------
private
--- Semantics in meta-langauge
⟦fac⟧ : ℕ → ℕ
⟦fac⟧ zero = 1
⟦fac⟧ (suc n) = suc n * ⟦fac⟧ n
-- 1. Correctness of recursive definition
fac-rec-body : St
fac-rec-body =
if lte (var "n") (lit 0) then
(ret (lit 1))
else
(ret (mul (var "n") ("fac" $: [ sub (var "n") (lit 1) ] )))
fac-rec : St
fac-rec =
fun "fac" [ "n" ] fac-rec-body
(ret ("fac" $: [ var "n" ]))
fac-rec-body-ok :
∀ n
→ ⟨ fac-rec-body ,
ok (("n" ,ₙ n) ∷ ("fac" , fun [ "n" ] fac-rec-body) ∷ []) ⟩⟱
ret (⟦fac⟧ n)
fac-rec-body-ok zero = if-true (lte var lit) (ret lit)
fac-rec-body-ok (suc n) =
if-false (lte var lit)
(ret (mul var ((sub var lit ∷ []) $: (fac-rec-body-ok n))))
fac-rec-ok :
∀ n → ⟨ fac-rec , ok [ ("n" ,ₙ n) ] ⟩⟱ ret (⟦fac⟧ n)
fac-rec-ok n = fun-ret (ret ((var ∷ []) $: (fac-rec-body-ok n)))
-- 2. Correctness of procedural definition
fac-loop : St
fac-loop =
while lt (var "i") (var "n") do (
"i" := add (lit 1) (var "i") ,
"acc" := mul (var "i") (var "acc")
)
fac-proc : St
fac-proc =
fun "fac" ( "n" ∷ []) (
decl "i" (lit 0) (
decl "acc" (lit 1) (
fac-loop ,
ret (var "acc") )))
(ret ("fac" $: [ var "n" ]))
fac-loop-ok :
∀ {s} d i
→ ⟨ fac-loop ,
ok (("acc",ₙ ⟦fac⟧ i) ∷ ("i",ₙ i ) ∷ ("n",ₙ d + i) ∷ s) ⟩⟱
ok (("acc",ₙ ⟦fac⟧ (d + i)) ∷ ("i",ₙ d + i) ∷ ("n",ₙ d + i) ∷ s)
fac-loop-ok zero i = while-false (substExp (¬A→≡false (a≮a i)) (lt var var))
fac-loop-ok (suc d) i with fac-loop-ok d (suc i)
... | next rewrite +-suc d i =
while-true (substExp (A→≡true (a<sb+a i d)) (lt var var))
( ass (add lit var) ,
ass (mul var var))
next
fac-proc-ok :
∀ n → ⟨ fac-proc , ok (("n",ₙ n) ∷ []) ⟩⟱ ret (⟦fac⟧ n)
fac-proc-ok n with fac-loop-ok n 0
... | loop-ok rewrite +-comm n 0 =
fun-ret (ret ((var ∷ []) $:
decl-ret lit (
decl-ret lit
(loop-ok ,
ret var))))
|
{
"alphanum_fraction": 0.5130984151,
"avg_line_length": 32.3257042254,
"ext": "agda",
"hexsha": "d724e9ea5b791ed74ea1d879d7605cf9eb3b1694",
"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": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AndrasKovacs/SemanticsWithApplications",
"max_forks_repo_path": "Extended/FunRetRec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"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": "AndrasKovacs/SemanticsWithApplications",
"max_issues_repo_path": "Extended/FunRetRec.agda",
"max_line_length": 103,
"max_stars_count": 8,
"max_stars_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AndrasKovacs/SemanticsWithApplications",
"max_stars_repo_path": "Extended/FunRetRec.agda",
"max_stars_repo_stars_event_max_datetime": "2020-02-02T10:01:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-09-12T04:25:39.000Z",
"num_tokens": 6161,
"size": 18361
}
|
-- We define ZigZag-complete relations and prove that quasi equivalence relations
-- give rise to equivalences on the set quotients.
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.ZigZag.Base where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.HITs.SetQuotients
open import Cubical.HITs.PropositionalTruncation as Trunc
open import Cubical.Relation.Binary.Base
open isEquivRel
private
variable
ℓ ℓ' : Level
isZigZagComplete : {A B : Type ℓ} (R : A → B → Type ℓ') → Type (ℓ-max ℓ ℓ')
isZigZagComplete R = ∀ {a b a' b'} → R a b → R a' b → R a' b' → R a b'
ZigZagRel : (A B : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
ZigZagRel A B ℓ' = Σ[ R ∈ (A → B → Type ℓ') ] (isZigZagComplete R)
record isQuasiEquivRel {A B : Type ℓ} (R : A → B → Type ℓ') : Type (ℓ-max ℓ ℓ') where
field
zigzag : isZigZagComplete R
fwd : (a : A) → ∃[ b ∈ B ] R a b
bwd : (b : B) → ∃[ a ∈ A ] R a b
open isQuasiEquivRel
QuasiEquivRel : (A B : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
QuasiEquivRel A B ℓ' =
Σ[ R ∈ PropRel A B ℓ' ] isQuasiEquivRel (R .fst)
invQER : {A B : Type ℓ} {ℓ' : Level} → QuasiEquivRel A B ℓ' → QuasiEquivRel B A ℓ'
invQER (R , qer) .fst = invPropRel R
invQER (R , qer) .snd .zigzag aRb aRb' a'Rb' = qer .zigzag a'Rb' aRb' aRb
invQER (R , qer) .snd .fwd = qer .bwd
invQER (R , qer) .snd .bwd = qer .fwd
QER→EquivRel : {A B : Type ℓ}
→ QuasiEquivRel A B ℓ' → EquivPropRel A (ℓ-max ℓ ℓ')
QER→EquivRel (R , sim) .fst = compPropRel R (invPropRel R)
QER→EquivRel (R , sim) .snd .reflexive a = Trunc.map (λ {(b , r) → b , r , r}) (sim .fwd a)
QER→EquivRel (R , sim) .snd .symmetric _ _ = Trunc.map (λ {(b , r₀ , r₁) → b , r₁ , r₀})
QER→EquivRel (R , sim) .snd .transitive _ _ _ =
Trunc.map2 (λ {(b , r₀ , r₁) (b' , r₀' , r₁') → b , r₀ , sim .zigzag r₁' r₀' r₁})
-- The following result is due to Carlo Angiuli
module QER→Equiv {A B : Type ℓ} (R : QuasiEquivRel A B ℓ') where
Rᴸ = QER→EquivRel R .fst .fst
Rᴿ = QER→EquivRel (invQER R) .fst .fst
private
sim = R .snd
private
f : (a : A) → ∃[ b ∈ B ] R .fst .fst a b → B / Rᴿ
f a =
Trunc.rec→Set squash/
([_] ∘ fst)
(λ {(b , r) (b' , r') → eq/ b b' ∣ a , r , r' ∣})
fPath :
(a₀ : A) (s₀ : ∃[ b ∈ B ] R .fst .fst a₀ b)
(a₁ : A) (s₁ : ∃[ b ∈ B ] R .fst .fst a₁ b)
→ Rᴸ a₀ a₁
→ f a₀ s₀ ≡ f a₁ s₁
fPath a₀ =
Trunc.elim (λ _ → isPropΠ3 λ _ _ _ → squash/ _ _)
(λ {(b₀ , r₀) a₁ →
Trunc.elim (λ _ → isPropΠ λ _ → squash/ _ _)
(λ {(b₁ , r₁) →
Trunc.elim (λ _ → squash/ _ _)
(λ {(b' , r₀' , r₁') → eq/ b₀ b₁ ∣ a₀ , r₀ , sim .zigzag r₀' r₁' r₁ ∣})})})
φ : A / Rᴸ → B / Rᴿ
φ [ a ] = f a (sim .fwd a)
φ (eq/ a₀ a₁ r i) = fPath a₀ (sim .fwd a₀) a₁ (sim .fwd a₁) r i
φ (squash/ _ _ p q j i) = squash/ _ _ (cong φ p) (cong φ q) j i
relToFwd≡ : ∀ {a b} → R .fst .fst a b → φ [ a ] ≡ [ b ]
relToFwd≡ {a} {b} r =
Trunc.elim {P = λ s → f a s ≡ [ b ]} (λ _ → squash/ _ _)
(λ {(b' , r') → eq/ b' b ∣ a , r' , r ∣})
(sim .fwd a)
fwd≡ToRel : ∀ {a b} → φ [ a ] ≡ [ b ] → R .fst .fst a b
fwd≡ToRel {a} {b} =
Trunc.elim {P = λ s → f a s ≡ [ b ] → R .fst .fst a b}
(λ _ → isPropΠ λ _ → R .fst .snd _ _)
(λ {(b' , r') p →
Trunc.rec (R .fst .snd _ _)
(λ {(a' , s' , s) → R .snd .zigzag r' s' s})
(effective
(QER→EquivRel (invQER R) .fst .snd)
(QER→EquivRel (invQER R) .snd)
b' b p)})
(sim .fwd a)
private
g : (b : B) → ∃[ a ∈ A ] R .fst .fst a b → A / Rᴸ
g b =
Trunc.rec→Set squash/
([_] ∘ fst)
(λ {(a , r) (a' , r') → eq/ a a' ∣ b , r , r' ∣})
gPath :
(b₀ : B) (s₀ : ∃[ a ∈ A ] R .fst .fst a b₀)
(b₁ : B) (s₁ : ∃[ a ∈ A ] R .fst .fst a b₁)
→ Rᴿ b₀ b₁
→ g b₀ s₀ ≡ g b₁ s₁
gPath b₀ =
Trunc.elim (λ _ → isPropΠ3 λ _ _ _ → squash/ _ _)
(λ {(a₀ , r₀) b₁ →
Trunc.elim (λ _ → isPropΠ λ _ → squash/ _ _)
(λ {(a₁ , r₁) →
Trunc.elim (λ _ → squash/ _ _)
(λ {(a' , r₀' , r₁') → eq/ a₀ a₁ ∣ b₀ , r₀ , sim .zigzag r₁ r₁' r₀' ∣})})})
ψ : B / Rᴿ → A / Rᴸ
ψ [ b ] = g b (sim .bwd b)
ψ (eq/ b₀ b₁ r i) = gPath b₀ (sim .bwd b₀) b₁ (sim .bwd b₁) r i
ψ (squash/ _ _ p q j i) = squash/ _ _ (cong ψ p) (cong ψ q) j i
relToBwd≡ : ∀ {a b} → R .fst .fst a b → ψ [ b ] ≡ [ a ]
relToBwd≡ {a} {b} r =
Trunc.elim {P = λ s → g b s ≡ [ a ]} (λ _ → squash/ _ _)
(λ {(a' , r') → eq/ a' a ∣ b , r' , r ∣})
(sim .bwd b)
private
η : ∀ qb → φ (ψ qb) ≡ qb
η =
elimProp (λ _ → squash/ _ _)
(λ b →
Trunc.elim {P = λ s → φ (g b s) ≡ [ b ]} (λ _ → squash/ _ _)
(λ {(a , r) → relToFwd≡ r})
(sim .bwd b))
ε : ∀ qa → ψ (φ qa) ≡ qa
ε =
elimProp (λ _ → squash/ _ _)
(λ a →
Trunc.elim {P = λ s → ψ (f a s) ≡ [ a ]} (λ _ → squash/ _ _)
(λ {(b , r) → relToBwd≡ r})
(sim .fwd a))
bwd≡ToRel : ∀ {a b} → ψ [ b ] ≡ [ a ] → R .fst .fst a b
bwd≡ToRel {a} {b} p = fwd≡ToRel (cong φ (sym p) ∙ η [ b ])
Thm : (A / Rᴸ) ≃ (B / Rᴿ)
Thm = isoToEquiv (iso φ ψ η ε)
|
{
"alphanum_fraction": 0.4912987727,
"avg_line_length": 33.6975308642,
"ext": "agda",
"hexsha": "aded8f02fadce4288b2c61a3973bea070c18c5a2",
"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/Relation/ZigZag/Base.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/Relation/ZigZag/Base.agda",
"max_line_length": 91,
"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/Relation/ZigZag/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2476,
"size": 5459
}
|
module Numeral.Natural.Sequence.Proofs where
import Lvl
open import Data
open import Data.Either as Either using (_‖_)
open import Data.Either.Equiv as Either
open import Data.Either.Equiv.Id
open import Data.Either.Proofs as Either
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
open import Data.Tuple.Equiv as Tuple
open import Data.Tuple.Equiv.Id
open import Data.Tuple.Proofs as Tuple
open import Functional
open import Function.Proofs
open import Lang.Inspect
open import Logic
open import Logic.Propositional
open import Logic.Predicate
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.DivMod.Proofs
open import Numeral.Natural.Oper.FlooredDivision
open import Numeral.Natural.Sequence
open import Relator.Equals renaming (_≡_ to Id)
open import Relator.Equals.Proofs.Equiv{T = ℕ}
open import Relator.Equals.Proofs.Equivalence using () renaming ([≡]-equiv to Id-equiv ; [≡]-to-function to Id-to-function)
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Function.Domain.Proofs
import Structure.Function.Names as Names
open import Structure.Operator
open import Structure.Setoid
open import Syntax.Transitivity
open import Type
private variable ℓ ℓ₁ ℓ₂ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₑ₄ ℓₑ₅ ℓₑ₆ : Lvl.Level
private variable n : ℕ
private variable A : Type{ℓ}
private variable B : Type{ℓ}
alternate₂-args : ∀{n} → (alternate₂(n ⋅ 2) ≡ Either.Left(n)) ∧ (alternate₂(𝐒(n ⋅ 2)) ≡ Either.Right(n))
alternate₂-args {0} = [∧]-intro [≡]-intro [≡]-intro
alternate₂-args {1} = [∧]-intro [≡]-intro [≡]-intro
alternate₂-args {𝐒(𝐒(n))} with [∧]-intro l r ← alternate₂-args {n} rewrite l rewrite r = [∧]-intro [≡]-intro [≡]-intro
alternate₂-values : ∀{n} → (alternate₂(n) ≡ Either.Left(n ⌊/⌋ 2)) ∨ (alternate₂(n) ≡ Either.Right(n ⌊/⌋ 2))
alternate₂-values {0} = Either.Left [≡]-intro
alternate₂-values {1} = Either.Right [≡]-intro
alternate₂-values {𝐒(𝐒(n))} with alternate₂-values {n}
... | Either.Left eq rewrite eq = Either.Left [≡]-intro
... | Either.Right eq rewrite eq = Either.Right [≡]-intro
instance
alternate₂-inverseₗ : Inverseₗ(alternate₂)(unalternate₂)
alternate₂-inverseₗ = intro proof where
p : ∀{e} → (unalternate₂(Either.map 𝐒 𝐒 e) ≡ 𝐒(𝐒(unalternate₂ e)))
p {Either.Left _} = [≡]-intro
p {Either.Right _} = [≡]-intro
proof : Names.Inverses(unalternate₂)(alternate₂)
proof {0} = [≡]-intro
proof {1} = [≡]-intro
proof {𝐒(𝐒(n))} =
(unalternate₂ ∘ alternate₂) (𝐒(𝐒(n))) 🝖[ _≡_ ]-[]
unalternate₂(alternate₂(𝐒(𝐒(n)))) 🝖[ _≡_ ]-[]
unalternate₂(Either.map 𝐒 𝐒 (alternate₂ n)) 🝖[ _≡_ ]-[ p{alternate₂ n} ]
𝐒(𝐒(unalternate₂(alternate₂ n))) 🝖[ _≡_ ]-[ congruence₁(𝐒) (congruence₁(𝐒) (proof {n})) ]
𝐒(𝐒(n)) 🝖-end
instance
alternate₂-inverseᵣ : Inverseᵣ(alternate₂)(unalternate₂)
alternate₂-inverseᵣ = intro proof where
proof : Names.Inverses(alternate₂)(unalternate₂)
proof {Either.Left n} = [∧]-elimₗ alternate₂-args
proof {Either.Right n} = [∧]-elimᵣ alternate₂-args
instance
alternate₂-inverse : Inverse(alternate₂)(unalternate₂)
alternate₂-inverse = [∧]-intro alternate₂-inverseₗ alternate₂-inverseᵣ
instance
alternate₂-bijective : Bijective(alternate₂)
alternate₂-bijective = invertible-to-bijective ⦃ inver = [∃]-intro unalternate₂ ⦃ [∧]-intro Id-to-function alternate₂-inverse ⦄ ⦄
pairIndexing-def3 : ∀{a b} → (pairIndexing a (𝐒 b) ≡ 𝐒(pairIndexing (𝐒 a) b))
pairIndexing-def3 {𝟎} {b} = [≡]-intro
pairIndexing-def3 {𝐒 a} {b} = [≡]-intro
instance
{-# TERMINATING #-}
pairIndexing-inverseₗ : Inverseₗ(Tuple.uncurry pairIndexing)(diagonalFilling)
pairIndexing-inverseₗ = intro proof where
proof : Names.Inverses(diagonalFilling)(Tuple.uncurry pairIndexing)
proof {𝟎 , 𝟎} = [≡]-intro
proof {𝐒(a) , 𝟎} with diagonalFilling(pairIndexing 𝟎 a) | proof {𝟎 , a}
... | 𝟎 , 𝟎 | [≡]-intro = [≡]-intro
... | 𝟎 , 𝐒(d) | [≡]-intro = [≡]-intro
... | 𝐒(c) , 𝟎 | ()
... | 𝐒(c) , 𝐒(d) | ()
{-# CATCHALL #-}
proof {a , 𝐒(b)} rewrite pairIndexing-def3 {a}{b} with diagonalFilling(pairIndexing (𝐒(a)) b) | proof {𝐒(a) , b}
... | 𝟎 , 𝟎 | ()
... | 𝟎 , 𝐒(d) | ()
... | 𝐒(c) , 𝟎 | [≡]-intro = [≡]-intro
... | 𝐒(c) , 𝐒(d) | [≡]-intro = [≡]-intro
instance
pairIndexing-inverseᵣ : Inverseᵣ(Tuple.uncurry pairIndexing)(diagonalFilling)
pairIndexing-inverseᵣ = intro proof where
proof : Names.Inverses(Tuple.uncurry pairIndexing)(diagonalFilling)
proof {𝟎} = [≡]-intro
proof {𝐒(n)} with diagonalFilling n | proof {n}
... | (𝟎 , b) | q = congruence₁(𝐒) q
... | (𝐒(a) , b) | q rewrite pairIndexing-def3 {a}{b} = congruence₁(𝐒) q
instance
pairIndexing-inverse : Inverse(Tuple.uncurry pairIndexing)(diagonalFilling)
pairIndexing-inverse = [∧]-intro pairIndexing-inverseₗ pairIndexing-inverseᵣ
instance
diagonalFilling-inverse : Inverse(diagonalFilling)(Tuple.uncurry pairIndexing)
diagonalFilling-inverse = [∧]-intro pairIndexing-inverseᵣ pairIndexing-inverseₗ
instance
pairIndexing-bijective : Bijective(Tuple.uncurry pairIndexing)
pairIndexing-bijective = invertible-to-bijective ⦃ inver = [∃]-intro diagonalFilling ⦃ [∧]-intro [≡]-function pairIndexing-inverse ⦄ ⦄
instance
diagonalFilling-bijective : Bijective(diagonalFilling)
diagonalFilling-bijective = invertible-to-bijective ⦃ inver = [∃]-intro (Tuple.uncurry pairIndexing) ⦃ [∧]-intro Id-to-function diagonalFilling-inverse ⦄ ⦄
tupleIndexing-inverseᵣ : Inverseᵣ(tupleIndexing{𝐒(n)})(spaceFilling{𝐒(n)})
tupleIndexing-inverseᵣ{n} = intro(proof{n}) where
proof : ∀{n} → Names.Inverses(tupleIndexing{𝐒(n)})(spaceFilling{𝐒(n)})
proof {𝟎} {_} = [≡]-intro
proof {𝐒(n)}{i} with (x , y) ← diagonalFilling i | intro [≡]-intro ← inspect diagonalFilling i =
pairIndexing x (tupleIndexing{𝐒(n)} (spaceFilling{𝐒(n)} y)) 🝖[ _≡_ ]-[ congruence₁(pairIndexing(x)) (proof{n}{y}) ]
pairIndexing x y 🝖[ _≡_ ]-[ inverseᵣ(Tuple.uncurry pairIndexing)(diagonalFilling) ]
i 🝖-end
tupleIndexing-inverseₗ : Inverseₗ(tupleIndexing{𝐒(n)})(spaceFilling{𝐒(n)})
tupleIndexing-inverseₗ{n} = intro(proof{n}) where
proof : ∀{n} → Names.Inverses(spaceFilling{𝐒(n)})(tupleIndexing{𝐒(n)})
proof {𝟎} {_} = [≡]-intro
proof {𝐒(n)}{x , xs} =
Tuple.mapRight spaceFilling (diagonalFilling (pairIndexing x (tupleIndexing xs))) 🝖[ _≡_ ]-[ congruence₁(Tuple.mapRight spaceFilling) (inverseₗ(Tuple.uncurry pairIndexing)(diagonalFilling)) ]
Tuple.mapRight spaceFilling (x , tupleIndexing xs) 🝖[ _≡_ ]-[]
(x , spaceFilling(tupleIndexing xs)) 🝖[ _≡_ ]-[ congruence₂ᵣ(_,_)(x) (proof{n}{xs}) ]
(x , xs) 🝖-end
instance
tupleIndexing-inverse : Inverse(tupleIndexing{𝐒(n)})(spaceFilling{𝐒(n)})
tupleIndexing-inverse = [∧]-intro tupleIndexing-inverseₗ tupleIndexing-inverseᵣ
instance
tupleIndexing-bijective : Bijective(tupleIndexing{𝐒(n)})
tupleIndexing-bijective = invertible-to-bijective ⦃ inver = [∃]-intro spaceFilling ⦃ [∧]-intro [≡]-function tupleIndexing-inverse ⦄ ⦄
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
⦃ equiv-AB : Equiv{ℓₑ}(A ‖ B) ⦄ ⦃ ext-AB : Either.Extensionality ⦃ equiv-A ⦄ ⦃ equiv-B ⦄ (equiv-AB) ⦄
{af : ℕ → A} ⦃ bij-af : Bijective ⦃ [≡]-equiv ⦄ ⦃ equiv-A ⦄ (af) ⦄
{bf : ℕ → B} ⦃ bij-bf : Bijective ⦃ [≡]-equiv ⦄ ⦃ equiv-B ⦄ (bf) ⦄
where
instance
interleave-bijective : Bijective(interleave af bf)
interleave-bijective = [∘]-bijective ⦃ bij-f = Either.map-bijective ⦄ ⦃ bij-g = alternate₂-bijective ⦄
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
⦃ equiv-AB : Equiv{ℓₑ}(A ⨯ B) ⦄ ⦃ ext-AB : Tuple.Extensionality ⦃ equiv-A ⦄ ⦃ equiv-B ⦄ (equiv-AB) ⦄
{af : ℕ → A} ⦃ bij-af : Bijective ⦃ [≡]-equiv ⦄ ⦃ equiv-A ⦄ (af) ⦄
{bf : ℕ → B} ⦃ bij-bf : Bijective ⦃ [≡]-equiv ⦄ ⦃ equiv-B ⦄ (bf) ⦄
where
instance
pair-bijective : Bijective ⦃ [≡]-equiv ⦄ ⦃ equiv-AB ⦄ (pair af bf)
pair-bijective = [∘]-bijective ⦃ bij-f = Tuple.map-bijective ⦃ Id-equiv ⦄ ⦃ Id-equiv ⦄ ⦃ equiv-A ⦄ ⦃ equiv-B ⦄ ⦃ Id-equiv ⦄ ⦄ ⦃ bij-g = diagonalFilling-bijective ⦄
{- TODO: Old stuff. Probably okay to delete? But maybe it could be handy when the new interleave is used (it is similar to the old one)?
-- Interleaves two sequences into one, alternating between the elements from each sequence.
interleave : (ℕ → A) → (ℕ → B) → (ℕ → (A ‖ B))
interleave af bf 𝟎 = Either.Left(af(𝟎))
interleave af bf (𝐒 𝟎) = Either.Right(bf(𝟎))
interleave af bf (𝐒(𝐒 n)) = interleave (af ∘ 𝐒) (bf ∘ 𝐒) n
private variable af : ℕ → A
private variable bf : ℕ → B
interleave-left : ∀{n} → (interleave af bf (2 ⋅ n) ≡ Either.Left(af(n)))
interleave-left {n = 𝟎} = [≡]-intro
interleave-left {n = 𝐒 n} = interleave-left {n = n}
interleave-right : ∀{n} → (interleave af bf (𝐒(2 ⋅ n)) ≡ Either.Right(bf(n)))
interleave-right {n = 𝟎} = [≡]-intro
interleave-right {n = 𝐒 n} = interleave-right {n = n}
interleave-values : ∀{n} → (interleave af bf n ≡ Either.Left(af(n ⌊/⌋ 2))) ∨ (interleave af bf n ≡ Either.Right(bf(n ⌊/⌋ 2)))
interleave-values {n = 𝟎} = [∨]-introₗ [≡]-intro
interleave-values {n = 𝐒 𝟎} = [∨]-introᵣ [≡]-intro
interleave-values {af = af}{bf = bf} {n = 𝐒(𝐒 n)} = interleave-values {af = af ∘ 𝐒}{bf = bf ∘ 𝐒} {n = n}
interleave-left-args : ⦃ _ : Injective(af) ⦄ → ∀{m n} → (interleave af bf m ≡ Either.Left(af(n))) ↔ (m ≡ 2 ⋅ n)
interleave-left-args {n = n} = [↔]-intro (\{[≡]-intro → interleave-left{n = n}}) r where
r : ⦃ _ : Injective(af) ⦄ → ∀{m n} → (interleave af bf m ≡ Either.Left(af(n))) → (m ≡ 2 ⋅ n)
r {af = af} {m = 𝟎}{n = n} = congruence₁(2 ⋅_) ∘ injective(af) ∘ injective(Either.Left) ⦃ Left-injective ⦄
r {af = af}{bf = bf} {m = 𝐒 (𝐒 m)}{n = 𝟎} p with interleave-values {af = af}{bf = bf}{n = 𝐒(𝐒 m)}
... | [∨]-introₗ v with () ← injective(af) (injective(Either.Left) ⦃ Left-injective ⦄ (symmetry(_≡_) v 🝖 p))
... | [∨]-introᵣ v with () ← symmetry(_≡_) v 🝖 p
r {af = af} {m = 𝐒 (𝐒 m)}{n = 𝐒 n} p = congruence₁(𝐒 ∘ 𝐒) (r ⦃ [∘]-injective {f = af} ⦄{m = m}{n = n} p)
interleave-right-args : ⦃ _ : Injective(bf) ⦄ → ∀{m n} → (interleave af bf m ≡ Either.Right(bf(n))) ↔ (m ≡ 𝐒(2 ⋅ n))
interleave-right-args {n = n} = [↔]-intro (\{[≡]-intro → interleave-right{n = n}}) r where
r : ⦃ _ : Injective(bf) ⦄ → ∀{m n} → (interleave af bf m ≡ Either.Right(bf(n))) → (m ≡ 𝐒(2 ⋅ n))
r {bf = bf} {m = 𝐒 𝟎}{n = n} = congruence₁(𝐒 ∘ (2 ⋅_)) ∘ injective(bf) ∘ injective(Either.Right) ⦃ Right-injective ⦄
r {bf = bf}{af = af} {m = 𝐒 (𝐒 m)}{n = 𝟎} p with interleave-values {af = af}{bf = bf}{n = 𝐒(𝐒 m)}
... | [∨]-introₗ v with () ← symmetry(_≡_) v 🝖 p
... | [∨]-introᵣ v with () ← injective(bf) (injective(Either.Right) ⦃ Right-injective ⦄ (symmetry(_≡_) v 🝖 p))
r {bf = bf} {m = 𝐒 (𝐒 m)}{n = 𝐒 n} p = congruence₁(𝐒 ∘ 𝐒) (r ⦃ [∘]-injective {f = bf} ⦄{m = m}{n = n} p)
interleave-step-left : ⦃ _ : Injective(af) ⦄ → ∀{m n} → (interleave af bf m ≡ Either.Left(af(n))) ↔ (interleave af bf (𝐒(𝐒 m)) ≡ Either.Left(af(𝐒 n)))
interleave-step-left{af = iaf}{bf = ibf}{m = m}{n = n} = [↔]-intro (l{af = iaf}{bf = ibf}{m = m}{n = n}) (r{af = iaf}{bf = ibf}{m = m}{n = n}) where
l : ⦃ _ : Injective(af) ⦄ → ∀{m n} → (interleave af bf m ≡ Either.Left(af(n))) ← (interleave af bf (𝐒(𝐒 m)) ≡ Either.Left(af(𝐒 n)))
l {af = af} {m = 𝟎} {n} = congruence₁(Either.Left) ∘ congruence₁(af) ∘ injective(𝐒) ∘ injective(af) ∘ injective(Either.Left) ⦃ Left-injective ⦄
l {af = af}{bf = bf} {m = 𝐒 (𝐒 m)}{𝟎} p with interleave-values {af = af}{bf = bf}{n = 𝐒(𝐒(𝐒(𝐒 m)))}
... | [∨]-introₗ v with () ← injective(af) (injective(Either.Left) ⦃ Left-injective ⦄ (symmetry(_≡_) v 🝖 p))
... | [∨]-introᵣ v with () ← symmetry(_≡_) v 🝖 p
l {af = af} {m = 𝐒 (𝐒 m)}{𝐒 n} = l {af = af ∘ 𝐒} ⦃ [∘]-injective {f = af} ⦄ {m = m}{n}
r : ⦃ _ : Injective(af) ⦄ → ∀{m n} → (interleave af bf m ≡ Either.Left(af(n))) → (interleave af bf (𝐒(𝐒 m)) ≡ Either.Left(af(𝐒 n)))
r {af = af} {m = 𝟎} {n} = congruence₁(Either.Left) ∘ congruence₁(af) ∘ congruence₁(𝐒) ∘ injective(af) ∘ injective(Either.Left) ⦃ Left-injective ⦄
r {af = af}{bf = bf} {m = 𝐒(𝐒 m)} {𝟎} p with interleave-values {af = af}{bf = bf}{n = 𝐒(𝐒 m)}
... | [∨]-introₗ v with () ← injective(af) (injective(Either.Left) ⦃ Left-injective ⦄ (symmetry(_≡_) v 🝖 p))
... | [∨]-introᵣ v with () ← symmetry(_≡_) v 🝖 p
r {af = af} {m = 𝐒(𝐒 m)} {𝐒 n} = r {af = af ∘ 𝐒} ⦃ [∘]-injective {f = af} ⦄ {m = m}{n}
postulate interleave-injective-raw : ⦃ inj-af : Injective(af) ⦄ → ⦃ inj-bf : Injective(bf) ⦄ → Names.Injective(interleave af bf)
{-interleave-injective-raw {af = af} {bf = bf} {x = 𝟎} {y = 𝟎} fxfy = [≡]-intro
interleave-injective-raw {af = af} {bf = bf} {x = 𝟎} {y = 𝐒 (𝐒 y)} fxfy = symmetry(_≡_) ([↔]-to-[→] (interleave-left-args {bf = bf}) (symmetry(_≡_) fxfy))
interleave-injective-raw {af = af} {bf = bf} {x = 𝐒 (𝐒 x)} {y = 𝟎} fxfy = [↔]-to-[→] (interleave-left-args {bf = bf}) fxfy
interleave-injective-raw {af = af} {bf = bf} {x = 𝐒 𝟎} {y = 𝐒 𝟎} fxfy = [≡]-intro
interleave-injective-raw {af = af} {bf = bf} {x = 𝐒 𝟎} {y = 𝐒 (𝐒 y)} fxfy = symmetry(_≡_) ([↔]-to-[→] (interleave-right-args {bf = bf}{af = af}) (symmetry(_≡_) fxfy))
interleave-injective-raw {af = af} {bf = bf} {x = 𝐒 (𝐒 x)} {y = 𝐒 𝟎} fxfy = [↔]-to-[→] (interleave-right-args {bf = bf}{af = af}) fxfy
interleave-injective-raw {af = af} {bf = bf} {x = 𝐒 (𝐒 x)} {y = 𝐒 (𝐒 y)} fxfy with interleave-values {af = af ∘ 𝐒}{bf = bf ∘ 𝐒}{n = x} | interleave-values {af = af ∘ 𝐒}{bf = bf ∘ 𝐒}{n = y}
... | [∨]-introₗ p | [∨]-introₗ q = {!congruence₁(𝐒) (injective(af) (injective(Either.Left) (symmetry(_≡_) p 🝖 fxfy 🝖 q)))!} -- TODO: interleave-left and a proof of the division algorihm would work here instead of using interleave-values. Or alternatively, use this, multiply by 2, prove the divisibilities for both cases so that each case have division as inverse of multiplication
... | [∨]-introₗ p | [∨]-introᵣ q = {!!}
... | [∨]-introᵣ p | [∨]-introₗ q = {!!}
... | [∨]-introᵣ p | [∨]-introᵣ q = {!congruence₁(𝐒) (injective(bf) (injective(Either.Right) (symmetry(_≡_) p 🝖 fxfy 🝖 q)))!}
-}
instance
interleave-injective : ⦃ inj-af : Injective(af) ⦄ → ⦃ inj-bf : Injective(bf) ⦄ → Injective(interleave af bf)
interleave-injective = intro interleave-injective-raw
instance
interleave-surjective : ⦃ surj-af : Surjective(af) ⦄ → ⦃ surj-bf : Surjective(bf) ⦄ → Surjective(interleave af bf)
Surjective.proof (interleave-surjective {af = af}{bf = bf}) {[∨]-introₗ y} with surjective(af){y}
... | [∃]-intro n ⦃ [≡]-intro ⦄ = [∃]-intro(2 ⋅ n) ⦃ interleave-left{n = n} ⦄
Surjective.proof (interleave-surjective {af = af}{bf = bf}) {[∨]-introᵣ y} with surjective(bf){y}
... | [∃]-intro n ⦃ [≡]-intro ⦄ = [∃]-intro(𝐒(2 ⋅ n)) ⦃ interleave-right{n = n} ⦄
instance
interleave-bijective : ⦃ bij-af : Bijective(af) ⦄ → ⦃ bij-bf : Bijective(bf) ⦄ → Bijective(interleave af bf)
interleave-bijective {af = af}{bf = bf} = injective-surjective-to-bijective(interleave af bf) where
instance
inj-af : Injective(af)
inj-af = bijective-to-injective af
instance
inj-bf : Injective(bf)
inj-bf = bijective-to-injective bf
instance
surj-af : Surjective(af)
surj-af = bijective-to-surjective af
instance
surj-bf : Surjective(bf)
surj-bf = bijective-to-surjective bf
-}
|
{
"alphanum_fraction": 0.6088114105,
"avg_line_length": 53.8395904437,
"ext": "agda",
"hexsha": "97c568f215ca11821daddf79aadc76ca05e8be09",
"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/Sequence/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Sequence/Proofs.agda",
"max_line_length": 382,
"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/Sequence/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 6518,
"size": 15775
}
|
module Issue347 where
import Common.Irrelevance
{- Dan Doel, 2010-10-09
This is a boiling down of a problem encountered by Eric Mertens. It
seems the unifier will make up values for records without bothering
with irrelevant fields: -}
data ⊥ : Set where
⊥-elim : {A : Set} → ⊥ → A
⊥-elim ()
⊥-elimⁱ : {A : Set} → .⊥ → A
⊥-elimⁱ ()
module Bad where
record ○ (A : Set) : Set where
constructor poof
field
.inflate : A
open ○
-- This, for some reason, doesn't. Apparently it thinks it can
-- make up records without bothering to infer the irrelevant fields.
evil : ∀ A → A
evil A = ⊥-elimⁱ (inflate _)
-- the meta var ?a : Squash A eta-expands to
-- ?a = poof Bot ?b
-- meta var ?b should be left over
|
{
"alphanum_fraction": 0.6469002695,
"avg_line_length": 21.2,
"ext": "agda",
"hexsha": "67a6adc06aed5e2e37831d00922c5c472211771f",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Fail/Issue347.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Fail/Issue347.agda",
"max_line_length": 70,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue347.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": 249,
"size": 742
}
|
data ⊤ : Set where
t : ⊤
data ⊤⊤ : Set where
tt : ⊤⊤
module M (x : ⊤⊤) where
instance
top : ⊤
top = t
search : ∀ {ℓ} {t : Set ℓ} {{_ : t}} → t
search {{p}} = p
-- no instance is in scope, and none is found
-- correct : ⊤
-- correct = search
someDef : ⊤
someDef = top
where
open M tt
-- incorrect! there should be no instance available.
leak : ⊤
leak = search
|
{
"alphanum_fraction": 0.5555555556,
"avg_line_length": 13.3448275862,
"ext": "agda",
"hexsha": "2daf26b27ed845469cd022bc901f9116dd12b98a",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue2489.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue2489.agda",
"max_line_length": 52,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2489.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": 152,
"size": 387
}
|
module IsLiteralSequent where
open import OscarPrelude
open import Sequent
open import IsLiteralFormula
record IsLiteralSequent (Φ : Sequent) : Set
where
constructor _╱_
field
isLiteralStatement : IsLiteralFormula (statement Φ)
isLiteralSuppositions : All IsLiteralFormula (suppositions Φ)
open IsLiteralSequent public
instance EqIsLiteralSequent : ∀ {Φ} → Eq (IsLiteralSequent Φ)
Eq._==_ EqIsLiteralSequent ( φᵗ₁ ╱ φˢs₁ ) ( φᵗ₂ ╱ φˢs₂ ) = decEq₂ (cong isLiteralStatement) (cong isLiteralSuppositions) (φᵗ₁ ≟ φᵗ₂) (φˢs₁ ≟ φˢs₂)
|
{
"alphanum_fraction": 0.7692307692,
"avg_line_length": 28.7368421053,
"ext": "agda",
"hexsha": "7062576a8a46e622f76127097e0dd9a2948db3a2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/IsLiteralSequent.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/IsLiteralSequent.agda",
"max_line_length": 146,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/IsLiteralSequent.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 193,
"size": 546
}
|
------------------------------------------------------------------------------
-- Totality properties respect to OrdTree
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.SortList.Properties.Totality.OrdTreeATP where
open import FOTC.Base
open import FOTC.Data.Bool.PropertiesI
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesATP
open import FOTC.Data.Nat.List.Type
open import FOTC.Data.Nat.Type
open import FOTC.Program.SortList.SortList
open import FOTC.Program.SortList.Properties.Totality.BoolATP
open import FOTC.Program.SortList.Properties.Totality.TreeATP
------------------------------------------------------------------------------
-- Subtrees
-- If (node t₁ i t₂) is ordered then t₁ is ordered.
postulate leftSubTree-OrdTree : ∀ {t₁ i t₂} → Tree t₁ → N i → Tree t₂ →
OrdTree (node t₁ i t₂) → OrdTree t₁
{-# ATP prove leftSubTree-OrdTree &&-Bool &&-list₂-t le-ItemTree-Bool le-TreeItem-Bool ordTree-Bool #-}
-- If (node t₁ i t₂) is ordered then t₂ is ordered.
postulate rightSubTree-OrdTree : ∀ {t₁ i t₂} → Tree t₁ → N i → Tree t₂ →
OrdTree (node t₁ i t₂) → OrdTree t₂
-- 2018-06-28: The ATPs could not prove the theorem (300 sec), but
-- Vampire 4.2.2, via `online-atps`, could prove it.
--
-- {-# ATP prove rightSubTree-OrdTree &&-Bool &&-list₂-t le-ItemTree-Bool le-TreeItem-Bool ordTree-Bool #-}
------------------------------------------------------------------------------
-- Helper functions
toTree-OrdTree-helper₁ : ∀ {i₁ i₂ t} → N i₁ → N i₂ → i₁ > i₂ →
Tree t →
≤-TreeItem t i₁ →
≤-TreeItem (toTree · i₂ · t) i₁
toTree-OrdTree-helper₁ {i₁} {i₂} .{nil} Ni₁ Ni₂ i₁>i₂ tnil t≤i₁ = prf
where postulate prf : ≤-TreeItem (toTree · i₂ · nil) i₁
{-# ATP prove prf x<y→x≤y #-}
toTree-OrdTree-helper₁ {i₁} {i₂} Ni₁ Ni₂ i₁>i₂ (ttip {j} Nj) t≤i₁ =
case prf₁ prf₂ (x>y∨x≤y Nj Ni₂)
where
postulate prf₁ : j > i₂ → ≤-TreeItem (toTree · i₂ · tip j) i₁
{-# ATP prove prf₁ x>y→x≰y x<y→x≤y #-}
postulate prf₂ : j ≤ i₂ → ≤-TreeItem (toTree · i₂ · tip j) i₁
{-# ATP prove prf₂ x<y→x≤y #-}
toTree-OrdTree-helper₁ {i₁} {i₂} Ni₁ Ni₂ i₁>i₂
(tnode {t₁} {j} {t₂} Tt₁ Nj Tt₂) t≤i₁ =
case (prf₁ (toTree-OrdTree-helper₁ Ni₁ Ni₂ i₁>i₂ Tt₁
(&&-list₂-t₁ (le-TreeItem-Bool Tt₁ Ni₁)
(le-TreeItem-Bool Tt₂ Ni₁)
(trans (sym (le-TreeItem-node t₁ j t₂ i₁)) t≤i₁))))
(prf₂ (toTree-OrdTree-helper₁ Ni₁ Ni₂ i₁>i₂ Tt₂
(&&-list₂-t₂ (le-TreeItem-Bool Tt₁ Ni₁)
(le-TreeItem-Bool Tt₂ Ni₁)
(trans (sym (le-TreeItem-node t₁ j t₂ i₁)) t≤i₁))))
(x>y∨x≤y Nj Ni₂)
where
postulate prf₁ : ≤-TreeItem (toTree · i₂ · t₁) i₁ →
j > i₂ →
≤-TreeItem (toTree · i₂ · node t₁ j t₂) i₁
{-# ATP prove prf₁ x>y→x≰y &&-list₂-t le-TreeItem-Bool #-}
postulate prf₂ : ≤-TreeItem (toTree · i₂ · t₂) i₁ →
j ≤ i₂ →
≤-TreeItem (toTree · i₂ · node t₁ j t₂) i₁
{-# ATP prove prf₂ &&-list₂-t le-TreeItem-Bool #-}
toTree-OrdTree-helper₂ : ∀ {i₁ i₂ t} → N i₁ → N i₂ → i₁ ≤ i₂ →
Tree t →
≤-ItemTree i₁ t →
≤-ItemTree i₁ (toTree · i₂ · t)
toTree-OrdTree-helper₂ {i₁} {i₂} .{nil} Ni₁ Ni₂ i₁≤i₂ tnil i₁≤t = prf
where postulate prf : ≤-ItemTree i₁ (toTree · i₂ · nil)
{-# ATP prove prf #-}
toTree-OrdTree-helper₂ {i₁} {i₂} Ni₁ Ni₂ i₁≤i₂ (ttip {j} Nj) i₁≤t =
case prf₁ prf₂ (x>y∨x≤y Nj Ni₂)
where
postulate prf₁ : j > i₂ → ≤-ItemTree i₁ (toTree · i₂ · tip j)
{-# ATP prove prf₁ x>y→x≰y #-}
postulate prf₂ : j ≤ i₂ → ≤-ItemTree i₁ (toTree · i₂ · tip j)
{-# ATP prove prf₂ #-}
toTree-OrdTree-helper₂ {i₁} {i₂} Ni₁ Ni₂ i₁≤i₂
(tnode {t₁} {j} {t₂} Tt₁ Nj Tt₂) i₁≤t =
case (prf₁ (toTree-OrdTree-helper₂ Ni₁ Ni₂ i₁≤i₂ Tt₁
(&&-list₂-t₁ (le-ItemTree-Bool Ni₁ Tt₁)
(le-ItemTree-Bool Ni₁ Tt₂)
(trans (sym (le-ItemTree-node i₁ t₁ j t₂)) i₁≤t))))
(prf₂ (toTree-OrdTree-helper₂ Ni₁ Ni₂ i₁≤i₂ Tt₂
(&&-list₂-t₂ (le-ItemTree-Bool Ni₁ Tt₁)
(le-ItemTree-Bool Ni₁ Tt₂)
(trans (sym (le-ItemTree-node i₁ t₁ j t₂)) i₁≤t))))
(x>y∨x≤y Nj Ni₂)
where
postulate prf₁ : ≤-ItemTree i₁ (toTree · i₂ · t₁) →
j > i₂ →
≤-ItemTree i₁ (toTree · i₂ · node t₁ j t₂)
{-# ATP prove prf₁ x>y→x≰y &&-list₂-t le-ItemTree-Bool #-}
postulate prf₂ : ≤-ItemTree i₁ (toTree · i₂ · t₂) →
j ≤ i₂ →
≤-ItemTree i₁ (toTree · i₂ · node t₁ j t₂)
{-# ATP prove prf₂ &&-list₂-t le-ItemTree-Bool #-}
|
{
"alphanum_fraction": 0.5166051661,
"avg_line_length": 42.9083333333,
"ext": "agda",
"hexsha": "8d2ea5c6828d70e9c86c1f6c765b6403e69df0d6",
"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/OrdTreeATP.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/OrdTreeATP.agda",
"max_line_length": 107,
"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/OrdTreeATP.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": 1802,
"size": 5149
}
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.Functor.Equivalence.Strong where
open import Level
open import Relation.Binary using (IsEquivalence)
open import Relation.Nullary using (¬_)
open import Data.Product using (Σ; ∃; _,_; proj₁; proj₂)
open import Function using () renaming (_∘_ to _∙_)
open import Categories.Category
open import Categories.Functor hiding (equiv)
open import Categories.Functor.Properties
import Categories.Morphisms as Morphisms
record StrongEquivalence {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} (F : Functor C D) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
.full : Full F
.faithful : Faithful F
eso : EssentiallySurjective F
record StronglyEquivalent {o ℓ e o′ ℓ′ e′} (C : Category o ℓ e) (D : Category o′ ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
C⇒D : Functor C D
strong-equivalence : StrongEquivalence C⇒D
open StrongEquivalence strong-equivalence public
refl : ∀ {o ℓ e} {C : Category o ℓ e} → StronglyEquivalent C C
refl {C = C} = record
{ C⇒D = id
; strong-equivalence = record
{ full = λ {X Y} → my-full X Y
; faithful = λ _ _ eq → eq
; eso = λ d → d , (record { f = C.id; g = C.id; iso = record { isoˡ = C.identityˡ; isoʳ = C.identityˡ } })
}
}
where
module C = Category C
open C hiding (id)
.my-full : ∀ X Y → ¬ Σ (X ⇒ Y) (λ f → ¬ ∃ (λ g → C [ g ≡ f ]))
my-full X Y (f , elim) = elim (f , Equiv.refl)
sym : ∀ {o ℓ e o′ ℓ′ e′} → {C : Category o ℓ e} {D : Category o′ ℓ′ e′} → StronglyEquivalent C D → StronglyEquivalent D C
sym {C = C} {D = D} Op = record
{ C⇒D = record
{ F₀ = λ d → proj₁ (Op.eso d)
; F₁ = λ f → {!rev (proj₂ (Op.eso _)) ∘ f ∘ ?!}
; identity = {!!}
; homomorphism = {!!}
; F-resp-≡ = {!!}
}
; strong-equivalence = record
{ full = {!!}
; faithful = {!!}
; eso = {!!}
}
}
where
module Op = StronglyEquivalent Op
open Op using () renaming (C⇒D to F)
open Functor F
open Morphisms._≅_ C renaming (f to fwd; g to rev)
trans : ∀ {o₁ ℓ₁ e₁ o₂ ℓ₂ e₂ o₃ ℓ₃ e₃} {C₁ : Category o₁ ℓ₁ e₁} {C₂ : Category o₂ ℓ₂ e₂} {C₃ : Category o₃ ℓ₃ e₃} → StronglyEquivalent C₁ C₂ → StronglyEquivalent C₂ C₃ → StronglyEquivalent C₁ C₃
trans {C₁ = C₁} {C₂} {C₃} C₁⇒C₂ C₂⇒C₃ = record
{ C⇒D = G ∘ F
; strong-equivalence = record
{ full = λ {X Y} → my-full X Y
; faithful = λ f g → C₁⇒C₂.faithful _ _ ∙ C₂⇒C₃.faithful _ _
; eso = my-eso }
}
where
module C₁⇒C₂ = StronglyEquivalent C₁⇒C₂
module C₂⇒C₃ = StronglyEquivalent C₂⇒C₃
open C₁⇒C₂ using () renaming (C⇒D to F)
open C₂⇒C₃ using () renaming (C⇒D to G)
module F = Functor F
open F using (F₀; F₁)
module G = Functor G
open G using () renaming (F₀ to G₀; F₁ to G₁)
module E = Category.Equiv C₃
open Morphisms C₃
.my-full : ∀ X Y → ¬ ∃ (λ f → ¬ ∃ (λ (g : C₁ [ X , Y ]) → C₃ [ G₁ (F₁ g) ≡ f ]))
my-full X Y (f , elim) = C₂⇒C₃.full (f , lemma)
where
lemma : ¬ ∃ (λ h → C₃ [ G₁ h ≡ f ])
lemma (h , G₁h≡f) = C₁⇒C₂.full (h , lemma₂)
where
lemma₂ : ¬ ∃ (λ g → C₂ [ F₁ g ≡ h ])
lemma₂ (g , F₁g≡h) = elim (g , E.trans (G.F-resp-≡ F₁g≡h) G₁h≡f)
my-eso : ∀ c₃ → ∃ (λ c₁ → G₀ (F₀ c₁) ≅ c₃)
my-eso c₃ with C₂⇒C₃.eso c₃
my-eso c₃ | c₂ , ff₃ with C₁⇒C₂.eso c₂
my-eso c₃ | c₂ , ff₃ | c₁ , ff₂ = c₁ , (ff₃ ⓘ resp-≅ ff₂)
where open FunctorsAlways G
equiv : ∀ {o ℓ e} → IsEquivalence (StronglyEquivalent {o} {ℓ} {e})
equiv = record
{ refl = refl
; sym = sym
; trans = trans
}
|
{
"alphanum_fraction": 0.5846462332,
"avg_line_length": 34.5643564356,
"ext": "agda",
"hexsha": "261832c7a1c7d237118bd13f8ec814c0056b96ce",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Functor/Equivalence/Strong.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Functor/Equivalence/Strong.agda",
"max_line_length": 194,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Functor/Equivalence/Strong.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 1476,
"size": 3491
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Sn.Properties where
open import Cubical.Data.Int hiding (_+_)
open import Cubical.Data.Bool
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Univalence
open import Cubical.HITs.S1 hiding (inv)
open import Cubical.Data.Nat
open import Cubical.Data.Prod
open import Cubical.HITs.Sn.Base
open import Cubical.HITs.Susp
open import Cubical.Data.Unit
open import Cubical.HITs.Join
open import Cubical.HITs.Pushout
open import Cubical.HITs.SmashProduct
open import Cubical.HITs.PropositionalTruncation
open Iso
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
--- Some silly lemmas on S1 ---
S¹≡S1 : S₊ 1 ≡ S¹
S¹≡S1 = cong Susp (sym (ua Bool≃Susp⊥)) ∙ sym S¹≡SuspBool
isOfHLevelS1 : isOfHLevel 3 (S₊ 1)
isOfHLevelS1 = transport (λ i → isOfHLevel 3 (S¹≡S1 (~ i)))
λ x y → J (λ y p → (q : x ≡ y) → isProp (p ≡ q))
(transport (λ i → isSet (basedΩS¹≡Int x (~ i))) isSetInt refl)
isGroupoidS1 : isGroupoid (S₊ 1)
isGroupoidS1 = transport (λ i → isGroupoid (S¹≡S1 (~ i))) isGroupoidS¹
isConnectedS1 : (x : S₊ 1) → ∥ north ≡ x ∥
isConnectedS1 x = rec propTruncIsProp
(λ p → ∣ cong (transport (sym (S¹≡S1))) p ∙ transport⁻Transport (S¹≡S1) x ∣)
(isConnectedS¹ (transport S¹≡S1 x))
SuspBool→S1 : Susp Bool → S₊ 1
SuspBool→S1 north = north
SuspBool→S1 south = south
SuspBool→S1 (merid false i) = merid south i
SuspBool→S1 (merid true i) = merid north i
S1→SuspBool : S₊ 1 → Susp Bool
S1→SuspBool north = north
S1→SuspBool south = south
S1→SuspBool (merid north i) = merid true i
S1→SuspBool (merid south i) = merid false i
SuspBool→S1-sect : section SuspBool→S1 S1→SuspBool
SuspBool→S1-sect north = refl
SuspBool→S1-sect south = refl
SuspBool→S1-sect (merid north i) = refl
SuspBool→S1-sect (merid south i) = refl
SuspBool→S1-retr : retract SuspBool→S1 S1→SuspBool
SuspBool→S1-retr north = refl
SuspBool→S1-retr south = refl
SuspBool→S1-retr (merid false i) = refl
SuspBool→S1-retr (merid true i) = refl
S1→S¹ : S₊ 1 → S¹
S1→S¹ x = SuspBool→S¹ (S1→SuspBool x)
S¹→S1 : S¹ → S₊ 1
S¹→S1 x = SuspBool→S1 (S¹→SuspBool x)
S1→S¹-sect : section S1→S¹ S¹→S1
S1→S¹-sect x =
cong SuspBool→S¹ (SuspBool→S1-retr (S¹→SuspBool x))
∙ S¹→SuspBool→S¹ x
S1→S¹-retr : retract S1→S¹ S¹→S1
S1→S¹-retr x =
cong SuspBool→S1 (SuspBool→S¹→SuspBool (S1→SuspBool x))
∙ SuspBool→S1-sect x
SuspBoolIsoS1 : Iso (Susp Bool) (S₊ 1)
fun SuspBoolIsoS1 = SuspBool→S1
inv SuspBoolIsoS1 = S1→SuspBool
rightInv SuspBoolIsoS1 north = refl
rightInv SuspBoolIsoS1 south = refl
rightInv SuspBoolIsoS1 (merid north i) = refl
rightInv SuspBoolIsoS1 (merid south i) = refl
leftInv SuspBoolIsoS1 north = refl
leftInv SuspBoolIsoS1 south = refl
leftInv SuspBoolIsoS1 (merid false i) = refl
leftInv SuspBoolIsoS1 (merid true i) = refl
SuspBool≃S1 : Susp Bool ≃ S₊ 1
SuspBool≃S1 = isoToEquiv SuspBoolIsoS1
-- map between S¹ ∧ A and Susp A.
private
f' : {a : A} → A → S₊ 1 → Susp A
f' {a = pt} A north = north
f' {a = pt} A south = north
f' {a = pt} a (merid p i) = ((merid a) ∙ sym (merid pt)) i
proj' : {A : Pointed ℓ} {B : Pointed ℓ'} → typ A → typ B → A ⋀ B
proj' a b = inr (a , b)
module smashS1→susp {(A , pt) : Pointed ℓ} where
f : (S₊ 1 , north) ⋀ (A , pt) → (Susp A)
f (inl tt) = north
f (inr (x , x₁)) = f' {a = pt} x₁ x
f (push (inl north) i) = north
f (push (inl south) i) = north
f (push (inl (merid a i₁)) i) = rCancel (merid pt) (~ i) i₁
f (push (inr x) i) = north
f (push (push tt i₁) i) = north
f⁻ : Susp A → (S₊ 1 , north) ⋀ (A , pt)
f⁻ north = inl tt
f⁻ south = inl tt
f⁻ (merid a i) =
(push (inr a) ∙∙ cong (λ x → proj' {A = S₊ 1 , north} {B = A , pt} x a) (merid south ∙ sym (merid north)) ∙∙ sym (push (inr a))) i
{- TODO : Prove that they cancel out -}
{- Map used in definition of cup product. Maybe mover there later -}
sphereSmashMap : (n m : ℕ) → (S₊ (suc n) , north) ⋀ (S₊ (suc m) , north) → S₊ (2 + n + m)
sphereSmashMap zero m = smashS1→susp.f
sphereSmashMap (suc n) m =
smashS1→susp.f ∘
(idfun∙ _ ⋀→ (sphereSmashMap n m , refl)) ∘
⋀-associate ∘
((smashS1→susp.f⁻ , refl) ⋀→ idfun∙ _)
|
{
"alphanum_fraction": 0.6347128378,
"avg_line_length": 32.8888888889,
"ext": "agda",
"hexsha": "b840b3a948a227932461d9dff136c2c97c05b5b2",
"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/Sn/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/Sn/Properties.agda",
"max_line_length": 134,
"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/Sn/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1846,
"size": 4736
}
|
record SemiRing : Set1 where
field
R : Set
_+_ : R -> R -> R
zero : R
_*_ : R -> R -> R
one : R
module Vectors (S : SemiRing) where
open SemiRing S
open import Data.Nat renaming (ℕ to Nat; zero to z; _*_ to times; _+_ to plus)
open import Data.Fin renaming (zero to z) hiding (_+_)
open import RMonads
open import Functors.Fin
open import Data.Bool
open import Function
open import Relation.Binary.HeterogeneousEquality
Vec : Nat -> Set
Vec n = Fin n -> R
Matrix : Nat -> Nat -> Set
Matrix m n = Fin m -> Vec n
-- unit
delta : forall {n} -> Matrix n n
delta i j = if feq i j then one else zero
transpose : forall {m n} -> Matrix m n -> Matrix n m
transpose A = λ j i -> A i j
dot : forall {n} -> Vec n -> Vec n -> R
dot {z} x y = zero
dot {suc n} x y = (x z * y z) + dot (x ∘ suc) (y ∘ suc)
mult : forall {m n} -> Matrix m n -> Vec m -> Vec n
mult A x = λ j -> dot (transpose A j) x
VecRMon : RMonad FinF
VecRMon = rmonad
Vec
delta
mult
{!!}
{!!}
{!!}
where
{-
lem : forall {n}(x : Vec n)(j : Fin n) -> dot (λ i → if feq i j then one else zero) x ≅ x j
lem {z} x ()
lem {suc n} x z = {!lem {n} (x ∘ suc) !}
lem {suc n} x (suc j) = {!!}
-}
|
{
"alphanum_fraction": 0.5394223263,
"avg_line_length": 21.7118644068,
"ext": "agda",
"hexsha": "1a96ef7860f5ac48f7b28f9e6ae82ec0378ef776",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "Vectors.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "Vectors.agda",
"max_line_length": 95,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "Vectors.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 465,
"size": 1281
}
|
module BBHeap.DropLast {A : Set}(_≤_ : A → A → Set) where
open import BBHeap _≤_
open import BBHeap.Compound _≤_
open import BBHeap.Properties _≤_
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import Data.Empty
open import Data.Sum renaming (_⊎_ to _∨_)
mutual
dropLast : {b : Bound} → BBHeap b → BBHeap b
dropLast leaf = leaf
dropLast (left b≤x l⋘r)
with l⋘r | lemma-dropLast⋘ l⋘r
... | lf⋘ | _ = leaf
... | ll⋘ x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ | inj₁ (≃nd .x≤y₁ .x≤y₂ .l₁⋘r₁ .l₂⋘r₂ l₁≃r₁ _ l₁≃l₂) =
let l≃r = ≃nd x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂
in right b≤x (lemma-dropLast≃ l≃r (cl x≤y₁ l₁⋘r₁))
... | lr⋘ _ _ _ _ _ _ | inj₁ ()
... | _ | inj₂ dl⋘r = left b≤x dl⋘r
dropLast (right b≤x l⋙r)
with lemma-dropLast⋙ l⋙r
... | inj₁ l⋗r = left b≤x (lemma-dropLast⋗ l⋗r)
... | inj₂ l⋙dr = right b≤x l⋙dr
lemma-dropLast-⊥ : {b : Bound}{l r : BBHeap b} → l ≃ r → dropLast l ⋘ r → Compound l → ⊥
lemma-dropLast-⊥ () _ (cr _ _)
lemma-dropLast-⊥ (≃nd b≤x b≤x' l⋘r l'⋘r' l≃r l'≃r' l≃l') dxlr⋘x'l'r' (cl .b≤x .l⋘r)
with l⋘r | l≃r | l≃l' | l'⋘r' | lemma-dropLast⋘ l⋘r | dxlr⋘x'l'r'
... | lf⋘ | ≃lf | _ | _ | _ | ()
... | lr⋘ x≤y₁ x≤y₂ l₁⋙r₁ l₂⋘r₂ l₁≃r₁ l₁⋗l₂ | () | _ | _ | _ | _
... | ll⋘ x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ | _ | ≃nd .x≤y₁ x'≤y'₁ .l₁⋘r₁ l'₁⋘r'₁ _ l'₁≃r'₁ l₁≃r'₁ | ll⋘ .x'≤y'₁ x'≤y'₂ .l'₁⋘r'₁ l'₂⋘r'₂ l'₂≃r'₂ r'₁≃l'₂ | inj₁ (≃nd .x≤y₁ .x≤y₂ .l₁⋘r₁ .l₂⋘r₂ l₁≃r₁ _ l₁≃l₂) | _dxlr⋘x'l'r'
with lemma-dropLast≃ (≃nd x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂) (cl x≤y₁ l₁⋘r₁) | _dxlr⋘x'l'r'
... | l⋙dr | lr⋘ .b≤x .b≤x' .l⋙dr .(ll⋘ x'≤y'₁ x'≤y'₂ l'₁⋘r'₁ l'₂⋘r'₂ l'₂≃r'₂ r'₁≃l'₂) _ l⋗l'
with lemma-≃-⊥ (≃nd x≤y₁ x'≤y'₁ l₁⋘r₁ l'₁⋘r'₁ l₁≃r₁ l'₁≃r'₁ l₁≃r'₁) l⋗l'
... | ()
lemma-dropLast-⊥ (≃nd b≤x b≤x' l⋘r l'⋘r' l≃r l'≃r' l≃l') dxlr⋘x'l'r' (cl .b≤x .l⋘r) | ll⋘ x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ | ≃nd .x≤y₁ .x≤y₂ .l₁⋘r₁ .l₂⋘r₂ l₁≃r₁ _ l₁≃l₂ | _ | _ | inj₂ dl⋘r | _
with lemma-dropLast-⊥ (≃nd x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂) dl⋘r (cl x≤y₁ l₁⋘r₁)
... | ()
lemma-dropLast≃ : {b : Bound}{l r : BBHeap b} → l ≃ r → Compound l → l ⋙ dropLast r
lemma-dropLast≃ () (cr _ _)
lemma-dropLast≃ (≃nd b≤x b≤x' l⋘r l'⋘r' l≃r l'≃r' l≃l') (cl .b≤x .l⋘r)
with l'≃r' | l≃l' | l≃r | l⋘r | l'⋘r' | lemma-dropLast⋘ l'⋘r'
... | ≃lf | ≃lf | ≃lf | lf⋘ | lf⋘ | _ = ⋙lf b≤x
... | ≃nd x'≤y₁ x'≤y₂ l₁⋘r₁ l₂⋘r₂ _ _ _ | _ | _l≃r | _l⋘r | ll⋘ .x'≤y₁ .x'≤y₂ .l₁⋘r₁ .l₂⋘r₂ l₂≃r₂ _ | inj₁ (≃nd .x'≤y₁ .x'≤y₂ .l₁⋘r₁ .l₂⋘r₂ l₁≃r₁ _ l₁≃l₂) =
let l'≃r' = ≃nd x'≤y₁ x'≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂ ;
l'⋙dr' = lemma-dropLast≃ l'≃r' (cl x'≤y₁ l₁⋘r₁)
in ⋙rr b≤x b≤x' _l⋘r _l≃r l'⋙dr' l≃l'
... | ≃nd x'≤y₁ x'≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂ | _l≃l' | _l≃r | _l⋘r | ll⋘ .x'≤y₁ .x'≤y₂ .l₁⋘r₁ .l₂⋘r₂ _ _ | inj₂ dl'⋘r'
with lemma-dropLast-⊥ (≃nd x'≤y₁ x'≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂) dl'⋘r' (cl x'≤y₁ l₁⋘r₁)
... | ()
lemma-dropLast⋗ : {b : Bound}{l r : BBHeap b} → l ⋗ r → dropLast l ⋘ r
lemma-dropLast⋗ (⋗lf b≤x) = lf⋘
lemma-dropLast⋗ (⋗nd b≤x b≤x' l⋘r l'⋘r' l≃r l'≃r' l⋗l')
with l⋘r | l≃r | l⋗l' | lemma-dropLast⋘ l⋘r
... | lf⋘ | _ | () | _
... | lr⋘ x≤y₁ x≤y₂ l₁⋙r₁ l₂⋘r₂ l₁≃r₁ l₁⋗l₂ | _ | _ | inj₁ ()
... | lr⋘ x≤y₁ x≤y₂ l₁⋙r₁ l₂⋘r₂ l₁≃r₁ l₁⋗l₂ | () | _ | inj₂ _
... | ll⋘ x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ | _ | _ | inj₁ (≃nd .x≤y₁ .x≤y₂ .l₁⋘r₁ .l₂⋘r₂ l₁≃r₁ _ l₁≃l₂) =
let _l≃r = ≃nd x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂ ;
l⋙dr = lemma-dropLast≃ _l≃r (cl x≤y₁ l₁⋘r₁)
in lr⋘ b≤x b≤x' l⋙dr l'⋘r' l'≃r' l⋗l'
... | ll⋘ x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ _ r₁≃l₂ | ≃nd .x≤y₁ .x≤y₂ .l₁⋘r₁ .l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂ | _ | inj₂ dl⋘r
with lemma-dropLast-⊥ (≃nd x≤y₁ x≤y₂ l₁⋘r₁ l₂⋘r₂ l₁≃r₁ l₂≃r₂ l₁≃l₂) dl⋘r (cl x≤y₁ l₁⋘r₁)
... | ()
lemma-dropLast⋘ : {b : Bound}{l r : BBHeap b} → l ⋘ r → l ≃ r ∨ dropLast l ⋘ r
lemma-dropLast⋘ lf⋘ = inj₁ ≃lf
lemma-dropLast⋘ (ll⋘ b≤x b≤x' l⋘r l'⋘r' l'≃r' r≃l')
with l⋘r | l'⋘r' | r≃l' | lemma-dropLast⋘ l⋘r
... | lf⋘ | lf⋘ | ≃lf | _ = inj₁ (≃nd b≤x b≤x' lf⋘ lf⋘ ≃lf ≃lf ≃lf)
... | ll⋘ x'≤y₁ x'≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ | _l'⋘r' | _r≃l' | inj₁ l≃r =
let l≃l' = trans≃ l≃r _r≃l' ;
_l⋘r = ll⋘ x'≤y₁ x'≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂
in inj₁ (≃nd b≤x b≤x' _l⋘r _l'⋘r' l≃r l'≃r' l≃l')
... | ll⋘ x'≤y₁ x'≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ | _l'⋘r' | _r≃l' | inj₂ dl⋘r = inj₂ (ll⋘ b≤x b≤x' dl⋘r _l'⋘r' l'≃r' _r≃l')
... | lr⋘ x'≤y₁ x'≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ | _l'⋘r' | _r≃l' | inj₁ l≃r =
let l≃l' = trans≃ l≃r _r≃l' ;
_l⋘r = lr⋘ x'≤y₁ x'≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂
in inj₁ (≃nd b≤x b≤x' _l⋘r _l'⋘r' l≃r l'≃r' l≃l')
... | lr⋘ x'≤y₁ x'≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ | _l'⋘r' | _r≃l' | inj₂ dl⋘r = inj₂ (ll⋘ b≤x b≤x' dl⋘r _l'⋘r' l'≃r' _r≃l')
lemma-dropLast⋘ (lr⋘ b≤x b≤x' l⋙r l'⋘r' l'≃r' l⋗l')
with lemma-dropLast⋙ l⋙r
... | inj₁ l⋗r =
let dl⋘r = lemma-dropLast⋗ l⋗r ;
r≃l' = lemma⋗⋗' l⋗r l⋗l'
in inj₂ (ll⋘ b≤x b≤x' dl⋘r l'⋘r' l'≃r' r≃l')
... | inj₂ l⋙dr = inj₂ (lr⋘ b≤x b≤x' l⋙dr l'⋘r' l'≃r' l⋗l')
lemma-dropLast⋙ : {b : Bound}{l r : BBHeap b} → l ⋙ r → l ⋗ r ∨ l ⋙ dropLast r
lemma-dropLast⋙ (⋙lf b≤x) = inj₁ (⋗lf b≤x)
lemma-dropLast⋙ (⋙rl b≤x b≤x' l⋘r l≃r l'⋘r' l⋗r')
with l'⋘r' | l≃r | l⋗r' | lemma-dropLast⋘ l'⋘r'
... | lf⋘ | ≃nd x≤y _ lf⋘ lf⋘ ≃lf ≃lf ≃lf | ⋗lf .x≤y | _ = inj₁ (⋗nd b≤x b≤x' l⋘r lf⋘ l≃r ≃lf (⋗lf x≤y))
... | ll⋘ x'≤y₁ x'≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ | _l≃r | _l⋗r' | inj₁ l'≃r' =
let l⋗l' = lemma⋗≃ _l⋗r' (sym≃ l'≃r') ;
_l'⋘r' = ll⋘ x'≤y₁ x'≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂
in inj₁ (⋗nd b≤x b≤x' l⋘r _l'⋘r' _l≃r l'≃r' l⋗l')
... | ll⋘ x'≤y₁ x'≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ | _l≃r | _l⋗r' | inj₂ dl'⋘r' = inj₂ (⋙rl b≤x b≤x' l⋘r _l≃r dl'⋘r' _l⋗r')
... | lr⋘ x'≤y₁ x'≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ | _l≃r | _l⋗r' | inj₁ l'≃r' =
let l⋗l' = lemma⋗≃ _l⋗r' (sym≃ l'≃r') ;
_l'⋘r' = lr⋘ x'≤y₁ x'≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂
in inj₁ (⋗nd b≤x b≤x' l⋘r _l'⋘r' _l≃r l'≃r' l⋗l')
... | lr⋘ x'≤y₁ x'≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ | _l≃r | _l⋗r' | inj₂ dl'⋘r' = inj₂ (⋙rl b≤x b≤x' l⋘r _l≃r dl'⋘r' _l⋗r')
lemma-dropLast⋙ (⋙rr b≤x b≤x' l⋘r l≃r l'⋙r' l≃l')
with lemma-dropLast⋙ l'⋙r'
... | inj₁ l'⋗r' =
let dl'⋘r' = lemma-dropLast⋗ l'⋗r' ;
l⋗r' = lemma≃⋗ l≃l' l'⋗r'
in inj₂ (⋙rl b≤x b≤x' l⋘r l≃r dl'⋘r' l⋗r')
... | inj₂ l'⋙dr' = inj₂ (⋙rr b≤x b≤x' l⋘r l≃r l'⋙dr' l≃l')
|
{
"alphanum_fraction": 0.4740696458,
"avg_line_length": 58.1826086957,
"ext": "agda",
"hexsha": "24ac646872cf0817f41ba5726e6609a146da12cb",
"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/BBHeap/DropLast.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/BBHeap/DropLast.agda",
"max_line_length": 223,
"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/BBHeap/DropLast.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": 4828,
"size": 6691
}
|
module Data.Bin.Props where
open import Data.Bin
import Data.Nat
import Data.Nat.Properties
open Data.Nat using (ℕ)
open import Data.List
open import Relation.Binary.PropositionalEquality
open import Function using (_⟨_⟩_)
open import Algebra.Structures using (IsCommutativeMonoid; module IsCommutativeMonoid; module IsCommutativeSemiring)
import Data.Bin.Addition
bin-+-is-comm-monoid = Data.Bin.Addition.is-commutativeMonoid
open import Data.Bin.Bijection using (fromℕ-bijection)
import Algebra.Lifting
module Lifting = Algebra.Lifting _ _ fromℕ-bijection
open import Data.Bin.Multiplication
bin-*-is-comm-monoid : IsCommutativeMonoid _≡_ _*_ ([] 1#)
bin-*-is-comm-monoid = lift-isCommutativeMonoid 1 *-isCommutativeMonoid
where
open IsCommutativeSemiring Data.Nat.Properties.isCommutativeSemiring using(*-isCommutativeMonoid)
open Lifting.WithOp₂ Data.Nat._*_ _*_ *-is-multiplication
open IsCommutativeMonoid bin-*-is-comm-monoid using () renaming (comm to *-comm)
*2-is-2* : ∀ x → x *2 ≡ (fromℕ 2) * x
*2-is-2* 0# = refl
*2-is-2* (bs 1#) = refl
*-distrib : ∀ {a b c} → (a + b) * c ≡ a * c + b * c
*-distrib {a} {b} {c} = Data.Bin.Multiplication.*-distribʳ a b c
*2-distrib : ∀ a b → (a + b) *2 ≡ a *2 + b *2
*2-distrib a b = *2-is-*2-bin (a + b) ⟨ trans ⟩ *-distrib {a} {b} {fromℕ 2} ⟨ trans ⟩ cong₂ _+_ (sym (*2-is-*2-bin a)) (sym (*2-is-*2-bin b))
where
*2-is-*2-bin : ∀ a → a *2 ≡ a * fromℕ 2
*2-is-*2-bin a = *2-is-2* a ⟨ trans ⟩ *-comm (fromℕ 2) a
open import Function
open import Data.Empty
1+≢0 : ∀ l → toℕ (l 1#) ≢ 0
1+≢0 l eq = case Data.Bin.Bijection.toℕ-inj {l 1#} {0#} eq of (λ ())
z<nzℕ : ∀ {n} → n ≢ 0 → Data.Nat._<_ 0 n
z<nzℕ {Data.Bin.0b} neq = ⊥-elim (neq refl)
z<nzℕ {Data.Bin.Bijection.1+ n} neq = Data.Nat.s≤s Data.Nat.z≤n
z<nz : ∀ l → 0# < l 1#
z<nz l = Data.Bin.less (z<nzℕ (1+≢0 l))
|
{
"alphanum_fraction": 0.639019301,
"avg_line_length": 34.2321428571,
"ext": "agda",
"hexsha": "27af607a30a81df8ff10e3e7e603d3c06c86cad7",
"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": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "Rotsor/BinDivMod",
"max_forks_repo_path": "Data/Bin/Props.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "Rotsor/BinDivMod",
"max_issues_repo_path": "Data/Bin/Props.agda",
"max_line_length": 143,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Rotsor/BinDivMod",
"max_stars_repo_path": "Data/Bin/Props.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-18T13:58:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-18T13:58:14.000Z",
"num_tokens": 776,
"size": 1917
}
|
import cedille-options
open import general-util
module classify (options : cedille-options.options) {mF : Set → Set} {{_ : monad mF}} where
open import lib
open import cedille-types
open import constants
open import conversion
open import ctxt
open import is-free
open import lift
open import rename
open import rewriting
open import meta-vars options {mF}
open import spans options {mF}
open import subst
open import syntax-util
open import to-string options
open import untyped-spans options {mF}
check-ret : ∀{A : Set} → maybe A → Set
check-ret{A} nothing = maybe A
check-ret (just _) = ⊤
infixl 2 _≫=spanr_
_≫=spanr_ : ∀{A : Set}{m : maybe A} → spanM (maybe A) → (A → spanM (check-ret m)) → spanM (check-ret m)
_≫=spanr_{m = nothing} = _≫=spanm_
_≫=spanr_{m = just _} = _≫=spanj_
-- return the appropriate value meaning that typing failed (in either checking or synthesizing mode)
check-fail : ∀{A : Set} → (m : maybe A) → spanM (check-ret m)
check-fail nothing = spanMr nothing
check-fail (just _) = spanMok
unimplemented-check : spanM ⊤
unimplemented-check = spanMok
unimplemented-synth : ∀{A : Set} → spanM (maybe A)
unimplemented-synth = spanMr nothing
unimplemented-if : ∀{A : Set} → (m : maybe A) → spanM (check-ret m)
unimplemented-if nothing = unimplemented-synth
unimplemented-if (just _) = unimplemented-check
-- return the second maybe value, if we are in synthesizing mode
return-when : ∀{A : Set} → (m : maybe A) → maybe A → spanM (check-ret m)
return-when nothing u = spanMr u
return-when (just _) u = spanMr triv
-- if m is not "nothing", return "just star"
return-star-when : (m : maybe kind) → spanM (check-ret m)
return-star-when m = return-when m (just star)
if-check-against-star-data : ctxt → string → maybe kind → 𝕃 tagged-val × err-m
if-check-against-star-data Γ desc nothing = [ kind-data Γ star ] , nothing
if-check-against-star-data Γ desc (just (Star _)) = [ kind-data Γ star ] , nothing
if-check-against-star-data Γ desc (just k) = [ expected-kind Γ k ] , just (desc ^ " is being checked against a kind other than ★")
hnf-from : ctxt → (e : 𝔹) → maybeMinus → term → term
hnf-from Γ e EpsHnf t = hnf Γ (unfolding-set-erased unfold-head e) t tt
hnf-from Γ e EpsHanf t = hanf Γ e t
maybe-hnf : {ed : exprd} → ctxt → maybe ⟦ ed ⟧ → maybe ⟦ ed ⟧
maybe-hnf Γ = maybe-map λ t → hnf Γ (unfolding-elab unfold-head) t tt
check-term-update-eq : ctxt → leftRight → maybeMinus → posinfo → term → term → posinfo → type
check-term-update-eq Γ Left m pi t1 t2 pi' = TpEq pi (hnf-from Γ tt m t1) t2 pi'
check-term-update-eq Γ Right m pi t1 t2 pi' = TpEq pi t1 (hnf-from Γ tt m t2) pi'
check-term-update-eq Γ Both m pi t1 t2 pi' = TpEq pi (hnf-from Γ tt m t1) (hnf-from Γ tt m t2) pi'
add-tk' : erased? → posinfo → var → tk → spanM restore-def
add-tk' e pi x atk =
helper atk ≫=span λ mi →
(if ~ (x =string ignored-var) then
(get-ctxt λ Γ →
spanM-add (var-span e Γ pi x checking atk nothing))
else spanMok) ≫span
spanMr mi
where helper : tk → spanM restore-def
helper (Tkk k) = spanM-push-type-decl pi x k
helper (Tkt t) = spanM-push-term-decl pi x t
add-tk : posinfo → var → tk → spanM restore-def
add-tk = add-tk' ff
check-type-return : ctxt → kind → spanM (maybe kind)
check-type-return Γ k = spanMr (just (hnf Γ unfold-head k tt))
check-termi-return-hnf : ctxt → (subject : term) → type → spanM (maybe type)
check-termi-return-hnf Γ subject tp = spanMr (just (hnf Γ (unfolding-elab unfold-head) tp tt))
lambda-bound-var-conv-error : ctxt → var → tk → tk → 𝕃 tagged-val → 𝕃 tagged-val × string
lambda-bound-var-conv-error Γ x atk atk' tvs =
(("the variable" , [[ x ]] , []) :: (to-string-tag-tk "its declared classifier" Γ atk') :: [ to-string-tag-tk "the expected classifier" Γ atk ]) ++ tvs ,
"The classifier given for a λ-bound variable is not the one we expected"
lambda-bound-class-if : optClass → tk → tk
lambda-bound-class-if NoClass atk = atk
lambda-bound-class-if (SomeClass atk') atk = atk'
{- for check-term and check-type, if the optional classifier is given, we will check against it.
Otherwise, we will try to synthesize a type.
check-type should return kinds in hnf using check-type-return.
Use add-tk above to add declarations to the ctxt, since these should be normalized
and with self-types instantiated.
The term/type/kind being checked is never qualified, but the type/kind it is being
checked against should always be qualified. So if a term/type is ever being checked
against something that was in a term/type the user wrote (phi, for example, needs to
check its first term against an equation between its second and third terms), the type/
kind being checked against should be qualified first. Additionally, when returning
a synthesized type, lambdas should substitute the position-qualified variable for the
original variable in the returned type, so that if the bound variable ever gets
substituted by some other code it will work correctly.
-}
record spine-data : Set where
constructor mk-spine-data
field
spine-mvars : meta-vars
spine-type : decortype
spine-locale : ℕ
{-# TERMINATING #-}
check-term : term → (m : maybe type) → spanM (check-ret m)
check-termi : term → (m : maybe type) → spanM (check-ret m)
check-term-spine : term → (m : prototype) → 𝔹 → spanM (maybe spine-data)
check-type : type → (m : maybe kind) → spanM (check-ret m)
check-typei : type → (m : maybe kind) → spanM (check-ret m)
check-kind : kind → spanM ⊤
check-args-against-params : (kind-or-import : maybe tagged-val {- location -}) → (posinfo × var) → params → args → spanM ⊤
check-erased-margs : term → maybe type → spanM ⊤
check-tk : tk → spanM ⊤
check-def : defTermOrType → spanM (var × restore-def)
{- Cedilleum specification, section 4.3 -}
is-arrow-type : type → kind → posinfo → posinfo → spanM ⊤
is-arrow-type t (KndTpArrow t' (Star _)) pi pi' =
get-ctxt (λ Γ → if (conv-type Γ t t') then spanMok
else (spanM-add (mk-span "Wrong motive" pi pi' (expected-type Γ t :: [ type-argument Γ t' ]) (just "Type missmatch"))))
is-arrow-type t (KndPi _ _ _ (Tkt t') (Star _)) pi pi' =
get-ctxt (λ Γ → if (conv-type Γ t t') then spanMok
else (spanM-add (mk-span "Wrong motive" pi pi' (expected-type Γ t :: [ type-argument Γ t' ]) (just "Type missmatch"))))
is-arrow-type t _ pi pi' =
spanM-add (mk-span "Wrong motive" pi pi' [] (just "Not a valid motive type 3"))
-- example of renaming: [[%CE%93%E2%86%92%CE%93' : ctxt %E2%86%92 ctxt][here]]
-- [[check-term-spine t'@(App t%E2%82%81 e? t%E2%82%82) mtp max =]]
valid-elim-kind : type → kind → kind → posinfo → posinfo → spanM ⊤
valid-elim-kind t (Star _) k pi pi' = is-arrow-type t k pi pi'
valid-elim-kind t (KndPi _ pix x (Tkt t1) k1) (KndPi _ _ y (Tkt t2) k2) pi pi' =
get-ctxt (λ Γ →
if (conv-type Γ t1 t2) then
set-ctxt (ctxt-term-decl pix x t1 Γ) ≫span
valid-elim-kind (TpAppt t (Var pix x)) k1 k2 pi pi'
else
spanM-add (mk-span "Motive error" pi pi' [] (just "Not a valid motive 4")))
valid-elim-kind t (KndPi _ pix x (Tkk k1') k1) (KndPi _ _ y (Tkk k2') k2) pi pi' =
get-ctxt (λ Γ →
if (conv-kind Γ k1' k2') then
set-ctxt (ctxt-type-decl pix x k1' Γ) ≫span
valid-elim-kind (TpApp t (TpVar pix x)) k1 k2 pi pi'
else
spanM-add (mk-span "Motive error" pi pi' [] (just "Not a valid motive 5")))
valid-elim-kind t (KndTpArrow t1 k1) (KndTpArrow t2 k2) pi pi' =
get-ctxt (λ Γ →
if (conv-type Γ t1 t2) then
valid-elim-kind (TpApp t t1) k1 k2 pi pi'
else
spanM-add (mk-span "Motive error" pi pi' [] (just "Not a valid motive 6")))
valid-elim-kind _ _ _ pi pi' =
spanM-add (mk-span "Motive error" pi pi' [] (just "Not a valid motive 7"))
{- Cedilleum specification, section 4.4 -}
branch-type : ctxt → term → type → type → type
-- Π x : Tk, ∀ x : T, ∀ x : k cases
branch-type Γ t (Abs pi e pi' x tk ty) m = Abs pi e pi' x tk (branch-type Γ t ty m)
branch-type Γ t _ m = TpAppt m t -- TODO: missing indices s ! is ctxt needed ?
-- converts mu cases (Example: from "vcons -n -m x xs -eq → ff" to "Λ n. Λ m. λ x. λ xs. Λ eq. ff")
abstract-varargs : varargs → term → spanM (maybe term)
abstract-varargs NoVarargs t = spanMr (just t)
abstract-varargs (NormalVararg x vs) t =
(abstract-varargs vs t) on-fail (spanMr nothing) ≫=spanm' (λ a →
spanMr (just (Lam posinfo-gen NotErased posinfo-gen x NoClass a)))
abstract-varargs (ErasedVararg x vs) t =
(abstract-varargs vs t) on-fail (spanMr nothing) ≫=spanm' (λ a →
spanMr (just (Lam posinfo-gen Erased posinfo-gen x NoClass a)))
abstract-varargs (TypeVararg x vs) t =
(abstract-varargs vs t) on-fail (spanMr nothing) ≫=spanm' (λ a →
get-ctxt (λ Γ → helper (ctxt-lookup-type-var Γ x) a))
where
helper : maybe kind → term → spanM (maybe term)
helper nothing t = spanMr nothing
helper (just k) t = spanMr (just (Lam posinfo-gen Erased posinfo-gen x (SomeClass (Tkk k)) t))
check-cases : dataConsts → cases → params → type → posinfo → posinfo → spanM ⊤
check-cases DataNull NoCase _ _ _ _ = spanMok
check-cases (DataCons (DataConst _ c t) cts) (SomeCase pi c' varsargs t' cs) ps ty pic pic' =
spanM-add (mk-span "Mu case" pi (term-end-pos t') [] nothing) ≫span
check-cases cts cs ps ty pic pic'
check-cases _ _ _ _ pic pic' = spanM-add (mk-span "Mu Cases error" pic pic' [] (just "Number of cases and constructors do not match"))
{- Cedilleum specification, section 4.5 -}
well-formed-patterns : defDatatype → term → type → cases → posinfo → posinfo → spanM ⊤
well-formed-patterns dd@(Datatype pi pix x ps k cons pf) t P cases pic pic' =
(check-type P nothing) on-fail (spanM-add (mk-span "Wrong motive" (type-start-pos P) (type-end-pos P) [] (just "Motive does not typecheck"))) ≫=spanm' (λ kmtv →
get-ctxt (λ Γ → valid-elim-kind (lam-expand-type ps (qualif-type Γ (TpVar pix x))) k kmtv (type-start-pos P) (type-end-pos P) ≫span
check-cases cons cases ps P pic pic'))
-- check-term
-- ==================================================
module check-term-errors {A : Set} where
inapplicable-tp : (t : term) (tp : type) (htp : type) (mtp : maybe type) → spanM $ check-ret mtp
inapplicable-tp t tp htp m =
get-ctxt λ Γ →
spanM-add (AppTp-span t tp (maybe-to-checking m)
([ head-type Γ htp ])
(just "The type of the head does not allow it to be applied to a type argument"))
≫span (spanMr $ ret m)
where
ret : (m : maybe type) → check-ret m
ret (just x₁) = triv
ret nothing = nothing
check-term = check-termi -- Used to call hnf on expected/synthesized type
check-type subject nothing = check-typei subject nothing
check-type subject (just k)
= get-ctxt (λ Γ → check-typei subject (just (hnf Γ (unfolding-elab unfold-head) k tt)))
check-termi (Parens pi t pi') tp =
spanM-add (punctuation-span "Parens" pi pi') ≫span
check-termi t tp
check-termi (Var pi x) mtp =
get-ctxt (cont mtp)
where cont : (mtp : maybe type) → ctxt → spanM (check-ret mtp)
cont mtp Γ with ctxt-lookup-term-var Γ x
cont mtp Γ | nothing =
spanM-add (Var-span Γ pi x (maybe-to-checking mtp)
(expected-type-if Γ mtp ++ [ missing-type ]) (just "Missing a type for a term variable.")) ≫span
return-when mtp mtp
cont nothing Γ | just tp =
spanM-add (Var-span Γ pi x synthesizing [ type-data Γ tp ] nothing)
≫span spanMr (just tp)
cont (just tp) Γ | just tp' =
spanM-add (uncurry (Var-span Γ pi x checking) (check-for-type-mismatch Γ "synthesized" tp tp'))
check-termi t'@(AppTp t tp') mtp =
get-ctxt λ Γ →
check-termi t nothing
on-fail spanM-add (AppTp-span t tp' (maybe-to-checking mtp)
(expected-type-if Γ mtp) nothing)
≫span return-when mtp mtp
≫=spanm' λ tp → spanMr (either-else' (to-is-tpabs tp)
(λ _ → to-is-tpabs (hnf Γ (unfolding-elab unfold-head) tp tt)) inj₂)
on-fail (λ _ → check-term-errors.inapplicable-tp {A = check-ret mtp} t tp' tp mtp)
≫=spans' λ ret → let mk-tpabs e? x k body = ret in
check-type tp' (just k)
≫span
let rtp = subst Γ (qualif-type Γ tp') x body in
spanM-add (uncurry (λ tvs →
AppTp-span t tp' (maybe-to-checking mtp) (type-data Γ rtp :: tvs))
(check-for-type-mismatch-if Γ "synthesizing" mtp rtp))
≫span return-when mtp (just rtp)
check-termi t''@(App t m t') tp =
get-ctxt λ Γ → check-term-spine t'' (proto-maybe tp) tt
on-fail check-fail tp
≫=spanm' λ where
(mk-spine-data Xs tp' _) → return-when tp (just (meta-vars-subst-type' ff Γ Xs (decortype-to-type tp')))
check-termi (Let pi d t) mtp =
-- spanM-add (punctuation-span "Let" pi (posinfo-plus pi 3)) ≫span
check-def d ≫=span finish
where maybe-subst : defTermOrType → (mtp : maybe type) → check-ret mtp → spanM (check-ret mtp)
maybe-subst _ (just T) triv = spanMok
maybe-subst _ nothing nothing = spanMr nothing
maybe-subst (DefTerm pi x NoType t) nothing (just T) = get-ctxt λ Γ →
spanMr (just (subst Γ (qualif-term Γ (Chi posinfo-gen NoType t)) (pi % x) T))
maybe-subst (DefTerm pi x (SomeType T') t) nothing (just T) = get-ctxt λ Γ →
spanMr (just (subst Γ (qualif-term Γ (Chi posinfo-gen (SomeType T') t)) (pi % x) T))
maybe-subst (DefType pi x k T') nothing (just T) = get-ctxt λ Γ →
spanMr (just (subst Γ (qualif-type Γ T') (pi % x) T))
-- maybe-subst covers the case where the synthesized type of t has the let-bound
-- variable in it by substituting the let definition for the let-bound variable
-- in the synthesized type. We also need to use Chi to maintain the checking mode
-- of the term so that the type still kind-checks, as a synthesizing term let could
-- be substituted into a checking position, or vice-versa with a checking term let.
finish : (var × restore-def) → spanM (check-ret mtp)
finish (x , m) =
get-ctxt λ Γ →
spanM-add (Let-span Γ (maybe-to-checking mtp) pi d t [] nothing) ≫span
check-term t mtp ≫=span λ r →
spanM-restore-info x m ≫span
maybe-subst d mtp r
check-termi (Open pi x t) mtp =
get-ctxt (λ Γ →
spanMr (ctxt-get-qi Γ x) ≫=span λ where
(just (x' , _)) →
cont x' mtp
nothing →
spanM-add (Var-span Γ (posinfo-plus pi 5) x (maybe-to-checking mtp) [] (just (nodef-err x))) ≫span
-- (open-span (just (nodef-err x))) ≫span
(check-fail mtp))
where
span-name = "Open an opaque definition in a sub-term"
nodef-err : string → string
nodef-err s = "the definition '" ^ s ^ "' is not in scope"
category-err : string → string
category-err s = "the definition '" ^ s ^ "' is not a type/term definition"
open-span : err-m → span
open-span err = mk-span span-name pi (term-end-pos t) [] err
cont : var → (m : maybe type) → spanM (check-ret m)
cont v mtp =
spanM-clarify-def v ≫=span λ where
(just si) →
spanM-add (open-span nothing) ≫span
get-ctxt (λ Γ' →
spanM-add (Var-span Γ' (posinfo-plus pi 5) x (maybe-to-checking mtp) [] nothing) ≫span
check-term t mtp ≫=span λ r →
spanM-restore-clarified-def v si ≫span
spanMr r)
nothing →
spanM-add (open-span (just (category-err v))) ≫span
(check-fail mtp)
check-termi (Lam pi l pi' x (SomeClass atk) t) nothing =
spanM-add (punctuation-span "Lambda" pi (posinfo-plus pi 1)) ≫span
check-tk atk ≫span
add-tk pi' x atk ≫=span λ mi →
check-term t nothing ≫=span λ mtp →
spanM-restore-info x mi ≫span -- now restore the context
cont mtp
where cont : maybe type → spanM (maybe type)
cont nothing =
get-ctxt λ Γ →
spanM-add (Lam-span Γ synthesizing pi l x (SomeClass atk) t [] nothing) ≫span
spanMr nothing
cont (just tp) =
get-ctxt λ Γ →
let atk' = qualif-tk Γ atk in
-- This should indeed "unqualify" occurrences of x in tp for rettp
let rettp = abs-tk l x atk' (rename-var Γ (pi' % x) x tp) in
let tvs = [ type-data Γ rettp ] in
let p = if me-erased l && is-free-in skip-erased x t then just "The bound variable occurs free in the erasure of the body (not allowed)." , [ erasure Γ t ] else nothing , [] in
spanM-add (Lam-span Γ synthesizing pi l x (SomeClass atk') t (snd p ++ tvs) (fst p)) ≫span
check-termi-return-hnf Γ (Lam pi l pi' x (SomeClass atk) t) rettp
check-termi (Lam pi l _ x NoClass t) nothing =
get-ctxt λ Γ →
spanM-add (punctuation-span "Lambda" pi (posinfo-plus pi 1)) ≫span
spanM-add (Lam-span Γ synthesizing pi l x NoClass t []
(just ("We are not checking this abstraction against a type, so a classifier must be"
^ " given for the bound variable " ^ x))) ≫span
spanMr nothing
check-termi (Lam pi l pi' x oc t) (just tp) =
get-ctxt λ Γ → cont (to-abs tp maybe-or to-abs (hnf Γ unfold-head tp tt)) where
cont : maybe abs → spanM ⊤
cont (just (mk-abs b x' atk _ tp')) =
check-oc oc ≫span
spanM-add (punctuation-span "Lambda" pi (posinfo-plus pi 1)) ≫span
get-ctxt λ Γ →
spanM-add (uncurry (this-span Γ atk oc) (check-erasures Γ l b)) ≫span
add-tk' (me-erased l) pi' x (lambda-bound-class-if oc atk) ≫=span λ mi →
get-ctxt λ Γ' → check-term t (just (rename-var Γ x' (qualif-var Γ' x) tp')) ≫span
spanM-restore-info x mi where
this-span : ctxt → tk → optClass → 𝕃 tagged-val → err-m → span
this-span Γ _ NoClass tvs = Lam-span Γ checking pi l x oc t tvs
this-span Γ atk (SomeClass atk') tvs err =
if conv-tk Γ (qualif-tk Γ atk') atk then
Lam-span Γ checking pi l x oc t tvs err
else
let p = lambda-bound-var-conv-error Γ x atk atk' tvs in
Lam-span Γ checking pi l x oc t (fst p) (just (snd p))
check-oc : optClass → spanM ⊤
check-oc NoClass = spanMok
check-oc (SomeClass atk) = check-tk atk
check-erasures : ctxt → maybeErased → maybeErased → 𝕃 tagged-val × err-m
check-erasures Γ Erased All =
if is-free-in skip-erased x t
then type-data Γ tp :: [ erasure Γ t ] , just "The Λ-bound variable occurs free in the erasure of the body."
else [ type-data Γ tp ] , nothing
check-erasures Γ NotErased Pi = [ type-data Γ tp ] , nothing
check-erasures Γ Erased Pi = [ expected-type Γ tp ] , just ("The expected type is a Π-abstraction (indicating explicit input), but"
^ " the term is a Λ-abstraction (implicit input).")
check-erasures Γ NotErased All = [ expected-type Γ tp ] , just ("The expected type is a ∀-abstraction (indicating implicit input), but"
^ " the term is a λ-abstraction (explicit input).")
cont nothing =
get-ctxt λ Γ →
spanM-add (punctuation-span "Lambda" pi (posinfo-plus pi 1)) ≫span
spanM-add (Lam-span Γ checking pi l x oc t [ expected-type Γ tp ] (just "The expected type is not of the form that can classify a λ-abstraction"))
check-termi (Beta pi ot ot') (just tp) =
untyped-optTerm-spans ot ≫span
untyped-optTerm-spans ot' ≫span
get-ctxt λ Γ →
spanM-add (uncurry (Beta-span pi (optTerm-end-pos-beta pi ot ot') checking)
(case hnf Γ unfold-head tp tt of λ where
(TpEq pi' t1 t2 pi'') →
if conv-term Γ t1 t2
then [ type-data Γ (TpEq pi' t1 t2 pi'') ] , (optTerm-conv Γ t1 ot)
else [ expected-type Γ (TpEq pi' t1 t2 pi'') ] , (just "The two terms in the equation are not β-equal")
tp → [ expected-type Γ tp ] , just "The expected type is not an equation."))
where
optTerm-conv : ctxt → term → optTerm → err-m
optTerm-conv Γ t1 NoTerm = nothing
optTerm-conv Γ t1 (SomeTerm t _) = if conv-term Γ (qualif-term Γ t) t1 then nothing else just "The expected type does not match the synthesized type"
check-termi (Beta pi (SomeTerm t pi') ot) nothing =
get-ctxt λ Γ →
untyped-term-spans t ≫span
untyped-optTerm-spans ot ≫span
let tp = qualif-type Γ (TpEq posinfo-gen t t posinfo-gen) in
spanM-add (Beta-span pi (optTerm-end-pos-beta pi (SomeTerm t pi') ot) synthesizing [ type-data Γ tp ] nothing) ≫span
spanMr (just tp)
check-termi (Beta pi NoTerm ot') nothing =
untyped-optTerm-spans ot' ≫span
spanM-add (Beta-span pi (optTerm-end-pos-beta pi NoTerm ot') synthesizing [] (just "An expected type is required in order to type a use of plain β.")) ≫span
spanMr nothing
check-termi (Epsilon pi lr m t) (just tp) = -- (TpEq pi' t1 t2 pi'')) =
get-ctxt λ Γ →
case hnf Γ unfold-head tp tt of λ where
(TpEq pi' t1 t2 pi'') →
spanM-add (Epsilon-span pi lr m t checking [ type-data Γ (TpEq pi' t1 t2 pi'') ] nothing) ≫span
check-term t (just (check-term-update-eq Γ lr m pi' t1 t2 pi''))
tp → spanM-add (Epsilon-span pi lr m t checking [ expected-type Γ tp ] (just "The expected type is not an equation, when checking an ε-term."))
check-termi (Epsilon pi lr m t) nothing =
check-term t nothing ≫=span λ mtp → get-ctxt λ Γ → cont (maybe-hnf Γ mtp)
where cont : maybe type → spanM (maybe type)
cont nothing =
spanM-add (Epsilon-span pi lr m t synthesizing []
(just "There is no expected type, and we could not synthesize a type from the body of the ε-term.")) ≫span
spanMr nothing
cont (just (TpEq pi' t1 t2 pi'')) =
get-ctxt λ Γ →
let r = check-term-update-eq Γ lr m pi' t1 t2 pi'' in
spanM-add (Epsilon-span pi lr m t synthesizing [ type-data Γ r ] nothing) ≫span
spanMr (just r)
cont (just tp) =
get-ctxt λ Γ →
spanM-add (Epsilon-span pi lr m t synthesizing [ to-string-tag "the synthesized type" Γ tp ]
(just "There is no expected type, and the type we synthesized for the body of the ε-term is not an equation.")) ≫span
spanMr nothing
check-termi (Sigma pi t) mt =
check-term t nothing ≫=span λ mt' → get-ctxt λ Γ → cont Γ mt (maybe-hnf Γ mt')
where cont : ctxt → (outer : maybe type) → maybe type → spanM (check-ret outer)
cont Γ mt nothing =
spanM-add (Sigma-span pi t (maybe-to-checking mt) [] (just "We could not synthesize a type from the body of the ς-term")) ≫span
check-fail mt
cont Γ mt (just tp) with mt | hnf Γ unfold-head tp tt
...| nothing | TpEq pi' t1 t2 pi'' =
spanM-add (Sigma-span pi t synthesizing [ type-data Γ (TpEq pi' t2 t1 pi'') ] nothing) ≫span
spanMr (just (TpEq pi' t2 t1 pi''))
...| just tp' | TpEq pi' t1 t2 pi'' =
spanM-add ∘ (flip uncurry) (check-for-type-mismatch Γ "synthesized" tp' (TpEq pi' t2 t1 pi'')) $
λ tvs err → Sigma-span pi t checking tvs err
...| mt' | tp' =
spanM-add (Sigma-span pi t (maybe-to-checking mt') (to-string-tag "the synthesized type" Γ tp' :: expected-type-if Γ mt')
(just ("The type we synthesized for the body of the ς-term is not an equation"))) ≫span
check-fail mt'
check-termi (Phi pi t₁≃t₂ t₁ t₂ pi') (just tp) =
get-ctxt λ Γ →
check-term t₁≃t₂ (just (qualif-type Γ (TpEq posinfo-gen t₁ t₂ posinfo-gen))) ≫span
check-term t₁ (just tp) ≫span
untyped-term-spans t₂ ≫span
spanM-add (Phi-span pi pi' checking [ type-data Γ tp ] nothing)
check-termi (Phi pi t₁≃t₂ t₁ t₂ pi') nothing =
get-ctxt λ Γ →
check-term t₁≃t₂ (just (qualif-type Γ (TpEq posinfo-gen t₁ t₂ posinfo-gen))) ≫span
check-term t₁ nothing ≫=span λ mtp →
untyped-term-spans t₂ ≫span
spanM-add (Phi-span pi pi' synthesizing (type-data-tvs Γ mtp) nothing) ≫span
spanMr mtp
where
type-data-tvs : ctxt → maybe type → 𝕃 tagged-val
type-data-tvs Γ (just tp) = [ type-data Γ tp ]
type-data-tvs Γ nothing = []
check-termi (Rho pi op on t (Guide pi' x tp) t') nothing =
get-ctxt λ Γ →
spanM-add (Var-span (ctxt-var-decl-loc pi' x Γ) pi' x synthesizing [] nothing) ≫span
check-term t' nothing ≫=span λ mtp →
untyped-optGuide-spans (Guide pi' x tp) ≫span
check-term t nothing ≫=span λ mtp' → case maybe-hnf Γ mtp' of λ where
(just (TpEq _ t1 t2 _)) → maybe-else
(spanM-add (Rho-span pi t t' synthesizing op (inj₂ x) [] nothing) ≫span spanMr nothing)
(λ tp' →
let Γ' = ctxt-var-decl-loc pi' x Γ
tp = qualif-type Γ' tp
tp'' = subst Γ t1 x tp
qt = qualif-term Γ t
-- tp''' = qualif-type Γ (subst-type Γ t2 x tp)
tp''' = post-rewrite Γ' x qt t2 (rewrite-at Γ' x qt tt tp' tp) in
if conv-type Γ tp'' tp'
then (spanM-add (Rho-span pi t t' synthesizing op (inj₂ x) [ type-data Γ tp''' ] nothing) ≫span spanMr (just tp'''))
else (spanM-add (Rho-span pi t t' synthesizing op (inj₂ x) (type-data Γ tp' :: [ expected-type-subterm Γ tp'' ])
(just "The expected type of the subterm does not match the synthesized type")) ≫span spanMr nothing)) mtp
(just _) → spanM-add (Rho-span pi t t' synthesizing op (inj₂ x) []
(just "We could not synthesize an equation from the first subterm in a ρ-term.")) ≫span spanMr nothing
nothing → spanM-add (Rho-span pi t t' synthesizing op (inj₂ x) [] nothing) ≫span check-term t' nothing
check-termi (Rho pi op on t (Guide pi' x tp) t') (just tp') =
get-ctxt λ Γ →
untyped-optGuide-spans (Guide pi' x tp) ≫span
check-term t nothing ≫=span λ mtp → case maybe-hnf Γ mtp of λ where
(just (TpEq _ t1 t2 _)) →
let Γ' = ctxt-var-decl-loc pi' x Γ
qt = qualif-term Γ t
tp = qualif-type Γ' tp
tp'' = subst Γ' t2 x tp -- This is t2 (and t1 below) so that Cedille Core files are correctly checked by regular Cedille
-- tp''' = subst-type Γ t1 x (qualif-type Γ tp)
tp''' = post-rewrite Γ' x qt t1 (rewrite-at Γ' x qt tt tp' tp)
err = if conv-type Γ tp'' tp' then nothing else just "The expected type does not match the specified type" in
spanM-add (Rho-span pi t t' checking op (inj₂ x) (type-data Γ tp'' :: [ expected-type Γ tp' ]) err) ≫span
spanM-add (Var-span (ctxt-var-decl-loc pi' x Γ) pi' x checking [] nothing) ≫span
check-term t' (just tp''')
(just _) → spanM-add (Rho-span pi t t' checking op (inj₂ x) []
(just "We could not synthesize an equation from the first subterm in a ρ-term."))
nothing → spanM-add (Rho-span pi t t' checking op (inj₂ x) [] nothing) ≫span check-term t' (just tp)
check-termi (Rho pi op on t NoGuide t') (just tp) =
get-ctxt λ Γ → check-term t nothing ≫=span λ mtp →
cont (maybe-hnf Γ mtp) (hnf Γ unfold-head-no-lift tp tt)
where cont : maybe type → type → spanM ⊤
cont nothing tp = get-ctxt λ Γ → spanM-add (Rho-span pi t t' checking op (inj₁ 0) [ expected-type Γ tp ] nothing) ≫span check-term t' (just tp)
cont (just (TpEq pi' t1 t2 pi'')) tp =
get-ctxt λ Γ →
let ns-err = optNums-to-stringset on
x = fresh-var "x" (ctxt-binds-var Γ) empty-renamectxt
Γ' = ctxt-var-decl x Γ
qt = qualif-term Γ t
s = rewrite-type tp Γ' (is-rho-plus op) (fst ns-err) qt t1 x 0
T = post-rewrite Γ' x qt t2 (fst s) in -- subst-type Γ' t2 x (fst s) in
check-term t' (just T) ≫span
spanM-add (Rho-span pi t t' checking op (inj₁ (fst (snd s))) ((to-string-tag "the equation" Γ (TpEq pi' t1 t2 pi'')) :: [ type-data Γ tp ]) (snd ns-err (snd (snd s))))
cont (just tp') tp =
get-ctxt λ Γ → spanM-add (Rho-span pi t t' checking op (inj₁ 0)
((to-string-tag "the synthesized type for the first subterm" Γ tp')
:: [ expected-type Γ tp ])
(just "We could not synthesize an equation from the first subterm in a ρ-term."))
check-termi (Rho pi op on t NoGuide t') nothing =
check-term t nothing ≫=span λ mtp →
check-term t' nothing ≫=span λ mtp' → get-ctxt λ Γ → cont (maybe-hnf Γ mtp)
(maybe-map (λ mtp' → hnf Γ unfold-head-no-lift mtp' tt) mtp')
where cont : maybe type → maybe type → spanM (maybe type)
cont (just (TpEq pi' t1 t2 pi'')) (just tp) =
get-ctxt λ Γ →
let ns-err = optNums-to-stringset on
x = fresh-var "x" (ctxt-binds-var Γ) empty-renamectxt
qt = qualif-term Γ t
Γ' = ctxt-var-decl x Γ
s = rewrite-type tp Γ' (is-rho-plus op) (fst ns-err) qt t1 x 0
tp' = post-rewrite Γ' x qt t2 (fst s) in -- subst-type Γ t2 x (fst s) in
spanM-add (Rho-span pi t t' synthesizing op (inj₁ (fst (snd s))) [ type-data Γ tp' ] (snd ns-err (snd (snd s)))) ≫span
check-termi-return-hnf Γ (Rho pi op on t NoGuide t') tp'
cont (just tp') (just _) =
get-ctxt λ Γ → spanM-add (Rho-span pi t t' synthesizing op (inj₁ 0) [ to-string-tag "the synthesized type for the first subterm" Γ tp' ]
(just "We could not synthesize an equation from the first subterm in a ρ-term.")) ≫span spanMr nothing
cont _ _ = spanM-add (Rho-span pi t t' synthesizing op (inj₁ 0) [] nothing) ≫span spanMr nothing
check-termi (Chi pi (SomeType tp) t) mtp =
check-type tp (just star) ≫span
get-ctxt λ Γ →
let tp' = qualif-type Γ tp in
check-termi t (just tp') ≫span cont tp' mtp
where cont : type → (m : maybe type) → spanM (check-ret m)
cont tp' nothing = get-ctxt λ Γ → spanM-add (Chi-span Γ pi (SomeType tp) t synthesizing [] nothing) ≫span spanMr (just tp')
cont tp' (just tp'') =
get-ctxt λ Γ →
spanM-add (uncurry (Chi-span Γ pi (SomeType tp') t checking) (check-for-type-mismatch Γ "asserted" tp'' tp'))
check-termi (Chi pi NoType t) (just tp) =
check-term t nothing ≫=span cont
where cont : (m : maybe type) → spanM ⊤
cont nothing = get-ctxt (λ Γ → spanM-add (Chi-span Γ pi NoType t checking [] nothing) ≫span spanMok)
cont (just tp') =
get-ctxt λ Γ →
spanM-add (uncurry (Chi-span Γ pi NoType t checking) (check-for-type-mismatch Γ "synthesized" tp tp'))
check-termi (Chi pi NoType t) nothing =
get-ctxt λ Γ → spanM-add (Chi-span Γ pi NoType t synthesizing [] nothing) ≫span check-term t nothing
check-termi (Delta pi mT t) mtp =
check-term t nothing ≫=span λ T →
get-ctxt λ Γ →
spanM-add (Delta-span Γ pi mT t (maybe-to-checking mtp) [] (maybe-hnf Γ T ≫=maybe check-contra Γ)) ≫span
(case mT of λ where
NoType → spanMr compileFailType
(SomeType T) → check-type T (just (Star posinfo-gen)) ≫span spanMr T) ≫=span λ T →
return-when mtp (just (qualif-type Γ T))
where check-contra : ctxt → type → err-m
check-contra Γ (TpEq _ t1 t2 _) =
if check-beta-inequiv (hnf Γ unfold-head t1 tt) (hnf Γ unfold-head t2 tt)
then nothing
else just "We could not find a contradiction in the synthesized type of the subterm."
check-contra _ _ = just "We could not synthesize an equation from the subterm."
check-termi (Theta pi u t ls) nothing =
get-ctxt λ Γ →
spanM-add (Theta-span Γ pi u t ls synthesizing []
(just "Theta-terms can only be used in checking positions (and this is a synthesizing one)."))
≫span spanMr nothing
check-termi (Theta pi AbstractEq t ls) (just tp) =
-- discard spans from checking t, because we will check it again below
check-term t nothing ≫=spand λ mtp → get-ctxt λ Γ → cont (maybe-hnf Γ mtp) (hnf Γ unfold-head tp tt)
where cont : maybe type → type → spanM ⊤
cont nothing tp = check-term t nothing ≫=span λ m →
get-ctxt λ Γ →
spanM-add (Theta-span Γ pi AbstractEq t ls checking [ expected-type Γ tp ] (just "We could not compute a motive from the given term"))
-- (expected-type Γ tp :: [ motive-label , [[ "We could not compute a motive from the given term" ]] , [] ]))))
cont (just htp) tp =
get-ctxt λ Γ →
let x = (fresh-var "x" (ctxt-binds-var Γ) empty-renamectxt) in
let motive = mtplam x (Tkt htp) (TpArrow (TpEq posinfo-gen t (mvar x) posinfo-gen) Erased tp) in
spanM-add (Theta-span Γ pi AbstractEq t ls checking (expected-type Γ tp :: [ the-motive Γ motive ]) nothing) ≫span
check-term (lterms-to-term AbstractEq (AppTp t (NoSpans motive (posinfo-plus (term-end-pos t) 1))) ls)
(just tp)
check-termi (Theta pi Abstract t ls) (just tp) =
-- discard spans from checking the head, because we will check it again below
check-term t nothing ≫=spand λ mtp → get-ctxt λ Γ → cont t (maybe-hnf Γ mtp) (hnf Γ unfold-head tp tt)
where cont : term → maybe type → type → spanM ⊤
cont _ nothing tp = check-term t nothing ≫=span λ m →
get-ctxt λ Γ →
spanM-add (Theta-span Γ pi Abstract t ls checking [ expected-type Γ tp ] (just "We could not compute a motive from the given term"))
-- (expected-type Γ tp :: [ motive-label , [[ "We could not compute a motive from the given term" ]] , [] ]))))
cont t (just htp) tp =
get-ctxt λ Γ →
let x = compute-var (hnf Γ unfold-head (qualif-term Γ t) tt)
x' = maybe-else (unqual-local x) id (var-suffix x) in
let motive = mtplam x' (Tkt htp) (rename-var Γ x x' tp) in
spanM-add (Theta-span Γ pi Abstract t ls checking (expected-type Γ tp :: [ the-motive Γ motive ]) nothing) ≫span
check-term (lterms-to-term Abstract (AppTp t (NoSpans motive (term-end-pos t))) ls)
(just tp)
where compute-var : term → var
compute-var (Var pi' x) = x
compute-var t = ignored-var
check-termi (Theta pi (AbstractVars vs) t ls) (just tp) =
get-ctxt λ Γ → let tp = hnf Γ unfold-head tp tt in cont (wrap-vars Γ vs tp {-(substs-type empty-ctxt (rep-vars Γ vs empty-trie) tp)-}) tp
where wrap-var : ctxt → var → type → maybe type
wrap-var Γ v tp = ctxt-lookup-tk-var Γ v ≫=maybe λ atk → just (mtplam v atk (rename-var Γ (qualif-var Γ v) v tp))
wrap-vars : ctxt → vars → type → maybe type
wrap-vars Γ (VarsStart v) tp = wrap-var Γ v tp
wrap-vars Γ (VarsNext v vs) tp = wrap-vars Γ vs tp ≫=maybe wrap-var Γ v
cont : maybe type → type → spanM ⊤
cont nothing tp = check-term t nothing ≫=span λ m →
get-ctxt λ Γ →
spanM-add (Theta-span Γ pi (AbstractVars vs) t ls checking
[ expected-type Γ tp ] (just ("We could not compute a motive from the given term"
^ " because one of the abstracted vars is not in scope.")))
cont (just motive) tp =
get-ctxt λ Γ →
spanM-add (Theta-span Γ pi (AbstractVars vs) t ls checking (expected-type Γ tp :: [ the-motive Γ motive ]) nothing) ≫span
check-term (lterms-to-term Abstract (AppTp t (NoSpans motive (posinfo-plus (term-end-pos t) 1))) ls)
(just tp)
{-rep-var : ctxt → var → trie term → trie term
rep-var Γ v ρ with trie-lookup (ctxt-get-qualif Γ) v
...| nothing = ρ
...| just (v' , _) = trie-insert ρ v' (Var posinfo-gen v)
rep-vars : ctxt → vars → trie term → trie term
rep-vars Γ (VarsStart v) = rep-var Γ v
rep-vars Γ (VarsNext v vs) ρ = rep-vars Γ vs (rep-var Γ v ρ)-}
check-termi (Hole pi) tp =
get-ctxt λ Γ → spanM-add (hole-span Γ pi tp []) ≫span return-when tp tp
check-termi (IotaPair pi t1 t2 og pi') (just tp) = -- (Iota pi1 pi2 x tp1 tp2)) =
get-ctxt λ Γ → case hnf Γ unfold-head tp tt of λ where
(Iota pi1 pi2 x tp1 tp2) →
check-term t1 (just tp1) ≫span
let t1' = qualif-term Γ t1
t2' = qualif-term Γ t2 in
check-term t2 (just (subst Γ t1' x tp2)) ≫span
optGuide-spans og checking ≫span
check-optGuide og tp1 tp2 pi2 x ≫=span λ e →
let cc = check-conv Γ t1' t2' e in
spanM-add (IotaPair-span pi pi' checking (expected-type Γ (Iota pi1 pi2 x tp1 tp2) :: snd cc) (fst cc))
tp → spanM-add (IotaPair-span pi pi' checking [ expected-type Γ tp ]
(just "The type we are checking against is not a iota-type"))
where ntag : ctxt → string → string → term → unfolding → tagged-val
ntag Γ nkind which t u = to-string-tag (nkind ^ " of the " ^ which ^ " component: ") Γ (hnf Γ u t tt)
err : ctxt → string → term → tagged-val
err Γ which t = ntag Γ "Hnf" which t unfold-head
check-conv : ctxt → term → term → err-m → err-m × 𝕃 tagged-val
check-conv Γ t1 t2 e = if conv-term Γ t1 t2
then e , []
else just "The two components of the iota-pair are not convertible (as required)." ,
err Γ "first" t1 :: [ err Γ "second" t2 ]
check-optGuide : optGuide → type → type → posinfo → var → spanM err-m
check-optGuide NoGuide tp1 tp2 pi2 x = spanMr nothing
check-optGuide (Guide pi x' tp) tp1 tp2 pi2 x = get-ctxt λ Γ → with-ctxt (ctxt-term-decl pi x' tp1 Γ) (check-type tp (just (Star posinfo-gen))) ≫span
spanMr (if conv-type Γ tp2 (qualif-type (ctxt-var-decl x Γ) (subst Γ (Var pi2 x) x' tp))
then nothing
else just "The expected type does not match the guided type")
check-termi (IotaPair pi t1 t2 (Guide pi' x T2) pi'') nothing =
get-ctxt λ Γ →
check-term t1 nothing ≫=span λ T1 →
check-term t2 (just (qualif-type Γ (subst Γ (qualif-term Γ t1) x T2))) ≫span
maybe-else spanMok (λ T1 → with-ctxt (ctxt-term-decl pi' x T1 Γ) (check-type T2 (just (Star posinfo-gen)))) T1 ≫span
let T2' = qualif-type (ctxt-var-decl x Γ) T2 in
spanM-add (IotaPair-span pi pi'' synthesizing (maybe-else [] (λ T1 → [ type-data Γ (Iota posinfo-gen posinfo-gen x T1 T2') ]) T1) nothing) ≫span
spanM-add (Var-span (ctxt-var-decl-loc pi' x Γ) pi' x synthesizing [] nothing) ≫span
spanMr (T1 ≫=maybe λ T1 → just (Iota posinfo-gen posinfo-gen x T1 T2'))
where
err : ctxt → err-m × 𝕃 tagged-val
err Γ = if conv-term Γ t1 t2
then nothing , []
else just "The two components of the iota-pair are not convertible (as required)." ,
to-string-tag "Hnf of the first component" Γ (hnf Γ unfold-head t1 tt) ::
[ to-string-tag "Hnf of the second component" Γ (hnf Γ unfold-head t2 tt) ]
check-termi (IotaPair pi t1 t2 NoGuide pi') nothing =
spanM-add (IotaPair-span pi pi' synthesizing [] (just "Iota pairs require a specified type when in a synthesizing position")) ≫span
spanMr nothing
check-termi (IotaProj t n pi) mtp =
check-term t nothing ≫=span λ mtp' → get-ctxt λ Γ → cont' mtp (posinfo-to-ℕ n) (maybe-hnf Γ mtp')
where cont : (outer : maybe type) → ℕ → (computed : type) → spanM (check-ret outer)
cont mtp n computed with computed
cont mtp 1 computed | Iota pi' pi'' x t1 t2 =
get-ctxt λ Γ →
spanM-add (uncurry (λ tvs → IotaProj-span t pi (maybe-to-checking mtp) (head-type Γ computed :: tvs))
(check-for-type-mismatch-if Γ "synthesized" mtp t1)) ≫span
return-when mtp (just t1)
cont mtp 2 computed | Iota pi' pi'' x a t2 =
get-ctxt λ Γ →
let t2' = subst Γ (qualif-term Γ t) x t2 in
spanM-add (uncurry (λ tvs → IotaProj-span t pi (maybe-to-checking mtp)
(head-type Γ computed :: tvs)) (check-for-type-mismatch-if Γ "synthesized" mtp t2')) ≫span
return-when mtp (just t2')
cont mtp n computed | Iota pi' pi'' x t1 t2 =
get-ctxt λ Γ →
spanM-add (IotaProj-span t pi (maybe-to-checking mtp) [ head-type Γ computed ] (just "Iota-projections must use .1 or .2 only.")) ≫span return-when mtp mtp
cont mtp n computed | _ =
get-ctxt λ Γ →
spanM-add (IotaProj-span t pi (maybe-to-checking mtp) [ head-type Γ computed ] (just "The head type is not a iota-abstraction.")) ≫span return-when mtp mtp
cont' : (outer : maybe type) → ℕ → (computed : maybe type) → spanM (check-ret outer)
cont' mtp _ nothing = spanM-add (IotaProj-span t pi (maybe-to-checking mtp) [] nothing) ≫span return-when mtp mtp
cont' mtp n (just tp) = get-ctxt λ Γ → cont mtp n (hnf Γ unfold-head tp tt)
-- we are looking for iotas in the bodies of rec defs
check-termi mu@(Mu' pi t (SomeType P) pi' cs pi'') nothing =
check-term t nothing on-fail (spanMr nothing) ≫=spanm' (λ I →
spanM-add (Mu'-span mu [] nothing) ≫span
spanMr (just I)
)
check-termi mu@(Mu' pi t (SomeType P) pi' cs pi'') (just tp) =
check-term t nothing on-fail spanMok ≫=spanm' (λ I →
-- TODO: remove T parameters and s indices from expression I T s
get-ctxt (helper I))
where
helper : type → ctxt → spanM ⊤
helper (TpVar _ x) (mk-ctxt _ _ _ _ d) with trie-lookup d x
... | just dt = well-formed-patterns dt t P cs pi' pi''
... | nothing = spanMok
helper _ Γ = spanMok
check-termi (Mu' pi t NoType _ cs pi') (just tp) = spanMok
check-termi (Mu' pi t NoType _ cs pi') nothing = spanMr nothing
check-termi (Mu pi x t (SomeType m) _ cs pi') (just tp) = spanMok
check-termi (Mu pi x t (SomeType m) _ cs pi') nothing = spanMr nothing
check-termi (Mu pi x t NoType _ cs pi') nothing = spanMr nothing
check-termi (Mu pi x t NoType _ cs pi') (just tp) = spanMok
{-check-termi t tp = get-ctxt (λ Γ → spanM-add (unimplemented-term-span Γ (term-start-pos t) (term-end-pos t) tp) ≫span unimplemented-if tp)-}
-- END check-term
-- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-- check-term-spine
-- ==================================================
-- check-term-spine is where metavariables are generated and solved, so it
-- requires its set of helpers
check-term-spine-return : ctxt → meta-vars → decortype → ℕ → spanM (maybe spine-data)
check-term-spine-return Γ Xs dt locl = spanMr (just (mk-spine-data Xs dt locl))
-- a flag indicating how aggresively we should be unfolding during matching.
-- "both" is the backtracking flag. We will attempt "both" matches, which means
-- first matching without unfolding, then if that fails unfolding the type once
-- and continue matching the subexpresions with "both"
data match-unfolding-state : Set where
match-unfolding-both match-unfolding-approx match-unfolding-hnf : match-unfolding-state
-- main matching definitions
-- --------------------------------------------------
-- NOTE: these functions don't actually ever emit spans
match-types : meta-vars → local-vars → match-unfolding-state → (tpₓ tp : type) → spanM $ match-error-t meta-vars
match-kinds : meta-vars → local-vars → match-unfolding-state → (kₓ k : kind) → spanM $ match-error-t meta-vars
match-tks : meta-vars → local-vars → match-unfolding-state → (tkₓ tk : tk) → spanM $ match-error-t meta-vars
record match-prototype-data : Set where
constructor mk-match-prototype-data
field
match-proto-mvars : meta-vars
match-proto-dectp : decortype
match-proto-error : 𝔹
open match-prototype-data
match-prototype : (Xs : meta-vars) (is-hnf : 𝔹) (tp : type) (pt : prototype) → spanM $ match-prototype-data
-- substitutions used during matching
-- --------------------------------------------------
-- These have to be in the spanM monad because substitution can unlock a `stuck`
-- decoration, causing another round of prototype matching (which invokes type matching)
substh-decortype : {ed : exprd} → ctxt → renamectxt → trie ⟦ ed ⟧ → decortype → spanM $ decortype
substh-decortype Γ ρ σ (decor-type tp) = spanMr $ decor-type (substh-type Γ ρ σ tp)
substh-decortype Γ ρ σ (decor-arrow e? dom cod) =
substh-decortype Γ ρ σ cod
≫=span λ cod → spanMr $ decor-arrow e? (substh-type Γ ρ σ dom) cod
-- spanMr $ decor-arrow e? (substh-type Γ ρ σ dom) (substh-decortype Γ ρ σ cod)
substh-decortype Γ ρ σ (decor-decor e? pi x sol dt) =
let x' = subst-rename-var-if Γ ρ x σ
Γ' = ctxt-var-decl-loc pi x' Γ
ρ' = renamectxt-insert ρ x x'
in substh-decortype Γ' ρ' σ dt
≫=span λ dt' → spanMr $ decor-decor e? pi x' (substh-meta-var-sort Γ ρ σ sol) dt'
-- decor-decor e? x' (substh-meta-var-sol Γ' ρ' σ sol) (substh-decortype Γ' ρ' σ dt)
substh-decortype Γ ρ σ (decor-stuck tp pt) =
match-prototype meta-vars-empty ff (substh-type Γ ρ σ tp) pt
-- NOTE: its an invariant that if you start with no meta-variables, prototype matching
-- produces no meta-variables as output
≫=span λ ret → spanMr (match-proto-dectp ret)
substh-decortype Γ ρ σ (decor-error tp pt) =
spanMr $ decor-error (substh-type Γ ρ σ tp) pt
subst-decortype : {ed : exprd} → ctxt → ⟦ ed ⟧ → var → decortype → spanM $ decortype
subst-decortype Γ s x dt = substh-decortype Γ empty-renamectxt (trie-single x s) dt
meta-vars-subst-decortype' : (unfold : 𝔹) → ctxt → meta-vars → decortype → spanM decortype
meta-vars-subst-decortype' uf Γ Xs dt =
substh-decortype Γ empty-renamectxt (meta-vars-get-sub Xs) dt
≫=span λ dt' → spanMr $
if uf then hnf-decortype Γ (unfolding-elab unfold-head) dt' tt else dt'
meta-vars-subst-decortype : ctxt → meta-vars → decortype → spanM decortype
meta-vars-subst-decortype = meta-vars-subst-decortype' tt
-- unfolding a decorated type to reveal a term / type abstraction
-- --------------------------------------------------
{-# TERMINATING #-}
meta-vars-peel' : ctxt → span-location → meta-vars → decortype → spanM $ (𝕃 meta-var) × decortype
meta-vars-peel' Γ sl Xs (decor-decor e? pi x (meta-var-tp k mtp) dt) =
let Y = meta-var-fresh-tp Xs x sl (k , mtp)
Xs' = meta-vars-add Xs Y
in subst-decortype Γ (meta-var-to-type-unsafe Y) x dt
≫=span λ dt' → meta-vars-peel' Γ sl Xs' dt'
≫=span λ ret → let Ys = fst ret ; rdt = snd ret
in spanMr $ Y :: Ys , rdt
meta-vars-peel' Γ sl Xs dt@(decor-decor e? pi x (meta-var-tm _ _) _) = spanMr $ [] , dt
meta-vars-peel' Γ sl Xs dt@(decor-arrow _ _ _) = spanMr $ [] , dt
-- NOTE: vv The clause below will later generate a type error vv
meta-vars-peel' Γ sl Xs dt@(decor-stuck _ _) = spanMr $ [] , dt
-- NOTE: vv The clause below is an internal error, if reached vv
meta-vars-peel' Γ sl Xs dt@(decor-type _) = spanMr $ [] , dt
meta-vars-peel' Γ sl Xs dt@(decor-error _ _) = spanMr $ [] , dt
meta-vars-unfold-tmapp' : ctxt → span-location → meta-vars → decortype → spanM $ (𝕃 meta-var × is-tmabsd?)
meta-vars-unfold-tmapp' Γ sl Xs dt =
meta-vars-subst-decortype Γ Xs dt
≫=span λ dt' → meta-vars-peel' Γ sl Xs dt'
≫=span λ where
(Ys , dt'@(decor-arrow e? dom cod)) →
spanMr $ Ys , yes-tmabsd dt' e? "_" dom ff cod
(Ys , dt'@(decor-decor e? pi x (meta-var-tm dom _) cod)) →
spanMr $ Ys , yes-tmabsd dt' e? x dom (is-free-in check-erased x (decortype-to-type cod)) cod
(Ys , dt@(decor-decor _ _ _ (meta-var-tp _ _) _)) →
spanMr $ Ys , not-tmabsd dt
-- NOTE: vv this is a type error vv
(Ys , dt@(decor-stuck _ _)) →
spanMr $ Ys , not-tmabsd dt
-- NOTE: vv this is an internal error, if reached vv
(Ys , dt@(decor-type _)) →
spanMr $ Ys , not-tmabsd dt
(Ys , dt@(decor-error _ _)) →
spanMr $ Ys , not-tmabsd dt
meta-vars-unfold-tpapp' : ctxt → meta-vars → decortype → spanM is-tpabsd?
meta-vars-unfold-tpapp' Γ Xs dt =
meta-vars-subst-decortype Γ Xs dt
≫=span λ where
(dt″@(decor-decor e? pi x (meta-var-tp k mtp) dt')) →
spanMr $ yes-tpabsd dt″ e? x k (flip maybe-map mtp meta-var-sol.sol) dt'
(dt″@(decor-decor _ _ _ (meta-var-tm _ _) _)) →
spanMr $ not-tpabsd dt″
(dt″@(decor-arrow _ _ _)) → spanMr $ not-tpabsd dt″
(dt″@(decor-stuck _ _)) → spanMr $ not-tpabsd dt″
(dt″@(decor-type _)) → spanMr $ not-tpabsd dt″
(dt″@(decor-error _ _)) → spanMr $ not-tpabsd dt″
-- errors
-- --------------------------------------------------
-- general type errors for applications
module check-term-app-tm-errors
{A : Set} (t₁ t₂ : term) (htp : type) (Xs : meta-vars) (is-locale : 𝔹) (m : checking-mode)
where
inapplicable : maybeErased → decortype → prototype → spanM (maybe A)
inapplicable e? dt pt =
get-ctxt λ Γ → spanM-add
(App-span is-locale t₁ t₂ m
(head-type Γ (meta-vars-subst-type Γ Xs htp)
-- :: decortype-data Γ dt
-- :: prototype-data Γ pt
:: meta-vars-data-all Γ Xs)
(just $ "The type of the head does not allow the head to be applied to "
^ h e? ^ " argument"))
≫span spanMr nothing
where h : maybeErased → string
h Erased = "an erased term"
h NotErased = "a term"
bad-erasure : maybeErased → spanM (maybe A)
bad-erasure e? =
get-ctxt λ Γ → spanM-add
(App-span is-locale t₁ t₂ m
(head-type Γ (meta-vars-subst-type Γ Xs htp) :: meta-vars-data-all Γ Xs)
(just (msg e?)))
≫span spanMr nothing
where
msg : maybeErased → string
msg Erased =
"The type computed for the head requires an explicit (non-erased) argument,"
^ " but the application is marked as erased"
msg NotErased =
"The type computed for the head requires an implicit (erased) argument,"
^ " but the application is marked as not erased"
unmatchable : (tpₓ tp : type) (msg : string) → 𝕃 tagged-val → spanM (maybe A)
unmatchable tpₓ tp msg tvs =
get-ctxt λ Γ → spanM-add
(App-span is-locale t₁ t₂ m
(arg-exp-type Γ tpₓ :: arg-type Γ tp :: tvs ++ meta-vars-data-all Γ Xs)
(just msg))
≫span spanMr nothing
unsolved-meta-vars : type → 𝕃 tagged-val → spanM (maybe A)
unsolved-meta-vars tp tvs =
get-ctxt λ Γ → spanM-add
(App-span tt t₁ t₂ m
(type-data Γ tp :: meta-vars-data-all Γ Xs ++ tvs)
(just "There are unsolved meta-variables in this maximal application"))
≫span spanMr nothing
module check-term-app-tp-errors
{A : Set} (t : term) (tp htp : type) (Xs : meta-vars) (m : checking-mode)
where
inapplicable : decortype → spanM (maybe A)
inapplicable dt =
get-ctxt λ Γ → spanM-add
(AppTp-span t tp synthesizing
(head-type Γ (meta-vars-subst-type Γ Xs htp)
-- :: decortype-data Γ dt
:: meta-vars-data-all Γ Xs)
(just "The type of the head does not allow the head to be applied to a type argument"))
≫span spanMr nothing
ctai-disagree : (ctai-sol : type) → spanM $ maybe A
ctai-disagree ctai-sol =
get-ctxt λ Γ → spanM-add (AppTp-span t tp m
(head-type Γ (meta-vars-subst-type Γ Xs htp)
:: contextual-type-argument Γ ctai-sol
:: meta-vars-data-all Γ Xs)
(just "The given and contextually inferred type argument differ"))
≫span spanMr nothing
-- meta-variable locality
-- --------------------------------------------------
-- for debugging -- prepend to the tvs returned by check-spine-locality if you're having trouble
private
locale-tag : ℕ → tagged-val
locale-tag n = "locale n" , [[ ℕ-to-string n ]] , []
private
is-locale : (max : 𝔹) → (locl : maybe ℕ) → 𝔹
is-locale max locl = max || maybe-else' locl ff iszero
check-spine-locality : ctxt → meta-vars → type → (max : 𝔹) → (locl : ℕ)
→ spanM (maybe (meta-vars × ℕ × 𝔹))
check-spine-locality Γ Xs tp max locl =
let new-locl = if iszero locl then num-arrows-in-type Γ tp else locl
new-Xs = if iszero locl then meta-vars-empty else Xs
left-locl = is-locale max (just locl)
in if left-locl && (~ meta-vars-solved? Xs)
then spanMr nothing
else spanMr (just (new-Xs , new-locl , left-locl))
-- main definition
--------------------------------------------------
data check-term-app-ret : Set where
check-term-app-return : (Xs : meta-vars) (cod : decortype) (arg-mode : checking-mode) → (tvs : 𝕃 tagged-val) → check-term-app-ret
check-term-app : (Xs : meta-vars) (Ys : 𝕃 meta-var) → (t₁ t₂ : term) → is-tmabsd → 𝔹 → spanM (maybe check-term-app-ret)
check-term-spine t'@(App t₁ e? t₂) pt max =
-- 1) type the applicand, extending the prototype
let pt' = proto-arrow e? pt in
check-term-spine t₁ pt' ff
on-fail handleApplicandTypeError
-- 2) make sure the applicand type reveals an arrow (term abstraction)
≫=spanm' λ ret → let (mk-spine-data Xs dt locl) = ret in
-- the meta-vars need to know the span they were introduced in
get-ctxt λ Γ → let sloc = span-loc $ ctxt-get-current-filename Γ in
-- see if the decorated type of the head `dt` reveals an arrow
meta-vars-unfold-tmapp' Γ sloc Xs dt
≫=span λ ret → let Ys = fst ret ; tm-arrow? = snd ret in
spanMr tm-arrow? on-fail (λ _ → genInapplicableError Xs dt pt' locl)
-- if so, get the (plain, undecorated) type of the head `htp`
≫=spans' λ arr → let htp = decortype-to-type ∘ is-tmabsd-dt $ arr in
-- 3) make sure erasures of the applicand type + syntax of application match
checkErasuresMatch e? (is-tmabsd-e? arr) htp Xs locl
-- 4) type the application, filling in missing type arguments with meta-variables
≫=spanm' λ _ → check-term-app Xs Ys t₁ t₂ arr (islocl locl)
-- 5) check no unsolved mvars, if the application is maximal (or a locality)
≫=spanm' λ {(check-term-app-return Xs' rtp' arg-mode tvs) →
let rtp = decortype-to-type rtp' in
checkLocality Γ Xs' htp rtp max (pred locl) tvs
≫=spanm' uncurry₂ λ Xs'' locl' is-loc →
-- 6) generate span and finish
genAppSpan Γ Xs Xs' Ys pt rtp is-loc tvs
≫span check-term-spine-return Γ Xs'' rtp' locl'
}
where
mode = prototype-to-checking pt
span-loc : (fn : string) → span-location
span-loc fn = fn , term-start-pos t₁ , term-end-pos t₂
islocl : ℕ → 𝔹
islocl locl = is-locale max (just $ pred locl)
handleApplicandTypeError : spanM ∘ maybe $ _
handleApplicandTypeError =
spanM-add (App-span max t₁ t₂ mode [] nothing)
≫span check-term t₂ nothing
≫=span (const $ spanMr nothing)
genInapplicableError : meta-vars → decortype → prototype → (locl : ℕ) → spanM (maybe _)
genInapplicableError Xs dt pt locl =
check-term-app-tm-errors.inapplicable
t₁ t₂ (decortype-to-type dt) Xs (islocl locl) mode e? dt (proto-arrow e? pt)
checkErasuresMatch : (e?₁ e?₂ : maybeErased) → type → meta-vars → (locl : ℕ) → spanM ∘ maybe $ ⊤
checkErasuresMatch e?₁ e?₂ htp Xs locl =
if ~ eq-maybeErased e?₁ e?₂
then check-term-app-tm-errors.bad-erasure t₁ t₂ htp Xs (islocl locl) mode e?₁
else (spanMr ∘ just $ triv)
checkLocality : ctxt → meta-vars → (htp rtp : type) → (max : 𝔹) (locl : ℕ) → 𝕃 tagged-val → spanM ∘ maybe $ _
checkLocality Γ Xs htp rtp max locl tvs =
check-spine-locality Γ Xs rtp max locl
on-fail check-term-app-tm-errors.unsolved-meta-vars
t₁ t₂ htp Xs (islocl locl) mode rtp tvs
≫=spanm' (spanMr ∘ just)
genAppSpan : ctxt → (Xs Xs' : meta-vars) → (Ys : 𝕃 meta-var) → prototype → type → (is-locl : 𝔹) → 𝕃 tagged-val → spanM ⊤
genAppSpan Γ Xs Xs' Ys pt rtp is-loc tvs =
spanM-add $ (flip uncurry)
(meta-vars-check-type-mismatch-if (prototype-to-maybe pt) Γ "synthesized" meta-vars-empty rtp)
λ tvs' → App-span is-loc t₁ t₂ mode
(tvs' ++ meta-vars-intro-data Γ (meta-vars-from-list Ys)
++ meta-vars-sol-data Γ Xs Xs' ++ tvs)
check-term-spine t'@(AppTp t tp) pt max = get-ctxt λ Γ →
-- 1) type the applicand
check-term-spine t pt max
on-fail handleApplicandTypeError
≫=spanm' λ ret → let (mk-spine-data Xs dt locl) = ret ; htp = decortype-to-type dt in
-- 2) make sure it reveals a type abstraction
meta-vars-unfold-tpapp' Γ Xs dt
on-fail (λ _ → genInapplicableError Xs htp dt)
-- 3) ensure the type argument has the expected kind,
-- but don't compare with the contextually infered type argument (for now)
≫=spans' λ ret → let mk-tpabsd dt e? x k sol rdt = ret in
check-type tp (just (meta-vars-subst-kind Γ Xs k))
-- 4) produce the result type of the application
≫span subst-decortype-if Γ Xs x k sol rdt
≫=span λ ret → let Xs = fst ret ; rdt = snd ret ; rtp = decortype-to-type rdt in
-- 5) generate span data and finish
genAppTpSpan Γ Xs pt rtp
≫span check-term-spine-return Γ Xs rdt locl
where
mode = prototype-to-checking pt
span-loc : ctxt → span-location
span-loc Γ = (ctxt-get-current-filename Γ) , term-start-pos t , type-end-pos tp
handleApplicandTypeError : spanM ∘ maybe $ spine-data
handleApplicandTypeError =
spanM-add (AppTp-span t tp synthesizing [] nothing)
≫span check-type tp nothing
≫=span (const $ spanMr nothing)
genInapplicableError : meta-vars → type → decortype → spanM ∘ maybe $ spine-data
genInapplicableError Xs htp dt =
check-term-app-tp-errors.inapplicable t tp htp Xs mode dt
subst-decortype-if : ctxt → meta-vars → var → kind → maybe type → decortype → spanM (meta-vars × decortype)
subst-decortype-if Γ Xs x k sol rdt =
if ~ is-hole tp
then subst-decortype Γ (qualif-type Γ tp) x rdt ≫=span (λ res → spanMr (Xs , res))
else let sol = maybe-map (λ t → mk-meta-var-sol t checking) sol
Y = meta-var-fresh-tp Xs x (span-loc Γ) (k , sol)
Xs' = meta-vars-add Xs Y
in subst-decortype Γ (meta-var-to-type-unsafe Y) x rdt ≫=span λ rdt' → spanMr (Xs' , rdt')
genAppTpSpan : ctxt → meta-vars → prototype → (ret-tp : type) → spanM ⊤
genAppTpSpan Γ Xs pt ret-tp = spanM-add ∘ (flip uncurry)
-- check for a type mismatch, if there even is an expected type
(meta-vars-check-type-mismatch-if (prototype-to-maybe pt) Γ "synthesizing" Xs ret-tp) $
-- then take the generated 𝕃 tagged-val and add to the span
λ tvs → AppTp-span t tp mode $ tvs ++ meta-vars-data-all Γ Xs -- ++ (prototype-data Γ tp :: [ decortype-data Γ dt ])
check-term-spine (Parens _ t _) pt max =
check-term-spine t pt max
check-term-spine t pt max =
check-term t nothing
≫=spanm' λ htp → get-ctxt λ Γ →
let locl = num-arrows-in-type Γ htp
in match-prototype meta-vars-empty ff htp pt
-- NOTE: it is an invariant that the variables solved in the
-- solution set of the fst of this are a subset of the variables given
-- to match-* -- that is, for (σ , W) = match-prototype ...
-- we have dom(σ) = ∅
≫=span λ ret → let dt = match-proto-dectp ret in
check-term-spine-return Γ meta-vars-empty dt locl
-- check-term-app
-- --------------------------------------------------
--
-- If `dom` has unsolved meta-vars in it, synthesize argument t₂ and try to solve for them.
-- Otherwise, check t₂ against a fully known expected type
check-term-app Xs Zs t₁ t₂ (mk-tmabsd dt e? x dom occurs cod) is-locl =
get-ctxt λ Γ → let Xs' = meta-vars-add* Xs Zs ; tp = decortype-to-type dt in
-- 1) calculate return type of function (possible subst)
genAppRetType Γ
-- 2) either synth or check arg type, depending on available info
-- checking "exits early", as well as failure
≫=span λ rdt → checkArgWithMetas Xs' tp rdt
exit-early spanMr
-- 3) match *synthesized* type with expected (partial) type
≫=spans' λ atp → match-types Xs' empty-trie match-unfolding-both dom atp
≫=span (handleMatchResult Xs' atp tp rdt)
where
mode = synthesizing
genAppRetType : ctxt → spanM decortype
genAppRetType Γ = if occurs then subst-decortype Γ (qualif-term Γ t₂) x cod else spanMr cod
genAppRetTypeHole : ctxt → spanM decortype
genAppRetTypeHole Γ = if occurs then subst-decortype Γ (Hole posinfo-gen) x cod else spanMr cod
checkArgWithMetas : meta-vars → type → decortype → spanM $ (maybe check-term-app-ret ∨ type)
checkArgWithMetas Xs' tp rdt = get-ctxt λ Γ →
-- check arg against fully known type
if ~ meta-vars-are-free-in-type Xs' dom
then check-term t₂ (just dom)
≫span (spanMr ∘' inj₁ ∘' just $ check-term-app-return Xs' rdt mode [])
-- synthesize type for the argument
else check-term t₂ nothing
-- if that doesn't work, press on -- feeding a hole for the dependency, if needed
on-fail (genAppRetTypeHole Γ
≫=span λ rdt-hole → spanMr ∘' inj₁ ∘' just $
check-term-app-return Xs' rdt-hole mode [ arg-exp-type Γ dom ])
≫=spanm' λ tp → spanMr ∘' inj₂ $ tp
handleMatchResult : meta-vars → (atp tp : type) → decortype → match-error-t meta-vars → spanM ∘ maybe $ check-term-app-ret
handleMatchResult Xs' atp tp rdt (match-error (msg , tvs)) =
check-term-app-tm-errors.unmatchable
t₁ t₂ tp Xs' is-locl mode dom atp msg tvs
handleMatchResult Xs' atp tp rdt (match-ok Xs) = get-ctxt λ Γ →
meta-vars-subst-decortype Γ Xs rdt
≫=span λ rdt → spanMr ∘ just $ check-term-app-return Xs rdt mode []
match-unfolding-next : match-unfolding-state → match-unfolding-state
match-unfolding-next match-unfolding-both = match-unfolding-both
match-unfolding-next match-unfolding-approx = match-unfolding-approx
match-unfolding-next match-unfolding-hnf = match-unfolding-both
module m-err = meta-vars-match-errors
check-type-for-match : type → spanM $ match-error-t kind
check-type-for-match tp =
(with-qualified-qualif $ with-clear-error $ get-ctxt λ Γ →
check-type tp nothing
on-fail spanMr ∘ match-error $ "Could not kind computed arg type" , []
≫=spanm' λ k → spanMr ∘ match-ok $ k)
≫=spand spanMr
where
qualified-qualif : ctxt → qualif
qualified-qualif (mk-ctxt mod ss is os _) =
for trie-strings is accum empty-trie use λ x q →
trie-insert q x (x , ArgsNil)
-- helper to restore qualif state
with-qualified-qualif : ∀ {A} → spanM A → spanM A
with-qualified-qualif sm =
get-ctxt λ Γ →
with-ctxt (ctxt-set-qualif Γ (qualified-qualif Γ))
sm
-- helper to restore error state
with-clear-error : ∀ {A} → spanM A → spanM A
with-clear-error m =
get-error λ es → set-error nothing
≫span m
≫=span λ a → set-error es
≫span spanMr a
-- match-types
-- --------------------------------------------------
match-types-ok : meta-vars → spanM $ match-error-t meta-vars
match-types-ok = spanMr ∘ match-ok
match-types-error : match-error-data → spanM $ match-error-t meta-vars
match-types-error = spanMr ∘ match-error
match-types Xs Ls match-unfolding-both tpₓ tp =
get-ctxt λ Γ →
match-types Xs Ls match-unfolding-approx tpₓ tp
≫=span λ where
(match-ok Xs) → match-types-ok Xs
(match-error msg) →
match-types Xs Ls match-unfolding-hnf
(hnf Γ (unfolding-elab unfold-head) tpₓ tt)
(hnf Γ (unfolding-elab unfold-head) tp tt)
match-types Xs Ls unf tpₓ@(TpVar pi x) tp =
-- check that x is a meta-var
get-ctxt λ Γ →
maybe-else' (meta-vars-lookup-with-kind Xs x)
-- if not, make sure the two variables are the same
-- TODO: above assumes no term meta-variables
(spanMr (err⊎-guard (~ conv-type Γ tpₓ tp) m-err.e-match-failure
≫⊎ match-ok Xs))
-- scope check the solution
λ ret → let X = fst ret ; kₓ = snd ret in
if are-free-in-type check-erased Ls tp then
match-types-error $ m-err.e-meta-scope Γ tpₓ tp
else (check-type-for-match tp
≫=spans' λ k → match-kinds Xs empty-trie match-unfolding-both kₓ k
on-fail (λ _ → spanMr ∘ match-error $ m-err.e-bad-sol-kind Γ x tp)
≫=spans' λ Xs → spanMr (meta-vars-solve-tp Γ Xs x tp synthesizing)
≫=spans' λ Xs → match-types-ok $ meta-vars-update-kinds Γ Xs Xs)
match-types Xs Ls unf (TpApp tpₓ₁ tpₓ₂) (TpApp tp₁ tp₂) =
match-types Xs Ls unf tpₓ₁ tp₁
≫=spans' λ Xs' → match-types Xs' Ls (match-unfolding-next unf) tpₓ₂ tp₂
match-types Xs Ls unf (TpAppt tpₓ tmₓ) (TpAppt tp tm) =
match-types Xs Ls unf tpₓ tp
≫=spans' λ Xs' → get-ctxt λ Γ →
spanMr $ if ~ conv-term Γ tmₓ tm
then (match-error m-err.e-match-failure) else
match-ok Xs'
match-types Xs Ls unf tpₓ'@(Abs piₓ bₓ piₓ' xₓ tkₓ tpₓ) tp'@(Abs pi b pi' x tk tp) =
get-ctxt λ Γ →
if ~ eq-maybeErased bₓ b
then (match-types-error m-err.e-match-failure) else
( match-tks Xs Ls (match-unfolding-next unf) tkₓ tk
≫=spans' λ Xs' → with-ctxt (Γ→Γ' Γ)
(match-types Xs' Ls' (match-unfolding-next unf) tpₓ tp))
where
Γ→Γ' : ctxt → ctxt
Γ→Γ' Γ = ctxt-rename xₓ x (ctxt-var-decl-if x Γ)
Ls' = stringset-insert Ls x
match-types Xs Ls unf tpₓ@(TpArrow tp₁ₓ atₓ tp₂ₓ) tp@(TpArrow tp₁ at tp₂) =
get-ctxt λ Γ → if ~ eq-maybeErased atₓ at
then match-types-error m-err.e-match-failure else
( match-types Xs Ls (match-unfolding-next unf) tp₁ₓ tp₁
≫=spans' λ Xs → match-types Xs Ls (match-unfolding-next unf) tp₂ₓ tp₂)
match-types Xs Ls unf tpₓ@(TpArrow tp₁ₓ atₓ tp₂ₓ) tp@(Abs pi b pi' x (Tkt tp₁) tp₂) =
get-ctxt λ Γ → if ~ eq-maybeErased atₓ b
then match-types-error m-err.e-match-failure else
( match-types Xs Ls (match-unfolding-next unf) tp₁ₓ tp₁
≫=spans' λ Xs → match-types Xs (stringset-insert Ls x) (match-unfolding-next unf) tp₂ₓ tp₂)
match-types Xs Ls unf tpₓ@(Abs piₓ bₓ piₓ' xₓ (Tkt tp₁ₓ) tp₂ₓ) tp@(TpArrow tp₁ at tp₂) =
get-ctxt λ Γ → if ~ eq-maybeErased bₓ at
then match-types-error m-err.e-match-failure else
( match-types Xs Ls (match-unfolding-next unf) tp₁ₓ tp₁
≫=spans' λ Xs → match-types Xs (stringset-insert Ls xₓ) (match-unfolding-next unf) tp₂ₓ tp₂)
match-types Xs Ls unf (Iota _ piₓ xₓ mₓ tpₓ) (Iota _ pi x m tp) =
get-ctxt λ Γ → match-types Xs Ls (match-unfolding-next unf) mₓ m
≫=spans' λ Xs → with-ctxt (Γ→Γ' Γ)
(match-types Xs Ls' (match-unfolding-next unf) tpₓ tp)
where
Γ→Γ' : ctxt → ctxt
Γ→Γ' Γ = ctxt-rename xₓ x (ctxt-var-decl-if x Γ)
Ls' = stringset-insert Ls x
match-types Xs Ls unf (TpEq _ t₁ₓ t₂ₓ _) (TpEq _ t₁ t₂ _) =
get-ctxt λ Γ → if ~ conv-term Γ t₁ₓ t₁
then match-types-error $ m-err.e-match-failure else
if ~ conv-term Γ t₂ₓ t₂
then match-types-error $ m-err.e-match-failure else
match-types-ok Xs
match-types Xs Ls unf (Lft _ piₓ xₓ tₓ lₓ) (Lft _ pi x t l) =
get-ctxt λ Γ → if ~ conv-liftingType Γ lₓ l
then match-types-error $ m-err.e-match-failure else
if ~ conv-term (Γ→Γ' Γ) tₓ t
then match-types-error $ m-err.e-match-failure else
match-types-ok Xs
where
Γ→Γ' : ctxt → ctxt
Γ→Γ' Γ = ctxt-rename xₓ x (ctxt-var-decl-if x Γ)
match-types Xs Ls unf (TpLambda _ piₓ xₓ atkₓ tpₓ) (TpLambda _ pi x atk tp) =
get-ctxt λ Γ → match-tks Xs Ls (match-unfolding-next unf) atkₓ atk
≫=spans' λ Xs → with-ctxt (Γ→Γ' Γ)
(match-types Xs Ls' (match-unfolding-next unf) tpₓ tp)
where
Γ→Γ' : ctxt → ctxt
Γ→Γ' Γ = ctxt-rename xₓ x (ctxt-var-decl-if x Γ)
Ls' = stringset-insert Ls x
match-types Xs Ls unf (NoSpans tpₓ _) (NoSpans tp _) =
match-types Xs Ls unf tpₓ tp
-- TODO for now, don't approximate lets
match-types Xs Ls unf (TpLet piₓ (DefTerm pi x ot t) tpₓ) tp =
get-ctxt λ Γ → match-types Xs Ls unf (subst Γ (Chi posinfo-gen ot t) x tpₓ) tp
match-types Xs Ls unf (TpLet piₓ (DefType pi x k tpₓ-let) tpₓ) tp =
get-ctxt λ Γ → match-types Xs Ls unf (subst Γ tpₓ-let x tpₓ) tp
match-types Xs Ls unf tpₓ (TpLet _ (DefTerm _ x ot t) tp) =
get-ctxt λ Γ → match-types Xs Ls unf tpₓ (subst Γ (Chi posinfo-gen ot t) x tp)
match-types Xs Ls unf tpₓ (TpLet _ (DefType _ x k tp-let) tp) =
get-ctxt λ Γ → match-types Xs Ls unf tpₓ (subst Γ tp-let x tp)
-- match-types Xs Ls unf (TpHole x₁) tp = {!!}
match-types Xs Ls unf (TpParens _ tpₓ _) tp =
match-types Xs Ls unf tpₓ tp
match-types Xs Ls unf tpₓ (TpParens _ tp _) =
match-types Xs Ls unf tpₓ tp
match-types Xs Ls unf tpₓ tp =
get-ctxt λ Γ → match-types-error m-err.e-match-failure
-- match-kinds
-- --------------------------------------------------
-- match-kinds-norm: match already normalized kinds
match-kinds-norm : meta-vars → local-vars → match-unfolding-state → (kₓ k : kind) → spanM $ match-error-t meta-vars
match-kinds-norm Xs Ls uf (KndParens _ kₓ _) (KndParens _ k _) =
match-kinds Xs Ls uf kₓ k
-- kind pi
match-kinds-norm Xs Ls uf (KndPi _ piₓ xₓ tkₓ kₓ) (KndPi _ pi x tk k) =
get-ctxt λ Γ → match-tks Xs Ls uf tkₓ tk
≫=spans' λ Xs → with-ctxt (Γ→Γ' Γ)
(match-kinds Xs Ls uf kₓ k)
where
Γ→Γ' : ctxt → ctxt
Γ→Γ' Γ = ctxt-rename xₓ x (ctxt-var-decl-if x Γ)
Ls' = stringset-insert Ls x
-- kind arrow
match-kinds-norm Xs Ls uf (KndArrow kₓ₁ kₓ₂) (KndArrow k₁ k₂) =
match-kinds Xs Ls uf kₓ₁ k₁
≫=spans' λ Xs → match-kinds Xs Ls uf kₓ₂ k₂
match-kinds-norm Xs Ls uf (KndArrow kₓ₁ kₓ₂) (KndPi _ pi x (Tkk k₁) k₂) =
match-kinds Xs Ls uf kₓ₁ k₁
≫=spans' λ Xs → match-kinds Xs Ls uf kₓ₂ k₂
match-kinds-norm Xs Ls uf (KndPi _ _ x (Tkk kₓ₁) kₓ₂) (KndArrow k₁ k₂) =
match-kinds Xs Ls uf kₓ₁ k₁
≫=spans' λ Xs → match-kinds Xs Ls uf kₓ₂ k₂
-- kind tp arrow
match-kinds-norm Xs Ls uf (KndTpArrow tpₓ kₓ) (KndTpArrow tp k) =
match-types Xs Ls uf tpₓ tp
≫=spans' λ Xs → match-kinds Xs Ls uf kₓ k
match-kinds-norm Xs Ls uf (KndPi _ _ x (Tkt tpₓ) kₓ) (KndTpArrow tp k) =
match-types Xs Ls uf tpₓ tp
≫=spans' λ Xs → match-kinds Xs Ls uf kₓ k
match-kinds-norm Xs Ls uf (KndTpArrow tpₓ kₓ) (KndPi _ _ x (Tkt tp) k) =
match-types Xs Ls uf tpₓ tp
≫=spans' λ Xs → match-kinds Xs Ls uf kₓ k
match-kinds-norm Xs Ls uf (Star _) (Star _) =
match-types-ok $ Xs
match-kinds-norm Xs Ls uf kₓ k =
get-ctxt λ Γ → match-types-error $ m-err.e-matchk-failure -- m-err.e-kind-ineq Γ kₓ k
match-kinds Xs Ls uf kₓ k =
get-ctxt λ Γ →
match-kinds-norm Xs Ls uf
(hnf Γ (unfolding-elab unfold-head) kₓ tt)
(hnf Γ (unfolding-elab unfold-head) k tt)
-- match-tk
-- --------------------------------------------------
match-tks Xs Ls uf (Tkk kₓ) (Tkk k) = match-kinds Xs Ls uf kₓ k
match-tks Xs Ls uf (Tkt tpₓ) (Tkt tp) = match-types Xs Ls uf tpₓ tp
match-tks Xs Ls uf tkₓ tk =
get-ctxt λ Γ → match-types-error m-err.e-matchk-failure -- m-err.e-tk-ineq Γ tkₓ tk
-- match-prototype
-- --------------------------------------------------
match-prototype-err : type → prototype → spanM match-prototype-data
match-prototype-err tp pt = spanMr $ mk-match-prototype-data meta-vars-empty (decor-error tp pt) tt
{-
--------------------
Xs ⊢? T ≔ ⁇ ⇒ (∅ , T)
-}
match-prototype Xs uf tp (proto-maybe nothing) =
spanMr $ mk-match-prototype-data Xs (decor-type tp) ff
{-
Xs ⊢= T ≔ S ⇒ σ
--------------------
Xs ⊢? T ≔ S ⇒ (σ , T)
-}
match-prototype Xs uf tp (proto-maybe (just tp')) =
match-types Xs empty-trie match-unfolding-both tp tp'
on-fail (λ _ → spanMr $ mk-match-prototype-data Xs (decor-type tp) tt)
≫=spans' λ Xs' → spanMr $ mk-match-prototype-data Xs' (decor-type tp) ff
{-
Xs,X ⊢? T ≔ ⁇ → P ⇒ (σ , W)
-----------------------------------------------
Xs ⊢? ∀ X . T ≔ ⁇ → P ⇒ (σ - X , ∀ X = σ(X) . W)
-}
match-prototype Xs uf (Abs pi bₓ pi' x (Tkk k) tp) pt'@(proto-arrow e? pt) =
get-ctxt λ Γ →
-- 1) generate a fresh meta-var Y, add it to the meta-vars, and rename
-- occurences of x in tp to Y
let ret = meta-vars-add-from-tpabs Γ missing-span-location Xs (mk-tpabs Erased x k tp)
Y = fst ret ; Xs' = snd ret ; tp' = subst Γ (meta-var-to-type-unsafe Y) x tp
-- 2) match the body against the original prototype to generate a decorated type
-- and find some solutions
in match-prototype Xs' ff tp' pt'
≫=span λ ret →
let mk-match-prototype-data Xs' dt err = ret
Y' = maybe-else' (meta-vars-lookup Xs' (meta-var-name Y)) Y λ Y → Y
-- 3) replace the meta-vars with the bound type variable
in subst-decortype Γ (TpVar pi x) (meta-var-name Y) dt
-- 4) leave behind the solution for Y as a decoration and drop Y from Xs
≫=span λ dt' →
let sort' = meta-var.sort (meta-var-set-src Y' checking)
dt″ = decor-decor Erased pi x sort' dt' in
spanMr $ mk-match-prototype-data (meta-vars-remove Xs' Y) dt″ err
{-
Xs ⊢? T ≔ P ⇒ (σ , P)
-----------------------------
Xs ⊢? S → T ≔ ⁇ → P ⇒ (σ , P)
-}
match-prototype Xs uf (Abs pi b pi' x (Tkt dom) cod) (proto-arrow e? pt) =
match-prototype Xs ff cod pt
≫=span λ ret →
let mk-match-prototype-data Xs dt err = ret
dt' = decor-decor b pi x (meta-var-tm dom nothing) dt
in spanMr $ if ~ eq-maybeErased b e?
then mk-match-prototype-data meta-vars-empty dt' tt
else mk-match-prototype-data Xs dt' err
match-prototype Xs uf (TpArrow dom at cod) (proto-arrow e? pt) =
match-prototype Xs ff cod pt
≫=span λ ret →
let mk-match-prototype-data Xs' dt err = ret
dt' = decor-arrow at dom dt
in spanMr $ if ~ eq-maybeErased at e?
then mk-match-prototype-data meta-vars-empty dt' tt
else mk-match-prototype-data Xs' dt' err
{-
X ∈ Xs
-----------------------------------
Xs ⊢? X ≔ ⁇ → P ⇒ (σ , (X , ⁇ → P))
-}
match-prototype Xs tt tp@(TpVar pi x) pt@(proto-arrow _ _) =
spanMr $ mk-match-prototype-data Xs (decor-stuck tp pt) ff
-- everything else...
-- Types for which we should keep digging
match-prototype Xs ff tp@(TpVar pi x) pt@(proto-arrow _ _) =
get-ctxt λ Γ →
match-prototype Xs tt (hnf Γ (unfolding-elab unfold-head) tp tt) pt
match-prototype Xs uf (NoSpans tp _) pt@(proto-arrow _ _) =
match-prototype Xs uf tp pt
match-prototype Xs uf (TpParens _ tp _) pt@(proto-arrow _ _) =
match-prototype Xs uf tp pt
match-prototype Xs uf (TpLet pi (DefTerm piₗ x opt t) tp) pt@(proto-arrow _ _) =
get-ctxt λ Γ →
let tp' = subst Γ (Chi posinfo-gen opt t) x tp in
match-prototype Xs uf tp' pt
match-prototype Xs uf (TpLet pi (DefType piₗ x k tp') tp) pt@(proto-arrow _ _) =
get-ctxt λ Γ →
let tp″ = subst Γ tp' x tp in
match-prototype Xs uf tp″ pt
match-prototype Xs ff tp@(TpApp _ _) pt@(proto-arrow _ _) =
get-ctxt λ Γ →
match-prototype Xs tt (hnf Γ (unfolding-elab unfold-head) tp tt) pt
match-prototype Xs ff tp@(TpAppt _ _) pt@(proto-arrow _ _) =
get-ctxt λ Γ →
match-prototype Xs tt (hnf Γ (unfolding-elab unfold-head) tp tt) pt
-- types for which we should suspend disbelief
match-prototype Xs tt tp@(TpApp _ _) pt@(proto-arrow _ _) =
spanMr $ mk-match-prototype-data Xs (decor-stuck tp pt) ff
match-prototype Xs tt tp@(TpAppt _ _) pt@(proto-arrow _ _) =
spanMr $ mk-match-prototype-data Xs (decor-stuck tp pt) ff
-- types which clearly do not match the prototype
match-prototype Xs uf tp@(TpEq _ _ _ _) pt@(proto-arrow _ _) =
match-prototype-err tp pt
match-prototype Xs uf tp@(TpHole _) pt@(proto-arrow _ _) =
match-prototype-err tp pt
match-prototype Xs uf tp@(TpLambda _ _ _ _ _) pt@(proto-arrow _ _) =
match-prototype-err tp pt
match-prototype Xs uf tp@(Iota _ _ _ _ _) pt@(proto-arrow _ _) =
match-prototype-err tp pt
match-prototype Xs uf tp@(Lft _ _ _ _ _) pt@(proto-arrow _ _) =
match-prototype-err tp pt
-- check-typei: check a type against (maybe) a kind
-- ==================================================
--ACG WIP
--check-typei (TpHole pi) k = spanM-add
check-typei (TpHole pi) k =
get-ctxt (λ Γ → spanM-add (tp-hole-span Γ pi k []) ≫span return-when k k)
check-typei (TpParens pi t pi') k =
spanM-add (punctuation-span "Parens (type)" pi pi') ≫span
check-type t k
check-typei (NoSpans t _) k = check-type t k ≫=spand spanMr
check-typei (TpVar pi x) mk =
get-ctxt (cont mk)
where cont : (mk : maybe kind) → ctxt → spanM (check-ret mk)
cont mk Γ with ctxt-lookup-type-var Γ x
cont mk Γ | nothing =
spanM-add (TpVar-span Γ pi x (maybe-to-checking mk)
(expected-kind-if Γ mk ++ [ missing-kind ])
(just "Missing a kind for a type variable.")) ≫span
return-when mk mk
cont nothing Γ | (just k) =
spanM-add (TpVar-span Γ pi x synthesizing [ kind-data Γ k ] nothing) ≫span
check-type-return Γ k
cont (just k) Γ | just k' =
spanM-add (TpVar-span Γ pi x checking
(expected-kind Γ k :: [ kind-data Γ k' ])
(if conv-kind Γ k k' then nothing else just "The computed kind does not match the expected kind."))
check-typei (TpLambda pi pi' x atk body) (just k) with to-absk k
check-typei (TpLambda pi pi' x atk body) (just k) | just (mk-absk x' atk' _ k') =
check-tk atk ≫span
spanM-add (punctuation-span "Lambda (type)" pi (posinfo-plus pi 1)) ≫span
get-ctxt λ Γ →
spanM-add (if conv-tk Γ (qualif-tk Γ atk) atk' then
TpLambda-span pi x atk body checking [ kind-data Γ k ] nothing
else
uncurry (λ tvs err → TpLambda-span pi x atk body checking tvs (just err)) (lambda-bound-var-conv-error Γ x atk' atk [ kind-data Γ k ])) ≫span
add-tk pi' x atk ≫=span λ mi →
get-ctxt λ Γ' → check-type body (just (rename-var Γ x' (qualif-var Γ' x) k')) ≫span
spanM-restore-info x mi
check-typei (TpLambda pi pi' x atk body) (just k) | nothing =
check-tk atk ≫span
spanM-add (punctuation-span "Lambda (type)" pi (posinfo-plus pi 1)) ≫span
get-ctxt λ Γ →
spanM-add (TpLambda-span pi x atk body checking [ expected-kind Γ k ]
(just "The type is being checked against a kind which is not an arrow- or Pi-kind."))
check-typei (TpLambda pi pi' x atk body) nothing =
spanM-add (punctuation-span "Lambda (type)" pi (posinfo-plus pi 1)) ≫span
check-tk atk ≫span
add-tk pi' x atk ≫=span λ mi →
check-type body nothing ≫=span
cont ≫=span λ mk →
spanM-restore-info x mi ≫span
spanMr mk
where cont : maybe kind → spanM (maybe kind)
cont nothing =
spanM-add (TpLambda-span pi x atk body synthesizing [] nothing) ≫span
spanMr nothing
cont (just k) =
get-ctxt λ Γ →
let atk' = qualif-tk Γ atk in
-- This should indeed "unqualify" occurrences of x in k for r
let r = absk-tk x atk' (rename-var Γ (pi' % x) x k) in
spanM-add (TpLambda-span pi x atk' body synthesizing [ kind-data Γ r ] nothing) ≫span
spanMr (just r)
check-typei (Abs pi b {- All or Pi -} pi' x atk body) k =
get-ctxt λ Γ →
spanM-add (uncurry (TpQuant-span (me-unerased b) pi x atk body (maybe-to-checking k))
(if-check-against-star-data Γ "A type-level quantification" k)) ≫span
spanM-add (punctuation-span "Forall" pi (posinfo-plus pi 1)) ≫span
check-tk atk ≫span
add-tk pi' x atk ≫=span λ mi →
check-type body (just star) ≫span
spanM-restore-info x mi ≫span
return-star-when k
check-typei (TpArrow t1 _ t2) k =
get-ctxt λ Γ →
spanM-add (uncurry (TpArrow-span t1 t2 (maybe-to-checking k)) (if-check-against-star-data Γ "An arrow type" k)) ≫span
check-type t1 (just star) ≫span
check-type t2 (just star) ≫span
return-star-when k
check-typei (TpAppt tp t) k =
check-type tp nothing ≫=span cont'' ≫=spanr cont' k
where cont : kind → spanM (maybe kind)
cont (KndTpArrow tp' k') =
check-term t (just tp') ≫span
spanMr (just k')
cont (KndPi _ _ x (Tkt tp') k') =
check-term t (just tp') ≫span
get-ctxt λ Γ →
spanMr (just (subst Γ (qualif-term Γ t) x k'))
cont k' =
get-ctxt λ Γ →
spanM-add (TpAppt-span tp t (maybe-to-checking k)
(type-app-head Γ tp :: head-kind Γ k' :: [ term-argument Γ t ])
(just ("The kind computed for the head of the type application does"
^ " not allow the head to be applied to an argument which is a term"))) ≫span
spanMr nothing
cont' : (outer : maybe kind) → kind → spanM (check-ret outer)
cont' nothing k =
get-ctxt λ Γ →
spanM-add (TpAppt-span tp t synthesizing [ kind-data Γ k ] nothing) ≫span
check-type-return Γ k
cont' (just k') k =
get-ctxt λ Γ →
if conv-kind Γ k k'
then spanM-add (TpAppt-span tp t checking (expected-kind Γ k' :: [ kind-data Γ k ]) nothing)
else spanM-add (TpAppt-span tp t checking (expected-kind Γ k' :: [ kind-data Γ k ])
(just "The kind computed for a type application does not match the expected kind."))
cont'' : maybe kind → spanM (maybe kind)
cont'' nothing = spanM-add (TpAppt-span tp t (maybe-to-checking k) [] nothing) ≫span spanMr nothing
cont'' (just k) = cont k
check-typei (TpApp tp tp') k =
check-type tp nothing ≫=span cont'' ≫=spanr cont' k
where cont : kind → spanM (maybe kind)
cont (KndArrow k'' k') =
check-type tp' (just k'') ≫span
spanMr (just k')
cont (KndPi _ _ x (Tkk k'') k') =
check-type tp' (just k'') ≫span
get-ctxt λ Γ →
spanMr (just (subst Γ (qualif-type Γ tp') x k'))
cont k' =
get-ctxt λ Γ →
spanM-add (TpApp-span tp tp' (maybe-to-checking k)
(type-app-head Γ tp :: head-kind Γ k' :: [ type-argument Γ tp' ])
(just ("The kind computed for the head of the type application does"
^ " not allow the head to be applied to an argument which is a type"))) ≫span
spanMr nothing
cont' : (outer : maybe kind) → kind → spanM (check-ret outer)
cont' nothing k =
get-ctxt λ Γ →
spanM-add (TpApp-span tp tp' synthesizing [ kind-data Γ k ] nothing) ≫span
check-type-return Γ k
cont' (just k') k =
get-ctxt λ Γ →
if conv-kind Γ k k'
then spanM-add (TpApp-span tp tp' checking (expected-kind Γ k' :: [ kind-data Γ k' ]) nothing)
else spanM-add (TpApp-span tp tp' checking (expected-kind Γ k' :: [ kind-data Γ k ])
(just "The kind computed for a type application does not match the expected kind."))
cont'' : maybe kind → spanM (maybe kind)
cont'' nothing = spanM-add (TpApp-span tp tp' (maybe-to-checking k) [] nothing) ≫span spanMr nothing
cont'' (just k) = cont k
check-typei (TpEq pi t1 t2 pi') k =
get-ctxt (λ Γ →
untyped-term-spans t1 ≫span
set-ctxt Γ ≫span
untyped-term-spans t2 ≫span
set-ctxt Γ) ≫span
get-ctxt λ Γ →
spanM-add (uncurry (TpEq-span pi t1 t2 pi' (maybe-to-checking k)) (if-check-against-star-data Γ "An equation" k)) ≫span
-- spanM-add (unchecked-term-span t1) ≫span
-- spanM-add (unchecked-term-span t2) ≫span
return-star-when k
check-typei (Lft pi pi' X t l) k =
add-tk pi' X (Tkk star) ≫=span λ mi →
get-ctxt λ Γ → check-term t (just (qualif-type Γ (liftingType-to-type X l))) ≫span
spanM-add (punctuation-span "Lift" pi (posinfo-plus pi 1)) ≫span
spanM-restore-info X mi ≫span
cont k (qualif-kind Γ (liftingType-to-kind l))
where cont : (outer : maybe kind) → kind → spanM (check-ret outer)
cont nothing k = get-ctxt λ Γ → spanM-add (Lft-span pi X t synthesizing [ kind-data Γ k ] nothing) ≫span spanMr (just k)
cont (just k') k =
get-ctxt λ Γ →
if conv-kind Γ k k' then
spanM-add (Lft-span pi X t checking ( expected-kind Γ k' :: [ kind-data Γ k ]) nothing)
else
spanM-add (Lft-span pi X t checking ( expected-kind Γ k' :: [ kind-data Γ k ]) (just "The expected kind does not match the computed kind."))
check-typei (Iota pi pi' x t1 t2) mk =
get-ctxt λ Γ →
spanM-add (uncurry (Iota-span pi t2 (maybe-to-checking mk)) (if-check-against-star-data Γ "A iota-type" mk)) ≫span
check-typei t1 (just star) ≫span
add-tk pi' x (Tkt t1) ≫=span λ mi →
check-typei t2 (just star) ≫span
spanM-restore-info x mi ≫span
return-star-when mk
check-typei (TpLet pi d T) mk =
check-def d ≫=span finish
where
maybe-subst : defTermOrType → (mk : maybe kind) → check-ret mk → spanM (check-ret mk)
maybe-subst _ (just k) triv = spanMok
maybe-subst _ nothing nothing = spanMr nothing
maybe-subst (DefTerm pi x NoType t) nothing (just k) = get-ctxt λ Γ →
spanMr (just (subst Γ (qualif-term Γ (Chi posinfo-gen NoType t)) (pi % x) k))
maybe-subst (DefTerm pi x (SomeType T) t) nothing (just k) = get-ctxt λ Γ →
spanMr (just (subst Γ (qualif-term Γ (Chi posinfo-gen (SomeType T) t)) (pi % x) k))
maybe-subst (DefType pi x k' T') nothing (just k) = get-ctxt λ Γ →
spanMr (just (subst Γ (qualif-type Γ T') (pi % x) k))
finish : var × restore-def → spanM (check-ret mk)
finish (x , m) =
get-ctxt λ Γ →
spanM-add (TpLet-span Γ (maybe-to-checking mk) pi d T [] nothing) ≫span
check-type T mk ≫=span λ r →
spanM-restore-info x m ≫span
maybe-subst d mk r
check-kind (KndParens pi k pi') =
spanM-add (punctuation-span "Parens (kind)" pi pi') ≫span
check-kind k
check-kind (Star pi) = spanM-add (Star-span pi checking nothing)
check-kind (KndVar pi x ys) =
get-ctxt λ Γ →
maybe-else' (ctxt-lookup-kind-var-def-args Γ x)
(spanM-add (KndVar-span Γ (pi , x) (kvar-end-pos pi x ys) ParamsNil checking []
(just "Undefined kind variable")))
λ ps-as → check-args-against-params nothing (pi , x) -- Isn't used vvvv
(fst $ snd $ elim-pair ps-as λ ps as → subst-params-args Γ ps as star) ys
{-helper (ctxt-lookup-kind-var-def-args Γ x)
where helper : maybe (params × args) → spanM ⊤
helper (just (ps , as)) = check-args-against-params nothing (pi , x) ps (append-args as ys)
helper nothing = get-ctxt λ Γ →
spanM-add (KndVar-span Γ (pi , x) (kvar-end-pos pi x ys) ParamsNil checking []
(just "Undefined kind variable"))-}
check-kind (KndArrow k k') =
spanM-add (KndArrow-span k k' checking nothing) ≫span
check-kind k ≫span
check-kind k'
check-kind (KndTpArrow t k) =
spanM-add (KndTpArrow-span t k checking nothing) ≫span
check-type t (just star) ≫span
check-kind k
check-kind (KndPi pi pi' x atk k) =
spanM-add (punctuation-span "Pi (kind)" pi (posinfo-plus pi 1)) ≫span
spanM-add (KndPi-span pi x atk k checking nothing) ≫span
check-tk atk ≫span
add-tk pi' x atk ≫=span λ mi →
check-kind k ≫span
spanM-restore-info x mi
check-args-against-params kind-or-import orig ps ys =
caap (~ isJust kind-or-import) ps ys empty-trie
where
make-span : ctxt → 𝕃 tagged-val → err-m → span
make-span Γ ts err = maybe-else
(KndVar-span Γ orig (kvar-end-pos (fst orig) (snd orig) ys) ps checking ts err)
(λ loc → Import-module-span Γ orig ps (loc :: ts) err)
kind-or-import
caap : 𝔹 → params → args → trie arg → spanM ⊤
caap koi (ParamsCons (Decl _ pi _ x (Tkk k) _) ps) (ArgsCons (TypeArg T) ys) σ =
get-ctxt λ Γ →
check-type T (just (substs Γ σ k)) ≫span
caap koi ps ys (trie-insert σ x $ TypeArg (qualif-type Γ T))
caap ff (ParamsCons (Decl _ pi NotErased x (Tkt T) _) ps) (ArgsCons (TermArg NotErased t) ys) σ =
get-ctxt λ Γ →
let T' = substs Γ σ T in
check-term t (just T') ≫span
check-erased-margs t (just T') ≫span
caap ff ps ys (trie-insert σ x $ TermArg NotErased (qualif-term Γ t))
caap ff (ParamsCons (Decl _ pi Erased x (Tkt T) _) ps) (ArgsCons (TermArg NotErased t) ys) σ =
get-ctxt λ Γ →
spanM-add (make-span Γ [ term-argument Γ t ]
(just ("A term argument was supplied for erased term parameter " ^ x)))
caap ff (ParamsCons (Decl _ pi NotErased x (Tkt T) _) ps) (ArgsCons (TermArg Erased t) ys) σ =
get-ctxt λ Γ →
spanM-add (make-span Γ [ term-argument Γ t ]
(just ("An erased term argument was supplied for term parameter " ^ x)))
-- Either a kind argument or a correctly erased module argument
caap koi (ParamsCons (Decl _ pi me x (Tkt T) _) ps) (ArgsCons (TermArg me' t) ys) σ =
get-ctxt λ Γ →
check-term t (just (substs Γ σ T)) ≫span
caap koi ps ys (trie-insert σ x $ TermArg me (qualif-term Γ t))
caap koi (ParamsCons (Decl _ x₁ _ x (Tkk x₃) x₄) ps₁) (ArgsCons (TermArg _ x₅) ys₂) σ =
get-ctxt λ Γ →
spanM-add (make-span Γ [ term-argument Γ x₅ ]
(just ("A term argument was supplied for type parameter " ^ x)))
caap koi (ParamsCons (Decl _ x₁ _ x (Tkt x₃) x₄) ps₁) (ArgsCons (TypeArg x₅) ys₂) σ =
get-ctxt λ Γ →
spanM-add (make-span Γ [ type-argument Γ x₅ ]
(just ("A type argument was supplied for term parameter " ^ x)))
caap tt (ParamsCons (Decl _ _ _ x _ _) ps₁) ArgsNil σ =
get-ctxt λ Γ →
spanM-add (make-span Γ []
(just ("Missing an argument for parameter " ^ x)))
caap ff (ParamsCons (Decl _ _ _ x _ _) ps₁) ArgsNil σ =
get-ctxt λ Γ → spanM-add (make-span Γ [] nothing)
caap koi ParamsNil (ArgsCons x₁ ys₂) σ =
get-ctxt λ Γ →
spanM-add (make-span Γ [ arg-argument Γ x₁ ]
(just "An extra argument was given"))
caap koi ParamsNil ArgsNil σ =
get-ctxt λ Γ → spanM-add (make-span Γ [] nothing)
check-erased-margs t mtp = get-ctxt λ Γ →
let x = erased-margs Γ in
if are-free-in skip-erased x t
then spanM-add (erased-marg-span Γ t mtp)
else spanMok
check-tk (Tkk k) = check-kind k
check-tk (Tkt t) = check-type t (just star)
check-def (DefTerm pi₁ x NoType t') =
get-ctxt λ Γ → check-term t' nothing ≫=span cont (compileFail-in Γ t') t'
where
cont : 𝕃 tagged-val × err-m → term → maybe type → spanM (var × restore-def)
cont (tvs , err) t' (just T) =
spanM-push-term-def pi₁ x t' T ≫=span λ m →
get-ctxt λ Γ →
spanM-add (Var-span Γ pi₁ x synthesizing (type-data Γ T :: noterased :: tvs) err) ≫span
spanMr (x , m)
cont (tvs , err) t' nothing = spanM-push-term-udef pi₁ x t' ≫=span λ m →
get-ctxt λ Γ →
spanM-add (Var-span Γ pi₁ x synthesizing (noterased :: tvs) err) ≫span
spanMr (x , m)
check-def (DefTerm pi₁ x (SomeType T) t') =
check-type T (just star) ≫span
get-ctxt λ Γ →
let T' = qualif-type Γ T in
check-term t' (just T') ≫span
spanM-push-term-def pi₁ x t' T' ≫=span λ m →
get-ctxt λ Γ →
let p = compileFail-in Γ t' in
spanM-add (Var-span Γ pi₁ x checking (type-data Γ T' :: noterased :: fst p) (snd p)) ≫span
spanMr (x , m)
check-def (DefType pi x k T) =
check-kind k ≫span
get-ctxt λ Γ →
let k' = qualif-kind Γ k in
check-type T (just k') ≫span
spanM-push-type-def pi x T k' ≫=span λ m →
get-ctxt λ Γ → spanM-add (Var-span Γ pi x checking (noterased :: [ kind-data Γ k' ]) nothing) ≫span
spanMr (x , m)
|
{
"alphanum_fraction": 0.6225491824,
"avg_line_length": 47.5155181483,
"ext": "agda",
"hexsha": "32125a2e6dbff2c453c7c20f7259ea1ce1ff2561",
"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": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xoltar/cedille",
"max_forks_repo_path": "src/classify.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"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": "xoltar/cedille",
"max_issues_repo_path": "src/classify.agda",
"max_line_length": 186,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xoltar/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": 29557,
"size": 90327
}
|
open import Relation.Binary.Core
module Heapsort.Impl2 {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import BBHeap _≤_ hiding (flatten)
open import BBHeap.Compound _≤_
open import BBHeap.Drop _≤_ tot≤ trans≤
open import BBHeap.Drop.Properties _≤_ tot≤ trans≤
open import BBHeap.Heapify _≤_ tot≤ trans≤
open import BBHeap.Order _≤_
open import BBHeap.Order.Properties _≤_
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import Data.List hiding (drop)
open import OList _≤_
flatten : {b : Bound}(h : BBHeap b) → Acc h → OList b
flatten leaf _ = onil
flatten (left b≤x l⋘r) (acc rs) = :< b≤x (flatten (drop (cl b≤x l⋘r)) (rs (drop (cl b≤x l⋘r)) (lemma-drop≤′ (cl b≤x l⋘r))))
flatten (right b≤x l⋙r) (acc rs) = :< b≤x (flatten (drop (cr b≤x l⋙r)) (rs (drop (cr b≤x l⋙r)) (lemma-drop≤′ (cr b≤x l⋙r))))
heapsort : List A → OList bot
heapsort xs = flatten (heapify xs) (≺-wf (heapify xs))
|
{
"alphanum_fraction": 0.6344621514,
"avg_line_length": 37.1851851852,
"ext": "agda",
"hexsha": "9352cea12f91e7d6f260cf1e7b97cae5ae6a2a1e",
"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/Heapsort/Impl2.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/Heapsort/Impl2.agda",
"max_line_length": 124,
"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/Heapsort/Impl2.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": 393,
"size": 1004
}
|
------------------------------------------------------------------------------
-- Equality reasoning on axiomatic PA
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module only re-export the preorder reasoning instanced on
-- the axiomatic PA propositional equality.
module PA.Axiomatic.Mendelson.Relation.Binary.EqReasoning where
open import PA.Axiomatic.Mendelson.Base
open import PA.Axiomatic.Mendelson.Relation.Binary.PropositionalEqualityI
using ( ≈-refl ; ≈-trans)
import Common.Relation.Binary.PreorderReasoning
open module ≈-Reasoning =
Common.Relation.Binary.PreorderReasoning _≈_ ≈-refl ≈-trans public
renaming ( _∼⟨_⟩_ to _≈⟨_⟩_ )
|
{
"alphanum_fraction": 0.5773672055,
"avg_line_length": 37.652173913,
"ext": "agda",
"hexsha": "0885e853e7a0e8d3061deca16df889f8d37dcb94",
"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/PA/Axiomatic/Mendelson/Relation/Binary/EqReasoning.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/PA/Axiomatic/Mendelson/Relation/Binary/EqReasoning.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/PA/Axiomatic/Mendelson/Relation/Binary/EqReasoning.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": 191,
"size": 866
}
|
module MJ.Examples.Integer where
open import Prelude
open import Data.Maybe
open import Data.Vec
import Data.Vec.All as Vec∀
open import Data.Star
open import Data.Bool
open import Data.List
open import Data.List.Any
open import Data.List.Membership.Propositional
open import Data.List.All hiding (lookup)
open import Data.Product hiding (Σ)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable
open import Data.String
open import MJ.Types
{-
class Integer {
int x = 0;
int get() {
return this.x;
}
int set(Integer b) {
this.x = b.get()
return;
}
}
-}
open import MJ.Classtable.Core 1
INT : Cid 1
INT = (cls (# 0))
decls : (ns : NS) → List (String × typing ns)
decls METHOD =
("get" , ([] , int))
∷ ("set" , (ref INT ∷ [] , void))
∷ []
decls FIELD =
("x" , int)
∷ []
IntegerSig = (class Object (int ∷ []) decls)
-- class table signature
Σ : Classtable
Σ = record {
Σ = λ{
(cls zero) → IntegerSig ;
(cls (suc ())) ;
Object → ObjectClass} ;
founded = refl ;
rooted = λ{
(cls zero) → super ◅ ε ;
(cls (suc ())) ;
Object → ε };
Σ-Object = refl }
open import MJ.Classtable.Code Σ
open import MJ.Syntax Σ
open import MJ.Syntax.Program Σ
-- Integer class body
IntegerImpl : Implementation INT
IntegerImpl = implementation
(body (body
(set
(var (here refl))
"x"
(var (there (here refl))) ◅ ε)
unit))
-- methods
(
-- get
body (body ε (get (var (here refl)) "x"))
-- set
∷ (body (body
(set
(var (here refl))
"x"
{int}
(get (var (there (here refl))) "x") ◅ ε)
unit))
∷ []
)
-- Implementation of the class table
Lib : Code
Lib (cls zero) = IntegerImpl
Lib (cls (suc ()))
Lib Object = implementation (body (body ε unit)) []
open import MJ.Semantics Σ Lib
open import MJ.Semantics.Values Σ
-- a simple program
p₀ : Prog int
p₀ = Lib ,
let
x = (here refl)
y = (there (here refl))
in body
(
loc (ref INT)
◅ loc (ref INT)
◅ asgn x (new INT ((num 9) ∷ []))
◅ asgn y (new INT ((num 18) ∷ []))
◅ run (call (var x) "set" {_}{void} (var y ∷ []))
◅ ε
)
(get (var x) "x")
test0 : p₀ ⇓⟨ 100 ⟩ (λ {W} (v : Val W int) → v ≡ num 18)
test0 = refl
|
{
"alphanum_fraction": 0.5591802593,
"avg_line_length": 19.5983606557,
"ext": "agda",
"hexsha": "8eb08a1de34ace25cb44dc0927335f6efba2505b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJ/Examples/Integer.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJ/Examples/Integer.agda",
"max_line_length": 56,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJ/Examples/Integer.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 744,
"size": 2391
}
|
{-# OPTIONS --sized-types #-}
module SBList.Properties {A : Set}(_≤_ : A → A → Set) where
open import Data.List
open import List.Permutation.Base A
open import SBList _≤_
lemma-unbound-bound : (xs : List A) → xs ∼ unbound (bound xs)
lemma-unbound-bound [] = ∼[]
lemma-unbound-bound (x ∷ xs) = ∼x /head /head (lemma-unbound-bound xs)
|
{
"alphanum_fraction": 0.6647058824,
"avg_line_length": 24.2857142857,
"ext": "agda",
"hexsha": "ea9349bec0f7a5b0406b9752ed457168f1417f95",
"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/SBList/Properties.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/SBList/Properties.agda",
"max_line_length": 70,
"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/SBList/Properties.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": 107,
"size": 340
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lexicographic products of binary relations
------------------------------------------------------------------------
-- The definition of lexicographic product used here is suitable if
-- the left-hand relation is a strict partial order.
{-# OPTIONS --without-K --safe #-}
module Data.Product.Relation.Binary.Lex.Strict where
open import Data.Product
open import Data.Product.Relation.Binary.Pointwise.NonDependent as Pointwise
using (Pointwise)
open import Data.Sum using (inj₁; inj₂; _-⊎-_; [_,_])
open import Data.Empty
open import Function
open import Level
open import Relation.Nullary
open import Relation.Nullary.Product
open import Relation.Nullary.Sum
open import Relation.Binary
open import Relation.Binary.Consequences
module _ {a₁ a₂ ℓ₁ ℓ₂} {A₁ : Set a₁} {A₂ : Set a₂} where
------------------------------------------------------------------------
-- A lexicographic ordering over products
×-Lex : (_≈₁_ _<₁_ : Rel A₁ ℓ₁) → (_≤₂_ : Rel A₂ ℓ₂) → Rel (A₁ × A₂) _
×-Lex _≈₁_ _<₁_ _≤₂_ =
(_<₁_ on proj₁) -⊎- (_≈₁_ on proj₁) -×- (_≤₂_ on proj₂)
------------------------------------------------------------------------
-- Some properties which are preserved by ×-Lex (under certain
-- assumptions).
×-reflexive : ∀ _≈₁_ _∼₁_ {_≈₂_ : Rel A₂ ℓ₂} _≤₂_ →
_≈₂_ ⇒ _≤₂_ → (Pointwise _≈₁_ _≈₂_) ⇒ (×-Lex _≈₁_ _∼₁_ _≤₂_)
×-reflexive _ _ _ refl₂ = λ x≈y →
inj₂ (proj₁ x≈y , refl₂ (proj₂ x≈y))
×-irreflexive : ∀ {_≈₁_ _<₁_} → Irreflexive _≈₁_ _<₁_ →
∀ {_≈₂_ _<₂_ : Rel A₂ ℓ₂} → Irreflexive _≈₂_ _<₂_ →
Irreflexive (Pointwise _≈₁_ _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_)
×-irreflexive ir₁ ir₂ x≈y (inj₁ x₁<y₁) = ir₁ (proj₁ x≈y) x₁<y₁
×-irreflexive ir₁ ir₂ x≈y (inj₂ x≈<y) =
ir₂ (proj₂ x≈y) (proj₂ x≈<y)
×-transitive : ∀ {_≈₁_ _<₁_} →
IsEquivalence _≈₁_ → _<₁_ Respects₂ _≈₁_ → Transitive _<₁_ →
∀ {_≤₂_} → Transitive _≤₂_ → Transitive (×-Lex _≈₁_ _<₁_ _≤₂_)
×-transitive {_≈₁_} {_<₁_} eq₁ resp₁ trans₁ {_≤₂_} trans₂ = trans
where
module Eq₁ = IsEquivalence eq₁
trans : Transitive (×-Lex _≈₁_ _<₁_ _≤₂_)
trans (inj₁ x₁<y₁) (inj₁ y₁<z₁) = inj₁ (trans₁ x₁<y₁ y₁<z₁)
trans (inj₁ x₁<y₁) (inj₂ y≈≤z) =
inj₁ (proj₁ resp₁ (proj₁ y≈≤z) x₁<y₁)
trans (inj₂ x≈≤y) (inj₁ y₁<z₁) =
inj₁ (proj₂ resp₁ (Eq₁.sym $ proj₁ x≈≤y) y₁<z₁)
trans (inj₂ x≈≤y) (inj₂ y≈≤z) =
inj₂ ( Eq₁.trans (proj₁ x≈≤y) (proj₁ y≈≤z)
, trans₂ (proj₂ x≈≤y) (proj₂ y≈≤z) )
×-antisymmetric : ∀ {_≈₁_ _<₁_} →
Symmetric _≈₁_ → Irreflexive _≈₁_ _<₁_ → Asymmetric _<₁_ →
∀ {_≈₂_ _≤₂_ : Rel A₂ ℓ₂} → Antisymmetric _≈₂_ _≤₂_ →
Antisymmetric (Pointwise _≈₁_ _≈₂_) (×-Lex _≈₁_ _<₁_ _≤₂_)
×-antisymmetric {_≈₁_} {_<₁_} sym₁ irrefl₁ asym₁
{_≈₂_} {_≤₂_} antisym₂ = antisym
where
antisym : Antisymmetric (Pointwise _≈₁_ _≈₂_) (×-Lex _≈₁_ _<₁_ _≤₂_)
antisym (inj₁ x₁<y₁) (inj₁ y₁<x₁) =
⊥-elim $ asym₁ x₁<y₁ y₁<x₁
antisym (inj₁ x₁<y₁) (inj₂ y≈≤x) =
⊥-elim $ irrefl₁ (sym₁ $ proj₁ y≈≤x) x₁<y₁
antisym (inj₂ x≈≤y) (inj₁ y₁<x₁) =
⊥-elim $ irrefl₁ (sym₁ $ proj₁ x≈≤y) y₁<x₁
antisym (inj₂ x≈≤y) (inj₂ y≈≤x) =
proj₁ x≈≤y , antisym₂ (proj₂ x≈≤y) (proj₂ y≈≤x)
×-asymmetric : ∀ {_≈₁_ _<₁_} →
Symmetric _≈₁_ → _<₁_ Respects₂ _≈₁_ → Asymmetric _<₁_ →
∀ {_<₂_} → Asymmetric _<₂_ →
Asymmetric (×-Lex _≈₁_ _<₁_ _<₂_)
×-asymmetric {_≈₁_} {_<₁_} sym₁ resp₁ asym₁ {_<₂_} asym₂ = asym
where
irrefl₁ : Irreflexive _≈₁_ _<₁_
irrefl₁ = asym⟶irr resp₁ sym₁ asym₁
asym : Asymmetric (×-Lex _≈₁_ _<₁_ _<₂_)
asym (inj₁ x₁<y₁) (inj₁ y₁<x₁) = asym₁ x₁<y₁ y₁<x₁
asym (inj₁ x₁<y₁) (inj₂ y≈<x) = irrefl₁ (sym₁ $ proj₁ y≈<x) x₁<y₁
asym (inj₂ x≈<y) (inj₁ y₁<x₁) = irrefl₁ (sym₁ $ proj₁ x≈<y) y₁<x₁
asym (inj₂ x≈<y) (inj₂ y≈<x) = asym₂ (proj₂ x≈<y) (proj₂ y≈<x)
×-respects₂ :
∀ {_≈₁_ _<₁_} → IsEquivalence _≈₁_ → _<₁_ Respects₂ _≈₁_ →
{_≈₂_ _<₂_ : Rel A₂ ℓ₂} → _<₂_ Respects₂ _≈₂_ →
(×-Lex _≈₁_ _<₁_ _<₂_) Respects₂ (Pointwise _≈₁_ _≈₂_)
×-respects₂ {_≈₁_} {_<₁_} eq₁ resp₁
{_≈₂_} {_<₂_} resp₂ = resp¹ , resp²
where
_<_ = ×-Lex _≈₁_ _<₁_ _<₂_
open IsEquivalence eq₁ renaming (sym to sym₁; trans to trans₁)
resp¹ : ∀ {x} → (x <_) Respects (Pointwise _≈₁_ _≈₂_)
resp¹ y≈y' (inj₁ x₁<y₁) = inj₁ (proj₁ resp₁ (proj₁ y≈y') x₁<y₁)
resp¹ y≈y' (inj₂ x≈<y) =
inj₂ ( trans₁ (proj₁ x≈<y) (proj₁ y≈y')
, proj₁ resp₂ (proj₂ y≈y') (proj₂ x≈<y) )
resp² : ∀ {y} → (flip _<_ y) Respects (Pointwise _≈₁_ _≈₂_)
resp² x≈x' (inj₁ x₁<y₁) = inj₁ (proj₂ resp₁ (proj₁ x≈x') x₁<y₁)
resp² x≈x' (inj₂ x≈<y) =
inj₂ ( trans₁ (sym₁ $ proj₁ x≈x') (proj₁ x≈<y)
, proj₂ resp₂ (proj₂ x≈x') (proj₂ x≈<y) )
×-decidable : ∀ {_≈₁_ _<₁_} → Decidable _≈₁_ → Decidable _<₁_ →
∀ {_≤₂_} → Decidable _≤₂_ →
Decidable (×-Lex _≈₁_ _<₁_ _≤₂_)
×-decidable dec-≈₁ dec-<₁ dec-≤₂ x y =
dec-<₁ (proj₁ x) (proj₁ y)
⊎-dec
(dec-≈₁ (proj₁ x) (proj₁ y)
×-dec
dec-≤₂ (proj₂ x) (proj₂ y))
×-total₁ : ∀ {_≈₁_ _<₁_} → Total _<₁_ →
∀ {_≤₂_} → Total (×-Lex _≈₁_ _<₁_ _≤₂_)
×-total₁ total₁ x y with total₁ (proj₁ x) (proj₁ y)
... | inj₁ x₁<y₁ = inj₁ (inj₁ x₁<y₁)
... | inj₂ x₁>y₁ = inj₂ (inj₁ x₁>y₁)
×-total₂ : ∀ {_≈₁_ _<₁_} → Symmetric _≈₁_ → Trichotomous _≈₁_ _<₁_ →
∀ {_≤₂_} → Total _≤₂_ →
Total (×-Lex _≈₁_ _<₁_ _≤₂_)
×-total₂ sym tri₁ total₂ x y with tri₁ (proj₁ x) (proj₁ y)
... | tri< x₁<y₁ _ _ = inj₁ (inj₁ x₁<y₁)
... | tri> _ _ y₁<x₁ = inj₂ (inj₁ y₁<x₁)
... | tri≈ _ x₁≈y₁ _ with total₂ (proj₂ x) (proj₂ y)
... | inj₁ x₂≤y₂ = inj₁ (inj₂ (x₁≈y₁ , x₂≤y₂))
... | inj₂ y₂≤x₂ = inj₂ (inj₂ (sym x₁≈y₁ , y₂≤x₂))
×-compare :
{_≈₁_ _<₁_ : Rel A₁ ℓ₁} → Symmetric _≈₁_ → Trichotomous _≈₁_ _<₁_ →
{_≈₂_ _<₂_ : Rel A₂ ℓ₂} → Trichotomous _≈₂_ _<₂_ →
Trichotomous (Pointwise _≈₁_ _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_)
×-compare sym₁ cmp₁ cmp₂ (x₁ , x₂) (y₁ , y₂) with cmp₁ x₁ y₁
... | (tri< x₁<y₁ x₁≉y₁ x₁≯y₁) =
tri< (inj₁ x₁<y₁)
(x₁≉y₁ ∘ proj₁)
[ x₁≯y₁ , x₁≉y₁ ∘ sym₁ ∘ proj₁ ]
... | (tri> x₁≮y₁ x₁≉y₁ x₁>y₁) =
tri> [ x₁≮y₁ , x₁≉y₁ ∘ proj₁ ]
(x₁≉y₁ ∘ proj₁)
(inj₁ x₁>y₁)
... | (tri≈ x₁≮y₁ x₁≈y₁ x₁≯y₁) with cmp₂ x₂ y₂
... | (tri< x₂<y₂ x₂≉y₂ x₂≯y₂) =
tri< (inj₂ (x₁≈y₁ , x₂<y₂))
(x₂≉y₂ ∘ proj₂)
[ x₁≯y₁ , x₂≯y₂ ∘ proj₂ ]
... | (tri> x₂≮y₂ x₂≉y₂ x₂>y₂) =
tri> [ x₁≮y₁ , x₂≮y₂ ∘ proj₂ ]
(x₂≉y₂ ∘ proj₂)
(inj₂ (sym₁ x₁≈y₁ , x₂>y₂))
... | (tri≈ x₂≮y₂ x₂≈y₂ x₂≯y₂) =
tri≈ [ x₁≮y₁ , x₂≮y₂ ∘ proj₂ ]
(x₁≈y₁ , x₂≈y₂)
[ x₁≯y₁ , x₂≯y₂ ∘ proj₂ ]
------------------------------------------------------------------------
-- Collections of properties which are preserved by ×-Lex.
×-isPreorder : ∀ {_≈₁_ _∼₁_} → IsPreorder _≈₁_ _∼₁_ →
∀ {_≈₂_ _∼₂_} → IsPreorder _≈₂_ _∼₂_ →
IsPreorder (Pointwise _≈₁_ _≈₂_) (×-Lex _≈₁_ _∼₁_ _∼₂_)
×-isPreorder {_≈₁_} {_∼₁_} pre₁ {_∼₂_ = _∼₂_} pre₂ =
record
{ isEquivalence = Pointwise.×-isEquivalence
(isEquivalence pre₁) (isEquivalence pre₂)
; reflexive = ×-reflexive _≈₁_ _∼₁_ _∼₂_ (reflexive pre₂)
; trans = ×-transitive
(isEquivalence pre₁) (∼-resp-≈ pre₁)
(trans pre₁) {_≤₂_ = _∼₂_} (trans pre₂)
}
where open IsPreorder
×-isStrictPartialOrder :
∀ {_≈₁_ _<₁_} → IsStrictPartialOrder _≈₁_ _<₁_ →
∀ {_≈₂_ _<₂_} → IsStrictPartialOrder _≈₂_ _<₂_ →
IsStrictPartialOrder (Pointwise _≈₁_ _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_)
×-isStrictPartialOrder {_<₁_ = _<₁_} spo₁ {_<₂_ = _<₂_} spo₂ =
record
{ isEquivalence = Pointwise.×-isEquivalence
(isEquivalence spo₁) (isEquivalence spo₂)
; irrefl = ×-irreflexive {_<₁_ = _<₁_} (irrefl spo₁)
{_<₂_ = _<₂_} (irrefl spo₂)
; trans = ×-transitive
{_<₁_ = _<₁_} (isEquivalence spo₁)
(<-resp-≈ spo₁) (trans spo₁)
{_≤₂_ = _<₂_} (trans spo₂)
; <-resp-≈ = ×-respects₂ (isEquivalence spo₁)
(<-resp-≈ spo₁)
(<-resp-≈ spo₂)
}
where open IsStrictPartialOrder
×-isStrictTotalOrder :
∀ {_≈₁_ _<₁_} → IsStrictTotalOrder _≈₁_ _<₁_ →
∀ {_≈₂_ _<₂_} → IsStrictTotalOrder _≈₂_ _<₂_ →
IsStrictTotalOrder (Pointwise _≈₁_ _≈₂_) (×-Lex _≈₁_ _<₁_ _<₂_)
×-isStrictTotalOrder {_<₁_ = _<₁_} spo₁ {_<₂_ = _<₂_} spo₂ =
record
{ isEquivalence = Pointwise.×-isEquivalence
(isEquivalence spo₁) (isEquivalence spo₂)
; trans = ×-transitive
{_<₁_ = _<₁_} (isEquivalence spo₁)
(<-resp-≈ spo₁) (trans spo₁)
{_≤₂_ = _<₂_} (trans spo₂)
; compare = ×-compare (Eq.sym spo₁) (compare spo₁)
(compare spo₂)
}
where open IsStrictTotalOrder
------------------------------------------------------------------------
-- "Packages" can also be combined.
module _ {ℓ₁ ℓ₂ ℓ₃ ℓ₄} where
×-preorder : Preorder ℓ₁ ℓ₂ _ → Preorder ℓ₃ ℓ₄ _ → Preorder _ _ _
×-preorder p₁ p₂ = record
{ isPreorder = ×-isPreorder (isPreorder p₁) (isPreorder p₂)
} where open Preorder
×-strictPartialOrder :
StrictPartialOrder ℓ₁ ℓ₂ _ → StrictPartialOrder ℓ₃ ℓ₄ _ →
StrictPartialOrder _ _ _
×-strictPartialOrder s₁ s₂ = record
{ isStrictPartialOrder = ×-isStrictPartialOrder
(isStrictPartialOrder s₁) (isStrictPartialOrder s₂)
} where open StrictPartialOrder
×-strictTotalOrder :
StrictTotalOrder ℓ₁ ℓ₂ _ → StrictTotalOrder ℓ₃ ℓ₄ _ →
StrictTotalOrder _ _ _
×-strictTotalOrder s₁ s₂ = record
{ isStrictTotalOrder = ×-isStrictTotalOrder
(isStrictTotalOrder s₁) (isStrictTotalOrder s₂)
} where open StrictTotalOrder
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.15
_×-irreflexive_ = ×-irreflexive
{-# WARNING_ON_USAGE _×-irreflexive_
"Warning: _×-irreflexive_ was deprecated in v0.15.
Please use ×-irreflexive instead."
#-}
_×-isPreorder_ = ×-isPreorder
{-# WARNING_ON_USAGE _×-isPreorder_
"Warning: _×-isPreorder_ was deprecated in v0.15.
Please use ×-isPreorder instead."
#-}
_×-isStrictPartialOrder_ = ×-isStrictPartialOrder
{-# WARNING_ON_USAGE _×-isStrictPartialOrder_
"Warning: _×-isStrictPartialOrder_ was deprecated in v0.15.
Please use ×-isStrictPartialOrder instead."
#-}
_×-isStrictTotalOrder_ = ×-isStrictTotalOrder
{-# WARNING_ON_USAGE _×-isStrictTotalOrder_
"Warning: _×-isStrictTotalOrder_ was deprecated in v0.15.
Please use ×-isStrictTotalOrder instead."
#-}
_×-preorder_ = ×-preorder
{-# WARNING_ON_USAGE _×-preorder_
"Warning: _×-preorder_ was deprecated in v0.15.
Please use ×-preorder instead."
#-}
_×-strictPartialOrder_ = ×-strictPartialOrder
{-# WARNING_ON_USAGE _×-strictPartialOrder_
"Warning: _×-strictPartialOrder_ was deprecated in v0.15.
Please use ×-strictPartialOrder instead."
#-}
_×-strictTotalOrder_ = ×-strictTotalOrder
{-# WARNING_ON_USAGE _×-strictTotalOrder_
"Warning: _×-strictTotalOrder_ was deprecated in v0.15.
Please use ×-strictTotalOrder instead."
#-}
×-≈-respects₂ = ×-respects₂
{-# WARNING_ON_USAGE ×-≈-respects₂
"Warning: ×-≈-respects₂ was deprecated in v0.15.
Please use ×-respects₂ instead."
#-}
|
{
"alphanum_fraction": 0.5509931564,
"avg_line_length": 39.2852459016,
"ext": "agda",
"hexsha": "ca5f13f23d887366dfe7d9dd6a9b297ae2e3226b",
"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/Relation/Binary/Lex/Strict.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/Relation/Binary/Lex/Strict.agda",
"max_line_length": 76,
"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/Relation/Binary/Lex/Strict.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4972,
"size": 11982
}
|
data _×_ (A B : Set) : Set where
_,_ : A → B → A × B
postulate
M : Set → Set
_>>=_ : ∀{A B : Set} → M A → (A → M B) → M B
infixr 1 bind
bind : _
bind = _>>=_
infix 0 id
id : ∀{A : Set} → A → A
id = λ x → x
syntax id x = do x
syntax bind ma (λ x → f) = x ← ma , f
swapM′ : ∀ {A B} → M (A × B) → M (B × A)
swapM′ mAB =
do
(a , b) ← mAB
, return $ b , a
-- Was:
-- An internal error has occurred. Please report this as a bug.
-- Location of the error:
-- src/full/Agda/TypeChecking/Monad/Base.hs:1793
|
{
"alphanum_fraction": 0.5074626866,
"avg_line_length": 17.8666666667,
"ext": "agda",
"hexsha": "6ac5181c4ba31c585384fa9bd278943c1254db2b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Fail/Issue1129b.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Fail/Issue1129b.agda",
"max_line_length": 63,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue1129b.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": 222,
"size": 536
}
|
{-# OPTIONS --cubical --no-import-sorts --allow-unsolved-metas #-}
module Number.Instances.QuoInt where
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Foundations.Logic renaming (inl to inlᵖ; inr to inrᵖ)
open import Cubical.Relation.Nullary.Base renaming (¬_ to ¬ᵗ_)
open import Cubical.Relation.Binary.Base
open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_)
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
open import Cubical.Data.Sigma
open import Cubical.Data.Bool using (not)
open import Cubical.Data.Empty renaming (elim to ⊥-elim; ⊥ to ⊥⊥) -- `⊥` and `elim`
open import Cubical.Foundations.Logic renaming (¬_ to ¬ᵖ_; inl to inlᵖ; inr to inrᵖ)
open import Function.Base using (it; _∋_; _$_)
open import Cubical.HITs.PropositionalTruncation --.Properties
open import Utils using (!_; !!_)
open import MoreLogic.Reasoning
open import MoreLogic.Definitions
open import MoreLogic.Properties
open import MorePropAlgebra.Definitions hiding (_≤''_)
open import MorePropAlgebra.Structures
open import MorePropAlgebra.Bundles
open import MorePropAlgebra.Consequences
open import Number.Structures2
open import Number.Bundles2
open import Number.Instances.Nat using (lemma10''; lemma12'') renaming
( _<_ to _<ⁿ_
; <-irrefl to <ⁿ-irrefl
; <-cotrans to <ⁿ-cotrans
; suc-creates-< to sucⁿ-creates-<ⁿ
; 0<suc to 0<ⁿsuc
)
open import Data.Nat.Base using () renaming
( _⊔_ to maxⁿ
; _⊓_ to minⁿ
; _+_ to _+ⁿ_
)
open import Cubical.HITs.Ints.QuoInt
open import Cubical.HITs.Ints.QuoInt.Properties
open import Cubical.Data.Nat using (suc; zero; ℕ) renaming
( +-comm to +ⁿ-comm )
open import Cubical.Data.Nat.Order using () renaming
( <-trans to <ⁿ-trans
; _<_ to _<ⁿᵗ_
; _≟_ to _≟ⁿ_
; lt to ltⁿ
; gt to gtⁿ
; eq to eqⁿ
; ¬-<-zero to ¬-<ⁿ-zero
)
-- hProp-valued _<_
_<_ : ∀(x y : ℤ) → hProp ℓ-zero
x < y with sign x | sign y
... | spos | spos = abs x <ⁿ abs y
... | spos | sneg = ⊥
... | sneg | spos = ⊤ -- ↯ NOTE: exploiting this specific behaviour of `sign` is not much different from using just `Int`
... | sneg | sneg = abs y <ⁿ abs x
-- _<_ on a representation `λ x → (sign x , abs x)` of QuoInt
_<ʳ_ : ∀(x y : Sign × ℕ) → hProp ℓ-zero
(spos , x) <ʳ (spos , y) = x <ⁿ y
(spos , x) <ʳ (sneg , y) = ⊥
(sneg , x) <ʳ (spos , y) = ⊤
(sneg , x) <ʳ (sneg , y) = y <ⁿ x
<≡<ʳ : ∀ x y → x < y ≡ (sign x , abs x) <ʳ (sign y , abs y)
<≡<ʳ x y with sign x | sign y
... | spos | spos = refl
... | spos | sneg = refl
... | sneg | spos = refl
... | sneg | sneg = refl
-- different version of _<_
_<'_ : ℤ → ℤ → hProp ℓ-zero
pos n₀ <' pos n₁ = n₀ <ⁿ n₁
pos n₀ <' neg n₁ = ⊥
neg 0 <' pos 0 = ⊥
neg 0 <' pos (suc n₁) = ⊤
neg (suc n₀) <' pos 0 = ⊤
neg (suc n₀) <' pos (suc n₁) = ⊤
neg n₀ <' neg n₁ = n₁ <ⁿ n₀
pos n₀ <' posneg j = lemma10'' n₀ j
neg 0 <' posneg j = lemma10'' 0 (~ j)
neg (suc n₀) <' posneg j = lemma12'' n₀ (~ j)
posneg i <' pos 0 = lemma10'' 0 i
posneg i <' pos (suc n₁) = lemma12'' n₁ i
posneg i <' neg n₁ = lemma10'' n₁ (~ i)
posneg i <' posneg j = lemma10'' 0 ((i ∨ j) ∧ ~(i ∧ j))
<'≡< : ∀ x y → x <' y ≡ x < y
<'≡< (pos zero ) (pos zero ) = refl
<'≡< (pos zero ) (pos (suc y)) = refl
<'≡< (pos (suc x)) (pos zero ) = refl
<'≡< (pos (suc x)) (pos (suc y)) = refl
<'≡< (pos zero ) (neg zero ) = sym (lemma10'' _)
<'≡< (pos zero ) (neg (suc y)) = refl
<'≡< (pos (suc x)) (neg zero ) = sym (lemma10'' _)
<'≡< (pos (suc x)) (neg (suc y)) = refl
<'≡< (neg zero ) (pos zero ) = sym (lemma10'' _)
<'≡< (neg zero ) (pos (suc y)) = sym (lemma12'' _)
<'≡< (neg (suc x)) (pos zero ) = refl
<'≡< (neg (suc x)) (pos (suc y)) = refl
<'≡< (neg zero ) (neg zero ) = refl
<'≡< (neg zero ) (neg (suc y)) = lemma10'' _
<'≡< (neg (suc x)) (neg zero ) = lemma12'' _
<'≡< (neg (suc x)) (neg (suc y)) = refl
<'≡< (pos zero ) (posneg i) j = lemma10'' 0 (~ j ∧ i)
<'≡< (pos (suc x)) (posneg i) j = lemma10'' (suc x) (~ j ∧ i)
<'≡< (neg zero ) (posneg i) j = lemma10'' 0 (~ j ∧ ~ i)
<'≡< (neg (suc x)) (posneg i) j = lemma12'' x (j ∨ ~ i)
<'≡< (posneg i) (pos zero ) j = lemma10'' 0 (~ j ∧ i)
<'≡< (posneg i) (pos (suc y)) j = lemma12'' y (~ j ∧ i)
<'≡< (posneg i) (neg zero ) j = lemma10'' 0 (~ j ∧ ~ i)
<'≡< (posneg i) (neg (suc y)) j = lemma10'' (suc y) (j ∨ ~ i)
<'≡< (posneg i) (posneg j ) k = lemma10'' 0 (((i ∨ j) ∧ ~ i ∨ ~ j) ∧ ~ k)
min : ℤ → ℤ → ℤ
min x y with sign x | sign y
... | spos | spos = pos (minⁿ (abs x) (abs y))
... | spos | sneg = y
... | sneg | spos = x
... | sneg | sneg = neg (maxⁿ (abs x) (abs y))
max : ℤ → ℤ → ℤ
max x y with sign x | sign y
... | spos | spos = pos (maxⁿ (abs x) (abs y))
... | spos | sneg = x
... | sneg | spos = y
... | sneg | sneg = neg (minⁿ (abs x) (abs y))
<-irrefl : (a : ℤ) → [ ¬ (a < a) ]
<-irrefl (pos zero) = <ⁿ-irrefl 0
<-irrefl (pos (suc n)) = <ⁿ-irrefl (suc n)
<-irrefl (neg zero) = <ⁿ-irrefl 0
<-irrefl (neg (suc n)) = <ⁿ-irrefl (suc n)
<-irrefl (posneg i) p = <ⁿ-irrefl 0 p
<-trans : (a b c : ℤ) → [ a < b ] → [ b < c ] → [ a < c ]
<-trans a b c a<b b<c with sign a | sign b | sign c
| pathTo⇒ (<≡<ʳ a b) a<b
| pathTo⇒ (<≡<ʳ b c) b<c
| pathTo⇐ (<≡<ʳ a c)
... | spos | spos | spos | a<b' | b<c' | p = p (<ⁿ-trans a<b' b<c')
... | spos | spos | sneg | a<b' | b<c' | p = p b<c'
... | spos | sneg | spos | a<b' | b<c' | p = p (⊥-elim a<b')
... | spos | sneg | sneg | a<b' | b<c' | p = p a<b'
... | sneg | spos | spos | a<b' | b<c' | p = p a<b'
... | sneg | spos | sneg | a<b' | b<c' | p = p (⊥-elim b<c')
... | sneg | sneg | spos | a<b' | b<c' | p = p b<c'
... | sneg | sneg | sneg | a<b' | b<c' | p = p (<ⁿ-trans b<c' a<b')
<-cotrans : (a b : ℤ) → [ a < b ] → (x : ℤ) → [ (a < x) ⊔ (x < b) ]
<-cotrans a b a<b c with sign a , abs a | sign b , abs b | sign c , abs c
| pathTo⇒ (<≡<ʳ a b) a<b
| pathTo⇐ (λ i → (<≡<ʳ a c) i ⊔ (<≡<ʳ c b) i)
... | spos , a' | spos , b' | spos , c' | a<b' | p = p (<ⁿ-cotrans _ _ a<b' c')
... | spos , a' | spos , b' | sneg , c' | a<b' | p = p (inrᵖ tt)
... | sneg , a' | spos , b' | spos , c' | a<b' | p = p (inlᵖ tt)
... | sneg , a' | spos , b' | sneg , c' | a<b' | p = p (inrᵖ tt)
... | sneg , a' | sneg , b' | spos , c' | a<b' | p = p (inlᵖ tt)
... | sneg , a' | sneg , b' | sneg , c' | a<b' | p = p (pathTo⇒ (⊔-comm (b' <ⁿ c') (c' <ⁿ a')) (<ⁿ-cotrans _ _ a<b' c'))
data Trichotomy (m n : ℤ) : Type₀ where
lt : [ m < n ] → Trichotomy m n
eq : m ≡ n → Trichotomy m n
gt : [ n < m ] → Trichotomy m n
record Reveal'_·_is_ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
(f⁻¹ : B → A)
(y : B) (x : A)
: Type ℓ where
eta-equality
constructor [_]ⁱ'
field eq' : x ≡ f⁻¹ y
inspect' : ∀{ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
(f⁻¹ : B → A) (f : A → B) (x : A) → f⁻¹ (f x) ≡ x → Reveal' f⁻¹ · (f x) is x
inspect' f⁻¹ f x p = [ sym p ]ⁱ'
reprℤ : ℤ → Sign × ℕ
reprℤ z = sign z , abs z
reprℤ⁻¹ : Sign × ℕ → ℤ
reprℤ⁻¹ (s , n) = signed s n
reprℤ-id : ∀ z → reprℤ⁻¹ (reprℤ z) ≡ z
reprℤ-id (pos zero ) = refl
reprℤ-id (pos (suc n)) = refl
reprℤ-id (neg zero ) = posneg
reprℤ-id (neg (suc n)) = refl
reprℤ-id (posneg i ) = λ j → posneg (i ∧ j)
inspect-reprℤ : (x : ℤ) → Reveal' reprℤ⁻¹ · (reprℤ x) is x
inspect-reprℤ a = inspect' reprℤ⁻¹ reprℤ a (reprℤ-id a)
-- abs : ℤ → ℕ
-- abs (signed _ n) = n
-- abs (posneg i) = zero
-- NOTE: this would be easier to get from `Int≡QuoInt`
_≟_ : ∀ m n → Trichotomy m n
m ≟ n with reprℤ m | reprℤ n
| inspect-reprℤ m
| inspect-reprℤ n
| abs m ≟ⁿ abs n
| pathTo⇐ (<≡<ʳ m n)
| pathTo⇐ (<≡<ʳ n m)
... | spos , m' | spos , n' | [ m≡ ]ⁱ' | [ n≡ ]ⁱ' | ltⁿ x | p | q = lt (p (transport (λ i → [ abs (m≡ i) <ⁿ abs (n≡ i) ]) x))
... | spos , m' | spos , n' | [ m≡ ]ⁱ' | [ n≡ ]ⁱ' | eqⁿ x | p | q = let m'≡n' = (λ i → abs (m≡ (~ i))) ∙ x ∙ (λ i → abs (n≡ i))
in eq (transport (λ i → (m≡ (~ i)) ≡ (n≡ (~ i))) (λ i → pos (m'≡n' i)))
... | spos , m' | spos , n' | [ m≡ ]ⁱ' | [ n≡ ]ⁱ' | gtⁿ x | p | q = gt (q (transport (λ i → [ abs (n≡ i) <ⁿ abs (m≡ i) ]) x))
... | spos , m' | sneg , n' | [ m≡ ]ⁱ' | [ n≡ ]ⁱ' | o | p | q = gt (q tt)
... | sneg , m' | spos , n' | [ m≡ ]ⁱ' | [ n≡ ]ⁱ' | o | p | q = lt (p tt)
... | sneg , m' | sneg , n' | [ m≡ ]ⁱ' | [ n≡ ]ⁱ' | ltⁿ x | p | q = gt (q (transport (λ i → [ abs (m≡ i) <ⁿ abs (n≡ i) ]) x))
... | sneg , m' | sneg , n' | [ m≡ ]ⁱ' | [ n≡ ]ⁱ' | eqⁿ x | p | q = let m'≡n' = (λ i → abs (m≡ (~ i))) ∙ x ∙ (λ i → abs (n≡ i))
in eq (transport (λ i → (m≡ (~ i)) ≡ (n≡ (~ i))) (λ i → neg (m'≡n' i)))
... | sneg , m' | sneg , n' | [ m≡ ]ⁱ' | [ n≡ ]ⁱ' | gtⁿ x | p | q = lt (p (transport (λ i → [ abs (n≡ i) <ⁿ abs (m≡ i) ]) x))
is-min : (x y z : ℤ) → [ ¬ᵖ (min x y < z) ⇔ ¬ᵖ (x < z) ⊓ ¬ᵖ (y < z) ]
is-min = {! !}
is-max : (x y z : ℤ) → [ ¬ᵖ (z < max x y) ⇔ ¬ᵖ (z < x) ⊓ ¬ᵖ (z < y) ]
is-max = {! !}
sucℤ-pos-suc : ∀ n → sucℤ (pos n) ≡ pos (suc n)
sucℤ-pos-suc x = refl -- holds definitionally
+-preserves-pos : ∀ x y → pos x + pos y ≡ pos (x +ⁿ y)
+-preserves-pos zero y = refl
+-preserves-pos (suc x) zero = transport (λ i → sucℤ (+-comm (pos 0) (pos x) i) ≡ pos (suc (+ⁿ-comm 0 x i))) refl
+-preserves-pos (suc x) (suc y) = λ i → sucℤ (+-preserves-pos x (suc y) i)
-- +-reflects-< : ∀ a b x → [ (a + x) < (b + x) ] → [ a < b ]
-- +-reflects-< a b x a+x<b+x with reprℤ a | reprℤ b | reprℤ x | reprℤ (a + x) | reprℤ (b + x)
-- | inspect-reprℤ a
-- | inspect-reprℤ b
-- | inspect-reprℤ x
-- | inspect-reprℤ (a + x)
-- | inspect-reprℤ (b + x)
-- | pathTo⇒ (<≡<ʳ (a + x) (b + x)) a+x<b+x
-- | pathTo⇐ (<≡<ʳ a b)
-- ... | spos , a' | spos , b' | sx , x' | spos , a+x | spos , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
-- ... | spos , a' | spos , b' | sx , x' | sneg , a+x | spos , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
-- ... | spos , a' | spos , b' | sx , x' | sneg , a+x | sneg , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
-- ... | spos , a' | sneg , b' | sx , x' | spos , a+x | spos , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
-- ... | spos , a' | sneg , b' | sx , x' | sneg , a+x | spos , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
-- ... | spos , a' | sneg , b' | sx , x' | sneg , a+x | sneg , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
-- ... | sneg , a' | spos , b' | sx , x' | spos , a+x | spos , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
-- ... | sneg , a' | spos , b' | sx , x' | sneg , a+x | spos , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
-- ... | sneg , a' | spos , b' | sx , x' | sneg , a+x | sneg , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
-- ... | sneg , a' | sneg , b' | sx , x' | spos , a+x | spos , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
-- ... | sneg , a' | sneg , b' | sx , x' | sneg , a+x | spos , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
-- ... | sneg , a' | sneg , b' | sx , x' | sneg , a+x | sneg , b+x | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | [ x≡ ]ⁱ' | [ a+x≡ ]ⁱ' | [ b+x≡ ]ⁱ' | p | q = q {! !}
+-identity-posˡ : ∀ a → pos zero + a ≡ a
+-identity-posˡ a = refl
+-identity-posʳ : ∀ a → a + pos zero ≡ a
+-identity-posʳ a = +-comm a (pos zero) ∙ +-identity-posˡ a
-- -_ : ℤ → ℤ
-- - signed s n = signed (not s) n
-- - posneg i = posneg (~ i)
--
-- _+_ : ℤ → ℤ → ℤ
-- (signed _ zero) + n = n
-- (posneg _) + n = n
-- (pos (suc m)) + n = sucℤ (pos m + n)
-- (neg (suc m)) + n = predℤ (neg m + n)
pos≡-neg : ∀ n → pos n ≡ - neg n
pos≡-neg n = refl
-pos≡neg : ∀ n → - pos n ≡ neg n
-pos≡neg n = refl
suc-neg-suc≡neg : ∀ n → sucℤ (neg (suc n)) ≡ neg n
suc-neg-suc≡neg n = refl
pos+neg≡0 : ∀ n → pos n + neg n ≡ 0
pos+neg≡0 zero = sym posneg
pos+neg≡0 (suc n) = transport (
pos n + neg n ≡ pos 0 ≡⟨ (λ i → +-comm (pos n) (neg n) i ≡ pos 0) ⟩
neg n + pos n ≡ pos 0 ≡⟨ refl ⟩
(sucℤ (neg (suc n)) + pos n) ≡ pos 0 ≡⟨ (λ i → sucℤ-+ˡ (neg (suc n)) (pos n) (~ i) ≡ pos 0) ⟩
sucℤ (neg (suc n) + pos n) ≡ pos 0 ≡⟨ (λ i → sucℤ (+-comm (pos n) (neg (suc n)) (~ i)) ≡ pos 0) ⟩
sucℤ (pos n + neg (suc n)) ≡ pos 0 ∎) (pos+neg≡0 n)
neg+pos≡0 : ∀ n → neg n + pos n ≡ 0
neg+pos≡0 n = +-comm (neg n) (pos n) ∙ pos+neg≡0 n
+-inverseʳ : ∀ a → a + (- a) ≡ 0
+-inverseʳ a with reprℤ a | inspect-reprℤ a
... | spos , a' | [ a≡ ]ⁱ' = transport (λ i → a≡ (~ i) + (- a≡ (~ i)) ≡ pos 0) (pos+neg≡0 a')
... | sneg , a' | [ a≡ ]ⁱ' = transport (λ i → a≡ (~ i) + (- a≡ (~ i)) ≡ pos 0) (neg+pos≡0 a')
+-inverseˡ : ∀ a → (- a) + a ≡ 0
+-inverseˡ a = +-comm (- a) a ∙ +-inverseʳ a
+-inverse : (x : ℤ) → (x + (- x) ≡ pos 0) × ((- x) + x ≡ pos 0)
+-inverse x .fst = +-inverseʳ x
+-inverse x .snd = +-inverseˡ x
-- -on-reprℤ : ∀ a → (sign (- a) , abs (- a)) ≡ (not (sign a) , abs a)
-- -on-reprℤ (pos zero) = {! !} -- Goal (spos , 0) ≡ (sneg , 0)
-- -on-reprℤ (pos (suc n)) = {! !}
-- -on-reprℤ (neg n) = {! !}
-- -on-reprℤ (posneg i) = {! !}
-flips-< : ∀ a b → [ a < b ] → [ (- b) < (- a) ]
-flips-< a b a<b with reprℤ a | reprℤ b
| inspect-reprℤ a
| inspect-reprℤ b
| pathTo⇒ (<≡<ʳ a b) a<b
| pathTo⇐ (<≡<ʳ (- b) (- a))
... | spos , zero | spos , zero | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r p)
... | sneg , zero | spos , zero | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r (⊥-elim $ <-irrefl a $ subst (λ p → [ a < p ]) (b≡ ∙ posneg ∙ sym a≡) a<b))
... | sneg , zero | sneg , zero | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r p)
... | spos , zero | spos , suc b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r tt)
... | sneg , zero | spos , suc b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r tt)
... | sneg , zero | sneg , suc b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r p)
... | spos , suc a' | spos , zero | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r (¬-<ⁿ-zero p))
... | sneg , suc a' | spos , zero | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r (0<ⁿsuc _))
... | sneg , suc a' | sneg , zero | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r (0<ⁿsuc _))
... | spos , suc a' | spos , suc b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r p)
... | sneg , suc a' | spos , suc b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r tt)
... | sneg , suc a' | sneg , suc b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (sym λ i → fst ((sign (- b≡ i) , abs (- b≡ i)) <ʳ (sign (- a≡ i) , abs (- a≡ i)))) in q (r p)
-- suc-reflects-< : ∀ a b → [ sucℤ a < sucℤ b ] → [ a < b ]
-- suc-reflects-< (pos zero) (pos zero) sa<sb = ⊥-elim $ <-irrefl (pos 1) sa<sb
-- suc-reflects-< (pos zero) (pos (suc n₁)) sa<sb = sucⁿ-creates-<ⁿ 0 (suc n₁) .snd sa<sb
-- suc-reflects-< (pos zero) (neg zero) sa<sb = {! !}
-- suc-reflects-< (pos zero) (neg (suc n₁)) sa<sb = {! !}
-- suc-reflects-< (pos (suc n₀)) (pos zero) sa<sb = {! !}
-- suc-reflects-< (pos (suc n₀)) (pos (suc n₁)) sa<sb = {! !}
-- suc-reflects-< (pos (suc n₀)) (neg zero) sa<sb = {! !}
-- suc-reflects-< (pos (suc n₀)) (neg (suc n₁)) sa<sb = {! !}
-- suc-reflects-< (neg zero) (pos zero) sa<sb = {! !}
-- suc-reflects-< (neg zero) (pos (suc n₁)) sa<sb = {! !}
-- suc-reflects-< (neg zero) (neg zero) sa<sb = {! !}
-- suc-reflects-< (neg zero) (neg (suc n₁)) sa<sb = {! !}
-- suc-reflects-< (neg (suc n₀)) (pos zero) sa<sb = {! !}
-- suc-reflects-< (neg (suc n₀)) (pos (suc n₁)) sa<sb = {! !}
-- suc-reflects-< (neg (suc n₀)) (neg zero) sa<sb = {! !}
-- suc-reflects-< (neg (suc n₀)) (neg (suc n₁)) sa<sb = {! !}
-- suc-reflects-< (signed s₀ n₀) (posneg j) sa<sb = {! !}
-- suc-reflects-< (posneg i) (signed s₁ n₁) sa<sb = {! !}
-- suc-reflects-< (posneg i) (posneg j) sa<sb = {! !}
suc-reflects-< : ∀ a b → [ sucℤ a < sucℤ b ] → [ a < b ]
suc-reflects-< a b sa<sb with reprℤ a | reprℤ b
| inspect-reprℤ a
| inspect-reprℤ b
| pathTo⇒ (<≡<ʳ (sucℤ a) (sucℤ b)) sa<sb
| pathTo⇐ (<≡<ʳ a b)
... | spos , a' | spos , b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (λ i → [ (sign (sucℤ (a≡ i)) , abs (sucℤ (a≡ i))) <ʳ (sign (sucℤ (b≡ i)) , abs (sucℤ (b≡ i))) ]) p
in q (sucⁿ-creates-<ⁿ a' b' .snd r)
-- ... | spos , a' | sneg , b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (λ i → [ (sign (sucℤ (a≡ i)) , abs (sucℤ (a≡ i))) <ʳ (sign (sucℤ (b≡ i)) , abs (sucℤ (b≡ i))) ]) p
-- in q {! !}
... | spos , a' | sneg , 0 | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (λ i → [ (sign (sucℤ (a≡ i)) , abs (sucℤ (a≡ i))) <ʳ (sign (sucℤ (b≡ i)) , abs (sucℤ (b≡ i))) ]) p
in q (¬-<ⁿ-zero $ sucⁿ-creates-<ⁿ a' 0 .snd r)
... | spos , a' | sneg , suc 0 | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (λ i → [ (sign (sucℤ (a≡ i)) , abs (sucℤ (a≡ i))) <ʳ (sign (sucℤ (b≡ i)) , abs (sucℤ (b≡ i))) ]) p
in q (¬-<ⁿ-zero r)
... | spos , a' | sneg , suc (suc b') | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (λ i → [ (sign (sucℤ (a≡ i)) , abs (sucℤ (a≡ i))) <ʳ (sign (sucℤ (b≡ i)) , abs (sucℤ (b≡ i))) ]) p
in q r
... | sneg , a' | spos , b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = q tt
... | sneg , zero | sneg , zero | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = q (⊥-elim $ <-irrefl (sucℤ a) $ subst (λ p → [ sucℤ a < sucℤ p ]) (b≡ ∙ sym a≡) sa<sb)
... | sneg , zero | sneg , suc b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = q {! !}
... | sneg , suc a' | sneg , zero | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = q (0<ⁿsuc _)
... | sneg , suc a' | sneg , suc b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (λ i → [ (sign (sucℤ (a≡ i)) , abs (sucℤ (a≡ i))) <ʳ (sign (sucℤ (b≡ i)) , abs (sucℤ (b≡ i))) ]) p
in q {! !}
-- ... | sneg , a' | sneg , b' | [ a≡ ]ⁱ' | [ b≡ ]ⁱ' | p | q = let r = transport (λ i → [ (- sucℤ (b≡ i)) < (- sucℤ (a≡ i)) ] )
-- in q {! sa<sb !}
-- [ (a + pos (suc n)) < (b + pos (suc n)) ] →
+-reflects-< : ∀ a b x → [ (a + x) < (b + x) ] → [ a < b ]
+-reflects-< a b (pos (suc n)) a+x<b+x = +-reflects-< a b (pos n) {! !}
+-reflects-< a b (neg (suc n)) a+x<b+x = {! !}
-- +-reflects-< a b (pos zero) a+x<b+x = pathTo⇒ (λ i → +-identity-posʳ a i < +-identity-posʳ b i) a+x<b+x
+-reflects-< a b (pos zero) a+x<b+x = pathTo⇒ (λ i → +-comm a (pos zero) i < +-comm b (pos zero) i) a+x<b+x
+-reflects-< a b (neg zero) a+x<b+x = pathTo⇒ (λ i → +-comm a (neg zero) i < +-comm b (neg zero) i) a+x<b+x
+-reflects-< a b (posneg i) a+x<b+x = pathTo⇒ (λ j → +-comm a (posneg i) j < +-comm b (posneg i) j) a+x<b+x
+-<-ext : (w x y z : ℤ) → [ (w + x) < (y + z) ] → [ (w < y) ⊔ (x < z) ]
+-<-ext w x y z r with w ≟ y | x ≟ z
... | lt w<y | q = inlᵖ w<y
... | eq w≡y | q = inrᵖ {! +-injˡ y x z !}
... | gt y<w | q = {! !}
·-preserves-< : (x y z : ℤ) → [ 0 < z ] → [ x < y ] → [ (x * z) < (y * z) ]
·-preserves-< = {! !}
+-Semigroup : [ isSemigroup _+_ ]
+-Semigroup .IsSemigroup.is-set = isSetℤ
+-Semigroup .IsSemigroup.is-assoc = +-assoc
·-Semigroup : [ isSemigroup _*_ ]
·-Semigroup .IsSemigroup.is-set = isSetℤ
·-Semigroup .IsSemigroup.is-assoc = *-assoc
+-Monoid : [ isMonoid 0 _+_ ]
+-Monoid .IsMonoid.is-Semigroup = +-Semigroup
+-Monoid .IsMonoid.is-identity x = +-identityʳ x , refl
·-Monoid : [ isMonoid 1 _*_ ]
·-Monoid .IsMonoid.is-Semigroup = ·-Semigroup
·-Monoid .IsMonoid.is-identity x = *-identityʳ x , *-identityˡ x
is-Semiring : [ isSemiring 0 1 _+_ _*_ ]
is-Semiring .IsSemiring.+-Monoid = +-Monoid
is-Semiring .IsSemiring.·-Monoid = ·-Monoid
is-Semiring .IsSemiring.+-comm = +-comm
is-Semiring .IsSemiring.is-dist x y z = sym (*-distribˡ x y z) , sym (*-distribʳ x y z)
is-CommSemiring : [ isCommSemiring 0 1 _+_ _*_ ]
is-CommSemiring .IsCommSemiring.is-Semiring = is-Semiring
is-CommSemiring .IsCommSemiring.·-comm = *-comm
<-StrictLinearOrder : [ isStrictLinearOrder _<_ ]
<-StrictLinearOrder .IsStrictLinearOrder.is-irrefl = <-irrefl
<-StrictLinearOrder .IsStrictLinearOrder.is-trans a b c = <-trans a b c
<-StrictLinearOrder .IsStrictLinearOrder.is-tricho a b with a ≟ b
... | lt a<b = inl (inl a<b)
... | eq a≡b = inr ∣ a≡b ∣
... | gt b<a = inl (inr b<a)
≤-isLattice : [ isLattice (λ x y → ¬ᵖ (y < x)) min max ]
≤-isLattice .IsLattice.≤-PartialOrder = linearorder⇒partialorder _ (≤'-isLinearOrder <-StrictLinearOrder)
≤-isLattice .IsLattice.is-min = is-min
≤-isLattice .IsLattice.is-max = is-max
is-LinearlyOrderedCommSemiring : [ isLinearlyOrderedCommSemiring 0 1 _+_ _*_ _<_ min max ]
is-LinearlyOrderedCommSemiring .IsLinearlyOrderedCommSemiring.is-CommSemiring = is-CommSemiring
is-LinearlyOrderedCommSemiring .IsLinearlyOrderedCommSemiring.<-StrictLinearOrder = <-StrictLinearOrder
is-LinearlyOrderedCommSemiring .IsLinearlyOrderedCommSemiring.≤-isLattice = ≤-isLattice
is-LinearlyOrderedCommSemiring .IsLinearlyOrderedCommSemiring.+-<-ext = +-<-ext
is-LinearlyOrderedCommSemiring .IsLinearlyOrderedCommSemiring.·-preserves-< = ·-preserves-<
is-LinearlyOrderedCommRing : [ isLinearlyOrderedCommRing 0 1 _+_ _*_ -_ _<_ min max ]
is-LinearlyOrderedCommRing .IsLinearlyOrderedCommRing.is-LinearlyOrderedCommSemiring = is-LinearlyOrderedCommSemiring
is-LinearlyOrderedCommRing .IsLinearlyOrderedCommRing.+-inverse = +-inverse
ℤbundle : LinearlyOrderedCommRing {ℓ-zero} {ℓ-zero}
ℤbundle .LinearlyOrderedCommRing.Carrier = ℤ
ℤbundle .LinearlyOrderedCommRing.0f = 0
ℤbundle .LinearlyOrderedCommRing.1f = 1
ℤbundle .LinearlyOrderedCommRing._+_ = _+_
ℤbundle .LinearlyOrderedCommRing._·_ = _*_
ℤbundle .LinearlyOrderedCommRing.-_ = -_
ℤbundle .LinearlyOrderedCommRing.min = min
ℤbundle .LinearlyOrderedCommRing.max = max
ℤbundle .LinearlyOrderedCommRing._<_ = _<_
ℤbundle .LinearlyOrderedCommRing.is-LinearlyOrderedCommRing = is-LinearlyOrderedCommRing
|
{
"alphanum_fraction": 0.4755294912,
"avg_line_length": 51.192224622,
"ext": "agda",
"hexsha": "9f9c3fc4d1c76659e5a1a44613d5a02445596df6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/Number/Instances/QuoIntUnfinished.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/Number/Instances/QuoIntUnfinished.agda",
"max_line_length": 252,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/Number/Instances/QuoIntUnfinished.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 10872,
"size": 23702
}
|
open import Oscar.Prelude
open import Oscar.Data.Maybe
open import Oscar.Class
open import Oscar.Class.Fmap
open import Oscar.Class.Pure
open import Oscar.Class.Apply
open import Oscar.Class.Bind
open import Oscar.Class.IsFunctor
open import Oscar.Class.IsPrefunctor
open import Oscar.Class.IsPrecategory
open import Oscar.Class.IsCategory
import Oscar.Property.Category.Function
import Oscar.Class.Reflexivity.Function
import Oscar.Class.Transextensionality.Proposequality
module Oscar.Property.Monad.Maybe where
instance
𝓕mapMaybe : ∀ {𝔬₁ 𝔬₂} → 𝓕map Maybe 𝔬₁ 𝔬₂
𝓕mapMaybe .𝓕map.fmap′ f ∅ = ∅
𝓕mapMaybe .𝓕map.fmap′ f (↑ x) = ↑ f x
𝓟ureMaybe : ∀ {𝔬} → 𝓟ure (Maybe {𝔬})
𝓟ureMaybe .𝓟ure.pure = ↑_
𝓐pplyMaybe : ∀ {𝔬₁ 𝔬₂} → 𝓐pply Maybe 𝔬₁ 𝔬₂
𝓐pplyMaybe .𝓐pply.apply ∅ x = ∅
𝓐pplyMaybe .𝓐pply.apply (↑ f) x = fmap′ f x
𝓑indMaybe : ∀ {𝔬₁ 𝔬₂} → 𝓑ind Maybe 𝔬₁ 𝔬₂
𝓑indMaybe .𝓑ind.bind ∅ _ = ∅
𝓑indMaybe .𝓑ind.bind (↑ x) f = f x
{-
FmapMaybe : ∀ {𝔬} → Fmap (Maybe {𝔬})
FmapMaybe .Fmap.fmap = fmap′
FmapMaybe .Fmap.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`IsPrecategory₁ = {!!}
FmapMaybe .Fmap.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`IsPrecategory₂ = {!!}
FmapMaybe .Fmap.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`𝓢urjtranscommutativity = {!!}
FmapMaybe .Fmap.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`𝓢urjextensionality = {!!}
FmapMaybe .Fmap.isFunctor .IsFunctor.`IsCategory₁ = !
FmapMaybe .Fmap.isFunctor .IsFunctor.`IsCategory₂ .IsCategory.`IsPrecategory .IsPrecategory.`𝓣ransextensionality = {!!!}
FmapMaybe .Fmap.isFunctor .IsFunctor.`IsCategory₂ .IsCategory.`IsPrecategory .IsPrecategory.`𝓣ransassociativity = {!!}
FmapMaybe .Fmap.isFunctor .IsFunctor.`IsCategory₂ .IsCategory.`𝓣ransleftidentity = {!!}
FmapMaybe .Fmap.isFunctor .IsFunctor.`IsCategory₂ .IsCategory.`𝓣ransrightidentity = {!!}
FmapMaybe .Fmap.isFunctor .IsFunctor.`𝒮urjidentity = {!!}
-}
|
{
"alphanum_fraction": 0.7429013939,
"avg_line_length": 39.5306122449,
"ext": "agda",
"hexsha": "c952cb6730c604a43f7ce82fa58145b2129049c7",
"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/Property/Monad/Maybe.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/Property/Monad/Maybe.agda",
"max_line_length": 122,
"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/Property/Monad/Maybe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 746,
"size": 1937
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module homotopy.FiberOfWedgeToProduct {i j} (X : Ptd i) (Y : Ptd j) where
private
X⊙×Y = X ⊙× Y
private
to-glue-template : ∀ {x y}
{p p' : (pt X , pt Y) == (x , y)}
(q : p == p' [ (λ w → ∨-to-× w == (x , y)) ↓ wglue ])
→ jright (snd×= p) == jleft (fst×= p') :> (pt X == x) * (pt Y == y)
to-glue-template {p = p} {p' = p'} q =
! (jglue (fst×= p) (snd×= p)) ∙' ap (jleft ∘ fst×=) (↓-∨to×=cst-out q)
module To (x : de⊙ X) (y : de⊙ Y) = WedgeElim
{P = λ x∨y → ∨-to-× x∨y == (x , y) → (pt X == x) * (pt Y == y)}
(λ x p → jright (snd×= p)) (λ y p → jleft (fst×= p))
(↓-app→cst-in to-glue-template)
to : ∀ x y → hfiber ∨-to-× (x , y) → (pt X == x) * (pt Y == y)
to x y = uncurry (To.f x y)
private
-- the only needed β-rule for [to] applied to [wglue].
abstract
to-glue-idp-β : ap (to (pt X) (pt Y)) (pair= wglue (↓-∨to×=cst-in idp))
== ! (jglue idp idp)
to-glue-idp-β =
split-ap2 (to _ _) wglue (↓-∨to×=cst-in idp)
∙ ap (λ p → ↓-app→cst-out p (↓-∨to×=cst-in idp)) (To.glue-β _ _)
∙ ↓-app→cst-β to-glue-template (↓-∨to×=cst-in idp)
∙ ap (λ p → ! (jglue idp idp) ∙' ap (left ∘ fst×=) p) (↓-∨to×=cst-β idp)
private
from-glue-template : ∀ {x y} (x-path : pt X == x) (y-path : pt Y == y)
→ (winr y , pair×= x-path idp) == (winl x , pair×= idp y-path)
:> hfiber ∨-to-× (x , y)
from-glue-template idp idp = ! $ pair= wglue (↓-∨to×=cst-in idp)
module From (x : de⊙ X) (y : de⊙ Y) = JoinRec
{C = hfiber ∨-to-× (x , y)}
(λ x-path → winr y , pair×= x-path idp)
(λ y-path → winl x , pair×= idp y-path)
from-glue-template
from : ∀ x y → (pt X == x) * (pt Y == y) → hfiber ∨-to-× (x , y)
from = From.f
private
abstract
to-from-glue-template : ∀ {x y} (x-path : pt X == x) (y-path : pt Y == y)
→ ap left (fst×=-β x-path idp) == ap right (snd×=-β idp y-path)
[ (λ j → to x y (from x y j) == j) ↓ jglue x-path y-path ]
to-from-glue-template idp idp = ↓-∘=idf-in' (to _ _) (from _ _) $
ap (ap (to _ _)) (From.glue-β _ _ idp idp)
∙ ap-! (to _ _) (pair= wglue (↓-∨to×=cst-in idp))
∙ ap ! to-glue-idp-β
∙ !-! (jglue idp idp)
to-from : ∀ x y j → to x y (from x y j) == j
to-from x y = Join-elim
{P = λ j → to x y (from x y j) == j}
(λ x-path → ap left (fst×=-β x-path idp))
(λ y-path → ap right (snd×=-β idp y-path))
to-from-glue-template
private
abstract
from-to-winl-template : ∀ {x x' y} (xy-path : (x' , pt Y) == (x , y))
→ (winl x , pair×= idp (snd×= xy-path)) == (winl x' , xy-path)
:> hfiber (∨-to-× {X = X} {Y = Y}) (x , y)
from-to-winl-template idp = idp
from-to-winr-template : ∀ {x y y'} (xy-path : (pt X , y') == (x , y))
→ (winr y , pair×= (fst×= xy-path) idp) == (winr y' , xy-path)
:> hfiber (∨-to-× {X = X} {Y = Y}) (x , y)
from-to-winr-template idp = idp
-- this version enables path induction on [q] which
-- turns *both* [p] and [p'] into [idp]. yay!
from-to-glue-template' : ∀ {x y}
(p p' : (pt X , pt Y) == (x , y)) (q : p == p')
→ from-to-winl-template p == from-to-winr-template p'
[ (λ xy → from x y (to x y xy) == xy) ↓ pair= wglue (↓-∨to×=cst-in q) ]
from-to-glue-template' idp .idp idp =
↓-∘=idf-in' (from (pt X) (pt Y)) (to (pt X) (pt Y)) $
ap (ap (from _ _)) to-glue-idp-β
∙ ap-! (from _ _) (jglue idp idp)
∙ ap ! (From.glue-β _ _ idp idp)
∙ !-! (pair= wglue (↓-∨to×=cst-in idp))
from-to-glue-template : ∀ {x y}
(p p' : (pt X , pt Y) == (x , y))
(q : p == p' [ (λ w → ∨-to-× w == (x , y)) ↓ wglue ])
→ from-to-winl-template p == from-to-winr-template p'
[ (λ xy → from x y (to x y xy) == xy) ↓ pair= wglue q ]
from-to-glue-template {x} {y} p p' q =
transport
(λ q →
from-to-winl-template p == from-to-winr-template p'
[ (λ xy → from x y (to x y xy) == xy) ↓ pair= wglue q ])
(↓-∨to×=cst-η q)
(from-to-glue-template' p p' (↓-∨to×=cst-out q))
from-to : ∀ x y hf → from x y (to x y hf) == hf
from-to x y = uncurry $ Wedge-elim
{P = λ w → ∀ p → from x y (To.f x y w p) == (w , p)}
(λ x → from-to-winl-template)
(λ y → from-to-winr-template)
(↓-Π-in λ {p} {p'} → from-to-glue-template p p')
fiber-thm : ∀ x y → hfiber ∨-to-× (x , y) ≃ (pt X == x) * (pt Y == y)
fiber-thm x y = equiv (to x y) (from x y) (to-from x y) (from-to x y)
|
{
"alphanum_fraction": 0.4595455511,
"avg_line_length": 40.2478632479,
"ext": "agda",
"hexsha": "9e979386e976693ed0b7d507111f4b877a023a6c",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/FiberOfWedgeToProduct.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/FiberOfWedgeToProduct.agda",
"max_line_length": 81,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/FiberOfWedgeToProduct.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 1963,
"size": 4709
}
|
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Algorithms.List.Sort.IsSort {c l₁ l₂} (DTO : DecTotalOrder c l₁ l₂) where
-- agda-stdlib
open import Level
import Relation.Binary.Reasoning.Setoid as SetoidReasoning
open import Data.List
import Data.List.Relation.Binary.Equality.Setoid as SetoidEquality
import Data.List.Relation.Binary.Permutation.Setoid as PermutationSetoid
open import Data.List.Relation.Unary.Linked as Linked
-- agda-misc
open import Algorithms.List.Sort.Common DTO
import Algorithms.List.Sort.Insertion as I
import Algorithms.List.Sort.Insertion.Properties as Iₚ
open DecTotalOrder DTO renaming (Carrier to A)
open PermutationSetoid Eq.setoid
open SetoidEquality Eq.setoid
open I.InsertionSortOperation _≤?_ renaming (sort to Isort)
record IsSort (sort : List A → List A) : Set (c ⊔ l₁ ⊔ l₂) where
field
sorted : (xs : List A) → Sorted (sort xs)
perm : (xs : List A) → sort xs ↭ xs
open Iₚ DTO
sort-Isort : ∀ xs → sort xs ≋ Isort xs
sort-Isort xs =
Sorted-unique (↭-trans (perm xs) (↭-sym (sort-permutation xs)))
(sorted xs)
(sort-Sorted xs)
isSort-unique : ∀ {sort₁ sort₂ : List A → List A} →
IsSort sort₁ → IsSort sort₂ → ∀ xs → sort₁ xs ≋ sort₂ xs
isSort-unique {sort₁} {sort₂} sort₁-isSort sort₂-isSort xs = begin
sort₁ xs ≈⟨ IsSort.sort-Isort sort₁-isSort xs ⟩
Isort xs ≈⟨ ≋-sym (IsSort.sort-Isort sort₂-isSort xs) ⟩
sort₂ xs ∎
where open SetoidReasoning ≋-setoid
|
{
"alphanum_fraction": 0.7007926024,
"avg_line_length": 33.6444444444,
"ext": "agda",
"hexsha": "a7416b778b084e2084137a83ae00b0a5d6e3c408",
"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": "Algorithms/List/Sort/IsSort.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": "Algorithms/List/Sort/IsSort.agda",
"max_line_length": 80,
"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": "Algorithms/List/Sort/IsSort.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": 462,
"size": 1514
}
|
module WithInParModule (A : Set) where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Bool : Set where
true : Bool
false : Bool
isZero : Nat -> Bool
isZero zero = true
isZero (suc _) = false
f : Nat -> Nat
f n with isZero n
f n | true = zero
f n | false = suc zero
g : Nat -> Nat
g zero = zero
g (suc n) with g n
g (suc n) | zero = n
g (suc n) | suc _ = n
-- Andreas, 2014-11-06 outlawing with on module parameter.
-- The following will trigger an error:
-- data T : Set where
-- tt : T
-- module A (x : T) where
-- h : T
-- h with x -- illegal!
-- h | y = y
-- postulate
-- C : T -> Set
-- test : C (A.h tt) -> C tt
-- test x = x
|
{
"alphanum_fraction": 0.5692995529,
"avg_line_length": 15.25,
"ext": "agda",
"hexsha": "f1995812a43d58d7e73c82e0978e2f14cd3131cf",
"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/WithInParModule.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/WithInParModule.agda",
"max_line_length": 58,
"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/WithInParModule.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": 244,
"size": 671
}
|
open import Level using (_⊔_)
open import Function using (_$_)
open import Data.Empty using (⊥)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Negation using (contradiction)
open import Relation.Binary using (Rel; Reflexive; Transitive; Antisymmetric; _Respects₂_; _Respectsʳ_; _Respectsˡ_; Symmetric; Decidable; Irrelevant)
open import Relation.Binary.PropositionalEquality using (_≡_) renaming (refl to ≡-refl; cong to ≡-cong)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Algebra.Bundles using (CommutativeSemiring)
module AKS.Algebra.Divisibility {c ℓ} (S : CommutativeSemiring c ℓ) where
open import AKS.Nat using (ℕ; _<_; <-irrelevant)
open import AKS.Nat.WellFounded using (Acc; acc; <-well-founded)
open CommutativeSemiring S using (_+_; _*_; 0#; 1#) renaming (Carrier to C)
open CommutativeSemiring S using (_≈_; setoid; refl; sym; trans)
open import Relation.Binary.Reasoning.Setoid setoid
open CommutativeSemiring S using (+-cong; +-congˡ; +-congʳ; +-identityʳ; +-comm; +-assoc)
open CommutativeSemiring S using (*-assoc; *-identityˡ; *-identityʳ; *-congˡ; *-congʳ; zeroˡ; zeroʳ; distribʳ; distribˡ; *-comm)
open import Algebra.Core using (Op₂)
open import Algebra.Definitions _≈_ using (Commutative; Congruent₂; LeftCongruent; RightCongruent)
open import AKS.Algebra.Structures C _≈_ using (module Divisibility; module Modulus)
open Divisibility _*_ using (_∣_; _∤_; divides; IsGCD) public
infix 4 _≉_
_≉_ : Rel C ℓ
x ≉ y = x ≈ y → ⊥
∣-refl : Reflexive _∣_
∣-refl {x} = divides 1# (sym (*-identityˡ x))
∣-trans : Transitive _∣_
∣-trans {x} {y} {z} (divides q₁ y≈q₁*x) (divides q₂ z≈q₂*y) = divides (q₂ * q₁) $ begin
z ≈⟨ z≈q₂*y ⟩
q₂ * y ≈⟨ *-congˡ y≈q₁*x ⟩
q₂ * (q₁ * x) ≈⟨ sym (*-assoc q₂ q₁ x) ⟩
(q₂ * q₁) * x ∎
∣-respʳ : _∣_ Respectsʳ _≈_
∣-respʳ {y} {x₁} {x₂} x₁≈x₂ (divides q x₁≈q*y) = divides q $ begin
x₂ ≈⟨ sym x₁≈x₂ ⟩
x₁ ≈⟨ x₁≈q*y ⟩
q * y ∎
∣-respˡ : _∣_ Respectsˡ _≈_
∣-respˡ {y} {x₁} {x₂} x₁≈x₂ (divides q y≈q*x₁) = divides q $ begin
y ≈⟨ y≈q*x₁ ⟩
q * x₁ ≈⟨ *-congˡ x₁≈x₂ ⟩
q * x₂ ∎
∣-resp : _∣_ Respects₂ _≈_
∣-resp = ∣-respʳ , ∣-respˡ
infix 10 1∣_ _∣0
1∣_ : ∀ n → 1# ∣ n
1∣ n = divides n (sym (*-identityʳ n))
_∣0 : ∀ n → n ∣ 0#
n ∣0 = divides 0# (sym (zeroˡ n))
0∣n⇒n≈0 : ∀ {n} → 0# ∣ n → n ≈ 0#
0∣n⇒n≈0 {n} (divides q n≈q*0) = begin
n ≈⟨ n≈q*0 ⟩
q * 0# ≈⟨ zeroʳ q ⟩
0# ∎
∣n⇒∣m*n : ∀ i n m → i ∣ n → i ∣ m * n
∣n⇒∣m*n i n m (divides q n≈q*i) = divides (m * q) $ begin
m * n ≈⟨ *-congˡ n≈q*i ⟩
m * (q * i) ≈⟨ sym (*-assoc m q i) ⟩
m * q * i ∎
∣n⇒∣n*m : ∀ i n m → i ∣ n → i ∣ n * m
∣n⇒∣n*m i n m i∣n = ∣-respʳ (*-comm m n) (∣n⇒∣m*n i n m i∣n)
module GCD {gcd : Op₂ C} (isGCD : IsGCD gcd) (∣-antisym : Antisymmetric _≈_ _∣_) where
open IsGCD isGCD
∣1⇒≈1 : ∀ {n} → n ∣ 1# → n ≈ 1#
∣1⇒≈1 {n} n∣1 = ∣-antisym n∣1 (1∣ n)
gcd[0,0]≈0 : gcd 0# 0# ≈ 0#
gcd[0,0]≈0 = ∣-antisym (gcd 0# 0# ∣0) (gcd-greatest ∣-refl ∣-refl)
gcd-comm : Commutative gcd
gcd-comm a b = ∣-antisym
(gcd-greatest (gcd[a,b]∣b a b) (gcd[a,b]∣a a b))
(gcd-greatest (gcd[a,b]∣b b a) (gcd[a,b]∣a b a))
gcd[0,a]≈a : ∀ a → gcd 0# a ≈ a
gcd[0,a]≈a a = ∣-antisym (gcd[a,b]∣b 0# a) (gcd-greatest (a ∣0) ∣-refl)
gcd[a,0]≈a : ∀ a → gcd a 0# ≈ a
gcd[a,0]≈a a = ∣-antisym (gcd[a,b]∣a a 0#) (gcd-greatest ∣-refl (a ∣0))
gcd[0,a]≈1⇒a≈1 : ∀ a → gcd 0# a ≈ 1# → a ≈ 1#
gcd[0,a]≈1⇒a≈1 a gcd[0,a]≈1 = ∣1⇒≈1 (∣-respʳ gcd[0,a]≈1 (gcd-greatest (a ∣0) ∣-refl))
gcd[a,0]≈1⇒a≈1 : ∀ a → gcd a 0# ≈ 1# → a ≈ 1#
gcd[a,0]≈1⇒a≈1 a gcd[a,0]≈1 = ∣1⇒≈1 (∣-respʳ gcd[a,0]≈1 (gcd-greatest ∣-refl (a ∣0)))
gcd[a,b]≈0⇒a≈0 : ∀ {a b} → gcd a b ≈ 0# → a ≈ 0#
gcd[a,b]≈0⇒a≈0 {a} {b} gcd[a,b]≈0 = 0∣n⇒n≈0 (∣-respˡ gcd[a,b]≈0 (gcd[a,b]∣a a b))
gcd[a,b]≈0⇒b≈0 : ∀ {a b} → gcd a b ≈ 0# → b ≈ 0#
gcd[a,b]≈0⇒b≈0 {a} {b} gcd[a,b]≈0 = 0∣n⇒n≈0 (∣-respˡ gcd[a,b]≈0 (gcd[a,b]∣b a b))
gcd[a,1]≈1 : ∀ a → gcd a 1# ≈ 1#
gcd[a,1]≈1 a = ∣-antisym (gcd[a,b]∣b a 1#) (gcd-greatest (1∣ a) ∣-refl)
gcd[1,a]≈1 : ∀ a → gcd 1# a ≈ 1#
gcd[1,a]≈1 a = ∣-antisym (gcd[a,b]∣a 1# a) (gcd-greatest ∣-refl (1∣ a))
-- gcd[d*a,d*b]≈d*gcd[a,b] : ∀ a b d → gcd (d * a) (d * b) ≈ d * gcd a b
-- gcd[d*a,d*b]≈d*gcd[a,b] = ?
a≉0⇒gcd[a,b]≉0 : ∀ a b → a ≉ 0# → gcd a b ≉ 0#
a≉0⇒gcd[a,b]≉0 a b a≉0 gcd[a,b]≈0 = a≉0 (gcd[a,b]≈0⇒a≈0 gcd[a,b]≈0)
b≉0⇒gcd[a,b]≉0 : ∀ a b → b ≉ 0# → gcd a b ≉ 0#
b≉0⇒gcd[a,b]≉0 a b b≉0 gcd[a,b]≈0 = b≉0 (gcd[a,b]≈0⇒b≈0 gcd[a,b]≈0)
gcd-cong : Congruent₂ gcd
gcd-cong {a} {b} {c} {d} a≈b c≈d = ∣-antisym
(gcd-greatest (∣-respʳ a≈b (gcd[a,b]∣a a c)) (∣-respʳ c≈d (gcd[a,b]∣b a c)))
(gcd-greatest (∣-respʳ (sym a≈b) (gcd[a,b]∣a b d)) (∣-respʳ (sym c≈d) (gcd[a,b]∣b b d)))
gcd-congˡ : LeftCongruent gcd
gcd-congˡ c≈d = gcd-cong refl c≈d
gcd-congʳ : RightCongruent gcd
gcd-congʳ a≈b = gcd-cong a≈b refl
infix 4 _⊥_
_⊥_ : C → C → Set ℓ
n ⊥ m = gcd n m ≈ 1#
⊥-sym : Symmetric _⊥_
⊥-sym {x} {y} gcd[x,y]≡1 = begin
gcd y x ≈⟨ gcd-comm y x ⟩
gcd x y ≈⟨ gcd[x,y]≡1 ⟩
1# ∎
⊥-respʳ : _⊥_ Respectsʳ _≈_
⊥-respʳ {y} {x₁} {x₂} x₁≈x₂ gcd[y,x₁]≈1 = begin
gcd y x₂ ≈⟨ gcd-congˡ (sym x₁≈x₂) ⟩
gcd y x₁ ≈⟨ gcd[y,x₁]≈1 ⟩
1# ∎
⊥-respˡ : _⊥_ Respectsˡ _≈_
⊥-respˡ {y} {x₁} {x₂} x₁≈x₂ gcd[x₁,y]≈1 = begin
gcd x₂ y ≈⟨ gcd-congʳ (sym x₁≈x₂) ⟩
gcd x₁ y ≈⟨ gcd[x₁,y]≈1 ⟩
1# ∎
⊥-resp : _⊥_ Respects₂ _≈_
⊥-resp = ⊥-respʳ , ⊥-respˡ
module _
(∣_∣ : ∀ n {n≉0 : n ≉ 0#} → ℕ)
(_div_ : ∀ (n m : C) {m≉0 : m ≉ 0#} → C)
(_mod_ : ∀ (n m : C) {m≉0 : m ≉ 0#} → C)
where
open Modulus 0# ∣_∣ _mod_
module Euclidean
(_≈?_ : Decidable _≈_)
(≈-irrelevant : Irrelevant _≈_)
(≉-irrelevant : Irrelevant _≉_)
(division : ∀ n m {m≉0 : m ≉ 0#} → n ≈ m * (n div m) {m≉0} + (n mod m) {m≉0})
(modulus : ∀ n m {m≉0 : m ≉ 0#} → Remainder n m {m≉0})
(mod-cong : ∀ {x₁ x₂} {y₁ y₂} → x₁ ≈ x₂ → y₁ ≈ y₂ → ∀ {y₁≉0 y₂≉0} → (x₁ mod y₁) {y₁≉0} ≈ (x₂ mod y₂) {y₂≉0})
(mod-distribʳ-* : ∀ c a b {b≉0} {b*c≉0} → ((a * c) mod (b * c)) {b*c≉0} ≈ (a mod b) {b≉0} * c)
where
gcdₕ : ∀ (n m : C) {m≉0 : m ≉ 0#} → Acc _<_ (∣ m ∣ {m≉0}) → C
gcdₕ n m {m≉0} (acc downward) with modulus n m {m≉0}
... | 0≈ r≈0 = m
... | 0≉ r≉0 r<m = gcdₕ m (n mod m) (downward r<m)
gcd : C → C → C
gcd n m with m ≈? 0#
... | yes m≈0 = n
... | no m≉0 = gcdₕ n m {m≉0} <-well-founded
∣b∣a%b⇒∣a : ∀ {c a b} {b≉0 : b ≉ 0#} → c ∣ b → c ∣ (a mod b) {b≉0} → c ∣ a
∣b∣a%b⇒∣a {c} {a} {b} {b≉0} (divides q₁ b≈q₁*c) (divides q₂ a%b≈q₂*c) = divides ((a div b) {b≉0} * q₁ + q₂) $ begin
a ≈⟨ division a b {b≉0} ⟩
b * (a div b) + a mod b ≈⟨ +-cong (*-congʳ b≈q₁*c) a%b≈q₂*c ⟩
(q₁ * c) * (a div b) + q₂ * c ≈⟨ +-congʳ (*-comm (q₁ * c) (a div b)) ⟩
(a div b) * (q₁ * c) + q₂ * c ≈⟨ +-congʳ (sym (*-assoc (a div b) q₁ c)) ⟩
((a div b) * q₁) * c + q₂ * c ≈⟨ sym (distribʳ c ((a div b) * q₁) q₂) ⟩
((a div b) * q₁ + q₂) * c ∎
gcd[a,b]∣a×gcd[a,b]∣b : ∀ a b → (gcd a b ∣ a) × (gcd a b ∣ b)
gcd[a,b]∣a×gcd[a,b]∣b a b with b ≈? 0#
... | yes b≈0 = ∣-refl , (∣-respʳ (sym b≈0) (a ∣0))
... | no b≉0 = loop a b {b≉0} <-well-founded
where
loop : ∀ a b {b≉0} (rec : Acc _<_ (∣ b ∣ {b≉0})) → (gcdₕ a b rec ∣ a) × (gcdₕ a b rec ∣ b)
loop a b {b≉0} (acc downward) with modulus a b {b≉0}
... | 0≈ r≈0 = ∣b∣a%b⇒∣a ∣-refl (∣-respʳ (sym r≈0) (b ∣0)) , ∣-refl
... | 0≉ r≉0 r<m with loop b (a mod b) (downward r<m)
... | gcd∣b , gcd∣a%b = ∣b∣a%b⇒∣a gcd∣b gcd∣a%b , gcd∣b
∣a∣b⇒∣a%b : ∀ {c a b} {b≉0 : b ≉ 0#} → c ∣ a → c ∣ b → c ∣ (a mod b) {b≉0}
∣a∣b⇒∣a%b {c} {a} {b} {b≉0} (divides q₁ a≈q₁*c) (divides q₂ b≈q₂*c) = divides ((q₁ mod q₂) {q≉0}) $ begin
a mod b ≈⟨ mod-cong a≈q₁*c b≈q₂*c {b≉0} {q₂*c≉0} ⟩
(q₁ * c) mod (q₂ * c) ≈⟨ mod-distribʳ-* c q₁ q₂ ⟩
(q₁ mod q₂) * c ∎
where
q≉0 : q₂ ≉ 0#
q≉0 q₂≈0 = b≉0 $ begin
b ≈⟨ b≈q₂*c ⟩
q₂ * c ≈⟨ *-congʳ q₂≈0 ⟩
0# * c ≈⟨ zeroˡ c ⟩
0# ∎
q₂*c≉0 : q₂ * c ≉ 0#
q₂*c≉0 q₂*c≈0 = b≉0 $ begin
b ≈⟨ b≈q₂*c ⟩
q₂ * c ≈⟨ q₂*c≈0 ⟩
0# ∎
gcd-greatest : ∀ {c a b} → c ∣ a → c ∣ b → c ∣ gcd a b
gcd-greatest {c} {a} {b} c∣a c∣b with b ≈? 0#
... | yes b≈0 = c∣a
... | no b≉0 = loop c a b <-well-founded c∣a c∣b
where
loop : ∀ c a b {b≉0} (rec : Acc _<_ (∣ b ∣ {b≉0})) → c ∣ a → c ∣ b → c ∣ gcdₕ a b rec
loop c a b {b≉0} (acc downward) c∣a c∣b with modulus a b {b≉0}
... | 0≈ r≈0 = c∣b
... | 0≉ r≉0 r<m = loop c b (a mod b) (downward r<m) c∣b (∣a∣b⇒∣a%b c∣a c∣b)
gcd-isGCD : IsGCD gcd
gcd-isGCD = record
{ gcd[a,b]∣a = λ a b → proj₁ (gcd[a,b]∣a×gcd[a,b]∣b a b)
; gcd[a,b]∣b = λ a b → proj₂ (gcd[a,b]∣a×gcd[a,b]∣b a b)
; gcd-greatest = gcd-greatest
}
-- open GCD gcd-isGCD ∣-antisym public
data Identity (d : C) (a : C) (b : C) : Set (c ⊔ ℓ) where
+ʳ : ∀ (x y : C) → d + x * a ≈ y * b → Identity d a b
+ˡ : ∀ (x y : C) → d + y * b ≈ x * a → Identity d a b
identity-sym : ∀ {d} → Symmetric (Identity d)
identity-sym (+ʳ x y pf) = +ˡ y x pf
identity-sym (+ˡ x y pf) = +ʳ y x pf
identity-base : ∀ {d a} → Identity d d a
identity-base {d} {a} = +ˡ 1# 0# $ begin
d + 0# * a ≈⟨ +-congˡ (zeroˡ a) ⟩
d + 0# ≈⟨ +-identityʳ d ⟩
d ≈⟨ sym (*-identityˡ d) ⟩
1# * d ∎
stepʳ
: ∀ d x y a b {b≉0}
→ d + x * b ≈ y * (a mod b) {b≉0}
→ d + (x + y * (a div b) {b≉0}) * b ≈ y * a
stepʳ d x y a b {b≉0} d+x*b≈y*[a%b] = begin
d + (x + y * a div b) * b ≈⟨ +-congˡ (distribʳ b x (y * (a div b) {b≉0})) ⟩
d + (x * b + y * a div b * b) ≈⟨ sym (+-assoc d (x * b) (y * a div b * b)) ⟩
(d + x * b) + y * a div b * b ≈⟨ +-cong d+x*b≈y*[a%b] (*-assoc y (a div b) b) ⟩
y * a mod b + y * (a div b * b) ≈⟨ sym (distribˡ y (a mod b) (a div b * b)) ⟩
y * (a mod b + a div b * b) ≈⟨ *-congˡ (+-comm (a mod b) (a div b * b)) ⟩
y * (a div b * b + a mod b) ≈⟨ *-congˡ (+-congʳ (*-comm (a div b) b)) ⟩
y * (b * a div b + a mod b) ≈⟨ *-congˡ (sym (division a b)) ⟩
y * a ∎
stepˡ
: ∀ d x y a b {b≉0}
→ d + y * (a mod b) {b≉0} ≈ x * b
→ d + y * a ≈ (x + y * (a div b) {b≉0}) * b
stepˡ d x y a b {b≉0} d+x*b≈y*[a%b] = begin
d + y * a ≈⟨ +-congˡ (*-congˡ (division a b {b≉0})) ⟩
d + y * (b * a div b + a mod b) ≈⟨ +-congˡ (*-congˡ (+-comm (b * a div b) (a mod b))) ⟩
d + y * (a mod b + b * a div b) ≈⟨ +-congˡ (distribˡ y (a mod b) (b * a div b)) ⟩
d + (y * (a mod b) + y * (b * a div b)) ≈⟨ sym (+-assoc d (y * (a mod b)) (y * (b * a div b))) ⟩
(d + y * (a mod b)) + y * (b * a div b) ≈⟨ +-cong d+x*b≈y*[a%b] (*-congˡ (*-comm b (a div b))) ⟩
x * b + y * (a div b * b) ≈⟨ +-congˡ (sym (*-assoc y (a div b) b)) ⟩
x * b + (y * a div b) * b ≈⟨ sym (distribʳ b x (y * a div b)) ⟩
(x + y * (a div b)) * b ∎
identity-step : ∀ {d a b} {b≉0} → Identity d b ((a mod b) {b≉0}) → Identity d a b
identity-step {d} {a} {b} {b≉0} (+ʳ x y d+x*b≈y*[a%b]) = +ˡ y (x + y * (a div b)) (stepʳ d x y a b {b≉0} d+x*b≈y*[a%b])
identity-step {d} {a} {b} {b≉0} (+ˡ x y d+y*[a%b]≈x*b) = +ʳ y (x + y * (a div b)) (stepˡ d x y a b {b≉0} d+y*[a%b]≈x*b)
data Bézoutₕ (a : C) (b : C) {b≉0 : b ≉ 0#} (rec : Acc _<_ (∣ b ∣ {b≉0})) : Set (c ⊔ ℓ) where
lemmaₕ : ∀ d → gcdₕ a b rec ≈ d → Identity d a b → Bézoutₕ a b rec
gcdₕ-base : ∀ {a b} {b≉0} {rec : Acc _<_ (∣ b ∣ {b≉0})} (r≈0 : (a mod b) {b≉0} ≈ 0#) → gcdₕ a b rec ≈ b
gcdₕ-base {a} {b} {b≉0} {acc downward} [r≈0]₁ with modulus a b {b≉0}
... | 0≈ [r≈0]₂ rewrite ≈-irrelevant [r≈0]₁ [r≈0]₂ = refl
... | 0≉ r≉0 _ = contradiction [r≈0]₁ r≉0
gcdₕ-step
: ∀ {d a b} {b≉0} {r≉0 : (a mod b) {b≉0} ≉ 0#}
{r<m : ∣ a mod b ∣ {r≉0} < ∣ b ∣ {b≉0}}
{downward : ∀ {x} → x < ∣ b ∣ {b≉0} → Acc _<_ x}
→ gcdₕ b (a mod b) (downward {∣ a mod b ∣} r<m) ≈ d → gcdₕ a b (acc downward) ≈ d
gcdₕ-step {d} {a} {b} {b≉0} {[r≉0]₁} {[r<m]₁} gcdₕ[b,a%b]≈d with modulus a b {b≉0}
... | 0≈ r≈0 = contradiction r≈0 [r≉0]₁
... | 0≉ [r≉0]₂ [r<m]₂ rewrite ≉-irrelevant [r≉0]₁ [r≉0]₂ | <-irrelevant [r<m]₁ [r<m]₂ = gcdₕ[b,a%b]≈d
bézoutₕ : ∀ a b {b≉0} (rec : Acc _<_ (∣ b ∣ {b≉0})) → Bézoutₕ a b rec
bézoutₕ a b {b≉0} (acc downward) with modulus a b {b≉0}
... | 0≈ r≈0 = lemmaₕ b (gcdₕ-base r≈0) (identity-sym identity-base)
... | 0≉ r≉0 r<m with bézoutₕ b (a mod b) {r≉0} (downward r<m)
... | lemmaₕ d gcdₕ[b,a%b]≈d ident = lemmaₕ d (gcdₕ-step gcdₕ[b,a%b]≈d) (identity-step ident)
data Bézout (a : C) (b : C) : Set (c ⊔ ℓ) where
lemma : ∀ d → gcd a b ≈ d → Identity d a b → Bézout a b
b≈0⇒gcd[a,b]≈a : ∀ a b → b ≈ 0# → gcd a b ≈ a
b≈0⇒gcd[a,b]≈a a b b≈0 with b ≈? 0#
... | yes _ = refl
... | no b≉0 = contradiction b≈0 b≉0
gcdₕ⇒gcd : ∀ {d a b} {b≉0} → gcdₕ a b {b≉0} <-well-founded ≈ d → gcd a b ≈ d
gcdₕ⇒gcd {d} {a} {b} {[b≉0]₁} gcdₕ[a,b]≈d with b ≈? 0#
... | yes b≈0 = contradiction b≈0 [b≉0]₁
... | no [b≉0]₂ rewrite ≉-irrelevant [b≉0]₁ [b≉0]₂ = gcdₕ[a,b]≈d
bézout : ∀ a b → Bézout a b
bézout a b with b ≈? 0#
... | yes b≈0 = lemma a (b≈0⇒gcd[a,b]≈a a b b≈0) identity-base
... | no b≉0 with bézoutₕ a b {b≉0} <-well-founded
... | lemmaₕ d gcdₕ[a,b]≈d ident = lemma d (gcdₕ⇒gcd gcdₕ[a,b]≈d) ident
|
{
"alphanum_fraction": 0.4715375587,
"avg_line_length": 40.2123893805,
"ext": "agda",
"hexsha": "85616f9e26a9fca746b9f6498ffda7cd0ee6d64c",
"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": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/thesis",
"max_forks_repo_path": "proofs/AKS/Algebra/Divisibility.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"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": "mckeankylej/thesis",
"max_issues_repo_path": "proofs/AKS/Algebra/Divisibility.agda",
"max_line_length": 150,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/thesis",
"max_stars_repo_path": "proofs/AKS/Algebra/Divisibility.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z",
"num_tokens": 7467,
"size": 13632
}
|
------------------------------------------------------------------------
-- A semantics which uses continuation-passing style
------------------------------------------------------------------------
module TotalParserCombinators.Semantics.Continuation where
open import Algebra
open import Codata.Musical.Notation
open import Data.List
import Data.List.Properties as ListProp
open import Data.List.Relation.Binary.BagAndSetEquality
using (bag) renaming (_∼[_]_ to _List-∼[_]_)
open import Data.Maybe using (Maybe)
open import Data.Product as Prod
open import Function
open import Relation.Binary.PropositionalEquality as P using (_≡_)
private
module LM {Tok : Set} = Monoid (ListProp.++-monoid Tok)
open import TotalParserCombinators.Parser
open import TotalParserCombinators.Semantics as S
hiding ([_-_]_⊛_; [_-_]_>>=_)
-- The statement x ⊕ s₂ ∈ p · s means that there is some s₁ such that
-- s ≡ s₁ ++ s₂ and x ∈ p · s₁. This variant of the semantics is
-- perhaps harder to understand, but sometimes easier to work with
-- (and it is proved to be language equivalent to the semantics in
-- TotalParserCombinators.Semantics).
infix 60 <$>_
infixl 50 [_-_]_⊛_
infixl 10 [_-_]_>>=_
infix 4 _⊕_∈_·_
data _⊕_∈_·_ {Tok} : ∀ {R xs} → R → List Tok →
Parser Tok R xs → List Tok → Set₁ where
return : ∀ {R} {x : R} {s} → x ⊕ s ∈ return x · s
token : ∀ {x s} → x ⊕ s ∈ token · x ∷ s
∣-left : ∀ {R x xs₁ xs₂ s s₁}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂}
(x∈p₁ : x ⊕ s₁ ∈ p₁ · s) → x ⊕ s₁ ∈ p₁ ∣ p₂ · s
∣-right : ∀ {R x xs₂ s s₁} xs₁
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂}
(x∈p₂ : x ⊕ s₁ ∈ p₂ · s) → x ⊕ s₁ ∈ p₁ ∣ p₂ · s
<$>_ : ∀ {R₁ R₂ x s s₁ xs} {p : Parser Tok R₁ xs} {f : R₁ → R₂}
(x∈p : x ⊕ s₁ ∈ p · s) → f x ⊕ s₁ ∈ f <$> p · s
[_-_]_⊛_ : ∀ {R₁ R₂ f x s s₁ s₂} xs fs
{p₁ : ∞⟨ xs ⟩Parser Tok (R₁ → R₂) (flatten fs)}
{p₂ : ∞⟨ fs ⟩Parser Tok R₁ (flatten xs)} →
(f∈p₁ : f ⊕ s₁ ∈ ♭? p₁ · s)
(x∈p₂ : x ⊕ s₂ ∈ ♭? p₂ · s₁) →
f x ⊕ s₂ ∈ p₁ ⊛ p₂ · s
[_-_]_>>=_ : ∀ {R₁ R₂ x y s s₁ s₂} (f : Maybe (R₁ → List R₂)) xs
{p₁ : ∞⟨ f ⟩Parser Tok R₁ (flatten xs)}
{p₂ : (x : R₁) → ∞⟨ xs ⟩Parser Tok R₂ (apply f x)} →
(x∈p₁ : x ⊕ s₁ ∈ ♭? p₁ · s)
(y∈p₂x : y ⊕ s₂ ∈ ♭? (p₂ x) · s₁) →
y ⊕ s₂ ∈ p₁ >>= p₂ · s
nonempty : ∀ {R xs x y s₂} s₁ {p : Parser Tok R xs}
(x∈p : y ⊕ s₂ ∈ p · x ∷ s₁ ++ s₂) →
y ⊕ s₂ ∈ nonempty p · x ∷ s₁ ++ s₂
cast : ∀ {R xs₁ xs₂ x s₁ s₂} {xs₁≈xs₂ : xs₁ List-∼[ bag ] xs₂}
{p : Parser Tok R xs₁}
(x∈p : x ⊕ s₂ ∈ p · s₁) → x ⊕ s₂ ∈ cast xs₁≈xs₂ p · s₁
-- A simple cast lemma.
private
cast∈′ : ∀ {Tok R xs} {p : Parser Tok R xs} {x s s′ s₁} →
s ≡ s′ → x ⊕ s₁ ∈ p · s → x ⊕ s₁ ∈ p · s′
cast∈′ P.refl x∈ = x∈
-- The definition is sound and complete with respect to the one in
-- TotalParserCombinators.Semantics.
sound′ : ∀ {Tok R xs x s₂ s} {p : Parser Tok R xs} →
x ⊕ s₂ ∈ p · s → ∃ λ s₁ → s ≡ s₁ ++ s₂ × x ∈ p · s₁
sound′ return = ([] , P.refl , return)
sound′ {x = x} token = ([ x ] , P.refl , token)
sound′ (∣-left x∈p₁) = Prod.map id (Prod.map id ∣-left) (sound′ x∈p₁)
sound′ (∣-right e₁ x∈p₁) = Prod.map id (Prod.map id (∣-right e₁)) (sound′ x∈p₁)
sound′ (<$> x∈p) = Prod.map id (Prod.map id (<$>_)) (sound′ x∈p)
sound′ ([ xs - fs ] f∈p₁ ⊛ x∈p₂) with sound′ f∈p₁ | sound′ x∈p₂
sound′ ([ xs - fs ] f∈p₁ ⊛ x∈p₂) | (s₁ , P.refl , f∈p₁′) | (s₂ , P.refl , x∈p₂′) =
(s₁ ++ s₂ , P.sym (LM.assoc s₁ s₂ _) ,
S.[_-_]_⊛_ xs fs f∈p₁′ x∈p₂′)
sound′ (nonempty s₁ x∈p) with sound′ x∈p
sound′ (nonempty s₁ x∈p) | (y ∷ s , eq , x∈p′) = (y ∷ s , eq , nonempty x∈p′)
sound′ (nonempty s₁ x∈p) | ([] , eq , x∈p′)
with ListProp.++-identityˡ-unique (_ ∷ s₁) (P.sym eq)
sound′ (nonempty s₁ x∈p) | ([] , eq , x∈p′) | ()
sound′ (cast x∈p) = Prod.map id (Prod.map id cast) (sound′ x∈p)
sound′ ([ f - xs ] x∈p₁ >>= y∈p₂x) with sound′ x∈p₁ | sound′ y∈p₂x
sound′ ([ f - xs ] x∈p₁ >>= y∈p₂x) | (s₁ , P.refl , x∈p₁′) | (s₂ , P.refl , y∈p₂x′) =
(s₁ ++ s₂ , P.sym (LM.assoc s₁ s₂ _) , S.[_-_]_>>=_ f xs x∈p₁′ y∈p₂x′)
sound : ∀ {Tok R xs x s} {p : Parser Tok R xs} →
x ⊕ [] ∈ p · s → x ∈ p · s
sound x∈p with sound′ x∈p
sound x∈p | (s , P.refl , x∈p′) with s ++ [] | Prod.proj₂ LM.identity s
sound x∈p | (s , P.refl , x∈p′) | .s | P.refl = x∈p′
extend : ∀ {Tok R xs x s s′ s″} {p : Parser Tok R xs} →
x ⊕ s′ ∈ p · s → x ⊕ s′ ++ s″ ∈ p · s ++ s″
extend return = return
extend token = token
extend (∣-left x∈p₁) = ∣-left (extend x∈p₁)
extend (∣-right e₁ x∈p₂) = ∣-right e₁ (extend x∈p₂)
extend (<$> x∈p) = <$> extend x∈p
extend ([ xs - fs ] f∈p₁ ⊛ x∈p₂) = [ xs - fs ] extend f∈p₁ ⊛ extend x∈p₂
extend ([ f - xs ] x∈p₁ >>= y∈p₂x) = [ f - xs ] extend x∈p₁ >>= extend y∈p₂x
extend (cast x∈p) = cast (extend x∈p)
extend (nonempty s₁ x∈p) = cast₂ (nonempty s₁ (cast₁ (extend x∈p)))
where
lem = LM.assoc (_ ∷ s₁) _ _
cast₁ = cast∈′ lem
cast₂ = cast∈′ (P.sym lem)
complete : ∀ {Tok R xs x s} {p : Parser Tok R xs} →
x ∈ p · s → x ⊕ [] ∈ p · s
complete return = return
complete token = token
complete (∣-left x∈p₁) = ∣-left (complete x∈p₁)
complete (∣-right e₁ x∈p₂) = ∣-right e₁ (complete x∈p₂)
complete (<$> x∈p) = <$> complete x∈p
complete (_⊛_ {fs = fs} {xs = xs} f∈p₁ x∈p₂) = [ xs - fs ] extend (complete f∈p₁) ⊛ complete x∈p₂
complete (_>>=_ {xs = xs} {f = f} x∈p₁ y∈p₂x) = [ f - xs ] extend (complete x∈p₁) >>= complete y∈p₂x
complete (cast x∈p) = cast (complete x∈p)
complete (nonempty {s = s} x∈p) = cast₂ (nonempty s (cast₁ (complete x∈p)))
where
lem = Prod.proj₂ LM.identity _
cast₁ = cast∈′ (P.sym lem)
cast₂ = cast∈′ lem
complete′ : ∀ {Tok R xs x s₂ s} {p : Parser Tok R xs} →
(∃ λ s₁ → s ≡ s₁ ++ s₂ × x ∈ p · s₁) →
x ⊕ s₂ ∈ p · s
complete′ (s₁ , P.refl , x∈p) = extend (complete x∈p)
|
{
"alphanum_fraction": 0.4642803654,
"avg_line_length": 47.3546099291,
"ext": "agda",
"hexsha": "33b27c9cc7ab8e0a7b6a8c14deb223eb80399a14",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "TotalParserCombinators/Semantics/Continuation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "TotalParserCombinators/Semantics/Continuation.agda",
"max_line_length": 103,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "TotalParserCombinators/Semantics/Continuation.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 2653,
"size": 6677
}
|
open import FRP.JS.Behaviour using ( Beh ; [_] )
open import FRP.JS.DOM using ( DOM ; element ; attr ; text ; _++_ )
open import FRP.JS.RSet using ( ⟦_⟧ )
module FRP.JS.Demo.HRef where
main : ∀ {w} → ⟦ Beh (DOM w) ⟧
main = element ("a")
( attr "href" ["http://bell-labs.com/"] ++
text ["A hyperlink."] )
|
{
"alphanum_fraction": 0.5942492013,
"avg_line_length": 28.4545454545,
"ext": "agda",
"hexsha": "c5cb0f5c99b1ce5b3749bc3e62b900af239fe7b8",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z",
"max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_forks_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-frp-js",
"max_forks_repo_path": "demo/agda/FRP/JS/Demo/HRef.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-frp-js",
"max_issues_repo_path": "demo/agda/FRP/JS/Demo/HRef.agda",
"max_line_length": 67,
"max_stars_count": 63,
"max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_stars_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-frp-js",
"max_stars_repo_path": "demo/agda/FRP/JS/Demo/HRef.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z",
"num_tokens": 111,
"size": 313
}
|
open import Prelude
module Implicits.Resolution.Scala.Terminates where
open import Implicits.Syntax
open import Implicits.Substitutions
open import Implicits.Resolution.Infinite.Algorithm
open import Implicits.Resolution.Scala.Type
open import Category.Monad.Partiality
open import Category.Monad.Partiality as P
open Workaround
open import Category.Monad.Partiality.All using (All; module Alternative)
open Alternative renaming (sound to AllP-sound) hiding (complete)
private
open import Relation.Binary.PropositionalEquality as PEq using (_≡_)
open module PartialEq = P.Equality {A = Bool} _≡_
open module PartialReasoning = P.Reasoning (PEq.isEquivalence {A = Bool})
match-terminates : ∀ {ν} (Δ : ICtx ν) → (τ : SimpleType ν) → (r : Type ν) → (match Δ τ r) ⇓
match-terminates Δ τ r = ?
match1st-terminates : ∀ {ν} (Δ : ICtx ν) → (ρs : ICtx ν) → (τ : SimpleType ν) → (match1st Δ ρs τ) ⇓
match1st-terminates Δ List.[] τ = false , (now refl)
match1st-terminates Δ (x List.∷ ρs) τ = {!!}
terminates : ∀ {ν} (Δ : ICtx ν) (a : Type ν) → ScalaICtx Δ → ScalaType a → (resolve Δ a) ⇓
terminates Δ (simpl x) p q = match1st-terminates Δ Δ x
terminates Δ (∀' a) p (∀' q) = terminates (ictx-weaken Δ) a (weaken-scalaictx p) q
terminates Δ (a ⇒ b) p ()
|
{
"alphanum_fraction": 0.7154213037,
"avg_line_length": 39.3125,
"ext": "agda",
"hexsha": "3df3f3e888f3d7fb6976e997a66fc3272d0303f1",
"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/Scala/Terminates.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/Scala/Terminates.agda",
"max_line_length": 99,
"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/Scala/Terminates.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": 413,
"size": 1258
}
|
-- {-# OPTIONS -v term:10 -v tc.pos:10 -v tc.decl:10 #-}
-- Andreas, 2018-02-26, issue #2975
-- Problem history:
--
-- The example below crashed with an internal error.
-- The problem is that the termination checker needs to know
-- whether force is the projection of a recursive coinductive
-- record. However, the positivity checker has not run,
-- thus, this information is not available.
record R : Set where
coinductive
field force : R
-- The following corecursive definition should pass the termination checker.
r : R
force r = r
-- Should succeed.
|
{
"alphanum_fraction": 0.7122807018,
"avg_line_length": 27.1428571429,
"ext": "agda",
"hexsha": "90821225617a4c7cb5ce6d06d08c07d8093f7524",
"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": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/Issue2975.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"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": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/Issue2975.agda",
"max_line_length": 78,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/Issue2975.agda",
"max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z",
"num_tokens": 147,
"size": 570
}
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.2-Category where
open import Level
open import Data.Product using (curry; _,_)
open import Function using () renaming (_∘_ to _·_)
open import Categories.Support.PropositionalEquality
open import Categories.Category
open import Categories.Categories
open import Categories.Object.Terminal
open import Categories.Terminal
open import Categories.Functor using (Functor) renaming (_∘_ to _∘F_; _≡_ to _≡F_; id to idF)
open import Categories.Bifunctor using (Bifunctor; reduce-×)
open import Categories.Product using (assocʳ; πˡ; πʳ)
record 2-Category (o ℓ t e : Level) : Set (suc (o ⊔ ℓ ⊔ t ⊔ e)) where
open Terminal (One {ℓ} {t} {e})
infix 4 _⇒_
infixr 9 _∘_
field
Obj : Set o
_⇒_ : (A B : Obj) → Category ℓ t e
id : {A : Obj} → Functor ⊤ (A ⇒ A)
—∘— : {A B C : Obj} → Bifunctor (B ⇒ C) (A ⇒ B) (A ⇒ C)
_∘_ : {A B C : Obj} {L R : Category ℓ t e} → Functor L (B ⇒ C) → Functor R (A ⇒ B) → Bifunctor L R (A ⇒ C)
_∘_ {A} {B} {C} F G = reduce-× {D₁ = B ⇒ C} {D₂ = A ⇒ B} —∘— F G
field
.assoc : ∀ {A B C D : Obj} → ((—∘— ∘ idF) ∘F assocʳ (C ⇒ D) (B ⇒ C) (A ⇒ B)) ≡F (idF ∘ —∘—)
.identityˡ : {A B : Obj} → (id {B} ∘ idF {C = A ⇒ B}) ≡F πʳ {C = ⊤} {A ⇒ B}
.identityʳ : {A B : Obj} → (idF {C = A ⇒ B} ∘ id {A}) ≡F πˡ {C = A ⇒ B} {⊤}
-- convenience?
module _⇒_ (A B : Obj) = Category (A ⇒ B)
open _⇒_ public using () renaming (Obj to _⇒₁_)
private module imp⇒ {X Y : Obj} = Category (X ⇒ Y)
open imp⇒ public using () renaming (_⇒_ to _⇒₂_; id to id₂; _∘_ to _•_; assoc to vassoc′; identityˡ to videntityˡ′; identityʳ to videntityʳ′; ∘-resp-≡ to •-resp-≡′; ∘-resp-≡ˡ to •-resp-≡′ˡ; ∘-resp-≡ʳ to •-resp-≡′ʳ; hom-setoid to hom₂′-setoid; _≡_ to _≡′_; equiv to equiv′; module Equiv to Equiv′)
module Equiv {X Y : Obj} = Heterogeneous (X ⇒ Y)
open Equiv public using () renaming (_∼_ to _≡_; ≡⇒∼ to loosely)
id₁ : ∀ {A} → A ⇒₁ A
id₁ {A} = Functor.F₀ (id {A}) unit
id₁₂ : ∀ {A} → id₁ {A} ⇒₂ id₁ {A}
id₁₂ {A} = id₂ {A = id₁ {A}}
infixr 9 _∘₁_
_∘₁_ : ∀ {A B C} → B ⇒₁ C → A ⇒₁ B → A ⇒₁ C
_∘₁_ = curry (Functor.F₀ —∘—)
-- horizontal composition
infixr 9 _∘₂_
_∘₂_ : ∀ {A B C} {g g′ : B ⇒₁ C} {f f′ : A ⇒₁ B} (β : g ⇒₂ g′) (α : f ⇒₂ f′) → (g ∘₁ f) ⇒₂ (g′ ∘₁ f′)
_∘₂_ = curry (Functor.F₁ —∘—)
.∘₂-resp-≡′ : ∀ {A B C} {f h : B ⇒₁ C} {g i : A ⇒₁ B} {α γ : f ⇒₂ h} {β δ : g ⇒₂ i} → α ≡′ γ → β ≡′ δ → α ∘₂ β ≡′ γ ∘₂ δ
∘₂-resp-≡′ = curry (Functor.F-resp-≡ —∘—)
.∘₂-resp-≡ : ∀ {A B C} {f f′ h h′ : B ⇒₁ C} {g g′ i i′ : A ⇒₁ B} {α : f ⇒₂ h} {γ : f′ ⇒₂ h′} {β : g ⇒₂ i} {δ : g′ ⇒₂ i′} → α ≡ γ → β ≡ δ → (α ∘₂ β) ≡ (γ ∘₂ δ)
∘₂-resp-≡ (loosely a) (loosely b) = loosely (∘₂-resp-≡′ a b)
-- left whiskering
infixl 9 _◃_
_◃_ : ∀ {A B C} {g g′ : B ⇒₁ C} → g ⇒₂ g′ → (f : A ⇒₁ B) → (g ∘₁ f) ⇒₂ (g′ ∘₁ f)
β ◃ f = β ∘₂ id₂
-- right whiskering
infixr 9 _▹_
_▹_ : ∀ {A B C} (g : B ⇒₁ C) → {f f′ : A ⇒₁ B} → f ⇒₂ f′ → (g ∘₁ f) ⇒₂ (g ∘₁ f′)
g ▹ α = id₂ ∘₂ α
private
≡F-on-objects : ∀ {o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} (F G : Functor C D) → (F ≡F G) → (X : Category.Obj C) → Functor.F₀ F X ≣ Functor.F₀ G X
≡F-on-objects {C = C} F G eq X with Functor.F₀ F X | Functor.F₁ F (Category.id C {X}) | eq (Category.id C {X})
≡F-on-objects {C = C} F G eq X | ._ | _ | Heterogeneous.≡⇒∼ _ = ≣-refl
private
module Laws1A {A B} {f : A ⇒₁ B} where
.assoc₁ : ∀ {C D} {g : B ⇒₁ C} {h : C ⇒₁ D} → ((h ∘₁ g) ∘₁ f) ≣ (h ∘₁ (g ∘₁ f))
assoc₁ {C} {D} {g} {h} = ≡F-on-objects ((—∘— ∘ idF) ∘F assocʳ (C ⇒ D) (B ⇒ C) (A ⇒ B)) (idF ∘ —∘—) assoc (h , g , f)
.identity₁ˡ : {- ∀ {A B} {f : A ⇒₁ B} → -} id₁ ∘₁ f ≣ f
identity₁ˡ = ≡F-on-objects (id {B} ∘ idF {C = A ⇒ B}) (πʳ {C = ⊤} {A ⇒ B}) identityˡ (unit , f)
.identity₁ʳ : ∀ {A B} {f : A ⇒₁ B} → f ∘₁ id₁ ≣ f
identity₁ʳ {A} {B} {f} = ≡F-on-objects (idF {C = A ⇒ B} ∘ id {A}) (πˡ {C = A ⇒ B} {⊤}) identityʳ (f , unit)
.vassoc : ∀ {A B} {f g h i : A ⇒₁ B} {η : f ⇒₂ g} {θ : g ⇒₂ h} {ι : h ⇒₂ i} → ((ι • θ) • η) ≡ (ι • (θ • η))
vassoc = loosely vassoc′
.hidentityˡ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (id₁₂ ∘₂ η) ≡ η
hidentityˡ {A} {B} {f} {f′} {η} = Equiv.trans (loosely (∘₂-resp-≡′ (Equiv′.sym (Functor.identity id)) Equiv′.refl)) (identityˡ (unit , η))
.hidentityʳ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (η ∘₂ id₁₂) ≡ η
hidentityʳ {A} {B} {f} {f′} {η} = Equiv.trans (loosely (∘₂-resp-≡′ Equiv′.refl (Equiv′.sym (Functor.identity id)))) (identityʳ (η , unit))
.im-id₂-closed-under-∘₂′ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → id₂ {A = g} ∘₂ id₂ {A = f} ≡′ id₂ {A = g ∘₁ f}
im-id₂-closed-under-∘₂′ = Functor.identity —∘—
.im-id₂-closed-under-∘₂ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → (id₂ {A = g} ∘₂ id₂ {A = f}) ≡ id₂ {A = g ∘₁ f}
im-id₂-closed-under-∘₂ = loosely im-id₂-closed-under-∘₂′
.lidentityˡ′ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → id₂ {A = g} ◃ f ≡′ id₂
lidentityˡ′ = Functor.identity —∘—
.lidentityˡ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → (id₂ {A = g} ◃ f) ≡ id₂ {A = g ∘₁ f}
lidentityˡ = loosely lidentityˡ′
.ridentityʳ′ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → g ▹ id₂ {A = f} ≡′ id₂
ridentityʳ′ = Functor.identity —∘—
.ridentityʳ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → (g ▹ id₂ {A = f}) ≡ id₂ {A = g ∘₁ f}
ridentityʳ = loosely ridentityʳ′
-- .lidentityʳ′ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (η ◃ id₁) ≡′ η
-- lidentityʳ′ = ?
.lidentityʳ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (η ◃ id₁) ≡ η
lidentityʳ {η = η} = Equiv.trans (∘₂-resp-≡ Equiv.refl (Equiv.sym (loosely (Functor.identity id)))) (identityʳ (η , unit))
-- .ridentityˡ′ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (id₁ ▹ η) ≡′ η
-- ridentityˡ′ = ?
.ridentityˡ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (id₁ ▹ η) ≡ η
ridentityˡ {η = η} = Equiv.trans (∘₂-resp-≡ (Equiv.sym (loosely (Functor.identity id))) Equiv.refl) (identityˡ (unit , η))
.interchange′ : ∀ {A B C} {f g h : A ⇒₁ B} {i j k : B ⇒₁ C} {α : f ⇒₂ g} {β : g ⇒₂ h} {γ : i ⇒₂ j} {δ : j ⇒₂ k} → ((δ • γ) ∘₂ (β • α)) ≡′ ((δ ∘₂ β) • (γ ∘₂ α))
interchange′ = Functor.homomorphism —∘—
.interchange : ∀ {A B C} {f g h : A ⇒₁ B} {i j k : B ⇒₁ C} {α : f ⇒₂ g} {β : g ⇒₂ h} {γ : i ⇒₂ j} {δ : j ⇒₂ k} → ((δ • γ) ∘₂ (β • α)) ≡ ((δ ∘₂ β) • (γ ∘₂ α))
interchange = loosely interchange′
.lvdistrib′ : ∀ {A B C} {f : A ⇒₁ B} {g h i : B ⇒₁ C} {η : g ⇒₂ h} {θ : h ⇒₂ i} → (θ • η) ◃ f ≡′ ((θ ◃ f) • (η ◃ f))
lvdistrib′ = Equiv′.trans (∘₂-resp-≡′ Equiv′.refl (Equiv′.sym videntityˡ′)) interchange′
.lvdistrib : ∀ {A B C} {f : A ⇒₁ B} {g h i : B ⇒₁ C} {η : g ⇒₂ h} {θ : h ⇒₂ i} → ((θ • η) ◃ f) ≡ ((θ ◃ f) • (η ◃ f))
lvdistrib = loosely lvdistrib′
.rvdistrib′ : ∀ {A B C} {f g h : A ⇒₁ B} {i : B ⇒₁ C} {η : f ⇒₂ g} {θ : g ⇒₂ h} → (i ▹ (θ • η)) ≡′ ((i ▹ θ) • (i ▹ η))
rvdistrib′ = Equiv′.trans (∘₂-resp-≡′ (Equiv′.sym videntityˡ′) Equiv′.refl) interchange′
.rvdistrib : ∀ {A B C} {f g h : A ⇒₁ B} {i : B ⇒₁ C} {η : f ⇒₂ g} {θ : g ⇒₂ h} → (i ▹ (θ • η)) ≡ ((i ▹ θ) • (i ▹ η))
rvdistrib = loosely rvdistrib′
-- XXX mixed assocs still need proving
{-
-- XXX not well-typed without a subst or something
-- .lhassoc′ : ∀ {A B C D} {f : A ⇒₁ B} {g : B ⇒₁ C} {h i : C ⇒₁ D} {η : h ⇒₂ i} → (η ◃ (g ∘₁ f)) ≡′ {!((η ◃ g) ◃ f)!}
-- lhassoc′ = {!!}
.lhassoc : ∀ {A B C D} {f : A ⇒₁ B} {g : B ⇒₁ C} {h i : C ⇒₁ D} {η : h ⇒₂ i} → (η ◃ (g ∘₁ f)) ≡ ((η ◃ g) ◃ f)
lhassoc = {!!}
-- XXX ditto
-- .rlassoc′ : ∀ {A B C D} {f : A ⇒₁ B} {g h : B ⇒₁ C} {i : C ⇒₁ D} {η : g ⇒₂ h} → (i ▹ (η ◃ f)) ≡′ {!((i ▹ η) ◃ f)!}
-- rlassoc′ = {!!}
.rlassoc : ∀ {A B C D} {f : A ⇒₁ B} {g h : B ⇒₁ C} {i : C ⇒₁ D} {η : g ⇒₂ h} → (i ▹ (η ◃ f)) ≡ ((i ▹ η) ◃ f)
rlassoc = {!!}
-- XXX tritto
-- .hrassoc′ : ∀ {A B C D} {f g : A ⇒₁ B} {h : B ⇒₁ C} {i : C ⇒₁ D} {η : f ⇒₂ g} → (i ▹ (h ▹ η)) ≡′ {!((i ∘₁ h) ▹ η)!}
-- hrassoc′ = {!!}
.hrassoc : ∀ {A B C D} {f g : A ⇒₁ B} {h : B ⇒₁ C} {i : C ⇒₁ D} {η : f ⇒₂ g} → (i ▹ (h ▹ η)) ≡ ((i ∘₁ h) ▹ η)
hrassoc = {!!}
-}
.lrsmoosh′ : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((θ ◃ g) • (h ▹ η)) ≡′ (θ ∘₂ η)
lrsmoosh′ = Equiv′.trans (Equiv′.sym interchange′) (∘₂-resp-≡′ videntityʳ′ videntityˡ′)
.lrsmoosh : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((θ ◃ g) • (h ▹ η)) ≡ (θ ∘₂ η)
lrsmoosh = loosely lrsmoosh′
.rlsmoosh′ : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((i ▹ η) • (θ ◃ f)) ≡′ (θ ∘₂ η)
rlsmoosh′ = Equiv′.trans (Equiv′.sym interchange′) (∘₂-resp-≡′ videntityˡ′ videntityʳ′)
.rlsmoosh : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((i ▹ η) • (θ ◃ f)) ≡ (θ ∘₂ η)
rlsmoosh = loosely rlsmoosh′
.lrexch′ : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((i ▹ η) • (θ ◃ f)) ≡′ ((θ ◃ g) • (h ▹ η))
lrexch′ = Equiv′.trans rlsmoosh′ (Equiv′.sym lrsmoosh′)
.lrexch : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((i ▹ η) • (θ ◃ f)) ≡ ((θ ◃ g) • (h ▹ η))
lrexch = loosely lrexch′
module Hom₁Reasoning = ≣-reasoning
module Hom₂′Reasoning {A B : Obj} {f g : A ⇒₁ B} where
open imp⇒.HomReasoning {A} {B} {f} {g} public renaming (_⟩∘⟨_ to _⟩•⟨_)
-- XXX won't work if Hom₂′Reasoning is frozen
infixr 4 _⟩∘₂⟨_
._⟩∘₂⟨_ : ∀ {C} {h i : C ⇒₁ A} {α β : f ⇒₂ g} {γ δ : h ⇒₂ i} → α ≡′ β → γ ≡′ δ → (α ∘₂ γ) ≡′ (β ∘₂ δ)
_⟩∘₂⟨_ = ∘₂-resp-≡′
|
{
"alphanum_fraction": 0.4703012304,
"avg_line_length": 46.6732673267,
"ext": "agda",
"hexsha": "1b19c3736c0c4c1feb43d874fccd48f8538dfc98",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/2-Category.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/2-Category.agda",
"max_line_length": 298,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/2-Category.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 4913,
"size": 9428
}
|
{-# 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
-- 27 May 2011.
-- Nils' idea about databases in the Agda mailing list.
-- http://thread.gmane.org/gmane.comp.lang.agda/2911/focus=2917
module FOT.Agsy.DataBase where
open import Data.Nat
open import Data.Product
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
postulate
right-identity : ∀ n → n + 0 ≡ n
move-suc : ∀ m n → suc (m + n) ≡ m + suc n
db = right-identity ,′ move-suc
comm : ∀ m n → m + n ≡ n + m -- Via auto {!-c db!}
comm zero n = sym (proj₁ db n)
comm (suc n) n' =
begin
suc (n + n') ≡⟨ cong suc (comm n n') ⟩
suc (n' + n) ≡⟨ proj₂ db n' n ⟩ (n' + suc n)
∎
|
{
"alphanum_fraction": 0.5944700461,
"avg_line_length": 26.303030303,
"ext": "agda",
"hexsha": "4e3531d045577139ec7843147485a2de19a88c09",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/Agsy/DataBase.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/Agsy/DataBase.agda",
"max_line_length": 70,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/Agsy/DataBase.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": 282,
"size": 868
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- A categorical view of List⁺
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.NonEmpty.Categorical where
open import Agda.Builtin.List
import Data.List.Categorical as List
open import Data.List.NonEmpty
open import Data.Product using (uncurry)
open import Category.Functor
open import Category.Applicative
open import Category.Monad
open import Category.Comonad
open import Function
------------------------------------------------------------------------
-- List⁺ applicative functor
functor : ∀ {f} → RawFunctor {f} List⁺
functor = record
{ _<$>_ = map
}
applicative : ∀ {f} → RawApplicative {f} List⁺
applicative = record
{ pure = [_]
; _⊛_ = λ fs as → concatMap (λ f → map f as) fs
}
------------------------------------------------------------------------
-- List⁺ monad
monad : ∀ {f} → RawMonad {f} List⁺
monad = record
{ return = [_]
; _>>=_ = flip concatMap
}
------------------------------------------------------------------------
-- List⁺ comonad
comonad : ∀ {f} → RawComonad {f} List⁺
comonad = record
{ extract = head
; extend = λ f → uncurry (extend f) ∘′ uncons
} where
extend : ∀ {A B} → (List⁺ A → B) → A → List A → List⁺ B
extend f x xs@[] = f (x ∷ xs) ∷ []
extend f x xs@(y ∷ ys) = f (x ∷ xs) ∷⁺ extend f y ys
------------------------------------------------------------------------
-- Get access to other monadic functions
module _ {f F} (App : RawApplicative {f} F) where
open RawApplicative App
sequenceA : ∀ {A} → List⁺ (F A) → F (List⁺ A)
sequenceA (x ∷ xs) = _∷_ <$> x ⊛ List.sequenceA App xs
mapA : ∀ {a} {A : Set a} {B} → (A → F B) → List⁺ A → F (List⁺ B)
mapA f = sequenceA ∘ map f
forA : ∀ {a} {A : Set a} {B} → List⁺ A → (A → F B) → F (List⁺ B)
forA = flip mapA
module _ {m M} (Mon : RawMonad {m} M) where
private App = RawMonad.rawIApplicative Mon
sequenceM = sequenceA App
mapM = mapA App
forM = forA App
------------------------------------------------------------------------
-- List⁺ monad transformer
monadT : ∀ {f} → RawMonadT {f} (_∘′ List⁺)
monadT M = record
{ return = pure ∘′ [_]
; _>>=_ = λ mas f → mas >>= λ as → concat <$> mapM M f as
} where open RawMonad M
|
{
"alphanum_fraction": 0.4774736842,
"avg_line_length": 26.3888888889,
"ext": "agda",
"hexsha": "a33778c544ce7e0ad0a282f996866b6d371f885f",
"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/List/NonEmpty/Categorical.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/List/NonEmpty/Categorical.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/List/NonEmpty/Categorical.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 705,
"size": 2375
}
|
{-# OPTIONS --safe #-}
module Definition.Conversion.Transitivity where
open import Definition.Untyped
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.RedSteps
open import Definition.Conversion
open import Definition.Conversion.Soundness
open import Definition.Conversion.Stability
open import Definition.Conversion.Conversion
open import Definition.Conversion.Whnf
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.Injectivity
import Definition.Typed.Consequences.Inequality as WF
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.Substitution
open import Definition.Typed.Consequences.NeTypeEq
open import Definition.Typed.Consequences.SucCong
open import Tools.Nat
open import Tools.Product
open import Tools.Empty
import Tools.PropositionalEquality as PE
mutual
-- Transitivity of algorithmic equality of neutrals.
trans~↑! : ∀ {t u v A B Γ Δ l l'}
→ l PE.≡ l'
→ ⊢ Γ ≡ Δ
→ Γ ⊢ t ~ u ↑! A ^ l
→ Δ ⊢ u ~ v ↑! B ^ l'
→ Γ ⊢ t ~ v ↑! A ^ l
× Γ ⊢ A ≡ B ^ [ ! , l ]
trans~↑! el Γ≡Δ (var-refl x₁ x≡y) (var-refl x₂ x≡y₁) =
var-refl x₁ (PE.trans x≡y x≡y₁)
, proj₂ (neTypeEq (var _) x₁
(PE.subst (λ x → _ ⊢ var x ∷ _ ^ _) (PE.sym x≡y)
(stabilityTerm (symConEq Γ≡Δ) (PE.subst (λ lx → _ ⊢ _ ∷ _ ^ [ ! , lx ]) (PE.sym el) x₂))))
trans~↑! el Γ≡Δ (app-cong {rF = !} t~u a<>b) (app-cong {rF = !} u~v b<>c) =
let t~v , ΠFG≡ΠF′G′ = trans~↓! PE.refl Γ≡Δ t~u u~v
F≡F₁ , rF≡rF₁ , lF≡lF₁ , lG≡lG₁ , G≡G₁ = injectivity ΠFG≡ΠF′G′
a<>c = transConv↑Term Γ≡Δ F≡F₁ a<>b (PE.subst (λ x → _ ⊢ _ [conv↑] _ ∷ _ ^ ι x) (PE.sym lF≡lF₁) b<>c)
in app-cong t~v a<>c , substTypeEq G≡G₁ (soundnessConv↑Term a<>b)
trans~↑! el Γ≡Δ (app-cong {rF = %} t~u a<>b) (app-cong {rF = %} u~v b<>c) =
let t~v , ΠFG≡ΠF′G′ = trans~↓! PE.refl Γ≡Δ t~u u~v
F≡F₁ , rF≡rF₁ , lF≡lF₁ , lG≡lG₁ , G≡G₁ = injectivity ΠFG≡ΠF′G′
⊢Γ = proj₁ (proj₂ (contextConvSubst Γ≡Δ))
a<>c = trans~↑% Γ≡Δ a<>b (conv~↑% (PE.subst (λ x → _ ⊢ _ ~ _ ↑% _ ^ ι x) (PE.sym lF≡lF₁) b<>c) (stabilityEq Γ≡Δ (sym F≡F₁)))
_ , _ , t≡v = soundness~↑% a<>b
in app-cong t~v a<>c , substTypeEq G≡G₁ t≡v
trans~↑! el Γ≡Δ (app-cong {rF = !} t~u a<>b) (app-cong {rF = %} u~v b<>c) =
let whnfA , neK , neL = ne~↓! t~u
⊢A , ⊢k , ⊢l₁ = syntacticEqTerm (soundness~↓! t~u)
⊢A' , ⊢l₁' , ⊢l = syntacticEqTerm (soundness~↓! u~v)
_ , ΠFG≡ΠF₂G₂ = neTypeEq neL ⊢l₁ (stabilityTerm (symConEq Γ≡Δ) ⊢l₁')
F≡F₂ , rF≡rF₂ , G≡G₂ = injectivity ΠFG≡ΠF₂G₂
in ⊥-elim (relevance-discr rF≡rF₂)
trans~↑! el Γ≡Δ (app-cong {rF = %} t~u a<>b) (app-cong {rF = !} u~v b<>c) =
let whnfA , neK , neL = ne~↓! t~u
⊢A , ⊢k , ⊢l₁ = syntacticEqTerm (soundness~↓! t~u)
⊢A' , ⊢l₁' , ⊢l = syntacticEqTerm (soundness~↓! u~v)
_ , ΠFG≡ΠF₂G₂ = neTypeEq neL ⊢l₁ (stabilityTerm (symConEq Γ≡Δ) ⊢l₁')
F≡F₂ , rF≡rF₂ , G≡G₂ = injectivity ΠFG≡ΠF₂G₂
in ⊥-elim (relevance-discr (PE.sym rF≡rF₂))
trans~↑! PE.refl Γ≡Δ (natrec-cong A<>B a₀<>b₀ aₛ<>bₛ t~u) (natrec-cong B<>C b₀<>c₀ bₛ<>cₛ u~v) =
let ⊢Γ , _ , _ = contextConvSubst Γ≡Δ
A≡B = soundnessConv↑ A<>B
F[0]≡F₁[0] = substTypeEq A≡B (refl (zeroⱼ ⊢Γ))
ΠℕFs≡ΠℕF₁s = sucCong A≡B
A<>C = transConv↑ (Γ≡Δ ∙ (refl (univ (ℕⱼ ⊢Γ)))) A<>B B<>C
a₀<>c₀ = transConv↑Term Γ≡Δ F[0]≡F₁[0] a₀<>b₀ b₀<>c₀
aₛ<>cₛ = transConv↑Term Γ≡Δ ΠℕFs≡ΠℕF₁s aₛ<>bₛ bₛ<>cₛ
t~v , _ = trans~↓! PE.refl Γ≡Δ t~u u~v
in natrec-cong A<>C a₀<>c₀ aₛ<>cₛ t~v
, substTypeEq A≡B (soundness~↓! t~u)
trans~↑! PE.refl Γ≡Δ (Emptyrec-cong A<>B t~u) (Emptyrec-cong B<>C u~v) =
let ⊢Γ , _ , _ = contextConvSubst Γ≡Δ
A≡B = soundnessConv↑ A<>B
A<>C = transConv↑ Γ≡Δ A<>B B<>C
⊢t , ⊢u , t≡u = soundness~↑% t~u
_ , ⊢v , u≡v = soundness~↑% u~v
t~v = %~↑ ⊢t (stabilityTerm (symConEq Γ≡Δ) ⊢v)
in Emptyrec-cong A<>C t~v , A≡B
trans~↑! el Γ≡Δ (Id-cong X x x₁) (Id-cong Y x₂ x₃) =
let XY , [U] = trans~↓! el Γ≡Δ X Y
X≡Y = univ (soundness~↓! XY)
Y≡Y = PE.subst (λ lx → _ ⊢ _ ≡ _ ^ [ ! , ι lx ]) (PE.sym (next-inj el)) (univ (soundness~↓! Y))
x₂' = PE.subst (λ lx → _ ⊢ _ [conv↑] _ ∷ _ ^ ι lx) (PE.sym (next-inj el)) x₂
t~t = transConv↑Term Γ≡Δ X≡Y x (convConvTerm x₂' Y≡Y)
x₃' = PE.subst (λ lx → _ ⊢ _ [conv↑] _ ∷ _ ^ ι lx) (PE.sym (next-inj el)) x₃
u~u = transConv↑Term Γ≡Δ X≡Y x₁ (convConvTerm x₃' Y≡Y)
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
in Id-cong XY t~t u~u , PE.subst (λ lx → _ ⊢ _ ≡ SProp lx ^ [ ! , _ ]) (next-inj el) (refl (Ugenⱼ ⊢Γ))
trans~↑! el Γ≡Δ (Id-ℕ X x) (Id-ℕ Y x₁) =
let t~t , ℕ≡ℕ = trans~↓! PE.refl Γ≡Δ X Y
u~u = transConv↑Term Γ≡Δ ℕ≡ℕ x x₁
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
in Id-ℕ t~t u~u , refl (Ugenⱼ ⊢Γ)
trans~↑! el Γ≡Δ (Id-ℕ0 X) (Id-ℕ0 Y) =
let t~t , ℕ≡ℕ = trans~↓! PE.refl Γ≡Δ X Y
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
in Id-ℕ0 t~t , refl (Ugenⱼ ⊢Γ)
trans~↑! el Γ≡Δ (Id-ℕS x X) (Id-ℕS x₁ Y) =
let X~X , ℕ≡ℕ = trans~↓! PE.refl Γ≡Δ X Y
t~t = transConv↑Term Γ≡Δ ℕ≡ℕ x x₁
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
in Id-ℕS t~t X~X , refl (Ugenⱼ ⊢Γ)
trans~↑! el Γ≡Δ (Id-U X x) (Id-U Y x₁) =
let t~t , U≡U = trans~↓! PE.refl Γ≡Δ X Y
u~u = transConv↑Term Γ≡Δ U≡U x x₁
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
in Id-U t~t u~u , refl (Ugenⱼ ⊢Γ)
trans~↑! el Γ≡Δ (Id-Uℕ X) (Id-Uℕ Y) =
let t~t , _ = trans~↓! PE.refl Γ≡Δ X Y
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
in Id-Uℕ t~t , refl (Ugenⱼ ⊢Γ)
trans~↑! el Γ≡Δ (Id-UΠ x X) (Id-UΠ x₁ Y) =
let t~t , U≡U = trans~↓! PE.refl Γ≡Δ X Y
u~u = transConv↑Term Γ≡Δ U≡U x x₁
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
in Id-UΠ u~u t~t , refl (Ugenⱼ ⊢Γ)
trans~↑! el Γ≡Δ (cast-cong X x x₁ x₂ x₃) (cast-cong Y x₄ x₅ x₆ x₇) =
let XY , [U] = trans~↓! PE.refl Γ≡Δ X Y
X≡Y = univ (soundness~↓! XY)
Y≡Y = univ (soundness~↓! Y)
t~t = transConv↑Term Γ≡Δ [U] x x₄
u~u = transConv↑Term Γ≡Δ X≡Y x₁ (convConvTerm x₅ Y≡Y)
A₁≡B = trans (soundnessConv↑Term t~t) (sym (soundnessConv↑Term (stabilityConv↑Term (symConEq Γ≡Δ) x₄)))
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
in cast-cong XY t~t u~u x₂ (stabilityTerm (symConEq Γ≡Δ) x₇) , univ A₁≡B
trans~↑! el Γ≡Δ (cast-ℕ X x x₁ x₂) (cast-ℕ Y x₃ x₄ x₅) =
let XY , [U] = trans~↓! PE.refl Γ≡Δ X Y
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
t~t = transConv↑Term Γ≡Δ (refl (univ (ℕⱼ ⊢Γ))) x x₃
in cast-ℕ XY t~t x₁ (stabilityTerm (symConEq Γ≡Δ) x₅) , univ (soundness~↓! X)
trans~↑! el Γ≡Δ (cast-ℕℕ X x x₁) (cast-ℕℕ Y x₂ x₃) =
let XY , N = trans~↓! PE.refl Γ≡Δ X Y
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
in cast-ℕℕ XY x (stabilityTerm (symConEq Γ≡Δ) x₃) , N
trans~↑! el Γ≡Δ (cast-Π x X x₁ x₂ x₃) (cast-Π x₄ Y x₅ x₆ x₇) =
let XY , [U] = trans~↓! PE.refl Γ≡Δ X Y
X≡Y = soundness~↓! XY
Y≡Y = univ (soundnessConv↑Term x₄)
t~t = transConv↑Term Γ≡Δ [U] x x₄
u~u = transConv↑Term Γ≡Δ (univ (soundnessConv↑Term t~t)) x₁ (convConvTerm x₅ Y≡Y)
A₁≡B = trans X≡Y (sym (soundness~↓! (stability~↓! (symConEq Γ≡Δ) Y)))
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
in cast-Π t~t XY u~u x₂ (stabilityTerm (symConEq Γ≡Δ) x₇) , univ A₁≡B
trans~↑! el Γ≡Δ (cast-Πℕ x x₁ x₂ x₃) (cast-Πℕ x₄ x₅ x₆ x₇) =
let Y≡Y = univ (soundnessConv↑Term x₄)
⊢Γ , _ , _ = contextConvSubst Γ≡Δ
t~t = transConv↑Term Γ≡Δ (refl (Ugenⱼ ⊢Γ)) x x₄
u~u = transConv↑Term Γ≡Δ (univ (soundnessConv↑Term t~t)) x₁ (convConvTerm x₅ Y≡Y)
in cast-Πℕ t~t u~u x₂ (stabilityTerm (symConEq Γ≡Δ) x₇) , refl (univ (ℕⱼ ⊢Γ))
trans~↑! el Γ≡Δ (cast-ℕΠ x x₁ x₂ x₃) (cast-ℕΠ x₄ x₅ x₆ x₇) =
let ⊢Γ , _ , _ = contextConvSubst Γ≡Δ
t~t = transConv↑Term Γ≡Δ (refl (Ugenⱼ ⊢Γ)) x x₄
u~u = transConv↑Term Γ≡Δ (refl (univ (ℕⱼ ⊢Γ))) x₁ x₅
in cast-ℕΠ t~t u~u x₂ (stabilityTerm (symConEq Γ≡Δ) x₇) , univ (soundnessConv↑Term x)
trans~↑! el Γ≡Δ (cast-ΠΠ%! x x₁ x₂ x₃ x₄) (cast-ΠΠ%! x₅ x₆ x₇ x₈ x₉) =
let ⊢Γ , _ , _ = contextConvSubst Γ≡Δ
A~A = transConv↑Term Γ≡Δ (refl (Ugenⱼ ⊢Γ)) x x₅
B~B = transConv↑Term Γ≡Δ (refl (Ugenⱼ ⊢Γ)) x₁ x₆
u~u = transConv↑Term Γ≡Δ (univ (soundnessConv↑Term x)) x₂ x₇
in cast-ΠΠ%! A~A B~B u~u x₃ (stabilityTerm (symConEq Γ≡Δ) x₉) ,
trans (univ (soundnessConv↑Term B~B)) (sym (univ (soundnessConv↑Term (stabilityConv↑Term (symConEq Γ≡Δ) x₆))))
trans~↑! el Γ≡Δ (cast-ΠΠ!% x x₁ x₂ x₃ x₄) (cast-ΠΠ!% x₅ x₆ x₇ x₈ x₉) =
let ⊢Γ , _ , _ = contextConvSubst Γ≡Δ
A~A = transConv↑Term Γ≡Δ (refl (Ugenⱼ ⊢Γ)) x x₅
B~B = transConv↑Term Γ≡Δ (refl (Ugenⱼ ⊢Γ)) x₁ x₆
u~u = transConv↑Term Γ≡Δ (univ (soundnessConv↑Term x)) x₂ x₇
in cast-ΠΠ!% A~A B~B u~u x₃ (stabilityTerm (symConEq Γ≡Δ) x₉) ,
trans (univ (soundnessConv↑Term B~B)) (sym (univ (soundnessConv↑Term (stabilityConv↑Term (symConEq Γ≡Δ) x₆))))
trans~↑% : ∀ {t u v A Γ Δ l}
→ ⊢ Γ ≡ Δ
→ Γ ⊢ t ~ u ↑% A ^ l
→ Δ ⊢ u ~ v ↑% A ^ l
→ Γ ⊢ t ~ v ↑% A ^ l
trans~↑% Γ≡Δ (%~↑ ⊢t ⊢u) (%~↑ ⊢u′ ⊢v) =
let ⊢Δu′ = stabilityTerm (symConEq Γ≡Δ) ⊢u′
⊢Δv = stabilityTerm (symConEq Γ≡Δ) ⊢v
in %~↑ ⊢t ⊢Δv
-- Transitivity of algorithmic equality of neutrals with types in WHNF.
trans~↓! : ∀ {t u v A B Γ Δ l l'}
→ l PE.≡ l'
→ ⊢ Γ ≡ Δ
→ Γ ⊢ t ~ u ↓! A ^ l
→ Δ ⊢ u ~ v ↓! B ^ l'
→ Γ ⊢ t ~ v ↓! A ^ l
× Γ ⊢ A ≡ B ^ [ ! , l ]
trans~↓! PE.refl Γ≡Δ ([~] A₁ D whnfA k~l) ([~] A₂ D₁ whnfA₁ k~l₁) =
let t~v , A≡B = trans~↑! PE.refl Γ≡Δ k~l k~l₁
in [~] A₁ D whnfA t~v
, trans (sym (subset* D))
(trans A≡B
(subset* (stabilityRed* (symConEq Γ≡Δ) D₁)))
-- Transitivity of algorithmic equality of types.
transConv↑ : ∀ {A B C r Γ Δ}
→ ⊢ Γ ≡ Δ
→ Γ ⊢ A [conv↑] B ^ r
→ Δ ⊢ B [conv↑] C ^ r
→ Γ ⊢ A [conv↑] C ^ r
transConv↑ {r = r} Γ≡Δ ([↑] A′ B′ D D′ whnfA′ whnfB′ A′<>B′)
([↑] A″ B″ D₁ D″ whnfA″ whnfB″ A′<>B″) =
[↑] A′ B″ D (stabilityRed* (symConEq Γ≡Δ) D″) whnfA′ whnfB″
(transConv↓ Γ≡Δ A′<>B′
(PE.subst (λ x → _ ⊢ x [conv↓] B″ ^ r)
(whrDet* (D₁ , whnfA″)
(stabilityRed* Γ≡Δ D′ , whnfB′))
A′<>B″))
-- Transitivity of algorithmic equality of types in WHNF.
transConv↓ : ∀ {A B C r Γ Δ}
→ ⊢ Γ ≡ Δ
→ Γ ⊢ A [conv↓] B ^ r
→ Δ ⊢ B [conv↓] C ^ r
→ Γ ⊢ A [conv↓] C ^ r
transConv↓ Γ≡Δ (U-refl e x) (U-refl e₁ x₁) = U-refl (PE.trans e e₁) x
transConv↓ Γ≡Δ (univ x) (univ y) =
let ⊢Γ , _ , _ = contextConvSubst Γ≡Δ
X = transConv↓Term Γ≡Δ (refl (Ugenⱼ ⊢Γ )) PE.refl x y
in univ X
-- Transitivity of algorithmic equality of terms.
transConv↑Term : ∀ {t u v A B Γ Δ l}
→ ⊢ Γ ≡ Δ
→ Γ ⊢ A ≡ B ^ [ ! , l ]
→ Γ ⊢ t [conv↑] u ∷ A ^ l
→ Δ ⊢ u [conv↑] v ∷ B ^ l
→ Γ ⊢ t [conv↑] v ∷ A ^ l
transConv↑Term Γ≡Δ A≡B ([↑]ₜ B₁ t′ u′ D d d′ whnfB whnft′ whnfu′ t<>u)
([↑]ₜ B₂ t″ u″ D₁ d₁ d″ whnfB₁ whnft″ whnfu″ t<>u₁) =
let B₁≡B₂ = trans (sym (subset* D))
(trans A≡B
(subset* (stabilityRed* (symConEq Γ≡Δ) D₁)))
d₁″ = conv* (stabilityRed*Term (symConEq Γ≡Δ) d″) (sym B₁≡B₂)
d₁′ = stabilityRed*Term Γ≡Δ (conv* d′ B₁≡B₂)
in [↑]ₜ B₁ t′ u″ D d d₁″ whnfB whnft′ whnfu″
(transConv↓Term Γ≡Δ B₁≡B₂ PE.refl t<>u
(PE.subst (λ x → _ ⊢ x [conv↓] u″ ∷ B₂ ^ _)
(whrDet*Term (d₁ , whnft″)
(d₁′ , whnfu′))
t<>u₁))
-- Transitivity of algorithmic equality of terms in WHNF.
transConv↓Term : ∀ {t u v A B Γ Δ l l'}
→ ⊢ Γ ≡ Δ
→ Γ ⊢ A ≡ B ^ [ ! , l ]
→ l PE.≡ l'
→ Γ ⊢ t [conv↓] u ∷ A ^ l
→ Δ ⊢ u [conv↓] v ∷ B ^ l'
→ Γ ⊢ t [conv↓] v ∷ A ^ l
transConv↓Term {Δ = Δ} Γ≡Δ A≡B el (ne x) (ne x₁) = ne (proj₁ (trans~↓! PE.refl Γ≡Δ x (PE.subst (λ lx → Δ ⊢ _ ~ _ ↓! Univ _ _ ^ lx) (PE.sym el) x₁)))
transConv↓Term Γ≡Δ A≡B el (ℕ-ins x) (ℕ-ins x₁) =
ℕ-ins (proj₁ (trans~↓! PE.refl Γ≡Δ x x₁))
transConv↓Term {Δ = Δ} Γ≡Δ A≡B el (ne-ins t u x x₁) (ne-ins {k} {l} {M} {N} t′ u′ x₂ x₃) =
ne-ins t (conv (stabilityTerm (symConEq Γ≡Δ) (PE.subst (λ lx → Δ ⊢ l ∷ N ^ [ ! , lx ]) (PE.sym el) u′))
(sym A≡B)) x
(proj₁ (trans~↓! PE.refl Γ≡Δ x₁ (PE.subst (λ lx → Δ ⊢ k ~ l ↓! M ^ lx ) (PE.sym el) x₃)))
transConv↓Term Γ≡Δ A≡B el (zero-refl x) (zero-refl x₁) =
zero-refl x
transConv↓Term Γ≡Δ A≡B el (suc-cong x) (suc-cong x₁) =
suc-cong (transConv↑Term Γ≡Δ A≡B x x₁)
transConv↓Term {Δ = Δ} Γ≡Δ A≡B el (η-eq {rF = rF₁} l< l<' x x₁ x₂ y y₁ x₃)
(η-eq {u} {v} {F} {G} {rF} {lF} {lG} {l} l<'' l<''' x₄ x₅ x₆ y₂ y₃ x₇) =
let F₁≡F , rF₁≡rF , lF₁≡lF , lG₁≡lG , G₁≡G = injectivity (PE.subst (λ lx → _ ⊢ _ ≡ Π _ ^ _ ° _ ▹ _ ° _ ° lx ^ _) (ιinj (PE.sym el)) A≡B )
in η-eq l< l<' x x₁ (conv (stabilityTerm (symConEq Γ≡Δ)
(PE.subst (λ lx → Δ ⊢ v ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ ! , lx ]) (PE.sym el) x₆))
(sym A≡B))
y y₃ (transConv↑Term (Γ≡Δ ∙ F₁≡F) G₁≡G x₃
(PE.subst (λ lx → Δ ∙ F ^ [ rF₁ , _ ] ⊢ _ ∘ _ ^ _ [conv↑] wk1 v ∘ var 0 ^ _ ∷ G ^ ι lx)
(PE.sym lG₁≡lG)
(PE.subst (λ lx → Δ ∙ F ^ [ rF₁ , _ ] ⊢ wk1 u ∘ var 0 ^ lx [conv↑] wk1 v ∘ var 0 ^ lx ∷ G ^ ι lG)
(PE.sym (ιinj el))
(PE.subst (λ lx → Δ ∙ F ^ [ rF₁ , lx ] ⊢ wk1 u ∘ var 0 ^ l [conv↑] wk1 v ∘ var 0 ^ l ∷ G ^ ι lG)
(PE.sym (PE.cong ι lF₁≡lF))
(PE.subst (λ rx → Δ ∙ F ^ [ rx , ι lF ] ⊢ _ [conv↑] _ ∷ _ ^ _) (PE.sym rF₁≡rF) x₇)))))
transConv↓Term Γ≡Δ A≡B el (ℕ-refl x) (ℕ-refl x₁) = ℕ-refl x
transConv↓Term Γ≡Δ A≡B el (Empty-refl PE.refl x) (Empty-refl PE.refl x₁) = Empty-refl PE.refl x
transConv↓Term Γ≡Δ A≡B el (U-refl e x) (U-refl e₁ x₁) = U-refl (PE.trans e e₁) x
transConv↓Term Γ≡Δ A≡B el (Π-cong PE.refl PE.refl PE.refl PE.refl l< l<' x₅ x₆ x₇) (Π-cong PE.refl PE.refl PE.refl PE.refl x₁₁ x₁₂ x₁₃ x₁₄ x₁₅) =
let ⊢Γ , _ , _ = contextConvSubst Γ≡Δ
rF≡rF₁ , _ = Uinjectivity A≡B
in Π-cong PE.refl PE.refl PE.refl PE.refl l< l<' x₅ (transConv↑Term Γ≡Δ (refl (Ugenⱼ ⊢Γ )) x₆ x₁₄)
(transConv↑Term (Γ≡Δ ∙ univ (soundnessConv↑Term x₆))
(PE.subst (λ rx → _ ⊢ _ ≡ Univ rx _ ^ _) rF≡rF₁ (refl (Ugenⱼ (⊢Γ ∙ x₅)) ) ) x₇ x₁₅)
transConv↓Term Γ≡Δ A≡B el (∃-cong PE.refl x₅ x₆ x₇) (∃-cong PE.refl x₁₃ x₁₄ x₁₅) =
let ⊢Γ , _ , _ = contextConvSubst Γ≡Δ
rF≡rF₁ , _ = Uinjectivity A≡B
in ∃-cong PE.refl x₅ (transConv↑Term Γ≡Δ (refl (Ugenⱼ ⊢Γ )) x₆ (PE.subst (λ l → _ ⊢ _ [conv↑] _ ∷ SProp l ^ next l) (next-inj (PE.sym el)) x₁₄ ))
(transConv↑Term (Γ≡Δ ∙ univ (soundnessConv↑Term x₆)) (refl (Ugenⱼ (⊢Γ ∙ x₅))) x₇
(PE.subst (λ l → _ ∙ _ ^ [ % , ι l ] ⊢ _ [conv↑] _ ∷ SProp l ^ next l) (next-inj (PE.sym el)) x₁₅ ))
transConv↓Term Γ≡Δ A≡B PE.refl (ℕ-refl x) (η-eq x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈) = ⊥-elim (WF.U≢Π! A≡B)
transConv↓Term Γ≡Δ A≡B el (Empty-refl {l} PE.refl x) (η-eq x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈) =
let X = PE.subst (λ lx → _ ⊢ SProp l ≡ Π _ ^ _ ° _ ▹ _ ° _ ° _ ^ [ _ , lx ]) el A≡B
in ⊥-elim (WF.U≢Π! X)
transConv↓Term Γ≡Δ A≡B el (Π-cong {rΠ = rΠ} {lΠ = lΠ} x x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₀) (η-eq x₈ x₉ x₁₀ x₁₁ x₁₂ x₁₃ x₁₄ x₁₅) =
let X = PE.subst (λ lx → _ ⊢ Univ rΠ lΠ ≡ Π _ ^ _ ° _ ▹ _ ° _ ° _ ^ [ _ , lx ]) el A≡B
in ⊥-elim (WF.U≢Π! X)
transConv↓Term Γ≡Δ A≡B el (∃-cong {l = l} x₅ x₆ x₇ x₀) (η-eq x₈ x₉ x₁₀ x₁₁ x₁₂ x₁₃ x₁₄ x₁₅) =
let X = PE.subst (λ lx → _ ⊢ SProp l ≡ Π _ ^ _ ° _ ▹ _ ° _ ° _ ^ [ _ , lx ]) el A≡B
in ⊥-elim (WF.U≢Π! X)
transConv↓Term Γ≡Δ A≡B el (ne x) (ℕ-ins x₁) = ⊥-elim (WF.U≢ℕ! A≡B)
transConv↓Term Γ≡Δ A≡B PE.refl (ne x) (ne-ins x₁ x₂ x₃ x₄) = ⊥-elim (WF.U≢ne! x₃ A≡B)
transConv↓Term Γ≡Δ A≡B PE.refl (ne x) (η-eq x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈) = ⊥-elim (WF.U≢Π! A≡B)
--transConv↓Term Γ≡Δ A≡B el (zero-refl x) (zero-refl x₁) = {!!}
transConv↓Term Γ≡Δ A≡B el (ℕ-ins x) (ne-ins t u x₂ x₃) = ⊥-elim (WF.ℕ≢ne! x₂ A≡B)
transConv↓Term Γ≡Δ A≡B PE.refl (ℕ-ins x) (η-eq _ _ x₂ x₃ x₄ y y₁ x₅) = ⊥-elim (WF.ℕ≢Π! A≡B)
transConv↓Term Γ≡Δ A≡B el (ℕ-ins x) (ne x₁) = ⊥-elim (WF.U≢ℕ! (sym A≡B))
transConv↓Term Γ≡Δ A≡B PE.refl (ne-ins x x₁ x₂ x₃) (ne x₄) = ⊥-elim (WF.U≢ne! x₂ (sym A≡B))
transConv↓Term Γ≡Δ A≡B PE.refl (ne-ins t u x x₁) (ℕ-ins x₂) =
⊥-elim (WF.ℕ≢ne! x (sym A≡B))
transConv↓Term Γ≡Δ A≡B PE.refl (ne-ins x x₁ x₂ x₃) (η-eq x₄ x₅ x₆ x₇ x₈ x₉ x₁₀ x₁₁) = ⊥-elim (WF.Π≢ne x₂ (sym A≡B))
transConv↓Term Γ≡Δ A≡B PE.refl (zero-refl x) (η-eq x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈) = ⊥-elim (WF.ℕ≢Π! A≡B)
transConv↓Term Γ≡Δ A≡B PE.refl (suc-cong x) (η-eq x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈) = ⊥-elim (WF.ℕ≢Π! A≡B)
transConv↓Term Γ≡Δ A≡B el (η-eq x x₁ x₂ x₃ x₄ x₅ x₆ x₇) (ne x₈) = ⊥-elim (WF.U≢Π! (sym A≡B))
transConv↓Term Γ≡Δ A≡B el (η-eq x x₁ x₂ x₃ x₄ x₅ x₆ x₇) (ℕ-refl x₈) = ⊥-elim (WF.U≢Π! (sym A≡B))
transConv↓Term Γ≡Δ A≡B el (η-eq x x₁ x₂ x₃ x₄ x₅ x₆ x₇) (Empty-refl x₀ x₈) = ⊥-elim (WF.U≢Π! (sym A≡B))
transConv↓Term Γ≡Δ A≡B el (η-eq x x₁ x₂ x₃ x₄ x₅ x₆ x₇) (Π-cong x₀ x₈ x₉ x₁₀ x₁₁ x₁₂ x₁₃ x₁₄ x₁₅) = ⊥-elim (WF.U≢Π! (sym A≡B))
transConv↓Term Γ≡Δ A≡B el (η-eq x x₁ x₂ x₃ x₄ x₅ x₆ x₇) (∃-cong x₀ x₁₃ x₁₄ x₁₅) = ⊥-elim (WF.U≢Π! (sym A≡B))
transConv↓Term Γ≡Δ A≡B PE.refl (η-eq x x₁ x₂ x₃ x₄ x₅ x₆ x₇) (ℕ-ins x₈) = ⊥-elim (WF.ℕ≢Π! (sym A≡B))
transConv↓Term Γ≡Δ A≡B el (η-eq x x₁ x₂ x₃ x₄ x₅ x₆ x₇) (ne-ins x₈ x₉ x₁₀ x₁₁) = ⊥-elim (WF.Π≢ne x₁₀ A≡B)
transConv↓Term Γ≡Δ A≡B PE.refl (η-eq x x₁ x₂ x₃ x₄ x₅ x₆ x₇) (zero-refl x₈) = ⊥-elim (WF.ℕ≢Π! (sym A≡B))
transConv↓Term Γ≡Δ A≡B PE.refl (η-eq x x₁ x₂ x₃ x₄ x₅ x₆ x₇) (suc-cong x₈) = ⊥-elim (WF.ℕ≢Π! (sym A≡B))
-- Transitivity of algorithmic equality of types of the same context.
transConv : ∀ {A B C r Γ}
→ Γ ⊢ A [conv↑] B ^ r
→ Γ ⊢ B [conv↑] C ^ r
→ Γ ⊢ A [conv↑] C ^ r
transConv A<>B B<>C =
let Γ≡Γ = reflConEq (wfEq (soundnessConv↑ A<>B))
in transConv↑ Γ≡Γ A<>B B<>C
-- Transitivity of algorithmic equality of terms of the same context.
transConvTerm : ∀ {t u v A Γ l}
→ Γ ⊢ t [conv↑] u ∷ A ^ l
→ Γ ⊢ u [conv↑] v ∷ A ^ l
→ Γ ⊢ t [conv↑] v ∷ A ^ l
transConvTerm t<>u u<>v =
let t≡u = soundnessConv↑Term t<>u
Γ≡Γ = reflConEq (wfEqTerm t≡u)
⊢A , _ , _ = syntacticEqTerm t≡u
in transConv↑Term Γ≡Γ (refl ⊢A) t<>u u<>v
trans~↑!Term : ∀ {t u v A Γ l}
→ Γ ⊢ t ~ u ↑% A ^ l
→ Γ ⊢ u ~ v ↑% A ^ l
→ Γ ⊢ t ~ v ↑% A ^ l
trans~↑!Term t<>u u<>v =
let _ , _ , t≡u = soundness~↑% t<>u
Γ≡Γ = reflConEq (wfEqTerm t≡u)
in trans~↑% Γ≡Γ t<>u u<>v
|
{
"alphanum_fraction": 0.5115045151,
"avg_line_length": 53.701369863,
"ext": "agda",
"hexsha": "bcc2c945fb9a41aab660cc3e1a8ccdc339530da7",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/Conversion/Transitivity.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/Conversion/Transitivity.agda",
"max_line_length": 150,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/Conversion/Transitivity.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 9898,
"size": 19601
}
|
------------------------------------------------------------------------
-- Mixfix operator grammars, and parsing of mixfix operators
--
-- Nils Anders Danielsson
------------------------------------------------------------------------
module Mixfix where
-- There are two separate developments here. One is very close to the
-- paper "Parsing Mixfix Operators" (by me and Ulf Norell), and uses
-- directed acyclic precedence graphs and grammars which are neither
-- left nor right recursive. The other uses precedence graphs which
-- may be cyclic and grammars which can be both left and right
-- recursive (following an alternative definition of grammars given in
-- the paper). The two grammar schemes are equivalent when restricted
-- to acyclic precedence graphs.
-- The grammars which use DAGs have the advantage that they can be
-- implemented using a larger variety of parser combinator libraries.
-- This could lead to a more efficient implementation. On the other
-- hand the definition of the other grammars does not attempt to avoid
-- left and right recursion, which means that it is arguably a bit
-- easier to understand and work with (compare the proofs in
-- Mixfix.Acyclic.Show and Mixfix.Cyclic.Show, for instance).
------------------------------------------------------------------------
-- Shared code
-- Fixity and associativity.
import Mixfix.Fixity
-- Operators.
import Mixfix.Operator
-- Precedence-correct expressions, parametrised on abstract precedence
-- graphs.
import Mixfix.Expr
------------------------------------------------------------------------
-- Acyclic graphs
-- A custom-made parser combinator library (with a formal semantics).
import Mixfix.Acyclic.Lib
-- Acyclic precedence graphs.
import Mixfix.Acyclic.PrecedenceGraph
-- Mixfix operator grammars. The resulting expressions are
-- precedence-correct by construction.
import Mixfix.Acyclic.Grammar
-- A minor lemma.
import Mixfix.Acyclic.Lemma
-- Linearisation of operators, and a proof showing that all the
-- generated strings are syntactically correct (although perhaps
-- ambiguous). If the result is combined with the one in
-- Mixfix.Cyclic.Uniqueness we get that every expression has a unique
-- representation. (Two different expressions may have the same
-- representation, though.)
import Mixfix.Acyclic.Show
-- An example.
import Mixfix.Acyclic.Example
------------------------------------------------------------------------
-- Cyclic graphs
-- A custom-made parser combinator library (with a formal semantics).
import Mixfix.Cyclic.Lib
-- Cyclic precedence graphs. (These graphs are not used below, because
-- Mixfix.Cyclic.Grammar can handle arbitrary precedence graphs.)
import Mixfix.Cyclic.PrecedenceGraph
-- Mixfix operator grammars. The resulting expressions are
-- precedence-correct by construction.
import Mixfix.Cyclic.Grammar
-- A constructive proof (i.e. a "show" function) showing that every
-- expression has at least one representation.
import Mixfix.Cyclic.Show
-- A proof showing that every expression has at most one
-- representation.
import Mixfix.Cyclic.Uniqueness
-- An example.
import Mixfix.Cyclic.Example
------------------------------------------------------------------------
-- Equivalence
-- For acyclic precedence graphs the two grammar definitions above are
-- equivalent.
-- Note that this proof only establishes language equivalence, not
-- parser equivalence (see TotalParserCombinators.Semantics). In other
-- words, the two definitions are seen as equivalent if they yield the
-- same language, even though the number of parse trees corresponding
-- to a certain (input string, result)-pair may vary between the two
-- definitions. For instance, when parsing the string s using one
-- grammar the result could contain the expression e once, whereas
-- parsing with the other grammar could yield a result containing two
-- copies of e. This is not a big problem: syntactic equality of
-- expressions is decidable, so extra occurrences of e can be filtered
-- out. The same considerations apply to the equivalence proofs in
-- Mixfix.Acyclic.Lib and Mixfix.Cyclic.Lib. Note that I believe that
-- it is easy (but tedious) to strengthen all these proofs so that
-- parser equivalence is established, but I have not tried to do this.
import Mixfix.Equivalence
|
{
"alphanum_fraction": 0.7000691085,
"avg_line_length": 33.9140625,
"ext": "agda",
"hexsha": "a2d56bb58df473552b8f1d0829ba847bfa8047fa",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "Mixfix.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "Mixfix.agda",
"max_line_length": 72,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "Mixfix.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 873,
"size": 4341
}
|
import Lvl
open import Functional
open import Logic.Propositional{Lvl.𝟎}
open import Logic.Predicate{Lvl.𝟎}{Lvl.𝟎}
open import Logic.Propositional.Theorems{Lvl.𝟎}
open import Relator.Equals{Lvl.𝟎}{Lvl.𝟎} renaming (_≡_ to _≡ₑ_)
open import Type{Lvl.𝟎}
-- Based on https://plato.stanford.edu/entries/set-theory-constructive/axioms-CZF-IZF.html (2017-10-13)
module Sets.IZF (S : Set(Lvl.𝟎)) (_∈_ : S → S → Stmt) where
module Relations where
_∉_ : S → S → Stmt
_∉_ x a = ¬(x ∈ a)
_⊆_ : S → S → Stmt
_⊆_ a b = (∀{x} → (x ∈ a) → (x ∈ b))
_⊇_ : S → S → Stmt
_⊇_ a b = (∀{x} → (x ∈ a) ← (x ∈ b))
_≡_ : S → S → Stmt
_≡_ a b = (∀{x} → (x ∈ a) ↔ (x ∈ b))
-- The statement that the set s is empty
Empty : S → Stmt
Empty(s) = (∀{x} → (x ∉ s))
-- The statement that the set s is inhabited/non-empty
NonEmpty : S → Stmt
NonEmpty(s) = ∃(x ↦ (x ∈ s))
-- The statement that the set s is a singleton set containing only the single element x₁
Singleton : S → S → Stmt
Singleton(s) (x₁) = (∀{x} → (x ∈ s) ↔ (x ≡ x₁))
-- The statement that the set s is a pair set containing only the two elements x₁, x₂
Pair : S → S → S → Stmt
Pair(s) (x₁)(x₂) = (∀{x} → (x ∈ s) ↔ (x ≡ x₁)∨(x ≡ x₂))
-- The statement that the set sᵤ is the union of the sets s₁, s₂
Union : S → S → S → Stmt
Union(sᵤ) (s₁)(s₂) = (∀{x} → (x ∈ sᵤ) ↔ (x ∈ s₁)∨(x ∈ s₂))
-- The statement that the set sᵤ is the intersection of the sets s₁, s₂
Intersection : S → S → S → Stmt
Intersection(sᵢ) (s₁)(s₂) = (∀{x} → (x ∈ sᵢ) ↔ (x ∈ s₁)∧(x ∈ s₂))
-- The statement that the set sₚ is the power set of s
Power : S → S → Stmt
Power(sₚ) (s) = (∀{x} → (x ∈ sₚ) ↔ (x ⊆ s))
-- The statement that the set sᵤ is the union of all sets in ss
UnionAll : S → S → Stmt
UnionAll(sᵤ) (ss) = (∀{x s} → (x ∈ sᵤ) ↔ (x ∈ s)∧(s ∈ ss))
-- The statement that the set sᵤ is the intersection of all sets in ss
IntersectionAll : S → S → Stmt
IntersectionAll(sᵢ) (ss) = (∀{x} → (x ∈ sᵢ) ↔ (∀{s} → (s ∈ ss) → (x ∈ s)))
-- The statement that the set sₛ is the subset of s where every element satisfies φ
FilteredSubset : S → (s : S) → ((x : S) → ⦃ _ : (x ∈ s) ⦄ → Stmt) → Stmt
FilteredSubset(sₛ) (s)(φ) = (∀{x} → (x ∈ sₛ) ↔ ∃{x ∈ s}(proof ↦ φ(x) ⦃ proof ⦄))
module RelationsTheorems where
open Relations
[≡]-reflexivity : ∀{s} → (s ≡ s)
[≡]-reflexivity = [↔]-reflexivity
[≡]-transitivity : ∀{s₁ s₂ s₃} → (s₁ ≡ s₂) → (s₂ ≡ s₃) → (s₁ ≡ s₃)
[≡]-transitivity(s12)(s23){x} = [↔]-transitivity(s12{x})(s23{x})
[≡]-symmetry : ∀{s₁ s₂} → (s₁ ≡ s₂) → (s₂ ≡ s₁)
[≡]-symmetry(s12){x} = [↔]-symmetry(s12{x})
-- TODO: Are these even provable with my def. of set equality?
-- [≡]-substitute : ∀{φ : S → Stmt}{s₁ s₂} → (s₁ ≡ s₂) → ∀{x} → φ(s₁) ↔ φ(s₂)
-- [≡]-substituteₗ : ∀{φ : Stmt → Stmt}{s₁ s₂} → (s₁ ≡ s₂) → ∀{x} → φ(s₁ ∈ x) ↔ φ(s₂ ∈ x)
[⊆]-reflexivity : ∀{s} → (s ⊆ s)
[⊆]-reflexivity = [→]-reflexivity
[⊆]-transitivity : ∀{s₁ s₂ s₃} → (s₁ ⊆ s₂) → (s₂ ⊆ s₃) → (s₁ ⊆ s₃)
[⊆]-transitivity(s12)(s23){x} = [→]-transitivity(s12{x})(s23{x})
[⊆]-antisymmetry : ∀{s₁ s₂} → (s₁ ⊇ s₂) → (s₁ ⊆ s₂) → (s₁ ≡ s₂)
[⊆]-antisymmetry(s21)(s12){x} = [↔]-intro (s21{x}) (s12{x})
module Axioms1 where
open Relations
-- Axiom of extensionality
-- Sets are equal when they have the same elements.
record SetEquality : Set(Lvl.𝟎) where
field equality : ∀{s₁ s₂} → (s₁ ≡ s₂) → (s₁ ≡ₑ s₂)
open SetEquality ⦃ ... ⦄ public
-- Axiom of the empty set
-- A set which is empty exists.
record EmptySetExistence : Set(Lvl.𝟎) where
field empty : ∃(s ↦ Empty(s))
open EmptySetExistence ⦃ ... ⦄ public
-- Axiom of pairing
-- A set with two elements exists.
record PairExistence : Set(Lvl.𝟎) where
field pair : ∀{x₁ x₂} → ∃(s ↦ Pair(s)(x₁)(x₂))
open PairExistence ⦃ ... ⦄ public
-- Axiom of union
-- A set which contains all the elements of a group of sets exists.
record UnionExistence : Set(Lvl.𝟎) where
field union : ∀{ss} → ∃(sᵤ ↦ UnionAll(sᵤ)(ss))
open UnionExistence ⦃ ... ⦄ public
-- Axiom of the power set
-- A set which contains all the subsets of a set exists.
record PowerSetExistence : Set(Lvl.𝟎) where
field power : ∀{s} → ∃(sₚ ↦ Power(sₚ)(s))
open PowerSetExistence ⦃ ... ⦄ public
-- Axiom schema of restricted comprehension | Axiom schema of specification | Axiom schema of separation
-- A set which is the subset of a set where all elements satisfies a predicate exists.
record RestrictedComprehensionExistence : Set(Lvl.𝐒(Lvl.𝟎)) where
field comprehension : ∀{s}{φ : (x : S) → ⦃ _ : (x ∈ s) ⦄ → Stmt} → ∃(sₛ ↦ FilteredSubset(sₛ)(s)(φ))
open RestrictedComprehensionExistence ⦃ ... ⦄ public
-- Axiom schema of collection
-- A set which collects all RHS in a binary relation (and possibly more elements) exists.
-- The image of a function has a superset?
-- Detailed explanation:
-- Given a set a and a formula φ:
-- If ∀(x∊a)∃y. φ(x)(y)
-- The binary relation φ describes a total multivalued function from the set a to b:
-- φ: a→b
-- Note: φ is not neccessarily a set.
-- Then ∃b∀(x∊a)∃(y∊b). φ(x)(y)
-- There exists a set b such that every argument of the function has one of its function values in it.
record CollectionAxiom : Set(Lvl.𝐒(Lvl.𝟎)) where
field collection : ∀{φ : S → S → Stmt} → ∀{a} → (∀{x} → (x ∈ a) → ∃(y ↦ φ(x)(y))) → ∃(b ↦ ∀{x} → (x ∈ a) → ∃(y ↦ ((y ∈ b) ∧ φ(x)(y))))
open CollectionAxiom ⦃ ... ⦄ public
-- Induction proof on sets.
-- This can be used to prove stuff about all sets.
-- This can be interpreted as:
-- A proof of a predicate satisfying every element of an arbitrary set is a proof of this predicate satisfying every set.
record InductionProof : Set(Lvl.𝐒(Lvl.𝟎)) where
field induction : ∀{φ : S → Stmt} → (∀{s} → (∀{x} → (x ∈ s) → φ(x)) → φ(s)) → (∀{s} → φ(s))
open InductionProof ⦃ ... ⦄ public
module Theorems1 where
open Axioms1
open Relations
module _ ⦃ _ : PairExistence ⦄ where
-- A set with only one element exists.
single : ∀{x₁} → ∃(s ↦ (∀{x} → (x ∈ s) ↔ (x ≡ x₁)))
single{x} with pair{x}{x}
... | [∃]-intro (z) ⦃ f ⦄ = ([∃]-intro (z) ⦃ \{w} → [↔]-transitivity (f{w}) [∨]-redundancy ⦄)
module _ ⦃ _ : EmptySetExistence ⦄ where
[∅]-uniqueness : ∀{x y} → Empty(x) → Empty(y) → (x ≡ y)
[∅]-uniqueness (empty-x)(empty-y) =
([↔]-intro
([⊥]-elim ∘ empty-y)
([⊥]-elim ∘ empty-x)
)
{-
Singleton-elem-uniqueness : ∀{x y₁ y₂} → (y₁ ∈ Singleton(x)) → (y₂ ∈ Singleton(x)) → (y₁ ≡ y₂)
Singleton-elem-uniqueness (y₁-proof)(y₂-proof) =
([↔]-intro
(y₁-proof)
(y₂-proof)
)
-}
module Operations where
open Axioms1
open Relations
open Theorems1
module _ ⦃ _ : EmptySetExistence ⦄ where
-- Definition of the empty set: ∅={}.
-- This can be used to construct a set with no elements.
∅ : S
∅ = [∃]-witness(empty)
module _ ⦃ _ : PairExistence ⦄ where
-- Definition of a singleton set: {x} for some element x.
-- This can be used to construct a set with a single element.
• : S → S
•(x) = [∃]-witness(single{x})
-- Definition of a pair set: {x,y} for some elements x and y.
-- This can be used to construct a set with a countable number of elements: x⟒y⟒z.
_⟒_ : S → S → S
_⟒_ (x)(y) = [∃]-witness(pair{x}{y})
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ where
-- Definition of the union of two sets: s₁∪s₂ for two sets s₁ and s₂.
-- This can be used to construct a set that contains all elements from either of the two sets.
_∪_ : S → S → S
_∪_ s₁ s₂ = [∃]-witness(union{s₁ ⟒ s₂})
module _ ⦃ _ : UnionExistence ⦄ where
-- Definition of the union of a set of sets: ⋃(ss) for a set of sets ss.
-- This can be used to construct a set that contains all elements from the sets.
reduce-[∪] : S → S
reduce-[∪] ss = [∃]-witness(union{ss})
module _ ⦃ _ : PowerSetExistence ⦄ where
-- Definition of the power set of a set: ℘(s) for some set s.
-- This can be used to construct a set that contains all subsets of a set.
℘ : S → S
℘(s) = [∃]-witness(power{s})
module _ ⦃ _ : RestrictedComprehensionExistence ⦄ where
-- Definition of the usual "set builder notation": {(x∊s). φ(x)} for some set s.
-- This can be used to construct a set that is the subset which satisfies a certain predicate for every element.
filter : S → (S → Stmt) → S
filter(s)(φ) = [∃]-witness(comprehension{s}{x ↦ \ ⦃ _ ⦄ → φ(x)})
-- Definition of a "set builder notation": {(x∊s). φ(x)} for some set s where the predicate φ gets a proof of (x∈s).
-- This can be used to construct a set that is the subset which satisfies a certain predicate for every element.
filter-dep : (s : S) → ((x : S) → ⦃ _ : (x ∈ s) ⦄ → Stmt) → S
filter-dep(s)(φ) = [∃]-witness(comprehension{s}{φ})
-- Definition of the intersection of two sets: s₁∩s₂ for two sets s₁ and s₂.
-- This can be used to construct a set that contains all elements that only are in both sets.
_∩_ : S → S → S
_∩_ (s₁)(s₂) = filter(s₁)(x ↦ (x ∈ s₂))
-- Definition of the subtraction of two sets: s₁∖s₂ for two sets s₁ and s₂.
-- This can be used to construct a set that contains all elements from s₁ which is not in s₂.
_∖_ : S → S → S
_∖_ (s₁)(s₂) = filter(s₁)(_∉ s₂)
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : RestrictedComprehensionExistence ⦄ where
-- Definition of the intersection of a set of sets: ⋂(ss) for a set of sets ss.
-- This can be used to construct a set that only contains the elements which all the sets have in common.
reduce-[∩] : S → S
reduce-[∩] ss = filter(reduce-[∪] (ss))(x ↦ ∀{s} → (s ∈ ss) → (x ∈ s))
module OperationsTheorems where
open Axioms1
open Operations
open Relations
open Theorems1
open Relations
open RelationsTheorems
-- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Containment
module _ ⦃ _ : EmptySetExistence ⦄ where
[∅]-containment : Empty(∅)
[∅]-containment = [∃]-proof(empty)
module _ ⦃ _ : PairExistence ⦄ where
[•]-containment : ∀{x₁} → (x₁ ∈ •(x₁))
[•]-containment{x₁} = [↔]-elimₗ([∃]-proof(single{x₁})) ([≡]-reflexivity)
[⟒]-containment : ∀{x₁ x₂}{x} → (x ∈ (x₁ ⟒ x₂)) ↔ (x ≡ x₁)∨(x ≡ x₂)
[⟒]-containment{x₁}{x₂} = [∃]-proof(pair{x₁}{x₂})
[⟒]-containmentₗ : ∀{x₁ x₂} → (x₁ ∈ (x₁ ⟒ x₂))
[⟒]-containmentₗ{x₁}{x₂} = [↔]-elimₗ([∃]-proof(pair{x₁}{x₂})) ([∨]-introₗ([≡]-reflexivity))
[⟒]-containmentᵣ : ∀{x₁ x₂} → (x₂ ∈ (x₁ ⟒ x₂))
[⟒]-containmentᵣ{x₁}{x₂} = [↔]-elimₗ([∃]-proof(pair{x₁}{x₂})) ([∨]-introᵣ([≡]-reflexivity))
module _ ⦃ _ : RestrictedComprehensionExistence ⦄ where
filter-dep-containment : ∀{s}{φ}{x} → (x ∈ filter-dep(s)(φ)) ↔ (∃{x ∈ s}(proof ↦ φ(x) ⦃ proof ⦄))
filter-dep-containment{s} = [∃]-proof(comprehension)
test : ∀{s}{φ}{x} → (x ∈ filter-dep(s)(φ)) → (∃{x ∈ s}(proof ↦ φ(x) ⦃ proof ⦄))
test{s} = [↔]-elimᵣ (filter-dep-containment)
test2 : ∀{s}{φ}{x} → (x ∈ filter-dep(s)(φ)) → (x ∈ s)
test2(a) = [∃]-witness (test(a))
-- TODO: ?
-- test3 : ∀{s}{φ}{x} → (x ∈ filter-dep(s)(φ)) → ⦃ _ : (x ∈ s) ⦄ → φ(x)
-- test3(a) ⦃ _ ⦄ = [∃]-proof (test(a))
postulate filter-containment : ∀{s}{φ}{x} → (x ∈ filter(s)(φ)) ↔ ((x ∈ s) ∧ φ(x))
-- filter-containment{s} = [∃]-proof(comprehension)
[∩]-containment : ∀{s₁ s₂}{x} → (x ∈ (s₁ ∩ s₂)) ↔ (x ∈ s₁)∧(x ∈ s₂)
[∩]-containment = filter-containment
module _ ⦃ _ : UnionExistence ⦄ where
postulate reduce-[∪]-containment : ∀{ss}{x} → (x ∈ reduce-[∪] (ss)) ↔ ∃(s ↦ (s ∈ ss)∧(x ∈ s))
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ where
[∪]-containment : ∀{s₁ s₂}{x} → (x ∈ (s₁ ∪ s₂)) ↔ (x ∈ s₁)∨(x ∈ s₂)
[∪]-containment = [↔]-intro [∪]-containmentₗ [∪]-containmentᵣ where
postulate [∪]-containmentₗ : ∀{s₁ s₂}{x} → (x ∈ (s₁ ∪ s₂)) ← (x ∈ s₁)∨(x ∈ s₂)
postulate [∪]-containmentᵣ : ∀{s₁ s₂}{x} → (x ∈ (s₁ ∪ s₂)) → (x ∈ s₁)∨(x ∈ s₂)
module _ ⦃ _ : PowerSetExistence ⦄ where
[℘]-containment : ∀{s sₛ} → (sₛ ⊆ s) ↔ (sₛ ∈ ℘(s))
[℘]-containment{s} = [↔]-symmetry([∃]-proof(power{s}))
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : RestrictedComprehensionExistence ⦄ where
postulate reduce-[∩]-containment : ∀{ss}{x} → (x ∈ reduce-[∪] (ss)) ↔ (∀{s} → (s ∈ ss) → (x ∈ s))
-- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Other
module _ ⦃ _ : EmptySetExistence ⦄ where
[∅]-in-subset : ∀{s} → (∅ ⊆ s)
[∅]-in-subset = [⊥]-elim ∘ [∅]-containment
module _ ⦃ _ : EmptySetExistence ⦄ ⦃ _ : PowerSetExistence ⦄ where
[℘][∅]-containment : ∀{s} → (∅ ∈ ℘(s))
[℘][∅]-containment = [↔]-elimᵣ([℘]-containment)([∅]-in-subset)
module _ ⦃ _ : PowerSetExistence ⦄ where
[℘]-set-containment : ∀{s} → (s ∈ ℘(s))
[℘]-set-containment = [↔]-elimᵣ([℘]-containment)([⊆]-reflexivity)
module _ ⦃ _ : InductionProof ⦄ where
self-noncontainment : ∀{s} → (s ∉ s) -- ¬ ∃(s ↦ s ∈ s)
self-noncontainment = induction{x ↦ x ∉ x} (proof) where
proof : ∀{s} → (∀{x} → (x ∈ s) → (x ∉ x)) → (s ∉ s)
proof{s} (f)(s∈s) = f{s}(s∈s)(s∈s)
-- ∀{s} → (∀{x} → (x ∈ s) → (x ∉ x)) → (s ∉ s)
-- ∀{s} → (∀{x} → (x ∈ s) → (x ∈ x) → ⊥) → (s ∈ s) → ⊥
[𝐔]-nonexistence : ¬ ∃(𝐔 ↦ ∀{x} → (x ∈ 𝐔))
[𝐔]-nonexistence ([∃]-intro(𝐔) ⦃ proof ⦄) = self-noncontainment {𝐔} (proof{𝐔})
-- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Subset
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : RestrictedComprehensionExistence ⦄ where
postulate reduce-[∪]-subset : ∀{ss}{s} → (s ∈ ss) → (s ⊆ reduce-[∪] (ss))
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ where
[∪]-subsetₗ : ∀{s₁ s₂} → (s₁ ⊆ (s₁ ∪ s₂))
[∪]-subsetₗ = ([↔]-elimₗ([∪]-containment)) ∘ [∨]-introₗ
[∪]-subsetᵣ : ∀{s₁ s₂} → (s₂ ⊆ (s₁ ∪ s₂))
[∪]-subsetᵣ = ([↔]-elimₗ([∪]-containment)) ∘ [∨]-introᵣ
postulate [∪]-subset-eq : ∀{s₁ s₂ s₃} → ((s₁ ∪ s₂) ⊆ s₃) ↔ ((s₁ ⊆ s₃)∧(s₂ ⊆ s₃))
module _ ⦃ _ : RestrictedComprehensionExistence ⦄ where
[∩]-subsetₗ : ∀{s₁ s₂} → ((s₁ ∩ s₂) ⊆ s₁)
[∩]-subsetₗ = [∧]-elimₗ ∘ ([↔]-elimᵣ([∩]-containment))
[∩]-subsetᵣ : ∀{s₁ s₂} → ((s₁ ∩ s₂) ⊆ s₂)
[∩]-subsetᵣ = [∧]-elimᵣ ∘ ([↔]-elimᵣ([∩]-containment))
filter-dep-subset : ∀{s}{φ} → (filter-dep(s)(φ) ⊆ s)
filter-dep-subset{s}{φ} {x}(x∈s) = [∃]-witness([↔]-elimᵣ(filter-dep-containment{s}{φ})(x∈s))
filter-subset : ∀{s}{φ} → (filter(s)(φ) ⊆ s)
filter-subset{s}{φ} {x}(x∈s) = [∧]-elimₗ([↔]-elimᵣ(filter-containment{s}{φ})(x∈s))
module _ ⦃ _ : PowerSetExistence ⦄ where
[℘]-subset : ∀{s₁ s₂} → (s₁ ⊆ s₂) ↔ (℘(s₁) ⊆ ℘(s₂))
[℘]-subset = [↔]-intro l r where
l : ∀{s₁ s₂} → (s₁ ⊆ s₂) ← (℘(s₁) ⊆ ℘(s₂))
l {s₁}{s₂} (p1p2) = ([↔]-elimₗ [℘]-containment) (p1p2{s₁} ([℘]-set-containment))
r : ∀{s₁ s₂} → (s₁ ⊆ s₂) → (℘(s₁) ⊆ ℘(s₂))
r {s₁}{s₂} (s12) {a} (aps1) = ([↔]-elimᵣ [℘]-containment) ([⊆]-transitivity (([↔]-elimₗ [℘]-containment) aps1) (s12))
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : RestrictedComprehensionExistence ⦄ where
postulate reduce-[∩]-subset : ∀{ss}{s} → (s ∈ ss) → (reduce-[∩] (ss) ⊆ s)
-- TODO: Does this hold: Empty(s) ∨ NonEmpty(s) ? Probably not
-- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Commutativity
-- [⟒]-commutativity : ∀{s₁ s₂} → (s₁ ⟒ s₂) ≡ (s₂ ⟒ s₁)
-- [⟒]-commutativity{s₁}{s₂} {x} = [↔]-intro (f{s₂}{s₁}) (f{s₁}{s₂}) where
-- f : ∀{s₁ s₂} → (x ∈ (s₁ ⟒ s₂)) → (x ∈ (s₂ ⟒ s₁))
-- f{s₁}{s₂} = ([↔]-elimₗ([⟒]-containment{s₂}{s₁}{x})) ∘ ([∨]-symmetry) ∘ ([↔]-elimᵣ([∪]-containment{s₁}{s₂}{x}))
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ where
[∪]-commutativity : ∀{s₁ s₂} → (s₁ ∪ s₂) ≡ (s₂ ∪ s₁)
[∪]-commutativity{s₁}{s₂} {x} = [↔]-intro (f{s₂}{s₁}) (f{s₁}{s₂}) where
f : ∀{s₁ s₂} → (x ∈ (s₁ ∪ s₂)) → (x ∈ (s₂ ∪ s₁))
f{s₁}{s₂} =
([↔]-elimₗ([∪]-containment{s₂}{s₁}{x}))
∘ ([∨]-symmetry)
∘ ([↔]-elimᵣ([∪]-containment{s₁}{s₂}{x}))
module _ ⦃ _ : RestrictedComprehensionExistence ⦄ where
[∩]-commutativity : ∀{s₁ s₂} → (s₁ ∩ s₂) ≡ (s₂ ∩ s₁)
[∩]-commutativity{s₁}{s₂} {x} = [↔]-intro (f{s₂}{s₁}) (f{s₁}{s₂}) where
f : ∀{s₁ s₂} → (x ∈ (s₁ ∩ s₂)) → (x ∈ (s₂ ∩ s₁))
f{s₁}{s₂} =
([↔]-elimₗ([∩]-containment{s₂}{s₁}{x}))
∘ ([∧]-symmetry)
∘ ([↔]-elimᵣ([∩]-containment{s₁}{s₂}{x}))
-- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Associativity
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ where
[∪]-associativity : ∀{s₁ s₂ s₃} → ((s₁ ∪ s₂) ∪ s₃) ≡ (s₁ ∪ (s₂ ∪ s₃))
[∪]-associativity{s₁}{s₂}{s₃} {x} = [↔]-intro l r where
l : (x ∈ ((s₁ ∪ s₂) ∪ s₃)) ← (x ∈ (s₁ ∪ (s₂ ∪ s₃)))
l = ([↔]-elimₗ([∪]-containment{s₁ ∪ s₂}{s₃}{x}))
∘ ([∨]-elim ([∨]-introₗ ∘ ([↔]-elimₗ([∪]-containment{s₁}{s₂}{x}))) ([∨]-introᵣ))
∘ ([↔]-elimₗ [∨]-associativity)
∘ ([∨]-elim ([∨]-introₗ) ([∨]-introᵣ ∘ ([↔]-elimᵣ([∪]-containment{s₂}{s₃}{x}))))
∘ ([↔]-elimᵣ([∪]-containment{s₁}{s₂ ∪ s₃}{x}))
r : (x ∈ ((s₁ ∪ s₂) ∪ s₃)) → (x ∈ (s₁ ∪ (s₂ ∪ s₃)))
r = ([↔]-elimₗ([∪]-containment{s₁}{s₂ ∪ s₃}{x}))
∘ ([∨]-elim ([∨]-introₗ) ([∨]-introᵣ ∘ ([↔]-elimₗ([∪]-containment{s₂}{s₃}{x}))))
∘ ([↔]-elimᵣ [∨]-associativity)
∘ ([∨]-elim ([∨]-introₗ ∘ ([↔]-elimᵣ([∪]-containment{s₁}{s₂}{x}))) ([∨]-introᵣ))
∘ ([↔]-elimᵣ([∪]-containment{s₁ ∪ s₂}{s₃}{x}))
module _ ⦃ _ : RestrictedComprehensionExistence ⦄ where
[∩]-associativity : ∀{s₁ s₂ s₃} → ((s₁ ∩ s₂) ∩ s₃) ≡ (s₁ ∩ (s₂ ∩ s₃))
[∩]-associativity{s₁}{s₂}{s₃} {x} = [↔]-intro l r where
l : (x ∈ ((s₁ ∩ s₂) ∩ s₃)) ← (x ∈ (s₁ ∩ (s₂ ∩ s₃)))
l = (([↔]-elimₗ([∩]-containment{s₁ ∩ s₂}{s₃}{x})) :of: ((x ∈ ((s₁ ∩ s₂) ∩ s₃)) ← (x ∈ (s₁ ∩ s₂))∧(x ∈ s₃)))
∘ ((prop ↦ ([∧]-intro ([↔]-elimₗ([∩]-containment{s₁}{s₂}{x}) ([∧]-elimₗ prop)) ([∧]-elimᵣ prop))) :of: ((x ∈ (s₁ ∩ s₂))∧(x ∈ s₃) ← ((x ∈ s₁)∧(x ∈ s₂))∧(x ∈ s₃)))
∘ ([↔]-elimₗ [∧]-associativity)
∘ ((prop ↦ ([∧]-intro ([∧]-elimₗ prop) ([↔]-elimᵣ([∩]-containment{s₂}{s₃}{x}) ([∧]-elimᵣ prop)))) :of: ((x ∈ s₁)∧((x ∈ s₂)∧(x ∈ s₃)) ← (x ∈ s₁)∧(x ∈ (s₂ ∩ s₃))))
∘ (([↔]-elimᵣ([∩]-containment{s₁}{s₂ ∩ s₃}{x})) :of: ((x ∈ s₁)∧(x ∈ (s₂ ∩ s₃)) ← (x ∈ (s₁ ∩ (s₂ ∩ s₃)))))
r : (x ∈ ((s₁ ∩ s₂) ∩ s₃)) → (x ∈ (s₁ ∩ (s₂ ∩ s₃)))
r = (([↔]-elimₗ([∩]-containment{s₁}{s₂ ∩ s₃}{x})) :of: ((x ∈ s₁)∧(x ∈ (s₂ ∩ s₃)) → (x ∈ (s₁ ∩ (s₂ ∩ s₃)))))
∘ ((prop ↦ ([∧]-intro ([∧]-elimₗ prop) ([↔]-elimₗ([∩]-containment{s₂}{s₃}{x}) ([∧]-elimᵣ prop)))) :of: ((x ∈ s₁)∧((x ∈ s₂)∧(x ∈ s₃)) → (x ∈ s₁)∧(x ∈ (s₂ ∩ s₃))))
∘ ([↔]-elimᵣ [∧]-associativity)
∘ ((prop ↦ ([∧]-intro ([↔]-elimᵣ([∩]-containment{s₁}{s₂}{x}) ([∧]-elimₗ prop)) ([∧]-elimᵣ prop))) :of: ((x ∈ (s₁ ∩ s₂))∧(x ∈ s₃) → ((x ∈ s₁)∧(x ∈ s₂))∧(x ∈ s₃)))
∘ (([↔]-elimᵣ([∩]-containment{s₁ ∩ s₂}{s₃}{x})) :of: ((x ∈ ((s₁ ∩ s₂) ∩ s₃)) → (x ∈ (s₁ ∩ s₂))∧(x ∈ s₃)))
module NaturalNumbers where
open Axioms1
open Operations
module _ ⦃ _ : EmptySetExistence ⦄ where
-- Could be interpreted as a set theoretic definition of zero from the natural numbers.
𝟎 : S
𝟎 = ∅
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ where
-- Could be interpreted as a set theoretic definition of the successor function from the natural numbers.
𝐒 : S → S
𝐒(x) = (x ∪ •(x))
module _ ⦃ _ : EmptySetExistence ⦄ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ where
Inductive : S → Stmt
Inductive(N) = ((𝟎 ∈ N) ∧ (∀{n} → (n ∈ N) → (𝐒(n) ∈ N)))
module Tuples where
open Axioms1
open Operations
open Relations
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ where
_,_ : S → S → S
_,_ x y = (x ∪ (x ⟒ y))
postulate Tuple-elem-uniqueness : ∀{x₁ x₂ y₁ y₂} → ((x₁ , y₁) ≡ (x₂ , y₂)) → (x₁ ≡ x₂)∧(y₁ ≡ y₂)
-- Tuple-elem-uniqueness (x1y1x2y2) =
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ ⦃ _ : RestrictedComprehensionExistence ⦄ ⦃ _ : PowerSetExistence ⦄ where
_⨯_ : S → S → S
_⨯_ s₁ s₂ = filter(℘(℘(s₁ ∪ s₂))) (s ↦ ∃(x ↦ ∃(y ↦ (x ∈ s₁) ∧ (y ∈ s₂) ∧ (s ≡ (x , y)))))
module Functions where
open Axioms1
open Operations
open Relations
open Tuples
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ ⦃ _ : RestrictedComprehensionExistence ⦄ where
Function : S → S → S → Stmt
Function(f) (s₁)(s₂) = (∀{x} → (x ∈ s₁) → ∃(y ↦ (y ∈ s₂) ∧ ((x , y) ∈ f) ∧ (∀{y₂} → ((x , y₂) ∈ f) → (y ≡ y₂))))
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ ⦃ _ : RestrictedComprehensionExistence ⦄ ⦃ _ : PowerSetExistence ⦄ where
_^_ : S → S → S
_^_ s₁ s₂ = filter(℘(s₂ ⨯ s₁)) (f ↦ Function(f)(s₁)(s₂))
module Axioms2 where
open Axioms1
open NaturalNumbers
open Relations
module _ ⦃ _ : EmptySetExistence ⦄ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ where
-- Sets can model ℕ.
-- This can be used to construct a set representing the natural numbers.
-- In this context, "Model" and "Representing" means a bijection.
record InfinityAxiom : Set(Lvl.𝟎) where
field infinity : ∃(N ↦ Inductive(N))
open InfinityAxiom ⦃ ... ⦄ public
record ChoiceAxiom : Set(Lvl.𝟎) where
field choice : ⊤
open ChoiceAxiom ⦃ ... ⦄ public
module NaturalNumberTheorems where
open Axioms1
open Axioms2
open NaturalNumbers
open Operations
open OperationsTheorems
open Relations
open RelationsTheorems
module _ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ where
[𝐒]-contains-arg : ∀{x} → (x ∈ 𝐒(x))
[𝐒]-contains-arg = [↔]-elimₗ ([∪]-containment) ([∨]-introᵣ [•]-containment)
[𝐒]-subset-arg : ∀{x} → (x ⊆ 𝐒(x))
[𝐒]-subset-arg = [∪]-subsetₗ
module _ ⦃ _ : EmptySetExistence ⦄ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ ⦃ _ : InfinityAxiom ⦄ where
Infinity-contains-[𝟎] : (𝟎 ∈ [∃]-witness(infinity))
Infinity-contains-[𝟎] = [∧]-elimₗ ([∃]-proof(infinity))
Infinity-contains-[𝐒] : ∀{n} → (n ∈ [∃]-witness(infinity)) → (𝐒(n) ∈ [∃]-witness(infinity))
Infinity-contains-[𝐒] = [∧]-elimᵣ ([∃]-proof(infinity))
Infinity-inductive : Inductive([∃]-witness(infinity))
Infinity-inductive = [∧]-intro (Infinity-contains-[𝟎]) (Infinity-contains-[𝐒])
module _ ⦃ _ : EmptySetExistence ⦄ ⦃ _ : UnionExistence ⦄ ⦃ _ : PairExistence ⦄ ⦃ _ : InfinityAxiom ⦄ ⦃ _ : RestrictedComprehensionExistence ⦄ where
ℕ : S
ℕ = filter([∃]-witness(infinity)) (n ↦ ∀{I} → Inductive(I) → (n ∈ I))
[ℕ]-subset-of-infinity : (ℕ ⊆ [∃]-witness(infinity))
[ℕ]-subset-of-infinity = filter-subset
[ℕ]-contains-[𝟎] : (𝟎 ∈ ℕ)
[ℕ]-contains-[𝟎] = ([↔]-elimₗ (filter-containment {_}{_}{𝟎})) ([∧]-intro (Infinity-contains-[𝟎]) (\{_} → [∧]-elimₗ))
[ℕ]-contains-[𝐒] : ∀{n} → (n ∈ ℕ) → (𝐒(n) ∈ ℕ)
[ℕ]-contains-[𝐒] {n} (n-in) with ([↔]-elimᵣ filter-containment) (n-in)
... | ([∧]-intro (n-in-inf) (n-satisfies)) =
(([↔]-elimₗ (filter-containment {_}{_}{𝐒(n)}))
([∧]-intro
(Sn-in-inf)
(\{_} → Sn-satisfies)
)
)
where
Sn-in-inf : (𝐒(n) ∈ [∃]-witness(infinity))
Sn-in-inf = Infinity-contains-[𝐒] (n-in-inf)
Sn-satisfies : ∀{I} → Inductive(I) → (𝐒(n) ∈ I)
Sn-satisfies{I}(I-inductive) = ([∧]-elimᵣ(I-inductive)) (n-satisfies{I}(I-inductive))
-- TODO: Is this provable without extensionality? The problem is (x∈z ↔ y∈z) when (x≡y).
module _ ⦃ _ : SetEquality ⦄ where
[ℕ]-containsₗ : ∀{n} → (n ∈ ℕ) ← (n ≡ 𝟎)∨(∃(x ↦ (x ∈ ℕ)∧(n ≡ 𝐒(x))))
[ℕ]-containsₗ {_} ([∨]-introₗ n-zero) with equality(n-zero)
... | [≡]-intro = [ℕ]-contains-[𝟎]
[ℕ]-containsₗ {n} ([∨]-introᵣ ([∃]-intro (x) ⦃ [∧]-intro (in-N) (n-succ) ⦄)) with equality(n-succ)
... | [≡]-intro = [ℕ]-contains-[𝐒] {x} (in-N)
[ℕ]-inductive : Inductive(ℕ)
[ℕ]-inductive = [∧]-intro ([ℕ]-contains-[𝟎]) ([ℕ]-contains-[𝐒])
[ℕ]-subset : ∀{I} → Inductive(I) → (ℕ ⊆ I)
[ℕ]-subset{I} (I-inductive) {n} (n-in-ℕ) with ([↔]-elimᵣ filter-containment) (n-in-ℕ)
... | ([∧]-intro (n-in-inf) (n-satisfies)) = n-satisfies{I} (I-inductive)
-- [ℕ]-containsᵣ : ∀{n} → (n ∈ ℕ) → (n ≡ 𝟎)∨(∃(x ↦ (x ∈ ℕ)∧(n ≡ 𝐒(x))))
-- [ℕ]-containsᵣ{n} (n-in) with ([↔]-elimᵣ filter-containment) (n-in) =
[ℕ]-set-induction : ∀{Nₛ} → (Nₛ ⊆ ℕ) → Inductive(Nₛ) → (Nₛ ≡ ℕ)
[ℕ]-set-induction {Nₛ} (Nₛ-subset) (ind) = [↔]-intro ([ℕ]-subset {Nₛ} (ind)) (Nₛ-subset)
module _ ⦃ _ : (𝟎 ∈ ℕ)⦄ ⦃ _ : ∀{n} → ⦃ _ : (n ∈ ℕ) ⦄ → (𝐒(n) ∈ ℕ) ⦄ where
postulate [ℕ]-induction : ∀{φ : (n : S) → ⦃ _ : (n ∈ ℕ) ⦄ → Stmt} → φ(𝟎) → (∀{n} → ⦃ n-in : (n ∈ ℕ) ⦄ → φ(n) → φ(𝐒(n))) → (∀{n} → ⦃ _ : n ∈ ℕ ⦄ → φ(n))
{-[ℕ]-induction {φ} (zero) (succ) {n} ⦃ n-in-ℕ ⦄ =
([∧]-elimᵣ
(([↔]-elimᵣ filter-containment)
([ℕ]-subset {set} ([∧]-intro (zero-in) (succ-in)) {n} (n-in-ℕ))
)
) where
set : S
set = filter-dep(ℕ)(φ)
module _ {n} ⦃ n-in-ℕ : (n ∈ ℕ) ⦄ where
n-inₗ : φ(n) ← (n ∈ set)
n-inₗ (proof) = [∃]-proof (([↔]-elimᵣ filter-dep-containment) (proof))
n-inᵣ : φ(n) → (n ∈ set)
n-inᵣ (proof) = ([↔]-elimₗ filter-containment) ([∧]-intro (n-in-ℕ) (proof))
-- TODO: Unnecessary
Sn-inₗ : φ(𝐒(n)) ← (𝐒(n) ∈ set)
Sn-inₗ (proof) = [∧]-elimᵣ (([↔]-elimᵣ filter-containment) (proof))
Sn-inᵣ : φ(𝐒(n)) → (𝐒(n) ∈ set)
Sn-inᵣ (proof) = ([↔]-elimₗ filter-containment) ([∧]-intro ([ℕ]-contains-[𝐒] (n-in-ℕ)) (proof))
zero-in : 𝟎 ∈ set
zero-in =
(([↔]-elimₗ filter-containment)
([∧]-intro
([ℕ]-contains-[𝟎])
(zero)
)
)
succ-in : ∀{n} → (n ∈ set) → (𝐒(n) ∈ set)
succ-in{n} (n-in-filter) with ([↔]-elimᵣ filter-containment) (n-in-filter)
... | ([∧]-intro (n-in-ℕ) (φn)) = (Sn-inᵣ ⦃ n-in-ℕ ⦄ (succ ⦃ n-in-ℕ ⦄ (n-inₗ ⦃ n-in-ℕ ⦄ n-in-filter)))
-}
{- ... | ([∧]-intro (n-in-ℕ) (φn)) =
(([↔]-elimₗ filter-containment)
([∧]-intro
([ℕ]-contains-[𝐒] (n-in-ℕ))
(?)
)
)
-}
-- succ-in = (Sn-inᵣ) ∘ (succ {n} (n-in-ℕ)) ∘ (n-inₗ)
_<_ : (a : S) → ⦃ _ : (a ∈ ℕ) ⦄ → (b : S) → ⦃ _ : (b ∈ ℕ) ⦄ → Stmt
a < b = (a ∈ b)
_≤_ : (a : S) → ⦃ _ : (a ∈ ℕ) ⦄ → (b : S) → ⦃ _ : (b ∈ ℕ) ⦄ → Stmt
a ≤ b = (a < b) ∨ (a ≡ b)
{- [<]-transitivity : ∀{a b c} → ⦃ _ : (a ∈ ℕ) ⦄ → ⦃ _ : (b ∈ ℕ) ⦄ → ⦃ _ : (c ∈ ℕ) ⦄ → (a < b) → (b < c) → (a < c)
[<]-transitivity{a}{b}{c} = [ℕ]-induction{n ↦ \ ⦃ _ ⦄ → ((a < b) → (b < n) → (a < n))} φ-zero φ-succ {c} where
postulate φ-zero : (a < b) → (b < 𝟎) ⦃ _ ⦄ ⦃ [ℕ]-contains-[𝟎] ⦄ → (a < 𝟎) ⦃ _ ⦄ ⦃ [ℕ]-contains-[𝟎] ⦄
postulate φ-succ : ∀{n} → ⦃ _ : n ∈ ℕ ⦄ → ((a < b) → (b < n) → (a < n)) → ((a < b) → (b < 𝐒(n)) → (a < 𝐒(n)))
-}
{--- TODO: I think a filtering like this gives the minimal inductive set? But probably not. (x∈ℕ) is missing, and then the definition is refering to itself.
ℕ : S
ℕ = filter([∃]-witness(infinity)) (n ↦ (n ≡ 𝟎) ∨ ∃(x ↦ ∧(n ≡ 𝐒(x)))) -- TODO: Does this potentially include other stuff too? Like 𝐒 ⦃ 𝟎 ⦄ ?
-- TODO: ∀{n} → (n ∈ ℕ) → (n ≡ 𝟎)∨(∃(x ↦ (x ∈ ℕ)∧(n ≡ 𝐒(x)))). COuld use [ℕ]-contains-[𝐒]-arg to achieve this.
[ℕ]-contains-only : ∀{n} → (n ∈ ℕ) → (n ≡ 𝟎)∨(∃(x ↦ n ≡ 𝐒(x)))
[ℕ]-contains-only {n} (n-containment) = [∧]-elimᵣ (([↔]-elimᵣ (filter-containment {_}{_}{n})) (n-containment))
-- [ℕ]-contains-[𝐒]-arg : ∀{n} → (𝐒(n) ∈ ℕ) → (n ∈ ℕ)
-- [ℕ]-contains-[𝐒]-arg{n} (sn-in) = [ℕ]-contains-only{𝐒(n)} ([∨]-introᵣ )
[ℕ]-contains-[𝟎] : (𝟎 ∈ ℕ)
[ℕ]-contains-[𝟎] = ([↔]-elimₗ (filter-containment {_}{_}{𝟎})) ([∧]-intro Infinity-contains-[𝟎] satisfy-property) where
satisfy-property : (𝟎 ≡ 𝟎) ∨ ∃(y ↦ 𝟎 ≡ 𝐒(y))
satisfy-property = [∨]-introₗ [≡]-reflexivity
[ℕ]-contains-[𝐒] : ∀{n} → (n ∈ ℕ) → (𝐒(n) ∈ ℕ)
[ℕ]-contains-[𝐒] {n} (n-containment) = ([↔]-elimₗ (filter-containment {_}{_}{𝐒(n)})) ([∧]-intro (Infinity-contains-[𝐒] {n} ([ℕ]-subset-of-infinity {n} (n-containment))) satisfy-property) where
satisfy-property : (𝐒(n) ≡ 𝟎) ∨ ∃(y ↦ 𝐒(n) ≡ 𝐒(y))
satisfy-property = [∨]-introᵣ ([∃]-intro n ⦃ [≡]-reflexivity ⦄)
-- [ℕ]-subset-implies-containment : ∀{n} → (n ⊆ ℕ) → (n ∈ ℕ)
-- [ℕ]-strict-subset-is-containment : ∀{n} → (n ⊂ ℕ) ↔ (n ∈ ℕ)
[ℕ]-subset : ∀{Nₛ} → Inductive(Nₛ) → (ℕ ⊆ Nₛ)
[ℕ]-subset {Nₛ} ([∧]-intro zero-containment successor-containment) {n} ([ℕ]-n-containment) =
[∨]-elim (zero) (succ) ([ℕ]-contains-only{n} ([ℕ]-n-containment)) where
zero : (n ≡ 𝟎) → (n ∈ Nₛ)
zero(n0) with equality(n0)
... | [≡]-intro = zero-containment
succ : (∃(x ↦ n ≡ 𝐒(x))) → (n ∈ Nₛ)
succ([∃]-intro(x) ⦃ prop ⦄) with equality(prop)
... | [≡]-intro = successor-containment(x-in) where
postulate x-in : (x ∈ Nₛ) -- TODO: Impossible to prove? Something is missing in the definition of ℕ?
-- TODO: Is it possible to connect this to the ℕ in Numeral.Natural.ℕ?
-- TODO: Is (∀{s₁ s₂ : S} → (s₁ ≡ s₂) → (s₁ ∈ S) → (s₂ ∈ S)) provable without axiom of extensionality?
-}
record IZF : Set(Lvl.𝐒(Lvl.𝟎)) where
instance constructor IZFStructure
open Axioms1
open Axioms2
field
⦃ extensionality ⦄ : SetEquality
⦃ empty ⦄ : EmptySetExistence
⦃ pair ⦄ : PairExistence
⦃ union ⦄ : UnionExistence
⦃ power ⦄ : PowerSetExistence
⦃ comprehension ⦄ : RestrictedComprehensionExistence
⦃ infinity ⦄ : InfinityAxiom
⦃ collection ⦄ : CollectionAxiom
⦃ induction ⦄ : InductionProof
|
{
"alphanum_fraction": 0.5194574086,
"avg_line_length": 42.7916666667,
"ext": "agda",
"hexsha": "8fdc6b449ad367e36de7f25afb84feb8da7ddc27",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Sets/IZF.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Sets/IZF.agda",
"max_line_length": 196,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Sets/IZF.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": 13192,
"size": 29783
}
|
{-# OPTIONS --without-K --safe #-}
module Math.NumberTheory.Product.Generic.Properties where
-- agda-stdlib
open import Algebra
-- agda-misc
open import Math.NumberTheory.Summation.Generic.Properties
-- TODO add renamaings
module CommutativeMonoidProductProperties {c e} (CM : CommutativeMonoid c e) =
CommutativeMonoidSummationProperties CM
renaming
( Σ<-cong to Π<-cong
; Σ<-congˡ to Π<-congˡ
; Σ<-congʳ to Π<-congʳ
; Σ≤-cong to Π≤-cong
; Σ≤-congˡ to Π≤-congˡ
; Σ≤-congʳ to Π≤-congʳ
; Σ<range-cong to Π<range-cong
; Σ<range-cong₃ to Π<range-cong₃
; Σ<range-cong₁₂ to Π<range-cong₁₂
; Σ<range-cong₁ to Π<range-cong₁
; Σ<range-cong₂ to Π<range-cong₂
; Σ≤range-cong to Π≤range-cong
; Σ<-congˡ-with-< to Π<-congˡ-with-<
; Σ≤-congˡ-with-≤ to Π≤-congˡ-with-≤
; Σ<-0 to Π<-1
; Σ≤-0 to Π≤-1
; Σ<[1,f]≈f[0] to Π<[1,f]≈f[0]
; Σ≤[0,f]≈f[0] to Π≤[0,f]≈f[0]
; n≤m⇒Σ<range[m,n,f]≈0 to n≤m⇒Π<range[m,n,f]≈1
; n<m⇒Σ≤range[m,n,f]≈0 to n<m⇒Π≤range[m,n,f]≈1
; Σ<range[n,n,f]≈0 to Π<range[n,n,f]≈1
; Σ<range-cong₃-with-< to Π<range-cong₃-with-<
; Σ≤range-cong₃-with-≤ to Π≤range-cong₃-wiht-≤
; Σ<range[n,1+n,f]≈f[n] to Π<range[n,1+n,f]≈f[n]
; Σ≤range[n,n,f]≈f[n] to Π≤range[n,n,f]≈f[n]
; Σ<-+ to Π<-+
; Σ≤-Σ<-+ to Π≤-Π<-+
; Σ≤-+ to Π≤-+
; Σ<-push-suc to Π<-push-suc
; Σ≤-push-suc to Π≤-push-suc
; Σ<range[0,n,f]≈Σ<[n,f] to Π<range[0,n,f]≈Π<[n,f]
; Σ≤range[0,n,f]≈Σ≤[n,f] to Π≤range[0,n,f]≈Π≤[n,f]
; Σ<range[m,m+n+o,f]≈Σ<range[m,m+n,f]+Σ<range[m+n,m+n+o,f] to
Π<range[m,m+n+o,f]≈Π<range[m,m+n,f]*Π<range[m+n,m+n+o,f]
; Σ<range[m,n,f]≈Σ<range[m,o,f]+Σ<range[o,n,f] to
Π<range[m,n,f]≈Π<range[m,o,f]*Π<range[o,n,f]
; Σ<range[m,n,f]≈Σ<range[o+m,o+n,i→f[i∸o]] to
Π<range[m,n,f]≈Π<range[o+m,o+n,i→f[i∸o]]
; Σ<-const to Π<-const
; Σ≤-const to Π≤-const
; Σ<range-const to Π<range-const
; Σ≤range-const to Π≤range-const
; Σ<-distrib-+ to Π<-distrib-*
; Σ≤-distrib-+ to Π≤-distrib-*
; Σ<range-distrib-+ to Π<range-distrib-*
; Σ≤range-distrib-+ to Π≤range-distrib-*
; Σ<-comm to Π<-comm
; Σ≤-comm to Π≤-comm
; Σ<range-comm to Π<range-comm
; Σ≤range-comm to Π≤range-comm
; Σ<-sumₜ-syntax to Π<-sumₜ-syntax
; Σ<-reverse to Π<-reverse
; Σ≤-reverse to Π≤-reverse
; Σ<range-reverse to Π<range-reverse
; Σ≤range-reverse to Π≤range-reverse
; Σ<-split-even to Π<-split-even
; Σ<-split-odd to Π<-split-odd
)
using ()
|
{
"alphanum_fraction": 0.5985099338,
"avg_line_length": 32.6486486486,
"ext": "agda",
"hexsha": "748af6fcd712037c226aa473486d8c73b9fd2f01",
"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": "Math/NumberTheory/Product/Generic/Properties.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": "Math/NumberTheory/Product/Generic/Properties.agda",
"max_line_length": 78,
"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": "Math/NumberTheory/Product/Generic/Properties.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": 1339,
"size": 2416
}
|
-- Andreas, 2015-10-26, issue reported by Wolfram Kahl
-- {-# OPTIONS -v scope.mod.inst:30 -v tc.mod.check:10 -v tc.mod.apply:80 #-}
module _ where
module ModParamsRecord (A : Set) where
record R (B : Set) : Set where
field F : A → B
module ModParamsToLoose (A : Set) where
open ModParamsRecord
private
module M (B : Set) (G : A → B) where
r : R A B
r = record { F = G }
module r = R r
open M public
module ModParamsLost (A : Set) where
open ModParamsRecord
open ModParamsToLoose A
f : (A → A) → A → A
f G = S.F
where
module S = r A G -- expected |S.F : A → A|,
-- WAS: but obtained |S.F : (B : Set) (G₁ : A → B) → A → B|
-- module S = r -- as expected: |S.F : (B : Set) (G₁ : A → B) → A → B|
-- module S = R A (r A G) -- as expected: |S.F : A → A|
|
{
"alphanum_fraction": 0.494002181,
"avg_line_length": 28.65625,
"ext": "agda",
"hexsha": "c0c0d424e36e14f8caad516c41105c0613f7f953",
"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/Issue1701a.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/Issue1701a.agda",
"max_line_length": 94,
"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/Issue1701a.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": 303,
"size": 917
}
|
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.Core
module Quasigroup.Definitions
{a ℓ} {A : Set a} -- The underlying set
(_≈_ : Rel A ℓ) -- The underlying equality
where
open import Algebra.Core
open import Data.Product
LatinSquareProperty₁ : Op₂ A → Set _
LatinSquareProperty₁ _*_ = ∀ a b x → (a * x) ≈ b
LatinSquareProperty₂ : Op₂ A → Set _
LatinSquareProperty₂ _*_ = ∀ a b y → (y * a) ≈ b
LatinSquareProperty : Op₂ A → Set _
LatinSquareProperty _*_ = (LatinSquareProperty₁ _*_) × (LatinSquareProperty₂ _*_)
|
{
"alphanum_fraction": 0.6886446886,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "0e86dd3238ac4b966fbf1dd30a54a86c104cb686",
"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": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_forks_repo_path": "src/Quasigroup/Definitions.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_issues_repo_issues_event_max_datetime": "2021-10-09T08:24:56.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-04T05:30:30.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_issues_repo_path": "src/Quasigroup/Definitions.agda",
"max_line_length": 81,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_stars_repo_path": "src/Quasigroup/Definitions.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-17T09:14:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-15T06:16:13.000Z",
"num_tokens": 168,
"size": 546
}
|
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Universe.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
isInjectiveTransport : ∀ {ℓ : Level} {A B : Type ℓ} {p q : A ≡ B}
→ transport p ≡ transport q → p ≡ q
isInjectiveTransport {p = p} {q} α i =
hcomp
(λ j → λ
{ (i = i0) → secEq univalence p j
; (i = i1) → secEq univalence q j
})
(invEq univalence ((λ a → α i a) , t i))
where
t : PathP (λ i → isEquiv (λ a → α i a)) (pathToEquiv p .snd) (pathToEquiv q .snd)
t = isProp→isContrPathP (λ i → isPropIsEquiv (λ a → α i a)) _ _ .fst
|
{
"alphanum_fraction": 0.6535859269,
"avg_line_length": 33.5909090909,
"ext": "agda",
"hexsha": "846b63d597380fb4d5ab212b331e56d9d0076c58",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Data/Universe/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Data/Universe/Properties.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Data/Universe/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 261,
"size": 739
}
|
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Reflexivity {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Tools.Product
-- Reflexivity of valid types.
reflᵛ : ∀ {A Γ l}
([Γ] : ⊩ᵛ Γ)
([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
→ Γ ⊩ᵛ⟨ l ⟩ A ≡ A / [Γ] / [A]
reflᵛ [Γ] [A] ⊢Δ [σ] =
reflEq (proj₁ ([A] ⊢Δ [σ]))
-- Reflexivity of valid terms.
reflᵗᵛ : ∀ {A t Γ l}
([Γ] : ⊩ᵛ Γ)
([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])
([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A])
→ Γ ⊩ᵛ⟨ l ⟩ t ≡ t ∷ A / [Γ] / [A]
reflᵗᵛ [Γ] [A] [t] ⊢Δ [σ] =
reflEqTerm (proj₁ ([A] ⊢Δ [σ])) (proj₁ ([t] ⊢Δ [σ]))
|
{
"alphanum_fraction": 0.5320754717,
"avg_line_length": 26.5,
"ext": "agda",
"hexsha": "c57d92a875d6b3161416206d91b6a25b6289fbfc",
"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/Reflexivity.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/Reflexivity.agda",
"max_line_length": 85,
"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/Reflexivity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 353,
"size": 795
}
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.RingSolver.RawRing where
open import Cubical.Foundations.Prelude
private
variable
ℓ : Level
record RawRing ℓ : Type (ℓ-suc ℓ) where
constructor rawring
field
Carrier : Type ℓ
0r : Carrier
1r : Carrier
_+_ : Carrier → Carrier → Carrier
_·_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
infixl 8 _·_
infixl 7 -_
infixl 6 _+_
⟨_⟩ : RawRing ℓ → Type ℓ
⟨_⟩ = RawRing.Carrier
|
{
"alphanum_fraction": 0.6206896552,
"avg_line_length": 17.6071428571,
"ext": "agda",
"hexsha": "46c5e1e7a3fc2609e3dcde1c31fa6269830ceacd",
"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/Algebra/RingSolver/RawRing.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/Algebra/RingSolver/RawRing.agda",
"max_line_length": 47,
"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/Algebra/RingSolver/RawRing.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 165,
"size": 493
}
|
module Issue1760f where
-- Skipping a single record definition in an abstract block.
abstract
{-# NO_POSITIVITY_CHECK #-}
record U : Set where
field ap : U → U
|
{
"alphanum_fraction": 0.7100591716,
"avg_line_length": 21.125,
"ext": "agda",
"hexsha": "72f71f950258e5a714e86fddb88be86fe9af1d44",
"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/Issue1760f.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/Issue1760f.agda",
"max_line_length": 60,
"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/Issue1760f.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": 44,
"size": 169
}
|
{-# OPTIONS --verbose=10 #-}
module inorderF where
open import Data.Nat
open import Data.Vec
open import Agda.Builtin.Sigma
open import Data.Product
open import Data.Fin using (fromℕ)
open import trees
open import optics
open import lemmas
inorderTreeF : {A : Set} -> (t : Tree A) -> Vec A (#nodes t) × (Vec A (#nodes t) -> Tree A)
inorderTreeF empty = ([] , λ _ -> empty)
inorderTreeF {A} (node t₁ x t₂) with inorderTreeF t₁ | inorderTreeF t₂
... | (g₁ , p₁) | (g₂ , p₂) =
(g₁ ++ (x ∷ g₂) , λ v -> node (p₁ (take n₁ v)) (head (drop n₁ v)) (righttree v))
where
n = #nodes (node t₁ x t₂)
n₁ = #nodes t₁
n₂ = #nodes t₂
righttree : Vec A n -> Tree A
righttree v rewrite +-suc n₁ n₂ = p₂ (drop (1 + n₁) v)
inorderF : {A : Set} -> TraversalF (Tree A) (Tree A) A A
inorderF = record{ extract = (#nodes , inorderTreeF) }
module tests where
tree1 : Tree ℕ
tree1 = node (node empty 1 empty) 3 empty
open Traversal
|
{
"alphanum_fraction": 0.5708812261,
"avg_line_length": 29,
"ext": "agda",
"hexsha": "b1a9f57fec50138ad4f3f0c252e3e2e31f71179d",
"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": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "hablapps/safeoptics",
"max_forks_repo_path": "src/main/agda/inorderF.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"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": "hablapps/safeoptics",
"max_issues_repo_path": "src/main/agda/inorderF.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "hablapps/safeoptics",
"max_stars_repo_path": "src/main/agda/inorderF.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 354,
"size": 1044
}
|
open import Common.Prelude
open import Common.Reflection
module TermSplicing1 where
x = unquote (give Set)
|
{
"alphanum_fraction": 0.8073394495,
"avg_line_length": 15.5714285714,
"ext": "agda",
"hexsha": "666dec597596153b947d45677ff35909ed63f8ab",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/TermSplicing1.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/TermSplicing1.agda",
"max_line_length": 29,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/TermSplicing1.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": 26,
"size": 109
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some properties related to Data.Star
--
-- This module is DEPRECATED. Please use the
-- Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties
-- module directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Star.Properties where
open import Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties
public
|
{
"alphanum_fraction": 0.552734375,
"avg_line_length": 30.1176470588,
"ext": "agda",
"hexsha": "781a6e6a9cb998a64e007d19a783fa73c16edd49",
"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/Star/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/Star/Properties.agda",
"max_line_length": 76,
"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/Star/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 84,
"size": 512
}
|
------------------------------------------------------------------------------
-- Well-founded induction on the relation _◁_
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- N.B This module does not contain combined proofs, but it imports
-- modules which contain combined proofs.
module FOTC.Program.McCarthy91.WF-Relation.Induction.Acc.WF-ATP where
open import FOTC.Base
open import FOTC.Data.Nat
import FOTC.Data.Nat.Induction.Acc.WF-ATP
open FOTC.Data.Nat.Induction.Acc.WF-ATP.<-WF using ( <-wf )
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.UnaryNumbers
open import FOTC.Induction.WF
open import FOTC.Program.McCarthy91.WF-Relation
open import FOTC.Program.McCarthy91.WF-Relation.PropertiesATP
-- Parametrized modules
open module InvImg =
FOTC.Induction.WF.InverseImage {N} {N} {_<_} ◁-fn-N
------------------------------------------------------------------------------
-- The relation _◁_ is well-founded (using the inverse image combinator).
◁-wf : WellFounded _◁_
◁-wf Nn = wellFounded <-wf Nn
-- Well-founded induction on the relation _◁_.
◁-wfind : (A : D → Set) →
(∀ {n} → N n → (∀ {m} → N m → m ◁ n → A m) → A n) →
∀ {n} → N n → A n
◁-wfind A = WellFoundedInduction ◁-wf
|
{
"alphanum_fraction": 0.5615010424,
"avg_line_length": 35.0975609756,
"ext": "agda",
"hexsha": "7c5eede1fff600f794cfbe65b8b67fa24d22df3a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/McCarthy91/WF-Relation/Induction/Acc/WF-ATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/McCarthy91/WF-Relation/Induction/Acc/WF-ATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/McCarthy91/WF-Relation/Induction/Acc/WF-ATP.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": 389,
"size": 1439
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lists defined in terms of the reflexive-transitive closure, Star
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Star.List where
open import Data.Star.Nat
open import Data.Unit
open import Relation.Binary.Construct.Always using (Always)
open import Relation.Binary.Construct.Constant using (Const)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
-- Lists.
List : ∀ {a} → Set a → Set a
List A = Star (Const A) tt tt
-- Nil and cons.
[] : ∀ {a} {A : Set a} → List A
[] = ε
infixr 5 _∷_
_∷_ : ∀ {a} {A : Set a} → A → List A → List A
_∷_ = _◅_
-- The sum of the elements in a list containing natural numbers.
sum : List ℕ → ℕ
sum = fold (Star Always) _+_ zero
|
{
"alphanum_fraction": 0.5664739884,
"avg_line_length": 24.0277777778,
"ext": "agda",
"hexsha": "379f1b0e682238d5b73fbb8986bc6d8d82d62ba5",
"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/Star/List.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/Star/List.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Star/List.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": 217,
"size": 865
}
|
module triple where
|
{
"alphanum_fraction": 0.6071428571,
"avg_line_length": 4.6666666667,
"ext": "agda",
"hexsha": "3e18612e33a40f983227a7edacd990b9c9605b80",
"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": "triple.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": "triple.agda",
"max_line_length": 19,
"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": "triple.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5,
"size": 28
}
|
-- Syntactic kits from Conor McBride's
-- "Type-Preserving Renaming and Substitution"
module Syntax.Substitution.Kits where
open import Syntax.Types
open import Syntax.Context
open import Syntax.Terms
open import CategoryTheory.Categories
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; sym)
-- Type of entities that we can traverse
-- (instantiated by variables and types)
Schema : Set₁
Schema = Context -> Judgement -> Set
-- Explicit substitution from term in context Δ to term in context Γ
-- E.g. from Γ ⌊ A ⌋ Γ′ ⊢ N : B to Γ ⌊⌋ Γ′ ⊢ N[σ] : B
-- using substitution Γ ⌊⌋ Γ′ ⊢ σ : Γ ⌊ A ⌋ Γ′
data Subst (𝒮 : Schema) : Context -> Context -> Set where
-- Empty substitution
● : ∀ {Δ} -> Subst 𝒮 ∙ Δ
-- Extending the domain of a substitution
_▸_ : ∀ {A Γ Δ} -> (σ : Subst 𝒮 Γ Δ) -> (T : 𝒮 Δ A) -> Subst 𝒮 (Γ , A) Δ
-- Syntactic kit grouping together common operations on traversable
-- syntactic entities such as variables and terms
record Kit (𝒮 : Schema) : Set where
field
-- Convert a variable to the entity
𝓋 : ∀ {Γ A} -> A ∈ Γ -> 𝒮 Γ A
-- Convert the entity to a term
𝓉 : ∀ {Γ A} -> 𝒮 Γ A -> Γ ⊢ A
-- Weaken the entity
𝓌 : ∀ {B Γ A} -> 𝒮 Γ A -> 𝒮 (Γ , B) A
-- Stabilise the context of the entity
𝒶 : ∀ {Γ A} -> 𝒮 Γ (A always) -> 𝒮 (Γ ˢ) (A always)
-- Substitutable kit
record SubstKit (𝒮 : Schema) : Set where
field
-- Underlying traversable kit
𝓀 : Kit 𝒮
-- Apply substitution to a kit
𝓈 : ∀ {Γ Δ A} -> Subst 𝒮 Γ Δ -> 𝒮 Γ A -> 𝒮 Δ A
open Kit
-- | Combinators
-- | All take a syntactic (substitutable) kit as an argument
-- | which provides the necessary operations
-- Weakening a substitution
-- Δ ⊢ σ : Γ to (Δ , A) ⊢ σ : Γ
_⁺_ : ∀ {A 𝒮 Γ Δ} -> Subst 𝒮 Γ Δ -> Kit 𝒮 -> Subst 𝒮 Γ (Δ , A)
● ⁺ _ = ●
(σ ▸ T) ⁺ k = (σ ⁺ k) ▸ 𝓌 k T
infixl 40 _⁺_
-- Lifting a substitution
-- Δ ⊢ σ : Γ to (Δ , A) ⊢ σ : (Γ , A)
_↑_ : ∀ {A 𝒮 Γ Δ} -> Subst 𝒮 Γ Δ -> Kit 𝒮 -> Subst 𝒮 (Γ , A) (Δ , A)
σ ↑ k = (σ ⁺ k) ▸ 𝓋 k top
infixl 40 _↑_
-- Stabilising a substitution
-- Δ ⊢ σ : Γ to Δ ˢ ⊢ σ : Γ ˢ
_↓ˢ_ : ∀ {𝒮 Γ Δ} -> Subst 𝒮 Γ Δ -> Kit 𝒮 -> Subst 𝒮 (Γ ˢ) (Δ ˢ)
● ↓ˢ _ = ●
(_▸_ {A now} σ T) ↓ˢ k = σ ↓ˢ k
(_▸_ {A always} σ T) ↓ˢ k = (σ ↓ˢ k) ▸ 𝒶 k T
infixl 40 _↓ˢ_
-- Identity substitution
idₛ : ∀ {Γ 𝒮} -> Kit 𝒮 -> Subst 𝒮 Γ Γ
idₛ {∙} k = ●
idₛ {Γ , _} k = idₛ k ↑ k
-- Composition of substitutions
_∘[_]ₛ_ : ∀ {𝒮 Γ Δ Ξ} -> Subst 𝒮 Δ Ξ -> SubstKit 𝒮 -> Subst 𝒮 Γ Δ -> Subst 𝒮 Γ Ξ
σ₂ ∘[ k ]ₛ ● = ●
σ₂ ∘[ k ]ₛ (σ₁ ▸ T) = (σ₂ ∘[ k ]ₛ σ₁) ▸ SubstKit.𝓈 k σ₂ T
-- Substitution from an order-preserving embedding
-- Γ ⊆ Δ to Δ ⊢ σ : Γ
_⊆ₛ_ : ∀ {𝒮 Γ Δ} -> Γ ⊆ Δ -> Kit 𝒮 -> Subst 𝒮 Γ Δ
refl ⊆ₛ k = idₛ k
(keep s) ⊆ₛ k = (s ⊆ₛ k) ↑ k
(drop s) ⊆ₛ k = (s ⊆ₛ k) ⁺ k
-- Substitution from propositional equality of contexts
_≡ₛ_ : ∀ {𝒮 Γ Δ} -> Γ ≡ Δ -> Kit 𝒮 -> Subst 𝒮 Γ Δ
refl ≡ₛ k = idₛ k
-- Substitution from idempotence of stabilisation
_ˢˢₛ_ : ∀ {𝒮} -> (Γ : Context) -> Kit 𝒮 -> Subst 𝒮 (Γ ˢ) (Γ ˢ ˢ)
∙ ˢˢₛ k = ●
(Γ , A now) ˢˢₛ k = Γ ˢˢₛ k
(Γ , A always) ˢˢₛ k = (Γ ˢˢₛ k) ↑ k
-- | Standard substitutions
-- | Common transformations between contexts
module _ {𝒮 : Schema} (sk : SubstKit 𝒮) where
open SubstKit sk
open Kit 𝓀
-- | Weakening
-- Weakening the top of the context
weak-topₛ : ∀{A Γ} -> Subst 𝒮 Γ (Γ , A)
weak-topₛ = idₛ 𝓀 ⁺ 𝓀
-- Weakening the middle of the context
weak-midₛ : ∀{A} Γ Γ′ -> Subst 𝒮 (Γ ⌊⌋ Γ′) (Γ ⌊ A ⌋ Γ′)
weak-midₛ Γ ∙ = weak-topₛ
weak-midₛ Γ (Γ′ , B) = weak-midₛ Γ Γ′ ↑ 𝓀
-- General weakening from an OPE
weakₛ : ∀{Γ Δ} -> Γ ⊆ Δ -> Subst 𝒮 Γ Δ
weakₛ = _⊆ₛ 𝓀
-- | Exchange
-- Exchange on top
ex-topₛ : ∀{A B} Γ -> Subst 𝒮 (Γ , A , B) (Γ , B , A)
ex-topₛ Γ = (idₛ 𝓀 ⁺ 𝓀 ↑ 𝓀) ▸ (𝓋 𝓀 (pop top))
-- General exchange lemma
exₛ : ∀{A B} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ⌊ A ⌋ Γ′ ⌊ B ⌋ Γ″) (Γ ⌊ B ⌋ Γ′ ⌊ A ⌋ Γ″)
exₛ Γ ∙ ∙ = ex-topₛ Γ
exₛ {A} {B} Γ (Γ′ , C) ∙ =
(exₛ Γ Γ′ [ A ] ∘[ sk ]ₛ ex-topₛ (Γ , C ⌊⌋ Γ′)) ∘[ sk ]ₛ exₛ Γ Γ′ [ B ]
exₛ Γ ∙ (Γ″ , D) = exₛ Γ ∙ Γ″ ↑ 𝓀
exₛ Γ (Γ′ , C) (Γ″ , D) = exₛ Γ (Γ′ , C) Γ″ ↑ 𝓀
-- | Contraction
-- Contraction on top
contr-topₛ : ∀{A Γ} -> Subst 𝒮 (Γ , A , A) (Γ , A)
contr-topₛ = (idₛ 𝓀) ▸ (𝓋 𝓀 top)
-- General contraction lemma (left)
contr-lₛ : ∀{A} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ⌊ A ⌋ Γ′ ⌊ A ⌋ Γ″) (Γ ⌊ A ⌋ Γ′ ⌊⌋ Γ″)
contr-lₛ Γ ∙ ∙ = contr-topₛ
contr-lₛ Γ (Γ′ , B) ∙ = (idₛ 𝓀) ▸ (𝓌 𝓀 (𝓈 (contr-lₛ Γ Γ′ ∙) (𝓋 𝓀 top)))
contr-lₛ Γ ∙ (Γ″ , C) = contr-lₛ Γ ∙ Γ″ ↑ 𝓀
contr-lₛ Γ (Γ′ , B) (Γ″ , C) = contr-lₛ Γ (Γ′ , B) Γ″ ↑ 𝓀
-- General contraction lemma (right)
contr-rₛ : ∀{A} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ⌊ A ⌋ Γ′ ⌊ A ⌋ Γ″) (Γ ⌊⌋ Γ′ ⌊ A ⌋ Γ″)
contr-rₛ Γ ∙ ∙ = contr-topₛ
contr-rₛ {A} Γ (Γ′ , B) ∙ =
(ex-topₛ (Γ ⌊⌋ Γ′) ∘[ sk ]ₛ contr-rₛ Γ Γ′ [ B ]) ∘[ sk ]ₛ ex-topₛ (Γ , A ⌊⌋ Γ′)
contr-rₛ Γ ∙ (Γ″ , C) = contr-rₛ Γ ∙ Γ″ ↑ 𝓀
contr-rₛ Γ (Γ′ , B) (Γ″ , C) = contr-rₛ Γ (Γ′ , B) Γ″ ↑ 𝓀
-- | Movement
-- Moving a variable to the right in the context
move-rₛ : ∀{A} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ⌊ A ⌋ Γ′ ⌊⌋ Γ″) (Γ ⌊⌋ Γ′ ⌊ A ⌋ Γ″)
move-rₛ {A} Γ Γ′ Γ″ = contr-rₛ Γ Γ′ Γ″ ∘[ sk ]ₛ weak-midₛ (Γ ⌊ A ⌋ Γ′) Γ″
-- Moving a variable to the left in the context
-- Bit verbose as we have to deal with associativity
move-lₛ : ∀{A} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ⌊⌋ Γ′ ⌊ A ⌋ Γ″) (Γ ⌊ A ⌋ Γ′ ⌊⌋ Γ″)
move-lₛ {A} Γ Γ′ Γ″
= contr-lₛ Γ Γ′ Γ″
∘[ sk ]ₛ ((sym (⌊A⌋-assoc Γ Γ′ Γ″ A A) ≡ₛ 𝓀)
∘[ sk ]ₛ ((weak-midₛ {A} Γ (Γ′ ⌊ A ⌋ Γ″))
∘[ sk ]ₛ (⌊⌋-assoc Γ (Γ′ , A) Γ″ ≡ₛ 𝓀)))
-- Moving a variable to the right in the stabilised context context
moveˢ-rₛ : ∀{A} Γ Γ′ Γ″ -> Subst 𝒮 (Γ ˢ ⌊ A ⌋ (Γ′ ⌊⌋ Γ″) ˢ) ((Γ ⌊⌋ Γ′) ˢ ⌊ A ⌋ Γ″ ˢ)
moveˢ-rₛ {A} Γ Γ′ Γ″
rewrite ˢ-pres-⌊⌋ Γ Γ′
| ˢ-pres-⌊⌋ Γ′ Γ″
| sym (⌊⌋-assoc (Γ ˢ , A) (Γ′ ˢ) (Γ″ ˢ))
= move-rₛ (Γ ˢ) (Γ′ ˢ) (Γ″ ˢ)
-- | Substitution
-- Substitution for the top of the context
sub-topₛ : ∀{A Γ} -> 𝒮 Γ A -> Subst 𝒮 (Γ , A) Γ
sub-topₛ T = (idₛ 𝓀) ▸ T
-- Substitution for the top of a stabilised context
sub-topˢₛ : ∀{Γ A} -> 𝒮 Γ A -> Subst 𝒮 (Γ ˢ , A) Γ
sub-topˢₛ {Γ} T = (Γˢ⊆Γ Γ ⊆ₛ 𝓀) ▸ T
-- Substitution for the middle of the context
sub-midₛ : ∀{A} Γ Γ′ -> 𝒮 (Γ ⌊⌋ Γ′) A -> Subst 𝒮 (Γ ⌊ A ⌋ Γ′) (Γ ⌊⌋ Γ′)
sub-midₛ Γ Γ′ T = sub-topₛ T ∘[ sk ]ₛ move-rₛ Γ Γ′ ∙
|
{
"alphanum_fraction": 0.5035949212,
"avg_line_length": 33.3520408163,
"ext": "agda",
"hexsha": "10bcbf704be0bb81aeda47765a72e07d0cce5ce9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DimaSamoz/temporal-type-systems",
"max_forks_repo_path": "src/Syntax/Substitution/Kits.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DimaSamoz/temporal-type-systems",
"max_issues_repo_path": "src/Syntax/Substitution/Kits.agda",
"max_line_length": 88,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DimaSamoz/temporal-type-systems",
"max_stars_repo_path": "src/Syntax/Substitution/Kits.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z",
"num_tokens": 3322,
"size": 6537
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module constructs the zero R-module, and similar for weaker
-- module-like structures.
-- The intended universal property is that, given any R-module M, there
-- is a unique map into and a unique map out of the zero R-module
-- from/to M.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Algebra.Module.Construct.Zero where
open import Algebra.Bundles
open import Algebra.Module.Bundles
open import Data.Unit
open import Level
private
variable
r s ℓr ℓs : Level
leftSemimodule : {R : Semiring r ℓr} → LeftSemimodule R 0ℓ 0ℓ
leftSemimodule = record
{ Carrierᴹ = ⊤
; _≈ᴹ_ = λ _ _ → ⊤
}
rightSemimodule : {S : Semiring s ℓs} → RightSemimodule S 0ℓ 0ℓ
rightSemimodule = record
{ Carrierᴹ = ⊤
; _≈ᴹ_ = λ _ _ → ⊤
}
bisemimodule :
{R : Semiring r ℓr} {S : Semiring s ℓs} → Bisemimodule R S 0ℓ 0ℓ
bisemimodule = record
{ Carrierᴹ = ⊤
; _≈ᴹ_ = λ _ _ → ⊤
}
semimodule : {R : CommutativeSemiring r ℓr} → Semimodule R 0ℓ 0ℓ
semimodule = record
{ Carrierᴹ = ⊤
; _≈ᴹ_ = λ _ _ → ⊤
}
leftModule : {R : Ring r ℓr} → LeftModule R 0ℓ 0ℓ
leftModule = record
{ Carrierᴹ = ⊤
; _≈ᴹ_ = λ _ _ → ⊤
}
rightModule : {S : Ring s ℓs} → RightModule S 0ℓ 0ℓ
rightModule = record
{ Carrierᴹ = ⊤
; _≈ᴹ_ = λ _ _ → ⊤
}
bimodule : {R : Ring r ℓr} {S : Ring s ℓs} → Bimodule R S 0ℓ 0ℓ
bimodule = record
{ Carrierᴹ = ⊤
; _≈ᴹ_ = λ _ _ → ⊤
}
⟨module⟩ : {R : CommutativeRing r ℓr} → Module R 0ℓ 0ℓ
⟨module⟩ = record
{ Carrierᴹ = ⊤
; _≈ᴹ_ = λ _ _ → ⊤
}
|
{
"alphanum_fraction": 0.5769462885,
"avg_line_length": 23.0138888889,
"ext": "agda",
"hexsha": "e6f8af4a3edcade50ffc2f9ca3294ac9221b943a",
"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/Zero.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/Zero.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/Module/Construct/Zero.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": 655,
"size": 1657
}
|
{-# OPTIONS --guardedness #-}
module Stream.Iterable where
open import Data
open import Data.Boolean
open import Functional
open import Logic.Propositional
open import Logic.Predicate
import Lvl
open import Relator.Equals
open import Stream as Stream
open import Structure.Container.Iterable
open import Type
private variable ℓ : Lvl.Level
private variable T : Type{ℓ}
instance
Stream-iterable : Iterable(Stream(T))
Iterable.Element (Stream-iterable {T = T}) = T
Iterable.isEmpty Stream-iterable = const 𝐹
Iterable.current Stream-iterable = Stream.head
Iterable.indexStep Stream-iterable = const <>
Iterable.step Stream-iterable = Stream.tail
instance
Stream-prepend : Iterable.PrependConstruction(Stream-iterable{T = T})(_⊰_)
∃.witness Stream-prepend = [≡]-intro
∃.proof (Stream-prepend) = [∧]-intro [≡]-intro [≡]-intro
|
{
"alphanum_fraction": 0.7450523865,
"avg_line_length": 27.7096774194,
"ext": "agda",
"hexsha": "c39fc224391fb2e014fcc74890f6e4b7e941eb2a",
"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": "Stream/Iterable.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": "Stream/Iterable.agda",
"max_line_length": 76,
"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": "Stream/Iterable.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": 225,
"size": 859
}
|
open import Mockingbird.Forest using (Forest)
-- To Mock a Mockingbird
module Mockingbird.Problems.Chapter09 {b ℓ} (forest : Forest {b} {ℓ}) where
open import Data.Product using (_,_; proj₁; proj₂; ∃-syntax)
open import Function using (_$_)
open import Level using (_⊔_)
open import Relation.Nullary using (¬_)
open import Mockingbird.Forest.Birds forest
open Forest forest
module _ ⦃ _ : HasComposition ⦄ ⦃ _ : HasMockingbird ⦄ where
problem₁ : ∀ A → ∃[ B ] A IsFondOf B
problem₁ A =
let C = A ∘ M
isFond : A IsFondOf (C ∙ C)
isFond = sym $ begin
C ∙ C ≈⟨ isComposition A M C ⟩
A ∙ (M ∙ C) ≈⟨ congˡ (isMockingbird C) ⟩
A ∙ (C ∙ C) ∎
in (C ∙ C , isFond)
module _ ⦃ _ : HasComposition ⦄ ⦃ _ : HasMockingbird ⦄ where
problem₂ : ∃[ E ] IsEgocentric E
problem₂ =
let (E , isFond) = problem₁ M
isEgocentric : IsEgocentric E
isEgocentric = begin
E ∙ E ≈˘⟨ isMockingbird E ⟩
M ∙ E ≈⟨ isFond ⟩
E ∎
in (E , isEgocentric)
module _ ⦃ _ : HasComposition ⦄ (hasAgreeable : ∃[ A ] IsAgreeable A) where
A = proj₁ hasAgreeable
isAgreeable = proj₂ hasAgreeable
problem₃ : ∀ B → ∃[ C ] B IsFondOf C
problem₃ B =
let D = B ∘ A
(x , Ax≈Dx) = isAgreeable D
isFond : B IsFondOf (A ∙ x)
isFond = begin
B ∙ (A ∙ x) ≈˘⟨ isComposition B A x ⟩
D ∙ x ≈˘⟨ Ax≈Dx ⟩
A ∙ x ∎
in (A ∙ x , isFond)
-- Bonus question of Problem 3.
C₂→HasAgreeable : ⦃ _ : HasMockingbird ⦄ → ∃[ A ] IsAgreeable A
C₂→HasAgreeable = (M , λ B → (B , isMockingbird B))
module _ ⦃ _ : HasComposition ⦄ (A B C : Bird) (Cx≈A[Bx] : IsComposition A B C) where
problem₄ : IsAgreeable C → IsAgreeable A
problem₄ C-isAgreeable D =
let E = D ∘ B
(x , Cx≈Ex) = C-isAgreeable E
agree : Agree A D (B ∙ x)
agree = begin
A ∙ (B ∙ x) ≈˘⟨ Cx≈A[Bx] x ⟩
C ∙ x ≈⟨ Cx≈Ex ⟩
E ∙ x ≈⟨ isComposition D B x ⟩
D ∙ (B ∙ x) ∎
in (B ∙ x , agree)
module _ ⦃ _ : HasComposition ⦄ where
problem₅ : ∀ A B C → ∃[ D ] (∀ x → D ∙ x ≈ A ∙ (B ∙ (C ∙ x)))
problem₅ A B C =
let E = B ∘ C
D = A ∘ E
in (D , λ x → trans (isComposition A E x) $ congˡ (isComposition B C x))
module _ ⦃ _ : HasComposition ⦄ ⦃ _ : HasMockingbird ⦄ where
problem₆ : ∀ A B → Compatible A B
problem₆ A B =
let C = A ∘ B
(y , Cy≈y) = problem₁ C
x = B ∙ y
in (x , y , trans (sym (isComposition A B y)) Cy≈y , refl)
problem₇ : ∀ A → ∃[ B ] A IsFondOf B → IsHappy A
problem₇ A (B , AB≈B) = (B , B , AB≈B , AB≈B)
-- problem₇ : ∀ A → IsNormal A → IsHappy A
module _ ⦃ _ : HasComposition ⦄ where
problem₈ : ∃[ H ] IsHappy H → ∃[ N ] IsNormal N
problem₈ (H , x , y , Hx≈y , Hy≈x) =
let N = H ∘ H
isFond : N IsFondOf x
isFond = begin
N ∙ x ≈⟨ isComposition H H x ⟩
H ∙ (H ∙ x) ≈⟨ congˡ Hx≈y ⟩
H ∙ y ≈⟨ Hy≈x ⟩
x ∎
in (N , x , isFond)
module _ ⦃ _ : HasComposition ⦄ ⦃ _ : HasMockingbird ⦄ ⦃ _ : HasKestrel ⦄ where
problem₉ : ∃[ A ] IsHopelesslyEgocentric A
problem₉ =
let (A , KA≈A) = problem₁ K
isHopelesslyEgocentric : IsHopelesslyEgocentric A
isHopelesslyEgocentric x = begin
A ∙ x ≈˘⟨ congʳ KA≈A ⟩
(K ∙ A) ∙ x ≈⟨ isKestrel A x ⟩
A ∎
in (A , isHopelesslyEgocentric)
problem₁₀ : ∀ x y → x IsFixatedOn y → x IsFondOf y
problem₁₀ x y xz≈y = xz≈y y
problem₁₁ : ∀ K → IsKestrel K → IsEgocentric K → IsHopelesslyEgocentric K
problem₁₁ K isKestrel KK≈K x = begin
K ∙ x ≈˘⟨ congʳ KK≈K ⟩
(K ∙ K) ∙ x ≈⟨ isKestrel K x ⟩
K ∎
problem₁₂ : ⦃ _ : HasKestrel ⦄ → ∀ x → IsEgocentric (K ∙ x) → K IsFondOf x
problem₁₂ x [Kx][Kx]≈Kx = begin
K ∙ x ≈˘⟨ [Kx][Kx]≈Kx ⟩
(K ∙ x) ∙ (K ∙ x) ≈⟨ isKestrel x (K ∙ x) ⟩
x ∎
problem₁₃ : ∀ A x y → IsHopelesslyEgocentric A → A ∙ x ≈ A ∙ y
problem₁₃ A x y Az≈A = begin
A ∙ x ≈⟨ Az≈A x ⟩
A ≈˘⟨ Az≈A y ⟩
A ∙ y ∎
problem₁₄ : ∀ A x y → IsHopelesslyEgocentric A → (A ∙ x) ∙ y ≈ A
problem₁₄ A x y Az≈A = begin
(A ∙ x) ∙ y ≈⟨ congʳ (Az≈A x) ⟩
A ∙ y ≈⟨ Az≈A y ⟩
A ∎
problem₁₅ : ∀ A x → IsHopelesslyEgocentric A → IsHopelesslyEgocentric (A ∙ x)
problem₁₅ A x Az≈A y = begin
(A ∙ x) ∙ y ≈⟨ congʳ (Az≈A x) ⟩
A ∙ y ≈⟨ Az≈A y ⟩
A ≈˘⟨ Az≈A x ⟩
A ∙ x ∎
problem₁₆ : ∀ K → IsKestrel K → ∀ x y → K ∙ x ≈ K ∙ y → x ≈ y
problem₁₆ K isKestrel x y Kx≈Ky = begin
x ≈˘⟨ isKestrel x K ⟩
-- NOTE: for the right-most kestrel, we can choose any bird. (Since we know
-- only of three birds to exist here, the only option is a combination of
-- {K, x, y}).
(K ∙ x) ∙ K ≈⟨ congʳ Kx≈Ky ⟩
(K ∙ y) ∙ K ≈⟨ isKestrel y K ⟩
y ∎
problem₁₇ : ∀ A x y → A IsFixatedOn x → A IsFixatedOn y → x ≈ y
problem₁₇ A x y Az≈x Az≈y = begin
x ≈˘⟨ Az≈x A ⟩
-- NOTE: for the right-most A, we can choose any bird. (In this case a
-- combination of {A, B, C}).
A ∙ A ≈⟨ Az≈y A ⟩
y ∎
problem₁₈ : ⦃ _ : HasKestrel ⦄ → ∀ x → K IsFondOf K ∙ x → K IsFondOf x
problem₁₈ x K[Kx]≈Kx = begin
K ∙ x ≈˘⟨ isKestrel (K ∙ x) x ⟩
-- NOTE: for the right-most x, we can choose any bird.
(K ∙ (K ∙ x)) ∙ x ≈⟨ congʳ K[Kx]≈Kx ⟩
(K ∙ x) ∙ x ≈⟨ isKestrel x x ⟩
x ∎
-- In the circumstances of Problem 19, the only bird in the forest is the
-- kestrel.
problem₁₉ : ∀ K → IsKestrel K → IsEgocentric K → ∀ x → x ≈ K
problem₁₉ K isKestrel KK≈K x = begin
x ≈⟨ lemma x x ⟩
K ∙ x ≈˘⟨ congʳ KK≈K ⟩
(K ∙ K) ∙ x ≈⟨ isKestrel K x ⟩
K ∎
where
lemma : ∀ y z → y ≈ K ∙ z
lemma y z = begin
y ≈˘⟨ isKestrel y z ⟩
(K ∙ y) ∙ z ≈˘⟨ congʳ (congʳ KK≈K) ⟩
((K ∙ K) ∙ y) ∙ z ≈⟨ congʳ (isKestrel K y) ⟩
K ∙ z ∎
module _ ⦃ _ : HasIdentity ⦄ where
problem₂₀ : IsAgreeable I → ∀ A → ∃[ B ] A IsFondOf B
problem₂₀ isAgreeable A =
let (B , IB≈AB) = isAgreeable A
isFond : A IsFondOf B
isFond = begin
A ∙ B ≈˘⟨ IB≈AB ⟩
I ∙ B ≈⟨ isIdentity B ⟩
B ∎
in (B , isFond)
problem₂₁ : (∀ A → ∃[ B ] A IsFondOf B) → IsAgreeable I
problem₂₁ isFond A =
let (B , AB≈B) = isFond A
agree : I ∙ B ≈ A ∙ B
agree = begin
I ∙ B ≈⟨ isIdentity B ⟩
B ≈˘⟨ AB≈B ⟩
A ∙ B ∎
in (B , agree)
problem₂₂-1 : (∀ A B → Compatible A B) → ∀ A → IsNormal A
problem₂₂-1 compatible A =
let (x , y , Ix≈y , Ay≈x) = compatible I A
isFond : A IsFondOf y
isFond = begin
A ∙ y ≈⟨ Ay≈x ⟩
x ≈˘⟨ isIdentity x ⟩
I ∙ x ≈⟨ Ix≈y ⟩
y ∎
in (y , isFond)
problem₂₂-2 : (∀ A B → Compatible A B) → IsAgreeable I
problem₂₂-2 compatible A =
let (x , y , Ix≈y , Ay≈x) = compatible I A
agree : Agree I A y
agree = begin
I ∙ y ≈⟨ isIdentity y ⟩
y ≈˘⟨ Ix≈y ⟩
I ∙ x ≈⟨ isIdentity x ⟩
x ≈˘⟨ Ay≈x ⟩
A ∙ y ∎
in (y , agree)
problem₂₃ : IsHopelesslyEgocentric I → ∀ x → I ≈ x
problem₂₃ isHopelesslyEgocentric x = begin
I ≈˘⟨ isHopelesslyEgocentric x ⟩
I ∙ x ≈⟨ isIdentity x ⟩
x ∎
module _ ⦃ _ : HasLark ⦄ ⦃ _ : HasIdentity ⦄ where
problem₂₄ : HasMockingbird
problem₂₄ = record
{ M = L ∙ I
; isMockingbird = λ x → begin
(L ∙ I) ∙ x ≈⟨ isLark I x ⟩
I ∙ (x ∙ x) ≈⟨ isIdentity (x ∙ x) ⟩
x ∙ x ∎
}
module _ ⦃ _ : HasLark ⦄ where
problem₂₅ : ∀ x → IsNormal x
problem₂₅ x =
let isFond : x IsFondOf (L ∙ x) ∙ (L ∙ x)
isFond = begin
x ∙ ((L ∙ x) ∙ (L ∙ x)) ≈˘⟨ isLark x (L ∙ x) ⟩
(L ∙ x) ∙ (L ∙ x) ∎
in ((L ∙ x) ∙ (L ∙ x) , isFond)
problem₂₆ : IsHopelesslyEgocentric L → ∀ x → x IsFondOf L
problem₂₆ isHopelesslyEgocentric x = begin
x ∙ L ≈˘⟨ congˡ $ isHopelesslyEgocentric L ⟩
x ∙ (L ∙ L) ≈˘⟨ isLark x L ⟩
(L ∙ x) ∙ L ≈⟨ congʳ $ isHopelesslyEgocentric x ⟩
L ∙ L ≈⟨ isHopelesslyEgocentric L ⟩
L ∎
module _ ⦃ _ : HasLark ⦄ ⦃ _ : HasKestrel ⦄ where
problem₂₇ : L ≉ K → ¬ L IsFondOf K
problem₂₇ L≉K isFond =
let K-fondOf-KK : K IsFondOf K ∙ K
K-fondOf-KK = begin
K ∙ (K ∙ K) ≈˘⟨ congʳ isFond ⟩
(L ∙ K) ∙ (K ∙ K) ≈⟨ isLark K (K ∙ K) ⟩
K ∙ ((K ∙ K) ∙ (K ∙ K)) ≈⟨ congˡ $ isKestrel K (K ∙ K) ⟩
K ∙ K ∎
isEgocentric : IsEgocentric K
isEgocentric = problem₁₈ K K-fondOf-KK
L≈K : L ≈ K
L≈K = problem₁₉ K isKestrel isEgocentric L
in L≉K L≈K
problem₂₈ : K IsFondOf L → ∀ x → x IsFondOf L
problem₂₈ KL≈L =
let isHopelesslyEgocentric : IsHopelesslyEgocentric L
isHopelesslyEgocentric y = begin
L ∙ y ≈˘⟨ congʳ KL≈L ⟩
(K ∙ L) ∙ y ≈⟨ isKestrel L y ⟩
L ∎
in problem₂₆ isHopelesslyEgocentric
module _ ⦃ _ : HasLark ⦄ where
problem₂₉ : ∃[ x ] IsEgocentric x
problem₂₉ =
let (y , [LL]y≈y) = problem₂₅ (L ∙ L)
isEgocentric : IsEgocentric (y ∙ y)
isEgocentric = begin
(y ∙ y) ∙ (y ∙ y) ≈˘⟨ isLark (y ∙ y) y ⟩
(L ∙ (y ∙ y)) ∙ y ≈˘⟨ congʳ (isLark L y) ⟩
((L ∙ L) ∙ y) ∙ y ≈⟨ congʳ [LL]y≈y ⟩
y ∙ y ∎
-- The expression of yy in terms of L and brackets.
_ : y ∙ y ≈ ((L ∙ (L ∙ L)) ∙ (L ∙ (L ∙ L))) ∙ ((L ∙ (L ∙ L)) ∙ (L ∙ (L ∙ L)))
_ = refl
in (y ∙ y , isEgocentric)
|
{
"alphanum_fraction": 0.4919610855,
"avg_line_length": 29.8623853211,
"ext": "agda",
"hexsha": "717d0e2d2a1ca48e056369a4fdf971af3052b7c5",
"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": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "splintah/combinatory-logic",
"max_forks_repo_path": "Mockingbird/Problems/Chapter09.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"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": "splintah/combinatory-logic",
"max_issues_repo_path": "Mockingbird/Problems/Chapter09.agda",
"max_line_length": 86,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "splintah/combinatory-logic",
"max_stars_repo_path": "Mockingbird/Problems/Chapter09.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-28T23:44:42.000Z",
"num_tokens": 4476,
"size": 9765
}
|
module Web.URI.Scheme.Primitive where
postulate Scheme? : Set
{-# COMPILED_TYPE Scheme? String #-}
postulate http: : Scheme?
{-# COMPILED http: "http:" #-}
postulate https: : Scheme?
{-# COMPILED https: "https:" #-}
postulate ε : Scheme?
{-# COMPILED ε "" #-}
|
{
"alphanum_fraction": 0.6528301887,
"avg_line_length": 17.6666666667,
"ext": "agda",
"hexsha": "868da09cde201739c6b311502fdeca94b7ca0f9c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:37:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:37:59.000Z",
"max_forks_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-web-uri",
"max_forks_repo_path": "src/Web/URI/Scheme/Primitive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-web-uri",
"max_issues_repo_path": "src/Web/URI/Scheme/Primitive.agda",
"max_line_length": 37,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "8ced22124dbe12fa820699bb362247a96d592c03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-uri",
"max_stars_repo_path": "src/Web/URI/Scheme/Primitive.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-23T04:56:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-23T04:56:25.000Z",
"num_tokens": 71,
"size": 265
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Base.ByteString
open import LibraBFT.Base.Encode
open import LibraBFT.Base.KVMap
open import LibraBFT.Base.PKCS
open import LibraBFT.Hash
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Impl.Consensus.Types
open import LibraBFT.Impl.Util.Crypto
open import LibraBFT.Impl.Util.Util
import LibraBFT.Yasm.Types as LYT
open import Optics.All
-- This module provides some scaffolding to define the handlers for our fake/simple
-- "implementation" and connect them to the interface of the SystemModel.
module LibraBFT.Impl.Handle where
open import LibraBFT.Impl.Consensus.RoundManager
open RWST-do
open EpochConfig
record GenesisInfo : Set where
constructor mkGenInfo
field
-- TODO-1 : Nodes, PKs for initial epoch
-- TODO-1 : Faults to tolerate (or quorum size?)
genQC : QuorumCert -- We use the same genesis QC for both highestQC and
-- highestCommitCert.
open GenesisInfo
postulate -- valid assumption
-- We postulate the existence of GenesisInfo known to all
-- TODO: construct one or write a function that generates one from some parameters.
genInfo : GenesisInfo
postulate -- TODO-2: define GenesisInfo to match implementation and write these functions
initVV : GenesisInfo → ValidatorVerifier
init-EC : GenesisInfo → EpochConfig
data ∈GenInfo : Signature → Set where
inGenQC : ∀ {vs} → vs ∈ qcVotes (genQC genInfo) → ∈GenInfo (proj₂ vs)
open import LibraBFT.Abstract.Records UID _≟UID_ NodeId
(init-EC genInfo)
(ConcreteVoteEvidence (init-EC genInfo))
as Abs using ()
postulate -- TODO-1 : prove
∈GenInfo? : (sig : Signature) → Dec (∈GenInfo sig)
postulate -- TODO-1: prove after defining genInfo
genVotesRound≡0 : ∀ {pk v}
→ (wvs : WithVerSig pk v)
→ ∈GenInfo (ver-signature wvs)
→ v ^∙ vRound ≡ 0
genVotesConsistent : (v1 v2 : Vote)
→ ∈GenInfo (₋vSignature v1) → ∈GenInfo (₋vSignature v2)
→ v1 ^∙ vProposedId ≡ v2 ^∙ vProposedId
postulate -- TODO-1: reasonable assumption that some RoundManager exists, though we could prove
-- it by construction; eventually we will construct an entire RoundManager, so
-- this won't be needed
-- This represents an uninitialised RoundManager, about which we know nothing, which we use as
-- the initial RoundManager for every peer until it is initialised.
fakeRM : RoundManager
initSR : SafetyRules
initSR = over (srPersistentStorage ∙ pssSafetyData ∙ sdEpoch) (const 1)
(over (srPersistentStorage ∙ pssSafetyData ∙ sdLastVotedRound) (const 0)
(₋rmSafetyRules (₋rmEC fakeRM)))
initRMEC : RoundManagerEC
initRMEC = RoundManagerEC∙new (EpochState∙new 1 (initVV genInfo)) initSR
postulate -- TODO-2 : prove these once initRMEC is defined directly
init-EC-epoch-1 : epoch (init-EC genInfo) ≡ 1
initRMEC-correct : RoundManagerEC-correct initRMEC
initRM : RoundManager
initRM = fakeRM
-- Eventually, the initialization should establish some properties we care about, but for now we
-- just initialise again to fakeRM, which means we cannot prove the base case for various
-- properties, e.g., in Impl.Properties.VotesOnce
-- TODO: create real RoundManager using GenesisInfo
initialRoundManagerAndMessages
: (a : Author) → GenesisInfo
→ RoundManager × List NetworkMsg
initialRoundManagerAndMessages a _ = initRM , []
handle : NodeId → NetworkMsg → Instant → LBFT Unit
handle _self msg now
with msg
...| P p = processProposalMsg now p
...| V v = processVote now v
...| C c = return unit -- We don't do anything with commit messages, they are just for defining Correctness.
initWrapper : NodeId → GenesisInfo → RoundManager × List (LYT.Action NetworkMsg)
initWrapper nid g = ×-map₂ (List-map LYT.send) (initialRoundManagerAndMessages nid g)
-- Note: the SystemModel allows anyone to receive any message sent, so intended recipient is ignored;
-- it is included in the model only to facilitate future work on liveness properties, when we will need
-- assumptions about message delivery between honest peers.
outputToActions : RoundManager → Output → List (LYT.Action NetworkMsg)
outputToActions rm (BroadcastProposal p) = List-map (const (LYT.send (P p)))
(List-map proj₁
(kvm-toList (:vvAddressToValidatorInfo (₋esVerifier (₋rmEpochState (₋rmEC rm))))))
outputToActions _ (LogErr x) = []
outputToActions _ (SendVote v toList) = List-map (const (LYT.send (V v))) toList
outputsToActions : ∀ {State} → List Output → List (LYT.Action NetworkMsg)
outputsToActions {st} = concat ∘ List-map (outputToActions st)
runHandler : RoundManager → LBFT Unit → RoundManager × List (LYT.Action NetworkMsg)
runHandler st handler = ×-map₂ (outputsToActions {st}) (proj₂ (LBFT-run handler st))
-- And ultimately, the all-knowing system layer only cares about the
-- step function.
--
-- Note that we currently do not do anything non-trivial with the timestamp.
-- Here, we just pass 0 to `handle`.
peerStep : NodeId → NetworkMsg → RoundManager → RoundManager × List (LYT.Action NetworkMsg)
peerStep nid msg st = runHandler st (handle nid msg 0)
|
{
"alphanum_fraction": 0.6845534031,
"avg_line_length": 44.1893939394,
"ext": "agda",
"hexsha": "53dfc7c4de1da6489287b9df21410833a2a5f833",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Impl/Handle.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Impl/Handle.agda",
"max_line_length": 145,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Impl/Handle.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1482,
"size": 5833
}
|
{-# OPTIONS --no-positivity-check --no-termination-check #-}
module Homogenous.Base where
-- module Homogenous.Base(Arity, Sig, T, Intro) where
import TYPE
import PolyDepPrelude
open PolyDepPrelude using
( Absurd
; Unit; unit
; Nat; zero; suc
; List; nil; _::_
; Either; left; right
; Pair; pair)
-- A homogenous algebra can be represented by a list of arities
-- (natural numbers)
Arity : Set
Arity = Nat
Sig : Set
Sig = List Arity
-- Many definitions below come in pairs - one for Arity and one for
-- Sig - where name of the first one ends in a (as in Arity) :
-- funa : Arity -> ...
-- fun : Sig -> ...
-- (Fa n,Fa1 n) is the functor "n-tuple of same type" or
-- "vector of length n" or "(^n)"
Fa : (n : Arity) -> Set -> Set
Fa (zero) X = Unit
Fa (suc m) X = Pair X (Fa m X)
----------------------------------------------------------------
Fa1 : (n : Arity) -> {a b : Set} -> (a -> b) -> Fa n a -> Fa n b
Fa1 (zero) f (unit) = unit
Fa1 (suc m) f (pair fst snd) = pair (f fst) (Fa1 m f snd)
-- (F fi, F1 fi) is the pattern functor for a homogenous algebra
F : (fi : Sig)(X : Set) -> Set
F (nil) X = Absurd
F (n :: fi') X = Either (Fa n X) (F fi' X)
F1 : (fi : Sig){a b : Set}(f : a -> b)(x : F fi a) -> F fi b
F1 (nil) f () -- empty
F1 (n :: ns) f (left t) = left (Fa1 n f t)
F1 (n :: ns) f (right y) = right (F1 ns f y)
-- For the definition of the recursor R we need family-level
-- variants of F and F1 : FIH and Fmap. As usual we define these first
-- for arities (with a postfix 'a' in the name) and then for signatures.
FIHa : (n : Arity){X : Set}(C : X -> Set)(x : Fa n X) -> Set
FIHa (zero) C unit = Unit
FIHa (suc m) C (pair fst snd) = Pair (C fst) (FIHa m C snd)
FIH : (fi : Sig){X : Set}(C : X -> Set)(x : F fi X) -> Set
FIH (nil) C () -- empty
FIH (n :: ns) C (left t) = FIHa n C t
FIH (n :: ns) C (right y) = FIH ns C y
Fmapa : (n : Arity){X : Set}{C : X -> Set}(h : (x : X) -> C x)(u : Fa n X)
-> FIHa n C u
Fmapa (zero) h (unit) = unit
Fmapa (suc m) h (pair fst snd) = pair (h fst) (Fmapa m h snd)
Fmap : (fi : Sig){X : Set}{C : X -> Set}(h : (x : X) -> C x)(u : F fi X)
-> FIH fi C u
Fmap (nil) h () -- empty
Fmap (n :: ns) h (left x) = Fmapa n h x
Fmap (n :: ns) h (right y) = Fmap ns h y
-- Finally the homogenous algebra construction itself - for each code
-- fi there is a datatype T fi and an iterator It fi
data T (fi : Sig) : Set where
Intro : F fi (T fi) -> T fi
It : (fi : Sig){C : Set}(d : F fi C -> C) -> T fi -> C
It fi d (Intro i) = d (F1 fi (It fi d) i)
-- Mendler style iterator is also straight forward
MIt : (fi : Sig){C : Set}(s : {X : Set} -> (X -> C) -> F fi X -> C)
-> T fi -> C
MIt fi s (Intro i) = s (MIt fi s) i
R : (fi : Sig)
{C : T fi -> Set}
(d : (y : F fi (T fi)) -> FIH fi C y -> C (Intro y))
(x : T fi) -> C x
R fi d (Intro i) = d i (Fmap fi (R fi d) i)
-- Special case of FIH
FIHs : (fi : Sig) -> (T fi -> Set) -> F fi (T fi) -> Set
FIHs fi = FIH fi
-- A simple example : the inverse of Intro
out : (fi : Sig) -> T fi -> F fi (T fi)
out fi = R fi (\y p -> y)
----------------------------------------------------------------
-- Now for the Type level : define FIHa, FIH, Fmapa, Fmap again
-- (universe polymorphism, please!)
FIHaT : (n : Arity)(X : Set)(C : X -> Set1)(x : Fa n X) -> Set1
FIHaT (zero) X C (unit) = TYPE.Unit
FIHaT (suc m) X C (pair fst snd) = TYPE.Pair (C fst) (FIHaT m X C snd)
FIHT : (fi : Sig)(X : Set)(C : X -> Set1)(x : F fi X) -> Set1
FIHT (nil) X C () -- empty
FIHT (n :: ns) X C (left t) = FIHaT n X C t
FIHT (n :: ns) X C (right y) = FIHT ns X C y
FIHsT : (fi : Sig)(C : T fi -> Set1)(x : F fi (T fi)) -> Set1
FIHsT fi C x = FIHT fi (T fi) C x
FmapaT : (n : Arity){X : Set}{C : X -> Set1}(h : (x : X) -> C x)(u : Fa n X)
-> FIHaT n X C u
FmapaT (zero) h (unit) = TYPE.unit
FmapaT (suc m) h (pair fst snd) = TYPE.pair (h fst) (FmapaT m h snd)
FmapT : (fi : Sig){X : Set}{C : X -> Set1}(h : (x : X) -> C x)(u : F fi X)
-> FIHT fi X C u
FmapT (nil) h () -- empty
FmapT (n :: ns) h (left x') = FmapaT n h x'
FmapT (n :: ns) h (right y) = FmapT ns h y
RT : (fi : Sig)
{C : T fi -> Set1}
(d : (y : F fi (T fi)) -> FIHT fi (T fi) C y -> C (Intro y))
(x : T fi) -> C x
RT fi d (Intro i) = d i (FmapT fi (RT fi d) i)
|
{
"alphanum_fraction": 0.5132382892,
"avg_line_length": 31.3404255319,
"ext": "agda",
"hexsha": "5590205b8154ca26b069addcce82a02fb515d05c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/AIM5/PolyDep/Homogenous/Base.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/AIM5/PolyDep/Homogenous/Base.agda",
"max_line_length": 76,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/AIM5/PolyDep/Homogenous/Base.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": 1717,
"size": 4419
}
|
{-
This second-order term syntax was created from the following second-order syntax description:
syntax Naturals | Nat
type
N : 0-ary
term
ze : N
su : N -> N
nrec : N α (α,N).α -> α
theory
(zeβ) z : α s : (α,N).α |> nrec (ze, z, r m. s[r,m]) = z
(suβ) z : α s : (α,N).α n : N |> nrec (su (n), z, r m. s[r,m]) = s[nrec (n, z, r m. s[r,m]), n]
-}
module Naturals.Syntax where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Construction.Structure
open import SOAS.ContextMaps.Inductive
open import SOAS.Metatheory.Syntax
open import Naturals.Signature
private
variable
Γ Δ Π : Ctx
α : NatT
𝔛 : Familyₛ
-- Inductive term declaration
module Nat:Terms (𝔛 : Familyₛ) where
data Nat : Familyₛ where
var : ℐ ⇾̣ Nat
mvar : 𝔛 α Π → Sub Nat Π Γ → Nat α Γ
ze : Nat N Γ
su : Nat N Γ → Nat N Γ
nrec : Nat N Γ → Nat α Γ → Nat α (α ∙ N ∙ Γ) → Nat α Γ
open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛
Natᵃ : MetaAlg Nat
Natᵃ = record
{ 𝑎𝑙𝑔 = λ where
(zeₒ ⋮ _) → ze
(suₒ ⋮ a) → su a
(nrecₒ ⋮ a , b , c) → nrec a b c
; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }
module Natᵃ = MetaAlg Natᵃ
module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where
open MetaAlg 𝒜ᵃ
𝕤𝕖𝕞 : Nat ⇾̣ 𝒜
𝕊 : Sub Nat Π Γ → Π ~[ 𝒜 ]↝ Γ
𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t
𝕊 (t ◂ σ) (old v) = 𝕊 σ v
𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)
𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v
𝕤𝕖𝕞 ze = 𝑎𝑙𝑔 (zeₒ ⋮ tt)
𝕤𝕖𝕞 (su a) = 𝑎𝑙𝑔 (suₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞 (nrec a b c) = 𝑎𝑙𝑔 (nrecₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b , 𝕤𝕖𝕞 c)
𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Natᵃ 𝒜ᵃ 𝕤𝕖𝕞
𝕤𝕖𝕞ᵃ⇒ = record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }
; ⟨𝑣𝑎𝑟⟩ = refl
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }
where
open ≡-Reasoning
⟨𝑎𝑙𝑔⟩ : (t : ⅀ Nat α Γ) → 𝕤𝕖𝕞 (Natᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)
⟨𝑎𝑙𝑔⟩ (zeₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (suₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (nrecₒ ⋮ _) = refl
𝕊-tab : (mε : Π ~[ Nat ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)
𝕊-tab mε new = refl
𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v
module _ (g : Nat ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Natᵃ 𝒜ᵃ g) where
open MetaAlg⇒ gᵃ⇒
𝕤𝕖𝕞! : (t : Nat α Γ) → 𝕤𝕖𝕞 t ≡ g t
𝕊-ix : (mε : Sub Nat Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)
𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x
𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v
𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))
= trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))
𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩
𝕤𝕖𝕞! ze = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (su a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (nrec a b c) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b | 𝕤𝕖𝕞! c = sym ⟨𝑎𝑙𝑔⟩
-- Syntax instance for the signature
Nat:Syn : Syntax
Nat:Syn = record
{ ⅀F = ⅀F
; ⅀:CS = ⅀:CompatStr
; mvarᵢ = Nat:Terms.mvar
; 𝕋:Init = λ 𝔛 → let open Nat:Terms 𝔛 in record
{ ⊥ = Nat ⋉ Natᵃ
; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }
; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }
-- Instantiation of the syntax and metatheory
open Syntax Nat:Syn public
open Nat:Terms public
open import SOAS.Families.Build public
open import SOAS.Syntax.Shorthands Natᵃ public
open import SOAS.Metatheory Nat:Syn public
|
{
"alphanum_fraction": 0.5295169946,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "2703b3ce71b02e8a02baa0f9e2d8199d21e8c6db",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/Naturals/Syntax.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/Naturals/Syntax.agda",
"max_line_length": 100,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/Naturals/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 2046,
"size": 3354
}
|
module Data.Option.Iterable where
open import Data
open import Data.Option
import Data.Option.Functions as Option
open import Functional
open import Logic.Propositional
open import Logic.Predicate
import Lvl
open import Relator.Equals
open import Structure.Container.Iterable
open import Type
private variable ℓ : Lvl.Level
private variable T : Type{ℓ}
instance
Option-iterable : Iterable(Option(T))
Iterable.Element (Option-iterable {T = T}) = T
Iterable.isEmpty Option-iterable = Option.isNone
Iterable.current Option-iterable None = <>
Iterable.current Option-iterable (Some x) = x
Iterable.indexStep Option-iterable None = <>
Iterable.indexStep Option-iterable (Some _) = <>
Iterable.step Option-iterable None = <>
Iterable.step Option-iterable (Some x) = None
instance
Option-finite-iterable : Iterable.Finite(Option-iterable{T = T})
∃.witness Option-finite-iterable(_▫_) id None = id
∃.witness Option-finite-iterable(_▫_) id (Some x) = x ▫ id
∃.proof Option-finite-iterable {iter = None} = [≡]-intro
∃.proof Option-finite-iterable {iter = Some x} = [≡]-intro
instance
Option-empty : Iterable.EmptyConstruction(Option-iterable{T = T})(None)
Option-empty = <>
|
{
"alphanum_fraction": 0.7182985554,
"avg_line_length": 32.7894736842,
"ext": "agda",
"hexsha": "bbe0595c28d9ae46edc5e58cb594cc3b2236612c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data/Option/Iterable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/Option/Iterable.agda",
"max_line_length": 73,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data/Option/Iterable.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": 347,
"size": 1246
}
|
{-# OPTIONS --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Properties.Conversion {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.RedSteps
open import Definition.Typed.Reduction
import Definition.Typed.Weakening as W
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Tools.Product
import Tools.PropositionalEquality as PE
import Data.Fin as Fin
import Data.Nat as Nat
-- Conversion of syntactic reduction closures.
convRed:*: : ∀ {t u A B Γ l} → Γ ⊢ t :⇒*: u ∷ A ^ l → Γ ⊢ A ≡ B ^ [ ! , l ] → Γ ⊢ t :⇒*: u ∷ B ^ l
convRed:*: [[ ⊢t , ⊢u , d ]] A≡B = [[ conv ⊢t A≡B , conv ⊢u A≡B , conv* d A≡B ]]
-- helper functions for the universe
convTermTUniv : ∀ {Γ A B t l l' r ll l< d r' ll' l<' el' d'}
(er : r PE.≡ r') (ellll' : ll PE.≡ ll') →
Γ ⊩⟨ l ⟩ t ∷ A ^ [ ! , next ll ] / Uᵣ (Uᵣ r ll l< PE.refl d) →
Γ ⊩⟨ l' ⟩ t ∷ B ^ [ ! , next ll ] / Uᵣ (Uᵣ r' ll' l<' el' d')
convTermTUniv {l< = l<} {l<' = l<'} {d' = d'} er ellll' (Uₜ K d typeK K≡K [t]) =
let dd = PE.subst (λ x → _ ⊢ _ :⇒*: Univ x _ ^ _) (PE.sym er) (PE.subst (λ x → _ ⊢ _ :⇒*: Univ _ x ^ [ ! , next x ]) (PE.sym ellll') d') in
reduction-irrelevant-Univ {l< = l<} {l<' = l<'} {el = PE.refl} {D = dd} {D' = d'} er (Uₜ K d typeK K≡K [t])
convEqTermTUniv : ∀ {Γ A B t u l r ll l< d dd} →
Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ [ ! , next ll ] / Uᵣ (Uᵣ r ll l< PE.refl d) →
Γ ⊩⟨ l ⟩ t ≡ u ∷ B ^ [ ! , next ll ] / Uᵣ (Uᵣ r ll l< PE.refl dd)
convEqTermTUniv {l = ι ¹} {r = r} {⁰} (Uₜ₌ [t] [u] A≡B [t≡u]) =
Uₜ₌ (convTermTUniv PE.refl PE.refl [t]) (convTermTUniv PE.refl PE.refl [u]) A≡B [t≡u]
convEqTermTUniv {l = ∞} {r = r} {¹} (Uₜ₌ [t] [u] A≡B [t≡u]) =
Uₜ₌ (convTermTUniv PE.refl PE.refl [t]) (convTermTUniv PE.refl PE.refl [u]) A≡B [t≡u]
mutual
-- Helper function for conversion of terms converting from left to right.
convTermT₁ : ∀ {Γ A B r t l l′} {[A] : Γ ⊩⟨ l ⟩ A ^ r} {[B] : Γ ⊩⟨ l′ ⟩ B ^ r}
→ ShapeView Γ l l′ A B r r [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A]
→ Γ ⊩⟨ l ⟩ t ∷ A ^ r / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B ^ r / [B]
convTermT₁ (ℕᵥ D D′) A≡B t = t
convTermT₁ (Emptyᵥ D D′) A≡B t = t
convTermT₁ {r = [ ! , ll ]} (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M) (neₜ k d (neNfₜ neK₂ ⊢k k≡k)) =
let K≡K₁ = PE.subst (λ x → _ ⊢ _ ≡ x ^ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(≅-eq (~-to-≅ K≡M))
in neₜ k (convRed:*: d K≡K₁)
(neNfₜ neK₂ (conv ⊢k K≡K₁) (~-conv k≡k K≡K₁))
convTermT₁ {r = [ % , ll ]} (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
(neₜ d) = let K≡K₁ = PE.subst (λ x → _ ⊢ _ ≡ x ^ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(≅-eq (~-to-≅ K≡M))
in neₜ (conv d (reduction (red D) (red D₁) (ne neK) (ne neK₁) K≡K₁))
convTermT₁ {Γ = Γ} {r = [ ! , ι ll ]} (Πᵥ (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ rF₁ lF₁ lG₁ _ _ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ f d funcF f≡f [f] [f]₁) =
let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
F₁≡F′ , rF₁≡rF′ , lF₁≡lF′ , G₁≡G′ , lG₁≡lG′ , lΠ≡lΠ₁ = Π-PE-injectivity ΠF₁G₁≡ΠF′G′
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° ll ≡ x ^ [ ! , ι ll ]) (PE.sym ΠF₁G₁≡ΠF′G′)
(≅-eq A≡B)
in Πₜ f (convRed:*: d ΠFG≡ΠF₁G₁) funcF (≅-conv f≡f ΠFG≡ΠF₁G₁)
(λ {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₂′ PE.refl (PE.sym rF₁≡rF′) (PE.cong ι (PE.sym lF₁≡lF′)) ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[b]₁ = convTerm₂′ PE.refl (PE.sym rF₁≡rF′) (PE.cong ι (PE.sym lF₁≡lF′)) ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [b]
[a≡b]₁ = convEqTerm₂′ (PE.sym rF₁≡rF′) (PE.cong ι (PE.sym lF₁≡lF′)) ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a≡b]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a]₁)
([G≡G′] [ρ] ⊢Δ [a]₁)
in convEqTerm₁′ PE.refl (PE.cong ι (PE.sym lG₁≡lG′)) ([G] [ρ] ⊢Δ [a]₁) ([G]₁ [ρ] ⊢Δ [a]) [G≡G₁]
([f] [ρ] ⊢Δ [a]₁ [b]₁ [a≡b]₁))
(λ {ρ} [ρ] ⊢Δ [a] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₂′ PE.refl (PE.sym rF₁≡rF′) (PE.cong ι (PE.sym lF₁≡lF′)) ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a]₁)
([G≡G′] [ρ] ⊢Δ [a]₁)
in convTerm₁′ PE.refl (PE.cong ι (PE.sym lG₁≡lG′)) ([G] [ρ] ⊢Δ [a]₁) ([G]₁ [ρ] ⊢Δ [a]) [G≡G₁] ([f]₁ [ρ] ⊢Δ [a]₁))
convTermT₁ {Γ = Γ} {r = [ % , ι ll ]} (Πᵥ (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ rF₁ lF₁ lG₁ _ _ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
d = let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
F₁≡F′ , rF₁≡rF′ , lF₁≡lF′ , G₁≡G′ , lG₁≡lG′ = Π-PE-injectivity ΠF₁G₁≡ΠF′G′
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° ll ≡ x ^ [ % , ι ll ]) (PE.sym ΠF₁G₁≡ΠF′G′)
(≅-eq A≡B)
in conv d ΠFG≡ΠF₁G₁
convTermT₁ {Γ = Γ} {r = [ % , ll ]} (∃ᵥ (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(∃ᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
d = let ∃F₁G₁≡∃F′G′ = whrDet* (red D₁ , ∃ₙ) (D′ , ∃ₙ)
F₁≡F′ , G₁≡G′ = ∃-PE-injectivity ∃F₁G₁≡∃F′G′
∃FG≡∃F₁G₁ = PE.subst (λ x → Γ ⊢ ∃ F ▹ G ≡ x ^ [ % , ll ]) (PE.sym ∃F₁G₁≡∃F′G′)
(≅-eq A≡B)
in conv d ∃FG≡∃F₁G₁
convTermT₁ (Uᵥ (Uᵣ r l l< PE.refl d) (Uᵣ r' l' l<' el' d')) A≡B X =
let U≡U = whrDet* (A≡B , Uₙ) (red d' , Uₙ)
r≡r , l≡l = Univ-PE-injectivity U≡U
in convTermTUniv r≡r l≡l X
convTermT₁ (emb⁰¹ X) A≡B t = convTermT₁ X A≡B t
convTermT₁ (emb¹⁰ X) A≡B t = convTermT₁ X A≡B t
convTermT₁ (emb¹∞ X) A≡B t = convTermT₁ X A≡B t
convTermT₁ (emb∞¹ X) A≡B t = convTermT₁ X A≡B t
-- Helper function for conversion of terms converting from right to left.
convTermT₂ : ∀ {l l′ Γ A B r t} {[A] : Γ ⊩⟨ l ⟩ A ^ r} {[B] : Γ ⊩⟨ l′ ⟩ B ^ r}
→ ShapeView Γ l l′ A B r r [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B ^ r / [B]
→ Γ ⊩⟨ l ⟩ t ∷ A ^ r / [A]
convTermT₂ (ℕᵥ D D′) A≡B t = t
convTermT₂ (Emptyᵥ D D′) A≡B t = t
convTermT₂ {r = [ ! , ll ]} (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
(neₜ k d (neNfₜ neK₂ ⊢k k≡k)) =
let K₁≡K = PE.subst (λ x → _ ⊢ x ≡ _ ^ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(sym (≅-eq (~-to-≅ K≡M)))
in neₜ k (convRed:*: d K₁≡K)
(neNfₜ neK₂ (conv ⊢k K₁≡K) (~-conv k≡k K₁≡K))
convTermT₂ {r = [ % , ll ]} (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
(neₜ d) = let K₁≡K = PE.subst (λ x → _ ⊢ x ≡ _ ^ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(sym (≅-eq (~-to-≅ K≡M)))
in neₜ (conv d (reduction (red D₁) (red D) (ne neK₁) (ne neK) K₁≡K))
convTermT₂ {Γ = Γ} {r = [ ! , ι ll ]} (Πᵥ (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ rF₁ lF₁ lG₁ _ _ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ f d funcF f≡f [f] [f]₁) =
let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
F₁≡F′ , rF₁≡rF′ , lF₁≡lF′ , G₁≡G′ , lG₁≡lG′ , lΠ≡lΠ₁ = Π-PE-injectivity ΠF₁G₁≡ΠF′G′
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° ll ≡ x ^ [ ! , ι ll ])
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in Πₜ f (convRed:*: d (sym ΠFG≡ΠF₁G₁)) funcF (≅-conv f≡f (sym ΠFG≡ΠF₁G₁))
(λ {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₁′ (PE.sym rF₁≡rF′) (PE.cong ι (PE.sym lF₁≡lF′)) ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[b]₁ = convTerm₁′ (PE.sym rF₁≡rF′) (PE.cong ι (PE.sym lF₁≡lF′)) ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [b]
[a≡b]₁ = convEqTerm₁′ (PE.sym rF₁≡rF′) (PE.cong ι (PE.sym lF₁≡lF′)) ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a≡b]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a])
([G≡G′] [ρ] ⊢Δ [a])
in convEqTerm₂′ PE.refl (PE.cong ι (PE.sym lG₁≡lG′)) ([G] [ρ] ⊢Δ [a]) ([G]₁ [ρ] ⊢Δ [a]₁)
[G≡G₁] ([f] [ρ] ⊢Δ [a]₁ [b]₁ [a≡b]₁))
(λ {ρ} [ρ] ⊢Δ [a] →
let [F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₁′ (PE.sym rF₁≡rF′) (PE.cong ι (PE.sym lF₁≡lF′)) ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a])
([G≡G′] [ρ] ⊢Δ [a])
in convTerm₂′ PE.refl PE.refl (PE.cong ι (PE.sym lG₁≡lG′)) ([G] [ρ] ⊢Δ [a]) ([G]₁ [ρ] ⊢Δ [a]₁)
[G≡G₁] ([f]₁ [ρ] ⊢Δ [a]₁))
convTermT₂ {Γ = Γ} {r = [ % , ι ll ]} (Πᵥ (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ rF₁ lF₁ lG₁ _ _ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
d = let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
F₁≡F′ , rF₁≡rF′ , lF₁≡lF′ , G₁≡G′ , lG₁≡lG′ = Π-PE-injectivity ΠF₁G₁≡ΠF′G′
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° ll ≡ x ^ [ % , ι ll ])
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in conv d (sym ΠFG≡ΠF₁G₁)
convTermT₂ {Γ = Γ} {r = [ % , ll ]} (∃ᵥ (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(∃ᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
d = let ∃F₁G₁≡∃F′G′ = whrDet* (red D₁ , ∃ₙ) (D′ , ∃ₙ)
F₁≡F′ , G₁≡G′ = ∃-PE-injectivity ∃F₁G₁≡∃F′G′
∃FG≡∃F₁G₁ = PE.subst (λ x → Γ ⊢ ∃ F ▹ G ≡ x ^ [ % , ll ])
(PE.sym ∃F₁G₁≡∃F′G′) (≅-eq A≡B)
in conv d (sym ∃FG≡∃F₁G₁)
convTermT₂ (Uᵥ (Uᵣ r l l< el d) (Uᵣ r' l' l<' PE.refl d')) A≡B X =
let U≡U = whrDet* (A≡B , Uₙ) (red d' , Uₙ)
r≡r , l≡l = Univ-PE-injectivity U≡U
in convTermTUniv (PE.sym r≡r) (PE.sym l≡l) X
convTermT₂ (emb⁰¹ X) A≡B t = convTermT₂ X A≡B t
convTermT₂ (emb¹⁰ X) A≡B t = convTermT₂ X A≡B t
convTermT₂ (emb¹∞ X) A≡B t = convTermT₂ X A≡B t
convTermT₂ (emb∞¹ X) A≡B t = convTermT₂ X A≡B t
-- Conversion of terms converting from left to right.
convTerm₁ : ∀ {Γ A B r ll t l l′} ([A] : Γ ⊩⟨ l ⟩ A ^ [ r , ll ]) ([B] : Γ ⊩⟨ l′ ⟩ B ^ [ r , ll ])
→ Γ ⊩⟨ l ⟩ A ≡ B ^ [ r , ll ] / [A]
→ Γ ⊩⟨ l ⟩ t ∷ A ^ [ r , ll ] / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B ^ [ r , ll ] / [B]
convTerm₁ [A] [B] A≡B t = convTermT₁ (goodCases [A] [B] A≡B) A≡B t
-- Conversion of terms converting from left to right. with PE
convTerm₁′ : ∀ {Γ A B r r' ll ll' t l l′} (eq : r PE.≡ r') (eql : ll PE.≡ ll')
([A] : Γ ⊩⟨ l ⟩ A ^ [ r , ll ]) ([B] : Γ ⊩⟨ l′ ⟩ B ^ [ r' , ll' ])
→ Γ ⊩⟨ l ⟩ A ≡ B ^ [ r , ll ] / [A]
→ Γ ⊩⟨ l ⟩ t ∷ A ^ [ r , ll ] / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B ^ [ r' , ll' ] / [B]
convTerm₁′ PE.refl PE.refl [A] [B] A≡B t = convTerm₁ [A] [B] A≡B t
-- Conversion of terms converting from right to left.
convTerm₂ : ∀ {Γ A B r t l l′} ([A] : Γ ⊩⟨ l ⟩ A ^ r) ([B] : Γ ⊩⟨ l′ ⟩ B ^ r)
→ Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B ^ r / [B]
→ Γ ⊩⟨ l ⟩ t ∷ A ^ r / [A]
convTerm₂ [A] [B] A≡B t = convTermT₂ (goodCases [A] [B] A≡B) A≡B t
-- Conversion of terms converting from right to left
-- with some propsitionally equal types.
convTerm₂′ : ∀ {Γ A r r' ll ll' B B′ t l l′} → B PE.≡ B′ → r PE.≡ r' → ll PE.≡ ll'
→ ([A] : Γ ⊩⟨ l ⟩ A ^ [ r , ll ] ) ([B] : Γ ⊩⟨ l′ ⟩ B ^ [ r' , ll' ])
→ Γ ⊩⟨ l ⟩ A ≡ B′ ^ [ r , ll ] / [A]
→ Γ ⊩⟨ l′ ⟩ t ∷ B ^ [ r' , ll' ] / [B]
→ Γ ⊩⟨ l ⟩ t ∷ A ^ [ r , ll ] / [A]
convTerm₂′ PE.refl PE.refl PE.refl [A] [B] A≡B t = convTerm₂ [A] [B] A≡B t
-- Helper function for conversion of term equality converting from left to right.
convEqTermT₁ : ∀ {l l′ Γ A B r t u} {[A] : Γ ⊩⟨ l ⟩ A ^ r} {[B] : Γ ⊩⟨ l′ ⟩ B ^ r}
→ ShapeView Γ l l′ A B r r [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ r / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B ^ r / [B]
convEqTermT₁ (ℕᵥ D D′) A≡B t≡u = t≡u
convEqTermT₁ (Emptyᵥ D D′) A≡B t≡u = t≡u
convEqTermT₁ {r = [ ! , ll ]} (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
(neₜ₌ k m d d′ (neNfₜ₌ neK₂ neM₁ k≡m)) =
let K≡K₁ = PE.subst (λ x → _ ⊢ _ ≡ x ^ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(≅-eq (~-to-≅ K≡M))
in neₜ₌ k m (convRed:*: d K≡K₁)
(convRed:*: d′ K≡K₁)
(neNfₜ₌ neK₂ neM₁ (~-conv k≡m K≡K₁))
convEqTermT₁ {r = [ % , ll ]} (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
(neₜ₌ d d′) =
let K≡K₁ = PE.subst (λ x → _ ⊢ _ ≡ x ^ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(≅-eq (~-to-≅ K≡M))
in neₜ₌ (conv d (reduction (red D) (red D₁) (ne neK) (ne neK₁) K≡K₁))
(conv d′ (reduction (red D) (red D₁) (ne neK) (ne neK₁) K≡K₁))
convEqTermT₁ {Γ = Γ} {r = [ ! , ι ll ]} (Πᵥ (Πᵣ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ rF₁ lF₁ lG₁ lF₁≤ lG₁≤ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ₌ f g d d′ funcF funcG t≡u [t] [u] [t≡u]) =
let [A] = Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext
[B] = Πᵣ′ rF₁ lF₁ lG₁ lF₁≤ lG₁≤ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁
[A≡B] = Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]
ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° ll ≡ x ^ [ ! , ι ll ])
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in Πₜ₌ f g (convRed:*: d ΠFG≡ΠF₁G₁) (convRed:*: d′ ΠFG≡ΠF₁G₁)
funcF funcG (≅-conv t≡u ΠFG≡ΠF₁G₁)
(convTerm₁ [A] [B] [A≡B] [t]) (convTerm₁ [A] [B] [A≡B] [u])
(λ {ρ} [ρ] ⊢Δ [a] →
let F₁≡F′ , rF₁≡rF′ , lF₁≡lF′ , G₁≡G′ , lG₁≡lG′ , lΠ≡lΠ₁ = Π-PE-injectivity (whrDet* (red D₁ , Πₙ) (D′ , Πₙ))
[F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₂′ PE.refl (PE.sym rF₁≡rF′) (PE.cong ι (PE.sym lF₁≡lF′)) ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a]₁)
([G≡G′] [ρ] ⊢Δ [a]₁)
in convEqTerm₁′ PE.refl (PE.cong ι (PE.sym lG₁≡lG′)) ([G] [ρ] ⊢Δ [a]₁) ([G]₁ [ρ] ⊢Δ [a])
[G≡G₁] ([t≡u] [ρ] ⊢Δ [a]₁))
convEqTermT₁ {Γ = Γ} {r = [ % , ι ll ]} (Πᵥ (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ rF₁ lF₁ lG₁ _ _ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(d , d′) = let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° ll ≡ x ^ [ % , ι ll ])
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in conv d ΠFG≡ΠF₁G₁ , conv d′ ΠFG≡ΠF₁G₁
convEqTermT₁ {Γ = Γ} {r = [ % , ll ]} (∃ᵥ (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(∃ᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(d , d′) = let ∃F₁G₁≡∃F′G′ = whrDet* (red D₁ , ∃ₙ) (D′ , ∃ₙ)
∃FG≡∃F₁G₁ = PE.subst (λ x → Γ ⊢ ∃ F ▹ G ≡ x ^ [ % , ll ])
(PE.sym ∃F₁G₁≡∃F′G′) (≅-eq A≡B)
in (conv d ∃FG≡∃F₁G₁) , conv d′ ∃FG≡∃F₁G₁
convEqTermT₁ (Uᵥ (Uᵣ r ll l< PE.refl d) (Uᵣ r' ll' l<' el' d')) A≡B X =
let U≡U = whrDet* (A≡B , Uₙ) (red d' , Uₙ)
r≡r , l≡l = Univ-PE-injectivity U≡U
dd = PE.subst (λ x → _ ⊢ _ :⇒*: Univ x _ ^ _) (PE.sym r≡r) (PE.subst (λ x → _ ⊢ _ :⇒*: Univ _ x ^ [ ! , next x ]) (PE.sym l≡l) d')
in reduction-irrelevant-Univ= {l< = l<} {l<' = l<'} {el = PE.refl} {el' = el'} {D = dd} {D' = d'} r≡r (convEqTermTUniv X)
convEqTermT₁ (emb⁰¹ X) A≡B t≡u = convEqTermT₁ X A≡B t≡u
convEqTermT₁ (emb¹⁰ X) A≡B t≡u = convEqTermT₁ X A≡B t≡u
convEqTermT₁ (emb¹∞ X) A≡B t≡u = convEqTermT₁ X A≡B t≡u
convEqTermT₁ (emb∞¹ X) A≡B t≡u = convEqTermT₁ X A≡B t≡u
-- Helper function for conversion of term equality converting from right to left.
convEqTermT₂ : ∀ {l l′ Γ A B t u r} {[A] : Γ ⊩⟨ l ⟩ A ^ r} {[B] : Γ ⊩⟨ l′ ⟩ B ^ r}
→ ShapeView Γ l l′ A B r r [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B ^ r / [B]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ r / [A]
convEqTermT₂ (ℕᵥ D D′) A≡B t≡u = t≡u
convEqTermT₂ (Emptyᵥ D D′) A≡B t≡u = t≡u
convEqTermT₂ {r = [ ! , ll ]} (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
(neₜ₌ k m d d′ (neNfₜ₌ neK₂ neM₁ k≡m)) =
let K₁≡K = PE.subst (λ x → _ ⊢ x ≡ _ ^ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(sym (≅-eq (~-to-≅ K≡M)))
in neₜ₌ k m (convRed:*: d K₁≡K) (convRed:*: d′ K₁≡K)
(neNfₜ₌ neK₂ neM₁ (~-conv k≡m K₁≡K))
convEqTermT₂ {r = [ % , ll ]} (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
(neₜ₌ d d′) =
let K₁≡K = PE.subst (λ x → _ ⊢ x ≡ _ ^ _)
(whrDet* (red D′ , ne neM) (red D₁ , ne neK₁))
(sym (≅-eq (~-to-≅ K≡M)))
in neₜ₌ (conv d (reduction (red D₁) (red D) (ne neK₁) (ne neK) K₁≡K))
(conv d′ (reduction (red D₁) (red D) (ne neK₁) (ne neK) K₁≡K))
convEqTermT₂ {Γ = Γ} {r = [ ! , ι ll ]} (Πᵥ (Πᵣ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ rF₁ lF₁ lG₁ lF₁≤ lG₁≤ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(Πₜ₌ f g d d′ funcF funcG t≡u [t] [u] [t≡u]) =
let [A] = Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext
[B] = Πᵣ′ rF₁ lF₁ lG₁ lF₁≤ lG₁≤ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁
[A≡B] = Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]
ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° ll ≡ x ^ [ ! , ι ll ])
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in Πₜ₌ f g (convRed:*: d (sym ΠFG≡ΠF₁G₁)) (convRed:*: d′ (sym ΠFG≡ΠF₁G₁))
funcF funcG (≅-conv t≡u (sym ΠFG≡ΠF₁G₁))
(convTerm₂ [A] [B] [A≡B] [t]) (convTerm₂ [A] [B] [A≡B] [u])
(λ {ρ} [ρ] ⊢Δ [a] →
let F₁≡F′ , rF₁≡rF′ , lF₁≡lF′ , G₁≡G′ , lG₁≡lG′ , lΠ≡lΠ₁ = Π-PE-injectivity (whrDet* (red D₁ , Πₙ) (D′ , Πₙ))
[F≡F₁] = irrelevanceEqR′ (PE.cong (wk ρ) (PE.sym F₁≡F′))
([F] [ρ] ⊢Δ) ([F≡F′] [ρ] ⊢Δ)
[a]₁ = convTerm₁′ (PE.sym rF₁≡rF′) (PE.cong ι (PE.sym lF₁≡lF′)) ([F] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ) [F≡F₁] [a]
[G≡G₁] = irrelevanceEqR′ (PE.cong (λ x → wk (lift ρ) x [ _ ])
(PE.sym G₁≡G′))
([G] [ρ] ⊢Δ [a])
([G≡G′] [ρ] ⊢Δ [a])
in convEqTerm₂′ PE.refl (PE.cong ι (PE.sym lG₁≡lG′)) ([G] [ρ] ⊢Δ [a]) ([G]₁ [ρ] ⊢Δ [a]₁)
[G≡G₁] ([t≡u] [ρ] ⊢Δ [a]₁))
convEqTermT₂ {Γ = Γ} {r = [ % , ι ll ]} (Πᵥ (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πᵣ rF₁ lF₁ lG₁ _ _ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(d , d′) =
let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , Πₙ) (D′ , Πₙ)
ΠFG≡ΠF₁G₁ = PE.subst (λ x → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° ll ≡ x ^ [ % , ι ll ])
(PE.sym ΠF₁G₁≡ΠF′G′) (≅-eq A≡B)
in (conv d (sym ΠFG≡ΠF₁G₁)) , (conv d′ (sym ΠFG≡ΠF₁G₁))
convEqTermT₂ {Γ = Γ} {r = [ % , ll ]} (∃ᵥ (∃ᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(∃ᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(∃₌ F′ G′ D′ A≡B [F≡F′] [G≡G′])
(d , d′) =
let ∃F₁G₁≡∃F′G′ = whrDet* (red D₁ , ∃ₙ) (D′ , ∃ₙ)
∃FG≡∃F₁G₁ = PE.subst (λ x → Γ ⊢ ∃ F ▹ G ≡ x ^ [ % , ll ])
(PE.sym ∃F₁G₁≡∃F′G′) (≅-eq A≡B)
in (conv d (sym ∃FG≡∃F₁G₁)) , (conv d′ (sym ∃FG≡∃F₁G₁))
convEqTermT₂ (Uᵥ (Uᵣ r l l< el d) (Uᵣ r' l' l<' PE.refl d')) A≡B X =
let U≡U = whrDet* (A≡B , Uₙ) (red d' , Uₙ)
r≡r , l≡l = Univ-PE-injectivity (PE.sym U≡U)
dd = PE.subst (λ x → _ ⊢ _ :⇒*: Univ x _ ^ _) (PE.sym r≡r) (PE.subst (λ x → _ ⊢ _ :⇒*: Univ _ x ^ [ ! , next x ]) (PE.sym l≡l) d)
in reduction-irrelevant-Univ= {l< = l<'} {el = PE.refl} {D = dd} {D' = d} r≡r (convEqTermTUniv X)
convEqTermT₂ (emb⁰¹ X) A≡B t≡u = convEqTermT₂ X A≡B t≡u
convEqTermT₂ (emb¹⁰ X) A≡B t≡u = convEqTermT₂ X A≡B t≡u
convEqTermT₂ (emb¹∞ X) A≡B t≡u = convEqTermT₂ X A≡B t≡u
convEqTermT₂ (emb∞¹ X) A≡B t≡u = convEqTermT₂ X A≡B t≡u
-- Conversion of term equality converting from left to right.
convEqTerm₁ : ∀ {l l′ Γ A B t u r} ([A] : Γ ⊩⟨ l ⟩ A ^ r) ([B] : Γ ⊩⟨ l′ ⟩ B ^ r)
→ Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ r / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B ^ r / [B]
convEqTerm₁ [A] [B] A≡B t≡u = convEqTermT₁ (goodCases [A] [B] A≡B) A≡B t≡u
-- Conversion of term equality converting from left to right. with PE
convEqTerm₁′ : ∀ {l l′ Γ A B t u r r' ll ll'} (eq : r PE.≡ r') (eql : ll PE.≡ ll')
([A] : Γ ⊩⟨ l ⟩ A ^ [ r , ll ]) ([B] : Γ ⊩⟨ l′ ⟩ B ^ [ r' , ll' ])
→ Γ ⊩⟨ l ⟩ A ≡ B ^ [ r , ll ] / [A]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ [ r , ll ] / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B ^ [ r' , ll' ] / [B]
convEqTerm₁′ PE.refl PE.refl [A] [B] A≡B t≡u = convEqTerm₁ [A] [B] A≡B t≡u
-- Conversion of term equality converting from right to left.
convEqTerm₂ : ∀ {l l′ Γ A B t u r ll} ([A] : Γ ⊩⟨ l ⟩ A ^ [ r , ll ]) ([B] : Γ ⊩⟨ l′ ⟩ B ^ [ r , ll ])
→ Γ ⊩⟨ l ⟩ A ≡ B ^ [ r , ll ] / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B ^ [ r , ll ] / [B]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ [ r , ll ] / [A]
convEqTerm₂ [A] [B] A≡B t≡u = convEqTermT₂ (goodCases [A] [B] A≡B) A≡B t≡u
-- Conversion of term equality converting from right to left with PE
convEqTerm₂′ : ∀ {l l′ Γ A B t u r r' ll ll'} (eq : r PE.≡ r') (eql : ll PE.≡ ll')
([A] : Γ ⊩⟨ l ⟩ A ^ [ r , ll ]) ([B] : Γ ⊩⟨ l′ ⟩ B ^ [ r' , ll' ])
→ Γ ⊩⟨ l ⟩ A ≡ B ^ [ r , ll ] / [A]
→ Γ ⊩⟨ l′ ⟩ t ≡ u ∷ B ^ [ r' , ll' ] / [B]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ [ r , ll ] / [A]
convEqTerm₂′ PE.refl PE.refl [A] [B] A≡B t≡u = convEqTerm₂ [A] [B] A≡B t≡u
|
{
"alphanum_fraction": 0.3947889443,
"avg_line_length": 62.0491400491,
"ext": "agda",
"hexsha": "c76f8bcad5918943f2ec2652ad95e02f72c75275",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Properties/Conversion.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Properties/Conversion.agda",
"max_line_length": 143,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Properties/Conversion.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 12898,
"size": 25254
}
|
-- Useless private
module Issue476a where
A : Set₁
private
A = Set
|
{
"alphanum_fraction": 0.7142857143,
"avg_line_length": 10,
"ext": "agda",
"hexsha": "eb3072bfcc65b269e12f8b7ddd794b11d4c2d0ef",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Issue476a.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/Issue476a.agda",
"max_line_length": 22,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue476a.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": 23,
"size": 70
}
|
-- Andreas, 2015-05-06
module Issue1484 where
data ⊥ : Set where
-- Smörgåsbord of legal absurd lambdas
-- non-hidden
abs esabs eabs eabs2 eabs3 : ⊥ → Set
abs = λ()
esabs = λ{ ()}
eabs = λ{()}
eabs2 = λ{(())}
eabs3 = λ{((()))}
-- hidden
habs eshabs eshpabs eshpabs2 : {_ : ⊥} → Set
habs = λ{}
eshabs = λ{ {}}
eshpabs = λ{ {()}}
eshpabs2 = λ{ {(())}}
-- instance
iabs esiabs esipabs esipabs2 : {{_ : ⊥}} → Set
iabs = λ{{}}
esiabs = λ{ {{}}}
esipabs = λ{ {{()}}}
esipabs2 = λ{ {{(())}}}
|
{
"alphanum_fraction": 0.525390625,
"avg_line_length": 14.2222222222,
"ext": "agda",
"hexsha": "5287462ff6b5e7736f61a23779313fc7aa75e5a8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Succeed/Issue1484.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Succeed/Issue1484.agda",
"max_line_length": 46,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/Issue1484.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 213,
"size": 512
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Component functions of permutations found in `Data.Fin.Permutation`
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Fin.Permutation.Components where
open import Data.Bool.Base using (Bool; true; false)
open import Data.Fin.Base
open import Data.Fin.Properties
open import Data.Nat.Base as ℕ using (zero; suc; _∸_)
import Data.Nat.Properties as ℕₚ
open import Data.Product using (proj₂)
open import Function.Base using (_∘_)
open import Relation.Nullary.Reflects using (invert)
open import Relation.Nullary using (does; _because_; yes; no)
open import Relation.Nullary.Decidable using (dec-true; dec-false)
open import Relation.Binary.PropositionalEquality
open import Algebra.Definitions using (Involutive)
open ≡-Reasoning
--------------------------------------------------------------------------------
-- Functions
--------------------------------------------------------------------------------
-- 'tranpose i j' swaps the places of 'i' and 'j'.
transpose : ∀ {n} → Fin n → Fin n → Fin n → Fin n
transpose i j k with does (k ≟ i)
... | true = j
... | false with does (k ≟ j)
... | true = i
... | false = k
-- reverse i = n ∸ 1 ∸ i
reverse : ∀ {n} → Fin n → Fin n
reverse {suc n} i = inject≤ (n ℕ- i) (ℕₚ.m∸n≤m (suc n) (toℕ i))
--------------------------------------------------------------------------------
-- Properties
--------------------------------------------------------------------------------
transpose-inverse : ∀ {n} (i j : Fin n) {k} →
transpose i j (transpose j i k) ≡ k
transpose-inverse i j {k} with k ≟ j
... | true because [k≡j] rewrite dec-true (i ≟ i) refl = sym (invert [k≡j])
... | false because [k≢j] with k ≟ i
... | true because [k≡i]
rewrite dec-false (j ≟ i) (invert [k≢j] ∘ trans (invert [k≡i]) ∘ sym)
| dec-true (j ≟ j) refl
= sym (invert [k≡i])
... | false because [k≢i] rewrite dec-false (k ≟ i) (invert [k≢i])
| dec-false (k ≟ j) (invert [k≢j]) = refl
reverse-prop : ∀ {n} → (i : Fin n) → toℕ (reverse i) ≡ n ∸ suc (toℕ i)
reverse-prop {suc n} i = begin
toℕ (inject≤ (n ℕ- i) _) ≡⟨ toℕ-inject≤ _ (ℕₚ.m∸n≤m (suc n) (toℕ i)) ⟩
toℕ (n ℕ- i) ≡⟨ toℕ‿ℕ- n i ⟩
n ∸ toℕ i ∎
reverse-involutive : ∀ {n} → Involutive _≡_ (reverse {n})
reverse-involutive {suc n} i = toℕ-injective (begin
toℕ (reverse (reverse i)) ≡⟨ reverse-prop (reverse i) ⟩
n ∸ (toℕ (reverse i)) ≡⟨ cong (n ∸_) (reverse-prop i) ⟩
n ∸ (n ∸ (toℕ i)) ≡⟨ ℕₚ.m∸[m∸n]≡n (ℕₚ.≤-pred (toℕ<n i)) ⟩
toℕ i ∎)
reverse-suc : ∀ {n} {i : Fin n} → toℕ (reverse (suc i)) ≡ toℕ (reverse i)
reverse-suc {n} {i} = begin
toℕ (reverse (suc i)) ≡⟨ reverse-prop (suc i) ⟩
suc n ∸ suc (toℕ (suc i)) ≡⟨⟩
n ∸ toℕ (suc i) ≡⟨⟩
n ∸ suc (toℕ i) ≡⟨ sym (reverse-prop i) ⟩
toℕ (reverse i) ∎
|
{
"alphanum_fraction": 0.4831059129,
"avg_line_length": 38.9620253165,
"ext": "agda",
"hexsha": "8123392c8c886bab3af93cb7985ab5d0eb4dd0b1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Fin/Permutation/Components.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Fin/Permutation/Components.agda",
"max_line_length": 80,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Fin/Permutation/Components.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": 1018,
"size": 3078
}
|
open import Common.Prelude
instance
tti : ⊤
tti = record{}
NonZero : Nat → Set
NonZero zero = ⊥
NonZero (suc _) = ⊤
pred′ : (n : Nat) .{{_ : NonZero n}} → Nat
pred′ zero {{}}
pred′ (suc n) = n
test : (n : Nat) {{x y : NonZero n}} → Nat
test n = pred′ n
_<_ : Nat → Nat → Set
m < zero = ⊥
zero < suc n = ⊤
suc m < suc n = m < n
instance
<-suc : ∀ {m n} → .(m < n) → m < suc n
<-suc {zero} _ = tt
<-suc {suc m} {zero} ()
<-suc {suc m} {suc n} = <-suc {m} {n}
|
{
"alphanum_fraction": 0.4947807933,
"avg_line_length": 16.5172413793,
"ext": "agda",
"hexsha": "e38d9250a1cab9b5ca4bb39b62a2c9cf6b661121",
"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": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/IrrelevantInstance.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"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": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/IrrelevantInstance.agda",
"max_line_length": 42,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/IrrelevantInstance.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": 213,
"size": 479
}
|
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
test : (x : Nat) (f : {n : Nat} → Nat) → f {0} ≡ x → Nat
test x f p = {!p!}
|
{
"alphanum_fraction": 0.5928571429,
"avg_line_length": 23.3333333333,
"ext": "agda",
"hexsha": "d68f2b80d20839043a57e7e11b5cf20714a67d9c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue1996.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue1996.agda",
"max_line_length": 56,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue1996.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": 56,
"size": 140
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Abelian.Definition
open import Groups.Definition
open import Groups.Lemmas
open import Rings.Definition
open import Setoids.Setoids
open import Sets.EquivalenceRelations
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.EuclideanAlgorithm
open import Numbers.Primes.PrimeNumbers
module Rings.Lemmas {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} (R : Ring S _+_ _*_) where
abstract
open Setoid S
open Ring R
open Group additiveGroup
ringMinusExtracts : {x y : A} → (x * Group.inverse (Ring.additiveGroup R) y) ∼ (Group.inverse (Ring.additiveGroup R) (x * y))
ringMinusExtracts {x = x} {y} = transferToRight' additiveGroup (transitive (symmetric *DistributesOver+) (transitive (*WellDefined reflexive invLeft) (Ring.timesZero R)))
where
open Equivalence eq
ringMinusExtracts' : {x y : A} → ((inverse x) * y) ∼ inverse (x * y)
ringMinusExtracts' {x = x} {y} = transitive *Commutative (transitive ringMinusExtracts (inverseWellDefined additiveGroup *Commutative))
where
open Equivalence eq
twoNegativesTimes : {a b : A} → (inverse a) * (inverse b) ∼ a * b
twoNegativesTimes {a} {b} = transitive (ringMinusExtracts) (transitive (inverseWellDefined additiveGroup ringMinusExtracts') (invTwice additiveGroup (a * b)))
where
open Equivalence eq
groupLemmaMove0G : {a b : _} → {A : Set a} → {_·_ : A → A → A} → {S : Setoid {a} {b} A} → (G : Group S _·_) → {x : A} → (Setoid._∼_ S (Group.0G G) (Group.inverse G x)) → Setoid._∼_ S x (Group.0G G)
groupLemmaMove0G {S = S} G {x} pr = transitive (symmetric (invInv G)) (transitive (symmetric p) (invIdent G))
where
open Equivalence (Setoid.eq S)
p : Setoid._∼_ S (Group.inverse G (Group.0G G)) (Group.inverse G (Group.inverse G x))
p = inverseWellDefined G pr
groupLemmaMove0G' : {a b : _} → {A : Set a} → {_·_ : A → A → A} → {S : Setoid {a} {b} A} → (G : Group S _·_) → {x : A} → Setoid._∼_ S x (Group.0G G) → (Setoid._∼_ S (Group.0G G) (Group.inverse G x))
groupLemmaMove0G' {S = S} G {x} pr = transferToRight' G (Equivalence.transitive (Setoid.eq S) (Group.identLeft G) pr)
oneZeroImpliesAllZero : 0R ∼ 1R → {x : A} → x ∼ 0R
oneZeroImpliesAllZero 0=1 = Equivalence.transitive eq (Equivalence.symmetric eq identIsIdent) (Equivalence.transitive eq (*WellDefined (Equivalence.symmetric eq 0=1) (Equivalence.reflexive eq)) (Equivalence.transitive eq *Commutative timesZero))
lemm3 : (a b : A) → 0G ∼ (a + b) → 0G ∼ a → 0G ∼ b
lemm3 a b pr1 pr2 with transferToRight' additiveGroup (Equivalence.symmetric eq pr1)
... | a=-b with Equivalence.transitive eq pr2 a=-b
... | 0=-b with inverseWellDefined additiveGroup 0=-b
... | -0=--b = Equivalence.transitive eq (Equivalence.symmetric eq (invIdent additiveGroup)) (Equivalence.transitive eq -0=--b (invTwice additiveGroup b))
charNot2ImpliesNontrivial : ((1R + 1R) ∼ 0R → False) → (0R ∼ 1R) → False
charNot2ImpliesNontrivial charNot2 0=1 = charNot2 (Equivalence.transitive eq (+WellDefined (Equivalence.symmetric eq 0=1) (Equivalence.symmetric eq 0=1)) identRight)
abelianUnderlyingGroup : AbelianGroup additiveGroup
abelianUnderlyingGroup = record { commutative = groupIsAbelian }
|
{
"alphanum_fraction": 0.6910569106,
"avg_line_length": 54.4426229508,
"ext": "agda",
"hexsha": "c868a83494b00834c25ccf00b12b283f1e839180",
"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/Lemmas.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/Lemmas.agda",
"max_line_length": 247,
"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/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 1122,
"size": 3321
}
|
{-# OPTIONS --without-K --safe --overlapping-instances #-}
-- Reference to check out
--
-- Simply Typed Lambda Calculus in Agda, without Shortcuts
-- https://gergo.erdi.hu/blog/2013-05-01-simply_typed_lambda_calculus_in_agda,_without_shortcuts/
module InterpreterWithConstants where
open import Data.Char hiding (_≤_)
open import Data.Bool hiding (_≤_)
open import Data.Nat hiding (_≤_)
open import Data.Unit
import Data.Nat as N
open import Data.Product
open import Data.Sum
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
import Data.String as Str
open import Data.Nat.Show
import Data.List as List
open import Data.Empty
infix 3 _:::_,_
infix 2 _∈_
infix 2 _∉_
infix 1 _⊢_
data `Set : Set where
`Bool : `Set
_`⇨_ : `Set → `Set → `Set
`⊤ : `Set
_`×_ : `Set → `Set → `Set
infixr 2 _`⇨_
data Var : Set where
x' : Var
y' : Var
z' : Var
-- Inequality proofs on variables
data _≠_ : Var → Var → Set where
x≠y : x' ≠ y'
x≠z : x' ≠ z'
y≠x : y' ≠ x'
y≠z : y' ≠ z'
z≠x : z' ≠ x'
z≠y : z' ≠ y'
instance
xy : x' ≠ y'
xy = x≠y
xz : x' ≠ z'
xz = x≠z
yx : y' ≠ x'
yx = y≠x
yz : y' ≠ z'
yz = y≠z
zx : z' ≠ x'
zx = z≠x
zy : z' ≠ y'
zy = z≠y
⟦_⟧ : `Set → Set
⟦ `Bool ⟧ = Bool
⟦ (t `⇨ s) ⟧ = ⟦ t ⟧ → ⟦ s ⟧
⟦ `⊤ ⟧ = ⊤
⟦ (t `× s) ⟧ = ⟦ t ⟧ × ⟦ s ⟧
data Γ : Set where
· : Γ
_:::_,_ : Var → `Set → Γ → Γ
data _∈_ : Var → Γ → Set where
H : ∀ {x Δ t } → x ∈ x ::: t , Δ
TH : ∀ {x y Δ t} → ⦃ prf : x ∈ Δ ⦄ → ⦃ neprf : x ≠ y ⦄ → x ∈ y ::: t , Δ
instance
∈_type₁ : ∀ {x Δ t} → x ∈ x ::: t , Δ
∈_type₁ = H
∈_type₂ : ∀ {x y Δ t} → ⦃ prf : x ∈ Δ ⦄ → ⦃ x ≠ y ⦄ → x ∈ y ::: t , Δ
∈_type₂ = TH
data _∉_ : Var → Γ → Set where
H : ∀ {x} → x ∉ ·
TH : ∀ {x y Δ t} → ⦃ prf : x ∉ Δ ⦄ → ⦃ neprf : x ≠ y ⦄ → x ∉ y ::: t , Δ
instance
∉_type₁ : ∀ {x} → x ∉ ·
∉_type₁ = H
∉_type₂ : ∀ {x y Δ t} → ⦃ prf : x ∉ Δ ⦄ → ⦃ x ≠ y ⦄ → x ∉ y ::: t , Δ
∉_type₂ = TH
!Γ_[_] : ∀ {x} → (Δ : Γ) → x ∈ Δ → `Set
!Γ_[_] · ()
!Γ _ ::: t , Δ [ H ] = t
!Γ _ ::: _ , Δ [ TH ⦃ prf = i ⦄ ] = !Γ Δ [ i ]
infix 30 `v_
infix 30 `c_
infix 24 _`,_
infixl 22 _`₋_
data Constant : `Set → Set where
`not : Constant (`Bool `⇨ `Bool)
`∧ : Constant (`Bool `× `Bool `⇨ `Bool)
`∨ : Constant (`Bool `× `Bool `⇨ `Bool)
`xor : Constant (`Bool `× `Bool `⇨ `Bool)
data _⊢_ : Γ → `Set → Set where
`false : ∀ {Δ} → Δ ⊢ `Bool
`true : ∀ {Δ} → Δ ⊢ `Bool
`v_ : ∀ {Δ} → (x : Var) → ⦃ i : x ∈ Δ ⦄ → Δ ⊢ !Γ Δ [ i ]
`c_ : ∀ {Δ t} → Constant t → Δ ⊢ t
_`₋_ : ∀ {Δ t s} → Δ ⊢ t `⇨ s → Δ ⊢ t → Δ ⊢ s --application
`λ_`:_⇨_ : ∀ {Δ tr} → (x : Var) → (tx : `Set)
→ x ::: tx , Δ ⊢ tr → Δ ⊢ tx `⇨ tr
_`,_ : ∀ {Δ t s} → Δ ⊢ t → Δ ⊢ s → Δ ⊢ t `× s
`fst : ∀ {Δ t s} → Δ ⊢ t `× s → Δ ⊢ t
`snd : ∀ {Δ t s} → Δ ⊢ t `× s → Δ ⊢ s
`tt : ∀ {Δ} → Δ ⊢ `⊤
data ⟨_⟩ : Γ → Set₁ where
[] : ⟨ · ⟩
_∷_ : ∀ {x t Δ} → ⟦ t ⟧ → ⟨ Δ ⟩ → ⟨ x ::: t , Δ ⟩
!_[_] : ∀ {x Δ} → ⟨ Δ ⟩ → (i : x ∈ Δ) → ⟦ !Γ Δ [ i ] ⟧
!_[_] [] ()
!_[_] (val ∷ env) H = val
!_[_] (val ∷ env) (TH ⦃ prf = i ⦄) = ! env [ i ]
interpretConstant : ∀ {t} → Constant t → ⟦ t ⟧
interpretConstant `not = not
interpretConstant `∧ = uncurry _∧_
interpretConstant `∨ = uncurry _∨_
interpretConstant `xor = uncurry _xor_
interpret : ∀ {t} → · ⊢ t → ⟦ t ⟧
interpret = interpret' []
where interpret' : ∀ {Δ t} → ⟨ Δ ⟩ → Δ ⊢ t → ⟦ t ⟧
interpret' env `true = true
interpret' env `false = false
interpret' env `tt = tt
interpret' env ((`v x) ⦃ i = idx ⦄) = ! env [ idx ]
interpret' env (f `₋ x) = (interpret' env f) (interpret' env x)
interpret' env (`λ _ `: tx ⇨ body) = λ (x : ⟦ tx ⟧) → interpret' (x ∷ env) body
interpret' env (`c f) = interpretConstant f
interpret' env (f `, s) = interpret' env f ,′ interpret' env s
interpret' env (`fst p) with interpret' env p
interpret' env (`fst p) | f , s = f
interpret' env (`snd p) with interpret' env p
interpret' env (`snd p) | f , s = s
-----
and₁ : · ⊢ `Bool `× `Bool `⇨ `Bool
and₁ = `λ x' `: `Bool `× `Bool ⇨ `c `∧ `₋ `v x'
and₂ : · ⊢ `Bool `× `Bool `⇨ `Bool
and₂ = `c `∧
{-
I want to write a function called eta-reduce that one could prove the following:
pf : eta-reduce and₁ ≡ and₂
pf = refl
This function will eta-reduce when it can, and do nothing when it can't.
For instance the following should be true:
eta-reduce-constant : ∀ {c} → eta-reduce (`c c) ≡ `c c
However, I get stuck even on this case. Uncomment the definition below and try to
type check this module:
-}
-- eta-reduce : ∀ {t₁ t₂} → · ⊢ t₁ `⇨ t₂ → · ⊢ t₁ `⇨ t₂
-- eta-reduce (`c c) = ?
{-
You will get the following error message:
I'm not sure if there should be a case for the constructor `v_,
because I get stuck when trying to solve the following unification
problems (inferred index ≟ expected index):
Δ ≟ ·
!Γ Δ [ i ] ≟ t₁ `⇨ t₂
when checking the definition of eta-reduce
I did a bit of searching on the Internet and the only source I could find
that I could understand was this one: https://doisinkidney.com/posts/2018-09-20-agda-tips.html
It seems to be suggesting that one of the indices for a type is not in constructor form but is,
rather, a function.
Looking at the definition of _⊢_ we see that the `v_` constructor is most likely at fault:
`v_ : ∀ {Δ} → (x : Var) → ⦃ i : x ∈ Δ ⦄ → Δ ⊢ !Γ Δ [ i ]
The result type is `Δ ⊢ !Γ Δ [ i ]`. Clearly the index `!Γ Δ [ i ]` is referring to a
user-defined function.
My question is, "how can I fix this?". How would I modify the _⊢_ data structure
- I would be open to an alternative interpreter for the Simply Typed Lambda Calculus
- This interpreter is a modified form of this code base. ttps://github.com/ahmadsalim/well-typed-agda-interpreter
It has had instance declarations added and the syntactic form of terms has changed a little. I pulled out
the constant functions into their own data structure called `Constant` and changed their types a little to work
on products (_×_) instead of a curried form.
-}
{-
The instance based searching for _∈_ proofs might be a problem. I'm uncomfortable
with the use of --overlapping-instances
-}
-- eta-reduce : ∀ {t₁ t₂} → · ⊢ t₁ `⇨ t₂ → · ⊢ t₁ `⇨ t₂
-- eta-reduce (`λ x `: _ ⇨ f `₋ y) = {!!}
-- eta-reduce t = t
|
{
"alphanum_fraction": 0.5265941372,
"avg_line_length": 26.2619047619,
"ext": "agda",
"hexsha": "18601ac944ba24cd8cd923ef865baa7050a8cf84",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-06-18T12:31:11.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-18T06:14:18.000Z",
"max_forks_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sseefried/well-typed-agda-interpreter",
"max_forks_repo_path": "InterpreterWithConstants.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c",
"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": "sseefried/well-typed-agda-interpreter",
"max_issues_repo_path": "InterpreterWithConstants.agda",
"max_line_length": 113,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "sseefried/well-typed-agda-interpreter",
"max_stars_repo_path": "InterpreterWithConstants.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-18T12:37:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-18T12:06:14.000Z",
"num_tokens": 2605,
"size": 6618
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT hiding (left; right)
import homotopy.WedgeExtension as WedgeExt
module homotopy.blakersmassey.CoherenceData {i j k}
{A : Type i} {B : Type j} (Q : A → B → Type k)
m (f-conn : ∀ a → is-connected (S m) (Σ B (λ b → Q a b)))
n (g-conn : ∀ b → is-connected (S n) (Σ A (λ a → Q a b)))
where
open import homotopy.blakersmassey.Pushout Q
{- goal :
Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r)
≃ Trunc (m +2+ n) (hfiber bmglue r)
-}
private
swap-level :
(m +2+ n) -Type (lmax i (lmax j k))
→ (n +2+ m) -Type (lmax i (lmax j k))
swap-level (X , level) = X , new-level where
abstract new-level = transport (λ o → has-level o X) (+2+-comm m n) level
α₁=α₁α₂⁻¹α₂ : ∀ {p₁ p₂ p₃ : BMPushout} (α₁ : p₁ == p₂) (α₂ : p₃ == p₂)
→ α₁ == α₁ ∙' ! α₂ ∙' α₂
α₁=α₁α₂⁻¹α₂ _ idp = idp
α₁=α₂α₂⁻¹α₁ : ∀ {p₁ p₂ p₃ : BMPushout} (α₁ : p₁ == p₂) (α₂ : p₁ == p₃)
→ α₁ == α₂ ∙' ! α₂ ∙' α₁
α₁=α₂α₂⁻¹α₁ idp α₂ = ! (!-inv'-r α₂)
private
path-lemma₁ : ∀ {a₀ a₁ b} (q₀ : Q a₀ b) (q₁ : Q a₁ b)
→ bmglue q₀ == bmglue q₀ ∙' ! (bmglue q₁) ∙' bmglue q₁
path-lemma₁ q₀ q₁ = α₁=α₁α₂⁻¹α₂ (bmglue q₀) (bmglue q₁)
path-lemma₂ : ∀ {a b₀ b₁} (q₀ : Q a b₀) (q₁ : Q a b₁)
→ bmglue q₀ == bmglue q₁ ∙' ! (bmglue q₁) ∙' bmglue q₀
path-lemma₂ q₀ q₁ = α₁=α₂α₂⁻¹α₁ (bmglue q₀) (bmglue q₁)
abstract
path-coherence : ∀ {a b} (q : Q a b)
→ path-lemma₁ q q == path-lemma₂ q q
path-coherence q = lemma (bmglue q) where
lemma : ∀ {p₀ p₁ : BMPushout} (path : p₀ == p₁)
→ α₁=α₁α₂⁻¹α₂ path path == α₁=α₂α₂⁻¹α₁ path path
lemma idp = idp
module To {a₁ b₀} (q₁₀ : Q a₁ b₀) where
U = Σ A λ a → Q a b₀
u₀ : U
u₀ = (a₁ , q₁₀)
V = Σ B λ b → Q a₁ b
v₀ : V
v₀ = (b₀ , q₁₀)
P : U → V → Type (lmax i (lmax j k))
P u v = (r : bmleft (fst u) == bmright (fst v))
→ bmglue (snd u) ∙' ! (bmglue q₁₀) ∙' bmglue (snd v) == r
→ Trunc (m +2+ n) (hfiber bmglue r)
template : ∀ (u : U) (v : V)
→ (r : bmleft (fst u) == bmright (fst v))
→ (shift : bmglue (snd u) ∙' ! (bmglue q₁₀) ∙' bmglue (snd v) == r)
→ ∀ q₀₁ → bmglue q₀₁ == bmglue (snd u) ∙' ! (bmglue q₁₀) ∙' bmglue (snd v)
→ Trunc (m +2+ n) (hfiber bmglue r)
template u v r shift q₀₁ path = [ q₀₁ , path ∙' shift ]
f = λ u r shift → template u v₀ r shift (snd u) (path-lemma₁ (snd u) q₁₀)
g = λ v r shift → template u₀ v r shift (snd v) (path-lemma₂ (snd v) q₁₀)
p' = λ r shift → ap (template u₀ v₀ r shift q₁₀) (path-coherence q₁₀)
p = λ= λ r → λ= λ shift → p' r shift
args : WedgeExt.args {A = U} {a₀ = u₀} {B = V} {b₀ = v₀}
args = record {
n = n; m = m;
cA = g-conn b₀;
cB = f-conn a₁;
P = λ u v → swap-level $ P u v , Π-level λ _ → Π-level λ _ → Trunc-level;
f = f; g = g; p = p}
ext : ∀ u v → P u v
ext = WedgeExt.ext args
β-l : ∀ u r shift → ext u v₀ r shift == f u r shift
β-l u r shift = app= (app= (WedgeExt.β-l u) r) shift
β-r : ∀ v r shift → ext u₀ v r shift == g v r shift
β-r v r shift = app= (app= (WedgeExt.β-r v) r) shift
abstract
coh : ∀ r shift → ! (β-l u₀ r shift) ∙ β-r v₀ r shift == p' r shift
coh r shift =
! (β-l u₀ r shift) ∙ β-r v₀ r shift
=⟨ ap (_∙ β-r v₀ r shift) (!-ap (_$ shift) (app= (WedgeExt.β-l u₀) r))
∙ ∙-ap (_$ shift)
(! (app= (WedgeExt.β-l {r = args} u₀) r))
(app= (WedgeExt.β-r {r = args} v₀) r)
∙ ap (λ p → app= p shift)
( ap (_∙ app= (WedgeExt.β-r {r = args} v₀) r)
(!-ap (_$ r) (WedgeExt.β-l {r = args} u₀))
∙ ∙-ap (_$ r)
(! (WedgeExt.β-l {r = args} u₀))
(WedgeExt.β-r {r = args} v₀)) ⟩
app= (app= (! (WedgeExt.β-l {r = args} u₀) ∙ WedgeExt.β-r {r = args} v₀) r) shift
=⟨ ap (λ p → app= (app= p r) shift) (WedgeExt.coh {r = args}) ⟩
app= (app= (λ= λ r → λ= λ shift → p' r shift) r) shift
=⟨ ap (λ p → app= p shift) (app=-β (λ r → λ= λ shift → p' r shift) r)
∙ app=-β (λ shift → p' r shift) shift ⟩
p' r shift
=∎
to' : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁)
→ (r : bmleft a₀ == bmright b₁)
→ hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r
→ Trunc (m +2+ n) (hfiber bmglue r)
to' q₀₀ q₁₁ r (q₁₀ , shift) = To.ext q₁₀ (_ , q₀₀) (_ , q₁₁) r shift
to : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁)
→ (r : bmleft a₀ == bmright b₁)
→ Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r)
→ Trunc (m +2+ n) (hfiber bmglue r)
to q₀₀ q₁₁ r = Trunc-rec (to' q₀₀ q₁₁ r)
module From {a₀ b₁} (q₀₁ : Q a₀ b₁) where
U = Σ A λ a → Q a b₁
u₀ : U
u₀ = (a₀ , q₀₁)
V = Σ B λ b → Q a₀ b
v₀ : V
v₀ = (b₁ , q₀₁)
P : U → V → Type (lmax i (lmax j k))
P u v = (r : bmleft a₀ == bmright b₁)
→ bmglue q₀₁ == r
→ Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue (snd v) ∙' ! (bmglue q₁₀) ∙' bmglue (snd u)) r)
template : ∀ (u : U) (v : V)
→ (r : bmleft a₀ == bmright b₁)
→ (shift : bmglue q₀₁ == r)
→ ∀ q₁₀ → bmglue q₀₁ == bmglue (snd v) ∙' ! (bmglue q₁₀) ∙' bmglue (snd u)
→ Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue (snd v) ∙' ! (bmglue q₁₀) ∙' bmglue (snd u)) r)
template u v r shift q₁₀ path = [ q₁₀ , ! path ∙' shift ]
f = λ u r shift → template u v₀ r shift (snd u) (path-lemma₁ q₀₁ (snd u))
g = λ v r shift → template u₀ v r shift (snd v) (path-lemma₂ q₀₁ (snd v))
p' = λ r shift → ap (template u₀ v₀ r shift q₀₁) (path-coherence q₀₁)
p = λ= λ r → λ= λ shift → p' r shift
args : WedgeExt.args {A = U} {a₀ = u₀} {B = V} {b₀ = v₀}
args = record {
n = n; m = m;
cA = g-conn b₁;
cB = f-conn a₀;
P = λ u v → swap-level $ P u v , Π-level λ _ → Π-level λ _ → Trunc-level;
f = f; g = g; p = p}
ext : ∀ u v → P u v
ext = WedgeExt.ext args
β-l : ∀ u r shift → ext u v₀ r shift == f u r shift
β-l u r shift = app= (app= (WedgeExt.β-l u) r) shift
β-r : ∀ v r shift → ext u₀ v r shift == g v r shift
β-r v r shift = app= (app= (WedgeExt.β-r v) r) shift
abstract
coh : ∀ r shift → ! (β-l u₀ r shift) ∙ β-r v₀ r shift == p' r shift
coh r shift =
! (β-l u₀ r shift) ∙ β-r v₀ r shift
=⟨ ap (_∙ β-r v₀ r shift) (!-ap (_$ shift) (app= β-l' r))
∙ ∙-ap (_$ shift) (! (app= β-l' r)) (app= β-r' r)
∙ ap (λ p → app= p shift)
( ap (_∙ app= β-r' r) (!-ap (_$ r) β-l')
∙ ∙-ap (_$ r) (! β-l') β-r') ⟩
app= (app= (! β-l' ∙ β-r') r) shift
=⟨ ap (λ p → app= (app= p r) shift) (WedgeExt.coh {r = args}) ⟩
app= (app= (λ= λ r → λ= λ shift → p' r shift) r) shift
=⟨ ap (λ p → app= p shift) (app=-β (λ r → λ= λ shift → p' r shift) r)
∙ app=-β (λ shift → p' r shift) shift ⟩
p' r shift
=∎
where β-l' = WedgeExt.β-l {r = args} u₀
β-r' = WedgeExt.β-r {r = args} v₀
from' : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁)
→ (r : bmleft a₀ == bmright b₁)
→ hfiber bmglue r
→ Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r)
from' q₀₀ q₁₁ r (q₀₁ , shift) = From.ext q₀₁ (_ , q₁₁) (_ , q₀₀) r shift
from : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁)
→ (r : bmleft a₀ == bmright b₁)
→ Trunc (m +2+ n) (hfiber bmglue r)
→ Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r)
from q₀₀ q₁₁ r = Trunc-rec (from' q₀₀ q₁₁ r)
-- Equivalence
{-
First step: Pack relevant rules into records.
-}
record βPair {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀)
(q₁₁ : Q a₁ b₁) (q₀₁ : Q a₀ b₁) (q₁₀ : Q a₁ b₀)
(r : bmleft a₀ == bmright b₁) : Type (lmax i (lmax j k)) where
constructor βpair
field
path : bmglue q₀₁ == bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁
to-β : ∀ shift → To.ext q₁₀ (_ , q₀₀) (_ , q₁₁) r shift
== To.template q₁₀ (_ , q₀₀) (_ , q₁₁) r shift q₀₁ path
from-β : ∀ shift → From.ext q₀₁ (_ , q₁₁) (_ , q₀₀) r shift
== From.template q₀₁ (_ , q₁₁) (_ , q₀₀) r shift q₁₀ path
βpair-bmleft : ∀ {a₀ a₁ b} (q₀ : Q a₀ b) (q₁ : Q a₁ b) r
→ βPair q₀ q₁ q₀ q₁ r
βpair-bmleft q₀ q₁ r = record
{ path = path-lemma₁ q₀ q₁
; to-β = To.β-l q₁ (_ , q₀) r
; from-β = From.β-l q₀ (_ , q₁) r
}
βpair-bmright : ∀ {a b₀ b₁} (q₀ : Q a b₀) (q₁ : Q a b₁) r
→ βPair q₀ q₁ q₁ q₀ r
βpair-bmright q₀ q₁ r = record
{ path = path-lemma₂ q₁ q₀
; to-β = To.β-r q₀ (_ , q₁) r
; from-β = From.β-r q₁ (_ , q₀) r
}
abstract
βpair= : ∀ {a₀ a₁} {b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁)
(q₀₁ : Q a₀ b₁) (q₁₀ : Q a₁ b₀) (r : bmleft a₀ == bmright b₁)
{p₁ p₂ : bmglue q₀₁ == bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁} (p= : p₁ == p₂)
{toβ₁} {toβ₂}
(toβ= : ∀ shift → toβ₁ shift ∙ ap (To.template q₁₀ (_ , q₀₀) (_ , q₁₁) r shift q₀₁) p=
== toβ₂ shift)
{fromβ₁} {fromβ₂}
(fromβ= : ∀ shift → fromβ₁ shift ∙ ap (From.template q₀₁ (_ , q₁₁) (_ , q₀₀) r shift q₁₀) p=
== fromβ₂ shift)
→ βpair p₁ toβ₁ fromβ₁ == βpair p₂ toβ₂ fromβ₂
βpair= q₀₀ q₁₁ q₀₁ q₁₀ r {p} idp toβ= fromβ= = lemma
(λ= λ shift → ! (∙-unit-r _) ∙ toβ= shift)
(λ= λ shift → ! (∙-unit-r _) ∙ fromβ= shift)
where
lemma : ∀ {toβ₁} {toβ₂} (toβ= : toβ₁ == toβ₂) {fromβ₁} {fromβ₂} (fromβ= : fromβ₁ == fromβ₂)
→ βpair p toβ₁ fromβ₁ == βpair p toβ₂ fromβ₂
lemma idp idp = idp
abstract
βpair-glue : ∀ {a} {b} (q : Q a b) r
→ βpair-bmleft q q r == βpair-bmright q q r
βpair-glue q r = βpair= q q q q r
(path-coherence q)
(λ shift →
To.β-l q (_ , q) r shift ∙ To.p' q r shift
=⟨ ! $ ap (To.β-l q (_ , q) r shift ∙_) (To.coh q r shift) ⟩
To.β-l q (_ , q) r shift ∙ ! (To.β-l q (_ , q) r shift) ∙ To.β-r q (_ , q) r shift
=⟨ ! (∙-assoc (To.β-l q (_ , q) r shift) (! (To.β-l q (_ , q) r shift)) (To.β-r q (_ , q) r shift))
∙ ap (_∙ To.β-r q (_ , q) r shift) (!-inv-r (To.β-l q (_ , q) r shift)) ⟩
To.β-r q (_ , q) r shift
∎)
(λ shift →
From.β-l q (_ , q) r shift ∙ From.p' q r shift
=⟨ ! $ ap (From.β-l q (_ , q) r shift ∙_) (From.coh q r shift) ⟩
From.β-l q (_ , q) r shift ∙ ! (From.β-l q (_ , q) r shift) ∙ From.β-r q (_ , q) r shift
=⟨ ! (∙-assoc (From.β-l q (_ , q) r shift) (! (From.β-l q (_ , q) r shift)) (From.β-r q (_ , q) r shift))
∙ ap (_∙ From.β-r q (_ , q) r shift) (!-inv-r (From.β-l q (_ , q) r shift)) ⟩
From.β-r q (_ , q) r shift
∎)
-- Lemmas
private
abstract
to-from-template : ∀ {a₀ a₁ b₀ b₁} {q₀₀ : Q a₀ b₀}
{q₁₁ : Q a₁ b₁} {q₀₁ : Q a₀ b₁} {q₁₀ : Q a₁ b₀} {r}
(params : βPair q₀₀ q₁₁ q₀₁ q₁₀ r) shift
→ to q₀₀ q₁₁ r (from q₀₀ q₁₁ r [ q₀₁ , shift ]) == [ q₀₁ , shift ]
to-from-template {q₀₀ = q₀₀} {q₁₁} {q₀₁} {q₁₀} {r} params shift =
to q₀₀ q₁₁ r (from q₀₀ q₁₁ r [ q₀₁ , shift ])
=⟨ ap (to q₀₀ q₁₁ r) $ from-β shift ⟩
to q₀₀ q₁₁ r [ q₁₀ , ! path ∙' shift ]
=⟨ to-β (! path ∙' shift) ⟩
[ q₀₁ , path ∙' ! path ∙' shift ]
=⟨ ap (λ p → [ q₀₁ , p ]) $ ! (∙'-assoc path (! path) shift) ∙ ap (_∙' shift) (!-inv'-r path) ∙ ∙'-unit-l shift ⟩
[ q₀₁ , shift ]
=∎
where open βPair params
module FromTo {a₁ b₀} (q₁₀ : Q a₁ b₀) where
-- upper
U = To.U q₁₀
u₀ = To.u₀ q₁₀
-- lower
V = To.V q₁₀
v₀ = To.v₀ q₁₀
P : U → V → Type (lmax i (lmax j k))
P u v = (r : bmleft (fst u) == bmright (fst v))
→ (shift : bmglue (snd u) ∙' ! (bmglue q₁₀) ∙' bmglue (snd v) == r)
→ from (snd u) (snd v) r (to (snd u) (snd v) r [ q₁₀ , shift ]) == [ q₁₀ , shift ]
abstract
template : ∀ (u : U) (v : V) r shift q₀₁
→ βPair (snd u) (snd v) q₀₁ q₁₀ r
→ from (snd u) (snd v) r (to (snd u) (snd v) r [ q₁₀ , shift ]) == [ q₁₀ , shift ]
template (_ , q₀₀) (_ , q₁₁) r shift q₀₁ params =
from q₀₀ q₁₁ r (to q₀₀ q₁₁ r [ q₁₀ , shift ])
=⟨ ap (from q₀₀ q₁₁ r) $ to-β shift ⟩
from q₀₀ q₁₁ r [ q₀₁ , path ∙' shift ]
=⟨ from-β (path ∙' shift) ⟩
[ q₁₀ , ! path ∙' path ∙' shift ]
=⟨ ap (λ p → [ q₁₀ , p ]) $ ! (∙'-assoc (! path) path shift) ∙ ap (_∙' shift) (!-inv'-l path) ∙ ∙'-unit-l shift ⟩
[ q₁₀ , shift ]
=∎
where open βPair params
f = λ u r shift → template u v₀ r shift (snd u) (βpair-bmleft (snd u) q₁₀ r)
g = λ v r shift → template u₀ v r shift (snd v) (βpair-bmright q₁₀ (snd v) r)
abstract
p : f u₀ == g v₀
p = λ= λ r → λ= λ shift → ap (template u₀ v₀ r shift q₁₀) (βpair-glue q₁₀ r)
args : WedgeExt.args {A = U} {a₀ = u₀} {B = V} {b₀ = v₀}
args = record {
n = n; m = m;
cA = g-conn b₀;
cB = f-conn a₁;
P = λ u v → swap-level $ P u v , Π-level λ _ → Π-level λ _ → =-preserves-level Trunc-level;
f = f; g = g; p = p}
abstract
ext : ∀ u v → P u v
ext = WedgeExt.ext args
abstract
from-to' : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁) r fiber
→ from q₀₀ q₁₁ r (to q₀₀ q₁₁ r [ fiber ]) == [ fiber ]
from-to' q₀₀ q₁₁ r (q₁₀ , shift) = FromTo.ext q₁₀ (_ , q₀₀) (_ , q₁₁) r shift
from-to : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁) r fiber
→ from q₀₀ q₁₁ r (to q₀₀ q₁₁ r fiber) == fiber
from-to q₀₀ q₁₁ r = Trunc-elim (from-to' q₀₀ q₁₁ r)
module ToFrom {a₀ b₁} (q₀₁ : Q a₀ b₁) where
-- upper
U = From.U q₀₁
u₀ = From.u₀ q₀₁
-- lower
V = From.V q₀₁
v₀ = From.v₀ q₀₁
P : U → V → Type (lmax i (lmax j k))
P u v = (r : bmleft a₀ == bmright b₁)
→ (shift : bmglue q₀₁ == r)
→ to (snd v) (snd u) r (from (snd v) (snd u) r [ q₀₁ , shift ]) == [ q₀₁ , shift ]
abstract
template : ∀ (u : U) (v : V) r shift q₁₀
→ βPair (snd v) (snd u) q₀₁ q₁₀ r
→ to (snd v) (snd u) r (from (snd v) (snd u) r [ q₀₁ , shift ]) == [ q₀₁ , shift ]
template (_ , q₁₁) (_ , q₀₀) r shift q₁₀ params =
to q₀₀ q₁₁ r (from q₀₀ q₁₁ r [ q₀₁ , shift ])
=⟨ ap (to q₀₀ q₁₁ r) $ from-β shift ⟩
to q₀₀ q₁₁ r [ q₁₀ , ! path ∙' shift ]
=⟨ to-β (! path ∙' shift) ⟩
[ q₀₁ , path ∙' ! path ∙' shift ]
=⟨ ap (λ p → [ q₀₁ , p ]) $ ! (∙'-assoc path (! path) shift) ∙ ap (_∙' shift) (!-inv'-r path) ∙ ∙'-unit-l shift ⟩
[ q₀₁ , shift ]
=∎
where open βPair params
f = λ u r shift → template u v₀ r shift (snd u) (βpair-bmleft q₀₁ (snd u) r)
g = λ v r shift → template u₀ v r shift (snd v) (βpair-bmright (snd v) q₀₁ r)
abstract
p : f u₀ == g v₀
p = λ= λ r → λ= λ shift → ap (template u₀ v₀ r shift q₀₁) (βpair-glue q₀₁ r)
args : WedgeExt.args {A = U} {a₀ = u₀} {B = V} {b₀ = v₀}
args = record {
n = n; m = m;
cA = g-conn b₁;
cB = f-conn a₀;
P = λ u v → swap-level $ P u v , Π-level λ _ → Π-level λ _ → =-preserves-level Trunc-level;
f = f; g = g; p = p}
abstract
ext : ∀ u v → P u v
ext = WedgeExt.ext args
abstract
to-from' : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁) r fiber
→ to q₀₀ q₁₁ r (from q₀₀ q₁₁ r [ fiber ]) == [ fiber ]
to-from' q₀₀ q₁₁ r (q₀₁ , shift) = ToFrom.ext q₀₁ (_ , q₁₁) (_ , q₀₀) r shift
to-from : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁) r fiber
→ to q₀₀ q₁₁ r (from q₀₀ q₁₁ r fiber) == fiber
to-from q₀₀ q₁₁ r = Trunc-elim (to-from' q₀₀ q₁₁ r)
eqv : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁) r
→ Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r)
≃ Trunc (m +2+ n) (hfiber bmglue r)
eqv q₀₀ q₁₁ r = equiv (to q₀₀ q₁₁ r) (from q₀₀ q₁₁ r) (to-from q₀₀ q₁₁ r) (from-to q₀₀ q₁₁ r)
|
{
"alphanum_fraction": 0.5070869199,
"avg_line_length": 37.5936739659,
"ext": "agda",
"hexsha": "6ec33cdced245afc9768b59818a77699ebeb3030",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/blakersmassey/CoherenceData.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/blakersmassey/CoherenceData.agda",
"max_line_length": 121,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/blakersmassey/CoherenceData.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7188,
"size": 15451
}
|
module examplesPaperJFP.StateDependentIO where
open import Size
open import NativeIO
open import Function
open import Agda.Primitive
open import Level using (_⊔_) renaming (suc to lsuc)
module _ {σ γ ρ} where
record IOInterfaceˢ : Set (lsuc (σ ⊔ γ ⊔ ρ )) where
field Stateˢ : Set σ
Commandˢ : Stateˢ → Set γ
Responseˢ : (s : Stateˢ) → Commandˢ s → Set ρ
nextˢ : (s : Stateˢ) → (c : Commandˢ s) → Responseˢ s c → Stateˢ
open IOInterfaceˢ public
module _ {α σ γ ρ}(i : IOInterfaceˢ {σ} {γ} {ρ} )
(let S = Stateˢ i) (let C = Commandˢ i)
(let R = Responseˢ i) (let next = nextˢ i)
where
mutual
record IOˢ (i : Size) (A : S → Set α) (s : S) : Set (lsuc (α ⊔ σ ⊔ γ ⊔ ρ )) where
coinductive
constructor delay
field forceˢ : {j : Size< i} → IOˢ′ j A s
data IOˢ′ (i : Size) (A : S → Set α) : S → Set (lsuc (α ⊔ σ ⊔ γ ⊔ ρ )) where
doˢ′ : {s : S} → (c : C s) → (f : (r : R s c) → IOˢ i A (next s c r) )
→ IOˢ′ i A s
returnˢ′ : {s : S} → (a : A s) → IOˢ′ i A s
data IOˢ+ (i : Size) (A : S → Set α ) : S → Set (lsuc (α ⊔ σ ⊔ γ ⊔ ρ )) where
doˢ′ : {s : S} → (c : C s) (f : (r : R s c) → IOˢ i A (next s c r))
→ IOˢ+ i A s
open IOˢ public
module _ {α σ γ ρ}{I : IOInterfaceˢ {σ} {γ} {ρ}}
(let S = Stateˢ I) (let C = Commandˢ I)
(let R = Responseˢ I) (let next = nextˢ I) where
returnˢ : ∀{i}{A : S → Set α} {s : S} (a : A s) → IOˢ I i A s
forceˢ (returnˢ a) = returnˢ′ a
doˢ : ∀{i}{A : S → Set α} {s : S}
(c : C s) (f : (r : R s c) → IOˢ I i A (next s c r)) → IOˢ I i A s
forceˢ (doˢ c f) = doˢ′ c f
module _ {σ γ}{I : IOInterfaceˢ {σ} {γ} {lzero}}
(let S = Stateˢ I) (let C = Commandˢ I)
(let R = Responseˢ I) (let next = nextˢ I) where
{-# NON_TERMINATING #-}
translateIOˢ : ∀{A : Set }{s : S}
→ (translateLocal : (s : S) → (c : C s) → NativeIO (R s c))
→ IOˢ I ∞ (λ s → A) s
→ NativeIO A
translateIOˢ {A} {s} translateLocal p = case (forceˢ p {_}) of
λ{ (doˢ′ {.s} c f) → (translateLocal s c) native>>= λ r →
translateIOˢ translateLocal (f r)
; (returnˢ′ a) → nativeReturn a
}
|
{
"alphanum_fraction": 0.4728553668,
"avg_line_length": 34.9710144928,
"ext": "agda",
"hexsha": "ddb6c4825b2d38dcd5bfaa2668a64c356c39da68",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/examplesPaperJFP/StateDependentIO.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "examples/examplesPaperJFP/StateDependentIO.agda",
"max_line_length": 88,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/examplesPaperJFP/StateDependentIO.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 978,
"size": 2413
}
|
module Tree where
open import Data.Vec
open import Data.Nat
data Head : Set where
H : Head
infixr 5 _⇒_
data Expr : Set where
S : Expr -- something
_⇒_ : Expr → Expr → Expr -- "->" expression
E : Head → ∀{n} → Vec Expr n → Expr -- arbitrary expression
-- the termination checker is very unhappy with this one
leftBalance : Expr → Expr
leftBalance S = S
leftBalance (e ⇒ S) = e ⇒ S
leftBalance (e ⇒ (f ⇒ g)) = leftBalance ((leftBalance (e ⇒ f)) ⇒ g)
leftBalance (e ⇒ E H []) = (e ⇒ E H [])
leftBalance (e ⇒ E H (a ∷ x)) = E H (leftBalance (leftBalance e ⇒ a) ∷ (map leftBalance x))
leftBalance (E H x) = E H (map leftBalance x)
-- leftBalance (e ⇒ E H (a ∷ x)) = E H ((leftBalance (e ⇒ a)) ∷ (map leftBalance x))
|
{
"alphanum_fraction": 0.5525672372,
"avg_line_length": 31.4615384615,
"ext": "agda",
"hexsha": "7db4abb9aaafd7bad5f39e5af3693f56b4452140",
"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": "442a0fa153c70cc8402d69738668bf853b39fc6a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "UnofficialJuliaMirror/MemoryMutate.jl-a5f39ad1-fb6e-5f16-afbb-4d8233a49418",
"max_forks_repo_path": "src/Tree.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "442a0fa153c70cc8402d69738668bf853b39fc6a",
"max_issues_repo_issues_event_max_datetime": "2019-03-04T19:02:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-03T18:44:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "UnofficialJuliaMirror/MemoryMutate.jl-a5f39ad1-fb6e-5f16-afbb-4d8233a49418",
"max_issues_repo_path": "src/Tree.agda",
"max_line_length": 91,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "442a0fa153c70cc8402d69738668bf853b39fc6a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UnofficialJuliaMirror/MemoryMutate.jl-a5f39ad1-fb6e-5f16-afbb-4d8233a49418",
"max_stars_repo_path": "src/Tree.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-29T12:37:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-03T16:33:15.000Z",
"num_tokens": 254,
"size": 818
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.NaturalTransformation.NaturalIsomorphism where
open import Level
open import Data.Product using (_×_; _,_; map; zip)
open import Function using (flip)
open import Categories.Category
open import Categories.Functor as ℱ renaming (id to idF)
import Categories.NaturalTransformation as NT
open NT hiding (id)
import Categories.Morphism as Morphism
import Categories.Morphism.Properties as Morphismₚ
import Categories.Morphism.Reasoning as MR
open import Categories.Functor.Properties
open import Relation.Binary
private
variable
o ℓ e o′ ℓ′ e′ : Level
B C D E : Category o ℓ e
record NaturalIsomorphism {C : Category o ℓ e}
{D : Category o′ ℓ′ e′}
(F G : Functor C D) : Set (o ⊔ ℓ ⊔ ℓ′ ⊔ e′) where
private
module F = Functor F
module G = Functor G
field
F⇒G : NaturalTransformation F G
F⇐G : NaturalTransformation G F
module ⇒ = NaturalTransformation F⇒G
module ⇐ = NaturalTransformation F⇐G
field
iso : ∀ X → Morphism.Iso D (⇒.η X) (⇐.η X)
module iso X = Morphism.Iso (iso X)
open Morphism D
FX≅GX : ∀ {X} → F.F₀ X ≅ G.F₀ X
FX≅GX {X} = record
{ from = _
; to = _
; iso = iso X
}
op : NaturalIsomorphism G.op F.op
op = record
{ F⇒G = ⇒.op
; F⇐G = ⇐.op
; iso = λ X → record
{ isoˡ = iso.isoʳ X
; isoʳ = iso.isoˡ X
}
}
op′ : NaturalIsomorphism F.op G.op
op′ = record
{ F⇒G = ⇐.op
; F⇐G = ⇒.op
; iso = λ X → record
{ isoˡ = iso.isoˡ X
; isoʳ = iso.isoʳ X
}
}
-- This helper definition lets us specify only one of the commuting
-- squares and have the other one derived.
record NIHelper {C : Category o ℓ e}
{D : Category o′ ℓ′ e′}
(F G : Functor C D) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
open Functor F using (F₀; F₁)
open Functor G using () renaming (F₀ to G₀; F₁ to G₁)
open Category D
field
η : ∀ X → D [ F₀ X , G₀ X ]
η⁻¹ : ∀ X → D [ G₀ X , F₀ X ]
commute : ∀ {X Y} (f : C [ X , Y ]) → η Y ∘ F₁ f ≈ G₁ f ∘ η X
iso : ∀ X → Morphism.Iso D (η X) (η⁻¹ X)
niHelper : ∀ {F G : Functor C D} → NIHelper F G → NaturalIsomorphism F G
niHelper {D = D} {F = F} {G = G} α = record
{ F⇒G = ntHelper record { η = η ; commute = commute }
; F⇐G = ntHelper record
{ η = η⁻¹
; commute = λ {X Y} f → begin
η⁻¹ Y ∘ F₁ G f ≈˘⟨ cancelʳ (isoʳ (iso X)) ⟩
((η⁻¹ Y ∘ F₁ G f) ∘ η X) ∘ η⁻¹ X ≈˘⟨ pushʳ (commute f) ⟩∘⟨refl ⟩
(η⁻¹ Y ∘ (η Y ∘ F₁ F f)) ∘ η⁻¹ X ≈⟨ cancelˡ (isoˡ (iso Y)) ⟩∘⟨refl ⟩
F₁ F f ∘ η⁻¹ X ∎
}
; iso = iso
}
where
open Morphism.Iso
open NIHelper α
open Functor
open Category D
open HomReasoning
open MR D
open NaturalIsomorphism
infixr 9 _ⓘᵥ_ _ⓘₕ_ _ⓘˡ_ _ⓘʳ_
infix 4 _≃_
-- commonly used short-hand in CT for NaturalIsomorphism
_≃_ : (F G : Functor C D) → Set _
_≃_ = NaturalIsomorphism
_ⓘᵥ_ : {F G H : Functor C D} → G ≃ H → F ≃ G → F ≃ H
_ⓘᵥ_ {D = D} α β = record
{ F⇒G = F⇒G α ∘ᵥ F⇒G β
; F⇐G = F⇐G β ∘ᵥ F⇐G α
; iso = λ X → Iso-∘ (iso β X) (iso α X)
}
where open NaturalIsomorphism
open Morphismₚ D
_ⓘₕ_ : {H I : Functor D E} {F G : Functor C D} → H ≃ I → F ≃ G → (H ∘F F) ≃ (I ∘F G)
_ⓘₕ_ {E = E} {I = I} α β = record
{ F⇒G = F⇒G α ∘ₕ F⇒G β
; F⇐G = F⇐G α ∘ₕ F⇐G β
; iso = λ X → Iso-resp-≈ (Iso-∘ (iso α _) ([ I ]-resp-Iso (iso β X)))
E.Equiv.refl (commute (F⇐G α) (η (F⇐G β) X))
}
where open NaturalIsomorphism
open NaturalTransformation
module E = Category E
open E.Equiv
open Morphismₚ E
_ⓘˡ_ : {F G : Functor C D} → (H : Functor D E) → (η : F ≃ G) → H ∘F F ≃ H ∘F G
H ⓘˡ η = record
{ F⇒G = H ∘ˡ F⇒G η
; F⇐G = H ∘ˡ F⇐G η
; iso = λ X → [ H ]-resp-Iso (iso η X)
}
where open Functor H
_ⓘʳ_ : {F G : Functor C D} → (η : F ≃ G) → (K : Functor E C) → F ∘F K ≃ G ∘F K
η ⓘʳ K = record
{ F⇒G = F⇒G η ∘ʳ K
; F⇐G = F⇐G η ∘ʳ K
; iso = λ X → iso η (F₀ X)
}
where open Functor K
refl : Reflexive (NaturalIsomorphism {C = C} {D = D})
refl {D = D} = record
{ F⇒G = NT.id
; F⇐G = NT.id
; iso = λ _ → record
{ isoˡ = Category.identityˡ D
; isoʳ = Category.identityʳ D
}
}
sym : Symmetric (NaturalIsomorphism {C = C} {D = D})
sym {D = D} F≃G = record
{ F⇒G = F⇐G F≃G
; F⇐G = F⇒G F≃G
; iso = λ X →
let open Iso (iso F≃G X) in record
{ isoˡ = isoʳ
; isoʳ = isoˡ
}
}
where open Morphism D
trans : Transitive (NaturalIsomorphism {C = C} {D = D})
trans = flip _ⓘᵥ_
isEquivalence : {C : Category o ℓ e} {D : Category o′ ℓ′ e′} → IsEquivalence (NaturalIsomorphism {C = C} {D = D})
isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
module ≃ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} = IsEquivalence (isEquivalence {C = C} {D = D})
Functor-NI-setoid : (C : Category o ℓ e) (D : Category o′ ℓ′ e′) → Setoid _ _
Functor-NI-setoid C D = record
{ Carrier = Functor C D
; _≈_ = NaturalIsomorphism
; isEquivalence = isEquivalence
}
module LeftRightId (F : Functor C D) where
module D = Category D
iso-id-id : (X : Category.Obj C) → Morphism.Iso D {A = Functor.F₀ F X} D.id D.id
iso-id-id X = record { isoˡ = D.identityˡ ; isoʳ = D.identityʳ }
-- Left and Right and 'Central' Unitors, Natural Isomorphisms.
module _ {F : Functor C D} where
open Category.HomReasoning D
open Functor F
open LeftRightId F
open Category D
unitorˡ : ℱ.id ∘F F ≃ F
unitorˡ = record { F⇒G = id∘F⇒F ; F⇐G = F⇒id∘F ; iso = iso-id-id }
unitorʳ : F ∘F ℱ.id ≃ F
unitorʳ = record { F⇒G = F∘id⇒F ; F⇐G = F⇒F∘id ; iso = iso-id-id }
unitor² : {C : Category o ℓ e} → ℱ.id ∘F ℱ.id ≃ ℱ.id {C = C}
unitor² = record { F⇒G = id∘id⇒id ; F⇐G = id⇒id∘id ; iso = LeftRightId.iso-id-id ℱ.id }
-- associator
module _ (F : Functor B C) (G : Functor C D) (H : Functor D E) where
open Category.HomReasoning E
open Category E
open Functor
open LeftRightId (H ∘F (G ∘F F))
private
-- components of α
assocʳ : NaturalTransformation ((H ∘F G) ∘F F) (H ∘F (G ∘F F))
assocʳ = ntHelper record { η = λ _ → id ; commute = λ _ → MR.id-comm-sym E }
assocˡ : NaturalTransformation (H ∘F (G ∘F F)) ((H ∘F G) ∘F F)
assocˡ = ntHelper record { η = λ _ → id ; commute = λ _ → MR.id-comm-sym E }
associator : (H ∘F G) ∘F F ≃ H ∘F (G ∘F F)
associator = record { F⇒G = assocʳ ; F⇐G = assocˡ ; iso = iso-id-id }
|
{
"alphanum_fraction": 0.5531074305,
"avg_line_length": 27.7679324895,
"ext": "agda",
"hexsha": "8bbce78e661551632322dd60b8ce4d64173fbe76",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/NaturalTransformation/NaturalIsomorphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/NaturalTransformation/NaturalIsomorphism.agda",
"max_line_length": 118,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/NaturalTransformation/NaturalIsomorphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2796,
"size": 6581
}
|
module Point where
open import Nat
open import Bool
-- A record can be seen as a one constructor datatype. In this case:
data Point' : Set where
mkPoint : (x : Nat)(y : Nat) -> Point'
getX : Point' -> Nat
getX (mkPoint x y) = x
getY : Point' -> Nat
getY (mkPoint x y) = y
|
{
"alphanum_fraction": 0.6582733813,
"avg_line_length": 18.5333333333,
"ext": "agda",
"hexsha": "9979e6f8e9570efdc5b0599c39283e184d6fc42a",
"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": "examples/outdated-and-incorrect/Alonzo/Point.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": "examples/outdated-and-incorrect/Alonzo/Point.agda",
"max_line_length": 68,
"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": "examples/outdated-and-incorrect/Alonzo/Point.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": 85,
"size": 278
}
|
{-# OPTIONS --safe --warning=error --without-K --guardedness #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Setoids.Setoids
open import Rings.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Orders.Total.Definition
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 Groups.Definition
module Rings.Orders.Total.Bounded {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} (tRing : TotallyOrderedRing pRing) where
open import Rings.Orders.Partial.Bounded pRing
open Ring R
open Group additiveGroup
open import Groups.Lemmas (Ring.additiveGroup R)
open Setoid S
open Equivalence eq
open SetoidPartialOrder pOrder
open import Rings.Orders.Total.Lemmas tRing
open PartiallyOrderedRing pRing
boundGreaterThanZero : {s : Sequence A} → (b : Bounded s) → 0G < underlying b
boundGreaterThanZero {s} (a , b) with b 0
... | (l ,, r) = halvePositive a (<WellDefined invLeft reflexive (orderRespectsAddition (<Transitive l r) a))
|
{
"alphanum_fraction": 0.7597597598,
"avg_line_length": 40.3636363636,
"ext": "agda",
"hexsha": "a7a38ac6afbe1ff55a09722cd602d59efd448b26",
"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/Orders/Total/Bounded.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/Orders/Total/Bounded.agda",
"max_line_length": 276,
"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/Orders/Total/Bounded.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": 381,
"size": 1332
}
|
{-# OPTIONS --without-K #-}
module Ch2-2 where
open import Ch2-1
open import Level
-- Lemma 2.2.1 (ap)
ap : ∀ {a b} {A : Set a} {B : Set b} {x y : A}
→ (f : A → B)
→ (p : x ≡ y)
→ f x ≡ f y
ap {a} {b} {A} {B} {x} {y} f p = J {a} {a ⊔ b} A D d x y p f
where
-- the predicate
D : (x y : A) (p : x ≡ y) → Set (a ⊔ b)
D x y p = (f : A → B) → f x ≡ f y
-- base case
d : (x : A) → D x x refl
d x f = refl
-- ap2 : {a b c : Level} {A : Set a} {B : Set b} {C : Set c} {x y : A} {z w : B}
-- → (f : A → B → C) (p : x ≡ y) (q : z ≡ w)
-- → f x z ≡ f y w
-- ap2 {a} {b} {c} {A} {B} {C} {x} {y} {z} {w} f p q = J A D d x y p z w q f
-- where
-- -- the predicate
-- D : (x y : A) (p : x ≡ y) → Set _
-- D x y p = (a b : B) (q : z ≡ w) (f : A → B → C) → f x z ≡ f y w
--
-- -- base case
-- d : (x : A) → D x x refl
-- d x z w q f = ap (f x) q
[_]∙ : ∀ {a} {A : Set a} {x y z : A}
→ (p : x ≡ y) (q : y ≡ z)
→ x ≡ z
[ p ]∙ q = p ∙ q
∙[_] : ∀ {a} {A : Set a} {x y z : A}
→ (q : y ≡ z) (p : x ≡ y)
→ x ≡ z
∙[ p ] q = q ∙ p
-- -- -- cong₂ ::
-- [_]∙[_] : ∀ {a} {A : Set a} {x y z : A}
-- → (p q : x ≡ y) (r s : y ≡ z)
-- → p ∙ r ≡ q ∙ s
-- [_]∙[_] {a} {A} {x} {y} {z} p q r s = {! ap2 !}
ap-refl : ∀ {a b} {A : Set a} {B : Set b} {x : A}
→ (f : A → B)
→ ap {a} {b} {A} {B} {x} f refl ≡ refl
ap-refl f = refl
-- Lemma 2.2.2.i (ap respects _∙_)
ap-∙ : ∀ {a b} {A : Set a} {B : Set b} {x y z : A}
→ (f : A → B)
→ (p : x ≡ y) (q : y ≡ z)
→ ap f (p ∙ q) ≡ ap f p ∙ ap f q
ap-∙ {a} {b} {A} {B} {x} {y} {z} f p q = J A D d x y p f z q
where
-- the predicate
D : (x y : A) (p : x ≡ y) → Set _
D x y p = (f : A → B) (z : A) (q : y ≡ z) → ap f (p ∙ q) ≡ ap f p ∙ ap f q
-- base case
d : (x : A) → D x x refl
d x f z q = J A E e x z q
where
-- the predicate
E : (x z : A) (q : x ≡ z) → Set _
E x z q = ap f (refl ∙ q) ≡ ap f refl ∙ ap f q
-- base case
e : (x : A) → E x x refl
e x = refl
-- Lemma 2.2.2.ii (ap respects ¬_)
ap-¬ : ∀ {a b} {A : Set a} {B : Set b} {x y : A}
→ (f : A → B)
→ (p : x ≡ y)
→ ap f (¬ p) ≡ ¬ ap f p
ap-¬ {a} {b} {A} {B} {x} {y} f p = J A D d x y p f
where
-- the predicate
D : (x y : A) (p : x ≡ y) → Set _
D x y p = (f : A → B) → ap f (¬ p) ≡ ¬ ap f p
-- base case
d : (x : A) → D x x refl
d x f = refl
open import Function using (_∘_; id)
-- Lemma 2.2.2.iii (ap respects function compos)
ap-∘ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} {x y : A}
→ (f : A → B) (g : B → C)
→ (p : x ≡ y)
→ ap g (ap f p) ≡ ap (g ∘ f) p
ap-∘ {_} {_} {_} {A} {B} {C} {x} {y} f g p = J A D d x y p f g
where
-- the predicate
D : (x y : A) (p : x ≡ y) → Set _
D x y p = (f : A → B) → (g : B → C) → ap g (ap f p) ≡ ap (g ∘ f) p
-- base case
d : (x : A) → D x x refl
d x f g = refl
-- Lemma 2.2.2.iv (ap respects identity function)
ap-id : ∀ {a} {A : Set a} {x y : A}
→ (p : x ≡ y)
→ ap id p ≡ p
ap-id {a} {A} {x} {y} p = J A D d x y p
where
-- the predicate
D : (x y : A) (p : x ≡ y) → Set a
D x y p = ap id p ≡ p
-- base case
d : (x : A) → D x x refl
d x = refl
|
{
"alphanum_fraction": 0.3715710723,
"avg_line_length": 25.4603174603,
"ext": "agda",
"hexsha": "945f7d863d2ac709d644d44670f3674bcf73cd78",
"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": "75eea99a879e100304bd48c538c9d2db0b4a4ff3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/hott",
"max_forks_repo_path": "src/Ch2-2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75eea99a879e100304bd48c538c9d2db0b4a4ff3",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/hott",
"max_issues_repo_path": "src/Ch2-2.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75eea99a879e100304bd48c538c9d2db0b4a4ff3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/hott",
"max_stars_repo_path": "src/Ch2-2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1625,
"size": 3208
}
|
------------------------------------------------------------------------
-- Well-typed binary relations lifted to substitutions
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module Data.Fin.Substitution.TypedRelation where
open import Data.Context hiding (map)
open import Data.Context.WellFormed
open import Data.Fin using (Fin; zero)
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Fin.Substitution.Typed
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product as Prod using (_×_; _,_)
open import Data.Vec as Vec using (_∷_; map; zip; unzip)
open import Data.Vec.Properties
open import Function using (flip)
open import Level using (_⊔_) renaming (zero to lzero; suc to lsuc)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Relation.Unary using (Pred)
------------------------------------------------------------------------
-- Abstract typed binary relations lifted point-wise to substitutions
-- A shorthand.
infixr 2 _⊗_
_⊗_ : ∀ {t₁ t₂ } → Pred ℕ t₁ → Pred ℕ t₂ → Pred ℕ (t₁ ⊔ t₂)
(T₁ ⊗ T₂) n = T₁ n × T₂ n
-- Abstract typed binary relations on terms.
--
-- An abtract typed term relation _⊢_∼_∈_ : TypedRel Bnd Term₁ Term₂
-- Type is a four-place relation which, in a given Bnd-context,
-- relates Term₁ to Term₂-terms and their Type-types.
-- An abtract typing judgment _⊢_∈_ : Typing Bnd Term Type is a
-- ternary relation which, in a given Bnd-context, relates Term-terms
-- to their Type-types.
TypedRel : ∀ {t₁ t₂ t₃ t₄} →
Pred ℕ t₁ → Pred ℕ t₂ → Pred ℕ t₃ → Pred ℕ t₄ → ∀ ℓ →
Set (t₁ ⊔ t₂ ⊔ t₃ ⊔ t₄ ⊔ lsuc ℓ)
TypedRel Bnd Term₁ Term₂ Type ℓ =
∀ {n} → Ctx Bnd n → Term₁ n → Term₂ n → Type n → Set ℓ
module _ {t₁ t₂ t₃ t₄ ℓ} {Bnd : Pred ℕ t₁}
{Term₁ : Pred ℕ t₂} {Term₂ : Pred ℕ t₃} {Type : Pred ℕ t₄} where
-- The following maps witness the obvious correspondence between typed
-- relations on Term₁ and Term₂ terms and typings of Term₁-Term₂ pairs.
toTyping : TypedRel Bnd Term₁ Term₂ Type ℓ →
Typing Bnd (Term₁ ⊗ Term₂) Type ℓ
toTyping _⊢_∼_∈_ Γ = Prod.uncurry (_⊢_∼_∈_ Γ)
fromTyping : Typing Bnd (Term₁ ⊗ Term₂) Type ℓ →
TypedRel Bnd Term₁ Term₂ Type ℓ
fromTyping _⊢_∈_ Γ = Prod.curry (_⊢_∈_ Γ)
record TypedRelation {t}
(Type : Pred ℕ t) -- Type syntax
(Term : Pred ℕ lzero) -- Term syntax
ℓ
: Set (lsuc (t ⊔ ℓ)) where
infix 4 _⊢_∼_∈_ _⊢_wf
field
_⊢_wf : Wf Type Type ℓ -- Type formation judgment
_⊢_∼_∈_ : TypedRel Type Term Term Type ℓ -- Typed relation judgment
------------------------------------------------------------------------
-- Abstract typed term relations lifted point-wise to substitutions
record TypedSubRel {t}
(Type : Pred ℕ t) -- Type syntax
(Term : Pred ℕ lzero) -- Term syntax
ℓ
: Set (lsuc (t ⊔ ℓ)) where
-- The underlying typed relation
field typedRelation : TypedRelation Type Term ℓ
open TypedRelation typedRelation public
-- Weakening and term substitutions in types.
field
typeExtension : Extension Type -- type weakening
typeTermApplication : Application Type (Term ⊗ Term) -- term subst. app.
termSimple : Simple Term -- simple term subst.
open ContextFormation _⊢_wf using (_wf)
open Application typeTermApplication using (_/_)
-- We associate with every typed relation _⊢_∼_∈_ lifted to a pair
-- of Term-substitutions a single typed substitution of pairs of
-- Term-terms.
termPairSimple : Simple (Term ⊗ Term)
termPairSimple = record
{ var = Prod.< var , var >
; weaken = Prod.map weaken weaken
}
where open Simple termSimple
typedSub : TypedSub Type (Term ⊗ Term) ℓ
typedSub = record
{ _⊢_wf = _⊢_wf
; _⊢_∈_ = toTyping _⊢_∼_∈_
; typeExtension = typeExtension
; typeTermApplication = typeTermApplication
; termSimple = termPairSimple
}
open TypedSub typedSub using (_⊢_∈_; _⊢/_∈_; /∈-wf) public
infix 4 _⊢/_∼_∈_
-- Typed relations lifted to substitutions.
--
-- A typed substitution relation Δ ⊢/ σ ∼ ρ ∈ Γ is a pair σ, ρ of
-- substitutions which, when applied to related terms Γ ⊢ s ∼ t ∈ a
-- in a source context Γ, yield related well-typed terms Δ ⊢ s / σ ∼
-- t / ρ ∈ a / zip σ ρ in a well-formed target context Δ.
_⊢/_∼_∈_ : ∀ {m n} →
Ctx Type n → Sub Term m n → Sub Term m n → Ctx Type m →
Set (t ⊔ ℓ)
Δ ⊢/ σ ∼ ρ ∈ Γ = Δ ⊢/ zip σ ρ ∈ Γ
------------------------------------------------------------------------
-- Operations on abstract well-typed substitutions
-- Helpers functions for relating extensions of (untyped) zipped
-- substitutions to their projections.
module ZipUnzipExtension {Tm₁ Tm₂ : ℕ → Set}
(ext₁ : Extension Tm₁)
(ext₂ : Extension Tm₂)
where
private
module E₁ = Extension ext₁
module E₂ = Extension ext₂
-- Extensions of (untyped) Tm⊗Tm substitutions.
zippedExtension : Extension (Tm₁ ⊗ Tm₂)
zippedExtension = record { weaken = Prod.map E₁.weaken E₂.weaken }
open Extension zippedExtension
-- Some useful shorthands
π₁ : ∀ {n m} → Sub (Tm₁ ⊗ Tm₂) m n → Sub Tm₁ m n
π₁ σ = Prod.proj₁ (unzip σ)
π₂ : ∀ {n m} → Sub (Tm₁ ⊗ Tm₂) m n → Sub Tm₂ m n
π₂ σ = Prod.proj₂ (unzip σ)
-- π₁ and π₂ are projections (w.r.t. zipping)
π₁-zip : ∀ {n m} (σ : Sub Tm₁ m n) (τ : Sub Tm₂ m n) → π₁ (zip σ τ) ≡ σ
π₁-zip σ τ = cong Prod.proj₁ (unzip∘zip σ τ)
π₂-zip : ∀ {n m} (σ : Sub Tm₁ m n) (τ : Sub Tm₂ m n) → π₂ (zip σ τ) ≡ τ
π₂-zip σ τ = cong Prod.proj₂ (unzip∘zip σ τ)
-- Weakening commutes with zipping and unzipping.
map-weaken-zip : ∀ {m n} (σ : Sub Tm₁ m n) τ →
Vec.map weaken (zip σ τ) ≡
zip (Vec.map E₁.weaken σ) (Vec.map E₂.weaken τ)
map-weaken-zip σ τ = map-zip E₁.weaken E₂.weaken σ τ
map-weaken-unzip : ∀ {m n} (στ : Sub (Tm₁ ⊗ Tm₂) m n) →
(Vec.map E₁.weaken (π₁ στ) , Vec.map E₂.weaken (π₂ στ)) ≡
unzip (Vec.map weaken στ)
map-weaken-unzip στ = map-unzip E₁.weaken E₂.weaken στ
-- Extension commutes with zipping and unzipping.
/∷-zip : ∀ {m n s t} (σ : Sub Tm₁ m n) τ →
(s , t) /∷ zip σ τ ≡ zip (s E₁./∷ σ) (t E₂./∷ τ)
/∷-zip σ τ = cong (_∷_ _) (map-weaken-zip σ τ)
/∷-unzip : ∀ {m n s t} (στ : Sub (Tm₁ ⊗ Tm₂) m n) →
(s E₁./∷ π₁ στ , t E₂./∷ π₂ στ) ≡ unzip ((s , t) /∷ στ)
/∷-unzip στ = cong (Prod.map (_∷_ _) (_∷_ _)) (map-weaken-unzip στ)
-- Operations on related abstract typed substitutions that require
-- weakening of derivations of the typed relation
record TypedRelWeakenOps {t ℓ} {Type : Pred ℕ t} {Term : Pred ℕ lzero}
(typedSubRel : TypedSubRel Type Term ℓ)
: Set (lsuc (t ⊔ ℓ)) where
open TypedSubRel typedSubRel
open ContextFormation _⊢_wf using (_wf)
open Application typeTermApplication using (_/_)
-- Operations on contexts and raw terms that require weakening
private
termExtension : Extension Term
termExtension = record { weaken = Simple.weaken termSimple }
module E = Extension termExtension
module C = WeakenOps typeExtension
module P = Simple termPairSimple
field
-- Weakening preserves well-typed terms.
∼∈-weaken : ∀ {n} {Δ : Ctx Type n} {t u a b} →
Δ ⊢ a wf → Δ ⊢ t ∼ u ∈ b →
(a ∷ Δ) ⊢ E.weaken t ∼ E.weaken u ∈ C.weaken b
-- Well-typedness implies well-formedness of contexts.
∼∈-wf : ∀ {n} {Δ : Ctx Type n} {t u a} → Δ ⊢ t ∼ u ∈ a → Δ wf
-- Lemmas relating type weakening to term substitutions
/-wk : ∀ {n} {a : Type n} → a / P.wk ≡ C.weaken a
/-weaken : ∀ {m n} {στ : Sub (Term ⊗ Term) m n} a →
a / Vec.map P.weaken στ ≡ a / στ / P.wk
weaken-/-∷ : ∀ {n m} {tu} {στ : Sub (Term ⊗ Term) m n} (a : Type m) →
C.weaken a / (tu ∷ στ) ≡ a / στ
-- Operations on the underlying abstract typed substitutions that
-- require weakening.
typedWeakenOps : TypedWeakenOps typedSub
typedWeakenOps = record
{ ∈-weaken = ∼∈-weaken
; ∈-wf = ∼∈-wf
; /-wk = /-wk
; /-weaken = /-weaken
; weaken-/-∷ = weaken-/-∷
}
open TypedWeakenOps typedWeakenOps using (∈-/∷)
open ZipUnzipExtension termExtension termExtension using (/∷-zip)
-- Look up a pair of related entries in a pair of related
-- substitutions.
lookup : ∀ {m n Δ} {σ τ : Sub Term m n} {Γ} →
Δ ⊢/ σ ∼ τ ∈ Γ → (x : Fin m) →
Δ ⊢ Vec.lookup σ x ∼ Vec.lookup τ x ∈ C.lookup Γ x / zip σ τ
lookup {σ = σ} {τ} σ∼τ∈Γ x =
subst₂ (toTyping _⊢_∼_∈_ _) (lookup-zip x σ τ) refl
(TypedWeakenOps.lookup typedWeakenOps σ∼τ∈Γ x)
-- Extension by a pair of related typed terms.
∼∈-/∷ : ∀ {m n Γ} {σ τ : Sub Term m n} {Δ t u a b} →
b ∷ Δ ⊢ t ∼ u ∈ C.weaken (a / zip σ τ) → Δ ⊢/ σ ∼ τ ∈ Γ →
b ∷ Δ ⊢/ (t E./∷ σ) ∼ (u E./∷ τ) ∈ a ∷ Γ
∼∈-/∷ t∼u∈a/στ σ∼τ∈Γ =
subst (flip (_⊢/_∈_ _) _) (/∷-zip _ _) (∈-/∷ t∼u∈a/στ σ∼τ∈Γ)
-- Helpers functions for relating simple (untyped) zipped
-- substitutions to their projections.
module ZipUnzipSimple {Tm₁ Tm₂ : ℕ → Set}
(simple₁ : Simple Tm₁)
(simple₂ : Simple Tm₂)
where
private
module S₁ = SimpleExt simple₁
module S₂ = SimpleExt simple₂
open ZipUnzipExtension S₁.extension S₂.extension public
-- Simple (untyped) Tm⊗Tm substitutions.
zippedSimple : Simple (Tm₁ ⊗ Tm₂)
zippedSimple = record
{ weaken = Prod.map S₁.weaken S₂.weaken
; var = λ x → S₁.var x , S₂.var x
}
open SimpleExt zippedSimple
-- Lifting commutes with zipping.
↑-zip : ∀ {m n} (σ : Sub Tm₁ m n) τ →
zip σ τ ↑ ≡ zip (σ S₁.↑) (τ S₂.↑)
↑-zip σ τ = /∷-zip σ τ
↑⋆-zip : ∀ {m n} (σ : Sub Tm₁ m n) τ k →
zip σ τ ↑⋆ k ≡ zip (σ S₁.↑⋆ k) (τ S₂.↑⋆ k)
↑⋆-zip σ τ zero = refl
↑⋆-zip σ τ (suc k) = cong (var zero ∷_) (begin
map weaken (zip σ τ ↑⋆ k)
≡⟨ cong (map weaken) (↑⋆-zip σ τ k) ⟩ --
map weaken (zip (σ S₁.↑⋆ k) (τ S₂.↑⋆ k))
≡⟨ map-weaken-zip (σ S₁.↑⋆ k) (τ S₂.↑⋆ k) ⟩
zip (map S₁.weaken (σ S₁.↑⋆ k)) (map S₂.weaken (τ S₂.↑⋆ k))
∎)
-- Lifting commutes with unzipping.
↑-unzip : ∀ {m n} (σ : Sub (Tm₁ ⊗ Tm₂) m n) →
(π₁ σ S₁.↑ , π₂ σ S₂.↑) ≡ unzip (σ ↑)
↑-unzip σ = /∷-unzip σ
-- Zipping preserves identity substitutions.
id-zip : ∀ {n} → id {n} ≡ zip S₁.id S₂.id
id-zip {zero} = refl
id-zip {suc n} = begin
id {n} ↑ ≡⟨ cong _↑ id-zip ⟩
(zip S₁.id S₂.id) ↑ ≡⟨ ↑-zip S₁.id S₂.id ⟩
zip (S₁.id S₁.↑) (S₂.id S₂.↑) ∎
-- Unzipping preserves identity substitutions.
id-unzip : ∀ {n} → (S₁.id , S₂.id) ≡ unzip (id {n})
id-unzip {zero} = refl
id-unzip {suc n} = begin
(S₁.id S₁.↑ , S₂.id S₂.↑) ≡⟨ cong (Prod.map S₁._↑ S₂._↑) id-unzip ⟩
(π₁ id S₁.↑ , π₂ id S₂.↑) ≡⟨ ↑-unzip id ⟩
unzip (id {n} ↑) ∎
-- Zipping preserves weakening substitutions.
wk-zip : ∀ {n} → wk {n} ≡ zip S₁.wk S₂.wk
wk-zip {n} = begin
map weaken id
≡⟨ cong (map weaken) id-zip ⟩
map weaken (zip S₁.id S₂.id)
≡⟨ map-zip S₁.weaken S₂.weaken _ _ ⟩
zip (map S₁.weaken S₁.id) (map S₂.weaken S₂.id)
∎
-- Unzipping preserves weakening substitutions.
wk-unzip : ∀ {n} → (S₁.wk , S₂.wk) ≡ unzip (wk {n})
wk-unzip {n} = begin
(map S₁.weaken S₁.id , map S₂.weaken S₂.id)
≡⟨ cong (Prod.map (map S₁.weaken) (map S₂.weaken)) id-unzip ⟩
(map S₁.weaken (π₁ id) , map S₂.weaken (π₂ id))
≡⟨ map-unzip S₁.weaken S₂.weaken id ⟩
unzip (map weaken id)
∎
-- Zipping preserves sigle-variable substitutions.
sub-zip : ∀ {n} (s : Tm₁ n) t → sub (s , t) ≡ zip (S₁.sub s) (S₂.sub t)
sub-zip s t = cong (_∷_ (s , t)) id-zip
-- Unzipping preserves sigle-variable substitutions.
sub-unzip : ∀ {n} (s : Tm₁ n) t → (S₁.sub s , S₂.sub t) ≡ unzip (sub (s , t))
sub-unzip s t = cong (Prod.map (_∷_ s) (_∷_ t)) id-unzip
-- Operations on abstract typed substitutions that require simple term
-- substitutions
record TypedRelSimple {t ℓ} {Type : Pred ℕ t} {Term : Pred ℕ lzero}
(typedSubRel : TypedSubRel Type Term ℓ)
: Set (lsuc (t ⊔ ℓ)) where
-- Operations on related abstract typed substitutions that require
-- weakening.
field typedRelWeakenOps : TypedRelWeakenOps typedSubRel
open TypedRelWeakenOps typedRelWeakenOps public
open TypedSubRel typedSubRel
open ContextFormation _⊢_wf using (_wf; _⊢_wfExt)
open Application typeTermApplication using (_/_)
private
module S = Simple termSimple
module C = WeakenOps typeExtension
module P = Simple termPairSimple
open S using (_↑; _↑⋆_; id; wk; sub)
-- Context operations that require term substitutions in types.
open SubstOps typeTermApplication termPairSimple using (_E/_)
field
-- Takes equal variables to well-typed related terms.
∼∈-var : ∀ {n} {Γ : Ctx Type n} →
∀ x → Γ wf → Γ ⊢ S.var x ∼ S.var x ∈ C.lookup Γ x
-- Well-formedness of related types implies well-formedness of
-- contexts.
wf-wf : ∀ {n} {Γ : Ctx Type n} {a} → Γ ⊢ a wf → Γ wf
-- The identity substitution in types is an identity
id-vanishes : ∀ {n} (a : Type n) → a / P.id ≡ a
-- Operations on the underlying abstract typed substitutions that
-- require simple typed term substitutions.
typedSimple : TypedSimple typedSub
typedSimple = record
{ typedWeakenOps = typedWeakenOps
; ∈-var = ∼∈-var
; wf-wf = wf-wf
; id-vanishes = id-vanishes
}
open TypedSimple typedSimple using (∈-↑; ∈-↑⋆; ∈-id; ∈-wk; ∈-sub; ∈-tsub)
open ZipUnzipSimple termSimple termSimple
-- Lifting.
∼∈-↑ : ∀ {m n Δ} {σ τ : Sub Term m n} {a Γ} →
Δ ⊢ a / zip σ τ wf → Δ ⊢/ σ ∼ τ ∈ Γ →
a / zip σ τ ∷ Δ ⊢/ σ ↑ ∼ τ ↑ ∈ a ∷ Γ
∼∈-↑ a/στ-wf σ∼τΓ =
subst (flip (_⊢/_∈_ _) _) (↑-zip _ _) (∈-↑ a/στ-wf σ∼τΓ)
∼∈-↑⋆ : ∀ {k m n Δ} {E : CtxExt Type m k} {σ τ : Sub Term m n} {Γ} →
Δ ⊢ (E E/ zip σ τ) wfExt → Δ ⊢/ σ ∼ τ ∈ Γ →
(E E/ zip σ τ) ++ Δ ⊢/ σ ↑⋆ k ∼ τ ↑⋆ k ∈ (E ++ Γ)
∼∈-↑⋆ {k} E/στ-wfExt σ∼τ∈Γ =
subst (flip (_⊢/_∈_ _) _) (↑⋆-zip _ _ k) (∈-↑⋆ E/στ-wfExt σ∼τ∈Γ)
-- The identity substitution.
∼∈-id : ∀ {n} {Γ : Ctx Type n} → Γ wf → Γ ⊢/ id ∼ id ∈ Γ
∼∈-id Γ-wf = subst (flip (_⊢/_∈_ _) _) id-zip (∈-id Γ-wf)
-- Weakening.
∼∈-wk : ∀ {n} {Γ : Ctx Type n} {a} → Γ ⊢ a wf → a ∷ Γ ⊢/ wk ∼ wk ∈ Γ
∼∈-wk a-wf = subst (flip (_⊢/_∈_ _) _) wk-zip (∈-wk a-wf)
-- A substitution which only replaces the first variable.
∼∈-sub : ∀ {n} {Γ : Ctx Type n} {t u a} → Γ ⊢ t ∼ u ∈ a →
Γ ⊢/ sub t ∼ sub u ∈ a ∷ Γ
∼∈-sub s∼t∈a =
subst (flip (_⊢/_∈_ _) _) (sub-zip _ _) (∈-sub s∼t∈a)
-- A substitution which only changes the type of the first variable.
∼∈-tsub : ∀ {n} {Γ : Ctx Type n} {a b} →
b ∷ Γ ⊢ S.var zero ∼ S.var zero ∈ C.weaken a →
b ∷ Γ ⊢/ id ∼ id ∈ a ∷ Γ
∼∈-tsub z∈a = subst (flip (_⊢/_∈_ _) _) id-zip (∈-tsub z∈a)
|
{
"alphanum_fraction": 0.5577132603,
"avg_line_length": 34.0676855895,
"ext": "agda",
"hexsha": "ddefbf82cf00d59bf24ac249ed196559db3a596e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/Data/Fin/Substitution/TypedRelation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/Data/Fin/Substitution/TypedRelation.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/Data/Fin/Substitution/TypedRelation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5661,
"size": 15603
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of interleaving using propositional equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Ternary.Interleaving.Propositional.Properties
{a} {A : Set a} where
import Data.List.Relation.Ternary.Interleaving.Setoid.Properties
as SetoidProperties
open import Relation.Binary.PropositionalEquality using (setoid)
------------------------------------------------------------------------
-- Re-exporting existing properties
open SetoidProperties (setoid A) public
|
{
"alphanum_fraction": 0.5326409496,
"avg_line_length": 33.7,
"ext": "agda",
"hexsha": "1156079c25d4f61c84c4f929decbbf131b230aab",
"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/List/Relation/Ternary/Interleaving/Propositional/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/List/Relation/Ternary/Interleaving/Propositional/Properties.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Propositional/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": 112,
"size": 674
}
|
-- Andreas, 2012-07-01, issue reported by patrickATparcs.ath...
-- {-# OPTIONS -v tc.term.let.pattern:20 #-}
module Issue671 where
open import Common.Prelude
record Foo : Set where
constructor foo
field
foo₁ : Nat
bar : Nat → Nat
bar a = let
b = a
c = b
foo x = foo 5
in b
-- should succeed, used to throw a panic from Open'ing a let assigned value
-- in a wrong Context
|
{
"alphanum_fraction": 0.655,
"avg_line_length": 20,
"ext": "agda",
"hexsha": "48717aa198197eb2fb537c35b87f96f4424f6bd4",
"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/Issue671.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/Issue671.agda",
"max_line_length": 75,
"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/Issue671.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": 124,
"size": 400
}
|
-- Andreas, 2020-02-15, issue #4447, reported by zraffer
record Wrap : Set₁ where
constructor ↑
field ↓ : Set
open Wrap public
data Unit : Set
-- The type checker sees through this definition,
-- thus, the positivity checker should as well:
𝕌nit = ↑ Unit
data Unit where
unit : ↓ 𝕌nit
-- WAS: internal error in the positivity checker.
|
{
"alphanum_fraction": 0.710982659,
"avg_line_length": 19.2222222222,
"ext": "agda",
"hexsha": "91f9602840bac3ea8ac111046722d5f57ad8a783",
"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": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/Issue4447.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/Issue4447.agda",
"max_line_length": 56,
"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/Issue4447.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": 96,
"size": 346
}
|
{-# OPTIONS --without-K #-}
open import HoTT
module homotopy.OneSkeleton {i} {A : Type i} {j} {B : Type j} where
private
module _ (map : A → B) where
data #OneSkeleton-aux : Type i where
#point : A → #OneSkeleton-aux
data #OneSkeleton : Type i where
#one-skeleton : #OneSkeleton-aux → (Unit → Unit) → #OneSkeleton
OneSkeleton : (A → B) → Type i
OneSkeleton = #OneSkeleton
module _ {map : A → B} where
point : A → OneSkeleton map
point a = #one-skeleton (#point a) _
postulate -- HIT
link : ∀ a₁ a₂ → map a₁ == map a₂ → point a₁ == point a₂
module OneSkeletonElim
{l} {P : OneSkeleton map → Type l}
(point* : ∀ a → P (point a))
(link* : ∀ a₁ a₂ p → point* a₁ == point* a₂ [ P ↓ link a₁ a₂ p ]) where
f : Π (OneSkeleton map) P
f = f-aux phantom where
f-aux : Phantom link* → Π (OneSkeleton map) P
f-aux phantom (#one-skeleton (#point a) _) = point* a
postulate
link-β : ∀ a₁ a₂ p → apd f (link a₁ a₂ p) == link* a₁ a₂ p
open OneSkeletonElim public using () renaming (f to OneSkeleton-elim)
module OneSkeletonRec
{l} {P : Type l}
(point* : ∀ a → P)
(link* : ∀ a₁ a₂ p → point* a₁ == point* a₂) where
private
module M = OneSkeletonElim point*
(λ a₁ a₂ p → ↓-cst-in (link* a₁ a₂ p))
f : OneSkeleton map → P
f = M.f
link-β : ∀ a₁ a₂ p → ap f (link a₁ a₂ p) == link* a₁ a₂ p
link-β a₁ a₂ p = apd=cst-in {f = f} (M.link-β a₁ a₂ p)
open OneSkeletonRec public using () renaming (f to OneSkeleton-rec)
OneSkeleton-lift : OneSkeleton map → B
OneSkeleton-lift = OneSkeleton-rec map (λ _ _ p → p)
{-
module _ {i} {A B : Set i} where
skeleton₁ : (A → B) → Set i
skeleton₁ f = Graveyard.skeleton₁ {i} {A} {B} {f}
-}
|
{
"alphanum_fraction": 0.5601952278,
"avg_line_length": 27.1176470588,
"ext": "agda",
"hexsha": "1216901a0f97074f6668169363b1b78a13fa4488",
"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": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danbornside/HoTT-Agda",
"max_forks_repo_path": "homotopy/OneSkeleton.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"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": "danbornside/HoTT-Agda",
"max_issues_repo_path": "homotopy/OneSkeleton.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danbornside/HoTT-Agda",
"max_stars_repo_path": "homotopy/OneSkeleton.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 633,
"size": 1844
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.NaturalTransformation.Extranatural where
-- Although there is a notion of Extranatural in Categories.NaturalTransformation.Dinatural,
-- it isn't the most general form, thus the need for this as well.
open import Level
open import Data.Product
open import Relation.Binary using (Rel; IsEquivalence; Setoid)
open import Categories.Category
open import Categories.NaturalTransformation as NT hiding (_∘ʳ_)
open import Categories.Functor
open import Categories.Functor.Construction.Constant
open import Categories.Category.Product
import Categories.Morphism.Reasoning as MR
private
variable
o₁ o₂ o₃ o₄ ℓ₁ ℓ₂ ℓ₃ ℓ₄ e₁ e₂ e₃ e₄ : Level
record ExtranaturalTransformation
{A : Category o₁ ℓ₁ e₁}
{B : Category o₂ ℓ₂ e₂}
{C : Category o₃ ℓ₃ e₃}
{D : Category o₄ ℓ₄ e₄}
(P : Functor (Product A (Product (Category.op B) B)) D)
(Q : Functor (Product A (Product (Category.op C) C)) D) : Set (o₁ ⊔ o₂ ⊔ o₃ ⊔ ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃ ⊔ ℓ₄ ⊔ e₄) where
private
module A = Category A
module B = Category B
module C = Category C
module D = Category D
module P = Functor P
module Q = Functor Q
open D hiding (op)
open Commutation D
field
α : ∀ a b c → D [ P.₀ (a , (b , b)) , Q.₀ (a , (c , c)) ]
commute : ∀ {a a′ b b′ c c′} (f : A [ a , a′ ]) (g : B [ b , b′ ])
(h : C [ c , c′ ]) →
[ P.₀ (a , (b′ , b) ) ⇒ Q.₀ (a′ , (c , c′)) ]⟨
P.₁ (f , B.id , g) ⇒⟨ P.₀ (a′ , (b′ , b′)) ⟩
α a′ b′ c ⇒⟨ Q.₀ (a′ , (c , c)) ⟩
Q.₁ (A.id , C.id , h)
≈ P.₁ (A.id , g , B.id) ⇒⟨ P.₀ (a , (b , b)) ⟩
α a b c′ ⇒⟨ Q.₀ (a , (c′ , c′)) ⟩
Q.₁ (f , h , C.id)
⟩
|
{
"alphanum_fraction": 0.5350971922,
"avg_line_length": 34.9433962264,
"ext": "agda",
"hexsha": "0bff0edbec1f7053d3cd246d508e9d065a052118",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/NaturalTransformation/Extranatural.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/NaturalTransformation/Extranatural.agda",
"max_line_length": 112,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/NaturalTransformation/Extranatural.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 646,
"size": 1852
}
|
open import Data.Nat as N using (ℕ; zero; suc; _<_; _≤_; _>_; z≤n; s≤s; _∸_)
open import Data.Nat.Properties as N
open import Data.Vec as V using (Vec; []; _∷_)
open import Data.Vec.Properties as V
open import Data.Fin as F using (Fin; zero; suc)
import Data.Fin.Properties as F
open import Data.List as L using (List; []; _∷_)
open import Data.Unit using (⊤; tt)
open import Data.Nat.Properties
import Data.Nat.DivMod as N
open import Data.Bool using (Bool; true; false)
open import Data.Product renaming (_×_ to _⊗_)
open import Relation.Binary.PropositionalEquality -- using (≡-Reasoning; _≡_; refl; cong; sym; subst; subst₂) -- (Extensionality)
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Relation.Nullary.Negation
open import Function
open import Reflection
open import Level using () renaming (zero to ℓ0; suc to lsuc)
open import Array.Base
open import Array.Properties
open import Agda.Builtin.Float
data dy-args : ∀ m n → Vec ℕ m → Vec ℕ n → Set where
n-n : ∀ {n s} → dy-args n n s s
n-0 : ∀ {n s} → dy-args n 0 s []
0-n : ∀ {n s} → dy-args 0 n [] s
dy-args-dim : ∀ {m n sx sy} → dy-args m n sx sy → ℕ
dy-args-dim {m} n-n = m
dy-args-dim {m} n-0 = m
dy-args-dim {m}{n} 0-n = n
dy-args-shp : ∀ {m n sx sy} → (dy : dy-args m n sx sy) → Vec ℕ (dy-args-dim dy)
dy-args-shp {m}{n}{sx} n-n = sx
dy-args-shp {m}{n}{sx} n-0 = sx
dy-args-shp {m}{n}{sx}{sy} 0-n = sy
dy-args-ok? : Term → TC ⊤
dy-args-ok? hole = do
goal ← inferType hole
def (quote dy-args) (vArg m ∷ vArg n ∷ vArg sx ∷ vArg sy ∷ []) ← reduce goal
where _ → typeError (strErr "expected dy-args expression in goal, found:" ∷ termErr goal ∷ [])
reduce m >>= λ where
(lit (nat 0)) → unify hole (con (quote 0-n) [])
(meta id _) → blockOnMeta id
m → reduce n >>= λ where
(lit (nat 0)) → unify hole (con (quote n-0) [])
(meta id _) → blockOnMeta id
n → do
catchTC
(unify m n)
(typeError (strErr "no valid dy-args found for goal: " ∷ termErr goal ∷ []))
-- XXX we could further check that sx and sy unify as well, however, this would
-- fail later if they don't.
unify hole (con (quote n-n) [])
dy-type : ∀ a → Set a → Set a
dy-type a X = ∀ {m n sx sy} {@(tactic dy-args-ok?) args : dy-args m n sx sy}
→ Ar X m sx → Ar X n sy → Ar X _ (dy-args-shp args)
lift′ : ∀ {a}{X : Set a} → (_⊕_ : X → X → X) → dy-type a X
lift′ _⊕_ {args = n-n} (imap a) (imap b) = imap λ iv → a iv ⊕ b iv
lift′ _⊕_ {args = n-0} (imap a) (imap b) = imap λ iv → a iv ⊕ b []
lift′ _⊕_ {args = 0-n} (imap a) (imap b) = imap λ iv → a [] ⊕ b iv
Scal : ∀ {a} → Set a → Set a
Scal X = Ar X 0 []
--scal : ∀ {a}{X : Set a} → X → Scal X
--scal = cst
--unscal : ∀ {a}{X : Set a} → Scal X → X
--unscal (imap f) = f []
--module reduce-split where
-- split-thm : ∀ m n → (m N.⊓ n) N.+ (n N.∸ m) ≡ n
-- split-thm zero n = refl
-- split-thm (suc m) zero = refl
-- split-thm (suc m) (suc n) = cong suc (split-thm m n)
--
-- {-# REWRITE split-thm #-}
--
-- split : ∀ {X : Set}{n} → (m : ℕ) → (xy : Vec X n)
-- → ∃₂ λ (x : Vec X (m N.⊓ n)) (y : Vec X (n N.∸ m)) → x V.++ y ≡ xy
-- split zero xy = [] , xy , refl
-- split {n = zero} (suc m) xy = [] , xy , refl
-- split {X = X}{n = suc n} (suc m) (x ∷ xy) with split m xy
-- ... | xs , ys , refl = x ∷ xs , ys , refl
--
-- split-axis : ∀ m → (k : Fin m) → ∃₂ λ l r → l N.+ 1 N.+ r ≡ m
-- split-axis zero ()
-- split-axis (suc m) zero = 0 , m , refl
-- split-axis (suc m) (suc k) with split-axis m k
-- ... | l' , r' , refl = suc l' , r' , refl
--
--
-- split-vec : ∀ {l r}{X : Set} → (xyz : Vec X (l N.+ 1 N.+ r))
-- → Σ[ x ∈ Vec X l ] Σ[ y ∈ Vec X 1 ] Σ[ z ∈ Vec X r ] ((x V.++ y) V.++ z ≡ xyz)
-- split-vec {zero} {r} (h ∷ t) = [] , (h ∷ []) , t , refl
-- split-vec {suc l} {r} (h ∷ t) with split-vec {l = l} t
-- ... | l' , m' , r' , refl = h ∷ l' , m' , r' , refl
data SVup (X : Set) : Set → (d : ℕ) → (sh : Vec ℕ d) → Set where
instance
scal : SVup X X 0 []
vect : ∀ {n} → SVup X (Vec X n) 1 (n ∷ [])
arry : ∀ {d s} → SVup X (Ar X d s) d s
-- XXX do we need the id case for arrays themselves?
infixr 30 ▴_
▴_ : ∀ {X A d s}{{t : SVup X A d s}} → A → Ar X d s
▴_ ⦃ t = scal ⦄ a = cst a --imap λ _ → a
▴_ ⦃ t = vect ⦄ a = imap λ iv → V.lookup a $ ix-lookup iv zero --imap λ where (i ∷ []) → V.lookup a i
▴_ ⦃ t = arry ⦄ a = a
{-
data SVdown (X : Set) : (d : ℕ) → (sh : Vec ℕ d) → Set → Set where
instance
scal : SVdown X 0 [] X
vect : ∀ {n} → SVdown X 1 (n ∷ []) (Vec X n)
-- XXX do we need the id case for arrays themselves?
-}
infixr 30 ▾_
▾_ : ∀ {X A d s}{{t : SVup X A d s}} → Ar X d s → A
▾_ ⦃ t = scal ⦄ (imap a) = a []
▾_ ⦃ t = vect ⦄ (imap a) = V.tabulate λ i → a $ i ∷ []
▾_ ⦃ t = arry ⦄ a = a
-- FIXME These cases are missing
-- Ar X 1 [n] + Vec X 0
-- Ar X 1 [n] + Vec X 1
-- Ar X 1 [n] + Vec X n
-- FIXME we should allow for different types of lhs and rhs and result,
-- e.g. replicate : ℕ → Char → String (not critical, but would be nice).
-- FIXME we can add the cases when indices are added with scalars/arrays/vectors.
--
-- Simplify handling concatenation of `Prog`s and `String`s
data DyScalVec (X : Set) : Set → Set → (d : ℕ) → (sh : Vec ℕ d) → Set where
instance
s-s : DyScalVec X X X 0 []
s-v : ∀ {n} → DyScalVec X X (Vec X n) 1 (n ∷ [])
s-a : ∀ {d s} → DyScalVec X X (Ar X d s) d s
v-s : ∀ {n} → DyScalVec X (Vec X n) X 1 (n ∷ [])
v-v : ∀ {n} → DyScalVec X (Vec X n) (Vec X n) 1 (n ∷ [])
-- v-a : X (Ar X 1 (n ∷ [])) (Vec X n) 1 (n ∷ [])
a-s : ∀ {d s} → DyScalVec X (Ar X d s) X d s
-- a-v : X (Vec X n) (Ar X 1 (n ∷ [])) 1 (n ∷ [])
a-a : ∀ {m n sx sy}{@(tactic dy-args-ok?) args : dy-args m n sx sy} → DyScalVec X (Ar X m sx) (Ar X n sy) (dy-args-dim args) (dy-args-shp args)
▴ₗ : ∀ {X A B d s} {{t : DyScalVec X A B d s}} → A → Ar X d s
▴ₗ {{s-s}} a = cst a
▴ₗ {{s-v}} a = cst a
▴ₗ {{s-a}} a = cst a
▴ₗ {{v-s}} a = ▴ a
▴ₗ {{v-v}} a = ▴ a
▴ₗ {{a-s}} a = a
▴ₗ ⦃ t = a-a {args = n-n} ⦄ a = a
▴ₗ ⦃ t = a-a {args = n-0} ⦄ a = a
▴ₗ ⦃ t = a-a {args = 0-n} ⦄ a = cst (sel a [])
▴ᵣ : ∀ {X A B d s} {{t : DyScalVec X A B d s}} → B → Ar X d s
▴ᵣ {{s-s}} b = cst b
▴ᵣ {{s-v}} b = ▴ b
▴ᵣ {{s-a}} b = b
▴ᵣ {{v-s}} b = cst b
▴ᵣ {{v-v}} b = ▴ b
▴ᵣ {{a-s}} b = cst b
▴ᵣ ⦃ t = a-a {args = n-n} ⦄ b = b
▴ᵣ ⦃ t = a-a {args = n-0} ⦄ b = cst (sel b [])
▴ᵣ ⦃ t = a-a {args = 0-n} ⦄ b = b
--infixr 20 _-′_
--_-′_ = lift′ N._∸_
_-safe-_ : (a : ℕ) → (b : ℕ) .{≥ : a N.≥ b} → ℕ
a -safe- b = a N.∸ b
{-
infixr 20 _-ₙ_
_-ₙ_ : ∀ {n}{s}
→ (a : Ar ℕ n s) → (b : Ar ℕ n s)
→ .{≥ : a ≥a b}
→ Ar ℕ n s
(imap f -ₙ imap g) {≥} = imap λ iv → (f iv -safe- g iv) {≥ = ≥ iv}
-}
---- FIXME: I guess we can eliminate _-′_ and lift′ entirely by inlining definitions.
--infixr 20 _-_
--_-_ : ∀ {A B d s}{{t : DyScalVec ℕ A B d s}} → (a : A) → (b : B) → .{≥ : ▴ₗ a ≥a ▴ᵣ b} → Ar ℕ d s
--_-_ ⦃ t = s-s ⦄ a b {a≥b} = imap λ iv → (a -safe- b) {a≥b iv}
--_-_ ⦃ t = s-v ⦄ a b {a≥b} = imap λ iv → (a -safe- sel (▴ b) iv) {a≥b iv}
--_-_ ⦃ t = s-a ⦄ a b {a≥b} = imap λ iv → (a -safe- sel b iv) {a≥b iv} --= ▴ a -′ b
--_-_ ⦃ t = v-s ⦄ a b {a≥b} = imap λ iv → (sel (▴ a) iv -safe- b) {a≥b iv} -- = ▴ a -′ ▴ b
--_-_ ⦃ t = v-v ⦄ a b {a≥b} = imap λ iv → (sel (▴ a) iv -safe- sel (▴ b) iv) {a≥b iv} --= ▴ a -′ ▴ b
--_-_ ⦃ t = a-s ⦄ a b {a≥b} = imap λ iv → (sel a iv -safe- b) {a≥b iv} --= a -′ ▴ b
--_-_ ⦃ t = a-a {args = n-n} ⦄ a b {a≥b} = imap λ iv → (sel a iv -safe- sel b iv) {a≥b iv}
--_-_ ⦃ t = a-a {args = n-0} ⦄ a b {a≥b} = imap λ iv → (sel a iv -safe- sel b []) {a≥b iv}
--_-_ ⦃ t = a-a {args = 0-n} ⦄ a b {a≥b} = imap λ iv → (sel a [] -safe- sel b iv) {a≥b iv}
infixr 20 _-_
_-_ : ∀ {A B d s}{{t : DyScalVec ℕ A B d s}} → (a : A) → (b : B) → .{≥ : ▴ₗ a ≥a ▴ᵣ b} → Ar ℕ d s
_-_ ⦃ t = s-s ⦄ a b = imap λ iv → (a N.∸ b)
_-_ ⦃ t = s-v ⦄ a b = imap λ iv → (a N.∸ sel (▴ b) iv)
_-_ ⦃ t = s-a ⦄ a b = imap λ iv → (a N.∸ sel b iv)
_-_ ⦃ t = v-s ⦄ a b = imap λ iv → (sel (▴ a) iv N.∸ b)
_-_ ⦃ t = v-v ⦄ a b = imap λ iv → (sel (▴ a) iv N.∸ sel (▴ b) iv)
_-_ ⦃ t = a-s ⦄ a b = imap λ iv → (sel a iv N.∸ b)
_-_ ⦃ t = a-a {args = n-n} ⦄ a b = imap λ iv → (sel a iv N.∸ sel b iv)
_-_ ⦃ t = a-a {args = n-0} ⦄ a b = imap λ iv → (sel a iv N.∸ sel b [])
_-_ ⦃ t = a-a {args = 0-n} ⦄ a b = imap λ iv → (sel a [] N.∸ sel b iv)
-- _-′_ {args = args} a b
lift : ∀ {X A B d s}{{t : DyScalVec X A B d s}} → A → B → (_⊕_ : X → X → X) → Ar X d s
lift ⦃ t ⦄ a b _⊕_ = imap λ iv → sel (▴ₗ a) iv ⊕ sel (▴ᵣ b) iv
-- ℕ operations
infixr 20 _+_ _×_
_+_ _×_ : ∀ {A B d s}{{t : DyScalVec ℕ A B d s}} → A → B → Ar ℕ d s
a + b = lift a b N._+_
a × b = lift a b N._*_
-- Float operations
infixr 20 _+ᵣ_ _-ᵣ_ _×ᵣ_ _÷ᵣ_
_+ᵣ_ _-ᵣ_ _×ᵣ_ _÷ᵣ_ : ∀ {A B d s}{{t : DyScalVec Float A B d s}} → A → B → Ar Float d s
a +ᵣ b = lift a b primFloatPlus
a -ᵣ b = lift a b primFloatMinus
a ×ᵣ b = lift a b primFloatTimes
-- XXX we can request the proof that the right argument is not zero.
-- However, the current primFloatDiv has the type Float → Float → Float, so...
a ÷ᵣ b = lift a b primFloatDiv
lift-unary : ∀ {X A d s}{{t : SVup X A d s}} → (X → X) → A → Ar X d s
lift-unary ⦃ t = scal ⦄ f a = cst $ f a
lift-unary ⦃ t = vect ⦄ f a = imap λ iv → f $ V.lookup a $ ix-lookup iv zero
lift-unary ⦃ t = arry ⦄ f (imap a) = imap λ iv → f $ a iv
infixr 20 -ᵣ_ ÷ᵣ_ *ᵣ_
-ᵣ_ ÷ᵣ_ *ᵣ_ : ∀ {A d s}{{t : SVup Float A d s}} → A → Ar Float d s
*ᵣ_ = lift-unary primFloatExp
-ᵣ_ = lift-unary primFloatNegate
÷ᵣ_ = lift-unary (primFloatDiv 1.0)
module reduce-custom where
drop-last : ∀ {m}{X : Set} → Vec X m → Vec X (m N.∸ 1)
drop-last {0} x = x
drop-last {1} x = []
drop-last {suc (suc m)} (x ∷ xs) = x ∷ drop-last xs
gz : ℕ → ℕ
gz 0 = 0
gz _ = 1
take-last : ∀ {m}{X : Set} → Vec X m → Vec X (gz m)
take-last {0} x = x
take-last {1} x = x
take-last {suc (suc m)} (x ∷ xs) = take-last xs
_tldl++_ : ∀ {d s} → Ix (d N.∸ 1) (drop-last s) → Ix (gz d) (take-last s) → Ix d s
_tldl++_ {0} {s} iv jv = iv
_tldl++_ {1} {s} iv jv = jv
_tldl++_ {suc (suc d)} {s ∷ ss} (i ∷ iv) jv = i ∷ (iv tldl++ jv)
reduce-1d : ∀ {X Y : Set}{s} → (X → Y → Y) → Y → Ar X 1 s → Y
reduce-1d {s = 0 ∷ []} _⊕_ ε a = ε
reduce-1d {s = suc x ∷ []} _⊕_ ε (imap a) = a (zero ∷ []) ⊕ reduce-1d {s = x ∷ []} _⊕_ ε (imap λ where (i ∷ []) → a (suc i ∷ []))
infixr 20 _/′_
_/′_ : ∀ {X Y : Set}{d s} → (X → Y → Y) → Ar X d s → {ε : Y} → Ar Y _ (drop-last s)
_/′_ {d = 0} f (imap a) {ε} = imap λ iv → ε
_/′_ {d = suc d} f (imap a) {ε} = imap λ iv → reduce-1d f ε (imap λ jv → a (iv tldl++ jv))
data reduce-neut : {X Y : Set} → (X → Y → Y) → Y → Set where
instance
plus-nat : reduce-neut N._+_ 0
mult-nat : reduce-neut N._*_ 1
plus-flo : reduce-neut primFloatPlus 0.0
gplus-float : reduce-neut (_+ᵣ_ {{t = a-a {sx = []}{sy = []}{args = n-n} }}) (cst 0.0)
infixr 20 _/_
_/_ : ∀ {X Y : Set}{n s ε}
→ (_⊕_ : X → Y → Y) → {{c : reduce-neut _⊕_ ε}}
→ Ar X n s → Ar Y _ (drop-last s)
_/_ {ε = ε} f a = (f /′ a){ε}
infixr 20 _//_
_//_ : ∀ {X Y : Set}{n s ε}
→ (_⊕_ : Scal X → Scal Y → Scal Y) → {{c : reduce-neut _⊕_ ε}}
→ Ar X n s → Ar Y _ (drop-last s)
_//_ {ε = ε} f a = imap λ jv → ▾ (sel ((f /′ (imap λ iv → ▴ (sel a iv))){ε}) jv)
infixr 20 _/ᵣ_
_/ᵣ_ : ∀ {X : Set}{d}{s}{m} → (n : ℕ) → Ar X (d N.+ 1) (s V.++ (m ∷ [])) → Ar X (d N.+ 1) (s V.++ (n N.* m ∷ []))
_/ᵣ_ {d = d} {s = s} 0 a = imap λ iv → magic-fin (ix-lookup (take-ix-r s _ iv) zero)
_/ᵣ_ {d = d} {s = s} (suc n) a = imap λ iv → let i = ix-lookup (take-ix-r s _ iv) zero
l = take-ix-l s _ iv
i/n = F.fromℕ< $ /-mono-f {b = suc n} (F.toℕ<n i) _
in sel a $ l ix++ (i/n ∷ [])
infixr 20 _⌿ᵣ_
_⌿ᵣ_ : ∀ {X : Set}{d s m} → (n : ℕ) → Ar X (1 N.+ d) ((m ∷ []) V.++ s) → Ar X (1 N.+ d) ((n N.* m ∷ []) V.++ s)
_⌿ᵣ_ {d = d} {s = s} 0 a = imap λ iv → magic-fin (ix-lookup iv zero)
_⌿ᵣ_ {d = d} {s = s} (suc n) a = imap λ iv → let i = ix-lookup iv zero
r = take-ix-r _ s iv
i/n = F.fromℕ< $ /-mono-f {b = suc n} (F.toℕ<n i) _
in sel a $ (i/n ∷ []) ix++ r
open reduce-custom public
-- shape and flatten
infixr 20 ρ_
ρ_ : ∀ {ℓ}{X : Set ℓ}{d s} → Ar X d s → Ar ℕ 1 (d ∷ [])
ρ_ {s = s} _ = s→a s
infixr 20 ,_
,_ : ∀ {a}{X : Set a}{n s} → Ar X n s → Ar X 1 (prod s ∷ [])
,_ {s = s} p = imap λ iv → sel p (off→idx s iv)
-- Note that two dots in an upper register combined with
-- the underscore form the _̈ symbol. When the symbol is
-- used on its own, it looks like ̈ which is the correct
-- "spelling".
infixr 20 _̈_
_̈_ : ∀ {a}{X Y : Set a}{n s}
→ (X → Y)
→ Ar X n s
→ Ar Y n s
f ̈ imap p = imap $ f ∘ p
module _ where
data iota-type : (d : ℕ) → (n : ℕ) → (Vec ℕ d) → Set where
instance
iota-scal : iota-type 0 1 []
iota-vec : ∀ {n} → iota-type 1 n (n ∷ [])
iota-res-t : ∀ {d n s} → iota-type d n s → (sh : Ar ℕ d s) → Set
iota-res-t {n = n} iota-scal sh = Ar (Σ ℕ λ x → x N.< ▾ sh)
1 (▾ sh ∷ [])
iota-res-t {n = n} iota-vec sh = Ar (Σ (Ar ℕ 1 (n ∷ []))
λ v → v <a sh)
n (a→s sh)
data iota-t : Set → (n : ℕ) → Set where
instance
iota-scal : iota-t ℕ 0
iota-vect : ∀ {n} → iota-t (Vec ℕ n) n
iota-arrs : iota-t (Ar ℕ 0 []) 1
iota-arrv : ∀ {n} → iota-t (Ar ℕ 1 (n ∷ [])) n
iota-ty : ∀ {X n} → iota-t X n → X → Set
iota-ty {n = n} iota-scal x = Ar (Ix 1 (x ∷ [])) 1 (x ∷ [])
iota-ty {n = n} iota-vect x = Ar (Ix n x) n x
iota-ty {n = n} iota-arrs x = Ar (Ix n (▾ x ∷ [])) n (▾ x ∷ [])
iota-ty {n = n} iota-arrv x = Ar (Ix n (▾ x)) n (▾ x)
iota_ : ∀ {X n}{{t : iota-t X n}} → (x : X) → iota-ty t x
iota_ ⦃ t = iota-scal ⦄ x = imap id
iota_ ⦃ t = iota-vect ⦄ x = imap id
iota_ ⦃ t = iota-arrs ⦄ x = imap id
iota_ ⦃ t = iota-arrv ⦄ x = imap id
{-
iota-t : ∀ {A d s} → SVup ℕ A d s → Ar ℕ d s → Set
iota-t {d = d}{s} scal a = Ar (Ix 1 (▾ a ∷ [])) 1 (▾ a ∷ [])
iota-t {d = d}{n ∷ []} vect a = Ar (Ix n (▾ a)) n (▾ a)
iota-t {d = d}{n ∷ []} arry a = Ar (Ix n (▾ a)) n (▾ a)
iota_ : ∀ {A d s}{{t : SVup ℕ A d s}} → (a : Ar ℕ d s) → iota-t t a
iota_ {d = d}{s}⦃ t = scal ⦄ a = imap id
iota_ {d = d}{s}⦃ t = vect ⦄ a = imap id
iota_ {d = d}{s}⦃ t = arry ⦄ a = {!!} --imap id
-}
a<b⇒b≡c⇒a<c : ∀ {a b c} → a N.< b → b ≡ c → a N.< c
a<b⇒b≡c⇒a<c a<b refl = a<b
infixr 20 ι_
ι_ : ∀ {d n s}{{c : iota-type d n s}}
→ (sh : Ar ℕ d s)
→ iota-res-t c sh
ι_ ⦃ c = iota-scal ⦄ s = (imap λ iv → (F.toℕ $ ix-lookup iv zero) , F.toℕ<n (ix-lookup iv zero))
ι_ {n = n} {s = s ∷ []} ⦃ c = iota-vec ⦄ (imap sh) = imap cast-ix→a
where
cast-ix→a : _
cast-ix→a iv = let
ix , pf = ix→a iv
in ix , λ jv → a<b⇒b≡c⇒a<c (pf jv) (s→a∘a→s (imap sh) jv)
module cnn where
open reduce-custom
-- blog←{⍺×⍵×1-⍵}
-- NOTE: We use + instead of - in the last example, as we are not in ℝ, and N.∸ needs a proof.
blog : ∀ {n s} → Ar ℕ n s → Ar ℕ n s → Ar ℕ n s
blog α ω = α × ω × 1 + ω
conv : ∀ {n wₛ aₛ}
→ Ar ℕ n wₛ
→ Ar ℕ n aₛ
→ {≥ : ▴ aₛ ≥a ▴ wₛ}
→ Ar ℕ n $ ▾ (1 + (aₛ - wₛ){≥})
conv _ _ = cst 1
-- backbias←{+/,⍵}
backbias : ∀ {n s} → Ar ℕ n s → Ar ℕ _ []
backbias ω = N._+_ / , ω
-- meansqerr←{÷∘2+/,(⍺-⍵)*2}
meansqerr : ∀ {n s} → Ar ℕ n s → Ar ℕ n s → Ar ℕ _ []
meansqerr α ω = _+ 2 $ N._+_ / , (α + ω) × (α + ω)
-- backavgpool←{2⌿2/⍵÷4}⍤2
backavgpool : ∀ {s} → Ar ℕ 2 s → Ar ℕ 2 $ ▾ (2 × s)
backavgpool {s = _ ∷ _ ∷ []} ω = 2 /ᵣ′ 2 ⌿ᵣ ω × 4
where
infixr 20 _/ᵣ′_
_/ᵣ′_ = _/ᵣ_ {s = _ ∷ []}
-- Something that could go in Stdlib.
≡⇒≤ : ∀ {a b} → a ≡ b → a N.≤ b
≡⇒≤ refl = ≤-refl
-- This should be perfectly generaliseable --- instead of 2
-- we can use any m>0
a<b⇒k<2⇒a*2+k<b*2 : ∀ {a b k} → a N.< b → k N.< 2 → a N.* 2 N.+ k N.< b N.* 2
a<b⇒k<2⇒a*2+k<b*2 {a} {b} {zero} a<b k<2
rewrite (+-identityʳ (a N.* 2))
| (*-comm a 2)
| (*-comm b 2) = *-monoʳ-< 1 a<b
a<b⇒k<2⇒a*2+k<b*2 {a} {b} {suc zero} a<b k<2 = ≤-trans (N.s≤s (≡⇒≤ (+-comm _ 1)))
(*-monoˡ-≤ 2 a<b)
a<b⇒k<2⇒a*2+k<b*2 {a} {b} {suc (suc k)} a<b (N.s≤s (N.s≤s ()))
A<B⇒K<2⇒A*2+K<B*2 : ∀ {n s}{a b k : Ar ℕ n s} → a <a b → k <a (cst 2) → ((a × 2) + k) <a (b × 2)
A<B⇒K<2⇒A*2+K<B*2 {a = imap a} {imap b} {imap k} a<b k<2 = λ iv → a<b⇒k<2⇒a*2+k<b*2 (a<b iv) (k<2 iv)
---
a<n⇒b<n⇒a+b<m+n : ∀ {m n} a b → a N.< m → b N.< n → a N.+ b N.< m N.+ n
a<n⇒b<n⇒a+b<m+n {m} zero b a<m b<n = ≤-stepsˡ m b<n
a<n⇒b<n⇒a+b<m+n {suc m} (suc a) b (N.s≤s a<m) b<n = N.s≤s (a<n⇒b<n⇒a+b<m+n a b a<m b<n)
a<n⇒b<n⇒a+b<m+n-1 : ∀ {m n} a b → a N.< m → b N.< n → a N.+ b N.< m N.+ n N.∸ 1
a<n⇒b<n⇒a+b<m+n-1 {suc m} {suc n} zero b a<m b<n = ≤-stepsˡ m b<n
a<n⇒b<n⇒a+b<m+n-1 {suc m} {suc n} (suc a) b (N.s≤s a<m) b<n rewrite +-suc m n =
N.s≤s $ begin
suc (a N.+ b) ≤⟨ a<n⇒b<n⇒a+b<m+n-1 a b a<m b<n ⟩
m N.+ suc n N.∸ 1 ≡⟨ cong₂ N._∸_ (+-suc m n) refl ⟩
suc (m N.+ n) N.∸ 1 ≡⟨⟩
m N.+ n
∎
where open N.≤-Reasoning
_+ff_ : ∀ {m n} → Fin m → Fin n → Fin (m N.+ n N.∸ 1)
a +ff b = F.fromℕ< (a<n⇒b<n⇒a+b<m+n-1 _ _ (F.toℕ<n a) (F.toℕ<n b))
_+f_ : ∀ {m n} → Fin m → Fin n → Fin (m N.+ n)
a +f b = F.fromℕ< (a<n⇒b<n⇒a+b<m+n _ _ (F.toℕ<n a) (F.toℕ<n b))
_*lf_ : ∀ {n} → (m : ℕ) → Fin n → .{m N.> 0} → Fin (suc (m N.* n N.∸ m))
_*lf_ {n} m (b) {m>0} = let
m*sb≤m*n = *-monoʳ-≤ m $ F.toℕ<n b
m+m*b≤m*n = subst₂ N._≤_ (*-suc m _) refl m*sb≤m*n
m+m*b-m≤m*n = ∸-monoˡ-≤ m m+m*b≤m*n
m*b≤m*n-m = subst₂ N._≤_ (m+n∸m≡n m _) refl m+m*b-m≤m*n
in F.fromℕ< (N.s≤s m*b≤m*n-m)
--_i+_ : ∀ {n s s'} → Ix n s → Ix n s' → Ix n (▾ ((s + s') -′ ▴ 1))
--iv i+ jv = ix-tabulate λ i → subst Fin (sym (V.lookup∘tabulate _ i)) $ ix-lookup iv i +ff ix-lookup jv i
-- Note that we explicitly use _-′_ instead of _-_ to avoid the proof.
-- It is ok if m ≥ s×m as this means that s=0, and therefore there is no
-- such index (element of Fin 0 at some position in s).
--_il×_ : ∀ {n s} → (m : ℕ) → Ix n s → .{≥ : m N.> 0} → let s = 1 + (m × s) -′ ▴ m in Ix n (▾ s)
--(a il× ix) {m>0} = ix-tabulate λ i → subst Fin (sym (V.lookup∘tabulate _ i)) $ (a *lf ix-lookup ix i){m>0}
{-
avgpool' : ∀ {s}
→ Ar Float 2 $ ▾ (2 × s)
→ Ar Float 2 s
avgpool' {s} (imap p) = imap body
where
m>0⇒k≤k*m : ∀ {m} → m N.> 0 → ∀ k → k N.≤ k N.* m
m>0⇒k≤k*m m>0 zero = N.z≤n
m>0⇒k≤k*m m>0 (suc k) = +-mono-≤ m>0 (m>0⇒k≤k*m m>0 k)
--a≤a*b
thm : ∀ {d s} → Ix d s → ∀ i → d N.+ (d N.* V.lookup s i N.∸ d) ≡ d N.* V.lookup s i
thm {d}{s} ix i with V.lookup s i | ix-lookup ix i
... | zero | ()
... | suc m | _ = m+[n∸m]≡n (m>0⇒k≤k*m {m = suc m} (N.s≤s N.z≤n) d)
thmx : ∀ {d s} → Ix d s → ∀ i → V.lookup (▾ (d + (d × s) -′ ▴ d)) i ≡ V.lookup (▾ (d × s)) i
thmx {d}{s} ix i with V.lookup s i | inspect (V.lookup s) i | ix-lookup ix i
... | zero | _ | ()
... | suc m | [ pf ] | _ = begin
V.lookup (V.tabulate (λ z → d N.+ (d N.* V.lookup s z N.∸ d))) i ≡⟨ lookup∘tabulate _ i ⟩
d N.+ (d N.* V.lookup s i N.∸ d) ≡⟨ cong (d N.+_) (cong (N._∸ d) (cong (d N.*_) pf)) ⟩
d N.+ (d N.* suc m N.∸ d) ≡⟨ m+[n∸m]≡n (m>0⇒k≤k*m {m = suc m} (N.s≤s N.z≤n) d) ⟩
d N.* suc m ≡⟨ cong (d N.*_) (sym pf) ⟩
d N.* V.lookup s i ≡⟨ sym (lookup∘tabulate _ i) ⟩
V.lookup (V.tabulate (λ z → d N.* V.lookup s z)) i
∎
where open ≡-Reasoning
body : _ → _
body iv = let
ixs = iota (2 ∷ 2 ∷ [])
ix = (2 il× iv) {N.s≤s N.z≤n}
f iv = p $ subst-ix {!!} $ iv i+ ix
xx = primFloatPlus / , f ̈ ixs
in {!!}
-}
avgpool : ∀ {s}
→ Ar ℕ 2 $ ▾ (s × 2)
→ Ar ℕ 2 s
avgpool {s} (imap p) = imap body
where body : _ → _
body iv = let
sh = s × 2
ix , ix<s = ix→a iv
bx = ix × 2
ixs = ι (cst {s = 2 ∷ []} 2)
use-ixs = λ where
(i , pf) → p $ a→ix (bx + i) sh $ A<B⇒K<2⇒A*2+K<B*2 ix<s pf
in ▾ (_× 4 $ N._+_ / , use-ixs ̈ ixs)
--test : ∀ {s : Vec ℕ 2} → ℕ
--test {s} = {! s × 2!}
-- Take and Drop
ax+sh<s : ∀ {n}
→ (ax sh s : Ar ℕ 1 (n ∷ []))
→ (s≥sh : s ≥a sh)
→ (ax <a (s - sh) {≥ = s≥sh})
→ (ax + sh) <a s
ax+sh<s (imap ax) (imap sh) (imap s) s≥sh ax<s-sh iv =
let
ax+sh<s-sh+sh = +-monoˡ-< (sh iv) (ax<s-sh iv)
s-sh+sh≡s = m∸n+n≡m (s≥sh iv)
in a<b⇒b≡c⇒a<c ax+sh<s-sh+sh s-sh+sh≡s
{-
_↑_ : ∀ {a}{X : Set a}{n s}
→ (sh : Ar ℕ 1 (n ∷ []))
→ (a : Ar X n s)
→ {pf : s→a s ≥a sh}
→ Ar X n $ a→s sh
_↑_ {s = s} sh (imap f) {pf} with (prod $ a→s sh) N.≟ 0
_↑_ {s = s} sh (imap f) {pf} | yes Πsh≡0 = imap λ iv → magic-fin $ Πs≡0⇒Fin0 _ iv Πsh≡0 --mkempty _ Πsh≡0
_↑_ {s = s} (imap q) (imap f) {pf} | no Πsh≢0 = imap λ iv → {- mtake
where
mtake : _
mtake iv = -} let
ai , ai< = ix→a iv
ix<q jv = a<b⇒b≡c⇒a<c (ai< jv) (s→a∘a→s (imap q) jv)
ix = a→ix ai (s→a s) λ jv → ≤-trans (ix<q jv) (pf jv)
in f (subst-ix (a→s∘s→a s) ix)
-}
{- -}
_↑_ : ∀ {a}{X : Set a}{n s}
→ (sh : Ar ℕ 1 (n ∷ []))
→ (a : Ar X n s)
→ {pf : s→a s ≥a sh}
→ Ar X n $ a→s sh
_↑_ {s = s} sh (imap f) {pf} = case (prod $ a→s sh) N.≟ 0 of λ where
(yes Πsh≡0) → imap λ iv → magic-fin $ Πs≡0⇒Fin0 _ iv Πsh≡0
(no Πsh≢0) → imap λ iv → let
ai , ai< = ix→a iv
ix<q jv = a<b⇒b≡c⇒a<c (ai< jv) (s→a∘a→s sh jv)
ix = a→ix ai (s→a s) λ jv → ≤-trans (ix<q jv) (pf jv)
in f (subst-ix (a→s∘s→a s) ix)
{- -}
_↓_ : ∀ {a}{X : Set a}{n s}
→ (sh : Ar ℕ 1 (n ∷ []))
→ (a : Ar X n s)
→ {pf : (s→a s) ≥a sh}
→ Ar X n $ a→s $ (s→a s - sh) {≥ = pf}
_↓_ {s = s} sh (imap x) {pf} with
let p = prod $ a→s $ (s→a s - sh) {≥ = pf}
in p N.≟ 0
_↓_ {s = s} sh (imap f) {pf} | yes Π≡0 = mkempty _ Π≡0
_↓_ {s = s} (imap q) (imap f) {pf} | no Π≢0 = imap mkdrop
where
mkdrop : _
mkdrop iv = let
ai , ai< = ix→a iv
ax = ai + (imap q)
thmx = ax+sh<s
ai (imap q) (s→a s) pf
λ jv → a<b⇒b≡c⇒a<c (ai< jv)
(s→a∘a→s ((s→a s - (imap q)) {≥ = pf}) jv)
ix = a→ix ax (s→a s) thmx
in f (subst-ix (a→s∘s→a s) ix)
∸-monoˡ-< : ∀ {m n o} → m < n → o ≤ m → m ∸ o < n ∸ o
∸-monoˡ-< {o = zero} m<n o≤m = m<n
∸-monoˡ-< {suc m} {o = suc o} (s≤s m<n) (s≤s o≤m) = ∸-monoˡ-< m<n o≤m
a+b-a≡a : ∀ {n} {s₁ : Vec ℕ n} {s : Ix 1 (n ∷ []) → ℕ}
{jv : Ix 1 (n ∷ [])} →
V.lookup (V.tabulate (λ i → s (i ∷ []) N.+ V.lookup s₁ i))
(ix-lookup jv zero)
∸ s jv
≡ V.lookup s₁ (ix-lookup jv zero)
a+b-a≡a {zero} {[]} {s} {x ∷ []} = magic-fin x
a+b-a≡a {suc n} {x ∷ s₁} {s} {zero ∷ []} = m+n∸m≡n (s (zero ∷ [])) x
a+b-a≡a {suc n} {x ∷ s₁} {s} {suc j ∷ []} = a+b-a≡a {s₁ = s₁} {s = λ { (j ∷ []) → s (suc j ∷ [])}} {jv = j ∷ []}
pre-pad : ∀ {a}{X : Set a}{n}{s₁ : Vec ℕ n}
→ (sh : Ar ℕ 1 (n ∷ []))
→ X
→ (a : Ar X n s₁)
→ Ar X n (a→s $ sh + ρ a)
pre-pad {s₁ = s₁} (imap s) e (imap f) = imap body
where
body : _
body iv = let ix , ix<s = ix→a iv
in case ix ≥a? (imap s) of λ where
(yes p) → let
fx = (ix - (imap s)) {≥ = p}
fv = a→ix fx (s→a s₁)
λ jv → a<b⇒b≡c⇒a<c
(∸-monoˡ-< (ix<s jv) (p jv))
(a+b-a≡a {s₁ = s₁} {s = s} {jv = jv})
in f (subst-ix (λ i → lookup∘tabulate _ i) fv)
(no ¬p) → e
b≤a⇒c<b⇒a-b+c<a : ∀ {a b c} → b ≤ a → c < b → a ∸ b N.+ c < a
b≤a⇒c<b⇒a-b+c<a {suc a} {suc b} {zero} b≤a c<b rewrite +-identityʳ (a ∸ b) = s≤s (m∸n≤m a b)
b≤a⇒c<b⇒a-b+c<a {suc a} {suc b} {suc c} (s≤s b≤a) (s≤s c<b) = let q = b≤a⇒c<b⇒a-b+c<a b≤a c<b
in subst₂ _<_ (sym $ +-suc (a ∸ b) c) refl $ +-monoʳ-< 1 q
[a+b≥c]⇒b<c⇒a+b-c<a : ∀ {a b c} → a N.+ b N.≥ c → b < c → a N.+ b ∸ c < a
[a+b≥c]⇒b<c⇒a+b-c<a {a}{b}{c} a+b≥c b<c = let a+b<a+c = +-monoʳ-< a b<c
in subst₂ _<_ refl (m+n∸n≡m _ c) $ ∸-monoˡ-< a+b<a+c a+b≥c
{-
_-↑⟨_⟩_ : ∀ {a}{X : Set a}{n}{s₁ : Vec ℕ n}
→ (sh : Ar ℕ 1 (n ∷ []))
→ X
→ (a : Ar X n s₁)
→ Ar X n (▾ sh)
_-↑⟨_⟩_ {s₁ = s₁} s e a = imap λ iv → let
ix , ix<s = ix→a iv
in case ((ρ a) + ix) ≥a? s of λ where
(yes p) → let
ov = (((ρ a) + ix) - s){p}
oi = a→ix ov (ρ a) λ { jv@(i ∷ []) → [a+b≥c]⇒b<c⇒a+b-c<a (p jv) (subst₂ _<_ refl (V.lookup∘tabulate _ i) $ ix<s jv) }
in sel a (subst-ix (λ i → lookup∘tabulate _ i) oi)
(no _) → e
-}
_-↑⟨_⟩_ : ∀ {a}{X : Set a}{n}{s₁ : Vec ℕ n}
→ (sh : Ar ℕ 1 (n ∷ []))
→ X
→ (a : Ar X n s₁)
→ Ar X n (▾ sh)
_-↑⟨_⟩_ {s₁ = s₁} s e a = imap body
where
body : _
body iv with ix→a iv
... | ix , ix<s with ((ρ a) + ix) ≥a? s
... | (yes p) = let
ov = (((ρ a) + ix) - s){p}
oi = a→ix ov (ρ a) λ { jv@(i ∷ []) → [a+b≥c]⇒b<c⇒a+b-c<a (p jv) (subst₂ _<_ refl (V.lookup∘tabulate _ i) $ ix<s jv) }
in sel a (subst-ix (λ i → lookup∘tabulate _ i) oi)
... | _ = e
{-
_↑⟨_⟩_ : ∀ {a}{X : Set a}{n}{s : Vec ℕ n}
→ (sh : Ar ℕ 1 (n ∷ []))
→ X
→ (a : Ar X n s)
→ Ar X n (▾ sh)
_↑⟨_⟩_ {s = s} (imap sh) e (imap a) = imap body
where
body : _
body iv = let ix , ix<s = ix→a iv
in case ix <a? (ρ imap a) of λ where
(yes p) → let
av = a→ix ix (ρ imap a) p
in a (subst-ix (λ i → lookup∘tabulate _ i) av)
(no ¬p) → e
-}
_↑⟨_⟩_ : ∀ {a}{X : Set a}{n}{s : Vec ℕ n}
→ (sh : Ar ℕ 1 (n ∷ []))
→ X
→ (a : Ar X n s)
→ Ar X n (▾ sh)
_↑⟨_⟩_ {s = s} (imap sh) e (imap a) = imap body
where
body : _
body iv with ix→a iv
... | ix , ix<s with ix <a? (ρ imap a)
... | (yes p) = let
av = a→ix ix (ρ imap a) p
in a (subst-ix (λ i → lookup∘tabulate _ i) av)
... | (no ¬p) = e
_̈⟨_⟩_ : ∀ {a}{X Y Z : Set a}{n s}
→ Ar X n s
→ (X → Y → Z)
→ Ar Y n s → Ar Z n s
--(imap p) ̈⟨ f ⟩ (imap p₁) = imap λ iv → f (p iv) (p₁ iv)
p ̈⟨ f ⟩ p₁ = imap λ iv → f (sel p iv) (sel p₁ iv)
module test where
s : Vec ℕ 3
s = 1 ∷ 2 ∷ 3 ∷ []
a : Ar ℕ 3 s
a = cst 10
b : Ar ℕ 0 []
b = cst 20
test/ : _
test/ = reduce-custom._/_ N._+_ a
-- These tests work, which is nice.
test₁ : Ar ℕ 3 s
test₁ = a + b
test₂ : Ar ℕ 3 s
test₂ = b + a
test₃ : Ar ℕ 3 s
test₃ = a + a
test₄ : Ar ℕ 0 []
test₄ = b + b
-- This looks much better.
test-nn : ∀ {n s} → (a b : Ar ℕ n s) → Ar ℕ n s
test-nn {n}{s} x y = x + y
test-n0 : ∀ {n s} → Ar ℕ n s → Ar ℕ n s
test-n0 x = x + b
test-0n : ∀ {n s} → Ar ℕ n s → Ar ℕ n s
test-0n x = b + x
-- This definition should fail, as sx ≠ sy (not necessarily)
--test-fail : ∀ {n sx sy} → Ar ℕ n sx → Ar ℕ n sy → Ar ℕ n sy
--test-fail x y = x + y
|
{
"alphanum_fraction": 0.4272331534,
"avg_line_length": 35.6708074534,
"ext": "agda",
"hexsha": "9e138334448fb1f0749445eb6ec47b58ac3be6cb",
"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": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "ashinkarov/agda-extractor",
"max_forks_repo_path": "APL2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "ashinkarov/agda-extractor",
"max_issues_repo_path": "APL2.agda",
"max_line_length": 150,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "ashinkarov/agda-extractor",
"max_stars_repo_path": "APL2.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-11T14:52:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-11T14:52:59.000Z",
"num_tokens": 13279,
"size": 28715
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Results concerning uniqueness of identity proofs, with axiom K
------------------------------------------------------------------------
{-# OPTIONS --with-K --safe #-}
module Axiom.UniquenessOfIdentityProofs.WithK where
open import Axiom.UniquenessOfIdentityProofs
open import Relation.Binary.PropositionalEquality.Core
-- Axiom K implies UIP.
uip : ∀ {a} {A : Set a} → UIP A
uip refl refl = refl
|
{
"alphanum_fraction": 0.5333333333,
"avg_line_length": 28.3333333333,
"ext": "agda",
"hexsha": "8529e4f4b28b5bc837846bd1906fdd487bf2efe7",
"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/Axiom/UniquenessOfIdentityProofs/WithK.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/Axiom/UniquenessOfIdentityProofs/WithK.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Axiom/UniquenessOfIdentityProofs/WithK.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": 102,
"size": 510
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.