diff --git a/.gitignore b/.gitignore
index 0d27235..acc2ee8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
-_freeze/
_site/
/.quarto/
index_files/
diff --git a/_freeze/polycount/1/index/execute-results/html.json b/_freeze/polycount/1/index/execute-results/html.json
new file mode 100644
index 0000000..44aae5e
--- /dev/null
+++ b/_freeze/polycount/1/index/execute-results/html.json
@@ -0,0 +1,12 @@
+{
+ "hash": "8eea12e2dbee7f9631ee6eec95583c6d",
+ "result": {
+ "engine": "jupyter",
+ "markdown": "---\ntitle: \"Polynomial Counting 1: A primer\"\nformat:\n html:\n html-math-method: katex\njupyter: python3\ndate: \"2021-02-03\"\ndate-modified: \"2025-02-07\"\ncategories:\n - algebra\n - phinary\n - python\n---\n\nThe single most common method of representing numbers in the modern world is in *positional numeral system*.\nDespite being taught in early grade school, it is the result of millennia of mathematical thought.\n\nThe decimal system we use today assigns integers to *expansions* consisting several symbols called *numerals* next to each other.\nEach numeral is positioned at a *place value*, which has a value ten times greater than its neighbor to the right and a tenth as much of its neighbor to the left.\nDue to place values sharing a constant ratio of ten, the system is called *decimal*.\n\n$$\n\\begin{align*}\n \\scriptsize 10^2 && \\scriptsize 10^1 && \\scriptsize 10^0 && \\scriptsize 10^{-1} &\n \\quad \\} \\quad \\text{Place values} \\\\\n 4 && 3 && 2 .&& 1 &\n \\quad \\} \\quad \\text {Numerals: 1, 2, 3, 4} \\\\\n \\hline\n\\end{align*} \\\\\n\\text{Four hundred, thirty-two, and one tenth}\n$$\n\n\n\nOn the difference between \"1, 2, 3, and 4\" and \"one, two, three, and four\"\n\nFor clarity, I distinguish between numerals, such as 1, 2, 3, and 4, and numbers, such as one, two, three, and four.\nWhen discussing different systems from decimal, it is easy to write things like \"base 2\" rather than \"base two\".\nThe former leverages a distinguished symbol for the number two existing, which while at times useful, leads to confusion between the symbol and the underlying number.\n\n\nWhen referring to its value, I'll tend to write out a number's English name, rather than how it would be written in decimal.\nConversely, when I want to refer to the symbols themselves, I will enclose them in quotes; for example, \"0\" refers to the symbol 0.\n\n\n\nA Brief History\n---------------\n\nAs mentioned, this practice is millenia old.\n\nArguably, the oldest common ancestor was used by the Babylonians (circa eighteenth century BC), who instead used a sexagesimal (base sixty) system.\nIt lacked a \"decimal point\" (more properly a sexagesimal point, *fractional separator*, or *radix point*), meaning that a representation could equally as well refer to thirty (30) or one-half (1/2), or one hundred and eight thousand (108000), since all these numbers differ by a power of sixty (60).\nThis system lacked a \"0\" symbol to represent an empty place value, opting instead to simply skip them.\nThus, the onus was on the arithmetician to properly align digits, maintain spacing, and correctly interpret results.\nDespite these limitations, it was robust enough to develop basic trigonometry and [approximate the square root of 2](https://en.wikipedia.org/wiki/YBC_7289).\n\nLater, Indian mathematics developed its own place value system -- this time in the familiar base ten -- at least by the time of Aryabhata (4th century AD). It introduced the empty \"0\" symbol that the Babylonian system lacked.\nEventually, this system made its way to Europe by means of the Arabs.\nThe 16th century Dutch engineer Simon Stevin was one of the first individuals to introduce a \"decimal point\".\nThough modern notation differs slightly from his, it introduced (or perhaps re-introduced) a means of adding and multiplying numbers between integers.\nNeedless to say, it has become so popular as to become one of the most predominant ways to express numbers.\n\nLater thought realized bases other than ten were possible; for example, [binary](https://en.wikipedia.org/wiki/Binary_number) (base two) due in part to Leibniz.\nStranger yet are non-integral bases, for example the complex base $2i$ due to Knuth.\nHowever, I find bases which rely on *irrational* numbers to be the most interesting.\n\nStaying Golden\n--------------\n\nThe [*golden ratio*](https://en.wikipedia.org/wiki/Golden_ratio), a number with many apocryphal attributions, was a favorite of Greek mathematics.\nAs such, it was originally recognized in the context of geometry, long before the development of algebra.\nIt is constructed by dividing a line segment such that the ratio between the longer and shorter sub-segments is the same as the ratio between original segment and the longer sub-segment.\n\nPhrased in modern algebraic language, the golden ratio *φ* is the unique positive root of the polynomial $x^2 - x - 1$, expressed as $\\frac{1 + \\sqrt 5}{2} \\approx 1.618…$.\nDespite its name, this number is ir**ratio**nal, since it cannot be represented as a **ratio** of integers.\nFurthermore, raising it to any integral power does not produce an integer (left as an exercise to the reader).\n\nIt might seem inconceivable that one may obtain an integer (other than zero or one) by summing powers of *φ*.\nHowever, base *φ* (also called phinary) does in fact exist.\nHere is a list of (canonical) expansions up to 10\n\n:::: {.row .text-center width=\"50%\"}\n::: {#canonical-phinary-table .column}\n\n| *n* (Decimal) | *n* (Phinary) |\n|--------------:|:-------------:|\n| 0 | 0 |\n| 1 | 1 |\n| 2 | 10.01 |\n| 3 | 100.01 |\n| 4 | 101.01 |\n| 5 | 1000.1001 |\n| 6 | 1010.0001 |\n| 7 | 10000.0001 |\n| 8 | 10001.0001 |\n| 9 | 10010.0101 |\n| 10 | 10100.0101 |\n\n:::\n::::\n\nWe can obtain the entries on this list in two ways: naively (and imprecisely), or directly.\n\n\n### The Naive Approach\n\nIn the most general sense, an expansion is just a sequence of integers, or digits.\nWe can recover the value by summing the products of the integers by their place values.\nFor example, a decimal number has the form\n\n$$\n\\begin{align*}\n x &= ({a_n a_{n-1}... a_1 a_0})_{10} \\\\\n &= a_0 \\cdot 10^0 + a_1 \\cdot 10^1 + ... + a_{n-1} \\cdot 10^{n-1} + a_n \\cdot 10^{n}\n\\end{align*}\n$$\n\nwhere the $a_i$ are digits of the number.\nNegative indices (corresponding to fractional values) may also be used, but have been omitted for horizontal space.\n\nThis equivalence means that we can convert to and from a particular base.\nNaively, we might use the following \"greedy\" algorithm to derive the base-$b$ expansion\n(also called a [β-expansion](https://en.wikipedia.org/wiki/Non-integer_base_of_numeration)) of a number $x$:\n\n::: {#d3ab392d .cell execution_count=1}\n``` {.python .cell-code}\nfrom math import log, floor\n\ndef beta_expand_greedy(\n x: float,\n b: float,\n tol: float = 0.0001\n) -> dict[int, int]:\n ret = {}\n\n while x > tol: # While we're not precise enough\n p = int(floor(log(x, b))) # Get the place value p\n digit, new_x = divmod(x, b**p) # Get the quotient and remainder from\n # dividing by this place value\n ret[p] = int(digit) # Place the digit in place value p\n x = new_x # Update the value of x and repeat\n\n return ret\n```\n:::\n\n\nAs a demonstration, this algorithm, when run on a decimal number gives the same value:\n\n::: {#7518c855 .cell execution_count=2}\n``` {.python .cell-code}\ndef as_digits(digits: dict[int, int]) -> str:\n '''Convert a dictionary from `beta_expand_greedy` to a sequence of digits'''\n return \"\".join(\n str(digits.get(i, 0)) + (\".\" if i == 0 else \"\")\n for i in range(max(digits.keys()), min(digits.keys()) - 1, -1)\n )\n\none_thousand_two_hundred_thirty_four = 1234\nprint(\n \"one_thousand_two_hundred_thirty_four =\",\n as_digits(beta_expand_greedy(one_thousand_two_hundred_thirty_four, 10)),\n \"in base 10\"\n)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\none_thousand_two_hundred_thirty_four = 1234. in base 10\n```\n:::\n:::\n\n\nThere are three problems with this.\n\n1. It is inexact. `x` gets smaller, but we can only ever approximate the result.\n For numbers smaller than the tolerance, it is outright wrong.\n Due to the nature of the approximation, the result can also appear in an unexpected form:\n\n\n ::: {#837b45d7 .cell execution_count=3}\n ``` {.python .cell-code}\n phi = (5**0.5 + 1) / 2\n print(\"Expected:\", \"10100.0101\")\n print(\"Got: \", as_digits(beta_expand_greedy(10, phi)))\n ```\n \n ::: {.cell-output .cell-output-stdout}\n ```\n Expected: 10100.0101\n Got: 10100.0100101010101010101\n ```\n :::\n :::\n \n \n2. It relies on a transcendental function, the logarithm.\n - One may approximate this by repeated division, but in general, it is practical to use a floating-point function.\n\n3. The arguments `x` and `b` are given as floating-point numbers.\n However, if `p` is always positive, we can instead use integer arithmetic, which is more precise.\n Generally, we need some form of fractional arithmetic.\n\nModern FPUs are make the last two items somewhat trivial, but they necessarily make the calculation approximate.\nFortunately for phinary, there is a direct method which remedies all these issues and produces exact results without floating-point operations.\n\n\n### Deriving Expansions\n\nTake another look at the canonical representations [above](#canonical-phinary-table).\nMuch like binary, phinary only requires the digits 0 and 1.\nAnother slightly less obvious fact is that the string \"11\" never occurs in the expansion.\nThis is because we can rewrite the polynomial as the following\n\n$$\n\\begin{gather*}\n x - 2 = 0 \\implies\n \\left. \\begin{align*}\n x &= 2 \\\\\n 10_x &= 02\n \\end{align*} \\right\\}\n & \\text{Binary}\n \\\\ \\\\\n \\varphi^2 - \\varphi - 1 = 0 \\implies\n \\left. \\begin{align*}\n \\varphi^2 &= \\varphi + 1 \\\\\n 100_\\varphi &= 11_\\varphi\n \\end{align*} \\right \\}\n & \\text{Phinary}\n\\end{gather*}\n$$\n\nThis shows a connection between polynomials and positional notation which is not at all obvious.\nThe second lines leverage positional notation in lieu of a symbol; their interpretation is exactly the same as the first line.\n\nWhen we multiply or divide by ten in decimal (or two in binary), we shift the digits left or right.\nLikewise, we may multiply or divide by *φ* on either side of the equation.\nThus, it is also true that\n\n$$\n\\begin{gather*}\n \\left. \\begin{align*}\n 2^2 &= 2\\cdot 2 &&\\iff&\n 100_2 &= 20_2 \\\\\n 1 &= 2\\cdot 2^{-1} &&\\iff&\n 1_2 &= 0.2_2\n \\end{align*}\\right \\}\n & \\text{Binary}\n \\\\ \\\\\n \\left. \\begin{align*}\n \\varphi^3 &= \\varphi^2 + \\varphi &&\\iff&\n 1000_\\varphi &= 110_\\varphi \\\\\n \\varphi &= 1 + \\frac 1 \\varphi &&\\iff&\n 10_\\varphi &= 1.1_\\varphi\n \\end{align*}\\right \\}\n & \\text{Phinary}\n\\end{gather*}\n$$\n\nSince this relationship holds for any adjacent place values, it is analogous to \"carrying\" in base ten.\nIn decimal, we care if a single place value exceeds ten and increment the next place value (once for each multiple of ten).\nIn phinary, we care if there are two \"1\"s in adjacent place values, and can remove such occurrences by doing the same.\n\nMore generally, we can look at expansions not restricted to the symbols \"0\" and \"1\" and do similarly\n\n$$\n\\begin{align*}\n 32_\\varphi &= 121_\\varphi \\\\\n 0.61_\\varphi &= 1.5_\\varphi\n\\end{align*}\n$$\n\nThinking a little more cleverly, we can decompose 2 as\n\n$$\n\\begin{align*}\n \\textcolor{red}{2} = 1.\\textcolor{red}{11}_\\varphi =\n \\textcolor{blue}{1.1}1_\\varphi &= \\textcolor{blue}{1}0.01_\\varphi \\\\\n 2 &= \\varphi + \\varphi^{-2}\n\\end{align*}\n$$\n\nWith this rule in tow, we can finally start counting in phinary.\nWe count in base ten by incrementing the ones digit (or 0th place value) and carrying tens to higher digits.\nIn phinary, we have two carry rules, which we repeat until we cannot:\n\n1. Express \"011\" as \"100\"\n2. Express \"0200\" as \"1001\"\n\nAggressively applying these rules results in the same expansion as found in the [canonical table](#canonical-phinary-table).\nFor example, the expansion of three is clearly\n\n$$\n3 = 2 + 1 = 10.01_\\varphi + 1 = \\textcolor{red}{11}.01 = \\textcolor{red}{1}00.01\n$$\n\nBoth of these rules hold for larger digits as well.\nFor example, we can expand the quantity $4\\varphi + 3$ as:\n\n$$\n\\stackrel{\\text{Carry 033 = 300}}{\n 00\\textcolor{red}{043}_\\varphi =\n 00\\textcolor{red}{310}\n}_\\varphi =\n\\stackrel{\\text{Carry 0200 = 1001}}{\n 0\\textcolor{blue}{0310}_\\varphi =\n 0\\textcolor{blue}{1111}\n}_\\varphi =\n0\\textcolor{green}{11}\\textcolor{orange}{11}_\\varphi =\n\\textcolor{green}{1}0\\textcolor{orange}{1}00_\\varphi\n$$\n\nChecking approximately, this identity appears to be true:\n\n::: {#91e15dfe .cell execution_count=4}\n``` {.python .cell-code}\nprint(phi**4 + phi**2 - (4 * phi + 3))\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n0.0\n```\n:::\n:::\n\n\n### The Other Root\n\nAs a quadratic, the polynomial $x^2 - x - 1$ has two roots: $\\varphi$ and its conjugate $\\varphi^* = -\\varphi^{-1}$.\nThis implies that each phinary string can be interpreted by either root.\n\n$$\n\\begin{align*}\n 5 = 1000.1001_{\\varphi_{\\phantom{*}}}\n &= \\varphi^3 + \\varphi^{-1} + \\varphi^{-4} \\\\\n \\phantom{5} = 1000.1001_{\\varphi^*}\n &= ((-\\varphi)^{-1})^3 + ((-\\varphi)^{-1})^{-1} + ((-\\varphi)^{-1})^{-4} \\\\\n &= \\varphi^{4} -\\ \\varphi -\\ \\varphi^{-3} \\\\\n &= 10000_\\varphi -\\ 10.001_\\varphi\n\\end{align*}\n$$\n\nTo make the calculation easier, we can un-expand the postive part to make cancellation with the negative part easier.\nThis is the same as borrowing when doing typical subtraction.\n\n$$\n\\begin{align*}\n 10000_\\varphi &= 1100_\\varphi = 1011_\\varphi = 1010.11_\\varphi \\\\\n &= 1010.1011_\\varphi\n\\end{align*}\n$$\n\nProceeding onwards,\n\n$$\n\\begin{align*}\n 1000.1001_{\\varphi^*} &= 10000_\\varphi -\\ 10.001_\\varphi \\\\\n &= 1010.1011_\\varphi -\\ 10.001_\\varphi \\\\\n &= 1000.1001_\\varphi\n\\end{align*}\n$$\n\nAnd we breathe a sigh of relief since the expansion we get is the same we started with.\nThis is perhaps one of the reasons phinary expansions seem so verbose.\n\nAs an aside, since $-\\varphi^{-1}$ is negative, its powers alternate between positive and negative.\nAlso, since its magnitude is less than one, place values to the right of the radix point are larger than one, the inverse of what one is used to with base ten.\n\n\nFibonacci and Zeckendorf\n------------------------\n\nInstead of assigning place values to powers of the base, we can instead imagine a situation where the place values correspond to the values of a sequence, in particular the Fibonacci numbers.\nPhi also turns up when discussing this sequence, or more generally, sequences generated by the recurrence $a_{n+1} = a_n + a_{n-1}$.\nThis bears a striking resemblance the the polynomial mentioned above, with cursory examination by [generating functions](https://en.wikipedia.org/wiki/Generating_function) revealing the connection.\n\nFibonacci numbers are all integers, so sums of them can only express integers.\nIf we assign place values to unique Fibonacci numbers (one is \"1\" and not \"10\"), we can imagine a similar algorithm to the one presented earlier.\nThat is, we can derive an expansion for a number by subtracting out the largest Fibonacci number less than it (possibly multiple times) and repeating with the remainder.\nExpansions of the integers up to 10 are:\n\n:::: {.row .text-center width=\"50%\"}\n::: {#canonical-zeckendorf-table .column}\n\n| *n* (Decimal) | *n* (Fibonacci) |\n|--------------:|----------------:|\n| 0 | 0 |\n| 1 | 1 |\n| 2 | 10 |\n| 3 | 100 |\n| 4 | 101 |\n| 5 | 1000 |\n| 6 | 1001 |\n| 7 | 1010 |\n| 8 | 10000 |\n| 9 | 10001 |\n| 10 | 10010 |\n\n:::\n::::\n\nThese are known as *Zeckendorf expansions*.\n\nThese representations seem very similar to the phinary strings above.\nNot only that, but this sequence is also the sequence of all binary strings that do not contain two consecutive \"1\"s ([OEIS A014417](https://oeis.org/A014417)).\nThis representation is exactly as arbitrary as preferring the greedy phinary representation;\ninstead, this is the \"greedy series expansion\" of an integer in the Fibonacci numbers.\n\n### Expanding Two, Again\n\nBecause of the relationship between phi and the Fibonacci numbers, we have the familiar relation\n\n$$\n\\begin{align*}\n 2 F_n &= F_{n+1} + F_{n-2} \\\\\n 0200_{Z} &= 1001_{Z}\n\\end{align*}\n$$\n\nFor small $n$, this identity seems wrong, but it can in fact be justified:\n\n$$\n\\begin{array}{c|ccccc:cc}\n & 8 & 5 & 3 & 2 & 1 & 1 & \\sim \\\\ \\hline\n 2 & & & & & 2 & & \\\\\n & & & & 1 & 0 & 0 & 1 \\\\\n & & & & 1 & 0 \\\\ \\hline\n 4 & & & & 2 & 0 & & \\\\\n & & & 1 & 0 & 0 & 1 & \\\\\n & & & 1 & 0 & 1\n\\end{array}\n$$\n\nIn the expansion of 2, the rightmost \"1\" seems to underflow.\nHowever, in the expansion of 4, we must consider the second \"1\" in the negative first place value.\nIt acts as a sort of temporary storage which is immediately transferred into place value zero.\n\n\nSynthesis: Generalizing Phinary\n-------------------------------\n\nBy starting with the golden ratio base, many natural questions arise.\nDoes this approach work with other quadratic roots?\nAre there any restrictions on the coefficients (or sequences)?\nDoes it work with any polynomial with positive roots?\nAre only monic polynomials allowed to be used?\nWhat digits are minimally necessary to represent any integer?\nHow \"canonical\" can \"canonical\" really be?\n\nRather than answering these questions or giving proofs, I think it's best to lay some ground rules.\nUsing the above examples, I define two genera of positional number systems:\n\n- A *fractional* number system is one where the place values are determined by the powers of the root of a polynomial with integer coefficients.\n The \"fraction\" in fractional comes allowing negative powers of our base.\n Therefore, we can represent rational numbers and use a fractional separator.\n - Naturally, the decimal system currently in use fits in here, corresponding to the polynomial $x - 10$.\n - Likewise, phinary corresponds to the polynomial $x^2 - x - 1$.\n\n- An *integral* number system is one where the place values are given by a strictly increasing integral sequence.\n It can express only integers and there is no fractional separator.\n\n - As an example, the geometric series produced from an integer (e.g.: 1, 2, 4, 8, …), corresponds to a typical system without support for fractions.\n\n - The already-discussed the Fibonacci base fits here as well.\n In fact, since linear recurrence relations correspond to polynomials, this extends to a correspondence between integral and fractional systems.\n\n - Other sequences are also valid, like the square numbers.\n In the \"square number base\" we know the digital root (of canonical expansions) never exceeds 4 due to\n [Lagrange's four-square theorem](https://en.wikipedia.org/wiki/Lagrange%27s_four-square_theorem).\n\n\n### Alphabets\n\nA positional number system not only has place values, but a *numeral alphabet*.\nIn standard decimal, there are ten distinct symbols including \"0\": {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.\nThe choice of symbols is arbitrary\n (it can vary [with](https://en.wikipedia.org/wiki/Eastern_Arabic_numerals) [language](https://en.wikipedia.org/wiki/Chinese_numerals)),\n but each has a *weight*, the integer quantity assigned to them.\nIn the modern Western world, [Hindu-Arabic numerals](https://en.wikipedia.org/wiki/Hindu%E2%80%93Arabic_numeral_system) are standard and distinct from alphabetic characters,\n so the distinction between \"weight\" and \"symbol\" can be ignored by using them conventionally for the first ten whole numbers.\nSubsets of this alphabet include the binary alphabet, {0, 1}, and the ternary alphabet, {0, 1, 2}.\n\nA *minimal alphabet* for a number system is an alphabet of the smallest size which can still represent every integer.\nIt is most convenient to consider an alphabet of integers from 0 up to a particular value,\n even though it may be true that minimal alphabets might exist which \"skip\" over certain weights.\n\nIt is often useful to be able to borrow a symbol of a certain weight, even if it would not be present in a minimal alphabet\n (for example, using \"2\" when it is convenient to do so, as above).\n In this manner, it is also possible to interpret the representation of a number in one base in another arbitrary base.\n\n*Balanced alphabets* also exist, which contain negative numeral weights.\nFor example, the balanced ternary alphabet consists of the weights of $\\{-1, 0, 1\\}$.\nPowers of 3 always determine the place values in ternary, but expansions change to suit the alphabet.\nTo conserve horizontal space, I'll use the symbols $\\bar{1}$ and \"T\" to signify -1.\n\n\n### Canonicity\n\nFinding the *canonical expansion* of a number should be as simple as incrementing the 0th place value and aggressively applying the carry.\nFor fractional systems, this amounts to adding one the 1's digit, and for integral ones, adding it to the rightmost.\n\nNote that irrational systems have at least *two* carry rules.\nIn phinary, these are the \"011\" = \"100\" rule, and the \"0200\" = \"1001\" rule.\n\n\n### Questions About the Above Rules\n\nOne may take several exceptions with these definitions and the restrictions they impose, to which I will offer a brief dismissal:\n\n\n#### Why limit alphabet weights to integers?\n\nIntegers and integer arithmetic are fundamental systems with very straightforward addition and multiplication.\nAdding more complex rules by introducing fractions or polynomial roots creates unnecessary complications.\n\n#### Why prefer weights of integers from 0 to n?\n\nAlphabets are best kept inductive -- either a weight is the largest possible or its successor is also a weight.\nIf we start with a negative weight, this includes balanced alphabets.\n\nUnbounded alphabets have their uses.\nFor example, we might hold off from carrying until necessary, or prefer expansions like\n $21_\\varphi = 1 + 2\\varphi$ to $21_\\varphi = 1000_\\varphi = \\varphi^4$.\n\nThe inductive base case, the binary alphabet, is fairly important for two reasons:\n\n- Expansions can always be padded with 0s to produce other valid expansions.\n- If \"1\" does not exist in the alphabet, it should be derivable in some way from other symbols like \"2\" and \"3\".\n\n\n#### Do we prefer monic polynomials?\n\nThe recurrence relation corresponding to a non-monic polynomials must cycle mod the leading term.\nThe simplest (only?) examples are just geometric series; in other words, normal integral systems.\n\nFor example, the powers of 3 satisfy $2a_{n+1} = 5a_n + 3a_{n-1}$. But the RHS simplifies:\n\n$$\n2a_{n+1} = 5a_n + 3a_{n-1} = 5a_n + a_n = 6a_n \\\\\na_{n+1} = 3a_n\n$$\n\nIncidentally, 3 is a root of $2x^2 - 5x - 3$.\nFermat's little theorem is likely a component in proving this generally.\n\n\n#### Why exclude transcendentals from fractional systems?\n\nConvergent series like $\\exp{x}$ require coefficients which shrink quickly, far below a magnitude of 1.\nThis conflicts with our expectation of counting polynomials to be integral polynomials.\nThis is disappointing, since relatively simple (in terms of continued fractions, combinatorics, etc) transcendental like $e$ relies on a series in rationals.\n\n\nClosing\n-------\n\nWith these restrictions in mind, I wrote a simple Haskell library to help explore these systems (found [here](https://github.com/queue-miscreant/GenBase)).\nThe [next post](../2) will discuss quadratic polynomials with larger coefficients than 1, and problems not discussed with higher expansions.\n\n",
+ "supporting": [
+ "index_files"
+ ],
+ "filters": [],
+ "includes": {}
+ }
+}
\ No newline at end of file
diff --git a/_freeze/polycount/3/index/execute-results/html.json b/_freeze/polycount/3/index/execute-results/html.json
new file mode 100644
index 0000000..cc45b74
--- /dev/null
+++ b/_freeze/polycount/3/index/execute-results/html.json
@@ -0,0 +1,12 @@
+{
+ "hash": "3ce9c87a34928281a8934daca818c9e4",
+ "result": {
+ "engine": "jupyter",
+ "markdown": "---\ntitle: \"Polynomial Counting 3: The third degree\"\nformat:\n html:\n html-math-method: katex\ndate: \"2021-02-06\"\ndate-modified: \"2025-02-08\"\njupyter: python3\ncategories:\n - algebra\n - phinary\n - binary\n - python\n---\n\n\n\nThis post assumes you have read the [first](../1) post, which introduces generalized positional counting, and the [second](../2), which restricts the focus and specifies the general aim.\n\nThus far, the systems have been based on quadratic polynomials and two-term linear recurrences,\n or more directly, carries of width two.\nNumbers larger than one introduce certain complications to carries.\nWith that in mind, let's go back to things closer to phinary and Fibonacci.\n\n\nTribonacci and Beyond\n---------------------\n\nThe *Tribonacci numbers* ([OEIS A000073](http://oeis.org/A000073)) come from elongating the Fibonacci recurrence to 3 terms.\nIn other words, this is the carry/recurrence $\\langle 1,1,1|$.\nThe Tribonacci numbers are seeded with two zeros followed by a single one; thus, the sequence begins $0, 0, 1, 1, 2, 4, 7, 13,\\dots$\nThe *Tribonacci constant* is the limiting ratio of these numbers (i.e., the positive real root of $x^3 - x^2 - x - 1$) with approximate value\n $T = 1.8393\\dots$\n\nThe number two bounds both this number and the terms in the recurrence, so its expansion can be deduced:\n\n$$\n\\textcolor{red}{2} = 1.\\textcolor{red}{111}_T = \\textcolor{blue}{1.11}1_T = \\textcolor{blue}{1}0.001_T\n$$\n\nNaturally, the string \"111\" will be illegal in both systems.\nThe Tribonacci expansions of the integers are as follows:\n\n:::: {.row .text-center width=\"60%\"}\n::: {#canonical-tribonacci-table .column}\n\n| *n* (Decimal) | *n* (base $T$) | *n* (Tribonacci) |\n|--------------:|:--------------:|------------------|\n| 0 | 0 | 0 |\n| 1 | 1 | 1 |\n| 2 | 10.001 | 10 |\n| 3 | 11.001 | 11 |\n| 4 | 100.100011 | 100 |\n| 5 | 101.100011 | 101 |\n| 6 | 110.101011 | 110 |\n| 7 | 1000.101011 | 1000 |\n| 8 | 1001.101011 | 1001 |\n| 9 | 1010.110100011 | 1010 |\n| 10 | 1100.010100011 | 1011 |\n\n:::\n::::\n\nSince \"111\" is a rarer string than \"11\", the integral base more closely resembles standard binary.\n\nExtensions of the Fibonacci numbers, which have an $n$-term recurrence\n (seeded with $n - 1$ zeroes followed by a one) are called \"n-nacci\" or \"n-bonacci\" numbers.\nIf we discard the seeding terms, then for larger and larger *n*, this sequence of sequences appears\n to approach the powers of two.\n\n$$\n\\begin{matrix}\n \\text{Fibonacci: } & & & 0,& 1,& 1,& 2,& 3,& 5,& 8\\dots \\\\\n \\text{Tribonacci: } & & 0,& 0,& 1,& 1,& 2,& 4,& 7,& 13\\dots \\\\\n \\text{Tetranacci: } & 0,& 0,& 0,& 1,& 1,& 2,& 4,& 8,& 15\\dots \\\\\n \\vdots \\\\\n \\text{Binary: } & (\\dots,& 0,& 0,& 1,)& 1,& 2,& 4,& 8,& 16\\dots\n\\end{matrix}\n$$\n\nIn the limit, the rightmost and leftmost \"1\"s in the carry $\\langle 1, 1, ..., 1, 1 |$ are\n infinitely far away from each other.\nThis is similar to binary, in which $2 = 1.1111\\dots_2$.\nThis argument is clearer if we directly manipulate the carry as a polynomial $p_n(x)$:\n\n$$\n\\begin{align*}\np_n &= x^n - x^{n-1} - … - x - 1 \\\\\n-p_n &= -x^n + x^{n-1} + … + x + 1 \\\\\nx^n - p_n &= x^{n-1} + … + x + 1 \\\\\nx - p_n x^{-n+1} &= 1 + x^{-1} + … x^{-n+2} + x^{-n+1} \\\\[8pt]\n\\text{Let } n &\\rightarrow \\infty \\\\\nx &= 1 + x^{-1} + x^{-2} + x^{-3} + …\n\\end{align*}\n$$\n\nSince both *φ* and $T$ are greater than 1, we can assume that $x > 1$, which causes the\n $x^{-n+1}$ term to vanish in the limit.\nUnfortunately, this means $p_n$ should diverge, invalidating the above argument.\n\nIgnoring this, the last line can be manipulated as a power series:\n\n$$\n\\begin{align*}\n\\frac{1}{1 - x} &= 1 + x + x^2 + x^3 + \\dots \\\\\n\\frac{1}{1 - (1/x)} &= 1 + x^{-1} + x^{-2} + x^{-3} + \\dots \\\\\nx &= \\frac{1}{1- (1/x)} \\\\\nx - 1 &= 1 \\\\\nx &= 2\n\\end{align*}\n$$\n\nWhich is to imply that, in a non-rigorous sense and by partially assuming the conclusion,\n that the $n$-nacci constants approach two.\n\n\nGolder than Gold\n----------------\n\nAll carries entirely made up of \"1\"s correspond to the $n$-nacci constants.\nWhile this would appear to exhaust every sequence without going to negative numbers,\n it ignores the potential of carries with a \"0\".\n\nStarting simple, Narayana's cows sequence ([OEIS A000930](http://oeis.org/A000930)) corresponds to\n the recurrence $\\langle 1,0,1|$.\nIt may be seeded with either three 1's, or in the same way as above, with a sequence of 0's followed by a 1.\nThe limiting ratio $\\psi \\approx 1.4656\\dots$ is called the supergolden ratio.\nThe introduction of \"0\"s turns out to have big implications, since the concatenation trick to devise\n the expansion of two no longer works.\nHowever, hope is not lost.\n\n$$\n\\begin{gather*}\n 1\\textcolor{red}{1}000_\\psi\n = 10\\textcolor{red}{101}_\\psi\n = \\textcolor{blue}{101}01_\\psi\n = \\textcolor{blue}{1}00001_\\psi \\\\\n \\textcolor{red}{2} = 1.\\textcolor{red}{101}_\\psi\n = \\textcolor{blue}{1.1}01_\\psi\n = \\textcolor{blue}{1}0.001\\textcolor{blue}{1}_\\psi\n = 10.00\\textcolor{purple}{11}_\\psi\n = 10.0\\textcolor{purple}{1}0000\\textcolor{purple}{1}_\\psi\n\\end{gather*}\n$$\n\nIncredibly, the carry contains not only an explicit rule for \"101\", but implicit rules \"2\" and \"11\".\nThis sort of makes sense: since $\\psi < \\varphi$, adjacent place values are \"too dense\",\n and therefore we can rewrite the string \"11\".\nOn the other hand, attempting to manipulate \"1001\" and \"10001\" results in circuiting back to the original string.\n\n$$\n\\begin{split}\n 100\\textcolor{red}{1}000000_\\psi\n &= 1000\\textcolor{red}{101}000_\\psi\n = 1000\\textcolor{orange}{1}01000_\\psi\n = 10000\\textcolor{orange}{1}1\\textcolor{orange}{1}00_\\psi \\\\\n &= 10000\\textcolor{blue}{11}100_\\psi\n = 1000\\textcolor{blue}{1}0010\\textcolor{blue}{1}_\\psi\n = 1000100\\textcolor{red}{101}_\\psi \\\\\n &= 100010\\textcolor{red}{1}000_\\psi\n = 1000\\textcolor{orange}{101}000_\\psi\n = 100\\textcolor{orange}1000000_\\psi \\\\ \\\\\n \\textcolor{red}{1}0001000_\\psi\n &= 0\\textcolor{red}{101}1000_\\psi\n = 010\\textcolor{blue}{11}000_\\psi\n = 01\\textcolor{blue}{1}0000\\textcolor{blue}{1}_\\psi \\\\\n &= 0\\textcolor{purple}{11}00001_\\psi\n = \\textcolor{purple}{1}0000\\textcolor{purple}{1}01_\\psi \\\\\n &= 10000\\textcolor{red}{101}_\\psi = 1000\\textcolor{red}{1}000_\\psi\n\\end{split}\n$$\n\nI call these strings of \"0\"s sandwiched between \"1\"s *spacings*.\nThe smallest spacing, with a width of zero, is the Fibonacci recurrence.\nIf we forbid both the width-1 and width-0 spacings from appearing in supergolden expansions,\n we obtain the following list:\n\n:::: {.row .text-center width=\"60%\"}\n::: {#canonical-supergolden-table .column}\n\n\n\n| *n* (Decimal) | *n* (base $\\psi$) |\n|--------------:|:-------------------:|\n| 0 | 0 |\n| 1 | 1 |\n| 2 | 10.0100001 |\n| 3 | *100.0110001* |\n| 3 | 100.1000100001 |\n| *4* | *110.0001100001* |\n| 4 | 1000.1000100001 |\n| *5* | *1010.0001100001* |\n| 5 | 10000.0010001 |\n| 6 | 10001.0010001 |\n| *7* | *10010.0110002* |\n| *7* | *10010.1000012* |\n| 7 | 100000.0001000001 |\n| 8 | 100001.0001000001 |\n| 9 | 100100.0000001001 |\n| 10 | 1000000.0000001001 |\n\n:::\n::::\n\nIn the above table, some intermediate steps are shown in red,\n but the last entry for each integer is canonical.\nNot only does the number of digits grow radically faster than in phinary (or even binary),\n but there are many more intermediate steps.\n\nFor space reasons, I do not show the integral dual.\nSlowly-growing sequences, which have largely uninteresting integral systems, dominate the rest of this post.\nTherefore, the remainder of this post will focus solely on fractional systems.\n\n\nRadiant Plastic\n---------------\n\nA similar degree 3 recurrence is $\\langle 0,1,1|$.\nIts root corresponds to the plastic ratio $\\rho \\approx 1.3247\\dots$.\nA number of sequences share this recurrence; when seeded with $0, 0, 1$ as before,\n the best match is the Padovan sequence ([OEIS A000931](http://oeis.org/A000931)),\n which begins with an additional one.\n\nSince $\\rho < \\psi < \\varphi$, we should expect that spacings of at least width two are illegal.\nThe system turns out to be even stricter than that: spacings up to and including width three are expandable.\n\n$$\n\\begin{array}{c|c}\n \\text{Width} & \\textcolor{red}{0} & \\textcolor{green}{1} & 2 & \\textcolor{blue}{3} \\\\ \\hline\n & 0\\textcolor{red}{011}_\\rho\n & 010\\textcolor{red}{1}000_\\rho\n & 0\\textcolor{red}{1}00\\textcolor{red}{1}00000_\\rho\n & 0\\textcolor{red}{1}0001_\\rho\n \\\\\n & \\textcolor{red}{1}000_\\rho\n & 0100\\textcolor{red}{011}_\\rho\n & 00\\textcolor{red}{011}\\textcolor{red}{011}00_\\rho\n & 00\\textcolor{red}{011}1_\\rho\n \\\\\n && 0\\textcolor{blue}{10001}1_\\rho\n & 000\\textcolor{blue}{11011}00_\\rho\n & 000\\textcolor{orange}{111}_\\rho\n \\\\\n && \\textcolor{blue}{1}000001_\\rho\n & 00\\textcolor{blue}{1}0101000_\\rho\n & 00\\textcolor{orange}{1}100_\\rho\n \\\\\n &&\n & 0010\\textcolor{green}{101}000_\\rho\n & 0\\textcolor{red}{011}00_\\rho\n \\\\\n &&\n & 001\\textcolor{green}{1000001}_\\rho\n & \\textcolor{red}{1}00000_\\rho\n \\\\\n &&\n & 0\\textcolor{red}{011}000001_\\rho\n \\\\\n &&\n & \\textcolor{red}{1}000000001_\\rho\n \\\\\\\\\n \\hline\n & s_0 = \\rho^2\n & s_1 = \\rho s_{5}\n & s_2 = \\rho s_{8}\n & s_3 = \\rho\n\\end{array}\n$$\n\nThe final line is shorthand for the spacing rules:\n\n- The zero-spacing is equal to a one in the place value two higher than it\n- The one-spacing is equal to an five-spacing which begins one place value higher than it\n- The two-spacing is equal to an eight-spacing which begins one place value higher than it\n- The three-spacing is equal to a one in the place value one higher than it\n\nWith these rules, we can write a canonical expansion expansion for 2:\n\n$$\n\\begin{align*}\n \\textcolor{red}{2}\n &= 1.\\textcolor{red}{011}\n = \\textcolor{blue}{1.011}\n = \\textcolor{blue}{1}\\overbrace{0.0100000}^{8 \\text{ digits}}\\textcolor{blue}{1} \\\\\n &= \\textcolor{purple}{10.01}000001\n = \\textcolor{purple}{1}00.000000\\textcolor{purple}{1}1 \\\\\n &= 100.00000\\textcolor{red}{011}\n = 100.0000\\textcolor{red}{1}\n\\end{align*}\n$$\n\nSince $\\rho < \\sqrt 2$, the largest place value in the expansion of two is $\\rho^2$, which\n distinguishes it from previous systems.\n\nSimilarly to how the width-two and width-three spacings are allowed in the supergolden ratio base,\n we realize that the width-four spacing cannot be expanded further in the plastic ratio base:\n\n$$\n\\begin{align*}\n \\textcolor{red}{1}0000\\textcolor{red}{1}000\n &= 0\\textcolor{red}{011}00\\textcolor{red}{011}\n = 001\\textcolor{blue}{10001}1\n = 00\\textcolor{blue}{2}000001 \\\\\n &= \\textcolor{blue}{1}000000\\textcolor{blue}{1}1\n = 100001000\n\\end{align*}\n$$\n\nWith these implicit rules derived for spacings of width smaller than three,\n the plastic expansions of the integers up to ten are as follows:\n\n:::: {.row .text-center width=\"70%\"}\n::: {#canonical-plastic-table .column}\n\n\n\n| *n* (Decimal) | *n* (base $\\rho$) |\n|--------------:|:----------------------------:|\n| 0 | 0 |\n| 1 | 1 |\n| 2 | 100.00001 |\n| *3* | *101.00001* |\n| *3* | *1000.00101* |\n| 3 | 1000.01000001 |\n| *4* | *10000.0101000000001* |\n| 4 | 10000.1000001000001 |\n| *5* | *10100.0000001000001* |\n| 5 | 100000.1000001000001 |\n| *6* | *100001.1000001000001* |\n| *6* | *100100.0000001000001* |\n| *6* | *1000000.0010001000001* |\n| 6 | 1000000.0100000000001 |\n| *7* | 1000001.0100000000001 |\n| 7 | 1000010.0000100000001 |\n| *8* | *1001000.0000100000001* |\n| *8* | *10000000.0100100000001* |\n| *8* | *10000000.1000000001001* |\n| 8 | 10000000.100000001000000001 |\n| 9 | 10000100.000000001000000001 |\n| 10 | 10001000.001000001000000001 |\n\n:::\n::::\n\nClearly, this base is incredibly sensitive.\nA number as small as 8 has a fractional part as small as $\\rho^{-18}$ in its expansion.\n\n\nSkipped Spacings\n----------------\n\nWhen discussing the expandable spacings in the supergolden and plastic bases, they jumped from\n width one to width three.\nDid we forgot width 2?\nThe strings \"1001\" and \"10001\" are associated to the carries\n $\\langle 1, 0, 0, 1|$ and $\\langle 1, 0, 0, 0, 1|$.\n\n| Spacing Width | Carry | Integral Sequence | Root |\n|---------------|--------------------------------------------|------------------------------------------|---------------------------|\n| 0 | $\\langle 1,1|$ | Fibonacci numbers, Lucas numbers | Golden Ratio, $\\varphi$ |\n| 1 | $\\langle 1,0,1|$ | Narayana's cows sequence | Supergolden Ratio, $\\psi$ |\n| 2 | $\\langle 1,0,0,1|$ | [OEIS A003269](https://oeis.org/A003269) | Unnamed $(\\upsilon?)$ |\n| 3 | $\\langle 1,0,0,0,1| \\simeq \\langle 0,1,1|$ | Padovan sequence, Perrin sequence | Plastic Ratio, $\\rho$ |\n\nI chose the symbol $\\upsilon$ since it came from the second half of the Greek alphabet,\n like the others.\n\nWhile the width-two spacing is a irreducible polynomial like its predecessors,\n the width-three one can be factored\n\n::: {#aae758ce .cell execution_count=2}\n``` {.python .cell-code}\nfrom sympy.abc import x\n\ndef spacing(width):\n return x**(width + 2) - x**(width + 1) - 1\n\nspacing(3).factor()\n```\n\n::: {.cell-output .cell-output-display .cell-output-markdown execution_count=2}\n$\\displaystyle \\left(x^{2} - x + 1\\right) \\left(x^{3} - x - 1\\right)$\n:::\n:::\n\n\nThis also means that despite $\\rho$ and $\\psi$ being cubic roots,\n $\\upsilon$ is irreducibly a quartic root, despite being between them in terms of spacing width.\n\nThe right polynomial may be familiar from the previous post as $\\langle 1, -1 |$,\n which only has complex roots.\nIt happens to be the sixth cyclotomic polynomial ($\\Phi_6$), and allows the width-three spacing\n to be equivalent to the simpler plastic ratio carry.\n\nAs previously stated, the cyclotomic polynomials cause big trouble for carries.\nOther than factoring, there appears to be no way to derive $\\langle 0,1,1|$ from $\\langle 1,0,0,0,1|$.\nAt best, we can observe the following:\n\n$$\n\\begin{matrix}\n \\langle 1,0,0,0,1| && \\langle 0,1,1| \\\\ \\hline\n 11111 &\\iff& 11111 \\\\\n 101110 && 1000111 \\\\\n 1001100 &\\iff& 1001100 \\\\\n 10001000 && 1100000 \\\\\n 100000000 &\\iff& 100000000 \\\\\n\\end{matrix}\n$$\n\n\n### Chopped Circles\n\nThe appearance of a cyclotomic factor is not unique to the width-three spacing.\nEach of the smaller-width rules in the supergolden and plastic bases can be reexamined as polynomials.\nAfter converting and factoring, their cyclotomic factors become clear:\n\n$$\n\\begin{gather*}\n 11000_\\psi = 100001_\\psi \\\\\n 1\\bar{1}\\bar{1}001_\\psi = 0 \\\\\n \\psi^5 - \\psi^4 - \\psi^3 + 1 \\\\\n (\\psi - 1)(\\psi + 1)(\\psi^3 - \\psi^2 - 1) \\\\\n \\Phi_1 \\Phi_2 \\langle 1,0,1|\n \\\\ \\\\\n \\begin{gather*}\n 101000_\\rho = 1000001_\\rho &\n 100100000_\\rho = 1000000001_\\rho \\\\\n 1\\bar{1}0\\bar{1}001_\\rho = 0 &\n 1\\bar{1}00\\bar{1}00001_\\rho = 0 \\\\\n \\rho^6 - \\rho^5 - \\rho^3 + 1 &\n \\rho^9 - \\rho^8 - \\rho^5 + 1 \\\\\n (\\rho - 1)(\\rho^2 + 1)(\\rho^3 - \\rho - 1) &\n \\dots(\\rho^2 - \\rho + 1)(\\rho^3 - \\rho - 1) \\\\\n \\Phi_1 \\Phi_4 \\langle 0,1,1| &\n \\Phi_1 \\Phi_2 \\Phi_4 \\Phi_6 \\langle 0,1,1|\n \\end{gather*}\n\\end{gather*}\n$$\n\nThough I am uncertain without a proof, it seems that cyclotomic polynomials\n play a role in spacing out \"1\"s.\nThis is to say that spacings have a \"fundamental\" irreducible polynomial.\nBy multiplying certain cyclotomic polynomials by the fundamental, (all?) smaller spacings\n can produce spacings the size of the fundamental or less.\n\nNaturally, I attempted to write a program to compute lesser spacings from an implicit rule.\nGenerally, this entailed assembling all lesser spacings, then expanding the rightmost 1\n if unable to find any spacing, else replacing and continuing.\nUnfortunately, since it operates in lockstep, it gets stuck easily, and I had little success.\nMy Haskell code can be found [here](zero_spacing.hs).\n\n### Inherently Factorable Spacings\n\nThe width-three spacing is not fundamental, since it can be factored.\nWe can collect reducible spacings into a table:\n\n::: {#6f97736a .cell execution_count=3}\n``` {.python .cell-code}\nis_irreducible = lambda p: len(p.factor().as_ordered_factors()) == 1\ndisplay = lambda x: color(\"green\", \"Yes\") if x else color(\"red\", \"No\")\n\nMarkdown(tabulate(\n zip(*(\n [[\"*n*\", \"Irreducible?\"]]\n + [[ str(i), display(is_irreducible(spacing(i))) ] for i in range(20)]\n ))\n))\n```\n\n::: {.cell-output .cell-output-display .cell-output-markdown execution_count=3}\n------------ ------------------------------------- ------------------------------------- ------------------------------------- ---------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ---------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ---------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- -------------------------------------\n*n* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\nIrreducible? YesYesYesNoYesYesYesYesYesNoYesYesYesYesYesNoYesYesYesYes\n------------ ------------------------------------- ------------------------------------- ------------------------------------- ---------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ---------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ---------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- -------------------------------------\n:::\n:::\n\n\nIn the range given, this table appears to repeat every six terms.\nWe can examine each of these factors directly:\n\n$$\n\\begin{align*}\n x^5 - x^4 - 1 &= (x^2 - x + 1)\n (x^3 - x - 1) \\\\\n &= 1\\bar{1}1_x * 10\\bar{1}\\bar{1}_x \\\\\n x^{11} - x^{10} - 1 &= (x^2 - x + 1)\n (x^9 - x^7 - x^6 + x^4 + x^3 - x - 1) \\\\\n &= 1\\bar{1}1_x * 10\\bar{1}\\bar{1}0110\\bar{1}\\bar{1}_x \\\\\n x^{17} - x^{16} - 1 &= (x^2 - x + 1)\n (x^{15} - x^{13} - \\dots + x^4 + x^3 - x - 1) \\\\\n &= 1\\bar{1}1_x * 10\\bar{1}\\bar{1}0110\\bar{1}\\bar{1}0110\\bar{1}\\bar{1}_x \\\\\n 5, 11, 17, \\dots &= 6n + 5\n\\end{align*}\n$$\n\nEach of these polynomials has $\\Phi_6$ as a common factor.\nThe other factor appears to be a truncation of the repeating string \"$\\underline{0110\\bar{1}\\bar{1}}$\".\n^[Since I already use the overbar for negative digits, I gather repeating terms using an underline as a vinculum.]\nInterpreted as a power series, this is the reciprocal of $-\\Phi_6$ ([OEIS A010892](https://oeis.org/A010892)).\n\nAs the carry approaches infinite width, the $x$ terms go to 0 for $x < 1$.\nThis shows that like the $n$-nacci constants approach two, the spacing constants approach one.\n\n\nRepeating Expansions\n--------------------\n\nLet's not get too eager here and instead return to base $\\upsilon$.\nIt should be possible to expand the strings \"11\" and \"101\", since it is the fundamental spacing of width 2.\nHowever, we immediately run into an issue:\n\n$$\n\\begin{array}{c|c}\n \\text{Width} & \\textcolor{green}{0} & \\textcolor{blue}{1} & \\textcolor{red}{2} \\\\ \\hline\n & 01\\textcolor{red}{1}00000_\\upsilon\n & 010\\textcolor{red}{1}0000_\\upsilon\n & 0\\textcolor{red}{1001}_\\upsilon\n \\\\\n & 010\\textcolor{red}{1001}0_\\upsilon\n & 0100\\textcolor{red}{1001}_\\upsilon\n & \\textcolor{red}{1}0000_\\upsilon\n \\\\\n & 0\\textcolor{blue}{101}0010_\\upsilon\n & 0\\textcolor{orange}{1001}001_\\upsilon\n \\\\\n & \\textcolor{blue}{1}000001\\textcolor{blue}{1}_\\upsilon\n & \\textcolor{orange}{1}0000001_\\upsilon\n \\\\\n & 100000\\textcolor{green}{11}_\\upsilon \\\\\n & \\vdots \\\\ \\hline\n & s_0 = \\ ? & s_1 = \\rho s_6 & s_2 = \\rho\n\\end{array}\n$$\n\nThe width-0 expansion is recursive.\nIf we continue to apply its rule, we generate the string \"100001\" repeating.\nFortunately, each repeating unit is a width-four spacing, which is allowed by the carry.\n\nRepeating expansions imply a representation by geometric series:\n\n$$\n\\begin{gather*}\n 1.\\underbrace{\\underline{0\\dots1}}_{n}{}_x = 1 + x^{-n} + x^{-2n} + x^{-3n} + \\dots\n = \\frac{1}{1 - (1/x)^n} = \\frac{x^n}{x^n - 1}\n \\\\\n 10 = 1.\\underbrace{\\underline{0\\dots1}}_{n}{}_x ~\\iff~ x = \\frac{x^n}{x^n - 1} \\\\\n 1 = \\frac{x^{n-1}}{x^n - 1} \\\\ \\\\\n x^{n-1} = x^n - 1\n\\end{gather*}\n$$\n\nThe final expression is just the definition of a carry, so we can immediately write:\n\n$$\n\\begin{align*}\n 10_\\varphi &= 1.\\underline{01}_\\varphi & &\n \\text{Carry } \\langle 1,1| \\\\\n 10_\\psi &= 1.\\underline{001}_\\psi & &\n \\text{Carry } \\langle 1,0,1| \\\\\n 10_\\upsilon &= 1.\\underline{0001}_\\upsilon & &\n \\text{Carry } \\langle 1,0,0,1| \\\\\n 10_{\\rho} &= 1.\\underline{00001}_\\rho & &\n \\text{Carry } \\langle 1,0,0,0,1| = \\langle 0,1,1|\n\\end{align*}\n$$\n\nThis neatly ties repeating spacings in with carries.\n^[Recall that when we naively computed ten in base phi, we got \"10100.0100101010101010101\".\nAfter a certain point, this expansion alternates between 0 and 1. Assuming that this is true repetition\nand applying $10_\\varphi = 1.\\underline{01}_\\varphi$, one obtains \"10100.0101\", which is canonical. ]\n\nBut we didn't want \"10\" as a repeating expansion, we wanted \"11\".\nAttempting to justify with the same strategy:\n\n$$\n\\begin{align*}\n 0.11_\\upsilon &= 1.\\underline{00001}_\\upsilon & \\text{Carry } \\langle 1,0,0,1|\n \\\\\n \\frac{1}{x} + \\frac{1}{x^2} &= \\frac{x^n}{x^n - 1} \\\\\n x + 1 &= \\frac{x^{n+2}}{x^n - 1}\n \\\\[8pt]\n x^{n+1} + x^n - x - 1 &= x^{n+2} \\\\\n x^{n+2} - x^{n+1} - x^n + x + 1 &= 0 \\\\\n x^n(x^2 - x - 1) + x + 1 &= 0\n\\end{align*}\n$$\n\n::: {#83a45569 .cell execution_count=4}\n``` {.python .cell-code}\nrepeating_pair = lambda n: (x**n * (x**2 - x - 1) + x + 1).expand().factor()\n\nMarkdown(tabulate(\n zip(*(\n [[\"*n*\", \"Irreducible?\"]]\n + [[ str(i), display(is_irreducible(repeating_pair(i))) ] for i in range(1, 10)]\n ))\n))\n```\n\n::: {.cell-output .cell-output-display .cell-output-markdown execution_count=4}\n------------ ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ---------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- -------------------------------------\n*n* 1 2 3 4 5 6 7 8 9\nIrreducible? YesYesYesYesNoYesYesYesYes\n------------ ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- ---------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- -------------------------------------\n:::\n:::\n\n\nFor $n$ = 5, the polynomial factors as the product of $\\langle 1, 0, 0, 1|$ and $\\langle 0, 1, 1|$.\nThe second factor should come as no surprise since we know directly that $0.11_\\rho = 10_\\rho$\n and we already evaluated $10_{\\rho} = 1.\\underline{00001}_\\rho$\n\nChecking more $n$, this polynomial actually seems to be the only reducible one for quite a while.\n\n::: {#3a22f178 .cell freeze='true' execution_count=5}\n``` {.python .cell-code}\nall(is_irreducible(repeating_pair(i)) for i in range(10, 100))\n```\n\n::: {.cell-output .cell-output-display execution_count=5}\n```\nTrue\n```\n:::\n:::\n\n\nThis bestows some level of intrigue upon the repeating expansion of \"11\".\nSince repeating expansions are required for base $\\upsilon$ I will elect to not show the expansion of the integers.\n\n\n### Weird Modulus Patterns\n\nThis can be generalized slightly to match any spacing with any repeating spacing:\n\n$$\n\\begin{gather*}\n 0.\\underbrace{10\\dots01}_m = 1.\\underbrace{\\underline{0\\dots01}}_n\n ~\\Leftrightarrow~\n \\frac{1}{x} + \\frac{1}{x^m} = \\frac{x^n}{x^n - 1}\n \\\\\n x^{m-1} + 1 = \\frac{x^{n+m}}{x^n - 1} \\\\\n \\\\\n x^{n+m-1} + x^n - x^{m-1} - 1 = x^{n+m}\\\\\n x^{n+m} - x^{n+m-1} - x^n + x^{m-1} + 1 = 0 \\\\\n (x^n)(x^m - x^{m-1} - 1) + x^{m-1} + 1 = 0 \\\\\n\\end{gather*}\n$$\n\nIf the polynomial has factors, then fractional systems where those factors are carries have\n repeating expansions of width $n$ for a spacing of width $m$.\nGraphing the tuples of reducible polynomials produces a strange pattern\n apparently arranged in lines (going from the lower left to the upper right):\n\n::: {#b7068ef6 .cell execution_count=6}\n``` {.python .cell-code}\ngeneral_repeats = lambda m, n: (x**n)*(x**m - x**(m-1) - 1) + x**(m-1) + 1\n\nplt.xticks(range(20))\nplt.yticks(range(20))\nplt.xlabel(\"$m - 1$\")\nplt.ylabel(\"$n - 1$\")\nplt.imshow([\n [ is_irreducible(general_repeats(m + 1, n + 1)) for m in range(20) ]\n for n in range(20)\n])\n```\n\n::: {.cell-output .cell-output-display}\n{width=433 height=429}\n:::\n:::\n\n\nThe leftmost purple square is the exception, which corresponds to the earlier $(m, n) = (2, 5)$.\nEvery purple square here is a reducible polynomial, the first few of whose factors are:\n\n\n| $(m, n)$ | Sum | Polynomial Factors\n|----------|-----|-------------------\n| (2, 5) | 7 | $(x^3 - x - 1) (x^4 - x^3 - 1)$\n| (3, 11) | 14 | $(x^4 - x^3 + x^2 - x + 1)$ $(x^{10} - x^8 - x^7 - x^6 - x^5 + x^3 + x^2 + x + 1)$\n| (7, 7) | | $(x^4 - x^3 + x^2 - x + 1)$ $(x^{10} - x^8 - x^5 + x + 1)$\n| (13, 1) | | $(x^4 - x^3 + x^2 - x + 1)$ $(x^{10} + x^7 - x^5 - x^2 + 1)$\n| (7, 17) | 24 | $(x^4 - x^3 + x^2 - x + 1)$ $(x^{20} - x^{18} - x^{15} - x^{12} + x^{10} + x^7 - x^5 + x + 1)$\n| (13, 11) | | $(x^4 - x^3 + x^2 - x + 1)$ $(x^{20} - x^{18} - x^{15} + x^{13} + x^{10} + \\dots + x + 1)$\n| (17, 7) | | $(x^4 - x^3 + x^2 - x + 1)$ $(x^{20} - x^{18} - x^{15} + x^{13} + x^{12} + \\dots + x + 1)$\n| (17, 17) | | $(x^4 - x^3 + x^2 - x + 1)$ $(x^{30} - x^{28} - x^{25} + x^{23} + x^{20} - x^{18} - \\dots + x + 1)$\n\nOnly the first entry has factor that is a carry associated to a spacing.\nEvery other entry appears to have $(x^4 - x^3 + x^2 - x + 1)$ as a common factor,\n which is the 10th cyclotomic polynomial.\n\nThese solutions also have sums which increment in tens, which correspond to the\n vertical and horizontal lines of purple squares in the image.\nBoth $m$ and $n$ solutions work in a similar way: the symmetric solution (7, 7)\n has similar solutions (7, 17), (17, 7), and (17, 17).\nThis pattern also holds up in the \"next\" terms (7, 27), (17, 27), (27, 27), (27, 17), and (27, 7).\nIt appears as though there is a congruence of $m + n\\ (\\text{mod } mn)$,\n where m and n come from the exception (2, 5).\nThis pattern is similar to the one in which one in every six spacings can be factored.\n\n\nClosing\n-------\n\nIn summary, the Fibonacci recurrence can be generalized in at least two two different ways.\nIntroducing \"0\"s into the carry is more touch-and-go than would otherwise seem,\n though they produce (with much effort) valid bases.\n\nThe [next post](../4) will explore a more distant cousin of the Fibonacci numbers,\n and other strange power series which arise from its discussion.\n\n",
+ "supporting": [
+ "index_files"
+ ],
+ "filters": [],
+ "includes": {}
+ }
+}
\ No newline at end of file
diff --git a/_freeze/polycount/3/index/figure-html/cell-7-output-1.png b/_freeze/polycount/3/index/figure-html/cell-7-output-1.png
new file mode 100644
index 0000000..d714e0f
Binary files /dev/null and b/_freeze/polycount/3/index/figure-html/cell-7-output-1.png differ
diff --git a/_freeze/polycount/4/index/execute-results/html.json b/_freeze/polycount/4/index/execute-results/html.json
new file mode 100644
index 0000000..6487f24
--- /dev/null
+++ b/_freeze/polycount/4/index/execute-results/html.json
@@ -0,0 +1,12 @@
+{
+ "hash": "e6b66233e4bd8354553fa53b3612202a",
+ "result": {
+ "engine": "jupyter",
+ "markdown": "---\ntitle: \"Polynomial Counting 4: Two 2's\"\nformat:\n html:\n html-math-method: katex\ndate: \"2021-02-09\"\ndate-modified: \"2025-02-12\"\njupyter: python3\ncategories:\n - algebra\n - python\n---\n\n\n\n\nThis post assumes you have read [the first](../1), which introduces generalized polynomial counting,\n and [the second](../2), which restricts the focus and specifies the general aim.\n\n\nExtra Metals\n------------\n\nAs previously shown, the golden ratio (recurrence $\\langle 1, 1|$) can be generalized in several ways.\nThe silver ratio was introduced as the next \"metallic mean\",\n a sequence of quadratic roots of the form $\\langle n, 1|$,\n and the limiting ratios of the corresponding recurrences.\n\nThe metallic ratios have simple [*continued fraction*](https://en.wikipedia.org/wiki/Continued_fraction) expansions:\n\n$$\n\\begin{gather*}\n \\langle n, 1| ~~\\iff~~ x^2 - nx - 1 \\\\\n x^2 = nx + 1 ~~\\implies~~\n x = n + \\frac{1}{x} \\\\\n x = n + \\cfrac{1}\n {n + \\cfrac{1}\n {n + \\cfrac{1}\n {n + \\cfrac{1}{\\ddots}}\n }\n }\n = [n; \\underline{n}]\n\\end{gather*}\n$$\n\nAgain, the underline denotes repetition, since the overbar has been used for negation.\n\nParametrizing the carry in both terms (recurrence $\\langle n, n|$) demonstrates a strange duality\n with the above continued fraction:\n\n$$\n\\begin{gather*}\n \\langle n, n| ~~\\iff~~ x^2 - nx - n \\\\\n x^2 = nx + n ~~\\implies~~\n x = n + \\frac{n}{x} \\\\\n x = n + \\cfrac{n}{n + \\cfrac{n}{n + \\cfrac{n}{n + \\cfrac{n}{\\ddots}}}} =\n n + \\cfrac{\\textcolor{red}{\\cancel{n}}}\n {\\textcolor{red}{\\cancel{n}} + \\cfrac{\\textcolor{red}{\\cancel{n}}}\n {n + \\cfrac{\\textcolor{blue}{\\cancel{n}}}\n {\\textcolor{blue}{\\cancel{n}} + \\cfrac{\\textcolor{blue}{\\cancel{n}}}{\\ddots}}\n }\n } \\\\\n x = n + \\cfrac{1}\n {1 + \\cfrac{1}\n {n + \\cfrac{1}\n {1 + \\cfrac{1}{\\ddots}}\n }\n }\n = [n; \\underline{1, n}]\n\\end{gather*}\n$$\n\nIn other words, the root of $\\langle n, 1|$ has continued fraction n repeating,\n and the root of $\\langle n, n|$ has continued fraction $n, 1$ repeating.\n\n\n### Gray Silver\n\nThe golden ratio belongs to both series.\nAfter it, the next term in in the non-metallic series is the recurrence $\\langle 2, 2 |$.\nIt produces the series $0, 1, 2, 6, 16\\dots$ ([OEIS A002605](http://oeis.org/A002605)),\n and the limiting ratio of its successive terms is $1 + \\sqrt 3 \\approx 2.7321\\dots$.\nThis value and the polynomial coefficients are bounded above by 3, so it stands to reason that\n a ternary alphabet is suitable.\nThe trick for expanding 3 works as before:\n\n$$\n\\textcolor{red}{3}00 = 2\\textcolor{red}{22}\n= \\textcolor{blue}{22}2 = \\textcolor{blue}{1}002\n$$\n\n:::: {.row .text-center}\n::: {#canonical-cendree-table .column width=\"60%\"}\n\n| *n* (Decimal) | *n* (Unnamed Ratio) | *n* (Unnamed Sequence) |\n|:------------------:|:------------------------:|:---------------------------:|\n| 0 | 0 | 0 |\n| 1 | 1 | 1 |\n| 2 | 2 | 10 |\n| 3 | 10.02 | 11 |\n| 4 | 11.02 | 20 |\n| 5 | 12.02 | 21 |\n| 6 | 20.1102 | 100 |\n| 7 | 21.1102 | 101 |\n| 8 | 100.1102 | 110 |\n| 9 | 101.1102 | 111 |\n| 10 | 102.1102 | 120 |\n\n:::\n::::\n\nAs an homage to heraldry terminology, I choose to call this system cendrée,\n and the root of the polynomial the ashen ratio (abbreviated *κ*).\nGold and silver (\"or\" and \"argent\") are \"metals\"; cendrée is a non-standard color\n referring to an ashen gray, which reflects its relationship to the metallic means.\n\n\nAsh on the Fulcrum\n------------------\n\nJust like the silver ratio base, we can try expressing these using a balanced alphabet\n {-1, 0, 1} instead of the standard one {0, 1, 2}.\nThere, we had the choice of forbidding either the string \"11\" or \"10\", because when the carry\n was applied to either, the negative of the other would appear.\nJust like then, we must choose whether to forbid \"11\" or \"TT\" (its negative), since carrying\n at one produces the other.\n\n$$\n0\\textcolor{red}{11} = \\textcolor{red}{1}\\bar{1}\\bar{1}\n$$\n\nI choose to permit \"11\" since both terms of the carry are positive.\n\n\n### Intractible Repetition\n\nOur first target for conversion into a balanced form is \"2\".\n\n$$\n\\textcolor{red}{2.0}_{\\kappa}\n = \\textcolor{red}{1}0.\\textcolor{blue}{\\bar{2}0}_{\\kappa}\n = 1\\textcolor{blue}{\\bar{1}}.0\\textcolor{orange}{20}_{\\kappa}\n = 1\\bar{1}.\\textcolor{orange}{1}0\\bar{2} _{\\kappa}\n = \\dots\n = 1\\bar{1}.\\underline{1\\bar{1}}_{\\kappa}\n$$\n\nBy iteratively applying the carry, we get a repeating balanced expansion.\nInstead of this, we could derive an expansion by decrementing the expansion of three\n\n$$\n2 = 3 - 1 = 10.02_{\\kappa} + \\bar{1}\n= 1\\bar{1}.0\\textcolor{green}{2}_{\\kappa}\n= 1\\bar{1}.1\\bar{1}0\\textcolor{green}{2}_{\\kappa}\n= \\dots\n= 1\\bar{1}.\\underline{1\\bar{1}}_{\\kappa}\n$$\n\nfor which we get the same expansion after recursing on the symbol \"2\".\n\nBoth of the above derivations involve an infinite number of steps, so there might still be some nagging suspicion\n that the methods used are invalid.\nTo put it on firm(er) ground, we can derive the carry polynomial directly from this series (and vice versa)\n using a geometric series argument:\n\n::: {#geometric-series-2}\n$$\n\\begin{gather*}\n 1.\\underline{\\vphantom{\\bar{1}}1}_x\n = 1 + x^{-1} + x^{-2} + x^{-3} + \\dots\n = \\frac{1}{1 - (1/x)}\n = \\frac{x}{x - 1}\n \\\\\n 1.\\underline{\\bar{1}1}_x\n = 1 -\\ x^{-1} + x^{-2} -\\ x^{-3} + \\dots\n = \\frac{1}{1 + (1/x)}\n = \\frac{x}{x + 1}\n \\\\\n 2 = 1\\bar{1}.\\underline{1\\bar{1}}_x\n = \\frac{x^2}{x + 1}\n \\\\\n x^2 = 2x + 2 \\iff \\langle 2, 2 |\n\\end{gather*}\n$$\n:::\n\nWe assume both series converge, since $\\kappa > 1$.\n\nRecall that in decimal, repeating expansions usually signify rational numbers, like $0.\\underline{3}_{10} = 1/3$.\nSimilarly, we can interpret \"$1\\bar{1}.\\underline{1\\bar{1}}$\" as a base three expansion by evaluating\n $x^2 / ( x + 1 )$ at three, getting $1\\bar{1}.\\underline{1\\bar{1}}_3 = 9/4 = 2.25_{10}$.\nNormally, the rule is that when the denominator of a rational number and base are coprime\n (in the first example, three and ten; in the second, four and three), its expansion repeats.\nBut two in the irrational base *κ* breaks that rule in a balanced alphabet.\n\n\n### Mixing Ashes\n\nNaively, we can convert each entry of the earlier table to a balanced form by replacing \"2\"s with\n (shifts of) the repeating expansion.\nBut notice that each listed fractional expansion above three appears to end in \"2\".\nIn contrast, the [silver ratio expansions](../2#canonical-silver-table) ended in both \"1\" and \"2\".\n\nWhile this isn't a problem with the fractional base on its own, it complicates things\n when considering the balanced alphabet.\nIn fact, it seems to be the case that *all* base *κ* expansions of integers above three terminate in \"2\",\n but I won't bother proving it (see note for a sketch[^1]).\n\nInstead of converting directly, we can also just try counting from zero again, remembering the aforementioned\n trick for converting \"2\", but we may get problems when \"2\" appears multiple times in the expansion.\nAlternatively, by applying a finite version of the rule, we can move \"2\" further and further to the right.\n\n\n:::: {.row .text-center}\n::: {#canonical-balanced-cendree-table .column width=\"100%\"}\n\n\n\n| *n* (Decimal) | *n* (Mixed Cendrée) | *n* (Balanced Cendrée) | Remark |\n|-------------------:|:------------------------:|:---------------------------:|:------------------------------------------|\n| 0 | 0 | 0 | |\n| 1 | 1 | 1 | |\n| *2* | *2* | *1T. 1T...* | |\n| 2 | 1T.02 | 1T. 1T... | Example of pushing \"2\" to the right |\n| 3 | 10.02 | 10. 1T... | |\n| 4 | 11.02 | 11. 1T... | |\n| *5* | *12.02* | *11. 1T...* | |\n| 5 | 1T0.02 | 1T0. 1T... | Carry \"012\" to \"1T0\" |\n| 6 | 1T1.02 | 1T1. 1T... | |\n| *7* | *1T2.02* | *1T2. 1T...* | |\n| 7 | 10T.1102 | 10T.11 1T... | Push \"02000\" to \"1T1T02\" |\n| 8 | 100.1102 | 100.11 1T... | |\n| 9 | 101.1102 | 101.11 1T... | |\n| *10* | *102.1102* | *102.11 1T...* | |\n| 10 | 110.T102 | 110.T1 1T... | Carry \"2.1\" to \"10.T\" |\n| 11 | 111.T102 | 111.T1 1T... | |\n| *12* | *112.T102* | *112.T1 1T...* | |\n| *12* | *2T0.T102* | | Carry \"012\" to \"1T0\" |\n| 12 | 1T0T.001102 | 1T0T.0011 1T... | Push \"0200000000\" to \"1T1T1T1T02\" |\n\n: {tbl-colwidths=\"[15,20,25,40]\"}\n\n:::\n::::\n\nBetween some rows of the table, we have to apply the carry slightly more greedily --\n on the strings \"21\" and \"12\" as well as \"22\".\nIn fact, looking slightly ahead to fifteen, we have to use another trick:\n\n$$\n\\begin{align*}\n15_{10} = 1\\bar{1}0\\textcolor{red}{2}.001102_{\\kappa}\n &= 1\\bar{1}\\textcolor{red}{1\\bar{1}.02}1102_{\\kappa} \\\\\n &= 1\\bar{1}1\\bar{1}.0\\textcolor{blue}{21}102_{\\kappa}\n = 1\\bar{1}1\\bar{1}.\\textcolor{blue}{10\\bar{1}}102_{\\kappa}\n\\end{align*}\n$$\n\nIn other words, \"2\" should only be pushed to the right as far as an occurrence of \"11\", since at that point we can carry.\n\nIt remains to be proven that all but the rightmost \"2\" can be eliminated from a balanced expansion,\n but good \"pushes\" appear to suffice.\n\n\n-ary to -adic\n-------------\n\nWe can convert a repeating expansions back into the ratio of two integers by using a fairly simple procedure.\nHere, we apply that procuedure is applied to both $0.\\underline{69}_{10}$\n and the string in question, \"$0.\\underline{1\\bar{1}}_{p}$\", for generic $p$:\n\n$$\n\\begin{gather*}\n {\n 0.\\underbrace{\n \\underline{\\textcolor{blue}{69}}_{10}\n }_{\\text{length } \\textcolor{red}{2}}\n }\n = \\frac{\\textcolor{blue}{69}_{10}}{10^{\\textcolor{red}{2}} - 1}\n = \\frac{\\textcolor{blue}{69}_{10}}{99_{10}}\n = \\frac{23_{10}}{33_{10}}\n \\\\\n 0.\\underline{\\textcolor{blue}{1\\bar{1}}}_p\n = \\frac{\\textcolor{blue}{1\\bar{1}}_p}{p^2 - 1}\n = \\frac{p - 1}{p^2 - 1}\n = \\frac{1}{p + 1}\n\\end{gather*}\n$$\n\nThese fractions can be used to construct [p-*adic numbers*](https://en.wikipedia.org/wiki/P-adic_number).\nDoing so requires us to realize that $p + 1$ always divides $p^{2n} - 1$.\nDoing the long division directly for some small $n$, we get:\n\n$$\n\\begin{align*}\n &\\frac{p^2 - 1}{p+1} = \\frac{10\\bar{1}_p}{11_p}\n & \\substack{\n \\phantom{11}{\\underline{\\phantom{)1}1\\bar{1}}} \\\\[3pt]\n 11)10\\bar{1} \\\\\n \\phantom{11)}\\underline{11} \\phantom{0} \\\\[3pt]\n \\phantom{11)1}{\\bar{1}\\bar{1}} \\\\\n \\phantom{11)1}{\\underline{\\bar{1}\\bar{1}}} \\\\[3pt]\n \\phantom{11)1}00\n } \\\\\n \\\\\n &\\frac{p^4 - 1}{p+1} = \\frac{1000\\bar{1}_p}{11_p}\n & \\substack{\n \\phantom{11}{\\underline{\\phantom{)1}1\\bar{1}1\\bar{1}}} \\\\[3pt]\n 11)1000\\bar{1} \\\\\n \\phantom{11)} \\underline{11} \\phantom{000} \\\\[3pt]\n \\phantom{11)1} \\bar{1}0 \\phantom{00}\\\\\n \\phantom{11)1} \\underline{\\bar{1}\\bar{1}} \\phantom{00} \\\\[3pt]\n \\phantom{11)10}10 \\phantom{0} \\\\\n \\phantom{11)10} \\underline{11} \\phantom{0} \\\\[3pt]\n \\phantom{11)100} \\bar{1}\\bar{1} \\\\\n \\phantom{11)100} \\underline{\\bar{1}\\bar{1}} \\\\[3pt]\n \\phantom{11)100} 00 \\\\\n }\n\\end{align*}\n$$\n\nIf we assert $p^\\infty$ approaches zero (regardless of whether $p$ is greater than or less than 1),\n then in the limit we have the quotient $\\bar{1}_p / 11_p = \\dots 1\\bar{1}1\\bar{1}1\\bar{1}_p$.\n\n\n### Flip it Radix-ways\n\nThe series we're actually interested in is $1_p / 11_p$, which is the negative of the above series.\nSince we're using a balanced alphabet, we can negate this by simply replacing $\\bar{1}$ with $1$\n (and vice versa), producing...\n\n$$\n0.\\underline{1\\bar{1}}_p\n = \\frac{1_p}{11_p}\n = \\underline{\\bar{1}1}\\bar{1}1_p\n$$\n\n...which is the initial expansion, but flipped about the radix point.\nWe might also remember what [we did earlier with geometric series](#geometric-series-2) and just do\n\n$$\n\\begin{align*}\n \\underline{1}1_p\n &= 1 + p + p^2 + p^3 + ...\n = \\frac{1}{1 - p} \\\\\n \\underline{\\bar{1}1}\\bar{1}1_p\n &= 1 - p + p^2 - p^3 + ...\n = \\frac{1}{1 + p}\n\\end{align*}\n$$\n\nContrary to the usual case, in a *p*-adic sense, these series always converge,\n since $p^n$ is considered to always shrink as $n$ grows.\n\n\n### Back to *κ*\n\nReturning to base *κ*, we can create the *κ*-adic expansion for two through simple addition:\n\n$$\n\\begin{align*}\n &\\phantom{+} 1\\bar{1}.000000\\dots_\\kappa\n ~=~ \\dots00001\\bar{1}_\\kappa \\\\\n &+ \\underline{00.1\\bar{1}1\\bar{1}1\\bar{1}\\dots_\\kappa\n ~=~ \\dots\\bar{1}1\\bar{1}1\\bar{1}1}_\\kappa \\\\\n & \\phantom{+} 1\\bar{1}.1\\bar{1}1\\bar{1}1\\bar{1}\\dots_\\kappa\n ~=~ \\dots\\bar{1}1\\bar{1}100_\\kappa \\\\\n\\end{align*}\n$$\n\nWe can check this expansion by power series manipulations:\n\n$$\n\\begin{align*}\n 2 = \\dots\\bar{1}1\\bar{1}100_\\kappa\n &=\\kappa^2 - \\kappa^3 + \\kappa^4 - \\kappa^5 +\\dots \\\\\n &= \\kappa^2(1 - \\kappa + \\kappa^2 - \\kappa^3 +\\dots) \\\\\n &= \\kappa^2 \\cdot \\frac{1}{1 - (-\\kappa)} \\\\\n &= \\frac{\\kappa^2}{\\kappa + 1} \\\\[8pt]\n {2\\kappa + 2}\n &= \\kappa^2\n\\end{align*}\n$$\n\nThis gives us the defining relation of *κ*, so the expansion appears to be correct.\n\n\nTwo Plus Two Equals Chaos\n-------------------------\n\n*p*-adic expansions are still expressions in the base *p*, so the carry rule still applies.\nHowever, since the carry continues to infinity, we have a necessarily limited view,\n which we can at best combat by marking repeating sections.\n\nWhile the *κ*-adic expansion for two can be incremented once to produce a valid expansion one for three,\n problems arise when attempting to construct four.\nThe most direct method is to start with the symbol \"4\" and manipulate it:\n\n$$\n\\begin{align*}\n 4_{\\kappa}\n &= 2\\bar{4}0_{\\kappa}\n = \\bar{2}600_{\\kappa}\n = 3\\bar{8}000_{\\kappa}\n = \\bar{4}\\text{B}0000_{\\kappa} \\\\\n &= 5\\bar{\\text E}10000_{\\kappa}\n = \\bar{7}\\text{J}0\\textcolor{red}{1}0000_{\\kappa}\n = \\dots\n\\end{align*}\n$$\n\nLatin characters used as numerals start at A for ten, as in hexadecimal.\nAs we carry to the left, the most significant digits (which I call the \"carry head\") grow larger without bound.\nHowever, in doing so, a residual \"1\" (marked in red) is left behind in the fourth place value.\n\nIn typical *p*-adics, *p* is an integer, and the carry head is a single digit wide.\n*κ* is not an integer, and the carry head here is two digits wide.\nThis may seem a little dubious, but truncating immediately to the right of the carry head\n will produce the same effect regardless of its size.\n\n\n### Alternative Constructions\n\nTo keep the head small, it would be nice if it were taken mod an integer.\nBoth $\\bar{1}$ and $1$ are odd, so one might hope that in between carries, we could mod out by two.\nUnfortunately, this is not the case.\nAll of the expansions above are identically four, and manipulating the digits directly would just\n give a different number.\n\nInstead, we could try representing \"4\" in a more direct manner\nThere are a few other options available.\n\n- Add the nonrepeating part of the mixed balanced expansion of 4 with the\n $\\kappa$-adic version of the repeating part (Another direct manipulation)\n\n- Increment the least significant digit in the expansion of 2 twice (Addition)\n $$\n 4 = 2 + 2 = \\frac{\\kappa^2}{1 + \\kappa} + 2 = \\dots\\bar{1}1\\bar{1}102_{\\kappa}\n $$\n\n- Add the expansion of 2 to itself (Multiplication)\n $$\n 4 = 2 \\cdot 2 = 2 \\cdot \\frac{\\kappa^2}{1 + \\kappa} = \\dots\\bar{2}2\\bar{2}200_{\\kappa}\n $$\n\n- Square the power series expansion of 2 (Exponentiation)\n $$\n \\begin{gather*}\n 4 = 2^2 = \\left(\\frac{\\kappa^2}{1 + \\kappa}\\right)^2 =\n -\\kappa^4 \\left(\n \\frac{d}{dx} \\frac{1}{1 + x}\n \\right)_{x = \\kappa}\n = \\dots\\bar{4}3\\bar{2}10000_{\\kappa}\n \\end{gather*}\n $$\n\nIf all of these series are expansions of four, then they should produce the same string after\n applying the carry enough times.\nFortunately, this seems to be the case, as this table demonstrates:\n\n$$\n\\begin{array}{}\n {\\kappa^2 \\over 1 + \\kappa} + 2 &\\phantom{00}&\n {2\\kappa^2 \\over 1 + \\kappa} &\\phantom{00}&\n \\left({\\kappa^2 \\over 1 + \\kappa}\\right)^2 \\\\[10pt] \\hline\n \\vphantom{2^{2^{2^2}}}\\dots\\bar{1}1\\bar{1}1\\bar{1}102 \\\\[4pt]\n \\dots\\bar{1}1\\bar{1}1\\bar{1}2\\bar{2}0 \\\\[4pt]\n \\dots\\bar{1}1\\bar{1}1\\bar{2}400 &&\n \\dots\\bar{2}2\\bar{2}2\\bar{2}200 \\\\[4pt]\n \\dots\\bar{1}1\\bar{1}3\\bar{6}000 &&\n \\dots\\bar{2}2\\bar{2}3\\bar{4}000 \\\\[4pt]\n \\dots\\bar{1}1\\bar{4}90000 &&\n \\dots\\bar{2}2\\bar{4}70000 \\\\[4pt]\n \\dots\\bar{1}5\\bar{\\text C}10000 &&\n \\dots\\bar{1}5\\bar{\\text A}10000 &&\n \\dots\\bar{4}3\\bar{2}10000 \\\\[4pt]\n \\dots\\bar{7}{\\text H}010000 &&\n \\dots\\bar{6}\\text F010000 &&\n \\dots\\bar{5}5010000 \\\\[4pt]\n \\dots\\bar{\\text N}1010000 &&\n \\dots\\bar{\\text L}1010000 &&\n \\dots\\bar{9}1010000 \\\\[4pt]\n \\textcolor{green}{\\dots\\bar{1}1010000} &&\n \\textcolor{green}{\\dots\\bar{1}1010000} &&\n \\textcolor{green}{\\dots\\bar{1}1010000}\n\\end{array}\n$$\n\nThe rightmost series is the most resilient to the carry head growth, but it comes at\n the cost of not operating on a repeating series.\nIn the range shown, all three columns converge to the same digit sequence, which truncated to 20 terms is:\n\n$$\n4 = \\dots \\bar{1}00000\\bar{1}00001\\bar{1}1010000_\\kappa = \\kappa^4 + \\kappa^6 -\\ \\kappa^7 + \\dots\n$$\n\nContrary to the sequence used to build it, this expansion appears to be nonrepeating.\nAs of writing, there are\n [no matches](http://oeis.org/search?q=1%2C0%2C1%2C-1%2C1%2C0%2C0%2C0%2C0%2C-1%2C0%2C0%2C0%2C0%2C0%2C-1&sort=&language=&go=Search)\n in the OEIS, even if the leading 0's are ignored.\nThe Haskell used to generate each expansion above can be found [here](./cendree.hs),\n and the first 8192 digits be found in a CSV [here](./cendree_adic_4.csv).\n\n\n### All Positive\n\nIf we are slightly greedier with the carry, we can clear it of all negative digits.\nFor example,\n\n$$\n\\begin{align*}\n 4 &= \\dots \\bar{1}00000\\bar{1}00001\\bar{1}1010000_\\kappa \\\\\n &= \\dots \\bar{1}00000\\bar{1}000\\bar{1}311010000_\\kappa \\\\\n &= \\dots \\bar{1}00000\\bar{1}001\\bar{3}111010000_\\kappa \\\\\n &= \\dots \\bar{1}00000\\bar{1}0\\bar{2}51111010000_\\kappa \\\\\n &= \\dots \\bar{1}00000\\bar{1}2\\bar{6}11111010000_\\kappa \\\\\n &= \\dots \\bar{1}00000\\bar{4}8011111010000_\\kappa \\\\\n &= \\quad \\vdots \\\\\n &= \\dots 0 11000 0 0011111010000_\\kappa \\\\\n &= \\kappa^4 + \\kappa^6 + \\kappa^7 + \\kappa^8 + \\kappa^9 \\dots\n\\end{align*}\n$$\n\nAgain, it appears to be possible to achieve this sequence by applying the carry enough times,\n starting with any of the alternative expansions.\nA similar CSV containing 8192 terms is available [here](./cendree_adic_4_binary.csv).\n\nThis alternate expansion is somewhat confounding, since *κ* is bounded above by the\n integer three and should therefore require three symbols in its alphabet.\nI can think of two explanations, and do not know whether either of them are correct:\n\n- The expansion is related to the conjugate root $\\kappa^* = 1 -\\ \\sqrt 3 \\approx -0.73205\\dots$.\n The reciprocal of this number is less than two.\n- Because infinite precision is required, the minimal alphabet can become (possibly arbitrarily) small.\n\n\nSearching for Repetition\n------------------------\n\nThe [discrete Fourier transform](https://en.wikipedia.org/wiki/Discrete_Fourier_transform)\n is an operation on a discrete signal (i.e., a sequence of numbers).\nIt has the desirable property that it converts highly repetitive signals sequences into ones with peaks.\nWe can use this to assess whether an expansion repeats or not.\n\nSince our expansions are infinite, we'll need to truncate them.\nUnfortunately, this renders us unable to pick up on repetitions larger than a certain size.\nIn other words, to detect very large periods, we need to truncate our sequence to a large number of terms.\n\nFor example, the digits in the decimal expansion of 1/7 form the string \"142857\", repeating.\nTruncating this sequence to 256 terms, we can plot its DFT:\n\n::: {#a6158b7e .cell execution_count=2}\n``` {.python .cell-code code-fold=\"true\"}\nfrom itertools import cycle, islice\nfrom matplotlib import pyplot as plt\nimport numpy as np\n\none_seventh = list(islice(cycle([1,4,2,8,5,7]), 256))\n\nplt.title(\"DFT of first 256 digits of decimal expansion of 1/7\")\nplt.plot(abs(np.fft.fft(one_seventh))[:129])\n```\n\n::: {.cell-output .cell-output-display}\n{width=583 height=431}\n:::\n:::\n\n\nThe clear peak near forty is because the expansion repeats every 6 terms and\n $\\frac{256}{43} < 6 < \\frac{256}{42}$.\n\n\n### Four-ier Transforms\n\nIf the $\\kappa$-adic expansion of four is nonrepeating, then its DFT should not have any noticeable peaks.\n\n::: {#079df1ce .cell execution_count=3}\n``` {.python .cell-code code-fold=\"true\"}\nimport csv\n\nwith open(\"cendree_adic_4.csv\") as f:\n cendree_adic_4 = [int(i) for i in list(csv.reader(f))[0]]\n\nplt.title(\"DFT of first 256 digits of $\\\\kappa$-adic expansion of 4\")\nplt.plot(abs(np.fft.fft(cendree_adic_4[:256]))[:129])\n```\n\n::: {.cell-output .cell-output-display}\n{width=575 height=432}\n:::\n:::\n\n\nThe DFT of the first 256 terms shows it to be very noisy.\nThere is a pronounced spike at the right edge of the graph (the Nyquist frequency),\n but it has a simple explanation: $1$ appears only at even place values and $\\bar{1}$ at odd.\nAt Nyquist, the DFT degenerates into an alternating sum, so its value is simply the number of nonzero digits.\n\nIf we map the negatives out of the sequence, the peak moves to the left edge (where the DFT degenerates into a sum).\n\n::: {#219cff53 .cell execution_count=4}\n``` {.python .cell-code code-fold=\"true\"}\nplt.title(\"DFT of $4_{\\\\kappa}$ after mapping $\\\\bar{1}$ to $1$\")\nplt.plot(abs(np.fft.fft([abs(i) for i in cendree_adic_4[:256]]))[:129])\n```\n\n::: {.cell-output .cell-output-display}\n{width=575 height=435}\n:::\n:::\n\n\nIf you look closely, you'll notice that this plot is a mirror of the other.\n\n\n### Longer Truncations\n\nEven in the 8192-term truncation, there are no noticeable spikes in its DFT,\n lending further credence to its aperiodicity.\nIf it feels like we're doing something wrong, we might also try the \"all-positive\" variant of the expansion.\nUnfortunately, we're not so lucky.\nEven then, we just end up with pure noise.\n\n:::: {#long-trunc-figures .row layout-ncol=\"2\"}\n::: {.column width=\"40%\"}\n\n::: {#e5d46955 .cell execution_count=5}\n``` {.python .cell-code code-fold=\"true\"}\nplt.title(\"DFT of first 8192 digits of $4_{\\\\kappa}$\")\nplt.plot(abs(np.fft.fft(cendree_adic_4))[:len(cendree_adic_4) // 2])\n\n#\n```\n\n::: {.cell-output .cell-output-display}\n{width=575 height=432}\n:::\n:::\n\n\n:::\n\n::: {.column width=\"40%\"}\n\n::: {#0370766d .cell execution_count=6}\n``` {.python .cell-code code-fold=\"true\"}\n# Alternatively, with the non-balanced expansion\nwith open(\"cendree_adic_4_binary.csv\") as f:\n cendree_adic_4_binary = [int(i) for i in list(csv.reader(f))[0]]\n\nplt.title(\"DFT of first 8192 digits of $4_\\\\kappa$ (binary)\")\nplt.plot(abs(np.fft.fft(cendree_adic_4_binary))[1:len(cendree_adic_4_binary) // 2])\n```\n\n::: {.cell-output .cell-output-display}\n{width=575 height=432}\n:::\n:::\n\n\n:::\n::::\n\nMuch like the expansion of irrational numbers in integral bases, the balanced\n *κ*-adic expansion of four seems to be nonrepeating.\nThis is surprising, considering four is an integer, and especially since its expansion terminates\n in a normal alphabet and repeats in a balaced alphabet.\n\n\nClosing\n-------\n\nThis concludes the discussion of base *κ* and the *κ*-adics.\nRemember, we only bothered investigating *κ*-adic expansions for the number four.\nGreater integers suffer the same issues, and other bases are certainly possible.\nHopefully, four provides an illuminating enough example of the general chaos induced by irrational bases.\n\nThe [next post](../5) will return to integral sequences, and the patterns produced from their\n \"erroneousness\" as an actual base.\n\n[^1]:\n \n \n Proof sketch that base *κ* expansions of integers above three end in \"2\"\n \n\n Recall that $3 = 10.02_{\\kappa}$ and $4 = 11.02_{\\kappa}$.\n\n We can add two expansion together to produce a new valid expansion.\n Hence,\n\n :::: {.row layout-ncol=\"2\"}\n ::: {.column width=\"40%\"}\n $$\n \\begin{align*}\n 8 &= 4 + 4\n = 11.02_{\\kappa} + 11.02_{\\kappa} \\\\\n &= \\textcolor{red}{22}.04_{\\kappa}\n = \\textcolor{red}{1}00.0\\textcolor{blue}{4}_{\\kappa}\n = 100.\\textcolor{blue}{1102}_{\\kappa}\n \\end{align*}\n $$\n :::\n\n ::: {.column width=\"40%\"}\n $$\n \\begin{align*}\n 11_{10} &= 8 + 3\n = 100.1102_{\\kappa} + 10.02_{\\kappa} \\\\\n &= 110.1\\textcolor{red}{3}02_{\\kappa}\n = 110.\\textcolor{red}{2004}_{\\kappa} \\\\\n &= 110.200\\textcolor{blue}{4}_{\\kappa}\n = 110.20\\textcolor{blue}{1102}_{\\kappa}\n \\end{align*}\n $$\n :::\n ::::\n\n From these examples, we see that adding small numbers like three will, at most,\n produce a \"3\" or \"4\" in the negative second place value.\n\n If there is a \"2\" in the negative first place value, then expanding \"3\" or \"4\" in the negative\n second will give a \"3\" there, which is troublesome.\n But we got in this position by adding three; by adding two first, we can apply the carry\n across the zeroth and negative first place values instead, which produces\n at most a \"3\" in the first place value.\n Expanding \"3\" at this place value places a \"2\" back in the negative first place value,\n and we don't have to worry about modifying digits in other negative place values.\n\n If there is *not* a \"2\" in the negative first place value, then expanding the \"3\" or \"4\"\n in the negative second place value pushes a \"2\" into the negative fourth place value.\n From here \"2\" is either in the terminal position, or causes another expansion of \"3\" or \"4\".\n In the latter cases, we recurse, eventually pushing a \"2\" into a negative even place value in terminal position.\n \n\n",
+ "supporting": [
+ "index_files"
+ ],
+ "filters": [],
+ "includes": {}
+ }
+}
\ No newline at end of file
diff --git a/_freeze/polycount/4/index/figure-html/cell-2-output-1.png b/_freeze/polycount/4/index/figure-html/cell-2-output-1.png
new file mode 100644
index 0000000..7ee8ef3
Binary files /dev/null and b/_freeze/polycount/4/index/figure-html/cell-2-output-1.png differ
diff --git a/_freeze/polycount/4/index/figure-html/cell-3-output-1.png b/_freeze/polycount/4/index/figure-html/cell-3-output-1.png
new file mode 100644
index 0000000..496f871
Binary files /dev/null and b/_freeze/polycount/4/index/figure-html/cell-3-output-1.png differ
diff --git a/_freeze/polycount/4/index/figure-html/cell-4-output-1.png b/_freeze/polycount/4/index/figure-html/cell-4-output-1.png
new file mode 100644
index 0000000..90b15f9
Binary files /dev/null and b/_freeze/polycount/4/index/figure-html/cell-4-output-1.png differ
diff --git a/_freeze/polycount/4/index/figure-html/cell-5-output-1.png b/_freeze/polycount/4/index/figure-html/cell-5-output-1.png
new file mode 100644
index 0000000..1289cd7
Binary files /dev/null and b/_freeze/polycount/4/index/figure-html/cell-5-output-1.png differ
diff --git a/_freeze/polycount/4/index/figure-html/cell-6-output-1.png b/_freeze/polycount/4/index/figure-html/cell-6-output-1.png
new file mode 100644
index 0000000..fefc759
Binary files /dev/null and b/_freeze/polycount/4/index/figure-html/cell-6-output-1.png differ
diff --git a/_freeze/polycount/5/index/execute-results/html.json b/_freeze/polycount/5/index/execute-results/html.json
new file mode 100644
index 0000000..3c4077a
--- /dev/null
+++ b/_freeze/polycount/5/index/execute-results/html.json
@@ -0,0 +1,12 @@
+{
+ "hash": "75ea07652b53798dee08142061175e2e",
+ "result": {
+ "engine": "jupyter",
+ "markdown": "---\ntitle: \"Polynomial Counting 5: Pentamerous multiplication\"\nformat:\n html:\n html-math-method: katex\ndate: \"2021-02-12\"\ndate-modified: \"2025-2-12\"\njupyter: python3\ncategories:\n - algebra\n - haskell\n---\n\n\n\n\nThis post assumes you have read [the first](../1), which introduces generalized polynomial counting.\n\nOne layer up from counting is arithmetic.\nWe've done a little arithmetic using irrational expansions in pursuit of counting, but maybe we should investigate it a bit.\n\n\nArithmetical Algorithms\n-----------------------\n\nAddition is a fairly simple process for positional systems: align the place values, add each term together,\n then apply the carry as many times as possible.\nWithout a carry rule, this can be approached formally by treating the place values as a sequence\n $b_n$ and gathering terms:\n\n$$\n\\begin{gather*}\n \\phantom{+~} \\overset{b_2}{1} \\overset{b_1}{2} \\overset{b_0}{3} &\n \\phantom{+~} 1b_2 + 2b_1 + 3b_0 \\\\\n \\underline{\n +\\\n \\smash{\n \\overset{\\phantom{b_0}}4\n \\overset{\\phantom{b_0}}5\n \\overset{\\phantom{b_0}}6\n }\n \\vphantom,\n } &\n \\underline{\n +\\\n 4b_2 + 5b_1 + 6b_0 \\vphantom,\n } \\\\\n \\phantom{+~}\n \\smash{\n \\overset{\\phantom{b_0}}5\n \\overset{\\phantom{b_0}}7\n \\overset{\\phantom{b_0}}9\n } &\n \\phantom{+~} 5b_2 + 7b_1 + 9b_0\n\\end{gather*}\n$$\n\nMultiplication is somewhat trickier.\nIts validity follows from the interpretation of an expansion as a polynomial.\nPolynomial multiplication itself is equivalent to\n [*discrete convolution*](https://en.wikipedia.org/wiki/Convolution#Discrete_convolution).\n\n$$\n\\begin{align*}\n &\\begin{matrix}\n \\phantom{\\cdot~}\n 111_x \\\\\n \\underline{\\cdot\\ \\phantom{1}21_x\\vphantom,} \\\\\n \\phantom{\\cdot \\ 0}\n 111_{\\phantom{x}} \\\\\n \\underline{\\phantom{\\cdot\\ } 2220_{\\phantom{x}} \\vphantom,} \\\\\n \\phantom{\\cdot\\ }\n 2331_{\\phantom{x}}\n \\end{matrix}\n &\\qquad&\n \\begin{gather*}\n (x^2 + x + 1)(2x + 1) \\\\ \\\\\n = \\phantom{2x^3 + } \\phantom{2}x^2 + \\phantom{2}x + 1 \\\\\n + \\phantom{.} 2x^3 + 2x^2 + 2x \\phantom{+ 1}\\\\\n = 2x^3 + 3x^2 + 3x + 1\n \\end{gather*}\n &\\qquad&\n \\begin{gather*}\n [1,1,1] * [2,1] \\\\\n \\begin{matrix}\n \\textcolor{blue}0 &\\textcolor{red}1 & \\textcolor{red}1 & \\textcolor{red}1 & \\textcolor{blue}0 &\\\\\n & & &1 & 2 & =~1\\\\\n & & 1 & 2 & &=~3\\\\\n & 1 & 2 & & &=~3\\\\\n 1 & 2 & & & & =~2\n \\end{matrix}\n \\end{gather*}\n\\end{align*}\n$$\n\nThe left equation shows familiar multiplication, the middle equation is the same product when expressed as polynomials,\n and the right equation shows this product obtained by convolution.\nNote that \\[2, 1\\], the second argument, is reversed when performing the convolution.\n\nWithout carrying, multiplication and addition are base-agnostic.\nWhen doing arithmetic in a particular base, we should obtain the same result even if we perform the same operations in another base.\n\n$$\n\\begin{array}{c}\n 18_{10} \\cdot 5_{10} = 10010_2 \\cdot 101_2\n \\\\ \\hline \\\\\n \\begin{gather*}\n &\n \\begin{matrix}\n \\phantom{\\cdot~}\n 18_{10} \\\\\n \\underline{\\cdot\\\n \\phantom{1}5_{10}\\vphantom,} \\\\\n \\phantom{\\cdot~}90_{10} \\\\ \\\\\n =~1011010_2\n \\end{matrix}\n &&\n \\begin{matrix}\n [1,0,0,1,0] * [1,0,1] \\\\ \\\\\n \\begin{matrix}\n \\textcolor{blue}0 & \\textcolor{blue}0 &\\textcolor{red}1 & \\textcolor{red}0 & \\textcolor{red}0\n & \\textcolor{red}1 & \\textcolor{red}0 & \\textcolor{blue}0 & \\textcolor{blue}0 &\\\\\n & & & & & &1 & 0 & 1 & =~0\\\\\n & & & & &1 & 0 & 1 & & =~1\\\\\n & & & &1 & 0 & 1 & & & =~0\\\\\n & & &1 & 0 & 1 & & & & =~1\\\\\n & &1 & 0 & 1 & & & & & =~1\\\\\n & 1 & 0 & 1 & & & & & & =~0\\\\\n 1 & 0 & 1 & & & & & & & =~1\\\\\n \\end{matrix}\n \\end{matrix}\n \\end{gather*}\n\\end{array}\n$$\n\nThis shows that regardless of whether we multiply eighteen and five together in base ten or two,\n we'll get the same string of digits if afterward everything is rendered in the same base.\nFortunately in this instance, we don't have to worry about any carries in the result.\n\n\nTwo Times Tables\n----------------\n\nThe strings \"10010\" and \"101\" do not contain adjacent \"1\"s, so they can also be interpreted as\n Zeckendorf expansions (of ten and four, respectively).\nThis destroys their correspondence to polynomials, so their product by convolution,\n as a Zeckendorf expansion (when returned to canonical form) is not the product of ten and four.\n\n$$\n\\begin{gather*}\n [1,0,0,1,0] * [1,0,1] = 1011010 \\\\\n 10\\textcolor{red}{11}010_{\\text{Zeck}}\n = 1\\textcolor{red}{1}00010_{\\text{Zeck}}\n = \\textcolor{blue}{11}00010_{\\text{Zeck}}\n = \\textcolor{blue}{1}0000010_{\\text{Zeck}} = 36_{10} \\\\\n \\text{Zeck}(10_{10}) * \\text{Zeck}(4_{10})\n = 36_{10} \\neq 40_{10} = 10_{10} \\cdot 4_{10}\n\\end{gather*}\n$$\n\nWe can express this operation for general integers *x* and *y* as\n\n$$\nx \\odot_\\text{Zeck} y = Unzeck(Zeck(x) * Zeck(y))\n$$\n\nwhere \"Zeck\" expands an integer into its Zeckendorf expansion and \"Unzeck\" signifies the process of\n re-interpreting the string as an integer.\nWe can do this because for every integer, a canonical expansion exists.\nFurther, since this operation is defined via convolution (which is commutative), it is also commutative.\n\n::: {#562ef349 .cell execution_count=2}\n``` {.python .cell-code}\nfrom itertools import count, chain, islice, takewhile\nimport numpy as np\n\ndef fibs():\n i = 1\n j = 1\n while True:\n yield i\n t = i + j\n j = i\n i = t\n\ndef zeck(n: int) -> list[int]:\n fibs_ = list(takewhile(lambda x: x <= n, fibs()))[::-1]\n ret = []\n\n for i in fibs_:\n digit, n = divmod(n, i)\n ret.append(digit)\n\n return ret or [0]\n\ndef unzeck(ns: list[int]) -> int:\n return sum(map(lambda x, y: x * y, reversed(ns), fibs()))\n\ndef zeck_times(x: int, y: int) -> int:\n return unzeck(np.convolve(zeck(x), zeck(y), \"full\"))\n```\n:::\n\n\nWe can then build a times table by experimentally multiplying.\nThe expansions for zero and one are invariably the strings \"0\" (or the empty string!) and \"1\".\nWhen a sequence has length one, convolution degenerates to term-by-term multiplication.\nThus, convolution by \"0\" produces a sequence of \"0\"s, and convolution by \"1\" produces the same sequence.\n\nIgnoring those rows, the table is:\n\n::: {#545985aa .cell execution_count=3}\n``` {.python .cell-code code-fold=\"true\"}\nfrom IPython.display import Markdown\nfrom tabulate import tabulate\n\nMarkdown(tabulate(\n [[zeck_times(i, j) for i in range(1, 10)] for j in range(2, 10)],\n headers=[\"$\\\\odot_\\\\text{Zeck}$\", *range(2, 10)]\n))\n```\n\n::: {.cell-output .cell-output-display .cell-output-markdown execution_count=2}\n $\\odot_\\text{Zeck}$ 2 3 4 5 6 7 8 9\n--------------------- --- --- --- --- --- --- --- ---\n 2 3 5 7 8 10 11 13 15\n 3 5 8 11 13 16 18 21 24\n 4 7 11 15 18 22 25 29 33\n 5 8 13 18 21 26 29 34 39\n 6 10 16 22 26 32 36 42 48\n 7 11 18 25 29 36 40 47 54\n 8 13 21 29 34 42 47 55 63\n 9 15 24 33 39 48 54 63 72\n:::\n:::\n\n\nThis resembles a sequence in the OEIS ([A101646](https://oeis.org/A101646)), where it mentions the defining operation\n is sometimes called the \"arroba\" product.\n\n### Correcting for Errors\n\nThe difference between the actual product and the false product can be interpreted as an error endemic to Zeckendorf expansions.\nIf assigned to the symbol $\\oplus_\\text{Zeck}$, then the normal product can be recovered as\n $mn = m \\odot_\\text{Zeck} n + m \\oplus_\\text{Zeck} n$.\n\nWe can then tabulate these errors just like we did our \"products\":\n\n::: {#f5cffcdc .cell execution_count=4}\n``` {.python .cell-code code-fold=\"true\"}\nzeck_error = lambda x, y: x*y - zeck_times(x, y)\n\nMarkdown(tabulate(\n [[j] + [zeck_error(i, j) for i in range(2, 10)] for j in range(2, 10)],\n headers=[\"$\\\\oplus_\\\\text{Zeck}$\", *range(2, 10)]\n))\n```\n\n::: {.cell-output .cell-output-display .cell-output-markdown execution_count=3}\n $\\oplus_\\text{Zeck}$ 2 3 4 5 6 7 8 9\n---------------------- --- --- --- --- --- --- --- ---\n 2 1 1 1 2 2 3 3 3\n 3 1 1 1 2 2 3 3 3\n 4 1 1 1 2 2 3 3 3\n 5 2 2 2 4 4 6 6 6\n 6 2 2 2 4 4 6 6 6\n 7 3 3 3 6 6 9 9 9\n 8 3 3 3 6 6 9 9 9\n 9 3 3 3 6 6 9 9 9\n:::\n:::\n\n\nNotice that the errors seem to be grouped together in rectangular blocks.\nBecause this operation is commutative, the shapes of the rectangles must agree along the main diagonal, where they are squares.\n\n### Fibonacci Runs\n\nThe shape of the rectangular blocks is somewhat odd.\nWe can assess the number of terms the series \"hangs\" before progressing by looking at the\n [*run lengths*](https://en.wikipedia.org/wiki/Run-length_encoding)).\n\n:::: {.row layout-ncol=\"1\"}\n::: {.row}\n\n::: {#b4a13686 .cell execution_count=5}\n``` {.python .cell-code code-fold=\"true\"}\nfrom IPython.display import Math\nfrom typing import Generator\n\ndef run_lengths(xs: Generator) -> Generator:\n last = next(xs)\n run_length = 1\n for i in xs:\n if i != last:\n yield run_length\n last = i\n run_length = 1\n else:\n run_length += 1\n\nshow_trunc_list = lambda xs, n: \"[\" + \", \".join(chain(islice(map(str, xs), n), (\"...\",))) + \"]\"\n\nMath(\n \"RL([i \\\\oplus 2]_{i}) =\"\n + f\"RL({show_trunc_list((zeck_error(i, 2) for i in count(0)), 10)}) =\"\n + show_trunc_list(run_lengths(zeck_error(i, 2) for i in count(0)), 10)\n)\n```\n\n::: {.cell-output .cell-output-display .cell-output-markdown execution_count=4}\n$\\displaystyle RL([i \\oplus 2]_{i}) =RL([0, 0, 1, 1, 1, 2, 2, 3, 3, 3, ...]) =[2, 3, 2, 3, 3, 2, 3, 2, 3, 3, ...]$\n:::\n:::\n\n\n:::\n\n::: {.row}\n\n::: {#c073b4b3 .cell execution_count=6}\n``` {.python .cell-code code-fold=\"true\"}\nMath(\n \"RL([i \\\\oplus 5]_{i}) =\"\n + f\"RL({show_trunc_list((zeck_error(i, 5) for i in count(0)), 10)}) =\"\n + show_trunc_list(run_lengths(zeck_error(i, 2) for i in count(0)), 10)\n)\n```\n\n::: {.cell-output .cell-output-display .cell-output-markdown execution_count=5}\n$\\displaystyle RL([i \\oplus 5]_{i}) =RL([0, 0, 2, 2, 2, 4, 4, 6, 6, 6, ...]) =[2, 3, 2, 3, 3, 2, 3, 2, 3, 3, ...]$\n:::\n:::\n\n\n:::\n\n::: {.row}\n\n::: {#a83206da .cell execution_count=7}\n``` {.python .cell-code code-fold=\"true\"}\nMath(\n \"RL([i \\\\oplus i]_{i}) =\"\n + f\"RL({show_trunc_list((zeck_error(i, i) for i in count(0)), 10)}) =\"\n + show_trunc_list(run_lengths(zeck_error(i, i) for i in count(0)), 10)\n)\n```\n\n::: {.cell-output .cell-output-display .cell-output-markdown execution_count=6}\n$\\displaystyle RL([i \\oplus i]_{i}) =RL([0, 0, 1, 1, 1, 4, 4, 9, 9, 9, ...]) =[2, 3, 2, 3, 3, 2, 3, 2, 3, 3, ...]$\n:::\n:::\n\n\n:::\n::::\n\nThe initial two comes from the errors for $0 \\oplus i$ and $1 \\oplus i$.\nThese rows never have errors, so they can be ignored.\n\nSince the run lengths appear to only be occur in twos and threes, we don't lose any information by converting it\n into, say, ones and zeroes.\nArbitrarily mapping $3 \\mapsto 0,~ 2 \\mapsto 1$, the sequence becomes (truncated to 30 terms):\n\n$$\n0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,0,...\n$$\n\nThis sequence matches the *Fibonacci word* ([OEIS A3849](http://oeis.org/A003849)).\nThe typical definition of this sequence follows from the a slight modification to that of\n the Fibonacci sequence: rather than starting with two 1s and adding, we start with\n \"0\" and \"1\" (as distinct strings), and concatenate.\n\nPerhaps this is unsurprising, since Zeckendorf expansions are literally strings in Fibonacci numbers.\nHowever, this shows that the errors can be interesting, since it is not obvious that this is the case\n from just looking at the multiplication table.\n\n\nVisualizing Tables\n------------------\n\nWhile it's great that we can build a table, just showing the numbers isn't the best we can do when it comes to visualization.\n\nFor inspiration, I remembered what WolframAlpha does when you ask it for operation tables in finite fields.\nRather than showing you the underlying field elements in a table, it renders\n [a grayscale image](https://www.wolframalpha.com/input?i=finite+field+of+order+25).\n\nI'd like produce something similar in color, but there's a slight problem: we don't have a finite number of elements.\nTo get around this, we'll have to take our tables mod an integer.\nIn the HSV color space, colors are cyclic just like the integers mod *n*.\nThis actually has an additional appealing feature: two colors with similar hues are \"near\" in a similar way to the underlying numbers.\nThen, the entry-to-color mapping can just be given as\n\n$$\nk \\mapsto HSV \\left({2\\pi k \\over n}, 100\\%, 100\\% \\right)\n$$\n\nIn this mapping, for $n = 2$, zero goes to red and one goes to cyan.\nThe following is a 100x100 image of the multiplication table of $\\oplus_\\text{Zeck}$ from 0 to 99.\n\n\n\n\n### Anima Moduli\n\nThis table can by animated by gathering various n into an animation and incrementing n every frame.\nBefore applying this technique to an error table, it'd be prudent to apply it to standard addition and multiplication tables first.\n\n::: {.row layout-ncol=\"2\"}\n{.image-wide}\n\n{.image-wide}\n:::\n\nBoth images appear to zoom in as the animation progresses.\nUnsurprisingly, addition produces diagonal stripes, along which the sum is the same.\nMultiplication produces a squarish pattern (with somewhat appealing moirés).\n\nTables for $\\odot_\\text{Zeck}$ and $\\oplus_\\text{Zeck}$ should resemble the table to the right,\n since their definition relies on it.\n\n::: {.row layout-ncol=\"2\"}\n{.image-wide}\n\n{.image-wide}\n:::\n\nIndeed, the zooming is present in both tables.\nAt later frames, both tables share the same \"square rainbow\" pattern, but the error table is closer.\nThough both tables appear to have a repeating pattern, the blocks in the error table are still\n irregularly shaped, as in the mod 2 case.\n\nThe error table also demonstrates (for a given modulus) how much the series differs from a geometric series.\nWe know there will always be an error since, while Fibonacci numbers grow on the order of\n $O(\\varphi^n)$, the ratio between place values is only *φ* in the limit.\n\n\nOther Error Tables\n------------------\n\nThese operations can can also be defined in terms of any other series expansion (i.e., integral system).\nRather than showing both of the multiplication and error tables, I will elect to show only the latter.\nThe error table is more fundamental since the table for $\\odot$ can be constructed from it and the normal multiplication table.\n\nThe error tables for some of the previously-discussed generalizations of the Fibonacci numbers are presented below.\n\n\n### Pell, Jacobsthal\n\n::: {.row layout-ncol=\"2\"}\n)\n $\\langle 2,1|$\n](series_tables/pell_oplus.gif){.image-wide}\n\n),\n $\\langle 1,2|$\n](series_tables/jacobsthal_oplus.gif){.image-wide}\n:::\n\nOf the two tables, the Pell table looks more similar to the Fibonacci one.\nMeanwhile, the Jacobsthal table has frames which are significantly redder than the either surrounding it.\nThese occur on frames for which *n* is a power of 2, which is a root of the recurrence polynomial.\n\n\n### *n*-nacci\n\n::: {.row layout-ncol=\"2\"}\n{.image-wide}\n\n{.image-wide}\n:::\n\nCompared to the Fibonacci image, the size of the square pattern in the Tribonacci and Tetranacci images is larger.\nHigher orders of Fibonacci recurrences approach binary, so in the limit,\n the pattern disappears, as if the tiny red corner in the upper-left is all that remains.\n\n\n### Other\n\nOf course, integral systems are not limited to linear recurrences, and tables can also be produced\n that correspond to other integer sequences.\nFor example, the factorials produce distinct patterns at certain frames.\nThe Catalan numbers (which are their own recurrence) mod two seem to make a fractal carpet.\nTo prevent the page from getting bloated, these frames are presented in isolation.\n\n\n::: {.row layout-ncol=\"2\"}\n{.image-wide}\n\n{.image-wide}\n:::\n\n\nAdditional tables which I find interesting are:\n\n- [\n Triangular Numbers (recurrence $\\langle 3, \\bar{3}, 1|$)\n](series_tables/triangular_oplus.gif){target=\"_blank_\"}\n- [\n Square Numbers\n](series_tables/square_oplus.gif){target=\"_blank_\"}\n- [\n Padovan Numbers (recurrence $\\langle 0,1,1|$)\n](series_tables/padovan_oplus.gif){target=\"_blank_\"}\n- [\n $\\langle 1, 1, 2|$, based on the first 3 Catalan numbers\n](series_tables/recurrence_1_1_2_oplus.gif){target=\"_blank_\"}\n\n\nClosing\n-------\n\nEven if not particularly useful, I enjoy the emergent behavior apparent in the tables.\nEven for typical multiplication, this visualization technique shows regular patterns which appear to \"grow\".\nMeanwhile, the sequence products frequently produce a pattern that either repeats, or is composed of many similar elements.\n\nThe project that I used to render the images can be found [here](https://github.com/queue-miscreant/SeriesDeficient).\nI didn't put much thought into command line arguments, nor did I build in many features.\nAs an executable, it should be completely serviceable to generate error tables based on recurrence relations;\n the GHCi REPL can be used for more sophisticated sequences.\n\n\n### Bad Visualization\n\nMy first attempt to map integers to colors was to consider its prime factorization.\nThe largest number in the factorization was related to the hue, and the number of terms in the factorization\n was related to the saturation.\nResults were not great.\n\n\n\n\n### Bad Filesizes\n\nWhile I rendered these animations as GIFs, I also attempted to convert some of them to MP4s in hopes of shrinking the filesize.\nHowever, this is a use case where the MP4 is larger than the GIF, at least without compromising on resolution.\nThis is a case when space-compression beats ill-suited time-compression.\n\n\n\n",
+ "supporting": [
+ "index_files"
+ ],
+ "filters": [],
+ "includes": {}
+ }
+}
\ No newline at end of file
diff --git a/_freeze/polycount/cell1/fig1/execute-results/html.json b/_freeze/polycount/cell1/fig1/execute-results/html.json
new file mode 100644
index 0000000..a27fbf7
--- /dev/null
+++ b/_freeze/polycount/cell1/fig1/execute-results/html.json
@@ -0,0 +1,16 @@
+{
+ "hash": "87c9932ff62d911a44f6d6fca5c513e4",
+ "result": {
+ "engine": "jupyter",
+ "markdown": "::: {#4d35cd9f .cell execution_count=1}\n``` {.python .cell-code}\nfrom IPython.display import HTML\nfrom carry2d import anim, carry\n\nHTML(\n anim.animate_carry(\n carry = carry.Carry([[2,-1],[-1,0]]),\n frames=list(range(200))\n ).to_jshtml()\n)\n```\n\n::: {.cell-output .cell-output-display execution_count=1}\n```{=html}\n\n\n\n\n\n\n