Statistiques
| Révision :

root / pobysoPythonSage / src / sageSLZ / runHtrn-01.sage @ 230

Historique | Voir | Annoter | Télécharger (3,09 ko)

1 224 storres
#! /opt/sage/sage
2 224 storres
#from scipy.constants.codata import precision
3 224 storres
def initialize_env():
4 224 storres
    """
5 224 storres
    Load all necessary modules.
6 224 storres
    """
7 224 storres
    if not 'mpfi' in sage.misc.cython.standard_libs:
8 224 storres
        sage.misc.cython.standard_libs.append('mpfi')
9 224 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage")
10 224 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
11 224 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx")
12 224 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py")
13 224 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage")
14 224 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage")
15 224 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage")
16 224 storres
    # Matrix operations are loaded by polynomial operations.
17 224 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage")
18 224 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage")
19 224 storres
20 224 storres
21 224 storres
print "Running HTRN..."
22 224 storres
initialize_env()
23 224 storres
#
24 224 storres
f(x)                  = exp(x)
25 224 storres
precision             = 53
26 224 storres
htrAccuracyShift      = 50#58
27 224 storres
precisionRF           = RealField(precision)
28 224 storres
precPlusOneRF         = RealField(precisionRF.prec()+1)
29 224 storres
quasiExactRF          = RealField(1024)
30 224 storres
targetAccuracy        = 2^-(precision + htrAccuracyShift)
31 224 storres
binade                = 2^-31
32 224 storres
binadeAbsLowerBound   = precisionRF(binade)
33 224 storres
binadeUlp             = binadeAbsLowerBound.ulp()
34 224 storres
35 224 storres
binadeLowerBound      = binadeAbsLowerBound
36 224 storres
htrnc                 = precisionRF("1.9E9CBBFD6080B",16)  * 2^-31
37 224 storres
38 224 storres
print binade.n()
39 224 storres
print binadeAbsLowerBound.n()
40 224 storres
41 224 storres
htrncOffset  = htrnc - binadeLowerBound
42 224 storres
iterStep     = binadeUlp * 2^22
43 224 storres
iterVar      = binadeLowerBound + floor(htrncOffset/iterStep) * iterStep
44 224 storres
iterLimit    = iterVar + iterStep
45 224 storres
46 224 storres
print iterVar.n()
47 224 storres
print htrnc.n()
48 224 storres
print iterLimit.n()
49 224 storres
50 224 storres
iterCount = 0
51 224 storres
iterationsStartTime = cputime()
52 224 storres
kiloIterStartTime = cputime()
53 224 storres
kiloIterCount     = 0
54 224 storres
kiloIterCountStep = 2^20
55 224 storres
print "Starting iterations..."
56 224 storres
while iterVar < iterLimit:
57 224 storres
    if iterVar == htrnc:
58 224 storres
        print "Found at iter count:", iterCount
59 224 storres
        print "After:", cputime(iterationsStartTime)
60 224 storres
    if slz_is_htrn(argument=iterVar,
61 224 storres
                  function=f,
62 224 storres
                  targetAccuracy=targetAccuracy,
63 224 storres
                  targetRF=precisionRF,
64 224 storres
                  targetPlusOnePrecRF=precPlusOneRF,
65 224 storres
                  quasiExactRF=quasiExactRF):
66 224 storres
        print "HTRN candidate:", iterVar.n().str(base=2)
67 224 storres
        print "HTRN candidate:", iterVar.n().str(base=10)
68 224 storres
        print "HTRN candidate:", iterVar.n().str(base=16)
69 224 storres
        print
70 224 storres
    if kiloIterCount == kiloIterCountStep:
71 224 storres
        print "1024 iterations computed in:",
72 224 storres
        print cputime(kiloIterStartTime), "s"
73 224 storres
        kiloIterCount = 0
74 224 storres
        kiloIterStartTime = cputime()
75 224 storres
76 224 storres
    # End if
77 224 storres
    iterVar         += binadeUlp
78 224 storres
    iterCount       += 1
79 224 storres
    kiloIterCount   += 1
80 224 storres
iterationsFullTime = cputime(iterationsStartTime)
81 224 storres
print "Iterations terminates in", iterationsStartTime, "s."