Révision 209

pobysoPythonSage/src/pobyso.py (revision 209)
1 1
"""
2
@file pobyso.py
2 3
Actual functions to use in Sage
3 4
ST 2012-11-13
4 5

  
......
228 229
def pobyso_constant_sa_so(rnArgSa, precisionSa=None):
229 230
    """
230 231
    Create a Sollya constant from a Sage RealNumber.
232
    The sollya_lib_constant() function creates a constant
233
    with the same precision as the source.
231 234
    """
232
    # Precision stuff
233
    if precisionSa is None:
234
        precisionSa = rnArgSa.parent().precision()
235
    currentSollyaPrecisionSo = sollya_lib_get_prec()
236
    currentSollyaPrecisionSa = \
237
        pobyso_constant_from_int(currentSollyaPrecisionSo)
235
    ## Precision stuff. If one wants to change precisions,
236
    #  everything takes place in Sage. That only makes
237
    #  sense if one wants to reduce the precision.
238
    if not precisionSa is None:
239
        RRR = RealField(precisionSa)
240
        rnArgSa = RRR(rnArgSa)
241
    #print rnArgSa, rnArgSa.precision()
238 242
    # Sollya constant creation takes place here.
239
    if precisionSa > currentSollyaPrecisionSa:
240
        pobyso_set_prec_sa_so(precisionSa)
241
        constantSo = sollya_lib_constant(get_rn_value(rnArgSa))
242
        pobyso_set_prec_so_so(currentSollyaPrecisionSo)
243
    else:
244
        constantSo = sollya_lib_constant(get_rn_value(rnArgSa))
245
    sollya_lib_clear_obj(currentSollyaPrecisionSo)
246
    return constantSo
243
    return sollya_lib_constant(get_rn_value(rnArgSa))
247 244
# End pobyso_constant_sa_so
248 245
     
249 246
def pobyso_constant_0_sa_so():
......
285 282
    return(constSa.value)
286 283
# End pobyso_constant_from_int_so_sa
287 284

  
288
def pobyso_constant_from_mpq_sa_so(rationalSa, precision = None):
285
def pobyso_constant_from_mpq_sa_so(rationalSa):
289 286
    """
290 287
    Make a Sollya constant from Sage rational.
291
    A bit convoluted to take into account precision and the fact
292
    that mpq constants in Sollya a non-evaluated expressions.
293
    Function building and evaluation is needed to make it a "real"
294
    evaluated constant.
288
    The Sollya constant is an unevaluated expression.
289
    Hence no precision argument is needed.
290
    It is better to leave this way since Sollya has its own
291
    optimized evaluation mecanism that tries very hard to
292
    return exact values or at least faithful ones.
295 293
    """
296
    ## Deal with precision stuff.
297
    curPrecSa = None
298
    curPrecSo = None
299
    if not precision is None:
300
        curPrecSo = pobyso_get_prec_so()
301
        curPrecSaSa = c_int(0)
302
        sollya_lib_get_constant_as_int(byref(curPrecSaSa), curPrecSo)
303
        curPrecSa = int(curPrecSaSa.value)
304
        if curPrecSa != precision:
305
            pobyso_set_prec_sa_so(precision)
306
    ## In Sollya mpq constants are non-evaluated expressions.
307
    #  We must force evaluation.
308
    zeroSo    = pobyso_constant_0_sa_so()
309
    oneSo     = pobyso_constant_1_sa_so()
310 294
    ratExprSo = \
311 295
        sollya_lib_constant_from_mpq(sgmp_get_rational_value(rationalSa))
312
    addExprSo = sollya_lib_build_function_add(zeroSo, ratExprSo)
313
    constSo   = sollya_lib_evaluate(addExprSo,oneSo)
314
    ## Clears expression and arguments, as the former was created with a
315
    #  "build" variant.
316
    sollya_lib_clear_obj(addExprSo)
317
    sollya_lib_clear_obj(oneSo)
318
    if curPrecSa != precision:
319
        pobyso_set_prec_so_so(curPrecSo)
320
        sollya_lib_clear_obj(curPrecSo)
321
    return constSo
296
    return ratExprSo
322 297
# End pobyso_constant_from_mpq_sa_so.
323 298

  
299
def pobyso_constant_sollya_prec_sa_so(rnArgSa):
300
    """
