Comments (3)
Hello @AlexandrKozlovskiy,
To answer your questions:
- Once the expression is parsed, the parsed result (RPN list) is cached and re-used on each subsequent evaluation.
Therefore, you can use loops for variable values outside of EvalEx without a performance impact.
Just make sure, that the expression is re-used:
Expression expression = new Expression("a*2);
for (int i = 0; i < 10; i++)
BigDecimal result = expression.with("a", BigDecimal.valueOf(i)).eval();
-
The parameter value for a function is only known when it comes to evaluation. During "design time", or when parsing the expression, it is unknown and therefore can't be validated. The check for correct parameter values is clearly part of the function itself, because also different implementation may have different constraints. Also, defining a simple min/max for a parameter might not be enough, as the validation might depend on the combination of parameters.
I do not see how to implement a generic validation here.
Version 3 of EvalEx (currently in work) will have a parameter definition structure for functions, which may allow some basic validation in the future. But also here, the parameter value is only known when it comes to evaluating the function. -
A main feature of EvalEx is to use BigDecimal for calculation. I do not see a way to implement an optional "fraction-reduction-less" calculation like you proposed.
from evalex.
- It very good,what you reuse instance of expression,i mean,not reparse expression,because i not learned sources of your library enough. I may be will check it,to be sure in it.
- Yes,it impossible get exact difinition scope for some functions,for example for function x^x,where x < 0,but for some functions and operators we can do it,e.g sqrt(x) or x^1/n,where n is even number. For this functions we know,what it define from 0 to +infty. Or we can do it for operator /,because we know,what it define for all values except zero. But problem will hapend,when we want to get difinition scope,but,i hope,it can be solved. For example difinition scope for function sqrt(1/x) is from 1 to +infty,because sqrt define from 0 to +infty,and / operator define in any value,except 0. So,if it possible compute exact definition scope for some functions,which we have in expression,it should be return joined definition of function for all expression. Probably it should be special class for it. Yes,i understand,what it's very dificult to do this,but,in my opinion,algorithm for this is not so dificult. at first we should take start and end values of scope definition for all functions and operators,which we have in our expression,and which we can compute. At second we should take the greatest value of start value,and smallest value for end value. After doing it for two functions or operators,we should compare this value for third function or operator,and do the same selection. We can compare value of definition of scope not only between functions and operators separately,but,for example,between function and operator. For some functions we can have several definitions of scope,so for each function and probably for whole expression,it should be returns list of objects of some class,which connected with some definition scope. E.g for / operator we have two objects of our class,because we have two scope definition (from 0 to infty and from -infty to 0). In two cases 0 not in interval. But i haven't idea how to compute scope definitions for whole expression,if at least one function or one operator have several scope definitions. It it difficult for you understand my idea and/or develop algorithm,you can add method,which allow to get list of definition scopes for each function and operator in this expression. Please also add feature,to user,if it want,can set definition scopes for existing or new functions and operators.
- About ordinary fraction,it seems it not dificult. At first,as i wrote before,you should create special class for it,e.g class fraction. Probably method of class expression eval should return not bigDecimal,but fractions even for integers,with numerator and denominator 0 for integers. to get ordinary fraction we should override / operator and get not only devision,but mode. and write this mode as numirator and the second value as denominator. e.g 14/6 have two integers. It have also mode 2,so in fraction object for integer we have 2,for numerator we have 2 and for denominator 6. To do reduction of fraction we should get greatest common divisor. Algorithms to define it in my opinion are not dificult. After computin of greatest common divisor (for 2 and 6 it 2),we should devide numerator and denominator on it,so in numerator we have 1 and in denominator we have 3. All object of class fraction,as i wrote,should be bigDecimal.
from evalex.
Closing this with version 3. Re-open, or better, create a new issue if there is more discussion needed. Consider using the discussion area, instead of the issue management, though.
from evalex.
Related Issues (20)
- Structure access with arbitrary key format HOT 5
- OutOfMemoryError/memory leak on `e.<number>` input HOT 1
- Consider some wildcards for `Map<String, Object> values` HOT 2
- Unsupported data type 'java.time.LocalDate' HOT 1
- Bundle Proguard Rules HOT 3
- How to restrict list of operators used in formula evaluation? HOT 1
- Custom ! post fix operator is not called HOT 1
- decimalPlacesRounding has confusing behavior HOT 5
- NoSuchElementException not being caught HOT 2
- Allow to only round the final result
- OutOfMemoryError: for wrong expression with 2 dots HOT 1
- Support arrays as function parameters HOT 7
- Equality depends on input type in 3.1.0
- problem with placeholder HOT 1
- Add module-info (or at least Automatic-Module-Name) HOT 2
- SQRT function doesn't work HOT 3
- With introduction of null, it's better to allow short circuiting (lazy evaluation) for those boolean operators HOT 4
- Equals/NotEquals operator is now sometimes showing inconsistent behavior HOT 1
- Broken boolean expression evaluation in version 3.1.0
- Allow Java arrays as input parameters
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from evalex.