Agda-2.5.1.2: A dependently typed functional programming language and proof assistant

Agda.TypeChecking.SizedTypes.Solve

Description

Solving size constraints under hypotheses.

The size solver proceeds as follows:

1. Get size constraints, cluster into connected components.

All size constraints that mention the same metas go into the same cluster. Each cluster can be solved by itself.

Constraints that do not fit our format are ignored. We check whether our computed solution fulfills them as well in the last step.

1. Find a joint context for each cluster.

Each constraint comes with its own typing context, which contains size hypotheses j : Size< i. We need to find a common super context in which all constraints of a cluster live, and raise all constraints to this context.

There might not be a common super context. Then we are screwed, since our solver is not ready to deal with such a situation. We will blatantly refuse to solve this cluster and blame it on the user.

1. Convert the joint context into a hypothesis graph.

This is straightforward. Each de Bruijn index becomes a rigid variable, each typing assumption j : Size< i becomes an arc.

1. Convert the constraints into a constraint graph.

Here we need to convert MetaVs into flexible variables.

1. Run the solver
2. Convert the solution into meta instantiations.
3. Double-check whether the constraints are solved.

Synopsis

# Documentation

Flag to control the behavior of size solver.

Constructors

 DefaultToInfty Instantiate all unconstrained size variables to ∞. DontDefaultToInfty Leave unconstrained size variables unsolved.

Instances

 Source # Methods Source # Methods Source # MethodsshowList :: [DefaultToInfty] -> ShowS #

Solve size constraints involving hypotheses.

Collect constraints from a typing context, looking for SIZELT hypotheses.

Convert size constraint into form where each meta is applied to indices n-1,...,1,0 where n is the arity of that meta.

X[σ] <= t becomes X[id] <= t[σ^-1]

X[σ] ≤ Y[τ] becomes X[id] ≤ Y[τ[σ^-1]] or X[σ[τ^1]] ≤ Y[id] whichever is defined. If none is defined, we give up.

Cf. SizedTypes.oldCanonicalizeSizeConstraint.

Fixes (the rather artificial) issue 300. But it is unsound when pruned metas occur and triggers issue 1914. Thus we deactivate it. This needs to be properly implemented, possibly using the metaPermuatation of each meta variable.

Identifiers for rigid variables.

Constructors

 NamedRigid FieldsrigidName :: StringName for printing in debug messages.rigidIndex :: IntDe Bruijn index.

Instances

 Source # Methods Source # Methods Source # MethodsshowList :: [NamedRigid] -> ShowS # Source # Assumes we are in the right context. Methods Source # Methods Source # Methods Source # Only for raise. Methods

data SizeMeta Source #

Size metas in size expressions.

Constructors

 SizeMeta FieldssizeMetaId :: MetaId sizeMetaArgs :: [Int]De Bruijn indices.

Instances

 Source # An equality which ignores the meta arguments. Methods Source # An order which ignores the meta arguments. Methods(<) :: SizeMeta -> SizeMeta -> Bool #(>) :: SizeMeta -> SizeMeta -> Bool # Source # MethodsshowList :: [SizeMeta] -> ShowS # Source # Assumes we are in the right context. Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Only for raise. Methods

Size expression with de Bruijn indices.

Size constraint with de Bruijn indices.

Constructors

 HypSizeConstraint FieldssizeContext :: Context sizeHypIds :: [CtxId] sizeHypotheses :: [SizeConstraint]Living in Context.sizeConstraint :: SizeConstraintLiving in Context.

Instances

 Source # Methods Source # Methods

Turn a constraint over de Bruijn indices into a size constraint.

Turn a term into a size expression.

Returns Nothing if the term isn't a proper size expression.

Turn a de size expression into a term.