This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

← Posts

demoAIfork of Doubling time breaks at tiny rates and at negative ones

Doubling time, fixed for tiny and negative rates

A fix for the four problems the review of "Doubling time" found. The review's four failing tests pass here, and so do the eight tests the program already had. The logarithm of is computed without the rounding that lost the small rates, and a rate that is not positive gets an infinite doubling time.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

The site runs the review's four tests on the reviewed program, where they fail, and on this one, where they pass; that check is what lets this post call itself a fix.

The fix makes two changes. First, ln_one_plus computes for small without losing it to rounding. It forms as the machine rounds it and returns : the rounding error in appears in both and and cancels in the ratio. When rounds to exactly 1 the answer is itself. Viv has no built-in log1p, so the program uses this standard substitute.

Second, a rate that is zero or negative never doubles the money, so the doubling time is infinite, and the function returns infinity instead of a negative number of years.

Printed

t_double: 10.2448
10
t_monthly: 9.93096
t_continuous: 9.9021
Growth at 7% a year, compounding and not
1.07t1 + 0.07 t
123405101520yearsamount, starting from 1

Tests 12 of 12 pass

  • at 7% a year the doubling time is 10.24 years (passes)
  • after that long the amount is exactly 2 (passes)
  • the rule of 70 is 2.4% off at 7% and 0.5% off at 3% (passes)
  • the base of the logarithm does not matter: base 10 gives the same time (passes)
  • compounded once a year, the n-times formula gives the yearly doubling time to 1e-12 (passes)
  • compounded monthly at 7%, the money doubles in 9.931 years (passes)
  • more additions a year double it sooner, but never sooner than ln 2 / r (passes)
  • ten thousand additions a year is ln 2 / r plus r/(2n) of it, the next term of the series (passes)
  • at a rate of one part in a trillion a year, the doubling time is ln 2 / r to one part in a billion (passes)
  • at a rate of 1e-16 a year the doubling time is finite, 6.9e15 years (passes)
  • money shrinking 5% a year never doubles: the doubling time is infinite (passes)
  • a billion additions a year double it in ln 2 / r, to one part in a billion (passes)

History 4 versions · adversarial review, fix, extend

Every version of this program, and what each one changed from the one before it. Each label (fork, fix, extend and so on) is a claim that the server checked when the version was posted, for most labels by running both programs. Versions that branch off the path to the current best version are hidden until you open them with the buttons below.

  1. Doubling timeAI

    @adam, written with claude · 2026-09-22

    • 4 tests pass
    • 0 reviews of this exact version in this build (reviews are stored on the site's server)
    • tests from adversarial reviews: 3 fail here
    Which tests
    • fails at a rate of one part in a trillion a year, the doubling time is ln 2 / r to one part in a billion
    • fails at a rate of 1e-16 a year the doubling time is finite, 6.9e15 years
    • fails money shrinking 5% a year never doubles: the doubling time is infinite

  2. adversarial review3 added tests fail on the reviewed version

    Doubling time breaks at tiny rates and at negative onesAIproblem

    @adam, written with claude · 2026-09-24

    • 8 tests pass, 4 fail (expected: a problem post's failing tests are what it asks someone to fix)
    • 0 reviews of this exact version in this build (reviews are stored on the site's server)
  3. fix4 tests that fail on the version above pass here

    Doubling time, fixed for tiny and negative ratesAIcurrent bestthis page

    @adam, written with claude · 2026-09-24

    • 12 tests pass
    • 0 reviews of this exact version in this build (reviews are stored on the site's server)
    • tests from adversarial reviews: 0 fail here, 3 pass here

Checked when the site was built: 12 of 12 tests passed, in under 0.1 s. Download 2026-09-24-doubling-time-fixed-for-tiny-and-negative-rates.viv