fib.rb 1.9.1/1.8.6 source code conflicts/errors

Discussion in 'Ruby' started by jzakiya, Jan 11, 2010.

  1. jzakiya

    jzakiya Guest

    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?
    jzakiya, Jan 11, 2010
    #1
    1. Advertising

  2. jzakiya wrote:
    > 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.
    --
    Posted via http://www.ruby-forum.com/.
    Brian Candler, Jan 11, 2010
    #2
    1. Advertising

  3. jzakiya

    jzakiya Guest

    > 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.
    jzakiya, Jan 11, 2010
    #3
  4. jzakiya wrote:
    > 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.
    --
    Posted via http://www.ruby-forum.com/.
    Brian Candler, Jan 11, 2010
    #4
  5. jzakiya

    jzakiya Guest

    > 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.
    jzakiya, Jan 11, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JonoMG

    Runtime Library Conflicts

    JonoMG, Apr 7, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    567
    JonoMG
    Apr 7, 2004
  2. Felix Wu [MSFT]

    RE: ASP.NET 1.1 conflicts with VS.NET 2002

    Felix Wu [MSFT], Jun 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    958
    Felix Wu [MSFT]
    Jun 25, 2003
  3. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    922
    Mark Goldin
    Jan 17, 2004
  4. John Goche
    Replies:
    1
    Views:
    7,447
    John Goche
    Dec 17, 2005
  5. jzakiya

    Error in fib.rb for 1.9

    jzakiya, Dec 25, 2007, in forum: Ruby
    Replies:
    0
    Views:
    84
    jzakiya
    Dec 25, 2007
Loading...

Share This Page