hoa/math
Hoa\Math is a PHP library for mathematical expression evaluation, offering functions, constants, arithmetic visitors, combinatorics helpers, and random samplers. It lets applications parse and compute math expressions using extensible contexts.
Treat this as a legacy dependency, not a default Laravel package. hoa/math is archived, its release line stopped in 2017 (the latest being 1.17.05.16, which only expanded the arithmetic constant table), and it has no Laravel integration. Use it only when you specifically need one of its small math primitives and accept the maintenance risk.
Minimal steps:
Check whether it can coexist with your app before committing:
composer require hoa/math --dry-run
composer why-not hoa/math
Expect possible conflicts with modern PHP and other hoa/* packages. Do not use --ignore-platform-reqs just to force it in.
Look first at the source and README for:
Hoa\Math\Set — set operations such as union, intersection, difference, Cartesian product, power set.Hoa\Math\Combinatorics\Combination — combinations/arrangements for small combinatorics tasks.Hoa\Math\Context and Hoa\Math\Visitor\Arithmetic — variable/function context and AST arithmetic evaluation, usually in conjunction with Hoa\Compiler.Try the simplest useful case in php artisan tinker, e.g. comparing permission sets:
use Hoa\Math\Set;
$current = new Set(['read', 'write']);
$required = new Set(['write', 'publish']);
$missing = $required->difference($current);
The first realistic day-to-day use case is not “do math in Laravel”; it is “use one isolated set/combinatorics helper behind an adapter.” For expression evaluation, confirm the Hoa\Compiler dependency path first, because the arithmetic visitor is AST-oriented and may pull in more legacy surface than expected.
Wrap Hoa types behind application-owned services. Do not let Hoa\Math\Set, visitors, or exceptions leak into controllers, models, or Blade views.
final class PermissionDiff
{
/** @return string[] */
public function missing(array $current, array $required): array
{
$currentSet = new \Hoa\Math\Set($current);
$requiredSet = new \Hoa\Math\Set($required);
return iterator_to_array($requiredSet->difference($currentSet));
}
}
Bind adapters in a service provider so tests can replace them:
$this->app->bind(PermissionDiff::class, fn () => new PermissionDiff());
Use it at the boundaries of a workflow. Good fits:
Convert to Laravel-native structures at the edge. Turn Hoa sets into arrays or Collections before passing data to the rest of the app, and convert back only inside the adapter. This keeps serialization, validation, and testing familiar.
Guard combinatorial input. Combinations grow explosively. Validate n and k, cap results, and push heavier generation into queued jobs rather than synchronous requests.
If using Hoa\Math\Visitor\Arithmetic, keep parsing and evaluation separate. Parse/compile once where possible, validate allowed variables and functions against an allow-list, and cache results keyed by expression plus variable values. Treat it as an evaluator for trusted internal expressions, not as a sandbox for arbitrary user code. The arithmetic constant set is fixed at the library level and differs slightly between 1.17.x builds, so pin the version and assert the constants you rely on.
Test with the exact PHP version used in production. A package that worked on PHP 7-era runtimes may behave differently under PHP 8.x. Add a small smoke test for the specific set or arithmetic operation you depend on.
Hoa\...), and there is no config file, Artisan integration, or framework-aware exception handling.Hoa\Math\Context, create a fresh context per evaluation or explicitly reset variables/functions. Reusing a mutable context across requests or jobs can produce subtle cross-contamination.brick/math or integer minor units for currency; use hoa/math only for ordinary native numeric work.hoa/* dependency family is old; check composer why-not hoa/math and avoid forcing installation into a modern Laravel dependency graph.1.17.05.16 patch only widened the arithmetic constant table (e.g. additional named constants available to Visitor\Arithmetic). Do not design around a constant being present unless your composer.lock pins that build and a test covers it; upgrading or downgrading the patch level can change which constants resolve.brick/math for precision, and a maintained expression evaluator for user-defined formulas. Keep hoa/math only where existing legacy behavior must be preserved.How can I help you explore Laravel packages today?