301
    Create a Sollya constant from a Sage RealNumber at the
302
    current precision in Sollya.
303
    """
304
    currentSollyaPrecSa = pobyso_get_prec_so_sa()
305
    return pobyso_constant_sa_so(rnArgSa, currentSollyaPrecSa)
306
# End pobyso_constant_sollya_prec_sa_so
307
     
324 308
def pobyso_error_so():
325 309
    return sollya_lib_error(None)
326 310
# End pobyso_error().
327 311

  
312
def pobyso_float_poly_sa_so(polySa, precSa = None):
313
    """
314
    Create a Sollya polynomial from a Sage RealField polynomial.
315
    """
316
    ## TODO: filter arguments.
317
    ## Precision. If a precision is given, convert the polynomial
318
    #  into the right polynomial field. If not convert it straight
319
    #  to Sollya.
320
    if not precSa is None:
321
        RRR = RealField(precSa)
322
        ## Create a Sage polynomial in the "right" precision.
323
        P_RRR = RRR[polySa.variables()[0]]
324
        polyFloatSa = P_RRR(polySa)
325
    else:
326
        polyFloatSa = polySa
327
        precSa = polySa.parent().base_ring().precision()
328
    ## Get exponents and coefficients.
329
    exponentSa = polyFloatSa.exponents()
330
    coefficientsSa = polyFloatSa.coefficients()
331
    ## Build the polynomial.
332
    polySo = None
333
    for coefficientSa, exponentSa in zip(coefficientsSa, exponentSa):
334
        #print coefficientSa.n(prec=precSa), exponentSa
335
        coefficientSo = \
336
            pobyso_constant_sa_so(coefficientSa)
337
        #pobyso_autoprint(coefficientSo)
338
        exponentSo = \
339
            pobyso_constant_from_int_sa_so(exponentSa)
340
        #pobyso_autoprint(exponentSo)
341
        monomialSo = sollya_lib_build_function_pow(
342
                       sollya_lib_build_function_free_variable(),
343
                       exponentSo)
344
        if polySo is None:
345
            polySo = sollya_lib_build_function_mul(coefficientSo,
346
                                                   monomialSo)
347
        else:
348
            polyTermSo = sollya_lib_build_function_mul(coefficientSo,
349
                                                       monomialSo)
350
            polySo = sollya_lib_build_function_add(polySo, polyTermSo)
351
    return polySo
352
# End pobyso_float_poly_sa_so    
353

  
354
def pobyso_float_poly_so_sa(polySo, realFieldSa=None):
355
    """
356
    Convert a Sollya polynomial into a Sage floating-point polynomial.
357
    We assume that the polynomial is in canonical form.
358
    If no realField is given, a RealField corresponding to the maximum 
359
    precision of the coefficients is internally computed.
360
    The real field is not returned but can be easily retrieved from 
361
    the polynomial itself.
362
    ALGORITHM:
363
    - (optional) compute the RealField of the coefficients;
364
    - convert the Sollya expression into a Sage expression;
365
    - convert the Sage expression into a Sage polynomial
366
    TODO: the canonical thing for the polynomial.
