/**
  * Variance from sample function values - iterative operator
  * vari(i,m,n,f(i),b) --> var f(i) from i=m to i=n by delta
  * i - index (argument)
  * m, n - numbers or expressions
  * f(i) - function string
  * by delta
  *
  * @param      pos                 the token position
  */
 private void VAR(int pos)
 {
     IterativeOperatorParameters iterParams = new IterativeOperatorParameters(getFunctionParameters(pos, tokensList));
     ArgumentParameter index = getParamArgument(iterParams.indexParam.paramStr);
     updateMissingTokens(index, iterParams);
     evalFromToDeltaParameters(index, iterParams);
     double var = Statistics.var(iterParams.funExp, index.argument, iterParams.from, iterParams.to, iterParams.delta);
     clearParamArgument(index);
     calcSetDecreaseRemove(pos, var, true);
 }
 /**
  * Summation operator (SIGMA by)
  * sum(i,m,n,f(i),b) --> sum f(i) from i=m to i=n by delta
  * i - index (argument)
  * m, n - numbers or expressions
  * f(i) - function string
  * by delta
  *
  * @param      pos                 the token position
  */
 private void SUM(int pos)
 {
     IterativeOperatorParameters iterParams = new IterativeOperatorParameters(getFunctionParameters(pos, tokensList));
     ArgumentParameter index = getParamArgument(iterParams.indexParam.paramStr);
     updateMissingTokens(index, iterParams);
     evalFromToDeltaParameters(index, iterParams);
     double sigma = NumberTheory.sigmaSummation(iterParams.funExp, index.argument, iterParams.from, iterParams.to, iterParams.delta);
     clearParamArgument(index);
     calcSetDecreaseRemove(pos, sigma, true);
 }
 /**
  * Update missing tokens in expression related
  * to iterative operators.
  *
  * @param index      Index parameter of the iterative operator
  * @param iterParams     Parameters list of the iterative operator
  */
 private void updateMissingTokens(ArgumentParameter index, IterativeOperatorParameters iterParams)
 {
     if (index.presence == Argument.NOT_FOUND) {
         updateMissingTokens(iterParams.indexParam.tokens, iterParams.indexParam.paramStr, index.index, Argument.TYPE_ID);
         updateMissingTokens(iterParams.fromParam.tokens, iterParams.indexParam.paramStr, index.index, Argument.TYPE_ID);
         updateMissingTokens(iterParams.toParam.tokens, iterParams.indexParam.paramStr, index.index, Argument.TYPE_ID);
         updateMissingTokens(iterParams.funParam.tokens, iterParams.indexParam.paramStr, index.index, Argument.TYPE_ID);
     }
 }
 /**
  * Evaluates ranges 'from', 'to', 'delta' for the iterative operator
  *
  * @param index      Index parameter of the iterative operator
  * @param iterParams     Parameters list of the iterative operator
  */
 private void evalFromToDeltaParameters(ArgumentParameter index, IterativeOperatorParameters iterParams)
 {
     /*
      * Create from, to, fun expression
      * based on the from string
      *    expressions will use the same arguments list
      *    as used in the main expression (this.argumentsList)
      */
     iterParams.fromExp = new Expression(iterParams.fromParam.paramStr, iterParams.fromParam.tokens, argumentsList, functionsList, constantsList, KEEP_ULP_ROUNDING_SETTINGS);
     iterParams.toExp = new Expression(iterParams.toParam.paramStr, iterParams.toParam.tokens, argumentsList, functionsList, constantsList, KEEP_ULP_ROUNDING_SETTINGS);
     iterParams.funExp = new Expression(iterParams.funParam.paramStr, iterParams.funParam.tokens, argumentsList, functionsList, constantsList, DISABLE_ULP_ROUNDING);
     iterParams.deltaExp = null;
     if (verboseMode == true) {
         iterParams.fromExp.setVerboseMode();
         iterParams.toExp.setVerboseMode();
         iterParams.funExp.setVerboseMode();
     }
     /*
      * Evaluate range
      */
     iterParams.from = iterParams.fromExp.calculate();
     iterParams.to = iterParams.toExp.calculate();
     iterParams.delta = 1;
     if (iterParams.to < iterParams.from) iterParams.delta = -1;
     if (iterParams.withDelta == true) {
         iterParams.deltaExp = new Expression(iterParams.deltaParam.paramStr, iterParams.deltaParam.tokens, argumentsList, functionsList, constantsList, DISABLE_ULP_ROUNDING);
         if (index.presence == Argument.NOT_FOUND) {
             updateMissingTokens(iterParams.deltaParam.tokens, iterParams.indexParam.paramStr, index.index, Argument.TYPE_ID);
         }
         if (verboseMode == true)
             iterParams.deltaExp.setVerboseMode();
         iterParams.delta = iterParams.deltaExp.calculate();
     }
 }