Ask Your Question
1

function within sum or product term

asked 4 years ago

Thrash gravatar image

updated 4 years ago

If I have a normal product, everything works well:

sage: product(x,x,2,3)                                                          
6

But if I have a function inside the product term, I get a value error:

sage: product(nth_prime(x),x,2,3)
ValueError: cannot convert x to int

sage: product(nth_prime(ZZ(x)),x,2,3)
TypeError: unable to convert x to an integer

The output should be

sage: nth_prime(2)*nth_prime(3)                                                 
15
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 4 years ago

slelievre gravatar image

updated 4 years ago

The problem is that product is the symbolic product, but nth_prime cannot take a symbolic argument.

One could open a ticket to make nth_prime accept symbolic arguments.

Or use prod and a generator with comprehension syntax:

sage: prod(nth_prime(x) for x in (2 .. 3))
15

Related ticket:

Preview: (hide)
link

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

Stats

Asked: 4 years ago

Seen: 246 times

Last updated: Feb 04 '21