367
    """    
368
    if realFieldSa is None:
369
        expressionPrecSa = pobyso_get_max_prec_of_exp_so_sa(polySo)
370
        realFieldSa      = RealField(expressionPrecSa)
371
    #print "Sollya expression before...",
372
    #pobyso_autoprint(polySo)
373

  
374
    expressionSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo,
375
                                                             realFieldSa)
376
    #print "...Sollya expression after.",
377
    #pobyso_autoprint(polySo)
378
    polyVariableSa = expressionSa.variables()[0]
379
    polyRingSa     = realFieldSa[str(polyVariableSa)]
380
    #print polyRingSa
381
    # Do not use the polynomial(expressionSa, ring=polyRingSa) form!
382
    polynomialSa = polyRingSa(expressionSa)
383
    return polynomialSa
384
# End pobyso_float_poly_so_sa
385

  
386
    
328 387
def pobyso_function_type_as_string(funcType):
329 388
    """ Legacy function. See pobyso_function_type_as_string_so_sa. """
330 389
    return(pobyso_function_type_as_string_so_sa(funcType))
......
427 486

  
428 487
def pobyso_get_constant(rnArgSa, constSo):
429 488
    """ Legacy function. See pobyso_get_constant_so_sa. """
430
    return(pobyso_get_constant_so_sa(rnArgSa, constSo))
489
    return pobyso_get_constant_so_sa(rnArgSa, constSo)
490
# End pobyso_get_constant
431 491

  
432 492
def pobyso_get_constant_so_sa(rnArgSa, constSo):
433 493
    """
......
435 495
    rnArg must already exist and belong to some RealField.
436 496
    We assume that constSo points to a Sollya constant.
437 497
    """
438
    return(sollya_lib_get_constant(get_rn_value(rnArgSa), constSo))
439
    
498
    outcome = sollya_lib_get_constant(get_rn_value(rnArgSa), constSo)
499
    if outcome == 0: # Failure because constSo is not a constant expression.
500
        return None
501
    else:
502
        return outcome
503
# End  pobyso_get_constant_so_sa
504
   
440 505
def pobyso_get_constant_as_rn(ctExpSo):
441 506
    """ 
442 507
    Legacy function. See pobyso_get_constant_as_rn_so_sa. 
......
449 514
    The precision of the floating-point number returned is that of the Sollya
450 515
    constant.
451 516
    """
452
    precisionSa  = pobyso_get_prec_of_constant_so_sa(constExpSo) 
517
    precisionSa  = pobyso_get_prec_of_constant_so_sa(constExpSo)
518
    ## If the expression can not be exactly converted, None is returned.
519
    #  In this case opt for the Sollya current expression.
520
    if precisionSa is None:
521
        precisionSa = pobyso_get_prec_so_sa()
453 522
    RRRR = RealField(precisionSa)
454 523
    rnSa = RRRR(0)
455
    sollya_lib_get_constant(get_rn_value(rnSa), constExpSo)
456
    return(rnSa)
524
    outcome = sollya_lib_get_constant(get_rn_value(rnSa), constExpSo)
525
    if outcome == 0:
526
        return None
527
    else:
528
        return rnSa
457 529
# End pobyso_get_constant_as_rn_so_sa
458 530

  
459 531
def pobyso_get_constant_as_rn_with_rf(ctExp, realField):
460 532
    """ 
461 533
    Legacy function. See pobyso_get_constant_as_rn_with_rf_so_sa.
462 534
    """
463
    return(pobyso_get_constant_as_rn_with_rf_so_sa(ctExp, realField))
535
    return pobyso_get_constant_as_rn_with_rf_so_sa(ctExp, realField)
536
# End pobyso_get_constant_as_rn_with_rf
464 537
    
465 538
def pobyso_get_constant_as_rn_with_rf_so_sa(ctExpSo, realFieldSa = None):
466 539
    """
......
470 543
    Otherwise is is that of the real field. Hence rounding may happen.
471 544
    """
472 545
    if realFieldSa is None:
473
        sollyaPrecSa = pobyso_get_prec_of_constant_so_sa(ctExpSo)
474
        realFieldSa = RealField(sollyaPrecSa)
546
        return pobyso_get_constant_as_rn_so_sa(ctExpSo)
475 547
    rnSa = realFieldSa(0)
476
    sollya_lib_get_constant(get_rn_value(rnSa), ctExpSo)
477
    return(rnSa)
548
    outcome = sollya_lib_get_constant(get_rn_value(rnSa), ctExpSo)
549
    if outcome == 0:
550
        return None
551
    else:
552
        return rnSa
478 553
# End pobyso_get_constant_as_rn_with_rf_so_sa
479 554

  
480
def pobyso_get_float_poly_sa_so(polySa, realFieldSa=None):
481
    """
482
    Create a Sollya polynomial from a Sage polynomial.
