Kernel.DtreeSourcetype dtree_error = | HeadSymbolMismatch of Basic.loc * Basic.name * Basic.name| ArityInnerMismatch of Basic.loc * Basic.ident * Basic.ident| ACSymbolRewritten of Basic.loc * Basic.name * inttype miller_var = {arity : int;Arity of the meta variable
*)depth : int;Depth under which this occurence of the meta variable is considered
*)vars : int list;The list of local DB indices of argument variables
*)mapping : int array;The mapping from all local DB indices for either -1 or position in the list of argument variables (starting from the end)
*)}This represent a meta variables applied to distinct locally bounded variables: X x_1 ... x_n.
arity is the number of argumentsdepth is the number of locally bounded variables availablevars is the list of successive arguments in ordermapping is a mapping for all available bounded variable n tovars listThe following invariants should therefore be verified:
arity is the length of varsdepth is the length of mappingvars are between 0 and depth-1mapping are between 0 and arity-1mapping.(i) = n >= 0 iff List.nth vars (arity-n-1) = iarity elements of mapping are non negativeAn example: { arity = 2; depth = 5; vars = 4; 2; mapping = | (-1) ; (-1) ; 0 ; (-1) ; 1 | }
mapping_of_vars depth arity vars build a reverse mapping from the list vars of DB indices arguments of a Miller variable. For instance the pattern x => y => z => F y x produces a call to mapping_of_vars 3 2 [1; 0] which returns the array | 1 ; 0 ; (-1) |
Abstract matching problems. This can be instantiated with
'a = int refers to positions in the stack'a = term Lazy.t refers to actual terms(vars, matched) is the higher order equational problem: X x1 ... xn = matched with vars=[ x1 ; ... ; xn ]
(n, vars) represents the n-th variable applied to the vars bound variables.
(depth, symb, njoks, vars, terms) Represents the flattenned equality under AC symbol symb of:
njoks jokers and the given variables varsterms e.g. +{ X[x] , _, Y[y,z] } = +{ f(a), f(y), f(x)} the depth field in all elements of vars should be equal to depth FIXME: do we need depth here then ?type pre_matching_problem = {pm_eq_problems : int eq_problem list Basic.LList.t;For each variable of a rewrite rule (array), a list of equational problems under various depths
*)pm_ac_problems : int ac_problem list;A list of AC-matching problems under a certain depth
*)pm_arity : int array;Constant time access to a variable's arity
*)}A problem with int indices referencing positions in the stack
int matching problem printing function (for dtree).
type case = | CConst of int * Basic.name * bool(size,name,ac) where size is the number of arguments expected for the constant c and ac is true iff the constant is a definable AC(U) symbol.
| CDB of int * int(size,db_index) where size is the number of *static* arguments expected for the bounded variable db_index
| CLamA lambda headed term
*)Arguments of a pattern may be the following:
type atomic_problem = {a_pos : int;position of the term to match in the stack.
*)a_depth : int;depth of the argument regarding absractions
*)a_args : int array;Arguments DB indices (distinct bound variables)
*)}An atomic matching problem. stack.(pos) ~? X DB(args_0), ..., DB(args_n) where X is the variable and the problem is considered under depth abstractions.
A matching problem to build a solution context from the stack
type dtree = | Switch of int * (case * dtree) list * dtree optionSwitch i [(case_0,tree_0) ; ... ; (case_n, tree_n)] default_tree tests whether the i-th argument in the stack matches with one of the given cases. If it does then proceed with the corresponding tree Otherwise, branch to the given default tree.
| Test of Rule.rule_name
* pre_matching_problem
* Rule.constr list
* Term.term
* dtree optionTest name pb cstrs rhs default_tree are the leaves of the tree. Checks that each problem can be solved such that constraints are satisfied. If it does then return a local context for the term rhs.
| Fetch of int * case * dtree * dtree optionFetch i case tree_suc tree_def assumes the i-th argument of a pattern is a * flattened AC symbols and checks that it contains a term that can be matched with the given * case. * If so then look at the corresponding tree, otherwise/afterwise, look at the default tree
| ACEmpty of int * dtree * dtree optionACEmpty i tree_suc tree_def assumes the i-th argument of a pattern is a * flattened AC symbols and checks that it is now empty.
Type of decision trees
Type mapping arities to decision trees (also called "forest")
find_dtree ar forest returns a pair (arity,dtree) in given forest such that arity <= ar. Returns None when not found.
Printer for a single decision tree.
Printer for forests of decision trees.
Compilation of rewrite rules into decision trees. Returns a list of arities and corresponding decision trees. Invariant : arities must be sorted in decreasing order. (see use case in state_whnf in reduction.ml) May raise Dtree_error.