Compute pi to base 12 using Python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan

    #16
    Re: Compute pi to base 12 using Python?

    On 13 Apr 2005 12:06:26 -0400, roy@panix.com (Roy Smith) wrote:
    [color=blue]
    >Scott David Daniels <Scott.Daniels@ Acm.Org> wrote:[color=green]
    >>If you think those are fun, try base (1j - 1)[/color]
    >
    >Get real. I can't imagine using anything so complex.[/color]

    Well said. :-)

    Dan

    Comment

    • Dan

      #17
      Re: Compute pi to base 12 using Python?

      On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rdm@rcblue.com >
      wrote:
      [color=blue]
      > I'm just trying to help an artist acquaintance who needs (I just
      >learned) the first 3003 digits of pi to the base 12.[/color]

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

      Dan

      Comment

      • John Machin

        #18
        Re: Compute pi to base 12 using Python?

        On Wed, 13 Apr 2005 08:28:29 -0400, Roy Smith <roy@panix.co m> wrote:
        [color=blue]
        >In article <1113390479.738 210.49530@z14g2 000cwz.googlegr oups.com>,
        > "Dan Bishop" <danb_83@yahoo. com> wrote:
        >[color=green]
        >> But there's no reason other than tradition why you should arrange them
        >> into groups of 10.[/color]
        >
        >Well, it is traditional for people to have 10 fingers :-)[/color]

        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.



        Comment

        • Dick Moores

          #19
          Re: Compute pi to base 12 using Python?

          Dan wrote at 18:02 4/13/2005:[color=blue]
          >On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rdm@rcblue.com >
          >wrote:
          >[color=green]
          > > I'm just trying to help an artist acquaintance who needs (I just
          > >learned) the first 3003 digits of pi to the base 12.[/color]
          >
          >Now you've got me curious. Why would an artist want the first 3003
          >digits of pi to the base 12?[/color]

          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


          Comment

          • Paul Rubin

            #20
            Re: Compute pi to base 12 using Python?

            Dick Moores <rdm@rcblue.com > writes:[color=blue]
            > I need to figure out how to compute pi to base 12, to as many digits
            > as possible. I found this reference,
            > <http://mathworld.wolfr am.com/Base.html>, but I really don't
            > understand it well enough. Could someone show me how to do what I need?[/color]

            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.184809493B918 664573A6211BB15 1551A05729290A7 809A492742140A6 0A55256A\
            0661A03753A3AA5 4805646880181A3 683083272BBBA0A 370B12265529A82 8903B4B2\
            56B8403759A7162 6B8A54687621849 B849A8225616B44 2796A31737B229B 23914898\
            53943B876372561 6447236B027A421 AA17A38B52A18A8 38B01514A51144A 23315A30\
            09A8906B61B8B48 A62253A88A50A43 BA0944572315933 664476B3AABB775 83975120\
            683526B75B46206 0BB03B432551913 772729A21475535 31793848A0402B9 99B50585\
            35374465A688067 16644039539A843 1935198527B9399 B112990ABB0383B 10764542\
            4577A51601B3624 A88B7A676A39929 12121A213887B92 873946A61332242 217AA735\
            411535774493911 2602BA4B888818A 3269222B5284877 47839994AB223B6 5B876269\
            5422822669BA00A 586097842A51750 362073B5A768363 B21BB1A97A4A194 44774939\
            9804922175A068A 46739461990A206 5BB0A30BBAB7024 A585B1A84428195 489784A0\
            7A331A7B0A15745 65B373B05B03A5A 80A13AB87857734 679985558A53731 78A7B282\
            71992A3894A5776 085083B9B238B22 20542462888641A 2BAB8B3083AB496 59172A31\
            2B78518654494A0 68662586A181835 A64440B2970A122 813975898815367 20890580\
            103288144922384 142876332961753 1239B9A65740558 4014534390B5876 25606BB8\
            0923795944B4375 7A431B039556282 978A6A495905534 90BA18449471756 37A90824\
            7B5012772246444 1380A852B0847B5 813019BB70A6766 3B4265654340698 84476132\
            193344BA55A2128 A03838974606B85 1B2979321A40806 7225A5AA4B3464A 1A174735\
            95333909AB91270 79655B3164B68B9 B28A9B818A220A0 25AB0934203995B 7A62A7AA\
            739355340539BA3 182905B19390560 3A43B660B9426A9 2294697144A896A 5B233935\
            8BB2B7294BB8963 5B071A635121136 0B820B1882AB843 3B54757B87A3732 84B1BA18\
            2A10326476B369A 4A6365B58B80189 94BB15255676547 5A704BB94B6B2A3 9458971A\
            8B90512786B5029 404818644323552 916170B3ABB7363 496427B088B6872 5A685700\
            40617949289077B 278069A09B55932 4B8A66828B40549 B0296065B230033 0592569A\
            7B76B92BA129358 5B6A9B604567A09 01362856373B4B5 6897946256B4172 B1B50474\
            351364749A33996 A81BA8847347A84 11B850B79A03018 291672AA0945656 A159AA6A\
            A0A845531A59200 5B8A34366B88225 7107B190969A846 474836A98007507 78920BA7\
            97297A2791101B0 685A86BB704B9BA A17B05529367984 3B35215B0A8B118 2B611953\
            B080AA5431B2199 07A8448A81B1A94 93245676B88013B 470335240859594 15862101\
            421661955324657 0601967448B4701 74B924489244481 7453865A4003B5A A7176451\
            AAB90681A949786 154AA040477382B A69371041710B87 28458A23979252B 25423675\
            3A44A1900AA2835 36A227648812525 743868B410A5677 94663359A6726A5 28678332\
            8135114789B7645 505B047848020A7 30A9557B206776A A56A19682744107 901306B2\
            9008808619866B4 911A05264B872A4 6B5376383932699 531B449195640B6 2A636228\
            30886247A47B395 716986123935804 1AA281333622AA1 5912B0A636047A4 89BB0726\
            282A78B96671B27 305A9652496B9B9 99011A7BA368988 91665B1A6009058 978850A2\
            1B01A158A1473B8 4A192B8672542A2 A7056581995207A 436A5B3BA282463 7A3112AB\
            B57176468206A07 1200A327B321642 5148100786502AA 21236ABB3549927 7670A126\
            9730583403B1922 A48385600730198 3989159BB688A58 B602339806B6300 2A339A50\
            B0BA533B8482779 3913081070A3259 5A101803A9A2023 4691B1A0B623274 B69B0B44\
            688195169461059 543A252BB052087 20BA13118266A87 2B26B9B584959B4 4B
            quit
            $

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

            Comment

            • Ivan Van Laningham

              #21
              Re: Compute pi to base 12 using Python?

              Hi All--

              Dick Moores wrote:[color=blue]
              >
              > Dan wrote at 18:02 4/13/2005:[color=green]
              > >On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rdm@rcblue.com >
              > >wrote:
              > >[color=darkred]
              > > > I'm just trying to help an artist acquaintance who needs (I just
              > > >learned) the first 3003 digits of pi to the base 12.[/color]
              > >
              > >Now you've got me curious. Why would an artist want the first 3003
              > >digits of pi to the base 12?[/color]
              >
              > 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
              >[/color]

              Oooh. Wanta hear it.

              Metta,
              Ivan
              ----------------------------------------------
              Ivan Van Laningham
              God N Locomotive Works


              Army Signal Corps: Cu Chi, Class of '70
              Author: Teach Yourself Python in 24 Hours

              Comment

              • Dick Moores

                #22
                Re: Compute pi to base 12 using Python?

                Paul Rubin wrote at 18:20 4/13/2005:[color=blue]
                >Dick Moores <rdm@rcblue.com > writes:[color=green]
                > > I need to figure out how to compute pi to base 12, to as many digits
                > > as possible. I found this reference,
                > > <http://mathworld.wolfr am.com/Base.html>, but I really don't
                > > understand it well enough. Could someone show me how to do what I need?[/color]
                >
                >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)[/color]

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

                Thanks,

                Dick Moores
                rdm@rcblue.com

                Comment

                • Paul Rubin

                  #23
                  Re: Compute pi to base 12 using Python?

                  Dick Moores <rdm@rcblue.com > writes:[color=blue]
                  > I don't believe GNU "bc" is available for Windows, is it?[/color]

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

                  Comment

                  • Steve Holden

                    #24
                    Re: Compute pi to base 12 using Python?

                    Dick Moores wrote:[color=blue]
                    > Dan wrote at 18:02 4/13/2005:
                    >[color=green]
                    >> On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rdm@rcblue.com >
                    >> wrote:
                    >>[color=darkred]
                    >> > I'm just trying to help an artist acquaintance who needs (I just
                    >> >learned) the first 3003 digits of pi to the base 12.[/color]
                    >>
                    >> Now you've got me curious. Why would an artist want the first 3003
                    >> digits of pi to the base 12?[/color]
                    >
                    >
                    > 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
                    >
                    >[/color]
                    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/

                    Comment

                    • Steve Holden

                      #25
                      Re: Compute pi to base 12 using Python?

                      Dan wrote:[color=blue]
                      > On 13 Apr 2005 12:06:26 -0400, roy@panix.com (Roy Smith) wrote:
                      >
                      >[color=green]
                      >>Scott David Daniels <Scott.Daniels@ Acm.Org> wrote:
                      >>[color=darkred]
                      >>>If you think those are fun, try base (1j - 1)[/color]
                      >>
                      >>Get real. I can't imagine using anything so complex.[/color]
                      >
                      >
                      > Well said. :-)
                      >[/color]
                      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/

                      Comment

                      • Doug Schwarz

                        #26
                        Re: Compute pi to base 12 using Python?

                        In article <mailman.1865.1 113441561.1799. python-list@python.org >,
                        Dick Moores <rdm@rcblue.com > wrote:
                        [color=blue]
                        > Dan wrote at 18:02 4/13/2005:[color=green]
                        > >On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rdm@rcblue.com >
                        > >wrote:
                        > >[color=darkred]
                        > > > I'm just trying to help an artist acquaintance who needs (I just
                        > > >learned) the first 3003 digits of pi to the base 12.[/color]
                        > >
                        > >Now you've got me curious. Why would an artist want the first 3003
                        > >digits of pi to the base 12?[/color]
                        >
                        > 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[/color]

                        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
                        dmschwarz&urgra d,rochester,edu
                        Make obvious changes to get real email address.

                        Comment

                        • Dick Moores

                          #27
                          Re: Compute pi to base 12 using Python?

                          Doug Schwarz wrote at 20:14 4/13/2005:[color=blue]
                          >In article <mailman.1865.1 113441561.1799. python-list@python.org >,
                          > Dick Moores <rdm@rcblue.com > wrote:
                          >[color=green]
                          > > Dan wrote at 18:02 4/13/2005:[color=darkred]
                          > > >On Wed, 13 Apr 2005 03:27:06 -0700, Dick Moores <rdm@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?[/color]
                          > >
                          > > 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[/color]
                          >
                          >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.[/color]

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

                          Dick

                          [color=blue]
                          >--
                          >Doug Schwarz
                          >dmschwarz&urgr ad,rochester,ed u
                          >Make obvious changes to get real email address.
                          >--
                          >http://mail.python.org/mailman/listinfo/python-list[/color]

                          Comment

                          • Roman Yakovenko

                            #28
                            Freezing python application

                            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

                            Comment

                            • Roman Yakovenko

                              #29
                              Re: Freezing python application

                              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

                              Comment

                              • Bengt Richter

                                #30
                                Re: Compute pi to base 12 using Python?

                                On Wed, 13 Apr 2005 21:52:45 GMT, bokr@oz.net (Bengt Richter) wrote:
                                [...][color=blue]
                                >
                                >If you replace
                                > a, a1 = 10L*(a%b), 10L*(a1%b1)
                                >with
                                > a, a1 = 12L*(a%b), 12L*(a1%b1)
                                >
                                >and
                                > sys.stdout.writ e(`int(d)`)
                                >with
                                > sys.stdout.writ e('%X'%d`)[/color]
                                Typo, sorry ----------------^
                                that back-tick should not be there ;-/[color=blue]
                                >
                                >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 '0123456789ABCD EFGHIJKLMNOPQRS TUVWXYZ'[digitvalue])
                                >
                                >[/color]
                                BTW, I would make this into a base-parameterized generator, something like
                                [color=blue][color=green][color=darkred]
                                >>> def pigen(base=10, ndigits=True):[/color][/color][/color]
                                ... 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
                                ...[color=blue][color=green][color=darkred]
                                >>> def pidigits(base, ndigits=True, digchars='01234 56789ABCDEFGHIJ KLMNOPQRSTUVWXY Z'):[/color][/color][/color]
                                ... 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 ]
                                ...[color=blue][color=green][color=darkred]
                                >>> import sys
                                >>> for d in pidigits(10, 60): sys.stdout.writ e(d)[/color][/color][/color]
                                ...
                                314159265358979 323846264338327 950288419716939 937510582097494 >>>[color=blue][color=green][color=darkred]
                                >>>
                                >>> print ''.join(d for d in pidigits(10,60)[/color][/color][/color]
                                ...
                                ... )
                                314159265358979 323846264338327 950288419716939 937510582097494[color=blue][color=green][color=darkred]
                                >>> print ''.join(d for d in pidigits(10,60) )[/color][/color][/color]
                                314159265358979 323846264338327 950288419716939 937510582097494[color=blue][color=green][color=darkred]
                                >>> print ''.join(d for d in pidigits(12,60) )[/color][/color][/color]
                                3184809493B9186 64573A6211BB151 551A05729290A78 09A492742140A60[color=blue][color=green][color=darkred]
                                >>> print ''.join(d for d in pidigits(26,60) )[/color][/color][/color]
                                33HIGBEBOHJHE3D B7DGJ6AK3G6JK8H ND4G12A1IP8LGGL 63C4BCK4NHE8G8O[color=blue][color=green][color=darkred]
                                >>> print ''.join(d for d in pidigits(36,60) )[/color][/color][/color]
                                353I5AB8P5FSA5J HK72I8ASC47WWZL ACLJJ9ZN98LTXM6 1VYMS1FRYTCI4U2[color=blue][color=green][color=darkred]
                                >>> print ''.join(d for d in pidigits( 2,60))[/color][/color][/color]
                                300100100001111 110110101010001 000100001011010 001100001000110[color=blue][color=green][color=darkred]
                                >>>
                                >>> for d in pidigits(10): sys.stdout.writ e(d); sys.stdout.flus h()[/color][/color][/color]
                                ...
                                314159265358979 323846264338327 950288419716939 937510582097494 459230781640628 620899862803482 534211
                                706798214808651 328230664709384 460955058223172 535940812848111 745028410270193 852110555964462 294895
                                493038196442881 097566593344612 847564823378678 316527120190914 564856692346034 861045432664821 339360
                                726024914127372 458700660631558 817488152092096 282925409171536 436789259036001 133053054882046 652138
                                414695194151160 943305727036575 959195309218611 738193261179310 511854807446237 996274956735188 575272
                                489122793818301 194912983367336 244065664308602 139494639522473 719070217986094 370277053921717 629317
                                675238467481846 766940513200056 812714526356082 778577134275778 960917363717872 146844090122495 343014
                                654958537105079 227968925892354 201995611212902 196086403441815 981362977477130 996051870721134 999999
                                837297804995105 973173281609631 859502445945534 690830264252230 825334468503526 193118817101000 313783
                                875288658753320 838142061717766 914730359825349 042875546873115 956286388235378 759375195778185 778053
                                217122680661300 192787661119590 921642019893809 525720106548586 327886593615338 182796823030195 203530
                                185296899577362 259941389124972 177528347913151 557485724245415 069595082953311 686172785588907 509838
                                175463746493931 925506040092770 167113900984882 401285836160356 370766010471018 194295559619894 676783
                                744944825537977 472684710404753 464620804668425 906949129331367 702898915210475 21Traceback (most rec
                                ent call last):
                                File "<stdin>", line 1, in ?
                                File "<stdin>", line 3, in pidigits
                                File "<stdin>", line 16, in pigen
                                KeyboardInterru pt

                                To make a file for your friend,
                                [color=blue][color=green][color=darkred]
                                >>> open('pi12.txt' ,'w').write(''. join(c for c in pidigits(12, 3003)))[/color][/color][/color]

                                That didn't take very long. No line breaks though. You can do that quick and dirty with
                                [color=blue][color=green][color=darkred]
                                >>> open('pi12by60. txt','w').write ([/color][/color][/color]
                                ... ''.join(c+'\n'[:(i+1)%60==0] for i,c in enumerate(pidig its(12, 3003)))+'\n')[color=blue][color=green][color=darkred]
                                >>>[/color][/color][/color]

                                (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

                                Comment

                                Working...