Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to use prime_range with a formula instead of an integer

Hi. First post here, so please tell me if I'm not doing this right. Thanks.

I want to find all the primes in a range defined by a formula rather than an integer. I tried:

  1. a=n^2+1
  2. b=(n+1)^2-1
  3. 0 is less than n is less than 21 (I tried typing this here in help with just the symbols, but the preview only showed "0" if I did that.)
  4. prime_range(a,b)

and got the error message:

TypeError Traceback (most recent call last) <ipython-input-1-9910057c7272> in <module>

----> 1 a=n**Integer(2)+Integer(1)

  2 b=(n+Integer(1))**Integer(2)-Integer(1)

  3 Integer(0)<n<Integer(20)

  4 prime_range(a,b)

/home/sc_serv/sage/local/lib/python3.9/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.__pow__ (build/cythonized/sage/rings/integer.c:15218)()

2206 return coercion_model.bin_op(left, right, operator.pow)

2207 # left is a non-Element: do the powering with a Python int

-> 2208 return left ** int(right)

2209

2210 cpdef _pow_(self, other):

TypeError: unsupported operand type(s) for ** or pow(): 'function' and 'int'

Can you tell me how to get the result I am looking for? Thank you!

How to use prime_range with a formula instead of an integer

Hi. First post here, so please tell me if I'm not doing this right. Thanks.

I want to find all the primes in a range defined by a formula rather than an integer. I tried:

  1. a=n^2+1
  2. b=(n+1)^2-1
  3. 0 is less than n is less than 21 (I tried typing this here in help with just the symbols, but the preview only showed "0" if I did that.)
  4. prime_range(a,b)

and got the error message:

TypeError Traceback (most recent call last) <ipython-input-1-9910057c7272> in <module>

----> 1 a=n**Integer(2)+Integer(1)

  2 b=(n+Integer(1))**Integer(2)-Integer(1)

  3 Integer(0)<n<Integer(20)

  4 prime_range(a,b)

/home/sc_serv/sage/local/lib/python3.9/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.__pow__ (build/cythonized/sage/rings/integer.c:15218)()

2206 return coercion_model.bin_op(left, right, operator.pow)

2207 # left is a non-Element: do the powering with a Python int

-> 2208 return left ** int(right)

2209

2210 cpdef _pow_(self, other):

TypeError: unsupported operand type(s) for ** or pow(): 'function' and 'int'

Can you tell me how to get the result I am looking for? Thank you!

How to use prime_range with a formula instead of an integer

Hi. First post here, so please tell me if I'm not doing this right. Thanks.

I want to find all the primes in a range defined by a formula rather than an integer. I tried:

  1. a=n^2+1
  2. b=(n+1)^2-1
  3. 0 is less than n is less than 21 (I tried typing this here in help with just the symbols, but the preview only showed "0" if I did that.)
  4. prime_range(a,b)

and got the error message:

TypeError Traceback (most recent call last) <ipython-input-1-9910057c7272> in <module>

----> 1 a=n**Integer(2)+Integer(1)

  2 b=(n+Integer(1))**Integer(2)-Integer(1)

  3 Integer(0)<n<Integer(20)

  4 prime_range(a,b)

/home/sc_serv/sage/local/lib/python3.9/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.__pow__ (build/cythonized/sage/rings/integer.c:15218)()

2206 return coercion_model.bin_op(left, right, operator.pow)

2207 # left is a non-Element: do the powering with a Python int

-> 2208 return left ** int(right)

2209

2210 cpdef _pow_(self, other):

TypeError: unsupported operand type(s) for ** or pow(): 'function' and 'int'

Can you tell me how to get the result I am looking for? Thank you!

How to use prime_range with a formula instead of an integer

Hi. First post here, so please tell me if I'm not doing this right. Thanks.

I want to find all the primes in a range defined by a formula rather than an integer. I tried:

  1. a=n^2+1
  2. b=(n+1)^2-1
  3. 0 is less than n is less than 21 (I tried typing this here in help with just the symbols, but the preview only showed "0" if I did that.)
  4. prime_range(a,b)

and got the error message:

TypeError                                 Traceback (most recent call last)
<ipython-input-1-9910057c7272> in <module>

<module> ----> 1 a=n**Integer(2)+Integer(1)

a=n**Integer(2)+Integer(1)
      2 b=(n+Integer(1))**Integer(2)-Integer(1)
    3 Integer(0)<n<Integer(20)
    4 prime_range(a,b)

/home/sc_serv/sage/local/lib/python3.9/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.__pow__ (build/cythonized/sage/rings/integer.c:15218)()

(build/cythonized/sage/rings/integer.c:15218)() 2206 return coercion_model.bin_op(left, right, operator.pow)

operator.pow) 2207 # left is a non-Element: do the powering with a Python int

int -> 2208 return left ** int(right)

int(right) 2209

2210 cpdef _pow_(self, other):

other): TypeError: unsupported operand type(s) for ** or pow(): 'function' and 'int'

'int'

Can you tell me how to get the result I am looking for? Thank you!