Ticket #9958: trac_9958-fix_randstate.patch

File trac_9958-fix_randstate.patch, 6.4 KB (added by fbissey, 9 years ago)

fix all numerical noise in randstate

  • sage/misc/randstate.pyx

    # HG changeset patch
    # User Francois Bissey <francois.bissey@canterbury.ac.nz>
    # Date 1323604153 -46800
    # Node ID a025013121f8c1bbb8c4128fe48e853cb91da5d1
    # Parent  27b676bc8b4d15d20aa3792b7dc698e0031b2e06
    trac 9958: fix randstate.pyx
    
    diff --git a/sage/misc/randstate.pyx b/sage/misc/randstate.pyx
    a b  
    5555
    5656    sage: set_random_seed(0)
    5757    sage: rtest()
    58     (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 963229057, 8045, 0.96619117347084138)  # 32-bit
    59     (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 265625921, 8045, 0.96619117347084138)  # 64-bit
     58    (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 963229057, 8045, 0.9661911734708414)  # 32-bit
     59    (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 265625921, 8045, 0.9661911734708414)  # 64-bit
    6060    sage: set_random_seed(1)
    6161    sage: rtest()
    62     (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1161603091, 60359, 0.83350776541997362)  # 32-bit
    63     (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ],  807447831, 60359, 0.83350776541997362)  # 64-bit
     62    (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1161603091, 60359, 0.8335077654199736)  # 32-bit
     63    (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ],  807447831, 60359, 0.8335077654199736)  # 64-bit
    6464    sage: set_random_seed(2)
    6565    sage: rtest()
    6666    (207, 0.505364206568040, 4*x^2 + 1/2, (1,2)(4,5), [ 0, 0, 1, 0, 1 ],  637693405, 27695, 0.19982565117278328)  # 32-bit
    6767    (207, 0.505364206568040, 4*x^2 + 1/2, (1,2)(4,5), [ 0, 0, 1, 0, 1 ], 1642898426, 27695, 0.19982565117278328)  # 64-bit
    6868    sage: set_random_seed(0)
    6969    sage: rtest()
    70     (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 963229057, 8045, 0.96619117347084138)  # 32-bit
    71     (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 265625921, 8045, 0.96619117347084138)  # 64-bit
     70    (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 963229057, 8045, 0.9661911734708414)  # 32-bit
     71    (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 265625921, 8045, 0.9661911734708414)  # 64-bit
    7272    sage: set_random_seed(1)
    7373    sage: rtest()
    74     (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1161603091, 60359, 0.83350776541997362)  # 32-bit
    75     (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ],  807447831, 60359, 0.83350776541997362)  # 64-bit
     74    (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1161603091, 60359, 0.8335077654199736)  # 32-bit
     75    (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ],  807447831, 60359, 0.8335077654199736)  # 64-bit
    7676    sage: set_random_seed(2)
    7777    sage: rtest()
    7878    (207, 0.505364206568040, 4*x^2 + 1/2, (1,2)(4,5), [ 0, 0, 1, 0, 1 ],  637693405, 27695, 0.19982565117278328)  # 32-bit
     
    8686    sage: initial_seed()
    8787    12345L
    8888    sage: rtest()
    89     (720, 0.0216737401150802, x^2 - x, (), [ 1, 0, 0, 0, 0 ], 912534076, 14005, 0.92053315995181839)   # 32-bit
    90     (720, 0.0216737401150802, x^2 - x, (), [ 1, 0, 0, 0, 0 ], 1911581957, 14005, 0.92053315995181839)  # 64-bit
     89    (720, 0.0216737401150802, x^2 - x, (), [ 1, 0, 0, 0, 0 ], 912534076, 14005, 0.9205331599518184)   # 32-bit
     90    (720, 0.0216737401150802, x^2 - x, (), [ 1, 0, 0, 0, 0 ], 1911581957, 14005, 0.9205331599518184)  # 64-bit
    9191    sage: initial_seed()
    9292    12345L
    9393
     
    151151    (0.111439293741037, 539332L, 8.26785106378383, 1.3893337539828183)
    152152    sage: set_random_seed(1)
    153153    sage: random(), getrandbits(20), uniform(5.0, 10.0), normalvariate(0, 1)
    154     (0.82940228518742587, 624859L, 5.77894484361117, -0.42013668263087578)
     154    (0.8294022851874259, 624859L, 5.77894484361117, -0.4201366826308758)
    155155    sage: set_random_seed(0)
    156156    sage: random(), getrandbits(20), uniform(5.0, 10.0), normalvariate(0, 1)
    157157    (0.111439293741037, 539332L, 8.26785106378383, 1.3893337539828183)
     
    222222
    223223    sage: set_random_seed(0)
    224224    sage: r1 = rtest(); r1
    225     (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 963229057, 8045, 0.96619117347084138)  # 32-bit
    226     (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 265625921, 8045, 0.96619117347084138)  # 64-bit
     225    (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 963229057, 8045, 0.9661911734708414)  # 32-bit
     226    (303, -0.187141682737491, 1/2*x^2 - 1/95*x - 1/2, (1,2,3)(4,5), [ 0, 0, 0, 0, 1 ], 265625921, 8045, 0.9661911734708414)  # 64-bit
    227227    sage: r2 = rtest(); r2
    228228    (105, -0.581229341007821, -x^2 - x - 6, (1,3), [ 1, 0, 0, 1, 1 ], 14082860, 1271, 0.001767155077382232)  # 32-bit
    229229    (105, -0.581229341007821, -x^2 - x - 6, (1,3), [ 1, 0, 0, 1, 1 ], 53231108, 1271, 0.001767155077382232)  # 64-bit
     
    234234    sage: r1 == rtest()
    235235    True
    236236    sage: with seed(1): rtest()
    237     (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1161603091, 60359, 0.83350776541997362)  # 32-bit
    238     (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ],  807447831, 60359, 0.83350776541997362)  # 64-bit
     237    (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1161603091, 60359, 0.8335077654199736)  # 32-bit
     238    (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ],  807447831, 60359, 0.8335077654199736)  # 64-bit
    239239    sage: r2m = rtest(); r2m
    240240    (105, -0.581229341007821, -x^2 - x - 6, (1,3), [ 1, 0, 0, 1, 1 ], 14082860, 19769, 0.001767155077382232)  # 32-bit
    241241    (105, -0.581229341007821, -x^2 - x - 6, (1,3), [ 1, 0, 0, 1, 1 ], 53231108, 19769, 0.001767155077382232)  # 64-bit
     
    277277    ... finally:
    278278    ...       ctx.__exit__(None, None, None)
    279279    <sage.misc.randstate.randstate object at 0x...>
    280     (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1161603091, 60359, 0.83350776541997362)  # 32-bit
    281     (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ],  807447831, 60359, 0.83350776541997362)  # 64-bit
     280    (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ], 1161603091, 60359, 0.8335077654199736)  # 32-bit
     281    (978, 0.184109262667515, -3*x^2 - 1/12, (4,5), [ 0, 1, 1, 0, 0 ],  807447831, 60359, 0.8335077654199736)  # 64-bit
    282282    False
    283283    sage: r2m == rtest()
    284284    True