Opened 3 years ago
Last modified 3 years ago
#25282 needs_info defect
Add .is_prime() function for symbolic expression
Reported by: | vklein | Owned by: | vklein |
---|---|---|---|
Priority: | major | Milestone: | sage-8.4 |
Component: | symbolics | Keywords: | |
Cc: | vdelecroix, rws | Merged in: | |
Authors: | Vincent Klein | Reviewers: | Vincent Delecroix |
Report Upstream: | N/A | Work issues: | |
Branch: | u/vklein/fix__is_prime___for_symbolic_expression (Commits, GitHub, GitLab) | Commit: | b46350d2c4b68d836c3b3d9e4ec8b236ca7c3807 |
Dependencies: | Stopgaps: |
Description (last modified by )
Fix the following behaviour :
sage: f(n)=n^2 sage: f(3).is_prime() --------------------------------------------------------------------------- NotImplementedError Traceback (most recent call last) <ipython-input-2-9727cba91e39> in <module>() ----> 1 f(Integer(3)).is_prime() /home/vklein/odk/sage/src/sage/structure/element.pyx in sage.structure.element.RingElement.is_prime (build/cythonized/sage/structure/element.c:19230)() 2741 if not self: # We exclude the 0 element 2742 return False -> 2743 return self._parent.ideal(self).is_prime() 2744 2745 /home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/rings/ideal.pyc in is_prime(self) 822 ass = self.associated_primes() 823 except (NotImplementedError, ValueError): --> 824 raise NotImplementedError 825 if len(ass) != 1: 826 return False NotImplementedError:
Change History (14)
comment:1 Changed 3 years ago by
- Description modified (diff)
comment:2 Changed 3 years ago by
- Owner changed from (none) to vklein
comment:3 Changed 3 years ago by
- Summary changed from Fix .is_prime() for symbolic expression to Add .is_prime() function for symbolic expression
comment:4 Changed 3 years ago by
- Branch set to u/vklein/fix__is_prime___for_symbolic_expression
comment:5 Changed 3 years ago by
- Commit set to f46abe6c0e167d03c89c6d2f347347c3d8f0f1a2
- Status changed from new to needs_review
comment:6 Changed 3 years ago by
- Description modified (diff)
comment:7 Changed 3 years ago by
- Commit changed from f46abe6c0e167d03c89c6d2f347347c3d8f0f1a2 to b46350d2c4b68d836c3b3d9e4ec8b236ca7c3807
comment:8 Changed 3 years ago by
comment:9 Changed 3 years ago by
- Cc vdelecroix rws added; videlec removed
comment:10 follow-up: ↓ 11 Changed 3 years ago by
- Reviewers set to Vincent Delecroix
- Status changed from needs_review to needs_work
- Instead of
prime number
I would rather useprime integer
.
- Because of the changes in this branch, the following
sage: is_prime(SR(2/3)) Traceback (most recent call last): ... TypeError: no conversion of this rational to integer
becomessage: is_prime(SR(2/3)) False
you need to check whetherself.pyobject()
is actually an integer.
- (possibly for a later ticket) I think that a cleaner way to proceed is to introduce a symbolic
is_prime
function that would also handle variables likesage: factorial(x) factorial(x) sage: factorial(x).subs(x=3) 6
In other words the following should ideally worksage: n = SR.var('n') sage: assume(n, 'integer') sage: is_prime(n) is_prime(n) sage: is_prime(n).subs(n=3) True
You can have a look atsage.functions.other
.
comment:11 in reply to: ↑ 10 ; follow-up: ↓ 12 Changed 3 years ago by
Replying to vdelecroix:
- Because of the changes in this branch, the following
sage: is_prime(SR(2/3)) Traceback (most recent call last): ... TypeError: no conversion of this rational to integerbecomessage: is_prime(SR(2/3)) Falseyou need to check whetherself.pyobject()
is actually an integer.
On the other hand even without this branch we have this :
sage: is_prime(2/3) False
Shouldn't is_prime(SR(2/3))
and is_prime(2/3)
behave the same way ?
The next question is if we want "This number is not an integer and therefore it is not prime" or "This number is not an integer so calling is_prime on it is an error"
comment:12 in reply to: ↑ 11 Changed 3 years ago by
Replying to vklein:
Replying to vdelecroix:
- Because of the changes in this branch, the following
sage: is_prime(SR(2/3)) Traceback (most recent call last): ... TypeError: no conversion of this rational to integerbecomessage: is_prime(SR(2/3)) Falseyou need to check whetherself.pyobject()
is actually an integer.
On the other hand even without this branch we have this :
sage: is_prime(2/3) FalseShouldn't
is_prime(SR(2/3))
andis_prime(2/3)
behave the same way ?
Perhaps.
The next question is if we want "This number is not an integer and therefore it is not prime" or "This number is not an integer so calling is_prime on it is an error"
I think so, see https://groups.google.com/forum/#!topic/sage-devel/NN0VP-OVZLw (but definitely a distinct ticket)
comment:13 Changed 3 years ago by
- Status changed from needs_work to needs_info
This ticket is on hold. A discussion about what is_prime
should do is in progress : How much do we support the casual user.
comment:14 Changed 3 years ago by
- Milestone changed from sage-8.3 to sage-8.4
milestone update 8.3 -> 8.4
Branch pushed to git repo; I updated commit sha1. New commits:
Trac #25282: Add is_prime() function to synmbolic ...