468,457 Members | 1,557 Online

Compute pi to base 12 using Python?

I need to figure out how to compute pi to base 12, to as many digits as
possible. I found this reference,
<http://mathworld.wolfram.com/Base.html>, but I really don't understand
it well enough. Could someone show me how to do what I need?

Thanks,

Dick Moores
rd*@rcblue.com

Jul 18 '05 #1
52 5177
On Wed, 13 Apr 2005 02:06:11 -0700, Dick Moores <rd*@rcblue.com> wrote:
I need to figure out how to compute pi to base 12, to as many digits as
possible. I found this reference,
<http://mathworld.wolfram.com/Base.html>, but I really don't understand
it well enough. Could someone show me how to do what I need?

Thanks,

Dick Moores
rd*@rcblue.com

See if this is enough digits for homework? ;-)

(Digits A and B are 10 and 11 in decimal respectively)

3184809493B918664573A6211BB151551A05729290A7809A49 2742140A60A55256A0661A03753A3AA54805646880181A
3683083272BBBA0A370B12265529A828903B4B256B8403759A 71626B8A54687621849B849A8225616B442796A31737B2
29B2391489853943B8763725616447236B027A421AA17A38B5 2A18A838B01514A51144A23315A3009A8906B61B8B48A6
2253A88A50A43BA0944572315933664476B3AABB7758397512 0683526B75B462060BB03B432551913772729A21475535
31793848A0402B999B5058535374465A68806716644039539A 8431935198527B9399B112990ABB0383B107645424577A
51601B3624A88B7A676A3992912121A213887B92873946A613 32242217AA7354115357744939112602BA4B888818A326
9222B528487747839994AB223B65B8762695422822669BA00A 586097842A51750362073B5A768363B21BB1A97A4A1944
47749399804922175A068A46739461990A2065BB0A30BBAB70 24A585B1A84428195489784A07A331A7B0A1574565B373
B05B03A5A80A13AB87857734679985558A5373178A7B282719 92A3894A5776085083B9B238B2220542462888641A2BAB
8B3083AB49659172A312B78518654494A068662586A181835A 64440B2970A12281397589881536720890580103288144
9223841428763329617531239B9A657405584014534390B587 625606BB80923795944B43757A431B039556282978A6A4
9590553490BA1844947175637A908247B50127722464441380 A852B0847B5813019BB70A67663B426565434069884476
132193344BA55A2128A03838974606B851B2979321A4080672 25A5AA4B3464A1A17473595333909AB9127079655B3164
B68B9B28A9B818A220A025AB0934203995B7A62A7AA7393553 40539BA3182905B193905603A43B660B9426A922946971
44A896A5B2339358BB2B7294BB89635B071A6351211360B820 B1882AB8433B54757B87A373284B1BA182A10326476B36
9A4A6365B58B8018994BB152556765475A704BB94B6B2A3945 8971A8B90512786B5029404818644323552916170B3ABB
7363496427B088B68725A68570040617949289077B278069A0 9B559324B8A66828B40549B0296065B2300330592569A7
B76B92BA1293585B6A9B604567A0901362856373B4B5689794 6256B4172B1B50474351364749A33996A81BA8847347A8
411B850B79A03018291672AA0945656A159AA6AA0A845531A5 92005B8A34366B882257107B190969A846474836A98007
50778920BA797297A2791101B0685A86BB704B9BAA17B05529 3679843B35215B0A8B1182B611953B080AA5431B219907
A8448A81B1A9493245676B88013B4703352408595941586210 14216619553246570601967448B470174B924489244481
7453865A4003B5AA7176451AAB90681A949786154AA0404773 82BA69371041710B8728458A23979252B254236753A44A
1900AA283536A227648812525743868B410A567794663359A6 726A5286783328135114789B7645505B047848020A730A
9557B206776AA56A19682744107901306B29008808619866B4 911A05264B872A46B5376383932699531B449195640B62
A63622830886247A47B3957169861239358041AA281333622A A15912B0A636047A489BB0726282A78B96671B27305A96
52496B9B999011A7BA36898891665B1A6009058978850A21B0 1A158A1473B84A192B8672542A2A7056581995207A436A
5B3BA2824637A3112ABB57176468206A071200A327B3216425 148100786502AA21236ABB35499277670A126973058340
3B1922A483856007301983989159BB688A58B602339806B630 02A339A50B0BA533B84827793913081070A32595A10180
3A9A20234691B1A0B623274B69B0B44688195169461059543A 252BB05208720BA13118266A872B26B9B584959B451795
19534B221A335A2BB6971B3276B3A63A5B791723109B176529 BB90651584279B7825712521B8269800738B07A62B1454
7884414451224092937165625696557A78799A82126613535A 36B410309B759976119777B895801074B9779B9B513753
8B2799951012273399BB818B721967957713B90947B2A11A6A 665848B22B531726616515939323229080B8AB574AA749
4773AB411A57150203067A112944833235A86153803A98689A 0762B79835413A46B347888A4AAB259665694B93129B62
1391751430A98B002620718437A7B85B891179479651AA3410 663715415B55BA47AA59465AB81567B7655780A8038135
85230122578485B071A529692B19A6537B28616A6355681694 5380634A90470354AAB303884B7B09B2037B95405BA145
704B19B14AA8028810881AB6072441194A875477836B37704B 5199062319A336375437403562A663B835B891957883AB

Hint: Lambert Meertens. Tweak the algorithm you find ;-)

Regards,
Bengt Richter
Jul 18 '05 #2
Bengt Richter wrote at 03:19 4/13/2005:
On Wed, 13 Apr 2005 02:06:11 -0700, Dick Moores <rd*@rcblue.com> wrote:
I need to figure out how to compute pi to base 12, to as many digits as
possible. I found this reference,
<http://mathworld.wolfram.com/Base.html>, but I really don't understand
it well enough. Could someone show me how to do what I need?

Thanks,

Dick Moores
rd*@rcblue.com
See if this is enough digits for homework? ;-)

This is not homework, nor am I a student, though I am trying to learn
Python. I'm just trying to help an artist acquaintance who needs (I just
learned) the first 3003 digits of pi to the base 12.
Hint: Lambert Meertens. Tweak the algorithm you find ;-)

Sorry. Your hint is beyond me.

Dick Moores
rd*@rcblue.com
Jul 18 '05 #3
# rd*@rcblue.com / 2005-04-13 03:27:06 -0700:
Bengt Richter wrote at 03:19 4/13/2005:
This is not homework, nor am I a student, though I am trying to learn
Python. I'm just trying to help an artist acquaintance who needs (I just
learned) the first 3003 digits of pi to the base 12.
Hint: Lambert Meertens. Tweak the algorithm you find ;-)

Sorry. Your hint is beyond me.

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
Jul 18 '05 #4
Dick Moores wrote:
I need to figure out how to compute pi to base 12, to as many digits as possible. I found this reference, <http://mathworld.wolfram.com/Base.html>, but I really don't understand it well enough.
How many stars are in "*************************"?

You probably answered "25". This means that, for convenience, you've
broken down the row of stars into ********** + ********** + *****, that
is, 2 tens with 5 left over, which the base-10 numeral system denotes
as "25".

But there's no reason other than tradition why you should arrange them
into groups of 10. For example, you could write it as ******** +
******** + ******** + *, or 3 eights plus 1. In octal (base-8)
notation, this is written as "31"; the "tens" place in octal represents
eights.

In general, in the base-r numeral system, the nth digit to the left of
the ones digit represents r^n. For example, in the binary number
11001, the place values for each digit are, right to left, 1, 2, 4, 8,
and 16, so the number as a whole represents
1×16+1×8+0×4+0×2+1×1=16+8+1=25. This analogous to 25=2×10+5 in
base-10.

It's also possible to write it as 3×8+0×4+0×2+1×1 = 3001 base 2,
but by convention, base-r only uses the digits in range(r). This
ensures a unique represenation for each number. This makes "11001" the
unique binary representation for decimal 25.

