Golden Ratio Problem I am needing help on designing code that uses a modified form of Binets Formula. I am a newbie to python so am very open to direction and samples you can provide that demonstrate how to structure this in python.
I believe I already have a solution in psuedo code (included below) but if someone can review this and provide any pointers on how we convert this to python - I would so appreciate this!!! :) Also, I have been trying to use these functions with sympy mpmath.phi sympy.GoldenRatio._evalf() And if possible would like to be able to use either of these in the python script version of the psuedo code below, however each time I have tried to reference these in my code I just error messages returned, so I dont know how to properly use these - I have tried looking all over the net and have asked around but cant seem to find how to do this properly. For example, one of the places I went to was here ; http://nullege.com/codes/search/sympy.GoldenRatio._evalf But when I tried typing this in from the command line, it just reported errors back! Regarding the binet formula modification, I have included a detailed problem description following the psuedo code below.... Its important for me to say - that I am NOT trying to simply run the Binet formula AS IS, but it needs to be modified and Ive described that below. Thanks for any insights you may provide! See the following ; Here is an example if the input is (75025, -8), For values given below, I do not always show the same number of significant digits to simplify the display, or to show when you have to round the numbers input integer input_value // may be or not a Fibonacci number // input_value set to 75025 as per example input integer input_index_offset // the offset index to add to the Fibonacci index //input_index_offset set to -8 as per your example approximate_index = log(sqrt(5)*input_value) / log(phi) // that is n' in my description above--a real number //approximate_index = 25.00001 or something close to 25 depending on precision. // that means that 75025 is the 25th (or close to the 25th) Fibonacci number closest_index = ceiling (approximate_index + 0.5) // that is the n in the description--an integer // closest_index = 25 now output_Fibonacci = Binet(closest_index +input_index_offset) // Binet() is the function calculating the nth // Fibonacci number, as explained in the wikipedia article // closest_index + input_index_offset = 25+ (-8) = 17 // Binet(17) or Fib(17) as you called in another example // you calculate ( (phi^17) - (-phi)^(-17) ) / sqrt(5) // = ( (1.6018^17) - (-1.6018)^(-17)) / sqrt(5) // 1.6018 is just an approximation of phi // use the calculated one (1+sqrt5)/2 // = (3572.00028 - 0.000280033) / 2.23607 // = 1597.000001 // because of precision problem, and as you want an integer, // you may want to actually round this number to the // closest integer--the result of Binet() may be something like // 1597.0001 or 1596.999 // after rounding: 1597 display output_Fibonacci // the end result // you show 1597 =================== BACK GROUND DESCRIPTION OF THIS ROUTINE ; My goal here is to try to create a python script using arbitrary precision with a very large float or similiar capacity to store large number calculations. I did a fair bit of leg work researching online what the best methods were to compute these sorts of values, and in a number of python forums it was repeated over and over that the most accurate and simple approach was to use a modified form of Binets formula as it would allow for the greatest accuracy and the least required coding. There are quite a few other approaches involving iterations, looping and matrices - but always it came back to Bients formula as being the optimal one. I did try to ask around on the forums, but the math involved to alter Bients formula was a topic that both they and I realized, would be best grasped by first understanding the maths, which I want to be able to do - not just write the code, and so I have taken the most meaningful route in asking experts in math, like yourself before I attempt the code. I want to be able to enter any value really, not just fibonacci values (but especially fibonacci values) and then use a modified version of Binets to "dial up" or "dial down". I will have two inputs always ; The number itself, such as the fibo value used as an example ; fibo value = 75025 and the number of steps (positions to move in the fibo sequence index) to move up or down so if x = 75025 and y = steps moved, + or -, we might move down 8 steps ( - 8 ) or we might move up 8 steps ( + 8 ) Imagine a rotary dial that can move left or right x = 75025 -------------------------> (+ 8) (- 8) <---------------------- so if my inputs are simply x = 75025 and y = +8 Then the index positions to the 33 value and returns ; 3524578 however if my inputs are x = 75025 and y = ( - ) 8 Then the index positions to the 17 value and returns ; 1597 I do not want to simply use a look up table or list of fibo numbers, and return the fib value associated with the associated index, instead I want to directly compute this by altering the current Binet formula so that it directly calculates the value. By doing this, I can enter non fibonacci values into (x) if I want, and then I can observe how that value changes when I change the index number. I'll know of course if this is working if I do enter a fibonacci number and the desired index change and a close enough approximation of the desired fibo number is returned. Most of the values I will be working with will be larger, at least greater than 1000. As it is Binets formula used by default as you know, accepts as an input only the index number of the fibo sequence and then it returns the associated actual fibo value, however what I am after is different in that, I want to modify the formula so that instead I enter the fibo number itself, and then I enter the index number I want to change the value to. But to do this I have to be able to make changes to both the parameter types input as well as how they are interacting and relating with each other - this is where I am struggling and would so love to hear your thoughts on! Warm regards A Hi Amy, I think I originally missed something in what you want to do.At first I thought you entered a Fibonacci number (first parameter), and then you wanted to jump +n (or -n) (second parameter) to find the nth Fibonacci number before or after the one in the first parameter.That would have meant that if you input (75025,17), from 75025 you find it is the 25th Fibonacci number, and then you want to calculate the (25+17)th or (25-17)th Fibonacci number. Now I realize it does not seem to be what you want. You want the 17th Fibonacci number. If this is what you want, the first parameter is irrelevant: The 17th Fibonacci is what it is, independent of whatever first number you input.So why would you ask the first parameter? So if all you want is the nth (here 17th) Fibonacci number, you just use the Binet's formula with n=17. And if my original understanding had been correct, once you got n=25 linked to the first parameter, then you change n to 25+17=42, and put this value in the Binet's formula. As for or , this is to characterize a Fibonacci number. I did not know this characterization.Basically they say that if 5*x^2+4 or 5*x^2-4 is a perfect square, x is a Fibonacci number; they say the reverse is also true Note that may be hard to verify, as you need a great precision--with x=75025, you would need at least 11 digit precision--I cannot double-check as my calculator I currently have with me is not that precise (10 digits only). BTW, that is interesting: it shows the difference between being mathematically true (I assume they are correct in their characterization of a Fibonacci number), and being practically useful. In this case you need at least two times as many digit precision as the number of digits the number you check. -- 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/bcde3785-b3db-4a24-98cf-47395ac16363%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.