syntax error in sum(). Please explicate.

2006-11-18 Thread Michael Press
I have not written python codes nor run any. I saw this
code posted and decided to try it. It fails. I read the
tutorial and the entry for the built in function sum,
but still do not see the problem. The code was cut and
paste. Please help. Thanks.

_BEGIN_CODE_
#!/usr/bin/python

ps = [none, 2,3,5,7,11,13,17,19,23,29]

def phi(x, a):
return x - sum(phi(x // ps[i+1], i) for i in range(a))

def pi(n):
from math import sqrt
if n <= 1:
return 0
a = pi(int(sqrt(n)))
return phi(n, a) + a - 1
__END_CODE__

Here is the result of running it:

  File "/Users/mdp/source/prime_counter_python", line 6
return x - sum(phi(x // ps[i+1], i) for i in range(a))
  ^
SyntaxError: invalid syntax

Here are some lines from python -v:

Python 2.3 (#1, Sep 13 2003, 00:49:11) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information

-- 
Michael Press
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: syntax error in sum(). Please explicate.

2006-11-18 Thread Michael Press
In article 
<[EMAIL PROTECTED]>
,
 "Matt Moriarity" <[EMAIL PROTECTED]> wrote:

> try surrounding your sum argument in brackets:
> 
> sum([phi(x // ps[i+1], i) for i in range(a)])
> 
> instead of:
> 
> sum(phi(x // ps[i+1], i) for i in range(a))

Thank you. That makes it work.

-- 
Michael Press
-- 
http://mail.python.org/mailman/listinfo/python-list


May I ask about Sage here?

2009-04-29 Thread Michael Press
May I ask for help with Sage problems here?  I
did not find a usenet Sage support group. If so,
here is a session I imitated from the tutorial.
The "load command failed. I logged output with
"logstart", then quit, started, executed "load",
and "load" failed to work.

__
 --
 | Sage Version 3.4.1, Release Date: 2009-04-21   |
 | Type notebook() for the GUI, and license() for information.|
 --
 sage: logstart setup
 Activating auto-logging. Current session state plus future input saved.
 Filename   : setup
 Mode   : backup
 Output logging : False
 Raw input log  : False
 Timestamping   : False
 State  : active
 sage: E = EllipticCurve([1,2,3,4,5]).minimal_model()
 sage: F = QQ^3
 sage: x,y = QQ['x,y'].gens()
 sage: G = E.gens()
 sage: exit
 Exiting SAGE (CPU time 0m0.27s, Wall time 0m11.10s).

 Script done on Wed Apr 29 17:23:57 2009
 Script started on Wed Apr 29 17:24:12 2009
 --
 | Sage Version 3.4.1, Release Date: 2009-04-21   |
 | Type notebook() for the GUI, and license() for information.|
 --
 sage: load "setup"
 ---
 IOError   Traceback (most recent call last)

 /Users/mdp/.sage/ in ()

 
/Applications/sage/local/lib/python2.5/site-packages/sage/structure/sage_object.so
 in sage.structure.sage_object.load (sage/structure/sage_object.c:6200)()

 IOError: [Errno 2] No such file or directory: 'setup.sobj'
 sage: exit
 Exiting SAGE (CPU time 0m0.85s, Wall time 0m11.08s).

$ ls -lF
total 16
drwxr-xr-x   2 mdp  staff68 Apr 29 16:37 db/
drwxr-xr-x   4 mdp  staff   136 Apr 29 16:37 gap/
drwxr-xr-x@ 14 mdp  staff   476 Apr 29 16:53 ipython/
drwxr-xr-x   7 mdp  staff   238 Apr 29 16:44 sage_notebook/
-rw-r--r--   1 mdp  staff   546 Apr 29 17:23 setup
drwxr-xr-x   4 mdp  staff   136 Apr 29 17:22 temp/
-rw-r--r--   1 mdp  staff  1684 Apr 29 17:24 typescript

__

-- 
Michael Press
--
http://mail.python.org/mailman/listinfo/python-list


Re: May I ask about Sage here?

2009-05-01 Thread Michael Press
In article 
<899b6a05-942a-4229-b3aa-f9099e171...@g31g2000pra.googlegroups.com>,
 alex23  wrote:

> On Apr 30, 11:06 am, Michael Press  wrote:
> > May I ask for help with Sage problems here?  I
> > did not find a usenet Sage support group.
> 
> http://www.sagemath.org/help-groups.html
> http://groups.google.com/group/sage-support/

Thanks.

-- 
Michael Press
--
http://mail.python.org/mailman/listinfo/python-list


Multiprecision arithmetic library question.

2008-06-17 Thread Michael Press
I already compiled and installed the GNU multiprecision library
on Mac OS X, and link to it in C programs. 
How do I link to the library from Python? 
I do not want to download and install redundant material.
(I am new to Python)

-- 
Michael Press
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiprecision arithmetic library question.

2008-06-18 Thread Michael Press
In article <[EMAIL PROTECTED]>,
 Mark Wooding <[EMAIL PROTECTED]> wrote:

> Michael Press <[EMAIL PROTECTED]> wrote:
> 
> > I already compiled and installed the GNU multiprecision library
> > on Mac OS X, and link to it in C programs. 
> > How do I link to the library from Python? 
> 
> You know that Python already supports multiprecision integer arithmetic,
> right?  If you desperately want GMP, though, there's the gmpy module
> (q.g.).

No, I do not know that. Define desperate. 
Does Python support the extended Euclidean algorithm
and other number theory functions?
How fast does Python multiply?
Not that the latter is particularly important,
as C is built for speed.

I've been fooling around. Ran dir(gmpy), and 
it does not show the full complement of GMP
library functions, such as the various division
functions. e.g. mpz_tdiv_qr.

-- 
Michael Press
--
http://mail.python.org/mailman/listinfo/python-list


Re: Nonlinear least square problem

2008-04-04 Thread Michael Press
In article 
<[EMAIL PROTECTED]>,
 Uwe Kotyczka <[EMAIL PROTECTED]> wrote:

> Hallo, sorry for multiposting, but I am really looking
> for some hint to solve my problem. And no, I don't
> use Matlab, but maybe the matlab people have an idea
> nevertheless.

No apology required, since you seem to have 
cross-posted appropriately, and not multi-posted.
Multi-posting is posting the same message one
at a time to more than one group. I see in
the Newsgroups: header line that you posted
to several groups at once. Furthermore the
number of groups is not out of bounds, and
the groups are appropriate to the question
and, presumably, your interests. 

Unfortunately, I cannot help with the actual question. :)

-- 
Michael Press
-- 
http://mail.python.org/mailman/listinfo/python-list