- Is markrogoyski/math-php compatible with Laravel?
- Yes. It is a standalone, dependency-free PHP library installed via Composer and autoloaded with PSR-4, so it works inside Laravel applications without framework coupling. Laravel version support depends on your PHP version rather than a Laravel-specific constraint, and there is no service provider or config publishing step.
- How do I install Math PHP in a Laravel project?
- Run composer require markrogoyski/math-php and let Composer autoload the classes. There are no migrations, no config publishing, and no Laravel service provider to register. Import the MathPHP namespaces directly in your services, controllers, or jobs.
- Does Math PHP need a service provider or config file in Laravel?
- No. Math PHP has no Laravel coupling and no service infrastructure, so it behaves like any other computational utility dependency. For maintainability, place it behind a thin application-level wrapper such as App\Analytics\StatisticsService so you control the exception contract in one place.
- What can I use Math PHP for in a Laravel application?
- Typical uses include descriptive and inferential statistics, probability distributions, matrices and vectors, number theory, financial calculations, and secure random generation. It is suitable for dashboards, A/B test readouts, feature-scaling pipelines, risk scoring, and other data-driven PHP workflows. Because it runs in-process, you avoid adding a Python service or network hop for many numerical tasks.
- How do I calculate statistics and probability distributions with Math PHP?
- Use the Statistics classes for descriptive stats and hypothesis testing, and the Probability\Distribution classes for distributions such as normal, binomial, and hypergeometric. The API is object-oriented and Composer-autoloaded, so you can call it from Laravel services or jobs. Wrap calls in your own service so exceptions and product decisions are handled consistently.
- Can Math PHP handle matrices and feature scaling in Laravel?
- Yes. Math PHP provides Matrix and Vector classes plus linear algebra operations, and v2.13.0 adds columnAddScalar, columnSubtract, columnSubtractScalar, and columnDivide. Those column operations let feature-scaling and data-transformation workflows stay inside PHP and Laravel instead of being moved to a separate Python service or BI tool.
- What changed in Math PHP v2.13.0?
- v2.13.0 includes behavioral changes in a minor release. SampleData\People::getShowSize was renamed to getShoeSize, which is fatal for live callers. Several statistical functions that previously returned NaN, INF, 0, or empty results now throw exceptions, and fractionalRanking, cumulativeFrequency, cumulativeRelativeFrequency, Hypergeometric::cdf, and geometricMean change numeric results without signature changes. Pin exact versions and review call sites before upgrading.
- Why does Math PHP throw exceptions instead of returning NaN or INF?
- The v2.13.0 release migrates many correlation, effect-size, divergence, stem-and-leaf, Grubbs outlier, and Experiment functions from tolerant sentinel values to exceptions. This is a correctness improvement, but it means Laravel controllers or queued jobs that relied on NaN/INF/0/empty returns may now fail. Decide per call site whether to fail the request, degrade gracefully, or use a documented fallback.
- How do I test Math PHP numeric output in Laravel?
- Use golden-file or snapshot tests around any user-visible numeric output, such as dashboards, pricing, risk scores, or model inputs. Capture results before and after upgrading, especially for functions with silent numeric drift in v2.13.0. Also test the new exception paths so queued jobs do not poison the queue.
- What are alternatives to Math PHP for Laravel, and how do I maintain it safely?
- Alternatives include calling a Python/NumPy service, using a BI tool, or choosing another PHP math library, but Math PHP avoids a network hop and keeps computation in-process. Maintain it by pinning exact versions because the project applies semver loosely, inventorying call sites, wrapping it in an application-level facade, and snapshot-testing numerics. If wrong numbers are a trust or compliance event, weight validation and review higher.