Saturday, 27 November 2021

Corona tests vs symptoms

corona

Who is more likely to have covid? Someone who has a negative selftest,
but has cold-like symptoms, or someone with a positive test but who
has no symptoms?

Define the following:

C: patient has convid
T: patient tested positive
S: patient is symptomatic

We use the following data from the following sources

P(S∣Cˉ)=1/200P(S|\bar C) = 1/200
from: https://www.cdc.gov/mmwr/volumes/70/wr/mm7029a1.htm and https://www.sciencedaily.com/releases/2012/06/120619225719.htm
combined to get symtpomatic common cold cases.
P(S∣C)=1/2P(S |C) = 1/2
from https://edition.cnn.com/2020/04/01/europe/iceland-testing-coronavirus-intl/index.html
P(C)=367639/11000000P(C) = 367 639/11 000 000
from https://www.worldometers.info/coronavirus/country/belgium/
P(T∣C)=0.97P(T|C) = 0.97
P(Tˉ∣Cˉ)=0.85P(\bar T|\bar C) = 0.85
https://covid-19.sciensano.be/nl/procedures/snelle-antigeen-ag-testen-0
And lets assume that the accuracy of the test is independent of the fact of the patient has symptomes
The last to givens can be extrapolated to
P(Tˉ∣C)=0.03P(\bar T|C) = 0.03
P(T∣Cˉ)=0.15P(T|\bar C) = 0.15
P(Sˉ∣Cˉ)=0.995P(\bar S|\bar C) = 0.995
P(Sˉ∣C)=0.5P(\bar S |C) = 0.5
P(C)=0.0334P(C) = 0.0334
P(Cˉ)=0.9665P(\bar C) = 0.9665

Law of bayes says:
P(A∧B)=P(A∣B)P(B)P(A \land B) = P(A|B)P(B)

If A and B are independant under constant X that
P(X∣A∧B)=P(X∧A∧B)/P(A∧B)=P(A∧B∣X)P(X)/P(A∧B)=P(A∣X)P(B∣X)P(X)/P(A∧B)=P(A∧X)P(B∧X)/P(A∧B)P(X)=P(A∧X)P(B∧X)/(P(A∧B∧X)+P(A∧B∧Xˉ))P(X)=P(A∧X)P(B∧X)/(P(A∧B∣X)P(X)+P(A∧B∣Xˉ)P(Xˉ))P(Xˉ)=P(A∧X)P(B∧X)/(P(A∣X)P(B∣X)P(X)+P(A∣Xˉ)P(B∣Xˉ)P(Xˉ))P(X)=P(A∣X)P(B∣X)P(X)/(P(A∣X)P(B∣X)P(X)+P(A∣Xˉ)P(B∣Xˉ)P(Xˉ))=11+P(A∣Xˉ)P(B∣Xˉ)P(Xˉ)P(A∣X)P(B∣X)P(X)\begin{aligned}P(X|A \land B) &= P(X \land A \land B)/P(A \land B) \\ & = P(A \land B|X)P(X)/P(A \land B) \\ &= P(A|X)P(B|X)P(X)/P(A \land B) \\ &= P(A\land X)P(B \land X)/P(A \land B)P(X)\\ &= P(A\land X)P(B \land X)/(P(A \land B \land X) + P(A \land B \land \bar X))P(X) \\ &= P(A\land X)P(B \land X)/(P(A \land B|X)P(X) +P(A \land B|\bar X)P(\bar X))P(\bar X) \\ &= P(A\land X)P(B \land X)/(P(A|X)P(B|X)P(X) +P(A|\bar X)P(B|\bar X)P(\bar X))P(X) \\ &= P(A|X)P(B|X)P(X)/(P(A|X)P(B|X)P(X) +P(A|\bar X)P(B|\bar X)P(\bar X))\\ &= \frac{1}{1 + \frac{P(A|\bar X)P(B|\bar X)P(\bar X)}{P(A|X)P(B|X)P(X)}}\\ \end{aligned}

