On Thu, Oct 18, 2012 at 2:13 PM, Ken Ribet <[email protected]> wrote:

> Thanks to everyone for the explanation of why my comparison of rational
> numbers did not work.  I'd like to make two comments:
>
> 1. I got into this mess by trying to count points above and below the line
> in the standard textbook proof of quadratic reciprocity.  You have two odd
> primes p and q, make the grid of integers whose x-coordinates run between 1
> and (p-1)/2 and whose y-coordinates run between 1 and (q-1)/2, and draw the
> line through the origin with slope q/p.  I drew a beautiful picture for my
> students but then miscounted the points below the line by using a rational
> number comparison instead of the apparently equivalent integer comparison
> (gotten by cross-multiplying).  The count looked more realistic after I
> cross-multiplied!
>
> 2. It occurred to me that the integers that I was dividing were of the
> wrong "type."  I asked sage what was going on and interpreted the output
>     <type 'int'>
> as referring to a standard sage integer.  I had no clue that I should have
> been looking for
>    <type 'sage.rings.integer.Integer'>
>   Ken
>

You're certainly not the only user of Sage (or Python for that matter) to
run into this problem -- it has happened a lot.

At least exactly this problem is not something  that will be around
forever.  In Python 3 (the next major revision of Python after the 2.x
series that Sage uses), they've removed this confusing int division
behavior:

wstein@combinat:~$ python3
Python 3.2.3 (default, Sep 10 2012, 18:14:40)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 2/3                    # not preparsed
0.6666666666666666

I'm not thrilled about getting a floating point answer, but it's better
than getting 0 in this case...

I don't know when we'll switch Sage to Python 3... maybe in a year or so.

 -- William



>  --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> Visit this group at http://groups.google.com/group/sage-support?hl=en.
>
>
>



-- 
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/sage-support?hl=en.


Reply via email to