Statistiques
| Révision :

root / pobysoPythonSage / src / pobyso.py @ 153

Historique | Voir | Annoter | Télécharger (47,5 ko)

1 5 storres
"""
2 5 storres
Actual functions to use in Sage
3 5 storres
ST 2012-11-13
4 5 storres

5 5 storres
Command line syntax:
6 5 storres
  use from Sage (via the "load" or the "attach" commands)
7 5 storres

8 38 storres
pobyso functions come in five flavors:
9 57 storres
- the _so_so (arguments and returned objects are pointers to Sollya objects,
10 57 storres
  includes the void function and the no arguments function that return a
11 57 storres
  pointer to a Sollya object);
12 38 storres
- the _so_sa (argument are pointers to Sollya objects, returned objects are
13 57 storres
  Sage/Python objects or, more generally, information is transfered from the
14 57 storres
  Sollya world to Sage/Python world; e.g. functions without arguments that
15 57 storres
  return a Sage/Python object);
16 38 storres
- the _sa_so (arguments are Sage/Python objects, returned objects are
17 38 storres
  pointers to Sollya objects);
18 38 storres
- the sa_sa (arguments and returned objects are all Sage/Python objects);
19 51 storres
- a catch all flavor, without any suffix, (e. g. functions that have no argument
20 51 storres
  nor return value).
21 57 storres
This classification is not always very strict. Conversion functions from Sollya
22 57 storres
to Sage/Python are sometimes decorated with Sage/Python arguments to set
23 57 storres
the precision. These functions remain in the so_sa category.
24 5 storres
NOTES:
25 5 storres
Reported errors in Eclipse come from the calls to
26 5 storres
the Sollya library
27 5 storres

28 10 storres
ToDo (among other things):
29 10 storres
 -memory management.
30 5 storres
"""
31 5 storres
from ctypes import *
32 37 storres
import re
33 37 storres
from sage.symbolic.expression_conversions import polynomial
34 59 storres
from sage.symbolic.expression_conversions import PolynomialConverter
35 38 storres
"""
36 38 storres
Create the equivalent to an enum for the Sollya function types.
37 38 storres
"""
38 5 storres
(SOLLYA_BASE_FUNC_ABS,
39 5 storres
SOLLYA_BASE_FUNC_ACOS,
40 5 storres
    SOLLYA_BASE_FUNC_ACOSH,
41 5 storres
    SOLLYA_BASE_FUNC_ADD,
42 5 storres
    SOLLYA_BASE_FUNC_ASIN,
43 5 storres
    SOLLYA_BASE_FUNC_ASINH,
44 5 storres
    SOLLYA_BASE_FUNC_ATAN,
45 5 storres
    SOLLYA_BASE_FUNC_ATANH,
46 5 storres
    SOLLYA_BASE_FUNC_CEIL,
47 5 storres
    SOLLYA_BASE_FUNC_CONSTANT,
48 5 storres
    SOLLYA_BASE_FUNC_COS,
49 5 storres
    SOLLYA_BASE_FUNC_COSH,
50 5 storres
    SOLLYA_BASE_FUNC_DIV,
51 5 storres
    SOLLYA_BASE_FUNC_DOUBLE,
52 5 storres
    SOLLYA_BASE_FUNC_DOUBLEDOUBLE,
53 5 storres
    SOLLYA_BASE_FUNC_DOUBLEEXTENDED,
54 5 storres
    SOLLYA_BASE_FUNC_ERF,
55 5 storres
    SOLLYA_BASE_FUNC_ERFC,
56 5 storres
    SOLLYA_BASE_FUNC_EXP,
57 5 storres
    SOLLYA_BASE_FUNC_EXP_M1,
58 5 storres
    SOLLYA_BASE_FUNC_FLOOR,
59 5 storres
    SOLLYA_BASE_FUNC_FREE_VARIABLE,
60 5 storres
    SOLLYA_BASE_FUNC_HALFPRECISION,
61 5 storres
    SOLLYA_BASE_FUNC_LIBRARYCONSTANT,
62 5 storres
    SOLLYA_BASE_FUNC_LIBRARYFUNCTION,
63 5 storres
    SOLLYA_BASE_FUNC_LOG,
64 5 storres
    SOLLYA_BASE_FUNC_LOG_10,
65 5 storres
    SOLLYA_BASE_FUNC_LOG_1P,
66 5 storres
    SOLLYA_BASE_FUNC_LOG_2,
67 5 storres
    SOLLYA_BASE_FUNC_MUL,
68 5 storres
    SOLLYA_BASE_FUNC_NEARESTINT,
69 5 storres
    SOLLYA_BASE_FUNC_NEG,
70 5 storres
    SOLLYA_BASE_FUNC_PI,
71 5 storres
    SOLLYA_BASE_FUNC_POW,
72 5 storres
    SOLLYA_BASE_FUNC_PROCEDUREFUNCTION,
73 5 storres
    SOLLYA_BASE_FUNC_QUAD,
74 5 storres
    SOLLYA_BASE_FUNC_SIN,
75 5 storres
    SOLLYA_BASE_FUNC_SINGLE,
76 5 storres
    SOLLYA_BASE_FUNC_SINH,
77 5 storres
    SOLLYA_BASE_FUNC_SQRT,
78 5 storres
    SOLLYA_BASE_FUNC_SUB,
79 5 storres
    SOLLYA_BASE_FUNC_TAN,
80 5 storres
    SOLLYA_BASE_FUNC_TANH,
81 5 storres
SOLLYA_BASE_FUNC_TRIPLEDOUBLE) = map(int,xrange(44))
82 56 storres
print "\nSuperficial pobyso check..."
83 5 storres
print "First constant - SOLLYA_BASE_FUNC_ABS: ", SOLLYA_BASE_FUNC_ABS
84 5 storres
print "Last constant  - SOLLYA_BASE_FUNC_TRIPLEDOUBLE: ", SOLLYA_BASE_FUNC_TRIPLEDOUBLE
85 5 storres
86 5 storres
pobyso_max_arity = 9
87 5 storres
88 85 storres
def pobyso_absolute_so_so():
89 85 storres
    return(sollya_lib_absolute(None))
90 85 storres
91 5 storres
def pobyso_autoprint(arg):
92 5 storres
    sollya_lib_autoprint(arg,None)
93 5 storres
94 38 storres
def pobyso_autoprint_so_so(arg):
95 38 storres
    sollya_lib_autoprint(arg,None)
96 54 storres
97 84 storres
def pobyso_bounds_to_range_sa_so(rnLowerBoundSa, rnUpperBoundSa, \
98 84 storres
                                 precisionSa=None):
99 84 storres
    """
100 84 storres
    Return a Sollya range from to 2 RealField Sage elements.
101 84 storres
    The Sollya range element has a sufficient precision to hold all
102 84 storres
    the digits of the Sage bounds.
103 84 storres
    """
104 84 storres
    # Sanity check.
105 84 storres
    if rnLowerBoundSa > rnUpperBoundSa:
106 84 storres
        return None
107 115 storres
    # Precision stuff.
108 85 storres
    if precisionSa is None:
109 84 storres
        # Check for the largest precision.
110 84 storres
        lbPrecSa = rnLowerBoundSa.parent().precision()
111 84 storres
        ubPrecSa = rnLowerBoundSa.parent().precision()
112 84 storres
        maxPrecSa = max(lbPrecSa, ubPrecSa)
113 84 storres
    else:
114 84 storres
        maxPrecSa = precisionSa
115 84 storres
    sollyaCurrentPrecSo = pobyso_get_prec_so()
116 84 storres
    sollyaCurrentPrecSa = pobyso_constant_from_int_so_sa(sollyaCurrentPrecSo)
117 84 storres
    # Change the current Sollya precision only if necessary.
118 84 storres
    if maxPrecSa > sollyaCurrentPrecSa:
119 84 storres
        pobyso_set_prec_sa_so(maxPrecSa)
120 115 storres
    # From Sage to Sollya bounds.
121 84 storres
    lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBoundSa))
122 84 storres
    upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBoundSa))
123 115 storres
    # From Sollya bounds to range.
124 84 storres
    rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo)
125 84 storres
    # Back to original precision.
126 84 storres
    if maxPrecSa > sollyaCurrentPrecSa:
127 84 storres
        sollya_lib_set_prec(sollyaCurrentPrecSo)
128 84 storres
    # Clean up
129 84 storres
    sollya_lib_clear_obj(sollyaCurrentPrecSo)
130 84 storres
    sollya_lib_clear_obj(lowerBoundSo)
131 84 storres
    sollya_lib_clear_obj(upperBoundSo)
132 84 storres
    return(rangeSo)
133 84 storres
# End pobyso_bounds_to_range_sa_so
134 84 storres
135 54 storres
def pobyso_build_function_sub_so_so(exp1So, exp2So):
136 54 storres
    return(sollya_lib_build_function_sub(exp1So, exp2So))
137 54 storres
138 85 storres
def pobyso_change_var_in_function_so_so(funcSo, chvarExpSo):
139 54 storres
    """
140 85 storres
    Variable change in a function.
141 85 storres
    """
142 85 storres
    return(sollya_lib_evaluate(funcSo,chvarExpSo))
143 85 storres
# End pobyso_change_var_in_function_so_so
144 85 storres
145 85 storres
def pobyso_chebyshevform_so_so(functionSo, degreeSo, intervalSo):
146 85 storres
    resultSo = sollya_lib_chebyshevform(functionSo, degreeSo, intervalSo)
