Thursday, 31 December 2020

Sum of periodic functions

Given the axiom of choice, you can write the identity function as a sum of two periodic functions. An example of a way to do this can be found here: https://mathblag.wordpress.com/2013/09/01/sums-of-periodic-functions/

Today, we are not going to solve this for the function ℝ → ℝ, but a simpler variant. Suppose 𝒬 is the set of all numbers that can be written as $q_1+q_2\sqrt{2}$ with q1, q2 ∈ ℚ. This set is closed under addition and multiplication. Now, find to periodic function of the form 𝒬 → 𝒬 that sum to the identity function. This is a way simpler proof that does not need the axiom of choice, but the solution follows the same recipe.

First, we will prove that q ∈ 𝒬, the decomposition into $q_1+q_2\sqrt{2}$ is unique, in other words, there exists only one pair q1, q2.

Proof:

Assume there are two pairs, q1, q2 and q1, q2 such that:

$q_1+q_2\sqrt{2}=q'_1+q'_2\sqrt{2}$

$q_1-q'_1=(q'_2-q_2)\sqrt{2}$

$\frac{q_1-q'_1}{q'_2-q_2}= \sqrt{2}$

This leads to a contradiction, as the left side is rational and the right side is irrational. The only way to solve this is if q2 − q2 = 0, because then the last step was not allowed. In this case we get: q1 − q1 = 0 Which means that both elements of the pair where equal.

Now that this is out of the way,

Define function $f: q_1+q_2\sqrt{2} \rightarrow q_1$

This function is well defined due to the previous theorem, and is periodic with period $\sqrt{2}$.

Proof:

$f(x + p\sqrt{2}) = f(q_1+q_2\sqrt{2} + p\sqrt{2}) = f(q_1+(q_2+p)\sqrt{2}) = q_1 = f(x)$

Analogous, define $g: q_1+q_2\sqrt{2} \rightarrow q_2\sqrt{2}$

g is for the same reason as above periodic with period 1

It is now easy to see that f + g is the identity function, so we found both our functions.

Sunday, 27 December 2020

Pokemon Types Battle

Consider the following two player game. Each player picks a Pokemon type, without revealing it to the other player. Each player then "deals damage" to the other player as if we are using the Pokemon advantage rules. So if your type is super effective on the opponents type, you will deal 200 damage, it is not very effective, it will deal 50 damage, if it has no effect, it will deal 0 damage, otherwise it will do 100 damage. This is played 10 times, and the player that has dealt the most damage wins. What is the optimal strategy?

As the amount of damage does not matter, only the fact whether or not you dealt more damage than the opponent, we can consider this a zero-sum game were each player only remembers the amount of damage that was dealt more than the enemy.

