## Elementary school math, again

Remember when you were five years old and you learned that one plus one is two? Remember when you were just about to enter middle school or sometime around there and you learned about finding x? And how you had to add some stupid constant on both sides or divide through by a variable and you were like, “What’s so goddamn important about this x anyway?”

And then you went to high school and finding x through simple addition and subtraction gradually got easier, but then you learned harder ways to find x for seemingly no reason. And if you got far enough in high school math you learned about some seemingly black magic where x was zero but apparently not really zero because of something called a limit?? What the heck?? And what were these fancy elongated S symbols?

And then you went even further than that, you went so far that you stumbled onto abstract algebra and realized that almost everything that you learned when you were little could be thought of as operations equipped on the set of integers $\mathbb{Z}$ with the algebraic structure of a group or ring.

Let me explain.

By algebraic structure I just mean that the integers (which math people like to call $\mathbb{Z}$) have some super obvious but also really nice properties that we’ve taken for granted in elementary school, because not all sets are created equal and $\mathbb{Z}$ just happens to be super privileged.

For example, there’s this property that for any two integers $a$ and $b$, adding them up will give you another integer. Really obvious, right? In fancy speak we say that the integers are closed under addition, or: $\forall a,b\in\mathbb{Z}, a+b\in\mathbb{Z}$.

Then, there’s the property of associativity which should be obvious to us since we’ve seen it jammed down our throats so many times in grade school. Formally, $\forall a,b,c\in\mathbb{Z}, (a+b)+c=a+(b+c).$

Next, there’s the property that there exists an additive identity 0 such that every integer plus 0 equals itself. Again, really obvious. In fancytalk, $\forall x\in\mathbb{Z}, \exists 0\in\mathbb{Z}$ such that $0+x=x$ and $x+0=x$.

Finally, there is the property that there exists an additive inverse -a such that every integer plus its additive inverse equals the identity, 0. This is obvious: -a+a=0, or a+(-a)=0, any way you slice it.

So these four properties being satisfied, as obvious as that is, defines a special object in mathematics called a group. A group is a set G equipped with some operation such as addition, multiplication, composition, rotation, or what have you; as long as that set with that operation satisfies these four group axioms. So when we try and solve for x in one-step equations like in seventh grade, what we were really doing was working in the additive group of integers. I won’t get into it now, but if we can also throw multiplication and the distributive property in the recipe of a group, we get an even spicier object called a ring.

So why define this horribly formal thing? Why do we need to call this the “additive group of integers?” Why can’t we just do our damn addition problems? Well, for starters, it’s freaking cool. The first time I saw this stuff my mind was blown. We just grow up assuming that this is just the way it is, and we add 5 on both sides to cancel the -5 in x-5 just because that’s how it’s done. We just follow a strict recipe for solving equations without knowing why. Well, this is the why.

Second, group theory can be applied to pretty much anything and everything that might have such a structure. The next basic additive group that we could talk about are the additive group of integers modulo n, otherwise known as cyclic groups because the integers just keep recycling around and around like numbers on a clock. The circle of fifths, an analog clock, the days of the week, anything that has a cycle can be isomorphic to the cyclic group of integers.

What the heck does isomorphic mean? The formal definition is kind of long to explain from scratch, but intuitively it means that two groups are isomorphic to each other if one group seems like another group in disguise. For example, the days of the week {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday} equipped with the operation of “progressing to the following day” (yes, operations can be defined in an informal way like this!) is isomorphic to the more abstract representation of this group, $\mathbb{Z}/7\mathbb{Z}$, defined as {0, 1, 2, 3, 4, 5, 6} with the operation of addition and the added caveat that 7=0. (Formally speaking, this definition is horribly incorrect, but I’m just trying to put it in a way that makes sense.) For example, 8 is equal to 7+1, which is equal to 0+1, which is equal to 1. So 8 is 1 modulo 7. In the same vein, 25 is 7+7+7+4=0+0+0+4=4, so 25 is 4 modulo 7.

