org.matheclipse.core.expression
Class AST
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- org.matheclipse.core.generic.util.HMArrayList<IExpr>
-
- org.matheclipse.core.expression.AST
-
- All Implemented Interfaces:
- AbelianGroupElem<IExpr>, Element<IExpr>, MonoidElem<IExpr>, RingElem<IExpr>, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<IExpr>, java.lang.Iterable<IExpr>, java.util.Collection<IExpr>, java.util.List<IExpr>, java.util.RandomAccess, IAST, IExpr
public class AST extends 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
Internally an AST is represented as aSin[x]expression will be denoted by an AST with 2 nodes. One node for the headerSinand one node for the argumentx.java.util.Listwhich contains- the operator of a function (i.e. the "header"-symbol: Sin, Cos, Inverse, Plus, Times,...) at index
0and - the
narguments of a function in the index1 to n
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.matheclipse.core.interfaces.IAST
CONTAINS_DEFAULT_PATTERN, CONTAINS_NO_DEFAULT_PATTERN_MASK, CONTAINS_PATTERN, CONTAINS_PATTERN_EXPR, CONTAINS_PATTERN_SEQUENCE, IS_DECOMPOSED_PARTIAL_FRACTION, IS_FLATTENED, IS_FLATTENED_OR_SORTED_MASK, IS_LISTABLE_THREADED, IS_MATRIX, IS_MATRIX_OR_VECTOR, IS_SORTED, IS_VECTOR, NO_FLAG
-
Fields inherited from interface org.matheclipse.core.interfaces.IExpr
ASTID, COMPLEXID, DOUBLECOMPLEXID, DOUBLEID, FRACTIONID, INTEGERID, METHODSYMBOLID, PATTERNID, STRINGID, SYMBOLID
-
-
Constructor Summary
Constructors Constructor and Description AST()Public no-arg constructor only needed for serializationAST(IExpr head, IExpr... es)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description IExprabs()Absolute value of this.<T> Taccept(IVisitor<T> visitor)Accept a visitor with return type Tbooleanaccept(IVisitorBoolean visitor)Accept a visitor with return typebooleanintaccept(IVisitorInt visitor)Accept a visitor with return typeintbooleanaddAll(java.util.List<? extends IExpr> ast)Appends all of the arguments (starting from offset1) in the specified AST to the end of this AST.booleanaddAll(java.util.List<? extends IExpr> ast, int startPosition, int endPosition)Appends all elements from offsetstartPositiontoendPositionin the specified AST to the end of this AST.voidaddEvalFlags(int i)Add an evaluation flag to the existing ones.IASTaddOneIdentity(IAST value)Add ansubASTwith attributeOneIdentityfor example Plus[] or Times[].IExprand(IExpr that)IASTappend(IExpr expr)Append an expression to this list.IExprapply(IExpr... leaves)IASTapply(IExpr head)Apply the given head to this expression (i.e.IASTapply(IExpr head, int start)Apply the given head to this expression (i.e.IASTapply(IExpr head, int start, int end)Apply the given head to this expression (i.e.IExprapply(java.util.List<? extends IExpr> leaves)IExprarg1()Get the first argument (i.e.IExprarg2()Get the second argument (i.e.IExprarg3()Get the third argument (i.e.ASTRangeargs()Get the range of elements [1..ast.size()[.java.lang.ObjectasType(java.lang.Class clazz)IASTclone()Returns a shallow copy of this AST instance.IASTcloneSet(int position, IExpr expr)Returns a shallow copy of thisIASTinstance (the elements themselves are not copied) and set theexprat the givenposition.intcompareTo(IExpr expr)Compares this expression with the specified expression for canonical order.IExprcopy()Clone this Element.IASTcopyHead()Create a copy of thisIAST, which only contains the head element of the list (i.e.IASTcopyUntil(int index)Create a copy of thisIAST, which contains alls elements up toindex(exclusive).IExprdivide(IExpr that)Divide this by S.IExpr[]egcd(IExpr b)Extended greatest common divisor.booleanequals(java.lang.Object obj)Test if this is equal to b.booleanequalsFromPosition(int from0, AST f1, int from1)IExprevaluate(EvalEngine engine)Evaluate an expressionElemFactory<IExpr>factory()Get the corresponding element factory.IASTfilter(IAST filterAST, IAST restAST, Predicate<IExpr> predicate)Apply the predicate to each element in thisASTand append the elements which satisfy the predicate to thefilterAST, or otherwise append it to therestAST.IASTfilter(IAST filterAST, Predicate<IExpr> predicate)Apply the predicate to each element in thisASTand append the elements which satisfy the predicate to thefilterAST.java.lang.StringfullFormString()Return the FullForm of this expressionIExprgcd(IExpr b)Greatest common divisor.IASTgetAST(int index)Casts anIExprat positionindexto anIAST.IExprgetAt(int index)Get the element at the specifiedindexif this object is of typeIAST.intgetEvalFlags()Get the evaluation flags for this list.IIntegergetInt(int index)Casts anIExprat positionindexto anIInteger.IASTgetList(int index)Casts anIExprwhich is a list at positionindexto anIAST.INumbergetNumber(int index)Casts anIExprat positionindexto anINumber.IExprgetOneIdentity(IExpr defaultValue)Get the argument at index 1, if thesize() == 2or the complete ast if thesize() > 2(useful for ASTs with attributeOneIdentityfor example forPlus[]you can callgetOneIdentity(F.C0)or forTimes[]) you can callgetOneIdentity(F.C1).IExprhead()If this object is an instance ofIASTget the first element (offset 0) of theIASTlist (i.e.inthierarchy()A unique integer ID for the implementation of this expressionjava.lang.StringinternalFormString(boolean symbolsAsFactoryMethod, int depth)Return the internal Java form of this expression.IExprinverse()Returns the multiplicative inverse of this object.booleanisAnd()Test if this expression is the functionAnd[<arg>,...]booleanisArcCos()Test if this expression is the functionArcCos[<arg>]booleanisArcCosh()Test if this expression is the functionArcCosh[<arg>]booleanisArcSin()Test if this expression is the functionArcSin[<arg>]booleanisArcSinh()Test if this expression is the functionArcSinh[<arg>]booleanisArcTan()Test if this expression is the functionArcTan[<arg>]booleanisArcTanh()Test if this expression is the functionArcTanh[<arg>]booleanisAST()Test if this expression is an AST list, which contains a header element (i.e.booleanisAST(IExpr header)Test if this expression is an AST list, which contains the given header element at index position0and some optional argument elements at the index positions1..(size()-1).booleanisAST(IExpr header, int length)Test if this expression is an AST list, which contains the given header element at index position0and optional argument elements at the index positions1..(length-1).booleanisAST(IExpr header, int length, IExpr... args)Test if this expression is an AST list, which contains the given header element at index position0and optional argument elements at the index positions1..(length-1).booleanisAST(java.lang.String symbol)Test if this expression is an AST list, where the string representation of the header element at index position0equals the givensymboland some optional argument elements at the index positions1..(size()-1).booleanisAST(java.lang.String symbol, int length)Test if this expression is an AST list, where the string representation of the header element at index position0equals the givensymboland some optional argument elements at the index positions1..(length-1).booleanisASTSizeGE(IExpr header, int length)Test if this expression is an AST (i.e.booleanisAtom()Test if this expression is an atomic expression (i.e.booleanisComplex()Test if this expression is a symbolic complex numberbooleanisComplexInfinity()Test if this expression is representing ComplexInfinity (i.e.booleanisComplexNumeric()Test if this expression is a numeric complex numberbooleanisCondition()Test if this expression is the Condition functionCondition[<arg1>, <arg2>]booleanisConstant()Test if this expression is a symbol with attributeConstant.booleanisCos()Test if this expression is the functionCos[<arg>]booleanisCosh()Test if this expression is the functionCosh[<arg>]booleanisDirectedInfinity()Test if this expression is representing a DirectedInfinity (i.e.booleanisEvalFlagOff(int i)Are the given evaluation flags disabled for this list ?booleanisEvalFlagOn(int i)Are the given evaluation flags enabled for this list ?booleanisFalse()Test if this expression equals the symbol "False"booleanisFlatAST()Test if this expression is an AST list, which contains a header element (i.e.booleanisFraction()Test if this expression is a fractional number, but no integer number.booleanisFree(IExpr pattern, boolean heads)Returnstrue, if all of the elements in the subexpressions or the expression itself, did not match the given pattern.booleanisFree(Predicate<IExpr> predicate, boolean heads)Returnstrue, if all of the elements in the subexpressions or the expression itself, did not satisfy the given unary predicate.booleanisFunction()Test if this expression is aFuntion[ arg1 ]expression with at least 1 argument.booleanisGEOrdered(IExpr obj)Compares this expression with the specified expression for order.booleanisGTOrdered(IExpr obj)Compares this expression with the specified expression for order.booleanisInfinity()Test if this expression is representingInfinity(i.e.booleanisInteger()Test if this expression is a integer numberbooleanisLEOrdered(IExpr obj)Compares this expression with the specified expression for order.booleanisList()Is this a list (i.e.booleanisListOfLists()Test if this expression is a list of listsbooleanisLog()Test if this expression is the functionLog[<arg>]booleanisLTOrdered(IExpr obj)Compares this expression with the specified expression for order.int[]isMatrix()Test if this expression is a matrix and return the dimensions as array [row-dimension, column-dimension].booleanisMember(IExpr pattern, boolean heads)Returnstrue, if at least one of the elements in the subexpressions or the expression itself, match the given pattern.booleanisMember(Predicate<IExpr> predicate, boolean heads)Returnstrue, if at least one of the elements in the subexpressions or the expression itself, satisfy the given unary predicate.booleanisMinusOne()Test if this expression equals-1in symbolic or numeric mode.booleanisModule()Test if this expression is the Module functionModule[<arg1>, <arg2>]booleanisNegative()Test if this object is a negative signed number.booleanisNegativeInfinity()Test if this expression is representing-Infinity(i.e.booleanisNot()Test if this expression is the functionNot[<arg>]booleanisNumber()Test if this expression is a numberbooleanisNumEqualInteger(IInteger ii)Check if this expression equals anIIntegervalue.booleanisNumeric()Test if this expression is a numeric number (i.e.booleanisNumericFunction()Test if this expression is a numeric function (i.e.booleanisNumIntValue()Check if this expression represents anintvalue.booleanisOne()Test if this expression equals1in symbolic or numeric mode.booleanisONE()Test if this is one.booleanisOr()Test if this expression is the functionOr[<arg>,...]booleanisOrderlessAST()Test if this expression is an AST list, which contains a header element (i.e.booleanisPattern()Test if this expression is a pattern objectbooleanisPatternExpr()Test if this expression or a subexpression is a pattern object.booleanisPatternSequence()Test if this expression is a pattern sequence objectbooleanisPlus()Test if this expression is the addition functionPlus[<arg1>, <arg2>, ...]booleanisPositive()Test if this object is a positive signed number.booleanisPower()Test if this expression is the functionPower[<arg1>, <arg2>]booleanisRational()Test if this expression is a rational number, i.e.booleanisRealFunction()Test if this expression is a real (non-complex) value (i.e.booleanisRuleAST()Test if this expression is of the formRule[<arg1>, <arg2>]orRuleDelayed[<arg1>, <arg2>].booleanisSame(IExpr expression)Test if this expression equals the given expression.booleanisSame(IExpr expression, double epsilon)Test if this expression equals the given expression.booleanisSequence()Test if this expression is a sequence (i.e.booleanisSignedNumber()Test if this expression is a signed numberbooleanisSin()Test if this expression is the functionSin[<arg>]booleanisSinh()Test if this expression is the functionSinh[<arg>]booleanisSlot()Test if this expression is the functionSlot[<integer-value>]booleanisSlotSequence()Test if this expression is the functionSlotSequence[<integer-value>]booleanisSymbol()Test if this expression is a symbolbooleanisTan()Test if this expression is the functionTAn[<arg>]booleanisTanh()Test if this expression is the functionTanh[<arg>]booleanisTimes()Test if this expression is the multiplication functionTimes[<arg1>, <arg2>, ...]booleanisTrue()Test if this expression equals the symbol "True"booleanisUnit()Test if this is a unit.booleanisValue()Returnstrue, if this symbol or ast expression is bound to a value (i.e.intisVector()Test if this expression is a vector and return the dimension of the vector.booleanisZero()Test if this expression equals0in symbolic or numeric mode.booleanisZERO()Test if this is zero.java.util.Iterator<IExpr>iterator()Returns an iterator over the elements in thisIASTstarting with offset 1.java.util.Iterator<IExpr>iterator0()Returns an iterator over the elements in this list starting with offset 0.IExprlast()Get the last element of theASTlist (i.e.java.util.List<IExpr>leaves()IASTmap(Function<IExpr,IExpr> function)Maps the elements of this IAST with the unary functor.IASTmap(IAST clonedResultAST, Function<IExpr,IExpr> function)Maps the elements of this IAST with the unary functor.IASTmap(IAST resultAST, IAST secondAST, BiFunction<IExpr,IExpr,IExpr> function)Maps the elements of this IAST with the elements of thesecondAST.IASTmap(IExpr head, Function<IExpr,IExpr> function)Maps the elements of this IAST with the unary functor.IExprminus(IExpr that)IExprmod(IExpr that)IExprmultiply(IExpr that)Multiply this with S.IExprnegate()Negate this.IExprnegative()Additionalnegativemethod, which works like opposite to fulfill groovy's method signaturestatic ASTnewInstance(IExpr head)static ASTnewInstance(int intialCapacity, IExpr head)static ASTnewInstance(ISymbol symbol, Complex... arr)static ASTnewInstance(ISymbol symbol, double... arr)Constructs a list with header symbol and the arguments containing the given DoubleImpl values.static ASTnewInstance(ISymbol symbol, double[][] matrix)Constructs a list with header symbol and the arguments containing the given DoubleImpl matrix values as List rowsstatic ASTnewInstance(ISymbol symbol, int... arr)IExpropposite()IExpror(IExpr that)static ASTparse(java.lang.String inputString)simple parser to simplify unit tests.intpatternHashCode()Calculate a special hash value to find a matching rule in a hash tableIExprplus(IExpr that)IExprpower(IExpr that)IExprpower(java.lang.Integer n)IASTprepend(IExpr expr)Prepend an expression to this list.ASTRangerange()Get the range of elements [0..sizeOfAST[ of the ASTASTRangerange(int start)Get the range of elements [start..sizeOfAST[ of the ASTASTRangerange(int start, int end)Get the range of elements [start..end[ of the ASTIExprremainder(IExpr S)Remainder after division of this by S.IExprreplaceAll(Function<IExpr,IExpr> function)Replace all (sub-) expressions with the given unary function.IExprreplaceAll(IAST astRules)Replace all (sub-) expressions with the given rule set.IExprreplacePart(IAST astRules)IExprreplaceRepeated(Function<IExpr,IExpr> function)Repeatedly replace all (sub-) expressions with the given unary function.IExprreplaceRepeated(IAST astRules)Repeatedly replace all (sub-) expressions with the given rule set.IExprreplaceSlots(IAST astSlots)voidsetEvalFlags(int i)Set the evaluation flags for this list.intsignum()Deprecated.IAST[]split(Function<IExpr,IExpr> function)Apply the function to each element in thisASTand append the result elements for which the function returns non-null elements to the0th elementof the result array, or otherwise append it to the1st elementof the result array.IAST[]split(Predicate<IExpr> predicate)Apply the predicate to each element in thisASTand append the elements which satisfy the predicate to the0th elementof the result array, or otherwise append it to the1st elementof the result array.IExprsubtract(IExpr that)Subtract S from this.IExprsum(IExpr that)Sum of this and S.IExprtimes(IExpr that)Returns the product of this object with the one specified.ISymboltopHead()Returns the ISymbol of the IAST.java.lang.StringtoScript()Get a scripting compatible string representation.java.lang.StringtoScriptFactory()Get a scripting compatible string representation of the factory.java.lang.StringtoString()IExprvariables2Slots(java.util.Map<IExpr,IExpr> map, java.util.List<IExpr> variableList)Convert the variables (i.e.-
Methods inherited from class org.matheclipse.core.generic.util.HMArrayList
add, add, addAll, addAll, clear, contains, ensureCapacity, get, hashCode, indexOf, isEmpty, isSameHead, isSameHead, isSameHeadSizeGE, lastIndexOf, remove, remove, set, size, toArray, toArray, trimToSize
-
-
-
-
Method Detail
-
parse
public static AST parse(java.lang.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:
clonein interfaceIAST- Overrides:
clonein classHMArrayList<IExpr>- Returns:
- a clone of this AST instance.
- See Also:
Cloneable
-
cloneSet
public IAST cloneSet(int position, IExpr expr)
Description copied from interface:IASTReturns a shallow copy of thisIASTinstance (the elements themselves are not copied) and set theexprat the givenposition.
-
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().
-
hierarchy
public final int hierarchy()
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:
isLTOrderedin interfaceIExpr- 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:
isLEOrderedin interfaceIExpr- 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:
isGTOrderedin interfaceIExpr- 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:
isGEOrderedin interfaceIExpr- 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:
getEvalFlagsin interfaceIAST- Returns:
-
setEvalFlags
public final void setEvalFlags(int i)
Set the evaluation flags for this list.- Specified by:
setEvalFlagsin interfaceIAST
-
addEvalFlags
public final void addEvalFlags(int i)
Add an evaluation flag to the existing ones.- Specified by:
addEvalFlagsin interfaceIAST
-
addOneIdentity
public IAST addOneIdentity(IAST value)
Add ansubASTwith attributeOneIdentityfor example Plus[] or Times[].- Specified by:
addOneIdentityin interfaceIAST- Parameters:
value- an ast with attributeOneIdentity.- Returns:
thisast after adding the subAST
-
getOneIdentity
public IExpr getOneIdentity(IExpr defaultValue)
Get the argument at index 1, if thesize() == 2or the complete ast if thesize() > 2(useful for ASTs with attributeOneIdentityfor example forPlus[]you can callgetOneIdentity(F.C0)or forTimes[]) you can callgetOneIdentity(F.C1).- Specified by:
getOneIdentityin interfaceIAST- Parameters:
defaultValue- default value, ifsize() < 2.- Returns:
-
isEvalFlagOn
public final boolean isEvalFlagOn(int i)
Are the given evaluation flags enabled for this list ?- Specified by:
isEvalFlagOnin interfaceIAST- Returns:
-
isEvalFlagOff
public final boolean isEvalFlagOff(int i)
Are the given evaluation flags disabled for this list ?- Specified by:
isEvalFlagOffin interfaceIAST- Returns:
-
opposite
public IExpr opposite()
-
inverse
public IExpr inverse()
Description copied from interface:IExprReturns the multiplicative inverse of this object. It is the object such asthis.times(this.inverse()) == ONE, withONEbeing the multiplicative identity.- Specified by:
inversein interfaceMonoidElem<IExpr>- Specified by:
inversein interfaceIExpr- Returns:
ONE / this.
-
times
public IExpr times(IExpr that)
Description copied from interface:IExprReturns the product of this object with the one specified.
-
isList
public final boolean isList()
Is this a list (i.e. with header == List)
-
isSequence
public final boolean isSequence()
Test if this expression is a sequence (i.e. an AST with head Sequence)- Specified by:
isSequencein interfaceIExpr
-
isListOfLists
public boolean isListOfLists()
Test if this expression is a list of lists- Specified by:
isListOfListsin interfaceIExpr- See Also:
IExpr.isList(),IExpr.isMatrix(),IExpr.isVector()
-
isComplexInfinity
public boolean isComplexInfinity()
Test if this expression is representing ComplexInfinity (i.e. DirectedInfinity[])- Specified by:
isComplexInfinityin interfaceIExpr
-
isDirectedInfinity
public boolean isDirectedInfinity()
Test if this expression is representing a DirectedInfinity (i.e.Infinity->DirectedInfinity[1],-Infinity->DirectedInfinity[-1],ComplexInfinity->DirectedInfinity[])- Specified by:
isDirectedInfinityin interfaceIExpr
-
isInfinity
public boolean isInfinity()
Test if this expression is representingInfinity(i.e.Infinity->DirectedInfinity[1])- Specified by:
isInfinityin interfaceIExpr
-
isNegative
public boolean isNegative()
Test if this object is a negative signed number.- Specified by:
isNegativein interfaceIExpr- Returns:
true, ifthis < 0;falsein all other case.
-
isNegativeInfinity
public boolean isNegativeInfinity()
Test if this expression is representing-Infinity(i.e.-Infinity->DirectedInfinity[-1])- Specified by:
isNegativeInfinityin interfaceIExpr
-
isPlus
public final boolean isPlus()
Test if this expression is the addition functionPlus[<arg1>, <arg2>, ...]
-
isPower
public final boolean isPower()
Test if this expression is the functionPower[<arg1>, <arg2>]
-
isTimes
public final boolean isTimes()
Test if this expression is the multiplication functionTimes[<arg1>, <arg2>, ...]
-
isSin
public final boolean isSin()
Test if this expression is the functionSin[<arg>]
-
isCos
public final boolean isCos()
Test if this expression is the functionCos[<arg>]
-
isTan
public final boolean isTan()
Test if this expression is the functionTAn[<arg>]
-
isArcSin
public final boolean isArcSin()
Test if this expression is the functionArcSin[<arg>]
-
isAnd
public final boolean isAnd()
Test if this expression is the functionAnd[<arg>,...]
-
isArcCos
public final boolean isArcCos()
Test if this expression is the functionArcCos[<arg>]
-
isArcTan
public final boolean isArcTan()
Test if this expression is the functionArcTan[<arg>]
-
isSinh
public final boolean isSinh()
Test if this expression is the functionSinh[<arg>]
-
isSlot
public final boolean isSlot()
Test if this expression is the functionSlot[<integer-value>]
-
isSlotSequence
public final boolean isSlotSequence()
Test if this expression is the functionSlotSequence[<integer-value>]- Specified by:
isSlotSequencein interfaceIExpr
-
isCosh
public final boolean isCosh()
Test if this expression is the functionCosh[<arg>]
-
isTanh
public final boolean isTanh()
Test if this expression is the functionTanh[<arg>]
-
isArcSinh
public final boolean isArcSinh()
Test if this expression is the functionArcSinh[<arg>]
-
isArcCosh
public final boolean isArcCosh()
Test if this expression is the functionArcCosh[<arg>]
-
isArcTanh
public final boolean isArcTanh()
Test if this expression is the functionArcTanh[<arg>]
-
isLog
public final boolean isLog()
Test if this expression is the functionLog[<arg>]
-
isOr
public final boolean isOr()
Test if this expression is the functionOr[<arg>,...]
-
isOne
public final boolean isOne()
Test if this expression equals1in symbolic or numeric mode.
-
isMinusOne
public final boolean isMinusOne()
Test if this expression equals-1in symbolic or numeric mode.- Specified by:
isMinusOnein interfaceIExpr
-
isZero
public final boolean isZero()
Test if this expression equals0in symbolic or numeric mode.
-
isTrue
public final boolean isTrue()
Test if this expression equals the symbol "True"
-
isFalse
public final boolean isFalse()
Test if this expression equals the symbol "False"
-
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
-
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
-
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 headerListand have the same size.
-
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 aList(...)and no element is itself aList(...).
-
isFraction
public final boolean isFraction()
Test if this expression is a fractional number, but no integer number.- Specified by:
isFractionin interfaceIExpr
-
isPattern
public final boolean isPattern()
Test if this expression is a pattern object
-
isPatternExpr
public boolean isPatternExpr()
Test if this expression or a subexpression is a pattern object. Used in pattern-matching; checks flags inIASTwith flagIAST.CONTAINS_PATTERN_EXPR.- Specified by:
isPatternExprin interfaceIExpr
-
isPatternSequence
public final boolean isPatternSequence()
Test if this expression is a pattern sequence object- Specified by:
isPatternSequencein interfaceIExpr
-
isPositive
public boolean isPositive()
Test if this object is a positive signed number.- Specified by:
isPositivein interfaceIExpr- Returns:
true, ifthis > 0;falsein all other case.
-
isCondition
public final boolean isCondition()
Test if this expression is the Condition functionCondition[<arg1>, <arg2>]- Specified by:
isConditionin interfaceIExpr
-
isModule
public final boolean isModule()
Test if this expression is the Module functionModule[<arg1>, <arg2>]
-
isSymbol
public final boolean isSymbol()
Description copied from interface:IExprTest if this expression is a symbol
-
isConstant
public boolean isConstant()
Test if this expression is a symbol with attributeConstant. Therefore numbers returnfalsefor this method!- Specified by:
isConstantin interfaceIExpr- See Also:
IExpr.isRealFunction(),IExpr.isNumericFunction()
-
isComplex
public final boolean isComplex()
Test if this expression is a symbolic complex number
-
isComplexNumeric
public boolean isComplexNumeric()
Test if this expression is a numeric complex number- Specified by:
isComplexNumericin interfaceIExpr
-
isInteger
public final boolean isInteger()
Test if this expression is a integer number
-
isNumEqualInteger
public boolean isNumEqualInteger(IInteger ii) throws java.lang.ArithmeticException
Check if this expression equals anIIntegervalue. The value of anINumor the value of anIIntegerobject can be anIIntegervalue.- Specified by:
isNumEqualIntegerin interfaceIExpr- Returns:
- Throws:
java.lang.ArithmeticException
-
isNumIntValue
public final boolean isNumIntValue()
Check if this expression represents anintvalue. The value of anINumobject can be anintvalue.- Specified by:
isNumIntValuein interfaceIExpr- Returns:
-
isRational
public final boolean isRational()
Test if this expression is a rational number, i.e. integer or fraction number.- Specified by:
isRationalin interfaceIExpr
-
isSignedNumber
public final boolean isSignedNumber()
Test if this expression is a signed number- Specified by:
isSignedNumberin interfaceIExpr
-
isNot
public final boolean isNot()
Test if this expression is the functionNot[<arg>]
-
isNumeric
public final boolean isNumeric()
Test if this expression is a numeric number (i.e. of typeINumorIComplexNum.
-
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:
isNumericFunctionin interfaceIExpr- 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 aPlus, Timesexpression with only real values)- Specified by:
isRealFunctionin interfaceIExpr- 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:IExprTest if this expression is a number
-
apply
public IAST apply(IExpr head)
Description copied from interface:IASTApply the given head to this expression (i.e. create a list clone and replace the old head with the given one)
-
apply
public final IAST apply(IExpr head, int start)
Description copied from interface:IASTApply 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)
-
apply
public IAST apply(IExpr head, int start, int end)
Description copied from interface:IASTApply 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)
-
map
public final IAST map(Function<IExpr,IExpr> function)
Maps the elements of this IAST with the unary functor. If the function returnsnullthe original element is used (i.e. the functor didn't modified this AST).
Example for mapping withFunctors#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))));
-
map
public IAST map(IExpr head, Function<IExpr,IExpr> function)
Maps the elements of this IAST with the unary functor. If the function returnsnullthe original element of the result list is used.
-
map
public IAST map(IAST clonedResultAST, Function<IExpr,IExpr> function)
Maps the elements of this IAST with the unary functor. If the function returnsnullthe original element of the result list is used.
-
map
public IAST map(IAST resultAST, IAST secondAST, BiFunction<IExpr,IExpr,IExpr> function)
Maps the elements of this IAST with the elements of thesecondAST.
-
replaceAll
public final IExpr replaceAll(IAST astRules)
Replace all (sub-) expressions with the given rule set. If no substitution matches, the method returnsnull.- Specified by:
replaceAllin interfaceIExpr- Parameters:
astRules- rules of the formx->yor{a->b, c->d}; the left-hand-side of the rule can contain pattern objects.- Returns:
nullif 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 returnsnull.- Specified by:
replaceAllin interfaceIExpr- Parameters:
function- if the unary functionsapply()method returnsnullthe expression isn't substituted.- Returns:
nullif no substitution of a (sub-)expression was possible.
-
replacePart
public final IExpr replacePart(IAST astRules)
- Specified by:
replacePartin interfaceIExpr
-
replaceRepeated
public final IExpr replaceRepeated(IAST astRules)
Repeatedly replace all (sub-) expressions with the given rule set. If no substitution matches, the method returnsthis.- Specified by:
replaceRepeatedin interfaceIExpr- Parameters:
astRules- rules of the formx->yor{a->b, c->d}; the left-hand-side of the rule can contain pattern objects.- Returns:
thisif 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 returnsthis.- Specified by:
replaceRepeatedin interfaceIExpr- Parameters:
function- if the unary functionsapply()method returnsnullthe expression isn't substituted.- Returns:
thisif no substitution of a (sub-)expression was possible.
-
replaceSlots
public final IExpr replaceSlots(IAST astSlots)
- Specified by:
replaceSlotsin interfaceIExpr
-
filter
public final IAST filter(IAST filterAST, Predicate<IExpr> predicate)
Apply the predicate to each element in thisASTand append the elements which satisfy the predicate to thefilterAST.
-
filter
public final IAST filter(IAST filterAST, IAST restAST, Predicate<IExpr> predicate)
Apply the predicate to each element in thisASTand append the elements which satisfy the predicate to thefilterAST, or otherwise append it to therestAST.
-
split
public IAST[] split(Predicate<IExpr> predicate)
Apply the predicate to each element in thisASTand append the elements which satisfy the predicate to the0th elementof the result array, or otherwise append it to the1st elementof the result array.
-
split
public IAST[] split(Function<IExpr,IExpr> function)
Apply the function to each element in thisASTand append the result elements for which the function returns non-null elements to the0th elementof the result array, or otherwise append it to the1st elementof the result 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 position0and some optional argument elements at the index positions1..n. Therefore this expression is no atomic expression.- Specified by:
isASTin interfaceIExpr- 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 examplePlus or Times) with attributeOrderlessat index position0and some optional argument elements at the index positions1..n. Examples forOrderlessfunctions arePlus[] or Times[]. Therefore this expression is no atomic expression.- Specified by:
isOrderlessASTin interfaceIExpr- 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 exampleDot, Plus or Times) with attributeFlatat index position0and some optional argument elements at the index positions1..(size()-1). Examples forFlatfunctions areDot[], Plus[] or Times[]. Therefore this expression is no atomic expression.- Specified by:
isFlatASTin interfaceIExpr- 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 position0and some optional argument elements at the index positions1..(size()-1). Therefore this expression is not an atomic expression.- Specified by:
isASTin interfaceIExpr- 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 position0and optional argument elements at the index positions1..(length-1). Therefore this expression is not an atomic expression.- Specified by:
isASTin interfaceIExpr- 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 position0and optional argument elements at the index positions1..(length-1). Therefore this expression is not an atomic expression.- Specified by:
isASTin interfaceIExprargs- the arguments of this AST which should be tested, if they are equal, anullvalue 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 position0and optional argument elements at the index positions1..n.nmust be greater equal than the givenlength. Therefore this expression is no atomic expression.- Specified by:
isASTSizeGEin interfaceIExpr- See Also:
IExpr.isAtom()
-
isAST
public final boolean isAST(java.lang.String symbol)
Test if this expression is an AST list, where the string representation of the header element at index position0equals the givensymboland some optional argument elements at the index positions1..(size()-1). Therefore this expression is no atomic expression. Example:isAST("Sin")givestrueforSin[Pi/2].- Specified by:
isASTin interfaceIExpr- See Also:
IExpr.isAtom()
-
isAST
public final boolean isAST(java.lang.String symbol, int length)Test if this expression is an AST list, where the string representation of the header element at index position0equals the givensymboland some optional argument elements at the index positions1..(length-1). Therefore this expression is no atomic expression. Example:isAST("Sin", 2)givestrueforSin[0].- Specified by:
isASTin interfaceIExpr- See Also:
IExpr.isAtom()
-
isRuleAST
public final boolean isRuleAST()
Test if this expression is of the formRule[<arg1>, <arg2>]orRuleDelayed[<arg1>, <arg2>].
-
isFree
public final boolean isFree(IExpr pattern, boolean heads)
Returnstrue, if all of the elements in the subexpressions or the expression itself, did not match the given pattern.
-
isFree
public final boolean isFree(Predicate<IExpr> predicate, boolean heads)
Returnstrue, if all of the elements in the subexpressions or the expression itself, did not satisfy the given unary predicate.
-
isMember
public boolean isMember(IExpr pattern, boolean heads)
Returnstrue, if at least one of the elements in the subexpressions or the expression itself, match the given pattern.
-
isMember
public final boolean isMember(Predicate<IExpr> predicate, boolean heads)
Returnstrue, if at least one of the elements in the subexpressions or the expression itself, satisfy the given unary predicate.
-
isFunction
public final boolean isFunction()
Test if this expression is aFuntion[ arg1 ]expression with at least 1 argument.- Specified by:
isFunctionin interfaceIExpr
-
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.
-
equals
public boolean equals(java.lang.Object obj)
Description copied from interface:ElementTest if this is equal to b.
-
evaluate
public IExpr evaluate(EvalEngine engine)
Description copied from interface:IExprEvaluate an expression
-
patternHashCode
public final int patternHashCode()
Calculate a special hash value to find a matching rule in a hash table- Specified by:
patternHashCodein interfaceIAST- Returns:
-
isAtom
public final boolean isAtom()
Description copied from interface:IExprTest if this expression is an atomic expression (i.e. no AST expression)
-
copyHead
public final IAST copyHead()
Description copied from interface:IASTCreate a copy of thisIAST, which only contains the head element of the list (i.e. the element with index 0).
-
copyUntil
public final IAST copyUntil(int index)
Description copied from interface:IASTCreate a copy of thisIAST, which contains alls elements up toindex(exclusive).
-
variables2Slots
public final IExpr variables2Slots(java.util.Map<IExpr,IExpr> map, java.util.List<IExpr> variableList)
Description copied from interface:IExprConvert 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:
variables2Slotsin interfaceIExpr- Returns:
nullif 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 java.lang.String fullFormString()
Description copied from interface:IExprReturn the FullForm of this expression- Specified by:
fullFormStringin interfaceIExpr
-
internalFormString
public java.lang.String internalFormString(boolean symbolsAsFactoryMethod, int depth)Description copied from interface:IExprReturn the internal Java form of this expression.- Specified by:
internalFormStringin interfaceIExpr- Parameters:
symbolsAsFactoryMethod- iftrueuse theF.symbol()method, otherwise print the symbol name.depth- the recursion depth of this call.0indicates "recurse without a limit".
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractCollection<IExpr>
-
addAll
public final boolean addAll(java.util.List<? extends IExpr> ast)
Appends all of the arguments (starting from offset1) in the specified AST to the end of this AST.
-
addAll
public boolean addAll(java.util.List<? extends IExpr> ast, int startPosition, int endPosition)
Appends all elements from offsetstartPositiontoendPositionin the specified AST to the end of this AST.
-
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).
-
range
public final ASTRange range()
Get the range of elements [0..sizeOfAST[ of the AST
-
range
public final ASTRange range(int start)
Get the range of elements [start..sizeOfAST[ of the AST
-
range
public final ASTRange range(int start, int end)
Get the range of elements [start..end[ of the AST
-
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(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
-
accept
public final boolean accept(IVisitorBoolean visitor)
Accept a visitor with return typeboolean
-
accept
public final int accept(IVisitorInt visitor)
Accept a visitor with return typeint
-
negative
public final IExpr negative()
Additionalnegativemethod, which works like opposite to fulfill groovy's method signature
-
multiply
public final IExpr multiply(IExpr that)
Multiply this with S.- Specified by:
multiplyin interfaceMonoidElem<IExpr>- Specified by:
multiplyin interfaceIExpr- Returns:
- this * S.
-
getAt
public final IExpr getAt(int index)
Description copied from interface:IExprGet the element at the specifiedindexif this object is of typeIAST.
-
asType
public java.lang.Object asType(java.lang.Class clazz)
-
getInt
public final IInteger getInt(int index)
Casts anIExprat positionindexto anIInteger.- Specified by:
getIntin interfaceIAST- Parameters:
index-- Returns:
- Throws:
WrongArgumentType- if the cast is not possible
-
getNumber
public final INumber getNumber(int index)
Casts anIExprat positionindexto anINumber.- Specified by:
getNumberin interfaceIAST- Parameters:
index-- Returns:
- Throws:
WrongArgumentType- if the cast is not possible
-
getAST
public final IAST getAST(int index)
Casts anIExprat positionindexto anIAST.- Specified by:
getASTin interfaceIAST- Parameters:
index-- Returns:
- Throws:
WrongArgumentType- if the cast is not possible
-
getList
public final IAST getList(int index)
Casts anIExprwhich is a list at positionindexto anIAST.- Specified by:
getListin interfaceIAST- Parameters:
index-- Returns:
- Throws:
WrongArgumentType
-
leaves
public java.util.List<IExpr> leaves()
-
egcd
public IExpr[] egcd(IExpr b)
Description copied from interface:RingElemExtended greatest common divisor.
-
abs
public IExpr abs()
Description copied from interface:AbelianGroupElemAbsolute value of this.- Specified by:
absin interfaceAbelianGroupElem<IExpr>- Returns:
- |this|.
-
isZERO
public final boolean isZERO()
Description copied from interface:AbelianGroupElemTest if this is zero.- Specified by:
isZEROin interfaceAbelianGroupElem<IExpr>- Returns:
- true if this is 0, else false.
-
signum
@Deprecated public int signum()
Deprecated.Signum functionality is used in JAS toString() method, don't use it as math signum function.- Specified by:
signumin interfaceAbelianGroupElem<IExpr>- Specified by:
signumin interfaceIExpr- Returns:
- the sign of this.
-
subtract
public IExpr subtract(IExpr that)
Description copied from interface:AbelianGroupElemSubtract S from this.- Specified by:
subtractin interfaceAbelianGroupElem<IExpr>- Returns:
- this - S.
-
sum
public IExpr sum(IExpr that)
Description copied from interface:AbelianGroupElemSum of this and S.- Specified by:
sumin interfaceAbelianGroupElem<IExpr>- Returns:
- this + S.
-
factory
public ElemFactory<IExpr> factory()
Description copied from interface:ElementGet the corresponding element factory.
-
toScript
public final java.lang.String toScript()
Description copied from interface:ElementGet a scripting compatible string representation.
-
toScriptFactory
public final java.lang.String toScriptFactory()
Description copied from interface:ElementGet a scripting compatible string representation of the factory.- Specified by:
toScriptFactoryin interfaceElement<IExpr>- Returns:
- script compatible representation for this ElemFactory.
-
divide
public IExpr divide(IExpr that)
Divide this by S.- Specified by:
dividein interfaceMonoidElem<IExpr>- Returns:
- this / S.
-
isONE
public final boolean isONE()
Test if this is one.- Specified by:
isONEin interfaceMonoidElem<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:
isUnitin interfaceMonoidElem<IExpr>- Returns:
- true if this is a unit, else false.
-
isValue
public final boolean isValue()
Returnstrue, if this symbol or ast expression is bound to a value (i.e. the evaluation returns an assigned value).
-
remainder
public IExpr remainder(IExpr S)
Description copied from interface:MonoidElemRemainder after division of this by S.- Specified by:
remainderin interfaceMonoidElem<IExpr>- Returns:
- this - (this / S) * S.
-
negate
public final IExpr negate()
Description copied from interface:AbelianGroupElemNegate this.- Specified by:
negatein interfaceAbelianGroupElem<IExpr>- Returns:
- - this.
-
head
public final IExpr head()
Description copied from interface:IExprIf this object is an instance ofIASTget the first element (offset 0) of theIASTlist (i.e. get(0) ).
-
iterator
public java.util.Iterator<IExpr> iterator()
Returns an iterator over the elements in thisIASTstarting with offset 1.- Specified by:
iteratorin interfacejava.lang.Iterable<IExpr>- Specified by:
iteratorin interfacejava.util.Collection<IExpr>- Specified by:
iteratorin interfacejava.util.List<IExpr>- Specified by:
iteratorin interfaceIAST- Overrides:
iteratorin classjava.util.AbstractList<IExpr>- Returns:
- an iterator over this
IASTs argument values from1..(size-1).
-
iterator0
public java.util.Iterator<IExpr> iterator0()
Description copied from interface:IASTReturns an iterator over the elements in this list starting with offset 0.
-
arg1
public final IExpr arg1()
Get the first argument (i.e. the second element of the underlying list structure) of theASTfunction (i.e. get(1) ).- Specified by:
arg1in interfaceIAST- 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 theASTfunction (i.e. get(2) ).- Specified by:
arg2in interfaceIAST- 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 theASTfunction (i.e. get(3) ).- Specified by:
arg3in interfaceIAST- 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 theASTlist (i.e. get(size()-1).- Specified by:
lastin interfaceIAST- 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:IASTAppend an expression to this list.
-
-
DMelt 3.0 © DataMelt by jWork.ORG