o(X∣A∧B)=P(A∣Xˉ)P(B∣Xˉ)P(Xˉ)P(A∣X)P(B∣X)P(X)o(X|A \land B) = \frac{P(A|\bar X)P(B|\bar X)P(\bar X)}{P(A|X)P(B|X)P(X)}

This gives

P(C∣Sˉ∧T)=11+P(Sˉ∣Cˉ)P(T∣Cˉ)P(Cˉ)P(Sˉ∣C)P(T∣C)P(C)\begin{aligned}P(C| \bar S \land T) &= \frac{1}{1 + \frac{P(\bar S|\bar C)P(T|\bar C)P(\bar C)}{P(\bar S|C)P(T|C)P(C)}}\\ \end{aligned}

Filling in the given numbers this has a chance of 10,09%

And
P(C∣S∧Tˉ)=11+P(S∣Cˉ)P(Tˉ∣Cˉ)P(Cˉ)P(S∣C)P(Tˉ∣C)P(C)\begin{aligned}P(C|S \land \bar T) &= \frac{1}{1 + \frac{P(S|\bar C)P(\bar T|\bar C)P(\bar C)}{P(S|C)P(\bar T|C)P(C)}}\\ \end{aligned}

Filling in the given numbers this has a chance of 10,87%

So having symptoms while having a negative test gives you the same chance to have covid as not having symptoms and having a positive test.

Saturday, 30 October 2021

Magic 7 finite state machine

Consider the riddle in the following video
You can solve it as follows: You can write any number as $$x = \overline{x_nx_{n-1}...x_1x_0}$$ With the overline meaning concatenation, and $x_i$, the different digits of $x$. This notation is a shorthand for $$x = \sum 10^i x_i$$ We can rewrite this sum using distributivity to be $$ x = x_0 + 10(x_1 + 10(x_2 + ... )))$$ If we define our instuction $f_{x_i}$ as $$f_{x_i}(a) = x_i + 10a$$ Then $x$ can be written as $$ x = f_{x_0}(f_{x_1}(f_{x_2}( ... ))) $$ or $$ x = f_{x_0} \circ f_{x_1} \circ ... \circ f_{x_{n-1}}(x_n) $$ But as $f_{x_n}(0) = x_n$, it is more natural to write it as $$ x = f_{x_0} \circ f_{x_1} \circ ... \circ f_{x_{n-1}}\odot f_{x_n}(0) $$ We are only interested in whether or final result is a multiple of 7, ans as we only use multiplication and addition, we can consider the the full system in mod 7. $$ x \equiv f_{x_0} \circ f_{x_1} \circ ... \circ f_{x_{n-1}}\circ f_{x_n}(0) (\mod 7)$$ This formula now represents a finite state machine with 7 states, (0,1,2,3,4,5 and 6) and 10 instructions ($f_0$ to $f_9$), where the final state is the same a s the remainder of the original number when dividing by 7.
0 1 2 3 4 5 6
0 0 3 6 2 5 1 4
1 1 4 0 3 6 2 5
2 2 5 1 4 0 3 6
3 3 6 2 5 1 4 0
4 4 0 3 6 2 5 1
5 5 1 4 0 3 6 2
6 6 2 5 1 4 0 3
7 0 3 6 2 5 1 4
8 1 4 0 3 6 2 5
9 2 5 1 4 0 3 6
Now, if we call state 0 X, state 1 A, state 2 C, state 3 F, state 4 B, state 5 D and state 6 E, we arrive at the transition table given by the riddle. So by consequence, the transition table works as a division test by 7.

Wednesday, 21 July 2021

Salamander riddle

Riddle

On a particular island live a lot of salamanders with different colours. Each salamander is defined by its genetics, an ordered list of unordered pairs of so-called genes. These genetics have the following properties:

  1. A child of two salamanders will, for each gene pair, select one random gene from each parent and form a new gene pair with the two selections. (Kind of like how it works in real biology if we ignore random mutations and crossing over).
  2. Two salamanders with the same gene pairs (so they are exact clones of each other) will have the same colour.
  3. Two full siblings (so salamanders with the same parents) have the same colour (totally not how it works in biology).

