-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDFAs Enumerating Binary Strings.nb
229 lines (219 loc) · 7.69 KB
/
DFAs Enumerating Binary Strings.nb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 11.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 158, 7]
NotebookDataLength[ 7712, 221]
NotebookOptionsPosition[ 7309, 203]
NotebookOutlinePosition[ 7661, 219]
CellTagsIndexPosition[ 7618, 216]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell["\<\
We want to construct a DFA, where the transitions are given by 0\
\[CloseCurlyQuote]s and 1\[CloseCurlyQuote]s \[Dash] and the final states are \
all strings of length N. We have a trapping state for any adjacent 1\
\[CloseCurlyQuote]s.\
\>", "Text",
CellChangeTimes->{{3.6803298626890297`*^9, 3.680329938747211*^9}, {
3.680330051905963*^9, 3.680330054671474*^9}}],
Cell[BoxData[{
RowBox[{
RowBox[{"Q3", " ", "=", " ",
RowBox[{"(", GridBox[{
{"0",
FractionBox["1", "2"],
FractionBox["1", "2"], "0", "0", "0", "0", "0"},
{"0", "0", "0",
FractionBox["1", "2"],
FractionBox["1", "2"], "0", "0", "0"},
{"0", "0", "0",
FractionBox["1", "2"], "0", "0", "0",
FractionBox["1", "2"]},
{"0", "0", "0", "0", "0",
FractionBox["1", "2"],
FractionBox["1", "2"], "0"},
{"0", "0", "0", "0", "0",
FractionBox["1", "2"], "0",
FractionBox["1", "2"]},
{"0", "0", "0", "0", "0", "0", "0", "1"},
{"0", "0", "0", "0", "0", "0", "0", "1"},
{"0", "0", "0", "0", "0", "0", "0", "1"}
}], ")"}]}], ";"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{"Q2", " ", "=", " ",
RowBox[{"(", GridBox[{
{"0",
FractionBox["1", "2"],
FractionBox["1", "2"], "0", "0", "0"},
{"0", "0", "0",
FractionBox["1", "2"],
FractionBox["1", "2"], "0"},
{"0", "0", "0",
FractionBox["1", "2"], "0",
FractionBox["1", "2"]},
{"0", "0", "0", "0", "0", "1"},
{"0", "0", "0", "0", "0", "1"},
{"0", "0", "0", "0", "0", "1"}
}], ")"}]}], ";"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{"Q31", "=",
RowBox[{"(", GridBox[{
{"0", "1", "1", "0", "0", "0", "0", "0"},
{"0", "0", "0", "1", "1", "0", "0", "0"},
{"0", "0", "0", "1", "0", "0", "0", "1"},
{"0", "0", "0", "0", "0", "1", "1", "0"},
{"0", "0", "0", "0", "0", "1", "0", "1"},
{"0", "0", "0", "0", "0", "1", "0", "0"},
{"0", "0", "0", "0", "0", "0", "1", "0"},
{"0", "0", "0", "0", "0", "0", "0", "1"}
}], ")"}]}], ";"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{"Q21", "=", " ",
RowBox[{"(", GridBox[{
{"0", "1", "1", "0", "0", "0"},
{"0", "0", "0", "1", "1", "0"},
{"0", "0", "0", "1", "0", "1"},
{"0", "0", "0", "0", "0", "1"},
{"0", "0", "0", "0", "0", "1"},
{"0", "0", "0", "0", "0", "1"}
}], ")"}]}], ";"}]}], "Input",
CellChangeTimes->{{3.6803598878428288`*^9, 3.680359905145759*^9}, {
3.680360076803694*^9, 3.6803603342143*^9}, {3.680360367327195*^9,
3.680360372415612*^9}, {3.680360408335876*^9, 3.680360501139606*^9}, {
3.680361206036378*^9, 3.680361386677074*^9}, {3.680361417360642*^9,
3.680361428493188*^9}, {3.680361504460895*^9, 3.680361519026729*^9}, {
3.68036404394014*^9, 3.6803640482336273`*^9}, {3.68038273447648*^9,
3.680382738330212*^9}, {3.680383046712925*^9, 3.680383049534542*^9}, {
3.680404623683419*^9, 3.680404633479396*^9}}],
Cell[BoxData[{
RowBox[{
RowBox[{
RowBox[{"MatrixPower", "[",
RowBox[{"Q3", ",", "3"}], "]"}], "//", "MatrixForm"}],
";"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{
RowBox[{"MatrixPower", "[",
RowBox[{"Q31", ",", "3"}], "]"}], "//", "MatrixForm"}],
";"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{
RowBox[{"MatrixPower", "[",
RowBox[{"Q21", ",", "2"}], "]"}], "//", "MatrixForm"}], ";"}]}], "Input",
CellChangeTimes->{{3.680360509855336*^9, 3.680360534828485*^9}, {
3.6803607692581663`*^9, 3.6803607758879004`*^9}, {3.680361240898982*^9,
3.680361267958972*^9}, {3.680361431564528*^9, 3.6803614416095743`*^9},
3.680361522508471*^9, {3.68036405738771*^9, 3.6803640607855186`*^9},
3.680404637952488*^9}],
Cell[BoxData[
RowBox[{
SuperscriptBox[
RowBox[{"(", GridBox[{
{"0",
FractionBox["1", "2"],
FractionBox["1", "2"], "0", "0", "0", "0", "0"},
{"0", "0", "0",
FractionBox["1", "2"],
FractionBox["1", "2"], "0", "0", "0"},
{"0", "0", "0",
FractionBox["1", "2"], "0", "0", "0",
FractionBox["1", "2"]},
{"0", "0", "0", "0", "0",
FractionBox["1", "2"],
FractionBox["1", "2"], "0"},
{"0", "0", "0", "0", "0",
FractionBox["1", "2"], "0",
FractionBox["1", "2"]},
{"0", "0", "0", "0", "0", "1", "0", "0"},
{"0", "0", "0", "0", "0", "0", "1", "0"},
{"0", "0", "0", "0", "0", "0", "0", "1"}
}], ")"}], "3"], "=",
TagBox[
RowBox[{"(", "\[NoBreak]", GridBox[{
{"0", "0", "0", "0", "0",
FractionBox["3", "8"],
FractionBox["1", "4"],
FractionBox["3", "8"]},
{"0", "0", "0", "0", "0",
FractionBox["1", "2"],
FractionBox["1", "4"],
FractionBox["1", "4"]},
{"0", "0", "0", "0", "0",
FractionBox["1", "4"],
FractionBox["1", "4"],
FractionBox["1", "2"]},
{"0", "0", "0", "0", "0",
FractionBox["1", "2"],
FractionBox["1", "2"], "0"},
{"0", "0", "0", "0", "0",
FractionBox["1", "2"], "0",
FractionBox["1", "2"]},
{"0", "0", "0", "0", "0", "1", "0", "0"},
{"0", "0", "0", "0", "0", "0", "1", "0"},
{"0", "0", "0", "0", "0", "0", "0", "1"}
},
GridBoxAlignment->{
"Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}},
"RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}],
Function[BoxForm`e$,
MatrixForm[BoxForm`e$]]]}]], "Input",
CellChangeTimes->{{3.680361686316182*^9, 3.6803617224417953`*^9}}],
Cell[TextData[{
"This is the transition matrix for a corresponding DFA that accepts binary \
strings of length 3 with no consecutive ones, where each transition is \
assigned an equal probability.\nOur accepting states are {5,6}.\n By taking \
the matrix power of 3 (past this point we reach a steady state), we get the \
right hand side.\n\nThen summing the probabilities for \[Rho](0,5) and \
\[Rho](0,6) we get ",
Cell[BoxData[
FormBox[
FractionBox["5", "8"], TraditionalForm]],
FormatType->"TraditionalForm"],
". Multiplying by ",
Cell[BoxData[
FormBox[
SuperscriptBox["2", "3"], TraditionalForm]],
FormatType->"TraditionalForm"],
" for all possible transitions (or all possible 3-long binary strings)... we \
get 5. Mind blown.\n"
}], "Text",
CellChangeTimes->{{3.68036172370494*^9, 3.680361889289906*^9}, {
3.680361919593956*^9, 3.6803620068848124`*^9}}]
},
WindowSize->{720, 851},
WindowMargins->{{Automatic, 0}, {Automatic, 0}},
FrontEndVersion->"11.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (July 28, \
2016)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 377, 7, 49, "Text"],
Cell[938, 29, 2639, 68, 639, "Input"],
Cell[3580, 99, 755, 19, 75, "Input"],
Cell[4338, 120, 2082, 59, 194, "Input"],
Cell[6423, 181, 882, 20, 191, "Text"]
}
]
*)