Math on OranLooney.com
https://www.oranlooney.com/tags/math/
Recent content in Math on OranLooney.com
Hugo  gohugo.io
en
© Copyright {year} Oran Looney
Mon, 08 Apr 2024 00:00:00 +0000

Stacking Triangles for Fun and Profit
https://www.oranlooney.com/post/angleaddition/
Mon, 08 Apr 2024 00:00:00 +0000
https://www.oranlooney.com/post/angleaddition/
One thing you may have noticed about the trigonometric functions sine and cosine is that they seem to have no agreed upon definition. Or rather, different authors choose different definitions as the starting point, mainly based on convenience. This isn’t problematic or even particularly unusual in mathematics  as long as we can derive any of the other forms from any starting point, it makes little theoretical difference which we start from since they’re all equivalent anyway.

Kaprekar's Magic 6174
https://www.oranlooney.com/post/kaprekar/
Sun, 25 Feb 2024 00:00:00 +0000
https://www.oranlooney.com/post/kaprekar/
Kaprekar’s routine is a simple arithmetic procedure which, when applied to four digit numbers, rapidly converges to the fixed point 6174, known as the Kaprekar constant. Unlike other famous iterative procedures such as the Collatz function, the somewhat arbitrary nature of the Kaprekar routine doesn’t hint at fundamental mathematical discoveries yet to be made; rather, its charm lies in its intuitive definition (requiring no more than elementary mathematics,) its oddly offcenter fixed point of 6174, and its surprisingly rapid convergence (which requires only five iterations on average and never more than seven.

Cracking Playfair Ciphers
https://www.oranlooney.com/post/playfair/
Wed, 13 Sep 2023 00:00:00 +0000
https://www.oranlooney.com/post/playfair/
In 2020, the Zodiac 340 cipher was finally cracked after more than 50 years of trying by amateur code breakers. While the effort to crack it was extremely impressive, the cipher itself was ultimately disappointing. A homophonic substitution cipher with a minor gimmick of writing diagonally, the main factor that prevented it from being solved much earlier was the several errors the Zodiac killer made when encoding it.
Substitution ciphers, which operate at the level of a single character, are children’s toys, the kind of thing you might get a decoder ring for from the back of a magazine.

A Seriously Slow Fibonacci Function
https://www.oranlooney.com/post/slowfibonacci/
Sat, 06 Jul 2019 00:00:00 +0000
https://www.oranlooney.com/post/slowfibonacci/
I recently wrote an article which was ostensibly about the Fibonacci series but was really about optimization techniques. I wanted to follow up on its (extremely moderate) success by going in the exact opposite direction: by writing a Fibonacci function which is as slow as possible.
This is not as easy as it sounds: any program can trivially be made slower, but this is boring. How can we make it slow in a fair and interesting way?

A Fairly Fast Fibonacci Function
https://www.oranlooney.com/post/fibonacci/
Tue, 19 Feb 2019 00:00:00 +0000
https://www.oranlooney.com/post/fibonacci/
A common example of recursion is the function to calculate the \(n\)th Fibonacci number:
def naive_fib(n): if n < 2: return n else: return naive_fib(n1) + naive_fib(n2) This follows the mathematical definition very closely but it’s performance is terrible: roughly \(\mathcal{O}(2^n)\). This is commonly patched up with dynamic programming. Specifically, either the memoization:
from functools import lru_cache @lru_cache(100) def memoized_fib(n): if n < 2: return n else: return memoized_fib(n1) + memoized_fib(n2) or tabulation:

Craps Variants
https://www.oranlooney.com/post/crapsgamevariants/
Wed, 11 Jul 2018 00:00:00 +0000
https://www.oranlooney.com/post/crapsgamevariants/
Craps is a suprisingly fair game. I remember calculating the probability of winning craps for the first time in an undergraduate discrete math class: I went back through my calculations several times, certain there was a mistake somewhere. How could it be closer than $\frac{1}{36}$?
(Spoiler Warning If you haven’t calculated these odds for yourself then you may want to do so before reading further. I’m about to spoil it for you rather thoroughly in the name of exploring a more general case.

Complex Numbers in R, Part II
https://www.oranlooney.com/post/complexrpart2/
Sat, 30 Jun 2018 00:00:00 +0000
https://www.oranlooney.com/post/complexrpart2/
This post is part of a series on complex number functionality in the R programming language. You may want to read Part I before continuing if you are not already comfortable with the basics.
In Part I of this series, we dipped our toes in the water by explicitly creating some complex numbers and showing how they worked with the most basic mathematical operators, functions, and plots.
In this second part, we’ll take a more indepth look at some scenarios where complex numbers arise naturally – where they are less of a choice an more of a necessity.

Complex Numbers in R, Part I
https://www.oranlooney.com/post/complexr/
Sun, 17 Jun 2018 00:00:00 +0000
https://www.oranlooney.com/post/complexr/
R, like many scientific programming languages, has firstclass support for complex numbers. And, just as in most other programming languages, this functionality is ignored by the vast majority of users.
Yet complex numbers can often offer surprisingly elegant formulations and solutions to problems. I want to convince you that familiarizing yourself with R’s excellent complex number functionality is well worth the effort and will pay off in two different ways: first by showing you how they are so amazingly useful you’ll want to go out of your way to use them, and then by showing you how they are so common and fundamental to modern analysis that you couldn’t avoid them if you wanted to.