147 85 storres
    return(resultSo)
148 85 storres
# End pobyso_chebyshevform_so_so.
149 85 storres
150 117 storres
def pobyso_clear_taylorform_sa_so(taylorFormSaSo):
151 117 storres
    """
152 117 storres
    This method is necessary to correctly clean up the memory from Taylor forms.
153 117 storres
    These are made of a Sollya object, a Sollya object list, a Sollya object.
154 117 storres
    For no clearly understood reason, sollya_lib_clear_object_list crashed
155 117 storres
    when applied to the object list.
156 117 storres
    Here, we decompose it into Sage list of Sollya objects references and we
157 117 storres
     clear them one by one.
158 117 storres
    """
159 117 storres
    sollya_lib_clear_obj(taylorFormSaSo[0])
160 117 storres
    (coefficientsErrorsListSaSo, numElementsSa, isEndEllipticSa) = \
161 117 storres
        pobyso_get_list_elements_so_so(taylorFormSaSo[1])
162 117 storres
    for element in coefficientsErrorsListSaSo:
163 117 storres
        sollya_lib_clear_obj(element)
164 117 storres
    sollya_lib_clear_obj(taylorFormSaSo[1])
165 117 storres
    sollya_lib_clear_obj(taylorFormSaSo[2])
166 117 storres
# End pobyso_clear_taylorform_sa_so
167 117 storres
168 85 storres
def pobyso_cmp(rnArgSa, cteSo):
169 85 storres
    """
170 54 storres
    Compare the MPFR value a RealNumber with that of a Sollya constant.
171 54 storres

172 54 storres
    Get the value of the Sollya constant into a RealNumber and compare
173 54 storres
    using MPFR. Could be optimized by working directly with a mpfr_t
174 54 storres
    for the intermediate number.
175 54 storres
    """
176 115 storres
    # Get the precision of the Sollya constant to build a Sage RealNumber
177 115 storres
    # with enough precision.to hold it.
178 5 storres
    precisionOfCte = c_int(0)
179 5 storres
    # From the Sollya constant, create a local Sage RealNumber.
180 85 storres
    sollya_lib_get_prec_of_constant(precisionOfCte, cteSo)
181 5 storres
    #print "Precision of constant: ", precisionOfCte
182 5 storres
    RRRR = RealField(precisionOfCte.value)
183 85 storres
    rnLocalSa = RRRR(0)
184 85 storres
    sollya_lib_get_constant(get_rn_value(rnLocalSa), cteSo)
185 115 storres
    #
186 115 storres
    ## Compare the Sage RealNumber version of the Sollya constant with rnArg.
187 85 storres
    return(cmp_rn_value(rnArgSa, rnLocal))
188 83 storres
# End pobyso_smp
189 5 storres
190 54 storres
def pobyso_compute_pos_function_abs_val_bounds_sa_sa(funcSa, lowerBoundSa, \
191 54 storres
                                                     upperBoundSa):
192 54 storres
    """
193 85 storres
    TODO: completely rework and test.
194 54 storres
    """
195 85 storres
    pobyso = pobyso_name_free_variable_sa_so(funcSa.variables()[0])
196 54 storres
    funcSo = pobyso_parse_string(funcSa._assume_str())
197 54 storres
    rangeSo = pobyso_range_sa_so(lowerBoundSa, upperBoundSa)
198 54 storres
    infnormSo = pobyso_infnorm_so_so(funcSo,rangeSo)
199 83 storres
    # Sollya return the infnorm as an interval.
200 54 storres
    fMaxSa = pobyso_get_interval_from_range_so_sa(infnormSo)
201 54 storres
    # Get the top bound and compute the binade top limit.
202 54 storres
    fMaxUpperBoundSa = fMaxSa.upper()
203 54 storres
    binadeTopLimitSa = 2**ceil(fMaxUpperBoundSa.log2())
204 54 storres
    # Put up together the function to use to compute the lower bound.
205 54 storres
    funcAuxSo = pobyso_parse_string(str(binadeTopLimitSa) +  \
206 54 storres
                                    '-(' + f._assume_str() + ')')
207 54 storres
    pobyso_autoprint(funcAuxSo)
208 83 storres
    # Clear the Sollya range before a new call to infnorm and issue the call.
209 54 storres
    sollya_lib_clear_obj(infnormSo)
210 54 storres
    infnormSo = pobyso_infnorm_so_so(funcAuxSo,rangeSo)
211 54 storres
    fMinSa = pobyso_get_interval_from_range_so_sa(infnormSo)
212 54 storres
    sollya_lib_clear_obj(infnormSo)
213 85 storres
    fMinLowerBoundSa = binadeTopLimitSa - fMinSa.lower()
214 54 storres
    # Compute the maximum of the precisions of the different bounds.
215 54 storres
    maxPrecSa = max([fMinLowerBoundSa.parent().precision(), \
216 54 storres
                     fMaxUpperBoundSa.parent().precision()])
217 54 storres
    # Create a RealIntervalField and create an interval with the "good" bounds.
218 54 storres
    RRRI = RealIntervalField(maxPrecSa)
219 54 storres
    imageIntervalSa = RRRI(fMinLowerBoundSa, fMaxUpperBoundSa)
220 83 storres
    # Free the unneeded Sollya objects
221 54 storres
    sollya_lib_clear_obj(funcSo)
222 54 storres
    sollya_lib_clear_obj(funcAuxSo)
223 54 storres
    sollya_lib_clear_obj(rangeSo)
224 54 storres
    return(imageIntervalSa)
225 83 storres
# End pobyso_compute_pos_function_abs_val_bounds_sa_sa
226 54 storres
227 5 storres
def pobyso_constant(rnArg):
228 38 storres
    """ Legacy function. See pobyso_constant_sa_so. """
229 38 storres
    return(pobyso_constant_sa_so(rnArg))
230 5 storres
231 84 storres
def pobyso_constant_sa_so(rnArgSa, precisionSa=None):
232 52 storres
    """
233 115 storres
    Create a Sollya constant from a Sage RealNumber.
234 52 storres
    """
235 84 storres
    # Precision stuff
236 84 storres
    if precisionSa is None:
237 84 storres
        precisionSa = rnArgSa.parent().precision()
238 85 storres
    currentSollyaPrecisionSo = sollya_lib_get_prec()
239 85 storres
    currentSollyaPrecisionSa = \
240 85 storres
        pobyso_constant_from_int(currentSollyaPrecisionSo)
241 115 storres
    # Sollya constant creation takes place here.
242 84 storres
    if precisionSa > currentSollyaPrecisionSa:
243 84 storres
        pobyso_set_prec_sa_so(precisionSa)
244 84 storres
        constantSo = sollya_lib_constant(get_rn_value(rnArgSa))
245 84 storres
        pobyso_set_prec_sa_so(currentSollyaPrecision)
246 84 storres
    else:
247 84 storres
        constantSo = sollya_lib_constant(get_rn_value(rnArgSa))
248 85 storres
    sollya_lib_clear_obj(currentSollyaPrecisionSo)
249 84 storres
    return(constantSo)
250 115 storres
# End pobyso_constant_sa_so
251 115 storres
252 55 storres
def pobyso_constant_0_sa_so():
253 115 storres
    """
254 115 storres
    Obvious.
255 115 storres
    """
256 55 storres
    return(pobyso_constant_from_int_sa_so(0))
257 55 storres
258 5 storres
def pobyso_constant_1():
259 115 storres
    """
260 115 storres
    Obvious.
261 115 storres
    Legacy function. See pobyso_constant_so_so.
262 115 storres
    """
263 52 storres
    return(pobyso_constant_1_sa_so())
264 5 storres
265 52 storres
def pobyso_constant_1_sa_so():
266 115 storres
    """
267 115 storres
    Obvious.
268 115 storres
    """
269 38 storres
    return(pobyso_constant_from_int_sa_so(1))
270 38 storres
271 5 storres
def pobyso_constant_from_int(anInt):
272 38 storres
    """ Legacy function. See pobyso_constant_from_int_sa_so. """
273 38 storres
    return(pobyso_constant_from_int_sa_so(anInt))
274 38 storres
275 38 storres
def pobyso_constant_from_int_sa_so(anInt):
276 115 storres
    """
277 115 storres
    Get a Sollya constant from a Sage int.
278 115 storres
    """
279 5 storres
    return(sollya_lib_constant_from_int(int(anInt)))
280 5 storres
281 84 storres
def pobyso_constant_from_int_so_sa(constSo):
282 84 storres
    """
283 117 storres
    Get a Sage int from a Sollya int constant.
284 115 storres
    Usefull for precision or powers in polynomials.
285 84 storres
    """
286 84 storres
    constSa = c_int(0)
287 84 storres
    sollya_lib_get_constant_as_int(byref(constSa), constSo)
288 84 storres
    return(constSa.value)
289 84 storres
# End pobyso_constant_from_int_so_sa
290 84 storres
291 5 storres
def pobyso_function_type_as_string(funcType):
292 38 storres
    """ Legacy function. See pobyso_function_type_as_string_so_sa. """
293 38 storres
    return(pobyso_function_type_as_string_so_sa(funcType))
294 38 storres
295 38 storres
def pobyso_function_type_as_string_so_sa(funcType):
296 38 storres
    """
297 38 storres
    Numeric Sollya function codes -> Sage mathematical function names.
298 38 storres
    Notice that pow -> ^ (a la Sage, not a la Python).
299 38 storres
    """
300 5 storres
    if funcType == SOLLYA_BASE_FUNC_ABS:
