Git Product home page Git Product logo

numbers.php's Introduction

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

numbers.php's People

Contributors

btmills avatar ethanresnick avatar foundrium avatar geopal-solutions avatar hrishikeshparanjape avatar kartiktalwar avatar larrybattle avatar leppert avatar mattfowler avatar milroc avatar napoleond avatar nkohari avatar philipithomas avatar sjkaliski avatar swairshah avatar thebyrd avatar timrwood avatar zikes avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.