Révision 227

pobysoPythonSage/src/sageSLZ/runSLZ-06.sage.py (revision 227)
1 1
# This file was *autogenerated* from the file ./runSLZ-06.sage
2 2
from sage.all_cmdline import *   # import sage library
3
_sage_const_3 = Integer(3); _sage_const_2 = Integer(2); _sage_const_45 = Integer(45); _sage_const_113 = Integer(113); _sage_const_49 = Integer(49); _sage_const_8 = Integer(8); _sage_const_16383 = Integer(16383); _sage_const_16382 = Integer(16382); _sage_const_18 = Integer(18); _sage_const_35 = Integer(35); _sage_const_6 = Integer(6)#! /opt/sage/sage
3
_sage_const_3 = Integer(3); _sage_const_2 = Integer(2); _sage_const_35 = Integer(35); _sage_const_8 = Integer(8); _sage_const_1023 = Integer(1023); _sage_const_1022 = Integer(1022); _sage_const_10 = Integer(10); _sage_const_53 = Integer(53)#! /opt/sage/sage
4 4
# @file runSLZ-05.sage
5 5
#from scipy.constants.codata import precision
6 6
def initialize_env():
7 7
    """
8 8
    Load all necessary modules.
9 9
    """
10
    compiledSpyxDir = "/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx"
11
    if compiledSpyxDir not in sys.path:
12
        sys.path.append(compiledSpyxDir)
10 13
    if not 'mpfi' in sage.misc.cython.standard_libs:
11 14
        sage.misc.cython.standard_libs.append('mpfi')
12 15
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage")
13
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
16
    #load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
14 17
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py")
15 18
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage")
16 19
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage")
......
22 25

  
23 26
print "Running SLZ..."
24 27
initialize_env()
28
from sageMpfr import *
29
from sageGMP  import *
30
#
25 31
x = var('x')
26 32
__tmp__=var("x"); func = symbolic_expression(exp(x)).function(x)
27
precision = _sage_const_113 
33
precision = _sage_const_53 
28 34
RRR = RealField(precision)
29
intervalCenter      = RRR(_sage_const_3 /_sage_const_8 )
35
intervalCenter      = RRR(_sage_const_3 /_sage_const_2 )
30 36
icUlp               = intervalCenter.ulp()
31
intervalRadiusInUlp = _sage_const_2 **_sage_const_49  + _sage_const_2 **_sage_const_45 
37
intervalRadiusInUlp = _sage_const_2 **_sage_const_8 
32 38
intervalRadius      = RRR(_sage_const_2 **(-_sage_const_35 ))          
33
srs_run_SLZ_v05(inputFunction=func, 
34
                inputLowerBound         = intervalCenter - intervalRadius, 
35
                inputUpperBound         = intervalCenter + intervalRadius, 
36
                alpha                   = _sage_const_6 , 
37
                degree                  = _sage_const_18 , 
39
srs_run_SLZ_v06(inputFunction           = func, 
40
                inputLowerBound         = intervalCenter - intervalRadiusInUlp * icUlp, 
41
                inputUpperBound         = intervalCenter + intervalRadiusInUlp * icUlp, 
42
                alpha                   = _sage_const_2 , 
43
                degree                  = _sage_const_2 , 
38 44
                precision               = precision, 
39
                emin                    = -_sage_const_16382 , 
40
                emax                    = _sage_const_16383 , 
41
                targetHardnessToRound   = precision * _sage_const_6 , 
45
                emin                    = -_sage_const_1022 , 
46
                emax                    = _sage_const_1023 , 
47
                targetHardnessToRound   = precision + _sage_const_10 , 
42 48
                debug                   = True)
43 49
#
pobysoPythonSage/src/sageSLZ/sageSLZ.sage (revision 227)
849 849

  
850 850
def slz_compute_polynomial_and_interval_02(functionSo, degreeSo, lowerBoundSa, 
851 851
                                        upperBoundSa, approxAccurSa, 
852
                                        sollyaPrecSa=None):
852
                                        sollyaPrecSa=None, debug=True ):
853 853
    """
854 854
    Under the assumptions listed for slz_get_intervals_and_polynomials, compute
855 855
    a polynomial that approximates the function on a an interval starting
......
866 866
    - the center of the interval;
867 867
    - the maximum error in the approximation of the input functionSo by the
868 868
      output polynomial ; this error <= approxAccurSaS.
869
    
869
    Changes fom v1:
870
        extra verbose.
870 871
    """
871 872
    print"In slz_compute_polynomial_and_interval..."
872 873
    ## Superficial argument check.
......
875 876
    ## Change Sollya precision, if requested.
876 877
    sollyaPrecChanged = False
877 878
    (initialSollyaPrecSo, initialSollyaPrecSa) = pobyso_get_prec_so_so_sa()
878
    if not sollyaPrecSa is None:
879
    #print "Initial Sollya prec:", initialSollyaPrecSa, type(initialSollyaPrecSa)
880
    if sollyaPrecSa is None:
879 881
        sollyaPrecSa = initialSollyaPrecSa
880 882
    else:
881 883
        if sollyaPrecSa <= 2:
......
888 890
    currentRangeSo = pobyso_bounds_to_range_sa_so(lowerBoundSa, upperBoundSa)
889 891
    currentUpperBoundSa = upperBoundSa
890 892
    currentLowerBoundSa = lowerBoundSa
891
    # What we want here is the polynomial without the variable change, 
892
    # since our actual variable will be x-intervalCenter defined over the 
893
    # domain [lowerBound-intervalCenter , upperBound-intervalCenter]. 
893
    #pobyso_autoprint(functionSo)
894
    #pobyso_autoprint(degreeSo)
895
    #pobyso_autoprint(currentRangeSo)
896
    #pobyso_autoprint(absoluteErrorTypeSo)
897
    ## What we want here is the polynomial without the variable change, 
898
    #  since our actual variable will be x-intervalCenter defined over the 
899
    #  domain [lowerBound-intervalCenter , upperBound-intervalCenter].
894 900
    (polySo, intervalCenterSo, maxErrorSo) = \
895 901
        pobyso_taylor_expansion_no_change_var_so_so(functionSo, degreeSo, 
896 902
                                                    currentRangeSo, 
897 903
                                                    absoluteErrorTypeSo)
898 904
    maxErrorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo)
905
    print "...after Taylor expansion."
899 906
    while maxErrorSa > approxAccurSa:
900 907
        print "++Approximation error:", maxErrorSa.n()
901 908
        sollya_lib_clear_obj(polySo)
pobysoPythonSage/src/sageSLZ/runSLZ-06.sage (revision 227)
5 5
    """
6 6
    Load all necessary modules.
7 7
    """
8
    compiledSpyxDir = "/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx"
9
    if compiledSpyxDir not in sys.path:
10
        sys.path.append(compiledSpyxDir)
8 11
    if not 'mpfi' in sage.misc.cython.standard_libs:
9 12
        sage.misc.cython.standard_libs.append('mpfi')
10 13
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage")
11
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
14
    #load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