301 5 storres
        return "abs"
302 5 storres
    elif funcType == SOLLYA_BASE_FUNC_ACOS:
303 5 storres
        return "arccos"
304 5 storres
    elif funcType == SOLLYA_BASE_FUNC_ACOSH:
305 5 storres
        return "arccosh"
306 5 storres
    elif funcType == SOLLYA_BASE_FUNC_ADD:
307 5 storres
        return "+"
308 5 storres
    elif funcType == SOLLYA_BASE_FUNC_ASIN:
309 5 storres
        return "arcsin"
310 5 storres
    elif funcType == SOLLYA_BASE_FUNC_ASINH:
311 5 storres
        return "arcsinh"
312 5 storres
    elif funcType == SOLLYA_BASE_FUNC_ATAN:
313 5 storres
        return "arctan"
314 5 storres
    elif funcType == SOLLYA_BASE_FUNC_ATANH:
315 5 storres
        return "arctanh"
316 5 storres
    elif funcType == SOLLYA_BASE_FUNC_CEIL:
317 5 storres
        return "ceil"
318 5 storres
    elif funcType == SOLLYA_BASE_FUNC_CONSTANT:
319 5 storres
        return "cte"
320 5 storres
    elif funcType == SOLLYA_BASE_FUNC_COS:
321 5 storres
        return "cos"
322 5 storres
    elif funcType == SOLLYA_BASE_FUNC_COSH:
323 5 storres
        return "cosh"
324 5 storres
    elif funcType == SOLLYA_BASE_FUNC_DIV:
325 5 storres
        return "/"
326 5 storres
    elif funcType == SOLLYA_BASE_FUNC_DOUBLE:
327 5 storres
        return "double"
328 5 storres
    elif funcType == SOLLYA_BASE_FUNC_DOUBLEDOUBLE:
329 5 storres
        return "doubleDouble"
330 5 storres
    elif funcType == SOLLYA_BASE_FUNC_DOUBLEEXTENDED:
331 5 storres
        return "doubleDxtended"
332 5 storres
    elif funcType == SOLLYA_BASE_FUNC_ERF:
333 5 storres
        return "erf"
334 5 storres
    elif funcType == SOLLYA_BASE_FUNC_ERFC:
335 5 storres
        return "erfc"
336 5 storres
    elif funcType == SOLLYA_BASE_FUNC_EXP:
337 5 storres
        return "exp"
338 5 storres
    elif funcType == SOLLYA_BASE_FUNC_EXP_M1:
339 5 storres
        return "expm1"
340 5 storres
    elif funcType == SOLLYA_BASE_FUNC_FLOOR:
341 5 storres
        return "floor"
342 5 storres
    elif funcType == SOLLYA_BASE_FUNC_FREE_VARIABLE:
343 5 storres
        return "freeVariable"
344 5 storres
    elif funcType == SOLLYA_BASE_FUNC_HALFPRECISION:
345 5 storres
        return "halfPrecision"
346 5 storres
    elif funcType == SOLLYA_BASE_FUNC_LIBRARYCONSTANT:
347 5 storres
        return "libraryConstant"
348 5 storres
    elif funcType == SOLLYA_BASE_FUNC_LIBRARYFUNCTION:
349 5 storres
        return "libraryFunction"
350 5 storres
    elif funcType == SOLLYA_BASE_FUNC_LOG:
351 5 storres
        return "log"
352 5 storres
    elif funcType == SOLLYA_BASE_FUNC_LOG_10:
353 5 storres
        return "log10"
354 5 storres
    elif funcType == SOLLYA_BASE_FUNC_LOG_1P:
355 5 storres
        return "log1p"
356 5 storres
    elif funcType == SOLLYA_BASE_FUNC_LOG_2:
357 5 storres
        return "log2"
358 5 storres
    elif funcType == SOLLYA_BASE_FUNC_MUL:
359 5 storres
        return "*"
360 5 storres
    elif funcType == SOLLYA_BASE_FUNC_NEARESTINT:
361 5 storres
        return "round"
362 5 storres
    elif funcType == SOLLYA_BASE_FUNC_NEG:
363 5 storres
        return "__neg__"
364 5 storres
    elif funcType == SOLLYA_BASE_FUNC_PI:
365 5 storres
        return "pi"
366 5 storres
    elif funcType == SOLLYA_BASE_FUNC_POW:
367 5 storres
        return "^"
368 5 storres
    elif funcType == SOLLYA_BASE_FUNC_PROCEDUREFUNCTION:
369 5 storres
        return "procedureFunction"
370 5 storres
    elif funcType == SOLLYA_BASE_FUNC_QUAD:
371 5 storres
        return "quad"
372 5 storres
    elif funcType == SOLLYA_BASE_FUNC_SIN:
373 5 storres
        return "sin"
374 5 storres
    elif funcType == SOLLYA_BASE_FUNC_SINGLE:
375 5 storres
        return "single"
376 5 storres
    elif funcType == SOLLYA_BASE_FUNC_SINH:
377 5 storres
        return "sinh"
378 5 storres
    elif funcType == SOLLYA_BASE_FUNC_SQRT:
379 5 storres
        return "sqrt"
380 5 storres
    elif funcType == SOLLYA_BASE_FUNC_SUB:
381 5 storres
        return "-"
382 5 storres
    elif funcType == SOLLYA_BASE_FUNC_TAN:
383 5 storres
        return "tan"
384 5 storres
    elif funcType == SOLLYA_BASE_FUNC_TANH:
385 5 storres
        return "tanh"
386 5 storres
    elif funcType == SOLLYA_BASE_FUNC_TRIPLEDOUBLE:
387 5 storres
        return "tripleDouble"
388 5 storres
    else:
389 5 storres
        return None
390 5 storres
391 85 storres
def pobyso_get_constant(rnArgSa, constSo):
392 38 storres
    """ Legacy function. See pobyso_get_constant_so_sa. """
393 85 storres
    return(pobyso_get_constant_so_sa(rnArgSa, constSo))
394 38 storres
395 84 storres
def pobyso_get_constant_so_sa(rnArgSa, constSo):
396 52 storres
    """
397 85 storres
    Set the value of rnArgSo to the value of constSo in MPFR_RNDN mode.
398 52 storres
    rnArg must already exist and belong to some RealField.
399 85 storres
    We assume that constSo points to a Sollya constant.
400 52 storres
    """
401 84 storres
    return(sollya_lib_get_constant(get_rn_value(rnArgSa), constSo))
402 5 storres
403 57 storres
def pobyso_get_constant_as_rn(ctExpSo):
404 83 storres
    """
405 83 storres
    Legacy function. See pobyso_get_constant_as_rn_so_sa.
406 83 storres
    """
407 57 storres
    return(pobyso_get_constant_as_rn_so_sa(ctExpSo))
408 38 storres
409 56 storres
def pobyso_get_constant_as_rn_so_sa(constExpSo):
410 83 storres
    """
411 83 storres
    Get a Sollya constant as a Sage "real number".
412 83 storres
    The precision of the floating-point number returned is that of the Sollya
413 83 storres
    constant.
414 83 storres
    """
415 57 storres
    precisionSa  = pobyso_get_prec_of_constant_so_sa(constExpSo)
416 56 storres
    RRRR = RealField(precisionSa)
417 56 storres
    rnSa = RRRR(0)
418 56 storres
    sollya_lib_get_constant(get_rn_value(rnSa), constExpSo)
419 56 storres
    return(rnSa)
420 83 storres
# End pobyso_get_constant_as_rn_so_sa
421 38 storres
422 38 storres
def pobyso_get_constant_as_rn_with_rf(ctExp, realField):
423 83 storres
    """
424 83 storres
    Legacy function. See pobyso_get_constant_as_rn_with_rf_so_sa.
425 83 storres
    """
426 38 storres
    return(pobyso_get_constant_as_rn_with_rf_so_sa(ctExp, realField))
427 5 storres
428 56 storres
def pobyso_get_constant_as_rn_with_rf_so_sa(ctExpSo, realFieldSa = None):
429 83 storres
    """
430 83 storres
    Get a Sollya constant as a Sage "real number".
431 83 storres
    If no real field is specified, the precision of the floating-point number
432 85 storres
    returned is that of the Sollya constant.
433 83 storres
    Otherwise is is that of the real field. Hence rounding may happen.
434 83 storres
    """
435 56 storres
    if realFieldSa is None:
436 85 storres
        sollyaPrecSa = pobyso_get_prec_of_constant_so_sa(ctExpSo)
437 56 storres
        realFieldSa = RealField(sollyaPrecSa)
438 56 storres
    rnSa = realFieldSa(0)
439 56 storres
    sollya_lib_get_constant(get_rn_value(rnSa), ctExpSo)
440 56 storres
    return(rnSa)
441 83 storres
# End pobyso_get_constant_as_rn_with_rf_so_sa
442 38 storres
443 5 storres
def pobyso_get_free_variable_name():
444 83 storres
    """
445 83 storres
    Legacy function. See pobyso_get_free_variable_name_so_sa.
446 83 storres
    """
447 38 storres
    return(pobyso_get_free_variable_name_so_sa())
448 38 storres
449 38 storres
def pobyso_get_free_variable_name_so_sa():
450 5 storres
    return(sollya_lib_get_free_variable_name())
451 5 storres
452 38 storres
def pobyso_get_function_arity(expressionSo):
453 83 storres
    """
454 83 storres
    Legacy function. See pobyso_get_function_arity_so_sa.
455 83 storres
    """
