Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. def compare_nfs_ecm(nfs_hours, median_curves, hours_per_curve, odds_factor_exists):
  2.      '''This is the meat, the workhorse. Everything else is a helper to precompute the arguments for
  3.     this function.
  4.    
  5.     The arguments are self explanatory. The return value is either number of curves to do, or
  6.     negative if you should just do the usual ECM before proceeding to the next level.
  7.     '''
  8.      # Now we want to find the crossover where ecm-work/odds_of_success = nfs_work.
  9.      # That is, curves*work_per_curve/[odds*(1-exp(-curves/median))] = nfs_work, which is transcendental.
  10.      # Fortunately it's an analytic function with no pathologies, so a stupid Newton iteration to
  11.      # find the solution will work fine.
  12.      f = lambda curves: curves*hours_per_curve/(-expm1(-curves/median_curves)) - odds_factor_exists*nfs_hours
  13.  
  14.      # ...rest of function is newton iteration to find the 0 of f