Statistiques
| Révision :

root / pobysoPythonSage / src / pobyso.py @ 38

Historique | Voir | Annoter | Télécharger (22,54 ko)

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

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

8
pobyso functions come in five flavors: 
9
- the _so_so (arguments and returned objects are pointers to Sollya objects, includes
10
  the void function and the no arguments function that return a pointer to a Sollya
11
  object);
12
- the _so_sa (argument are pointers to Sollya objects, returned objects are
13
  Sage/Python objects or, more generally, information is transfered from the Sollya
14
  world to Sage/Python world);
15
- the _sa_so (arguments are Sage/Python objects, returned objects are 
16
  pointers to Sollya objects);
17
- the sa_sa (arguments and returned objects are all Sage/Python objects);
18
- a catch all flavor without suffix.
19
NOTES:
20
Reported errors in Eclipse come from the calls to
21
the Sollya library
22

23
ToDo (among other things): 
24
 -memory management.
25
"""
26
from ctypes import *
27
import re
28
from sage.symbolic.expression_conversions import polynomial
29
"""
30
Create the equivalent to an enum for the Sollya function types.
31
"""
32
(SOLLYA_BASE_FUNC_ABS,
33
SOLLYA_BASE_FUNC_ACOS,
34
    SOLLYA_BASE_FUNC_ACOSH,
35
    SOLLYA_BASE_FUNC_ADD,
36
    SOLLYA_BASE_FUNC_ASIN,
37
    SOLLYA_BASE_FUNC_ASINH,
38
    SOLLYA_BASE_FUNC_ATAN,
39
    SOLLYA_BASE_FUNC_ATANH,
40
    SOLLYA_BASE_FUNC_CEIL,
41
    SOLLYA_BASE_FUNC_CONSTANT,
42
    SOLLYA_BASE_FUNC_COS,
43
    SOLLYA_BASE_FUNC_COSH,
44
    SOLLYA_BASE_FUNC_DIV,
45
    SOLLYA_BASE_FUNC_DOUBLE,
46
    SOLLYA_BASE_FUNC_DOUBLEDOUBLE,
47
    SOLLYA_BASE_FUNC_DOUBLEEXTENDED,
48
    SOLLYA_BASE_FUNC_ERF,
49
    SOLLYA_BASE_FUNC_ERFC,
50
    SOLLYA_BASE_FUNC_EXP,
51
    SOLLYA_BASE_FUNC_EXP_M1,
52
    SOLLYA_BASE_FUNC_FLOOR,
53
    SOLLYA_BASE_FUNC_FREE_VARIABLE,
54
    SOLLYA_BASE_FUNC_HALFPRECISION,
55
    SOLLYA_BASE_FUNC_LIBRARYCONSTANT,
56
    SOLLYA_BASE_FUNC_LIBRARYFUNCTION,
57
    SOLLYA_BASE_FUNC_LOG,
58
    SOLLYA_BASE_FUNC_LOG_10,
59
    SOLLYA_BASE_FUNC_LOG_1P,
60
    SOLLYA_BASE_FUNC_LOG_2,
61
    SOLLYA_BASE_FUNC_MUL,
62
    SOLLYA_BASE_FUNC_NEARESTINT,
63
    SOLLYA_BASE_FUNC_NEG,
64
    SOLLYA_BASE_FUNC_PI,
65
    SOLLYA_BASE_FUNC_POW,
66
    SOLLYA_BASE_FUNC_PROCEDUREFUNCTION,
67
    SOLLYA_BASE_FUNC_QUAD,
68
    SOLLYA_BASE_FUNC_SIN,
69
    SOLLYA_BASE_FUNC_SINGLE,
70
    SOLLYA_BASE_FUNC_SINH,
71
    SOLLYA_BASE_FUNC_SQRT,
72
    SOLLYA_BASE_FUNC_SUB,
73
    SOLLYA_BASE_FUNC_TAN,
74
    SOLLYA_BASE_FUNC_TANH,
75
SOLLYA_BASE_FUNC_TRIPLEDOUBLE) = map(int,xrange(44))
76
print "First constant - SOLLYA_BASE_FUNC_ABS: ", SOLLYA_BASE_FUNC_ABS
77
print "Last constant  - SOLLYA_BASE_FUNC_TRIPLEDOUBLE: ", SOLLYA_BASE_FUNC_TRIPLEDOUBLE
78

    
79
pobyso_max_arity = 9
80

    
81
def pobyso_autoprint(arg):
82
    sollya_lib_autoprint(arg,None)
83

    
84
def pobyso_autoprint_so_so(arg):
85
    sollya_lib_autoprint(arg,None)
86

    
87
def pobyso_cmp(rnArg, soCte):
88
    precisionOfCte = c_int(0)
89
    # From the Sollya constant, create a local Sage RealNumber.
90
    sollya_lib_get_prec_of_constant(precisionOfCte, soCte) 
91
    #print "Precision of constant: ", precisionOfCte
92
    RRRR = RealField(precisionOfCte.value)
93
    rnLocal = RRRR(0)
94
    sollya_lib_get_constant(get_rn_value(rnLocal), soCte)
95
    #print "rnDummy: ", rnDummy
96
    # Compare the local Sage RealNumber with rnArg.
97
    return(cmp_rn_value(rnArg, rnLocal))
98

    
99
def pobyso_constant(rnArg):
100
    """ Legacy function. See pobyso_constant_sa_so. """
101
    return(pobyso_constant_sa_so(rnArg))
102
    
103
def pobyso_constant_sa_so(rnArg):
104
    return(sollya_lib_constant(get_rn_value(rnArg)))
105
    
106
def pobyso_constant_1():
107
    """ Legacy function. See pobyso_constant_so_so. """
108
    return(pobyso_constant_1_so_so())
109

    
110
def pobyso_constant_1_so_so():
111
    return(pobyso_constant_from_int_sa_so(1))
112

    
113
def pobyso_constant_from_int(anInt):
114
    """ Legacy function. See pobyso_constant_from_int_sa_so. """
115
    return(pobyso_constant_from_int_sa_so(anInt))
116

    
117
def pobyso_constant_from_int_sa_so(anInt):
118
    return(sollya_lib_constant_from_int(int(anInt)))
119

    
120
def pobyso_function_type_as_string(funcType):
121
    """ Legacy function. See pobyso_function_type_as_string_so_sa. """
122
    return(pobyso_function_type_as_string_so_sa(funcType))
123

    
124
def pobyso_function_type_as_string_so_sa(funcType):
125
    """
