Class MathExpression
- All Implemented Interfaces:
Savable,Solvable,Serializable
- Direct Known Subclasses:
BaseNFunction,MatrixExpression,MatrixFunction,PolynomialExpression
NOTE: The parser operation is divided into: Step 1. Expression Processing...This step takes time. Step 2. Expression Evaluation....Is an high speed one. For expressions that contain either user defined functions or statistical functions however, The second part is self-referentially mixed with the first and so this gives rise to a problem. For iterative processes, the parser only needs parse (Step 1.)the expression once(which takes the bulk of the time) and then it can evaluate it many times over iteratively in a loop. Step 2 is an high speed one. But if the expression contains statistical functions or user defined ones, the self-referential processes modify the scanner output and so this scanner output cannot be reliably referred to later on by iterative processes or any process that seeks to reuse the scanner's output.
- Author:
- GBENRO
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptiondefault no argument constructor for class MathExpression.MathExpression(String input) MathExpression(String input, VariableManager variableManager) -
Method Summary
Modifier and TypeMethodDescriptiongetDRG()static StringintSometimes, after evaluation the evaluation list which is a local variable, is reduced to a function name(or other object as time goes on) instead of a number of other list.doublegetVars()static booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanstatic voidstatic voidstatic voidsetAutoInitOn(boolean autoInitOn) voidsetCorrectFunction(boolean correctFunction) voidsetDRG(int mode) voidsets the DRG propertyfinal voidsetExpression(String expression) voidsetHasListReturningOperators(boolean hasListReturningOperators) voidsetHasLogicOperators(boolean hasLogicOperators) voidsetHasMulOrDivOperators(boolean hasMulOrDivOperators) voidsetHasNumberReturningStatsOperators(boolean hasNumberReturningStatsOperators) voidsetHasPermOrCombOperators(boolean hasPermOrCombOperators) voidsetHasPlusOrMinusOperators(boolean hasPlusOrMinusOperators) voidsetHasPostNumberOperators(boolean hasPostNumberOperators) voidsetHasPowerOperators(boolean hasPowerOperators) voidsetHasPreNumberOperators(boolean hasPreNumberOperators) voidsetHasRemainderOperators(boolean hasRemainderOperators) static voidsetLastResult(String lastResult) voidsetNoOfListReturningOperators(int noOfListReturningOperators) voidsetOptimizable(boolean optimizable) voidsetReturnType(TYPE returnType) voidsetScanner(ArrayList<String> scanner) voidvoidsetVariableHandlerOnly(boolean variableHandlerOnly) voidsetVariableManager(VariableManager variableManager) voidAn important process that must occur before the function is solved.voidsetWhitespaceremover(ArrayList<String> whitespaceremover) solve()solveSubPortions(List<String> scanner)
-
Field Details
-
parser_Result
-
lastResult
-
correctFunction
protected boolean correctFunction -
noOfListReturningOperators
protected int noOfListReturningOperators -
scanner
-
hasListReturningOperators
protected boolean hasListReturningOperators -
SYNTAX_ERROR
- See Also:
-
-
Constructor Details
-
MathExpression
public MathExpression()default no argument constructor for class MathExpression. It creates a function which has the value 0; -
MathExpression
- Parameters:
input- The function to be evaluated. The general format contains variable, constant and function declarations for variables, constants and functions that are not yet initialized, assignment expressions for those that have been initialized and then an expression to evaluate. e.g. x = -12; y =x+1/12; const x1,x2,x3=10; z =sin(3x-1)+2.98cos(4x);cos(3x+12); The last expression is a function to be evaluated and it is always without any equals sign and may or may not end with a semicolon.
-
MathExpression
-
-
Method Details
-
getExpression
-
setExpression
- Parameters:
expression- The expression
-
isScannedAndOptimized
public boolean isScannedAndOptimized()- Returns:
- true if this object has been scanned and is found valid. In this state, objects of this class are optimized to run at very high speeds.
-
setAutoInitOn
public static void setAutoInitOn(boolean autoInitOn) -
isAutoInitOn
public static boolean isAutoInitOn() -
getDRG
- Returns:
- the DRG value:0 for degrees, 1 for rads, 2 for grads
-
setDRG
-
setDRG
public void setDRG(int mode) -
isCorrectFunction
public boolean isCorrectFunction()- Returns:
- true if the input can be evaluated.
-
setCorrectFunction
public void setCorrectFunction(boolean correctFunction) - Parameters:
correctFunction- sets if the input is valid and can be evaluated or not.
-
getNoOfListReturningOperators
public int getNoOfListReturningOperators()- Returns:
- the number of list returning operators found in the input.
-
setNoOfListReturningOperators
public void setNoOfListReturningOperators(int noOfListReturningOperators) - Parameters:
noOfListReturningOperators- sets the number of list returning operators found in the input.
-
getScanner
-
setScanner
-
getWhitespaceremover
-
setWhitespaceremover
-
isHasListReturningOperators
public boolean isHasListReturningOperators()- Returns:
- true if there are list-returning operators
-
setHasListReturningOperators
public void setHasListReturningOperators(boolean hasListReturningOperators) - Parameters:
hasListReturningOperators- sets the number of list returning operators.
-
setOptimizable
public void setOptimizable(boolean optimizable) - Parameters:
optimizable- sets whether this input can be optimized.
-
isOptimizable
public boolean isOptimizable()- Returns:
- whether or not this input can be optimized
-
setLastResult
- Parameters:
lastResult- sets the last answer gotten by this parser
-
getLastResult
- Returns:
- the last answer calculated by this tool
-
setHasPreNumberOperators
public void setHasPreNumberOperators(boolean hasPreNumberOperators) - Parameters:
hasPreNumberOperators- sets whether the input has pre-number operators or not
-
isHasPreNumberOperators
public boolean isHasPreNumberOperators()- Returns:
- true if the input has pre number operators
-
setHasLogicOperators
public void setHasLogicOperators(boolean hasLogicOperators) - Parameters:
hasLogicOperators- sets whether the input has logic operators or not.
-
isHasLogicOperators
public boolean isHasLogicOperators()- Returns:
- true if the input has logic operators
-
setHasPostNumberOperators
public void setHasPostNumberOperators(boolean hasPostNumberOperators) - Parameters:
hasPostNumberOperators- sets whether the input has post number operators
-
isHasPostNumberOperators
public boolean isHasPostNumberOperators()- Returns:
- true if post number operators like factorial, inverse e.t.c
-
setHasPowerOperators
public void setHasPowerOperators(boolean hasPowerOperators) - Parameters:
hasPowerOperators- sets whether or not the input has the power operator
-
isHasPowerOperators
public boolean isHasPowerOperators()- Returns:
- true if the input has the power operator
-
setHasMulOrDivOperators
public void setHasMulOrDivOperators(boolean hasMulOrDivOperators) - Parameters:
hasMulOrDivOperators- sets whether the input has multiplication or division operators
-
isHasMulOrDivOperators
public boolean isHasMulOrDivOperators()- Returns:
- true if the input has multiplication or division operators
-
getReturnObjectName
Sometimes, after evaluation the evaluation list which is a local variable, is reduced to a function name(or other object as time goes on) instead of a number of other list. The parser unfortunately will not return this variable, but instead returns the data which it refers to..e.g aMatrixfunction or other. But we at times need that function name...So we cache this value here.- Returns:
- the object returned via its string reference name
-
setHasPlusOrMinusOperators
public void setHasPlusOrMinusOperators(boolean hasPlusOrMinusOperators) - Parameters:
hasPlusOrMinusOperators- sets whether or not the input contains plus or minus operators
-
isHasPlusOrMinusOperators
public boolean isHasPlusOrMinusOperators()- Returns:
- true if plus or minus operators are found in the input
-
setHasRemainderOperators
public void setHasRemainderOperators(boolean hasRemainderOperators) - Parameters:
hasRemainderOperators- sets whether or not remainder operators are found in the input
-
isHasRemainderOperators
public boolean isHasRemainderOperators()- Returns:
- true if remainder operators are found in the input
-
setHasPermOrCombOperators
public void setHasPermOrCombOperators(boolean hasPermOrCombOperators) - Parameters:
hasPermOrCombOperators- sets whether permutation and combination operators are found in the input
-
isHasPermOrCombOperators
public boolean isHasPermOrCombOperators()- Returns:
- true if permutation and combination operators are found in the input
-
setHasNumberReturningStatsOperators
public void setHasNumberReturningStatsOperators(boolean hasNumberReturningStatsOperators) - Parameters:
hasNumberReturningStatsOperators- sets whether or not the input contains a data set that will evaluate to a number
-
isHasNumberReturningStatsOperators
public boolean isHasNumberReturningStatsOperators()- Returns:
- true if the input contains a data set that will evaluate to a number
-
setVariableHandlerOnly
public void setVariableHandlerOnly(boolean variableHandlerOnly) -
isVariableHandlerOnly
public boolean isVariableHandlerOnly() -
getVariableManager
-
setVariableManager
-
getVars
-
setVariableValuesInFunction
An important process that must occur before the function is solved. Variables must be replaced by their values. The method checks the variable store and assumes that between function input time and function solution time, the user would have modified the value attribute stored in the variables. So it gets the values there and fixes them in the appropriate points in the equation. Ensure that no shift has occurred in Variable object position during the time that the record was taken and the time when the position is about to be referenced.- Parameters:
scan- the data it is to process
-
getValue
- Parameters:
name- The name of the variable or constant.- Returns:
- the value of the named variable or constant
- Throws:
NullPointerException- if a Variable object that has that name id not found.
-
setValue
- Parameters:
name- The name of the variable or constant.value- The value to set to the variable- Throws:
NullPointerException- if a Variable object that has that name id not found.NumberFormatException
-
setReturnType
-
getReturnType
-
solveGeneric
-
solve
-
solve
-
getNextResult
-
solveSubPortions
- Parameters:
scanner- is a list of scanner functions, gotten during the evaluation of sets of data that contain functions that need to be evaluated instead of numbers.If the data set does not contain functions e.g avg(2,3,7,1,0,9,5), then method solve will easily solve it. But if it does e.g avg(2,sin,3,5,cos,(,5,) ), then we invoke this method in class Set's constructor before we evaluate the data set. Note this is method is not called directly by MathExpression objects but by objects of class Set invoked by a MathExpression object.- Returns:
- the solution to the scanner function
-
main1
-
main
-
serialize
-
parse
-