Hello I wrote some code in Python, using the mpmath
, arbitrary precision math module:
from __future__ import division
from numpy import arctan, sin, absolute, log10
from mpmath import *
import time
imax = 1000001
x = mpf(0)
y = mpf(0)
z = mpf(0)
t = mpf(0)
u = mpf(0)
i = 1
mp.prec = 128
start_time = time.time()
while i < 1000001:
i += 1
x = mpf(x + 1)
y = mpf(y + x * x)
z = mpf(z + sin(y))
t = mpf(t + absolute(z))
u = mpf(u + log10(t))
print("--- %s seconds ---" % (time.time() - start_time))
print x
print y
print z
print t
print u
It took approximately 87 secs to print results. How can I improve this code? My friend in Fortran wrote similar program and it took only 3.14 secs for him to print results.