How can spells per day be determined mathematically?

I want a character sheet I'm designing to automatically show available spells per day at each spell level without the user having to enter that information by hand.

Is there a formula for determining a class's spells per day without consulting the class's table? That is, can spells per day be determined mathematically, or are spells per day arbitrary, making the lookup chart required?

I don't need the math for bonus spells, only for classes.

• Why not just use a lookup table? Why must it be math? – Erik Jul 4 '16 at 5:39
• I took a crack at editing this. I hope that's okay. If it no longer asks what you need answered, please repair it. – Hey I Can Chan Jul 4 '16 at 7:21
• When you make a form-fillable PDF is it not possible to script it to just draw from a table or array? (says the person with no practical experience doing so) – Jason_c_o Jul 4 '16 at 8:33
• Perhaps this is an X/Y? Is the real problem "How do I get my custom character sheet to display the appropriate spells per day at each level?" – Jason_c_o Jul 4 '16 at 8:34
• Judging by the posted formula, I think you're better off sticking with that table... – Erik Jul 4 '16 at 9:23

TL;DR: Use lookup tables, because we're not in Kansas any more.

We're off to see the Wizard...

Just looking at the wizard, there seems to be a fairly regular progression. You get the first spell of spell level $S$ when your class level $C$ satisfies

\begin{align} \frac{C+1}{2} & \geq S &\Leftrightarrow&& C-2S+1 & \geq 0 \end{align}

The second, third and fourth spell for each level are obtained when

\begin{align} C-2S+1 \geq 1, C-2S+1 \geq 3, C-2S+1 \geq 6 \end{align}

This can be easily written as

$$C-2S+1 = \sum_{i=1}^{k-1} i = \frac{k(k-1)}{2}$$

We can solve this for $k$, which yields

$$k_S(C) = \frac{1}{2} \pm \frac{1}{2} \sqrt{1+8(C-2S+1)}$$

The correct solution here is the one with the positive sign. We also have to round down to the next integer. Finally, there's a maximum of 4 for wizards:

$$k_S(C) = \min\left(4,\left\lfloor\frac{1}{2} + \frac{1}{2} \sqrt{1+8(C-2S+1)}\right\rfloor\right)$$

If that seems pretty reasonable so far, it's because it doesn't account for deviations yet. This formula only holds true for $1\leq S \leq7$. Spell levels 0, 8 and 9 have slightly different progressions (in order to end with 4 slots on all spell levels at level 20), which I'm not going into in this answer (although spell level 0 can be obtained using $S=-0.5$).

The same calculation works for clerics and druids, too, with the exception that the limit is 5, except for 0-level spells, which have a limit of 6. I guess Tier 1 classes are simply better.

The wicked witch of the west sinister sorcerer of the south

If we try to adapt this to the sorcerer, things start getting wonky. The progression is all different, the maximum is increased to 6, there's a minimum of 3 unless it's 0. The shunted progression (new spell levels at odd levels) causes spell level 1 to deviate from the pattern.

For $2\leq S \leq 8$, we have

$$k_S(C) = \begin{cases}\min\left(6,3+C-2S\right)& C\geq 2S\\0 & C < 2S\end{cases}$$

Spell level 1 is offset by 1 class level, so

$$k_1(C) = \min\left(6,3+C+1-2S\right)$$

Let loose the flying monkeys

Now let's go to where math breaks completely: Bards. Not only is the Bard spell progression majorly weird, with exceptions being as common as rules, you now also have to deal with 0 spells per day being different from "–" spells per day.

I'm not even going to talk about Rangers and Paladins. Or, you know, classes outside of the PHB (like the Duskblade). Or prestige classes (Sublime Chord comes to mind).

Conclusion: Not worth the effort

I hope this illustrates that while WotC seems to have started with a plan, the dozens of variations for special cases within the same class, as well as major differences between characters makes it so that a lookup table, a nested if else or case structure are the only real way to deal with the problem.

