Questions tagged [factorization]

In mathematics, factorization is basically the decomposition of an object like number or polynomials into a product of smaller, simpler objects. An important subset is Integer Factorization, or further, Prime Factorization.

Factorization is the decomposition of an object (for example, a number, a polynomial, or a matrix) into a product of other objects, or factors, which when multiplied together give the original. For example, the number 45 factors as 3 × 15 or into primes as 3 × 3 × 5, and the polynomial x^2 − 4 factors as (x − 2)(x + 2). In all cases, a product of simpler objects is obtained.

The aim of factoring carried in full is usually to reduce something to “basic building blocks”, such as numbers to prime numbers, or polynomials to irreducible polynomials. Factoring integers is covered by the fundamental theorem of arithmetic and factoring polynomials by the fundamental theorem of algebra. Viète's formulas relate the coefficients of a polynomial to its roots.

The opposite of polynomial factorization is expansion, the multiplying together of polynomial factors to an “expanded” polynomial, written as just a sum of terms.

Integer factorization for large integers appears to be a difficult problem. There is no known method to carry it out quickly. Its complexity is the basis of the assumed security of some public key cryptography algorithms, such as RSA.

A matrix can also be factorized into a product of matrices of special types, for an application in which that form is convenient. One major example of this uses an orthogonal or unitary matrix, and a triangular matrix. There are different types: QR decomposition, LQ, QL, RQ, RZ.

Another example is the factorization of a function as the composition of other functions having certain properties; for example, every function can be viewed as the composition of a surjective function with an injective function. This situation is generalized by factorization systems.

275 questions
154
votes
22 answers

What is the most efficient way of finding all the factors of a number in Python?

Can someone explain to me an efficient way of finding all the factors of a number in Python (2.7)? I can create an algorithm to do this, but I think it is poorly coded and takes too long to produce a result for a large number.
Adnan
  • 2,451
  • 4
  • 24
  • 32
65
votes
9 answers

What is the fastest integer factorization algorithm?

I've written a program that attempts to find Amicable Pairs. This requires finding the sums of the proper divisors of numbers. Here is my current sumOfDivisors() method: int sumOfDivisors(int n) { int sum = 1; int bound = (int) sqrt(n); …
Mithrax
  • 7,053
  • 17
  • 52
  • 58
60
votes
13 answers

Efficiently getting all divisors of a given number

According to this post, we can get all divisors of a number through the following codes. for (int i = 1; i <= num; ++i){ if (num % i == 0) cout << i << endl; } For example, the divisors of number 24 are 1 2 3 4 6 8 12 24. After…
zangw
  • 33,777
  • 15
  • 127
  • 153
36
votes
6 answers

R Function for returning ALL factors

My normal search foo is failing me. I'm trying to find an R function that returns ALL of the factors of an integer. There are at least 2 packages with factorize() functions: gmp and conf.design, however these functions return only prime factors. I'd…
JD Long
  • 55,115
  • 51
  • 188
  • 278
25
votes
2 answers

Generating all factors of a number given its prime factorization

If you already have the prime factorization of a number, what is the easiest way to get the set of all factors of that number? I know I could just loop from 2 to sqrt(n) and find all divisible numbers, but that seems inefficient since we already…
dimo414
  • 42,340
  • 17
  • 131
  • 218
22
votes
9 answers

Efficient storage of prime numbers

For a library, I need to store the first primes numbers up to a limit L. This collection must have a O(1) lookup time (to check whether a number is prime or not) and it must be easy, given a number, to find the next prime number (assuming it is…
Samuel Tardieu
  • 2,040
  • 1
  • 14
  • 17
17
votes
3 answers

Why is this Haskell code snippet not infinitely recursive?

To help me learn Haskell, I am working through the problems on Project Euler. After solving each problem, I check my solution against the Haskell wiki in an attempt to learn better coding practices. Here is the solution to problem 3: primes = 2 :…
Matthew
  • 25,652
  • 26
  • 93
  • 158
17
votes
8 answers

Prime factors in Haskell

I'm new to Haskell. How to generate a list of lists which contains prime factors of next integers? Currently, I only know how to generate prime numbers: primes = map head $ iterate (\(x:xs) -> [y | y<-xs, y `mod` x /= 0 ]) [2..]
Chris
  • 562
  • 1
  • 5
  • 20
15
votes
4 answers

how to generate numbers given their prime factors, but with unknown exponents?

Possible Duplicates: nth ugly number Find the Kth least number for expression (2^x)*(3^y)*(5^z) I'm wondering how to solve this problem in a fast and elegant way: We define "ugly" every number n which can be written in the form: 2^x * 3^y *…
Bakuriu
  • 85,459
  • 18
  • 168
  • 202
15
votes
3 answers

why is integer factorization a non-polynomial time?

I am just a beginner of computer science. I learned something about running time but I can't be sure what I understood is right. So please help me. So integer factorization is currently not a polynomial time problem but primality test is. Assume…
14
votes
6 answers

I have a Python list of the prime factors of a number. How do I (pythonically) find all the factors?

I'm working on a Project Euler problem which requires factorization of an integer. I can come up with a list of all of the primes that are the factor of a given number. The Fundamental Theorem of Arithmetic implies that I can use this list to derive…
spencer nelson
  • 3,745
  • 2
  • 20
  • 21
13
votes
3 answers

Determining complexity of an integer factorization algorithm

I'm starting to study computational complexity, BigOh notation and the likes, and I was tasked to do an integer factorization algorithm and determine its complexity. I've written the algorithm and it is working, but I'm having trouble calculating…
12
votes
1 answer

Why is tail call optimization not occurring here?

We are using recursion to find factors and are receiving a StackOverflow exception. We've read that the C# compiler on x64 computers performs tail call optimizations: JIT definitely does tailcals when running optimized code and not…
Shaun Luttin
  • 107,550
  • 65
  • 332
  • 414
11
votes
2 answers

Efficiently finding all divisors of a number

So I simply want to find all the divisors of a given number (excepting the number itself). Currently, I have this: public static List proper_divisors(int x) { List toreturn = new List(); toreturn.Add(1); int i = 0; int…
soandos
  • 4,699
  • 12
  • 56
  • 89
10
votes
3 answers

Factorization of an integer

While answering another, I stumbled over the question how I actually could find all factors of an integer number without the Symbolic Math Toolbox. For example: factor(60) returns: 2 2 3 5 unique(factor(60)) would therefore return…
thewaywewalk
  • 24,484
  • 9
  • 62
  • 109
1
2 3
18 19