Révision 284

pobysoPythonSage/src/pobyso.py (revision 284)
36 36
from sage.symbolic.expression_conversions import polynomial
37 37
from sage.symbolic.expression_conversions import PolynomialConverter
38 38
"""
39
Create the equivalent to an enum for the Sollya function types.
39
Create the equivalent to an enum for the Sollya function types and other
40
common types (error types...).
40 41
"""
41 42
(SOLLYA_BASE_FUNC_ABS,
42
SOLLYA_BASE_FUNC_ACOS,
43
    SOLLYA_BASE_FUNC_ACOS,
43 44
    SOLLYA_BASE_FUNC_ACOSH,
44 45
    SOLLYA_BASE_FUNC_ADD,
45 46
    SOLLYA_BASE_FUNC_ASIN,
......
81 82
    SOLLYA_BASE_FUNC_SUB,
82 83
    SOLLYA_BASE_FUNC_TAN,
83 84
    SOLLYA_BASE_FUNC_TANH,
84
SOLLYA_BASE_FUNC_TRIPLEDOUBLE) = map(int,xrange(44))
85
    SOLLYA_BASE_FUNC_TRIPLEDOUBLE,
86
    SOLLYA_ABSOLUTE,
87
    SOLLYA_RELATIVE) = map(int,xrange(46))
88
sys.stderr.write("SOLLYA_RELATIVE = " + str(SOLLYA_RELATIVE) + "\n")
85 89
sys.stderr.write("Superficial pobyso check...\n")
86 90
#print "First constant - SOLLYA_BASE_FUNC_ABS: ", SOLLYA_BASE_FUNC_ABS
87 91
#print "Last constant  - SOLLYA_BASE_FUNC_TRIPLEDOUBLE: ", SOLLYA_BASE_FUNC_TRIPLEDOUBLE
......
376 380
    with the same precision as the source.
377 381
    """
378 382
    ## Precision stuff. If one wants to change precisions,
379
    #  everything takes place in Sage. That only makes
383
    #  everything takes place in Sage. This only makes
380 384
    #  sense if one wants to reduce the precision.
381 385
    # TODO: revisit precision stuff with new technique.
386
    # Check that rnArgSa is a realFiedl element.
387
    try:
388
        rnArgSa.ulp()
389
    except AttributeError:
390
        return pobyso_error_so()
391
    # If a different precision is wanted modify it.
382 392
    if not precisionSa is None:
383 393
        RRR = RealField(precisionSa)
384 394
        rnArgSa = RRR(rnArgSa)
......
759 769

  
760 770
def pobyso_get_constant_so_sa(rnArgSa, constSo):
761 771
    """
762
    Set the value of rnArgSo to the value of constSo in MPFR_RNDN mode.
772
    Set the value of rnArgSa to the value of constSo in MPFR_RNDN mode.
763 773
    rnArg must already exist and belong to some RealField.
764 774
    We assume that constSo points to a Sollya constant.
765 775
    """
......
2096 2106
    sollya_lib_set_prec(newPrecSo)
2097 2107
# End pobyso_set_prec_so_so.
2098 2108
#   
2099
def pobyso_supnorm_sa_sa(poly):
2109
def pobyso_supnorm_sa_sa(polySa, 
2110
                         funcSa, 
2111
                         intervalSa, 
2112
                         errorTypeSa=SOLLYA_ABSOLUTE, 
2113
                         accuracySa=RR(2^-40)):
2100 2114
    """
2101
    Computes the supremum norm from Sage input arguments and returns a
2102
    Sage floating-point number whose precision is set by the realFieldSa
2103
    argument.
2104
    TODO: complete this stub!
2115
    An supnorm call with Sage arguments.
