Skip to content

FormulaJ is a multithreading Java library for evaluating mathematical expressions. It supports +, -, *, ^, and % operators, boolean expressions, a short expression format (2x + 3y), and variables. It includes a standard library with 20 mathematical functions, that can delegate unknown functions or symbols. Users can create and use their own cust…

License

Notifications You must be signed in to change notification settings

teleping/formulaj

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FormulaJ Build Status

What is it?

FormulaJ is a multithreading Java library for evaluating mathematical expressions. It supports +, -, *, ^, and % operators, boolean expressions, a short expression format (2x + 3y), and variables. It includes a standard library with 20 mathematical functions, that can delegate unknown functions or symbols. Users can create and use their own custom functions in an easy way.

Features

  • Expressions may have variables
  • Supports the use of implicit variables; e.g., sum ("x + y * z ^ x", 1, 2, 3)
  • Supports nested functions
  • FormulaJ comes with a standard library with 20 mathematical functions
  • Users can create and use their own custom functions
  • Users can provide and use their own custom expression evaluator
  • An expression can be associated to a variable; e.g., c = a * b

How to use it?

  1. Maven Repository

    See instructions in Maven Repository

  2. Usage

    ExpressionBuilder. newMathExpression("a * b") .withVariable("a", Decimal.from(7)) .withVariable("b", Decimal.from(8)) .evaluate();

or

Decimal value = ExpressionBuilder.<Decimal> evaluate("x + y * z ^ x", 1, 2, 3);

The variables are resolved according with their position and their name. If a variable is used more than one time in the expression, we don't need to repeat its value. In that expression we have three variables (x, y, z) and the variable x appears two times in the expression. As we can see, the method was called with just three values (1,2,3). The analyzer knows that the value of x is 1, y is 2 and z is 3.

Defining custom functions

  • Functions are instances of formulaj.expression.function.Function.

  • The return of a function is a formulaj.expression.Decimal.

  • To create a function you can extended the class formulaj.expression.function.math.FunctionSupport and write its code in the method eval. For instance:

    public class Times extends FunctionSupport { /** * Creates an object of the {@link Times} function. */ public Times() { super(2); }

    @Override
    protected Decimal eval(Decimal[] arguments)
    {
       return arguments[0].times(arguments[1]);
    }
    

    }

Using the custom function

Decimal value = ExpressionBuilder.<Decimal> newMathExpression("times(2,3)")
         .withFunction(new Times())
         .evaluate();

How to contribute

Reporting a Bug / Requesting a Feature

To report an issue or request a new feature you just have to open an issue in the repository issue tracker (https://github.com/alessandroleite/formulaj/issues).

Contributing with some code

To contribute, follow this steps:

  1. Fork this project
  2. Add the progress label to the issue you want to solve (add a comments to say that you work on it)
  3. Create a topic branch for this issue
  4. When you have finish your work, open a pull request (use the issue title for the pull request title)

Comments and contributions are welcome.

License

Copyright (C) 2013-2015 Contributors.

FormulaJ is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

FormulaJ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see [http://www.gnu.org/licenses/].

Bitdeli Badge

About

FormulaJ is a multithreading Java library for evaluating mathematical expressions. It supports +, -, *, ^, and % operators, boolean expressions, a short expression format (2x + 3y), and variables. It includes a standard library with 20 mathematical functions, that can delegate unknown functions or symbols. Users can create and use their own cust…

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%