126
    Numeric Sollya function codes -> Sage mathematical function names.
127
    Notice that pow -> ^ (a la Sage, not a la Python).
128
    """
129
    if funcType == SOLLYA_BASE_FUNC_ABS:
130
        return "abs"
131
    elif funcType == SOLLYA_BASE_FUNC_ACOS:
132
        return "arccos"
133
    elif funcType == SOLLYA_BASE_FUNC_ACOSH:
134
        return "arccosh"
135
    elif funcType == SOLLYA_BASE_FUNC_ADD:
136
        return "+"
137
    elif funcType == SOLLYA_BASE_FUNC_ASIN:
138
        return "arcsin"
139
    elif funcType == SOLLYA_BASE_FUNC_ASINH:
140
        return "arcsinh"
141
    elif funcType == SOLLYA_BASE_FUNC_ATAN:
142
        return "arctan"
143
    elif funcType == SOLLYA_BASE_FUNC_ATANH:
144
        return "arctanh"
145
    elif funcType == SOLLYA_BASE_FUNC_CEIL:
146
        return "ceil"
147
    elif funcType == SOLLYA_BASE_FUNC_CONSTANT:
148
        return "cte"
149
    elif funcType == SOLLYA_BASE_FUNC_COS:
150
        return "cos"
151
    elif funcType == SOLLYA_BASE_FUNC_COSH:
152
        return "cosh"
153
    elif funcType == SOLLYA_BASE_FUNC_DIV:
154
        return "/"
155
    elif funcType == SOLLYA_BASE_FUNC_DOUBLE:
156
        return "double"
157
    elif funcType == SOLLYA_BASE_FUNC_DOUBLEDOUBLE:
158
        return "doubleDouble"
159
    elif funcType == SOLLYA_BASE_FUNC_DOUBLEEXTENDED:
160
        return "doubleDxtended"
161
    elif funcType == SOLLYA_BASE_FUNC_ERF:
162
        return "erf"
163
    elif funcType == SOLLYA_BASE_FUNC_ERFC:
164
        return "erfc"
165
    elif funcType == SOLLYA_BASE_FUNC_EXP:
166
        return "exp"
167
    elif funcType == SOLLYA_BASE_FUNC_EXP_M1:
168
        return "expm1"
169
    elif funcType == SOLLYA_BASE_FUNC_FLOOR:
170
        return "floor"
171
    elif funcType == SOLLYA_BASE_FUNC_FREE_VARIABLE:
172
        return "freeVariable"
173
    elif funcType == SOLLYA_BASE_FUNC_HALFPRECISION:
174
        return "halfPrecision"
175
    elif funcType == SOLLYA_BASE_FUNC_LIBRARYCONSTANT:
176
        return "libraryConstant"
177
    elif funcType == SOLLYA_BASE_FUNC_LIBRARYFUNCTION:
178
        return "libraryFunction"
179
    elif funcType == SOLLYA_BASE_FUNC_LOG:
180
        return "log"
181
    elif funcType == SOLLYA_BASE_FUNC_LOG_10:
182
        return "log10"
183
    elif funcType == SOLLYA_BASE_FUNC_LOG_1P:
184
        return "log1p"
185
    elif funcType == SOLLYA_BASE_FUNC_LOG_2:
186
        return "log2"
187
    elif funcType == SOLLYA_BASE_FUNC_MUL:
188
        return "*"
189
    elif funcType == SOLLYA_BASE_FUNC_NEARESTINT:
190
        return "round"
191
    elif funcType == SOLLYA_BASE_FUNC_NEG:
192
        return "__neg__"
193
    elif funcType == SOLLYA_BASE_FUNC_PI:
194
        return "pi"
195
    elif funcType == SOLLYA_BASE_FUNC_POW:
196
        return "^"
197
    elif funcType == SOLLYA_BASE_FUNC_PROCEDUREFUNCTION:
198
        return "procedureFunction"
199
    elif funcType == SOLLYA_BASE_FUNC_QUAD:
200
        return "quad"
201
    elif funcType == SOLLYA_BASE_FUNC_SIN:
202
        return "sin"
203
    elif funcType == SOLLYA_BASE_FUNC_SINGLE:
204
        return "single"
205
    elif funcType == SOLLYA_BASE_FUNC_SINH:
206
        return "sinh"
207
    elif funcType == SOLLYA_BASE_FUNC_SQRT:
208
        return "sqrt"
209
    elif funcType == SOLLYA_BASE_FUNC_SUB:
210
        return "-"
211
    elif funcType == SOLLYA_BASE_FUNC_TAN:
212
        return "tan"
213
    elif funcType == SOLLYA_BASE_FUNC_TANH:
214
        return "tanh"
215
    elif funcType == SOLLYA_BASE_FUNC_TRIPLEDOUBLE:
216
        return "tripleDouble"
217
    else:
218
        return None
219

    
220
def pobyso_get_constant(rnArg, soConst):
221
    """ Legacy function. See pobyso_get_constant_so_sa. """
222
    pobyso_get_constant_so_sa(rnArg, soConst)
223

    
224
def pobyso_get_constant_so_sa(rnArg, soConst):
225
    set_rn_value(rnArg, soConst)
226
    
227
def pobyso_get_constant_as_rn(ctExp):
228
    """ Legacy function. See pobyso_get_constant_as_rn_so_sa. """ 
229
    return(pobyso_get_constant_as_rn_so_sa(ctExp))
230
    
231
def pobyso_get_constant_as_rn_so_sa(ctExp):
232
    precision  = pobyso_get_prec_of_constant(ctExp) 
233
    RRRR = RealField(precision)
234
    rn = RRRR(0)
235
    sollya_lib_get_constant(get_rn_value(rn), ctExp)
236
    return(rn)
237

    
238
def pobyso_get_constant_as_rn_with_rf(ctExp, realField):
239
    """ Legacy function. See ."""
240
    return(pobyso_get_constant_as_rn_with_rf_so_sa(ctExp, realField))
241
    
242
def pobyso_get_constant_as_rn_with_rf_so_sa(ctExp, realField):
243
    rn = realField(0)
244
    sollya_lib_get_constant(get_rn_value(rn), ctExp)
245
    return(rn)
246

    
247
def pobyso_get_free_variable_name():
248
    """ Legacy function. See pobyso_get_free_variable_name_so_sa."""
249
    return(pobyso_get_free_variable_name_so_sa())
250

    
251
def pobyso_get_free_variable_name_so_sa():
252
    return(sollya_lib_get_free_variable_name())
253
    
254
def pobyso_get_function_arity(expressionSo):
255
    """ Legacy function. See pobyso_get_function_arity_so_sa."""
256
    return(pobyso_get_function_arity_so_sa(expressionSo))
257

    
258
def pobyso_get_function_arity_so_sa(expressionSo):
259
    arity = c_int(0)
260
    sollya_lib_get_function_arity(byref(arity),expressionSo)
261
    return(int(arity.value))
262

    
263
def pobyso_get_head_function(expressionSo):
264
    """ Legacy function. See pobyso_get_head_function_so_sa. """
265
    return(pobyso_get_head_function_so_sa(expressionSo)) 
266

    
267
def pobyso_get_head_function_so_sa(expressionSo):
268
    functionType = c_int(0)
269
    sollya_lib_get_head_function(byref(functionType), expressionSo, None)
270
    return(int(functionType.value))
271

    
272
def pobyso_get_list_elements(soObj):
273
    """ Legacy function. See pobyso_get_list_elements_so_so. """
274
    return(pobyso_get_list_elements_so_so(soObj))
275
 
276
def pobyso_get_list_elements_so_so(soObj):
277
    # Type for array of pointers to sollya_obj_t
278
    listAddress = POINTER(c_longlong)()
279
    numElements = c_int(0)
280
    isEndElliptic = c_int(0)
281
    listAsList = []
282
    result = sollya_lib_get_list_elements(byref(listAddress),\
283
                                        byref(numElements),\
284
                                        byref(isEndElliptic),\
285
                                        soObj)
286
    if result == 0 :
287
        return None
288
    for i in xrange(0, numElements.value, 1):
289
        #print "address ", i, " ->", listAddress[i]
290
        listAsList.append(listAddress[i])
291
    return(listAsList, numElements.value, isEndElliptic.value)
292

    
293
def pobyso_get_max_prec_of_exp(soExp):
294
    """ Legacy function. See pobyso_get_max_prec_of_exp_so_sa. """
295
    return(pobyso_get_max_prec_of_exp_so_sa(soExp))
296

    
297
def pobyso_get_max_prec_of_exp_so_sa(soExp):
298
    """
