Révision 280

pobysoPythonSage/src/pobyso.py (revision 280)
142 142
    are cleared when the list is cleared).
143 143
    """
144 144
    if len(args) == 0:
145
        ## Called with an empty list produced "error".
146
        return sollya_lib_build_end_elliptic_list(None)
145
        ## When called with an empty list, sollya_lib_build_end_elliptic_list,
146
        #  produces "error".
147
        return sollya_lib_build_list(None)
147 148
    index = 0
148 149
    ## One can not append elements to an elliptic list, prepend only is 
149 150
    #  permitted.
......
207 208
    return(resultSo)
208 209
# End pobyso_chebyshevform_so_so.
209 210

  
211
def pobyso_clear_full_list_elements_sa_so(objectListSaSo):
212
    """
213
    Clear the elements of list created by the 
214
    pobyso_get_list_elements_so_so function.
215
    objectListSaSo is as follows:
216
    - objectListSaSo[0]: a list of Sollya objects;
217
    - objectListSaSo[1]: the number of elements of the previous list;
218
    - objectListSaSo[2]: an integer that if != 0 states that the list is 
219
                         end-elliptic
220
    The objects to clear are the elements of the objectListSaSo[0] list. 
221
    """
222
    for index in xrange(0, objectListSaSo[1]):
223
        sollya_lib_clear_obj(objectListSaSo[0][index])
224
# End pobyso_clear_full_list_elements_sa_so
225

  
226
def pobyso_clear_list_elements_sa_so(objectListSaSo):
227
    """
228
    Clear the elements of list of references to Sollya objects
229
    """
230
    for index in xrange(0, len(objectListSaSo)):
231
        sollya_lib_clear_obj(objectListSaSo[index])
232
# End pobyso_clear_list_elements_sa_so
233

  
210 234
def pobyso_clear_obj(objSo):
211 235
    """
212 236
    Free a Sollya object's memory.
......
217 241

  
218 242
def pobyso_clear_taylorform_sa_so(taylorFormSaSo):
219 243
    """
220
    This method is necessary to correctly clean up the memory from Taylor forms.
221
    These are made of a Sollya object, a Sollya object list, a Sollya object.
222
    For no clearly understood reason, sollya_lib_clear_object_list crashed 
223
    when applied to the object list.
224
    Here, we decompose it into Sage list of Sollya objects references and we
225
     clear them one at a time. 
244
    This method is rapper around pobyso_clear_list_elements_sa_so.
245
    It is a legacy method left here since it may be used in existing code 
246
    where Taylor forms are used as Sage lists obtained by converting
247
    Sollya Taylor forms (a list made of:
248
    - a polynomial;
249
    - a list of intervals enclosing the errors accumulated when computing
250
      the polynomial coefficients;
251
    - a bound on the approximation error between the polynomial and the 
252
      function.)
253
    A Taylor form directly obtained from pobyso_taylorform_so_so is cleared
254
    by sollya_lib_clear_obj. 
226 255
    """
227
    sollya_lib_clear_obj(taylorFormSaSo[0])
228
    (coefficientsErrorsListSaSo, numElementsSa, isEndEllipticSa) = \
229
        pobyso_get_list_elements_so_so(taylorFormSaSo[1])
230
    for element in coefficientsErrorsListSaSo:
231
        sollya_lib_clear_obj(element)
232
    sollya_lib_clear_obj(taylorFormSaSo[1])
233
    sollya_lib_clear_obj(taylorFormSaSo[2])
256
    pobyso_clear_list_elements_sa_so(taylorFormSaSo)
234 257
# End pobyso_clear_taylorform_sa_so 
235 258

  
236 259
def pobyso_cmp(rnArgSa, cteSo):
......
2074 2097
    maxErrorSo    = sollya_lib_sup(taylorFormListSaSo[2])
2075 2098
    minErrorSo    = sollya_lib_inf(taylorFormListSaSo[2])
2076 2099
    # List taylorFormListSaSo is not needed anymore.
2077
    pobyso_clear_taylorform_sa_so(taylorFormListSaSo)
2100
    pobyso_clear_list_elements_sa_so(taylorFormListSaSo)
2078 2101
    absMaxErrorSo = sollya_lib_abs(maxErrorSo)
2079 2102
    absMinErrorSo = sollya_lib_abs(minErrorSo)
2080 2103
    sollya_lib_clear_obj(maxErrorSo)
......
2146 2169
                       sollya_lib_copy_obj(intervalCenterSo))
2147 2170
    polyVarChangedSo = sollya_lib_evaluate(polySo, changeVarExpSo)
2148 2171
    # List taylorFormListSaSo is not needed anymore.
2149
    pobyso_clear_taylorform_sa_so(taylorFormListSaSo)
2172
    pobyso_clear_list_elements_sa_so(taylorFormListSaSo)
2150 2173
    sollya_lib_clear_obj(changeVarExpSo)
2151 2174
    # If changed, reset the Sollya working precision.
2152 2175
    if sollyaPrecChanged:
pobysoPythonSage/src/sollya_lib.sage (revision 280)
4 4
#
5 5
## Load the Sollya library.
6 6
try:
7
    #sollya=CDLL("/usr/local/lib/libsollya.so")
8 7
    sollya=CDLL("/usr/local/lib/libsollya.so")    
9 8
except :
10 9
    print "\nCould not find nor load the Sollya library.\n"
pobysoPythonSage/src/sageSLZ/runSLZ-113projWeak.sage.py (revision 280)
1
# This file was *autogenerated* from the file ./runSLZ-113projWeak.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.sage
5
#
6
#@par Changes from runSLZ-113.sage
7
# LLL reduction is not performed on the matrix itself but rather on the
8
# product of the matrix with a uniform random matrix.
9
# The reduced matrix obtained is discarded but the transformation matrix 
10
# obtained is used to multiply the original matrix in order to reduced it.
11
# If a sufficient level of reduction is obtained, we stop here. If not
12
# the product matrix obtained above is LLL reduced. But as it has been
13
# pre-reduced at the above step, reduction is supposed to be much faster.
14
#
15
# Both reductions combined should hopefully be faster than a straight single
16
# reduction.
17
#
18
# Run SLZ for p=113
19
#from scipy.constants.codata import precision
20
def initialize_env():
21
    """
22
    Load all necessary modules.
23
    """
24
    if version().split()[_sage_const_2 ].replace(',','') > '6.6':
25
        compiledSpyxDir = \
26
            "/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx"
27
        if compiledSpyxDir not in sys.path:
28
            sys.path.append(compiledSpyxDir)
29
    else:
30
        if not 'mpfi' in sage.misc.cython.standard_libs:
31
            sage.misc.cython.standard_libs.append('mpfi')
32
        load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
33
        load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx")
34
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage")
35
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
36
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx")
37
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py")
38
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage")
39
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage")
40
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage")
41
    # Matrix operations are loaded by polynomial operations.
42
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage")
43
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage")
44

  
45

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

  
pobysoPythonSage/src/sageSLZ/argsForRunSLZ-113best.sh (revision 280)
1
#! /bin/bash
2
#@file argsForRunSLZ-113proj.sh
3
DEGREE=45
4
ALPHA=10
5
HARDNESS_TO_ROUND="113*10"
6
INTERVAL_CENTER="3/8"
7
NUM_OF_NUMBERS="2^92"
8
#
9
printf -- "$DEGREE \
10
$ALPHA \
11
$HARDNESS_TO_ROUND \
12
$INTERVAL_CENTER \
13
$NUM_OF_NUMBERS\n"
0 14

  
pobysoPythonSage/src/sageSLZ/runSLZ-113proj-02.sage.py (revision 280)
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
    
0 150

  
pobysoPythonSage/src/testPobyso.sage (revision 280)
73 73
    return timing
74 74
# End test_pobyso_bounds_to_range_sa_so
75 75

  
76
def test_pobyso_clear_taylorform_sa_so(repeat=1000, number=10):
76
def test_pobyso_clear_full_list_elements_sa_so(repeat=1000, number=10):
77 77
    functionName =  inspect.stack()[0][3]
78 78
    print "Running", inspect.stack()[0][3], "..."
79 79
    intervalSa = RIF(1,2)
......
84 84
    intervalSo = pobyso_interval_to_range_sa_so(intervalSa)
85 85
    #
86 86
    def test(functionSo, degreeSo, pointSo, intervalSo):
87
        """
88
        We use Taylor models to generate the lists.
89
        """
87 90
        taylorformSo = pobyso_taylorform_so_so(functionSo,
88 91
                                               degreeSo,
89 92
                                               pointSo,
90 93
                                               intervalSo)
91
        pobyso_clear_taylorform_sa_so(taylorformSo)
94
        taylorformSaSo = pobyso_get_list_elements_so_so(taylorformSo)
95
        pobyso_clear_full_list_elements_sa_so(taylorformSaSo)
96
        sollya_lib_clear_obj(taylorformSo)
92 97
    #
93 98
    wrapped = test_pobyso_wrapper(test,
94 99
                                  functionSo, 
......
103 108
    sollya_lib_clear_obj(intervalSo)
104 109
    print "\t...", functionName, "done."
105 110
    return timing
106
# End test_pobyso_bounds_to_range_sa_so
111
# End test_pobyso_clear_full_list_elements_sa_so
107 112

  
108 113
def test_pobyso_float_poly_sa_so(repeat=100, number=10):
109 114
    functionName = inspect.stack()[0][3]

Formats disponibles : Unified diff