• While technically correct, the equation you started with seems much less intuitive to me than the mental calculation I've been using for what level spells you can cast: S=(C+1)/2. While mathematically equivalent, I wonder if you'd get a more useful formula if you started with that and carried it through. – SirTechSpec Jul 4 '16 at 11:53
• @SirTechSpec I started with that as well, but it doesn't help with figuring out when you get the second spell of a given level. I made that into a variable and put everything else on the same side of the equation. This allowed me to notice the pattern (0, 1, 3, 6) and to generalize it. I added the intuitive form to the answer as well now, noting the equivalence. – MrLemon Jul 4 '16 at 13:41
• Sheesh, it makes no sense at all lol. To me at least. This is beyond confusing and appears to be the result of random chart clicking on wotc part... ok so scratch math formula following the exact same patterns. I'm going to try to come up with an easy homebrew progression. In the app I've got I can easily set floors and ceilings seperate and even base them off of functions. Perhaps a simple math progression. Where you gain 1 spell slot every so many levels – Zakier Jul 4 '16 at 16:54
• @Zakier - Ask a math question, get a math answer. – indigochild Jul 5 '16 at 20:02

Yes, but don't do it.

I did the exact same thing a few years ago, and I recommend against trying to generate spells by level and class. D&D is immensely complex. Even if you successfully account for all the myriad effects on spells (which is hard), PDFs bog down quickly. And, like I said, it's hard. Just for quick example: how will you account for prestige classes?

Unlike other answers, I advise against even building in lookup tables. Instead, I strongly suggest making a sheet that's easier to fill in (fill the stat bonuses to skills and saves, put nice text boxes everywhere, generate carrying capacities, etc). You'll be happier on the coding side, and you'll be happier filling it out (because you don't have to constantly fight the system you built). Again, I speak here from experience.

If you'd like, message me and I'll send you the form-filling sheet I ended up with. It might not be exactly what you want, but it's well over a 90% solution.

Yes, sort of.

There is a formula, but it's different depending on which class you are. Clerics, druids, and wizards follow the same base formula. Except clerics have one extra spell (domain spell). Wizards max out at 4 spells per day instead of 5. Sorcerers follow a different progression entirely.

Most primary casters (Cleric, Druid, Wizard):

Spells per day come from the quadratic formula.

x = (-b + sqrt(b^2 -4ac))/2a

Where ax^2 + b*x + c = 0

x is the number of spells per day, max 5 (4 for wizards)
a = 1
b = 1
c = -2 * s
s = spell slot level

Spell slot level is calculated from your character level and spell level.

s = 2 + cl - 2 * sl

As an example, how many 3rd-level spells can a 14th-level wizard cast?

s = 2 + 14 - 2*3 = 10
a = 1, b = 1
c = -20
x = (-b + sqrt(b^2 - 4ac)) / 2a
= (-1 + sqrt(1^2 - 4*1*-20)) / 2*1
= -1 + sqrt(1 - -80) / 2
= (-1 + sqrt(81)) / 2
= (-1 * 9) /2
= 4

x = 4

n.b. if you ran the same calculation for first-level spells, you'd get a higher number; in this case you need to use a minimum function on it.

Sorcerers

Sorcerers follow a different formula. They simply count up from level 1:

x = s + 3, max 6

And s is character level - 2 * spell level (except for first level spells where it's just 0).

c - 2s

This gives a formula:

x = c - 2s + 3, max 6

How many 2nd level spells can an 8th level sorcerer cast?

x = c - 2s + 3
= 8 - 2*2 + 3
= 7 -> 6
• The sorcerer calculation confuses me. Where does the sorcerer's level come into it? – gaynorvader Jul 4 '16 at 9:35
• Oops, sorry about that. I pasted in the wrong formula from my spreadsheet while I was figuring it out :( – Brian Jul 4 '16 at 19:55