Login Register






[Java] Math Expression Parser filter_list
Author
Message
[Java] Math Expression Parser #1
Hello HC,

Today I am sharing a simple math expression parser that I made. This parser can parse and evaluate math expressions.


About the Parser


This parser supports many trigonometric functions and logarithmic and some general functions like exp, sqrt, abs etc. See the snapshots and everything will be clear. See the third screenshots for examples and their output

Screenshots


Spoiler: Screenshots

[Image: mathparser1_zps115f779f.png]

[Image: mathparser2_zps03449d3d.png]

[Image: mathparser3_zpsddeb5dbb.png]




Download

https://app.box.com/s/91j8b7wn98iqggj4yms5


Code :
https://github.com/PsychoCoderHC/MathExpressionParser


Virusscan

http://scanurl.net/?u=https%3A%2F%2Fapp....RL#results
http://onlinelinkscan.com/results/httpsa...qggj4yms5/


Instructions

You must have Java 7.

Open terminal and type :-

Code:
java -jar MathExpressionParser.jar

Note:- You must have set CLASSPATH and JAVA_HOME. If not then google for "how to set classpath in java".


Thanks to @Deque. I got references from her regarding my work.



Thank you,
Sincerely,
Psycho_Coder
[Image: OilyCostlyEwe.gif]

Reply

RE: [Java] Math Expression Parser #2
Awesome project. I will have a look at it, if I get the time.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Java] Math Expression Parser #3
A first impression:
I like the interactive calculus and the exception messages are quite good, I always know what went wrong. I.e.:

Code:
parseMathExpression exception: Missing right parenthesis after parameter of function 'sin'. (Position = 12.) $$>> ^[[A) parseMathExpression exception: Illegal character ' found in data. (Position = 0.) $$>> sin(43.3E-3) $$>> 0.04328647081218256 $$>> sin(.E-3) parseMathExpression exception: Improper number found, consisting of decimal point only. (Position = 5.)

I rarely see such a good user feedback.

I also know it is still in progress, so you probably had the following in mind already, but maybe you can include some command-line-like features, like if I press up I want to see the command I entered previously.

I would also like to use more than one variable, i.e.
sin(x) * cos(y)

Or store variables/functions beforehand, like:
x = 3
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Java] Math Expression Parser #4
(10-08-2013, 07:41 PM)Deque Wrote: A first impression:
I like the interactive calculus and the exception messages are quite good, I always know what went wrong. I.e.:

Code:
parseMathExpression exception: Missing right parenthesis after parameter of function 'sin'. (Position = 12.) $$>> ^[[A) parseMathExpression exception: Illegal character ' found in data. (Position = 0.) $$>> sin(43.3E-3) $$>> 0.04328647081218256 $$>> sin(.E-3) parseMathExpression exception: Improper number found, consisting of decimal point only. (Position = 5.)

I rarely see such a good user feedback.

I also know it is still in progress, so you probably had the following in mind already, but maybe you can include some command-line-like features, like if I press up I want to see the command I entered previously.

I would also like to use more than one variable, i.e.
sin(x) * cos(y)

Or store variables/functions beforehand, like:
x = 3

yes I know about that and I will implement them for sure. I am actually having some trouble with graph plotting package (Another part of the project). It will draw graphs based on the type of data or mathematical expressions. I have done simple plots for arrays,but when I want to use decimal point values I don't get accuracy and without accuracy this JGraphPlot package has no meaning.
[Image: OilyCostlyEwe.gif]

Reply

RE: [Java] Math Expression Parser #5
Quote:yes I know about that and I will implement them for sure. I am actually having some trouble with graph plotting package (Another part of the project). It will draw graphs based on the type of data or mathematical expressions. I have done simple plots for arrays,but when I want to use decimal point values I don't get accuracy and without accuracy this JGraphPlot package has no meaning.

Is that a third party library you use for plotting?
I only ever tried JFreeChart and had no problems with it. But it wasn't much that I did there.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Java] Math Expression Parser #6
(10-09-2013, 11:15 AM)Deque Wrote:
Quote:yes I know about that and I will implement them for sure. I am actually having some trouble with graph plotting package (Another part of the project). It will draw graphs based on the type of data or mathematical expressions. I have done simple plots for arrays,but when I want to use decimal point values I don't get accuracy and without accuracy this JGraphPlot package has no meaning.

Is that a third party library you use for plotting?
I only ever tried JFreeChart and had no problems with it. But it wasn't much that I did there.


No its not. You will not find it on the web. My Compiler has several hierarchy for executions and JGraphPlot is another library that is on its way. If you remember then in a PM I told you about a JMath library which I am coding as well, so this plotting library will be in direct communion with that JMath. I will not use any external tool for my work. So, I want to make something like the that JFreeChart on my own I don't wnat to use any external library. JFreeChart was made with Graphics2D and so do I will as well. There is pure java behind JFreeChart and so I wanna make something like that for my work.

I will figure it out somehow on how to make the graphs shows greater detail and efficient, optimized, and readable (learnt this from you, arkphaze and invisal)

If I use JFreeChart then my work will be reduced but with no satisfaction. I feel great when I see something good and thats made entirely by me. I always believe that programming is like caring a child as you have the responsibility of the child, the child won't receive complete care if one hires maid for them. Hence I prefer to do everything from scratch by myself. Since I have never done any graph plotting things so having optimization problems but maybe I need to study more and more endlessly.

JGraphPlot will be more of expression and syntax based.

Suppose you pass the following :-

plot(e^sin(x)) ; then a JFrame pops up with the equivalent graph for this functions.


Another example :-

JMath library has a package :

import static com.psychocoder.Numbers.Primes;

what we do is this, we have a function, primeSeries(int limit)

the user passes gives : plot(primeSeries(100))

Now using sieve of Eratosthenes we generate primes and return an array of primes and then we plot them on the JFrane.

Also I have done module of frequency analysis for cryptanalysis like :- plot(findFrequency(String ciphertext,char c)) where c is the character whose frequency is to be found and a histogram will be shown

I hope you got my idea about what kind of motive I have behind JGraphPlot.

Everything I have on JMath.jar is an algorithm.



Note: I haven't implemented any plotting functions (except simple arrays) yet but I will do it in somewhat like this way.

Thank you,
Sincerely,
Psycho_Coder
[Image: OilyCostlyEwe.gif]

Reply

RE: [Java] Math Expression Parser #7
(10-09-2013, 11:15 AM)Deque Wrote:
Quote:yes I know about that and I will implement them for sure. I am actually having some trouble with graph plotting package (Another part of the project). It will draw graphs based on the type of data or mathematical expressions. I have done simple plots for arrays,but when I want to use decimal point values I don't get accuracy and without accuracy this JGraphPlot package has no meaning.

Is that a third party library you use for plotting?
I only ever tried JFreeChart and had no problems with it. But it wasn't much that I did there.


No its not. You will not find it on the web. My Compiler has several hierarchy for executions and JGraphPlot is another library that is on its way. If you remember then in a PM I told you about a JMath library which I am coding as well, so this plotting library will be in direct communion with that JMath. I will not use any external tool for my work. So, I want to make something like the that JFreeChart on my own I don't wnat to use any external library. JFreeChart was made with Graphics2D and so do I will as well. There is pure java behind JFreeChart and so I wanna make something like that for my work.

I will figure it out somehow on how to make the graphs shows greater detail and efficient, optimized, and readable (learnt this from you, arkphaze and invisal)

If I use JFreeChart then my work will be reduced but with no satisfaction. I feel great when I see something good and thats made entirely by me. I always believe that programming is like caring a child as you have the responsibility of the child, the child won't receive complete care if one hires maid for them. Hence I prefer to do everything from scratch by myself. Since I have never done any graph plotting things so having optimization problems but maybe I need to study more and more endlessly.

JGraphPlot will be more of expression and syntax based.

Suppose you pass the following :-

plot(e^sin(x)) ; then a JFrame pops up with the equivalent graph for this functions.


Another example :-

JMath library has a package :

import static com.psychocoder.Numbers.Primes;

what we do is this, we have a function, primeSeries(int limit)

the user passes gives : plot(primeSeries(100))

Now using sieve of Eratosthenes we generate primes and return an array of primes and then we plot them on the JFrane.

Also I have done module of frequency analysis for cryptanalysis like :- plot(findFrequency(String ciphertext,char c)) where c is the character whose frequency is to be found and a histogram will be shown

I hope you got my idea about what kind of motive I have behind JGraphPlot.

Everything I have on JMath.jar is an algorithm.



Note: I haven't implemented any plotting functions (except simple arrays) yet but I will do it in somewhat like this way.

Thank you,
Sincerely,
Psycho_Coder
[Image: OilyCostlyEwe.gif]

Reply

RE: [Java] Math Expression Parser #8
Thread updated. Screenshots links fixed.
[Image: OilyCostlyEwe.gif]

Reply