Compare commits
No commits in common. "092f98c17abedeac5a36acd0cdf550f34d444cd2" and "7ac85b5b1e3741f0ad3a54afb5b359afe3a55169" have entirely different histories.
092f98c17a
...
7ac85b5b1e
@ -12,7 +12,7 @@ _"Pick a number"_, he said, _"And I'll teach you how to draw a pattern from it."
|
||||
The procedure was rather simple:
|
||||
|
||||
1. Pick a number between 2 and 8 (inclusive).
|
||||
2. Start generating positive multiples of this number. If you picked 8,
|
||||
2. Start generating multiples of this number. If you picked 8,
|
||||
your multiples would be 8, 16, 24, and so on.
|
||||
3. If a multiple is more than one digit long, sum its digits. For instance, for 16, write 1+6=7.
|
||||
If the digits add up to a number that's still more than 1 digit long, add up the digits of _that_
|
||||
@ -37,7 +37,7 @@ characters (`"17"` becomes `["1", "7"]`), turning each of these character back i
|
||||
|
||||
We may now encode the "drawing" logic. At any point, there's a "direction" we're going - which
|
||||
I'll denote by the Ruby symbols `:top`, `:bottom`, `:left`, and `:right`. Each step, we take
|
||||
the current `x`,`y` coordinates (our position on the grid), and shift them by `n` in a particular
|
||||
the current `x`/`y` coordinates (our position on the grid), and shift them by `n` in a particular
|
||||
direction `dir`. We also return the new direction alongside the new coordinates.
|
||||
|
||||
{{< codelines "Ruby" "patterns/patterns.rb" 10 21 >}}
|
||||
@ -109,7 +109,7 @@ larger than \(k\).
|
||||
\end{aligned}
|
||||
{{< /latex >}}
|
||||
|
||||
We only really care about the remainder here, not the quotient, since it's the remainder
|
||||
We only _really_ care about the remainder here, not the quotient, since it's the remainder
|
||||
that determines if something is divisible or not. From the form of the second equation, we can
|
||||
deduce that \\(b-r\\) is divisible by \\(a\\) (it's literally equal to \\(a\\) times \\(k\\),
|
||||
so it must be divisible). Thus, we can write:
|
||||
@ -126,16 +126,13 @@ two numbers is divisible by a third number, we write:
|
||||
{{< /latex >}}
|
||||
|
||||
Some things that _seem_ like they would work from this "equation-like" notation do, indeed, work.
|
||||
For instance, we can "add two equations" (I'll omit the proof here; jump down to [this
|
||||
section](#adding-two-congruences) to see how it works):
|
||||
For instance, we can "add two equations":
|
||||
|
||||
{{< latex >}}
|
||||
\textbf{if}\ a \equiv b\ (\text{mod}\ k)\ \textbf{and}\ c \equiv d, (\text{mod}\ k),\ \textbf{then}\
|
||||
a+c \equiv b+d\ (\text{mod}\ k).
|
||||
{{< /latex >}}
|
||||
|
||||
Multiplying both sides by the same number (call it \\(n\\)) also works (once
|
||||
again, you can find the proof in [this section below](#multiplying-both-sides-of-a-congruence)).
|
||||
Multiplying both sides by the same number (call it \\(n\\)) also works:
|
||||
|
||||
{{< latex >}}
|
||||
\textbf{if}\ a \equiv b\ (\text{mod}\ k),\ \textbf{then}\ na \equiv nb\ (\text{mod}\ k).
|
||||
@ -246,29 +243,13 @@ will always be 0.
|
||||
Repeating remainders alone do not guarantee that we will return to the center. The repeating sequence 1,2,3,4
|
||||
will certainly cause a spiral. The reason is that, if we start facing "up", we will always move up 1
|
||||
and down 3 after four steps, leaving us 2 steps below where we started. Next, the cycle will repeat,
|
||||
and since turning four times leaves us facing "up" again, we'll end up getting _further_ away. Here's
|
||||
a picture that captures this behvior:
|
||||
|
||||
{{< figure src="pattern_1_4.svg" caption="Spiral generated by the number 1 with divisor 4." class="tiny" alt="Spiral generated by the number 1 by summing digits." >}}
|
||||
|
||||
And here's one more where the cycle repeats after 8 steps instead of 4. You can see that it also
|
||||
leads to a spiral:
|
||||
|
||||
{{< figure src="pattern_1_8.svg" caption="Spiral generated by the number 1 with divisor 8." class="tiny" alt="Spiral generated by the number 1 by summing digits." >}}
|
||||
and since turning four times leaves us facing "up" again, we'll end up getting _further_ down.
|
||||
|
||||
From this, we can devise a simple condition to prevent spiraling -- the _length_ of the sequence before
|
||||
it repeats _cannot be a multiple of 4_. This way, whenever the cycle restarts, it will do so in a
|
||||
different direction: backwards, turned once to the left, or turned once to the right. Clearly repeating
|
||||
the sequence backwards is guaranteed to take us back to the start. The same is true for the left and right-turn sequences, though it's less obvious. If drawing our sequence once left us turned to the right,
|
||||
drawing our sequence twice will leave us turned more to the right. On a grid, two right turns are
|
||||
the same as turning around. The third repetition will then undo the effects of the first one
|
||||
(since we're facing backwards now), and the fourth will undo the effects of the second.
|
||||
|
||||
There is an exception to this
|
||||
multiple-of-4 rule: if a sequence makes it back to the origin right before it starts over.
|
||||
In that case, even if it's facing the very same direction it started with, all is well -- things
|
||||
are just like when it first started, and the cycle repeats. I haven't found a sequence that does this,
|
||||
so for our purposes, we'll stick with avoiding multiples of 4.
|
||||
the sequence backwards is guaranteed to take us back to the start. The same is true for the left and right-turn sequences,
|
||||
since after two iterations they will _also_ leave us facing backwards.
|
||||
|
||||
Okay, so we want to avoid cycles with lengths divisible by four. What does it mean for a cycle to be of length _k_? It effectively means the following:
|
||||
|
||||
@ -291,8 +272,7 @@ between 2 and 8. What went wrong? Turns out, it's that last step: we can't alway
|
||||
Some values of \\(k\\) are special, and it's only _those_ values that can serve as cycle lengths
|
||||
without causing a contradiction. So, what are they?
|
||||
|
||||
They're values that have a common factor with 9 (an incomplete explanation is in
|
||||
[this section below](#invertible-numbers-textmod-d-share-no-factors-with-d)). There are many numbers that have a common
|
||||
They're values that have a common factor with 9. There are many numbers that have a common
|
||||
factor with 9; 3, 6, 9, 12, and so on. However, those can't all serve as cycle lengths: as we said,
|
||||
cycles can't get longer than 9. This leaves us with 3, 6, and 9 as _possible_ cycle lengths,
|
||||
none of which are divisible by 4. We've eliminated the possibility of spirals!
|
||||
@ -323,10 +303,10 @@ is not ruled out as a valid cycle by our previous condition, we don't find any c
|
||||
|
||||
So what is it that _really_ determines if there can be cycles or not?
|
||||
|
||||
Let's do some more playing around. What are the actual cycle lengths when we divide by 9?
|
||||
Let's do some more playing around. What _are_ the actual cycle lengths when we divide by 9?
|
||||
For all but two numbers, the cycle lengths are 9. The two special numbers are 6 and 3, and they end up
|
||||
with a cycle length of 3. From this, we can say that the cycle length seems to depend on whether or
|
||||
not our \\(n\\) has any common factors with the divisor.
|
||||
nor our \\(n\\) has any common factors with the divisor.
|
||||
|
||||
Let's explore this some more with a different divisor, say 12. We fill find that 8 has a cycle length
|
||||
of 3, 7 has a cycle length of 12, 9 has a cycle length of 4. What's
|
||||
@ -340,26 +320,25 @@ for the length of a cycle:
|
||||
k = \frac{d}{\text{gcd}(d,n)}
|
||||
{{< /latex >}}
|
||||
|
||||
Where \\(d\\) is our divisor, which has been 9 until just recently, and \\(\\text{gcd}(d,n)\\)
|
||||
is the greatest common factor of \\(d\\) and \\(n\\). This equation is in agreement
|
||||
with our experiment for \\(d = 9\\), too. Why might this be? Recall that sequences with
|
||||
period \\(k\\) imply the following congruence:
|
||||
Where \\(d\\) is our divisor, which has been 9 until just recently. Indeed, this equation is in agreement
|
||||
with our experiment for \\(d = 9\\), too. Why might this be? Let's start once again with
|
||||
our equation for paths of length \\(k\\):
|
||||
|
||||
{{< latex >}}
|
||||
kn \equiv 0\ (\text{mod}\ d)
|
||||
{{< /latex >}}
|
||||
|
||||
Here I've replaced 9 with \\(d\\), since we're trying to make it work for _any_ divisor, not just 9.
|
||||
Here we've replaced 9 with \\(d\\), since we're trying to make it work for _any_ divisor, not just 9.
|
||||
Now, suppose the greatest common divisor of \\(n\\) and \\(d\\) is some number \\(f\\). Then,
|
||||
since this number divides \\(n\\) and \\(d\\), we can write \\(n=fm\\) for some \\(m\\), and
|
||||
\\(d=fg\\) for some \\(g\\). We can rewrite our congruence as follows:
|
||||
\\(d=fg\\) for some \\(g\\). We can rewrite our equation as follows:
|
||||
|
||||
{{< latex >}}
|
||||
kfm \equiv 0\ (\text{mod}\ fg)
|
||||
{{< /latex >}}
|
||||
|
||||
We can simplify this a little bit. Recall that what this congruence really means is that the
|
||||
difference of \\(kfm\\) and \\(0\\), which is just \\(kfm\\), is divisible by \\(fg\\):
|
||||
We can simplify this a little bit. Recall that what this equation _really_ means is that the
|
||||
difference of \\(kfm\\) and \\(0\\), which is just \\(kfm\\) is divisible by \\(fg\\):
|
||||
|
||||
{{< latex >}}
|
||||
fg|kfm
|
||||
@ -372,17 +351,14 @@ we can write:
|
||||
g|km
|
||||
{{< /latex >}}
|
||||
|
||||
Can we distill this statement even further? It turns out that we can. Remember that we got \\(g\\)
|
||||
and \\(m\\) by dividing \\(d\\) and \\(n\\) by their greatest common factor, \\(f\\). This, in
|
||||
turn, means that \\(g\\) and \\(m\\) have no more common factors that aren't equal to 1 (see
|
||||
[this section below](#numbers-divided-by-their-textgcd-have-no-common-factors)). From this, in turn, we can deduce that \\(m\\) is not
|
||||
relevant to \\(g\\) dividing \\(km\\), and we get:
|
||||
We also know that \\(g\\) and \\(m\\) have no common factors -- they were all divided out from \\(d\\)
|
||||
and \\(n\\) when we divided by \\(f\\)! We can thus further simplify our claim:
|
||||
|
||||
{{< latex >}}
|
||||
g|k
|
||||
{{< /latex >}}
|
||||
|
||||
That is, we get that \\(k\\) must be divisible by \\(g\\). Recall that we got \\(g\\) by dividing
|
||||
This says that \\(k\\) must be divisible by \\(g\\). Recall that we got \\(g\\) by dividing
|
||||
\\(d\\) by \\(f\\), which is our largest common factor -- aka \\(\\text{gcd}(d,n)\\). We can thus
|
||||
write:
|
||||
|
||||
@ -390,25 +366,24 @@ write:
|
||||
\frac{d}{\text{gcd}(d,n)}|k
|
||||
{{< /latex >}}
|
||||
|
||||
Let's stop and appreciate this result. We have found a condition that is required for a sequnce
|
||||
of remainders from dividing by \\(d\\) (which was 9 in the original problem) to repeat after \\(k\\)
|
||||
numbers. Furthermore, all of our steps can be performed in reverse, which means that if a \\(k\\)
|
||||
matches this conditon, we can work backwards and determine that a sequence of numbers has
|
||||
to repeat after \\(k\\) steps.
|
||||
All that's left is to pick the smallest \\(k\\) that fits this description (that would be the first
|
||||
point at which our sequence of multiples of \\(n\\) will loop). Zero is divisible by anything, but
|
||||
alas, our sequence numbers start at 1 -- zero's out. The next best thing is \\(d/\\text{gcd}(d,n)\\).
|
||||
And there we have it: the first point at which our sequence loops, just like we guessed.
|
||||
|
||||
Multiple \\(k\\)s will match this condition, and that's not surprising. If a sequence repeats after 5 steps,
|
||||
it also repeats after 10, 15, and so on. We're interested in the first time our sequences repeat after
|
||||
taking any steps, which means we have to pick the smallest possible non-zero value of \\(k\\). The smallest
|
||||
number divisible by \\(d/\\text{gcd}(d,n)\\) is \\(d/\\text{gcd}(d,n)\\) itself. We thus confirm
|
||||
our hypothesis:
|
||||
|
||||
{{< latex >}}
|
||||
k = \frac{d}{\text{gcd}(d,n)}
|
||||
{{< /latex >}}
|
||||
|
||||
Lastly, recall that our patterns would spiral away from the center whenever a \\(k\\) is a multiple of 4. Now that we know what
|
||||
Lastly, recall that a cycle occurs whenever a \\(k\\) is a multiple of 4. Now that we know what
|
||||
\\(k\\) is, we can restate this as "\\(d/\\text{gcd}(d,n)\\) is divisible by 4". But if we pick
|
||||
\\(n=d-1\\), the greatest common factor has to be \\(1\\) (see [this section below](#divisors-of-n-and-n-1)), so we can even further simplify this "\\(d\\) is divisible by 4".
|
||||
\\(n=d-1\\), the
|
||||
{{< sidenote "right" "coprime-note" "greatest common factor has to be \(1\)," >}}
|
||||
Wait, why is <em>this</em> true? Well, suppose some number \(f\) divides both \(d\) and \(d-1\).
|
||||
In that case, we can write \(d=af\), and \((d-1)=bf\). Subtracting one equation from the other:
|
||||
{{< latex >}}
|
||||
1 = (a-b)f
|
||||
{{< /latex >}}
|
||||
But this means that 1 is divisible by \(f\)! That's only possible if \(f=1\). Thus, the only
|
||||
number that divides \(x\) and \(x-1\) is 1; that's our greatest common factor.
|
||||
{{< /sidenote >}} which means that our condition further simplifies to
|
||||
"\\(d\\) is divisible by 4".
|
||||
Thus, we can state simply that any divisor divisible by 4 is off-limits, as it will induce loops.
|
||||
For example, pick \\(d=4\\). Running our algorithm for \\(n=d-1=3\\), we indeed find an infinite
|
||||
spiral:
|
||||
@ -523,81 +498,3 @@ But let's not be so boring. We can branch out some, of course.
|
||||
{{< figure src="pattern_1_7_t5.svg" caption="Pattern generated by the number 1 in base 8 while turning 5 times." class="tiny" alt="Pattern generated by the number 1 by summing digits in base 8 and turning 72 degrees." >}}
|
||||
|
||||
{{< figure src="pattern_3_11_t6.svg" caption="Pattern generated by the number 3 in base 12 while turning 6 times." class="tiny" alt="Pattern generated by the number 3 by summing digits in base 12 and turning 60 degrees." >}}
|
||||
|
||||
### Omitted Proofs
|
||||
|
||||
#### Adding Two Congruences
|
||||
__Claim__: If for some numbers \\(a\\), \\(b\\), \\(c\\), \\(d\\), and \\(k\\), we have
|
||||
\\(a \\equiv b\\ (\\text{mod}\\ k)\\) and \\(c \\equiv d\\ (\\text{mod}\\ k)\\), then
|
||||
it's also true that \\(a+c \\equiv b+d\\ (\\text{mod}\\ k)\\).
|
||||
|
||||
__Proof__: By definition, we have \\(k|(a-b)\\) and \\(k|(c-d)\\). This, in turn, means
|
||||
that for some \\(i\\) and \\(j\\), \\(a-b=ik\\) and \\(c-d=jk\\). Add both sides to get:
|
||||
{{< latex >}}
|
||||
\begin{aligned}
|
||||
& (a-b)+(c-d) = ik+jk \\
|
||||
\Rightarrow\ & (a+c)-(b+d) = (i+j)k \\
|
||||
\Rightarrow\ & k\ |\left[(a+c)-(b+d)\right]\\
|
||||
\Rightarrow\ & a+c \equiv b+d\ (\text{mod}\ k) \\
|
||||
\end{aligned}
|
||||
{{< /latex >}}
|
||||
\\(\\blacksquare\\)
|
||||
|
||||
#### Multiplying Both Sides of a Congruence
|
||||
__Claim__: If for some numbers \\(a\\), \\(b\\), \\(n\\) and \\(k\\), we have
|
||||
\\(a \\equiv b\\ (\\text{mod}\\ k)\\) then we also have that \\(an \\equiv bn\\ (\\text{mod}\\ k)\\).
|
||||
|
||||
__Proof__: By definition, we have \\(k|(a-b)\\). Since multiplying \\(a-b\\) but \\(n\\) cannot
|
||||
make it _not_ divisible by \\(k\\), we also have \\(k|\\left[n(a-b)\\right]\\). Distributing
|
||||
\\(n\\), we have \\(k|(na-nb)\\). By definition, this means \\(na\\equiv nb\\ (\\text{mod}\\ k)\\).
|
||||
|
||||
\\(\\blacksquare\\)
|
||||
|
||||
#### Invertible Numbers \\(\\text{mod}\\ d\\) Share no Factors with \\(d\\)
|
||||
__Claim__: A number \\(k\\) is only invertible (can be divided by) in \\(\\text{mod}\\ d\\) if \\(k\\)
|
||||
and \\(d\\) share no common factors (except 1).
|
||||
|
||||
__Proof__: Write \\(\\text{gcd}(k,d)\\) for the greatest common factor divisor of \\(k\\) and \\(d\\).
|
||||
Another important fact (not proven here, but see something [like this](https://sharmaeklavya2.github.io/theoremdep/nodes/number-theory/gcd/gcd-is-min-lincomb.html)), is that if \\(\\text{gcd}(k,d) = r\\),
|
||||
then the smallest possible number that can be made by adding and subtracting \\(k\\)s and \\(d\\)s
|
||||
is \\(r\\). That is, for some \\(i\\) and \\(j\\), the smallest possible positive value of \\(ik + jd\\) is \\(r\\).
|
||||
|
||||
Now, note that \\(d \\equiv 0\\ (\\text{mod}\\ d)\\). Multiplying both sides by \\(j\\), get
|
||||
\\(jd\\equiv 0\\ (\\text{mod}\\ d)\\). This, in turn, means that the smallest possible
|
||||
value of \\(ik+jd \\equiv ik\\) is \\(r\\). If \\(r\\) is bigger than 1 (i.e., if
|
||||
\\(k\\) and \\(d\\) have common factors), then we can't pick \\(i\\) such that \\(ik\\equiv1\\),
|
||||
since we know that \\(r>1\\) is the least possible value we can make. There is therefore no
|
||||
multiplicative inverse to \\(k\\). Alternatively worded, we cannot divide by \\(k\\).
|
||||
|
||||
\\(\\blacksquare\\)
|
||||
|
||||
#### Numbers Divided by Their \\(\\text{gcd}\\) Have No Common Factors
|
||||
__Claim__: For any two numbers \\(a\\) and \\(b\\) and their largest common factor \\(f\\),
|
||||
if \\(a=fc\\) and \\(b=fd\\), then \\(c\\) and \\(d\\) have no common factors other than 1 (i.e.,
|
||||
\\(\\text{gcd}(c,d)=1\\)).
|
||||
|
||||
__Proof__: Suppose that \\(c\\) and \\(d\\) do have sommon factor, \\(e\\neq1\\). In that case, we have
|
||||
\\(c=ei\\) and \\(d=ej\\) for some \\(i\\) and \\(j\\). then, we have \\(a=fei\\), and \\(b=fej\\).
|
||||
From this, it's clear that both \\(a\\) and \\(b\\) are divisible by \\(fe\\). Since \\(e\\)
|
||||
is greater than \\(1\\), \\(fe\\) is greater than \\(f\\). But our assumptions state that
|
||||
\\(f\\) is the greatest common divisor of \\(a\\) and \\(b\\)! We have arrived at a contradiction.
|
||||
|
||||
Thus, \\(c\\) and \\(d\\) cannot have a common factor other than 1.
|
||||
|
||||
\\(\\blacksquare\\)
|
||||
|
||||
#### Divisors of \\(n\\) and \\(n-1\\).
|
||||
__Claim__: For any \\(n\\), \\(\\text{gcd}(n,n-1)=1\\). That is, \\(n\\) and \\(n-1\\) share
|
||||
no common divisors.
|
||||
|
||||
__Proof__: Suppose some number \\(f\\) divides both \\(n\\) and \\(n-1\\).
|
||||
In that case, we can write \\(n=af\\), and \\((n-1)=bf\\) for some \\(a\\) and \\(b\\).
|
||||
Subtracting one equation from the other:
|
||||
|
||||
{{< latex >}}
|
||||
1 = (a-b)f
|
||||
{{< /latex >}}
|
||||
But this means that 1 is divisible by \\(f\\)! That's only possible if \\(f=1\\). Thus, the only
|
||||
number that divides \\(n\\) and \\(n-1\\) is 1; that's our greatest common factor.
|
||||
|
||||
\\(\\blacksquare\\)
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit f4d4f4e5d74785e1f84e34afb2f4910a76f80cd5
|
||||
Subproject commit 9b0c70ac05c209011e32f97a35cbca0b42267974
|
Loading…
Reference in New Issue
Block a user