Giter Club home page Giter Club logo

teleping / formulaj Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alessandroleite/formulaj

1.0 1.0 0.0 288 KB

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.

License: GNU General Public License v3.0

Java 100.00%

formulaj's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.