PHPackages                             hoa-math-community/math - 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. hoa-math-community/math

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

hoa-math-community/math
=======================

The Hoa\\Math library.

v2.0.0(3y ago)11.1k↓25%2BSD-3-ClausePHPPHP ~8.0

Since Sep 16Pushed 1y agoCompare

[ Source](https://github.com/hoa-math-community/Math)[ Packagist](https://packagist.org/packages/hoa-math-community/math)[ Docs](https://hoa-project.net/)[ RSS](/packages/hoa-math-community-math/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (21)Used By (2)

 [![Hoa](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)

---

 [![Build status](https://camo.githubusercontent.com/b6bccab0d567026081ab3fca8671c90d27bf25f82cfad8e0e8d43c779ed34046/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f686f6170726f6a6563742f6d6174682f6d61737465722e737667)](https://travis-ci.org/hoaproject/math) [![Code coverage](https://camo.githubusercontent.com/9bf1da5a2aeb9cd09872baec8d732553b5ea45f2a7b116ef00958a1b967d2971/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f686f6170726f6a6563742f6d6174682f6d61737465722e737667)](https://coveralls.io/github/hoaproject/math?branch=master) [![Packagist](https://camo.githubusercontent.com/284fca4744f5433e24f62d18f61c206a4fd4ceb3c08d108ead3cb68a9369c94c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f612f6d6174682e737667)](https://packagist.org/packages/hoa/math) [![License](https://camo.githubusercontent.com/a0c4f64633c44499a0c67c463846adb4b2552c54254740e34aa8239ba580a1eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f612f6d6174682e737667)](https://hoa-project.net/LICENSE)

 Hoa is a **modular**, **extensible** and **structured** set of PHP libraries.
 Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\\Math
=========

[](#hoamath)

[![Help on IRC](https://camo.githubusercontent.com/4dbc9c9d28c30cf1ab591f4bb8212fe4dbddc734145df532a9bb86b09878d4c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d253233686f6170726f6a6563742d6666303036362e737667)](https://webchat.freenode.net/?channels=#hoaproject)[![Help on Gitter](https://camo.githubusercontent.com/8c4c85951788ff606b1268cb3dd946be05e3054795455d0a7b9250711bc2ac05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d6769747465722d6666303036362e737667)](https://gitter.im/hoaproject/central)[![Documentation](https://camo.githubusercontent.com/7059ad5f1a363f9098686c59d432f01d7330aed9d4b6c8111d985fd64cfc6c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d6861636b5f626f6f6b2d6666303036362e737667)](https://central.hoa-project.net/Documentation/Library/Math)[![Board](https://camo.githubusercontent.com/fd81654ba14b3aca3a713e1b471bc3fc3ba7b5bb3761ccffd6eea2e2ed1fa5ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f7267616e69736174696f6e2d626f6172642d6666303036362e737667)](https://waffle.io/hoaproject/math)

This library provides tools around mathematical operations.

[Learn more](https://central.hoa-project.net/Documentation/Library/Math).

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

[](#installation)

With [Composer](https://getcomposer.org/), to include this library into your dependencies, you need to require [`hoa/math`](https://packagist.org/packages/hoa/math):

```
$ composer require hoa/math '~1.0'
```

For more installation procedures, please read [the Source page](https://hoa-project.net/Source.html).

Testing
-------

[](#testing)

Before running the test suites, the development dependencies must be installed:

```
$ composer install
```

Then, to run all the test suites:

```
$ vendor/bin/hoa test:run
```

For more information, please read the [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#quick-usage)

We propose a quick overview of one feature: evaluation of arithmetical expressions.

### Evaluation of arithmetical expressions

[](#evaluation-of-arithmetical-expressions)

The `hoa://Library/Math/Arithmetic.pp` describes the form of an arithmetical expression. Therefore, we will use the classical workflow when manipulating a grammar, that involves the [`Hoa\Compiler`library](https://central.hoa-project.net/Resource/Library/Compiler) and the `Hoa\Math\Visitor\Arithmetic` class.

```
// 1. Load the compiler.
$compiler = Hoa\Compiler\Llk::load(
    new Hoa\File\Read('hoa://Library/Math/Arithmetic.pp')
);

// 2. Load the visitor, aka the “evaluator”.
$visitor    = new Hoa\Math\Visitor\Arithmetic();

// 3. Declare the expression.
$expression = '1 / 2 / 3 + 4 * (5 * 2 - 6) * PI / avg(7, 8, 9)';

// 4. Parse the expression.
$ast        = $compiler->parse($expression);

// 5. Evaluate.
var_dump(
    $visitor->visit($ast)
);

/**
 * Will output:
 *     float(6.4498519738463)
 */

// Bonus. Print the AST of the expression.
$dump = new Hoa\Compiler\Visitor\Dump();
echo $dump->visit($ast);

/**
 * Will output:
 *     >  #addition
 *     >  >  #division
 *     >  >  >  token(number, 1)
 *     >  >  >  #division
 *     >  >  >  >  token(number, 2)
 *     >  >  >  >  token(number, 3)
 *     >  >  #multiplication
 *     >  >  >  token(number, 4)
 *     >  >  >  #multiplication
 *     >  >  >  >  #group
 *     >  >  >  >  >  #substraction
 *     >  >  >  >  >  >  #multiplication
 *     >  >  >  >  >  >  >  token(number, 5)
 *     >  >  >  >  >  >  >  token(number, 2)
 *     >  >  >  >  >  >  token(number, 6)
 *     >  >  >  >  #division
 *     >  >  >  >  >  token(constant, PI)
 *     >  >  >  >  >  #function
 *     >  >  >  >  >  >  token(id, avg)
 *     >  >  >  >  >  >  token(number, 7)
 *     >  >  >  >  >  >  token(number, 8)
 *     >  >  >  >  >  >  token(number, 9)
 */
```

We can add functions and constants on the visitor, thanks to the `addFunction`and `addConstant` methods. Thus, we will add the `rand` function (with 2 parameters) and the `ANSWER` constant, set to 42:

```
$visitor->addFunction('rand', function ($min, $max) {
    return mt_rand($min, $max);
});
$visitor->addConstant('ANSWER', 42);

$expression = 'rand(ANSWER / 2, ANSWER * 2)'
var_dump(
    $visitor->visit($compiler->parse($expression))
);

/**
 * Could output:
 *     int(53)
 */
```

Documentation
-------------

[](#documentation)

The [hack book of `Hoa\Math`](https://central.hoa-project.net/Documentation/Library/Math) contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

```
$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open
```

More documentation can be found on the project's website: [hoa-project.net](https://hoa-project.net/).

Getting help
------------

[](#getting-help)

There are mainly two ways to get help:

- On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)IRC channel,
- On the forum at [users.hoa-project.net](https://users.hoa-project.net).

Contribution
------------

[](#contribution)

Do you want to contribute? Thanks! A detailed [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html) explains everything you need to know.

License
-------

[](#license)

Hoa is under the New BSD License (BSD-3-Clause). Please, see [`LICENSE`](https://hoa-project.net/LICENSE) for details.

Related projects
----------------

[](#related-projects)

The following projects are using this library:

- [PSIH &amp; PMSIpilot](http://www.psih.fr/en/), PSIH is the leading French integrator of business intelligence solutions for the healthcare sector,
- [PHP Telegram Bot](https://github.com/akalongman/php-telegram-bot/), Telegram bot based on the official Telegram Bot API.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 77.6% 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 ~177 days

Recently: every ~600 days

Total

18

Last Release

1249d ago

Major Versions

0.15.10.26 → 1.16.01.142016-01-14

1.17.05.16 → v2.0.02022-12-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/14144958f1893ddd81dafbd4df8583e38792ccc089462e3cb14b80eeba32cef3?d=identicon)[hubipe](/maintainers/hubipe)

---

Top Contributors

[![Hywan](https://avatars.githubusercontent.com/u/946104?v=4)](https://github.com/Hywan "Hywan (118 commits)")[![vonglasow](https://avatars.githubusercontent.com/u/1275202?v=4)](https://github.com/vonglasow "vonglasow (13 commits)")[![mgratch](https://avatars.githubusercontent.com/u/2238658?v=4)](https://github.com/mgratch "mgratch (4 commits)")[![zackkatz](https://avatars.githubusercontent.com/u/870979?v=4)](https://github.com/zackkatz "zackkatz (3 commits)")[![jubianchi](https://avatars.githubusercontent.com/u/327237?v=4)](https://github.com/jubianchi "jubianchi (3 commits)")[![stephpy](https://avatars.githubusercontent.com/u/232744?v=4)](https://github.com/stephpy "stephpy (2 commits)")[![hubipe](https://avatars.githubusercontent.com/u/617880?v=4)](https://github.com/hubipe "hubipe (2 commits)")[![Ph3nol](https://avatars.githubusercontent.com/u/183984?v=4)](https://github.com/Ph3nol "Ph3nol (1 commits)")[![jremes-foss](https://avatars.githubusercontent.com/u/4118513?v=4)](https://github.com/jremes-foss "jremes-foss (1 commits)")[![Metalaka](https://avatars.githubusercontent.com/u/5406767?v=4)](https://github.com/Metalaka "Metalaka (1 commits)")[![edsonmedina](https://avatars.githubusercontent.com/u/5449?v=4)](https://github.com/edsonmedina "edsonmedina (1 commits)")[![rparpa](https://avatars.githubusercontent.com/u/2761980?v=4)](https://github.com/rparpa "rparpa (1 commits)")[![shulard](https://avatars.githubusercontent.com/u/482993?v=4)](https://github.com/shulard "shulard (1 commits)")[![tyx](https://avatars.githubusercontent.com/u/245494?v=4)](https://github.com/tyx "tyx (1 commits)")

---

Tags

librarymathsetcombinatoricsarrangementcombinationcountingpermutationsampler

### Embed Badge

![Health badge](/badges/hoa-math-community-math/health.svg)

```
[![Health](https://phpackages.com/badges/hoa-math-community-math/health.svg)](https://phpackages.com/packages/hoa-math-community-math)
```

###  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)[league/iso3166

ISO 3166-1 PHP Library

70036.3M116](/packages/league-iso3166)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49644.8M97](/packages/marc-mabe-php-enum)[alphazygma/combinatorics

Math libraries for Combinatorics (Combinations, Permutations, ...).

15192.0k](/packages/alphazygma-combinatorics)[dekor/php-array-table

PHP Library for printing associative arrays as text table (similar to mysql terminal console)

296.6M2](/packages/dekor-php-array-table)

PHPackages © 2026

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