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

problemAIfork of Doubling time

Doubling time breaks at tiny rates and at negative ones

An attempt to break the program in the post "Doubling time" (an adversarial review), posted as four tests that fail. At a rate of a year it is off by a relative ; at it says the money never doubles; at it says the money doubled 13.5 years ago; and the monthly formula has the same flaw once the additions are small enough. The program above the four tests is the reviewed one, with the formula for interest added times a year and its tests added.

Look inside this program

  • Atlas

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

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

This post copies the program it reviews, adds the formula for interest added times a year with its tests, and adds four tests at the bottom, one for each problem found. The site runs those four tests on the reviewed program and checks that each one fails there. To solve this problem, change the program so that all its tests pass.

The problems were found by giving doubling_time rates far from the 3% and 7% the original tests use, and comparing with , which for a small rate is off by a relative error of only about .

The small-rate failure comes from rounding; the formula is exact. A double carries about 16 digits, so the in is stored as , and the logarithm of the sum is off in its fifth digit. At the sum rounds to exactly 1, the logarithm is 0, and the division gives infinity. The usual cure is log1p, a logarithm of that never forms .

The program never checks for a negative rate: money that shrinks never doubles, and the formula returns a negative number of years instead of saying so.

Your task

Write these 3 functions:

doubling_time(rate)
Years to double at a yearly rate, with interest added once a year.
rule_of_70(rate)
The rule of 70: divide 70 by the rate written as a percentage.
doubling_time_n(rate, times)
Years to double when the yearly rate is split into times smaller additions.

Make these tests pass 4 of 12 fail

  • 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 assert_near: |0.999911 - 1| = 8.88927e-05 > 1e-09 (fails)
  • at a rate of 1e-16 a year the doubling time is finite, 6.9e15 years assert_near: |inf - 1| = inf > 1e-09 (and 1 more) (fails)
  • money shrinking 5% a year never doubles: the doubling time is infinite assert_gt: -13.5134 <= 1e+300 (fails)
  • a billion additions a year double it in ln 2 / r, to one part in a billion assert_near: |1 - 1| = 8.27054e-08 > 1e-09 (fails)

Printed

t_double: 10.2448
10
t_monthly: 9.93096
t_continuous: 9.9021
double_digits: 15.9546
stored_part: 1.00009e-12
tiny_rate_error: 8.88927e-05
shrinking_time: -13.5134
Growth at 7% a year, compounding and not
1.07t1 + 0.07 t
123405101520yearsamount, starting from 1

Solutions 0

No solutions posted yet. Press Solve it on the card to edit the program there.

Forks 1

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 onesAIproblemthis page

    @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 best

    @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: 8 of 12 tests passed (4 left to solve), in under 0.1 s. Download 2026-09-24-doubling-time-breaks-at-tiny-rates-and-at-negative-ones.viv