456 38 storres
    return(pobyso_get_function_arity_so_sa(expressionSo))
457 38 storres
458 38 storres
def pobyso_get_function_arity_so_sa(expressionSo):
459 5 storres
    arity = c_int(0)
460 38 storres
    sollya_lib_get_function_arity(byref(arity),expressionSo)
461 5 storres
    return(int(arity.value))
462 5 storres
463 38 storres
def pobyso_get_head_function(expressionSo):
464 83 storres
    """
465 83 storres
    Legacy function. See pobyso_get_head_function_so_sa.
466 83 storres
    """
467 38 storres
    return(pobyso_get_head_function_so_sa(expressionSo))
468 38 storres
469 38 storres
def pobyso_get_head_function_so_sa(expressionSo):
470 5 storres
    functionType = c_int(0)
471 38 storres
    sollya_lib_get_head_function(byref(functionType), expressionSo, None)
472 5 storres
    return(int(functionType.value))
473 5 storres
474 56 storres
def pobyso_get_interval_from_range_so_sa(soRange, realIntervalFieldSa = None ):
475 53 storres
    """
476 53 storres
    Return the Sage interval corresponding to the Sollya range argument.
477 83 storres
    If no reaIntervalField is passed as an argument, the interval bounds are not
478 56 storres
    rounded: they are elements of RealIntervalField of the "right" precision
479 56 storres
    to hold all the digits.
480 53 storres
    """
481 53 storres
    prec = c_int(0)
482 56 storres
    if realIntervalFieldSa is None:
483 56 storres
        retval = sollya_lib_get_prec_of_range(byref(prec), soRange, None)
484 56 storres
        if retval == 0:
485 56 storres
            return(None)
486 56 storres
        realIntervalFieldSa = RealIntervalField(prec.value)
487 56 storres
    intervalSa = realIntervalFieldSa(0,0)
488 53 storres
    retval = \
489 53 storres
        sollya_lib_get_interval_from_range(get_interval_value(intervalSa),\
490 53 storres
                                           soRange)
491 53 storres
    if retval == 0:
492 53 storres
        return(None)
493 53 storres
    return(intervalSa)
494 56 storres
# End pobyso_get_interval_from_range_so_sa
495 56 storres
496 5 storres
def pobyso_get_list_elements(soObj):
497 38 storres
    """ Legacy function. See pobyso_get_list_elements_so_so. """
498 38 storres
    return(pobyso_get_list_elements_so_so(soObj))
499 38 storres
500 117 storres
def pobyso_get_list_elements_so_so(objectListSo):
501 51 storres
    """
502 118 storres
    Get the Sollya list elements as a Sage/Python array of Sollya objects.
503 118 storres

504 118 storres
    INPUT:
505 118 storres
    - objectListSo: a Sollya list of Sollya objects.
506 118 storres

507 118 storres
    OUTPUT:
508 118 storres
    - a Sage/Python tuple made of:
509 118 storres
      - a Sage/Python list of Sollya objects,
510 118 storres
      - a Sage/Python int holding the number of elements,
511 118 storres
      - a Sage/Python int stating (!= 0) that the list is end-elliptic.
512 118 storres
    NOTE::
513 118 storres
        We recover the addresses of the Sollya object from the list of pointers
514 118 storres
        returned by sollya_lib_get_list_elements. The list itself is freed.
515 118 storres
    TODO::
516 118 storres
        Figure out what to do with numElements since the number of elements
517 118 storres
        can easily be recovered from the list itself.
518 118 storres
        Ditto for isEndElliptic.
519 51 storres
    """
520 5 storres
    listAddress = POINTER(c_longlong)()
521 5 storres
    numElements = c_int(0)
522 5 storres
    isEndElliptic = c_int(0)
523 117 storres
    listAsSageList = []
524 5 storres
    result = sollya_lib_get_list_elements(byref(listAddress),\
525 54 storres
                                          byref(numElements),\
526 54 storres
                                          byref(isEndElliptic),\
527 117 storres
                                          objectListSo)
528 5 storres
    if result == 0 :
529 5 storres
        return None
530 5 storres
    for i in xrange(0, numElements.value, 1):
531 118 storres
       #listAsSageList.append(sollya_lib_copy_obj(listAddress[i]))
532 118 storres
       listAsSageList.append(listAddress[i])
533 117 storres
       # Clear each of the elements returned by Sollya.
534 118 storres
       #sollya_lib_clear_obj(listAddress[i])
535 117 storres
    # Free the list itself.
536 117 storres
    sollya_lib_free(listAddress)
537 117 storres
    return(listAsSageList, numElements.value, isEndElliptic.value)
538 5 storres
539 38 storres
def pobyso_get_max_prec_of_exp(soExp):
540 38 storres
    """ Legacy function. See pobyso_get_max_prec_of_exp_so_sa. """
541 38 storres
    return(pobyso_get_max_prec_of_exp_so_sa(soExp))
542 5 storres
543 85 storres
def pobyso_get_max_prec_of_exp_so_sa(expSo):
544 38 storres
    """
545 38 storres
    Get the maximum precision used for the numbers in a Sollya expression.
546 52 storres

547 52 storres
    Arguments:
548 52 storres
    soExp -- a Sollya expression pointer
549 52 storres
    Return value:
550 52 storres
    A Python integer
551 38 storres
    TODO:
552 38 storres
    - error management;
553 38 storres
    - correctly deal with numerical type such as DOUBLEEXTENDED.
554 38 storres
    """
555 5 storres
    maxPrecision = 0
556 52 storres
    minConstPrec = 0
557 52 storres
    currentConstPrec = 0
558 85 storres
    operator = pobyso_get_head_function_so_sa(expSo)
559 5 storres
    if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \
560 5 storres
    (operator != SOLLYA_BASE_FUNC_FREE_VARIABLE):
561 85 storres
        (arity, subexpressions) = pobyso_get_subfunctions_so_sa(expSo)
562 5 storres
        for i in xrange(arity):
563 5 storres
            maxPrecisionCandidate = \
564 38 storres
                pobyso_get_max_prec_of_exp_so_sa(subexpressions[i])
565 5 storres
            if maxPrecisionCandidate > maxPrecision:
566 5 storres
                maxPrecision = maxPrecisionCandidate
567 5 storres
        return(maxPrecision)
568 5 storres
    elif operator == SOLLYA_BASE_FUNC_CONSTANT:
569 85 storres
        #minConstPrec = pobyso_get_min_prec_of_constant_so_sa(expSo)
570 52 storres
        #currentConstPrec = pobyso_get_min_prec_of_constant_so_sa(soExp)
571 52 storres
        #print minConstPrec, " - ", currentConstPrec
572 85 storres
        return(pobyso_get_min_prec_of_constant_so_sa(expSo))
573 52 storres
574 5 storres
    elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE:
575 5 storres
        return(0)
576 5 storres
    else:
577 38 storres
        print "pobyso_get_max_prec_of_exp_so_sa: unexepected operator."
578 5 storres
        return(0)
579 5 storres
580 85 storres
def pobyso_get_min_prec_of_constant_so_sa(constExpSo):
581 52 storres
    """
582 52 storres
    Get the minimum precision necessary to represent the value of a Sollya
583 52 storres
    constant.
584 52 storres
    MPFR_MIN_PREC and powers of 2 are taken into account.
585 85 storres
    We assume that constExpSo is a point
586 52 storres
    """
587 85 storres
    constExpAsRnSa = pobyso_get_constant_as_rn_so_sa(constExpSo)
588 85 storres
    return(min_mpfr_size(get_rn_value(constExpAsRnSa)))
589 52 storres
590 85 storres
def pobyso_get_sage_exp_from_sollya_exp(sollyaExpSo, realField = RR):
591 38 storres
    """ Legacy function. See pobyso_get_sage_exp_from_sollya_exp_so_sa. """
592 85 storres
    return(pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExpSo, \
593 85 storres
                                                     realField = RR))
594 38 storres
595 85 storres
def pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExpSo, realFieldSa = RR):
596 5 storres
    """
597 38 storres
    Get a Sage expression from a Sollya expression.
598 38 storres
    Currently only tested with polynomials with floating-point coefficients.
599 5 storres
    Notice that, in the returned polynomial, the exponents are RealNumbers.
600 5 storres
    """
601 5 storres
    #pobyso_autoprint(sollyaExp)
602 85 storres
    operatorSa = pobyso_get_head_function_so_sa(sollyaExpSo)
603 83 storres
    sollyaLibFreeVariableName = sollya_lib_get_free_variable_name()
604 5 storres
    # Constants and the free variable are special cases.
605 5 storres
    # All other operator are dealt with in the same way.
606 85 storres
    if (operatorSa != SOLLYA_BASE_FUNC_CONSTANT) and \
607 85 storres
       (operatorSa != SOLLYA_BASE_FUNC_FREE_VARIABLE):
608 85 storres
        (aritySa, subexpressionsSa) = pobyso_get_subfunctions_so_sa(sollyaExpSo)
609 85 storres
        if aritySa == 1:
610 85 storres
            sageExpSa = eval(pobyso_function_type_as_string_so_sa(operatorSa) + \
611 85 storres
            "(" + pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressionsSa[0], \
612 85 storres
            realFieldSa) + ")")
613 85 storres
        elif aritySa == 2:
614 63 storres
            # We do not get through the preprocessor.
615 63 storres
            # The "^" operator is then a special case.
616 85 storres
            if operatorSa == SOLLYA_BASE_FUNC_POW:
617 85 storres
                operatorAsStringSa = "**"
618 5 storres
            else:
619 85 storres
                operatorAsStringSa = \
620 85 storres
                    pobyso_function_type_as_string_so_sa(operatorSa)
621 85 storres
            sageExpSa = \
622 85 storres
              eval("pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressionsSa[0], realFieldSa)"\
623 85 storres
              + " " + operatorAsStringSa + " " + \
624 85 storres
                   "pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressionsSa[1], realFieldSa)")
625 63 storres
        # We do not know yet how to deal with arity >= 3
626 63 storres
        # (is there any in Sollya anyway?).
627 5 storres
        else:
628 85 storres
            sageExpSa = eval('None')
629 85 storres
        return(sageExpSa)
630 85 storres
    elif operatorSa == SOLLYA_BASE_FUNC_CONSTANT:
631 5 storres
        #print "This is a constant"
632 85 storres
        return pobyso_get_constant_as_rn_with_rf_so_sa(sollyaExpSo, realFieldSa)
633 85 storres
    elif operatorSa == SOLLYA_BASE_FUNC_FREE_VARIABLE:
634 5 storres
        #print "This is free variable"
635 83 storres
        return(eval(sollyaLibFreeVariableName))
636 5 storres
    else:
637 5 storres
        print "Unexpected"
638 5 storres
        return eval('None')
639 5 storres
# End pobyso_get_sage_poly_from_sollya_poly
640 73 storres
641 73 storres
def pobyso_get_poly_sa_so(polySo, realFieldSa=None):
642 83 storres
    """
643 83 storres
    Create a Sollya polynomial from a Sage polynomial.
644 83 storres
    """
645 73 storres
    pass
646 73 storres
# pobyso_get_poly_sa_so
647 73 storres
648 62 storres
def pobyso_get_poly_so_sa(polySo, realFieldSa=None):
649 57 storres
    """
650 57 storres
    Convert a Sollya polynomial into a Sage polynomial.
651 62 storres
    We assume that the polynomial is in canonical form.
652 124 storres
    If no realField is given, a RealField corresponding to the maximum
653 124 storres
    precision of the coefficients is internally computed.
654 124 storres
    The real field is not returned but can be easily retrieved from
655 124 storres
    the polynomial itself.
656 124 storres
    ALGORITHM:
657 57 storres
    - (optional) compute the RealField of the coefficients;
658 57 storres
    - convert the Sollya expression into a Sage expression;
659 57 storres
    - convert the Sage expression into a Sage polynomial
660 59 storres
    TODO: the canonical thing for the polynomial.
661 57 storres
    """
662 57 storres
    if realFieldSa is None:
663 57 storres
        expressionPrecSa = pobyso_get_max_prec_of_exp_so_sa(polySo)
664 57 storres
        realFieldSa = RealField(expressionPrecSa)
665 63 storres
    #print "Sollya expression before...",
666 63 storres
    #pobyso_autoprint(polySo)
667 63 storres
668 57 storres
    expressionSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, \
669 57 storres
                                                             realFieldSa)
670 63 storres
    #print "...Sollya expression after.",
671 63 storres
    #pobyso_autoprint(polySo)
672 57 storres
    polyVariableSa = expressionSa.variables()[0]
673 59 storres
    polyRingSa = realFieldSa[str(polyVariableSa)]
674 81 storres
    #print polyRingSa
675 62 storres
    # Do not use the polynomial(expressionSa, ring=polyRingSa) form!
676 62 storres
    polynomialSa = polyRingSa(expressionSa)
677 57 storres
    return(polynomialSa)
678 57 storres
# End pobyso_get_sage_poly_from_sollya_poly
679 57 storres
680 38 storres
def pobyso_get_subfunctions(expressionSo):
681 38 storres
    """ Legacy function. See pobyso_get_subfunctions_so_sa. """
682 38 storres
    return(pobyso_get_subfunctions_so_sa(expressionSo))
683 38 storres
684 38 storres
def pobyso_get_subfunctions_so_sa(expressionSo):
685 38 storres
    """
686 38 storres
    Get the subfunctions of an expression.
687 38 storres
    Return the number of subfunctions and the list of subfunctions addresses.
688 55 storres
    S.T.: Could not figure out another way than that ugly list of declarations
689 83 storres
    to recover the addresses of the subfunctions.
690 83 storres
    We limit ourselves to arity 8 functions.
691 38 storres
    """
692 5 storres
    subf0 = c_int(0)
693 5 storres
    subf1 = c_int(0)
694 5 storres
    subf2 = c_int(0)
695 5 storres
    subf3 = c_int(0)
696 5 storres
    subf4 = c_int(0)
697 5 storres
    subf5 = c_int(0)
698 5 storres
    subf6 = c_int(0)
699 5 storres
    subf7 = c_int(0)
700 5 storres
    subf8 = c_int(0)
701 5 storres
    arity = c_int(0)
702 5 storres
    nullPtr = POINTER(c_int)()
703 38 storres
    sollya_lib_get_subfunctions(expressionSo, byref(arity), \
704 83 storres
      byref(subf0), byref(subf1), byref(subf2), byref(subf3), \
705 83 storres
      byref(subf4), byref(subf5),\
706 83 storres
      byref(subf6), byref(subf7), byref(subf8), nullPtr, None)
707 83 storres
#    byref(cast(subfunctions[0], POINTER(c_int))), \
708 83 storres
#    byref(cast(subfunctions[0], POINTER(c_int))), \
709 83 storres
#    byref(cast(subfunctions[2], POINTER(c_int))), \
710 83 storres
#    byref(cast(subfunctions[3], POINTER(c_int))), \
711 83 storres
#    byref(cast(subfunctions[4], POINTER(c_int))), \
712 83 storres
#    byref(cast(subfunctions[5], POINTER(c_int))), \
713 83 storres
#    byref(cast(subfunctions[6], POINTER(c_int))), \
714 83 storres
#    byref(cast(subfunctions[7], POINTER(c_int))), \
715 5 storres
#    byref(cast(subfunctions[8], POINTER(c_int))), nullPtr)
716 83 storres
    subfunctions = [subf0, subf1, subf2, subf3, subf4, subf5, subf6, subf7, \
717 83 storres
                    subf8]
718 5 storres
    subs = []
719 5 storres
    if arity.value > pobyso_max_arity:
720 38 storres
        return(0,[])
721 5 storres
    for i in xrange(arity.value):
722 5 storres
        subs.append(int(subfunctions[i].value))
723 5 storres
        #print subs[i]
724 5 storres
    return(int(arity.value), subs)
725 5 storres
726 5 storres
def pobyso_get_prec():
727 38 storres
    """ Legacy function. See pobyso_get_prec_so_sa(). """
728 38 storres
    return(pobyso_get_prec_so_sa())
729 38 storres
730 84 storres
def pobyso_get_prec_so():
731 84 storres
    """
732 84 storres
    Get the current default precision in Sollya.
733 84 storres
    The return value is a Sollya object.
734 84 storres
    Usefull when modifying the precision back and forth by avoiding
735 84 storres
    extra conversions.
736 84 storres
    """
737 84 storres
    return(sollya_lib_get_prec(None))
738 84 storres
739 38 storres
def pobyso_get_prec_so_sa():
740 38 storres
    """
741 38 storres
    Get the current default precision in Sollya.
742 38 storres
    The return value is Sage/Python int.
743 38 storres
    """
744 56 storres
    precSo = sollya_lib_get_prec(None)
745 56 storres
    precSa = c_int(0)
746 56 storres
    sollya_lib_get_constant_as_int(byref(precSa), precSo)
747 56 storres
    sollya_lib_clear_obj(precSo)
748 56 storres
    return(int(precSa.value))
749 83 storres
# End pobyso_get_prec_so_sa.
750 5 storres
751 38 storres
def pobyso_get_prec_of_constant(ctExpSo):
752 38 storres
    """ Legacy function. See pobyso_get_prec_of_constant_so_sa. """
753 38 storres
    return(pobyso_get_prec_of_constant_so_sa(ctExpSo))
754 38 storres
755 56 storres
def pobyso_get_prec_of_constant_so_sa(ctExpSo):
756 56 storres
    prec = c_int(0)
757 56 storres
    retc = sollya_lib_get_prec_of_constant(byref(prec), ctExpSo, None)
758 56 storres
    if retc == 0:
759 56 storres
        return(None)
760 56 storres
    return(int(prec.value))
761 56 storres
762 53 storres
def pobyso_get_prec_of_range_so_sa(rangeSo):
763 5 storres
    prec = c_int(0)
764 53 storres
    retc = sollya_lib_get_prec_of_range(byref(prec), rangeSo, None)
765 56 storres
    if retc == 0:
766 56 storres
        return(None)
767 5 storres
    return(int(prec.value))
768 153 storres
# End pobyso_get_prec_of_range_so_sa()
769 5 storres
770 153 storres
def pobyso_guess_degree_so_sa(functionSo, rangeSo, errorSo, weightSo=None, \
771 153 storres
                              degreeBoundsSo=None):
772 153 storres
    # weightSo and degreeBoundsSo are optional arguments.
773 153 storres
    if weightSo is None:
774 153 storres
        degreeRangeSo = sollya_lib_guessdegree(functionSo, rangeSo, errorSo)
775 153 storres
    elif degreeBounds is None:
776 153 storres
        degreeRangeSo =  sollya_lib_guessdegree(functionSo, rangeSo, \
777 153 storres
                                                errorSo, weightSo)
