PHP Класс MathPHP\Algebra

Показать файл Открыть проект

Открытые методы

Метод Описание
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.

Описание методов

extendedGCD() публичный статический Метод

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
Результат array [gcd, a', b']

factors() публичный статический Метод

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
Результат array of factors

gcd() публичный статический Метод

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
Результат integer

lcm() публичный статический Метод

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
Результат integer