Révision 254

pobysoPythonSage/src/sageSLZ/runSLZ-53proj-binade.sage (revision 254)
44 44
from subprocess import call
45 45
#
46 46
## Main variables and parameters.
47
x         = var('x')
48
func(x)   = exp(x)
49
precision = 53
50
emin      = -1022
51
emax      = 1023 
52
RRR       = RealField(precision)
53
degree    = 0
54
alpha     = 0
55
htrn      = 0
56
binade    = 0
57
debugMode = False          
47
x            = var('x')
48
func(x)      = exp(x)
49
precision    = 53
50
emin         = -1022
51
emax         = 1023 
52
RRR          = RealField(precision)
53
degree       = 0
54
alpha        = 0
55
htrn         = 0
56
signAsString = ""
57
binade       = 0
58
debugMode    = False          
58 59
## Local functions
59 60
#
60 61
def usage():
......
68 69
    write("  htrn            hardness-to-round - a number of bits (integer)\n")
69 70
    write("  binade          the binade we want to  explore\n")
70 71
    write("                  as a positive integral expression\n")
72
    write("  sign            the sign of the interval we want to expolore\n")
73
    write("                  either \"pos\" or \"neg\"\n")
71 74
    write("  debug           debug mode (\"debug\", in any case)\n\n")
72 75
    sys.exit(2)
73 76
# End usage.
74 77
#
75 78
argsCount = len(sys.argv)
76 79
scriptName = os.path.basename(__file__)
77
if argsCount < 5:
80
if argsCount < 6:
78 81
    usage()
79 82
for index in xrange(1,argsCount):
80 83
    if index == 1:
......
85 88
        htrn = int(eval(sys.argv[index]))
86 89
    elif index == 4:
87 90
        binade = int(eval(sys.argv[index]))
88
        ## The number must be strictly positive.
89 91
    elif index == 5:
92
        signAsString = sys.argv[index]
93
        signAsString = signAsString.lower()
94
    elif index == 6:
90 95
        debugMode = sys.argv[index].upper()
91 96
        debugMode = (debugMode == "DEBUG")
92 97
# Done with command line arguments collection.
93 98
#
99
## Set the terminal window title.
100
terminalWindowTitle = ['stt', 
101
                        str(degree), 
102
                        str(alpha), 
103
                        str(htrn), 
104
                        str(binade),
105
                        signAsString]
106
call(terminalWindowTitle)
107
#
108
binadeUlp    = 2^(binade - precision + 1)
109
if signAsString == "pos": 
110
    lowerBound   = RRR(2^binade)
111
    upperBound   = RRR(2^(binade+1)) - binadeUlp
112
elif signAsString == "neg":
113
    lowerBound  = -RRR(2^(binade+1)) + binadeUlp
114
    upperBound  =  -RRR(2^binade)
115
    print lowerBound
116
    print upperBound
117
else:
118
    exceptionErrorMess = "\"" + signAsString + "\" is an invalid sign." \
119
    ". Aborting!\n"
120
    raise Exception(exceptionErrorMess)
121
#
94 122
## Debug printing
95 123
print "degree         :", degree
96 124
print "alpha          :", alpha
97 125
print "htrn           :", htrn
98 126
print "binade         :", binade
127
print "lower bound    :", lowerBound.str(truncate=False)
128
print "upper bound    :", upperBound.str(truncate=False)
129
print "sign           :", signAsString
99 130
print "debug mode     :", debugMode
100 131
print
101 132
#
102
## Set the terminal window title.
103
terminalWindowTitle = ['stt', 
104
                        str(degree), 
105
                        str(alpha), 
106
                        str(htrn), 
107
                        str(binade)]