Note that for bases larger than 10, the digits will be numbers that are
not single digits in base 10. By convention, letters are used for
larger digits: A=10, B=11, C=12, ... Z=35. For example, the number
(dec) 2005 = 1×12³+1×12²+11×12+1×1 is represented in base-12 by
"11B1".

Fractions are handled in a similar manner. The nth place to the right
of the radix point (i.e., the "decimal point", but that term is
inaccurate for bases other than ten) represents the value radix**(-n).

For example, in binary,
0.1 = 1/2 = dec. 0.5
0.01 = 1/4 = dec. 0.25
0.11 = 1/2 + 1/4 = 3/4 = dec. 0.75
0.001 = 1/8 = dec. 0.125
0.01010101... = 1/4 + 1/16 + 1/64 + ... = 1/3
0.0001100110011... = 1/10 = dec. 0.1

The last row explains why Python gives:
0.1

0.10000000000000001

Most computers store floating-point numbers in binary, which doesn't
have a finite representation for one-tenth. The above result is
rounded to 53 signficant bits
(1.10011001100110011001100110011001100110011001101 0×2^-4), which is
exactly equivalent to decimal
0.100000000000000005551115123125782702118158340454 1015625, but gets
rounded to 17 significant digits for display.

Similarly, in base-12:

0.1 = 1/12
0.14 = 1/12 + 4/144 = 1/9
0.16 = 1/12 + 6/144 = 1/8
0.2 = 2/12 = 1/6
0.3 = 3/12 = 1/4
0.4 = 4/12 = 1/3
0.6 = 6/12 = 1/2
0.8 = 8/12 = 2/3
0.9 = 9/12 = 3/4
0.A = 10/12 = 5/6

Notice that several common fractions have simpler representations in
base-12 than in base-10. For this reason, there are people who believe
that base-12 is superior to base-10.
(http://www.dozenalsociety.org.uk)
Could someone show me how to do what I need?

You'll need 3 things:

(1) An algorithm for computing approximations of pi.

The simplest one is 4*(1-1/3+1/5-1/7+1/9-1/11+...), which is based on
the Taylor series expansion of 4*arctan(1).

There are other, faster ways. Search Google for them.

(2) An unlimited-precision numeric representation. The standard
"float" isn't good enough: It has only 53 bits of precision, which is
only enough for 14 base-12 digits.

The "decimal" module will probably work, although of course its base-10
internal representation will introduce slight inaccuracies.

(3) A function for converting numbers to their base-12 representation.

For integers, this can be done with:

DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
is_negative = False
if num < 0:
is_negative = True
num = -num
digits = []
digits.append(DIGITS[last_digit])
digits.append(DIGITS[num])
if is_negative:
digits.append("-")
digits.reverse()
return ''.join(digits)

For a floating-point number x, the representation with d "decimal"
places count be found by taking the representation of int(round(x *
radix ** d)) and inserting a "." d places from the right.

Jul 18 '05 #5
Dan Bishop wrote at 04:07 4/13/2005:
(3) A function for converting numbers to their base-12 representation.

For integers, this can be done with:

DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
is_negative = False
if num < 0:
is_negative = True
num = -num
digits = []
digits.append(DIGITS[last_digit])
digits.append(DIGITS[num])
if is_negative:
digits.append("-")
digits.reverse()
return ''.join(digits)
I see this works perfectly for integers. Thanks!
For a floating-point number x, the representation with d "decimal"
places count be found by taking the representation of int(round(x *
radix ** d)) and inserting a "." d places from the right.

But I'm sorry, but I can't follow you. I do have the first 10000 or so
places of pi base 10 (<http://mathwithmrherte.com/pi_digits.htm>), but
could you show me what to do with, say, just 3.14159?

I apologize for being so dense.

Dick Moores
rd*@rcblue.com
Jul 18 '05 #6
"Dan Bishop" <da*****@yahoo.com> wrote:
But there's no reason other than tradition why you should arrange them
into groups of 10.

Well, it is traditional for people to have 10 fingers :-)

Other fun things to think about are negative bases. For example, 3(10) =
111(-2). That's 1*(-2)^2 + 1*(-2)^1 + 1*(-2)^0 = 4 - 2 + 1. I can't
think of any use for negative bases, but they are a fun game to play with
(if you're into that sort of stuff).

Non-integer bases are fun too.
Jul 18 '05 #7
Dick Moores wrote:
Dan Bishop wrote at 04:07 4/13/2005: ....
For a floating-point number x, the representation with d "decimal"
places count be found by taking the representation of int(round(x *
radix ** d)) and inserting a "." d places from the right.

But I'm sorry, but I can't follow you. I do have the first 10000 or

so places of pi base 10 (<http://mathwithmrherte.com/pi_digits.htm>), but could you show me what to do with, say, just 3.14159?

First, decide how many "decimal" places to use for the conversion.
Five decimal digits is equivalent to 5*log(10)/log(12) = 4.63 base-12
digits, so use 4 digits.

Next, multiply by 12**4, obtaining the value 65144.01024, and round to
the nearest integer, 65144. Convert this to base 12, obtaining 31848.
But this is 12**4 times the number we really want, so divide this by
12**4 (i.e., shift the radix point left 4 places), for a final result
of 3.1848.

Jul 18 '05 #8
Roy Smith wrote:
"Dan Bishop" <da*****@yahoo.com> wrote:

But there's no reason other than tradition why you should arrange them
into groups of 10.

Well, it is traditional for people to have 10 fingers :-)

Other fun things to think about are negative bases. For example, 3(10) =
111(-2). That's 1*(-2)^2 + 1*(-2)^1 + 1*(-2)^0 = 4 - 2 + 1. I can't
think of any use for negative bases, but they are a fun game to play with
(if you're into that sort of stuff).

Non-integer bases are fun too.

If you think those are fun, try base (1j - 1)

--Scott David Daniels
Sc***********@Acm.Org
Jul 18 '05 #9
Scott David Daniels <Sc***********@Acm.Org> wrote:
If you think those are fun, try base (1j - 1)

Get real. I can't imagine using anything so complex.
Jul 18 '05 #10
On 13 Apr 2005 12:06:26 -0400, Roy Smith <ro*@panix.com> wrote:
Scott David Daniels <Sc***********@Acm.Org> wrote:
If you think those are fun, try base (1j - 1)

Get real. I can't imagine using anything so complex.

+1 QOTW

--
Kristian

kristian.zoerhoff(AT)gmail.com
zoerhoff(AT)freeshell.org
Jul 18 '05 #11
Scott David Daniels wrote:
Roy Smith wrote:
"Dan Bishop" <da*****@yahoo.com> wrote:
But there's no reason other than tradition why you should arrange theminto groups of 10.
Well, it is traditional for people to have 10 fingers :-)

Other fun things to think about are negative bases. For example, 3(10) = 111(-2). That's 1*(-2)^2 + 1*(-2)^1 + 1*(-2)^0 = 4 - 2 + 1. I can't think of any use for negative bases, but they are a fun game to play with (if you're into that sort of stuff).

Non-integer bases are fun too.

Pi has an interesting representation in bases between 0 and 1,
exclusive. There are a finite number of digits after the radix point,
but an infinite number _before_ it.
If you think those are fun, try base (1j - 1)

I think Knuth wrote something about complex bases back in the year
1000200000001000000010001.

Jul 18 '05 #12
On 2005-04-13, Dan Bishop <da*****@yahoo.com> wrote:
Pi has an interesting representation in bases between 0 and 1,
exclusive. There are a finite number of digits after the radix point,
but an infinite number _before_ it.

You really oughtn't make me think so hard right after lunch.

--
Grant Edwards grante Yow! I'd like some JUNK
at FOOD... and then I want to
visi.com be ALONE --
Jul 18 '05 #13
On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rd*@rcblue.com> wrote:
Bengt Richter wrote at 03:19 4/13/2005:
On Wed, 13 Apr 2005 02:06:11 -0700, Dick Moores <rd*@rcblue.com> wrote:
>I need to figure out how to compute pi to base 12, to as many digits as
>possible. I found this reference,
><http://mathworld.wolfram.com/Base.html>, but I really don't understand
>it well enough. Could someone show me how to do what I need?
>
>Thanks,
>
>Dick Moores
>rd*@rcblue.com
>

See if this is enough digits for homework? ;-)

This is not homework, nor am I a student, though I am trying to learn
Python. I'm just trying to help an artist acquaintance who needs (I just
learned) the first 3003 digits of pi to the base 12.
Hint: Lambert Meertens. Tweak the algorithm you find ;-)

