fib.rb 1.9.1/1.8.6 source code conflicts/errors

J

jzakiya

In the latest ruby-1.8.6-p388 source code I just downloaded
the file fib.rb; 2007-2-12 contains correct code:

------------------------------
# calculate Fibonacci(20)
# benchmark
def fib(n)
if n<2
n
else
fib(n-2)+fib(n-1)
end
end
print(fib(20), "\n")
---------------------------

The code in fib.(awk,pl,py.scm) is also correct.

But in the lastest ruby-1.9.1-p378 source code

the file fib.rb (and fib.(awk,pl,py,scm) files)

has the same date but the code has been changed to
give an incorrect value for fib(0), which should be 0:

--------------------
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end

fib(34)
--------------------

The correct series starts with '0' and is::

n | 0 1 2 3 4 5 6 7 8 9 10...
----------------------------------------------
fib(n) | 0 1 1 2 3 5 8 13 21 34 55,..

See for verification:
http://goldennumber.net/fibonser.htm
http://en.wikipedia.org/wiki/Fibonacci_number

This is troubling, because not only does the 1.9.1 code
not give the fully accurate results, but the changes to
the file doesn't show a newer/different data than the
file in the 1.8.6 source code. The dates are the same.

Is someone messing with the source code, or has the 1.9.1
line not been thoroughly tested/vetted to catch these
obvious errors/differences from the prior versions?

A BIG obvious question now is, what else has been changed
that no longer completely gives accurate answers/results?
 
B

Brian Candler

jzakiya said:
The code in fib.(awk,pl,py.scm) is also correct.

But in the lastest ruby-1.9.1-p378 source code

the file fib.rb (and fib.(awk,pl,py,scm) files)

has the same date but the code has been changed to
give an incorrect value for fib(0), which should be 0:

So you have two complaints:

(1) The files are different between two different versions of ruby (1.8
and 1.9), but have the same timestamp in the respective tarfiles.

(2) The new files are computing fib(0) "incorrectly".

Actually, you're not entirely right in case (1). I see that:

* ruby-1.8.6-p388/sample/fib.rb and ruby-1.9.1-p378/sample/fib.rb are
identical

$ diff -u ruby-1.8.6-p388/sample/fib.rb ruby-1.9.1-p378/sample/fib.rb
$

* ruby-1.9.1-p378 contains benchmark/other-lang/fib.rb (with slightly
different code), but it does not exist in ruby-1.8.6-p388 at all.

Regarding your point (2): the code you are referring to is in the
benchmark/ directory, so I don't think the return value is important.
After all, the code for the other languages is doing exactly the same.

The "correct" version of the code is still in the sample/ directory.

Looking at 'svn log', the benchmark directory found its way into trunk
when YARV was merged in. There's no explanation of why the code used for
benchmarking was slightly different to the fib sample code.

You can always raise a ticket on redmine.ruby-lang.org if you are
unhappy about the algorithms used in the benchmarks, but it seems pretty
trivial to me.
 
J

jzakiya

Regarding your point (2): the code you are referring to is in the
benchmark/ directory, so I don't think the return value is important.
After all, the code for the other languages is doing exactly the same.

The "correct" version of the code is still in the sample/ directory.

Looking at 'svn log', the benchmark directory found its way into trunk
when YARV was merged in. There's no explanation of why the code used for
benchmarking was slightly different to the fib sample code.

Thanks for tracking down the apparent source for this code.
You can always raise a ticket on redmine.ruby-lang.org if you are
unhappy about the algorithms used in the benchmarks, but it seems pretty
trivial to me.

The 'solution' to this 'problem' is to change the erroneous coding to
a correct
one, or delete the file(s) (all the other incorrect language versions
too).

This is not a 'trivial' matter. It is a matter of mindset that is
troubling to me.

The Fibonacci series has been known, taught, and used for centuries.
It is not
a matter of speculation or ambiguities. Either you write an algorithm
to do it
correctly, or you are writing an algorithm to do some other series.

This lack of an apparent need to satisfy mathematical rigor is
troubling, and
potentially dangerous. You don't know who, and for what purpose,
someone will use
Ruby for, so it needs to be as well written, and accurate, as
possible.

I use Ruby in engineering, scientific, mathematical, and educational
fields. So
doing math to me matters. Doing it correctly matters. Other people use
Ruby in
these fields too, so it matters to them as well. See this one example
below:

http://www.artcompsci.org/kali/five-year-plan3.html

That's why these releases came out, to 'fix' a mistake in the coding
that allowed security related exploits to occur. Now, someone 'could'
say these mistakes are unlikely to cause any real harm, that they're
'trivial', but you don't allow these errors to exist when you find
them. You 'fix' them, and keep looking for others.

So, since we agree the code in question is 'wrong', it should be
corrected and/or discarded.
 
B

Brian Candler

jzakiya said:
So, since we agree the code in question is 'wrong', it should be
corrected and/or discarded.

No, I disagree that the code is 'wrong' (that's why I used the quotes).

It's a benchmark. Its sole purpose in life is to be run a number of
times, and to have its execution time measured. If fib() were renamed to
foo() or bignum_test() would that make you happy?

Indeed, "f" "i" "b" are just three letters. Unless I'm mistaken, nowhere
is it claimed that this code calculates the correct value of the
Fibonacci series. The code does happen to do so for n>0.

Anyway, I'm not inclined to argue further. Redmine or ruby-core would be
the appropriate places to post patches.
 
J

jzakiya

No, I disagree that the code is 'wrong' (that's why I used the quotes).

Yes, the code is 'wrong' because it does not correctly produce the
Fibonacci series.
It's a benchmark. Its sole purpose in life is to be run a number of
times, and to have its execution time measured. If fib() were renamed to
foo() or bignum_test() would that make you happy?

Actually, yes it would make me happy to rename. It would make me more
happy to completely delete it, and not confuse anyone.
Indeed, "f" "i" "b" are just three letters. Unless I'm mistaken, nowhere
is it claimed that this code calculates the correct value of the
Fibonacci series. The code does happen to do so for n>0.

This is very troubling that you feel some 'need' to even make this
specious argument. The code is 'wrong'. Its doesn't matter what its
intimated purpose is. Anyone looking at this code, no matter what
directory it's in, will naturally assume it'll produce (allegedly) the
correct Fibonacci series. Like I said, you don't know who is looking
at this code and for what purpose they'll put it to use. There was no
disclaimer in this code saying: 'Intended only for benchmarking, not
for real use.'

For some reason, when 'I' identify an irrefutable coding 'error' of a
mathematical algorithm it just not good enough to accept it, fix it,
and move on.

Why defend inaccuracy and mediocrity?

Like I said, this is a troubling mindset.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top