13 |
13 |
-memory management.
|
14 |
14 |
"""
|
15 |
15 |
from ctypes import *
|
|
16 |
import re
|
|
17 |
from sage.symbolic.expression_conversions import polynomial
|
16 |
18 |
|
17 |
19 |
(SOLLYA_BASE_FUNC_ABS,
|
18 |
20 |
SOLLYA_BASE_FUNC_ACOS,
|
... | ... | |
332 |
334 |
retc = sollya_lib_get_prec_of_constant(byref(prec), ctExp, None)
|
333 |
335 |
return(int(prec.value))
|
334 |
336 |
|
|
337 |
def pobyso_lib_init():
|
|
338 |
sollya_lib_init(None)
|
|
339 |
|
|
340 |
def pobyso_name_free_variable(freeVariableName):
|
|
341 |
sollya_lib_name_free_variable(freeVariableName)
|
|
342 |
|
335 |
343 |
def pobyso_parse_string(string):
|
336 |
344 |
return(sollya_lib_parse_string(string))
|
337 |
345 |
|
338 |
|
def pobyso_univar_polynomial_print_reverse(polySa):
|
339 |
|
"""
|
340 |
|
Return the string representation of a univariate polynomial with
|
341 |
|
monomial ordered in the x^0..x^n order of the monomials.
|
342 |
|
Remember: Sage
|
343 |
|
"""
|
344 |
|
polynomialRing = polySa.base_ring()
|
345 |
|
# A very expensive solution:
|
346 |
|
# -create a fake multivariate polynomial field with only one variable,
|
347 |
|
# specifying a negative lexicographical order;
|
348 |
|
mpolynomialRing = PolynomialRing(polynomialRing.base(), \
|
349 |
|
polynomialRing.variable_name(), \
|
350 |
|
1, order='neglex')
|
351 |
|
# - convert the univariate argument polynomial into a multivariate
|
352 |
|
# version;
|
353 |
|
p = mpolynomialRing(polySa)
|
354 |
|
# - return the string representation of the converted form.
|
355 |
|
# There is no simple str() method defined for p's class.
|
356 |
|
return(p.__str__())
|
357 |
|
|
358 |
346 |
def pobyso_range(rnLowerBound, rnUpperBound):
|
359 |
347 |
lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBound))
|
360 |
348 |
upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBound))
|
... | ... | |
391 |
379 |
def pobyso_taylor(function, degree, point):
|
392 |
380 |
return(sollya_lib_taylor(function, degree, point))
|
393 |
381 |
|
|
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.
|
394 |
386 |
def pobyso_taylorform(function, degree, point = None, interval = None, errorType=None):
|
|
387 |
"""
|
|
388 |
Compute the Taylor form of 'degre' for 'function' at 'point'
|
|
389 |
for 'interval' with 'errorType'.
|
|
390 |
point: must be a Real or a Real interval.
|
|
391 |
return the Taylor form as an array
|
|
392 |
"""
|
|
393 |
# Absolute as the default error.
|
395 |
394 |
if errorType is None:
|
396 |
|
errorType = sollya_lib_absolute()
|
397 |
|
return(sollya_lib_taylorform(function, degree, point, errorType, None))
|
|
395 |
errorTypeSo = sollya_lib_absolute()
|
|
396 |
else:
|
|
397 |
#TODO: deal with the other case.
|
|
398 |
pass
|
|
399 |
varSa = function.variables()[0]
|
|
400 |
pointBaseRingString = str(point.base_ring())
|
|
401 |
if not re.search('Real', pointBaseRingString):
|
|
402 |
return None
|
|
403 |
# Call Sollya but first "sollyafy" the arguments.
|
|
404 |
sollya_lib_init(None)
|
|
405 |
pobyso_name_free_variable(str(varSa))
|
|
406 |
# Sollyafy the function.
|
|
407 |
functionSo = pobyso_parse_string(function._assume_str())
|
|
408 |
if sollya_lib_obj_is_error(functionSo):
|
|
409 |
print "pobyso_tailorform: function string can't be parsed!"
|
|
410 |
return None
|
|
411 |
# Sollyafy the degree
|
|
412 |
degreeSo = sollya_lib_constant_from_int(int(degree))
|
|
413 |
# Sollyafy the point
|
|
414 |
if not re.search('Interval', pointBaseRingString):
|
|
415 |
pointSo = pobyso_constant(point)
|
|
416 |
else:
|
|
417 |
# TODO: deal with the interval case.
|
|
418 |
pass
|
|
419 |
# Call Sollya
|
|
420 |
taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, pointSo, errorTypeSo,\
|
|
421 |
None)
|
|
422 |
(tfsAsList, numElements, isEndElliptic) = pobyso_get_list_elements(taylorFormSo)
|
|
423 |
polySo = tfsAsList[0]
|
|
424 |
maxPrecision = pobyso_get_max_prec_of_exp(polySo)
|
|
425 |
polyRealField = RealField(maxPrecision)
|
|
426 |
expSa = pobyso_get_sage_exp_from_sollya_exp(polySo, polyRealField)
|
|
427 |
sollya_lib_close()
|
|
428 |
polynomialRing = polyRealField[str(varSa)]
|
|
429 |
polySa = polynomial(expSa, polynomialRing)
|
|
430 |
taylorFormSa = [polySa]
|
|
431 |
return(taylorFormSa)
|
|
432 |
|
|
433 |
def pobyso_univar_polynomial_print_reverse(polySa):
|
|
434 |
"""
|
|
435 |
Return the string representation of a univariate polynomial with
|
|
436 |
monomial ordered in the x^0..x^n order of the monomials.
|
|
437 |
Remember: Sage
|
|
438 |
"""
|
|
439 |
polynomialRing = polySa.base_ring()
|
|
440 |
# A very expensive solution:
|
|
441 |
# -create a fake multivariate polynomial field with only one variable,
|
|
442 |
# specifying a negative lexicographical order;
|
|
443 |
mpolynomialRing = PolynomialRing(polynomialRing.base(), \
|
|
444 |
polynomialRing.variable_name(), \
|
|
445 |
1, order='neglex')
|
|
446 |
# - convert the univariate argument polynomial into a multivariate
|
|
447 |
# version;
|
|
448 |
p = mpolynomialRing(polySa)
|
|
449 |
# - return the string representation of the converted form.
|
|
450 |
# There is no simple str() method defined for p's class.
|
|
451 |
return(p.__str__())
|
398 |
452 |
#
|
399 |
453 |
print "Superficial test of pobyso:"
|
400 |
454 |
print pobyso_get_prec()
|