Sorry. Your hint is beyond me.

If you google with this line in the slot:

lambert meertens pi site:python.org

the first hit is

http://mail.python.org/pipermail/tut...st/002143.html

In that (scroll down) you will find:

--------------------------------------------------
# Based on a algorithm of Lambert Meertens (remember those days of the
# B -> ABC-programming language!!!)
import sys

def main():
k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L
while 1:
p, q, k = k*k, 2L*k+1L, k+1L
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
d, d1 = a/b, a1/b1
while d == d1:
output(d)
a, a1 = 10L*(a%b), 10L*(a1%b1)
d, d1 = a/b, a1/b1

def output(d):
sys.stdout.write(`int(d)`)
sys.stdout.flush()

main()

# Reading/writing Python source often gives me the impression of
# Layout, indentation, rythm, I like the look and feel!

# What does this tiny program do? It is not a sonnet, even not a
# pi-sonnet, but it surely produces Pi!
--------------------------------------------------

If you replace
a, a1 = 10L*(a%b), 10L*(a1%b1)
with
a, a1 = 12L*(a%b), 12L*(a1%b1)

and
sys.stdout.write(`int(d)`)
with
sys.stdout.write('%X'%d`)

and run it, I think it will do what you want, even though I haven't worked through exactly
what it's doing, though it's pretty. (For confidence I just tried it and decoded the result
far enough to match math.pi exactly ;-)

(the %X formats hex, but for single digits that's fine for base 12, giving A for 10 and B for 11.
If you want bases >16 you'll have to use something like '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'[digitvalue])

BTW, I find that googling restricted to site:python.org
is a good bet for python-related info. After that, if no joy,
you can of course expand the search.

BTW2, I played with using pi digits to various bases as directions for turtle-style plotting, to
see if my eye would pick out patterns in the random-seeming sequence. Also played with coloring
the vector steps. I.e., set up a base-length (12 in your case) list of (dx,dy) tuples
for relative plot vectors and just relatively plot deltalist[pidigitvalue] and update the display
so you can see it develop. It was kind of interesting. For bases under 4 you have to decide what
to do with the "first" digit ;-)

Regards,
Bengt Richter
Jul 18 '05 #14
Dan Bishop wrote:
Dick Moores wrote:
I need to figure out how to compute pi to base 12, to as many digits
as
possible. I found this reference, <http://mathworld.wolfram.com/Base.html>,
but I really don't understand it well enough.

How many stars are in "*************************"?

You probably answered "25". This means that, for convenience, you've
broken down the row of stars into ********** + ********** + *****,

that is, 2 tens with 5 left over, which the base-10 numeral system denotes
as "25".

But there's no reason other than tradition why you should arrange them into groups of 10. For example, you could write it as ******** +
******** + ******** + *, or 3 eights plus 1. In octal (base-8)
notation, this is written as "31"; the "tens" place in octal represents eights.

In general, in the base-r numeral system, the nth digit to the left of the ones digit represents r^n. For example, in the binary number
11001, the place values for each digit are, right to left, 1, 2, 4, 8, and 16, so the number as a whole represents
1×16+1×8+0×4+0×2+1×1=16+8+1=25. This analogous to 25=2×10+5 in
base-10.

It's also possible to write it as 3×8+0×4+0×2+1×1 = 3001 base 2,
but by convention, base-r only uses the digits in range(r). This
ensures a unique represenation for each number. This makes "11001" the unique binary representation for decimal 25.

Note that for bases larger than 10, the digits will be numbers that are not single digits in base 10. By convention, letters are used for
larger digits: A=10, B=11, C=12, ... Z=35. For example, the number
(dec) 2005 = 1×12³+1×12²+11×12+1×1 is represented in base-12 by
"11B1".

Fractions are handled in a similar manner. The nth place to the right of the radix point (i.e., the "decimal point", but that term is
inaccurate for bases other than ten) represents the value radix**(-n).
For example, in binary,
0.1 = 1/2 = dec. 0.5
0.01 = 1/4 = dec. 0.25
0.11 = 1/2 + 1/4 = 3/4 = dec. 0.75
0.001 = 1/8 = dec. 0.125
0.01010101... = 1/4 + 1/16 + 1/64 + ... = 1/3
0.0001100110011... = 1/10 = dec. 0.1

The last row explains why Python gives:
0.1 0.10000000000000001

Most computers store floating-point numbers in binary, which doesn't
have a finite representation for one-tenth. The above result is
rounded to 53 signficant bits
(1.10011001100110011001100110011001100110011001101 0×2^-4), which is
exactly equivalent to decimal
0.100000000000000005551115123125782702118158340454 1015625, but gets
rounded to 17 significant digits for display.

Similarly, in base-12:

0.1 = 1/12
0.14 = 1/12 + 4/144 = 1/9
0.16 = 1/12 + 6/144 = 1/8
0.2 = 2/12 = 1/6
0.3 = 3/12 = 1/4
0.4 = 4/12 = 1/3
0.6 = 6/12 = 1/2
0.8 = 8/12 = 2/3
0.9 = 9/12 = 3/4
0.A = 10/12 = 5/6

Notice that several common fractions have simpler representations in
base-12 than in base-10. For this reason, there are people who believe that base-12 is superior to base-10.
(http://www.dozenalsociety.org.uk)
Could someone show me how to do what I need?
You'll need 3 things:

(1) An algorithm for computing approximations of pi.

The simplest one is 4*(1-1/3+1/5-1/7+1/9-1/11+...), which is based on
the Taylor series expansion of 4*arctan(1).

There are other, faster ways. Search Google for them.

That one's way too slow. I found the one I use below on Mathworld.

(2) An unlimited-precision numeric representation. The standard
"float" isn't good enough: It has only 53 bits of precision, which is
only enough for 14 base-12 digits.

The "decimal" module will probably work, although of course its base-10 internal representation will introduce slight inaccuracies.
I'm using GMPY (see code).

(3) A function for converting numbers to their base-12 representation.

GMPY can do this also.

For integers, this can be done with:

DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
is_negative = False
if num < 0:
is_negative = True
num = -num
digits = []
digits.append(DIGITS[last_digit])
digits.append(DIGITS[num])
if is_negative:
digits.append("-")
digits.reverse()
return ''.join(digits)

For a floating-point number x, the representation with d "decimal"
places count be found by taking the representation of int(round(x *
radix ** d)) and inserting a "." d places from the right.

# better pi/2 = 1 + 1/3 + (1*2)/(3*5) + (1*2*3)/(3*5*7) + ...

import gmpy
# unlimited precision math library

def pialso(n,b):
# input number of digits (n) in requested base (b)
p = gmpy.mpq(1,1)
# gmpy rationals are unlimited precision
sn = 1
sd = 3
c = gmpy.mpq(sn,sd)
# create the next term to be summed
num = gmpy.mpf(p.numer())
# seperately convert the numerator
den = gmpy.mpf(p.denom())
# and denominator to gmpy floats
f = (num/den) * 2
# to get unlimited precision float
olds = gmpy.fdigits(f,b,n,0,1,2)
# extract the requested digits and do base conversion
done = 0
while done==0:
p = p + c
# sum next term of pi equation
sn += 1
# set numerator
sd += 2
# and demoniator
c = c * gmpy.mpq(sn,sd)
# to create term for next iteration
num = gmpy.mpf(p.numer())
# meanwhile, convert this iteration
den = gmpy.mpf(p.denom())
f = (num/den) * 2
# to an unlimited precision float
s = gmpy.fdigits(f,b,n,0,1,2)
if s[0]==olds[0]:
# we're done when the number of digits
done = 1
# we want stops changing
else:
# otherwise, keep iterating until we reach the
olds = s
# the desired convergence
print s[0],sn
# prints the digits and how many iterations it took
print

"""

The first 100 digits of pi in base 10.
pialso(100,10) 31415926535897932384626433832795028841971693993751 05820974944592307816406286208998628034825342117067
327

The first 100 digits of pi in base 12. pialso(100,12)

3184809493b918664573a6211bb151551a05729290a7809a49 2742140a60a55256a0661a03753a3aa54805646880181a3682
353

Note it took more iterations (longer to converge) because base 12
digits are "bigger" than base 10.

"""

Jul 18 '05 #15
On 13 Apr 2005 12:06:26 -0400, ro*@panix.com (Roy Smith) wrote:
Scott David Daniels <Sc***********@Acm.Org> wrote:
If you think those are fun, try base (1j - 1)

Get real. I can't imagine using anything so complex.

Well said. :-)

Dan
Jul 18 '05 #16
On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rd*@rcblue.com>
wrote:
I'm just trying to help an artist acquaintance who needs (I just
learned) the first 3003 digits of pi to the base 12.

Now you've got me curious. Why would an artist want the first 3003
digits of pi to the base 12?

Dan

Jul 18 '05 #17
On Wed, 13 Apr 2005 08:28:29 -0400, Roy Smith <ro*@panix.com> wrote:
"Dan Bishop" <da*****@yahoo.com> wrote:
But there's no reason other than tradition why you should arrange them
into groups of 10.

Well, it is traditional for people to have 10 fingers :-)

According to anthropology archives, there was once a tribe called
"OS/360 system programmers" who would cut off their thumbs and great
toes in order that they might better count in hexadecimal.

Jul 18 '05 #18
Dan wrote at 18:02 4/13/2005:
On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rd*@rcblue.com>
wrote:
I'm just trying to help an artist acquaintance who needs (I just
learned) the first 3003 digits of pi to the base 12.

Now you've got me curious. Why would an artist want the first 3003
digits of pi to the base 12?

He says,
Do you know how I can get "base12 pi"?
Because the chromatic scale is base12.
c c# d d# e f f# g g# a a# b

Dick
Jul 18 '05 #19
Dick Moores <rd*@rcblue.com> writes:
I need to figure out how to compute pi to base 12, to as many digits
as possible. I found this reference,
<http://mathworld.wolfram.com/Base.html>, but I really don't
understand it well enough. Could someone show me how to do what I need?

Using the GNU "bc" utility:

\$ bc -l
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale = 3000 # number of output places wanted
obase = 12 # output base
print 4 * a(1) # pi = 4*arctan(1)
3.184809493B918664573A6211BB151551A05729290A7809A4 92742140A60A55256A\
0661A03753A3AA54805646880181A3683083272BBBA0A370B1 2265529A828903B4B2\
56B8403759A71626B8A54687621849B849A8225616B442796A 31737B229B23914898\
53943B8763725616447236B027A421AA17A38B52A18A838B01 514A51144A23315A30\
09A8906B61B8B48A62253A88A50A43BA094457231593366447 6B3AABB77583975120\
683526B75B462060BB03B432551913772729A2147553531793 848A0402B999B50585\
35374465A68806716644039539A8431935198527B9399B1129 90ABB0383B10764542\
4577A51601B3624A88B7A676A3992912121A213887B9287394 6A61332242217AA735\
4115357744939112602BA4B888818A3269222B528487747839 994AB223B65B876269\
5422822669BA00A586097842A51750362073B5A768363B21BB 1A97A4A19444774939\
9804922175A068A46739461990A2065BB0A30BBAB7024A585B 1A84428195489784A0\
7A331A7B0A1574565B373B05B03A5A80A13AB8785773467998 5558A5373178A7B282\
71992A3894A5776085083B9B238B2220542462888641A2BAB8 B3083AB49659172A31\
2B78518654494A068662586A181835A64440B2970A12281397 589881536720890580\
1032881449223841428763329617531239B9A6574055840145 34390B587625606BB8\
0923795944B43757A431B039556282978A6A49590553490BA1 844947175637A90824\
7B50127722464441380A852B0847B5813019BB70A67663B426 565434069884476132\
193344BA55A2128A03838974606B851B2979321A408067225A 5AA4B3464A1A174735\
95333909AB9127079655B3164B68B9B28A9B818A220A025AB0 934203995B7A62A7AA\
739355340539BA3182905B193905603A43B660B9426A922946 97144A896A5B233935\
8BB2B7294BB89635B071A6351211360B820B1882AB8433B547 57B87A373284B1BA18\
2A10326476B369A4A6365B58B8018994BB152556765475A704 BB94B6B2A39458971A\
8B90512786B5029404818644323552916170B3ABB736349642 7B088B68725A685700\
40617949289077B278069A09B559324B8A66828B40549B0296 065B2300330592569A\
7B76B92BA1293585B6A9B604567A0901362856373B4B568979 46256B4172B1B50474\
351364749A33996A81BA8847347A8411B850B79A0301829167 2AA0945656A159AA6A\
A0A845531A592005B8A34366B882257107B190969A84647483 6A9800750778920BA7\
97297A2791101B0685A86BB704B9BAA17B055293679843B352 15B0A8B1182B611953\
B080AA5431B219907A8448A81B1A9493245676B88013B47033 524085959415862101\
4216619553246570601967448B470174B92448924448174538 65A4003B5AA7176451\
AAB90681A949786154AA040477382BA69371041710B8728458 A23979252B25423675\
3A44A1900AA283536A227648812525743868B410A567794663 359A6726A528678332\
8135114789B7645505B047848020A730A9557B206776AA56A1 9682744107901306B2\
9008808619866B4911A05264B872A46B5376383932699531B4 49195640B62A636228\
30886247A47B3957169861239358041AA281333622AA15912B 0A636047A489BB0726\
282A78B96671B27305A9652496B9B999011A7BA36898891665 B1A6009058978850A2\
1B01A158A1473B84A192B8672542A2A7056581995207A436A5 B3BA2824637A3112AB\
B57176468206A071200A327B3216425148100786502AA21236 ABB35499277670A126\
9730583403B1922A483856007301983989159BB688A58B6023 39806B63002A339A50\
B0BA533B84827793913081070A32595A101803A9A20234691B 1A0B623274B69B0B44\
688195169461059543A252BB05208720BA13118266A872B26B 9B584959B44B
quit
\$

The arctan calculation takes about 20 sec on an Athlon of around 2 ghz.
Jul 18 '05 #20
Hi All--

Dick Moores wrote:

Dan wrote at 18:02 4/13/2005:
On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rd*@rcblue.com>
wrote:
I'm just trying to help an artist acquaintance who needs (I just
learned) the first 3003 digits of pi to the base 12.

Now you've got me curious. Why would an artist want the first 3003
digits of pi to the base 12?

He says,
Do you know how I can get "base12 pi"?
Because the chromatic scale is base12.
c c# d d# e f f# g g# a a# b

Oooh. Wanta hear it.

Metta,
Ivan
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/worksh...oceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
Jul 18 '05 #21
Paul Rubin wrote at 18:20 4/13/2005:
Dick Moores <rd*@rcblue.com> writes:
I need to figure out how to compute pi to base 12, to as many digits
as possible. I found this reference,
<http://mathworld.wolfram.com/Base.html>, but I really don't
understand it well enough. Could someone show me how to do what I need?

Using the GNU "bc" utility:

\$ bc -l
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale = 3000 # number of output places wanted
obase = 12 # output base
print 4 * a(1) # pi = 4*arctan(1)

I don't believe GNU "bc" is available for Windows, is it?

Thanks,

Dick Moores
rd*@rcblue.com

Jul 18 '05 #22
Dick Moores <rd*@rcblue.com> writes:
I don't believe GNU "bc" is available for Windows, is it?

I don't know. It probably works ok under Cygwin at least.
Jul 18 '05 #23
Dick Moores wrote:
Dan wrote at 18:02 4/13/2005:
On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rd*@rcblue.com>
wrote:
> I'm just trying to help an artist acquaintance who needs (I just
>learned) the first 3003 digits of pi to the base 12.

Now you've got me curious. Why would an artist want the first 3003
digits of pi to the base 12?

He says,
Do you know how I can get "base12 pi"?
Because the chromatic scale is base12.
c c# d d# e f f# g g# a a# b

Dick

So it's, like, the guy is going to "play pi"? So why does the melody
have 3003 notes?

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 18 '05 #24
Dan wrote:
On 13 Apr 2005 12:06:26 -0400, ro*@panix.com (Roy Smith) wrote:

Scott David Daniels <Sc***********@Acm.Org> wrote:
If you think those are fun, try base (1j - 1)

Get real. I can't imagine using anything so complex.

Well said. :-)

Oh, no, now we're sunk

three-holes-in-the-ground-ly y'rs - steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 18 '05 #25
In article <ma**************************************@python.o rg>,
Dick Moores <rd*@rcblue.com> wrote:
Dan wrote at 18:02 4/13/2005:
On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rd*@rcblue.com>
wrote:
I'm just trying to help an artist acquaintance who needs (I just
learned) the first 3003 digits of pi to the base 12.

Now you've got me curious. Why would an artist want the first 3003
digits of pi to the base 12?

He says,
Do you know how I can get "base12 pi"?
Because the chromatic scale is base12.
c c# d d# e f f# g g# a a# b

Dick

Does your artist friend have any idea what base 12 means?

The chromatic scale is based on one twelfth powers of two, i.e., if the
frequency of a note in the scale is f(n), then the frequency of the next
note is given by

f(n+1) = f(n) * 2^(1/12)

so by the time you go all 12 notes in an octave you have doubled the
frequency. There is nothing here involving base 12 or pi.

--
Doug Schwarz
Make obvious changes to get real email address.
Jul 18 '05 #26
Doug Schwarz wrote at 20:14 4/13/2005:
In article <ma**************************************@python.o rg>,
Dick Moores <rd*@rcblue.com> wrote:
Dan wrote at 18:02 4/13/2005:
On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rd*@rcblue.com>
wrote:

> I'm just trying to help an artist acquaintance who needs (I just
>learned) the first 3003 digits of pi to the base 12.

Now you've got me curious. Why would an artist want the first 3003
digits of pi to the base 12?
He says,
Do you know how I can get "base12 pi"?
Because the chromatic scale is base12.
c c# d d# e f f# g g# a a# b

Dick

Does your artist friend have any idea what base 12 means?

The chromatic scale is based on one twelfth powers of two, i.e., if the
frequency of a note in the scale is f(n), then the frequency of the next
note is given by

f(n+1) = f(n) * 2^(1/12)

so by the time you go all 12 notes in an octave you have doubled the
frequency. There is nothing here involving base 12 or pi.

He's a friend of a friend. I don't know what he knows, but I'll forward
this to MY friend. Thanks.

Dick

--
Doug Schwarz
Make obvious changes to get real email address.
--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #27
Hi. I would like to freeze python application on linux. There are a
few tools that make the job to be done:
freeze ( comes with python )
cx_Freeze
Gordon McMillan's installer
Is it possible to freeze python application on linux in such way that
it doesn't depends on python installed on cu
Jul 18 '05 #28
Sorry for previous post - hit the wrong button

Hi. I would like to freeze python application on linux. There are a
few tools that make the job to be done:
freeze ( comes with python )
cx_Freeze
Gordon McMillan's installer

I have one problem with all of them: they require python to be
installed on target machine.
May be I missed something or did not understand right the docs? Also
if I am right could you point me to "freeze" tool that doesn't require
python installed on customer computer?

For windows I have py2exe. What should I use for linux to get same affect?

Thanks

Roman
Jul 18 '05 #29
On Wed, 13 Apr 2005 21:52:45 GMT, bo**@oz.net (Bengt Richter) wrote:
[...]

If you replace
a, a1 = 10L*(a%b), 10L*(a1%b1)
with
a, a1 = 12L*(a%b), 12L*(a1%b1)

and
sys.stdout.write(`int(d)`)
with
sys.stdout.write('%X'%d`) Typo, sorry ----------------^
that back-tick should not be there ;-/
and run it, I think it will do what you want, even though I haven't worked through exactly
what it's doing, though it's pretty. (For confidence I just tried it and decoded the result
far enough to match math.pi exactly ;-)

