rzk-0.11.4: An experimental proof assistant for synthetic ∞-categories
Safe HaskellNone
LanguageHaskell2010

Rzk.Check.Value

Description

checker's context.

Evaluation is the library's; this module gives it the elimination rules (β, the projections, path induction, let, a recOR whose guard the tope context entails, the lattice and flip operations of the cube layer, the connectives of the tope layer), the η laws of λ and pairs, what each binder adds to the context, how two nodes compare (subtyping in the context's variance, holes, topes by entailment), and the refinement of a neutral by a restriction of its type.

The algorithm is free-foil-NBE's (Renata Shakirova and Nikolai Kudasov): normalisation by evaluation generic in the signature, conversion checking after Coquand (An algorithm for type-checking dependent types, 1996), the untyped η for surjective pairs of Abel and Coquand (2007), glued evaluation and approximate conversion checking after Kovács's smalltt, and subtyping as conversion with the direction in the context, as in Rocq's kernel and in Rzk's own unification. The rules follow the evaluator and the unification of Rzk.TypeCheck.

Synopsis

Values

type Value = Value Pattern Sig Source #

A value of the core: free-foil-NBE's, over the pattern binder and the signature.

type Whnf = Whnf Pattern Sig Source #

pattern VUniverse :: Whnf n Source #

A weak head normal form of each constructor: VTypeFun for TypeFunF, and so on. A node with scoped subterms is suspended under its environment, which the pattern binds first.

pattern VUniverseCube :: Whnf n Source #

pattern VUniverseTope :: Whnf n Source #

pattern VCubeUnit :: Whnf n Source #

pattern VCubeUnitStar :: Whnf n Source #

pattern VCube2 :: Whnf n Source #

pattern VCube2_0 :: Whnf n Source #

pattern VCube2_1 :: Whnf n Source #

pattern VCubeI :: Whnf n Source #

pattern VCubeI_0 :: Whnf n Source #

pattern VCubeI_1 :: Whnf n Source #

pattern VCubeProduct :: Value n -> Value n -> Whnf n Source #

pattern VCubeFlip :: Value n -> Whnf n Source #

pattern VCubeUnflip :: Value n -> Whnf n Source #

pattern VCubeSup :: Value n -> Value n -> Whnf n Source #

pattern VCubeInf :: Value n -> Value n -> Whnf n Source #

pattern VTopeTop :: Whnf n Source #

pattern VTopeBottom :: Whnf n Source #

pattern VTopeEQ :: Value n -> Value n -> Whnf n Source #

pattern VTopeLEQ :: Value n -> Value n -> Whnf n Source #

pattern VTopeAnd :: Value n -> Value n -> Whnf n Source #

pattern VTopeOr :: Value n -> Value n -> Whnf n Source #

pattern VTopeInv :: Value n -> Whnf n Source #

pattern VTopeUninv :: Value n -> Whnf n Source #

pattern VRecBottom :: Whnf n Source #

pattern VRecOr :: Value n -> [(Value n, Value n)] -> Whnf n Source #

pattern VTypeFun :: forall n (i :: S). () => Distinct i => Env i n -> TModality -> Value n -> Maybe (Value n) -> ScopedCore i -> Whnf n Source #

pattern VTypeShape :: TModality -> Value n -> Maybe (Value n) -> Whnf n Source #

pattern VTypeSigma :: forall n (i :: S). () => Distinct i => Env i n -> TModality -> Value n -> ScopedCore i -> Whnf n Source #

pattern VTypeId :: Value n -> Maybe (Value n) -> Value n -> Whnf n Source #

pattern VApp :: Value n -> Value n -> Whnf n Source #

pattern VLet :: forall n (i :: S). () => Distinct i => Env i n -> Maybe (Value n) -> Value n -> ScopedCore i -> Whnf n Source #

pattern VLambda :: forall n (i :: S). () => Distinct i => Env i n -> Maybe (Param (Value n)) -> ScopedCore i -> Whnf n Source #

pattern VPair :: Value n -> Value n -> Whnf n Source #

pattern VFirst :: Value n -> Whnf n Source #

pattern VSecond :: Value n -> Whnf n Source #

pattern VRefl :: Maybe (Value n, Maybe (Value n)) -> Whnf n Source #

pattern VIdJ :: Value n -> Value n -> Value n -> Value n -> Value n -> Value n -> Whnf n Source #

pattern VMatch :: TModality -> Value n -> Maybe (Value n) -> [(VarIdent, Value n)] -> Whnf n Source #

pattern VMatchArm :: forall n (i :: S). () => Distinct i => Env i n -> ScopedCore i -> Whnf n Source #

