Compute pi to base 12 using Python?

D

Dick Moores

Dick Moores wrote at 18:40 4/14/2005:

I just listened to Kojima's

"NEW
Chorus Pi (Japanese) / 2:28
Chorus: MacinTalk Voices. The music was created from the constant PI."

on that page. The vocal is singing the digits of base-10 pi.

ten is . or decimal point
zero is 0
inchi is 1
ni is 2
san is 3
ta? is 4 (don't understand that "ta" or "tan", but it must be 4)
go is 5
roku is 6 -- in the music 6 sounds like "raku"
nana is 7
hachi is 8
ku is 9

Take a look/listen to

"String Quartet Pi / 5:06 and the process of data
The music was created from the constant PI (3.141592.......) to 3,000
decimal places by programming."

Lots of details there on the music.

Dick
 
D

Dick Moores

M.E.Farmer wrote at 23:18 4/14/2005:
Wow! this got me the 3003 (changed from 3000) digits of pi to base 12 in
60.8 secs. No, I didn't count them yet, nor am I sure they're correct.
But I'd bet on them..

Could someone remind me how to get the output of bc -l into a text file
on Windows? (I've tried employing " > pi3003.txt" in various ways) OR,
how to copy and paste from the command line window, or whatever that
window is called? (Sorry for the OT question.)

BTW I found a nice set of SCO UNIX man pages at <http://www.rt.com/man/>.

Dick
 
R

Roel Schroeven

Dick said:
M.E.Farmer wrote at 23:18 4/14/2005:



Wow! this got me the 3003 (changed from 3000) digits of pi to base 12 in
60.8 secs. No, I didn't count them yet, nor am I sure they're correct.
But I'd bet on them..

Could someone remind me how to get the output of bc -l into a text file
on Windows? (I've tried employing " > pi3003.txt" in various ways) OR,
how to copy and paste from the command line window, or whatever that
window is called? (Sorry for the OT question.)

Works for me (using the Cygwin version though) when I do

C:\cygwin\bin\bc -l > pi12.txt

Otherwise, to copy from the command prompt window: open the system menu
(icon in the top left corner of the window) and choose Edit->Mark. Then
select what you want to copy and press Enter or choose Edit->Copy in the
system menu.
 
D

Dick Moores

Roel Schroeven wrote at 01:45 4/17/2005:
Works for me (using the Cygwin version though) when I do

C:\cygwin\bin\bc -l > pi12.txt

But how or when do you enter the lines

scale = 3000
obase = 12
print 4 * a(1)
Otherwise, to copy from the command prompt window: open the system menu
(icon in the top left corner of the window) and choose Edit->Mark. Then
select what you want to copy and press Enter or choose Edit->Copy in the
system menu.

Thanks! You've just relieved years of frustration.

Dick
 
B

Bengt Richter

M.E.Farmer wrote at 23:18 4/14/2005:

Wow! this got me the 3003 (changed from 3000) digits of pi to base 12 in
60.8 secs. No, I didn't count them yet, nor am I sure they're correct.
But I'd bet on them..

Could someone remind me how to get the output of bc -l into a text file
on Windows? (I've tried employing " > pi3003.txt" in various ways) OR,
how to copy and paste from the command line window, or whatever that
window is called? (Sorry for the OT question.)
To copy from the command window to the clipboard:

1. Scroll top of desired stuff to make it visible near top
2. Hold down Alt
3. Tap Space Bar
4. Release Alt
5. Tap e
6. Tap k
7. Use mouse or arrow keys to place cursor on top left corner of desired box
8. Hold down Shift
9. Use arrow keys or mouse-with-left-button-pressed to go to bottom right character of desired box
9a. If the bottom is out of sight, keep holding shift down and pretend you can cursor down below bottom.
the attempt should make the screen scroll up and select more desired material. If you overshoot, don't panic,
just keep holding down shift and use arrows (the are slower) or mouse-with-left-button-still-down to move to
desired bottom right corner.
10. Release mouse button if using that
11. Release Shift
12. Press Enter
That should copy to the clipboard and make the selection box revert to normal display.

Pasting from clipboard is up to you. Pasting into the command window from clipboard
is 2-5 above, and Tap p

HTH

PS. Redirecting with > from a script whose interpreter was started by windows extension association
doesn't work on some version of windows. To be safe, invoke the interpreter explicitly, e.g.,
python myscript.py [whatever args here] > pi3003.txt

If myscript.py is not in the current directory, use a sufficient path to it. If your windows is having
that problem, the same will happen with a perl script or other script when you run it as just myscript.ext ...
and depend on windows to start the right interpreter.

Regards,
Bengt Richter
 
P

Paul Rubin

Dick Moores said:
But how or when do you enter the lines

scale = 3000
obase = 12
print 4 * a(1)

You could put them into a file, say pi.bc. Then run
bc -l pi.bc
 
D

Dick Moores

Bengt Richter wrote at 02:26 4/17/2005:
To copy from the command window to the clipboard:

1. Scroll top of desired stuff to make it visible near top
2. Hold down Alt
3. Tap Space Bar
4. Release Alt
5. Tap e
6. Tap k
7. Use mouse or arrow keys to place cursor on top left corner of desired box
8. Hold down Shift
9. Use arrow keys or mouse-with-left-button-pressed to go to bottom
right character of desired box
9a. If the bottom is out of sight, keep holding shift down and pretend
you can cursor down below bottom.
the attempt should make the screen scroll up and select more
desired material. If you overshoot, don't panic,
just keep holding down shift and use arrows (the are slower) or
mouse-with-left-button-still-down to move to
desired bottom right corner.
10. Release mouse button if using that
11. Release Shift
12. Press Enter
That should copy to the clipboard and make the selection box revert to
normal display.

Pasting from clipboard is up to you. Pasting into the command window
from clipboard
is 2-5 above, and Tap p

Thanks for showing me another way. But Roel Schroeven's

"to copy from the command prompt window: open the system menu
(icon in the top left corner of the window) and choose Edit->Mark. Then
select what you want to copy and press Enter or choose Edit->Copy in the
system menu."

seems to be easier.

PS. Redirecting with > from a script whose interpreter was started by
windows extension association
doesn't work on some version of windows. To be safe, invoke the
interpreter explicitly, e.g.,
python myscript.py [whatever args here] > pi3003.txt

Thanks very much for this.

What kind of args could I use here?

Dick
 
D

Dick Moores

Paul Rubin wrote at 02:35 4/17/2005:
You could put them into a file, say pi.bc. Then run
bc -l pi.bc

OK, now that I've got Textpad trained to open .bc files, I'm thinking of
things to store in them. I'm sure I'll want to put in some remarks as
well. What should I use to mark the remarks. "#", "//", or what?

The bc man page at <http://www.rt.com/man/bc.1.html> is tough. Any
suggestion for more easily understandable help?

And finally (maybe), is it possible to employ bc within a Python script?

Thanks,

Dick
 
M

M.E.Farmer

PS. Redirecting with > from a script whose interpreter was started by
windows extension association
doesn't work on some version of windows. To be safe, invoke the
interpreter explicitly, e.g.,
python myscript.py [whatever args here] > pi3003.txt
Thanks very much for this.
What kind of args could I use here?
Any that your script allows or understands.
an example:
python c:/Python22/Lib/PySourceColor.py -i- -s -l < c:/MyFile.py >
c:/tmp/myfile.html

A few things that might help you write a well behaved script:
if sys.stdin.isatty():
"direct"
else:
"redirected"
This snippet can determine if you have redirected IO.

I just found this and it looks informative.
http://www.jpsdomain.org/windows/redirection.html

hth,
M.E.Farmer
 
N

Nick Craig-Wood

Nick said:
I'm using GMPY (see code).
[snip]

If you are using gmpy you might as well do it like this.....

gmpy.pi() uses the Brent-Salamin Arithmetic-Geometric Mean formula
for
pi IIRC. This converges quadratically, and it will calculate you a
million places without breaking a sweat.

It would be nice if that were documented. What do I have to do, go get
the documentation for the original GMP to find out what else is in GMPY
that they didn't include in the doc file?

"pydoc gmpy" works for me. Not sure how you use pydoc on windows, but
you can do this...
Help on module gmpy:

NAME
gmpy

FILE
/usr/lib/python2.3/site-packages/gmpy.so
[snip]
Help on built-in function pi:

pi(...)
pi(n): returns pi with n bits of precision in an mpf object
[snip]

The original gmp documentation is sensible also, since gmpy is really
just a thin wrapper to it. There is also the gmp source code too.
 
M

mensanator

Nick said:
Nick said:
I'm using GMPY (see code).
[snip]

If you are using gmpy you might as well do it like this.....

gmpy.pi() uses the Brent-Salamin Arithmetic-Geometric Mean formula
for
pi IIRC. This converges quadratically, and it will calculate you a
million places without breaking a sweat.

It would be nice if that were documented. What do I have to do, go get
the documentation for the original GMP to find out what else is in GMPY
that they didn't include in the doc file?

"pydoc gmpy" works for me. Not sure how you use pydoc on windows, but
you can do this...
Help on module gmpy:

NAME
gmpy

FILE
/usr/lib/python2.3/site-packages/gmpy.so
[snip]
Help on built-in function pi:

pi(...)
pi(n): returns pi with n bits of precision in an mpf object
[snip]

Thanks, didn't know you could do that. And I'm glad you didn't reply
until today, because I learned how to do it the hard way:
for q in f:
if q[:2]=='__':
pass
else:
d = 'gmpy.' + q + '.__doc__'
e = eval(compile(d,'<string>','eval')
print e
print

That's 3 new functions I learned, dir(), compile() and eval().
And now that I know help(), I'll probably never need them, but
hopefully will remember them.

Even better, I realize the inadequecy of the doc strings of a
program I wrote. Now that I know how to use them interactively,
I can make them more useful.
The original gmp documentation is sensible also, since gmpy is really
just a thin wrapper to it.

I already looked. Utterly useless.
There is also the gmp source code too.

That helped, as there's a list of the function names in the source
code, but help() makes it unnecessary.

You still have to wonder, though, with as easy as this is, how the
gmpy documention ended up incomplete. I'm always reminded of something
I read in the National Lampoon:

"You know what a ****-up you are at work, how would anything get
done if everyone was like you? Well, the sad fact is everyone _is_
just like you...including the air traffic controller who's supposed
to be tracking your flight but has just looked away because he
dropped a cigarette ash and burned a hole in his trousers..."

So I suppose I shouldn't complain, after all, I got something
positive out of it.
http://www.craig-wood.com/nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top