php-math
Collection of mathematical and math related functions
* Get all divisors of $x * if $all==true return the other half * Output #1 (default): factors(10) => array(1=>10,2=>5) * Output #2 : factors(10,true) => array(1=>10,2=>5,5=>2,10=>1) FACTORS - DIVISORS (array)
function factors($x,$all=false,$onlyCount=false)
sum all proper divisors (1 included, N excluded)
function sumFactors($x)
* return: array(0,1) get the first factor (v2)
function firstFactor($x)
* Input: A < B !!! LCD: LOWEST COMMON DIVISOR
function lcd($a,$b)
* Input: array() !!! LCM: LOWEST COMMON MULTIPLE
function lcm($a)
* Needs a prime slieve !!! with primes as keys !!! * Will return all primes that factor in the number (and their powers) unless $howMany is set over 1 * Will return false is $howMany is set and prime factors differ from $howMany (except value 1) * - using this with a prime number will just waste time PRIME FACTORS
function primeFactors($x,&$primeList,$howMany=0)
* Output: array() | eg. prime=>Nth (2=>1,3=>2,5=>3,7=>4,11=>5,13=>6,17=>7,19=>8...) PRIMES
function primes($max)
* Output: bool (true/false) IS PRIME
function is_prime($x)
* Default: Return lowest base at highest power * Backwards: Return highest base -at least squared- * Fallback: Return the number itself at power 1 * eg. unpow(1024) => array(2,10) * eg. unpow(1024,true) => array(32,2) UN-POWER
function unpow($n,$backwards=false)
* n! = n * (n-1) * (n-2) .. 1 [eg. 5! = 5 * 4 * 3 * 2 * 1 = 120] BC FACTORIAL
function bcfact($n)
* Sum all numbers 1...$n * Output : sigma(10) => 55 * Output : sigma(100) => 5050 SIGMA - SUM (int)
function sigma($n)
BC SIGMA big numbers
function bcsigma($n)
* Sum all numbers 1^2...$n^2 * Output : sigma2(4) => 30 * Output : sigma2(10) => 385 SIGMA^2 - SUM^2 (int)
function sigma2($n)
BC SIGMA^2 big numbers
function bcsigma2($n)
* Find out individual grade posibilities when graded by $no Prof.s * $grade (float); grades (int) base10! range 1..10 ! GRADED
function graded($grade,$no,$min=1,$max=10)
* Input: (string) !!!! * Unknown effects for sting length other than 3 or 4 !!! MIGHT LOOP 4ever Kaprekar
function kaprekar($x,$c=0)
* Input: (array) !!!! * Output: (int) number of stages to get to the constant * Unknown effects for Base != ^above^ !!! MIGHT LOOP 4ever Kaprekar BASE b = 6t+3, t>1 (15,21...) (constant length will be 5)
function kaprekarB($x,$base,$c=0,$orig=array())
* Return NEXT Collatz number in Sequence ! * Input: (string/int) Collatz Sequence
function Collatz($n)
* Input: $a, $b (array) !!! A>B ! * Output: (array) !!! ADD a+b (in base $base)
function add($a,$b,$base)
* Input: $a, $b (array) !!! A>B !!! * Output: (array) !!! SUBSTRACT a-b (in base $base)
function sub($a,$b,$base)
* Return next lexicographic permutation of the array PERMUTE
function permute($array)
* Make unique sets for given $base INCREASE UNIQUE
function inc_uniq($a,$base,$autoExpand=false)
* Strip leading zeroes * Output : strip0('00009') => 9 STRIP ZEROES (string)
function strip0($n)
* Get the first (shortest) repeating substring * Useful with fractions::repeating decimals REPEATING SUB STRING
function repeatingSubString($s)
* Get all posible substrings from (string) $s * Output : subStrings('1234') => array('1234','123','234','12','23','34','1','2','3','4') * Output : subStrings('abc') => array('abc','ab','bc','a','b','c') SUB STRINGS (array)
function subStrings($s)
* score a word (eg. 'Bay'=2+1+25=28) WORD SCORE
function wordScore($word)
* Add up all digits in a number ADD DIGITS
function addDigits($stringNumber)
* Up to 999 in English (translate for more langs) SPELL NUMBER
function spellNumber($number,$separator=' ',$useAND=true)
* Dummy DIVISOR OF 1 (bool)
function
* Output : true !!!
function divisor1($n)
function divisor2($n)
* Evaluate if very big integer is divisible * Fallback on engine math if it can handle it //(Slower)??? * Input: (string) !!! * Output : true/false DIVISOR OF 3 (bool)
function divisor3($n)
* Evaluate if very big integer is divisible * Fallback on engine math if it can handle it * Input: (string) !!! * Output : true/false DIVISOR OF 4 (bool)
function divisor4($n)
* Evaluate if very big integer is divisible * Input: (string) !!! * Output : true/false DIVISOR OF 5 (bool)
function divisor5($n)
* Evaluate if very big integer is divisible * Input: (string) !!! * Output : true/false DIVISOR OF 6 (bool)
function divisor6($n)
* Evaluate if very big integer is divisible * Input: (string) !!! * Output : true/false DIVISOR OF 7 (bool)
function divisor7($n)
Licensed to the Public Domain