Advanced Mathematics Library for PHP (port of Numbers.js)

Related tags

Numbers numbers.php
Overview

Numbers.php

Numbers.php - an advanced mathematics toolkit for PHP >= 5.3. It is a port of Numbers.js - same toolkit for JavaScript.

There is a version of Numbers.php which supports PHP 5.2, but it is no longer developed: https://github.com/powder96/numbers.php/archive/fd946ea8742ba46789dc2a38cc6c1f93a7512e6d.zip

Description

Numbers.php provides a comprehensive set of mathematical tools that currently are not offered in PHP. These tools include:

  • Basic calculations
  • Calculus
  • Matrix Operations
  • Prime Numbers
  • Statistics
  • More...

A few things to note before using: PHP, like many languages, does not necessarily manage floating points as well as we'd all like it to. For example, if adding decimals, the addition tool won't return the exact value. This is an unfortunate error. Precautions have been made to account for this. After including numbers, you can set an error bound. Anything in this will be considered an "acceptable outcome."

The primary uses cases are calculations and data analysis on the server side. For client side operations, please use Numbers.js.

How to use

Numbers is pretty straightforward to use.

For example, if we wanted to estimate the integral of sin(x) from -2 to 4, we could:

Use riemann integrals (with 200 subdivisions)

use NumbersPHP\Calculus;
use NumbersPHP\Matrix;
use NumbersPHP\Statistic;
use NumbersPHP\Prime;

Calculus::riemann('sin', -2, 4, 200);

Or use adaptive simpson quadrature (with epsilon 0.0001)

Calculus::adaptiveSimpson('sin', -2, 4, 0.0001);

User-defined functions can be used too:

function myFunc($x) {
  return 2 * pow($x, 2) + 1;
}
Calculus::riemann('myFunc', -2, 4, 200);

Calculus::adaptiveSimpson(create_function('$x', 'return 2 * pow($x, 2) + 1;'), -2, 4, 0.0001);

Now say we wanted to run some matrix calculations:

We can add two matrices

$matrix1 = array(array(0, 1, 2),
				 array(3, 4, 5));
$matrix2 = array(array( 6,  7,  8),
				 array( 9, 10, 11));
Matrix::addition($matrix1, $matrix2);

We can transpose a matrix

Matrix::transpose($array);

Numbers also includes some basic prime number analysis. We can check if a number is prime:

//basic check
Prime::simple($number);

// Miller�Rabin primality test
Prime::millerRabin($number);

The statistics tools include mean, median, mode, standard deviation, random sample generator, correlation, confidence intervals, t-test, chi-square, and more.

Statistic::mean($array);
Statistic::median($array);
Statistic::mode($array);
Statistic::standardDev($array);
Statistic::randomSample($lower, $upper, $n);
Statistic::correlation($array1, $array2);

Test

Download and install these things:

Run in the command prompt:

	php composer.phar install
	php phpunit.phar --configuration phpunit.xml.dist

If you are going to run tests multiple times and you are using Microsoft(R) Windows(TM), you can use the batch file /test.cmd. Do not forget to set the path to PHP, Composer, and PHPUnit in the beginnig of that file.

Authors

Numbers.js

Numbers.php

