PHPackages                             jlawrence/eos - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jlawrence/eos

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jlawrence/eos
=============

Parse and solve math equations without using 'eval()'.

v3.2.2(10y ago)1071.1M↓12.2%22[2 issues](https://github.com/jlawrence11/eos/issues)11LGPL-2.1+PHP

Since Mar 23Pushed 10y ago10 watchersCompare

[ Source](https://github.com/jlawrence11/eos)[ Packagist](https://packagist.org/packages/jlawrence/eos)[ RSS](/packages/jlawrence-eos/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (15)Used By (11)

EOS
===

[](#eos)

[![Build Status](https://camo.githubusercontent.com/c647d8141a605ff00fe1720ab68170f64c16177a881f49a3c10a0aa07744277a/68747470733a2f2f7472617669732d63692e6f72672f6a6c617772656e636531312f656f732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jlawrence11/eos)[![Latest Stable Version](https://camo.githubusercontent.com/49636a052577c983aa9e49ed68a364a97d2c107e9aeab710464d5b99eb55bee0/68747470733a2f2f706f7365722e707567782e6f72672f6a6c617772656e63652f656f732f762f737461626c652e737667)](https://packagist.org/packages/jlawrence/eos)[![Latest Unstable Version](https://camo.githubusercontent.com/d83b5cbaee2c0214a8befda59e5f8c69616e9b3b2d270eb7f98c5884d111eeba/68747470733a2f2f706f7365722e707567782e6f72672f6a6c617772656e63652f656f732f762f756e737461626c652e737667)](https://packagist.org/packages/jlawrence/eos)[![Total Downloads](https://camo.githubusercontent.com/736fdd9eb8f24cb14e23e4bca4fbffbdb2a9c29dc28b1757c12e55e26dea8271/68747470733a2f2f706f7365722e707567782e6f72672f6a6c617772656e63652f656f732f646f776e6c6f6164732e737667)](https://packagist.org/packages/jlawrence/eos)[![License](https://camo.githubusercontent.com/1883317a2813406415a0a3975eab2d5d0cf0e394e0bc8b9ae08a537519266333/68747470733a2f2f706f7365722e707567782e6f72672f6a6c617772656e63652f656f732f6c6963656e73652e737667)](https://packagist.org/packages/jlawrence/eos)[![Code Climate](https://camo.githubusercontent.com/864cceea1fccb7b57dba466502172ce528cd519d05e48aa50edcbb93bd3e425d/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6a6c617772656e636531312f656f732f6261646765732f6770612e737667)](https://codeclimate.com/github/jlawrence11/eos)[![Test Coverage](https://camo.githubusercontent.com/6a63c1248311cdea5a898ee5aeceef2b3ef518678af5fed2afd1167f2ebcdd4e/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6a6c617772656e636531312f656f732f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/jlawrence11/eos)

Installation
------------

[](#installation)

Install EOS with [Composer](https://getcomposer.org/)

Add the dependency:

```
"require": {
    "jlawrence/eos": "3.*"
}
```

Run `composer update` and you're done.

Equation Operating System
-------------------------

[](#equation-operating-system)

### jlawrence\\eos\\

[](#jlawrenceeos)

This class makes it incredibly easy to use and parse/solve equations in your own applications. **NOTE** ALL of the functions within these classes are static. It is also important to note that these classes throw exceptions if running in to errors, please read the beginning of the `Math.php` file for the defines of the exceptions thrown. Exceptions includes a descriptive message of the error encountered and within `Parser` will also typically include the full equation used.

#### Parser

[](#parser)

This class has one important function, `Parser::solve()` which does all the legwork, so we'll start there and end with examples.

```
use jlawrence\eos\Parser;

```

##### solve($infix, $variables)

[](#solveinfix-variables)

To use this function:

```
$value = Parser::solve($eq, $vars);

```

###### *$infix*

[](#infix)

Is simply a standard equation with variable support.

Example Equations:

```
2(4x)
5+((1+2)*4)+3
5+4(1+2)+3
10*sin(x)
10*cos(x)

```

The parser has good implied multiplication.

###### *$variables*

[](#variables)

The variables are fairly simple to understand. If it contains a scalar (ie a non-array value) *every* variable within the equation will be replaced with that number. If it contains an array, there will be a by-variable replacement - note that the array MUST be in the format of `'variable' => value`
Such as:

```
array(
    'x' => 2,
    'y' => 3
);

```

Given the equation:

```
5x^y

```

If this is called by:

```
Parser::solveIF('5x^y', 2);

```

It will equal '20', as every variable is replaced by 2. However, if called like:

```
Parser::solveIF('5x^y', array(
                            'x' => 2,
                            'y' => 3));

```

You will get the result of '40' as it would equate to `5*2^3`, as expected.

#### jlawrence\\eos\\Graph

[](#jlawrenceeosgraph)

To use:

```
use jlawrence\eos\Graph;

```

This is the fun class that can create graphs. The image will default to 640x480, to initialize a different size use:

```
Graph::init($width, $height);

```

The `$width` and `$height` are the values used for the image size.

##### graph($eq, $xLow, $xHigh, \[$xStep, $xyGrid, $yGuess, ...\])

[](#grapheq-xlow-xhigh-xstep-xygrid-yguess-)

This method will generate the graph for the equation (`$eq`) with a min and max `x` range that it will parse through. All Variables explained:

- `$eq`The Standard Equation to use. *Must* have a variable in it. (ie `x`)
- `$xLow`The starting point for the calculations - the left side of the graph.
- `$xHigh`The last point calculated for the variable - the right side of the graph.
- `$xStep`Stepping point for the variable. Set to null/false to use the smart xStep feature within the graph class.
- `$xyGrid = false`Show `x/y` gridlines on the graph. Defaults to false. Each grid line is set at an integer, with a max of 30 lines, so it will calculate the stepping for it. When the grid is show, the lines are labeled along the top and left side of the image.
- `$yGuess = true`Guess the Lower and Upper `y-bounds` (The bottom and top of the image respectively.) This will set the the bounds to the lowest `y` value encountered for the `$yLow`, and the largest `y` value for `$yHigh`.
- `$yLow = null`Lower bound for `y`. Will be reset if a lower value for `y` is found if `$yGuess` is true.
- `$yHigh = null`Upper bound for `y`. Will be reset if a larger `y` value is found if `$yGuess` is true.

If you don't want the axis' labeled with their numbers, you can turn off the default behavior with:

```
Graph::$labelAxis = false;

```

TODO:

- Allow user-defined colors for all aspects of the graph.

To set up a graph with a `21x21` window (ie `-10 to 10`) for the equation `sin(x)` and output as PNG, would use as:

```
Graph::graph('sin(x)', -10, 10, 0.01, true, false, -10, 10);
Graph::outPNG();

```

It would look like:
[![Sin(x)](https://camo.githubusercontent.com/a43b2181a1fe1d9ce687997f46c94d46cdfbca81bf54373519aa268852eab825/687474703a2f2f73362e706f7374696d672e6f72672f6e6d3774636a386c742f656f73332e706e67)](https://camo.githubusercontent.com/a43b2181a1fe1d9ce687997f46c94d46cdfbca81bf54373519aa268852eab825/687474703a2f2f73362e706f7374696d672e6f72672f6e6d3774636a386c742f656f73332e706e67)

Development
-----------

[](#development)

### Testing

[](#testing)

Run the unit tests by first installing phpunit with (from the repository root)

```
composer update

```

Then run the tests with

```
phpunit

```

---

When creating classes for adding functions to the package, make sure to call `Parser::solveIF()` instead of `Parser::solve()` so that the class retains the full original equation used by the user.

---

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity53

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 77.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~28 days

Recently: every ~55 days

Total

13

Last Release

3729d ago

Major Versions

v2.2.2 → v3.0.02015-07-13

v2.2.3 → v3.2.02015-07-27

v2.2.4 → v3.2.22016-03-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/678417fd5eb003a32e591419969d6df28c9bb110d42b2391c6fd212e11e3f0d8?d=identicon)[jlawrence11](/maintainers/jlawrence11)

---

Top Contributors

[![jlawrence11](https://avatars.githubusercontent.com/u/4178771?v=4)](https://github.com/jlawrence11 "jlawrence11 (61 commits)")[![elliotwms](https://avatars.githubusercontent.com/u/4396779?v=4)](https://github.com/elliotwms "elliotwms (15 commits)")[![thebeline](https://avatars.githubusercontent.com/u/130580?v=4)](https://github.com/thebeline "thebeline (3 commits)")

---

Tags

matheossolveequations

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jlawrence-eos/health.svg)

```
[![Health](https://phpackages.com/badges/jlawrence-eos/health.svg)](https://phpackages.com/packages/jlawrence-eos)
```

###  Alternatives

[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M277](/packages/brick-math)[markrogoyski/math-php

Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra

2.4k7.1M40](/packages/markrogoyski-math-php)[phpseclib/bcmath_compat

PHP 5.x-8.x polyfill for bcmath extension

16720.7M17](/packages/phpseclib-bcmath-compat)[rubix/tensor

A library and extension that provides objects for scientific computing in PHP.

2751.4M5](/packages/rubix-tensor)[php-decimal/php-decimal

Correctly-rounded arbitrary precision decimal floating point

781.0M9](/packages/php-decimal-php-decimal)[prestashop/decimal

Object-oriented wrapper/shim for BC Math PHP extension. Allows for arbitrary-precision math operations.

178.2M5](/packages/prestashop-decimal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
