Update "search as polynomial" article to new math delimiters
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
parent
357a3bef09
commit
53ff0c39e4
|
@ -58,7 +58,7 @@ two binomials! Here's the corresponding multiplication:
|
||||||
|
|
||||||
It's not just binomials that correspond to our combining paths between cities.
|
It's not just binomials that correspond to our combining paths between cities.
|
||||||
We can represent any combination of trips of various lengths as a polynomial.
|
We can represent any combination of trips of various lengths as a polynomial.
|
||||||
Each term \\(ax^n\\) represents \\(a\\) trips of length \\(n\\). As we just
|
Each term \(ax^n\) represents \(a\) trips of length \(n\). As we just
|
||||||
saw, multiplying two polynomials corresponds to "sequencing" the trips they
|
saw, multiplying two polynomials corresponds to "sequencing" the trips they
|
||||||
represent -- matching each trip in one with each of the trips in the other,
|
represent -- matching each trip in one with each of the trips in the other,
|
||||||
and totaling them up.
|
and totaling them up.
|
||||||
|
@ -66,8 +66,8 @@ and totaling them up.
|
||||||
What about adding polynomials, what does that correspond to? The answer there
|
What about adding polynomials, what does that correspond to? The answer there
|
||||||
is actually quite simple: if two polynomials both represent (distinct) lists of
|
is actually quite simple: if two polynomials both represent (distinct) lists of
|
||||||
trips from A to B, then adding them just combines the list. If I know one trip
|
trips from A to B, then adding them just combines the list. If I know one trip
|
||||||
that takes two hours (\\(x^2\\)) and someone else knows a shortcut (\\(x\\\)),
|
that takes two hours (\(x^2\)) and someone else knows a shortcut (\(x\)),
|
||||||
then we can combine that knowledge (\\(x^2+x\\)).
|
then we can combine that knowledge (\(x^2+x\)).
|
||||||
|
|
||||||
{{< dialog >}}
|
{{< dialog >}}
|
||||||
{{< message "question" "reader" >}}
|
{{< message "question" "reader" >}}
|
||||||
|
@ -119,16 +119,16 @@ example should do.
|
||||||
|
|
||||||
The first thing we do is _distribute_ the multiplication over the addition, on
|
The first thing we do is _distribute_ the multiplication over the addition, on
|
||||||
the left. We then do that again, on the right this time. After this, we finally
|
the left. We then do that again, on the right this time. After this, we finally
|
||||||
get some terms, but they aren't properly grouped together; an \\(x\\) is at the
|
get some terms, but they aren't properly grouped together; an \(x\) is at the
|
||||||
front, and a \\(-x\\) is at the very back. We use the fact that addition is
|
front, and a \(-x\) is at the very back. We use the fact that addition is
|
||||||
_commutative_ (\\(a+b=b+a\\)) and _associative_ (\\(a+(b+c)=(a+b)+c\\)) to
|
_commutative_ (\(a+b=b+a\)) and _associative_ (\(a+(b+c)=(a+b)+c\)) to
|
||||||
rearrange the equation, grouping the \\(x\\) and its negation together. This
|
rearrange the equation, grouping the \(x\) and its negation together. This
|
||||||
gives us \\((1-1)x=0x=0\\). That last step is important: we've used the fact
|
gives us \((1-1)x=0x=0\). That last step is important: we've used the fact
|
||||||
that multiplication by zero gives zero. Another important property (though
|
that multiplication by zero gives zero. Another important property (though
|
||||||
we didn't use it here) is that multiplication has to be associative, too.
|
we didn't use it here) is that multiplication has to be associative, too.
|
||||||
|
|
||||||
So, what if we didn't use numbers, but rather any _thing_ with two
|
So, what if we didn't use numbers, but rather any _thing_ with two
|
||||||
operations, one kind of like \\((\\times)\\) and one kind of like \\((+)\\)?
|
operations, one kind of like \((\times)\) and one kind of like \((+)\)?
|
||||||
|
|
||||||
{{< dialog >}}
|
{{< dialog >}}
|
||||||
{{< message "question" "reader" >}}
|
{{< message "question" "reader" >}}
|
||||||
|
@ -167,8 +167,8 @@ that "things with addition and multiplication that work in the way we
|
||||||
described" have an established name in math - they're called semirings.
|
described" have an established name in math - they're called semirings.
|
||||||
|
|
||||||
A __semiring__ is a set equipped with two operations, one called
|
A __semiring__ is a set equipped with two operations, one called
|
||||||
"multiplicative" (and thus carrying the symbol \\(\\times)\\) and one
|
"multiplicative" (and thus carrying the symbol \(\times)\) and one
|
||||||
called "additive" (and thus written as \\(+\\)). Both of these operations
|
called "additive" (and thus written as \(+\)). Both of these operations
|
||||||
need to have an "identity element". The identity element for multiplication
|
need to have an "identity element". The identity element for multiplication
|
||||||
is usually
|
is usually
|
||||||
{{< sidenote "right" "written-as-note" "written as \(1\)," >}}
|
{{< sidenote "right" "written-as-note" "written as \(1\)," >}}
|
||||||
|
@ -180,10 +180,10 @@ other more "esoteric" things, using numbers to stand for special elements
|
||||||
seems to help use intuition.
|
seems to help use intuition.
|
||||||
{{< /sidenote >}}
|
{{< /sidenote >}}
|
||||||
and the identity element for addition is written
|
and the identity element for addition is written
|
||||||
as \\(0\\). Furthermore, a few equations hold. I'll present them in groups.
|
as \(0\). Furthermore, a few equations hold. I'll present them in groups.
|
||||||
First, multiplication is associative and multiplying by \\(1\\) does nothing;
|
First, multiplication is associative and multiplying by \(1\) does nothing;
|
||||||
in mathematical terms, the set forms a [monoid](https://mathworld.wolfram.com/Monoid.html)
|
in mathematical terms, the set forms a [monoid](https://mathworld.wolfram.com/Monoid.html)
|
||||||
with multiplication and \\(1\\).
|
with multiplication and \(1\).
|
||||||
{{< latex >}}
|
{{< latex >}}
|
||||||
\begin{array}{cl}
|
\begin{array}{cl}
|
||||||
(a\times b)\times c = a\times(b\times c) & \text{(multiplication associative)}\\
|
(a\times b)\times c = a\times(b\times c) & \text{(multiplication associative)}\\
|
||||||
|
@ -191,9 +191,9 @@ with multiplication and \\(1\\).
|
||||||
\end{array}
|
\end{array}
|
||||||
{{< /latex >}}
|
{{< /latex >}}
|
||||||
|
|
||||||
Similarly, addition is associative and adding \\(0\\) does nothing.
|
Similarly, addition is associative and adding \(0\) does nothing.
|
||||||
Addition must also be commutative; in other words, the set forms a
|
Addition must also be commutative; in other words, the set forms a
|
||||||
commutative monoid with addition and \\(0\\).
|
commutative monoid with addition and \(0\).
|
||||||
{{< latex >}}
|
{{< latex >}}
|
||||||
\begin{array}{cl}
|
\begin{array}{cl}
|
||||||
(a+b)+c = a+(b+c) & \text{(addition associative)}\\
|
(a+b)+c = a+(b+c) & \text{(addition associative)}\\
|
||||||
|
@ -219,9 +219,9 @@ another in a particular number of hours. There are, however, other semirings
|
||||||
we can use that yield interesting results, even though we continue to add
|
we can use that yield interesting results, even though we continue to add
|
||||||
and multiply polynomials.
|
and multiply polynomials.
|
||||||
|
|
||||||
One last thing before we look at other semirings: given a semiring \\(R\\),
|
One last thing before we look at other semirings: given a semiring \(R\),
|
||||||
the polynomials using that \\(R\\), and written in terms of the variable
|
the polynomials using that \(R\), and written in terms of the variable
|
||||||
\\(x\\), are denoted as \\(R[x]\\).
|
\(x\), are denoted as \(R[x]\).
|
||||||
|
|
||||||
|
|
||||||
#### The Semiring of Booleans, \\(\\mathbb{B}\\)
|
#### The Semiring of Booleans, \\(\\mathbb{B}\\)
|
||||||
|
@ -239,7 +239,7 @@ is true, and false otherwise.
|
||||||
\end{array}
|
\end{array}
|
||||||
{{< /latex >}}
|
{{< /latex >}}
|
||||||
|
|
||||||
For addition, the identity element -- our \\(0\\) -- is \\(\\text{false}\\).
|
For addition, the identity element -- our \(0\) -- is \(\text{false}\).
|
||||||
|
|
||||||
Correspondingly, multiplication is the "and" operation (aka `&&`), in which the
|
Correspondingly, multiplication is the "and" operation (aka `&&`), in which the
|
||||||
result is false if either operand is false, and true otherwise.
|
result is false if either operand is false, and true otherwise.
|
||||||
|
@ -252,23 +252,23 @@ result is false if either operand is false, and true otherwise.
|
||||||
\end{array}
|
\end{array}
|
||||||
{{< /latex >}}
|
{{< /latex >}}
|
||||||
|
|
||||||
For multiplication, the identity element -- the \\(1\\) -- is \\(\\text{true}\\).
|
For multiplication, the identity element -- the \(1\) -- is \(\text{true}\).
|
||||||
|
|
||||||
It's not hard to see that _both_ operations are commutative - the first and
|
It's not hard to see that _both_ operations are commutative - the first and
|
||||||
second equations for addition, for instance, can be combined to get
|
second equations for addition, for instance, can be combined to get
|
||||||
\\(\\text{true}+b=b+\\text{true}\\), and the third equation clearly shows
|
\(\text{true}+b=b+\text{true}\), and the third equation clearly shows
|
||||||
commutativity when both operands are false. The other properties are
|
commutativity when both operands are false. The other properties are
|
||||||
easy enough to verify by simple case analysis (there are 8 cases to consider).
|
easy enough to verify by simple case analysis (there are 8 cases to consider).
|
||||||
The set of booleans is usually denoted as \\(\\mathbb{B}\\), which means
|
The set of booleans is usually denoted as \(\mathbb{B}\), which means
|
||||||
polynomials using booleans are denoted by \\(\\mathbb{B}[x]\\).
|
polynomials using booleans are denoted by \(\mathbb{B}[x]\).
|
||||||
|
|
||||||
Let's try some examples. We can't count how many ways there are to get from
|
Let's try some examples. We can't count how many ways there are to get from
|
||||||
A to B in a certain number of hours anymore: booleans aren't numbers!
|
A to B in a certain number of hours anymore: booleans aren't numbers!
|
||||||
Instead, what we _can_ do is track _whether or not_ there is a way to get
|
Instead, what we _can_ do is track _whether or not_ there is a way to get
|
||||||
from A to B in a certain number of hours (call it \\(n\\)). If we can,
|
from A to B in a certain number of hours (call it \(n\)). If we can,
|
||||||
we write that as \\(\text{true}\ x^n = 1x^n = x^n\\). If we can't, we write
|
we write that as \(\text{true}\ x^n = 1x^n = x^n\). If we can't, we write
|
||||||
that as \\(\\text{false}\ x^n = 0x^n = 0\\). The polynomials corresponding
|
that as \(\text{false}\ x^n = 0x^n = 0\). The polynomials corresponding
|
||||||
to our introductory problem are \\(x^2+x^1\\) and \\(x^3+x^2\\). Multiplying
|
to our introductory problem are \(x^2+x^1\) and \(x^3+x^2\). Multiplying
|
||||||
them out gives:
|
them out gives:
|
||||||
|
|
||||||
{{< latex >}}
|
{{< latex >}}
|
||||||
|
@ -306,7 +306,7 @@ that we lost information, rather than gained it, but switching to
|
||||||
boolean polynomials: we can always recover a boolean polynomial from the
|
boolean polynomials: we can always recover a boolean polynomial from the
|
||||||
natural number one, but not the other way around.
|
natural number one, but not the other way around.
|
||||||
{{< /sidenote >}}
|
{{< /sidenote >}}
|
||||||
(which were \\(\\mathbb{N}[x]\\), polynomials over natural numbers \\(\\mathbb{N} = \\{ 0, 1, 2, ... \\}\\)), so it's unclear why we'd prefer them. However,
|
(which were \(\mathbb{N}[x]\), polynomials over natural numbers \(\mathbb{N} = \{ 0, 1, 2, ... \}\)), so it's unclear why we'd prefer them. However,
|
||||||
we're just warming up - there are more interesting semirings for us to
|
we're just warming up - there are more interesting semirings for us to
|
||||||
consider!
|
consider!
|
||||||
|
|
||||||
|
@ -316,12 +316,12 @@ equivalent". If we're giving directions, though, we might benefit
|
||||||
from knowing not just that there _is_ a way, but what roads that
|
from knowing not just that there _is_ a way, but what roads that
|
||||||
way is made up of!
|
way is made up of!
|
||||||
|
|
||||||
To this end, we define the set of paths, \\(\\Pi\\). This set will consist
|
To this end, we define the set of paths, \(\Pi\). This set will consist
|
||||||
of the empty path (which we will denote \\(\\circ\\), why not?), street
|
of the empty path (which we will denote \(\circ\), why not?), street
|
||||||
names (e.g. \\(\\text{Mullholland Dr.}\\) or \\(\\text{Sunset Blvd.}\\)), and
|
names (e.g. \(\text{Mullholland Dr.}\) or \(\text{Sunset Blvd.}\)), and
|
||||||
concatenations of paths, written using \\(\\rightarrow\\). For instance,
|
concatenations of paths, written using \(\rightarrow\). For instance,
|
||||||
a path that first takes us on \\(\\text{Highway}\\) and then on
|
a path that first takes us on \(\text{Highway}\) and then on
|
||||||
\\(\\text{Exit 4b}\\) will be written as:
|
\(\text{Exit 4b}\) will be written as:
|
||||||
|
|
||||||
{{< latex >}}
|
{{< latex >}}
|
||||||
\text{Highway}\rightarrow\text{Exit 4b}
|
\text{Highway}\rightarrow\text{Exit 4b}
|
||||||
|
@ -329,7 +329,7 @@ a path that first takes us on \\(\\text{Highway}\\) and then on
|
||||||
|
|
||||||
Furthermore, it's not too much of a stretch to say that adding an empty path
|
Furthermore, it's not too much of a stretch to say that adding an empty path
|
||||||
to the front or the back of another path doesn't change it. If we use
|
to the front or the back of another path doesn't change it. If we use
|
||||||
the letter \\(\\pi\\) to denote a path, this means the following equation:
|
the letter \(\pi\) to denote a path, this means the following equation:
|
||||||
|
|
||||||
{{< latex >}}
|
{{< latex >}}
|
||||||
\circ \rightarrow \pi = \pi = \pi \rightarrow \circ
|
\circ \rightarrow \pi = \pi = \pi \rightarrow \circ
|
||||||
|
@ -347,8 +347,8 @@ different ways to get from one place to another. This is an excellent
|
||||||
use case for sets!
|
use case for sets!
|
||||||
|
|
||||||
Our next semiring will be that of _sets of paths_. Some example elements
|
Our next semiring will be that of _sets of paths_. Some example elements
|
||||||
of this semiring are \\(\\varnothing\\), also known as the empty set,
|
of this semiring are \(\varnothing\), also known as the empty set,
|
||||||
\\(\\{\\circ\\}\\), the set containing only the empty path, and the set
|
\(\{\circ\}\), the set containing only the empty path, and the set
|
||||||
containing a path via the highway, and another path via the suburbs:
|
containing a path via the highway, and another path via the suburbs:
|
||||||
|
|
||||||
{{< latex >}}
|
{{< latex >}}
|
||||||
|
@ -364,16 +364,16 @@ A + B \triangleq A \cup B
|
||||||
{{< /latex >}}
|
{{< /latex >}}
|
||||||
|
|
||||||
It's well known (and not hard to verify) that set union is commutative
|
It's well known (and not hard to verify) that set union is commutative
|
||||||
and associative. The additive identity \\(0\\) is simply the empty set
|
and associative. The additive identity \(0\) is simply the empty set
|
||||||
\\(\\varnothing\\). Intuitively, adding "no paths" to another set of
|
\(\varnothing\). Intuitively, adding "no paths" to another set of
|
||||||
paths doesn't add anything, and thus leaves that other set unchanged.
|
paths doesn't add anything, and thus leaves that other set unchanged.
|
||||||
|
|
||||||
Multiplication is a little bit more interesting, and uses the path
|
Multiplication is a little bit more interesting, and uses the path
|
||||||
concatenation operation we defined earlier. We will use this
|
concatenation operation we defined earlier. We will use this
|
||||||
operation to describe path sequencing; given two sets of paths,
|
operation to describe path sequencing; given two sets of paths,
|
||||||
\\(A\\) and \\(B\\), we'll create a new set of paths
|
\(A\) and \(B\), we'll create a new set of paths
|
||||||
consisting of each path from \\(A\\) concatenated with each
|
consisting of each path from \(A\) concatenated with each
|
||||||
path from \\(B\\):
|
path from \(B\):
|
||||||
|
|
||||||
{{< latex >}}
|
{{< latex >}}
|
||||||
A \times B \triangleq \{ a \rightarrow b\ |\ a \in A, b \in B \}
|
A \times B \triangleq \{ a \rightarrow b\ |\ a \in A, b \in B \}
|
||||||
|
@ -394,8 +394,8 @@ A \times (B \times C) & = & \{ a \rightarrow (b \rightarrow c)\ |\ a \in A, b \i
|
||||||
What's the multiplicative identity? Well, since multiplication concatenates
|
What's the multiplicative identity? Well, since multiplication concatenates
|
||||||
all the combinations of paths from two sets, we could try making a set of
|
all the combinations of paths from two sets, we could try making a set of
|
||||||
elements that don't do anything when concatenating. Sound familiar? It should,
|
elements that don't do anything when concatenating. Sound familiar? It should,
|
||||||
that's \\(\\circ\\), the empty path element! We thus define our multiplicative
|
that's \(\circ\), the empty path element! We thus define our multiplicative
|
||||||
identity as \\(\\{\\circ\\}\\), and verify that it is indeed the identity:
|
identity as \(\{\circ\}\), and verify that it is indeed the identity:
|
||||||
|
|
||||||
{{< latex >}}
|
{{< latex >}}
|
||||||
\begin{gathered}
|
\begin{gathered}
|
||||||
|
@ -409,11 +409,11 @@ sets of paths, either; I won't do that here, though. Finally, let's take
|
||||||
a look at an example. Like before, we'll try make one that corresponds to
|
a look at an example. Like before, we'll try make one that corresponds to
|
||||||
our introductory description of paths from A to B and from B to C. Now we need
|
our introductory description of paths from A to B and from B to C. Now we need
|
||||||
to be a little bit creative, and come up with names for all these different
|
to be a little bit creative, and come up with names for all these different
|
||||||
roads between our hypothetical cities. Let's say that \\(\\text{Highway A}\\)
|
roads between our hypothetical cities. Let's say that \(\text{Highway A}\)
|
||||||
and \\(\\text{Highway B}\\) are the two paths from A to B that take two hours
|
and \(\text{Highway B}\) are the two paths from A to B that take two hours
|
||||||
each, and then \\(\\text{Shortcut}\\) is the path that takes one hour. As for
|
each, and then \(\text{Shortcut}\) is the path that takes one hour. As for
|
||||||
paths from B to C, let's just call them \\(\\text{Long}\\) for the three-hour
|
paths from B to C, let's just call them \(\text{Long}\) for the three-hour
|
||||||
path, and \\(\\text{Short}\\) for the two-hour path. Our two polynomials
|
path, and \(\text{Short}\) for the two-hour path. Our two polynomials
|
||||||
are then:
|
are then:
|
||||||
|
|
||||||
{{< latex >}}
|
{{< latex >}}
|
||||||
|
@ -440,12 +440,12 @@ I only have one last semiring left to show you. It's a fun semiring though,
|
||||||
as even its name might suggest: we'll take a look at a _tropical semiring_.
|
as even its name might suggest: we'll take a look at a _tropical semiring_.
|
||||||
|
|
||||||
In this semiring, we go back to numbers; particularly, real numbers (e.g.,
|
In this semiring, we go back to numbers; particularly, real numbers (e.g.,
|
||||||
\\(1.34\\), \\(163\\), \\(e\\), that kind of thing). We even use addition --
|
\(1.34\), \(163\), \(e\), that kind of thing). We even use addition --
|
||||||
sort of. In the tropical semiring, addition serves as the _multiplicative_
|
sort of. In the tropical semiring, addition serves as the _multiplicative_
|
||||||
operation! This is even confusing to write, so I'm going to switch up notation;
|
operation! This is even confusing to write, so I'm going to switch up notation;
|
||||||
in the rest of this section, I'll use \\(\\otimes\\) to represent the
|
in the rest of this section, I'll use \(\otimes\) to represent the
|
||||||
multiplicative operation in semirings, and \\(\\oplus\\) to represent the
|
multiplicative operation in semirings, and \(\oplus\) to represent the
|
||||||
additive one. The symbols \\(\\times\\) and \\(+\\) will be used to represent
|
additive one. The symbols \(\times\) and \(+\) will be used to represent
|
||||||
the regular operations on real numbers. With that, the operations on our
|
the regular operations on real numbers. With that, the operations on our
|
||||||
tropical semiring over real numbers are defined as follows:
|
tropical semiring over real numbers are defined as follows:
|
||||||
|
|
||||||
|
@ -461,17 +461,17 @@ the duration of the trip, you'd like to track the distance you must travel for
|
||||||
each route (shorter routes do sometimes have more traffic!). Let's watch what
|
each route (shorter routes do sometimes have more traffic!). Let's watch what
|
||||||
happens when we add and multiply polynomials over this semiring.
|
happens when we add and multiply polynomials over this semiring.
|
||||||
When we add terms with the same power but different coefficients, like
|
When we add terms with the same power but different coefficients, like
|
||||||
\\(ax\oplus bx\\), we end up with a term \\(\min(a,b)x\\). In other words,
|
\(ax\oplus bx\), we end up with a term \(\min(a,b)x\). In other words,
|
||||||
for each trip duration, we pick the shortest length. When we multiply two
|
for each trip duration, we pick the shortest length. When we multiply two
|
||||||
polynomials, like \\(ax\otimes bx\\), we get \\((a+b)x\\); in other words,
|
polynomials, like \(ax\otimes bx\), we get \((a+b)x\); in other words,
|
||||||
when sequencing two trips, we add up the distances to get the combined
|
when sequencing two trips, we add up the distances to get the combined
|
||||||
distance, just like we'd expect.
|
distance, just like we'd expect.
|
||||||
|
|
||||||
We can, of course, come up with a polynomial to match our initial example.
|
We can, of course, come up with a polynomial to match our initial example.
|
||||||
Say that the trips from A to B are represented by \\(2.0x^2\oplus1.5x\\\) (the
|
Say that the trips from A to B are represented by \(2.0x^2\oplus1.5x\) (the
|
||||||
shortest two-hour trip is \\(2\\) units of distance long, and the one-hour
|
shortest two-hour trip is \(2\) units of distance long, and the one-hour
|
||||||
trip is \\(1.5\\) units long), and that the trips from B to C are represented
|
trip is \(1.5\) units long), and that the trips from B to C are represented
|
||||||
by \\(4.0x^3\oplus1.0x^2\\). Multiplying the two polynomials out gives:
|
by \(4.0x^3\oplus1.0x^2\). Multiplying the two polynomials out gives:
|
||||||
|
|
||||||
{{< latex >}}
|
{{< latex >}}
|
||||||
\begin{array}{rcl}
|
\begin{array}{rcl}
|
||||||
|
@ -484,7 +484,7 @@ The only time we used the additive operation in this case was to pick between
|
||||||
two trips of equal druation but different length (two-hour trip from A to B
|
two trips of equal druation but different length (two-hour trip from A to B
|
||||||
followed by a two-hour trip from B to C, or one-hour trip from A to C followed
|
followed by a two-hour trip from B to C, or one-hour trip from A to C followed
|
||||||
by a three-hour trip from B to C). The first trip wins out, since it requires
|
by a three-hour trip from B to C). The first trip wins out, since it requires
|
||||||
only \\(3.0\\) units of distance.
|
only \(3.0\) units of distance.
|
||||||
|
|
||||||
### Anything but Routes
|
### Anything but Routes
|
||||||
So far, all I've done can be reduced to variations on a theme: keeping track
|
So far, all I've done can be reduced to variations on a theme: keeping track
|
||||||
|
|
Loading…
Reference in New Issue
Block a user