Ladislav,

I am impressed by your recursive fib. In fact it inspired me to write a
zero finding routine in a similar manner. If I am not imposing too much,
can you tell me if it is functional programming?

Jerry

>> x: binsrch "x - exp - x" 'x 0 1
== 0.567143290409784
>> exp - x
== 0.567143290409784
>>

xeq: func [f v x] [do join v [": " x]  do f]

binsrch: func [f v b e]
[
   if ((xeq f v b) * (xeq f v e)) > 0
   [print "binsrch: f must have different signs at endpoints"
   return none]
   either (xeq f v b) < 0
   [binsrch0 f v b e 50]
   [binsrch0 f v e b 50]
]

binsrch0: function [f v b e n] [x]
[
   x: b + e / 2
   if n = 0 [return x]
   either (xeq f v x) < 0
   [binsrch0 f v x e n - 1]
   [binsrch0 f v b x n - 1]
]

Reply via email to