778 153 storres
    else:
779 153 storres
        degreeRangeSo =  sollya_lib_guessdegree(functionSo, rangeSo, errorSo, \
780 153 storres
                                                weightSo, degreeBoundsSo)
781 153 storres
    pobyso_range_to_interval_so_sa(degreeRangeSo)
782 153 storres
# End pobyso_guess_degree_so_sa
783 153 storres
784 53 storres
def pobyso_infnorm_so_so(func, interval, file = None, intervalList = None):
785 54 storres
    print "Do not use this function. User pobyso_supnorm_so_so instead."
786 54 storres
    return(None)
787 53 storres
788 84 storres
def pobyso_interval_to_range_sa_so(intervalSa, precisionSa=None):
789 84 storres
    if precisionSa is None:
790 84 storres
        precisionSa = intervalSa.parent().precision()
791 84 storres
    intervalSo = pobyso_bounds_to_range_sa_so(intervalSa.lower(),\
792 84 storres
                                              intervalSa.upper(),\
793 84 storres
                                              precisionSa)
794 84 storres
    return(intervalSo)
795 84 storres
# End pobyso_interval_to_range_sa_so
796 84 storres
797 37 storres
def pobyso_lib_init():
798 37 storres
    sollya_lib_init(None)
799 116 storres
800 116 storres
def pobyso_lib_close():
801 116 storres
    sollya_lib_close(None)
802 37 storres
803 85 storres
def pobyso_name_free_variable(freeVariableNameSa):
804 38 storres
    """ Legacy function. See pobyso_name_free_variable_sa_so. """
805 85 storres
    pobyso_name_free_variable_sa_so(freeVariableNameSa)
806 38 storres
807 85 storres
def pobyso_name_free_variable_sa_so(freeVariableNameSa):
808 83 storres
    """
809 83 storres
    Set the free variable name in Sollya from a Sage string.
810 83 storres
    """
811 85 storres
    sollya_lib_name_free_variable(freeVariableNameSa)
812 37 storres
813 5 storres
def pobyso_parse_string(string):
814 38 storres
    """ Legacy function. See pobyso_parse_string_sa_so. """
815 38 storres
    return(pobyso_parse_string_sa_so(string))
816 38 storres
817 38 storres
def pobyso_parse_string_sa_so(string):
818 83 storres
    """
819 83 storres
    Get the Sollya expression computed from a Sage string.
820 83 storres
    """
821 5 storres
    return(sollya_lib_parse_string(string))
822 5 storres
823 5 storres
def pobyso_range(rnLowerBound, rnUpperBound):
824 38 storres
    """ Legacy function. See pobyso_range_sa_so. """
825 51 storres
    return(pobyso_range_sa_so(rnLowerBound, rnUpperBound))
826 38 storres
827 5 storres
828 85 storres
def pobyso_range_to_interval_so_sa(rangeSo, realIntervalFieldSa = None):
829 83 storres
    """
830 83 storres
    Get a Sage interval from a Sollya range.
831 83 storres
    If no realIntervalField is given as a parameter, the Sage interval
832 83 storres
    precision is that of the Sollya range.
833 85 storres
    Otherwise, the precision is that of the realIntervalField. In this case
834 85 storres
    rounding may happen.
835 83 storres
    """
836 85 storres
    if realIntervalFieldSa is None:
837 56 storres
        precSa = pobyso_get_prec_of_range_so_sa(rangeSo)
838 85 storres
        realIntervalFieldSa = RealIntervalField(precSa)
839 56 storres
    intervalSa = \
840 85 storres
        pobyso_get_interval_from_range_so_sa(rangeSo, realIntervalFieldSa)
841 56 storres
    return(intervalSa)
842 56 storres
843 52 storres
def pobyso_remez_canonical_sa_sa(func, \
844 52 storres
                                 degree, \
845 52 storres
                                 lowerBound, \
846 52 storres
                                 upperBound, \
847 52 storres
                                 weight = None, \
848 52 storres
                                 quality = None):
849 52 storres
    """
850 52 storres
    All arguments are Sage/Python.
851 52 storres
    The functions (func and weight) must be passed as expressions or strings.
852 52 storres
    Otherwise the function fails.
853 83 storres
    The return value is a Sage polynomial.
854 52 storres
    """
855 83 storres
    var('zorglub')    # Dummy variable name for type check only. Type of
856 83 storres
    # zorglub is "symbolic expression".
857 52 storres
    polySo = pobyso_remez_canonical_sa_so(func, \
858 52 storres
                                 degree, \
859 52 storres
                                 lowerBound, \
860 52 storres
                                 upperBound, \
861 85 storres
                                 weight, \
862 85 storres
                                 quality)
863 83 storres
    # String test
864 52 storres
    if parent(func) == parent("string"):
865 52 storres
        functionSa = eval(func)
866 52 storres
    # Expression test.
867 52 storres
    elif type(func) == type(zorglub):
868 52 storres
        functionSa = func
869 83 storres
    else:
870 83 storres
        return None
871 83 storres
    #
872 52 storres
    maxPrecision = 0
873 52 storres
    if polySo is None:
874 52 storres
        return(None)
875 52 storres
    maxPrecision = pobyso_get_max_prec_of_exp_so_sa(polySo)
876 85 storres
    RRRRSa = RealField(maxPrecision)
877 85 storres
    polynomialRingSa = RRRRSa[functionSa.variables()[0]]
878 85 storres
    expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, RRRRSa)
879 85 storres
    polySa = polynomial(expSa, polynomialRingSa)
880 83 storres
    sollya_lib_clear_obj(polySo)
881 52 storres
    return(polySa)
882 85 storres
# End pobyso_remez_canonical_sa_sa
883 52 storres
884 38 storres
def pobyso_remez_canonical(func, \
885 5 storres
                           degree, \
886 5 storres
                           lowerBound, \
887 5 storres
                           upperBound, \
888 38 storres
                           weight = "1", \
889 5 storres
                           quality = None):
890 38 storres
    """ Legacy function. See pobyso_remez_canonical_sa_so. """
891 51 storres
    return(pobyso_remez_canonical_sa_so(func, \
892 51 storres
                                        degree, \
893 51 storres
                                        lowerBound, \
894 51 storres
                                        upperBound, \
895 51 storres
                                        weight, \
896 51 storres
                                        quality))
897 38 storres
def pobyso_remez_canonical_sa_so(func, \
898 38 storres
                                 degree, \
899 38 storres
                                 lowerBound, \
900 38 storres
                                 upperBound, \
901 52 storres
                                 weight = None, \
902 38 storres
                                 quality = None):
903 38 storres
    """
904 38 storres
    All arguments are Sage/Python.
905 51 storres
    The functions (func and weight) must be passed as expressions or strings.
906 51 storres
    Otherwise the function fails.
907 38 storres
    The return value is a pointer to a Sollya function.
908 38 storres
    """
909 83 storres
    var('zorglub')    # Dummy variable name for type check only. Type of
910 83 storres
    # zorglub is "symbolic expression".
911 85 storres
    currentVariableNameSa = None
912 52 storres
    # The func argument can be of different types (string,
913 52 storres
    # symbolic expression...)
914 38 storres
    if parent(func) == parent("string"):
915 85 storres
        localFuncSa = eval(func)
916 85 storres
        if len(localFuncSa.variables()) > 0:
917 85 storres
            currentVariableNameSa = localFuncSa.variables()[0]
918 85 storres
            sollya_lib_name_free_variable(str(currentVariableNameSa))
919 85 storres
            functionSo = sollya_lib_parse_string(localFuncSa._assume_str())
920 51 storres
    # Expression test.
921 52 storres
    elif type(func) == type(zorglub):
922 52 storres
        # Until we are able to translate Sage expressions into Sollya
923 52 storres
        # expressions : parse the string version.
924 85 storres
        if len(func.variables()) > 0:
925 85 storres
            currentVariableNameSa = func.variables()[0]
926 85 storres
            sollya_lib_name_free_variable(str(currentVariableNameSa))
927 85 storres
            functionSo = sollya_lib_parse_string(func._assume_str())
928 38 storres
    else:
929 38 storres
        return(None)
930 85 storres
    if weight is None: # No weight given -> 1.
931 52 storres
        weightSo = pobyso_constant_1_sa_so()
932 85 storres
    elif parent(weight) == parent("string"): # Weight given as string: parse it.
933 51 storres
        weightSo = sollya_lib_parse_string(func)
934 85 storres
    elif type(weight) == type(zorglub): # Weight given as symbolice expression.
935 51 storres
        functionSo = sollya_lib_parse_string_sa_so(weight._assume_str())
936 51 storres
    else:
937 51 storres
        return(None)
938 5 storres
    degreeSo = pobyso_constant_from_int(degree)
939 85 storres
    rangeSo = pobyso_bounds_to_range_sa_so(lowerBound, upperBound)
940 38 storres
    if not quality is None:
941 38 storres
        qualitySo= pobyso_constant_sa_so(quality)
942 52 storres
    else:
943 52 storres
        qualitySo = None
944 83 storres
945 83 storres
    remezPolySo = sollya_lib_remez(functionSo, \
946 83 storres
                                   degreeSo, \
947 83 storres
                                   rangeSo, \
948 83 storres
                                   weightSo, \
949 83 storres
                                   qualitySo, \
950 83 storres
                                   None)
951 83 storres
    sollya_lib_clear_obj(functionSo)
952 83 storres
    sollya_lib_clear_obj(degreeSo)