The type advantage table is this:
📦 🔥 💧 🌿 ❄️ 🥊 ☠️ ⛰️ 🐦 👁️ 🐞 🗿 👻 🐲 🌙 ⚙️
📦 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.5 0.0 1.0 1.0 0.5 1.0
🔥 1.0 0.5 0.5 1.0 2.0 2.0 1.0 1.0 1.0 1.0 1.0 2.0 0.5 1.0 0.5 1.0 2.0 1.0
💧 1.0 2.0 0.5 1.0 0.5 1.0 1.0 1.0 2.0 1.0 1.0 1.0 2.0 1.0 0.5 1.0 1.0 1.0
1.0 1.0 2.0 0.5 0.5 1.0 1.0 1.0 0.0 2.0 1.0 1.0 1.0 1.0 0.5 1.0 1.0 1.0
🌿 1.0 0.5 2.0 1.0 0.5 1.0 1.0 0.5 2.0 0.5 1.0 0.5 2.0 1.0 0.5 1.0 0.5 1.0
❄️ 1.0 0.5 0.5 1.0 2.0 0.5 1.0 1.0 2.0 2.0 1.0 1.0 1.0 1.0 2.0 1.0 0.5 1.0
🥊 2.0 1.0 1.0 1.0 1.0 2.0 1.0 0.5 1.0 0.5 0.5 0.5 2.0 0.0 1.0 2.0 2.0 0.5
☠️ 1.0 1.0 1.0 1.0 2.0 1.0 1.0 0.5 0.5 1.0 1.0 1.0 0.5 0.5 1.0 1.0 0.0 2.0
⛰️ 1.0 2.0 1.0 2.0 0.5 1.0 1.0 2.0 1.0 0.0 1.0 0.5 2.0 1.0 1.0 1.0 2.0 1.0
🐦 1.0 1.0 1.0 0.5 2.0 1.0 2.0 1.0 1.0 1.0 1.0 2.0 0.5 1.0 1.0 1.0 0.5 1.0
👁️ 1.0 1.0 1.0 1.0 1.0 1.0 2.0 2.0 1.0 1.0 0.5 1.0 1.0 1.0 1.0 0.0 0.5 1.0
🐞 1.0 0.5 1.0 1.0 2.0 1.0 0.5 0.5 1.0 0.5 2.0 1.0 1.0 0.5 1.0 2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1.0 0.0 0.0 0.0 0.0 1.0 0.0 -0.5 0.0 -1.5 -1.5 0.0 1.5 -1.0 0.0 1.5 1.0 -1.5
☠️ 0.0 0.0 0.0 0.0 1.5 0.0 0.5 0.0 -1.5 0.0 -1.0 0.5 -0.5 -0.5 0.0 0.0 -1.0 1.5
⛰️ 0.0 1.0 -1.0 2.0 -1.5 -1.0 0.0 1.5 0.0 -1.0 0.0 -0.5 1.5 0.0 0.0 0.0 1.0 0.0
🐦 0.0 0.0 0.0 -1.5 1.5 -1.0 1.5 0.0 1.0 0.0 0.0 1.5 -1.5 0.0 0.0 0.0 -0.5 0.0
👁️ 0.0 0.0 0.0 0.0 0.0 0.0 1.5 1.0 0.0 0.0 0.0 -1.0 0.0 -1.0 0.0 -2.0 -0.5 0.0
🐞 0.0 -1.5 0.0 0.0 1.5 0.0 0.0 -0.5 0.5 -1.5 1.0 0.0 -1.0 -0.5 0.0 1.0 -0.5 -0.5
🗿 0.5 1.5 -1.0 0.0 -1.0 1.0 -1.5 0.5 -1.5 1.5 0.0 1.0 0.0 0.0 0.0 0.0 -1.5 0.0
👻 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.5 0.0 0.0 1.0 0.5 0.0 0.0 0.0 -1.5 0.0 0.0
🐲 0.0 0.5 0.5 0.5 0.5 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.5 -2.0
🌙 0.0 0.0 0.0 0.0 0.0 0.0 -1.5 0.0 0.0 0.0 2.0 -1.0 0.0 1.5 0.0 0.0 0.0 -1.5
⚙️ 0.5 -1.5 -0.5 -0.5 0.5 1.5 -1.0 1.0 -1.0 0.5 0.5 0.5 1.5 0.0 0.5 0.0 0.0 1.5
0.0 -0.5 0.0 0.0 0.0 0.0 1.5 -1.5 0.0 0.0 0.0 0.5 0.0 0.0 2.0 1.5 -1.5 0.0

Using the technique described here we can find a Mixed strategy that solves this game.

The mixed strategy we use looks like this:
pick deal recieve overflow
Water 💧 0.1640 0.9932 0.9932 0.0000
Dragon 🐲 0.1040 1.0026 1.0026 0.0000
Grass 🌿 0.0982 1.0193 1.0193 -0.0000
Electric ⚡ 0.0907 0.9780 0.9780 0.0000
Fire 🔥 0.0898 1.0569 1.0569 0.0000
Ground ⛰️ 0.0865 1.2078 1.2078 0.0000
Steel ⚙️ 0.0793 0.9080 0.9080 0.0000
Ghost 👻 0.0617 1.0544 1.0544 0.0000
Fairy ✨ 0.0617 1.0121 1.0121 0.0000
Ice ❄️ 0.0582 1.1400 1.1400 -0.0000
Flying 🐦 0.0470 1.0132 1.0132 -0.0000
Poison ☠️ 0.0441 0.9845 0.9845 -0.0000
Dark 🌙 0.0147 1.0235 1.0235 0.0000
Normal 📦 0.0000 0.8986 0.9383 -0.0397
Bug 🐞 0.0000 0.9211 1.0444 -0.1233
Psychic 👁️ 0.0000 0.9897 1.0764 -0.0867
Fighting 🥊 0.0000 1.0141 1.1014 -0.0873
Rock 🗿 0.0000 1.1121 1.3377 -0.2256

In this table, "pick" decides the probability of each pure strategy of picking that specific type, "deal" is the expected amount of damage that the user deals if this type is used against this strategy, "receive" is the expected damage that will be received from this strategy, and overflow the difference between the two. Note that for a Nash Equilibrium, the overflow value has to be negative, because if it was positive increasing the probability of this strategy would create a strategy that would beat this. Analogous, for each type with a nonzero probability, the overflow cannot be negative, otherwise removing this type from the strategy would result in a new mixed strategy that can defeat this strategy.

putting the non zero values in a pie-chart looks like this: