home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / misc_programming / batnmore.z!p / DECOMPOS.BTM < prev    next >
Text File  |  1992-11-15  |  2KB  |  57 lines

  1. *REM This batch file is Freeware, free to use and redistribute unmodified *
  2. *REM Jouni Miettunen * jon@stekt.oulu.fi * Oulu * Finland * Europe * 1992 *
  3.  
  4. REM Divide numbers into prime number factors
  5. REM Some extra code added to get around 9 digit limit in IF/IFF comparisons
  6. REM Timestamp 15-Nov-1992
  7.  
  8. break on^setlocal^unalias *^if %#==0 .or. "%1"=="-?" goto info
  9.  
  10. alias next `shift^if "%1" != "" goto work^goto end`
  11.  
  12. REM Reset variables back to defaults, check for negative numbers and zero
  13.  
  14. :work
  15. set index=5^set test=%1^if %_column != 0 echo.
  16. iff %@ascii[%test]==45 then^echos %test = -1^set test=%@eval[-1*%test]
  17. elseiff %test=0 then^echo 0 = 0^next %1^else^echos %test = 1^endiff
  18.  
  19. REM Process even numbers
  20.  
  21. :2loop
  22. if %@eval[%test%%%2] != 0 goto 3loop^echos ` `* 2^set test=%@eval[%test/2]
  23. goto 2loop
  24.  
  25. REM Divide numbers by three, special case to speed up things
  26.  
  27. :3loop
  28. if %@eval[%test%%%3] != 0 goto loop^echos ` `* 3^set test=%@eval[%test/3]
  29. goto 3loop
  30.  
  31. REM the main loop, check if there are more numbers in queue
  32.  
  33. :loop
  34. iff %@eval[%test%%%%index] != 0 then
  35.     iff %test==1 then^next %1^endiff
  36.     set index=%@eval[%index+2+(%index+1)%%3]^goto loop
  37. else^echos ` `* %index^set test=%@eval[%test/%index]^endiff
  38. goto loop
  39.  
  40. :info
  41. echo Usage:%@lower[%@name[%0]] number(s)
  42. echo.
  43. echo Divides numbers into prime number factors
  44.  
  45. :end
  46. break off^quit
  47.  
  48. REM Well, even more optimized C code isn't fast enough.. Need info about MPQS
  49. REM "the fastest currently known general factoring algoritm" (1992). Anybody?
  50.  
  51. REM References for future inspirations:
  52. REM 1987 Cohen,H. & Lenstra,A.K.: Implementation of a new primality test (and Suppelement). Math. Comp. 48: 103-121 and S1-S4
  53. REM 1984 Cohen,H. & Lenstra,Jr.,H.W.: Primality testing and Jacobi sums. Math. Comp. 42: 297-330
  54. REM 1975 Guy,R.K.: How to factor a number. Proc. Fifth Manitoba conf. Numerical Math. 49-89 (Congressus Numerantium, XVI, Winnipeg, Manitoba, 1976)
  55. REM 1984 Williams,H.C.: Factoring on a computer. Math. Intelligencer 6: No. 3, 29-36
  56. REM 1984 An overview of factoring. In _Advances in Cryptology_ (Edited by D.Chaum), 71-80 Plenum, New York, 1984
  57.