953 83 storres
    sollya_lib_clear_obj(rangeSo)
954 83 storres
    sollya_lib_clear_obj(weightSo)
955 83 storres
    if not qualitySo is None:
956 85 storres
        sollya_lib_clear_obj(qualitySo)
957 83 storres
    return(remezPolySo)
958 83 storres
# End pobyso_remez_canonical_sa_so
959 83 storres
960 38 storres
def pobyso_remez_canonical_so_so(funcSo, \
961 38 storres
                                 degreeSo, \
962 38 storres
                                 rangeSo, \
963 52 storres
                                 weightSo = pobyso_constant_1_sa_so(),\
964 38 storres
                                 qualitySo = None):
965 38 storres
    """
966 38 storres
    All arguments are pointers to Sollya objects.
967 38 storres
    The return value is a pointer to a Sollya function.
968 38 storres
    """
969 38 storres
    if not sollya_lib_obj_is_function(funcSo):
970 38 storres
        return(None)
971 38 storres
    return(sollya_lib_remez(funcSo, degreeSo, rangeSo, weightSo, qualitySo, None))
972 38 storres
973 5 storres
def pobyso_set_canonical_off():
974 5 storres
    sollya_lib_set_canonical(sollya_lib_off())
975 5 storres
976 5 storres
def pobyso_set_canonical_on():
977 5 storres
    sollya_lib_set_canonical(sollya_lib_on())
978 5 storres
979 5 storres
def pobyso_set_prec(p):
980 38 storres
    """ Legacy function. See pobyso_set_prec_sa_so. """
981 85 storres
    pobyso_set_prec_sa_so(p)
982 38 storres
983 38 storres
def pobyso_set_prec_sa_so(p):
984 5 storres
    a = c_int(p)
985 5 storres
    precSo = c_void_p(sollya_lib_constant_from_int(a))
986 85 storres
    sollya_lib_set_prec(precSo, None)
987 5 storres
988 85 storres
def pobyso_set_prec_so_so(newPrecSo):
989 85 storres
    sollya_lib_set_prec(newPrecSo, None)
990 54 storres
991 85 storres
def pobyso_supnorm_so_so(polySo, funcSo, intervalSo, errorTypeSo = None,\
992 85 storres
                         accuracySo = None):
993 58 storres
    """
994 85 storres
    Computes the supnorm of the approximation error between the given
995 85 storres
    polynomial and function.
996 85 storres
    errorTypeSo defaults to "absolute".
997 85 storres
    accuracySo defaults to 2^(-40).
998 85 storres
    """
999 85 storres
    if errorTypeSo is None:
1000 85 storres
        errorTypeSo = sollya_lib_absolute(None)
1001 85 storres
        errorTypeIsNone = True
1002 85 storres
    else:
1003 85 storres
        errorTypeIsNone = False
1004 85 storres
    #
1005 85 storres
    if accuracySo is None:
1006 85 storres
        # Notice the **!
1007 85 storres
        accuracySo = pobyso_constant_sa_so(RR(2**(-40)))
1008 85 storres
        accuracyIsNone = True
1009 85 storres
    else:
1010 85 storres
        accuracyIsNone = False
1011 85 storres
    pobyso_autoprint(accuracySo)
1012 85 storres
    resultSo = \
1013 85 storres
        sollya_lib_supnorm(polySo, funcSo, intervalSo, errorTypeSo, \
1014 85 storres
                              accuracySo)
1015 85 storres
    if errorTypeIsNone:
1016 85 storres
        sollya_lib_clear_obj(errorTypeSo)
1017 85 storres
    if accuracyIsNone:
1018 85 storres
        sollya_lib_clear_obj(accuracySo)
1019 85 storres
    return resultSo
1020 85 storres
# End pobyso_supnorm_so_so
1021 85 storres
1022 85 storres
def pobyso_taylor_expansion_with_change_var_so_so(functionSo, degreeSo, \
1023 85 storres
                                                  rangeSo, \
1024 85 storres
                                                  errorTypeSo=None, \
1025 85 storres
                                                  sollyaPrecSo=None):
1026 85 storres
    """
1027 58 storres
    Compute the Taylor expansion with the variable change
1028 58 storres
    x -> (x-intervalCenter) included.
1029 58 storres
    """
1030 58 storres
    # No global change of the working precision.
1031 58 storres
    if not sollyaPrecSo is None:
1032 58 storres
        initialPrecSo = sollya_lib_get_prec(None)
1033 58 storres
        sollya_lib_set_prec(sollyaPrecSo)
1034 58 storres
    #
1035 85 storres
    # Error type stuff: default to absolute.
1036 85 storres
    if errorTypeSo is None:
1037 85 storres
        errorTypeIsNone = True
1038 85 storres
        errorTypeSo = sollya_lib_absolute(None)
1039 85 storres
    else:
1040 85 storres
        errorTypeIsNone = False
1041 58 storres
    intervalCenterSo = sollya_lib_mid(rangeSo)
1042 58 storres
    taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \
1043 58 storres
                                         intervalCenterSo, \
1044 58 storres
                                         rangeSo, errorTypeSo, None)
1045 117 storres
    # taylorFormListSaSo is a Python list of Sollya objects references that
1046 117 storres
    # are copies of the elements of taylorFormSo.
1047 117 storres
    # pobyso_get_list_elements_so_so clears taylorFormSo.
1048 58 storres
    (taylorFormListSo, numElements, isEndElliptic) = \
1049 58 storres
        pobyso_get_list_elements_so_so(taylorFormSo)
1050 58 storres
    polySo = taylorFormListSo[0]
1051 58 storres
    errorRangeSo = taylorFormListSo[2]
1052 58 storres
    maxErrorSo = sollya_lib_sup(errorRangeSo)
1053 58 storres
    changeVarExpSo = sollya_lib_build_function_sub(\
1054 58 storres
                       sollya_lib_build_function_free_variable(),\
1055 58 storres
                       sollya_lib_copy_obj(intervalCenterSo))
1056 58 storres
    polyVarChangedSo = sollya_lib_evaluate(polySo, changeVarExpSo)
1057 115 storres
    sollya_lib_clear_obj(changeVarExpSo)
1058 58 storres
    # If changed, reset the Sollya working precision.
1059 58 storres
    if not sollyaPrecSo is None:
1060 58 storres
        sollya_lib_set_prec(initialPrecSo)
1061 83 storres
        sollya_lib_clear_obj(initialPrecSo)
1062 85 storres
    if errorTypeIsNone:
1063 85 storres
        sollya_lib_clear_obj(errorTypeSo)
1064 85 storres
    sollya_lib_clear_obj(taylorFormSo)
1065 85 storres
    # Do not clear maxErrorSo.
1066 63 storres
    return((polyVarChangedSo, intervalCenterSo, maxErrorSo))
1067 58 storres
# end pobyso_taylor_expansion_with_change_var_so_so
1068 58 storres
1069 117 storres
def pobyso_taylor_expansion_no_change_var_so_so(functionSo, degreeSo, rangeSo,
1070 117 storres
                                                errorTypeSo=None,
1071 56 storres
                                                sollyaPrecSo=None):
1072 58 storres
    """
1073 58 storres
    Compute the Taylor expansion without the variable change
1074 58 storres
    x -> x-intervalCenter.
1075 58 storres
    """
1076 56 storres
    # No global change of the working precision.
1077 56 storres
    if not sollyaPrecSo is None:
1078 56 storres
        initialPrecSo = sollya_lib_get_prec(None)
1079 56 storres
        sollya_lib_set_prec(sollyaPrecSo)
1080 85 storres
    # Error type stuff: default to absolute.
1081 85 storres
    if errorTypeSo is None:
1082 85 storres
        errorTypeIsNone = True
1083 85 storres
        errorTypeSo = sollya_lib_absolute(None)
1084 85 storres
    else:
1085 85 storres
        errorTypeIsNone = False
1086 117 storres
    intervalCenterSo = sollya_lib_mid(rangeSo, None)
1087 117 storres
    taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo,
1088 117 storres
                                         intervalCenterSo,
1089 56 storres
                                         rangeSo, errorTypeSo, None)
1090 116 storres
    # taylorFormListSaSo is a Python list of Sollya objects references that
1091 116 storres
    # are copies of the elements of taylorFormSo.
1092 116 storres
    # pobyso_get_list_elements_so_so clears taylorFormSo.
1093 116 storres
    (taylorFormListSaSo, numElementsSa, isEndEllipticSa) = \
1094 56 storres
        pobyso_get_list_elements_so_so(taylorFormSo)
1095 120 storres
    polySo = sollya_lib_copy_obj(taylorFormListSaSo[0])
1096 120 storres
    #print "Num elements:", numElementsSa
1097 117 storres
    sollya_lib_clear_obj(taylorFormSo)
1098 117 storres
    #polySo = taylorFormListSaSo[0]
1099 116 storres
    #errorRangeSo = sollya_lib_copy_obj(taylorFormListSaSo[2])
1100 116 storres
    errorRangeSo = taylorFormListSaSo[2]
1101 103 storres
    # No copy_obj needed here: a new object is created.
1102 56 storres
    maxErrorSo = sollya_lib_sup(errorRangeSo)
1103 56 storres
    # If changed, reset the Sollya working precision.
1104 56 storres
    if not sollyaPrecSo is None:
1105 56 storres
        sollya_lib_set_prec(initialPrecSo)
1106 63 storres
        sollya_lib_clear_obj(initialPrecSo)
