

# This file was *autogenerated* from the file ./get_D.sage
from sage.all_cmdline import *   # import sage library

_sage_const_2 = Integer(2); _sage_const_1 = Integer(1); _sage_const_0 = Integer(0); _sage_const_512 = Integer(512); _sage_const_128 = Integer(128); _sage_const_8 = Integer(8); _sage_const_4p0 = RealNumber('4.0')
import argparse

def ps(q, m, n):
  R = PowerSeriesRing(ZZ, names=('X',)); (X,) = R._first_ngens(1)

  if(q == _sage_const_2 ):
    return (_sage_const_1 +X)**n/((_sage_const_1 -X)*(_sage_const_1 +X**_sage_const_2 )**m)
  else:
    return (_sage_const_1 -X)**(m-n-_sage_const_1 )*(_sage_const_1 +X)**m


def deg_info(q, m, n):
  f_XL = ps(q, m, n)

  for i, coef in enumerate(f_XL):
    if coef <= _sage_const_0 :
      return i

  return -_sage_const_1 


parser = argparse.ArgumentParser(description='',
                                 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-q', dest='q',
                   type=int, required=True,
                   help='field')

parser.add_argument('-m', dest='m',
                   type=int, required=True,
                   help='M')

parser.add_argument('-n', dest='n',
                   type=int, required=True,
                   help='N')

parser.add_argument("-s", "--stat", help="print stat", action="store_true")

options = parser.parse_args()

deg = deg_info(q = options.q, m = options.m, n = options.n)


if not options.stat:
  print(deg)
else:

  def num_mons_sum(q, n, d):
      if(q == _sage_const_2 ):
          sum = _sage_const_0 ;
          for i in range(d + _sage_const_1 ):
              sum += binomial(n, i);
      else:
          sum = binomial(n + d, d);
  
      return sum;

  if options.q == _sage_const_2 :
    BW_N = _sage_const_512 
    BW_M = _sage_const_512 
  else:
    BW_N = _sage_const_128 
    BW_M = _sage_const_128 
  
  n = options.n
  m = options.m
  
  Mac_width = num_mons_sum(options.q, n, deg)
  orig_sys_m = num_mons_sum(options.q, n, _sage_const_2 )
  
  num_it = Mac_width / BW_M + Mac_width / BW_N + _sage_const_8 

  bm = (num_it*num_it) / _sage_const_4p0  * (float)(_sage_const_2 *BW_N*BW_N*BW_N)
  
  bw1 = (Mac_width * orig_sys_m + (BW_N * BW_N)) * BW_N * num_it
  
  print("%i %.0f %.0f %.02f %i %i" % (m, bw1, bm, bw1/bm, orig_sys_m, deg))