Comments
  • Hey

    Hey

    So I do not expect this pull request to be too successful but I think you should consider it.

    Maybe by making a new branch for 5.3 support but basically I modified this to be php 5.3 friendly

    Overview of the changes:

    I tried editing a few of the doc blocks as most but gave up I converted a good bit of code to the psr2 standard I namespaced the project so no more requires I added composer support (now I left the json file mostly blank, I think someone from numbers.php should add in necessary repo address, name, keywords and so on and submit to composer package list when ready I thought about adding phpunit support but didnt, I will probably need to be done at some stage though And updated the readme

    All tests pass in this build

    I think you should think about switching over to namespaces and composer and keep a separate branch from 5.2 support

    opened by geopal-solutions 3
  • is this thing dead?

    is this thing dead?

    I'm a collaborator for Numbers.js and I'm going to be adding more content to it soon. I was wondering if I should also write the same functions in PHP and merge it here.

    opened by Dakkers 2
  • Introduced new conversion class for base conversion on numbers

    Introduced new conversion class for base conversion on numbers

    use to convert number's bases like decimal to binary, binary to octal and etc and can return string or array according to the passed argument (0 or 1). Exceptions are not handled right now but i am working on it.

    opened by ankitsamarthya 1
  • Filename Case Sensitivity

    Filename Case Sensitivity

    On case sensitive filesystems autoloading these classes fails because the filenames are all lowercase and do not match the class names. This fix simply makes the filenames identical to the classnames.

    opened by zacharyblank 1
  • updates to unit tests

    updates to unit tests

    Hi

    I have done out all the unit tests and they all pass except for Prime::factorization

    This is to do with array indexes out of bounds I have not fixed it just commented it out for now

    You can just run the tests using phpunit with config options because I added phpunit.xml.dist

    I only added two small functions to complex, getReal and getImaginary

    I left in all the old web page tests

    I think this is looking in good shape to submit to composer

    opened by geopal-solutions 0
  • Inverse of a Matrix and Scalar Multiplication

    Inverse of a Matrix and Scalar Multiplication

    Hi, I've used this library recently, and I believe these two functions are pretty much basic part of any linear algebra library. There's already a pull request that implements the inverse of a matrix, but it looks like it wasn't merged..Any eta on this? Thanks!

    opened by ghost 0
Owner
null
PHP version of Google's phone number handling library

libphonenumber for PHP What is it? A PHP library for parsing, formatting, storing and validating international phone numbers. This library is based on

Joshua Gigg 4.2k Jan 7, 2023
Library for converting units and sizes in PHP

php-conversion Library for converting units and sizes in PHP. Units supported Acceleration Angle Area Digital information Electric current Frequency F

Christoffer Niska 127 Dec 23, 2022
BigNum library for PHP compatible with bn.js

BigNum library for PHP Information This library provides a PHP Big Number API compatible with bn.js and is used in Fast PHP ECC library elliptic-php.

Simplito 16 Nov 13, 2022
Library for converting units and sizes in PHP

php-conversion Library for converting units and sizes in PHP. Units supported Acceleration Angle Area Digital information Electric current Frequency F

Christoffer Niska 122 Mar 16, 2021
Mark Rogoyski 2.2k Dec 29, 2022
Arbitrary-precision arithmetic library for PHP

Arbitrary-precision arithmetic library for PHP

Brick 1.4k Jan 1, 2023
Tensor is a library and extension that provides objects for scientific computing in PHP.

Tensor is a library and extension that provides objects for scientific computing in PHP. The multithreaded extension is especially suited for computing large sets of numbers. In some cases, the extension is 230X faster than the same operation in PHPland. Tensor is used by libraries such as Rubix ML to build and accelerate machine learning algorithms such as linear regression, dimensionality reduction, and neural networks.

Rubix 157 Jan 3, 2023
Library to parse, format and convert byte units

Byte Units This is a utility component for parsing, formatting, converting and manipulating byte units in various formats. Usage <?php // Bytes manip

Gabriele Lana 156 Dec 9, 2022
A library for handling physical quantities and the units of measure in which they're represented.

PHP Units of Measure master: Introduction This is a PHP library for representing and converting physical units of measure. The utility of this library

Jonathan Hanson 21 Sep 28, 2022
Unit converter and calculator for php

Unit converter and calculator This library uses the awesome lisachenko/z-engine to allow mathematical operations on objects, allowing to do stuff like

Dominik Chrástecký 8 Apr 8, 2022
A PHP 5.3+ mathematics library, providing functionality for large numbers

Moontoast Math Library Moontoast\Math is useful for working with integers that are larger than (or may become larger than, through mathematical comput

Moontoast 245 Sep 8, 2022
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP

Lodash-PHP Lodash-PHP is a port of the Lodash JS library to PHP. It is a set of easy to use utility functions for everyday PHP projects. Lodash-PHP tr

Lodash PHP 474 Dec 31, 2022
PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Manufacturing Industry, Phone numbers & Zipcodes for many countries

IsoCodes PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Book Industry, Phone numbers & Zipcodes

Ronan Guilloux 767 Jan 2, 2023
A small PHP library to generate YouTube-like ids from numbers.

A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.

Vincent Klaiber 4.9k Dec 30, 2022
A small PHP library for validating VAT identification numbers (VATINs).

VATIN A small PHP library for validating VAT identification numbers (VATINs). Installation This library is available on Packagist: $ composer require

David de Boer 128 Oct 27, 2022
PHP library to validate and format license plate numbers.

License plate validator and formatter CI Status Lint Coverage Tests This library can be used to validate and format license plate numbers. Countries s

Automex.website 1 Oct 19, 2022
A library for generating random numbers and strings

RandomLib A library for generating random numbers and strings of various strengths. This library is useful in security contexts. Install Via Composer

Anthony Ferrara 832 Nov 24, 2022
A small library for validating International Bankaccount Numbers (IBANs) based on the IBAN Registry provided by SWIFT

A small library for validating International Bankaccount Numbers (IBANs) based on the IBAN Registry provided by SWIFT

Jan Schädlich 69 Dec 18, 2022
BaconQrCode is a port of QR code portion of the ZXing library

QR Code generator Introduction BaconQrCode is a port of QR code portion of the ZXing library. It currently only features the encoder part, but could l

Bacon 1.5k Jan 6, 2023
Simple PHP package for add two numbers

Sum Simple PHP package for add two numbers Installation To get the latest version of Sum, simply require the project using Composer: composer require

Nazar 13 Nov 20, 2022