102 |
102 |
return(pobyso_constant_sa_so(rnArg))
|
103 |
103 |
|
104 |
104 |
def pobyso_constant_sa_so(rnArg):
|
|
105 |
"""
|
|
106 |
Create a Sollya constant from a RealNumber.
|
|
107 |
"""
|
105 |
108 |
return(sollya_lib_constant(get_rn_value(rnArg)))
|
106 |
109 |
|
107 |
110 |
def pobyso_constant_1():
|
108 |
111 |
""" Legacy function. See pobyso_constant_so_so. """
|
109 |
|
return(pobyso_constant_1_so_so())
|
|
112 |
return(pobyso_constant_1_sa_so())
|
110 |
113 |
|
111 |
|
def pobyso_constant_1_so_so():
|
|
114 |
def pobyso_constant_1_sa_so():
|
112 |
115 |
return(pobyso_constant_from_int_sa_so(1))
|
113 |
116 |
|
114 |
117 |
def pobyso_constant_from_int(anInt):
|
... | ... | |
223 |
226 |
pobyso_get_constant_so_sa(rnArg, soConst)
|
224 |
227 |
|
225 |
228 |
def pobyso_get_constant_so_sa(rnArg, soConst):
|
226 |
|
set_rn_value(rnArg, soConst)
|
|
229 |
"""
|
|
230 |
Set the value of rnArg to the value of soConst in MPFR_RNDN mode.
|
|
231 |
rnArg must already exist and belong to some RealField.
|
|
232 |
We assume that soConst points to a Sollya constant.
|
|
233 |
"""
|
|
234 |
sollya_lib_get_constant(get_rn_value(rnArg), soConst)
|
227 |
235 |
|
228 |
236 |
def pobyso_get_constant_as_rn(ctExp):
|
229 |
237 |
""" Legacy function. See pobyso_get_constant_as_rn_so_sa. """
|
230 |
238 |
return(pobyso_get_constant_as_rn_so_sa(ctExp))
|
231 |
239 |
|
232 |
|
def pobyso_get_constant_as_rn_so_sa(ctExp):
|
233 |
|
precision = pobyso_get_prec_of_constant(ctExp)
|
|
240 |
def pobyso_get_constant_as_rn_so_sa(constExp):
|
|
241 |
precision = pobyso_get_prec_of_constant(constExp)
|
234 |
242 |
RRRR = RealField(precision)
|
235 |
243 |
rn = RRRR(0)
|
236 |
|
sollya_lib_get_constant(get_rn_value(rn), ctExp)
|
|
244 |
sollya_lib_get_constant(get_rn_value(rn), constExp)
|
237 |
245 |
return(rn)
|
238 |
246 |
|
239 |
247 |
def pobyso_get_constant_as_rn_with_rf(ctExp, realField):
|
... | ... | |
300 |
308 |
def pobyso_get_max_prec_of_exp_so_sa(soExp):
|
301 |
309 |
"""
|
302 |
310 |
Get the maximum precision used for the numbers in a Sollya expression.
|
|
311 |
|
|
312 |
Arguments:
|
|
313 |
soExp -- a Sollya expression pointer
|
|
314 |
Return value:
|
|
315 |
A Python integer
|
303 |
316 |
TODO:
|
304 |
317 |
- error management;
|
305 |
318 |
- correctly deal with numerical type such as DOUBLEEXTENDED.
|
306 |
319 |
"""
|
307 |
320 |
maxPrecision = 0
|
308 |
|
currentPrecision = c_int(0)
|
|
321 |
minConstPrec = 0
|
|
322 |
currentConstPrec = 0
|
309 |
323 |
operator = pobyso_get_head_function_so_sa(soExp)
|
310 |
324 |
if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \
|
311 |
325 |
(operator != SOLLYA_BASE_FUNC_FREE_VARIABLE):
|
... | ... | |
317 |
331 |
maxPrecision = maxPrecisionCandidate
|
318 |
332 |
return(maxPrecision)
|
319 |
333 |
elif operator == SOLLYA_BASE_FUNC_CONSTANT:
|
320 |
|
sollya_lib_get_prec_of_constant(currentPrecision, soExp)
|
321 |
|
#sollya_lib_autoprint(soExp, None)
|
322 |
|
print currentPrecision
|
323 |
|
return(pobyso_get_prec_of_constant_so_sa(soExp))
|
|
334 |
minConstPrec = pobyso_get_min_prec_of_constant_so_sa(soExp)
|
|
335 |
#currentConstPrec = pobyso_get_min_prec_of_constant_so_sa(soExp)
|
|
336 |
#print minConstPrec, " - ", currentConstPrec
|
|
337 |
return(pobyso_get_min_prec_of_constant_so_sa(soExp))
|
|
338 |
|
324 |
339 |
elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE:
|
325 |
340 |
return(0)
|
326 |
341 |
else:
|
327 |
342 |
print "pobyso_get_max_prec_of_exp_so_sa: unexepected operator."
|
328 |
343 |
return(0)
|
329 |
344 |
|
|
345 |
def pobyso_get_min_prec_of_constant_so_sa(soConstExp):
|
|
346 |
"""
|
|
347 |
Get the minimum precision necessary to represent the value of a Sollya
|
|
348 |
constant.
|
|
349 |
MPFR_MIN_PREC and powers of 2 are taken into account.
|
|
350 |
We assume that soCteExp is a point
|
|
351 |
"""
|
|
352 |
constExpAsRn = pobyso_get_constant_as_rn_so_sa(soConstExp)
|
|
353 |
return(min_mpfr_size(get_rn_value(constExpAsRn)))
|
|
354 |
|
330 |
355 |
def pobyso_get_sage_exp_from_sollya_exp(sollyaExp, realField = RR):
|
331 |
356 |
""" Legacy function. See pobyso_get_sage_exp_from_sollya_exp_so_sa. """
|
332 |
357 |
return(pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExp, realField = RR))
|
... | ... | |
346 |
371 |
(arity, subexpressions) = pobyso_get_subfunctions_so_sa(sollyaExp)
|
347 |
372 |
if arity == 1:
|
348 |
373 |
sageExp = eval(pobyso_function_type_as_string_so_sa(operator) + \
|
349 |
|
"(" + pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], realField)\
|
350 |
|
+ ")")
|
|
374 |
"(" + pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], \
|
|
375 |
realField) + ")")
|
351 |
376 |
elif arity == 2:
|
352 |
377 |
if operator == SOLLYA_BASE_FUNC_POW:
|
353 |
378 |
operatorAsString = "**"
|
354 |
379 |
else:
|
355 |
|
operatorAsString = pobyso_function_type_as_string_so_sa(operator)
|
|
380 |
operatorAsString = \
|
|
381 |
pobyso_function_type_as_string_so_sa(operator)
|
356 |
382 |
sageExp = \
|
357 |
383 |
eval("pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], realField)"\
|
358 |
384 |
+ " " + operatorAsString + " " + \
|
... | ... | |
462 |
488 |
rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo)
|
463 |
489 |
return(rangeSo)
|
464 |
490 |
|
|
491 |
def pobyso_remez_canonical_sa_sa(func, \
|
|
492 |
degree, \
|
|
493 |
lowerBound, \
|
|
494 |
upperBound, \
|
|
495 |
weight = None, \
|
|
496 |
quality = None):
|
|
497 |
"""
|
|
498 |
All arguments are Sage/Python.
|
|
499 |
The functions (func and weight) must be passed as expressions or strings.
|
|
500 |
Otherwise the function fails.
|
|
501 |
The return value is a pointer is a Sage polynomial.
|
|
502 |
"""
|
|
503 |
var('zorglub') # Dummy variable name for type check only.
|
|
504 |
polySo = pobyso_remez_canonical_sa_so(func, \
|
|
505 |
degree, \
|
|
506 |
lowerBound, \
|
|
507 |
upperBound, \
|
|
508 |
weight = None, \
|
|
509 |
quality = None)
|
|
510 |
if parent(func) == parent("string"):
|
|
511 |
functionSa = eval(func)
|
|
512 |
# Expression test.
|
|
513 |
elif type(func) == type(zorglub):
|
|
514 |
functionSa = func
|
|
515 |
maxPrecision = 0
|
|
516 |
if polySo is None:
|
|
517 |
return(None)
|
|
518 |
maxPrecision = pobyso_get_max_prec_of_exp_so_sa(polySo)
|
|
519 |
RRRR = RealField(maxPrecision)
|
|
520 |
polynomialRing = RRRR[functionSa.variables()[0]]
|
|
521 |
expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, RRRR)
|
|
522 |
polySa = polynomial(expSa, polynomialRing)
|
|
523 |
return(polySa)
|
|
524 |
|
465 |
525 |
def pobyso_remez_canonical(func, \
|
466 |
526 |
degree, \
|
467 |
527 |
lowerBound, \
|
... | ... | |
479 |
539 |
degree, \
|
480 |
540 |
lowerBound, \
|
481 |
541 |
upperBound, \
|
482 |
|
weight = "1", \
|
|
542 |
weight = None, \
|
483 |
543 |
quality = None):
|
484 |
544 |
"""
|
485 |
545 |
All arguments are Sage/Python.
|
... | ... | |
487 |
547 |
Otherwise the function fails.
|
488 |
548 |
The return value is a pointer to a Sollya function.
|
489 |
549 |
"""
|
490 |
|
var('zorglub')
|
|
550 |
var('zorglub') # Dummy variable name for type check only.
|
|
551 |
currentVariableName = None
|
|
552 |
# The func argument can be of different types (string,
|
|
553 |
# symbolic expression...)
|
491 |
554 |
if parent(func) == parent("string"):
|
492 |
555 |
functionSo = sollya_lib_parse_string(func)
|
493 |
556 |
# Expression test.
|
494 |
|
elif type(func) == type(zorglub):
|
495 |
|
functionSo = sollya_lib_parse_string_sa_so(func._assume_str())
|
|
557 |
elif type(func) == type(zorglub):
|
|
558 |
# Until we are able to translate Sage expressions into Sollya
|
|
559 |
# expressions : parse the string version.
|
|
560 |
currentVariableName = func.variables()[0]
|
|
561 |
sollya_lib_name_free_variable(str(currentVariableName))
|
|
562 |
functionSo = sollya_lib_parse_string(func._assume_str())
|
496 |
563 |
else:
|
497 |
564 |
return(None)
|
498 |
|
if parent(weight) == parent("string"):
|
|
565 |
if weight is None:
|
|
566 |
weightSo = pobyso_constant_1_sa_so()
|
|
567 |
elif parent(weight) == parent("string"):
|
499 |
568 |
weightSo = sollya_lib_parse_string(func)
|
500 |
569 |
elif type(weight) == type(zorglub):
|
501 |
570 |
functionSo = sollya_lib_parse_string_sa_so(weight._assume_str())
|
... | ... | |
505 |
574 |
rangeSo = pobyso_range_sa_so(lowerBound, upperBound)
|
506 |
575 |
if not quality is None:
|
507 |
576 |
qualitySo= pobyso_constant_sa_so(quality)
|
508 |
|
return(sollya_lib_remez(functionSo, degreeSo, rangeSo, weightSo, qualitySo, None))
|
|
577 |
else:
|
|
578 |
qualitySo = None
|
|
579 |
return(sollya_lib_remez(functionSo, \
|
|
580 |
degreeSo, \
|
|
581 |
rangeSo, \
|
|
582 |
weightSo, \
|
|
583 |
qualitySo, \
|
|
584 |
None))
|
509 |
585 |
|
510 |
586 |
def pobyso_remez_canonical_so_so(funcSo, \
|
511 |
587 |
degreeSo, \
|
512 |
588 |
rangeSo, \
|
513 |
|
weightSo = pobyso_constant_1_so_so(),\
|
|
589 |
weightSo = pobyso_constant_1_sa_so(),\
|
514 |
590 |
qualitySo = None):
|
515 |
591 |
"""
|
516 |
592 |
All arguments are pointers to Sollya objects.
|