parseva-math is a symbolic expression parsing tool, which can analyze and evaluate mathematical expressions. In a nutshell, parseva-math accepts a mathematical expression as a string, and first builds a heterogeneous abstract syntax tree of the expression. Then, parseva-math walks the tree to evaluate the expression. Parseva-math also supports building a homogeneous abstract syntax tree and printing the result; this way expressions can be analyzed for structure and correctness.
You will need to have a version of the JDK >= 17 in order to build parseva-math.
I plan to make a compiled jar once parseva-math reaches version 1.0. Until then, you must
clone this repository and build it yourself:
git clone https://github.com/nmancus1/parseva-math.git && cd parseva-math
Then, to build the jar:
mvn clean compile assembly:single
Finally, you can run parseva-math:
java -jar --enable-preview target/parseva-math-<version>-SNAPSHOT-jar-with-dependencies.jar
Note that --enable-preview
is required for now, since parseva-math uses JDK15 preview features.
parseva-math has two different modes of operation; interactive and command line. Mathematical
functions, such as logarithmic and trigonometric functions are currently supplied by
java.lang.Math.
To run parseva-math in the interactive mode, use -i
or --interact
:
java -jar --enable-preview target/parseva-math-<version>-SNAPSHOT-jar-with-dependencies.jar -i
This will drop you into the parseva-math terminal, where you can evaluate expressions:
> 2 + 2
= 4.000000
> sin(1)
= 0.841471
> sqrt(sin(0) + 20 + sqrt(50 - pow(5, 2)))
= 5.000000
To exit, simply press enter at an empty prompt.
To evaluate one expression via command line, use -e "<expression>"
or
--evaluate "<expression>"
:
➜ java -jar --enable-preview target/parseva-math-<version>-SNAPSHOT-jar-with-dependencies.jar -e "atan(0.5)"
= 0.463648
parseva-math also supports the constants pi
and e
.
Using the -t <expression>
or --tree <expression>
allows users to tell parseva-math to construct a homogeneous abstract syntax tree using MathAstNodes, then walk the tree and print the results.
Example:
➜ java -jar --enable-preview target/parseva-math-0.1-SNAPSHOT-jar-with-dependencies.jar -t "sin(sqrt(2.2) + pow(0.5,0.5))"
'- FUNCTION -> sin
|- LPAREN -> (
|- OP_ADD -> +
| |- FUNCTION -> sqrt
| | |- LPAREN -> (
| | |- NUM -> 2.2
| | '- RPAREN -> )
| '- FUNCTION -> pow
| |- LPAREN -> (
| |- NUM -> 0.5
| |- COMMA -> ,
| |- NUM -> 0.5
| '- RPAREN -> )
'- RPAREN -> )
Usage help is available using -h
, --help
, or simply providing no arguments to parseva-math.
If you'd like to contribute, start by searching through the issues and pull requests to see whether someone else has raised a similar idea or question.
If you don't see your idea listed, and you think it fits into the goals of this guide, start by opening an issue first. That way, other people can weigh in on the discussion before you do any work.
- Fork this repo on GitHub
- Clone the project to your own machine from YOUR fork on github.
git clone "url from your fork"
then change into the new directory. - Set Upstream do
git remote add upstream https://github.com/nmancus1/parseva-math.git
- Make new branch for YOUR code submission; do
git checkout -b <whatever you want to name this branch>
- Commit changes to your new branch, with descriptive message
- Run
mvn clean verify
; make sure this passes before pushing your changes. - Push your work back up to your fork
git push origin <your branch name>
- On Github Submit a Pull request so that your changes can be reviewed
NOTE: Be sure to merge the latest from "upstream" before making a pull request! All conflicts should be handled locally, then rebased and pushed to github.
To sync your main
branch before starting to code, do:
git checkout main
git fetch --all
git pull upstream main
git push
- this syncs your fork on github.- Start on #4 above to begin a new contribution.
Here is a great cheatsheet for git/github.
Here is another article that describes this exact workflow, in more detail.
Before we get started, here are a few things we expect from you (and that you should expect from others):
- Be kind and thoughtful in your conversations around this project. We all come from different backgrounds and projects, which means we likely have different perspectives on "how open source is done." Try to listen to others rather than convince them that your way is correct.
- If you open a pull request, please ensure that your contribution passes all tests. If there are test failures, you will need to address them before we can merge your contribution.
To generate Jacoco report, do:
mvn clean verify
The report will be generated in target/site/jacoco
.
Distributed under the Unlicense.