(the %X formats hex, but for single digits that's fine for base 12, giving A for 10 and B for 11.
If you want bases >16 you'll have to use something like '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'[digitvalue])

BTW, I would make this into a base-parameterized generator, something like
def pigen(base=10, ndigits=True): ... base = long(base)
... k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L
... while ndigits:
... # Next approximation
... p, q, k = k*k, 2L*k+1L, k+1L
... a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
... # Print common digits
... d, d1 = a/b, a1/b1
... while d == d1:
... yield int(d)
... if ndigits is not True:
... ndigits -= 1
... if ndigits == 0: break
... a, a1 = base*(a%b), base*(a1%b1)
... d, d1 = a/b, a1/b1
... def pidigits(base, ndigits=True, digchars='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'): ... assert base>=2 and base <= len(digchars) and ndigits>=0
... for d in pigen(base, ndigits):
... yield digchars[d]

[ I just realized the original had tabs, so the above is fixed and pasted after the below ]
... import sys
for d in pidigits(10, 60): sys.stdout.write(d) ...
31415926535897932384626433832795028841971693993751 0582097494>>>
print ''.join(d for d in pidigits(10,60) ...
... )
31415926535897932384626433832795028841971693993751 0582097494 print ''.join(d for d in pidigits(10,60)) 31415926535897932384626433832795028841971693993751 0582097494 print ''.join(d for d in pidigits(12,60)) 3184809493B918664573A6211BB151551A05729290A7809A49 2742140A60 print ''.join(d for d in pidigits(26,60)) 33HIGBEBOHJHE3DB7DGJ6AK3G6JK8HND4G12A1IP8LGGL63C4B CK4NHE8G8O print ''.join(d for d in pidigits(36,60)) 353I5AB8P5FSA5JHK72I8ASC47WWZLACLJJ9ZN98LTXM61VYMS 1FRYTCI4U2 print ''.join(d for d in pidigits( 2,60)) 30010010000111111011010101000100010000101101000110 0001000110
for d in pidigits(10): sys.stdout.write(d); sys.stdout.flush() ...
31415926535897932384626433832795028841971693993751 0582097494459230781640628620899862803482534211
70679821480865132823066470938446095505822317253594 0812848111745028410270193852110555964462294895
49303819644288109756659334461284756482337867831652 7120190914564856692346034861045432664821339360
72602491412737245870066063155881748815209209628292 5409171536436789259036001133053054882046652138
41469519415116094330572703657595919530921861173819 3261179310511854807446237996274956735188575272
48912279381830119491298336733624406566430860213949 4639522473719070217986094370277053921717629317
67523846748184676694051320005681271452635608277857 7134275778960917363717872146844090122495343014
65495853710507922796892589235420199561121290219608 6403441815981362977477130996051870721134999999
83729780499510597317328160963185950244594553469083 0264252230825334468503526193118817101000313783
87528865875332083814206171776691473035982534904287 5546873115956286388235378759375195778185778053
21712268066130019278766111959092164201989380952572 0106548586327886593615338182796823030195203530
18529689957736225994138912497217752834791315155748 5724245415069595082953311686172785588907509838
17546374649393192550604009277016711390098488240128 5836160356370766010471018194295559619894676783
74494482553797747268471040475346462080466842590694 912933136770289891521047521Traceback (most rec
ent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in pidigits
File "<stdin>", line 16, in pigen
KeyboardInterrupt

To make a file for your friend,
open('pi12.txt','w').write(''.join(c for c in pidigits(12, 3003)))
That didn't take very long. No line breaks though. You can do that quick and dirty with
open('pi12by60.txt','w').write( ... ''.join(c+'\n'[:(i+1)%60==0] for i,c in enumerate(pidigits(12, 3003)))+'\n')

(adding the last EOL since we know 3003%60 =!0 ;-)

You could speed up the initial burst a lot, but after a while the data passing overhead is not
a significant part of the whole time.

Hm, ... that first digit still needs to be fixed for base <4 ;-)

Regards,
Bengt Richter
Jul 18 '05 #30
On Thu, 14 Apr 2005 03:14:51 GMT, Doug Schwarz <se*@sig.for.address.edu> wrote:
In article <ma**************************************@python.o rg>,
Dick Moores <rd*@rcblue.com> wrote:
Dan wrote at 18:02 4/13/2005:
>On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rd*@rcblue.com>
>wrote:
>
> > I'm just trying to help an artist acquaintance who needs (I just
> >learned) the first 3003 digits of pi to the base 12.
>
>Now you've got me curious. Why would an artist want the first 3003
>digits of pi to the base 12?
He says,
Do you know how I can get "base12 pi"?
Because the chromatic scale is base12.
c c# d d# e f f# g g# a a# b

