FactorInteger
The prime factorisation of n as a list of [prime, exponent] pairs.
Integer factorizationMathWorldPrimeFactorizationWikidataQ4846249Wolfram LanguageFactorInteger!Rosetta CodePrime decompositionFactorInteger(n)prime factorization of as pairs.enumeratio_factor_integer(n)SymPylist(factorrat(S(n)).items())Juliaenumeratio_factor_integer(n)Rustfactor_integer(n)FactorInteger(n, Over -> GaussianIntegers)the factorisation in : a unit first when it is not 1, then first-quadrant primes; a complex is always factored thereFactorInteger(n, Over -> QuadraticIntegers(d))the prime factorisation of in the ring of integers of , where that ring factors uniquelyenumeratio_factor_integer(d)SymPylist(factorrat(S(d)).items())Juliaenumeratio_factor_integer(d)Rustfactor_integer(d)Typed signatures
| Type | Package | Applies |
|---|---|---|
(integer) -> list<tuple<integer, integer>> | compute-engine | always |
(number | quadratic_integer, any*) -> list | number-theoryreplaces compute-engine | always |
Details
- For , returns the pairs in increasing order of prime.
- Multiplying the factors back together recovers .
- compute-engine represents 1 as and 0 as .
- Negative carries an explicit unit factor ahead of the prime factors.
- compute-engine handles ordinary integers only.
Examples
28 more kept as data, checked against the oraclesScope #
Possible issues #
About
| Examples | 47 |
|---|---|
| Checked against | Wolfram Language 45 agree2 differSageMath 33 agree3 differSymPy 11 agree7 differ4 errormathlib4 6 agree3 differ13 errorJulia 18 agree19 errorRust 8 agree2 differ12 errormpmath 1 agreeOscar 1 agree |
| Crosswalk | WikipediaMathWorldWikidataWolfram LanguageSageMathSymPyJuliaRustRosetta Code |
Implementation
sagepackages/oracle/src/mappings.tsSage has no unit factor for 1, 0 or a negative n — a shape difference from compute-engine's explicit 1^1/0^1/-1^1, not a bug.
sympypackages/oracle/src/mappings.tsfactorrat is SymPy's factorint that also takes a rational, giving the denominator's primes negative exponents as ours does. SymPy has no factor for 1, writes the -1 of a negative integer after the primes and a negative rational's between the numerator's primes and the denominator's, and lists factors in the order it finds them, which for a large n is not always ascending. A Complex operand is not emitted: factorrat takes rationals only, and SymPy has no factorization in Z[i] to ask for.
sympypackages/oracle/src/mappings.tsThe Over -> GaussianIntegers and QuadraticIntegers(d) forms have no SymPy counterpart: factorint and factorrat are over Z and Q, GaussianIntegerRing has a gcd but no prime factorization, and factor(n, gaussian=True) factors polynomials, leaving an integer as it is. Composing one from factorint of the norm and a gcd would test our algorithm against a restatement of itself.
juliapackages/oracle/src/mappings.tsrustpackages/oracle/src/mappings.tsPositive operands only.
mathlib4packages/oracle/src/mappings.tsNat.primeFactorsList (ascending, with multiplicity) grouped into [prime, exponent] pairs. Natural n only: Mathlib has no unit factor, so 0 and 1 give [] where ours gives 0^1 and 1^1, and a negative or rational n is a domain error.
See also: NthPrime, Divisors, PrimeNu, PrimeOmega