-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract subsections on formal languages into a standalone section
- Loading branch information
Showing
15 changed files
with
647 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from ..linalg.matrix import zeros | ||
|
||
|
||
def hamming(v: str, w: str): | ||
return sum(a != b for a, b in zip(v, w)) | ||
|
||
|
||
# This is alg:wagner_fisher in the text | ||
def fisher_wagner(v: str, w: str): | ||
mtx = zeros(len(v) + 1, len(w) + 1) | ||
|
||
for i in range(len(v) + 1): | ||
mtx[(i, 0)] = i | ||
|
||
for j in range(len(w) + 1): | ||
mtx[(0, j)] = j | ||
|
||
for i in range(1, len(v) + 1): | ||
for j in range(1, len(w) + 1): | ||
mtx[(i, j)] = min( | ||
mtx[(i - 1, j)] + 1, | ||
mtx[(i, j - 1)] + 1, | ||
mtx[(i - 1, j - 1)] + (0 if v[i - 1] == w[j - 1] else 1) | ||
) | ||
|
||
return mtx[(len(v), len(w))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from .distance import hamming, fisher_wagner | ||
|
||
|
||
def test_hamming(): | ||
assert hamming('', '') == 0 | ||
assert hamming('test', 'test') == 0 | ||
|
||
# ex:def:levenshtein_distance/shift | ||
assert hamming('ac', 'ba') == 2 | ||
assert hamming('abc', 'bca') == 3 | ||
assert hamming('abbc', 'bbca') == 3 | ||
assert hamming('abbbc', 'bbbca') == 3 | ||
|
||
|
||
def test_fisher_wagner(): | ||
assert fisher_wagner('', '') == 0 | ||
assert fisher_wagner('test', 'test') == 0 | ||
|
||
# ex:def:levenshtein_distance/shift | ||
assert fisher_wagner('ac', 'ba') == 2 | ||
assert fisher_wagner('abc', 'bca') == 2 | ||
assert fisher_wagner('abbc', 'bbca') == 2 | ||
assert fisher_wagner('abbbc', 'bbbca') == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
\documentclass{classes/tikzcd} | ||
|
||
\begin{document} | ||
\begin{tikzcd}[every arrow/.append style={dash}, column sep=small] | ||
&& & & \cdots \ar[rd, bend left] & & && \\ | ||
&& & q_{i+1} \ar[ru, bend left] & & q_{j-1} \ar[ld, bend left] & && \\ | ||
q_0 \ar[rr, "a_1"] && \cdots \ar[rr, "a_i"] & & q_i = q_j \ar[lu, bend left] \ar[rr, "a_j"] & & \cdots \ar[rr, "a_n"] && q_n | ||
\end{tikzcd} | ||
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\section{Formal language theory}\label{sec:formal_language_theory} |
Oops, something went wrong.