Révision 38 pobysoPythonSage/src/pobyso.py
pobyso.py (revision 38) | ||
---|---|---|
5 | 5 |
Command line syntax: |
6 | 6 |
use from Sage (via the "load" or the "attach" commands) |
7 | 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. |
|
8 | 19 |
NOTES: |
9 | 20 |
Reported errors in Eclipse come from the calls to |
10 | 21 |
the Sollya library |
... | ... | |
15 | 26 |
from ctypes import * |
16 | 27 |
import re |
17 | 28 |
from sage.symbolic.expression_conversions import polynomial |
18 |
|
|
29 |
""" |
|
30 |
Create the equivalent to an enum for the Sollya function types. |
|
31 |
""" |
|
19 | 32 |
(SOLLYA_BASE_FUNC_ABS, |
20 | 33 |
SOLLYA_BASE_FUNC_ACOS, |
21 | 34 |
SOLLYA_BASE_FUNC_ACOSH, |
... | ... | |
68 | 81 |
def pobyso_autoprint(arg): |
69 | 82 |
sollya_lib_autoprint(arg,None) |
70 | 83 |
|
84 |
def pobyso_autoprint_so_so(arg): |
|
85 |
sollya_lib_autoprint(arg,None) |
|
86 |
|
|
71 | 87 |
def pobyso_cmp(rnArg, soCte): |
72 | 88 |
precisionOfCte = c_int(0) |
73 | 89 |
# From the Sollya constant, create a local Sage RealNumber. |
... | ... | |
81 | 97 |
return(cmp_rn_value(rnArg, rnLocal)) |
82 | 98 |
|
83 | 99 |
def pobyso_constant(rnArg): |
84 |
return (sollya_lib_constant(get_rn_value(rnArg))) |
|
100 |
""" Legacy function. See pobyso_constant_sa_so. """ |
|
101 |
return(pobyso_constant_sa_so(rnArg)) |
|
85 | 102 |
|
103 |
def pobyso_constant_sa_so(rnArg): |
|
104 |
return(sollya_lib_constant(get_rn_value(rnArg))) |
|
105 |
|
|
86 | 106 |
def pobyso_constant_1(): |
87 |
return(pobyso_constant_from_int(1)) |
|
107 |
""" Legacy function. See pobyso_constant_so_so. """ |
|
108 |
return(pobyso_constant_1_so_so()) |
|
88 | 109 |
|
110 |
def pobyso_constant_1_so_so(): |
|
111 |
return(pobyso_constant_from_int_sa_so(1)) |
|
112 |
|
|
89 | 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): |
|
90 | 118 |
return(sollya_lib_constant_from_int(int(anInt))) |
91 | 119 |
|
92 |
# Numeric Sollya function codes -> Sage mathematical function names |
|
93 | 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 |
""" |
|
94 | 129 |
if funcType == SOLLYA_BASE_FUNC_ABS: |
95 | 130 |
return "abs" |
96 | 131 |
elif funcType == SOLLYA_BASE_FUNC_ACOS: |
... | ... | |
183 | 218 |
return None |
184 | 219 |
|
185 | 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): |
|
186 | 225 |
set_rn_value(rnArg, soConst) |
187 | 226 |
|
188 | 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): |
|
189 | 232 |
precision = pobyso_get_prec_of_constant(ctExp) |
190 | 233 |
RRRR = RealField(precision) |
191 | 234 |
rn = RRRR(0) |
192 | 235 |
sollya_lib_get_constant(get_rn_value(rn), ctExp) |
193 | 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)) |
|
194 | 241 |
|
195 |
def pobyso_get_constant_as_rn_with_rf(ctExp, realField): |
|
242 |
def pobyso_get_constant_as_rn_with_rf_so_sa(ctExp, realField):
|
|
196 | 243 |
rn = realField(0) |
197 | 244 |
sollya_lib_get_constant(get_rn_value(rn), ctExp) |
198 | 245 |
return(rn) |
246 |
|
|
199 | 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(): |
|
200 | 252 |
return(sollya_lib_get_free_variable_name()) |
201 | 253 |
|
202 |
def pobyso_get_function_arity(expression): |
|
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): |
|
203 | 259 |
arity = c_int(0) |
204 |
sollya_lib_get_function_arity(byref(arity),expression) |
|
260 |
sollya_lib_get_function_arity(byref(arity),expressionSo)
|
|
205 | 261 |
return(int(arity.value)) |
206 | 262 |
|
207 |
def pobyso_get_head_function(expression): |
|
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): |
|
208 | 268 |
functionType = c_int(0) |
209 |
sollya_lib_get_head_function(byref(functionType), expression, None) |
|
269 |
sollya_lib_get_head_function(byref(functionType), expressionSo, None)
|
|
210 | 270 |
return(int(functionType.value)) |
211 | 271 |
|
212 | 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): |
|
213 | 277 |
# Type for array of pointers to sollya_obj_t |
214 | 278 |
listAddress = POINTER(c_longlong)() |
215 | 279 |
numElements = c_int(0) |
... | ... | |
222 | 286 |
if result == 0 : |
223 | 287 |
return None |
224 | 288 |
for i in xrange(0, numElements.value, 1): |
225 |
print "address ", i, " ->", listAddress[i] |
|
289 |
#print "address ", i, " ->", listAddress[i]
|
|
226 | 290 |
listAsList.append(listAddress[i]) |
227 | 291 |
return(listAsList, numElements.value, isEndElliptic.value) |
228 | 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)) |
|
229 | 296 |
|
230 |
# Get the maximum precision used for the numbers in a |
|
231 |
# Sollya expression. |
|
232 |
# ToDo: |
|
233 |
# - error management; |
|
234 |
# - correctly deal with numerical type such as DOUBLEEXTENDED. |
|
235 |
def pobyso_get_max_prec_of_exp(soExp): |
|
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 |
""" |
|
236 | 304 |
maxPrecision = 0 |
237 |
operator = pobyso_get_head_function(soExp) |
|
305 |
operator = pobyso_get_head_function_so_sa(soExp)
|
|
238 | 306 |
if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \ |
239 | 307 |
(operator != SOLLYA_BASE_FUNC_FREE_VARIABLE): |
240 |
(arity, subexpressions) = pobyso_get_subfunctions(soExp) |
|
308 |
(arity, subexpressions) = pobyso_get_subfunctions_so_sa(soExp)
|
|
241 | 309 |
for i in xrange(arity): |
242 | 310 |
maxPrecisionCandidate = \ |
243 |
pobyso_get_max_prec_of_exp(subexpressions[i])
|
|
311 |
pobyso_get_max_prec_of_exp_so_sa(subexpressions[i])
|
|
244 | 312 |
if maxPrecisionCandidate > maxPrecision: |
245 | 313 |
maxPrecision = maxPrecisionCandidate |
246 | 314 |
return(maxPrecision) |
247 | 315 |
elif operator == SOLLYA_BASE_FUNC_CONSTANT: |
248 | 316 |
#print pobyso_get_prec_of_constant(soExp) |
249 |
return(pobyso_get_prec_of_constant(soExp)) |
|
317 |
return(pobyso_get_prec_of_constant_so_sa(soExp))
|
|
250 | 318 |
elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE: |
251 | 319 |
return(0) |
252 | 320 |
else: |
253 |
print "pobyso_get_max_prec_of_exp: unexepected operator." |
|
321 |
print "pobyso_get_max_prec_of_exp_so_sa: unexepected operator."
|
|
254 | 322 |
return(0) |
255 | 323 |
|
256 | 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): |
|
257 | 329 |
""" |
258 |
Get a Sage expression from a Sollya expression, currently only tested
|
|
259 |
with polynomials with floating-point coefficients. |
|
330 |
Get a Sage expression from a Sollya expression.
|
|
331 |
Currently only tested with polynomials with floating-point coefficients.
|
|
260 | 332 |
Notice that, in the returned polynomial, the exponents are RealNumbers. |
261 | 333 |
""" |
262 | 334 |
#pobyso_autoprint(sollyaExp) |
... | ... | |
265 | 337 |
# All other operator are dealt with in the same way. |
266 | 338 |
if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \ |
267 | 339 |
(operator != SOLLYA_BASE_FUNC_FREE_VARIABLE): |
268 |
(arity, subexpressions) = pobyso_get_subfunctions(sollyaExp) |
|
340 |
(arity, subexpressions) = pobyso_get_subfunctions_so_sa(sollyaExp)
|
|
269 | 341 |
if arity == 1: |
270 |
sageExp = eval(pobyso_function_type_as_string(operator) + \ |
|
271 |
"(" + pobyso_get_sage_exp_from_sollya_exp(subexpressions[0], realField)\ |
|
342 |
sageExp = eval(pobyso_function_type_as_string_so_sa(operator) + \
|
|
343 |
"(" + pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], realField)\
|
|
272 | 344 |
+ ")") |
273 | 345 |
elif arity == 2: |
274 | 346 |
if operator == SOLLYA_BASE_FUNC_POW: |
275 | 347 |
operatorAsString = "**" |
276 | 348 |
else: |
277 |
operatorAsString = pobyso_function_type_as_string(operator) |
|
349 |
operatorAsString = pobyso_function_type_as_string_so_sa(operator)
|
|
278 | 350 |
sageExp = \ |
279 |
eval("pobyso_get_sage_exp_from_sollya_exp(subexpressions[0], realField)"\ |
|
351 |
eval("pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], realField)"\
|
|
280 | 352 |
+ " " + operatorAsString + " " + \ |
281 |
"pobyso_get_sage_exp_from_sollya_exp(subexpressions[1], realField)") |
|
353 |
"pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[1], realField)")
|
|
282 | 354 |
# We do not know yet how to deal with arity > 3 (is there any in Sollya anyway?). |
283 | 355 |
else: |
284 | 356 |
sageExp = eval('None') |
285 | 357 |
return(sageExp) |
286 | 358 |
elif operator == SOLLYA_BASE_FUNC_CONSTANT: |
287 | 359 |
#print "This is a constant" |
288 |
return pobyso_get_constant_as_rn_with_rf(sollyaExp, realField) |
|
360 |
return pobyso_get_constant_as_rn_with_rf_so_sa(sollyaExp, realField)
|
|
289 | 361 |
elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE: |
290 | 362 |
#print "This is free variable" |
291 | 363 |
return(eval(sollya_lib_get_free_variable_name())) |
... | ... | |
294 | 366 |
return eval('None') |
295 | 367 |
# End pobyso_get_sage_poly_from_sollya_poly |
296 | 368 |
|
297 |
def pobyso_get_subfunctions(expression): |
|
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 |
""" |
|
298 | 381 |
subf0 = c_int(0) |
299 | 382 |
subf1 = c_int(0) |
300 | 383 |
subf2 = c_int(0) |
... | ... | |
306 | 389 |
subf8 = c_int(0) |
307 | 390 |
arity = c_int(0) |
308 | 391 |
nullPtr = POINTER(c_int)() |
309 |
sollya_lib_get_subfunctions(expression, byref(arity), \ |
|
392 |
sollya_lib_get_subfunctions(expressionSo, byref(arity), \
|
|
310 | 393 |
byref(subf0), byref(subf1), byref(subf2), byref(subf3), byref(subf4), byref(subf5),\ |
311 | 394 |
byref(subf6), byref(subf7), byref(subf8), nullPtr, None) |
312 | 395 |
# byref(cast(subfunctions[0], POINTER(c_int))), byref(cast(subfunctions[0], POINTER(c_int))), \ |
... | ... | |
317 | 400 |
subfunctions = [subf0, subf1, subf2, subf3, subf4, subf5, subf6, subf7, subf8] |
318 | 401 |
subs = [] |
319 | 402 |
if arity.value > pobyso_max_arity: |
320 |
return(None,None)
|
|
403 |
return(0,[])
|
|
321 | 404 |
for i in xrange(arity.value): |
322 | 405 |
subs.append(int(subfunctions[i].value)) |
323 | 406 |
#print subs[i] |
324 | 407 |
return(int(arity.value), subs) |
325 | 408 |
|
326 | 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 |
""" |
|
327 | 418 |
retc = sollya_lib_get_prec(None) |
328 | 419 |
a = c_int(0) |
329 | 420 |
sollya_lib_get_constant_as_int(byref(a), retc) |
330 | 421 |
return(int(a.value)) |
331 | 422 |
|
332 |
def pobyso_get_prec_of_constant(ctExp): |
|
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): |
|
333 | 428 |
prec = c_int(0) |
334 |
retc = sollya_lib_get_prec_of_constant(byref(prec), ctExp, None) |
|
429 |
retc = sollya_lib_get_prec_of_constant(byref(prec), ctExpSo, None)
|
|
335 | 430 |
return(int(prec.value)) |
336 | 431 |
|
337 | 432 |
def pobyso_lib_init(): |
338 | 433 |
sollya_lib_init(None) |
339 | 434 |
|
340 | 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): |
|
341 | 440 |
sollya_lib_name_free_variable(freeVariableName) |
342 | 441 |
|
343 | 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): |
|
344 | 447 |
return(sollya_lib_parse_string(string)) |
345 | 448 |
|
346 | 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): |
|
347 | 454 |
lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBound)) |
348 | 455 |
upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBound)) |
349 | 456 |
rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo) |
350 | 457 |
return(rangeSo) |
351 | 458 |
|
352 |
def pobyso_remez_canonical(function, \
|
|
459 |
def pobyso_remez_canonical(func, \ |
|
353 | 460 |
degree, \ |
354 | 461 |
lowerBound, \ |
355 | 462 |
upperBound, \ |
356 |
weightSo = pobyso_constant_1(),
|
|
463 |
weight = "1", \
|
|
357 | 464 |
quality = None): |
358 |
if parent(function) == parent("string"): |
|
359 |
functionSo = sollya_lib_parse_string(function) |
|
360 |
# print "Is string!" |
|
361 |
elif sollya_lib_obj_is_function(function): |
|
362 |
functionSo = function |
|
363 |
# print "Is Function!" |
|
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) |
|
364 | 481 |
degreeSo = pobyso_constant_from_int(degree) |
365 |
rangeSo = pobyso_range(lowerBound, upperBound) |
|
366 |
return(sollya_lib_remez(functionSo, degreeSo, rangeSo, quality, None)) |
|
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)) |
|
367 | 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 |
|
|
368 | 501 |
def pobyso_set_canonical_off(): |
369 | 502 |
sollya_lib_set_canonical(sollya_lib_off()) |
370 | 503 |
|
... | ... | |
372 | 505 |
sollya_lib_set_canonical(sollya_lib_on()) |
373 | 506 |
|
374 | 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): |
|
375 | 512 |
a = c_int(p) |
376 | 513 |
precSo = c_void_p(sollya_lib_constant_from_int(a)) |
377 | 514 |
sollya_lib_set_prec(precSo) |
378 | 515 |
|
379 | 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): |
|
380 | 521 |
return(sollya_lib_taylor(function, degree, point)) |
381 | 522 |
|
382 |
# TODO: take care of the interval and of point when it is an interval; |
|
383 |
# when errorType is not None; |
|
384 |
# take care of the other elements of the Taylor form (coefficients errors and |
|
385 |
# delta. |
|
386 | 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): |
|
387 | 531 |
""" |
388 |
Compute the Taylor form of 'degre' for 'function' at 'point'
|
|
532 |
Compute the Taylor form of 'degree' for 'functionSa' at 'point'
|
|
389 | 533 |
for 'interval' with 'errorType'. |
390 | 534 |
point: must be a Real or a Real interval. |
391 | 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. |
|
392 | 540 |
""" |
393 | 541 |
# Absolute as the default error. |
394 | 542 |
if errorType is None: |
... | ... | |
396 | 544 |
else: |
397 | 545 |
#TODO: deal with the other case. |
398 | 546 |
pass |
399 |
varSa = function.variables()[0] |
|
547 |
varSa = functionSa.variables()[0]
|
|
400 | 548 |
pointBaseRingString = str(point.base_ring()) |
401 | 549 |
if not re.search('Real', pointBaseRingString): |
402 | 550 |
return None |
403 | 551 |
# Call Sollya but first "sollyafy" the arguments. |
404 | 552 |
sollya_lib_init(None) |
405 |
pobyso_name_free_variable(str(varSa)) |
|
553 |
pobyso_name_free_variable_sa_so(str(varSa)) |
|
554 |
#pobyso_set_prec_sa_so(300) |
|
406 | 555 |
# Sollyafy the function. |
407 |
functionSo = pobyso_parse_string(function._assume_str())
|
|
556 |
functionSo = pobyso_parse_string_sa_so(functionSa._assume_str())
|
|
408 | 557 |
if sollya_lib_obj_is_error(functionSo): |
409 | 558 |
print "pobyso_tailorform: function string can't be parsed!" |
410 | 559 |
return None |
... | ... | |
412 | 561 |
degreeSo = sollya_lib_constant_from_int(int(degree)) |
413 | 562 |
# Sollyafy the point |
414 | 563 |
if not re.search('Interval', pointBaseRingString): |
415 |
pointSo = pobyso_constant(point) |
|
564 |
pointSo = pobyso_constant_sa_so(point)
|
|
416 | 565 |
else: |
417 | 566 |
# TODO: deal with the interval case. |
418 | 567 |
pass |
419 | 568 |
# Call Sollya |
420 | 569 |
taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, pointSo, errorTypeSo,\ |
421 | 570 |
None) |
422 |
(tfsAsList, numElements, isEndElliptic) = pobyso_get_list_elements(taylorFormSo) |
|
571 |
(tfsAsList, numElements, isEndElliptic) = \ |
|
572 |
pobyso_get_list_elements_so_so(taylorFormSo) |
|
423 | 573 |
polySo = tfsAsList[0] |
424 |
maxPrecision = pobyso_get_max_prec_of_exp(polySo) |
|
574 |
maxPrecision = pobyso_get_max_prec_of_exp_so_sa(polySo)
|
|
425 | 575 |
polyRealField = RealField(maxPrecision) |
426 |
expSa = pobyso_get_sage_exp_from_sollya_exp(polySo, polyRealField) |
|
576 |
expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, polyRealField)
|
|
427 | 577 |
sollya_lib_close() |
428 | 578 |
polynomialRing = polyRealField[str(varSa)] |
429 | 579 |
polySa = polynomial(expSa, polynomialRing) |
... | ... | |
431 | 581 |
return(taylorFormSa) |
432 | 582 |
|
433 | 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): |
|
434 | 588 |
""" |
435 | 589 |
Return the string representation of a univariate polynomial with |
436 |
monomial ordered in the x^0..x^n order of the monomials. |
|
590 |
monomials ordered in the x^0..x^n order of the monomials.
|
|
437 | 591 |
Remember: Sage |
438 | 592 |
""" |
439 | 593 |
polynomialRing = polySa.base_ring() |
Formats disponibles : Unified diff