483
    """
484
    pass
485
# End get_float_poly_sa_so.
486
    
487 555
def pobyso_get_free_variable_name():
488 556
    """ 
489 557
    Legacy function. See pobyso_get_free_variable_name_so_sa.
......
491 559
    return(pobyso_get_free_variable_name_so_sa())
492 560

  
493 561
def pobyso_get_free_variable_name_so_sa():
494
    return(sollya_lib_get_free_variable_name())
562
    return sollya_lib_get_free_variable_name()
495 563
    
496 564
def pobyso_get_function_arity(expressionSo):
497 565
    """ 
......
502 570
def pobyso_get_function_arity_so_sa(expressionSo):
503 571
    arity = c_int(0)
504 572
    sollya_lib_get_function_arity(byref(arity),expressionSo)
505
    return(int(arity.value))
573
    return int(arity.value)
506 574

  
507 575
def pobyso_get_head_function(expressionSo):
508 576
    """ 
......
513 581
def pobyso_get_head_function_so_sa(expressionSo):
514 582
    functionType = c_int(0)
515 583
    sollya_lib_get_head_function(byref(functionType), expressionSo, None)
516
    return(int(functionType.value))
584
    return int(functionType.value)
517 585

  
518 586
def pobyso_get_interval_from_range_so_sa(soRange, realIntervalFieldSa = None ):
519 587
    """
......
526 594
    if realIntervalFieldSa is None:
527 595
        retval = sollya_lib_get_prec_of_range(byref(prec), soRange, None)
528 596
        if retval == 0:
529
            return(None)
597
            return None
530 598
        realIntervalFieldSa = RealIntervalField(prec.value)
531 599
    intervalSa = realIntervalFieldSa(0,0)
532 600
    retval = \
533 601
        sollya_lib_get_interval_from_range(get_interval_value(intervalSa),\
534 602
                                           soRange)
535 603
    if retval == 0:
536
        return(None)
537
    return(intervalSa)
604
        return None
605
    return intervalSa
538 606
# End pobyso_get_interval_from_range_so_sa
539 607

  
540 608
def pobyso_get_list_elements(soObj):
541 609
    """ Legacy function. See pobyso_get_list_elements_so_so. """
542
    return(pobyso_get_list_elements_so_so(soObj))
610
    return pobyso_get_list_elements_so_so(soObj)
543 611
 
544 612
def pobyso_get_list_elements_so_so(objectListSo):
545 613
    """
......
578 646
       #sollya_lib_clear_obj(listAddress[i])
579 647
    # Free the list itself.   
580 648
    sollya_lib_free(listAddress)
581
    return(listAsSageList, numElements.value, isEndElliptic.value)
649
    return (listAsSageList, numElements.value, isEndElliptic.value)
582 650

  
583 651
def pobyso_get_max_prec_of_exp(soExp):
584 652
    """ Legacy function. See pobyso_get_max_prec_of_exp_so_sa. """
585
    return(pobyso_get_max_prec_of_exp_so_sa(soExp))
653
    return pobyso_get_max_prec_of_exp_so_sa(soExp)
586 654

  
587 655
def pobyso_get_max_prec_of_exp_so_sa(expSo):
588 656
    """
......
608 676
                pobyso_get_max_prec_of_exp_so_sa(subexpressions[i])
609 677
            if maxPrecisionCandidate > maxPrecision:
610 678
                maxPrecision = maxPrecisionCandidate
611
        return(maxPrecision)
679
        return maxPrecision
612 680
    elif operator == SOLLYA_BASE_FUNC_CONSTANT:
613 681
        #minConstPrec = pobyso_get_min_prec_of_constant_so_sa(expSo)
614 682
        #currentConstPrec = pobyso_get_min_prec_of_constant_so_sa(soExp)
615 683
        #print minConstPrec, " - ", currentConstPrec 
616
        return(pobyso_get_min_prec_of_constant_so_sa(expSo))
684
        return pobyso_get_min_prec_of_constant_so_sa(expSo)
617 685
    
618 686
    elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE:
619
        return(0)
687
        return 0
620 688
    else:
621 689
        print "pobyso_get_max_prec_of_exp_so_sa: unexepected operator."
622
        return(0)
690
        return 0
623 691

  
624 692
def pobyso_get_min_prec_of_constant_so_sa(constExpSo):
625 693
    """
