PHPackages                             rizalmf/deductive-formula - 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. rizalmf/deductive-formula

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

rizalmf/deductive-formula
=========================

Evaluate given math expressions

0.0.1-alpha(5y ago)21MITPHPPHP &gt;=7.0

Since Apr 4Pushed 5y ago1 watchersCompare

[ Source](https://github.com/rizalmf/deductive-formula)[ Packagist](https://packagist.org/packages/rizalmf/deductive-formula)[ Docs](https://github.com/rizalmf)[ RSS](/packages/rizalmf-deductive-formula/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

DeductiveFormula
================

[](#deductiveformula)

DeductiveFormula is library evaluate expression of variables from given string

### Install via "composer require"

[](#install-via-composer-require)

```
composer require rizalmf/deductive-formula
```

### Usage:

[](#usage)

```
use rizalmf\formula\DeductiveFormula;
use rizalmf\formula\exception\FormulaException;

require_once __DIR__ . '/vendor/autoload.php'; // example path

$formula = new DeductiveFormula();
```

Example 1: (Define Expressions &amp; Set Formula)

```
try {
    $expression = '{foo}^({bar}/2+(2+3^(1/2)))';
    $requestedVariables = $formula->setFormula($expression);
    var_dump($formula->getFormula());
    var_dump($requestedVariables);

} catch (FormulaException $e) {
    // handle Exceptions
}

// output :
// {foo}^({bar}/2+(2+3^(1/2)))
// array ([0] => "foo", [1] => "bar")
```

Example 2: (Set Variables)

```
    // ...

    // 1. define value per variable
    $formula->setVariable("foo", 4);
    $formula->setVariable("bar", 1);

    // 2. use array
    $formula->setVariables([
        "foo" => 4,
        "bar" => 1
    ]);
```

Example 3: (Get Variables)

```
    // ...

    // 1. get value from specific variable
    var_dump($formula->getVariable("foo"));
    // output : 4

    // 2. get values all variables
    var_dump($formula->getVariables());
    // output : array ([foo] => 4, [bar] => 1)

    // 1. get possible variables from Formula
    var_dump($formula->getRequestedVariables());
    // output : array ([0] => "foo", [1] => "bar")
```

Example 4: (Evaluate)

```
    $result = $formula->execute();
    var_dump($result);

    // output : 353.141268350837
```

Example 5: (Set Limit Iteration &amp; Debug)

```
    // (optional) set limit iteration calculating machine. default 200
    $formula->setLimit(50);

    // show prepared formula
    var_dump($formula->getFormulaExposed());
    // output : 4^(1/2+(2+3^(1/2)))

    // debug
    $result = $formula->execute(true);
    var_dump($result);
    // output :
    // iteration-1 => 4^(1/2+(2+3^(1/2)))
    // iteration-2 => 4^(1/2+(2+3^0.50))
    // iteration-3 => 4^(1/2+(2+1.73205080756888))
    // iteration-4 => 4^(1/2+3.73205080756888)
    // iteration-5 => 4^(0.50+3.73205080756888)
    // iteration-6 => 4^4.23205080756888
    // 353.141268350837
```

Exception Tree

```
    FormulaException
        |- BadFormulaException
```

### Unit Test:

[](#unit-test)

1. [Composer](https://getcomposer.org) is a prerequisite for running the tests.

```
composer install

```

2. The tests can be executed by running this command from the root directory:

```
./vendor/bin/phpunit test
```

LICENSE
-------

[](#license)

The MIT License (MIT) Copyright (c) 2021 Rizal Maulana Fahmi

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

1868d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8be4465a069b513fa50a37e0667e011c9df567926a844a9d783f267afb296b56?d=identicon)[rizalmf](/maintainers/rizalmf)

---

Top Contributors

[![rizalmf](https://avatars.githubusercontent.com/u/34501392?v=4)](https://github.com/rizalmf "rizalmf (11 commits)")

---

Tags

phpphp-libraryformulaevaluatecalculatemath expressiondeductive

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rizalmf-deductive-formula/health.svg)

```
[![Health](https://phpackages.com/badges/rizalmf-deductive-formula/health.svg)](https://phpackages.com/packages/rizalmf-deductive-formula)
```

###  Alternatives

[rezzza/formulate

Making life easier while writing complex math formulas, take a breath

1235.3k1](/packages/rezzza-formulate)

PHPackages © 2026

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