root / pobysoPythonSage / src / sageSLZ / runSLZ-113proj-02.sage.py @ 281
Historique | Voir | Annoter | Télécharger (6,99 ko)
| 1 |
# This file was *autogenerated* from the file ./runSLZ-113proj-02.sage
|
|---|---|
| 2 |
from sage.all_cmdline import * # import sage library |
| 3 |
_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_113 = Integer(113); _sage_const_10 = Integer(10); _sage_const_16383 = Integer(16383); _sage_const_16382 = Integer(16382)#! /opt/sage/sage |
| 4 |
# @file runSLZ-113proj-92.sage
|
| 5 |
#
|
| 6 |
#@par Changes from runSLZ-113proj.sage
|
| 7 |
# The uniform random matrix element can be integers in the
|
| 8 |
# [-2^(n-1),2^(n-1)-1] range. The value of "n" is set in function
|
| 9 |
# slz_reduce_lll_proj_02.
|
| 10 |
#
|
| 11 |
#@par Changes from runSLZ-113.sage
|
| 12 |
# LLL reduction is not performed on the matrix itself but rather on the
|
| 13 |
# product of the matrix with a uniform random matrix.
|
| 14 |
# The reduced matrix obtained is discarded but the transformation matrix
|
| 15 |
# obtained is used to multiply the original matrix in order to reduced it.
|
| 16 |
# If a sufficient level of reduction is obtained, we stop here. If not
|
| 17 |
# the product matrix obtained above is LLL reduced. But as it has been
|
| 18 |
# pre-reduced at the above step, reduction is supposed to be much faster.
|
| 19 |
#
|
| 20 |
# Both reductions combined should hopefully be faster than a straight single
|
| 21 |
# reduction.
|
| 22 |
#
|
| 23 |
# Run SLZ for p=113
|
| 24 |
#from scipy.constants.codata import precision
|
| 25 |
def initialize_env(): |
| 26 |
"""
|
| 27 |
Load all necessary modules.
|
| 28 |
"""
|
| 29 |
if version().split()[_sage_const_2 ].replace(',','') > '6.6': |
| 30 |
compiledSpyxDir = \ |
| 31 |
"/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx"
|
| 32 |
if compiledSpyxDir not in sys.path: |
| 33 |
sys.path.append(compiledSpyxDir) |
| 34 |
else:
|
| 35 |
if not 'mpfi' in sage.misc.cython.standard_libs: |
| 36 |
sage.misc.cython.standard_libs.append('mpfi')
|
| 37 |
load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
|
| 38 |
load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx")
|
| 39 |
load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage")
|
| 40 |
# load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
|
| 41 |
# load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx")
|
| 42 |
load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py")
|
| 43 |
load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage")
|
| 44 |
load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage")
|
| 45 |
load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage")
|
| 46 |
# Matrix operations are loaded by polynomial operations.
|
| 47 |
load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage")
|
| 48 |
load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage")
|
| 49 |
|
| 50 |
|
| 51 |
print "Running SLZ..." |
| 52 |
initialize_env() |
| 53 |
if version().split()[_sage_const_2 ].replace(',','') > '6.6': |
| 54 |
from sageMpfr import * |
| 55 |
from sageGMP import * |
| 56 |
import sys |
| 57 |
from subprocess import call |
| 58 |
#
|
| 59 |
## Main variables and parameters.
|
| 60 |
x = var('x')
|
| 61 |
__tmp__=var("x"); func = symbolic_expression(exp(x)).function(x)
|
| 62 |
precision = _sage_const_113 |
| 63 |
emin = -_sage_const_16382 |
| 64 |
emax = _sage_const_16383 |
| 65 |
RRR = RealField(precision) |
| 66 |
degree = _sage_const_0 |
| 67 |
alpha = _sage_const_0 |
| 68 |
htrn = _sage_const_0 |
| 69 |
intervalCenter = _sage_const_0 |
| 70 |
intervalRadius = _sage_const_0 |
| 71 |
debugMode = False
|
| 72 |
## Local functions
|
| 73 |
#
|
| 74 |
def usage(): |
| 75 |
write = sys.stderr.write |
| 76 |
write("\nUsage:\n")
|
| 77 |
write(" " + scriptName + " <degree> <alpha> <htrn> <intervalCenter>\n") |
| 78 |
write(" <numberOfNumbers> [debug]\n")
|
| 79 |
write("\nArguments:\n")
|
| 80 |
write(" degree the degree of the polynomial (integer)\n")
|
| 81 |
write(" alpha alpha (integer)\n")
|
| 82 |
write(" htrn hardness-to-round - a number of bits (integer)\n")
|
| 83 |
write(" intervalCenter the interval center (a floating-point number)\n")
|
| 84 |
write(" numberOfNumbers the number of floating-point numbers in the interval\n")
|
| 85 |
write(" as a positive integral expression\n")
|
| 86 |
write(" debug debug mode (\"debug\", in any case)\n\n")
|
| 87 |
sys.exit(_sage_const_2 ) |
| 88 |
# End usage.
|
| 89 |
#
|
| 90 |
argsCount = len(sys.argv)
|
| 91 |
scriptName = os.path.basename(__file__) |
| 92 |
if argsCount < _sage_const_5 :
|
| 93 |
usage() |
| 94 |
for index in xrange(_sage_const_1 ,argsCount): |
| 95 |
if index == _sage_const_1 :
|
| 96 |
degree = int(sys.argv[index])
|
| 97 |
elif index == _sage_const_2 :
|
| 98 |
alpha = int(sys.argv[index])
|
| 99 |
elif index == _sage_const_3 :
|
| 100 |
htrn = int(eval(sys.argv[index])) |
| 101 |
elif index == _sage_const_4 :
|
| 102 |
try:
|
| 103 |
intervalCenter = QQ(sage_eval(sys.argv[index])) |
| 104 |
except:
|
| 105 |
intervalCenter = RRR(sys.argv[index]) |
| 106 |
intervalCenter = RRR(intervalCenter) |
| 107 |
elif index == _sage_const_5 :
|
| 108 |
## Can be read as rational number but must end up as an integer.
|
| 109 |
numberOfNumbers = QQ(sage_eval(sys.argv[index])) |
| 110 |
if numberOfNumbers != numberOfNumbers.round():
|
| 111 |
raise Exception("Invalid number of numbers: " + sys.argv[index] + ".") |
| 112 |
numberOfNumbers = numberOfNumbers.round() |
| 113 |
## The number must be strictly positive.
|
| 114 |
if numberOfNumbers <= _sage_const_0 :
|
| 115 |
raise Exception("Invalid number of numbers: " + sys.argv[index] + ".") |
| 116 |
elif index == _sage_const_6 :
|
| 117 |
debugMode = sys.argv[index].upper() |
| 118 |
debugMode = (debugMode == "DEBUG")
|
| 119 |
# Done with command line arguments collection.
|
| 120 |
#
|
| 121 |
## Debug printing
|
| 122 |
print "degree :", degree |
| 123 |
print "alpha :", alpha |
| 124 |
print "htrn :", htrn |
| 125 |
print "interval center:", intervalCenter.n(prec=_sage_const_10 ).str(truncate=False) |
| 126 |
print "num of nums :", RR(numberOfNumbers).log2().n(prec=_sage_const_10 ).str(truncate=False) |
| 127 |
print "debug mode :", debugMode |
| 128 |
print
|
| 129 |
#
|
| 130 |
## Set the terminal window title.
|
| 131 |
terminalWindowTitle = ['stt', str(degree), str(alpha), str(htrn), |
| 132 |
intervalCenter.n(prec=_sage_const_10 ).str(truncate=False),
|
| 133 |
RRR(numberOfNumbers).log2().n(prec=_sage_const_10 ).str(truncate=False)]
|
| 134 |
call(terminalWindowTitle) |
| 135 |
#
|
| 136 |
intervalCenterBinade = slz_compute_binade(intervalCenter) |
| 137 |
intervalRadius = \ |
| 138 |
_sage_const_2 **intervalCenterBinade * _sage_const_2 **(-precision + _sage_const_1 ) * numberOfNumbers / _sage_const_2 |
| 139 |
srs_run_SLZ_v05_proj_02(inputFunction=func, |
| 140 |
inputLowerBound = intervalCenter - intervalRadius, |
| 141 |
inputUpperBound = intervalCenter + intervalRadius, |
| 142 |
alpha = alpha, |
| 143 |
degree = degree, |
| 144 |
precision = precision, |
| 145 |
emin = emin, |
| 146 |
emax = emax, |
| 147 |
targetHardnessToRound = htrn, |
| 148 |
debug = debugMode) |
| 149 |
|