299
    Get the maximum precision used for the numbers in a Sollya expression.
300
    TODO: 
301
    - error management;
302
    - correctly deal with numerical type such as DOUBLEEXTENDED.
303
    """
304
    maxPrecision = 0
305
    operator = pobyso_get_head_function_so_sa(soExp)
306
    if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \
307
    (operator != SOLLYA_BASE_FUNC_FREE_VARIABLE):
308
        (arity, subexpressions) = pobyso_get_subfunctions_so_sa(soExp)
309
        for i in xrange(arity):
310
            maxPrecisionCandidate = \
311
                pobyso_get_max_prec_of_exp_so_sa(subexpressions[i])
312
            if maxPrecisionCandidate > maxPrecision:
313
                maxPrecision = maxPrecisionCandidate
314
        return(maxPrecision)
315
    elif operator == SOLLYA_BASE_FUNC_CONSTANT:
316
        #print pobyso_get_prec_of_constant(soExp)
317
        return(pobyso_get_prec_of_constant_so_sa(soExp))
318
    elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE:
319
        return(0)
320
    else:
321
        print "pobyso_get_max_prec_of_exp_so_sa: unexepected operator."
322
        return(0)
323

    
324
def pobyso_get_sage_exp_from_sollya_exp(sollyaExp, realField = RR):
325
    """ Legacy function. See pobyso_get_sage_exp_from_sollya_exp_so_sa. """
326
    return(pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExp, realField = RR))
327

    
328
def pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExp, realField = RR):
329
    """
