Even though you set the precision to 2000, you're still only using 9
digits of the golden ratio. I recommend using mpmath.phi and
1/mpmath.phi. (Also, "from sympy import mpmath" no longer works in the
lastet version of SymPy, just use "import mpmath").
Or, using SymPy, you can use sympy.GoldenRatio, and use evalf() to get a number
In [34]: (1/GoldenRatio**4*514229).evalf()
Out[34]: 75024.9999973910
This number is accurate to 15 digits (the default precision), so I
think it's close to, but not exactly an integer. You can also see this
by rewriting the GoldenRatio using square roots and expanding it
In [1]: (1/GoldenRatio**4*514229).rewrite(sqrt).expand()
Out[1]:
514229
────────
3⋅√5 7
──── + ─
2 2
I guess this calculation uses the fact that the golden ratio phi ≈
F_n/F_{n-1}, so F_29/phi^4 ≈
F_29/[(F_28/F_27)*(F_27/F_26)*(F_26/F_25)*(F_25/F_24)] = F_24. But
this is only an approximation (although it's quite accurate even for
smaller n). So if you use it to compute fibonacci numbers, it's
necessary to use round() to round to the nearest integer (assuming n
is large enough that it's within 0.5 of the answer).
Here's the calculation going from the 301st to the 251st number:
In [9]:
(359579325206583560961765665172189099052367214309267232255589801/GoldenRatio**50).evalf(100)
Out[9]:
12776523572924732586037033894655031898659556447352249.00000000000000000000000000000000000000000000000
In [10]: fibonacci(251)
Out[10]: 12776523572924732586037033894655031898659556447352249
The important thing is to use evalf(100) (you actually only need
evalf(53)), as the default evalf() only gives 15 digits, which isn't
enough.
Aaron Meurer
On Fri, Apr 8, 2016 at 4:37 PM, Amy Valhausen <[email protected]> wrote:
> Hi Aaron, thanks for your reply!
>
> Do you feel this is due to the size of the 301st number?
>
> I tried something different, I picked the 29th fibonacci number of ; 514229
>
> And then tried to step down, backwards to the fourth preceeding fibo value
> using this
> code ;
>
> from sympy import mpmath
> mpmath.mp.dps = 2000
> x = (mpmath.mpf('0.618008776') **4)
> x=x*514229
> print(x)
>
> Got this value ; 75012.7581
> a result very close to the correct fibo number ; 75025
>
> In your opinion, is it that the 301st fibo number is over the limit that
> symopy can handle
> for computing fibo numbers occurring before it?
>
> On Friday, April 8, 2016 at 10:43:27 AM UTC-6, Aaron Meurer wrote:
>>
>> It seems SymPy's solve() is not able to solve fibonacci(n) -
>> 359579325206583560961765665172189099052367214309267232255589801, even
>> if you rewrite fibonacci(n) using GoldenRatio or using the explicit
>> value for GoldenRatio (or even the floating point value).
>>
>> The Wikipedia article gives a way to invert Binet's formula
>>
>> https://en.wikipedia.org/wiki/Fibonacci_number#Recognizing_Fibonacci_numbers.
>> That should be useful for calculating what you want.
>>
>> Aaron Meurer
>>
>>
>> On Fri, Apr 8, 2016 at 5:02 AM, Francesco Bonazzi
>> <[email protected]> wrote:
>> > Hi there!
>> >
>> > Are you asking about the math or about a programming strategy?
>> >
>> > From a programming point of view, you could use a vector of pre-computed
>> > Fibonacci numbers if the numbers you're dealing with aren't too big.
>> >
>> > Otherwise, I'd give a try to use the closed formula for Fibonacci
>> > numbers
>> > with SymPy's equation solver.
>> >
>> > Anyway, I suggest to ask about mathematical details on
>> >
>> > http://math.stackexchange.com/
>> >
>> >
>> >
>> > On Friday, 8 April 2016 02:19:14 UTC+2, Amy Valhausen wrote:
>> >>
>> >> Fibonacci Reverse Calculation?
>> >>
>> >> Hi All!
>> >>
>> >> I was reading Dr Knotts entries about Binets formula on his fibonacci
>> >> page
>> >>
>> >>
>> >> http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibFormula.html
>> >>
>> >> I entered the formula into an Excel spreadsheet to see how this would
>> >> work
>> >> ;
>> >>
>> >> Binet Formula
>> >> Fib(n) = (1.6180339^n – (–0.6180339..)^n) / 2.236067977..
>> >>
>> >> Its fascinating to see how I can enter any number for (n) and see the
>> >> correct fibonacci number returned!
>> >>
>> >> I have a question though, I am a newbie computer programmer using
>> >> VB and Python and my math skills are average at best but I am very
>> >> interest and curious about math and especially fibonacci numbers!
>> >>
>> >> Say I wanted to reverse and change the process.
>> >>
>> >> I have a very large fibonacci number and I want to know what the
>> >> fibonacci number is at a specified position BEFORE it, how would
>> >> I compute this, what would the formula be?
>> >>
>> >> So for example I have the 301 st fibo number of ;
>> >>
>> >> 359579325206583560961765665172189099052367214309267232255589801
>> >>
>> >> And I want to be able to find what the fibonacci value would be (n)
>> >> numbers
>> >> BEFORE this... so I might want to know what the fibo value would be 50
>> >> numbers before or the 251st fibo number. How would I do that?
>> >>
>> >>
>> > --
>> > 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 [email protected].
>> > To post to this group, send email to [email protected].
>> > 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/5b6e68d0-8b65-495a-bd8b-0c601bdef403%40googlegroups.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/dc81edc9-866e-4c13-962e-b0446fb294a0%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
--
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 [email protected].
To post to this group, send email to [email protected].
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/CAKgW%3D6KpwA58yjkL9z%3D4n_7t8dt1YOtYfpHnDzQHrxOwiwHc7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.