On May 22, 2009, at 3:36 AM, Kevin Horton wrote:

> I am using sage-4.0.rc0 on 32 bit ubuntu 8.10.
>
> I have discovered a very strange interaction between the "Integer=int"
> declaration, division, and the number of times a worksheet is  
> evaluated.

This is an error due to literal constant extraction, I thought there  
was a ticket for this on trac but was unable to find it for the moment.

> Consider the following worksheet.  The very first time it is
> evaluated, division is handled as float division, and the results are
> what I hoped for.  But, if I evaluate the cell again, I get a
> different answer.  This time the division seems to be python integer
> division, and I get a different result.  I keep getting this second
> result until I restart the worksheet, then I get the first result for
> a single evaluation.
>
> Regardless of what the correct behaviour is, I would hope to get the
> same behaviour every time I evaluate the worksheet.  This looks like a
> bug to me.
>
> ================================
> First evaluation after restarting worksheet:
>
> Division Error?
> system:sage
>
> {{{id=2|
> Integer=int
>
> print float(500/1000), float(1000/1000)
> print float(500/1000.), float(1000/1000.)
> ///
>
> 0.5 1.0
> 0.5 1.0
> }}}

To see what is really going on, this gets turned into

{{{
print sage.misc.preparser.preparse_file("""
Integer=int

print float(500/1000), float(1000/1000)
print float(500/1000.), float(1000/1000.)
""")
///
_sage_const_500 = Integer(500); _sage_const_1000 = Integer(1000);
_sage_const_1000p = RealNumber('1000.')
Integer=int

print float(_sage_const_500 /_sage_const_1000 ), float 
(_sage_const_1000/_sage_const_1000 )
print float(_sage_const_500 /_sage_const_1000p ), float 
(_sage_const_1000/_sage_const_1000p )
}}}

We do this to avoid the (large) overhead of re-creating constants in  
the bodies of loops, functions, etc. Perhaps we need to detect the  
Integer=xxx line explicitly?

- Robert


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

Reply via email to