2017 © Pedro Peláez
 

library mathr

Math expressions: parser and evaluator.

image

rodriados/mathr

Math expressions: parser and evaluator.

  • Thursday, March 22, 2018
  • by rodriados
  • Repository
  • 2 Watchers
  • 3 Stars
  • 183 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 8 % Grown

The README.md

Mathr

license MIT version 3.0 Build Status Coverage Status, (*1)

Mathr is a fast mathematical expression parser, evaluator and calculator with some added juice., (*2)

Usage

The simplest usage possible for Mathr is by simply sending in a math expression., (*3)

<?php
$mathr = new Mathr;
$result = $mathr->evaluate("3 + 4 * 5");
echo $result; // 23

You also can create your own variables and functions!, (*4)

<?php
$mathr->evaluate("v = 10");
$mathr->evaluate("fibonacci(0) = 0");
$mathr->evaluate("fibonacci(1) = 1");
$mathr->evaluate("fibonacci(x) = fibonacci(x - 1) + fibonacci(x - 2)");
$result = $mathr->evaluate("fibonacci(v)");
echo $result; // 55

If you want to, it's possible to bind functions to native PHP closures!, (*5)

<?php
$mathr->set('triangle(b, h)', fn ($b, $h) => ($b * $h) / 2);
$result = $mathr->evaluate('triangle(5, 8)');
echo $result; // 20

There are a plenty of native functions and variables which you can use at will., (*6)

<?php
$mathr->evaluate("fibonacci(x) = ceil((φ ^ x - (1 - φ) ^ x) / sqrt(5))");
$result = $mathr->evaluate("fibonacci(10)");
echo $result; // 55

You can easily export and import your functions and variables., (*7)

<?php
$exported = $mathr->export(); // Exports all bound functions and variables.
$mathr->import($exported); // Imports functions and variables.

Install

The recommended way to install Mathr is via Composer., (*8)

{
    "require": {
        "rodriados/mathr": "v3.0"
    }
}

The Versions

22/03 2018

dev-master

9999999-dev

Math expressions: parser and evaluator.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

parser math mathematics evaluator math expression

20/03 2018

v2.0

2.0.0.0

Math expressions: parser and evaluator.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

parser math mathematics evaluator math expression

20/03 2018

v2.0.x-dev

2.0.9999999.9999999-dev

Math expressions: parser and evaluator.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

parser math mathematics evaluator math expression

20/09 2017

dev-test

dev-test

Math expressions: parser and evaluator.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

parser math mathematics evaluator math expression

21/07 2017

v1.0

1.0.0.0

Math expressions: parser and evaluator.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

parser math mathematics evaluator math expression