Class ASTRealVector

  • All Implemented Interfaces:
    edu.jas.structure.AbelianGroupElem<IExpr>, edu.jas.structure.Element<IExpr>, edu.jas.structure.GcdRingElem<IExpr>, edu.jas.structure.MonoidElem<IExpr>, edu.jas.structure.RingElem<IExpr>, Externalizable, Serializable, Cloneable, Comparable<IExpr>, Iterable<IExpr>, RandomAccess, org.hipparchus.CalculusFieldElement<IExpr>, org.hipparchus.FieldElement<IExpr>, IAST, IASTMutable, IExpr, ITensorAccess

    public class ASTRealVector
    extends AbstractAST
    implements Externalizable, RandomAccess
    Immutable (A)bstract (S)yntax (T)ree of a given function with no argument.

    In Symja, an abstract syntax tree (AST), is a tree representation of the abstract syntactic structure of the Symja source code. Each node of the tree denotes a construct occurring in the source code. The syntax is 'abstract' in the sense that it does not represent every detail that appears in the real syntax. For instance, grouping parentheses are implicit in the tree structure, and a syntactic construct such as a Sin[x] expression will be denoted by an AST with 2 nodes. One node for the header Sin and one node for the argument x. Internally an AST is represented as a java.util.List which contains

    • the operator of a function (i.e. the "header"-symbol: Sin, Cos, Inverse, Plus, Times,...) at index 0 and
    • the n arguments of a function in the index 1 to n
    See Abstract syntax tree.
    See Also:
    AST, Serialized Form
    • Constructor Detail

      • ASTRealVector

        public ASTRealVector()
      • ASTRealVector

        public ASTRealVector​(double[] vector,
                             boolean deepCopy)
        Parameters:
        vector -
        deepCopy - if true allocate new memory and copy all elements from the vector
      • ASTRealVector

        public ASTRealVector​(org.hipparchus.linear.RealVector vector,
                             boolean deepCopy)
        Parameters:
        vector - the vector which should be wrapped in this object.
        deepCopy - if true allocate new memory and copy all elements from the vector
    • Method Detail

      • map

        public static ASTRealVector map​(IAST astVector,
                                        DoubleUnaryOperator function)
        Returns a new ASTRealVector where each element is mapped by the given function.
        Parameters:
        astVector - an AST which could be converted into double[]
        function - Function to apply to each entry.
        Returns:
        a new vector.
      • arg1

        public IExpr arg1()
        Get the first argument (i.e. the second element of the underlying list structure) of the AST function (i.e. get(1) ).
        Example: for the AST representing the expression Sin(x), arg1() returns x.
        Specified by:
        arg1 in interface IAST
        Returns:
        the first argument of the function represented by this AST.
        See Also:
        IExpr.head()
      • arg2

        public IExpr arg2()
        Get the second argument (i.e. the third element of the underlying list structure) of the AST function (i.e. get(2) ).
        Example: for the AST representing the expression x^y (i.e. Power(x, y)), arg2() returns y.
        Specified by:
        arg2 in interface IAST
        Returns:
        the second argument of the function represented by this AST.
        See Also:
        IExpr.head()
      • arg3

        public IExpr arg3()
        Get the third argument (i.e. the fourth element of the underlying list structure) of the AST function (i.e. get(3) ).
        Example: for the AST representing the expression f(a, b, c), arg3() returns c.
        Specified by:
        arg3 in interface IAST
        Returns:
        the third argument of the function represented by this AST.
        See Also:
        IExpr.head()
      • arg4

        public IExpr arg4()
        Get the fourth argument (i.e. the fifth element of the underlying list structure) of the AST function (i.e. get(4) ).
        Example: for the AST representing the expression f(a, b ,c, d), arg4() returns d.
        Specified by:
        arg4 in interface IAST
        Returns:
        the fourth argument of the function represented by this AST.
        See Also:
        IExpr.head()
      • arg5

        public IExpr arg5()
        Get the fifth argument (i.e. the sixth element of the underlying list structure) of the AST function (i.e. get(5) ).
        Example: for the AST representing the expression f(a, b ,c, d, e), arg5() returns e .
        Specified by:
        arg5 in interface IAST
        Returns:
        the fifth argument of the function represented by this AST.
        See Also:
        IExpr.head()
      • argSize

        public int argSize()
        Returns the number of arguments in this IAST. The number of arguments equals size() - 1 (i.e. the number of elements minus 1). If this is an atom return size -1.
        Specified by:
        argSize in interface IAST
        Specified by:
        argSize in interface IExpr
        Returns:
        the number of arguments in this IAST.
        See Also:
        IExpr.size()
      • asSet

        public Set<IExpr> asSet()
        Description copied from interface: IAST
        Collect all arguments of this AST in a new set.
        Specified by:
        asSet in interface IAST
        Overrides:
        asSet in class AbstractAST
        Returns:
        null if a set couldn't be created
      • clone

        public ASTRealVector clone()
        Returns a new HMArrayList with the same elements, the same size and the same capacity as this HMArrayList.
        Overrides:
        clone in class Object
        Returns:
        a shallow copy of this ArrayList
        See Also:
        Cloneable
      • contains

        public boolean contains​(Object object)
        Tests whether this List contains the specified object.
        Specified by:
        contains in interface IAST
        Overrides:
        contains in class AbstractAST
        Parameters:
        object - the object to search for.
        Returns:
        true if object is an element of this List, false otherwise
      • copy

        public ASTRealVector copy()

        Returns a shallow copy of this IAST instance (the elements themselves are not copied). In contrast to the IAST.copyAppendable() method, this method returns exactly the same type for AST0, AST1, AST2, AST3 and tries to transform AST objects to AST0, AST1, AST2, AST3 if possible.

        Because it's not allowed to set the header object (offset 0) to an arbitrary expression after a copy(), this method should only be used if the arguments (offset 1..argSize) should be set to new expressions.

        Specified by:
        copy in interface edu.jas.structure.Element<IExpr>
        Specified by:
        copy in interface IAST
        Returns:
        a copy of this IAST instance.
      • copyAppendable

        public IASTAppendable copyAppendable()
        Description copied from interface: IAST

        Returns a shallow copy of this IAST instance (the elements themselves are not copied). In contrast to the IAST.copy() method, this method doesn't return exactly the same type for a given AST0, AST1, AST2, AST3... object but transforms it into a new AST object, so that additional arguments could be appended at the end.

        This also allows to set the header object to an arbitrary expression.

        Specified by:
        copyAppendable in interface IAST
        Returns:
        a copy of this IAST instance.
      • copyAppendable

        public IASTAppendable copyAppendable​(int additionalCapacity)
        Description copied from interface: IAST

        Returns a shallow copy of this IAST instance (the elements themselves are not copied). In contrast to the IAST.copy() method, this method doesn't return exactly the same type for a given AST0, AST1, AST2, AST3... object but transforms it into a new AST object, so that additional arguments could be appended at the end.

        This also allows to set the header object to an arbitrary expression.

        Specified by:
        copyAppendable in interface IAST
        Returns:
        a copy of this IAST instance.
      • equals

        public boolean equals​(Object obj)
        Specified by:
        equals in interface edu.jas.structure.Element<IExpr>
        Overrides:
        equals in class AbstractAST
      • evaluate

        public IExpr evaluate​(EvalEngine engine)
        Evaluate an expression
        Specified by:
        evaluate in interface IExpr
        Overrides:
        evaluate in class AbstractAST
        Parameters:
        engine - the evaluation engine
        Returns:
        the evaluated Object or F.NIL if the evaluation is not possible (i.e. the evaluation doesn't change the object).
      • evalEvaluate

        public IExpr evalEvaluate​(EvalEngine engine)
        Description copied from class: AbstractAST
        Evaluate arguments with the head F.Evaluate, i.e. f(a, ... , Evaluate(x), ...)
        Overrides:
        evalEvaluate in class AbstractAST
        Parameters:
        engine - the evaluation engine
        Returns:
      • filterFunction

        public final IAST filterFunction​(IASTAppendable filterAST,
                                         IASTAppendable restAST,
                                         Function<IExpr,​IExpr> function)
        Select all elements by applying the function to each argument in this AST and append the result elements for which the function returns non F.NIL elements to the filterAST, or otherwise append the argument to the restAST.
        Overrides:
        filterFunction in class AbstractAST
        Parameters:
        filterAST - the non F.NIL elements which were returned by the function#apply() method
        restAST - the arguments in this AST for which the function#apply() method returned F.NIL
        function - the function which filters each argument by returning a value which unequals F.NIL
        Returns:
        the given filterAST
      • filter

        public IAST filter​(IASTAppendable filterAST,
                           IASTAppendable restAST,
                           Predicate<? super IExpr> predicate)
        Select all elements by applying the predicate to each argument in this AST and append the elements which satisfy the predicate to the filterAST , or otherwise append it to the restAST.
        Specified by:
        filter in interface IAST
        Overrides:
        filter in class AbstractAST
        Parameters:
        filterAST - the elements where the predicate#apply() method returns true
        restAST - the elements which don't match the predicate
        predicate - the predicate which filters each argument in this AST
        Returns:
        the filterAST
      • filter

        public IAST filter​(IASTAppendable filterAST,
                           Predicate<? super IExpr> predicate)
        Select all elements by applying the predicate to each argument in this AST and append the arguments which satisfy the predicate to the filterAST.
        Specified by:
        filter in interface IAST
        Overrides:
        filter in class AbstractAST
        Parameters:
        filterAST - the elements where the predicate#apply() method returns true
        predicate - the predicate which filters each argument in this AST
        Returns:
        the filterAST
      • get

        public IExpr get​(int location)
        Description copied from interface: IAST
        Returns the element at the specified location in this IAST. If this is an IAssociation return the value of the rule at the specified location.
        Specified by:
        get in interface IAST
        Specified by:
        get in interface ITensorAccess
        Specified by:
        get in class AbstractAST
        Parameters:
        location - the index of the element to return.
        Returns:
        the element at the specified location.
      • getItems

        public IAST getItems​(int[] items,
                             int length)
        Description copied from interface: IAST
        Returns length number of elements specified in the items position array in this IAST.
        Specified by:
        getItems in interface IAST
        Parameters:
        items - ascending ordered array of positions which should be selected from this IAST.
        length - the end position (exclusive) to which the items array is filled with valid element positions
        Returns:
      • getEntry

        public double getEntry​(int location)
      • getRealVector

        public org.hipparchus.linear.RealVector getRealVector()
      • head

        public final IExpr head()
        Description copied from interface: IExpr
        If this object is an instance of IAST get the first element (offset 0) of the IAST list (i.e. #get(0) ). Otherwise return the specific header, i.e. for integer number type => S.Integer, fraction number type => S.Rational, complex number type => S.Complex, ...
        Specified by:
        head in interface IExpr
        Returns:
        the head of the expression, which must not be null.
      • isAST0

        public boolean isAST0()
        Test if this expression is an IAST function, which contains a header element (i.e. the function name) at index position 0 and no argument elements.
        Therefore this expression is no atomic expression.
        Specified by:
        isAST0 in interface IExpr
        Overrides:
        isAST0 in class AbstractAST
        Returns:
        See Also:
        IExpr.isAtom()
      • isAST1

        public boolean isAST1()
        Test if this expression is an IAST function, which contains a header element (i.e. the function name) at index position 0 and one argument element at the index position 1.
        Therefore this expression is no atomic expression.
        Specified by:
        isAST1 in interface IExpr
        Overrides:
        isAST1 in class AbstractAST
        Returns:
        See Also:
        IExpr.isAtom()
      • isAST2

        public boolean isAST2()
        Test if this expression is an IAST function, which contains a header element (i.e. the function name) at index position 0 and two argument elements at the index positions 1, 2.
        Therefore this expression is no atomic expression.
        Specified by:
        isAST2 in interface IExpr
        Overrides:
        isAST2 in class AbstractAST
        Returns:
        See Also:
        IExpr.isAtom()
      • isAST3

        public boolean isAST3()
        Test if this expression is an IAST function, which contains a header element (i.e. the function name) at index position 0 and three argument elements at the index positions 1, 2, 3.
        Therefore this expression is no atomic expression.
        Specified by:
        isAST3 in interface IExpr
        Overrides:
        isAST3 in class AbstractAST
        Returns:
        See Also:
        IExpr.isAtom()
      • isList

        public boolean isList()
        Test if this expression is a list (i.e. an AST with head List)
        Specified by:
        isList in interface IExpr
        Overrides:
        isList in class AbstractAST
        Returns:
      • isNaN

        public boolean isNaN()
        Specified by:
        isNaN in interface org.hipparchus.CalculusFieldElement<IExpr>
      • isRealVector

        public boolean isRealVector()
        Test if this expression is a real vector (i.e. an instance of ASTRealVector or a List[...] with elements of type org.matheclipse.core.expression.Num.
        Specified by:
        isRealVector in interface IExpr
        Overrides:
        isRealVector in class AbstractAST
        Returns:
      • isSameHead

        public boolean isSameHead​(ISymbol head)
        Check if the object at index 0 (i.e. the head of the list) is the same object as head
        Overrides:
        isSameHead in class AbstractAST
        Parameters:
        head - object to compare with element at location 0
        Returns:
      • isSameHead

        public boolean isSameHead​(ISymbol head,
                                  int length)
        Check if the object at index 0 (i.e. the head of the list) is the same object as head and if the size of the list equals length.
        Overrides:
        isSameHead in class AbstractAST
        Parameters:
        head - object to compare with element at location 0
        Returns:
      • isSameHead

        public boolean isSameHead​(ISymbol head,
                                  int minLength,
                                  int maxLength)
        Check if the object at index 0 (i.e. the head of the list) is the same object as head and if the size of the list is between minLength and maxLength .
        Overrides:
        isSameHead in class AbstractAST
        Parameters:
        head - object to compare with element at location 0
        minLength - minimum length of list elements.
        maxLength - maximum length of list elements.
        Returns:
      • isSameHeadSizeGE

        public boolean isSameHeadSizeGE​(ISymbol head,
                                        int length)
        Check if the object at index 0 (i.e. the head of the list) is the same object as head and if the size of the list is greater or equal length.
        Specified by:
        isSameHeadSizeGE in interface IAST
        Specified by:
        isSameHeadSizeGE in interface IExpr
        Parameters:
        head - object to compare with element at location 0
        Returns:
      • isVector

        public final int isVector()
        Test if this expression is a vector and return the length of the vector. This expression is only a vector, if the expression is a ASTRealVector or a List(...) and no element is itself a List(...) or a SparseArray(...) of dimension 1;
        Specified by:
        isVector in interface IExpr
        Overrides:
        isVector in class AbstractAST
        Returns:
        -1 if the expression is no vector or size()-1 of this vector AST.
      • isNumericAST

        public boolean isNumericAST()
        Test if this expression is an IAST and contains at least one numeric argument.
        Specified by:
        isNumericAST in interface IExpr
        Overrides:
        isNumericAST in class AbstractAST
        Returns:
      • isNumericFunction

        public boolean isNumericFunction​(boolean allowList)
        Test if this expression is a numeric function (i.e. a number, a symbolic constant or a function (with attribute NumericFunction) where all arguments are also "numeric functions")
        Specified by:
        isNumericFunction in interface IExpr
        Overrides:
        isNumericFunction in class AbstractAST
        Parameters:
        allowList - if true a List(...) AST is seen, as if it has attribute ISymbol.NUMERICFUNCTION
        Returns:
        true, if the given expression is a numeric function or value.
        See Also:
        IExpr.isRealResult()
      • isNumericMode

        public boolean isNumericMode()
        Test if this expression contains a numeric number (i.e. of type INum or IComplexNum.
        Specified by:
        isNumericMode in interface IExpr
        Overrides:
        isNumericMode in class AbstractAST
        Returns:
        true, if the given expression contains numeric number (i.e. of type INum or IComplexNum.
        See Also:
        IExpr.isRealResult()
      • joinToString

        public void joinToString​(StringBuilder builder,
                                 CharSequence delimiter)
        Append a String composed of the elements of this vector joined together with the specified delimiter.
        Specified by:
        joinToString in interface IAST
        Parameters:
        builder - join the elements as strings
        delimiter - the delimiter that separates each element
      • set

        public IExpr set​(int location,
                         IExpr object)
        Replaces the element at the specified location in this ArrayList with the specified object. Internally the hashValue will be reset to 0.
        Specified by:
        set in interface IASTMutable
        Parameters:
        location - the index at which to put the specified object.
        object - the object to add.
        Returns:
        the previous element at the index.
        Throws:
        IndexOutOfBoundsException - when location < 0 || >= size()
      • setAtCopy

        public IASTMutable setAtCopy​(int i,
                                     IExpr expr)
        Description copied from interface: IAST
        Create a shallow copy of this IAST instance (the elements themselves are not copied) and set the expr at the given position. In contrast to the setAtClone() method, this method returns exactly the same type for AST0, AST1, AST2, AST3.
        Specified by:
        setAtCopy in interface IAST
        Returns:
        a copy with element set to expr at the given position.
      • setEntry

        public void setEntry​(int location,
                             double value)
      • size

        public int size()
        Returns the number of elements in this ArrayList.
        Specified by:
        size in interface IAST
        Specified by:
        size in interface IExpr
        Returns:
        the number of elements in this ArrayList.
        See Also:
        IAST.argSize()
      • toArray

        public IExpr[] toArray()
        Returns a new array containing all elements contained in this ArrayList.
        Specified by:
        toArray in interface IAST
        Returns:
        an array of the elements from this ArrayList
      • toDoubleVector

        public double[] toDoubleVector()
        Convert this object into a double[] vector.
        Specified by:
        toDoubleVector in interface IExpr
        Overrides:
        toDoubleVector in class AbstractAST
        Returns:
        null if this object can not be converted into a double[] vector
      • toComplexVector

        public org.hipparchus.complex.Complex[] toComplexVector()
        Description copied from class: AbstractAST
        Convert this object into a Complex[] vector.
        Specified by:
        toComplexVector in interface IExpr
        Overrides:
        toComplexVector in class AbstractAST
        Returns:
        null if this object can not be converted into a Complex[] vector
      • toRealVector

        public org.hipparchus.linear.RealVector toRealVector()
        Convert this object into a RealVector.
        Specified by:
        toRealVector in interface IExpr
        Returns:
        null if this object can not be converted into a RealVector
      • toString

        public void toString​(Appendable buf)