Révision 253

pobysoPythonSage/src/sageSLZ/argsForRunSLZ-53-binade-01.sh (revision 253)
1
#! /bin/bash
2
#@file argsForRunSLZ-53-01proj.sh
3
DEGREE=3
4
ALPHA=3
5
HARDNESS_TO_ROUND="53+50"
6
BINADE="-31"
7
#
8
printf -- "$DEGREE \
9
$ALPHA \
10
$HARDNESS_TO_ROUND \
11
$BINADE\n"
0 12

  
pobysoPythonSage/src/sageSLZ/runSLZ-53-binade.sage (revision 253)
1
#! /opt/sage/sage
2
# @file runSLZ-113proj.sage
3
#
4
#@par Changes from runSLZ-113.sage
5
# LLL reduction is not performed on the matrix itself but rather on the
6
# product of the matrix with a uniform random matrix.
7
# The reduced matrix obtained is discarded but the transformation matrix 
8
# obtained is used to multiply the original matrix in order to reduced it.
9
# If a sufficient level of reduction is obtained, we stop here. If not
10
# the product matrix obtained above is LLL reduced. But as it has been
11
# pre-reduced at the above step, reduction is supposed to be much faster.
12
#
13
# Both reductions combined should hopefully be faster than a straight single
14
# reduction.
15
#
16
# Run SLZ for p=113
17
#from scipy.constants.codata import precision
18
def initialize_env():
19
    """
20
    Load all necessary modules.
21
    """
22
    compiledSpyxDir = "/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx"
23
    if compiledSpyxDir not in sys.path:
24
        sys.path.append(compiledSpyxDir)
25
    if not 'mpfi' in sage.misc.cython.standard_libs:
26
        sage.misc.cython.standard_libs.append('mpfi')
27
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage")
28
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
29
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx")
30
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py")
31
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage")
32
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage")
33
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage")
34
    # Matrix operations are loaded by polynomial operations.
35
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage")
36
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage")
37

  
38

  
39
print "Running SLZ..."
40
initialize_env()
41
from sageMpfr import *
42
from sageGMP  import *
43
import sys
44
from subprocess import call
45
#
46
## Main variables and parameters.
47
x            = var('x')
48
func(x)      = exp(x)
49
precision    = 53
50
emin         = -1022
51
emax         = 1023 
52
RRR          = RealField(precision)
53
degree       = 0
54
alpha        = 0
55
htrn         = 0
56
signAsString = ""
57
binade       = 0
58
debugMode    = False          
59
## Local functions
60
#
61
def usage():
62
    write = sys.stderr.write
63
    write("\nUsage:\n")
64
    write("  " + scriptName + " <degree> <alpha> <htrn> <intervalCenter>\n")
65
    write("               <numberOfNumbers> [debug]\n")
66
    write("\nArguments:\n")
67
    write("  degree          the degree of the polynomial (integer)\n")
68
    write("  alpha           alpha (integer)\n")
69
    write("  htrn            hardness-to-round - a number of bits (integer)\n")
70
    write("  binade          the binade we want to  explore\n")
71
    write("                  as a positive integral expression\n")
72
    write("  sign            the sign of the interval we want to expolore\n")
73
    write("                  either \"pos\" or \"neg\"\n")
74
    write("  debug           debug mode (\"debug\", in any case)\n\n")
75
    sys.exit(2)
76
# End usage.
77
#
78
argsCount = len(sys.argv)
79
scriptName = os.path.basename(__file__)
80
if argsCount < 6:
81
    usage()
82
for index in xrange(1,argsCount):
83
    if index == 1:
84
        degree = int(sys.argv[index])
85
    elif index == 2:
86
        alpha = int(sys.argv[index])
87
    elif index == 3:
88
        htrn = int(eval(sys.argv[index]))
89
    elif index == 4:
90
        binade = int(eval(sys.argv[index]))
91
    elif index == 5:
92
        signAsString = sys.argv[index]
93
    elif index == 6:
94
        debugMode = sys.argv[index].upper()
95
        debugMode = (debugMode == "DEBUG")
96
# Done with command line arguments collection.
97
#
98
## Debug printing
99
print "degree         :", degree
100
print "alpha          :", alpha
101
print "htrn           :", htrn
102
print "binade         :", binade
103
print "sign           :", signAsString
104
print "debug mode     :", debugMode
105
print
106
#
107
## Set the terminal window title.
108
terminalWindowTitle = ['stt', 
109
                        str(degree), 
110
                        str(alpha), 
111
                        str(htrn), 
112
                        str(binade),
113
                        signAsString]
114
call(terminalWindowTitle)
115
#
116
binadeUlp    = 2^(binade - precision + 1)
117
signAsString = signAsString.lower()
118
if signAsString == "pos": 
119
    lowerBound   = RRR(2^binade)
120
    upperBound   = RRR(2^(binade+1)) - binadeUlp
121
elif signAsString == "neg":
122
    lowerBound  = -RRR(2^(binade+1)) + binadeUlp
123
    upperBound  =  -RRR(2^binade)
