org.matheclipse.core.expression
Class Symbol
- java.lang.Object
-
- org.matheclipse.core.expression.ExprImpl
-
- org.matheclipse.core.expression.Symbol
-
- All Implemented Interfaces:
- AbelianGroupElem<IExpr>, Element<IExpr>, MonoidElem<IExpr>, RingElem<IExpr>, java.io.Serializable, java.lang.Comparable<IExpr>, IExpr, ISymbol
- Direct Known Subclasses:
- MethodSymbol
public class Symbol extends ExprImpl implements ISymbol
Implements Symbols for function, constant and variable names- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.matheclipse.core.interfaces.ISymbol
CONSOLE_OUTPUT, CONSTANT, DEFAULT_RULE_PRIORITY, FLAT, FLATORDERLESS, HOLDALL, HOLDFIRST, HOLDREST, LISTABLE, NHOLDALL, NHOLDFIRST, NHOLDREST, NOATTRIBUTE, NUMERICFUNCTION, ONEIDENTITY, ORDERLESS, PACKAGE_LOADED
-
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 Symbol(java.lang.String symbolName)Symbol(java.lang.String symbolName, IEvaluator evaluator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description <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 typeintIExprapply(IExpr... expressions)voidclear(EvalEngine engine)Clear the associated rules for this symbolvoidclearAll(EvalEngine engine)Clear all associated rules and attributes for this symbolintcompareTo(IExpr obj)Compares this expression with the specified expression for order.java.util.List<IAST>definition()Return a list of the rules associated to this symboljava.lang.StringdefinitionToString()Return the rules associated to this symbol in String representationbooleanequals(java.lang.Object obj)Test if this is equal to b.IExprevalDownRule(IEvaluationEngine ee, IExpr expression)Evaluate the given expression for the "down value" rules associated with this symbolIExprevaluate(EvalEngine engine)Evaluate an expressionIExprevalUpRule(IEvaluationEngine ee, IExpr expression)Evaluate the given expression for the "up value" rules associated with this symboljava.lang.StringfullFormString()Return the FullForm of this expressionIExprget()Get the topmost value from the local variable stackIExprgetAssignedValue()Get the value which is assigned to the symbol ornull, if no value is assigned.intgetAttributes()Get the Attributes of this symbol (i.e.IExprgetDefaultValue()Get the general default value for this symbol (i.e.IExprgetDefaultValue(int pos)Get the default value at the arguments position for this symbol (i.e.IEvaluatorgetEvaluator()Get the current evaluator for this symboljava.lang.StringgetSymbol()inthashCode()Hashcode of this Element.booleanhasLocalVariableStack()Is a local variable stack created for this symbol ?ISymbolhead()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.booleanisAtom()Test if this expression is an atomic expression (i.e.booleanisConstant()Test if this expression is a symbol with attributeConstant.booleanisFalse()Test if this expression equals the symbol "False"booleanisNegative()Test if this object is a negative signed number.booleanisPositive()Test if this object is a positive signed number.booleanisString(java.lang.String str)Tests if this symbols name equals the given stringbooleanisSymbolName(java.lang.String name)Returnstrue, if this symbol has the given name.booleanisTrue()Test if this expression equals the symbol "True"booleanisValue()Returnstrue, if this symbol or ast expression is bound to a value (i.e.IExprmapConstantDouble(INumericFunction<IExpr> function)If this symbol has attributeISymbol.CONSTANTand the symbol's evaluator is of instanceINumericConstant, then apply the constants double value to the given function and return the result, otherwise returnnull.IExprnegate()Negate this.voidpopLocalVariable()Delete the topmost placeholder from the local variable stackvoidpushLocalVariable()Create a new variable placeholder on the symbols variable stackvoidpushLocalVariable(IExpr expression)Create a new variable placeholder on the symbols variable stack and set the local valueIPatternMatcherputDownRule(ISymbol symbol, boolean equalRule, IExpr leftHandSide, IExpr rightHandSide, boolean packageMode)Associate a new "down value" rule with default priority to this symbol.IPatternMatcherputDownRule(ISymbol setSymbol, boolean equalRule, IExpr leftHandSide, IExpr rightHandSide, int priority, boolean packageMode)Associate a new rule with the given priority to this symbol.
Rules with lower numbers have higher priorities.PatternMatcherputDownRule(PatternMatcherAndInvoker pmEvaluator)Associate a new rule, which invokes a method, to this symbol.IPatternMatcherputUpRule(ISymbol symbol, boolean equalRule, IAST leftHandSide, IExpr rightHandSide)Associate a new "up value" rule with default priority to this symbol.IPatternMatcherputUpRule(ISymbol setSymbol, boolean equalRule, IAST leftHandSide, IExpr rightHandSide, int priority)Associate a new "up value" rule with the given priority to this symbol.
Rules with lower numbers have higher priorities.voidreadSymbol(java.io.ObjectInputStream stream)Deserialize the rules associated to this objectIExpr[]reassignSymbolValue(Function<IExpr,IExpr> function, ISymbol functionSymbol)Apply the function to the currently assigned value of the symbol and reassign the result value to the symbol.voidset(IExpr value)Set the value of the local variable on top of the local variable stackvoidsetAttributes(int attributes)Set the Attributes of this symbol (i.e.voidsetDefaultValue(IExpr expr)Set the general default value for this symbol (i.e.voidsetDefaultValue(int pos, IExpr expr)Set the default value at the arguments position for this symbol (i.e.voidsetEvaluator(IEvaluator evaluator)Set the current evaluator which is associated to this symboljava.lang.StringtoString()IExprvariables2Slots(java.util.Map<IExpr,IExpr> map, java.util.List<IExpr> variableList)Convert the variables (i.e.voidwriteSymbol(java.io.ObjectOutputStream stream)Serialize the rules associated to this object-
Methods inherited from class org.matheclipse.core.expression.ExprImpl
abs, and, apply, asType, copy, divide, egcd, factory, gcd, getAt, inverse, isAnd, isArcCos, isArcCosh, isArcSin, isArcSinh, isArcTan, isArcTanh, isAST, isAST, isAST, isAST, isAST, isAST, isASTSizeGE, isComplex, isComplexInfinity, isComplexNumeric, isCondition, isCos, isCosh, isDirectedInfinity, isFlatAST, isFraction, isFree, isFree, isFunction, isGEOrdered, isGTOrdered, isInfinity, isInteger, isLEOrdered, isList, isListOfLists, isLog, isLTOrdered, isMatrix, isMember, isMember, isMinusOne, isModule, isNegativeInfinity, isNot, isNumber, isNumEqualInteger, isNumeric, isNumericFunction, isNumIntValue, isOne, isONE, isOr, isOrderlessAST, isPattern, isPatternExpr, isPatternSequence, isPlus, isPower, isRational, isRealFunction, isRuleAST, isSame, isSame, isSequence, isSignedNumber, isSin, isSinh, isSlot, isSlotSequence, isSymbol, isTan, isTanh, isTimes, isUnit, isVector, isZero, isZERO, leaves, minus, mod, multiply, negative, opposite, or, plus, power, power, remainder, replaceAll, replaceAll, replacePart, replaceRepeated, replaceRepeated, replaceRepeated, replaceSlots, signum, subtract, sum, times, topHead, toScript, toScriptFactory
-
Methods inherited from interface org.matheclipse.core.interfaces.IExpr
and, apply, asType, getAt, inverse, isAnd, isArcCos, isArcCosh, isArcSin, isArcSinh, isArcTan, isArcTanh, isAST, isAST, isAST, isAST, isAST, isAST, isASTSizeGE, isComplex, isComplexInfinity, isComplexNumeric, isCondition, isCos, isCosh, isDirectedInfinity, isFlatAST, isFraction, isFree, isFree, isFunction, isGEOrdered, isGTOrdered, isInfinity, isInteger, isLEOrdered, isList, isListOfLists, isLog, isLTOrdered, isMatrix, isMember, isMember, isMinusOne, isModule, isNegativeInfinity, isNot, isNumber, isNumEqualInteger, isNumeric, isNumericFunction, isNumIntValue, isOne, isOr, isOrderlessAST, isPattern, isPatternExpr, isPatternSequence, isPlus, isPower, isRational, isRealFunction, isRuleAST, isSame, isSame, isSequence, isSignedNumber, isSin, isSinh, isSlot, isSlotSequence, isSymbol, isTan, isTanh, isTimes, isVector, isZero, leaves, minus, mod, multiply, negative, or, plus, power, power, replaceAll, replaceAll, replacePart, replaceRepeated, replaceRepeated, replaceSlots, signum, times, topHead
-
Methods inherited from interface edu.jas.structure.AbelianGroupElem
abs, isZERO, subtract, sum
-
Methods inherited from interface edu.jas.structure.MonoidElem
divide, isONE, isUnit, remainder
-
Methods inherited from interface edu.jas.structure.Element
copy, factory, toScript, toScriptFactory
-
-
-
-
Constructor Detail
-
Symbol
public Symbol(java.lang.String symbolName)
-
Symbol
public Symbol(java.lang.String symbolName, IEvaluator evaluator)
-
-
Method Detail
-
reassignSymbolValue
public IExpr[] reassignSymbolValue(Function<IExpr,IExpr> function, ISymbol functionSymbol)
Apply the function to the currently assigned value of the symbol and reassign the result value to the symbol.- Specified by:
reassignSymbolValuein interfaceISymbol- Parameters:
function- the function which should be appliedfunctionSymbol- TODO- Returns:
- an array with the currently assigned value of the symbol and the new calculated value of the symbol or
nullif the reassignment isn't possible.
-
getAssignedValue
public IExpr getAssignedValue()
Get the value which is assigned to the symbol ornull, if no value is assigned.- Specified by:
getAssignedValuein interfaceISymbol- Returns:
null, if no value is assigned.
-
pushLocalVariable
public void pushLocalVariable()
Create a new variable placeholder on the symbols variable stack- Specified by:
pushLocalVariablein interfaceISymbol
-
pushLocalVariable
public void pushLocalVariable(IExpr expression)
Create a new variable placeholder on the symbols variable stack and set the local value- Specified by:
pushLocalVariablein interfaceISymbol
-
popLocalVariable
public void popLocalVariable()
Delete the topmost placeholder from the local variable stack- Specified by:
popLocalVariablein interfaceISymbol
-
clear
public void clear(EvalEngine engine)
Clear the associated rules for this symbol
-
clearAll
public void clearAll(EvalEngine engine)
Clear all associated rules and attributes for this symbol
-
equals
public boolean equals(java.lang.Object obj)
Test if this is equal to b.
-
isSymbolName
public boolean isSymbolName(java.lang.String name)
Description copied from interface:ISymbolReturnstrue, if this symbol has the given name. The comparison of the symbols name with the given name is done according to theConfig.PARSER_USE_LOWERCASE_SYMBOLSsetting.- Specified by:
isSymbolNamein interfaceISymbol
-
evaluate
public IExpr evaluate(EvalEngine engine)
Evaluate an expression
-
evalDownRule
public IExpr evalDownRule(IEvaluationEngine ee, IExpr expression)
Evaluate the given expression for the "down value" rules associated with this symbol- Specified by:
evalDownRulein interfaceISymbol- Returns:
-
evalUpRule
public IExpr evalUpRule(IEvaluationEngine ee, IExpr expression)
Evaluate the given expression for the "up value" rules associated with this symbol- Specified by:
evalUpRulein interfaceISymbol- Returns:
-
getAttributes
public final int getAttributes()
Get the Attributes of this symbol (i.e. LISTABLE, FLAT, ORDERLESS,...)- Specified by:
getAttributesin interfaceISymbol- Returns:
- See Also:
ISymbol.FLAT
-
getEvaluator
public IEvaluator getEvaluator()
Get the current evaluator for this symbol- Specified by:
getEvaluatorin interfaceISymbol- Returns:
- the evaluator which is associated to this symbol or
nullif no evaluator is associated
-
hasLocalVariableStack
public boolean hasLocalVariableStack()
Is a local variable stack created for this symbol ?- Specified by:
hasLocalVariableStackin interfaceISymbol- Returns:
trueif this symbol has a local variable stack
-
get
public IExpr get()
Get the topmost value from the local variable stack
-
set
public void set(IExpr value)
Set the value of the local variable on top of the local variable stack
-
hashCode
public int hashCode()
Hashcode of this Element.
-
hierarchy
public int hierarchy()
A unique integer ID for the implementation of this expression
-
isString
public final boolean isString(java.lang.String str)
Tests if this symbols name equals the given string
-
putDownRule
public IPatternMatcher putDownRule(ISymbol symbol, boolean equalRule, IExpr leftHandSide, IExpr rightHandSide, boolean packageMode)
Associate a new "down value" rule with default priority to this symbol.- Specified by:
putDownRulein interfaceISymbolequalRule-trueif the leftHandSide could be matched with equalitypackageMode- TODO- Returns:
- See Also:
ISymbol.DEFAULT_RULE_PRIORITY
-
putDownRule
public IPatternMatcher putDownRule(ISymbol setSymbol, boolean equalRule, IExpr leftHandSide, IExpr rightHandSide, int priority, boolean packageMode)
Associate a new rule with the given priority to this symbol.
Rules with lower numbers have higher priorities.- Specified by:
putDownRulein interfaceISymbolequalRule-trueif the leftHandSide could be matched with equalitypriority- the priority of the rulepackageMode- TODO- Returns:
- See Also:
ISymbol.DEFAULT_RULE_PRIORITY
-
putDownRule
public PatternMatcher putDownRule(PatternMatcherAndInvoker pmEvaluator)
Associate a new rule, which invokes a method, to this symbol.- Specified by:
putDownRulein interfaceISymbol
-
putUpRule
public IPatternMatcher putUpRule(ISymbol symbol, boolean equalRule, IAST leftHandSide, IExpr rightHandSide)
Associate a new "up value" rule with default priority to this symbol.- Specified by:
putUpRulein interfaceISymbolequalRule-trueif the leftHandSide could be matched with equality- Returns:
- See Also:
ISymbol.DEFAULT_RULE_PRIORITY
-
putUpRule
public IPatternMatcher putUpRule(ISymbol setSymbol, boolean equalRule, IAST leftHandSide, IExpr rightHandSide, int priority)
Associate a new "up value" rule with the given priority to this symbol.
Rules with lower numbers have higher priorities.- Specified by:
putUpRulein interfaceISymbolequalRule-trueif the leftHandSide could be matched with equalitypriority- the priority of the rule- Returns:
- See Also:
ISymbol.DEFAULT_RULE_PRIORITY
-
setAttributes
public void setAttributes(int attributes)
Set the Attributes of this symbol (i.e. LISTABLE, FLAT, ORDERLESS,...)- Specified by:
setAttributesin interfaceISymbol- Parameters:
attributes- the Attributes of this symbol
-
setEvaluator
public final void setEvaluator(IEvaluator evaluator)
Set the current evaluator which is associated to this symbol- Specified by:
setEvaluatorin interfaceISymbol
-
compareTo
public int compareTo(IExpr obj)
Compares this expression with the specified expression for 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.
-
isAtom
public final boolean isAtom()
Test if this expression is an atomic expression (i.e. no AST expression)
-
isConstant
public boolean isConstant()
Test if this expression is a symbol with attributeConstant. Therefore numbers returnfalsefor this method!- Specified by:
isConstantin interfaceIExpr- Overrides:
isConstantin classExprImpl- See Also:
IExpr.isRealFunction(),IExpr.isNumericFunction()
-
isTrue
public boolean isTrue()
Test if this expression equals the symbol "True"
-
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).
-
isFalse
public boolean isFalse()
Test if this expression equals the symbol "False"
-
isNegative
public boolean isNegative()
Test if this object is a negative signed number.- Specified by:
isNegativein interfaceIExpr- Overrides:
isNegativein classExprImpl- Returns:
true, ifthis < 0;falsein all other case.
-
isPositive
public boolean isPositive()
Test if this object is a positive signed number.- Specified by:
isPositivein interfaceIExpr- Overrides:
isPositivein classExprImpl- Returns:
true, ifthis > 0;falsein all other case.
-
head
public ISymbol head()
If this object is an instance ofIASTget the first element (offset 0) of theIASTlist (i.e. get(0) ).
-
getSymbol
public final java.lang.String getSymbol()
-
variables2Slots
public 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- Overrides:
variables2Slotsin classExprImpl- 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.
-
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- Overrides:
internalFormStringin classExprImpl- 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.lang.Object
-
fullFormString
public java.lang.String fullFormString()
Return the FullForm of this expression- Specified by:
fullFormStringin interfaceIExpr- Overrides:
fullFormStringin classExprImpl
-
definition
public java.util.List<IAST> definition()
Return a list of the rules associated to this symbol- Specified by:
definitionin interfaceISymbol- Returns:
-
getDefaultValue
public IExpr getDefaultValue()
Get the general default value for this symbol (i.e.1is the default value forTimes,0is the default value forPlus). The general default value is used in pattern-matching for expressions likea_. * b_. + c_- Specified by:
getDefaultValuein interfaceISymbol- Returns:
- the default value or
nullif undefined.
-
getDefaultValue
public IExpr getDefaultValue(int pos)
Get the default value at the arguments position for this symbol (i.e.1is the default value forPoweratposition2). The default value is used in pattern-matching for expressions likea ^ b_.- Specified by:
getDefaultValuein interfaceISymbol- Parameters:
pos- the position for the default value- Returns:
- the default value or
nullif undefined.
-
setDefaultValue
public void setDefaultValue(IExpr expr)
Set the general default value for this symbol (i.e.1is the default value forTimes,0is the default value forPlus). The general default value is used in pattern-matching for expressions likea_. * b_. + c_- Specified by:
setDefaultValuein interfaceISymbol- Parameters:
expr- the general default value- See Also:
ISymbol.getDefaultValue()
-
setDefaultValue
public void setDefaultValue(int pos, IExpr expr)Set the default value at the arguments position for this symbol (i.e.1is the default value forPoweratposition2). The default value is used in pattern-matching for expressions likea ^ b_.- Specified by:
setDefaultValuein interfaceISymbol- Parameters:
pos- the position for the default valueexpr- the default value for the given position- See Also:
ISymbol.getDefaultValue(int)
-
definitionToString
public java.lang.String definitionToString() throws java.io.IOExceptionReturn the rules associated to this symbol in String representation- Specified by:
definitionToStringin interfaceISymbol- Returns:
- Throws:
java.io.IOException
-
readSymbol
public void readSymbol(java.io.ObjectInputStream stream) throws java.io.IOExceptionDeserialize the rules associated to this object- Specified by:
readSymbolin interfaceISymbol- Throws:
java.io.IOException
-
writeSymbol
public void writeSymbol(java.io.ObjectOutputStream stream) throws java.io.IOExceptionSerialize the rules associated to this object- Specified by:
writeSymbolin interfaceISymbol- Throws:
java.io.IOException
-
accept
public <T> T accept(IVisitor<T> visitor)
Accept a visitor with return type T
-
accept
public boolean accept(IVisitorBoolean visitor)
Accept a visitor with return typeboolean
-
accept
public int accept(IVisitorInt visitor)
Accept a visitor with return typeint
-
mapConstantDouble
public IExpr mapConstantDouble(INumericFunction<IExpr> function)
If this symbol has attributeISymbol.CONSTANTand the symbol's evaluator is of instanceINumericConstant, then apply the constants double value to the given function and return the result, otherwise returnnull.- Specified by:
mapConstantDoublein interfaceISymbol- Parameters:
function- applys the function to adoublevalue, resulting in an object of typeIExpr.- Returns:
- the resulting expression from the function or
null. - See Also:
Abs,Ceiling,Floor
-
negate
public IExpr negate()
Description copied from interface:AbelianGroupElemNegate this.- Specified by:
negatein interfaceAbelianGroupElem<IExpr>- Overrides:
negatein classExprImpl- Returns:
- - this.
-
-
DMelt 3.0 © DataMelt by jWork.ORG