626 694
    Get the minimum precision necessary to represent the value of a Sollya
627 695
    constant.
628 696
    MPFR_MIN_PREC and powers of 2 are taken into account.
629
    We assume that constExpSo is a point
697
    We assume that constExpSo is a pointer to a Sollay constant expression.
630 698
    """
631 699
    constExpAsRnSa = pobyso_get_constant_as_rn_so_sa(constExpSo)
632 700
    return(min_mpfr_size(get_rn_value(constExpAsRnSa)))
......
634 702
def pobyso_get_poly_so_sa(polySo, realFieldSa=None):
635 703
    """
636 704
    Convert a Sollya polynomial into a Sage polynomial.
637
    We assume that the polynomial is in canonical form.
638
    If no realField is given, a RealField corresponding to the maximum 
639
    precision of the coefficients is internally computed.
640
    The real field is not returned but can be easily retrieved from 
641
    the polynomial itself.
642
    ALGORITHM:
643
    - (optional) compute the RealField of the coefficients;
644
    - convert the Sollya expression into a Sage expression;
645
    - convert the Sage expression into a Sage polynomial
646
    TODO: the canonical thing for the polynomial.
705
    Legacy function. Use pobyso_float_poly_so_sa() instead.
647 706
    """    
648
    if realFieldSa is None:
649
        expressionPrecSa = pobyso_get_max_prec_of_exp_so_sa(polySo)
650
        realFieldSa = RealField(expressionPrecSa)
651
    #print "Sollya expression before...",
652
    #pobyso_autoprint(polySo)
653

  
654
    expressionSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, \
655
                                                             realFieldSa)
656
    #print "...Sollya expression after.",
657
    #pobyso_autoprint(polySo)
658
    polyVariableSa = expressionSa.variables()[0]
659
    polyRingSa = realFieldSa[str(polyVariableSa)]
660
    #print polyRingSa
661
    # Do not use the polynomial(expressionSa, ring=polyRingSa) form!
662
    polynomialSa = polyRingSa(expressionSa)
663
    return(polynomialSa)
707
    return pobyso_float_poly_so_sa(polySo,realField)
664 708
# End pobyso_get_poly_so_sa
665 709

  
666 710
def pobyso_get_prec():
667 711
    """ Legacy function. See pobyso_get_prec_so_sa(). """
668
    return(pobyso_get_prec_so_sa())
712
    return pobyso_get_prec_so_sa()
669 713

  
670 714
def pobyso_get_prec_so():
671 715
    """
......
674 718
    Usefull when modifying the precision back and forth by avoiding
675 719
    extra conversions.
676 720
    """
677
    return(sollya_lib_get_prec(None))
721
    return sollya_lib_get_prec(None)
678 722
    
679 723
def pobyso_get_prec_so_sa():
680 724
    """
......
688 732
    return int(precSa.value)
689 733
# End pobyso_get_prec_so_sa.
690 734

  
735
def pobyso_get_prec_so_so_sa():
736
    """
737
    Return the current precision both as a Sollya object and a
738
    Sage integer as hybrid tuple.
739
    To avoid multiple calls for precision manipulations. 
740
    """
741
    precSo = sollya_lib_get_prec(None)
742
    precSa = c_int(0)
743
    sollya_lib_get_constant_as_int(byref(precSa), precSo)
744
    return (precSo, precSa)
691 745
    
692 746
def pobyso_get_prec_of_constant(ctExpSo):
693 747
    """ Legacy function. See pobyso_get_prec_of_constant_so_sa. """
694
    return(pobyso_get_prec_of_constant_so_sa(ctExpSo))
748
    return pobyso_get_prec_of_constant_so_sa(ctExpSo)