330
    Get a Sage expression from a Sollya expression. 
331
    Currently only tested with polynomials with floating-point coefficients.
332
    Notice that, in the returned polynomial, the exponents are RealNumbers.
333
    """
334
    #pobyso_autoprint(sollyaExp)
335
    operator = pobyso_get_head_function(sollyaExp)
336
    # Constants and the free variable are special cases.
337
    # All other operator are dealt with in the same way.
338
    if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \
339
       (operator != SOLLYA_BASE_FUNC_FREE_VARIABLE):
340
        (arity, subexpressions) = pobyso_get_subfunctions_so_sa(sollyaExp)
341
        if arity == 1:
342
            sageExp = eval(pobyso_function_type_as_string_so_sa(operator) + \
343
            "(" + pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], realField)\
344
             + ")")
345
        elif arity == 2:
346
            if operator == SOLLYA_BASE_FUNC_POW:
347
                operatorAsString = "**"
348
            else:
349
                operatorAsString = pobyso_function_type_as_string_so_sa(operator)
350
            sageExp = \
351
              eval("pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], realField)"\
352
              + " " + operatorAsString + " " + \
353
                   "pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[1], realField)")
354
        # We do not know yet how to deal with arity > 3 (is there any in Sollya anyway?).
355
        else:
356
            sageExp = eval('None')
357
        return(sageExp)
358
    elif operator == SOLLYA_BASE_FUNC_CONSTANT:
359
        #print "This is a constant"
360
        return pobyso_get_constant_as_rn_with_rf_so_sa(sollyaExp, realField)
361
    elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE:
362
        #print "This is free variable"
363
        return(eval(sollya_lib_get_free_variable_name()))
364
    else:
365
        print "Unexpected"
366
        return eval('None')
367
# End pobyso_get_sage_poly_from_sollya_poly
368
    
369
def pobyso_get_subfunctions(expressionSo):
370
    """ Legacy function. See pobyso_get_subfunctions_so_sa. """
371
    return(pobyso_get_subfunctions_so_sa(expressionSo)) 
372

    
373
def pobyso_get_subfunctions_so_sa(expressionSo):
374
    """