108
call(terminalWindowTitle)
109
#
110
binadeUlp  = 2^(binade - precision + 1)
111
lowerBound = RRR(2^binade)
112
upperBound = RRR(2^(binade+1)) - binadeUlp
113 133
srs_run_SLZ_v05_proj(inputFunction=func, 
114 134
                     inputLowerBound         = lowerBound, 
115 135
                     inputUpperBound         = upperBound, 
pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage (revision 254)
3502 3502

  
3503 3503
    if debug:
3504 3504
        print "Function                :", inputFunction
3505
        print "Lower bound             :", inputLowerBound
3506
        print "Upper bounds            :", inputUpperBound
3505
        print "Lower bound             :", inputLowerBound.str(truncate=False)
3506
        print "Upper bounds            :", inputUpperBound.str(truncate=False)
3507 3507
        print "Alpha                   :", alpha
3508 3508
        print "Degree                  :", degree
3509 3509
        print "Precision               :", precision
......
3530 3530
    lowerBound = RRR(inputLowerBound)
3531 3531
    upperBound = RRR(inputUpperBound)
3532 3532
    ## Before going any further, check domain and image binade conditions.
3533
    print inputFunction(1).n()
3533
    print inputFunction._assume_str(), "at 1:", inputFunction(1).n()
3534 3534
    output = slz_fix_bounds_for_binades(lowerBound, upperBound, inputFunction)
3535
    #print "srsv04p:", output, (output is None)
3536
    #
3537
    ## Check if input to thr fix_bounds function is valid.
3535 3538
    if output is None:
3536 3539
        print "Invalid domain/image binades. Domain:",\
3537
        lowerBound, upperBound, "Images:", \
3540
        lowerBound.str(truncate=False), upperBound(truncate=False), \
3541
        "Images:", \
3538 3542
        inputFunction(lowerBound), inputFunction(upperBound)
3539 3543
        raise Exception("Invalid domain/image binades.")
3540 3544
    lb = output[0] ; ub = output[1]
3545
    #
3546
    ## Check if bounds have changed.
3541 3547
    if lb != lowerBound or ub != upperBound:
3542
        print "lb:", lb, " - ub:", ub
3543
        print "Invalid domain/image binades. Domain:",\
3544
        lowerBound, upperBound, "Images:", \
3548
        print "lb:", lb.str(truncate=False), " - ub:", ub.str(truncate=False)
3549
        print "Invalid domain/image binades."
3550
        print "Domain:", lowerBound, upperBound
3551
        print "Images:", \
3545 3552
        inputFunction(lowerBound), inputFunction(upperBound)
3546 3553
        raise Exception("Invalid domain/image binades.")
3547 3554
    #
......
3568 3575
    pobyso_name_free_variable_sa_so(str(function.variables()[0]))
3569 3576
    ## Compute the scaled function and the degree, in their Sollya version 
3570 3577
    #  once for all.
3578
    #print "srsvp initial bounds:",lowerBound, upperBound
3571 3579
    (scaledf, sdlb, sdub, silb, siub) = \
3572 3580
        slz_compute_scaled_function(function, lowerBound, upperBound, precision)
3573 3581
    print "Scaled function:", scaledf._assume_str().replace('_SAGE_VAR_', '')
3574
    #print "Scaled bounds:", sdlb, sdub
3582
    #print "srsvp Scaled bounds:", sdlb, sdub
3575 3583
    scaledfSo = sollya_lib_parse_string(scaledf._assume_str().replace('_SAGE_VAR_', ''))
3576 3584
    degreeSo  = pobyso_constant_from_int_sa_so(degree)
3577 3585
    #
......
3807 3815
        iRootsSet           = set()
3808 3816
        hasNonNullResultant = False
3809 3817
        for polyPair in polyPairsList:
3810
            resultantsComputationTime   = cputime()
3818
            resultantsComputationTime = cputime()
3811 3819
            currentResultantI = \
3812 3820
                slz_resultant(polyPair[0],
3813 3821
                              polyPair[1],
......
3835 3843
            rootsComputationsFullTime   =   cputime(rootsComputationTime)
3836 3844
            if len(iRootsList) == 0:
3837 3845
                print "No roots in \"i\"."
3838
                break # No roots in i.
3846
                #break # No roots in i.
3839 3847
            else:
3840 3848
                for iRoot in iRootsList:
3841 3849
                    # A root is given as a (value, multiplicity) tuple.
3842 3850
                    iRootsSet.add(iRoot[0])
3851
                    print "Root added."
3852
            #### A non null, non constant resultant has been tested
3853
            #    for. There is no need to check for another one. Break
3854
            #    whether roots are found or not.
3855
            break
3843 3856
        # End loop for polyPair in polyParsList. We only loop again if a 
3844 3857
        # None or zero resultant is found.
3845 3858
        #### Prepare for results for the current interval..
pobysoPythonSage/src/sageSLZ/argsForRunSLZ-53-binade-01.sh (revision 254)
1 1
#! /bin/bash
2
#@file argsForRunSLZ-53-01proj.sh
2
#@file argsForRunSLZ-53-binade-01.sh
3 3
DEGREE=3
4 4
ALPHA=3
5 5
HARDNESS_TO_ROUND="53+50"
6 6
BINADE="-31"
7
SIGN="pos"
7 8
#
8 9
printf -- "$DEGREE \
9 10
$ALPHA \
10 11
$HARDNESS_TO_ROUND \
11
$BINADE\n"
12
$BINADE \
13
$SIGN\n"
pobysoPythonSage/src/sageSLZ/runSLZ-53-binade.sage (revision 254)
90 90
        binade = int(eval(sys.argv[index]))
91 91
    elif index == 5:
92 92
        signAsString = sys.argv[index]
93
        signAsString = signAsString.lower()
93 94
    elif index == 6:
94 95
        debugMode = sys.argv[index].upper()
95 96
        debugMode = (debugMode == "DEBUG")
96 97
# Done with command line arguments collection.
97 98
#
98
## Debug printing
99
print "degree         :", degree
100
print "alpha          :", alpha
101
print "htrn           :", htrn
102
print "binade         :", binade
103
print "sign           :", signAsString
104
print "debug mode     :", debugMode
105
print
106
#
107 99
## Set the terminal window title.
108 100
terminalWindowTitle = ['stt', 
109 101
                        str(degree), 
......
114 106
call(terminalWindowTitle)
115 107
#
116 108
binadeUlp    = 2^(binade - precision + 1)
117
signAsString = signAsString.lower()
118 109
if signAsString == "pos": 
119 110
    lowerBound   = RRR(2^binade)
120 111
    upperBound   = RRR(2^(binade+1)) - binadeUlp
121 112
elif signAsString == "neg":
122 113
    lowerBound  = -RRR(2^(binade+1)) + binadeUlp
123 114
    upperBound  =  -RRR(2^binade)
124
    print lowerBound
125
    print upperBound
126 115
else:
127 116
    exceptionErrorMess = "\"" + signAsString + "\" is an invalid sign." \
128 117
    ". Aborting!\n"
129 118
    raise Exception(exceptionErrorMess)
119
#
120
## Debug printing
121
print "degree         :", degree
122
print "alpha          :", alpha
123
print "htrn           :", htrn
124
print "binade         :", binade
125
print "lower bound    :", lowerBound.str(truncate=False)
126
print "upper bound    :", upperBound.str(truncate=False)
127
print "sign           :", signAsString
128
print "debug mode     :", debugMode
129
print
130
#
130 131
srs_run_SLZ_v05(inputFunction=func, 
131 132
                     inputLowerBound         = lowerBound, 
132 133
                     inputUpperBound         = upperBound, 
pobysoPythonSage/src/sageSLZ/sageSLZ.sage (revision 254)
1523 1523
    if debug:
1524 1524
        print 'ff:', ff, "- Domain:", scaledLowerBoundSa, \
1525 1525
              scaledUpperBoundSa
1526
    ## If both bounds are negative, swap them.
1527
    if lowerBoundSa < 0 and upperBoundSa < 0:
1528
        scaledLowerBoundSa, scaledUpperBoundSa = \
1529
        scaledUpperBoundSa,scaledLowerBoundSa
1526 1530
    #
1527 1531
    # Scalling the image -> [1,2[.
1528 1532
    flbSa = ff(scaledLowerBoundSa).n(prec=floatingPointPrecSa)
......
1591 1595
        else:
1592 1596
            lb = lb + newIntervalWidth
1593 1597
            lbBinade = slz_compute_binade(lb) 
1598
    #print "sfbfb: lower bound:", lb.str(truncate=False)
1599
    #print "sfbfb: upper bound:", ub.str(truncate=False)
1600
    ## At this point, both bounds belond to the same binade.
1594 1601
    ## Image binade.
1595 1602
    if lb == ub:
1596 1603
        return (lb, ub)
1597 1604
    lbImg = func(lb)
1598 1605
    ubImg = func(ub)
1599
    funcIsInc = (ubImg >= lbImg)
1606
    funcIsInc = ((ubImg - lbImg) >= 0)
1600 1607
    lbImgBinade = slz_compute_binade(lbImg)
1601 1608
    ubImgBinade = slz_compute_binade(ubImg)
1602 1609
    while lbImgBinade != ubImgBinade:

Formats disponibles : Unified diff