# This file was *autogenerated* from the file ./runSLZ-53.sage
from sage.all_cmdline import *   # import sage library
_sage_const_3 = Integer(3); _sage_const_2 = Integer(2); _sage_const_1 = Integer(1); _sage_const_0 = Integer(0); _sage_const_6 = Integer(6); _sage_const_5 = Integer(5); _sage_const_4 = Integer(4); _sage_const_1023 = Integer(1023); _sage_const_1022 = Integer(1022); _sage_const_10 = Integer(10); _sage_const_53 = Integer(53)#! /opt/sage/sage
# @file runSLZ-113.sage
#
# Run SLZ for p=113
#from scipy.constants.codata import precision
def initialize_env():
    """
    Load all necessary modules.
    """
    compiledSpyxDir = "/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx"
    if compiledSpyxDir not in sys.path:
        sys.path.append(compiledSpyxDir)
    if not 'mpfi' in sage.misc.cython.standard_libs:
        sage.misc.cython.standard_libs.append('mpfi')
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage")
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx")
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py")
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage")
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage")
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage")
    # Matrix operations are loaded by polynomial operations.
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage")
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage")


print "Running SLZ..."
initialize_env()
from sageMpfr import *
from sageGMP  import *
import sys
from subprocess import call
#
## Main variables and parameters.
x         = var('x')
__tmp__=var("x"); func = symbolic_expression(exp(x)).function(x)
precision = _sage_const_53 
emin      = -_sage_const_1022 
emax      = _sage_const_1023  
RRR = RealField(precision)
degree              = _sage_const_0 
alpha               = _sage_const_0 
htrn                = _sage_const_0 
intervalCenter      = _sage_const_0 
intervalRadius      = _sage_const_0 
debugMode           = False          
## Local functions
#
def usage():
    write = sys.stderr.write
    write("\nUsage:\n")
    write("  " + scriptName + " <degree> <alpha> <htrn> <intervalCenter>\n")
    write("               <numberOfNumbers> [debug]\n")
    write("\nArguments:\n")
    write("  degree          the degree of the polynomial (integer)\n")
    write("  alpha           alpha (integer)\n")
    write("  htrn            hardness-to-round - a number of bits (integer)\n")
    write("  intervalCenter  the interval center (a floating-point number)\n")
    write("  numberOfNumbers the number of floating-point numbers in the interval\n")
    write("                  as a positive integral expression\n")
    write("  debug           debug mode (\"debug\", in any case)\n\n")
    sys.exit(_sage_const_2 )
# End usage.
#
argsCount = len(sys.argv)
scriptName = os.path.basename(__file__)
if argsCount < _sage_const_5 :
    usage()
for index in xrange(_sage_const_1 ,argsCount):
    if index == _sage_const_1 :
        degree = int(sys.argv[index])
    elif index == _sage_const_2 :
        alpha = int(sys.argv[index])
    elif index == _sage_const_3 :
        htrn = int(eval(sys.argv[index]))
    elif index == _sage_const_4 :
        try:
            intervalCenter = QQ(sage_eval(sys.argv[index]))
        except:
            intervalCenter = RRR(sys.argv[index])
        intervalCenter = RRR(intervalCenter)
    elif index == _sage_const_5 :
        ## Can be read as rational number but must end up as an integer.
        numberOfNumbers = QQ(sage_eval(sys.argv[index]))
        if numberOfNumbers != numberOfNumbers.round():
            raise Exception("Invalid number of numbers: " + sys.argv[index] + ".")
        numberOfNumbers = numberOfNumbers.round()
        ## The number must be strictly positive.
        if numberOfNumbers <= _sage_const_0 :
            raise Exception("Invalid number of numbers: " + sys.argv[index] + ".")
    elif index == _sage_const_6 :
        debugMode = sys.argv[index].upper()
        debugMode = (debugMode == "DEBUG")
# Done with command line arguments collection.
#
## Debug printing
print "degree         :", degree
print "alpha          :", alpha
print "htrn           :", htrn
print "interval center:", intervalCenter.n(prec=_sage_const_10 ).str(truncate=False)
print "num of nums    :", RR(numberOfNumbers).log2().n(prec=_sage_const_10 ).str(truncate=False)
print "debug mode     :", debugMode
print
#
## Set the terminal window title.
terminalWindowTitle = ['stt', str(degree), str(alpha), str(htrn), 
                       intervalCenter.n(prec=_sage_const_10 ).str(truncate=False), 
                       RRR(numberOfNumbers).log2().n(prec=_sage_const_10 ).str(truncate=False)]
call(terminalWindowTitle)
#
intervalCenterBinade = slz_compute_binade(intervalCenter)
intervalRadius       = \
    _sage_const_2 **intervalCenterBinade * _sage_const_2 **(-precision + _sage_const_1 ) * numberOfNumbers / _sage_const_2 
srs_run_SLZ_v05(inputFunction=func, 
                inputLowerBound         = intervalCenter - intervalRadius, 
                inputUpperBound         = intervalCenter + intervalRadius, 
                alpha                   = alpha, 
                degree                  = degree, 
                precision               = precision, 
                emin                    = emin, 
                emax                    = emax, 
                targetHardnessToRound   = htrn, 
                debug                   = debugMode)
    
