{{ message }}

Instantly share code, notes, and snippets.

Last active Sep 11, 2021
How Anki calculates intervals

Reading `_nextRevIvl` and its subfunction `_constrainedIvl` plus `_rescheduleLapse` will illuminate how Anki calculates the `due` date of a flashcard, based on whether you answer

• again
• hard
• good
• easy

This is more of a self-note, so I assume you’ve read the Anki manual top-to-bottom a couple of times.

Let `factor` be the flashcard’s factor, by default be the Starting Ease, default `startingease = 2.5`, which is Anki’s estimate for how well you’ve memorized this flashcard. The bigger the number, the better you understand it. It’s maximum is 1.3 and it gets incremented by 0.15 to 0.2 points every review, as we will show below. The manual also calls this ease. Recall that factor is Anki’s guess of the strengh of the memory in your mind, and it controls the exponential growth of intervals for good and easy reivews.

Here’s how to calculate the new `factor`:

• `factor = max(1.3, lastfactor - 0.2)` when you fail a review (reference)
• `factor = max(1.3, lastfactor - 0.15)` for a hard review.
• `factor = max(1.3, lastfactor)` for a good review. No change in factor.
• `factor = max(1.3, lastfactor + 0.15)` for an easy review (reference).

Let the `interval` be the flashcard’s interval, by default be the New Interval, default `graduatinginterval = 1`. Let `intervalmodifier` be the Interval Modifier, default `intervalmodifier = 1`, a number nominally around 1.0 but that a user can set higher or lower. Anki multiplies the interval by this number, letting the user ask for more or less time between reviews uniformly, across all cards. Let `hardinterval` be the Hard Interval, which applies for hard reviews, default `hardinterval = 1.2`. Let `easybonus` be the Easy Bonus, default `easybonus = 1.3`, which applies for easy reviews. Let `delay` be the days between the `due` date and the date you actually reviewed, and `delay>=0`. This can be important because if you successfully answer a flashcard a long time after it was due for study, that means you probably know it really well.

Here’s how to calculate the new `interval`:

• `againinterval = newinterval * lastinterval` is the new interval for failed reviews. It can have a minimum.
• `hardinterval = max(lastinterval + 1, (lastinterval + delay//4) * hardinterval * intervalmodifier)` is the new interval for hard reviews.
• `goodinterval = max(hardinterval + 1, (lastinterval + delay//2) * lastfactor * intervalmodifier)` is the new interval for good reviews.
• `easyinterval = max(goodinterval + 1, (lastinterval + delay) * lastfactor * easybonus * intervalmodifier)` is the new interval for easy reviews.

The new interval can be limited to Maximum Interval, default `maximuminterval=36500` day.

Finally, new `due` date is the day you actually review + new `interval`.