org.matheclipse.core.interfaces
Interface IAST
-
- All Superinterfaces:
- AbelianGroupElem<IExpr>, java.lang.Cloneable, java.util.Collection<IExpr>, java.lang.Comparable<IExpr>, Element<IExpr>, IExpr, java.lang.Iterable<IExpr>, java.util.List<IExpr>, MonoidElem<IExpr>, RingElem<IExpr>, java.io.Serializable
- All Known Implementing Classes:
- AST
public interface IAST extends IExpr, java.util.List<IExpr>, java.lang.Cloneable
(I)nterface for the (A)bstract (S)yntax (T)ree of a given function.
In MathEclipse, an abstract syntax tree (AST), is a tree representation of the abstract syntactic structure of the MathEclipse 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
-
-
Field Summary
Fields Modifier and Type Field and Description static intCONTAINS_DEFAULT_PATTERNOne of the arguments of the list contains a pattern object which can be set to a default value.static intCONTAINS_NO_DEFAULT_PATTERN_MASKNegative flag mask for CONTAINS_DEFAULT_PATTERNstatic intCONTAINS_PATTERNThe head or one of the arguments of the list or sublists contains a pattern objectstatic intCONTAINS_PATTERN_EXPROne of the arguments of the list or sublists contains a pattern object.static intCONTAINS_PATTERN_SEQUENCEThe head or one of the arguments of the list or sublists contains a pattern objectstatic intIS_DECOMPOSED_PARTIAL_FRACTIONThis expression represents an already decomposed partial fractionstatic intIS_FLATTENEDThis expression is an already flattened expressionstatic intIS_FLATTENED_OR_SORTED_MASKThis expression is an already flattened or sorted expressionstatic intIS_LISTABLE_THREADEDThis expression has already applied the Listable attribute to its argument expressionsstatic intIS_MATRIXThis expression represents a matrixstatic intIS_MATRIX_OR_VECTORThis expression represents a matrix or vector if one of the following bits is set.static intIS_SORTEDThis expression is an already sorted expressionstatic intIS_VECTORThis expression represents a vectorstatic intNO_FLAGNO_FLAG ACTIVATED-
Fields inherited from interface org.matheclipse.core.interfaces.IExpr
ASTID, COMPLEXID, DOUBLECOMPLEXID, DOUBLEID, FRACTIONID, INTEGERID, METHODSYMBOLID, PATTERNID, STRINGID, SYMBOLID
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description booleanaddAll(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 subAST)Add ansubASTwith attributeOneIdentityfor example Plus[] or Times[].IASTappend(IExpr expr)Append an expression to this list.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.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()[.IASTclone()Returns a shallow copy of thisIASTinstance (the elements themselves are not copied).IASTcloneSet(int position, IExpr expr)Returns a shallow copy of thisIASTinstance (the elements themselves are not copied) and set theexprat the givenposition.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).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.IASTgetAST(int index)Casts anIExprat positionindexto anIAST.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).booleanisEvalFlagOff(int i)Are the given evaluation flags disabled for this list ?booleanisEvalFlagOn(int i)Are the given evaluation flags enabled for this list ?booleanisList()Is this a list (i.e.booleanisPlus()Test if this expression is the addition functionPlus[<arg1>, <arg2>, ...]booleanisPower()Test if this expression is the functionPower[<arg1>, <arg2>]booleanisTimes()Test if this expression is the multiplication functionTimes[<arg1>, <arg2>, ...]java.util.Iterator<IExpr>iterator()Returns an iterator over the elements in this list starting 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.IASTmap(Function<IExpr,IExpr> functor)Maps the elements of this IAST with the unary functor.IASTmap(IAST clonedResultAST, Function<IExpr,IExpr> functor)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> functor)Maps the elements of this IAST with the unary functor.intpatternHashCode()Calculate a special hash value for pattern matchingIASTprepend(IExpr expr)Prepend an expression to this list.ASTRangerange()Get the range of elements [0..ast.size()[ of the AST.ASTRangerange(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 ASTvoidsetEvalFlags(int i)Set the evaluation flags for this list.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.ISymboltopHead()Returns the header.-
Methods inherited from interface org.matheclipse.core.interfaces.IExpr
accept, accept, accept, and, apply, apply, asType, compareTo, evaluate, fullFormString, getAt, head, hierarchy, internalFormString, inverse, isAnd, isArcCos, isArcCosh, isArcSin, isArcSinh, isArcTan, isArcTanh, isAST, isAST, isAST, isAST, isAST, isAST, isASTSizeGE, isAtom, isComplex, isComplexInfinity, isComplexNumeric, isCondition, isConstant, isCos, isCosh, isDirectedInfinity, isFalse, isFlatAST, isFraction, isFree, isFree, isFunction, isGEOrdered, isGTOrdered, isInfinity, isInteger, isLEOrdered, isListOfLists, isLog, isLTOrdered, isMatrix, isMember, isMember, isMinusOne, isModule, isNegative, isNegativeInfinity, isNot, isNumber, isNumEqualInteger, isNumeric, isNumericFunction, isNumIntValue, isOne, isOr, isOrderlessAST, isPattern, isPatternExpr, isPatternSequence, isPositive, isRational, isRealFunction, isRuleAST, isSame, isSame, isSequence, isSignedNumber, isSin, isSinh, isSlot, isSlotSequence, isSymbol, isTan, isTanh, isTrue, isValue, isVector, isZero, leaves, minus, mod, multiply, negative, or, plus, power, power, replaceAll, replaceAll, replacePart, replaceRepeated, replaceRepeated, replaceSlots, signum, times, variables2Slots
-
Methods inherited from interface edu.jas.structure.AbelianGroupElem
abs, isZERO, negate, subtract, sum
-
Methods inherited from interface edu.jas.structure.MonoidElem
divide, isONE, isUnit, remainder
-
Methods inherited from interface edu.jas.structure.Element
copy, equals, factory, hashCode, toScript, toScriptFactory
-
-
-
-
Field Detail
-
NO_FLAG
static final int NO_FLAG
NO_FLAG ACTIVATED- See Also:
- Constant Field Values
-
CONTAINS_PATTERN
static final int CONTAINS_PATTERN
The head or one of the arguments of the list or sublists contains a pattern object- See Also:
- Constant Field Values
-
CONTAINS_PATTERN_SEQUENCE
static final int CONTAINS_PATTERN_SEQUENCE
The head or one of the arguments of the list or sublists contains a pattern object- See Also:
- Constant Field Values
-
CONTAINS_DEFAULT_PATTERN
static final int CONTAINS_DEFAULT_PATTERN
One of the arguments of the list contains a pattern object which can be set to a default value.- See Also:
- Constant Field Values
-
CONTAINS_PATTERN_EXPR
static final int CONTAINS_PATTERN_EXPR
One of the arguments of the list or sublists contains a pattern object. Combination ofCONTAINS_PATTERN, CONTAINS_PATTERN_SEQUENCE, CONTAINS_DEFAULT_PATTERN- See Also:
- Constant Field Values
-
CONTAINS_NO_DEFAULT_PATTERN_MASK
static final int CONTAINS_NO_DEFAULT_PATTERN_MASK
Negative flag mask for CONTAINS_DEFAULT_PATTERN- See Also:
- Constant Field Values
-
IS_MATRIX
static final int IS_MATRIX
This expression represents a matrix- See Also:
- Constant Field Values
-
IS_VECTOR
static final int IS_VECTOR
This expression represents a vector- See Also:
- Constant Field Values
-
IS_MATRIX_OR_VECTOR
static final int IS_MATRIX_OR_VECTOR
This expression represents a matrix or vector if one of the following bits is set.- See Also:
- Constant Field Values
-
IS_DECOMPOSED_PARTIAL_FRACTION
static final int IS_DECOMPOSED_PARTIAL_FRACTION
This expression represents an already decomposed partial fraction- See Also:
Apart, Constant Field Values
-
IS_FLATTENED
static final int IS_FLATTENED
This expression is an already flattened expression- See Also:
- Constant Field Values
-
IS_SORTED
static final int IS_SORTED
This expression is an already sorted expression- See Also:
- Constant Field Values
-
IS_LISTABLE_THREADED
static final int IS_LISTABLE_THREADED
This expression has already applied the Listable attribute to its argument expressions- See Also:
- Constant Field Values
-
IS_FLATTENED_OR_SORTED_MASK
static final int IS_FLATTENED_OR_SORTED_MASK
This expression is an already flattened or sorted expression- See Also:
- Constant Field Values
-
-
Method Detail
-
getEvalFlags
int getEvalFlags()
Get the evaluation flags for this list.- Returns:
-
topHead
ISymbol topHead()
Returns the header. If the header itself is an ISymbol it will return the symbol object. If the header itself is an IAST it will recursively call headSymbol(). If the head is of type INumbers, the head will return one of these headers: "DoubleComplex", "Double", "Integer", "Fraction", "Complex". All other objects returnnull.
-
isEvalFlagOff
boolean isEvalFlagOff(int i)
Are the given evaluation flags disabled for this list ?- Returns:
-
isEvalFlagOn
boolean isEvalFlagOn(int i)
Are the given evaluation flags enabled for this list ?- Returns:
-
setEvalFlags
void setEvalFlags(int i)
Set the evaluation flags for this list.- Parameters:
i-
-
addEvalFlags
void addEvalFlags(int i)
Add an evaluation flag to the existing ones.- Parameters:
i-
-
addOneIdentity
IAST addOneIdentity(IAST subAST)
Add ansubASTwith attributeOneIdentityfor example Plus[] or Times[].- Parameters:
subAST- an ast with attributeOneIdentity.- Returns:
thisast after adding the subAST
-
getOneIdentity
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).- Parameters:
defaultValue- default value, ifsize() < 2.- Returns:
-
addAll
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.- Parameters:
ast- AST containing elements to be added to this ASTstartPosition- 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)
-
addAll
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.- 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)
-
isList
boolean isList()
Is this a list (i.e. with header == List)
-
isPlus
boolean isPlus()
Test if this expression is the addition functionPlus[<arg1>, <arg2>, ...]
-
isPower
boolean isPower()
Test if this expression is the functionPower[<arg1>, <arg2>]
-
isTimes
boolean isTimes()
Test if this expression is the multiplication functionTimes[<arg1>, <arg2>, ...]
-
iterator
java.util.Iterator<IExpr> iterator()
Returns an iterator over the elements in this list starting with offset 1.
-
iterator0
java.util.Iterator<IExpr> iterator0()
Returns an iterator over the elements in this list starting with offset 0.- Returns:
- an iterator over this list values.
-
arg1
IExpr arg1()
Get the first argument (i.e. the second element of the underlying list structure) of theASTfunction (i.e. get(1) ).- Returns:
- the first argument of the function represented by this
AST. - See Also:
IExpr.head()
-
arg2
IExpr arg2()
Get the second argument (i.e. the third element of the underlying list structure) of theASTfunction (i.e. get(2) ).- Returns:
- the second argument of the function represented by this
AST. - See Also:
IExpr.head()
-
arg3
IExpr arg3()
Get the third argument (i.e. the fourth element of the underlying list structure) of theASTfunction (i.e. get(3) ).- Returns:
- the third argument of the function represented by this
AST. - See Also:
IExpr.head()
-
last
IExpr last()
Get the last element of theASTlist (i.e. get(size()-1).- Returns:
- the last argument of the function represented by this
AST. - See Also:
IExpr.head()
-
apply
IAST apply(IExpr head)
Apply the given head to this expression (i.e. create a list clone and replace the old head with the given one)- Parameters:
head-- Returns:
-
apply
IAST apply(IExpr head, int start)
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)- Parameters:
head-- Returns:
-
apply
IAST apply(IExpr head, int start, int end)
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)- Parameters:
head-- Returns:
-
map
IAST map(Function<IExpr,IExpr> functor)
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))));
- Parameters:
functor- a unary function- Returns:
-
map
IAST map(IExpr head, Function<IExpr,IExpr> functor)
Maps the elements of this IAST with the unary functor. If the function returnsnullthe original element of the result list is used.- Parameters:
head- the new head element of the result listfunctor- a unary function- Returns:
-
map
IAST map(IAST clonedResultAST, Function<IExpr,IExpr> functor)
Maps the elements of this IAST with the unary functor. If the function returnsnullthe original element of the result list is used.- Parameters:
clonedResultAST- a list which is cloned fromthislist or greater or equal in size ofthislist.functor- a unary function- Returns:
-
map
IAST map(IAST resultAST, IAST secondAST, BiFunction<IExpr,IExpr,IExpr> function)
Maps the elements of this IAST with the elements of thesecondAST.- Parameters:
functor- a binary function- Returns:
- the given resultAST.
- Throws:
java.lang.IndexOutOfBoundsException- if the secondAST size is lesser than this AST size
-
filter
IAST filter(IAST filterAST, Predicate<IExpr> predicate)
Apply the predicate to each element in thisASTand append the elements which satisfy the predicate to thefilterAST.- Parameters:
filterAST- the elements which satisfy the predicatepredicate- the predicate which filters each element in the range- Returns:
- the
filterList
-
filter
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.- Parameters:
filterAST- the elements satisfy match the predicaterestAST- the elements which don't match the predicatepredicate- the predicate which filters each element in the range- Returns:
- the
filterList
-
split
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.- 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
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.- 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
-
clone
IAST clone()
Returns a shallow copy of thisIASTinstance (the elements themselves are not copied).- Returns:
- a clone of this
IASTinstance.
-
append
IAST append(IExpr expr)
Append an expression to this list.- Returns:
thisafter appending the given expression.
-
cloneSet
IAST cloneSet(int position, IExpr expr)
Returns a shallow copy of thisIASTinstance (the elements themselves are not copied) and set theexprat the givenposition.- Returns:
- a clone of this
IASTinstance.
-
copyHead
IAST copyHead()
Create a copy of thisIAST, which only contains the head element of the list (i.e. the element with index 0).
-
copyUntil
IAST copyUntil(int index)
Create a copy of thisIAST, which contains alls elements up toindex(exclusive).
-
patternHashCode
int patternHashCode()
Calculate a special hash value for pattern matching- Returns:
-
prepend
IAST prepend(IExpr expr)
Prepend an expression to this list.- Returns:
thisafter prepending the given expression.
-
args
ASTRange args()
Get the range of elements [1..ast.size()[. These range elements are the arguments of a function (represented as an AST).- Returns:
-
range
ASTRange range()
Get the range of elements [0..ast.size()[ of the AST. This range elements are the head of the function prepended by the arguments of a function.- Returns:
-
range
ASTRange range(int start)
Get the range of elements [start..sizeOfAST[ of the AST- Returns:
-
range
ASTRange range(int start, int end)
Get the range of elements [start..end[ of the AST- Returns:
-
getInt
IInteger getInt(int index)
Casts anIExprat positionindexto anIInteger.- Parameters:
index-- Returns:
- Throws:
WrongArgumentType- if the cast is not possible
-
getNumber
INumber getNumber(int index)
Casts anIExprat positionindexto anINumber.- Parameters:
index-- Returns:
- Throws:
WrongArgumentType- if the cast is not possible
-
getAST
IAST getAST(int index)
Casts anIExprat positionindexto anIAST.- Parameters:
index-- Returns:
- Throws:
WrongArgumentType- if the cast is not possible
-
getList
IAST getList(int index)
Casts anIExprwhich is a list at positionindexto anIAST.- Parameters:
index-- Returns:
- Throws:
WrongArgumentType
-
-
DMelt 3.0 © DataMelt by jWork.ORG