From: Andy R. Terrel <[EMAIL PROTECTED]>

---
 examples/advanced/pidigits.py |   37 ++++++++++++++++++++-----------------
 examples/all.py               |    2 +-
 2 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/examples/advanced/pidigits.py b/examples/advanced/pidigits.py
index 60b59ca..72e79f7 100755
--- a/examples/advanced/pidigits.py
+++ b/examples/advanced/pidigits.py
@@ -1,16 +1,19 @@
 #!/usr/bin/env python
 """Pi digits example
 
-Example shows the computation of the digits of pi.
+Example shows arbitrary precision using mpmath with the
+computation of the digits of pi.
 """
 
-#from sympy.numerics import *
-#from sympy.numerics.utils_ import *
-#from sympy.numerics.constants import pi_float
+from sympy.mpmath import libmpf
+from sympy.mpmath import functions as mpf_funs
+
 import math
 from time import clock
+import sys
 
 def display_fraction(digits, skip=0, colwidth=10, columns=5):
+    """Pretty printer for first n digits of a fraction"""
     perline = colwidth * columns
     printed = 0
     for linecount in range((len(digits)-skip) // (colwidth * columns)):
@@ -31,21 +34,22 @@ def display_fraction(digits, skip=0, colwidth=10, 
columns=5):
         print s + ":", printed + colwidth*columns
 
 def calculateit(func, base, n, tofile):
-    Float.setprec(100)
-    intpart = small_numeral(int(float(func())), base)
+    """Writes first n base-digits of a mpmath function to file"""
+    prec = 100
+    intpart = libmpf.small_numeral(int(float(func(prec))), base)
     if intpart == 0:
         skip = 0
     else:
         skip = len(intpart)
-    Float.setprec(int(n*math.log(base,2))+10)
     print "Step 1 of 2: calculating binary value..."
     t = clock()
-    a = func()
+    prec = int(n*math.log(base,2))+10
+    a = func(prec)
     step1_time = clock() - t
     print "Step 2 of 2: converting to specified base..."
     t = clock()
-    d = bin_to_radix(a.man, -a.exp, base, n)
-    d = fixed_to_str(d, base, n)
+    d = libmpf.bin_to_radix(a.man, -a.exp, base, n)
+    d = libmpf.numeral(d, base, n)
     step2_time = clock() - t
     print "\nWriting output...\n"
     if tofile:
@@ -60,22 +64,21 @@ def calculateit(func, base, n, tofile):
         ((step1_time + step2_time), step1_time, step2_time)
 
 def interactive():
+    """Simple function to interact with user"""
     print "Compute digits of pi with SymPy\n"
     base = input("Which base? (2-36, 10 for decimal) \n> ")
     digits = input("How many digits? (enter a big number, say, 10000)\n> ")
     tofile = raw_input("Output to file? (enter a filename, or just press 
enter\nto print directly to the screen) \n> ")
     if tofile:
         tofile = open(tofile, "w")
-    global_options["verbose"] = True
-    global_options["verbose_base"] = base
-    calculateit(pi_float, base, digits, tofile)
-    raw_input("\nPress enter to close this script.")
+    calculateit(mpf_funs.pi, base, digits, tofile)
 
 def main():
-    base = 10
-    digits = 10000
+    """A non-interactive runner"""
+    base = 16
+    digits = 500
     tofile = None
-    calculateit(pi_float, base, digits, tofile)
+    calculateit(mpf_funs.pi, base, digits, tofile)
 
 if __name__ == "__main__":
     interactive()
diff --git a/examples/all.py b/examples/all.py
index 4e1c80f..7e85656 100755
--- a/examples/all.py
+++ b/examples/all.py
@@ -44,7 +44,7 @@ WORKING_EXAMPLES = [
     "intermediate.vandermonde",
     "advanced.fem",
     "advanced.gibbs_phenomenon",
-    #"advanced.pidigits",
+    "advanced.pidigits",
     #"advanced.plotting",
     #"advanced.qft",
     "advanced.relativity",
-- 
1.6.0.3


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patches@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sympy-patches?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to