How do I use round down function in Camunda literal expression? - camunda

I wish to round the result (type long) of literal expression of DMN. I tried using rounddown(exp, -6), but it did not work. Function ceiling and floor also not working. I'm using Camunda 7.17. Please suggest if I'm missing something or any other way to round the result to 6 digits.

By default recent Camunda versions use the Friendly Enough Expression Language defined in the DMN standard. The FEEL Scala Engine used is documented here: https://camunda.github.io/feel-scala/docs/reference/
You are looking for the built-in numeric functions:
https://camunda.github.io/feel-scala/docs/reference/builtin-functions/feel-built-in-functions-numeric
such as
round down(5.5)
round up(5.5)
floor(1.5)

Related

Read inner Parentheses of a String (VB.NET) [duplicate]

This question already has answers here:
Evaluate mathematical expression from a string using VB
(3 answers)
Closed 4 years ago.
I am developping a calculator function in Visual Basic. I think there is no basic one in the default .NET libraries.
I use System.Data.DataTable.Compute() to calculate the normal Math expression. But I want my function to solve functions like Sinus() or Round() as well.
Currently I am using Regex for this. For example for functions with one argument I use
Dim expr As String = Regex.Replace(Term, "(?<func>[A-Za-z]*?)\((?<arg1>[0-9,.]*?)\)", AddressOf FunctionLibrary.Funcs1)
the Sinus() function would look like this: sin(Number).
But this only allows to write Doubles or Integers into the argument. I can not write inner functions or even another math expression between the parentheses.
If I would write more functions as an argument, Regex would detect the first ")" inside the function, which is the closing parenthese of the inner function, as the end of the outer function.
Is there any way to make Regex recognize that theres an inner function as well?
If anyone knows an Evaluate() function for Visual Basic which is in the default .NET libraries, this might help me as well
Is there any way to make Regex recognize that theres an inner function as well?
No, there is not. Regular expressions, as the name implies, solve Regular grammars and simple mathematical expressions are Context-Free. Regular expressions do not have a stack to match arbitrary expressions. For example, distinguishing between (()) and ()() require at least one character of lookahead (or backtracking). Yes, PCRE-style regular expressions can let you create a fixed number of lookahead characters, but so far as I know you have to specify the number of characters, and anyway this is not going to solve your problem.
Evaluating arithmetic expressions require handling precedence, subexpressions, possibly variables and types. Regular expressions cannot do this, attempting to do it with regular expressions will lead you into a pit of failure.
Nor are they even necessary. Evaluating mathematical expressions is a solved problem and there are dozens of parsers and evaluators written, tested, and ready for you to drop into your application. You have not given us enough information to decide which one would be best for you, and anyway Stack Overflow is not a tool advocacy site. You could start by going through the list at Gary Beene's Equation Parser review.

Using SIMILAR TO for a regex?

Why is the following instruction returning FALSE?
SELECT '[1-3]{5}' SIMILAR TO '22222' ;
I can't find what is wrong with that, according to the Postgres doc ...
Your basic error has already been answered.
More importantly, don't use SIMILAR TO at all. It's completely pointless:
Query performance in PostgreSQL using 'similar to'
Difference between LIKE and ~ in Postgres
Use LIKE, or the regular expression match operator ~, or other pattern matching operators:
Pattern matching with LIKE, SIMILAR TO or regular expressions in PostgreSQL
For 5 digits between 1 and 3 use the expression #Thomas provided.
If you actually want 5 identical digits between 1 and 3 like your example suggests I suggest a back reference:
SELECT '22222' ~ '([1-9])\1{4}';
Related answer with more explanation:
Deleting records with number repeating more than 5
sqlfiddle demonstrating both.
The operator is defined as:
string SIMILAR TO pattern
so the first parameter is the string that you want to compare. The second parameter is the regex to compare against.
You need:
SELECT '22222' SIMILAR TO '[1-3]{5}';
try
SELECT '22222' ~ '[1-3]{5}'
SIMILAR is not POSIX standard
The SIMILAR TO operator returns true or false depending on whether its pattern matches the given string. It is similar to LIKE, except that it interprets the pattern using the SQL standard's definition of a regular expression. SQL regular expressions are a curious cross between LIKE notation and common regular expression notation.
...
POSIX regular expressions provide a more powerful means for pattern matching than the LIKE and SIMILAR TO operators. Many Unix tools such as egrep, sed, or awk use a pattern matching language that is similar to the one described here.
http://www.postgresql.org/docs/9.2/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP

Writing INTEGRATOR similar to http://integrals.wolfram.com/index.jsp using parsing in java

Hi as part of my project I have been working on evaluation of arithmetic expression using reg-ex in java.
expressions are like this : 2+3/4(5+7)
first I will modify it to this : 2+3/4*(5+7)
and convert it to postfix
postfix: 23457+*/+
The procedure I have adopted is parsing all of the tokens (i.e. Integers,Operators,Open Paren,Close Paren) using Reg-Ex and then sorting by the i-th position of their occurrence. After that I converted that array of token into post-fix expression and then solved that expression, Until this point every thing is working fine.
Now I would like to extend it to solving differentiation,integration or solving quadratic equation.
foe ex: differentiate or integrate expression x^2+2*x+2
similar to http://integrals.wolfram.com/index.jsp
Is it possible? because right now I dont have any clue how to proceed with that?
Most calculators I am aware of - calculating equations/differentions and integrals using numerical analysis. This allows one to find a close solution to the exact (analytical one) solution, sometimes even for unsolveable equations (This is how we got the standard normal table, for the unsolveable normal density function)
For example, solving integrals - gaussian quardature is very common and efficeint way.
For solving equations - regula-falsi method is a simple and intuitive one
I think that most integral computation engines use the numerical approach just as amit said, however there's a way to compute it symbolically, but it's heuristic more than algorithmic, it's done by pattern matching. I think that Mathematica follows this approach.

Is there a parser that interprets colon and comma notation?

I'm new to using Using boost::program_options, and I'd like to parse a numeric command line argument with colon and comma notation. For example i'd like to have this kind of argument:
myprogram --numbers 1:100,200,300
Produce a vector with the integers 1-100 then 200 and finally 300.
Is there a name for this notation?
My first inclination is that I'd have to treat this argument as a string, then pass it to a function function that does the parsing. It seems like this is an excellent candidate for "somthing someone has done already and made available."
I would use boost::spirit and define some custom semantic actions. Make sure the version of boost::spirit you use is compatible with the compiler with this. I've had issues with using newer boost::spirit with older compilers. Matlab calls the 1:5 "colon notation". Pretty anti-climactic eh?

What would be the Regular Expression to retrieve number in front of % symbol in string?

I'm using a math parser that uses % as the mod symbol. I'd like to use it for the percent symbol instead to allow users to type "25%*10" or "25% of 10" and receive the answer "2.5" (they could type anything).
I'd then use the regex asked for to get the "25%" (could be in any part of the string) and do a simple calculation (25 / 100) and then replace the 25% in the string with the calculated value to pass to the math parser. Basically I'm doing some pre calculations on the number in front of the percent symbol before passing the full string to the math parser.
I've always struggled with regex and was hoping someone could help me.
Thanks
Easiest way would be to let the math parser do the dividing:
s/([0-9.]+)%/($1\/100)/g
Which just replaces "25%" with "(25/100)" ... so if the user typed "25%*10" they'll now have "(25/100)*10" which when evaluated gives them the right answer.
Alternatively, in Perl, you could do:
s{([0-9.]+)%}{$1/100}eg
which would have Perl calculate the division by a hundred and pass that to the math parser
The regular expression to find a number before a '%' sign is /(\d+)%/.
However, mathematical expressions are not a regular language, so a regular expression is likely not the right tool. You should instead tell your parser to interpret '%' as "take whatever comes before this and divide it by 100". "Whatever comes before this" can then be any mathematical expression, and you won't run into operator precedence problems, resp. you could sort these out in the syntax tree parser.
Mixing text substitution with real language features often violates the principle of least astonishment. When a user sees that '%' divides whatever comes before by 100, he might try to use expressions like (23+42)%, but that will just produce a syntax error. Also, you need a more elaborate regex if you have something like 1.34e-14%, but these things would just sort themselves out when you use the tree parser.