Dick

Does your artist friend have any idea what base 12 means?

Maybe he wants to play sounds of pi and has found base 10 digits don't
hit all the notes, and he may not be as dumb as you think ;-)
The chromatic scale is based on one twelfth powers of two, i.e., if the
frequency of a note in the scale is f(n), then the frequency of the next
note is given by

f(n+1) = f(n) * 2^(1/12)

so by the time you go all 12 notes in an octave you have doubled the
frequency. There is nothing here involving base 12 or pi.

I expect something interesting and imaginative ;-)
It might also be interesting to keep a running sum of the base 12 values
and use sum % 88 to select piano keys, to let it walk intervals outside
of a single octave ;-)

I found using different base digits to draw end-to-end vectors selected from
equal vectors equally spaced in all base directions for a "random" walk picture
was interesting. I also changed the color according to various criteria such
as digit run length ending on the current digit. Maybe the artist could scale
that up and put it on the wall as backdrop to the music ;-)
It would be easy to generate postscript for it, that could be scaled up and
printed wall size. Or pdf. I'm tempted to play with my pdf plotting toy and
maybe make it work ;-)

I'm kind of curious what the ear could pick up about pi from hearing the sequence
as notes. Or intervals, or grouped to make chords even. Anyone have an easy python
midi interface for windows to play on the sound card? I could generate a .wav file
to play tones, but midi would be much more compact ;-)

