#8601: Bug in vector reduction
------------------------------+---------------------------------------------
Reporter: robertwb | Owner: was
Type: defect | Status: new
Priority: critical | Milestone: sage-4.4
Component: linear algebra | Keywords:
Author: | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
------------------------------+---------------------------------------------
Comment(by jason):
If after line 150 of vector_mod2_dense.pyx, you put the line:
{{{
print xi, type(xi), xi%2
}}}
you see that the problem happens because in the Cython file, -1%2 is -1,
not 1. Apparently the C standard doesn't specify what happens if you mod
with a negative number; some compilers return positive numbers, some
return negative numbers.
Here is a patch which fixes the issue. I don't have time to formalize it
and upload it right now.
{{{
diff -r c04df7b7f023 sage/modules/vector_mod2_dense.pyx
--- a/sage/modules/vector_mod2_dense.pyx Thu Mar 18 01:56:14 2010
-0500
+++ b/sage/modules/vector_mod2_dense.pyx Wed Mar 24 20:12:27 2010
-0500
@@ -137,6 +137,8 @@
(0, 0, 1)
sage: VS((0,0,GF(2)(1)))
(0, 0, 1)
+ sage: VS((-1,-2,-3))
+ (1, 0, 1)
"""
cdef Py_ssize_t i
cdef int xi
@@ -146,7 +148,8 @@
for i from 0 <= i < self._degree:
if PY_TYPE_CHECK(x[i],IntegerMod_int) or
PY_TYPE_CHECK(x[i],int) or PY_TYPE_CHECK(x[i],Integer):
xi = x[i]
- mzd_write_bit(self._entries, 0, i, xi%2)
+ # the if/else statement is because some in some
compilers, (-1)%2 is -1
+ mzd_write_bit(self._entries, 0, i, 0 if xi%2==0 else
1)
else:
mzd_write_bit(self._entries, 0, i, x[i]%2)
return
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8601#comment:5>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
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.