pattern VUnit :: Whnf n Source #

pattern VTypeUnit :: Whnf n Source #

pattern VTypeAsc :: Value n -> Value n -> Whnf n Source #

pattern VAnn :: Value n -> Value n -> Whnf n Source #

pattern VTypeRestricted :: Value n -> [(Value n, Value n)] -> Whnf n Source #

pattern VTypeModal :: TModality -> Value n -> Whnf n Source #

pattern VModApp :: TModality -> Value n -> Whnf n Source #

pattern VModExtract :: TModality -> TModality -> Value n -> Whnf n Source #

pattern VLetMod :: forall n (i :: S). () => Distinct i => Env i n -> TModality -> TModality -> Maybe (Value n) -> Maybe (Value n) -> Value n -> ScopedCore i -> Whnf n Source #

pattern VHole :: Maybe VarIdent -> Whnf n Source #

type Env (i :: S) (n :: S) = Substitution (Value Pattern Sig) i n Source #

Evaluation and readback

evalCore :: forall (n :: S). Distinct n => Scope n -> Context n -> Core n -> Value n Source #

A core term as a value, in the scope it was checked in.

evalScope :: forall (n :: S) (i :: S). (Distinct n, Distinct i) => Scope n -> Context n -> Env i n -> ScopedCore i -> Value n -> Value n Source #

A scoped term at a value for its pattern.

quoteIn :: forall (n :: S). Distinct n => Scope n -> Context n -> Value n -> Core n Source #

quoteFolded :: forall (n :: S). Distinct n => Scope n -> Context n -> Value n -> Core n Source #

Read a value back with defined names folded, as the checker's own terms spell them.

quoteWhnfFolded :: forall (n :: S). Distinct n => Scope n -> Context n -> Value n -> Core n Source #

Read back the weak head normal form of a value: the head unfolded and reduced, its arguments read back with defined names folded, as the old checker's #compute-whnf printed them.

quoteWhnfCore :: forall (n :: S). Distinct n => Scope n -> Context n -> Core n -> Core n Source #

Evaluate a core term and read back its weak head normal form.

nfCore :: forall (n :: S). Distinct n => Scope n -> Context n -> Core n -> Core n Source #

force :: forall (n :: S). Value n -> Whnf n Source #

conv :: forall (n :: S). Distinct n => Scope n -> Context n -> Value n -> Value n -> Bool Source #

Compare an expected value with an actual one in the context's variance.

convertible :: forall (n :: S). Distinct n => Scope n -> Context n -> Core n -> Core n -> Bool Source #

Values the rules build

vnode :: forall (n :: S). Sig Void (Value n) -> Value n Source #

universe :: forall (n :: S). Value n Source #

cubeUniverse :: forall (n :: S). Value n Source #

topeUniverse :: forall (n :: S). Value n Source #

vcube2 :: forall (n :: S). Value n Source #

vcubeI :: forall (n :: S). Value n Source #

vtopeBottom :: forall (n :: S). Value n Source #

vunit :: forall (n :: S). Value n Source #

vtypeUnit :: forall (n :: S). Value n Source #

vhole :: forall (n :: S). Maybe VarIdent -> Value n Source #

vrecBottom :: forall (n :: S). Value n Source #

Elimination

appValue :: forall (n :: S). Distinct n => Scope n -> Context n -> Value n -> Value n -> Value n Source #

Apply a function value: a λ enters its body under the pattern bound to the argument; a neutral stays stuck, with the shape of a tope family it is an application of as a side condition.

firstValue :: forall (n :: S). Value n -> Value n Source #

secondValue :: forall (n :: S). Value n -> Value n Source #

codomainAt :: forall (n :: S) (i :: S). (Distinct n, Distinct i) => Scope n -> Context n -> Env i n -> ScopedCore i -> Value n -> Value n Source #

The codomain of a scope at a value for its pattern.

data Pi (n :: S) where Source #

A Π type value, opened: the environment its codomain is suspended under, its modality, its domain, its shape and its codomain.

Constructors

Pi :: forall (i :: S) (n :: S). Distinct i => Env i n -> TModality -> Value n -> Maybe (Value n) -> ScopedCore i -> Pi n 

piOf :: forall (n :: S). Value n -> Maybe (Pi n) Source #

data Sigma (n :: S) where Source #

A Σ type value, opened.

Constructors

Sigma :: forall (i :: S) (n :: S). Distinct i => Env i n -> TModality -> Value n -> ScopedCore i -> Sigma n 

sigmaOf :: forall (n :: S). Value n -> Maybe (Sigma n) Source #

