  
  [1X8 [33X[0;0YManaging Derived Methods[133X[101X
  
  
  [1X8.1 [33X[0;0YInfo Class[133X[101X
  
  [1X8.1-1 DerivationInfo[101X
  
  [29X[2XDerivationInfo[102X[32X info class
  
  [33X[0;0YInfo class for derivations.[133X
  
  [1X8.1-2 ActivateDerivationInfo[101X
  
  [29X[2XActivateDerivationInfo[102X( [3Xarg[103X ) [32X function
  
  [1X8.1-3 DeactivateDerivationInfo[101X
  
  [29X[2XDeactivateDerivationInfo[102X( [3Xarg[103X ) [32X function
  
  
  [1X8.2 [33X[0;0YDerivation Objects[133X[101X
  
  [1X8.2-1 IsDerivedMethod[101X
  
  [29X[2XIsDerivedMethod[102X( [3Xarg[103X ) [32X filter
  [6XReturns:[106X  [33X[0;10Y[10Xtrue[110X or [10Xfalse[110X[133X
  
  [33X[0;0YA  derivation  object  describes  a  derived method. It contains information
  about  which  operation  the  derived  method  implements,  and  which other
  operations it relies on.[133X
  
  [1X8.2-2 MakeDerivation[101X
  
  [29X[2XMakeDerivation[102X( [3Xname[103X, [3Xtarget_op[103X, [3Xused_ops_with_multiples[103X, [3Xweight[103X, [3Ximplementations_with_extra_filters[103X, [3Xcategory_filter[103X ) [32X operation
  
  [33X[0;0YCreates a new derivation object. The argument [3Xname[103X is an arbitrary name used
  to  identify this derivation, and is useful only for debugging purposes. The
  argument [3Xtarget_op[103X is the operation which the derived method implements. The
  argument [3Xused_ops_with_multiples[103X contains each operation used by the derived
  method,  together  with  a  positive  integer specifying how many times that
  operation  is used. This is given as a list of lists, where each sublist has
  as  first  entry  an  operation and as second entry an integer. The argument
  [3Xweight[103X  is an additional number to add when calculating the resulting weight
  of  the  target  operation  using  this  derivation.  Unless  there  is  any
  particular  reason  to  regard the derivation as exceedingly expensive, this
  number should be [10X1[110X. The argument [3Ximplementations_with_extra_filters[103X contains
  one  or more functions with the actual implementation of the derived method,
  together  with  lists  of  extra  argument  filters  for  each function. The
  argument  is  a list with entries of the form [10X[fun, filters][110X, where [10Xfun[110X is a
  function  and [10Xfilters[110X is a (not necessarily dense) list of argument filters.
  If  only  one  function  is given, then [10Xfilters[110X should be the empty list; in
  this  case  the  argument's  value  would  be  [[fun,[]]],  where [10Xfun[110X is the
  function.   The  argument  [3Xcategory_filter[103X  is  a  filter  describing  which
  categories  the  derivation is valid for. If it is valid for all categories,
  then this argument should have the value [10XIsCapCategory[110X.[133X
  
  [1X8.2-3 DerivationName[101X
  
  [29X[2XDerivationName[102X( [3Xd[103X ) [32X attribute
  
  [33X[0;0YThe  name  of  the  derivation.  This  is a name identifying this particular
  derivation,  and  normally  not  the  same  as  the  name  of  the operation
  implemented by the derivation.[133X
  
  [1X8.2-4 DerivationWeight[101X
  
  [29X[2XDerivationWeight[102X( [3Xd[103X ) [32X attribute
  
  [33X[0;0YExtra weight for the derivation.[133X
  
  [1X8.2-5 DerivationFunctionsWithExtraFilters[101X
  
  [29X[2XDerivationFunctionsWithExtraFilters[102X( [3Xd[103X ) [32X attribute
  
  [33X[0;0YThe  implementation(s)  of  the  derivation,  together  with  lists of extra
  filters for each implementation.[133X
  
  [1X8.2-6 CategoryFilter[101X
  
  [29X[2XCategoryFilter[102X( [3Xd[103X ) [32X attribute
  
  [33X[0;0YFilter describing which categories the derivation is valid for.[133X
  
  [1X8.2-7 IsApplicableToCategory[101X
  
  [29X[2XIsApplicableToCategory[102X( [3Xd[103X, [3XC[103X ) [32X operation
  [6XReturns:[106X  [33X[0;10Y[10Xtrue[110X  if the category [3XC[103X is known to satisfy the category filter of
            the derivation [3Xd[103X.[133X
  
  [33X[0;0YChecks if the derivation is known to be valid for a given category.[133X
  
  [1X8.2-8 TargetOperation[101X
  
  [29X[2XTargetOperation[102X( [3Xd[103X ) [32X attribute
  [6XReturns:[106X  [33X[0;10YThe  name  (as  a  string)  of  the  operation  implemented by the
            derivation [3Xd[103X[133X
  
  [1X8.2-9 UsedOperations[101X
  
  [29X[2XUsedOperations[102X( [3Xd[103X ) [32X attribute
  [6XReturns:[106X  [33X[0;10YThe names (as strings) of the operations used by the derivation [3Xd[103X[133X
  
  [1X8.2-10 UsedOperationMultiples[101X
  
  [29X[2XUsedOperationMultiples[102X( [3Xd[103X ) [32X attribute
  [6XReturns:[106X  [33X[0;10YMultiplicities  of  each  operation  used  by the derivation [3Xd[103X, in
            order   corresponding   to   the   operation   names  returned  by
            [10XUsedOperations(d)[110X.[133X
  
  [1X8.2-11 UsedOperationsWithMultiples[101X
  
  [29X[2XUsedOperationsWithMultiples[102X( [3Xd[103X ) [32X attribute
  [6XReturns:[106X  [33X[0;10YThe  names  of  the  operations used by the derivation [3Xd[103X, together
            with  their  multiplicities.  The  result  is a list consisting of
            lists  of  the form [10X[op_name, mult][110X, where [10Xop_name[110X is a string and
            [10Xmult[110X a positive integer.[133X
  
  [1X8.2-12 InstallDerivationForCategory[101X
  
  [29X[2XInstallDerivationForCategory[102X( [3Xd[103X, [3Xweight[103X, [3XC[103X ) [32X operation
  
  [33X[0;0YInstall  the  derived method [3Xd[103X for the category [3XC[103X. The integer [3Xweight[103X is the
  computed weight of the operation implemented by this derivation.[133X
  
  [1X8.2-13 DerivationResultWeight[101X
  
  [29X[2XDerivationResultWeight[102X( [3Xd[103X, [3Xop_weights[103X ) [32X operation
  
  [33X[0;0YComputes  the  resulting  weight  of the target operation of this derivation
  given  a list of weights for the operations it uses. The argument [3Xop_weights[103X
  should  be a list of integers specifying weights for the operations given by
  [10XUsedOperations( d )[110X, in the same order.[133X
  
  
  [1X8.3 [33X[0;0YDerivation Graphs[133X[101X
  
  [1X8.3-1 IsDerivedMethodGraph[101X
  
  [29X[2XIsDerivedMethodGraph[102X( [3Xarg[103X ) [32X filter
  [6XReturns:[106X  [33X[0;10Y[10Xtrue[110X or [10Xfalse[110X[133X
  
  [33X[0;0YA  derivation graph consists of a set of operations and a set of derivations
  specifying  how  some  operations  can  be  implemented  in  terms  of other
  operations.[133X
  
  [1X8.3-2 MakeDerivationGraph[101X
  
  [29X[2XMakeDerivationGraph[102X( [3Xoperations[103X ) [32X operation
  
  [33X[0;0YMake  a  derivation  graph  containing  the  given  set of operations and no
  derivations.  The argument [3Xoperations[103X should be a list of strings, the names
  of the operations. The set of operations is fixed once the graph is created.
  Derivations can be added to the graph by calling [10XAddDerivation[110X.[133X
  
  [1X8.3-3 AddOperationsToDerivationGraph[101X
  
  [29X[2XAddOperationsToDerivationGraph[102X( [3Xgraph[103X, [3Xoperations[103X ) [32X operation
  
  [33X[0;0YAdds a list of operation names [3Xoperations[103X to a given derivation graph [3Xgraph[103X.
  This  is  used  in  extensions of CAP which want to have their own primitive
  operations,  but  do not want to pollute the CAP kernel any more. Please use
  it with caution. If a weight list/category was created before it will not be
  aware of the operations.[133X
  
  [1X8.3-4 AddDerivation[101X
  
  [29X[2XAddDerivation[102X( [3XG[103X, [3Xd[103X ) [32X operation
  
  [33X[0;0YAdd a derivation to a derivation graph.[133X
  
  [1X8.3-5 AddDerivation[101X
  
  [29X[2XAddDerivation[102X( [3Xarg1[103X, [3Xarg2[103X, [3Xarg3[103X, [3Xarg4[103X ) [32X operation
  
  [1X8.3-6 AddDerivation[101X
  
  [29X[2XAddDerivation[102X( [3Xarg1[103X, [3Xarg2[103X, [3Xarg3[103X ) [32X operation
  
  [1X8.3-7 AddDerivation[101X
  
  [29X[2XAddDerivation[102X( [3Xarg1[103X, [3Xarg2[103X, [3Xarg3[103X ) [32X operation
  
  [1X8.3-8 AddDerivationPair[101X
  
  [29X[2XAddDerivationPair[102X( [3Xarg1[103X, [3Xarg2[103X, [3Xarg3[103X, [3Xarg4[103X, [3Xarg5[103X, [3Xarg6[103X ) [32X operation
  
  [1X8.3-9 AddDerivationPair[101X
  
  [29X[2XAddDerivationPair[102X( [3Xarg1[103X, [3Xarg2[103X, [3Xarg3[103X, [3Xarg4[103X, [3Xarg5[103X ) [32X operation
  
  [1X8.3-10 AddDerivationPair[101X
  
  [29X[2XAddDerivationPair[102X( [3Xarg1[103X, [3Xarg2[103X, [3Xarg3[103X, [3Xarg4[103X, [3Xarg5[103X, [3Xarg6[103X ) [32X operation
  
  [1X8.3-11 AddDerivationPair[101X
  
  [29X[2XAddDerivationPair[102X( [3Xarg1[103X, [3Xarg2[103X, [3Xarg3[103X, [3Xarg4[103X, [3Xarg5[103X ) [32X operation
  
  [1X8.3-12 AddDerivationToCAP[101X
  
  [29X[2XAddDerivationToCAP[102X( [3Xarg[103X ) [32X function
  
  [1X8.3-13 AddDerivationPairToCAP[101X
  
  [29X[2XAddDerivationPairToCAP[102X( [3Xarg[103X ) [32X function
  
  [1X8.3-14 AddWithGivenDerivationPairToCAP[101X
  
  [29X[2XAddWithGivenDerivationPairToCAP[102X( [3Xarg[103X ) [32X function
  
  [1X8.3-15 Operations[101X
  
  [29X[2XOperations[102X( [3XG[103X ) [32X attribute
  
  [33X[0;0YGives the operations in the graph [3XG[103X, as a list of strings.[133X
  
  [1X8.3-16 DerivationsUsingOperation[101X
  
  [29X[2XDerivationsUsingOperation[102X( [3XG[103X, [3Xop_name[103X ) [32X operation
  
  [33X[0;0YFinds  all  the  derivations  in  the  graph  [3XG[103X that use the operation named
  [3Xop_name[103X, and returns them as a list.[133X
  
  [1X8.3-17 DerivationsOfOperation[101X
  
  [29X[2XDerivationsOfOperation[102X( [3XG[103X, [3Xop_name[103X ) [32X operation
  
  [33X[0;0YFinds  all  the  derivations  in  the  graph [3XG[103X targeting the operation named
  [3Xop_name[103X  (that  is,  the  derivations  that  provide implementations of this
  operation), and returns them as a list.[133X
  
  
  [1X8.4 [33X[0;0YManaging Derivations in a Category[133X[101X
  
  [1X8.4-1 IsOperationWeightList[101X
  
  [29X[2XIsOperationWeightList[102X( [3Xarg[103X ) [32X filter
  [6XReturns:[106X  [33X[0;10Y[10Xtrue[110X or [10Xfalse[110X[133X
  
  [33X[0;0YAn operation weight list manages the use of derivations in a single category
  [23XC[123X.  For  every operation, it keeps a weight value which indicates how costly
  it  is to perform that operation in the category [23XC[123X. Whenever a new operation
  is implemented in [23XC[123X, the operation weight list should be notified about this
  and  given  a weight to assign to this operation. It will then automatically
  install  all  possible  derived  methods  for  [23XC[123X  in  such  a way that every
  operation  has  the smallest possible weight (the weight of a derived method
  is   computed   by  using  the  weights  of  the  operations  it  uses;  see
  [10XDerivationResultWeight[110X).[133X
  
  [1X8.4-2 MakeOperationWeightList[101X
  
  [29X[2XMakeOperationWeightList[102X( [3XC[103X, [3XG[103X ) [32X operation
  
  [33X[0;0YCreate  the  operation  weight list for a category. This should only be done
  once  for  every  category,  and the category should afterwards remember the
  returned  object.  The  argument [3XC[103X is the CAP category this operation weight
  list  is  associated to, and the argument [3XG[103X is a derivation graph containing
  operation names and derivations.[133X
  
  [1X8.4-3 DerivationGraph[101X
  
  [29X[2XDerivationGraph[102X( [3Xowl[103X ) [32X attribute
  
  [33X[0;0YReturns the derivation graph used by the operation weight list [3Xowl[103X.[133X
  
  [1X8.4-4 CategoryOfOperationWeightList[101X
  
  [29X[2XCategoryOfOperationWeightList[102X( [3Xowl[103X ) [32X attribute
  
  [33X[0;0YReturns the CAP category associated to the operation weight list [3Xowl[103X.[133X
  
  [1X8.4-5 CurrentOperationWeight[101X
  
  [29X[2XCurrentOperationWeight[102X( [3Xowl[103X, [3Xop_name[103X ) [32X operation
  
  [33X[0;0YReturns the current weight of the operation named [3Xop_name[103X.[133X
  
  [1X8.4-6 OperationWeightUsingDerivation[101X
  
  [29X[2XOperationWeightUsingDerivation[102X( [3Xowl[103X, [3Xd[103X ) [32X operation
  
  [33X[0;0YFinds  out  what the weight of the operation implemented by the derivation [3Xd[103X
  would be if we had used that derivation.[133X
  
  [1X8.4-7 DerivationOfOperation[101X
  
  [29X[2XDerivationOfOperation[102X( [3Xowl[103X, [3Xop_name[103X ) [32X operation
  
  [33X[0;0YReturns  the  derivation  which is currently used to implement the operation
  named [3Xop_name[103X. If the operation is not implemented by a derivation (that is,
  either  implemented  directly  or  not  implemented  at  all),  then [10Xfail[110X is
  returned.[133X
  
  [1X8.4-8 InstallDerivationsUsingOperation[101X
  
  [29X[2XInstallDerivationsUsingOperation[102X( [3Xowl[103X, [3Xop_name[103X ) [32X operation
  
  [33X[0;0YPerforms  a  search from the operation [3Xop_name[103X, and installs all derivations
  that  give  improvements  over the current state. This is used internally by
  [10XAddPrimitiveOperation[110X and [10XReevaluate[110X. It should normally not be necessary to
  call this function directly.[133X
  
  [1X8.4-9 Reevaluate[101X
  
  [29X[2XReevaluate[102X( [3Xowl[103X ) [32X operation
  
  [33X[0;0YReevaluate  the  installed  derivations,  installing  better  derivations if
  possible.  This should be called if new derivations become available for the
  category,  either  because  the  category  has acquired more knowledge about
  itself  (e.g. it is told that it is abelian) or because new derivations have
  been added to the graph.[133X
  
  [1X8.4-10 AddPrimitiveOperation[101X
  
  [29X[2XAddPrimitiveOperation[102X( [3Xowl[103X, [3Xop_name[103X, [3Xweight[103X ) [32X operation
  
  [33X[0;0YAdd the operation named [3Xop_name[103X to the operation weight list [3Xowl[103X with weight
  [3Xweight[103X.  This  causes  all  operations  that  can  be  derived,  directly or
  indirectly,  from  the newly added operation to be installed as well (unless
  they are already installed with the same or lower weight).[133X
  
  [1X8.4-11 PrintDerivationTree[101X
  
  [29X[2XPrintDerivationTree[102X( [3Xowl[103X, [3Xop_name[103X ) [32X operation
  
  [33X[0;0YPrint  a  tree  representation  of  the  way  the operation named [3Xop_name[103X is
  implemented in the category of the operation weight list [3Xowl[103X.[133X
  
  [1X8.4-12 PrintTree[101X
  
  [29X[2XPrintTree[102X( [3Xarg1[103X, [3Xarg2[103X, [3Xarg3[103X ) [32X operation
  
  [33X[0;0YPrints a tree structure.[133X
  
  [1X8.4-13 PrintTreeRec[101X
  
  [29X[2XPrintTreeRec[102X( [3Xarg1[103X, [3Xarg2[103X, [3Xarg3[103X, [3Xarg4[103X ) [32X operation
  
  
  [1X8.5 [33X[0;0YMin Heaps for Strings[133X[101X
  
  [33X[0;0YThis  section  describes  an implementation of min heaps for storing strings
  with associated integer keys, used internally by operation weight lists.[133X
  
  [1X8.5-1 IsStringMinHeap[101X
  
  [29X[2XIsStringMinHeap[102X( [3Xarg[103X ) [32X filter
  [6XReturns:[106X  [33X[0;10Y[10Xtrue[110X or [10Xfalse[110X[133X
  
  [33X[0;0YA string min heap is a min heap where every node contains a string label and
  an integer key.[133X
  
  [1X8.5-2 StringMinHeap[101X
  
  [29X[2XStringMinHeap[102X( [3Xarg[103X ) [32X function
  
  [33X[0;0YCreate an empty string min heap.[133X
  
  [1X8.5-3 Add[101X
  
  [29X[2XAdd[102X( [3XH[103X, [3Xstring[103X, [3Xkey[103X ) [32X operation
  
  [33X[0;0YAdd a new node containing the label [3Xstring[103X and the key [3Xkey[103X to the heap [3XH[103X.[133X
  
  [1X8.5-4 ExtractMin[101X
  
  [29X[2XExtractMin[102X( [3XH[103X ) [32X operation
  
  [33X[0;0YRemove  a  node  with  minimal key value from the heap [3XH[103X, and return it. The
  return  value  is a list [10X[ label, key ][110X, where [10Xlabel[110X is the extracted node's
  label (a string) and [10Xkey[110X is the node's key (an integer).[133X
  
  [1X8.5-5 DecreaseKey[101X
  
  [29X[2XDecreaseKey[102X( [3XH[103X, [3Xstring[103X, [3Xkey[103X ) [32X operation
  
  [33X[0;0YDecrease the key value for the node with label [3Xstring[103X in the heap [3XH[103X. The new
  key value is given by [3Xkey[103X and must be smaller than the node's current value.[133X
  
  [1X8.5-6 IsEmptyHeap[101X
  
  [29X[2XIsEmptyHeap[102X( [3XH[103X ) [32X operation
  
  [33X[0;0YReturns [10Xtrue[110X if the heap [3XH[103X is empty, [10Xfalse[110X otherwise.[133X
  
  [1X8.5-7 HeapSize[101X
  
  [29X[2XHeapSize[102X( [3XH[103X ) [32X operation
  
  [33X[0;0YReturns the number of nodes in the heap [3XH[103X.[133X
  
  [1X8.5-8 Contains[101X
  
  [29X[2XContains[102X( [3XH[103X, [3Xstring[103X ) [32X operation
  
  [33X[0;0YReturns  [10Xtrue[110X  if  the  heap  [3XH[103X contains a node with label [3Xstring[103X, and [10Xfalse[110X
  otherwise.[133X
  
  [1X8.5-9 Swap[101X
  
  [29X[2XSwap[102X( [3XH[103X, [3Xi[103X, [3Xj[103X ) [32X operation
  
  [33X[0;0YSwaps  two  elements in the list used to implement the heap, and updates the
  heap's  internal  mapping  of  labels  to  list indices. This is an internal
  function  which  should only be called from the functions that implement the
  heap functionality.[133X
  
  [1X8.5-10 Heapify[101X
  
  [29X[2XHeapify[102X( [3XH[103X, [3Xi[103X ) [32X operation
  
  [33X[0;0YHeapify the heap [3XH[103X, starting from index [3Xi[103X. This is an internal function.[133X
  
