Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

math-php

> 数据库
Open source

Powerful modern math library for PHP: Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with ma

2.4K stars0 likes2 views
WebsiteGitHub

About

Powerful modern math library for PHP: Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with ma

MathPHP - Powerful Modern Math Library for PHP

The only library you need to integrate mathematical functions into your applications. It is a self-contained library in pure PHP with no external dependencies. Features

  • Algebra
  • Arithmetic
  • Expression
    • Polynomial
  • Finance
  • Functions
    • Map
    • Special Functions
  • Information Theory
    • Entropy
  • Linear Algebra
    • Matrix
    • Vector
  • Numbers
    • Arbitrary Integer
    • Complex
    • Quaternion
    • Rational
  • Number Theory
    • Integers
  • Numerical Analysis
    • Interpolation
    • Numerical Differentiation
    • Numerical Integration
    • Root Finding
  • Probability
    • Combinatorics
    • Distributions
      • Continuous
      • Discrete
      • Multivariate
      • Tables
  • Sample Data
  • Search
  • Sequences
    • Basic
    • Advanced
    • NonInteger
  • Set Theory
  • Statistics
    • ANOVA
    • Averages
    • Circular
    • Correlation
    • Descriptive
    • Distance
    • Distributions
    • Divergence
    • Effect Size
    • Experiments
    • Kernel Density Estimation
    • Multivariate
      • PCA (Principal Component Analysis)
      • PLS (Partial Least Squares Regression)
    • Outlier
    • Random Variables
    • Regressions
    • Significance Testing
  • Trigonometry

Setup

Add the library to your composer.json file in your project:

javascript
{
  "require": {
      "markrogoyski/math-php": "2.*"
  }
}

Use composer to install the library:

bash
$ php composer.phar install

Composer will install MathPHP inside your vendor folder. Then you can add the following to your .php files to use the library with Autoloading.

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

Alternatively, use composer on the command line to require and install MathPHP:

$ php composer.phar require markrogoyski/math-php:2.*

Minimum Requirements

  • PHP 7.2

Note: For PHP 7.0 and 7.1, use v1.0 (markrogoyski/math-php:1.*)

Usage

Algebra

…

Arithmetic

…

Expression - Polynomial

…

Finance

…

Functions - Map - Single Array

…

Functions - Map - Multiple Arrays

…

Functions - Special Functions

…

Information Theory - Entropy

…

Linear Algebra - Matrix

…

Linear Algebra - Matrix Construction (Factory)

…

Linear Algebra - Vector

…

Number - Arbitrary Length Integers

…

Number - Complex Numbers

…

Number - Quaternion

…

Number - Rational Numbers

…

Number Theory - Integers

…

Numerical Analysis - Interpolation

…

Numerical Analysis - Numerical Differentiation

…

Numerical Analysis - Numerical Integration

…

Numerical Analysis - Root Finding

…

Probability - Combinatorics

…

Probability - Continuous Distributions

…

Probability - Discrete Distributions

…

Probability - Multivariate Distributions

…

Probability - Distribution Tables

…

Sample Data

…

Search

…

Sequences - Basic

…

Sequences - Advanced

…

Sequences - Non-Integer

php
use MathPHP\Sequence\NonInteger;

$n = 4; // Number of elements in the sequence

// Harmonic sequence
$harmonic = NonInteger::harmonic($n);
// [1, 3/2, 11/6, 25/12] - Indexed from 1

// Generalized harmonic sequence
$m           = 2;  // exponent
$generalized = NonInteger::generalizedHarmonic($n, $m);
// [1, 5 / 4, 49 / 36, 205 / 144] - Indexed from 1

// Hyperharmonic sequence
$r             = 2;  // depth of recursion
$hyperharmonic = NonInteger::hyperharmonic($n, $r);
// [1, 5/2, 26/6, 77/12] - Indexed from 1

Set Theory

…

Statistics - ANOVA

…

Statistics - Averages

…

Statistics - Circular

…

Statistics - Correlation

…

Statistics - Descriptive

…

Statistics - Distance

…

Statistics - Distributions

…

Statistics - Divergence

php
use MathPHP\Statistics\Divergence;

// Probability distributions
$X = [0.2, 0.5, 0.3];
$Y = [0.1, 0.4, 0.5];

// Divergences
$Dkl⟮X‖Y⟯ = Divergence::kullbackLeibler($X, $Y);
$JSD⟮X‖Y⟯ = Divergence::jensenShannon($X, $Y);

Statistics - Effect Size

…

Statistics - Experiments

…

Statistics - Kernel Density Estimation

…

Statistics - Multivariate - Principal Component Analysis

…

Statistics - Multivariate - Partial Least Squares Regression

…

Statistics - Outlier

…

Statistics - Random Variables

…

Statistics - Regressions

…

Statistics - Significance Testing

…

Trigonometry

php
use MathPHP\Trigonometry;

$n      = 9;
$points = Trigonometry::unitCircle($n); // Produce n number of points along the unit circle

Unit Tests

Beyond 100% code coverage!

MathPHP has thousands of unit tests testing individual functions directly with numerous data inputs to achieve 100% test coverage. MathPHP unit tests also test mathematical axioms which indirectly test the same functions in multiple different ways ensuring that those math properties all work out according to the axioms.

bash
$ cd tests
$ phpunit

Standards

MathPHP conforms to the following standards:

  • PSR-1 - Basic coding standard (http://www.php-fig.org/psr/psr-1/)
  • PSR-4 - Autoloader (http://www.php-fig.org/psr/psr-4/)
  • PSR-12 - Extended coding style guide (http://www.php-fig.org/psr/psr-12/)

License

MathPHP is licensed under the MIT License.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPalgebracombinatoricsdistributionsfinance

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库