On Mon, Dec 13, 2010 at 12:16 PM, Chris Seberino <cseber...@gmail.com> wrote:
>
> OK thanks for your help.  I think I got it.   The effect of RealField
> is like creating a new number type.  I need to make sure all my real
> are of the right type.  It appears integers are fine as is.

Yes, exactly. Exact types (e.g. integers, rationals, symbolic
expressions) will get converted to the correct degree of precision.

> Here is working code...
>
> def test(big):
>    my_pi      = RealField(big)(pi)
>    ten        = RealField(big)(10.0)
>    constant   = 100 * sqrt(my_pi/log(ten))
>    ten_thou   = RealField(big)(10000.0)
>    f(k)       = ten^(-k^2/ten_thou)
>    the_sum    = RealField(big)(sum(f(k) for k in range(-big, big +
> 1)))
>    difference = the_sum - constant
>    return difference

You can be a bit simpler then this. E.g.

sage: R = RealField(1000)

sage: constant = R(100 * sqrt(pi/log(10))) # everything exact before the cast

sage: ten_thou = R(10000)

sage: f(k) = 10^(-k^2/ten_thou) # result will be in R because ten_thou is

sage: the_sum = sum(f(k) for k in range(-1000, 1001)); the_sum
 
116.806521814573408154703961183569656583504707301922359958037591640215510813039244934779299244023546182097713963521073027455330258514764785349144281947839532827346835171962415366657291332526181608818055375581821843529213967899316532193194799347444658828139424420035706699509726059514135509142461539243

- Robert

-- 
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

Reply via email to