124
    print lowerBound
125
    print upperBound
126
else:
127
    exceptionErrorMess = "\"" + signAsString + "\" is an invalid sign." \
128
    ". Aborting!\n"
129
    raise Exception(exceptionErrorMess)
130
srs_run_SLZ_v05(inputFunction=func, 
131
                     inputLowerBound         = lowerBound, 
132
                     inputUpperBound         = upperBound, 
133
                     alpha                   = alpha, 
134
                     degree                  = degree, 
135
                     precision               = precision, 
136
                     emin                    = emin, 
137
                     emax                    = emax, 
138
                     targetHardnessToRound   = htrn, 
139
                     debug                   = debugMode)
140
    
0 141

  
pobysoPythonSage/src/sageSLZ/sageSLZ.sage (revision 253)
487 487
        print "Less than 2 Coppersmith condition compliant vectors."
488 488
        print "Extra reduction starting..."
489 489
        reducedMatrix = reducedMatrixStep1.LLL(algorithm='fpLLL:wrapper')
490
        ### If uncommented, the following statement avoids performing
491
        #   an actual LLL reduction. This allows for demonstrating
492
        #   the behavior of our pseudo-reduction alone.
493
        #return ()
490 494
    else:
491
        print "First step of reduction affords enough vectors"
495
        print "First step of reduction afforded enough vectors"
492 496
        return ccReducedPolynomialsList
493 497
    #print ccReducedPolynomialsList
494 498
    ## Check again the Coppersmith condition for each row and build the reduced 
......
512 516
            #print l2Norm.n() , ">", nAtAlpha
513 517
            pass
514 518
    if len(ccReducedPolynomialsList) < 2: # Insufficient reduction.
515
        print "Less than 2 Coppersmith condition compliant vectors."
519
        print "Less than 2 Coppersmith condition compliant vectors after extra reduction."
516 520
        return ()
517 521
    else:
518 522
        return ccReducedPolynomialsList
......
2091 2095
#
2092 2096
def slz_pm1():
2093 2097
    """
2094
    Compute a uniform RV in {-1, 1}.
2098
    Compute a uniform RV in {-1, 1} (not zero).
2095 2099
    """
2096 2100
    ## function getrandbits(N) generates a long int with N random bits.
2097 2101
    return getrandbits(1) * 2-1
......
2314 2318
#
2315 2319
def slz_uniform(n):
2316 2320
    """
2317
    Compute a uniform RV in {-1, 1}.
2321
    Compute a uniform RV in [-2^(n-1), 2^(n-1)-1] (zero is included).
2318 2322
    """
2319 2323
    ## function getrandbits(n) generates a long int with n random bits.
2320 2324
    return getrandbits(n) - 2^(n-1)
pobysoPythonSage/src/sageSLZ/runSLZ-53.sage.py (revision 253)
1
# This file was *autogenerated* from the file ./runSLZ-53.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_1023 = Integer(1023); _sage_const_1022 = Integer(1022); _sage_const_10 = Integer(10); _sage_const_53 = Integer(53)#! /opt/sage/sage
4
# @file runSLZ-113.sage
5
#
6
# Run SLZ for p=113
7
#from scipy.constants.codata import precision
8
def initialize_env():
9
    """
10
    Load all necessary modules.
11
    """
12
    compiledSpyxDir = "/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx"
13
    if compiledSpyxDir not in sys.path:
14
        sys.path.append(compiledSpyxDir)
15
    if not 'mpfi' in sage.misc.cython.standard_libs:
16
        sage.misc.cython.standard_libs.append('mpfi')
17
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage")
18
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
19
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx")
20
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py")
21
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage")
22
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage")
23
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage")
24
    # Matrix operations are loaded by polynomial operations.
25
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage")
26
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage")
27

  
28

  
29
print "Running SLZ..."
30
initialize_env()
31
from sageMpfr import *
32
from sageGMP  import *
33
import sys
34
from subprocess import call
35
#
36
## Main variables and parameters.
37
x         = var('x')
38
__tmp__=var("x"); func = symbolic_expression(exp(x)).function(x)
39
precision = _sage_const_53 
40
emin      = -_sage_const_1022 
41
emax      = _sage_const_1023  
42
RRR = RealField(precision)
43
degree              = _sage_const_0 
44
alpha               = _sage_const_0 
45
htrn                = _sage_const_0 
46
intervalCenter      = _sage_const_0 
47
intervalRadius      = _sage_const_0 
48
debugMode           = False          
49
## Local functions
50
#
51
def usage():
52
    write = sys.stderr.write
53
    write("\nUsage:\n")
54
    write("  " + scriptName + " <degree> <alpha> <htrn> <intervalCenter>\n")
55
    write("               <numberOfNumbers> [debug]\n")
56
    write("\nArguments:\n")
57
    write("  degree          the degree of the polynomial (integer)\n")
58
    write("  alpha           alpha (integer)\n")
59
    write("  htrn            hardness-to-round - a number of bits (integer)\n")
60
    write("  intervalCenter  the interval center (a floating-point number)\n")
