fixes for sitewide display
This commit is contained in:
parent
c9d552879d
commit
a7fd265823
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
**/*_files
|
||||
*.html
|
||||
_freeze/
|
||||
_site/
|
||||
/.quarto/
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
---
|
||||
title: "Polynomial Counting 1: A primer"
|
||||
format:
|
||||
html:
|
||||
html-math-method: katex
|
||||
jupyter: python3
|
||||
date: "2021/02/03"
|
||||
categories:
|
||||
- algebra
|
||||
- phinary
|
||||
---
|
||||
|
||||
Polynomial Counting: A primer
|
||||
=============================
|
||||
|
||||
The single most common method of representing numbers in the modern world is in *positional numeral system*.
|
||||
Despite being taught in early grade school, it is the result of millennia of mathematical thought.
|
||||
|
||||
@ -120,7 +122,7 @@ Naively, we might use the following "greedy" algorithm to derive the base-$b$ ex
|
||||
(also called a [β-expansion](https://en.wikipedia.org/wiki/Non-integer_base_of_numeration)) of a number $x$:
|
||||
|
||||
```{python}
|
||||
from math import log
|
||||
from math import log, floor
|
||||
|
||||
def beta_expand_greedy(
|
||||
x: float,
|
||||
@ -130,7 +132,7 @@ def beta_expand_greedy(
|
||||
ret = {}
|
||||
|
||||
while x > tol: # While we're not precise enough
|
||||
p = int(log(x, b)) # Get the place value p
|
||||
p = int(floor(log(x, b))) # Get the place value p
|
||||
digit, new_x = divmod(x, b**p) # Get the quotient and remainder from
|
||||
# dividing by this place value
|
||||
ret[p] = int(digit) # Place the digit in place value p
|
||||
@ -138,7 +140,12 @@ def beta_expand_greedy(
|
||||
|
||||
return ret
|
||||
|
||||
def as_digits(digits: dict[int, int]):
|
||||
```
|
||||
|
||||
As a demonstration, this algorithm, when run on a decimal number gives the same value:
|
||||
|
||||
```{python}
|
||||
def as_digits(digits: dict[int, int]) -> str:
|
||||
'''Convert a dictionary from `beta_expand_greedy` to a sequence of digits'''
|
||||
return "".join(
|
||||
str(digits.get(i, 0)) + ("." if i == 0 else "")
|
||||
@ -160,7 +167,8 @@ There are three problems with this.
|
||||
Due to the nature of the approximation, the result can also appear in an unexpected form:
|
||||
```{python}
|
||||
phi = (5**0.5 + 1) / 2
|
||||
# print(as_digits(beta_expand_greedy(10, phi)))
|
||||
print("Expected:", "10100.0101")
|
||||
print("Got: ", as_digits(beta_expand_greedy(10, phi)))
|
||||
```
|
||||
|
||||
2. It relies on a transcendental function, the logarithm.
|
||||
@ -170,7 +178,7 @@ There are three problems with this.
|
||||
However, if `p` is always positive, we can instead use integer arithmetic, which is more precise.
|
||||
Generally, we need some form of fractional arithmetic.
|
||||
|
||||
Modern FPUs are make the last two items somewhat trivial, but they are necessarily approximate.
|
||||
Modern FPUs are make the last two items somewhat trivial, but they necessarily make the calculation approximate.
|
||||
Fortunately for phinary, there is a direct method which remedies all these issues and produces exact results without floating-point operations.
|
||||
|
||||
|
||||
@ -363,8 +371,8 @@ Expansions of the integers up to 10 are:
|
||||
|
||||
These are known as *Zeckendorf expansions*.
|
||||
|
||||
These representations very similar to the phinary strings above.
|
||||
Not 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)).
|
||||
These representations seem very similar to the phinary strings above.
|
||||
Not 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)).
|
||||
This representation is exactly as arbitrary as preferring the greedy phinary representation;
|
||||
instead, this is the "greedy series expansion" of an integer in the Fibonacci numbers.
|
||||
|
||||
@ -395,7 +403,7 @@ $$
|
||||
|
||||
In the expansion of 2, the rightmost "1" seems to underflow.
|
||||
However, in the expansion of 4, we must consider the second "1" in the negative first place value.
|
||||
It acts as a sort of temporary storage which is immediately transferred into place value 0.
|
||||
It acts as a sort of temporary storage which is immediately transferred into place value zero.
|
||||
|
||||
|
||||
Synthesis: Generalizing Phinary
|
||||
@ -517,4 +525,4 @@ Closing
|
||||
-------
|
||||
|
||||
With these restrictions in mind, I wrote a simple Haskell library to help explore these systems (found [here](https://github.com/queue-miscreant/GenBase)).
|
||||
The [next post]() will discuss quadratic polynomials with larger coefficients than 1, and problems not discussed with higher expansions.
|
||||
The [next post](../2) will discuss quadratic polynomials with larger coefficients than 1, and problems not discussed with higher expansions.
|
||||
|
||||
@ -3,9 +3,13 @@ title: "Polynomial Counting: Binary and beyond"
|
||||
format:
|
||||
html:
|
||||
html-math-method: katex
|
||||
date: "2021/02/05"
|
||||
categories:
|
||||
- algebra
|
||||
- binary
|
||||
---
|
||||
|
||||
This post assumes you have read [the one prior](1), which introduces generalized polynomial counting.
|
||||
This post assumes you have read [the one prior](../1), which introduces generalized polynomial counting.
|
||||
|
||||
Before I start, I'd like to introduce some shorthand.
|
||||
Since we prefer (monic) polynomials which may correspond to linear recurrences, it is useful to use an ordered tuple of their coefficients.
|
||||
@ -329,5 +333,5 @@ This polynomial belongs to a family called
|
||||
which have complex roots of 1 as their roots.
|
||||
I'll have more to say about cyclotomic polynomials in the future, but they cannot be carries by themselves.
|
||||
|
||||
Since higher numbers appearing in carries are somewhat scary, the [next post]() will
|
||||
Since higher numbers appearing in carries are somewhat scary, the [next post](../3) will
|
||||
focus on two more generalizations of the Fibonacci numbers and exceptions to the above rules.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user