[sage-support] weird inequality bug...

2011-05-31 Thread J. Maurice Rojas
Dear Sage Gurus,

I was playing with Sage and discovered what appears to be a
really weird bug with Sage's checking of inequalities.

In the attached code, I generate some random 2x2 linear equations
with integer coefficients, and I try to find the minimum and maximum
coordinates of the resulting solutions.  However, somehow, the maxima
are computed but the minima are not.

   In particular, when I run the attached code on my machine, I get (random)
values of x[0] and maxx with x[0]=maxx (as expected). However,
minx and miny always (incorrectly) remain at +Infinity, even though
x[0] is always less than minx!

   I am a newcomer to Sage so I apologize if I've missed something
dumb. But as of this moment, I'm completely stumped as to why my
simple program is behaving so strangely.

   Hope to hear from you soon.

 Best Wishes,

 Maurice

P.S.:  I get this bug when running my program on my lenovo X201s
laptop, running
 Ubuntu LTS 10.04, and Sage Version 4.6.2, Release Date: 2011-02-25 .

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


bug.sage
Description: Binary data


Re: [sage-support] weird inequality bug...

2011-05-31 Thread D. S. McNeil
The key here is understanding exactly what x[0] is: it's not a
rational.  If you run your code (after adding the line
set_random_seed(3) at the start to make sure we're working with the
same matrices), you see:

sage: minx, maxx, miny, maxy
(+Infinity, (3), +Infinity, (21/5))

and the odd parentheses should hint at the problem:

sage: type(maxx), type(maxy)
(type 'sage.modules.vector_rational_dense.Vector_rational_dense',
type 'sage.modules.vector_rational_dense.Vector_rational_dense')
sage: x[0]
(5/7)
sage: type(x[0])
type 'sage.modules.vector_rational_dense.Vector_rational_dense'

We're not comparing the rational 5/7 with infinity, we're comparing
the *vector* (5/7,) -- comma inserted for clarity -- with infinity.
Anyway, comparisons between things which shouldn't be compared tend to
give weird results if they work:

sage: x = 5/7
sage: x  infinity # good
True
sage: x  infinity # good
False
sage: x = vector([5/7])
sage: x  infinity
False
sage: x  infinity
True
sage: 5/7  vector([0.0])
True

If you replace x[0] by x[0][0], and x[1] by x[1][0], so that you're
comparing the entries and not the row vectors, it should do what you
expect.  (You could also use x = x.list() to coerce to a list and then
x[0] and x[1] will work, I guess, but that kind of hides what's going
on.)


Hope that helps,

Doug

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org