data Family (n :: S) Source #

The type of a tope family: its modality, its cube and its shape.

Constructors

Family TModality (Value n) (Maybe (Value n)) 

familyOf :: forall (n :: S). Value n -> Maybe (Family n) Source #

isTopShape :: forall (n :: S). Value n -> Bool Source #

Is a shape the one that is ⊤ everywhere?

stripRestrictions :: forall (n :: S). Value n -> Value n Source #

A type value with its restrictions peeled off.

restrictionsOf :: forall (n :: S). Value n -> [(Value n, Value n)] Source #

The restrictions of a type value, outermost first.

Patterns

patternValue :: forall (n :: S) (l :: S). (Distinct n, Distinct l) => Pattern n l -> Value l Source #

A pattern as a value of its own scope: its names, paired.

bindPattern :: forall (i :: S) (n :: S) (l :: S). Env i n -> Pattern i l -> Value n -> Env l n Source #

An environment extended with a pattern bound to a value: each leaf gets the projection of the value at its position, computed when the name is looked up.

patternEntries :: forall (n :: S) (l :: S). (Distinct n, Distinct l) => Scope l -> Context l -> TModality -> Maybe LocationInfo -> Value l -> Pattern n l -> [Entry l] Source #

The entries of a pattern's names, in binding order, from the type of the value it is bound to: a pair pattern destructures a Σ type or a cube product. A leaf whose type cannot be read gets a hole for a type.

The context is the one under the pattern, without the pattern's own entries yet: the codomain of a Σ is evaluated at the left component's names, which the environment binds, so the entries are never consulted while they are built.

letEntries :: forall (n :: S) (l :: S). (Distinct n, Distinct l) => Scope l -> Context l -> Maybe LocationInfo -> Value l -> Value l -> Pattern n l -> [Entry l] Source #

The entries of a let's pattern: each name has its component of the value.

singlePattern :: forall (n :: S) (l :: S). NameBinder n l -> Pattern n l Source #

The pattern binding one name.

underPattern :: forall (n :: S) (l :: S). (Distinct n, DExt n l) => Scope l -> Context n -> TModality -> Value n -> Maybe (Value n) -> Pattern n l -> Context l Source #

The context under a pattern bound at a type, with a shape assumed for it.

underFreshVar :: forall (n :: S) r. Distinct n => Scope n -> Context n -> TModality -> Value n -> Maybe (Value n) -> (forall (l :: S). (DExt n l, Distinct l) => Scope l -> Context l -> Name l -> r) -> r Source #

The context under one fresh name of a type: the scope, the context with the name's entry, and the name.

isCube :: forall (n :: S). Distinct n => Scope n -> Context n -> Value n -> Bool Source #

Does a value stand for a cube: by its head, or by the sort of the entry at its head?

topShapeValue :: forall (n :: S). Distinct n => Scope n -> Value n -> Value n Source #

The shape of a binder over a cube with no restriction: the family that is ⊤ everywhere.

The tope layer

topeOf :: forall (n :: S). Distinct n => Scope n -> Context n -> Value n -> Tope n Source #

A tope value read into the solver's syntax.

pointOf :: forall (n :: S). Distinct n => Scope n -> Context n -> Value n -> Point n Source #

A point value read into the solver's syntax. A variable carries its cube; a defined point is unfolded.

cubeOfType :: forall (n :: S). Value n -> Cube Source #

A cube value, as far as the solver tells cubes apart.

entailsValue :: forall (n :: S). Distinct n => Scope n -> Context n -> Value n -> Bool Source #

Does the context entail a tope value?

assumeValue :: forall (n :: S). Distinct n => Scope n -> Context n -> Value n -> Context n Source #

Assume a tope value.

topeAndValue :: forall (n :: S). Value n -> Value n -> Value n Source #

The conjunction of two tope values, with ⊥ absorbing.

recOrValue :: forall (n :: S). Distinct n => Scope n -> Context n -> [(Value n, Value n)] -> Value n Source #

A recOR of values, simplified as evaluation simplifies one: the branch whose guard the context entails, otherwise the one branch if all are convertible, otherwise the recOR itself.

Types of neutrals

neutralType :: forall (n :: S). Distinct n => Scope n -> Context n -> Value n -> Maybe (Value n) Source #

The type of a neutral, read off its head and its eliminations: an application has the codomain of its function's type at the argument, a projection the component of the pair's Σ type, a path induction the motive at its endpoints. A glued head keeps its declared type. An elimination of a neutral whose type is restricted is restricted by the same elimination of the terms: under ϕ, a neutral f : (X → A) [ϕ ↦ g] is g, so f a : A [ϕ ↦ g a]. A neutral built by evaluation carries its type (AnnF), so each step reads only the type of the neutral it eliminates.

