AST
org.matheclipse.core.expression

Class AST

  • All Implemented Interfaces:
    AbelianGroupElem<IExpr>, Element<IExpr>, MonoidElem<IExpr>, RingElem<IExpr>, Serializable, Cloneable, Comparable<IExpr>, Iterable<IExpr>, Collection<IExpr>, List<IExpr>, RandomAccess, IAST, IExpr


    public class ASTextends HMArrayList<IExpr>implements IAST

    (A)bstract (S)yntax (T)ree of a given function.

    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:
    Serialized Form
    • Constructor Detail

      • AST

        public AST()
        Public no-arg constructor only needed for serialization
    • Method Detail

      • parse

        public static AST parse(String inputString)
        simple parser to simplify unit tests. The parser assumes that the String contains no syntax errors. Example "List[x,List[y]]"
      • clone

        public IAST clone()
        Returns a shallow copy of this AST instance. (The elements themselves are not copied.)
        Specified by:
        clone in interface IAST
        Overrides:
        clone in class HMArrayList<IExpr>
        Returns:
        a clone of this AST instance.
        See Also:
        Cloneable
      • cloneSet

        public IAST cloneSet(int position,            IExpr expr)
        Description copied from interface: IAST
        Returns a shallow copy of this IAST instance (the elements themselves are not copied) and set the expr at the given position.
        Specified by:
        cloneSet in interface IAST
        Returns:
        a clone of this IAST instance.
      • copy

        public IExpr copy()
        Description copied from interface: Element
        Clone this Element.
        Specified by:
        copy in interface Element<IExpr>
        Returns:
        Creates and returns a copy of this Element.
      • equalsFromPosition

        public boolean equalsFromPosition(int from0,                         AST f1,                         int from1)
      • topHead

        public ISymbol topHead()
        Returns the ISymbol of the IAST. If the head itself is a IAST it will recursively call head().
        Specified by:
        topHead in interface IAST
        Specified by:
        topHead in interface IExpr
        Returns:
        the \'highest level\' head of the expression, before Symbol, Integer, Real or String. for example while the head of a[b][c] is a[b], the top head is a.
      • hierarchy

        public final int hierarchy()
        A unique integer ID for the implementation of this expression
        Specified by:
        hierarchy in interface IExpr
        Returns:
        a unique integer id for the implementation of this expression
      • isLTOrdered

        public final boolean isLTOrdered(IExpr obj)
        Compares this expression with the specified expression for order. Returns true if this expression is canonical less than the specified expression (< relation).
        Specified by:
        isLTOrdered in interface IExpr
        Parameters:
        obj - an expression to compare with
        Returns:
        true if this expression is canonical less than the specified expression.
      • isLEOrdered

        public final boolean isLEOrdered(IExpr obj)
        Compares this expression with the specified expression for order. Returns true if this expression is canonical less than or equal to the specified expression (<= relation).
        Specified by:
        isLEOrdered in interface IExpr
        Returns:
        true if this expression is canonical less than or equal to the specified expression.
      • isGTOrdered

        public final boolean isGTOrdered(IExpr obj)
        Compares this expression with the specified expression for order. Returns true if this expression is canonical greater than the specified expression (< relation).
        Specified by:
        isGTOrdered in interface IExpr
        Parameters:
        obj - an expression to compare with
        Returns:
        true if this expression is canonical greater than the specified expression.
      • isGEOrdered

        public final boolean isGEOrdered(IExpr obj)
        Compares this expression with the specified expression for order. Returns true if this expression is canonical greater than or equal to the specified expression (<= relation).
        Specified by:
        isGEOrdered in interface IExpr
        Returns:
        true if this expression is canonical greater than or equal to the specified expression.
      • getEvalFlags

        public final int getEvalFlags()
        Get the evaluation flags for this list.
        Specified by:
        getEvalFlags in interface IAST
        Returns:
      • setEvalFlags

        public final void setEvalFlags(int i)
        Set the evaluation flags for this list.
        Specified by:
        setEvalFlags in interface IAST
      • addEvalFlags

        public final void addEvalFlags(int i)
        Add an evaluation flag to the existing ones.
        Specified by:
        addEvalFlags in interface IAST
      • addOneIdentity

        public IAST addOneIdentity(IAST value)
        Add an subAST with attribute OneIdentity for example Plus[] or Times[].
        Specified by:
        addOneIdentity in interface IAST
        Parameters:
        value - an ast with attribute OneIdentity.
        Returns:
        this ast after adding the subAST
      • getOneIdentity

        public IExpr getOneIdentity(IExpr defaultValue)
        Get the argument at index 1, if the size() == 2 or the complete ast if the size() > 2 (useful for ASTs with attribute OneIdentity for example for Plus[] you can call getOneIdentity(F.C0) or for Times[]) you can call getOneIdentity(F.C1).
        Specified by:
        getOneIdentity in interface IAST
        Parameters:
        defaultValue - default value, if size() < 2.
        Returns:
      • isEvalFlagOn

        public final boolean isEvalFlagOn(int i)
        Are the given evaluation flags enabled for this list ?
        Specified by:
        isEvalFlagOn in interface IAST
        Returns:
      • isEvalFlagOff

        public final boolean isEvalFlagOff(int i)
        Are the given evaluation flags disabled for this list ?
        Specified by:
        isEvalFlagOff in interface IAST
        Returns:
      • opposite

        public IExpr opposite()
      • inverse

        public IExpr inverse()
        Description copied from interface: IExpr
        Returns the multiplicative inverse of this object. It is the object such as this.times(this.inverse()) == ONE , with ONE being the multiplicative identity.
        Specified by:
        inverse in interface MonoidElem<IExpr>
        Specified by:
        inverse in interface IExpr
        Returns:
        ONE / this.
      • times

        public IExpr times(IExpr that)
        Description copied from interface: IExpr
        Returns the product of this object with the one specified.
        Specified by:
        times in interface IExpr
        Parameters:
        that - the object multiplier.
        Returns:
        this \xc2\xb7 that.
      • isList

        public final boolean isList()
        Is this a list (i.e. with header == List)
        Specified by:
        isList in interface IAST
        Specified by:
        isList in interface IExpr
      • isSequence

        public final boolean isSequence()
        Test if this expression is a sequence (i.e. an AST with head Sequence)
        Specified by:
        isSequence in interface IExpr
      • isComplexInfinity

        public boolean isComplexInfinity()
        Test if this expression is representing ComplexInfinity (i.e. DirectedInfinity[])
        Specified by:
        isComplexInfinity in interface IExpr
      • isDirectedInfinity

        public boolean isDirectedInfinity()
        Test if this expression is representing a DirectedInfinity (i.e. Infinity->DirectedInfinity[1], -Infinity->DirectedInfinity[-1], ComplexInfinity->DirectedInfinity[])
        Specified by:
        isDirectedInfinity in interface IExpr
      • isInfinity

        public boolean isInfinity()
        Test if this expression is representing Infinity (i.e. Infinity->DirectedInfinity[1])
        Specified by:
        isInfinity in interface IExpr
      • isNegative

        public boolean isNegative()
        Test if this object is a negative signed number.
        Specified by:
        isNegative in interface IExpr
        Returns:
        true, if this < 0; false in all other case.
      • isNegativeInfinity

        public boolean isNegativeInfinity()
        Test if this expression is representing -Infinity (i.e. -Infinity->DirectedInfinity[-1])
        Specified by:
        isNegativeInfinity in interface IExpr
      • isPlus

        public final boolean isPlus()
        Test if this expression is the addition function Plus[<arg1>, <arg2>, ...]
        Specified by:
        isPlus in interface IAST
        Specified by:
        isPlus in interface IExpr
      • isPower

        public final boolean isPower()
        Test if this expression is the function Power[<arg1>, <arg2>]
        Specified by:
        isPower in interface IAST
        Specified by:
        isPower in interface IExpr
      • isTimes

        public final boolean isTimes()
        Test if this expression is the multiplication function Times[<arg1>, <arg2>, ...]
        Specified by:
        isTimes in interface IAST
        Specified by:
        isTimes in interface IExpr
      • isSin

        public final boolean isSin()
        Test if this expression is the function Sin[<arg>]
        Specified by:
        isSin in interface IExpr
      • isCos

        public final boolean isCos()
        Test if this expression is the function Cos[<arg>]
        Specified by:
        isCos in interface IExpr
      • isTan

        public final boolean isTan()
        Test if this expression is the function TAn[<arg>]
        Specified by:
        isTan in interface IExpr
      • isArcSin

        public final boolean isArcSin()
        Test if this expression is the function ArcSin[<arg>]
        Specified by:
        isArcSin in interface IExpr
      • isAnd

        public final boolean isAnd()
        Test if this expression is the function And[<arg>,...]
        Specified by:
        isAnd in interface IExpr
      • isArcCos

        public final boolean isArcCos()
        Test if this expression is the function ArcCos[<arg>]
        Specified by:
        isArcCos in interface IExpr
      • isArcTan

        public final boolean isArcTan()
        Test if this expression is the function ArcTan[<arg>]
        Specified by:
        isArcTan in interface IExpr
      • isSinh

        public final boolean isSinh()
        Test if this expression is the function Sinh[<arg>]
        Specified by:
        isSinh in interface IExpr
      • isSlot

        public final boolean isSlot()
        Test if this expression is the function Slot[<integer-value>]
        Specified by:
        isSlot in interface IExpr
      • isSlotSequence

        public final boolean isSlotSequence()
        Test if this expression is the function SlotSequence[<integer-value>]
        Specified by:
        isSlotSequence in interface IExpr
      • isCosh

        public final boolean isCosh()
        Test if this expression is the function Cosh[<arg>]
        Specified by:
        isCosh in interface IExpr
      • isTanh

        public final boolean isTanh()
        Test if this expression is the function Tanh[<arg>]
        Specified by:
        isTanh in interface IExpr
      • isArcSinh

        public final boolean isArcSinh()
        Test if this expression is the function ArcSinh[<arg>]
        Specified by:
        isArcSinh in interface IExpr
      • isArcCosh

        public final boolean isArcCosh()
        Test if this expression is the function ArcCosh[<arg>]
        Specified by:
        isArcCosh in interface IExpr
      • isArcTanh

        public final boolean isArcTanh()
        Test if this expression is the function ArcTanh[<arg>]
        Specified by:
        isArcTanh in interface IExpr
      • isLog

        public final boolean isLog()
        Test if this expression is the function Log[<arg>]
        Specified by:
        isLog in interface IExpr
      • isOr

        public final boolean isOr()
        Test if this expression is the function Or[<arg>,...]
        Specified by:
        isOr in interface IExpr
      • isOne

        public final boolean isOne()
        Test if this expression equals 1 in symbolic or numeric mode.
        Specified by:
        isOne in interface IExpr
      • isMinusOne

        public final boolean isMinusOne()
        Test if this expression equals -1 in symbolic or numeric mode.
        Specified by:
        isMinusOne in interface IExpr
      • isZero

        public final boolean isZero()
        Test if this expression equals 0 in symbolic or numeric mode.
        Specified by:
        isZero in interface IExpr
      • isTrue

        public final boolean isTrue()
        Test if this expression equals the symbol "True"
        Specified by:
        isTrue in interface IExpr
      • isFalse

        public final boolean isFalse()
        Test if this expression equals the symbol "False"
        Specified by:
        isFalse in interface IExpr
      • isSame

        public final boolean isSame(IExpr expression)
        Test if this expression equals the given expression. If the compared expressions are of the same numeric type, they are equal to a given EPSILON
        Specified by:
        isSame in interface IExpr
      • isSame

        public final boolean isSame(IExpr expression,             double epsilon)
        Test if this expression equals the given expression. If the compared expressions are of the same numeric type, they are equal to a given EPSILON
        Specified by:
        isSame in interface IExpr
      • isMatrix

        public int[] isMatrix()
        Test if this expression is a matrix and return the dimensions as array [row-dimension, column-dimension]. This expression is only a matrix, if all elements are lists with the header List and have the same size.
        Specified by:
        isMatrix in interface IExpr
        Returns:
        null if the expression is not a matrix
      • isVector

        public final int isVector()
        Test if this expression is a vector and return the dimension of the vector. This expression is only a vector, if the expression is a List(...) and no element is itself a List(...).
        Specified by:
        isVector in interface IExpr
        Returns:
        -1 if the expression is no vector or size()-1 of the corresponding IAST.
      • isFraction

        public final boolean isFraction()
        Test if this expression is a fractional number, but no integer number.
        Specified by:
        isFraction in interface IExpr
      • isPattern

        public final boolean isPattern()
        Test if this expression is a pattern object
        Specified by:
        isPattern in interface IExpr
      • isPatternExpr

        public boolean isPatternExpr()
        Test if this expression or a subexpression is a pattern object. Used in pattern-matching; checks flags in IAST with flag IAST.CONTAINS_PATTERN_EXPR.
        Specified by:
        isPatternExpr in interface IExpr
      • isPatternSequence

        public final boolean isPatternSequence()
        Test if this expression is a pattern sequence object
        Specified by:
        isPatternSequence in interface IExpr
      • isPositive

        public boolean isPositive()
        Test if this object is a positive signed number.
        Specified by:
        isPositive in interface IExpr
        Returns:
        true, if this > 0; false in all other case.
      • isCondition

        public final boolean isCondition()
        Test if this expression is the Condition function Condition[<arg1>, <arg2>]
        Specified by:
        isCondition in interface IExpr
      • isModule

        public final boolean isModule()
        Test if this expression is the Module function Module[<arg1>, <arg2>]
        Specified by:
        isModule in interface IExpr
      • isSymbol

        public final boolean isSymbol()
        Description copied from interface: IExpr
        Test if this expression is a symbol
        Specified by:
        isSymbol in interface IExpr
      • isComplex

        public final boolean isComplex()
        Test if this expression is a symbolic complex number
        Specified by:
        isComplex in interface IExpr
      • isComplexNumeric

        public boolean isComplexNumeric()
        Test if this expression is a numeric complex number
        Specified by:
        isComplexNumeric in interface IExpr
      • isInteger

        public final boolean isInteger()
        Test if this expression is a integer number
        Specified by:
        isInteger in interface IExpr
      • isNumIntValue

        public final boolean isNumIntValue()
        Check if this expression represents an int value. The value of an INum object can be an int value.
        Specified by:
        isNumIntValue in interface IExpr
        Returns:
      • isRational

        public final boolean isRational()
        Test if this expression is a rational number, i.e. integer or fraction number.
        Specified by:
        isRational in interface IExpr
      • isSignedNumber

        public final boolean isSignedNumber()
        Test if this expression is a signed number
        Specified by:
        isSignedNumber in interface IExpr
      • isNot

        public final boolean isNot()
        Test if this expression is the function Not[<arg>]
        Specified by:
        isNot in interface IExpr
      • isNumeric

        public final boolean isNumeric()
        Test if this expression is a numeric number (i.e. of type INum or IComplexNum.
        Specified by:
        isNumeric in interface IExpr
      • isNumericFunction

        public boolean isNumericFunction()
        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
        Returns:
        true, if the given expression is a numeric function or value.
        See Also:
        IExpr.isRealFunction()
      • isRealFunction

        public boolean isRealFunction()
        Test if this expression is a real (non-complex) value (i.e. a real number or a real symbolic constant or a Plus, Times expression with only real values)
        Specified by:
        isRealFunction in interface IExpr
        Returns:
        true, if the given expression is a real (non-complex) value.
        See Also:
        IExpr.isConstant(), IExpr.isNumericFunction()
      • isNumber

        public final boolean isNumber()
        Description copied from interface: IExpr
        Test if this expression is a number
        Specified by:
        isNumber in interface IExpr
      • apply

        public IAST apply(IExpr head)
        Description copied from interface: IAST
        Apply the given head to this expression (i.e. create a list clone and replace the old head with the given one)
        Specified by:
        apply in interface IAST
        Returns:
      • apply

        public final IAST apply(IExpr head,         int start)
        Description copied from interface: IAST
        Apply the given head to this expression (i.e. create a sublist clone starting from index start and replacing the old head with the given one)
        Specified by:
        apply in interface IAST
        Returns:
      • apply

        public IAST apply(IExpr head,         int start,         int end)
        Description copied from interface: IAST
        Apply the given head to this expression (i.e. create a sublist clone from index start to end, and replacing the old head with the given one)
        Specified by:
        apply in interface IAST
        Returns:
      • apply

        public IExpr apply(List<? extends IExpr> leaves)
        Specified by:
        apply in interface IExpr
        Returns:
        an IExpr instance with the current expression as head(), and leaves as leaves().
      • apply

        public IExpr apply(IExpr... leaves)
        Specified by:
        apply in interface IExpr
        Returns:
        an IExpr instance with the current expression as head(), and leaves as leaves().
      • map

        public final IAST map(Function<IExpr,IExpr> function)
        Maps the elements of this IAST with the unary functor. If the function returns null the original element is used (i.e. the functor didn\'t modified this AST).

        Example for mapping with Functors#replace1st(), where the first argument will be replaced by the current argument of this AST:
         plusAST.map(Functors.replace1st(F.D(F.Null, dAST.get(2)))); 
        Specified by:
        map in interface IAST
        Parameters:
        function - a unary function
        Returns:
      • map

        public IAST map(IExpr head,       Function<IExpr,IExpr> function)
        Maps the elements of this IAST with the unary functor. If the function returns null the original element of the result list is used.
        Specified by:
        map in interface IAST
        Parameters:
        head - the new head element of the result list
        function - a unary function
        Returns:
      • map

        public IAST map(IAST clonedResultAST,       Function<IExpr,IExpr> function)
        Maps the elements of this IAST with the unary functor. If the function returns null the original element of the result list is used.
        Specified by:
        map in interface IAST
        Parameters:
        clonedResultAST - a list which is cloned from this list or greater or equal in size of this list.
        function - a unary function
        Returns:
      • map

        public IAST map(IAST resultAST,       IAST secondAST,       BiFunction<IExpr,IExpr,IExpr> function)
        Maps the elements of this IAST with the elements of the secondAST.
        Specified by:
        map in interface IAST
        Returns:
        the given resultAST.
      • replaceAll

        public final IExpr replaceAll(IAST astRules)
        Replace all (sub-) expressions with the given rule set. If no substitution matches, the method returns null.
        Specified by:
        replaceAll in interface IExpr
        Parameters:
        astRules - rules of the form x->y or {a->b, c->d}; the left-hand-side of the rule can contain pattern objects.
        Returns:
        null if no substitution of a (sub-)expression was possible.
      • replaceAll

        public final IExpr replaceAll(Function<IExpr,IExpr> function)
        Replace all (sub-) expressions with the given unary function. If no substitution matches, the method returns null.
        Specified by:
        replaceAll in interface IExpr
        Parameters:
        function - if the unary functions apply() method returns null the expression isn\'t substituted.
        Returns:
        null if no substitution of a (sub-)expression was possible.
      • replaceRepeated

        public final IExpr replaceRepeated(IAST astRules)
        Repeatedly replace all (sub-) expressions with the given rule set. If no substitution matches, the method returns this.
        Specified by:
        replaceRepeated in interface IExpr
        Parameters:
        astRules - rules of the form x->y or {a->b, c->d}; the left-hand-side of the rule can contain pattern objects.
        Returns:
        this if no substitution of a (sub-)expression was possible.
      • replaceRepeated

        public final IExpr replaceRepeated(Function<IExpr,IExpr> function)
        Repeatedly replace all (sub-) expressions with the given unary function. If no substitution matches, the method returns this.
        Specified by:
        replaceRepeated in interface IExpr
        Parameters:
        function - if the unary functions apply() method returns null the expression isn\'t substituted.
        Returns:
        this if no substitution of a (sub-)expression was possible.
      • filter

        public final IAST filter(IAST filterAST,          Predicate<IExpr> predicate)
        Apply the predicate to each element in this AST and append the elements which satisfy the predicate to the filterAST.
        Specified by:
        filter in interface IAST
        Parameters:
        filterAST - the elements which satisfy the predicate
        predicate - the predicate which filters each element in the range
        Returns:
        the filterList
      • filter

        public final IAST filter(IAST filterAST,          IAST restAST,          Predicate<IExpr> predicate)
        Apply the predicate to each element 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
        Parameters:
        filterAST - the elements satisfy match the predicate
        restAST - the elements which don\'t match the predicate
        predicate - the predicate which filters each element in the range
        Returns:
        the filterList
      • split

        public IAST[] split(Predicate<IExpr> predicate)
        Apply the predicate to each element in this AST and append the elements which satisfy the predicate to the 0th element of the result array, or otherwise append it to the 1st element of the result array.
        Specified by:
        split in interface IAST
        Parameters:
        predicate - the predicate which filters each element in the range
        Returns:
        the resulting ASTs in the 0-th and 1-st element of the array
      • split

        public IAST[] split(Function<IExpr,IExpr> function)
        Apply the function to each element in this AST and append the result elements for which the function returns non-null elements to the 0th element of the result array, or otherwise append it to the 1st element of the result array.
        Specified by:
        split in interface IAST
        Parameters:
        function - the function which filters each element in the range by returning a non-null result.
        Returns:
        the resulting ASTs in the 0-th and 1-st element of the array
      • isAST

        public final boolean isAST()
        Test if this expression is an AST list, which contains a header element (i.e. the function name) at index position 0 and some optional argument elements at the index positions 1..n. Therefore this expression is no atomic expression.
        Specified by:
        isAST in interface IExpr
        See Also:
        IExpr.isAtom()
      • isOrderlessAST

        public final boolean isOrderlessAST()
        Test if this expression is an AST list, which contains a header element (i.e. a function symbol like for example Plus or Times) with attribute Orderless at index position 0 and some optional argument elements at the index positions 1..n. Examples for Orderless functions are Plus[] or Times[]. Therefore this expression is no atomic expression.
        Specified by:
        isOrderlessAST in interface IExpr
        See Also:
        IExpr.isAtom()
      • isFlatAST

        public final boolean isFlatAST()
        Test if this expression is an AST list, which contains a header element (i.e. a function symbol like for example Dot, Plus or Times) with attribute Flat at index position 0 and some optional argument elements at the index positions 1..(size()-1). Examples for Flat functions are Dot[], Plus[] or Times[]. Therefore this expression is no atomic expression.
        Specified by:
        isFlatAST in interface IExpr
        See Also:
        IExpr.isAtom()
      • isAST

        public final boolean isAST(IExpr header)
        Test if this expression is an AST list, which contains the given header element at index position 0 and some optional argument elements at the index positions 1..(size()-1). Therefore this expression is not an atomic expression.
        Specified by:
        isAST in interface IExpr
        See Also:
        IExpr.isAtom()
      • isAST

        public final boolean isAST(IExpr header,            int length)
        Test if this expression is an AST list, which contains the given header element at index position 0 and optional argument elements at the index positions 1..(length-1). Therefore this expression is not an atomic expression.
        Specified by:
        isAST in interface IExpr
        See Also:
        IExpr.isAtom()
      • isAST

        public boolean isAST(IExpr header,            int length,            IExpr... args)
        Test if this expression is an AST list, which contains the given header element at index position 0 and optional argument elements at the index positions 1..(length-1). Therefore this expression is not an atomic expression.
        Specified by:
        isAST in interface IExpr
        args - the arguments of this AST which should be tested, if they are equal, a null value argument skips the equals chack.
        See Also:
        IExpr.isAtom()
      • isASTSizeGE

        public final boolean isASTSizeGE(IExpr header,                  int length)
        Test if this expression is an AST (i.e. no atomic expression) with the given head expression and size of elements greater equal than the AST#size() Test if this expression is an AST list, which contains the given header element at index position 0 and optional argument elements at the index positions 1..n. n must be greater equal than the given length. Therefore this expression is no atomic expression.
        Specified by:
        isASTSizeGE in interface IExpr
        See Also:
        IExpr.isAtom()
      • isAST

        public final boolean isAST(String symbol)
        Test if this expression is an AST list, where the string representation of the header element at index position 0 equals the given symbol and some optional argument elements at the index positions 1..(size()-1). Therefore this expression is no atomic expression. Example: isAST("Sin") gives true for Sin[Pi/2].
        Specified by:
        isAST in interface IExpr
        See Also:
        IExpr.isAtom()
      • isAST

        public final boolean isAST(String symbol,            int length)
        Test if this expression is an AST list, where the string representation of the header element at index position 0 equals the given symbol and some optional argument elements at the index positions 1..(length-1). Therefore this expression is no atomic expression. Example: isAST("Sin", 2) gives true for Sin[0].
        Specified by:
        isAST in interface IExpr
        See Also:
        IExpr.isAtom()
      • isRuleAST

        public final boolean isRuleAST()
        Test if this expression is of the form Rule[<arg1>, <arg2>] or RuleDelayed[<arg1>, <arg2>].
        Specified by:
        isRuleAST in interface IExpr
      • isFree

        public final boolean isFree(IExpr pattern,             boolean heads)
        Returns true, if all of the elements in the subexpressions or the expression itself, did not match the given pattern.
        Specified by:
        isFree in interface IExpr
        Parameters:
        pattern - a pattern-matching expression
        heads - if set to false, only the arguments of an IAST should be tested and not the Head[] element.
      • isFree

        public final boolean isFree(Predicate<IExpr> predicate,             boolean heads)
        Returns true, if all of the elements in the subexpressions or the expression itself, did not satisfy the given unary predicate.
        Specified by:
        isFree in interface IExpr
        Parameters:
        predicate - a unary predicate
        heads - if set to false, only the arguments of an IAST should be tested and not the Head[] element.
      • isMember

        public boolean isMember(IExpr pattern,               boolean heads)
        Returns true, if at least one of the elements in the subexpressions or the expression itself, match the given pattern.
        Specified by:
        isMember in interface IExpr
        Parameters:
        pattern - a pattern-matching expression
        heads - if set to false, only the arguments of an IAST should be tested and not the Head[] element.
      • isMember

        public final boolean isMember(Predicate<IExpr> predicate,               boolean heads)
        Returns true, if at least one of the elements in the subexpressions or the expression itself, satisfy the given unary predicate.
        Specified by:
        isMember in interface IExpr
        Parameters:
        predicate - a unary predicate
        heads - if set to false, only the arguments of an IAST should be tested and not the Head[] element.
      • isFunction

        public final boolean isFunction()
        Test if this expression is a Funtion[ arg1 ] expression with at least 1 argument.
        Specified by:
        isFunction in interface IExpr
      • compareTo

        public int compareTo(IExpr expr)
        Compares this expression with the specified expression for canonical order. Returns a negative integer, zero, or a positive integer as this expression is canonical less than, equal to, or greater than the specified expression.
        Specified by:
        compareTo in interface Element<IExpr>
        Specified by:
        compareTo in interface Comparable<IExpr>
        Specified by:
        compareTo in interface IExpr
        Returns:
        0 if this is equal to b, -1 if this is less then b, else +1.
      • evaluate

        public IExpr evaluate(EvalEngine engine)
        Description copied from interface: IExpr
        Evaluate an expression
        Specified by:
        evaluate in interface IExpr
        Parameters:
        engine - the evaluation engine
        Returns:
        the evaluated Object or null if the evaluation is not possible (i.e. the evaluation doesn\'t change the object).
      • patternHashCode

        public final int patternHashCode()
        Calculate a special hash value to find a matching rule in a hash table
        Specified by:
        patternHashCode in interface IAST
        Returns:
      • isAtom

        public final boolean isAtom()
        Description copied from interface: IExpr
        Test if this expression is an atomic expression (i.e. no AST expression)
        Specified by:
        isAtom in interface IExpr
      • copyHead

        public final IAST copyHead()
        Description copied from interface: IAST
        Create a copy of this IAST, which only contains the head element of the list (i.e. the element with index 0).
        Specified by:
        copyHead in interface IAST
      • copyUntil

        public final IAST copyUntil(int index)
        Description copied from interface: IAST
        Create a copy of this IAST, which contains alls elements up to index (exclusive).
        Specified by:
        copyUntil in interface IAST
      • variables2Slots

        public final IExpr variables2Slots(Map<IExpr,IExpr> map,                    List<IExpr> variableList)
        Description copied from interface: IExpr
        Convert the variables (i.e. ISymbol\'s with lower case character in the 0-th position of their name) in this expression into Slot[] s.
        Specified by:
        variables2Slots in interface IExpr
        Returns:
        null if the expression contains a variable with a \'$\' character in the 0-th position of its name and the math engine runs in server mode.
      • fullFormString

        public String fullFormString()
        Description copied from interface: IExpr
        Return the FullForm of this expression
        Specified by:
        fullFormString in interface IExpr
      • internalFormString

        public String internalFormString(boolean symbolsAsFactoryMethod,                        int depth)
        Description copied from interface: IExpr
        Return the internal Java form of this expression.
        Specified by:
        internalFormString in interface IExpr
        Parameters:
        symbolsAsFactoryMethod - if true use the F.symbol() method, otherwise print the symbol name.
        depth - the recursion depth of this call. 0 indicates "recurse without a limit".
      • addAll

        public final boolean addAll(List<? extends IExpr> ast)
        Appends all of the arguments (starting from offset 1) in the specified AST to the end of this AST.
        Specified by:
        addAll in interface IAST
        Parameters:
        ast - AST containing elements to be added to this AST
        Returns:
        true if this AST changed as a result of the call
        See Also:
        List.add(Object)
      • addAll

        public boolean addAll(List<? extends IExpr> ast,             int startPosition,             int endPosition)
        Appends all elements from offset startPosition to endPosition in the specified AST to the end of this AST.
        Specified by:
        addAll in interface IAST
        Parameters:
        ast - AST containing elements to be added to this AST
        startPosition - the start position, inclusive.
        endPosition - the ending position, exclusive.
        Returns:
        true if this AST changed as a result of the call
        See Also:
        List.add(Object)
      • args

        public final ASTRange args()
        Get the range of elements [1..ast.size()[. These range elements are the arguments of a function (represented as an AST).
        Specified by:
        args in interface IAST
        Returns:
      • range

        public final ASTRange range()
        Get the range of elements [0..sizeOfAST[ of the AST
        Specified by:
        range in interface IAST
        Returns:
      • range

        public final ASTRange range(int start)
        Get the range of elements [start..sizeOfAST[ of the AST
        Specified by:
        range in interface IAST
        Returns:
      • range

        public final ASTRange range(int start,             int end)
        Get the range of elements [start..end[ of the AST
        Specified by:
        range in interface IAST
        Returns:
      • newInstance

        public static AST newInstance(int intialCapacity,              IExpr head)
        Parameters:
        intialCapacity - the initial capacity (i.e. number of arguments without the header element) of the list.
        head -
        Returns:
      • newInstance

        public static AST newInstance(IExpr head)
      • newInstance

        public static AST newInstance(ISymbol symbol,              int... arr)
      • newInstance

        public static AST newInstance(ISymbol symbol,              double... arr)
        Constructs a list with header symbol and the arguments containing the given DoubleImpl values.
        See Also:
        Num
      • newInstance

        public static AST newInstance(ISymbol symbol,              double[][] matrix)
        Constructs a list with header symbol and the arguments containing the given DoubleImpl matrix values as List rows
        See Also:
        Num
      • accept

        public final <T> T accept(IVisitor<T> visitor)
        Accept a visitor with return type T
        Specified by:
        accept in interface IExpr
      • accept

        public final boolean accept(IVisitorBoolean visitor)
        Accept a visitor with return type boolean
        Specified by:
        accept in interface IExpr
      • accept

        public final int accept(IVisitorInt visitor)
        Accept a visitor with return type int
        Specified by:
        accept in interface IExpr
        Returns:
      • negative

        public final IExpr negative()
        Additional negative method, which works like opposite to fulfill groovy\'s method signature
        Specified by:
        negative in interface IExpr
        Returns:
      • getAt

        public final IExpr getAt(int index)
        Description copied from interface: IExpr
        Get the element at the specified index if this object is of type IAST.
        Specified by:
        getAt in interface IExpr
        Returns:
      • getInt

        public final IInteger getInt(int index)
        Casts an IExpr at position index to an IInteger.
        Specified by:
        getInt in interface IAST
        Parameters:
        index -
        Returns:
        Throws:
        WrongArgumentType - if the cast is not possible
      • getNumber

        public final INumber getNumber(int index)
        Casts an IExpr at position index to an INumber.
        Specified by:
        getNumber in interface IAST
        Parameters:
        index -
        Returns:
        Throws:
        WrongArgumentType - if the cast is not possible
      • getAST

        public final IAST getAST(int index)
        Casts an IExpr at position index to an IAST.
        Specified by:
        getAST in interface IAST
        Parameters:
        index -
        Returns:
        Throws:
        WrongArgumentType - if the cast is not possible
      • getList

        public final IAST getList(int index)
        Casts an IExpr which is a list at position index to an IAST.
        Specified by:
        getList in interface IAST
        Parameters:
        index -
        Returns:
        Throws:
        WrongArgumentType
      • leaves

        public List<IExpr> leaves()
        Specified by:
        leaves in interface IExpr
        Returns:
        a list of the the leaf expressions. Instances of ExprImpl should return null, while any other expression may not return null (but can return an empty list).
      • egcd

        public IExpr[] egcd(IExpr b)
        Description copied from interface: RingElem
        Extended greatest common divisor.
        Specified by:
        egcd in interface RingElem<IExpr>
        Parameters:
        b - other element.
        Returns:
        [ gcd(this,b), c1, c2 ] with c1*this + c2*b = gcd(this,b).
      • gcd

        public IExpr gcd(IExpr b)
        Description copied from interface: RingElem
        Greatest common divisor.
        Specified by:
        gcd in interface RingElem<IExpr>
        Parameters:
        b - other element.
        Returns:
        gcd(this,b).
      • signum

        @Deprecatedpublic int signum()
        Deprecated. 
        Signum functionality is used in JAS toString() method, don\'t use it as math signum function.
        Specified by:
        signum in interface AbelianGroupElem<IExpr>
        Specified by:
        signum in interface IExpr
        Returns:
        the sign of this.
      • toScript

        public final String toScript()
        Description copied from interface: Element
        Get a scripting compatible string representation.
        Specified by:
        toScript in interface Element<IExpr>
        Returns:
        script compatible representation for this Element.
      • toScriptFactory

        public final String toScriptFactory()
        Description copied from interface: Element
        Get a scripting compatible string representation of the factory.
        Specified by:
        toScriptFactory in interface Element<IExpr>
        Returns:
        script compatible representation for this ElemFactory.
      • isONE

        public final boolean isONE()
        Test if this is one.
        Specified by:
        isONE in interface MonoidElem<IExpr>
        Returns:
        true if this is 1, else false.
      • isUnit

        public final boolean isUnit()
        Test if this is a unit. I.e. there exists x with this.multiply(x).isONE() == true.
        Specified by:
        isUnit in interface MonoidElem<IExpr>
        Returns:
        true if this is a unit, else false.
      • isValue

        public final boolean isValue()
        Returns true, if this symbol or ast expression is bound to a value (i.e. the evaluation returns an assigned value).
        Specified by:
        isValue in interface IExpr
      • 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) ).
        Specified by:
        head in interface IExpr
        Returns:
        the head of the expression, which must not be null.
      • iterator0

        public Iterator<IExpr> iterator0()
        Description copied from interface: IAST
        Returns an iterator over the elements in this list starting with offset 0.
        Specified by:
        iterator0 in interface IAST
        Returns:
        an iterator over this list values.
      • arg1

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

        public final IExpr arg2()
        Get the second argument (i.e. the third element of the underlying list structure) of the AST function (i.e. get(2) ).
        Specified by:
        arg2 in interface IAST
        Returns:
        the second argument of the function represented by this AST.
        See Also:
        IExpr.head()
      • arg3

        public final IExpr arg3()
        Get the third argument (i.e. the fourth element of the underlying list structure) of the AST function (i.e. get(3) ).
        Specified by:
        arg3 in interface IAST
        Returns:
        the third argument of the function represented by this AST.
        See Also:
        IExpr.head()
      • last

        public final IExpr last()
        Get the last element of the AST list (i.e. get(size()-1).
        Specified by:
        last in interface IAST
        Returns:
        the last argument of the function represented by this AST.
        See Also:
        IExpr.head()
      • append

        public IAST append(IExpr expr)
        Description copied from interface: IAST
        Append an expression to this list.
        Specified by:
        append in interface IAST
        Returns:
        this after appending the given expression.
      • prepend

        public IAST prepend(IExpr expr)
        Description copied from interface: IAST
        Prepend an expression to this list.
        Specified by:
        prepend in interface IAST
        Returns:
        this after prepending the given expression.

SCaVis 2.0 © jWork.ORG