Ask Your Question
1

function within sum or product term

asked 2021-02-03 23:59:22 +0100

Thrash gravatar image

updated 2021-02-03 23:59:32 +0100

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
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-02-04 00:10:19 +0100

slelievre gravatar image

updated 2021-02-04 23:03:29 +0100

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:

edit flag offensive delete link more

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: 2021-02-03 23:59:22 +0100

Seen: 230 times

Last updated: Feb 04 '21