## Tuesday, November 29, 2011

### Math: Factoring Numbers

I was thinking this morning about factoring numbers. I wonder if it might sometimes be helpful to use real numbers to gain an interesting perspective in order to solve certain problems involving integer numbers (i.e. number theory problems). For instance, I was thinking about factoring large numbers.

For every natural number, C, (that isn't equal to 0 or 1), there are an infinite number of pairs of positive, real numbers A and B for which A * B = C. For instance, 6 = 1.0 * 6.0 = 2.4 * 2.5 = 2.0 * 3.0 = ... I wonder if playing around with pairs of real numbers like (2.4, 2.5) can lead you to pairs of integer numbers like (2, 3).

Imagine all the pairs (A, B) for which A * B = C. Let's create a way to graph all such pairs in a funny sort of way. Let's pick a bunch of A's going from 0 to C. For each different A, we can calculate B via C / A. Let's consider the parts of A and B that are to the right of the decimal point to see if one pair, (A, B) can lead us to another pair (A', B') which are integers (i.e. have only zeros to the right of the decimal point). In fact, let's see if we can come up with a numerical analysis approach where we use estimations to hunt down (A', B').

To do this, let's create a funny sort of three dimensional graph. Here's the pseudo code (assuming we're trying to factor some number, c):
`for step in range (1, LARGE_NUM_OF_STEPS + 1):    a = (step / LARGE_NUM_OF_STEPS) * c    b = c / a    x = a - int(a)  # x and y will always be in the range [0, 1).    y = b - int(b)    z = floor(a)    draw_point(x, y, z)`
If you use a very large number for LARGE_NUM_OF_STEPS, you'll create a funny looking 3D graph. Any place where x = 0 and y = 0, you'll have a pair of integers (a, b) that multiply to equal c.

Naturally, this is an extremely expensive way to factor numbers. However, I'll bet you'd learn a lot about factoring numbers by looking at this graph. In fact, I'm guessing that looking at this graph will lead you to a numerical-analysis-style approximation algorithm for honing in on valid integer pairs (a, b) where a * b = c.

Humans are fairly good at visualizing things in 3D, but it'd be really cool to extend this graph to four dimensions (perhaps using time as the fourth dimension). The fourth dimension would be used for various values of C, from 0 to infinity. I really think that looking at such a graph would help with fast number factoring.

Updated: Fixed a couple of errors pointed out by BMeph.

Eric Bloch said...

re: initial comment about real numbers.

A lot of the stuff in Knuth's book on Concrete math is based on the principals of using ideas from continous, infinitesimal calculus and applying them to discrete math problems (hence title con-crete). It's a great book.

Shannon -jj Behrens said...

"Using ideas from continous, infinitesimal calculus and applying them to discrete math problems" is exactly what I had in mind, and the fact that Knuth beat me to the punch is probably a good sign. Thanks, Eric! :)

BMeph said...

As a member of the Pedantic Police, I feel "Compelled" to hand out some tickets for clarity's sake:

"a = (i / LARGE_NUM_OF_STEPS) * c" should be "a = (step / LARGE_NUM_OF_STEPS) * c", or you can change the for line above it. Being a pedant, I of course prefer the wordier version.

"z = floor(x)" should be "z = floor(a)", since otherwise it'll always be 0.

Shannon -jj Behrens said...

You are quite correct. Thank you :)