Class RecursiveArgument


  • public class RecursiveArgument
    extends Argument
    RecursiveArgument class enables to declare the argument (variable) which is defined in a recursive way. Such an argument can be used in further processing in expressions, functions and dependent or recursive arguments.
    For example:
    • 'fib(n) = fin(n-1)+fib(n-2), fib(0) = 0, fib(1) = 1'
    • 'factorial(n) = n*factorial(n-1), factorial(0) = 1'

    When creating an argument you should avoid:

    • names reserved as parser keywords, in general words known in mathematical language as function names, operators (for example: sin, cos, +, -, etc...). Please be informed that after associating the argument with the expression, function or dependent/recursive argument its name will be recognized by the parser as reserved key word. It means that it could not be the same as any other key word known by the parser for this particular expression.
    • defining statements with increasing index: 'a(n) = a(n+1) + ... ', otherwise you will get Double.NaN
    • if recursion is not properly defined you will get Double.NaN in the result. This is due to the recursion counter inside of the recursive argument. Calculating n-th element requires no more than n recursion steps (usually less than n).
    • For negative 'n' you will get Double.NaN.
    Version:
    5.0.0
    Author:
    Mariusz Gromada
    MathParser.org - mXparser project page
    mXparser on GitHub
    INFIMA place to purchase a commercial MathParser.org-mXparser software license
    info@mathparser.org
    ScalarMath.org - a powerful math engine and math scripting language
    Scalar Lite
    Scalar Pro
    MathSpace.pl

    Buy me a cup of coffee via donation

    Did you find the software useful? Please consider donation

    or support me purchasing the license via ORDER Page , or INFIMA online store


    INFIMA online store
    See Also:
    Argument, Expression, Function, Constant
    • Constructor Detail

      • RecursiveArgument

        public RecursiveArgument​(String argumentName,
                                 String recursiveExpressionString,
                                 String indexName)
        Constructor - creates recursive argument.
        Parameters:
        argumentName - the argument name
        recursiveExpressionString - the recursive expression string
        indexName - index argument name
      • RecursiveArgument

        public RecursiveArgument​(String argumentName,
                                 String recursiveExpressionString,
                                 Argument n,
                                 PrimitiveElement... elements)
        Constructor - creates recursive argument.
        Parameters:
        argumentName - the argument name
        recursiveExpressionString - the recursive expression string
        n - the index argument
        elements - Optional elements list (variadic - comma separated) of types: Argument, Constant, Function
        See Also:
        PrimitiveElement, Argument
      • RecursiveArgument

        public RecursiveArgument​(String argumentDefinitionString,
                                 PrimitiveElement... elements)
        Constructor - creates argument based on the argument definition string.
        Parameters:
        argumentDefinitionString - Argument definition string, i.e.:
        • 'x' - only argument name
        • 'x=5' - argument name and argument value
        • 'x=2*5' - argument name and argument value given as simple expression
        • 'x=2*y' - argument name and argument expression (dependent argument 'x' on argument 'y')
        • 'x(n)=x(n-1)+x(n-2)' - for recursive arguments)
        elements - Optional elements list (variadic - comma separated) of types: Argument, Constant, Function
        See Also:
        PrimitiveElement, Argument
    • Method Detail

      • addBaseCase

        public void addBaseCase​(int index,
                                double value)
        Adds base case
        Parameters:
        index - the base case index
        value - the base case value
      • resetAllCases

        public void resetAllCases()
        Clears all based cases and stored calculated values
      • getArgumentValue

        public double getArgumentValue​(double index)
        Gets recursive argument value
        Parameters:
        index - the index
        Returns:
        value as double