61
    write("  numberOfNumbers the number of floating-point numbers in the interval\n")
62
    write("                  as a positive integral expression\n")
63
    write("  debug           debug mode (\"debug\", in any case)\n\n")
64
    sys.exit(_sage_const_2 )
65
# End usage.
66
#
67
argsCount = len(sys.argv)
68
scriptName = os.path.basename(__file__)
69
if argsCount < _sage_const_5 :
70
    usage()
71
for index in xrange(_sage_const_1 ,argsCount):
72
    if index == _sage_const_1 :
73
        degree = int(sys.argv[index])
74
    elif index == _sage_const_2 :
75
        alpha = int(sys.argv[index])
76
    elif index == _sage_const_3 :
77
        htrn = int(eval(sys.argv[index]))
78
    elif index == _sage_const_4 :
79
        try:
80
            intervalCenter = QQ(sage_eval(sys.argv[index]))
81
        except:
82
            intervalCenter = RRR(sys.argv[index])
83
        intervalCenter = RRR(intervalCenter)
84
    elif index == _sage_const_5 :
85
        ## Can be read as rational number but must end up as an integer.
86
        numberOfNumbers = QQ(sage_eval(sys.argv[index]))
87
        if numberOfNumbers != numberOfNumbers.round():
88
            raise Exception("Invalid number of numbers: " + sys.argv[index] + ".")
89
        numberOfNumbers = numberOfNumbers.round()
90
        ## The number must be strictly positive.
91
        if numberOfNumbers <= _sage_const_0 :
92
            raise Exception("Invalid number of numbers: " + sys.argv[index] + ".")
93
    elif index == _sage_const_6 :
94
        debugMode = sys.argv[index].upper()
95
        debugMode = (debugMode == "DEBUG")
96
# Done with command line arguments collection.
97
#
98
## Debug printing
99
print "degree         :", degree
100
print "alpha          :", alpha
101
print "htrn           :", htrn
102
print "interval center:", intervalCenter.n(prec=_sage_const_10 ).str(truncate=False)
103
print "num of nums    :", RR(numberOfNumbers).log2().n(prec=_sage_const_10 ).str(truncate=False)
104
print "debug mode     :", debugMode
105
print
106
#
107
## Set the terminal window title.
108
terminalWindowTitle = ['stt', str(degree), str(alpha), str(htrn), 
109
                       intervalCenter.n(prec=_sage_const_10 ).str(truncate=False), 
110
                       RRR(numberOfNumbers).log2().n(prec=_sage_const_10 ).str(truncate=False)]
111
call(terminalWindowTitle)
112
#
113
intervalCenterBinade = slz_compute_binade(intervalCenter)
114
intervalRadius       = \
115
    _sage_const_2 **intervalCenterBinade * _sage_const_2 **(-precision + _sage_const_1 ) * numberOfNumbers / _sage_const_2 
116
srs_run_SLZ_v05(inputFunction=func, 
117
                inputLowerBound         = intervalCenter - intervalRadius, 
118
                inputUpperBound         = intervalCenter + intervalRadius, 
119
                alpha                   = alpha, 
120
                degree                  = degree, 
121
                precision               = precision, 
122
                emin                    = emin, 
123
                emax                    = emax, 
124
                targetHardnessToRound   = htrn, 
125
                debug                   = debugMode)
126
    
0 127

  
pobysoPythonSage/src/sageSLZ/argsForRunSLZ-53proj-01.sh (revision 253)
1
#! /bin/bash
2
#@file argsForRunSLZ-53proj-01.sh
3
#
4
# These data correspond to the small example of the 
5
# SLZ-implementation chapter.
6
#
7
DEGREE=2
8
ALPHA=2
9
HARDNESS_TO_ROUND="53+10"
10
INTERVAL_CENTER=3/2
11
NUM_OF_NUMBERS="2^9"
12
#
13
printf -- "$DEGREE \
14
$ALPHA \
15
$HARDNESS_TO_ROUND \
16
$INTERVAL_CENTER \
17
$NUM_OF_NUMBERS\n"
0 18

  
pobysoPythonSage/src/sageSLZ/argsForRunSLZ-53-01.sh (revision 253)
1 1
#! /bin/bash
2
#@file argsForRunSLZ-53-01proj.sh
3
DEGREE=3
4
ALPHA=3
5
HARDNESS_TO_ROUND="53+50"
6
INTERVAL_CENTER=3/4294967296
7
NUM_OF_NUMBERS="2^52-1"
2
#@file argsForRunSLZ-53-01.sh
8 3
#
4
# These data correspond to the small example of the 
5
# SLZ-implementation chapter.
6
#
7
DEGREE=2
8
ALPHA=2
9
HARDNESS_TO_ROUND="53+10"
10
INTERVAL_CENTER=3/2
11
NUM_OF_NUMBERS="2^9"
12
#
9 13
printf -- "$DEGREE \
10 14
$ALPHA \
11 15
$HARDNESS_TO_ROUND \
12 16

  

Formats disponibles : Unified diff