Fermat's Algorithm for finding factors of a number near the square
root of a number..... until a multiprecision program is found, this has a limit
of the number to be factored < 10^12 or thereabouts.....
Any comments about the code itself (suggestions....speed improvements, etc
) would be greatly appreciated as I would like to 'catch up' to the tricks of
the trade in HP-28S programming.
Hope someone out there finds this useful.....
<< -> n
<< n square-root FLOOR 'sqrt' STO :comment replace square root with
2 sqrt * 1 + 'u' STO :the symbol that is on the calculator
1 'v' STO
sqrt DUP * n - 'r' STO
WHILE r 0 <> REPEAT
IF r 0 > THEN
WHILE r 0 > REPEAT
r v - 'r' STO
v 2 + 'v' STO
END
END
IF r 0 < THEN
r u + 'r' STO
u 2 + 'u' STO
END
END
u v + 2 - 2 /
u v - 2 /
>>
{ 'r' 'v' 'u' 'sqrt' } PURGE
>>
STACK:
in: out:
1: Number to be factored 1: first factor
2: second factor
-------
********************************************************************
* J.J. * JJL101@psuvm.bitnet *
* * Penn State Center for Academic Computing *
* John Lehett * Computational Mathematics *
********************************************************************