12 15
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py")
13 16
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage")
14 17
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage")
......
20 23

  
21 24
print "Running SLZ..."
22 25
initialize_env()
26
from sageMpfr import *
27
from sageGMP  import *
28
#
23 29
x = var('x')
24 30
func(x) = exp(x)
25
precision = 113
31
precision = 53
26 32
RRR = RealField(precision)
27
intervalCenter      = RRR(3/8)
33
intervalCenter      = RRR(3/2)
28 34
icUlp               = intervalCenter.ulp()
29
intervalRadiusInUlp = 2^49 + 2^45
35
intervalRadiusInUlp = 2^8
30 36
intervalRadius      = RRR(2^(-35))          
31
srs_run_SLZ_v05(inputFunction=func, 
32
                inputLowerBound         = intervalCenter - intervalRadius, 
33
                inputUpperBound         = intervalCenter + intervalRadius, 
34
                alpha                   = 6, 
35
                degree                  = 18, 
37
srs_run_SLZ_v06(inputFunction           = func, 
38
                inputLowerBound         = intervalCenter - intervalRadiusInUlp * icUlp, 
39
                inputUpperBound         = intervalCenter + intervalRadiusInUlp * icUlp, 
40
                alpha                   = 2, 
41
                degree                  = 2, 
36 42
                precision               = precision, 
37
                emin                    = -16382, 
38
                emax                    = 16383, 
39
                targetHardnessToRound   = precision * 6, 
43
                emin                    = -1022, 
44
                emax                    = 1023, 
45
                targetHardnessToRound   = precision + 10, 
40 46
                debug                   = True)
41 47
#
pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage (revision 227)
2966 2966
        2- once a non null resultant is found, check for roots;
2967 2967
        3- constant resultant == no root.
2968 2968
    """
2969

  
2970 2969
    if debug:
2971 2970
        print "Function                :", inputFunction
2972 2971
        print "Lower bound             :", inputLowerBound
......
3046 3045
    internalSollyaPrec = ceil((RR('1.5') * targetHardnessToRound) / 64) * 64
3047 3046
    if internalSollyaPrec < 192:
3048 3047
        internalSollyaPrec = 192
3048
    pobyso_lib_init()
3049 3049
    pobyso_set_prec_sa_so(internalSollyaPrec)
3050 3050
    print "Sollya internal precision:", internalSollyaPrec
3051 3051
    targetPlusOnePrecRF       = RealField(RRR.prec()+1)
......
3108 3108
        iterCount += 1
3109 3109
        print "[", lb, ",", ub, "]", ((ub - lb) / intervalUlp).log2().n(), \
3110 3110
            "log2(numbers)." 
3111
        #print "Debugging..."
3111 3112
        ### Compute a Sollya polynomial that will honor the Taylor condition.
3112
        prceSo = slz_compute_polynomial_and_interval_01(scaledfSo,
3113
        prceSo = slz_compute_polynomial_and_interval_02(scaledfSo,
3113 3114
                                                        degreeSo,
3114 3115
                                                        lb,
3115 3116
                                                        ub,
3116 3117
                                                        polyApproxAccur,
3117 3118
                                                        debug=True)
3118 3119
        if debug:
3119
            print "Sollya Taylor polynomial:", pobyso_autoprint(prceSo[0])
3120
            print "Sollya interval         :", pobyso_autoprint(prceSo[1])
3121
            print "Sollya interval center  :", pobyso_autoprint(prceSo[2])
3122
            print "Sollya Taylor error     :", pobyso_autoprint(prceSo[3])
3120
            print "Sollya Taylor polynomial:", ; pobyso_autoprint(prceSo[0])
3121
            print "Sollya interval         :", ; pobyso_autoprint(prceSo[1])
3122
            print "Sollya interval center  :", ; pobyso_autoprint(prceSo[2])
3123
            print "Sollya Taylor error     :", ; pobyso_autoprint(prceSo[3])
3123 3124

  
3124 3125
        ### Convert back the data into Sage space.                         
3125 3126
        (floatP, floatPcv, intvl, ic, terr) = \
pobysoPythonSage/src/pobyso.py (revision 227)
799 799
    Get the current default precision in Sollya.
800 800
    The return value is Sage/Python int.
801 801
    """
802
    precSo = sollya_lib_get_prec(None)
803
    precSa = c_int(0)
804
    sollya_lib_get_constant_as_int(byref(precSa), precSo)
802
    precSo = sollya_lib_get_prec()
803
    precSa = pobyso_constant_from_int_so_sa(precSo)
805 804
    sollya_lib_clear_obj(precSo)
806
    return int(precSa.value)
805
    return precSa
807 806
# End pobyso_get_prec_so_sa.
808 807

  
809 808
def pobyso_get_prec_so_so_sa():
......
812 811
    Sage integer as hybrid tuple.
813 812
    To avoid multiple calls for precision manipulations. 
814 813
    """
815
    precSo = sollya_lib_get_prec(None)
816
    precSa = c_int(0)
817
    sollya_lib_get_constant_as_int(byref(precSa), precSo)
818
    return (precSo, precSa.value)
814
    precSo = sollya_lib_get_prec()
815
    precSa = pobyso_constant_from_int_so_sa(precSo)
816
    return (precSo, int(precSa))
819 817
    
820 818
def pobyso_get_prec_of_constant(ctExpSo):
821 819
    """ Legacy function. See pobyso_get_prec_of_constant_so_sa. """
......
1669 1667
    pobyso_set_prec_sa_so(p)
1670 1668

  
1671 1669
def pobyso_set_prec_sa_so(p):
1672
    a = c_int(p)
1670
    #a = c_int(p)
1673 1671
    #precSo = c_void_p(sollya_lib_constant_from_int(a))
1674
    precSo = sollya_lib_constant_from_int(a)
1672
    #precSo = sollya_lib_constant_from_int(a)
1673
    precSo = pobyso_constant_from_int_sa_so(p)
1675 1674
    sollya_lib_set_prec(precSo)
1676 1675
    sollya_lib_clear_obj(precSo)
1677 1676
# End pobyso_set_prec_sa_so.
......
1728 1727
    x -> x-intervalCenter.
1729 1728
    """
1730 1729
    # Change internal Sollya precision, if needed.
1731
    (initialSollyaPrecSo, initialSollyaPrecSo) = pobyso_get_prec_so_so_sa()
1730
    (initialSollyaPrecSo, initialSollyaPrecSa) = pobyso_get_prec_so_so_sa()
1732 1731
    sollyaPrecChanged = False
1733 1732
    if sollyaPrecSo is None:
1734 1733
        pass
......
1774 1773
    pobyso_clear_taylorform_sa_so(taylorFormListSaSo)
1775 1774
    if absMaxErrorSa > absMinErrorSa:
1776 1775
        sollya_lib_clear_obj(absMinErrorSo)
1777
        return((polySo, intervalCenterSo, absMaxErrorSo))
1776
        return (polySo, intervalCenterSo, absMaxErrorSo)
1778 1777
    else:
1779 1778
        sollya_lib_clear_obj(absMaxErrorSo)
1780
        return((polySo, intervalCenterSo, absMinErrorSo))
1779
        return (polySo, intervalCenterSo, absMinErrorSo)
1781 1780
# end pobyso_taylor_expansion_no_change_var_so_so
1782 1781

  
1783 1782
def pobyso_taylor_expansion_with_change_var_so_so(functionSo, degreeSo, \

Formats disponibles : Unified diff