#5140: is_irreducible() reports units as irreducible
--------------------------+-------------------------------------------------
Reporter: lars.fischer | Owner: tbd
Type: defect | Status: new
Priority: trivial | Milestone:
Component: algebra | Keywords: is_irreducible
--------------------------+-------------------------------------------------
= Description of the bug =
The following happens with
{{{
----------------------------------------------------------------------
| SAGE Version 3.1.2, Release Date: 2008-09-19 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
}}}
'''The function is_irreducible returns True on units:'''
{{{
sage: R.<x>=PolynomialRing( IntegerModRing(13),'x')
sage: (x^2-2).is_irreducible()
True
sage: (x^2).is_irreducible()
False
sage: R(1).is_irreducible()
True
}}}
The last line should say False or raise an exception as
R(0).is_irreducible() does. Because irreducibility of B requires B to be
not zero and not a unit.
= Use case where this bug occured to me =
If I want to loop over polynomials in R and count irreducible ones, I need
a loop like this:
{{{
for p in R.polynomials(max_degree=3):
if not p.is_zero() and not p.is_unit() and p.is_irreducible():
# count p
}}}
It is easy to forget the check if p is a unit. Then the count would be
wrong.
= Bug-Fix =
The bug is in the implementation:
{{{
e=R(1)
e.is_irreducible??
}}}
shows as code after the docstring:
{{{
if self.is_zero():
raise ValueError, "self must be nonzero"
if self.degree() == 0:
return True
}}}
'''I propose to insert a check'''
{{{
if self.is_unit():
raise ValueError, "self must not be a unit"
}}}
between the above ifs. I created a file via commit and bundle with this
modification.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/5140>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of
Reinventing the Wheel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---