From: tim_one at email.msn.com (Tim Peters)
Date: Tue, 13 Apr 1999 02:06:20 GMT
Subject: role of semilcolon
In-Reply-To: <slrn7h4q72.mou.rasumner@bach.wisdom.weizmann.ac.il>
References: <slrn7h4q72.mou.rasumner@bach.wisdom.weizmann.ac.il>
Message-ID: <000801be8552$393f1300$97a02299@tim>
Content-Length: 1897
X-UID: 600                                                  

[Reuben Sumner]
> In the python interpreter doing 'a=1;b=2;b=3' does what I would
> expect, three seperate assignments.  However ; doesn't seem to appear
> in the language reference except in the list of delimeters.  Is the
> above example formally valid python?

Yup, and the semicolon's formal role in the grammar is captured in the
non-terminal "stmt_list", which you'll find in the manual's chapter on
compound statements.

Note that you'll hardly ever see a semicolon in an experienced Python
programmer's code, though!  "a, b, c = 1, 2, 3" is more idiomatic for what
you did above, and in general Python is succinct so you can afford to write
code readably and still fit a major algorithm on a single screen.

> BTW as you can tell I am a newbie

Yes:  nobody else ever looks at the reference manual <wink>.

> but I am impressed with the ease at which I was able to implement
> some number theoretic algorithms (gcd, primaility testing, pollard
> rho factoring, jacobian...)

So let's pick on gcd.  Here's the bare-bones idiomatic way to spell that:

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

Close to what you did?  Finding the *fastest* way to write gcd in Python is
something I've been working on for years <wink>.

> Is there a big practical difference between using long numbers and
> the mpz package?  (is the latter faster)

Python's bigint implementation is straightforward, very compact (in code
size), and extremely portable.  It wasn't aiming at speed or completeness.
In contrast, the GNU GMP package has been labored over for years, with
hyper-optimized core assembler routines on most major platforms.  If you
need peak speed, use that.  At one time Andrew Kuckling combined the two,
but don't know how usable that still is; see the first link at:

     http://starship.python.net/crew/amk/python/code.html

big-ints-for-big-brains-ly y'rs  - tim