Holes

Orphan instances

HasHeads Sig Source #

The heads: the function of an application, the pair of a projection, the path of an induction.

Instance details

Methods

headsWith :: (b -> d) -> (b -> d) -> Sig a b -> Sig a d

Eval Context Pattern Sig Source # 
Instance details

Methods

definition :: forall (n :: S). Scope n -> Context n -> Name n -> Value Pattern Sig n

unfolding :: forall (n :: S). Scope n -> Context n -> Value Pattern Sig n -> Value Pattern Sig n -> Value Pattern Sig n

glueSpeculation :: forall (n :: S). Scope n -> Context n -> Name n -> Value Pattern Sig n -> Name n -> Value Pattern Sig n -> GlueSpeculation Context n

unfoldGlued :: forall (n :: S). Scope n -> Context n -> Name n -> Value Pattern Sig n -> Maybe (Context n)

evalSig :: forall (o :: S) (i :: S). (Distinct o, Distinct i) => Scope o -> Context o -> Substitution (Value Pattern Sig) i o -> Sig (ScopedAST Pattern Sig i) (AST Pattern Sig i) -> Value Pattern Sig o

etaMatchWith :: forall a (n :: S) c b d. (a -> EtaScoped Context Pattern Sig n -> c) -> (b -> EtaTerm Context Pattern Sig n -> d) -> Sig a b -> Maybe (Sig c d)

extendScopedWith :: forall (n :: S) a c d. Distinct n => (a -> Extend Context Pattern Sig n -> c) -> (Value Pattern Sig n -> d) -> Sig a (Value Pattern Sig n) -> Sig c d

relateWith :: forall m (n :: S) a a'. (Monoid m, Distinct n) => Scope n -> Context n -> (a -> a' -> Context n -> Extend Context Pattern Sig n -> m) -> (Value Pattern Sig n -> Value Pattern Sig n -> Context n -> m) -> (Value Pattern Sig n -> Value Pattern Sig n -> Context n -> m) -> Sig a (Value Pattern Sig n) -> Sig a' (Value Pattern Sig n) -> Maybe m

relateMismatch :: forall (n :: S). (Eval Context Pattern Sig, Distinct n) => Scope n -> Context n -> Value Pattern Sig n -> Value Pattern Sig n -> Bool

refineVar :: forall (n :: S). (Eval Context Pattern Sig, Distinct n) => Scope n -> Context n -> Name n -> Value Pattern Sig n

refineSig :: forall (n :: S) a. (Eval Context Pattern Sig, Distinct n) => Scope n -> Context n -> Value Pattern Sig n -> Sig a (Value Pattern Sig n) -> Value Pattern Sig n

binderValue :: forall (n :: S) (l :: S). (Distinct n, Distinct l) => Scope l -> Context l -> Pattern n l -> Maybe (Value Pattern Sig l)

bindValue :: forall (o :: S) (i :: S) (l :: S). Distinct o => Scope o -> Context o -> Substitution (Value Pattern Sig) i o -> Pattern i l -> Value Pattern Sig o -> Maybe (Substitution (Value Pattern Sig) l o)

evalBinder :: forall (n :: S) (i :: S) (e :: S -> Type) (l :: S) r. (CoSinkable Pattern, Distinct n, Distinct i, Sinkable e, InjectName e) => Scope n -> Context n -> Substitution (Value Pattern Sig) i n -> Pattern i l -> (forall (n' :: S). DExt n n' => (Substitution e i n -> Substitution e l n') -> Pattern n n' -> Scope n' -> r) -> r

HasDefinitions Context Pattern Sig Source #

A defined name is glued to its value; any other name is a neutral.

Instance details

Methods

contextDefinition :: forall (n :: S). Scope n -> Context n -> Name n -> Value Pattern Sig n

contextUnfolding :: forall (n :: S). Scope n -> Context n -> Value Pattern Sig n -> Value Pattern Sig n -> Value Pattern Sig n

contextGlueSpeculation :: forall (n :: S). Scope n -> Context n -> Name n -> Value Pattern Sig n -> Name n -> Value Pattern Sig n -> GlueSpeculation Context n

contextUnfoldGlued :: forall (n :: S). Scope n -> Context n -> Name n -> Value Pattern Sig n -> Maybe (Context n)

Show (Sig () ()) Source # 
Instance details

Methods

showsPrec :: Int -> Sig () () -> ShowS #

show :: Sig () () -> String #

showList :: [Sig () ()] -> ShowS #