695 749

  
696 750
def pobyso_get_prec_of_constant_so_sa(ctExpSo):
697 751
    """
......
701 755
    prec = c_int(0)
702 756
    retc = sollya_lib_get_prec_of_constant(byref(prec), ctExpSo, None)
703 757
    if retc == 0:
704
        return(None)
705
    return(int(prec.value))
758
        return None
759
    return int(prec.value)
706 760

  
707 761
def pobyso_get_prec_of_range_so_sa(rangeSo):
708 762
    """
......
712 766
    retc = sollya_lib_get_prec_of_range(byref(prec), rangeSo, None)
713 767
    if retc == 0:
714 768
        return(None)
715
    return(int(prec.value))
769
    return int(prec.value)
716 770
# End pobyso_get_prec_of_range_so_sa()
717 771

  
718
def pobyso_get_rat_poly_sa_so(polySa, precSa = None):
719
    """
720
    Create a Sollya polynomial from a Sage rational polynomial.
721
    """
722
    ## TODO: filter arguments.
723
    ##
724
    if not precSa is None:
725
        initialPrecSo = pobyso_get_prec_so() 
726
    coefficients = polySa.coefficients()
727
    exponents    = polySa.exponents()
728
    ## TODO: deal with variables names.
729
    
730
    ## If necessary, return Sollya to its initial default precision.
731
    if not precSa is None:
732
        pobyso_set_prec_so_so(initialPrecSo)
733
# End pobyso_get_rat_poly_sa_so    
734
    
735 772
def pobyso_get_sage_exp_from_sollya_exp(sollyaExpSo, realField = RR):
736 773
    """ Legacy function. See pobyso_get_sage_exp_from_sollya_exp_so_sa. """
737
    return(pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExpSo, \
738
                                                     realField = RR))
774
    return pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExpSo, 
775
                                                     realField = RR)
739 776

  
740 777
def pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExpSo, realFieldSa = RR):
741 778
    """
......
771 808
        # (is there any in Sollya anyway?).
772 809
        else:
773 810
            sageExpSa = eval('None')
774
        return(sageExpSa)
811
        return sageExpSa
775 812
    elif operatorSa == SOLLYA_BASE_FUNC_CONSTANT:
776 813
        #print "This is a constant"
777 814
        return pobyso_get_constant_as_rn_with_rf_so_sa(sollyaExpSo, realFieldSa)
778 815
    elif operatorSa == SOLLYA_BASE_FUNC_FREE_VARIABLE:
779 816
        #print "This is free variable"
780
        return(eval(sollyaLibFreeVariableName))
817
        return eval(sollyaLibFreeVariableName)
781 818
    else:
782 819
        print "Unexpected"
783 820
        return eval('None')
......
786 823

  
787 824
def pobyso_get_subfunctions(expressionSo):
788 825
    """ Legacy function. See pobyso_get_subfunctions_so_sa. """
789
    return(pobyso_get_subfunctions_so_sa(expressionSo)) 
826
    return pobyso_get_subfunctions_so_sa(expressionSo) 
790 827
# End pobyso_get_subfunctions.
791 828
 
792 829
def pobyso_get_subfunctions_so_sa(expressionSo):
......
829 866
    for i in xrange(arity.value):
830 867
        subs.append(int(subfunctions[i].value))
831 868
        #print subs[i]
832
    return(int(arity.value), subs)
869
    return (int(arity.value), subs)
833 870
# End pobyso_get_subfunctions_so_sa
834 871
    
835 872
def pobyso_guess_degree_sa_sa(functionSa, intervalSa, approxErrorSa, 
......
932 969

  
933 970
def pobyso_infnorm_so_so(func, interval, file = None, intervalList = None):
934 971
    print "Do not use this function. User pobyso_supnorm_so_so instead."
935
    return(None)
972
    return None
936 973

  
937 974
def pobyso_interval_to_range_sa_so(intervalSa, precisionSa=None):
938 975
    if precisionSa is None:
......
940 977
    intervalSo = pobyso_bounds_to_range_sa_so(intervalSa.lower(),\
941 978
                                              intervalSa.upper(),\
942 979
                                              precisionSa)
943
    return(intervalSo)
980
    return intervalSo
944 981
# End pobyso_interval_to_range_sa_so
945 982

  
946 983
def pobyso_is_error_so_sa(objSo):
......
955 992

  
956 993
def pobyso_is_floating_point_number_sa_sa(numberSa):
957 994
    """
