Révision 162

pobysoPythonSage/src/sollya_lib.sage (revision 162)
78 78
        sollya_lib_on = sollya.sollya_lib_on
79 79
        sollya_lib_parse_string = sollya.sollya_lib_parse_string
80 80
        sollya_lib_range = sollya.sollya_lib_range
81
        sollya_lib_range_from_bounds = sollya.sollya_lib_range_from_bounds
82
        sollya_lib_range_from_interval = \
83
            sollya.sollya_lib_range_from_interval
81 84
        sollya_lib_relative = sollya.sollya_lib_relative
82 85
        sollya_lib_remez = sollya.sollya_lib_remez
83 86
        sollya_lib_set_canonical = sollya.sollya_lib_set_canonical
......
104 107
# Set the argument type of several functions.
105 108
#
106 109
try:
110
    sollya_lib_autoprint.argtypes            = [c_ulong]
111
    sollya_lib_constant.argtypes             = [c_ulong]
112
    sollya_lib_constant.restype              = c_ulong
113
    sollya_lib_get_constant.argtypes         = [c_ulong, c_ulong]
107 114
    sollya_lib_get_constant_as_int.argtypes  = [POINTER(c_int), c_int]
108 115
    sollya_lib_get_function_arity.argtypes   = [POINTER(c_int), c_int]
109 116
    sollya_lib_get_head_function.argtypes    = [POINTER(c_int), c_int]
117
    sollya_lib_get_interval_from_range.argtypes = [c_ulong, c_ulong]
110 118
    sollya_lib_get_list_elements.argtypes    = [POINTER(POINTER(c_longlong)), \
111 119
                                                POINTER(c_int),\
112 120
                                                POINTER(c_int), c_int]
......
116 124
            POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int), \
117 125
            POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int), \
118 126
            POINTER(c_int), POINTER(c_int)]
127
    sollya_lib_guessdegree.argtypes          = [c_ulong, c_ulong, c_ulong, \
128
            c_ulong, c_ulong]
129
    sollya_lib_guessdegree.restype           = c_ulong        
119 130
    sollya_lib_name_free_variable.argtypes   = [POINTER(c_char)]
131
    sollya_lib_parse_string.restype          = c_long
132
    sollya_lib_range.argtypes                = [c_ulong, c_ulong]
133
    sollya_lib_range.restype                 = c_ulong
134
    sollya_lib_range_from_bounds.argtypes    = [c_ulong, c_ulong]
135
    sollya_lib_range_from_bounds.restype     = c_ulong
136
    sollya_lib_range_from_interval.argtypes  = [c_ulong]
137
    sollya_lib_range_from_interval.restype   = c_ulong
120 138
except :
121 139
    print "\nOne of the Python-Sollya argument type setting command has \
122 140
          failed.\n"
pobysoPythonSage/src/testPobyso.sage (revision 162)
76 76
    pointSo    = pobyso_constant_sa_so(RR("1.5"))
77 77
    intervalSo = pobyso_interval_to_range_sa_so(intervalSa)
78 78
    #
79
    def test(lowerBoundSa, upperBoundSa):
79
    def test(functionSo, degreeSo, pointSo, intervalSo):
80 80
        taylorformSo = pobyso_taylorform_so_so(functionSo,
81 81
                                               degreeSo,
82 82
                                               pointSo,
83 83
                                               intervalSo)
84
        sollya_lib_clear_obj(rangeSo)
84
        pobyso_clear_taylorform_sa_so(taylorformSo)
85 85
    #
86
    wrapped = test_pobyso_wrapper(test,lowerBoundSa, upperBoundSa)
86
    wrapped = test_pobyso_wrapper(test,
87
                                  functionSo, 
88
                                  degreeSo, 
89
                                  pointSo, 
90
                                  intervalSo)
87 91
    timing = min(timeit.repeat(wrapped, repeat=repeat, number=number))
88 92
    #
89
    precSo = pobyso_get_prec_so()
90
    #pobyso_autoprint(precSo)
91
    sollya_lib_clear_obj(precSo)
93
    sollya_lib_clear_obj(functionSo)
94
    sollya_lib_clear_obj(degreeSo)
95
    sollya_lib_clear_obj(pointSo)
96
    sollya_lib_clear_obj(intervalSo)
92 97
    print "\t...", functionName, "done."
93 98
    return timing
94 99
# End test_pobyso_bounds_to_range_sa_so
pobysoPythonSage/src/pobyso.py (revision 162)
99 99
    """
100 100
    Return a Sollya range from to 2 RealField Sage elements.
101 101
    The Sollya range element has a sufficient precision to hold all
102
    the digits of the Sage bounds.
102
    the digits of the widest of the Sage bounds.
103 103
    """
104 104
    # Sanity check.
105 105
    if rnLowerBoundSa > rnUpperBoundSa:
......
113 113
    else:
114 114
        maxPrecSa = precisionSa
115 115
    # From Sage to Sollya bounds.
116
    lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBoundSa),
116
#    lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBoundSa),
117
#                                       maxPrecSa)
118
    lowerBoundSo = pobyso_constant_sa_so(rnLowerBoundSa,
119
                                         maxPrecSa)
120
    upperBoundSo = pobyso_constant_sa_so(rnUpperBoundSa,
117 121
                                       maxPrecSa)
118
    upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBoundSa),
119
                                       maxPrecSa)
122
    
120 123
    # From Sollya bounds to range.
121 124
    rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo)
122 125
    # Back to original precision.
......
798 801
    else:
799 802
        degreeBoundSo = None
800 803
    guessedDegreeSa = pobyso_guess_degree_so_sa(functionSo,
801
                                              rangeSo,
802
                                              approxErrorSo,
803
                                              weightSo,
804
                                              degreeBoundSo)
804
                                                rangeSo,
805
                                                approxErrorSo,
806
                                                weightSo,
807
                                                degreeBoundSo)
805 808
    sollya_lib_clear_obj(functionSo)
806 809
    sollya_lib_clear_obj(rangeSo)
807 810
    sollya_lib_clear_obj(approxErrorSo)
......
831 834
    if neededPrecisionSa > currentPrecSa:
832 835
        currentPrecSo = pobyso_get_prec_so()
833 836
        pobyso_set_prec_sa_so(neededPrecisionSa)
837
    print "Guessing degree..."
834 838
    # weightSo and degreeBoundsSo are optional arguments.
839
    # As declared, sollya_lib_guessdegree must take 5 arguments.
835 840
    if weightSo is None:
836
        degreeRangeSo = sollya_lib_guessdegree(functionSo, rangeSo, errorSo, None)
841
        degreeRangeSo = sollya_lib_guessdegree(functionSo, rangeSo, errorSo, 
842
                                               0, 0, None)
837 843
    elif degreeBoundSo is None:
838 844
        degreeRangeSo =  sollya_lib_guessdegree(functionSo, rangeSo, \
839
                                                errorSo, weightSo, None)
845
                                                errorSo, weightSo, 0, None)
840 846
    else:
841 847
        degreeRangeSo =  sollya_lib_guessdegree(functionSo, rangeSo, errorSo, \
842 848
                                                weightSo, degreeBoundSo, None)
849
    print "Degree guess done."
843 850
    # Restore internal precision, if applicable.
844 851
    if neededPrecisionSa > currentPrecSa:
845 852
        pobyso_set_prec_so_so(currentPrecSo)
......
1117 1124
    return resultSo
1118 1125
# End pobyso_supnorm_so_so
1119 1126

  
1120
def pobyso_taylor_expansion_with_change_var_so_so(functionSo, degreeSo, \
1121
                                                  rangeSo, \
1122
                                                  errorTypeSo=None, \
1123
                                                  sollyaPrecSo=None):
1127
def pobyso_taylor_expansion_no_change_var_so_so(functionSo, 
1128
                                                degreeSo, 
1129
                                                rangeSo,
1130
                                                errorTypeSo=None, 
1131
                                                sollyaPrecSo=None):
1124 1132
    """
1125
    Compute the Taylor expansion with the variable change
1126
    x -> (x-intervalCenter) included.
1133
    Compute the Taylor expansion without the variable change
1134
    x -> x-intervalCenter.
1127 1135
    """
1128 1136
    # No global change of the working precision.
1129 1137
    if not sollyaPrecSo is None:
1130 1138
        initialPrecSo = sollya_lib_get_prec(None)
1131 1139
        sollya_lib_set_prec(sollyaPrecSo)
1132
    #
1133 1140
    # Error type stuff: default to absolute.
1134 1141
    if errorTypeSo is None:
1135 1142
        errorTypeIsNone = True
1136 1143
        errorTypeSo = sollya_lib_absolute(None)
1137 1144
    else:
1138 1145
        errorTypeIsNone = False
1139
    intervalCenterSo = sollya_lib_mid(rangeSo)
1140
    taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \
1141
                                         intervalCenterSo, \
1146
    intervalCenterSo = sollya_lib_mid(rangeSo, None)
1147
    taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo,
1148
                                         intervalCenterSo,
1142 1149
                                         rangeSo, errorTypeSo, None)
1143 1150
    # taylorFormListSaSo is a Python list of Sollya objects references that 
1144 1151
    # are copies of the elements of taylorFormSo.
1145 1152
    # pobyso_get_list_elements_so_so clears taylorFormSo.
1146
    (taylorFormListSo, numElements, isEndElliptic) = \
1153
    (taylorFormListSaSo, numElementsSa, isEndEllipticSa) = \
1147 1154
        pobyso_get_list_elements_so_so(taylorFormSo)
1148
    polySo = taylorFormListSo[0]
1149
    errorRangeSo = taylorFormListSo[2]
1155
    polySo = sollya_lib_copy_obj(taylorFormListSaSo[0])
1156
    #print "Num elements:", numElementsSa
1157
    sollya_lib_clear_obj(taylorFormSo)
1158
    #polySo = taylorFormListSaSo[0]
1159
    #errorRangeSo = sollya_lib_copy_obj(taylorFormListSaSo[2])
1160
    errorRangeSo = taylorFormListSaSo[2]
1161
    # No copy_obj needed here: a new object is created.
1150 1162
    maxErrorSo = sollya_lib_sup(errorRangeSo)
1151
    changeVarExpSo = sollya_lib_build_function_sub(\
1152
                       sollya_lib_build_function_free_variable(),\
1153
                       sollya_lib_copy_obj(intervalCenterSo))
1154
    polyVarChangedSo = sollya_lib_evaluate(polySo, changeVarExpSo) 
1155
    sollya_lib_clear_obj(changeVarExpSo)
1156 1163
    # If changed, reset the Sollya working precision.
1157 1164
    if not sollyaPrecSo is None:
1158 1165
        sollya_lib_set_prec(initialPrecSo)
1159 1166
        sollya_lib_clear_obj(initialPrecSo)
1160 1167
    if errorTypeIsNone:
1161 1168
        sollya_lib_clear_obj(errorTypeSo)
1162
    sollya_lib_clear_obj(taylorFormSo)
1163
    # Do not clear maxErrorSo.
1164
    return((polyVarChangedSo, intervalCenterSo, maxErrorSo))
1165
# end pobyso_taylor_expansion_with_change_var_so_so
1169
    pobyso_clear_taylorform_sa_so(taylorFormListSaSo)
1170
    return((polySo, intervalCenterSo, maxErrorSo))
1171
# end pobyso_taylor_expansion_no_change_var_so_so
1166 1172

  
1167
def pobyso_taylor_expansion_no_change_var_so_so(functionSo, degreeSo, rangeSo,
1168
                                                errorTypeSo=None, 
1169
                                                sollyaPrecSo=None):
1173
def pobyso_taylor_expansion_with_change_var_so_so(functionSo, degreeSo, \
1174
                                                  rangeSo, \
1175
                                                  errorTypeSo=None, \
1176
                                                  sollyaPrecSo=None):
1170 1177
    """
1171
    Compute the Taylor expansion without the variable change
1172
    x -> x-intervalCenter.
1178
    Compute the Taylor expansion with the variable change
1179
    x -> (x-intervalCenter) included.
1173 1180
    """
1174 1181
    # No global change of the working precision.
1175 1182
    if not sollyaPrecSo is None:
1176 1183
        initialPrecSo = sollya_lib_get_prec(None)
1177 1184
        sollya_lib_set_prec(sollyaPrecSo)
1185
    #
1178 1186
    # Error type stuff: default to absolute.
1179 1187
    if errorTypeSo is None:
1180 1188
        errorTypeIsNone = True
1181 1189
        errorTypeSo = sollya_lib_absolute(None)
1182 1190
    else:
1183 1191
        errorTypeIsNone = False
1184
    intervalCenterSo = sollya_lib_mid(rangeSo, None)
1185
    taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo,
1186
                                         intervalCenterSo,
1192
    intervalCenterSo = sollya_lib_mid(rangeSo)
1193
    taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \
1194
                                         intervalCenterSo, \
1187 1195
                                         rangeSo, errorTypeSo, None)
1188 1196
    # taylorFormListSaSo is a Python list of Sollya objects references that 
1189 1197
    # are copies of the elements of taylorFormSo.
1190 1198
    # pobyso_get_list_elements_so_so clears taylorFormSo.
1191
    (taylorFormListSaSo, numElementsSa, isEndEllipticSa) = \
1199
    (taylorFormListSo, numElements, isEndElliptic) = \
1192 1200
        pobyso_get_list_elements_so_so(taylorFormSo)
1193
    polySo = sollya_lib_copy_obj(taylorFormListSaSo[0])
1194
    #print "Num elements:", numElementsSa
1195
    sollya_lib_clear_obj(taylorFormSo)
1196
    #polySo = taylorFormListSaSo[0]
1197
    #errorRangeSo = sollya_lib_copy_obj(taylorFormListSaSo[2])
1198
    errorRangeSo = taylorFormListSaSo[2]
1199
    # No copy_obj needed here: a new object is created.
1201
    polySo = taylorFormListSo[0]
1202
    errorRangeSo = taylorFormListSo[2]
1200 1203
    maxErrorSo = sollya_lib_sup(errorRangeSo)
1204
    changeVarExpSo = sollya_lib_build_function_sub(\
1205
                       sollya_lib_build_function_free_variable(),\
1206
                       sollya_lib_copy_obj(intervalCenterSo))
1207
    polyVarChangedSo = sollya_lib_evaluate(polySo, changeVarExpSo) 
1208
    sollya_lib_clear_obj(changeVarExpSo)
1201 1209
    # If changed, reset the Sollya working precision.
1202 1210
    if not sollyaPrecSo is None:
1203 1211
        sollya_lib_set_prec(initialPrecSo)
1204 1212
        sollya_lib_clear_obj(initialPrecSo)
1205 1213
    if errorTypeIsNone:
1206 1214
        sollya_lib_clear_obj(errorTypeSo)
1207
    pobyso_clear_taylorform_sa_so(taylorFormListSaSo)
1208
    return((polySo, intervalCenterSo, maxErrorSo))
1209
# end pobyso_taylor_expansion_no_change_var_so_so
1215
    sollya_lib_clear_obj(taylorFormSo)
1216
    # Do not clear maxErrorSo.
1217
    return((polyVarChangedSo, intervalCenterSo, maxErrorSo))
1218
# end pobyso_taylor_expansion_with_change_var_so_so
1210 1219

  
1211 1220
def pobyso_taylor(function, degree, point):
1212 1221
    """ Legacy function. See pobysoTaylor_so_so. """
pobysoPythonSage/src/testSageMpfr.sage (revision 162)
10 10

  
11 11
"""
12 12
print "\ntestSageMpfr loading..."
13
load(str('/home/storres/recherche/arithmetique/pobysoPythonSage/src/ppsTestFunctions.sage'))
14
#
15

  
16
def test_cmp_rn_values(repeat=10, number=100):
17
    functionName =  inspect.stack()[0][3]
18
    print "Running", inspect.stack()[0][3], "..."
19
    rn1Sa    = RR(1)
20
    rn1bisSa = RR(1) 
21
    rn2Sa    = RR(2)
22
    #
23
    def test(rn1Sa, rn1bisSa, rn2Sa):
24
        if cmp_rn_values(rn1Sa, rn1bisSa) != 0:
25
            exit()
26
        if cmp_rn_values(rn1Sa, rn2Sa) >= 0:
27
            exit()
28
        if cmp_rn_values(rn2Sa, rn1Sa) <= 0:
29
            exit()
30
    wrapped = pps_test_wrapper(test, rn1Sa, rn1bisSa, rn2Sa)
31
    timing = min(timeit.repeat(wrapped, repeat=repeat, number=number))        
32
    print "\t...", functionName, "done."
33
    return timing
34
# End test_cmp_rn_values
35

  
36
def test_get_set_interval_value(repeat=10, number=100):
37
    functionName =  inspect.stack()[0][3]
38
    print "Running", inspect.stack()[0][3], "..."
39
    interval1Sa = RIF(1,2)
40
    interval2Sa = RIF(2,3)
41
    #
42
    def test(interval1Sa, interval2Sa):
43
        interval1SaValue = get_interval_value(interval1Sa)
44
        interval2SaValue = get_interval_value(interval2Sa)
45
        set_interval_value(interval2Sa, interval1SaValue)
46
        if cmp_interval_values(interval1Sa, interval2Sa) != 0:
47
            exit()
48
        set_interval_value(interval2Sa, interval2SaValue)
49
    #
50
    wrapped = pps_test_wrapper(test, interval1Sa, interval2Sa)
51
    timing = min(timeit.repeat(wrapped, repeat=repeat, number=number))        
52
    print "\t...", functionName, "done."
53
    return timing
54
# End test_get_set_interval_value
55

  
56
print "\ntestSageMpfr loading..."
13 57
attach(str('/home/storres/recherche/arithmetique/pobysoPythonSage/src/ppsTestFunctions.sage'))
14 58
#
15 59

  
16
def test_get_interval_value(repeat=10, number=100):
60
def test_get_set_rn_value(repeat=10, number=100):
17 61
    functionName =  inspect.stack()[0][3]
18 62
    print "Running", inspect.stack()[0][3], "..."
19
    intervalSa = RIF(1,2)
63
    rn1Sa = RR(1)
64
    rn2Sa = RR(2)
20 65
    #
21
    def test(intervalSa):
22
        intervalSaValue = get_interval_value(intervalSa)
66
    def test(rn1Sa, rn2Sa):
67
        rn1SaValue = get_rn_value(rn1Sa)
68
        rn2SaValue = get_rn_value(rn2Sa)
69
        set_rn_value(rn2Sa, rn1SaValue)
70
        if cmp_rn_values(rn1Sa, rn2Sa) != 0:
71
            exit()
72
        set_rn_value(rn2Sa, rn2SaValue)
23 73
    #
24
    wrapped = pps_test_wrapper(test,intervalSa)
74
    wrapped = pps_test_wrapper(test, rn1Sa, rn2Sa)
25 75
    timing = min(timeit.repeat(wrapped, repeat=repeat, number=number))        
26 76
    print "\t...", functionName, "done."
27 77
    return timing
28

  
78
# End test_get_set_rn_value
29 79
print "\t...testSageMpfr loaded"
pobysoPythonSage/src/sageMpfr.spyx (revision 162)
19 19
    cdef mp_rnd_t MPFR_RNDN "MPFR_RNDN"
20 20
    cdef mpfr_prec_t mpfr_min_prec(mpfr_t x)
21 21

  
22
cpdef unsigned long int deref(unsigned long int p, int index):
23
    return((<unsigned long int*>p)[index])
24

  
22 25
cpdef unsigned long int get_interval_value(RealIntervalFieldElement x):
23 26
    """
24 27
    Get the address of the value of a RealIntervalField Element. 
......
115 118

  
116 119
#
117 120

  
118
cpdef cmp_rn_value(RealNumber x, RealNumber y):
119
    """
120
    Compare two RN with the mpfr_cmp function
121
    """
122
    return(mpfr_cmp(x.value, y.value))
123
 
124
cpdef cmp_interval_value(RealIntervalFieldElement x, 
121
cpdef cmp_interval_values(RealIntervalFieldElement x, 
125 122
                         RealIntervalFieldElement y):
126 123
    """
127 124
    Compare two intervals with the mpfi_cmp function
128 125
    """
129 126
    return(mpfi_cmp(x.value, y.value))
130 127
 
128
cpdef cmp_rn_values(RealNumber x, RealNumber y):
129
    """
130
    Compare two RN with the mpfr_cmp function
131
    """
132
    return(mpfr_cmp(x.value, y.value))
133
 
131 134
# Do not use this function!
132 135
# It changes the precision of the instance behind the curtain, but precision is
133 136
# class attribute. If the precision is increased, memory space is wasted and

Formats disponibles : Unified diff