Note that not all gene combinations have to be viable, so not every gene combination has a corresponding salamander.

Prove that two salamanders with different colours cannot have viable offspring.

Solution

Assume a salamander XX has genes (x1,x1′),(x2,x2′),...(x_1, x'_1), (x_2, x'_2), ... and a salamander YY has genes (y1,y1′),(y2,y2′),...(y_1, y'_1), (y_2, y'_2), .... And they have viable offspring ZZ with genes (x1,y1),(x2,y2),...(x_1, y_1), (x_2, y_2), ....
XX and ZZ can have offspring genetically identical to ZZ (by selecting xix_i from XX and yiy_i from ZZ). And can have offspring that is genetically identical to XX(by selecting xi′x'_i from XX and xix_i from ZZ). Therefore using the third axiom, XX and ZZ have the same colour. Analogously, YY and ZZ have the same colour. By consequence, XX and YY have to be the same colour.
You can find a more rigorous version of this proof that is a computer verified here: https://gitlab.com/Elmosfire/blog-links/-/blob/378a210994d4e5d5f96af505ebf1011aecbfca3f/salamander.lean.

Alternate version

If we soften the third axiom to be

Two full siblings have the same colour if neither of them is genetically equal to their parents.
In this case, a salamander can breed with another salamander of a different colour and produce viable offspring.
Assume there are three gene pairs, all with two possible genes. Call them r/R, g/G and b/B.
Then have only six viable gene combinations,
rRGGbb, rRggBB which are red.
rrgGBB, RRgGbb which are green,
RRggbB, rrGGbB which are blue.
And let each time call the first mentioned geneset to have left chirality and the right mentioned geneset to have right chirality.

Note that genesets of the same chirality are symmetric to one another by replacing r with g, g with b and b with r. Genes from the left chirality transform into genes with right chirality by swapping two genes.

Now we can check all cases:

  • If a salamander breeds with a clone of itself, the only viable offspring is itself. For example, if rRGGbb breeds with itself, the offspring can only be RRGGbb, rRGGbb and rrGGbb, of which only the middle one is viable.
  • If a salamander breeds with a salamander with the same chirality, it has one viable offspring. For example rRGGbb and rrgGBB only have rrGGbB as viable offspring.
  • Two salamanders with the same colours but different chirality cannot have viable offspring.
  • If two salamanders with different colours and chirality have offspring, the offspring always is a clone of one of the parents.
    If this argument does not convince you, you can check the system case by case:
rRGGbb(  red) & rRGGbb(  red) => <rRGGbb(  red)>
rRGGbb(  red) & rrgGBB(green) =>  rrGGbB( blue) 
rRGGbb(  red) & RRggbB( blue) =>  RRgGbb(green) 
rRGGbb(  red) & rRggBB(  red) => 
rRGGbb(  red) & RRgGbb(green) => <rRGGbb(  red)> or <RRgGbb(green)>
rRGGbb(  red) & rrGGbB( blue) => <rrGGbB( blue)> or <rRGGbb(  red)>
rrgGBB(green) & rRGGbb(  red) =>  rrGGbB( blue) 
rrgGBB(green) & rrgGBB(green) => <rrgGBB(green)>
rrgGBB(green) & RRggbB( blue) =>  rRggBB(  red) 
rrgGBB(green) & rRggBB(  red) => <rrgGBB(green)> or <rRggBB(  red)>
rrgGBB(green) & RRgGbb(green) => 
rrgGBB(green) & rrGGbB( blue) => <rrgGBB(green)> or <rrGGbB( blue)>
RRggbB( blue) & rRGGbb(  red) =>  RRgGbb(green) 
RRggbB( blue) & rrgGBB(green) =>  rRggBB(  red) 
RRggbB( blue) & RRggbB( blue) => <RRggbB( blue)>
RRggbB( blue) & rRggBB(  red) => <RRggbB( blue)> or <rRggBB(  red)>
RRggbB( blue) & RRgGbb(green) => <RRggbB( blue)> or <RRgGbb(green)>
RRggbB( blue) & rrGGbB( blue) => 
rRggBB(  red) & rRGGbb(  red) => 
rRggBB(  red) & rrgGBB(green) => <rrgGBB(green)> or <rRggBB(  red)>
rRggBB(  red) & RRggbB( blue) => <RRggbB( blue)> or <rRggBB(  red)>
rRggBB(  red) & rRggBB(  red) => <rRggBB(  red)>
rRggBB(  red) & RRgGbb(green) =>  RRggbB( blue) 
rRggBB(  red) & rrGGbB( blue) =>  rrgGBB(green) 
RRgGbb(green) & rRGGbb(  red) => <rRGGbb(  red)> or <RRgGbb(green)>
RRgGbb(green) & rrgGBB(green) => 
RRgGbb(green) & RRggbB( blue) => <RRggbB( blue)> or <RRgGbb(green)>
RRgGbb(green) & rRggBB(  red) =>  RRggbB( blue) 
RRgGbb(green) & RRgGbb(green) => <RRgGbb(green)>
RRgGbb(green) & rrGGbB( blue) =>  rRGGbb(  red) 
rrGGbB( blue) & rRGGbb(  red) => <rrGGbB( blue)> or <rRGGbb(  red)>
rrGGbB( blue) & rrgGBB(green) => <rrgGBB(green)> or <rrGGbB( blue)>
rrGGbB( blue) & RRggbB( blue) => 
rrGGbB( blue) & rRggBB(  red) =>  rrgGBB(green) 
rrGGbB( blue) & RRgGbb(green) =>  rRGGbb(  red) 
rrGGbB( blue) & rrGGbB( blue) => <rrGGbB( blue)>

If the salamander is in <>-brackets, it means it is a clone of one of the parents. You can quickly check two full siblings where none are a clone of either of the parents do not exist.
So the last hypothesis is fulfilled automatically.

Saturday, 3 April 2021

Uncountably infinite elves.

Problem Statement

The original can be found here: https://www.reddit.com/r/mathriddles/comments/mgsg6n/a_game_between_elves/

The empress has organised a game for the elves of elf city. In her very large park she has positioned stations, each labelled by a non-negative real number. Initially, there is an elf at each station. Because there are so many elves, she has had to create many stations — indeed, every \(x \geq 0\) corresponds to some station \(S_x\).

The empress will have elves run between stations in the following way: at every station \(S_x\) where \(x > 0\), there is a note telling the elves currently positioned there where they should go next. Crucially, the index of this next station will always be smaller than the index of the current one (so if at \(S_x\) the note says to go to \(S_y\), we must have \(y < x\)). The station \(S_0\) does not have a note: if an elf reaches \(S_0\), they stay put. Every time the horn is blown, all elves travel to their next station, and wait till the next horn blow. The game ends after \(\omega\) horn blows (elves live forever, of course).

Is it possible for uncountably many stations to be occupied when the game ends?

(as with previous elf problems, AC is a law of the land)

Mathematical formulation

This problem can be reformulated mathematically.

Build a function \(f\) with the following properties.

  • \(f: \mathbb{R}^+ \rightarrow \mathbb{R}^+ \)

  • \(\forall x > 0 \in \mathbb{R}, f(x) < x\)

  • \(f(0) = 0\)

  • \(\forall y \in \mathbb{R}, \exists x \in \mathbb{R} : \lim_{n \rightarrow \infty} f^n(x) = y\)

Note that \(\forall n, \forall y \in \mathbb{R}, \exists x \in \mathbb{R} :f^n(x) = y\)

Is not sufficient to make this work in the limit.

Because obviously \(f(x) = x/2\) works for every \(n\), but \(\lim_{n \rightarrow \infty} f^n(x) = 0\)

Solution

Let us note \(\lim_{n \rightarrow \infty} f^n(x)\) as \(f^\omega(x)\).

Consider the equivalence relation \(x \sim y \Leftrightarrow x-y \in \mathbb{Q}\)
Call the partitions created by this equivalence relation \(\mathcal{S}\)

The fact that this relation is an equivalence relation is trivial. The partitions \(\mathcal{S}\) has the following properties:

  • Each subset is dense in the positive reals (cause \(\mathbb{Q}\) is)

  • Each subset is countable (cause there exists bijection with \(\mathbb{Q}\))

  • There are uncountable subsets (cause the union is uncountable, and each set is countable).

According to the Axiom of choice, there exists an bijection from \(\mathcal{S}\) to \(\mathbb{R}\). Call this bijection \(\mu\).

Create for each \(S \in \mathcal{S}\) a subset \(T_S\) defined by \[T_S = \left\{s \in S \middle| s > \mu(S) \right\}\]

This set of subsets \(\mathcal{T}\) has the following properties:

  • All subsets are disjunct.

  • Each subset is dense in the reals larger than \(\mu(S)\).

  • Each subset is countable

  • There are uncountable subsets

Define \(\mu'\) such that \(\mu'(T_S) = \mu(S)\).

Now note that \(\inf T_S = \mu'(T_S)\) This is trivial because the subset is dense in the reals larger than \(\mu'(T_S)\).

From this follows that for each \(T_S\) there exists a deceasing sequence that as \(\mu'(T_S)\) as limit. Call this \(a_{TS}\).

Define \(\varphi : T_S \rightarrow \mathbb{R}\) such that \(\varphi(x)\) equals the first value in \(a_{TS}\) smaller than \(x\). This is well defined, as the limit is lower than \(x\) so a value exists.

Define \(\phi : \mathbb{R} \rightarrow \mathbb{R}\) such that \(\phi(x)\) is \(\varphi(x)\) if \(x \in T_S\), and 0 otherwise. As all options for \(T_S\) are disjunct, this is well defined.

After one application, the value becomes an element of the sequence \(a_{TS}\). After another application of the function, the value becomes an element further on in the sequence. This means that the sequence \(\phi^i(x)\) for \(i > 0\) is a subsequence of \(a_{TS}\), so as \(a_{TS}\) converges to \(\mu'(T_S)\), so does \(\phi^i(x)\).

This means that if \(x \in T_S\) then \(\phi^\omega(x) = \mu'(T_S)\)

This means that the range of \(\phi^\omega(x)\) is the range of \(\mu'\), which is the range of \(\mu\) which is all real numbers. So we have found the function we where looking for.

Saturday, 20 March 2021

Prime number sided die

Puzzle

Assume you roll 3 p-sided die, with p a prime larger than 3, and instead of looking at the individual value, you look at the sum of all three die, and the sum of the squares, and take these 2 values modulo p.

For example, if you have 7 sided die and you roll 3,4,5, then the sum is 12 and the sum of squares is 50, so the result would be (5,1), as $12\equiv 5 \pmod 7$ and $50 \equiv 1 \pmod 7$

This procedure generates p2 possible values. Proof that p2 − p of these outcomes are equally likely, and that the remaining p values also are equally likely.

Solution

For the the rest of the solution, if we use ≡, we mean $\equiv \pmod p$

Call the values of the die a, b and c

To get the likelihood of an outcome (x, y) we have to count the number of solutions of
$$\begin{cases}a+b+c &\equiv x \\a^2+b^2+c^2 &\equiv y\end{cases}$$

Now call f(x, y) the number of solutions matching these equations

Define α :  ≡ a − x/3, β :  ≡ b − x/3, γ :  ≡ c − x/3, ω :  ≡ y/2 − x2/6

As p is coprime with 2 and 3 and prime, this is well defined.

Using these definitions, after some simple aritmatic, our equations become the following:


α + β + γ ≡ 0

α2 + β2 + γ2 ≡ 2ω

Note that for every solution that exists for these equations, there exist p in the original one, namely, one solution for every value of x. In other words, the number of solutions f(x, y), is the number of solutions for the above equation, if we state that ω :  ≡ y/2 − x2/6. Let us call this f(ω)

In our equations, γ ≡  − α − β so


α2 + β2 + ( − α − β)2 ≡ 2ω


2α2 + 2β2 + 2αβ ≡ 2ω


α2 + β2 + αβ ≡ ω

This is a quadratic equation in α, and thus, The number of solutions for a given β is determined by the determinant:


D ≡  − 3β2 + ω

Call Θ(d) a function that is the number of solutions that x2 ≡ d has. This function can be refined in detail using Eulers Criteria, but in essence, this function is always 0 or 2, except when d = 0, then it is one. This function also has the nice property that Θ(r) = 2 ⇒ Θ(d) = Θ(rd)

The total number of possible solutions for different β can now be stated as


∑βΘ( − 3β2 + ω)

Now assume that ω is nonzero.

Now as p is an odd prime, we can always find an n such that
ω ≡ 4n

Now define ξ ≡ b/2n.

As there exists one β for each ξ, so the number of solutions for ξ is equal to the number of solutions for β.


∑ξΘ((1 − 3ξ2)4n) = ∑ξΘ((1 − 3ξ2))

So the counting function is independent on the value of ω as long as it is not zero. This makes up p2 − p of original cases.

Now assume ω is zero.


∑βΘ( − 3β2) = ∑βΘ( − 3) = pΘ( − 3)

So this counting function is also constant if ω is p, which makes the other p cases.

Friday, 12 March 2021

Dice

Imagine you try to simulate a single six-sided die roll by rolling a large number of die, using the following system: 1. Roll a die 2. Check what number appears the most frequent 3. If there is a single number, take that number 4. If there is a tie, scrap both and continue.

For example, if you roll

132 ⚀’s, 144 ⚁’s, 120 ⚂’s, 97 ⚃’s, 101 ⚄’s and 118 ⚅’s

Then your result is ⚁ cause 144 is the highest.

If you roll 144 ⚀’s, 144 ⚁’s, 120 ⚂’s, 97 ⚃’s, 101 ⚄’s and 118 ⚅’s

Then ⚀ and ⚁ tie, so they are scrapped, so the highest remaining is ⚂.

The question now is the following:

For what number of dice (n) is this method: 1. Well defined 2. Does it produce the numbers 1 to 6 with equal chance

and does this work for dice with other than 6 sides?

First off, the fact that it produces all number with equal chance can be explained by a simple isomorphism argument.

The only thing that is needed to proof this is well defined, is to make sure that not all numbers are tied. There are different ways in which the frequencies can all tie, namely

2-2-2 tie, for example 0x⚀ 0x⚁ 1x⚂ 1x⚃ 3x⚄ 3x⚅ (roll: ⚂⚃⚄⚄⚄⚅⚅⚅ for 8 dice) 2-4 tie, for example 1x⚄ 1x⚅ (roll:⚄⚅ for 2 dice) 3-3 tie for example 1x⚃,1x⚄,1x⚅ (roll: ⚃⚄⚅ for 3 dice)

But for the first two ties, this can only happen if the number of die is a multiple of 2, and for the last die, this can only happen if this is a multiple of 3.

This means that if the number of die is not a multiple of 2 or 3, the frequencies cannot tie.

The argument in the other direction is similar. If n is a multiple of 2, then n/2 fives and n/2 sixes will tie. Same if n is a multiple of 3, then n/3 fours, fives and sixes will tie.

For all other n

n = 2,3 or 4 has a similar argument.

And for 5, and all numbers starting from 7, there is a tie of the form

2-3-x with x a positive integer that is not one (if it was one, that one die would not be tied).

And if we assign a frequency of zero to the x, this turns into the question, can be find for each positive number n two positive integers p and q such that 2p + 3q = n. Ans this is obviously true if n is not one.