Regards,
Bengt Richter
Jul 18 '05 #31
On Thu, 14 Apr 2005 11:05:17 +1000, John Machin <sj******@lexicon.net> wrote:
On Wed, 13 Apr 2005 08:28:29 -0400, Roy Smith <ro*@panix.com> wrote:
"Dan Bishop" <da*****@yahoo.com> wrote:
But there's no reason other than tradition why you should arrange them
into groups of 10.

Well, it is traditional for people to have 10 fingers :-)

According to anthropology archives, there was once a tribe called
"OS/360 system programmers" who would cut off their thumbs and great
toes in order that they might better count in hexadecimal.

I suspect using four dates back to the nixie tribe, who practiced bi-quinary.
And they would cut off little toes and fingers rather, because then the thumb
was more significant and it was easier to remember it as 5 (or 0 if hidden)
with the rest counting octally ;-)

Regards,
Bengt Richter
Jul 18 '05 #32
On 13 Apr 2005 18:20:06 -0700, Paul Rubin <http://ph****@NOSPAM.invalid> wrote:
Dick Moores <rd*@rcblue.com> writes:
I need to figure out how to compute pi to base 12, to as many digits
as possible. I found this reference,
<http://mathworld.wolfram.com/Base.html>, but I really don't
understand it well enough. Could someone show me how to do what I need?

Using the GNU "bc" utility:

\$ bc -l
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale = 3000 # number of output places wanted
obase = 12 # output base
print 4 * a(1) # pi = 4*arctan(1)
3.184809493B918664573A6211BB151551A05729290A7809A4 92742140A60A55256A\
0661A03753A3AA54805646880181A3683083272BBBA0A370B1 2265529A828903B4B2\
56B8403759A71626B8A54687621849B849A8225616B442796A 31737B229B23914898\
53943B8763725616447236B027A421AA17A38B52A18A838B01 514A51144A23315A30\
09A8906B61B8B48A62253A88A50A43BA094457231593366447 6B3AABB77583975120\
683526B75B462060BB03B432551913772729A2147553531793 848A0402B999B50585\
35374465A68806716644039539A8431935198527B9399B1129 90ABB0383B10764542\
4577A51601B3624A88B7A676A3992912121A213887B9287394 6A61332242217AA735\
4115357744939112602BA4B888818A3269222B528487747839 994AB223B65B876269\
5422822669BA00A586097842A51750362073B5A768363B21BB 1A97A4A19444774939\
9804922175A068A46739461990A2065BB0A30BBAB7024A585B 1A84428195489784A0\
7A331A7B0A1574565B373B05B03A5A80A13AB8785773467998 5558A5373178A7B282\
71992A3894A5776085083B9B238B2220542462888641A2BAB8 B3083AB49659172A31\
2B78518654494A068662586A181835A64440B2970A12281397 589881536720890580\
1032881449223841428763329617531239B9A6574055840145 34390B587625606BB8\
0923795944B43757A431B039556282978A6A49590553490BA1 844947175637A90824\
7B50127722464441380A852B0847B5813019BB70A67663B426 565434069884476132\
193344BA55A2128A03838974606B851B2979321A408067225A 5AA4B3464A1A174735\
95333909AB9127079655B3164B68B9B28A9B818A220A025AB0 934203995B7A62A7AA\
739355340539BA3182905B193905603A43B660B9426A922946 97144A896A5B233935\
8BB2B7294BB89635B071A6351211360B820B1882AB8433B547 57B87A373284B1BA18\
2A10326476B369A4A6365B58B8018994BB152556765475A704 BB94B6B2A39458971A\
8B90512786B5029404818644323552916170B3ABB736349642 7B088B68725A685700\
40617949289077B278069A09B559324B8A66828B40549B0296 065B2300330592569A\
7B76B92BA1293585B6A9B604567A0901362856373B4B568979 46256B4172B1B50474\
351364749A33996A81BA8847347A8411B850B79A0301829167 2AA0945656A159AA6A\
A0A845531A592005B8A34366B882257107B190969A84647483 6A9800750778920BA7\
97297A2791101B0685A86BB704B9BAA17B055293679843B352 15B0A8B1182B611953\
B080AA5431B219907A8448A81B1A9493245676B88013B47033 524085959415862101\
4216619553246570601967448B470174B92448924448174538 65A4003B5AA7176451\
AAB90681A949786154AA040477382BA69371041710B8728458 A23979252B25423675\
3A44A1900AA283536A227648812525743868B410A567794663 359A6726A528678332\
8135114789B7645505B047848020A730A9557B206776AA56A1 9682744107901306B2\
9008808619866B4911A05264B872A46B5376383932699531B4 49195640B62A636228\
30886247A47B3957169861239358041AA281333622AA15912B 0A636047A489BB0726\
282A78B96671B27305A9652496B9B999011A7BA36898891665 B1A6009058978850A2\
1B01A158A1473B84A192B8672542A2A7056581995207A436A5 B3BA2824637A3112AB\
B57176468206A071200A327B3216425148100786502AA21236 ABB35499277670A126\
9730583403B1922A483856007301983989159BB688A58B6023 39806B63002A339A50\
B0BA533B84827793913081070A32595A101803A9A20234691B 1A0B623274B69B0B44\
688195169461059543A252BB05208720BA13118266A872B26B 9B584959B44B
quit
\$

The arctan calculation takes about 20 sec on an Athlon of around 2 ghz.

That's cool. I will have to find out about bc. Thanks ;-)

Interesting to note, it also took about 20 sec on my _old_ machine:
from time import clock
def foo(): ... t0 = clock()
... open('pi12by60.txt','w').write(
... ''.join(c+'\n'[:(i+1)%60==0] for i,c in enumerate(pidigits(12, 3003)))+'\n')
... print clock()-t0
... foo()

22.3866400935

That's on a 300Mhz Pentium II using the Lambert Meertens algorithm for pi ;-)