2105 2116
    """
2106
    print("This function does nothing!")
2107
    return None
2117
    # Check that polySa is a univariate polynomial. We only check here at
2118
    # expression level, not at polynomial ring level
2119
    ## Make sure it is not a multivariate polynomial. The number of variables
2120
    #  can be zero in the case of a constant.
2121
    try:
2122
        if len(polySa.free_variables()) > 1 :
2123
            print "Invalid number of free variables in polySa:", polySa,
2124
            " -", polySa.free_variables()
2125
            return None
2126
    except AttributeError:
2127
        print "polySa is not a SymbolicExpression."
2128
        return None 
2129
    ## Make sure it is a polynomial.
2130
    if not polySa.is_polynomial(polySa.default_variable()):
2131
        print "polySa is not a polynomila expression."
2132
        return None
2133
    # Check that funcSa is a function.
2134
    if not \
2135
     sage.symbolic.callable.is_CallableSymbolicExpressionRing(parent(funcSa)):
2136
        return None
2137
    # Check that intervalSa is an interval.
2138
    try:
2139
        intervalSa.upper()
2140
    except AttributeError:
2141
        print "intervalSa is not an interval."
2142
        return None
2143
    # Convert the Sage polynomial into a Sollya polynomial.
2144
    polyAsStringSa = polySa._assume_str().replace('_SAGE_VAR_', '')
2145
    polySo = pobyso_parse_string_sa_so(polyAsStringSa)
2146
    if not pobyso_obj_is_function_so_sa(polySo):
2147
        sollya_lib_clear_obj(polySo)
2148
        print "The Sollya object created from the polynomial is not a function."
2149
        return None
2150
    #pobyso_autoprint(polySo)
2151
    # Convert the Sage function into a Sollya function.
2152
    funcAsStringSa = funcSa._assume_str().replace('_SAGE_VAR_', '')
2153
    funcSo = pobyso_parse_string_sa_so(funcAsStringSa)
2154
    if not pobyso_obj_is_function_so_sa(funcSo):
2155
        sollya_lib_clear_obj(polySo)
2156
        sollya_lib_clear_obj(funcSo)
2157
        print "The Sollya object created from the function is not a function."
2158
        return None
2159
    #pobyso_autoprint(funcSo)
2160
    # Convert the Sage interval into a Sollya range.
2161
    rangeSo = pobyso_interval_to_range_sa_so(intervalSa)
2162
    if not pobyso_is_range_so_sa(rangeSo):
2163
        sollya_lib_clear_obj(polySo)
2164
        sollya_lib_clear_obj(funcSo)
2165
        sollya_lib_clear_obj(rangeSo)
2166
        print "The Sollya object created from the interval is not a range."
2167
        return None
2168
    #pobyso_autoprint(rangeSo)
2169
    # Check the error type. We do not check the returned object since we
2170
    # trust our code and Sollya on this one.
2171
    if errorTypeSa != SOLLYA_ABSOLUTE and errorTypeSa != SOLLYA_RELATIVE:
2172
        sollya_lib_clear_obj(polySo)
2173
        sollya_lib_clear_obj(funcSo)
2174
        sollya_lib_clear_obj(rangeSo)
2175
        return None
2176
    if errorTypeSa == SOLLYA_ABSOLUTE:
2177
        errorTypeSo = pobyso_absolute_so_so()
2178
    else:
2179
        errorTypeSo = pobyso_relative_so_so()
2180
    #pobyso_autoprint(errorTypeSo)
2181
    # Check if accuracySa is an element of a RealField. If not, try to 
2182
    # convert it.
2183
    try:
2184
        accuracySa.ulp()
2185
    except AttributeError:
2186
        try:
2187
            accuracySa = RR(accuracySa)
2188
        except TypeError:
2189
            accuracySa = RR(str(accuracySa))
2190
    # Create the Sollya object
2191
    accuracySo = pobyso_constant_sa_so(accuracySa)
2192
    #pobyso_autoprint(accuracySo)
2193
    if pobyso_is_error_so_sa(accuracySo):
2194
        sollya_lib_clear_obj(polySo)
2195
        sollya_lib_clear_obj(funcSo)
2196
        sollya_lib_clear_obj(rangeSo)
2197
        sollya_lib_clear_obj(errorTypeSo)
2198
        sollya_lib_clear_obj(accuracySo)
2199
        return None
2200
    retValSo = sollya_lib_supnorm(polySo, 
2201
                                  funcSo, 
2202
                                  rangeSo, 
2203
                                  errorTypeSo, 
2204
                                  accuracySo, 
2205
                                  None)
2206
    sollya_lib_clear_obj(polySo)
2207
    sollya_lib_clear_obj(funcSo)
2208
    sollya_lib_clear_obj(rangeSo)
2209
    sollya_lib_clear_obj(errorTypeSo)
2210
    sollya_lib_clear_obj(accuracySo)
2211
    if pobyso_is_error_so_sa(retValSo):
2212
        sollya_lib_clear_obj(retValSo)
2213
        return None
2214
    #pobyso_autoprint(retValSo)
2215
    retValSa = pobyso_range_to_interval_so_sa(retValSo)
2216
    sollya_lib_clear_obj(retValSo)
2217
    return retValSa
2108 2218
# End pobyso_supnorm_sa_sa
2109 2219

  
2110 2220
def pobyso_supnorm_so_sa(polySo, funcSo, intervalSo, errorTypeSo = None,\

Formats disponibles : Unified diff