LOG10 Operator

36 views
Skip to first unread message

famer

unread,
Sep 23, 2014, 6:39:57 PM9/23/14
to jep-...@googlegroups.com
I am trying to parse an expression that has a logarithm as

expr = 10 * log10( 12345 / (  (5 ^ 2) * 3) )

Can this be done using JEP 2.4.1?

If not, can it be done using a later version of JEP?



-famer

Richard Morris

unread,
Sep 24, 2014, 4:36:47 AM9/24/14
to jep-...@googlegroups.com
Jep uses "log" for the base 10 logarithm and "ln" for base e logarithm. So you can do
 
   expr = 10 * log( 12345 / (  (5 ^ 2) * 3) )

If you want to use "log10" for base 10 logs them you can change the name of the function using JEP.addFunction(String, PostfixMathCommandI).

Richard

famer

unread,
Sep 24, 2014, 8:02:39 PM9/24/14
to jep-...@googlegroups.com
Thank you for the quick reply.

I tried to use it as "log" in my expression like you mentioned but I get the error "Syntax Error (implicit multiplication not enabled)".

This is how my parser has been set up
       
        org.nfunk.jep.JEP myParser = new org.nfunk.jep.JEP();
        myParser.setAllowUndeclared(true);
        Node node = jep.parseExpression(test);
        if ( jep.hasError()) {
            System.out.println("ERROR: " + jep.getErrorInfo());
        }

I can only make it work if I use a later version of JEP. I used the trial version 3.3.0 of the Jep parser as
       Jep jep = new Jep();
       Node node = jep.parse(test);
       com.singularsys.jep.walkers.TreeAnalyzer ta = new com.singularsys.jep.walkers.TreeAnalyzer(node);
       System.out.println(ta.toString());

Is it that version 2.4.1 does not support function parsing?

Thanks,
-F

Richard Morris

unread,
Sep 25, 2014, 9:53:04 AM9/25/14
to jep-...@googlegroups.com
I'm not quite sure why you are getting problems. This code works for me

JEP myParser = new JEP();

myParser.addStandardFunctions();

myParser.parseExpression("10 * log( 12345 / (  (5 ^ 2) * 3) )");

System.out.println(myParser.getValue());


If you try and do

myParser.parseExpression("10 * log10( 12345 / (  (5 ^ 2) * 3) )");

Jep does not understand "log10" is a function and interprets it as "log * 10" using implicit multiplication. 

However unless you explicitly call myParser.setImplicitMul(true); it will not allow implicit multiplication and raise an exception.


On Thursday, 25 September 2014 01:02:39 UTC+1, famer wrote:
Thank you for the quick reply.

I tried to use it as "log" in my expression like you mentioned but I get the error "Syntax Error (implicit multiplication not enabled)".

This is how my parser has been set up
       
        org.nfunk.jep.JEP myParser = new org.nfunk.jep.JEP();
        myParser.setAllowUndeclared(true);
        Node node = jep.parseExpression(test);
        if ( jep.hasError()) {
            System.out.println("ERROR: " + jep.getErrorInfo());
        }

I can only make it work if I use a later version of JEP. I used the trial version 3.3.0 of the Jep parser as
       Jep jep = new Jep();
       Node node = jep.parse(test);
       com.singularsys.jep.walkers.TreeAnalyzer ta = new com.singularsys.jep.walkers.TreeAnalyzer(node);
       System.out.println(ta.toString());

Is it that version 2.4.1 does not support function parsing?


I'm not sure whats wrong with this code you would need to post the complete code.

Richard

famer

unread,
Sep 25, 2014, 12:57:59 PM9/25/14
to jep-...@googlegroups.com
That was the problem...I was missing the "addStandardFunctions()" call. After adding this, the parsing is ok without errors. Thanks for the help.

On a different note, we were thinking of upgrading to JEP 3.4.0, but I encountered an issue while trying to use the addOperator api. OperatorKey does not seem to be defined anywhere in the jar file and the code would not compile. Version 3.3.0 does not have this issue. Is it better to upgrade to 3.3.0?

Thanks,
-F

Richard Morris

unread,
Sep 25, 2014, 6:17:04 PM9/25/14
to jep-...@googlegroups.com
I would go with the 3.4.0 versions as it fixes a number of minor bugs with 3.3. I'm not quite sure what the problem with OperatorKey can you post an example?

Richard

famer

unread,
Sep 26, 2014, 12:00:48 PM9/26/14
to jep-...@googlegroups.com
Actuallly I found that OperatorKey is somehow in the package OperatorTable2 although it is not shown. Thanks for all the input and help. Most probably we will upgrade to version 3.4.0.

Thanks,
-F

famer

unread,
Sep 29, 2014, 2:33:28 PM9/29/14
to jep-...@googlegroups.com
So if we go to the "Order" page, and I want to get the latest jar (3.4) which item number should I select? Is it Item # 1059 (Jep Java 3.4   Binary).

Thanks,
-F

Nathan Funk

unread,
Sep 30, 2014, 1:31:20 AM9/30/14
to jep-...@googlegroups.com

Yes that's correct

--
You received this message because you are subscribed to the Google Groups "Jep Java Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jep-users+...@googlegroups.com.
To post to this group, send email to jep-...@googlegroups.com.
Visit this group at http://groups.google.com/group/jep-users.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages