PHP Class MathPHP\Algebra

显示文件 Open project: markrogoyski/math-php

Public Methods

Method Description
extendedGCD ( integer $a, integer $b ) : array Extended greatest common divisor Compute the gcd as a multiple of the inputs: gcd(a, b) = a*a' + b*b' https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm Knuth, The Art of Computer Programming, Volume 2, 4.5.2 Algorithm X.
factors ( integer $x ) : array Get factors of an integer The decomposition of a composite number into a product of smaller integers.
gcd ( integer $a, integer $b ) : integer Greatest common divisor - recursive Euclid's algorithm The largest positive integer that divides the numbers without a remainder.
lcm ( integer $a, integer $b ) : integer Least common multiple The smallest positive integer that is divisible by both a and b.

Method Details

extendedGCD() public static method

Extended greatest common divisor Compute the gcd as a multiple of the inputs: gcd(a, b) = a*a' + b*b' https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm Knuth, The Art of Computer Programming, Volume 2, 4.5.2 Algorithm X.
public static extendedGCD ( integer $a, integer $b ) : array
$a integer
$b integer
return array [gcd, a', b']

factors() public static method

https://en.wikipedia.org/wiki/Integer_factorization Method: Iterate from 1 to √x If x mod i = 0, it is a factor Furthermore, x/i is a factor
public static factors ( integer $x ) : array
$x integer
return array of factors

gcd() public static method

For example, the GCD of 8 and 12 is 4. https://en.wikipedia.org/wiki/Greatest_common_divisor gcd(a, 0) = a gcd(a, b) = gcd(b, a mod b)
public static gcd ( integer $a, integer $b ) : integer
$a integer
$b integer
return integer

lcm() public static method

For example, the LCM of 5 and 2 is 10. https://en.wikipedia.org/wiki/Least_common_multiple |a ⋅ b| lcm(a, b) = --------- gcd(a, b)
public static lcm ( integer $a, integer $b ) : integer
$a integer
$b integer
return integer