Banish rawhtml shortcode, instead write shortcodes for katex, sagecell
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Anthony Wang 2024-01-06 22:15:17 -05:00
parent 185411bbaa
commit 2f240764ca
Signed by: a
SSH key fingerprint: SHA256:B5ADfMCqd2M7d/jtXDoihAV/yfXOAbWWri9+GdCN4hQ
7 changed files with 22 additions and 26 deletions

View file

@ -7,11 +7,7 @@ tags: ["math"]
---
{{< rawhtml >}}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css" integrity="sha384-n8MVd4RsNIU0tAv4ct0nTaAbDJwPJzDEaqSD1odI+WdtXRGWt2kTvGFasHpSy3SV" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js" integrity="sha384-XjKyOOlGwcjNTAIQHIpgOno0Hl1YQqzUOEleOLALmuqehneUG+vnGctmUb0ZY0l8" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous" onload="renderMathInElement(document.body, {delimiters: [{left: '$$', right: '$$', display: true}, {left: '$', right: '$', display: false}, {left: '\\begin{equation}', right: '\\end{equation}', display: true}, {left: '\\begin{align}', right: '\\end{align}', display: true}]});"></script>
{{< /rawhtml >}}
{{< katex >}}
*Originally posted on my [old old private blog](https://artofproblemsolving.com/community/c922786h1895231_a_mathematical_curiosity)*

View file

@ -7,13 +7,9 @@ tags: ["math", "game-theory", "probability", "fun", "numerical-computing", "bad-
---
{{< rawhtml >}}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css" integrity="sha384-n8MVd4RsNIU0tAv4ct0nTaAbDJwPJzDEaqSD1odI+WdtXRGWt2kTvGFasHpSy3SV" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js" integrity="sha384-XjKyOOlGwcjNTAIQHIpgOno0Hl1YQqzUOEleOLALmuqehneUG+vnGctmUb0ZY0l8" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous" onload="renderMathInElement(document.body, {delimiters: [{left: '$$', right: '$$', display: true}, {left: '$', right: '$', display: false}, {left: '\\begin{equation}', right: '\\end{equation}', display: true}, {left: '\\begin{align}', right: '\\end{align}', display: true}]});"></script>
<script src="https://sagecell.sagemath.org/static/embedded_sagecell.js"></script>
<script>sagecell.makeSagecell({"inputLocation": ".sage"});</script>
{{< /rawhtml >}}
{{< katex >}}
{{< sagecell >}}
Recently, I noticed that "Bayesian", as in Bayesian statistics or Bayesian inference, sounds very close to "Asian". Pun potential!
@ -56,8 +52,8 @@ Using the equation from above, $p(k) = \frac{1}{A}$, we get
This integral can be computed because it's just a polynomial, but then you have to find the root of a high-degree polynomial, so there's probably no explicit formula for the cutoff $k$. However, we can solve it numerically using SageMath!
{{< rawhtml >}}
<div class="sage"><script type="text/x-sage">from sage.symbolic.integration.integral import definite_integral
{{< sagescript >}}
from sage.symbolic.integration.integral import definite_integral
def f(N, M, A):
k = var('k')
@ -71,15 +67,14 @@ test(10, 4, 10)
test(10, 2, 10)
test(10, 8, 10)
test(100, 50, 10)
</script></div>
{{< /rawhtml >}}
{{< /sagescript >}}
The first three answers seem reasonable, but the fourth one is totally wack! Only one third of the players applying when half of them can get in? What's going on?
The culprit is loss-of-precision. The left side blows up to gigantic numbers, while the right side becomes a high-degree polynomial. If we move the factorials to inside the integral, we get much more reasonable results.
{{< rawhtml >}}
<div class="sage"><script type="text/x-sage">from sage.symbolic.integration.integral import definite_integral
{{< sagescript >}}
from sage.symbolic.integration.integral import definite_integral
def f(N, M, A):
k = var('k')
@ -98,15 +93,14 @@ test(10, 4, 10)
test(10, 2, 10)
test(10, 8, 10)
test(100, 50, 10)
</script></div>
{{< /rawhtml >}}
{{< /sagescript >}}
Much better! Try testing out some other values of $N, M, A$ to see what happens.
Also, using math lingo, $p(x)$ is actually the cumulative distribution for the beta distribution, so we can also use SageMath's [built-in functions](https://doc.sagemath.org/html/en/reference/probability/sage/probability/probability_distribution.html#sage.probability.probability_distribution.RealDistribution.cum_distribution_function) to compute $k$ instead of writing out all the factorials and stuff.
{{< rawhtml >}}
<div class="sage"><script type="text/x-sage">from sage.symbolic.integration.integral import definite_integral
{{< sagescript >}}
from sage.symbolic.integration.integral import definite_integral
def f(N, M, A):
k = var('k')
@ -128,8 +122,7 @@ test(10, 4, 10)
test(10, 2, 10)
test(10, 8, 10)
test(100, 50, 10)
</script></div>
{{< /rawhtml >}}
{{< /sagescript >}}
As you can see, our own implementation still has some precision issues, and doesn't quite match the results from using SageMath's beta distribution, but it's better than our first attempt. Lesson learned: leave numerical computation to the experts and use the built-in functions whenever possible.

View file

@ -18,7 +18,7 @@ That thing is mind-boggling massive. When I visited Yellowstone a few years ago,
But why was I at Yellowstone in the first place? Well, of course because of the supervolcano! Not to see the supervolcano itself (apparently scientists couldn't find the caldera for a long time because they didn't expect it to be so big), but because the supervolcano is the reason for all of Yellowstone's wonderful hot springs and geysers and landscapes. Also, if you commit a crime in the Idaho section of Yellowstone, there's [supposedly a loophole in the Constitution](https://en.wikipedia.org/wiki/Zone_of_Death_(Yellowstone) so that you can't get put on trial for it. In reality, you'd probably get a trial anyways.
My family drove to Yellowstone since our house is in St. Louis which isn't that far away, and also because there aren't any nice airports near Yellowstone. Along the way, we saw a lot of horses, antelope, and cows, but no Belted Galloways unfortunately, which we did see on a previous road trip. In particular, we passed by a group of particularly depressed-looking horses within 50 miles of Yellowstone, and my parents described the horses as {{< rawhtml >}}<ruby><rp>(</rp><rt>yōu</rt><rp>)</rp><rp>(</rp><rt></rt><rp>)</rp>{{< /rawhtml >}} (ruby annotations in HTML are kinda gory), which is a term I didn't know at the time.
My family drove to Yellowstone since our house is in St. Louis which isn't that far away, and also because there aren't any nice airports near Yellowstone. Along the way, we saw a lot of horses, antelope, and cows, but no Belted Galloways unfortunately, which we did see on a previous road trip. In particular, we passed by a group of particularly depressed-looking horses within 50 miles of Yellowstone, and my parents described the horses as 忧郁 (yōuyù), which is a term I didn't know at the time.
Later, I looked up [忧郁 on Wiktionary](https://en.wiktionary.org/wiki/%E6%86%82%E9%AC%B1#Chinese) and one of the derived terms is 忧郁的台湾乌龟, or in traditional Chinese, the complete abomination 憂鬱的臺灣烏龜. Just imagine having to hand-write that. And then on the Wiktionary page for this insane term, there's a link in the further reading section to Moegirlpedia.

View file

@ -0,0 +1,3 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css" integrity="sha384-n8MVd4RsNIU0tAv4ct0nTaAbDJwPJzDEaqSD1odI+WdtXRGWt2kTvGFasHpSy3SV" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js" integrity="sha384-XjKyOOlGwcjNTAIQHIpgOno0Hl1YQqzUOEleOLALmuqehneUG+vnGctmUb0ZY0l8" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous" onload="renderMathInElement(document.body, {delimiters: [{left: '$$', right: '$$', display: true}, {left: '$', right: '$', display: false}, {left: '\\begin{equation}', right: '\\end{equation}', display: true}, {left: '\\begin{align}', right: '\\end{align}', display: true}]});"></script>

View file

@ -1 +0,0 @@
{{ .Inner }}

View file

@ -0,0 +1,2 @@
<script src="https://sagecell.sagemath.org/static/embedded_sagecell.js"></script>
<script>sagecell.makeSagecell({"inputLocation": ".sage"});</script>

View file

@ -0,0 +1,3 @@
<div class="sage">
<script type="text/x-sage">{{ .Inner }}</script>
</div>