On 9 April 2016 at 19:56, Amy Valhausen <amy.vaulhau...@gmail.com> wrote:
> In the thread ; https://groups.google.com/forum/#!topic/sympy/eUfW6C_nHdI
>
> I was seeking feedback and help with the problem of type ;
>
> ( 1.414213562^6000) % 400)
>
> After reviewing all the excellent collaboration at the above link, Im
> feeling
> a little lost and overwhelmed.  So many good suggestions were made and
> also a lot of bugs, and bottlenecks discovered - Im not sure which approach
> is best for what I am hoping to solve?

Yes the thread did bring up a few issues and there were some bugs. I
think the reason for those bugs is that sympy's Float algebra is less
well used and tested than its other features. Modulo division with
floats for example seems an unusual usuage to me. That's because for a
problem like the one you have posed it's usually best not to use
float.

> Ive been reviewing the problems with the different approaches, including
> precision loss
> with use of floats, some of the suggested functions, etc.

The short answer is to just use rational numbers unless you can't for
some reason. So if 1.4142 is supposed to be an exact rational number
then:

    Rational("1.4142")**6000 % 400

This will give you the exact answer is a rational number.
Unfortunately the rational number has a really big numerator and
denominator (print it to see) so this isn't necessarily a useful form
for viewing the output. To see the first say 50 decimal digits just
use evalf():

    >>> ((Rational("1.4142")**6000) % 400).evalf(50)
    271.04818100863092181593910948838929251832458036415

> Oscar mentioned the solution of using a string value and storing it as a
> possibility?

That was a suggestion for how the implementation of sympy could
change. I wasn't suggesting that to you to use. For your problem you
can pass the decimal string to Rational. But as already pointed out in
this thread it must be Rational("1.4142") and not Rational(1.4142).

> My hope is to arrive at a method that returns lossless precision, if I dont
> have to sacrifice speed then
> thats great but if preserving accuracy comes at a cost of speed thats ok
> with me.
>
> I'd like also to get the highest precision available, if possible past the
> 15 digit limit, the larger the better.

So see above. You can compute the result exactly as a rational number
(effectively having infinite precision). However this isn't always a
useful form so you can also evaluate it with evalf and ask for as many
digits as you desire. The exact answer can be written in decimal but
it needs 24003 digits so you can print it with:

    >>> ((Rational("1.4142")**6000) % 400).evalf(24100)

As you can imagine though 24003 digits is usually too many to be
useful so it really depends what you're trying to do.

--
Oscar

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxRz2ocN4gvAntGWj%3DdJivXJre8rGs%3DQTB71iaSthNgd9w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to