title: Optimization of a simple Python script to calculate the first sophomore's dream number
body: <p>I am currently working on a program to calculate 100,000 digits of the first sophomore's dream constant, I1. It's given by the sum below.</p>
  <p><a href="https://i.stack.imgur.com/NL4qI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NL4qI.png" alt="enter image description here" /></a></p>
  <p>After about 10,000 terms in this series it gets quite slow. I opted to write the program so small because I wanted to see how small I could make it</p>
  <pre><code>from decimal import *
  
  def sophodream(a):
      s,i,t=0,1,int(a*1.5)
      while i&lt;t:
           print(i)
           n,d=Decimal(pow(-1,i+1)),Decimal(i**i)
           f=n/d
           s+=f
           i+=1
      return s
  </code></pre>
  <p>I would like to know if there are any ways to speed this up aside from multithreading/multiprocessing. I find that when I do series like these in threaded pieces the accuracy of them gets lower.</p>