958
    Check whether a Sage number is floating point
995
    Check whether a Sage number is floating point.
996
    Exception stuff added because numbers other than
997
    floating-point ones do not have the is_real() attribute.
959 998
    """
960
    return numberSa.parent().__class__ is RR.__class__
999
    try:
1000
        return numberSa.is_real()
1001
    except AttributeError:
1002
        return False
1003
# End pobyso_is_floating_piont_number_sa_sa
961 1004

  
962 1005
def pobyso_lib_init():
963 1006
    sollya_lib_init(None)
......
977 1020

  
978 1021
def pobyso_parse_string(string):
979 1022
    """ Legacy function. See pobyso_parse_string_sa_so. """
980
    return(pobyso_parse_string_sa_so(string))
1023
    return pobyso_parse_string_sa_so(string)
981 1024
 
982 1025
def pobyso_parse_string_sa_so(string):
983 1026
    """
984 1027
    Get the Sollya expression computed from a Sage string or
985 1028
    a Sollya error object if parsing failed.
986 1029
    """
987
    return(sollya_lib_parse_string(string))
1030
    return sollya_lib_parse_string(string)
988 1031

  
989 1032
def pobyso_precision_so_sa(ctExpSo):
1033
    """
1034
    Computes the necessary precision to represent a number.
1035
    If x is not zero, it can be uniquely written as x = m · 2e 
1036
    where m is an odd integer and e is an integer. 
1037
    precision(x) returns the number of bits necessary to write m 
1038
    in binary (i.e. ceil(log2(m))).
1039
    """
1040
    #TODO: take care of the special case: 0, @NaN@, @Inf@
990 1041
    precisionSo = sollya_lib_precision(ctExpSo)
991 1042
    precisionSa = pobyso_constant_from_int_so_sa(precisionSo)
992 1043
    sollya_lib_clear_obj(precisionSo)
......
995 1046
    
996 1047
def pobyso_range(rnLowerBound, rnUpperBound):
997 1048
    """ Legacy function. See pobyso_range_sa_so. """
998
    return(pobyso_range_sa_so(rnLowerBound, rnUpperBound)) 
1049
    return pobyso_range_sa_so(rnLowerBound, rnUpperBound) 
999 1050

  
1000 1051

  
1001 1052
def pobyso_range_to_interval_so_sa(rangeSo, realIntervalFieldSa = None):
......
1011 1062
        realIntervalFieldSa = RealIntervalField(precSa)
1012 1063
    intervalSa = \
1013 1064
        pobyso_get_interval_from_range_so_sa(rangeSo, realIntervalFieldSa) 
1014
    return(intervalSa)
1065
    return intervalSa
1066
# End pobyso_range_to_interval_so_sa
1015 1067

  
1068
def pobyso_rat_poly_sa_so(polySa, precSa = None):
1069
    """
1070
    Create a Sollya polynomial from a Sage rational polynomial.
1071
    """
1072
    ## TODO: filter arguments.
1073
    ## Precision. If no precision is given, use the current precision
1074
    #  of Sollya.
1075
    if precSa is None:
1076
        precSa =  pobyso_get_prec_so_sa()
1077
    #print "Precision:",  precSa
1078
    RRR = RealField(precSa)
1079
    ## Create a Sage polynomial in the "right" precision.
1080
    P_RRR = RRR[polySa.variables()[0]]
1081
    polyFloatSa = P_RRR(polySa)
1082
    ## Make sure no precision is provided.
1083
    return pobyso_float_poly_sa_so(polyFloatSa)
1084
    
1085
# End pobyso_rat_poly_sa_so    
1086
    
1016 1087
def pobyso_remez_canonical_sa_sa(func, \
1017 1088
                                 degree, \
1018 1089
                                 lowerBound, \

Formats disponibles : Unified diff