Why are they isomorphic? Because the former group (the days of the week) looks like it could be the same thing as $\mathbb{Z}/7\mathbb{Z}$. We can see this if we assign the element “Sunday” to 0, “Monday” to 1, “Tuesday” to 2, and so on all the way to “Saturday” being 6. With this one-to-one assignment (keyword being one-to-one! or, formally, bijection) we can see that “progressing to the following day” is the same thing as “adding by 1” in $\mathbb{Z}/7\mathbb{Z}$.

If you’re beginning to realize it (and start getting your mind blown), you’ll see that “If today is Friday, what day of the week will it be 4 days from now?” and “What is 5+4 in $\mathbb{Z}/7\mathbb{Z}$?” are the same question. Instead of counting “Saturday, Sunday, Monday, Tuesday!” we can say “5+4 is 9, which is 2 mod 7” and if we wanted we could see that 2 corresponds to Tuesday, as we had assigned earlier. Obviously this is a really easy example, but what if I asked what the day of the week would be 1000 days from now? You can’t count those days one by one ad infinitum.

You might be saying, “Well, only a stupid person would do that. A realistic person would break the 1000 up into multiples of 7, with the knowledge that every 7 days it’ll be the same day of the week. Then we get 7(142)+6=1000, so we’d just need to count 6 days instead of 1000.”

Dude. You just did the same exact thing as computing 1000 modulo 7.

Of course, cyclic groups are still pretty basic. There are a huge variety of groups that are insane in their own right when explored. But I’ll leave that up to you to explore, if this blog post sparked your curiosity even a little bit.

## Integration by parts for multiple functions (n>2)

Let me preface this by saying that the things I’ll get into aren’t even remotely useful from a practical standpoint. This is basically for shits and giggles. They might be useful if you don’t have a calculator/computer and want to rip your hair out, however.

If you take/took BC Calculus or Calc II you’ve probably heard of the integration by parts technique. You can look at it as an inverse product rule that lets you take the integral of a product of two functions $f(x)=u$ and $g(x)=v$. An example would be

$\displaystyle \int x^2\sin{x}\ dx.$

In the above case you would apply IBP twice to decrement the power of $x^2$ to a constant. If you continue on I’m just going to assume that you’ve seen this already and know how to do these kinds of problems.

What if we wanted to find the integral of a product of three functions, or four, or $n$? Sometimes such an integral might not be expressed in terms of elementary functions, but there’s probably an approximation out there using a computer. Sometimes the solution exists, however.

For two functions, the solution to integration by parts is

$\displaystyle \int u\ dv = uv-\int v\ du.$

This is derived by taking the integral on both sides of the product rule. So to find the n-function integration by parts formula, it makes sense to first derive the general n-function product rule.

Let’s start small with the product of three functions, $uvw.$ Taking $(uvw)'$ is equivalent to $(uv)'w+(uv)w'$ by treating $uv$ like a single function. Now we use the product rule again on $uv$ to get

$\displaystyle (uvw)'=u'vw+uv'w+uvw'.$

This seems to make sense; for a product rule of three functions, there are three terms with each function having one and only one derivative for each term. Let’s see if this trend continues for four functions $f_1 f_2 f_3 f_4$. We can consider $f_1 f_2 f_3$ as an entire function and apply the product rule to get $(f_1 f_2 f_3 f_4)' = (f_1 f_2 f_3)'f_4+(f_1 f_2 f_3)f_4'.$ But we already found what $(f_1 f_2 f_3)'$ is! We just used different letters. So we now know that

$\displaystyle (f_1 f_2 f_3 f_4)'=f_1'f_2f_3f_4+f_1f_2'f_3f_4+f_1f_2f_3'f_4+f_1f_2f_3f_4'.$

Our pattern is now confirmed! We can continue like this on towards infinity, since if we do it this way we have a formula for an (n-1)-function product rule that we can apply towards the n-function product rule. The only small challenge is formulating this pattern concisely. Using a combination of pi and sigma notation, we can state the following proposition.

Proposition 1 (General product rule). Let $f_1, f_2, \cdots, f_n$ be $n$ different differentiable functions of $x$. Then