375
    Get the subfunctions of an expression.
376
    Return the number of subfunctions and the list of subfunctions addresses.
377
    Could not figure out another way than that ugly list of declarations
378
    to recover the addresses of the subfunctions.
379
    Arity is limited to 9.
380
    """
381
    subf0 = c_int(0)
382
    subf1 = c_int(0)
383
    subf2 = c_int(0)
384
    subf3 = c_int(0)
385
    subf4 = c_int(0)
386
    subf5 = c_int(0)
387
    subf6 = c_int(0)
388
    subf7 = c_int(0)
389
    subf8 = c_int(0)
390
    arity = c_int(0)
391
    nullPtr = POINTER(c_int)()
392
    sollya_lib_get_subfunctions(expressionSo, byref(arity), \
393
    byref(subf0), byref(subf1), byref(subf2), byref(subf3), byref(subf4), byref(subf5),\
394
     byref(subf6), byref(subf7), byref(subf8), nullPtr, None) 
395
#    byref(cast(subfunctions[0], POINTER(c_int))), byref(cast(subfunctions[0], POINTER(c_int))), \
396
#    byref(cast(subfunctions[2], POINTER(c_int))), byref(cast(subfunctions[3], POINTER(c_int))), \
397
#    byref(cast(subfunctions[4], POINTER(c_int))), byref(cast(subfunctions[5], POINTER(c_int))), \
398
#    byref(cast(subfunctions[6], POINTER(c_int))), byref(cast(subfunctions[7], POINTER(c_int))), \
399
#    byref(cast(subfunctions[8], POINTER(c_int))), nullPtr)
400
    subfunctions = [subf0, subf1, subf2, subf3, subf4, subf5, subf6, subf7, subf8]
401
    subs = []
402
    if arity.value > pobyso_max_arity:
403
        return(0,[])
404
    for i in xrange(arity.value):
405
        subs.append(int(subfunctions[i].value))
406
        #print subs[i]
407
    return(int(arity.value), subs)
408
    
409
def pobyso_get_prec():
410
    """ Legacy function. See pobyso_get_prec_so_sa(). """
411
    return(pobyso_get_prec_so_sa())
412

    
413
def pobyso_get_prec_so_sa():
414
    """
415
    Get the current default precision in Sollya.
416
    The return value is Sage/Python int.