Regards,
Bengt Richter
Jul 18 '05 #33

[Dan]
Now you've got me curious. Why would an artist want the first 3003
digits of pi to the base 12?
[Dick] He says,
Do you know how I can get "base12 pi"?
Because the chromatic scale is base12.
c c# d d# e f f# g g# a a# b

Landscapes", from "Dirk Gently's Holistic Detective Agency":

"I believe that there must be a form of
music inherent in nature, in natural objects, in the patterns
of natural processes. A music that would be as deeply
satisfying as any naturally occurring beauty [...]"

You can see the text here:
http://66.102.9.104/search?q=cache:3...capes%22&hl=en

or via this tinyurl:

http://tinyurl.com/6ugnk

(Search within that page for the phrase "Music and Fractal Landscapes".

--
Richie Hindle
ri****@entrian.com

Jul 18 '05 #34
> He says,
Do you know how I can get "base12 pi"?
Because the chromatic scale is base12.
c c# d d# e f f# g g# a a# b

Dick

It might feel more "natural" to do this with 'e' (2.718...)
--greg

Jul 18 '05 #35
[Doug Schwarz]
The chromatic scale is based on one twelfth powers of two, i.e., if
the frequency of a note in the scale is f(n), then the frequency of
the next note is given by f(n+1) = f(n) * 2^(1/12)

This easy view of things has been known for a long time, but has only
been popular (relatively) recently. Traditionally, scale designers were
definitely running after rational proportions between scale notes, not
fearing some problems they necessarily create, because such scales are
often nicer and interesting to the musical ear.

I should relate this discussion to Python somehow! :-) Easy, as I have a
few Python programs doing various scale computations -- I should try to
bundle these together somewhere in my personal Web site, some day...

--
François Pinard http://pinard.progiciels-bpi.ca
Jul 18 '05 #36
[Bengt Richter]
It might also be interesting to keep a running sum of the base 12
values and use sum % 88 to select piano keys, to let it walk intervals
outside of a single octave ;-)
The generated would then run from the low octaves to high octaves
monotically, then start over again and again.

Maybe a more interesting approach might be to pick the note in the same
octave, the octave below or above, where the new note is closest to the
preceding one.
a "random" walk picture was interesting.
Using the closest note would have similarity with a random walk, given
Ï€ digits are seemingly random. On a random walk, one gets away from
the departure point on average, the distance being proportional to
sqrt(N) where N is the number of steps. So, when using the closest
note, one would need a corrective device nevertheless so notes are kept
near the middle of the range of comfortable audible frequencies.
Anyone have an easy python midi interface for windows to play on the
sound card? I could generate a .wav file to play tones, but midi
would be much more compact ;-)

There are surely many. I use my own (Python) interfaces on Linux, and
even there, by combining a few tools, it is rather easy to get .WAV
files out of MIDI. In any case, googling around might help.

--
FranÃ§ois Pinard http://pinard.progiciels-bpi.ca
Jul 18 '05 #37
On 13 Apr 2005 19:05:01 -0700, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
Dick Moores <rd*@rcblue.com> writes:
I don't believe GNU "bc" is available for Windows, is it?

I don't know. It probably works ok under Cygwin at least.

bc definitely works on cygwin, and is available at
http://gnuwin32.sourceforge.net/packages/bc.htm for windows. Make sure
you download both the dependencies and the binary package for it to
work. I put the dll from the dependancy archive in c:/winnt/system32
and it worked.

It should be noted that running the win32 bc from cygwin messed up my
terminal, so I recommend running it from a cmd window (which worked
fine).

Peace
Bill Mill
bill.mill at gmail.com
Jul 19 '05 #38
me********@aol.com <me********@aol.com> wrote:
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.
import gmpy
from math import log
bits = int(3003*log(12)/log(2))
pi=gmpy.pi(bits+100)
gmpy.fdigits(pi, 12, 3003)

'3.184809493b918664573a6211bb151551a05729290a7809a 492742140a60a55256a0661a03753a3aa54805646880181a36 83083272bbba0a370b12265529a828903b4b256b8403759a71 626b8a54687621849b849a8225616b442796a31737b229b239 1489853943b8763725616447236b027a421aa17a38b52a18a8 38b01514a51144a23315a3009a8906b61b8b48a62253a88a50 a43ba0944572315933664476b3aabb77583975120683526b75 b462060bb03b432551913772729a2147553531793848a0402b 999b5058535374465a68806716644039539a8431935198527b 9399b112990abb0383b107645424577a51601b3624a88b7a67 6a3992912121a213887b92873946a61332242217aa73541153 57744939112602ba4b888818a3269222b528487747839994ab 223b65b8762695422822669ba00a586097842a51750362073b 5a768363b21bb1a97a4a194447749399804922175a068a4673 9461990a2065bb0a30bbab7024a585b1a84428195489784a07 a331a7b0a1574565b373b05b03a5a80a13ab87857734679985 558a5373178a7b28271992a3894a5776085083b9b238b22205 42462888641a2bab8b3083ab49659172a312b78518654494a0 68662586a181835a64440b2970a12281397589881536720890 5801032881449223841428763329617531239b9a6574055840 14534390b587625606bb80923795944b43757a431b03955628 2978a6a49590553490ba1844947175637a908247b501277224 64441380a852b0847b5813019bb70a67663b42656543406988 4476132193344ba55a2128a03838974606b851b2979321a408 067225a5aa4b3464a1a17473595333909ab9127079655b3164 b68b9b28a9b818a220a025ab0934203995b7a62a7aa7393553 40539ba3182905b193905603a43b660b9426a92294697144a8 96a5b2339358bb2b7294bb89635b071a6351211360b820b188 2ab8433b54757b87a373284b1ba182a10326476b369a4a6365 b58b8018994bb152556765475a704bb94b6b2a39458971a8b9 0512786b5029404818644323552916170b3abb7363496427b0 88b68725a68570040617949289077b278069a09b559324b8a6 6828b40549b0296065b2300330592569a7b76b92ba1293585b 6a9b604567a0901362856373b4b56897946256b4172b1b5047 4351364749a33996a81ba8847347a8411b850b79a030182916 72aa0945656a159aa6aa0a845531a592005b8a34366b882257 107b190969a846474836a9800750778920ba797297a2791101 b0685a86bb704b9baa17b055293679843b35215b0a8b1182b6 11953b080aa5431b219907a8448a81b1a9493245676b88013b 470335240859594158621014216619553246570601967448b4 70174b9244892444817453865a4003b5aa7176451aab90681a 949786154aa040477382ba69371041710b8728458a23979252 b254236753a44a1900aa283536a227648812525743868b410a 567794663359a6726a5286783328135114789b7645505b0478 48020a730a9557b206776aa56a19682744107901306b290088 08619866b4911a05264b872a46b5376383932699531b449195 640b62a63622830886247a47b3957169861239358041aa2813 33622aa15912b0a636047a489bb0726282a78b96671b27305a 9652496b9b999011a7ba36898891665b1a6009058978850a21 b01a158a1473b84a192b8672542a2a7056581995207a436a5b 3ba2824637a3112abb57176468206a071200a327b321642514 8100786502aa21236abb35499277670a1269730583403b1922 a483856007301983989159bb688a58b602339806b63002a339 a50b0ba533b84827793913081070a32595a101803a9a202346 91b1a0b623274b69b0b44688195169461059543a252bb05208 720ba13118266a872b26b9b584959b45179519534b221a335a 2bb6971b3276b3a63a5b791723109b176529bb90651584279b 7825712521b8269800738b07a62b1454788441445122409293 7165625696557a78799a82126613535a36b410309b75997611 9777b895801074b9779b9b5137538b2799951012273399bb81 8b722@0'

--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Jul 19 '05 #39

Nick Craig-Wood wrote:
me********@aol.com <me********@aol.com> wrote:
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?

import gmpy
from math import log
bits = int(3003*log(12)/log(2))
pi=gmpy.pi(bits+100)
gmpy.fdigits(pi, 12, 3003)

'3.184809493b918664573a6211bb151551a05729290a7809a 492742140a60a55256a0661a03753a3aa54805646880181a36 83083272bbba0a370b12265529a828903b4b256b8403759a71 626b8a54687621849b849a8225616b442796a31737b229b239 1489853943b8763725616447236b027a421aa17a38b52a18a8 38b01514a51144a23315a3009a8906b61b8b48a62253a88a50 a43ba0944572315933664476b3aabb77583975120683526b75 b462060bb03b432551913772729a2147553531793848a0402b 999b5058535374465a68806716644039539a8431935198527b 9399b112990abb0383b107645424577a51601b3624a88b7a67 6a3992912121a213887b92873946a61332242217aa73541153 57744939112602ba4b888818a3269222b528487747839994ab 223b65b8762695422822669ba00a586097842a51750362073b 5a768363b21bb1a97a4a194447749399804922175a068a4673 9461990a2065bb0a30bbab7024a585b1a84428195489784a07 a331a7b0a1574565b373b05b03a5a80a13ab87857734679985 558a5373178a7b28271992a3894a5776085083b9b238b22205 42462888641a2bab8b3083ab49659172a312b78518654494a0 68662586a181835a64440b2970a12281397589881536720890 5801032881449223841428763329617531239b9a6574055840 14534390b587625606bb80923795944b43757a431b03955628 2978a6a49590553490ba1844947175637a908247b501277224 64441380a852b0847b5813019bb70a67663b42656543406988 4476132193344ba55a2128a03838974606b851b2979321a408 067225a5aa4b3464a1a17473595333909ab9127079655b3164 b68b9b28a9b818a220a025ab0934203995b7a62a7aa7393553 40539ba3182905b193905603a43b660b9426a92294697144a8 96a5b2339358bb2b7294bb89635b071a6351211360b820b188 2ab8433b54757b87a373284b1ba182a10326476b369a4a6365 b58b8018994bb152556765475a704bb94b6b2a39458971a8b9 0512786b5029404818644323552916170b3abb7363496427b0 88b68725a68570040617949289077b278069a09b559324b8a6 6828b40549b0296065b2300330592569a7b76b92ba1293585b 6a9b604567a0901362856373b4b56897946256b4172b1b5047 4351364749a33996a81ba8847347a8411b850b79a030182916 72aa0945656a159aa6aa0a845531a592005b8a34366b882257 107b190969a846474836a9800750778920ba797297a2791101 b0685a86bb704b9baa17b055293679843b35215b0a8b1182b6 11953b080aa5431b219907a8448a81b1a9493245676b88013b 470335240859594158621014216619553246570601967448b4 70174b9244892444817453865a4003b5aa7176451aab90681a 949786154aa040477382ba69371041710b8728458a23979252 b254236753a44a1900aa283536a227648812525743868b410a 567794663359a6726a5286783328135114789b7645505b0478 48020a730a9557b206776aa56a19682744107901306b290088 08619866b4911a05264b872a46b5376383932699531b449195 640b62a63622830886247a47b3957169861239358041aa2813 33622aa15912b0a636047a489bb0726282a78b96671b27305a 9652496b9b999011a7ba36898891665b1a6009058978850a21 b01a158a1473b84a192b8672542a2a7056581995207a436a5b 3ba2824637a3112abb57176468206a071200a327b321642514 8100786502aa21236abb35499277670a1269730583403b1922 a483856007301983989159bb688a58b602339806b63002a339 a50b0ba533b84827793913081070a32595a101803a9a202346 91b1a0b623274b69b0b44688195169461059543a252bb05208 720ba13118266a872b26b9b584959b45179519534b221a335a 2bb6971b3276b3a63a5b791723109b176529bb90651584279b 7825712521b8269800738b07a62b1454788441445122409293 7165625696557a78799a82126613535a36b410309b75997611 9777b895801074b9779b9b5137538b2799951012273399bb81 8b722@0'
--
Nick Craig-Wood <ni**@craig-wood.com> --

http://www.craig-wood.com/nick

Jul 19 '05 #40
Steve Holden wrote at 22:29 4/13/2005:
Dick Moores wrote:
Steve Holden wrote at 19:12 4/13/2005:
Dick Moores wrote:

Dan wrote at 18:02 4/13/2005:

>On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rd*@rcblue.com>
>wrote:
>
> > I'm just trying to help an artist acquaintance who needs (I just
> >learned) the first 3003 digits of pi to the base 12.
>
>Now you've got me curious. Why would an artist want the first 3003
>digits of pi to the base 12?
He says,
Do you know how I can get "base12 pi"?
Because the chromatic scale is base12.
c c# d d# e f f# g g# a a# b
Dick

So it's, like, the guy is going to "play pi"? So why does the melody
have 3003 notes?

Sorry, he's just a friend of a friend. If I find out I'll post. Here's
his site if you want to poke around for yourself. Maybe his email
Dick

Where?

Dick
Jul 19 '05 #41
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

Jul 19 '05 #42
Dick Moores wrote:
Paul Rubin wrote at 18:20 4/13/2005:
Dick Moores <rd*@rcblue.com> writes:
I need to figure out how to compute pi to base 12, to as many digits as possible. I found this reference,
<http://mathworld.wolfram.com/Base.html>, but I really don't
understand it well enough. Could someone show me how to do what I
need?
Using the GNU "bc" utility:

\$ bc -l
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale = 3000 # number of output places wanted
obase = 12 # output base
print 4 * a(1) # pi = 4*arctan(1)

I don't believe GNU "bc" is available for Windows, is it?

Thanks,

Dick Moores
rd*@rcblue.com

Nice collection of unix tools, Cygwin not needed.
http://unxutils.sourceforge.net/
hth,
M.E.Farmer

Jul 19 '05 #43
M.E.Farmer wrote at 23:18 4/14/2005:
Using the GNU "bc" utility:

\$ bc -l
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation,Inc. This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale = 3000 # number of output places wanted
obase = 12 # output base
print 4 * a(1) # pi = 4*arctan(1)

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
Jul 19 '05 #44
Dick Moores wrote:
M.E.Farmer wrote at 23:18 4/14/2005:
> >Using the GNU "bc" utility:
> >
> > \$ bc -l
> > bc 1.06
> > Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation,

Inc.
> > This is free software with ABSOLUTELY NO WARRANTY.
> > For details type `warranty'.
> > scale = 3000 # number of output places wanted
> > obase = 12 # output base
> > print 4 * a(1) # pi = 4*arctan(1)

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

--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton

Roel Schroeven
Jul 19 '05 #45
On Sun, 17 Apr 2005 01:00:46 -0700, Dick Moores <rd*@rcblue.com> wrote:
M.E.Farmer wrote at 23:18 4/14/2005:
> >Using the GNU "bc" utility:
> >
> > \$ bc -l
> > bc 1.06
> > Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation,

Inc.
> > This is free software with ABSOLUTELY NO WARRANTY.
> > For details type `warranty'.
> > scale = 3000 # number of output places wanted
> > obase = 12 # output base
> > print 4 * a(1) # pi = 4*arctan(1)

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
Jul 19 '05 #46
Roel Schroeven wrote at 01:45 4/17/2005:
Dick Moores wrote:
M.E.Farmer wrote at 23:18 4/14/2005:
> >Using the GNU "bc" utility:
> >
> > \$ bc -l
> > bc 1.06
> > Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation,
Inc.
> > This is free software with ABSOLUTELY NO WARRANTY.
> > For details type `warranty'.
> > scale = 3000 # number of output places wanted
> > obase = 12 # output base
> > print 4 * a(1) # pi = 4*arctan(1)
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

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

Thanks! You've just relieved years of frustration.

Dick

Jul 19 '05 #47
Dick Moores <rd*@rcblue.com> writes:
C:\cygwin\bin\bc -l > pi12.txt

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
Jul 19 '05 #48
Bengt Richter wrote at 02:26 4/17/2005:
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

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

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
Jul 19 '05 #49
Paul Rubin wrote at 02:35 4/17/2005:
Dick Moores <rd*@rcblue.com> writes:
C:\cygwin\bin\bc -l > pi12.txt

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

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

Jul 19 '05 #50