1107 85 storres
    if errorTypeIsNone:
1108 85 storres
        sollya_lib_clear_obj(errorTypeSo)
1109 117 storres
    pobyso_clear_taylorform_sa_so(taylorFormListSaSo)
1110 63 storres
    return((polySo, intervalCenterSo, maxErrorSo))
1111 56 storres
# end pobyso_taylor_expansion_no_change_var_so_so
1112 56 storres
1113 5 storres
def pobyso_taylor(function, degree, point):
1114 38 storres
    """ Legacy function. See pobysoTaylor_so_so. """
1115 38 storres
    return(pobyso_taylor_so_so(function, degree, point))
1116 38 storres
1117 56 storres
def pobyso_taylor_so_so(functionSo, degreeSo, pointSo):
1118 56 storres
    return(sollya_lib_taylor(functionSo, degreeSo, pointSo))
1119 5 storres
1120 85 storres
def pobyso_taylorform(function, degree, point = None,
1121 85 storres
                      interval = None, errorType=None):
1122 85 storres
    """ Legacy function. See pobyso_taylorform_sa_sa;"""
1123 38 storres
1124 38 storres
def pobyso_taylorform_sa_sa(functionSa, \
1125 84 storres
                            degreeSa, \
1126 84 storres
                            pointSa, \
1127 84 storres
                            intervalSa=None, \
1128 84 storres
                            errorTypeSa=None, \
1129 84 storres
                            precisionSa=None):
1130 37 storres
    """
1131 85 storres
    Compute the Taylor form of 'degreeSa' for 'functionSa' at 'pointSa'
1132 85 storres
    for 'intervalSa' with 'errorTypeSa' (a string) using 'precisionSa'.
1133 37 storres
    point: must be a Real or a Real interval.
1134 37 storres
    return the Taylor form as an array
1135 83 storres
    TODO: take care of the interval and of the point when it is an interval;
1136 38 storres
          when errorType is not None;
1137 83 storres
          take care of the other elements of the Taylor form (coefficients
1138 83 storres
          errors and delta.
1139 37 storres
    """
1140 37 storres
    # Absolute as the default error.
1141 84 storres
    if errorTypeSa is None:
1142 37 storres
        errorTypeSo = sollya_lib_absolute()
1143 84 storres
    elif errorTypeSa == "relative":
1144 84 storres
        errorTypeSo = sollya_lib_relative()
1145 84 storres
    elif errortypeSa == "absolute":
1146 84 storres
        errorTypeSo = sollya_lib_absolute()
1147 37 storres
    else:
1148 84 storres
        # No clean up needed.
1149 84 storres
        return None
1150 84 storres
    # Global precision stuff
1151 84 storres
    precisionChangedSa = False
1152 84 storres
    currentSollyaPrecSo = pobyso_get_prec_so()
1153 84 storres
    currentSollyaPrecSa = pobyso_constant_from_int_so_sa(currentSollyaPrecSo)
1154 84 storres
    if not precisionSa is None:
1155 84 storres
        if precisionSa > currentSollyaPrecSa:
1156 84 storres
            pobyso_set_prec_sa_so(precisionSa)
1157 84 storres
            precisionChangedSa = True
1158 84 storres
1159 85 storres
    if len(functionSa.variables()) > 0:
1160 85 storres
        varSa = functionSa.variables()[0]
1161 85 storres
        pobyso_name_free_variable_sa_so(str(varSa))
1162 84 storres
    # In any case (point or interval) the parent of pointSa has a precision
1163 84 storres
    # method.
1164 84 storres
    pointPrecSa = pointSa.parent().precision()
1165 84 storres
    if precisionSa > pointPrecSa:
1166 84 storres
        pointPrecSa = precisionSa
1167 84 storres
    # In any case (point or interval) pointSa has a base_ring() method.
1168 84 storres
    pointBaseRingString = str(pointSa.base_ring())
1169 84 storres
    if re.search('Interval', pointBaseRingString) is None: # Point
1170 84 storres
        pointSo = pobyso_constant_sa_so(pointSa, pointPrecSa)
1171 84 storres
    else: # Interval.
1172 84 storres
        pointSo = pobyso_interval_to_range_sa_so(pointSa, pointPrecSa)
1173 37 storres
    # Sollyafy the function.
1174 38 storres
    functionSo = pobyso_parse_string_sa_so(functionSa._assume_str())
1175 37 storres
    if sollya_lib_obj_is_error(functionSo):
1176 37 storres
        print "pobyso_tailorform: function string can't be parsed!"
1177 37 storres
        return None
1178 37 storres
    # Sollyafy the degree
1179 84 storres
    degreeSo = sollya_lib_constant_from_int(int(degreeSa))
1180 37 storres
    # Sollyafy the point
1181 37 storres
    # Call Sollya
1182 83 storres
    taylorFormSo = \
1183 83 storres
        sollya_lib_taylorform(functionSo, degreeSo, pointSo, errorTypeSo,\
1184 37 storres
                                         None)
1185 85 storres
    sollya_lib_clear_obj(functionSo)
1186 85 storres
    sollya_lib_clear_obj(degreeSo)
1187 85 storres
    sollya_lib_clear_obj(pointSo)
1188 85 storres
    sollya_lib_clear_obj(errorTypeSo)
1189 38 storres
    (tfsAsList, numElements, isEndElliptic) = \
1190 38 storres
            pobyso_get_list_elements_so_so(taylorFormSo)
1191 37 storres
    polySo = tfsAsList[0]
1192 38 storres
    maxPrecision = pobyso_get_max_prec_of_exp_so_sa(polySo)
1193 37 storres
    polyRealField = RealField(maxPrecision)
1194 38 storres
    expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, polyRealField)
1195 84 storres
    if precisionChangedSa:
1196 84 storres
        sollya_lib_set_prec(currentSollyaPrecSo)
1197 84 storres
        sollya_lib_clear_obj(currentSollyaPrecSo)
1198 37 storres
    polynomialRing = polyRealField[str(varSa)]
1199 37 storres
    polySa = polynomial(expSa, polynomialRing)
1200 37 storres
    taylorFormSa = [polySa]
1201 85 storres
    # Final clean-up.
1202 85 storres
    sollya_lib_clear_obj(taylorFormSo)
1203 51 storres
    return(taylorFormSa)
1204 51 storres
# End pobyso_taylor_form_sa_sa
1205 54 storres
1206 54 storres
def pobyso_taylorform_so_so(functionSo, degreeSo, pointSo, intervalSo=None, \
1207 54 storres
                            errorTypeSo=None):
1208 54 storres
    createdErrorType = False
1209 51 storres
    if errorTypeSo is None:
1210 51 storres
        errorTypeSo = sollya_lib_absolute()
1211 54 storres
        createdErrorType = True
1212 51 storres
    else:
1213 51 storres
        #TODO: deal with the other case.
1214 51 storres
        pass
1215 51 storres
    if intervalSo is None:
1216 54 storres
        resultSo = sollya_lib_taylorform(functionSo, degreeSo, pointSo, \
1217 54 storres
                                         errorTypeSo, None)
1218 51 storres
    else:
1219 54 storres
        resultSo = sollya_lib_taylorform(functionSo, degreeSo, pointSo, \
1220 54 storres
                                         intervalSo, errorTypeSo, None)
1221 54 storres
    if createdErrorType:
1222 54 storres
        sollya_lib_clear_obj(errorTypeSo)
1223 51 storres
    return(resultSo)
1224 51 storres
1225 37 storres
1226 37 storres
def pobyso_univar_polynomial_print_reverse(polySa):
1227 51 storres
    """ Legacy function. See pobyso_univar_polynomial_print_reverse_sa_sa. """
1228 51 storres
    return(pobyso_univar_polynomial_print_reverse_sa_sa(polySa))
1229 38 storres
1230 51 storres
def pobyso_univar_polynomial_print_reverse_sa_sa(polySa):
1231 37 storres
    """
1232 37 storres
    Return the string representation of a univariate polynomial with
1233 38 storres
    monomials ordered in the x^0..x^n order of the monomials.
1234 37 storres
    Remember: Sage
1235 37 storres
    """
1236 37 storres
    polynomialRing = polySa.base_ring()
1237 37 storres
    # A very expensive solution:
1238 37 storres
    # -create a fake multivariate polynomial field with only one variable,
1239 37 storres
    #   specifying a negative lexicographical order;
1240 37 storres
    mpolynomialRing = PolynomialRing(polynomialRing.base(), \
1241 37 storres
                                     polynomialRing.variable_name(), \
1242 37 storres
                                     1, order='neglex')
1243 37 storres
    # - convert the univariate argument polynomial into a multivariate
1244 37 storres
    #   version;
1245 37 storres
    p = mpolynomialRing(polySa)
1246 37 storres
    # - return the string representation of the converted form.
1247 37 storres
    # There is no simple str() method defined for p's class.
1248 37 storres
    return(p.__str__())
1249 5 storres
#
1250 5 storres
print pobyso_get_prec()
1251 5 storres
pobyso_set_prec(165)
1252 5 storres
print pobyso_get_prec()
1253 5 storres
a=100
1254 5 storres
print type(a)
1255 5 storres
id(a)
1256 5 storres
print "Max arity: ", pobyso_max_arity
1257 5 storres
print "Function tripleDouble (43) as a string: ", pobyso_function_type_as_string(43)
1258 56 storres
print "Function None (44) as a string: ", pobyso_function_type_as_string(44)
1259 56 storres
print "...Pobyso check done"