Ask Your Question

Mertens Function Error

asked 2014-12-10 03:38:44 -0500

Kevin Smith gravatar image

updated 2015-01-14 05:19:54 -0500

FrédéricC gravatar image

I am new to Sage, so I suppose the answer to this is ridiculously obvious, but please go easy on me!

I have an error when I try to get Mertens function as an output yet: I know the summation works for other functions; and I know the Moebius function is defined on the range. So what's going on?

This is the input and output:

sage: var('j')
sage: f = moebius(j) 
TypeError                                 Traceback (most recent call last)
----> f=moebius(j)
TypeError: 'sage.symbolic.expression.Expression' object is not iterable
edit retag flag offensive close merge delete


Hello, I rewrote your example with identation (if you indent with four spaces you get a nice presentation of the code) and keeping only the relevant part of the traceback.

vdelecroix gravatar imagevdelecroix ( 2014-12-10 03:54:04 -0500 )edit

Thank you.

Kevin Smith gravatar imageKevin Smith ( 2014-12-10 03:56:45 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2014-12-10 03:48:56 -0500

FrédéricC gravatar image

You cannot make sums with symbolic bounds, or at least it does not work very often.

Rather do something like that:

sage: def mertens(n):
....:     return sum(moebius(i) for i in range(1, n+1))
sage: mertens(6)
sage: mertens(66)
sage: mertens(691)
edit flag offensive delete link more


Thank you! Is there an obvious reason why this only works sporadically? I would like to know.

Kevin Smith gravatar imageKevin Smith ( 2014-12-10 03:58:36 -0500 )edit

You have to have a symbolic function, and then you have to have a symbolic function that Maxima would be able to do summation on, I guess. See for a step in that direction - this would indeed be useful.

kcrisman gravatar imagekcrisman ( 2014-12-10 07:50:15 -0500 )edit

Could you please upvote my answer (by clicking on the up arrow on the left) if it suits you ?

FrédéricC gravatar imageFrédéricC ( 2014-12-10 14:08:08 -0500 )edit

Sorry it seems I dont have enough rep to up vote yet.

Kevin Smith gravatar imageKevin Smith ( 2015-01-03 05:31:16 -0500 )edit

You should be able to accept it, though...

kcrisman gravatar imagekcrisman ( 2015-01-03 16:41:36 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-12-10 03:38:44 -0500

Seen: 80 times

Last updated: Dec 10 '14