417
    """
418
    retc = sollya_lib_get_prec(None)
419
    a = c_int(0)
420
    sollya_lib_get_constant_as_int(byref(a), retc)
421
    return(int(a.value))
422

    
423
def pobyso_get_prec_of_constant(ctExpSo):
424
    """ Legacy function. See pobyso_get_prec_of_constant_so_sa. """
425
    return(pobyso_get_prec_of_constant_so_sa(ctExpSo))
426

    
427
def pobyso_get_prec_of_constant_so_sa(ctExpSo):
428
    prec = c_int(0)
429
    retc = sollya_lib_get_prec_of_constant(byref(prec), ctExpSo, None)
430
    return(int(prec.value))
431

    
432
def pobyso_lib_init():
433
    sollya_lib_init(None)
434
    
435
def pobyso_name_free_variable(freeVariableName):
436
    """ Legacy function. See pobyso_name_free_variable_sa_so. """
437
    pobyso_name_free_variable_sa_so(freeVariableName)
438

    
439
def pobyso_name_free_variable_sa_so(freeVariableName):
440
    sollya_lib_name_free_variable(freeVariableName)
441

    
442
def pobyso_parse_string(string):
443
    """ Legacy function. See pobyso_parse_string_sa_so. """
444
    return(pobyso_parse_string_sa_so(string))
445
 
446
def pobyso_parse_string_sa_so(string):
447
    return(sollya_lib_parse_string(string))
448

    
449
def pobyso_range(rnLowerBound, rnUpperBound):
450
    """ Legacy function. See pobyso_range_sa_so. """
451
    pobyso_range_sa_so(rnLowerBound, rnUpperBound) 
452

    
453
def pobyso_range_sa_so(rnLowerBound, rnUpperBound):
454
    lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBound))
455
    upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBound))
456
    rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo)
457
    return(rangeSo)
458

    
459
def pobyso_remez_canonical(func, \
460
                           degree, \
461
                           lowerBound, \
462
                           upperBound, \
463
                           weight = "1", \
464
                           quality = None):
465
    """ Legacy function. See pobyso_remez_canonical_sa_so. """
466
def pobyso_remez_canonical_sa_so(func, \
467
                                 degree, \
468
                                 lowerBound, \
469
                                 upperBound, \
470
                                 weight = "1", \
471
                                 quality = None):
472
    """
473
    All arguments are Sage/Python.
474
    The weight function must be passed as string. A Sage function will fail.
475
    The return value is a pointer to a Sollya function.
476
    """
477
    if parent(func) == parent("string"):
478
        functionSo = sollya_lib_parse_string(func)
479
    else:
480
        return(None)
481
    degreeSo = pobyso_constant_from_int(degree)
482
    rangeSo = pobyso_range_sa_so(lowerBound, upperBound)
483
    weightSo = pobyso_parse_string_sa_so(weight)
484
    if not quality is None:
485
        qualitySo= pobyso_constant_sa_so(quality)
486
    return(sollya_lib_remez(functionSo, degreeSo, rangeSo, weightSo, qualitySo, None))
487
    
488
def pobyso_remez_canonical_so_so(funcSo, \
489
                                 degreeSo, \
490
                                 rangeSo, \
491
                                 weightSo = pobyso_constant_1_so_so(),\
492
                                 qualitySo = None):
493
    """
494
    All arguments are pointers to Sollya objects.
495
    The return value is a pointer to a Sollya function.
496
    """
497
    if not sollya_lib_obj_is_function(funcSo):
498
        return(None)
499
    return(sollya_lib_remez(funcSo, degreeSo, rangeSo, weightSo, qualitySo, None))
500
    
501
def pobyso_set_canonical_off():
502
    sollya_lib_set_canonical(sollya_lib_off())
503

    
504
def pobyso_set_canonical_on():
505
    sollya_lib_set_canonical(sollya_lib_on())
506

    
507
def pobyso_set_prec(p):
508
    """ Legacy function. See pobyso_set_prec_sa_so. """
509
    return( pobyso_set_prec_sa_so(p))
510

    
511
def pobyso_set_prec_sa_so(p):
512
    a = c_int(p)
513
    precSo = c_void_p(sollya_lib_constant_from_int(a))
514
    sollya_lib_set_prec(precSo)
515

    
516
def pobyso_taylor(function, degree, point):
517
    """ Legacy function. See pobysoTaylor_so_so. """
518
    return(pobyso_taylor_so_so(function, degree, point))
519

    
520
def pobyso_taylor_so_so(function, degree, point):
521
    return(sollya_lib_taylor(function, degree, point))
522
    
523
def pobyso_taylorform(function, degree, point = None, interval = None, errorType=None):
524
    """ Legacy function. See ;"""
525
    
526
def pobyso_taylorform_sa_sa(functionSa, \
527
                            degree, \
528
                            point = None, \
529
                            interval = None, \
530
                            errorType=None):
531
    """
532
    Compute the Taylor form of 'degree' for 'functionSa' at 'point' 
533
    for 'interval' with 'errorType'. 
534
    point: must be a Real or a Real interval.
535
    return the Taylor form as an array
536
    TODO: take care of the interval and of point when it is an interval;
537
          when errorType is not None;
538
          take care of the other elements of the Taylor form (coefficients errors and
539
          delta.
540
    """
541
    # Absolute as the default error.
542
    if errorType is None:
543
        errorTypeSo = sollya_lib_absolute()
544
    else:
545
        #TODO: deal with the other case.
546
        pass
547
    varSa = functionSa.variables()[0]
548
    pointBaseRingString = str(point.base_ring())
549
    if not re.search('Real', pointBaseRingString):
550
        return None
551
    # Call Sollya but first "sollyafy" the arguments.
552
    sollya_lib_init(None)
553
    pobyso_name_free_variable_sa_so(str(varSa))
554
    #pobyso_set_prec_sa_so(300)
555
    # Sollyafy the function.
556
    functionSo = pobyso_parse_string_sa_so(functionSa._assume_str())
557
    if sollya_lib_obj_is_error(functionSo):
558
        print "pobyso_tailorform: function string can't be parsed!"
559
        return None
560
    # Sollyafy the degree
561
    degreeSo = sollya_lib_constant_from_int(int(degree))
562
    # Sollyafy the point
563
    if not re.search('Interval', pointBaseRingString):
564
        pointSo  = pobyso_constant_sa_so(point)
565
    else:
566
        # TODO: deal with the interval case.
567
        pass
568
    # Call Sollya
569
    taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, pointSo, errorTypeSo,\
570
                                         None)
571
    (tfsAsList, numElements, isEndElliptic) = \
572
            pobyso_get_list_elements_so_so(taylorFormSo)
573
    polySo = tfsAsList[0]
574
    maxPrecision = pobyso_get_max_prec_of_exp_so_sa(polySo)
575
    polyRealField = RealField(maxPrecision)
576
    expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, polyRealField)
577
    sollya_lib_close()
578
    polynomialRing = polyRealField[str(varSa)]
579
    polySa = polynomial(expSa, polynomialRing)
580
    taylorFormSa = [polySa]
581
    return(taylorFormSa)                    
582

    
583
def pobyso_univar_polynomial_print_reverse(polySa):
584
    """ Legacy function. See pobyso_univar_polynomial_print_reverse_so_so. """
585
    return(pobyso_univar_polynomial_print_reverse_so_so(polySa))
586

    
587
def pobyso_univar_polynomial_print_reverse_so_so(polySa):
588
    """
589
    Return the string representation of a univariate polynomial with
590
    monomials ordered in the x^0..x^n order of the monomials.
591
    Remember: Sage
592
    """
593
    polynomialRing = polySa.base_ring()
594
    # A very expensive solution:
595
    # -create a fake multivariate polynomial field with only one variable,
596
    #   specifying a negative lexicographical order;
597
    mpolynomialRing = PolynomialRing(polynomialRing.base(), \
598
                                     polynomialRing.variable_name(), \
599
                                     1, order='neglex')
600
    # - convert the univariate argument polynomial into a multivariate
601
    #   version;
602
    p = mpolynomialRing(polySa)
603
    # - return the string representation of the converted form.
604
    # There is no simple str() method defined for p's class.
605
    return(p.__str__())
606
#
607
print "Superficial test of pobyso:"    
608
print pobyso_get_prec()  
609
pobyso_set_prec(165)
610
print pobyso_get_prec()  
611
a=100
612
print type(a)
613
id(a)
614
print "Max arity: ", pobyso_max_arity
615
print "Function tripleDouble (43) as a string: ", pobyso_function_type_as_string(43)
616
print "Function None (44) as a string: ", pobyso_function_type_as_string(44)