Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

William Stein -- Talk for Mathematics is a long conversation: a celebration of Barry Mazur

4001 views
def prime_g(B): """ Compute the numbers g(p) for all primes p <= B, as a time series. These are the numbers g(p)=(next_prime(p)-p)/p, which are numbers between 0 and 1. """ v = [float(p) for p in prime_range(next_prime(B)+1)] # primes less than B and one more. return stats.TimeSeries([(v[i+1]-v[i])/v[i] for i in range(len(v)-1)])
%time t = prime_g(10^7); t
Error in lines 1-1 Traceback (most recent call last): File "/mnt/home/4by9x1bp/.sagemathcloud/sage_server.py", line 671, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "", line 8, in prime_g File "c_lib.pyx", line 70, in sage.ext.c_lib.sage_python_check_interrupt (sage/ext/c_lib.c:925) KeyboardInterrupt
CPU time: 7.02 s, Wall time: 6.91 s
%time show(t.plot_histogram(bins=5000), xmax=.01,ymax=150)
CPU time: 10.65 s, Wall time: 8.76 s
t2 = stats.TimeSeries([x for x in t if x<=.002])
len(t) len(t2)
664579 663995
%time show(t2.plot_histogram(bins=1000), ymax=10000)
CPU time: 1.92 s, Wall time: 1.78 s
t3 = stats.TimeSeries([x for x in t2 if x<=.001]) len(t) len(t2) len(t3) %time show(t3.plot_histogram(bins=1000), ymax=10000)
664579 663995 663432
CPU time: 1.94 s, Wall time: 1.81 s
%time t = prime_g(10^8); t
[0.5000, 0.6667, 0.4000, 0.5714, 0.1818 ... 0.0000, 0.0000, 0.0000, 0.0000, 0.0000] CPU time: 7.95 s, Wall time: 7.94 s
%time show(t.plot_histogram(bins=3000), xmax=.01,ymax=150)
CPU time: 5.07 s, Wall time: 4.98 s
t2 = stats.TimeSeries([x for x in t if x<=.001]) len(t) len(t2) %time show(t2.plot_histogram(bins=1000), ymax=10000)
5761455 5760308
CPU time: 2.24 s, Wall time: 2.12 s
%time show(t2.plot_histogram(bins=1000), ymax=20000, xmax=2e-4)
CPU time: 1.95 s, Wall time: 1.89 s
%time t = prime_g(10^9); t
[0.5000, 0.6667, 0.4000, 0.5714, 0.1818 ... 0.0000, 0.0000, 0.0000, 0.0000, 0.0000] CPU time: 75.75 s, Wall time: 75.64 s
%time show(t.plot_histogram(bins=3000), xmax=.01,ymax=150)
CPU time: 7.95 s, Wall time: 7.86 s
eps = float(0.001) t2 = stats.TimeSeries([x for x in t if x<=eps]) len(t) len(t2) %time show(t2.plot_histogram(bins=1000), ymax=10000)
50847534 50846387
CPU time: 3.57 s, Wall time: 3.46 s
%time show(t2.plot_histogram(bins=1000), ymax=20000, xmax=5e-5)
CPU time: 2.80 s, Wall time: 2.63 s
%time show(t2.plot_histogram(bins=5000), ymax=20000, xmax=1e-5)
CPU time: 9.60 s, Wall time: 9.50 s