$\displaystyle \frac{d}{dx}\prod_{i=1}^{n}f_i = \sum_{i=1}^{n}\frac{f_i'}{f_i}\prod_{j=1}^{n}f_j.$

Now that we have the general product rule, we just have to take the integral of both sides with respect to $x$ to get the general integration by parts formula. Doing so, we get

$\displaystyle \int\prod_{i=1}^{n}f_i = \int\sum_{i=1}^{n}\frac{f_i'}{f_i}\prod_{j=1}^{n}f_j\ dx.$

Although this is technically a valid formulation of the general IBP formula, I claim that integral signs are interchangeable, that is,

$\displaystyle \int\sum_{i=1}^{n}f_i\ dx = \sum_{i=1}^{n}\int f_i\ dx.$

This is due to the sum rule of integration: $\int(f+g)\ dx=\int f\ dx + \int g\ dx.$

Proposition 2 (General integration by parts). Let $f_1, f_2, \cdots, f_n$ be $n$ different continuous and differentiable functions of $x$. Then integration by parts is given by

$\displaystyle \prod_{i=1}^{n}f_i = \sum_{i=1}^{n}\int\frac{f_i'}{f_i}\prod_{j=1}^{n}f_j\ dx.$

This isn’t in a ‘useable’ form per se yet since we need to expand that sum and product notation to actually apply it in an integration, but this is as clean as the theorem is going to get. To see IBP in its familiar form, we make the substitutions $u_1=f_1(x), u_2=f_2(x),\cdots,u_n=f_n(x)$ to get

$\displaystyle \prod_{i=1}^{n}u_i = \sum_{i=1}^{n}\int\frac{du_i}{u_i}\prod_{j=1}^{n}u_j.$

Let’s see what this form looks like when $n=3$.

$\displaystyle \prod_{i=1}^{3}u_i = \sum_{i=1}^{3}\int\frac{du_i}{u_i}\prod_{j=1}^{3}u_j$

$\displaystyle u_1 u_2 u_3 = \int\frac{du_1}{u_1}(u_1u_2u_3)+\int\frac{du_2}{u_2}(u_1u_2u_3)+\int\frac{du_3}{u_3}(u_1u_2u_3)$

$\displaystyle \int u_1 u_2\ du_3 = u_1u_2u_3 -\int u_2u_3\ du_1 - \int u_1u_3\ du_2.$

This last form is finally something we can work with when trying to find, say, the fiendish integral

$\displaystyle \int xe^x\cos{x}\ dx.$

I’ll leave the work up to you if you so choose, but using the n=3 IBP formula I got a solution of

$\displaystyle \int xe^x\cos{x}\ dx = \frac{e^x(x\cos{x}+(x-1)\sin{x})}{2}.$

That’s all for now.

## An Optimal Buildpath

Fair warning: if you don’t play League of Legends this post may not be interesting to you. Or it still might. Who knows. Oh, and for people who actually want to use relevant versions of these statistics, this post was made in the middle of Patch 6.2.

Armor is a statistic that reduces incoming physical damage taken. It’s similar to magic resist, which is another defensive stat that reduces incoming magic damage taken. The Wikia article I linked does a good job of explaining how armor is calculated, but i’ll restate it here: all incoming physical damage to your champion is multiplied by a factor of $\frac{100}{100+A}$ where A stands for armor. For example, if you have 100 armor, you’ll receive $\frac{100}{100+100}$ or 0.5 times all incoming physical damage.

It sounds like you can theoretically stack armor forever and reduce your incoming physical damage to a multiplier so low that you’d take close to zero damage at all times. This graph of the multiplier function shows you why that’s not possible:

The horizontal axis is armor, while the vertical axis is the multiplier. Even at 400 armor, which is an absurdly high amount, you would still receive 20% of incoming physical damage which is relatively high compared to what you invested.

Another reason why stacking solely on armor is a bad idea is because of the notion of effective health. Effective health is the amount of damage required to kill you, taking resistances into account. If you build resistances, your EH will always be higher than your HP. If you have a lot of armor but not that much base HP, it won’t matter how much armor you have since it doesn’t take a lot to kill you. In addition, physical damage isn’t the only source of damage: magic damage and true damage (damage that is dealt directly to your HP without exception) is also prevalent. Here’s a simple example: if you have 3000 HP and 100 armor, you have an EH of 6000, which is equivalent to having 1500 HP and 300 armor. The downside to having 300 armor is when the opposing team has a good source of magic damage as well, making your armor useless.

Since every point of armor requires you to take 1% more of your maximum health in physical damage to be killed, armor doesn’t have diminishing returns per se, but it’s a much better idea to find an optimal balance between HP and armor to have the optimal EH from a frontline tank’s perspective.

It’s apparent that investing in straight health is useful because it raises EH regardless of magic or physical damage. In contrast, armor will only raise EH if physical damage is concerned, and magic resist will only raise EH is magic damage is concerned. Health is a universal defense for physical, magic, and true damage. Of course, there is also a point where simply buying HP gives diminishing returns with respect to EH. Simply put, the more well-rounded the enemy team composition is in terms of physical/magic damage, the more highly you should invest in health. If the enemy composition is almost entirely AD (physical) or AP (magical), then they made a giant mistake as long as you can abuse it: stacking the appropriate resistances here are much more helpful than raw health due to the percentage nature of how armor and magic resist works.

There’s another advantage to armor: it makes healing EH easier. Most healing abilities on champions heal a flat amount of HP. If you only buy health, it makes heals weaker in terms of effective health (it’s just a 1:1 healing to effective health increase ratio), but investing in resistances forces enemies to go through your HP bar more slowly, making the healing:EH ratio greater than one.

So the question that remains is: how do you know what to invest in at a given stage of the game? Should you prioritize flat health or resistances? To answer that, we need to optimize our EH function given a set amount of money c. How do we do that?

We first need some unit of account to gauge how much armor, magic resist, or HP is really worth. Fortunately, there are three “basic” items that grant solely armor, MR, or health. These items are Cloth Armor (300g, +15 armor), Null-Magic Mantle (450g, +25 magic resist), and Ruby Crystal (400g, +150 HP) respectively. Dividing through, we get unit costs of 20g/+1 armor, 18g/+1 MR, and 2.67g/+1 HP. Note that armor actually costs a bit higher than MR.

The tricky thing is that given constant resistance r, investing in +1 hp raises effective health by $\frac{100+r}{100}$. For example, if I have 200 armor, each point of health I invest in raises EH by 3. Taking it the other way around, every point of armor I invest in given constant health h raises EH by $\frac{h}{100}$. For example, investing in +1 magic resist with 2000 health gives 20 additional EH. (This is all assuming single-type damage, and not split.)

Since 2.67g gives +1 HP and 20g gives +1 armor, 1g of HP will give you $\frac{100+r}{2.67(100)}=\frac{100+r}{267}$ EH, and 1g of armor will give you $\frac{h}{20(100)}=\frac{h}{2000}$ EH. We now know the value (in terms of effective health) of both armor and health: the key here is to recognize that setting these values equal to each other means that our buildpath is optimized. Doing so and solving for h, we get roughly $h=750+7.5r$. This equation is what we’ve been looking for.

The horizontal axis is armor, the vertical axis is HP. If you find yourself above the line (aka to the left), invest in armor to shift right and get yourself back on the equilibrium line. If you’re below the line, invest in health to shift up.

Magic resist is pretty much the same thing. Repeating the calculations done above gives a graph of $h=670+6.7r$.

I won’t get into specifics, but the equilibrium line will shift upwards if the incoming damage is hybrid instead of just one type. This is because mixed damage favors building flat health. You should still build resistances, but not as much as if the enemy composition is mostly one type of damage.

The exact defensive items that you should buy I won’t get into, as this post is already getting a bit long. But if you can multiply your resistances by seven and add 700 to that total in your head, you should be in good shape to make some better item choices on the Rift.